/[PAMELA software]/calo/flight/CaloEnergy/src/CaloEnergy.cpp
ViewVC logotype

Annotation of /calo/flight/CaloEnergy/src/CaloEnergy.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (hide annotations) (download)
Wed Jul 29 12:58:27 2009 UTC (15 years, 4 months ago) by mocchiut
Branch: MAIN
Changes since 1.3: +372 -164 lines
New methods implemented, bugs fixed, comments added

1 mocchiut 1.1 #include <CaloEnergy.h>
2     #include <PamLevel2.h>
3    
4     //--------------------------------------
5     /**
6     * Default constructor
7     */
8     CaloEnergy::CaloEnergy(){
9     Clear();
10     }
11    
12     CaloEnergy::CaloEnergy(PamLevel2 *l2p){
13     //
14     Clear();
15     //
16     L2 = l2p;
17     //
18     if ( !L2->IsORB() ) printf(" WARNING: OrbitalInfo Tree is needed, the plugin could not work properly without it \n");
19     //
20     fSimu = false;
21 mocchiut 1.3 this->Set();
22 mocchiut 1.1 //
23     }
24    
25     CaloEnergy::CaloEnergy(PamLevel2 *l2p, Bool_t simulation){
26     //
27     Clear();
28     //
29     L2 = l2p;
30     //
31     if ( !L2->IsORB() ) printf(" WARNING: OrbitalInfo Tree is needed, the plugin could not work properly without it \n");
32     //
33 mocchiut 1.3 fSimu = simulation;
34     this->Set();
35     //
36     }
37    
38 mocchiut 1.4 void CaloEnergy::UseCaloPreSampler(){
39     //
40     // use the presampler setting forcefitmode to 1000 means to force the DV routine to find the track inside the calorimeter using the "shower" approach developed for electrons
41     //
42     cp = new CaloPreSampler(L2);
43     cp->SplitInto(0,22);
44     cp->SetForceFitMode(1000);
45     // cp->UseTracker(false);
46     // cp->ForceCaloFit();
47     // cp->SetDebug(true);
48     // cp->Process();
49     }
50    
51 mocchiut 1.3 void CaloEnergy::Set(){
52 mocchiut 1.4 //
53     // set default values, NB default conversion factor for energy is just very approximated!
54     //
55 mocchiut 1.1 OBT = 0;
56     PKT = 0;
57     atime = 0;
58     sntr = "start";
59     //
60     AOBT = 0;
61     APKT = 0;
62     aatime = 0;
63     asntr = "start";
64     //
65     debug = false;
66     //
67 mocchiut 1.4 indep = false;
68     //
69 mocchiut 1.1 fLong = false;
70     fPl = 1;
71 mocchiut 1.2 fRad = -1;
72 mocchiut 1.4 cp = NULL;
73 mocchiut 1.1 //
74     this->DefineGeometry();
75     fXosel =true;
76     fXesel = true;
77     fYosel = true;
78     fYesel = true;
79 mocchiut 1.2 fConv_rxe = 44.4;
80     fConv_rxo = 44.4;
81     fConv_ryo = 44.4;
82     fConv_rye = 44.4;
83 mocchiut 1.3 fXomin = 1000;
84     fXemin = 1000;
85     fYomin = 1000;
86     fYemin = 1000;
87     }
88    
89     void CaloEnergy::SetMinimumContainment(TString section, Int_t plane){
90     section.ToUpper();
91     if ( section.Contains("XO") ) fXomin = plane;
92     if ( section.Contains("XE") ) fXemin = plane;
93     if ( section.Contains("YO") ) fYomin = plane;
94     if ( section.Contains("YE") ) fYemin = plane;
95     }
96    
97 mocchiut 1.4 void CaloEnergy::SetMinimumContainment(Int_t plane){
98     this->SetMinimumContainment("XEXOYEYO",plane);
99     }
100    
101 mocchiut 1.3 Int_t CaloEnergy::GetMinimumContainment(TString section){
102     section.ToUpper();
103     if ( section.Contains("XO") ) return(fXomin);
104     if ( section.Contains("XE") ) return(fXemin);
105     if ( section.Contains("YE") ) return(fYemin);
106     if ( section.Contains("YO") ) return(fYomin);
107     printf(" ERROR: section not recognized \n");
108     return(-1000);
109 mocchiut 1.1 }
110    
111 mocchiut 1.2 void CaloEnergy::SetConversionFactor(TString section, Float_t conv){
112     section.ToUpper();
113     if ( section.Contains("XO") ) fConv_rxo = conv;
114     if ( section.Contains("XE") ) fConv_rxe = conv;
115     if ( section.Contains("YO") ) fConv_ryo = conv;
116     if ( section.Contains("YE") ) fConv_rye = conv;
117     }
118    
119 mocchiut 1.4 void CaloEnergy::SetConversionFactor(Float_t conv){
120     this->SetConversionFactor("XEXOYEYO",conv);
121     }
122    
123 mocchiut 1.2 Float_t CaloEnergy::GetConversionFactor(TString section){
124     section.ToUpper();
125     if ( section.Contains("XO") ) return(fConv_rxo);
126     if ( section.Contains("XE") ) return(fConv_rxe);
127     if ( section.Contains("YO") ) return(fConv_ryo);
128     if ( section.Contains("YE") ) return(fConv_rye);
129     printf(" ERROR: section not recognized \n");
130     return(-1000.);
131     }
132    
133     Int_t CaloEnergy::GetMaxplane(TString section){
134     section.ToUpper();
135     if ( section.Contains("XO") ) return fMax_planexo;
136     if ( section.Contains("XE") ) return fMax_planexe;
137     if ( section.Contains("YO") ) return fMax_planeyo;
138     if ( section.Contains("YE") ) return fMax_planeye;
139     return(-1);
140     }
141    
142 mocchiut 1.4 Float_t CaloEnergy::GetMaxEnergy(TString section){
143     section.ToUpper();
144     if ( section.Contains("XO") ) return fXOen_maxplane;
145     if ( section.Contains("XE") ) return fXEen_maxplane;
146     if ( section.Contains("YO") ) return fYOen_maxplane;
147     if ( section.Contains("YE") ) return fYEen_maxplane;
148     return(-1);
149     }
150    
151 mocchiut 1.1 void CaloEnergy::DefineGeometry(){
152     //
153 mocchiut 1.4 // Use CaloStrip to determine once the position of border strips for each section
154     //
155     //
156 mocchiut 1.2 fM = 2. + 0.096; // real position from cbar
157     fM1 = 2. - 0.122 - 0.096; // due to calculation of xe1 etc.
158 mocchiut 1.1 if ( fM1 < 0. ) fM1 = 0.;
159     //
160     CaloStrip *cs = new CaloStrip(fSimu);
161 mocchiut 1.4 //
162     // view y plane 0 strip 0
163 mocchiut 1.1 cs->Set(1,0,0);
164     xe1= cs->GetY();
165 mocchiut 1.4 // z1= cs->GetZ();
166     // view y plane 0 strip 31
167 mocchiut 1.1 cs->Set(1,0,31);
168     xe2= cs->GetY();
169 mocchiut 1.4 // view y plane 0 strip 32
170 mocchiut 1.1 cs->Set(1,0,32);
171     xe3= cs->GetY();
172 mocchiut 1.4 // view y plane 0 strip 63
173 mocchiut 1.1 cs->Set(1,0,63);
174     xe4= cs->GetY();
175 mocchiut 1.4 // view y plane 0 strip 64
176 mocchiut 1.1 cs->Set(1,0,64);
177     xe5= cs->GetY();
178 mocchiut 1.4 // view y plane 0 strip 95
179 mocchiut 1.1 cs->Set(1,0,95);
180     xe6= cs->GetY();
181    
182 mocchiut 1.4 // view x plane 0 strip 0
183 mocchiut 1.1 cs->Set(0,0,0);
184     yo1= cs->GetX();
185 mocchiut 1.4 // z2= cs->GetZ();
186     // view x plane 0 strip 31
187 mocchiut 1.1 cs->Set(0,0,31);
188     yo2= cs->GetX();
189 mocchiut 1.4 // view x plane 0 strip 32
190 mocchiut 1.1 cs->Set(0,0,32);
191     yo3= cs->GetX();
192 mocchiut 1.4 // view x plane 0 strip 63
193 mocchiut 1.1 cs->Set(0,0,63);
194     yo4= cs->GetX();
195 mocchiut 1.4 // view x plane 0 strip 64
196 mocchiut 1.1 cs->Set(0,0,64);
197     yo5= cs->GetX();
198 mocchiut 1.4 // view x plane 0 strip 95
199 mocchiut 1.1 cs->Set(0,0,95);
200     yo6= cs->GetX();
201    
202    
203 mocchiut 1.4 // view y plane 1 strip 0
204 mocchiut 1.1 cs->Set(1,1,0);
205     xo1= cs->GetY();
206 mocchiut 1.4 // z3= cs->GetZ();
207     // view y plane 1 strip 31
208 mocchiut 1.1 cs->Set(1,1,31);
209     xo2= cs->GetY();
210 mocchiut 1.4 // view y plane 1 strip 32
211 mocchiut 1.1 cs->Set(1,1,32);
212     xo3= cs->GetY();
213 mocchiut 1.4 // view y plane 1 strip 63
214 mocchiut 1.1 cs->Set(1,1,63);
215     xo4= cs->GetY();
216 mocchiut 1.4 // view y plane 1 strip 64
217 mocchiut 1.1 cs->Set(1,1,64);
218     xo5= cs->GetY();
219 mocchiut 1.4 // view y plane 1 strip 95
220 mocchiut 1.1 cs->Set(1,1,95);
221     xo6= cs->GetY();
222    
223 mocchiut 1.4 // view x plane 1 strip 0
224 mocchiut 1.1 cs->Set(0,1,0);
225     ye1= cs->GetX();
226 mocchiut 1.4 // z4= cs->GetZ();
227     // view x plane 1 strip 31
228 mocchiut 1.1 cs->Set(0,1,31);
229     ye2= cs->GetX();
230 mocchiut 1.4 // view x plane 1 strip 32
231 mocchiut 1.1 cs->Set(0,1,32);
232     ye3= cs->GetX();
233 mocchiut 1.4 // view x plane 1 strip 63
234 mocchiut 1.1 cs->Set(0,1,63);
235     ye4= cs->GetX();
236 mocchiut 1.4 // view x plane 1 strip 64
237 mocchiut 1.1 cs->Set(0,1,64);
238     ye5= cs->GetX();
239 mocchiut 1.4 // view x plane 1 strip 95
240 mocchiut 1.1 cs->Set(0,1,95);
241     ye6= cs->GetX();
242    
243     //
244     for (Int_t p = 0; p<22; p ++){
245     for (Int_t v = 0; v<2; v++ ){
246     cs->Set(v,p,0);
247 mocchiut 1.4 trk_z[p][v]= cs->GetZ(); // Z coord for each plane
248 mocchiut 1.1 };
249     };
250     //
251     delete cs;
252     //
253     }
254    
255     void CaloEnergy::Clear(){
256     //
257 mocchiut 1.4 // clear variables
258     //
259 mocchiut 1.3 fPartsel = false;
260     fSel = false;
261     fXosel = false;
262     fXesel = false;
263     fYosel = false;
264     fYesel = false;
265     fCount = 0.;
266 mocchiut 1.1 fEnergy = 0.;
267 mocchiut 1.2 fEnergyxe = 0.;
268     fEnergyxo = 0.;
269     fEnergyye = 0.;
270     fEnergyyo = 0.;
271 mocchiut 1.3 fMax_plane = 0;
272     fMax_planexo = 0;
273     fMax_planexe = 0;
274     fMax_planeyo = 0;
275     fMax_planeye = 0;
276 mocchiut 1.1 memset(enstrip,0,2*22*96*(sizeof(Float_t)));
277     en = 0.;
278     view = 0;
279     plane = 0;
280     strip = 0;
281     energyxe = 0.;
282     energyyo = 0.;
283     energyxo = 0.;
284     energyye = 0.;
285 mocchiut 1.3 fYoout = 0;
286     fYeout = 0;
287     fXoout = 0;
288     fXeout = 0;
289 mocchiut 1.4 fXEen_maxplane = 0.;
290     fXOen_maxplane = 0.;
291     fYEen_maxplane = 0.;
292     fYOen_maxplane = 0.;
293 mocchiut 1.1 memset(en_xep,0,11*sizeof(Float_t));
294     memset(en_yep,0,11*sizeof(Float_t));
295     memset(en_xop,0,11*sizeof(Float_t));
296     memset(en_yop,0,11*sizeof(Float_t));
297     //
298     }
299    
300     void CaloEnergy::Print(){
301     //
302     printf("========================================================================\n");
303     printf(" OBT: %u PKT: %u ATIME: %u \n",OBT,PKT,atime);
304     printf(" fEnergy :.............. %f \n",fEnergy);
305 mocchiut 1.2 printf(" fMax_plane :........... %f \n",fMax_plane);
306     printf(" fMax_planexo :......... %i \n",fMax_planexo);
307     printf(" fMax_planexe :......... %i \n",fMax_planexe);
308     printf(" fMax_planeyo :......... %i \n",fMax_planeyo);
309     printf(" fMax_planeye :......... %i \n",fMax_planeye);
310 mocchiut 1.1 printf(" fCount :.............. %f \n",fCount);
311 mocchiut 1.3 printf(" fSel :.............. %i \n",fSel);
312     printf(" fPartsel:.............. %i \n",fPartsel);
313 mocchiut 1.1 printf(" fXesel :.............. %i \n",fXesel);
314     printf(" fXosel :.............. %i \n",fXosel);
315     printf(" fYesel :.............. %i \n",fYesel);
316     printf(" fYosel :.............. %i \n",fYosel);
317 mocchiut 1.3 printf(" fXemin :.............. %i \n",fXemin);
318     printf(" fXomin :.............. %i \n",fXomin);
319     printf(" fYemin :.............. %i \n",fYemin);
320     printf(" fYomin :.............. %i \n",fYomin);
321     printf(" fXeout :.............. %i \n",fXeout);
322     printf(" fXoout :.............. %i \n",fXoout);
323     printf(" fYeout :.............. %i \n",fYeout);
324     printf(" fYoout :.............. %i \n",fYoout);
325 mocchiut 1.1 printf(" fSimu :.............. %i \n",fSimu);
326     printf(" fM :.............. %f \n",fM);
327     printf(" fM1 :.............. %f \n",fM1);
328 mocchiut 1.2 printf(" fRad :.............. %i \n",fRad);
329     printf(" fPl :.............. %i \n",fPl);
330     printf(" fConv_rxe ............. %f \n",fConv_rxe);
331     printf(" fConv_rxo ............. %f \n",fConv_rxo);
332     printf(" fConv_ryo ............. %f \n",fConv_ryo);
333     printf(" fConv_rye ............. %f \n",fConv_rye);
334 mocchiut 1.1 printf(" fLong :.............. %i \n",fLong);
335     printf(" energyxe:.............. %f \n",energyxe);
336     printf(" energyxo:.............. %f \n",energyxo);
337     printf(" energyye:.............. %f \n",energyye);
338     printf(" energyyo:.............. %f \n",energyyo);
339     printf(" debug :.............. %i \n",debug);
340    
341     printf("========================================================================\n");
342     //
343     }
344    
345     void CaloEnergy::Delete(){
346     Clear();
347 mocchiut 1.4 delete this;
348 mocchiut 1.1 }
349    
350    
351     Bool_t CaloEnergy::IsInsideAcceptance(TString section){
352     //
353 mocchiut 1.4 // check if the event is inside the acceptance of the given section(s)
354 mocchiut 1.1 //
355     TString ntr = section;
356     if ( !L2 ){
357     printf(" ERROR: cannot find PamLevel2 object, use the correct constructor or check your program!\n");
358     printf(" ERROR: CaloEnergy variables not filled \n");
359     return false;
360     };
361     //
362     Bool_t newentry = false;
363     //
364     if ( L2->IsORB() ){
365     if ( L2->GetOrbitalInfo()->pkt_num != APKT || L2->GetOrbitalInfo()->OBT != AOBT || L2->GetOrbitalInfo()->absTime != aatime || strcmp(ntr.Data(),asntr.Data()) ){
366     newentry = true;
367     AOBT = L2->GetOrbitalInfo()->OBT;
368     APKT = L2->GetOrbitalInfo()->pkt_num;
369     aatime = L2->GetOrbitalInfo()->absTime;
370     asntr = ntr;
371     };
372     } else {
373     newentry = true;
374     };
375     //
376 mocchiut 1.4 // if we have already called this method for this event and no input changed then return fSel and exit
377     //
378 mocchiut 1.1 if ( !newentry ) return fSel;
379     //
380 mocchiut 1.4 // process the event
381     //
382 mocchiut 1.1 if ( debug ) printf(" ########## IsInsideAcceptance ######### \n");
383     //
384 mocchiut 1.4 // clear variables
385     //
386 mocchiut 1.3 this->Clear();
387     //
388 mocchiut 1.1 section.ToUpper();
389     //
390 mocchiut 1.4 // Count the number of section(s) given as input
391     //
392     Int_t fNumSec = Int_t(section.Contains("XO"))+Int_t(section.Contains("XE"))+Int_t(section.Contains("YO"))+Int_t(section.Contains("YE"));
393     if ( !fNumSec ){
394 mocchiut 1.1 printf(" ERROR: section must be XO or XE or YO or YE while it is %s \n",section.Data());
395 mocchiut 1.3 return false;
396     };
397     //
398 mocchiut 1.4 // If the presampler object exists then use the presampler output instead of the level2 output
399     //
400     CaloLevel2 *cl2 = NULL;
401     if ( cp ){
402     cl2 = cp->GetCaloLevel2();
403     } else {
404     cl2 = L2->GetCaloLevel2();
405     };
406     //
407     // get the energy for every strip of the calorimeter
408 mocchiut 1.3 //
409     for (Int_t ch=0; ch< L2->GetCaloLevel1()->istrip; ch++){
410     en = L2->GetCaloLevel1()->DecodeEstrip(ch,view,plane,strip);
411     enstrip[view][plane][strip]=en;
412     };
413 mocchiut 1.4 //
414     // sum energy plane by plane for each sections
415     //
416 mocchiut 1.3 for (Int_t i=0;i<11;i++){
417     for(strip=0; strip<96; strip++) {
418     if ( fRad < 0 ){
419 mocchiut 1.4 //
420     // run over all the strips of the plane
421     //
422 mocchiut 1.3 en_xep[i] += enstrip[1][2*i][strip];
423     en_yop[i] += enstrip[0][2*i][strip];
424     en_xop[i] += enstrip[1][2*i+1][strip];
425     en_yep[i] += enstrip[0][2*i+1][strip];
426     } else {
427 mocchiut 1.4 //
428     // use only the strips inside a cylinder of given radius fRad
429     //
430     if ( strip >= cl2->cibar[2*i][1]-1-fRad && strip <= cl2->cibar[2*i][1]-1+fRad ) en_xep[i] += enstrip[1][2*i][strip];
431     if ( strip >= cl2->cibar[2*i][0]-1-fRad && strip <= cl2->cibar[2*i][0]-1+fRad ) en_yop[i] += enstrip[0][2*i][strip];
432     if ( strip >= cl2->cibar[2*i+1][1]-1-fRad && strip <= cl2->cibar[2*i+1][1]-1+fRad ) en_xop[i] += enstrip[1][2*i+1][strip];
433     if ( strip >= cl2->cibar[2*i+1][0]-1-fRad && strip <= cl2->cibar[2*i+1][0]-1+fRad ) en_yep[i] += enstrip[0][2*i+1][strip];
434 mocchiut 1.3 };
435     };
436     energyxe += en_xep[i];
437     energyyo += en_yop[i];
438     energyxo += en_xop[i];
439     energyye += en_yep[i];
440     };
441     //
442 mocchiut 1.4 // Find the plane of maximum for each section
443     //
444     Float_t xomax_en= 0.;
445     Float_t xemax_en= 0.;
446     Float_t yomax_en= 0.;
447     Float_t yemax_en= 0.;
448     //
449     //
450     Int_t xen = 0;
451     Int_t yon = 0;
452     Int_t xon = 0;
453     Int_t yen = 0;
454     //
455     if ( section.Contains("XE") ){
456     yon++;
457     xon++;
458     yen++;
459     for (Int_t ipl =0; ipl < 11; ipl ++) {
460     if(en_xep[ipl] > xemax_en) {
461     xemax_en = en_xep[ipl];
462     fMax_planexe = ipl;
463 mocchiut 1.3 };
464 mocchiut 1.4 };
465 mocchiut 1.3 };
466     //
467 mocchiut 1.4 if ( section.Contains("YO") ){
468     xon++;
469     yen++;
470     for (Int_t ipl =0; ipl < 11; ipl ++) {
471     if(en_yop[ipl] > yomax_en) {
472     yomax_en = en_yop[ipl];
473     fMax_planeyo = ipl;
474     };
475 mocchiut 1.3 };
476     };
477     //
478 mocchiut 1.4 if ( section.Contains("XO") ){
479     yen++;
480     for (Int_t ipl =0; ipl < 11; ipl ++) {
481     if(en_xop[ipl] > xomax_en) {
482     xomax_en = en_xop[ipl];
483     fMax_planexo = ipl;
484     };
485 mocchiut 1.3 };
486     };
487     //
488 mocchiut 1.4 if ( section.Contains("YE") ){
489     for (Int_t ipl =0; ipl < 11; ipl ++) {
490     if(en_yep[ipl] > yemax_en) {
491     yemax_en = en_yep[ipl];
492     fMax_planeye = ipl;
493     };
494     };
495     };
496     //
497     Int_t nPl = fPl;
498     //
499     // Set the maximum in case of coherent mode was selected
500     //
501     if ( !indep ){
502     nPl = 0;
503     if ( debug ) printf(" A: Check maximum, coherent mode: xoen %f yoen %f xeen %f yeen %f xomax %i yomax %i xemax %i yemax %i\n",xomax_en,yomax_en,xemax_en,yemax_en,fMax_planexo,fMax_planeyo,fMax_planexe,fMax_planeye);
504     Int_t nummod = 0;
505     Int_t numexpl = 0;
506     if ( xomax_en > xemax_en && xomax_en > yemax_en && xomax_en > yomax_en ){
507     //
508     // Section XO contains the maximum energy release per plane of the whole calorimeter
509     //
510     if ( debug ) printf(" XO is MAX %i %i %i %i\n",xen,yon,xon,yen);
511     //
512     // fMax_plane is the plane of maximum + number of additional dE/dx measurement counting planes from 0 to 43
513     //
514     fMax_plane = (fNumSec * fMax_planexo) +(Float_t)xon + fPl;
515     //
516     // nummod is the integer part of the number of modules in which the maximum is contained
517     //
518     nummod = (Int_t)(((Float_t)fMax_plane)/(Float_t)fNumSec);
519     //
520     // numexpl is the number of additional planes (0,1,2) inside the module
521     //
522     numexpl = (Int_t)((Float_t)fMax_plane-(Float_t)fNumSec*(Float_t)nummod);
523     //
524     };
525     if ( xemax_en > xomax_en && xemax_en > yemax_en && xemax_en > yomax_en ){
526     if ( debug ) printf(" XE is MAX %i %i %i %i\n",xen,yon,xon,yen);
527     fMax_plane = (fNumSec * fMax_planexe) +(Float_t)xen + fPl;
528     nummod = (Int_t)(((Float_t)fMax_plane)/(Float_t)fNumSec);
529     numexpl = (Int_t)((Float_t)fMax_plane-(Float_t)fNumSec*(Float_t)nummod);
530     //
531     };
532    
533     if ( yemax_en > xomax_en && yemax_en > xemax_en && yemax_en > yomax_en ){
534     if ( debug ) printf(" YE is MAX %i %i %i %i\n",xen,yon,xon,yen);
535     fMax_plane = (fNumSec * fMax_planeye) +(Float_t)yen + fPl;
536     nummod = (Int_t)(((Float_t)fMax_plane)/(Float_t)fNumSec);
537     numexpl = (Int_t)((Float_t)fMax_plane-(Float_t)fNumSec*(Float_t)nummod);
538     //
539     };
540     if ( yomax_en > xemax_en && yomax_en > yemax_en && yomax_en > xomax_en ){
541     if ( debug ) printf(" YO is MAX %i %i %i %i\n",xen,yon,xon,yen);
542     fMax_plane = (fNumSec * fMax_planeyo) +(Float_t)yon + fPl;
543     nummod = (Int_t)(((Float_t)fMax_plane)/(Float_t)fNumSec);
544     numexpl = (Int_t)((Float_t)fMax_plane-(Float_t)fNumSec*(Float_t)nummod);
545     //
546 mocchiut 1.3 };
547 mocchiut 1.4 //
548     // find the plane up to which is necessary to integrate the energy for each section
549     //
550     Int_t a = 0;
551     Int_t b = 0;
552     Int_t c = 0;
553     if ( numexpl > xen ) a = 1;
554     if ( numexpl > yon ) b = 1;
555     if ( numexpl > xon ) c = 1;
556     fMax_planexe = nummod;
557     fMax_planeyo = nummod - 1 + a;
558     fMax_planexo = nummod - 1 + b;
559     fMax_planeye = nummod - 1 + c;
560     if ( debug ) printf(" fMax_plane %f nummod %i numexpl %i a %i b %i c %i \n",fMax_plane,nummod,numexpl,a,b,c);
561     if ( debug ) printf(" DONE: Check maximum, coherent mode: xoen %f yoen %f xeen %f yeen %f xomax %i yomax %i xemax %i yemax %i\n",xomax_en,yomax_en,xemax_en,yemax_en,fMax_planexo,fMax_planeyo,fMax_planexe,fMax_planeye);
562 mocchiut 1.1 };
563     //
564 mocchiut 1.4 // for each plane of the calorimeter find the position of the track in the direction along the strip (where we do not have a measurement from the selected plane) by looking at the plane above/below of the other view and extrapolating the trajectory to the given plane
565     //
566 mocchiut 1.1 Float_t track_coordx[22][2];
567     Float_t track_coordy[22][2];
568     //
569     Float_t tgx_cl2;
570     Float_t tgy_cl2;
571 mocchiut 1.4 tgx_cl2 = cl2->tanx[0];
572     tgy_cl2 = cl2->tany[0];
573 mocchiut 1.1 //
574     for (Int_t p=0; p<22; p++){
575 mocchiut 1.4 track_coordy[p][1] = cl2->cbar[p][1];
576     track_coordx[p][1] = cl2->cbar[p][0] - fabs(trk_z[p][1]-trk_z[p][0])*tgx_cl2;
577     track_coordx[p][0] = cl2->cbar[p][0];
578     track_coordy[p][0] = cl2->cbar[p][1] - fabs(trk_z[p][1]-trk_z[p][0])*tgy_cl2;
579 mocchiut 1.1 if ( debug ) printf(" p %i track_coordy[p][1] %f track_coordx[p][1] %f track_coordx[p][0] %f track_coordy[p][0] %f \n",p,track_coordy[p][1],track_coordx[p][1],track_coordx[p][0],track_coordy[p][0]);
580     };
581     //
582 mocchiut 1.4 if ( debug ) printf(" acceptance fNumSec %i tgx %f tgy %f\n",fNumSec,tgx_cl2,tgy_cl2);
583 mocchiut 1.1 //
584     if ( section.Contains("XO") ){
585 mocchiut 1.4 //
586     // check event is inside XO acceptance
587     //
588 mocchiut 1.1 for (Int_t i=0; i<11; i++) {
589     if
590     (
591     (((track_coordx[2*i+1][1]>=(-12.054+fM))&&
592     (track_coordx[2*i+1][1]<=(-4.246-fM)))&&
593 mocchiut 1.4 (((cl2->cbar[2*i+1][1]>=xo1 + fM1)&&
594     (cl2->cbar[2*i+1][1]<=xo2 - fM1 ))||
595     ((cl2->cbar[2*i+1][1]>=xo3 + fM1)&&
596     (cl2->cbar[2*i+1][1]<=xo4 - fM1 ))||
597     ((cl2->cbar[2*i+1][1]>=xo5 + fM1)&&
598     (cl2->cbar[2*i+1][1]<=xo6 - fM1 ))))||
599 mocchiut 1.1
600     (((track_coordx[2*i+1][1]>=(-4.004+fM))&&
601     (track_coordx[2*i+1][1]<=(3.804-fM)))&&
602 mocchiut 1.4 (((cl2->cbar[2*i+1][1]>=xo1 + fM1)&&
603     (cl2->cbar[2*i+1][1]<=xo2 - fM1 ))||
604     ((cl2->cbar[2*i+1][1]>=xo3 + fM1)&&
605     (cl2->cbar[2*i+1][1]<=xo4 - fM1))||
606     ((cl2->cbar[2*i+1][1]>=xo5 + fM1)&&
607     (cl2->cbar[2*i+1][1]<=xo6 - fM1 ))))||
608 mocchiut 1.1
609     (((track_coordx[2*i+1][1]>=(4.046+fM))&&
610     (track_coordx[2*i+1][1]<=(11.854-fM)))&&
611 mocchiut 1.4 (((cl2->cbar[2*i+1][1]>=xo1 + fM1)&&
612     (cl2->cbar[2*i+1][1]<=xo2 - fM1))||
613     ((cl2->cbar[2*i+1][1]>=xo3 + fM1)&&
614     (cl2->cbar[2*i+1][1]<=xo4 - fM1 ))||
615     ((cl2->cbar[2*i+1][1]>=xo5 + fM1)&&
616     (cl2->cbar[2*i+1][1]<=xo6 - fM1 ))))
617 mocchiut 1.1 ){
618     fXosel = true;
619 mocchiut 1.3 fXoout = i;
620 mocchiut 1.1 } else {
621     fXosel = false;
622     break;
623     };
624     };
625 mocchiut 1.4 //
626     // if it goes out of the acceptance BUT the plane up to which we are integrating the energy is contained then the event is "partially" contained
627     //
628     if ( !fXosel && fXoout >= fXomin && fXoout >= (Int_t)(fMax_planexo+nPl) ){
629     if ( debug ) printf(" XO: this event is only partially contained: fXoout %i fXomin %i fMax_planexo + nPl %i \n",fXoout,fXomin,(Int_t)(fMax_planexo+nPl));
630 mocchiut 1.3 fPartsel = true;
631     fXosel = true;
632     };
633 mocchiut 1.4 //
634     // event is contained (or partially contained) hence we can integrate energy up to the maximum and calculate the energy as measured by this section
635     //
636 mocchiut 1.3 if ( fXosel ){
637 mocchiut 1.4 for (Int_t iplm=0;iplm<=TMath::Min(10,(Int_t)(fMax_planexo+nPl)) ;iplm++) fXOen_maxplane += en_xop[iplm];
638     fEnergyxo = fXOen_maxplane/fConv_rxo;
639 mocchiut 1.3 };
640 mocchiut 1.1 };
641     //
642     if ( section.Contains("XE") ){
643     for (Int_t i=0; i<11; i++) {
644     if
645     (
646     (((track_coordx[2*i][1]>=(-11.854+fM))&&
647     (track_coordx[2*i][1]<=(-4.046-fM)))&&
648 mocchiut 1.4 (((cl2->cbar[2*i][1]>=xe1 + fM1)&&
649     (cl2->cbar[2*i][1]<=xe2 - fM1 ))||
650     ((cl2->cbar[2*i][1]>=xe3 + fM1)&&
651     (cl2->cbar[2*i][1]<=xe4 - fM1 ))||
652     ((cl2->cbar[2*i][1]>=xe5 + fM1)&&
653     (cl2->cbar[2*i][1]<=xe6 - fM1 ))))||
654 mocchiut 1.1
655     (((track_coordx[2*i][1]>=(-3.804+fM))&&
656     (track_coordx[2*i][1]<=(4.004-fM)))&&
657 mocchiut 1.4 (((cl2->cbar[2*i][1]>=xe1 + fM1)&&
658     (cl2->cbar[2*i][1]<=xe2 - fM1 ))||
659     ((cl2->cbar[2*i][1]>=xe3 + fM1)&&
660     (cl2->cbar[2*i][1]<=xe4 - fM1))||
661     ((cl2->cbar[2*i][1]>=xe5 + fM1)&&
662     (cl2->cbar[2*i][1]<=xe6 - fM1 ))))||
663 mocchiut 1.1
664     (((track_coordx[2*i][1]>=(4.246+fM))&&
665     (track_coordx[2*i][1]<=(12.054-fM)))&&
666 mocchiut 1.4 (((cl2->cbar[2*i][1]>=xe1 + fM1)&&
667     (cl2->cbar[2*i][1]<=xe2 - fM1))||
668     ((cl2->cbar[2*i][1]>=xe3 + fM1)&&
669     (cl2->cbar[2*i][1]<=xe4 - fM1 ))||
670     ((cl2->cbar[2*i][1]>=xe5 + fM1)&&
671     (cl2->cbar[2*i][1]<=xe6 - fM1 ))))
672 mocchiut 1.1 ){
673     fXesel = true;
674 mocchiut 1.3 fXeout = i;
675 mocchiut 1.1 } else {
676     fXesel = false;
677     break;
678     };
679     };
680 mocchiut 1.4 if ( !fXesel && fXeout >= fXemin && fXeout >= (Int_t)(fMax_planexe+nPl) ){
681     if ( debug ) printf(" XE: this event is only partially contained: fXeout %i fXemin %i fMax_planexe + nPl %i \n",fXeout,fXemin,(Int_t)(fMax_planexe+nPl));
682 mocchiut 1.3 fPartsel = true;
683     fXesel = true;
684     };
685     if ( fXesel ){
686 mocchiut 1.4 for (Int_t iplm=0;iplm<=TMath::Min(10,(Int_t)(fMax_planexe+nPl)) ;iplm++) fXEen_maxplane += en_xep[iplm];
687     fEnergyxe = fXEen_maxplane/fConv_rxe;
688 mocchiut 1.3 };
689 mocchiut 1.1 };
690     //
691     if ( section.Contains("YE") ){
692     for (Int_t i=0; i<11; i++) {
693     if
694     (
695     (((track_coordy[2*i+1][0]>=(-12.154+fM))&&
696     (track_coordy[2*i+1][0]<=(-4.346-fM)))&&
697 mocchiut 1.4 (((cl2->cbar[2*i+1][0]>=ye1 + fM1)&&
698     (cl2->cbar[2*i+1][0]<=ye2 - fM1 ))||
699     ((cl2->cbar[2*i+1][0]>=ye3 + fM1)&&
700     (cl2->cbar[2*i+1][0]<=ye4 - fM1 ))||
701     ((cl2->cbar[2*i+1][0]>=ye5 + fM1)&&
702     (cl2->cbar[2*i+1][0]<=ye6 - fM1 ))))||
703 mocchiut 1.1
704     (((track_coordy[2*i+1][0]>=(-4.104+fM))&&
705     (track_coordy[2*i+1][0]<=(3.704-fM)))&&
706 mocchiut 1.4 (((cl2->cbar[2*i+1][0]>=ye1 + fM1)&&
707     (cl2->cbar[2*i+1][0]<=ye2 - fM1 ))||
708     ((cl2->cbar[2*i+1][0]>=ye3 + fM1)&&
709     (cl2->cbar[2*i+1][0]<=ye4 - fM1))||
710     ((cl2->cbar[2*i+1][0]>=ye5 + fM1)&&
711     (cl2->cbar[2*i+1][0]<=ye6 - fM1 ))))||
712 mocchiut 1.1
713     (((track_coordy[2*i+1][0]>=(3.946+fM))&&
714     (track_coordy[2*i+1][0]<=(11.754-fM)))&&
715 mocchiut 1.4 (((cl2->cbar[2*i+1][0]>=ye1 + fM1)&&
716     (cl2->cbar[2*i+1][0]<=ye2 - fM1))||
717     ((cl2->cbar[2*i+1][0]>=ye3 + fM1)&&
718     (cl2->cbar[2*i+1][0]<=ye4 - fM1 ))||
719     ((cl2->cbar[2*i+1][0]>=ye5 + fM1)&&
720     (cl2->cbar[2*i+1][0]<=ye6 - fM1 ))))
721 mocchiut 1.1 ){
722     fYesel = true;
723 mocchiut 1.3 fYeout = i;
724 mocchiut 1.1 } else {
725     fYesel = false;
726     break;
727     };
728     };
729 mocchiut 1.4 if ( !fYesel && fYeout >= fYemin && fYeout >= (Int_t)(fMax_planeye+nPl) ){
730     if ( debug ) printf(" YE: this event is only partially contained: fYeout %i fYemin %i fMax_planeye + nPl %i \n",fYeout,fYemin,(Int_t)(fMax_planeye+nPl));
731 mocchiut 1.3 fPartsel = true;
732     fYesel = true;
733     };
734     if ( fYesel ){
735 mocchiut 1.4 for (Int_t iplm=0;iplm<=TMath::Min(10,(Int_t)(fMax_planeye+nPl)) ;iplm++) fYEen_maxplane += en_yep[iplm];
736     fEnergyye = fYEen_maxplane/fConv_rye;
737 mocchiut 1.3 };
738 mocchiut 1.1 };
739     //
740     if ( section.Contains("YO") ){
741     for (Int_t i=0; i<11; i++) {
742 mocchiut 1.4 if ( debug ) printf(" i %i track_coordy[2*i][0] %f cl2->cbar[2*i][0] %f \n",i,track_coordy[2*i][0],cl2->cbar[2*i][0]);
743 mocchiut 1.1 if ( debug ) printf(" i %i fm %f fm1 %f yo1 %g yo2 %f yo3 %f yo4 %f yo5 %f yo6 %f \n",i,fM,fM1,yo1,yo2,yo3,yo4,yo5,yo6);
744     if
745     (
746     (((track_coordy[2*i][0]>=(-11.954+fM))&&
747     (track_coordy[2*i][0]<=(-4.146-fM)))&&
748 mocchiut 1.4 (((cl2->cbar[2*i][0]>=yo1 + fM1)&&
749     (cl2->cbar[2*i][0]<=yo2 - fM1 ))||
750     ((cl2->cbar[2*i][0]>=yo3 + fM1)&&
751     (cl2->cbar[2*i][0]<=yo4 - fM1 ))||
752     ((cl2->cbar[2*i][0]>=yo5 + fM1)&&
753     (cl2->cbar[2*i][0]<=yo6 - fM1 ))))||
754 mocchiut 1.1
755     (((track_coordy[2*i][0]>=(-3.904+fM))&&
756     (track_coordy[2*i][0]<=(+3.904-fM)))&&
757 mocchiut 1.4 (((cl2->cbar[2*i][0]>=yo1 + fM1)&&
758     (cl2->cbar[2*i][0]<=yo2 - fM1 ))||
759     ((cl2->cbar[2*i][0]>=yo3 + fM1)&&
760     (cl2->cbar[2*i][0]<=yo4 - fM1))||
761     ((cl2->cbar[2*i][0]>=yo5 + fM1)&&
762     (cl2->cbar[2*i][0]<=yo6 - fM1 ))))||
763 mocchiut 1.1
764     (((track_coordy[2*i][0]>=(4.146+fM))&&
765     (track_coordy[2*i][0]<=(11.954-fM)))&&
766 mocchiut 1.4 (((cl2->cbar[2*i][0]>=yo1 + fM1)&&
767     (cl2->cbar[2*i][0]<=yo2 - fM1))||
768     ((cl2->cbar[2*i][0]>=yo3 + fM1)&&
769     (cl2->cbar[2*i][0]<=yo4 - fM1 ))||
770     ((cl2->cbar[2*i][0]>=yo5 + fM1)&&
771     (cl2->cbar[2*i][0]<=yo6 - fM1 ))))
772 mocchiut 1.1 ){
773     fYosel = true;
774 mocchiut 1.3 fYoout = i;
775 mocchiut 1.1 } else {
776     fYosel = false;
777     break;
778     };
779     };
780 mocchiut 1.4 if ( !fYosel && fYoout >= fYomin && fYoout >= (Int_t)(fMax_planeyo+nPl) ){
781     if ( debug ) printf(" YO: this event is only partially contained: fYoout %i fYomin %i fMax_planeyo + nPl %i \n",fYoout,fYomin,(Int_t)(fMax_planeyo+nPl));
782 mocchiut 1.3 fPartsel = true;
783     fYosel = true;
784     };
785     if ( fYosel ){
786 mocchiut 1.4 for (Int_t iplm=0;iplm<=TMath::Min(10,(Int_t)(fMax_planeyo+nPl)) ;iplm++) fYOen_maxplane += en_yop[iplm];
787     fEnergyyo = fYOen_maxplane/fConv_ryo;
788 mocchiut 1.3 };
789 mocchiut 1.1 };
790     //
791 mocchiut 1.4 // Count the number of sections in which the event is contained
792     //
793 mocchiut 1.1 fCount = (Float_t)((Int_t)fXesel+(Int_t)fXosel+(Int_t)fYesel+(Int_t)fYosel);
794     if ( debug ) printf(" IsInside XE %i XO %i YE %i YO %i => SEL %i \n",fXesel,fXosel,fYesel,fYosel,fSel);
795 mocchiut 1.4 //
796     if ( indep ){
797     //
798     // independent mode, average the energy measurement and max plane of the contained sections
799     //
800     fSel = ( fXesel || fYesel || fXosel || fYosel );
801     fMax_plane = (Float_t)(fMax_planeyo+fMax_planeye+fMax_planexo+fMax_planexe)/fCount;
802     fEnergy = (fEnergyxe+fEnergyyo+fEnergyye+fEnergyxo)/fCount;
803     //
804     } else {
805     //
806     // coherent mode, sum the energy [MIP] of the given sections and convert using fConv_rxo. **** NB: it is assumed that the conversion factor is unique and the method SetConvertionFactor(Float_t) has been used**** The event is selected only if it is contained in all the given sections
807     //
808     if ( fCount != fNumSec ){
809     fSel = false;
810     } else {
811     fSel = true;
812     };
813     fEnergy = (fXEen_maxplane+fYOen_maxplane+fYEen_maxplane+fXOen_maxplane)/fConv_rxo;
814     };
815     //
816     if ( debug ) printf("sel %i indep %i fMax_plane %f conv_r %f en_maxplane %f encalo %f \n",fSel,indep,fMax_plane,fConv_rxo,fXOen_maxplane,fEnergy);
817     //
818     // finish exit
819 mocchiut 1.1 //
820     return fSel;
821     //
822     }
823    
824     void CaloEnergy::Process(){
825     TString xo = "XO";
826     this->Process(xo);
827     }
828    
829    
830     void CaloEnergy::Process(TString section){
831     //
832 mocchiut 1.4 // process the event
833     //
834 mocchiut 1.1 TString ntr = section;
835     if ( !L2 ){
836     printf(" ERROR: cannot find PamLevel2 object, use the correct constructor or check your program!\n");
837     printf(" ERROR: CaloEnergy variables not filled \n");
838     return;
839     };
840     //
841     Bool_t newentry = false;
842     //
843     if ( L2->IsORB() ){
844     if ( L2->GetOrbitalInfo()->pkt_num != PKT || L2->GetOrbitalInfo()->OBT != OBT || L2->GetOrbitalInfo()->absTime != atime || strcmp(ntr.Data(),sntr.Data()) ){
845     newentry = true;
846     OBT = L2->GetOrbitalInfo()->OBT;
847     PKT = L2->GetOrbitalInfo()->pkt_num;
848     atime = L2->GetOrbitalInfo()->absTime;
849     sntr = ntr;
850     };
851     } else {
852     newentry = true;
853     };
854     //
855 mocchiut 1.4 // if we have already called this method for this event and no input changed then return fSel and exit
856     //
857 mocchiut 1.1 if ( !newentry ) return;
858     //
859 mocchiut 1.4 // process the event
860     //
861 mocchiut 1.1 if ( debug ) printf(" Processing event at OBT %u PKT %u time %u section %s\n",OBT,PKT,atime,section.Data());
862     //
863 mocchiut 1.4 // check if the cylinder of integration can go out of the sensor given the frame which has been set (if we use all the calorimeter fRad is < 0 and the printout is suppressed)
864 mocchiut 1.1 //
865 mocchiut 1.2 if ( (fM1+0.122-0.244*(Float_t)fRad) < 0. ) printf("Error: (fM1+0.122-0.244*(Float_t)fRad) < 0. fM1 %f fRad %i %f \n",fM1,fRad,(fM1+0.122-0.244*(Float_t)fRad));
866     //
867 mocchiut 1.1 if ( fLong ){
868 mocchiut 1.4 //
869     // use long fit to measure energy NOT IMPLEMENTED YET
870     //
871 mocchiut 1.1 } else {
872     //
873 mocchiut 1.4 // use the energy measurement
874     //
875 mocchiut 1.1 if ( this->IsInsideAcceptance(section) ){
876     //
877 mocchiut 1.4 // the event is good
878     //
879 mocchiut 1.1 if ( debug ) printf(" XE %i XO %i YE %i YO %i \n",fXesel,fXosel,fYesel,fYosel);
880     //
881     } else {
882 mocchiut 1.4 //
883     // if the event is not in the acceptance, return a negative energy.
884     //
885 mocchiut 1.1 if ( debug ) printf(" Outside acceptance \n");
886 mocchiut 1.4 fEnergy *= -1.;
887     //
888 mocchiut 1.1 };
889     };
890     //
891     }

  ViewVC Help
Powered by ViewVC 1.1.23