/[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.13 - (hide annotations) (download)
Fri Mar 14 09:24:35 2008 UTC (16 years, 11 months ago) by mocchiut
Branch: MAIN
Changes since 1.12: +4 -2 lines
Another bug in StdeDx1 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 mocchiut 1.13 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     // if ( (mindx-1)>=0 && stfpl[ii] == stfpl[mindx-1] ) stdedx1 += vfpl[ii];
151     // if ( (mindx+1)<96 && stfpl[ii] == stfpl[mindx+1] ) stdedx1 += vfpl[ii];
152 mocchiut 1.5 };
153     } else {
154     stdedx1 = 0.;
155     };
156     //
157 mocchiut 1.6 if ( debug ) printf(" if ( !usetrack ) return: usetrack %i ntr %i \n",usetrack,ntr);
158 mocchiut 1.5 //
159     //
160 mocchiut 1.8 // if ( !usetrack ) return;
161 mocchiut 1.5 //
162     PamTrack *ptrack = 0;
163     CaloTrkVar *track = 0;
164 mocchiut 1.8 //
165     if ( usetrack ){
166     if ( ntr >= 0 ){
167     ptrack = L2->GetTrack(ntr);
168     if ( ptrack ) track = ptrack->GetCaloTrack();
169     } else {
170     track = L2->GetCaloStoredTrack(ntr);
171     };
172     //
173     if ( !track && ntr >= 0 ){
174     printf(" ERROR: cannot find any track!\n");
175     printf(" ERROR: CaloNuclei variables not completely filled \n");
176     return;
177     };
178 mocchiut 1.5 } else {
179 mocchiut 1.8 if ( ntr >= 0 ){
180 mocchiut 1.9 if ( debug ) printf(" ERROR: you asked not to use a track but you are looking for track number %i !\n",ntr);
181     if ( debug ) printf(" ERROR: CaloNuclei variables not completely filled \n");
182 mocchiut 1.8 return;
183     };
184 mocchiut 1.5 };
185     //
186 mocchiut 1.1 // Float_t defethr = 6. * 0.90;
187     Float_t defethr = 6.25; // = (sqrt(9) - 0.5) ** 2.;
188     //
189     // Calculate dedx1 and dedx3
190     //
191     for ( Int_t i=0; i<L2->GetCaloLevel1()->istrip; i++ ){
192     //
193     mip = L2->GetCaloLevel1()->DecodeEstrip(i,view,plane,strip);
194     //
195 mocchiut 1.5 if ( ntr >= 0 ){
196     //
197     if ( strip != -1 &&
198     view == 1 &&
199     plane == 0 &&
200     ( strip == (track->tibar[0][1]-1) || strip == (track->tibar[0][1]-2) || strip == (track->tibar[0][1]) )
201     && true ){
202     dedx1 += mip;
203     };
204     if ( strip != -1 &&
205     (( view == 1 && ( plane == 0 || plane == 1 ) ) ||
206     ( view == 0 && plane == 0 )) &&
207     (( view == 0 && ( strip == track->tibar[0][0] || strip == (track->tibar[0][0]-1) || strip == (track->tibar[0][0]-2) )) ||
208     ( view == 1 && ( strip == track->tibar[0][1] || strip == (track->tibar[0][1]-1) || strip == (track->tibar[0][1]-2) )) ||
209     ( view == 1 && ( strip == track->tibar[1][1] || strip == (track->tibar[1][1]-1) || strip == (track->tibar[1][1]-2) ))) &&
210     true ){
211     dedx3 += mip;
212     };
213     } else {
214     //
215     if ( strip != -1 &&
216     view == 1 &&
217     plane == 0 &&
218     ( strip == (L2->GetCaloLevel2()->cibar[0][1]-1) || strip == (L2->GetCaloLevel2()->cibar[0][1]-2) || strip == (L2->GetCaloLevel2()->cibar[0][1]) )
219     && true ){
220     dedx1 += mip;
221     };
222     if ( strip != -1 &&
223     (( view == 1 && ( plane == 0 || plane == 1 ) ) ||
224     ( view == 0 && plane == 0 )) &&
225     (( view == 0 && ( strip == L2->GetCaloLevel2()->cibar[0][0] || strip == (L2->GetCaloLevel2()->cibar[0][0]-1) || strip == (L2->GetCaloLevel2()->cibar[0][0]-2) )) ||
226     ( view == 1 && ( strip == L2->GetCaloLevel2()->cibar[0][1] || strip == (L2->GetCaloLevel2()->cibar[0][1]-1) || strip == (L2->GetCaloLevel2()->cibar[0][1]-2) )) ||
227     ( view == 1 && ( strip == L2->GetCaloLevel2()->cibar[1][1] || strip == (L2->GetCaloLevel2()->cibar[1][1]-1) || strip == (L2->GetCaloLevel2()->cibar[1][1]-2) ))) &&
228     true ){
229     dedx3 += mip;
230     };
231 mocchiut 1.1 };
232     //
233     };
234     //
235     dedx3 /= 3.;
236     // Float_t mesethr = dedx1 * 0.90;
237     Float_t mesethr = 0.;
238     if ( dedx1 > 0. ) mesethr = (sqrt(dedx1) - 0.50)*(sqrt(dedx1) - 0.50);
239     Bool_t aldone = false;
240     //
241     retry:
242     //
243 mocchiut 1.4 if ( debug ) printf("retry\n");
244 mocchiut 1.1 //
245     interplane = 0;
246     //
247     ethr = TMath::Max(defethr,mesethr);
248     //
249     // Find the interaction plane "interplane"
250     //
251     Int_t gapth = 3;
252     Int_t nhit[2] = {0,0};
253     Int_t splane[2] = {-1,-1};
254     Int_t sview[2] = {-1,-1};
255     Int_t interpl[2] = {-1,-1};
256     Int_t interv[2] = {-1,-1};
257     Bool_t wmulthit[2] = {false,false};
258     Bool_t wgap[2] = {false,false};
259     Int_t ii = 0;
260     while ( ii<L2->GetCaloLevel1()->istrip ){
261     //
262     mip = L2->GetCaloLevel1()->DecodeEstrip(ii,view,plane,strip);
263     //
264 mocchiut 1.5 if ( ntr >= 0 ){
265     if ( strip != -1 && mip > ethr && !wmulthit[view] && !wgap[view] &&
266     ( strip == (track->tibar[plane][view]-1) || strip == (track->tibar[plane][view]-2) || strip == (track->tibar[plane][view]) )
267     && true ){
268     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]);
269     interpl[view] = plane;
270     interv[view] = view;
271     if ( splane[view] != plane || sview[view] != view ){
272     if ( nhit[view] > 1 ){
273     wmulthit[view] = true;
274     // if ( splane[view] == -1 ) splane[view] = 0; //
275     // if ( sview[view] == -1 ) sview[view] = view; //
276     interpl[view] = splane[view];
277     interv[view] = sview[view];
278     };
279     if ( plane > splane[view]+gapth ){
280     wgap[view] = true;
281     // if ( splane[view] == -1 ) splane[view] = 0;//
282     // if ( sview[view] == -1 ) sview[view] = view; //
283     interpl[view] = splane[view];
284     interv[view] = sview[view];
285     };
286     splane[view] = plane;
287     sview[view] = view;
288     nhit[view] = 1;
289     } else {
290     nhit[view]++;
291     };
292     };
293     } else {
294     if ( strip != -1 && mip > ethr && !wmulthit[view] && !wgap[view] &&
295     ( strip == (L2->GetCaloLevel2()->cibar[plane][view]-1) || strip == (L2->GetCaloLevel2()->cibar[plane][view]-2) || strip == (L2->GetCaloLevel2()->cibar[plane][view]) )
296     && true ){
297     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]);
298     interpl[view] = plane;
299     interv[view] = view;
300     if ( splane[view] != plane || sview[view] != view ){
301     if ( nhit[view] > 1 ){
302     wmulthit[view] = true;
303     // if ( splane[view] == -1 ) splane[view] = 0; //
304     // if ( sview[view] == -1 ) sview[view] = view; //
305     interpl[view] = splane[view];
306     interv[view] = sview[view];
307 mocchiut 1.1 };
308 mocchiut 1.5 if ( plane > splane[view]+gapth ){
309     wgap[view] = true;
310     // if ( splane[view] == -1 ) splane[view] = 0;//
311     // if ( sview[view] == -1 ) sview[view] = view; //
312     interpl[view] = splane[view];
313     interv[view] = sview[view];
314     };
315     splane[view] = plane;
316     sview[view] = view;
317     nhit[view] = 1;
318     } else {
319     nhit[view]++;
320 mocchiut 1.1 };
321     };
322     };
323     //
324     ii++;
325     //
326     };
327     //
328 mocchiut 1.4 if (debug ) printf("conversion interpl %i interv %i multhit %i interplane %i \n",interpl[0],interv[0],multhit,interplane);
329 mocchiut 1.1 Int_t winterplane[2] = {-1,-1};
330     //
331     for ( Int_t view = 0; view < 2; view++){
332     //
333     if ( nhit[view] > 1 && !wmulthit[view] && !wgap[view] ){
334     wmulthit[view] = true;
335     interpl[view] = splane[view];
336     interv[view] = sview[view];
337     };
338     //
339     if ( wmulthit[view] ) multhit = true;
340     if ( wgap[view] ) gap = true;
341     //
342     // convert view and plane number of interaction plane into number of available dE/dx measurements before the interaction plane
343     //
344     if ( interpl[view] >= 0 ) {
345     if ( interv[view] == 0 ){
346     winterplane[view] = (1 + interpl[view]) * 2;
347     } else {
348     winterplane[view] = (1 + interpl[view]) + (1 + interpl[view] - 1);
349     };
350     if ( wmulthit[view] ) winterplane[view]--;
351     };
352     };
353     if ( winterplane[0] > 0 && winterplane[1] > 0 ){
354     if ( multhit ){
355     interplane = TMath::Min(winterplane[0],winterplane[1]);
356     } else {
357     interplane = TMath::Max(winterplane[0],winterplane[1]);
358     };
359     } else {
360     if ( !winterplane[0] || !winterplane[1] ){
361     interplane = 0;
362     } else {
363     interplane = TMath::Max(winterplane[0],winterplane[1]);
364     };
365     };
366     //
367 mocchiut 1.4 if ( debug ) printf("2conversion interpl %i interv %i multhit %i interplane %i \n",interpl[1],interv[1],multhit,interplane);
368     if ( debug ) printf("3conversion winterpl0 %i winterpl1 %i \n",winterplane[0],winterplane[1]);
369 mocchiut 1.1 //
370     Int_t ipl = 0;
371     if ( interplane > 0 ){
372     //
373     // Calculate preq, postq, qpremean
374     //
375     ii = 0;
376     Int_t ind = -1;
377     Int_t qsplane = -1;
378     Int_t qsview = -1;
379 mocchiut 1.2 Int_t ind2 = -1;
380     Int_t qsplane2 = -1;
381     Int_t qsview2 = -1;
382 mocchiut 1.1 Float_t qme[200];
383     memset(qme,0,200*sizeof(Float_t));
384 mocchiut 1.2 Float_t qme2[2112];
385     memset(qme2,0,2112*sizeof(Float_t));
386 mocchiut 1.1 //
387     while ( ii<L2->GetCaloLevel1()->istrip ){
388     //
389     mip = L2->GetCaloLevel1()->DecodeEstrip(ii,view,plane,strip);
390     //
391     if ( strip != -1 ){
392     if ( view == 0 ){
393     ipl = (1 + plane) * 2;
394     } else {
395     ipl = (1 + plane) + (1 + plane - 1 );
396     };
397     if ( ipl > interplane ){
398     postq += mip;
399     } else {
400     preq += mip;
401 mocchiut 1.5 if ( ntr >= 0 ){
402     if ( strip == (track->tibar[plane][view]-1) || strip == (track->tibar[plane][view]-2) || strip == (track->tibar[plane][view]) ){
403     if ( qsplane != plane || qsview != view ){
404     qsplane = plane;
405     qsview = view;
406     ind++;
407     if ( debug && ind > 199 ) printf(" AAAGH!! \n");
408     qme[ind] = 0.;
409     };
410     qme[ind] += mip;
411 mocchiut 1.1 };
412 mocchiut 1.5 for ( Int_t ns = 0; ns < R ; ns++){
413     Int_t ms = track->tibar[plane][view] - 1 - ns + (R - 1)/2;
414     if ( strip == ms ){
415     if ( qsplane2 != plane || qsview2 != view ){
416     qsplane2 = plane;
417     qsview2 = view;
418     ind2++;
419     if ( debug && ind2 > 2112 ) printf(" AAAGH!! \n");
420     qme2[ind2] = 0.;
421     };
422     qme2[ind2] += mip;
423     };
424     };
425     } else {
426     if ( strip == (L2->GetCaloLevel2()->cibar[plane][view]-1) || strip == (L2->GetCaloLevel2()->cibar[plane][view]-2) || strip == (L2->GetCaloLevel2()->cibar[plane][view]) ){
427     if ( qsplane != plane || qsview != view ){
428     qsplane = plane;
429     qsview = view;
430     ind++;
431     if ( debug && ind > 199 ) printf(" AAAGH!! \n");
432     qme[ind] = 0.;
433 mocchiut 1.2 };
434 mocchiut 1.5 qme[ind] += mip;
435 mocchiut 1.2 };
436 mocchiut 1.5 for ( Int_t ns = 0; ns < R ; ns++){
437     Int_t ms = L2->GetCaloLevel2()->cibar[plane][view] - 1 - ns + (R - 1)/2;
438     if ( strip == ms ){
439     if ( qsplane2 != plane || qsview2 != view ){
440     qsplane2 = plane;
441     qsview2 = view;
442     ind2++;
443     if ( debug && ind2 > 2112 ) printf(" AAAGH!! \n");
444     qme2[ind2] = 0.;
445     };
446     qme2[ind2] += mip;
447     };
448     };
449     };
450 mocchiut 1.1 };
451     //
452     };
453     //
454     ii++;
455     //
456     };
457     //
458     // here we must calculate qpremean, order vector qme, select 3 lowest measurements and caculate the mean...
459     //
460 mocchiut 1.4 if ( debug ){
461     for (Int_t l=0; l < interplane; l++){
462     printf(" qme[%i] = %f \n",l,qme[l]);
463     };
464     };
465     //
466 mocchiut 1.1 Long64_t work[200];
467     ind = 0;
468     Int_t l = 0;
469 mocchiut 1.5 Int_t RN = 0;
470 mocchiut 1.1 Float_t qm = 0.;
471 mocchiut 1.2 Float_t qm2 = 0.;
472     //
473     Float_t qmt = ethr*0.8; // *0.9
474     //
475 mocchiut 1.1 Int_t uplim = TMath::Max(3,N);
476 mocchiut 1.2 //
477 mocchiut 1.1 while ( l < uplim && ind < interplane ){
478     qm = TMath::KOrdStat(interplane,qme,ind,work);
479 mocchiut 1.2 if ( qm >= qmt ){
480 mocchiut 1.5 if ( l < 3 ){
481     qpremean += qm;
482     RN++;
483     };
484 mocchiut 1.1 l++;
485 mocchiut 1.4 if ( debug ) printf(" value no %i qm %f qmt %f \n",l,qm,qmt);
486 mocchiut 1.2 };
487     ind++;
488     };
489     //
490 mocchiut 1.5 qpremean /= (Float_t)RN;
491 mocchiut 1.4 //
492 mocchiut 1.2 ind = 0;
493     l = 0;
494 mocchiut 1.5 RN = 0;
495 mocchiut 1.2 while ( l < uplim && ind < interplane ){
496     qm2 = TMath::KOrdStat(interplane,qme2,ind,work);
497     if ( qm2 >= qmt ){
498 mocchiut 1.5 if ( l < N ){
499     qpremeanN += qm2;
500     RN++;
501     };
502 mocchiut 1.2 l++;
503 mocchiut 1.5 if ( debug ) printf(" qm2 value no %i qm %f qmt %f RN %i \n",l,qm2,qmt,RN);
504 mocchiut 1.1 };
505     ind++;
506     };
507     //
508 mocchiut 1.5 qpremeanN /= (Float_t)RN;
509 mocchiut 1.11 UN = RN;
510 mocchiut 1.1 //
511 mocchiut 1.4 if ( debug ) printf(" charge is %f \n",sqrt(qpremean));
512 mocchiut 1.1 //
513     if ( mesethr != ethr && interplane >= 3 && !aldone ){
514     Float_t mesethr2 = (sqrt(qpremean) - 0.50)*(sqrt(qpremean) - 0.50);
515     if ( mesethr2 < mesethr*0.90 ){
516     mesethr = (sqrt(dedx1) - 0.25)*(sqrt(dedx1) - 0.25);
517     } else {
518     mesethr = mesethr2;
519     };
520     aldone = true;
521 mocchiut 1.7 if ( mesethr > defethr ){
522     interplane = 0;
523     preq = 0.;
524     postq = 0.;
525     qpremean = 0.;
526     qpremeanN = 0.;
527     multhit = false;
528     gap = false;
529     goto retry;
530     };
531 mocchiut 1.1 };
532     };
533     //
534 mocchiut 1.5 if ( debug ) this->Print();
535 mocchiut 1.4 if ( debug ) printf(" esci \n");
536 mocchiut 1.1 //
537     };

  ViewVC Help
Powered by ViewVC 1.1.23