]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGHF/hfe/AliHFEpid.cxx
Updates for TRD HFE analysis
[u/mrichter/AliRoot.git] / PWGHF / hfe / AliHFEpid.cxx
CommitLineData
809a4336 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**************************************************************************/
50685501 15//
16// PID Steering Class
17// Interface to the user task
9bcfd1ab 18// Several strategies for Electron identification implemented.
19// In addition users can combine different detectors or use
20// single detector PID
50685501 21//
22// Authors:
23// Markus Fasel <M.Fasel@gsi.de>
24//
25#include <TAxis.h>
809a4336 26#include <TClass.h>
faee3b18 27#include <TF1.h>
809a4336 28#include <TIterator.h>
29#include <TList.h>
8c1c76e9 30#include <TMath.h>
809a4336 31#include <TObjArray.h>
32#include <TObjString.h>
33#include <TString.h>
34
75d81601 35#include "AliLog.h"
36#include "AliPID.h"
3a72645a 37#include "AliVParticle.h"
809a4336 38
3a72645a 39#include "AliHFEcontainer.h"
809a4336 40#include "AliHFEpid.h"
3a72645a 41#include "AliHFEpidQAmanager.h"
75d81601 42#include "AliHFEpidITS.h"
809a4336 43#include "AliHFEpidTPC.h"
44#include "AliHFEpidTRD.h"
45#include "AliHFEpidTOF.h"
c2690925 46#include "AliHFEpidEMCAL.h"
809a4336 47#include "AliHFEpidMC.h"
8c1c76e9 48#include "AliHFEpidBayes.h"
3a72645a 49#include "AliHFEvarManager.h"
809a4336 50
51ClassImp(AliHFEpid)
52
3a72645a 53const Char_t* AliHFEpid::fgkDetectorName[AliHFEpid::kNdetectorPID + 1] = {
54 "MCPID",
8c1c76e9 55 "BAYESPID",
3a72645a 56 "ITSPID",
57 "TPCPID",
58 "TRDPID",
59 "TOFPID",
e3ae862b 60 "EMCALPID",
3a72645a 61 "UndefinedPID"
62};
63
809a4336 64//____________________________________________________________
65AliHFEpid::AliHFEpid():
e3fc062d 66 TNamed(),
809a4336 67 fEnabledDetectors(0),
3a72645a 68 fNPIDdetectors(0),
69 fVarManager(NULL),
faee3b18 70 fCommonObjects(NULL)
809a4336 71{
72 //
73 // Default constructor
74 //
75 memset(fDetectorPID, 0, sizeof(AliHFEpidBase *) * kNdetectorPID);
3a72645a 76 memset(fDetectorOrder, kUndefined, sizeof(UInt_t) * kNdetectorPID);
8c1c76e9 77 memset(fSortedOrder, 0, sizeof(UInt_t) * kNdetectorPID);
809a4336 78}
79
e3fc062d 80//____________________________________________________________
81AliHFEpid::AliHFEpid(const Char_t *name):
82 TNamed(name, ""),
83 fEnabledDetectors(0),
3a72645a 84 fNPIDdetectors(0),
85 fVarManager(NULL),
e3fc062d 86 fCommonObjects(NULL)
87{
88 //
89 // Default constructor
90 // Create PID objects for all detectors
91 //
92 memset(fDetectorPID, 0, sizeof(AliHFEpidBase *) * kNdetectorPID);
3a72645a 93 memset(fDetectorOrder, kUndefined, sizeof(UInt_t) * kNdetectorPID);
94 memset(fSortedOrder, 0, sizeof(UInt_t) * kNdetectorPID);
95
e3fc062d 96 fDetectorPID[kMCpid] = new AliHFEpidMC("MCPID");
8c1c76e9 97 fDetectorPID[kBAYESpid] = new AliHFEpidBayes("BAYESPID");
3a72645a 98 fDetectorPID[kTPCpid] = new AliHFEpidTPC("TPCPID");
e3fc062d 99 fDetectorPID[kTRDpid] = new AliHFEpidTRD("TRDPID");
100 fDetectorPID[kTOFpid] = new AliHFEpidTOF("TOFPID");
c2690925 101 fDetectorPID[kEMCALpid] = new AliHFEpidEMCAL("EMCALPID");
e3fc062d 102
103}
104
809a4336 105//____________________________________________________________
106AliHFEpid::AliHFEpid(const AliHFEpid &c):
e3fc062d 107 TNamed(c),
809a4336 108 fEnabledDetectors(c.fEnabledDetectors),
3a72645a 109 fNPIDdetectors(c.fNPIDdetectors),
110 fVarManager(c.fVarManager),
faee3b18 111 fCommonObjects(NULL)
809a4336 112{
113 //
114 // Copy Constructor
115 //
116 memset(fDetectorPID, 0, sizeof(AliHFEpidBase *) * kNdetectorPID);
e3fc062d 117 c.Copy(*this);
809a4336 118}
119
120//____________________________________________________________
121AliHFEpid& AliHFEpid::operator=(const AliHFEpid &c){
122 //
123 // Assignment operator
124 //
e3fc062d 125 if(&c != this) c.Copy(*this);
126 return *this;
809a4336 127}
128
129//____________________________________________________________
130AliHFEpid::~AliHFEpid(){
131 //
132 // Destructor
133 //
e3fc062d 134 for(Int_t idet = 0; idet < kNdetectorPID; idet++)
135 if(fDetectorPID[idet]) delete fDetectorPID[idet];
faee3b18 136 ClearCommonObjects();
137}
138
e3fc062d 139//____________________________________________________________
140void AliHFEpid::Copy(TObject &o) const{
141 //
142 // Make copy
143 //
144
145 TNamed::Copy(o);
146 AliHFEpid &target = dynamic_cast<AliHFEpid &>(o);
147 target.ClearCommonObjects();
148
149 target.fEnabledDetectors = fEnabledDetectors;
3a72645a 150 target.fNPIDdetectors = fNPIDdetectors;
151 target.fVarManager = fVarManager;
e3fc062d 152
153 // Copy detector PIDs
154 for(Int_t idet = 0; idet < kNdetectorPID; idet++){
155 //Cleanup pointers in case of assignment
156 if(target.fDetectorPID[idet])
157 delete target.fDetectorPID[idet];
158 if(fDetectorPID[idet])
159 target.fDetectorPID[idet] = dynamic_cast<AliHFEpidBase *>(fDetectorPID[idet]->Clone());
160 }
3a72645a 161 memcpy(target.fDetectorOrder, fDetectorOrder, sizeof(UInt_t) * kNdetectorPID);
162 memcpy(target.fSortedOrder, fSortedOrder, sizeof(UInt_t) * kNdetectorPID);
e3fc062d 163}
164
faee3b18 165//____________________________________________________________
166void AliHFEpid::AddCommonObject(TObject * const o){
167 //
168 // Add common object to the garbage collection
169 //
170 if(!fCommonObjects) fCommonObjects = new TObjArray;
171 fCommonObjects->Add(o);
172}
173
174//____________________________________________________________
175void AliHFEpid::ClearCommonObjects(){
176 //
177 // empty garbage collection
178 //
179 if(fCommonObjects){
180 fCommonObjects->Delete();
181 delete fCommonObjects;
182 fCommonObjects = NULL;
183 }
809a4336 184}
185
c3e32eae 186//____________________________________________________________
187void AliHFEpid::SetDetectorsForAnalysis(TString detectors){
188 //
189 // Set detectors used in Analysis to the position corresponding to their
190 // position in the string
191 // Detectors are separated by ","
192 //
193 TObjArray *detarray = detectors.Tokenize(",");
194 TObjString *detString(NULL);
195 int ndet(0);
196 for(int idet = 0; idet < detarray->GetEntries(); idet++){
197 detString = dynamic_cast<TObjString *>(detarray->At(idet));
198 if(detString) AddDetector(detString->String(), ndet++);
199 }
200 AliDebug(1, Form("%d detectors used in Analysis", ndet));
201}
202
809a4336 203//____________________________________________________________
3a72645a 204void AliHFEpid::AddDetector(TString detector, UInt_t position){
809a4336 205 //
3a72645a 206 // Add Detector in position
809a4336 207 //
3a72645a 208 UInt_t detectorID = kUndefined;
209 detector.ToUpper();
210 if(!detector.CompareTo("MC")) detectorID = kMCpid;
8c1c76e9 211 else if(!detector.CompareTo("BAYES")) detectorID = kBAYESpid;
3a72645a 212 else if(!detector.CompareTo("TPC")) detectorID = kTPCpid;
213 else if(!detector.CompareTo("TRD")) detectorID = kTRDpid;
214 else if(!detector.CompareTo("TOF")) detectorID = kTOFpid;
e3ae862b 215 else if(!detector.CompareTo("EMCAL")) detectorID = kEMCALpid;
3a72645a 216 else AliError("Detector not available");
e3fc062d 217
3a72645a 218 if(detectorID == kUndefined) return;
219 if(IsDetectorOn(detectorID)) return;
220 SwitchOnDetector(detectorID);
221 fDetectorOrder[detectorID] = position;
222 fNPIDdetectors++;
223}
224
225//____________________________________________________________
8c1c76e9 226Bool_t AliHFEpid::InitializePID(Int_t run){
3a72645a 227 //
228 // Initializes the PID object
229 //
230
8c1c76e9 231 if(!TestBit(kDetectorsSorted)) SortDetectors();
809a4336 232 Bool_t status = kTRUE;
233 for(Int_t idet = 0; idet < kNdetectorPID; idet++){
e3fc062d 234 if(!IsDetectorOn(idet)) continue;
809a4336 235 if(fDetectorPID[idet]){
8c1c76e9 236 status &= fDetectorPID[idet]->InitializePID(run);
809a4336 237 if(HasMCData() && status) fDetectorPID[idet]->SetHasMCData();
238 }
239 }
8c1c76e9 240 SetBit(kIsInit);
e3fc062d 241 PrintStatus();
809a4336 242 return status;
243}
244
245//____________________________________________________________
e156c3bb 246Bool_t AliHFEpid::IsSelected(const AliHFEpidObject * const track, AliHFEcontainer *cont, const Char_t *contname, AliHFEpidQAmanager *pidqa){
809a4336 247 //
3a72645a 248 // Select Tracks
809a4336 249 //
3a72645a 250 Bool_t isSelected = kTRUE;
251 AliDebug(1, Form("Particle used for PID, QA available: %s", pidqa ? "Yes" : "No"));
252 for(UInt_t idet = 0; idet < fNPIDdetectors; idet++){
253 AliDebug(2, Form("Using Detector %s\n", SortedDetectorName(idet)));
254 if(TMath::Abs(fDetectorPID[fSortedOrder[idet]]->IsSelected(track, pidqa)) != 11){
255 isSelected = kFALSE;
256 break;
0792aa82 257 }
3a72645a 258 AliDebug(2, "Particlae selected by detector");
259 if(fVarManager && cont){
bf892a6a 260 TString reccontname = contname; reccontname += "Reco";
261 AliDebug(2, Form("Filling container %s", reccontname.Data()));
3a72645a 262 if(fVarManager->IsSignalTrack())
bf892a6a 263 fVarManager->FillContainerStepname(cont, reccontname.Data(), SortedDetectorName(idet));
3a72645a 264 if(HasMCData()){
bf892a6a 265 TString mccontname = contname; mccontname += "MC";
266 AliDebug(2, Form("MC Information available, Filling container %s", mccontname.Data()));
267 if(fVarManager->IsSignalTrack()) {
268 fVarManager->FillContainerStepname(cont, mccontname.Data(), SortedDetectorName(idet), kTRUE);
e3ae862b 269 if(cont->GetCorrelationMatrix("correlationstepafterTOF")){
270 TString tstept("TOFPID");
271 if(!tstept.CompareTo(SortedDetectorName(idet))) {
272 fVarManager->FillCorrelationMatrix(cont->GetCorrelationMatrix("correlationstepafterTOF"));
273 //printf("Step %s\n",(const char*) SortedDetectorName(idet));
274 }
275 }
276 }
3a72645a 277 }
278 // The PID will NOT fill the double counting information
809a4336 279 }
75d81601 280 }
3a72645a 281 return isSelected;
75d81601 282}
283
faee3b18 284//____________________________________________________________
8c1c76e9 285void AliHFEpid::SortDetectors(){
286 //
287 // Make sorted list of detectors
288 //
289 if(TestBit(kDetectorsSorted)) return; // Don't sort detectors when they are already sorted
290 TMath::Sort(static_cast<UInt_t>(kNdetectorPID), fDetectorOrder, fSortedOrder, kFALSE);
291 SetBit(kDetectorsSorted);
292}
293
294//____________________________________________________________
295void AliHFEpid::SetPIDResponse(const AliPIDResponse * const pid){
faee3b18 296 //
297 // Set ESD PID to the Detector PID objects
298 //
299 for(Int_t idet = 0; idet < kNdetectorPID; idet++){
8c1c76e9 300 if(fDetectorPID[idet]) fDetectorPID[idet]->SetPIDResponse(pid);
faee3b18 301 }
302}
303
809a4336 304//____________________________________________________________
8c1c76e9 305const AliPIDResponse *AliHFEpid::GetPIDResponse() const {
0792aa82 306 //
8c1c76e9 307 // Return PID response function
0792aa82 308 //
8c1c76e9 309 const AliPIDResponse *response = NULL;
3a72645a 310 for(Int_t idet = 0; idet < kNdetectorPID; idet++){
8c1c76e9 311 if(fDetectorPID[idet]){
312 response = fDetectorPID[idet]->GetPIDResponse();
313 break;
314 }
315 }
316 return response;
0792aa82 317}
318
319//____________________________________________________________
3a72645a 320void AliHFEpid::ConfigureTPCasymmetric(Double_t pmin, Double_t pmax, Double_t sigmamin, Double_t sigmamax){
0792aa82 321 //
322 // TPC alone, symmetric 3 sigma cut and asymmetric sigma cut in the momentum region between 2GeV/c and 10 GeV/c and sigma between -1 and 100
323 //
e3fc062d 324 AliHFEpidTPC *pid = dynamic_cast<AliHFEpidTPC *>(fDetectorPID[kTPCpid]);
bf892a6a 325 if(pid){
326 pid->SetTPCnSigma(3);
327 pid->SetAsymmetricTPCsigmaCut(pmin, pmax, sigmamin, sigmamax);
328 }
0792aa82 329}
330
331//____________________________________________________________
3a72645a 332void AliHFEpid::ConfigureTPCrejectionSimple(){
0792aa82 333 //
334 // TPC alone, symmetric 3 sigma cut and 2 - -100 sigma pion rejection
335 //
e3fc062d 336 AliHFEpidTPC *pid = dynamic_cast<AliHFEpidTPC *>(fDetectorPID[kTPCpid]);
bf892a6a 337 if(pid){
338 pid->SetTPCnSigma(3);
339 pid->SetRejectParticle(AliPID::kPion, 0., -100., 10., 1.);
340 }
0792aa82 341}
342
343//____________________________________________________________
e156c3bb 344void AliHFEpid::ConfigureTOF(Float_t TOFCut){
9bcfd1ab 345 //
e156c3bb 346 // Set Number of sigmas for TOF PID
9bcfd1ab 347 //
e3fc062d 348 AliHFEpidTOF *tofpid = dynamic_cast<AliHFEpidTOF *>(fDetectorPID[kTOFpid]);
c2690925 349 if(tofpid) tofpid->SetTOFnSigma(TOFCut);
e156c3bb 350}
351
352//____________________________________________________________
353void AliHFEpid::ConfigureTPCcentralityCut(Int_t centralityBin, const char *lowerCutParam, const Double_t * const params, Float_t upperTPCCut){
354 //
355 // Cofigure centrality dependent cut function for TPC PID
356 //
357 ConfigureTPCcut(centralityBin, lowerCutParam, params, upperTPCCut);
358}
3a72645a 359
e156c3bb 360//____________________________________________________________
361void AliHFEpid::ConfigureTPCdefaultCut(const char *lowerCutParam, const Double_t * const params, Float_t upperTPCCut){
362 //
363 // Cofigure default cut function for TPC PID
364 //
365 ConfigureTPCcut(-1, lowerCutParam, params, upperTPCCut);
366}
367
368//____________________________________________________________
369void AliHFEpid::ConfigureTPCcut(Int_t centralityBin, const char *lowerCutParam, const Double_t * const params, Float_t upperTPCCut){
370 //
371 // Cofigure cut function for TPC PID
372 // if no function parameterizaion is given, then the default one (exponential) is chosen
373 //
374
375 if(HasMCData()) AliInfo("Configuring TPC for MC\n");
376 AliHFEpidTPC *tpcpid = dynamic_cast<AliHFEpidTPC *>(fDetectorPID[kTPCpid]);
faee3b18 377 //TF1 *upperCut = new TF1("upperCut", "[0] * TMath::Exp([1]*x)", 0, 20);
e156c3bb 378 TF1 *upperCut = new TF1(Form("upperCut%s", centralityBin < 0 ? "Default" : Form("Bin%d", centralityBin)), "[0]", 0, 20); // Use constant upper cut
379 TF1 *lowerCut = new TF1(Form("lowerCut%s", centralityBin < 0 ? "Default" : Form("Bin%d", centralityBin)), lowerCutParam == NULL ? "[0] * TMath::Exp([1]*x) + [2]": lowerCutParam, 0, 20);
c2690925 380
381 upperCut->SetParameter(0, upperTPCCut); // pp
382
e3ae862b 383 if(params){
e156c3bb 384 for(Int_t ipar = 0; ipar < lowerCut->GetNpar(); ipar++)
385 {
386 lowerCut->SetParameter(ipar, params[ipar]);
387 // printf("printout %i %s %f \n", centralityBin, lowerCutParam, params[ipar]);
388 }
e3ae862b 389 } else {
390 // Set default parameterization
e156c3bb 391 if(HasMCData()) lowerCut->SetParameter(0, -2.5);
392 else lowerCut->SetParameter(0, -4.03); //pp
c2690925 393 lowerCut->SetParameter(1, -0.22); // pp
c2690925 394
e3ae862b 395 if(HasMCData()) lowerCut->SetParameter(2, -2.2);
c2690925 396 else lowerCut->SetParameter(2, 0.92); //pp
e3ae862b 397 }
c2690925 398
399
bf892a6a 400 if(tpcpid){
401 tpcpid->SetTPCnSigma(2);
e156c3bb 402 if(centralityBin < 0){
403 tpcpid->SetUpperSigmaCutDefault(upperCut);
404 tpcpid->SetLowerSigmaCutDefault(lowerCut);
405 } else {
406 tpcpid->SetUpperSigmaCutCentrality(upperCut, centralityBin);
407 tpcpid->SetLowerSigmaCutCentrality(lowerCut, centralityBin);
408 }
bf892a6a 409 }
faee3b18 410 AddCommonObject(upperCut);
411 AddCommonObject(lowerCut);
9bcfd1ab 412}
413
8c1c76e9 414//____________________________________________________________
415void AliHFEpid::ConfigureBayesDetectorMask(Int_t detmask){
416 //
417 // Configure detector mask for Bayes PID
418 // if no detector mask is set the default mask is chosen
419 //
420
421 if(HasMCData()) AliInfo("Configuring Bayes for MC\n");
422 AliHFEpidBayes *bayespid = dynamic_cast<AliHFEpidBayes *>(fDetectorPID[kBAYESpid]);
423
424 if(bayespid)
425 {
426 bayespid->SetBayesDetectorMask(detmask);
427 printf("detector mask in pid class %i \n",detmask);
428 }
429
430}
431
432//____________________________________________________________
433void AliHFEpid::ConfigureBayesPIDThreshold(Float_t pidthres){
434 //
435 // Configure pid threshold for Bayes PID
436 // if no threshold is set the default threshold is chosen
437 //
438
439 if(HasMCData()) AliInfo("Configuring Bayes for MC\n");
440 AliHFEpidBayes *bayespid = dynamic_cast<AliHFEpidBayes *>(fDetectorPID[kBAYESpid]);
441
442 if(bayespid)
443 {
444 bayespid->SetBayesPIDThreshold(pidthres);
445 printf("combined pidthreshold %f \n",pidthres);
446 }
447
448}
449
e3fc062d 450//____________________________________________________________
451void AliHFEpid::PrintStatus() const {
452 //
453 // Print the PID configuration
454 //
455 printf("\n%s: Printing configuration\n", GetName());
456 printf("===============================================\n");
e3fc062d 457 printf("PID Detectors: \n");
458 Int_t npid = 0;
8c1c76e9 459 TString detectors[kNdetectorPID] = {"MC", "BAYES", "ITS", "TPC", "TRD", "TOF", "EMCAL"};
e3fc062d 460 for(Int_t idet = 0; idet < kNdetectorPID; idet++){
461 if(IsDetectorOn(idet)){
462 printf("\t%s\n", detectors[idet].Data());
463 npid++;
464 }
465 }
466 if(!npid) printf("\tNone\n");
467 printf("\n");
468}