TPC module
[u/mrichter/AliRoot.git] / TPC / TPCrec / AliTPCReconstructor.cxx
CommitLineData
59697224 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
1598ba75 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
59697224 32///////////////////////////////////////////////////////////////////////////////
33// //
34// class for TPC reconstruction //
35// //
36///////////////////////////////////////////////////////////////////////////////
37
a7b1d798 38#include <TObject.h>
39#include <TString.h>
40#include <TObjString.h>
41#include <TObjArray.h>
42#include <TFile.h>
59697224 43
a7b1d798 44#include <AliLog.h>
45#include <AliPID.h>
46#include <AliESDpid.h>
47#include <AliTPCPIDResponse.h>
59697224 48#include "AliTPCReconstructor.h"
49#include "AliRunLoader.h"
50#include "AliRun.h"
38e6e547 51#include "AliRawReader.h"
829455ad 52#include "AliTPCclusterer.h"
53#include "AliTPCtracker.h"
4fb6310b 54#include "AliTPCParam.h"
90c7886e 55#include "AliTPCParamSR.h"
3d37b790 56#include "AliTPCcalibDB.h"
7bab76cf 57#include "AliTracker.h"
58#include "AliMagF.h"
59697224 59
60ClassImp(AliTPCReconstructor)
61
194b0609 62
08542a9f 63Int_t AliTPCReconstructor::fgStreamLevel = 0; // stream (debug) level
e2a1f213 64AliTPCAltroEmulator * AliTPCReconstructor::fAltroEmulator=0; // ALTRO emulator
194b0609 65
3464c690 66AliTPCReconstructor::AliTPCReconstructor():
67AliReconstructor(),
3deecc7e 68fClusterer(NULL),
69fArrSplines(NULL)
3464c690 70{
194b0609 71 //
72 // default constructor
73 //
7a9e557b 74 //
75 //
7bab76cf 76 AliTPCcalibDB * calib = AliTPCcalibDB::Instance();
745b6db9 77 const AliMagF * field = (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
0a997b33 78 calib->SetExBField(field);
3464c690 79 AliTPCParam* param = GetTPCParam();
80 if (!param) {
81 AliWarning("Loading default TPC parameters !");
82 param = new AliTPCParamSR;
83 }
829455ad 84 fClusterer = new AliTPCclusterer(param);
194b0609 85}
86
0ffd2ae1 87AliTPCReconstructor::AliTPCReconstructor(const AliTPCReconstructor& /*rec*/):
88AliReconstructor(),
3deecc7e 89fClusterer(NULL),
90fArrSplines(NULL)
0ffd2ae1 91{
92 //
93 // Dummy copu constructor
94 //
95}
96
97AliTPCReconstructor& AliTPCReconstructor::operator=(const AliTPCReconstructor&){
98 //
99 // dummy operator
100 //
101 return *this;
102}
103
3464c690 104//_____________________________________________________________________________
105AliTPCReconstructor::~AliTPCReconstructor()
106{
3464c690 107 if (fClusterer) delete fClusterer;
3deecc7e 108 delete fArrSplines;
b1e5634c 109 delete AliTPCcalibDB::Instance();
3464c690 110}
194b0609 111
59697224 112//_____________________________________________________________________________
3464c690 113void 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//_____________________________________________________________________________
3464c690 122void AliTPCReconstructor::Reconstruct(AliRawReader* rawReader, TTree* clustersTree) const {
123 // single event local reconstruction
124 // of TPC data starting from raw data
3464c690 125
126 fClusterer->SetOutput(clustersTree);
127 fClusterer->Digits2Clusters(rawReader);
128}
129
130//_____________________________________________________________________________
d76c31f4 131AliTracker* AliTPCReconstructor::CreateTracker() const
59697224 132{
133// create a TPC tracker
134
3464c690 135 AliTPCParam* param = GetTPCParam();
90c7886e 136 if (!param) {
137 AliWarning("Loading default TPC parameters !");
138 param = new AliTPCParamSR;
139 }
4fb6310b 140 param->ReadGeoMatrices();
1598ba75 141
829455ad 142 AliTPCtracker* tracker = new AliTPCtracker(param);
1598ba75 143
144 ParseOptions(tracker);
145
146 return tracker;
59697224 147}
148
149//_____________________________________________________________________________
d76c31f4 150void AliTPCReconstructor::FillESD(TTree */*digitsTree*/, TTree */*clustersTree*/,
937a076a 151 AliESDEvent* /*esd*/) const
59697224 152{
153// make PID
10d100d4 154/* Now done in AliESDpid
83afd539 155 Double_t parTPC[] = {50., 0.07, 5.}; // MIP nnormalized to channel 50 -MI
59697224 156 AliTPCpidESD tpcPID(parTPC);
157 tpcPID.MakePID(esd);
10d100d4 158*/
59697224 159}
160
161
162//_____________________________________________________________________________
3464c690 163AliTPCParam* AliTPCReconstructor::GetTPCParam() const
59697224 164{
165// get the TPC parameters
166
3464c690 167 AliTPCParam* param = AliTPCcalibDB::Instance()->GetParameters();
3d37b790 168
6d75e4b6 169 return param;
59697224 170}
1598ba75 171
a7b1d798 172//_____________________________________________________________________________
173void AliTPCReconstructor::SetSplinesFromOADB(const char* tmplt, AliESDpid *esdPID)
174{
175 //
176 // load splines from the OADB using 'template'
177 //
178
3deecc7e 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 }
a7b1d798 226 }
227
a7b1d798 228 for (Int_t ispec=0; ispec<AliPID::kSPECIES; ++ispec)
229 {
3deecc7e 230 esdPID->GetTPCResponse().SetResponseFunction( (AliPID::EParticleType)ispec, fArrSplines->UncheckedAt(ispec) );
a7b1d798 231 }
232
3deecc7e 233 esdPID->GetTPCResponse().SetUseDatabase(kTRUE);
a7b1d798 234}
235
236//_____________________________________________________________________________
237void 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
4e087e75 248 // defines whether the pid was set via a specific option in the rec.C
249 Bool_t pidSetInOptions = kFALSE;
250
a7b1d798 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);
4e087e75 266 pidSetInOptions=kTRUE;
a7b1d798 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);
4e087e75 273 pidSetInOptions=kTRUE;
a7b1d798 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
4e087e75 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
a7b1d798 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}
1598ba75 327
328//_____________________________________________________________________________
829455ad 329void AliTPCReconstructor::ParseOptions( AliTPCtracker* tracker ) const
1598ba75 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
c08dc6e5 341 if (option.Contains("useRAW")) {
1598ba75 342 useHLTClusters = 1;
c08dc6e5 343 if (option.Contains("useRAWorHLT"))
344 useHLTClusters = 2;
345 }
346 else if (option.Contains("useHLT")) {
1598ba75 347 useHLTClusters = 3;
c08dc6e5 348 if (option.Contains("useHLTorRAW"))
349 useHLTClusters = 4;
350 }
1598ba75 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}