1 |
mocchiut |
1.1 |
#if !defined(__CINT__) || defined(__MAKECINT__) |
2 |
|
|
|
3 |
|
|
|
4 |
|
|
#include <fstream> |
5 |
|
|
#include <sstream> |
6 |
|
|
#include <string> |
7 |
|
|
#include <math.h> |
8 |
|
|
#include <iostream> |
9 |
|
|
#include <TTree.h> |
10 |
|
|
#include <TClassEdit.h> |
11 |
|
|
#include <TObject.h> |
12 |
|
|
#include <TList.h> |
13 |
|
|
#include <TSystem.h> |
14 |
|
|
#include <TSystemDirectory.h> |
15 |
|
|
#include <TString.h> |
16 |
|
|
#include <TFile.h> |
17 |
|
|
#include <TClass.h> |
18 |
|
|
#include <TCanvas.h> |
19 |
|
|
#include <TH1.h> |
20 |
|
|
#include <TH1F.h> |
21 |
|
|
#include <TH2D.h> |
22 |
|
|
#include <TLatex.h> |
23 |
|
|
#include <TPad.h> |
24 |
|
|
#include <TPaveLabel.h> |
25 |
|
|
#include <TChain.h> |
26 |
|
|
#include <TGraph.h> |
27 |
|
|
#include <TMultiGraph.h> |
28 |
|
|
#include <TLine.h> |
29 |
|
|
#include <TStyle.h> |
30 |
|
|
#include <TF1.h> |
31 |
|
|
#include <TH1F.h> |
32 |
|
|
#include <TTree.h> |
33 |
|
|
#include <TCanvas.h> |
34 |
|
|
#include <PamLevel2.h> |
35 |
|
|
#include <iomanip> |
36 |
|
|
// |
37 |
|
|
#include <ToFCore.h> |
38 |
|
|
// |
39 |
|
|
// Declaration of the core fortran routines |
40 |
|
|
// |
41 |
|
|
#define tofl2com tofl2com_ |
42 |
|
|
extern "C" int tofl2com(); |
43 |
|
|
#define toftrk toftrk_ |
44 |
|
|
extern "C" int toftrk(); |
45 |
|
|
///extern "C" int toftrk(float); |
46 |
|
|
#define rdtofcal rdtofcal_ |
47 |
|
|
extern "C" int rdtofcal(char [], int *); |
48 |
|
|
|
49 |
|
|
using namespace std; |
50 |
|
|
|
51 |
|
|
#endif |
52 |
|
|
|
53 |
|
|
//=================================== |
54 |
|
|
// global variables |
55 |
|
|
//=================================== |
56 |
|
|
TString DIR; |
57 |
|
|
TString OUTF; |
58 |
|
|
TString LIST; |
59 |
|
|
TString OPTIONS; |
60 |
|
|
|
61 |
|
|
PamLevel2 *pam_event = NULL; |
62 |
|
|
|
63 |
|
|
//========================================== |
64 |
|
|
//000000000000000000000000000000000000000000 |
65 |
|
|
//========================================== |
66 |
|
|
Int_t Loop(TString ddir,TString list, TString options){ |
67 |
|
|
// |
68 |
|
|
// |
69 |
|
|
extern struct ToFInput tofinput_; |
70 |
|
|
extern struct ToFOutput tofoutput_; |
71 |
|
|
// -------------------- |
72 |
|
|
// read input file/list |
73 |
|
|
// -------------------- |
74 |
|
|
pam_event = new PamLevel2(ddir,list,options); |
75 |
|
|
TTree::SetMaxTreeSize(1000*Long64_t(2000000000)); |
76 |
|
|
// |
77 |
|
|
TString outfile_t =0; |
78 |
|
|
outfile_t = OUTF; |
79 |
|
|
outfile_t.Append("b.root"); |
80 |
|
|
TFile *outft = (TFile*)gROOT->FindObject(outfile_t); |
81 |
|
|
if (outft) outft->Close(); |
82 |
|
|
outft = new TFile(outfile_t,"RECREATE"); |
83 |
|
|
if(outft->IsZombie()){ |
84 |
|
|
cout << "Output file could not be created\n"; |
85 |
|
|
return 1; |
86 |
|
|
}; |
87 |
|
|
cout << "Created output file: "<<outft->GetName()<<endl; |
88 |
|
|
// |
89 |
|
|
outft->cd(); |
90 |
|
|
ToFLevel2 *tof = new ToFLevel2(); |
91 |
|
|
TTree *toft = new TTree("ToF","PAMELA Level2 ToF data"); |
92 |
|
|
toft->SetAutoSave(900000000000000LL); |
93 |
|
|
tof->Set();//ELENA **TEMPORANEO?** |
94 |
|
|
toft->Branch("ToFLevel2","ToFLevel2",&tof); |
95 |
|
|
// |
96 |
|
|
pam_event->CreateCloneTrees(outft); |
97 |
|
|
// |
98 |
|
|
Int_t ntrkentry = 0; |
99 |
|
|
Int_t npmtentry = 0; |
100 |
|
|
// |
101 |
|
|
ULong64_t nevents = pam_event->GetEntries(); |
102 |
|
|
printf("\n\n Running on %llu events \n\n",nevents); |
103 |
|
|
// |
104 |
|
|
TFile *tfile = TFile::Open(list.Data(),"READ"); |
105 |
|
|
TTree *toftr = (TTree*)tfile->Get("ToF"); |
106 |
|
|
ToFLevel2 *tofl2 = new ToFLevel2(); |
107 |
|
|
toftr->SetBranchAddress("ToFLevel2", &tofl2); |
108 |
|
|
ULong64_t ntofev = toftr->GetEntries(); |
109 |
|
|
printf(" ToF events are %llu \n",ntofev); |
110 |
|
|
// |
111 |
|
|
// |
112 |
|
|
GL_PARAM *glparam = new GL_PARAM(); |
113 |
|
|
TrkLevel2 *trk = new TrkLevel2(); |
114 |
|
|
// |
115 |
|
|
TString host; |
116 |
|
|
TString user; |
117 |
|
|
TString psw; |
118 |
|
|
const char *pamdbhost=gSystem->Getenv("PAM_DBHOST"); |
119 |
|
|
const char *pamdbuser=gSystem->Getenv("PAM_DBUSER"); |
120 |
|
|
const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW"); |
121 |
|
|
if ( !pamdbhost ) pamdbhost = ""; |
122 |
|
|
if ( !pamdbuser ) pamdbuser = ""; |
123 |
|
|
if ( !pamdbpsw ) pamdbpsw = ""; |
124 |
|
|
if ( strcmp(pamdbhost,"") ) host = pamdbhost; |
125 |
|
|
if ( strcmp(pamdbuser,"") ) user = pamdbuser; |
126 |
|
|
if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw; |
127 |
|
|
// |
128 |
|
|
// |
129 |
|
|
TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
130 |
|
|
if ( !dbc->IsConnected() ) return 1; |
131 |
|
|
stringstream myquery; |
132 |
|
|
myquery.str(""); |
133 |
|
|
myquery << "SET time_zone='+0:00'"; |
134 |
|
|
dbc->Query(myquery.str().c_str()); |
135 |
|
|
glparam->Query_GL_PARAM(1,1,dbc); // parameters stored in DB in GL_PRAM table |
136 |
|
|
trk->LoadField(glparam->PATH+glparam->NAME); |
137 |
|
|
// |
138 |
|
|
Long64_t myrun = 0; |
139 |
|
|
Long64_t mysrun = -1; |
140 |
|
|
Int_t adc[4][12]; |
141 |
|
|
Int_t tdc[4][12]; |
142 |
|
|
Float_t tdcc[4][12]; |
143 |
|
|
// |
144 |
|
|
Bool_t defcal = true; |
145 |
|
|
for(ULong64_t iev=0; iev<nevents; iev++){ |
146 |
|
|
|
147 |
|
|
|
148 |
|
|
//================================================================== |
149 |
|
|
|
150 |
|
|
|
151 |
|
|
// for(ULong64_t iev=0; iev<50; iev++){ |
152 |
|
|
// |
153 |
|
|
if ( !(iev%1000) ) printf(" %iK \n",(int)iev/1000); |
154 |
|
|
pam_event->Clear(); |
155 |
|
|
// |
156 |
|
|
if( pam_event->GetEntry(iev) ){ |
157 |
|
|
// |
158 |
|
|
pam_event->FillCloneTrees(); |
159 |
|
|
toftr->GetEntry(iev); |
160 |
|
|
// |
161 |
|
|
// variable to save information about the tof calibration used |
162 |
|
|
// |
163 |
|
|
// |
164 |
|
|
myrun=pam_event->GetRunInfo()->ID; |
165 |
|
|
if ( myrun != mysrun ){ |
166 |
|
|
// printf(" rhtime %u myrun %i mysrun %i \n",pam_event->GetRunInfo()->RUNHEADER_TIME,(int)myrun,(int)mysrun); |
167 |
|
|
mysrun = myrun; |
168 |
|
|
// |
169 |
|
|
Int_t error=glparam->Query_GL_PARAM(pam_event->GetRunInfo()->RUNHEADER_TIME,201,dbc); // parameters stored in DB in GL_PRAM table |
170 |
|
|
if ( error<0 ) { |
171 |
|
|
return(1); |
172 |
|
|
}; |
173 |
|
|
// |
174 |
|
|
printf(" Reading ToF parameter file: %s \n",(glparam->PATH+glparam->NAME).Data()); |
175 |
|
|
// |
176 |
|
|
if ( (UInt_t)glparam->TO_TIME != (UInt_t)4294967295UL ) defcal = false; |
177 |
|
|
// |
178 |
|
|
Int_t nlen = (Int_t)(glparam->PATH+glparam->NAME).Length(); |
179 |
|
|
rdtofcal((char *)(glparam->PATH+glparam->NAME).Data(),&nlen); |
180 |
|
|
// |
181 |
|
|
}; |
182 |
|
|
// |
183 |
|
|
|
184 |
|
|
|
185 |
|
|
//================================================================ |
186 |
|
|
//================================================================== |
187 |
|
|
//--- Define absolute time |
188 |
|
|
Float_t tabs=pam_event->GetOrbitalInfo()->absTime; |
189 |
|
|
|
190 |
|
|
//================================================================== |
191 |
|
|
Float_t dedx_corr_m[2000][48],dedx_corr[48]; |
192 |
|
|
Double_t mtime[2000],t1,t2,tm; |
193 |
|
|
Float_t yhelp1,yhelp2,slope,inter,thelp1,thelp2; |
194 |
|
|
Float_t xmean1,xwidth1; |
195 |
|
|
|
196 |
|
|
Int_t ical,ii,j,jj; |
197 |
|
|
|
198 |
|
|
if (iev==0) { |
199 |
|
|
|
200 |
|
|
ical=0; // counter set to zero if first-time reading |
201 |
|
|
|
202 |
|
|
//----------------------------------------------------------- |
203 |
|
|
// Here I read the dEdx_korr parameters |
204 |
|
|
//----------------------------------------------------------- |
205 |
|
|
|
206 |
|
|
jj=0; |
207 |
|
|
|
208 |
|
|
ifstream fin("adcmonitor.7th.100k.cut.dat"); |
209 |
|
|
|
210 |
|
|
while (! fin.eof()) { |
211 |
|
|
fin>>t1>>tm>>t2; |
212 |
|
|
//cout<<jj<<" "<<tm<<endl; |
213 |
|
|
cout << setiosflags(ios::fixed) << setw(10) << setprecision(3) << tm << endl; |
214 |
|
|
mtime[jj]=tm; |
215 |
|
|
for (ii=0; ii<48;ii++) { |
216 |
|
|
fin>>j>>xmean1>>xwidth1; |
217 |
|
|
dedx_corr_m[jj][ii]=xmean1; |
218 |
|
|
} |
219 |
|
|
jj=jj+1; |
220 |
|
|
} |
221 |
|
|
|
222 |
|
|
fin.close(); |
223 |
|
|
|
224 |
|
|
|
225 |
|
|
while (tabs > mtime[ical]) { |
226 |
|
|
ical = ical+1; |
227 |
|
|
} |
228 |
|
|
ical = ical-1; |
229 |
|
|
cout<<"abs time "<<tabs<<" limit low "<<mtime[ical]<<" limit up "<<mtime[ical+1]<<" ical "<<ical<<endl; |
230 |
|
|
} // if iev==0... |
231 |
|
|
|
232 |
|
|
//================================================================== |
233 |
|
|
//== End of first time reading & filling the array |
234 |
|
|
//================================================================== |
235 |
|
|
|
236 |
|
|
//================================================================== |
237 |
|
|
//== if time is outside time limits: |
238 |
|
|
//================================================================== |
239 |
|
|
|
240 |
|
|
if (tabs<mtime[ical] || tabs>mtime[ical+1]) { |
241 |
|
|
cout<<"Checking Time Limits!"<<endl; |
242 |
|
|
ical=0; |
243 |
|
|
while (tabs > mtime[ical]) { |
244 |
|
|
ical = ical+1; |
245 |
|
|
} |
246 |
|
|
ical = ical-1; |
247 |
|
|
cout<<"abs time "<<tabs<<" limit low "<<mtime[ical]<<" limit up "<<mtime[ical+1]<<" ical "<<ical<<endl; |
248 |
|
|
}; |
249 |
|
|
|
250 |
|
|
//================================================================== |
251 |
|
|
//== interpolate betwen time limits |
252 |
|
|
//================================================================== |
253 |
|
|
|
254 |
|
|
thelp1 = mtime[ical]; |
255 |
|
|
thelp2 = mtime[ical+1]; |
256 |
|
|
|
257 |
|
|
for (ii=0; ii<48;ii++) { |
258 |
|
|
yhelp1 = dedx_corr_m[ical][ii]; |
259 |
|
|
yhelp2 = dedx_corr_m[ical+1][ii]; |
260 |
|
|
slope = (yhelp2-yhelp1)/(thelp2-thelp1); |
261 |
|
|
inter = yhelp1 - slope*thelp1; |
262 |
|
|
dedx_corr[ii] = slope*tabs + inter; |
263 |
|
|
// if (ii==0) cout<<thelp1<<" "<<thelp2<<" "<<tabs<<" "<<yhelp1<<" "<<yhelp2<<" "<<dedx_corr[0]<<endl; |
264 |
|
|
} |
265 |
|
|
|
266 |
|
|
//================================================================ |
267 |
|
|
//================================================================ |
268 |
|
|
|
269 |
|
|
|
270 |
|
|
// process tof data |
271 |
|
|
// |
272 |
|
|
for (Int_t hh=0; hh<12;hh++){ |
273 |
|
|
for (Int_t kk=0; kk<4;kk++){ |
274 |
|
|
adc[kk][hh] = 4095; |
275 |
|
|
tdc[kk][hh] = 4095; |
276 |
|
|
tdcc[kk][hh] = 4095.; |
277 |
|
|
tofinput_.adc[hh][kk] = 4095; |
278 |
|
|
tofinput_.tdc[hh][kk] = 4095; |
279 |
|
|
}; |
280 |
|
|
}; |
281 |
|
|
// memset(adc, 0, 12*4*sizeof(Int_t)); |
282 |
|
|
// memset(tdc, 0, 12*4*sizeof(Int_t)); |
283 |
|
|
Int_t gg = 0; |
284 |
|
|
Int_t hh = 0; |
285 |
|
|
Int_t adcf[48]; |
286 |
|
|
memset(adcf, 0, 48*sizeof(Int_t)); |
287 |
|
|
Int_t tdcf[48]; |
288 |
|
|
memset(tdcf, 0, 48*sizeof(Int_t)); |
289 |
|
|
for (Int_t pm=0; pm < tofl2->ntrk() ; pm++){ |
290 |
|
|
ToFTrkVar *ttf = tofl2->GetToFTrkVar(pm); |
291 |
|
|
for ( Int_t nc=0; nc < ttf->npmttdc; nc++){ |
292 |
|
|
if ( (ttf->tdcflag).At(nc) != 0 ) tdcf[(ttf->pmttdc).At(nc)] = 1; |
293 |
|
|
}; |
294 |
|
|
for ( Int_t nc=0; nc < ttf->npmtadc; nc++){ |
295 |
|
|
if ( (ttf->adcflag).At(nc) != 0 ) adcf[(ttf->pmtadc).At(nc)] = 1; |
296 |
|
|
}; |
297 |
|
|
}; |
298 |
|
|
// |
299 |
|
|
for (Int_t pm=0; pm < tofl2->npmt() ; pm++){ |
300 |
|
|
ToFPMT *pmt = tofl2->GetToFPMT(pm); |
301 |
|
|
tofl2->GetPMTIndex(pmt->pmt_id, gg, hh); |
302 |
|
|
if ( adcf[pmt->pmt_id] == 0 ){ |
303 |
|
|
tofinput_.adc[gg][hh] = (int)pmt->adc; |
304 |
|
|
adc[hh][gg] = (int)pmt->adc; |
305 |
|
|
}; |
306 |
|
|
if ( tdcf[pmt->pmt_id] == 0 ){ |
307 |
|
|
tofinput_.tdc[gg][hh] = (int)pmt->tdc; |
308 |
|
|
tdc[hh][gg] = (int)pmt->tdc; |
309 |
|
|
}; |
310 |
|
|
tdcc[hh][gg] = (float)pmt->tdc_tw; |
311 |
|
|
// Int_t pppid = tof->GetPMTid(hh,gg); |
312 |
|
|
// printf(" pm %i pmt_id %i pppid %i hh %i gg %i tdcc %f tdc %f adc %f \n",pm,pmt->pmt_id,pppid,hh,gg,pmt->tdc_tw,pmt->tdc,pmt->adc); |
313 |
|
|
}; |
314 |
|
|
|
315 |
|
|
|
316 |
|
|
// for (Int_t pm=0; pm <48 ; pm++){ |
317 |
|
|
// tof->GetPMTIndex(pm, gg, hh); |
318 |
|
|
// tofinput_.tdc[hh][gg] = (int)500.; |
319 |
|
|
// tofinput_.adc[hh][gg] = (int)500.; |
320 |
|
|
// tdc[hh][gg] = (int)500.; |
321 |
|
|
// adc[hh][gg] = (int)500.; |
322 |
|
|
// // printf(" hh %i gg %i tdc %f adc %f \n",hh,gg,pmt->tdc,pmt->adc); |
323 |
|
|
// }; |
324 |
|
|
// |
325 |
|
|
for (Int_t hh=0; hh<5;hh++){ |
326 |
|
|
tofinput_.patterntrig[hh]=pam_event->GetTrigLevel2()->patterntrig[hh]; |
327 |
|
|
}; |
328 |
|
|
// |
329 |
|
|
tof->Clear(); |
330 |
|
|
Int_t pmt_id = 0; |
331 |
|
|
ToFPMT *t_pmt = new ToFPMT(); |
332 |
|
|
if(!(tof->PMT))tof->PMT = new TClonesArray("ToFPMT",12); //ELENA |
333 |
|
|
TClonesArray &tpmt = *tof->PMT; |
334 |
|
|
ToFTrkVar *t_tof = new ToFTrkVar(); |
335 |
|
|
if(!(tof->ToFTrk))tof->ToFTrk = new TClonesArray("ToFTrkVar",2); //ELENA |
336 |
|
|
TClonesArray &t = *tof->ToFTrk; |
337 |
|
|
// |
338 |
|
|
// |
339 |
|
|
// Here we have calibrated data, ready to be passed to the FORTRAN routine which will extract common and track-related variables. |
340 |
|
|
// |
341 |
|
|
npmtentry = 0; |
342 |
|
|
// |
343 |
|
|
ntrkentry = 0; |
344 |
|
|
// |
345 |
|
|
// Calculate tracks informations from ToF alone |
346 |
|
|
// |
347 |
|
|
tofl2com(); |
348 |
|
|
// |
349 |
|
|
memcpy(tof->tof_j_flag,tofoutput_.tof_j_flag,6*sizeof(Int_t)); |
350 |
|
|
// |
351 |
|
|
t_tof->trkseqno = -1; |
352 |
|
|
// |
353 |
|
|
// and now we must copy from the output structure to the level2 class: |
354 |
|
|
// |
355 |
|
|
t_tof->npmttdc = 0; |
356 |
|
|
// |
357 |
|
|
for (Int_t hh=0; hh<12;hh++){ |
358 |
|
|
for (Int_t kk=0; kk<4;kk++){ |
359 |
|
|
if ( tofoutput_.tofmask[hh][kk] != 0 ){ |
360 |
|
|
pmt_id = tof->GetPMTid(kk,hh); |
361 |
|
|
t_tof->pmttdc.AddAt(pmt_id,t_tof->npmttdc); |
362 |
|
|
t_tof->tdcflag.AddAt(tofoutput_.tdcflagtof[hh][kk],t_tof->npmttdc); // gf: Jan 09/07 |
363 |
|
|
t_tof->npmttdc++; |
364 |
|
|
}; |
365 |
|
|
}; |
366 |
|
|
}; |
367 |
|
|
for (Int_t kk=0; kk<13;kk++){ |
368 |
|
|
t_tof->beta[kk] = tofoutput_.betatof_a[kk]; |
369 |
|
|
} |
370 |
|
|
// |
371 |
|
|
t_tof->npmtadc = 0; |
372 |
|
|
for (Int_t hh=0; hh<12;hh++){ |
373 |
|
|
for (Int_t kk=0; kk<4;kk++){ |
374 |
|
|
if ( tofoutput_.adctof_c[hh][kk] < 1000 ){ |
375 |
|
|
// t_tof->dedx.AddAt(tofoutput_.adctof_c[hh][kk],t_tof->npmtadc); // EMILIANO |
376 |
|
|
pmt_id = tof->GetPMTid(kk,hh); |
377 |
|
|
t_tof->dedx.AddAt((tofoutput_.adctof_c[hh][kk]*4./dedx_corr[pmt_id]),t_tof->npmtadc); // EMILIANO |
378 |
|
|
t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc); |
379 |
|
|
t_tof->adcflag.AddAt(tofoutput_.adcflagtof[hh][kk],t_tof->npmtadc); // gf: Jan 09/07 |
380 |
|
|
t_tof->npmtadc++; |
381 |
|
|
}; |
382 |
|
|
}; |
383 |
|
|
}; |
384 |
|
|
// |
385 |
|
|
memcpy(t_tof->xtofpos,tofoutput_.xtofpos,sizeof(t_tof->xtofpos)); |
386 |
|
|
memcpy(t_tof->ytofpos,tofoutput_.ytofpos,sizeof(t_tof->ytofpos)); |
387 |
|
|
memcpy(t_tof->xtr_tof,tofoutput_.xtr_tof,sizeof(t_tof->xtr_tof)); |
388 |
|
|
memcpy(t_tof->ytr_tof,tofoutput_.ytr_tof,sizeof(t_tof->ytr_tof)); |
389 |
|
|
// |
390 |
|
|
new(t[ntrkentry]) ToFTrkVar(*t_tof); |
391 |
|
|
ntrkentry++; |
392 |
|
|
t_tof->Clear(); |
393 |
|
|
// |
394 |
|
|
// |
395 |
|
|
// |
396 |
|
|
t_pmt->Clear(); |
397 |
|
|
// |
398 |
|
|
for (Int_t hh=0; hh<12;hh++){ |
399 |
|
|
for (Int_t kk=0; kk<4;kk++){ |
400 |
|
|
// new WM |
401 |
|
|
// if ( tofoutput_.tdc_c[hh][kk] < 4095 || adc[kk][hh] < 4095 || tdc[kk][hh] < 4095 ){ |
402 |
|
|
if ( tdcc[kk][hh] < 4095. || adc[kk][hh] < 4095 || tdc[kk][hh] < 4095 ){ |
403 |
|
|
// |
404 |
|
|
t_pmt->pmt_id = tof->GetPMTid(kk,hh); |
405 |
|
|
t_pmt->tdc_tw = tofoutput_.tdc_c[hh][kk]; |
406 |
|
|
t_pmt->adc = (Float_t)adc[kk][hh]; |
407 |
|
|
t_pmt->tdc = (Float_t)tdc[kk][hh]; |
408 |
|
|
// |
409 |
|
|
new(tpmt[npmtentry]) ToFPMT(*t_pmt); |
410 |
|
|
npmtentry++; |
411 |
|
|
t_pmt->Clear(); |
412 |
|
|
}; |
413 |
|
|
}; |
414 |
|
|
}; |
415 |
|
|
// |
416 |
|
|
// Calculate track-related variables |
417 |
|
|
// |
418 |
|
|
if ( pam_event->GetTrkLevel2()->ntrk() > 0 ){ |
419 |
|
|
// |
420 |
|
|
// We have at least one track |
421 |
|
|
// |
422 |
|
|
// |
423 |
|
|
// Run over tracks |
424 |
|
|
// |
425 |
|
|
for(Int_t nt=0; nt < pam_event->GetTrkLevel2()->ntrk(); nt++){ |
426 |
|
|
// |
427 |
|
|
TrkTrack *ptt = pam_event->GetTrkLevel2()->GetStoredTrack(nt); |
428 |
|
|
// |
429 |
|
|
// Copy the alpha vector in the input structure |
430 |
|
|
// |
431 |
|
|
for (Int_t e = 0; e < 5 ; e++){ |
432 |
|
|
tofinput_.al_pp[e] = ptt->al[e]; |
433 |
|
|
}; |
434 |
|
|
// |
435 |
|
|
// Get tracker related variables for this track |
436 |
|
|
// |
437 |
|
|
toftrk(); |
438 |
|
|
// toftrk(thelp); |
439 |
|
|
// |
440 |
|
|
// Copy values in the class from the structure (we need to use a temporary class to store variables). |
441 |
|
|
// |
442 |
|
|
t_tof->npmttdc = 0; |
443 |
|
|
for (Int_t hh=0; hh<12;hh++){ |
444 |
|
|
for (Int_t kk=0; kk<4;kk++){ |
445 |
|
|
if ( tofoutput_.tofmask[hh][kk] != 0 ){ |
446 |
|
|
pmt_id = tof->GetPMTid(kk,hh); |
447 |
|
|
t_tof->pmttdc.AddAt(pmt_id,t_tof->npmttdc); |
448 |
|
|
t_tof->tdcflag.AddAt(tofoutput_.tdcflag[hh][kk],t_tof->npmttdc); // gf: Jan 09/07 |
449 |
|
|
t_tof->npmttdc++; |
450 |
|
|
}; |
451 |
|
|
}; |
452 |
|
|
}; |
453 |
|
|
for (Int_t kk=0; kk<13;kk++){ |
454 |
|
|
t_tof->beta[kk] = tofoutput_.beta_a[kk]; |
455 |
|
|
}; |
456 |
|
|
// |
457 |
|
|
t_tof->npmtadc = 0; |
458 |
|
|
for (Int_t hh=0; hh<12;hh++){ |
459 |
|
|
for (Int_t kk=0; kk<4;kk++){ |
460 |
|
|
if ( tofoutput_.adc_c[hh][kk] < 1000 ){ |
461 |
|
|
// t_tof->dedx.AddAt(tofoutput_.adc_c[hh][kk],t_tof->npmtadc); // EMILIANO |
462 |
|
|
pmt_id = tof->GetPMTid(kk,hh); |
463 |
|
|
t_tof->dedx.AddAt((tofoutput_.adc_c[hh][kk]*4./dedx_corr[pmt_id]),t_tof->npmtadc); // EMILIANO |
464 |
|
|
t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc); |
465 |
|
|
t_tof->adcflag.AddAt(tofoutput_.adcflag[hh][kk],t_tof->npmtadc); // gf: Jan 09/07 |
466 |
|
|
t_tof->npmtadc++; |
467 |
|
|
}; |
468 |
|
|
}; |
469 |
|
|
}; |
470 |
|
|
// |
471 |
|
|
memcpy(t_tof->xtofpos,tofoutput_.xtofpos,sizeof(t_tof->xtofpos)); |
472 |
|
|
memcpy(t_tof->ytofpos,tofoutput_.ytofpos,sizeof(t_tof->ytofpos)); |
473 |
|
|
memcpy(t_tof->xtr_tof,tofoutput_.xtr_tof,sizeof(t_tof->xtr_tof)); |
474 |
|
|
memcpy(t_tof->ytr_tof,tofoutput_.ytr_tof,sizeof(t_tof->ytr_tof)); |
475 |
|
|
// |
476 |
|
|
// Store the tracker track number in order to be sure to have shyncronized data during analysis |
477 |
|
|
// |
478 |
|
|
t_tof->trkseqno = nt; |
479 |
|
|
// |
480 |
|
|
// create a new object for this event with track-related variables |
481 |
|
|
// |
482 |
|
|
new(t[ntrkentry]) ToFTrkVar(*t_tof); |
483 |
|
|
ntrkentry++; |
484 |
|
|
t_tof->Clear(); |
485 |
|
|
// |
486 |
|
|
}; // loop on all the tracks |
487 |
|
|
}; |
488 |
|
|
// |
489 |
|
|
tof->unpackError = tofl2->unpackError; |
490 |
|
|
if ( defcal ){ |
491 |
|
|
tof->default_calib = 1; |
492 |
|
|
} else { |
493 |
|
|
tof->default_calib = 0; |
494 |
|
|
}; |
495 |
|
|
// |
496 |
|
|
// Fill the rootple |
497 |
|
|
// |
498 |
|
|
toft->Fill(); |
499 |
|
|
// |
500 |
|
|
// toft->Show(); |
501 |
|
|
// toftr->Show(); |
502 |
|
|
// |
503 |
|
|
delete t_tof; |
504 |
|
|
// |
505 |
|
|
// |
506 |
|
|
}; |
507 |
|
|
// |
508 |
|
|
}; |
509 |
|
|
// |
510 |
|
|
pam_event->Clear(); |
511 |
|
|
// |
512 |
|
|
outft->cd(); |
513 |
|
|
pam_event->WriteCloneTrees(); |
514 |
|
|
toftr->Delete(); |
515 |
|
|
|
516 |
|
|
toft->Write(); |
517 |
|
|
outft->Close(); |
518 |
|
|
// |
519 |
|
|
return 0; |
520 |
|
|
// |
521 |
|
|
} |
522 |
|
|
|
523 |
|
|
///////////////////////////////////////////////////////////////// |
524 |
|
|
|
525 |
|
|
#if !defined(__CINT__) |
526 |
|
|
|
527 |
|
|
void usage(){ |
528 |
|
|
|
529 |
|
|
cout << "------------------------------------------------------------"<<endl; |
530 |
|
|
cout << "Loop over events (on one or more Level2-files), applying some selection cuts (defined in My-Selection.cpp), \n"; |
531 |
|
|
cout << "creating output histograms (defined in My-Histos.cpp) and/or trees with selected events. \n \n "; |
532 |
|
|
cout << "USAGE:"<<endl; |
533 |
|
|
cout << "-processDir DIR - Level2 data directory \n"; |
534 |
|
|
cout << "-processList LIST - list of files (.txt) or single file (.root) to be analysed \n"; |
535 |
|
|
cout << "-outputFile PATH - name of the output file \n"; |
536 |
|
|
cout << "-NumEvents XXX - number of events to be analysed \n"; |
537 |
|
|
cout << "--debug, -g - debug mode \n"; |
538 |
|
|
cout << "--help, -h - print this help \n"; |
539 |
|
|
cout << "-options [ options ] - options: \n"; |
540 |
|
|
cout << " fillHistos --> create an output file with histograms \n"; |
541 |
|
|
cout << " fillTree --> create an output file with trees storing the selected events \n "; |
542 |
|
|
cout << " +(-)ALL --> inlcude(exclude) all trees and branches \n " ; |
543 |
|
|
cout << " +(-)TRK1 +(-)TRK2 +(-)CAL1 +(-)CAL2 +(-)TOF +(-)TRG +(-)ND +(-)S4 +(-)ORB --> inlcude(exclude) trees and branches \n" ; |
544 |
|
|
cout << "------------------------------------------------------------"<<endl; |
545 |
|
|
} |
546 |
|
|
// |
547 |
|
|
int HandleInputPar(int argc, char **argv){ |
548 |
|
|
|
549 |
|
|
if(argc>1){ |
550 |
|
|
|
551 |
|
|
if(!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help") ){ |
552 |
|
|
usage(); |
553 |
|
|
return(1); |
554 |
|
|
}; |
555 |
|
|
// ----------------------- |
556 |
|
|
// Read input parameters |
557 |
|
|
// ----------------------- |
558 |
|
|
DIR = gSystem->WorkingDirectory(); |
559 |
|
|
LIST = ""; |
560 |
|
|
OUTF = "myfile"; |
561 |
|
|
OPTIONS = "+AUTO -TOF"; |
562 |
|
|
|
563 |
|
|
for (int i = 1; i < argc; i++){ |
564 |
|
|
// -----------------------------------------------------// |
565 |
|
|
if (!strcmp(argv[i], "-processDir")){ |
566 |
|
|
if (++i >= argc) throw -1; |
567 |
|
|
DIR = argv[i]; |
568 |
|
|
cout << "processDir "<<DIR<<endl; |
569 |
|
|
continue; |
570 |
|
|
} |
571 |
|
|
// -----------------------------------------------------// |
572 |
|
|
else if (!strcmp(argv[i], "-processList")){ |
573 |
|
|
if (++i >= argc) throw -1; |
574 |
|
|
LIST = argv[i]; |
575 |
|
|
cout << "processList "<<LIST<<endl; |
576 |
|
|
continue; |
577 |
|
|
} |
578 |
|
|
// -----------------------------------------------------// |
579 |
|
|
else if (!strcmp(argv[i], "-outputFile")){ |
580 |
|
|
if (++i >= argc) throw -1; |
581 |
|
|
OUTF = argv[i]; |
582 |
|
|
cout << "outputFile "<<OUTF<<endl; |
583 |
|
|
continue; |
584 |
|
|
} |
585 |
|
|
// -----------------------------------------------------// |
586 |
|
|
else if (!strcmp(argv[i], "-options")){ |
587 |
|
|
if (++i >= argc) throw -1; |
588 |
|
|
OPTIONS = argv[i]; |
589 |
|
|
if( OPTIONS.Contains("[") ){ |
590 |
|
|
do{ |
591 |
|
|
if (++i >= argc) throw -1; |
592 |
|
|
OPTIONS.Append(argv[i]); |
593 |
|
|
}while(!OPTIONS.Contains("]")); |
594 |
|
|
}else cout << "wrong option format --> ignoring " << endl; |
595 |
|
|
} |
596 |
|
|
else{ |
597 |
|
|
cout << "Unidentified input parameter. Ignored."<< endl; |
598 |
|
|
}; |
599 |
|
|
}; |
600 |
|
|
}else{ |
601 |
|
|
usage(); |
602 |
|
|
return(1); |
603 |
|
|
}; |
604 |
|
|
// ----------------------- |
605 |
|
|
// Check input parameters |
606 |
|
|
// ----------------------- |
607 |
|
|
|
608 |
|
|
|
609 |
|
|
return(0); |
610 |
|
|
|
611 |
|
|
}; |
612 |
|
|
// |
613 |
|
|
|
614 |
|
|
int main(int argc, char **argv) |
615 |
|
|
{ |
616 |
|
|
|
617 |
|
|
if( HandleInputPar(argc,argv) )return(1); |
618 |
|
|
|
619 |
|
|
cout << "OPTIONS "<<OPTIONS<<endl; |
620 |
|
|
Loop(DIR,LIST,OPTIONS); |
621 |
|
|
|
622 |
|
|
cout << "Back to main - end"<<endl; |
623 |
|
|
|
624 |
|
|
return 0; |
625 |
|
|
|
626 |
|
|
}; |
627 |
|
|
|
628 |
|
|
#endif |