]>
Commit | Line | Data |
---|---|---|
dc740de4 | 1 | /* $Id$ */ |
2 | ||
539b6cb4 | 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" | |
b8e8168f | 28 | |
539b6cb4 | 29 | #include <TStyle.h> |
30 | #include <TSystem.h> | |
31 | #include <TCanvas.h> | |
32 | #include <TRegexp.h> | |
b8e8168f | 33 | #include <TTime.h> |
4dd2ad81 | 34 | #include <TParticle.h> |
35 | #include <TParticlePDG.h> | |
dc740de4 | 36 | #include <TFriendElement.h> |
f8e00da3 | 37 | #include <TTree.h> |
38 | #include <TChain.h> | |
39 | #include <TFile.h> | |
539b6cb4 | 40 | |
b8e8168f | 41 | #include <AliLog.h> |
f8e00da3 | 42 | #include <AliESD.h> |
539b6cb4 | 43 | |
44 | ClassImp(AliSelector) | |
45 | ||
ee998961 | 46 | AliSelector::AliSelector() : |
539b6cb4 | 47 | TSelector(), |
16e24ca3 | 48 | fTree(0), |
539b6cb4 | 49 | fESD(0), |
dc740de4 | 50 | fCountFiles(0), |
16e24ca3 | 51 | fKineFile(0) |
539b6cb4 | 52 | { |
79ab56b9 | 53 | // |
539b6cb4 | 54 | // Constructor. Initialization of pointers |
79ab56b9 | 55 | // |
16e24ca3 | 56 | |
57 | AliLog::SetClassDebugLevel("AliSelector", AliLog::kDebug); | |
539b6cb4 | 58 | } |
59 | ||
60 | AliSelector::~AliSelector() | |
61 | { | |
79ab56b9 | 62 | // |
63 | // Destructor | |
64 | // | |
539b6cb4 | 65 | |
66 | // histograms are in the output list and deleted when the output | |
67 | // list is deleted by the TSelector dtor | |
68 | } | |
69 | ||
16e24ca3 | 70 | void AliSelector::Begin(TTree*) |
539b6cb4 | 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). | |
539b6cb4 | 75 | } |
76 | ||
16e24ca3 | 77 | void AliSelector::SlaveBegin(TTree* tree) |
539b6cb4 | 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 | ||
b8e8168f | 83 | AliDebug(AliLog::kDebug, "=======SLAVEBEGIN========"); |
84 | AliDebug(AliLog::kDebug, Form("Hostname: %s", gSystem->HostName())); | |
85 | AliDebug(AliLog::kDebug, Form("Time: %s", gSystem->Now().AsString())); | |
539b6cb4 | 86 | |
16e24ca3 | 87 | if (tree != 0) |
88 | Init(tree); | |
539b6cb4 | 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 | ||
b8e8168f | 99 | AliDebug(AliLog::kDebug, "=========Init=========="); |
539b6cb4 | 100 | |
16e24ca3 | 101 | fTree = tree; |
539b6cb4 | 102 | |
16e24ca3 | 103 | if (fTree == 0) |
539b6cb4 | 104 | { |
16e24ca3 | 105 | AliDebug(AliLog::kError, "ERROR: tree argument is 0."); |
539b6cb4 | 106 | return; |
107 | } | |
108 | ||
16e24ca3 | 109 | // Set branch address |
110 | fTree->SetBranchAddress("ESD", &fESD); | |
539b6cb4 | 111 | if (fESD != 0) |
b8e8168f | 112 | AliDebug(AliLog::kInfo, "INFO: Found ESD branch in chain."); |
539b6cb4 | 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 | ||
b8e8168f | 124 | AliDebug(AliLog::kDebug, "=========NOTIFY=========="); |
125 | AliDebug(AliLog::kDebug, Form("Hostname: %s", gSystem->HostName())); | |
126 | AliDebug(AliLog::kDebug, Form("Time: %s", gSystem->Now().AsString())); | |
ee998961 | 127 | |
dc740de4 | 128 | ++fCountFiles; |
16e24ca3 | 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 | } | |
539b6cb4 | 138 | |
139 | DeleteKinematicsFile(); | |
dc740de4 | 140 | |
539b6cb4 | 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. | |
16e24ca3 | 161 | // Assuming that fTree is the pointer to the TChain being processed, |
162 | // use fTree->GetTree()->GetEntry(entry). | |
539b6cb4 | 163 | |
b8e8168f | 164 | AliDebug(AliLog::kDebug, Form("=========PROCESS========== Entry %lld", entry)); |
539b6cb4 | 165 | |
16e24ca3 | 166 | if (!fTree) |
539b6cb4 | 167 | { |
16e24ca3 | 168 | AliDebug(AliLog::kError, "ERROR: fTree is 0."); |
539b6cb4 | 169 | return kFALSE; |
170 | } | |
171 | ||
16e24ca3 | 172 | fTree->GetTree()->GetEntry(entry); |
539b6cb4 | 173 | |
dc740de4 | 174 | /* |
175 | // debugging | |
539b6cb4 | 176 | if (fESD) |
b8e8168f | 177 | AliDebug(AliLog::kDebug, Form("ESD: We have %d tracks.", fESD->GetNumberOfTracks())); |
539b6cb4 | 178 | |
179 | if (fHeader) | |
b8e8168f | 180 | AliDebug(AliLog::kDebug, Form("Header: We have %d primaries.", fHeader->GetNprimary())); |
539b6cb4 | 181 | |
182 | TTree* kinematics = GetKinematics(); | |
183 | if (kinematics) | |
b8e8168f | 184 | AliDebug(AliLog::kDebug, Form("Kinematics: We have %lld particles.", kinematics->GetEntries())); |
dc740de4 | 185 | */ |
539b6cb4 | 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(); | |
539b6cb4 | 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 | ||
b8e8168f | 205 | AliDebug(AliLog::kDebug, "=========TERMINATE=========="); |
539b6cb4 | 206 | } |
207 | ||
208 | TTree* AliSelector::GetKinematics() | |
209 | { | |
16e24ca3 | 210 | // Returns kinematics tree corresponding to current ESD active in fTree |
79ab56b9 | 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 | ||
539b6cb4 | 214 | if (!fKineFile) |
215 | { | |
16e24ca3 | 216 | if (!fTree->GetCurrentFile()) |
539b6cb4 | 217 | return 0; |
218 | ||
16e24ca3 | 219 | TString fileName(fTree->GetCurrentFile()->GetName()); |
539b6cb4 | 220 | fileName.ReplaceAll("AliESDs", "Kinematics"); |
221 | ||
dc740de4 | 222 | AliDebug(AliLog::kInfo, Form("Opening %s", fileName.Data())); |
223 | ||
539b6cb4 | 224 | fKineFile = TFile::Open(fileName); |
225 | if (!fKineFile) | |
226 | return 0; | |
227 | } | |
228 | ||
16e24ca3 | 229 | return dynamic_cast<TTree*> (fKineFile->Get(Form("Event%d/TreeK", fTree->GetTree()->GetReadEntry()))); |
539b6cb4 | 230 | } |
231 | ||
232 | void AliSelector::DeleteKinematicsFile() | |
233 | { | |
79ab56b9 | 234 | // |
235 | // Closes the kinematics file and deletes the pointer. | |
236 | // | |
237 | ||
539b6cb4 | 238 | if (fKineFile) |
239 | { | |
240 | fKineFile->Close(); | |
241 | delete fKineFile; | |
242 | fKineFile = 0; | |
243 | } | |
244 | } | |
245 | ||
4dd2ad81 | 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) | |
dc740de4 | 255 | { |
256 | AliDebug(AliLog::kDebug+1, "Dropping particle because it has a daughter among the primaries."); | |
4dd2ad81 | 257 | return kFALSE; |
dc740de4 | 258 | } |
4dd2ad81 | 259 | |
260 | Int_t pdgCode = TMath::Abs(aParticle->GetPdgCode()); | |
261 | ||
262 | // skip quarks and gluon | |
263 | if (pdgCode <= 10 || pdgCode == 21) | |
dc740de4 | 264 | { |
265 | AliDebug(AliLog::kDebug+1, "Dropping particle because it is a quark or gluon."); | |
4dd2ad81 | 266 | return kFALSE; |
dc740de4 | 267 | } |
4dd2ad81 | 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) | |
dc740de4 | 284 | { |
4dd2ad81 | 285 | return kFALSE; |
dc740de4 | 286 | AliDebug(AliLog::kDebug+1, "Dropping particle because it is not charged."); |
287 | } | |
4dd2ad81 | 288 | |
289 | return kTRUE; | |
290 | } |