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"
105 #include "AliMpArea.h"
106 #include "AliMpCDB.h"
107 #include "AliMpConstants.h"
108 #include "AliMpDDLStore.h"
109 #include "AliMpSegmentation.h"
111 #include "AliRawReader.h"
112 #include "AliCDBManager.h"
113 #include "AliCodeTimer.h"
115 #include "AliRunInfo.h"
117 #include <Riostream.h>
118 #include <TObjArray.h>
119 #include <TClonesArray.h>
124 ClassImp(AliMUONReconstructor)
127 //_____________________________________________________________________________
128 AliMUONReconstructor::AliMUONReconstructor() :
131 fTransformer(new AliMUONGeometryTransformer()),
133 fTriggerCircuit(0x0),
134 fCalibrationData(0x0),
135 fDigitCalibrator(0x0),
140 fTriggerProcessor(0x0)
146 // Unload mapping objects
147 // if they have been loaded from the obsolete OCDB mapping objects
149 if ( AliMpDDLStore::Instance(false) ) {
150 AliCDBManager::Instance()->UnloadFromCache("MUON/Calib/DDLStore");
151 delete AliMpDDLStore::Instance();
154 if ( AliMpSegmentation::Instance(false) ) {
155 AliCDBManager::Instance()->UnloadFromCache("MUON/Calib/Mapping");
156 delete AliMpSegmentation::Instance();
160 if ( ! AliMpCDB::LoadDDLStore() ) {
161 AliFatal("Could not access mapping from OCDB !");
164 // Load geometry data
165 fTransformer->LoadGeometryData();
169 //_____________________________________________________________________________
170 AliMUONReconstructor::~AliMUONReconstructor()
179 delete fTriggerCircuit;
180 delete fDigitCalibrator;
181 delete fCalibrationData;
182 delete fClusterServer;
183 delete fTriggerStore;
185 delete fClusterStore;
186 delete fTriggerProcessor;
188 delete AliMpSegmentation::Instance(false);
189 delete AliMpDDLStore::Instance(false);
192 //_____________________________________________________________________________
194 AliMUONReconstructor::Calibrate(AliMUONVDigitStore& digitStore) const
196 /// Calibrate the digitStore
197 if (!fDigitCalibrator)
201 AliCodeTimerAuto(Form("%s::Calibrate(AliMUONVDigitStore*)",fDigitCalibrator->ClassName()),0)
202 fDigitCalibrator->Calibrate(digitStore);
205 //_____________________________________________________________________________
207 AliMUONReconstructor::ConvertDigits(AliRawReader* rawReader,
208 AliMUONVDigitStore* digitStore,
209 AliMUONVTriggerStore* triggerStore) const
211 /// Convert raw data into digit and trigger stores
214 // Skip reconstruction if event is Calibration
215 if ( GetRecoParam()->GetEventSpecie() == AliRecoParam::kCalib ) {
216 digitStore->Clear(); // Remove possible digits from previous event
217 triggerStore->Clear(); // Remove possible triggers from previous event
218 AliInfo("Calibration event: do not convert digits");
222 AliCodeTimerStart(Form("%s::Raw2Digits(AliRawReader*,AliMUONVDigitStore*,AliMUONVTriggerStore*)",
223 fDigitMaker->ClassName()))
224 fDigitMaker->Raw2Digits(rawReader,digitStore,triggerStore);
225 AliCodeTimerStop(Form("%s::Raw2Digits(AliRawReader*,AliMUONVDigitStore*,AliMUONVTriggerStore*)",
226 fDigitMaker->ClassName()))
227 Calibrate(*digitStore);
230 //_____________________________________________________________________________
232 AliMUONReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
234 /// convert raw data into a digit tree
235 AliCodeTimerAuto("",0)
237 Bool_t alone = ( TriggerStore() == 0 );
239 Bool_t ok = DigitStore()->Connect(*digitsTree,alone);
240 if ( TriggerStore() )
242 ok = ok && TriggerStore()->Connect(*digitsTree,kFALSE);
247 AliError("Could not make branches on TreeD");
251 ConvertDigits(rawReader,DigitStore(),TriggerStore());
252 AliCodeTimerStart("Fill digits")
254 AliCodeTimerStop("Fill digits")
255 DigitStore()->Clear();
259 //_____________________________________________________________________________
261 AliMUONReconstructor::CreateDigitMaker() const
263 /// Create (and create if necessary) the digit maker
264 if (fDigitMaker) return;
266 AliCodeTimerAuto("",0)
268 TString option = GetOption();
270 Bool_t enableErrorLogging = kFALSE;
272 if (option.Contains("ENABLEERRORLOGGING"))
274 enableErrorLogging = kTRUE;
277 fDigitMaker = new AliMUONDigitMaker(enableErrorLogging);
280 // Always make trigger digits
281 // (needed when calculating trigger chamber efficiency)
282 fDigitMaker->SetMakeTriggerDigits(kTRUE);
284 if ( GetRecoParam()->TryRecover() )
286 fDigitMaker->SetTryRecover(kTRUE);
290 fDigitMaker->SetTryRecover(kFALSE);
294 //_____________________________________________________________________________
296 AliMUONReconstructor::CreateTriggerCircuit() const
298 /// Return (and create if necessary) the trigger circuit object
299 if (fTriggerCircuit) return;
301 AliCodeTimerAuto("",0)
303 fTriggerCircuit = new AliMUONTriggerCircuit(fTransformer);
307 //_____________________________________________________________________________
309 AliMUONReconstructor::CreateTracker() const
311 /// Create the MUONTracker object
313 CreateTriggerCircuit();
314 CreateClusterServer();
316 AliMUONTracker* tracker(0x0);
318 if ( ! GetRecoParam()->CombineClusterTrackReco() )
320 tracker = new AliMUONTracker(GetRecoParam(),
328 tracker = new AliMUONTracker(GetRecoParam(),
339 //_____________________________________________________________________________
340 AliMUONVClusterFinder*
341 AliMUONReconstructor::CreateClusterFinder(const char* clusterFinderType)
343 /// Create a given cluster finder instance
345 AliCodeTimerAutoGeneral("",0)
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("",0);
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::CreateCalibrationData() const
432 /// Create the calibrator
434 AliCodeTimerAuto("",0);
436 Int_t runNumber = AliCDBManager::Instance()->GetRun();
438 fCalibrationData = new AliMUONCalibrationData(runNumber);
439 if ( !fCalibrationData->IsValid() )
441 AliError("Could not retrieve calibrations !");
442 delete fCalibrationData;
443 fCalibrationData = 0x0;
447 // It is now time to check whether we have everything to proceed.
448 // What we need depends on whether both tracker and trigger
449 // are in the readout chain, and what specific "bad channel policy"
452 Bool_t kTracker(kFALSE);
453 Bool_t kTrigger(kFALSE);
455 const AliRunInfo* runInfo = GetRunInfo();
458 AliError("Could not get runinfo ?");
462 TString detectors(runInfo->GetActiveDetectors());
463 if (detectors.Contains("MUONTRK")) kTracker=kTRUE;
464 if (detectors.Contains("MUONTRG")) kTrigger=kTRUE;
467 AliInfo(Form("Run with MUON TRIGGER : %s and MUON TRACKER : %s",
468 kTrigger ? "YES":"NO" ,
469 kTracker ? "YES":"NO"));
473 // Check that we get all the calibrations we'll need
474 if ( !fCalibrationData->Pedestals() ||
475 !fCalibrationData->Gains() )
477 AliFatal(Form("Could not access all required calibration data (PED %p GAIN %p)",
478 fCalibrationData->Pedestals(),fCalibrationData->Gains()));
481 if ( !fCalibrationData->HV() )
483 // Special treatment of HV. We only break if the values
484 // are not there *AND* we cut on them.
485 UInt_t mask = GetRecoParam()->PadGoodnessMask();
486 TString smask(AliMUONPadStatusMaker::AsCondition(mask));
487 if ( smask.Contains("HV") )
489 AliFatal("Could not access all required calibration data (HV)");
495 //_____________________________________________________________________________
497 AliMUONReconstructor::CreateCalibrator() const
499 /// Create the calibrator
501 AliCodeTimerAuto("",0);
503 if ( ! fCalibrationData )
504 CreateCalibrationData();
506 AliInfo("Calibration will occur.");
508 TString opt(GetOption());
511 if ( strstr(opt,"NOSTATUSMAP") )
513 AliWarning("NOSTATUSMAP is obsolete");
516 TString calibMode = GetRecoParam()->GetCalibrationMode();
518 fDigitCalibrator = new AliMUONDigitCalibrator(*fCalibrationData,GetRecoParam(),calibMode.Data());
521 //_____________________________________________________________________________
523 AliMUONReconstructor::ResponseRemovingChambers(AliMUONVTriggerStore* triggerStore) const
525 /// Update trigger information with informatins obtained after
526 /// re-calculation of trigger response
527 AliCodeTimerAuto("",0);
529 if ( ! fCalibrationData )
530 CreateCalibrationData();
532 if ( ! fTriggerProcessor )
533 fTriggerProcessor = new AliMUONTriggerElectronics(fCalibrationData);
535 fTriggerProcessor->ResponseRemovingChambers(*triggerStore);
538 //_____________________________________________________________________________
540 AliMUONReconstructor::DigitStore() const
542 /// Return (and create if necessary) the digit container
545 TString sopt(GetOption());
548 AliInfo(Form("Options=%s",sopt.Data()));
550 if ( sopt.Contains("DIGITSTOREV1") )
552 fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV1");
554 else if ( sopt.Contains("DIGITSTOREV2R") )
556 fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2R");
558 else if ( sopt.Contains("DIGITSTOREV2S") )
560 fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2S");
563 if (!fDigitStore) fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2R");
565 AliInfo(Form("Will use %s to store digits during reconstruction",fDigitStore->ClassName()));
570 //_____________________________________________________________________________
572 AliMUONReconstructor::FillTreeR(AliMUONVTriggerStore* triggerStore,
573 TTree& clustersTree) const
575 /// Write the trigger and cluster information into TreeR
577 AliCodeTimerAuto("",0)
580 Bool_t alone(kTRUE); // is trigger the only info in TreeR ?
582 if ( ! GetRecoParam()->CombineClusterTrackReco() )
584 alone = kFALSE; // we'll get both tracker and trigger information in TreeR
589 ResponseRemovingChambers(triggerStore);
590 ok = triggerStore->Connect(clustersTree,alone);
593 AliError("Could not create triggerStore branches in TreeR");
601 fClusterStore = new AliMUONClusterStoreV2;
604 CreateClusterServer();
606 TIter next(DigitStore()->CreateIterator());
607 fClusterServer->UseDigits(next,DigitStore());
611 AliDebug(1,Form("Doing full clusterization in local reconstruction using %s ",fClusterServer->ClassName()));
613 for ( Int_t i = 0; i < AliMpConstants::NofTrackingChambers(); ++i )
615 if (GetRecoParam()->UseChamber(i))
617 if ( ( i == 6 || i == 7 ) && GetRecoParam()->BypassSt4() ) continue;
618 if ( ( i == 8 || i == 9 ) && GetRecoParam()->BypassSt5() ) continue;
620 fClusterServer->Clusterize(i,*fClusterStore,area,GetRecoParam());
624 Bool_t cok = fClusterStore->Connect(clustersTree,alone);
626 if (!cok) AliError("Could not connect clusterStore to clusterTree");
628 AliDebug(1,Form("Number of clusters found = %d",fClusterStore->GetSize()));
630 StdoutToAliDebug(1,fClusterStore->Print());
633 if (ok) // at least one type of branches created successfully
638 if (fClusterStore) fClusterStore->Clear();
641 //_____________________________________________________________________________
643 AliMUONReconstructor::HasDigitConversion() const
645 /// We *do* have digit conversion, but we might advertise it only
646 /// if we want to save the digits.
648 TString opt(GetOption());
650 if ( opt.Contains("SAVEDIGITS" ) && !opt.Contains("NOLOCALRECONSTRUCTION") )
660 //_____________________________________________________________________________
662 AliMUONReconstructor::Reconstruct(AliRawReader* rawReader, TTree* clustersTree) const
664 /// This method is called by AliReconstruction if HasLocalReconstruction()==kTRUE AND
665 /// HasDigitConversion()==kFALSE
669 AliError("clustersTree is 0x0 !");
673 ConvertDigits(rawReader,DigitStore(),TriggerStore());
675 FillTreeR(TriggerStore(),*clustersTree);
678 //_____________________________________________________________________________
680 AliMUONReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
682 /// This method is called by AliReconstruction if HasLocalReconstruction()==kTRUE
683 /// AND HasDigitConversion()==kTRUE
685 AliCodeTimerAuto("",0)
689 if (!digitsTree || !clustersTree)
691 AliError(Form("Tree is null : digitsTree=%p clustersTree=%p",
692 digitsTree,clustersTree));
698 fDigitStore = AliMUONVDigitStore::Create(*digitsTree);
701 AliError(Form("Could not get DigitStore from %s",digitsTree->GetName()));
705 AliInfo(Form("Created %s from %s",fDigitStore->ClassName(),digitsTree->GetName()));
710 fTriggerStore = AliMUONVTriggerStore::Create(*digitsTree);
713 AliError(Form("Could not get TriggerStore from %s",digitsTree->GetName()));
717 AliInfo(Form("Created %s from %s",fTriggerStore->ClassName(),digitsTree->GetName()));
721 if (!fTriggerStore && !fDigitStore)
723 AliError("No store at all. Nothing to do.");
727 // insure we start with empty stores
730 fDigitStore->Clear();
731 Bool_t alone = ( fTriggerStore ? kFALSE : kTRUE );
732 Bool_t ok = fDigitStore->Connect(*digitsTree,alone);
735 AliError("Could not connect digitStore to digitsTree");
741 fTriggerStore->Clear();
742 Bool_t alone = ( fDigitStore ? kFALSE : kTRUE );
743 Bool_t ok = fTriggerStore->Connect(*digitsTree,alone);
746 AliError("Could not connect triggerStore to digitsTree");
751 digitsTree->GetEvent(0);
755 // Insure we got calibrated digits (if we reconstruct from pure simulated,
756 // i.e. w/o going through raw data, this will be the case)
757 TIter next(fDigitStore->CreateIterator());
758 AliMUONVDigit* digit = static_cast<AliMUONVDigit*>(next());
759 if (digit && !digit->IsCalibrated())
761 Calibrate(*fDigitStore);
765 FillTreeR(fTriggerStore,*clustersTree);
768 //_____________________________________________________________________________
769 AliMUONVTriggerStore*
770 AliMUONReconstructor::TriggerStore() const
772 /// Return (and create if necessary and allowed) the trigger container
773 TString sopt(GetOption());
776 if (sopt.Contains("TRIGGERDISABLE"))
778 delete fTriggerStore;
785 fTriggerStore = new AliMUONTriggerStoreV1;
788 return fTriggerStore;