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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.12 - (hide annotations) (download)
Wed Mar 12 14:19:21 2008 UTC (16 years, 8 months ago) by mocchiut
Branch: MAIN
Changes since 1.11: +1 -1 lines
Bug in StdEdx1 determination fixed (thanks to Laura)

1 mocchiut 1.1 #include <CaloNuclei.h>
2    
3     //--------------------------------------
4     /**
5     * Default constructor
6     */
7     CaloNuclei::CaloNuclei(){
8     Clear();
9     };
10    
11     CaloNuclei::CaloNuclei(PamLevel2 *l2p){
12     //
13     Clear();
14     //
15     L2 = l2p;
16     //
17     if ( !L2->IsORB() ) printf(" WARNING: OrbitalInfo Tree is needed, the plugin could not work properly without it \n");
18     //
19     OBT = 0;
20     PKT = 0;
21     atime = 0;
22     N = 5;
23 mocchiut 1.2 R = 3;
24 mocchiut 1.1 //
25 mocchiut 1.4 debug = false;
26 mocchiut 1.5 usetrack = true;
27 mocchiut 1.4 //
28 mocchiut 1.1 };
29    
30     void CaloNuclei::Clear(){
31     //
32 mocchiut 1.11 UN = 0;
33 mocchiut 1.3 tr = 0;
34 mocchiut 1.5 sntr = 0;
35 mocchiut 1.1 interplane = 0;
36     preq = 0.;
37     postq = 0.;
38 mocchiut 1.10 stdedx1 = 0.;
39     ethr = 0.;
40 mocchiut 1.1 dedx1 = 0.;
41     dedx3 = 0.;
42     qpremean = 0.;
43     qpremeanN = 0.;
44     //
45     multhit = false;
46     gap = false;
47     //
48     };
49    
50     void CaloNuclei::Print(){
51     //
52 mocchiut 1.2 Process();
53     //
54 mocchiut 1.3 printf("========================================================================\n");
55 mocchiut 1.5 printf(" OBT: %u PKT: %u ATIME: %u Track %i Use track %i \n",OBT,PKT,atime,tr,usetrack);
56     printf(" interplane [number of available dE/dx before interaction]:.. %i\n",interplane);
57     printf(" ethr [threshold used to determine interplane]:.............. %f \n",ethr);
58     printf(" dedx1 [dE/dx from the first calorimeter plane]:............. %f \n",dedx1);
59     printf(" stdedx1 [dE/dx from the first calorimeter plane standalone]: %f \n",stdedx1);
60     printf(" dedx3 [dE/dx (average) if the first 3 Si planes]:........... %f \n",dedx3);
61     printf(" multhit [true if interplane determined by multiple hits]:... %i \n",multhit);
62     printf(" gap [true if interplane determined by a gap]:............... %i \n",gap);
63     printf(" preq [total energy in MIP before the interaction plane]:.... %f \n",preq);
64     printf(" postq [total energy in MIP after the interaction plane]:.... %f \n",postq);
65     printf(" qpremean [truncated mean using 3 planes and 3 strips]:...... %f \n",qpremean);
66     printf(" N [no of used plane]:....................................... %i \n",N);
67     printf(" R [no strip used per plane ]:............................... %i \n",R);
68     printf(" qpremeanN [truncated mean using N planes and R strips]:..... %f \n",qpremeanN);
69 mocchiut 1.3 printf("========================================================================\n");
70 mocchiut 1.1 //
71     };
72    
73     void CaloNuclei::Delete(){
74     Clear();
75     //delete this;
76     };
77    
78    
79     void CaloNuclei::Process(){
80 mocchiut 1.3 Process(0);
81     };
82    
83     void CaloNuclei::Process(Int_t ntr){
84     //
85 mocchiut 1.1 if ( !L2 ){
86     printf(" ERROR: cannot find PamLevel2 object, use the correct constructor or check your program!\n");
87     printf(" ERROR: CaloNuclei variables not filled \n");
88     return;
89     };
90     //
91     Bool_t newentry = false;
92     //
93     if ( L2->IsORB() ){
94 mocchiut 1.5 if ( L2->GetOrbitalInfo()->pkt_num != PKT || L2->GetOrbitalInfo()->OBT != OBT || L2->GetOrbitalInfo()->absTime != atime || ntr != sntr ){
95 mocchiut 1.1 newentry = true;
96     OBT = L2->GetOrbitalInfo()->OBT;
97     PKT = L2->GetOrbitalInfo()->pkt_num;
98     atime = L2->GetOrbitalInfo()->absTime;
99 mocchiut 1.5 sntr = ntr;
100 mocchiut 1.1 };
101     } else {
102     newentry = true;
103     };
104     //
105     if ( !newentry ) return;
106     //
107 mocchiut 1.3 tr = ntr;
108     //
109 mocchiut 1.4 if ( debug ) printf(" Processing event at OBT %u PKT %u time %u \n",OBT,PKT,atime);
110 mocchiut 1.1 //
111     Clear();
112 mocchiut 1.11 //
113 mocchiut 1.6 if ( debug ) printf(" Always calculate stdedx1 \n");
114 mocchiut 1.1 //
115 mocchiut 1.5 // Always calculate stdedx1
116 mocchiut 1.1 //
117     Int_t view = 0;
118     Int_t plane = 0;
119     Int_t strip = 0;
120 mocchiut 1.5 Int_t indx = 0;
121     Float_t vfpl[96];
122     Int_t stfpl[96];
123     memset(vfpl, 0, 96*sizeof(Float_t));
124     memset(stfpl, 0, 96*sizeof(Int_t));
125 mocchiut 1.1 Float_t mip = 0.;
126 mocchiut 1.5 for ( Int_t i=0; i<L2->GetCaloLevel1()->istrip; i++ ){
127     //
128     mip = L2->GetCaloLevel1()->DecodeEstrip(i,view,plane,strip);
129     //
130     // put in vfpl vector the energy release on the first plane
131     //
132     if ( strip != -1 && view == 1 && plane == 0 ) {
133     stfpl[indx] = strip;
134     vfpl[indx] = mip;
135     indx++;
136     };
137     //
138     };
139     //
140 mocchiut 1.6 if ( debug ) printf(" find energy released along the strip of maximum on the first plane and on the two neighbour strips \n");
141     //
142 mocchiut 1.5 // find energy released along the strip of maximum on the first plane and on the two neighbour strips
143     //
144     if ( indx > 0 ){
145 mocchiut 1.12 Int_t mindx = (Int_t)TMath::LocMax(indx,vfpl);
146 mocchiut 1.5 for (Int_t ii=0; ii<indx; ii++){
147     if ( stfpl[ii] == stfpl[mindx] ) stdedx1 += vfpl[ii];
148     if ( (mindx-1)>=0 && stfpl[ii] == stfpl[mindx-1] ) stdedx1 += vfpl[ii];
149     if ( (mindx+1)<96 && stfpl[ii] == stfpl[mindx+1] ) stdedx1 += vfpl[ii];
150     };
151     } else {
152     stdedx1 = 0.;
153     };
154     //
155 mocchiut 1.6 if ( debug ) printf(" if ( !usetrack ) return: usetrack %i ntr %i \n",usetrack,ntr);
156 mocchiut 1.5 //
157     //
158 mocchiut 1.8 // if ( !usetrack ) return;
159 mocchiut 1.5 //
160     PamTrack *ptrack = 0;
161     CaloTrkVar *track = 0;
162 mocchiut 1.8 //
163     if ( usetrack ){
164     if ( ntr >= 0 ){
165     ptrack = L2->GetTrack(ntr);
166     if ( ptrack ) track = ptrack->GetCaloTrack();
167     } else {
168     track = L2->GetCaloStoredTrack(ntr);
169     };
170     //
171     if ( !track && ntr >= 0 ){
172     printf(" ERROR: cannot find any track!\n");
173     printf(" ERROR: CaloNuclei variables not completely filled \n");
174     return;
175     };
176 mocchiut 1.5 } else {
177 mocchiut 1.8 if ( ntr >= 0 ){
178 mocchiut 1.9 if ( debug ) printf(" ERROR: you asked not to use a track but you are looking for track number %i !\n",ntr);
179     if ( debug ) printf(" ERROR: CaloNuclei variables not completely filled \n");
180 mocchiut 1.8 return;
181     };
182 mocchiut 1.5 };
183     //
184 mocchiut 1.1 // Float_t defethr = 6. * 0.90;
185     Float_t defethr = 6.25; // = (sqrt(9) - 0.5) ** 2.;
186     //
187     // Calculate dedx1 and dedx3
188     //
189     for ( Int_t i=0; i<L2->GetCaloLevel1()->istrip; i++ ){
190     //
191     mip = L2->GetCaloLevel1()->DecodeEstrip(i,view,plane,strip);
192     //
193 mocchiut 1.5 if ( ntr >= 0 ){
194     //
195     if ( strip != -1 &&
196     view == 1 &&
197     plane == 0 &&
198     ( strip == (track->tibar[0][1]-1) || strip == (track->tibar[0][1]-2) || strip == (track->tibar[0][1]) )
199     && true ){
200     dedx1 += mip;
201     };
202     if ( strip != -1 &&
203     (( view == 1 && ( plane == 0 || plane == 1 ) ) ||
204     ( view == 0 && plane == 0 )) &&
205     (( view == 0 && ( strip == track->tibar[0][0] || strip == (track->tibar[0][0]-1) || strip == (track->tibar[0][0]-2) )) ||
206     ( view == 1 && ( strip == track->tibar[0][1] || strip == (track->tibar[0][1]-1) || strip == (track->tibar[0][1]-2) )) ||
207     ( view == 1 && ( strip == track->tibar[1][1] || strip == (track->tibar[1][1]-1) || strip == (track->tibar[1][1]-2) ))) &&
208     true ){
209     dedx3 += mip;
210     };
211     } else {
212     //
213     if ( strip != -1 &&
214     view == 1 &&
215     plane == 0 &&
216     ( strip == (L2->GetCaloLevel2()->cibar[0][1]-1) || strip == (L2->GetCaloLevel2()->cibar[0][1]-2) || strip == (L2->GetCaloLevel2()->cibar[0][1]) )
217     && true ){
218     dedx1 += mip;
219     };
220     if ( strip != -1 &&
221     (( view == 1 && ( plane == 0 || plane == 1 ) ) ||
222     ( view == 0 && plane == 0 )) &&
223     (( view == 0 && ( strip == L2->GetCaloLevel2()->cibar[0][0] || strip == (L2->GetCaloLevel2()->cibar[0][0]-1) || strip == (L2->GetCaloLevel2()->cibar[0][0]-2) )) ||
224     ( view == 1 && ( strip == L2->GetCaloLevel2()->cibar[0][1] || strip == (L2->GetCaloLevel2()->cibar[0][1]-1) || strip == (L2->GetCaloLevel2()->cibar[0][1]-2) )) ||
225     ( view == 1 && ( strip == L2->GetCaloLevel2()->cibar[1][1] || strip == (L2->GetCaloLevel2()->cibar[1][1]-1) || strip == (L2->GetCaloLevel2()->cibar[1][1]-2) ))) &&
226     true ){
227     dedx3 += mip;
228     };
229 mocchiut 1.1 };
230     //
231     };
232     //
233     dedx3 /= 3.;
234     // Float_t mesethr = dedx1 * 0.90;
235     Float_t mesethr = 0.;
236     if ( dedx1 > 0. ) mesethr = (sqrt(dedx1) - 0.50)*(sqrt(dedx1) - 0.50);
237     Bool_t aldone = false;
238     //
239     retry:
240     //
241 mocchiut 1.4 if ( debug ) printf("retry\n");
242 mocchiut 1.1 //
243     interplane = 0;
244     //
245     ethr = TMath::Max(defethr,mesethr);
246     //
247     // Find the interaction plane "interplane"
248     //
249     Int_t gapth = 3;
250     Int_t nhit[2] = {0,0};
251     Int_t splane[2] = {-1,-1};
252     Int_t sview[2] = {-1,-1};
253     Int_t interpl[2] = {-1,-1};
254     Int_t interv[2] = {-1,-1};
255     Bool_t wmulthit[2] = {false,false};
256     Bool_t wgap[2] = {false,false};
257     Int_t ii = 0;
258     while ( ii<L2->GetCaloLevel1()->istrip ){
259     //
260     mip = L2->GetCaloLevel1()->DecodeEstrip(ii,view,plane,strip);
261     //
262 mocchiut 1.5 if ( ntr >= 0 ){
263     if ( strip != -1 && mip > ethr && !wmulthit[view] && !wgap[view] &&
264     ( strip == (track->tibar[plane][view]-1) || strip == (track->tibar[plane][view]-2) || strip == (track->tibar[plane][view]) )
265     && true ){
266     if ( debug ) printf(" inside loop: ii %i mip %f view %i plane %i strip %i tibar %i nhit %i splane %i sview %i \n",ii,mip,view,plane,strip,track->tibar[plane][view]-1,nhit[view],splane[view],sview[view]);
267     interpl[view] = plane;
268     interv[view] = view;
269     if ( splane[view] != plane || sview[view] != view ){
270     if ( nhit[view] > 1 ){
271     wmulthit[view] = true;
272     // if ( splane[view] == -1 ) splane[view] = 0; //
273     // if ( sview[view] == -1 ) sview[view] = view; //
274     interpl[view] = splane[view];
275     interv[view] = sview[view];
276     };
277     if ( plane > splane[view]+gapth ){
278     wgap[view] = true;
279     // if ( splane[view] == -1 ) splane[view] = 0;//
280     // if ( sview[view] == -1 ) sview[view] = view; //
281     interpl[view] = splane[view];
282     interv[view] = sview[view];
283     };
284     splane[view] = plane;
285     sview[view] = view;
286     nhit[view] = 1;
287     } else {
288     nhit[view]++;
289     };
290     };
291     } else {
292     if ( strip != -1 && mip > ethr && !wmulthit[view] && !wgap[view] &&
293     ( strip == (L2->GetCaloLevel2()->cibar[plane][view]-1) || strip == (L2->GetCaloLevel2()->cibar[plane][view]-2) || strip == (L2->GetCaloLevel2()->cibar[plane][view]) )
294     && true ){
295     if ( debug ) printf(" inside loop: ii %i mip %f view %i plane %i strip %i cibar %i nhit %i splane %i sview %i \n",ii,mip,view,plane,strip,L2->GetCaloLevel2()->cibar[plane][view]-1,nhit[view],splane[view],sview[view]);
296     interpl[view] = plane;
297     interv[view] = view;
298     if ( splane[view] != plane || sview[view] != view ){
299     if ( nhit[view] > 1 ){
300     wmulthit[view] = true;
301     // if ( splane[view] == -1 ) splane[view] = 0; //
302     // if ( sview[view] == -1 ) sview[view] = view; //
303     interpl[view] = splane[view];
304     interv[view] = sview[view];
305 mocchiut 1.1 };
306 mocchiut 1.5 if ( plane > splane[view]+gapth ){
307     wgap[view] = true;
308     // if ( splane[view] == -1 ) splane[view] = 0;//
309     // if ( sview[view] == -1 ) sview[view] = view; //
310     interpl[view] = splane[view];
311     interv[view] = sview[view];
312     };
313     splane[view] = plane;
314     sview[view] = view;
315     nhit[view] = 1;
316     } else {
317     nhit[view]++;
318 mocchiut 1.1 };
319     };
320     };
321     //
322     ii++;
323     //
324     };
325     //
326 mocchiut 1.4 if (debug ) printf("conversion interpl %i interv %i multhit %i interplane %i \n",interpl[0],interv[0],multhit,interplane);
327 mocchiut 1.1 Int_t winterplane[2] = {-1,-1};
328     //
329     for ( Int_t view = 0; view < 2; view++){
330     //
331     if ( nhit[view] > 1 && !wmulthit[view] && !wgap[view] ){
332     wmulthit[view] = true;
333     interpl[view] = splane[view];
334     interv[view] = sview[view];
335     };
336     //
337     if ( wmulthit[view] ) multhit = true;
338     if ( wgap[view] ) gap = true;
339     //
340     // convert view and plane number of interaction plane into number of available dE/dx measurements before the interaction plane
341     //
342     if ( interpl[view] >= 0 ) {
343     if ( interv[view] == 0 ){
344     winterplane[view] = (1 + interpl[view]) * 2;
345     } else {
346     winterplane[view] = (1 + interpl[view]) + (1 + interpl[view] - 1);
347     };
348     if ( wmulthit[view] ) winterplane[view]--;
349     };
350     };
351     if ( winterplane[0] > 0 && winterplane[1] > 0 ){
352     if ( multhit ){
353     interplane = TMath::Min(winterplane[0],winterplane[1]);
354     } else {
355     interplane = TMath::Max(winterplane[0],winterplane[1]);
356     };
357     } else {
358     if ( !winterplane[0] || !winterplane[1] ){
359     interplane = 0;
360     } else {
361     interplane = TMath::Max(winterplane[0],winterplane[1]);
362     };
363     };
364     //
365 mocchiut 1.4 if ( debug ) printf("2conversion interpl %i interv %i multhit %i interplane %i \n",interpl[1],interv[1],multhit,interplane);
366     if ( debug ) printf("3conversion winterpl0 %i winterpl1 %i \n",winterplane[0],winterplane[1]);
367 mocchiut 1.1 //
368     Int_t ipl = 0;
369     if ( interplane > 0 ){
370     //
371     // Calculate preq, postq, qpremean
372     //
373     ii = 0;
374     Int_t ind = -1;
375     Int_t qsplane = -1;
376     Int_t qsview = -1;
377 mocchiut 1.2 Int_t ind2 = -1;
378     Int_t qsplane2 = -1;
379     Int_t qsview2 = -1;
380 mocchiut 1.1 Float_t qme[200];
381     memset(qme,0,200*sizeof(Float_t));
382 mocchiut 1.2 Float_t qme2[2112];
383     memset(qme2,0,2112*sizeof(Float_t));
384 mocchiut 1.1 //
385     while ( ii<L2->GetCaloLevel1()->istrip ){
386     //
387     mip = L2->GetCaloLevel1()->DecodeEstrip(ii,view,plane,strip);
388     //
389     if ( strip != -1 ){
390     if ( view == 0 ){
391     ipl = (1 + plane) * 2;
392     } else {
393     ipl = (1 + plane) + (1 + plane - 1 );
394     };
395     if ( ipl > interplane ){
396     postq += mip;
397     } else {
398     preq += mip;
399 mocchiut 1.5 if ( ntr >= 0 ){
400     if ( strip == (track->tibar[plane][view]-1) || strip == (track->tibar[plane][view]-2) || strip == (track->tibar[plane][view]) ){
401     if ( qsplane != plane || qsview != view ){
402     qsplane = plane;
403     qsview = view;
404     ind++;
405     if ( debug && ind > 199 ) printf(" AAAGH!! \n");
406     qme[ind] = 0.;
407     };
408     qme[ind] += mip;
409 mocchiut 1.1 };
410 mocchiut 1.5 for ( Int_t ns = 0; ns < R ; ns++){
411     Int_t ms = track->tibar[plane][view] - 1 - ns + (R - 1)/2;
412     if ( strip == ms ){
413     if ( qsplane2 != plane || qsview2 != view ){
414     qsplane2 = plane;
415     qsview2 = view;
416     ind2++;
417     if ( debug && ind2 > 2112 ) printf(" AAAGH!! \n");
418     qme2[ind2] = 0.;
419     };
420     qme2[ind2] += mip;
421     };
422     };
423     } else {
424     if ( strip == (L2->GetCaloLevel2()->cibar[plane][view]-1) || strip == (L2->GetCaloLevel2()->cibar[plane][view]-2) || strip == (L2->GetCaloLevel2()->cibar[plane][view]) ){
425     if ( qsplane != plane || qsview != view ){
426     qsplane = plane;
427     qsview = view;
428     ind++;
429     if ( debug && ind > 199 ) printf(" AAAGH!! \n");
430     qme[ind] = 0.;
431 mocchiut 1.2 };
432 mocchiut 1.5 qme[ind] += mip;
433 mocchiut 1.2 };
434 mocchiut 1.5 for ( Int_t ns = 0; ns < R ; ns++){
435     Int_t ms = L2->GetCaloLevel2()->cibar[plane][view] - 1 - ns + (R - 1)/2;
436     if ( strip == ms ){
437     if ( qsplane2 != plane || qsview2 != view ){
438     qsplane2 = plane;
439     qsview2 = view;
440     ind2++;
441     if ( debug && ind2 > 2112 ) printf(" AAAGH!! \n");
442     qme2[ind2] = 0.;
443     };
444     qme2[ind2] += mip;
445     };
446     };
447     };
448 mocchiut 1.1 };
449     //
450     };
451     //
452     ii++;
453     //
454     };
455     //
456     // here we must calculate qpremean, order vector qme, select 3 lowest measurements and caculate the mean...
457     //
458 mocchiut 1.4 if ( debug ){
459     for (Int_t l=0; l < interplane; l++){
460     printf(" qme[%i] = %f \n",l,qme[l]);
461     };
462     };
463     //
464 mocchiut 1.1 Long64_t work[200];
465     ind = 0;
466     Int_t l = 0;
467 mocchiut 1.5 Int_t RN = 0;
468 mocchiut 1.1 Float_t qm = 0.;
469 mocchiut 1.2 Float_t qm2 = 0.;
470     //
471     Float_t qmt = ethr*0.8; // *0.9
472     //
473 mocchiut 1.1 Int_t uplim = TMath::Max(3,N);
474 mocchiut 1.2 //
475 mocchiut 1.1 while ( l < uplim && ind < interplane ){
476     qm = TMath::KOrdStat(interplane,qme,ind,work);
477 mocchiut 1.2 if ( qm >= qmt ){
478 mocchiut 1.5 if ( l < 3 ){
479     qpremean += qm;
480     RN++;
481     };
482 mocchiut 1.1 l++;
483 mocchiut 1.4 if ( debug ) printf(" value no %i qm %f qmt %f \n",l,qm,qmt);
484 mocchiut 1.2 };
485     ind++;
486     };
487     //
488 mocchiut 1.5 qpremean /= (Float_t)RN;
489 mocchiut 1.4 //
490 mocchiut 1.2 ind = 0;
491     l = 0;
492 mocchiut 1.5 RN = 0;
493 mocchiut 1.2 while ( l < uplim && ind < interplane ){
494     qm2 = TMath::KOrdStat(interplane,qme2,ind,work);
495     if ( qm2 >= qmt ){
496 mocchiut 1.5 if ( l < N ){
497     qpremeanN += qm2;
498     RN++;
499     };
500 mocchiut 1.2 l++;
501 mocchiut 1.5 if ( debug ) printf(" qm2 value no %i qm %f qmt %f RN %i \n",l,qm2,qmt,RN);
502 mocchiut 1.1 };
503     ind++;
504     };
505     //
506 mocchiut 1.5 qpremeanN /= (Float_t)RN;
507 mocchiut 1.11 UN = RN;
508 mocchiut 1.1 //
509 mocchiut 1.4 if ( debug ) printf(" charge is %f \n",sqrt(qpremean));
510 mocchiut 1.1 //
511     if ( mesethr != ethr && interplane >= 3 && !aldone ){
512     Float_t mesethr2 = (sqrt(qpremean) - 0.50)*(sqrt(qpremean) - 0.50);
513     if ( mesethr2 < mesethr*0.90 ){
514     mesethr = (sqrt(dedx1) - 0.25)*(sqrt(dedx1) - 0.25);
515     } else {
516     mesethr = mesethr2;
517     };
518     aldone = true;
519 mocchiut 1.7 if ( mesethr > defethr ){
520     interplane = 0;
521     preq = 0.;
522     postq = 0.;
523     qpremean = 0.;
524     qpremeanN = 0.;
525     multhit = false;
526     gap = false;
527     goto retry;
528     };
529 mocchiut 1.1 };
530     };
531     //
532 mocchiut 1.5 if ( debug ) this->Print();
533 mocchiut 1.4 if ( debug ) printf(" esci \n");
534 mocchiut 1.1 //
535     };

  ViewVC Help
Powered by ViewVC 1.1.23