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