Class implements interface AliAnalysisCuts.
[u/mrichter/AliRoot.git] / PWG0 / esdTrackCuts / AliTestESDtrackCutsSelector.cxx
CommitLineData
3633478d 1/* $Id$ */
2
3#include "AliTestESDtrackCutsSelector.h"
4
5#include <TStyle.h>
6#include <TSystem.h>
7#include <TCanvas.h>
8#include <TParticle.h>
9#include <TParticlePDG.h>
10#include <TVector3.h>
11#include <TChain.h>
12#include <TFile.h>
13#include <TH1F.h>
14
15#include <TSelector.h>
16#include <TFile.h>
17
18#include <AliLog.h>
19#include <AliESD.h>
20#include <AliRunLoader.h>
21#include <AliStack.h>
22
23#include "esdTrackCuts/AliESDtrackCuts.h"
24#include "AliPWG0Helper.h"
25
26
27ClassImp(AliTestESDtrackCutsSelector)
28
29AliTestESDtrackCutsSelector::AliTestESDtrackCutsSelector() :
30 AliSelectorRL(),
31 fEsdTrackCutsAll(0),
32 fEsdTrackCutsPri(0),
3c4b53f0 33 fEsdTrackCutsSec(0),
34 fEsdTrackCutsPlusZ(0),
35 fEsdTrackCutsMinusZ(0),
36 fEsdTrackCutsPos(0),
37 fEsdTrackCutsNeg(0)
3633478d 38{
39 //
40 // Constructor. Initialization of pointers
41 //
42}
43
44AliTestESDtrackCutsSelector::~AliTestESDtrackCutsSelector()
45{
46 //
47 // Destructor
48 //
49
50 // histograms are in the output list and deleted when the output
51 // list is deleted by the TSelector dtor
52}
53
54void AliTestESDtrackCutsSelector::Begin(TTree* tree)
55{
56 // Begin function
57
58 AliSelectorRL::Begin(tree);
59
60 ReadUserObjects(tree);
61}
62
63void AliTestESDtrackCutsSelector::ReadUserObjects(TTree* tree)
64{
65 // read the user objects, called from slavebegin and begin
66
3c4b53f0 67 // only do it once
68 if (fEsdTrackCutsAll)
69 return;
70
3633478d 71 if (!fEsdTrackCutsAll && fInput)
0b8a2421 72 fEsdTrackCutsAll = dynamic_cast<AliESDtrackCuts*> (fInput->FindObject("esdTrackCutsAll")->Clone());
3633478d 73
74 if (!fEsdTrackCutsAll && tree)
75 fEsdTrackCutsAll = dynamic_cast<AliESDtrackCuts*> (tree->GetUserInfo()->FindObject("esdTrackCutsAll"));
3633478d 76
3c4b53f0 77 if (!fEsdTrackCutsAll)
78 AliDebug(AliLog::kError, "ERROR: Could not read fEsdTrackCutsAll from input list.");
79
80 fEsdTrackCutsPri = dynamic_cast<AliESDtrackCuts*> (fEsdTrackCutsAll->Clone("fEsdTrackCutsPri"));
81 fEsdTrackCutsSec = dynamic_cast<AliESDtrackCuts*> (fEsdTrackCutsAll->Clone("fEsdTrackCutsSec"));
82 fEsdTrackCutsPlusZ = dynamic_cast<AliESDtrackCuts*> (fEsdTrackCutsAll->Clone("fEsdTrackCutsPlusZ"));
83 fEsdTrackCutsMinusZ = dynamic_cast<AliESDtrackCuts*> (fEsdTrackCutsAll->Clone("fEsdTrackCutsMinusZ"));
84 fEsdTrackCutsPos = dynamic_cast<AliESDtrackCuts*> (fEsdTrackCutsAll->Clone("fEsdTrackCutsPos"));
85 fEsdTrackCutsNeg = dynamic_cast<AliESDtrackCuts*> (fEsdTrackCutsAll->Clone("fEsdTrackCutsNeg"));
3633478d 86}
87
88void AliTestESDtrackCutsSelector::SlaveBegin(TTree* tree)
89{
90 // The SlaveBegin() function is called after the Begin() function.
91 // When running with PROOF SlaveBegin() is called on each slave server.
92 // The tree argument is deprecated (on PROOF 0 is passed).
93
94 AliSelectorRL::SlaveBegin(tree);
95
96 ReadUserObjects(tree);
97}
98
3c4b53f0 99void AliTestESDtrackCutsSelector::Init(TTree* tree)
100{
101 // read the user objects
102
103 AliSelectorRL::Init(tree);
104
105 // Enable only the needed branches
106 if (tree)
107 {
108 tree->SetBranchStatus("*", 0);
109 tree->SetBranchStatus("fTriggerMask", 1);
110 tree->SetBranchStatus("fSPDVertex*", 1);
111 tree->SetBranchStatus("fTracks.fLabel", 1);
112
113 AliESDtrackCuts::EnableNeededBranches(tree);
114 }
115}
116
3633478d 117Bool_t AliTestESDtrackCutsSelector::Process(Long64_t entry)
118{
119 // The Process() function is called for each entry in the tree (or possibly
120 // keyed object in the case of PROOF) to be processed. The entry argument
121 // specifies which entry in the currently loaded tree is to be processed.
122 // It can be passed to either TTree::GetEntry() or TBranch::GetEntry()
123 // to read either all or the required parts of the data. When processing
124 // keyed objects with PROOF, the object is already loaded and is available
125 // via the fObject pointer.
126 //
127 // This function should contain the "body" of the analysis. It can contain
128 // simple or elaborate selection criteria, run algorithms on the data
129 // of the event and typically fill histograms.
130
131 // WARNING when a selector is used with a TChain, you must use
132 // the pointer to the current TTree to call GetEntry(entry).
133 // The entry is always the local entry number in the current tree.
134 // Assuming that fTree is the pointer to the TChain being processed,
135 // use fTree->GetTree()->GetEntry(entry).
136
137 if (AliSelectorRL::Process(entry) == kFALSE)
138 return kFALSE;
139
140 // Check prerequisites
141 if (!fESD) {
142 AliDebug(AliLog::kError, "ESD branch not available");
143 return kFALSE;
3c4b53f0 144 }
3633478d 145
146 if (!AliPWG0Helper::IsVertexReconstructed(fESD)) {
147 AliDebug(AliLog::kDebug+5, "Vertex is not reconstructed");
148 return kFALSE;
149 }
150
151 // check if the esd track cut objects are there
3c4b53f0 152 if (!fEsdTrackCutsAll || !fEsdTrackCutsPri || !fEsdTrackCutsSec || !fEsdTrackCutsPlusZ || !fEsdTrackCutsMinusZ || !fEsdTrackCutsPos || !fEsdTrackCutsNeg) {
3633478d 153 AliDebug(AliLog::kError, "fEsdTrackCutsXXX not available");
154 return kFALSE;
155 }
156
157 // get particle stack
158 AliStack* stack = GetStack();
159 if (!stack) {
160 AliDebug(AliLog::kError, "Stack not available");
161 return kFALSE;
162 }
163 Int_t nPrim = stack->GetNprimary();
164
165 // ########################################################
166 // loop over esd tracks
167 Int_t nTracks = fESD->GetNumberOfTracks();
168
169 // count the number of "good" tracks as parameter for vertex reconstruction efficiency
170 for (Int_t t=0; t<nTracks; t++) {
171 AliDebug(AliLog::kDebug+1, Form("ESD Loop: Processing track %d.", t));
172
173 AliESDtrack* esdTrack = fESD->GetTrack(t);
174
175 fEsdTrackCutsAll->AcceptTrack(esdTrack);
176
177 // using the properties of the mc particle
178 Int_t label = TMath::Abs(esdTrack->GetLabel());
179 if (label == 0) {
180 AliDebug(AliLog::kWarning, Form("WARNING: cannot find corresponding mc part for track %d.", t));
181 continue;
182 }
183 TParticle* particle = stack->Particle(label);
184 if (!particle) {
185 AliDebug(AliLog::kError, Form("UNEXPECTED: part with label %d not found in stack (track loop).", label));
186 continue;
187 }
0b8a2421 188
189 if (label < nPrim)
3633478d 190 fEsdTrackCutsPri->AcceptTrack(esdTrack);
191 else
192 fEsdTrackCutsSec->AcceptTrack(esdTrack);
3c4b53f0 193
194 TParticlePDG* pdgPart = particle->GetPDG();
195 if (pdgPart)
196 {
197 if (pdgPart->Charge() > 0)
198 fEsdTrackCutsPos->AcceptTrack(esdTrack);
199 else if (pdgPart->Charge() < 0)
200 fEsdTrackCutsNeg->AcceptTrack(esdTrack);
201 }
202
203 if (particle->Eta() < 0)
204 fEsdTrackCutsPlusZ->AcceptTrack(esdTrack);
205 else
206 fEsdTrackCutsMinusZ->AcceptTrack(esdTrack);
3633478d 207 }
208
209 return kTRUE;
210}
211
212void AliTestESDtrackCutsSelector::SlaveTerminate()
213{
214 // The SlaveTerminate() function is called after all entries or objects
215 // have been processed. When running with PROOF SlaveTerminate() is called
216 // on each slave server.
217
218 AliSelectorRL::SlaveTerminate();
219
220 // Add the histograms to the output on each slave server
221 if (!fOutput)
222 {
223 AliDebug(AliLog::kError, Form("ERROR: Output list not initialized."));
224 return;
225 }
226
227 fOutput->Add(fEsdTrackCutsAll);
228 fOutput->Add(fEsdTrackCutsPri);
229 fOutput->Add(fEsdTrackCutsSec);
3c4b53f0 230 fOutput->Add(fEsdTrackCutsPlusZ);
231 fOutput->Add(fEsdTrackCutsMinusZ);
232 fOutput->Add(fEsdTrackCutsPos);
233 fOutput->Add(fEsdTrackCutsNeg);
3633478d 234}
235
236void AliTestESDtrackCutsSelector::Terminate()
237{
238 // The Terminate() function is the last function to be called during
239 // a query. It always runs on the client, it can be used to present
240 // the results graphically or save the results to file.
241
242 AliSelectorRL::Terminate();
243
0b8a2421 244 fEsdTrackCutsAll = dynamic_cast<AliESDtrackCuts*> (fOutput->FindObject("esdTrackCutsAll"));
3c4b53f0 245 fEsdTrackCutsPri = dynamic_cast<AliESDtrackCuts*> (fOutput->FindObject("fEsdTrackCutsPri"));
246 fEsdTrackCutsSec = dynamic_cast<AliESDtrackCuts*> (fOutput->FindObject("fEsdTrackCutsSec"));
247 fEsdTrackCutsPlusZ = dynamic_cast<AliESDtrackCuts*> (fOutput->FindObject("fEsdTrackCutsPlusZ"));
248 fEsdTrackCutsMinusZ = dynamic_cast<AliESDtrackCuts*> (fOutput->FindObject("fEsdTrackCutsMinusZ"));
249 fEsdTrackCutsPos = dynamic_cast<AliESDtrackCuts*> (fOutput->FindObject("fEsdTrackCutsPos"));
250 fEsdTrackCutsNeg = dynamic_cast<AliESDtrackCuts*> (fOutput->FindObject("fEsdTrackCutsNeg"));
0b8a2421 251
252 // check if the esd track cut objects are there
3c4b53f0 253 if (!fEsdTrackCutsAll || !fEsdTrackCutsPri || !fEsdTrackCutsSec || !fEsdTrackCutsPlusZ || !fEsdTrackCutsMinusZ || !fEsdTrackCutsPos || !fEsdTrackCutsNeg) {
254 AliDebug(AliLog::kError, Form("fEsdTrackCutsXXX not available %p %p %p %p %p %p %p", fEsdTrackCutsAll, fEsdTrackCutsPri, fEsdTrackCutsSec, fEsdTrackCutsPlusZ, fEsdTrackCutsMinusZ, fEsdTrackCutsPos, fEsdTrackCutsNeg));
0b8a2421 255 return;
256 }
257
3633478d 258 TFile* file = TFile::Open("trackCuts.root", "RECREATE");
3c4b53f0 259
260 fEsdTrackCutsAll->SaveHistograms();
261 fEsdTrackCutsPri->SaveHistograms();
262 fEsdTrackCutsSec->SaveHistograms();
263 fEsdTrackCutsPlusZ->SaveHistograms();
264 fEsdTrackCutsMinusZ->SaveHistograms();
265 fEsdTrackCutsPos->SaveHistograms();
266 fEsdTrackCutsNeg->SaveHistograms();
3633478d 267
268 file->Close();
3c4b53f0 269
270 fEsdTrackCutsAll->DrawHistograms();
3633478d 271}