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"
26 #include "AliESDMuonTrack.h"
28 #include "AliMUONConstants.h"
29 #include "AliMUONCalibrationData.h"
30 #include "AliMUONClusterFinderAZ.h"
31 #include "AliMUONClusterReconstructor.h"
32 #include "AliMUONData.h"
33 #include "AliMUONDigitCalibrator.h"
34 #include "AliMUONEventRecoCombi.h"
35 #include "AliMUONDigitMaker.h"
36 #include "AliMUONTrack.h"
37 #include "AliMUONTrackParam.h"
38 #include "AliMUONTrackExtrap.h"
39 #include "AliMUONVTrackReconstructor.h"
40 #include "AliMUONTrackReconstructor.h"
41 #include "AliMUONTrackReconstructorK.h"
42 #include "AliMUONTriggerTrack.h"
43 #include "AliMUONTriggerCircuit.h"
44 #include "AliMUONTriggerCrateStore.h"
45 #include "AliMUONSegFactory.h"
46 #include "AliMUONSegmentation.h"
48 #include "AliMpSegmentation.h"
50 #include "AliMUONPreClusterFinder.h"
51 #include "AliMUONClusterFinderCOG.h"
52 #include "AliMUONClusterFinderSimpleFit.h"
53 #include "AliMUONClusterFinderMLEM.h"
55 #include "AliRawReader.h"
57 #include "AliRunLoader.h"
59 #include "TStopwatch.h"
62 ClassImp(AliMUONReconstructor)
65 //_____________________________________________________________________________
66 AliMUONReconstructor::AliMUONReconstructor()
69 fDigitMaker(new AliMUONDigitMaker()),
70 fCalibrationData(0x0),
71 fCrateManager(new AliMUONTriggerCrateStore()),
72 fTriggerCircuit(new TClonesArray("AliMUONTriggerCircuit", 234)),
73 fTransformer(new AliMUONGeometryTransformer(kTRUE)),
77 /// Default constructor
81 fCrateManager->ReadFromFile();
84 fDigitMaker->SetCrateManager(fCrateManager);
87 fTransformer->ReadGeometryData("volpath.dat", "geometry.root");
89 // create segmentation and pass it to EventRecoCombi
90 AliMUONSegFactory factory(fTransformer);
91 fSegmentation = factory.CreateSegmentation();
92 AliMUONEventRecoCombi::Instance(fSegmentation);
95 for (Int_t i = 0; i < AliMUONConstants::NTriggerCircuit(); i++) {
96 AliMUONTriggerCircuit* c = new AliMUONTriggerCircuit();
97 c->SetTransformer(fTransformer);
98 c->Init(i,*fCrateManager);
99 TClonesArray& circuit = *fTriggerCircuit;
100 new(circuit[circuit.GetEntriesFast()])AliMUONTriggerCircuit(*c);
107 //_____________________________________________________________________________
108 AliMUONReconstructor::~AliMUONReconstructor()
113 delete fCalibrationData;
115 delete fCrateManager;
116 delete fTriggerCircuit;
118 delete fSegmentation;
121 //_____________________________________________________________________________
123 AliMUONReconstructor::GetCalibrationTask(AliMUONData* data) const
125 /// Create the calibration task(s).
127 const AliRun* run = fRunLoader->GetAliRun();
129 AliInfo("Calibration will occur.");
130 Int_t runNumber = run->GetRunNumber();
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");
140 calibration->Add(new AliMUONDigitCalibrator(data,fCalibrationData));
141 //FIXME: calibration->Add(something about dead channels should go here).
146 //_____________________________________________________________________________
148 AliMUONReconstructor::Init(AliRunLoader* runLoader)
152 fRunLoader = runLoader;
155 //_____________________________________________________________________________
156 AliMUONClusterReconstructor*
157 AliMUONReconstructor::CreateClusterReconstructor(AliMUONData* data) const
159 /// Create cluster reconstructor
161 AliMUONVClusterFinder* clusterFinder(0x0);
163 TString opt(GetOption());
166 if ( strstr(opt,"PRECLUSTER") )
168 clusterFinder = new AliMUONPreClusterFinder;
170 else if ( strstr(opt,"COG") )
172 clusterFinder = new AliMUONClusterFinderCOG;
174 else if ( strstr(opt,"SIMPLEFIT") )
176 clusterFinder = new AliMUONClusterFinderSimpleFit;
178 else if ( strstr(opt,"MLEM:DRAW") )
180 clusterFinder = new AliMUONClusterFinderMLEM(kTRUE);
182 else if ( strstr(opt,"MLEM") )
184 clusterFinder = new AliMUONClusterFinderMLEM(kFALSE);
189 AliInfo(Form("Will use %s for clusterizing",clusterFinder->ClassName()));
192 AliMUONClusterReconstructor* clusterReco =
193 new AliMUONClusterReconstructor(data,clusterFinder,fTransformer);
197 //_____________________________________________________________________________
198 void AliMUONReconstructor::Reconstruct(AliRunLoader* runLoader) const
203 AliLoader* loader = runLoader->GetLoader("MUONLoader");
204 Int_t nEvents = runLoader->GetNumberOfEvents();
205 Int_t evtNumber = runLoader->GetEventNumber();
207 AliMUONData* data = new AliMUONData(loader,"MUON","MUON");
209 // passing loader as argument.
210 AliMUONVTrackReconstructor* recoEvent;
211 if (strstr(GetOption(),"Original")) recoEvent = new AliMUONTrackReconstructor(data);
212 else if (strstr(GetOption(),"Combi")) recoEvent = new AliMUONTrackReconstructorK(data,"Combi");
213 else recoEvent = new AliMUONTrackReconstructorK(data,"Kalman");
215 recoEvent->SetTriggerCircuit(fTriggerCircuit);
217 AliMUONClusterReconstructor* recoCluster = CreateClusterReconstructor(data);
219 AliMUONClusterFinderVS *recModel = recoCluster->GetRecoModel();
221 if (!strstr(GetOption(),"VS")) {
222 recModel = (AliMUONClusterFinderVS*) new AliMUONClusterFinderAZ();
223 recoCluster->SetRecoModel(recModel);
225 recModel->SetGhostChi2Cut(10);
226 recModel->SetEventNumber(evtNumber);
228 loader->LoadDigits("READ");
229 loader->LoadRecPoints("RECREATE");
230 loader->LoadTracks("RECREATE");
232 TTask* calibration = GetCalibrationTask(data);
234 Int_t chBeg = (strstr(GetOption(),"Combi") ? 6 : 0);
237 for(Int_t ievent = 0; ievent < nEvents; ievent++) {
239 AliDebug(1,Form("Event %d",ievent));
241 runLoader->GetEvent(ievent);
243 //----------------------- digit2cluster & Trigger2Trigger -------------------
244 if (!loader->TreeR()) loader->MakeRecPointsContainer();
247 if (!strstr(GetOption(),"Combi")) {
248 data->MakeBranch("RC");
249 data->SetTreeAddress("D,RC");
251 data->SetTreeAddress("D");
252 data->SetTreeAddress("RCC");
254 // Important for avoiding a memory leak when reading digits ( to be investigated more in detail)
255 // In any case the reading of GLT is needed for the Trigger2Tigger method below
256 data->SetTreeAddress("GLT");
262 calibration->ExecuteTask();
265 recoCluster->Digits2Clusters(chBeg);
267 if (strstr(GetOption(),"Combi")) {
268 // Combined cluster / track finder
269 AliMUONEventRecoCombi::Instance()->FillEvent(data, (AliMUONClusterFinderAZ*)recModel);
270 ((AliMUONClusterFinderAZ*) recModel)->SetReco(2);
272 else data->Fill("RC");
275 data->MakeBranch("TC");
276 data->SetTreeAddress("TC");
277 recoCluster->Trigger2Trigger();
280 //AZ loader->WriteRecPoints("OVERWRITE");
282 //---------------------------- Track & TriggerTrack ---------------------
283 if (!loader->TreeT()) loader->MakeTracksContainer();
286 data->MakeBranch("RL"); //trigger track
287 data->SetTreeAddress("RL");
288 recoEvent->EventReconstructTrigger();
292 data->MakeBranch("RT"); //track
293 data->SetTreeAddress("RT");
294 recoEvent->EventReconstruct();
297 loader->WriteTracks("OVERWRITE");
299 if (strstr(GetOption(),"Combi")) {
300 // Combined cluster / track
301 ((AliMUONClusterFinderAZ*) recModel)->SetReco(1);
302 data->MakeBranch("RC");
303 data->SetTreeAddress("RC");
304 AliMUONEventRecoCombi::Instance()->FillRecP(data, (AliMUONTrackReconstructorK*)recoEvent);
307 loader->WriteRecPoints("OVERWRITE");
309 //--------------------------- Resetting branches -----------------------
311 data->ResetRawClusters();
312 data->ResetTrigger();
313 data->ResetRecTracks();
314 data->ResetRecTriggerTracks();
317 loader->UnloadDigits();
318 loader->UnloadRecPoints();
319 loader->UnloadTracks();
327 //_____________________________________________________________________________
328 void AliMUONReconstructor::Reconstruct(AliRunLoader* runLoader,
329 AliRawReader* rawReader) const
335 AliLoader* loader = runLoader->GetLoader("MUONLoader");
336 Int_t evtNumber = runLoader->GetEventNumber();
338 AliMUONData data(loader,"MUON","MUON");
340 // passing loader as argument.
341 fDigitMaker->SetMUONData(&data);
343 AliMUONClusterReconstructor* recoCluster = CreateClusterReconstructor(&data);
345 AliMUONVTrackReconstructor *recoEvent;
346 if (strstr(GetOption(),"Original")) recoEvent = new AliMUONTrackReconstructor(&data);
347 else if (strstr(GetOption(),"Combi")) recoEvent = new AliMUONTrackReconstructorK(&data,"Combi");
348 else recoEvent = new AliMUONTrackReconstructorK(&data,"Kalman");
350 recoEvent->SetTriggerCircuit(fTriggerCircuit);
352 AliMUONClusterFinderVS *recModel = recoCluster->GetRecoModel();
354 if (!strstr(GetOption(),"VS"))
356 recModel = (AliMUONClusterFinderVS*) new AliMUONClusterFinderAZ();
357 recoCluster->SetRecoModel(recModel);
359 recModel->SetGhostChi2Cut(10);
360 recModel->SetEventNumber(evtNumber);
362 TTask* calibration = GetCalibrationTask(&data);
364 loader->LoadRecPoints("RECREATE");
365 loader->LoadTracks("RECREATE");
367 // Digits are not stored on disk and created on flight from rawdata.
368 // In order to write digits on disk the following line should be uncommented
369 // loader->LoadDigits("RECREATE");
374 TStopwatch totalTimer;
376 TStopwatch calibTimer;
377 TStopwatch clusterTimer;
378 TStopwatch trackingTimer;
380 rawTimer.Start(kTRUE); rawTimer.Stop();
381 calibTimer.Start(kTRUE); calibTimer.Stop();
382 clusterTimer.Start(kTRUE); clusterTimer.Stop();
383 trackingTimer.Start(kTRUE); trackingTimer.Stop();
385 totalTimer.Start(kTRUE);
387 while (rawReader->NextEvent())
389 AliDebug(1,Form("Event %d",iEvent));
391 runLoader->GetEvent(iEvent++);
393 //----------------------- raw2digits & raw2trigger-------------------
394 // if (!loader->TreeD())
396 // AliDebug(1,Form("Making Digit Container for event %d",iEvent));
397 // loader->MakeDigitsContainer();
399 // Digits are not stored on disk and created on flight from rawdata.
400 // In order to write digits on disk the following lines should be uncommented
401 // data.MakeBranch("D,GLT");
402 // data.SetTreeAddress("D,GLT");
403 data.SetDataContainer("D, GLT");
404 rawTimer.Start(kFALSE);
405 fDigitMaker->Raw2Digits(rawReader);
410 calibTimer.Start(kFALSE);
411 calibration->ExecuteTask();
414 // Digits are not stored on disk and created on flight from rawdata.
415 // In order to write digits on disk the following lines should be uncommented
416 // data.Fill("D,GLT");
417 // loader->WriteDigits("OVERWRITE");
418 //----------------------- digit2cluster & Trigger2Trigger -------------------
419 clusterTimer.Start(kFALSE);
421 if (!loader->TreeR()) loader->MakeRecPointsContainer();
424 data.MakeBranch("RC");
425 data.SetTreeAddress("RC");
426 recoCluster->Digits2Clusters();
430 data.MakeBranch("TC");
431 data.SetTreeAddress("TC");
434 loader->WriteRecPoints("OVERWRITE");
438 //---------------------------- Track & TriggerTrack ---------------------
439 trackingTimer.Start(kFALSE);
440 if (!loader->TreeT()) loader->MakeTracksContainer();
443 data.MakeBranch("RL"); //trigger track
444 data.SetTreeAddress("RL");
445 recoEvent->EventReconstructTrigger();
449 data.MakeBranch("RT"); //track
450 data.SetTreeAddress("RT");
451 recoEvent->EventReconstruct();
454 loader->WriteTracks("OVERWRITE");
455 trackingTimer.Stop();
457 //--------------------------- Resetting branches -----------------------
459 data.ResetRawClusters();
461 data.ResetRecTracks();
462 data.ResetRecTriggerTracks();
468 loader->UnloadRecPoints();
469 loader->UnloadTracks();
470 loader->UnloadDigits();
476 AliInfo(Form("Execution time for converting RAW data to digits in MUON : R:%.2fs C:%.2fs",
477 rawTimer.RealTime(),rawTimer.CpuTime()));
478 AliInfo(Form("Execution time for calibrating MUON : R:%.2fs C:%.2fs",
479 calibTimer.RealTime(),calibTimer.CpuTime()));
480 AliInfo(Form("Execution time for clusterizing MUON : R:%.2fs C:%.2fs",
481 clusterTimer.RealTime(),clusterTimer.CpuTime()));
482 AliInfo(Form("Execution time for tracking MUON : R:%.2fs C:%.2fs",
483 trackingTimer.RealTime(),trackingTimer.CpuTime()));
484 AliInfo(Form("Total Execution time for Reconstruct(from raw) MUON : R:%.2fs C:%.2fs",
485 totalTimer.RealTime(),totalTimer.CpuTime()));
488 //_____________________________________________________________________________
489 void AliMUONReconstructor::FillESD(AliRunLoader* runLoader, AliESD* esd) const
494 TClonesArray* recTracksArray = 0;
495 TClonesArray* recTrigTracksArray = 0;
497 AliLoader* loader = runLoader->GetLoader("MUONLoader");
498 loader->LoadTracks("READ");
499 AliMUONData* muonData = new AliMUONData(loader,"MUON","MUON");
502 Int_t iEvent;// nPart;
503 Int_t nTrackHits;// nPrimary;
506 Double_t bendingSlope, nonBendingSlope, inverseBendingMomentum;
507 Double_t xRec, yRec, zRec, chi2MatchTrigger;
510 // setting pointer for tracks, triggertracks & trackparam at vertex
511 AliMUONTrack* recTrack = 0;
512 AliMUONTrackParam* trackParam = 0;
513 AliMUONTriggerTrack* recTriggerTrack = 0;
515 iEvent = runLoader->GetEventNumber();
516 runLoader->GetEvent(iEvent);
519 Double_t vertex[3] = {0};
520 const AliESDVertex *esdVert = esd->GetVertex();
521 if (esdVert->GetNContributors()) {
522 esdVert->GetXYZ(vertex);
523 printf("find vertex\n");
525 // setting ESD MUON class
526 AliESDMuonTrack* theESDTrack = new AliESDMuonTrack() ;
528 //-------------------- trigger tracks-------------
530 muonData->SetTreeAddress("RL");
531 muonData->GetRecTriggerTracks();
532 recTrigTracksArray = muonData->RecTriggerTracks();
534 // ready global trigger pattern from first track
535 if (recTrigTracksArray)
536 recTriggerTrack = (AliMUONTriggerTrack*) recTrigTracksArray->First();
537 if (recTriggerTrack) trigPat = recTriggerTrack->GetGTPattern();
539 //printf(">>> Event %d Number of Recconstructed tracks %d \n",iEvent, nrectracks);
541 // -------------------- tracks-------------
542 muonData->SetTreeAddress("RT");
543 muonData->GetRecTracks();
544 recTracksArray = muonData->RecTracks();
546 Int_t nRecTracks = 0;
548 nRecTracks = (Int_t) recTracksArray->GetEntriesFast(); //
551 for (Int_t iRecTracks = 0; iRecTracks < nRecTracks; iRecTracks++) {
553 // reading info from tracks
554 recTrack = (AliMUONTrack*) recTracksArray->At(iRecTracks);
556 trackParam = (AliMUONTrackParam*) (recTrack->GetTrackParamAtHit())->First();
558 if (esdVert->GetNContributors())
559 AliMUONTrackExtrap::ExtrapToVertex(trackParam, vertex[0],vertex[1],vertex[2]);
561 bendingSlope = trackParam->GetBendingSlope();
562 nonBendingSlope = trackParam->GetNonBendingSlope();
563 inverseBendingMomentum = trackParam->GetInverseBendingMomentum();
564 xRec = trackParam->GetNonBendingCoor();
565 yRec = trackParam->GetBendingCoor();
566 zRec = trackParam->GetZ();
568 nTrackHits = recTrack->GetNTrackHits();
569 fitFmin = recTrack->GetFitFMin();
570 matchTrigger = recTrack->GetMatchTrigger();
571 chi2MatchTrigger = recTrack->GetChi2MatchTrigger();
573 // setting data member of ESD MUON
574 theESDTrack->SetInverseBendingMomentum(inverseBendingMomentum);
575 theESDTrack->SetThetaX(TMath::ATan(nonBendingSlope));
576 theESDTrack->SetThetaY(TMath::ATan(bendingSlope));
577 theESDTrack->SetZ(zRec);
578 theESDTrack->SetBendingCoor(yRec); // calculate vertex at ESD or Tracking level ?
579 theESDTrack->SetNonBendingCoor(xRec);
580 theESDTrack->SetChi2(fitFmin);
581 theESDTrack->SetNHit(nTrackHits);
582 theESDTrack->SetMatchTrigger(matchTrigger);
583 theESDTrack->SetChi2MatchTrigger(chi2MatchTrigger);
585 // storing ESD MUON Track into ESD Event
587 esd->AddMuonTrack(theESDTrack);
591 muonData->ResetRecTracks();
592 muonData->ResetRecTriggerTracks();
594 //} // end loop on event
595 loader->UnloadTracks();
599 }//_____________________________________________________________________________
600 void AliMUONReconstructor::FillESD(AliRunLoader* runLoader, AliRawReader* /*rawReader*/, AliESD* esd) const
605 // don't need rawReader ???
606 FillESD(runLoader, esd);