LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
fluxr::PPFXFluxReader Class Reference

#include "PPFXFluxReader.h"

Public Member Functions

 PPFXFluxReader (fhicl::ParameterSet const &pset, art::ProductRegistryHelper &helper, art::SourceHelper const &pm)
 
void closeCurrentFile ()
 
void readFile (std::string const &name, art::FileBlock *&fb)
 
bool readNext (art::RunPrincipal *const &inR, art::SubRunPrincipal *const &inSR, art::RunPrincipal *&outR, art::SubRunPrincipal *&outSR, art::EventPrincipal *&outE)
 

Private Attributes

art::SourceHelper const & fSourceHelper
 
art::SubRunID fSubRunID
 
uint32_t fEventCounter
 
uint32_t fEntry
 
int fMaxEvents
 
uint32_t fSkipEvents
 
std::string fInputType
 
float fPOT
 
FluxInterfacefFluxDriver
 
TFile * fFluxInputFile
 
TH1D * fHFlux [4]
 
TH1D * fHFluxParent [4][4]
 
TH1D * fHFluxSec [4][5]
 
fhicl::ParameterSet fConfigPS
 
art::TypeLabel fTLmctruth
 
art::TypeLabel fTLmcflux
 
art::TypeLabel fTLdk2nu
 
art::TypeLabel fTLnuchoice
 

Detailed Description

Definition at line 18 of file PPFXFluxReader.h.

Constructor & Destructor Documentation

fluxr::PPFXFluxReader::PPFXFluxReader ( fhicl::ParameterSet const &  pset,
art::ProductRegistryHelper helper,
art::SourceHelper const &  pm 
)

Definition at line 39 of file PPFXFluxReader.cxx.

References fConfigPS, fEntry, fEventCounter, fHFlux, fHFluxParent, fHFluxSec, fInputType, fMaxEvents, fTLdk2nu, fTLmcflux, fTLmctruth, fTLnuchoice, art::ServiceHandle< T, SCOPE >::get(), fhicl::ParameterSet::get(), art::InEvent, art::InSubRun, and art::ProductRegistryHelper::reconstitutes().

42  : fSourceHelper(pm)
43  , fSubRunID()
44  , fInputType(ps.get<std::string>("inputType"))
45  , fTLmctruth{helper.reconstitutes<std::vector<simb::MCTruth>, art::InEvent>("flux")}
46  , fTLmcflux{helper.reconstitutes<std::vector<simb::MCFlux>, art::InEvent>("flux")}
47  , fTLdk2nu{fInputType == "dk2nu" ?
48  helper.reconstitutes<std::vector<bsim::Dk2Nu>, art::InEvent>("flux") :
49  fTLmctruth}
50  , fTLnuchoice{fInputType == "dk2nu" ?
51  helper.reconstitutes<std::vector<bsim::NuChoice>, art::InEvent>("flux") :
52  fTLmctruth}
53  {
55 
56  if (fInputType == "dk2nu") {
60 
61  fConfigPS = ps.get<fhicl::ParameterSet>(ps.get<std::string>("dk2nuConfig"));
62  }
63 
65  //initialize beam histograms specified in fhicl file
66  art::TFileDirectory tffluxdir = tfs->mkdir("Flux");
67  string nutype[] = {"nue", "nuebar", "numu", "numubar"};
68  string nultx[] = {"#nu_{e}", "#bar{#nu}_{e}", "#nu_{#mu}", "#bar{#nu}_{#mu}"};
69  string pltx[] = {"#mu^{#pm}", "#pi^{#pm}", "K^{0}_{L}", "K^{#pm}"};
70  string secltx[] = {"pBe->#pi^{#pm}->...->#mu^{#pm}",
71  "pBe->#pi^{#pm}->..(not #mu^{#pm})..",
72  "pBe->K^{0}_{L}->...",
73  "pBe->K^{#pm}->...",
74  "pBe->(p or n)->..."};
75 
76  int nbins = ps.get<int>("nBins", 0);
77  int Elow = ps.get<float>("Elow", 0);
78  int Ehigh = ps.get<float>("Ehigh", 0);
79 
80  for (int i = 0; i < 4; i++) {
81  fHFlux[i] = tffluxdir.make<TH1D>(Form("h50%i", i + 1),
82  Form("%s (all);Energy %s (GeV);#phi(%s)/50MeV/POT",
83  nultx[i].c_str(),
84  nultx[i].c_str(),
85  nultx[i].c_str()),
86  nbins,
87  Elow,
88  Ehigh);
89  fHFlux[i]->Sumw2();
90  }
91 
92  for (int inu = 0; inu < 4; inu++) {
93  for (int ipar = 0; ipar < 4; ipar++) {
94  fHFluxParent[inu][ipar] =
95  tffluxdir.make<TH1D>(Form("h5%i%i", ipar + 1, inu + 1),
96  Form("...->%s->%s;Energy %s (GeV);#phi(%s)/50MeV/POT",
97  pltx[ipar].c_str(),
98  nultx[inu].c_str(),
99  nultx[inu].c_str(),
100  nultx[inu].c_str()),
101  nbins,
102  Elow,
103  Ehigh);
104 
105  fHFluxParent[inu][ipar]->Sumw2();
106  }
107  for (int isec = 0; isec < 5; isec++) {
108  fHFluxSec[inu][isec] =
109  tffluxdir.make<TH1D>(Form("h7%i%i", isec + 1, inu + 1),
110  Form("%s->%s;Energy %s (GeV);#phi(%s)/50MeV/POT",
111  secltx[isec].c_str(),
112  nultx[inu].c_str(),
113  nultx[inu].c_str(),
114  nultx[inu].c_str()),
115  nbins,
116  Elow,
117  Ehigh);
118  fHFluxSec[inu][isec]->Sumw2();
119  }
120  }
121 
122  fEventCounter = 0;
123  fEntry = ps.get<uint32_t>("skipEvents", 0);
124  fMaxEvents = ps.get<int>("maxEvents", -1);
125  }
fhicl::ParameterSet fConfigPS
art::TypeLabel fTLdk2nu
T * get() const
Definition: ServiceHandle.h:69
art::TypeLabel fTLmcflux
TH1D * fHFluxParent[4][4]
TypeLabel const & reconstitutes(std::string const &modLabel, std::string const &instanceName={})
T get(std::string const &key) const
Definition: ParameterSet.h:314
art::SourceHelper const & fSourceHelper
art::TypeLabel fTLnuchoice
TH1D * fHFluxSec[4][5]
art::SubRunID fSubRunID
art::TypeLabel fTLmctruth

Member Function Documentation

void fluxr::PPFXFluxReader::closeCurrentFile ( )

Definition at line 127 of file PPFXFluxReader.cxx.

References fEntry, fEventCounter, fFluxInputFile, art::SubRunID::flushSubRun(), fSkipEvents, and fSubRunID.

128  {
130  fEventCounter = 0;
131  fFluxInputFile->Close();
132  delete fFluxInputFile;
133  fSkipEvents = 0; //if crossing file boundary don't skip events in next file
134  fEntry = 0;
135  }
static constexpr SubRunID flushSubRun() noexcept
Definition: SubRunID.h:171
art::SubRunID fSubRunID
void fluxr::PPFXFluxReader::readFile ( std::string const &  name,
art::FileBlock *&  fb 
)

Definition at line 137 of file PPFXFluxReader.cxx.

References fConfigPS, fFluxDriver, fFluxInputFile, fInputType, fPOT, fluxr::FluxInterface::GetEntries(), fluxr::FluxInterface::GetPOT(), and fluxr::FluxInterface::GetRun().

138  {
139  // Fill and return a new Fileblock.
140  fb = new art::FileBlock(art::FileFormatVersion(1, "PPFXFluxReader"), name);
141 
142  fFluxInputFile = new TFile(name.c_str());
143  if (fFluxInputFile->IsZombie()) {
144  //throw cet::exception(__PRETTY_FUNCTION__) << "Failed to open "<<fFluxInputFile<<std::endl;
145  }
146 
147  if (fInputType == "gsimple") {
148  fFluxDriver = new GSimpleInterface();
149  ((GSimpleInterface*)fFluxDriver)->SetRootFile(fFluxInputFile);
150  }
151  else if (fInputType == "dk2nu") {
152  fFluxDriver = new DK2NuInterface();
153  ((DK2NuInterface*)fFluxDriver)->SetRootFile(fFluxInputFile);
154  ((DK2NuInterface*)fFluxDriver)->Init(fConfigPS);
155  }
156  else {
157  throw cet::exception(__PRETTY_FUNCTION__)
158  << "Ntuple format " << fInputType << " not supported" << std::endl;
159  }
160 
161  std::cout << "File has " << fFluxDriver->GetEntries() << " entries" << std::endl;
162  std::cout << "POT = " << fFluxDriver->GetPOT() << std::endl;
163  std::cout << "Run = " << fFluxDriver->GetRun() << std::endl;
164  fPOT += fFluxDriver->GetPOT();
165  }
fhicl::ParameterSet fConfigPS
virtual Long64_t GetEntries() const =0
virtual float GetPOT() const =0
virtual int GetRun() const =0
FluxInterface * fFluxDriver
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
bool fluxr::PPFXFluxReader::readNext ( art::RunPrincipal *const &  inR,
art::SubRunPrincipal *const &  inSR,
art::RunPrincipal *&  outR,
art::SubRunPrincipal *&  outSR,
art::EventPrincipal *&  outE 
)

Definition at line 167 of file PPFXFluxReader.cxx.

References simb::MCTruth::Add(), simb::MCParticle::AddTrajectoryPoint(), fEntry, fEventCounter, fFluxDriver, fHFlux, fHFluxParent, fHFluxSec, fluxr::FluxInterface::FillMCFlux(), fInputType, fMaxEvents, simb::MCFlux::fnenergyn, simb::MCFlux::fnimpwt, simb::MCFlux::fntype, simb::MCFlux::fnwtnear, fPOT, simb::MCFlux::fptype, fSourceHelper, fSubRunID, fTLdk2nu, fTLmcflux, fTLmctruth, fTLnuchoice, simb::MCFlux::ftptype, fluxr::FluxInterface::GetNuMomentum(), fluxr::FluxInterface::GetNuPosition(), fluxr::FluxInterface::GetRun(), art::SourceHelper::makeEventPrincipal(), art::SourceHelper::makePtr(), art::SourceHelper::makeRunPrincipal(), art::SourceHelper::makeSubRunPrincipal(), art::put_product_in_principal(), art::SubRunID::run(), art::SubRunID::runID(), simb::MCTruth::SetNeutrino(), art::SubRunID::subRun(), sumdata::POTSummary::totgoodpot, and sumdata::POTSummary::totpot.

172  {
173  if (fMaxEvents > 0 && fEventCounter == unsigned(fMaxEvents)) return false;
174 
175  // Create empty result, then fill it from current file:
176  std::unique_ptr<std::vector<simb::MCFlux>> mcfluxvec(new std::vector<simb::MCFlux>);
177  std::unique_ptr<std::vector<simb::MCTruth>> mctruthvec(new std::vector<simb::MCTruth>);
178 
179  std::unique_ptr<std::vector<bsim::Dk2Nu>> dk2nuvec(new std::vector<bsim::Dk2Nu>);
180  std::unique_ptr<std::vector<bsim::NuChoice>> nuchoicevec(new std::vector<bsim::NuChoice>);
181  std::unique_ptr<art::Assns<simb::MCTruth, bsim::Dk2Nu>> dk2nuassn(
183  std::unique_ptr<art::Assns<simb::MCTruth, bsim::NuChoice>> nuchoiceassn(
185  std::unique_ptr<art::Assns<simb::MCTruth, simb::MCFlux>> mcfluxassn(
187 
188  simb::MCFlux flux;
189  if (!fFluxDriver->FillMCFlux(fEntry, flux)) return false;
190 
191  //fake mctruth product to cheat eventweight that gets neutrino energy from it
192  simb::MCTruth mctruth;
193  simb::MCParticle mcpnu(0, flux.fntype, "Flux");
194  mcpnu.AddTrajectoryPoint(fFluxDriver->GetNuPosition(), fFluxDriver->GetNuMomentum());
195  mctruth.Add(mcpnu);
196  mctruth.SetNeutrino(0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
197  mctruthvec->push_back(mctruth);
198 
199  if (fInputType == "dk2nu") {
200  dk2nuvec->push_back(*((DK2NuInterface*)fFluxDriver)->GetDk2Nu());
201  nuchoicevec->push_back(*((DK2NuInterface*)fFluxDriver)->GetNuChoice());
202  }
203 
204  int ipdg = 0;
205  //select index matching order in nutype defined in constructor
206  if (flux.fntype == 12)
207  ipdg = 0;
208  else if (flux.fntype == -12)
209  ipdg = 1;
210  else if (flux.fntype == 14)
211  ipdg = 2;
212  else if (flux.fntype == -14)
213  ipdg = 3;
214 
215  double enu = flux.fnenergyn;
216  double totwgh = flux.fnwtnear * flux.fnimpwt / fPOT;
217  if (totwgh < 0 || totwgh > 100) {
218  std::cout << " Bad weight " << totwgh << std::endl;
219  totwgh = 0;
220  }
221  if (fInputType == "gsimple") totwgh = 1. / fPOT; //for gsimple files weight is actually 1
222 
223  fHFlux[ipdg]->Fill(enu, totwgh);
224 
225  if (flux.fptype == 13 || flux.fptype == -13) //mu+-
226  fHFluxParent[ipdg][0]->Fill(enu, totwgh);
227  else if (flux.fptype == 211 || flux.fptype == -211) //pi+-
228  fHFluxParent[ipdg][1]->Fill(enu, totwgh);
229  else if (flux.fptype == 130) //K0L
230  fHFluxParent[ipdg][2]->Fill(enu, totwgh);
231  else if (flux.fptype == 321 || flux.fptype == -321) //K+-
232  fHFluxParent[ipdg][3]->Fill(enu, totwgh);
233 
234  if (fabs(flux.ftptype == 211) && fabs(flux.fptype) == 13)
235  fHFluxSec[ipdg][0]->Fill(enu, totwgh);
236  else if (fabs(flux.ftptype) == 211)
237  fHFluxSec[ipdg][1]->Fill(enu, totwgh);
238  else if (fabs(flux.ftptype) == 130)
239  fHFluxSec[ipdg][2]->Fill(enu, totwgh);
240  else if (fabs(flux.ftptype) == 321)
241  fHFluxSec[ipdg][3]->Fill(enu, totwgh);
242  else if (flux.ftptype == 2212 || flux.ftptype == 2112)
243  fHFluxSec[ipdg][4]->Fill(enu, totwgh);
244 
245  mcfluxvec->push_back(flux);
246  fEventCounter++;
247  fEntry++;
248 
249  art::RunNumber_t rn;
250  if (fFluxDriver->GetRun() > 0) { rn = fFluxDriver->GetRun(); }
251  else {
252  rn = 999999;
253  }
254  art::Timestamp tstamp(time(0));
255 
256  art::SubRunID newID(rn, 0); //subrun not used in flux files, so set to 0
257  if (fSubRunID.runID() != newID.runID()) { // New Run
258  outR = fSourceHelper.makeRunPrincipal(rn, tstamp);
259  mf::LogInfo(__FUNCTION__) << "Cached run number (" << fSubRunID.run()
260  << ") does not match current run number (" << newID.run()
261  << ")! Reassigning variable...." << std::endl;
262  }
263  if (fSubRunID != newID) { // New SubRun
264  mf::LogInfo(__FUNCTION__) << "Cached subrun number (" << fSubRunID.subRun()
265  << ") does not match current subrun number (" << newID.subRun()
266  << ")! Reassigning variable...." << std::endl;
267  outSR = fSourceHelper.makeSubRunPrincipal(rn, 0, tstamp);
268  std::unique_ptr<sumdata::POTSummary> pot(new sumdata::POTSummary);
269  pot->totpot = fPOT;
270  pot->totgoodpot = fPOT;
271 
272  art::put_product_in_principal(std::move(pot), *outSR, "flux");
273 
274  fSubRunID = newID;
275  }
276 
277  outE =
279 
280  // Put products in the event.
281  art::put_product_in_principal(std::move(mcfluxvec), *outE, "flux");
282  art::put_product_in_principal(std::move(mctruthvec), *outE, "flux");
283  if (fInputType == "dk2nu") {
284  art::put_product_in_principal(std::move(dk2nuvec), *outE, "flux");
285  art::put_product_in_principal(std::move(nuchoicevec), *outE, "flux");
286 
287  auto aptr = fSourceHelper.makePtr<simb::MCTruth>(fTLmctruth, *outE, 0);
288  auto bptr = fSourceHelper.makePtr<bsim::Dk2Nu>(fTLdk2nu, *outE, 0);
289  auto cptr = fSourceHelper.makePtr<bsim::NuChoice>(fTLnuchoice, *outE, 0);
290  auto dptr = fSourceHelper.makePtr<simb::MCFlux>(fTLmcflux, *outE, 0);
291 
292  dk2nuassn->addSingle(aptr, bptr);
293  nuchoiceassn->addSingle(aptr, cptr);
294  mcfluxassn->addSingle(aptr, dptr);
295 
296  art::put_product_in_principal(std::move(dk2nuassn), *outE, "flux");
297  art::put_product_in_principal(std::move(nuchoiceassn), *outE, "flux");
298  art::put_product_in_principal(std::move(mcfluxassn), *outE, "flux");
299  }
300 
301  return true;
302  }
Ptr< T > makePtr(TypeLabel const &t, Principal const &p, typename Ptr< T >::key_type key) const
art::TypeLabel fTLdk2nu
virtual TLorentzVector GetNuPosition() const =0
virtual bool FillMCFlux(Long64_t ientry, simb::MCFlux &mclux)=0
SubRunPrincipal * makeSubRunPrincipal(SubRunAuxiliary subRunAux) const
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
art::TypeLabel fTLmcflux
int ftptype
Definition: MCFlux.h:82
TH1D * fHFluxParent[4][4]
EventPrincipal * makeEventPrincipal(EventAuxiliary eventAux) const
void SetNeutrino(int CCNC, int mode, int interactionType, int target, int nucleon, int quark, double w, double x, double y, double qsqr)
Definition: MCTruth.cxx:30
virtual int GetRun() const =0
RunID const & runID() const
Definition: SubRunID.h:79
double fnwtnear
Definition: MCFlux.h:44
FluxInterface * fFluxDriver
int fptype
Definition: MCFlux.h:63
RunNumber_t run() const
Definition: SubRunID.h:85
art::SourceHelper const & fSourceHelper
art::TypeLabel fTLnuchoice
void Add(simb::MCParticle const &part)
Definition: MCTruth.h:80
RunPrincipal * makeRunPrincipal(RunAuxiliary runAux) const
Definition: SourceHelper.cc:89
std::enable_if_t<!detail::range_sets_supported(P::branch_type)> put_product_in_principal(std::unique_ptr< T > &&product, P &principal, std::string const &module_label, std::string const &instance_name={})
int fntype
Definition: MCFlux.h:51
TH1D * fHFluxSec[4][5]
virtual TLorentzVector GetNuMomentum() const =0
art::SubRunID fSubRunID
art::TypeLabel fTLmctruth
SubRunNumber_t subRun() const
Definition: SubRunID.h:91
Event generator information.
Definition: MCTruth.h:32
double fnenergyn
Definition: MCFlux.h:43
double fnimpwt
Definition: MCFlux.h:72
IDNumber_t< Level::Run > RunNumber_t
Definition: IDNumber.h:120

Member Data Documentation

fhicl::ParameterSet fluxr::PPFXFluxReader::fConfigPS
private

Definition at line 52 of file PPFXFluxReader.h.

Referenced by PPFXFluxReader(), and readFile().

uint32_t fluxr::PPFXFluxReader::fEntry
private

Definition at line 39 of file PPFXFluxReader.h.

Referenced by closeCurrentFile(), PPFXFluxReader(), and readNext().

uint32_t fluxr::PPFXFluxReader::fEventCounter
private

Definition at line 38 of file PPFXFluxReader.h.

Referenced by closeCurrentFile(), PPFXFluxReader(), and readNext().

FluxInterface* fluxr::PPFXFluxReader::fFluxDriver
private

Definition at line 45 of file PPFXFluxReader.h.

Referenced by readFile(), and readNext().

TFile* fluxr::PPFXFluxReader::fFluxInputFile
private

Definition at line 46 of file PPFXFluxReader.h.

Referenced by closeCurrentFile(), and readFile().

TH1D* fluxr::PPFXFluxReader::fHFlux[4]
private

Definition at line 48 of file PPFXFluxReader.h.

Referenced by PPFXFluxReader(), and readNext().

TH1D* fluxr::PPFXFluxReader::fHFluxParent[4][4]
private

Definition at line 49 of file PPFXFluxReader.h.

Referenced by PPFXFluxReader(), and readNext().

TH1D* fluxr::PPFXFluxReader::fHFluxSec[4][5]
private

Definition at line 50 of file PPFXFluxReader.h.

Referenced by PPFXFluxReader(), and readNext().

std::string fluxr::PPFXFluxReader::fInputType
private

Definition at line 42 of file PPFXFluxReader.h.

Referenced by PPFXFluxReader(), readFile(), and readNext().

int fluxr::PPFXFluxReader::fMaxEvents
private

Definition at line 40 of file PPFXFluxReader.h.

Referenced by PPFXFluxReader(), and readNext().

float fluxr::PPFXFluxReader::fPOT
private

Definition at line 43 of file PPFXFluxReader.h.

Referenced by readFile(), and readNext().

uint32_t fluxr::PPFXFluxReader::fSkipEvents
private

Definition at line 41 of file PPFXFluxReader.h.

Referenced by closeCurrentFile().

art::SourceHelper const& fluxr::PPFXFluxReader::fSourceHelper
private

Definition at line 35 of file PPFXFluxReader.h.

Referenced by readNext().

art::SubRunID fluxr::PPFXFluxReader::fSubRunID
private

Definition at line 36 of file PPFXFluxReader.h.

Referenced by closeCurrentFile(), and readNext().

art::TypeLabel fluxr::PPFXFluxReader::fTLdk2nu
private

Definition at line 56 of file PPFXFluxReader.h.

Referenced by PPFXFluxReader(), and readNext().

art::TypeLabel fluxr::PPFXFluxReader::fTLmcflux
private

Definition at line 55 of file PPFXFluxReader.h.

Referenced by PPFXFluxReader(), and readNext().

art::TypeLabel fluxr::PPFXFluxReader::fTLmctruth
private

Definition at line 54 of file PPFXFluxReader.h.

Referenced by PPFXFluxReader(), and readNext().

art::TypeLabel fluxr::PPFXFluxReader::fTLnuchoice
private

Definition at line 57 of file PPFXFluxReader.h.

Referenced by PPFXFluxReader(), and readNext().


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