1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 ///////////////////////////////////////////////////////////////////////////////
19 // TPC tender: reapply pid on the fly //
21 ///////////////////////////////////////////////////////////////////////////////
24 #include <TObjArray.h>
25 #include <TObjString.h>
31 #include <AliDCSSensor.h>
32 #include <AliGRPObject.h>
33 #include <AliESDpid.h>
35 #include <AliESDEvent.h>
36 #include <AliESDtrack.h>
37 #include <AliESDInputHandler.h>
38 #include <AliAnalysisManager.h>
39 #include <AliSplineFit.h>
41 #include <AliCDBManager.h>
42 #include <AliCDBEntry.h>
43 #include <AliCDBRunRange.h>
44 #include <AliTender.h>
45 #include <AliTPCcalibDButil.h>
48 #include "AliTPCTenderSupply.h"
50 ClassImp(AliTPCTenderSupply)
52 AliTPCTenderSupply::AliTPCTenderSupply() :
57 fGainCorrection(kTRUE),
59 fArrPidResponseMaster(0x0),
69 //_____________________________________________________
70 AliTPCTenderSupply::AliTPCTenderSupply(const char *name, const AliTender *tender) :
71 AliTenderSupply(name,tender),
75 fGainCorrection(kTRUE),
77 fArrPidResponseMaster(0x0),
87 //_____________________________________________________
88 void AliTPCTenderSupply::Init()
91 // Initialise TPC tender
94 AliLog::SetClassDebugLevel("AliTPCTenderSupply",10);
95 AliAnalysisManager *mgr=AliAnalysisManager::GetAnalysisManager();
100 // Check if another detector already created the esd pid object
101 // if not we create it and set it to the ESD input handler
102 fESDpid=fTender->GetESDhandler()->GetESDpid();
104 fESDpid=new AliESDpid;
105 fTender->GetESDhandler()->SetESDpid(fESDpid);
109 //set bethe bloch parameters depending on whether we have MC or real data
111 // for the moment we set the values hardwired. In future they should be stored either in
112 // the OCDB or an equivalent calibration data base
114 Double_t alephParameters[5];
116 alephParameters[0] = 2.15898e+00/50.;
117 alephParameters[1] = 1.75295e+01;
118 alephParameters[2] = 3.40030e-09;
119 alephParameters[3] = 1.96178e+00;
120 alephParameters[4] = 3.91720e+00;
122 // assume data if there is no mc handler
123 if (!mgr->GetMCtruthEventHandler()){
124 alephParameters[0] = 0.0283086/0.97;
125 //alephParameters[0] = 0.0283086;
126 alephParameters[1] = 2.63394e+01;
127 alephParameters[2] = 5.04114e-11;
128 alephParameters[3] = 2.12543e+00;
129 alephParameters[4] = 4.88663e+00;
131 //fESDpid->GetTPCResponse().SetMip(fMip);
132 if (fDebugLevel>0) AliInfo(Form("Use Data parametrisation, Mip set to: %.3f\n",fMip));
133 //fESDpid->GetTPCResponse().SetMip(49.2);
135 //force no gain and P correction in MC
136 fGainCorrection=kFALSE;
138 if (fDebugLevel>0) AliInfo("Use MC parametrisation\n");
141 fESDpid->GetTPCResponse().SetBetheBlochParameters(
142 alephParameters[0],alephParameters[1],alephParameters[2],
143 alephParameters[3],alephParameters[4]);
145 //set detector resolution parametrisation
146 fESDpid->GetTPCResponse().SetSigma(3.79301e-03, 2.21280e+04);
149 //_____________________________________________________
150 void AliTPCTenderSupply::ProcessEvent()
153 // Reapply pid information
156 AliESDEvent *event=fTender->GetEvent();
159 //load gain correction if run has changed
160 if (fTender->RunChanged()){
161 if (fDebugLevel>0) AliInfo(Form("Run Changed (%d)\n",fTender->GetRun()));
162 SetParametrisation();
163 if (fGainCorrection) SetSplines();
167 // get gain correction factor
169 Double_t corrFactor = 1;
170 if (fGainCorrection) corrFactor=GetGainCorrection();
173 // - correct TPC signals
174 // - recalculate PID probabilities for TPC
176 Int_t ntracks=event->GetNumberOfTracks();
177 for(Int_t itrack = 0; itrack < ntracks; itrack++){
178 AliESDtrack *track=event->GetTrack(itrack);
180 track->SetTPCsignal(track->GetTPCsignal()*corrFactor,track->GetTPCsignalSigma(),track->GetTPCsignalN());
181 fESDpid->MakeTPCPID(track);
186 //_____________________________________________________
187 void AliTPCTenderSupply::SetSplines()
190 // Get Gain splines from OCDB
193 AliInfo("Update Gain splines");
196 // Get GPR info for pressure correction
200 AliCDBEntry *entryGRP=fTender->GetCDBManager()->Get("GRP/GRP/Data",fTender->GetRun());
202 AliError("No new GRP entry found");
204 fGRP = (AliGRPObject*)entryGRP->GetObject();
206 if (fDebugLevel>1) AliInfo(Form("GRP entry used: %s\n",entryGRP->GetId().ToString().Data()));
211 //find previous entry from the UserInfo
213 // TTree *tree=((TChain*)fTender->GetInputData(0))->GetTree();
214 AliAnalysisManager*mgr = AliAnalysisManager::GetAnalysisManager();
215 AliAnalysisTaskSE *task = (AliAnalysisTaskSE*)mgr->GetTasks()->First();
216 TTree *tree=((TChain*)task->GetInputData(0))->GetTree();
218 AliError("Tree not found in ESDhandler");
222 TList *userInfo=(TList*)tree->GetUserInfo();
224 AliError("No UserInfo found in tree");
228 TList *cdbList=(TList*)userInfo->FindObject("cdbList");
230 AliError("No cdbList found in UserInfo");
231 if (AliLog::GetGlobalLogLevel()>=AliLog::kError) userInfo->Print();
235 TIter nextCDB(cdbList);
237 while ( (os=(TObjString*)nextCDB()) ){
238 if (!(os->GetString().Contains("TPC/Calib/TimeGain"))) continue;
239 AliCDBId *id=AliCDBId::MakeFromString(os->GetString());
241 AliCDBEntry *entry=fTender->GetCDBManager()->Get(*id);
243 AliError("No previous gain calibration entry found");
247 if (fDebugLevel>1) AliInfo(Form("Used old Gain entry: %s\n",entry->GetId().ToString().Data()));
249 TObjArray *arr=(TObjArray *)entry->GetObject();
251 AliError("Gain Splines array not found in calibration entry");
255 AliSplineFit *fit=(AliSplineFit*)arr->At(0);
257 AliError("Spline fit not found in array");
267 //new gain correction
269 AliCDBEntry *entryNew=fTender->GetCDBManager()->Get("TPC/Calib/TimeGain",fTender->GetRun());
271 AliError("No new gain calibration entry found");
274 if (fDebugLevel>1) AliInfo(Form("Used new Gain entry: %s\n",entryNew->GetId().ToString().Data()));
276 if (entryNew->GetId().GetLastRun()==AliCDBRunRange::Infinity()){
277 if (fDebugLevel>0) AliInfo("Use P correction\n");
281 TObjArray *arrSplines=(TObjArray *)entryNew->GetObject();
283 AliError("Gain Splines array not found in new calibration entry");
287 fGainNew = (AliSplineFit*)arrSplines->At(0);
289 if (!fGainNew) AliError("No recent spline fit object found");
292 //_____________________________________________________
293 Double_t AliTPCTenderSupply::GetGainCorrection()
296 // Calculate gain correction factor
298 AliESDEvent *event=fTender->GetEvent();
299 UInt_t time=event->GetTimeStamp();
306 //first correction for the eval
307 // needs to be removed when the fix is in AliROOT and
308 // the production was done with EvalGraphConst
310 if (fTender->GetRun()<=138154||fTender->GetRun()==138197){
311 Double_t valDefault = fGainOld->Eval(time);
312 Double_t valConst = AliTPCcalibDButil::EvalGraphConst(fGainOld, time);
313 gain = valDefault/valConst;
316 gain *= AliTPCcalibDButil::EvalGraphConst(fGainOld,time)/AliTPCcalibDButil::EvalGraphConst(fGainNew,time);
320 //If there is only the default calibration, at least apply correction for pressure
323 Double_t pressure=fGRP->GetCavernAtmosPressure()->GetValue(time);
324 // gain=fGainOld->Eval(time)/(7.03814-0.00459798*pressure)/49.53*fMip;
325 // gain=fGainOld->Eval(time)/(7.03814-0.00459798*pressure)/51.51*fMip;
326 gain=AliTPCcalibDButil::EvalGraphConst(fGainOld,time)/(7.03814-0.00459798*pressure)/51.51*fMip;
333 //_____________________________________________________
334 void AliTPCTenderSupply::SetParametrisation()
337 // Change BB parametrisation for current run
340 //Get CDB Entry with pid response parametrisations
341 AliCDBEntry *pidCDB=fTender->GetCDBManager()->Get("TPC/Calib/PidResponse",fTender->GetRun());
343 fArrPidResponseMaster=(TObjArray*)pidCDB->GetObject();
346 //Get the current file to check the reconstruction pass (UGLY, but not stored in ESD... )
347 AliESDInputHandler *esdIH = dynamic_cast<AliESDInputHandler*> (fTender->GetESDhandler());
349 TTree *tree= (TTree*)esdIH->GetTree();
350 TFile *file= (TFile*) tree->GetCurrentFile();
352 AliError("File not found, not changing parametrisation");
356 Int_t run=fTender->GetRun();
357 AliAnalysisManager *mgr=AliAnalysisManager::GetAnalysisManager();
358 Double_t alephParameters[5]={0,0,0,0,0};
360 //find the period by run number (UGLY, but not stored in ESD... )
362 if (run>=114737&&run<=117223) period="LHC10B";
363 else if (run>=118503&&run<=121040) period="LHC10C";
364 else if (run>=122195&&run<=126437) period="LHC10D";
365 else if (run>=127719&&run<=130850) period="LHC10E";
366 else if (run>=133004&&run<=135029) period="LHC10F";
367 else if (run>=135654&&run<=136377) period="LHC10G";
368 else if (run>=136851&&run<=139517) period="LHC10H";
369 else if (run>=139699) period="LHC11A";
371 //find pass from file name (UGLY, but not stored in ESD... )
372 TString fileName(file->GetName());
374 if (fileName.Contains("/pass1")) {
376 } else if (fileName.Contains("/pass2")) {
381 TString beamtype=fTender->GetEvent()->GetBeamType();
382 if (beamtype.IsNull()||beamtype.Contains("No Beam")) beamtype="p-p";
384 beamtype.ReplaceAll("-","");
387 // Set default parametrisations for data and MC
389 Bool_t isMC=mgr->GetMCtruthEventHandler();
392 alephParameters[0] = 2.15898e+00/50.;
393 alephParameters[1] = 1.75295e+01;
394 alephParameters[2] = 3.40030e-09;
395 alephParameters[3] = 1.96178e+00;
396 alephParameters[4] = 3.91720e+00;
399 //data parametrisation
402 //use defaut data parametrisation in case no other will be selected
403 alephParameters[0] = 0.0283086/0.97;
404 alephParameters[1] = 2.63394e+01;
405 alephParameters[2] = 5.04114e-11;
406 alephParameters[3] = 2.12543e+00;
407 alephParameters[4] = 4.88663e+00;
409 fESDpid->GetTPCResponse().SetSigma(3.79301e-03, 2.21280e+04);
415 if (run>=114737&&run<=117223){
417 } else if (run>=118503&&run<=121040) {
419 } else if (run>=122195){
421 // last run in LHC10d: &&run<126437
422 alephParameters[0] = 1.63246/50.;
423 alephParameters[1] = 2.20028e+01;
424 alephParameters[2] = TMath::Exp(-2.48879e+01);
425 alephParameters[3] = 2.39804e+00;
426 alephParameters[4] = 5.12090e+00;
429 fESDpid->GetTPCResponse().SetSigma(2.30176e-02, 5.60422e+02);
433 if ( beamtype == "PBPB" ){
434 AliInfo("BETHE-BLOCH parametrization for PbPb !!!!!!!!!!!!!!!!!!!!!!\n");
436 alephParameters[0] = 1.25202/50.; //was 1.79571/55.;
437 alephParameters[1] = 2.74992e+01; //was 22.0028;
438 alephParameters[2] = TMath::Exp(-3.31517e+01); //was1.55354e-11;
439 alephParameters[3] = 2.46246; //was 2.39804;
440 alephParameters[4] = 6.78938; //was 5.1209;
444 fESDpid->GetTPCResponse().SetBetheBlochParameters(
445 alephParameters[0],alephParameters[1],alephParameters[2],
446 alephParameters[3],alephParameters[4]);
449 TString datatype="DATA";
450 //in case of mc pass is per default 1
457 //set the new parametrisation
460 if (fArrPidResponseMaster){
462 //for MC don't use period information
463 if (isMC) period="[A-Z0-9]*";
464 //pattern for the default entry (valid for all particles)
465 TPRegexp reg(Form("TSPLINE3_%s_([A-Z]*)_%s_PASS%d_%s_MEAN",datatype.Data(),period.Data(),pass,beamtype.Data()));
467 //loop over entries and filter them
468 for (Int_t iresp=0; iresp<fArrPidResponseMaster->GetEntriesFast();++iresp){
469 TObject *responseFunction=fArrPidResponseMaster->At(iresp);
470 TString responseName=responseFunction->GetName();
472 if (!reg.MatchB(responseName)) continue;
474 TObjArray *arr=reg.MatchS(responseName);
475 TString particleName=arr->At(1)->GetName();
477 if (particleName.IsNull()) continue;
478 if (particleName=="ALL") grAll=responseFunction;
481 for (Int_t ispec=0; ispec<AliPID::kSPECIES; ++ispec){
482 TString particle=AliPID::ParticleName(ispec);
484 if ( particle == particleName ){
485 //test if there is already a function set. If yes, cleanup
486 TObject *old=const_cast<TObject*>(fESDpid->GetTPCResponse().GetResponseFunction((AliPID::EParticleType)ispec));
488 fESDpid->GetTPCResponse().SetResponseFunction((AliPID::EParticleType)ispec,responseFunction);
489 fESDpid->GetTPCResponse().SetUseDatabase(kTRUE);
490 AliInfo(Form("Adding graph: %d - %s\n",ispec,responseFunction->GetName()));
497 //set default response function to all particles which don't have a specific one
499 for (Int_t ispec=0; ispec<AliPID::kSPECIES; ++ispec){
500 if (!fESDpid->GetTPCResponse().GetResponseFunction((AliPID::EParticleType)ispec)){
501 fESDpid->GetTPCResponse().SetResponseFunction((AliPID::EParticleType)ispec,grAll);
502 AliInfo(Form("Adding graph: %d - %s\n",ispec,grAll->GetName()));