- return *this;
-}
-
-
-void AliMUONDataInterface::Reset()
-{
-// Sets all internal pointers to NULL and indices to -1.
-// Note: No resources are released!
-// Specificaly AliRunLoader is not deleted.
-
- fRunloader = NULL;
- fMuonloader = NULL;
- fEventnumber = -1;
- fTrack = -1;
- fSCathode = -1;
- fCathode = -1;
- fHitAddressSet = kFALSE;
- fSDigitAddressSet = kFALSE;
- fDigitAddressSet = kFALSE;
- fClusterAddressSet = kFALSE;
- fTriggerAddressSet = kFALSE;
-}
-
-
-Bool_t AliMUONDataInterface::LoadLoaders(TString filename, TString foldername)
-{
-// Load the run and muon loaders from the specified file and folder.
-// kTRUE is returned on success and kFALSE on failure.
-
- fRunloader = AliRunLoader::Open(filename, foldername, "READ");
- if (fRunloader == NULL)
- {
- AliError(Form("Could not find or load the run loader for the file: %s and folder: %s",
- (const char*)filename, (const char*)foldername));
- return kFALSE;
- }
- fMuonloader = fRunloader->GetLoader("MUONLoader");
- if (fMuonloader == NULL)
- {
- AliError(Form("Could not find the MUON loader in file: %s and folder: %s",
- (const char*)filename, (const char*)foldername));
- fRunloader = NULL;
- return kFALSE;
- }
-
- // Need to connect the muon loader to the AliMUONData object,
- // else class to fData will return NULL.
- fData.SetLoader(fMuonloader);
-
- fFilename = filename;
- fFoldername = foldername;
- fEventnumber = -1; // Reset the event number to force the event to be loaded.
- return kTRUE;
-}
-
-
-Bool_t AliMUONDataInterface::FetchLoaders(TString filename, TString foldername)
-{
-// Fetch the run loader and muon loader objects from memory if they already exist,
-// or from memory if they do not.
-// If the currently loaded run loader (if any) is not refering to the file and folder
-// we are interested in then it is deleted and reopened with the required file and
-// folder names.
-
- if (fRunloader == NULL)
- {
- fRunloader = AliRunLoader::GetRunLoader();
- if (fRunloader == NULL)
- return LoadLoaders(filename, foldername);
-
- // Fetch the current file and folder names.
- fFilename = fRunloader->GetFileName();
- fFoldername = fRunloader->GetEventFolder()->GetName();
- }
-
- // If filename or foldername are not the same as the ones currently selected then
- // reopen the file.
- if ( filename.CompareTo(fFilename) != 0 || foldername.CompareTo(fFoldername) != 0 )
- {
- delete fRunloader;
- return LoadLoaders(filename, foldername);
- }
- return kTRUE;
-}
-
-
-Bool_t AliMUONDataInterface::FetchEvent(Int_t event)
-{
-// Fetch the specified event from the runloader and reset all the track, cathode
-// and address flags to force them to be reloaded.
-
- if (fEventnumber < 0)
- {
- fEventnumber = fRunloader->GetEventNumber();
- fTrack = -1;
- fSCathode = -1;
- fCathode = -1;
- fHitAddressSet = kFALSE;
- fSDigitAddressSet = kFALSE;
- fDigitAddressSet = kFALSE;
- fClusterAddressSet = kFALSE;
- fTriggerAddressSet = kFALSE;
- }
- if ( event != fEventnumber )
- {
- if ( fRunloader->GetEvent(event) < 0 ) return kFALSE;
- fEventnumber = event;
- fTrack = -1;
- fSCathode = -1;
- fCathode = -1;
- fHitAddressSet = kFALSE;
- fSDigitAddressSet = kFALSE;
- fDigitAddressSet = kFALSE;
- fClusterAddressSet = kFALSE;
- fTriggerAddressSet = kFALSE;
- }
- return kTRUE;
-}
-
-
-Bool_t AliMUONDataInterface::FetchTreeK()
-{
-// Fetch the Kine tree from the current run loader.
-
- if (fRunloader->TreeK() == NULL)
- {
- fRunloader->LoadKinematics("READ");
- if (fRunloader->TreeK() == NULL)
- {
- AliError("Could not load TreeK.");
- return kFALSE;
- }
- }
- return kTRUE;
-}
-
-
-Bool_t AliMUONDataInterface::FetchTreeH()
-{
-// Fetch the Hits tree from the current muon loader.
-// Set all the required addresses etc...
-
- if (fMuonloader->TreeH() == NULL)
- {
- fMuonloader->LoadHits("READ");
- if (fMuonloader->TreeH() == NULL)
- {
- AliError("Could not load TreeH.");
- return kFALSE;
- }
- fData.SetTreeAddress("H");
- fHitAddressSet = kTRUE;
- }
- else if ( ! fHitAddressSet )
- {
- fData.SetTreeAddress("H");
- fHitAddressSet = kTRUE;
- }
- return kTRUE;
-}
-
-
-Bool_t AliMUONDataInterface::FetchTreeS()
-{
-// Fetch the S-Digits tree from the current muon loader.
-// Set all the required addresses etc...
-
- if (fMuonloader->TreeS() == NULL)
- {
- fMuonloader->LoadSDigits("READ");
- if (fMuonloader->TreeS() == NULL)
- {
- AliError("Could not load TreeS.");
- return kFALSE;
- }
- fData.SetTreeAddress("S");
- fSDigitAddressSet = kTRUE;
- }
- else if ( ! fSDigitAddressSet )
- {
- fData.SetTreeAddress("S");
- fSDigitAddressSet = kTRUE;
- }
- return kTRUE;
-}
-
-
-Bool_t AliMUONDataInterface::FetchTreeD()
-{
-// Fetch the digits tree from the current muon loader.
-// Set all the required addresses etc...
-
- if (fMuonloader->TreeD() == NULL)
- {
- fMuonloader->LoadDigits("READ");
- if (fMuonloader->TreeD() == NULL)
- {
- AliError("Could not load TreeD.");
- return kFALSE;
- }
- fData.SetTreeAddress("D");
- fDigitAddressSet = kTRUE;
- }
- else if ( ! fDigitAddressSet )
- {
- fData.SetTreeAddress("D");
- fDigitAddressSet = kTRUE;
- }
- return kTRUE;
-}
-
-
-Bool_t AliMUONDataInterface::FetchTreeR()
-{
-// Fetch the reconstructed objects tree from the current muon loader.
-// Note: The addresses must still be set.
-
- if (fMuonloader->TreeR() == NULL)
- {
- fMuonloader->LoadRecPoints("READ");
- if (fMuonloader->TreeR() == NULL)
- {
- AliError("Could not load TreeR.");
- return kFALSE;
- }
-
- // Need to reset these flags so that the cluster and trigger address
- // gets reset after this method.
- fClusterAddressSet = kFALSE;
- fTriggerAddressSet = kFALSE;
- }
- return kTRUE;
-}
-
-
-Int_t AliMUONDataInterface::NumberOfEvents(TString filename, TString foldername)
-{
-// Returns the number of events in the specified file/folder, and -1 on error.
-
- if ( ! FetchLoaders(filename, foldername) ) return -1;
- return fRunloader->GetNumberOfEvents();
-}
-
-
-Int_t AliMUONDataInterface::NumberOfParticles(TString filename, TString foldername, Int_t event)
-{
-// Returns the number of events in the specified file/folder, and -1 on error.
-
- if ( ! FetchLoaders(filename, foldername) ) return -1;
- if ( ! FetchEvent(event) ) return -1;
- if ( ! FetchTreeK() ) return -1;
- return (Int_t) fRunloader->TreeK()->GetEntriesFast();
-}
-
-
-TParticle* AliMUONDataInterface::Particle(
- TString filename, TString foldername, Int_t event, Int_t particle
- )
-{
-// Returns the specified particle in the given file, folder and event.
-// NULL is returned on error.
-
- if ( ! FetchLoaders(filename, foldername) ) return NULL;
- if ( ! FetchEvent(event) ) return NULL;
- if ( ! FetchTreeK() ) return NULL;
-
- TTree* treeK = fRunloader->TreeK();
- TParticle* p = NULL;
- treeK->GetBranch("Particles")->SetAddress(&p);
- treeK->GetEvent(particle);
- return p;
-}
-
-
-Int_t AliMUONDataInterface::NumberOfTracks(TString filename, TString foldername, Int_t event)
-{
-// Returns the number of tracks in the specified file/folder and event.
-// -1 is returned on error.
-
- if ( ! FetchLoaders(filename, foldername) ) return -1;
- if ( ! FetchEvent(event) ) return -1;
- if ( ! FetchTreeH() ) return -1;
- return fData.GetNtracks();
-}
-
-
-Int_t AliMUONDataInterface::NumberOfHits(
- TString filename, TString foldername, Int_t event, Int_t track
- )
-{
-// Returns the number of hits in the specified file/folder, event and track.
-// -1 is returned on error.
-
- if ( ! FetchLoaders(filename, foldername) ) return -1;
- if ( ! FetchEvent(event) ) return -1;
- if ( ! FetchTreeH() ) return -1;
-
- if (fTrack < 0 || fTrack != track)
- {
- fData.ResetHits();
- fData.GetTrack(track);
- fTrack = track;
- }
- return fData.Hits()->GetEntriesFast();
-}
-
-
-AliMUONHit* AliMUONDataInterface::Hit(
- TString filename, TString foldername, Int_t event,
- Int_t track, Int_t hit
- )
-{
-// Returns the specified hit in the given file, folder, event and track.
-// NULL is returned on error.
-
- if ( ! FetchLoaders(filename, foldername) ) return NULL;
- if ( ! FetchEvent(event) ) return NULL;
- if ( ! FetchTreeH() ) return NULL;
-
- if (fTrack < 0 || fTrack != track)
- {
- fData.ResetHits();
- fData.GetTrack(track);
- fTrack = track;
- }
- return static_cast<AliMUONHit*>( fData.Hits()->At(hit) );
-}
-
-
-Int_t AliMUONDataInterface::NumberOfSDigits(
- TString filename, TString foldername, Int_t event,
- Int_t chamber, Int_t cathode
- )
-{
-// Returns the number of s-digits in the given file, folder, event,
-// chamber and cathode. -1 is returned on error.
-
- Assert( 0 <= chamber && chamber <= 13 );
- Assert( 0 <= cathode && cathode <= 1 );
-
- if ( ! FetchLoaders(filename, foldername) ) return -1;
- if ( ! FetchEvent(event) ) return -1;
- if ( ! FetchTreeS() ) return -1;
-
- if ( fSCathode != cathode )
- {
- fData.ResetSDigits();
- fData.GetSDigits();
- fSCathode = cathode;
- }
- return fData.SDigits(chamber)->GetEntriesFast();
-}
-
-
-AliMUONDigit* AliMUONDataInterface::SDigit(
- TString filename, TString foldername, Int_t event,
- Int_t chamber, Int_t cathode, Int_t sdigit
- )
-{
-// Returns the specified s-digit in the given file, folder, event,
-// chamber and cathode. NULL is returned on error.
-
- Assert( 0 <= chamber && chamber <= 13 );
- Assert( 0 <= cathode && cathode <= 1 );
-
- if ( ! FetchLoaders(filename, foldername) ) return NULL;
- if ( ! FetchEvent(event) ) return NULL;
- if ( ! FetchTreeS() ) return NULL;
-
- if ( fSCathode != cathode )
- {
- fData.ResetSDigits();
- fData.GetSDigits();
- fSCathode = cathode;
- }
- return static_cast<AliMUONDigit*>( fData.SDigits(chamber)->At(sdigit) );
-}
-
-
-Int_t AliMUONDataInterface::NumberOfDigits(
- TString filename, TString foldername, Int_t event,
- Int_t chamber, Int_t cathode
- )
-{
-// Returns the number of digits in the given file, folder, event,
-// chamber and cathode. -1 is returned on error.
- Assert( 0 <= chamber && chamber <= 13 );
- Assert( 0 <= cathode && cathode <= 1 );
-
- if ( ! FetchLoaders(filename, foldername) ) return -1;
- if ( ! FetchEvent(event) ) return -1;
- if ( ! FetchTreeD() ) return -1;
-
- if ( fCathode != cathode )
- {
- fData.ResetDigits();
- fData.GetDigits();
- fCathode = cathode;
- }
- return fData.Digits(chamber)->GetEntriesFast();
-}
-
-
-AliMUONDigit* AliMUONDataInterface::Digit(
- TString filename, TString foldername, Int_t event,
- Int_t chamber, Int_t cathode, Int_t digit
- )
-{
-// Returns the specified digit in the given file, folder, event,
-// chamber and cathode. NULL is returned on error.
-
- Assert( 0 <= chamber && chamber <= 13 );
- Assert( 0 <= cathode && cathode <= 1 );
-
- if ( ! FetchLoaders(filename, foldername) ) return NULL;
- if ( ! FetchEvent(event) ) return NULL;
- if ( ! FetchTreeD() ) return NULL;
-
- if ( fCathode != cathode )
- {
- fData.ResetDigits();
- fData.GetDigits();
- fCathode = cathode;
- }
- return static_cast<AliMUONDigit*>( fData.Digits(chamber)->At(digit) );
-}
-
-
-Int_t AliMUONDataInterface::NumberOfRawClusters(
- TString filename, TString foldername, Int_t event, Int_t chamber
- )
-{
-// Returns the number of raw clusters in the specified file, folder, event and chamber.
-// -1 is returned or error.
-
- Assert( 0 <= chamber && chamber <= 13 );
- if ( ! FetchLoaders(filename, foldername) ) return -1;
- if ( ! FetchEvent(event) ) return -1;
- if ( ! FetchTreeR() ) return -1;
- if ( ! fClusterAddressSet )
- {
- // If the raw cluster address in TreeR is not set yet then set it now.
- fData.SetTreeAddress("RC");
- fData.ResetRawClusters();
- fData.GetRawClusters();
- fClusterAddressSet = kTRUE;
- }
- return fData.RawClusters(chamber)->GetEntriesFast();
-}
-
-
-AliMUONRawCluster* AliMUONDataInterface::RawCluster(
- TString filename, TString foldername, Int_t event,
- Int_t chamber, Int_t cluster
- )
-{
-// Fetch the specified raw cluster from the given file, folder, event and chamber number.
-// NULL is returned on error.
-
- Assert( 0 <= chamber && chamber <= 13 );
- if ( ! FetchLoaders(filename, foldername) ) return NULL;
- if ( ! FetchEvent(event) ) return NULL;
- if ( ! FetchTreeR() ) return NULL;
- if ( ! fClusterAddressSet )
- {
- // If the raw cluster address in TreeR is not set yet then set it now.
- fData.SetTreeAddress("RC");
- fData.ResetRawClusters();
- fData.GetRawClusters();
- fClusterAddressSet = kTRUE;
- }
- return static_cast<AliMUONRawCluster*>( fData.RawClusters(chamber)->At(cluster) );
-}
-
-
-Int_t AliMUONDataInterface::NumberOfLocalTriggers(TString filename, TString foldername, Int_t event)
-{
-// Return the number of local trigger objects in the specified file, folder and
-// event number. -1 is returned on error.
-
- if ( ! FetchLoaders(filename, foldername) ) return -1;
- if ( ! FetchEvent(event) ) return -1;
- if ( ! FetchTreeR() ) return -1;
- if ( ! fTriggerAddressSet )
- {
- // If the local trigger address in TreeR is not set yet then set it now.
- fData.SetTreeAddress("GLT");
- fData.ResetTrigger();
- fData.GetTrigger();
- fTriggerAddressSet = kTRUE;
- }
- return fData.LocalTrigger()->GetEntriesFast();
-}
-
-
-AliMUONLocalTrigger* AliMUONDataInterface::LocalTrigger(
- TString filename, TString foldername, Int_t event, Int_t trigger
- )
-{
-// Fetch the specified local trigger object from the given file, folder and event number.
-// NULL is returned on error.
-
- if ( ! FetchLoaders(filename, foldername) ) return NULL;
- if ( ! FetchEvent(event) ) return NULL;
- if ( ! FetchTreeR() ) return NULL;
- if ( ! fTriggerAddressSet )
- {
- // If the local trigger address in TreeR is not set yet then set it now.
- fData.SetTreeAddress("GLT");
- fData.ResetTrigger();
- fData.GetTrigger();
- fTriggerAddressSet = kTRUE;
- }
- return static_cast<AliMUONLocalTrigger*>( fData.LocalTrigger()->At(trigger) );
-}
-
-
-Bool_t AliMUONDataInterface::SetFile(TString filename, TString foldername)
-{
-// Set the current file and folder from which to fetch data.
-// kTRUE is returned if the run and muon loaders were found, else kFALSE.
-
- return FetchLoaders(filename, foldername);
-}
-
-
+ AliMUONVTriggerStore* triggerStore = TriggerStore(ievent,treeLetter);
+
+ if (!triggerStore)
+ {
+ AliError(Form("Could not read %s from tree%s","Trigger",treeLetter));
+ return;
+ }
+
+ // get global trigger info
+ AliMUONGlobalTrigger* gloTrg = triggerStore->Global();
+ sLowpt+=gloTrg->SingleLpt();
+ sHighpt+=gloTrg->SingleHpt();
+ uSLowpt+=gloTrg->PairUnlikeLpt();
+ uSHighpt+=gloTrg->PairUnlikeHpt();
+ lSLowpt+=gloTrg->PairLikeLpt();
+ lSHighpt+=gloTrg->PairLikeHpt();
+
+ // loop on local triggers
+ TIter next(triggerStore->CreateIterator());
+ AliMUONLocalTrigger* locTrg(0x0);
+ while ( ( locTrg = static_cast<AliMUONLocalTrigger*>(next()) ) )
+ {
+ Bool_t xTrig=locTrg->IsTrigX();
+ Bool_t yTrig=locTrg->IsTrigY();
+
+ if (xTrig && yTrig)
+ { // fill ntuple if trigger in X and Y
+ tupleLoc.Fill(ievent,locTrg->LoCircuit(),
+ locTrg->LoStripX(),
+ locTrg->LoDev(),
+ locTrg->LoStripY(),
+ locTrg->LoLpt(),
+ locTrg->LoHpt(),
+ triggerCircuit.GetY11Pos(locTrg->LoCircuit(),locTrg->LoStripX()),
+ triggerCircuit.GetY21Pos(locTrg->LoCircuit(),locTrg->LoStripX()+locTrg->LoDev()+1),
+ triggerCircuit.GetX11Pos(locTrg->LoCircuit(),locTrg->LoStripY()));
+ }
+ tupleGlo.Fill(ievent,gloTrg->SingleLpt(),gloTrg->SingleHpt(),
+ gloTrg->PairUnlikeLpt(),gloTrg->PairUnlikeHpt(),
+ gloTrg->PairLikeLpt(),gloTrg->PairLikeHpt());
+ } // end of loop on local triggers
+ } // end of loop on events
+
+ // print info and store ntuples
+ printf("\n");
+ printf("=============================================\n");
+ printf("================ SUMMARY ==================\n");
+ printf("\n");
+ printf("Total number of events processed %d \n",nevents);
+ printf("\n");
+ printf(" Global Trigger output Low pt High pt\n");
+ printf(" number of Single :\t");
+ printf("%i\t%i\t",sLowpt,sHighpt);
+ printf("\n");
+ printf(" number of UnlikeSign pair :\t");
+ printf("%i\t%i\t",uSLowpt,uSHighpt);
+ printf("\n");
+ printf(" number of LikeSign pair :\t");
+ printf("%i\t%i\t",lSLowpt,lSHighpt);
+ printf("\n");
+ printf("=============================================\n");
+ fflush(stdout);
+
+ TFile myFile(fileNameOut, "RECREATE");
+ tupleGlo.Write();
+ tupleLoc.Write();
+ myFile.Close();
+}
+
+//_____________________________________________________________________________
+Bool_t
+AliMUONDataInterface::LoadEvent(Int_t event)
+{
+ /// Load event if different from the current one.
+ /// Returns kFALSE on error and kTRUE if the event was loaded.
+
+ assert( IsValid() );
+
+ AliDebug(1,Form("Loading event %d using runLoader %p",event,fLoader->GetRunLoader()));
+ if (fLoader->GetRunLoader()->GetEvent(event) == 0)
+ {
+ fCurrentEvent = event;
+ return kTRUE;
+ }
+ else
+ return kFALSE;
+}
+
+//______________________________________________________________________________
+Int_t
+AliMUONDataInterface::NumberOfEvents() const
+{
+ /// Number of events in the current galice.root file we're attached to
+ if (not IsValid()) return -1;
+ return fLoader->GetRunLoader()->GetNumberOfEvents();
+}
+
+//_____________________________________________________________________________
+void
+AliMUONDataInterface::Open(const char* filename)
+{
+ /// Connect to a given galice.root file
+
+ ResetStores();
+
+ fCurrentEvent=-1;
+
+ if ( fLoader != 0x0 )
+ {
+ delete fLoader->GetRunLoader();
+ }
+
+ fLoader = 0x0;
+
+ fIsValid = kTRUE;
+
+ TString foldername(Form("%s-%d",ClassName(),fgInstanceCounter));
+
+ while (AliRunLoader::GetRunLoader(foldername) != 0x0)
+ {
+ delete AliRunLoader::GetRunLoader(foldername);
+ }
+
+ AliRunLoader* runLoader = AliRunLoader::Open(filename,foldername);
+ if (runLoader == 0x0)
+ {
+ AliError(Form("Cannot open file %s",filename));
+ fIsValid = kFALSE;
+ }
+
+ runLoader->LoadHeader();
+ if ( ! runLoader->GetHeader() ) {
+ AliError("Cannot load header.");
+ fIsValid = kFALSE;
+ }
+ else {
+ Int_t runNumber = runLoader->GetHeader()->GetRun();
+ AliCDBManager::Instance()->SetRun(runNumber);
+ }
+ runLoader->UnloadHeader();
+
+ fLoader = runLoader->GetDetectorLoader("MUON");
+ if (fLoader == 0x0)
+ {
+ AliError("Cannot get AliMUONLoader");
+ fIsValid = kFALSE;
+ }
+
+ if (not IsValid())
+ {
+ AliError(Form("Could not access %s filename. Object is unuseable",filename));
+ }
+}
+
+//_____________________________________________________________________________