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 /// \class AliMUONMCDataInterface
21 /// Easy to use MC data accessor
23 /// \author Laurent Aphecetche, Subatech
24 //-----------------------------------------------------------------------------
26 #include "AliMUONMCDataInterface.h"
27 #include "AliMUONVDigitStore.h"
28 #include "AliMUONVHitStore.h"
29 #include "AliMUONVStore.h"
30 #include "AliMUONVTriggerStore.h"
33 #include "AliRunLoader.h"
36 #include <Riostream.h>
37 #include <TClonesArray.h>
39 #include <TParticle.h>
42 ClassImp(AliMUONMCDataInterface)
45 Int_t AliMUONMCDataInterface::fgInstanceCounter(0);
47 //_____________________________________________________________________________
48 AliMUONMCDataInterface::AliMUONMCDataInterface(const char* filename) :
66 //_____________________________________________________________________________
67 AliMUONMCDataInterface::~AliMUONMCDataInterface()
72 delete fLoader->GetRunLoader();
77 //_____________________________________________________________________________
79 AliMUONMCDataInterface::DigitStore(Int_t event)
81 /// Return a pointer to the digitStore for a given event (or 0 if not found)
82 /// Returned pointer should not be deleted
84 if ( LoadEvent(event) ) return 0x0;
86 fLoader->LoadDigits();
88 TTree* treeD = fLoader->TreeD();
92 AliError("Could not get treeD");
98 fDigitStore = AliMUONVDigitStore::Create(*treeD);
103 fDigitStore->Clear();
104 fDigitStore->Connect(*treeD);
108 fLoader->UnloadDigits();
113 //_____________________________________________________________________________
115 AliMUONMCDataInterface::DumpDigits(Int_t event, Bool_t sorted)
117 /// Dump the digits for a given event, sorted if requested.
124 DumpSorted(*fDigitStore);
128 fDigitStore->Print();
133 //_____________________________________________________________________________
135 AliMUONMCDataInterface::DumpHits(Int_t event)
137 /// Dump all the hits for one event
139 Int_t ntracks = NumberOfTracks(event);
141 for ( Int_t i = 0; i < ntracks; ++i )
143 cout << ">> Track " << i << endl;
147 fHitStore->Print("","full");
152 //_____________________________________________________________________________
154 AliMUONMCDataInterface::DumpKine(Int_t event)
156 /// Dump all generated particles for one event
157 AliStack* stack = Stack(event);
161 Int_t nparticles = (Int_t) stack->GetNtrack();
163 for (Int_t iparticle=0; iparticle<nparticles; ++iparticle)
165 stack->Particle(iparticle)->Print("");
170 AliError("Could not get stack");
174 //_____________________________________________________________________________
176 AliMUONMCDataInterface::DumpSDigits(Int_t event, Bool_t sorted)
178 /// Dump the SDigits for a given event, sorted if requested
185 DumpSorted(*fSDigitStore);
189 fSDigitStore->Print();
194 //_____________________________________________________________________________
196 AliMUONMCDataInterface::DumpSorted(const AliMUONVStore& store) const
198 /// Dump the given store in sorted order
200 TIter next(store.CreateIterator());
203 list.SetOwner(kFALSE);
205 while ( ( object = next() ) )
215 //_____________________________________________________________________________
217 AliMUONMCDataInterface::DumpTrackRefs(Int_t event)
219 /// Dump track references for one event
220 Int_t ntrackrefs = NumberOfTrackRefs(event);
222 for ( Int_t i = 0; i < ntrackrefs; ++i )
227 fTrackRefs->Print("","*");
232 //_____________________________________________________________________________
234 AliMUONMCDataInterface::DumpTrigger(Int_t event)
236 /// Dump trigger for a given event (trigger is read from TreeD)
242 fTriggerStore->Print();
246 //_____________________________________________________________________________
248 AliMUONMCDataInterface::HitStore(Int_t event, Int_t track)
250 /// Return the hitStore for a given track of one event
251 /// Return 0 if event and/or track not found
252 /// Returned pointer should not be deleted
254 if ( !IsValid() ) return 0x0;
256 if ( LoadEvent(event) ) return 0x0;
258 if ( fHitStore) fHitStore->Clear();
262 TTree* treeH = fLoader->TreeH();
266 AliError("Could not get treeH");
272 fHitStore = AliMUONVHitStore::Create(*treeH);
273 AliDebug(1,"Creating hitStore from treeH");
278 fHitStore->Connect(*treeH);
279 if ( treeH->GetEvent(track) == 0 )
281 AliError(Form("Could not read track %d",track));
286 fLoader->UnloadHits();
291 //_____________________________________________________________________________
293 AliMUONMCDataInterface::IsValid() const
295 /// Whether we were initialized properly or not
299 //_____________________________________________________________________________
301 AliMUONMCDataInterface::LoadEvent(Int_t event)
303 /// Load event if different from the current one.
304 if ( event != fCurrentEvent )
306 fCurrentEvent = event;
307 AliDebug(1,Form("Loading event %d using runLoader %p",event,fLoader->GetRunLoader()));
308 if ( event < NumberOfEvents() )
310 return fLoader->GetRunLoader()->GetEvent(event);
321 //_____________________________________________________________________________
323 AliMUONMCDataInterface::NumberOfEvents() const
325 /// Number of events in the file we're connected to
326 if (!IsValid()) return 0;
327 return fLoader->GetRunLoader()->GetNumberOfEvents();
330 //_____________________________________________________________________________
332 AliMUONMCDataInterface::NumberOfTracks(Int_t event)
334 /// Number of tracks in the event
335 if (!IsValid()) return 0;
337 if ( LoadEvent(event) ) return 0;
343 TTree* treeH = fLoader->TreeH();
346 rv = static_cast<Int_t>(treeH->GetEntries());
350 AliError("Could not get TreeH");
353 fLoader->UnloadHits();
358 //_____________________________________________________________________________
360 AliMUONMCDataInterface::NumberOfTrackRefs(Int_t event)
362 /// Number of track references in the event
363 if (!IsValid()) return 0;
365 if ( LoadEvent(event) ) return 0;
367 fLoader->GetRunLoader()->LoadTrackRefs();
371 TTree* treeTR = fLoader->GetRunLoader()->TreeTR();
374 rv = static_cast<Int_t>(treeTR->GetEntries());
378 AliError("Could not get TreeTR");
381 fLoader->GetRunLoader()->UnloadTrackRefs();
386 //_____________________________________________________________________________
388 AliMUONMCDataInterface::Open(const char* filename)
390 /// Connect to a given galice.root file
400 delete fTriggerStore;
407 delete fLoader->GetRunLoader();
414 TString foldername(Form("%s-%d",ClassName(),fgInstanceCounter));
416 while (AliRunLoader::GetRunLoader(foldername))
418 delete AliRunLoader::GetRunLoader(foldername);
421 AliRunLoader* runLoader = AliRunLoader::Open(filename,foldername);
424 AliError(Form("Cannot open file %s",filename));
427 fLoader = runLoader->GetDetectorLoader("MUON");
430 AliError("Cannot get AliMUONLoader");
436 AliError(Form("Could not access %s filename. Object is unuseable",filename));
440 //_____________________________________________________________________________
442 AliMUONMCDataInterface::SDigitStore(Int_t event)
444 /// Return the SDigit store for a given event.
445 /// Return 0 if event not found
446 /// Returned pointer should not be deleted
448 if ( LoadEvent(event) ) return 0x0;
450 fLoader->LoadSDigits();
452 TTree* treeS = fLoader->TreeS();
456 AliError("Could not get treeS");
462 fSDigitStore = AliMUONVDigitStore::Create(*treeS);
467 fSDigitStore->Clear();
468 fSDigitStore->Connect(*treeS);
472 fLoader->UnloadSDigits();
477 //_____________________________________________________________________________
479 AliMUONMCDataInterface::Stack(Int_t event)
481 /// Get the Stack (list of generated particles) for one event
482 /// Returned pointer should not be deleted
484 if (!IsValid()) return 0x0;
486 if ( LoadEvent(event) ) return 0;
488 fLoader->GetRunLoader()->LoadKinematics();
490 return fLoader->GetRunLoader()->Stack();
493 //_____________________________________________________________________________
495 AliMUONMCDataInterface::TrackRefs(Int_t event, Int_t track)
497 /// Get the track references for a given (generated) track of one event
498 /// Returned pointer should not be deleted
500 if ( !IsValid() ) return 0x0;
502 if ( LoadEvent(event) ) return 0;
504 fLoader->GetRunLoader()->LoadTrackRefs();
506 TTree* treeTR = fLoader->GetRunLoader()->TreeTR();
508 if ( fTrackRefs ) fTrackRefs->Clear("C");
512 if ( treeTR->GetEvent(track) > 0 )
514 TBranch* branch = treeTR->GetBranch("MUON");
515 branch->SetAddress(&fTrackRefs);
516 branch->GetEvent(track);
521 AliError("Could not get TreeTR");
524 fLoader->GetRunLoader()->UnloadTrackRefs();
529 //_____________________________________________________________________________
530 AliMUONVTriggerStore*
531 AliMUONMCDataInterface::TriggerStore(Int_t event)
533 /// Return the triggerStore for a given event.
534 /// Return 0x0 if event not found.
535 /// Returned pointer should not be deleted.
537 if ( LoadEvent(event) ) return 0x0;
539 fLoader->LoadDigits();
541 TTree* treeD = fLoader->TreeD();
545 AliError("Could not get treeD");
551 fTriggerStore = AliMUONVTriggerStore::Create(*treeD);
556 fTriggerStore->Clear();
557 fTriggerStore->Connect(*treeD);
561 fLoader->UnloadDigits();
563 return fTriggerStore;