]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONRecoCheck.cxx
fixing small memory leak
[u/mrichter/AliRoot.git] / MUON / AliMUONRecoCheck.cxx
CommitLineData
b8dc484b 1/**************************************************************************
48217459 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**************************************************************************/
b8dc484b 15
d19b6003 16/* $Id$ */
17
3d1463c8 18//-----------------------------------------------------------------------------
5398f946 19/// \class AliMUONRecoCheck
78649106 20/// Utility class to check reconstruction
5398f946 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.
3d1463c8 24//-----------------------------------------------------------------------------
b8dc484b 25
9bdda5f6 26// 13 Nov 2007:
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>
103e6575 31// 25 Jan 2008:
32// Use the new ESDInterface to create MUON objects from ESD data
33// - Philippe Pillot
7c29acf1 34//
9bdda5f6 35
cc056de1 36#include "AliMUONRecoCheck.h"
37#include "AliMUONTrack.h"
103e6575 38#include "AliMUONVTrackStore.h"
39#include "AliMUONVCluster.h"
40#include "AliMUONVClusterStore.h"
cc056de1 41#include "AliMUONConstants.h"
103e6575 42#include "AliMUONESDInterface.h"
933daf4c 43#include "AliMUONTrackParam.h"
9f164762 44#include "AliMUONTriggerTrack.h"
45#include "AliMUONVTriggerTrackStore.h"
b7474abb 46#include "AliMUONTriggerStoreV1.h"
47#include "AliMUONLocalTrigger.h"
96ebe67e 48#include "AliMCEventHandler.h"
49#include "AliMCEvent.h"
b8dc484b 50#include "AliStack.h"
cc056de1 51#include "AliTrackReference.h"
9bdda5f6 52#include "AliLog.h"
53#include "AliESDEvent.h"
54#include "AliESDMuonTrack.h"
b7474abb 55#include "AliMUONDigitStoreV2S.h"
56#include "AliMUONDigit.h"
57#include "AliMpVSegmentation.h"
58#include "AliMpSegmentation.h"
59#include "AliMpPad.h"
96ebe67e 60
9f164762 61#include "AliGeomManager.h"
b7474abb 62#include "AliCDBManager.h"
9f164762 63#include "AliMpCDB.h"
64#include "AliMpDDLStore.h"
65#include "AliMUONCDB.h"
66#include "AliMUONGeometryTransformer.h"
67#include "AliMUONTriggerCircuit.h"
68#include "AliMUONVTrackReconstructor.h"
69#include "AliMUONVTriggerStore.h"
b7474abb 70#include "AliMUONCalibrationData.h"
71#include "AliMUONTriggerElectronics.h"
72
9f164762 73
74#include "TGeoManager.h"
75
61fed964 76#include <TFile.h>
77#include <TTree.h>
cc056de1 78#include <TParticle.h>
5b1afea0 79#include <TParticlePDG.h>
96ebe67e 80#include <Riostream.h>
81
9f164762 82#include "AliMUONRecoCheck.h"
83
5398f946 84/// \cond CLASSIMP
b8dc484b 85ClassImp(AliMUONRecoCheck)
5398f946 86/// \endcond
b8dc484b 87
068e4c36 88//_____________________________________________________________________________
1f2d22de 89AliMUONRecoCheck::AliMUONRecoCheck(const Char_t *esdFileName, const Char_t *pathSim)
48217459 90: TObject(),
96ebe67e 91fMCEventHandler(new AliMCEventHandler()),
61fed964 92fESDEvent(new AliESDEvent()),
93fESDTree (0x0),
94fESDFile (0x0),
96ebe67e 95fCurrentEvent(0),
96fTrackRefStore(0x0),
97fRecoTrackRefStore(0x0),
9f164762 98fRecoTriggerRefStore(0x0),
7c29acf1 99fRecoTrackStore(0x0),
9f164762 100fRecoTriggerTrackStore(0x0),
101fGeometryTransformer(0x0),
102fTriggerCircuit(0x0),
b7474abb 103fCalibrationData(0x0),
104fTriggerElectronics(0x0),
7c29acf1 105fESDEventOwner(kTRUE)
068e4c36 106{
48217459 107 /// Normal ctor
61fed964 108
109 // TrackRefs and Particules
96ebe67e 110 fMCEventHandler->SetInputPath(pathSim);
111 fMCEventHandler->InitIO("");
61fed964 112
113 // ESD MUON Tracks
114 fESDFile = TFile::Open(esdFileName); // open the file
115 if (!fESDFile || !fESDFile->IsOpen()) {
116 AliError(Form("opening ESD file %s failed", esdFileName));
117 fESDFile = 0x0;
118 return;
119 }
120 fESDTree = (TTree*) fESDFile->Get("esdTree"); // get the tree
121 if (!fESDTree) {
122 AliError("no ESD tree found");
123 fESDFile->Close();
124 fESDFile = 0x0;
125 return;
126 }
127 fESDEvent->ReadFromTree(fESDTree); // link fESDEvent to the tree
068e4c36 128}
129
7c29acf1 130//_____________________________________________________________________________
131AliMUONRecoCheck::AliMUONRecoCheck(AliESDEvent *esdEvent, AliMCEventHandler *mcEventHandler)
132: TObject(),
133fMCEventHandler(0),
134fESDEvent(0),
135fESDTree (0x0),
136fESDFile (0x0),
137fCurrentEvent(0),
138fTrackRefStore(0x0),
139fRecoTrackRefStore(0x0),
9f164762 140fRecoTriggerRefStore(0x0),
7c29acf1 141fRecoTrackStore(0x0),
9f164762 142fRecoTriggerTrackStore(0x0),
143fGeometryTransformer(0x0),
144fTriggerCircuit(0x0),
b7474abb 145fCalibrationData(0x0),
146fTriggerElectronics(0x0),
7c29acf1 147fESDEventOwner(kFALSE)
148{
149 /// Normal ctor
150
151 // TrackRefs and Particules
152 fMCEventHandler = mcEventHandler;
153
154 // ESD MUON Tracks
155 fESDEvent = esdEvent;
7c29acf1 156}
157
b8dc484b 158//_____________________________________________________________________________
48217459 159AliMUONRecoCheck::~AliMUONRecoCheck()
b8dc484b 160{
48217459 161 /// Destructor
7c29acf1 162 if (fESDEventOwner) {
163 delete fMCEventHandler;
164 delete fESDEvent;
165 if (fESDFile) fESDFile->Close();
166 }
96ebe67e 167 ResetStores();
9f164762 168 delete fGeometryTransformer;
169 delete fTriggerCircuit;
b7474abb 170 delete fTriggerElectronics;
171 delete fCalibrationData;
96ebe67e 172}
173
174//_____________________________________________________________________________
175void AliMUONRecoCheck::ResetStores()
176{
177 /// Deletes all the store objects that have been created and resets the pointers to 0x0
178 delete fTrackRefStore; fTrackRefStore = 0x0;
179 delete fRecoTrackRefStore; fRecoTrackRefStore = 0x0;
9f164762 180 delete fRecoTriggerRefStore; fRecoTriggerRefStore = 0x0;
96ebe67e 181 delete fRecoTrackStore; fRecoTrackStore = 0x0;
9f164762 182 delete fRecoTriggerTrackStore; fRecoTriggerTrackStore = 0x0;
96ebe67e 183}
184
9f164762 185//_____________________________________________________________________________
186Bool_t AliMUONRecoCheck::InitCircuit()
187{
188
189 if ( fTriggerCircuit ) return kTRUE;
b7474abb 190
191 if ( ! InitGeometryTransformer() ) return kFALSE;
9f164762 192
193 fTriggerCircuit = new AliMUONTriggerCircuit(fGeometryTransformer);
194
195 // reset tracker for local trigger to trigger track conversion
196 if ( ! AliMUONESDInterface::GetTracker() )
197 AliMUONESDInterface::ResetTracker();
198
199 return kTRUE;
200}
201
202
a99c3449 203//_____________________________________________________________________________
204Int_t AliMUONRecoCheck::GetRunNumber()
205{
206 /// Return the run number of the current ESD event
207
9f164762 208 if (fESDEventOwner && fRecoTrackStore == 0x0 && fRecoTriggerTrackStore == 0x0) {
a99c3449 209 if (!fESDTree || fESDTree->GetEvent(fCurrentEvent) <= 0) {
210 AliError(Form("fails to read ESD object for event %d: cannot get the run number",fCurrentEvent));
211 return -1;
212 }
213 }
214
215 return fESDEvent->GetRunNumber();
216}
217
96ebe67e 218//_____________________________________________________________________________
219Int_t AliMUONRecoCheck::NumberOfEvents() const
220{
221 /// Return the number of events
7c29acf1 222 if (fESDEventOwner && fESDTree) return fESDTree->GetEntries();
96ebe67e 223 return 0;
b8dc484b 224}
225
48217459 226//_____________________________________________________________________________
a99c3449 227AliMUONVTrackStore* AliMUONRecoCheck::ReconstructedTracks(Int_t event, Bool_t refit)
48217459 228{
61fed964 229 /// Return a track store containing the reconstructed tracks (converted into
a99c3449 230 /// MUONTrack objects) for a given event.
231 /// Track parameters at each clusters are computed or not depending on the flag "refit".
232 /// If not, only the track parameters at first cluster are valid.
7c29acf1 233
234 if (!fESDEventOwner) {
a99c3449 235 if (fRecoTrackStore == 0x0) MakeReconstructedTracks(refit);
7c29acf1 236 return fRecoTrackStore;
237 }
238
96ebe67e 239 if (event != fCurrentEvent) {
240 ResetStores();
241 fCurrentEvent = event;
242 }
243
244 if (fRecoTrackStore != 0x0) return fRecoTrackStore;
61fed964 245 else {
246 if (!fESDTree) return 0x0;
247 if (fESDTree->GetEvent(event) <= 0) {
248 AliError(Form("fails to read ESD object for event %d", event));
249 return 0x0;
9bdda5f6 250 }
a99c3449 251 MakeReconstructedTracks(refit);
61fed964 252 return fRecoTrackStore;
9bdda5f6 253 }
9bdda5f6 254}
255
9f164762 256
257//_____________________________________________________________________________
258AliMUONVTriggerTrackStore* AliMUONRecoCheck::TriggeredTracks(Int_t event)
259{
260 /// Return a track store containing the reconstructed trigger tracks (converted into
261 /// MUONTriggerTrack objects) for a given event.
262
263 if (!fESDEventOwner) {
264 if (fRecoTriggerTrackStore == 0x0) MakeTriggeredTracks();
265 return fRecoTriggerTrackStore;
266 }
267
268 if (event != fCurrentEvent) {
269 ResetStores();
270 fCurrentEvent = event;
271 }
272
273 if (fRecoTriggerTrackStore != 0x0) return fRecoTriggerTrackStore;
274 else {
275 if (!fESDTree) return 0x0;
276 if (fESDTree->GetEvent(event) <= 0) {
277 AliError(Form("fails to read ESD object for event %d", event));
278 return 0x0;
279 }
280 MakeTriggeredTracks();
281 return fRecoTriggerTrackStore;
282 }
283}
284
285
9bdda5f6 286//_____________________________________________________________________________
96ebe67e 287AliMUONVTrackStore* AliMUONRecoCheck::TrackRefs(Int_t event)
b8dc484b 288{
48217459 289 /// Return a track store containing the track references (converted into
290 /// MUONTrack objects) for a given event
7c29acf1 291
292 if (!fESDEventOwner) {
a99c3449 293 if (fTrackRefStore == 0x0) MakeTrackRefs();
7c29acf1 294 return fTrackRefStore;
295 }
296
96ebe67e 297 if (event != fCurrentEvent) {
298 ResetStores();
299 fCurrentEvent = event;
300 }
301
302 if (fTrackRefStore != 0x0) return fTrackRefStore;
303 else {
e473e8b0 304 if (!fMCEventHandler->LoadEvent(event)) {
61fed964 305 AliError(Form("fails to read MC objects for event %d", event));
306 return 0x0;
307 }
96ebe67e 308 MakeTrackRefs();
309 return fTrackRefStore;
310 }
b8dc484b 311}
312
9f164762 313//_____________________________________________________________________________
314AliMUONVTriggerTrackStore* AliMUONRecoCheck::TriggerableTracks(Int_t event)
315{
316 /// Return a trigger track store containing the triggerable track references (converted into
317 /// AliMUONTriggerTrack objects) for a given event
318
319 if (!fESDEventOwner) {
320 if (fRecoTriggerRefStore == 0x0) MakeTriggerableTracks();
321 return fRecoTriggerRefStore;
322 }
323
324 if (event != fCurrentEvent) {
325 ResetStores();
326 fCurrentEvent = event;
327 }
328
329 if (fRecoTriggerRefStore != 0x0) return fRecoTriggerRefStore;
330 else {
e473e8b0 331 if (!fMCEventHandler->LoadEvent(event)) {
9f164762 332 AliError(Form("fails to read MC objects for event %d", event));
333 return 0x0;
334 }
335 MakeTriggerableTracks();
336 return fRecoTriggerRefStore;
337 }
338}
339
340
b8dc484b 341//_____________________________________________________________________________
e0146591 342AliMUONVTrackStore* AliMUONRecoCheck::ReconstructibleTracks(Int_t event, UInt_t requestedStationMask,
343 Bool_t request2ChInSameSt45, Bool_t hitInFrontOfPad)
b8dc484b 344{
f202486b 345 /// Return a track store containing the reconstructible tracks for a given event,
346 /// according to the mask of requested stations and the minimum number of chambers hit in stations 4 & 5.
7c29acf1 347
348 if (!fESDEventOwner) {
a99c3449 349 if (fRecoTrackRefStore == 0x0) {
350 if (TrackRefs(event) == 0x0) return 0x0;
e0146591 351 MakeReconstructibleTracks(requestedStationMask, request2ChInSameSt45, hitInFrontOfPad);
a99c3449 352 }
7c29acf1 353 return fRecoTrackRefStore;
354 }
355
96ebe67e 356 if (event != fCurrentEvent) {
357 ResetStores();
358 fCurrentEvent = event;
359 }
360
361 if (fRecoTrackRefStore != 0x0) return fRecoTrackRefStore;
362 else {
363 if (TrackRefs(event) == 0x0) return 0x0;
e0146591 364 MakeReconstructibleTracks(requestedStationMask, request2ChInSameSt45, hitInFrontOfPad);
96ebe67e 365 return fRecoTrackRefStore;
366 }
48217459 367}
b8dc484b 368
9f164762 369
61fed964 370//_____________________________________________________________________________
a99c3449 371void AliMUONRecoCheck::MakeReconstructedTracks(Bool_t refit)
61fed964 372{
373 /// Make reconstructed tracks
103e6575 374 if (!(fRecoTrackStore = AliMUONESDInterface::NewTrackStore())) return;
61fed964 375
b1fea02e 376 // loop over all reconstructed tracks and add them to the store (skip ghosts)
103e6575 377 Int_t nTracks = (Int_t) fESDEvent->GetNumberOfMuonTracks();
b1fea02e 378 for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
379 AliESDMuonTrack* esdTrack = fESDEvent->GetMuonTrack(iTrack);
a99c3449 380 if (esdTrack->ContainTrackerData()) AliMUONESDInterface::Add(*esdTrack, *fRecoTrackStore, refit);
b1fea02e 381 }
61fed964 382
383}
384
9f164762 385
386//_____________________________________________________________________________
387void AliMUONRecoCheck::MakeTriggeredTracks()
388{
389 /// Make reconstructed trigger tracks
390 if (!(fRecoTriggerTrackStore = AliMUONESDInterface::NewTriggerTrackStore())) return;
391
392 AliMUONVTriggerStore* tmpTriggerStore = AliMUONESDInterface::NewTriggerStore();
393 if ( ! tmpTriggerStore ) return;
394
395 // loop over all reconstructed tracks and add them to the store (include ghosts)
396 Int_t nTracks = (Int_t) fESDEvent->GetNumberOfMuonTracks();
397 for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
398 AliESDMuonTrack* esdTrack = fESDEvent->GetMuonTrack(iTrack);
399 if (esdTrack->ContainTriggerData()) AliMUONESDInterface::Add(*esdTrack, *tmpTriggerStore);
400 }
401
b7474abb 402 if ( InitCircuit() ) {
9f164762 403
b7474abb 404 AliMUONVTrackReconstructor* tracker = AliMUONESDInterface::GetTracker();
405 tracker->EventReconstructTrigger(*fTriggerCircuit, *tmpTriggerStore, *fRecoTriggerTrackStore);
406 }
9f164762 407
408 delete tmpTriggerStore;
409}
410
411//_____________________________________________________________________________
412void AliMUONRecoCheck::TriggerToTrack(const AliMUONLocalTrigger& locTrg, AliMUONTriggerTrack& triggerTrack)
413{
414 /// Make trigger track from local trigger info
415 if ( ! InitCircuit() ) return;
416 AliMUONVTrackReconstructor* tracker = AliMUONESDInterface::GetTracker();
417 tracker->TriggerToTrack(*fTriggerCircuit, locTrg, triggerTrack);
418}
419
420
48217459 421//_____________________________________________________________________________
96ebe67e 422void AliMUONRecoCheck::MakeTrackRefs()
48217459 423{
424 /// Make reconstructible tracks
103e6575 425 AliMUONVTrackStore *tmpTrackRefStore = AliMUONESDInterface::NewTrackStore();
426 if (!tmpTrackRefStore) return;
48217459 427
96ebe67e 428 Double_t x, y, z, pX, pY, pZ, bendingSlope, nonBendingSlope, inverseBendingMomentum;
429 TParticle* particle;
430 TClonesArray* trackRefs;
431 Int_t nTrackRef = fMCEventHandler->MCEvent()->GetNumberOfTracks();
103e6575 432 AliMUONVClusterStore* cStore = AliMUONESDInterface::NewClusterStore();
433 if (!cStore) return;
434 AliMUONVCluster* hit = cStore->CreateCluster(0,0,0);
b8dc484b 435
96ebe67e 436 // loop over simulated tracks
437 for (Int_t iTrackRef = 0; iTrackRef < nTrackRef; ++iTrackRef) {
438 Int_t nHits = fMCEventHandler->GetParticleAndTR(iTrackRef, particle, trackRefs);
48217459 439
96ebe67e 440 // skip empty trackRefs
441 if (nHits < 1) continue;
442
61fed964 443 // get the particle charge for further calculation
444 TParticlePDG* ppdg = particle->GetPDG();
46df197d 445 Int_t charge = ppdg != NULL ? (Int_t)(ppdg->Charge()/3.0) : 0;
96ebe67e 446
61fed964 447 AliMUONTrack track;
48217459 448
96ebe67e 449 // loop over simulated track hits
450 for (Int_t iHit = 0; iHit < nHits; ++iHit) {
451 AliTrackReference* trackReference = static_cast<AliTrackReference*>(trackRefs->UncheckedAt(iHit));
068e4c36 452
61fed964 453 // skip trackRefs not in MUON
454 if (trackReference->DetectorId() != AliTrackReference::kMUON) continue;
455
96ebe67e 456 // Get track parameters of current hit
457 x = trackReference->X();
458 y = trackReference->Y();
459 z = trackReference->Z();
460 pX = trackReference->Px();
461 pY = trackReference->Py();
462 pZ = trackReference->Pz();
b8dc484b 463
96ebe67e 464 // check chamberId of current trackReference
c59f70b9 465 Int_t detElemId = trackReference->UserId();
466 Int_t chamberId = detElemId / 100 - 1;
96ebe67e 467 if (chamberId < 0 || chamberId >= AliMUONConstants::NTrackingCh()) continue;
48217459 468
96ebe67e 469 // set hit parameters
c59f70b9 470 hit->SetUniqueID(AliMUONVCluster::BuildUniqueID(chamberId, detElemId, iHit));
103e6575 471 hit->SetXYZ(x,y,z);
472 hit->SetErrXY(0.,0.);
b8dc484b 473
96ebe67e 474 // compute track parameters at hit
7cdc832b 475 bendingSlope = 0;
476 nonBendingSlope = 0;
477 inverseBendingMomentum = 0;
96ebe67e 478 if (TMath::Abs(pZ) > 0) {
479 bendingSlope = pY/pZ;
480 nonBendingSlope = pX/pZ;
b8dc484b 481 }
96ebe67e 482 Double_t pYZ = TMath::Sqrt(pY*pY+pZ*pZ);
483 if (pYZ >0) inverseBendingMomentum = 1/pYZ;
484 inverseBendingMomentum *= charge;
485
486 // set track parameters at hit
487 AliMUONTrackParam trackParam;
488 trackParam.SetNonBendingCoor(x);
489 trackParam.SetBendingCoor(y);
490 trackParam.SetZ(z);
491 trackParam.SetBendingSlope(bendingSlope);
492 trackParam.SetNonBendingSlope(nonBendingSlope);
493 trackParam.SetInverseBendingMomentum(inverseBendingMomentum);
494
495 // add track parameters at current hit to the track
103e6575 496 track.AddTrackParamAtCluster(trackParam, *hit, kTRUE);
96ebe67e 497 }
498
61fed964 499 // if none of the track hits was in MUON, goto the next track
500 if (track.GetNClusters() < 1) continue;
501
502 // get track parameters at particle's vertex
503 x = particle->Vx();
504 y = particle->Vy();
505 z = particle->Vz();
506 pX = particle->Px();
507 pY = particle->Py();
508 pZ = particle->Pz();
509
510 // compute rest of track parameters at particle's vertex
511 bendingSlope = 0;
512 nonBendingSlope = 0;
513 inverseBendingMomentum = 0;
514 if (TMath::Abs(pZ) > 0) {
515 bendingSlope = pY/pZ;
516 nonBendingSlope = pX/pZ;
517 }
518 Double_t pYZ = TMath::Sqrt(pY*pY+pZ*pZ);
519 if (pYZ >0) inverseBendingMomentum = 1/pYZ;
520 inverseBendingMomentum *= charge;
521
522 // set track parameters at particle's vertex
523 AliMUONTrackParam trackParamAtVertex;
524 trackParamAtVertex.SetNonBendingCoor(x);
525 trackParamAtVertex.SetBendingCoor(y);
526 trackParamAtVertex.SetZ(z);
527 trackParamAtVertex.SetBendingSlope(bendingSlope);
528 trackParamAtVertex.SetNonBendingSlope(nonBendingSlope);
529 trackParamAtVertex.SetInverseBendingMomentum(inverseBendingMomentum);
530
531 // add track parameters at vertex
532 track.SetTrackParamAtVertex(&trackParamAtVertex);
533
103e6575 534 // store the track
2e2d0c44 535 track.SetUniqueID(iTrackRef);
96ebe67e 536 tmpTrackRefStore->Add(track);
b8dc484b 537 }
b8dc484b 538
96ebe67e 539 CleanMuonTrackRef(tmpTrackRefStore);
48217459 540
103e6575 541 delete hit;
542 delete cStore;
96ebe67e 543 delete tmpTrackRefStore;
b8dc484b 544}
545
9f164762 546//_____________________________________________________________________________
547void AliMUONRecoCheck::MakeTriggerableTracks()
548{
549 /// Make triggerable tracks
550 if (!(fRecoTriggerRefStore = AliMUONESDInterface::NewTriggerTrackStore()))
551 return;
552
b7474abb 553 Double_t x, y, z, slopeX, slopeY, pZ, xLoc, yLoc, zLoc;
9f164762 554 TParticle* particle;
555 TClonesArray* trackRefs;
556 Int_t nTrackRef = fMCEventHandler->MCEvent()->GetNumberOfTracks();
557
558 // loop over simulated tracks
559 for (Int_t iTrackRef = 0; iTrackRef < nTrackRef; ++iTrackRef) {
560 Int_t nHits = fMCEventHandler->GetParticleAndTR(iTrackRef, particle, trackRefs);
561
562 // skip empty trackRefs
563 if (nHits < 1) continue;
564
565 AliMUONTriggerTrack track;
b7474abb 566 AliMUONDigitStoreV2S digitStore;
9f164762 567 Int_t hitsOnTrigger = 0;
568 Int_t currCh = -1;
569
570 // loop over simulated track hits
571 for (Int_t iHit = 0; iHit < nHits; ++iHit) {
572 AliTrackReference* trackReference = static_cast<AliTrackReference*>(trackRefs->UncheckedAt(iHit));
573
574 // skip trackRefs not in MUON
575 if (trackReference->DetectorId() != AliTrackReference::kMUON) continue;
576
577 // check chamberId of current trackReference
578 Int_t detElemId = trackReference->UserId();
579 Int_t chamberId = detElemId / 100 - 1;
580 if (chamberId < AliMUONConstants::NTrackingCh() || chamberId >= AliMUONConstants::NCh() ) continue;
b7474abb 581
582 // Get track parameters of current hit
583 x = trackReference->X();
584 y = trackReference->Y();
585 z = trackReference->Z();
586
587 if ( InitTriggerResponse() ) {
588 fGeometryTransformer->Global2Local(detElemId, x, y, z, xLoc, yLoc, zLoc);
589
590 Int_t nboard = 0;
591 for ( Int_t cath = AliMp::kCath0; cath <= AliMp::kCath1; ++cath )
592 {
593 const AliMpVSegmentation* seg
594 = AliMpSegmentation::Instance()
595 ->GetMpSegmentation(detElemId,AliMp::GetCathodType(cath));
596
597 AliMpPad pad = seg->PadByPosition(xLoc,yLoc,kFALSE);
598 Int_t ix = pad.GetIx();
599 Int_t iy = pad.GetIy();
600
601 if ( !pad.IsValid() ) continue;
602
603 if ( cath == AliMp::kCath0 ) nboard = pad.GetLocalBoardId(0);
604
605 AliMUONDigit* digit = new AliMUONDigit(detElemId,nboard,
606 pad.GetLocalBoardChannel(0),cath);
607 digit->SetPadXY(ix,iy);
608 digit->SetCharge(1.);
609 digitStore.Add(*digit,AliMUONVDigitStore::kDeny);
610 }
611 }
612
9f164762 613 if ( hitsOnTrigger == 0 ) {
9f164762 614 pZ = trackReference->Pz();
615 slopeX = ( pZ == 0. ) ? 99999. : trackReference->Px() / pZ;
616 slopeY = ( pZ == 0. ) ? 99999. : trackReference->Py() / pZ;
617
618 track.SetX11(x);
619 track.SetY11(y);
620 track.SetZ11(z);
621 track.SetSlopeX(slopeX);
622 track.SetSlopeY(slopeY);
623 }
624
625 if ( currCh != chamberId ) {
626 hitsOnTrigger++;
627 currCh = chamberId;
628 }
629
630 } // loop on hits
b7474abb 631
632 if ( hitsOnTrigger < 3 ) continue;
633
634 // Check if the track passes the trigger algorithm
635 if ( InitTriggerResponse() ) {
636 AliMUONTriggerStoreV1 triggerStore;
637 fTriggerElectronics->Digits2Trigger(digitStore,triggerStore);
638
639 TIter next(triggerStore.CreateIterator());
640 AliMUONLocalTrigger* locTrg(0x0);
641
642 Int_t ptCutLevel = 0;
643
644 while ( ( locTrg = static_cast<AliMUONLocalTrigger*>(next()) ) )
645 {
646 if ( locTrg->IsTrigX() && locTrg->IsTrigY() )
647 {
648 ptCutLevel = TMath::Max(ptCutLevel, 1);
649 if ( locTrg->LoHpt() ) ptCutLevel = TMath::Max(ptCutLevel, 3);
650 else if ( locTrg->LoLpt() ) ptCutLevel = TMath::Max(ptCutLevel, 2);
651 } // board is fired
652 } // end of loop on Local Trigger
653 track.SetPtCutLevel(ptCutLevel);
9f164762 654 }
b7474abb 655 track.SetUniqueID(iTrackRef);
656 fRecoTriggerRefStore->Add(track);
9f164762 657 }
658}
659
660
b8dc484b 661//_____________________________________________________________________________
96ebe67e 662void AliMUONRecoCheck::CleanMuonTrackRef(const AliMUONVTrackStore *tmpTrackRefStore)
b8dc484b 663{
48217459 664 /// Re-calculate hits parameters because two AliTrackReferences are recorded for
665 /// each chamber (one when particle is entering + one when particle is leaving
666 /// the sensitive volume)
103e6575 667 if (!(fTrackRefStore = AliMUONESDInterface::NewTrackStore())) return;
48217459 668
96ebe67e 669 Double_t maxGasGap = 1.; // cm
670 Double_t x, y, z, pX, pY, pZ, x1, y1, z1, pX1, pY1, pZ1, z2;
671 Double_t bendingSlope,nonBendingSlope,inverseBendingMomentum;
103e6575 672 AliMUONVClusterStore* cStore = AliMUONESDInterface::NewClusterStore();
673 if (!cStore) return;
674 AliMUONVCluster* hit = cStore->CreateCluster(0,0,0);
48217459 675
96ebe67e 676 // create iterator
677 TIter next(tmpTrackRefStore->CreateIterator());
48217459 678
96ebe67e 679 // loop over tmpTrackRef
48217459 680 AliMUONTrack* track;
96ebe67e 681 while ( ( track = static_cast<AliMUONTrack*>(next()) ) ) {
682
683 AliMUONTrack newTrack;
684
685 // loop over tmpTrackRef's hits
686 Int_t iHit1 = 0;
687 Int_t nTrackHits = track->GetNClusters();
688 while (iHit1 < nTrackHits) {
689 AliMUONTrackParam *trackParam1 = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->UncheckedAt(iHit1);
690
691 // get track parameters at hit1
692 x1 = trackParam1->GetNonBendingCoor();
693 y1 = trackParam1->GetBendingCoor();
694 z1 = trackParam1->GetZ();
695 pX1 = trackParam1->Px();
696 pY1 = trackParam1->Py();
697 pZ1 = trackParam1->Pz();
698
699 // prepare new track parameters
700 x = x1;
701 y = y1;
702 z = z1;
703 pX = pX1;
704 pY = pY1;
705 pZ = pZ1;
706
707 // loop over next tmpTrackRef's hits
708 Int_t nCombinedHits = 1;
709 for (Int_t iHit2 = iHit1+1; iHit2 < nTrackHits; iHit2++) {
710 AliMUONTrackParam *trackParam2 = (AliMUONTrackParam*) track->GetTrackParamAtCluster()->UncheckedAt(iHit2);
48217459 711
96ebe67e 712 // get z position of hit2
713 z2 = trackParam2->GetZ();
714
715 // complete new track parameters if hit2 is on the same detection element
716 if ( TMath::Abs(z2-z1) < maxGasGap ) {
717 x += trackParam2->GetNonBendingCoor();
718 y += trackParam2->GetBendingCoor();
719 z += z2;
720 pX += trackParam2->Px();
721 pY += trackParam2->Py();
722 pZ += trackParam2->Pz();
723 nCombinedHits++;
48217459 724 iHit1 = iHit2;
725 }
726
96ebe67e 727 }
728
729 // finalize new track parameters
730 x /= (Double_t)nCombinedHits;
731 y /= (Double_t)nCombinedHits;
732 z /= (Double_t)nCombinedHits;
733 pX /= (Double_t)nCombinedHits;
734 pY /= (Double_t)nCombinedHits;
735 pZ /= (Double_t)nCombinedHits;
736 bendingSlope = 0;
737 nonBendingSlope = 0;
738 inverseBendingMomentum = 0;
739 if (TMath::Abs(pZ) > 0) {
740 bendingSlope = pY/pZ;
741 nonBendingSlope = pX/pZ;
742 }
743 Double_t pYZ = TMath::Sqrt(pY*pY+pZ*pZ);
744 if (pYZ >0) inverseBendingMomentum = 1/pYZ;
745 inverseBendingMomentum *= trackParam1->GetCharge();
b8dc484b 746
96ebe67e 747 // set hit parameters
c59f70b9 748 hit->SetUniqueID(trackParam1->GetClusterPtr()->GetUniqueID());
103e6575 749 hit->SetXYZ(x,y,z);
750 hit->SetErrXY(0.,0.);
48217459 751
96ebe67e 752 // set new track parameters at new hit
753 AliMUONTrackParam trackParam;
754 trackParam.SetNonBendingCoor(x);
755 trackParam.SetBendingCoor(y);
756 trackParam.SetZ(z);
757 trackParam.SetBendingSlope(bendingSlope);
758 trackParam.SetNonBendingSlope(nonBendingSlope);
759 trackParam.SetInverseBendingMomentum(inverseBendingMomentum);
760
761 // add track parameters at current hit to the track
103e6575 762 newTrack.AddTrackParamAtCluster(trackParam, *hit, kTRUE);
b8dc484b 763
764 iHit1++;
96ebe67e 765 }
48217459 766
2e2d0c44 767 newTrack.SetUniqueID(track->GetUniqueID());
96ebe67e 768 newTrack.SetTrackParamAtVertex(track->GetTrackParamAtVertex());
769 fTrackRefStore->Add(newTrack);
b8dc484b 770
96ebe67e 771 }
b8dc484b 772
103e6575 773 delete hit;
774 delete cStore;
b8dc484b 775}
776
777//_____________________________________________________________________________
e0146591 778void AliMUONRecoCheck::MakeReconstructibleTracks(UInt_t requestedStationMask, Bool_t request2ChInSameSt45,
779 Bool_t hitInFrontOfPad)
b8dc484b 780{
61fed964 781 /// Isolate the reconstructible tracks
103e6575 782 if (!(fRecoTrackRefStore = AliMUONESDInterface::NewTrackStore())) return;
48217459 783
e0146591 784 // need geometry transformer and segmentation to check if trackrefs are located in front of pad(s)
785 if (hitInFrontOfPad) {
786 if (!InitGeometryTransformer()) return;
787 if (!AliMpSegmentation::Instance(kFALSE) && !AliMUONCDB::LoadMapping(kTRUE)) return;
788 }
789
96ebe67e 790 // create iterator on trackRef
791 TIter next(fTrackRefStore->CreateIterator());
b8dc484b 792
f202486b 793 // loop over trackRef and add reconstructible tracks to fRecoTrackRefStore
48217459 794 AliMUONTrack* track;
96ebe67e 795 while ( ( track = static_cast<AliMUONTrack*>(next()) ) ) {
e0146591 796
797 // check if the track is valid as it is
798 if (track->IsValid(requestedStationMask, request2ChInSameSt45)) {
799
800 if (hitInFrontOfPad) {
801
802 AliMUONTrack trackTmp(*track);
803
804 // loop over clusters and remove those which are not in front of pad(s)
805 AliMUONTrackParam *param = static_cast<AliMUONTrackParam*>(trackTmp.GetTrackParamAtCluster()->First());
806 while (param) {
807 AliMUONTrackParam *nextParam = static_cast<AliMUONTrackParam*>(trackTmp.GetTrackParamAtCluster()->After(param));
808 if (!IsHitInFrontOfPad(param)) trackTmp.RemoveTrackParamAtCluster(param);
809 param = nextParam;
810 }
811
812 // add the track if it is still valid
813 if (trackTmp.IsValid(requestedStationMask, request2ChInSameSt45)) fRecoTrackRefStore->Add(trackTmp);
814
815 } else {
816
817 // add the track
818 fRecoTrackRefStore->Add(*track);
819
820 }
821
822 }
823
f202486b 824 }
825
826}
827
828//_____________________________________________________________________________
829AliMUONTrack* AliMUONRecoCheck::FindCompatibleTrack(AliMUONTrack &track, AliMUONVTrackStore &trackStore,
830 Int_t &nMatchClusters, Bool_t useLabel, Double_t sigmaCut)
831{
832 /// Return the track from the store matched with the given track (or 0x0) and the number of matched clusters.
833 /// Matching is done by using the MC label of by comparing cluster/TrackRef positions according to the flag "useLabel".
834 /// WARNING: Who match who matters since the matching algorithm uses the *fraction* of matched clusters of the given track
835
836 AliMUONTrack *matchedTrack = 0x0;
837 nMatchClusters = 0;
838
839 if (useLabel) { // by using the MC label
96ebe67e 840
f202486b 841 // get the corresponding simulated track if any
842 Int_t label = track.GetMCLabel();
843 matchedTrack = (AliMUONTrack*) trackStore.FindObject(label);
48217459 844
f202486b 845 // get the fraction of matched clusters
846 if (matchedTrack) {
847 Int_t nClusters = track.GetNClusters();
848 for (Int_t iCl = 0; iCl < nClusters; iCl++)
849 if (((AliMUONTrackParam*) track.GetTrackParamAtCluster()->UncheckedAt(iCl))->GetClusterPtr()->GetMCLabel() == label)
850 nMatchClusters++;
851 }
96ebe67e 852
f202486b 853 } else { // by comparing cluster/TrackRef positions
48217459 854
f202486b 855 // look for the corresponding simulated track if any
856 TIter next(trackStore.CreateIterator());
857 AliMUONTrack* track2;
858 while ( ( track2 = static_cast<AliMUONTrack*>(next()) ) ) {
859
860 // check compatibility
861 Int_t n = 0;
862 if (track.Match(*track2, sigmaCut, n)) {
863 matchedTrack = track2;
864 nMatchClusters = n;
865 break;
866 }
867
868 }
48217459 869
b8dc484b 870 }
f202486b 871
872 return matchedTrack;
873
b8dc484b 874}
875
9f164762 876
877//_____________________________________________________________________________
57e2ad1a 878AliMUONTriggerTrack* AliMUONRecoCheck::FindCompatibleTrack(AliMUONTriggerTrack &track, const AliMUONVTriggerTrackStore &triggerTrackStore,
9f164762 879 Double_t sigmaCut)
880{
881 /// Return the trigger track from the store matched with the given track (or 0x0).
882 /// Matching is done by comparing cluster/TrackRef positions.
883
884 AliMUONTriggerTrack *matchedTrack = 0x0;
885
886 // look for the corresponding simulated track if any
887 TIter next(triggerTrackStore.CreateIterator());
888 AliMUONTriggerTrack* track2;
889 while ( ( track2 = static_cast<AliMUONTriggerTrack*>(next()) ) ) {
9f164762 890 // check compatibility
891 if (track.Match(*track2, sigmaCut)) {
892 matchedTrack = track2;
893 break;
894 }
895 }
896
897 return matchedTrack;
898
899}
900
b7474abb 901
902//____________________________________________________________________________
903Bool_t AliMUONRecoCheck::InitTriggerResponse()
904{
905 /// Initialize trigger electronics
906 /// for building of triggerable tracks from MC
907
908 if ( fTriggerElectronics ) return kTRUE;
909
910 if ( ! InitGeometryTransformer() ) return kFALSE;
911
e0146591 912 if ( ! AliMpDDLStore::Instance(false) ) AliMpCDB::LoadDDLStore();
913
b7474abb 914 if ( ! InitCalibrationData() ) return kFALSE;
915
916 fTriggerElectronics = new AliMUONTriggerElectronics(fCalibrationData);
917
918 return kTRUE;
919}
920
921
922//____________________________________________________________________________
923Bool_t AliMUONRecoCheck::InitCalibrationData()
924{
925 /// Initialize calibration data
926 if ( ! fCalibrationData ) {
927 if ( !AliMUONCDB::CheckOCDB() ) return kFALSE;
928 fCalibrationData = new AliMUONCalibrationData(AliCDBManager::Instance()->GetRun());
929 }
930 return kTRUE;
931}
932
933
934//____________________________________________________________________________
935Bool_t AliMUONRecoCheck::InitGeometryTransformer()
936{
e0146591 937 /// Return geometry transformer
b7474abb 938 /// (create it if necessary)
939 if ( ! fGeometryTransformer ) {
940
941 if ( !AliMUONCDB::CheckOCDB() ) return kFALSE;
942
e0146591 943 if (!AliGeomManager::GetGeometry()) {
b7474abb 944 AliGeomManager::LoadGeometry();
e0146591 945 if (!AliGeomManager::GetGeometry()) return kFALSE;
946 if (!AliGeomManager::ApplyAlignObjsFromCDB("MUON")) return kFALSE;
947 }
b7474abb 948
949 fGeometryTransformer = new AliMUONGeometryTransformer();
950 fGeometryTransformer->LoadGeometryData();
951 }
952
953 return kTRUE;
954}
955
e0146591 956//________________________________________________________________________
957Bool_t AliMUONRecoCheck::IsHitInFrontOfPad(AliMUONTrackParam *param) const
958{
959 /// Return kTRUE if the hit is located in front of at least 1 pad
960
961 Int_t deId = param->GetClusterPtr()->GetDetElemId();
962
963 Double_t xL, yL, zL;
964 fGeometryTransformer->Global2Local(deId, param->GetNonBendingCoor(), param->GetBendingCoor(), param->GetZ(), xL, yL, zL);
965
966 const AliMpVSegmentation* seg1 = AliMpSegmentation::Instance()->GetMpSegmentation(deId, AliMp::kCath0);
967 const AliMpVSegmentation* seg2 = AliMpSegmentation::Instance()->GetMpSegmentation(deId, AliMp::kCath1);
968 if (!seg1 || !seg2) return kFALSE;
969
970 AliMpPad pad1 = seg1->PadByPosition(xL, yL, kFALSE);
971 AliMpPad pad2 = seg2->PadByPosition(xL, yL, kFALSE);
972
973 return (pad1.IsValid() || pad2.IsValid());
974}
975