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