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
36 #include "AliMUONRecoCheck.h"
37 #include "AliMUONTrack.h"
38 #include "AliMUONVTrackStore.h"
39 #include "AliMUONVCluster.h"
40 #include "AliMUONVClusterStore.h"
41 #include "AliMUONConstants.h"
42 #include "AliMUONESDInterface.h"
43 #include "AliMUONTrackParam.h"
44 #include "AliMCEventHandler.h"
45 #include "AliMCEvent.h"
47 #include "AliTrackReference.h"
49 #include "AliESDEvent.h"
50 #include "AliESDMuonTrack.h"
54 #include <TParticle.h>
55 #include <TParticlePDG.h>
56 #include <Riostream.h>
59 ClassImp(AliMUONRecoCheck)
62 //_____________________________________________________________________________
63 AliMUONRecoCheck::AliMUONRecoCheck(const Char_t *esdFileName, const Char_t *pathSim)
65 fMCEventHandler(new AliMCEventHandler()),
66 fESDEvent(new AliESDEvent()),
71 fRecoTrackRefStore(0x0),
77 // TrackRefs and Particules
78 fMCEventHandler->SetInputPath(pathSim);
79 fMCEventHandler->InitIO("");
82 fESDFile = TFile::Open(esdFileName); // open the file
83 if (!fESDFile || !fESDFile->IsOpen()) {
84 AliError(Form("opening ESD file %s failed", esdFileName));
88 fESDTree = (TTree*) fESDFile->Get("esdTree"); // get the tree
90 AliError("no ESD tree found");
95 fESDEvent->ReadFromTree(fESDTree); // link fESDEvent to the tree
98 //_____________________________________________________________________________
99 AliMUONRecoCheck::AliMUONRecoCheck(AliESDEvent *esdEvent, AliMCEventHandler *mcEventHandler)
107 fRecoTrackRefStore(0x0),
108 fRecoTrackStore(0x0),
109 fESDEventOwner(kFALSE)
113 // TrackRefs and Particules
114 fMCEventHandler = mcEventHandler;
117 fESDEvent = esdEvent;
121 //_____________________________________________________________________________
122 AliMUONRecoCheck::~AliMUONRecoCheck()
125 if (fESDEventOwner) {
126 delete fMCEventHandler;
128 if (fESDFile) fESDFile->Close();
133 //_____________________________________________________________________________
134 void AliMUONRecoCheck::ResetStores()
136 /// Deletes all the store objects that have been created and resets the pointers to 0x0
137 delete fTrackRefStore; fTrackRefStore = 0x0;
138 delete fRecoTrackRefStore; fRecoTrackRefStore = 0x0;
139 delete fRecoTrackStore; fRecoTrackStore = 0x0;
142 //_____________________________________________________________________________
143 Int_t AliMUONRecoCheck::NumberOfEvents() const
145 /// Return the number of events
146 if (fESDEventOwner && fESDTree) return fESDTree->GetEntries();
150 //_____________________________________________________________________________
151 AliMUONVTrackStore* AliMUONRecoCheck::ReconstructedTracks(Int_t event)
153 /// Return a track store containing the reconstructed tracks (converted into
154 /// MUONTrack objects) for a given event
156 if (!fESDEventOwner) {
157 MakeReconstructedTracks();
158 return fRecoTrackStore;
161 if (event != fCurrentEvent) {
163 fCurrentEvent = event;
166 if (fRecoTrackStore != 0x0) return fRecoTrackStore;
168 if (!fESDTree) return 0x0;
169 if (fESDTree->GetEvent(event) <= 0) {
170 AliError(Form("fails to read ESD object for event %d", event));
173 MakeReconstructedTracks();
174 return fRecoTrackStore;
178 //_____________________________________________________________________________
179 AliMUONVTrackStore* AliMUONRecoCheck::TrackRefs(Int_t event)
181 /// Return a track store containing the track references (converted into
182 /// MUONTrack objects) for a given event
184 if (!fESDEventOwner) {
186 return fTrackRefStore;
189 if (event != fCurrentEvent) {
191 fCurrentEvent = event;
194 if (fTrackRefStore != 0x0) return fTrackRefStore;
196 if (!fMCEventHandler->GetEvent(event)) {
197 AliError(Form("fails to read MC objects for event %d", event));
201 return fTrackRefStore;
205 //_____________________________________________________________________________
206 AliMUONVTrackStore* AliMUONRecoCheck::ReconstructibleTracks(Int_t event)
208 /// Return a track store containing the reconstructible tracks for a given event
210 if (!fESDEventOwner) {
211 if (TrackRefs(event) == 0x0) return 0x0;
212 MakeReconstructibleTracks();
213 return fRecoTrackRefStore;
216 if (event != fCurrentEvent) {
218 fCurrentEvent = event;
221 if (fRecoTrackRefStore != 0x0) return fRecoTrackRefStore;
223 if (TrackRefs(event) == 0x0) return 0x0;
224 MakeReconstructibleTracks();
225 return fRecoTrackRefStore;
229 //_____________________________________________________________________________
230 void AliMUONRecoCheck::MakeReconstructedTracks()
232 /// Make reconstructed tracks
233 if (!(fRecoTrackStore = AliMUONESDInterface::NewTrackStore())) return;
235 // loop over all reconstructed tracks and add them to the store (skip ghosts)
236 Int_t nTracks = (Int_t) fESDEvent->GetNumberOfMuonTracks();
237 for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
238 AliESDMuonTrack* esdTrack = fESDEvent->GetMuonTrack(iTrack);
239 if (esdTrack->ContainTrackerData()) AliMUONESDInterface::Add(*esdTrack, *fRecoTrackStore);
244 //_____________________________________________________________________________
245 void AliMUONRecoCheck::MakeTrackRefs()
247 /// Make reconstructible tracks
248 AliMUONVTrackStore *tmpTrackRefStore = AliMUONESDInterface::NewTrackStore();
249 if (!tmpTrackRefStore) return;
251 Double_t x, y, z, pX, pY, pZ, bendingSlope, nonBendingSlope, inverseBendingMomentum;
253 TClonesArray* trackRefs;
254 Int_t nTrackRef = fMCEventHandler->MCEvent()->GetNumberOfTracks();
255 AliMUONVClusterStore* cStore = AliMUONESDInterface::NewClusterStore();
257 AliMUONVCluster* hit = cStore->CreateCluster(0,0,0);
259 // loop over simulated tracks
260 for (Int_t iTrackRef = 0; iTrackRef < nTrackRef; ++iTrackRef) {
261 Int_t nHits = fMCEventHandler->GetParticleAndTR(iTrackRef, particle, trackRefs);
263 // skip empty trackRefs
264 if (nHits < 1) continue;
266 // get the particle charge for further calculation
267 TParticlePDG* ppdg = particle->GetPDG();
268 Int_t charge = ppdg != NULL ? (Int_t)(ppdg->Charge()/3.0) : 0;
272 // loop over simulated track hits
273 for (Int_t iHit = 0; iHit < nHits; ++iHit) {
274 AliTrackReference* trackReference = static_cast<AliTrackReference*>(trackRefs->UncheckedAt(iHit));
276 // skip trackRefs not in MUON
277 if (trackReference->DetectorId() != AliTrackReference::kMUON) continue;
279 // Get track parameters of current hit
280 x = trackReference->X();
281 y = trackReference->Y();
282 z = trackReference->Z();
283 pX = trackReference->Px();
284 pY = trackReference->Py();
285 pZ = trackReference->Pz();
287 // check chamberId of current trackReference
288 Int_t detElemId = trackReference->UserId();
289 Int_t chamberId = detElemId / 100 - 1;
290 if (chamberId < 0 || chamberId >= AliMUONConstants::NTrackingCh()) continue;
292 // set hit parameters
293 hit->SetUniqueID(AliMUONVCluster::BuildUniqueID(chamberId, detElemId, iHit));
295 hit->SetErrXY(0.,0.);
297 // compute track parameters at hit
300 inverseBendingMomentum = 0;
301 if (TMath::Abs(pZ) > 0) {
302 bendingSlope = pY/pZ;
303 nonBendingSlope = pX/pZ;
305 Double_t pYZ = TMath::Sqrt(pY*pY+pZ*pZ);
306 if (pYZ >0) inverseBendingMomentum = 1/pYZ;
307 inverseBendingMomentum *= charge;
309 // set track parameters at hit
310 AliMUONTrackParam trackParam;
311 trackParam.SetNonBendingCoor(x);
312 trackParam.SetBendingCoor(y);
314 trackParam.SetBendingSlope(bendingSlope);
315 trackParam.SetNonBendingSlope(nonBendingSlope);
316 trackParam.SetInverseBendingMomentum(inverseBendingMomentum);
318 // add track parameters at current hit to the track
319 track.AddTrackParamAtCluster(trackParam, *hit, kTRUE);
322 // if none of the track hits was in MUON, goto the next track
323 if (track.GetNClusters() < 1) continue;
325 // get track parameters at particle's vertex
333 // compute rest of track parameters at particle's vertex
336 inverseBendingMomentum = 0;
337 if (TMath::Abs(pZ) > 0) {
338 bendingSlope = pY/pZ;
339 nonBendingSlope = pX/pZ;
341 Double_t pYZ = TMath::Sqrt(pY*pY+pZ*pZ);
342 if (pYZ >0) inverseBendingMomentum = 1/pYZ;
343 inverseBendingMomentum *= charge;
345 // set track parameters at particle's vertex
346 AliMUONTrackParam trackParamAtVertex;
347 trackParamAtVertex.SetNonBendingCoor(x);
348 trackParamAtVertex.SetBendingCoor(y);
349 trackParamAtVertex.SetZ(z);
350 trackParamAtVertex.SetBendingSlope(bendingSlope);
351 trackParamAtVertex.SetNonBendingSlope(nonBendingSlope);
352 trackParamAtVertex.SetInverseBendingMomentum(inverseBendingMomentum);
354 // add track parameters at vertex
355 track.SetTrackParamAtVertex(&trackParamAtVertex);
358 track.SetUniqueID(iTrackRef);
359 tmpTrackRefStore->Add(track);
362 CleanMuonTrackRef(tmpTrackRefStore);
366 delete tmpTrackRefStore;
369 //_____________________________________________________________________________
370 void AliMUONRecoCheck::CleanMuonTrackRef(const AliMUONVTrackStore *tmpTrackRefStore)
372 /// Re-calculate hits parameters because two AliTrackReferences are recorded for
373 /// each chamber (one when particle is entering + one when particle is leaving
374 /// the sensitive volume)
375 if (!(fTrackRefStore = AliMUONESDInterface::NewTrackStore())) return;
377 Double_t maxGasGap = 1.; // cm
378 Double_t x, y, z, pX, pY, pZ, x1, y1, z1, pX1, pY1, pZ1, z2;
379 Double_t bendingSlope,nonBendingSlope,inverseBendingMomentum;
380 AliMUONVClusterStore* cStore = AliMUONESDInterface::NewClusterStore();
382 AliMUONVCluster* hit = cStore->CreateCluster(0,0,0);
385 TIter next(tmpTrackRefStore->CreateIterator());
387 // loop over tmpTrackRef
389 while ( ( track = static_cast<AliMUONTrack*>(next()) ) ) {
391 AliMUONTrack newTrack;
393 // loop over tmpTrackRef's hits
395 Int_t nTrackHits = track->GetNClusters();
396 while (iHit1 < nTrackHits) {
397 AliMUONTrackParam *trackParam1 = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->UncheckedAt(iHit1);
399 // get track parameters at hit1
400 x1 = trackParam1->GetNonBendingCoor();
401 y1 = trackParam1->GetBendingCoor();
402 z1 = trackParam1->GetZ();
403 pX1 = trackParam1->Px();
404 pY1 = trackParam1->Py();
405 pZ1 = trackParam1->Pz();
407 // prepare new track parameters
415 // loop over next tmpTrackRef's hits
416 Int_t nCombinedHits = 1;
417 for (Int_t iHit2 = iHit1+1; iHit2 < nTrackHits; iHit2++) {
418 AliMUONTrackParam *trackParam2 = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->UncheckedAt(iHit2);
420 // get z position of hit2
421 z2 = trackParam2->GetZ();
423 // complete new track parameters if hit2 is on the same detection element
424 if ( TMath::Abs(z2-z1) < maxGasGap ) {
425 x += trackParam2->GetNonBendingCoor();
426 y += trackParam2->GetBendingCoor();
428 pX += trackParam2->Px();
429 pY += trackParam2->Py();
430 pZ += trackParam2->Pz();
437 // finalize new track parameters
438 x /= (Double_t)nCombinedHits;
439 y /= (Double_t)nCombinedHits;
440 z /= (Double_t)nCombinedHits;
441 pX /= (Double_t)nCombinedHits;
442 pY /= (Double_t)nCombinedHits;
443 pZ /= (Double_t)nCombinedHits;
446 inverseBendingMomentum = 0;
447 if (TMath::Abs(pZ) > 0) {
448 bendingSlope = pY/pZ;
449 nonBendingSlope = pX/pZ;
451 Double_t pYZ = TMath::Sqrt(pY*pY+pZ*pZ);
452 if (pYZ >0) inverseBendingMomentum = 1/pYZ;
453 inverseBendingMomentum *= trackParam1->GetCharge();
455 // set hit parameters
456 hit->SetUniqueID(trackParam1->GetClusterPtr()->GetUniqueID());
458 hit->SetErrXY(0.,0.);
460 // set new track parameters at new hit
461 AliMUONTrackParam trackParam;
462 trackParam.SetNonBendingCoor(x);
463 trackParam.SetBendingCoor(y);
465 trackParam.SetBendingSlope(bendingSlope);
466 trackParam.SetNonBendingSlope(nonBendingSlope);
467 trackParam.SetInverseBendingMomentum(inverseBendingMomentum);
469 // add track parameters at current hit to the track
470 newTrack.AddTrackParamAtCluster(trackParam, *hit, kTRUE);
475 newTrack.SetUniqueID(track->GetUniqueID());
476 newTrack.SetTrackParamAtVertex(track->GetTrackParamAtVertex());
477 fTrackRefStore->Add(newTrack);
485 //_____________________________________________________________________________
486 void AliMUONRecoCheck::MakeReconstructibleTracks()
488 /// Isolate the reconstructible tracks
489 if (!(fRecoTrackRefStore = AliMUONESDInterface::NewTrackStore())) return;
491 // create iterator on trackRef
492 TIter next(fTrackRefStore->CreateIterator());
494 // loop over trackRef
496 while ( ( track = static_cast<AliMUONTrack*>(next()) ) ) {
498 Bool_t* chamberInTrack = new Bool_t(AliMUONConstants::NTrackingCh());
499 for (Int_t iCh = 0; iCh < AliMUONConstants::NTrackingCh(); iCh++) chamberInTrack[iCh] = kFALSE;
501 // loop over trackRef's hits to get hit chambers
502 Int_t nTrackHits = track->GetNClusters();
503 for (Int_t iHit = 0; iHit < nTrackHits; iHit++) {
504 AliMUONVCluster* hit = ((AliMUONTrackParam*) track->GetTrackParamAtCluster()->UncheckedAt(iHit))->GetClusterPtr();
505 chamberInTrack[hit->GetChamberId()] = kTRUE;
508 // track is reconstructible if the particle is depositing a hit
509 // in the following chamber combinations:
510 Bool_t trackOK = kTRUE;
511 if (!chamberInTrack[0] && !chamberInTrack[1]) trackOK = kFALSE;
512 if (!chamberInTrack[2] && !chamberInTrack[3]) trackOK = kFALSE;
513 if (!chamberInTrack[4] && !chamberInTrack[5]) trackOK = kFALSE;
514 Int_t nHitsInLastStations = 0;
515 for (Int_t iCh = 6; iCh < AliMUONConstants::NTrackingCh(); iCh++)
516 if (chamberInTrack[iCh]) nHitsInLastStations++;
517 if(nHitsInLastStations < 3) trackOK = kFALSE;
519 // Add reconstructible tracks to fRecoTrackRefStore
520 if (trackOK) fRecoTrackRefStore->Add(*track);
522 delete [] chamberInTrack;