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