1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 /* $Id: AliMCGenHandler.cxx 64675 2013-10-23 12:21:37Z hristov $ */
18 //-------------------------------------------------------------------------
19 // Class AliMCGenHandler
20 // This class can be used with the analysis framework to generate event on
21 // the fly and analyse them.
23 // Origin: Andrei Gheata, Jan Fiete Grosse-Oetringhaus
24 //-------------------------------------------------------------------------
26 #include "AliMCGenHandler.h"
27 #include "AliMCEvent.h"
29 #include "AliHeader.h"
32 #include "AliGenerator.h"
33 #include "AliRunLoader.h"
35 #include "AliAnalysisManager.h"
37 ClassImp(AliMCGenHandler)
39 AliMCGenHandler::AliMCGenHandler() :
40 AliInputEventHandler(),
50 // Default constructor
52 // Be sure to add all particles to the PDG database
53 AliPDG::AddParticlesToPdgDataBase();
56 AliMCGenHandler::AliMCGenHandler(const char* name, const char* title) :
57 AliInputEventHandler(name, title),
69 // Be sure to add all particles to the PDG database
70 AliPDG::AddParticlesToPdgDataBase();
73 AliMCGenHandler::~AliMCGenHandler()
80 Bool_t AliMCGenHandler::Init(Option_t* /*opt*/)
86 AliFatal("fGenerator needs to be set before");
89 Printf("AliMCGenHandler::Init: Not setting any seed. Seed needs to be set externally!");
94 Printf("AliMCGenHandler::Init: Using manually set seed");
96 else if (fSeedMode == 2)
98 Printf("AliMCGenHandler::Init: Taking seed from current time");
101 else if (fSeedMode == 3)
103 Printf("AliMCGenHandler::Init: Taking seed from AliEn job id");
104 TString tmp(gSystem->Getenv("ALIEN_PROC_ID"));
106 if (tmp.Length() == 0 || fSeed == 0)
107 AliFatal(Form("Could not retrieve AliEn job id for seed. The variable ALIEN_PROC_ID contains %s", tmp.Data()));
110 AliFatal(Form("Seed mode %d unknown", fSeedMode));
112 Printf("AliMCGenHandler::Init: Using seed: %d", fSeed);
113 gRandom->SetSeed(fSeed);
116 AliRunLoader* rl = AliRunLoader::Open("galice.root","FASTRUN","recreate");
118 gAlice->SetRunLoader(rl);
120 fStack = rl->Stack();
121 fHeader = rl->GetHeader();
123 fGenerator->SetStack(fStack);
126 fMCEvent = new AliMCEvent;
131 Bool_t AliMCGenHandler::BeginEvent(Long64_t /*entry*/)
135 fHeader->Reset(0, fEventNumber++);
137 if (AliAnalysisManager::GetAnalysisManager()->GetDebugLevel() > 1)
138 Printf("AliMCGenHandler::BeginEvent: Generating Event number %lld", fEventNumber);
140 fGenerator->Generate();
142 fHeader->SetStack(fStack);
143 fHeader->SetNprimary(fStack->GetNprimary());
144 fHeader->SetNtrack(fStack->GetNtrack());
146 fMCEvent->ConnectHeaderAndStack(fHeader);
151 Bool_t AliMCGenHandler::FinishEvent()
153 // Clean-up after each event
155 fMCEvent->Stack()->Reset();