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