15 #define TALKATIVE // get some comments while processing
19 #define INSIDE_VECTOR(vector) \
20 cout << #vector << "={"; for (unsigned int i = 0 ; i < vector.size()-1 ; i++) cout << vector[i] << ","; cout << vector.back() << "}";
21 #define CHECK_MAP_CONTENT(m,type) \
22 for (map<TString,type>::iterator it = m.begin() ; it != m.end() ; it++) \
23 cout << __FILE__ << ":" << __LINE__ << ":Info: " << #m << "[" << it->first << "]=" << it->second << endl;
27 TString output_directory) :
28 _output_directory(output_directory + TString(output_directory.EndsWith(
"/") ?
"" :
"/")),
29 _output_filename(
"comparison.root"),
50 cout <<
">>> TALKATIVE MODE ACTIVATED <<<" << endl;
53 cout <<
">>> DEBUG MODE ACTIVATED <<<" << endl;
54 cout << __FILE__ <<
":"<< __LINE__ <<
":Info: inside constructor of GeometryComparisonPlotter utility"<< endl;
67 tree_file =
new TFile(tree_file_name,
"UPDATE");
74 data->SetBranchAddress(
"sublevel" ,&
branch_i[
"sublevel"]);
75 data->SetBranchAddress(
"useDetId" ,&
branch_i[
"useDetId"]);
95 if (
data->GetBranch(
"rdphi") == 0x0)
98 cout << __FILE__ <<
":" << __LINE__ <<
":Info: computing the rdphi branch from r and dphi branches (assuming they exist...)" << endl;
100 TBranch * br_rdphi =
data->Branch(
"rdphi", &
branch_f[
"rdphi"],
"rdphi/F");
101 for (
unsigned int ientry = 0 ; ientry <
data->GetEntries() ; ientry++)
103 data->GetEntry(ientry);
112 cout << __FILE__ <<
":" << __LINE__ <<
":Info: branch addresses set" << endl;
118 data->SetMarkerSize(0.5);
119 data->SetMarkerStyle(6);
121 gStyle->SetOptStat(
"emr");
122 gStyle->SetTitleAlign(22);
123 gStyle->SetTitleX(0.5);
124 gStyle->SetTitleY(0.97);
125 gStyle->SetTitleFont(62);
128 gStyle->SetTextFont(132);
129 gStyle->SetTextSize(0.08);
130 gStyle->SetLabelFont(132,
"x");
131 gStyle->SetLabelFont(132,
"y");
132 gStyle->SetLabelFont(132,
"z");
133 gStyle->SetTitleSize(0.08,
"x");
134 gStyle->SetTitleSize(0.08,
"y");
135 gStyle->SetTitleSize(0.08,
"z");
136 gStyle->SetLabelSize(0.08,
"x");
137 gStyle->SetLabelSize(0.08,
"y");
138 gStyle->SetLabelSize(0.08,
"z");
140 gStyle->SetMarkerStyle(8);
141 gStyle->SetHistLineWidth(2);
142 gStyle->SetLineStyleString(2,
"[12 12]");
144 gStyle->SetFrameBorderMode(0);
145 gStyle->SetCanvasBorderMode(0);
146 gStyle->SetPadBorderMode(0);
147 gStyle->SetPadColor(0);
148 gStyle->SetCanvasColor(0);
149 gStyle->SetTitleColor(1);
150 gStyle->SetStatColor(0);
151 gStyle->SetStatBorderSize(1);
152 gStyle->SetFrameFillColor(0);
154 gStyle->SetPadTickX(1);
155 gStyle->SetPadTickY(1);
157 gStyle->SetPadTopMargin(0.1);
158 gStyle->SetPadRightMargin(0.05);
159 gStyle->SetPadBottomMargin(0.16);
160 gStyle->SetPadLeftMargin(0.18);
163 cout << __FILE__ <<
":" << __LINE__ <<
":Info: end of constructor" << endl;
170 cout << __FILE__ <<
":" << __LINE__ <<
":Info: in destructor of the GeometryComparisonPlotter utility" << endl;
174 cout << __FILE__ <<
":" << __LINE__ <<
":Info: ending." << endl;
184 #define CHECK_BRANCHES(branchname_vector) \
185 for (unsigned int i = 0 ; i < branchname_vector.size() ; i++) \
187 if (branch_f.find(branchname_vector[i]) == branch_f.end()) \
189 cout << __FILE__ << ":" << __LINE__ << ":Error: The branch " << branchname_vector[i] << " is not recognised." << endl; \
196 const unsigned int nentries =
data->GetEntries();
206 #define LIMITS(axes_vector) \
207 for (unsigned int i = 0 ; i < axes_vector.size() ; i++) \
209 if ( _SF.find(axes_vector[i]) == _SF.end()) _SF[axes_vector[i]] = 1.; \
210 if (_min.find(axes_vector[i]) == _min.end()) _min[axes_vector[i]] = _SF[axes_vector[i]]*data->GetMinimum(axes_vector[i]); \
211 if (_max.find(axes_vector[i]) == _max.end()) _max[axes_vector[i]] = _SF[axes_vector[i]]*data->GetMaximum(axes_vector[i]); \
230 #define NB_SUBLEVELS 6
232 #define NB_Z_SLICES 2
237 if (y.size() >= x.size()){
245 cout <<
"nxPlots: " << nxPlots << endl;
246 cout <<
"nyPlots: " << nyPlots << endl;
251 TMultiGraph * mgraphs[nxPlots][nyPlots][1+
NB_SUBLEVELS];
258 c_global[ic] =
new TCanvas (TString::Format(
"global_%s_%d", ic==0?
"tracker":
_sublevel_names[ic-1].
Data(),
260 TString::Format(
"Global overview of the %s variables", ic==0?
"tracker":
_sublevel_names[ic-1].
Data()),
263 c_global[ic]->Divide(nxPlots,nyPlots);
266 if (y.size() >= x.size()){
267 for (
unsigned int ix = 0 ; ix < x.size() ; ix++)
269 for (
unsigned int iy = 0 ; iy < y.size() ; iy++)
275 ipoint[ix][iy][igraph] = 0;
276 graphs[ix][iy][igraph] =
new TGraph ();
277 #define COLOR_CODE(icolor) int(icolor/4)+icolor+1
278 graphs[ix][iy][igraph]->SetMarkerColor(
COLOR_CODE(igraph));
279 graphs[ix][iy][igraph]->SetMarkerStyle(6);
285 graphs[ix][iy][igraph]->SetMarkerStyle(6);
291 for (
unsigned int ix = 0 ; ix < x.size() ; ix++)
293 for (
unsigned int iy = 0 ; iy < y.size() ; iy++)
299 ipoint[iy][ix][igraph] = 0;
300 graphs[iy][ix][igraph] =
new TGraph ();
301 #define COLOR_CODE(icolor) int(icolor/4)+icolor+1
302 graphs[iy][ix][igraph]->SetMarkerColor(
COLOR_CODE(igraph));
303 graphs[iy][ix][igraph]->SetMarkerStyle(6);
309 graphs[iy][ix][igraph]->SetMarkerStyle(6);
315 cout << __FILE__ <<
":" << __LINE__ <<
":Info: Creation of the TGraph[" << x.size() <<
"][" << y.size() <<
"][" <<
NB_SUBLEVELS*
NB_Z_SLICES <<
"] ended." << endl;
320 cout << __FILE__ <<
":" << __LINE__ <<
":Info: Looping on the TTree" << endl;
323 unsigned int progress = 0;
324 cout << __FILE__ <<
":" << __LINE__ <<
":Info: 0%" << endl;
326 for (
unsigned int ientry = 0 ; ientry < nentries ; ientry++)
329 if (10*ientry/nentries != progress)
331 progress = 10*ientry/nentries;
332 cout << __FILE__ <<
":" << __LINE__ <<
":Info: " << 10*progress <<
"%" << endl;
336 data->GetEntry(ientry);
344 for (
unsigned int ix = 0 ; ix < x.size() ; ix++)
355 for (
unsigned int iy = 0 ; iy < y.size() ; iy++)
370 if (y.size() >= x.size()){
371 graphs[ix][iy][igraph]->SetPoint(ipoint[ix][iy][igraph],
374 ipoint[ix][iy][igraph]++;
377 graphs[iy][ix][igraph]->SetPoint(ipoint[iy][ix][igraph],
380 ipoint[iy][ix][igraph]++;
386 cout << __FILE__ <<
":" << __LINE__ <<
":Info: 100%\tLoop ended" << endl;
407 if (
_write) legend->Write();
409 if (y.size() >= x.size()){
410 #define INDEX_IN_GLOBAL_CANVAS(i1,i2) 1 + i1 + i2*x.size()
412 for (
unsigned int ix = 0 ; ix < x.size() ; ix++)
415 cout << __FILE__ <<
":" << __LINE__ <<
":Info: x[" << ix <<
"]="<< x[ix] << endl;
429 for (
unsigned int iy = 0 ; iy < y.size() ; iy++)
445 cout << __FILE__ <<
":" << __LINE__ <<
":Info: x[" << ix <<
"]=" << x[ix]
446 <<
" and y[" << iy <<
"]=" << y[iy]
447 <<
"\t-> creating TMultiGraph" << endl;
449 mgraphs[ix][iy][0] =
new TMultiGraph (TString::Format(
"mgr_%s_vs_%s_tracker_%d", x[ix].
Data(),
461 unsigned short int igraph =
NB_SUBLEVELS*NB_Z_SLICES - jgraph - 1;
476 cout << __FILE__ <<
":" << __LINE__ <<
":Info: writing TGraph to file" << endl;
479 if (
_write) graphs[ix][iy][igraph]->Write();
480 if (graphs[ix][iy][igraph]->GetN() == 0)
483 cout << __FILE__ <<
":" << __LINE__ <<
":Info: " << graphs[ix][iy][igraph]->GetName() <<
" is empty." << endl;
488 cout << __FILE__ <<
":" << __LINE__ <<
":Info: cloning, coloring and adding TGraph "
491 <<
" to global TMultiGraph" << endl;
494 TGraph * gr = (TGraph *) graphs[ix][iy][igraph]->Clone();
497 mgraphs[ix][iy][0]->Add(gr,
"P");
501 for (
unsigned int isublevel = 1 ; isublevel <=
NB_SUBLEVELS ; isublevel++)
504 cout << __FILE__ <<
":" << __LINE__ <<
":Info: cloning, coloring and adding TGraph "
507 mgraphs[ix][iy][isublevel] =
new TMultiGraph (TString::Format(
"%s_vs_%s_%s_%d", x[ix].
Data(),
515 graphs[ix][iy][ isublevel-1]->SetMarkerColor(kBlack);
516 graphs[ix][iy][
NB_SUBLEVELS+isublevel-1]->SetMarkerColor(kRed);
517 if (graphs[ix][iy][ isublevel-1]->GetN() > 0) mgraphs[ix][iy][isublevel]->Add(graphs[ix][iy][ isublevel-1],
"P");
519 else cout << __FILE__ <<
":" << __LINE__ <<
":Info: graphs[ix][iy][isublevel-1]=" << graphs[ix][iy][isublevel-1]->GetName() <<
" is empty -> not added into " << mgraphs[ix][iy][isublevel]->GetName() << endl;
521 if (graphs[ix][iy][
NB_SUBLEVELS+isublevel-1]->GetN() > 0) mgraphs[ix][iy][isublevel]->Add(graphs[ix][iy][
NB_SUBLEVELS+isublevel-1],
"P");
523 else cout << __FILE__ <<
":" << __LINE__ <<
":Info: graphs[ix][iy][NB_SUBLEVEL+isublevel-1]=" << graphs[ix][iy][NB_Z_SLICES+isublevel-1]->GetName() <<
" is empty -> not added into " << mgraphs[ix][iy][isublevel]->GetName() << endl;
526 cout << __FILE__ <<
":" << __LINE__ <<
":Error: color code incomplete for Z slices..." << endl;
532 for (
unsigned short int imgr = 0 ; imgr <=
NB_SUBLEVELS ; imgr++)
535 cout << __FILE__ <<
":" << __LINE__ <<
":Info: treating individual canvases." << endl;
538 c[ix][iy][imgr] =
new TCanvas (TString::Format(
"c_%s_vs_%s_%s_%d", x[ix].
Data(),
542 TString::Format(
"%s vs. %s at %s level", x[ix].
Data(),
548 if (mgraphs[ix][iy][imgr]->GetListOfGraphs() != 0) mgraphs[ix][iy][imgr]->Draw(
"A");
549 if (imgr == 0 &&
_legend) legend->Draw();
565 if (
_write) mgraphs[ix][iy][imgr]->Write();
571 if (mgraphs[ix][iy][imgr]->GetListOfGraphs() != 0) mgraphs[ix][iy][imgr]->Draw(
"A");
581 #define INDEX_IN_GLOBAL_CANVAS_Y(i1,i2) 1 + i1 + i2*y.size()
584 if (
_write) legend->Write();
586 for (
unsigned int ix = 0 ; ix < x.size() ; ix++)
589 cout << __FILE__ <<
":" << __LINE__ <<
":Info: x[" << ix <<
"]="<< x[ix] << endl;
593 for (
unsigned int iy = 0 ; iy < y.size() ; iy++)
597 cout << __FILE__ <<
":" << __LINE__ <<
":Info: x[" << ix <<
"]=" << x[ix]
598 <<
" and y[" << iy <<
"]=" << y[iy]
599 <<
"\t-> creating TMultiGraph" << endl;
601 mgraphs[iy][ix][0] =
new TMultiGraph (TString::Format(
"mgr_%s_vs_%s_tracker_%d", x[ix].
Data(),
613 unsigned short int igraph =
NB_SUBLEVELS*NB_Z_SLICES - jgraph - 1;
617 cout << __FILE__ <<
":" << __LINE__ <<
":Info: writing TGraph to file" << endl;
620 if (
_write) graphs[iy][ix][igraph]->Write();
621 if (graphs[iy][ix][igraph]->GetN() == 0)
624 cout << __FILE__ <<
":" << __LINE__ <<
":Info: " << graphs[iy][ix][igraph]->GetName() <<
" is empty." << endl;
629 cout << __FILE__ <<
":" << __LINE__ <<
":Info: cloning, coloring and adding TGraph "
632 <<
" to global TMultiGraph" << endl;
635 TGraph * gr = (TGraph *) graphs[iy][ix][igraph]->Clone();
638 mgraphs[iy][ix][0]->Add(gr,
"P");
642 for (
unsigned int isublevel = 1 ; isublevel <=
NB_SUBLEVELS ; isublevel++)
646 cout << __FILE__ <<
":" << __LINE__ <<
":Info: cloning, coloring and adding TGraph "
649 mgraphs[iy][ix][isublevel] =
new TMultiGraph (TString::Format(
"%s_vs_%s_%s_%d", x[ix].
Data(),
657 graphs[iy][ix][ isublevel-1]->SetMarkerColor(kBlack);
658 graphs[iy][ix][
NB_SUBLEVELS+isublevel-1]->SetMarkerColor(kRed);
659 if (graphs[iy][ix][ isublevel-1]->GetN() > 0) mgraphs[iy][ix][isublevel]->Add(graphs[iy][ix][ isublevel-1],
"P");
661 else cout << __FILE__ <<
":" << __LINE__ <<
":Info: graphs[iy][ix][isublevel-1]=" << graphs[iy][ix][isublevel-1]->GetName() <<
" is empty -> not added into " << mgraphs[iy][ix][isublevel]->GetName() << endl;
663 if (graphs[iy][ix][
NB_SUBLEVELS+isublevel-1]->GetN() > 0) mgraphs[iy][ix][isublevel]->Add(graphs[iy][ix][
NB_SUBLEVELS+isublevel-1],
"P");
665 else cout << __FILE__ <<
":" << __LINE__ <<
":Info: graphs[iy][ix][NB_SUBLEVEL+isublevel-1]=" << graphs[iy][ix][NB_Z_SLICES+isublevel-1]->GetName() <<
" is empty -> not added into " << mgraphs[iy][ix][isublevel]->GetName() << endl;
668 cout << __FILE__ <<
":" << __LINE__ <<
":Error: color code incomplete for Z slices..." << endl;
674 for (
unsigned short int imgr = 0 ; imgr <=
NB_SUBLEVELS ; imgr++)
677 cout << __FILE__ <<
":" << __LINE__ <<
":Info: treating individual canvases." << endl;
680 c[iy][ix][imgr] =
new TCanvas (TString::Format(
"c_%s_vs_%s_%s_%d", x[ix].
Data(),
684 TString::Format(
"%s vs. %s at %s level", x[ix].
Data(),
690 if (mgraphs[iy][ix][imgr]->GetListOfGraphs() != 0) mgraphs[iy][ix][imgr]->Draw(
"A");
691 if (imgr == 0 &&
_legend) legend->Draw();
697 if (
_write) mgraphs[iy][ix][imgr]->Write();
703 if (mgraphs[iy][ix][imgr]->GetListOfGraphs() != 0) mgraphs[iy][ix][imgr]->Draw(
"A");
712 gStyle->SetOptTitle(0);
716 c_global[ic]->Draw();
720 TCanvas * c_temp = (TCanvas *) c_global[ic]->Clone(c_global[ic]->GetTitle() + TString(
"_sub"));
722 c_global[ic] =
new TCanvas (c_temp->GetName() + TString(
"_final"), c_temp->GetTitle(), c_temp->GetWindowWidth(), c_temp->GetWindowHeight());
723 c_global[ic]->Draw();
724 TPad * p_up =
new TPad (TString(
"legend_") + c_temp->GetName(),
"",
727 * p_down =
new TPad (TString(
"main_") + c_temp->GetName(),
"",
733 c_temp->DrawClonePad();
740 TLegend * global_legend =
MakeLegend(.05,.1,.95,.8);
741 global_legend->Draw();
745 TPaveText *
pt =
new TPaveText(.05,.1,.95,.8,
"NB");
752 if (
_write) c_global[ic]->Write();
758 cout << __FILE__ <<
":" << __LINE__ <<
":Info: End of MakePlots method" << endl;
772 const int kGridY) {
_grid_x = kGridX ;
779 const float SF) {
_SF[branchname] = SF ; }
788 + TString(name.EndsWith(
"/") ?
"" :
"/") ; }
794 if (word.BeginsWith(
"d")) word.ReplaceAll(
"d",
"#Delta");
795 if (word == TString(
"rdphi")) word =
"r#Delta#phi";
796 else if (word.EndsWith(
"phi")) word.ReplaceAll(
"phi",
"#phi");
797 else if (word.EndsWith(
"alpha")) word.ReplaceAll(
"alpha",
"#alpha");
798 else if (word.EndsWith(
"beta")) word.ReplaceAll(
"beta" ,
"#beta");
799 else if (word.EndsWith(
"gamma")) word.ReplaceAll(
"gamma",
"#gamma");
800 else if (word.EndsWith(
"eta")) word.ReplaceAll(
"eta",
"#eta");
806 if (print_option.Contains(
"pdf" ))
return TString(
".pdf" );
807 else if (print_option.Contains(
"eps" ))
return TString(
".eps" );
808 else if (print_option.Contains(
"ps" ))
return TString(
".ps" );
809 else if (print_option.Contains(
"svg" ))
return TString(
".svg" );
810 else if (print_option.Contains(
"tex" ))
return TString(
".tex" );
811 else if (print_option.Contains(
"gif" ))
return TString(
".gif" );
812 else if (print_option.Contains(
"xpm" ))
return TString(
".xpm" );
813 else if (print_option.Contains(
"png" ))
return TString(
".png" );
814 else if (print_option.Contains(
"jpg" ))
return TString(
".jpg" );
815 else if (print_option.Contains(
"tiff"))
return TString(
".tiff");
816 else if (print_option.Contains(
"cxx" ))
return TString(
".cxx" );
817 else if (print_option.Contains(
"xml" ))
return TString(
".xml" );
818 else if (print_option.Contains(
"root"))
return TString(
".root");
821 cout << __FILE__ <<
":" << __LINE__ <<
":Warning: unknown format. Returning .pdf, but possibly wrong..." << endl;
822 return TString(
".pdf");
832 TLegend * legend =
new TLegend (x1, y1, x2, y2, title.Data(),
"NBNDC");
834 legend->SetFillColor(0);
835 legend->SetLineColor(0);
836 legend->SetLineWidth(0);
837 for (
unsigned int isublevel = 0 ; isublevel <
NB_SUBLEVELS ; isublevel++)
839 TGraph *
g =
new TGraph (0);
842 g->SetMarkerStyle(kFullSquare);
843 g->SetMarkerSize(10);
void SetCanvasSize(const int window_width=3508, const int window_height=2480)
void Set1dModule(const bool)
#define INDEX_IN_GLOBAL_CANVAS_Y(i1, i2)
map< TString, float > branch_f
void MakePlots(const vector< TString >, const vector< TString >)
TString LateXstyle(TString)
void SetGrid(const int, const int)
void SetBatchMode(const bool)
#define LIMITS(axes_vector)
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
~GeometryComparisonPlotter()
#define INDEX_IN_GLOBAL_CANVAS(i1, i2)
void SetBranchMax(const TString, const float)
void SetBranchUnits(const TString, const TString)
#define DEFAULT_WINDOW_WIDTH
TLegend * MakeLegend(double x1, double y1, double x2, double y2, const TString title="")
void SetOutputDirectoryName(const TString)
map< TString, float > _max
void SetPrintOption(const Option_t *)
void Set2dModule(const bool)
void SetLegend(const bool)
map< TString, float > _min
#define CHECK_MAP_CONTENT(m, type)
void SetWrite(const bool)
TString _output_directory
map< TString, TString > _units
TString _sublevel_names[6]
GeometryComparisonPlotter(TString tree_file_name, TString outputDirname="output/")
TString ExtensionFromPrintOption(TString)
void SetOutputFileName(const TString)
void SetPrint(const bool)
void SetBranchSF(const TString, const float)
TString units(TString variable, Char_t axis)
#define CHECK_BRANCHES(branchname_vector)
map< TString, int > branch_i
volatile std::atomic< bool > shutdown_flag false
#define DEFAULT_WINDOW_HEIGHT
#define COLOR_CODE(icolor)
void SetBranchMin(const TString, const float)
#define INSIDE_VECTOR(vector)
void SetLevelCut(const int)
map< TString, float > _SF