76 #include "art/Framework/Core/EDProducer.h"
77 #include "art/Framework/Core/ModuleMacros.h"
78 #include "art/Framework/Principal/Event.h"
79 #include "art/Framework/Principal/SubRun.h"
80 #include "fhiclcpp/ParameterSet.h"
81 #include "cetlib_except/exception.h"
82 #include "art/Framework/Services/Registry/ServiceHandle.h"
83 #include "cetlib/search_path.h"
84 #include "cetlib/getenv.h"
85 #include "cetlib/split_path.h"
86 #include "cetlib_except/exception.h"
87 #include "messagefacility/MessageLogger/MessageLogger.h"
88 #include "TLorentzVector.h"
92 #include "nusimdata/SimulationBase/MCTruth.h"
93 #include "nusimdata/SimulationBase/MCParticle.h"
95 #include "ifdh_art/IFDHService/IFDH_service.h"
96 #undef USE_IFDH_SERVICE // ifdh for now
104 void produce(art::Event &
e)
override;
106 void beginRun(art::Run & run)
override;
107 void endSubRun(art::SubRun& sr)
override;
120 , fInputFilePath(
p.get<std::string>(
"InputFilePath"))
121 , fInputFile(
nullptr)
122 , fEventsPerPOT{
p.get<
double>(
"EventsPerPOT", -1.)}
123 , fEventsPerSubRun(0)
125 produces< std::vector<simb::MCTruth> >();
126 produces< sumdata::RunData, art::InRun >();
127 produces< sumdata::POTSummary, art::InSubRun >();
142 std::string fullFileName = fInputFilePath;
144 cet::search_path searchPath(
"FW_SEARCH_PATH");
145 if (searchPath.find_file(fInputFilePath, fullFileName)) {
146 mf::LogDebug(
"HepMCFileGen")
147 <<
"Input file '" << fInputFilePath <<
"' found in FW_SEARCH_PATH:\n"
155 if (fullFileName.compare(0, 6,
"/pnfs/") == 0) {
156 fullFileName = art::ServiceHandle<IFDH>()->fetchInput(fullFileName);
157 mf::LogDebug(
"HepMCFileGen")
158 <<
"IFDH fetch: '" << fInputFilePath <<
"' -> '" << fullFileName <<
"'";
164 mf::LogDebug(
"HepMCFileGen")
165 <<
"Reading input file '" << fInputFilePath <<
"' as:\n" << fullFileName;
166 std::ifstream inputFile(fullFileName);
167 if (inputFile)
return inputFile;
170 throw cet::exception(
"HepMCFileGen")
171 <<
"HEPMC input file '" << fInputFilePath <<
"' can't be opened.\n";
180 fInputFile =
new std::ifstream(open_file());
186 fEventsPerSubRun = 0;
187 art::ServiceHandle<geo::Geometry const> geo;
188 run.put(std::make_unique<sumdata::RunData>(geo->DetectorName()));
193 auto p = std::make_unique<sumdata::POTSummary>();
194 p->totpot = fEventsPerSubRun * fEventsPerPOT;
195 p->totgoodpot = fEventsPerSubRun * fEventsPerPOT;
196 sr.put(std::move(
p));
203 if( !fInputFile->good() || fInputFile->peek() == EOF) {
206 if( !fInputFile->good() || fInputFile->peek() == EOF) {
207 throw cet::exception(
"HepMCFileGen") <<
"input text file "
208 <<
" cannot be read in produce().\n";
210 std::unique_ptr< std::vector<simb::MCTruth> > truthcol(
new std::vector<simb::MCTruth>);
214 unsigned short nParticles = 0;
218 int secondMother = 0;
219 int firstDaughter = 0;
220 int secondDaughter = 0;
221 double xMomentum = 0.;
222 double yMomentum = 0.;
223 double zMomentum = 0.;
226 double xPosition = 0.;
227 double yPosition = 0.;
228 double zPosition = 0.;
230 bool set_neutrino =
false;
232 int ccnc = -1,
mode = -1, itype = -1, target = -1, nucleon = -1, quark = -1;
233 double w = -1,
x = -1,
y = -1, qsqr = -1;
236 std::getline(*fInputFile, oneLine);
237 std::istringstream inputLine;
238 inputLine.str(oneLine);
239 inputLine >>
event >> nParticles;
243 for(
unsigned short i = 0; i < nParticles; ++i){
244 std::getline(*fInputFile, oneLine);
246 inputLine.str(oneLine);
247 inputLine >> status >> pdg
248 >> firstMother >> secondMother >> firstDaughter >> secondDaughter
249 >> xMomentum >> yMomentum >> zMomentum >> energy >> mass
250 >> xPosition >> yPosition >> zPosition >> time;
251 std::cout<<
"pdg_all"<<pdg<<
"xmomentum_all"<<xMomentum<<
"ymomentum_all"<<yMomentum<<
"zposition_all"<<zPosition<<std::endl;
252 TLorentzVector pos(xPosition, yPosition, zPosition, time);
253 TLorentzVector mom(xMomentum, yMomentum, zMomentum, energy);
254 simb::MCParticle part(i, pdg,
"primary", firstMother, mass, status);
255 part.AddTrajectoryPoint(pos, mom);
260 ccnc = firstDaughter;
261 mode = secondDaughter;
263 target = nucleon = quark = w =
x =
y = qsqr = -1;
264 std::cout<<
"pdg_mother"<<pdg<<
"xmomentum_mother"<<xMomentum<<
"ymomentum_mother"<<yMomentum<<
"zposition_mother"<<zPosition<<std::endl;
267 std::cout << i <<
" Particle added with Pdg " << part.PdgCode() <<
", Mother " << part.Mother() <<
", track id " << part.TrackId() <<
", ene " << part.E() << std::endl;
271 truth.SetNeutrino(ccnc,
282 truth.SetOrigin(simb::kBeamNeutrino);
289 truthcol->push_back(truth);
290 e.put(std::move(truthcol));
std::ifstream * fInputFile
int fEventsPerSubRun
Keeps track of the number of processed events per subrun.
std::string fInputFilePath
Path to the HEPMC input file, relative to FW_SEARCH_PATH.
process_name opflash particleana ie x
void endSubRun(art::SubRun &sr) override
process_name opflash particleana ie ie y
void beginRun(art::Run &run) override
std::ifstream open_file()
HepMCFileGen(fhicl::ParameterSet const &p)
double fEventsPerPOT
Number of events per POT (to be set)
art framework interface to geometry description
BEGIN_PROLOG could also be cout
void produce(art::Event &e) override