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