1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 #include "AliMUONDataInterface.h"
19 #include "AliMUONDigit.h"
20 #include "AliMUONGeometryTransformer.h"
21 #include "AliMUONGlobalTrigger.h"
22 #include "AliMUONHit.h"
23 #include "AliMUONLocalTrigger.h"
24 #include "AliMUONRawCluster.h"
25 #include "AliMUONTrack.h"
26 #include "AliMUONTriggerCircuit.h"
27 #include "AliMUONVClusterStore.h"
28 #include "AliMUONVDigitStore.h"
29 #include "AliMUONVTrackStore.h"
30 #include "AliMUONVTriggerStore.h"
31 #include "AliMUONVTriggerTrackStore.h"
34 #include "AliLoader.h"
37 #include "AliRunLoader.h"
40 #include <TParticle.h>
41 #include <Riostream.h>
47 //-----------------------------------------------------------------------------
48 /// \class AliMUONDataInterface
50 /// An easy to use interface to the MUON data data stored in
51 /// TreeS, TreeD, TreeR and TreeT.
53 /// For MC related information (i.e. TreeH, TreeK, TreeTR), see
54 /// AliMUONMCDataInterface.
57 /// This interface in not necessarily the fastest way to fetch the data but
58 /// it is the easiest.
60 /// \author Laurent Aphecetche, Subatech
61 //-----------------------------------------------------------------------------
64 ClassImp(AliMUONDataInterface)
67 //AliLoader* fLoader; //!< Tree accessor
68 //AliMUONVDigitStore* fDigitStore; //!< current digit store (owner)
69 //AliMUONVTriggerStore* fTriggerStore; //!< current trigger store (owner)
70 //AliMUONVClusterStore* fClusterStore; //!< current cluster store (owner)
71 //AliMUONVTrackStore* fTrackStore; //!< current track store (owner)
72 //AliMUONVTriggerTrackStore* fTriggerTrackStore; //!< current trigger track store (owner)
73 //Int_t fCurrentEvent; //!< Current event we've read in
74 //Bool_t fIsValid; //!< whether we were initialized properly or not
76 Int_t AliMUONDataInterface::fgInstanceCounter(0);
78 //______________________________________________________________________________
79 AliMUONDataInterface::AliMUONDataInterface(const char* filename)
86 fTriggerTrackStore(0x0),
91 /// @param filename should be the full path to a valid galice.root file
98 //______________________________________________________________________________
99 AliMUONDataInterface::~AliMUONDataInterface()
104 delete fLoader->GetRunLoader();
109 //______________________________________________________________________________
110 AliMUONVClusterStore*
111 AliMUONDataInterface::ClusterStore(Int_t event)
113 /// Return clusterStore for a given event.
114 /// Return 0x0 if event not found.
115 /// Returned pointer should not be deleted
117 if ( LoadEvent(event) ) return 0x0;
119 fLoader->LoadRecPoints();
121 TTree* treeR = fLoader->TreeR();
125 AliError("Could not get treeR");
131 fClusterStore = AliMUONVClusterStore::Create(*treeR);
136 fClusterStore->Clear();
137 fClusterStore->Connect(*treeR);
141 fLoader->UnloadRecPoints();
143 return fClusterStore;
146 //______________________________________________________________________________
148 AliMUONDataInterface::DigitStore(Int_t event)
150 /// Return digitStore for a given event.
151 /// Return 0x0 if event not found.
152 /// Returned pointer should not be deleted
154 if ( LoadEvent(event) ) return 0x0;
156 fLoader->LoadDigits();
158 TTree* treeD = fLoader->TreeD();
162 AliError("Could not get treeD");
168 fDigitStore = AliMUONVDigitStore::Create(*treeD);
173 fDigitStore->Clear();
174 fDigitStore->Connect(*treeD);
178 fLoader->UnloadDigits();
183 //______________________________________________________________________________
185 AliMUONDataInterface::DumpDigits(Int_t event, Bool_t sorted)
187 /// Dump the digits for a given event, sorted if so required
193 DumpSorted(*fDigitStore);
197 fDigitStore->Print();
202 //______________________________________________________________________________
204 AliMUONDataInterface::DumpRecPoints(Int_t event, Bool_t sorted)
206 /// Dump the recpoints for a given event, sorted if so required
212 DumpSorted(*fClusterStore);
216 fClusterStore->Print();
221 //_____________________________________________________________________________
223 AliMUONDataInterface::DumpSorted(const AliMUONVStore& store) const
225 /// Dump the given store, in sorted order
227 TIter next(store.CreateIterator());
230 list.SetOwner(kFALSE);
232 while ( ( object = next() ) )
242 //______________________________________________________________________________
244 AliMUONDataInterface::DumpTracks(Int_t event, Bool_t sorted)
246 /// Dump tracks for a given event, sorted if requested
254 DumpSorted(*fTrackStore);
258 fTrackStore->Print();
263 //______________________________________________________________________________
265 AliMUONDataInterface::DumpTriggerTracks(Int_t event, Bool_t sorted)
267 /// Dump trigger tracks for a given event, sorted if requested
269 TriggerTrackStore(event);
271 if ( fTriggerTrackStore )
275 DumpSorted(*fTriggerTrackStore);
279 fTriggerTrackStore->Print();
284 //_____________________________________________________________________________
286 AliMUONDataInterface::DumpTrigger(Int_t event, const char* treeLetter)
288 /// Dump trigger for a given event from a given tree (if event>=0)
289 /// or loop over all events and build a trigger ntuple if event<0
290 /// treeLetter can be R or D to tell from which tree to read the information
294 NtupleTrigger(treeLetter);
298 TriggerStore(event,treeLetter);
302 fTriggerStore->Print();
307 //_____________________________________________________________________________
309 AliMUONDataInterface::NtupleTrigger(const char* treeLetter)
311 //// Loop over events to build trigger ntuples
314 TString sTreeLetter(treeLetter);
315 sTreeLetter.ToUpper();
317 if ( sTreeLetter != "R" && sTreeLetter != "D" )
319 AliError(Form("Cannot handle tree%s. Use D or R",treeLetter));
324 TNtuple tupleGlo("TgtupleGlo","Global Trigger Ntuple",
325 "ev:slpt:shpt:uplpt:uphpt:lplpt:lplpt");
326 TNtuple tupleLoc("TgtupleLoc","Local Trigger Ntuple",
327 "ev:LoCircuit:LoStripX:LoDev:StripY:LoLpt:LoHpt:y11:y21:x11");
329 // initialize counters
337 AliMUONGeometryTransformer transformer;
338 transformer.LoadGeometryData(Form("%s/geometry.root",
339 gSystem->DirName(fLoader->GetRunLoader()->GetFileName())));
342 if ( ! AliMpCDB::LoadMpSegmentation() )
344 AliFatal("Could not access mapping from OCDB !");
348 if ( ! AliMpCDB::LoadDDLStore() )
350 AliFatal("Could not access DDL Store from OCDB !");
353 AliMUONTriggerCircuit triggerCircuit(&transformer);
355 // select output file name from selected Tree
356 Char_t fileNameOut[30];
357 if (sTreeLetter == "D")
359 AliInfo(Form("reading from Digits\n"));
360 sprintf(fileNameOut,"TriggerCheckFromDigits.root");
362 else if (sTreeLetter == "R")
364 AliInfo(Form("reading from RecPoints\n"));
365 sprintf(fileNameOut,"TriggerCheckFromRP.root");
369 Int_t nevents = NumberOfEvents();
371 for (Int_t ievent=0; ievent<nevents; ++ievent)
373 if (ievent%100==0) AliInfo(Form("Processing event %d\n",ievent));
375 AliMUONVTriggerStore* triggerStore = TriggerStore(ievent);
379 AliError(Form("Could not read %s from tree%s","Trigger",treeLetter));
383 // get global trigger info
384 AliMUONGlobalTrigger* gloTrg = triggerStore->Global();
385 sLowpt+=gloTrg->SingleLpt();
386 sHighpt+=gloTrg->SingleHpt();
387 uSLowpt+=gloTrg->PairUnlikeLpt();
388 uSHighpt+=gloTrg->PairUnlikeHpt();
389 lSLowpt+=gloTrg->PairLikeLpt();
390 lSHighpt+=gloTrg->PairLikeHpt();
392 // loop on local triggers
393 TIter next(triggerStore->CreateIterator());
394 AliMUONLocalTrigger* locTrg(0x0);
395 while ( ( locTrg = static_cast<AliMUONLocalTrigger*>(next()) ) )
400 if ( locTrg->LoSdev()==1 && locTrg->LoDev()==0 &&
401 locTrg->LoStripX()==0) xTrig=kFALSE; // no trigger in X
402 else xTrig=kTRUE; // trigger in X
403 if (locTrg->LoTrigY()==1 &&
404 locTrg->LoStripY()==15 ) yTrig = kFALSE; // no trigger in Y
405 else yTrig = kTRUE; // trigger in Y
408 { // fill ntuple if trigger in X and Y
409 tupleLoc.Fill(ievent,locTrg->LoCircuit(),
415 triggerCircuit.GetY11Pos(locTrg->LoCircuit(),locTrg->LoStripX()),
416 triggerCircuit.GetY21Pos(locTrg->LoCircuit(),locTrg->LoStripX()+locTrg->LoDev()+1),
417 triggerCircuit.GetX11Pos(locTrg->LoCircuit(),locTrg->LoStripY()));
419 tupleGlo.Fill(ievent,gloTrg->SingleLpt(),gloTrg->SingleHpt(),
420 gloTrg->PairUnlikeLpt(),gloTrg->PairUnlikeHpt(),
421 gloTrg->PairLikeLpt(),gloTrg->PairLikeHpt());
422 } // end of loop on local triggers
423 } // end of loop on events
425 // print info and store ntuples
427 printf("=============================================\n");
428 printf("================ SUMMARY ==================\n");
430 printf("Total number of events processed %d \n",nevents);
432 printf(" Global Trigger output Low pt High pt\n");
433 printf(" number of Single :\t");
434 printf("%i\t%i\t",sLowpt,sHighpt);
436 printf(" number of UnlikeSign pair :\t");
437 printf("%i\t%i\t",uSLowpt,uSHighpt);
439 printf(" number of LikeSign pair :\t");
440 printf("%i\t%i\t",lSLowpt,lSHighpt);
442 printf("=============================================\n");
445 TFile myFile(fileNameOut, "RECREATE");
451 //______________________________________________________________________________
453 AliMUONDataInterface::IsValid() const
455 /// Whether we were properly initialized from a valid galice.root file
459 //_____________________________________________________________________________
461 AliMUONDataInterface::LoadEvent(Int_t event)
463 /// Load event if different from the current one.
464 if ( event != fCurrentEvent )
466 fCurrentEvent = event;
467 AliDebug(1,Form("Loading event %d using runLoader %p",event,fLoader->GetRunLoader()));
468 if ( event < NumberOfEvents() )
470 return fLoader->GetRunLoader()->GetEvent(event);
480 //______________________________________________________________________________
482 AliMUONDataInterface::NumberOfEvents() const
484 /// Number of events in the current galice.root file we're attached to
485 if (!IsValid()) return 0;
486 return fLoader->GetRunLoader()->GetNumberOfEvents();
489 //_____________________________________________________________________________
491 AliMUONDataInterface::Open(const char* filename)
493 /// Connect to a given galice.root file
497 delete fTriggerStore;
499 delete fClusterStore;
503 delete fTriggerTrackStore;
504 fTriggerTrackStore=0x0;
510 delete fLoader->GetRunLoader();
517 TString foldername(Form("%s-%d",ClassName(),fgInstanceCounter));
519 while (AliRunLoader::GetRunLoader(foldername))
521 delete AliRunLoader::GetRunLoader(foldername);
524 AliRunLoader* runLoader = AliRunLoader::Open(filename,foldername);
527 AliError(Form("Cannot open file %s",filename));
530 fLoader = runLoader->GetDetectorLoader("MUON");
533 AliError("Cannot get AliMUONLoader");
539 AliError(Form("Could not access %s filename. Object is unuseable",filename));
543 //______________________________________________________________________________
545 AliMUONDataInterface::TrackStore(Int_t event)
547 /// Return the trackStore for a given event.
548 /// Return 0x0 if event not found.
549 /// Returned pointer should not be deleted
551 if ( LoadEvent(event) ) return 0x0;
553 fLoader->LoadTracks();
555 TTree* treeT = fLoader->TreeT();
559 AliError("Could not get treeT");
565 fTrackStore = AliMUONVTrackStore::Create(*treeT);
570 fTrackStore->Clear();
571 fTrackStore->Connect(*treeT);
575 fLoader->UnloadTracks();
580 //______________________________________________________________________________
581 AliMUONVTriggerTrackStore*
582 AliMUONDataInterface::TriggerTrackStore(Int_t event)
584 /// Return the triggerTrackStore for a given event.
585 /// Return 0x0 if event not found.
586 /// Returned pointer should not be deleted
588 if ( LoadEvent(event) ) return 0x0;
590 fLoader->LoadTracks();
592 TTree* treeT = fLoader->TreeT();
596 AliError("Could not get treeT");
600 if (!fTriggerTrackStore)
602 fTriggerTrackStore = AliMUONVTriggerTrackStore::Create(*treeT);
605 if ( fTriggerTrackStore )
607 fTriggerTrackStore->Clear();
608 fTriggerTrackStore->Connect(*treeT);
612 fLoader->UnloadTracks();
614 return fTriggerTrackStore;
617 //_____________________________________________________________________________
618 AliMUONVTriggerStore*
619 AliMUONDataInterface::TriggerStore(Int_t event, const char* treeLetter)
621 /// Return the triggerStore for a given event.
622 /// Return 0x0 if event not found.
623 /// Returned pointer should not be deleted
624 /// treeLetter can be R or D to tell from which tree to read the information
626 if ( LoadEvent(event) ) return 0x0;
630 TString stree(treeLetter);
635 fLoader->LoadDigits();
636 tree = fLoader->TreeD();
638 else if ( stree == "R" )
640 fLoader->LoadRecPoints();
641 tree = fLoader->TreeR();
646 AliError(Form("Could not get tree%s",treeLetter));
652 fTriggerStore = AliMUONVTriggerStore::Create(*tree);
657 fTriggerStore->Clear();
658 fTriggerStore->Connect(*tree);
664 fLoader->UnloadDigits();
666 else if ( stree == "R" )
668 fLoader->UnloadRecPoints();
671 return fTriggerStore;
674 //______________________________________________________________________________
675 //______________________________________________________________________________
676 //______________________________________________________________________________
677 //______________________________________________________________________________
679 void AliMUONDataInterface::Reset()
681 /// \deprecated Method is going to be removed
683 AliFatal("Deprecated");
686 Bool_t AliMUONDataInterface::UseCurrentRunLoader()
688 /// \deprecated Method is going to be removed
690 AliFatal("Deprecated");
694 Int_t AliMUONDataInterface::NumberOfEvents(TString , TString )
696 /// \deprecated Method is going to be removed
698 AliFatal("Deprecated");
703 Int_t AliMUONDataInterface::NumberOfParticles(TString , TString , Int_t )
705 /// \deprecated Method is going to be removed
707 AliFatal("Deprecated");
712 TParticle* AliMUONDataInterface::Particle(
713 TString , TString , Int_t , Int_t
716 /// \deprecated Method is going to be removed
718 AliFatal("Deprecated");
723 Int_t AliMUONDataInterface::NumberOfTracks(TString , TString , Int_t )
725 /// \deprecated Method is going to be removed
727 AliFatal("Deprecated");
732 Int_t AliMUONDataInterface::NumberOfHits(
733 TString , TString , Int_t , Int_t
736 /// \deprecated Method is going to be removed
738 AliFatal("Deprecated");
743 AliMUONHit* AliMUONDataInterface::Hit(
744 TString , TString , Int_t ,
748 /// \deprecated Method is going to be removed
750 AliFatal("Deprecated");
755 Int_t AliMUONDataInterface::NumberOfSDigits(
756 TString , TString , Int_t ,
760 /// \deprecated Method is going to be removed
762 AliFatal("Deprecated");
767 AliMUONDigit* AliMUONDataInterface::SDigit(
768 TString , TString , Int_t ,
769 Int_t , Int_t , Int_t
772 /// \deprecated Method is going to be removed
774 AliFatal("Deprecated");
779 Int_t AliMUONDataInterface::NumberOfDigits(
780 TString , TString , Int_t ,
784 /// \deprecated Method is going to be removed
786 AliFatal("Deprecated");
791 AliMUONDigit* AliMUONDataInterface::Digit(
792 TString , TString , Int_t ,
793 Int_t , Int_t , Int_t
796 /// \deprecated Method is going to be removed
798 AliFatal("Deprecated");
803 Int_t AliMUONDataInterface::NumberOfRawClusters(
804 TString , TString , Int_t , Int_t
807 /// \deprecated Method is going to be removed
809 AliFatal("Deprecated");
814 AliMUONRawCluster* AliMUONDataInterface::RawCluster(
815 TString , TString , Int_t ,
819 /// \deprecated Method is going to be removed
821 AliFatal("Deprecated");
826 Int_t AliMUONDataInterface::NumberOfLocalTriggers(TString , TString , Int_t )
828 /// \deprecated Method is going to be removed
830 AliFatal("Deprecated");
835 AliMUONLocalTrigger* AliMUONDataInterface::LocalTrigger(
836 TString , TString , Int_t , Int_t
839 /// \deprecated Method is going to be removed
841 AliFatal("Deprecated");
845 Bool_t AliMUONDataInterface::SetFile(TString , TString )
847 /// \deprecated Method is going to be removed
849 AliFatal("Deprecated");
854 Bool_t AliMUONDataInterface::GetEvent(Int_t )
856 /// \deprecated Method is going to be removed
858 AliFatal("Deprecated");
862 Int_t AliMUONDataInterface::NumberOfParticles()
864 /// \deprecated Method is going to be removed
866 AliFatal("Deprecated");
871 TParticle* AliMUONDataInterface::Particle(Int_t )
873 /// \deprecated Method is going to be removed
875 AliFatal("Deprecated");
880 Int_t AliMUONDataInterface::NumberOfTracks()
882 /// \deprecated Method is going to be removed
884 AliFatal("Deprecated");
889 Int_t AliMUONDataInterface::NumberOfHits(Int_t )
891 /// \deprecated Method is going to be removed
893 AliFatal("Deprecated");
899 AliMUONDataInterface::Hit(Int_t , Int_t )
901 /// \deprecated Method is going to be removed
903 AliFatal("Deprecated");
908 Int_t AliMUONDataInterface::NumberOfSDigits(Int_t , Int_t )
910 /// \deprecated Method is going to be removed
912 AliFatal("Deprecated");
917 AliMUONDigit* AliMUONDataInterface::SDigit(Int_t , Int_t , Int_t )
919 /// \deprecated Method is going to be removed
921 AliFatal("Deprecated");
927 Int_t AliMUONDataInterface::NumberOfDigits(Int_t , Int_t )
929 /// \deprecated Method is going to be removed
931 AliFatal("Deprecated");
937 AliMUONDigit* AliMUONDataInterface::Digit(Int_t , Int_t , Int_t )
939 /// \deprecated Method is going to be removed
941 AliFatal("Deprecated");
946 Int_t AliMUONDataInterface::NumberOfRawClusters(Int_t )
948 /// \deprecated Method is going to be removed
950 AliFatal("Deprecated");
955 AliMUONRawCluster* AliMUONDataInterface::RawCluster(Int_t , Int_t )
957 /// \deprecated Method is going to be removed
959 AliFatal("Deprecated");
964 Int_t AliMUONDataInterface::NumberOfLocalTriggers()
966 /// \deprecated Method is going to be removed
968 AliFatal("Deprecated");
973 AliMUONLocalTrigger* AliMUONDataInterface::LocalTrigger(Int_t )
975 /// \deprecated Method is going to be removed
977 AliFatal("Deprecated");
981 Int_t AliMUONDataInterface::NumberOfGlobalTriggers()
983 /// \deprecated Method is going to be removed
985 AliFatal("Deprecated");
989 AliMUONGlobalTrigger* AliMUONDataInterface::GlobalTrigger(Int_t )
991 /// \deprecated Method is going to be removed
993 AliFatal("Deprecated");
997 Int_t AliMUONDataInterface::NumberOfRecTracks()
999 /// \deprecated Method is going to be removed
1001 AliFatal("Deprecated");
1005 AliMUONTrack* AliMUONDataInterface::RecTrack(Int_t )
1007 /// \deprecated Method is going to be removed
1009 AliFatal("Deprecated");