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

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

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

revision 1.2 by mocchiut, Fri Jul 20 09:13:38 2007 UTC revision 1.15 by mocchiut, Tue Sep 15 10:19:03 2009 UTC
# Line 12  Line 12 
12   */   */
13  CaloPreSampler::CaloPreSampler(){  CaloPreSampler::CaloPreSampler(){
14    Clear();    Clear();
15  };  }
16    
17  CaloPreSampler::CaloPreSampler(PamLevel2 *l2p){    CaloPreSampler::CaloPreSampler(PamLevel2 *l2p){  
18    //    //
# Line 30  CaloPreSampler::CaloPreSampler(PamLevel2 Line 30  CaloPreSampler::CaloPreSampler(PamLevel2
30    cstrip = new CaloStrip(false);    cstrip = new CaloStrip(false);
31    //  c1 = new CaloLevel1();    //  c1 = new CaloLevel1();
32    pcalo = new CaloLevel2();    pcalo = new CaloLevel2();
33    N = 3;    N = 4;
34      NC = 22-N;
35    debug = false;    debug = false;
36    sel = true;    sel = true;
37    cont = false;    cont = false;
38    emulate18 = true;    emulate18 = true;
39    simulation = false;    simulation = false;
40      withtrk = true;
41      rigdefault = 50.;
42      nox = false;
43      noy = false;
44      forcecalo = false;
45      forcefitmode = -1;
46      memset(mask,0,2*22*sizeof(Int_t));
47    //    //
48    Clear();    Clear();
49    //    //
# Line 62  CaloPreSampler::CaloPreSampler(PamLevel2 Line 70  CaloPreSampler::CaloPreSampler(PamLevel2
70    printf(" Reading magnetic field maps at %s\n",(q4->PATH+q4->NAME).Data());    printf(" Reading magnetic field maps at %s\n",(q4->PATH+q4->NAME).Data());
71    trk->LoadField(q4->PATH+q4->NAME);    trk->LoadField(q4->PATH+q4->NAME);
72    //    //
73  };  }
74    
75    CaloTrkVar* CaloPreSampler::GetCaloTrack(Int_t t){
76      this->Process();
77      if ( t < 0 ) return pcalo->GetCaloStoredTrack(t);
78      if ( L2->GetTrack(t) ){
79        return pcalo->GetCaloStoredTrack(L2->GetTrack(t)->GetTrkTrack()->GetSeqNo());
80      };
81      return NULL;
82    }
83    
84    void CaloPreSampler::SetNoWpreSampler(Int_t n){
85      if ( NC+n < 23 ){
86        N = n;
87      } else {
88        printf(" ERROR! Calorimeter is made of 22 W planes\n");
89        printf(" you are giving N presampler = %i and N calo = %i \n",n,NC);
90        printf(" WARNING: using default values NWpre = 4, NWcalo = 18\n");
91        NC = 18;
92        N = 4;
93      };
94    }
95    
96    void CaloPreSampler::SetNoWcalo(Int_t n){
97      if ( N+n < 23 ){
98        NC = n;
99      } else {
100        printf(" ERROR! Calorimeter is made of 22 W planes\n");
101        printf(" you are giving N W presampler = %i and N W calo = %i \n",N,n);
102        printf(" WARNING: using default values NWpre = 4, NWcalo = 18\n");
103        NC = 18;
104        N = 4;
105      };
106    }
107    
108    void CaloPreSampler::SplitInto(Int_t NoWpreSampler, Int_t NoWcalo){
109      this->SetNoWcalo(0);
110      this->SetNoWpreSampler(0);
111      if ( NoWpreSampler < NoWcalo ){
112            this->SetNoWpreSampler(NoWpreSampler);
113            this->SetNoWcalo(NoWcalo);
114      } else {
115            this->SetNoWcalo(NoWcalo);
116            this->SetNoWpreSampler(NoWpreSampler);
117      };
118    }
119    
120  void CaloPreSampler::Clear(){  void CaloPreSampler::Clear(){
121    //    //
122    pcalo->Clear();    pcalo->Clear();
123    //    //
124  };  }
125    
126  void CaloPreSampler::Print(){  void CaloPreSampler::Print(){
127    //    //
# Line 90  void CaloPreSampler::Print(){ Line 143  void CaloPreSampler::Print(){
143    };    };
144    printf("========================================================================\n");    printf("========================================================================\n");
145    //    //
146  };  }
147    
148  void CaloPreSampler::Delete(){  void CaloPreSampler::Delete(){
149    Clear();    Clear();
150    delete pcalo;    delete pcalo;
151    //delete this;    //delete this;
152  };  }
153    
154    
155  void CaloPreSampler::Process(){  void CaloPreSampler::Process(){
# Line 107  void CaloPreSampler::Process(){ Line 160  void CaloPreSampler::Process(){
160      return;      return;
161    };    };
162    //    //
163      // Clear structures used to communicate with fortran
164      //
165      event->ClearStructs();//ELENA
166      if ( forcefitmode > 0 ){
167        if ( forcefitmode != 1000 && forcefitmode != 1001 && forcefitmode != 1002 ){
168          printf(" ERROR! forcefitmode=%i \n Use forcefitmode = 1000 for fit mode 0, 1001 fit mode 1, 1002 fit mode 3\n",forcefitmode);
169          forcefitmode = -1;
170        } else {
171          event->clevel2->fmode[0] = forcefitmode;
172          event->clevel2->fmode[1] = forcefitmode;
173        };
174      };
175      //
176    Bool_t newentry = false;    Bool_t newentry = false;
177    //    //
178    if ( L2->IsORB() ){    if ( L2->IsORB() ){
179        if ( debug ) printf(" I am here, we have orbital infos \n");
180      if ( L2->GetOrbitalInfo()->pkt_num != PKT || L2->GetOrbitalInfo()->OBT != OBT || L2->GetOrbitalInfo()->absTime != atime || sel != ssel ){      if ( L2->GetOrbitalInfo()->pkt_num != PKT || L2->GetOrbitalInfo()->OBT != OBT || L2->GetOrbitalInfo()->absTime != atime || sel != ssel ){
181        newentry = true;        newentry = true;
182        OBT = L2->GetOrbitalInfo()->OBT;        OBT = L2->GetOrbitalInfo()->OBT;
# Line 131  void CaloPreSampler::Process(){ Line 198  void CaloPreSampler::Process(){
198    Int_t S11 = 0;    Int_t S11 = 0;
199    Float_t tmptrigty = -1.;    Float_t tmptrigty = -1.;
200    Bool_t trackanyway = true;    Bool_t trackanyway = true;
201    Float_t rigdefault = 50.;    //  Float_t rigdefault = 50.;
202    Bool_t hZn = true;    Bool_t hZn = true;
203    Bool_t withtrk = true;    //  Bool_t withtrk = true;
204    Bool_t st = true;    Bool_t st = true;
205    Int_t ntrkentry = 0;    Int_t ntrkentry = 0;
206    TrkLevel2 *trk = L2->GetTrkLevel2();    TrkLevel2 *trk = L2->GetTrkLevel2();
# Line 153  void CaloPreSampler::Process(){ Line 220  void CaloPreSampler::Process(){
220      if ( L2->GetCaloLevel2()->GetCaloTrkVar(mm)->trkseqno == -2 ) m2 = true;      if ( L2->GetCaloLevel2()->GetCaloTrkVar(mm)->trkseqno == -2 ) m2 = true;
221      if ( L2->GetCaloLevel2()->GetCaloTrkVar(mm)->trkseqno == -3 ) m3 = true;      if ( L2->GetCaloLevel2()->GetCaloTrkVar(mm)->trkseqno == -3 ) m3 = true;
222    };    };
223      if ( !withtrk ) m3 = true;
224    //    //
225    if ( debug ) printf(" Fill estrip matrix needed to calculate variables \n");    if ( debug ) printf(" Fill estrip matrix needed to calculate variables \n");
226    //    //
# Line 167  void CaloPreSampler::Process(){ Line 235  void CaloPreSampler::Process(){
235      //      //
236      mip = L2->GetCaloLevel1()->DecodeEstrip(i,view,plane,strip);      mip = L2->GetCaloLevel1()->DecodeEstrip(i,view,plane,strip);
237      //      //
238        // Mask x or y view if nox and/or noy are true (default false)
239        //
240        if ( mask[view][plane] ) mip = 0.;
241        if ( nox && view == 0 ) mip = 0.;
242        if ( noy && view == 1 ) mip = 0.;
243        //
244        if ( emulate18 && view == 0 && plane == 18 ) mip = 0.;
245        //
246      // Selection mode: fill the matrix only for plane < (22 - N) REMEMBER N = number of W planes to be used as presampler, ie if N = 2 then we want to use planes from 0 to 19      // Selection mode: fill the matrix only for plane < (22 - N) REMEMBER N = number of W planes to be used as presampler, ie if N = 2 then we want to use planes from 0 to 19
247      //                 included so plane < (22 - 2)      //                 included so plane < (22 - 2)
248      //      //
249      if ( sel ){      if ( sel ){
250        if ( plane < (22 - N) ){        if ( plane < (22 - N) ){
251          //          //
252          if ( emulate18 && plane == (18 - N) ) mip = 0.;          if ( emulate18 && plane == (18 - N) && view == 0 ) mip = 0.;
253            if ( plane >= NC ) mip = 0.;
254          event->clevel1->estrip[strip][plane][view] = mip;          event->clevel1->estrip[strip][plane][view] = mip;
255          //          //
256        };        };
# Line 184  void CaloPreSampler::Process(){ Line 261  void CaloPreSampler::Process(){
261      if ( cont ){      if ( cont ){
262        if ( plane >= N ){        if ( plane >= N ){
263          //          //
264          if ( emulate18 && plane == (18 + N) ) mip = 0.;          if ( emulate18 && plane == (18 + N) && view == 0 ) mip = 0.;
265            if ( (plane-N) >= NC ) mip = 0.;
266          event->clevel1->estrip[strip][(plane-N)][view] = mip;          event->clevel1->estrip[strip][(plane-N)][view] = mip;
267          //          //
268        };        };
# Line 228  void CaloPreSampler::Process(){ Line 306  void CaloPreSampler::Process(){
306    //    //
307    // use only N W planes    // use only N W planes
308    //    //
309    event->clevel1->npla = 22-N;    //  event->clevel1->npla = 22-N;
310      event->clevel1->npla = NC;
311    //    //
312    S3 = 0;    S3 = 0;
313    S2 = 0;    S2 = 0;
# Line 248  void CaloPreSampler::Process(){ Line 327  void CaloPreSampler::Process(){
327    //    //
328    event->clevel1->good2 = 1;    event->clevel1->good2 = 1;
329    //    //
330      // copy variables calculated during calibration process which is skipped here...
331      //
332      event->clevel2->good = L2->GetCaloLevel2()->good;
333      memcpy(event->clevel2->perr,L2->GetCaloLevel2()->perr,sizeof(L2->GetCaloLevel2()->perr));
334      memcpy(event->clevel2->swerr,L2->GetCaloLevel2()->swerr,sizeof(L2->GetCaloLevel2()->swerr));
335      memcpy(event->clevel2->crc,L2->GetCaloLevel2()->crc,sizeof(L2->GetCaloLevel2()->crc));
336      event->clevel2->selftrigger = L2->GetCaloLevel2()->selftrigger;
337      //
338    // Calculate variables common to all tracks (qtot, nstrip, etc.)    // Calculate variables common to all tracks (qtot, nstrip, etc.)
339    //    //
340    if ( debug ) printf("1 Call GetCommonVar() \n");    if ( debug ) printf("1 Call GetCommonVar() \n");
# Line 311  void CaloPreSampler::Process(){ Line 398  void CaloPreSampler::Process(){
398    // conditions are: 0) no track from the tracker 1) we have a track fit both in x and y 2) no problems with calo for this event 3) no selftrigger event    // conditions are: 0) no track from the tracker 1) we have a track fit both in x and y 2) no problems with calo for this event 3) no selftrigger event
399    //    //
400    //  if ( trackanyway && !filled && event->clevel2->npcfit[0] >= 2 && event->clevel2->npcfit[1] >= 2 && event->clevel2->good != 0 && event->clevel2->trigty < 2. ){    //  if ( trackanyway && !filled && event->clevel2->npcfit[0] >= 2 && event->clevel2->npcfit[1] >= 2 && event->clevel2->good != 0 && event->clevel2->trigty < 2. ){
401    if ( trackanyway && m3 ){    if ( (trackanyway && m3) || forcecalo ){
402      if ( debug ) printf(" Event with a track not fitted by the tracker \n");      if ( debug ) printf(" Event with a track not fitted by the tracker \n");
403      //      //
404      // Disable "track mode" in the fortran routine      // Disable "track mode" in the fortran routine
# Line 443  void CaloPreSampler::Process(){ Line 530  void CaloPreSampler::Process(){
530        if ( debug ) printf(" Selftrigger: problems with event \n");        if ( debug ) printf(" Selftrigger: problems with event \n");
531      };      };
532    };    };
533    //  //   //
534    // Clear structures used to communicate with fortran  //   // Clear structures used to communicate with fortran
535    //  //   //
536    event->ClearStructs();  //   event->ClearStructs();
537    // ELENA: moved @ beginning
538    //    //
539    //    //
540    //    //
541    if ( debug ) this->Print();    if ( debug ) this->Print();
542    if ( debug ) printf(" exit \n");    if ( debug ) printf(" exit \n");
543    //    //
544  };  }
545    
546    //
547    // Method to add a calorimeter track, evaluated around a tracker track defined by a status vector.
548    // (can be used to evaluate the calorimeter track around an arbitrary axis, by setting the status vector with zero deflection )
549    //
550    //
551    CaloTrkVar* CaloPreSampler::AddCaloTrkVar(float *al,int trktag){
552    
553        int ntrkentry = pcalo->ntrk();
554        //
555        for (Int_t nt=0; nt < ntrkentry; nt++){  
556            if( pcalo->GetCaloTrkVar(nt)->trkseqno == trktag){
557                cout << " CaloTrkVar* CaloPreSampler::AddCaloTrkVar(float *al,int trktag)"<<endl;
558                cout << " --> trktag = "<<trktag<<" already defined "<<endl;
559                return NULL;
560            }
561        }
562        //
563        event->clevel1->good2 = 1; //is a trk track
564        event->clevel1->trkchi2 = 0;
565        event->clevel1->hzn = 0;
566        //
567        // Copy the alpha vector in the input structure
568        //
569        for (Int_t e = 0; e < 5 ; e++){
570            event->clevel1->al_p[e][0] = al[e];
571        };    
572        //
573        // Get tracker related variables for this track
574        //
575        if ( debug ) printf("track %i Call GetTrkVar() \n",trktag);
576        event->GetTrkVar();
577        if ( debug ) printf(" event->clevel2->dX0l %f \n",event->clevel2->dX0l);
578        //
579        // Save tracker track sequence number
580        //  
581        event->trkseqno = trktag;
582        //
583        // Copy values in the class ca from the structure clevel2
584        //
585        if ( debug ) printf("track %i Call FillTrkVar() \n",trktag);
586        event->FillTrkVar(pcalo,ntrkentry);
587    
588        return pcalo->GetCaloTrkVar(ntrkentry);
589        
590    
591    };//ELENA

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.15

  ViewVC Help
Powered by ViewVC 1.1.23