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. *
7 * Primary Authors: Jochen Thaeder <thaeder@kip.uni-heidelberg.de> *
8 * for The ALICE HLT Project. *
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 **************************************************************************/
19 /** @file AliHLTMCEvent.cxx
20 @author Jochen Thaeder
22 @brief Container class for an AliMCEvent
25 // see header file for class documentation
27 // refer to README to build package
29 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
36 #include "TParticlePDG.h"
37 #include "TDatabasePDG.h"
39 #include "AliGenCocktailEventHeader.h"
41 #include "AliHLTMCEvent.h"
43 /** ROOT macro for the implementation of ROOT specific class methods */
44 ClassImp(AliHLTMCEvent)
47 * ---------------------------------------------------------------------------------
48 * Constructor / Destructor
49 * ---------------------------------------------------------------------------------
52 // #################################################################################
53 AliHLTMCEvent::AliHLTMCEvent() :
54 fCurrentParticleIndex(-1),
57 fCurrentGenJetIndex(-1),
60 fHasParticleCuts(kFALSE) {
61 // see header file for class documentation
63 // refer to README to build package
65 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
68 // #################################################################################
69 AliHLTMCEvent::AliHLTMCEvent( Bool_t applyParticleCuts ) :
70 fCurrentParticleIndex(-1),
73 fCurrentGenJetIndex(-1),
76 fHasParticleCuts(applyParticleCuts) {
77 // see header file for class documentation
80 // #################################################################################
81 AliHLTMCEvent::~AliHLTMCEvent() {
82 // see header file for class documentation
98 * ---------------------------------------------------------------------------------
100 * ---------------------------------------------------------------------------------
103 // #################################################################################
104 Int_t AliHLTMCEvent::FillMCEvent( AliStack *stack, AliHeader *header ) {
105 // see header file for class documentation
110 if ( (iResult = FillMCTracks(stack)) )
111 HLTError("Error filling particles" );
114 HLTError("Error reading stack" );
119 AliGenPythiaEventHeader* pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*> (header->GenEventHeader());
120 if ( pythiaGenHeader ) {
121 if ( (iResult = FillMCJets(pythiaGenHeader)) )
122 HLTError("Error filling jets" );
125 HLTError("Error reading gen header" );
130 HLTError("Error reading header" );
139 // #################################################################################
140 Int_t AliHLTMCEvent::FillMCEvent( AliMCEvent *pMCEvent ) {
141 // see header file for class documentation
145 if ( (iResult = FillMCTracks(pMCEvent->Stack())) )
146 HLTError("Error filling particles" );
148 if ( (iResult = FillMCJets(GetPythiaEventHeader(pMCEvent))) )
149 HLTError("Error filling jets" );
157 * ---------------------------------------------------------------------------------
159 * ---------------------------------------------------------------------------------
162 // #################################################################################
163 TParticle* AliHLTMCEvent::Particle( Int_t iParticle ) {
164 // see header file for class documentation
166 if ( iParticle >= fNParticles || !fStack )
169 return (TParticle*) (*fStack)[iParticle];
172 // #################################################################################
173 TParticle* AliHLTMCEvent::NextParticle() {
174 // see header file for class documentation
176 fCurrentParticleIndex++;
177 return Particle( fCurrentParticleIndex );
180 // #################################################################################
181 AliAODJet* AliHLTMCEvent::GenJet( Int_t iJet ) const {
182 // see header file for class documentation
184 if ( iJet >= fNGenJets || !fGenJets )
187 return reinterpret_cast<AliAODJet*> ((*fGenJets)[iJet]);
190 // #################################################################################
191 AliAODJet* AliHLTMCEvent:: NextGenJet() {
192 // see header file for class documentation
194 fCurrentGenJetIndex++;
195 return GenJet( fCurrentGenJetIndex );
199 * ---------------------------------------------------------------------------------
201 * ---------------------------------------------------------------------------------
204 // #################################################################################
205 void AliHLTMCEvent::Compress() {
206 // see header file for class documentation
211 fGenJets->Compress();
214 // #################################################################################
215 void AliHLTMCEvent::Reset() {
216 // see header file for class documentation
218 fCurrentParticleIndex = -1;
219 fCurrentGenJetIndex = -1;
223 * ---------------------------------------------------------------------------------
225 * ---------------------------------------------------------------------------------
228 // #################################################################################
229 Int_t AliHLTMCEvent::FillMCTracks( AliStack* stack ) {
230 // see header file for class documentation
234 // -- Create local stack
235 if ( stack && stack->GetNtrack() > 0 )
236 fStack = new TClonesArray("TParticle", stack->GetNtrack() );
238 HLTError( "Error creating local stack" );
239 iResult = -EINPROGRESS;
242 // -- Loop over off-line stack and fill local stack
243 for (Int_t iterStack = 0; iterStack < stack->GetNtrack() && !iResult; iterStack++) {
245 TParticle *particle = stack->Particle(iterStack);
247 HLTError( "Error reading particle %i out of %i", iterStack, stack->GetNtrack() );
248 iResult = -EINPROGRESS;
256 if ( fHasParticleCuts ) {
259 if ( !(stack->IsPhysicalPrimary(iterStack)) )
263 if ( particle->GetNDaughters() != 0 )
267 TParticlePDG * particlePDG = particle->GetPDG();
268 if ( ! particlePDG ) {
269 particlePDG = TDatabasePDG::Instance()->GetParticle( particle->GetPdgCode() );
271 if ( ! particlePDG ) {
272 HLTError("Particle %i not in PDG database", particle->GetPdgCode() );
273 iResult = -EINPROGRESS;
279 // -- Add particle after cuts
280 AddParticle ( particle );
286 // #################################################################################
287 void AliHLTMCEvent::AddParticle( const TParticle* particle ) {
288 // see header file for class documentation
290 new( (*fStack) [fNParticles] ) TParticle( *particle );
296 // #################################################################################
297 Int_t AliHLTMCEvent::FillMCJets( AliGenPythiaEventHeader* header ) {
298 // see header file for class documentation
302 // -- Create jet array
303 if ( header && header->NTriggerJets() > 0 )
304 fGenJets = new TClonesArray("AliAODJet", header->NTriggerJets());
306 HLTError( "Error creating trigger array" );
307 iResult = -EINPROGRESS;
310 // -- Loop over jets in header and fill local array
311 for (Int_t iterJet = 0; iterJet < header->NTriggerJets() && !iResult; iterJet++) {
314 AddGenJet(header, iterJet);
316 } // for (Int_t iterJet = 0; iterJet < header->NTriggerJets() && !iResult; iterJet++) {
318 HLTDebug("Pythia Jets found: %d", fNGenJets );
324 * ---------------------------------------------------------------------------------
325 * Pythia jets - private
326 * ---------------------------------------------------------------------------------
329 //##################################################################################
330 AliGenPythiaEventHeader* AliHLTMCEvent::GetPythiaEventHeader(AliMCEvent *mcEvent) {
331 // see header file for class documentation
335 AliGenPythiaEventHeader* pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*> (mcEvent->GenEventHeader());
337 if ( !pythiaGenHeader ) {
339 // -- is cocktail header
340 AliGenCocktailEventHeader* genCocktailHeader = dynamic_cast<AliGenCocktailEventHeader*>(mcEvent->GenEventHeader());
341 if ( !genCocktailHeader ) {
342 HLTError("Error: Unknown header type (not Pythia or Cocktail)");
348 TList* headerList = genCocktailHeader->GetHeaders();
350 for (Int_t iter = 0; iter < headerList->GetEntries(); iter++ ) {
351 pythiaGenHeader = dynamic_cast<AliGenPythiaEventHeader*>(headerList->At(iter));
352 if ( pythiaGenHeader )
358 if ( pythiaGenHeader && !iResult )
359 return pythiaGenHeader;
361 HLTError("PythiaHeader not found!");
366 //##################################################################################
367 void AliHLTMCEvent::AddGenJet( AliGenPythiaEventHeader* header, Int_t iterJet ) {
368 // see header file for class documentation
370 Float_t pJet[] = {0., 0., 0., 0.}; // jet 4-vector ( x y z )
373 header->TriggerJet(iterJet, pJet);
375 // -- Create TLorentzVector
376 TLorentzVector v(pJet);
379 new( (*fGenJets) [fNGenJets] ) AliAODJet(v);