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 /// \class AliMUONMCDataInterface
20 /// Easy to use MC data accessor
22 /// \author Laurent Aphecetche, Subatech
25 #include "AliMUONMCDataInterface.h"
26 #include "AliMUONVDigitStore.h"
27 #include "AliMUONVHitStore.h"
28 #include "AliMUONVStore.h"
29 #include "AliMUONVTriggerStore.h"
32 #include "AliRunLoader.h"
35 #include <Riostream.h>
36 #include <TClonesArray.h>
38 #include <TParticle.h>
41 ClassImp(AliMUONMCDataInterface)
44 Int_t AliMUONMCDataInterface::fgInstanceCounter(0);
46 //_____________________________________________________________________________
47 AliMUONMCDataInterface::AliMUONMCDataInterface(const char* filename) :
65 //_____________________________________________________________________________
66 AliMUONMCDataInterface::~AliMUONMCDataInterface()
71 delete fLoader->GetRunLoader();
76 //_____________________________________________________________________________
78 AliMUONMCDataInterface::DigitStore(Int_t event)
80 /// Return a pointer to the digitStore for a given event (or 0 if not found)
81 /// Returned pointer should not be deleted
83 if ( LoadEvent(event) ) return 0x0;
85 fLoader->LoadDigits();
87 TTree* treeD = fLoader->TreeD();
91 AliError("Could not get treeD");
97 fDigitStore = AliMUONVDigitStore::Create(*treeD);
102 fDigitStore->Clear();
103 fDigitStore->Connect(*treeD);
107 fLoader->UnloadDigits();
112 //_____________________________________________________________________________
114 AliMUONMCDataInterface::DumpDigits(Int_t event, Bool_t sorted)
116 /// Dump the digits for a given event, sorted if requested.
123 DumpSorted(*fDigitStore);
127 fDigitStore->Print();
132 //_____________________________________________________________________________
134 AliMUONMCDataInterface::DumpHits(Int_t event)
136 /// Dump all the hits for one event
138 Int_t ntracks = NumberOfTracks(event);
140 for ( Int_t i = 0; i < ntracks; ++i )
142 cout << ">> Track " << i << endl;
146 fHitStore->Print("","full");
151 //_____________________________________________________________________________
153 AliMUONMCDataInterface::DumpKine(Int_t event)
155 /// Dump all generated particles for one event
156 AliStack* stack = Stack(event);
160 Int_t nparticles = (Int_t) stack->GetNtrack();
162 for (Int_t iparticle=0; iparticle<nparticles; ++iparticle)
164 stack->Particle(iparticle)->Print("");
169 AliError("Could not get stack");
173 //_____________________________________________________________________________
175 AliMUONMCDataInterface::DumpSDigits(Int_t event, Bool_t sorted)
177 /// Dump the SDigits for a given event, sorted if requested
184 DumpSorted(*fSDigitStore);
188 fSDigitStore->Print();
193 //_____________________________________________________________________________
195 AliMUONMCDataInterface::DumpSorted(const AliMUONVStore& store) const
197 /// Dump the given store in sorted order
199 TIter next(store.CreateIterator());
202 list.SetOwner(kFALSE);
204 while ( ( object = next() ) )
214 //_____________________________________________________________________________
216 AliMUONMCDataInterface::DumpTrackRefs(Int_t event)
218 /// Dump track references for one event
219 Int_t ntrackrefs = NumberOfTrackRefs(event);
221 for ( Int_t i = 0; i < ntrackrefs; ++i )
226 fTrackRefs->Print("","*");
231 //_____________________________________________________________________________
233 AliMUONMCDataInterface::DumpTrigger(Int_t event)
235 /// Dump trigger for a given event (trigger is read from TreeD)
241 fTriggerStore->Print();
245 //_____________________________________________________________________________
247 AliMUONMCDataInterface::HitStore(Int_t event, Int_t track)
249 /// Return the hitStore for a given track of one event
250 /// Return 0 if event and/or track not found
251 /// Returned pointer should not be deleted
253 if ( !IsValid() ) return 0x0;
255 if ( LoadEvent(event) ) return 0x0;
257 if ( fHitStore) fHitStore->Clear();
261 TTree* treeH = fLoader->TreeH();
265 AliError("Could not get treeH");
271 fHitStore = AliMUONVHitStore::Create(*treeH);
272 AliDebug(1,"Creating hitStore from treeH");
277 fHitStore->Connect(*treeH);
278 if ( treeH->GetEvent(track) == 0 )
280 AliError(Form("Could not read track %d",track));
285 fLoader->UnloadHits();
290 //_____________________________________________________________________________
292 AliMUONMCDataInterface::IsValid() const
294 /// Whether we were initialized properly or not
298 //_____________________________________________________________________________
300 AliMUONMCDataInterface::LoadEvent(Int_t event)
302 /// Load event if different from the current one.
303 if ( event != fCurrentEvent )
305 fCurrentEvent = event;
306 AliDebug(1,Form("Loading event %d using runLoader %p",event,fLoader->GetRunLoader()));
307 if ( event < NumberOfEvents() )
309 return fLoader->GetRunLoader()->GetEvent(event);
320 //_____________________________________________________________________________
322 AliMUONMCDataInterface::NumberOfEvents() const
324 /// Number of events in the file we're connected to
325 if (!IsValid()) return 0;
326 return fLoader->GetRunLoader()->GetNumberOfEvents();
329 //_____________________________________________________________________________
331 AliMUONMCDataInterface::NumberOfTracks(Int_t event)
333 /// Number of tracks in the event
334 if (!IsValid()) return 0;
336 if ( LoadEvent(event) ) return 0;
342 TTree* treeH = fLoader->TreeH();
345 rv = static_cast<Int_t>(treeH->GetEntries());
349 AliError("Could not get TreeH");
352 fLoader->UnloadHits();
357 //_____________________________________________________________________________
359 AliMUONMCDataInterface::NumberOfTrackRefs(Int_t event)
361 /// Number of track references in the event
362 if (!IsValid()) return 0;
364 if ( LoadEvent(event) ) return 0;
366 fLoader->GetRunLoader()->LoadTrackRefs();
370 TTree* treeTR = fLoader->GetRunLoader()->TreeTR();
373 rv = static_cast<Int_t>(treeTR->GetEntries());
377 AliError("Could not get TreeTR");
380 fLoader->GetRunLoader()->UnloadTrackRefs();
385 //_____________________________________________________________________________
387 AliMUONMCDataInterface::Open(const char* filename)
389 /// Connect to a given galice.root file
399 delete fTriggerStore;
406 delete fLoader->GetRunLoader();
413 TString foldername(Form("%s-%d",ClassName(),fgInstanceCounter));
415 while (AliRunLoader::GetRunLoader(foldername))
417 delete AliRunLoader::GetRunLoader(foldername);
420 AliRunLoader* runLoader = AliRunLoader::Open(filename,foldername);
423 AliError(Form("Cannot open file %s",filename));
426 fLoader = runLoader->GetDetectorLoader("MUON");
429 AliError("Cannot get AliMUONLoader");
435 AliError(Form("Could not access %s filename. Object is unuseable",filename));
439 //_____________________________________________________________________________
441 AliMUONMCDataInterface::SDigitStore(Int_t event)
443 /// Return the SDigit store for a given event.
444 /// Return 0 if event not found
445 /// Returned pointer should not be deleted
447 if ( LoadEvent(event) ) return 0x0;
449 fLoader->LoadSDigits();
451 TTree* treeS = fLoader->TreeS();
455 AliError("Could not get treeS");
461 fSDigitStore = AliMUONVDigitStore::Create(*treeS);
466 fSDigitStore->Clear();
467 fSDigitStore->Connect(*treeS);
471 fLoader->UnloadSDigits();
476 //_____________________________________________________________________________
478 AliMUONMCDataInterface::Stack(Int_t event)
480 /// Get the Stack (list of generated particles) for one event
481 /// Returned pointer should not be deleted
483 if (!IsValid()) return 0x0;
485 if ( LoadEvent(event) ) return 0;
487 fLoader->GetRunLoader()->LoadKinematics();
489 return fLoader->GetRunLoader()->Stack();
492 //_____________________________________________________________________________
494 AliMUONMCDataInterface::TrackRefs(Int_t event, Int_t track)
496 /// Get the track references for a given (generated) track of one event
497 /// Returned pointer should not be deleted
499 if ( !IsValid() ) return 0x0;
501 if ( LoadEvent(event) ) return 0;
503 fLoader->GetRunLoader()->LoadTrackRefs();
505 TTree* treeTR = fLoader->GetRunLoader()->TreeTR();
507 if ( fTrackRefs ) fTrackRefs->Clear("C");
511 if ( treeTR->GetEvent(track) > 0 )
513 TBranch* branch = treeTR->GetBranch("MUON");
514 branch->SetAddress(&fTrackRefs);
515 branch->GetEvent(track);
520 AliError("Could not get TreeTR");
523 fLoader->GetRunLoader()->UnloadTrackRefs();
528 //_____________________________________________________________________________
529 AliMUONVTriggerStore*
530 AliMUONMCDataInterface::TriggerStore(Int_t event)
532 /// Return the triggerStore for a given event.
533 /// Return 0x0 if event not found.
534 /// Returned pointer should not be deleted.
536 if ( LoadEvent(event) ) return 0x0;
538 fLoader->LoadDigits();
540 TTree* treeD = fLoader->TreeD();
544 AliError("Could not get treeD");
550 fTriggerStore = AliMUONVTriggerStore::Create(*treeD);
555 fTriggerStore->Clear();
556 fTriggerStore->Connect(*treeD);
560 fLoader->UnloadDigits();
562 return fTriggerStore;