]>
Commit | Line | Data |
---|---|---|
b16d48a7 | 1 | //-*- Mode: C++ -*- |
2 | // $Id: AliHLTMCEvent.cxx $ | |
3 | /************************************************************************** | |
4 | * This file is property of and copyright by the ALICE HLT Project * | |
5 | * ALICE Experiment at CERN, All rights reserved. * | |
6 | * * | |
7 | * Primary Authors: Jochen Thaeder <thaeder@kip.uni-heidelberg.de> * | |
8 | * for The ALICE HLT Project. * | |
9 | * * | |
10 | * Permission to use, copy, modify and distribute this software and its * | |
11 | * documentation strictly for non-commercial purposes is hereby granted * | |
12 | * without fee, provided that the above copyright notice appears in all * | |
13 | * copies and that both the copyright notice and this permission notice * | |
14 | * appear in the supporting documentation. The authors make no claims * | |
15 | * about the suitability of this software for any purpose. It is * | |
16 | * provided "as is" without express or implied warranty. * | |
17 | **************************************************************************/ | |
18 | ||
805aa9da | 19 | /** @file AliHLTMCEvent.cxx |
b16d48a7 | 20 | @author Jochen Thaeder |
21 | @date | |
22 | @brief Container class for an AliMCEvent | |
23 | */ | |
24 | ||
25 | // see header file for class documentation | |
26 | // or | |
27 | // refer to README to build package | |
28 | // or | |
29 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
30 | ||
31 | #if __GNUC__ >= 3 | |
32 | using namespace std; | |
33 | #endif | |
34 | ||
7aac8168 | 35 | #include "TList.h" |
36 | #include "TParticlePDG.h" | |
37 | #include "TDatabasePDG.h" | |
805aa9da | 38 | |
7aac8168 | 39 | #include "AliGenCocktailEventHeader.h" |
805aa9da | 40 | |
b16d48a7 | 41 | #include "AliHLTMCEvent.h" |
b16d48a7 | 42 | |
43 | /** ROOT macro for the implementation of ROOT specific class methods */ | |
44 | ClassImp(AliHLTMCEvent) | |
45 | ||
46 | /* | |
47 | * --------------------------------------------------------------------------------- | |
48 | * Constructor / Destructor | |
49 | * --------------------------------------------------------------------------------- | |
50 | */ | |
51 | ||
52 | // ################################################################################# | |
7aac8168 | 53 | AliHLTMCEvent::AliHLTMCEvent() : |
b16d48a7 | 54 | fCurrentParticleIndex(-1), |
7aac8168 | 55 | fNParticles(0), |
56 | fStack( NULL ), | |
57 | fCurrentGenJetIndex(-1), | |
58 | fNGenJets(0), | |
396e75ed | 59 | fGenJets(NULL), |
60 | fHasParticleCuts(kFALSE) { | |
b16d48a7 | 61 | // see header file for class documentation |
62 | // or | |
63 | // refer to README to build package | |
64 | // or | |
65 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
b16d48a7 | 66 | } |
67 | ||
396e75ed | 68 | // ################################################################################# |
69 | AliHLTMCEvent::AliHLTMCEvent( Bool_t applyParticleCuts ) : | |
70 | fCurrentParticleIndex(-1), | |
71 | fNParticles(0), | |
72 | fStack( NULL ), | |
73 | fCurrentGenJetIndex(-1), | |
74 | fNGenJets(0), | |
75 | fGenJets(NULL), | |
76 | fHasParticleCuts(applyParticleCuts) { | |
77 | // see header file for class documentation | |
78 | } | |
79 | ||
b16d48a7 | 80 | // ################################################################################# |
7aac8168 | 81 | AliHLTMCEvent::~AliHLTMCEvent() { |
b16d48a7 | 82 | // see header file for class documentation |
83 | ||
7aac8168 | 84 | if ( fStack ) { |
85 | fStack->Delete(); | |
86 | delete fStack; | |
87 | } | |
88 | fStack = NULL; | |
89 | ||
90 | if ( fGenJets ) { | |
91 | fGenJets->Delete(); | |
92 | delete fGenJets; | |
93 | } | |
94 | fGenJets = NULL; | |
b16d48a7 | 95 | } |
805aa9da | 96 | |
7aac8168 | 97 | /* |
98 | * --------------------------------------------------------------------------------- | |
99 | * Setter - public | |
100 | * --------------------------------------------------------------------------------- | |
101 | */ | |
102 | ||
b16d48a7 | 103 | // ################################################################################# |
7aac8168 | 104 | Int_t AliHLTMCEvent::FillMCEvent( AliStack *stack, AliHeader *header ) { |
b16d48a7 | 105 | // see header file for class documentation |
106 | ||
7aac8168 | 107 | Int_t iResult = 0; |
108 | ||
109 | if ( stack ) { | |
110 | if ( (iResult = FillMCTracks(stack)) ) | |
111 | HLTError("Error filling particles" ); | |
112 | } | |
113 | else { | |
114 | HLTError("Error reading stack" ); | |
115 | iResult = -2; | |
116 | } | |
117 | ||
118 | if ( header ) { | |
119 | AliGenPythiaEventHeader* pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*> (header->GenEventHeader()); | |
120 | if ( pythiaGenHeader ) { | |
121 | if ( (iResult = FillMCJets(pythiaGenHeader)) ) | |
122 | HLTError("Error filling jets" ); | |
123 | } | |
124 | else { | |
d5b05c26 | 125 | HLTError("Error reading PythiaHeader" ); |
7aac8168 | 126 | iResult = -2; |
127 | } | |
128 | } | |
129 | else { | |
130 | HLTError("Error reading header" ); | |
131 | iResult = -2; | |
132 | } | |
133 | ||
134 | Compress(); | |
135 | ||
136 | return iResult;; | |
b16d48a7 | 137 | } |
138 | ||
139 | // ################################################################################# | |
7aac8168 | 140 | Int_t AliHLTMCEvent::FillMCEvent( AliMCEvent *pMCEvent ) { |
b16d48a7 | 141 | // see header file for class documentation |
7aac8168 | 142 | |
143 | Int_t iResult = 0; | |
144 | ||
145 | if ( (iResult = FillMCTracks(pMCEvent->Stack())) ) | |
146 | HLTError("Error filling particles" ); | |
b16d48a7 | 147 | |
7aac8168 | 148 | if ( (iResult = FillMCJets(GetPythiaEventHeader(pMCEvent))) ) |
149 | HLTError("Error filling jets" ); | |
150 | ||
151 | Compress(); | |
152 | ||
153 | return iResult; | |
b16d48a7 | 154 | } |
155 | ||
156 | /* | |
157 | * --------------------------------------------------------------------------------- | |
158 | * Getter | |
159 | * --------------------------------------------------------------------------------- | |
160 | */ | |
161 | ||
162 | // ################################################################################# | |
163 | TParticle* AliHLTMCEvent::Particle( Int_t iParticle ) { | |
164 | // see header file for class documentation | |
165 | ||
166 | if ( iParticle >= fNParticles || !fStack ) | |
167 | return NULL; | |
168 | ||
169 | return (TParticle*) (*fStack)[iParticle]; | |
170 | } | |
171 | ||
172 | // ################################################################################# | |
173 | TParticle* AliHLTMCEvent::NextParticle() { | |
174 | // see header file for class documentation | |
175 | ||
176 | fCurrentParticleIndex++; | |
b16d48a7 | 177 | return Particle( fCurrentParticleIndex ); |
178 | } | |
179 | ||
7aac8168 | 180 | // ################################################################################# |
181 | AliAODJet* AliHLTMCEvent::GenJet( Int_t iJet ) const { | |
182 | // see header file for class documentation | |
183 | ||
184 | if ( iJet >= fNGenJets || !fGenJets ) | |
185 | return NULL; | |
186 | ||
187 | return reinterpret_cast<AliAODJet*> ((*fGenJets)[iJet]); | |
188 | } | |
189 | ||
190 | // ################################################################################# | |
191 | AliAODJet* AliHLTMCEvent:: NextGenJet() { | |
192 | // see header file for class documentation | |
193 | ||
194 | fCurrentGenJetIndex++; | |
195 | return GenJet( fCurrentGenJetIndex ); | |
196 | } | |
197 | ||
b16d48a7 | 198 | /* |
199 | * --------------------------------------------------------------------------------- | |
7aac8168 | 200 | * Helper |
b16d48a7 | 201 | * --------------------------------------------------------------------------------- |
202 | */ | |
203 | ||
204 | // ################################################################################# | |
7aac8168 | 205 | void AliHLTMCEvent::Compress() { |
b16d48a7 | 206 | // see header file for class documentation |
b16d48a7 | 207 | |
7aac8168 | 208 | if (fStack) |
209 | fStack->Compress(); | |
210 | if (fGenJets) | |
211 | fGenJets->Compress(); | |
212 | } | |
213 | ||
214 | // ################################################################################# | |
215 | void AliHLTMCEvent::Reset() { | |
216 | // see header file for class documentation | |
217 | ||
218 | fCurrentParticleIndex = -1; | |
219 | fCurrentGenJetIndex = -1; | |
b16d48a7 | 220 | } |
221 | ||
7aac8168 | 222 | /* |
223 | * --------------------------------------------------------------------------------- | |
224 | * Setter - private | |
225 | * --------------------------------------------------------------------------------- | |
226 | */ | |
227 | ||
b16d48a7 | 228 | // ################################################################################# |
7aac8168 | 229 | Int_t AliHLTMCEvent::FillMCTracks( AliStack* stack ) { |
b16d48a7 | 230 | // see header file for class documentation |
231 | ||
7aac8168 | 232 | Int_t iResult = 0; |
b16d48a7 | 233 | |
234 | // -- Create local stack | |
235 | if ( stack && stack->GetNtrack() > 0 ) | |
236 | fStack = new TClonesArray("TParticle", stack->GetNtrack() ); | |
7aac8168 | 237 | else { |
238 | HLTError( "Error creating local stack" ); | |
239 | iResult = -EINPROGRESS; | |
240 | } | |
241 | ||
b16d48a7 | 242 | // -- Loop over off-line stack and fill local stack |
7aac8168 | 243 | for (Int_t iterStack = 0; iterStack < stack->GetNtrack() && !iResult; iterStack++) { |
b16d48a7 | 244 | |
245 | TParticle *particle = stack->Particle(iterStack); | |
246 | if ( !particle) { | |
7aac8168 | 247 | HLTError( "Error reading particle %i out of %i", iterStack, stack->GetNtrack() ); |
248 | iResult = -EINPROGRESS; | |
b16d48a7 | 249 | continue; |
250 | } | |
251 | ||
252 | // ---------------- | |
396e75ed | 253 | // -- Apply cuts |
b16d48a7 | 254 | // ---------------- |
255 | ||
396e75ed | 256 | if ( fHasParticleCuts ) { |
257 | ||
258 | // -- primary | |
259 | if ( !(stack->IsPhysicalPrimary(iterStack)) ) | |
260 | continue; | |
261 | ||
262 | // -- final state | |
263 | if ( particle->GetNDaughters() != 0 ) | |
805aa9da | 264 | continue; |
396e75ed | 265 | |
266 | // -- particle in DB | |
267 | TParticlePDG * particlePDG = particle->GetPDG(); | |
268 | if ( ! particlePDG ) { | |
269 | particlePDG = TDatabasePDG::Instance()->GetParticle( particle->GetPdgCode() ); | |
270 | ||
271 | if ( ! particlePDG ) { | |
272 | HLTError("Particle %i not in PDG database", particle->GetPdgCode() ); | |
273 | iResult = -EINPROGRESS; | |
274 | continue; | |
275 | } | |
805aa9da | 276 | } |
277 | } | |
7aac8168 | 278 | |
b16d48a7 | 279 | // -- Add particle after cuts |
280 | AddParticle ( particle ); | |
281 | } | |
396e75ed | 282 | |
7aac8168 | 283 | return iResult; |
284 | } | |
285 | ||
286 | // ################################################################################# | |
287 | void AliHLTMCEvent::AddParticle( const TParticle* particle ) { | |
288 | // see header file for class documentation | |
289 | ||
290 | new( (*fStack) [fNParticles] ) TParticle( *particle ); | |
291 | fNParticles++; | |
b16d48a7 | 292 | |
293 | return; | |
294 | } | |
295 | ||
7aac8168 | 296 | // ################################################################################# |
297 | Int_t AliHLTMCEvent::FillMCJets( AliGenPythiaEventHeader* header ) { | |
298 | // see header file for class documentation | |
299 | ||
300 | Int_t iResult = 0; | |
301 | ||
d5b05c26 | 302 | // -- Check if Header is present |
303 | if ( !header ) { | |
304 | HLTError( "Error no PythiaHeader present" ); | |
7aac8168 | 305 | iResult = -EINPROGRESS; |
306 | } | |
307 | ||
d5b05c26 | 308 | // -- Create jet array |
309 | if ( header->NTriggerJets() > 0 ) | |
310 | fGenJets = new TClonesArray("AliAODJet", header->NTriggerJets()); | |
311 | else | |
312 | return iResult; | |
313 | ||
7aac8168 | 314 | // -- Loop over jets in header and fill local array |
315 | for (Int_t iterJet = 0; iterJet < header->NTriggerJets() && !iResult; iterJet++) { | |
316 | ||
317 | // -- Add jet | |
318 | AddGenJet(header, iterJet); | |
319 | ||
320 | } // for (Int_t iterJet = 0; iterJet < header->NTriggerJets() && !iResult; iterJet++) { | |
321 | ||
322 | HLTDebug("Pythia Jets found: %d", fNGenJets ); | |
323 | ||
324 | return iResult; | |
325 | } | |
326 | ||
b16d48a7 | 327 | /* |
328 | * --------------------------------------------------------------------------------- | |
7aac8168 | 329 | * Pythia jets - private |
b16d48a7 | 330 | * --------------------------------------------------------------------------------- |
331 | */ | |
332 | ||
7aac8168 | 333 | //################################################################################## |
334 | AliGenPythiaEventHeader* AliHLTMCEvent::GetPythiaEventHeader(AliMCEvent *mcEvent) { | |
b16d48a7 | 335 | // see header file for class documentation |
336 | ||
7aac8168 | 337 | Int_t iResult = 0; |
338 | ||
339 | AliGenPythiaEventHeader* pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*> (mcEvent->GenEventHeader()); | |
340 | ||
341 | if ( !pythiaGenHeader ) { | |
342 | ||
343 | // -- is cocktail header | |
344 | AliGenCocktailEventHeader* genCocktailHeader = dynamic_cast<AliGenCocktailEventHeader*>(mcEvent->GenEventHeader()); | |
345 | if ( !genCocktailHeader ) { | |
346 | HLTError("Error: Unknown header type (not Pythia or Cocktail)"); | |
347 | iResult = -1; | |
348 | } | |
349 | ||
350 | if ( !iResult ) { | |
351 | // -- Get Header | |
352 | TList* headerList = genCocktailHeader->GetHeaders(); | |
353 | ||
354 | for (Int_t iter = 0; iter < headerList->GetEntries(); iter++ ) { | |
355 | pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(headerList->At(iter)); | |
356 | if ( pythiaGenHeader ) | |
357 | break; | |
358 | } | |
359 | } | |
360 | } | |
361 | ||
362 | if ( pythiaGenHeader && !iResult ) | |
363 | return pythiaGenHeader; | |
364 | else { | |
365 | HLTError("PythiaHeader not found!"); | |
366 | return NULL; | |
367 | } | |
b16d48a7 | 368 | } |
369 | ||
7aac8168 | 370 | //################################################################################## |
371 | void AliHLTMCEvent::AddGenJet( AliGenPythiaEventHeader* header, Int_t iterJet ) { | |
b16d48a7 | 372 | // see header file for class documentation |
373 | ||
7aac8168 | 374 | Float_t pJet[] = {0., 0., 0., 0.}; // jet 4-vector ( x y z ) |
375 | ||
376 | // -- Get jet | |
377 | header->TriggerJet(iterJet, pJet); | |
378 | ||
379 | // -- Create TLorentzVector | |
380 | TLorentzVector v(pJet); | |
381 | ||
382 | // -- Add AliAODJet | |
383 | new( (*fGenJets) [fNGenJets] ) AliAODJet(v); | |
384 | fNGenJets++; | |
385 | ||
386 | return; | |
b16d48a7 | 387 | } |