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

Public Member Functions

 CVNZlibMaker (fhicl::ParameterSet const &pset)
 
 ~CVNZlibMaker ()
 
void beginJob () override
 
void analyze (const art::Event &evt) override
 
void reconfigure (const fhicl::ParameterSet &pset)
 
- 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 write_files (TrainingData td, unsigned int n, std::string evtid)
 

Private Attributes

std::string fOutputDir
 
std::string fPixelMapInput
 
bool fSetLog
 
std::vector< boolfReverseViews
 
unsigned int fTopologyHitsCut
 
std::string fGenieGenModuleLabel
 
std::string fEnergyNueLabel
 
std::string fEnergyNumuLabel
 
std::string fEnergyNutauLabel
 
unsigned int fPlaneLimit
 
unsigned int fTDCLimit
 
std::string out_dir
 

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 39 of file CVNZlibMaker_module.cc.

Constructor & Destructor Documentation

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

Definition at line 72 of file CVNZlibMaker_module.cc.

73  : EDAnalyzer(pset)
74  {
75  this->reconfigure(pset);
76  }
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
void reconfigure(const fhicl::ParameterSet &pset)
cvn::CVNZlibMaker::~CVNZlibMaker ( )

Definition at line 79 of file CVNZlibMaker_module.cc.

80  { }

Member Function Documentation

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

Definition at line 133 of file CVNZlibMaker_module.cc.

134  {
135 
136  // Get the pixel maps
137  std::vector<art::Ptr<cvn::PixelMap>> pixelmaps;
139  auto h_pixelmaps = evt.getHandle<std::vector<cvn::PixelMap>>(itag1);
140  if (h_pixelmaps)
141  art::fill_ptr_vector(pixelmaps, h_pixelmaps);
142 
143  // If no pixel maps, quit
144  if (pixelmaps.size() == 0) return;
145 
147 
148  // MC information
149  std::vector<art::Ptr<simb::MCTruth>> mctruth_list;
150  auto h_mctruth = evt.getHandle<std::vector<simb::MCTruth>>(fGenieGenModuleLabel);
151  if (h_mctruth)
152  art::fill_ptr_vector(mctruth_list, h_mctruth);
153 
154  art::Ptr<simb::MCTruth> mctruth = mctruth_list[0];
155  simb::MCNeutrino true_neutrino = mctruth->GetNeutrino();
156 
157  AssignLabels labels;
158 
159  interaction = labels.GetInteractionType(true_neutrino);
160  labels.GetTopology(mctruth, fTopologyHitsCut);
161 
162  // True lepton and neutrino energies
163  float nu_energy = true_neutrino.Nu().E();
164  float lep_energy = true_neutrino.Lepton().E();
165 
166  // Put a containment cut here
167 
168  float reco_nue_energy = 0;
169  float reco_numu_energy = 0;
170  float reco_nutau_energy = 0;
171 
172  // Get nue info
173  if (fEnergyNueLabel != "") {
174  auto h_ereco = evt.getHandle<dune::EnergyRecoOutput>(fEnergyNueLabel);
175  reco_nue_energy = h_ereco->fNuLorentzVector.E();
176  }
177 
178  // Get numu info
179  if (fEnergyNueLabel != "") {
181  reco_numu_energy = h_ereco->fNuLorentzVector.E();
182  }
183 
184  // Get nutau info
185  if (fEnergyNutauLabel != "") {
187  reco_nutau_energy = h_ereco->fNuLorentzVector.E();
188  }
189 
190  // Hard-coding event weight for now
191  // Should probably fix this at some point
192  int event_weight = 1;
193 
194  TrainingData train(interaction, nu_energy, lep_energy,
195  reco_nue_energy, reco_numu_energy, reco_nutau_energy,
196  event_weight, *pixelmaps[0]);
197 
198  int pdg = labels.GetPDG();
199  int n_proton = labels.GetNProtons();
200  int n_pion = labels.GetNPions();
201  int n_pi0 = labels.GetNPizeros();
202  int n_neutron = labels.GetNNeutrons();
203  int toptype = labels.GetTopologyType();
204  int toptypealt = labels.GetTopologyTypeAlt();
205 
206  train.SetTopologyInformation(pdg, n_proton, n_pion,
207  n_pi0, n_neutron, toptype, toptypealt);
208 
209  std::string evtid = "r"+std::to_string(evt.run())+"_s"+std::to_string(evt.subRun())+"_e"+std::to_string(evt.event());
210  this->write_files(train, evt.event(), evtid);
211  }
double E(const int i=0) const
Definition: MCParticle.h:233
EventNumber_t event() const
Definition: DataViewImpl.cc:85
const simb::MCNeutrino & GetNeutrino() const
Definition: MCTruth.h:77
void write_files(TrainingData td, unsigned int n, std::string evtid)
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
std::string string
Definition: nybbler.cc:12
const simb::MCParticle & Nu() const
Definition: MCNeutrino.h:146
enum cvn::Interaction InteractionType
std::string fEnergyNutauLabel
def train(model, train_files, valid_files, maskpatterns, epochs, batchsize, info)
Definition: train.py:16
std::string fEnergyNumuLabel
const simb::MCParticle & Lepton() const
Definition: MCNeutrino.h:147
Definition: train.py:1
SubRunNumber_t subRun() const
Definition: DataViewImpl.cc:78
RunNumber_t run() const
Definition: DataViewImpl.cc:71
Something else. Tau? Hopefully we don&#39;t use this.
unsigned int fTopologyHitsCut
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:297
std::string fGenieGenModuleLabel
Event generator information.
Definition: MCNeutrino.h:18
std::string to_string(ModuleType const mt)
Definition: ModuleType.h:34
void cvn::CVNZlibMaker::beginJob ( )
overridevirtual

Reimplemented from art::EDAnalyzer.

Definition at line 101 of file CVNZlibMaker_module.cc.

102  {
103  // Set the output directory.
104  // First we look for CONDOR_DIR_INPUT and set it to the grid location.
105  // If it isn't there, we look for a FHICL parameter.
106  // Otherwise it just goes to the current directory.
107 /*
108  char const* grid_dir = getenv("CONDOR_DIR_INPUT");
109  if (grid_dir != NULL) {
110  char const* tmp_grid_dir = getenv("TMP");
111  if (tmp_grid_dir == NULL)
112  throw art::Exception(art::errors::NotFound)
113  << "Could not find environment variable \"TMP\" which "
114  << "is usually set for condor_lar environment." << std::endl;
115  out_dir = std::string(tmp_grid_dir) + "/out";
116  }
117 */
118  if (fOutputDir != "")
120 
121  else
122  out_dir = ".";
123 
124  // Throw an error if the specified output directory doesn't exist
125  if (!fs::exists(out_dir))
127  << "Output directory " << out_dir << " does not exist!" << std::endl;
128 
129  // std::cout << "Writing files to output directory " << out_dir << std::endl;
130  }
bool exists(std::string path)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
QTextStream & endl(QTextStream &s)
void cvn::CVNZlibMaker::reconfigure ( const fhicl::ParameterSet pset)

Definition at line 83 of file CVNZlibMaker_module.cc.

84  {
85  fOutputDir = pset.get<std::string>("OutputDir", "");
86  fPixelMapInput = pset.get<std::string>("PixelMapInput");
87  fSetLog = pset.get<bool>("SetLog");
88  fReverseViews = pset.get<std::vector<bool>>("ReverseViews");
89  fTopologyHitsCut = pset.get<unsigned int>("TopologyHitsCut");
90 
91  fGenieGenModuleLabel = pset.get<std::string>("GenieGenModuleLabel");
92  fEnergyNueLabel = pset.get<std::string>("EnergyNueLabel");
93  fEnergyNumuLabel = pset.get<std::string>("EnergyNumuLabel");
94  fEnergyNutauLabel = pset.get<std::string>("EnergyNutauLabel");
95 
96  fPlaneLimit = pset.get<unsigned int>("PlaneLimit");
97  fTDCLimit = pset.get<unsigned int>("TDCLimit");
98  }
std::string string
Definition: nybbler.cc:12
std::vector< bool > fReverseViews
std::string fEnergyNutauLabel
std::string fEnergyNumuLabel
T get(std::string const &key) const
Definition: ParameterSet.h:271
unsigned int fTopologyHitsCut
std::string fGenieGenModuleLabel
void cvn::CVNZlibMaker::write_files ( TrainingData  td,
unsigned int  n,
std::string  evtid 
)
private

Definition at line 214 of file CVNZlibMaker_module.cc.

215  {
216  // cropped from 2880 x 500 to 500 x 500 here
217  std::vector<unsigned char> pixel_array(3 * fPlaneLimit * fTDCLimit);
218 
219  CVNImageUtils image_utils(fPlaneLimit, fTDCLimit, 3);
220  image_utils.SetPixelMapSize(td.fPMap.NWire(), td.fPMap.NTdc());
221  image_utils.SetLogScale(fSetLog);
222  image_utils.SetViewReversal(fReverseViews);
223  image_utils.ConvertPixelMapToPixelArray(td.fPMap, pixel_array);
224 
225  ulong src_len = 3 * fPlaneLimit * fTDCLimit; // pixelArray length
226  ulong dest_len = compressBound(src_len); // calculate size of the compressed data
227  char* ostream = (char *) malloc(dest_len); // allocate memory for the compressed data
228 
229  int res = compress((Bytef *) ostream, &dest_len, (Bytef *) &pixel_array[0], src_len);
230 
231  // Buffer error
232 
233  if (res == Z_BUF_ERROR)
234  std::cout << "Buffer too small!" << std::endl;
235 
236  // Memory error
237  else if (res == Z_MEM_ERROR)
238  std::cout << "Not enough memory for compression!" << std::endl;
239 
240  // Compression ok
241  else {
242 
243  // Create output files
244  std::string image_file_name = out_dir + "/event_" + evtid + ".gz";
245  std::string info_file_name = out_dir + "/event_" + evtid + ".info";
246 
247  std::ofstream image_file (image_file_name, std::ofstream::binary);
248  std::ofstream info_file (info_file_name);
249 
250  if(image_file.is_open() && info_file.is_open()) {
251 
252  // Write compressed data to file
253 
254  image_file.write(ostream, dest_len);
255 
256  image_file.close(); // close file
257 
258  // Write records to file
259 
260  // Category
261 
262  info_file << td.fInt << std::endl;
263 
264  // Energy
265 
266  info_file << td.fNuEnergy << std::endl;
267  info_file << td.fLepEnergy << std::endl;
268  info_file << td.fRecoNueEnergy << std::endl;
269  info_file << td.fRecoNumuEnergy << std::endl;
270  info_file << td.fRecoNutauEnergy << std::endl;
271  info_file << td.fEventWeight << std::endl;
272 
273  // Topology
274 
275  info_file << td.fNuPDG << std::endl;
276  info_file << td.fNProton << std::endl;
277  info_file << td.fNPion << std::endl;
278  info_file << td.fNPizero << std::endl;
279  info_file << td.fNNeutron << std::endl;
280 
281  info_file << td.fTopologyType << std::endl;
282  info_file << td.fTopologyTypeAlt << std::endl;
283  info_file << td.fPMap.GetTotHits() << std::endl;
284 
285  info_file.close(); // close file
286  }
287  else {
288 
289  if (image_file.is_open())
290  image_file.close();
291  else
293  << "Unable to open file " << image_file_name << "!" << std::endl;
294 
295  if (info_file.is_open())
296  info_file.close();
297  else
299  << "Unable to open file " << info_file_name << "!" << std::endl;
300  }
301  }
302 
303  free(ostream); // free allocated memory
304 
305  } // cvn::CVNZlibMaker::write_files
std::string string
Definition: nybbler.cc:12
std::vector< bool > fReverseViews
unsigned long ulong
Definition: qglobal.h:352
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
QTextStream & endl(QTextStream &s)

Member Data Documentation

std::string cvn::CVNZlibMaker::fEnergyNueLabel
private

Definition at line 58 of file CVNZlibMaker_module.cc.

std::string cvn::CVNZlibMaker::fEnergyNumuLabel
private

Definition at line 59 of file CVNZlibMaker_module.cc.

std::string cvn::CVNZlibMaker::fEnergyNutauLabel
private

Definition at line 60 of file CVNZlibMaker_module.cc.

std::string cvn::CVNZlibMaker::fGenieGenModuleLabel
private

Definition at line 57 of file CVNZlibMaker_module.cc.

std::string cvn::CVNZlibMaker::fOutputDir
private

Definition at line 51 of file CVNZlibMaker_module.cc.

std::string cvn::CVNZlibMaker::fPixelMapInput
private

Definition at line 52 of file CVNZlibMaker_module.cc.

unsigned int cvn::CVNZlibMaker::fPlaneLimit
private

Definition at line 62 of file CVNZlibMaker_module.cc.

std::vector<bool> cvn::CVNZlibMaker::fReverseViews
private

Definition at line 54 of file CVNZlibMaker_module.cc.

bool cvn::CVNZlibMaker::fSetLog
private

Definition at line 53 of file CVNZlibMaker_module.cc.

unsigned int cvn::CVNZlibMaker::fTDCLimit
private

Definition at line 63 of file CVNZlibMaker_module.cc.

unsigned int cvn::CVNZlibMaker::fTopologyHitsCut
private

Definition at line 55 of file CVNZlibMaker_module.cc.

std::string cvn::CVNZlibMaker::out_dir
private

Definition at line 65 of file CVNZlibMaker_module.cc.


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