]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONReconstructor.cxx
In MUONRecoCheck.C:
[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 "AliMUONPadStatusMaker.h"
93 #include "AliMUONPreClusterFinder.h"
94 #include "AliMUONPreClusterFinderV2.h"
95 #include "AliMUONPreClusterFinderV3.h"
96 #include "AliMUONSimpleClusterServer.h"
97 #include "AliMUONTracker.h"
98 #include "AliMUONTriggerCircuit.h"
99 #include "AliMUONTriggerStoreV1.h"
100 #include "AliMUONVClusterFinder.h"
101 #include "AliMUONVClusterServer.h"
102 #include "AliMUONVTrackStore.h"
103 #include "AliMUONTriggerElectronics.h"
104
105 #include "AliMpArea.h"
106 #include "AliMpCDB.h"
107 #include "AliMpConstants.h"
108 #include "AliMpDDLStore.h"
109 #include "AliMpSegmentation.h"
110
111 #include "AliRawReader.h"
112 #include "AliCDBManager.h"
113 #include "AliCodeTimer.h"
114 #include "AliLog.h"
115 #include "AliRunInfo.h"
116
117 #include <Riostream.h>
118 #include <TObjArray.h>
119 #include <TClonesArray.h>
120 #include <TString.h>
121 #include <TTree.h>
122
123 /// \cond CLASSIMP
124 ClassImp(AliMUONReconstructor)
125 /// \endcond 
126
127 //_____________________________________________________________________________
128 AliMUONReconstructor::AliMUONReconstructor() : 
129 AliReconstructor(),
130 fDigitMaker(0x0),
131 fTransformer(new AliMUONGeometryTransformer()),
132 fDigitStore(0x0),
133 fTriggerCircuit(0x0),
134 fCalibrationData(0x0),
135 fDigitCalibrator(0x0),
136 fClusterServer(0x0),
137 fTriggerStore(0x0),
138 fTrackStore(0x0),
139 fClusterStore(0x0),
140 fTriggerProcessor(0x0)  
141 {
142   /// normal ctor
143
144   AliDebug(1,"");
145   
146   // Unload mapping objects
147   // if they have been loaded from the obsolete OCDB mapping objects
148
149   if ( AliMpDDLStore::Instance(false) ) {
150     AliCDBManager::Instance()->UnloadFromCache("MUON/Calib/DDLStore");
151     delete AliMpDDLStore::Instance();
152   }  
153
154   if ( AliMpSegmentation::Instance(false) ) { 
155     AliCDBManager::Instance()->UnloadFromCache("MUON/Calib/Mapping");
156     delete AliMpSegmentation::Instance();
157   }  
158
159   // Load mapping
160   if ( ! AliMpCDB::LoadDDLStore() ) {
161     AliFatal("Could not access mapping from OCDB !");
162   }
163   
164   // Load geometry data
165   fTransformer->LoadGeometryData();
166   
167 }
168
169 //_____________________________________________________________________________
170 AliMUONReconstructor::~AliMUONReconstructor()
171 {
172   /// dtor
173
174   AliDebug(1,"");
175
176   delete fDigitMaker;
177   delete fDigitStore;
178   delete fTransformer;
179   delete fTriggerCircuit;
180   delete fDigitCalibrator;
181   delete fCalibrationData;
182   delete fClusterServer;
183   delete fTriggerStore;
184   delete fTrackStore;
185   delete fClusterStore;
186   delete fTriggerProcessor;
187
188   delete AliMpSegmentation::Instance(false);
189   delete AliMpDDLStore::Instance(false);
190 }
191
192 //_____________________________________________________________________________
193 void
194 AliMUONReconstructor::Calibrate(AliMUONVDigitStore& digitStore) const
195 {
196   /// Calibrate the digitStore
197   if (!fDigitCalibrator)
198   {
199     CreateCalibrator();
200   }
201   AliCodeTimerAuto(Form("%s::Calibrate(AliMUONVDigitStore*)",fDigitCalibrator->ClassName()),0)
202   fDigitCalibrator->Calibrate(digitStore);      
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   // Skip reconstruction if event is Calibration
215   if ( GetRecoParam()->GetEventSpecie() == AliRecoParam::kCalib ) {
216     digitStore->Clear(); // Remove possible digits from previous event
217     triggerStore->Clear(); // Remove possible triggers from previous event
218     AliInfo("Calibration event: do not convert digits");
219     return;
220   }
221   
222   AliCodeTimerStart(Form("%s::Raw2Digits(AliRawReader*,AliMUONVDigitStore*,AliMUONVTriggerStore*)",
223                     fDigitMaker->ClassName()))
224   fDigitMaker->Raw2Digits(rawReader,digitStore,triggerStore);
225   AliCodeTimerStop(Form("%s::Raw2Digits(AliRawReader*,AliMUONVDigitStore*,AliMUONVTriggerStore*)",
226                          fDigitMaker->ClassName()))
227   Calibrate(*digitStore);
228 }
229
230 //_____________________________________________________________________________
231 void 
232 AliMUONReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
233 {
234    /// convert raw data into a digit tree
235   AliCodeTimerAuto("",0)
236
237   Bool_t alone = ( TriggerStore() == 0 );
238   
239   Bool_t ok = DigitStore()->Connect(*digitsTree,alone);
240   if ( TriggerStore() ) 
241   {
242     ok = ok && TriggerStore()->Connect(*digitsTree,kFALSE);
243   }
244   
245   if (!ok)
246   {
247     AliError("Could not make branches on TreeD");
248   }
249   else
250   {
251     ConvertDigits(rawReader,DigitStore(),TriggerStore());
252     AliCodeTimerStart("Fill digits")
253     digitsTree->Fill();
254     AliCodeTimerStop("Fill digits")
255     DigitStore()->Clear();
256   }
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("",0)
267
268   TString option = GetOption();
269   
270   Bool_t enableErrorLogging = kFALSE;
271
272   if (option.Contains("ENABLEERRORLOGGING"))
273   {
274     enableErrorLogging = kTRUE;
275   }
276
277   fDigitMaker = new AliMUONDigitMaker(enableErrorLogging);
278   option.ToUpper();
279   if ( option.Contains("SAVEDIGITS" ))
280     {
281       fDigitMaker->SetMakeTriggerDigits(kTRUE);
282     }
283 }
284
285 //_____________________________________________________________________________
286 void 
287 AliMUONReconstructor::CreateTriggerCircuit() const
288 {
289   /// Return (and create if necessary) the trigger circuit object
290   if (fTriggerCircuit) return;
291
292   AliCodeTimerAuto("",0)
293
294   fTriggerCircuit = new AliMUONTriggerCircuit(fTransformer);
295
296 }
297
298 //_____________________________________________________________________________
299 AliTracker* 
300 AliMUONReconstructor::CreateTracker() const
301 {
302   /// Create the MUONTracker object
303   
304   CreateTriggerCircuit();
305   CreateDigitMaker();
306   CreateClusterServer();
307
308   AliMUONTracker* tracker(0x0);
309   
310   if ( ! GetRecoParam()->CombineClusterTrackReco() )
311   {
312     tracker = new AliMUONTracker(GetRecoParam(),
313                                  0x0,
314                                  *DigitStore(),
315                                  fDigitMaker,
316                                  fTransformer,
317                                  fTriggerCircuit);
318   }
319   else
320   {
321     tracker = new AliMUONTracker(GetRecoParam(),
322                                  fClusterServer,
323                                  *DigitStore(),
324                                  fDigitMaker,
325                                  fTransformer,
326                                  fTriggerCircuit);
327   }
328   
329   
330   return tracker;
331 }
332
333 //_____________________________________________________________________________
334 AliMUONVClusterFinder*
335 AliMUONReconstructor::CreateClusterFinder(const char* clusterFinderType)
336 {
337   /// Create a given cluster finder instance
338   
339   AliCodeTimerAutoGeneral("",0)
340
341   AliMUONVClusterFinder* clusterFinder(0x0);
342   
343   TString opt(clusterFinderType);
344   opt.ToUpper();
345   
346   if ( strstr(opt,"PRECLUSTERV2") )
347   {
348     clusterFinder = new AliMUONPreClusterFinderV2;
349   }    
350   else if ( strstr(opt,"PRECLUSTERV3") )
351   {
352     clusterFinder = new AliMUONPreClusterFinderV3;
353   }  
354   else if ( strstr(opt,"PRECLUSTER") )
355   {
356     clusterFinder = new AliMUONPreClusterFinder;
357   }  
358   else if ( strstr(opt,"PEAKCOG") )
359   {
360     clusterFinder = new AliMUONClusterFinderPeakCOG(kFALSE,new AliMUONPreClusterFinder);
361   }
362   else if ( strstr(opt,"PEAKFIT") )
363   {
364     clusterFinder = new AliMUONClusterFinderPeakFit(kFALSE,new AliMUONPreClusterFinder);
365   }
366   else if ( strstr(opt,"COG") )
367   {
368     clusterFinder = new AliMUONClusterFinderCOG(new AliMUONPreClusterFinder);
369   }  
370   else if ( strstr(opt,"SIMPLEFITV3") )
371   {
372     clusterFinder = new AliMUONClusterFinderSimpleFit(new AliMUONClusterFinderCOG(new AliMUONPreClusterFinderV3));
373   }
374   else if ( strstr(opt,"SIMPLEFIT") )
375   {
376     clusterFinder = new AliMUONClusterFinderSimpleFit(new AliMUONClusterFinderCOG(new AliMUONPreClusterFinder));
377   }
378   else if ( strstr(opt,"MLEM:DRAW") )
379   {
380     clusterFinder = new AliMUONClusterFinderMLEM(kTRUE,new AliMUONPreClusterFinder);
381   }
382   else if ( strstr(opt,"MLEMV3") )
383   {
384     clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinderV3);
385   } 
386   else if ( strstr(opt,"MLEMV2") )
387   {
388     clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinderV2);
389   } 
390   else if ( strstr(opt,"MLEM") )
391   {
392     clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinder);
393   } 
394   else
395   {
396     AliErrorClass(Form("clustering mode \"%s\" does not exist",opt.Data()));
397     return 0x0;
398   }
399   
400   return clusterFinder;
401 }
402
403 //_____________________________________________________________________________
404 void
405 AliMUONReconstructor::CreateClusterServer() const
406 {
407   /// Create cluster server
408   
409   if ( fClusterServer ) return;
410   
411   AliCodeTimerAuto("",0);
412     
413   AliMUONVClusterFinder* clusterFinder = CreateClusterFinder(GetRecoParam()->GetClusteringMode());
414   
415   if ( !clusterFinder ) return;
416   
417   AliInfo(Form("Will use %s for clusterizing",clusterFinder->ClassName()));
418   
419   fClusterServer = new AliMUONSimpleClusterServer(clusterFinder,*fTransformer);
420 }
421
422 //_____________________________________________________________________________
423 void
424 AliMUONReconstructor::CreateCalibrationData() const
425 {
426   /// Create the calibrator
427   
428   AliCodeTimerAuto("",0);
429   
430   Int_t runNumber = AliCDBManager::Instance()->GetRun();
431
432   fCalibrationData = new AliMUONCalibrationData(runNumber);
433   if ( !fCalibrationData->IsValid() )
434   {
435     AliError("Could not retrieve calibrations !");
436     delete fCalibrationData;
437     fCalibrationData = 0x0;
438     return;
439   }    
440   
441   // It is now time to check whether we have everything to proceed.
442   // What we need depends on whether both tracker and trigger
443   // are in the readout chain, and what specific "bad channel policy"
444   // we use
445   
446   Bool_t kTracker(kFALSE);
447   Bool_t kTrigger(kFALSE);
448   
449   const AliRunInfo* runInfo = GetRunInfo();
450   if (!runInfo)
451   {
452     AliError("Could not get runinfo ?")
453   }
454   else
455   {
456     TString detectors(runInfo->GetActiveDetectors());
457     if (detectors.Contains("MUONTRK")) kTracker=kTRUE;
458     if (detectors.Contains("MUONTRG")) kTrigger=kTRUE;
459   }
460    
461   AliInfo(Form("Run with MUON TRIGGER : %s and MUON TRACKER : %s",
462                kTrigger ? "YES":"NO" , 
463                kTracker ? "YES":"NO"));
464   
465   if ( kTracker ) 
466   {
467     // Check that we get all the calibrations we'll need
468     if ( !fCalibrationData->Pedestals() ||
469         !fCalibrationData->Gains() )
470     {
471       AliFatal(Form("Could not access all required calibration data (PED %p GAIN %p)",
472                     fCalibrationData->Pedestals(),fCalibrationData->Gains()));      
473     }
474     
475     if ( !fCalibrationData->HV() ) 
476     {
477       // Special treatment of HV. We only break if the values
478       // are not there *AND* we cut on them.
479       UInt_t mask = GetRecoParam()->PadGoodnessMask();
480       TString smask(AliMUONPadStatusMaker::AsCondition(mask));
481       if ( smask.Contains("HV") )
482       {
483         AliFatal("Could not access all required calibration data (HV)");      
484       }
485     } 
486   }
487 }
488
489 //_____________________________________________________________________________
490 void
491 AliMUONReconstructor::CreateCalibrator() const
492 {
493   /// Create the calibrator
494
495   AliCodeTimerAuto("",0);
496
497   if ( ! fCalibrationData )
498     CreateCalibrationData();
499
500   AliInfo("Calibration will occur.");
501
502   TString opt(GetOption());
503   opt.ToUpper();
504   
505   if ( strstr(opt,"NOSTATUSMAP") )
506   {
507     AliWarning("NOSTATUSMAP is obsolete");
508   }
509
510   TString calibMode = GetRecoParam()->GetCalibrationMode();
511
512   fDigitCalibrator = new AliMUONDigitCalibrator(*fCalibrationData,GetRecoParam(),calibMode.Data());
513 }
514
515 //_____________________________________________________________________________
516 void
517 AliMUONReconstructor::ResponseRemovingChambers(AliMUONVTriggerStore* triggerStore) const
518 {
519   /// Update trigger information with informatins obtained after
520   /// re-calculation of trigger response
521   AliCodeTimerAuto("",0);
522
523   if ( ! fCalibrationData )
524     CreateCalibrationData();
525
526   if ( ! fTriggerProcessor )
527     fTriggerProcessor = new AliMUONTriggerElectronics(fCalibrationData);
528
529   fTriggerProcessor->ResponseRemovingChambers(*triggerStore);
530 }
531
532 //_____________________________________________________________________________
533 AliMUONVDigitStore*
534 AliMUONReconstructor::DigitStore() const
535 {
536   /// Return (and create if necessary) the digit container
537   if (!fDigitStore) 
538   {
539     TString sopt(GetOption());
540     sopt.ToUpper();
541     
542     AliInfo(Form("Options=%s",sopt.Data()));
543     
544     if ( sopt.Contains("DIGITSTOREV1") )
545     {
546       fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV1");
547     }
548     else if ( sopt.Contains("DIGITSTOREV2R") ) 
549     {
550       fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2R");
551     }
552     else if ( sopt.Contains("DIGITSTOREV2S") ) 
553     {
554       fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2S");
555     }
556     
557     if (!fDigitStore) fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2R");
558     
559     AliInfo(Form("Will use %s to store digits during reconstruction",fDigitStore->ClassName()));
560   }
561   return fDigitStore;
562 }
563
564 //_____________________________________________________________________________
565 void
566 AliMUONReconstructor::FillTreeR(AliMUONVTriggerStore* triggerStore,
567                                 TTree& clustersTree) const
568 {
569   /// Write the trigger and cluster information into TreeR
570   
571   AliCodeTimerAuto("",0)
572
573   AliDebug(1,"");
574   
575   Bool_t ok(kFALSE);
576   Bool_t alone(kTRUE); // is trigger the only info in TreeR ?
577   
578   if ( ! GetRecoParam()->CombineClusterTrackReco() )
579   {
580     alone = kFALSE; // we'll get both tracker and trigger information in TreeR
581   }
582   
583   if ( triggerStore ) 
584   {
585     ResponseRemovingChambers(triggerStore);
586     ok = triggerStore->Connect(clustersTree,alone);
587     if (!ok)
588     {
589       AliError("Could not create triggerStore branches in TreeR");
590     }
591   }
592
593   if ( !alone )
594   {
595     if (!fClusterStore)
596     {
597       fClusterStore = new AliMUONClusterStoreV2;
598     }
599     
600     CreateClusterServer();
601     
602     TIter next(DigitStore()->CreateIterator());
603     fClusterServer->UseDigits(next,DigitStore());
604
605     AliMpArea area;
606     
607     AliDebug(1,Form("Doing full clusterization in local reconstruction using %s ",fClusterServer->ClassName()));
608     
609     for ( Int_t i = 0; i < AliMpConstants::NofTrackingChambers(); ++i ) 
610     {
611       if (GetRecoParam()->UseChamber(i))
612       {
613         if ( ( i == 6 || i == 7 )  && GetRecoParam()->BypassSt4() ) continue;
614         if ( ( i == 8 || i == 9 )  && GetRecoParam()->BypassSt5() ) continue;
615         
616         fClusterServer->Clusterize(i,*fClusterStore,area,GetRecoParam());
617       }
618     }
619     
620     Bool_t cok = fClusterStore->Connect(clustersTree,alone);
621     
622     if (!cok) AliError("Could not connect clusterStore to clusterTree");
623     
624     AliDebug(1,Form("Number of clusters found = %d",fClusterStore->GetSize()));
625     
626     StdoutToAliDebug(1,fClusterStore->Print());
627   }
628          
629   if (ok) // at least one type of branches created successfully
630   {
631     clustersTree.Fill();
632   }
633   
634   if (fClusterStore) fClusterStore->Clear();
635 }
636
637 //_____________________________________________________________________________
638 Bool_t 
639 AliMUONReconstructor::HasDigitConversion() const
640 {
641   /// We *do* have digit conversion, but we might advertise it only 
642   /// if we want to save the digits.
643   
644   TString opt(GetOption());
645   opt.ToUpper();
646   if ( opt.Contains("SAVEDIGITS" ) && !opt.Contains("NOLOCALRECONSTRUCTION") )
647   {
648     return kTRUE;
649   }
650   else
651   {
652     return kFALSE;
653   }
654 }
655
656 //_____________________________________________________________________________
657 void 
658 AliMUONReconstructor::Reconstruct(AliRawReader* rawReader, TTree* clustersTree) const
659 {
660   /// This method is called by AliReconstruction if HasLocalReconstruction()==kTRUE AND
661   /// HasDigitConversion()==kFALSE
662   
663   if ( !clustersTree ) 
664   {
665     AliError("clustersTree is 0x0 !");
666     return;
667   }
668   
669   ConvertDigits(rawReader,DigitStore(),TriggerStore());
670
671   FillTreeR(TriggerStore(),*clustersTree);
672 }
673
674 //_____________________________________________________________________________
675 void 
676 AliMUONReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
677 {
678   /// This method is called by AliReconstruction if HasLocalReconstruction()==kTRUE
679   /// AND HasDigitConversion()==kTRUE
680   
681   AliCodeTimerAuto("",0)
682   
683   AliDebug(1,"");
684   
685   if (!digitsTree || !clustersTree) 
686   {
687     AliError(Form("Tree is null : digitsTree=%p clustersTree=%p",
688                   digitsTree,clustersTree));
689     return;
690   }
691
692   if (!fDigitStore)
693   {
694     fDigitStore = AliMUONVDigitStore::Create(*digitsTree);
695     if (!fDigitStore)
696     {
697       AliError(Form("Could not get DigitStore from %s",digitsTree->GetName()));
698     }
699     else
700     {
701       AliInfo(Form("Created %s from %s",fDigitStore->ClassName(),digitsTree->GetName()));
702     }
703   }
704   if (!fTriggerStore)
705   {
706     fTriggerStore = AliMUONVTriggerStore::Create(*digitsTree);
707     if (!fTriggerStore)
708     {
709       AliError(Form("Could not get TriggerStore from %s",digitsTree->GetName()));
710     }
711     else
712     {
713       AliInfo(Form("Created %s from %s",fTriggerStore->ClassName(),digitsTree->GetName()));
714     }
715   }
716   
717   if (!fTriggerStore && !fDigitStore)
718   {
719     AliError("No store at all. Nothing to do.");
720     return;
721   }
722   
723   // insure we start with empty stores
724   if ( fDigitStore ) 
725   {
726     fDigitStore->Clear(); 
727     Bool_t alone = ( fTriggerStore ? kFALSE : kTRUE );
728     Bool_t ok = fDigitStore->Connect(*digitsTree,alone);
729     if (!ok)
730     {
731       AliError("Could not connect digitStore to digitsTree");
732       return;
733     }
734   }
735   if ( fTriggerStore ) 
736   {
737     fTriggerStore->Clear();
738     Bool_t alone = ( fDigitStore ? kFALSE : kTRUE );
739     Bool_t ok = fTriggerStore->Connect(*digitsTree,alone);
740     if (!ok)
741     {
742       AliError("Could not connect triggerStore to digitsTree");
743       return;
744     }
745   }
746   
747   digitsTree->GetEvent(0);
748   
749   if ( fDigitStore ) 
750   {
751     // Insure we got calibrated digits (if we reconstruct from pure simulated,
752     // i.e. w/o going through raw data, this will be the case)
753     TIter next(fDigitStore->CreateIterator());
754     AliMUONVDigit* digit = static_cast<AliMUONVDigit*>(next());
755     if (digit && !digit->IsCalibrated())
756     {
757       Calibrate(*fDigitStore);
758     }
759   }
760     
761   FillTreeR(fTriggerStore,*clustersTree);
762 }
763
764 //_____________________________________________________________________________
765 AliMUONVTriggerStore*
766 AliMUONReconstructor::TriggerStore() const
767 {
768   /// Return (and create if necessary and allowed) the trigger container
769   TString sopt(GetOption());
770   sopt.ToUpper();
771   
772   if (sopt.Contains("TRIGGERDISABLE"))
773   {
774     delete fTriggerStore;
775     fTriggerStore = 0x0;
776   }
777   else
778   {
779     if (!fTriggerStore)
780     {
781       fTriggerStore = new AliMUONTriggerStoreV1;
782     }
783   }
784   return fTriggerStore;
785 }