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 by using
23 /// AliMUONRecoParam *muonRecoParam = AliMUONRecoParam::GetLow(High)FluxParam();
24 /// muonRecoParam->Set...(); // see methods in AliMUONRecoParam.h for details
25 /// AliRecoParam::Instance()->RegisterRecoParam(muonRecoParam);
29 /// SIMPLEFIT : use the AliMUONClusterFinderSimpleFit clusterizer
31 /// SIMPLEFITV3 : SIMPLEFIT with preclustering=PRECLUSTERV3
33 /// MLEM : use AliMUONClusterFinderMLEM and AliMUONPreClusterFinder for preclustering (default)
34 /// MLEMV2 : MLEM with preclustering=PRECLUSTERV2
35 /// MLEMV3 : MLEM with preclustering=PRECLUSTERV3
37 /// PRECLUSTER : use only AliMUONPreClusterFinder. Only for debug as
38 /// the produced clusters do not have a position, hence the tracking will not
40 /// PRECLUSTERV2 : another version of the preclustering
41 /// PRECLUSTERV3 : yet another version of the preclustering
43 /// COG : use AliMUONClusterFinderCOG clusterizer. Not really a production
44 /// option either, as center-of-gravity is generally not a good estimate
45 /// of the cluster position...
47 /// PEAKCOG : COG cluster finder around local maxima
48 /// PEAKFIT : fit around local maxima with up to 3 peaks, COG otherwise
50 /// NOCLUSTERING : bypass completely the clustering stage
54 /// The behavior of the MUON reconstruction can also be changed, besides
55 /// the usual methods found in AliReconstruction (e.g. to disable tracking)
56 /// by using AliReconstruction::SetOption("MUON",options)
57 /// where options should be a space separated string.
59 /// Valid options are :
61 /// SAVEDIGITS : if you want to save in the TreeD the *calibrated* digits
62 /// that are used for the clustering
64 /// DIGITSTOREV1 : use the V1 implementation of the digitstore
65 /// DIGITSTOREV2R : use the V2R implementation of the digitstore
67 /// NOLOCALRECONSTRUCTION : for debug, to disable local reconstruction (and hence
68 /// "recover" old behavior)
70 /// TRIGGERDISABLE : disable the treatment of MUON trigger
72 /// USEFASTDECODER : makes the digit maker class use the high performance decoder
73 /// AliMUONTrackerDDLDecoder instead of AliMUONPayloadTracker.
75 /// \author Laurent Aphecetche, Subatech
76 //-----------------------------------------------------------------------------
78 #include "AliMUONReconstructor.h"
80 #include "AliMUONCalibrationData.h"
81 #include "AliMUONClusterFinderCOG.h"
82 #include "AliMUONClusterFinderMLEM.h"
83 #include "AliMUONClusterFinderSimpleFit.h"
84 #include "AliMUONClusterFinderPeakCOG.h"
85 #include "AliMUONClusterFinderPeakFit.h"
86 #include "AliMUONClusterStoreV1.h"
87 #include "AliMUONClusterStoreV2.h"
88 #include "AliMUONConstants.h"
89 #include "AliMUONDigitCalibrator.h"
90 #include "AliMUONDigitMaker.h"
91 #include "AliMUONDigitStoreV1.h"
92 #include "AliMUONDigitStoreV2R.h"
93 #include "AliMUONGeometryTransformer.h"
94 #include "AliMUONPreClusterFinder.h"
95 #include "AliMUONPreClusterFinderV2.h"
96 #include "AliMUONPreClusterFinderV3.h"
97 #include "AliMUONRecoParam.h"
98 #include "AliMUONSimpleClusterServer.h"
99 #include "AliMUONTracker.h"
100 #include "AliMUONTriggerCircuit.h"
101 #include "AliMUONTriggerCrateStore.h"
102 #include "AliMUONTriggerStoreV1.h"
103 #include "AliMUONVClusterFinder.h"
104 #include "AliMUONVClusterServer.h"
105 #include "AliMUONVTrackStore.h"
107 #include "AliMpArea.h"
108 #include "AliMpCDB.h"
109 #include "AliMpConstants.h"
111 #include "AliRecoParam.h"
112 #include "AliRawReader.h"
113 #include "AliCDBManager.h"
114 #include "AliCodeTimer.h"
117 #include <Riostream.h>
118 #include <TObjArray.h>
119 #include <TClonesArray.h>
124 ClassImp(AliMUONReconstructor)
127 AliMUONRecoParam* AliMUONReconstructor::fgRecoParam = 0x0; // reconstruction parameters
129 //_____________________________________________________________________________
130 AliMUONReconstructor::AliMUONReconstructor() :
134 fTransformer(new AliMUONGeometryTransformer()),
136 fTriggerCircuit(0x0),
137 fCalibrationData(0x0),
138 fDigitCalibrator(0x0),
146 if ( ! AliMpCDB::LoadDDLStore() ) {
147 AliFatal("Could not access mapping from OCDB !");
150 // Load geometry data
151 fTransformer->LoadGeometryData();
155 //_____________________________________________________________________________
156 AliMUONReconstructor::~AliMUONReconstructor()
162 delete fCrateManager;
163 delete fTriggerCircuit;
164 delete fCalibrationData;
165 delete fDigitCalibrator;
166 delete fClusterServer;
167 delete fTriggerStore;
171 //_____________________________________________________________________________
172 const AliMUONRecoParam* AliMUONReconstructor::GetRecoParam()
174 /// get reconstruction parameters
178 // get reconstruction parameters from AliRecoParam if any
179 TObjArray *recoParams = AliRecoParam::Instance()->GetRecoParam("MUON");
183 fgRecoParam = (AliMUONRecoParam*) recoParams->Last();
187 // initialize reconstruction parameters if not already done
188 cout<<"W-AliMUONReconstructor::GetRecoParam: Reconstruction parameters not initialized - Use default one"<<endl;
189 fgRecoParam = AliMUONRecoParam::GetLowFluxParam();
190 AliRecoParam::Instance()->RegisterRecoParam(fgRecoParam);
199 //_____________________________________________________________________________
201 AliMUONReconstructor::Calibrate(AliMUONVDigitStore& digitStore) const
203 /// Calibrate the digitStore
204 if (!fDigitCalibrator)
208 AliCodeTimerAuto(Form("%s::Calibrate(AliMUONVDigitStore*)",fDigitCalibrator->ClassName()))
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 AliCodeTimerStart(Form("%s::Raw2Digits(AliRawReader*,AliMUONVDigitStore*,AliMUONVTriggerStore*)",
222 fDigitMaker->ClassName()))
223 fDigitMaker->Raw2Digits(rawReader,digitStore,triggerStore);
224 AliCodeTimerStop(Form("%s::Raw2Digits(AliRawReader*,AliMUONVDigitStore*,AliMUONVTriggerStore*)",
225 fDigitMaker->ClassName()))
226 Calibrate(*digitStore);
229 //_____________________________________________________________________________
231 AliMUONReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
233 /// convert raw data into a digit tree
236 Bool_t alone = ( TriggerStore() == 0 );
238 Bool_t ok = DigitStore()->Connect(*digitsTree,alone);
239 if ( TriggerStore() )
241 ok = ok && TriggerStore()->Connect(*digitsTree,kFALSE);
246 AliError("Could not make branches on TreeD");
250 ConvertDigits(rawReader,DigitStore(),TriggerStore());
251 AliCodeTimerStart("Fill digits")
253 AliCodeTimerStop("Fill digits")
254 DigitStore()->Clear();
258 //_____________________________________________________________________________
259 AliMUONTriggerCrateStore*
260 AliMUONReconstructor::CrateManager() const
262 /// Return (and create if necessary) the trigger crate store
263 if (fCrateManager) return fCrateManager;
264 fCrateManager = new AliMUONTriggerCrateStore;
265 fCrateManager->ReadFromFile();
266 return fCrateManager;
269 //_____________________________________________________________________________
271 AliMUONReconstructor::CreateDigitMaker() const
273 /// Create (and create if necessary) the digit maker
274 if (fDigitMaker) return;
278 TString option = GetOption();
279 Bool_t enableErrorLogging = kTRUE;
280 Bool_t useFastDecoder = kFALSE;
281 if (option.Contains("USEFASTDECODER"))
283 useFastDecoder = kTRUE;
285 fDigitMaker = new AliMUONDigitMaker(enableErrorLogging, useFastDecoder);
287 if ( option.Contains("SAVEDIGITS" ))
289 fDigitMaker->SetMakeTriggerDigits(kTRUE);
293 //_____________________________________________________________________________
295 AliMUONReconstructor::CreateTriggerCircuit() const
297 /// Return (and create if necessary) the trigger circuit object
298 if (fTriggerCircuit) return;
302 fTriggerCircuit = new AliMUONTriggerCircuit(fTransformer);
306 //_____________________________________________________________________________
308 AliMUONReconstructor::CreateTracker() const
310 /// Create the MUONTracker object
312 CreateTriggerCircuit();
314 CreateClusterServer();
316 AliMUONTracker* tracker(0x0);
318 if ( ! AliMUONReconstructor::GetRecoParam()->CombineClusterTrackReco() )
320 tracker = new AliMUONTracker(0x0,
328 tracker = new AliMUONTracker(fClusterServer,
339 //_____________________________________________________________________________
340 AliMUONVClusterFinder*
341 AliMUONReconstructor::CreateClusterFinder(const char* clusterFinderType)
343 /// Create a given cluster finder instance
345 AliCodeTimerAutoGeneral("")
347 AliMUONVClusterFinder* clusterFinder(0x0);
349 TString opt(clusterFinderType);
352 if ( strstr(opt,"PRECLUSTERV2") )
354 clusterFinder = new AliMUONPreClusterFinderV2;
356 else if ( strstr(opt,"PRECLUSTERV3") )
358 clusterFinder = new AliMUONPreClusterFinderV3;
360 else if ( strstr(opt,"PRECLUSTER") )
362 clusterFinder = new AliMUONPreClusterFinder;
364 else if ( strstr(opt,"PEAKCOG") )
366 clusterFinder = new AliMUONClusterFinderPeakCOG(kFALSE,new AliMUONPreClusterFinder);
368 else if ( strstr(opt,"PEAKFIT") )
370 clusterFinder = new AliMUONClusterFinderPeakFit(kFALSE,new AliMUONPreClusterFinder);
372 else if ( strstr(opt,"COG") )
374 clusterFinder = new AliMUONClusterFinderCOG(new AliMUONPreClusterFinder);
376 else if ( strstr(opt,"SIMPLEFITV3") )
378 clusterFinder = new AliMUONClusterFinderSimpleFit(new AliMUONClusterFinderCOG(new AliMUONPreClusterFinderV3));
380 else if ( strstr(opt,"SIMPLEFIT") )
382 clusterFinder = new AliMUONClusterFinderSimpleFit(new AliMUONClusterFinderCOG(new AliMUONPreClusterFinder));
384 else if ( strstr(opt,"MLEM:DRAW") )
386 clusterFinder = new AliMUONClusterFinderMLEM(kTRUE,new AliMUONPreClusterFinder);
388 else if ( strstr(opt,"MLEMV3") )
390 clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinderV3);
392 else if ( strstr(opt,"MLEMV2") )
394 clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinderV2);
396 else if ( strstr(opt,"MLEM") )
398 clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinder);
402 AliErrorClass(Form("clustering mode \"%s\" does not exist",opt.Data()));
406 return clusterFinder;
409 //_____________________________________________________________________________
411 AliMUONReconstructor::CreateClusterServer() const
413 /// Create cluster server
415 if ( fClusterServer ) return;
417 AliCodeTimerAuto("");
419 AliMUONVClusterFinder* clusterFinder = CreateClusterFinder(GetRecoParam()->GetClusteringMode());
421 if ( !clusterFinder ) return;
423 AliInfo(Form("Will use %s for clusterizing",clusterFinder->ClassName()));
425 fClusterServer = new AliMUONSimpleClusterServer(clusterFinder,*fTransformer);
428 //_____________________________________________________________________________
430 AliMUONReconstructor::CreateCalibrator() const
432 /// Create the calibrator
436 Int_t runNumber = AliCDBManager::Instance()->GetRun();
438 AliInfo("Calibration will occur.");
440 fCalibrationData = new AliMUONCalibrationData(runNumber);
441 if ( !fCalibrationData->IsValid() )
443 AliError("Could not retrieve calibrations !");
444 delete fCalibrationData;
445 fCalibrationData = 0x0;
449 // Check that we get all the calibrations we'll need
450 if ( !fCalibrationData->Pedestals() ||
451 !fCalibrationData->Gains() ||
452 !fCalibrationData->HV() )
454 AliFatal("Could not access all required calibration data");
457 TString opt(GetOption());
460 if ( strstr(opt,"NOSTATUSMAP") )
462 AliWarning("NOSTATUSMAP is obsolete");
465 TString calibMode = GetRecoParam()->GetCalibrationMode();
467 fDigitCalibrator = new AliMUONDigitCalibrator(*fCalibrationData,calibMode.Data());
470 //_____________________________________________________________________________
472 AliMUONReconstructor::DigitStore() const
474 /// Return (and create if necessary) the digit container
477 TString sopt(GetOption());
480 AliInfo(Form("Options=%s",sopt.Data()));
482 if ( sopt.Contains("DIGITSTOREV1") )
484 fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV1");
486 else if ( sopt.Contains("DIGITSTOREV2R") )
488 fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2R");
490 else if ( sopt.Contains("DIGITSTOREV2S") )
492 fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2S");
495 if (!fDigitStore) fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2R");
497 AliInfo(Form("Will use %s to store digits during reconstruction",fDigitStore->ClassName()));
502 //_____________________________________________________________________________
504 AliMUONReconstructor::FillTreeR(AliMUONVTriggerStore* triggerStore,
505 TTree& clustersTree) const
507 /// Write the trigger and cluster information into TreeR
514 Bool_t alone(kTRUE); // is trigger the only info in TreeR ?
516 if ( ! AliMUONReconstructor::GetRecoParam()->CombineClusterTrackReco() )
518 alone = kFALSE; // we'll get both tracker and trigger information in TreeR
523 ok = triggerStore->Connect(clustersTree,alone);
526 AliError("Could not create triggerStore branches in TreeR");
530 AliMUONVClusterStore* clusterStore(0x0);
534 clusterStore = new AliMUONClusterStoreV2;
536 CreateClusterServer();
538 TIter next(DigitStore()->CreateIterator());
539 fClusterServer->UseDigits(next);
543 AliDebug(1,Form("Doing full clusterization in local reconstruction using %s ",fClusterServer->ClassName()));
545 for ( Int_t i = 0; i < AliMpConstants::NofTrackingChambers(); ++i )
547 if (AliMUONReconstructor::GetRecoParam()->UseChamber(i))
549 if ( i >= 6 && AliMUONReconstructor::GetRecoParam()->BypassSt45() ) continue;
551 fClusterServer->Clusterize(i,*clusterStore,area);
555 Bool_t cok = clusterStore->Connect(clustersTree,alone);
557 if (!cok) AliError("Could not connect clusterStore to clusterTree");
559 AliDebug(1,Form("Number of clusters found = %d",clusterStore->GetSize()));
561 StdoutToAliDebug(1,clusterStore->Print());
564 if (ok) // at least one type of branches created successfully
572 //_____________________________________________________________________________
574 AliMUONReconstructor::HasDigitConversion() const
576 /// We *do* have digit conversion, but we might advertise it only
577 /// if we want to save the digits.
579 TString opt(GetOption());
581 if ( opt.Contains("SAVEDIGITS" ) && !opt.Contains("NOLOCALRECONSTRUCTION") )
591 //_____________________________________________________________________________
593 AliMUONReconstructor::Reconstruct(AliRawReader* rawReader, TTree* clustersTree) const
595 /// This method is called by AliReconstruction if HasLocalReconstruction()==kTRUE AND
596 /// HasDigitConversion()==kFALSE
600 AliError("clustersTree is 0x0 !");
604 ConvertDigits(rawReader,DigitStore(),TriggerStore());
606 FillTreeR(TriggerStore(),*clustersTree);
609 //_____________________________________________________________________________
611 AliMUONReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
613 /// This method is called by AliReconstruction if HasLocalReconstruction()==kTRUE
614 /// AND HasDigitConversion()==kTRUE
620 if (!digitsTree || !clustersTree)
622 AliError(Form("Tree is null : digitsTree=%p clustersTree=%p",
623 digitsTree,clustersTree));
629 fDigitStore = AliMUONVDigitStore::Create(*digitsTree);
632 AliError(Form("Could not get DigitStore from %s",digitsTree->GetName()));
636 AliInfo(Form("Created %s from %s",fDigitStore->ClassName(),digitsTree->GetName()));
641 fTriggerStore = AliMUONVTriggerStore::Create(*digitsTree);
644 AliError(Form("Could not get TriggerStore from %s",digitsTree->GetName()));
648 AliInfo(Form("Created %s from %s",fTriggerStore->ClassName(),digitsTree->GetName()));
652 if (!fTriggerStore && !fDigitStore)
654 AliError("No store at all. Nothing to do.");
658 // insure we start with empty stores
661 fDigitStore->Clear();
662 Bool_t alone = ( fTriggerStore ? kFALSE : kTRUE );
663 Bool_t ok = fDigitStore->Connect(*digitsTree,alone);
666 AliError("Could not connect digitStore to digitsTree");
672 fTriggerStore->Clear();
673 Bool_t alone = ( fDigitStore ? kFALSE : kTRUE );
674 Bool_t ok = fTriggerStore->Connect(*digitsTree,alone);
677 AliError("Could not connect triggerStore to digitsTree");
682 digitsTree->GetEvent(0);
686 // Insure we got calibrated digits (if we reconstruct from pure simulated,
687 // i.e. w/o going through raw data, this will be the case)
688 TIter next(fDigitStore->CreateIterator());
689 AliMUONVDigit* digit = static_cast<AliMUONVDigit*>(next());
690 if (digit && !digit->IsCalibrated())
692 Calibrate(*fDigitStore);
696 FillTreeR(fTriggerStore,*clustersTree);
699 //_____________________________________________________________________________
700 AliMUONVTriggerStore*
701 AliMUONReconstructor::TriggerStore() const
703 /// Return (and create if necessary and allowed) the trigger container
704 TString sopt(GetOption());
707 if (sopt.Contains("TRIGGERDISABLE"))
709 delete fTriggerStore;
716 fTriggerStore = new AliMUONTriggerStoreV1;
719 return fTriggerStore;