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),
141 fTriggerProcessor(0x0),
142 fTriggerUtilities(0x0)
148 // Unload mapping objects
149 // if they have been loaded from the obsolete OCDB mapping objects
151 if ( AliMpDDLStore::Instance(false) ) {
152 AliCDBManager::Instance()->UnloadFromCache("MUON/Calib/DDLStore");
153 delete AliMpDDLStore::Instance();
156 if ( AliMpSegmentation::Instance(false) ) {
157 AliCDBManager::Instance()->UnloadFromCache("MUON/Calib/Mapping");
158 delete AliMpSegmentation::Instance();
162 if ( ! AliMpCDB::LoadDDLStore() ) {
163 AliFatal("Could not access mapping from OCDB !");
166 // Load geometry data
167 fTransformer->LoadGeometryData();
171 //_____________________________________________________________________________
172 AliMUONReconstructor::~AliMUONReconstructor()
178 delete fDigitCalibrator;
183 delete fTriggerCircuit;
184 delete fTriggerStore;
186 delete fClusterStore;
187 delete fTriggerProcessor;
188 delete fTriggerUtilities;
190 delete AliMpSegmentation::Instance(false);
191 delete AliMpDDLStore::Instance(false);
193 delete fCalibrationData;
196 //_____________________________________________________________________________
198 AliMUONReconstructor::Calibrate(AliMUONVDigitStore& digitStore) const
200 /// Calibrate the digitStore
201 if (!fDigitCalibrator)
205 AliCodeTimerAuto(Form("%s::Calibrate(AliMUONVDigitStore*)",fDigitCalibrator->ClassName()),0)
206 fDigitCalibrator->Calibrate(digitStore);
209 //_____________________________________________________________________________
211 AliMUONReconstructor::ConvertDigits(AliRawReader* rawReader,
212 AliMUONVDigitStore* digitStore,
213 AliMUONVTriggerStore* triggerStore) const
215 /// Convert raw data into digit and trigger stores
218 // Skip reconstruction if event is Calibration
219 if ( GetRecoParam()->GetEventSpecie() == AliRecoParam::kCalib ) {
220 digitStore->Clear(); // Remove possible digits from previous event
221 triggerStore->Clear(); // Remove possible triggers from previous event
222 AliInfo("Calibration event: do not convert digits");
226 AliCodeTimerStart(Form("%s::Raw2Digits(AliRawReader*,AliMUONVDigitStore*,AliMUONVTriggerStore*)",
227 fDigitMaker->ClassName()))
228 fDigitMaker->Raw2Digits(rawReader,digitStore,triggerStore);
229 AliCodeTimerStop(Form("%s::Raw2Digits(AliRawReader*,AliMUONVDigitStore*,AliMUONVTriggerStore*)",
230 fDigitMaker->ClassName()))
231 Calibrate(*digitStore);
234 //_____________________________________________________________________________
236 AliMUONReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
238 /// convert raw data into a digit tree
239 AliCodeTimerAuto("",0)
241 Bool_t alone = ( TriggerStore() == 0 );
243 Bool_t ok = DigitStore()->Connect(*digitsTree,alone);
244 if ( TriggerStore() )
246 ok = ok && TriggerStore()->Connect(*digitsTree,kFALSE);
251 AliError("Could not make branches on TreeD");
255 ConvertDigits(rawReader,DigitStore(),TriggerStore());
256 AliCodeTimerStart("Fill digits")
258 AliCodeTimerStop("Fill digits")
259 DigitStore()->Clear();
263 //_____________________________________________________________________________
265 AliMUONReconstructor::CreateDigitMaker() const
267 /// Create (and create if necessary) the digit maker
268 if (fDigitMaker) return;
270 AliCodeTimerAuto("",0)
272 TString option = GetOption();
274 Bool_t enableErrorLogging = kFALSE;
276 if (option.Contains("ENABLEERRORLOGGING"))
278 enableErrorLogging = kTRUE;
281 fDigitMaker = new AliMUONDigitMaker(enableErrorLogging);
284 // Always make trigger digits
285 // (needed when calculating trigger chamber efficiency)
286 fDigitMaker->SetMakeTriggerDigits(kTRUE);
288 if ( GetRecoParam()->TryRecover() )
290 fDigitMaker->SetTryRecover(kTRUE);
294 fDigitMaker->SetTryRecover(kFALSE);
298 //_____________________________________________________________________________
300 AliMUONReconstructor::CreateTriggerCircuit() const
302 /// Return (and create if necessary) the trigger circuit object
303 if (fTriggerCircuit) return;
305 AliCodeTimerAuto("",0)
307 fTriggerCircuit = new AliMUONTriggerCircuit(fTransformer);
311 //_____________________________________________________________________________
313 AliMUONReconstructor::CreateTriggerUtilities() const
315 /// Return (and create if necessary) the trigger utilities object
316 if ( fTriggerUtilities ) return;
318 AliCodeTimerAuto("",0)
320 if ( ! fCalibrationData ) CreateCalibrationData();
322 fTriggerUtilities = new AliMUONTriggerUtilities(fCalibrationData);
325 //_____________________________________________________________________________
327 AliMUONReconstructor::CreateTracker() const
329 /// Create the MUONTracker object
331 CreateTriggerCircuit();
332 CreateTriggerUtilities();
333 CreateClusterServer();
335 AliMUONTracker* tracker(0x0);
337 if ( ! GetRecoParam()->CombineClusterTrackReco() )
339 tracker = new AliMUONTracker(GetRecoParam(),
348 tracker = new AliMUONTracker(GetRecoParam(),
360 //_____________________________________________________________________________
361 AliMUONVClusterFinder*
362 AliMUONReconstructor::CreateClusterFinder(const char* clusterFinderType)
364 /// Create a given cluster finder instance
366 AliCodeTimerAutoGeneral("",0)
368 AliMUONVClusterFinder* clusterFinder(0x0);
370 TString opt(clusterFinderType);
373 if ( strstr(opt,"PRECLUSTERV2") )
375 clusterFinder = new AliMUONPreClusterFinderV2;
377 else if ( strstr(opt,"PRECLUSTERV3") )
379 clusterFinder = new AliMUONPreClusterFinderV3;
381 else if ( strstr(opt,"PRECLUSTER") )
383 clusterFinder = new AliMUONPreClusterFinder;
385 else if ( strstr(opt,"PEAKCOG") )
387 clusterFinder = new AliMUONClusterFinderPeakCOG(kFALSE,new AliMUONPreClusterFinder);
389 else if ( strstr(opt,"PEAKFIT") )
391 clusterFinder = new AliMUONClusterFinderPeakFit(kFALSE,new AliMUONPreClusterFinder);
393 else if ( strstr(opt,"COG") )
395 clusterFinder = new AliMUONClusterFinderCOG(new AliMUONPreClusterFinder);
397 else if ( strstr(opt,"SIMPLEFITV3") )
399 clusterFinder = new AliMUONClusterFinderSimpleFit(new AliMUONClusterFinderCOG(new AliMUONPreClusterFinderV3));
401 else if ( strstr(opt,"SIMPLEFIT") )
403 clusterFinder = new AliMUONClusterFinderSimpleFit(new AliMUONClusterFinderCOG(new AliMUONPreClusterFinder));
405 else if ( strstr(opt,"MLEM:DRAW") )
407 clusterFinder = new AliMUONClusterFinderMLEM(kTRUE,new AliMUONPreClusterFinder);
409 else if ( strstr(opt,"MLEMV3") )
411 clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinderV3);
413 else if ( strstr(opt,"MLEMV2") )
415 clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinderV2);
417 else if ( strstr(opt,"MLEM") )
419 clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinder);
423 AliErrorClass(Form("clustering mode \"%s\" does not exist",opt.Data()));
427 return clusterFinder;
430 //_____________________________________________________________________________
432 AliMUONReconstructor::CreateClusterServer() const
434 /// Create cluster server
436 if ( fClusterServer ) return;
438 AliCodeTimerAuto("",0);
440 AliMUONVClusterFinder* clusterFinder = CreateClusterFinder(GetRecoParam()->GetClusteringMode());
442 if ( !clusterFinder ) return;
444 AliInfo(Form("Will use %s for clusterizing",clusterFinder->ClassName()));
446 fClusterServer = new AliMUONSimpleClusterServer(clusterFinder,*fTransformer);
449 //_____________________________________________________________________________
451 AliMUONReconstructor::CreateCalibrationData() const
453 /// Create the calibrator
455 AliCodeTimerAuto("",0);
457 Int_t runNumber = AliCDBManager::Instance()->GetRun();
459 fCalibrationData = new AliMUONCalibrationData(runNumber);
460 if ( !fCalibrationData->IsValid() )
462 AliError("Could not retrieve calibrations !");
463 delete fCalibrationData;
464 fCalibrationData = 0x0;
468 // It is now time to check whether we have everything to proceed.
469 // What we need depends on whether both tracker and trigger
470 // are in the readout chain, and what specific "bad channel policy"
473 Bool_t kTracker(kFALSE);
474 Bool_t kTrigger(kFALSE);
476 const AliRunInfo* runInfo = GetRunInfo();
479 AliError("Could not get runinfo ?");
483 TString detectors(runInfo->GetActiveDetectors());
484 if (detectors.Contains("MUONTRK")) kTracker=kTRUE;
485 if (detectors.Contains("MUONTRG")) kTrigger=kTRUE;
488 AliInfo(Form("Run with MUON TRIGGER : %s and MUON TRACKER : %s",
489 kTrigger ? "YES":"NO" ,
490 kTracker ? "YES":"NO"));
494 // Check that we get all the calibrations we'll need
495 if ( !fCalibrationData->Pedestals() ||
496 !fCalibrationData->Gains() )
498 AliFatal(Form("Could not access all required calibration data (PED %p GAIN %p)",
499 fCalibrationData->Pedestals(),fCalibrationData->Gains()));
502 if ( !fCalibrationData->HV() )
504 // Special treatment of HV. We only break if the values
505 // are not there *AND* we cut on them.
506 UInt_t mask = GetRecoParam()->PadGoodnessMask();
507 TString smask(AliMUONPadStatusMaker::AsCondition(mask));
508 if ( smask.Contains("HV") )
510 AliFatal("Could not access all required calibration data (HV)");
516 //_____________________________________________________________________________
518 AliMUONReconstructor::CreateCalibrator() const
520 /// Create the calibrator
522 AliCodeTimerAuto("",0);
524 if ( ! fCalibrationData )
525 CreateCalibrationData();
527 AliInfo("Calibration will occur.");
529 TString opt(GetOption());
532 if ( strstr(opt,"NOSTATUSMAP") )
534 AliWarning("NOSTATUSMAP is obsolete");
537 fDigitCalibrator = new AliMUONDigitCalibrator(*fCalibrationData,GetRecoParam());
540 //_____________________________________________________________________________
542 AliMUONReconstructor::ResponseRemovingChambers(AliMUONVTriggerStore* triggerStore) const
544 /// Update trigger information with informatins obtained after
545 /// re-calculation of trigger response
546 AliCodeTimerAuto("",0);
548 if ( ! fCalibrationData )
549 CreateCalibrationData();
551 if ( ! fTriggerProcessor )
552 fTriggerProcessor = new AliMUONTriggerElectronics(fCalibrationData);
554 fTriggerProcessor->ResponseRemovingChambers(*triggerStore);
557 //_____________________________________________________________________________
559 AliMUONReconstructor::DigitStore() const
561 /// Return (and create if necessary) the digit container
564 TString sopt(GetOption());
567 AliInfo(Form("Options=%s",sopt.Data()));
569 if ( sopt.Contains("DIGITSTOREV1") )
571 fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV1");
573 else if ( sopt.Contains("DIGITSTOREV2R") )
575 fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2R");
577 else if ( sopt.Contains("DIGITSTOREV2S") )
579 fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2S");
582 if (!fDigitStore) fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2R");
584 AliInfo(Form("Will use %s to store digits during reconstruction",fDigitStore->ClassName()));
589 //_____________________________________________________________________________
591 AliMUONReconstructor::FillTreeR(AliMUONVTriggerStore* triggerStore,
592 TTree& clustersTree) const
594 /// Write the trigger and cluster information into TreeR
596 AliCodeTimerAuto("",0)
599 Bool_t alone(kTRUE); // is trigger the only info in TreeR ?
601 if ( ! GetRecoParam()->CombineClusterTrackReco() )
603 alone = kFALSE; // we'll get both tracker and trigger information in TreeR
608 ResponseRemovingChambers(triggerStore);
609 ok = triggerStore->Connect(clustersTree,alone);
612 AliError("Could not create triggerStore branches in TreeR");
620 fClusterStore = new AliMUONClusterStoreV2;
623 CreateClusterServer();
625 TIter next(DigitStore()->CreateIterator());
626 fClusterServer->UseDigits(next,DigitStore());
630 AliDebug(1,Form("Doing full clusterization in local reconstruction using %s ",fClusterServer->ClassName()));
632 for ( Int_t i = 0; i < AliMpConstants::NofTrackingChambers(); ++i )
634 if (GetRecoParam()->UseChamber(i))
636 if ( ( i == 6 || i == 7 ) && GetRecoParam()->BypassSt4() ) continue;
637 if ( ( i == 8 || i == 9 ) && GetRecoParam()->BypassSt5() ) continue;
639 fClusterServer->Clusterize(i,*fClusterStore,area,GetRecoParam());
643 Bool_t cok = fClusterStore->Connect(clustersTree,alone);
645 if (!cok) AliError("Could not connect clusterStore to clusterTree");
647 AliDebug(1,Form("Number of clusters found = %d",fClusterStore->GetSize()));
649 StdoutToAliDebug(1,fClusterStore->Print());
652 if (ok) // at least one type of branches created successfully
657 if (fClusterStore) fClusterStore->Clear();
660 //_____________________________________________________________________________
662 AliMUONReconstructor::HasDigitConversion() const
664 /// We *do* have digit conversion, but we might advertise it only
665 /// if we want to save the digits.
667 TString opt(GetOption());
669 if ( opt.Contains("SAVEDIGITS" ) && !opt.Contains("NOLOCALRECONSTRUCTION") )
679 //_____________________________________________________________________________
681 AliMUONReconstructor::Reconstruct(AliRawReader* rawReader, TTree* clustersTree) const
683 /// This method is called by AliReconstruction if HasLocalReconstruction()==kTRUE AND
684 /// HasDigitConversion()==kFALSE
688 AliError("clustersTree is 0x0 !");
692 ConvertDigits(rawReader,DigitStore(),TriggerStore());
694 FillTreeR(TriggerStore(),*clustersTree);
697 //_____________________________________________________________________________
699 AliMUONReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
701 /// This method is called by AliReconstruction if HasLocalReconstruction()==kTRUE
702 /// AND HasDigitConversion()==kTRUE
704 AliCodeTimerAuto("",0)
708 if (!digitsTree || !clustersTree)
710 AliError(Form("Tree is null : digitsTree=%p clustersTree=%p",
711 digitsTree,clustersTree));
717 fDigitStore = AliMUONVDigitStore::Create(*digitsTree);
720 AliError(Form("Could not get DigitStore from %s",digitsTree->GetName()));
724 AliInfo(Form("Created %s from %s",fDigitStore->ClassName(),digitsTree->GetName()));
729 fTriggerStore = AliMUONVTriggerStore::Create(*digitsTree);
732 AliError(Form("Could not get TriggerStore from %s",digitsTree->GetName()));
736 AliInfo(Form("Created %s from %s",fTriggerStore->ClassName(),digitsTree->GetName()));
740 if (!fTriggerStore && !fDigitStore)
742 AliError("No store at all. Nothing to do.");
746 // insure we start with empty stores
749 fDigitStore->Clear();
750 Bool_t alone = ( fTriggerStore ? kFALSE : kTRUE );
751 Bool_t ok = fDigitStore->Connect(*digitsTree,alone);
754 AliError("Could not connect digitStore to digitsTree");
760 fTriggerStore->Clear();
761 Bool_t alone = ( fDigitStore ? kFALSE : kTRUE );
762 Bool_t ok = fTriggerStore->Connect(*digitsTree,alone);
765 AliError("Could not connect triggerStore to digitsTree");
770 digitsTree->GetEvent(0);
774 // Insure we got calibrated digits (if we reconstruct from pure simulated,
775 // i.e. w/o going through raw data, this will be the case)
776 TIter next(fDigitStore->CreateIterator());
777 AliMUONVDigit* digit = static_cast<AliMUONVDigit*>(next());
778 if (digit && !digit->IsCalibrated())
780 Calibrate(*fDigitStore);
784 FillTreeR(fTriggerStore,*clustersTree);
787 //_____________________________________________________________________________
788 AliMUONVTriggerStore*
789 AliMUONReconstructor::TriggerStore() const
791 /// Return (and create if necessary and allowed) the trigger container
792 TString sopt(GetOption());
795 if (sopt.Contains("TRIGGERDISABLE"))
797 delete fTriggerStore;
804 fTriggerStore = new AliMUONTriggerStoreV1;
807 return fTriggerStore;