/[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.1 by mocchiut, Fri Jul 20 08:27:45 2007 UTC revision 1.18 by mocchiut, Thu Mar 18 19:50:10 2010 UTC
# Line 12  Line 12 
12   */   */
13  CaloPreSampler::CaloPreSampler(){  CaloPreSampler::CaloPreSampler(){
14    Clear();    Clear();
15  };  }
16    
17    void CaloPreSampler::SetCaloLevel2Pointer(CaloLevel2 *cl2p){
18      if ( pcalo ) delete pcalo;
19      pcalo = cl2p;
20    }
21    
22  CaloPreSampler::CaloPreSampler(PamLevel2 *l2p){    CaloPreSampler::CaloPreSampler(PamLevel2 *l2p){  
23    //    //
# Line 30  CaloPreSampler::CaloPreSampler(PamLevel2 Line 35  CaloPreSampler::CaloPreSampler(PamLevel2
35    cstrip = new CaloStrip(false);    cstrip = new CaloStrip(false);
36    //  c1 = new CaloLevel1();    //  c1 = new CaloLevel1();
37    pcalo = new CaloLevel2();    pcalo = new CaloLevel2();
38    N = 3;    N = 4;
39      NC = 22-N;
40    debug = false;    debug = false;
41    sel = true;    sel = true;
42    cont = false;    cont = false;
43    emulate18 = true;    emulate18 = true;
44      usepl18x = false;
45    simulation = false;    simulation = false;
46      withtrk = true;
47      rigdefault = 50.;
48      nox = false;
49      noy = false;
50      forcecalo = false;
51      forcefitmode = -1;
52      memset(mask,0,2*22*sizeof(Int_t));
53    //    //
54    Clear();    Clear();
55    //    //
# Line 62  CaloPreSampler::CaloPreSampler(PamLevel2 Line 76  CaloPreSampler::CaloPreSampler(PamLevel2
76    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());
77    trk->LoadField(q4->PATH+q4->NAME);    trk->LoadField(q4->PATH+q4->NAME);
78    //    //
79  };  }
80    
81    CaloTrkVar* CaloPreSampler::GetCaloTrack(Int_t t){
82      this->Process();
83      if ( t < 0 ) return pcalo->GetCaloStoredTrack(t);
84      if ( L2->GetTrack(t) ){
85        return pcalo->GetCaloStoredTrack(L2->GetTrack(t)->GetTrkTrack()->GetSeqNo());
86      };
87      return NULL;
88    }
89    
90    void CaloPreSampler::SetNoWpreSampler(Int_t n){
91      if ( NC+n < 23 ){
92        N = n;
93      } else {
94        printf(" ERROR! Calorimeter is made of 22 W planes\n");
95        printf(" you are giving N presampler = %i and N calo = %i \n",n,NC);
96        printf(" WARNING: using default values NWpre = 4, NWcalo = 18\n");
97        NC = 18;
98        N = 4;
99      };
100    }
101    
102    void CaloPreSampler::SetNoWcalo(Int_t n){
103      if ( N+n < 23 ){
104        NC = n;
105      } else {
106        printf(" ERROR! Calorimeter is made of 22 W planes\n");
107        printf(" you are giving N W presampler = %i and N W calo = %i \n",N,n);
108        printf(" WARNING: using default values NWpre = 4, NWcalo = 18\n");
109        NC = 18;
110        N = 4;
111      };
112    }
113    
114    void CaloPreSampler::SplitInto(Int_t NoWpreSampler, Int_t NoWcalo){
115      this->SetNoWcalo(0);
116      this->SetNoWpreSampler(0);
117      if ( NoWpreSampler < NoWcalo ){
118            this->SetNoWpreSampler(NoWpreSampler);
119            this->SetNoWcalo(NoWcalo);
120      } else {
121            this->SetNoWcalo(NoWcalo);
122            this->SetNoWpreSampler(NoWpreSampler);
123      };
124    }
125    
126  void CaloPreSampler::Clear(){  void CaloPreSampler::Clear(){
127    //    //
128    pcalo->Clear();    pcalo->Clear();
129    //    //
130  };  }
131    
132  void CaloPreSampler::Print(){  void CaloPreSampler::Print(){
133    //    //
# Line 84  void CaloPreSampler::Print(){ Line 143  void CaloPreSampler::Print(){
143    printf(" pre-sampler planes               :.. %i\n",N);    printf(" pre-sampler planes               :.. %i\n",N);
144    printf(" pcalo->qtot                      :.. %f\n",pcalo->qtot);    printf(" pcalo->qtot                      :.. %f\n",pcalo->qtot);
145    printf(" pcalo->nstrip                    :.. %i\n",pcalo->nstrip);      printf(" pcalo->nstrip                    :.. %i\n",pcalo->nstrip);  
146    printf(" pcalo->track0->qtrack            :.. %f\n",pcalo->GetCaloTrkVar(0)->qtrack);      if ( pcalo->ntrk() > 0 ){
147    printf(" pcalo->track0->dX0l              :.. %f\n",pcalo->GetCaloTrkVar(0)->dX0l);        printf(" pcalo->track0->qtrack            :.. %f\n",pcalo->GetCaloTrkVar(0)->qtrack);  
148        printf(" pcalo->track0->dX0l              :.. %f\n",pcalo->GetCaloTrkVar(0)->dX0l);  
149      };
150    printf("========================================================================\n");    printf("========================================================================\n");
151    //    //
152  };  }
153    
154  void CaloPreSampler::Delete(){  void CaloPreSampler::Delete(){
155    Clear();    Clear();
156    delete pcalo;    delete pcalo;
157    //delete this;    //delete this;
158  };  }
159    
160    
161  void CaloPreSampler::Process(){  void CaloPreSampler::Process(){
# Line 105  void CaloPreSampler::Process(){ Line 166  void CaloPreSampler::Process(){
166      return;      return;
167    };    };
168    //    //
169      // Clear structures used to communicate with fortran
170      //
171      event->ClearStructs();//ELENA
172      if ( forcefitmode > 0 ){
173        if ( forcefitmode != 1000 && forcefitmode != 1001 && forcefitmode != 1002 ){
174          printf(" ERROR! forcefitmode=%i \n Use forcefitmode = 1000 for fit mode 0, 1001 fit mode 1, 1002 fit mode 3\n",forcefitmode);
175          forcefitmode = -1;
176        } else {
177          event->clevel2->fmode[0] = forcefitmode;
178          event->clevel2->fmode[1] = forcefitmode;
179        };
180      };
181      //
182    Bool_t newentry = false;    Bool_t newentry = false;
183    //    //
184    if ( L2->IsORB() ){    if ( L2->IsORB() ){
185        if ( debug ) printf(" I am here, we have orbital infos \n");
186      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 ){
187        newentry = true;        newentry = true;
188        OBT = L2->GetOrbitalInfo()->OBT;        OBT = L2->GetOrbitalInfo()->OBT;
# Line 129  void CaloPreSampler::Process(){ Line 204  void CaloPreSampler::Process(){
204    Int_t S11 = 0;    Int_t S11 = 0;
205    Float_t tmptrigty = -1.;    Float_t tmptrigty = -1.;
206    Bool_t trackanyway = true;    Bool_t trackanyway = true;
207    Float_t rigdefault = 50.;    //  Float_t rigdefault = 50.;
208    Bool_t hZn = true;    Bool_t hZn = true;
209    Bool_t withtrk = true;    //  Bool_t withtrk = true;
210    Bool_t st = true;    Bool_t st = true;
211    Int_t ntrkentry = 0;    Int_t ntrkentry = 0;
212    TrkLevel2 *trk = L2->GetTrkLevel2();    TrkLevel2 *trk = L2->GetTrkLevel2();
# Line 139  void CaloPreSampler::Process(){ Line 214  void CaloPreSampler::Process(){
214    //    //
215    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);
216    //    //
   this->Clear();  
   //  
217    // find out if we have trkseqno = -1, -2 or -3    // find out if we have trkseqno = -1, -2 or -3
218    //    //
219    Bool_t m1 = false;    Bool_t m1 = false;
# Line 151  void CaloPreSampler::Process(){ Line 224  void CaloPreSampler::Process(){
224      if ( L2->GetCaloLevel2()->GetCaloTrkVar(mm)->trkseqno == -2 ) m2 = true;      if ( L2->GetCaloLevel2()->GetCaloTrkVar(mm)->trkseqno == -2 ) m2 = true;
225      if ( L2->GetCaloLevel2()->GetCaloTrkVar(mm)->trkseqno == -3 ) m3 = true;      if ( L2->GetCaloLevel2()->GetCaloTrkVar(mm)->trkseqno == -3 ) m3 = true;
226    };    };
227      if ( !withtrk ) m3 = true;
228      //
229      // copy variables calculated during calibration process which is skipped here... this has been moved before this->Clear() for reprocessing purpose
230      //
231      event->clevel2->good = L2->GetCaloLevel2()->good;
232      memcpy(event->clevel2->perr,L2->GetCaloLevel2()->perr,sizeof(L2->GetCaloLevel2()->perr));
233      memcpy(event->clevel2->swerr,L2->GetCaloLevel2()->swerr,sizeof(L2->GetCaloLevel2()->swerr));
234      memcpy(event->clevel2->crc,L2->GetCaloLevel2()->crc,sizeof(L2->GetCaloLevel2()->crc));
235      event->clevel2->selftrigger = L2->GetCaloLevel2()->selftrigger;
236      //
237      //
238      this->Clear(); // moved after all calls to L2->GetCaloLevel2() since pcalo could be the same as L2->GetCaloLevel2() !!!
239      //
240    //    //
241    if ( debug ) printf(" Fill estrip matrix needed to calculate variables \n");    if ( debug ) printf(" Fill estrip matrix needed to calculate variables \n");
242    //    //
# Line 165  void CaloPreSampler::Process(){ Line 251  void CaloPreSampler::Process(){
251      //      //
252      mip = L2->GetCaloLevel1()->DecodeEstrip(i,view,plane,strip);      mip = L2->GetCaloLevel1()->DecodeEstrip(i,view,plane,strip);
253      //      //
254        if ( !usepl18x && view==0 && plane==18 ) mip = 0.;
255        //
256        // Mask x or y view if nox and/or noy are true (default false)
257        //
258        if ( mask[view][plane] ) mip = 0.;
259        if ( nox && view == 0 ) mip = 0.;
260        if ( noy && view == 1 ) mip = 0.;
261        //
262        if ( emulate18 && view == 0 && plane == 18 ) mip = 0.;
263        //
264      // 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
265      //                 included so plane < (22 - 2)      //                 included so plane < (22 - 2)
266      //      //
267      if ( sel ){      if ( sel ){
268        if ( plane < (22 - N) ){        if ( plane < (22 - N) ){
269          //          //
270          if ( emulate18 && plane == (18 - N) ) mip = 0.;          if ( emulate18 && plane == (18 - N) && view == 0 ) mip = 0.;
271            if ( plane >= NC ) mip = 0.;
272          event->clevel1->estrip[strip][plane][view] = mip;          event->clevel1->estrip[strip][plane][view] = mip;
273          //          //
274        };        };
# Line 182  void CaloPreSampler::Process(){ Line 279  void CaloPreSampler::Process(){
279      if ( cont ){      if ( cont ){
280        if ( plane >= N ){        if ( plane >= N ){
281          //          //
282          if ( emulate18 && plane == (18 + N) ) mip = 0.;          if ( emulate18 && plane == (18 + N) && view == 0 ) mip = 0.;
283            if ( (plane-N) >= NC ) mip = 0.;
284          event->clevel1->estrip[strip][(plane-N)][view] = mip;          event->clevel1->estrip[strip][(plane-N)][view] = mip;
285          //          //
286        };        };
# Line 226  void CaloPreSampler::Process(){ Line 324  void CaloPreSampler::Process(){
324    //    //
325    // use only N W planes    // use only N W planes
326    //    //
327    event->clevel1->npla = 22-N;    //  event->clevel1->npla = 22-N;
328      event->clevel1->npla = NC;
329    //    //
330    S3 = 0;    S3 = 0;
331    S2 = 0;    S2 = 0;
# Line 246  void CaloPreSampler::Process(){ Line 345  void CaloPreSampler::Process(){
345    //    //
346    event->clevel1->good2 = 1;    event->clevel1->good2 = 1;
347    //    //
348      // copy variables calculated during calibration process which is skipped here... this has to be moved before this->Clear() for reprocessing purpose
349      //
350    //  event->clevel2->good = L2->GetCaloLevel2()->good;
351    //  memcpy(event->clevel2->perr,L2->GetCaloLevel2()->perr,sizeof(L2->GetCaloLevel2()->perr));
352    //  memcpy(event->clevel2->swerr,L2->GetCaloLevel2()->swerr,sizeof(L2->GetCaloLevel2()->swerr));
353    //  memcpy(event->clevel2->crc,L2->GetCaloLevel2()->crc,sizeof(L2->GetCaloLevel2()->crc));
354    //  event->clevel2->selftrigger = L2->GetCaloLevel2()->selftrigger;
355      //
356    // Calculate variables common to all tracks (qtot, nstrip, etc.)    // Calculate variables common to all tracks (qtot, nstrip, etc.)
357    //    //
358    if ( debug ) printf("1 Call GetCommonVar() \n");    if ( debug ) printf("1 Call GetCommonVar() \n");
# Line 309  void CaloPreSampler::Process(){ Line 416  void CaloPreSampler::Process(){
416    // 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
417    //    //
418    //  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. ){
419    if ( trackanyway && m3 ){    if ( (trackanyway && m3) || forcecalo ){
420      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");
421      //      //
422      // Disable "track mode" in the fortran routine      // Disable "track mode" in the fortran routine
# Line 441  void CaloPreSampler::Process(){ Line 548  void CaloPreSampler::Process(){
548        if ( debug ) printf(" Selftrigger: problems with event \n");        if ( debug ) printf(" Selftrigger: problems with event \n");
549      };      };
550    };    };
551    //  //   //
552    // Clear structures used to communicate with fortran  //   // Clear structures used to communicate with fortran
553    //  //   //
554    event->ClearStructs();  //   event->ClearStructs();
555    // ELENA: moved @ beginning
556    //    //
557    //    //
558    //    //
559    if ( debug ) this->Print();    if ( debug ) this->Print();
560    if ( debug ) printf(" exit \n");    if ( debug ) printf(" exit \n");
561    //    //
562  };  }
563    
564    //
565    // Method to add a calorimeter track, evaluated around a tracker track defined by a status vector.
566    // (can be used to evaluate the calorimeter track around an arbitrary axis, by setting the status vector with zero deflection )
567    //
568    //
569    CaloTrkVar* CaloPreSampler::AddCaloTrkVar(float *al,int trktag){
570    
571        int ntrkentry = pcalo->ntrk();
572        //
573        for (Int_t nt=0; nt < ntrkentry; nt++){  
574            if( pcalo->GetCaloTrkVar(nt)->trkseqno == trktag){
575                cout << " CaloTrkVar* CaloPreSampler::AddCaloTrkVar(float *al,int trktag)"<<endl;
576                cout << " --> trktag = "<<trktag<<" already defined "<<endl;
577                return NULL;
578            }
579        }
580        //
581        event->clevel1->good2 = 1; //is a trk track
582        event->clevel1->trkchi2 = 0;
583        event->clevel1->hzn = 0;
584        //
585        // Copy the alpha vector in the input structure
586        //
587        for (Int_t e = 0; e < 5 ; e++){
588            event->clevel1->al_p[e][0] = al[e];
589        };    
590        //
591        // Get tracker related variables for this track
592        //
593        if ( debug ) printf("track %i Call GetTrkVar() \n",trktag);
594        event->GetTrkVar();
595        if ( debug ) printf(" event->clevel2->dX0l %f \n",event->clevel2->dX0l);
596        //
597        // Save tracker track sequence number
598        //  
599        event->trkseqno = trktag;
600        //
601        // Copy values in the class ca from the structure clevel2
602        //
603        if ( debug ) printf("track %i Call FillTrkVar() \n",trktag);
604        event->FillTrkVar(pcalo,ntrkentry);
605    
606        return pcalo->GetCaloTrkVar(ntrkentry);
607        
608    
609    };//ELENA

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.18

  ViewVC Help
Powered by ViewVC 1.1.23