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

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

  ViewVC Help
Powered by ViewVC 1.1.23