FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
plots.C
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 plots(Int_t nEvents = 1000, Int_t iout = 1, TString mcEngine = "TGeant3")
9 {
10 
11  // Input data definitions
12  //-----User Settings:-----------------------------------------------
13  TString MCFile = "testrun_" + mcEngine + ".root";
14  TString ParFile = "testparams_" + mcEngine + ".root";
15  TString RecoFile = "testreco_" + mcEngine + ".root";
16  ;
17 
18  // ----- Reconstruction run -------------------------------------------
19  FairRunAna *fRun = new FairRunAna();
20  FairFileSource *fFileSource = new FairFileSource(MCFile);
21  fRun->SetSource(fFileSource);
22  fRun->AddFriend(RecoFile.Data());
23 
24  FairRuntimeDb *rtdb = fRun->GetRuntimeDb();
25  FairParRootFileIo *parInput1 = new FairParRootFileIo();
26  parInput1->open(ParFile.Data());
27  rtdb->setFirstInput(parInput1);
28 
29  TFile *f1 = TFile::Open(MCFile);
30  TFile *f2 = TFile::Open(RecoFile);
31 
32  TTree *t1 = f1->Get("cbmsim");
33  TTree *t2 = f2->Get("cbmsim");
34 
35  FairMCEventHeader *MCEventHeader = new FairMCEventHeader();
36  TClonesArray *MCTracks = new TClonesArray("FairMCTrack");
37  TClonesArray *TutorialDetPoints = new TClonesArray("FairTutorialDet4Point");
38  TClonesArray *TutorialDetHits = new TClonesArray("FairTutorialDet4Hit");
39 
40  t1->SetBranchAddress("MCEventHeader.", &MCEventHeader);
41  t1->SetBranchAddress("MCTrack", &MCTracks);
42  t1->SetBranchAddress("TutorialDetPoint", &TutorialDetPoints);
43  t2->SetBranchAddress("TutorialDetHit", &TutorialDetHits);
44 
45  FairMCTrack *MCTrack;
46  FairTutorialDet4Point *Point;
48 
49  // histograms
50  fRun->SetSink(new FairRootFileSink("test.ana.root"));
51  TFile *fHist = fRun->GetOutputFile();
52 
53  Float_t xrange = 80.;
54  Float_t yrange = 80.;
55 
56  TH2F *dxx = new TH2F("dxx", "Hit; x; Delta x;", 100, -xrange, xrange, 50., -10., 10.);
57  TH2F *dyy = new TH2F("dyy", "Hit; y; Delta y;", 100, -yrange, yrange, 50., -10., 10.);
58  TH1F *pullx = new TH1F("pullx", "Hit; pullx;", 100., -5., 5.);
59  TH1F *pully = new TH1F("pully", "Hit; pully;", 100., -5., 5.);
60  TH1F *pullz = new TH1F("pullz", "Hit; pullz;", 50., -10., 10.);
61  TH1F *pointx = new TH1F("pointx", "Hit; posx;", 200., -80., 80.);
62  TH1F *pointy = new TH1F("pointy", "Hit; posy;", 200., -80., 80.);
63 
64  Int_t nMCTracks, nPoints, nHits;
65  Float_t x_point, y_point, z_point, tof_point, SMtype_point, mod_point, cel_point, gap_point;
66  Float_t x_poi, y_poi, z_poi;
67  Float_t SMtype_poi, mod_poi, cel_poi, gap_poi;
68  Float_t p_MC, px_MC, py_MC, pz_MC;
69  Float_t x_hit, y_hit, z_hit, dy_hit;
70 
71  Int_t nevent = t1->GetEntries();
72 
73  if (nevent > nEvents)
74  nevent = nEvents;
75 
76  cout << "total number of events to process: " << nevent << endl;
77 
78  // Event loop
79 
80  for (Int_t iev = 0; iev < nevent; iev++) {
81  // get entry
82  t1->GetEntry(iev);
83  t2->GetEntry(iev);
84 
85  nMCTracks = MCTracks->GetEntriesFast();
86  nPoints = TutorialDetPoints->GetEntriesFast();
87  nHits = TutorialDetHits->GetEntriesFast();
88 
89  cout << " Event" << iev << ":";
90  cout << nMCTracks << " MC tracks ";
91  cout << nPoints << " points ";
92  cout << nHits << " Hits " << endl;
93 
94  // Hit loop
95  for (Int_t j = 0; j < nHits; j++) {
96  Hit = (FairTutorialDet4Hit *)TutorialDetHits->At(j);
97  Int_t l = Hit->GetRefIndex();
98  Point = (FairTutorialDet4Point *)TutorialDetPoints->At(l);
99 
100  // Point info
101  x_poi = Point->GetX();
102  y_poi = Point->GetY();
103  z_poi = Point->GetZ();
104 
105  // Hit info
106  x_hit = Hit->GetX();
107  y_hit = Hit->GetY();
108  z_hit = Hit->GetZ();
109  dy_hit = Hit->GetDy();
110  // Int_t flg_hit = Hit->GetFlag();
111 
112  Float_t delta_x = x_poi - x_hit;
113  Float_t delta_y = y_poi - y_hit;
114  Float_t delta_z = z_poi - z_hit;
115 
116  dxx->Fill(x_poi, delta_x);
117  dyy->Fill(y_poi, delta_y);
118  pullx->Fill(delta_x);
119  pully->Fill(delta_y);
120  pullz->Fill(delta_z);
121  pointx->Fill(x_hit);
122  pointy->Fill(y_hit);
123 
124  } // Hit loop end
125 
126  } // event loop end
127 
128  // save histos to file
129  // TFile *fHist = TFile::Open("data/auaumbias.hst.root","RECREATE");
130  cout << "Processing done, outflag =" << iout << endl;
131  if (iout == 1) {
132  fHist->Write();
133  if (0) { // explicit writing
134  TIter next(gDirectory->GetList());
135  TH1 *h;
136  TObject *obj;
137  while (obj = (TObject *)next()) {
138  if (obj->InheritsFrom(TH1::Class())) {
139  h = (TH1 *)obj;
140  cout << "Write histo " << h->GetTitle() << endl;
141  h->Write();
142  }
143  }
144  }
145  fHist->ls();
146  fHist->Close();
147  }
148 
149  // ----- Finish -------------------------------------------------------
150 
151  cout << endl << endl;
152 
153  // Extract the maximal used memory an add is as Dart measurement
154  // This line is filtered by CTest and the value send to CDash
155  FairSystemInfo sysInfo;
156  Float_t maxMemory = sysInfo.GetMaxMemory();
157  cout << "<DartMeasurement name=\"MaxMemory\" type=\"numeric/double\">";
158  cout << maxMemory;
159  cout << "</DartMeasurement>" << endl;
160 
161  timer.Stop();
162  Double_t rtime = timer.RealTime();
163  Double_t ctime = timer.CpuTime();
164 
165  Float_t cpuUsage = ctime / rtime;
166  cout << "<DartMeasurement name=\"CpuLoad\" type=\"numeric/double\">";
167  cout << cpuUsage;
168  cout << "</DartMeasurement>" << endl;
169 
170  cout << endl << endl;
171  cout << "Output file is " << outFile << endl;
172  cout << "Parameter file is " << parFile << endl;
173  cout << "Real time " << rtime << " s, CPU time " << ctime << "s" << endl << endl;
174  cout << "Macro finished successfully." << endl;
175 
176  // ------------------------------------------------------------------------
177 }
list of container factories
Definition: FairRuntimeDb.h:24
Double_t GetZ() const
Definition: FairHit.h:50
TFile * GetOutputFile()
Definition: FairRun.cxx:168
Double_t GetZ() const
Definition: FairMCPoint.h:69
Double_t GetX() const
Definition: FairMCPoint.h:67
Double_t GetX() const
Definition: FairHit.h:48
void SetSink(FairSink *tempSink)
Definition: FairRun.h:84
Float_t GetMaxMemory()
Int_t GetRefIndex() const
Definition: FairHit.h:45
Double_t GetDy() const
Definition: FairHit.h:43
FairRuntimeDb * GetRuntimeDb(void)
Definition: FairRun.h:80
Double_t GetY() const
Definition: FairHit.h:49
Bool_t open(const Text_t *fname, Option_t *option="READ", const Text_t *ftitle="", Int_t compress=1)
plots(Int_t nEvents=1000, Int_t iout=1, TString mcEngine="TGeant3")
Definition: plots.C:8
virtual void SetSource(FairSource *tempSource)
Definition: FairRunAna.h:70
Double_t GetY() const
Definition: FairMCPoint.h:68
Bool_t setFirstInput(FairParIo *)