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"
33 #include "AliLoader.h"
36 #include "AliRunLoader.h"
39 #include <TParticle.h>
40 #include <Riostream.h>
47 /// \class AliMUONDataInterface
49 /// An easy to use interface to the MUON data data stored in
50 /// TreeS, TreeD, TreeR and TreeT.
52 /// For MC related information (i.e. TreeH, TreeK, TreeTR), see
53 /// AliMUONMCDataInterface.
56 /// This interface in not necessarily the fastest way to fetch the data but
57 /// it is the easiest.
59 /// \author Laurent Aphecetche, Subatech
62 ClassImp(AliMUONDataInterface)
65 //AliLoader* fLoader; //!< Tree accessor
66 //AliMUONVDigitStore* fDigitStore; //!< current digit store (owner)
67 //AliMUONVTriggerStore* fTriggerStore; //!< current trigger store (owner)
68 //AliMUONVClusterStore* fClusterStore; //!< current cluster store (owner)
69 //AliMUONVTrackStore* fTrackStore; //!< current track store (owner)
70 //AliMUONVTriggerTrackStore* fTriggerTrackStore; //!< current trigger track store (owner)
71 //Int_t fCurrentEvent; //!< Current event we've read in
72 //Bool_t fIsValid; //!< whether we were initialized properly or not
74 Int_t AliMUONDataInterface::fgInstanceCounter(0);
76 //______________________________________________________________________________
77 AliMUONDataInterface::AliMUONDataInterface(const char* filename)
84 fTriggerTrackStore(0x0),
89 /// @param filename should be the full path to a valid galice.root file
96 //______________________________________________________________________________
97 AliMUONDataInterface::~AliMUONDataInterface()
102 delete fLoader->GetRunLoader();
107 //______________________________________________________________________________
108 AliMUONVClusterStore*
109 AliMUONDataInterface::ClusterStore(Int_t event)
111 /// Return clusterStore for a given event.
112 /// Return 0x0 if event not found.
113 /// Returned pointer should not be deleted
115 if ( LoadEvent(event) ) return 0x0;
117 fLoader->LoadRecPoints();
119 TTree* treeR = fLoader->TreeR();
123 AliError("Could not get treeR");
129 fClusterStore = AliMUONVClusterStore::Create(*treeR);
134 fClusterStore->Clear();
135 fClusterStore->Connect(*treeR);
139 fLoader->UnloadRecPoints();
141 return fClusterStore;
144 //______________________________________________________________________________
146 AliMUONDataInterface::DigitStore(Int_t event)
148 /// Return digitStore for a given event.
149 /// Return 0x0 if event not found.
150 /// Returned pointer should not be deleted
152 if ( LoadEvent(event) ) return 0x0;
154 fLoader->LoadDigits();
156 TTree* treeD = fLoader->TreeD();
160 AliError("Could not get treeD");
166 fDigitStore = AliMUONVDigitStore::Create(*treeD);
171 fDigitStore->Clear();
172 fDigitStore->Connect(*treeD);
176 fLoader->UnloadDigits();
181 //______________________________________________________________________________
183 AliMUONDataInterface::DumpDigits(Int_t event, Bool_t sorted)
185 /// Dump the digits for a given event, sorted if so required
191 DumpSorted(*fDigitStore);
195 fDigitStore->Print();
200 //______________________________________________________________________________
202 AliMUONDataInterface::DumpRecPoints(Int_t event, Bool_t sorted)
204 /// Dump the recpoints for a given event, sorted if so required
210 DumpSorted(*fClusterStore);
214 fClusterStore->Print();
219 //_____________________________________________________________________________
221 AliMUONDataInterface::DumpSorted(const AliMUONVStore& store) const
223 /// Dump the given store, in sorted order
225 TIter next(store.CreateIterator());
228 list.SetOwner(kFALSE);
230 while ( ( object = next() ) )
240 //______________________________________________________________________________
242 AliMUONDataInterface::DumpTracks(Int_t event, Bool_t sorted)
244 /// Dump tracks for a given event, sorted if requested
252 DumpSorted(*fTrackStore);
256 fTrackStore->Print();
261 //______________________________________________________________________________
263 AliMUONDataInterface::DumpTriggerTracks(Int_t event, Bool_t sorted)
265 /// Dump trigger tracks for a given event, sorted if requested
267 TriggerTrackStore(event);
269 if ( fTriggerTrackStore )
273 DumpSorted(*fTriggerTrackStore);
277 fTriggerTrackStore->Print();
282 //_____________________________________________________________________________
284 AliMUONDataInterface::DumpTrigger(Int_t event, const char* treeLetter)
286 /// Dump trigger for a given event from a given tree (if event>=0)
287 /// or loop over all events and build a trigger ntuple if event<0
288 /// treeLetter can be R or D to tell from which tree to read the information
292 NtupleTrigger(treeLetter);
296 TriggerStore(event,treeLetter);
300 fTriggerStore->Print();
305 //_____________________________________________________________________________
307 AliMUONDataInterface::NtupleTrigger(const char* treeLetter)
309 //// Loop over events to build trigger ntuples
312 TString sTreeLetter(treeLetter);
313 sTreeLetter.ToUpper();
315 if ( sTreeLetter != "R" && sTreeLetter != "D" )
317 AliError(Form("Cannot handle tree%s. Use D or R",treeLetter));
322 TNtuple tupleGlo("TgtupleGlo","Global Trigger Ntuple",
323 "ev:slpt:shpt:uplpt:uphpt:lplpt:lplpt");
324 TNtuple tupleLoc("TgtupleLoc","Local Trigger Ntuple",
325 "ev:LoCircuit:LoStripX:LoDev:StripY:LoLpt:LoHpt:y11:y21:x11");
327 // initialize counters
335 AliMUONGeometryTransformer transformer;
336 transformer.LoadGeometryData(Form("%s/geometry.root",
337 gSystem->DirName(fLoader->GetRunLoader()->GetFileName())));
339 AliMUONTriggerCircuit triggerCircuit(&transformer);
341 // select output file name from selected Tree
342 Char_t fileNameOut[30];
343 if (sTreeLetter == "D")
345 AliInfo(Form("reading from Digits\n"));
346 sprintf(fileNameOut,"TriggerCheckFromDigits.root");
348 else if (sTreeLetter == "R")
350 AliInfo(Form("reading from RecPoints\n"));
351 sprintf(fileNameOut,"TriggerCheckFromRP.root");
355 Int_t nevents = NumberOfEvents();
357 for (Int_t ievent=0; ievent<nevents; ++ievent)
359 if (ievent%100==0) AliInfo(Form("Processing event %d\n",ievent));
361 AliMUONVTriggerStore* triggerStore = TriggerStore(ievent);
365 AliError(Form("Could not read %s from tree%s","Trigger",treeLetter));
369 // get global trigger info
370 AliMUONGlobalTrigger* gloTrg = triggerStore->Global();
371 sLowpt+=gloTrg->SingleLpt();
372 sHighpt+=gloTrg->SingleHpt();
373 uSLowpt+=gloTrg->PairUnlikeLpt();
374 uSHighpt+=gloTrg->PairUnlikeHpt();
375 lSLowpt+=gloTrg->PairLikeLpt();
376 lSHighpt+=gloTrg->PairLikeHpt();
378 // loop on local triggers
379 TIter next(triggerStore->CreateIterator());
380 AliMUONLocalTrigger* locTrg(0x0);
381 while ( ( locTrg = static_cast<AliMUONLocalTrigger*>(next()) ) )
386 if ( locTrg->LoSdev()==1 && locTrg->LoDev()==0 &&
387 locTrg->LoStripX()==0) xTrig=kFALSE; // no trigger in X
388 else xTrig=kTRUE; // trigger in X
389 if (locTrg->LoTrigY()==1 &&
390 locTrg->LoStripY()==15 ) yTrig = kFALSE; // no trigger in Y
391 else yTrig = kTRUE; // trigger in Y
394 { // fill ntuple if trigger in X and Y
395 tupleLoc.Fill(ievent,locTrg->LoCircuit(),
401 triggerCircuit.GetY11Pos(locTrg->LoCircuit(),locTrg->LoStripX()),
402 triggerCircuit.GetY21Pos(locTrg->LoCircuit(),locTrg->LoStripX()+locTrg->LoDev()+1),
403 triggerCircuit.GetX11Pos(locTrg->LoCircuit(),locTrg->LoStripY()));
405 tupleGlo.Fill(ievent,gloTrg->SingleLpt(),gloTrg->SingleHpt(),
406 gloTrg->PairUnlikeLpt(),gloTrg->PairUnlikeHpt(),
407 gloTrg->PairLikeLpt(),gloTrg->PairLikeHpt());
408 } // end of loop on local triggers
409 } // end of loop on events
411 // print info and store ntuples
413 printf("=============================================\n");
414 printf("================ SUMMARY ==================\n");
416 printf("Total number of events processed %d \n",nevents);
418 printf(" Global Trigger output Low pt High pt\n");
419 printf(" number of Single :\t");
420 printf("%i\t%i\t",sLowpt,sHighpt);
422 printf(" number of UnlikeSign pair :\t");
423 printf("%i\t%i\t",uSLowpt,uSHighpt);
425 printf(" number of LikeSign pair :\t");
426 printf("%i\t%i\t",lSLowpt,lSHighpt);
428 printf("=============================================\n");
431 TFile myFile(fileNameOut, "RECREATE");
437 //______________________________________________________________________________
439 AliMUONDataInterface::IsValid() const
441 /// Whether we were properly initialized from a valid galice.root file
445 //_____________________________________________________________________________
447 AliMUONDataInterface::LoadEvent(Int_t event)
449 /// Load event if different from the current one.
450 if ( event != fCurrentEvent )
452 fCurrentEvent = event;
453 AliDebug(1,Form("Loading event %d using runLoader %p",event,fLoader->GetRunLoader()));
454 if ( event < NumberOfEvents() )
456 return fLoader->GetRunLoader()->GetEvent(event);
466 //______________________________________________________________________________
468 AliMUONDataInterface::NumberOfEvents() const
470 /// Number of events in the current galice.root file we're attached to
471 if (!IsValid()) return 0;
472 return fLoader->GetRunLoader()->GetNumberOfEvents();
475 //_____________________________________________________________________________
477 AliMUONDataInterface::Open(const char* filename)
479 /// Connect to a given galice.root file
483 delete fTriggerStore;
485 delete fClusterStore;
489 delete fTriggerTrackStore;
490 fTriggerTrackStore=0x0;
496 delete fLoader->GetRunLoader();
503 TString foldername(Form("%s-%d",ClassName(),fgInstanceCounter));
505 while (AliRunLoader::GetRunLoader(foldername))
507 delete AliRunLoader::GetRunLoader(foldername);
510 AliRunLoader* runLoader = AliRunLoader::Open(filename,foldername);
513 AliError(Form("Cannot open file %s",filename));
516 fLoader = runLoader->GetDetectorLoader("MUON");
519 AliError("Cannot get AliMUONLoader");
525 AliError(Form("Could not access %s filename. Object is unuseable",filename));
529 //______________________________________________________________________________
531 AliMUONDataInterface::TrackStore(Int_t event)
533 /// Return the trackStore for a given event.
534 /// Return 0x0 if event not found.
535 /// Returned pointer should not be deleted
537 if ( LoadEvent(event) ) return 0x0;
539 fLoader->LoadTracks();
541 TTree* treeT = fLoader->TreeT();
545 AliError("Could not get treeT");
551 fTrackStore = AliMUONVTrackStore::Create(*treeT);
556 fTrackStore->Clear();
557 fTrackStore->Connect(*treeT);
561 fLoader->UnloadTracks();
566 //______________________________________________________________________________
567 AliMUONVTriggerTrackStore*
568 AliMUONDataInterface::TriggerTrackStore(Int_t event)
570 /// Return the triggerTrackStore for a given event.
571 /// Return 0x0 if event not found.
572 /// Returned pointer should not be deleted
574 if ( LoadEvent(event) ) return 0x0;
576 fLoader->LoadTracks();
578 TTree* treeT = fLoader->TreeT();
582 AliError("Could not get treeT");
586 if (!fTriggerTrackStore)
588 fTriggerTrackStore = AliMUONVTriggerTrackStore::Create(*treeT);
591 if ( fTriggerTrackStore )
593 fTriggerTrackStore->Clear();
594 fTriggerTrackStore->Connect(*treeT);
598 fLoader->UnloadTracks();
600 return fTriggerTrackStore;
603 //_____________________________________________________________________________
604 AliMUONVTriggerStore*
605 AliMUONDataInterface::TriggerStore(Int_t event, const char* treeLetter)
607 /// Return the triggerStore for a given event.
608 /// Return 0x0 if event not found.
609 /// Returned pointer should not be deleted
610 /// treeLetter can be R or D to tell from which tree to read the information
612 if ( LoadEvent(event) ) return 0x0;
616 TString stree(treeLetter);
621 fLoader->LoadDigits();
622 tree = fLoader->TreeD();
624 else if ( stree == "R" )
626 fLoader->LoadRecPoints();
627 tree = fLoader->TreeR();
632 AliError(Form("Could not get tree%s",treeLetter));
638 fTriggerStore = AliMUONVTriggerStore::Create(*tree);
643 fTriggerStore->Clear();
644 fTriggerStore->Connect(*tree);
650 fLoader->UnloadDigits();
652 else if ( stree == "R" )
654 fLoader->UnloadRecPoints();
657 return fTriggerStore;
660 //______________________________________________________________________________
661 //______________________________________________________________________________
662 //______________________________________________________________________________
663 //______________________________________________________________________________
665 void AliMUONDataInterface::Reset()
667 /// \deprecated Method is going to be removed
669 AliFatal("Deprecated");
672 Bool_t AliMUONDataInterface::UseCurrentRunLoader()
674 /// \deprecated Method is going to be removed
676 AliFatal("Deprecated");
680 Int_t AliMUONDataInterface::NumberOfEvents(TString , TString )
682 /// \deprecated Method is going to be removed
684 AliFatal("Deprecated");
689 Int_t AliMUONDataInterface::NumberOfParticles(TString , TString , Int_t )
691 /// \deprecated Method is going to be removed
693 AliFatal("Deprecated");
698 TParticle* AliMUONDataInterface::Particle(
699 TString , TString , Int_t , Int_t
702 /// \deprecated Method is going to be removed
704 AliFatal("Deprecated");
709 Int_t AliMUONDataInterface::NumberOfTracks(TString , TString , Int_t )
711 /// \deprecated Method is going to be removed
713 AliFatal("Deprecated");
718 Int_t AliMUONDataInterface::NumberOfHits(
719 TString , TString , Int_t , Int_t
722 /// \deprecated Method is going to be removed
724 AliFatal("Deprecated");
729 AliMUONHit* AliMUONDataInterface::Hit(
730 TString , TString , Int_t ,
734 /// \deprecated Method is going to be removed
736 AliFatal("Deprecated");
741 Int_t AliMUONDataInterface::NumberOfSDigits(
742 TString , TString , Int_t ,
746 /// \deprecated Method is going to be removed
748 AliFatal("Deprecated");
753 AliMUONDigit* AliMUONDataInterface::SDigit(
754 TString , TString , Int_t ,
755 Int_t , Int_t , Int_t
758 /// \deprecated Method is going to be removed
760 AliFatal("Deprecated");
765 Int_t AliMUONDataInterface::NumberOfDigits(
766 TString , TString , Int_t ,
770 /// \deprecated Method is going to be removed
772 AliFatal("Deprecated");
777 AliMUONDigit* AliMUONDataInterface::Digit(
778 TString , TString , Int_t ,
779 Int_t , Int_t , Int_t
782 /// \deprecated Method is going to be removed
784 AliFatal("Deprecated");
789 Int_t AliMUONDataInterface::NumberOfRawClusters(
790 TString , TString , Int_t , Int_t
793 /// \deprecated Method is going to be removed
795 AliFatal("Deprecated");
800 AliMUONRawCluster* AliMUONDataInterface::RawCluster(
801 TString , TString , Int_t ,
805 /// \deprecated Method is going to be removed
807 AliFatal("Deprecated");
812 Int_t AliMUONDataInterface::NumberOfLocalTriggers(TString , TString , Int_t )
814 /// \deprecated Method is going to be removed
816 AliFatal("Deprecated");
821 AliMUONLocalTrigger* AliMUONDataInterface::LocalTrigger(
822 TString , TString , Int_t , Int_t
825 /// \deprecated Method is going to be removed
827 AliFatal("Deprecated");
831 Bool_t AliMUONDataInterface::SetFile(TString , TString )
833 /// \deprecated Method is going to be removed
835 AliFatal("Deprecated");
840 Bool_t AliMUONDataInterface::GetEvent(Int_t )
842 /// \deprecated Method is going to be removed
844 AliFatal("Deprecated");
848 Int_t AliMUONDataInterface::NumberOfParticles()
850 /// \deprecated Method is going to be removed
852 AliFatal("Deprecated");
857 TParticle* AliMUONDataInterface::Particle(Int_t )
859 /// \deprecated Method is going to be removed
861 AliFatal("Deprecated");
866 Int_t AliMUONDataInterface::NumberOfTracks()
868 /// \deprecated Method is going to be removed
870 AliFatal("Deprecated");
875 Int_t AliMUONDataInterface::NumberOfHits(Int_t )
877 /// \deprecated Method is going to be removed
879 AliFatal("Deprecated");
885 AliMUONDataInterface::Hit(Int_t , Int_t )
887 /// \deprecated Method is going to be removed
889 AliFatal("Deprecated");
894 Int_t AliMUONDataInterface::NumberOfSDigits(Int_t , Int_t )
896 /// \deprecated Method is going to be removed
898 AliFatal("Deprecated");
903 AliMUONDigit* AliMUONDataInterface::SDigit(Int_t , Int_t , Int_t )
905 /// \deprecated Method is going to be removed
907 AliFatal("Deprecated");
913 Int_t AliMUONDataInterface::NumberOfDigits(Int_t , Int_t )
915 /// \deprecated Method is going to be removed
917 AliFatal("Deprecated");
923 AliMUONDigit* AliMUONDataInterface::Digit(Int_t , Int_t , Int_t )
925 /// \deprecated Method is going to be removed
927 AliFatal("Deprecated");
932 Int_t AliMUONDataInterface::NumberOfRawClusters(Int_t )
934 /// \deprecated Method is going to be removed
936 AliFatal("Deprecated");
941 AliMUONRawCluster* AliMUONDataInterface::RawCluster(Int_t , Int_t )
943 /// \deprecated Method is going to be removed
945 AliFatal("Deprecated");
950 Int_t AliMUONDataInterface::NumberOfLocalTriggers()
952 /// \deprecated Method is going to be removed
954 AliFatal("Deprecated");
959 AliMUONLocalTrigger* AliMUONDataInterface::LocalTrigger(Int_t )
961 /// \deprecated Method is going to be removed
963 AliFatal("Deprecated");
967 Int_t AliMUONDataInterface::NumberOfGlobalTriggers()
969 /// \deprecated Method is going to be removed
971 AliFatal("Deprecated");
975 AliMUONGlobalTrigger* AliMUONDataInterface::GlobalTrigger(Int_t )
977 /// \deprecated Method is going to be removed
979 AliFatal("Deprecated");
983 Int_t AliMUONDataInterface::NumberOfRecTracks()
985 /// \deprecated Method is going to be removed
987 AliFatal("Deprecated");
991 AliMUONTrack* AliMUONDataInterface::RecTrack(Int_t )
993 /// \deprecated Method is going to be removed
995 AliFatal("Deprecated");