]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/Rec/AliTPCReconstructor.cxx
Modifications needed to use PID framework based mass during tracking and
[u/mrichter/AliRoot.git] / TPC / Rec / AliTPCReconstructor.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$ */
17
18 //--------------------------------------------------------------------
19 //          Options for the TPC Reconstruction in rec.C
20 //
21 //  4 options can be set to change the input for TPC reconstruction
22 //  which overwrites the usage of fUseHLTClusters of the AliTPCRecoParam
23 //
24 //  1) useRAW        - use RAW, if not present -> do nothing
25 //  2) useRAWorHLT   - use RAW, if not present -> use HLT clusters
26 //  3) useHLT        - use HLT clusters, if not present -> do nothing
27 //  4) useHLTorRAW   - use HLT clusters, if not present -> use RAW
28 //
29 //  -> The current default is useHLTorRAW
30 //--------------------------------------------------------------------
31
32 ///////////////////////////////////////////////////////////////////////////////
33 //                                                                           //
34 // class for TPC reconstruction                                              //
35 //                                                                           //
36 ///////////////////////////////////////////////////////////////////////////////
37
38 #include <TObject.h>
39 #include <TString.h>
40 #include <TObjString.h>
41 #include <TObjArray.h>
42 #include <TFile.h>
43
44 #include <AliLog.h>
45 #include <AliPID.h>
46 #include <AliESDpid.h>
47 #include <AliTPCPIDResponse.h>
48 #include "AliTPCReconstructor.h"
49 #include "AliRunLoader.h"
50 #include "AliRun.h"
51 #include "AliRawReader.h"
52 #include "AliTPCclusterer.h"
53 #include "AliTPCtracker.h"
54 #include "AliTPCParam.h"
55 #include "AliTPCParamSR.h"
56 #include "AliTPCcalibDB.h"
57 #include "AliTracker.h"
58 #include "AliMagF.h"
59
60 ClassImp(AliTPCReconstructor)
61
62
63 Int_t    AliTPCReconstructor::fgStreamLevel     = 1;        // stream (debug) level
64 AliTPCAltroEmulator *  AliTPCReconstructor::fAltroEmulator=0;    // ALTRO emulator
65
66 AliTPCReconstructor::AliTPCReconstructor():
67 AliReconstructor(),
68 fClusterer(NULL),
69 fArrSplines(NULL)
70 {
71   //
72   // default constructor
73   //
74   //
75   //
76   AliTPCcalibDB * calib = AliTPCcalibDB::Instance();
77   const AliMagF * field = (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
78   calib->SetExBField(field);
79   AliTPCParam* param = GetTPCParam();
80   if (!param) {
81     AliWarning("Loading default TPC parameters !");
82     param = new AliTPCParamSR;
83   }
84   fClusterer = new AliTPCclusterer(param);
85 }
86
87 AliTPCReconstructor::AliTPCReconstructor(const AliTPCReconstructor& /*rec*/):
88 AliReconstructor(),
89 fClusterer(NULL),
90 fArrSplines(NULL)
91 {
92   //
93   // Dummy copu constructor
94   //
95 }
96
97 AliTPCReconstructor& AliTPCReconstructor::operator=(const AliTPCReconstructor&){
98   //
99   // dummy operator
100   //
101   return *this;
102 }
103
104 //_____________________________________________________________________________
105 AliTPCReconstructor::~AliTPCReconstructor()
106 {
107   if (fClusterer)   delete fClusterer;
108   delete fArrSplines;
109 }
110
111 //_____________________________________________________________________________
112 void AliTPCReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const {
113   // single event local reconstruction
114   // of TPC data
115   fClusterer->SetInput(digitsTree);
116   fClusterer->SetOutput(clustersTree);
117   fClusterer->Digits2Clusters();
118 }
119
120 //_____________________________________________________________________________
121 void AliTPCReconstructor::Reconstruct(AliRawReader* rawReader, TTree* clustersTree) const {
122   // single event local reconstruction
123   // of TPC data starting from raw data
124
125   fClusterer->SetOutput(clustersTree);
126   fClusterer->Digits2Clusters(rawReader);
127 }
128
129 //_____________________________________________________________________________
130 AliTracker* AliTPCReconstructor::CreateTracker() const
131 {
132 // create a TPC tracker
133
134   AliTPCParam* param = GetTPCParam();
135   if (!param) {
136     AliWarning("Loading default TPC parameters !");
137     param = new AliTPCParamSR;
138   }
139   param->ReadGeoMatrices();
140   
141   AliTPCtracker* tracker = new AliTPCtracker(param);
142
143   ParseOptions(tracker);
144
145   return tracker;
146 }
147
148 //_____________________________________________________________________________
149 void AliTPCReconstructor::FillESD(TTree */*digitsTree*/, TTree */*clustersTree*/,
150                                   AliESDEvent* /*esd*/) const
151 {
152 // make PID
153 /*  Now done in AliESDpid
154   Double_t parTPC[] = {50., 0.07, 5.};  // MIP nnormalized to channel 50 -MI
155   AliTPCpidESD tpcPID(parTPC);
156   tpcPID.MakePID(esd);
157 */
158 }
159
160
161 //_____________________________________________________________________________
162 AliTPCParam* AliTPCReconstructor::GetTPCParam() const
163 {
164 // get the TPC parameters
165
166   AliTPCParam* param = AliTPCcalibDB::Instance()->GetParameters();
167
168   return param;
169 }
170
171 //_____________________________________________________________________________
172 void AliTPCReconstructor::SetSplinesFromOADB(const char* tmplt, AliESDpid *esdPID)
173 {
174   //
175   //  load splines from the OADB using 'template'
176   //
177
178   // only load splines if not already set
179   if (!fArrSplines) {
180     fArrSplines=new TObjArray(Int_t(AliPID::kSPECIES));
181     fArrSplines->SetOwner();
182     TString stemplate(tmplt);
183
184     TString fileNamePIDresponse("$ALICE_ROOT/OADB/COMMON/PID/data/TPCPIDResponse.root");
185     TFile f(fileNamePIDresponse.Data());
186
187     TObjArray *arrPidResponseMaster=0x0;
188
189     if (f.IsOpen() && !f.IsZombie()){
190       arrPidResponseMaster=dynamic_cast<TObjArray*>(f.Get("TPCPIDResponse"));
191     }
192     f.Close();
193
194     if (!arrPidResponseMaster){
195       AliError("PID response array not found, cannot assign proper splines");
196       return;
197     }
198
199     for (Int_t ispec=0; ispec<AliPID::kSPECIES; ++ispec)
200     {
201       Int_t ispec2=ispec;
202       if (ispec==Int_t(AliPID::kMuon)) ispec2=Int_t(AliPID::kPion);
203
204       TString particle=AliPID::ParticleName(ispec2);
205       particle.ToUpper();
206
207       TString splineName;
208       splineName.Form(stemplate.Data(),particle.Data());
209       TObject *spline=arrPidResponseMaster->FindObject(splineName.Data());
210       if (!spline) {
211         AliError(Form("No spline found for '%s'", splineName.Data()));
212         continue;
213       };
214       AliInfo(Form("Adding Response function %d:%s",ispec,splineName.Data()));
215       fArrSplines->AddAt(spline->Clone(), ispec);
216     }    
217     arrPidResponseMaster->Delete();
218     delete arrPidResponseMaster;
219     if (fArrSplines->GetEntries()!=Int_t(AliPID::kSPECIES)) {
220       AliError("Splines not found for all species, cannot use proper PID");
221       delete fArrSplines;
222       fArrSplines=NULL;
223       return;
224     }
225   }
226
227   for (Int_t ispec=0; ispec<AliPID::kSPECIES; ++ispec)
228   {
229     esdPID->GetTPCResponse().SetResponseFunction( (AliPID::EParticleType)ispec, fArrSplines->UncheckedAt(ispec) );
230   }
231
232   esdPID->GetTPCResponse().SetUseDatabase(kTRUE);
233 }
234
235 //_____________________________________________________________________________
236 void AliTPCReconstructor::GetPidSettings(AliESDpid *esdPID)
237 {
238   //
239   // Get TPC pid splines. They should be written to the OCDB during the CPass
240   // the splines themselves are owned by the OCDB object
241   //
242
243   // parse options
244   TString allopt(GetOption());
245   TObjArray *optArray=allopt.Tokenize(";");
246
247   for (Int_t iopt=0; iopt<optArray->GetEntriesFast(); ++iopt){
248     if (!optArray->At(iopt)) continue;
249     TString option(static_cast<TObjString*>(optArray->At(iopt))->GetString().Strip(TString::kBoth,' '));
250
251     if (!option.BeginsWith("PID.")) continue;
252
253     // remove 'PID.' identifyer
254     option.Remove(0,4);
255
256     // parse PID type
257     if (option.BeginsWith("Static=")){
258       option.Remove(0,option.First('=')+1);
259       if (option.Contains("LHC13b2_fix_PID")) {
260         esdPID->GetTPCResponse().SetBetheBlochParameters(0.0320981, 19.9768, 2.52666e-16, 2.72123, 6.08092);
261         esdPID->GetTPCResponse().SetMip(53.4968);
262       }
263       
264     } else if (option.BeginsWith("OADB=")) {
265       option.Remove(0,option.First('=')+1);
266       AliInfo(Form("Setting splines From OADB using template: '%s'",option.Data()));
267       SetSplinesFromOADB(option, esdPID);
268     } else if (option.BeginsWith("OCDB=")){
269       option.Remove(0,option.First('=')+1);
270       // not yet implemented
271     }
272     
273   }
274
275   delete optArray;
276
277 /*
278   AliTPCcalibDB * calib = AliTPCcalibDB::Instance();
279   
280   //Get pid splines array
281   TObjArray *arrSplines=calib->GetPidResponse();
282   if (!arrSplines) return;
283   AliTPCPIDResponse &tpcPID=esdPID->GetTPCResponse();
284   tpcPID.SetUseDatabase(kTRUE);
285
286   // check if parametrisations are already set.
287   // since this is uniq for one run, we don't have to reload them
288   if (tpcPID.GetResponseFunction(AliPID::kPion)) return;
289
290   // get the default object
291   TObject *defaultPID=arrSplines->At(AliPID::kUnknown);
292   
293   // loop over all particle species and set the response functions
294   for (Int_t ispec=0; ispec<AliPID::kUnknown; ++ispec){
295     TObject *pidSpline=arrSplines->At(ispec);
296     if (!pidSpline) pidSpline=defaultPID;
297     tpcPID.SetResponseFunction((AliPID::EParticleType)ispec,pidSpline);
298   }
299  */ 
300 }
301
302 //_____________________________________________________________________________
303 void AliTPCReconstructor::ParseOptions( AliTPCtracker* tracker ) const
304 {
305 // parse options from rec.C and set in clusterer and tracker
306   
307   TString option = GetOption();
308   
309   Int_t useHLTClusters = 3;
310
311   if (option.Contains("use")) {
312     
313     AliInfo(Form("Overide TPC RecoParam with option %s",option.Data()));
314     
315     if (option.Contains("useRAW")) {
316       useHLTClusters = 1;
317       if (option.Contains("useRAWorHLT"))
318         useHLTClusters = 2;
319     }
320     else if (option.Contains("useHLT")) {
321       useHLTClusters = 3;
322       if (option.Contains("useHLTorRAW"))
323         useHLTClusters = 4;
324     }
325   }
326   else {
327     const AliTPCRecoParam* param = GetRecoParam();
328     useHLTClusters = param->GetUseHLTClusters();
329   }
330
331   AliInfo(Form("Usage of HLT clusters in TPC reconstruction : %d", useHLTClusters));
332
333   fClusterer->SetUseHLTClusters(useHLTClusters);
334   tracker->SetUseHLTClusters(useHLTClusters);
335
336   return;
337 }