]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - STEER/STEER/AliMCGenHandler.cxx
Fix for raw ctp decoding (Marek)
[u/mrichter/AliRoot.git] / STEER / STEER / AliMCGenHandler.cxx
... / ...
CommitLineData
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
16/* $Id: AliMCGenHandler.cxx 64675 2013-10-23 12:21:37Z hristov $ */
17
18//-------------------------------------------------------------------------
19// Class AliMCGenHandler
20// This class can be used with the analysis framework to generate event on
21// the fly and analyse them.
22//
23// Origin: Andrei Gheata, Jan Fiete Grosse-Oetringhaus
24//-------------------------------------------------------------------------
25
26#include "AliMCGenHandler.h"
27#include "AliMCEvent.h"
28#include "AliPDG.h"
29#include "AliHeader.h"
30#include "AliStack.h"
31#include "AliLog.h"
32#include "AliGenerator.h"
33#include "AliRunLoader.h"
34#include "AliRun.h"
35#include "AliAnalysisManager.h"
36
37ClassImp(AliMCGenHandler)
38
39AliMCGenHandler::AliMCGenHandler() :
40 AliInputEventHandler(),
41 fMCEvent(0),
42 fEventNumber(0),
43 fStack(0),
44 fHeader(0),
45 fGenerator(0),
46 fSeedMode(0),
47 fSeed(0)
48{
49 //
50 // Default constructor
51 //
52 // Be sure to add all particles to the PDG database
53 AliPDG::AddParticlesToPdgDataBase();
54}
55
56AliMCGenHandler::AliMCGenHandler(const char* name, const char* title) :
57 AliInputEventHandler(name, title),
58 fMCEvent(0),
59 fEventNumber(0),
60 fStack(0),
61 fHeader(0),
62 fGenerator(0),
63 fSeedMode(0),
64 fSeed(0)
65{
66 //
67 // Constructor
68 //
69 // Be sure to add all particles to the PDG database
70 AliPDG::AddParticlesToPdgDataBase();
71}
72
73AliMCGenHandler::~AliMCGenHandler()
74{
75 // Destructor
76 delete fMCEvent;
77 delete fGenerator;
78}
79
80Bool_t AliMCGenHandler::Init(Option_t* /*opt*/)
81{
82 // Initialize input
83 //
84
85 if (!fGenerator)
86 AliFatal("fGenerator needs to be set before");
87
88 if (fSeedMode == 0)
89 Printf("AliMCGenHandler::Init: Not setting any seed. Seed needs to be set externally!");
90 else
91 {
92 if (fSeedMode == 1)
93 {
94 Printf("AliMCGenHandler::Init: Using manually set seed");
95 }
96 else if (fSeedMode == 2)
97 {
98 Printf("AliMCGenHandler::Init: Taking seed from current time");
99 fSeed = time(0);
100 }
101 else if (fSeedMode == 3)
102 {
103 Printf("AliMCGenHandler::Init: Taking seed from AliEn job id");
104 TString tmp(gSystem->Getenv("ALIEN_PROC_ID"));
105 fSeed = tmp.Atoi();
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()));
108 }
109 else
110 AliFatal(Form("Seed mode %d unknown", fSeedMode));
111
112 Printf("AliMCGenHandler::Init: Using seed: %d", fSeed);
113 gRandom->SetSeed(fSeed);
114 }
115
116 AliRunLoader* rl = AliRunLoader::Open("galice.root","FASTRUN","recreate");
117 rl->MakeTree("E");
118 gAlice->SetRunLoader(rl);
119 rl->MakeStack();
120 fStack = rl->Stack();
121 fHeader = rl->GetHeader();
122
123 fGenerator->SetStack(fStack);
124 fGenerator->Init();
125
126 fMCEvent = new AliMCEvent;
127
128 return kTRUE;
129}
130
131Bool_t AliMCGenHandler::BeginEvent(Long64_t /*entry*/)
132{
133 // Begin event
134
135 fHeader->Reset(0, fEventNumber++);
136
137 if (AliAnalysisManager::GetAnalysisManager()->GetDebugLevel() > 1)
138 Printf("AliMCGenHandler::BeginEvent: Generating Event number %lld", fEventNumber);
139
140 fGenerator->Generate();
141
142 fHeader->SetStack(fStack);
143 fHeader->SetNprimary(fStack->GetNprimary());
144 fHeader->SetNtrack(fStack->GetNtrack());
145
146 fMCEvent->ConnectHeaderAndStack(fHeader);
147
148 return kTRUE;
149}
150
151Bool_t AliMCGenHandler::FinishEvent()
152{
153 // Clean-up after each event
154
155 fMCEvent->Stack()->Reset();
156
157 return kTRUE;
158}