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 and delete old mapping
147 AliCDBManager::Instance()->UnloadFromCache("MUON/Calib/Mapping");
148 AliCDBManager::Instance()->UnloadFromCache("MUON/Calib/DDLStore");
149 delete AliMpDDLStore::Instance();
150 delete AliMpSegmentation::Instance();
153 if ( ! AliMpCDB::LoadDDLStore() ) {
154 AliFatal("Could not access mapping from OCDB !");
157 // Load geometry data
158 fTransformer->LoadGeometryData();
162 //_____________________________________________________________________________
163 AliMUONReconstructor::~AliMUONReconstructor()
172 delete fTriggerCircuit;
173 delete fDigitCalibrator;
174 delete fCalibrationData;
175 delete fClusterServer;
176 delete fTriggerStore;
178 delete fClusterStore;
179 delete fTriggerProcessor;
181 delete AliMpSegmentation::Instance(false);
182 delete AliMpDDLStore::Instance(false);
185 //_____________________________________________________________________________
187 AliMUONReconstructor::Calibrate(AliMUONVDigitStore& digitStore) const
189 /// Calibrate the digitStore
190 if (!fDigitCalibrator)
194 AliCodeTimerAuto(Form("%s::Calibrate(AliMUONVDigitStore*)",fDigitCalibrator->ClassName()),0)
195 fDigitCalibrator->Calibrate(digitStore);
198 //_____________________________________________________________________________
200 AliMUONReconstructor::ConvertDigits(AliRawReader* rawReader,
201 AliMUONVDigitStore* digitStore,
202 AliMUONVTriggerStore* triggerStore) const
204 /// Convert raw data into digit and trigger stores
207 // Skip reconstruction if event is Calibration
208 if ( GetRecoParam()->GetEventSpecie() == AliRecoParam::kCalib ) {
209 digitStore->Clear(); // Remove possible digits from previous event
210 triggerStore->Clear(); // Remove possible triggers from previous event
211 AliInfo("Calibration event: do not convert digits");
215 AliCodeTimerStart(Form("%s::Raw2Digits(AliRawReader*,AliMUONVDigitStore*,AliMUONVTriggerStore*)",
216 fDigitMaker->ClassName()))
217 fDigitMaker->Raw2Digits(rawReader,digitStore,triggerStore);
218 AliCodeTimerStop(Form("%s::Raw2Digits(AliRawReader*,AliMUONVDigitStore*,AliMUONVTriggerStore*)",
219 fDigitMaker->ClassName()))
220 Calibrate(*digitStore);
223 //_____________________________________________________________________________
225 AliMUONReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
227 /// convert raw data into a digit tree
228 AliCodeTimerAuto("",0)
230 Bool_t alone = ( TriggerStore() == 0 );
232 Bool_t ok = DigitStore()->Connect(*digitsTree,alone);
233 if ( TriggerStore() )
235 ok = ok && TriggerStore()->Connect(*digitsTree,kFALSE);
240 AliError("Could not make branches on TreeD");
244 ConvertDigits(rawReader,DigitStore(),TriggerStore());
245 AliCodeTimerStart("Fill digits")
247 AliCodeTimerStop("Fill digits")
248 DigitStore()->Clear();
252 //_____________________________________________________________________________
254 AliMUONReconstructor::CreateDigitMaker() const
256 /// Create (and create if necessary) the digit maker
257 if (fDigitMaker) return;
259 AliCodeTimerAuto("",0)
261 TString option = GetOption();
263 Bool_t enableErrorLogging = kFALSE;
265 if (option.Contains("ENABLEERRORLOGGING"))
267 enableErrorLogging = kTRUE;
270 fDigitMaker = new AliMUONDigitMaker(enableErrorLogging);
272 if ( option.Contains("SAVEDIGITS" ))
274 fDigitMaker->SetMakeTriggerDigits(kTRUE);
278 //_____________________________________________________________________________
280 AliMUONReconstructor::CreateTriggerCircuit() const
282 /// Return (and create if necessary) the trigger circuit object
283 if (fTriggerCircuit) return;
285 AliCodeTimerAuto("",0)
287 fTriggerCircuit = new AliMUONTriggerCircuit(fTransformer);
291 //_____________________________________________________________________________
293 AliMUONReconstructor::CreateTracker() const
295 /// Create the MUONTracker object
297 CreateTriggerCircuit();
299 CreateClusterServer();
301 AliMUONTracker* tracker(0x0);
303 if ( ! GetRecoParam()->CombineClusterTrackReco() )
305 tracker = new AliMUONTracker(GetRecoParam(),
314 tracker = new AliMUONTracker(GetRecoParam(),
326 //_____________________________________________________________________________
327 AliMUONVClusterFinder*
328 AliMUONReconstructor::CreateClusterFinder(const char* clusterFinderType)
330 /// Create a given cluster finder instance
332 AliCodeTimerAutoGeneral("",0)
334 AliMUONVClusterFinder* clusterFinder(0x0);
336 TString opt(clusterFinderType);
339 if ( strstr(opt,"PRECLUSTERV2") )
341 clusterFinder = new AliMUONPreClusterFinderV2;
343 else if ( strstr(opt,"PRECLUSTERV3") )
345 clusterFinder = new AliMUONPreClusterFinderV3;
347 else if ( strstr(opt,"PRECLUSTER") )
349 clusterFinder = new AliMUONPreClusterFinder;
351 else if ( strstr(opt,"PEAKCOG") )
353 clusterFinder = new AliMUONClusterFinderPeakCOG(kFALSE,new AliMUONPreClusterFinder);
355 else if ( strstr(opt,"PEAKFIT") )
357 clusterFinder = new AliMUONClusterFinderPeakFit(kFALSE,new AliMUONPreClusterFinder);
359 else if ( strstr(opt,"COG") )
361 clusterFinder = new AliMUONClusterFinderCOG(new AliMUONPreClusterFinder);
363 else if ( strstr(opt,"SIMPLEFITV3") )
365 clusterFinder = new AliMUONClusterFinderSimpleFit(new AliMUONClusterFinderCOG(new AliMUONPreClusterFinderV3));
367 else if ( strstr(opt,"SIMPLEFIT") )
369 clusterFinder = new AliMUONClusterFinderSimpleFit(new AliMUONClusterFinderCOG(new AliMUONPreClusterFinder));
371 else if ( strstr(opt,"MLEM:DRAW") )
373 clusterFinder = new AliMUONClusterFinderMLEM(kTRUE,new AliMUONPreClusterFinder);
375 else if ( strstr(opt,"MLEMV3") )
377 clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinderV3);
379 else if ( strstr(opt,"MLEMV2") )
381 clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinderV2);
383 else if ( strstr(opt,"MLEM") )
385 clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinder);
389 AliErrorClass(Form("clustering mode \"%s\" does not exist",opt.Data()));
393 return clusterFinder;
396 //_____________________________________________________________________________
398 AliMUONReconstructor::CreateClusterServer() const
400 /// Create cluster server
402 if ( fClusterServer ) return;
404 AliCodeTimerAuto("",0);
406 AliMUONVClusterFinder* clusterFinder = CreateClusterFinder(GetRecoParam()->GetClusteringMode());
408 if ( !clusterFinder ) return;
410 AliInfo(Form("Will use %s for clusterizing",clusterFinder->ClassName()));
412 fClusterServer = new AliMUONSimpleClusterServer(clusterFinder,*fTransformer);
415 //_____________________________________________________________________________
417 AliMUONReconstructor::CreateCalibrationData() const
419 /// Create the calibrator
421 AliCodeTimerAuto("",0);
423 Int_t runNumber = AliCDBManager::Instance()->GetRun();
425 fCalibrationData = new AliMUONCalibrationData(runNumber);
426 if ( !fCalibrationData->IsValid() )
428 AliError("Could not retrieve calibrations !");
429 delete fCalibrationData;
430 fCalibrationData = 0x0;
434 // It is now time to check whether we have everything to proceed.
435 // What we need depends on whether both tracker and trigger
436 // are in the readout chain, and what specific "bad channel policy"
439 Bool_t kTracker(kFALSE);
440 Bool_t kTrigger(kFALSE);
442 const AliRunInfo* runInfo = GetRunInfo();
445 AliError("Could not get runinfo ?")
449 TString detectors(runInfo->GetActiveDetectors());
450 if (detectors.Contains("MUONTRK")) kTracker=kTRUE;
451 if (detectors.Contains("MUONTRG")) kTrigger=kTRUE;
454 AliInfo(Form("Run with MUON TRIGGER : %s and MUON TRACKER : %s",
455 kTrigger ? "YES":"NO" ,
456 kTracker ? "YES":"NO"));
460 // Check that we get all the calibrations we'll need
461 if ( !fCalibrationData->Pedestals() ||
462 !fCalibrationData->Gains() )
464 AliFatal(Form("Could not access all required calibration data (PED %p GAIN %p)",
465 fCalibrationData->Pedestals(),fCalibrationData->Gains()));
468 if ( !fCalibrationData->HV() )
470 // Special treatment of HV. We only break if the values
471 // are not there *AND* we cut on them.
472 UInt_t mask = GetRecoParam()->PadGoodnessMask();
473 TString smask(AliMUONPadStatusMaker::AsCondition(mask));
474 if ( smask.Contains("HV") )
476 AliFatal("Could not access all required calibration data (HV)");
482 //_____________________________________________________________________________
484 AliMUONReconstructor::CreateCalibrator() const
486 /// Create the calibrator
488 AliCodeTimerAuto("",0);
490 if ( ! fCalibrationData )
491 CreateCalibrationData();
493 AliInfo("Calibration will occur.");
495 TString opt(GetOption());
498 if ( strstr(opt,"NOSTATUSMAP") )
500 AliWarning("NOSTATUSMAP is obsolete");
503 TString calibMode = GetRecoParam()->GetCalibrationMode();
505 fDigitCalibrator = new AliMUONDigitCalibrator(*fCalibrationData,GetRecoParam(),calibMode.Data());
508 //_____________________________________________________________________________
510 AliMUONReconstructor::ResponseRemovingChambers(AliMUONVTriggerStore* triggerStore) const
512 /// Update trigger information with informatins obtained after
513 /// re-calculation of trigger response
514 AliCodeTimerAuto("",0);
516 if ( ! fCalibrationData )
517 CreateCalibrationData();
519 if ( ! fTriggerProcessor )
520 fTriggerProcessor = new AliMUONTriggerElectronics(fCalibrationData);
522 fTriggerProcessor->ResponseRemovingChambers(*triggerStore);
525 //_____________________________________________________________________________
527 AliMUONReconstructor::DigitStore() const
529 /// Return (and create if necessary) the digit container
532 TString sopt(GetOption());
535 AliInfo(Form("Options=%s",sopt.Data()));
537 if ( sopt.Contains("DIGITSTOREV1") )
539 fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV1");
541 else if ( sopt.Contains("DIGITSTOREV2R") )
543 fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2R");
545 else if ( sopt.Contains("DIGITSTOREV2S") )
547 fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2S");
550 if (!fDigitStore) fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2R");
552 AliInfo(Form("Will use %s to store digits during reconstruction",fDigitStore->ClassName()));
557 //_____________________________________________________________________________
559 AliMUONReconstructor::FillTreeR(AliMUONVTriggerStore* triggerStore,
560 TTree& clustersTree) const
562 /// Write the trigger and cluster information into TreeR
564 AliCodeTimerAuto("",0)
569 Bool_t alone(kTRUE); // is trigger the only info in TreeR ?
571 if ( ! GetRecoParam()->CombineClusterTrackReco() )
573 alone = kFALSE; // we'll get both tracker and trigger information in TreeR
578 ResponseRemovingChambers(triggerStore);
579 ok = triggerStore->Connect(clustersTree,alone);
582 AliError("Could not create triggerStore branches in TreeR");
590 fClusterStore = new AliMUONClusterStoreV2;
593 CreateClusterServer();
595 TIter next(DigitStore()->CreateIterator());
596 fClusterServer->UseDigits(next,DigitStore());
600 AliDebug(1,Form("Doing full clusterization in local reconstruction using %s ",fClusterServer->ClassName()));
602 for ( Int_t i = 0; i < AliMpConstants::NofTrackingChambers(); ++i )
604 if (GetRecoParam()->UseChamber(i))
606 if ( ( i == 6 || i == 7 ) && GetRecoParam()->BypassSt4() ) continue;
607 if ( ( i == 8 || i == 9 ) && GetRecoParam()->BypassSt5() ) continue;
609 fClusterServer->Clusterize(i,*fClusterStore,area,GetRecoParam());
613 Bool_t cok = fClusterStore->Connect(clustersTree,alone);
615 if (!cok) AliError("Could not connect clusterStore to clusterTree");
617 AliDebug(1,Form("Number of clusters found = %d",fClusterStore->GetSize()));
619 StdoutToAliDebug(1,fClusterStore->Print());
622 if (ok) // at least one type of branches created successfully
627 if (fClusterStore) fClusterStore->Clear();
630 //_____________________________________________________________________________
632 AliMUONReconstructor::HasDigitConversion() const
634 /// We *do* have digit conversion, but we might advertise it only
635 /// if we want to save the digits.
637 TString opt(GetOption());
639 if ( opt.Contains("SAVEDIGITS" ) && !opt.Contains("NOLOCALRECONSTRUCTION") )
649 //_____________________________________________________________________________
651 AliMUONReconstructor::Reconstruct(AliRawReader* rawReader, TTree* clustersTree) const
653 /// This method is called by AliReconstruction if HasLocalReconstruction()==kTRUE AND
654 /// HasDigitConversion()==kFALSE
658 AliError("clustersTree is 0x0 !");
662 ConvertDigits(rawReader,DigitStore(),TriggerStore());
664 FillTreeR(TriggerStore(),*clustersTree);
667 //_____________________________________________________________________________
669 AliMUONReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
671 /// This method is called by AliReconstruction if HasLocalReconstruction()==kTRUE
672 /// AND HasDigitConversion()==kTRUE
674 AliCodeTimerAuto("",0)
678 if (!digitsTree || !clustersTree)
680 AliError(Form("Tree is null : digitsTree=%p clustersTree=%p",
681 digitsTree,clustersTree));
687 fDigitStore = AliMUONVDigitStore::Create(*digitsTree);
690 AliError(Form("Could not get DigitStore from %s",digitsTree->GetName()));
694 AliInfo(Form("Created %s from %s",fDigitStore->ClassName(),digitsTree->GetName()));
699 fTriggerStore = AliMUONVTriggerStore::Create(*digitsTree);
702 AliError(Form("Could not get TriggerStore from %s",digitsTree->GetName()));
706 AliInfo(Form("Created %s from %s",fTriggerStore->ClassName(),digitsTree->GetName()));
710 if (!fTriggerStore && !fDigitStore)
712 AliError("No store at all. Nothing to do.");
716 // insure we start with empty stores
719 fDigitStore->Clear();
720 Bool_t alone = ( fTriggerStore ? kFALSE : kTRUE );
721 Bool_t ok = fDigitStore->Connect(*digitsTree,alone);
724 AliError("Could not connect digitStore to digitsTree");
730 fTriggerStore->Clear();
731 Bool_t alone = ( fDigitStore ? kFALSE : kTRUE );
732 Bool_t ok = fTriggerStore->Connect(*digitsTree,alone);
735 AliError("Could not connect triggerStore to digitsTree");
740 digitsTree->GetEvent(0);
744 // Insure we got calibrated digits (if we reconstruct from pure simulated,
745 // i.e. w/o going through raw data, this will be the case)
746 TIter next(fDigitStore->CreateIterator());
747 AliMUONVDigit* digit = static_cast<AliMUONVDigit*>(next());
748 if (digit && !digit->IsCalibrated())
750 Calibrate(*fDigitStore);
754 FillTreeR(fTriggerStore,*clustersTree);
757 //_____________________________________________________________________________
758 AliMUONVTriggerStore*
759 AliMUONReconstructor::TriggerStore() const
761 /// Return (and create if necessary and allowed) the trigger container
762 TString sopt(GetOption());
765 if (sopt.Contains("TRIGGERDISABLE"))
767 delete fTriggerStore;
774 fTriggerStore = new AliMUONTriggerStoreV1;
777 return fTriggerStore;