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; };
90
91 private:
93 void updateHeader(o2::dataformats::MCEventHeader* eventHeader) override;
94
95 TFile* mEventFile = nullptr;
96 TBranch* mEventBranch = nullptr;
97 TBranch* mMCHeaderBranch = nullptr;
98 int mEventCounter = 0;
99 int mEventsAvailable = 0;
100 bool mSkipNonTrackable = true;
101 bool mContinueMode = false;
102 bool mRoundRobin = false;
103 bool mRandomize = false;
104 unsigned int mRngSeed = 0;
105 bool mRandomPhi = false;
106 TGrid* mAlienInstance = nullptr; // a cached connection to TGrid (needed for Alien locations)
107 std::unique_ptr<O2KineGenConfig> mConfig;
108
109 std::unique_ptr<o2::dataformats::MCEventHeader> mOrigMCEventHeader;
110
111 ClassDefOverride(GeneratorFromO2Kine, 2);
112};
113
121{
122 public:
123 constexpr static std::string_view eventpool_filename = "evtpool.root";
124 constexpr static std::string_view alien_protocol_prefix = "alien://";
125
126 GeneratorFromEventPool() = default; // mainly for ROOT IO
128
129 bool Init() override;
130
131 // the o2 Generator interface methods
132 bool generateEvent() override
133 { /* trivial - actual work in importParticles */
134 return mO2KineGenerator->generateEvent();
135 }
136 bool importParticles() override
137 {
138 mO2KineGenerator->clearParticles(); // clear old container before filling with new ones
139 auto import_good = mO2KineGenerator->importParticles();
140 // transfer the particles (could be avoided)
141 mParticles = mO2KineGenerator->getParticles();
142
143 return import_good;
144 }
145
146 // determine the collection of available files
147 std::vector<std::string> setupFileUniverse(std::string const& path) const;
148
149 std::vector<std::string> const& getFileUniverse() const { return mPoolFilesAvailable; }
150
151 private:
152 EventPoolGenConfig mConfig;
153 std::unique_ptr<o2::eventgen::GeneratorFromO2Kine> mO2KineGenerator = nullptr;
154 std::vector<std::string> mPoolFilesAvailable;
155 std::string mFileChosen;
156 // random number generator to determine a concrete file name
157 std::mt19937 mRandomEngine;
158
159 ClassDefOverride(GeneratorFromEventPool, 1);
160};
161
162} // end namespace eventgen
163} // end namespace o2
164
165#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
std::vector< std::string > const & getFileUniverse() const
bool ReadEvent(FairPrimaryGenerator *primGen) override
std::vector< TParticle > mParticles
Definition Generator.h:140
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 ...