Public Member Functions | Private Member Functions | Private Attributes | List of all members
cvn::CVNEventDump Class Reference
Inheritance diagram for cvn::CVNEventDump:
art::EDAnalyzer art::detail::Analyzer art::detail::LegacyModule art::Observer art::ModuleBase

Public Member Functions

 CVNEventDump (fhicl::ParameterSet const &pset)
 
 ~CVNEventDump ()
 
void analyze (const art::Event &evt) override
 
void reconfigure (const fhicl::ParameterSet &pset)
 
void beginJob () override
 
void endJob () override
 
- Public Member Functions inherited from art::EDAnalyzer
 EDAnalyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 EDAnalyzer (Table< Config > const &config)
 
std::string workerType () const
 
- Public Member Functions inherited from art::detail::Analyzer
virtual ~Analyzer () noexcept
 
 Analyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 Analyzer (Table< Config > const &config)
 
void doBeginJob (SharedResources const &resources)
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
- Public Member Functions inherited from art::Observer
 ~Observer () noexcept
 
 Observer (Observer const &)=delete
 
 Observer (Observer &&)=delete
 
Observeroperator= (Observer const &)=delete
 
Observeroperator= (Observer &&)=delete
 
void registerProducts (ProductDescriptions &, ModuleDescription const &)
 
void fillDescriptions (ModuleDescription const &)
 
fhicl::ParameterSetID selectorConfig () const
 
- Public Member Functions inherited from art::ModuleBase
virtual ~ModuleBase () noexcept
 
 ModuleBase ()
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

Private Member Functions

void WriteMapTH2 (const art::Event &evt, int slice, const PixelMap &pm)
 Function to extract TH2 from PixelMap and write to TFile. More...
 

Private Attributes

dunemva::MVAAlg fMVAAlg
 
std::string fPixelMapInput
 
std::string fGenieGenModuleLabel
 
std::string fEnergyNueLabel
 
std::string fEnergyNumuLabel
 
std::string fEnergyNutauLabel
 
bool fGetEnergyOutput
 
bool fGetEventWeight
 
bool fWriteMapTH2
 
bool fApplyFidVol
 
bool fUseTopology
 
unsigned int fTopologyHits
 
TrainingDatafTrain
 
TTree * fTrainTree
 

Additional Inherited Members

- Public Types inherited from art::EDAnalyzer
using WorkerType = WorkerT< EDAnalyzer >
 
using ModuleType = EDAnalyzer
 
- Protected Member Functions inherited from art::Observer
std::string const & processName () const
 
bool wantAllEvents () const noexcept
 
bool wantEvent (ScheduleID id, Event const &e) const
 
Handle< TriggerResultsgetTriggerResults (Event const &e) const
 
 Observer (fhicl::ParameterSet const &config)
 
 Observer (std::vector< std::string > const &select_paths, std::vector< std::string > const &reject_paths, fhicl::ParameterSet const &config)
 
- Protected Member Functions inherited from art::ModuleBase
ConsumesCollectorconsumesCollector ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 

Detailed Description

Definition at line 44 of file CVNEventDump_module.cc.

Constructor & Destructor Documentation

cvn::CVNEventDump::CVNEventDump ( fhicl::ParameterSet const &  pset)
explicit

Definition at line 81 of file CVNEventDump_module.cc.

82  : EDAnalyzer(pset),
83  fMVAAlg(pset.get<fhicl::ParameterSet>("MVAAlg"))
84  {
85  this->reconfigure(pset);
86  }
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
dunemva::MVAAlg fMVAAlg
void reconfigure(const fhicl::ParameterSet &pset)
cvn::CVNEventDump::~CVNEventDump ( )

Definition at line 89 of file CVNEventDump_module.cc.

90  { }

Member Function Documentation

void cvn::CVNEventDump::analyze ( const art::Event evt)
override

Definition at line 128 of file CVNEventDump_module.cc.

129  {
130 
131  // Get the pixel maps
132  std::vector< art::Ptr< cvn::PixelMap > > pixelmaplist;
134  auto pixelmapListHandle = evt.getHandle< std::vector< cvn::PixelMap > >(itag1);
135  if (pixelmapListHandle)
136  art::fill_ptr_vector(pixelmaplist, pixelmapListHandle);
137 
138  // If we have no pixel map then return
139  if(pixelmaplist.size() == 0) return;
140 
142 
143  // * monte carlo
144  std::vector<art::Ptr<simb::MCTruth> > mclist;
145  auto mctruthListHandle = evt.getHandle< std::vector<simb::MCTruth> >(fGenieGenModuleLabel);
146  if (mctruthListHandle)
147  art::fill_ptr_vector(mclist, mctruthListHandle);
148 
149  //unsigned short nmclist= mclist.size();
150 
151  //std::cout<<"mctruth: "<<nmclist<<std::endl;
152 
153  art::Ptr<simb::MCTruth> truth = mclist[0];
154  simb::MCNeutrino truthN=truth->GetNeutrino();
155  //truth = mclist[0];
156 
157  AssignLabels labels;
158 
159  interaction = labels.GetInteractionType(truthN);
160  if(fUseTopology){
161  labels.GetTopology(truth,fTopologyHits);
162 // labels.PrintTopology();
163  }
164  float nuEnergy = 0;
165  float lepEnergy = 0;
166 // if(truth.NeutrinoSet()){
167  nuEnergy = truthN.Nu().E();
168  lepEnergy = truthN.Lepton().E();
169 // }
170 
171  // If outside the fiducial volume don't waste any time filling other variables
172  if(fApplyFidVol){
173  // Get the interaction vertex from the end point of the neutrino. This is
174  // because the start point of the lepton doesn't make sense for taus as they
175  // are decayed by the generator and not GEANT
176  TVector3 vtx = truthN.Nu().EndPosition().Vect();
177  bool isFid = (fabs(vtx.X())<310 && fabs(vtx.Y())<550 && vtx.Z()>50 && vtx.Z()<1244);
178  if(!isFid) return;
179  }
180 
181  float recoNueEnergy = 0.;
182  float recoNumuEnergy = 0.;
183  float recoNutauEnergy = 0.;
184  // Should we use the EnergyReco_module reconstructed energies?
185  if(fGetEnergyOutput){
186  // Get the nue info
187  if(fEnergyNueLabel != ""){
188  auto energyRecoNueHandle = evt.getHandle<dune::EnergyRecoOutput>(fEnergyNueLabel);
189  recoNueEnergy = energyRecoNueHandle->fNuLorentzVector.E();
190  }
191  // And the numu
192  if(fEnergyNumuLabel != ""){
193  auto energyRecoNumuHandle = evt.getHandle<dune::EnergyRecoOutput>(fEnergyNumuLabel);
194  recoNumuEnergy = energyRecoNumuHandle->fNuLorentzVector.E();
195  }
196  // And the nutau
197  if(fEnergyNutauLabel != ""){
198  auto energyRecoNutauHandle = evt.getHandle<dune::EnergyRecoOutput>(fEnergyNutauLabel);
199  recoNutauEnergy = energyRecoNutauHandle->fNuLorentzVector.E();
200  }
201  }
202 
203  // If we don't want to get the event weight then leave it as 1.0.
204  double eventWeight = 1.;
205  if(fGetEventWeight){
206  double mvaResult = 0.; // We don't care about this, but need it for the call
207  fMVAAlg.Run(evt,mvaResult,eventWeight);
208  }
209 
210  // Create the training data and add it to the tree
211  TrainingData train(interaction, nuEnergy, lepEnergy, recoNueEnergy,
212  recoNumuEnergy, recoNutauEnergy, eventWeight, *pixelmaplist[0]);
213  // Set the topology information
214  int topPDG = labels.GetPDG();
215  int nprot = labels.GetNProtons();
216  int npion = labels.GetNPions();
217  int npi0 = labels.GetNPizeros();
218  int nneut = labels.GetNNeutrons();
219  int toptype = labels.GetTopologyType();
220  int toptypealt = labels.GetTopologyTypeAlt();
221  if(fUseTopology){
222  train.SetTopologyInformation(topPDG, nprot, npion, npi0, nneut, toptype, toptypealt);
223  }
224  fTrain = &train;
225  fTrainTree->Fill();
226 
227  // Make a plot of the pixel map if required
228  if (fWriteMapTH2) WriteMapTH2(evt, 0, train.fPMap);
229 
230  }
double E(const int i=0) const
Definition: MCParticle.h:233
const simb::MCNeutrino & GetNeutrino() const
Definition: MCTruth.h:77
const TLorentzVector & EndPosition() const
Definition: MCParticle.h:225
unsigned int fTopologyHits
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
const simb::MCParticle & Nu() const
Definition: MCNeutrino.h:146
void WriteMapTH2(const art::Event &evt, int slice, const PixelMap &pm)
Function to extract TH2 from PixelMap and write to TFile.
enum cvn::Interaction InteractionType
void Run(const art::Event &evt, std::vector< double > &result, double &wgt)
def train(model, train_files, valid_files, maskpatterns, epochs, batchsize, info)
Definition: train.py:16
const simb::MCParticle & Lepton() const
Definition: MCNeutrino.h:147
Definition: train.py:1
std::string fEnergyNumuLabel
dunemva::MVAAlg fMVAAlg
std::string fGenieGenModuleLabel
Something else. Tau? Hopefully we don&#39;t use this.
std::string fEnergyNutauLabel
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:297
Event generator information.
Definition: MCNeutrino.h:18
void cvn::CVNEventDump::beginJob ( )
overridevirtual

Reimplemented from art::EDAnalyzer.

Definition at line 109 of file CVNEventDump_module.cc.

110  {
111 
112 
114 
115  fTrainTree = tfs->make<TTree>("CVNTrainTree", "Training records");
116  fTrainTree->Branch("train", "cvn::TrainingData", &fTrain);
117 
118 
119  }
void cvn::CVNEventDump::endJob ( )
overridevirtual

Reimplemented from art::EDAnalyzer.

Definition at line 122 of file CVNEventDump_module.cc.

123  {
124 
125  }
void cvn::CVNEventDump::reconfigure ( const fhicl::ParameterSet pset)

Definition at line 93 of file CVNEventDump_module.cc.

94  {
95  fPixelMapInput = pset.get<std::string>("PixelMapInput");
96  fGenieGenModuleLabel = pset.get<std::string>("GenieGenModuleLabel");
97  fWriteMapTH2 = pset.get<bool> ("WriteMapTH2");
98  fApplyFidVol = pset.get<bool>("ApplyFidVol");
99  fEnergyNueLabel = pset.get<std::string> ("EnergyNueLabel");
100  fEnergyNumuLabel = pset.get<std::string> ("EnergyNumuLabel");
101  fEnergyNutauLabel = pset.get<std::string> ("EnergyNutauLabel");
102  fGetEnergyOutput = pset.get<bool> ("GetEnergyOutput");
103  fGetEventWeight = pset.get<bool> ("GetEventWeight");
104  fUseTopology = pset.get<bool>("UseTopology");
105  fTopologyHits = pset.get<unsigned int>("TopologyHitsCut");
106  }
unsigned int fTopologyHits
std::string string
Definition: nybbler.cc:12
T get(std::string const &key) const
Definition: ParameterSet.h:271
std::string fEnergyNumuLabel
std::string fGenieGenModuleLabel
std::string fEnergyNutauLabel
void cvn::CVNEventDump::WriteMapTH2 ( const art::Event evt,
int  slice,
const PixelMap pm 
)
private

Function to extract TH2 from PixelMap and write to TFile.

Definition at line 236 of file CVNEventDump_module.cc.

237  {
238  std::stringstream name;
239  name << "PixelMap_r" << evt.run() << "_s" << evt.subRun()<< "_e" << evt.event() << "_sl" << slice;
240  std::stringstream nameL;
241  nameL << "PixelTruthMap_r" << evt.run() << "_s" << evt.subRun()<< "_e" << evt.event() << "_sl" << slice;
242  std::stringstream nameX;
243  nameX << "PixelMap_X_r" << evt.run() << "_s" << evt.subRun()<< "_e" << evt.event() << "_sl" << slice;
244  std::stringstream nameY;
245  nameY << "PixelMap_Y_r" << evt.run() << "_s" << evt.subRun()<< "_e" << evt.event() << "_sl" << slice;
246  std::stringstream nameZ;
247  nameZ << "PixelMap_Z_r" << evt.run() << "_s" << evt.subRun()<< "_e" << evt.event() << "_sl" << slice;
248  TH2F* hist = pm.ToTH2();
249  TH2F* histL = pm.ToLabTH2();
250  TH2F* histX = pm.SingleViewToTH2(0);
251  TH2F* histY = pm.SingleViewToTH2(1);
252  TH2F* histZ = pm.SingleViewToTH2(2);
253  hist->SetName(name.str().c_str());
254  histL->SetName(nameL.str().c_str());
255  histX->SetName(nameX.str().c_str());
256  histY->SetName(nameY.str().c_str());
257  histZ->SetName(nameZ.str().c_str());
258 
260 
261  TH2F* histWrite = tfs->make<TH2F>(*hist);
262  histWrite->Write();
263  TH2F* histWriteL = tfs->make<TH2F>(*histL);
264  histWriteL->GetZaxis()->SetRangeUser(0,10);
265  histWriteL->Write();
266  TH2F* histWriteX = tfs->make<TH2F>(*histX);
267  histWriteX->Write();
268  TH2F* histWriteY = tfs->make<TH2F>(*histY);
269  histWriteY->Write();
270  TH2F* histWriteZ = tfs->make<TH2F>(*histZ);
271  histWriteZ->Write();
272 
273  delete hist;
274  delete histWrite;
275  delete histL;
276  delete histWriteL;
277  delete histX;
278  delete histWriteX;
279  delete histY;
280  delete histWriteY;
281  delete histZ;
282  delete histWriteZ;
283 
284  }
static QCString name
Definition: declinfo.cpp:673
EventNumber_t event() const
Definition: DataViewImpl.cc:85
SubRunNumber_t subRun() const
Definition: DataViewImpl.cc:78
RunNumber_t run() const
Definition: DataViewImpl.cc:71

Member Data Documentation

bool cvn::CVNEventDump::fApplyFidVol
private

Definition at line 67 of file CVNEventDump_module.cc.

std::string cvn::CVNEventDump::fEnergyNueLabel
private

Definition at line 61 of file CVNEventDump_module.cc.

std::string cvn::CVNEventDump::fEnergyNumuLabel
private

Definition at line 62 of file CVNEventDump_module.cc.

std::string cvn::CVNEventDump::fEnergyNutauLabel
private

Definition at line 63 of file CVNEventDump_module.cc.

std::string cvn::CVNEventDump::fGenieGenModuleLabel
private

Definition at line 60 of file CVNEventDump_module.cc.

bool cvn::CVNEventDump::fGetEnergyOutput
private

Definition at line 64 of file CVNEventDump_module.cc.

bool cvn::CVNEventDump::fGetEventWeight
private

Definition at line 65 of file CVNEventDump_module.cc.

dunemva::MVAAlg cvn::CVNEventDump::fMVAAlg
private

Definition at line 57 of file CVNEventDump_module.cc.

std::string cvn::CVNEventDump::fPixelMapInput
private

Definition at line 59 of file CVNEventDump_module.cc.

unsigned int cvn::CVNEventDump::fTopologyHits
private

Definition at line 69 of file CVNEventDump_module.cc.

TrainingData* cvn::CVNEventDump::fTrain
private

Definition at line 72 of file CVNEventDump_module.cc.

TTree* cvn::CVNEventDump::fTrainTree
private

Definition at line 73 of file CVNEventDump_module.cc.

bool cvn::CVNEventDump::fUseTopology
private

Definition at line 68 of file CVNEventDump_module.cc.

bool cvn::CVNEventDump::fWriteMapTH2
private

Definition at line 66 of file CVNEventDump_module.cc.


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