1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
19 29.05.2001 Yuri Kharlov:
20 Everywhere reading the treese TTree->GetEvent(i)
21 is replaced by reading the branches TBranch->GetEntry(0)
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.
33 // An example of how to use (see also class AliPHOSAnalyser):
34 // AliPHOSIndexToObject * please = AliPHOSIndexToObject::GetInstance("galice.root","RecParticles","") ;
35 // for(Int_t irecp = 0; irecp < please->GimeNRecParticles() ; irecp++)
36 // AliPHOSRecParticle * part = please->GimeRecParticle(1) ;
38 // please->GetEvent(event) ; // reads new event from galice.root
40 //*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC KI & SUBATECH)
41 //*-- Complitely redesigned by Dmitri Peressounko March 2001
42 //////////////////////////////////////////////////////////////////////////////
45 // --- ROOT system ---
50 #include "TObjString.h"
52 // --- Standard library ---
55 // --- AliRoot header files ---
58 #include "AliPHOSIndexToObject.h"
59 #include "AliPHOSDigitizer.h"
60 #include "AliPHOSSDigitizer.h"
61 #include "AliPHOSClusterizer.h"
62 #include "AliPHOSClusterizerv1.h"
63 #include "AliPHOSTrackSegmentMaker.h"
64 #include "AliPHOSTrackSegmentMakerv1.h"
65 #include "AliPHOSTrackSegment.h"
66 #include "AliPHOSPID.h"
67 #include "AliPHOSPIDv1.h"
69 ClassImp(AliPHOSIndexToObject)
71 AliPHOSIndexToObject * AliPHOSIndexToObject::fgObjGetter = 0 ;
73 //____________________________________________________________________________
74 AliPHOSIndexToObject::AliPHOSIndexToObject(const char* headerFile,const char* branch,const char* branchTitle )
76 //Initialize all lists
79 fSDigits = new TClonesArray("AliPHOSDigit",100) ;
80 fDigits = new TClonesArray("AliPHOSDigit",100) ;
81 fEmcRecPoints = new TObjArray(100) ;
82 fCpvRecPoints = new TObjArray(100) ;
83 fTS = new TClonesArray("AliPHOSTrackSegment",100) ;
84 fRecParticles = new TClonesArray("AliPHOSRecParticle",100) ;
85 fPrimaries = new TObjArray(1) ;
94 fHeaderFile = headerFile ;
95 TFile * file = (TFile*) gROOT->GetFile(fHeaderFile.Data() ) ;
98 if(fHeaderFile.Contains("rfio")) // if we read file using HPSS
99 file = TFile::Open(fHeaderFile.Data(),"update") ;
101 file = new TFile(fHeaderFile.Data(),"update") ;
102 gAlice = (AliRun *) file->Get("gAlice") ;
105 fMaxEvent = (Int_t) gAlice->TreeE()->GetEntries() ;
107 DefineBranchTitles(branch,branchTitle) ;
109 //Now read all data from trees
114 //____________________________________________________________________________
115 void AliPHOSIndexToObject:: DefineBranchTitles(const char* startBranch,const char* branchTitle)
117 // Points to the branches of all reconstructed objects with the specified names
119 gAlice->GetEvent(0) ;
120 // Read all reconstruction classes to extract titles of
121 // branches, constituing "reconstruction branch"
122 AliPHOSPID * pids[50]; // here AliPHOSPID's will be stored
124 AliPHOSTrackSegmentMaker * tsms[50] ;
126 AliPHOSClusterizer * clus[50] ;
128 AliPHOSDigitizer * digs[50];
130 AliPHOSSDigitizer * sdigs[50];
134 TObjArray * branches = gAlice->TreeR()->GetListOfBranches() ;
137 for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){
138 branch=(TBranch *) branches->At(ibranch) ;
139 if( (strcmp(branch->GetName(),"AliPHOSPID") == 0) ){
140 pids[ipids] = new AliPHOSPIDv1() ;
141 branch->SetAddress(& (pids[ipids])) ;
142 branch->GetEntry(0) ;
145 if( (strcmp(branch->GetName(),"AliPHOSTrackSegmentMaker") == 0) ){
146 tsms[itsms] = new AliPHOSTrackSegmentMakerv1() ;
147 branch->SetAddress(&(tsms[itsms])) ;
148 branch->GetEntry(0) ;
151 if( (strcmp(branch->GetName(),"AliPHOSClusterizer") == 0) ){
152 clus[iclus] = new AliPHOSClusterizerv1() ;
153 branch->SetAddress(&(clus[iclus])) ;
154 branch->GetEntry(0) ;
158 // gAlice->TreeR()->GetEvent(0) ;
162 branches = gAlice->TreeD()->GetListOfBranches() ;
163 for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){
164 branch=(TBranch *) branches->At(ibranch) ;
165 if( (strcmp(branch->GetName(),"AliPHOSDigitizer") == 0) ){
166 digs[idigs] = new AliPHOSDigitizer() ;
167 branch->SetAddress(&(digs[idigs])) ;
168 branch->GetEntry(0) ;
172 // gAlice->TreeD()->GetEvent(0) ;
175 branches = gAlice->TreeS()->GetListOfBranches() ;
176 for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){
177 branch=(TBranch *) branches->At(ibranch) ;
178 gAlice->TreeS()->GetBranch(branch->GetName())->GetEntry(0) ; // YK
179 if( (strcmp(branch->GetName(),"AliPHOSSDigitizer") == 0) ){
180 sdigs[isdigs] = new AliPHOSSDigitizer() ;
181 branch->SetAddress(&(sdigs[isdigs])) ;
182 branch->GetEntry(0) ;
186 // gAlice->TreeS()->GetEvent(0) ;
188 // now choose among read Reconstruction classes those,
189 // which constituite "reconstruction branch"
190 Bool_t pidDefined = kFALSE ;
191 Bool_t tsmDefined = kFALSE ;
192 Bool_t cluDefined = kFALSE ;
193 Bool_t digDefined = kFALSE ;
194 Bool_t sdigDefined = kFALSE ;
197 // First, go from the end (RecParticles) to the beginning(SDigits)
198 if((strcmp(startBranch,"PHOSRP") == 0)||(strcmp(startBranch,"AliPHOSPID") == 0)){
199 fRPTitle = branchTitle ;
200 for(index = 0; index < ipids ; index++){
201 if(fRPTitle.CompareTo(((AliPHOSPID*)pids[index])->GetRecParticlesBranch())== 0){
203 fTSTitle =((AliPHOSPID*)pids[index])->GetTrackSegmentsBranch() ;
207 if((strcmp(startBranch,"PHOSTS") == 0)||(strcmp(startBranch,"AliPHOSTrackSegmentMaker") == 0)|| pidDefined ) {
209 fTSTitle = branchTitle ;
210 for(index = 0; index < itsms ; index++)
211 if(fTSTitle.CompareTo(((AliPHOSTrackSegmentMaker*)tsms[index])->GetTrackSegmentsBranch())== 0){
213 fRecPointsTitle =((AliPHOSTrackSegmentMaker*)tsms[index])->GetRecPointsBranch() ;
216 if((strcmp(startBranch,"PHOSEmcRP") == 0) ||
217 (strcmp(startBranch,"PHOSCpvRP") == 0) ||
218 (strcmp(startBranch,"AliPHOSClusterizer") == 0) || tsmDefined ) {
220 fRecPointsTitle = branchTitle ;
221 for(index = 0; index < iclus ; index++)
222 if(fRecPointsTitle.CompareTo(((AliPHOSClusterizer*)clus[index])->GetRecPointsBranch())== 0){
224 fDigitsTitle =((AliPHOSClusterizer*)clus[index])->GetDigitsBranch() ;
227 if((strcmp(startBranch,"PHOS") == 0) || (strcmp(startBranch,"AliPHOSDigitizer") == 0) ||cluDefined ) {
229 fDigitsTitle = branchTitle ;
230 for(index = 0; index < idigs ; index++) {
231 if(fDigitsTitle.CompareTo(((AliPHOSDigitizer*)digs[index])->GetDigitsBranch())== 0){
233 fSDigitsTitle =((AliPHOSDigitizer*)digs[index])->GetSDigitsBranch() ;
237 for(index = 0; index < idigs ; index++)
238 if(fSDigitsTitle.CompareTo(((AliPHOSSDigitizer*)sdigs[index])->GetSDigitsBranch())== 0)
239 sdigDefined = kTRUE ;
242 cout << "Can not define titles of branches " << endl ;
246 // Now we go in the inverse direction: from sdigits to recparticles - for the
247 // case, if we started decending not from RecParticles, but e.g. from digits
250 for(index = 0; index < iclus ; index++)
251 if(fDigitsTitle.CompareTo(((AliPHOSClusterizer*)clus[index])->GetDigitsBranch())== 0){
253 fRecPointsTitle =((AliPHOSClusterizer*)clus[index])->GetRecPointsBranch() ;
257 for(index = 0; index < itsms ; index++)
258 if(fRecPointsTitle.CompareTo(((AliPHOSTrackSegmentMaker*)tsms[index])->GetRecPointsBranch())== 0){
260 fTSTitle =((AliPHOSTrackSegmentMaker*)tsms[index])->GetTrackSegmentsBranch() ;
264 for(index = 0; index < ipids ; index++)
265 if(fTSTitle.CompareTo(((AliPHOSPID*)pids[index])->GetTrackSegmentsBranch())== 0){
267 fRPTitle = ((AliPHOSPID*)pids[index])->GetRecParticlesBranch() ;
271 //delete created objects
272 for(index = 0; index < ipids ; index++)
274 for(index = 0; index < itsms ; index++)
276 for(index = 0; index < iclus ; index++)
278 for(index = 0; index < idigs ; index++)
280 for(index = 0; index < isdigs ; index++)
281 delete sdigs[index] ;
284 //____________________________________________________________________________
285 AliPHOSIndexToObject * AliPHOSIndexToObject::GetInstance()
287 // Returns the pointer of the unique instance already defined
289 AliPHOSIndexToObject * rv = 0 ;
293 cout << "AliPHOSIndexToObject::GetInstance ERROR: not yet initialized" << endl ;
298 //____________________________________________________________________________
299 AliPHOSIndexToObject * AliPHOSIndexToObject::GetInstance(const char* headerFile,
301 const char* branchTitle)
303 // Creates and returns the pointer of the unique instance
304 // Must be called only when the environment has changed
306 if(strcmp(branch,"PHOSRP") && strcmp(branch,"AliPHOSPID") &&
307 strcmp(branch,"PHOSTS") && strcmp(branch,"AliPHOSTrackSegmentMaker") &&
308 strcmp(branch,"PHOSEmcRP") && strcmp(branch,"PHOSCpvRP") && strcmp(branch,"AliPHOSClusterizer") &&
309 strcmp(branch,"PHOS") && strcmp(branch,"AliPHOSDigitizer") ){
311 cout << "AliPHOSIndexToObject: wrong branch name specified: " << branch << endl ;
312 cout << " avalilable names are `PHOSRP', `AliPHOSPID'"<<endl ;
313 cout << " `PHOSTS', `AliPHOSTrackSegmentMaker'"<<endl ;
314 cout << " `PHOSEmcRP', `PHOSCpvRP', `AliPHOSClusterizer'"<< endl ;
315 cout << " `PHOS' and `AliPHOSDigitizer'"<< endl ;
320 if ( fgObjGetter ) // delete it if already exists
323 fgObjGetter = new AliPHOSIndexToObject(headerFile,branch,branchTitle) ;
329 //____________________________________________________________________________
330 TParticle * AliPHOSIndexToObject::GimePrimary(Int_t index) const
332 // Return primary particle numbered by <index>
337 Int_t primaryIndex = index % 10000000 ;
338 Int_t primaryList = (Int_t ) ((index-primaryIndex)/10000000.) ;
340 if ( primaryList > 0 ) {
341 cout << " IndexToObject does not support currently Mixing of primary " << endl ;
342 cout << " can not return primary: " << index<< " (list "<< primaryList<< " primary # " << primaryIndex << " )"<<endl ;
346 return gAlice->Particle(primaryIndex) ;
350 //____________________________________________________________________________
351 void AliPHOSIndexToObject::ReadTreeD()
353 // Read the digit tree gAlice->TreeD()
354 if(gAlice->TreeD()== 0){
355 cout << "AliPHOSIndexToObject : can not read TreeD " << endl;
359 TBranch * digitsBranch = 0;
360 TBranch * digitizerBranch = 0;
362 TObjArray * branches = gAlice->TreeD()->GetListOfBranches() ;
364 Bool_t phosNotFound = kTRUE ;
365 Bool_t digitizerNotFound = kTRUE ;
367 for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){
370 digitsBranch=(TBranch *) branches->At(ibranch) ;
371 if( (strcmp(digitsBranch->GetTitle(),fDigitsTitle)==0 ) &&
372 (strcmp(digitsBranch->GetName(),"PHOS") == 0) )
373 phosNotFound = kFALSE ;
375 if(digitizerNotFound){
376 digitizerBranch = (TBranch *) branches->At(ibranch) ;
377 if( (strcmp(digitizerBranch->GetTitle(),fDigitsTitle) == 0) &&
378 (strcmp(digitizerBranch->GetName(),"AliPHOSDigitizer") == 0) )
379 digitizerNotFound = kFALSE ;
383 if(digitizerNotFound || phosNotFound){
384 cout << "AliPHOSIndexToObject error: " << endl ;
385 cout << " Can't find Branch with Digits or Digitizer "<< endl ; ;
389 digitsBranch ->SetAddress(&fDigits) ;
390 digitizerBranch->SetAddress(&fDigitizer) ;
391 digitsBranch ->GetEntry(0) ;
392 digitizerBranch->GetEntry(0) ;
394 // gAlice->TreeD()->GetEvent(0) ; // YK 29.05.2001
397 //____________________________________________________________________________
398 void AliPHOSIndexToObject::ReadTreeS()
400 // Read the summable digits tree gAlice->TreeS()
402 if(gAlice->TreeS()== 0){
403 cout << "AliPHOSIndexToObject: can not read TreeS " << endl ;
407 TBranch * sdigitsBranch = 0;
408 TBranch * sdigitizerBranch = 0;
410 TObjArray * branches = gAlice->TreeS()->GetListOfBranches() ;
412 Bool_t phosNotFound = kTRUE ;
413 Bool_t sdigitizerNotFound = kTRUE ;
415 for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){
418 sdigitsBranch=(TBranch *) branches->At(ibranch) ;
419 if( (strcmp(sdigitsBranch->GetTitle(),fSDigitsTitle)==0 ) &&
420 (strcmp(sdigitsBranch->GetName(),"PHOS") == 0) )
421 phosNotFound = kFALSE ;
423 if(sdigitizerNotFound){
424 sdigitizerBranch = (TBranch *) branches->At(ibranch) ;
425 if( (strcmp(sdigitizerBranch->GetTitle(),fSDigitsTitle) == 0) &&
426 (strcmp(sdigitizerBranch->GetName(),"AliPHOSSDigitizer") == 0) )
427 sdigitizerNotFound = kFALSE ;
431 if(sdigitizerNotFound || phosNotFound){
432 cout << "AliPHOSIndexToObject error: " << endl ;
433 cout << " Can't find Branch with SDigits or SDigitizer "<< endl ; ;
437 sdigitsBranch ->SetAddress(&fSDigits) ;
438 sdigitizerBranch->SetAddress(&fSDigitizer) ;
439 sdigitsBranch ->GetEvent(0) ;
440 sdigitizerBranch->GetEvent(0) ;
442 // gAlice->TreeS()->GetEvent(0) ; // YK 29.05.2001
445 //____________________________________________________________________________
446 void AliPHOSIndexToObject::ReadTreeR()
448 // Read the reconstrunction tree gAlice->TreeR()
450 if(gAlice->TreeR()== 0){
451 cout << "AliPHOSIndexToObject: can not read TreeR " << endl ;
455 TBranch * pidBranch = 0;
456 TBranch * rpBranch = 0;
457 TBranch * tsMakerBranch = 0;
458 TBranch * tsBranch = 0;
459 TBranch * emcBranch = 0;
460 TBranch * cpvBranch = 0;
461 TBranch * clusterizerBranch = 0;
463 TObjArray * branches = gAlice->TreeR()->GetListOfBranches() ;
465 Bool_t pidNotFound = kTRUE ;
466 Bool_t rpNotFound = kTRUE ;
467 Bool_t tsMakerNotFound = kTRUE ;
468 Bool_t tsNotFound = kTRUE ;
469 Bool_t emcNotFound = kTRUE ;
470 Bool_t cpvNotFound = kTRUE ;
471 Bool_t clusterizerNotFound = kTRUE ;
473 for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){
476 pidBranch=(TBranch *) branches->At(ibranch) ;
477 if( (fRPTitle.CompareTo(pidBranch->GetTitle())==0 ) &&
478 (strcmp(pidBranch->GetName(),"AliPHOSPID") == 0) )
479 pidNotFound = kFALSE ;
482 rpBranch=(TBranch *) branches->At(ibranch) ;
483 if( (fRPTitle.CompareTo(rpBranch->GetTitle())==0 ) &&
484 (strcmp(rpBranch->GetName(),"PHOSRP") == 0) )
485 rpNotFound = kFALSE ;
488 tsMakerBranch=(TBranch *) branches->At(ibranch) ;
489 if( fTSTitle.CompareTo(tsMakerBranch->GetTitle())==0 )
490 if( strcmp(tsMakerBranch->GetName(),"AliPHOSTrackSegmentMaker") == 0)
491 tsMakerNotFound = kFALSE ;
494 tsBranch=(TBranch *) branches->At(ibranch) ;
495 if( fTSTitle.CompareTo(tsBranch->GetTitle())==0 )
496 if( strcmp(tsBranch->GetName(),"PHOSTS") == 0)
497 tsNotFound = kFALSE ;
500 emcBranch=(TBranch *) branches->At(ibranch) ;
501 if( (fRecPointsTitle.CompareTo(emcBranch->GetTitle()) == 0) &&
502 (strcmp(emcBranch->GetName(),"PHOSEmcRP") == 0) )
503 emcNotFound = kFALSE ;
506 cpvBranch=(TBranch *) branches->At(ibranch) ;
507 if( (fRecPointsTitle.CompareTo(cpvBranch->GetTitle()) == 0) &&
508 (strcmp(cpvBranch->GetName(),"PHOSCpvRP") == 0) )
509 cpvNotFound = kFALSE ;
511 if(clusterizerNotFound){
512 clusterizerBranch = (TBranch *) branches->At(ibranch) ;
513 if( (fRecPointsTitle.CompareTo(clusterizerBranch->GetTitle()) == 0) &&
514 (strcmp(clusterizerBranch->GetName(),"AliPHOSClusterizer") == 0) )
515 clusterizerNotFound = kFALSE ;
519 if(pidNotFound ||rpNotFound ){
520 cout << "AliPHOSIndexToObject error" << endl ;
521 cout << " Can't find Branch with PID and RecParticles " ;
524 if(tsMakerNotFound ||tsNotFound ){
525 cout << "AliPHOSIndexToObject error" << endl ;
526 cout << " Can't find Branch with TrackSegmentMaker and TrackSegments " ;
527 cout << " Do nothing" <<endl ;
530 if(clusterizerNotFound || emcNotFound || cpvNotFound){
531 cout << "AliPHOSIndexToObject error" << endl ;
532 cout << " Can't find Branch with RecPoints or Clusterizer " << endl ;
536 // YK 29.05.2001 : Read branch instead of tree
537 emcBranch ->SetAddress(&fEmcRecPoints) ;
538 cpvBranch ->SetAddress(&fCpvRecPoints) ;
539 clusterizerBranch->SetAddress(&fClusterizer) ;
540 emcBranch ->GetEntry(0) ;
541 cpvBranch ->GetEntry(0) ;
542 clusterizerBranch->GetEntry(0) ;
544 tsMakerBranch ->SetAddress(&fTSMaker) ;
545 tsBranch ->SetAddress(&fTS) ;
546 tsMakerBranch ->GetEntry(0) ;
547 tsBranch ->GetEntry(0) ;
549 pidBranch ->SetAddress(&fPID) ;
550 rpBranch ->SetAddress(&fRecParticles) ;
551 pidBranch ->GetEntry(0) ;
552 rpBranch ->GetEntry(0) ;
554 // gAlice->TreeR()->GetEvent(0) ; // YK 29.05.2001
557 //____________________________________________________________________________
558 void AliPHOSIndexToObject::ReadPrimaries()
560 // Reads specific branches of primaries
562 fNPrimaries = gAlice->GetNtrack();
564 // //Check, is it necessary to open new files
565 // TArrayI* events = fDigitizer->GetCurrentEvents() ;
566 // TClonesArray * filenames = fDigitizer->GetHeadersFiles() ;
568 // for(input = 0; input < filenames->GetEntriesFast(); input++){
570 // TObjString * filename = (TObjString *) filenames->At(input) ;
572 // //Test, if this file already open
573 // TFile *file = (TFile*) gROOT->GetFile( filename->GetString() ) ;
575 // file = new TFile( filename->GetString()) ;
578 // // Get Kine Tree from file
579 // // char treeName[20];
580 // // sprintf(treeName,"TreeK%d",events->At(input));
581 // // TTree * treeK = (TTree*)gDirectory->Get(treeName);
583 // // treeK->SetBranchAddress("Particles", &fParticleBuffer);
585 // // cout << "AliPHOSIndexToObject: cannot find Kine Tree for event:" << events->At(input) << endl;
587 // // // Create the particle stack
588 // // if(!fParticles) fParticles = new TClonesArray("TParticle",1000);
589 // // // Build the pointer list
590 // // if(fParticleMap) { <----
591 // // fParticleMap->Clear();
592 // // fParticleMap->Expand(treeK->GetEntries());
594 // // fParticleMap = new TObjArray(treeK->GetEntries());
596 // // From gAlice->Particle(i)
599 // // if(!(*fParticleMap)[i]) {
600 // // Int_t nentries = fParticles->GetEntries();
602 // // // algorithmic way of getting entry index
603 // // // (primary particles are filled after secondaries)
605 // // if (i<fHeader.GetNprimary())
606 // // entry = i+fHeader.GetNsecondary();
608 // // entry = i-fHeader.GetNprimary();
610 // // // only check the algorithmic way and give
611 // // // the fatal error if it is wrong
612 // // if (entry != fParticleFileMap[i]) {
613 // // Fatal("Particle",
614 // // "!!!! The algorithmic way is WRONG: !!!\n entry: %d map: %d",
615 // // entry, fParticleFileMap[i]);
618 // // fTreeK->GetEntry(fParticleFileMap[i]);
619 // // new ((*fParticles)[nentries]) TParticle(*fParticleBuffer);
620 // // fParticleMap->AddAt((*fParticles)[nentries],i);
622 // // return (TParticle *) (*fParticleMap)[i];
629 // //scan over opened files and read corresponding TreeK##
633 //____________________________________________________________________________
634 void AliPHOSIndexToObject::GetEvent(Int_t event)
636 // Reads the content of all Tree's S, D and R
638 if(event == fEvent) // do nothing
641 if(event > fMaxEvent){
642 cout << "There is no such event " << event << " total # of events " << fMaxEvent << endl ;
647 gAlice->GetEvent(fEvent) ;