/[PAMELA software]/DarthVader/CalorimeterLevel2/src/CaloProcessing.cpp
ViewVC logotype

Annotation of /DarthVader/CalorimeterLevel2/src/CaloProcessing.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations) (download)
Thu Sep 7 09:47:07 2006 UTC (18 years, 3 months ago) by mocchiut
Branch: MAIN
CVS Tags: v2r00BETA
Changes since 1.4: +16 -4 lines
Adapted to profiler version v2r00

1 mocchiut 1.1 /**
2     * \file src/CaloProcessing.cpp
3     * \author Emiliano Mocchiutti
4     **/
5     //
6     // C/C++ headers
7     //
8     #include <sstream>
9     #include <fstream>
10     //
11     // ROOT headers
12     //
13     #include <TTree.h>
14     #include <TBranch.h>
15     #include <TFile.h>
16     #include <TObject.h>
17     //
18     // YODA headers
19     //
20     #include <PamelaRun.h>
21     #include <physics/calorimeter/CalorimeterEvent.h>
22     #include <CalibCalPedEvent.h>
23     //
24     //
25     //
26     #include <GLTables.h>
27     //
28     // this package headers
29     //
30     #include <delay.h>
31     #include <CaloProcessing.h>
32     //
33     //
34     // Declaration of the core fortran routines
35     //
36     #define calol2cm calol2cm_
37     extern "C" int calol2cm();
38     #define calol2tr calol2tr_
39     extern "C" int calol2tr();
40     //
41     using namespace std;
42     //
43     //
44     // Public methods
45     //
46    
47     CaloProcessing::~CaloProcessing(){
48 mocchiut 1.3 delete de;
49 mocchiut 1.1 delete this;
50     }
51    
52     CaloProcessing::CaloProcessing(){
53     //
54     extern struct FlCaLevel1 clevel1_;
55     extern struct FlCaLevel2 clevel2_;
56     clevel1 = &clevel1_;
57     clevel2 = &clevel2_;
58     //
59     trkseqno = 0;
60     ClearStructs();
61 mocchiut 1.3 //
62     memset(dexy, 0, 2*22*96*sizeof(Float_t));
63     memset(dexyc, 0, 2*22*96*sizeof(Float_t));
64     memset(mip, 0, 2*22*96*sizeof(Float_t));
65     memset(base, 0, 2*22*6*sizeof(Float_t));
66     memset(sbase, 0, 2*22*6*sizeof(Float_t));
67 mocchiut 1.1 calopar1 = true;
68     calopar2 = true;
69 mocchiut 1.4 ftcalopar1 = 0;
70     ttcalopar1 = 0;
71     ftcalopar2 = 0;
72     ttcalopar2 = 0;
73 mocchiut 1.1 }
74    
75     /**
76     * Initialize CaloProcessing object
77     **/
78 mocchiut 1.4 void CaloProcessing::ProcessingInit(TSQLServer *dbc, UInt_t hs, Int_t &sgnl, TTree *l0tree, Bool_t isdeb, Bool_t isverb){
79 mocchiut 1.1 //
80     debug = isdeb;
81     verbose = isverb;
82     //
83     l0tr=(TTree*)l0tree;
84     de = new pamela::calorimeter::CalorimeterEvent();
85     l0calo = (TBranch*)l0tr->GetBranch("Calorimeter");
86     l0tr->SetBranchAddress("Calorimeter", &de);
87     //
88     trkseqno = 0;
89     ClearStructs();
90     //
91     GL_CALO_CALIB *glcalo = new GL_CALO_CALIB();
92     //
93     sgnl = 0;
94 mocchiut 1.5 UInt_t uptime = 0;
95 mocchiut 1.1 //
96     for (Int_t s = 0; s < 4; s++){
97 mocchiut 1.4 idcalib[s] = 0;
98     fromtime[s] = 0;
99     totime[s] = 0;
100 mocchiut 1.1 calibno[s] = 0;
101     ClearCalibVals(s);
102 mocchiut 1.4 //
103 mocchiut 1.5 sgnl = glcalo->Query_GL_CALO_CALIB(hs,uptime,s,dbc);
104 mocchiut 1.1 if ( sgnl < 0 ){
105     if ( verbose ) printf(" CALORIMETER - ERROR: error from GLTables\n");
106     return;
107     };
108 mocchiut 1.4 //
109     idcalib[s] = glcalo->ID_ROOT_L0;
110 mocchiut 1.1 fromtime[s] = glcalo->FROM_TIME;
111 mocchiut 1.5 if ( glcalo->TO_TIME < hs ){ // calibration is corrupted and we are using the one that preceed the good one
112     totime[s] = uptime;
113     } else {
114     totime[s] = glcalo->TO_TIME;
115     };
116 mocchiut 1.4 calibno[s] = glcalo->EV_ROOT;
117     //
118     if ( totime[s] == 0 ){
119 mocchiut 1.1 if ( verbose ) printf(" CALORIMETER - WARNING: data with no associated calibration\n");
120     ClearCalibVals(s);
121     sgnl = 100;
122     };
123     };
124     //
125     // determine path and name and entry of the calibration file
126     //
127     GL_ROOT *glroot = new GL_ROOT();
128     if ( verbose ) printf("\n");
129     for (Int_t s = 0; s < 4; s++){
130     if ( verbose ) printf(" ** SECTION %i **\n",s);
131 mocchiut 1.4 if ( totime[s] > 0 ){
132     //
133 mocchiut 1.1 sgnl = glroot->Query_GL_ROOT(idcalib[s],dbc);
134     if ( sgnl < 0 ){
135     if ( verbose ) printf(" CALORIMETER - ERROR: error from GLTables\n");
136     return;
137     };
138 mocchiut 1.4 //
139 mocchiut 1.1 stringstream name;
140     name.str("");
141     name << glroot->PATH.Data() << "/";
142     name << glroot->NAME.Data();
143     //
144     fcalname[s] = (TString)name.str().c_str();
145 mocchiut 1.4 if ( verbose ) printf(" - runheader at time %u. From time %u to time %u \n use file %s \n calibration at entry %i \n\n",hs,fromtime[s],totime[s],fcalname[s].Data(),calibno[s]);
146 mocchiut 1.1 } else {
147 mocchiut 1.4 if ( verbose ) printf(" - runheader at time %u. NO CALIBRATION INCLUDE THE RUNHEADER! ",hs);
148 mocchiut 1.1 };
149     sgnl = LoadCalib(s);
150     if ( sgnl ) break;
151     };
152     //
153 mocchiut 1.2 delete glcalo;
154     delete glroot;
155     //
156 mocchiut 1.1 return;
157     //
158     }
159    
160 mocchiut 1.4 Int_t CaloProcessing::ChkCalib(TSQLServer *dbc, UInt_t atime){
161 mocchiut 1.1 Int_t sgnl = 0;
162     for ( Int_t s = 0; s < 4; s++){
163     if ( atime > totime[s] ){
164     sgnl = Update(dbc,atime,s);
165     if ( sgnl < 0 ) return(sgnl);
166     };
167     };
168     return(sgnl);
169     }
170    
171 mocchiut 1.4 Int_t CaloProcessing::ChkParam(TSQLServer *dbc, UInt_t runheader){
172 mocchiut 1.1 stringstream calfile;
173     stringstream aligfile;
174     Int_t error = 0;
175     FILE *f = 0;
176     GL_PARAM *glparam = new GL_PARAM();
177     //
178     if ( calopar1 || ( ttcalopar1 != 0 && ttcalopar1 < runheader ) ){
179     calopar1 = false;
180     //
181     // determine where I can find calorimeter ADC to MIP conversion file
182     //
183     if ( verbose ) printf(" Querying DB for calorimeter parameters files...\n");
184     //
185     error = 0;
186 mocchiut 1.4 error = glparam->Query_GL_PARAM(runheader,101,dbc);
187 mocchiut 1.1 if ( error < 0 ) return(error);
188     //
189     calfile.str("");
190     calfile << glparam->PATH.Data() << "/";
191     calfile << glparam->NAME.Data();
192     ftcalopar1 = glparam->FROM_TIME;
193     ttcalopar1 = glparam->TO_TIME;
194     //
195     if ( verbose ) printf("\n Using ADC to MIP conversion file: \n %s \n",calfile.str().c_str());
196     f = fopen(calfile.str().c_str(),"rb");
197     if ( !f ){
198     if ( verbose ) printf(" CALORIMETER - ERROR: no ADC to MIP file!\n");
199     return(-105);
200     };
201     //
202     for (Int_t m = 0; m < 2 ; m++ ){
203     for (Int_t k = 0; k < 22; k++ ){
204     for (Int_t l = 0; l < 96; l++ ){
205     fread(&mip[m][k][l],sizeof(mip[m][k][l]),1,f);
206     };
207     };
208     };
209     fclose(f);
210     };
211     //
212     if ( calopar2 || ( ttcalopar2 != 0 && ttcalopar2 < runheader ) ){
213     calopar2 = false;
214     //
215     // determine where I can find calorimeter alignment file
216     //
217     //
218     error = 0;
219 mocchiut 1.4 error = glparam->Query_GL_PARAM(runheader,102,dbc);
220 mocchiut 1.1 if ( error < 0 ) return(error);
221     //
222     aligfile.str("");
223     aligfile << glparam->PATH.Data() << "/";
224     aligfile << glparam->NAME.Data();
225     ftcalopar2 = glparam->FROM_TIME;
226     ttcalopar2 = glparam->TO_TIME;
227     //
228     if ( verbose ) printf("\n Using alignment file: \n %s \n\n",aligfile.str().c_str());
229     f = fopen(aligfile.str().c_str(),"rb");
230     if ( !f ){
231     if ( verbose ) printf(" CALORIMETER - ERROR: no alignement file!\n");
232     return(-106);
233     };
234     //
235     fread(&clevel1->xalig,sizeof(clevel1->xalig),1,f);
236     if ( debug ) printf(" xalig = %f \n",clevel1->xalig);
237     fread(&clevel1->yalig,sizeof(clevel1->yalig),1,f);
238     if ( debug ) printf(" yalig = %f \n",clevel1->yalig);
239     fread(&clevel1->zalig,sizeof(clevel1->zalig),1,f);
240     if ( debug ) printf(" zalig = %f \n",clevel1->zalig);
241     fread(&clevel1->emin,sizeof(clevel1->emin),1,f);
242     if ( debug ) printf(" signal threshold = %f \n",clevel1->emin);
243     //
244     fclose(f);
245     };
246     //
247 mocchiut 1.2 delete glparam;
248     //
249 mocchiut 1.1 return(0);
250     }
251    
252    
253    
254     void CaloProcessing::FindBaseRaw(Int_t l, Int_t m, Int_t pre){
255     Float_t minstrip = 100000.;
256     Float_t rms = 0.;
257     base[l][m][pre] = 0.;
258     for (Int_t e = pre*16; e < (pre+1)*16 ; e++){
259     if ( calgood[l][m][e] == 0. && dexy[l][m][e]-calped[l][m][e] < minstrip && dexy[l][m][e] > 0.) {
260     minstrip = dexy[l][m][e]-calped[l][m][e];
261     rms = calthr[l][m][pre];
262     };
263     };
264     if ( minstrip != 100000. ) {
265     Float_t strip6s = 0.;
266     for (Int_t e = pre*16; e < (pre+1)*16 ; e++){
267     if ( (dexy[l][m][e]-calped[l][m][e]) >= minstrip && (dexy[l][m][e]-calped[l][m][e]) <= (minstrip+rms) ) {
268     strip6s += 1.;
269     base[l][m][pre] += (dexy[l][m][e] - calped[l][m][e]);
270     };
271     //
272     // compression
273     //
274     if ( abs((int)(dexy[l][m][e]-calped[l][m][e])) <= (minstrip+rms) ) {
275     dexyc[l][m][e] = 0.;
276     } else {
277     dexyc[l][m][e] = dexy[l][m][e];
278     };
279     };
280     if ( strip6s >= 9. ){
281     Double_t arro = base[l][m][pre]/strip6s;
282     Float_t deci = 1000.*((float)arro - float(int(arro)));
283     if ( deci < 500. ) {
284     arro = double(int(arro));
285     } else {
286     arro = 1. + double(int(arro));
287     };
288     base[l][m][pre] = arro;
289     } else {
290     base[l][m][pre] = 31000.;
291     for (Int_t e = pre*16; e < (pre+1)*16 ; e++){
292     dexyc[l][m][e] = dexy[l][m][e];
293     };
294     };
295     } else {
296     base[l][m][pre] = 31000.;
297     };
298     }
299    
300     Int_t CaloProcessing::Calibrate(Int_t ei){
301     //
302     // get entry ei
303     //
304     l0calo->GetEntry(ei);
305     //
306     // if it was not a selftrigger event, could it ever been a selftrigger event? if so trigty = 3.
307     //
308     Int_t val = 0;
309     Int_t del = 1100;
310     if ( clevel2->trigty != 2. ){
311     for (Int_t sec = 0; sec < 4; sec++){
312     val = (Int_t)de->calselftrig[sec][6];
313     del = delay(val);
314     if ( del < 1100 ){
315     clevel2->trigty = 3.;
316     break;
317     };
318     };
319     };
320     //
321     Int_t se = 5;
322     Int_t done = 0;
323     Int_t pre = -1;
324     Bool_t isCOMP = false;
325     Bool_t isFULL = false;
326     Bool_t isRAW = false;
327     Float_t ener;
328     Int_t doneb = 0;
329     Int_t donec = 0;
330     Int_t ck = 0;
331     Int_t ipre = 0;
332     Int_t ip[3] = {0};
333     Float_t base0, base1, base2;
334     base0 = 0.;
335     base1 = 0.;
336     base2 = 0.;
337     Float_t qpre[6] = {0.,0.,0.,0.,0.,0.};
338     Float_t ene[96];
339     Int_t chdone[4] = {0,0,0,0};
340     Int_t pe = 0;
341     //
342     // run over views and planes
343     //
344     for (Int_t l = 0; l < 2; l++){
345     for (Int_t m = 0; m < 22; m++){
346     //
347     // determine the section number
348     //
349     se = 5;
350     if (l == 0 && m%2 == 0) se = 3;
351     if (l == 0 && m%2 != 0) se = 2;
352     if (l == 1 && m%2 == 0) se = 1;
353     if (l == 1 && m%2 != 0) se = 0;
354     //
355     // determine what kind of event we are going to analyze
356     //
357     isCOMP = false;
358     isFULL = false;
359     isRAW = false;
360     if ( de->stwerr[se] & (1 << 16) ) isCOMP = true;
361     if ( de->stwerr[se] & (1 << 17) ) isFULL = true;
362     if ( de->stwerr[se] & (1 << 3) ) isRAW = true;
363     if ( !chdone[se] ){
364     //
365     // check for any error in the event
366     //
367     clevel2->crc[se] = 0;
368     if ( de->perror[se] == 132 ){
369     clevel2->crc[se] = 1;
370     pe++;
371     };
372     clevel2->perr[se] = 0;
373     if ( de->perror[se] != 0 ){
374     clevel2->perr[se] = 1;
375     pe++;
376     };
377     clevel2->swerr[se] = 0;
378     for (Int_t j = 0; j < 7 ; j++){
379     if ( (j != 3) && (de->stwerr[se] & (1 << j)) ){
380     clevel2->swerr[se] = 1;
381     pe++;
382     };
383     };
384     chdone[se] = 1;
385     };
386     if ( clevel2->crc[se] == 0 && (clevel1->good2 == 1 || clevel2->trigty >= 2) ){
387     pre = -1;
388     //
389     for (Int_t nn = 0; nn < 96; nn++){
390     ene[nn] = 0.;
391     dexy[l][m][nn] = de->dexy[l][m][nn] ;
392     dexyc[l][m][nn] = de->dexyc[l][m][nn] ;
393     };
394     //
395     // run over preamplifiers
396     //
397     pre = -1;
398     for (Int_t i = 0; i < 3; i++){
399     for (Int_t j = 0; j < 2; j++){
400     pre = j + i*2;
401     //
402     // baseline check and calculation
403     //
404     if ( !isRAW ) {
405     base[l][m][pre] = de->base[l][m][pre] ;
406     } else {
407     //
408     // if it is a raw event and we haven't checked
409     // yet, calculate the baseline.
410     //
411     FindBaseRaw(l,m,pre);
412     };
413     };
414     };
415     //
416     // run over strips
417     //
418     pre = -1;
419     for (Int_t i = 0 ; i < 3 ; i++){
420     ip[i] = 0;
421     for (Int_t n = i*32 ; n < (i+1)*32 ; n++){
422     if (n%16 == 0) {
423     ck = 0;
424     done = 0;
425     doneb = 0;
426     donec = 0;
427     pre++;
428 mocchiut 1.3 qpre[pre] = 0.;
429 mocchiut 1.1 };
430     //
431     // baseline check and calculation
432     //
433     // no suitable new baseline, use old ones!
434     //
435     if ( !done ){
436     if ( (base[l][m][pre] == 31000. || base[l][m][pre] == 0.) ){
437     ck = 1;
438     if (pre%2 == 0) {
439     ip[i] = pre + 1;
440     } else {
441     ip[i] = pre - 1;
442     };
443     if ( (base[l][m][ip[i]] == 31000. || base[l][m][ip[i]] == 0.) ){
444     //
445     ck = 2;
446     if ( sbase[l][m][pre] == 31000. || sbase[l][m][pre] == 0. ) {
447     ck = 3;
448     };
449     };
450     done = 1;
451     };
452     };
453     //
454     // CALIBRATION ALGORITHM
455     //
456     if ( !doneb ){
457     switch (ck) {
458     case 0:
459     base0 = base[l][m][pre];
460     base2 = calbase[l][m][pre];
461     break;
462     case 1:
463     base0 = base[l][m][ip[i]];
464     base2 = calbase[l][m][ip[i]];
465     break;
466     case 2:
467     base0 = sbase[l][m][pre];
468     base2 = calbase[l][m][pre];
469     break;
470     case 3:
471     base0 = calbase[l][m][pre];
472     base2 = calbase[l][m][pre];
473     break;
474     };
475     base1 = calbase[l][m][pre];
476     doneb = 1;
477     };
478     ener = dexyc[l][m][n];
479     clevel1->estrip[n][m][l] = 0.;
480     if ( base0>0 && base0 < 30000. ){
481     if ( !donec && (base0 - base1 + base2) != 0. ){
482     sbase[l][m][pre] = base0 - base1 + base2;
483     donec = 1;
484     };
485     if ( ener > 0. ){
486     clevel1->estrip[n][m][l] = (ener - calped[l][m][n] - base0 - base1 + base2)/mip[l][m][n] ;
487     //
488     // OK, now in estrip we have the energy deposit in MIP of all the strips for this event (at the end of loops of course)
489     //
490     qpre[pre] += clevel1->estrip[n][m][l];
491     };
492     };
493     };
494     if (ck == 1){
495     if (ip[i]%2 == 0) {
496     ipre = ip[i] + 1;
497     } else {
498     ipre = ip[i] - 1;
499     };
500     for (Int_t j = ipre*16 ; j < (ipre+1)*16 ; j++){
501 mocchiut 1.3 clevel1->estrip[j][m][l] += (qpre[ipre] - qpre[ip[i]]) * 0.00478;
502 mocchiut 1.1 };
503     };
504     if (ck == 2){
505     for (Int_t j = i*32 ; j < (i+1)*32 ; j++){
506     ipre = j/16 + 1;
507 mocchiut 1.3 clevel1->estrip[j][m][l] += qpre[ipre] * 0.00478;
508 mocchiut 1.1 };
509     };
510     };
511     //
512     Int_t j4 = -4;
513     Int_t jjj = -3;
514     Int_t jj = -2;
515     for (Int_t j = 0 ; j < 100 ; j++){
516     jj++;
517     jjj++;
518     j4++;
519     if ( j < 96 ) ene[j] = clevel1->estrip[j][m][l];
520     if ( jj >= 0 && jj < 96 ){
521 mocchiut 1.3 if ( jj != 0 && jj != 32 && jj != 64 ) ene[jj-1] += -clevel1->estrip[jj][m][l] * 0.01581;
522     if ( jj != 31 && jj != 63 && jj != 95 ) ene[jj+1] += -clevel1->estrip[jj][m][l] * 0.01581;
523 mocchiut 1.1 };
524     if ( jjj >= 0 && jjj < 96 ){
525 mocchiut 1.3 if ( jjj != 0 && jjj != 32 && jjj != 64 ) clevel1->estrip[jjj-1][m][l] += -ene[jjj] * 0.01581;
526     if ( jjj != 31 && jjj != 63 && jjj != 95 ) clevel1->estrip[jjj+1][m][l] += -ene[jjj] * 0.01581;
527 mocchiut 1.1 };
528     if ( j4 >= 0 && j4 < 96 ){
529     //
530     // NOTICE: THE FOLLOWING LINE EXCLUDE ALL STRIPS FOR WHICH THE RMS*4 IS GREATER THAN 26 !!! <===V============ IMPORTANT! =================>
531     //
532     if ( clevel1->estrip[j4][m][l]!=0. && ( clevel1->estrip[j4][m][l] < clevel1->emin || calrms[l][m][j4] > 26 )){
533     clevel1->estrip[j4][m][l] = 0.;
534     };
535     if ( clevel1->estrip[j4][m][l] > clevel1->emin ){
536     if ( l == 0 ){
537     //
538     // +-PPSSmmmm.mmmm
539     //
540     svstrip[istrip] = ((Float_t)m)*1000000. + ((Float_t)j4)*10000. + clevel1->estrip[j4][m][l];
541     } else {
542     svstrip[istrip] = -(((Float_t)m)*1000000. + ((Float_t)j4)*10000. + clevel1->estrip[j4][m][l]);
543     };
544     istrip++;
545     };
546     };
547     };
548     //
549     } else {
550     for (Int_t nn = 0; nn < 96; nn++){
551     clevel1->estrip[nn][m][l] = 0.;
552     };
553     };
554     };
555     };
556     if ( !pe ){
557     clevel2->good = 1;
558     } else {
559     clevel2->good = 0;
560     };
561     return(0);
562     }
563    
564     void CaloProcessing::GetTrkVar(){
565     calol2tr();
566     }
567    
568     void CaloProcessing::FillTrkVar(CaloLevel2 *ca, Int_t nutrk){
569     //
570     CaloTrkVar *t_ca = new CaloTrkVar();
571     //
572     t_ca->trkseqno = trkseqno;
573     t_ca->ncore = (Int_t)clevel2->ncore;
574     t_ca->qcore = clevel2->qcore;
575     t_ca->noint = (Int_t)clevel2->noint;
576     t_ca->ncyl = (Int_t)clevel2->ncyl;
577     t_ca->qcyl = clevel2->qcyl;
578     t_ca->qtrack = clevel2->qtrack;
579     t_ca->qtrackx = clevel2->qtrackx;
580     t_ca->qtracky = clevel2->qtracky;
581     t_ca->dxtrack = clevel2->dxtrack;
582     t_ca->dytrack = clevel2->dytrack;
583     t_ca->qlast = clevel2->qlast;
584     t_ca->nlast = (Int_t)clevel2->nlast;
585     t_ca->qpre = clevel2->qpre;
586     t_ca->npre = (Int_t)clevel2->npre;
587     t_ca->qpresh = clevel2->qpresh;
588     t_ca->npresh = (Int_t)clevel2->npresh;
589     t_ca->qtr = clevel2->qtr;
590     t_ca->ntr = (Int_t)clevel2->ntr;
591     t_ca->planetot = (Int_t)clevel2->planetot;
592     t_ca->qmean = clevel2->qmean;
593     t_ca->dX0l = clevel2->dX0l;
594     t_ca->qlow = clevel2->qlow;
595     t_ca->nlow = (Int_t)clevel2->nlow;
596     //
597     memcpy(t_ca->tibar,clevel2->tibar,sizeof(clevel2->tibar));
598     memcpy(t_ca->tbar,clevel2->tbar,sizeof(clevel2->tbar));
599     //
600     if ( trkseqno == -1 ){
601     ca->impx = clevel2->impx;
602     ca->impy = clevel2->impy;
603     ca->tanx = clevel2->tanx;
604     ca->tany = clevel2->tany;
605     ca->elen = clevel2->elen;
606     ca->selen = clevel2->selen;
607     memcpy(ca->cibar,clevel2->cibar,sizeof(clevel2->cibar));
608     memcpy(ca->cbar,clevel2->cbar,sizeof(clevel2->cbar));
609     memcpy(ca->planemax,clevel2->planemax,sizeof(clevel2->planemax));
610     memcpy(ca->varcfit,clevel2->varcfit,sizeof(clevel2->varcfit));
611     memcpy(ca->npcfit,clevel2->npcfit,sizeof(clevel2->npcfit));
612     };
613     //
614     TClonesArray &t = *ca->CaloTrk;
615     new(t[nutrk]) CaloTrkVar(*t_ca);
616     //
617 mocchiut 1.2 delete t_ca;
618     //
619 mocchiut 1.1 ClearTrkVar();
620     }
621    
622     void CaloProcessing::GetCommonVar(){
623     calol2cm();
624     }
625    
626     void CaloProcessing::FillCommonVar(CaloLevel2 *ca){
627     //
628     ca->good = clevel2->good;
629     if ( clevel2->trigty == 2. ){
630     ca->selftrigger = 1;
631     } else {
632     ca->selftrigger = 0;
633     };
634     memcpy(ca->perr,clevel2->perr,sizeof(clevel2->perr));
635     memcpy(ca->swerr,clevel2->swerr,sizeof(clevel2->swerr));
636     memcpy(ca->crc,clevel2->crc,sizeof(clevel2->crc));
637     ca->estrip = TArrayF(0,svstrip);
638     ca->nstrip = (Int_t)clevel2->nstrip;
639     ca->qtot = clevel2->qtot;
640     ca->impx = clevel2->impx;
641     ca->impy = clevel2->impy;
642     ca->tanx = clevel2->tanx;
643     ca->tany = clevel2->tany;
644     ca->nx22 = (Int_t)clevel2->nx22;
645     ca->qx22 = clevel2->qx22;
646     ca->qmax = clevel2->qmax;
647     ca->elen = clevel2->elen;
648     ca->selen = clevel2->selen;
649     ca->estrip = TArrayF(ca->nstrip,svstrip);
650     memcpy(ca->qq,clevel2->qq,sizeof(clevel2->qq));
651     memcpy(ca->planemax,clevel2->planemax,sizeof(clevel2->planemax));
652     memcpy(ca->varcfit,clevel2->varcfit,sizeof(clevel2->varcfit));
653     memcpy(ca->npcfit,clevel2->npcfit,sizeof(clevel2->npcfit));
654     memcpy(ca->cibar,clevel2->cibar,sizeof(clevel2->cibar));
655     memcpy(ca->cbar,clevel2->cbar,sizeof(clevel2->cbar));
656     //
657     }
658    
659     void CaloProcessing::ClearStructs(){
660     ClearTrkVar();
661     ClearCommonVar();
662     }
663    
664     void CaloProcessing::RunClose(){
665     l0tr->Delete();
666     ClearStructs();
667 mocchiut 1.3 //
668     memset(dexy, 0, 2*22*96*sizeof(Float_t));
669     memset(dexyc, 0, 2*22*96*sizeof(Float_t));
670     memset(base, 0, 2*22*6*sizeof(Float_t));
671     memset(sbase, 0, 2*22*6*sizeof(Float_t));
672     //
673 mocchiut 1.1 }
674    
675     //
676     // Private methods
677     //
678    
679     void CaloProcessing::ClearTrkVar(){
680     clevel2->ncore = 0;
681     clevel2->qcore = 0.;
682     clevel2->noint = 0.;
683     clevel2->ncyl = 0.;
684     clevel2->qcyl = 0.;
685     clevel2->qtrack = 0.;
686     clevel2->qtrackx = 0.;
687     clevel2->qtracky = 0.;
688     clevel2->dxtrack = 0.;
689     clevel2->dytrack = 0.;
690     clevel2->qlast = 0.;
691     clevel2->nlast = 0.;
692     clevel2->qpre = 0.;
693     clevel2->npre = 0.;
694     clevel2->qpresh = 0.;
695     clevel2->npresh = 0.;
696     clevel2->qlow = 0.;
697     clevel2->nlow = 0.;
698     clevel2->qtr = 0.;
699     clevel2->ntr = 0.;
700     clevel2->planetot = 0.;
701     clevel2->qmean = 0.;
702     clevel2->dX0l = 0.;
703     clevel2->elen = 0.;
704     clevel2->selen = 0.;
705 mocchiut 1.3 memset(clevel1->al_p, 0, 5*2*sizeof(Double_t));
706     memset(clevel2->tibar, 0, 2*22*sizeof(Int_t));
707     memset(clevel2->tbar, 0, 2*22*sizeof(Float_t));
708 mocchiut 1.1 }
709    
710     void CaloProcessing::ClearCommonVar(){
711     istrip = 0;
712     clevel2->trigty = -1.;
713     clevel2->good = 0;
714     clevel2->nstrip = 0.;
715     clevel2->qtot = 0.;
716     clevel2->impx = 0.;
717     clevel2->impy = 0.;
718     clevel2->tanx = 0.;
719     clevel2->tany = 0.;
720     clevel2->qmax = 0.;
721     clevel2->nx22 = 0.;
722     clevel2->qx22 = 0.;
723 mocchiut 1.3 memset(clevel2->perr, 0, 4*sizeof(Int_t));
724     memset(clevel2->swerr, 0, 4*sizeof(Int_t));
725     memset(clevel2->crc, 0, 4*sizeof(Int_t));
726     memset(clevel2->qq, 0, 4*sizeof(Int_t));
727     memset(clevel2->varcfit, 0, 2*sizeof(Float_t));
728     memset(clevel2->npcfit, 0, 2*sizeof(Int_t));
729     memset(clevel2->planemax, 0, 2*sizeof(Int_t));
730     memset(clevel2->cibar, 0, 2*22*sizeof(Int_t));
731     memset(clevel2->cbar, 0, 2*22*sizeof(Float_t));
732 mocchiut 1.1 }
733    
734     void CaloProcessing::ClearCalibVals(Int_t s){
735     //
736     for ( Int_t d=0 ; d<11 ;d++ ){
737     Int_t pre = -1;
738     for ( Int_t j=0; j<96 ;j++){
739     if ( j%16 == 0 ) pre++;
740     if ( s == 2 ){
741     calped[0][2*d+1][j] = 0.;
742     cstwerr[3] = 0.;
743     cperror[3] = 0.;
744     calgood[0][2*d+1][j] = 0.;
745     calthr[0][2*d+1][pre] = 0.;
746     calrms[0][2*d+1][j] = 0.;
747     calbase[0][2*d+1][pre] = 0.;
748     calvar[0][2*d+1][pre] = 0.;
749     };
750     if ( s == 3 ){
751     calped[0][2*d][j] = 0.;
752     cstwerr[1] = 0.;
753     cperror[1] = 0.;
754     calgood[0][2*d][j] = 0.;
755     calthr[0][2*d][pre] = 0.;
756     calrms[0][2*d][j] = 0.;
757     calbase[0][2*d][pre] = 0.;
758     calvar[0][2*d][pre] = 0.;
759     };
760     if ( s == 0 ){
761     calped[1][2*d][j] = 0.;
762     cstwerr[0] = 0.;
763     cperror[0] = 0.;
764     calgood[1][2*d][j] = 0.;
765     calthr[1][2*d][pre] = 0.;
766     calrms[1][2*d][j] = 0.;
767     calbase[1][2*d][pre] = 0.;
768     calvar[1][2*d][pre] = 0.;
769     };
770     if ( s == 1 ){
771     calped[1][2*d+1][j] = 0.;
772     cstwerr[2] = 0.;
773     cperror[2] = 0.;
774     calgood[1][2*d+1][j] = 0.;
775     calthr[1][2*d+1][pre] = 0.;
776     calrms[1][2*d+1][j] = 0.;
777     calbase[1][2*d+1][pre] = 0.;
778     calvar[1][2*d+1][pre] = 0.;
779     };
780     };
781     };
782     return;
783     }
784    
785 mocchiut 1.4 Int_t CaloProcessing::Update(TSQLServer *dbc, UInt_t atime, Int_t s){
786 mocchiut 1.1 //
787     Int_t sgnl = 0;
788     //
789     GL_CALO_CALIB *glcalo = new GL_CALO_CALIB();
790     //
791     sgnl = 0;
792     //
793 mocchiut 1.4 idcalib[s] = 0;
794     fromtime[s] = 0;
795     totime[s] = 0;
796 mocchiut 1.1 calibno[s] = 0;
797     ClearCalibVals(s);
798     //
799 mocchiut 1.5 UInt_t uptime = 0;
800     //
801     sgnl = glcalo->Query_GL_CALO_CALIB(atime,uptime,s,dbc);
802 mocchiut 1.1 if ( sgnl < 0 ){
803     if ( verbose ) printf(" CALORIMETER - ERROR: error from GLTables\n");
804     return(sgnl);
805     };
806     //
807 mocchiut 1.4 idcalib[s] = glcalo->ID_ROOT_L0;
808 mocchiut 1.1 fromtime[s] = glcalo->FROM_TIME;
809 mocchiut 1.5 if ( glcalo->TO_TIME < atime ){ // calibration is corrupted and we are using the one that preceed the good one
810     totime[s] = uptime;
811     } else {
812     totime[s] = glcalo->TO_TIME;
813     };
814     // totime[s] = glcalo->TO_TIME;
815 mocchiut 1.4 calibno[s] = glcalo->EV_ROOT;
816 mocchiut 1.1 //
817 mocchiut 1.4 if ( totime[s] == 0 ){
818 mocchiut 1.1 if ( verbose ) printf(" CALORIMETER - WARNING: data with no associated calibration\n");
819     ClearCalibVals(s);
820     sgnl = 100;
821     };
822     //
823     // determine path and name and entry of the calibration file
824     //
825     GL_ROOT *glroot = new GL_ROOT();
826     if ( verbose ) printf("\n");
827     if ( verbose ) printf(" ** SECTION %i **\n",s);
828     //
829     sgnl = glroot->Query_GL_ROOT(idcalib[s],dbc);
830     if ( sgnl < 0 ){
831     if ( verbose ) printf(" CALORIMETER - ERROR: error from GLTables\n");
832     return(sgnl);
833     };
834     //
835     stringstream name;
836     name.str("");
837     name << glroot->PATH.Data() << "/";
838     name << glroot->NAME.Data();
839     //
840     fcalname[s] = (TString)name.str().c_str();
841 mocchiut 1.4 if ( verbose ) printf(" - event at time %u. From time %u to time %u \n use file %s \n calibration at entry %i \n\n",atime,fromtime[s],totime[s],fcalname[s].Data(),calibno[s]);
842 mocchiut 1.1 //
843     sgnl = LoadCalib(s);
844     //
845     if ( sgnl != 0 ) return(sgnl);
846 mocchiut 1.2 delete glcalo;
847     delete glroot;
848 mocchiut 1.1 //
849     return(0);
850     //
851     }
852    
853     Int_t CaloProcessing::LoadCalib(Int_t s){
854     //
855     ifstream myfile;
856     myfile.open(fcalname[s].Data());
857     if ( !myfile ){
858     return(-107);
859     };
860     myfile.close();
861     //
862     TFile *File = new TFile(fcalname[s].Data());
863     if ( !File ) return(-108);
864     TTree *tr = (TTree*)File->Get("CalibCalPed");
865     if ( !tr ) return(-109);
866     //
867     TBranch *calo = tr->GetBranch("CalibCalPed");
868     //
869     pamela::CalibCalPedEvent *ce = 0;
870     tr->SetBranchAddress("CalibCalPed", &ce);
871     //
872 mocchiut 1.4 Long64_t ncalibs = calo->GetEntries();
873 mocchiut 1.1 //
874     if ( !ncalibs ) return(-110);
875     //
876 mocchiut 1.4 calo->GetEntry(calibno[s]);
877 mocchiut 1.1 //
878     if (ce->cstwerr[s] != 0 && ce->cperror[s] == 0 ) {
879     for ( Int_t d=0 ; d<11 ;d++ ){
880     Int_t pre = -1;
881     for ( Int_t j=0; j<96 ;j++){
882     if ( j%16 == 0 ) pre++;
883     if ( s == 2 ){
884     calped[0][2*d+1][j] = ce->calped[3][d][j];
885     cstwerr[3] = ce->cstwerr[3];
886     cperror[3] = ce->cperror[3];
887     calgood[0][2*d+1][j] = ce->calgood[3][d][j];
888     calthr[0][2*d+1][pre] = ce->calthr[3][d][pre];
889     calrms[0][2*d+1][j] = ce->calrms[3][d][j];
890     calbase[0][2*d+1][pre] = ce->calbase[3][d][pre];
891     calvar[0][2*d+1][pre] = ce->calvar[3][d][pre];
892     };
893     if ( s == 3 ){
894     calped[0][2*d][j] = ce->calped[1][d][j];
895     cstwerr[1] = ce->cstwerr[1];
896     cperror[1] = ce->cperror[1];
897     calgood[0][2*d][j] = ce->calgood[1][d][j];
898     calthr[0][2*d][pre] = ce->calthr[1][d][pre];
899     calrms[0][2*d][j] = ce->calrms[1][d][j];
900     calbase[0][2*d][pre] = ce->calbase[1][d][pre];
901     calvar[0][2*d][pre] = ce->calvar[1][d][pre];
902     };
903     if ( s == 0 ){
904     calped[1][2*d][j] = ce->calped[0][d][j];
905     cstwerr[0] = ce->cstwerr[0];
906     cperror[0] = ce->cperror[0];
907     calgood[1][2*d][j] = ce->calgood[0][d][j];
908     calthr[1][2*d][pre] = ce->calthr[0][d][pre];
909     calrms[1][2*d][j] = ce->calrms[0][d][j];
910     calbase[1][2*d][pre] = ce->calbase[0][d][pre];
911     calvar[1][2*d][pre] = ce->calvar[0][d][pre];
912     };
913     if ( s == 1 ){
914     calped[1][2*d+1][j] = ce->calped[2][d][j];
915     cstwerr[2] = ce->cstwerr[2];
916     cperror[2] = ce->cperror[2];
917     calgood[1][2*d+1][j] = ce->calgood[2][d][j];
918     calthr[1][2*d+1][pre] = ce->calthr[2][d][pre];
919     calrms[1][2*d+1][j] = ce->calrms[2][d][j];
920     calbase[1][2*d+1][pre] = ce->calbase[2][d][pre];
921     calvar[1][2*d+1][pre] = ce->calvar[2][d][pre];
922     };
923     };
924     };
925     } else {
926     if ( verbose ) printf(" CALORIMETER - ERROR: problems finding a good calibration in this file! \n\n ");
927     return(-111);
928     };
929     File->Close();
930     return(0);
931     }

  ViewVC Help
Powered by ViewVC 1.1.23