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