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(kFALSE);
336 transformer.ReadGeometryData("volpath.dat",
337 Form("%s/geometry.root",
338 gSystem->DirName(fLoader->GetRunLoader()->GetFileName())));
340 AliMUONTriggerCircuit triggerCircuit(&transformer);
342 // select output file name from selected Tree
343 Char_t fileNameOut[30];
344 if (sTreeLetter == "D")
346 AliInfo(Form("reading from Digits\n"));
347 sprintf(fileNameOut,"TriggerCheckFromDigits.root");
349 else if (sTreeLetter == "R")
351 AliInfo(Form("reading from RecPoints\n"));
352 sprintf(fileNameOut,"TriggerCheckFromRP.root");
356 Int_t nevents = NumberOfEvents();
358 for (Int_t ievent=0; ievent<nevents; ++ievent)
360 if (ievent%100==0) AliInfo(Form("Processing event %d\n",ievent));
362 AliMUONVTriggerStore* triggerStore = TriggerStore(ievent);
366 AliError(Form("Could not read %s from tree%s","Trigger",treeLetter));
370 // get global trigger info
371 AliMUONGlobalTrigger* gloTrg = triggerStore->Global();
372 sLowpt+=gloTrg->SingleLpt();
373 sHighpt+=gloTrg->SingleHpt();
374 uSLowpt+=gloTrg->PairUnlikeLpt();
375 uSHighpt+=gloTrg->PairUnlikeHpt();
376 lSLowpt+=gloTrg->PairLikeLpt();
377 lSHighpt+=gloTrg->PairLikeHpt();
379 // loop on local triggers
380 TIter next(triggerStore->CreateIterator());
381 AliMUONLocalTrigger* locTrg(0x0);
382 while ( ( locTrg = static_cast<AliMUONLocalTrigger*>(next()) ) )
387 if ( locTrg->LoSdev()==1 && locTrg->LoDev()==0 &&
388 locTrg->LoStripX()==0) xTrig=kFALSE; // no trigger in X
389 else xTrig=kTRUE; // trigger in X
390 if (locTrg->LoTrigY()==1 &&
391 locTrg->LoStripY()==15 ) yTrig = kFALSE; // no trigger in Y
392 else yTrig = kTRUE; // trigger in Y
395 { // fill ntuple if trigger in X and Y
396 tupleLoc.Fill(ievent,locTrg->LoCircuit(),
402 triggerCircuit.GetY11Pos(locTrg->LoCircuit(),locTrg->LoStripX()),
403 triggerCircuit.GetY21Pos(locTrg->LoCircuit(),locTrg->LoStripX()+locTrg->LoDev()+1),
404 triggerCircuit.GetX11Pos(locTrg->LoCircuit(),locTrg->LoStripY()));
406 tupleGlo.Fill(ievent,gloTrg->SingleLpt(),gloTrg->SingleHpt(),
407 gloTrg->PairUnlikeLpt(),gloTrg->PairUnlikeHpt(),
408 gloTrg->PairLikeLpt(),gloTrg->PairLikeHpt());
409 } // end of loop on local triggers
410 } // end of loop on events
412 // print info and store ntuples
414 printf("=============================================\n");
415 printf("================ SUMMARY ==================\n");
417 printf("Total number of events processed %d \n",nevents);
419 printf(" Global Trigger output Low pt High pt\n");
420 printf(" number of Single :\t");
421 printf("%i\t%i\t",sLowpt,sHighpt);
423 printf(" number of UnlikeSign pair :\t");
424 printf("%i\t%i\t",uSLowpt,uSHighpt);
426 printf(" number of LikeSign pair :\t");
427 printf("%i\t%i\t",lSLowpt,lSHighpt);
429 printf("=============================================\n");
432 TFile myFile(fileNameOut, "RECREATE");
438 //______________________________________________________________________________
440 AliMUONDataInterface::IsValid() const
442 /// Whether we were properly initialized from a valid galice.root file
446 //_____________________________________________________________________________
448 AliMUONDataInterface::LoadEvent(Int_t event)
450 /// Load event if different from the current one.
451 if ( event != fCurrentEvent )
453 fCurrentEvent = event;
454 AliDebug(1,Form("Loading event %d using runLoader %p",event,fLoader->GetRunLoader()));
455 if ( event < NumberOfEvents() )
457 return fLoader->GetRunLoader()->GetEvent(event);
467 //______________________________________________________________________________
469 AliMUONDataInterface::NumberOfEvents() const
471 /// Number of events in the current galice.root file we're attached to
472 if (!IsValid()) return 0;
473 return fLoader->GetRunLoader()->GetNumberOfEvents();
476 //_____________________________________________________________________________
478 AliMUONDataInterface::Open(const char* filename)
480 /// Connect to a given galice.root file
484 delete fTriggerStore;
486 delete fClusterStore;
490 delete fTriggerTrackStore;
491 fTriggerTrackStore=0x0;
497 delete fLoader->GetRunLoader();
504 TString foldername(Form("%s-%d",ClassName(),fgInstanceCounter));
506 while (AliRunLoader::GetRunLoader(foldername))
508 delete AliRunLoader::GetRunLoader(foldername);
511 AliRunLoader* runLoader = AliRunLoader::Open(filename,foldername);
514 AliError(Form("Cannot open file %s",filename));
517 fLoader = runLoader->GetDetectorLoader("MUON");
520 AliError("Cannot get AliMUONLoader");
526 AliError(Form("Could not access %s filename. Object is unuseable",filename));
530 //______________________________________________________________________________
532 AliMUONDataInterface::TrackStore(Int_t event)
534 /// Return the trackStore for a given event.
535 /// Return 0x0 if event not found.
536 /// Returned pointer should not be deleted
538 if ( LoadEvent(event) ) return 0x0;
540 fLoader->LoadTracks();
542 TTree* treeT = fLoader->TreeT();
546 AliError("Could not get treeT");
552 fTrackStore = AliMUONVTrackStore::Create(*treeT);
557 fTrackStore->Clear();
558 fTrackStore->Connect(*treeT);
562 fLoader->UnloadTracks();
567 //______________________________________________________________________________
568 AliMUONVTriggerTrackStore*
569 AliMUONDataInterface::TriggerTrackStore(Int_t event)
571 /// Return the triggerTrackStore for a given event.
572 /// Return 0x0 if event not found.
573 /// Returned pointer should not be deleted
575 if ( LoadEvent(event) ) return 0x0;
577 fLoader->LoadTracks();
579 TTree* treeT = fLoader->TreeT();
583 AliError("Could not get treeT");
587 if (!fTriggerTrackStore)
589 fTriggerTrackStore = AliMUONVTriggerTrackStore::Create(*treeT);
592 if ( fTriggerTrackStore )
594 fTriggerTrackStore->Clear();
595 fTriggerTrackStore->Connect(*treeT);
599 fLoader->UnloadTracks();
601 return fTriggerTrackStore;
604 //_____________________________________________________________________________
605 AliMUONVTriggerStore*
606 AliMUONDataInterface::TriggerStore(Int_t event, const char* treeLetter)
608 /// Return the triggerStore for a given event.
609 /// Return 0x0 if event not found.
610 /// Returned pointer should not be deleted
611 /// treeLetter can be R or D to tell from which tree to read the information
613 if ( LoadEvent(event) ) return 0x0;
617 TString stree(treeLetter);
622 fLoader->LoadDigits();
623 tree = fLoader->TreeD();
625 else if ( stree == "R" )
627 fLoader->LoadRecPoints();
628 tree = fLoader->TreeR();
633 AliError(Form("Could not get tree%s",treeLetter));
639 fTriggerStore = AliMUONVTriggerStore::Create(*tree);
644 fTriggerStore->Clear();
645 fTriggerStore->Connect(*tree);
651 fLoader->UnloadDigits();
653 else if ( stree == "R" )
655 fLoader->UnloadRecPoints();
658 return fTriggerStore;
661 //______________________________________________________________________________
662 //______________________________________________________________________________
663 //______________________________________________________________________________
664 //______________________________________________________________________________
666 void AliMUONDataInterface::Reset()
668 /// \deprecated Method is going to be removed
670 AliFatal("Deprecated");
673 Bool_t AliMUONDataInterface::UseCurrentRunLoader()
675 /// \deprecated Method is going to be removed
677 AliFatal("Deprecated");
681 Int_t AliMUONDataInterface::NumberOfEvents(TString , TString )
683 /// \deprecated Method is going to be removed
685 AliFatal("Deprecated");
690 Int_t AliMUONDataInterface::NumberOfParticles(TString , TString , Int_t )
692 /// \deprecated Method is going to be removed
694 AliFatal("Deprecated");
699 TParticle* AliMUONDataInterface::Particle(
700 TString , TString , Int_t , Int_t
703 /// \deprecated Method is going to be removed
705 AliFatal("Deprecated");
710 Int_t AliMUONDataInterface::NumberOfTracks(TString , TString , Int_t )
712 /// \deprecated Method is going to be removed
714 AliFatal("Deprecated");
719 Int_t AliMUONDataInterface::NumberOfHits(
720 TString , TString , Int_t , Int_t
723 /// \deprecated Method is going to be removed
725 AliFatal("Deprecated");
730 AliMUONHit* AliMUONDataInterface::Hit(
731 TString , TString , Int_t ,
735 /// \deprecated Method is going to be removed
737 AliFatal("Deprecated");
742 Int_t AliMUONDataInterface::NumberOfSDigits(
743 TString , TString , Int_t ,
747 /// \deprecated Method is going to be removed
749 AliFatal("Deprecated");
754 AliMUONDigit* AliMUONDataInterface::SDigit(
755 TString , TString , Int_t ,
756 Int_t , Int_t , Int_t
759 /// \deprecated Method is going to be removed
761 AliFatal("Deprecated");
766 Int_t AliMUONDataInterface::NumberOfDigits(
767 TString , TString , Int_t ,
771 /// \deprecated Method is going to be removed
773 AliFatal("Deprecated");
778 AliMUONDigit* AliMUONDataInterface::Digit(
779 TString , TString , Int_t ,
780 Int_t , Int_t , Int_t
783 /// \deprecated Method is going to be removed
785 AliFatal("Deprecated");
790 Int_t AliMUONDataInterface::NumberOfRawClusters(
791 TString , TString , Int_t , Int_t
794 /// \deprecated Method is going to be removed
796 AliFatal("Deprecated");
801 AliMUONRawCluster* AliMUONDataInterface::RawCluster(
802 TString , TString , Int_t ,
806 /// \deprecated Method is going to be removed
808 AliFatal("Deprecated");
813 Int_t AliMUONDataInterface::NumberOfLocalTriggers(TString , TString , Int_t )
815 /// \deprecated Method is going to be removed
817 AliFatal("Deprecated");
822 AliMUONLocalTrigger* AliMUONDataInterface::LocalTrigger(
823 TString , TString , Int_t , Int_t
826 /// \deprecated Method is going to be removed
828 AliFatal("Deprecated");
832 Bool_t AliMUONDataInterface::SetFile(TString , TString )
834 /// \deprecated Method is going to be removed
836 AliFatal("Deprecated");
841 Bool_t AliMUONDataInterface::GetEvent(Int_t )
843 /// \deprecated Method is going to be removed
845 AliFatal("Deprecated");
849 Int_t AliMUONDataInterface::NumberOfParticles()
851 /// \deprecated Method is going to be removed
853 AliFatal("Deprecated");
858 TParticle* AliMUONDataInterface::Particle(Int_t )
860 /// \deprecated Method is going to be removed
862 AliFatal("Deprecated");
867 Int_t AliMUONDataInterface::NumberOfTracks()
869 /// \deprecated Method is going to be removed
871 AliFatal("Deprecated");
876 Int_t AliMUONDataInterface::NumberOfHits(Int_t )
878 /// \deprecated Method is going to be removed
880 AliFatal("Deprecated");
886 AliMUONDataInterface::Hit(Int_t , Int_t )
888 /// \deprecated Method is going to be removed
890 AliFatal("Deprecated");
895 Int_t AliMUONDataInterface::NumberOfSDigits(Int_t , Int_t )
897 /// \deprecated Method is going to be removed
899 AliFatal("Deprecated");
904 AliMUONDigit* AliMUONDataInterface::SDigit(Int_t , Int_t , Int_t )
906 /// \deprecated Method is going to be removed
908 AliFatal("Deprecated");
914 Int_t AliMUONDataInterface::NumberOfDigits(Int_t , Int_t )
916 /// \deprecated Method is going to be removed
918 AliFatal("Deprecated");
924 AliMUONDigit* AliMUONDataInterface::Digit(Int_t , Int_t , Int_t )
926 /// \deprecated Method is going to be removed
928 AliFatal("Deprecated");
933 Int_t AliMUONDataInterface::NumberOfRawClusters(Int_t )
935 /// \deprecated Method is going to be removed
937 AliFatal("Deprecated");
942 AliMUONRawCluster* AliMUONDataInterface::RawCluster(Int_t , Int_t )
944 /// \deprecated Method is going to be removed
946 AliFatal("Deprecated");
951 Int_t AliMUONDataInterface::NumberOfLocalTriggers()
953 /// \deprecated Method is going to be removed
955 AliFatal("Deprecated");
960 AliMUONLocalTrigger* AliMUONDataInterface::LocalTrigger(Int_t )
962 /// \deprecated Method is going to be removed
964 AliFatal("Deprecated");
968 Int_t AliMUONDataInterface::NumberOfGlobalTriggers()
970 /// \deprecated Method is going to be removed
972 AliFatal("Deprecated");
976 AliMUONGlobalTrigger* AliMUONDataInterface::GlobalTrigger(Int_t )
978 /// \deprecated Method is going to be removed
980 AliFatal("Deprecated");
984 Int_t AliMUONDataInterface::NumberOfRecTracks()
986 /// \deprecated Method is going to be removed
988 AliFatal("Deprecated");
992 AliMUONTrack* AliMUONDataInterface::RecTrack(Int_t )
994 /// \deprecated Method is going to be removed
996 AliFatal("Deprecated");