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