31#include "TParameter.h"
44 ver = (TParameter<int>*)source->Get(
"version");
46 if ((ver ==
nullptr) || (ver->GetVal() !=
LIB_VERSION))
return nullptr;
48 TTree* TTreeMeta = (TTree*)source->Get(
"meta");
49 TTree* TTreeLib = (TTree*)source->Get(
"library");
51 if ((TTreeMeta ==
nullptr) || (TTreeLib ==
nullptr))
return nullptr;
53 std::cout <<
"TestShowerLib header found." << std::endl;
57 if (!(newlib->
readMeta(TTreeMeta)) || !(newlib->
read(TTreeLib))) {
59 std::cout <<
"TestShowerLib read unsuccessful." << std::endl;
79 std::ifstream filestr(inputFile.c_str(),std::ios::in);
81 if (!filestr.is_open()) {
82 std::cout <<
"TestShowerLib " << inputFile <<
": bad file!" << std::endl;
87 std::getline(filestr,instr);
88 std::stringstream
ss(instr);
111 std::getline(filestr,instr);
121 std::cout <<
"Library is not created for production use" << std::endl;
125 std::cout <<
"Library is only for testing, not for production use" << std::endl;
132 std::cout <<
"Library is not created for production use" << std::endl;
136 std::cout <<
"Library is only for testing, not for production use" << std::endl;
143 std::cout <<
"Library is not created for production use" << std::endl;
147 std::cout <<
"Library is only for testing, not for production use" << std::endl;
154 std::cout <<
"ERROR: filled" << std::endl;
159 theinfo.
vertex = std::make_unique<HepMC::FourVector>(genParticle->production_vertex()->position());
160 theinfo.
momentum = std::make_unique<HepMC::FourVector>(genParticle->momentum());
162 m_libData.emplace_back(std::move(theinfo), *shower);
172 dest->WriteObject(&ver,
"version");
180 dest->WriteObject(&TTreeLib,
"library");
181 dest->WriteObject(&TTreeMeta,
"meta");
201 int nentr = source->GetEntriesFast();
202 if (nentr < 3)
return false;
203 Float_t
x,
y,
z,e,time;
204 source->SetBranchAddress(
"x",&
x);
205 source->SetBranchAddress(
"y",&
y);
206 source->SetBranchAddress(
"z",&
z);
207 source->SetBranchAddress(
"e",&e);
208 source->SetBranchAddress(
"time",&time);
213 source->GetEntry(entr++);
214 int nhits = (int)(e+0.1);
218 theinfo.
vertex = std::make_unique<HepMC::FourVector>(
x,
y,
z,0);
219 source->GetEntry(entr++);
221 theinfo.
momentum = std::make_unique<HepMC::FourVector>(
x,
y,
z,e);
222 for(
int i = 0; i < nhits; i++) {
223 source->GetEntry(entr++);
226 m_libData.emplace_back(std::move(theinfo),shower);
227 }
while (entr < nentr);
247 Float_t
x,
y,
z,e,time;
248 dest->Branch(
"x",&
x);
249 dest->Branch(
"y",&
y);
250 dest->Branch(
"z",&
z);
251 dest->Branch(
"e",&e);
252 dest->Branch(
"time",&time);
254 HepMC::FourVector vertex = *lib.first.vertex;
255 HepMC::FourVector momentum = *lib.first.momentum;
259 e = lib.second.size();
260 time = lib.second.getZSize();
266 time = lib.second.getRSize();
bool readMeta(TTree *source)
read metadata from the given TTree
IShowerLib()
default constructor
int m_particle
ID of the generated particles.
bool writeMeta(TTree *dest) const
write metadata to the given TTree
std::string m_detector
name of the detector
std::string m_comment
comment
bool m_filled
is the library read from ROOT or from structure file
G4ThreeVector GetPosition() const
G4double GetEnergy() const
Class for shower library shower.
void setZSize(const float zsize)
void setRSize(const float rsize)
virtual std::vector< EnergySpot > * getShower(const G4Track *track, ShowerLibStatistics *stats, int randomShift) const
get shower for given G4 track
virtual bool storeShower(HepMC::ConstGenParticlePtr genParticle, const Shower *shower)
store shower in the library
std::pair< genInfo, Shower > storedShower
static IShowerLib * createEmptyLib(const std::string &inputFile)
factory method. create empty library with the given structure. returns NULL if file is invalid.
virtual bool writeToROOT(TFile *dest)
write library to ROOT file
virtual double getContainmentR(const G4Track *track) const
get average lateral spread of the showers for the given energy
virtual double getContainmentZ(const G4Track *track) const
get average length of showers for the given energy
bool write(TTree *dest) const
write library to given TTree
static IShowerLib * readFromROOTFile(TFile *source)
factory method. create a library from root file. returns NULL if file is invalid.
virtual ~TestShowerLib()
default destructor
bool read(TTree *source)
read library from given TTree
virtual ShowerLibStatistics * createStatistics() const
const GenParticle * ConstGenParticlePtr
Namespace for the ShowerLib related classes.
std::unique_ptr< HepMC::FourVector > momentum
std::unique_ptr< HepMC::FourVector > vertex