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