1919#include " TMath.h"
2020#include " snprintf.h"
2121
22+ #include < sstream>
23+ #include < string>
24+
2225extern void Yields (Int_t &, Double_t *, Double_t &f, Double_t *x, Int_t iflag);
2326
2427ClassImp (TSPlot);
@@ -286,11 +289,7 @@ The results above can be obtained by running the tutorial TestSPlot.C
286289// //////////////////////////////////////////////////////////////////////////////
287290// / default constructor (used by I/O only)
288291
289- TSPlot::TSPlot () :
290- fTree(nullptr ),
291- fTreename(nullptr ),
292- fVarexp(nullptr ),
293- fSelection(nullptr )
292+ TSPlot::TSPlot ()
294293{
295294 fNx = 0 ;
296295 fNy =0 ;
@@ -307,11 +306,7 @@ TSPlot::TSPlot() :
307306// / - ns : number of species
308307// / - tree: input data
309308
310- TSPlot::TSPlot (Int_t nx, Int_t ny, Int_t ne, Int_t ns, TTree *tree) :
311- fTreename(nullptr ),
312- fVarexp(nullptr ),
313- fSelection(nullptr )
314-
309+ TSPlot::TSPlot (Int_t nx, Int_t ny, Int_t ne, Int_t ns, TTree *tree)
315310{
316311 fNx = nx;
317312 fNy =ny;
@@ -530,10 +525,9 @@ void TSPlot::FillXvarHists(Int_t nbins)
530525 }
531526
532527 // make the histograms
533- char name[12 ];
534528 for (i=0 ; i<fNx ; i++){
535- snprintf ( name, sizeof (name), " x%d " , i);
536- TH1D *h = new TH1D (name, name, nbins, fMinmax (0 , i), fMinmax (1 , i));
529+ std::string name = " x " + std::to_string ( i);
530+ TH1D *h = new TH1D (name. c_str () , name. c_str () , nbins, fMinmax (0 , i), fMinmax (1 , i));
537531 for (j=0 ; j<fNevents ; j++)
538532 h->Fill (fXvar (j, i));
539533 fXvarHists .Add (h);
@@ -587,10 +581,9 @@ void TSPlot::FillYvarHists(Int_t nbins)
587581 }
588582
589583 // make the histograms
590- char name[12 ];
591584 for (i=0 ; i<fNy ; i++){
592- snprintf ( name, sizeof (name), " y%d " , i);
593- TH1D *h=new TH1D (name, name, nbins, fMinmax (0 , fNx +i), fMinmax (1 , fNx +i));
585+ std::string name = " y " + std::to_string ( i);
586+ TH1D *h=new TH1D (name. c_str () , name. c_str () , nbins, fMinmax (0 , fNx +i), fMinmax (1 , fNx +i));
594587 for (j=0 ; j<fNevents ; j++)
595588 h->Fill (fYvar (j, i));
596589 fYvarHists .Add (h);
@@ -639,12 +632,13 @@ void TSPlot::FillYpdfHists(Int_t nbins)
639632 return ;
640633 }
641634
642- char name[34 ];
643635 for (ispecies=0 ; ispecies<fNSpecies ; ispecies++){
644636 for (i=0 ; i<fNy ; i++){
645- snprintf (name,sizeof (name), " pdf_species%d_y%d" , ispecies, i);
637+ std::stringstream nameStream;
638+ nameStream << " pdf_species" << ispecies << " _y" << i;
639+ std::string name = nameStream.str ();
646640 // TH1D *h = new TH1D(name, name, nbins, ypdfmin[ispecies*fNy+i], ypdfmax[ispecies*fNy+i]);
647- TH1D *h = new TH1D (name, name, nbins, fMinmax (0 , fNx +fNy +ispecies*fNy +i), fMinmax (1 , fNx +fNy +ispecies*fNy +i));
641+ TH1D *h = new TH1D (name. c_str () , name. c_str () , nbins, fMinmax (0 , fNx +fNy +ispecies*fNy +i), fMinmax (1 , fNx +fNy +ispecies*fNy +i));
648642 for (j=0 ; j<fNevents ; j++)
649643 h->Fill (fYpdf (j, ispecies*fNy +i));
650644 fYpdfHists .Add (h);
@@ -702,13 +696,13 @@ void TSPlot::FillSWeightsHists(Int_t nbins)
702696 return ;
703697 }
704698
705- char name[30 ];
706-
707699 // Fill histograms of x-variables weighted with sWeights
708700 for (Int_t ivar=0 ; ivar<fNx ; ivar++){
709701 for (Int_t ispecies=0 ; ispecies<fNSpecies ; ispecies++){
710- snprintf (name,30 , " x%d_species%d" , ivar, ispecies);
711- TH1D *h = new TH1D (name, name, nbins, fMinmax (0 , ivar), fMinmax (1 , ivar));
702+ std::stringstream nameStream;
703+ nameStream << " x" << ivar << " _species" << ispecies;
704+ std::string name = nameStream.str ();
705+ TH1D *h = new TH1D (name.c_str (), name.c_str (), nbins, fMinmax (0 , ivar), fMinmax (1 , ivar));
712706 h->Sumw2 ();
713707 for (Int_t ievent=0 ; ievent<fNevents ; ievent++)
714708 h->Fill (fXvar (ievent, ivar), fSWeights (ievent, ispecies));
@@ -719,8 +713,10 @@ void TSPlot::FillSWeightsHists(Int_t nbins)
719713 // Fill histograms of y-variables (excluded from the fit), weighted with sWeights
720714 for (Int_t iexcl=0 ; iexcl<fNy ; iexcl++){
721715 for (Int_t ispecies=0 ; ispecies<fNSpecies ; ispecies++){
722- snprintf (name,30 , " y%d_species%d" , iexcl, ispecies);
723- TH1D *h = new TH1D (name, name, nbins, fMinmax (0 , fNx +iexcl), fMinmax (1 , fNx +iexcl));
716+ std::stringstream nameStream;
717+ nameStream << " y" << iexcl << " _species" << ispecies;
718+ std::string name = nameStream.str ();
719+ TH1D *h = new TH1D (name.c_str (), name.c_str (), nbins, fMinmax (0 , fNx +iexcl), fMinmax (1 , fNx +iexcl));
724720 h->Sumw2 ();
725721 for (Int_t ievent=0 ; ievent<fNevents ; ievent++)
726722 h->Fill (fYvar (ievent, iexcl), fSWeights (ievent, fNSpecies *(iexcl+1 )+ispecies));
0 commit comments