]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONReconstructor.cxx
Adding options:
[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   fClusterServer->UseDigitStore(*(DigitStore()));
316   
317   AliMUONTracker* tracker = new AliMUONTracker(*fClusterServer,
318                                                fDigitMaker,
319                                                fTransformer,
320                                                fTriggerCircuit);
321   
322   return tracker;
323 }
324
325 //_____________________________________________________________________________
326 AliMUONVClusterFinder*
327 AliMUONReconstructor::CreateClusterFinder(const char* clusterFinderType) const
328 {
329   /// Create a given cluster finder instance
330   
331   AliCodeTimerAuto("")
332
333   AliMUONVClusterFinder* clusterFinder(0x0);
334   
335   TString opt(clusterFinderType);
336   opt.ToUpper();
337   
338   if ( strstr(opt,"PRECLUSTERV2") )
339   {
340     clusterFinder = new AliMUONPreClusterFinderV2;
341   }    
342   else if ( strstr(opt,"PRECLUSTERV3") )
343   {
344     clusterFinder = new AliMUONPreClusterFinderV3;
345   }  
346   else if ( strstr(opt,"PRECLUSTER") )
347   {
348     clusterFinder = new AliMUONPreClusterFinder;
349   }  
350   else if ( strstr(opt,"PEAKCOG") )
351   {
352     clusterFinder = new AliMUONClusterFinderPeakCOG(kFALSE,new AliMUONPreClusterFinder);
353   }
354   else if ( strstr(opt,"PEAKFIT") )
355   {
356     clusterFinder = new AliMUONClusterFinderPeakFit(kFALSE,new AliMUONPreClusterFinder);
357   }
358   else if ( strstr(opt,"COG") )
359   {
360     clusterFinder = new AliMUONClusterFinderCOG(new AliMUONPreClusterFinder);
361   }  
362   else if ( strstr(opt,"SIMPLEFITV3") )
363   {
364     clusterFinder = new AliMUONClusterFinderSimpleFit(new AliMUONClusterFinderCOG(new AliMUONPreClusterFinderV3));
365   }
366   else if ( strstr(opt,"SIMPLEFIT") )
367   {
368     clusterFinder = new AliMUONClusterFinderSimpleFit(new AliMUONClusterFinderCOG(new AliMUONPreClusterFinder));
369   }
370   else if ( strstr(opt,"MLEM:DRAW") )
371   {
372     clusterFinder = new AliMUONClusterFinderMLEM(kTRUE,new AliMUONPreClusterFinder);
373   }
374   else if ( strstr(opt,"MLEMV3") )
375   {
376     clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinderV3);
377   } 
378   else if ( strstr(opt,"MLEMV2") )
379   {
380     clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinderV2);
381   } 
382   else if ( strstr(opt,"MLEM") )
383   {
384     clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinder);
385   } 
386   else
387   {
388     AliError(Form("clustering mode \"%s\" does not exist",opt.Data()));
389     return 0x0;
390   }
391   
392   return clusterFinder;
393 }
394
395 //_____________________________________________________________________________
396 void
397 AliMUONReconstructor::CreateClusterServer() const
398 {
399   /// Create cluster server
400   
401   if ( fClusterServer ) return;
402   
403   AliCodeTimerAuto("")
404
405   AliDebug(1,"");
406   
407   AliMUONVClusterFinder* clusterFinder = CreateClusterFinder(GetRecoParam()->GetClusteringMode());
408   
409   if ( !clusterFinder ) return;
410   
411   AliInfo(Form("Will use %s for clusterizing",clusterFinder->ClassName()));
412   
413   fClusterServer = new AliMUONSimpleClusterServer(*clusterFinder,*fTransformer);
414 }
415
416 //_____________________________________________________________________________
417 void
418 AliMUONReconstructor::CreateCalibrator() const
419 {
420   /// Create the calibrator
421   
422   AliCodeTimerAuto("")
423   
424   Int_t runNumber = AliCDBManager::Instance()->GetRun();
425
426   AliInfo("Calibration will occur.");
427   
428   fCalibrationData = new AliMUONCalibrationData(runNumber);
429   if ( !fCalibrationData->IsValid() )
430   {
431     AliError("Could not retrieve calibrations !");
432     delete fCalibrationData;
433     fCalibrationData = 0x0;
434     return;
435   }    
436   
437   // Check that we get all the calibrations we'll need
438   if ( !fCalibrationData->Pedestals() ||
439        !fCalibrationData->Gains() ||
440        !fCalibrationData->HV() )
441   {
442     AliFatal("Could not access all required calibration data");
443   }
444   
445   TString opt(GetOption());
446   opt.ToUpper();
447   
448   if ( strstr(opt,"NOSTATUSMAP") )
449   {
450     AliWarning("NOSTATUSMAP is obsolete");
451   }
452
453   fDigitCalibrator = new AliMUONDigitCalibrator(*fCalibrationData);
454 }
455
456 //_____________________________________________________________________________
457 AliMUONVDigitStore*
458 AliMUONReconstructor::DigitStore() const
459 {
460   /// Return (and create if necessary) the digit container
461   if (!fDigitStore) 
462   {
463     TString sopt(GetOption());
464     sopt.ToUpper();
465     
466     AliInfo(Form("Options=%s",sopt.Data()));
467     
468     if ( sopt.Contains("DIGITSTOREV1") )
469     {
470       fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV1");
471     }
472     else if ( sopt.Contains("DIGITSTOREV2R") ) 
473     {
474       fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2R");
475     }
476     else if ( sopt.Contains("DIGITSTOREV2S") ) 
477     {
478       fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2S");
479     }
480     
481     if (!fDigitStore) fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2R");
482     
483     AliInfo(Form("Will use %s to store digits during reconstruction",fDigitStore->ClassName()));
484   }
485   return fDigitStore;
486 }
487
488 //_____________________________________________________________________________
489 void
490 AliMUONReconstructor::FillTreeR(AliMUONVTriggerStore* triggerStore,
491                                 TTree& clustersTree) const
492 {
493   /// Write the trigger and cluster information into TreeR
494   
495   AliCodeTimerAuto("")
496
497   AliDebug(1,"");
498   
499   Bool_t ok(kFALSE);
500   if ( triggerStore ) 
501   {
502     ok = triggerStore->Connect(clustersTree,kTRUE);
503     if (!ok)
504     {
505       AliError("Could not create triggerStore branches in TreeR");
506     }
507   }
508   
509   if (ok) // at least one type of branches created successfully
510   {
511     clustersTree.Fill();
512   }
513 }
514
515 //_____________________________________________________________________________
516 Bool_t 
517 AliMUONReconstructor::HasDigitConversion() const
518 {
519   /// We *do* have digit conversion, but we might advertise it only 
520   /// if we want to save the digits.
521   
522   TString opt(GetOption());
523   opt.ToUpper();
524   if ( opt.Contains("SAVEDIGITS" ) && !opt.Contains("NOLOCALRECONSTRUCTION") )
525   {
526     return kTRUE;
527   }
528   else
529   {
530     return kFALSE;
531   }
532 }
533
534 //_____________________________________________________________________________
535 void 
536 AliMUONReconstructor::Reconstruct(AliRawReader* rawReader, TTree* clustersTree) const
537 {
538   /// This method is called by AliReconstruction if HasLocalReconstruction()==kTRUE AND
539   /// HasDigitConversion()==kFALSE
540   
541   if ( !clustersTree ) 
542   {
543     AliError("clustersTree is 0x0 !");
544     return;
545   }
546   
547   ConvertDigits(rawReader,DigitStore(),TriggerStore());
548
549   FillTreeR(TriggerStore(),*clustersTree);
550 }
551
552 //_____________________________________________________________________________
553 void 
554 AliMUONReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
555 {
556   /// This method is called by AliReconstruction if HasLocalReconstruction()==kTRUE
557   /// AND HasDigitConversion()==kTRUE
558   
559   AliCodeTimerAuto("")
560   
561   AliDebug(1,"");
562   
563   if (!digitsTree || !clustersTree) 
564   {
565     AliError(Form("Tree is null : digitsTree=%p clustersTree=%p",
566                   digitsTree,clustersTree));
567     return;
568   }
569
570   if (!fDigitStore)
571   {
572     fDigitStore = AliMUONVDigitStore::Create(*digitsTree);
573     if (!fDigitStore)
574     {
575       AliError(Form("Could not get DigitStore from %s",digitsTree->GetName()));
576     }
577     else
578     {
579       AliInfo(Form("Created %s from %s",fDigitStore->ClassName(),digitsTree->GetName()));
580     }
581   }
582   if (!fTriggerStore)
583   {
584     fTriggerStore = AliMUONVTriggerStore::Create(*digitsTree);
585     if (!fTriggerStore)
586     {
587       AliError(Form("Could not get TriggerStore from %s",digitsTree->GetName()));
588     }
589     else
590     {
591       AliInfo(Form("Created %s from %s",fTriggerStore->ClassName(),digitsTree->GetName()));
592     }
593   }
594   
595   if (!fTriggerStore && !fDigitStore)
596   {
597     AliError("No store at all. Nothing to do.");
598     return;
599   }
600   
601   // insure we start with empty stores
602   if ( fDigitStore ) 
603   {
604     fDigitStore->Clear(); 
605     Bool_t alone = ( fTriggerStore ? kFALSE : kTRUE );
606     Bool_t ok = fDigitStore->Connect(*digitsTree,alone);
607     if (!ok)
608     {
609       AliError("Could not connect digitStore to digitsTree");
610       return;
611     }
612   }
613   if ( fTriggerStore ) 
614   {
615     fTriggerStore->Clear();
616     Bool_t alone = ( fDigitStore ? kFALSE : kTRUE );
617     Bool_t ok = fTriggerStore->Connect(*digitsTree,alone);
618     if (!ok)
619     {
620       AliError("Could not connect triggerStore to digitsTree");
621       return;
622     }
623   }
624   
625   digitsTree->GetEvent(0);
626   
627   if ( fDigitStore ) 
628   {
629     // Insure we got calibrated digits (if we reconstruct from pure simulated,
630     // i.e. w/o going through raw data, this will be the case)
631     TIter next(fDigitStore->CreateIterator());
632     AliMUONVDigit* digit = static_cast<AliMUONVDigit*>(next());
633     if (!digit->IsCalibrated())
634     {
635       Calibrate(*fDigitStore);
636     }
637   }
638     
639   FillTreeR(fTriggerStore,*clustersTree);
640 }
641
642 //_____________________________________________________________________________
643 AliMUONVTriggerStore*
644 AliMUONReconstructor::TriggerStore() const
645 {
646   /// Return (and create if necessary and allowed) the trigger container
647   TString sopt(GetOption());
648   sopt.ToUpper();
649   
650   if (sopt.Contains("TRIGGERDISABLE"))
651   {
652     delete fTriggerStore;
653     fTriggerStore = 0x0;
654   }
655   else
656   {
657     if (!fTriggerStore)
658     {
659       fTriggerStore = new AliMUONTriggerStoreV1;
660     }
661   }
662   return fTriggerStore;
663 }