All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Attributes | List of all members
evgen::ldm::NuMiKaonGen Class Reference

NuMiKaonGen class definiton. More...

Inheritance diagram for evgen::ldm::NuMiKaonGen:
evgen::ldm::IMesonGen evgen::ldm::IMeVPrtlStage

Public Member Functions

 NuMiKaonGen (fhicl::ParameterSet const &pset)
 Constructor. More...
 
 ~NuMiKaonGen ()
 Destructor. More...
 
double GetPOT () override
 
simb::MCFlux GetNext () override
 
void configure (const fhicl::ParameterSet &) override
 Interface for configuring the particular algorithm tool. More...
 
const bsim::Dk2Nu * GetNextEntry ()
 
std::vector< std::string > LoadFluxFiles ()
 
simb::MCFlux MakeMCFlux (const bsim::Dk2Nu &dk2nu)
 
double LoadPOT ()
 
double MaxWeight () override
 
- Public Member Functions inherited from evgen::ldm::IMesonGen
virtual ~IMesonGen () noexcept=default
 Virtual Destructor. More...
 
- Public Member Functions inherited from evgen::ldm::IMeVPrtlStage
virtual ~IMeVPrtlStage () noexcept
 Virtual Destructor. More...
 
 IMeVPrtlStage (const char *name)
 
TVector3 RandomUnitVector ()
 
double GetRandom ()
 
const char * Name ()
 

Private Attributes

std::string fSearchPath
 
std::vector< std::string > fSearchPatterns
 
unsigned long fMaxFluxFileMB
 
std::string fFluxCopyMethod
 
bool fRandomizeFiles
 
std::string fTreeName
 
std::string fMetaTreeName
 
unsigned fFileIndex
 
bool fNewFile
 
std::vector< std::string > fFluxFiles
 
unsigned fEntry
 
unsigned fEntryStart
 
TTree * fFluxTree
 
TFile * fFluxFile
 
bsim::Dk2Nu * fDk2Nu
 
double fAccumulatedPOT
 
double fThisFilePOT
 

Additional Inherited Members

- Protected Attributes inherited from evgen::ldm::IMeVPrtlStage
CLHEP::HepRandomEngine * fEngine
 
const char * fName
 

Detailed Description

NuMiKaonGen class definiton.

Definition at line 48 of file NuMiKaonGen_tool.cc.

Constructor & Destructor Documentation

evgen::ldm::NuMiKaonGen::NuMiKaonGen ( fhicl::ParameterSet const &  pset)

Constructor.

Definition at line 105 of file NuMiKaonGen_tool.cc.

105  :
106  IMeVPrtlStage("NuMiKaonGen")
107 {
108  configure(pset);
109 
110  // copy the flux files locally
112 
113  // setup indices
114  fFileIndex = 0;
115  fEntry = 0;
116  fEntryStart = 0;
117  fNewFile = true;
118  fFluxTree = NULL;
119  fFluxFile = NULL;
120  fDk2Nu = new bsim::Dk2Nu;
121 
122  fAccumulatedPOT = 0.;
123  fThisFilePOT = 0.;
124 
125 }
void configure(const fhicl::ParameterSet &) override
Interface for configuring the particular algorithm tool.
std::vector< std::string > fFluxFiles
std::vector< std::string > LoadFluxFiles()
IMeVPrtlStage(const char *name)
Definition: IMeVPrtlStage.h:46
evgen::ldm::NuMiKaonGen::~NuMiKaonGen ( )

Destructor.

Definition at line 129 of file NuMiKaonGen_tool.cc.

130 {
131 
132  if (fDk2Nu) delete fDk2Nu;
133 }

Member Function Documentation

void evgen::ldm::NuMiKaonGen::configure ( const fhicl::ParameterSet &  )
overridevirtual

Interface for configuring the particular algorithm tool.

Parameters
ParameterSetThe input set of parameters for configuration

Implements evgen::ldm::IMeVPrtlStage.

Definition at line 136 of file NuMiKaonGen_tool.cc.

137 {
138  fSearchPath = pset.get<std::string>("SearchPath");
139  fSearchPatterns = pset.get<std::vector<std::string>>("FluxFiles");
140  fMaxFluxFileMB = pset.get<unsigned long>("MaxFluxFileMB", 2 * 1024);
141  fFluxCopyMethod = pset.get<std::string>("FluxCopyMethod", "IFDH");
142  fTreeName = pset.get<std::string>("TreeName");
143  fMetaTreeName = pset.get<std::string>("MetaTreeName");
144  fRandomizeFiles = pset.get<bool>("RandomizeFiles");
145 
146  std::cout << "Searching for flux files at path: " << fSearchPath << std::endl;
147  std::cout << "With patterns:\n";
148  for (const std::string &s: fSearchPatterns) std::cout << s << std::endl;
149  std::cout << "With copy method: " << fFluxCopyMethod << std::endl;
150 }
std::vector< std::string > fSearchPatterns
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
BEGIN_PROLOG could also be cout
simb::MCFlux evgen::ldm::NuMiKaonGen::GetNext ( )
overridevirtual

Implements evgen::ldm::IMesonGen.

Definition at line 269 of file NuMiKaonGen_tool.cc.

269  {
270  const bsim::Dk2Nu *flux = GetNextEntry();
271  return MakeMCFlux(*flux);
272 }
const bsim::Dk2Nu * GetNextEntry()
simb::MCFlux MakeMCFlux(const bsim::Dk2Nu &dk2nu)
const bsim::Dk2Nu * evgen::ldm::NuMiKaonGen::GetNextEntry ( )

Definition at line 227 of file NuMiKaonGen_tool.cc.

227  {
228  // new file -- set the start entry
229  if (fNewFile) {
230  // wrap file index around
231  if (fFileIndex >= fFluxFiles.size()) {
232  fFileIndex = 0;
233  }
234  // if (fFileIndex >= fFluxFiles.size()) {
235  // throw cet::exception("FluxReader Out of Files",
236  // "At file index (" + std::to_string(fFileIndex) + ") of available files (" + std::to_string(fFluxFiles.size()) + ").");
237  // }
238 
239  std::cout << "New file: " << fFluxFiles[fFileIndex] << " at index: " << fFileIndex << " of: " << fFluxFiles.size() << std::endl;
240  if (fFluxFile) delete fFluxFile;
241  fFluxFile = new TFile(fFluxFiles[fFileIndex].c_str());
242  fFluxTree = (TTree*)fFluxFile->Get(fTreeName.c_str());
243  fFluxTree->SetBranchAddress("dk2nu",&fDk2Nu);
244 
245  // Start at a random index in this file
246  fEntryStart = CLHEP::RandFlat::shootInt(fEngine, fFluxTree->GetEntries()-1);
248 
249  // load the POT in this file
250  fThisFilePOT = LoadPOT();
251  fNewFile = false;
252  }
253  else {
254  fEntry = (fEntry + 1) % fFluxTree->GetEntries();
255  // if this is the last entry, get ready for the next file
256  if ((fEntry + 1) % fFluxTree->GetEntries() == fEntryStart) {
257  fFileIndex ++;
258  fNewFile = true;
259  }
260  }
261 
262  // count the POT
263  fAccumulatedPOT += fThisFilePOT / fFluxTree->GetEntries();
264 
265  fFluxTree->GetEntry(fEntry);
266  return fDk2Nu;
267 }
CLHEP::HepRandomEngine * fEngine
Definition: IMeVPrtlStage.h:79
std::vector< std::string > fFluxFiles
BEGIN_PROLOG could also be cout
double evgen::ldm::NuMiKaonGen::GetPOT ( )
overridevirtual

Implements evgen::ldm::IMesonGen.

Definition at line 221 of file NuMiKaonGen_tool.cc.

221  {
222  double ret = fAccumulatedPOT;
223  fAccumulatedPOT = 0.;
224  return ret;
225 }
std::vector< std::string > evgen::ldm::NuMiKaonGen::LoadFluxFiles ( )

Definition at line 152 of file NuMiKaonGen_tool.cc.

152  {
153  art::ServiceHandle<IFDH> ifdhp;
154 
155  std::vector<std::pair<std::string, long>> allFiles;
156 
157  // find the flux files
158  for (unsigned i = 0; i < fSearchPatterns.size(); i++) {
159  std::vector<std::pair<std::string, long>> thisList = ifdhp->findMatchingFiles(fSearchPath, fSearchPatterns[i]);
160  std::copy (thisList.begin(), thisList.end(), std::back_inserter(allFiles));
161  }
162 
163  // first randomize the flux files
164  std::vector<unsigned long> order(allFiles.size(), 0);
165  if (fRandomizeFiles) {
166  std::vector<double> rand(allFiles.size(), 0.);
167  CLHEP::RandFlat::shootArray(fEngine, rand.size(), &rand[0]);
168  TMath::Sort(allFiles.size(), &rand[0], &order[0], false);
169  }
170  else {
171  for (unsigned i = 0; i < order.size(); i++) {
172  order[i] = i;
173  }
174  }
175 
176  // If we are directly accessing the files, no need to copy
177  if (fFluxCopyMethod == "DIRECT") {
178  std::cout << "DIRECTLY ACCESSING FLUX FILES.\n";
179  std::vector<std::string> files(allFiles.size());
180  for (unsigned i = 0; i < order.size(); i++) {
181  files[i] = allFiles[order[i]].first;
182  }
183  return files;
184  }
185 
186  // copy over up to the provided limit
187  std::vector<std::pair<std::string, long>> selected;
188  unsigned long totalBytes = 0;
189  unsigned ind = 0;
190  while (totalBytes < (fMaxFluxFileMB * 1024 * 1024) && ind < allFiles.size()) {
191  selected.push_back(allFiles[order[ind]]);
192  totalBytes += allFiles[order[ind]].second;
193  ind ++;
194  }
195 
196  // copy the files locally
197  std::vector<std::pair<std::string, long>> localFiles = ifdhp->fetchSharedFiles(selected, fFluxCopyMethod);
198 
199  std::vector<std::string> files(localFiles.size());
200  for (unsigned i = 0; i < localFiles.size(); i++) {
201  files[i] = localFiles[i].first;
202  }
203 
204  return files;
205 }
CLHEP::HepRandomEngine * fEngine
Definition: IMeVPrtlStage.h:79
std::vector< std::string > fSearchPatterns
T copy(T const &v)
BEGIN_PROLOG could also be cout
double evgen::ldm::NuMiKaonGen::LoadPOT ( )

Definition at line 207 of file NuMiKaonGen_tool.cc.

207  {
208  TTreeReader metaReader(fMetaTreeName.c_str(), fFluxFile);
209  TTreeReaderValue<double> pot(metaReader, "pots");
210 
211  double total_pot = 0.;
212 
213  while (metaReader.Next()) {
214  total_pot += *pot;
215  }
216 
217  return total_pot;
218 }
simb::MCFlux evgen::ldm::NuMiKaonGen::MakeMCFlux ( const bsim::Dk2Nu &  dk2nu)

Definition at line 274 of file NuMiKaonGen_tool.cc.

274  {
275  simb::MCFlux flux;
276 
277  flux.fFluxType = simb::kDk2Nu;
278  flux.fntype = dk2nu.decay.ntype;
279  flux.fnimpwt = dk2nu.decay.nimpwt;
280  flux.fvx = dk2nu.decay.vx;
281  flux.fvy = dk2nu.decay.vy;
282  flux.fvz = dk2nu.decay.vz;
283  flux.fpdpx = dk2nu.decay.pdpx;
284  flux.fpdpy = dk2nu.decay.pdpy;
285  flux.fpdpz = dk2nu.decay.pdpz;
286  flux.fppdxdz = dk2nu.decay.ppdxdz;
287  flux.fppdydz = dk2nu.decay.ppdydz;
288  flux.fpppz = dk2nu.decay.pppz;
289  flux.fppenergy = dk2nu.decay.ppenergy;
290  flux.fppmedium = dk2nu.decay.ppmedium;
291  flux.fptype = dk2nu.decay.ptype;
292  flux.fndecay = dk2nu.decay.ndecay;
293  flux.fmuparpx = dk2nu.decay.muparpx;
294  flux.fmuparpy = dk2nu.decay.muparpy;
295  flux.fmuparpz = dk2nu.decay.muparpz;
296  flux.fmupare = dk2nu.decay.mupare;
297  flux.fnecm = dk2nu.decay.necm;
298 
299  flux.fppvx = dk2nu.ppvx;
300  flux.fppvy = dk2nu.ppvy;
301  flux.fppvz = dk2nu.ppvz;
302 
303  flux.ftvx = dk2nu.tgtexit.tvx;
304  flux.ftvy = dk2nu.tgtexit.tvy;
305  flux.ftvz = dk2nu.tgtexit.tvz;
306  flux.ftpx = dk2nu.tgtexit.tpx;
307  flux.ftpy = dk2nu.tgtexit.tpy;
308  flux.ftpz = dk2nu.tgtexit.tpz;
309  flux.ftptype = dk2nu.tgtexit.tptype;
310  flux.ftgen = dk2nu.tgtexit.tgen;
311 
312  flux.frun = dk2nu.job;
313  flux.fevtno = dk2nu.potnum;
314  flux.ftgptype = dk2nu.ancestor[1].pdg;
315 
316  // flux.fnenergyn = flux.fnenergyf = enu;
317  // flux.fnwtnear = flux.fnwtfar = wgt;
318  // ignore variables dealing with the neutrino
319  flux.fnenergyn = -1;
320  flux.fnwtnear = flux.fnwtfar = -1;
321  flux.fdk2gen = -1;
322 
323  // placeholder for time
324  flux.fxpoint = dk2nu.ancestor.back().startt;
325 
326  return flux;
327 }
double evgen::ldm::NuMiKaonGen::MaxWeight ( )
inlineoverridevirtual

Implements evgen::ldm::IMeVPrtlStage.

Definition at line 72 of file NuMiKaonGen_tool.cc.

72 { return -1.; }

Member Data Documentation

double evgen::ldm::NuMiKaonGen::fAccumulatedPOT
private

Definition at line 100 of file NuMiKaonGen_tool.cc.

bsim::Dk2Nu* evgen::ldm::NuMiKaonGen::fDk2Nu
private

Definition at line 97 of file NuMiKaonGen_tool.cc.

unsigned evgen::ldm::NuMiKaonGen::fEntry
private

Definition at line 91 of file NuMiKaonGen_tool.cc.

unsigned evgen::ldm::NuMiKaonGen::fEntryStart
private

Definition at line 92 of file NuMiKaonGen_tool.cc.

unsigned evgen::ldm::NuMiKaonGen::fFileIndex
private

Definition at line 86 of file NuMiKaonGen_tool.cc.

std::string evgen::ldm::NuMiKaonGen::fFluxCopyMethod
private

Definition at line 79 of file NuMiKaonGen_tool.cc.

TFile* evgen::ldm::NuMiKaonGen::fFluxFile
private

Definition at line 96 of file NuMiKaonGen_tool.cc.

std::vector<std::string> evgen::ldm::NuMiKaonGen::fFluxFiles
private

Definition at line 88 of file NuMiKaonGen_tool.cc.

TTree* evgen::ldm::NuMiKaonGen::fFluxTree
private

Definition at line 95 of file NuMiKaonGen_tool.cc.

unsigned long evgen::ldm::NuMiKaonGen::fMaxFluxFileMB
private

Definition at line 78 of file NuMiKaonGen_tool.cc.

std::string evgen::ldm::NuMiKaonGen::fMetaTreeName
private

Definition at line 83 of file NuMiKaonGen_tool.cc.

bool evgen::ldm::NuMiKaonGen::fNewFile
private

Definition at line 87 of file NuMiKaonGen_tool.cc.

bool evgen::ldm::NuMiKaonGen::fRandomizeFiles
private

Definition at line 80 of file NuMiKaonGen_tool.cc.

std::string evgen::ldm::NuMiKaonGen::fSearchPath
private

Definition at line 76 of file NuMiKaonGen_tool.cc.

std::vector<std::string> evgen::ldm::NuMiKaonGen::fSearchPatterns
private

Definition at line 77 of file NuMiKaonGen_tool.cc.

double evgen::ldm::NuMiKaonGen::fThisFilePOT
private

Definition at line 101 of file NuMiKaonGen_tool.cc.

std::string evgen::ldm::NuMiKaonGen::fTreeName
private

Definition at line 82 of file NuMiKaonGen_tool.cc.


The documentation for this class was generated from the following file: