From 93fcaf9f02feda85ecdc639855a215c9918dee03 Mon Sep 17 00:00:00 2001 From: prino Date: Thu, 10 May 2012 13:28:41 +0000 Subject: [PATCH] adding control histograms to particle selection class --- .../AliAnalysisTaskDxHFEParticleSelection.cxx | 17 +++ .../AliDxHFEParticleSelection.cxx | 119 +++++++++++++++++- .../correlationHF/AliDxHFEParticleSelection.h | 27 +++- .../AliDxHFEParticleSelectionD0.cxx | 67 +++++++++- .../AliDxHFEParticleSelectionD0.h | 10 ++ 5 files changed, 230 insertions(+), 10 deletions(-) diff --git a/PWGHF/correlationHF/AliAnalysisTaskDxHFEParticleSelection.cxx b/PWGHF/correlationHF/AliAnalysisTaskDxHFEParticleSelection.cxx index 32f84674a30..68998335470 100644 --- a/PWGHF/correlationHF/AliAnalysisTaskDxHFEParticleSelection.cxx +++ b/PWGHF/correlationHF/AliAnalysisTaskDxHFEParticleSelection.cxx @@ -25,12 +25,14 @@ #include "AliAnalysisTaskDxHFEParticleSelection.h" #include "AliDxHFEParticleSelection.h" +#include "AliDxHFEParticleSelectionD0.h" #include "AliAnalysisManager.h" #include "AliLog.h" #include "AliESDInputHandler.h" #include "TChain.h" #include "TSystem.h" #include "TFile.h" +#include /// ROOT macro for the implementation of ROOT specific class methods ClassImp(AliAnalysisTaskDxHFEParticleSelection) @@ -83,6 +85,10 @@ void AliAnalysisTaskDxHFEParticleSelection::UserCreateOutputObjects() fOutput = new TList; fOutput->SetOwner(); + + fSelector=new AliDxHFEParticleSelectionD0; + fSelector->InitControlObjects(); + fOutput->Add(fSelector); // all tasks must post data once for all outputs PostData(1, fOutput); @@ -105,6 +111,17 @@ void AliAnalysisTaskDxHFEParticleSelection::UserExec(Option_t* /*option*/) return; } + std::auto_ptr selectedTracks(fSelector->Select(pEvent)); + // TODO: use the array of selected track for something, right now + // only the control histograms of the selection class are filled + // note: the pointer is deleted automatically once the scope is left + // if the array should be published, the auto pointer must be released + // first, however some other cleanup will be necessary in that case + // probably a clone with a reduced AliVParticle implementation is + // appropriate. + if (selectedTracks.get()) { + } + PostData(1, fOutput); } diff --git a/PWGHF/correlationHF/AliDxHFEParticleSelection.cxx b/PWGHF/correlationHF/AliDxHFEParticleSelection.cxx index 9a6fcc170a3..899da3c1cd7 100644 --- a/PWGHF/correlationHF/AliDxHFEParticleSelection.cxx +++ b/PWGHF/correlationHF/AliDxHFEParticleSelection.cxx @@ -24,18 +24,31 @@ /// #include "AliDxHFEParticleSelection.h" +#include "AliLog.h" #include "AliVEvent.h" #include "AliVParticle.h" #include "TObjArray.h" +#include "TList.h" +#include "TMath.h" +#include "TH1D.h" +#include "THnSparse.h" +#include "TFile.h" +#include #include +#include + +using namespace std; /// ROOT macro for the implementation of ROOT specific class methods ClassImp(AliDxHFEParticleSelection) -AliDxHFEParticleSelection::AliDxHFEParticleSelection(const char* opt) - : TObject() +AliDxHFEParticleSelection::AliDxHFEParticleSelection(const char* name, const char* opt) + : TNamed(name?name:"AliDxHFEParticleSelection", name?name:"AliDxHFEParticleSelection") , fOption(opt) , fSelectedTracks(NULL) + , fControlObjects(NULL) + , fhEventControl(NULL) + , fhTrackControl(NULL) { // constructor // @@ -49,6 +62,52 @@ AliDxHFEParticleSelection::~AliDxHFEParticleSelection() // destructor if (fSelectedTracks) delete fSelectedTracks; fSelectedTracks=NULL; + if (fControlObjects) delete fControlObjects; + fControlObjects=NULL; +} + +int AliDxHFEParticleSelection::InitControlObjects() +{ + /// init the control objects, can be overloaded by childs which should + /// call AliDxHFEParticleSelection::InitControlObjects() explicitly + std::auto_ptr hEventControl(new TH1D("hEventControl", "hEventControl", 10, 0, 10)); + std::auto_ptr hTrackControl(new TH1D("hTrackControl", "hTrackControl", 10, 0, 10)); + + fhEventControl=hEventControl.release(); + AddControlObject(fhEventControl); + fhTrackControl=hTrackControl.release(); + AddControlObject(fhTrackControl); + + return 0; +} + +int AliDxHFEParticleSelection::AddControlObject(TObject* pObj) +{ + /// add control object to list, the base class becomes owner of the object + if (!pObj) return -EINVAL; + if (!fControlObjects) { + fControlObjects=new TList; + if (!fControlObjects) return -ENOMEM; + fControlObjects->SetOwner(); + } + if (fControlObjects->FindObject(pObj->GetName())) { + AliError(Form("ignoring duplicate object '%s' of type %s", pObj->GetName(), pObj->ClassName())); + return -EEXIST; + } + fControlObjects->Add(pObj); + return 0; +} + +int AliDxHFEParticleSelection::HistogramParticleProperties(AliVParticle* p, bool selected) +{ + /// histogram particle properties + if (!p) return -EINVAL; + if (!fControlObjects) return 0; + + // TODO: use enums for the bins of the control histogram + fhTrackControl->Fill(0); + if (selected) fhTrackControl->Fill(1); + return 0; } TObjArray* AliDxHFEParticleSelection::Select(const AliVEvent* pEvent) @@ -61,7 +120,9 @@ TObjArray* AliDxHFEParticleSelection::Select(const AliVEvent* pEvent) int nofTracks=pEvent->GetNumberOfTracks(); for (int itrack=0; itrackGetTrack(itrack); - if (!IsSelected(track)) continue; + bool selected=IsSelected(track); + HistogramParticleProperties(track, selected); + if (!selected) continue; selectedTracks->Add(track); } return selectedTracks; @@ -79,7 +140,9 @@ TObjArray* AliDxHFEParticleSelection::Select(TObjArray* pTracks) while ((pObj=itrack())!=NULL) { AliVParticle* track=dynamic_cast(pObj); if (!track) continue; - if (!IsSelected(track)) continue; + bool selected=IsSelected(track); + HistogramParticleProperties(track, selected); + if (!selected) continue; selectedTracks->Add(track); } return selectedTracks; @@ -107,9 +170,53 @@ void AliDxHFEParticleSelection::AliDxHFEParticleSelection::Clear(Option_t * /*op void AliDxHFEParticleSelection::Print(Option_t */*option*/) const { /// inherited from TObject: print info + cout << "====================================================================" << endl; + TNamed::Print(); + if (fControlObjects) fControlObjects->Print(); } -void AliDxHFEParticleSelection::SaveAs(const char */*filename*/,Option_t */*option*/) const +void AliDxHFEParticleSelection::SaveAs(const char* filename,Option_t */*option*/) const { - /// inherited from TObject: safe selection criteria + /// inherited from TObject: save selection criteria + std::auto_ptr output(TFile::Open(filename, "RECREATE")); + if (!output.get() || output->IsZombie()) { + AliError(Form("can not open file %s from writing", filename)); + return; + } + output->cd(); + if (fControlObjects) fControlObjects->Write(); + output->Close(); +} + +void AliDxHFEParticleSelection::Draw(Option_t* /*option*/) +{ + /// inherited from TObject: draw content + + // TODO: implement drawing code + // - create canvas objects + // - plot internal objects + // - optionally save canvases to file + // + // It might be appropriate to have another Draw function taking a + // TList as argument and implementing the actual drawing. If this + // function is 'static', it can be used stand-alone also from macros +} + +TObject* AliDxHFEParticleSelection::FindObject(const char* name) const +{ + /// inherited from TObject: find object by name + + if (fControlObjects) { + return fControlObjects->FindObject(name); + } + return NULL; +} + +TObject* AliDxHFEParticleSelection::FindObject(const TObject* obj) const +{ + /// inherited from TObject: find object by pointer + if (fControlObjects) { + return fControlObjects->FindObject(obj); + } + return NULL; } diff --git a/PWGHF/correlationHF/AliDxHFEParticleSelection.h b/PWGHF/correlationHF/AliDxHFEParticleSelection.h index d9bba615cd2..c2fd5159800 100644 --- a/PWGHF/correlationHF/AliDxHFEParticleSelection.h +++ b/PWGHF/correlationHF/AliDxHFEParticleSelection.h @@ -14,11 +14,13 @@ #ifndef ALIDXHFEPARTICLESELECTION_H #define ALIDXHFEPARTICLESELECTION_H -#include "TObject.h" +#include "TNamed.h" #include "TString.h" class AliVEvent; class AliVParticle; class TObjArray; +class TH1; +class THnSparse; /** * @class AliDxHFEParticleSelection @@ -33,10 +35,10 @@ class TObjArray; * Might be that there is already something similar, then this class * can be merged with some other class. */ -class AliDxHFEParticleSelection : public TObject { +class AliDxHFEParticleSelection : public TNamed { public: /// constructor - AliDxHFEParticleSelection(const char* opt=""); + AliDxHFEParticleSelection(const char* name=NULL, const char* opt=""); /// destructor virtual ~AliDxHFEParticleSelection(); @@ -45,6 +47,9 @@ class AliDxHFEParticleSelection : public TObject { /// overloaded from TObject: get option virtual Option_t* GetOption() const { return fOption;} + /// init the control objects + virtual int InitControlObjects(); + /// create selection, array contains only pointers but does not own the objects /// object array needs to be deleted by caller virtual TObjArray* Select(const AliVEvent* pEvent); @@ -67,8 +72,19 @@ class AliDxHFEParticleSelection : public TObject { virtual void Print(Option_t *option="") const; /// inherited from TObject: safe selection criteria virtual void SaveAs(const char *filename="",Option_t *option="") const; + /// inherited from TObject: draw content + virtual void Draw(Option_t *option=""); + /// inherited from TObject: find object by name + virtual TObject* FindObject(const char *name) const; + /// inherited from TObject: find object by pointer + virtual TObject* FindObject(const TObject *obj) const; protected: + /// add control object to list, the base class becomes owner of the object + int AddControlObject(TObject* pObj); + + /// histogram particle properties + virtual int HistogramParticleProperties(AliVParticle* p, bool selected=true); private: /// copy contructor prohibited @@ -79,6 +95,11 @@ class AliDxHFEParticleSelection : public TObject { TString fOption; // option TObjArray* fSelectedTracks; //! array of selected tracks + // control histograms, note: only the list is saved, pointers only used for fast access + TList* fControlObjects; // list of control objects + TH1* fhEventControl; //! event control histogram + TH1* fhTrackControl; //! track control histogram + ClassDef(AliDxHFEParticleSelection, 1); }; diff --git a/PWGHF/correlationHF/AliDxHFEParticleSelectionD0.cxx b/PWGHF/correlationHF/AliDxHFEParticleSelectionD0.cxx index a82e19d0180..d09c62faf0e 100644 --- a/PWGHF/correlationHF/AliDxHFEParticleSelectionD0.cxx +++ b/PWGHF/correlationHF/AliDxHFEParticleSelectionD0.cxx @@ -25,13 +25,20 @@ #include "AliDxHFEParticleSelectionD0.h" #include "AliVParticle.h" +#include "AliAODRecoDecayHF2Prong.h" // libPWGHFvertexingHF #include "TObjArray.h" +#include "THnSparse.h" +#include "TAxis.h" +#include +#include +#include /// ROOT macro for the implementation of ROOT specific class methods ClassImp(AliDxHFEParticleSelectionD0) AliDxHFEParticleSelectionD0::AliDxHFEParticleSelectionD0(const char* opt) - : AliDxHFEParticleSelection(opt) + : AliDxHFEParticleSelection("D0", opt) + , fD0Properties(NULL) { // constructor // @@ -45,6 +52,64 @@ AliDxHFEParticleSelectionD0::~AliDxHFEParticleSelectionD0() // destructor } +int AliDxHFEParticleSelectionD0::InitControlObjects() +{ + /// init the control objects, can be overloaded by childs which should + /// call AliDxHFEParticleSelection::InitControlObjects() explicitly + TString name; + const int thnSize = 4; + const double pi=TMath::Pi(); + + // TODO: very specific D0 for the moment, sort out later + // TODO: theta? + // 0 1 2 3 + // mass Pt Phi Ptbin + int thnBins[thnSize] = { 200, 1000, 100, 100}; + double thnMin [thnSize] = { 1.5648, 0, 0, 0}; + double thnMax [thnSize] = { 2.1648, 100, (2*pi), 100}; + + name.Form("%s info", GetName()); + std::auto_ptr D0Properties(new THnSparseF(name, name, thnSize, thnBins, thnMin, thnMax)); + + if (D0Properties.get()==NULL) { + return -ENOMEM; + } + int axis=0; + D0Properties->GetAxis(axis++)->SetTitle("mass"); + D0Properties->GetAxis(axis++)->SetTitle("Pt"); + D0Properties->GetAxis(axis++)->SetTitle("Phi"); + D0Properties->GetAxis(axis++)->SetTitle("Ptbin"); + + fD0Properties=D0Properties.release(); + AddControlObject(fD0Properties); + + return AliDxHFEParticleSelection::InitControlObjects(); +} + +int AliDxHFEParticleSelectionD0::HistogramParticleProperties(AliVParticle* p, bool selected) +{ + /// histogram particle properties + if (!p) return -EINVAL; + + // fill the common histograms + AliDxHFEParticleSelection::HistogramParticleProperties(p, selected); + + // TODO: histograms for all and selected particles + if (!selected) return 0; + + // TODO: find out which type is necessary + AliAODRecoDecayHF2Prong* part=dynamic_cast(p); + if (part) { + Double_t invmassD0 = part->InvMassD0(); + // TODO: use cut object to define pt bin + Int_t ptbin=0;//cuts->PtBin(part->Pt()); + Double_t D0Stuff[] = {invmassD0,part->Pt(),part->Phi(),ptbin}; + if (fD0Properties) fD0Properties->Fill(D0Stuff); + } + + return 0; +} + bool AliDxHFEParticleSelectionD0::IsSelected(AliVParticle* /*p*/) { /// TODO: implement specific selection of D0 candidates diff --git a/PWGHF/correlationHF/AliDxHFEParticleSelectionD0.h b/PWGHF/correlationHF/AliDxHFEParticleSelectionD0.h index 94e0c3a32d7..fc80e82b338 100644 --- a/PWGHF/correlationHF/AliDxHFEParticleSelectionD0.h +++ b/PWGHF/correlationHF/AliDxHFEParticleSelectionD0.h @@ -28,10 +28,15 @@ class AliDxHFEParticleSelectionD0 : public AliDxHFEParticleSelection { /// destructor virtual ~AliDxHFEParticleSelectionD0(); + /// overloaded from AliDxHFEParticleSelection: init the control objects + virtual int InitControlObjects(); + /// overloaded from AliDxHFEParticleSelection: check particle virtual bool IsSelected(AliVParticle* p); protected: + /// overloaded from AliDxHFEParticleSelection: histogram particle properties + virtual int HistogramParticleProperties(AliVParticle* p, bool selected=true); private: /// copy contructor prohibited @@ -39,6 +44,11 @@ class AliDxHFEParticleSelectionD0 : public AliDxHFEParticleSelection { /// assignment operator prohibited AliDxHFEParticleSelectionD0& operator=(const AliDxHFEParticleSelectionD0&); + THnSparse* fD0Properties; //! the particle properties of selected particles + // TODO: at the moment the dimensions of the different THnSparse objects are different + // needs to be consolidated + // TODO: one might need particle properties of all and/or at different cut stages + ClassDef(AliDxHFEParticleSelectionD0, 1); }; -- 2.43.5