implemented destructors
[u/mrichter/AliRoot.git] / PWG0 / dNdEta / AliMultiplicityESDSelector.cxx
CommitLineData
0ab29cfa 1/* $Id$ */
2
3#include "AliMultiplicityESDSelector.h"
4
5#include <TStyle.h>
6#include <TSystem.h>
7#include <TCanvas.h>
8#include <TVector3.h>
9#include <TChain.h>
10#include <TFile.h>
11#include <TH1F.h>
12
13#include <AliLog.h>
14#include <AliESD.h>
15
16#include "esdTrackCuts/AliESDtrackCuts.h"
17#include "AliPWG0Helper.h"
18
19ClassImp(AliMultiplicityESDSelector)
20
21AliMultiplicityESDSelector::AliMultiplicityESDSelector() :
22 AliSelector(),
23 fMultiplicity(0),
24 fEsdTrackCuts(0)
25{
26 //
27 // Constructor. Initialization of pointers
28 //
0ab29cfa 29}
30
31AliMultiplicityESDSelector::~AliMultiplicityESDSelector()
32{
33 //
34 // Destructor
35 //
36
37 // histograms are in the output list and deleted when the output
38 // list is deleted by the TSelector dtor
39}
40
41void AliMultiplicityESDSelector::Begin(TTree* tree)
42{
43 // Begin function
44
45 ReadUserObjects(tree);
46}
47
48void AliMultiplicityESDSelector::ReadUserObjects(TTree* tree)
49{
50 // read the user objects, called from slavebegin and begin
51
52 if (!fEsdTrackCuts && fInput)
53 fEsdTrackCuts = dynamic_cast<AliESDtrackCuts*> (fInput->FindObject("AliESDtrackCuts"));
54
55 if (!fEsdTrackCuts && tree)
56 fEsdTrackCuts = dynamic_cast<AliESDtrackCuts*> (tree->GetUserInfo()->FindObject("AliESDtrackCuts"));
57
58 if (!fEsdTrackCuts)
59 AliDebug(AliLog::kError, "ERROR: Could not read EsdTrackCuts from input list.");
60}
61
62void AliMultiplicityESDSelector::SlaveBegin(TTree* tree)
63{
64 // The SlaveBegin() function is called after the Begin() function.
65 // When running with PROOF SlaveBegin() is called on each slave server.
66 // The tree argument is deprecated (on PROOF 0 is passed).
67
68 AliSelector::SlaveBegin(tree);
69
70 ReadUserObjects(tree);
71
72 fMultiplicity = new TH1F("multiplicity", "multiplicity", 100, 0, 100);
73}
74
75Bool_t AliMultiplicityESDSelector::Process(Long64_t entry)
76{
77 // The Process() function is called for each entry in the tree (or possibly
78 // keyed object in the case of PROOF) to be processed. The entry argument
79 // specifies which entry in the currently loaded tree is to be processed.
80 // It can be passed to either TTree::GetEntry() or TBranch::GetEntry()
81 // to read either all or the required parts of the data. When processing
82 // keyed objects with PROOF, the object is already loaded and is available
83 // via the fObject pointer.
84 //
85 // This function should contain the "body" of the analysis. It can contain
86 // simple or elaborate selection criteria, run algorithms on the data
87 // of the event and typically fill histograms.
88
89 // WARNING when a selector is used with a TChain, you must use
90 // the pointer to the current TTree to call GetEntry(entry).
91 // The entry is always the local entry number in the current tree.
92 // Assuming that fTree is the pointer to the TChain being processed,
93 // use fTree->GetTree()->GetEntry(entry).
94
95 if (AliSelector::Process(entry) == kFALSE)
96 return kFALSE;
97
98 // Check prerequisites
99 if (!fESD)
100 {
101 AliDebug(AliLog::kError, "ESD branch not available");
102 return kFALSE;
103 }
104
105 if (!fEsdTrackCuts)
106 {
107 AliDebug(AliLog::kError, "fESDTrackCuts not available");
108 return kFALSE;
109 }
110
111 if (AliPWG0Helper::IsEventTriggered(fESD) == kFALSE)
112 return kTRUE;
113
114 if (AliPWG0Helper::IsVertexReconstructed(fESD) == kFALSE)
115 return kTRUE;
116
117 // get number of "good" tracks
38233af1 118 Int_t nGoodTracks = fEsdTrackCuts->CountAcceptedTracks(fESD);
0ab29cfa 119
120 fMultiplicity->Fill(nGoodTracks);
121
0ab29cfa 122 return kTRUE;
123}
124
125void AliMultiplicityESDSelector::SlaveTerminate()
126{
127 // The SlaveTerminate() function is called after all entries or objects
128 // have been processed. When running with PROOF SlaveTerminate() is called
129 // on each slave server.
130
131 AliSelector::SlaveTerminate();
132
133 // Add the histograms to the output on each slave server
134 if (!fOutput)
135 {
136 AliDebug(AliLog::kError, Form("ERROR: Output list not initialized."));
137 return;
138 }
139
140 fOutput->Add(fMultiplicity);
141}
142
143void AliMultiplicityESDSelector::Terminate()
144{
145 // The Terminate() function is the last function to be called during
146 // a query. It always runs on the client, it can be used to present
147 // the results graphically or save the results to file.
148
149 AliSelector::Terminate();
150
151 fMultiplicity = dynamic_cast<TH1F*> (fOutput->FindObject("multiplicity"));
152
153 if (!fMultiplicity)
154 {
155 AliDebug(AliLog::kError, Form("ERROR: Histograms not available %p", (void*) fMultiplicity));
156 return;
157 }
158
159 new TCanvas;
160 fMultiplicity->Draw();
161}