]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TPC/TPCcalib/AliTPCSelectorESD.cxx
Protection for AliESDevent (Marian)
[u/mrichter/AliRoot.git] / TPC / TPCcalib / AliTPCSelectorESD.cxx
CommitLineData
d89d7dbb 1// The class definition in esdClus.h has been generated automatically
2// by the ROOT utility TTree::MakeSelector(). This class is derived
3// from the ROOT class TSelector. For more information on the TSelector
4// framework see $ROOTSYS/README/README.SELECTOR or the ROOT User Manual.
5
6// The following methods are defined in this file:
7// Begin(): called everytime a loop on the tree starts,
8// a convenient place to create your histograms.
9// SlaveBegin(): called after Begin(), when on PROOF called only on the
10// slave servers.
11// Process(): called for each event, in this function you decide what
12// to read and fill your histograms.
13// SlaveTerminate: called at the end of the loop on the tree, when on PROOF
14// called only on the slave servers.
15// Terminate(): called at the end of the loop on the tree,
16// a convenient place to draw/fit your histograms.
17//
18// To use this file, try the following session on your Tree T:
19//
20// Root > T->Process("esdClus.C")
21// Root > T->Process("esdClus.C","some options")
22// Root > T->Process("esdClus.C+")
23//
24// Modification log:
25// 05/11/2006 HH Correct for large pads (outer sectors) in amplitude plots
26
27#include "TSystem.h"
28#include <TPDGCode.h>
29#include <TStyle.h>
30#include "TCint.h"
31#include "TH1I.h"
32#include "TTimeStamp.h"
33#include "TProof.h"
34#include "TTree.h"
35//
36#include "AliTracker.h"
37#include "AliMagF.h"
38//
39#include "AliESDEvent.h" // new container
40#include "AliESD.h"
41#include "AliESDtrack.h"
42#include "AliESDfriend.h"
43#include "AliESDfriendTrack.h"
44#include "AliTPCseed.h"
45#include "AliTPCclusterMI.h"
46//
47#include "AliTPCSelectorESD.h"
48
49
50
51
52
2e551f34 53AliTPCSelectorESD::AliTPCSelectorESD(TTree *tree) :
d89d7dbb 54 TSelector(),
55 fChain(0),
56 fESDevent(0),
57 fESD(0),
58 fESDfriend(0),
59 fFileNo(0),
60 fSysWatch(0), // system info
61 fFileWatch(0), // file watch - write the status of the analyzed files
62 fDebugLevel(0)
63 {
64 G__SetCatchException(0);
65 //
66 //
67 //if (somthing){
68 fSysWatch = new fstream("syswatch.log", ios_base::out|ios_base::trunc);
69 fFileWatch = new fstream("filewatch.log", ios_base::out|ios_base::trunc);
70 if (gProof) fDebugLevel = gProof->GetLogLevel();
2e551f34 71 if (tree) fChain=tree;
d89d7dbb 72 }
73
74
75void AliTPCSelectorESD::Begin(TTree * /*tree*/)
76{
77 // The Begin() function is called at the start of the query.
78 // When running with PROOF Begin() is only called on the client.
79 // The tree argument is deprecated (on PROOF 0 is passed).
80
81 TString option = GetOption();
82
83}
84
85void AliTPCSelectorESD::SlaveBegin(TTree * tree)
86{
87 // The SlaveBegin() function is called after the Begin() function.
88 // When running with PROOF SlaveBegin() is called on each slave server.
89 // The tree argument is deprecated (on PROOF 0 is passed).
2e551f34 90 if (tree) fChain = tree;
d89d7dbb 91 Init(tree);
92 //
93 fNtracks = new TH1I("ntracks","Number of tracks",100,0,400);
94 fNtracksFriend = new TH1I("ntracksF","Number of friend tracks",100,0,400);
95 fNClusters = new TH1I("ncluster","Number of clusters",100,0,200);
96 fOutput->AddLast(fNtracks);
97 fOutput->AddLast(fNtracksFriend);
98 fOutput->AddLast(fNClusters);
99
100
101}
102
103void AliTPCSelectorESD::CleanESD(){
104 //
105 Bool_t isNew = fESDevent!=0;
106 if (isNew) return;
107
108
109 if (fESD!=0){
110 delete fESD;
111 fESD = 0;
112 }
113 if (fESDevent!=0){
114 delete fESDevent;
115 fESDevent=0;
116 }
117 if (fESDfriend){
118 delete fESDfriend;
119 fESDfriend =0;
120 }
121}
122
123Bool_t AliTPCSelectorESD::Process(Long64_t entry)
124{
125 // The Process() function is called for each entry in the tree (or possibly
126 // keyed object in the case of PROOF) to be processed. The entry argument
127 // specifies which entry in the currently loaded tree is to be processed.
128 // It can be passed to either AliTPCSelectorESD::GetEntry() or TBranch::GetEntry()
129 // to read either all or the required parts of the data. When processing
130 // keyed objects with PROOF, the object is already loaded and is available
131 // via the fObject pointer.
132 //
133 // This function should contain the "body" of the analysis. It can contain
134 // simple or elaborate selection criteria, run algorithms on the data
135 // of the event and typically fill histograms.
136 //
137 // The processing can be stopped by calling Abort().
138 //
139 // Use fStatus to set the return value of TTree::Process().
140 //
141 // The return value is currently not used.
142
143 Int_t status = ProcessIn(entry);
144 if (fFileWatch) {
145 (*fFileWatch) << "__" << status ;
146 }
147 return (status==0);
148}
149
150
151
152
153Int_t AliTPCSelectorESD::ReadEvent(Long64_t entry){
154 //
155 //
156 //
157
158
159 if (!fChain) return -1;
160 if (!fChain->GetTree()) return -1;
161 try {
162 fChain->GetTree()->GetEntry(entry);
163 } catch (std::bad_alloc) {
164 printf("Pica vyjebana pojebany skurveny kokot piciak\n");
165 // fESD =0;
166 //fESDfriend = 0;
167 //fESDevent=0;
168 return -1;
169 }
170 //
171 // Info("Procces","0");
172 if (!fESD && !fESDevent) {
173 //fESD = 0;
174 //fESDfriend = 0;
175 //CleanESD();
176 return -2;
177 }
178 Int_t ntracks = (fESD) ? fESD->GetNumberOfTracks() : fESDevent->GetNumberOfTracks();
179
180 if (fESDevent){
181 fESDevent->SetESDfriend(fESDfriend);
182 }
183
184
185 fNtracks->Fill(ntracks);
186 Info("Procces", Form("entry\t%d: Ntracks = %d",entry, ntracks));
187
188 if (!fESDfriend || fESDfriend->GetNumberOfTracks() != ntracks) {
189 try {
190 delete fESD;
191 }
192 catch (std::bad_alloc) {
193 printf("Pica vyjebana pojebany skurveny kokot piciak\n");
194 fESD =0;
195 return -1;
196 }
197 //fESD = 0;
198 //fESDfriend = 0;
199 //fESD = 0;
200 // CleanESD();
201 if (fESDfriend) fNtracksFriend->Fill(fESDfriend->GetNumberOfTracks());
202 Info("Procces","2: PROBLEM");
203 return -3;
204 }
205 if (fESD) fESD->SetESDfriend(fESDfriend);
206 return 0;
207}
208
209
210Int_t AliTPCSelectorESD::ProcessIn(Long64_t entry)
211{
212 //
213 // User part of proccess method
214 //
215
216 //
217 // USER code to go here
218 //
219 Int_t status = ReadEvent(entry);
220 if (status<0) return status;
221 Int_t ntracks = (fESD) ? fESD->GetNumberOfTracks() : fESDevent->GetNumberOfTracks();
222 //
223 AliTPCseed *seed;
224 AliTPCclusterMI cl;
225 Info("Procces", Form("entry\t%d: NtracksF = %d",entry,fESDfriend->GetNumberOfTracks() ));
226
227 for (Int_t tr = 0; tr < ntracks; tr++){
228 AliESDtrack *esdTrack = fESD ? (AliESDtrack*) fESD->GetTrack(tr): (AliESDtrack*) fESDevent->GetTrack(tr);
229 AliESDfriendTrack *friendtrack = (AliESDfriendTrack*) esdTrack->GetFriendTrack();
2e551f34 230 seed = 0;
d89d7dbb 231 TObject *cobject=0;
232 for (Int_t i=0;;i++){
233 cobject = friendtrack->GetCalibObject(i);
234 if (!cobject) break;
235 seed = dynamic_cast<AliTPCseed*>(cobject);
236 if (seed) break;
237 }
238 //
239 //Info("Process",Form("Proccessing track%d\n",tr));
240 if (seed) {
241 fNClusters->Fill(seed->GetNumberOfClusters());
242 //
243 //
244 }
245 }
246 CleanESD();
247 return 0;
248
249}
250
251
252void AliTPCSelectorESD::SlaveTerminate()
253{
254 // The SlaveTerminate() function is called after all entries or objects
255 // have been processed. When running with PROOF SlaveTerminate() is called
256 // on each slave server.
257 printf ("SlaveTerminate.. \n");
258
259}
260
261void AliTPCSelectorESD::Terminate()
262{
263 // The Terminate() function is the last function to be called during
264 // a query. It always runs on the client, it can be used to present
265 // the results graphically or save the results to file.
266
267 printf ("Terminate... \n");
268 if (!fOutput) return;
269 TFile file("Output.root","recreate");
270 printf("fOutput contains the following: \n");
271 fOutput->Print();
272 printf("Trying to write the file 'Output.root'... \n");
273 fOutput->Write();
274 file.Close();
275
276
277}
278
279
280
2e551f34 281void AliTPCSelectorESD::Init(TTree *tree)
d89d7dbb 282{
283 // The Init() function is called when the selector needs to initialize
284 // a new tree or chain. Typically here the branch addresses and branch
285 // pointers of the tree will be set.
286 // It is normaly not necessary to make changes to the generated
287 // code, but the routine can be extended by the user if needed.
288 // Init() will be called many times when running on PROOF
289 // (once per file to be processed).
290
291 // Set branch addresses and branch pointers
2e551f34 292 static Int_t counter=0;
293 printf(Form("\nAliTPCSelectorESD::Init Accesing%d time\n",counter));
294 counter++;
295 if (!tree) return;
296 fChain = tree;
297 //if (counter>1) return;
298 tree->SetBranchStatus("*",1);
299 //
300 // New AliESDevent format
301 //
302 if (!fChain->GetBranch("ESD")){
303 //
304 //
305 //
306 if (fESDevent) delete fESDevent;
307 fESDevent = new AliESDEvent();
d89d7dbb 308 fESDevent->ReadFromTree(tree); // Attach the branch with ESD friends
309 fESDfriend = (AliESDfriend*)fESDevent->FindListObject("AliESDfriend");
310 tree->SetBranchAddress("ESDfriend.",&fESDfriend);
311 return;
2e551f34 312 }
313 //
314 // if old format
315 //
316
d89d7dbb 317
318
319 // fChain->SetMakeClass(1);
320 fChain->SetBranchAddress("ESD",&fESD);
321 Info("Init","Enter");
322 Bool_t isOK=kFALSE;
323 if (fChain->GetBranch("ESDfriend")) {
324 fChain->SetBranchAddress("ESDfriend",&fESDfriend);
325 Info("Init","V0-ESDfriend.");
326 isOK=kTRUE;
327 }
328 if (fChain->GetBranch("ESDfriend.")){
329 Info("Init","V1-ESDfriend.");
330 fChain->SetBranchAddress("ESDfriend.",&fESDfriend);
331 isOK=kTRUE;
332 }
333 if (isOK) return;
334
335 //
336 // Try to solve problem
337 //
338
339 Info("Init","Problem");
340 if (tree->GetBranch("ESD")){
341 Info("InitTree",tree->GetBranch("ESD")->GetFile()->GetName());
342 char fname[1000];
343 sprintf(fname,"%s/AliESDfriends.root",gSystem->DirName(tree->GetBranch("ESD")->GetFile()->GetName()));
344 Info("InitFile",fname);
345 if (tree->AddFriend("esdFriendTree",fname)){
346 Info("InitFileOK",fname);
347 if (fChain->GetBranch("ESDfriend")) {
348 fChain->SetBranchAddress("ESDfriend",&fESDfriend);
349 Info("Init","V0-ESDfriend.");
350 isOK=kTRUE;
351 }
352 if (fChain->GetBranch("ESDfriend.")){
353 Info("Init","V1-ESDfriend.");
354 fChain->SetBranchAddress("ESDfriend.",&fESDfriend);
355 isOK=kTRUE;
356 }
357 }
358 }
359}
360
361
362
363Bool_t AliTPCSelectorESD::Notify()
364{
365 // The Notify() function is called when a new file is opened. This
366 // can be either for a new TTree in a TChain or when when a new TTree
367 // is started when using PROOF. It is normaly not necessary to make changes
368 // to the generated code, but the routine can be extended by the
369 // user if needed. The return value is currently not used.
370
371 ++fFileNo;
372 const char * fname = "UNKNOWN";
373 const char * hname = gSystem->HostName();
2e551f34 374 if (!fChain) return kFALSE;
d89d7dbb 375 if (fChain->GetCurrentFile()){
376 fname = fChain->GetCurrentFile()->GetName();
377 }
378 Info("Notify",Form("Host %s processing file no %d %s\n",hname,fFileNo,fname));
379
380 //
381 // Print statistic to log file
382 //
383 if (fname) {
384 (*fFileWatch) << endl;
385 (*fFileWatch) << hname <<"\t"
386 << fname <<"\t";
387 }
388 DumpSysInfo(-1);
389
390 return kTRUE;
391}
392
393
394void AliTPCSelectorESD::DumpSysInfo(Int_t entry){
395 //
396 // dump system info to log file
397 // entry - entry number in the chain
398 //
399 const char * fname = "UNKNOWN";
400 const char * hname = gSystem->HostName();
401 if (fChain->GetCurrentFile()){
402 fname = fChain->GetCurrentFile()->GetName();
403 }
404 //
405 if (fSysWatch){
406 TTimeStamp stamp;
407 CpuInfo_t cpuInfo;
408 MemInfo_t memInfo;
409 ProcInfo_t procInfo;
410
411 gSystem->GetCpuInfo(&cpuInfo, 1000);
412 gSystem->GetMemInfo(&memInfo);
413 gSystem->GetProcInfo(&procInfo);
414
415 (*fSysWatch) << hname <<"\t" // hname - hostname
416 << fname <<"\t" // fname - filename
417 << entry <<"\t" // entry - entry number
418 << stamp.GetSec()<<"\t" // time - time stamp in seconds
419 << memInfo.fMemUsed<<"\t" //
420 << memInfo.fSwapUsed<<"\t" //
421 << procInfo.fMemResident<<"\t" //
422 << procInfo.fMemVirtual<<"\t" //
423 << cpuInfo.fUser <<"\t" //
424 << cpuInfo.fSys <<"\t" //
425 << procInfo.fCpuUser<<"\t" //
426 << procInfo.fCpuSys<<"\t" //
427 << endl;
428 }
429}