FairRoot/PandaRoot
Classes | Functions
comp_multiFiles.C File Reference
#include <iostream>
#include <utility>
#include <algorithm>

Go to the source code of this file.

Classes

struct  fileData
 

Functions

TCanvas * createCanvas (int picpercan)
 
int GetMaxHisto (std::vector< TH1 * > histos)
 
std::vector< fileDataGetFileNames (std::string inputFile)
 
int comp_multiFiles (std::string listOfFiles_File="inputFiles.txt", int picpercan=9)
 

Function Documentation

int comp_multiFiles ( std::string  listOfFiles_File = "inputFiles.txt",
int  picpercan = 9 
)

Definition at line 60 of file comp_multiFiles.C.

References createCanvas(), f, files, fileData::fScalingFactor, g, Get(), GetFileNames(), GetMaxHisto(), graphs, h, i, name, next, and TString.

60  {
61 
62  std::vector<TCanvas*> canvasses;
63  std::string filter = "";
64 
65  std::vector<fileData> fileNames = GetFileNames(listOfFiles_File);
66  std::vector<TFile*> files;
67  for (auto name : fileNames){
68  files.push_back(new TFile(name.fFileName.c_str(), "READ"));
69  }
70 
71  auto maxScalingFactor = std::max_element(fileNames.begin(), fileNames.end(), [](fileData const& lhs, fileData const& rhs){return lhs.fScalingFactor < rhs.fScalingFactor;});
72  double maxScaling = maxScalingFactor->fScalingFactor;
73 
74  std::cout << "Max Scaling Factor: " << maxScalingFactor->fScalingFactor << std::endl;
75  if (files.size() < 2)
76  return 1;
77  TFile *f = files[0];
78  if (!f->IsZombie()) {
79  TKey *key;
80  TIter next(f->GetListOfKeys());
81 
82  int failcount = 0;
83  Int_t yy = 0;
84  Int_t actualCanvas = 0;
85  Int_t actualPad = 0;
86  Int_t i = 0;
87  while ((key = (TKey*) next())) {
88 
89  TObject *obj = key->ReadObj();
90  TString name = obj->GetName();
91  std::cout << name << std::endl;
92  if (!name.Contains(filter.c_str())) continue;
93 
94  actualCanvas = TMath::Floor((double)yy / picpercan);
95  actualPad = (yy % picpercan) + 1;
96  cout << yy << " : " << actualCanvas << "/" << actualPad << endl;
97  if (!(canvasses.size() > actualCanvas)){
98  cout << "New canvas" << endl;
99  canvasses.push_back(createCanvas(picpercan));
100  }
101  canvasses[actualCanvas]->cd(actualPad);
102  yy++;
103 
104  // only check TH1Fs
105  if (obj->InheritsFrom("TH1")){
106  TH1* h = (TH1*) obj;
107  h->Scale(maxScaling/fileNames[0].fScalingFactor);
108  h->SetLineWidth(2);
109  std::vector<TH1*> histos;
110  histos.push_back(h);
111  for (int i = 1; i < files.size(); i++){
112  TH1* currentHisto = (TH1*)files[i]->Get(name);
113  currentHisto->Scale(maxScaling/fileNames[i].fScalingFactor);
114  histos.push_back(currentHisto);
115  currentHisto->SetLineColor(i);
116  currentHisto->SetLineWidth(2);
117  }
118  int maxHisto = GetMaxHisto(histos);
119  if (maxHisto > -1){
120  TLegend* theLegend = new TLegend(0.5,0.55,0.9,0.75);
121  histos[maxHisto]->Draw();
122  theLegend->AddEntry(histos[maxHisto], fileNames[maxHisto].fParameter.c_str(),"l");
123  for (int j = 0; j < histos.size(); j++){
124  if (j != maxHisto){
125  histos[j]->Draw("same");
126  theLegend->AddEntry(histos[j], fileNames[j].fParameter.c_str(),"l");
127  }
128  }
129  theLegend->Draw();
130  }
131  }
132  if (obj->InheritsFrom("TGraph")){
133  TString name = obj->GetName();
134  TLegend* aLegend = new TLegend(0.5,0.55,0.9,0.75);
135  TGraph* g = (TGraph*)obj;
136  g->SetMarkerStyle(6);
137  g->Draw("AL");
138  aLegend->AddEntry(g, fileNames[0].fParameter.c_str(),"l");
139  std::vector<TGraph*> graphs;
140  graphs.push_back(g);
141  for (int i = 1; i < files.size(); i++){
142  TGraph* currentGraph = (TGraph*)files[i]->Get(name);
143  graphs.push_back(currentGraph);
144  currentGraph->SetMarkerStyle(6);
145  currentGraph->SetMarkerColor(i+1);
146  currentGraph->SetLineColor(i+1);
147  currentGraph->Draw("L");
148  aLegend->AddEntry(currentGraph, fileNames[i].fParameter.c_str(),"l");
149  }
150 
151  }
152  }
153  }
154  return 0;
155 }
Int_t i
Definition: run_full.C:25
TFile * g
std::map< int, TString > files
Definition: simubg.C:28
TCanvas * createCanvas(int picpercan)
TFile * f
Definition: bump_analys.C:12
int GetMaxHisto(std::vector< TH1 * > histos)
TString name
file Get("FairBaseParSet")
double fScalingFactor
std::vector< fileData > GetFileNames(std::string inputFile)
static int next[96]
Definition: ranlxd.cxx:374
TCanvas * graphs
Definition: dedx_bands.C:109
TCanvas* createCanvas ( int  picpercan)

Definition at line 17 of file comp_multiFiles.C.

References CAMath::Sqrt().

Referenced by comp_multiFiles(), and comp_recoqa().

17  {
18  double division = TMath::Sqrt((double)picpercan);
19  int first = ceil(division);
20  int second = round(division);
21  cout << "createCanvas: " << picpercan << " : " << first << "/" << second << endl;
22  TCanvas* newCan = new TCanvas();
23  newCan->Divide(second, first);
24  return newCan;
25 }
static T Sqrt(const T &x)
Definition: PndCAMath.h:37
std::vector<fileData> GetFileNames ( std::string  inputFile)

Definition at line 46 of file comp_multiFiles.C.

Referenced by comp_multiFiles().

47 {
48  std::vector<fileData> listOfFiles;
49  std::string fileName;
50  std::string parameter;
51  double scalingFactor;
52 
53  std::ifstream in(inputFile);
54  while(in >> fileName >> parameter >> scalingFactor){
55  listOfFiles.push_back(fileData(fileName, parameter, scalingFactor));
56  }
57  return listOfFiles;
58 }
int GetMaxHisto ( std::vector< TH1 * >  histos)

Definition at line 27 of file comp_multiFiles.C.

References i.

Referenced by comp_multiFiles().

27  {
28  int index = -1;
29  int oldMax = 0;
30  for (int i = 0; i < histos.size(); i++){
31  if (histos[i]->GetMaximum() > oldMax){
32  oldMax = histos[i]->GetMaximum();
33  index = i;
34  }
35  }
36  return index;
37 }
Int_t i
Definition: run_full.C:25