]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONReconstructor.cxx
First big commit of the mchview program and its accompanying library,
[u/mrichter/AliRoot.git] / MUON / AliMUONReconstructor.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15 /* $Id$ */
16
17 //-----------------------------------------------------------------------------
18 /// \class AliMUONReconstructor
19 ///
20 /// Implementation of AliReconstructor for MUON subsystem.
21 ///
22 /// The clustering mode and the associated parameters can be changed by using
23 /// AliMUONRecoParam *muonRecoParam = AliMUONRecoParam::GetLow(High)FluxParam();
24 /// muonRecoParam->Set...(); // see methods in AliMUONRecoParam.h for details
25 /// AliRecoParam::Instance()->RegisterRecoParam(muonRecoParam);
26 ///
27 /// Valid modes are :
28 ///
29 /// SIMPLEFIT : use the AliMUONClusterFinderSimpleFit clusterizer
30 ///
31 /// SIMPLEFITV3 : SIMPLEFIT with preclustering=PRECLUSTERV3
32 ///
33 /// MLEM : use AliMUONClusterFinderMLEM and AliMUONPreClusterFinder for preclustering (default)
34 /// MLEMV2 : MLEM with preclustering=PRECLUSTERV2
35 /// MLEMV3 : MLEM with preclustering=PRECLUSTERV3
36 ///
37 /// PRECLUSTER : use only AliMUONPreClusterFinder. Only for debug as
38 /// the produced clusters do not have a position, hence the tracking will not
39 /// work
40 /// PRECLUSTERV2 : another version of the preclustering
41 /// PRECLUSTERV3 : yet another version of the preclustering
42 ///
43 /// COG : use AliMUONClusterFinderCOG clusterizer. Not really a production
44 /// option either, as center-of-gravity is generally not a good estimate
45 /// of the cluster position...
46 ///
47 /// PEAKCOG : COG cluster finder around local maxima
48 /// PEAKFIT : fit around local maxima with up to 3 peaks, COG otherwise
49 ///
50 /// NOCLUSTERING : bypass completely the clustering stage
51 ///
52 /// ------
53 ///
54 /// The behavior of the MUON reconstruction can also be changed, besides
55 /// the usual methods found in AliReconstruction (e.g. to disable tracking)
56 /// by using AliReconstruction::SetOption("MUON",options)
57 /// where options should be a space separated string.
58 ///
59 /// Valid options are :
60 ///
61 /// SAVEDIGITS : if you want to save in the TreeD the *calibrated* digits
62 ///     that are used for the clustering
63 ///
64 /// DIGITSTOREV1 : use the V1 implementation of the digitstore 
65 /// DIGITSTOREV2R : use the V2R implementation of the digitstore 
66 ///
67 /// NOLOCALRECONSTRUCTION : for debug, to disable local reconstruction (and hence
68 /// "recover" old behavior)
69 ///
70 /// TRIGGERDISABLE : disable the treatment of MUON trigger
71 ///
72 /// USEFASTDECODER : makes the digit maker class use the high performance decoder
73 ///                  AliMUONTrackerDDLDecoder instead of AliMUONPayloadTracker.
74 ///
75 /// \author Laurent Aphecetche, Subatech
76 //-----------------------------------------------------------------------------
77
78 #include "AliMUONReconstructor.h"
79
80 #include "AliMUONCalibrationData.h"
81 #include "AliMUONClusterFinderCOG.h"
82 #include "AliMUONClusterFinderMLEM.h"
83 #include "AliMUONClusterFinderSimpleFit.h"
84 #include "AliMUONClusterFinderPeakCOG.h"
85 #include "AliMUONClusterFinderPeakFit.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 "AliMUONRecoParam.h"
96 #include "AliMUONSimpleClusterServer.h"
97 #include "AliMUONTracker.h"
98 #include "AliMUONTriggerCircuit.h"
99 #include "AliMUONTriggerCrateStore.h"
100 #include "AliMUONTriggerStoreV1.h"
101 #include "AliMUONVClusterFinder.h"
102 #include "AliMUONVClusterServer.h"
103 #include "AliMUONVTrackStore.h"
104
105 #include "AliMpArea.h"
106 #include "AliMpCDB.h"
107 #include "AliMpConstants.h"
108
109 #include "AliRecoParam.h"
110 #include "AliRawReader.h"
111 #include "AliCDBManager.h"
112 #include "AliCodeTimer.h"
113 #include "AliLog.h"
114
115 #include <Riostream.h>
116 #include <TObjArray.h>
117 #include <TClonesArray.h>
118 #include <TString.h>
119 #include <TTree.h>
120
121 /// \cond CLASSIMP
122 ClassImp(AliMUONReconstructor)
123 /// \endcond 
124
125 AliMUONRecoParam* AliMUONReconstructor::fgRecoParam = 0x0; // reconstruction parameters
126
127 //_____________________________________________________________________________
128 AliMUONReconstructor::AliMUONReconstructor() : 
129 AliReconstructor(),
130 fCrateManager(0x0),
131 fDigitMaker(0x0),
132 fTransformer(new AliMUONGeometryTransformer()),
133 fDigitStore(0x0),
134 fTriggerCircuit(0x0),
135 fCalibrationData(0x0),
136 fDigitCalibrator(0x0),
137 fClusterServer(0x0),
138 fTriggerStore(0x0),
139 fTrackStore(0x0)
140 {
141   /// normal ctor
142
143   // Load mapping
144   if ( ! AliMpCDB::LoadDDLStore() ) {
145     AliFatal("Could not access mapping from OCDB !");
146   }
147   
148   // Load geometry data
149   fTransformer->LoadGeometryData();
150   
151 }
152
153 //_____________________________________________________________________________
154 AliMUONReconstructor::~AliMUONReconstructor()
155 {
156   /// dtor
157   delete fDigitMaker;
158   delete fDigitStore;
159   delete fTransformer;
160   delete fCrateManager;
161   delete fTriggerCircuit;
162   delete fCalibrationData;
163   delete fDigitCalibrator;
164   delete fClusterServer;
165   delete fTriggerStore;
166   delete fTrackStore;
167 }
168
169 //_____________________________________________________________________________
170 const AliMUONRecoParam* AliMUONReconstructor::GetRecoParam()
171 {
172   /// get reconstruction parameters
173   
174   if (!fgRecoParam) {
175     
176     // get reconstruction parameters from AliRecoParam if any
177     TObjArray *recoParams = AliRecoParam::Instance()->GetRecoParam("MUON");
178     
179     if (recoParams) {
180       
181       fgRecoParam = (AliMUONRecoParam*) recoParams->Last();
182       
183     } else {
184       
185       // initialize reconstruction parameters if not already done
186       cout<<"W-AliMUONReconstructor::GetRecoParam: Reconstruction parameters not initialized - Use default one"<<endl;
187       fgRecoParam = AliMUONRecoParam::GetLowFluxParam();
188       AliRecoParam::Instance()->RegisterRecoParam(fgRecoParam);
189       
190     }
191     
192   }
193   
194   return fgRecoParam;
195 }
196
197 //_____________________________________________________________________________
198 void
199 AliMUONReconstructor::Calibrate(AliMUONVDigitStore& digitStore) const
200 {
201   /// Calibrate the digitStore
202   if (!fDigitCalibrator)
203   {
204     CreateCalibrator();
205   }
206   AliCodeTimerAuto(Form("%s::Calibrate(AliMUONVDigitStore*)",fDigitCalibrator->ClassName()))
207   fDigitCalibrator->Calibrate(digitStore);  
208 }
209
210 //_____________________________________________________________________________
211 void
212 AliMUONReconstructor::ConvertDigits(AliRawReader* rawReader, 
213                                     AliMUONVDigitStore* digitStore,
214                                     AliMUONVTriggerStore* triggerStore) const
215 {
216   /// Convert raw data into digit and trigger stores
217   CreateDigitMaker();
218   
219   AliCodeTimerStart(Form("%s::Raw2Digits(AliRawReader*,AliMUONVDigitStore*,AliMUONVTriggerStore*)",
220                     fDigitMaker->ClassName()))
221   fDigitMaker->Raw2Digits(rawReader,digitStore,triggerStore);
222   AliCodeTimerStop(Form("%s::Raw2Digits(AliRawReader*,AliMUONVDigitStore*,AliMUONVTriggerStore*)",
223                          fDigitMaker->ClassName()))
224   Calibrate(*digitStore);
225 }
226
227 //_____________________________________________________________________________
228 void 
229 AliMUONReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
230 {
231    /// convert raw data into a digit tree
232   AliCodeTimerAuto("")
233
234   Bool_t alone = ( TriggerStore() == 0 );
235   
236   Bool_t ok = DigitStore()->Connect(*digitsTree,alone);
237   if ( TriggerStore() ) 
238   {
239     ok = ok && TriggerStore()->Connect(*digitsTree,kFALSE);
240   }
241   
242   if (!ok)
243   {
244     AliError("Could not make branches on TreeD");
245   }
246   else
247   {
248     ConvertDigits(rawReader,DigitStore(),TriggerStore());
249     AliCodeTimerStart("Fill digits")
250     digitsTree->Fill();
251     AliCodeTimerStop("Fill digits")
252     DigitStore()->Clear();
253   }
254 }
255
256 //_____________________________________________________________________________
257 AliMUONTriggerCrateStore*
258 AliMUONReconstructor::CrateManager() const
259 {
260   /// Return (and create if necessary) the trigger crate store
261   if (fCrateManager) return fCrateManager;
262   fCrateManager = new AliMUONTriggerCrateStore;
263   fCrateManager->ReadFromFile();
264   return fCrateManager;
265 }
266
267 //_____________________________________________________________________________
268 void
269 AliMUONReconstructor::CreateDigitMaker() const
270 {
271   /// Create (and create if necessary) the digit maker
272   if (fDigitMaker) return;
273
274   AliCodeTimerAuto("")
275
276   TString option = GetOption();
277   Bool_t enableErrorLogging = kTRUE;
278   Bool_t useFastDecoder = kFALSE;
279   if (option.Contains("USEFASTDECODER"))
280   {
281     useFastDecoder = kTRUE;
282   }
283   fDigitMaker = new AliMUONDigitMaker(enableErrorLogging, useFastDecoder);
284 }
285
286 //_____________________________________________________________________________
287 void 
288 AliMUONReconstructor::CreateTriggerCircuit() const
289 {
290   /// Return (and create if necessary) the trigger circuit object
291   if (fTriggerCircuit) return;
292
293   AliCodeTimerAuto("")
294
295   fTriggerCircuit = new AliMUONTriggerCircuit(fTransformer);
296
297 }
298
299 //_____________________________________________________________________________
300 AliTracker* 
301 AliMUONReconstructor::CreateTracker() const
302 {
303   /// Create the MUONTracker object
304   
305   CreateTriggerCircuit();
306   CreateDigitMaker();
307   CreateClusterServer();
308   
309   if (!fClusterServer) 
310   {
311     AliError("ClusterServer is NULL ! Cannot create tracker");
312     return 0x0;
313   }
314   
315   AliMUONTracker* tracker = new AliMUONTracker(*fClusterServer,
316                                                *DigitStore(),
317                                                fDigitMaker,
318                                                fTransformer,
319                                                fTriggerCircuit);
320   
321   return tracker;
322 }
323
324 //_____________________________________________________________________________
325 AliMUONVClusterFinder*
326 AliMUONReconstructor::CreateClusterFinder(const char* clusterFinderType) const
327 {
328   /// Create a given cluster finder instance
329   
330   AliCodeTimerAuto("")
331
332   AliMUONVClusterFinder* clusterFinder(0x0);
333   
334   TString opt(clusterFinderType);
335   opt.ToUpper();
336   
337   if ( strstr(opt,"PRECLUSTERV2") )
338   {
339     clusterFinder = new AliMUONPreClusterFinderV2;
340   }    
341   else if ( strstr(opt,"PRECLUSTERV3") )
342   {
343     clusterFinder = new AliMUONPreClusterFinderV3;
344   }  
345   else if ( strstr(opt,"PRECLUSTER") )
346   {
347     clusterFinder = new AliMUONPreClusterFinder;
348   }  
349   else if ( strstr(opt,"PEAKCOG") )
350   {
351     clusterFinder = new AliMUONClusterFinderPeakCOG(kFALSE,new AliMUONPreClusterFinder);
352   }
353   else if ( strstr(opt,"PEAKFIT") )
354   {
355     clusterFinder = new AliMUONClusterFinderPeakFit(kFALSE,new AliMUONPreClusterFinder);
356   }
357   else if ( strstr(opt,"COG") )
358   {
359     clusterFinder = new AliMUONClusterFinderCOG(new AliMUONPreClusterFinder);
360   }  
361   else if ( strstr(opt,"SIMPLEFITV3") )
362   {
363     clusterFinder = new AliMUONClusterFinderSimpleFit(new AliMUONClusterFinderCOG(new AliMUONPreClusterFinderV3));
364   }
365   else if ( strstr(opt,"SIMPLEFIT") )
366   {
367     clusterFinder = new AliMUONClusterFinderSimpleFit(new AliMUONClusterFinderCOG(new AliMUONPreClusterFinder));
368   }
369   else if ( strstr(opt,"MLEM:DRAW") )
370   {
371     clusterFinder = new AliMUONClusterFinderMLEM(kTRUE,new AliMUONPreClusterFinder);
372   }
373   else if ( strstr(opt,"MLEMV3") )
374   {
375     clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinderV3);
376   } 
377   else if ( strstr(opt,"MLEMV2") )
378   {
379     clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinderV2);
380   } 
381   else if ( strstr(opt,"MLEM") )
382   {
383     clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinder);
384   } 
385   else
386   {
387     AliError(Form("clustering mode \"%s\" does not exist",opt.Data()));
388     return 0x0;
389   }
390   
391   return clusterFinder;
392 }
393
394 //_____________________________________________________________________________
395 void
396 AliMUONReconstructor::CreateClusterServer() const
397 {
398   /// Create cluster server
399   
400   if ( fClusterServer ) return;
401   
402   AliCodeTimerAuto("")
403
404   AliDebug(1,"");
405   
406   AliMUONVClusterFinder* clusterFinder = CreateClusterFinder(GetRecoParam()->GetClusteringMode());
407   
408   if ( !clusterFinder ) return;
409   
410   AliInfo(Form("Will use %s for clusterizing",clusterFinder->ClassName()));
411   
412   fClusterServer = new AliMUONSimpleClusterServer(*clusterFinder,*fTransformer);
413 }
414
415 //_____________________________________________________________________________
416 void
417 AliMUONReconstructor::CreateCalibrator() const
418 {
419   /// Create the calibrator
420   
421   AliCodeTimerAuto("")
422   
423   Int_t runNumber = AliCDBManager::Instance()->GetRun();
424
425   AliInfo("Calibration will occur.");
426   
427   fCalibrationData = new AliMUONCalibrationData(runNumber);
428   if ( !fCalibrationData->IsValid() )
429   {
430     AliError("Could not retrieve calibrations !");
431     delete fCalibrationData;
432     fCalibrationData = 0x0;
433     return;
434   }    
435   
436   // Check that we get all the calibrations we'll need
437   if ( !fCalibrationData->Pedestals() ||
438        !fCalibrationData->Gains() ||
439        !fCalibrationData->HV() )
440   {
441     AliFatal("Could not access all required calibration data");
442   }
443   
444   TString opt(GetOption());
445   opt.ToUpper();
446   
447   if ( strstr(opt,"NOSTATUSMAP") )
448   {
449     AliWarning("NOSTATUSMAP is obsolete");
450   }
451
452   fDigitCalibrator = new AliMUONDigitCalibrator(*fCalibrationData);
453 }
454
455 //_____________________________________________________________________________
456 AliMUONVDigitStore*
457 AliMUONReconstructor::DigitStore() const
458 {
459   /// Return (and create if necessary) the digit container
460   if (!fDigitStore) 
461   {
462     TString sopt(GetOption());
463     sopt.ToUpper();
464     
465     AliInfo(Form("Options=%s",sopt.Data()));
466     
467     if ( sopt.Contains("DIGITSTOREV1") )
468     {
469       fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV1");
470     }
471     else if ( sopt.Contains("DIGITSTOREV2R") ) 
472     {
473       fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2R");
474     }
475     else if ( sopt.Contains("DIGITSTOREV2S") ) 
476     {
477       fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2S");
478     }
479     
480     if (!fDigitStore) fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2R");
481     
482     AliInfo(Form("Will use %s to store digits during reconstruction",fDigitStore->ClassName()));
483   }
484   return fDigitStore;
485 }
486
487 //_____________________________________________________________________________
488 void
489 AliMUONReconstructor::FillTreeR(AliMUONVTriggerStore* triggerStore,
490                                 TTree& clustersTree) const
491 {
492   /// Write the trigger and cluster information into TreeR
493   
494   AliCodeTimerAuto("")
495
496   AliDebug(1,"");
497   
498   Bool_t ok(kFALSE);
499   if ( triggerStore ) 
500   {
501     ok = triggerStore->Connect(clustersTree,kTRUE);
502     if (!ok)
503     {
504       AliError("Could not create triggerStore branches in TreeR");
505     }
506   }
507   
508   if (ok) // at least one type of branches created successfully
509   {
510     clustersTree.Fill();
511   }
512 }
513
514 //_____________________________________________________________________________
515 Bool_t 
516 AliMUONReconstructor::HasDigitConversion() const
517 {
518   /// We *do* have digit conversion, but we might advertise it only 
519   /// if we want to save the digits.
520   
521   TString opt(GetOption());
522   opt.ToUpper();
523   if ( opt.Contains("SAVEDIGITS" ) && !opt.Contains("NOLOCALRECONSTRUCTION") )
524   {
525     return kTRUE;
526   }
527   else
528   {
529     return kFALSE;
530   }
531 }
532
533 //_____________________________________________________________________________
534 void 
535 AliMUONReconstructor::Reconstruct(AliRawReader* rawReader, TTree* clustersTree) const
536 {
537   /// This method is called by AliReconstruction if HasLocalReconstruction()==kTRUE AND
538   /// HasDigitConversion()==kFALSE
539   
540   if ( !clustersTree ) 
541   {
542     AliError("clustersTree is 0x0 !");
543     return;
544   }
545   
546   ConvertDigits(rawReader,DigitStore(),TriggerStore());
547
548   FillTreeR(TriggerStore(),*clustersTree);
549 }
550
551 //_____________________________________________________________________________
552 void 
553 AliMUONReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
554 {
555   /// This method is called by AliReconstruction if HasLocalReconstruction()==kTRUE
556   /// AND HasDigitConversion()==kTRUE
557   
558   AliCodeTimerAuto("")
559   
560   AliDebug(1,"");
561   
562   if (!digitsTree || !clustersTree) 
563   {
564     AliError(Form("Tree is null : digitsTree=%p clustersTree=%p",
565                   digitsTree,clustersTree));
566     return;
567   }
568
569   if (!fDigitStore)
570   {
571     fDigitStore = AliMUONVDigitStore::Create(*digitsTree);
572     if (!fDigitStore)
573     {
574       AliError(Form("Could not get DigitStore from %s",digitsTree->GetName()));
575     }
576     else
577     {
578       AliInfo(Form("Created %s from %s",fDigitStore->ClassName(),digitsTree->GetName()));
579     }
580   }
581   if (!fTriggerStore)
582   {
583     fTriggerStore = AliMUONVTriggerStore::Create(*digitsTree);
584     if (!fTriggerStore)
585     {
586       AliError(Form("Could not get TriggerStore from %s",digitsTree->GetName()));
587     }
588     else
589     {
590       AliInfo(Form("Created %s from %s",fTriggerStore->ClassName(),digitsTree->GetName()));
591     }
592   }
593   
594   if (!fTriggerStore && !fDigitStore)
595   {
596     AliError("No store at all. Nothing to do.");
597     return;
598   }
599   
600   // insure we start with empty stores
601   if ( fDigitStore ) 
602   {
603     fDigitStore->Clear(); 
604     Bool_t alone = ( fTriggerStore ? kFALSE : kTRUE );
605     Bool_t ok = fDigitStore->Connect(*digitsTree,alone);
606     if (!ok)
607     {
608       AliError("Could not connect digitStore to digitsTree");
609       return;
610     }
611   }
612   if ( fTriggerStore ) 
613   {
614     fTriggerStore->Clear();
615     Bool_t alone = ( fDigitStore ? kFALSE : kTRUE );
616     Bool_t ok = fTriggerStore->Connect(*digitsTree,alone);
617     if (!ok)
618     {
619       AliError("Could not connect triggerStore to digitsTree");
620       return;
621     }
622   }
623   
624   digitsTree->GetEvent(0);
625   
626   if ( fDigitStore ) 
627   {
628     // Insure we got calibrated digits (if we reconstruct from pure simulated,
629     // i.e. w/o going through raw data, this will be the case)
630     TIter next(fDigitStore->CreateIterator());
631     AliMUONVDigit* digit = static_cast<AliMUONVDigit*>(next());
632     if (!digit->IsCalibrated())
633     {
634       Calibrate(*fDigitStore);
635     }
636   }
637     
638   FillTreeR(fTriggerStore,*clustersTree);
639 }
640
641 //_____________________________________________________________________________
642 AliMUONVTriggerStore*
643 AliMUONReconstructor::TriggerStore() const
644 {
645   /// Return (and create if necessary and allowed) the trigger container
646   TString sopt(GetOption());
647   sopt.ToUpper();
648   
649   if (sopt.Contains("TRIGGERDISABLE"))
650   {
651     delete fTriggerStore;
652     fTriggerStore = 0x0;
653   }
654   else
655   {
656     if (!fTriggerStore)
657     {
658       fTriggerStore = new AliMUONTriggerStoreV1;
659     }
660   }
661   return fTriggerStore;
662 }