Fixing an error in the computation of the efficiency of a whole chamber (Matthieu)
[u/mrichter/AliRoot.git] / PWG3 / muondep / AliAnalysisTaskESDMCLabelAddition.cxx
CommitLineData
63c5d0a6 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
63c5d0a6 16#include <TChain.h>
17#include <TFile.h>
18#include <TParticle.h>
19
20#include "AliAnalysisTaskESDMCLabelAddition.h"
21#include "AliAnalysisManager.h"
22#include "AliESDEvent.h"
23#include "AliAODEvent.h"
24#include "AliESDInputHandler.h"
25#include "AliAODHandler.h"
26#include "AliAnalysisFilter.h"
27#include "AliESDtrack.h"
28#include "AliESDMuonTrack.h"
29#include "AliESDMuonCluster.h"
30#include "AliESDVertex.h"
31#include "AliMultiplicity.h"
32#include "AliLog.h"
33#include "AliStack.h"
34#include "AliMCEvent.h"
35#include "AliMCEventHandler.h"
36#include "AliAODMCParticle.h"
37
38#include "AliMUONRecoCheck.h"
39#include "AliMUONESDInterface.h"
40#include "AliMUONTrack.h"
41#include "AliMUONTrackParam.h"
42#include "AliMUONVTrackStore.h"
43#include "AliMUONVCluster.h"
44#include "AliMUONVClusterStore.h"
45
46ClassImp(AliAnalysisTaskESDMCLabelAddition)
47
48// sigma cut applied to match a reconstructed cluster with a trackref
49const Double_t AliAnalysisTaskESDMCLabelAddition::fgkSigmaCut = 10.;
50
51//----------------------------------------------------------------------
52AliAnalysisTaskESDMCLabelAddition::AliAnalysisTaskESDMCLabelAddition():
53 AliAnalysisTaskSE()
54{
55 // Default constructor
56}
57
58
59//----------------------------------------------------------------------
60AliAnalysisTaskESDMCLabelAddition::AliAnalysisTaskESDMCLabelAddition(const char* name):
61 AliAnalysisTaskSE(name)
62{
63 // Constructor
64}
65
66
67//----------------------------------------------------------------------
68void AliAnalysisTaskESDMCLabelAddition::UserCreateOutputObjects()
69{
70}
71
72
73//----------------------------------------------------------------------
74void AliAnalysisTaskESDMCLabelAddition::Init()
75{
d5e5d942 76 AliDebug(2, "Init()");
63c5d0a6 77}
78
79
80//----------------------------------------------------------------------
81void AliAnalysisTaskESDMCLabelAddition::UserExec(Option_t */*option*/)
82{
83 // Execute analysis for current event
84 Long64_t ientry = Entry();
d5e5d942 85 AliDebug(1, Form("MCLabel Addition: Analysing event # %5d\n",(Int_t) ientry));
63c5d0a6 86 AddMCLabel();
87}
88
89
90//----------------------------------------------------------------------
91void AliAnalysisTaskESDMCLabelAddition::AddMCLabel()
92{
93 // Load ESD event
94 AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());
95
96 // Load MC event
97 AliMCEventHandler *mcH = 0;
98 if(MCEvent()) mcH = (AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler());
99
100 // Get reference tracks
101 AliMUONRecoCheck rc(esd,mcH);
102 AliMUONVTrackStore* trackRefStore = rc.TrackRefs(-1);
103
104 // Loop over reconstructed tracks
105 AliESDMuonTrack *esdTrack = 0x0;
106 Int_t nMuTracks = esd->GetNumberOfMuonTracks();
107 for (Int_t nMuTrack = 0; nMuTrack < nMuTracks; ++nMuTrack) {
108
109 esdTrack = esd->GetMuonTrack(nMuTrack);
110
111 // skip ghosts
112 if (!esdTrack->ContainTrackerData()) continue;
113
f202486b 114 // convert ESD track to MUON track (without recomputing track parameters at each clusters)
115 AliMUONTrack muonTrack;
116 AliMUONESDInterface::ESDToMUON(*esdTrack, muonTrack, kFALSE);
117
63c5d0a6 118 // try to match the reconstructed track with a simulated one
f202486b 119 Int_t nMatchClusters = 0;
120 AliMUONTrack* matchedTrackRef = rc.FindCompatibleTrack(muonTrack, *trackRefStore, nMatchClusters, kFALSE, fgkSigmaCut);
63c5d0a6 121
f202486b 122 // set the MC label
123 if (matchedTrackRef) esdTrack->SetLabel(matchedTrackRef->GetUniqueID());
124 else esdTrack->SetLabel(-1);
63c5d0a6 125
126 }
127
128}
129
130
131//----------------------------------------------------------------------
132void AliAnalysisTaskESDMCLabelAddition::Terminate(Option_t */*option*/)
133{
134 // Terminate analysis
135 //
d5e5d942 136 AliDebug(2, "Terminate()");
63c5d0a6 137}
138