]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG0/AliSelector.cxx
renamed CorrectionMatrix class
[u/mrichter/AliRoot.git] / PWG0 / AliSelector.cxx
1 /* $Id$ */
2
3 // The class definition in esdV0.h has been generated automatically
4 // by the ROOT utility TTree::MakeSelector(). This class is derived
5 // from the ROOT class TSelector. For more information on the TSelector
6 // framework see $ROOTSYS/README/README.SELECTOR or the ROOT User Manual.
7
8 // The following methods are defined in this file:
9 //    Begin():        called everytime a loop on the tree starts,
10 //                    a convenient place to create your histograms.
11 //    SlaveBegin():   called after Begin(), when on PROOF called only on the
12 //                    slave servers.
13 //    Process():      called for each event, in this function you decide what
14 //                    to read and fill your histograms.
15 //    SlaveTerminate: called at the end of the loop on the tree, when on PROOF
16 //                    called only on the slave servers.
17 //    Terminate():    called at the end of the loop on the tree,
18 //                    a convenient place to draw/fit your histograms.
19 //
20 // To use this file, try the following session on your Tree T:
21 //
22 // Root > T->Process("AliSelector.C")
23 // Root > T->Process("AliSelector.C","some options")
24 // Root > T->Process("AliSelector.C+")
25 //
26
27 #include "AliSelector.h"
28
29 #include <TStyle.h>
30 #include <TSystem.h>
31 #include <TCanvas.h>
32 #include <TRegexp.h>
33 #include <TTime.h>
34 #include <TParticle.h>
35 #include <TParticlePDG.h>
36 #include <TFriendElement.h>
37 #include <TTree.h>
38 #include <TChain.h>
39 #include <TFile.h>
40
41 #include <AliLog.h>
42 #include <AliESD.h>
43
44 ClassImp(AliSelector)
45
46 AliSelector::AliSelector() :
47   TSelector(),
48   fTree(0),
49   fESD(0),
50   fCountFiles(0),
51   fKineFile(0)
52 {
53   //
54   // Constructor. Initialization of pointers
55   //
56
57   AliLog::SetClassDebugLevel("AliSelector", AliLog::kDebug);
58 }
59
60 AliSelector::~AliSelector()
61 {
62   //
63   // Destructor
64   //
65
66   // histograms are in the output list and deleted when the output
67   // list is deleted by the TSelector dtor
68 }
69
70 void AliSelector::Begin(TTree*)
71 {
72   // The Begin() function is called at the start of the query.
73   // When running with PROOF Begin() is only called on the client.
74   // The tree argument is deprecated (on PROOF 0 is passed).
75 }
76
77 void AliSelector::SlaveBegin(TTree* tree)
78 {
79   // The SlaveBegin() function is called after the Begin() function.
80   // When running with PROOF SlaveBegin() is called on each slave server.
81   // The tree argument is deprecated (on PROOF 0 is passed).
82
83   AliDebug(AliLog::kDebug, "=======SLAVEBEGIN========");
84   AliDebug(AliLog::kDebug, Form("Hostname: %s", gSystem->HostName()));
85   AliDebug(AliLog::kDebug, Form("Time: %s", gSystem->Now().AsString()));
86
87   if (tree != 0)
88     Init(tree);
89 }
90
91 void AliSelector::Init(TTree *tree)
92 {
93   // The Init() function is called when the selector needs to initialize
94   // a new tree or chain. Typically here the branch addresses of the tree
95   // will be set. It is normaly not necessary to make changes to the
96   // generated code, but the routine can be extended by the user if needed.
97   // Init() will be called many times when running with PROOF.
98
99   AliDebug(AliLog::kDebug, "=========Init==========");
100
101   fTree = tree;
102
103   if (fTree == 0)
104   {
105     AliDebug(AliLog::kError, "ERROR: tree argument is 0.");
106     return;
107   }
108
109   // Set branch address
110   fTree->SetBranchAddress("ESD", &fESD);
111   if (fESD != 0)
112     AliDebug(AliLog::kInfo, "INFO: Found ESD branch in chain.");
113 }
114
115 Bool_t AliSelector::Notify()
116 {
117   // The Notify() function is called when a new file is opened. This
118   // can be either for a new TTree in a TChain or when when a new TTree
119   // is started when using PROOF. Typically here the branch pointers
120   // will be retrieved. It is normaly not necessary to make changes
121   // to the generated code, but the routine can be extended by the
122   // user if needed.
123
124   AliDebug(AliLog::kDebug, "=========NOTIFY==========");
125   AliDebug(AliLog::kDebug, Form("Hostname: %s", gSystem->HostName()));
126   AliDebug(AliLog::kDebug, Form("Time: %s", gSystem->Now().AsString()));
127
128   ++fCountFiles;
129   if (fTree)
130   {
131     TFile *f = fTree->GetCurrentFile();
132     AliDebug(AliLog::kInfo, Form("Processing %d. file %s", fCountFiles, f->GetName()));
133   }
134   else
135   {
136     AliDebug(AliLog::kError, "fTree not available");
137   }
138
139   DeleteKinematicsFile();
140
141   return kTRUE;
142 }
143
144 Bool_t AliSelector::Process(Long64_t entry)
145 {
146   // The Process() function is called for each entry in the tree (or possibly
147   // keyed object in the case of PROOF) to be processed. The entry argument
148   // specifies which entry in the currently loaded tree is to be processed.
149   // It can be passed to either TTree::GetEntry() or TBranch::GetEntry()
150   // to read either all or the required parts of the data. When processing
151   // keyed objects with PROOF, the object is already loaded and is available
152   // via the fObject pointer.
153   //
154   // This function should contain the "body" of the analysis. It can contain
155   // simple or elaborate selection criteria, run algorithms on the data
156   // of the event and typically fill histograms.
157
158   // WARNING when a selector is used with a TChain, you must use
159   //  the pointer to the current TTree to call GetEntry(entry).
160   //  The entry is always the local entry number in the current tree.
161   //  Assuming that fTree is the pointer to the TChain being processed,
162   //  use fTree->GetTree()->GetEntry(entry).
163
164   AliDebug(AliLog::kDebug, Form("=========PROCESS========== Entry %lld", entry));
165
166   if (!fTree)
167   {
168     AliDebug(AliLog::kError, "ERROR: fTree is 0.");
169     return kFALSE;
170   }
171
172   fTree->GetTree()->GetEntry(entry);
173
174   /*
175   // debugging
176   if (fESD)
177     AliDebug(AliLog::kDebug, Form("ESD: We have %d tracks.", fESD->GetNumberOfTracks()));
178
179   if (fHeader)
180     AliDebug(AliLog::kDebug, Form("Header: We have %d primaries.", fHeader->GetNprimary()));
181
182   TTree* kinematics = GetKinematics();
183   if (kinematics)
184     AliDebug(AliLog::kDebug, Form("Kinematics: We have %lld particles.", kinematics->GetEntries()));
185   */
186
187   return kTRUE;
188 }
189
190 void AliSelector::SlaveTerminate()
191 {
192   // The SlaveTerminate() function is called after all entries or objects
193   // have been processed. When running with PROOF SlaveTerminate() is called
194   // on each slave server.
195
196   DeleteKinematicsFile();
197 }
198
199 void AliSelector::Terminate()
200 {
201   // The Terminate() function is the last function to be called during
202   // a query. It always runs on the client, it can be used to present
203   // the results graphically or save the results to file.
204
205   AliDebug(AliLog::kDebug, "=========TERMINATE==========");
206 }
207
208 TTree* AliSelector::GetKinematics()
209 {
210   // Returns kinematics tree corresponding to current ESD active in fTree
211   // Loads the kinematics from the kinematics file, the file is identified by replacing "AliESDs" to
212   // "Kinematics" in the file path of the ESD file. This is a hack, to be changed!
213
214   if (!fKineFile)
215   {
216     if (!fTree->GetCurrentFile())
217       return 0;
218
219     TString fileName(fTree->GetCurrentFile()->GetName());
220     fileName.ReplaceAll("AliESDs", "Kinematics");
221
222     AliDebug(AliLog::kInfo, Form("Opening %s", fileName.Data()));
223
224     fKineFile = TFile::Open(fileName);
225     if (!fKineFile)
226       return 0;
227   }
228
229   return dynamic_cast<TTree*> (fKineFile->Get(Form("Event%d/TreeK", fTree->GetTree()->GetReadEntry())));
230 }
231
232 void AliSelector::DeleteKinematicsFile()
233 {
234   //
235   // Closes the kinematics file and deletes the pointer.
236   //
237
238   if (fKineFile)
239   {
240     fKineFile->Close();
241     delete fKineFile;
242     fKineFile = 0;
243   }
244 }
245
246 Bool_t AliSelector::IsPrimaryCharged(TParticle* aParticle, Int_t aTotalPrimaries) const
247 {
248   //
249   // Returns if the given particle is a primary particle
250   // This function or a equivalent should be available in some common place of AliRoot
251   //
252
253   // if the particle has a daughter primary, we do not want to count it
254   if (aParticle->GetFirstDaughter() != -1 && aParticle->GetFirstDaughter() < aTotalPrimaries)
255   {
256     AliDebug(AliLog::kDebug+1, "Dropping particle because it has a daughter among the primaries.");
257     return kFALSE;
258   }
259
260   Int_t pdgCode = TMath::Abs(aParticle->GetPdgCode());
261
262   // skip quarks and gluon
263   if (pdgCode <= 10 || pdgCode == 21)
264   {
265     AliDebug(AliLog::kDebug+1, "Dropping particle because it is a quark or gluon.");
266     return kFALSE;
267   }
268
269   if (strcmp(aParticle->GetName(),"XXX") == 0)
270   {
271     AliDebug(AliLog::kDebug, Form("WARNING: There is a particle named XXX."));
272     return kFALSE;
273   }
274
275   TParticlePDG* pdgPart = aParticle->GetPDG();
276
277   if (strcmp(pdgPart->ParticleClass(),"Unknown") == 0)
278   {
279     AliDebug(AliLog::kDebug, Form("WARNING: There is a particle with an unknown particle class (pdg code %d).", pdgCode));
280     return kFALSE;
281   }
282
283   if (pdgPart->Charge() == 0)
284   {
285     return kFALSE;
286     AliDebug(AliLog::kDebug+1, "Dropping particle because it is not charged.");
287   }
288
289   return kTRUE;
290 }