/[PAMELA software]/tof/flight/ToFReprocessing/ToFreproc.cpp
ViewVC logotype

Contents of /tof/flight/ToFReprocessing/ToFreproc.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (show annotations) (download)
Wed Mar 10 12:31:40 2010 UTC (14 years, 8 months ago) by mocchiut
Branch: MAIN
Changes since 1.4: +1 -1 lines
Expand path of input calibration

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 TString CALIBF;
61
62 PamLevel2 *pam_event = NULL;
63
64 //==========================================
65 //000000000000000000000000000000000000000000
66 //==========================================
67 Int_t Loop(TString ddir,TString list, TString options){
68 //
69 //
70 extern struct ToFInput tofinput_;
71 extern struct ToFOutput tofoutput_;
72 // --------------------
73 // read input file/list
74 // --------------------
75 pam_event = new PamLevel2(ddir,list,options);
76 pam_event->SetSELLI(2);
77 TTree::SetMaxTreeSize(1000*Long64_t(2000000000));
78 //
79 TString outfile_t = "";
80 outfile_t = OUTF;
81 outfile_t.Append(".root");
82 TFile *outft = (TFile*)gROOT->FindObject(outfile_t);
83 if (outft) outft->Close();
84 outft = new TFile(outfile_t,"RECREATE");
85 if(outft->IsZombie()){
86 cout << "Output file could not be created\n";
87 return 1;
88 };
89 cout << "Created output file: "<<outft->GetName()<<endl;
90 //
91 outft->cd();
92 ToFLevel2 *tof = new ToFLevel2();
93 ToFdEdx *tofdedx = new ToFdEdx();
94 TTree *toft = new TTree("ToF","PAMELA Level2 ToF data");
95 toft->SetAutoSave(900000000000000LL);
96 tof->Set();//ELENA **TEMPORANEO?**
97 toft->Branch("ToFLevel2","ToFLevel2",&tof);
98 //
99 pam_event->CreateCloneTrees(outft);
100 //
101 Int_t ntrkentry = 0;
102 Int_t npmtentry = 0;
103 Float_t xleft=0;
104 Float_t xright=0;
105 Float_t yleft=0;
106 Float_t yright=0;
107 //
108 ULong64_t nevents = pam_event->GetEntries();
109 printf("\n\n Running on %llu events \n\n",nevents);
110 //
111 TFile *tfile = TFile::Open(list.Data(),"READ");
112 TTree *toftr = (TTree*)tfile->Get("ToF");
113 ToFLevel2 *tofl2 = new ToFLevel2();
114 toftr->SetBranchAddress("ToFLevel2", &tofl2);
115 ULong64_t ntofev = toftr->GetEntries();
116 printf(" ToF events are %llu \n",ntofev);
117 //
118 //
119 GL_PARAM *glparam = new GL_PARAM();
120 TrkLevel2 *trk = new TrkLevel2();
121 //
122 TString host;
123 TString user;
124 TString psw;
125 const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");
126 const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");
127 const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");
128 if ( !pamdbhost ) pamdbhost = "";
129 if ( !pamdbuser ) pamdbuser = "";
130 if ( !pamdbpsw ) pamdbpsw = "";
131 if ( strcmp(pamdbhost,"") ) host = pamdbhost;
132 if ( strcmp(pamdbuser,"") ) user = pamdbuser;
133 if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;
134 //
135 //
136 TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
137 if ( !dbc->IsConnected() ) return 1;
138 stringstream myquery;
139 myquery.str("");
140 myquery << "SET time_zone='+0:00'";
141 dbc->Query(myquery.str().c_str());
142 glparam->Query_GL_PARAM(1,1,dbc); // parameters stored in DB in GL_PRAM table
143 trk->LoadField(glparam->PATH+glparam->NAME);
144 //
145 Long64_t myrun = 0;
146 Long64_t mysrun = -1;
147 Int_t adc[4][12];
148 Int_t tdc[4][12];
149 Float_t tdcc[4][12];
150 //
151 Bool_t defcal = true;
152 for(ULong64_t iev=0; iev<nevents; iev++){
153
154
155 //==================================================================
156
157
158 // for(ULong64_t iev=0; iev<50; iev++){
159 //
160 if ( !(iev%1000) ) printf(" %iK \n",(int)iev/1000);
161 pam_event->Clear();
162 //
163 if( pam_event->GetEntry(iev) ){
164 //
165 pam_event->FillCloneTrees();
166 toftr->GetEntry(iev);
167 //
168 // variable to save information about the tof calibration used
169 //
170 //
171 myrun=pam_event->GetRunInfo()->ID;
172 if ( myrun != mysrun ){
173 // printf(" rhtime %u myrun %i mysrun %i \n",pam_event->GetRunInfo()->RUNHEADER_TIME,(int)myrun,(int)mysrun);
174 mysrun = myrun;
175 //
176
177
178
179
180 Int_t error=glparam->Query_GL_PARAM(pam_event->GetRunInfo()->RUNHEADER_TIME,204,dbc); // parameters stored in DB in GL_PRAM table
181 if ( error<0 ) {
182 return(1);
183 };
184 //
185 tofdedx->ReadParAtt((glparam->PATH+glparam->NAME).Data());
186
187 //
188 error=glparam->Query_GL_PARAM(pam_event->GetRunInfo()->RUNHEADER_TIME,205,dbc); // parameters stored in DB in GL_PRAM table
189 if ( error<0 ) {
190 return(1);
191 };
192 //
193 tofdedx->ReadParPos((glparam->PATH+glparam->NAME).Data());
194
195 //
196 error=glparam->Query_GL_PARAM(pam_event->GetRunInfo()->RUNHEADER_TIME,206,dbc); // parameters stored in DB in GL_PRAM table
197 if ( error<0 ) {
198 return(1);
199 };
200 //
201 tofdedx->ReadParBBneg((glparam->PATH+glparam->NAME).Data());
202
203 //
204 error=glparam->Query_GL_PARAM(pam_event->GetRunInfo()->RUNHEADER_TIME,207,dbc); // parameters stored in DB in GL_PRAM table
205 if ( error<0 ) {
206 return(1);
207 };
208 //
209 tofdedx->ReadParBBpos((glparam->PATH+glparam->NAME).Data());
210
211 //
212 error=glparam->Query_GL_PARAM(pam_event->GetRunInfo()->RUNHEADER_TIME,208,dbc); // parameters stored in DB in GL_PRAM table
213 if ( error<0 ) {
214 return(1);
215 };
216 //
217 tofdedx->ReadParDesatBB((glparam->PATH+glparam->NAME).Data());
218
219
220 tofdedx->CheckConnectors(pam_event->GetRunInfo()->RUNHEADER_TIME,glparam,dbc);
221
222
223
224 error=glparam->Query_GL_PARAM(pam_event->GetRunInfo()->RUNHEADER_TIME,201,dbc); // parameters stored in DB in GL_PRAM table
225 if ( error<0 ) {
226 return(1);
227 };
228 //
229 printf(" Reading ToF parameter file: %s \n",(glparam->PATH+glparam->NAME).Data());
230 //
231 if ( (UInt_t)glparam->TO_TIME != (UInt_t)4294967295UL ) defcal = false;
232 //
233 Int_t nlen = (Int_t)(glparam->PATH+glparam->NAME).Length();
234 rdtofcal((char *)(glparam->PATH+glparam->NAME).Data(),&nlen);
235 //
236 };
237 //
238
239
240 //================================================================
241 //==================================================================
242 //--- Define absolute time
243 UInt_t tabs=pam_event->GetOrbitalInfo()->absTime;
244
245 if ( !(iev%1000) ) printf(" ATIME %u re %u \n",(Int_t)tabs,(UInt_t)iev);
246
247 //==================================================================
248 Float_t dedx_corr_m[2000][48],dedx_corr[48];
249 Double_t mtime[2000],t1,t2,tm;
250 Float_t yhelp1,yhelp2,slope,inter,thelp1,thelp2;
251 Float_t xmean1,xwidth1;
252
253 Int_t ical,ii,j,jj;
254
255 if (iev==0) {
256
257 ical=0; // counter set to zero if first-time reading
258
259 //-----------------------------------------------------------
260 // Here I read the dEdx_korr parameters
261 //-----------------------------------------------------------
262
263 jj=0;
264 printf(" READING NEW CALIBRATION FILE: %s \n",CALIBF.Data());
265
266 ifstream fin(CALIBF.Data());
267
268 while (! fin.eof()) {
269 fin>>t1>>tm>>t2;
270 // cout<<jj<<" "<<tm<<endl;
271 cout << setiosflags(ios::fixed) << setw(10) << setprecision(3) << tm << endl;
272 mtime[jj]=tm;
273 for (ii=0; ii<48;ii++) {
274 fin>>j>>xmean1>>xwidth1;
275 dedx_corr_m[jj][ii]=xmean1;
276 }
277 jj=jj+1;
278 // printf(" kk %i \n",jj);
279 }
280 // printf(" 1ical %i \n",ical);
281
282 fin.close();
283
284
285 while (tabs<mtime[ical] || tabs > mtime[ical+1]) {
286 // printf(" ical %i \n",ical);
287 ical = ical+1;
288 }
289 // ical = ical-1;
290 cout<<"abs time "<<tabs<<" limit low "<<mtime[ical]<<" limit up "<<mtime[ical+1]<<" ical "<<ical<<endl;
291 } // if iev==0...
292
293 //==================================================================
294 //== End of first time reading & filling the array
295 //==================================================================
296
297 //==================================================================
298 //== if time is outside time limits:
299 //==================================================================
300
301 if (tabs<mtime[ical] || tabs>mtime[ical+1]) {
302 cout<<"Checking Time Limits!"<<endl;
303 ical=0;
304 while (tabs > mtime[ical+1] || tabs<mtime[ical]) {
305 ical = ical+1;
306 }
307 // ical = ical-1;
308 cout<<"abs time "<<tabs<<" limit low "<<mtime[ical]<<" limit up "<<mtime[ical+1]<<" ical "<<ical<<endl;
309 };
310
311 // printf(" 2ical %i \n",ical);
312 //==================================================================
313 //== interpolate betwen time limits
314 //==================================================================
315
316 thelp1 = mtime[ical];
317 thelp2 = mtime[ical+1];
318
319 for (ii=0; ii<48;ii++) {
320 yhelp1 = fabs(dedx_corr_m[ical][ii]);
321 // yhelp1 = 6.;
322 if ( yhelp1 < 0.1 ) yhelp1 = 4.;
323 yhelp2 = fabs(dedx_corr_m[ical+1][ii]);
324 // yhelp2 = 6.;
325 if ( yhelp2 < 0.1 ) yhelp2 = 4.;
326 slope = (yhelp2-yhelp1)/(thelp2-thelp1);
327 inter = yhelp1 - slope*thelp1;
328 dedx_corr[ii] = slope*tabs + inter;
329 // if (ii==0) cout<<thelp1<<" "<<thelp2<<" "<<tabs<<" "<<yhelp1<<" "<<yhelp2<<" "<<dedx_corr[0]<<endl;
330 }
331
332 //================================================================
333 //================================================================
334 // printf("cpippo \n");
335
336 // process tof data
337 //
338 for (Int_t hh=0; hh<12;hh++){
339 for (Int_t kk=0; kk<4;kk++){
340 adc[kk][hh] = 4095;
341 tdc[kk][hh] = 4095;
342 tdcc[kk][hh] = 4095.;
343 tofinput_.adc[hh][kk] = 4095;
344 tofinput_.tdc[hh][kk] = 4095;
345 };
346 };
347 // memset(adc, 0, 12*4*sizeof(Int_t));
348 // memset(tdc, 0, 12*4*sizeof(Int_t));
349 Int_t gg = 0;
350 Int_t hh = 0;
351 Int_t adcf[48];
352 memset(adcf, 0, 48*sizeof(Int_t));
353 Int_t tdcf[48];
354 memset(tdcf, 0, 48*sizeof(Int_t));
355 for (Int_t pm=0; pm < tofl2->ntrk() ; pm++){
356 ToFTrkVar *ttf = tofl2->GetToFTrkVar(pm);
357 for ( Int_t nc=0; nc < ttf->npmttdc; nc++){
358 if ( (ttf->tdcflag).At(nc) != 0 ) tdcf[(ttf->pmttdc).At(nc)] = 1;
359 };
360 for ( Int_t nc=0; nc < ttf->npmtadc; nc++){
361 if ( (ttf->adcflag).At(nc) != 0 ) adcf[(ttf->pmtadc).At(nc)] = 1;
362 };
363 };
364 //
365 for (Int_t pm=0; pm < tofl2->npmt() ; pm++){
366 ToFPMT *pmt = tofl2->GetToFPMT(pm);
367 tofl2->GetPMTIndex(pmt->pmt_id, gg, hh);
368 if ( adcf[pmt->pmt_id] == 0 ){
369 tofinput_.adc[gg][hh] = (int)pmt->adc;
370 adc[hh][gg] = (int)pmt->adc;
371 };
372 if ( tdcf[pmt->pmt_id] == 0 ){
373 tofinput_.tdc[gg][hh] = (int)pmt->tdc;
374 tdc[hh][gg] = (int)pmt->tdc;
375 };
376 tdcc[hh][gg] = (float)pmt->tdc_tw;
377 // Int_t pppid = tof->GetPMTid(hh,gg);
378 // 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);
379 };
380 for (Int_t hh=0; hh<12;hh++){
381 for (Int_t kk=0; kk<4;kk++){
382 tofdedx->Init(kk,hh,adc[kk][hh]);
383 };
384 };
385 // for (Int_t pm=0; pm <48 ; pm++){
386 // tof->GetPMTIndex(pm, gg, hh);
387 // tofinput_.tdc[hh][gg] = (int)500.;
388 // tofinput_.adc[hh][gg] = (int)500.;
389 // tdc[hh][gg] = (int)500.;
390 // adc[hh][gg] = (int)500.;
391 // // printf(" hh %i gg %i tdc %f adc %f \n",hh,gg,pmt->tdc,pmt->adc);
392 // };
393 //
394 for (Int_t hh=0; hh<5;hh++){
395 tofinput_.patterntrig[hh]=pam_event->GetTrigLevel2()->patterntrig[hh];
396 };
397 //
398 tof->Clear();
399 Int_t pmt_id = 0;
400 ToFPMT *t_pmt = new ToFPMT();
401 if(!(tof->PMT))tof->PMT = new TClonesArray("ToFPMT",12); //ELENA
402 TClonesArray &tpmt = *tof->PMT;
403 ToFTrkVar *t_tof = new ToFTrkVar();
404 if(!(tof->ToFTrk))tof->ToFTrk = new TClonesArray("ToFTrkVar",2); //ELENA
405 TClonesArray &t = *tof->ToFTrk;
406 //
407 //
408 // Here we have calibrated data, ready to be passed to the FORTRAN routine which will extract common and track-related variables.
409 //
410 npmtentry = 0;
411 //
412 ntrkentry = 0;
413 //
414 // Calculate tracks informations from ToF alone
415 //
416 tofl2com();
417 //
418 memcpy(tof->tof_j_flag,tofoutput_.tof_j_flag,6*sizeof(Int_t));
419 //
420 t_tof->trkseqno = -1;
421 //
422 // and now we must copy from the output structure to the level2 class:
423 //
424 t_tof->npmttdc = 0;
425 //
426 for (Int_t hh=0; hh<12;hh++){
427 for (Int_t kk=0; kk<4;kk++){
428 if ( tofoutput_.tofmask[hh][kk] != 0 ){
429 pmt_id = tof->GetPMTid(kk,hh);
430 t_tof->pmttdc.AddAt(pmt_id,t_tof->npmttdc);
431 t_tof->tdcflag.AddAt(tofoutput_.tdcflagtof[hh][kk],t_tof->npmttdc); // gf: Jan 09/07
432 t_tof->npmttdc++;
433 };
434 };
435 };
436 for (Int_t kk=0; kk<13;kk++){
437 t_tof->beta[kk] = tofoutput_.betatof_a[kk];
438 }
439 //
440 memcpy(t_tof->xtofpos,tofoutput_.xtofpos,sizeof(t_tof->xtofpos));
441 memcpy(t_tof->ytofpos,tofoutput_.ytofpos,sizeof(t_tof->ytofpos));
442 memcpy(t_tof->xtr_tof,tofoutput_.xtr_tof,sizeof(t_tof->xtr_tof));
443 memcpy(t_tof->ytr_tof,tofoutput_.ytr_tof,sizeof(t_tof->ytr_tof));
444 // {
445 // Float_t xtof_temp[6]={0.,t_tof->xtofpos[0],t_tof->xtofpos[1],0.,0.,t_tof->xtofpos[2]};
446 // Float_t ytof_temp[6]={t_tof->ytofpos[0],0.,0.,t_tof->ytofpos[1],t_tof->ytofpos[2],0.};
447 // tofdedx->Process(pam_event->GetOrbitalInfo()->absTime,t_tof->beta[12], (Float_t *)xtof_temp,(Float_t *)ytof_temp);
448 // }
449 // t_tof->npmtadc = 0;
450
451
452 // for (Int_t hh=0; hh<12;hh++){
453 // for (Int_t kk=0; kk<4;kk++){
454 // pmt_id = tof->GetPMTid(kk,hh);
455 // if ( tofdedx->GetdEdx_pmt(pmt_id)>-1. ){
456 // t_tof->dedx.AddAt((tofdedx->GetdEdx_pmt(pmt_id)*36./pow(dedx_corr[pmt_id],2)),t_tof->npmtadc);
457 // t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc);
458 // t_tof->adcflag.AddAt(0,t_tof->npmtadc); // gf: Jan 09/07
459 // t_tof->npmtadc++;
460 // };
461 // };
462 // };
463 {
464
465 Float_t xtof_temp[6]={100.,100.,100.,100.,100.,100.};
466 Float_t ytof_temp[6]={100.,100.,100.,100.,100.,100.};
467
468 if(t_tof->xtofpos[0]<100. && t_tof->ytofpos[0]<100.){
469 xtof_temp[1]=t_tof->xtofpos[0];
470 ytof_temp[0]=t_tof->ytofpos[0];
471 }else if(t_tof->xtofpos[0]>=100. && t_tof->ytofpos[0]<100.){
472 ytof_temp[0]=t_tof->ytofpos[0];
473 tof->GetPaddleGeometry(0,(Int_t)log2(tof->tof_j_flag[0]),xleft, xright, yleft, yright);
474 xtof_temp[1]=xleft+2.55;
475 }else if(t_tof->ytofpos[0]>=100. && t_tof->xtofpos[0]<100.){
476 xtof_temp[1]=t_tof->xtofpos[0];
477 tof->GetPaddleGeometry(1,(Int_t)log2(tof->tof_j_flag[1]),xleft, xright, yleft, yright);
478 ytof_temp[0]=yleft+2.75;
479 }
480
481 if(t_tof->xtofpos[1]<100. && t_tof->ytofpos[1]<100.){
482 xtof_temp[2]=t_tof->xtofpos[1];
483 ytof_temp[3]=t_tof->ytofpos[1];
484 }else if(t_tof->xtofpos[1]>=100. && t_tof->ytofpos[1]<100.){
485 ytof_temp[3]=t_tof->ytofpos[1];
486 tof->GetPaddleGeometry(3,(Int_t)log2(tof->tof_j_flag[3]),xleft, xright, yleft, yright);
487 xtof_temp[2]=xleft+4.5;
488 }else if(t_tof->ytofpos[1]>=100. && t_tof->xtofpos[1]<100.){
489 xtof_temp[2]=t_tof->xtofpos[1];
490 tof->GetPaddleGeometry(2,(Int_t)log2(tof->tof_j_flag[2]),xleft, xright, yleft, yright);
491 ytof_temp[3]=yleft+3.75;
492 }
493
494 if(t_tof->xtofpos[2]<100. && t_tof->ytofpos[2]<100.){
495 xtof_temp[5]=t_tof->xtofpos[2];
496 ytof_temp[4]=t_tof->ytofpos[2];
497 }else if(t_tof->xtofpos[2]>=100. && t_tof->ytofpos[2]<100.){
498 ytof_temp[4]=t_tof->ytofpos[2];
499 tof->GetPaddleGeometry(4,(Int_t)log2(tof->tof_j_flag[4]),xleft, xright, yleft, yright);
500 xtof_temp[5]=xleft+3;
501 }else if(t_tof->ytofpos[2]>=100. && t_tof->xtofpos[2]<100.){
502 xtof_temp[5]=t_tof->xtofpos[2];
503 tof->GetPaddleGeometry(5,(Int_t)log2(tof->tof_j_flag[5]),xleft, xright, yleft, yright);
504 ytof_temp[4]=yleft+2.5;
505 }
506 // Float_t xtof_temp[6]={0.,t_tof->xtofpos[0],t_tof->xtofpos[1],0.,0.,t_tof->xtofpos[2]};
507 // Float_t ytof_temp[6]={t_tof->ytofpos[0],0.,0.,t_tof->ytofpos[1],t_tof->ytofpos[2],0.};
508 // tofdedx->Process(atime,t_tof->beta[12], (Float_t *)xtof_temp,(Float_t *)ytof_temp);
509 tofdedx->Process(pam_event->GetOrbitalInfo()->absTime,t_tof->beta[12], (Float_t *)xtof_temp,(Float_t *)ytof_temp);
510 t_tof->npmtadc = 0;
511 for (Int_t hh=0; hh<12;hh++){
512 for (Int_t kk=0; kk<4;kk++){
513 pmt_id = tof->GetPMTid(kk,hh);
514 Int_t Iplane=-1;
515 Int_t Ipaddle=-1;
516 // Int_t IpaddleT=-1;
517 tof->GetPMTPaddle(pmt_id, Iplane, Ipaddle);
518 tof->GetPaddleGeometry(Iplane,Ipaddle,xleft,xright,yleft,yright);
519 if ( tofdedx->GetdEdx_pmt(pmt_id)>-1. &&((xtof_temp[Iplane]>=xleft&&xtof_temp[Iplane]<=xright) || (ytof_temp[Iplane]>=yleft&&ytof_temp[Iplane]<=yright)) ){ //attenzione:qui va inserito un controllo sulla traccia tof o sulle variabili di posizione !!!!
520 t_tof->dedx.AddAt((tofdedx->GetdEdx_pmt(pmt_id)*4./dedx_corr[pmt_id]),t_tof->npmtadc);
521 t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc);
522 t_tof->adcflag.AddAt(0,t_tof->npmtadc); // gf: Jan 09/07
523 t_tof->npmtadc++;
524 };
525 };
526 };
527 };
528
529
530
531
532
533
534
535
536
537
538 // for (Int_t hh=0; hh<12;hh++){
539 // for (Int_t kk=0; kk<4;kk++){
540 // if ( tofoutput_.adctof_c[hh][kk] < 1000 ){
541 // // t_tof->dedx.AddAt(tofoutput_.adctof_c[hh][kk],t_tof->npmtadc); // EMILIANO
542 // pmt_id = tof->GetPMTid(kk,hh);
543 // t_tof->dedx.AddAt((tofoutput_.adctof_c[hh][kk]*4./dedx_corr[pmt_id]),t_tof->npmtadc); // EMILIANO
544 // t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc);
545 // t_tof->adcflag.AddAt(tofoutput_.adcflagtof[hh][kk],t_tof->npmtadc); // gf: Jan 09/07
546 // t_tof->npmtadc++;
547 // };
548 // };
549 // };
550 //
551
552 //
553 new(t[ntrkentry]) ToFTrkVar(*t_tof);
554 ntrkentry++;
555 t_tof->Clear();
556 //
557 //
558 //
559 t_pmt->Clear();
560 //
561 for (Int_t hh=0; hh<12;hh++){
562 for (Int_t kk=0; kk<4;kk++){
563 // new WM
564 // if ( tofoutput_.tdc_c[hh][kk] < 4095 || adc[kk][hh] < 4095 || tdc[kk][hh] < 4095 ){
565 if ( tdcc[kk][hh] < 4095. || adc[kk][hh] < 4095 || tdc[kk][hh] < 4095 ){
566 //
567 t_pmt->pmt_id = tof->GetPMTid(kk,hh);
568 t_pmt->tdc_tw = tofoutput_.tdc_c[hh][kk];
569 t_pmt->adc = (Float_t)adc[kk][hh];
570 t_pmt->tdc = (Float_t)tdc[kk][hh];
571 //
572 new(tpmt[npmtentry]) ToFPMT(*t_pmt);
573 npmtentry++;
574 t_pmt->Clear();
575 };
576 };
577 };
578 //
579 // Calculate track-related variables
580 //
581 if ( pam_event->GetTrkLevel2()->ntrk() > 0 ){
582 //
583 // We have at least one track
584 //
585 //
586 // Run over tracks
587 //
588 for(Int_t nt=0; nt < pam_event->GetTrkLevel2()->ntrk(); nt++){
589 //
590 TrkTrack *ptt = pam_event->GetTrkLevel2()->GetStoredTrack(nt);
591 //
592 // Copy the alpha vector in the input structure
593 //
594 for (Int_t e = 0; e < 5 ; e++){
595 tofinput_.al_pp[e] = ptt->al[e];
596 };
597
598 // new input for 9th reduction: tracker dEdx
599 tofinput_.trkmip = ptt->GetDEDX();
600
601 //
602 // Get tracker related variables for this track
603 //
604 toftrk();
605 // toftrk(thelp);
606 //
607 // Copy values in the class from the structure (we need to use a temporary class to store variables).
608 //
609 t_tof->npmttdc = 0;
610 for (Int_t hh=0; hh<12;hh++){
611 for (Int_t kk=0; kk<4;kk++){
612 if ( tofoutput_.tofmask[hh][kk] != 0 ){
613 pmt_id = tof->GetPMTid(kk,hh);
614 t_tof->pmttdc.AddAt(pmt_id,t_tof->npmttdc);
615 t_tof->tdcflag.AddAt(tofoutput_.tdcflag[hh][kk],t_tof->npmttdc); // gf: Jan 09/07
616 t_tof->npmttdc++;
617 };
618 };
619 };
620 for (Int_t kk=0; kk<13;kk++){
621 t_tof->beta[kk] = tofoutput_.beta_a[kk];
622 };
623 //
624 memcpy(t_tof->xtofpos,tofoutput_.xtofpos,sizeof(t_tof->xtofpos));
625 memcpy(t_tof->ytofpos,tofoutput_.ytofpos,sizeof(t_tof->ytofpos));
626 memcpy(t_tof->xtr_tof,tofoutput_.xtr_tof,sizeof(t_tof->xtr_tof));
627 memcpy(t_tof->ytr_tof,tofoutput_.ytr_tof,sizeof(t_tof->ytr_tof));
628 //
629 tofdedx->Process(pam_event->GetOrbitalInfo()->absTime,t_tof->beta[12], (Float_t *)t_tof->xtr_tof,(Float_t *)t_tof->ytr_tof);
630 t_tof->npmtadc = 0;
631
632 for (Int_t hh=0; hh<12;hh++){
633 for (Int_t kk=0; kk<4;kk++){
634 pmt_id = tof->GetPMTid(kk,hh);
635 Int_t Iplane=-1;
636 Int_t Ipaddle=-1;
637 Int_t IpaddleT=-1;
638 tof->GetPMTPaddle(pmt_id, Iplane, Ipaddle);
639 IpaddleT=tof->GetPaddleIdOfTrack(t_tof->xtr_tof[Iplane],t_tof->ytr_tof[Iplane], Iplane,0.0);
640 if ( tofdedx->GetdEdx_pmt(pmt_id) > -1. && Ipaddle==IpaddleT ){
641 t_tof->dedx.AddAt((tofdedx->GetdEdx_pmt(pmt_id)*4./dedx_corr[pmt_id]),t_tof->npmtadc);
642 t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc);
643 t_tof->adcflag.AddAt(0,t_tof->npmtadc); // gf: Jan 09/07
644 t_tof->npmtadc++;
645 };
646
647 };
648 };
649
650
651 // for (Int_t hh=0; hh<12;hh++){
652 // for (Int_t kk=0; kk<4;kk++){
653 // pmt_id = tof->GetPMTid(kk,hh);
654 // if ( tofdedx->GetdEdx_pmt(pmt_id) > -1. ){
655 // t_tof->dedx.AddAt((tofdedx->GetdEdx_pmt(pmt_id)*36./pow(dedx_corr[pmt_id],2)),t_tof->npmtadc);
656 // t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc);
657 // t_tof->adcflag.AddAt(0,t_tof->npmtadc); // gf: Jan 09/07
658 // printf(" nt %i npmtadc %i dedx %f dedx corr %f\n",nt,t_tof->npmtadc,(tofdedx->GetdEdx_pmt(pmt_id)*36./pow(dedx_corr[pmt_id],2)),dedx_corr[pmt_id]);
659 // t_tof->npmtadc++;
660 // };
661
662 // };
663 // };
664 // t_tof->npmtadc = 0;
665 // for (Int_t hh=0; hh<12;hh++){
666 // for (Int_t kk=0; kk<4;kk++){
667 // if ( tofoutput_.adc_c[hh][kk] < 1000 ){
668 // // t_tof->dedx.AddAt(tofoutput_.adc_c[hh][kk],t_tof->npmtadc); // EMILIANO
669 // pmt_id = tof->GetPMTid(kk,hh);
670 // t_tof->dedx.AddAt((tofoutput_.adc_c[hh][kk]*4./dedx_corr[pmt_id]),t_tof->npmtadc); // EMILIANO
671 // t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc);
672 // t_tof->adcflag.AddAt(tofoutput_.adcflag[hh][kk],t_tof->npmtadc); // gf: Jan 09/07
673 // t_tof->npmtadc++;
674 // };
675 // };
676 // };
677 //
678
679 //
680 // Store the tracker track number in order to be sure to have shyncronized data during analysis
681 //
682 t_tof->trkseqno = nt;
683 //
684 // create a new object for this event with track-related variables
685 //
686 new(t[ntrkentry]) ToFTrkVar(*t_tof);
687 ntrkentry++;
688 t_tof->Clear();
689 //
690 }; // loop on all the tracks
691 };
692 //
693 tof->unpackError = tofl2->unpackError;
694 if ( defcal ){
695 tof->default_calib = 1;
696 } else {
697 tof->default_calib = 0;
698 };
699 //
700 // Fill the rootple
701 //
702 toft->Fill();
703 //
704 // toft->Show();
705 // toftr->Show();
706 //
707 delete t_tof;
708 //
709 //
710 };
711 //
712 };
713 //
714 pam_event->Clear();
715 //
716 outft->cd();
717 pam_event->WriteCloneTrees();
718 toftr->Delete();
719
720 toft->Write();
721 outft->Close();
722 //
723 return 0;
724 //
725 }
726
727 /////////////////////////////////////////////////////////////////
728
729 #if !defined(__CINT__)
730
731 void usage(){
732
733 cout << "------------------------------------------------------------"<<endl;
734 cout << "Loop over events (on one or more Level2-files), applying some selection cuts (defined in My-Selection.cpp), \n";
735 cout << "creating output histograms (defined in My-Histos.cpp) and/or trees with selected events. \n \n ";
736 cout << "USAGE:"<<endl;
737 cout << "-processDir DIR - Level2 data directory \n";
738 cout << "-processList LIST - list of files (.txt) or single file (.root) to be analysed \n";
739 cout << "-outputFile PATH - name of the output file \n";
740 cout << "-calibFile PATH+NAME - name of the calibration file \n";
741 cout << "-NumEvents XXX - number of events to be analysed \n";
742 cout << "--debug, -g - debug mode \n";
743 cout << "--help, -h - print this help \n";
744 cout << "-options [ options ] - options: \n";
745 cout << " fillHistos --> create an output file with histograms \n";
746 cout << " fillTree --> create an output file with trees storing the selected events \n ";
747 cout << " +(-)ALL --> inlcude(exclude) all trees and branches \n " ;
748 cout << " +(-)TRK1 +(-)TRK2 +(-)CAL1 +(-)CAL2 +(-)TOF +(-)TRG +(-)ND +(-)S4 +(-)ORB --> inlcude(exclude) trees and branches \n" ;
749 cout << "------------------------------------------------------------"<<endl;
750 }
751 //
752 int HandleInputPar(int argc, char **argv){
753
754 if(argc>1){
755
756 if(!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help") ){
757 usage();
758 return(1);
759 };
760 // -----------------------
761 // Read input parameters
762 // -----------------------
763 DIR = gSystem->WorkingDirectory();
764 LIST = "";
765 OUTF = "myfile";
766 OPTIONS = "+AUTO -TOF";
767
768 for (int i = 1; i < argc; i++){
769 // -----------------------------------------------------//
770 if (!strcmp(argv[i], "-processDir")){
771 if (++i >= argc) throw -1;
772 DIR = argv[i];
773 cout << "processDir "<<DIR<<endl;
774 continue;
775 }
776 // -----------------------------------------------------//
777 else if (!strcmp(argv[i], "-processList")){
778 if (++i >= argc) throw -1;
779 LIST = argv[i];
780 cout << "processList "<<LIST<<endl;
781 continue;
782 }
783 // -----------------------------------------------------//
784 else if (!strcmp(argv[i], "-outputFile")){
785 if (++i >= argc) throw -1;
786 OUTF = argv[i];
787 cout << "outputFile "<<OUTF<<endl;
788 continue;
789 }
790 // -----------------------------------------------------//
791 // -----------------------------------------------------//
792 else if (!strcmp(argv[i], "-calibFile")){
793 if (++i >= argc) throw -1;
794 CALIBF = gSystem->ExpandPathName(argv[i]);
795 cout << "calibFile "<<CALIBF<<endl;
796 continue;
797 }
798 // -----------------------------------------------------//
799 else if (!strcmp(argv[i], "-options")){
800 if (++i >= argc) throw -1;
801 OPTIONS = argv[i];
802 if( OPTIONS.Contains("[") ){
803 do{
804 if (++i >= argc) throw -1;
805 OPTIONS.Append(argv[i]);
806 }while(!OPTIONS.Contains("]"));
807 }else cout << "wrong option format --> ignoring " << endl;
808 }
809 else{
810 cout << "Unidentified input parameter. Ignored."<< endl;
811 };
812 };
813 }else{
814 usage();
815 return(1);
816 };
817 // -----------------------
818 // Check input parameters
819 // -----------------------
820
821
822 return(0);
823
824 };
825 //
826
827 int main(int argc, char **argv)
828 {
829
830 if( HandleInputPar(argc,argv) )return(1);
831
832 cout << "OPTIONS "<<OPTIONS<<endl;
833 Loop(DIR,LIST,OPTIONS);
834
835 cout << "Back to main - end"<<endl;
836
837 return 0;
838
839 };
840
841 #endif

  ViewVC Help
Powered by ViewVC 1.1.23