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