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