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"
69 #include "AliLoader.h"
71 #include "AliRunLoader.h"
72 #include "AliMUONCalibrationData.h"
73 #include "AliMUONClusterFinderCOG.h"
74 #include "AliMUONClusterFinderMLEM.h"
75 #include "AliMUONClusterFinderSimpleFit.h"
76 #include "AliMUONClusterFinderAZ.h"
77 #include "AliMUONClusterReconstructor.h"
78 #include "AliMUONClusterStoreV1.h"
79 #include "AliMUONConstants.h"
80 #include "AliMUONDigitCalibrator.h"
81 #include "AliMUONDigitMaker.h"
82 #include "AliMUONDigitStoreV1.h"
83 #include "AliMUONDigitStoreV2R.h"
84 #include "AliMUONGeometryTransformer.h"
85 #include "AliMUONPreClusterFinder.h"
86 #include "AliMUONPreClusterFinderV2.h"
87 #include "AliMUONPreClusterFinderV3.h"
88 #include "AliMUONTracker.h"
89 #include "AliMUONVTrackStore.h"
90 #include "AliMUONTriggerChamberEff.h"
91 #include "AliMUONTriggerCircuit.h"
92 #include "AliMUONTriggerCrateStore.h"
93 #include "AliMUONTriggerStoreV1.h"
94 #include "AliMUONVClusterFinder.h"
96 #include "AliRawReader.h"
97 #include "AliCodeTimer.h"
98 #include <Riostream.h>
99 #include <TClonesArray.h>
102 //#include "AliCodeTimer.h"
104 ClassImp(AliMUONReconstructor)
107 //_____________________________________________________________________________
108 AliMUONReconstructor::AliMUONReconstructor() :
112 fTransformer(new AliMUONGeometryTransformer()),
114 fTriggerCircuit(0x0),
115 fCalibrationData(0x0),
116 fDigitCalibrator(0x0),
117 fClusterReconstructor(0x0),
125 // Load geometry data
126 fTransformer->LoadGeometryData();
129 if ( ! AliMpCDB::LoadMpSegmentation() )
131 AliFatal("Could not access mapping from OCDB !");
135 if ( ! AliMpCDB::LoadDDLStore() )
137 AliFatal("Could not access DDL Store from OCDB !");
143 //_____________________________________________________________________________
144 AliMUONReconstructor::~AliMUONReconstructor()
150 delete fCrateManager;
151 delete fTriggerCircuit;
152 delete fCalibrationData;
153 delete fDigitCalibrator;
154 delete fClusterReconstructor;
155 delete fClusterStore;
156 delete fTriggerStore;
158 delete fTrigChamberEff;
161 //_____________________________________________________________________________
163 AliMUONReconstructor::Calibrate(AliMUONVDigitStore& digitStore) const
165 /// Calibrate the digitStore
166 if (!fDigitCalibrator)
170 AliCodeTimerAuto(Form("%s::Calibrate(AliMUONVDigitStore*)",fDigitCalibrator->ClassName()))
171 fDigitCalibrator->Calibrate(digitStore);
174 //_____________________________________________________________________________
176 AliMUONReconstructor::Clusterize(const AliMUONVDigitStore& digitStore,
177 AliMUONVClusterStore& clusterStore) const
179 /// Creates clusters from digits.
181 TString sopt(GetOption());
183 if ( sopt.Contains("NOCLUSTERING") ) return;
185 if (!fClusterReconstructor)
187 CreateClusterReconstructor();
190 AliCodeTimerAuto(Form("%s::Digits2Clusters(const AliMUONVDigitStore&,AliMUONVClusterStore&)",
191 fClusterReconstructor->ClassName()))
192 fClusterReconstructor->Digits2Clusters(digitStore,clusterStore);
195 //_____________________________________________________________________________
196 AliMUONVClusterStore*
197 AliMUONReconstructor::ClusterStore() const
199 /// Return (and create if necessary) the cluster container
202 fClusterStore = new AliMUONClusterStoreV1;
204 return fClusterStore;
207 //_____________________________________________________________________________
209 AliMUONReconstructor::ConvertDigits(AliRawReader* rawReader,
210 AliMUONVDigitStore* digitStore,
211 AliMUONVTriggerStore* triggerStore) const
213 /// Convert raw data into digit and trigger stores
216 AliCodeTimerStart(Form("%s::Raw2Digits(AliRawReader*,AliMUONVDigitStore*,AliMUONVTriggerStore*)",
217 fDigitMaker->ClassName()))
218 fDigitMaker->Raw2Digits(rawReader,digitStore,triggerStore);
219 AliCodeTimerStop(Form("%s::Raw2Digits(AliRawReader*,AliMUONVDigitStore*,AliMUONVTriggerStore*)",
220 fDigitMaker->ClassName()))
221 Calibrate(*digitStore);
224 //_____________________________________________________________________________
226 AliMUONReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
228 /// convert raw data into a digit tree
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());
246 DigitStore()->Clear();
250 //_____________________________________________________________________________
251 AliMUONTriggerCrateStore*
252 AliMUONReconstructor::CrateManager() const
254 /// Return (and create if necessary) the trigger crate store
255 if (fCrateManager) return fCrateManager;
256 fCrateManager = new AliMUONTriggerCrateStore;
257 fCrateManager->ReadFromFile();
258 return fCrateManager;
261 //_____________________________________________________________________________
263 AliMUONReconstructor::CreateDigitMaker() const
265 /// Create (and create if necessary) the digit maker
266 if (fDigitMaker) return;
270 fDigitMaker = new AliMUONDigitMaker;
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::CreateTriggerChamberEff() const
290 /// Create (and create if necessary) the trigger chamber efficiency class
291 if (fTrigChamberEff) return;
295 fTrigChamberEff = new AliMUONTriggerChamberEff(fTransformer,fDigitMaker,kTRUE);
296 //fTrigChamberEff->SetDebugLevel(1);
299 //_____________________________________________________________________________
301 AliMUONReconstructor::CreateTracker(AliRunLoader* runLoader) const
303 /// Create the MUONTracker object
304 /// The MUONTracker is passed the GetOption(), i.e. our own options
306 CreateTriggerCircuit();
308 CreateTriggerChamberEff();
310 AliLoader* loader = runLoader->GetDetectorLoader("MUON");
313 AliError("Cannot get MUONLoader, so cannot create MUONTracker");
316 AliMUONTracker* tracker = new AliMUONTracker(loader,fDigitMaker,fTransformer,fTriggerCircuit,fTrigChamberEff);
317 tracker->SetOption(GetOption());
322 //_____________________________________________________________________________
324 AliMUONReconstructor::CreateClusterReconstructor() const
326 /// Create cluster reconstructor, depending on GetOption()
332 AliMUONVClusterFinder* clusterFinder(0x0);
334 TString opt(GetOption());
337 if ( strstr(opt,"PRECLUSTERV2") )
339 clusterFinder = new AliMUONPreClusterFinderV2;
341 else if ( strstr(opt,"PRECLUSTERV3") )
343 clusterFinder = new AliMUONPreClusterFinderV3;
345 else if ( strstr(opt,"PRECLUSTER") )
347 clusterFinder = new AliMUONPreClusterFinder;
349 else if ( strstr(opt,"COG") )
351 clusterFinder = new AliMUONClusterFinderCOG(new AliMUONPreClusterFinder);
353 else if ( strstr(opt,"SIMPLEFITV3") )
355 clusterFinder = new AliMUONClusterFinderSimpleFit(new AliMUONClusterFinderCOG(new AliMUONPreClusterFinderV3));
357 else if ( strstr(opt,"SIMPLEFIT") )
359 clusterFinder = new AliMUONClusterFinderSimpleFit(new AliMUONClusterFinderCOG(new AliMUONPreClusterFinder));
361 else if ( strstr(opt,"MLEM:DRAW") )
363 clusterFinder = new AliMUONClusterFinderMLEM(kTRUE,new AliMUONPreClusterFinder);
365 else if ( strstr(opt,"MLEMV3") )
367 clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinderV3);
369 else if ( strstr(opt,"MLEMV2") )
371 clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinderV2);
373 else if ( strstr(opt,"MLEM") )
375 clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinder);
377 else if ( strstr(opt,"AZ") )
379 clusterFinder = new AliMUONClusterFinderAZ;
383 // default is currently AZ
384 clusterFinder = new AliMUONClusterFinderAZ;
389 AliInfo(Form("Will use %s for clusterizing",clusterFinder->ClassName()));
392 fClusterReconstructor = new AliMUONClusterReconstructor(clusterFinder,fTransformer);
395 //_____________________________________________________________________________
397 AliMUONReconstructor::CreateCalibrator() const
399 /// Create the calibrator
403 Int_t runNumber = AliCDBManager::Instance()->GetRun();
405 AliInfo("Calibration will occur.");
407 fCalibrationData = new AliMUONCalibrationData(runNumber);
408 if ( !fCalibrationData->IsValid() )
410 AliError("Could not retrieve calibrations !");
411 delete fCalibrationData;
412 fCalibrationData = 0x0;
416 // Check that we get all the calibrations we'll need
417 if ( !fCalibrationData->Pedestals() ||
418 !fCalibrationData->Gains() ||
419 !fCalibrationData->HV() )
421 AliFatal("Could not access all required calibration data");
424 TString opt(GetOption());
426 Bool_t statusMap(kTRUE);
428 if ( strstr(opt,"NOSTATUSMAP") )
430 AliWarning("Disconnecting status map : SHOULD BE USED FOR DEBUG ONLY. NOT FOR PRODUCTION !!!");
433 fDigitCalibrator = new AliMUONDigitCalibrator(*fCalibrationData,statusMap);
436 //_____________________________________________________________________________
438 AliMUONReconstructor::DigitStore() const
440 /// Return (and create if necessary) the digit container
443 TString sopt(GetOption());
446 AliInfo(Form("Options=%s",sopt.Data()));
448 if ( sopt.Contains("DIGITSTOREV1") )
450 fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV1");
452 else if ( sopt.Contains("DIGITSTOREV2R") )
454 fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2R");
456 else if ( sopt.Contains("DIGITSTOREV2S") )
458 fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2S");
461 if (!fDigitStore) fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2R");
463 AliInfo(Form("Will use %s to store digits during reconstruction",fDigitStore->ClassName()));
468 //_____________________________________________________________________________
470 AliMUONReconstructor::FillTreeR(AliMUONVTriggerStore* triggerStore,
471 AliMUONVClusterStore* clusterStore,
472 TTree& clustersTree) const
474 /// Write the trigger and cluster information into TreeR
483 Bool_t alone = ( clusterStore ? kFALSE : kTRUE );
484 ok = triggerStore->Connect(clustersTree,alone);
487 AliError("Could not create triggerStore branches in TreeR");
493 Bool_t alone = ( triggerStore ? kFALSE : kTRUE );
494 ok = clusterStore->Connect(clustersTree,alone);
497 AliError("Could not create triggerStore branches in TreeR");
501 if (ok) // at least one type of branches created successfully
507 //_____________________________________________________________________________
509 AliMUONReconstructor::HasDigitConversion() const
511 /// We *do* have digit conversion, but we might advertise it only
512 /// if we want to save the digits.
514 TString opt(GetOption());
516 if ( opt.Contains("SAVEDIGITS" ) && !opt.Contains("NOLOCALRECONSTRUCTION") )
526 //_____________________________________________________________________________
528 AliMUONReconstructor::HasLocalReconstruction() const
530 /// Whether or not we have local reconstruction
531 TString opt(GetOption());
533 if ( opt.Contains("NOLOCALRECONSTRUCTION" ) )
543 //_____________________________________________________________________________
545 AliMUONReconstructor::Reconstruct(AliRawReader* rawReader, TTree* clustersTree) const
547 /// This method is called by AliReconstruction if HasLocalReconstruction()==kTRUE AND
548 /// HasDigitConversion()==kFALSE
552 AliError("clustersTree is 0x0 !");
556 ConvertDigits(rawReader,DigitStore(),TriggerStore());
557 Clusterize(*(DigitStore()),*(ClusterStore()));
559 FillTreeR(TriggerStore(),ClusterStore(),*clustersTree);
562 //_____________________________________________________________________________
564 AliMUONReconstructor::Reconstruct(AliRunLoader* runLoader) const
566 /// Reconstruct simulated data
568 AliCodeTimerAuto("Reconstruct(AliRunLoader*)")
570 AliLoader* loader = runLoader->GetDetectorLoader("MUON");
573 AliError("Could not get MUON loader");
577 Int_t nEvents = runLoader->GetNumberOfEvents();
579 for ( Int_t i = 0; i < nEvents; ++i )
581 runLoader->GetEvent(i);
583 loader->LoadRecPoints("update");
584 loader->CleanRecPoints();
585 loader->MakeRecPointsContainer();
586 TTree* clustersTree = loader->TreeR();
588 loader->LoadDigits("read");
589 TTree* digitsTree = loader->TreeD();
591 Reconstruct(digitsTree,clustersTree);
593 loader->UnloadDigits();
594 loader->WriteRecPoints("OVERWRITE");
595 loader->UnloadRecPoints();
599 //_____________________________________________________________________________
601 AliMUONReconstructor::Reconstruct(AliRunLoader* runLoader, AliRawReader* rawReader) const
603 /// This method is called by AliReconstruction if HasLocalReconstruction()==kFALSE
605 AliCodeTimerAuto("AliMUONReconstructor::Reconstruct(AliRunLoader*, AliRawReader*)")
607 AliLoader* loader = runLoader->GetDetectorLoader("MUON");
610 AliError("Could not get MUON loader");
616 while (rawReader->NextEvent())
618 runLoader->GetEvent(i++);
620 loader->LoadRecPoints("update");
621 loader->CleanRecPoints();
622 loader->MakeRecPointsContainer();
623 TTree* clustersTree = loader->TreeR();
625 loader->LoadDigits("update");
626 loader->CleanDigits();
627 loader->MakeDigitsContainer();
628 TTree* digitsTree = loader->TreeD();
629 ConvertDigits(rawReader, digitsTree);
630 loader->WriteDigits("OVERWRITE");
632 Reconstruct(digitsTree,clustersTree);
634 loader->UnloadDigits();
635 loader->WriteRecPoints("OVERWRITE");
636 loader->UnloadRecPoints();
640 //_____________________________________________________________________________
642 AliMUONReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
644 /// This method is called by AliReconstruction if HasLocalReconstruction()==kTRUE
645 /// AND HasDigitConversion()==kTRUE
647 // AliCodeTimerAuto("(TTree*,TTree*)")
651 if (!digitsTree || !clustersTree)
653 AliError(Form("Tree is null : digitsTree=%p clustersTree=%p",
654 digitsTree,clustersTree));
660 fDigitStore = AliMUONVDigitStore::Create(*digitsTree);
663 AliError(Form("Could not get DigitStore from %s",digitsTree->GetName()));
667 AliInfo(Form("Created %s from %s",fDigitStore->ClassName(),digitsTree->GetName()));
672 fTriggerStore = AliMUONVTriggerStore::Create(*digitsTree);
675 AliError(Form("Could not get TriggerStore from %s",digitsTree->GetName()));
679 AliInfo(Form("Created %s from %s",fTriggerStore->ClassName(),digitsTree->GetName()));
683 if (!fTriggerStore && !fDigitStore)
685 AliError("No store at all. Nothing to do.");
689 // insure we start with empty stores
692 fDigitStore->Clear();
693 Bool_t alone = ( fTriggerStore ? kFALSE : kTRUE );
694 Bool_t ok = fDigitStore->Connect(*digitsTree,alone);
697 AliError("Could not connect digitStore to digitsTree");
703 fTriggerStore->Clear();
704 Bool_t alone = ( fDigitStore ? kFALSE : kTRUE );
705 Bool_t ok = fTriggerStore->Connect(*digitsTree,alone);
708 AliError("Could not connect triggerStore to digitsTree");
713 digitsTree->GetEvent(0);
717 // Insure we got calibrated digits (if we reconstruct from pure simulated,
718 // i.e. w/o going through raw data, this will be the case)
719 TIter next(fDigitStore->CreateIterator());
720 AliMUONVDigit* digit = static_cast<AliMUONVDigit*>(next());
721 if (!digit->IsCalibrated())
723 Calibrate(*fDigitStore);
725 Clusterize(*fDigitStore,*(ClusterStore()));
728 FillTreeR(fTriggerStore,ClusterStore(),*clustersTree);
731 //_____________________________________________________________________________
732 AliMUONVTriggerStore*
733 AliMUONReconstructor::TriggerStore() const
735 /// Return (and create if necessary and allowed) the trigger container
736 TString sopt(GetOption());
739 if (sopt.Contains("TRIGGERDISABLE"))
741 delete fTriggerStore;
748 fTriggerStore = new AliMUONTriggerStoreV1;
751 return fTriggerStore;