]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/TenderSupplies/AliTOFT0makerANA.cxx
7436b550d11170183fd8f7e1c868805a653f99a9
[u/mrichter/AliRoot.git] / ANALYSIS / TenderSupplies / AliTOFT0makerANA.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: AliTOFT0makerANA.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 AliTOFT0makerANA();                                        //
25 // fTOFmakerANA->SetTimeResolution(130.0); // 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 // //calcolot0[3] = tracks at TOF                                          // 
35 // //calcolot0[4] = calculated event time (only TOF)                       //
36 // //calcolot0[5] = event time time resolution (only TOF)                  //
37 // //calcolot0[6] = sigma t0 fill                                          //
38 // //calcolot0[7] = tracks at TOF really used in tht algorithm             // 
39 //                                                                         //
40 // Let consider that:                                                      //
41 // - the PIF is automatically recalculated with the event time subtrction  //
42 //                                                                         //
43 /////////////////////////////////////////////////////////////////////////////
44
45 #include <AliPID.h>
46 #include <AliESDpid.h>
47 #include <AliESDEvent.h>
48 #include <TFile.h>
49 #include <TH1F.h>
50
51 #include "AliTOFT0v2.h"
52 #include "AliTOFT0makerANA.h"
53
54 ClassImp(AliTOFT0makerANA)
55
56 //____________________________________________________________________________ 
57 AliTOFT0makerANA::AliTOFT0makerANA():
58   fPIDesd(0x0),
59   fnT0(0),
60   fiT0(0),
61   fNoTOFT0(0),
62   fTimeResolution(115),
63   fT0sigma(1000),
64   fHmapChannel(0),
65   fKmask(0)
66 {
67   // ctr
68   fCalculated[0] = 0;
69   fCalculated[1] = 0;
70   fCalculated[2] = 0;
71   fCalculated[3] = 0;
72   
73   if(AliPID::ParticleMass(0) == 0) new AliPID();
74   
75   fPIDesd = new AliESDpid();
76   
77 }
78 //____________________________________________________________________________ 
79 AliTOFT0makerANA::AliTOFT0makerANA(AliESDpid *const externalPID):
80   fPIDesd(0x0),
81   fnT0(0),
82   fiT0(0),
83   fNoTOFT0(0),
84   fTimeResolution(115),
85   fT0sigma(1000),
86   fHmapChannel(0),
87   fKmask(0)
88 {
89   // ctr
90   fCalculated[0] = 0;
91   fCalculated[1] = 0;
92   fCalculated[2] = 0;
93   fCalculated[3] = 0;
94   
95   if(AliPID::ParticleMass(0) == 0) new AliPID();
96   
97   fPIDesd = externalPID;
98   if(!fPIDesd){
99     fPIDesd = new AliESDpid();
100     printf("ATTENTION!!!\n New AliESDpid is created in AliTOFT0makerANA class!!!!\n");
101   }
102   
103 }
104 //____________________________________________________________________________ 
105 AliTOFT0makerANA::AliTOFT0makerANA(const AliTOFT0makerANA & t) :
106 TObject(),
107 fPIDesd(t.fPIDesd),
108 fnT0(t.fnT0),
109 fiT0(t.fiT0),
110 fNoTOFT0(t.fNoTOFT0),
111 fTimeResolution(t.fTimeResolution),
112 fT0sigma(t.fT0sigma),
113 fHmapChannel(t.fHmapChannel),
114 fKmask(t.fKmask)
115 {
116   // copy ctr
117 }
118
119 //____________________________________________________________________________ 
120 AliTOFT0makerANA& AliTOFT0makerANA::operator=(const AliTOFT0makerANA &t)
121 {
122   //
123   // assign. operator
124   //
125   
126   if (this == &t)
127     return *this;
128   fTimeResolution = t.fTimeResolution;
129   fT0sigma = t.fT0sigma;
130   
131   return *this;
132 }
133 //____________________________________________________________________________ 
134 AliTOFT0makerANA::~AliTOFT0makerANA()
135 {
136   // dtor
137 }
138 //____________________________________________________________________________ 
139 Double_t* AliTOFT0makerANA::RemakePID(AliESDEvent *esd,Double_t t0time,Double_t t0sigma){
140   //
141   // Remake TOF PID probabilities
142   //
143   
144   Double_t *t0tof;
145   
146   if(fKmask) ApplyMask(esd);
147   
148   AliTOFT0v2 t0makerANA(esd);
149   t0makerANA.SetTimeResolution(fTimeResolution*1e-12*1.1);
150   
151   t0tof=t0makerANA.DefineT0("all");
152   
153   Float_t lT0Current=0.;
154   fT0sigma=1000;
155   
156   Double_t t0fill = GetT0Fill();
157   t0time += t0fill;
158   
159   Float_t sigmaFill = (t0fill - Int_t(t0fill))*1000;
160   if(sigmaFill < 0) sigmaFill += 1000;
161   
162   if(sigmaFill < 50) sigmaFill = 50;
163   
164   fCalculated[0]=-1000*t0tof[0]; // best t0
165   fCalculated[1]=1000*t0tof[1]; // sigma best t0
166   fCalculated[2] = t0fill;    //t0 fill
167   fCalculated[3] = t0tof[2];  // n TOF tracks
168   fCalculated[4]=-1000*t0tof[0]; // TOF t0
169   fCalculated[5]=1000*t0tof[1]; // TOF t0 sigma
170   fCalculated[6]=sigmaFill; // sigma t0 fill
171   fCalculated[7] = t0tof[3];  // n TOF tracks used for T0
172   
173   if(fCalculated[1] < sigmaFill){
174     if(fnT0 < 10){
175       fT0fill[fiT0] = fCalculated[0];
176       fT0sigmaTOF[fiT0] = fCalculated[1];
177       fiT0++;
178       fnT0++;
179     }
180     else if(TMath::Abs(fCalculated[0] - t0fill) < 500){
181       fT0fill[fiT0] = fCalculated[0];
182       fT0sigmaTOF[fiT0] = fCalculated[1];
183       fiT0++;
184       fnT0++;
185     }
186     
187     //        printf("%i - %i) %f\n",fiT0,fnT0,t0fill);
188   }
189   if(fnT0==10) fiT0=0;
190   
191   if(fiT0 > fgkNmaxT0step-1) fiT0=0;
192   
193   if(fnT0 < 100){
194     t0time -= t0fill;
195     sigmaFill=200;
196     t0fill=0;
197     fCalculated[2] = t0fill;    //t0 fill
198   }
199   
200   if(fCalculated[1] < sigmaFill && TMath::Abs(fCalculated[0] - t0fill) < 500){
201     fT0sigma=fCalculated[1];
202     lT0Current=fCalculated[0];
203   }
204   else{
205     fCalculated[4] = t0fill;
206     fCalculated[5] = sigmaFill;
207   }
208   
209   if(fCalculated[1] < 1 || fT0sigma > sigmaFill){
210     fT0sigma =1000;
211     fCalculated[4] = t0fill;
212     fCalculated[5] = sigmaFill;
213   }
214   
215   if(t0sigma < 1000){
216     if(fT0sigma < 1000){
217       Double_t w1 = 1./t0sigma/t0sigma;
218       Double_t w2 = 1./fCalculated[1]/fCalculated[1];
219       
220       Double_t wtot = w1+w2;
221       
222       lT0Current = (w1*t0time + w2*fCalculated[0]) / wtot;
223       fT0sigma = TMath::Sqrt(1./wtot);
224     }
225     else{
226       lT0Current=t0time;
227       fT0sigma=t0sigma;
228     }
229   }
230   
231   if(fT0sigma < sigmaFill && TMath::Abs(lT0Current - t0fill) < 500){
232     fCalculated[1]=fT0sigma;
233     fCalculated[0]=lT0Current;
234   }
235   
236   if(fT0sigma >= 1000 || fNoTOFT0){
237     lT0Current = t0fill;
238     fT0sigma = sigmaFill;
239     
240     fCalculated[0] = t0fill;
241     fCalculated[1] = sigmaFill;
242   }
243   
244   
245   
246   RemakeTOFpid(/*esd,*/lT0Current);
247   
248   return fCalculated;
249 }
250 //____________________________________________________________________________ 
251 void AliTOFT0makerANA::RemakeTOFpid(/*AliESDEvent *esd,*/Float_t timezero){
252   //
253   // Recalculate TOF PID probabilities
254   //
255   
256   fPIDesd->GetTOFResponse().SetTimeResolution(TMath::Sqrt(fT0sigma*fT0sigma + fTimeResolution*fTimeResolution));
257   //  fPIDesd->MakePID(esd,kFALSE,timezero);
258   fPIDesd->GetTOFResponse().SetTimeZero(timezero);
259   // please call fESDpid->MakePID(fEvent, kFALSE,fESDpid->GetTOFResponse().GetTimeZero()); when you make new PID
260 }
261 //____________________________________________________________________________ 
262 Double_t AliTOFT0makerANA::GetT0Fill() const {
263   //
264   // Return T0 of filling
265   //
266   
267   Double_t t0=0.200;
268   
269   Int_t n=fnT0;
270   
271   if(n >10 && n <= 20) n = 10;
272   else if(n > 20){
273     n -= 10;
274   }
275   
276   if(n > fgkNmaxT0step) n = fgkNmaxT0step;
277   
278   if(n>1){
279     Double_t lT0av=0;
280     Double_t lT0sigmaav=0;
281     Double_t lT0avErr=0;
282     for(Int_t i=0;i<n;i++){
283       lT0av+=fT0fill[i];
284       lT0sigmaav += fT0sigmaTOF[fiT0];
285       lT0avErr+=fT0fill[i]*fT0fill[i];
286     }
287     lT0avErr -= lT0av*lT0av/n;
288     lT0av /= n;
289     lT0sigmaav /= n;
290     lT0avErr = TMath::Sqrt(TMath::Max(lT0avErr/(n-1) - lT0sigmaav*lT0sigmaav,0.00001));
291     
292     
293     if(lT0avErr > 300) lT0avErr = 300;
294     
295     lT0av = Int_t(lT0av) + lT0avErr/1000.;
296     
297     return lT0av;
298   }
299   
300   
301   return t0;
302 }
303 //____________________________________________________________________________ 
304 void  AliTOFT0makerANA::LoadChannelMap(char *filename){
305   // Load the histo with the channel off map
306   TFile *f= new TFile(filename);
307   if(!f){
308     printf("Cannot open the channel map file (%s)\n",filename);
309     return;
310   }
311   
312   fHmapChannel = (TH1F *) f->Get("hChEnabled");
313   
314   if(!fHmapChannel){
315     printf("Cannot laod the channel map histo (from %s)\n",filename);
316     return;
317   }
318   
319 }
320 //____________________________________________________________________________ 
321 void AliTOFT0makerANA::ApplyMask(AliESDEvent * const esd){
322   // Switch off the disable channel
323   if(!fHmapChannel){
324     printf("Channel Map is not available\n");
325     return;
326   }
327   
328   Int_t ntracks = esd->GetNumberOfTracks();
329   
330   while (ntracks--) {
331     AliESDtrack *t=esd->GetTrack(ntracks);
332     
333     if ((t->GetStatus()&AliESDtrack::kTOFout)==0) continue;
334     
335     Int_t chan = t->GetTOFCalChannel();
336     
337     if(fHmapChannel->GetBinContent(chan) < 0.01){
338       t->ResetStatus(AliESDtrack::kTOFout);
339     }
340   }
341 }
342
343 //____________________________________________________________________________