99// granted to it by virtue of its status as an Intergovernmental Organization
1010// or submit itself to any jurisdiction.
1111
12+ // / \file FlowContainer.cxx
13+ // / \brief Container class to store and calculate multi-particle azimuthal correlations and cumulants
14+ // / \author Emil Gorm Dahlbæk Nielsen <emil.gorm.nielsen@cern.ch>
15+
1216#include " FlowContainer.h"
1317
1418#include " PWGCF/GenericFramework/Core/ProfileSubset.h"
3034#include < Rtypes.h>
3135#include < RtypesCore.h>
3236
33- #include < cstdio>
37+ #include < fstream>
38+ #include < string>
3439#include < vector>
3540
3641ClassImp (FlowContainer);
@@ -73,15 +78,15 @@ void FlowContainer::Initialize(TObjArray* inputList, const o2::framework::AxisSp
7378 if (nMultiBins <= 0 )
7479 nMultiBins = multiBins.size () - 1 ;
7580 if (nMultiBins <= 0 ) {
76- printf ( " Multiplicity axis does not exist" );
81+ LOGF (error, " Multiplicity axis does not exist" );
7782 return ;
7883 }
7984 if (!inputList) {
80- printf ( " Input list not specified\n " );
85+ LOGF (warning, " Input list not specified" );
8186 return ;
8287 }
8388 if (inputList->GetEntries () < 1 ) {
84- printf ( " Input list empty!\n " );
89+ LOGF (warning, " Input list empty!" );
8590 return ;
8691 }
8792 fProf = new TProfile2D (Form (" %s_CorrProfile" , this ->GetName ()), " CorrProfile" , nMultiBins, &multiBins[0 ], inputList->GetEntries (), 0.5 , inputList->GetEntries () + 0.5 );
@@ -101,11 +106,11 @@ void FlowContainer::Initialize(TObjArray* inputList, const o2::framework::AxisSp
101106void FlowContainer::Initialize (TObjArray* inputList, int nMultiBins, double MultiMin, double MultiMax, int nRandom)
102107{
103108 if (!inputList) {
104- printf ( " Input list not specified\n " );
109+ LOGF (warning, " Input list not specified" );
105110 return ;
106111 }
107112 if (inputList->GetEntries () < 1 ) {
108- printf ( " Input list empty!\n " );
113+ LOGF (warning, " Input list empty!" );
109114 return ;
110115 }
111116 fProf = new TProfile2D (Form (" %s_CorrProfile" , this ->GetName ()), " CorrProfile" , nMultiBins, MultiMin, MultiMax, inputList->GetEntries (), 0.5 , inputList->GetEntries () + 0.5 );
@@ -138,7 +143,7 @@ void FlowContainer::SetXAxis(TAxis* inax)
138143 fXAxis = dynamic_cast <TAxis*>(inax->Clone (" pTAxis" ));
139144 bool success = CreateBinsFromAxis (fXAxis );
140145 if (!success)
141- printf ( " Something went wrong setting the x axis!\n " );
146+ LOGF (warning, " Something went wrong setting the x axis!" );
142147}
143148void FlowContainer::SetXAxis ()
144149{
@@ -161,7 +166,7 @@ int FlowContainer::FillProfile(const char* hname, double multi, double corr, dou
161166 return -1 ;
162167 int yin = fProf ->GetYaxis ()->FindBin (hname);
163168 if (!yin) {
164- printf ( " Could not find bin %s\n " , hname);
169+ LOGF (info, " Could not find bin %s\n " , hname);
165170 return -1 ;
166171 }
167172 fProf ->Fill (multi, yin, corr, w);
@@ -176,23 +181,23 @@ void FlowContainer::OverrideProfileErrors(TProfile2D* inpf)
176181 int nBinsX = fProf ->GetNbinsX ();
177182 int nBinsY = fProf ->GetNbinsY ();
178183 if ((inpf->GetNbinsX () != nBinsX) || (inpf->GetNbinsY () != nBinsY)) {
179- printf ( " Number of bins in two profiles do not match, not doing anything\n " );
184+ LOGF (info, " Number of bins in two profiles do not match, not doing anything\n " );
180185 return ;
181186 }
182187 if (!inpf->GetBinSumw2 ()->fArray ) {
183- printf ( " Input profile has no BinSumw2()! Returning\n " );
188+ LOGF (info, " Input profile has no BinSumw2()! Returning\n " );
184189 return ;
185190 }
186191 if (!fProf ->GetBinSumw2 ()->fArray )
187192 fProf ->Sumw2 ();
188193 double * sumw2Prof = fProf ->GetSumw2 ()->fArray ;
189- double * sumw2Targ = inpf->GetSumw2 ()->fArray ;
194+ const double * sumw2Targ = inpf->GetSumw2 ()->fArray ;
190195 double * binsw2Prof = fProf ->GetBinSumw2 ()->fArray ;
191- double * binsw2Targ = inpf->GetBinSumw2 ()->fArray ;
196+ const double * binsw2Targ = inpf->GetBinSumw2 ()->fArray ;
192197 double * farrProf = fProf ->fArray ;
193198 for (int ix = 1 ; ix <= nBinsX; ix++) {
194199 double xval = fProf ->GetXaxis ()->GetBinCenter (ix);
195- printf ( " Processing x-bin %i\n " , ix);
200+ LOGF (info, " Processing x-bin %i\n " , ix);
196201 for (int iy = 1 ; iy <= nBinsY; iy++) {
197202 double yval = fProf ->GetYaxis ()->GetBinCenter (iy);
198203 int binno = fProf ->FindBin (xval, yval);
@@ -244,34 +249,38 @@ Long64_t FlowContainer::Merge(TCollection* collist)
244249
245250void FlowContainer::ReadAndMerge (const char * filelist)
246251{
247- FILE * flist = fopen (filelist, " r" );
248- char str[150 ];
249- int nFiles = 0 ;
250- while (fscanf (flist, " %s\n " , str) == 1 )
251- nFiles++;
252- rewind (flist);
253- if (nFiles == 0 ) {
254- printf (" No files to read!\n " );
252+ if (!filelist) {
253+ LOGF (error, " File list path is null!" );
254+ return ;
255+ }
256+ std::ifstream input (filelist);
257+ if (!input) {
258+ LOGF (error, " Could not open file list %s!" , filelist);
255259 return ;
256260 }
257- for (int i = 0 ; i < nFiles; i++) {
258- auto retVal = fscanf (flist, " %s\n " , str);
259- (void )retVal;
260- TFile* tf = new TFile (str, " READ" );
261- if (tf->IsZombie ()) {
262- printf (" Could not open file %s!\n " , str);
263- tf->Close ();
261+
262+ std::string filename;
263+ bool hasFiles = false ;
264+ while (input >> filename) {
265+ hasFiles = true ;
266+ TFile tf (filename.c_str (), " READ" );
267+ if (tf.IsZombie ()) {
268+ LOGF (info, " Could not open file %s!" , filename.c_str ());
264269 continue ;
265270 }
266- PickAndMerge (tf);
267- tf->Close ();
271+ PickAndMerge (&tf);
272+ }
273+ if (input.bad ()) {
274+ LOGF (error, " Error reading file list %s!" , filelist);
275+ } else if (!hasFiles) {
276+ LOGF (info, " No files to read!" );
268277 }
269278}
270279void FlowContainer::PickAndMerge (TFile* tfi)
271280{
272281 FlowContainer* lfc = dynamic_cast <FlowContainer*>(tfi->Get (this ->GetName ()));
273282 if (!lfc) {
274- printf ( " Could not pick up the %s from %s\n " , this ->GetName (), tfi->GetName ());
283+ LOGF (info, " Could not pick up the %s from %s" , this ->GetName (), tfi->GetName ());
275284 return ;
276285 }
277286 TProfile2D* spro = lfc->GetProfile ();
@@ -313,13 +322,13 @@ bool FlowContainer::OverrideBinsWithZero(int xb1, int yb1, int xb2, int yb2)
313322bool FlowContainer::OverrideMainWithSub (int ind, bool ExcludeChosen)
314323{
315324 if (!fProfRand ) {
316- printf ( " Cannot override main profile with a randomized one. Random profile array does not exist.\n " );
325+ LOGF (info, " Cannot override main profile with a randomized one. Random profile array does not exist." );
317326 return kFALSE ;
318327 }
319328 if (!ExcludeChosen) {
320329 TProfile2D* tarprof = dynamic_cast <TProfile2D*>(fProfRand ->At (ind));
321330 if (!tarprof) {
322- printf ( " Target random histogram does not exist.\n " );
331+ LOGF (info, " Target random histogram does not exist." );
323332 return kFALSE ;
324333 }
325334 TString ts (fProf ->GetName ());
@@ -345,7 +354,7 @@ bool FlowContainer::OverrideMainWithSub(int ind, bool ExcludeChosen)
345354bool FlowContainer::RandomizeProfile (int nSubsets)
346355{
347356 if (!fProfRand ) {
348- printf ( " Cannot randomize profile, random array does not exist.\n " );
357+ LOGF (info, " Cannot randomize profile, random array does not exist." );
349358 return kFALSE ;
350359 }
351360 int l_Subsets = nSubsets ? nSubsets : fProfRand ->GetEntries ();
@@ -393,7 +402,7 @@ TProfile* FlowContainer::GetCorrXXVsMulti(const char* order, int l_pti)
393402 const char * ybinlab = Form (" %s%s%s" , l_name.Data (), order, ptpf);
394403 int ybinno = fProf ->GetYaxis ()->FindBin (ybinlab);
395404 if (ybinno < 0 ) {
396- printf ( " Could not find %s!\n " , ybinlab);
405+ LOGF (info, " Could not find %s!" , ybinlab);
397406 return 0 ;
398407 }
399408 TProfile* rethist = dynamic_cast <TProfile*>(fProf ->ProfileX (" temp_prof" , ybinno, ybinno));
@@ -426,7 +435,6 @@ TH1D* FlowContainer::GetCorrXXVsPt(const char* order, double lminmulti, double l
426435 }
427436 if (lmaxmulti > lminmulti)
428437 maxm = fProf ->GetXaxis ()->FindBin (lmaxmulti - 0.001 );
429- ProfileSubset* rhProfSub = new ProfileSubset (*fProf );
430438 TString l_name (" " );
431439 Ssiz_t l_pos = 0 ;
432440 while (fIDName .Tokenize (l_name, l_pos)) {
@@ -435,20 +443,19 @@ TH1D* FlowContainer::GetCorrXXVsPt(const char* order, double lminmulti, double l
435443 int ybn1 = fProf ->GetYaxis ()->FindBin (ybl1.Data ());
436444 int ybn2 = fProf ->GetYaxis ()->FindBin (ybl2.Data ());
437445 if (fNbinsPt != (ybn2 - ybn1 + 1 )) {
438- printf ( " fNbinsPt is not matching the num of found histograms" );
446+ LOGF (info, " fNbinsPt is not matching the num of found histograms" );
439447 return nullptr ;
440448 }
441- TProfile* profY = rhProfSub->ProfileY (" profY" , minm, maxm);
449+ const TString temporaryTag = Form (" %s_%s_%.3f_%.3f" , fIDName .Data (), order, lminmulti, lmaxmulti);
450+ TProfile* profY = fProf ->ProfileY (Form (" profY_%s" , temporaryTag.Data ()), minm, maxm);
442451 TH1D * histY = ProfToHist (profY);
443- TH1D * hist = new TH1D (" temphist" , " temphist" , fNbinsPt , fbinsPt);
452+ delete profY;
453+ TH1D * hist = new TH1D (Form (" temphist_%s" , temporaryTag.Data ()), " temphist" , fNbinsPt , fbinsPt);
444454 for (int ibin = 1 ; ibin <= hist->GetNbinsX (); ibin++) {
445- TString bLabel = rhProfSub->GetYaxis ()->GetBinLabel (ibin + ybn1 - 1 );
446- hist->GetXaxis ()->SetBinLabel (ibin, bLabel.Data ());
447455 hist->SetBinContent (ibin, histY->GetBinContent (ibin + ybn1 - 1 ));
448456 hist->SetBinError (ibin, histY->GetBinError (ibin + ybn1 - 1 ));
449457 }
450458 delete histY;
451- delete rhProfSub;
452459 return hist;
453460 }
454461 return nullptr ;
@@ -479,7 +486,7 @@ TH1D* FlowContainer::GetHistCorrXXVsPt(const char* order, double lminmulti, doub
479486{
480487 TH1D * rethist = GetCorrXXVsPt (order, lminmulti, lmaxmulti);
481488 if (!rethist) {
482- printf ( " GetCorrXXVsPt return nullptr!" );
489+ LOGF (info, " GetCorrXXVsPt return nullptr!" );
483490 return nullptr ;
484491 }
485492 TProfile* refflow = GetRefFlowProfile (order, lminmulti, lmaxmulti);
@@ -890,23 +897,24 @@ TH1D* FlowContainer::GetVN8VsX(int n, bool onPt, double arg1, double arg2)
890897 }
891898 return rethist;
892899}
900+
893901TH1D * FlowContainer::GetCNN (int n, int c, bool onPt, double arg1, double arg2)
894902{
895- if (c == 8 )
903+ if (c == kEightParticleOrder )
896904 return GetCN8VsX (n, onPt, arg1, arg2);
897- if (c == 6 )
905+ if (c == kSixParticleOrder )
898906 return GetCN6VsX (n, onPt, arg1, arg2);
899- if (c == 4 )
907+ if (c == kFourParticleOrder )
900908 return GetCN4VsX (n, onPt, arg1, arg2);
901909 return GetCN2VsX (n, onPt, arg1, arg2);
902910};
903911TH1D * FlowContainer::GetVNN (int n, int c, bool onPt, double arg1, double arg2)
904912{
905- if (c == 8 )
913+ if (c == kEightParticleOrder )
906914 return GetVN8VsX (n, onPt, arg1, arg2);
907- if (c == 6 )
915+ if (c == kSixParticleOrder )
908916 return GetVN6VsX (n, onPt, arg1, arg2);
909- if (c == 4 )
917+ if (c == kFourParticleOrder )
910918 return GetVN4VsX (n, onPt, arg1, arg2);
911919 return GetVN2VsX (n, onPt, arg1, arg2);
912920};
@@ -1051,12 +1059,14 @@ double FlowContainer::CN6Error(double cor6e, double cor4, double cor4e, double c
10511059{
10521060 if (!fPropagateErrors )
10531061 return 0 ;
1054- double inters[3 ];
1062+
1063+ constexpr int kCN6Terms = 3 ;
1064+ double inters[kCN6Terms ];
10551065 inters[0 ] = cor6e;
10561066 inters[1 ] = -9 * cor2 * cor4e;
10571067 inters[2 ] = (-9 * cor4 + 36 * cor2 * cor2) * cor2e;
10581068 double sum = 0 ;
1059- for (int i = 0 ; i < 3 ; i++)
1069+ for (int i = 0 ; i < kCN6Terms ; i++)
10601070 sum += (inters[i] * inters[i]);
10611071 return TMath::Sqrt (sum);
10621072};
@@ -1070,14 +1080,15 @@ double FlowContainer::DN6Error(double d6e, double d4, double d4e, double d2,
10701080{
10711081 if (!fPropagateErrors )
10721082 return 0 ;
1073- double inters[5 ];
1083+ constexpr int kDN6Terms = 5 ;
1084+ double inters[kDN6Terms ];
10741085 inters[0 ] = d6e;
10751086 inters[1 ] = -6 * c2 * d4e;
10761087 inters[2 ] = (-3 * c4 + 12 * c2 * c2) * d2e;
10771088 inters[3 ] = -3 * d2 * c4e;
10781089 inters[4 ] = (-6 * d4 + 24 * d2 * c2) * c2e;
10791090 double sum = 0 ;
1080- for (int i = 0 ; i < 5 ; i++)
1091+ for (int i = 0 ; i < kDN6Terms ; i++)
10811092 sum += (inters[i] * inters[i]);
10821093 return TMath::Sqrt (sum);
10831094};
@@ -1126,13 +1137,14 @@ double FlowContainer::CN8Error(double cor8e, double cor6, double cor6e,
11261137{
11271138 if (!fPropagateErrors )
11281139 return 0 ;
1129- double parts[4 ];
1140+ constexpr int kCN8Terms = 4 ;
1141+ double parts[kCN8Terms ];
11301142 parts[0 ] = cor8e;
11311143 parts[1 ] = -16 * cor2 * cor6e;
11321144 parts[2 ] = (-36 * cor4 + 144 * cor2 * cor2) * cor4e;
11331145 parts[3 ] = (-16 * cor6 + 288 * cor4 * cor2 + 576 * cor2 * cor2 * cor2) * cor2e;
11341146 double retval = 0 ;
1135- for (int i = 0 ; i < 4 ; i++)
1147+ for (int i = 0 ; i < kCN8Terms ; i++)
11361148 retval += TMath::Power (parts[i], 2 );
11371149 return TMath::Sqrt (retval);
11381150};
@@ -1147,7 +1159,8 @@ double FlowContainer::DN8Error(double d8e, double d6, double d6e, double d4,
11471159{
11481160 if (!fPropagateErrors )
11491161 return 0 ;
1150- double parts[7 ];
1162+ constexpr int kDN8Terms = 7 ;
1163+ double parts[kDN8Terms ];
11511164 parts[0 ] = d8e; // d/d8'
11521165 parts[1 ] = -12 * c2 * d6e; // d/d6'
11531166 parts[2 ] = -4 * d2 * c6e; // d/d6
@@ -1156,7 +1169,7 @@ double FlowContainer::DN8Error(double d8e, double d6, double d6e, double d4,
11561169 parts[5 ] = (-4 * c6 + 72 * c4 * c2 - 144 * c2 * c2 * c2) * d2e;
11571170 parts[6 ] = (-12 * d6 + 144 * d4 * c2 + 72 * c4 * d2 - 432 * d2 * c2 * c2) * c2e;
11581171 double retval = 0 ;
1159- for (int i = 0 ; i < 7 ; i++)
1172+ for (int i = 0 ; i < kDN8Terms ; i++)
11601173 retval += TMath::Power (parts[i], 2 );
11611174 return TMath::Sqrt (retval);
11621175};
@@ -1197,26 +1210,6 @@ void FlowContainer::SetPtRebin(int nbins, double* binedges)
11971210{
11981211 fPtRebin = nbins;
11991212 fPtRebinEdges = binedges;
1200- return ;
1201- int fPtRebin = 0 ;
1202- // double *lPtRebinEdges=binedges;
1203- if (!fbinsPt)
1204- SetXAxis ();
1205- for (int i = 0 ; i < nbins; i++)
1206- if (binedges[i] < fbinsPt[0 ] || binedges[i] > fbinsPt[fNbinsPt - 1 ])
1207- continue ;
1208- else
1209- fPtRebin ++;
1210- if (fPtRebinEdges )
1211- delete[] fPtRebinEdges ;
1212- fPtRebinEdges = new double [fPtRebin ];
1213- fPtRebin = 0 ;
1214- for (int i = 0 ; i < nbins; i++)
1215- if (binedges[i] < fbinsPt[0 ] || binedges[i] > fbinsPt[fNbinsPt ])
1216- continue ;
1217- else
1218- fPtRebinEdges [fPtRebin ++] = binedges[i];
1219- // fPtRebin--;
12201213}
12211214void FlowContainer::SetMultiRebin (int nbins, double * binedges)
12221215{
0 commit comments