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 behavior of the MUON reconstruction can be changed, besides
23 /// the usual methods found in AliReconstruction (e.g. to disable tracking)
24 /// by using AliReconstruction::SetOption("MUON",options)
25 /// where options should be a space separated string.
27 /// Valid options are :
29 /// SAVEDIGITS : if you want to save in the TreeD the *calibrated* digits
30 /// that are used for the clustering
32 /// SIMPLEFIT : use the AliMUONClusterFinderSimpleFit clusterizer
34 /// AZ : use the AliMUONClusterFinderAZ clusterizer (default)
36 /// MLEM : another implementation of AZ, where preclustering is external
37 /// MLEMV3 : MLEM with preclustering=PRECLUSTERV2
38 /// MLEMV3 : MLEM with preclustering=PRECLUSTERV3
40 /// PRECLUSTER : use only AliMUONPreClusterFinder. Only for debug as
41 /// the produced clusters do not have a position, hence the tracking will not
43 /// PRECLUSTERV2 : another version of the preclustering
44 /// PRECLUSTERV3 : yet another version of the preclustering
46 /// COG : use AliMUONClusterFinderCOG clusterizer. Not really a production
47 /// option either, as center-of-gravity is generally not a good estimate
48 /// of the cluster position...
50 /// NOCLUSTERING : bypass completely the clustering stage
52 /// NOSTATUSMAP : disable the computation and usage of the pad status map. Only
55 /// NOLOCALRECONSTRUCTION : for debug, to disable local reconstruction (and hence
56 /// "recover" old behavior)
58 /// TRIGGERDISABLE : disable the treatment of MUON trigger
60 /// DIGITSTOREV1 : use the V1 implementation of the digitstore
61 /// DIGITSTOREV2R : use the V2R implementation of the digitstore
63 /// \author Laurent Aphecetche, Subatech
64 //-----------------------------------------------------------------------------
66 #include "AliMUONReconstructor.h"
68 #include "AliCDBManager.h"
70 #include "AliMUONCalibrationData.h"
71 #include "AliMUONClusterFinderCOG.h"
72 #include "AliMUONClusterFinderMLEM.h"
73 #include "AliMUONClusterFinderSimpleFit.h"
74 #include "AliMUONClusterFinderAZ.h"
75 #include "AliMUONClusterReconstructor.h"
76 #include "AliMUONClusterStoreV1.h"
77 #include "AliMUONConstants.h"
78 #include "AliMUONDigitCalibrator.h"
79 #include "AliMUONDigitMaker.h"
80 #include "AliMUONDigitStoreV1.h"
81 #include "AliMUONDigitStoreV2R.h"
82 #include "AliMUONGeometryTransformer.h"
83 #include "AliMUONPreClusterFinder.h"
84 #include "AliMUONPreClusterFinderV2.h"
85 #include "AliMUONPreClusterFinderV3.h"
86 #include "AliMUONTracker.h"
87 #include "AliMUONVTrackStore.h"
88 #include "AliMUONTriggerChamberEff.h"
89 #include "AliMUONTriggerCircuit.h"
90 #include "AliMUONTriggerCrateStore.h"
91 #include "AliMUONTriggerStoreV1.h"
92 #include "AliMUONVClusterFinder.h"
94 #include "AliRawReader.h"
95 #include "AliCodeTimer.h"
96 #include <Riostream.h>
97 #include <TClonesArray.h>
100 //#include "AliCodeTimer.h"
102 ClassImp(AliMUONReconstructor)
105 //_____________________________________________________________________________
106 AliMUONReconstructor::AliMUONReconstructor() :
110 fTransformer(new AliMUONGeometryTransformer()),
112 fTriggerCircuit(0x0),
113 fCalibrationData(0x0),
114 fDigitCalibrator(0x0),
115 fClusterReconstructor(0x0),
123 // Load geometry data
124 fTransformer->LoadGeometryData();
127 if ( ! AliMpCDB::LoadMpSegmentation() )
129 AliFatal("Could not access mapping from OCDB !");
133 if ( ! AliMpCDB::LoadDDLStore() )
135 AliFatal("Could not access DDL Store from OCDB !");
141 //_____________________________________________________________________________
142 AliMUONReconstructor::~AliMUONReconstructor()
148 delete fCrateManager;
149 delete fTriggerCircuit;
150 delete fCalibrationData;
151 delete fDigitCalibrator;
152 delete fClusterReconstructor;
153 delete fClusterStore;
154 delete fTriggerStore;
156 delete fTrigChamberEff;
159 //_____________________________________________________________________________
161 AliMUONReconstructor::Calibrate(AliMUONVDigitStore& digitStore) const
163 /// Calibrate the digitStore
164 if (!fDigitCalibrator)
168 AliCodeTimerAuto(Form("%s::Calibrate(AliMUONVDigitStore*)",fDigitCalibrator->ClassName()))
169 fDigitCalibrator->Calibrate(digitStore);
172 //_____________________________________________________________________________
174 AliMUONReconstructor::Clusterize(const AliMUONVDigitStore& digitStore,
175 AliMUONVClusterStore& clusterStore) const
177 /// Creates clusters from digits.
179 TString sopt(GetOption());
181 if ( sopt.Contains("NOCLUSTERING") ) return;
183 if (!fClusterReconstructor)
185 CreateClusterReconstructor();
188 AliCodeTimerAuto(Form("%s::Digits2Clusters(const AliMUONVDigitStore&,AliMUONVClusterStore&)",
189 fClusterReconstructor->ClassName()))
190 fClusterReconstructor->Digits2Clusters(digitStore,clusterStore);
193 //_____________________________________________________________________________
194 AliMUONVClusterStore*
195 AliMUONReconstructor::ClusterStore() const
197 /// Return (and create if necessary) the cluster container
200 fClusterStore = new AliMUONClusterStoreV1;
202 return fClusterStore;
205 //_____________________________________________________________________________
207 AliMUONReconstructor::ConvertDigits(AliRawReader* rawReader,
208 AliMUONVDigitStore* digitStore,
209 AliMUONVTriggerStore* triggerStore) const
211 /// Convert raw data into digit and trigger stores
214 AliCodeTimerStart(Form("%s::Raw2Digits(AliRawReader*,AliMUONVDigitStore*,AliMUONVTriggerStore*)",
215 fDigitMaker->ClassName()))
216 fDigitMaker->Raw2Digits(rawReader,digitStore,triggerStore);
217 AliCodeTimerStop(Form("%s::Raw2Digits(AliRawReader*,AliMUONVDigitStore*,AliMUONVTriggerStore*)",
218 fDigitMaker->ClassName()))
219 Calibrate(*digitStore);
222 //_____________________________________________________________________________
224 AliMUONReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
226 /// convert raw data into a digit tree
228 Bool_t alone = ( TriggerStore() == 0 );
230 Bool_t ok = DigitStore()->Connect(*digitsTree,alone);
231 if ( TriggerStore() )
233 ok = ok && TriggerStore()->Connect(*digitsTree,kFALSE);
238 AliError("Could not make branches on TreeD");
242 ConvertDigits(rawReader,DigitStore(),TriggerStore());
244 DigitStore()->Clear();
248 //_____________________________________________________________________________
249 AliMUONTriggerCrateStore*
250 AliMUONReconstructor::CrateManager() const
252 /// Return (and create if necessary) the trigger crate store
253 if (fCrateManager) return fCrateManager;
254 fCrateManager = new AliMUONTriggerCrateStore;
255 fCrateManager->ReadFromFile();
256 return fCrateManager;
259 //_____________________________________________________________________________
261 AliMUONReconstructor::CreateDigitMaker() const
263 /// Create (and create if necessary) the digit maker
264 if (fDigitMaker) return;
268 fDigitMaker = new AliMUONDigitMaker;
271 //_____________________________________________________________________________
273 AliMUONReconstructor::CreateTriggerCircuit() const
275 /// Return (and create if necessary) the trigger circuit object
276 if (fTriggerCircuit) return;
280 fTriggerCircuit = new AliMUONTriggerCircuit(fTransformer);
284 //_____________________________________________________________________________
286 AliMUONReconstructor::CreateTriggerChamberEff() const
288 /// Create (and create if necessary) the trigger chamber efficiency class
289 if (fTrigChamberEff) return;
293 fTrigChamberEff = new AliMUONTriggerChamberEff(fTransformer,fDigitMaker,kTRUE);
294 //fTrigChamberEff->SetDebugLevel(1);
297 //_____________________________________________________________________________
299 AliMUONReconstructor::CreateTracker() const
301 /// Create the MUONTracker object
302 /// The MUONTracker is passed the GetOption(), i.e. our own options
304 CreateTriggerCircuit();
306 CreateTriggerChamberEff();
308 AliMUONTracker* tracker = new AliMUONTracker(fDigitMaker,fTransformer,fTriggerCircuit,fTrigChamberEff);
309 tracker->SetOption(GetOption());
314 //_____________________________________________________________________________
316 AliMUONReconstructor::CreateClusterReconstructor() const
318 /// Create cluster reconstructor, depending on GetOption()
324 AliMUONVClusterFinder* clusterFinder(0x0);
326 TString opt(GetOption());
329 if ( strstr(opt,"PRECLUSTERV2") )
331 clusterFinder = new AliMUONPreClusterFinderV2;
333 else if ( strstr(opt,"PRECLUSTERV3") )
335 clusterFinder = new AliMUONPreClusterFinderV3;
337 else if ( strstr(opt,"PRECLUSTER") )
339 clusterFinder = new AliMUONPreClusterFinder;
341 else if ( strstr(opt,"COG") )
343 clusterFinder = new AliMUONClusterFinderCOG(new AliMUONPreClusterFinder);
345 else if ( strstr(opt,"SIMPLEFITV3") )
347 clusterFinder = new AliMUONClusterFinderSimpleFit(new AliMUONClusterFinderCOG(new AliMUONPreClusterFinderV3));
349 else if ( strstr(opt,"SIMPLEFIT") )
351 clusterFinder = new AliMUONClusterFinderSimpleFit(new AliMUONClusterFinderCOG(new AliMUONPreClusterFinder));
353 else if ( strstr(opt,"MLEM:DRAW") )
355 clusterFinder = new AliMUONClusterFinderMLEM(kTRUE,new AliMUONPreClusterFinder);
357 else if ( strstr(opt,"MLEMV3") )
359 clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinderV3);
361 else if ( strstr(opt,"MLEMV2") )
363 clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinderV2);
365 else if ( strstr(opt,"MLEM") )
367 clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinder);
369 else if ( strstr(opt,"AZ") )
371 clusterFinder = new AliMUONClusterFinderAZ;
375 // default is currently AZ
376 clusterFinder = new AliMUONClusterFinderAZ;
381 AliInfo(Form("Will use %s for clusterizing",clusterFinder->ClassName()));
384 fClusterReconstructor = new AliMUONClusterReconstructor(clusterFinder,fTransformer);
387 //_____________________________________________________________________________
389 AliMUONReconstructor::CreateCalibrator() const
391 /// Create the calibrator
395 Int_t runNumber = AliCDBManager::Instance()->GetRun();
397 AliInfo("Calibration will occur.");
399 fCalibrationData = new AliMUONCalibrationData(runNumber);
400 if ( !fCalibrationData->IsValid() )
402 AliError("Could not retrieve calibrations !");
403 delete fCalibrationData;
404 fCalibrationData = 0x0;
408 // Check that we get all the calibrations we'll need
409 if ( !fCalibrationData->Pedestals() ||
410 !fCalibrationData->Gains() ||
411 !fCalibrationData->HV() )
413 AliFatal("Could not access all required calibration data");
416 TString opt(GetOption());
418 Bool_t statusMap(kTRUE);
420 if ( strstr(opt,"NOSTATUSMAP") )
422 AliWarning("Disconnecting status map : SHOULD BE USED FOR DEBUG ONLY. NOT FOR PRODUCTION !!!");
425 fDigitCalibrator = new AliMUONDigitCalibrator(*fCalibrationData,statusMap);
428 //_____________________________________________________________________________
430 AliMUONReconstructor::DigitStore() const
432 /// Return (and create if necessary) the digit container
435 TString sopt(GetOption());
438 AliInfo(Form("Options=%s",sopt.Data()));
440 if ( sopt.Contains("DIGITSTOREV1") )
442 fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV1");
444 else if ( sopt.Contains("DIGITSTOREV2R") )
446 fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2R");
448 else if ( sopt.Contains("DIGITSTOREV2S") )
450 fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2S");
453 if (!fDigitStore) fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2R");
455 AliInfo(Form("Will use %s to store digits during reconstruction",fDigitStore->ClassName()));
460 //_____________________________________________________________________________
462 AliMUONReconstructor::FillTreeR(AliMUONVTriggerStore* triggerStore,
463 AliMUONVClusterStore* clusterStore,
464 TTree& clustersTree) const
466 /// Write the trigger and cluster information into TreeR
475 Bool_t alone = ( clusterStore ? kFALSE : kTRUE );
476 ok = triggerStore->Connect(clustersTree,alone);
479 AliError("Could not create triggerStore branches in TreeR");
485 Bool_t alone = ( triggerStore ? kFALSE : kTRUE );
486 ok = clusterStore->Connect(clustersTree,alone);
489 AliError("Could not create triggerStore branches in TreeR");
493 if (ok) // at least one type of branches created successfully
499 //_____________________________________________________________________________
501 AliMUONReconstructor::HasDigitConversion() const
503 /// We *do* have digit conversion, but we might advertise it only
504 /// if we want to save the digits.
506 TString opt(GetOption());
508 if ( opt.Contains("SAVEDIGITS" ) && !opt.Contains("NOLOCALRECONSTRUCTION") )
518 //_____________________________________________________________________________
520 AliMUONReconstructor::Reconstruct(AliRawReader* rawReader, TTree* clustersTree) const
522 /// This method is called by AliReconstruction if HasLocalReconstruction()==kTRUE AND
523 /// HasDigitConversion()==kFALSE
527 AliError("clustersTree is 0x0 !");
531 ConvertDigits(rawReader,DigitStore(),TriggerStore());
532 Clusterize(*(DigitStore()),*(ClusterStore()));
534 FillTreeR(TriggerStore(),ClusterStore(),*clustersTree);
537 //_____________________________________________________________________________
539 AliMUONReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
541 /// This method is called by AliReconstruction if HasLocalReconstruction()==kTRUE
542 /// AND HasDigitConversion()==kTRUE
544 // AliCodeTimerAuto("(TTree*,TTree*)")
548 if (!digitsTree || !clustersTree)
550 AliError(Form("Tree is null : digitsTree=%p clustersTree=%p",
551 digitsTree,clustersTree));
557 fDigitStore = AliMUONVDigitStore::Create(*digitsTree);
560 AliError(Form("Could not get DigitStore from %s",digitsTree->GetName()));
564 AliInfo(Form("Created %s from %s",fDigitStore->ClassName(),digitsTree->GetName()));
569 fTriggerStore = AliMUONVTriggerStore::Create(*digitsTree);
572 AliError(Form("Could not get TriggerStore from %s",digitsTree->GetName()));
576 AliInfo(Form("Created %s from %s",fTriggerStore->ClassName(),digitsTree->GetName()));
580 if (!fTriggerStore && !fDigitStore)
582 AliError("No store at all. Nothing to do.");
586 // insure we start with empty stores
589 fDigitStore->Clear();
590 Bool_t alone = ( fTriggerStore ? kFALSE : kTRUE );
591 Bool_t ok = fDigitStore->Connect(*digitsTree,alone);
594 AliError("Could not connect digitStore to digitsTree");
600 fTriggerStore->Clear();
601 Bool_t alone = ( fDigitStore ? kFALSE : kTRUE );
602 Bool_t ok = fTriggerStore->Connect(*digitsTree,alone);
605 AliError("Could not connect triggerStore to digitsTree");
610 digitsTree->GetEvent(0);
614 // Insure we got calibrated digits (if we reconstruct from pure simulated,
615 // i.e. w/o going through raw data, this will be the case)
616 TIter next(fDigitStore->CreateIterator());
617 AliMUONVDigit* digit = static_cast<AliMUONVDigit*>(next());
618 if (!digit->IsCalibrated())
620 Calibrate(*fDigitStore);
622 Clusterize(*fDigitStore,*(ClusterStore()));
625 FillTreeR(fTriggerStore,ClusterStore(),*clustersTree);
628 //_____________________________________________________________________________
629 AliMUONVTriggerStore*
630 AliMUONReconstructor::TriggerStore() const
632 /// Return (and create if necessary and allowed) the trigger container
633 TString sopt(GetOption());
636 if (sopt.Contains("TRIGGERDISABLE"))
638 delete fTriggerStore;
645 fTriggerStore = new AliMUONTriggerStoreV1;
648 return fTriggerStore;