1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 //-----------------------------
18 // Class AliMUONReconstructor
19 //-----------------------------
21 // MUON track reconstruction
23 #include "AliMUONReconstructor.h"
25 #include "AliMUONConstants.h"
26 #include "AliMUONCalibrationData.h"
27 #include "AliMUONClusterFinderAZ.h"
28 #include "AliMUONClusterReconstructor.h"
29 #include "AliMUONData.h"
30 #include "AliMUONDigitCalibrator.h"
31 #include "AliMUONEventRecoCombi.h"
32 #include "AliMUONDigitMaker.h"
33 #include "AliMUONTrack.h"
34 #include "AliMUONTrackParam.h"
35 #include "AliMUONTrackExtrap.h"
36 #include "AliMUONTracker.h"
37 #include "AliMUONVTrackReconstructor.h"
38 #include "AliMUONTrackReconstructor.h"
39 #include "AliMUONTrackReconstructorK.h"
40 #include "AliMUONTriggerTrack.h"
41 #include "AliMUONTriggerCircuit.h"
42 #include "AliMUONTriggerCrateStore.h"
43 #include "AliMUONSegFactory.h"
44 #include "AliMUONSegmentation.h"
45 #include "AliMUONPreClusterFinder.h"
46 #include "AliMUONClusterFinderCOG.h"
47 #include "AliMUONClusterFinderSimpleFit.h"
48 #include "AliMUONClusterFinderMLEM.h"
51 #include "AliESDMuonTrack.h"
53 #include "AliRawReader.h"
54 #include "AliRunLoader.h"
55 #include "AliCDBManager.h"
58 #include "TStopwatch.h"
61 ClassImp(AliMUONReconstructor)
64 //_____________________________________________________________________________
65 AliMUONReconstructor::AliMUONReconstructor()
67 fDigitMaker(new AliMUONDigitMaker()),
68 fCalibrationData(0x0),
69 fCrateManager(new AliMUONTriggerCrateStore()),
70 fTriggerCircuit(new TClonesArray("AliMUONTriggerCircuit", 234)),
71 fTransformer(new AliMUONGeometryTransformer(kTRUE)),
73 fMUONData(new AliMUONData(0x0,"MUON","MUON"))
75 /// Default constructor
79 fCrateManager->ReadFromFile();
82 fDigitMaker->SetCrateManager(fCrateManager);
85 fTransformer->ReadGeometryData("volpath.dat", "geometry.root");
87 // create segmentation and pass it to EventRecoCombi
88 AliMUONSegFactory factory(fTransformer);
89 fSegmentation = factory.CreateSegmentation();
90 AliMUONEventRecoCombi::Instance(fSegmentation);
93 for (Int_t i = 0; i < AliMUONConstants::NTriggerCircuit(); i++) {
94 AliMUONTriggerCircuit* c = new AliMUONTriggerCircuit();
95 c->SetTransformer(fTransformer);
96 c->Init(i,*fCrateManager);
97 TClonesArray& circuit = *fTriggerCircuit;
98 new(circuit[circuit.GetEntriesFast()])AliMUONTriggerCircuit(*c);
105 //_____________________________________________________________________________
106 AliMUONReconstructor::~AliMUONReconstructor()
111 delete fCalibrationData;
113 delete fCrateManager;
114 delete fTriggerCircuit;
116 delete fSegmentation;
120 //_____________________________________________________________________________
122 AliMUONReconstructor::GetCalibrationTask() const
124 /// Create the calibration task(s).
126 //const AliRun* run = fRunLoader->GetAliRun();
127 //Int_t runNumber = run->GetRunNumber();
128 Int_t runNumber = AliCDBManager::Instance()->GetRun();
129 AliInfo("Calibration will occur.");
131 fCalibrationData = new AliMUONCalibrationData(runNumber);
132 if ( !fCalibrationData->IsValid() )
134 AliError("Could not retrieve calibrations !");
135 delete fCalibrationData;
136 fCalibrationData = 0x0;
139 // Check that we get all the calibrations we'll need
140 if ( !fCalibrationData->Pedestals() ||
141 !fCalibrationData->Gains() ||
142 !fCalibrationData->HV() )
144 AliFatal("Could not access all required calibration data");
146 TTask* calibration = new TTask("MUONCalibrator","MUON Digit calibrator");
148 TString opt(GetOption());
150 Bool_t statusMap(kTRUE);
152 if ( strstr(opt,"NOSTATUSMAP") )
154 AliWarning("Disconnecting status map : SHOULD BE USED FOR DEBUG ONLY. NOT FOR PRODUCTION !!!");
157 calibration->Add(new AliMUONDigitCalibrator(fMUONData,fCalibrationData,statusMap));
161 //_____________________________________________________________________________
162 AliMUONClusterReconstructor*
163 AliMUONReconstructor::CreateClusterReconstructor() const
165 /// Create cluster reconstructor
167 AliMUONVClusterFinder* clusterFinder(0x0);
169 TString opt(GetOption());
172 if ( strstr(opt,"PRECLUSTER") )
174 clusterFinder = new AliMUONPreClusterFinder;
176 else if ( strstr(opt,"COG") )
178 clusterFinder = new AliMUONClusterFinderCOG;
180 else if ( strstr(opt,"SIMPLEFIT") )
182 clusterFinder = new AliMUONClusterFinderSimpleFit;
184 else if ( strstr(opt,"MLEM:DRAW") )
186 clusterFinder = new AliMUONClusterFinderMLEM(kTRUE);
188 else if ( strstr(opt,"MLEM") )
190 clusterFinder = new AliMUONClusterFinderMLEM(kFALSE);
195 AliInfo(Form("Will use %s for clusterizing",clusterFinder->ClassName()));
198 AliMUONClusterReconstructor* clusterReco =
199 new AliMUONClusterReconstructor(fMUONData,clusterFinder,fTransformer);
203 //_____________________________________________________________________________
204 void AliMUONReconstructor::Reconstruct(AliRunLoader* runLoader) const
209 AliLoader* loader = runLoader->GetLoader("MUONLoader");
210 Int_t nEvents = runLoader->GetNumberOfEvents();
211 Int_t evtNumber = runLoader->GetEventNumber();
213 fMUONData->SetLoader(loader);
215 // passing loader as argument.
216 AliMUONVTrackReconstructor* recoEvent;
217 if (strstr(GetOption(),"Original")) recoEvent = new AliMUONTrackReconstructor(fMUONData);
218 else if (strstr(GetOption(),"Combi")) recoEvent = new AliMUONTrackReconstructorK(fMUONData,"Combi");
219 else recoEvent = new AliMUONTrackReconstructorK(fMUONData,"Kalman");
221 recoEvent->SetTriggerCircuit(fTriggerCircuit);
223 AliMUONClusterReconstructor* recoCluster = CreateClusterReconstructor();
225 AliMUONClusterFinderVS *recModel = recoCluster->GetRecoModel();
227 if (!strstr(GetOption(),"VS")) {
228 recModel = (AliMUONClusterFinderVS*) new AliMUONClusterFinderAZ();
229 recoCluster->SetRecoModel(recModel);
231 recModel->SetGhostChi2Cut(10);
232 recModel->SetEventNumber(evtNumber);
234 loader->LoadDigits("READ");
235 loader->LoadRecPoints("RECREATE");
236 loader->LoadTracks("RECREATE");
238 TTask* calibration = GetCalibrationTask();
240 Int_t chBeg = (strstr(GetOption(),"Combi") ? 6 : 0);
243 for(Int_t ievent = 0; ievent < nEvents; ievent++) {
245 AliDebug(1,Form("Event %d",ievent));
247 runLoader->GetEvent(ievent);
249 //----------------------- digit2cluster & Trigger2Trigger -------------------
250 if (!loader->TreeR()) loader->MakeRecPointsContainer();
253 if (!strstr(GetOption(),"Combi")) {
254 fMUONData->MakeBranch("RC");
255 fMUONData->SetTreeAddress("D,RC");
257 fMUONData->SetTreeAddress("D");
258 fMUONData->SetTreeAddress("RCC");
260 // Important for avoiding a memory leak when reading digits ( to be investigated more in detail)
261 // In any case the reading of GLT is needed for the Trigger2Tigger method below
262 fMUONData->SetTreeAddress("GLT");
264 fMUONData->GetDigits();
268 calibration->ExecuteTask();
271 recoCluster->Digits2Clusters(chBeg);
273 if (strstr(GetOption(),"Combi")) {
274 // Combined cluster / track finder
275 AliMUONEventRecoCombi::Instance()->FillEvent(fMUONData, (AliMUONClusterFinderAZ*)recModel);
276 ((AliMUONClusterFinderAZ*) recModel)->SetReco(2);
278 else fMUONData->Fill("RC");
281 fMUONData->MakeBranch("TC");
282 fMUONData->SetTreeAddress("TC");
283 recoCluster->Trigger2Trigger();
284 fMUONData->Fill("TC");
286 //AZ loader->WriteRecPoints("OVERWRITE");
288 //---------------------------- Track & TriggerTrack ---------------------
289 if (!loader->TreeT()) loader->MakeTracksContainer();
292 fMUONData->MakeBranch("RL"); //trigger track
293 fMUONData->SetTreeAddress("RL");
294 recoEvent->EventReconstructTrigger();
295 fMUONData->Fill("RL");
298 fMUONData->MakeBranch("RT"); //track
299 fMUONData->SetTreeAddress("RT");
300 recoEvent->EventReconstruct();
301 fMUONData->Fill("RT");
303 loader->WriteTracks("OVERWRITE");
305 if (strstr(GetOption(),"Combi")) {
306 // Combined cluster / track
307 ((AliMUONClusterFinderAZ*) recModel)->SetReco(1);
308 fMUONData->MakeBranch("RC");
309 fMUONData->SetTreeAddress("RC");
310 AliMUONEventRecoCombi::Instance()->FillRecP(fMUONData, (AliMUONTrackReconstructorK*)recoEvent);
311 fMUONData->Fill("RC");
313 loader->WriteRecPoints("OVERWRITE");
315 //--------------------------- Resetting branches -----------------------
316 fMUONData->ResetDigits();
317 fMUONData->ResetRawClusters();
318 fMUONData->ResetTrigger();
319 fMUONData->ResetRecTracks();
320 fMUONData->ResetRecTriggerTracks();
323 loader->UnloadDigits();
324 loader->UnloadRecPoints();
325 loader->UnloadTracks();
332 //_____________________________________________________________________________
333 void AliMUONReconstructor::Reconstruct(AliRunLoader* runLoader,
334 AliRawReader* rawReader) const
340 AliLoader* loader = runLoader->GetLoader("MUONLoader");
341 Int_t evtNumber = runLoader->GetEventNumber();
343 fMUONData->SetLoader(loader);
345 // passing loader as argument.
346 fDigitMaker->SetMUONData(fMUONData);
348 // disable trigger rawdata reading
349 if (strstr(GetOption(),"TriggerDisable"))
350 fDigitMaker->DisableTrigger();
352 AliMUONClusterReconstructor* recoCluster = CreateClusterReconstructor();
354 AliMUONClusterFinderVS *recModel = recoCluster->GetRecoModel();
356 if (!strstr(GetOption(),"VS"))
358 recModel = (AliMUONClusterFinderVS*) new AliMUONClusterFinderAZ();
359 recoCluster->SetRecoModel(recModel);
361 recModel->SetGhostChi2Cut(10);
362 recModel->SetEventNumber(evtNumber);
364 TTask* calibration = GetCalibrationTask();
366 loader->LoadRecPoints("RECREATE");
368 // Digits are not stored on disk and created on flight from rawdata.
369 // In order to write digits on disk the following line should be uncommented
370 // loader->LoadDigits("RECREATE");
375 TStopwatch totalTimer;
377 TStopwatch calibTimer;
378 TStopwatch clusterTimer;
380 rawTimer.Start(kTRUE); rawTimer.Stop();
381 calibTimer.Start(kTRUE); calibTimer.Stop();
382 clusterTimer.Start(kTRUE); clusterTimer.Stop();
384 totalTimer.Start(kTRUE);
386 while (rawReader->NextEvent())
388 AliDebug(1,Form("Event %d",iEvent));
390 runLoader->GetEvent(iEvent++);
392 //----------------------- raw2digits & raw2trigger-------------------
393 // if (!loader->TreeD())
395 // AliDebug(1,Form("Making Digit Container for event %d",iEvent));
396 // loader->MakeDigitsContainer();
398 // Write digits from raw data on disk
399 if (strstr(GetOption(),"SAVEDIGITS")) {
400 if (!loader->TreeD())fMUONData->GetLoader()->MakeDigitsContainer();
401 fMUONData->MakeBranch("D,GLT");
402 fMUONData->SetTreeAddress("D,GLT");
403 AliInfo("Digits from raw data will be stored.");
406 fMUONData->SetDataContainer("D, GLT");
408 rawTimer.Start(kFALSE);
409 fDigitMaker->Raw2Digits(rawReader);
414 calibTimer.Start(kFALSE);
415 calibration->ExecuteTask();
419 // Write digits from raw data on disk
420 if (strstr(GetOption(),"SAVEDIGITS")) {
421 fMUONData->Fill("D,GLT");
422 loader->WriteDigits("OVERWRITE");
424 //----------------------- digit2cluster & Trigger2Trigger -------------------
425 clusterTimer.Start(kFALSE);
427 if (!loader->TreeR()) loader->MakeRecPointsContainer();
430 fMUONData->MakeBranch("RC");
431 fMUONData->SetTreeAddress("RC");
432 recoCluster->Digits2Clusters();
433 fMUONData->Fill("RC");
436 fMUONData->MakeBranch("TC");
437 fMUONData->SetTreeAddress("TC");
438 fMUONData->Fill("TC");
440 loader->WriteRecPoints("OVERWRITE");
445 //--------------------------- Resetting branches -----------------------
446 fMUONData->ResetDigits();
447 fMUONData->ResetRawClusters();
448 fMUONData->ResetTrigger();
453 loader->UnloadRecPoints();
454 loader->UnloadDigits();
459 AliInfo(Form("Execution time for converting RAW data to digits in MUON : R:%.2fs C:%.2fs",
460 rawTimer.RealTime(),rawTimer.CpuTime()));
461 AliInfo(Form("Execution time for calibrating MUON : R:%.2fs C:%.2fs",
462 calibTimer.RealTime(),calibTimer.CpuTime()));
463 AliInfo(Form("Execution time for clusterizing MUON : R:%.2fs C:%.2fs",
464 clusterTimer.RealTime(),clusterTimer.CpuTime()));
465 AliInfo(Form("Total Execution time for Reconstruct(from raw) MUON : R:%.2fs C:%.2fs",
466 totalTimer.RealTime(),totalTimer.CpuTime()));
469 //_____________________________________________________________________________
470 void AliMUONReconstructor::FillESD(AliRunLoader* runLoader, AliESD* esd) const
475 TClonesArray* recTracksArray = 0;
476 TClonesArray* recTrigTracksArray = 0;
478 AliLoader* loader = runLoader->GetLoader("MUONLoader");
479 loader->LoadTracks("READ");
480 fMUONData->SetLoader(loader);
483 Int_t iEvent;// nPart;
484 Int_t nTrackHits;// nPrimary;
485 Double_t fitFmin, chi2MatchTrigger;
486 Double_t xRec, yRec, zRec, bendingSlope, nonBendingSlope, inverseBendingMomentum;
487 Double_t xVtx, yVtx, zVtx, bendingSlopeAtVtx, nonBendingSlopeAtVtx, inverseBendingMomentumAtVtx;
489 UShort_t hitsPatternInTrigCh;
491 // setting pointer for tracks, triggertracks & trackparam at vertex
492 AliMUONTrack* recTrack = 0;
493 AliMUONTrackParam trackParamAtVtx;
494 AliMUONTriggerTrack* recTriggerTrack = 0;
496 iEvent = runLoader->GetEventNumber();
497 runLoader->GetEvent(iEvent);
500 Double_t vertex[3] = {0};
501 const AliESDVertex *esdVert = esd->GetVertex();
502 if (esdVert->GetNContributors()) {
503 esdVert->GetXYZ(vertex);
504 AliDebug(1, "find vertex\n");
506 // setting ESD MUON class
507 AliESDMuonTrack* theESDTrack = new AliESDMuonTrack() ;
509 //-------------------- trigger tracks-------------
511 fMUONData->SetTreeAddress("RL");
512 fMUONData->GetRecTriggerTracks();
513 recTrigTracksArray = fMUONData->RecTriggerTracks();
515 // ready global trigger pattern from first track
516 if (recTrigTracksArray)
517 recTriggerTrack = (AliMUONTriggerTrack*) recTrigTracksArray->First();
518 if (recTriggerTrack) trigPat = recTriggerTrack->GetGTPattern();
520 //printf(">>> Event %d Number of Recconstructed tracks %d \n",iEvent, nrectracks);
522 // -------------------- tracks-------------
523 fMUONData->SetTreeAddress("RT");
524 fMUONData->GetRecTracks();
525 recTracksArray = fMUONData->RecTracks();
527 Int_t nRecTracks = 0;
529 nRecTracks = (Int_t) recTracksArray->GetEntriesFast(); //
532 for (Int_t iRecTracks = 0; iRecTracks < nRecTracks; iRecTracks++) {
534 // reading info from tracks
535 recTrack = (AliMUONTrack*) recTracksArray->At(iRecTracks);
536 AliMUONTrackParam *trackParam = (AliMUONTrackParam*) (recTrack->GetTrackParamAtHit())->First();
537 trackParamAtVtx = *trackParam;
539 // extrapolate to the vertex if available, else to (0,0,0)
540 if (esdVert->GetNContributors())
541 AliMUONTrackExtrap::ExtrapToVertex(&trackParamAtVtx, vertex[0],vertex[1],vertex[2]);
543 AliMUONTrackExtrap::ExtrapToVertex(&trackParamAtVtx, 0.,0.,0.);
545 // Track parameters at first station
546 bendingSlope = trackParam->GetBendingSlope();
547 nonBendingSlope = trackParam->GetNonBendingSlope();
548 inverseBendingMomentum = trackParam->GetInverseBendingMomentum();
549 xRec = trackParam->GetNonBendingCoor();
550 yRec = trackParam->GetBendingCoor();
551 zRec = trackParam->GetZ();
553 // Track parameters at vertex
554 bendingSlopeAtVtx = trackParamAtVtx.GetBendingSlope();
555 nonBendingSlopeAtVtx = trackParamAtVtx.GetNonBendingSlope();
556 inverseBendingMomentumAtVtx = trackParamAtVtx.GetInverseBendingMomentum();
557 xVtx = trackParamAtVtx.GetNonBendingCoor();
558 yVtx = trackParamAtVtx.GetBendingCoor();
559 zVtx = trackParamAtVtx.GetZ();
562 nTrackHits = recTrack->GetNTrackHits();
563 fitFmin = recTrack->GetFitFMin();
564 matchTrigger = recTrack->GetMatchTrigger();
565 chi2MatchTrigger = recTrack->GetChi2MatchTrigger();
566 hitsPatternInTrigCh = recTrack->GetHitsPatternInTrigCh();
568 // setting data member of ESD MUON
570 theESDTrack->SetInverseBendingMomentumUncorrected(inverseBendingMomentum);
571 theESDTrack->SetThetaXUncorrected(TMath::ATan(nonBendingSlope));
572 theESDTrack->SetThetaYUncorrected(TMath::ATan(bendingSlope));
573 theESDTrack->SetZUncorrected(zRec);
574 theESDTrack->SetBendingCoorUncorrected(yRec);
575 theESDTrack->SetNonBendingCoorUncorrected(xRec);
577 theESDTrack->SetInverseBendingMomentum(inverseBendingMomentumAtVtx);
578 theESDTrack->SetThetaX(TMath::ATan(nonBendingSlopeAtVtx));
579 theESDTrack->SetThetaY(TMath::ATan(bendingSlopeAtVtx));
580 theESDTrack->SetZ(zVtx);
581 theESDTrack->SetBendingCoor(yVtx);
582 theESDTrack->SetNonBendingCoor(xVtx);
584 theESDTrack->SetChi2(fitFmin);
585 theESDTrack->SetNHit(nTrackHits);
586 theESDTrack->SetMatchTrigger(matchTrigger);
587 theESDTrack->SetChi2MatchTrigger(chi2MatchTrigger);
588 theESDTrack->SetHitsPatternInTrigCh(hitsPatternInTrigCh);
590 // storing ESD MUON Track into ESD Event
592 esd->AddMuonTrack(theESDTrack);
596 fMUONData->ResetRecTracks();
597 fMUONData->ResetRecTriggerTracks();
599 //} // end loop on event
600 loader->UnloadTracks();
605 //_____________________________________________________________________________
606 void AliMUONReconstructor::FillESD(AliRunLoader* runLoader, AliRawReader* /*rawReader*/, AliESD* esd) const
611 // don't need rawReader ???
612 FillESD(runLoader, esd);
615 //_____________________________________________________________________________
616 AliTracker* AliMUONReconstructor::CreateTracker(AliRunLoader* runLoader) const
618 /// create tracker for MUON
619 /// go into the tracking framework finally (Ch.F)
621 AliLoader* loader = runLoader->GetLoader("MUONLoader");
623 fMUONData->SetLoader(loader);
625 AliMUONTracker* tracker = new AliMUONTracker();
626 tracker->SetMUONData(fMUONData);
627 tracker->SetTriggerCircuit(fTriggerCircuit);
628 tracker->SetOption(GetOption());