]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/Rec/AliTPCReconstructor.cxx
Install macros
[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     = 0;        // 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   delete AliTPCcalibDB::Instance();
110 }
111
112 //_____________________________________________________________________________
113 void AliTPCReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const {
114   // single event local reconstruction
115   // of TPC data
116   fClusterer->SetInput(digitsTree);
117   fClusterer->SetOutput(clustersTree);
118   fClusterer->Digits2Clusters();
119 }
120
121 //_____________________________________________________________________________
122 void AliTPCReconstructor::Reconstruct(AliRawReader* rawReader, TTree* clustersTree) const {
123   // single event local reconstruction
124   // of TPC data starting from raw data
125
126   fClusterer->SetOutput(clustersTree);
127   fClusterer->Digits2Clusters(rawReader);
128 }
129
130 //_____________________________________________________________________________
131 AliTracker* AliTPCReconstructor::CreateTracker() const
132 {
133 // create a TPC tracker
134
135   AliTPCParam* param = GetTPCParam();
136   if (!param) {
137     AliWarning("Loading default TPC parameters !");
138     param = new AliTPCParamSR;
139   }
140   param->ReadGeoMatrices();
141   
142   AliTPCtracker* tracker = new AliTPCtracker(param);
143
144   ParseOptions(tracker);
145
146   return tracker;
147 }
148
149 //_____________________________________________________________________________
150 void AliTPCReconstructor::FillESD(TTree */*digitsTree*/, TTree */*clustersTree*/,
151                                   AliESDEvent* /*esd*/) const
152 {
153 // make PID
154 /*  Now done in AliESDpid
155   Double_t parTPC[] = {50., 0.07, 5.};  // MIP nnormalized to channel 50 -MI
156   AliTPCpidESD tpcPID(parTPC);
157   tpcPID.MakePID(esd);
158 */
159 }
160
161
162 //_____________________________________________________________________________
163 AliTPCParam* AliTPCReconstructor::GetTPCParam() const
164 {
165 // get the TPC parameters
166
167   AliTPCParam* param = AliTPCcalibDB::Instance()->GetParameters();
168
169   return param;
170 }
171
172 //_____________________________________________________________________________
173 void AliTPCReconstructor::SetSplinesFromOADB(const char* tmplt, AliESDpid *esdPID)
174 {
175   //
176   //  load splines from the OADB using 'template'
177   //
178
179   // only load splines if not already set
180   if (!fArrSplines) {
181     fArrSplines=new TObjArray(Int_t(AliPID::kSPECIES));
182     fArrSplines->SetOwner();
183     TString stemplate(tmplt);
184
185     TString fileNamePIDresponse("$ALICE_ROOT/OADB/COMMON/PID/data/TPCPIDResponse.root");
186     TFile f(fileNamePIDresponse.Data());
187
188     TObjArray *arrPidResponseMaster=0x0;
189
190     if (f.IsOpen() && !f.IsZombie()){
191       arrPidResponseMaster=dynamic_cast<TObjArray*>(f.Get("TPCPIDResponse"));
192     }
193     f.Close();
194
195     if (!arrPidResponseMaster){
196       AliError("PID response array not found, cannot assign proper splines");
197       return;
198     }
199
200     for (Int_t ispec=0; ispec<AliPID::kSPECIES; ++ispec)
201     {
202       Int_t ispec2=ispec;
203       if (ispec==Int_t(AliPID::kMuon)) ispec2=Int_t(AliPID::kPion);
204
205       TString particle=AliPID::ParticleName(ispec2);
206       particle.ToUpper();
207
208       TString splineName;
209       splineName.Form(stemplate.Data(),particle.Data());
210       TObject *spline=arrPidResponseMaster->FindObject(splineName.Data());
211       if (!spline) {
212         AliError(Form("No spline found for '%s'", splineName.Data()));
213         continue;
214       };
215       AliInfo(Form("Adding Response function %d:%s",ispec,splineName.Data()));
216       fArrSplines->AddAt(spline->Clone(), ispec);
217     }    
218     arrPidResponseMaster->Delete();
219     delete arrPidResponseMaster;
220     if (fArrSplines->GetEntries()!=Int_t(AliPID::kSPECIES)) {
221       AliError("Splines not found for all species, cannot use proper PID");
222       delete fArrSplines;
223       fArrSplines=NULL;
224       return;
225     }
226   }
227
228   for (Int_t ispec=0; ispec<AliPID::kSPECIES; ++ispec)
229   {
230     esdPID->GetTPCResponse().SetResponseFunction( (AliPID::EParticleType)ispec, fArrSplines->UncheckedAt(ispec) );
231   }
232
233   esdPID->GetTPCResponse().SetUseDatabase(kTRUE);
234 }
235
236 //_____________________________________________________________________________
237 void AliTPCReconstructor::GetPidSettings(AliESDpid *esdPID)
238 {
239   //
240   // Get TPC pid splines. They should be written to the OCDB during the CPass
241   // the splines themselves are owned by the OCDB object
242   //
243
244   // parse options
245   TString allopt(GetOption());
246   TObjArray *optArray=allopt.Tokenize(";");
247
248   // defines whether the pid was set via a specific option in the rec.C
249   Bool_t pidSetInOptions = kFALSE;
250   
251   for (Int_t iopt=0; iopt<optArray->GetEntriesFast(); ++iopt){
252     if (!optArray->At(iopt)) continue;
253     TString option(static_cast<TObjString*>(optArray->At(iopt))->GetString().Strip(TString::kBoth,' '));
254
255     if (!option.BeginsWith("PID.")) continue;
256
257     // remove 'PID.' identifyer
258     option.Remove(0,4);
259
260     // parse PID type
261     if (option.BeginsWith("Static=")){
262       option.Remove(0,option.First('=')+1);
263       if (option.Contains("LHC13b2_fix_PID")) {
264         esdPID->GetTPCResponse().SetBetheBlochParameters(0.0320981, 19.9768, 2.52666e-16, 2.72123, 6.08092);
265         esdPID->GetTPCResponse().SetMip(53.4968);
266         pidSetInOptions=kTRUE;
267       }
268       
269     } else if (option.BeginsWith("OADB=")) {
270       option.Remove(0,option.First('=')+1);
271       AliInfo(Form("Setting splines From OADB using template: '%s'",option.Data()));
272       SetSplinesFromOADB(option, esdPID);
273       pidSetInOptions=kTRUE;
274     } else if (option.BeginsWith("OCDB=")){
275       option.Remove(0,option.First('=')+1);
276       // not yet implemented
277     }
278     
279   }
280
281   delete optArray;
282
283   //
284   // Initialisation of BB parameters from the OCDB.
285   // They are stored in the AliTPCParam
286   //
287   if (!pidSetInOptions) {
288     AliTPCParam* param = AliTPCcalibDB::Instance()->GetParameters();
289     if (param) {
290       TVectorD *paramBB=param->GetBetheBlochParameters();
291       if (paramBB){
292         esdPID->GetTPCResponse().SetBetheBlochParameters((*paramBB)(0),(*paramBB)(1),(*paramBB)(2),(*paramBB)(3),(*paramBB)(4));
293         AliInfo(Form("Setting BB parameters from OCDB (AliTPCParam): %.2g, %.2g, %.2g, %.2g, %.2g",
294                      (*paramBB)(0),(*paramBB)(1),(*paramBB)(2),(*paramBB)(3),(*paramBB)(4)));
295       } else {
296         AliError("Couldn't get BB parameters from OCDB, the old default values will be used instead");
297       }
298     } else {
299       AliError("Couldn't get TPC parameters");
300     }
301   }
302   
303 /*
304   AliTPCcalibDB * calib = AliTPCcalibDB::Instance();
305   
306   //Get pid splines array
307   TObjArray *arrSplines=calib->GetPidResponse();
308   if (!arrSplines) return;
309   AliTPCPIDResponse &tpcPID=esdPID->GetTPCResponse();
310   tpcPID.SetUseDatabase(kTRUE);
311
312   // check if parametrisations are already set.
313   // since this is uniq for one run, we don't have to reload them
314   if (tpcPID.GetResponseFunction(AliPID::kPion)) return;
315
316   // get the default object
317   TObject *defaultPID=arrSplines->At(AliPID::kUnknown);
318   
319   // loop over all particle species and set the response functions
320   for (Int_t ispec=0; ispec<AliPID::kUnknown; ++ispec){
321     TObject *pidSpline=arrSplines->At(ispec);
322     if (!pidSpline) pidSpline=defaultPID;
323     tpcPID.SetResponseFunction((AliPID::EParticleType)ispec,pidSpline);
324   }
325  */ 
326 }
327
328 //_____________________________________________________________________________
329 void AliTPCReconstructor::ParseOptions( AliTPCtracker* tracker ) const
330 {
331 // parse options from rec.C and set in clusterer and tracker
332   
333   TString option = GetOption();
334   
335   Int_t useHLTClusters = 3;
336
337   if (option.Contains("use")) {
338     
339     AliInfo(Form("Overide TPC RecoParam with option %s",option.Data()));
340     
341     if (option.Contains("useRAW")) {
342       useHLTClusters = 1;
343       if (option.Contains("useRAWorHLT"))
344         useHLTClusters = 2;
345     }
346     else if (option.Contains("useHLT")) {
347       useHLTClusters = 3;
348       if (option.Contains("useHLTorRAW"))
349         useHLTClusters = 4;
350     }
351   }
352   else {
353     const AliTPCRecoParam* param = GetRecoParam();
354     useHLTClusters = param->GetUseHLTClusters();
355   }
356
357   AliInfo(Form("Usage of HLT clusters in TPC reconstruction : %d", useHLTClusters));
358
359   fClusterer->SetUseHLTClusters(useHLTClusters);
360   tracker->SetUseHLTClusters(useHLTClusters);
361
362   return;
363 }