Static data member fgTop replaced with the static function GetTop();
[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///////////////////////////////////////////////////////////////////////////////
b002ac70 22#include <TParticle.h>
30178c30 23#include <TArrayF.h>
24
cac2eb58 25#include "AliRunLoader.h"
b002ac70 26#include "AliHeader.h"
27#include "AliGenEventHeader.h"
cac2eb58 28#include "AliESD.h"
cf464691 29#include "AliMUONReconstructor.h"
cc87ebcd 30
cac2eb58 31#include "AliMUONData.h"
29f1b13a 32#include "AliMUONTrackReconstructor.h"
cac2eb58 33#include "AliMUONClusterReconstructor.h"
cac2eb58 34#include "AliMUONClusterFinderVS.h"
346fb008 35#include "AliMUONClusterFinderAZ.h"
cc87ebcd 36#include "AliMUONEventRecoCombi.h"
cac2eb58 37#include "AliMUONTrack.h"
38#include "AliMUONTrackParam.h"
39#include "AliMUONTriggerTrack.h"
40#include "AliESDMuonTrack.h"
1197ff51 41#include "AliMUONRawData.h"
42
cf464691 43#include "AliRawReader.h"
cac2eb58 44
29f1b13a 45
cac2eb58 46ClassImp(AliMUONReconstructor)
47//_____________________________________________________________________________
48AliMUONReconstructor::AliMUONReconstructor()
30178c30 49 : AliReconstructor()
8789635b 50{
51}
52//_____________________________________________________________________________
53AliMUONReconstructor::~AliMUONReconstructor()
cac2eb58 54{
55}
56//_____________________________________________________________________________
57void AliMUONReconstructor::Reconstruct(AliRunLoader* runLoader) const
58{
59// AliLoader
60 AliLoader* loader = runLoader->GetLoader("MUONLoader");
61 Int_t nEvents = runLoader->GetNumberOfEvents();
62
63// used local container for each method
64// passing fLoader as argument, could be avoided ???
29f1b13a 65 AliMUONTrackReconstructor* recoEvent = new AliMUONTrackReconstructor(loader);
cac2eb58 66 AliMUONData* dataEvent = recoEvent->GetMUONData();
8e0ae46c 67 if (strstr(GetOption(),"Original")) recoEvent->SetTrackMethod(1); // Original tracking
cc87ebcd 68 else if (strstr(GetOption(),"Combi")) recoEvent->SetTrackMethod(3); // Combined cluster / track
8e0ae46c 69 else recoEvent->SetTrackMethod(2); // Kalman
9ffe3ef4 70
cac2eb58 71 AliMUONClusterReconstructor* recoCluster = new AliMUONClusterReconstructor(loader);
72 AliMUONData* dataCluster = recoCluster->GetMUONData();
7e4a628d 73 AliMUONClusterFinderVS *recModel = recoCluster->GetRecoModel();
8e0ae46c 74 if (!strstr(GetOption(),"VS")) {
1af223d7 75 recModel = (AliMUONClusterFinderVS*) new AliMUONClusterFinderAZ();
9ffe3ef4 76 recoCluster->SetRecoModel(recModel);
9ffe3ef4 77 }
7e4a628d 78 recModel->SetGhostChi2Cut(10);
cac2eb58 79
80 loader->LoadDigits("READ");
81 loader->LoadRecPoints("RECREATE");
82 loader->LoadTracks("RECREATE");
cc87ebcd 83
84 Int_t chBeg = recoEvent->GetTrackMethod() == 3 ? 6 : 0;
85 // Loop over events
cac2eb58 86 for(Int_t ievent = 0; ievent < nEvents; ievent++) {
87 printf("Event %d\n",ievent);
88 runLoader->GetEvent(ievent);
89
8210cb40 90 //----------------------- digit2cluster & Trigger2Trigger -------------------
cac2eb58 91 if (!loader->TreeR()) loader->MakeRecPointsContainer();
cc87ebcd 92
cac2eb58 93 // tracking branch
cc87ebcd 94 if (recoEvent->GetTrackMethod() != 3) {
95 dataCluster->MakeBranch("RC");
96 dataCluster->SetTreeAddress("D,RC");
97 } else {
98 dataCluster->SetTreeAddress("D");
99 dataCluster->SetTreeAddress("RCC");
100 }
addbf88a 101 // Important for avoiding a memory leak when reading digits ( to be investigated more in detail)
cc87ebcd 102 // In any case the reading of GLT is needed for the Trigger2Tigger method below
addbf88a 103 dataCluster->SetTreeAddress("GLT");
cc87ebcd 104
105 recoCluster->Digits2Clusters(chBeg);
106 if (recoEvent->GetTrackMethod() == 3) {
107 // Combined cluster / track finder
108 AliMUONEventRecoCombi::Instance()->FillEvent(dataCluster, dataEvent, (AliMUONClusterFinderAZ*)recModel);
109 ((AliMUONClusterFinderAZ*) recModel)->SetReco(2);
110 }
111 else dataCluster->Fill("RC");
cac2eb58 112
113 // trigger branch
ce3e25a8 114 dataCluster->MakeBranch("TC");
115 dataCluster->SetTreeAddress("TC");
cc87ebcd 116 recoCluster->Trigger2Trigger();
ce3e25a8 117 dataCluster->Fill("TC");
cac2eb58 118
cc87ebcd 119 //AZ loader->WriteRecPoints("OVERWRITE");
cac2eb58 120
121 //---------------------------- Track & TriggerTrack ---------------------
122 if (!loader->TreeT()) loader->MakeTracksContainer();
123
124 // trigger branch
125 dataEvent->MakeBranch("RL"); //trigger track
126 dataEvent->SetTreeAddress("RL");
127 recoEvent->EventReconstructTrigger();
128 dataEvent->Fill("RL");
129
130 // tracking branch
131 dataEvent->MakeBranch("RT"); //track
132 dataEvent->SetTreeAddress("RT");
133 recoEvent->EventReconstruct();
134 dataEvent->Fill("RT");
135
cc87ebcd 136 loader->WriteTracks("OVERWRITE");
137
138 if (recoEvent->GetTrackMethod() == 3) {
139 // Combined cluster / track
140 ((AliMUONClusterFinderAZ*) recModel)->SetReco(1);
141 dataCluster->MakeBranch("RC");
142 dataCluster->SetTreeAddress("RC");
143 AliMUONEventRecoCombi::Instance()->FillRecP(dataCluster, recoEvent);
144 dataCluster->Fill("RC");
145 }
146 loader->WriteRecPoints("OVERWRITE");
147
cac2eb58 148 //--------------------------- Resetting branches -----------------------
149 dataCluster->ResetDigits();
150 dataCluster->ResetRawClusters();
ce3e25a8 151 dataCluster->ResetTrigger();
cac2eb58 152
153 dataEvent->ResetRawClusters();
154 dataEvent->ResetTrigger();
cc87ebcd 155 dataEvent->ResetRecTracks();
cac2eb58 156 dataEvent->ResetRecTriggerTracks();
29f1b13a 157
cac2eb58 158 }
159 loader->UnloadDigits();
160 loader->UnloadRecPoints();
161 loader->UnloadTracks();
162
163 delete recoCluster;
164 delete recoEvent;
cac2eb58 165}
cf464691 166
167//_____________________________________________________________________________
168void AliMUONReconstructor::Reconstruct(AliRunLoader* runLoader, AliRawReader* rawReader) const
169{
170// AliLoader
171 AliLoader* loader = runLoader->GetLoader("MUONLoader");
172
173// used local container for each method
174// passing fLoader as argument, could be avoided ???
29f1b13a 175 AliMUONTrackReconstructor* recoEvent = new AliMUONTrackReconstructor(loader);
cf464691 176 AliMUONData* dataEvent = recoEvent->GetMUONData();
177
1197ff51 178 AliMUONRawData* rawData = new AliMUONRawData(loader);
179 AliMUONData* dataCluster = rawData->GetMUONData();
180
181 AliMUONClusterReconstructor* recoCluster = new AliMUONClusterReconstructor(loader, dataCluster);
7e4a628d 182 AliMUONClusterFinderVS *recModel = recoCluster->GetRecoModel();
183 recModel->SetGhostChi2Cut(10);
cf464691 184
cf464691 185 loader->LoadRecPoints("RECREATE");
186 loader->LoadTracks("RECREATE");
ce6a659c 187 loader->LoadDigits("RECREATE");
188
189
cc87ebcd 190 // Loop over events
8210cb40 191 Int_t iEvent = 0;
cc87ebcd 192
8210cb40 193 while (rawReader->NextEvent()) {
cf464691 194 printf("Event %d\n",iEvent);
195 runLoader->GetEvent(iEvent++);
ce6a659c 196
197 //----------------------- raw2digits & raw2trigger-------------------
198 if (!loader->TreeD()) loader->MakeDigitsContainer();
199
a2da7817 200 // tracking branch
201 dataCluster->MakeBranch("D");
202 dataCluster->SetTreeAddress("D");
203 rawData->ReadTrackerDDL(rawReader);
cc87ebcd 204 dataCluster->Fill("D");
a2da7817 205
206 // trigger branch
207 dataCluster->MakeBranch("GLT");
208 dataCluster->SetTreeAddress("GLT");
209 rawData->ReadTriggerDDL(rawReader);
cc87ebcd 210 dataCluster->Fill("GLT");
ce6a659c 211
212 loader->WriteDigits("OVERWRITE");
cf464691 213
8210cb40 214 //----------------------- digit2cluster & Trigger2Trigger -------------------
cf464691 215 if (!loader->TreeR()) loader->MakeRecPointsContainer();
cc87ebcd 216
cf464691 217 // tracking branch
218 dataCluster->MakeBranch("RC");
a2da7817 219 dataCluster->SetTreeAddress("RC");
cc87ebcd 220 recoCluster->Digits2Clusters();
221 dataCluster->Fill("RC");
cf464691 222
223 // trigger branch
224 dataCluster->MakeBranch("TC");
225 dataCluster->SetTreeAddress("TC");
cc87ebcd 226 recoCluster->Trigger2Trigger();
cf464691 227 dataCluster->Fill("TC");
228
229 loader->WriteRecPoints("OVERWRITE");
230
231 //---------------------------- Track & TriggerTrack ---------------------
232 if (!loader->TreeT()) loader->MakeTracksContainer();
233
234 // trigger branch
235 dataEvent->MakeBranch("RL"); //trigger track
236 dataEvent->SetTreeAddress("RL");
237 recoEvent->EventReconstructTrigger();
238 dataEvent->Fill("RL");
239
240 // tracking branch
241 dataEvent->MakeBranch("RT"); //track
242 dataEvent->SetTreeAddress("RT");
243 recoEvent->EventReconstruct();
244 dataEvent->Fill("RT");
245
cc87ebcd 246 loader->WriteTracks("OVERWRITE");
247
cf464691 248 //--------------------------- Resetting branches -----------------------
249 dataCluster->ResetDigits();
250 dataCluster->ResetRawClusters();
251 dataCluster->ResetTrigger();
252
253 dataEvent->ResetRawClusters();
254 dataEvent->ResetTrigger();
255 dataEvent->ResetRecTracks();
256 dataEvent->ResetRecTriggerTracks();
cc87ebcd 257
cf464691 258 }
cf464691 259 loader->UnloadRecPoints();
260 loader->UnloadTracks();
ce6a659c 261 loader->UnloadDigits();
cf464691 262
263 delete recoCluster;
264 delete recoEvent;
cf464691 265}
266
cac2eb58 267//_____________________________________________________________________________
268void AliMUONReconstructor::FillESD(AliRunLoader* runLoader, AliESD* esd) const
269{
270 TClonesArray* recTracksArray = 0;
271 TClonesArray* recTrigTracksArray = 0;
cc87ebcd 272
cac2eb58 273 AliLoader* loader = runLoader->GetLoader("MUONLoader");
274 loader->LoadTracks("READ");
cac2eb58 275 AliMUONData* muonData = new AliMUONData(loader,"MUON","MUON");
276
cc87ebcd 277 // declaration
a2da7817 278 Int_t iEvent;// nPart;
279 Int_t nTrackHits;// nPrimary;
cac2eb58 280 Double_t fitFmin;
b002ac70 281 TArrayF vertex(3);
cac2eb58 282
283 Double_t bendingSlope, nonBendingSlope, inverseBendingMomentum;
284 Double_t xRec, yRec, zRec, chi2MatchTrigger;
285 Bool_t matchTrigger;
286
b002ac70 287 // setting pointer for tracks, triggertracks & trackparam at vertex
cac2eb58 288 AliMUONTrack* recTrack = 0;
289 AliMUONTrackParam* trackParam = 0;
290 AliMUONTriggerTrack* recTriggerTrack = 0;
a2da7817 291// TParticle* particle = new TParticle();
292// AliGenEventHeader* header = 0;
cc87ebcd 293 iEvent = runLoader->GetEventNumber();
cac2eb58 294 runLoader->GetEvent(iEvent);
295
b002ac70 296 // vertex calculation (maybe it exists already somewhere else)
297 vertex[0] = vertex[1] = vertex[2] = 0.;
a2da7817 298 // nPrimary = 0;
299// if ( (header = runLoader->GetHeader()->GenEventHeader()) ) {
300// header->PrimaryVertex(vertex);
301// } else {
302// runLoader->LoadKinematics("READ");
303// runLoader->TreeK()->GetBranch("Particles")->SetAddress(&particle);
304// nPart = (Int_t)runLoader->TreeK()->GetEntries();
305// for(Int_t iPart = 0; iPart < nPart; iPart++) {
306// runLoader->TreeK()->GetEvent(iPart);
307// if (particle->GetFirstMother() == -1) {
308// vertex[0] += particle->Vx();
309// vertex[1] += particle->Vy();
310// vertex[2] += particle->Vz();
311// nPrimary++;
312// }
313// if (nPrimary) {
314// vertex[0] /= (double)nPrimary;
315// vertex[1] /= (double)nPrimary;
316// vertex[2] /= (double)nPrimary;
317// }
318// }
319// }
cac2eb58 320 // setting ESD MUON class
30178c30 321 AliESDMuonTrack* theESDTrack = new AliESDMuonTrack() ;
cac2eb58 322
323 //-------------------- trigger tracks-------------
324 Long_t trigPat = 0;
325 muonData->SetTreeAddress("RL");
326 muonData->GetRecTriggerTracks();
327 recTrigTracksArray = muonData->RecTriggerTracks();
328
329 // ready global trigger pattern from first track
cc87ebcd 330 if (recTrigTracksArray)
cac2eb58 331 recTriggerTrack = (AliMUONTriggerTrack*) recTrigTracksArray->First();
332 if (recTriggerTrack) trigPat = recTriggerTrack->GetGTPattern();
333
334 //printf(">>> Event %d Number of Recconstructed tracks %d \n",iEvent, nrectracks);
cc87ebcd 335
cac2eb58 336 // -------------------- tracks-------------
337 muonData->SetTreeAddress("RT");
338 muonData->GetRecTracks();
339 recTracksArray = muonData->RecTracks();
cc87ebcd 340
cac2eb58 341 Int_t nRecTracks = 0;
342 if (recTracksArray)
343 nRecTracks = (Int_t) recTracksArray->GetEntriesFast(); //
cc87ebcd 344
cac2eb58 345 // loop over tracks
346 for (Int_t iRecTracks = 0; iRecTracks < nRecTracks; iRecTracks++) {
347
348 // reading info from tracks
349 recTrack = (AliMUONTrack*) recTracksArray->At(iRecTracks);
350
889a0215 351 trackParam = (AliMUONTrackParam*) (recTrack->GetTrackParamAtHit())->First();
352 trackParam->ExtrapToVertex(vertex[0],vertex[1],vertex[2]);
cac2eb58 353
354 bendingSlope = trackParam->GetBendingSlope();
355 nonBendingSlope = trackParam->GetNonBendingSlope();
356 inverseBendingMomentum = trackParam->GetInverseBendingMomentum();
357 xRec = trackParam->GetNonBendingCoor();
358 yRec = trackParam->GetBendingCoor();
359 zRec = trackParam->GetZ();
360
361 nTrackHits = recTrack->GetNTrackHits();
362 fitFmin = recTrack->GetFitFMin();
363 matchTrigger = recTrack->GetMatchTrigger();
364 chi2MatchTrigger = recTrack->GetChi2MatchTrigger();
365
366 // setting data member of ESD MUON
30178c30 367 theESDTrack->SetInverseBendingMomentum(inverseBendingMomentum);
368 theESDTrack->SetThetaX(TMath::ATan(nonBendingSlope));
369 theESDTrack->SetThetaY(TMath::ATan(bendingSlope));
889a0215 370 theESDTrack->SetZ(zRec);
371 theESDTrack->SetBendingCoor(yRec); // calculate vertex at ESD or Tracking level ?
372 theESDTrack->SetNonBendingCoor(xRec);
30178c30 373 theESDTrack->SetChi2(fitFmin);
374 theESDTrack->SetNHit(nTrackHits);
375 theESDTrack->SetMatchTrigger(matchTrigger);
376 theESDTrack->SetChi2MatchTrigger(chi2MatchTrigger);
cac2eb58 377
cc87ebcd 378 // storing ESD MUON Track into ESD Event
379 if (nRecTracks != 0)
30178c30 380 esd->AddMuonTrack(theESDTrack);
cac2eb58 381 } // end loop tracks
382
383 // add global trigger pattern
cc87ebcd 384 if (nRecTracks != 0)
cac2eb58 385 esd->SetTrigger(trigPat);
386
387 // reset muondata
388 muonData->ResetRecTracks();
389 muonData->ResetRecTriggerTracks();
390
cc87ebcd 391 //} // end loop on event
392 loader->UnloadTracks();
a2da7817 393 // if (!header)
394// runLoader->UnloadKinematics();
30178c30 395 delete theESDTrack;
cac2eb58 396 delete muonData;
b002ac70 397 // delete particle;
a2da7817 398}//_____________________________________________________________________________
399void AliMUONReconstructor::FillESD(AliRunLoader* runLoader, AliRawReader* /*rawReader*/, AliESD* esd) const
400{
401 // don't need rawReader ???
402 FillESD(runLoader, esd);
cac2eb58 403}