]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONDataInterface.cxx
Updated list of MUON libraries
[u/mrichter/AliRoot.git] / MUON / AliMUONDataInterface.cxx
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 #include <cassert>
19 #include <TError.h>
20 #include <TParticle.h>
21
22 #include "AliRunLoader.h"
23 #include "AliLoader.h"
24
25 #include "AliMUONDataInterface.h"
26 #include "AliMUONLocalTrigger.h"
27 #include "AliMUONGlobalTrigger.h"
28 #include "AliMUONHit.h"
29 #include "AliMUONDigit.h"
30 #include "AliMUONRawCluster.h"
31 #include "AliMUONTrack.h"
32 #include "AliLog.h"
33
34 #include <iostream>
35 using std::endl;
36 using std::cout;
37
38 ///
39 /// \class AliMUONDataInterface
40 ///
41 /// An easy to use interface to the MUON module data stored in
42 /// TreeK, TreeH, TreeS, TreeD and TreeR
43 /// One can fetch any of the data objects with all the calls to runloader, 
44 /// muon loader and AliMUONData done behind the scenes and automatically.
45 ///
46 /// This interface in not necessarily the fastest way to fetch the data but
47 /// it is the easiest.
48 /// Note: If independant calls to the run loader, muon loader or 
49 /// AliMUONData objects are interspersed with calls to the 
50 /// AliMUONDataInterface to fetch data, one might need to call the Reset 
51 /// method between these method calls at some point to prevent 
52 /// AliMUONDataInterface from getting confused.
53 /// This is necessary since this object assumes the state of runloader,
54 /// muon loader nor AliMUONData has not changed between calls.
55 /// If the state has changes then one must call Reset so that 
56 /// AliMUONDataInterface refreshes what it knows about the state
57 /// of the loader and AliMUONData objects.
58 ///
59 /// \deprecated We have to revisit all this AliMUONData stuff anyway,
60 /// and probably make a real AliMUONLoader instead...
61 ///
62 /// \author Artur Szostak
63 /// email: artur@alice.phy.uct.ac.za
64
65
66 /// \cond CLASSIMP
67 ClassImp(AliMUONDataInterface)
68 /// \endcond
69
70 AliMUONDataInterface::AliMUONDataInterface()
71         : TObject(), 
72           fCreatedRunLoader(kFALSE),
73           fCreatedRunLoaderSim(kFALSE),
74           fHitAddressSet(kFALSE),
75           fSDigitAddressSet(kFALSE),
76           fDigitAddressSet(kFALSE),
77           fClusterAddressSet(kFALSE),
78           fTriggerAddressSet(kFALSE),
79           fRecTracksAddressSet(kFALSE),
80           fRunloader(0x0),
81           fRunloaderSim(0x0),
82           fRecLoader(0x0),
83           fSimLoader(0x0),
84           fRecData(0x0, "MUON", "MUON"),
85           fSimData(0x0, "MUON", "MUON"),
86           fFilename(),
87           fFoldername("MUONLoader"),
88           fFoldernameSim("MUONLoaderSim"),
89           fEventnumber(-1),
90           fTrack(-1),
91           fSCathode(-1),
92           fCathode(-1)
93 {
94 /// Set all internal pointers to 0x0 and indices to -1.
95
96         Reset();
97 }
98
99 AliMUONDataInterface::~AliMUONDataInterface()
100 {
101 /// Delete the runloader if we created it.
102 /// If the runloader is not to be deleted then call Reset just before 
103 /// the destructor is called.
104
105         if (fRunloader != NULL && fCreatedRunLoader)
106                 delete fRunloader;
107
108         if (fRunloaderSim != NULL && fCreatedRunLoaderSim)
109                 delete fRunloaderSim;
110 }
111
112 void AliMUONDataInterface::Reset()
113 {
114 /// Sets all internal pointers to NULL and indices to -1.
115 /// Note: No resources are released!
116 /// Specificaly AliRunLoader is not deleted.
117
118         fCreatedRunLoader = kFALSE;
119         fCreatedRunLoaderSim = kFALSE;
120         fRunloader = NULL;
121         fRunloaderSim = NULL;
122         fRecLoader = NULL;
123         fSimLoader = NULL;
124         fEventnumber = -1;
125         fTrack = -1;
126         fSCathode = -1;
127         fCathode = -1;
128         fHitAddressSet = kFALSE;
129         fSDigitAddressSet = kFALSE;
130         fDigitAddressSet = kFALSE;
131         fClusterAddressSet = kFALSE;
132         fTriggerAddressSet = kFALSE;
133         fRecTracksAddressSet = kFALSE;
134 }
135
136
137 Bool_t AliMUONDataInterface::UseCurrentRunLoader()
138 {
139 /// Tries to fetch the current runloader with AliRunLoader::GetRunLoader. If nothing is
140 /// currently loaded then kFALSE is returned and AliMUONDataInterface is reset.
141
142         Reset();
143         fRunloader = AliRunLoader::GetRunLoader();
144         if (fRunloader == NULL) return kFALSE;
145         // Fetch the current file name, folder name and event number.
146         fFilename = fRunloader->GetFileName();
147         // fFoldername = fRunloader->GetEventFolder()->GetName();
148         fEventnumber = fRunloader->GetEventNumber();
149
150         if ( ! FetchMuonLoader(fFilename.Data()) )
151         {
152                 Reset();
153                 return kFALSE;
154         }               
155
156         return kTRUE;
157 }
158
159
160 Bool_t AliMUONDataInterface::FetchMuonLoader(TString filename)
161 {
162 /// Fetches the muon loader for the given filename/foldername
163
164
165         fRecLoader = fRunloader->GetLoader("MUONLoader");
166         if (fRecLoader == NULL)
167         {
168                 AliError(Form("Could not find the MUON loader in file: %s and folder: %s", 
169                         (const char*)filename, fFoldername.Data() ));
170                 return kFALSE;
171         }
172         
173         // Need to connect the muon loader to the AliMUONData object,
174         // else class to fRecData will return NULL.
175         fRecData.SetLoader(fRecLoader);
176
177         fSimLoader = fRunloaderSim->GetLoader("MUONLoader");
178         if (fSimLoader == NULL)
179         {
180                 AliError(Form("Could not find the MUON loader in file: %s and folder: %s", 
181                         (const char*)filename, fFoldernameSim.Data()));
182                 return kFALSE;
183         }
184         
185         // Need to connect the muon loader to the AliMUONData object,
186         // else class to fSimData will return NULL.
187         fSimData.SetLoader(fSimLoader);
188         return kTRUE;
189 }
190
191
192 Bool_t AliMUONDataInterface::LoadLoaders(TString filename)
193 {
194 /// Load the run and muon loaders from the specified file and folder.
195 /// kTRUE is returned on success and kFALSE on failure.
196
197         fRunloader = AliRunLoader::Open(filename, "MUONFolder", "READ");
198         if (fRunloader == NULL)
199         {
200                 AliError(Form("Could not find or load the run loader for the file: %s and folder: MUONFolder", 
201                         (const char*)filename));
202                 return kFALSE;
203         }
204         fCreatedRunLoader = kTRUE;
205
206         fRunloaderSim = AliRunLoader::Open(filename, "MUONFolderSim", "READ");
207         if (fRunloaderSim == NULL)
208         {
209                 AliError(Form("Could not find or load the run loader for the file: %s and folder: MUONFolderSim", 
210                         (const char*)filename));
211                 return kFALSE;
212         }
213         fCreatedRunLoaderSim = kTRUE;
214
215         if ( ! FetchMuonLoader(filename) )
216         {
217                 fRunloader = NULL;
218                 fRunloaderSim = NULL;
219                 return kFALSE;
220         }
221         
222         fFilename = filename;
223         fEventnumber = -1;  // Reset the event number to force the event to be loaded.
224         return kTRUE;
225 }
226
227
228 Bool_t AliMUONDataInterface::FetchLoaders(TString filename)
229 {
230 /// Fetch the run loader and muon loader objects from memory if they already exist,
231 /// or from memory if they do not. 
232 /// If the currently loaded run loader (if any) is not refering to the file and folder
233 /// we are interested in then it is deleted and reopened with the required file and
234 /// folder names.
235
236         if (fRunloader == NULL)
237         {
238                 fRunloader = AliRunLoader::GetRunLoader();
239                 if (fRunloader == NULL)
240                         return LoadLoaders(filename);
241                 else
242                 {
243                         if (fRecLoader == NULL)
244                         {
245                                 if ( ! FetchMuonLoader(filename) )
246                                 {
247                                         fRunloader = NULL;
248                                         return kFALSE;
249                                 }
250                         }
251                 }
252                 
253                 // Fetch the current file and folder names.
254                 fFilename = fRunloader->GetFileName();
255                 // fFoldername = fRunloader->GetEventFolder()->GetName();
256         }
257
258         // If filename or foldername are not the same as the ones currently selected then
259         // reopen the file.
260         if ( filename.CompareTo(fFilename) != 0 )
261         {
262                 delete fRunloader;
263                 return LoadLoaders(filename);
264         }
265         return kTRUE;
266 }
267
268
269 Bool_t AliMUONDataInterface::FetchEvent(Int_t event)
270 {
271 /// Fetch the specified event from the runloader and reset all the track, cathode
272 /// and address flags to force them to be reloaded.
273 /// If a negative event number is specified then the current runloader event
274 /// number is used.
275
276         if (fEventnumber < 0)
277         {
278                 fEventnumber = fRunloader->GetEventNumber();
279                 fTrack = -1;
280                 fSCathode = -1;
281                 fCathode = -1;
282                 fHitAddressSet = kFALSE;
283                 fSDigitAddressSet = kFALSE;
284                 fDigitAddressSet = kFALSE;
285                 fClusterAddressSet = kFALSE;
286                 fTriggerAddressSet = kFALSE;
287                 fRecTracksAddressSet = kFALSE;
288         }
289         if ( event != fEventnumber )
290         {
291                 if ( fRunloader->GetEvent(event) < 0 ) return kFALSE;
292                 fEventnumber = event;
293                 fTrack = -1;
294                 fSCathode = -1;
295                 fCathode = -1;
296                 fHitAddressSet = kFALSE;
297                 fSDigitAddressSet = kFALSE;
298                 fDigitAddressSet = kFALSE;
299                 fClusterAddressSet = kFALSE;
300                 fTriggerAddressSet = kFALSE;
301                 fRecTracksAddressSet = kFALSE;
302         }
303         return kTRUE;
304 }
305
306
307 Bool_t AliMUONDataInterface::FetchTreeK()
308 {
309 /// Fetch the Kine tree from the current run loader.
310
311         if (fRunloaderSim->TreeK() == NULL)
312         {
313                 fRunloaderSim->LoadKinematics("READ");
314                 if (fRunloaderSim->TreeK() == NULL)
315                 {
316                         AliError("Could not load TreeK.");
317                         return kFALSE;
318                 }
319         }
320         return kTRUE;
321 }
322
323
324 Bool_t AliMUONDataInterface::FetchTreeH()
325 {
326 /// Fetch the Hits tree from the current muon loader.
327 /// Set all the required addresses etc...
328
329         if (fSimLoader->TreeH() == NULL)
330         {
331                 fSimLoader->LoadHits("READ");
332                 if (fSimLoader->TreeH() == NULL)
333                 {
334                         AliError("Could not load TreeH.");
335                         return kFALSE;
336                 }
337                 fSimData.SetTreeAddress("H");
338                 fHitAddressSet = kTRUE;
339         }
340         else if ( ! fHitAddressSet )
341         {
342                 fSimData.SetTreeAddress("H");
343                 fHitAddressSet = kTRUE;
344         }
345         return kTRUE;
346 }
347
348
349 Bool_t AliMUONDataInterface::FetchTreeS()
350 {
351 /// Fetch the S-Digits tree from the current muon loader.
352 /// Set all the required addresses etc...
353
354         if (fSimLoader->TreeS() == NULL)
355         {
356                 fSimLoader->LoadSDigits("READ");
357                 if (fSimLoader->TreeS() == NULL)
358                 {
359                         AliError("Could not load TreeS.");
360                         return kFALSE;
361                 }
362                 fSimData.SetTreeAddress("S");
363                 fSDigitAddressSet = kTRUE;
364         }
365         else if ( ! fSDigitAddressSet )
366         {
367                 fSimData.SetTreeAddress("S");
368                 fSDigitAddressSet = kTRUE;
369         }
370         return kTRUE;
371 }
372
373
374 Bool_t AliMUONDataInterface::FetchTreeD()
375 {
376 /// Fetch the digits tree from the current muon loader.
377 /// Set all the required addresses etc...
378
379         if (fSimLoader->TreeD() == NULL)
380         {
381                 fSimLoader->LoadDigits("READ");
382                 if (fSimLoader->TreeD() == NULL)
383                 {
384                         AliError("Could not load TreeD.");
385                         return kFALSE;
386                 }
387                 fSimData.SetTreeAddress("D");
388                 fDigitAddressSet = kTRUE;
389         }
390         else if ( ! fDigitAddressSet )
391         {
392                 fSimData.SetTreeAddress("D");
393                 fDigitAddressSet = kTRUE;
394         }
395         return kTRUE;
396 }
397
398
399 Bool_t AliMUONDataInterface::FetchTreeR()
400 {
401 /// Fetch the reconstructed objects tree from the current muon loader.
402 /// Note: The addresses must still be set. 
403   
404   if (fRecLoader->TreeR() == NULL)
405     {
406       fRecLoader->LoadRecPoints("READ");
407       if (fRecLoader->TreeR() == NULL)
408         {
409           AliError("Could not load TreeR.");
410           return kFALSE;
411         }
412       
413       // Need to reset these flags so that the cluster and trigger address
414       // gets reset after this method. 
415       fClusterAddressSet = kFALSE;
416       fTriggerAddressSet = kFALSE;
417     }
418   return kTRUE;
419 }
420
421 Bool_t AliMUONDataInterface::FetchTreeT()
422 {
423 /// fetch the reconstructed tracks tree from the current muon loader
424 /// note : the addresses must still be set.
425   if (fRecLoader->TreeT() == NULL)
426     {
427       fRecLoader->LoadTracks("READ");
428       if (fRecLoader->TreeT() == NULL)
429         {
430           AliError("Could not load TreeT.");
431           return kFALSE;
432         }
433       
434       // Need to reset these flags so that the rec tracks address
435       // gets reset after this method. 
436       fRecTracksAddressSet = kFALSE;
437     }
438   return kTRUE;
439 }
440   
441 Int_t AliMUONDataInterface::NumberOfEvents(TString filename, TString foldername)
442 {
443 /// Returns the number of events in the specified file/folder, and -1 on error.
444
445         if ( ! FetchLoaders(filename) ) return -1;
446         return fRunloader->GetNumberOfEvents();
447 }
448
449
450 Int_t AliMUONDataInterface::NumberOfParticles(TString filename, TString foldername, Int_t event)
451 {
452 /// Returns the number of events in the specified file/folder, and -1 on error.
453
454         if ( ! FetchLoaders(filename) ) return -1;
455         if ( ! FetchEvent(event) ) return -1;
456         if ( ! FetchTreeK() ) return -1;
457         return (Int_t) fRunloader->TreeK()->GetEntriesFast();
458 }
459
460
461 TParticle* AliMUONDataInterface::Particle(
462                 TString filename, TString foldername, Int_t event, Int_t particle
463         )
464 {
465 /// Returns the specified particle in the given file, folder and event.
466 /// NULL is returned on error.
467
468         if ( ! FetchLoaders(filename) ) return NULL;
469         if ( ! FetchEvent(event) ) return NULL;
470         if ( ! FetchTreeK() ) return NULL;
471         
472         TTree* treeK = fRunloader->TreeK();
473         TParticle* p = NULL;
474         treeK->GetBranch("Particles")->SetAddress(&p);
475         treeK->GetEvent(particle);
476         return p;
477 }
478
479
480 Int_t AliMUONDataInterface::NumberOfTracks(TString filename, TString foldername, Int_t event)
481 {
482 /// Returns the number of tracks in the specified file/folder and event.
483 /// -1 is returned on error.
484
485         if ( ! FetchLoaders(filename) ) return -1;
486         if ( ! FetchEvent(event) ) return -1;
487         if ( ! FetchTreeH() ) return -1;
488         return fSimData.GetNtracks();
489 }
490
491
492 Int_t AliMUONDataInterface::NumberOfHits(
493                 TString filename, TString foldername, Int_t event, Int_t track
494         )
495 {
496 /// Returns the number of hits in the specified file/folder, event and track.
497 /// -1 is returned on error.
498
499         if ( ! FetchLoaders(filename) ) return -1;
500         if ( ! FetchEvent(event) ) return -1;
501         if ( ! FetchTreeH() ) return -1;
502
503         if (fTrack < 0 || fTrack != track)
504         {
505                 fSimData.ResetHits();
506                 fSimData.GetTrack(track);
507                 fTrack = track;
508         }
509         return fSimData.Hits()->GetEntriesFast();
510 }
511
512
513 AliMUONHit* AliMUONDataInterface::Hit(
514                 TString filename, TString foldername, Int_t event,
515                 Int_t track, Int_t hit
516         )
517 {
518 /// Returns the specified hit in the given file, folder, event and track.
519 /// NULL is returned on error.
520
521         if ( ! FetchLoaders(filename) ) return NULL;
522         if ( ! FetchEvent(event) ) return NULL;
523         if ( ! FetchTreeH() ) return NULL;
524
525         if (fTrack < 0 || fTrack != track)
526         {
527                 fSimData.ResetHits();
528                 fSimData.GetTrack(track);
529                 fTrack = track;
530         }
531         return static_cast<AliMUONHit*>( fSimData.Hits()->At(hit) );
532 }
533
534
535 Int_t AliMUONDataInterface::NumberOfSDigits(
536                 TString filename, TString foldername, Int_t event,
537                 Int_t chamber, Int_t cathode
538         )
539 {
540 /// Returns the number of s-digits in the given file, folder, event,
541 /// chamber and cathode. -1 is returned on error.
542
543         assert( 0 <= chamber && chamber <= 13 );
544         assert( 0 <= cathode && cathode <= 1 );
545         
546         if ( ! FetchLoaders(filename) ) return -1;
547         if ( ! FetchEvent(event) ) return -1;
548         if ( ! FetchTreeS() ) return -1;
549
550         if ( fSCathode != cathode )
551         {
552                 fSimData.ResetSDigits();
553                 fSimData.GetSDigits();
554                 fSCathode = cathode;
555         }
556         return fSimData.SDigits(chamber)->GetEntriesFast();
557 }
558
559
560 AliMUONDigit* AliMUONDataInterface::SDigit(
561                 TString filename, TString foldername, Int_t event,
562                 Int_t chamber, Int_t cathode, Int_t sdigit
563         )
564 {
565 /// Returns the specified s-digit in the given file, folder, event,
566 /// chamber and cathode. NULL is returned on error.
567
568         assert( 0 <= chamber && chamber <= 13 );
569         assert( 0 <= cathode && cathode <= 1 );
570         
571         if ( ! FetchLoaders(filename) ) return NULL;
572         if ( ! FetchEvent(event) ) return NULL;
573         if ( ! FetchTreeS() ) return NULL;
574
575         if ( fSCathode != cathode )
576         {
577                 fSimData.ResetSDigits();
578                 fSimData.GetSDigits();
579                 fSCathode = cathode;
580         }
581         return static_cast<AliMUONDigit*>( fSimData.SDigits(chamber)->At(sdigit) );
582 }
583
584
585 Int_t AliMUONDataInterface::NumberOfDigits(
586                 TString filename, TString foldername, Int_t event,
587                 Int_t chamber, Int_t cathode
588         )
589 {
590 /// Returns the number of digits in the given file, folder, event,
591 /// chamber and cathode. -1 is returned on error.
592         assert( 0 <= chamber && chamber <= 13 );
593         assert( 0 <= cathode && cathode <= 1 );
594         
595         if ( ! FetchLoaders(filename) ) return -1;
596         if ( ! FetchEvent(event) ) return -1;
597         if ( ! FetchTreeD() ) return -1;
598
599         if ( fCathode != cathode )
600         {
601                 fSimData.ResetDigits();
602                 fSimData.GetDigits();
603                 fCathode = cathode;
604         }
605         return fSimData.Digits(chamber)->GetEntriesFast();
606 }
607
608
609 AliMUONDigit* AliMUONDataInterface::Digit(
610                 TString filename, TString foldername, Int_t event,
611                 Int_t chamber, Int_t cathode, Int_t digit
612         )
613 {
614 /// Returns the specified digit in the given file, folder, event,
615 /// chamber and cathode. NULL is returned on error.
616
617         assert( 0 <= chamber && chamber <= 13 );
618         assert( 0 <= cathode && cathode <= 1 );
619         
620         if ( ! FetchLoaders(filename) ) return NULL;
621         if ( ! FetchEvent(event) ) return NULL;
622         if ( ! FetchTreeD() ) return NULL;
623
624         if ( fCathode != cathode )
625         {
626                 fSimData.ResetDigits();
627                 fSimData.GetDigits();
628                 fCathode = cathode;
629         }
630         return static_cast<AliMUONDigit*>( fSimData.Digits(chamber)->At(digit) );
631 }
632
633
634 Int_t AliMUONDataInterface::NumberOfRawClusters(
635                 TString filename, TString foldername, Int_t event, Int_t chamber
636         )
637 {
638 /// Returns the number of raw clusters in the specified file, folder, event and chamber.
639 /// -1 is returned or error.
640
641         assert( 0 <= chamber && chamber <= 13 );
642         if ( ! FetchLoaders(filename) ) return -1;
643         if ( ! FetchEvent(event) ) return -1;
644         if ( ! FetchTreeR() ) return -1;
645         if ( ! fClusterAddressSet )
646         {
647                 // If the raw cluster address in TreeR is not set yet then set it now.
648                 fRecData.SetTreeAddress("RC");
649                 fRecData.ResetRawClusters();
650                 fRecData.GetRawClusters();
651                 fClusterAddressSet = kTRUE;
652         }
653         return fRecData.RawClusters(chamber)->GetEntriesFast();
654 }
655
656
657 AliMUONRawCluster* AliMUONDataInterface::RawCluster(
658                 TString filename, TString foldername, Int_t event,
659                 Int_t chamber, Int_t cluster
660         )
661 {
662 /// Fetch the specified raw cluster from the given file, folder, event and chamber number.
663 /// NULL is returned on error.
664
665         assert( 0 <= chamber && chamber <= 13 );
666         if ( ! FetchLoaders(filename) ) return NULL;
667         if ( ! FetchEvent(event) ) return NULL;
668         if ( ! FetchTreeR() ) return NULL;
669         if ( ! fClusterAddressSet )
670         {
671                 // If the raw cluster address in TreeR is not set yet then set it now.
672                 fRecData.SetTreeAddress("RC");
673                 fRecData.ResetRawClusters();
674                 fRecData.GetRawClusters();
675                 fClusterAddressSet = kTRUE;
676         }
677         return static_cast<AliMUONRawCluster*>( fRecData.RawClusters(chamber)->At(cluster) );
678 }
679
680
681 Int_t AliMUONDataInterface::NumberOfLocalTriggers(TString filename, TString foldername, Int_t event)
682 {
683 /// Return the number of local trigger objects in the specified file, folder and
684 /// event number. -1 is returned on error.
685
686         if ( ! FetchLoaders(filename) ) return -1;
687         if ( ! FetchEvent(event) ) return -1;
688         if ( ! FetchTreeD() ) return -1;
689         if ( ! fTriggerAddressSet )
690         {
691                 // If the local trigger address in TreeR is not set yet then set it now.
692                 fRecData.SetTreeAddress("GLT");
693                 fRecData.ResetTrigger();
694                 fRecData.GetTriggerD();
695                 fTriggerAddressSet = kTRUE;
696         }
697         return fRecData.LocalTrigger()->GetEntriesFast();
698 }
699
700
701 AliMUONLocalTrigger* AliMUONDataInterface::LocalTrigger(
702                 TString filename, TString foldername, Int_t event, Int_t trigger
703         )
704 {
705 /// Fetch the specified local trigger object from the given file, folder and event number.
706 /// NULL is returned on error.
707
708         if ( ! FetchLoaders(filename) ) return NULL;
709         if ( ! FetchEvent(event) ) return NULL;
710         if ( ! FetchTreeD() ) return NULL;
711         if ( ! fTriggerAddressSet )
712         {
713                 // If the local trigger address in TreeR is not set yet then set it now.
714                 fRecData.SetTreeAddress("GLT");
715                 fRecData.ResetTrigger();
716                 fRecData.GetTriggerD();
717                 fTriggerAddressSet = kTRUE;
718         }
719         return static_cast<AliMUONLocalTrigger*>( fRecData.LocalTrigger()->At(trigger) );
720 }
721
722 Bool_t AliMUONDataInterface::SetFile(TString filename, TString foldername)
723 {
724 /// Set the current file and folder from which to fetch data.
725 /// kTRUE is returned if the run and muon loaders were found, else kFALSE. 
726
727         return FetchLoaders(filename);
728 }
729
730
731 Bool_t AliMUONDataInterface::GetEvent(Int_t event)
732 {
733 /// Select the current event from which to fetch data.
734 /// kTRUE is returned if the event was found, else kFALSE is returned.
735
736         if (fRunloader == NULL)
737         {
738                 AliError("File not set.");
739                 return kFALSE;
740         }
741         else
742                 return FetchEvent(event);
743 }
744
745
746 Int_t AliMUONDataInterface::NumberOfEvents()
747 {
748 /// Get the number of events in the currently selected file.
749 /// -1 is returned on error.
750
751         if (fRunloader == NULL)
752         {
753                 AliError("File not set.");
754                 return -1;
755         }
756         return fRunloader->GetNumberOfEvents();
757 }
758
759
760 Int_t AliMUONDataInterface::NumberOfParticles()
761 {
762 /// Get the number of particles in the current event.
763 /// -1 is returned on error.
764
765         if (fRunloader == NULL)
766         {
767                 AliError("File not set.");
768                 return -1;
769         }
770         if ( ! FetchTreeK() ) return -1;
771         return (Int_t) fRunloader->TreeK()->GetEntriesFast();
772 }
773
774
775 TParticle* AliMUONDataInterface::Particle(Int_t particle)
776 {
777 /// Fetch the specified particle from the current event.
778 /// NULL is returned on error.
779
780         if (fRunloader == NULL)
781         {
782                 AliError("File not set.");
783                 return NULL;
784         }
785         if (fEventnumber < 0)
786         {
787                 AliError("Event not chosen.");
788                 return NULL;
789         }
790         if ( ! FetchTreeK() ) return NULL;
791         TTree* treeK = fRunloader->TreeK();
792         TParticle* p = NULL;
793         treeK->GetBranch("Particles")->SetAddress(&p);
794         treeK->GetEvent(particle);
795         return p;
796 }
797
798
799 Int_t AliMUONDataInterface::NumberOfTracks()
800 {
801 /// Get the number of tracks in the current event.
802 /// -1 is returned on error.
803
804         if (fRunloader == NULL)
805         {
806                 AliError("File not set.");
807                 return -1;
808         }
809         if (fEventnumber < 0)
810         {
811                 AliError( "Event not chosen.");
812                 return -1;
813         }
814         if ( ! FetchTreeH() ) return -1;
815         return fSimData.GetNtracks();
816 }
817
818
819 Int_t AliMUONDataInterface::NumberOfHits(Int_t track)
820 {
821 /// Get the number of hits for the given track in the current event.
822 /// -1 is returned on error.
823
824         if (fRunloader == NULL)
825         {
826                 AliError("File not set.");
827                 return -1;
828         }
829         if (fEventnumber < 0)
830         {
831                 AliError("Event not chosen.");
832                 return -1;
833         }
834         if ( ! FetchTreeH() ) return -1;
835         if (fTrack < 0 || fTrack != track)
836         {
837                 fSimData.ResetHits();
838                 fSimData.GetTrack(track);
839                 fTrack = track;
840         }
841         return fSimData.Hits()->GetEntriesFast();
842 }
843
844
845 AliMUONHit* AliMUONDataInterface::Hit(Int_t track, Int_t hit)
846 {
847 /// Fetch the specified hit from the current event.
848 /// NULL is returned on error.
849
850         if (fRunloader == NULL)
851         {
852                 AliError("File not set.");
853                 return NULL;
854         }
855         if (fEventnumber < 0)
856         {
857                 AliError("Event not chosen.");
858                 return NULL;
859         }
860         if ( ! FetchTreeH() ) return NULL;
861         if (fTrack < 0 || fTrack != track)
862         {
863                 fSimData.ResetHits();
864                 fSimData.GetTrack(track);
865                 fTrack = track;
866         }
867         return static_cast<AliMUONHit*>( fSimData.Hits()->At(hit) );
868 }
869
870
871 Int_t AliMUONDataInterface::NumberOfSDigits(Int_t chamber, Int_t cathode)
872 {
873 /// Get the number of s-digits on the chamber, cathode in the current event.
874 /// -1 is returned on error.
875
876         assert( 0 <= chamber && chamber <= 13 );
877         assert( 0 <= cathode && cathode <= 1 );
878         
879         if (fRunloader == NULL)
880         {
881                 AliError("File not set.");
882                 return -1;
883         }
884         if (fEventnumber < 0)
885         {
886                 AliError("Event not chosen.");
887                 return -1;
888         }
889
890         if ( ! FetchTreeS() ) return -1;
891         if ( fSCathode != cathode )
892         {
893                 fSimData.ResetSDigits();
894                 fSimData.GetSDigits();
895                 fSCathode = cathode;
896         }
897         return fSimData.SDigits(chamber)->GetEntriesFast();
898 }
899
900
901 AliMUONDigit* AliMUONDataInterface::SDigit(Int_t chamber, Int_t cathode, Int_t sdigit)
902 {
903 /// Fetch the specified s-digits on the chamber, cathode from the current event.
904 /// NULL is returned on error.
905
906         assert( 0 <= chamber && chamber <= 13 );
907         assert( 0 <= cathode && cathode <= 1 );
908         
909         if (fRunloader == NULL)
910         {
911                 AliError("File not set.");
912                 return NULL;
913         }
914         if (fEventnumber < 0)
915         {
916                 AliError("Event not chosen.");
917                 return NULL;
918         }
919
920         if ( ! FetchTreeS() ) return NULL;
921         if ( fSCathode != cathode )
922         {
923                 fSimData.ResetSDigits();
924                 fSimData.GetSDigits();
925                 fSCathode = cathode;
926         }
927         return static_cast<AliMUONDigit*>( fSimData.SDigits(chamber)->At(sdigit) );
928 }
929
930
931 Int_t AliMUONDataInterface::NumberOfDigits(Int_t chamber, Int_t cathode)
932 {
933 /// Get the number of digits on the chamber, cathode in the current event.
934 /// -1 is returned on error.
935
936         assert( 0 <= chamber && chamber <= 13 );
937         assert( 0 <= cathode && cathode <= 1 );
938         
939         if (fRunloader == NULL)
940         {
941                 AliError("File not set.");
942                 return -1;
943         }
944         if (fEventnumber < 0)
945         {
946                 AliError("Event not chosen.");
947                 return -1;
948         }
949         
950         if ( ! FetchTreeD() ) return -1;
951         if ( fCathode != cathode )
952         {
953                 fSimData.ResetDigits();
954                 fSimData.GetDigits();
955                 fCathode = cathode;
956         }
957         return fSimData.Digits(chamber)->GetEntriesFast();
958 }
959
960
961 AliMUONDigit* AliMUONDataInterface::Digit(Int_t chamber, Int_t cathode, Int_t digit)
962 {
963 /// Fetch the specified digits on the chamber, cathode from the current event.
964 /// NULL is returned on error.
965
966         assert( 0 <= chamber && chamber <= 13 );
967         assert( 0 <= cathode && cathode <= 1 );
968         
969         if (fRunloader == NULL)
970         {
971                 AliError("File not set.");
972                 return NULL;
973         }
974         if (fEventnumber < 0)
975         {
976                 AliError("Event not chosen.");
977                 return NULL;
978         }
979
980         if ( ! FetchTreeD() ) return NULL;
981         if ( fCathode != cathode )
982         {
983                 fSimData.ResetDigits();
984                 fSimData.GetDigits();
985                 fCathode = cathode;
986         }
987         return static_cast<AliMUONDigit*>( fSimData.Digits(chamber)->At(digit) );
988 }
989
990
991 Int_t AliMUONDataInterface::NumberOfRawClusters(Int_t chamber)
992 {
993 /// Get the number of raw clusters on the given chamber in the current event.
994 /// -1 is returned on error.
995
996         assert( 0 <= chamber && chamber <= 13 );
997
998         if (fRunloader == NULL)
999         {
1000                 AliError("File not set.");
1001                 return -1;
1002         }
1003         if (fEventnumber < 0)
1004         {
1005                 AliError("Event not chosen.");
1006                 return -1;
1007         }
1008
1009         if ( ! FetchTreeR() ) return -1;
1010         if ( ! fClusterAddressSet )
1011         {
1012                 fRecData.SetTreeAddress("RC");
1013                 fRecData.ResetRawClusters();
1014                 fRecData.GetRawClusters();
1015                 fClusterAddressSet = kTRUE;
1016         }
1017         return fRecData.RawClusters(chamber)->GetEntriesFast();
1018 }
1019
1020
1021 AliMUONRawCluster* AliMUONDataInterface::RawCluster(Int_t chamber, Int_t cluster)
1022 {
1023 /// Fetch the specified raw cluster on the given chamber from the current event.
1024 /// NULL is returned on error.
1025
1026         assert( 0 <= chamber && chamber <= 13 );
1027
1028         if (fRunloader == NULL)
1029         {
1030                 AliError("File not set.");
1031                 return NULL;
1032         }
1033         if (fEventnumber < 0)
1034         {
1035                 AliError("Event not chosen.");
1036                 return NULL;
1037         }
1038
1039         if ( ! FetchTreeR() ) return NULL;
1040         if ( ! fClusterAddressSet )
1041         {
1042                 fRecData.SetTreeAddress("RC");
1043                 fRecData.ResetRawClusters();
1044                 fRecData.GetRawClusters();
1045                 fClusterAddressSet = kTRUE;
1046         }
1047         return static_cast<AliMUONRawCluster*>( fRecData.RawClusters(chamber)->At(cluster) );
1048 }
1049
1050
1051 Int_t AliMUONDataInterface::NumberOfLocalTriggers()
1052 {
1053 /// Get the number of local trigger objects in the current event.
1054 /// -1 is returned on error.
1055
1056         if (fRunloader == NULL)
1057         {
1058                 AliError("File not set.");
1059                 return -1;
1060         }
1061         if (fEventnumber < 0)
1062         {
1063                 AliError("Event not chosen.");
1064                 return -1;
1065         }
1066
1067         if ( ! FetchTreeD() ) return -1;
1068         if ( ! fTriggerAddressSet )
1069         {
1070                 fRecData.SetTreeAddress("GLT");
1071                 fRecData.ResetTrigger();
1072                 fRecData.GetTriggerD();
1073                 fTriggerAddressSet = kTRUE;
1074         }
1075         return fRecData.LocalTrigger()->GetEntriesFast();
1076 }
1077
1078
1079 AliMUONLocalTrigger* AliMUONDataInterface::LocalTrigger(Int_t trigger)
1080 {
1081 /// Fetch the specified local trigger object from the current event.
1082 /// NULL is returned on error.
1083
1084         if (fRunloader == NULL)
1085         {
1086                 AliError("File not set.");
1087                 return NULL;
1088         }
1089         if (fEventnumber < 0)
1090         {
1091                 AliError( "Event not chosen.");
1092                 return NULL;
1093         }
1094
1095         if ( ! FetchTreeD() ) return NULL;
1096         if ( ! fTriggerAddressSet )
1097         {
1098                 fRecData.SetTreeAddress("GLT");
1099                 fRecData.ResetTrigger();
1100                 fRecData.GetTriggerD();
1101                 fTriggerAddressSet = kTRUE;
1102         }
1103         return static_cast<AliMUONLocalTrigger*>( fRecData.LocalTrigger()->At(trigger) );
1104 }
1105
1106 Int_t AliMUONDataInterface::NumberOfGlobalTriggers()
1107 {
1108 /// Get the number of local trigger objects in the current event.
1109 /// -1 is returned on error.
1110   
1111   if (fRunloader == NULL)
1112     {
1113       AliError("File not set.");
1114       return -1;
1115     }
1116   if (fEventnumber < 0)
1117     {
1118       AliError("Event not chosen.");
1119       return -1;
1120     }
1121   
1122   if ( ! FetchTreeD() ) return -1;
1123   if ( ! fTriggerAddressSet )
1124     {
1125       fRecData.SetTreeAddress("GLT");
1126       fRecData.ResetTrigger();
1127       fRecData.GetTriggerD();
1128       fTriggerAddressSet = kTRUE;
1129     }
1130   return fRecData.GlobalTrigger()->GetEntriesFast();
1131 }
1132
1133 AliMUONGlobalTrigger* AliMUONDataInterface::GlobalTrigger(Int_t trigger)
1134 {
1135 /// Fetch the specified local trigger object from the current event.
1136 /// NULL is returned on error.
1137   
1138   if (fRunloader == NULL)
1139     {
1140       AliError("File not set.");
1141       return NULL;
1142     }
1143   if (fEventnumber < 0)
1144     {
1145       AliError( "Event not chosen.");
1146       return NULL;
1147     }
1148   
1149   if ( ! FetchTreeD() ) return NULL;
1150   if ( ! fTriggerAddressSet )
1151     {
1152       fRecData.SetTreeAddress("GLT");
1153       fRecData.ResetTrigger();
1154       fRecData.GetTriggerD();
1155       fTriggerAddressSet = kTRUE;
1156     }
1157   return static_cast<AliMUONGlobalTrigger*>( fRecData.GlobalTrigger()->At(trigger) );
1158 }
1159
1160 Int_t AliMUONDataInterface::NumberOfRecTracks()
1161 {
1162 /// Fetch the number of reconstructed tracks from the current event.
1163 /// NULL is returned on error.
1164   
1165   if (fRunloader == NULL)
1166     {
1167       AliError("File not set.");
1168       return -1;
1169     }
1170   if (fEventnumber < 0)
1171     {
1172       AliError( "Event not chosen.");
1173       return -1;
1174     }
1175   
1176   if ( ! FetchTreeT() ) return -1;
1177   if ( ! fRecTracksAddressSet )
1178     {
1179       fRecData.SetTreeAddress("RT");
1180       fRecData.ResetRecTracks();
1181       fRecData.GetRecTracks();
1182       fRecTracksAddressSet = kTRUE;
1183     }
1184   return fRecData.RecTracks()->GetEntriesFast();
1185 }
1186
1187 AliMUONTrack* AliMUONDataInterface::RecTrack(Int_t rectrack)
1188 {
1189 /// Fetch the specified reconstructed track object from the current event.
1190 /// NULL is returned on error.
1191   
1192   if (fRunloader == NULL)
1193     {
1194       AliError("File not set.");
1195       return NULL;
1196     }
1197   if (fEventnumber < 0)
1198     {
1199       AliError( "Event not chosen.");
1200       return NULL;
1201     }
1202   
1203   if ( ! FetchTreeT() ) return NULL;
1204   if ( ! fRecTracksAddressSet )
1205     {
1206       fRecData.SetTreeAddress("RT");
1207       fRecData.ResetRecTracks();
1208       fRecData.GetRecTracks();
1209       fRecTracksAddressSet = kTRUE;
1210     }
1211   return static_cast<AliMUONTrack*>( fRecData.RecTracks()->At(rectrack) );
1212   // return (AliMUONTrack*)(fRecData.RecTracks()->At(rectrack));
1213 }