ROOT logo
/* $Id: AliPhysicsSelection.h 35782 2009-10-22 11:54:31Z jgrosseo $ */

#ifndef ALIPHYSICSSELECTION_H
#define ALIPHYSICSSELECTION_H

/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 * See cxx source for full Copyright notice                               */

//-------------------------------------------------------------------------
//                      Implementation of   Class AliPhysicsSelection
// 
// This class selects collision candidates from data runs, applying selection cuts on triggers 
// and background rejection based on the content of the ESD
//
//   Origin: Jan Fiete Grosse-Oetringhaus, CERN
//           Michele Floris, CERN
//-------------------------------------------------------------------------

#include <AliAnalysisCuts.h>
#include <TList.h>
#include "TObjString.h"
#include "AliVEvent.h"
#include "AliLog.h"
#include "AliAnalysisManager.h"

//#define VERBOSE_STAT

class AliESDEvent;
class TH2F;
class TH1F;
class TCollection;
class AliTriggerAnalysis;
class AliAnalysisTaskSE;
class AliOADBPhysicsSelection ;
class AliOADBFillingScheme    ;
class AliOADBTriggerAnalysis;
class TPRegexp;

class AliPhysicsSelection : public AliAnalysisCuts
{
public:

public:
  enum {kStatTriggerClass=1,kStatHWTrig,kStatV0ABG,kStatV0CBG,kStatMB1,kStatMB1Prime,kStatLaserCut,kHVdipCut,kStatFO1,kStatFO2,kStatFO2L1,kStatV0A,kStatV0C, kStatT0BB, kStatT0BG, kStatT0PileUp, kStatZDCA,kStatZDCC,kStatZDCAC,kStatZDCTime,kStatZNABG,kStatZNCBG,kStatV0,kStatV0ZN,kStatOffline,kStatBG, kStatAcceptedPileUp, kStatAccepted};

#ifdef VERBOSE_STAT
  enum {kStatRowAllB=0, kStatRowAllAC, kStatRowAllE, kStatRowBG,kStatRowAcc,kStatRowBGFrac,kStatRowAccFrac,kStatRowErrGoodFrac,kStatRowGoodFrac,kStatRowErrGood,kStatRowGood}; // offset wrt fBGStatOffset
#else
  enum {kStatRowAllB=0, kStatRowAllAC, kStatRowAllE, kStatRowBG, kStatRowAcc,kStatRowGood}; // offset wrt fBGStatOffset
#endif

  enum {kStatIdxAll=0,kStatIdxBin0=1};
  enum ETriggerLogic { kCINT1 = 0, kCMBS2A, kCMBS2C, kCMBAC, kCMBACS2, kHighMultL1 };

  typedef Bool_t (*Bin0Callback_t)(const AliESDEvent *);

  AliPhysicsSelection();
  virtual ~AliPhysicsSelection();
    
  // AliAnalysisCuts interface
  virtual UInt_t GetSelectionMask(const TObject* obj) { return IsCollisionCandidate((const AliESDEvent*) obj); }
  virtual Bool_t IsSelected(TList*) { return kFALSE; }
  virtual Bool_t IsSelected(TObject*)  {return kFALSE;}
    
  Int_t  GetCurrentRun() const {return fCurrentRun;}
  UInt_t IsCollisionCandidate(const AliESDEvent* aEsd);
  Bool_t Initialize(const AliESDEvent* aEsd);
  Bool_t Initialize(Int_t runNumber);
    
  void SetAnalyzeMC(Bool_t flag = kTRUE) { fMC = flag; }
  void SetSkipTriggerClassSelection(Bool_t flag = kTRUE) { fSkipTriggerClassSelection = flag; }
  void SetSkipV0(Bool_t flag=kTRUE) { AliError ("This method is deprecated! Please change the OADB configuration instead") ; fSkipV0 = flag;}
   
  void AddBackgroundIdentification(AliAnalysisCuts*) { AliFatal ("This method is deprecated. Please use the kSPDClsVsTrkBG tag in the OADB configuration instead"); }
    
  virtual void Print(const Option_t* option = "") const;
  virtual Long64_t Merge(TCollection* list);
  void SaveHistograms(const char* folder = 0);
    
  const TList* GetCollisionTriggerClasses() const { return &fCollTrigClasses; }
  const TList* GetBGTriggerClasses()        const { return &fBGTrigClasses; }
  void AddCollisionTriggerClass(const char* className);
  void AddBGTriggerClass(const char* className)       ;
  void SetCustomOADBObjects(AliOADBPhysicsSelection * oadbPS, AliOADBFillingScheme * oadbFS, AliOADBTriggerAnalysis * oadbTA = 0) { fPSOADB = oadbPS; fFillOADB = oadbFS; fTriggerOADB = oadbTA; fUsingCustomClasses = kTRUE;}
  const AliOADBPhysicsSelection * GetOADBPhysicsSelection() const {return fPSOADB;  }
  const AliOADBFillingScheme    * GetOADBFillingScheme()    const {return fFillOADB;}
  const AliOADBTriggerAnalysis  * GetOADBTriggerAnalysis()  const {return fTriggerOADB;}

  Int_t GetBGStatOffset() const { return fBGStatOffset; }


  AliTriggerAnalysis* GetTriggerAnalysis(Int_t i = 0) { return (fTriggerAnalysis.GetEntries() > 0) ? (AliTriggerAnalysis*) fTriggerAnalysis.At(i) : 0; }    
    
  const TH2F* GetStatisticsHistogram(Int_t idx=kStatIdxAll) const { return fHistStatistics[idx]; }
  const TH2F* GetBunchCrossingHistogram() const { return fHistBunchCrossing; }
  virtual TObject *GetStatistics(const Option_t *option) const;
    
  void SetBIFactors(const AliESDEvent * aESD);
  
  void SetUseBXNumbers(Bool_t flag = kTRUE) {fUseBXNumbers = flag;}
  void SetComputeBG   (UInt_t flag = AliVEvent::kMB) {fComputeBG    = flag; if(flag) fUseBXNumbers = flag;}
  void SetUseMuonTriggers(Bool_t) { Printf("ERROR: Use of AliPhysicsSelection::SetUseMuonTriggers is deprecated. Use AliVEvent::kMUON selection instead."); }
  void SetBin0Callback( const char * cb) {fBin0CallBack = cb;} 
  void SetBin0CallbackViaPointer( Bin0Callback_t cb) {fBin0CallBackPointer = cb;}// WARNING: THIS SHOULD NOT BE USED, WILL BE REMOVED SOON
  
  static const char * GetOADBFileName() {   static TString filename; filename.Form("%s/COMMON/PHYSICSSELECTION/data/physicsSelection.root", AliAnalysisManager::GetOADBPath()); return filename.Data();};

  void SetPassName(const TString passName) { fPassName = passName; }
  void DetectPassName();
  Bool_t IsMC() const { return fMC; }
protected:
  UInt_t CheckTriggerClass(const AliESDEvent* aEsd, const char* trigger, Int_t& triggerLogic) const;
  Bool_t EvaluateTriggerLogic(const AliESDEvent* aEsd, AliTriggerAnalysis* triggerAnalysis, const char* triggerLogic, Bool_t offline);
  TH2F * BookHistStatistics(const char * tag) ;
  Int_t GetStatRow(const char * triggerBXClass, UInt_t offlineTriggerType, UInt_t ** rowIDs) const;
  const char * GetTriggerString(TObjString * obj);

  TString fPassName;      // pass name for current run
  Int_t fCurrentRun;      // run number for which the object is initialized
  Bool_t fMC;             // flag if MC is analyzed
  TList fCollTrigClasses; // trigger class identifying collision candidates
  TList fBGTrigClasses;   // trigger classes identifying background events
    
  TList fTriggerAnalysis; // list of offline trigger objects (several are needed to keep the control histograms separate per trigger class)
      
  TH2F* fHistStatistics[2];      // how many events are cut away why {all,bin 0}
  //  TH2F* fHistStatisticsTokens;   // how many events are cut away why (new version, bins for all tokens. Only used tokens are filled)
  TH2F* fHistBunchCrossing;   // histograms of accepted bunch crossing numbers
  TH1F* fHistTriggerPattern;  // Pattern of the individual detectors in the MB1 trigger. Can reveal inconsistencies/inefficiencies in the trigger 
    
  Bool_t fSkipTriggerClassSelection;  // flag that determines if the trigger class selection is skipped
  Bool_t fUsingCustomClasses;         // flag that is set if costum trigger classes are defined
  Bool_t fSkipV0;                     // ignore information from v0

  Float_t fBIFactorA;                 // ratio of interacting over non interacting bunch intensities for beam 1
  Float_t fBIFactorC;                 // ratio of interacting over non interacting bunch intensities for beam 2
  Float_t fBIFactorAC;                // ratio of interacting over non interacting bunch intensities for beam 1&2: 
                                      // for some trigger classes we do not distinguish betweem 1 and 2


  UInt_t fComputeBG; // Switch on computation of background and filling of relevant stat table entries. If you enable this you can only process one run at a time (the relative bunch intensity used to compute this chages from run to run); This is a mask of the trigger types to be used in the selection, as defined in AliVEvent
  Int_t fBGStatOffset; // Offset of the BG statistics computed at the end of the processing. It depends on how many trigger classes you have selected
  Bool_t fUseBXNumbers;	// Explicitely select "good" bunch crossing numbers (exclude pilot, afterpulses and fakes). If you anable this you can only process  runs within the same filling scheme.
  Bool_t fUseMuonTriggers;	// if true, also use the muon triggers
  TString fFillingScheme; // stores the filling scheme of the current run.

  TString fBin0CallBack; // callback used to determine if an event is in the bin0 (name of the task where the callback is implemented);
  Bin0Callback_t fBin0CallBackPointer; //! don't stream this. TO BE REMOVED SOON

  Bool_t fIsPP; // True if processing pp run, false if heavy ion

  AliOADBPhysicsSelection * fPSOADB; // Physics selection OADB object
  AliOADBFillingScheme    * fFillOADB; // Filling scheme OADB object
  AliOADBTriggerAnalysis  * fTriggerOADB; // Trigger analysis OADB object

  TPRegexp* fRegexp; //! regular expression for trigger tokens
  TList* fCashedTokens; //! trigger token lookup list

  ClassDef(AliPhysicsSelection, 16)
    
    private:
  AliPhysicsSelection(const AliPhysicsSelection&);
  AliPhysicsSelection& operator=(const AliPhysicsSelection&);
};

#endif
 AliPhysicsSelection.h:1
 AliPhysicsSelection.h:2
 AliPhysicsSelection.h:3
 AliPhysicsSelection.h:4
 AliPhysicsSelection.h:5
 AliPhysicsSelection.h:6
 AliPhysicsSelection.h:7
 AliPhysicsSelection.h:8
 AliPhysicsSelection.h:9
 AliPhysicsSelection.h:10
 AliPhysicsSelection.h:11
 AliPhysicsSelection.h:12
 AliPhysicsSelection.h:13
 AliPhysicsSelection.h:14
 AliPhysicsSelection.h:15
 AliPhysicsSelection.h:16
 AliPhysicsSelection.h:17
 AliPhysicsSelection.h:18
 AliPhysicsSelection.h:19
 AliPhysicsSelection.h:20
 AliPhysicsSelection.h:21
 AliPhysicsSelection.h:22
 AliPhysicsSelection.h:23
 AliPhysicsSelection.h:24
 AliPhysicsSelection.h:25
 AliPhysicsSelection.h:26
 AliPhysicsSelection.h:27
 AliPhysicsSelection.h:28
 AliPhysicsSelection.h:29
 AliPhysicsSelection.h:30
 AliPhysicsSelection.h:31
 AliPhysicsSelection.h:32
 AliPhysicsSelection.h:33
 AliPhysicsSelection.h:34
 AliPhysicsSelection.h:35
 AliPhysicsSelection.h:36
 AliPhysicsSelection.h:37
 AliPhysicsSelection.h:38
 AliPhysicsSelection.h:39
 AliPhysicsSelection.h:40
 AliPhysicsSelection.h:41
 AliPhysicsSelection.h:42
 AliPhysicsSelection.h:43
 AliPhysicsSelection.h:44
 AliPhysicsSelection.h:45
 AliPhysicsSelection.h:46
 AliPhysicsSelection.h:47
 AliPhysicsSelection.h:48
 AliPhysicsSelection.h:49
 AliPhysicsSelection.h:50
 AliPhysicsSelection.h:51
 AliPhysicsSelection.h:52
 AliPhysicsSelection.h:53
 AliPhysicsSelection.h:54
 AliPhysicsSelection.h:55
 AliPhysicsSelection.h:56
 AliPhysicsSelection.h:57
 AliPhysicsSelection.h:58
 AliPhysicsSelection.h:59
 AliPhysicsSelection.h:60
 AliPhysicsSelection.h:61
 AliPhysicsSelection.h:62
 AliPhysicsSelection.h:63
 AliPhysicsSelection.h:64
 AliPhysicsSelection.h:65
 AliPhysicsSelection.h:66
 AliPhysicsSelection.h:67
 AliPhysicsSelection.h:68
 AliPhysicsSelection.h:69
 AliPhysicsSelection.h:70
 AliPhysicsSelection.h:71
 AliPhysicsSelection.h:72
 AliPhysicsSelection.h:73
 AliPhysicsSelection.h:74
 AliPhysicsSelection.h:75
 AliPhysicsSelection.h:76
 AliPhysicsSelection.h:77
 AliPhysicsSelection.h:78
 AliPhysicsSelection.h:79
 AliPhysicsSelection.h:80
 AliPhysicsSelection.h:81
 AliPhysicsSelection.h:82
 AliPhysicsSelection.h:83
 AliPhysicsSelection.h:84
 AliPhysicsSelection.h:85
 AliPhysicsSelection.h:86
 AliPhysicsSelection.h:87
 AliPhysicsSelection.h:88
 AliPhysicsSelection.h:89
 AliPhysicsSelection.h:90
 AliPhysicsSelection.h:91
 AliPhysicsSelection.h:92
 AliPhysicsSelection.h:93
 AliPhysicsSelection.h:94
 AliPhysicsSelection.h:95
 AliPhysicsSelection.h:96
 AliPhysicsSelection.h:97
 AliPhysicsSelection.h:98
 AliPhysicsSelection.h:99
 AliPhysicsSelection.h:100
 AliPhysicsSelection.h:101
 AliPhysicsSelection.h:102
 AliPhysicsSelection.h:103
 AliPhysicsSelection.h:104
 AliPhysicsSelection.h:105
 AliPhysicsSelection.h:106
 AliPhysicsSelection.h:107
 AliPhysicsSelection.h:108
 AliPhysicsSelection.h:109
 AliPhysicsSelection.h:110
 AliPhysicsSelection.h:111
 AliPhysicsSelection.h:112
 AliPhysicsSelection.h:113
 AliPhysicsSelection.h:114
 AliPhysicsSelection.h:115
 AliPhysicsSelection.h:116
 AliPhysicsSelection.h:117
 AliPhysicsSelection.h:118
 AliPhysicsSelection.h:119
 AliPhysicsSelection.h:120
 AliPhysicsSelection.h:121
 AliPhysicsSelection.h:122
 AliPhysicsSelection.h:123
 AliPhysicsSelection.h:124
 AliPhysicsSelection.h:125
 AliPhysicsSelection.h:126
 AliPhysicsSelection.h:127
 AliPhysicsSelection.h:128
 AliPhysicsSelection.h:129
 AliPhysicsSelection.h:130
 AliPhysicsSelection.h:131
 AliPhysicsSelection.h:132
 AliPhysicsSelection.h:133
 AliPhysicsSelection.h:134
 AliPhysicsSelection.h:135
 AliPhysicsSelection.h:136
 AliPhysicsSelection.h:137
 AliPhysicsSelection.h:138
 AliPhysicsSelection.h:139
 AliPhysicsSelection.h:140
 AliPhysicsSelection.h:141
 AliPhysicsSelection.h:142
 AliPhysicsSelection.h:143
 AliPhysicsSelection.h:144
 AliPhysicsSelection.h:145
 AliPhysicsSelection.h:146
 AliPhysicsSelection.h:147
 AliPhysicsSelection.h:148
 AliPhysicsSelection.h:149
 AliPhysicsSelection.h:150
 AliPhysicsSelection.h:151
 AliPhysicsSelection.h:152
 AliPhysicsSelection.h:153
 AliPhysicsSelection.h:154
 AliPhysicsSelection.h:155
 AliPhysicsSelection.h:156
 AliPhysicsSelection.h:157
 AliPhysicsSelection.h:158
 AliPhysicsSelection.h:159
 AliPhysicsSelection.h:160
 AliPhysicsSelection.h:161
 AliPhysicsSelection.h:162
 AliPhysicsSelection.h:163
 AliPhysicsSelection.h:164
 AliPhysicsSelection.h:165
 AliPhysicsSelection.h:166