Access to common block ALLDLT containing primary ionisation electron information.
[u/mrichter/AliRoot.git] / MUON / AliMUONReconstructor.cxx
CommitLineData
cac2eb58 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 **************************************************************************/
cac2eb58 15/* $Id$ */
16
17///////////////////////////////////////////////////////////////////////////////
18// //
b002ac70 19// class for MUON reconstruction //
cac2eb58 20// //
21///////////////////////////////////////////////////////////////////////////////
30178c30 22
cf464691 23#include "AliMUONReconstructor.h"
b2d7df0b 24
25#include "AliESD.h"
26#include "AliESDMuonTrack.h"
94f6fba9 27#include "AliLog.h"
b2d7df0b 28#include "AliMUON.h"
29#include "AliMUONCalibrationData.h"
346fb008 30#include "AliMUONClusterFinderAZ.h"
b2d7df0b 31#include "AliMUONClusterFinderVS.h"
32#include "AliMUONClusterReconstructor.h"
33#include "AliMUONData.h"
34#include "AliMUONDigitCalibrator.h"
cc87ebcd 35#include "AliMUONEventRecoCombi.h"
2cf44ef3 36#include "AliMUONDigitMaker.h"
cac2eb58 37#include "AliMUONTrack.h"
38#include "AliMUONTrackParam.h"
b2d7df0b 39#include "AliMUONTrackReconstructor.h"
cac2eb58 40#include "AliMUONTriggerTrack.h"
cf464691 41#include "AliRawReader.h"
b2d7df0b 42#include "AliRun.h"
43#include "AliRunLoader.h"
44#include "TTask.h"
94f6fba9 45#include "TStopwatch.h"
29f1b13a 46
cac2eb58 47ClassImp(AliMUONReconstructor)
b2d7df0b 48
cac2eb58 49//_____________________________________________________________________________
50AliMUONReconstructor::AliMUONReconstructor()
b2d7df0b 51 : AliReconstructor(), fCalibrationData(0x0)
8789635b 52{
d19b6003 53/// Default constructor
54
94f6fba9 55 AliDebug(1,"");
8789635b 56}
94f6fba9 57
884a73f1 58//______________________________________________________________________________
59AliMUONReconstructor::AliMUONReconstructor(const AliMUONReconstructor& right)
60 : AliReconstructor(right)
61{
62/// Protected copy constructor (not implemented)
63
64 AliFatal("Copy constructor not provided.");
65}
66
8789635b 67//_____________________________________________________________________________
68AliMUONReconstructor::~AliMUONReconstructor()
cac2eb58 69{
d19b6003 70/// Destructor
71
94f6fba9 72 AliDebug(1,"");
b2d7df0b 73 delete fCalibrationData;
cac2eb58 74}
b2d7df0b 75
884a73f1 76//______________________________________________________________________________
77AliMUONReconstructor&
78AliMUONReconstructor::operator=(const AliMUONReconstructor& right)
79{
80/// Protected assignement operator (not implemented)
81
82 // check assignement to self
83 if (this == &right) return *this;
84
85 AliFatal("Assignement operator not provided.");
86
87 return *this;
88}
89
b2d7df0b 90//_____________________________________________________________________________
91TTask*
92AliMUONReconstructor::GetCalibrationTask(AliMUONData* data) const
93{
d19b6003 94/// Create the calibration task(s).
b2d7df0b 95
96 const AliRun* run = fRunLoader->GetAliRun();
97
98 // Not really clean, but for the moment we must check whether the
99 // simulation has decalibrated the data or not...
100 const AliMUON* muon = static_cast<AliMUON*>(run->GetModule("MUON"));
101 if ( muon->DigitizerType().Contains("NewDigitizer") )
102 {
103 AliInfo("Calibration will occur.");
104 Int_t runNumber = run->GetRunNumber();
105 fCalibrationData = new AliMUONCalibrationData(runNumber);
106 if ( !fCalibrationData->IsValid() )
107 {
108 AliError("Could not retrieve calibrations !");
109 delete fCalibrationData;
110 fCalibrationData = 0x0;
111 return 0x0;
112 }
113 TTask* calibration = new TTask("MUONCalibrator","MUON Digit calibrator");
114 calibration->Add(new AliMUONDigitCalibrator(data,fCalibrationData));
115 //FIXME: calibration->Add(something about dead channels should go here).
116 return calibration;
117 }
118 else
119 {
120 AliInfo("Detected the usage of old digitizer (w/o decalibration). "
121 "Will not calibrate then.");
122 return 0x0;
123 }
124}
125
126//_____________________________________________________________________________
127void
128AliMUONReconstructor::Init(AliRunLoader* runLoader)
129{
d19b6003 130/// Initialize
131
b2d7df0b 132 fRunLoader = runLoader;
133}
134
cac2eb58 135//_____________________________________________________________________________
136void AliMUONReconstructor::Reconstruct(AliRunLoader* runLoader) const
137{
d19b6003 138/// Reconstruct
139/// \todo add more
140
cac2eb58 141 AliLoader* loader = runLoader->GetLoader("MUONLoader");
142 Int_t nEvents = runLoader->GetNumberOfEvents();
143
3bc8b580 144 AliMUONData* data = new AliMUONData(loader,"MUON","MUON");
145
146// passing loader as argument.
147 AliMUONTrackReconstructor* recoEvent = new AliMUONTrackReconstructor(loader, data);
148
149 if (strstr(GetOption(),"Original"))
150 recoEvent->SetTrackMethod(1); // Original tracking
151 else if (strstr(GetOption(),"Combi"))
152 recoEvent->SetTrackMethod(3); // Combined cluster / track
153 else
154 recoEvent->SetTrackMethod(2); // Kalman
155
94f6fba9 156 AliMUONClusterReconstructor* recoCluster = new AliMUONClusterReconstructor(data);
3bc8b580 157
7e4a628d 158 AliMUONClusterFinderVS *recModel = recoCluster->GetRecoModel();
3bc8b580 159
8e0ae46c 160 if (!strstr(GetOption(),"VS")) {
1af223d7 161 recModel = (AliMUONClusterFinderVS*) new AliMUONClusterFinderAZ();
9ffe3ef4 162 recoCluster->SetRecoModel(recModel);
9ffe3ef4 163 }
7e4a628d 164 recModel->SetGhostChi2Cut(10);
cac2eb58 165
166 loader->LoadDigits("READ");
167 loader->LoadRecPoints("RECREATE");
168 loader->LoadTracks("RECREATE");
cc87ebcd 169
b2d7df0b 170 TTask* calibration = GetCalibrationTask(data);
171
cc87ebcd 172 Int_t chBeg = recoEvent->GetTrackMethod() == 3 ? 6 : 0;
173 // Loop over events
cac2eb58 174 for(Int_t ievent = 0; ievent < nEvents; ievent++) {
94f6fba9 175
176 AliDebug(1,Form("Event %d",ievent));
177
cac2eb58 178 runLoader->GetEvent(ievent);
179
8210cb40 180 //----------------------- digit2cluster & Trigger2Trigger -------------------
cac2eb58 181 if (!loader->TreeR()) loader->MakeRecPointsContainer();
cc87ebcd 182
cac2eb58 183 // tracking branch
cc87ebcd 184 if (recoEvent->GetTrackMethod() != 3) {
3bc8b580 185 data->MakeBranch("RC");
186 data->SetTreeAddress("D,RC");
cc87ebcd 187 } else {
3bc8b580 188 data->SetTreeAddress("D");
189 data->SetTreeAddress("RCC");
cc87ebcd 190 }
addbf88a 191 // Important for avoiding a memory leak when reading digits ( to be investigated more in detail)
cc87ebcd 192 // In any case the reading of GLT is needed for the Trigger2Tigger method below
3bc8b580 193 data->SetTreeAddress("GLT");
cc87ebcd 194
3bc8b580 195 data->GetDigits();
b2d7df0b 196
197 if ( calibration )
198 {
199 calibration->ExecuteTask();
200 }
201
cc87ebcd 202 recoCluster->Digits2Clusters(chBeg);
b2d7df0b 203
cc87ebcd 204 if (recoEvent->GetTrackMethod() == 3) {
205 // Combined cluster / track finder
3bc8b580 206 AliMUONEventRecoCombi::Instance()->FillEvent(data, (AliMUONClusterFinderAZ*)recModel);
cc87ebcd 207 ((AliMUONClusterFinderAZ*) recModel)->SetReco(2);
208 }
3bc8b580 209 else data->Fill("RC");
cac2eb58 210
211 // trigger branch
3bc8b580 212 data->MakeBranch("TC");
213 data->SetTreeAddress("TC");
cc87ebcd 214 recoCluster->Trigger2Trigger();
3bc8b580 215 data->Fill("TC");
cac2eb58 216
cc87ebcd 217 //AZ loader->WriteRecPoints("OVERWRITE");
cac2eb58 218
219 //---------------------------- Track & TriggerTrack ---------------------
220 if (!loader->TreeT()) loader->MakeTracksContainer();
221
222 // trigger branch
3bc8b580 223 data->MakeBranch("RL"); //trigger track
224 data->SetTreeAddress("RL");
cac2eb58 225 recoEvent->EventReconstructTrigger();
3bc8b580 226 data->Fill("RL");
cac2eb58 227
228 // tracking branch
3bc8b580 229 data->MakeBranch("RT"); //track
230 data->SetTreeAddress("RT");
cac2eb58 231 recoEvent->EventReconstruct();
3bc8b580 232 data->Fill("RT");
cac2eb58 233
cc87ebcd 234 loader->WriteTracks("OVERWRITE");
235
236 if (recoEvent->GetTrackMethod() == 3) {
237 // Combined cluster / track
238 ((AliMUONClusterFinderAZ*) recModel)->SetReco(1);
3bc8b580 239 data->MakeBranch("RC");
240 data->SetTreeAddress("RC");
241 AliMUONEventRecoCombi::Instance()->FillRecP(data, recoEvent);
242 data->Fill("RC");
cc87ebcd 243 }
244 loader->WriteRecPoints("OVERWRITE");
245
cac2eb58 246 //--------------------------- Resetting branches -----------------------
3bc8b580 247 data->ResetDigits();
248 data->ResetRawClusters();
249 data->ResetTrigger();
cac2eb58 250
3bc8b580 251 data->ResetRawClusters();
252 data->ResetTrigger();
253 data->ResetRecTracks();
254 data->ResetRecTriggerTracks();
29f1b13a 255
cac2eb58 256 }
257 loader->UnloadDigits();
258 loader->UnloadRecPoints();
259 loader->UnloadTracks();
260
261 delete recoCluster;
262 delete recoEvent;
3bc8b580 263 delete data;
b2d7df0b 264 delete calibration;
cac2eb58 265}
cf464691 266
267//_____________________________________________________________________________
268void AliMUONReconstructor::Reconstruct(AliRunLoader* runLoader, AliRawReader* rawReader) const
269{
d19b6003 270/// Recontruct
271/// \todo add more
272
94f6fba9 273 // AliLoader
cf464691 274 AliLoader* loader = runLoader->GetLoader("MUONLoader");
94f6fba9 275 AliMUONData data(loader,"MUON","MUON");
cf464691 276
94f6fba9 277 // passing loader as argument.
278 AliMUONTrackReconstructor recoEvent(loader, &data);
cf464691 279
2cf44ef3 280 AliMUONDigitMaker rawData(&data);
1197ff51 281
94f6fba9 282 AliMUONClusterReconstructor recoCluster(&data);
30eabfb8 283
284 if (strstr(GetOption(),"Original"))
94f6fba9 285 {
286 recoEvent.SetTrackMethod(1); // Original tracking
287 }
30eabfb8 288 else
94f6fba9 289 {
290 recoEvent.SetTrackMethod(2); // Kalman
291 }
292
293 AliMUONClusterFinderVS *recModel = recoCluster.GetRecoModel();
294 if (!strstr(GetOption(),"VS"))
295 {
30eabfb8 296 recModel = (AliMUONClusterFinderVS*) new AliMUONClusterFinderAZ();
94f6fba9 297 recoCluster.SetRecoModel(recModel);
30eabfb8 298 }
7e4a628d 299 recModel->SetGhostChi2Cut(10);
cf464691 300
94f6fba9 301 TTask* calibration = GetCalibrationTask(&data);
b2d7df0b 302
cf464691 303 loader->LoadRecPoints("RECREATE");
304 loader->LoadTracks("RECREATE");
94f6fba9 305 loader->LoadDigits("READ");
306
cc87ebcd 307 // Loop over events
8210cb40 308 Int_t iEvent = 0;
94f6fba9 309
310 TStopwatch totalTimer;
311 TStopwatch rawTimer;
312 TStopwatch calibTimer;
313 TStopwatch clusterTimer;
314 TStopwatch trackingTimer;
315
316 rawTimer.Start(kTRUE); rawTimer.Stop();
317 calibTimer.Start(kTRUE); calibTimer.Stop();
318 clusterTimer.Start(kTRUE); clusterTimer.Stop();
319 trackingTimer.Start(kTRUE); trackingTimer.Stop();
320
321 totalTimer.Start(kTRUE);
322
323 while (rawReader->NextEvent())
324 {
325 AliDebug(1,Form("Event %d",iEvent));
326
cf464691 327 runLoader->GetEvent(iEvent++);
ce6a659c 328
329 //----------------------- raw2digits & raw2trigger-------------------
94f6fba9 330 if (!loader->TreeD())
331 {
332 AliDebug(1,Form("Making Digit Container for event %d",iEvent));
333 loader->MakeDigitsContainer();
334 }
335
336 data.SetTreeAddress("D,GLT");
337 rawTimer.Start(kFALSE);
338 rawData.Raw2Digits(rawReader);
339 rawTimer.Stop();
340
b2d7df0b 341 if ( calibration )
342 {
94f6fba9 343 calibTimer.Start(kFALSE);
b2d7df0b 344 calibration->ExecuteTask();
94f6fba9 345 calibTimer.Stop();
b2d7df0b 346 }
94f6fba9 347
8210cb40 348 //----------------------- digit2cluster & Trigger2Trigger -------------------
94f6fba9 349 clusterTimer.Start(kFALSE);
350
cf464691 351 if (!loader->TreeR()) loader->MakeRecPointsContainer();
cc87ebcd 352
cf464691 353 // tracking branch
94f6fba9 354 data.MakeBranch("RC");
355 data.SetTreeAddress("RC");
356 recoCluster.Digits2Clusters();
357 data.Fill("RC");
cf464691 358
359 // trigger branch
94f6fba9 360 data.MakeBranch("TC");
361 data.SetTreeAddress("TC");
b59ce4c6 362 recoCluster.Trigger2Trigger();
94f6fba9 363 data.Fill("TC");
364
cf464691 365 loader->WriteRecPoints("OVERWRITE");
366
94f6fba9 367 clusterTimer.Stop();
368
cf464691 369 //---------------------------- Track & TriggerTrack ---------------------
94f6fba9 370 trackingTimer.Start(kFALSE);
cf464691 371 if (!loader->TreeT()) loader->MakeTracksContainer();
372
373 // trigger branch
94f6fba9 374 data.MakeBranch("RL"); //trigger track
375 data.SetTreeAddress("RL");
376 recoEvent.EventReconstructTrigger();
377 data.Fill("RL");
cf464691 378
379 // tracking branch
94f6fba9 380 data.MakeBranch("RT"); //track
381 data.SetTreeAddress("RT");
382 recoEvent.EventReconstruct();
383 data.Fill("RT");
cf464691 384
cc87ebcd 385 loader->WriteTracks("OVERWRITE");
94f6fba9 386 trackingTimer.Stop();
387
cf464691 388 //--------------------------- Resetting branches -----------------------
94f6fba9 389 data.ResetDigits();
390 data.ResetRawClusters();
391 data.ResetTrigger();
392
393 data.ResetRawClusters();
394 data.ResetTrigger();
395 data.ResetRecTracks();
396 data.ResetRecTriggerTracks();
cc87ebcd 397
cf464691 398 }
94f6fba9 399
400 totalTimer.Stop();
401
cf464691 402 loader->UnloadRecPoints();
403 loader->UnloadTracks();
ce6a659c 404 loader->UnloadDigits();
cf464691 405
94f6fba9 406 AliInfo(Form("Execution time for converting RAW data to digits in MUON : R:%.2fs C:%.2fs",
407 rawTimer.RealTime(),rawTimer.CpuTime()));
408 AliInfo(Form("Execution time for calibrating MUON : R:%.2fs C:%.2fs",
409 calibTimer.RealTime(),calibTimer.CpuTime()));
410 AliInfo(Form("Execution time for clusterizing MUON : R:%.2fs C:%.2fs",
411 clusterTimer.RealTime(),clusterTimer.CpuTime()));
412 AliInfo(Form("Execution time for tracking MUON : R:%.2fs C:%.2fs",
413 trackingTimer.RealTime(),trackingTimer.CpuTime()));
414 AliInfo(Form("Total Execution time for Reconstruct(from raw) MUON : R:%.2fs C:%.2fs",
415 totalTimer.RealTime(),totalTimer.CpuTime()));
cf464691 416}
417
cac2eb58 418//_____________________________________________________________________________
419void AliMUONReconstructor::FillESD(AliRunLoader* runLoader, AliESD* esd) const
420{
d19b6003 421/// Fill ESD
422/// \todo add more
423
cac2eb58 424 TClonesArray* recTracksArray = 0;
425 TClonesArray* recTrigTracksArray = 0;
cc87ebcd 426
cac2eb58 427 AliLoader* loader = runLoader->GetLoader("MUONLoader");
428 loader->LoadTracks("READ");
cac2eb58 429 AliMUONData* muonData = new AliMUONData(loader,"MUON","MUON");
430
cc87ebcd 431 // declaration
a2da7817 432 Int_t iEvent;// nPart;
433 Int_t nTrackHits;// nPrimary;
cac2eb58 434 Double_t fitFmin;
cac2eb58 435
436 Double_t bendingSlope, nonBendingSlope, inverseBendingMomentum;
437 Double_t xRec, yRec, zRec, chi2MatchTrigger;
438 Bool_t matchTrigger;
439
b002ac70 440 // setting pointer for tracks, triggertracks & trackparam at vertex
cac2eb58 441 AliMUONTrack* recTrack = 0;
442 AliMUONTrackParam* trackParam = 0;
443 AliMUONTriggerTrack* recTriggerTrack = 0;
2cf44ef3 444
cc87ebcd 445 iEvent = runLoader->GetEventNumber();
cac2eb58 446 runLoader->GetEvent(iEvent);
447
94f6fba9 448 // Get vertex
449 Double_t vertex[3] = {0};
450 const AliESDVertex *esdVert = esd->GetVertex();
451 if (esdVert) esdVert->GetXYZ(vertex);
452
cac2eb58 453 // setting ESD MUON class
30178c30 454 AliESDMuonTrack* theESDTrack = new AliESDMuonTrack() ;
cac2eb58 455
456 //-------------------- trigger tracks-------------
457 Long_t trigPat = 0;
458 muonData->SetTreeAddress("RL");
459 muonData->GetRecTriggerTracks();
460 recTrigTracksArray = muonData->RecTriggerTracks();
461
462 // ready global trigger pattern from first track
cc87ebcd 463 if (recTrigTracksArray)
cac2eb58 464 recTriggerTrack = (AliMUONTriggerTrack*) recTrigTracksArray->First();
465 if (recTriggerTrack) trigPat = recTriggerTrack->GetGTPattern();
466
467 //printf(">>> Event %d Number of Recconstructed tracks %d \n",iEvent, nrectracks);
cc87ebcd 468
cac2eb58 469 // -------------------- tracks-------------
470 muonData->SetTreeAddress("RT");
471 muonData->GetRecTracks();
472 recTracksArray = muonData->RecTracks();
cc87ebcd 473
cac2eb58 474 Int_t nRecTracks = 0;
475 if (recTracksArray)
476 nRecTracks = (Int_t) recTracksArray->GetEntriesFast(); //
cc87ebcd 477
cac2eb58 478 // loop over tracks
479 for (Int_t iRecTracks = 0; iRecTracks < nRecTracks; iRecTracks++) {
480
481 // reading info from tracks
482 recTrack = (AliMUONTrack*) recTracksArray->At(iRecTracks);
483
889a0215 484 trackParam = (AliMUONTrackParam*) (recTrack->GetTrackParamAtHit())->First();
211c52eb 485
486 if (esdVert)
487 trackParam->ExtrapToVertex(vertex[0],vertex[1],vertex[2]);
cac2eb58 488
489 bendingSlope = trackParam->GetBendingSlope();
490 nonBendingSlope = trackParam->GetNonBendingSlope();
211c52eb 491 inverseBendingMomentum = trackParam->GetInverseBendingMomentum();
cac2eb58 492 xRec = trackParam->GetNonBendingCoor();
493 yRec = trackParam->GetBendingCoor();
494 zRec = trackParam->GetZ();
495
496 nTrackHits = recTrack->GetNTrackHits();
497 fitFmin = recTrack->GetFitFMin();
498 matchTrigger = recTrack->GetMatchTrigger();
499 chi2MatchTrigger = recTrack->GetChi2MatchTrigger();
500
501 // setting data member of ESD MUON
30178c30 502 theESDTrack->SetInverseBendingMomentum(inverseBendingMomentum);
503 theESDTrack->SetThetaX(TMath::ATan(nonBendingSlope));
504 theESDTrack->SetThetaY(TMath::ATan(bendingSlope));
889a0215 505 theESDTrack->SetZ(zRec);
506 theESDTrack->SetBendingCoor(yRec); // calculate vertex at ESD or Tracking level ?
507 theESDTrack->SetNonBendingCoor(xRec);
30178c30 508 theESDTrack->SetChi2(fitFmin);
509 theESDTrack->SetNHit(nTrackHits);
510 theESDTrack->SetMatchTrigger(matchTrigger);
511 theESDTrack->SetChi2MatchTrigger(chi2MatchTrigger);
cac2eb58 512
cc87ebcd 513 // storing ESD MUON Track into ESD Event
514 if (nRecTracks != 0)
30178c30 515 esd->AddMuonTrack(theESDTrack);
cac2eb58 516 } // end loop tracks
517
cac2eb58 518 // reset muondata
519 muonData->ResetRecTracks();
520 muonData->ResetRecTriggerTracks();
521
cc87ebcd 522 //} // end loop on event
523 loader->UnloadTracks();
2cf44ef3 524
30178c30 525 delete theESDTrack;
cac2eb58 526 delete muonData;
a2da7817 527}//_____________________________________________________________________________
528void AliMUONReconstructor::FillESD(AliRunLoader* runLoader, AliRawReader* /*rawReader*/, AliESD* esd) const
529{
d19b6003 530/// Fill ESD
531/// \todo add more
532
a2da7817 533 // don't need rawReader ???
534 FillESD(runLoader, esd);
cac2eb58 535}