/[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.17 by mocchiut, Wed Mar 10 12:11:11 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 90  void CaloPreSampler::Print(){ Line 149  void CaloPreSampler::Print(){
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 107  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 131  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 153  void CaloPreSampler::Process(){ Line 226  void CaloPreSampler::Process(){
226      if ( L2->GetCaloLevel2()->GetCaloTrkVar(mm)->trkseqno == -2 ) m2 = true;      if ( L2->GetCaloLevel2()->GetCaloTrkVar(mm)->trkseqno == -2 ) m2 = true;
227      if ( L2->GetCaloLevel2()->GetCaloTrkVar(mm)->trkseqno == -3 ) m3 = true;      if ( L2->GetCaloLevel2()->GetCaloTrkVar(mm)->trkseqno == -3 ) m3 = true;
228    };    };
229      if ( !withtrk ) m3 = true;
230    //    //
231    if ( debug ) printf(" Fill estrip matrix needed to calculate variables \n");    if ( debug ) printf(" Fill estrip matrix needed to calculate variables \n");
232    //    //
# Line 167  void CaloPreSampler::Process(){ Line 241  void CaloPreSampler::Process(){
241      //      //
242      mip = L2->GetCaloLevel1()->DecodeEstrip(i,view,plane,strip);      mip = L2->GetCaloLevel1()->DecodeEstrip(i,view,plane,strip);
243      //      //
244        if ( !usepl18x && view==0 && plane==18 ) mip = 0.;
245        //
246        // Mask x or y view if nox and/or noy are true (default false)
247        //
248        if ( mask[view][plane] ) mip = 0.;
249        if ( nox && view == 0 ) mip = 0.;
250        if ( noy && view == 1 ) mip = 0.;
251        //
252        if ( emulate18 && view == 0 && plane == 18 ) mip = 0.;
253        //
254      // 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
255      //                 included so plane < (22 - 2)      //                 included so plane < (22 - 2)
256      //      //
257      if ( sel ){      if ( sel ){
258        if ( plane < (22 - N) ){        if ( plane < (22 - N) ){
259          //          //
260          if ( emulate18 && plane == (18 - N) ) mip = 0.;          if ( emulate18 && plane == (18 - N) && view == 0 ) mip = 0.;
261            if ( plane >= NC ) mip = 0.;
262          event->clevel1->estrip[strip][plane][view] = mip;          event->clevel1->estrip[strip][plane][view] = mip;
263          //          //
264        };        };
# Line 184  void CaloPreSampler::Process(){ Line 269  void CaloPreSampler::Process(){
269      if ( cont ){      if ( cont ){
270        if ( plane >= N ){        if ( plane >= N ){
271          //          //
272          if ( emulate18 && plane == (18 + N) ) mip = 0.;          if ( emulate18 && plane == (18 + N) && view == 0 ) mip = 0.;
273            if ( (plane-N) >= NC ) mip = 0.;
274          event->clevel1->estrip[strip][(plane-N)][view] = mip;          event->clevel1->estrip[strip][(plane-N)][view] = mip;
275          //          //
276        };        };
# Line 228  void CaloPreSampler::Process(){ Line 314  void CaloPreSampler::Process(){
314    //    //
315    // use only N W planes    // use only N W planes
316    //    //
317    event->clevel1->npla = 22-N;    //  event->clevel1->npla = 22-N;
318      event->clevel1->npla = NC;
319    //    //
320    S3 = 0;    S3 = 0;
321    S2 = 0;    S2 = 0;
# Line 248  void CaloPreSampler::Process(){ Line 335  void CaloPreSampler::Process(){
335    //    //
336    event->clevel1->good2 = 1;    event->clevel1->good2 = 1;
337    //    //
338      // copy variables calculated during calibration process which is skipped here...
339      //
340      event->clevel2->good = L2->GetCaloLevel2()->good;
341      memcpy(event->clevel2->perr,L2->GetCaloLevel2()->perr,sizeof(L2->GetCaloLevel2()->perr));
342      memcpy(event->clevel2->swerr,L2->GetCaloLevel2()->swerr,sizeof(L2->GetCaloLevel2()->swerr));
343      memcpy(event->clevel2->crc,L2->GetCaloLevel2()->crc,sizeof(L2->GetCaloLevel2()->crc));
344      event->clevel2->selftrigger = L2->GetCaloLevel2()->selftrigger;
345      //
346    // Calculate variables common to all tracks (qtot, nstrip, etc.)    // Calculate variables common to all tracks (qtot, nstrip, etc.)
347    //    //
348    if ( debug ) printf("1 Call GetCommonVar() \n");    if ( debug ) printf("1 Call GetCommonVar() \n");
# Line 311  void CaloPreSampler::Process(){ Line 406  void CaloPreSampler::Process(){
406    // 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
407    //    //
408    //  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. ){
409    if ( trackanyway && m3 ){    if ( (trackanyway && m3) || forcecalo ){
410      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");
411      //      //
412      // Disable "track mode" in the fortran routine      // Disable "track mode" in the fortran routine
# Line 443  void CaloPreSampler::Process(){ Line 538  void CaloPreSampler::Process(){
538        if ( debug ) printf(" Selftrigger: problems with event \n");        if ( debug ) printf(" Selftrigger: problems with event \n");
539      };      };
540    };    };
541    //  //   //
542    // Clear structures used to communicate with fortran  //   // Clear structures used to communicate with fortran
543    //  //   //
544    event->ClearStructs();  //   event->ClearStructs();
545    // ELENA: moved @ beginning
546    //    //
547    //    //
548    //    //
549    if ( debug ) this->Print();    if ( debug ) this->Print();
550    if ( debug ) printf(" exit \n");    if ( debug ) printf(" exit \n");
551    //    //
552  };  }
553    
554    //
555    // Method to add a calorimeter track, evaluated around a tracker track defined by a status vector.
556    // (can be used to evaluate the calorimeter track around an arbitrary axis, by setting the status vector with zero deflection )
557    //
558    //
559    CaloTrkVar* CaloPreSampler::AddCaloTrkVar(float *al,int trktag){
560    
561        int ntrkentry = pcalo->ntrk();
562        //
563        for (Int_t nt=0; nt < ntrkentry; nt++){  
564            if( pcalo->GetCaloTrkVar(nt)->trkseqno == trktag){
565                cout << " CaloTrkVar* CaloPreSampler::AddCaloTrkVar(float *al,int trktag)"<<endl;
566                cout << " --> trktag = "<<trktag<<" already defined "<<endl;
567                return NULL;
568            }
569        }
570        //
571        event->clevel1->good2 = 1; //is a trk track
572        event->clevel1->trkchi2 = 0;
573        event->clevel1->hzn = 0;
574        //
575        // Copy the alpha vector in the input structure
576        //
577        for (Int_t e = 0; e < 5 ; e++){
578            event->clevel1->al_p[e][0] = al[e];
579        };    
580        //
581        // Get tracker related variables for this track
582        //
583        if ( debug ) printf("track %i Call GetTrkVar() \n",trktag);
584        event->GetTrkVar();
585        if ( debug ) printf(" event->clevel2->dX0l %f \n",event->clevel2->dX0l);
586        //
587        // Save tracker track sequence number
588        //  
589        event->trkseqno = trktag;
590        //
591        // Copy values in the class ca from the structure clevel2
592        //
593        if ( debug ) printf("track %i Call FillTrkVar() \n",trktag);
594        event->FillTrkVar(pcalo,ntrkentry);
595    
596        return pcalo->GetCaloTrkVar(ntrkentry);
597        
598    
599    };//ELENA

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

  ViewVC Help
Powered by ViewVC 1.1.23