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