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