5252
5353using namespace rapidjson ;
5454
55- constexpr int UndefValueInt {-999 };
56-
5755void runMassFitter (const std ::string & configFileName = "config_massfitter.json" );
5856
5957TFile * openFileWithNullptrCheck (const std ::string & fileName , const std ::string & option = "read" );
@@ -88,21 +86,21 @@ void runMassFitter(const std::string& configFileName)
8886 }
8987
9088 Document config ;
91- char readBuffer [ 65536 ] ;
92- FileReadStream is (configFile , readBuffer , sizeof ( readBuffer ));
89+ std :: array < char , 65536 > readBuffer {} ;
90+ FileReadStream is (configFile , readBuffer . data (), readBuffer . size ( ));
9391 config .ParseStream (is );
9492 fclose (configFile );
9593
9694 if (config .HasParseError ()) {
9795 throw std ::runtime_error ("ERROR: Parsing the configuration json file failed. Check the config for correct formatting" );
9896 }
9997
100- bool const isMc = readJsonField < bool > (config , "IsMC" );
101- bool const writeSignalPar = readJsonField < bool > (config , "WriteSignalPar" , true);
102- std :: string const particleName = readJsonField < std ::string > (config , "Particle" );
103- std :: string const collisionSystem = readJsonField < std ::string > (config , "CollisionSystem" , "" );
104- std :: string const inputFileName = readJsonField < std ::string > (config , "InFileName" );
105- std :: string const reflFileName = readJsonField < std ::string > (config , "ReflFileName" , "" );
98+ auto const isMc = readJsonField < bool > (config , "IsMC" );
99+ auto const writeSignalPar = readJsonField < bool > (config , "WriteSignalPar" , true);
100+ auto const particleName = readJsonField < std ::string > (config , "Particle" );
101+ auto const collisionSystem = readJsonField < std ::string > (config , "CollisionSystem" , "" );
102+ auto const inputFileName = readJsonField < std ::string > (config , "InFileName" );
103+ auto const reflFileName = readJsonField < std ::string > (config , "ReflFileName" , "" );
106104 TString outputFileName = readJsonField < std ::string > (config , "OutFileName" , "mInvFit.root" );
107105
108106 std ::vector < std ::string > inputHistoName ;
@@ -149,23 +147,23 @@ void runMassFitter(const std::string& configFileName)
149147 readJsonVector (fdSecPeakHistoName , config , "FDSecPeakHistoName" );
150148 readJsonVector (signalSecPeakHistoName , config , "SignalSecPeakHistoName" );
151149
152- const bool fixMean = readJsonField < bool > (config , "FixMean" , false);
153- const std :: string meanFile = readJsonField < std ::string > (config , "MeanFile" , "" );
150+ const auto fixMean = readJsonField < bool > (config , "FixMean" , false);
151+ const auto meanFile = readJsonField < std ::string > (config , "MeanFile" , "" );
154152 readJsonVectorFlexible (fixMeanManual , config , nHistograms , "FixMeanManual" );
155153
156- const bool fixSigma = readJsonField < bool > (config , "FixSigma" , false);
157- const std :: string sigmaFile = readJsonField < std ::string > (config , "SigmaFile" , "" );
154+ const auto fixSigma = readJsonField < bool > (config , "FixSigma" , false);
155+ const auto sigmaFile = readJsonField < std ::string > (config , "SigmaFile" , "" );
158156 readJsonVectorFlexible (fixSigmaManual , config , nHistograms , "FixSigmaManual" );
159157
160- const bool fixSecondSigma = readJsonField < bool > (config , "FixSecondSigma" , false);
161- const std :: string secondSigmaFile = readJsonField < std ::string > (config , "SecondSigmaFile" , "" );
158+ const auto fixSecondSigma = readJsonField < bool > (config , "FixSecondSigma" , false);
159+ const auto secondSigmaFile = readJsonField < std ::string > (config , "SecondSigmaFile" , "" );
162160 readJsonVectorFlexible (fixSecondSigmaManual , config , nHistograms , "FixSecondSigmaManual" );
163161
164- const bool fixFracDoubleGaus = readJsonField < bool > (config , "FixFracDoubleGaus" , false);
165- const std :: string fracDoubleGausFile = readJsonField < std ::string > (config , "FracDoubleGausFile" , "" );
162+ const auto fixFracDoubleGaus = readJsonField < bool > (config , "FixFracDoubleGaus" , false);
163+ const auto fracDoubleGausFile = readJsonField < std ::string > (config , "FracDoubleGausFile" , "" );
166164 readJsonVectorFlexible (fixFracDoubleGausManual , config , nHistograms , "FixFracDoubleGausManual" );
167165
168- const bool fixDscbTailParams = readJsonField < bool > (config , "FixDscbTailParams" , false);
166+ const auto fixDscbTailParams = readJsonField < bool > (config , "FixDscbTailParams" , false);
169167
170168 const TString sliceVarName = readJsonField < std ::string > (config , "SliceVarName" );
171169 const TString sliceVarUnit = readJsonField < std ::string > (config , "SliceVarUnit" );
@@ -178,18 +176,18 @@ void runMassFitter(const std::string& configFileName)
178176
179177 readJsonVectorFlexible (nRebin , config , nHistograms , "Rebin" , true);
180178
181- bool const includeSecPeak = readJsonField < bool > (config , "InclSecPeak" , false);
182- bool const useLikelihood = readJsonField < bool > (config , "UseLikelihood" );
179+ auto const includeSecPeak = readJsonField < bool > (config , "InclSecPeak" , false);
180+ auto const useLikelihood = readJsonField < bool > (config , "UseLikelihood" );
183181
184182 readJsonVectorFlexible (bkgFunc , config , nHistograms , "BkgFunc" , true);
185183 readJsonVectorFlexible (sgnFunc , config , nHistograms , "SgnFunc" , true);
186184
187- const bool enableRefl = readJsonField < bool > (config , "EnableRefl" , false);
188- const bool drawBgPrefit = readJsonField < bool > (config , "DrawBgPrefit" , true);
189- const bool highlightPeakRegion = readJsonField < bool > (config , "HighlightPeakRegion" , true);
190- const int randomSeed = readJsonField < int > (config , "RandomSeed" , -1 );
191- const double nSigmaForSideband = readJsonField < double > (config , "NSigmaForSideband" , 3. );
192- const double nSigmaForSignal = readJsonField < double > (config , "NSigmaForSignal" , 3. );
185+ const auto enableRefl = readJsonField < bool > (config , "EnableRefl" , false);
186+ const auto drawBgPrefit = readJsonField < bool > (config , "DrawBgPrefit" , true);
187+ const auto highlightPeakRegion = readJsonField < bool > (config , "HighlightPeakRegion" , true);
188+ const auto randomSeed = readJsonField < int > (config , "RandomSeed" , -1 );
189+ const auto nSigmaForSideband = readJsonField < double > (config , "NSigmaForSideband" , 3. );
190+ const auto nSigmaForSignal = readJsonField < double > (config , "NSigmaForSignal" , 3. );
193191
194192 readJsonVector (dscbAlphaLInitial , config , "DscbAlphaLInitial" );
195193 readJsonVector (dscbAlphaLLower , config , "DscbAlphaLLower" );
@@ -305,13 +303,13 @@ void runMassFitter(const std::string& configFileName)
305303 {"LcToPK0s" , {"pK^{0}_{s}" , "Lambda_c+" , "#Lambda_{c}^{+}" , "pK^{0}_{s}" }},
306304 {"Dstar" , {"D^{0}pi^{+}" , "D*+" , "D^{*+}" , "D^{0}#pi^{+}" }},
307305 {"XicToXiPiPi" , {"#Xi#pi#pi" , "Xi_c+" , "#Xi_{c}^{+}" , "#Xi^{-}#pi^{+}#pi^{+}" }}};
308- if (particles .find (particleName . c_str () ) == particles .end ()) {
306+ if (particles .find (particleName ) == particles .end ()) {
309307 throw std ::runtime_error ("ERROR: only Dplus, D0, Ds, LcToPKPi, LcToPK0s, Dstar and XicToXiPiPi particles supported! Exit" );
310308 }
311309 const auto& particle = particles [particleName .c_str ()];
312310 const std ::string massAxisTitle = "#it{M}(" + particle .decayProducts + ") (GeV/#it{c}^{2})" ;
313311 const double massPDG = TDatabasePDG ::Instance ()-> GetParticle (particle .pdgName .c_str ())-> Mass ();
314- const std ::vector < std ::string > plotLabels = {( particle .decayFormulaLhs + " #rightarrow " + particle .decayFormulaRhs + " + c.c." ). c_str () , collisionSystem };
312+ const std ::vector < std ::string > plotLabels = {particle .decayFormulaLhs + " #rightarrow " + particle .decayFormulaRhs + " + c.c." , collisionSystem };
315313
316314 // load inv-mass histograms
317315 auto* inputFile = openFileWithNullptrCheck (inputFileName );
@@ -395,14 +393,14 @@ void runMassFitter(const std::string& configFileName)
395393 NFitResultsToSave
396394 };
397395 auto* hFitConfig = new TH2F ("hFitConfig" , "Fit Configurations" , NConfigsToSave - 1 , 0 , NConfigsToSave - 1 , nHistograms , sliceVarLimits .data ());
398- const char * hFitConfigXLabel [ NConfigsToSave - 1 ] = {"mass min" , "mass max" , "rebin num" , "fix sigma" , "bkg func" , "sgn func" , "rnd seed" };
396+ constexpr std :: array < const char * , NConfigsToSave - 1 > HFitConfigXLabel = {"mass min" , "mass max" , "rebin num" , "fix sigma" , "bkg func" , "sgn func" , "rnd seed" };
399397 auto* hFitResult = new TH2F ("hFitResult" , "Fit Result" , NFitResultsToSave - 1 , 0 , NFitResultsToSave - 1 , nHistograms , sliceVarLimits .data ());
400- const char * hFitResultXLabel [ NFitResultsToSave - 1 ] = {"status" , "cov qual" , "edm" , "minNLL" , "N Sig GCC" };
398+ constexpr std :: array < const char * , NFitResultsToSave - 1 > HFitResultXLabel = {"status" , "cov qual" , "edm" , "minNLL" , "N Sig GCC" };
401399 for (int i = 0 ; i < NConfigsToSave - 1 ; i ++ ) {
402- hFitConfig -> GetXaxis ()-> SetBinLabel (i + 1 , hFitConfigXLabel [i ]);
400+ hFitConfig -> GetXaxis ()-> SetBinLabel (i + 1 , HFitConfigXLabel [i ]);
403401 }
404402 for (int i = 0 ; i < NFitResultsToSave - 1 ; i ++ ) {
405- hFitResult -> GetXaxis ()-> SetBinLabel (i + 1 , hFitResultXLabel [i ]);
403+ hFitResult -> GetXaxis ()-> SetBinLabel (i + 1 , HFitResultXLabel [i ]);
406404 }
407405 for (const auto& h : {hFitConfig , hFitResult }) {
408406 h -> SetStats (false );
@@ -451,7 +449,7 @@ void runMassFitter(const std::string& configFileName)
451449 TH1 * hSecondSigmaToFix = getHistToFix (fixSecondSigma , fixSecondSigmaManual , secondSigmaFile , "SecSigma" );
452450 TH1 * hFracDoubleGausToFix = getHistToFix (fixFracDoubleGaus , fixFracDoubleGausManual , fracDoubleGausFile , "FracDoubleGaus" );
453451
454- int canvasSize [ 2 ] = {1920 , 1080 };
452+ std :: array < int , 2 > canvasSize = {1920 , 1080 };
455453 if (nHistograms == 1 ) {
456454 canvasSize [0 ] = 500 ;
457455 canvasSize [1 ] = 500 ;
@@ -511,7 +509,7 @@ void runMassFitter(const std::string& configFileName)
511509
512510 double reflOverSgn = 0 ;
513511
514- HFInvMassFitter * massFitter = new HFInvMassFitter (hMass [iSliceVar ], massMin [iSliceVar ], massMax [iSliceVar ], bkgFunc [iSliceVar ], sgnFunc [iSliceVar ], randomSeed );
512+ auto * massFitter = new HFInvMassFitter (hMass [iSliceVar ], massMin [iSliceVar ], massMax [iSliceVar ], bkgFunc [iSliceVar ], sgnFunc [iSliceVar ], randomSeed );
515513 massFitter -> setDrawBgPrefit (drawBgPrefit );
516514 massFitter -> setNumberOfSigmaForSidebands (nSigmaForSideband );
517515 massFitter -> setNumberOfSigmaForSignal (nSigmaForSignal );
@@ -525,27 +523,27 @@ void runMassFitter(const std::string& configFileName)
525523 massFitter -> setUseChi2Fit ();
526524 }
527525
528- auto setFixedValue = [& iSliceVar ](bool const & isFix , std ::vector < double > const & fixManual , const TH1 * histToFix , std :: function < void (double )> setFunc , std ::string const & var ) -> void {
526+ auto setFixedValue = [& iSliceVar , massFitter ](bool const & isFix , std ::vector < double > const & fixManual , const TH1 * histToFix , void ( HFInvMassFitter :: * setter ) (double ), std ::string const & var ) -> void {
529527 if (isFix ) {
530528 if (fixManual .empty () && histToFix == nullptr) {
531529 throw std ::runtime_error ("Histogram to fix " + var + " is null while isFix==true and fixManual is empty" );
532530 }
533531 const auto valueToFix = fixManual .empty () ? histToFix -> GetBinContent (iSliceVar + 1 ) : fixManual [iSliceVar ];
534- setFunc (valueToFix );
532+ ( massFitter -> * setter ) (valueToFix );
535533 printf ("*****************************\n" );
536534 printf ("FIXED %s: %f\n" , var .data (), valueToFix );
537535 printf ("*****************************\n" );
538536 }
539537 };
540538
541- setFixedValue (fixMean , fixMeanManual , hMeanToFix , std :: bind ( & HFInvMassFitter ::setFixGaussianMean , massFitter , std :: placeholders :: _1 ) , "MEAN" );
542- setFixedValue (fixSigma , fixSigmaManual , hSigmaToFix , std :: bind ( & HFInvMassFitter ::setFixGaussianSigma , massFitter , std :: placeholders :: _1 ) , "SIGMA" );
543- setFixedValue (fixSecondSigma , fixSecondSigmaManual , hSecondSigmaToFix , std :: bind ( & HFInvMassFitter ::setFixSecondGaussianSigma , massFitter , std :: placeholders :: _1 ) , "SECOND SIGMA" );
544- setFixedValue (fixFracDoubleGaus , fixFracDoubleGausManual , hFracDoubleGausToFix , std :: bind ( & HFInvMassFitter ::setFixFrac2Gaus , massFitter , std :: placeholders :: _1 ) , "FRAC DOUBLE GAUS" );
545- setFixedValue (fixDscbTailParams , dscbAlphaLInitial , nullptr , std :: bind ( & HFInvMassFitter ::setFixDscbAlphaL , massFitter , std :: placeholders :: _1 ) , "DSCB ALPHA LEFT" );
546- setFixedValue (fixDscbTailParams , dscbAlphaRInitial , nullptr , std :: bind ( & HFInvMassFitter ::setFixDscbAlphaR , massFitter , std :: placeholders :: _1 ) , "DSCB ALPHA RIGHT" );
547- setFixedValue (fixDscbTailParams , dscbNLInitial , nullptr , std :: bind ( & HFInvMassFitter ::setFixDscbNL , massFitter , std :: placeholders :: _1 ) , "DSCB N LEFT" );
548- setFixedValue (fixDscbTailParams , dscbNRInitial , nullptr , std :: bind ( & HFInvMassFitter ::setFixDscbNR , massFitter , std :: placeholders :: _1 ) , "DSCB N RIGHT" );
539+ setFixedValue (fixMean , fixMeanManual , hMeanToFix , & HFInvMassFitter ::setFixGaussianMean , "MEAN" );
540+ setFixedValue (fixSigma , fixSigmaManual , hSigmaToFix , & HFInvMassFitter ::setFixGaussianSigma , "SIGMA" );
541+ setFixedValue (fixSecondSigma , fixSecondSigmaManual , hSecondSigmaToFix , & HFInvMassFitter ::setFixSecondGaussianSigma , "SECOND SIGMA" );
542+ setFixedValue (fixFracDoubleGaus , fixFracDoubleGausManual , hFracDoubleGausToFix , & HFInvMassFitter ::setFixFrac2Gaus , "FRAC DOUBLE GAUS" );
543+ setFixedValue (fixDscbTailParams , dscbAlphaLInitial , nullptr , & HFInvMassFitter ::setFixDscbAlphaL , "DSCB ALPHA LEFT" );
544+ setFixedValue (fixDscbTailParams , dscbAlphaRInitial , nullptr , & HFInvMassFitter ::setFixDscbAlphaR , "DSCB ALPHA RIGHT" );
545+ setFixedValue (fixDscbTailParams , dscbNLInitial , nullptr , & HFInvMassFitter ::setFixDscbNL , "DSCB N LEFT" );
546+ setFixedValue (fixDscbTailParams , dscbNRInitial , nullptr , & HFInvMassFitter ::setFixDscbNR , "DSCB N RIGHT" );
549547
550548 if (!isMc && enableRefl ) {
551549 reflOverSgn = hMassSgn [iSliceVar ]-> Integral (hMassSgn [iSliceVar ]-> FindBin (massMin [iSliceVar ] * 1.0001 ), hMassSgn [iSliceVar ]-> FindBin (massMax [iSliceVar ] * 0.999 ));
@@ -578,7 +576,7 @@ void runMassFitter(const std::string& configFileName)
578576 printf ("Warinig! Exception \"%s\" caught while doing fit of the histogram no. %d. The fitting process will be continued without it.\n" , e .what (), iSliceVar );
579577 }
580578
581- auto drawOnCanvas = [& ](std ::vector < TCanvas * > & canvas , std ::function < void ()> drawer ) {
579+ auto drawOnCanvas = [& ](std ::vector < TCanvas * > & canvas , const std ::function < void ()> & drawer ) {
582580 if (nHistograms > 1 ) {
583581 canvas [iCanvas ]-> cd (iSliceVar - NCanvasesMax * iCanvas + 1 );
584582 } else {
@@ -853,9 +851,8 @@ void readJsonVectorFlexible(std::vector<T>& vec, const Document& config, int nHi
853851 if (!config .HasMember (fieldName .c_str ())) {
854852 if (isRequired ) {
855853 throw std ::runtime_error ("readJsonVectorFlexible(): missing required field " + fieldName );
856- } else {
857- return ;
858854 }
855+ return ;
859856 }
860857 if (config [fieldName .c_str ()].IsArray ()) {
861858 readJsonVector (vec , config , fieldName );
0 commit comments