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 TTask* calibration = new TTask("MUONCalibrator","MUON Digit calibrator");
141 TString opt(GetOption());
143 Bool_t statusMap(kTRUE);
145 if ( strstr(opt,"NOSTATUSMAP") )
147 AliWarning("Disconnecting status map : SHOULD BE USED FOR DEBUG ONLY. NOT FOR PRODUCTION !!!");
150 calibration->Add(new AliMUONDigitCalibrator(fMUONData,fCalibrationData,statusMap));
154 //_____________________________________________________________________________
155 AliMUONClusterReconstructor*
156 AliMUONReconstructor::CreateClusterReconstructor() const
158 /// Create cluster reconstructor
160 AliMUONVClusterFinder* clusterFinder(0x0);
162 TString opt(GetOption());
165 if ( strstr(opt,"PRECLUSTER") )
167 clusterFinder = new AliMUONPreClusterFinder;
169 else if ( strstr(opt,"COG") )
171 clusterFinder = new AliMUONClusterFinderCOG;
173 else if ( strstr(opt,"SIMPLEFIT") )
175 clusterFinder = new AliMUONClusterFinderSimpleFit;
177 else if ( strstr(opt,"MLEM:DRAW") )
179 clusterFinder = new AliMUONClusterFinderMLEM(kTRUE);
181 else if ( strstr(opt,"MLEM") )
183 clusterFinder = new AliMUONClusterFinderMLEM(kFALSE);
188 AliInfo(Form("Will use %s for clusterizing",clusterFinder->ClassName()));
191 AliMUONClusterReconstructor* clusterReco =
192 new AliMUONClusterReconstructor(fMUONData,clusterFinder,fTransformer);
196 //_____________________________________________________________________________
197 void AliMUONReconstructor::Reconstruct(AliRunLoader* runLoader) const
202 AliLoader* loader = runLoader->GetLoader("MUONLoader");
203 Int_t nEvents = runLoader->GetNumberOfEvents();
204 Int_t evtNumber = runLoader->GetEventNumber();
206 fMUONData->SetLoader(loader);
208 // passing loader as argument.
209 AliMUONVTrackReconstructor* recoEvent;
210 if (strstr(GetOption(),"Original")) recoEvent = new AliMUONTrackReconstructor(fMUONData);
211 else if (strstr(GetOption(),"Combi")) recoEvent = new AliMUONTrackReconstructorK(fMUONData,"Combi");
212 else recoEvent = new AliMUONTrackReconstructorK(fMUONData,"Kalman");
214 recoEvent->SetTriggerCircuit(fTriggerCircuit);
216 AliMUONClusterReconstructor* recoCluster = CreateClusterReconstructor();
218 AliMUONClusterFinderVS *recModel = recoCluster->GetRecoModel();
220 if (!strstr(GetOption(),"VS")) {
221 recModel = (AliMUONClusterFinderVS*) new AliMUONClusterFinderAZ();
222 recoCluster->SetRecoModel(recModel);
224 recModel->SetGhostChi2Cut(10);
225 recModel->SetEventNumber(evtNumber);
227 loader->LoadDigits("READ");
228 loader->LoadRecPoints("RECREATE");
229 loader->LoadTracks("RECREATE");
231 TTask* calibration = GetCalibrationTask();
233 Int_t chBeg = (strstr(GetOption(),"Combi") ? 6 : 0);
236 for(Int_t ievent = 0; ievent < nEvents; ievent++) {
238 AliDebug(1,Form("Event %d",ievent));
240 runLoader->GetEvent(ievent);
242 //----------------------- digit2cluster & Trigger2Trigger -------------------
243 if (!loader->TreeR()) loader->MakeRecPointsContainer();
246 if (!strstr(GetOption(),"Combi")) {
247 fMUONData->MakeBranch("RC");
248 fMUONData->SetTreeAddress("D,RC");
250 fMUONData->SetTreeAddress("D");
251 fMUONData->SetTreeAddress("RCC");
253 // Important for avoiding a memory leak when reading digits ( to be investigated more in detail)
254 // In any case the reading of GLT is needed for the Trigger2Tigger method below
255 fMUONData->SetTreeAddress("GLT");
257 fMUONData->GetDigits();
261 calibration->ExecuteTask();
264 recoCluster->Digits2Clusters(chBeg);
266 if (strstr(GetOption(),"Combi")) {
267 // Combined cluster / track finder
268 AliMUONEventRecoCombi::Instance()->FillEvent(fMUONData, (AliMUONClusterFinderAZ*)recModel);
269 ((AliMUONClusterFinderAZ*) recModel)->SetReco(2);
271 else fMUONData->Fill("RC");
274 fMUONData->MakeBranch("TC");
275 fMUONData->SetTreeAddress("TC");
276 recoCluster->Trigger2Trigger();
277 fMUONData->Fill("TC");
279 //AZ loader->WriteRecPoints("OVERWRITE");
281 //---------------------------- Track & TriggerTrack ---------------------
282 if (!loader->TreeT()) loader->MakeTracksContainer();
285 fMUONData->MakeBranch("RL"); //trigger track
286 fMUONData->SetTreeAddress("RL");
287 recoEvent->EventReconstructTrigger();
288 fMUONData->Fill("RL");
291 fMUONData->MakeBranch("RT"); //track
292 fMUONData->SetTreeAddress("RT");
293 recoEvent->EventReconstruct();
294 fMUONData->Fill("RT");
296 loader->WriteTracks("OVERWRITE");
298 if (strstr(GetOption(),"Combi")) {
299 // Combined cluster / track
300 ((AliMUONClusterFinderAZ*) recModel)->SetReco(1);
301 fMUONData->MakeBranch("RC");
302 fMUONData->SetTreeAddress("RC");
303 AliMUONEventRecoCombi::Instance()->FillRecP(fMUONData, (AliMUONTrackReconstructorK*)recoEvent);
304 fMUONData->Fill("RC");
306 loader->WriteRecPoints("OVERWRITE");
308 //--------------------------- Resetting branches -----------------------
309 fMUONData->ResetDigits();
310 fMUONData->ResetRawClusters();
311 fMUONData->ResetTrigger();
312 fMUONData->ResetRecTracks();
313 fMUONData->ResetRecTriggerTracks();
316 loader->UnloadDigits();
317 loader->UnloadRecPoints();
318 loader->UnloadTracks();
325 //_____________________________________________________________________________
326 void AliMUONReconstructor::Reconstruct(AliRunLoader* runLoader,
327 AliRawReader* rawReader) const
333 AliLoader* loader = runLoader->GetLoader("MUONLoader");
334 Int_t evtNumber = runLoader->GetEventNumber();
336 fMUONData->SetLoader(loader);
338 // passing loader as argument.
339 fDigitMaker->SetMUONData(fMUONData);
341 // disable trigger rawdata reading
342 if (strstr(GetOption(),"TriggerDisable"))
343 fDigitMaker->DisableTrigger();
345 AliMUONClusterReconstructor* recoCluster = CreateClusterReconstructor();
347 AliMUONClusterFinderVS *recModel = recoCluster->GetRecoModel();
349 if (!strstr(GetOption(),"VS"))
351 recModel = (AliMUONClusterFinderVS*) new AliMUONClusterFinderAZ();
352 recoCluster->SetRecoModel(recModel);
354 recModel->SetGhostChi2Cut(10);
355 recModel->SetEventNumber(evtNumber);
357 TTask* calibration = GetCalibrationTask();
359 loader->LoadRecPoints("RECREATE");
361 // Digits are not stored on disk and created on flight from rawdata.
362 // In order to write digits on disk the following line should be uncommented
363 // loader->LoadDigits("RECREATE");
368 TStopwatch totalTimer;
370 TStopwatch calibTimer;
371 TStopwatch clusterTimer;
373 rawTimer.Start(kTRUE); rawTimer.Stop();
374 calibTimer.Start(kTRUE); calibTimer.Stop();
375 clusterTimer.Start(kTRUE); clusterTimer.Stop();
377 totalTimer.Start(kTRUE);
379 while (rawReader->NextEvent())
381 AliDebug(1,Form("Event %d",iEvent));
383 runLoader->GetEvent(iEvent++);
385 //----------------------- raw2digits & raw2trigger-------------------
386 // if (!loader->TreeD())
388 // AliDebug(1,Form("Making Digit Container for event %d",iEvent));
389 // loader->MakeDigitsContainer();
391 // Digits are not stored on disk and created on flight from rawdata.
392 // In order to write digits on disk the following lines should be uncommented
393 // fMUONData->MakeBranch("D,GLT");
394 // fMUONData->SetTreeAddress("D,GLT");
395 fMUONData->SetDataContainer("D, GLT");
396 rawTimer.Start(kFALSE);
397 fDigitMaker->Raw2Digits(rawReader);
402 calibTimer.Start(kFALSE);
403 calibration->ExecuteTask();
406 // Digits are not stored on disk and created on flight from rawdata.
407 // In order to write digits on disk the following lines should be uncommented
408 // fMUONData->Fill("D,GLT");
409 // loader->WriteDigits("OVERWRITE");
410 //----------------------- digit2cluster & Trigger2Trigger -------------------
411 clusterTimer.Start(kFALSE);
413 if (!loader->TreeR()) loader->MakeRecPointsContainer();
416 fMUONData->MakeBranch("RC");
417 fMUONData->SetTreeAddress("RC");
418 recoCluster->Digits2Clusters();
419 fMUONData->Fill("RC");
422 fMUONData->MakeBranch("TC");
423 fMUONData->SetTreeAddress("TC");
424 fMUONData->Fill("TC");
426 loader->WriteRecPoints("OVERWRITE");
431 //--------------------------- Resetting branches -----------------------
432 fMUONData->ResetDigits();
433 fMUONData->ResetRawClusters();
434 fMUONData->ResetTrigger();
439 loader->UnloadRecPoints();
440 loader->UnloadDigits();
444 AliInfo(Form("Execution time for converting RAW data to digits in MUON : R:%.2fs C:%.2fs",
445 rawTimer.RealTime(),rawTimer.CpuTime()));
446 AliInfo(Form("Execution time for calibrating MUON : R:%.2fs C:%.2fs",
447 calibTimer.RealTime(),calibTimer.CpuTime()));
448 AliInfo(Form("Execution time for clusterizing MUON : R:%.2fs C:%.2fs",
449 clusterTimer.RealTime(),clusterTimer.CpuTime()));
450 AliInfo(Form("Total Execution time for Reconstruct(from raw) MUON : R:%.2fs C:%.2fs",
451 totalTimer.RealTime(),totalTimer.CpuTime()));
454 //_____________________________________________________________________________
455 void AliMUONReconstructor::FillESD(AliRunLoader* runLoader, AliESD* esd) const
460 TClonesArray* recTracksArray = 0;
461 TClonesArray* recTrigTracksArray = 0;
463 AliLoader* loader = runLoader->GetLoader("MUONLoader");
464 loader->LoadTracks("READ");
465 fMUONData->SetLoader(loader);
468 Int_t iEvent;// nPart;
469 Int_t nTrackHits;// nPrimary;
472 Double_t bendingSlope, nonBendingSlope, inverseBendingMomentum;
473 Double_t xRec, yRec, zRec, chi2MatchTrigger;
476 // setting pointer for tracks, triggertracks & trackparam at vertex
477 AliMUONTrack* recTrack = 0;
478 AliMUONTrackParam* trackParam = 0;
479 AliMUONTriggerTrack* recTriggerTrack = 0;
481 iEvent = runLoader->GetEventNumber();
482 runLoader->GetEvent(iEvent);
485 Double_t vertex[3] = {0};
486 const AliESDVertex *esdVert = esd->GetVertex();
487 if (esdVert->GetNContributors()) {
488 esdVert->GetXYZ(vertex);
489 AliDebug(1, "find vertex\n");
491 // setting ESD MUON class
492 AliESDMuonTrack* theESDTrack = new AliESDMuonTrack() ;
494 //-------------------- trigger tracks-------------
496 fMUONData->SetTreeAddress("RL");
497 fMUONData->GetRecTriggerTracks();
498 recTrigTracksArray = fMUONData->RecTriggerTracks();
500 // ready global trigger pattern from first track
501 if (recTrigTracksArray)
502 recTriggerTrack = (AliMUONTriggerTrack*) recTrigTracksArray->First();
503 if (recTriggerTrack) trigPat = recTriggerTrack->GetGTPattern();
505 //printf(">>> Event %d Number of Recconstructed tracks %d \n",iEvent, nrectracks);
507 // -------------------- tracks-------------
508 fMUONData->SetTreeAddress("RT");
509 fMUONData->GetRecTracks();
510 recTracksArray = fMUONData->RecTracks();
512 Int_t nRecTracks = 0;
514 nRecTracks = (Int_t) recTracksArray->GetEntriesFast(); //
517 for (Int_t iRecTracks = 0; iRecTracks < nRecTracks; iRecTracks++) {
519 // reading info from tracks
520 recTrack = (AliMUONTrack*) recTracksArray->At(iRecTracks);
522 trackParam = (AliMUONTrackParam*) (recTrack->GetTrackParamAtHit())->First();
524 if (esdVert->GetNContributors())
525 AliMUONTrackExtrap::ExtrapToVertex(trackParam, vertex[0],vertex[1],vertex[2]);
527 bendingSlope = trackParam->GetBendingSlope();
528 nonBendingSlope = trackParam->GetNonBendingSlope();
529 inverseBendingMomentum = trackParam->GetInverseBendingMomentum();
530 xRec = trackParam->GetNonBendingCoor();
531 yRec = trackParam->GetBendingCoor();
532 zRec = trackParam->GetZ();
534 nTrackHits = recTrack->GetNTrackHits();
535 fitFmin = recTrack->GetFitFMin();
536 matchTrigger = recTrack->GetMatchTrigger();
537 chi2MatchTrigger = recTrack->GetChi2MatchTrigger();
539 // setting data member of ESD MUON
540 theESDTrack->SetInverseBendingMomentum(inverseBendingMomentum);
541 theESDTrack->SetThetaX(TMath::ATan(nonBendingSlope));
542 theESDTrack->SetThetaY(TMath::ATan(bendingSlope));
543 theESDTrack->SetZ(zRec);
544 theESDTrack->SetBendingCoor(yRec); // calculate vertex at ESD or Tracking level ?
545 theESDTrack->SetNonBendingCoor(xRec);
546 theESDTrack->SetChi2(fitFmin);
547 theESDTrack->SetNHit(nTrackHits);
548 theESDTrack->SetMatchTrigger(matchTrigger);
549 theESDTrack->SetChi2MatchTrigger(chi2MatchTrigger);
551 // storing ESD MUON Track into ESD Event
553 esd->AddMuonTrack(theESDTrack);
557 fMUONData->ResetRecTracks();
558 fMUONData->ResetRecTriggerTracks();
560 //} // end loop on event
561 loader->UnloadTracks();
566 //_____________________________________________________________________________
567 void AliMUONReconstructor::FillESD(AliRunLoader* runLoader, AliRawReader* /*rawReader*/, AliESD* esd) const
572 // don't need rawReader ???
573 FillESD(runLoader, esd);
576 //_____________________________________________________________________________
577 AliTracker* AliMUONReconstructor::CreateTracker(AliRunLoader* runLoader) const
579 /// create tracker for MUON
580 /// go into the tracking framework finally (Ch.F)
582 AliLoader* loader = runLoader->GetLoader("MUONLoader");
584 fMUONData->SetLoader(loader);
586 AliMUONTracker* tracker = new AliMUONTracker();
587 tracker->SetMUONData(fMUONData);
588 tracker->SetTriggerCircuit(fTriggerCircuit);
589 tracker->SetOption(GetOption());