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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by mocchiut, Thu Apr 5 13:38:32 2007 UTC revision 1.8 by mocchiut, Fri Sep 28 10:05:00 2007 UTC
# Line 23  CaloNuclei::CaloNuclei(PamLevel2 *l2p){ Line 23  CaloNuclei::CaloNuclei(PamLevel2 *l2p){
23    R = 3;    R = 3;
24    //    //
25    debug = false;    debug = false;
26      usetrack = true;
27    //    //
28  };  };
29    
30  void CaloNuclei::Clear(){  void CaloNuclei::Clear(){
31    //    //
32    tr = 0;    tr = 0;
33      sntr = 0;
34    interplane = 0;    interplane = 0;
35    preq = 0.;    preq = 0.;
36    postq = 0.;    postq = 0.;
# Line 47  void CaloNuclei::Print(){ Line 49  void CaloNuclei::Print(){
49    Process();    Process();
50    //    //
51    printf("========================================================================\n");    printf("========================================================================\n");
52    printf(" OBT: %u PKT: %u ATIME: %u Track %i \n",OBT,PKT,atime,tr);    printf(" OBT: %u PKT: %u ATIME: %u Track %i Use track %i \n",OBT,PKT,atime,tr,usetrack);
53    printf(" interplane [number of available dE/dx before interaction]: %i\n",interplane);    printf(" interplane [number of available dE/dx before interaction]:.. %i\n",interplane);
54    printf(" ethr [threshold used to determine interplane]:............ %f \n",ethr);    printf(" ethr [threshold used to determine interplane]:.............. %f \n",ethr);
55    printf(" dedx1 [dE/dx from the first calorimeter plane]:........... %f \n",dedx1);    printf(" dedx1 [dE/dx from the first calorimeter plane]:............. %f \n",dedx1);
56    printf(" dedx3 [dE/dx (average) if the first 3 Si planes]:......... %f \n",dedx3);    printf(" stdedx1 [dE/dx from the first calorimeter plane standalone]: %f \n",stdedx1);
57    printf(" multhit [true if interplane determined by multiple hits]:. %i \n",multhit);    printf(" dedx3 [dE/dx (average) if the first 3 Si planes]:........... %f \n",dedx3);
58    printf(" gap [true if interplane determined by a gap]:............. %i \n",gap);    printf(" multhit [true if interplane determined by multiple hits]:... %i \n",multhit);
59    printf(" preq [total energy in MIP before the interaction plane]:.. %f \n",preq);    printf(" gap [true if interplane determined by a gap]:............... %i \n",gap);
60    printf(" postq [total energy in MIP after the interaction plane]:.. %f \n",postq);    printf(" preq [total energy in MIP before the interaction plane]:.... %f \n",preq);
61    printf(" qpremean [truncated mean using 3 planes and 3 strips]:.... %f \n",qpremean);    printf(" postq [total energy in MIP after the interaction plane]:.... %f \n",postq);
62    printf(" N [no of used plane]:..................................... %i \n",N);    printf(" qpremean [truncated mean using 3 planes and 3 strips]:...... %f \n",qpremean);
63    printf(" R [no strip used per plane ]:............................. %i \n",R);    printf(" N [no of used plane]:....................................... %i \n",N);
64    printf(" qpremeanN [truncated mean using N planes and R strips]:... %f \n",qpremeanN);    printf(" R [no strip used per plane ]:............................... %i \n",R);
65      printf(" qpremeanN [truncated mean using N planes and R strips]:..... %f \n",qpremeanN);
66    printf("========================================================================\n");    printf("========================================================================\n");
67    //    //
68  };  };
# Line 85  void CaloNuclei::Process(Int_t ntr){ Line 88  void CaloNuclei::Process(Int_t ntr){
88    Bool_t newentry = false;    Bool_t newentry = false;
89    //    //
90    if ( L2->IsORB() ){    if ( L2->IsORB() ){
91      if ( L2->GetOrbitalInfo()->pkt_num != PKT || L2->GetOrbitalInfo()->OBT != OBT || L2->GetOrbitalInfo()->absTime != atime ){      if ( L2->GetOrbitalInfo()->pkt_num != PKT || L2->GetOrbitalInfo()->OBT != OBT || L2->GetOrbitalInfo()->absTime != atime || ntr != sntr ){
92        newentry = true;        newentry = true;
93        OBT = L2->GetOrbitalInfo()->OBT;        OBT = L2->GetOrbitalInfo()->OBT;
94        PKT = L2->GetOrbitalInfo()->pkt_num;        PKT = L2->GetOrbitalInfo()->pkt_num;
95        atime = L2->GetOrbitalInfo()->absTime;        atime = L2->GetOrbitalInfo()->absTime;
96          sntr = ntr;
97      };      };
98    } else {    } else {
99      newentry = true;      newentry = true;
# Line 102  void CaloNuclei::Process(Int_t ntr){ Line 106  void CaloNuclei::Process(Int_t ntr){
106    if ( debug ) printf(" Processing event at OBT %u PKT %u time %u \n",OBT,PKT,atime);    if ( debug ) printf(" Processing event at OBT %u PKT %u time %u \n",OBT,PKT,atime);
107    //    //
108    Clear();    Clear();
109      if ( debug ) printf(" Always calculate stdedx1 \n");
110    //    //
111    PamTrack *track = 0;    // Always calculate stdedx1
   track = L2->GetTrack(ntr);  
112    //    //
113    Int_t view = 0;    Int_t view = 0;
114    Int_t plane = 0;    Int_t plane = 0;
115    Int_t strip = 0;    Int_t strip = 0;
116      Int_t indx = 0;
117      Float_t vfpl[96];
118      Int_t stfpl[96];
119      memset(vfpl, 0, 96*sizeof(Float_t));
120      memset(stfpl, 0, 96*sizeof(Int_t));
121    Float_t mip = 0.;    Float_t mip = 0.;
122      for ( Int_t i=0; i<L2->GetCaloLevel1()->istrip; i++ ){
123        //
124        mip = L2->GetCaloLevel1()->DecodeEstrip(i,view,plane,strip);
125        //
126        // put in vfpl vector the energy release on the first plane
127        //
128        if ( strip != -1 && view == 1 && plane == 0 ) {
129          stfpl[indx] = strip;
130          vfpl[indx] = mip;
131          indx++;
132        };
133        //
134      };
135      //
136      if ( debug ) printf(" find energy released along the strip of maximum on the first plane and on the two neighbour strips \n");
137      //
138      // find energy released along the strip of maximum on the first plane and on the two neighbour strips
139      //
140      if ( indx > 0 ){
141        Int_t mindx = (Int_t)TMath::LocMax(indx,stfpl);
142        for (Int_t ii=0; ii<indx; ii++){
143          if ( stfpl[ii] == stfpl[mindx] ) stdedx1 += vfpl[ii];
144          if ( (mindx-1)>=0 && stfpl[ii] == stfpl[mindx-1] ) stdedx1 += vfpl[ii];
145          if ( (mindx+1)<96 && stfpl[ii] == stfpl[mindx+1] ) stdedx1 += vfpl[ii];
146        };
147      } else {
148        stdedx1 = 0.;
149      };
150      //
151      if ( debug ) printf(" if ( !usetrack ) return: usetrack %i ntr %i \n",usetrack,ntr);
152      //
153      //
154      //  if ( !usetrack ) return;
155      //
156      PamTrack *ptrack = 0;
157      CaloTrkVar *track = 0;
158      //
159      if ( usetrack ){
160        if ( ntr >= 0 ){
161          ptrack = L2->GetTrack(ntr);
162          if ( ptrack ) track = ptrack->GetCaloTrack();
163        } else {
164          track = L2->GetCaloStoredTrack(ntr);
165        };
166        //
167        if ( !track && ntr >= 0 ){
168          printf(" ERROR: cannot find any track!\n");
169          printf(" ERROR: CaloNuclei variables not completely filled \n");
170          return;  
171        };
172      } else {
173        if ( ntr >= 0 ){
174          printf(" ERROR: you asked not to use a track but you are looking for track number %i !\n",ntr);
175          printf(" ERROR: CaloNuclei variables not completely filled \n");
176          return;      
177        };
178      };
179      //
180    //  Float_t defethr = 6. * 0.90;    //  Float_t defethr = 6. * 0.90;
181    Float_t defethr = 6.25; // = (sqrt(9) - 0.5) ** 2.;    Float_t defethr = 6.25; // = (sqrt(9) - 0.5) ** 2.;
182    //    //
# Line 119  void CaloNuclei::Process(Int_t ntr){ Line 186  void CaloNuclei::Process(Int_t ntr){
186      //      //
187      mip = L2->GetCaloLevel1()->DecodeEstrip(i,view,plane,strip);      mip = L2->GetCaloLevel1()->DecodeEstrip(i,view,plane,strip);
188      //      //
189      if ( strip != -1 &&      if ( ntr >= 0 ){
190           view == 1   &&        //
191           plane == 0  &&        if ( strip != -1 &&
192           ( strip == (track->GetCaloTrack()->tibar[0][1]-1) || strip == (track->GetCaloTrack()->tibar[0][1]-2) || strip == (track->GetCaloTrack()->tibar[0][1]) )             view == 1   &&
193           && true ){                   plane == 0  &&
194        dedx1 += mip;             ( strip == (track->tibar[0][1]-1) || strip == (track->tibar[0][1]-2) || strip == (track->tibar[0][1]) )
195      };             && true ){      
196      if ( strip != -1 &&          dedx1 += mip;
197           (( view == 1 && ( plane == 0 || plane == 1 ) ) ||        };
198           ( view == 0 && plane == 0 )) &&        if ( strip != -1 &&
199           (( view == 0 && ( strip == track->GetCaloTrack()->tibar[0][0] || strip == (track->GetCaloTrack()->tibar[0][0]-1) || strip == (track->GetCaloTrack()->tibar[0][0]-2) )) ||             (( view == 1 && ( plane == 0 || plane == 1 ) ) ||
200            ( view == 1 && ( strip == track->GetCaloTrack()->tibar[0][1] || strip == (track->GetCaloTrack()->tibar[0][1]-1) || strip == (track->GetCaloTrack()->tibar[0][1]-2) )) ||              ( view == 0 && plane == 0 )) &&
201            ( view == 1 && ( strip == track->GetCaloTrack()->tibar[1][1] || strip == (track->GetCaloTrack()->tibar[1][1]-1) || strip == (track->GetCaloTrack()->tibar[1][1]-2) ))) &&             (( view == 0 && ( strip == track->tibar[0][0] || strip == (track->tibar[0][0]-1) || strip == (track->tibar[0][0]-2) )) ||
202           true ){              ( view == 1 && ( strip == track->tibar[0][1] || strip == (track->tibar[0][1]-1) || strip == (track->tibar[0][1]-2) )) ||
203        dedx3 += mip;              ( view == 1 && ( strip == track->tibar[1][1] || strip == (track->tibar[1][1]-1) || strip == (track->tibar[1][1]-2) ))) &&
204               true ){
205            dedx3 += mip;
206          };
207        } else {
208          //
209          if ( strip != -1 &&
210               view == 1   &&
211               plane == 0  &&
212               ( strip == (L2->GetCaloLevel2()->cibar[0][1]-1) || strip == (L2->GetCaloLevel2()->cibar[0][1]-2) || strip == (L2->GetCaloLevel2()->cibar[0][1]) )
213               && true ){      
214            dedx1 += mip;
215          };
216          if ( strip != -1 &&
217               (( view == 1 && ( plane == 0 || plane == 1 ) ) ||
218                ( view == 0 && plane == 0 )) &&
219               (( view == 0 && ( strip == L2->GetCaloLevel2()->cibar[0][0] || strip == (L2->GetCaloLevel2()->cibar[0][0]-1) || strip == (L2->GetCaloLevel2()->cibar[0][0]-2) )) ||
220                ( view == 1 && ( strip == L2->GetCaloLevel2()->cibar[0][1] || strip == (L2->GetCaloLevel2()->cibar[0][1]-1) || strip == (L2->GetCaloLevel2()->cibar[0][1]-2) )) ||
221                ( view == 1 && ( strip == L2->GetCaloLevel2()->cibar[1][1] || strip == (L2->GetCaloLevel2()->cibar[1][1]-1) || strip == (L2->GetCaloLevel2()->cibar[1][1]-2) ))) &&
222               true ){
223            dedx3 += mip;
224          };
225      };      };
226      //          //    
227    };    };
# Line 167  void CaloNuclei::Process(Int_t ntr){ Line 255  void CaloNuclei::Process(Int_t ntr){
255      //      //
256      mip = L2->GetCaloLevel1()->DecodeEstrip(ii,view,plane,strip);          mip = L2->GetCaloLevel1()->DecodeEstrip(ii,view,plane,strip);    
257      //      //
258      if ( strip != -1 && mip > ethr && !wmulthit[view] && !wgap[view] &&      if ( ntr >= 0 ){
259           ( strip == (track->GetCaloTrack()->tibar[plane][view]-1) || strip == (track->GetCaloTrack()->tibar[plane][view]-2) || strip == (track->GetCaloTrack()->tibar[plane][view]) )        if ( strip != -1 && mip > ethr && !wmulthit[view] && !wgap[view] &&
260           && true ){                   ( strip == (track->tibar[plane][view]-1) || strip == (track->tibar[plane][view]-2) || strip == (track->tibar[plane][view]) )
261        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->GetCaloTrack()->tibar[plane][view]-1,nhit[view],splane[view],sview[view]);             && true ){      
262        interpl[view] = plane;          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]);
263        interv[view] = view;          interpl[view] = plane;
264        if ( splane[view] != plane || sview[view] != view ){          interv[view] = view;
265          if ( nhit[view] > 1 ){          if ( splane[view] != plane || sview[view] != view ){
266            wmulthit[view] = true;            if ( nhit[view] > 1 ){
267            //      if ( splane[view] == -1 ) splane[view] = 0; //              wmulthit[view] = true;
268            //      if ( sview[view] == -1 ) sview[view] = view; //              //    if ( splane[view] == -1 ) splane[view] = 0; //
269            interpl[view] = splane[view];              //    if ( sview[view] == -1 ) sview[view] = view; //
270            interv[view] = sview[view];                  interpl[view] = splane[view];
271                interv[view] = sview[view];  
272          };          };
273          if ( plane > splane[view]+gapth ){            if ( plane > splane[view]+gapth ){
274            wgap[view] = true;              wgap[view] = true;
275            //      if ( splane[view] == -1 ) splane[view] = 0;//              //    if ( splane[view] == -1 ) splane[view] = 0;//
276            //      if ( sview[view] == -1 ) sview[view] = view; //              //    if ( sview[view] == -1 ) sview[view] = view; //
277            interpl[view] = splane[view];              interpl[view] = splane[view];
278            interv[view] = sview[view];              interv[view] = sview[view];
279              };
280              splane[view] = plane;
281              sview[view] = view;
282              nhit[view] = 1;
283            } else {
284              nhit[view]++;
285            };
286          };
287        } else {
288          if ( strip != -1 && mip > ethr && !wmulthit[view] && !wgap[view] &&
289               ( strip == (L2->GetCaloLevel2()->cibar[plane][view]-1) || strip == (L2->GetCaloLevel2()->cibar[plane][view]-2) || strip == (L2->GetCaloLevel2()->cibar[plane][view]) )
290               && true ){      
291            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]);
292            interpl[view] = plane;
293            interv[view] = view;
294            if ( splane[view] != plane || sview[view] != view ){
295              if ( nhit[view] > 1 ){
296                wmulthit[view] = true;
297                //    if ( splane[view] == -1 ) splane[view] = 0; //
298                //    if ( sview[view] == -1 ) sview[view] = view; //
299                interpl[view] = splane[view];
300                interv[view] = sview[view];  
301            };
302              if ( plane > splane[view]+gapth ){
303                wgap[view] = true;
304                //    if ( splane[view] == -1 ) splane[view] = 0;//
305                //    if ( sview[view] == -1 ) sview[view] = view; //
306                interpl[view] = splane[view];
307                interv[view] = sview[view];
308              };
309              splane[view] = plane;
310              sview[view] = view;
311              nhit[view] = 1;
312            } else {
313              nhit[view]++;
314          };          };
         splane[view] = plane;  
         sview[view] = view;  
         nhit[view] = 1;  
       } else {  
         nhit[view]++;  
315        };        };
316      };      };
317      //      //
# Line 273  void CaloNuclei::Process(Int_t ntr){ Line 392  void CaloNuclei::Process(Int_t ntr){
392            postq += mip;            postq += mip;
393          } else {          } else {
394            preq += mip;            preq += mip;
395            if (  strip == (track->GetCaloTrack()->tibar[plane][view]-1) || strip == (track->GetCaloTrack()->tibar[plane][view]-2) || strip == (track->GetCaloTrack()->tibar[plane][view]) ){            if ( ntr >= 0 ){
396              if ( qsplane != plane || qsview != view ){              if (  strip == (track->tibar[plane][view]-1) || strip == (track->tibar[plane][view]-2) || strip == (track->tibar[plane][view]) ){
397                qsplane = plane;                if ( qsplane != plane || qsview != view ){
398                qsview = view;                  qsplane = plane;
399                ind++;                  qsview = view;
400                if ( debug && ind > 199 ) printf(" AAAGH!! \n");                  ind++;
401                qme[ind] = 0.;                  if ( debug && ind > 199 ) printf(" AAAGH!! \n");
402                    qme[ind] = 0.;
403                  };
404                  qme[ind] += mip;
405              };              };
406              qme[ind] += mip;              for ( Int_t ns = 0; ns < R ; ns++){
407            };                Int_t ms =  track->tibar[plane][view] - 1 - ns + (R - 1)/2;
408            for ( Int_t ns = 0; ns < R ; ns++){                if ( strip == ms ){
409              Int_t ms =  track->GetCaloTrack()->tibar[plane][view] - 1 - ns + (R - 1)/2;                  if ( qsplane2 != plane || qsview2 != view ){
410              if ( strip == ms ){                    qsplane2 = plane;
411                if ( qsplane2 != plane || qsview2 != view ){                    qsview2 = view;
412                  qsplane2 = plane;                    ind2++;
413                  qsview2 = view;                    if ( debug && ind2 > 2112 ) printf(" AAAGH!! \n");
414                  ind2++;                    qme2[ind2] = 0.;
415                  if ( debug && ind2 > 2112 ) printf(" AAAGH!! \n");                  };
416                  qme2[ind2] = 0.;                  qme2[ind2] += mip;
417                };                };
418                qme2[ind2] += mip;              };  
419              } else {
420                if (  strip == (L2->GetCaloLevel2()->cibar[plane][view]-1) || strip == (L2->GetCaloLevel2()->cibar[plane][view]-2) || strip == (L2->GetCaloLevel2()->cibar[plane][view]) ){
421                  if ( qsplane != plane || qsview != view ){
422                    qsplane = plane;
423                    qsview = view;
424                    ind++;
425                    if ( debug && ind > 199 ) printf(" AAAGH!! \n");
426                    qme[ind] = 0.;
427                  };
428                  qme[ind] += mip;
429              };              };
430            };                  for ( Int_t ns = 0; ns < R ; ns++){
431                  Int_t ms =  L2->GetCaloLevel2()->cibar[plane][view] - 1 - ns + (R - 1)/2;
432                  if ( strip == ms ){
433                    if ( qsplane2 != plane || qsview2 != view ){
434                      qsplane2 = plane;
435                      qsview2 = view;
436                      ind2++;
437                      if ( debug && ind2 > 2112 ) printf(" AAAGH!! \n");
438                      qme2[ind2] = 0.;
439                    };
440                    qme2[ind2] += mip;
441                  };
442                };  
443              };
444          };                };      
445          //          //
446        };        };
# Line 315  void CaloNuclei::Process(Int_t ntr){ Line 460  void CaloNuclei::Process(Int_t ntr){
460      Long64_t work[200];      Long64_t work[200];
461      ind = 0;      ind = 0;
462      Int_t l = 0;      Int_t l = 0;
463        Int_t RN = 0;
464      Float_t qm = 0.;      Float_t qm = 0.;
465      Float_t qm2 = 0.;      Float_t qm2 = 0.;
466      //      //
# Line 325  void CaloNuclei::Process(Int_t ntr){ Line 471  void CaloNuclei::Process(Int_t ntr){
471      while ( l < uplim && ind < interplane ){      while ( l < uplim && ind < interplane ){
472        qm = TMath::KOrdStat(interplane,qme,ind,work);        qm = TMath::KOrdStat(interplane,qme,ind,work);
473        if ( qm >= qmt ){        if ( qm >= qmt ){
474          if ( l < 3 ) qpremean += qm;          if ( l < 3 ){
475              qpremean += qm;
476              RN++;
477            };
478          l++;          l++;
479          if ( debug ) printf(" value no %i qm %f qmt %f \n",l,qm,qmt);          if ( debug ) printf(" value no %i qm %f qmt %f \n",l,qm,qmt);
480        };        };
481        ind++;        ind++;
482      };      };
483      //      //
484      qpremean /= l;      qpremean /= (Float_t)RN;
485      //      //
486      ind = 0;      ind = 0;
487      l = 0;      l = 0;
488        RN = 0;
489      while ( l < uplim && ind < interplane ){      while ( l < uplim && ind < interplane ){
490        qm2 = TMath::KOrdStat(interplane,qme2,ind,work);        qm2 = TMath::KOrdStat(interplane,qme2,ind,work);
491        if ( qm2 >= qmt ){                if ( qm2 >= qmt ){        
492          if ( l < N ) qpremeanN += qm2;          if ( l < N ){
493              qpremeanN += qm2;
494              RN++;
495            };
496          l++;          l++;
497          if ( debug ) printf(" qm2 value no %i qm %f qmt %f \n",l,qm2,qmt);          if ( debug ) printf(" qm2 value no %i qm %f qmt %f RN %i \n",l,qm2,qmt,RN);
498        };        };
499        ind++;        ind++;
500      };      };
501      //      //
502      qpremeanN /= l;      qpremeanN /= (Float_t)RN;
503      //      //
504      if ( debug ) printf(" charge is %f \n",sqrt(qpremean));      if ( debug ) printf(" charge is %f \n",sqrt(qpremean));
505      //      //
# Line 358  void CaloNuclei::Process(Int_t ntr){ Line 511  void CaloNuclei::Process(Int_t ntr){
511          mesethr = mesethr2;          mesethr = mesethr2;
512        };        };
513        aldone = true;        aldone = true;
514        if ( mesethr > defethr ) goto retry;        if ( mesethr > defethr ){
515            interplane = 0;
516            preq = 0.;
517            postq = 0.;
518            qpremean = 0.;
519            qpremeanN = 0.;
520            multhit = false;
521            gap = false;
522            goto retry;
523          };
524      };      };
525    };    };
526    //    //
527      if ( debug ) this->Print();
528    if ( debug ) printf(" esci \n");    if ( debug ) printf(" esci \n");
529    //    //
530  };  };

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.8

  ViewVC Help
Powered by ViewVC 1.1.23