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 **************************************************************************/
17 //-----------------------------------------------------------------------------
18 /// \class AliMUONReconstructor
20 /// Implementation of AliReconstructor for MUON subsystem.
22 /// The clustering mode and the associated parameters can be changed through the
23 /// AliMUONRecoParam object set in the reconstruction macro or read from the CDB
24 /// (see methods in AliMUONRecoParam.h file for details)
28 /// SIMPLEFIT : use the AliMUONClusterFinderSimpleFit clusterizer
30 /// SIMPLEFITV3 : SIMPLEFIT with preclustering=PRECLUSTERV3
32 /// MLEM : use AliMUONClusterFinderMLEM and AliMUONPreClusterFinder for preclustering (default)
33 /// MLEMV2 : MLEM with preclustering=PRECLUSTERV2
34 /// MLEMV3 : MLEM with preclustering=PRECLUSTERV3
36 /// PRECLUSTER : use only AliMUONPreClusterFinder. Only for debug as
37 /// the produced clusters do not have a position, hence the tracking will not
39 /// PRECLUSTERV2 : another version of the preclustering
40 /// PRECLUSTERV3 : yet another version of the preclustering
42 /// COG : use AliMUONClusterFinderCOG clusterizer. Not really a production
43 /// option either, as center-of-gravity is generally not a good estimate
44 /// of the cluster position...
46 /// PEAKCOG : COG cluster finder around local maxima
47 /// PEAKFIT : fit around local maxima with up to 3 peaks, COG otherwise
49 /// NOCLUSTERING : bypass completely the clustering stage
53 /// The behavior of the MUON reconstruction can also be changed, besides
54 /// the usual methods found in AliReconstruction (e.g. to disable tracking)
55 /// by using AliReconstruction::SetOption("MUON",options)
56 /// where options should be a space separated string.
58 /// Valid options are :
60 /// SAVEDIGITS : if you want to save in the TreeD the *calibrated* digits
61 /// that are used for the clustering
63 /// DIGITSTOREV1 : use the V1 implementation of the digitstore
64 /// DIGITSTOREV2R : use the V2R implementation of the digitstore
66 /// NOLOCALRECONSTRUCTION : for debug, to disable local reconstruction (and hence
67 /// "recover" old behavior)
69 /// TRIGGERDISABLE : disable the treatment of MUON trigger
71 /// ENABLEERRORLOGGING : enable error logging (this activates also warnings in RawStreamTracker)
73 /// \author Laurent Aphecetche, Subatech
74 //-----------------------------------------------------------------------------
76 #include "AliMUONReconstructor.h"
78 #include "AliMUONCalibrationData.h"
79 #include "AliMUONClusterFinderCOG.h"
80 #include "AliMUONClusterFinderMLEM.h"
81 #include "AliMUONClusterFinderSimpleFit.h"
82 #include "AliMUONClusterFinderPeakCOG.h"
83 #include "AliMUONClusterFinderPeakFit.h"
84 #include "AliMUONClusterStoreV1.h"
85 #include "AliMUONClusterStoreV2.h"
86 #include "AliMUONConstants.h"
87 #include "AliMUONDigitCalibrator.h"
88 #include "AliMUONDigitMaker.h"
89 #include "AliMUONDigitStoreV1.h"
90 #include "AliMUONDigitStoreV2R.h"
91 #include "AliMUONGeometryTransformer.h"
92 #include "AliMUONPadStatusMaker.h"
93 #include "AliMUONPreClusterFinder.h"
94 #include "AliMUONPreClusterFinderV2.h"
95 #include "AliMUONPreClusterFinderV3.h"
96 #include "AliMUONSimpleClusterServer.h"
97 #include "AliMUONTracker.h"
98 #include "AliMUONTriggerCircuit.h"
99 #include "AliMUONTriggerStoreV1.h"
100 #include "AliMUONVClusterFinder.h"
101 #include "AliMUONVClusterServer.h"
102 #include "AliMUONVTrackStore.h"
103 #include "AliMUONTriggerElectronics.h"
104 #include "AliMUONTriggerUtilities.h"
106 #include "AliMpArea.h"
107 #include "AliMpCDB.h"
108 #include "AliMpConstants.h"
109 #include "AliMpDDLStore.h"
110 #include "AliMpSegmentation.h"
112 #include "AliRawReader.h"
113 #include "AliCDBManager.h"
114 #include "AliCodeTimer.h"
116 #include "AliRunInfo.h"
118 #include <Riostream.h>
119 #include <TObjArray.h>
120 #include <TClonesArray.h>
125 ClassImp(AliMUONReconstructor)
128 //_____________________________________________________________________________
129 AliMUONReconstructor::AliMUONReconstructor() :
132 fTransformer(new AliMUONGeometryTransformer()),
134 fTriggerCircuit(0x0),
135 fCalibrationData(0x0),
136 fDigitCalibrator(0x0),
140 fTriggerProcessor(0x0),
141 fTriggerUtilities(0x0),
149 // Unload mapping objects
150 // if they have been loaded from the obsolete OCDB mapping objects
152 if ( AliMpDDLStore::Instance(false) ) {
153 AliCDBManager::Instance()->UnloadFromCache("MUON/Calib/DDLStore");
154 delete AliMpDDLStore::Instance();
157 if ( AliMpSegmentation::Instance(false) ) {
158 AliCDBManager::Instance()->UnloadFromCache("MUON/Calib/Mapping");
159 delete AliMpSegmentation::Instance();
163 if ( ! AliMpCDB::LoadDDLStore() ) {
164 AliFatal("Could not access mapping from OCDB !");
167 // Load geometry data
168 fTransformer->LoadGeometryData();
170 fClusterServers.SetOwner(kTRUE);
171 fTrackers.SetOwner(kTRUE);
174 //_____________________________________________________________________________
175 AliMUONReconstructor::~AliMUONReconstructor()
181 delete fDigitCalibrator;
186 delete fTriggerCircuit;
187 delete fTriggerStore;
189 delete fClusterStore;
190 delete fTriggerProcessor;
191 delete fTriggerUtilities;
193 delete AliMpSegmentation::Instance(false);
194 delete AliMpDDLStore::Instance(false);
196 delete fCalibrationData;
199 //_____________________________________________________________________________
201 AliMUONReconstructor::Calibrate(AliMUONVDigitStore& digitStore) const
203 /// Calibrate the digitStore
204 if (!fDigitCalibrator)
208 AliCodeTimerAuto(Form("%s::Calibrate(AliMUONVDigitStore*)",fDigitCalibrator->ClassName()),0)
209 fDigitCalibrator->Calibrate(digitStore);
212 //_____________________________________________________________________________
214 AliMUONReconstructor::ConvertDigits(AliRawReader* rawReader,
215 AliMUONVDigitStore* digitStore,
216 AliMUONVTriggerStore* triggerStore) const
218 /// Convert raw data into digit and trigger stores
221 // Skip reconstruction if event is Calibration
222 if ( GetRecoParam()->GetEventSpecie() == AliRecoParam::kCalib ) {
223 digitStore->Clear(); // Remove possible digits from previous event
224 triggerStore->Clear(); // Remove possible triggers from previous event
225 AliInfo("Calibration event: do not convert digits");
229 AliCodeTimerStart(Form("%s::Raw2Digits(AliRawReader*,AliMUONVDigitStore*,AliMUONVTriggerStore*)",
230 fDigitMaker->ClassName()))
231 fDigitMaker->Raw2Digits(rawReader,digitStore,triggerStore);
232 AliCodeTimerStop(Form("%s::Raw2Digits(AliRawReader*,AliMUONVDigitStore*,AliMUONVTriggerStore*)",
233 fDigitMaker->ClassName()))
234 Calibrate(*digitStore);
237 //_____________________________________________________________________________
239 AliMUONReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
241 /// convert raw data into a digit tree
242 AliCodeTimerAuto("",0)
244 Bool_t alone = ( TriggerStore() == 0 );
246 Bool_t ok = DigitStore()->Connect(*digitsTree,alone);
247 if ( TriggerStore() )
249 ok = ok && TriggerStore()->Connect(*digitsTree,kFALSE);
254 AliError("Could not make branches on TreeD");
258 ConvertDigits(rawReader,DigitStore(),TriggerStore());
259 AliCodeTimerStart("Fill digits")
261 AliCodeTimerStop("Fill digits")
262 DigitStore()->Clear();
266 //_____________________________________________________________________________
268 AliMUONReconstructor::CreateDigitMaker() const
270 /// Create (and create if necessary) the digit maker
271 if (fDigitMaker) return;
273 AliCodeTimerAuto("",0)
275 TString option = GetOption();
277 Bool_t enableErrorLogging = kFALSE;
279 if (option.Contains("ENABLEERRORLOGGING"))
281 enableErrorLogging = kTRUE;
284 fDigitMaker = new AliMUONDigitMaker(enableErrorLogging);
287 // Always make trigger digits
288 // (needed when calculating trigger chamber efficiency)
289 fDigitMaker->SetMakeTriggerDigits(kTRUE);
291 if ( GetRecoParam()->TryRecover() )
293 fDigitMaker->SetTryRecover(kTRUE);
297 fDigitMaker->SetTryRecover(kFALSE);
301 //_____________________________________________________________________________
303 AliMUONReconstructor::CreateTriggerCircuit() const
305 /// Return (and create if necessary) the trigger circuit object
306 if (fTriggerCircuit) return;
308 AliCodeTimerAuto("",0)
310 fTriggerCircuit = new AliMUONTriggerCircuit(fTransformer);
314 //_____________________________________________________________________________
316 AliMUONReconstructor::CreateTriggerUtilities() const
318 /// Return (and create if necessary) the trigger utilities object
319 if ( fTriggerUtilities ) return;
321 AliCodeTimerAuto("",0)
323 if ( ! fCalibrationData ) CreateCalibrationData();
325 fTriggerUtilities = new AliMUONTriggerUtilities(fCalibrationData);
328 //_____________________________________________________________________________
330 AliMUONReconstructor::CreateTracker() const
332 /// Create the MUONTracker object
334 CreateTriggerCircuit();
335 CreateTriggerUtilities();
337 const AliMUONRecoParam* rp = GetRecoParam();
339 Int_t es = rp->GetEventSpecie();
341 AliTracker* tracker = static_cast<AliTracker*>(fTrackers.At(es));
345 if ( ! rp->CombineClusterTrackReco() )
347 tracker = new AliMUONTracker(rp,
354 AliInfo(Form("Created tracker %p for recoparam of type %s es=%d",
356 AliRecoParam::GetEventSpecieName(AliRecoParam::Convert(rp->GetEventSpecie())),es));
361 tracker = new AliMUONTracker(rp,
362 CreateClusterServer(*rp),
368 AliInfo(Form("Created (combined) tracker %p for recoparam of type %s es=%d",
370 AliRecoParam::GetEventSpecieName(AliRecoParam::Convert(rp->GetEventSpecie())),es));
373 fTrackers.AddAtAndExpand(tracker,es);
380 //_____________________________________________________________________________
381 AliMUONVClusterFinder*
382 AliMUONReconstructor::CreateClusterFinder(const char* clusterFinderType)
384 /// Create a given cluster finder instance
386 AliCodeTimerAutoGeneral("",0)
388 AliMUONVClusterFinder* clusterFinder(0x0);
390 TString opt(clusterFinderType);
393 if ( strstr(opt,"PRECLUSTERV2") )
395 clusterFinder = new AliMUONPreClusterFinderV2;
397 else if ( strstr(opt,"PRECLUSTERV3") )
399 clusterFinder = new AliMUONPreClusterFinderV3;
401 else if ( strstr(opt,"PRECLUSTER") )
403 clusterFinder = new AliMUONPreClusterFinder;
405 else if ( strstr(opt,"PEAKCOG") )
407 clusterFinder = new AliMUONClusterFinderPeakCOG(kFALSE,new AliMUONPreClusterFinder);
409 else if ( strstr(opt,"PEAKFIT") )
411 clusterFinder = new AliMUONClusterFinderPeakFit(kFALSE,new AliMUONPreClusterFinder);
413 else if ( strstr(opt,"COG") )
415 clusterFinder = new AliMUONClusterFinderCOG(new AliMUONPreClusterFinder);
417 else if ( strstr(opt,"SIMPLEFITV3") )
419 clusterFinder = new AliMUONClusterFinderSimpleFit(new AliMUONClusterFinderCOG(new AliMUONPreClusterFinderV3));
421 else if ( strstr(opt,"SIMPLEFIT") )
423 clusterFinder = new AliMUONClusterFinderSimpleFit(new AliMUONClusterFinderCOG(new AliMUONPreClusterFinder));
425 else if ( strstr(opt,"MLEM:DRAW") )
427 clusterFinder = new AliMUONClusterFinderMLEM(kTRUE,new AliMUONPreClusterFinder);
429 else if ( strstr(opt,"MLEMV3") )
431 clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinderV3);
433 else if ( strstr(opt,"MLEMV2") )
435 clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinderV2);
437 else if ( strstr(opt,"MLEM") )
439 clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinder);
443 AliErrorClass(Form("clustering mode \"%s\" does not exist",opt.Data()));
447 return clusterFinder;
450 //_____________________________________________________________________________
451 AliMUONVClusterServer*
452 AliMUONReconstructor::CreateClusterServer(const AliMUONRecoParam& rp) const
454 /// Create cluster server
456 AliCodeTimerAuto("",0);
458 AliMUONVClusterServer* clusterServer = static_cast<AliMUONVClusterServer*>(fClusterServers.At(rp.GetEventSpecie()));
462 AliMUONVClusterFinder* clusterFinder = CreateClusterFinder(rp.GetClusteringMode());
464 if ( !clusterFinder ) return 0x0;
466 clusterServer = new AliMUONSimpleClusterServer(clusterFinder,*fTransformer);
468 AliInfo(Form("Created AliMUONSimpleClusterServer (%p) for specie %d with clustering = %s (following requesting clustering mode %s)",
469 clusterServer,rp.GetEventSpecie(),clusterFinder->ClassName(),rp.GetClusteringMode()));
471 fClusterServers.AddAtAndExpand(clusterServer,rp.GetEventSpecie());
474 return clusterServer;
477 //_____________________________________________________________________________
479 AliMUONReconstructor::CreateCalibrationData() const
481 /// Create the calibrator
483 AliCodeTimerAuto("",0);
485 Int_t runNumber = AliCDBManager::Instance()->GetRun();
487 fCalibrationData = new AliMUONCalibrationData(runNumber);
488 if ( !fCalibrationData->IsValid() )
490 AliError("Could not retrieve calibrations !");
491 delete fCalibrationData;
492 fCalibrationData = 0x0;
496 // It is now time to check whether we have everything to proceed.
497 // What we need depends on whether both tracker and trigger
498 // are in the readout chain, and what specific "bad channel policy"
501 Bool_t kTracker(kFALSE);
502 Bool_t kTrigger(kFALSE);
504 const AliRunInfo* runInfo = GetRunInfo();
507 AliError("Could not get runinfo ?");
511 TString detectors(runInfo->GetActiveDetectors());
512 if (detectors.Contains("MUONTRK")) kTracker=kTRUE;
513 if (detectors.Contains("MUONTRG")) kTrigger=kTRUE;
516 AliInfo(Form("Run with MUON TRIGGER : %s and MUON TRACKER : %s",
517 kTrigger ? "YES":"NO" ,
518 kTracker ? "YES":"NO"));
522 // Check that we get all the calibrations we'll need
523 if ( !fCalibrationData->Pedestals() ||
524 !fCalibrationData->Gains() )
526 AliFatal(Form("Could not access all required calibration data (PED %p GAIN %p)",
527 fCalibrationData->Pedestals(),fCalibrationData->Gains()));
530 if ( !fCalibrationData->HV() )
532 // Special treatment of HV. We only break if the values
533 // are not there *AND* we cut on them.
534 UInt_t mask = GetRecoParam()->PadGoodnessMask();
535 TString smask(AliMUONPadStatusMaker::AsCondition(mask));
536 if ( smask.Contains("HV") )
538 AliFatal("Could not access all required calibration data (HV)");
544 //_____________________________________________________________________________
546 AliMUONReconstructor::CreateCalibrator() const
548 /// Create the calibrator
550 AliCodeTimerAuto("",0);
552 if ( ! fCalibrationData )
553 CreateCalibrationData();
555 AliInfo("Calibration will occur.");
557 TString opt(GetOption());
560 if ( strstr(opt,"NOSTATUSMAP") )
562 AliWarning("NOSTATUSMAP is obsolete");
565 fDigitCalibrator = new AliMUONDigitCalibrator(*fCalibrationData,GetRecoParam());
568 //_____________________________________________________________________________
570 AliMUONReconstructor::ResponseRemovingChambers(AliMUONVTriggerStore* triggerStore) const
572 /// Update trigger information with informatins obtained after
573 /// re-calculation of trigger response
574 AliCodeTimerAuto("",0);
576 if ( ! fCalibrationData )
577 CreateCalibrationData();
579 if ( ! fTriggerProcessor )
580 fTriggerProcessor = new AliMUONTriggerElectronics(fCalibrationData);
582 fTriggerProcessor->ResponseRemovingChambers(*triggerStore);
585 //_____________________________________________________________________________
587 AliMUONReconstructor::DigitStore() const
589 /// Return (and create if necessary) the digit container
592 TString sopt(GetOption());
595 AliInfo(Form("Options=%s",sopt.Data()));
597 if ( sopt.Contains("DIGITSTOREV1") )
599 fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV1");
601 else if ( sopt.Contains("DIGITSTOREV2R") )
603 fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2R");
605 else if ( sopt.Contains("DIGITSTOREV2S") )
607 fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2S");
610 if (!fDigitStore) fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2R");
612 AliInfo(Form("Will use %s to store digits during reconstruction",fDigitStore->ClassName()));
617 //_____________________________________________________________________________
619 AliMUONReconstructor::FillTreeR(AliMUONVTriggerStore* triggerStore,
620 TTree& clustersTree) const
622 /// Write the trigger and cluster information into TreeR
624 AliCodeTimerAuto("",0)
627 Bool_t alone(kTRUE); // is trigger the only info in TreeR ?
629 const AliMUONRecoParam* rp = GetRecoParam();
631 if ( ! rp->CombineClusterTrackReco() )
633 alone = kFALSE; // we'll get both tracker and trigger information in TreeR
638 ResponseRemovingChambers(triggerStore);
639 ok = triggerStore->Connect(clustersTree,alone);
642 AliError("Could not create triggerStore branches in TreeR");
650 fClusterStore = new AliMUONClusterStoreV2;
653 AliMUONVClusterServer* clusterServer = CreateClusterServer(*rp);
655 TIter next(DigitStore()->CreateIterator());
656 clusterServer->UseDigits(next,DigitStore());
660 AliDebug(1,Form("Doing full clusterization in local reconstruction using %s ",clusterServer->ClassName()));
662 for ( Int_t i = 0; i < AliMpConstants::NofTrackingChambers(); ++i )
664 if (rp->UseChamber(i))
666 if ( ( i == 6 || i == 7 ) && rp->BypassSt4() ) continue;
667 if ( ( i == 8 || i == 9 ) && rp->BypassSt5() ) continue;
669 clusterServer->Clusterize(i,*fClusterStore,area,rp);
673 Bool_t cok = fClusterStore->Connect(clustersTree,alone);
675 if (!cok) AliError("Could not connect clusterStore to clusterTree");
677 AliDebug(1,Form("Number of clusters found = %d",fClusterStore->GetSize()));
679 StdoutToAliDebug(1,fClusterStore->Print());
682 if (ok) // at least one type of branches created successfully
687 if (fClusterStore) fClusterStore->Clear();
690 //_____________________________________________________________________________
691 const AliMUONRecoParam* AliMUONReconstructor::GetRecoParam()
693 /// Get the recoparam from reconstruction
694 return dynamic_cast<const AliMUONRecoParam*>(AliReconstructor::GetRecoParam(AliReconstruction::GetDetIndex("MUON")));
698 //_____________________________________________________________________________
700 AliMUONReconstructor::HasDigitConversion() const
702 /// We *do* have digit conversion, but we might advertise it only
703 /// if we want to save the digits.
705 TString opt(GetOption());
707 if ( opt.Contains("SAVEDIGITS" ) && !opt.Contains("NOLOCALRECONSTRUCTION") )
717 //_____________________________________________________________________________
719 AliMUONReconstructor::Reconstruct(AliRawReader* rawReader, TTree* clustersTree) const
721 /// This method is called by AliReconstruction if HasLocalReconstruction()==kTRUE AND
722 /// HasDigitConversion()==kFALSE
726 AliError("clustersTree is 0x0 !");
730 ConvertDigits(rawReader,DigitStore(),TriggerStore());
732 FillTreeR(TriggerStore(),*clustersTree);
735 //_____________________________________________________________________________
737 AliMUONReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
739 /// This method is called by AliReconstruction if HasLocalReconstruction()==kTRUE
740 /// AND HasDigitConversion()==kTRUE
742 AliCodeTimerAuto("",0)
746 if (!digitsTree || !clustersTree)
748 AliError(Form("Tree is null : digitsTree=%p clustersTree=%p",
749 digitsTree,clustersTree));
755 fDigitStore = AliMUONVDigitStore::Create(*digitsTree);
758 AliError(Form("Could not get DigitStore from %s",digitsTree->GetName()));
762 AliInfo(Form("Created %s from %s",fDigitStore->ClassName(),digitsTree->GetName()));
767 fTriggerStore = AliMUONVTriggerStore::Create(*digitsTree);
770 AliError(Form("Could not get TriggerStore from %s",digitsTree->GetName()));
774 AliInfo(Form("Created %s from %s",fTriggerStore->ClassName(),digitsTree->GetName()));
778 if (!fTriggerStore && !fDigitStore)
780 AliError("No store at all. Nothing to do.");
784 // insure we start with empty stores
787 fDigitStore->Clear();
788 Bool_t alone = ( fTriggerStore ? kFALSE : kTRUE );
789 Bool_t ok = fDigitStore->Connect(*digitsTree,alone);
792 AliError("Could not connect digitStore to digitsTree");
798 fTriggerStore->Clear();
799 Bool_t alone = ( fDigitStore ? kFALSE : kTRUE );
800 Bool_t ok = fTriggerStore->Connect(*digitsTree,alone);
803 AliError("Could not connect triggerStore to digitsTree");
808 digitsTree->GetEvent(0);
812 // Insure we got calibrated digits (if we reconstruct from pure simulated,
813 // i.e. w/o going through raw data, this will be the case)
814 TIter next(fDigitStore->CreateIterator());
815 AliMUONVDigit* digit = static_cast<AliMUONVDigit*>(next());
816 if (digit && !digit->IsCalibrated())
818 Calibrate(*fDigitStore);
822 FillTreeR(fTriggerStore,*clustersTree);
825 //_____________________________________________________________________________
826 AliMUONVTriggerStore*
827 AliMUONReconstructor::TriggerStore() const
829 /// Return (and create if necessary and allowed) the trigger container
830 TString sopt(GetOption());
833 if (sopt.Contains("TRIGGERDISABLE"))
835 delete fTriggerStore;
842 fTriggerStore = new AliMUONTriggerStoreV1;
845 return fTriggerStore;