1616
1717#include " FFitWeights.h"
1818
19+ #include " Framework/Logger.h"
20+
1921#include < TCollection.h>
2022#include < TH1.h>
21- #include < TH2.h>
2223#include < TNamed.h>
2324#include < TObjArray.h>
24- #include < TProfile.h>
2525#include < TSpline.h>
2626#include < TString.h>
2727
@@ -36,6 +36,8 @@ ClassImp(FFitWeights)
3636
3737 FFitWeights::FFitWeights() : TNamed(" " , " " ),
3838 fW_data{nullptr },
39+ ptProfCent{nullptr },
40+ h2ptCent{nullptr },
3941 centBin{100 },
4042 qAxis{nullptr },
4143 nResolution{3000 },
@@ -47,6 +49,8 @@ ClassImp(FFitWeights)
4749
4850FFitWeights::FFitWeights (const char * name) : TNamed(name, name),
4951 fW_data{nullptr },
52+ ptProfCent{nullptr },
53+ h2ptCent{nullptr },
5054 centBin{100 },
5155 qAxis{nullptr },
5256 nResolution{3000 },
@@ -77,9 +81,11 @@ void FFitWeights::init()
7781
7882 if (!ptAxis)
7983 this ->setPtAxis (3000 , -3 , 3 );
80- // fW_data->Add(new TH2D("hPtWeight", "", centBin, 0, centBin, ptBin, ptAxis->GetXmin(), ptAxis->GetXmax()));
8184 fW_data ->Add (new TProfile (" pMeanPt" , " " , centBin, 0 , centBin));
8285 fW_data ->Add (new TH2D (" hPtWeight" , " " , centBin, 0 , centBin, ptBin, ptAxis->GetXmin (), ptAxis->GetXmax ()));
86+
87+ ptProfCent = reinterpret_cast <TProfile*>(fW_data ->FindObject (" pMeanPt" ));
88+ h2ptCent = reinterpret_cast <TH2D*>(fW_data ->FindObject (" hPtWeight" ));
8389};
8490
8591void FFitWeights::fillWeights (float centrality, float qn, int nh, const char * pf)
@@ -97,40 +103,21 @@ void FFitWeights::fillWeights(float centrality, float qn, int nh, const char* pf
97103 }
98104 th2->Fill (centrality, qn);
99105};
106+
100107void FFitWeights::fillPt (float centrality, float pt, bool first)
101108{
102- TObjArray* tar{nullptr };
103- tar = fW_data ;
104- if (!tar)
105- return ;
106109 if (first) {
107- auto tp = reinterpret_cast <TProfile*>(tar->FindObject (" pMeanPt" ));
108- if (!tp) {
109- tar->Add (new TProfile (" pMeanPt" , " " , centBin, 0 , centBin));
110- tp = reinterpret_cast <TProfile*>(tar->At (tar->GetEntries () - 1 ));
111- }
112- tp->Fill (centrality, pt);
110+ ptProfCent->Fill (centrality, pt);
113111 } else {
114- auto th2 = reinterpret_cast <TH2D*>(tar->FindObject (" hPtWeight" ));
115- if (!th2) {
116- tar->Add (new TH2D (" hPtWeight" , " " , centBin, 0 , centBin, ptBin, ptAxis->GetXmin (), ptAxis->GetXmax ()));
117- th2 = reinterpret_cast <TH2D*>(tar->At (tar->GetEntries () - 1 ));
118- }
119- th2->Fill (centrality, pt);
112+ h2ptCent->Fill (centrality, pt);
120113 }
121114};
122115float FFitWeights::getPtMult (float centrality)
123116{
124- TObjArray* tar{nullptr };
125- tar = fW_data ;
126- if (!tar)
127- return -1 ;
128-
129- auto tp = reinterpret_cast <TProfile*>(tar->FindObject (" pMeanPt" ));
130- if (!tp) {
131- return -1 ;
117+ if (!ptProfCent) {
118+ ptProfCent = reinterpret_cast <TProfile*>(fW_data ->FindObject (" pMeanPt" ));
132119 }
133- return tp ->GetBinContent (tp ->FindBin (centrality));
120+ return ptProfCent ->GetBinContent (ptProfCent ->FindBin (centrality));
134121};
135122
136123Long64_t FFitWeights::Merge (TCollection* collist)
@@ -151,23 +138,26 @@ Long64_t FFitWeights::Merge(TCollection* collist)
151138};
152139void FFitWeights::addArray (TObjArray* targ, TObjArray* sour)
153140{
154- if (!sour) {
155- // printf("Source array does not exist!\n");
156- // LOGF(info, "FFitWeights source array does not exist!");
141+ if (!sour)
157142 return ;
158- }
143+
159144 for (int i = 0 ; i < sour->GetEntries (); i++) {
160- TH2D* sourh = reinterpret_cast <TH2D*>(sour->At (i));
161- TH2D* targh = reinterpret_cast <TH2D*>(targ->FindObject (sourh->GetName ()));
162- if (!targh) {
163- targh = reinterpret_cast <TH2D*>(sourh->Clone (sourh->GetName ()));
164- targh->SetDirectory (0 );
165- targ->Add (targh);
166- } else {
167- targh->Add (sourh);
145+ auto * obj = sour->At (i);
146+ if (!obj)
147+ continue ;
148+
149+ auto * tObj = targ->FindObject (obj->GetName ());
150+ if (!tObj) {
151+ auto * clone = static_cast <TObject*>(obj->Clone (obj->GetName ()));
152+ if (auto * h = dynamic_cast <TH1*>(clone))
153+ h->SetDirectory (0 );
154+ targ->Add (clone);
155+ } else if (auto * h1 = dynamic_cast <TH1*>(tObj)) {
156+ if (auto * h2 = dynamic_cast <TH1*>(obj))
157+ h1->Add (h2);
168158 }
169159 }
170- };
160+ }
171161
172162void FFitWeights::mptSel ()
173163{
@@ -208,8 +198,7 @@ void FFitWeights::qSelection(const std::vector<int>& nhv, const std::vector<std:
208198 for (const auto & nh : nhv) {
209199 TH2D* th2{reinterpret_cast <TH2D*>(tar->FindObject (this ->getQName (nh, pf.c_str ())))};
210200 if (!th2) {
211- // printf("qh not found!\n");
212- // LOGF(info, "FFitWeights qh not found!");
201+ LOGF (info, " FFitWeights qh not found!" );
213202 return ;
214203 }
215204
@@ -225,63 +214,36 @@ void FFitWeights::qSelection(const std::vector<int>& nhv, const std::vector<std:
225214 tmp->GetQuantiles (nResolution, yq.data (), xq.data ());
226215 tmpgr = new TGraph (nResolution, yq.data (), xq.data ());
227216 tmpgr->SetName (Form (" sp_q%i%s_%i" , nh, pf.c_str (), iSP));
228- // spline = new TSpline3(Form("sp_q%i%s_%i", nh, pf.c_str(), iSP), tmpgr);
229- // spline->SetName(Form("sp_q%i%s_%i", nh, pf.c_str(), iSP));
230217 fW_data ->Add (tmpgr);
231218 }
232219 }
233220 }
234221};
235-
236- float FFitWeights::eval (float centr, const float & dqn, const int nh, const char * pf)
222+ float FFitWeights::internalEval (float centr, const float & val, const char * name)
237223{
238- TObjArray* tar{nullptr };
239-
240- tar = fW_data ;
241- if (!tar) {
224+ if (!fW_data ) {
242225 return -1 ;
243226 }
244-
245- int isp{static_cast <int >(centr)};
227+ int isp = static_cast <int >(centr);
246228 if (isp < 0 || isp > NumberSp) {
247229 return -1 ;
248230 }
249231
250- TGraph* spline{nullptr };
251- spline = reinterpret_cast <TGraph*>(tar->FindObject (Form (" sp_q%i%s_%i" , nh, pf, isp)));
232+ auto * spline = dynamic_cast <TGraph*>(fW_data ->FindObject (Form (name, isp)));
252233 if (!spline) {
253234 return -1 ;
254235 }
255236
256- float qnVal{static_cast <float >(100 . * spline->Eval (dqn))};
257- if (qnVal < 0 || qnVal > MaxTol) {
258- return -1 ;
259- }
237+ float perc = 100 .f * spline->Eval (val);
238+ return (perc < 0 || perc > MaxTol) ? -1 : perc;
239+ };
260240
261- return qnVal;
241+ float FFitWeights::eval (float centr, const float & dqn, int nh, const char * pf)
242+ {
243+ return internalEval (centr, dqn, Form (" sp_q%i%s_%%i" , nh, pf));
262244};
263245
264246float FFitWeights::evalPt (float centr, const float & mpt)
265247{
266- TObjArray* tar{nullptr };
267- tar = fW_data ;
268- if (!tar) {
269- return -1 ;
270- }
271-
272- int isp{static_cast <int >(centr)};
273- if (isp < 0 || isp > NumberSp) {
274- return -1 ;
275- }
276-
277- TGraph* spline{nullptr };
278- spline = reinterpret_cast <TGraph*>(tar->FindObject (Form (" sp_mpt_%i" , isp)));
279- if (!spline) {
280- return -1 ;
281- }
282- float ptVal{static_cast <float >(100 . * spline->Eval (mpt))};
283- if (ptVal < 0 || ptVal > MaxTol) {
284- return -1 ;
285- }
286- return ptVal;
248+ return internalEval (centr, mpt, " sp_mpt_%i" );
287249};
0 commit comments