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 fCalibrationData;
170 delete fDigitCalibrator;
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 AliCodeTimerStart(Form("%s::Raw2Digits(AliRawReader*,AliMUONVDigitStore*,AliMUONVTriggerStore*)",
203 fDigitMaker->ClassName()))
204 fDigitMaker->Raw2Digits(rawReader,digitStore,triggerStore);
205 AliCodeTimerStop(Form("%s::Raw2Digits(AliRawReader*,AliMUONVDigitStore*,AliMUONVTriggerStore*)",
206 fDigitMaker->ClassName()))
207 Calibrate(*digitStore);
210 //_____________________________________________________________________________
212 AliMUONReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
214 /// convert raw data into a digit tree
217 Bool_t alone = ( TriggerStore() == 0 );
219 Bool_t ok = DigitStore()->Connect(*digitsTree,alone);
220 if ( TriggerStore() )
222 ok = ok && TriggerStore()->Connect(*digitsTree,kFALSE);
227 AliError("Could not make branches on TreeD");
231 ConvertDigits(rawReader,DigitStore(),TriggerStore());
232 AliCodeTimerStart("Fill digits")
234 AliCodeTimerStop("Fill digits")
235 DigitStore()->Clear();
239 //_____________________________________________________________________________
241 AliMUONReconstructor::CreateDigitMaker() const
243 /// Create (and create if necessary) the digit maker
244 if (fDigitMaker) return;
248 TString option = GetOption();
250 Bool_t enableErrorLogging = kFALSE;
252 if (option.Contains("ENABLEERRORLOGGING"))
254 enableErrorLogging = kTRUE;
257 fDigitMaker = new AliMUONDigitMaker(enableErrorLogging);
259 if ( option.Contains("SAVEDIGITS" ))
261 fDigitMaker->SetMakeTriggerDigits(kTRUE);
265 //_____________________________________________________________________________
267 AliMUONReconstructor::CreateTriggerCircuit() const
269 /// Return (and create if necessary) the trigger circuit object
270 if (fTriggerCircuit) return;
274 fTriggerCircuit = new AliMUONTriggerCircuit(fTransformer);
278 //_____________________________________________________________________________
280 AliMUONReconstructor::CreateTracker() const
282 /// Create the MUONTracker object
284 CreateTriggerCircuit();
286 CreateClusterServer();
288 AliMUONTracker* tracker(0x0);
290 if ( ! GetRecoParam()->CombineClusterTrackReco() )
292 tracker = new AliMUONTracker(GetRecoParam(),
301 tracker = new AliMUONTracker(GetRecoParam(),
313 //_____________________________________________________________________________
314 AliMUONVClusterFinder*
315 AliMUONReconstructor::CreateClusterFinder(const char* clusterFinderType)
317 /// Create a given cluster finder instance
319 AliCodeTimerAutoGeneral("")
321 AliMUONVClusterFinder* clusterFinder(0x0);
323 TString opt(clusterFinderType);
326 if ( strstr(opt,"PRECLUSTERV2") )
328 clusterFinder = new AliMUONPreClusterFinderV2;
330 else if ( strstr(opt,"PRECLUSTERV3") )
332 clusterFinder = new AliMUONPreClusterFinderV3;
334 else if ( strstr(opt,"PRECLUSTER") )
336 clusterFinder = new AliMUONPreClusterFinder;
338 else if ( strstr(opt,"PEAKCOG") )
340 clusterFinder = new AliMUONClusterFinderPeakCOG(kFALSE,new AliMUONPreClusterFinder);
342 else if ( strstr(opt,"PEAKFIT") )
344 clusterFinder = new AliMUONClusterFinderPeakFit(kFALSE,new AliMUONPreClusterFinder);
346 else if ( strstr(opt,"COG") )
348 clusterFinder = new AliMUONClusterFinderCOG(new AliMUONPreClusterFinder);
350 else if ( strstr(opt,"SIMPLEFITV3") )
352 clusterFinder = new AliMUONClusterFinderSimpleFit(new AliMUONClusterFinderCOG(new AliMUONPreClusterFinderV3));
354 else if ( strstr(opt,"SIMPLEFIT") )
356 clusterFinder = new AliMUONClusterFinderSimpleFit(new AliMUONClusterFinderCOG(new AliMUONPreClusterFinder));
358 else if ( strstr(opt,"MLEM:DRAW") )
360 clusterFinder = new AliMUONClusterFinderMLEM(kTRUE,new AliMUONPreClusterFinder);
362 else if ( strstr(opt,"MLEMV3") )
364 clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinderV3);
366 else if ( strstr(opt,"MLEMV2") )
368 clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinderV2);
370 else if ( strstr(opt,"MLEM") )
372 clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinder);
376 AliErrorClass(Form("clustering mode \"%s\" does not exist",opt.Data()));
380 return clusterFinder;
383 //_____________________________________________________________________________
385 AliMUONReconstructor::CreateClusterServer() const
387 /// Create cluster server
389 if ( fClusterServer ) return;
391 AliCodeTimerAuto("");
393 AliMUONVClusterFinder* clusterFinder = CreateClusterFinder(GetRecoParam()->GetClusteringMode());
395 if ( !clusterFinder ) return;
397 AliInfo(Form("Will use %s for clusterizing",clusterFinder->ClassName()));
399 fClusterServer = new AliMUONSimpleClusterServer(clusterFinder,*fTransformer);
402 //_____________________________________________________________________________
404 AliMUONReconstructor::CreateCalibrator() const
406 /// Create the calibrator
410 Int_t runNumber = AliCDBManager::Instance()->GetRun();
412 AliInfo("Calibration will occur.");
414 fCalibrationData = new AliMUONCalibrationData(runNumber);
415 if ( !fCalibrationData->IsValid() )
417 AliError("Could not retrieve calibrations !");
418 delete fCalibrationData;
419 fCalibrationData = 0x0;
423 // Check that we get all the calibrations we'll need
424 if ( !fCalibrationData->Pedestals() ||
425 !fCalibrationData->Gains() ||
426 !fCalibrationData->HV() )
428 AliFatal("Could not access all required calibration data");
431 TString opt(GetOption());
434 if ( strstr(opt,"NOSTATUSMAP") )
436 AliWarning("NOSTATUSMAP is obsolete");
439 TString calibMode = GetRecoParam()->GetCalibrationMode();
441 fDigitCalibrator = new AliMUONDigitCalibrator(*fCalibrationData,GetRecoParam(),calibMode.Data());
444 //_____________________________________________________________________________
446 AliMUONReconstructor::DigitStore() const
448 /// Return (and create if necessary) the digit container
451 TString sopt(GetOption());
454 AliInfo(Form("Options=%s",sopt.Data()));
456 if ( sopt.Contains("DIGITSTOREV1") )
458 fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV1");
460 else if ( sopt.Contains("DIGITSTOREV2R") )
462 fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2R");
464 else if ( sopt.Contains("DIGITSTOREV2S") )
466 fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2S");
469 if (!fDigitStore) fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2R");
471 AliInfo(Form("Will use %s to store digits during reconstruction",fDigitStore->ClassName()));
476 //_____________________________________________________________________________
478 AliMUONReconstructor::FillTreeR(AliMUONVTriggerStore* triggerStore,
479 TTree& clustersTree) const
481 /// Write the trigger and cluster information into TreeR
488 Bool_t alone(kTRUE); // is trigger the only info in TreeR ?
490 if ( ! GetRecoParam()->CombineClusterTrackReco() )
492 alone = kFALSE; // we'll get both tracker and trigger information in TreeR
497 ok = triggerStore->Connect(clustersTree,alone);
500 AliError("Could not create triggerStore branches in TreeR");
508 fClusterStore = new AliMUONClusterStoreV2;
511 CreateClusterServer();
513 TIter next(DigitStore()->CreateIterator());
514 fClusterServer->UseDigits(next,DigitStore());
518 AliDebug(1,Form("Doing full clusterization in local reconstruction using %s ",fClusterServer->ClassName()));
520 for ( Int_t i = 0; i < AliMpConstants::NofTrackingChambers(); ++i )
522 if (GetRecoParam()->UseChamber(i))
524 if ( ( i == 6 || i == 7 ) && GetRecoParam()->BypassSt4() ) continue;
525 if ( ( i == 8 || i == 9 ) && GetRecoParam()->BypassSt5() ) continue;
527 fClusterServer->Clusterize(i,*fClusterStore,area,GetRecoParam());
531 Bool_t cok = fClusterStore->Connect(clustersTree,alone);
533 if (!cok) AliError("Could not connect clusterStore to clusterTree");
535 AliDebug(1,Form("Number of clusters found = %d",fClusterStore->GetSize()));
537 StdoutToAliDebug(1,fClusterStore->Print());
540 if (ok) // at least one type of branches created successfully
545 if (fClusterStore) fClusterStore->Clear();
548 //_____________________________________________________________________________
550 AliMUONReconstructor::HasDigitConversion() const
552 /// We *do* have digit conversion, but we might advertise it only
553 /// if we want to save the digits.
555 TString opt(GetOption());
557 if ( opt.Contains("SAVEDIGITS" ) && !opt.Contains("NOLOCALRECONSTRUCTION") )
567 //_____________________________________________________________________________
569 AliMUONReconstructor::Reconstruct(AliRawReader* rawReader, TTree* clustersTree) const
571 /// This method is called by AliReconstruction if HasLocalReconstruction()==kTRUE AND
572 /// HasDigitConversion()==kFALSE
576 AliError("clustersTree is 0x0 !");
580 ConvertDigits(rawReader,DigitStore(),TriggerStore());
582 FillTreeR(TriggerStore(),*clustersTree);
585 //_____________________________________________________________________________
587 AliMUONReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
589 /// This method is called by AliReconstruction if HasLocalReconstruction()==kTRUE
590 /// AND HasDigitConversion()==kTRUE
596 if (!digitsTree || !clustersTree)
598 AliError(Form("Tree is null : digitsTree=%p clustersTree=%p",
599 digitsTree,clustersTree));
605 fDigitStore = AliMUONVDigitStore::Create(*digitsTree);
608 AliError(Form("Could not get DigitStore from %s",digitsTree->GetName()));
612 AliInfo(Form("Created %s from %s",fDigitStore->ClassName(),digitsTree->GetName()));
617 fTriggerStore = AliMUONVTriggerStore::Create(*digitsTree);
620 AliError(Form("Could not get TriggerStore from %s",digitsTree->GetName()));
624 AliInfo(Form("Created %s from %s",fTriggerStore->ClassName(),digitsTree->GetName()));
628 if (!fTriggerStore && !fDigitStore)
630 AliError("No store at all. Nothing to do.");
634 // insure we start with empty stores
637 fDigitStore->Clear();
638 Bool_t alone = ( fTriggerStore ? kFALSE : kTRUE );
639 Bool_t ok = fDigitStore->Connect(*digitsTree,alone);
642 AliError("Could not connect digitStore to digitsTree");
648 fTriggerStore->Clear();
649 Bool_t alone = ( fDigitStore ? kFALSE : kTRUE );
650 Bool_t ok = fTriggerStore->Connect(*digitsTree,alone);
653 AliError("Could not connect triggerStore to digitsTree");
658 digitsTree->GetEvent(0);
662 // Insure we got calibrated digits (if we reconstruct from pure simulated,
663 // i.e. w/o going through raw data, this will be the case)
664 TIter next(fDigitStore->CreateIterator());
665 AliMUONVDigit* digit = static_cast<AliMUONVDigit*>(next());
666 if (digit && !digit->IsCalibrated())
668 Calibrate(*fDigitStore);
672 FillTreeR(fTriggerStore,*clustersTree);
675 //_____________________________________________________________________________
676 AliMUONVTriggerStore*
677 AliMUONReconstructor::TriggerStore() const
679 /// Return (and create if necessary and allowed) the trigger container
680 TString sopt(GetOption());
683 if (sopt.Contains("TRIGGERDISABLE"))
685 delete fTriggerStore;
692 fTriggerStore = new AliMUONTriggerStoreV1;
695 return fTriggerStore;