- TClonesArray* recTracksArray = 0;
- TClonesArray* recTrigTracksArray = 0;
-
- AliLoader* loader = runLoader->GetLoader("MUONLoader");
- loader->LoadTracks("READ");
- AliMUONData* muonData = new AliMUONData(loader,"MUON","MUON");
-
- // declaration
- Int_t iEvent;// nPart;
- Int_t nTrackHits;// nPrimary;
- Double_t fitFmin;
- TArrayF vertex(3);
-
- Double_t bendingSlope, nonBendingSlope, inverseBendingMomentum;
- Double_t xRec, yRec, zRec, chi2MatchTrigger;
- Bool_t matchTrigger;
-
- // setting pointer for tracks, triggertracks & trackparam at vertex
- AliMUONTrack* recTrack = 0;
- AliMUONTrackParam* trackParam = 0;
- AliMUONTriggerTrack* recTriggerTrack = 0;
-// TParticle* particle = new TParticle();
-// AliGenEventHeader* header = 0;
- iEvent = runLoader->GetEventNumber();
- runLoader->GetEvent(iEvent);
-
- // vertex calculation (maybe it exists already somewhere else)
- vertex[0] = vertex[1] = vertex[2] = 0.;
- // nPrimary = 0;
-// if ( (header = runLoader->GetHeader()->GenEventHeader()) ) {
-// header->PrimaryVertex(vertex);
-// } else {
-// runLoader->LoadKinematics("READ");
-// runLoader->TreeK()->GetBranch("Particles")->SetAddress(&particle);
-// nPart = (Int_t)runLoader->TreeK()->GetEntries();
-// for(Int_t iPart = 0; iPart < nPart; iPart++) {
-// runLoader->TreeK()->GetEvent(iPart);
-// if (particle->GetFirstMother() == -1) {
-// vertex[0] += particle->Vx();
-// vertex[1] += particle->Vy();
-// vertex[2] += particle->Vz();
-// nPrimary++;
-// }
-// if (nPrimary) {
-// vertex[0] /= (double)nPrimary;
-// vertex[1] /= (double)nPrimary;
-// vertex[2] /= (double)nPrimary;
-// }
-// }
-// }
- // setting ESD MUON class
- AliESDMuonTrack* theESDTrack = new AliESDMuonTrack() ;
-
- //-------------------- trigger tracks-------------
- Long_t trigPat = 0;
- muonData->SetTreeAddress("RL");
- muonData->GetRecTriggerTracks();
- recTrigTracksArray = muonData->RecTriggerTracks();
-
- // ready global trigger pattern from first track
- if (recTrigTracksArray)
- recTriggerTrack = (AliMUONTriggerTrack*) recTrigTracksArray->First();
- if (recTriggerTrack) trigPat = recTriggerTrack->GetGTPattern();
-
- //printf(">>> Event %d Number of Recconstructed tracks %d \n",iEvent, nrectracks);
-
- // -------------------- tracks-------------
- muonData->SetTreeAddress("RT");
- muonData->GetRecTracks();
- recTracksArray = muonData->RecTracks();
+ /// convert raw data into a digit tree
+ AliCodeTimerAuto("",0)
+
+ Bool_t alone = ( TriggerStore() == 0 );
+
+ Bool_t ok = DigitStore()->Connect(*digitsTree,alone);
+ if ( TriggerStore() )
+ {
+ ok = ok && TriggerStore()->Connect(*digitsTree,kFALSE);
+ }
+
+ if (!ok)
+ {
+ AliError("Could not make branches on TreeD");
+ }
+ else
+ {
+ ConvertDigits(rawReader,DigitStore(),TriggerStore());
+ AliCodeTimerStart("Fill digits")
+ digitsTree->Fill();
+ AliCodeTimerStop("Fill digits")
+ DigitStore()->Clear();
+ }
+}
+
+//_____________________________________________________________________________
+void
+AliMUONReconstructor::CreateDigitMaker() const
+{
+ /// Create (and create if necessary) the digit maker
+ if (fDigitMaker) return;
+
+ AliCodeTimerAuto("",0)
+
+ TString option = GetOption();
+
+ Bool_t enableErrorLogging = kFALSE;
+
+ if (option.Contains("ENABLEERRORLOGGING"))
+ {
+ enableErrorLogging = kTRUE;
+ }
+
+ fDigitMaker = new AliMUONDigitMaker(enableErrorLogging);
+ option.ToUpper();
+
+ // Always make trigger digits
+ // (needed when calculating trigger chamber efficiency)
+ fDigitMaker->SetMakeTriggerDigits(kTRUE);
+
+ if ( GetRecoParam()->TryRecover() )
+ {
+ fDigitMaker->SetTryRecover(kTRUE);
+ }
+ else
+ {
+ fDigitMaker->SetTryRecover(kFALSE);
+ }
+}
+
+//_____________________________________________________________________________
+void
+AliMUONReconstructor::CreateTriggerCircuit() const
+{
+ /// Return (and create if necessary) the trigger circuit object
+ if (fTriggerCircuit) return;
+
+ AliCodeTimerAuto("",0)
+
+ fTriggerCircuit = new AliMUONTriggerCircuit(fTransformer);
+
+}
+
+//_____________________________________________________________________________
+void
+AliMUONReconstructor::CreateTriggerUtilities() const
+{
+ /// Return (and create if necessary) the trigger utilities object
+ if ( fTriggerUtilities ) return;
+
+ AliCodeTimerAuto("",0)
+
+ if ( ! fCalibrationData ) CreateCalibrationData();
+
+ fTriggerUtilities = new AliMUONTriggerUtilities(fCalibrationData);
+}
+
+//_____________________________________________________________________________
+AliTracker*
+AliMUONReconstructor::CreateTracker() const
+{
+ /// Create the MUONTracker object
+
+ CreateTriggerCircuit();
+ CreateTriggerUtilities();
+
+ const AliMUONRecoParam* rp = GetRecoParam();
+
+ Int_t es = rp->GetEventSpecie();
+
+ AliTracker* tracker = static_cast<AliTracker*>(fTrackers.At(es));
+
+ if (!tracker )
+ {
+ if ( ! rp->CombineClusterTrackReco() )
+ {
+ tracker = new AliMUONTracker(rp,
+ 0x0,
+ *DigitStore(),
+ fTransformer,
+ fTriggerCircuit,
+ fTriggerUtilities);
+
+ AliInfo(Form("Created tracker %p for recoparam of type %s es=%d",
+ tracker,
+ AliRecoParam::GetEventSpecieName(AliRecoParam::Convert(rp->GetEventSpecie())),es));
+ }
+ else
+ {
+
+ tracker = new AliMUONTracker(rp,
+ CreateClusterServer(*rp),
+ *DigitStore(),
+ fTransformer,
+ fTriggerCircuit,
+ fTriggerUtilities);
+
+ AliInfo(Form("Created (combined) tracker %p for recoparam of type %s es=%d",
+ tracker,
+ AliRecoParam::GetEventSpecieName(AliRecoParam::Convert(rp->GetEventSpecie())),es));
+ }
+
+ fTrackers.AddAtAndExpand(tracker,es);
+ }
+
+
+ return tracker;
+}
+
+//_____________________________________________________________________________
+AliMUONVClusterFinder*
+AliMUONReconstructor::CreateClusterFinder(const char* clusterFinderType)
+{
+ /// Create a given cluster finder instance
+
+ AliCodeTimerAutoGeneral("",0)
+
+ AliMUONVClusterFinder* clusterFinder(0x0);
+
+ TString opt(clusterFinderType);
+ opt.ToUpper();
+
+ if ( strstr(opt,"PRECLUSTERV2") )
+ {
+ clusterFinder = new AliMUONPreClusterFinderV2;
+ }
+ else if ( strstr(opt,"PRECLUSTERV3") )
+ {
+ clusterFinder = new AliMUONPreClusterFinderV3;
+ }
+ else if ( strstr(opt,"PRECLUSTER") )
+ {
+ clusterFinder = new AliMUONPreClusterFinder;
+ }
+ else if ( strstr(opt,"PEAKCOG") )
+ {
+ clusterFinder = new AliMUONClusterFinderPeakCOG(kFALSE,new AliMUONPreClusterFinder);
+ }
+ else if ( strstr(opt,"PEAKFIT") )
+ {
+ clusterFinder = new AliMUONClusterFinderPeakFit(kFALSE,new AliMUONPreClusterFinder);
+ }
+ else if ( strstr(opt,"COG") )
+ {
+ clusterFinder = new AliMUONClusterFinderCOG(new AliMUONPreClusterFinder);
+ }
+ else if ( strstr(opt,"SIMPLEFITV3") )
+ {
+ clusterFinder = new AliMUONClusterFinderSimpleFit(new AliMUONClusterFinderCOG(new AliMUONPreClusterFinderV3));
+ }
+ else if ( strstr(opt,"SIMPLEFIT") )
+ {
+ clusterFinder = new AliMUONClusterFinderSimpleFit(new AliMUONClusterFinderCOG(new AliMUONPreClusterFinder));
+ }
+ else if ( strstr(opt,"MLEM:DRAW") )
+ {
+ clusterFinder = new AliMUONClusterFinderMLEM(kTRUE,new AliMUONPreClusterFinder);
+ }
+ else if ( strstr(opt,"MLEMV3") )
+ {
+ clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinderV3);
+ }
+ else if ( strstr(opt,"MLEMV2") )
+ {
+ clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinderV2);
+ }
+ else if ( strstr(opt,"MLEM") )
+ {
+ clusterFinder = new AliMUONClusterFinderMLEM(kFALSE,new AliMUONPreClusterFinder);
+ }
+ else
+ {
+ AliErrorClass(Form("clustering mode \"%s\" does not exist",opt.Data()));
+ return 0x0;
+ }
+
+ return clusterFinder;
+}
+
+//_____________________________________________________________________________
+AliMUONVClusterServer*
+AliMUONReconstructor::CreateClusterServer(const AliMUONRecoParam& rp) const
+{
+ /// Create cluster server
+
+ AliCodeTimerAuto("",0);
+
+ AliMUONVClusterServer* clusterServer = static_cast<AliMUONVClusterServer*>(fClusterServers.At(rp.GetEventSpecie()));
+
+ if (!clusterServer )
+ {
+ AliMUONVClusterFinder* clusterFinder = CreateClusterFinder(rp.GetClusteringMode());
+
+ if ( !clusterFinder ) return 0x0;
+
+ clusterServer = new AliMUONSimpleClusterServer(clusterFinder,*fTransformer);
+
+ AliInfo(Form("Created AliMUONSimpleClusterServer (%p) for specie %d with clustering = %s (following requesting clustering mode %s)",
+ clusterServer,rp.GetEventSpecie(),clusterFinder->ClassName(),rp.GetClusteringMode()));
+
+ fClusterServers.AddAtAndExpand(clusterServer,rp.GetEventSpecie());
+ }
+
+ return clusterServer;
+}
+
+//_____________________________________________________________________________
+void
+AliMUONReconstructor::CreateCalibrationData() const
+{
+ /// Create the calibrator
+
+ AliCodeTimerAuto("",0);
+
+ Int_t runNumber = AliCDBManager::Instance()->GetRun();
+
+ fCalibrationData = new AliMUONCalibrationData(runNumber);
+ if ( !fCalibrationData->IsValid() )
+ {
+ AliError("Could not retrieve calibrations !");
+ delete fCalibrationData;
+ fCalibrationData = 0x0;
+ return;
+ }
+
+ // It is now time to check whether we have everything to proceed.
+ // What we need depends on whether both tracker and trigger
+ // are in the readout chain, and what specific "bad channel policy"
+ // we use
+
+ Bool_t kTracker(kFALSE);
+ Bool_t kTrigger(kFALSE);
+
+ const AliRunInfo* runInfo = GetRunInfo();
+ if (!runInfo)
+ {
+ AliError("Could not get runinfo ?");
+ }
+ else
+ {
+ TString detectors(runInfo->GetActiveDetectors());
+ if (detectors.Contains("MUONTRK")) kTracker=kTRUE;
+ if (detectors.Contains("MUONTRG")) kTrigger=kTRUE;
+ }
+
+ AliInfo(Form("Run with MUON TRIGGER : %s and MUON TRACKER : %s",
+ kTrigger ? "YES":"NO" ,
+ kTracker ? "YES":"NO"));
+
+ if ( kTracker )
+ {
+ // Check that we get all the calibrations we'll need
+ if ( !fCalibrationData->Pedestals() ||
+ !fCalibrationData->Gains() )
+ {
+ AliFatal(Form("Could not access all required calibration data (PED %p GAIN %p)",
+ fCalibrationData->Pedestals(),fCalibrationData->Gains()));
+ }
+
+ if ( !fCalibrationData->HV() )
+ {
+ // Special treatment of HV. We only break if the values
+ // are not there *AND* we cut on them.
+ UInt_t mask = GetRecoParam()->PadGoodnessMask();
+ TString smask(AliMUONPadStatusMaker::AsCondition(mask));
+ if ( smask.Contains("HV") )
+ {
+ AliFatal("Could not access all required calibration data (HV)");
+ }
+ }
+ }
+}
+
+//_____________________________________________________________________________
+void
+AliMUONReconstructor::CreateCalibrator() const
+{
+ /// Create the calibrator
+
+ AliCodeTimerAuto("",0);
+
+ if ( ! fCalibrationData )
+ CreateCalibrationData();
+
+ AliInfo("Calibration will occur.");
+
+ TString opt(GetOption());
+ opt.ToUpper();
+
+ if ( strstr(opt,"NOSTATUSMAP") )
+ {
+ AliWarning("NOSTATUSMAP is obsolete");
+ }
+
+ Bool_t kTracker(kFALSE);
+
+ const AliRunInfo* runInfo = GetRunInfo();
+ if (!runInfo)
+ {
+ AliError("Could not get runinfo ?");
+ }
+ else
+ {
+ TString detectors(runInfo->GetActiveDetectors());
+ if (detectors.Contains("MUONTRK")) kTracker=kTRUE;
+ }
+
+ if ( kTracker )
+ {
+ fDigitCalibrator = new AliMUONDigitCalibrator(*fCalibrationData,GetRecoParam());
+ }
+ else
+ {
+ AliWarning("Apparently running without MCH so will not instantiante the DigitCalibrator nor read MCH OCDB objects...");
+ fShouldCalibrate=kFALSE;
+ }
+}
+
+//_____________________________________________________________________________
+void
+AliMUONReconstructor::ResponseRemovingChambers(AliMUONVTriggerStore* triggerStore) const
+{
+ /// Update trigger information with informatins obtained after
+ /// re-calculation of trigger response
+ AliCodeTimerAuto("",0);
+
+ if ( ! fCalibrationData )
+ CreateCalibrationData();
+
+ if ( ! fTriggerProcessor )
+ fTriggerProcessor = new AliMUONTriggerElectronics(fCalibrationData);
+
+ fTriggerProcessor->ResponseRemovingChambers(*triggerStore);
+}
+
+//_____________________________________________________________________________
+AliMUONVDigitStore*
+AliMUONReconstructor::DigitStore() const
+{
+ /// Return (and create if necessary) the digit container
+ if (!fDigitStore)
+ {
+ TString sopt(GetOption());
+ sopt.ToUpper();
+
+ AliInfo(Form("Options=%s",sopt.Data()));
+
+ if ( sopt.Contains("DIGITSTOREV1") )
+ {
+ fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV1");
+ }
+ else if ( sopt.Contains("DIGITSTOREV2R") )
+ {
+ fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2R");
+ }
+ else if ( sopt.Contains("DIGITSTOREV2S") )
+ {
+ fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2S");
+ }
+
+ if (!fDigitStore) fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV2R");
+
+ AliInfo(Form("Will use %s to store digits during reconstruction",fDigitStore->ClassName()));
+ }
+ return fDigitStore;
+}
+
+//_____________________________________________________________________________
+void
+AliMUONReconstructor::FillTreeR(AliMUONVTriggerStore* triggerStore,
+ TTree& clustersTree) const
+{
+ /// Write the trigger and cluster information into TreeR
+
+ AliCodeTimerAuto("",0)
+
+ Bool_t ok(kFALSE);
+ Bool_t alone(kTRUE); // is trigger the only info in TreeR ?
+
+ const AliMUONRecoParam* rp = GetRecoParam();
+
+ if ( ! rp->CombineClusterTrackReco() )
+ {
+ alone = kFALSE; // we'll get both tracker and trigger information in TreeR
+ }
+
+ if ( triggerStore )
+ {
+ ResponseRemovingChambers(triggerStore);
+ ok = triggerStore->Connect(clustersTree,alone);
+ if (!ok)
+ {
+ AliError("Could not create triggerStore branches in TreeR");
+ }
+ }
+
+ if ( !alone )
+ {
+ if (!fClusterStore)
+ {
+ fClusterStore = new AliMUONClusterStoreV2;
+ }
+
+ AliMUONVClusterServer* clusterServer = CreateClusterServer(*rp);
+
+ TIter next(DigitStore()->CreateIterator());
+ clusterServer->UseDigits(next,DigitStore());
+
+ AliMpArea area;
+
+ AliDebug(1,Form("Doing full clusterization in local reconstruction using %s ",clusterServer->ClassName()));
+
+ for ( Int_t i = 0; i < AliMpConstants::NofTrackingChambers(); ++i )
+ {
+ if (rp->UseChamber(i))
+ {
+ if ( ( i == 6 || i == 7 ) && rp->BypassSt4() ) continue;
+ if ( ( i == 8 || i == 9 ) && rp->BypassSt5() ) continue;