]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnTOFT0maker.cxx
fixed sig.segv
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnTOFT0maker.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15 /* $Id: AliRsnTOFT0maker.cxx,v 1.8 2010/01/19 16:32:20 noferini Exp $ */
16
17 /////////////////////////////////////////////////////////////////////////////
18 //                                                                         //
19 //  This class contains the basic functions for the time zero              //
20 //  evaluation with TOF detector informations.                             //
21 // Use case in an analysis task:                                           //
22 //                                                                         //
23 // Create the object in the task constructor (fTOFmakerANA is a private var)  //
24 // fTOFmakerANA = new AliRsnTOFT0maker();                                        //
25 // fTOFmakerANA->SetTimeResolution(115.0e-12); // if you want set the TOF res //
26 // 115 ps is the TOF default resolution value                              //
27 //                                                                         //
28 // Use the RemakePID method in the task::Exec                              //
29 // Double_t* calcolot0;                                                    //
30 // calcolot0=fTOFmakerANA->RemakePID(fESD);                                   //
31 // //calcolot0[0] = calculated event time                                  // 
32 // //calcolot0[1] = event time time resolution                             //
33 // //calcolot0[2] = average event time for the current fill                //
34 //                                                                         //
35 // Let consider that:                                                      //
36 // - the PIF is automatically recalculated with the event time subtrction  //
37 //                                                                         //
38 /////////////////////////////////////////////////////////////////////////////
39
40 #include <Riostream.h>
41 #include <stdlib.h>
42
43 #include "AliTOFT0v1.h"
44 #include "AliTOFcalibHisto.h"
45 #include "AliPID.h"
46 #include "AliESDpid.h"
47 #include "TFile.h"
48 #include "AliRsnTOFT0maker.h"
49
50 ClassImp(AliRsnTOFT0maker)
51            
52 //____________________________________________________________________________ 
53   AliRsnTOFT0maker::AliRsnTOFT0maker():
54     fSettings(kNone),
55     fCalib(new AliTOFcalibHisto()),
56     fESDswitch(0),
57     fTimeResolution(115),
58     fT0sigma(1000),
59     fHmapChannel(0),
60     fKmask(0),
61     fNoTOFT0(0)
62 {
63   fCalculated[0] = 0;
64   fCalculated[1] = 0;
65   fCalculated[2] = 0;
66   fCalculated[3] = 0;
67
68   fCalib->LoadCalibPar();
69
70   if(AliPID::ParticleMass(0) == 0) new AliPID();
71 }
72 //____________________________________________________________________________ 
73 AliRsnTOFT0maker::AliRsnTOFT0maker(const AliRsnTOFT0maker & t) :
74   TObject(),
75   fSettings(t.fSettings),
76   fCalib(t.fCalib),
77   fESDswitch(t.fESDswitch),
78   fTimeResolution(t.fTimeResolution),
79   fT0sigma(t.fT0sigma),
80   fHmapChannel(t.fHmapChannel),
81   fKmask(t.fKmask),
82   fNoTOFT0(t.fNoTOFT0)
83 {
84 }
85
86 //____________________________________________________________________________ 
87 AliRsnTOFT0maker& AliRsnTOFT0maker::operator=(const AliRsnTOFT0maker &t)
88 {
89  //
90   // assign. operator
91   //
92
93   fSettings = t.fSettings;
94   if (this == &t)
95     return *this;
96   fCalib = t.fCalib;
97   fESDswitch = t.fESDswitch;
98   fTimeResolution = t.fTimeResolution;
99   fT0sigma = t.fT0sigma;
100
101   return *this;
102 }
103 //____________________________________________________________________________ 
104 AliRsnTOFT0maker::~AliRsnTOFT0maker()
105 {
106   // dtor
107   if(fCalib) delete fCalib;
108 }
109 //____________________________________________________________________________ 
110 Double_t* AliRsnTOFT0maker::RemakePID(AliESDEvent *esd,Double_t t0time,Double_t t0sigma){
111   //
112   // Remake TOF PID probabilities
113   //
114
115   Double_t *t0tof;
116
117   if(fKmask) ApplyMask(esd);
118
119   AliTOFT0v1* t0makerANA=new AliTOFT0v1(esd);
120 //   t0makerANA->SetCalib(fCalib);
121   t0makerANA->SetTimeResolution(fTimeResolution*1e-12);
122
123   if(! fESDswitch){
124     TakeTimeRawCorrection(esd);
125   }
126
127   t0tof=t0makerANA->DefineT0("all");
128
129   Float_t lT0Current=0.;
130   fT0sigma=1000;
131
132   Int_t nrun = 0;//esd->GetRunNumber();
133   Double_t t0fill = 175;//GetT0Fill(nrun);
134   if (fSettings == kPass2 || fSettings == kPass4)      // cambiato!!!!!!!!
135   {
136    nrun = esd->GetRunNumber();
137    t0fill = GetT0Fill(nrun);
138   }
139   else if (fSettings == kLHC09d10) // e' il MC del pass2?
140   {
141    t0fill = GetT0Fill(nrun);
142   } 
143
144   fCalculated[0]=-1000*t0tof[0];
145   fCalculated[1]=1000*t0tof[1];
146   fCalculated[2] = t0fill;
147   fCalculated[3] = t0tof[2];
148
149   if(fCalculated[1] < 150 && TMath::Abs(fCalculated[0] - t0fill) < 500){
150     fT0sigma=fCalculated[1];
151     lT0Current=fCalculated[0];
152   }
153
154   if(t0sigma < 1000){
155     if(fT0sigma < 1000){
156       Double_t w1 = 1./t0sigma/t0sigma;
157       Double_t w2 = 1./fCalculated[1]/fCalculated[1];
158
159       Double_t wtot = w1+w2;
160
161       lT0Current = (w1*t0time + w2*fCalculated[0]) / wtot;
162       fT0sigma = TMath::Sqrt(1./wtot);
163     }
164     else{
165       lT0Current=t0time;
166       fT0sigma=t0sigma;
167     }
168   }
169
170   if(fT0sigma >= 1000 || fNoTOFT0){
171     lT0Current = t0fill;
172     fT0sigma = 135;
173
174     fCalculated[0] = t0fill;
175     fCalculated[1] = 150;
176   }
177
178   RemakeTOFpid(esd,lT0Current);
179   
180   return fCalculated;
181 }
182 //____________________________________________________________________________ 
183 void AliRsnTOFT0maker::TakeTimeRawCorrection(AliESDEvent * const esd){
184   //
185   // Take raw corrections for time measurements
186   //
187   
188   Int_t ntracks = esd->GetNumberOfTracks();
189   
190   while (ntracks--) {
191     AliESDtrack *t=esd->GetTrack(ntracks);
192     
193     if ((t->GetStatus()&AliESDtrack::kTOFout)==0) continue;
194     
195     Double_t time=t->GetTOFsignalRaw();
196     Double_t tot = t->GetTOFsignalToT();
197     Int_t chan = t->GetTOFCalChannel();
198     Double_t corr = fCalib->GetFullCorrection(chan,tot) - fCalib->GetCorrection(AliTOFcalibHisto::kTimeSlewingCorr,chan,0);
199     time -= corr*1000;
200
201     //Int_t crate = Int_t(fCalib->GetCalibMap(AliTOFcalibHisto::kDDL,chan));
202     
203 //     if(crate == 63 || crate == 62){
204 //       time += 9200;
205       
206 //    }
207
208 //     if(crate == 63 || crate == 62|| crate == 61){
209 //  printf("%i) %f\n",crate,time);
210 //     getchar();
211 //   }
212     t->SetTOFsignal(time);
213   }
214 }
215 //____________________________________________________________________________ 
216 void AliRsnTOFT0maker::RemakeTOFpid(AliESDEvent *esd,Float_t timezero){
217   //
218   // Recalculate TOF PID probabilities
219   //
220   AliESDpid pidESD;
221   pidESD.GetTOFResponse().SetTimeResolution(TMath::Sqrt(fT0sigma*fT0sigma + fTimeResolution*fTimeResolution));
222   pidESD.MakePID(esd,kFALSE,timezero);
223   
224 }
225 //____________________________________________________________________________ 
226 Double_t AliRsnTOFT0maker::GetT0Fill(Int_t nrun) const {
227   //
228   // Return T0 of filling
229   //
230   
231   Double_t t0;
232   if(nrun==104065) t0= 1771614;
233   else if(nrun==104068) t0= 1771603;
234   else if(nrun==104070) t0= 1771594;
235   else if(nrun==104073) t0= 1771610;
236   else if(nrun==104080) t0= 1771305;
237   else if(nrun==104083) t0= 1771613;
238   else if(nrun==104157) t0= 1771665;
239   else if(nrun==104159) t0= 1771679;
240   else if(nrun==104160) t0= 1771633;
241   else if(nrun==104316) t0= 1764344;
242   else if(nrun==104320) t0= 1764342;
243   else if(nrun==104321) t0= 1764371;
244   else if(nrun==104439) t0= 1771750;
245   else if(nrun==104792) t0= 1771755;
246   else if(nrun==104793) t0= 1771762;
247   else if(nrun==104799) t0= 1771828;
248   else if(nrun==104800) t0= 1771788;
249   else if(nrun==104801) t0= 1771796;
250   else if(nrun==104802) t0= 1771775;
251   else if(nrun==104803) t0= 1771795;
252   else if(nrun==104824) t0= 1771751;
253   else if(nrun==104825) t0= 1771763;
254   else if(nrun==104845) t0= 1771792;
255   else if(nrun==104852) t0= 1771817;
256   else if(nrun==104864) t0= 1771825;
257   else if(nrun==104865) t0= 1771827;
258   else if(nrun==104867) t0= 1771841;
259   else if(nrun==104876) t0= 1771856;
260   else if(nrun==104878) t0= 1771847;
261   else if(nrun==104879) t0= 1771830;
262   else if(nrun==104892) t0= 1771837;
263   else t0= 487;
264
265   if(fESDswitch) t0 -= 487;
266   else { if (fSettings == kPass4) t0 -=37*1024*24.4; }
267
268   return t0;
269 }
270
271 //____________________________________________________________________________ 
272 void  AliRsnTOFT0maker::LoadChannelMap(char *filename){
273   // Load the histo with the channel off map
274   TFile *f= new TFile(filename);
275   if(!f){
276     printf("Cannot open the channel map file (%s)\n",filename);
277     return;
278   }
279   
280   fHmapChannel = (TH1F *) f->Get("hChEnabled");
281   
282   if(!fHmapChannel){
283     printf("Cannot laod the channel map histo (from %s)\n",filename);
284     return;
285   }
286     
287 }
288 //____________________________________________________________________________ 
289 void AliRsnTOFT0maker::ApplyMask(AliESDEvent *esd){
290   // Switch off the disable channel
291   if(!fHmapChannel){
292     printf("Channel Map is not available\n");
293     return;
294   }
295   
296   Int_t ntracks = esd->GetNumberOfTracks();
297   
298   while (ntracks--) {
299     AliESDtrack *t=esd->GetTrack(ntracks);
300     
301     if ((t->GetStatus()&AliESDtrack::kTOFout)==0) continue;
302     
303     Int_t chan = t->GetTOFCalChannel();
304  
305     if(fHmapChannel->GetBinContent(chan) < 0.01){
306       t->ResetStatus(AliESDtrack::kTOFout);
307     }
308   }
309 }