FairRoot/PandaRoot
tools/auxi.C
Go to the documentation of this file.
1 // **** some auxilliary functions in auxtut.C ****
2 // - FairRunAna* initrun(TString prefix, TString outfile, int min=-1, int max=-1) --> Init FairRunAna
3 // - plotmyhistos() --> Plots all histograms in current TDirectory on a autosized canvas
4 // - writemyhistos() --> Writes all histos in current TFile
5 // - fillM(RhoCandList l, TH1* h) --> Fill mass histogram h with masses of candidates in l
6 // - RemoveGeoManager() --> Temporary fix for error on macro exit
7 // **** some auxilliary functions in auxtut.C ****
8 
9 #include "TGeoManager.h"
10 
12 {
13  if (gROOT->GetVersionInt() >= 60602) {
14  gGeoManager->GetListOfVolumes()->Delete();
15  gGeoManager->GetListOfShapes()->Delete();
16  delete gGeoManager;
17  }
18 }
19 
21 {
22  bool fileok=true;
23  TFile fff(fn);
24  if (fff.IsZombie()) fileok=false;
25  TTree *t=(TTree*)fff.Get("pndsim");
26  if (t==0x0) fileok=false;
27 
28  if (!fileok) cout <<"Skipping broken file '"<<fn<<"'"<<endl;
29  return fileok;
30 }
31 
32 FairRunAna* initrun(TString prefix, TString outfile, int min=-1, int max=-1)
33 {
34  // *** the files coming from the simulation
35  TString inPidFile = prefix+"_pid.root"; // this file contains the PndPidCandidates and McTruth
36  TString inParFile = prefix+"_par.root";
37 
38  // *** PID table with selection thresholds; can be modified by the user
39  TString pidParFile = TString(gSystem->Getenv("VMCWORKDIR"))+"/macro/params/all.par";
40 
41  // *** initialization
42  FairLogger::GetLogger()->SetLogToFile(kFALSE);
43  FairRunAna* fRun = new FairRunAna();
44  FairRuntimeDb* rtdb = fRun->GetRuntimeDb();
45  fRun->SetSource(new FairFileSource(inPidFile));
46 
47  // *** setup parameter database
48  FairParRootFileIo* parIO = new FairParRootFileIo();
49  parIO->open(inParFile);
50  FairParAsciiFileIo* parIOPid = new FairParAsciiFileIo();
51  parIOPid->open(pidParFile.Data(),"in");
52 
53  rtdb->setFirstInput(parIO);
54  rtdb->setSecondInput(parIOPid);
55  rtdb->setOutput(parIO);
56 
57  fRun->SetOutputFile(outfile);
58 
59  return fRun;
60 }
61 
62 void plotmyhistos(std::vector<TH1*> h, int maxy=700, double asp = 1.1)
63 {
64  int N = h.size();
65  if (N<=0) return;
66 
67  int nx=sqrt(N);
68  int ny=nx;
69  while(nx*ny<N) nx++;
70 
71  int dim = maxy/ny;
72  if (dim>400) dim=400;
73 
74  TCanvas *c=new TCanvas("c","c",10,10,dim*nx*asp, dim*ny);
75 
76  c->Divide(nx,ny, 0.0005,0.0005);
77 
78  for (int i=0;i<N;++i)
79  {
80  c->cd(i+1);
81  h[i]->Draw();
82  }
83 }
84 
85 void plotmyhistos(int maxy=700, double asp = 1.1)
86 {
87  std::vector<TH1*> h;
88 
89  //somehow either one or the other is filled, depending on
90  // whether a TFile was opened, or we write to one
91  int Nkey = gDirectory->GetListOfKeys()->GetSize();
92  int Nlst = gDirectory->GetList()->GetSize();
93 
94  if( Nkey==0 && Nlst==0) return;
95 
96  if (Nkey>0)
97  {
98  TIter next(gDirectory->GetListOfKeys());
99  TKey *key;
100  while ((key = (TKey*)next()))
101  {
102  TClass *cl = gROOT->GetClass(key->GetClassName());
103  if (!cl->InheritsFrom("TH1")) continue;
104  TH1 *hist = (TH1*)key->ReadObj();
105  h.push_back(hist);
106  }
107  }
108  else
109  {
110  TList *hl=gDirectory->GetList();
111  for (int i=0;i<hl->GetSize();++i)
112  {
113  TString cn = hl->At(i)->ClassName();
114  if (cn.BeginsWith("TH1") || cn.BeginsWith("TH2")) h.push_back((TH1*)hl->At(i));
115  }
116  }
117 
118  plotmyhistos(h, maxy, asp);
119 }
120 
121 int writemyhistos(int maxy=800, double asp = 1.1)
122 {
123  TList *hl=gDirectory->GetList();
124  std::vector<TH1*> h;
125  for (int i=0;i<hl->GetSize();++i)
126  {
127  TString cn = hl->At(i)->ClassName();
128  if (cn.BeginsWith("TH1") || cn.BeginsWith("TH2")) h.push_back((TH1*)hl->At(i));
129  }
130 
131  int N = h.size();
132  if (N==0) return 0;
133 
134  for (int i=0;i<N;++i) h[i]->Write();
135 
136  return N;
137 }
138 
139 int fillM(RhoCandList &l, TH1* h)
140 {
141  for (int i=0;i<l.GetLength();++i) h->Fill(l[i]->M());
142 
143  return l.GetLength();
144 }
145 
146 int fillP(RhoCandList &l, TH1* h)
147 {
148  for (int i=0;i<l.GetLength();++i) h->Fill(l[i]->P());
149 
150  return l.GetLength();
151 }
Double_t x0
Definition: checkhelixhit.C:70
Int_t i
Definition: run_full.C:25
friend F32vec4 sqrt(const F32vec4 &a)
Definition: P4_F32vec4.h:29
bool checkfile(TString fn)
Definition: tools/auxi.C:20
Int_t GetLength() const
Definition: RhoCandList.h:46
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:26
TGeoManager * gGeoManager
int writemyhistos(int maxy=800, double asp=1.1)
Definition: tools/auxi.C:121
FairRunAna * fRun
Definition: hit_dirc.C:58
vTop Write()
int fillM(RhoCandList &l, TH1 *h)
Definition: tools/auxi.C:139
void CloseGeoManager()
Definition: tools/auxi.C:11
FairRuntimeDb * rtdb
Definition: hit_dirc.C:66
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:25
int fillP(RhoCandList &l, TH1 *h)
Definition: tools/auxi.C:146
void plotmyhistos(std::vector< TH1 * > h, int maxy=700, double asp=1.1)
Definition: tools/auxi.C:62
FairRunAna * initrun(TString prefix, TString outfile, int min=-1, int max=-1)
Definition: tools/auxi.C:32
TTree * t
Definition: bump_analys.C:13
static int next[96]
Definition: ranlxd.cxx:374
TH1F * hist
TString outfile