1919#include < TCollection.h>
2020#include < TH1.h>
2121#include < TH2.h>
22+ #include < TProfile.h>
2223#include < TNamed.h>
2324#include < TObjArray.h>
2425#include < TSpline.h>
@@ -35,25 +36,31 @@ ClassImp(FFitWeights)
3536
3637 FFitWeights::FFitWeights() : TNamed(" " , " " ),
3738 fW_data{nullptr },
38- CentBin {100 },
39+ centBin {100 },
3940 qAxis{nullptr },
4041 nResolution{3000 },
42+ ptBin{100 },
43+ ptAxis{nullptr },
4144 qnTYPE{0 }
4245{
4346}
4447
4548FFitWeights::FFitWeights (const char * name) : TNamed(name, name),
4649 fW_data{nullptr },
47- CentBin {100 },
50+ centBin {100 },
4851 qAxis{nullptr },
4952 nResolution{3000 },
53+ ptBin{100 },
54+ ptAxis{nullptr },
5055 qnTYPE{0 } {}
5156
5257FFitWeights::~FFitWeights ()
5358{
5459 delete fW_data ;
5560 if (qAxis)
5661 delete qAxis;
62+ if (ptAxis)
63+ delete ptAxis;
5764};
5865
5966void FFitWeights::init ()
@@ -65,8 +72,14 @@ void FFitWeights::init()
6572 if (!qAxis)
6673 this ->setBinAxis (500 , 0 , 25 );
6774 for (const auto & qn : qnTYPE) {
68- fW_data ->Add (new TH2D (this ->getQName (qn.first , qn.second .c_str ()), this ->getAxisName (qn.first , qn.second .c_str ()), CentBin , 0 , CentBin , qAxis->GetNbins (), qAxis->GetXmin (), qAxis->GetXmax ()));
75+ fW_data ->Add (new TH2D (this ->getQName (qn.first , qn.second .c_str ()), this ->getAxisName (qn.first , qn.second .c_str ()), centBin , 0 , centBin , qAxis->GetNbins (), qAxis->GetXmin (), qAxis->GetXmax ()));
6976 }
77+
78+ if (!ptAxis)
79+ this ->setPtAxis (3000 , -3 , 3 );
80+ // fW_data->Add(new TH2D("hPtWeight", "", centBin, 0, centBin, ptBin, ptAxis->GetXmin(), ptAxis->GetXmax()));
81+ fW_data ->Add (new TProfile (" pMeanPt" ," " , centBin, 0 , centBin));
82+ fW_data ->Add (new TH2D (" hPtWeight" , " " , centBin, 0 , centBin, ptBin, ptAxis->GetXmin (), ptAxis->GetXmax ()));
7083};
7184
7285void FFitWeights::fillWeights (float centrality, float qn, int nh, const char * pf)
@@ -79,11 +92,47 @@ void FFitWeights::fillWeights(float centrality, float qn, int nh, const char* pf
7992
8093 TH2D* th2 = reinterpret_cast <TH2D*>(tar->FindObject (this ->getQName (nh, pf)));
8194 if (!th2) {
82- tar->Add (new TH2D (this ->getQName (nh, pf), this ->getAxisName (nh, pf), CentBin , 0 , CentBin , qAxis->GetNbins (), qAxis->GetXmin (), qAxis->GetXmax ()));
95+ tar->Add (new TH2D (this ->getQName (nh, pf), this ->getAxisName (nh, pf), centBin , 0 , centBin , qAxis->GetNbins (), qAxis->GetXmin (), qAxis->GetXmax ()));
8396 th2 = reinterpret_cast <TH2D*>(tar->At (tar->GetEntries () - 1 ));
8497 }
8598 th2->Fill (centrality, qn);
8699};
100+ void FFitWeights::fillPt (float centrality, float pt, bool first)
101+ {
102+ TObjArray* tar{nullptr };
103+ tar = fW_data ;
104+ if (!tar)
105+ return ;
106+ 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);
113+ }
114+ else {
115+ auto th2 = reinterpret_cast <TH2D*>(tar->FindObject (" hPtWeight" ));
116+ if (!th2) {
117+ tar->Add (new TH2D (" hPtWeight" , " " , centBin, 0 , centBin, ptBin, ptAxis->GetXmin (), ptAxis->GetXmax ()));
118+ th2 = reinterpret_cast <TH2D*>(tar->At (tar->GetEntries () - 1 ));
119+ }
120+ th2->Fill (centrality, pt);
121+ }
122+ };
123+ float FFitWeights::getPtMult (float centrality)
124+ {
125+ TObjArray* tar{nullptr };
126+ tar = fW_data ;
127+ if (!tar)
128+ return -1 ;
129+
130+ auto tp = reinterpret_cast <TProfile*>(tar->FindObject (" pMeanPt" ));
131+ if (!tp) {
132+ return -1 ;
133+ }
134+ return tp->GetBinContent (tp->FindBin (centrality));
135+ };
87136
88137Long64_t FFitWeights::Merge (TCollection* collist)
89138{
@@ -93,18 +142,19 @@ Long64_t FFitWeights::Merge(TCollection* collist)
93142 fW_data ->SetName (" FFitWeights_Data" );
94143 fW_data ->SetOwner (kTRUE );
95144 }
96- FFitWeights* l_w = 0 ;
97- TIter all_w (collist);
98- while ((l_w = (reinterpret_cast <FFitWeights*>(all_w ())))) {
99- addArray (fW_data , l_w ->getDataArray ());
145+ FFitWeights* lW = 0 ;
146+ TIter allW (collist);
147+ while ((lW = (reinterpret_cast <FFitWeights*>(allW ())))) {
148+ addArray (fW_data , lW ->getDataArray ());
100149 nmerged++;
101150 }
102151 return nmerged;
103152};
104153void FFitWeights::addArray (TObjArray* targ, TObjArray* sour)
105154{
106155 if (!sour) {
107- printf (" Source array does not exist!\n " );
156+ // printf("Source array does not exist!\n");
157+ // LOGF(info, "FFitWeights source array does not exist!");
108158 return ;
109159 }
110160 for (int i = 0 ; i < sour->GetEntries (); i++) {
@@ -120,6 +170,34 @@ void FFitWeights::addArray(TObjArray* targ, TObjArray* sour)
120170 }
121171};
122172
173+ void FFitWeights::mptSel ()
174+ {
175+ TObjArray* tar{nullptr };
176+ tar = fW_data ;
177+ if (!tar)
178+ return ;
179+
180+ TH2D* th2 = reinterpret_cast <TH2D*>(tar->FindObject (" hPtWeight" ));
181+ if (!th2) {
182+ return ;
183+ }
184+
185+ TH1D* tmp{nullptr };
186+ TGraph* tmpgr{nullptr };
187+ for (int iSP{0 }; iSP < NumberSp; iSP++) {
188+ tmp = th2->ProjectionY (Form (" mpt_%i_%i" , iSP, iSP + 1 ), iSP + 1 , iSP + 1 );
189+ std::vector<double > xq (nResolution);
190+ std::vector<double > yq (nResolution);
191+ for (int i{0 }; i < nResolution; i++)
192+ xq[i] = static_cast <double >(i + 1 ) / static_cast <double >(nResolution);
193+ tmp->GetQuantiles (nResolution, yq.data (), xq.data ());
194+ tmpgr = new TGraph (nResolution, yq.data (), xq.data ());
195+ tmpgr->SetName (Form (" sp_mpt_%i" , iSP));
196+ fW_data ->Add (tmpgr);
197+ }
198+
199+ }
200+
123201void FFitWeights::qSelection (const std::vector<int >& nhv, const std::vector<std::string>& stv) /* only execute OFFLINE */
124202{
125203 TObjArray* tar{nullptr };
@@ -132,14 +210,15 @@ void FFitWeights::qSelection(const std::vector<int>& nhv, const std::vector<std:
132210 for (const auto & nh : nhv) {
133211 TH2D* th2{reinterpret_cast <TH2D*>(tar->FindObject (this ->getQName (nh, pf.c_str ())))};
134212 if (!th2) {
135- printf (" qh not found!\n " );
213+ // printf("qh not found!\n");
214+ // LOGF(info, "FFitWeights qh not found!");
136215 return ;
137216 }
138217
139218 TH1D* tmp{nullptr };
140219 TGraph* tmpgr{nullptr };
141220 // TSpline3* spline = nullptr;
142- for (int iSP{0 }; iSP < 90 ; iSP++) {
221+ for (int iSP{0 }; iSP < NumberSp ; iSP++) {
143222 tmp = th2->ProjectionY (Form (" q%i_%i_%i" , nh, iSP, iSP + 1 ), iSP + 1 , iSP + 1 );
144223 std::vector<double > xq (nResolution);
145224 std::vector<double > yq (nResolution);
@@ -161,11 +240,12 @@ float FFitWeights::eval(float centr, const float& dqn, const int nh, const char*
161240 TObjArray* tar{nullptr };
162241
163242 tar = fW_data ;
164- if (!tar)
243+ if (!tar) {
165244 return -1 ;
245+ }
166246
167247 int isp{static_cast <int >(centr)};
168- if (isp < 0 || isp > 90 ) {
248+ if (isp < 0 || isp > NumberSp ) {
169249 return -1 ;
170250 }
171251
@@ -175,10 +255,36 @@ float FFitWeights::eval(float centr, const float& dqn, const int nh, const char*
175255 return -1 ;
176256 }
177257
178- float qn_val {static_cast <float >(100 . * spline->Eval (dqn))};
179- if (qn_val < 0 || qn_val > 100.05 ) {
258+ float qnVal {static_cast <float >(100 . * spline->Eval (dqn))};
259+ if (qnVal < 0 || qnVal > MaxTol ) {
180260 return -1 ;
181261 }
182262
183- return qn_val ;
263+ return qnVal ;
184264};
265+
266+ float FFitWeights::evalPt (float centr, const float & mpt)
267+ {
268+ TObjArray* tar{nullptr };
269+ tar = fW_data ;
270+ if (!tar) {
271+ return -1 ;
272+ }
273+
274+ int isp{static_cast <int >(centr)};
275+ if (isp < 0 || isp > NumberSp) {
276+ return -1 ;
277+ }
278+
279+ TGraph* spline{nullptr };
280+ spline = reinterpret_cast <TGraph*>(tar->FindObject (Form (" sp_mpt_%i" , isp)));
281+ if (!spline) {
282+ return -1 ;
283+ }
284+ float ptVal{static_cast <float >(100 . * spline->Eval (mpt))};
285+ if (ptVal < 0 || ptVal > MaxTol) {
286+ return -1 ;
287+ }
288+ return ptVal;
289+ };
290+
0 commit comments