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