er  dev
recoTOF.cxx
1 #if !defined(__CLING__)
2 
3 
4 #include "TFile.h"
5 #include "TChain.h"
6 #include "TCanvas.h"
7 #include "TRandom3.h"
8 
9 #include "~/Acculinna/ER/beamtime/data/ERBeamTimeEventHeader.h"
10 
11 #include "~/Acculinna/ER/BeamDet/data/ERBeamDetTOFDigi.h"
12 
13 
14 #include <iostream>
15 
16 using std::cout;
17 using std::endl;
18 
19 #endif
20 
21 void Reset();
22 
23 
24 void TOF(TClonesArray *dataF3, TClonesArray *dataF5);
25 
26 Int_t trigger;
27 Double_t dE;
28 Double_t ToF;
29 Double_t tF3, tF5;
30 
31 void recoTOF() {
32 
33  TString inFile = "he8_10_0010.Digi.root";
34  TString outFile = "he8_10_0010.TOF.reco.root";
35 
36  TString inPath = "~/Acculinna/ER/showBeam_VC/analysed/";
37  TString outPath = "~/Acculinna/ER/showBeam_VC/reco/";
38 
40  //Input file
42  TFile *fr = new TFile(inPath + inFile);
43  TTree *tr = (TTree*)fr->Get("er");
44 
45  cout << "Founding " << tr->GetEntries() << " entries" << endl;
46 
48 
49 
50  TClonesArray *v_F3 = new TClonesArray("ERBeamDetTOFDigi");
51  TClonesArray *v_F5 = new TClonesArray("ERBeamDetTOFDigi");
52 
53  //tr->Print();
54  tr->SetBranchAddress("EventHeader.", &header);
55 
56  printf("Yey! %i\n", tr->SetBranchAddress("BeamDetToFDigi1", &v_F3));
57  printf("Yey! %i\n", tr->SetBranchAddress("BeamDetToFDigi2", &v_F5));
58 
60  //output file
62  TFile *fw = new TFile(outPath + outFile, "RECREATE");
63  TTree *tw = new TTree("reco", "Selected reconstructed variables");
64 
65 // Int_t trigger;
66  tw->Branch("trigger", &trigger, "trigger/I");
67  tw->Branch("dE", &dE, "dE/D");
68  tw->Branch("ToF", &ToF, "ToF/D");
69  tw->Branch("tF3", &tF3, "tF3/D");
70  tw->Branch("tF5", &tF5, "tF5/D");
71 
72  Long64_t noEntries = tr->GetEntries();
73 
74 
75  //todo: first event is triggered by 1 for some reason
76  for(Long64_t nentry = 1; nentry < noEntries; nentry++) {
77 
78  if(nentry%100000==0) cout << "#Event " << nentry << "#" << endl;
79 
80  Reset();
81 
82  tr->GetEntry(nentry);
83 
84  trigger = header->GetTrigger();
85 
86  TOF(v_F3, v_F5);
87 
88  tw->Fill();
89 
90  }
91  /*
92  TCanvas *c1 = new TCanvas("c1", "PID - dE vs ToF", 1000, 1000);
93  c1->Divide(1,2);
94 
95  c1->cd(1);
96  tw->Draw("dE:ToF>>(1000, 0, 1000, 5000, 0, 10000)", "", "col");
97 
98  c1->cd(2);
99  tw->Draw("trigger", "");
100  c1->Update();*/ // I would like to plot PID picture here
101  fw->cd();
102  tw->Write();
103  fw->Close();
104 
105 
106 
107 }
108 
109 void Reset() {
110  trigger = 0;
111 
112 }
113 
114 
115 
116 void TOF(TClonesArray *dataF3, TClonesArray *dataF5) {
117 
118  //cout << "F3 " << dataF3->GetEntriesFast() << endl;
119  //cout << "F5 " << dataF5->GetEntriesFast() << endl;
120 
121  Int_t F3 = 0;
122  Int_t F5 = 0;
123 
124  if (dataF3)
125  {
126  F3 = dataF3->GetEntriesFast();
127 
128  }
129  if (dataF5)
130  {
131  F5 = dataF5->GetEntriesFast();
132  }
133 
134  if (F5 == 1) {
135  Double_t dEbeam;
136  for (Int_t i = 0; i < 1; i++) {
137  //printf("dE 's here \t%i\n",i );
138  dEbeam = ((ERBeamDetTOFDigi*)dataF5->At(i))->GetEdep();
139  //cout << " dE = " << dEbeam << endl;
140 
141  dE = dEbeam;
142  }
143 
144 
145  }
146 
147  Double_t TIME = 0.;
148  const Double_t timeCal = 0.125;
149  const Double_t constTOF = 89.165;
150 
151  if (F3 == 1 && F5 == 1) {
152 
153  Float_t timeF3, timeF5;
154  for (Int_t i = 0; i < 1; i++) {
155  //printf("hi\t%i\n",i );
156  timeF3 = ((ERBeamDetTOFDigi*)dataF3->At(i))->GetTime();
157  //cout<< " Time F3 = " << timeF3 <<endl;
158  tF3 = timeF3;
159  }
160 
161 
162  for (Int_t i = 0; i < 1; i++) {
163  //printf("helllllllloo\t%i\n",i );
164  timeF5 = ((ERBeamDetTOFDigi*)dataF5->At(i))->GetTime();
165  //cout << " Time F5 = " << timeF5 <<endl;
166  tF5 = timeF5;
167  }
168 
169  TIME = (timeF5 - timeF3) + constTOF; // I'm not sure in Digi file
170  // do we take time caliration or not? That's why I didn't put timeCal here
171  //cout << " TOF = " << TIME << endl;
172  ToF = TIME;
173 
174  }
175 
176 }