]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG0/dNdEta/AliMultiplicityESDSelector.cxx
small fix, enhanced comments
[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 #ifdef ALISELECTOR_USEMONALISA
20   #include <TMonaLisaWriter.h>
21 #endif
22
23 ClassImp(AliMultiplicityESDSelector)
24
25 AliMultiplicityESDSelector::AliMultiplicityESDSelector() :
26   AliSelector(),
27   fMultiplicity(0),
28   fEsdTrackCuts(0)
29 #ifdef ALISELECTOR_USEMONALISA
30   ,fMonaLisaWriter(0)
31 #endif
32 {
33   //
34   // Constructor. Initialization of pointers
35   //
36 }
37
38 AliMultiplicityESDSelector::~AliMultiplicityESDSelector()
39 {
40   //
41   // Destructor
42   //
43
44   // histograms are in the output list and deleted when the output
45   // list is deleted by the TSelector dtor
46 }
47
48 void AliMultiplicityESDSelector::Begin(TTree* tree)
49 {
50   // Begin function
51
52   AliSelector::Begin(tree);
53
54   ReadUserObjects(tree);
55 }
56
57 void AliMultiplicityESDSelector::ReadUserObjects(TTree* tree)
58 {
59   // read the user objects, called from slavebegin and begin
60
61   if (!fEsdTrackCuts && fInput)
62     fEsdTrackCuts = dynamic_cast<AliESDtrackCuts*> (fInput->FindObject("AliESDtrackCuts"));
63
64   if (!fEsdTrackCuts && tree)
65     fEsdTrackCuts = dynamic_cast<AliESDtrackCuts*> (tree->GetUserInfo()->FindObject("AliESDtrackCuts"));
66
67   if (!fEsdTrackCuts)
68      AliDebug(AliLog::kError, "ERROR: Could not read EsdTrackCuts from input list.");
69 }
70
71 void AliMultiplicityESDSelector::SlaveBegin(TTree* tree)
72 {
73   // The SlaveBegin() function is called after the Begin() function.
74   // When running with PROOF SlaveBegin() is called on each slave server.
75   // The tree argument is deprecated (on PROOF 0 is passed).
76
77   AliSelector::SlaveBegin(tree);
78
79   ReadUserObjects(tree);
80
81   fMultiplicity = new TH1F("fMultiplicity", "multiplicity", 201, 0.5, 200.5);
82
83   #ifdef ALISELECTOR_USEMONALISA
84     TNamed *nm = 0;
85     if (fInput)
86       nm = dynamic_cast<TNamed*> (fInput->FindObject("PROOF_QueryTag"));
87     if (!nm)
88     {
89       AliDebug(AliLog::kError, "Query tag not found. Cannot enable monitoring");
90       return;
91     }
92
93     TString option = GetOption();
94     option.ReplaceAll("#+", "");
95
96     TString id;
97     id.Form("%s_%s%d", gSystem->HostName(), nm->GetTitle(), gSystem->GetPid());
98     fMonaLisaWriter = new TMonaLisaWriter(option, id, "CAF", "aliendb6.cern.ch");
99   #endif
100 }
101
102 Bool_t AliMultiplicityESDSelector::Process(Long64_t entry)
103 {
104   // The Process() function is called for each entry in the tree (or possibly
105   // keyed object in the case of PROOF) to be processed. The entry argument
106   // specifies which entry in the currently loaded tree is to be processed.
107   // It can be passed to either TTree::GetEntry() or TBranch::GetEntry()
108   // to read either all or the required parts of the data. When processing
109   // keyed objects with PROOF, the object is already loaded and is available
110   // via the fObject pointer.
111   //
112   // This function should contain the "body" of the analysis. It can contain
113   // simple or elaborate selection criteria, run algorithms on the data
114   // of the event and typically fill histograms.
115
116   // WARNING when a selector is used with a TChain, you must use
117   //  the pointer to the current TTree to call GetEntry(entry).
118   //  The entry is always the local entry number in the current tree.
119   //  Assuming that fTree is the pointer to the TChain being processed,
120   //  use fTree->GetTree()->GetEntry(entry).
121
122   if (AliSelector::Process(entry) == kFALSE)
123     return kFALSE;
124
125   // Check prerequisites
126   if (!fESD)
127   {
128     AliDebug(AliLog::kError, "ESD branch not available");
129     return kFALSE;
130   }
131
132   if (!fEsdTrackCuts)
133   {
134     AliDebug(AliLog::kError, "fESDTrackCuts not available");
135     return kFALSE;
136   }
137
138   if (AliPWG0Helper::IsEventTriggered(fESD) == kFALSE)
139     return kTRUE;
140
141   if (AliPWG0Helper::IsVertexReconstructed(fESD) == kFALSE)
142     return kTRUE;
143
144   // get number of "good" tracks
145   Int_t nGoodTracks = fEsdTrackCuts->CountAcceptedTracks(fESD);
146
147   fMultiplicity->Fill(nGoodTracks);
148
149   return kTRUE;
150 }
151
152 void AliMultiplicityESDSelector::SlaveTerminate()
153 {
154   // The SlaveTerminate() function is called after all entries or objects
155   // have been processed. When running with PROOF SlaveTerminate() is called
156   // on each slave server.
157
158   AliSelector::SlaveTerminate();
159
160   #ifdef ALISELECTOR_USEMONALISA
161     if (fMonaLisaWriter)
162     {
163       delete fMonaLisaWriter;
164       fMonaLisaWriter = 0;
165     }
166   #endif
167
168   // Add the histograms to the output on each slave server
169   if (!fOutput)
170   {
171     AliDebug(AliLog::kError, Form("ERROR: Output list not initialized."));
172     return;
173   }
174
175   fOutput->Add(fMultiplicity);
176 }
177
178 void AliMultiplicityESDSelector::Terminate()
179 {
180   // The Terminate() function is the last function to be called during
181   // a query. It always runs on the client, it can be used to present
182   // the results graphically or save the results to file.
183
184   AliSelector::Terminate();
185
186   fMultiplicity = dynamic_cast<TH1F*> (fOutput->FindObject("fMultiplicity"));
187
188   if (!fMultiplicity)
189   {
190     AliDebug(AliLog::kError, Form("ERROR: Histogram not available %p", (void*) fMultiplicity));
191     return;
192   }
193
194   TFile* file = TFile::Open("multiplicityESD.root", "RECREATE");
195   fMultiplicity->Write();
196   file->Close();
197 }