ROOT logo
//-*- Mode: C++ -*-
// $Id$

//* This file is property of and copyright by the ALICE Project        * 
//* ALICE Experiment at CERN, All rights reserved.                     *
//* See cxx source for full Copyright notice                           *

/// @file   AliDxHFECorrelation.h
/// @author Sedat Altinpinar, Hege Erdal, Matthias Richter
/// @date   2012-04-25
/// @brief  Worker class for D0-HF electron correlation
///

#ifndef ALIDXHFECORRELATION_H
#define ALIDXHFECORRELATION_H

#include "TNamed.h"

class TH1;
class THnSparse;
class TObject;
class TList;
class AliHFCorrelator;
class AliVParticle;
class TObjArray;
class AliVEvent;
class AliAnalysisCuts;

class AliDxHFECorrelation : public TNamed {
 public:
  /// default constructor
  AliDxHFECorrelation(const char* name=NULL);
  /// destructor
  virtual ~AliDxHFECorrelation();

  // event control histogram
  enum {
    kEventsAll = 0, // all events
    kEventsSel,     // selected events
    kEventsTriggered,     // events with D0s
    kEventsCorrelated,     // events with correlated D0s
    kNEventControlLabels
  };

  // Enums for setting trigger particle type
  enum {
    kD=0,       
    kElectron=1
  } ;

  // init
  int Init(const char* arguments="");

  // parse argument string
  int ParseArguments(const char* arguments);

  /// fill histograms from particles
  int Fill(const TObjArray* candidatesD0, const TObjArray* candidatesElectron, const AliVEvent* pEvent);

  /// histogram event properties
  virtual int HistogramEventProperties(int bin);
  virtual THnSparse* DefineTHnSparse();
  virtual int FillParticleProperties(AliVParticle* tr, AliVParticle* as, Double_t* data, int dimension) const;

  /// create control THnSparse
  THnSparse* CreateControlTHnSparse(const char* name,
				    int thnSize,
				    int* thnBins,
				    double* thnMin,
				    double* thnMax,
				    const char** binLabels) const;

  /// overloaded from TObject: cleanup
  virtual void Clear(Option_t * option ="");
  /// overloaded from TObject: print info
  virtual void Print(Option_t *option="") const;
  /// overloaded from TObject: draw histograms
  virtual void Draw(Option_t *option="");
  /// overloaded from TObject: find object by name
  virtual TObject* FindObject(const char *name) const;
  /// overloaded from TObject: find object by pointer
  virtual TObject* FindObject(const TObject *obj) const;
  /// overloaded from TObject: save to file
  virtual void     SaveAs(const char *filename="",Option_t *option="") const; // *MENU*

  virtual void SetCuts(AliAnalysisCuts* cuts) {fCuts=cuts;}
  virtual void SetUseMC(Bool_t useMC){fUseMC=useMC;}
  //void SetUseEventMixing(Bool_t useMixing) {fUseEventMixing=useMixing;}
  //void SetSystem(Bool_t system){fSystem=system;}
  //void SetPhiRange(Double_t min, Double_t max){fMinPhi=min; fMaxPhi=max;}
  // TODO: SetEventType only needed for MC. How to avoid this?
  virtual void SetEventType(int type){fEventType=type;}

  Bool_t GetUseMC() const {return fUseMC;}
  const TList* GetControlObjects() const {return fControlObjects;}
  Double_t GetMinPhi() const {return fMinPhi;}
  Double_t GetMaxPhi() const {return fMaxPhi;}
  Double_t GetDeltaPhi() const {return fDeltaPhi;}
  Double_t GetDeltaEta() const {return fDeltaEta;}
  inline int GetDimTHnSparse() const {return fDimThn;}
  Int_t GetTriggerParticleType() const {return fTriggerParticleType;}

  void EventMixingChecks(const AliVEvent* pEvent);

  AliDxHFECorrelation& operator+=(const AliDxHFECorrelation& other);

  // Probably not needed anymore, since code was changed to THnSparse
  // but keep here in case we need it later
  enum {
    khD0pT,         // TH1F
    khD0Phi,        // TH1F
    khD0Eta,        // TH1F
    khElectronpT,   // TH1F
    khElectronPhi,  // TH1F
    khElectronEta,  // TH1F
    kNofHistograms
  };

 protected:
  /// add control object to list, the base class becomes owner of the object
  int AddControlObject(TObject* pObj);

 /// set the dimension of THn and allocate filling array
  void InitTHnSparseArray(int dimension) {
    fDimThn=dimension; 
    if (fCorrArray) delete[] fCorrArray; fCorrArray=NULL;
    if (dimension>0) fCorrArray=new Double_t[dimension];
  }

  inline Double_t* ParticleProperties() const {return fCorrArray;}

 private:
  /// copy constructor
  AliDxHFECorrelation(const AliDxHFECorrelation& other);
  /// assignment operator
  AliDxHFECorrelation& operator=(const AliDxHFECorrelation& other);

  // 2012-09-18: when running on Grid the histograms were empty. We encountered
  // messages "cannot create object of class TH1" when writing the analysis manager
  // to file for Grid analysis.
  // This class had a TH1 member marked to be saved, the object though was part of
  // a list, also a member of the class. Root has a problem with the schema info
  // in that case.
  // Solved by marking fhEventControlCorr as transient, the cause, though, is not
  // understood

  TObjArray* fHistograms;        //  the histograms - for the moment not in use. 
  TList* fControlObjects;        //  list of control objects
  THnSparse* fCorrProperties;    //  the Correlation properties of selected particles
  TH1* fhEventControlCorr;       //! event control histogram (saved via control object list)
  AliAnalysisCuts *fCuts;        //! Cuts 
  Bool_t fUseMC;                 // use MC info
  AliHFCorrelator *fCorrelator;  //! object for correlations
  Bool_t fUseEventMixing;        // Run Event Mixing analysis
  Short_t fSystem;               // Which system pp/PbPb
  Double_t fMinPhi;              // Holds min phi
  Double_t fMaxPhi;              // Holds maxa phi
  Double_t fDeltaPhi;            // Delta Phi  
  Double_t fDeltaEta;            // Delta Eta
  int fDimThn;                   // Holds dim of THnSparse
  Double_t* fCorrArray;          //! filling array for THnSparse
  Int_t fEventType;              // Event type. Only needed for MC (fix)
  Int_t fTriggerParticleType;    // Which particle to trigger on

  static const char* fgkEventControlBinNames[];

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