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>
2425#include < TSpline.h>
@@ -35,25 +36,35 @@ ClassImp(FFitWeights)
3536
3637 FFitWeights::FFitWeights() : TNamed(" " , " " ),
3738 fW_data{nullptr },
38- CentBin{100 },
39+ ptProfCent{nullptr },
40+ h2ptCent{nullptr },
41+ centBin{100 },
3942 qAxis{nullptr },
4043 nResolution{3000 },
44+ ptBin{100 },
45+ ptAxis{nullptr },
4146 qnTYPE{0 }
4247{
4348}
4449
4550FFitWeights::FFitWeights (const char * name) : TNamed(name, name),
4651 fW_data{nullptr },
47- CentBin{100 },
52+ ptProfCent{nullptr },
53+ h2ptCent{nullptr },
54+ centBin{100 },
4855 qAxis{nullptr },
4956 nResolution{3000 },
57+ ptBin{100 },
58+ ptAxis{nullptr },
5059 qnTYPE{0 } {}
5160
5261FFitWeights::~FFitWeights ()
5362{
5463 delete fW_data ;
5564 if (qAxis)
5665 delete qAxis;
66+ if (ptAxis)
67+ delete ptAxis;
5768};
5869
5970void FFitWeights::init ()
@@ -65,8 +76,16 @@ void FFitWeights::init()
6576 if (!qAxis)
6677 this ->setBinAxis (500 , 0 , 25 );
6778 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 ()));
79+ 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 ()));
6980 }
81+
82+ if (!ptAxis)
83+ this ->setPtAxis (3000 , -3 , 3 );
84+ fW_data ->Add (new TProfile (" pMeanPt" , " " , centBin, 0 , centBin));
85+ 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" ));
7089};
7190
7291void FFitWeights::fillWeights (float centrality, float qn, int nh, const char * pf)
@@ -79,12 +98,28 @@ void FFitWeights::fillWeights(float centrality, float qn, int nh, const char* pf
7998
8099 TH2D* th2 = reinterpret_cast <TH2D*>(tar->FindObject (this ->getQName (nh, pf)));
81100 if (!th2) {
82- tar->Add (new TH2D (this ->getQName (nh, pf), this ->getAxisName (nh, pf), CentBin , 0 , CentBin , qAxis->GetNbins (), qAxis->GetXmin (), qAxis->GetXmax ()));
101+ tar->Add (new TH2D (this ->getQName (nh, pf), this ->getAxisName (nh, pf), centBin , 0 , centBin , qAxis->GetNbins (), qAxis->GetXmin (), qAxis->GetXmax ()));
83102 th2 = reinterpret_cast <TH2D*>(tar->At (tar->GetEntries () - 1 ));
84103 }
85104 th2->Fill (centrality, qn);
86105};
87106
107+ void FFitWeights::fillPt (float centrality, float pt, bool first)
108+ {
109+ if (first) {
110+ ptProfCent->Fill (centrality, pt);
111+ } else {
112+ h2ptCent->Fill (centrality, pt);
113+ }
114+ };
115+ float FFitWeights::getPtMult (float centrality)
116+ {
117+ if (!ptProfCent) {
118+ ptProfCent = reinterpret_cast <TProfile*>(fW_data ->FindObject (" pMeanPt" ));
119+ }
120+ return ptProfCent->GetBinContent (ptProfCent->FindBin (centrality));
121+ };
122+
88123Long64_t FFitWeights::Merge (TCollection* collist)
89124{
90125 Long64_t nmerged = 0 ;
@@ -93,32 +128,63 @@ Long64_t FFitWeights::Merge(TCollection* collist)
93128 fW_data ->SetName (" FFitWeights_Data" );
94129 fW_data ->SetOwner (kTRUE );
95130 }
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 ());
131+ FFitWeights* lW = 0 ;
132+ TIter allW (collist);
133+ while ((lW = (reinterpret_cast <FFitWeights*>(allW ())))) {
134+ addArray (fW_data , lW ->getDataArray ());
100135 nmerged++;
101136 }
102137 return nmerged;
103138};
104139void FFitWeights::addArray (TObjArray* targ, TObjArray* sour)
105140{
106- if (!sour) {
107- printf (" Source array does not exist!\n " );
141+ if (!sour)
108142 return ;
109- }
143+
110144 for (int i = 0 ; i < sour->GetEntries (); i++) {
111- TH2D* sourh = reinterpret_cast <TH2D*>(sour->At (i));
112- TH2D* targh = reinterpret_cast <TH2D*>(targ->FindObject (sourh->GetName ()));
113- if (!targh) {
114- targh = reinterpret_cast <TH2D*>(sourh->Clone (sourh->GetName ()));
115- targh->SetDirectory (0 );
116- targ->Add (targh);
117- } else {
118- 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);
119158 }
120159 }
121- };
160+ }
161+
162+ void FFitWeights::mptSel ()
163+ {
164+ TObjArray* tar{nullptr };
165+ tar = fW_data ;
166+ if (!tar)
167+ return ;
168+
169+ TH2D* th2 = reinterpret_cast <TH2D*>(tar->FindObject (" hPtWeight" ));
170+ if (!th2) {
171+ return ;
172+ }
173+
174+ TH1D* tmp{nullptr };
175+ TGraph* tmpgr{nullptr };
176+ for (int iSP{0 }; iSP < NumberSp; iSP++) {
177+ tmp = th2->ProjectionY (Form (" mpt_%i_%i" , iSP, iSP + 1 ), iSP + 1 , iSP + 1 );
178+ std::vector<double > xq (nResolution);
179+ std::vector<double > yq (nResolution);
180+ for (int i{0 }; i < nResolution; i++)
181+ xq[i] = static_cast <double >(i + 1 ) / static_cast <double >(nResolution);
182+ tmp->GetQuantiles (nResolution, yq.data (), xq.data ());
183+ tmpgr = new TGraph (nResolution, yq.data (), xq.data ());
184+ tmpgr->SetName (Form (" sp_mpt_%i" , iSP));
185+ fW_data ->Add (tmpgr);
186+ }
187+ }
122188
123189void FFitWeights::qSelection (const std::vector<int >& nhv, const std::vector<std::string>& stv) /* only execute OFFLINE */
124190{
@@ -132,14 +198,14 @@ void FFitWeights::qSelection(const std::vector<int>& nhv, const std::vector<std:
132198 for (const auto & nh : nhv) {
133199 TH2D* th2{reinterpret_cast <TH2D*>(tar->FindObject (this ->getQName (nh, pf.c_str ())))};
134200 if (!th2) {
135- printf ( " qh not found!\n " );
201+ LOGF (info, " FFitWeights qh not found!" );
136202 return ;
137203 }
138204
139205 TH1D* tmp{nullptr };
140206 TGraph* tmpgr{nullptr };
141207 // TSpline3* spline = nullptr;
142- for (int iSP{0 }; iSP < 90 ; iSP++) {
208+ for (int iSP{0 }; iSP < NumberSp ; iSP++) {
143209 tmp = th2->ProjectionY (Form (" q%i_%i_%i" , nh, iSP, iSP + 1 ), iSP + 1 , iSP + 1 );
144210 std::vector<double > xq (nResolution);
145211 std::vector<double > yq (nResolution);
@@ -148,37 +214,36 @@ void FFitWeights::qSelection(const std::vector<int>& nhv, const std::vector<std:
148214 tmp->GetQuantiles (nResolution, yq.data (), xq.data ());
149215 tmpgr = new TGraph (nResolution, yq.data (), xq.data ());
150216 tmpgr->SetName (Form (" sp_q%i%s_%i" , nh, pf.c_str (), iSP));
151- // spline = new TSpline3(Form("sp_q%i%s_%i", nh, pf.c_str(), iSP), tmpgr);
152- // spline->SetName(Form("sp_q%i%s_%i", nh, pf.c_str(), iSP));
153217 fW_data ->Add (tmpgr);
154218 }
155219 }
156220 }
157221};
158-
159- 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)
160223{
161- TObjArray* tar{nullptr };
162-
163- tar = fW_data ;
164- if (!tar)
224+ if (!fW_data ) {
165225 return -1 ;
166-
167- int isp{ static_cast <int >(centr)} ;
168- if (isp < 0 || isp > 90 ) {
226+ }
227+ int isp = static_cast <int >(centr);
228+ if (isp < 0 || isp > NumberSp ) {
169229 return -1 ;
170230 }
171231
172- TGraph* spline{nullptr };
173- 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)));
174233 if (!spline) {
175234 return -1 ;
176235 }
177236
178- float qn_val{static_cast <float >(100 . * spline->Eval (dqn))};
179- if (qn_val < 0 || qn_val > 100.05 ) {
180- return -1 ;
181- }
237+ float perc = 100 .f * spline->Eval (val);
238+ return (perc < 0 || perc > MaxTol) ? -1 : perc;
239+ };
182240
183- return qn_val;
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));
244+ };
245+
246+ float FFitWeights::evalPt (float centr, const float & mpt)
247+ {
248+ return internalEval (centr, mpt, " sp_mpt_%i" );
184249};
0 commit comments