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