Project
Loading...
Searching...
No Matches
GeneratorFromFile.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
13
14#ifndef ALICEO2_GENERATORFROMFILE_H_
15#define ALICEO2_GENERATORFROMFILE_H_
16
17#include "FairGenerator.h"
21#include <TRandom3.h>
22#include <random>
23
24class TBranch;
25class TFile;
26class TParticle;
27class TGrid;
28
29namespace o2
30{
31namespace eventgen
32{
39{
40 public:
41 GeneratorFromFile() = default;
42 GeneratorFromFile(const char* name);
43
44 // the FairGenerator interface methods
45
50 bool ReadEvent(FairPrimaryGenerator* primGen) override;
51
52 // Set from which event to start
53 void SetStartEvent(int start);
54
55 void SetSkipNonTrackable(bool b) { mSkipNonTrackable = b; }
56 void setFixOffShell(bool b) { mFixOffShell = b; }
57 bool rejectOrFixKinematics(TParticle& p);
58
59 private:
60 TFile* mEventFile = nullptr;
61 int mEventCounter = 0;
62 int mEventsAvailable = 0;
63 bool mSkipNonTrackable = true;
64 bool mFixOffShell = true; // fix particles with M_assigned != M_calculated
65 ClassDefOverride(GeneratorFromFile, 1);
66};
67
71{
72 public:
74 GeneratorFromO2Kine(const char* name);
76
77 bool Init() override;
78
79 // the o2 Generator interface methods
80 bool generateEvent() override
81 { /* trivial - actual work in importParticles */
82 return true;
83 }
84 bool importParticles() override;
85
86 // Set from which event to start
87 void SetStartEvent(int start);
88
89 void setContinueMode(bool val) { mContinueMode = val; };
91 void updateHeader(o2::dataformats::MCEventHeader* eventHeader) override;
92
93 private:
94 TFile* mEventFile = nullptr;
95 TBranch* mEventBranch = nullptr;
96 TBranch* mMCHeaderBranch = nullptr;
97 int mEventCounter = 0;
98 int mEventsAvailable = 0;
99 bool mSkipNonTrackable = true;
100 bool mContinueMode = false;
101 bool mRoundRobin = false;
102 bool mRandomize = false;
103 unsigned int mRngSeed = 0;
104 bool mRandomPhi = false;
105 TGrid* mAlienInstance = nullptr; // a cached connection to TGrid (needed for Alien locations)
106 std::unique_ptr<O2KineGenConfig> mConfig;
107
108 std::unique_ptr<o2::dataformats::MCEventHeader> mOrigMCEventHeader;
109
110 ClassDefOverride(GeneratorFromO2Kine, 2);
111};
112
120{
121 public:
122 constexpr static std::string_view eventpool_filename = "evtpool.root";
123 constexpr static std::string_view alien_protocol_prefix = "alien://";
124
125 GeneratorFromEventPool() = default; // mainly for ROOT IO
127
128 bool Init() override;
129
130 // the o2 Generator interface methods
131 bool generateEvent() override
132 { /* trivial - actual work in importParticles */
133 return mO2KineGenerator->generateEvent();
134 }
135 bool importParticles() override
136 {
137 mO2KineGenerator->clearParticles(); // clear old container before filling with new ones
138 auto import_good = mO2KineGenerator->importParticles();
139 // transfer the particles (could be avoided)
140 mParticles = mO2KineGenerator->getParticles();
141
142 return import_good;
143 }
144
146 {
147 mO2KineGenerator->updateHeader(eventHeader);
148 }
149
150 // determine the collection of available files
151 std::vector<std::string> setupFileUniverse(std::string const& path) const;
152
153 std::vector<std::string> const& getFileUniverse() const { return mPoolFilesAvailable; }
154
155 private:
156 EventPoolGenConfig mConfig;
157 std::unique_ptr<o2::eventgen::GeneratorFromO2Kine> mO2KineGenerator = nullptr;
158 std::vector<std::string> mPoolFilesAvailable;
159 std::string mFileChosen;
160 // random number generator to determine a concrete file name
161 std::mt19937 mRandomEngine;
162
163 ClassDefOverride(GeneratorFromEventPool, 1);
164};
165
166} // end namespace eventgen
167} // end namespace o2
168
169#endif
static constexpr std::string_view eventpool_filename
static constexpr std::string_view alien_protocol_prefix
std::vector< std::string > setupFileUniverse(std::string const &path) const
void updateHeader(o2::dataformats::MCEventHeader *eventHeader) override
std::vector< std::string > const & getFileUniverse() const
bool ReadEvent(FairPrimaryGenerator *primGen) override
void updateHeader(o2::dataformats::MCEventHeader *eventHeader) override
std::vector< TParticle > mParticles
Definition Generator.h:147
GLuint const GLchar * name
Definition glcorearb.h:781
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLuint GLfloat * val
Definition glcorearb.h:1582
GLsizei const GLchar *const * path
Definition glcorearb.h:3591
GLuint start
Definition glcorearb.h:469
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...