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 /// AliMUONReconstructor::SetRecoParam(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 /// NOCLUSTERING : bypass completely the clustering stage
51 /// The behavior of the MUON reconstruction can also be changed, besides
52 /// the usual methods found in AliReconstruction (e.g. to disable tracking)
53 /// by using AliReconstruction::SetOption("MUON",options)
54 /// where options should be a space separated string.
56 /// Valid options are :
58 /// SAVEDIGITS : if you want to save in the TreeD the *calibrated* digits
59 /// that are used for the clustering
61 /// DIGITSTOREV1 : use the V1 implementation of the digitstore
62 /// DIGITSTOREV2R : use the V2R implementation of the digitstore
64 /// NOLOCALRECONSTRUCTION : for debug, to disable local reconstruction (and hence
65 /// "recover" old behavior)
67 /// TRIGGERDISABLE : disable the treatment of MUON trigger
69 /// \author Laurent Aphecetche, Subatech
70 //-----------------------------------------------------------------------------
72 #include "AliMUONReconstructor.h"
74 #include "AliCDBManager.h"
76 #include "AliMUONCalibrationData.h"
77 #include "AliMUONClusterFinderCOG.h"
78 #include "AliMUONClusterFinderMLEM.h"
79 #include "AliMUONClusterFinderSimpleFit.h"
80 #include "AliMUONClusterReconstructor.h"
81 #include "AliMUONClusterStoreV2.h"
82 #include "AliMUONConstants.h"
83 #include "AliMUONDigitCalibrator.h"
84 #include "AliMUONDigitMaker.h"
85 #include "AliMUONDigitStoreV1.h"
86 #include "AliMUONDigitStoreV2R.h"
87 #include "AliMUONGeometryTransformer.h"
88 #include "AliMUONPreClusterFinder.h"
89 #include "AliMUONPreClusterFinderV2.h"
90 #include "AliMUONPreClusterFinderV3.h"
91 #include "AliMUONTracker.h"
92 #include "AliMUONVTrackStore.h"
93 #include "AliMUONTriggerChamberEff.h"
94 #include "AliMUONTriggerCircuit.h"
95 #include "AliMUONTriggerCrateStore.h"
96 #include "AliMUONTriggerStoreV1.h"
97 #include "AliMUONVClusterFinder.h"
98 #include "AliMUONRecoParam.h"
100 #include "AliRawReader.h"
101 #include "AliCodeTimer.h"
102 #include <Riostream.h>
103 #include <TClonesArray.h>
108 ClassImp(AliMUONReconstructor)
111 AliMUONRecoParam* AliMUONReconstructor::fgRecoParam = 0x0; // reconstruction parameters
113 //_____________________________________________________________________________
114 AliMUONReconstructor::AliMUONReconstructor() :
118 fTransformer(new AliMUONGeometryTransformer()),
120 fTriggerCircuit(0x0),
121 fCalibrationData(0x0),
122 fDigitCalibrator(0x0),
123 fClusterReconstructor(0x0),
132 if ( ! AliMpCDB::LoadDDLStore() ) {
133 AliFatal("Could not access mapping from OCDB !");
136 // Load geometry data
137 fTransformer->LoadGeometryData();
139 // initialize reconstruction parameters in not already done
141 AliWarning("Reconstruction parameters not initialized - Use default one");
142 fgRecoParam = AliMUONRecoParam::GetLowFluxParam();
147 //_____________________________________________________________________________
148 AliMUONReconstructor::~AliMUONReconstructor()
154 delete fCrateManager;
155 delete fTriggerCircuit;
156 delete fCalibrationData;
157 delete fDigitCalibrator;
158 delete fClusterReconstructor;
159 delete fClusterStore;
160 delete fTriggerStore;
162 delete fTrigChamberEff;
165 //_____________________________________________________________________________
166 void AliMUONReconstructor::SetRecoParam(AliMUONRecoParam *param)
168 /// set reconstruction parameters
170 // remove existing parameters
172 cout<<"AliMUONReconstructor::SetRecoParam: Reconstruction parameters already initialized - overwrite them"<<endl;
179 //_____________________________________________________________________________
181 AliMUONReconstructor::Calibrate(AliMUONVDigitStore& digitStore) const
183 /// Calibrate the digitStore
184 if (!fDigitCalibrator)
188 AliCodeTimerAuto(Form("%s::Calibrate(AliMUONVDigitStore*)",fDigitCalibrator->ClassName()))
189 fDigitCalibrator->Calibrate(digitStore);
192 //_____________________________________________________________________________
194 AliMUONReconstructor::Clusterize(const AliMUONVDigitStore& digitStore,
195 AliMUONVClusterStore& clusterStore) const
197 /// Creates clusters from digits.
199 TString sopt(fgRecoParam->GetClusteringMode());
201 if ( sopt.Contains("NOCLUSTERING") ) return;
203 if (!fClusterReconstructor) CreateClusterReconstructor();
205 // if the required clustering mode does not exist
206 if (!fClusterReconstructor) return;
208 AliCodeTimerAuto(Form("%s::Digits2Clusters(const AliMUONVDigitStore&,AliMUONVClusterStore&)",
209 fClusterReconstructor->ClassName()))
210 fClusterReconstructor->Digits2Clusters(digitStore,clusterStore);
213 //_____________________________________________________________________________
214 AliMUONVClusterStore*
215 AliMUONReconstructor::ClusterStore() const
217 /// Return (and create if necessary) the cluster container
220 fClusterStore = new AliMUONClusterStoreV2;
222 return fClusterStore;
225 //_____________________________________________________________________________
227 AliMUONReconstructor::ConvertDigits(AliRawReader* rawReader,
228 AliMUONVDigitStore* digitStore,
229 AliMUONVTriggerStore* triggerStore) const
231 /// Convert raw data into digit and trigger stores
234 AliCodeTimerStart(Form("%s::Raw2Digits(AliRawReader*,AliMUONVDigitStore*,AliMUONVTriggerStore*)",
235 fDigitMaker->ClassName()))
236 fDigitMaker->Raw2Digits(rawReader,digitStore,triggerStore);
237 AliCodeTimerStop(Form("%s::Raw2Digits(AliRawReader*,AliMUONVDigitStore*,AliMUONVTriggerStore*)",
238 fDigitMaker->ClassName()))
239 Calibrate(*digitStore);
242 //_____________________________________________________________________________
244 AliMUONReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
246 /// convert raw data into a digit tree
249 Bool_t alone = ( TriggerStore() == 0 );
251 Bool_t ok = DigitStore()->Connect(*digitsTree,alone);
252 if ( TriggerStore() )
254 ok = ok && TriggerStore()->Connect(*digitsTree,kFALSE);
259 AliError("Could not make branches on TreeD");
263 ConvertDigits(rawReader,DigitStore(),TriggerStore());
264 AliCodeTimerStart("Fill digits")
266 AliCodeTimerStop("Fill digits")
267 DigitStore()->Clear();
271 //_____________________________________________________________________________
272 AliMUONTriggerCrateStore*
273 AliMUONReconstructor::CrateManager() const
275 /// Return (and create if necessary) the trigger crate store
276 if (fCrateManager) return fCrateManager;
277 fCrateManager = new AliMUONTriggerCrateStore;
278 fCrateManager->ReadFromFile();
279 return fCrateManager;
282 //_____________________________________________________________________________
284 AliMUONReconstructor::CreateDigitMaker() const
286 /// Create (and create if necessary) the digit maker
287 if (fDigitMaker) return;
291 fDigitMaker = new AliMUONDigitMaker;
294 //_____________________________________________________________________________
296 AliMUONReconstructor::CreateTriggerCircuit() const
298 /// Return (and create if necessary) the trigger circuit object
299 if (fTriggerCircuit) return;
303 fTriggerCircuit = new AliMUONTriggerCircuit(fTransformer);
307 //_____________________________________________________________________________
309 AliMUONReconstructor::CreateTriggerChamberEff() const
311 /// Create (and create if necessary) the trigger chamber efficiency class
312 if (fTrigChamberEff) return;
316 fTrigChamberEff = new AliMUONTriggerChamberEff(fTransformer,fDigitMaker,kTRUE);
317 //fTrigChamberEff->SetDebugLevel(1);
320 //_____________________________________________________________________________
322 AliMUONReconstructor::CreateTracker() const
324 /// Create the MUONTracker object
326 CreateTriggerCircuit();
328 CreateTriggerChamberEff();
330 AliMUONTracker* tracker = new AliMUONTracker(fDigitMaker,fTransformer,fTriggerCircuit,fTrigChamberEff);
335 //_____________________________________________________________________________
337 AliMUONReconstructor::CreateClusterReconstructor() const
339 /// Create cluster reconstructor, depending on clustering mode set in RecoParam
345 AliMUONVClusterFinder* clusterFinder(0x0);
347 TString opt(fgRecoParam->GetClusteringMode());
350 if ( strstr(opt,"PRECLUSTERV2") )
352 clusterFinder = new AliMUONPreClusterFinderV2;
354 else if ( strstr(opt,"PRECLUSTERV3") )
356 clusterFinder = new AliMUONPreClusterFinderV3;
358 else if ( strstr(opt,"PRECLUSTER") )
360 clusterFinder = new AliMUONPreClusterFinder;
362 else if ( strstr(opt,"COG") )
364 clusterFinder = new AliMUONClusterFinderCOG(new AliMUONPreClusterFinder);
366 else if ( strstr(opt,"SIMPLEFITV3") )
368 clusterFinder = new AliMUONClusterFinderSimpleFit(new AliMUONClusterFinderCOG(new AliMUONPreClusterFinderV3));
370 else if ( strstr(opt,"SIMPLEFIT") )
372 clusterFinder = new AliMUONClusterFinderSimpleFit(new AliMUONClusterFinderCOG(new AliMUONPreClusterFinder));
374 else if ( strstr(opt,"MLEM:DRAW") )
376 clusterFinder = new AliMUONClusterFinderMLEM(kTRUE,new AliMUONPreClusterFinder);
378 else if ( strstr(opt,"MLEMV3") )
380 clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinderV3);
382 else if ( strstr(opt,"MLEMV2") )
384 clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinderV2);
386 else if ( strstr(opt,"MLEM") )
388 clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinder);
392 AliError(Form("clustering mode \"%s\" does not exist",opt.Data()));
396 AliInfo(Form("Will use %s for clusterizing",clusterFinder->ClassName()));
398 fClusterReconstructor = new AliMUONClusterReconstructor(clusterFinder,fTransformer);
401 //_____________________________________________________________________________
403 AliMUONReconstructor::CreateCalibrator() const
405 /// Create the calibrator
409 Int_t runNumber = AliCDBManager::Instance()->GetRun();
411 AliInfo("Calibration will occur.");
413 fCalibrationData = new AliMUONCalibrationData(runNumber);
414 if ( !fCalibrationData->IsValid() )
416 AliError("Could not retrieve calibrations !");
417 delete fCalibrationData;
418 fCalibrationData = 0x0;
422 // Check that we get all the calibrations we'll need
423 if ( !fCalibrationData->Pedestals() ||
424 !fCalibrationData->Gains() ||
425 !fCalibrationData->HV() )
427 AliFatal("Could not access all required calibration data");
430 TString opt(GetOption());
433 if ( strstr(opt,"NOSTATUSMAP") )
435 AliWarning("NOSTATUSMAP is obsolete");
438 fDigitCalibrator = new AliMUONDigitCalibrator(*fCalibrationData);
441 //_____________________________________________________________________________
443 AliMUONReconstructor::DigitStore() const
445 /// Return (and create if necessary) the digit container
448 TString sopt(GetOption());
451 AliInfo(Form("Options=%s",sopt.Data()));
453 if ( sopt.Contains("DIGITSTOREV1") )
455 fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV1");
457 else if ( sopt.Contains("DIGITSTOREV2R") )
459 fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2R");
461 else if ( sopt.Contains("DIGITSTOREV2S") )
463 fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2S");
466 if (!fDigitStore) fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2R");
468 AliInfo(Form("Will use %s to store digits during reconstruction",fDigitStore->ClassName()));
473 //_____________________________________________________________________________
475 AliMUONReconstructor::FillTreeR(AliMUONVTriggerStore* triggerStore,
476 AliMUONVClusterStore* clusterStore,
477 TTree& clustersTree) const
479 /// Write the trigger and cluster information into TreeR
488 Bool_t alone = ( clusterStore ? kFALSE : kTRUE );
489 ok = triggerStore->Connect(clustersTree,alone);
492 AliError("Could not create triggerStore branches in TreeR");
498 Bool_t alone = ( triggerStore ? kFALSE : kTRUE );
499 ok = clusterStore->Connect(clustersTree,alone);
502 AliError("Could not create triggerStore branches in TreeR");
506 if (ok) // at least one type of branches created successfully
512 //_____________________________________________________________________________
514 AliMUONReconstructor::HasDigitConversion() const
516 /// We *do* have digit conversion, but we might advertise it only
517 /// if we want to save the digits.
519 TString opt(GetOption());
521 if ( opt.Contains("SAVEDIGITS" ) && !opt.Contains("NOLOCALRECONSTRUCTION") )
531 //_____________________________________________________________________________
533 AliMUONReconstructor::Reconstruct(AliRawReader* rawReader, TTree* clustersTree) const
535 /// This method is called by AliReconstruction if HasLocalReconstruction()==kTRUE AND
536 /// HasDigitConversion()==kFALSE
540 AliError("clustersTree is 0x0 !");
544 ConvertDigits(rawReader,DigitStore(),TriggerStore());
545 Clusterize(*(DigitStore()),*(ClusterStore()));
547 FillTreeR(TriggerStore(),ClusterStore(),*clustersTree);
550 //_____________________________________________________________________________
552 AliMUONReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
554 /// This method is called by AliReconstruction if HasLocalReconstruction()==kTRUE
555 /// AND HasDigitConversion()==kTRUE
561 if (!digitsTree || !clustersTree)
563 AliError(Form("Tree is null : digitsTree=%p clustersTree=%p",
564 digitsTree,clustersTree));
570 fDigitStore = AliMUONVDigitStore::Create(*digitsTree);
573 AliError(Form("Could not get DigitStore from %s",digitsTree->GetName()));
577 AliInfo(Form("Created %s from %s",fDigitStore->ClassName(),digitsTree->GetName()));
582 fTriggerStore = AliMUONVTriggerStore::Create(*digitsTree);
585 AliError(Form("Could not get TriggerStore from %s",digitsTree->GetName()));
589 AliInfo(Form("Created %s from %s",fTriggerStore->ClassName(),digitsTree->GetName()));
593 if (!fTriggerStore && !fDigitStore)
595 AliError("No store at all. Nothing to do.");
599 // insure we start with empty stores
602 fDigitStore->Clear();
603 Bool_t alone = ( fTriggerStore ? kFALSE : kTRUE );
604 Bool_t ok = fDigitStore->Connect(*digitsTree,alone);
607 AliError("Could not connect digitStore to digitsTree");
613 fTriggerStore->Clear();
614 Bool_t alone = ( fDigitStore ? kFALSE : kTRUE );
615 Bool_t ok = fTriggerStore->Connect(*digitsTree,alone);
618 AliError("Could not connect triggerStore to digitsTree");
623 digitsTree->GetEvent(0);
627 // Insure we got calibrated digits (if we reconstruct from pure simulated,
628 // i.e. w/o going through raw data, this will be the case)
629 TIter next(fDigitStore->CreateIterator());
630 AliMUONVDigit* digit = static_cast<AliMUONVDigit*>(next());
631 if (!digit->IsCalibrated())
633 Calibrate(*fDigitStore);
635 Clusterize(*fDigitStore,*(ClusterStore()));
638 FillTreeR(fTriggerStore,ClusterStore(),*clustersTree);
641 //_____________________________________________________________________________
642 AliMUONVTriggerStore*
643 AliMUONReconstructor::TriggerStore() const
645 /// Return (and create if necessary and allowed) the trigger container
646 TString sopt(GetOption());
649 if (sopt.Contains("TRIGGERDISABLE"))
651 delete fTriggerStore;
658 fTriggerStore = new AliMUONTriggerStoreV1;
661 return fTriggerStore;