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 "AliMUONPreClusterFinder.h"
93 #include "AliMUONPreClusterFinderV2.h"
94 #include "AliMUONPreClusterFinderV3.h"
95 #include "AliMUONSimpleClusterServer.h"
96 #include "AliMUONTracker.h"
97 #include "AliMUONTriggerCircuit.h"
98 #include "AliMUONTriggerStoreV1.h"
99 #include "AliMUONVClusterFinder.h"
100 #include "AliMUONVClusterServer.h"
101 #include "AliMUONVTrackStore.h"
103 #include "AliMpArea.h"
104 #include "AliMpCDB.h"
105 #include "AliMpConstants.h"
106 #include "AliMpDDLStore.h"
107 #include "AliMpSegmentation.h"
109 #include "AliRawReader.h"
110 #include "AliCDBManager.h"
111 #include "AliCodeTimer.h"
114 #include <Riostream.h>
115 #include <TObjArray.h>
116 #include <TClonesArray.h>
121 ClassImp(AliMUONReconstructor)
124 //_____________________________________________________________________________
125 AliMUONReconstructor::AliMUONReconstructor() :
128 fTransformer(new AliMUONGeometryTransformer()),
130 fTriggerCircuit(0x0),
131 fCalibrationData(0x0),
132 fDigitCalibrator(0x0),
142 // Unload and delete old mapping
143 AliCDBManager::Instance()->UnloadFromCache("MUON/Calib/Mapping");
144 AliCDBManager::Instance()->UnloadFromCache("MUON/Calib/DDLStore");
145 delete AliMpDDLStore::Instance();
146 delete AliMpSegmentation::Instance();
149 if ( ! AliMpCDB::LoadDDLStore() ) {
150 AliFatal("Could not access mapping from OCDB !");
153 // Load geometry data
154 fTransformer->LoadGeometryData();
158 //_____________________________________________________________________________
159 AliMUONReconstructor::~AliMUONReconstructor()
168 delete fTriggerCircuit;
169 delete fDigitCalibrator;
170 delete fCalibrationData;
171 delete fClusterServer;
172 delete fTriggerStore;
174 delete fClusterStore;
176 delete AliMpSegmentation::Instance(false);
177 delete AliMpDDLStore::Instance(false);
180 //_____________________________________________________________________________
182 AliMUONReconstructor::Calibrate(AliMUONVDigitStore& digitStore) const
184 /// Calibrate the digitStore
185 if (!fDigitCalibrator)
189 AliCodeTimerAuto(Form("%s::Calibrate(AliMUONVDigitStore*)",fDigitCalibrator->ClassName()))
190 fDigitCalibrator->Calibrate(digitStore);
193 //_____________________________________________________________________________
195 AliMUONReconstructor::ConvertDigits(AliRawReader* rawReader,
196 AliMUONVDigitStore* digitStore,
197 AliMUONVTriggerStore* triggerStore) const
199 /// Convert raw data into digit and trigger stores
202 // Skip reconstruction if event is Calibration
203 if ( GetRecoParam()->GetEventSpecie() == AliRecoParam::kCalib ) {
204 digitStore->Clear(); // Remove possible digits from previous event
205 triggerStore->Clear(); // Remove possible triggers from previous event
206 AliInfo("Calibration event: do not convert digits");
210 AliCodeTimerStart(Form("%s::Raw2Digits(AliRawReader*,AliMUONVDigitStore*,AliMUONVTriggerStore*)",
211 fDigitMaker->ClassName()))
212 fDigitMaker->Raw2Digits(rawReader,digitStore,triggerStore);
213 AliCodeTimerStop(Form("%s::Raw2Digits(AliRawReader*,AliMUONVDigitStore*,AliMUONVTriggerStore*)",
214 fDigitMaker->ClassName()))
215 Calibrate(*digitStore);
218 //_____________________________________________________________________________
220 AliMUONReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
222 /// convert raw data into a digit tree
225 Bool_t alone = ( TriggerStore() == 0 );
227 Bool_t ok = DigitStore()->Connect(*digitsTree,alone);
228 if ( TriggerStore() )
230 ok = ok && TriggerStore()->Connect(*digitsTree,kFALSE);
235 AliError("Could not make branches on TreeD");
239 ConvertDigits(rawReader,DigitStore(),TriggerStore());
240 AliCodeTimerStart("Fill digits")
242 AliCodeTimerStop("Fill digits")
243 DigitStore()->Clear();
247 //_____________________________________________________________________________
249 AliMUONReconstructor::CreateDigitMaker() const
251 /// Create (and create if necessary) the digit maker
252 if (fDigitMaker) return;
256 TString option = GetOption();
258 Bool_t enableErrorLogging = kFALSE;
260 if (option.Contains("ENABLEERRORLOGGING"))
262 enableErrorLogging = kTRUE;
265 fDigitMaker = new AliMUONDigitMaker(enableErrorLogging);
267 if ( option.Contains("SAVEDIGITS" ))
269 fDigitMaker->SetMakeTriggerDigits(kTRUE);
273 //_____________________________________________________________________________
275 AliMUONReconstructor::CreateTriggerCircuit() const
277 /// Return (and create if necessary) the trigger circuit object
278 if (fTriggerCircuit) return;
282 fTriggerCircuit = new AliMUONTriggerCircuit(fTransformer);
286 //_____________________________________________________________________________
288 AliMUONReconstructor::CreateTracker() const
290 /// Create the MUONTracker object
292 CreateTriggerCircuit();
294 CreateClusterServer();
296 AliMUONTracker* tracker(0x0);
298 if ( ! GetRecoParam()->CombineClusterTrackReco() )
300 tracker = new AliMUONTracker(GetRecoParam(),
309 tracker = new AliMUONTracker(GetRecoParam(),
321 //_____________________________________________________________________________
322 AliMUONVClusterFinder*
323 AliMUONReconstructor::CreateClusterFinder(const char* clusterFinderType)
325 /// Create a given cluster finder instance
327 AliCodeTimerAutoGeneral("")
329 AliMUONVClusterFinder* clusterFinder(0x0);
331 TString opt(clusterFinderType);
334 if ( strstr(opt,"PRECLUSTERV2") )
336 clusterFinder = new AliMUONPreClusterFinderV2;
338 else if ( strstr(opt,"PRECLUSTERV3") )
340 clusterFinder = new AliMUONPreClusterFinderV3;
342 else if ( strstr(opt,"PRECLUSTER") )
344 clusterFinder = new AliMUONPreClusterFinder;
346 else if ( strstr(opt,"PEAKCOG") )
348 clusterFinder = new AliMUONClusterFinderPeakCOG(kFALSE,new AliMUONPreClusterFinder);
350 else if ( strstr(opt,"PEAKFIT") )
352 clusterFinder = new AliMUONClusterFinderPeakFit(kFALSE,new AliMUONPreClusterFinder);
354 else if ( strstr(opt,"COG") )
356 clusterFinder = new AliMUONClusterFinderCOG(new AliMUONPreClusterFinder);
358 else if ( strstr(opt,"SIMPLEFITV3") )
360 clusterFinder = new AliMUONClusterFinderSimpleFit(new AliMUONClusterFinderCOG(new AliMUONPreClusterFinderV3));
362 else if ( strstr(opt,"SIMPLEFIT") )
364 clusterFinder = new AliMUONClusterFinderSimpleFit(new AliMUONClusterFinderCOG(new AliMUONPreClusterFinder));
366 else if ( strstr(opt,"MLEM:DRAW") )
368 clusterFinder = new AliMUONClusterFinderMLEM(kTRUE,new AliMUONPreClusterFinder);
370 else if ( strstr(opt,"MLEMV3") )
372 clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinderV3);
374 else if ( strstr(opt,"MLEMV2") )
376 clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinderV2);
378 else if ( strstr(opt,"MLEM") )
380 clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinder);
384 AliErrorClass(Form("clustering mode \"%s\" does not exist",opt.Data()));
388 return clusterFinder;
391 //_____________________________________________________________________________
393 AliMUONReconstructor::CreateClusterServer() const
395 /// Create cluster server
397 if ( fClusterServer ) return;
399 AliCodeTimerAuto("");
401 AliMUONVClusterFinder* clusterFinder = CreateClusterFinder(GetRecoParam()->GetClusteringMode());
403 if ( !clusterFinder ) return;
405 AliInfo(Form("Will use %s for clusterizing",clusterFinder->ClassName()));
407 fClusterServer = new AliMUONSimpleClusterServer(clusterFinder,*fTransformer);
410 //_____________________________________________________________________________
412 AliMUONReconstructor::CreateCalibrator() const
414 /// Create the calibrator
418 Int_t runNumber = AliCDBManager::Instance()->GetRun();
420 AliInfo("Calibration will occur.");
422 fCalibrationData = new AliMUONCalibrationData(runNumber);
423 if ( !fCalibrationData->IsValid() )
425 AliError("Could not retrieve calibrations !");
426 delete fCalibrationData;
427 fCalibrationData = 0x0;
431 // Check that we get all the calibrations we'll need
432 if ( !fCalibrationData->Pedestals() ||
433 !fCalibrationData->Gains() ||
434 !fCalibrationData->HV() )
436 AliFatal("Could not access all required calibration data");
439 TString opt(GetOption());
442 if ( strstr(opt,"NOSTATUSMAP") )
444 AliWarning("NOSTATUSMAP is obsolete");
447 TString calibMode = GetRecoParam()->GetCalibrationMode();
449 fDigitCalibrator = new AliMUONDigitCalibrator(*fCalibrationData,GetRecoParam(),calibMode.Data());
452 //_____________________________________________________________________________
454 AliMUONReconstructor::DigitStore() const
456 /// Return (and create if necessary) the digit container
459 TString sopt(GetOption());
462 AliInfo(Form("Options=%s",sopt.Data()));
464 if ( sopt.Contains("DIGITSTOREV1") )
466 fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV1");
468 else if ( sopt.Contains("DIGITSTOREV2R") )
470 fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2R");
472 else if ( sopt.Contains("DIGITSTOREV2S") )
474 fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2S");
477 if (!fDigitStore) fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2R");
479 AliInfo(Form("Will use %s to store digits during reconstruction",fDigitStore->ClassName()));
484 //_____________________________________________________________________________
486 AliMUONReconstructor::FillTreeR(AliMUONVTriggerStore* triggerStore,
487 TTree& clustersTree) const
489 /// Write the trigger and cluster information into TreeR
496 Bool_t alone(kTRUE); // is trigger the only info in TreeR ?
498 if ( ! GetRecoParam()->CombineClusterTrackReco() )
500 alone = kFALSE; // we'll get both tracker and trigger information in TreeR
505 ok = triggerStore->Connect(clustersTree,alone);
508 AliError("Could not create triggerStore branches in TreeR");
516 fClusterStore = new AliMUONClusterStoreV2;
519 CreateClusterServer();
521 TIter next(DigitStore()->CreateIterator());
522 fClusterServer->UseDigits(next,DigitStore());
526 AliDebug(1,Form("Doing full clusterization in local reconstruction using %s ",fClusterServer->ClassName()));
528 for ( Int_t i = 0; i < AliMpConstants::NofTrackingChambers(); ++i )
530 if (GetRecoParam()->UseChamber(i))
532 if ( ( i == 6 || i == 7 ) && GetRecoParam()->BypassSt4() ) continue;
533 if ( ( i == 8 || i == 9 ) && GetRecoParam()->BypassSt5() ) continue;
535 fClusterServer->Clusterize(i,*fClusterStore,area,GetRecoParam());
539 Bool_t cok = fClusterStore->Connect(clustersTree,alone);
541 if (!cok) AliError("Could not connect clusterStore to clusterTree");
543 AliDebug(1,Form("Number of clusters found = %d",fClusterStore->GetSize()));
545 StdoutToAliDebug(1,fClusterStore->Print());
548 if (ok) // at least one type of branches created successfully
553 if (fClusterStore) fClusterStore->Clear();
556 //_____________________________________________________________________________
558 AliMUONReconstructor::HasDigitConversion() const
560 /// We *do* have digit conversion, but we might advertise it only
561 /// if we want to save the digits.
563 TString opt(GetOption());
565 if ( opt.Contains("SAVEDIGITS" ) && !opt.Contains("NOLOCALRECONSTRUCTION") )
575 //_____________________________________________________________________________
577 AliMUONReconstructor::Reconstruct(AliRawReader* rawReader, TTree* clustersTree) const
579 /// This method is called by AliReconstruction if HasLocalReconstruction()==kTRUE AND
580 /// HasDigitConversion()==kFALSE
584 AliError("clustersTree is 0x0 !");
588 ConvertDigits(rawReader,DigitStore(),TriggerStore());
590 FillTreeR(TriggerStore(),*clustersTree);
593 //_____________________________________________________________________________
595 AliMUONReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
597 /// This method is called by AliReconstruction if HasLocalReconstruction()==kTRUE
598 /// AND HasDigitConversion()==kTRUE
604 if (!digitsTree || !clustersTree)
606 AliError(Form("Tree is null : digitsTree=%p clustersTree=%p",
607 digitsTree,clustersTree));
613 fDigitStore = AliMUONVDigitStore::Create(*digitsTree);
616 AliError(Form("Could not get DigitStore from %s",digitsTree->GetName()));
620 AliInfo(Form("Created %s from %s",fDigitStore->ClassName(),digitsTree->GetName()));
625 fTriggerStore = AliMUONVTriggerStore::Create(*digitsTree);
628 AliError(Form("Could not get TriggerStore from %s",digitsTree->GetName()));
632 AliInfo(Form("Created %s from %s",fTriggerStore->ClassName(),digitsTree->GetName()));
636 if (!fTriggerStore && !fDigitStore)
638 AliError("No store at all. Nothing to do.");
642 // insure we start with empty stores
645 fDigitStore->Clear();
646 Bool_t alone = ( fTriggerStore ? kFALSE : kTRUE );
647 Bool_t ok = fDigitStore->Connect(*digitsTree,alone);
650 AliError("Could not connect digitStore to digitsTree");
656 fTriggerStore->Clear();
657 Bool_t alone = ( fDigitStore ? kFALSE : kTRUE );
658 Bool_t ok = fTriggerStore->Connect(*digitsTree,alone);
661 AliError("Could not connect triggerStore to digitsTree");
666 digitsTree->GetEvent(0);
670 // Insure we got calibrated digits (if we reconstruct from pure simulated,
671 // i.e. w/o going through raw data, this will be the case)
672 TIter next(fDigitStore->CreateIterator());
673 AliMUONVDigit* digit = static_cast<AliMUONVDigit*>(next());
674 if (digit && !digit->IsCalibrated())
676 Calibrate(*fDigitStore);
680 FillTreeR(fTriggerStore,*clustersTree);
683 //_____________________________________________________________________________
684 AliMUONVTriggerStore*
685 AliMUONReconstructor::TriggerStore() const
687 /// Return (and create if necessary and allowed) the trigger container
688 TString sopt(GetOption());
691 if (sopt.Contains("TRIGGERDISABLE"))
693 delete fTriggerStore;
700 fTriggerStore = new AliMUONTriggerStoreV1;
703 return fTriggerStore;