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