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