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 **************************************************************************/
18 //_________________________________________________________________________
19 // A singleton. This class should be used in the analysis stage to get
20 // reconstructed objects: Digits, RecPoints, TrackSegments and RecParticles,
21 // instead of directly reading them from galice.root file. This container
22 // ensures, that one reads Digits, made of these particular digits, RecPoints,
23 // made of these particular RecPoints, TrackSegments and RecParticles.
24 // This becomes non trivial if there are several identical branches, produced with
25 // different set of parameters.
27 // An example of how to use (see also class AliPHOSAnalyser):
28 // AliPHOSIndexToObject * please = AliPHOSIndexToObject::GetInstance("galice.root","RecParticles","") ;
29 // for(Int_t irecp = 0; irecp < please->GimeNRecParticles() ; irecp++)
30 // AliPHOSRecParticle * part = please->GimeRecParticle(1) ;
32 // please->GetEvent(event) ; // reads new event from galice.root
34 //*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC KI & SUBATECH)
35 //*-- Complitely redesigned by Dmitri Peressounko March 2001
36 //////////////////////////////////////////////////////////////////////////////
39 // --- ROOT system ---
44 #include "TObjString.h"
46 // --- Standard library ---
49 // --- AliRoot header files ---
52 #include "AliPHOSIndexToObject.h"
53 #include "AliPHOSDigitizer.h"
54 #include "AliPHOSSDigitizer.h"
55 #include "AliPHOSClusterizer.h"
56 #include "AliPHOSClusterizerv1.h"
57 #include "AliPHOSTrackSegmentMaker.h"
58 #include "AliPHOSTrackSegmentMakerv1.h"
59 #include "AliPHOSTrackSegment.h"
60 #include "AliPHOSPID.h"
61 #include "AliPHOSPIDv1.h"
63 ClassImp(AliPHOSIndexToObject)
65 AliPHOSIndexToObject * AliPHOSIndexToObject::fgObjGetter = 0 ;
67 //____________________________________________________________________________
68 AliPHOSIndexToObject::AliPHOSIndexToObject(const char* headerFile,const char* branch,const char* branchTitle )
70 //Initialize all lists
73 fSDigits = new TClonesArray("AliPHOSDigit",100) ;
74 fDigits = new TClonesArray("AliPHOSDigit",100) ;
75 fEmcRecPoints = new TObjArray(100) ;
76 fCpvRecPoints = new TObjArray(100) ;
77 fTS = new TClonesArray("AliPHOSTrackSegment",100) ;
78 fRecParticles = new TClonesArray("AliPHOSRecParticle",100) ;
79 fPrimaries = new TObjArray(1) ;
88 fHeaderFile = headerFile ;
89 TFile * file = (TFile*) gROOT->GetFile(fHeaderFile.Data() ) ;
92 if(fHeaderFile.Contains("rfio")) // if we read file using HPSS
93 file = TFile::Open(fHeaderFile.Data(),"update") ;
95 file = new TFile(fHeaderFile.Data(),"update") ;
96 gAlice = (AliRun *) file->Get("gAlice") ;
99 fMaxEvent = (Int_t) gAlice->TreeE()->GetEntries() ;
101 DefineBranchTitles(branch,branchTitle) ;
103 //Now read all data from trees
108 //____________________________________________________________________________
109 void AliPHOSIndexToObject:: DefineBranchTitles(const char* startBranch,const char* branchTitle)
111 // Points to the branches of all reconstructed objects with the specified names
112 gAlice->GetEvent(0) ;
113 // Read all reconstruction classes to extract titles of
114 // branches, constituing "reconstruction branch"
115 AliPHOSPID * pids[50]; // here AliPHOSPID's will be stored
117 AliPHOSTrackSegmentMaker * tsms[50] ;
119 AliPHOSClusterizer * clus[50] ;
121 AliPHOSDigitizer * digs[50];
123 AliPHOSSDigitizer * sdigs[50];
127 TObjArray * branches = gAlice->TreeR()->GetListOfBranches() ;
130 for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){
131 branch=(TBranch *) branches->At(ibranch) ;
132 if( (strcmp(branch->GetName(),"AliPHOSPID") == 0) ){
133 pids[ipids] = new AliPHOSPIDv1() ;
134 branch->SetAddress(& (pids[ipids])) ;
137 if( (strcmp(branch->GetName(),"AliPHOSTrackSegmentMaker") == 0) ){
138 tsms[itsms] = new AliPHOSTrackSegmentMakerv1() ;
139 branch->SetAddress(&(tsms[itsms])) ;
142 if( (strcmp(branch->GetName(),"AliPHOSClusterizer") == 0) ){
143 clus[iclus] = new AliPHOSClusterizerv1() ;
144 branch->SetAddress(&(clus[iclus])) ;
148 gAlice->TreeR()->GetEvent(0) ;
152 branches = gAlice->TreeD()->GetListOfBranches() ;
153 for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){
154 branch=(TBranch *) branches->At(ibranch) ;
155 if( (strcmp(branch->GetName(),"AliPHOSDigitizer") == 0) ){
156 digs[idigs] = new AliPHOSDigitizer() ;
157 branch->SetAddress(&(digs[idigs])) ;
161 gAlice->TreeD()->GetEvent(0) ;
164 branches = gAlice->TreeS()->GetListOfBranches() ;
165 for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){
166 branch=(TBranch *) branches->At(ibranch) ;
167 if( (strcmp(branch->GetName(),"AliPHOSSDigitizer") == 0) ){
168 sdigs[isdigs] = new AliPHOSSDigitizer() ;
169 branch->SetAddress(&(sdigs[isdigs])) ;
173 gAlice->TreeS()->GetEvent(0) ;
175 // now choose among read Reconstruction classes those,
176 // which constituite "reconstruction branch"
177 Bool_t pidDefined = kFALSE ;
178 Bool_t tsmDefined = kFALSE ;
179 Bool_t cluDefined = kFALSE ;
180 Bool_t digDefined = kFALSE ;
181 Bool_t sdigDefined = kFALSE ;
184 // First, go from the end (RecParticles) to the beginning(SDigits)
185 if((strcmp(startBranch,"PHOSRP") == 0)||(strcmp(startBranch,"AliPHOSPID") == 0)){
186 fRPTitle = branchTitle ;
187 for(index = 0; index < ipids ; index++){
188 if(fRPTitle.CompareTo(((AliPHOSPID*)pids[index])->GetRecParticlesBranch())== 0){
190 fTSTitle =((AliPHOSPID*)pids[index])->GetTrackSegmentsBranch() ;
194 if((strcmp(startBranch,"PHOSTS") == 0)||(strcmp(startBranch,"AliPHOSTrackSegmentMaker") == 0)|| pidDefined ) {
196 fTSTitle = branchTitle ;
197 for(index = 0; index < itsms ; index++)
198 if(fTSTitle.CompareTo(((AliPHOSTrackSegmentMaker*)tsms[index])->GetTrackSegmentsBranch())== 0){
200 fRecPointsTitle =((AliPHOSTrackSegmentMaker*)tsms[index])->GetRecPointsBranch() ;
203 if((strcmp(startBranch,"PHOSEmcRP") == 0) ||
204 (strcmp(startBranch,"PHOSCpvRP") == 0) ||
205 (strcmp(startBranch,"AliPHOSClusterizer") == 0) || tsmDefined ) {
207 fRecPointsTitle = branchTitle ;
208 for(index = 0; index < iclus ; index++)
209 if(fRecPointsTitle.CompareTo(((AliPHOSClusterizer*)clus[index])->GetRecPointsBranch())== 0){
211 fDigitsTitle =((AliPHOSClusterizer*)clus[index])->GetDigitsBranch() ;
214 if((strcmp(startBranch,"PHOS") == 0) || (strcmp(startBranch,"AliPHOSDigitizer") == 0) ||cluDefined ) {
216 fDigitsTitle = branchTitle ;
217 for(index = 0; index < idigs ; index++)
218 if(fDigitsTitle.CompareTo(((AliPHOSDigitizer*)digs[index])->GetDigitsBranch())== 0){
220 fSDigitsTitle =((AliPHOSDigitizer*)digs[index])->GetSDigitsBranch() ;
223 for(index = 0; index < idigs ; index++)
224 if(fSDigitsTitle.CompareTo(((AliPHOSSDigitizer*)sdigs[index])->GetSDigitsBranch())== 0)
225 sdigDefined = kTRUE ;
228 cout << "Can not define titles of branches " << endl ;
232 // Now we go in the inverse direction: from sdigits to recparticles - for the
233 // case, if we started decending not from RecParticles, but e.g. from digits
236 for(index = 0; index < iclus ; index++)
237 if(fDigitsTitle.CompareTo(((AliPHOSClusterizer*)clus[index])->GetDigitsBranch())== 0){
239 fRecPointsTitle =((AliPHOSClusterizer*)clus[index])->GetRecPointsBranch() ;
243 for(index = 0; index < itsms ; index++)
244 if(fRecPointsTitle.CompareTo(((AliPHOSTrackSegmentMaker*)tsms[index])->GetRecPointsBranch())== 0){
246 fTSTitle =((AliPHOSTrackSegmentMaker*)tsms[index])->GetTrackSegmentsBranch() ;
250 for(index = 0; index < ipids ; index++)
251 if(fTSTitle.CompareTo(((AliPHOSPID*)pids[index])->GetTrackSegmentsBranch())== 0){
253 fRPTitle = ((AliPHOSPID*)pids[index])->GetRecParticlesBranch() ;
257 //delete created objects
258 for(index = 0; index < ipids ; index++)
260 for(index = 0; index < itsms ; index++)
262 for(index = 0; index < iclus ; index++)
264 for(index = 0; index < idigs ; index++)
266 for(index = 0; index < isdigs ; index++)
267 delete sdigs[index] ;
270 //____________________________________________________________________________
271 AliPHOSIndexToObject * AliPHOSIndexToObject::GetInstance()
273 // Returns the pointer of the unique instance already defined
275 AliPHOSIndexToObject * rv = 0 ;
279 cout << "AliPHOSIndexToObject::GetInstance ERROR: not yet initialized" << endl ;
284 //____________________________________________________________________________
285 AliPHOSIndexToObject * AliPHOSIndexToObject::GetInstance(const char* headerFile,
287 const char* branchTitle)
289 // Creates and returns the pointer of the unique instance
290 // Must be called only when the environment has changed
292 if(strcmp(branch,"PHOSRP") && strcmp(branch,"AliPHOSPID") &&
293 strcmp(branch,"PHOSTS") && strcmp(branch,"AliPHOSTrackSegmentMaker") &&
294 strcmp(branch,"PHOSEmcRP") && strcmp(branch,"PHOSCpvRP") && strcmp(branch,"AliPHOSClusterizer") &&
295 strcmp(branch,"PHOS") && strcmp(branch,"AliPHOSDigitizer") ){
297 cout << "AliPHOSIndexToObject: wrong branch name specified: " << branch << endl ;
298 cout << " avalilable names are `PHOSRP', `AliPHOSPID'"<<endl ;
299 cout << " `PHOSTS', `AliPHOSTrackSegmentMaker'"<<endl ;
300 cout << " `PHOSEmcRP', `PHOSCpvRP', `AliPHOSClusterizer'"<< endl ;
301 cout << " `PHOS' and `AliPHOSDigitizer'"<< endl ;
306 if ( fgObjGetter ) // delete it if already exists
309 fgObjGetter = new AliPHOSIndexToObject(headerFile,branch,branchTitle) ;
315 //____________________________________________________________________________
316 TParticle * AliPHOSIndexToObject::GimePrimary(Int_t index)
318 // retrieves the primary particle indexed by index
322 Int_t primaryIndex = index % 10000000 ;
323 Int_t primaryList = (Int_t ) ((index-primaryIndex)/10000000.) ;
325 if ( primaryList > 0 ) {
326 cout << " IndexToObject does not support currently Mixing of primary " << endl ;
327 cout << " can not return primary: " << index<< " (list "<< primaryList<< " primary # " << primaryIndex << " )"<<endl ;
331 return gAlice->Particle(primaryIndex) ;
335 //____________________________________________________________________________
336 void AliPHOSIndexToObject::ReadTreeD(){
338 if(gAlice->TreeD()== 0){
339 cout << "AliPHOSIndexToObject : can not read TreeD " << endl;
343 TBranch * digitsBranch = 0;
344 TBranch * digitizerBranch = 0;
346 TObjArray * branches = gAlice->TreeD()->GetListOfBranches() ;
348 Bool_t phosNotFound = kTRUE ;
349 Bool_t digitizerNotFound = kTRUE ;
351 for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){
354 digitsBranch=(TBranch *) branches->At(ibranch) ;
355 if( (strcmp(digitsBranch->GetTitle(),fDigitsTitle)==0 ) &&
356 (strcmp(digitsBranch->GetName(),"PHOS") == 0) )
357 phosNotFound = kFALSE ;
359 if(digitizerNotFound){
360 digitizerBranch = (TBranch *) branches->At(ibranch) ;
361 if( (strcmp(digitizerBranch->GetTitle(),fDigitsTitle) == 0) &&
362 (strcmp(digitizerBranch->GetName(),"AliPHOSDigitizer") == 0) )
363 digitizerNotFound = kFALSE ;
367 if(digitizerNotFound || phosNotFound){
368 cout << "AliPHOSIndexToObject error: " << endl ;
369 cout << " Can't find Branch with Digits or Digitizer "<< endl ; ;
373 digitsBranch->SetAddress(&fDigits) ;
374 digitizerBranch->SetAddress(&fDigitizer) ;
376 gAlice->TreeD()->GetEvent(0) ;
379 //____________________________________________________________________________
380 void AliPHOSIndexToObject::ReadTreeS()
382 // Reads the contents of SDigits
383 if(gAlice->TreeS()== 0){
384 cout << "AliPHOSIndexToObject: can not read TreeS " << endl ;
388 TBranch * sdigitsBranch = 0;
389 TBranch * sdigitizerBranch = 0;
391 TObjArray * branches = gAlice->TreeS()->GetListOfBranches() ;
393 Bool_t phosNotFound = kTRUE ;
394 Bool_t sdigitizerNotFound = kTRUE ;
396 for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){
399 sdigitsBranch=(TBranch *) branches->At(ibranch) ;
400 if( (strcmp(sdigitsBranch->GetTitle(),fSDigitsTitle)==0 ) &&
401 (strcmp(sdigitsBranch->GetName(),"PHOS") == 0) )
402 phosNotFound = kFALSE ;
404 if(sdigitizerNotFound){
405 sdigitizerBranch = (TBranch *) branches->At(ibranch) ;
406 if( (strcmp(sdigitizerBranch->GetTitle(),fSDigitsTitle) == 0) &&
407 (strcmp(sdigitizerBranch->GetName(),"AliPHOSSDigitizer") == 0) )
408 sdigitizerNotFound = kFALSE ;
412 if(sdigitizerNotFound || phosNotFound){
413 cout << "AliPHOSIndexToObject error: " << endl ;
414 cout << " Can't find Branch with SDigits or SDigitizer "<< endl ; ;
418 sdigitsBranch->SetAddress(&fSDigits) ;
419 sdigitizerBranch->SetAddress(&fSDigitizer) ;
421 gAlice->TreeS()->GetEvent(0) ;
424 //____________________________________________________________________________
425 void AliPHOSIndexToObject::ReadTreeR()
427 // Reads the contents of reconstruction Tree
429 if(gAlice->TreeR()== 0){
430 cout << "AliPHOSIndexToObject: can not read TreeR " << endl ;
434 TBranch * pidBranch = 0;
435 TBranch * rpBranch = 0;
436 TBranch * tsMakerBranch = 0;
437 TBranch * tsBranch = 0;
438 TBranch * emcBranch = 0;
439 TBranch * cpvBranch = 0;
440 TBranch * clusterizerBranch = 0;
442 TObjArray * branches = gAlice->TreeR()->GetListOfBranches() ;
444 Bool_t pidNotFound = kTRUE ;
445 Bool_t rpNotFound = kTRUE ;
446 Bool_t tsMakerNotFound = kTRUE ;
447 Bool_t tsNotFound = kTRUE ;
448 Bool_t emcNotFound = kTRUE ;
449 Bool_t cpvNotFound = kTRUE ;
450 Bool_t clusterizerNotFound = kTRUE ;
452 for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){
455 pidBranch=(TBranch *) branches->At(ibranch) ;
456 if( (fRPTitle.CompareTo(pidBranch->GetTitle())==0 ) &&
457 (strcmp(pidBranch->GetName(),"AliPHOSPID") == 0) )
458 pidNotFound = kFALSE ;
461 rpBranch=(TBranch *) branches->At(ibranch) ;
462 if( (fRPTitle.CompareTo(rpBranch->GetTitle())==0 ) &&
463 (strcmp(rpBranch->GetName(),"PHOSRP") == 0) )
464 rpNotFound = kFALSE ;
467 tsMakerBranch=(TBranch *) branches->At(ibranch) ;
468 if( fTSTitle.CompareTo(tsMakerBranch->GetTitle())==0 )
469 if( strcmp(tsMakerBranch->GetName(),"AliPHOSTrackSegmentMaker") == 0)
470 tsMakerNotFound = kFALSE ;
473 tsBranch=(TBranch *) branches->At(ibranch) ;
474 if( fTSTitle.CompareTo(tsBranch->GetTitle())==0 )
475 if( strcmp(tsBranch->GetName(),"PHOSTS") == 0)
476 tsNotFound = kFALSE ;
479 emcBranch=(TBranch *) branches->At(ibranch) ;
480 if( (fRecPointsTitle.CompareTo(emcBranch->GetTitle()) == 0) &&
481 (strcmp(emcBranch->GetName(),"PHOSEmcRP") == 0) )
482 emcNotFound = kFALSE ;
485 cpvBranch=(TBranch *) branches->At(ibranch) ;
486 if( (fRecPointsTitle.CompareTo(cpvBranch->GetTitle()) == 0) &&
487 (strcmp(cpvBranch->GetName(),"PHOSCpvRP") == 0) )
488 cpvNotFound = kFALSE ;
490 if(clusterizerNotFound){
491 clusterizerBranch = (TBranch *) branches->At(ibranch) ;
492 if( (fRecPointsTitle.CompareTo(clusterizerBranch->GetTitle()) == 0) &&
493 (strcmp(clusterizerBranch->GetName(),"AliPHOSClusterizer") == 0) )
494 clusterizerNotFound = kFALSE ;
498 if(pidNotFound ||rpNotFound ){
499 cout << "AliPHOSIndexToObject error" << endl ;
500 cout << " Can't find Branch with PID and RecParticles " ;
503 if(tsMakerNotFound ||tsNotFound ){
504 cout << "AliPHOSIndexToObject error" << endl ;
505 cout << " Can't find Branch with TrackSegmentMaker and TrackSegments " ;
506 cout << " Do nothing" <<endl ;
509 if(clusterizerNotFound || emcNotFound || cpvNotFound){
510 cout << "AliPHOSIndexToObject error" << endl ;
511 cout << " Can't find Branch with RecPoints or Clusterizer " << endl ;
515 emcBranch->SetAddress(&fEmcRecPoints) ;
516 cpvBranch->SetAddress(&fCpvRecPoints) ;
517 clusterizerBranch->SetAddress(&fClusterizer) ;
519 tsMakerBranch->SetAddress(&fTSMaker) ;
520 tsBranch->SetAddress(&fTS) ;
522 pidBranch->SetAddress(&fPID) ;
523 rpBranch->SetAddress(&fRecParticles) ;
525 gAlice->TreeR()->GetEvent(0) ;
528 //____________________________________________________________________________
529 void AliPHOSIndexToObject::ReadPrimaries()
531 // Reads specific branches of primaries
533 fNPrimaries = gAlice->GetNtrack();
535 // //Check, is it necessary to open new files
536 // TArrayI* events = fDigitizer->GetCurrentEvents() ;
537 // TClonesArray * filenames = fDigitizer->GetHeadersFiles() ;
539 // for(input = 0; input < filenames->GetEntriesFast(); input++){
541 // TObjString * filename = (TObjString *) filenames->At(input) ;
543 // //Test, if this file already open
544 // TFile *file = (TFile*) gROOT->GetFile( filename->GetString() ) ;
546 // file = new TFile( filename->GetString()) ;
549 // // Get Kine Tree from file
550 // // char treeName[20];
551 // // sprintf(treeName,"TreeK%d",events->At(input));
552 // // TTree * treeK = (TTree*)gDirectory->Get(treeName);
554 // // treeK->SetBranchAddress("Particles", &fParticleBuffer);
556 // // cout << "AliPHOSIndexToObject: cannot find Kine Tree for event:" << events->At(input) << endl;
558 // // // Create the particle stack
559 // // if(!fParticles) fParticles = new TClonesArray("TParticle",1000);
560 // // // Build the pointer list
561 // // if(fParticleMap) { <----
562 // // fParticleMap->Clear();
563 // // fParticleMap->Expand(treeK->GetEntries());
565 // // fParticleMap = new TObjArray(treeK->GetEntries());
567 // // From gAlice->Particle(i)
570 // // if(!(*fParticleMap)[i]) {
571 // // Int_t nentries = fParticles->GetEntries();
573 // // // algorithmic way of getting entry index
574 // // // (primary particles are filled after secondaries)
576 // // if (i<fHeader.GetNprimary())
577 // // entry = i+fHeader.GetNsecondary();
579 // // entry = i-fHeader.GetNprimary();
581 // // // only check the algorithmic way and give
582 // // // the fatal error if it is wrong
583 // // if (entry != fParticleFileMap[i]) {
584 // // Fatal("Particle",
585 // // "!!!! The algorithmic way is WRONG: !!!\n entry: %d map: %d",
586 // // entry, fParticleFileMap[i]);
589 // // fTreeK->GetEntry(fParticleFileMap[i]);
590 // // new ((*fParticles)[nentries]) TParticle(*fParticleBuffer);
591 // // fParticleMap->AddAt((*fParticles)[nentries],i);
593 // // return (TParticle *) (*fParticleMap)[i];
600 // //scan over opened files and read corresponding TreeK##
604 //____________________________________________________________________________
605 void AliPHOSIndexToObject::GetEvent(Int_t event)
607 // Reads the content of all Tree's S, D and R
608 if(event == fEvent) // do nothing
611 if(event > fMaxEvent){
612 cout << "There is no such event " << event << " total # of events " << fMaxEvent << endl ;
617 gAlice->GetEvent(fEvent) ;