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 /// \class AliMUONReconstructor
19 /// Implementation of AliReconstructor for MUON subsystem.
21 /// The behavior of the MUON reconstruction can be changed, besides
22 /// the usual methods found in AliReconstruction (e.g. to disable tracking)
23 /// by using AliReconstruction::SetOption("MUON",options)
24 /// where options should be a space separated string.
26 /// Valid options are :
28 /// SAVEDIGITS : if you want to save in the TreeD the *calibrated* digits
29 /// that are used for the clustering
31 /// SIMPLEFIT : use the AliMUONClusterFinderSimpleFit clusterizer
33 /// AZ : use the AliMUONClusterFinderAZ clusterizer (default)
35 /// MLEM : another implementation of AZ, where preclustering is external
36 /// MLEMV3 : MLEM with preclustering=PRECLUSTERV2
37 /// MLEMV3 : MLEM with preclustering=PRECLUSTERV3
39 /// PRECLUSTER : use only AliMUONPreClusterFinder. Only for debug as
40 /// the produced clusters do not have a position, hence the tracking will not
42 /// PRECLUSTERV2 : another version of the preclustering
43 /// PRECLUSTERV3 : yet another version of the preclustering
45 /// COG : use AliMUONClusterFinderCOG clusterizer. Not really a production
46 /// option either, as center-of-gravity is generally not a good estimate
47 /// of the cluster position...
49 /// NOCLUSTERING : bypass completely the clustering stage
51 /// NOSTATUSMAP : disable the computation and usage of the pad status map. Only
54 /// NOLOCALRECONSTRUCTION : for debug, to disable local reconstruction (and hence
55 /// "recover" old behavior)
57 /// TRIGGERDISABLE : disable the treatment of MUON trigger
59 /// DIGITSTOREV1 : use the V1 implementation of the digitstore
60 /// DIGITSTOREV2R : use the V2R implementation of the digitstore
62 /// \author Laurent Aphecetche, Subatech
64 #include "AliMUONReconstructor.h"
66 #include "AliCDBManager.h"
67 #include "AliLoader.h"
69 #include "AliRunLoader.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"
93 #include "AliRawReader.h"
94 #include "AliCodeTimer.h"
95 #include <Riostream.h>
96 #include <TClonesArray.h>
99 //#include "AliCodeTimer.h"
101 ClassImp(AliMUONReconstructor)
104 //_____________________________________________________________________________
105 AliMUONReconstructor::AliMUONReconstructor() :
109 fTransformer(new AliMUONGeometryTransformer()),
111 fTriggerCircuit(0x0),
112 fCalibrationData(0x0),
113 fDigitCalibrator(0x0),
114 fClusterReconstructor(0x0),
121 fTransformer->LoadGeometryData();
124 //_____________________________________________________________________________
125 AliMUONReconstructor::~AliMUONReconstructor()
131 delete fCrateManager;
132 delete fTriggerCircuit;
133 delete fCalibrationData;
134 delete fDigitCalibrator;
135 delete fClusterReconstructor;
136 delete fClusterStore;
137 delete fTriggerStore;
139 delete fTrigChamberEff;
142 //_____________________________________________________________________________
144 AliMUONReconstructor::Calibrate(AliMUONVDigitStore& digitStore) const
146 /// Calibrate the digitStore
147 if (!fDigitCalibrator)
151 AliCodeTimerAuto(Form("%s::Calibrate(AliMUONVDigitStore*)",fDigitCalibrator->ClassName()))
152 fDigitCalibrator->Calibrate(digitStore);
155 //_____________________________________________________________________________
157 AliMUONReconstructor::Clusterize(const AliMUONVDigitStore& digitStore,
158 AliMUONVClusterStore& clusterStore) const
160 /// Creates clusters from digits.
162 TString sopt(GetOption());
164 if ( sopt.Contains("NOCLUSTERING") ) return;
166 if (!fClusterReconstructor)
168 CreateClusterReconstructor();
171 AliCodeTimerAuto(Form("%s::Digits2Clusters(const AliMUONVDigitStore&,AliMUONVClusterStore&)",
172 fClusterReconstructor->ClassName()))
173 fClusterReconstructor->Digits2Clusters(digitStore,clusterStore);
176 //_____________________________________________________________________________
177 AliMUONVClusterStore*
178 AliMUONReconstructor::ClusterStore() const
180 /// Return (and create if necessary) the cluster container
183 fClusterStore = new AliMUONClusterStoreV1;
185 return fClusterStore;
188 //_____________________________________________________________________________
190 AliMUONReconstructor::ConvertDigits(AliRawReader* rawReader,
191 AliMUONVDigitStore* digitStore,
192 AliMUONVTriggerStore* triggerStore) const
194 /// Convert raw data into digit and trigger stores
197 AliCodeTimerStart(Form("%s::Raw2Digits(AliRawReader*,AliMUONVDigitStore*,AliMUONVTriggerStore*)",
198 fDigitMaker->ClassName()))
199 fDigitMaker->Raw2Digits(rawReader,digitStore,triggerStore);
200 AliCodeTimerStop(Form("%s::Raw2Digits(AliRawReader*,AliMUONVDigitStore*,AliMUONVTriggerStore*)",
201 fDigitMaker->ClassName()))
202 Calibrate(*digitStore);
205 //_____________________________________________________________________________
207 AliMUONReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
209 /// convert raw data into a digit tree
211 Bool_t alone = ( TriggerStore() == 0 );
213 Bool_t ok = DigitStore()->Connect(*digitsTree,alone);
214 if ( TriggerStore() )
216 ok = ok && TriggerStore()->Connect(*digitsTree,kFALSE);
221 AliError("Could not make branches on TreeD");
225 ConvertDigits(rawReader,DigitStore(),TriggerStore());
227 DigitStore()->Clear();
231 //_____________________________________________________________________________
232 AliMUONTriggerCrateStore*
233 AliMUONReconstructor::CrateManager() const
235 /// Return (and create if necessary) the trigger crate store
236 if (fCrateManager) return fCrateManager;
237 fCrateManager = new AliMUONTriggerCrateStore;
238 fCrateManager->ReadFromFile();
239 return fCrateManager;
242 //_____________________________________________________________________________
244 AliMUONReconstructor::CreateDigitMaker() const
246 /// Create (and create if necessary) the digit maker
247 if (fDigitMaker) return;
251 fDigitMaker = new AliMUONDigitMaker;
254 //_____________________________________________________________________________
256 AliMUONReconstructor::CreateTriggerCircuit() const
258 /// Return (and create if necessary) the trigger circuit object
259 if (fTriggerCircuit) return;
263 fTriggerCircuit = new AliMUONTriggerCircuit(fTransformer);
267 //_____________________________________________________________________________
269 AliMUONReconstructor::CreateTriggerChamberEff() const
271 /// Create (and create if necessary) the trigger chamber efficiency class
272 if (fTrigChamberEff) return;
276 fTrigChamberEff = new AliMUONTriggerChamberEff(fTransformer,fDigitMaker,kTRUE);
277 //fTrigChamberEff->SetDebugLevel(1);
280 //_____________________________________________________________________________
282 AliMUONReconstructor::CreateTracker(AliRunLoader* runLoader) const
284 /// Create the MUONTracker object
285 /// The MUONTracker is passed the GetOption(), i.e. our own options
287 CreateTriggerCircuit();
289 CreateTriggerChamberEff();
291 AliLoader* loader = runLoader->GetDetectorLoader("MUON");
294 AliError("Cannot get MUONLoader, so cannot create MUONTracker");
297 AliMUONTracker* tracker = new AliMUONTracker(loader,fDigitMaker,fTransformer,fTriggerCircuit,fTrigChamberEff);
298 tracker->SetOption(GetOption());
303 //_____________________________________________________________________________
305 AliMUONReconstructor::CreateClusterReconstructor() const
307 /// Create cluster reconstructor, depending on GetOption()
313 AliMUONVClusterFinder* clusterFinder(0x0);
315 TString opt(GetOption());
318 if ( strstr(opt,"PRECLUSTERV2") )
320 clusterFinder = new AliMUONPreClusterFinderV2;
322 else if ( strstr(opt,"PRECLUSTERV3") )
324 clusterFinder = new AliMUONPreClusterFinderV3;
326 else if ( strstr(opt,"PRECLUSTER") )
328 clusterFinder = new AliMUONPreClusterFinder;
330 else if ( strstr(opt,"COG") )
332 clusterFinder = new AliMUONClusterFinderCOG(new AliMUONPreClusterFinder);
334 else if ( strstr(opt,"SIMPLEFITV3") )
336 clusterFinder = new AliMUONClusterFinderSimpleFit(new AliMUONClusterFinderCOG(new AliMUONPreClusterFinderV3));
338 else if ( strstr(opt,"SIMPLEFIT") )
340 clusterFinder = new AliMUONClusterFinderSimpleFit(new AliMUONClusterFinderCOG(new AliMUONPreClusterFinder));
342 else if ( strstr(opt,"MLEM:DRAW") )
344 clusterFinder = new AliMUONClusterFinderMLEM(kTRUE,new AliMUONPreClusterFinder);
346 else if ( strstr(opt,"MLEMV3") )
348 clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinderV3);
350 else if ( strstr(opt,"MLEMV2") )
352 clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinderV2);
354 else if ( strstr(opt,"MLEM") )
356 clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinder);
358 else if ( strstr(opt,"AZ") )
360 clusterFinder = new AliMUONClusterFinderAZ;
364 // default is currently AZ
365 clusterFinder = new AliMUONClusterFinderAZ;
370 AliInfo(Form("Will use %s for clusterizing",clusterFinder->ClassName()));
373 fClusterReconstructor = new AliMUONClusterReconstructor(clusterFinder,fTransformer);
376 //_____________________________________________________________________________
378 AliMUONReconstructor::CreateCalibrator() const
380 /// Create the calibrator
384 Int_t runNumber = AliCDBManager::Instance()->GetRun();
386 AliInfo("Calibration will occur.");
388 fCalibrationData = new AliMUONCalibrationData(runNumber);
389 if ( !fCalibrationData->IsValid() )
391 AliError("Could not retrieve calibrations !");
392 delete fCalibrationData;
393 fCalibrationData = 0x0;
397 // Check that we get all the calibrations we'll need
398 if ( !fCalibrationData->Pedestals() ||
399 !fCalibrationData->Gains() ||
400 !fCalibrationData->HV() )
402 AliFatal("Could not access all required calibration data");
405 TString opt(GetOption());
407 Bool_t statusMap(kTRUE);
409 if ( strstr(opt,"NOSTATUSMAP") )
411 AliWarning("Disconnecting status map : SHOULD BE USED FOR DEBUG ONLY. NOT FOR PRODUCTION !!!");
414 fDigitCalibrator = new AliMUONDigitCalibrator(*fCalibrationData,statusMap);
417 //_____________________________________________________________________________
419 AliMUONReconstructor::DigitStore() const
421 /// Return (and create if necessary) the digit container
424 TString sopt(GetOption());
427 AliInfo(Form("Options=%s",sopt.Data()));
429 if ( sopt.Contains("DIGITSTOREV1") )
431 fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV1");
433 else if ( sopt.Contains("DIGITSTOREV2R") )
435 fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2R");
437 else if ( sopt.Contains("DIGITSTOREV2S") )
439 fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2S");
442 if (!fDigitStore) fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2R");
444 AliInfo(Form("Will use %s to store digits during reconstruction",fDigitStore->ClassName()));
449 //_____________________________________________________________________________
451 AliMUONReconstructor::FillTreeR(AliMUONVTriggerStore* triggerStore,
452 AliMUONVClusterStore* clusterStore,
453 TTree& clustersTree) const
455 /// Write the trigger and cluster information into TreeR
464 Bool_t alone = ( clusterStore ? kFALSE : kTRUE );
465 ok = triggerStore->Connect(clustersTree,alone);
468 AliError("Could not create triggerStore branches in TreeR");
474 Bool_t alone = ( triggerStore ? kFALSE : kTRUE );
475 ok = clusterStore->Connect(clustersTree,alone);
478 AliError("Could not create triggerStore branches in TreeR");
482 if (ok) // at least one type of branches created successfully
488 //_____________________________________________________________________________
490 AliMUONReconstructor::HasDigitConversion() const
492 /// We *do* have digit conversion, but we might advertise it only
493 /// if we want to save the digits.
495 TString opt(GetOption());
497 if ( opt.Contains("SAVEDIGITS" ) && !opt.Contains("NOLOCALRECONSTRUCTION") )
507 //_____________________________________________________________________________
509 AliMUONReconstructor::HasLocalReconstruction() const
511 /// Whether or not we have local reconstruction
512 TString opt(GetOption());
514 if ( opt.Contains("NOLOCALRECONSTRUCTION" ) )
524 //_____________________________________________________________________________
526 AliMUONReconstructor::Reconstruct(AliRawReader* rawReader, TTree* clustersTree) const
528 /// This method is called by AliReconstruction if HasLocalReconstruction()==kTRUE AND
529 /// HasDigitConversion()==kFALSE
533 AliError("clustersTree is 0x0 !");
537 ConvertDigits(rawReader,DigitStore(),TriggerStore());
538 Clusterize(*(DigitStore()),*(ClusterStore()));
540 FillTreeR(TriggerStore(),ClusterStore(),*clustersTree);
543 //_____________________________________________________________________________
545 AliMUONReconstructor::Reconstruct(AliRunLoader* runLoader) const
547 /// Reconstruct simulated data
549 AliCodeTimerAuto("Reconstruct(AliRunLoader*)")
551 AliLoader* loader = runLoader->GetDetectorLoader("MUON");
554 AliError("Could not get MUON loader");
558 Int_t nEvents = runLoader->GetNumberOfEvents();
560 for ( Int_t i = 0; i < nEvents; ++i )
562 runLoader->GetEvent(i);
564 loader->LoadRecPoints("update");
565 loader->CleanRecPoints();
566 loader->MakeRecPointsContainer();
567 TTree* clustersTree = loader->TreeR();
569 loader->LoadDigits("read");
570 TTree* digitsTree = loader->TreeD();
572 Reconstruct(digitsTree,clustersTree);
574 loader->UnloadDigits();
575 loader->WriteRecPoints("OVERWRITE");
576 loader->UnloadRecPoints();
580 //_____________________________________________________________________________
582 AliMUONReconstructor::Reconstruct(AliRunLoader* runLoader, AliRawReader* rawReader) const
584 /// This method is called by AliReconstruction if HasLocalReconstruction()==kFALSE
586 AliCodeTimerAuto("AliMUONReconstructor::Reconstruct(AliRunLoader*, AliRawReader*)")
588 AliLoader* loader = runLoader->GetDetectorLoader("MUON");
591 AliError("Could not get MUON loader");
597 while (rawReader->NextEvent())
599 runLoader->GetEvent(i++);
601 loader->LoadRecPoints("update");
602 loader->CleanRecPoints();
603 loader->MakeRecPointsContainer();
604 TTree* clustersTree = loader->TreeR();
606 loader->LoadDigits("update");
607 loader->CleanDigits();
608 loader->MakeDigitsContainer();
609 TTree* digitsTree = loader->TreeD();
610 ConvertDigits(rawReader, digitsTree);
611 loader->WriteDigits("OVERWRITE");
613 Reconstruct(digitsTree,clustersTree);
615 loader->UnloadDigits();
616 loader->WriteRecPoints("OVERWRITE");
617 loader->UnloadRecPoints();
621 //_____________________________________________________________________________
623 AliMUONReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
625 /// This method is called by AliReconstruction if HasLocalReconstruction()==kTRUE
626 /// AND HasDigitConversion()==kTRUE
628 // AliCodeTimerAuto("(TTree*,TTree*)")
632 if (!digitsTree || !clustersTree)
634 AliError(Form("Tree is null : digitsTree=%p clustersTree=%p",
635 digitsTree,clustersTree));
641 fDigitStore = AliMUONVDigitStore::Create(*digitsTree);
644 AliError(Form("Could not get DigitStore from %s",digitsTree->GetName()));
648 AliInfo(Form("Created %s from %s",fDigitStore->ClassName(),digitsTree->GetName()));
653 fTriggerStore = AliMUONVTriggerStore::Create(*digitsTree);
656 AliError(Form("Could not get TriggerStore from %s",digitsTree->GetName()));
660 AliInfo(Form("Created %s from %s",fTriggerStore->ClassName(),digitsTree->GetName()));
664 if (!fTriggerStore && !fDigitStore)
666 AliError("No store at all. Nothing to do.");
670 // insure we start with empty stores
673 fDigitStore->Clear();
674 Bool_t alone = ( fTriggerStore ? kFALSE : kTRUE );
675 Bool_t ok = fDigitStore->Connect(*digitsTree,alone);
678 AliError("Could not connect digitStore to digitsTree");
684 fTriggerStore->Clear();
685 Bool_t alone = ( fDigitStore ? kFALSE : kTRUE );
686 Bool_t ok = fTriggerStore->Connect(*digitsTree,alone);
689 AliError("Could not connect triggerStore to digitsTree");
694 digitsTree->GetEvent(0);
698 // Insure we got calibrated digits (if we reconstruct from pure simulated,
699 // i.e. w/o going through raw data, this will be the case)
700 TIter next(fDigitStore->CreateIterator());
701 AliMUONVDigit* digit = static_cast<AliMUONVDigit*>(next());
702 if (!digit->IsCalibrated())
704 Calibrate(*fDigitStore);
706 Clusterize(*fDigitStore,*(ClusterStore()));
709 FillTreeR(fTriggerStore,ClusterStore(),*clustersTree);
712 //_____________________________________________________________________________
713 AliMUONVTriggerStore*
714 AliMUONReconstructor::TriggerStore() const
716 /// Return (and create if necessary and allowed) the trigger container
717 TString sopt(GetOption());
720 if (sopt.Contains("TRIGGERDISABLE"))
722 delete fTriggerStore;
729 fTriggerStore = new AliMUONTriggerStoreV1;
732 return fTriggerStore;