1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //-----------------------------------------------------------------------------
19 /// \class AliMUONRecoCheck
20 /// Utility class to check reconstruction
21 /// Reconstructed tracks are compared to reference tracks.
22 /// The reference tracks are built from AliTrackReference for the
23 /// hit in chamber (0..9) and from kinematics for the vertex parameters.
24 //-----------------------------------------------------------------------------
27 // Added a method to create a list of reconstructed AliMUONTrack objects from
28 // ESD data. This is necessary since the track objects that are actually created
29 // during offline reconstruction are no longer stored to disk.
30 // - Artur Szostak <artursz@iafrica.com>
32 // Use the new ESDInterface to create MUON objects from ESD data
35 #include "AliMUONRecoCheck.h"
36 #include "AliMUONTrack.h"
37 #include "AliMUONVTrackStore.h"
38 #include "AliMUONVCluster.h"
39 #include "AliMUONVClusterStore.h"
40 #include "AliMUONConstants.h"
41 #include "AliMUONESDInterface.h"
42 #include "AliMCEventHandler.h"
43 #include "AliMCEvent.h"
45 #include "AliTrackReference.h"
47 #include "AliESDEvent.h"
48 #include "AliESDMuonTrack.h"
52 #include <TParticle.h>
53 #include <TParticlePDG.h>
54 #include <Riostream.h>
57 ClassImp(AliMUONRecoCheck)
60 //_____________________________________________________________________________
61 AliMUONRecoCheck::AliMUONRecoCheck(const Char_t *esdFileName, const Char_t *pathSim)
63 fMCEventHandler(new AliMCEventHandler()),
64 fESDEvent(new AliESDEvent()),
69 fRecoTrackRefStore(0x0),
74 // TrackRefs and Particules
75 fMCEventHandler->SetInputPath(pathSim);
76 fMCEventHandler->InitIO("");
79 fESDFile = TFile::Open(esdFileName); // open the file
80 if (!fESDFile || !fESDFile->IsOpen()) {
81 AliError(Form("opening ESD file %s failed", esdFileName));
85 fESDTree = (TTree*) fESDFile->Get("esdTree"); // get the tree
87 AliError("no ESD tree found");
92 fESDEvent->ReadFromTree(fESDTree); // link fESDEvent to the tree
95 //_____________________________________________________________________________
96 AliMUONRecoCheck::~AliMUONRecoCheck()
99 delete fMCEventHandler;
101 if (fESDFile) fESDFile->Close();
105 //_____________________________________________________________________________
106 void AliMUONRecoCheck::ResetStores()
108 /// Deletes all the store objects that have been created and resets the pointers to 0x0
109 delete fTrackRefStore; fTrackRefStore = 0x0;
110 delete fRecoTrackRefStore; fRecoTrackRefStore = 0x0;
111 delete fRecoTrackStore; fRecoTrackStore = 0x0;
114 //_____________________________________________________________________________
115 Int_t AliMUONRecoCheck::NumberOfEvents() const
117 /// Return the number of events
118 if (fESDTree) return fESDTree->GetEntries();
122 //_____________________________________________________________________________
123 AliMUONVTrackStore* AliMUONRecoCheck::ReconstructedTracks(Int_t event)
125 /// Return a track store containing the reconstructed tracks (converted into
126 /// MUONTrack objects) for a given event
127 if (event != fCurrentEvent) {
129 fCurrentEvent = event;
132 if (fRecoTrackStore != 0x0) return fRecoTrackStore;
134 if (!fESDTree) return 0x0;
135 if (fESDTree->GetEvent(event) <= 0) {
136 AliError(Form("fails to read ESD object for event %d", event));
139 MakeReconstructedTracks();
140 return fRecoTrackStore;
144 //_____________________________________________________________________________
145 AliMUONVTrackStore* AliMUONRecoCheck::TrackRefs(Int_t event)
147 /// Return a track store containing the track references (converted into
148 /// MUONTrack objects) for a given event
149 if (event != fCurrentEvent) {
151 fCurrentEvent = event;
154 if (fTrackRefStore != 0x0) return fTrackRefStore;
156 if (!fMCEventHandler->GetEvent(event)) {
157 AliError(Form("fails to read MC objects for event %d", event));
161 return fTrackRefStore;
165 //_____________________________________________________________________________
166 AliMUONVTrackStore* AliMUONRecoCheck::ReconstructibleTracks(Int_t event)
168 /// Return a track store containing the reconstructible tracks for a given event
169 if (event != fCurrentEvent) {
171 fCurrentEvent = event;
174 if (fRecoTrackRefStore != 0x0) return fRecoTrackRefStore;
176 if (TrackRefs(event) == 0x0) return 0x0;
177 MakeReconstructibleTracks();
178 return fRecoTrackRefStore;
182 //_____________________________________________________________________________
183 void AliMUONRecoCheck::MakeReconstructedTracks()
185 /// Make reconstructed tracks
186 if (!(fRecoTrackStore = AliMUONESDInterface::NewTrackStore())) return;
188 // loop over all reconstructed tracks and add them to the store (skip ghosts)
189 Int_t nTracks = (Int_t) fESDEvent->GetNumberOfMuonTracks();
190 for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
191 AliESDMuonTrack* esdTrack = fESDEvent->GetMuonTrack(iTrack);
192 if (esdTrack->ContainTrackerData()) AliMUONESDInterface::Add(*esdTrack, *fRecoTrackStore);
197 //_____________________________________________________________________________
198 void AliMUONRecoCheck::MakeTrackRefs()
200 /// Make reconstructible tracks
201 AliMUONVTrackStore *tmpTrackRefStore = AliMUONESDInterface::NewTrackStore();
202 if (!tmpTrackRefStore) return;
204 Double_t x, y, z, pX, pY, pZ, bendingSlope, nonBendingSlope, inverseBendingMomentum;
206 TClonesArray* trackRefs;
207 Int_t nTrackRef = fMCEventHandler->MCEvent()->GetNumberOfTracks();
208 AliMUONVClusterStore* cStore = AliMUONESDInterface::NewClusterStore();
210 AliMUONVCluster* hit = cStore->CreateCluster(0,0,0);
212 // loop over simulated tracks
213 for (Int_t iTrackRef = 0; iTrackRef < nTrackRef; ++iTrackRef) {
214 Int_t nHits = fMCEventHandler->GetParticleAndTR(iTrackRef, particle, trackRefs);
216 // skip empty trackRefs
217 if (nHits < 1) continue;
219 // get the particle charge for further calculation
220 TParticlePDG* ppdg = particle->GetPDG();
221 Int_t charge = ppdg != NULL ? (Int_t)(ppdg->Charge()/3.0) : 0;
225 // loop over simulated track hits
226 for (Int_t iHit = 0; iHit < nHits; ++iHit) {
227 AliTrackReference* trackReference = static_cast<AliTrackReference*>(trackRefs->UncheckedAt(iHit));
229 // skip trackRefs not in MUON
230 if (trackReference->DetectorId() != AliTrackReference::kMUON) continue;
232 // Get track parameters of current hit
233 x = trackReference->X();
234 y = trackReference->Y();
235 z = trackReference->Z();
236 pX = trackReference->Px();
237 pY = trackReference->Py();
238 pZ = trackReference->Pz();
240 // check chamberId of current trackReference
241 Int_t detElemId = trackReference->UserId();
242 Int_t chamberId = detElemId / 100 - 1;
243 if (chamberId < 0 || chamberId >= AliMUONConstants::NTrackingCh()) continue;
245 // set hit parameters
246 hit->SetUniqueID(AliMUONVCluster::BuildUniqueID(chamberId, detElemId, iHit));
248 hit->SetErrXY(0.,0.);
250 // compute track parameters at hit
253 inverseBendingMomentum = 0;
254 if (TMath::Abs(pZ) > 0) {
255 bendingSlope = pY/pZ;
256 nonBendingSlope = pX/pZ;
258 Double_t pYZ = TMath::Sqrt(pY*pY+pZ*pZ);
259 if (pYZ >0) inverseBendingMomentum = 1/pYZ;
260 inverseBendingMomentum *= charge;
262 // set track parameters at hit
263 AliMUONTrackParam trackParam;
264 trackParam.SetNonBendingCoor(x);
265 trackParam.SetBendingCoor(y);
267 trackParam.SetBendingSlope(bendingSlope);
268 trackParam.SetNonBendingSlope(nonBendingSlope);
269 trackParam.SetInverseBendingMomentum(inverseBendingMomentum);
271 // add track parameters at current hit to the track
272 track.AddTrackParamAtCluster(trackParam, *hit, kTRUE);
275 // if none of the track hits was in MUON, goto the next track
276 if (track.GetNClusters() < 1) continue;
278 // get track parameters at particle's vertex
286 // compute rest of track parameters at particle's vertex
289 inverseBendingMomentum = 0;
290 if (TMath::Abs(pZ) > 0) {
291 bendingSlope = pY/pZ;
292 nonBendingSlope = pX/pZ;
294 Double_t pYZ = TMath::Sqrt(pY*pY+pZ*pZ);
295 if (pYZ >0) inverseBendingMomentum = 1/pYZ;
296 inverseBendingMomentum *= charge;
298 // set track parameters at particle's vertex
299 AliMUONTrackParam trackParamAtVertex;
300 trackParamAtVertex.SetNonBendingCoor(x);
301 trackParamAtVertex.SetBendingCoor(y);
302 trackParamAtVertex.SetZ(z);
303 trackParamAtVertex.SetBendingSlope(bendingSlope);
304 trackParamAtVertex.SetNonBendingSlope(nonBendingSlope);
305 trackParamAtVertex.SetInverseBendingMomentum(inverseBendingMomentum);
307 // add track parameters at vertex
308 track.SetTrackParamAtVertex(&trackParamAtVertex);
311 track.SetTrackID(iTrackRef);
312 tmpTrackRefStore->Add(track);
315 CleanMuonTrackRef(tmpTrackRefStore);
319 delete tmpTrackRefStore;
322 //_____________________________________________________________________________
323 void AliMUONRecoCheck::CleanMuonTrackRef(const AliMUONVTrackStore *tmpTrackRefStore)
325 /// Re-calculate hits parameters because two AliTrackReferences are recorded for
326 /// each chamber (one when particle is entering + one when particle is leaving
327 /// the sensitive volume)
328 if (!(fTrackRefStore = AliMUONESDInterface::NewTrackStore())) return;
330 Double_t maxGasGap = 1.; // cm
331 Double_t x, y, z, pX, pY, pZ, x1, y1, z1, pX1, pY1, pZ1, z2;
332 Double_t bendingSlope,nonBendingSlope,inverseBendingMomentum;
333 AliMUONVClusterStore* cStore = AliMUONESDInterface::NewClusterStore();
335 AliMUONVCluster* hit = cStore->CreateCluster(0,0,0);
338 TIter next(tmpTrackRefStore->CreateIterator());
340 // loop over tmpTrackRef
342 while ( ( track = static_cast<AliMUONTrack*>(next()) ) ) {
344 AliMUONTrack newTrack;
346 // loop over tmpTrackRef's hits
348 Int_t nTrackHits = track->GetNClusters();
349 while (iHit1 < nTrackHits) {
350 AliMUONTrackParam *trackParam1 = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->UncheckedAt(iHit1);
352 // get track parameters at hit1
353 x1 = trackParam1->GetNonBendingCoor();
354 y1 = trackParam1->GetBendingCoor();
355 z1 = trackParam1->GetZ();
356 pX1 = trackParam1->Px();
357 pY1 = trackParam1->Py();
358 pZ1 = trackParam1->Pz();
360 // prepare new track parameters
368 // loop over next tmpTrackRef's hits
369 Int_t nCombinedHits = 1;
370 for (Int_t iHit2 = iHit1+1; iHit2 < nTrackHits; iHit2++) {
371 AliMUONTrackParam *trackParam2 = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->UncheckedAt(iHit2);
373 // get z position of hit2
374 z2 = trackParam2->GetZ();
376 // complete new track parameters if hit2 is on the same detection element
377 if ( TMath::Abs(z2-z1) < maxGasGap ) {
378 x += trackParam2->GetNonBendingCoor();
379 y += trackParam2->GetBendingCoor();
381 pX += trackParam2->Px();
382 pY += trackParam2->Py();
383 pZ += trackParam2->Pz();
390 // finalize new track parameters
391 x /= (Double_t)nCombinedHits;
392 y /= (Double_t)nCombinedHits;
393 z /= (Double_t)nCombinedHits;
394 pX /= (Double_t)nCombinedHits;
395 pY /= (Double_t)nCombinedHits;
396 pZ /= (Double_t)nCombinedHits;
399 inverseBendingMomentum = 0;
400 if (TMath::Abs(pZ) > 0) {
401 bendingSlope = pY/pZ;
402 nonBendingSlope = pX/pZ;
404 Double_t pYZ = TMath::Sqrt(pY*pY+pZ*pZ);
405 if (pYZ >0) inverseBendingMomentum = 1/pYZ;
406 inverseBendingMomentum *= trackParam1->GetCharge();
408 // set hit parameters
409 hit->SetUniqueID(trackParam1->GetClusterPtr()->GetUniqueID());
411 hit->SetErrXY(0.,0.);
413 // set new track parameters at new hit
414 AliMUONTrackParam trackParam;
415 trackParam.SetNonBendingCoor(x);
416 trackParam.SetBendingCoor(y);
418 trackParam.SetBendingSlope(bendingSlope);
419 trackParam.SetNonBendingSlope(nonBendingSlope);
420 trackParam.SetInverseBendingMomentum(inverseBendingMomentum);
422 // add track parameters at current hit to the track
423 newTrack.AddTrackParamAtCluster(trackParam, *hit, kTRUE);
428 newTrack.SetTrackID(track->GetTrackID());
429 newTrack.SetTrackParamAtVertex(track->GetTrackParamAtVertex());
430 fTrackRefStore->Add(newTrack);
438 //_____________________________________________________________________________
439 void AliMUONRecoCheck::MakeReconstructibleTracks()
441 /// Isolate the reconstructible tracks
442 if (!(fRecoTrackRefStore = AliMUONESDInterface::NewTrackStore())) return;
444 // create iterator on trackRef
445 TIter next(fTrackRefStore->CreateIterator());
447 // loop over trackRef
449 while ( ( track = static_cast<AliMUONTrack*>(next()) ) ) {
451 Bool_t* chamberInTrack = new Bool_t(AliMUONConstants::NTrackingCh());
452 for (Int_t iCh = 0; iCh < AliMUONConstants::NTrackingCh(); iCh++) chamberInTrack[iCh] = kFALSE;
454 // loop over trackRef's hits to get hit chambers
455 Int_t nTrackHits = track->GetNClusters();
456 for (Int_t iHit = 0; iHit < nTrackHits; iHit++) {
457 AliMUONVCluster* hit = ((AliMUONTrackParam*) track->GetTrackParamAtCluster()->UncheckedAt(iHit))->GetClusterPtr();
458 chamberInTrack[hit->GetChamberId()] = kTRUE;
461 // track is reconstructible if the particle is depositing a hit
462 // in the following chamber combinations:
463 Bool_t trackOK = kTRUE;
464 if (!chamberInTrack[0] && !chamberInTrack[1]) trackOK = kFALSE;
465 if (!chamberInTrack[2] && !chamberInTrack[3]) trackOK = kFALSE;
466 if (!chamberInTrack[4] && !chamberInTrack[5]) trackOK = kFALSE;
467 Int_t nHitsInLastStations = 0;
468 for (Int_t iCh = 6; iCh < AliMUONConstants::NTrackingCh(); iCh++)
469 if (chamberInTrack[iCh]) nHitsInLastStations++;
470 if(nHitsInLastStations < 3) trackOK = kFALSE;
472 // Add reconstructible tracks to fRecoTrackRefStore
473 if (trackOK) fRecoTrackRefStore->Add(*track);
475 delete [] chamberInTrack;