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