]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliPIDResponse.cxx
New TPC BB for PbPb pass2 (Rossella)
[u/mrichter/AliRoot.git] / STEER / AliPIDResponse.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
16 /* $Id: AliPIDResponse.cxx 46193 2010-12-21 09:00:14Z wiechula $ */
17
18 //-----------------------------------------------------------------
19 //        Base class for handling the pid response               //
20 //        functions of all detectors                             //
21 //        and give access to the nsigmas                         //
22 //                                                               //
23 //   Origin: Jens Wiechula, Uni Tuebingen, jens.wiechula@cern.ch //
24 //-----------------------------------------------------------------
25
26 #include <TList.h>
27 #include <TObjArray.h>
28 #include <TPRegexp.h>
29 #include <TF1.h>
30 #include <TSpline.h>
31 #include <TFile.h>
32
33 #include <AliVEvent.h>
34 #include <AliLog.h>
35 #include <AliPID.h>
36
37 #include "AliPIDResponse.h"
38
39 ClassImp(AliPIDResponse);
40
41 AliPIDResponse::AliPIDResponse(Bool_t isMC/*=kFALSE*/) :
42 TNamed("PIDResponse","PIDResponse"),
43 fITSResponse(isMC),
44 fTPCResponse(),
45 fTRDResponse(),
46 fTOFResponse(),
47 fIsMC(isMC),
48 fOADBPath(),
49 fBeamType("PP"),
50 fLHCperiod(),
51 fMCperiodTPC(),
52 fRecoPass(0),
53 fRun(0),
54 fOldRun(0),
55 fArrPidResponseMaster(0x0),
56 fResolutionCorrection(0x0),
57 fTOFTimeZeroType(kBest_T0),
58 fTOFres(100.)
59 {
60   //
61   // default ctor
62   //
63   AliLog::SetClassDebugLevel("AliPIDResponse",10);
64   AliLog::SetClassDebugLevel("AliESDpid",10);
65   AliLog::SetClassDebugLevel("AliAODpidUtil",10);
66 }
67
68 //______________________________________________________________________________
69 AliPIDResponse::~AliPIDResponse()
70 {
71   //
72   // dtor
73   //
74   delete fArrPidResponseMaster;
75 }
76
77 //______________________________________________________________________________
78 AliPIDResponse::AliPIDResponse(const AliPIDResponse &other) :
79 TNamed(other),
80 fITSResponse(other.fITSResponse),
81 fTPCResponse(other.fTPCResponse),
82 fTRDResponse(other.fTRDResponse),
83 fTOFResponse(other.fTOFResponse),
84 fIsMC(other.fIsMC),
85 fOADBPath(other.fOADBPath),
86 fBeamType("PP"),
87 fLHCperiod(),
88 fMCperiodTPC(),
89 fRecoPass(0),
90 fRun(0),
91 fOldRun(0),
92 fArrPidResponseMaster(0x0),
93 fResolutionCorrection(0x0),
94 fTOFTimeZeroType(AliPIDResponse::kBest_T0),
95 fTOFres(100.)
96 {
97   //
98   // copy ctor
99   //
100 }
101
102 //______________________________________________________________________________
103 AliPIDResponse& AliPIDResponse::operator=(const AliPIDResponse &other)
104 {
105   //
106   // copy ctor
107   //
108   if(this!=&other) {
109     delete fArrPidResponseMaster;
110     TNamed::operator=(other);
111     fITSResponse=other.fITSResponse;
112     fTPCResponse=other.fTPCResponse;
113     fTRDResponse=other.fTRDResponse;
114     fTOFResponse=other.fTOFResponse;
115     fOADBPath=other.fOADBPath;
116     fIsMC=other.fIsMC;
117     fBeamType="PP";
118     fLHCperiod="";
119     fMCperiodTPC="";
120     fRecoPass=0;
121     fRun=0;
122     fOldRun=0;
123     fArrPidResponseMaster=0x0;
124     fResolutionCorrection=0x0;
125     fTOFTimeZeroType=AliPIDResponse::kBest_T0;
126     fTOFres=100.;
127   }
128   return *this;
129 }
130
131 //______________________________________________________________________________
132 void AliPIDResponse::InitialiseEvent(AliVEvent *event, Int_t pass)
133 {
134   //
135   // Apply settings for the current event
136   //
137   fRecoPass=pass;
138
139   if (!event) return;
140   fRun=event->GetRunNumber();
141   
142   if (fRun!=fOldRun){
143     ExecNewRun();
144     fOldRun=fRun;
145   }
146   
147   //TPC resolution parametrisation PbPb
148   if ( fResolutionCorrection ){
149     Double_t corrSigma=fResolutionCorrection->Eval(GetTPCMultiplicityBin(event));
150     fTPCResponse.SetSigma(3.79301e-03*corrSigma, 2.21280e+04);
151   }
152   
153   //TOF resolution
154   SetTOFResponse(event, (AliPIDResponse::EStartTimeType_t)fTOFTimeZeroType);
155   
156 }
157
158 //______________________________________________________________________________
159 void AliPIDResponse::ExecNewRun()
160 {
161   //
162   // Things to Execute upon a new run
163   //
164   SetRecoInfo();
165   
166   SetITSParametrisation();
167   
168   SetTPCPidResponseMaster();
169   SetTPCParametrisation();
170   
171   fTOFResponse.SetTimeResolution(fTOFres);
172 }
173
174 //_____________________________________________________
175 Double_t AliPIDResponse::GetTPCMultiplicityBin(const AliVEvent * const event)
176 {
177   //
178   // Get TPC multiplicity in bins of 150
179   //
180   
181   const AliVVertex* vertexTPC = event->GetPrimaryVertex();
182   Double_t tpcMulti=0.;
183   if(vertexTPC){
184     Double_t vertexContribTPC=vertexTPC->GetNContributors();
185     tpcMulti=vertexContribTPC/150.;
186     if (tpcMulti>20.) tpcMulti=20.;
187   }
188   
189   return tpcMulti;
190 }
191
192 //______________________________________________________________________________
193 void AliPIDResponse::SetRecoInfo()
194 {
195   //
196   // Set reconstruction information
197   //
198   
199   //reset information
200   fLHCperiod="";
201   fMCperiodTPC="";
202   
203   fBeamType="";
204     
205   fBeamType="PP";
206   
207   //find the period by run number (UGLY, but not stored in ESD and AOD... )
208   if (fRun>=114737&&fRun<=117223)      { fLHCperiod="LHC10B"; fMCperiodTPC="LHC10D1";  }
209   else if (fRun>=118503&&fRun<=121040) { fLHCperiod="LHC10C"; fMCperiodTPC="LHC10D1";  }
210   else if (fRun>=122195&&fRun<=126437) { fLHCperiod="LHC10D"; fMCperiodTPC="LHC10F6A"; }
211   else if (fRun>=127719&&fRun<=130850) { fLHCperiod="LHC10E"; fMCperiodTPC="LHC10F6A"; }
212   else if (fRun>=133004&&fRun<=135029) { fLHCperiod="LHC10F"; fMCperiodTPC="LHC10F6A"; }
213   else if (fRun>=135654&&fRun<=136377) { fLHCperiod="LHC10G"; fMCperiodTPC="LHC10F6A"; }
214   else if (fRun>=136851&&fRun<=139517) { fLHCperiod="LHC10H"; fMCperiodTPC="LHC10H8"; fBeamType="PBPB"; }
215   else if (fRun>=139699) { fLHCperiod="LHC11A"; fMCperiodTPC="LHC10F6A"; }
216   
217 }
218
219 //______________________________________________________________________________
220 void AliPIDResponse::SetITSParametrisation()
221 {
222   //
223   // Set the ITS parametrisation
224   //
225 }
226
227 //______________________________________________________________________________
228 void AliPIDResponse::SetTPCPidResponseMaster()
229 {
230   //
231   // Load the TPC pid response functions from the OADB
232   //
233   
234   //reset the PID response functions
235   delete fArrPidResponseMaster;
236   fArrPidResponseMaster=0x0;
237   
238   TString fileName(Form("%s/COMMON/PID/data/TPCPIDResponse.root", fOADBPath.Data()));
239   
240   TFile f(fileName.Data());
241   if (f.IsOpen() && !f.IsZombie()){
242     fArrPidResponseMaster=dynamic_cast<TObjArray*>(f.Get("TPCPIDResponse"));
243     f.Close();
244   }
245   
246   if (!fArrPidResponseMaster){
247     AliFatal(Form("Could not retrieve the TPC pid response from: %s",fileName.Data()));
248     return;
249   }
250   fArrPidResponseMaster->SetOwner();
251 }
252
253 //______________________________________________________________________________
254 void AliPIDResponse::SetTPCParametrisation()
255 {
256   //
257   // Change BB parametrisation for current run
258   //
259   
260   if (fLHCperiod.IsNull()) {
261     AliFatal("No period set, not changing parametrisation");
262     return;
263   }
264   
265   //
266   // Set default parametrisations for data and MC
267   //
268   
269   //data type
270   TString datatype="DATA";
271   //in case of mc fRecoPass is per default 1
272   if (fIsMC) {
273     datatype="MC";
274     fRecoPass=1;
275   }
276   
277   //
278   //reset old splines
279   //
280   for (Int_t ispec=0; ispec<AliPID::kSPECIES; ++ispec){
281     fTPCResponse.SetResponseFunction((AliPID::EParticleType)ispec,0x0);
282   }
283   
284   //
285   //set the new PID splines
286   //
287   TString period=fLHCperiod;
288   if (fArrPidResponseMaster){
289     TObject *grAll=0x0;
290     //for MC don't use period information
291 //     if (fIsMC) period="[A-Z0-9]*";
292     //for MC use MC period information
293     if (fIsMC) period=fMCperiodTPC;
294 //pattern for the default entry (valid for all particles)
295     TPRegexp reg(Form("TSPLINE3_%s_([A-Z]*)_%s_PASS%d_%s_MEAN",datatype.Data(),period.Data(),fRecoPass,fBeamType.Data()));
296     
297     //loop over entries and filter them
298     for (Int_t iresp=0; iresp<fArrPidResponseMaster->GetEntriesFast();++iresp){
299       TObject *responseFunction=fArrPidResponseMaster->At(iresp);
300       if (responseFunction==0x0) continue;
301       TString responseName=responseFunction->GetName();
302       
303       if (!reg.MatchB(responseName)) continue;
304       
305       TObjArray *arr=reg.MatchS(responseName);
306       TString particleName=arr->At(1)->GetName();
307       delete arr;
308       if (particleName.IsNull()) continue;
309       if (particleName=="ALL") grAll=responseFunction;
310       else {
311         //find particle id
312         for (Int_t ispec=0; ispec<AliPID::kSPECIES; ++ispec){
313           TString particle=AliPID::ParticleName(ispec);
314           particle.ToUpper();
315           if ( particle == particleName ){
316             fTPCResponse.SetResponseFunction((AliPID::EParticleType)ispec,responseFunction);
317             fTPCResponse.SetUseDatabase(kTRUE);
318             AliInfo(Form("Adding graph: %d - %s",ispec,responseFunction->GetName()));
319             break;
320           }
321         }
322       }
323     }
324     
325     //set default response function to all particles which don't have a specific one
326     if (grAll){
327       for (Int_t ispec=0; ispec<AliPID::kSPECIES; ++ispec){
328         if (!fTPCResponse.GetResponseFunction((AliPID::EParticleType)ispec)){
329           fTPCResponse.SetResponseFunction((AliPID::EParticleType)ispec,grAll);
330           AliInfo(Form("Adding graph: %d - %s",ispec,grAll->GetName()));
331         }
332       }
333     }
334   }
335   
336   //
337   // Setup resolution parametrisation
338   //
339   
340   //default
341   fTPCResponse.SetSigma(3.79301e-03, 2.21280e+04);
342   
343   if (fRun>=122195){
344     fTPCResponse.SetSigma(2.30176e-02, 5.60422e+02);
345   }
346   
347   fResolutionCorrection=(TF1*)fArrPidResponseMaster->FindObject(Form("TF1_%s_ALL_%s_PASS%d_%s_SIGMA",datatype.Data(),period.Data(),fRecoPass,fBeamType.Data()));
348   
349   if (fResolutionCorrection) AliInfo(Form("Setting multiplicity correction function: %s",fResolutionCorrection->GetName()));
350 }
351