]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/RESONANCES/extra/AliRsnTOFT0maker.cxx
Coverity 18193
[u/mrichter/AliRoot.git] / PWGLF / RESONANCES / extra / 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    Int_t i;
73    for (i = 0; i < 4; i++) fCalculated[i] = 0.0;
74 }
75 //____________________________________________________________________________
76 AliRsnTOFT0maker::AliRsnTOFT0maker(const AliRsnTOFT0maker & t) :
77    TObject(),
78    fSettings(t.fSettings),
79    fCalib(t.fCalib),
80    fESDswitch(t.fESDswitch),
81    fTimeResolution(t.fTimeResolution),
82    fT0sigma(t.fT0sigma),
83    fHmapChannel(t.fHmapChannel),
84    fKmask(t.fKmask),
85    fNoTOFT0(t.fNoTOFT0)
86 {
87    fCalculated[0] = t.fCalculated[0];
88    fCalculated[1] = t.fCalculated[1];
89    fCalculated[2] = t.fCalculated[2];
90    fCalculated[3] = t.fCalculated[3];
91 }
92
93 //____________________________________________________________________________
94 AliRsnTOFT0maker& AliRsnTOFT0maker::operator=(const AliRsnTOFT0maker &t)
95 {
96 //
97    // assign. operator
98    //
99    
100    fCalculated[0] = t.fCalculated[0];
101    fCalculated[1] = t.fCalculated[1];
102    fCalculated[2] = t.fCalculated[2];
103    fCalculated[3] = t.fCalculated[3];
104
105    fSettings = t.fSettings;
106    if (this == &t)
107       return *this;
108    fCalib = t.fCalib;
109    fESDswitch = t.fESDswitch;
110    fTimeResolution = t.fTimeResolution;
111    fT0sigma = t.fT0sigma;
112
113    return *this;
114 }
115 //____________________________________________________________________________
116 AliRsnTOFT0maker::~AliRsnTOFT0maker()
117 {
118    // dtor
119    if (fCalib) delete fCalib;
120 }
121 //____________________________________________________________________________
122 Double_t* AliRsnTOFT0maker::RemakePID(AliESDEvent *esd, Double_t t0time, Double_t t0sigma)
123 {
124    //
125    // Remake TOF PID probabilities
126    //
127
128    Double_t *t0tof;
129
130    if (fKmask) ApplyMask(esd);
131
132    AliTOFT0v1* t0makerANA = new AliTOFT0v1(esd);
133 //   t0makerANA->SetCalib(fCalib);
134    t0makerANA->SetTimeResolution(fTimeResolution * 1e-12);
135
136    if (! fESDswitch) {
137       TakeTimeRawCorrection(esd);
138    }
139
140    t0tof = t0makerANA->DefineT0("all");
141
142    Float_t lT0Current = 0.;
143    fT0sigma = 1000;
144
145    Int_t nrun = 0;//esd->GetRunNumber();
146    Double_t t0fill = 175;//GetT0Fill(nrun);
147    if (fSettings == kPass2 || fSettings == kPass4) {    // cambiato!!!!!!!!
148       nrun = esd->GetRunNumber();
149       t0fill = GetT0Fill(nrun);
150    } else if (fSettings == kLHC09d10) { // e' il MC del pass2?
151       t0fill = GetT0Fill(nrun);
152    }
153
154    fCalculated[0] = -1000 * t0tof[0];
155    fCalculated[1] = 1000 * t0tof[1];
156    fCalculated[2] = t0fill;
157    fCalculated[3] = t0tof[2];
158
159    if (fCalculated[1] < 150 && TMath::Abs(fCalculated[0] - t0fill) < 500) {
160       fT0sigma = fCalculated[1];
161       lT0Current = fCalculated[0];
162    }
163
164    if (t0sigma < 1000) {
165       if (fT0sigma < 1000) {
166          Double_t w1 = 1. / t0sigma / t0sigma;
167          Double_t w2 = 1. / fCalculated[1] / fCalculated[1];
168
169          Double_t wtot = w1 + w2;
170
171          lT0Current = (w1 * t0time + w2 * fCalculated[0]) / wtot;
172          fT0sigma = TMath::Sqrt(1. / wtot);
173       } else {
174          lT0Current = t0time;
175          fT0sigma = t0sigma;
176       }
177    }
178
179    if (fT0sigma >= 1000 || fNoTOFT0) {
180       lT0Current = t0fill;
181       fT0sigma = 135;
182
183       fCalculated[0] = t0fill;
184       fCalculated[1] = 150;
185    }
186
187    RemakeTOFpid(esd, lT0Current);
188
189    return fCalculated;
190 }
191 //____________________________________________________________________________
192 void AliRsnTOFT0maker::TakeTimeRawCorrection(AliESDEvent * const esd)
193 {
194    //
195    // Take raw corrections for time measurements
196    //
197
198    Int_t ntracks = esd->GetNumberOfTracks();
199
200    while (ntracks--) {
201       AliESDtrack *t = esd->GetTrack(ntracks);
202
203       if ((t->GetStatus()&AliESDtrack::kTOFout) == 0) continue;
204
205       Double_t time = t->GetTOFsignalRaw();
206       Double_t tot = t->GetTOFsignalToT();
207       Int_t chan = t->GetTOFCalChannel();
208       Double_t corr = fCalib->GetFullCorrection(chan, tot) - fCalib->GetCorrection(AliTOFcalibHisto::kTimeSlewingCorr, chan, 0);
209       time -= corr * 1000;
210
211       //Int_t crate = Int_t(fCalib->GetCalibMap(AliTOFcalibHisto::kDDL,chan));
212
213 //     if(crate == 63 || crate == 62){
214 //       time += 9200;
215
216 //    }
217
218 //     if(crate == 63 || crate == 62|| crate == 61){
219 //  printf("%i) %f\n",crate,time);
220 //     getchar();
221 //   }
222       t->SetTOFsignal(time);
223    }
224 }
225 //____________________________________________________________________________
226 void AliRsnTOFT0maker::RemakeTOFpid(AliESDEvent *esd, Float_t timezero)
227 {
228    //
229    // Recalculate TOF PID probabilities
230    //
231    AliESDpid pidESD;
232    pidESD.GetTOFResponse().SetTimeResolution(TMath::Sqrt(fT0sigma * fT0sigma + fTimeResolution * fTimeResolution));
233    pidESD.MakePID(esd, kFALSE, timezero);
234
235 }
236 //____________________________________________________________________________
237 Double_t AliRsnTOFT0maker::GetT0Fill(Int_t nrun) const
238 {
239    //
240    // Return T0 of filling
241    //
242
243    Double_t t0;
244    if (nrun == 104065) t0 = 1771614;
245    else if (nrun == 104068) t0 = 1771603;
246    else if (nrun == 104070) t0 = 1771594;
247    else if (nrun == 104073) t0 = 1771610;
248    else if (nrun == 104080) t0 = 1771305;
249    else if (nrun == 104083) t0 = 1771613;
250    else if (nrun == 104157) t0 = 1771665;
251    else if (nrun == 104159) t0 = 1771679;
252    else if (nrun == 104160) t0 = 1771633;
253    else if (nrun == 104316) t0 = 1764344;
254    else if (nrun == 104320) t0 = 1764342;
255    else if (nrun == 104321) t0 = 1764371;
256    else if (nrun == 104439) t0 = 1771750;
257    else if (nrun == 104792) t0 = 1771755;
258    else if (nrun == 104793) t0 = 1771762;
259    else if (nrun == 104799) t0 = 1771828;
260    else if (nrun == 104800) t0 = 1771788;
261    else if (nrun == 104801) t0 = 1771796;
262    else if (nrun == 104802) t0 = 1771775;
263    else if (nrun == 104803) t0 = 1771795;
264    else if (nrun == 104824) t0 = 1771751;
265    else if (nrun == 104825) t0 = 1771763;
266    else if (nrun == 104845) t0 = 1771792;
267    else if (nrun == 104852) t0 = 1771817;
268    else if (nrun == 104864) t0 = 1771825;
269    else if (nrun == 104865) t0 = 1771827;
270    else if (nrun == 104867) t0 = 1771841;
271    else if (nrun == 104876) t0 = 1771856;
272    else if (nrun == 104878) t0 = 1771847;
273    else if (nrun == 104879) t0 = 1771830;
274    else if (nrun == 104892) t0 = 1771837;
275    else t0 = 487;
276
277    if (fESDswitch) t0 -= 487;
278    else { if (fSettings == kPass4) t0 -= 37 * 1024 * 24.4; }
279
280    return t0;
281 }
282
283 //____________________________________________________________________________
284 void  AliRsnTOFT0maker::LoadChannelMap(char *filename)
285 {
286    // Load the histo with the channel off map
287    TFile *f = new TFile(filename);
288    if (!f) {
289       printf("Cannot open the channel map file (%s)\n", filename);
290       return;
291    }
292
293    fHmapChannel = (TH1F *) f->Get("hChEnabled");
294
295    if (!fHmapChannel) {
296       printf("Cannot laod the channel map histo (from %s)\n", filename);
297       return;
298    }
299
300 }
301 //____________________________________________________________________________
302 void AliRsnTOFT0maker::ApplyMask(AliESDEvent *esd)
303 {
304    // Switch off the disable channel
305    if (!fHmapChannel) {
306       printf("Channel Map is not available\n");
307       return;
308    }
309
310    Int_t ntracks = esd->GetNumberOfTracks();
311
312    while (ntracks--) {
313       AliESDtrack *t = esd->GetTrack(ntracks);
314
315       if ((t->GetStatus()&AliESDtrack::kTOFout) == 0) continue;
316
317       Int_t chan = t->GetTOFCalChannel();
318
319       if (fHmapChannel->GetBinContent(chan) < 0.01) {
320          t->ResetStatus(AliESDtrack::kTOFout);
321       }
322    }
323 }