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 /// \class AliMUONData
20 /// Class containing MUON data: hits, digits, rawclusters, globaltrigger, localtrigger, etc ..
21 /// The classe makes the lik between the MUON data lists and the event trees from loaders
23 /// \author Gines Martinez, Subatech, September 2003
26 #include "AliMUONData.h"
27 #include "AliMUONDataIterator.h"
28 #include "AliMUONConstants.h"
29 #include "AliMUONDigit.h"
30 #include "AliMUONGlobalTrigger.h"
31 #include "AliMUONLocalTrigger.h"
32 #include "AliMUONRegionalTrigger.h"
33 #include "AliMUONTriggerCrateStore.h"
34 #include "AliMUONTriggerCircuit.h"
35 #include "AliMUONGeometryTransformer.h"
36 #include "AliMUONRawCluster.h"
38 #include "AliRunLoader.h"
43 #include <TParticle.h>
45 #include <Riostream.h>
52 //_____________________________________________________________________________
53 AliMUONData::AliMUONData():
61 fRegionalTrigger(0x0),
70 /// Default constructor
72 //_____________________________________________________________________________
73 AliMUONData::AliMUONData(AliLoader * loader, const char* name, const char* title):
81 fRegionalTrigger(0x0),
90 /// Standard constructor
93 //_____________________________________________________________________________
94 AliMUONData::AliMUONData(const char* galiceFile, const char* folderName):
95 TNamed("MUON", "MUON"),
102 fRegionalTrigger(0x0),
107 fNregionaltrigger(0),
111 /// Constructor for loading data from gAlice file
113 fRunLoader = AliRunLoader::Open(galiceFile, folderName, "READ");
115 AliError(Form("Error opening %s file \n", galiceFile));
119 fLoader = fRunLoader->GetLoader("MUONLoader");
121 AliError(Form("Could get MUONLoader"));
126 //_____________________________________________________________________________
127 AliMUONData::~AliMUONData()
129 /// Destructor for AliMUONData
141 fGlobalTrigger->Delete();
142 delete fGlobalTrigger;
144 if (fRegionalTrigger){
145 fRegionalTrigger->Delete();
146 delete fRegionalTrigger;
149 fLocalTrigger->Delete();
150 delete fLocalTrigger;
154 fRunLoader->UnloadAll();
158 //_____________________________________________________________________________
159 void AliMUONData::AddSDigit(Int_t id, const AliMUONDigit& Sdigit)
161 /// Add a MUON Sdigit to the list of SDigits of the detection plane id
163 TClonesArray &lSdigits = * SDigits(id) ;
164 new(lSdigits[fNSdigits[id]++]) AliMUONDigit(Sdigit);
166 //_____________________________________________________________________________
167 void AliMUONData::AddDigit(Int_t id, const AliMUONDigit& digit)
169 /// Add a MUON digit to the list of Digits of the detection plane id
171 TClonesArray &ldigits = * Digits(id) ;
172 new(ldigits[fNdigits[id]++]) AliMUONDigit(digit);
175 //_____________________________________________________________________________
176 void AliMUONData::AddGlobalTrigger(const AliMUONGlobalTrigger& trigger )
178 /// Add a MUON Global Trigger to the list (only one GlobalTrigger per event !);
180 TClonesArray &globalTrigger = *fGlobalTrigger;
181 new(globalTrigger[fNglobaltrigger++]) AliMUONGlobalTrigger(trigger);
184 //____________________________________________________________________________
185 void AliMUONData::AddRegionalTrigger(const AliMUONRegionalTrigger& trigger)
187 /// add a MUON regional Trigger to the list
188 TClonesArray ®ionalTrigger = *fRegionalTrigger;
189 new(regionalTrigger[fNregionaltrigger++]) AliMUONRegionalTrigger(trigger);
191 //____________________________________________________________________________
192 void AliMUONData::AddLocalTrigger(const AliMUONLocalTrigger& trigger)
194 /// add a MUON Local Trigger to the list
196 TClonesArray &localTrigger = *fLocalTrigger;
197 new(localTrigger[fNlocaltrigger++]) AliMUONLocalTrigger(trigger);
200 //____________________________________________________________________________
201 TClonesArray* AliMUONData::SDigits(Int_t DetectionPlane) const
203 /// Getting List of SDigits
206 return ( (TClonesArray*) fSDigits->At(DetectionPlane) );
210 //____________________________________________________________________________
211 TClonesArray* AliMUONData::Digits(Int_t DetectionPlane) const
213 /// Getting List of Digits
216 return ( (TClonesArray*) fDigits->At(DetectionPlane) );
220 //____________________________________________________________________________
221 Bool_t AliMUONData::IsDigitsBranchesInTree()
223 /// Checking if there are Digits Branches In TreeD
226 AliError("No treeD in memory");
231 sprintf(branchname,"%sDigits1",GetName());
232 TBranch * branch = 0x0;
233 branch = TreeD()->GetBranch(branchname);
234 if (branch) return kTRUE;
238 //____________________________________________________________________________
239 Bool_t AliMUONData::IsTriggerBranchesInTreeD()
241 /// Checking if there are Trigger Branches In TreeD
243 AliError("No treeD in memory");
248 sprintf(branchname,"%sLocalTrigger",GetName());
249 TBranch * branch = 0x0;
250 branch = TreeD()->GetBranch(branchname);
251 if (branch) return kTRUE;
256 //____________________________________________________________________________
257 void AliMUONData::Fill(Option_t* option)
259 /// Method to fill the trees
261 const char *cS = strstr(option,"S"); // SDigits branches in TreeS
262 const char *cD = strstr(option,"D"); // Digits branches in TreeD
263 const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeD
266 TBranch * branch = 0x0;
276 if ( TreeD() && cD && cGLT )
278 // Writing digits and (global+local) trigger at once.
285 if ( IsTriggerBranchesInTreeD() )
287 for (int i=0; i<AliMUONConstants::NCh(); i++)
289 sprintf(branchname,"%sDigits%d",GetName(),i+1);
290 branch = TreeD()->GetBranch(branchname);
300 if ( TreeD() && cGLT )
302 if ( IsDigitsBranchesInTree() )
304 sprintf(branchname,"%sLocalTrigger",GetName());
305 branch = TreeD()->GetBranch(branchname);
307 sprintf(branchname,"%sRegionalTrigger",GetName());
308 branch = TreeD()->GetBranch(branchname);
310 sprintf(branchname,"%sGlobalTrigger",GetName());
311 branch = TreeD()->GetBranch(branchname);
320 } // end of TreeD() handling.
323 //_____________________________________________________________________________
324 void AliMUONData::MakeBranch(Option_t* option)
326 /// Create Tree branches for the MUON.
328 const Int_t kBufferSize = 4000;
331 //Setting Data Container
332 SetDataContainer(option);
334 const char *cS = strstr(option,"S"); // Digits branches in TreeS
335 const char *cD = strstr(option,"D"); // Digits branches in TreeD
336 const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeD
338 TBranch * branch = 0x0;
340 //Creating Branches for SDigits
341 if (TreeS() && cS ) {
342 // one branch for Sdigits per chamber
343 for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
344 sprintf(branchname,"%sSDigits%d",GetName(),iDetectionPlane+1);
346 branch = TreeS()->GetBranch(branchname);
348 AliInfo(Form("Branch %s is already in tree.",branchname));
351 TClonesArray * sdigits = SDigits(iDetectionPlane);
352 branch = TreeS()->Branch(branchname, &sdigits, kBufferSize,1);
353 //Info("MakeBranch","Making Branch %s for sdigits in detection plane %d\n",branchname,iDetectionPlane+1);
357 //Creating Branches for Digits
366 // one branch for digits per chamber
367 for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++)
369 sprintf(branchname,"%sDigits%d",GetName(),iDetectionPlane+1);
370 branch = treeD->GetBranch(branchname);
373 AliInfo(Form("Branch %s is already in tree.",branchname));
376 TClonesArray * digits = Digits(iDetectionPlane);
377 branch = treeD->Branch(branchname, &digits, kBufferSize,1);
384 // one branch for global trigger
386 sprintf(branchname,"%sGlobalTrigger",GetName());
387 branch = treeD->GetBranch(branchname);
390 AliInfo(Form("Branch GlobalTrigger is already in treeD."));
393 branch = treeD->Branch(branchname, &fGlobalTrigger, kBufferSize);
396 // one branch for regional trigger
398 sprintf(branchname,"%sRegionalTrigger",GetName());
400 branch = treeD->GetBranch(branchname);
403 AliInfo(Form("Branch RegionalTrigger is already in treeD."));
406 branch = treeD->Branch(branchname, &fRegionalTrigger, kBufferSize);
410 // one branch for local trigger
412 sprintf(branchname,"%sLocalTrigger",GetName());
414 branch = treeD->GetBranch(branchname);
417 AliInfo(Form("Branch LocalTrigger is already in treeD."));
420 branch = treeD->Branch(branchname, &fLocalTrigger, kBufferSize);
424 //____________________________________________________________________________
426 AliMUONData::LocalTrigger() const
428 /// Getting local trigger
430 return fLocalTrigger;
433 //____________________________________________________________________________
435 AliMUONData::RegionalTrigger() const
437 /// Getting regional trigger
439 return fRegionalTrigger;
442 //____________________________________________________________________________
444 AliMUONData::GetDigits() const
446 /// Load the digits from TreeD for the current event.
448 Int_t event = fLoader->GetRunLoader()->GetEventNumber();
449 if ( fCurrentEvent != event )
451 if (fLoader->TreeD()) {
452 fLoader->TreeD()->GetEvent(0);
453 fCurrentEvent = event;
458 //____________________________________________________________________________
460 AliMUONData::GlobalTrigger() const
462 /// Return the global trigger
464 return fGlobalTrigger;
467 //____________________________________________________________________________
468 void AliMUONData::ResetSDigits()
470 /// Reset number of Sdigits and the Sdigits array for this detector
472 if (fSDigits == 0x0) return;
473 for ( int i=0;i<AliMUONConstants::NCh();i++ ) {
474 if ((*fSDigits)[i]) ((TClonesArray*)fSDigits->At(i))->Clear();
475 if (fNSdigits) fNSdigits[i]=0;
478 //____________________________________________________________________________
479 void AliMUONData::ResetDigits()
481 /// Reset number of digits and the digits array for this detector
483 if (fDigits == 0x0) return;
484 for ( int i=0;i<AliMUONConstants::NCh();i++ ) {
485 if ((*fDigits)[i]) ((TClonesArray*)fDigits->At(i))->Clear("C");
486 if (fNdigits) fNdigits[i]=0;
489 //_______________________________________________________________________________
490 void AliMUONData::ResetTrigger()
492 /// Reset Local and Global Trigger
495 if (fGlobalTrigger) fGlobalTrigger->Clear();
496 fNregionaltrigger = 0;
497 if (fRegionalTrigger) fRegionalTrigger->Clear();
499 if (fLocalTrigger) fLocalTrigger->Clear();
502 //____________________________________________________________________________
503 void AliMUONData::SetDataContainer(Option_t* option)
505 /// Setting data containers of muon data
507 const char *cS = strstr(option,"S"); // SDigits
508 const char *cD = strstr(option,"D"); // Digits
509 const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger
511 AliDebug(1,Form("option=%s",option));
514 // Container for Sdigits
516 if (fSDigits == 0x0) {
517 AliDebug(1,"Creating fSDigits TObjArray");
518 fSDigits = new TObjArray(AliMUONConstants::NCh());
519 fNSdigits= new Int_t[AliMUONConstants::NCh()];
520 for (Int_t i=0; i<AliMUONConstants::NCh() ;i++) {
521 TClonesArray* a = new TClonesArray("AliMUONDigit",10000);
523 fSDigits->AddAt(a,i);
524 AliDebug(1,Form("fSDigits[%d]=%p",i,a));
529 AliDebug(1,Form("fSDigits already there = %p",fSDigits));
535 // ObjArray of ClonesArrays for Digits
537 if (fDigits == 0x0 ) {
538 fDigits = new TObjArray(AliMUONConstants::NCh());
539 fNdigits= new Int_t[AliMUONConstants::NCh()];
540 for (Int_t i=0; i<AliMUONConstants::NCh() ;i++) {
541 TClonesArray * tca = new TClonesArray("AliMUONDigit",10000);
543 fDigits->AddAt(tca,i);
548 AliDebug(1,Form("fDigits already there = %p",fDigits));
554 // ClonesArrays for Trigger
556 if (fLocalTrigger == 0x0) {
557 fLocalTrigger = new TClonesArray("AliMUONLocalTrigger",234);
559 if (fRegionalTrigger == 0x0) {
560 fRegionalTrigger = new TClonesArray("AliMUONRegionalTrigger",16);
562 if (fGlobalTrigger== 0x0) {
563 fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1);
569 //____________________________________________________________________________
570 void AliMUONData::SetTreeAddress(Option_t* option)
572 // Setting Data containers
573 SetDataContainer(option);
575 /// Setting Addresses to the events trees
577 const char *cS = strstr(option,"S"); // SDigits branches in TreeS
578 const char *cD = strstr(option,"D"); // Digits branches in TreeD
579 const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeD
581 // Set branch address for the Hits, Digits, RawClusters, GlobalTrigger and LocalTrigger Tree.
583 TBranch * branch = 0x0;
585 AliDebug(1,Form("option=%s",option));
588 // Branch address for Sdigit tree
589 if (TreeS() && fSDigits && cS) {
590 AliDebug(1,"Setting branch addresses");
591 for (int i=0; i<AliMUONConstants::NCh(); i++) {
592 sprintf(branchname,"%sSDigits%d",GetName(),i+1);
594 AliDebug(1,Form("TreeS=%p for ich=%d branchname=%s",
595 TreeS(),i,branchname));
596 branch = TreeS()->GetBranch(branchname);
597 TClonesArray * sdigits = SDigits(i);
598 if (branch) branch->SetAddress( &sdigits );
599 else AliWarning(Form("(%s) Failed for SDigits Detection plane %d. Can not find branch in tree.",GetName(),i));
605 // Branch address for digit tree
606 if (TreeD() && fDigits && cD) {
607 for (int i=0; i<AliMUONConstants::NCh(); i++) {
608 sprintf(branchname,"%sDigits%d",GetName(),i+1);
610 branch = TreeD()->GetBranch(branchname);
611 TClonesArray * digits = Digits(i);
613 branch->SetAddress( &digits );
615 else AliWarning(Form("(%s) Failed for Digits Detection plane %d. Can not find branch in tree.",GetName(),i));
619 if ( TreeD() && fLocalTrigger && cGLT) {
620 sprintf(branchname,"%sLocalTrigger",GetName());
621 branch = TreeD()->GetBranch(branchname);
622 if (branch) branch->SetAddress(&fLocalTrigger);
623 else AliWarning(Form("(%s) Failed for LocalTrigger. Can not find branch in treeD.",GetName()));
625 if ( TreeD() && fRegionalTrigger && cGLT) {
626 sprintf(branchname,"%sRegionalTrigger",GetName());
627 branch = TreeD()->GetBranch(branchname);
628 if (branch) branch->SetAddress(&fRegionalTrigger);
629 else AliWarning(Form("(%s) Failed for RegionalTrigger. Can not find branch in treeD.",GetName()));
631 if ( TreeD() && fGlobalTrigger && cGLT) {
632 sprintf(branchname,"%sGlobalTrigger",GetName());
633 branch = TreeD()->GetBranch(branchname);
634 if (branch) branch->SetAddress(&fGlobalTrigger);
635 else AliWarning(Form("(%s) Failed for GlobalTrigger. Can not find branch in treeD.",GetName()));
639 //_____________________________________________________________________________
641 AliMUONData::Print(Option_t* opt) const
643 /// Dump object on screen
645 TString options(opt);
648 if ( options.Contains("D") )
650 for ( Int_t ich = 0; ich < AliMUONConstants::NCh(); ++ich)
652 TClonesArray* digits = Digits(ich);
653 Int_t ndigits = digits->GetEntriesFast();
654 for ( Int_t id = 0; id < ndigits; ++id )
656 AliMUONDigit* digit =
657 static_cast<AliMUONDigit*>(digits->UncheckedAt(id));
663 if ( options.Contains("S") )
665 for ( Int_t ich = 0; ich < AliMUONConstants::NCh(); ++ich)
667 TClonesArray* digits = SDigits(ich);
668 Int_t ndigits = digits->GetEntriesFast();
669 for ( Int_t id = 0; id < ndigits; ++id )
671 AliMUONDigit* digit =
672 static_cast<AliMUONDigit*>(digits->UncheckedAt(id));
679 //_____________________________________________________________________________
681 AliMUONData::DumpSDigits(Int_t event2Check, Option_t* opt)
685 fLoader->LoadSDigits("READ");
688 Int_t nevents = fRunLoader->GetNumberOfEvents();
689 for (Int_t ievent=0; ievent<nevents; ievent++) {
690 if (event2Check!=0) ievent=event2Check;
691 printf(">>> Event %d \n",ievent);
693 // Getting event ievent
694 fRunLoader->GetEvent(ievent);
699 Int_t nchambers = AliMUONConstants::NCh(); ;
700 for (Int_t ichamber=0; ichamber<nchambers; ichamber++) {
701 TClonesArray* digits = SDigits(ichamber);
704 Int_t ndigits = (Int_t)digits->GetEntriesFast();
705 for (Int_t idigit=0; idigit<ndigits; idigit++) {
706 AliMUONDigit* mDigit = static_cast<AliMUONDigit*>(digits->At(idigit));
711 if (event2Check!=0) ievent=nevents;
713 fLoader->UnloadSDigits();
715 //_____________________________________________________________________________
717 AliMUONData::DumpDigits(Int_t event2Check, Option_t* opt)
721 fLoader->LoadDigits("READ");
724 Int_t firstEvent = 0;
725 Int_t lastEvent = fRunLoader->GetNumberOfEvents()-1;
726 if ( event2Check != 0 ) {
727 firstEvent = event2Check;
728 lastEvent = event2Check;
731 for ( Int_t ievent = firstEvent; ievent <= lastEvent; ++ievent ) {
732 printf(">>> Event %d \n",ievent);
733 fRunLoader->GetEvent(ievent);
735 AliMUONDataIterator it(this, "digit", AliMUONDataIterator::kTrackingChambers);
738 while ( ( digit = (AliMUONDigit*)it.Next() ) )
743 fLoader->UnloadDigits();