- Calculation of fraction of event corresponding to selected pt-range corrected
[u/mrichter/AliRoot.git] / PHOS / AliPHOSGetter.cxx
CommitLineData
4ae78bb1 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/* $Id: */
17
18/* $Log:
19 29.05.2001 Yuri Kharlov:
20 Everywhere reading the treese TTree->GetEvent(i)
21 is replaced by reading the branches TBranch->GetEntry(0)
22*/
23
24//_________________________________________________________________________
25// A singleton. This class should be used in the analysis stage to get
26// reconstructed objects: Digits, RecPoints, TrackSegments and RecParticles,
27// instead of directly reading them from galice.root file. This container
28// ensures, that one reads Digits, made of these particular digits, RecPoints,
29// made of these particular RecPoints, TrackSegments and RecParticles.
30// This becomes non trivial if there are several identical branches, produced with
31// different set of parameters.
32//
33// An example of how to use (see also class AliPHOSAnalyser):
34// AliPHOSGetter * gime = AliPHOSGetter::GetInstance("galice.root","test") ;
35// for(Int_t irecp = 0; irecp < gime->NRecParticles() ; irecp++)
36// AliPHOSRecParticle * part = gime->RecParticle(1) ;
37// ................
38// please->GetEvent(event) ; // reads new event from galice.root
39//
40//*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC KI & SUBATECH)
41//*-- Completely redesigned by Dmitri Peressounko March 2001
42//
43//*-- YS June 2001 : renamed the original AliPHOSIndexToObject and make
44//*-- systematic usage of TFolders without changing the interface
45//////////////////////////////////////////////////////////////////////////////
46
47
48// --- ROOT system ---
49
50#include "TFile.h"
51#include "TTree.h"
52#include "TROOT.h"
53#include "TObjString.h"
54#include "TFolder.h"
55
56// --- Standard library ---
57#include <iostream.h>
58
59// --- AliRoot header files ---
60
61#include "AliRun.h"
62#include "AliPHOSGetter.h"
63#include "AliPHOS.h"
64#include "AliPHOSDigitizer.h"
65#include "AliPHOSSDigitizer.h"
66#include "AliPHOSClusterizer.h"
67#include "AliPHOSClusterizerv1.h"
68#include "AliPHOSTrackSegmentMaker.h"
69#include "AliPHOSTrackSegmentMakerv1.h"
70#include "AliPHOSTrackSegment.h"
71#include "AliPHOSPID.h"
72#include "AliPHOSPIDv1.h"
73#include "AliPHOSGeometry.h"
74
75ClassImp(AliPHOSGetter)
76
77 AliPHOSGetter * AliPHOSGetter::fgObjGetter = 0 ;
78
79//____________________________________________________________________________
80AliPHOSGetter::AliPHOSGetter(const char* headerFile, const char* branchTitle )
81{
82 //Initialize all lists
83
84 fHeaderFile = headerFile ;
85 fSDigitsTitle = branchTitle ;
86 fDigitsTitle = branchTitle ;
87 fRecPointsTitle = branchTitle ;
88 fRecParticlesTitle = branchTitle ;
89 fTrackSegmentsTitle = branchTitle ;
90
91 fPrimaries = new TObjArray(1) ;
92
93 //open headers file
94 TFile * file = (TFile*) gROOT->GetFile(fHeaderFile.Data() ) ;
95
96 if(file == 0){ //if file was not opened yet, read gAlice
97 if(fHeaderFile.Contains("rfio")) // if we read file using HPSS
98 file = TFile::Open(fHeaderFile.Data(),"update") ;
99 else
100 file = new TFile(fHeaderFile.Data(),"update") ;
101
102 if (!file->IsOpen()) {
103 cerr << "ERROR : AliPHOSGetter::AliPHOSGetter -> Cannot open " << fHeaderFile.Data() << endl ;
104 abort() ;
105 }
106
107 gAlice = (AliRun *) file->Get("gAlice") ;
108
109 if (!gAlice) {
110 cerr << "ERROR : AliPHOSGetter::AliPHOSGetter -> Cannot find gAlice in " << fHeaderFile.Data() << endl ;
111 abort() ;
112 }
113 }
114}
115
116//____________________________________________________________________________
117void AliPHOSGetter::CreateWhiteBoard() const
118{
119 // Posts a few item to the white board (folders)
120
121 // -- the geometry
122 Post(fHeaderFile, "G") ;
123
124 // -- the hits
125 Post(fHeaderFile, "H") ;
126
127}
128
129//____________________________________________________________________________
130AliPHOSGetter * AliPHOSGetter::GetInstance()
131{
132 // Returns the pointer of the unique instance already defined
133
134 AliPHOSGetter * rv = 0 ;
135 if ( fgObjGetter )
136 rv = fgObjGetter ;
137 else
138 cout << "AliPHOSGetter::GetInstance ERROR: not yet initialized" << endl ;
139
140 return rv ;
141}
142
143//____________________________________________________________________________
144AliPHOSGetter * AliPHOSGetter::GetInstance(const char* headerFile,
145 const char* branchTitle)
146{
147 // Creates and returns the pointer of the unique instance
148 // Must be called only when the environment has changed
149
150
151 if ( fgObjGetter ) // delete it if already exists
152 delete fgObjGetter ;
153
154 fgObjGetter = new AliPHOSGetter(headerFile,branchTitle) ;
155
156 // Posts a few item to the white board (folders)
157 fgObjGetter->CreateWhiteBoard() ;
158
159 // Get the first event into the arrays posted on the white board
160 // branchTitle = 0, means simulation run and no event yet
161 if (branchTitle)
162 fgObjGetter->Event(0) ;
163
164 return fgObjGetter ;
165
166}
167
168//____________________________________________________________________________
169 const AliPHOS * AliPHOSGetter::PHOS() const
170{
171 // returns the PHOS object
172 return ( (AliPHOS*)gAlice->GetDetector("PHOS") );
173}
174
175//____________________________________________________________________________
176 const AliPHOSGeometry * AliPHOSGetter::PHOSGeometry() const
177{
178 // retrieves the geometr from the folder
179
180 TString path("YSAlice/WhiteBoard/Geometry/PHOS/") ;
181 path += PHOS()->GetTitle() ;
182 return (AliPHOSGeometry*)gROOT->FindObjectAny(path.Data()) ;
183}
184
185//____________________________________________________________________________
186void AliPHOSGetter::Post(const char * headerFile, const char * opt, const char * name, const Int_t event) const
187{
188 // Adds a new folder for summable digits
189
190 TString foldertitle ;
191 if ( event >= 0 )
192 foldertitle += event ;
193 else
194 foldertitle = "" ;
195
196 TFolder * aliceF = (TFolder*)gROOT->FindObjectAny("YSAlice") ;
197
198 if ( strcmp(opt, "G") == 0 ) { // Geometry
199 // the hierarchy is //YSALICE/WhiteBoard/Geometry/PHOS/
200 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance(PHOS()->GetTitle(),"") ;
201 TFolder * geomF = (TFolder*)aliceF->FindObject("WhiteBoard/Geometry/PHOS") ;
202 if ( !geomF ) {
203 cerr << "ERROR: AliPHOSGetter::Post G -> Folder WhiteBoard/Geometry/PHOS/" << " not found!" << endl;
204 abort() ;
205 }
206 else
207 geomF->Add((TObject*)geom) ;
208
209 } else if ( strcmp(opt, "H") == 0 ) { // Hits
210 // the hierarchy is //YSALICE/WhiteBoard/SDigits/PHOS/Hits
211 TClonesArray * hits = new TClonesArray("AliPHOSHit",1000) ;
212 hits->SetName("Hits") ;
213 TFolder * hitsF = (TFolder*)aliceF->FindObject("WhiteBoard/Hits/PHOS") ;
214 if ( !hitsF ) {
215 cerr << "ERROR: AliPHOSGetter::Post H -> Folder WhiteBoard/Hits/PHOS/" << " not found!" << endl;
216 abort() ;
217 }
218 else
219 hitsF->Add(hits) ;
220
221 } else if ( strcmp(opt, "S") == 0 ) { // summable digits
222 // the hierarchy is //YSALICE/WhiteBoard/SDigits/PHOS/headerFile/sdigitsname
223 // because you can have sdigits from several hit files for mixing
224 TClonesArray * sdigits = new TClonesArray("AliPHOSDigit",1000) ;
225 TString sdigitsName ;
226 if (name)
227 sdigitsName = name ;
228 else
229 sdigitsName = "SDigits" ;
230 sdigits->SetName( sdigitsName.Data() ) ;
231 TFolder * sdigitsF = (TFolder*)aliceF->FindObject("WhiteBoard/SDigits/PHOS") ;
232 TFolder * sdigitsF2 = 0 ;
233 TString subdir(headerFile) ;
234 if ( !(sdigitsF2=(TFolder*)sdigitsF->FindObject(subdir)) )
235 sdigitsF2 = sdigitsF->AddFolder(subdir, foldertitle);
236 else {
237 if ( sdigitsF2->FindObject( sdigitsName.Data() ) ) {
238 cerr <<"INFO: AliPHOSGetter::Post S -> Folder " << subdir << ", " << foldertitle
239 << " already exists!" << endl ;
240 return ;
241 }
242 }
243 if ( !sdigitsF2 ) {
244 cerr << "ERROR: AliPHOSGetter::Post S -> Folder WhiteBoard/SDigits/PHOS/" << subdir << " not created!" << endl;
245 abort() ;
246 }
247 else
248 sdigitsF2->Add(sdigits) ;
249
250 } else if ( strcmp(opt, "Ser") == 0 ) { // sdigizer
251 // the hierarchy is //YSALICE/tasks/Digitizer/PHOS/sdigitsname
252 AliPHOSSDigitizer * sdigitizer = new AliPHOSSDigitizer() ;
253 TString sdigitsName ;
254 if (name)
255 sdigitsName = name ;
256 else
257 sdigitsName = "SDigitizer" ;
258 sdigitizer->SetName( sdigitsName.Data() ) ;
259 TTask * sdigitsF = (TTask*)aliceF->FindObject("tasks/SDigitizer") ;
260 if ( !sdigitsF ) {
261 cerr << "ERROR: AliPHOSGetter::Post Ser -> Task tasks/SDigitizer" << " not found!" << endl;
262 abort() ;
263 }
264 TTask * phos = (TTask*)sdigitsF->GetListOfTasks()->FindObject("PHOS") ;
265 if ( !phos ) {
266 cerr <<"ERROR: AliPHOSGetter::Post Ser -> tasks/SDigitizer/PHOS" << " not found!" << endl;
267 abort() ;
268 } else {
269 AliPHOSSDigitizer * phossd = (AliPHOSSDigitizer*)phos->GetListOfTasks()->FindObject(sdigitsName.Data()) ;
270 if (phossd) {
271 cout << "INFO: AliPHOSGetter::Post Ser -> Task " << sdigitsName.Data() << " already exists" << endl ;
272 return ;
273 } else
274 phos->Add(sdigitizer) ;
275 }
276
277 } else if ( strcmp(opt, "D") == 0 ) { // digits
278 // the hierarchy is //YSALICE/WhiteBoard/Digits/PHOS/digitsname
279 TClonesArray * digits = new TClonesArray("AliPHOSDigit",20000) ;
280 TString digitsName ;
281 if (name)
282 digitsName = name ;
283 else
284 digitsName = "Digits" ;
285 digits->SetName( digitsName.Data() ) ;
286 TFolder * digitsF = (TFolder*)aliceF->FindObject("WhiteBoard/Digits/PHOS") ;
287 if ( !digitsF ) {
288 cerr << "ERROR: AliPHOSGetter::Post D -> Folder WhiteBoard/Digits/PHOS/" << " not found!" << endl;
289 abort() ;
290 }
291 digitsF->SetTitle(foldertitle) ;
292 if ( digitsF->FindObject( digitsName.Data() ) ) {
293 cerr <<"INFO: AliPHOSGetter::Post D -> Object " << digitsName.Data()
294 << " already exists!" << endl ;
295 return ;
296 }
297 else
298 digitsF->Add(digits) ;
299
300 } else if ( strcmp(opt, "Der") == 0 ) { // sdigizer
301 // the hierarchy is //YSALICE/tasks/Digitizer/PHOS/digitsname
302 AliPHOSDigitizer * digitizer = new AliPHOSDigitizer() ;
303 TString digitsName ;
304 if (name)
305 digitsName = name ;
306 else
307 digitsName = "Digitizer" ;
308 digitizer->SetName( digitsName.Data() ) ;
309 TTask * digitsF = (TTask*)aliceF->FindObject("tasks/Digitizer") ;
310 if ( !digitsF ) {
311 cerr << "ERROR: AliPHOSGetter::Post Der -> Task tasks/Digitizer" << " not found!" << endl;
312 abort() ;
313 }
314 TTask * phos = (TTask*)digitsF->GetListOfTasks()->FindObject("PHOS") ;
315 if ( !phos ) {
316 cerr <<"ERROR: AliPHOSGetter::Post Der -> tasks/Digitizer/PHOS" << " not found!" << endl;
317 abort() ;
318 } else {
319 AliPHOSDigitizer * phosd = (AliPHOSDigitizer*)phos->GetListOfTasks()->FindObject(digitsName.Data()) ;
320 if (phosd) {
321 cout << "INFO: AliPHOSGetter::Post Der -> Task " << digitsName.Data() << " already exists" << endl ;
322 return ;
323 } else
324 phos->Add(digitizer) ;
325 }
326
327 } else if ( strcmp(opt, "R") == 0 ) { // RecPoints
328 // the hierarchy is //YSALICE/WhiteBoard/RecPoints/PHOS/emc/recpointsname
329 // //YSALICE/WhiteBoard/RecPoints/PHOS/cpv/recpointsname
330 TObjArray * emcrp = new TObjArray(100) ;
331 TObjArray * cpvrp = new TObjArray(100) ;
332 TString recpointsName ;
333 if (name)
334 recpointsName = name ;
335 else
336 recpointsName = "RecPoints" ;
337 emcrp->SetName( recpointsName.Data() ) ;
338 cpvrp->SetName( recpointsName.Data() ) ;
339 TFolder * emcrpF = (TFolder*)aliceF->FindObject("WhiteBoard/RecPoints/PHOS/emc") ;
340 TFolder * cpvrpF = (TFolder*)aliceF->FindObject("WhiteBoard/RecPoints/PHOS/cpv") ;
341 emcrpF->SetTitle(foldertitle) ;
342 cpvrpF->SetTitle(foldertitle) ;
343 if ( !emcrpF || !cpvrpF ) {
344 cerr << "ERROR: AliPHOSGetter::Post R -> Folder WhiteBoard/RecPoints/PHOS/emc(cpv)" << " not found!" << endl;
345 abort() ;
346 }
347 // TString title("PHOS Digits") ;
348 if ( emcrpF->FindObject( recpointsName.Data() ) || cpvrpF->FindObject( recpointsName.Data() ) ) {
349 cerr <<"INFO: AliPHOSGetter::Post R -> Object " << recpointsName.Data()
350 << " already exists!" << endl ;
351 return ;
352 }
353 else {
354 emcrpF->Add(emcrp) ;
355 cpvrpF->Add(cpvrp) ;
356 }
357
358 } else if ( strcmp(opt, "Rer") == 0 ) { // clusterizer
359 // the hierarchy is //YSALICE/tasks/Reconstructionner/PHOS/recpointsname
360 AliPHOSClusterizer * clusterizer;
361 if ( strstr(name, "clu-v1") != 0 )
362 clusterizer = new AliPHOSClusterizerv1() ;
363 else {
364 cerr << "ERROR: AliPHOSGetter::Post Rer -> " << name << " unknown clusterizer version" << endl ;
365 abort() ;
366 }
367 TString recpointsName ;
368 if (name)
369 recpointsName = name ;
370 else
371 recpointsName = "Clusterizer" ;
372 clusterizer->SetName( recpointsName.Data() ) ;
373 TTask * reF = (TTask*)aliceF->FindObject("tasks/Reconstructioner") ;
374 if ( !reF ) {
375 cerr << "ERROR: AliPHOSGetter::Post Rer -> Task tasks/Reconstructioner" << " not found!" << endl;
376 abort() ;
377 }
378 TTask * phos = (TTask*)reF->GetListOfTasks()->FindObject("PHOS") ;
379 if ( !phos ) {
380 cerr <<"ERROR: AliPHOSGetter::Post Rer -> tasks/Reconstructioner/PHOS" << " not found!" << endl;
381 abort() ;
382 } else {
383 AliPHOSClusterizer * phoscl = (AliPHOSClusterizer*)phos->GetListOfTasks()->FindObject(recpointsName.Data()) ;
384 if (phoscl) {
385 cout << "INFO: AliPHOSGetter::Post Rer -> Task " << recpointsName.Data() << " already exists" << endl ;
386 return ;
387 } else
388 phos->Add(clusterizer) ;
389 }
390
391 } else if ( strcmp(opt, "T") == 0 ) { //TrackSegments
392 // the hierarchy is //YSALICE/WhiteBoard/TrackSegments/PHOS/tracksegmentsname
393
394 TClonesArray * tracksegments = new TClonesArray("AliPHOSTrackSegment", 200) ;
395 TString tracksegmentsName ;
396 if (name)
397 tracksegmentsName = name ;
398 else
399 tracksegmentsName = "TrackSegments" ;
400 tracksegments->SetName( tracksegmentsName.Data() ) ;
401 TFolder * tracksegmentsF = (TFolder*)aliceF->FindObject("WhiteBoard/TrackSegments/PHOS") ;
402 tracksegmentsF->SetTitle(foldertitle) ;
403 if ( !tracksegmentsF) {
404 cerr << "ERROR: AliPHOSGetter::Post T -> Folder WhiteBoard/TrackSegments/PHOS" << " not found!" << endl;
405 abort() ;
406 }
407 if ( tracksegmentsF->FindObject( tracksegmentsName.Data() ) ) {
408 cerr <<"INFO: AliPHOSGetter::Post T -> Object " << tracksegmentsName.Data()
409 << " already exists!" << endl ;
410 return ;
411 }
412 else
413 tracksegmentsF->Add(tracksegments) ;
414
415 } else if ( strcmp(opt, "Ter") == 0 ) { // TrackSegmentsMaker
416 // the hierarchy is //YSALICE/tasks/Reconstructionner/PHOS/tracksegmentsname
417 AliPHOSTrackSegmentMaker * tracksegmentmaker ;
418 if ( strstr(name, "tsm-v1") != 0 )
419 tracksegmentmaker = new AliPHOSTrackSegmentMakerv1() ;
420 else {
421 cerr << "ERROR: AliPHOSGetter::Post Ter -> " << name << " unknown track segment maker version" << endl ;
422 abort() ;
423 }
424 TString tracksegmentsName ;
425 if (name)
426 tracksegmentsName = name ;
427 else
428 tracksegmentsName = "TrackSegmentMaker" ;
429 tracksegmentmaker->SetName( tracksegmentsName.Data() ) ;
430 TTask * reF = (TTask*)aliceF->FindObject("tasks/Reconstructioner") ;
431 if ( !reF ) {
432 cerr << "ERROR: AliPHOSGetter::Post Ter -> Task tasks/Reconstructioner" << " not found!" << endl;
433 abort() ;
434 }
435 TTask * phos = (TTask*)reF->GetListOfTasks()->FindObject("PHOS") ;
436 if ( !phos ) {
437 cerr <<"ERROR: AliPHOSGetter::Post Ter -> tasks/Reconstructioner/PHOS" << " not found!" << endl;
438 abort() ;
439 } else {
440 AliPHOSTrackSegmentMaker * phosts = (AliPHOSTrackSegmentMaker*)phos->GetListOfTasks()->FindObject(tracksegmentsName.Data()) ;
441 if (phosts) {
442 cout << "INFO: AliPHOSGetter::Post Ter -> Task " << tracksegmentsName.Data() << " already exists" << endl ;
443 return ;
444 } else
445 phos->Add(tracksegmentmaker) ;
446 }
447
448 } else if ( strcmp(opt, "P") == 0 ) { // RecParticles
449 // the hierarchy is //YSALICE/WhiteBoard/RecParticles/PHOS/recparticlesname
450
451 TClonesArray * recparticles = new TClonesArray("AliPHOSRecParticle", 200) ;
452 TString recparticlesName ;
453 if (name)
454 recparticlesName = name ;
455 else
456 recparticlesName = "RecParticles" ;
457 recparticles->SetName( recparticlesName.Data() ) ;
458 TFolder * recparticlesF = (TFolder*)aliceF->FindObject("WhiteBoard/RecParticles/PHOS") ;
459 recparticlesF->SetTitle(foldertitle) ;
460 if ( !recparticlesF) {
461 cerr << "ERROR: AliPHOSGetter::Post P -> Folder WhiteBoard/RecParticles/PHOS" << " not found!" << endl;
462 abort() ;
463 }
464 if ( recparticlesF->FindObject( recparticlesName.Data() ) ) {
465 cerr <<"INFO: AliPHOSGetter::Post P -> Object " << recparticlesName.Data()
466 << " already exists!" << endl ;
467 return ;
468 }
469 else
470 recparticlesF->Add(recparticles) ;
471
472 } else if ( strcmp(opt, "Per") == 0 ) { // PID Maker
473 // the hierarchy is //YSALICE/tasks/Reconstructionner/PHOS/recparticlesname
474 AliPHOSPID * pid ;
475 if ( strstr(name, "pid-v1") != 0 )
476 pid = new AliPHOSPIDv1() ;
477 else {
478 cerr << "ERROR: AliPHOSGetter::Post Per -> " << name << " unknown PID maker version" << endl ;
479 abort() ;
480 }
481 TString recparticlesName ;
482 if (name)
483 recparticlesName = name ;
484 else
485 recparticlesName = "PID" ;
486 pid->SetName( recparticlesName.Data() ) ;
487 TTask * reF = (TTask*)aliceF->FindObject("tasks/Reconstructioner") ;
488 if ( !reF ) {
489 cerr << "ERROR: AliPHOSGetter::Post Per -> Task tasks/Reconstructioner" << " not found!" << endl;
490 abort() ;
491 }
492 TTask * phos = (TTask*)reF->GetListOfTasks()->FindObject("PHOS") ;
493 if ( !phos ) {
494 cerr <<"ERROR: AliPHOSGetter::Post Per -> tasks/Reconstructioner/PHOS" << " not found!" << endl;
495 abort() ;
496 } else {
497 AliPHOSPID * phospid = (AliPHOSPID*)phos->GetListOfTasks()->FindObject(recparticlesName.Data()) ;
498 if (phospid) {
499 cout << "INFO: AliPHOSGetter::Post Per -> Task " << recparticlesName.Data() << " already exists" << endl ;
500 return ;
501 } else
502 phos->Add(pid) ;
503 }
504 }
505 else if ( strcmp(opt, "QA") == 0 ) { // Alarms
506 // the hierarchy is //YSALICE/WhiteBoard/Alarms/PHOS/
507
508 TFolder * alarmsF = new TFolder() ;
509 TString alarmsName ;
510 if (name)
511 alarmsName = name ;
512 else
513 alarmsName = "Alarm with no name" ;
514 alarmsF->SetName( alarmsName.Data() ) ;
515 alarmsF->SetTitle(foldertitle) ;
516 TFolder * qaaF = (TFolder*)aliceF->FindObject("WhiteBoard/QAAlarms") ;
517 if ( !qaaF) {
518 cerr << "ERROR: AliPHOSGetter::Post QA -> Folder WhiteBoard/QAAlarms/" << " not found!" << endl;
519 return ;
520 }
521 if ( qaaF->FindObject( alarmsName.Data() ) )
522 qaaF->RecursiveRemove( qaaF->FindObject( alarmsName.Data() ) ) ;
523
524 qaaF->Add(alarmsF) ;
525
526 }
527}
528
529//____________________________________________________________________________
530const TParticle * AliPHOSGetter::Primary(Int_t index) const
531{
532 // Return primary particle numbered by <index>
533
534 if(index < 0)
535 return 0 ;
536
537 Int_t primaryIndex = index % 10000000 ;
538 Int_t primaryList = (Int_t ) ((index-primaryIndex)/10000000.) ;
539
540 if ( primaryList > 0 ) {
541 cout << " Getter does not support currently Mixing of primary " << endl ;
542 cout << " can not return primary: " << index<< " (list "<< primaryList<< " primary # " << primaryIndex << " )"<<endl ;
543 return 0;
544 }
545
546 return gAlice->Particle(primaryIndex) ;
547
548}
549
550//____________________________________________________________________________
551void AliPHOSGetter::ReadTreeD()
552{
553 // Read the digit tree gAlice->TreeD()
554 if(gAlice->TreeD()== 0){
555 cerr << "ERROR: AliPHOSGetter::ReadTreeD: can not read TreeD " << endl ;
556 return ;
557 }
558
559 TObjArray * lob = (TObjArray*)gAlice->TreeD()->GetListOfBranches() ;
560 TIter next(lob) ;
561 TBranch * branch = 0 ;
562 TBranch * digitsbranch = 0 ;
563 TBranch * digitizerbranch = 0 ;
564 Bool_t phosfound = kFALSE, digitizerfound = kFALSE ;
565
566 while ( (branch = (TBranch*)next()) && (!phosfound || !digitizerfound) ) {
567 if ( (strcmp(branch->GetName(), "PHOS")==0) && (strcmp(branch->GetTitle(), fDigitsTitle)==0) ) {
568 digitsbranch = branch ;
569 phosfound = kTRUE ;
570 }
571 else if ( (strcmp(branch->GetName(), "AliPHOSDigitizer")==0) && (strcmp(branch->GetTitle(), fDigitsTitle)==0) ) {
572 digitizerbranch = branch ;
573 digitizerfound = kTRUE ;
574 }
575 }
576
577 if ( !phosfound || !digitizerfound ) {
578 cerr << "WARNING: AliPHOSGetter::ReadTreeD -> Cannot find Digits and/or Digitizer with name " << fDigitsTitle << endl ;
579 return ;
580 }
581
582
583 // Post the Digits
584 Post(fHeaderFile, "D", fDigitsTitle) ;
585
586 // Post the Digitizer
587 Post(fHeaderFile, "Der", fDigitsTitle) ;
588
589 TClonesArray * digits = Digits(fDigitsTitle) ;
590 digits->Clear() ;
591 digitsbranch ->SetAddress(&digits) ;
592
593 AliPHOSDigitizer * digitizer = Digitizer(fDigitsTitle) ;
594 digitizerbranch->SetAddress(&digitizer) ;
595
596 digitsbranch ->GetEntry(0) ;
597 digitizerbranch->GetEntry(0) ;
598
599}
600
601//____________________________________________________________________________
602void AliPHOSGetter::ReadTreeH()
603{
604 // Read the first entry of PHOS branch in hit tree gAlice->TreeH()
605
606 if(gAlice->TreeH()== 0){
607 cerr << "ERROR: AliPHOSGetter::ReadTreeH: -> Cannot read TreeH " << endl ;
608 return ;
609 }
610
611 TBranch * hitsbranch = (TBranch*)gAlice->TreeH()->GetListOfBranches()->FindObject("PHOS") ;
612 if ( !hitsbranch ) {
613 cerr << "WARNING: AliPHOSGetter::ReadTreeH -> Cannot find branch PHOS" << endl ;
614 } else {
615 TClonesArray * hits = Hits() ;
616 hits->Clear() ;
617 hitsbranch->SetAddress(&hits) ;
618 hitsbranch->GetEntry(0) ;
619 }
620}
621
622//____________________________________________________________________________
623void AliPHOSGetter::ReadTreeQA()
624{
625 // Read the digit tree gAlice->TreeQA()
626 // so far only PHOS knows about this Tree
627
628 if(PHOS()->TreeQA()== 0){
629 cerr << "ERROR: AliPHOSGetter::ReadTreeQA: can not read TreeQA " << endl ;
630 return ;
631 }
632
633 TBranch * qabranch = PHOS()->TreeQA()->GetBranch("PHOS") ;
634 if (!qabranch) {
635 cerr << "WARNING: AliPHOSGetter::ReadTreeQA -> Cannot find QA Alarms for PHOS" << endl ;
636 return ;
637 }
638
639 // Post the QA Alarms
640 Post(fHeaderFile, "QA", "PHOS") ;
641 TFolder * alarmsF = Alarms() ;
642 alarmsF->Clear() ;
643 qabranch->SetAddress(&alarmsF) ;
644 qabranch->GetEntry(0) ;
645
646}
647
648//____________________________________________________________________________
649void AliPHOSGetter::ReadTreeR()
650{
651 // Read the reconstrunction tree gAlice->TreeR()
652
653 if(gAlice->TreeR()== 0){
654 cout << "ERROR: AliPHOSGetter::ReadTreeR: can not read TreeR " << endl ;
655 return ;
656 }
657 // RecPoints
658 TObjArray * lob = (TObjArray*)gAlice->TreeR()->GetListOfBranches() ;
659 TIter next(lob) ;
660 TBranch * branch = 0 ;
661 TBranch * emcbranch = 0 ;
662 TBranch * cpvbranch = 0 ;
663 TBranch * clusterizerbranch = 0 ;
664 Bool_t phosemcrpfound = kFALSE, phoscpvrpfound = kFALSE, clusterizerfound = kFALSE ;
665
666 while ( (branch = (TBranch*)next()) && (!phosemcrpfound || !phoscpvrpfound || !clusterizerfound) ) {
667 if ( (strcmp(branch->GetName(), "PHOSEmcRP")==0) && (strcmp(branch->GetTitle(), fRecPointsTitle)==0) ) {
668 emcbranch = branch ;
669 phosemcrpfound = kTRUE ;
670 }
671 else if ( (strcmp(branch->GetName(), "PHOSCpvRP")==0) && (strcmp(branch->GetTitle(), fRecPointsTitle)==0) ) {
672 cpvbranch = branch ;
673 phoscpvrpfound = kTRUE ;
674 }
675 else if ( (strcmp(branch->GetName(), "AliPHOSClusterizer")==0) && (strcmp(branch->GetTitle(), fRecPointsTitle)==0) ) {
676 clusterizerbranch = branch ;
677 clusterizerfound = kTRUE ;
678 }
679 }
680
681 if ( !phosemcrpfound || !phoscpvrpfound || !clusterizerfound ) {
682 cerr << "WARNING: AliPHOSGetter::ReadTreeR -> Cannot find RecPoints and/or Clusterizer with name " << fRecPointsTitle << endl ;
683 return ;
684 }
685
686 // Post the RecPoints
687 Post(fHeaderFile, "R", fRecPointsTitle) ;
688
689 // Post the Clusterizer
690 // Need the version first
691 AliPHOSClusterizer * clusterizer = 0 ;
692 clusterizerbranch->SetAddress(&clusterizer) ;
693 clusterizerbranch->GetEntry(0) ;
694 TString clusterizerName(fRecPointsTitle) ;
695 clusterizerName.Append(clusterizer->Version()) ;
696 delete clusterizer ;
697 Post(fHeaderFile, "Rer", clusterizerName) ;
698
699 TObjArray * emcRecPoints = EmcRecPoints(fRecPointsTitle) ;
700 emcRecPoints->Clear() ;
701 emcbranch->SetAddress(&emcRecPoints) ;
702
703 TObjArray * cpvRecPoints = CpvRecPoints(fRecPointsTitle) ;
704 cpvRecPoints->Clear() ;
705 cpvbranch->SetAddress(&cpvRecPoints) ;
706
707 clusterizer = Clusterizer(clusterizerName) ;
708 clusterizerbranch->SetAddress(&clusterizer) ;
709
710 emcbranch ->GetEntry(0) ;
711 cpvbranch ->GetEntry(0) ;
712 clusterizerbranch->GetEntry(0) ;
713
714 // TrackSegments
715 next.Reset() ;
716 TBranch * tsbranch = 0 ;
717 TBranch * tsmakerbranch = 0 ;
718 Bool_t phostsfound = kFALSE, tsmakerfound = kFALSE ;
719
720 while ( (branch = (TBranch*)next()) && (!phostsfound || !tsmakerfound) ) {
721 if ( (strcmp(branch->GetName(), "PHOSTS")==0) && (strcmp(branch->GetTitle(), fTrackSegmentsTitle)==0) ) {
722 tsbranch = branch ;
723 phostsfound = kTRUE ;
724 }
725 else if ( (strcmp(branch->GetName(), "AliPHOSTrackSegmentMaker")==0) && (strcmp(branch->GetTitle(), fTrackSegmentsTitle)==0) ) {
726 tsmakerbranch = branch ;
727 tsmakerfound = kTRUE ;
728 }
729 }
730
731 if ( !phostsfound || !tsmakerfound ) {
732 cerr << "WARNING: AliPHOSGetter::ReadTreeR -> Cannot find TrackSegments and/or TrackSegmentMaker with name " << fTrackSegmentsTitle << endl ;
733 return ;
734 }
735
736 // Post the TrackSegments
737 Post(fHeaderFile, "T", fTrackSegmentsTitle) ;
738
739 // Post the TrackSegment Maker
740 // Need the version first
741 AliPHOSTrackSegmentMaker * tsmaker = 0 ;
742 tsmakerbranch->SetAddress(&tsmaker) ;
743 tsmakerbranch->GetEntry(0) ;
744 TString tsmakerName(fTrackSegmentsTitle) ;
745 tsmakerName.Append(tsmaker->Version()) ;
746 delete tsmaker ;
747 Post(fHeaderFile, "Ter", tsmakerName) ;
748
749 TClonesArray * tracksegments = TrackSegments(fTrackSegmentsTitle) ;
750 tracksegments->Clear() ;
751 tsbranch->SetAddress(&tracksegments) ;
752
753 tsmaker = TrackSegmentMaker(tsmakerName) ;
754 tsmakerbranch->SetAddress(&tsmaker) ;
755
756 tsmakerbranch ->GetEntry(0) ;
757 tsbranch ->GetEntry(0) ;
758
759 // RecParticles
760 next.Reset() ;
761 TBranch * rpabranch = 0 ;
762 TBranch * pidbranch = 0 ;
763 Bool_t phosrpafound = kFALSE, pidfound = kFALSE ;
764
765 while ( (branch = (TBranch*)next()) && (!phosrpafound || !pidfound) ) {
766 if ( (strcmp(branch->GetName(), "PHOSRP")==0) && (strcmp(branch->GetTitle(), fRecParticlesTitle)==0) ) {
767 rpabranch = branch ;
768 phosrpafound = kTRUE ;
769 }
770 else if ( (strcmp(branch->GetName(), "AliPHOSPID")==0) && (strcmp(branch->GetTitle(), fRecParticlesTitle)==0) ) {
771 pidbranch = branch ;
772 pidfound = kTRUE ;
773 }
774 }
775
776 if ( !phosrpafound || !pidfound ) {
777 cerr << "WARNING: AliPHOSGetter::ReadTreeR -> Cannot find RecParticles and/or PID with name " << fRecParticlesTitle << endl ;
778 return ;
779 }
780
781 // Post the RecParticles
782 Post(fHeaderFile, "P", fRecParticlesTitle) ;
783
784 // Post the PID
785 // Need the version first
786 AliPHOSPID * pid = 0 ;
787 pidbranch->SetAddress(&pid) ;
788 pidbranch->GetEntry(0) ;
789 TString pidName(fRecParticlesTitle) ;
790 pidName.Append(pid->Version()) ;
791 delete pid ;
792
793 Post(fHeaderFile, "Per", pidName) ;
794
795 TClonesArray * recParticles = RecParticles(fRecParticlesTitle) ;
796 recParticles->Clear() ;
797 rpabranch->SetAddress(&recParticles) ;
798
799 pid = PID(pidName) ;
800 pidbranch->SetAddress(&pid) ;
801
802 pidbranch ->GetEntry(0) ;
803 rpabranch ->GetEntry(0) ;
804
805}
806
807//____________________________________________________________________________
808void AliPHOSGetter::ReadTreeS()
809{
810 // Read the summable digits tree gAlice->TreeS()
811
812 if(gAlice->TreeS()== 0){
813 cerr << "ERROR: AliPHOSGetter::ReadTreeS -> Cannot find TreeS " << endl ;
814 return ;
815 }
816
817 TObjArray * lob = (TObjArray*)gAlice->TreeS()->GetListOfBranches() ;
818 TIter next(lob) ;
819 TBranch * branch = 0 ;
820 TBranch * sdigitsbranch = 0 ;
821 TBranch * sdigitizerbranch = 0 ;
822 Bool_t phosfound = kFALSE, sdigitizerfound = kFALSE ;
823
824 while ( (branch = (TBranch*)next()) && (!phosfound || !sdigitizerfound) ) {
825 if ( (strcmp(branch->GetName(), "PHOS")==0) && (strcmp(branch->GetTitle(), fSDigitsTitle)==0) ) {
826 sdigitsbranch = branch ;
827 phosfound = kTRUE ;
828 }
829 else if ( (strcmp(branch->GetName(), "AliPHOSSDigitizer")==0) && (strcmp(branch->GetTitle(), fSDigitsTitle)==0) ) {
830 sdigitizerbranch = branch ;
831 sdigitizerfound = kTRUE ;
832 }
833 }
834
835 if ( !phosfound || !sdigitizerfound ) {
836 cerr << "WARNING: AliPHOSGetter::ReadTreeS -> Cannot find SDigits and/or SDigitizer with name " << fSDigitsTitle << endl ;
837 return ;
838 }
839
840 // -- the SDigits
841 Post(fHeaderFile, "S", fSDigitsTitle) ;
842
843 // Post the SDigitizer
844 Post(fHeaderFile, "Ser", fSDigitsTitle) ;
845
846 TClonesArray * sdigits = SDigits(fSDigitsTitle) ;
847 sdigits->Clear() ;
848 sdigitsbranch->SetAddress(&sdigits) ;
849
850 AliPHOSSDigitizer * sdigitizer = SDigitizer(fSDigitsTitle) ;
851 sdigitizerbranch->SetAddress(&sdigitizer) ;
852
853 sdigitsbranch->GetEvent(0) ;
854 sdigitizerbranch->GetEvent(0) ;
855
856}
857
858//____________________________________________________________________________
859void AliPHOSGetter::ReadPrimaries()
860{
861 // Reads specific branches of primaries
862
863 fNPrimaries = gAlice->GetNtrack();
864
865 // //Check, is it necessary to open new files
866 // TArrayI* events = fDigitizer->GetCurrentEvents() ;
867 // TClonesArray * filenames = fDigitizer->GetHeadersFiles() ;
868// Int_t input ;
869// for(input = 0; input < filenames->GetEntriesFast(); input++){
870
871// TObjString * filename = (TObjString *) filenames->At(input) ;
872
873// //Test, if this file already open
874// TFile *file = (TFile*) gROOT->GetFile( filename->GetString() ) ;
875// if(file == 0)
876// file = new TFile( filename->GetString()) ;
877// file->cd() ;
878
879// // Get Kine Tree from file
880// // char treeName[20];
881// // sprintf(treeName,"TreeK%d",events->At(input));
882// // TTree * treeK = (TTree*)gDirectory->Get(treeName);
883// // if (treeK)
884// // treeK->SetBranchAddress("Particles", &fParticleBuffer);
885// // else
886// // cout << "AliPHOSGetter: cannot find Kine Tree for event:" << events->At(input) << endl;
887
888// // // Create the particle stack
889// // if(!fParticles) fParticles = new TClonesArray("TParticle",1000);
890// // // Build the pointer list
891// // if(fParticleMap) { <----
892// // fParticleMap->Clear();
893// // fParticleMap->Expand(treeK->GetEntries());
894// // } else
895// // fParticleMap = new TObjArray(treeK->GetEntries());
896
897// // From gAlice->Particle(i)
898
899
900// // if(!(*fParticleMap)[i]) {
901// // Int_t nentries = fParticles->GetEntries();
902
903// // // algorithmic way of getting entry index
904// // // (primary particles are filled after secondaries)
905// // Int_t entry;
906// // if (i<fHeader.GetNprimary())
907// // entry = i+fHeader.GetNsecondary();
908// // else
909// // entry = i-fHeader.GetNprimary();
910
911// // // only check the algorithmic way and give
912// // // the fatal error if it is wrong
913// // if (entry != fParticleFileMap[i]) {
914// // Fatal("Particle",
915// // "!!!! The algorithmic way is WRONG: !!!\n entry: %d map: %d",
916// // entry, fParticleFileMap[i]);
917// // }
918
919// // fTreeK->GetEntry(fParticleFileMap[i]);
920// // new ((*fParticles)[nentries]) TParticle(*fParticleBuffer);
921// // fParticleMap->AddAt((*fParticles)[nentries],i);
922// // }
923// // return (TParticle *) (*fParticleMap)[i];
924
925
926
927// }
928
929
930// //scan over opened files and read corresponding TreeK##
931
932 return ;
933}
934//____________________________________________________________________________
935void AliPHOSGetter::Event(Int_t event)
936{
937 // Reads the content of all Tree's S, D and R
938
939 if ( event > gAlice->TreeE()->GetEntries() ) {
940 cerr << "ERROR: AliPHOSGetter::Event -> There are only " << gAlice->TreeE()->GetEntries() << " events in this file" << endl ;
941 return ;
942 }
943
944 gAlice->GetEvent(event) ;
945
946 ReadTreeH() ;
947 ReadTreeS() ;
948 ReadTreeD() ;
949 ReadTreeR() ;
950 ReadTreeQA() ;
951 ReadPrimaries() ;
952
953}
954
955//____________________________________________________________________________
956const TObject * AliPHOSGetter::ReturnO(TString what, TString name, TString file) const
957{
958 // get the object named "what" from the folder
959 // folders are named like //YSAlice/WhiteBoard/what/PHOS/name
960
961 if ( file.IsNull() )
962 file = fHeaderFile ;
963 TString path("WhiteBoard/") ;
964 if ( name.IsNull() ) {
965 if ( what.CompareTo("Hits") == 0 ) {
966 path += what ;
967 path += "/PHOS/";
968 path += what ;
969 }
970 else if ( what.CompareTo("SDigits") == 0 ) {
971 path += what ;
972 path += "/PHOS/";
973 path += file ;
974 path += "/" ;
975 path += fSDigitsTitle ;
976 }
977 else if ( what.CompareTo("Digits") == 0 ){
978 path += what ;
979 path += "/PHOS/";
980 path += fDigitsTitle ;
981 }
982 else if ( what.CompareTo("EmcRecPoints") == 0 ) {
983 path += "RecPoints/PHOS/";
984 path += "emc/" ;
985 path += fRecPointsTitle ;
986 }
987 else if ( what.CompareTo("CpvRecPoints") == 0 ) {
988 path += "RecPoints/PHOS/";
989 path += "cpv/" ;
990 path += fRecPointsTitle ;
991 }
992 else if ( what.CompareTo("TrackSegments") == 0 ) {
993 path += "TrackSegments/PHOS/";
994 path += fTrackSegmentsTitle ;
995 }
996 else if ( what.CompareTo("RecParticles") == 0 ) {
997 path += "RecParticles/PHOS/";
998 path += fRecParticlesTitle ;
999 }
1000 else if ( what.CompareTo("Alarms") == 0 ) {
1001 path += "QAAlarms/PHOS";
1002 }
1003 }
1004 else {
1005 if ( what.CompareTo("SDigits") == 0 ) {
1006 path += what ;
1007 path += "/PHOS/";
1008 path += file ;
1009 path += "/" ;
1010 path += name ;
1011 }
1012 else if ( what.CompareTo("Digits") == 0 ) {
1013 path += what ;
1014 path += "/PHOS/";
1015 path += name ;
1016 }
1017 else if ( what.CompareTo("EmcRecPoints") == 0 ) {
1018 path += "RecPoints/PHOS/";
1019 path += "emc/" ;
1020 path += name ;
1021 }
1022 else if ( what.CompareTo("CpvRecPoints") == 0 ) {
1023 path += "RecPoints/PHOS/";
1024 path += "cpv/" ;
1025 path += name ;
1026 }
1027 else if ( what.CompareTo("TrackSegments") == 0 ) {
1028 path += "TrackSegments/PHOS/";
1029 path += name ;
1030 }
1031 else if ( what.CompareTo("RecParticles") == 0 ) {
1032 path += "RecParticles/PHOS/";
1033 path += name ;
1034 }
1035 else if ( what.CompareTo("Alarms") == 0 ) {
1036 path += "QAAlarms/PHOS/";
1037 path += name ;
1038 }
1039 }
1040 path.Prepend("YSAlice/") ;
1041 TObject * phosO = (TObject*)gROOT->FindObjectAny(path) ;
1042 if (!phosO) {
1043 cerr << "ERROR : AliPHOSGetter::ReturnO -> Object " << path << " not found!" << endl ;
1044 abort() ;
1045 }
1046 return phosO ;
1047}
1048
1049//____________________________________________________________________________
1050const TTask * AliPHOSGetter::ReturnT(TString what, TString name) const
1051{
1052 // get the TTask named "what" from the folder
1053 // folders are named like //YSAlice/Tasks/what/PHOS/name
1054
1055 TString path("tasks") ;
1056
1057 if ( what.CompareTo("SDigitizer") == 0 )
1058 path += "/SDigitizer" ;
1059 else if ( what.CompareTo("Digitizer") == 0 )
1060 path += "/Digitizer" ;
1061 else if ( what.CompareTo("Clusterizer") == 0 )
1062 path += "/Reconstructioner" ;
1063 else if ( what.CompareTo("TrackSegmentMaker") == 0 )
1064 path += "/Reconstructioner" ;
1065 else if ( what.CompareTo("PID") == 0 )
1066 path += "/Reconstructioner" ;
1067
1068 TFolder * aliceF = (TFolder*)gROOT->FindObjectAny("YSAlice") ;
1069 TTask * aliceT = (TTask*)aliceF->FindObject(path) ;
1070
1071 if (!aliceT) {
1072 cerr << "ERROR: AliPHOSGetter::ReturnT -> Task " << path << " not found!" << endl ;
1073 abort() ;
1074 }
1075
1076 TTask * phosT = (TTask*)aliceT->GetListOfTasks()->FindObject("PHOS") ;
1077 if (!phosT) {
1078 cerr << "ERROR: AliPHOSGetter::ReturnT -> Task " << path << "/PHOS not found!" << endl ;
1079 abort() ;
1080 }
1081 TList * l = phosT->GetListOfTasks() ;
1082
1083 if (what.CompareTo("SDigitizer") == 0) {
1084 if ( name.IsNull() )
1085 name = fSDigitsTitle ;
1086 } else if (what.CompareTo("Digitizer") == 0){
1087 if ( name.IsNull() )
1088 name = fDigitsTitle ;
1089 } else if (what.CompareTo("Clusterizer") == 0){
1090 if ( name.IsNull() )
1091 name = fRecPointsTitle ;
1092 }
1093 else if (what.CompareTo("TrackSegmentMaker") == 0){
1094 if ( name.IsNull() )
1095 name = fTrackSegmentsTitle ;
1096 }
1097 else if (what.CompareTo("PID") == 0){
1098 if ( name.IsNull() )
1099 name = fRecParticlesTitle ;
1100 }
1101
1102 TTask * task = (TTask*)l->FindObject(name) ;
1103
1104 if (!task)
1105 cout << "WARNING: AliPHOSGetter::ReturnT -> Task " << path << "/" << name << " not found!" << endl ;
1106
1107 return task ;
1108}