]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG4/AliAnaCaloTriggerMC.cxx
coding conventions, compilation warnings, code cleanup
[u/mrichter/AliRoot.git] / PWG4 / AliAnaCaloTriggerMC.cxx
CommitLineData
884e9012 1
2/**************************************************************************
3 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * *
5 * Author: The ALICE Off-line Project. *
6 * Contributors are mentioned in the code where appropriate. *
7 * *
8 * Permission to use, copy, modify and distribute this software and its *
9 * documentation strictly for non-commercial purposes is hereby granted *
10 * without fee, provided that the above copyright notice appears in all *
11 * copies and that both the copyright notice and this permission notice *
12 * appear in the supporting documentation. The authors make no claims *
13 * about the suitability of this software for any purpose. It is *
14 * provided "as is" without express or implied warranty. *
15 **************************************************************************/
16
17//_________________________________________________________________________
18// An analysis task to check the PHOS/EMCAL simulated trigger
19//
20//*-- Yves Schutz & Gustavo Conesa Balbastre
21//////////////////////////////////////////////////////////////////////////////
22
23#include <TChain.h>
24#include <TFile.h>
25#include <TNtuple.h>
26#include <TVector3.h>
27
28#include "AliAnalysisManager.h"
29#include "AliMCEventHandler.h"
30#include "AliAnaCaloTriggerMC.h"
31#include "AliESDEvent.h"
32#include "AliESDCaloCluster.h"
33#include "AliLog.h"
34#include "AliStack.h"
35#include "TParticle.h"
36
37//______________________________________________________________________________
38AliAnaCaloTriggerMC::AliAnaCaloTriggerMC() :
39 fChain(0),
40 fESD(0),
41 fOutputContainer(0),
42 fCalorimeter("PHOS"),
43 fNtTrigger22(0),
44 fNtTriggerNN(0)
45
46{
47 // Default constructor.
48
49}
50//______________________________________________________________________________
51AliAnaCaloTriggerMC::AliAnaCaloTriggerMC(const char *name) :
52 AliAnalysisTask(name, "AnaCaloTriggerMC"),
53 fChain(0),
54 fESD(0),
55 fOutputContainer(0),
56 fCalorimeter("PHOS"),
57 fNtTrigger22(0),
58 fNtTriggerNN(0)
59
60{
61 // Constructor.
62 // Input slot #0 works with an Ntuple
63 DefineInput(0, TChain::Class());
64 // Output slot #0 writes into a TH1 container
65 DefineOutput(0, TObjArray::Class()) ;
66}
67//____________________________________________________________________________
68AliAnaCaloTriggerMC::AliAnaCaloTriggerMC(const AliAnaCaloTriggerMC & ct) :
69 fChain(ct.fChain), fESD(ct.fESD),
70 fOutputContainer(ct.fOutputContainer), fCalorimeter(ct. fCalorimeter),
71 fNtTrigger22(ct.fNtTrigger22), fNtTriggerNN(ct.fNtTriggerNN)
72{
73
74 // cpy ctor
75 SetName (ct.GetName()) ;
76 SetTitle(ct.GetTitle()) ;
77
78}
79
80//_________________________________________________________________________
81AliAnaCaloTriggerMC & AliAnaCaloTriggerMC::operator = (const AliAnaCaloTriggerMC & source)
82{
83 // assignment operator
84
85 if(&source == this) return *this;
86
87 fChain = source.fChain ;
88 fESD = source.fESD ;
89 fOutputContainer = source.fOutputContainer ;
90 fCalorimeter = source. fCalorimeter ;
91 fNtTrigger22 = source.fNtTrigger22 ;
92 fNtTriggerNN = source.fNtTriggerNN ;
93
94 return *this;
95
96}
97
98//______________________________________________________________________________
99AliAnaCaloTriggerMC::~AliAnaCaloTriggerMC()
100{
101 // dtor
102 fOutputContainer->Clear() ;
103 delete fOutputContainer ;
104 delete fNtTrigger22 ;
105 delete fNtTriggerNN ;
106}
107
108
109//______________________________________________________________________________
110void AliAnaCaloTriggerMC::ConnectInputData(const Option_t*)
111{
112 // Initialisation of branch container and histograms
113
114 AliInfo(Form("*** Initialization of %s", GetName())) ;
115
116 // Get input data
117 fChain = dynamic_cast<TChain *>(GetInputData(0)) ;
118 if (!fChain) {
119 AliError(Form("Input 0 for %s not found\n", GetName()));
120 return ;
121 }
122
123 fESD = new AliESDEvent();
124 fESD->ReadFromTree(fChain);
125
126}
127
128//________________________________________________________________________
129
130void AliAnaCaloTriggerMC::CreateOutputObjects()
131{
132
133 // Create the output container
134 OpenFile(0);
135
136 // create histograms
137 fNtTrigger22 = new TNtuple(fCalorimeter+"trigger22", "Trigger data 2x2 patch", "a22:a220:enMax:phEnMax:eta22:phi22:etaMax:phiMax:phEtaMax:phPhiMax");
138 fNtTriggerNN = new TNtuple(fCalorimeter+"triggerNN", "Trigger data NxN patch", "aNN:aNN0:enMax:phEnMax:etaNN:phiNN:etaMax:phiMax:phEtaMax:phPhiMax");
139
140 // create output container
141
142 fOutputContainer = new TObjArray(2) ;
143 fOutputContainer->SetName(GetName()) ;
144
145 fOutputContainer->AddAt(fNtTrigger22, 0) ;
146 fOutputContainer->AddAt(fNtTriggerNN, 1) ;
147
148}
149
150//______________________________________________________________________________
151void AliAnaCaloTriggerMC::Exec(Option_t *)
152{
153
154 // Processing of one event
155
156 Long64_t entry = fChain->GetReadEntry() ;
157
158 if (!fESD) {
159 AliError("fESD is not connected to the input!") ;
160 return ;
161 }
162
163 if ( !((entry-1)%100) )
164 AliInfo(Form("%s ----> Processing event # %lld", (dynamic_cast<TChain *>(fChain))->GetFile()->GetName(), entry)) ;
165
166 //Get MC data
167 AliStack* stack = 0x0;
168 AliMCEventHandler* mctruth = (AliMCEventHandler*)
169 ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler());
170
171 if(mctruth)
172 stack = mctruth->Stack();
173
174 if (!stack) {
175 AliError("Stack not found") ;
176 return ;
177 }
178
179 // Get trigger information of fCalorimeter
180 TArrayF * triggerAmplitudes = 0x0 ;
181 TArrayF * triggerPosition = 0x0 ;
182 Int_t numberOfCaloClusters = 0 ;
183
184 if(fCalorimeter == "PHOS"){
185 triggerAmplitudes = fESD->GetPHOSTriggerAmplitudes();
186 triggerPosition = fESD->GetPHOSTriggerPosition();
187 }
188 else if(fCalorimeter == "EMCAL"){
189 triggerAmplitudes = fESD->GetEMCALTriggerAmplitudes();
190 triggerPosition = fESD->GetEMCALTriggerPosition();
191 }
192
193 if( triggerAmplitudes && triggerPosition ){
194 // trigger amplitudes
195 const Float_t a22 = static_cast<Float_t>(triggerAmplitudes->At(0)) ;
196 const Float_t a22O = static_cast<Float_t>(triggerAmplitudes->At(1)) ;
197 const Float_t aNN = static_cast<Float_t>(triggerAmplitudes->At(2)) ;
198 const Float_t aNNO = static_cast<Float_t>(triggerAmplitudes->At(3)) ;
199
200 // trigger position
201 const Float_t x22 = static_cast<Float_t>(triggerPosition->At(0)) ;
202 const Float_t y22 = static_cast<Float_t>(triggerPosition->At(1)) ;
203 const Float_t z22 = static_cast<Float_t>(triggerPosition->At(2)) ;
204 const Float_t xNN = static_cast<Float_t>(triggerPosition->At(3)) ;
205 const Float_t yNN = static_cast<Float_t>(triggerPosition->At(4)) ;
206 const Float_t zNN = static_cast<Float_t>(triggerPosition->At(5)) ;
207
208 Float_t enMax = 0. ;
209 Float_t phEnMax = 0. ;
210 Float_t etaMax = 0.5 ;
211 Float_t phiMax = 0. ;
212 Float_t phEtaMax = 0.5 ;
213 Float_t phPhiMax = 0. ;
214
215 TVector3 vpos22(x22, y22, z22) ;
216 TVector3 vposNN(xNN, yNN, zNN) ;
217 Float_t eta22 = vpos22.Eta() ;
218 Float_t phi22 = vpos22.Phi() * TMath::RadToDeg() + 360. ;
219 Float_t etaNN = vposNN.Eta() ;
220 Float_t phiNN = vposNN.Phi() * TMath::RadToDeg() + 360. ;
221
222 Int_t icaloCluster ;
223
224 // loop over the Calorimeters Clusters
225 Float_t cluEnergy = 0;
226 Int_t labelmax = -5;
227 for(icaloCluster = 0 ; icaloCluster < numberOfCaloClusters ; icaloCluster++) {
228
229 AliESDCaloCluster * cluster = fESD->GetCaloCluster(icaloCluster) ;
230
231 if (cluster && ( (fCalorimeter == "PHOS" && cluster->IsPHOS()) ||
232 (fCalorimeter == "EMCAL" && cluster->IsEMCAL()))) {
233
234 cluEnergy = cluster->E() ;
235 Float_t pos[3] ;
236 TVector3 vpos ;
237
238 cluster->GetPosition( pos ) ;
239
240 if ( cluEnergy > enMax) {
241 enMax = cluEnergy ;
242 vpos.SetXYZ(pos[0], pos[1], pos[2]) ;
243 etaMax = vpos.Eta() ;
244 phiMax = vpos.Phi() ;
245 labelmax = cluster->GetLabel();
246 }
247
248 Float_t * pid = cluster->GetPid() ;
249
250 if(pid[AliPID::kPhoton] > 0.9) {
251 if ( cluEnergy > phEnMax) {
252 phEnMax = cluEnergy ;
253 vpos.SetXYZ(pos[0], pos[1], pos[2]) ;
254 phEtaMax = vpos.Eta() ;
255 phPhiMax = vpos.Phi() ;
256 }
257 }
258 }//if cluster
259 }//CaloCluster loop
260
261 if(labelmax < stack->GetNtrack() && labelmax >= 0 ){
262 TParticle * particle = stack->Particle(labelmax);
263 Float_t ptgen = particle->Energy();
264 fNtTrigger22->Fill(a22, a22O, ptgen, enMax, phEnMax, eta22, phi22, etaMax, phiMax * TMath::RadToDeg() + 360., phEtaMax, phPhiMax * TMath::RadToDeg() + 360.);
265 fNtTriggerNN->Fill(aNN, aNNO, ptgen, enMax, phEnMax, etaNN, phiNN, etaMax, phiMax * TMath::RadToDeg() + 360., phEtaMax, phPhiMax * TMath::RadToDeg() + 360.);
266 }
267 else AliDebug(1, Form("Wrong label %d, ntrack %d, Emax %f ",labelmax, stack->GetNtrack(), phEnMax));
268 }//If trigger arrays filled
269
270 PostData(0, fOutputContainer);
271
272}
273
274
275//______________________________________________________________________________
276void AliAnaCaloTriggerMC::Terminate(Option_t *)
277{
278 // Processing when the event loop is ended
279
280}