CVNEventDumpProtoDUNE_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // \file CVNEventDumpProtoDUNE_module.cc
3 // \brief Analyzer module for creating CVN PixelMap objects using protoDUNE particles
4 // \author Leigh Whitehead - leigh.howard.whitehead@cern.ch
5 //
6 ////////////////////////////////////////////////////////////////////////
7 
8 // C/C++ includes
9 #include <iostream>
10 #include <sstream>
11 
12 // ROOT includes
13 #include "TTree.h"
14 #include "TH2F.h"
15 
16 // Framework includes
21 #include "art_root_io/TFileDirectory.h"
22 #include "art_root_io/TFileService.h"
24 #include "fhiclcpp/ParameterSet.h"
27 
31 
32 
33 namespace cvn {
35  public:
36 
37  explicit CVNEventDumpProtoDUNE(fhicl::ParameterSet const& pset);
39 
40  void analyze(const art::Event& evt) override;
41  void reconfigure(const fhicl::ParameterSet& pset);
42  void beginJob() override;
43  void endJob() override;
44 
45  private:
46 
49  //bool fApplyFidVol;
50 
52  TTree* fTrainTree;
53 
54  /// Function to extract TH2 from PixelMap and write to TFile
55  void WriteMapTH2(const art::Event& evt, int slice, const PixelMap& pm);
56 
57  };
58 
59  //.......................................................................
61  : EDAnalyzer(pset)
62  {
63  this->reconfigure(pset);
64  }
65 
66  //......................................................................
68  { }
69 
70  //......................................................................
72  {
73  fPixelMapInput = pset.get<std::string>("PixelMapInput");
74  fWriteMapTH2 = pset.get<bool> ("WriteMapTH2");
75  }
76 
77  //......................................................................
79  {
80 
81 
83 
84  fTrainTree = tfs->make<TTree>("CVNTrainTree", "Training records");
85  fTrainTree->Branch("train", "cvn::TrainingData", &fTrain);
86 
87 
88  }
89 
90  //......................................................................
92  {
93 
94  }
95 
96  //......................................................................
98  {
99 
100  // Get the pixel maps
101  std::vector< art::Ptr< cvn::PixelMap > > pixelmaplist;
103  auto pixelmapListHandle = evt.getHandle< std::vector< cvn::PixelMap > >(itag1);
104  if (pixelmapListHandle)
105  art::fill_ptr_vector(pixelmaplist, pixelmapListHandle);
106 
107  std::cout << "Found " << pixelmaplist.size() << " pixel maps in event" << std::endl;
108 
109  for(unsigned int p = 0; p < pixelmaplist.size(); ++p){
110 
111  // We will have to just fake the truth information we would usually have for the events
113 
114  // Create the training data and add it to the tree
115  TrainingData train(interaction, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, *pixelmaplist[p]);
116  fTrain = &train;
117  fTrainTree->Fill();
118 
119  // Make a plot of the pixel map if required
120  if (fWriteMapTH2) WriteMapTH2(evt, p, train.fPMap);
121 
122  }
123 
124  }
125 
126  //----------------------------------------------------------------------
127 
128 
129 
131  {
132  std::stringstream name;
133  name << "PixelMap_r" << evt.run() << "_s" << evt.subRun()<< "_e" << evt.event() << "_sl" << slice;
134  std::stringstream nameL;
135  nameL << "PixelTruthMap_r" << evt.run() << "_s" << evt.subRun()<< "_e" << evt.event() << "_sl" << slice;
136  std::stringstream nameX;
137  nameX << "PixelMap_X_r" << evt.run() << "_s" << evt.subRun()<< "_e" << evt.event() << "_sl" << slice;
138  std::stringstream nameY;
139  nameY << "PixelMap_Y_r" << evt.run() << "_s" << evt.subRun()<< "_e" << evt.event() << "_sl" << slice;
140  std::stringstream nameZ;
141  nameZ << "PixelMap_Z_r" << evt.run() << "_s" << evt.subRun()<< "_e" << evt.event() << "_sl" << slice;
142  TH2F* hist = pm.ToTH2();
143  TH2F* histL = pm.ToLabTH2();
144  TH2F* histX = pm.SingleViewToTH2(0);
145  TH2F* histY = pm.SingleViewToTH2(1);
146  TH2F* histZ = pm.SingleViewToTH2(2);
147  hist->SetName(name.str().c_str());
148  histL->SetName(nameL.str().c_str());
149  histX->SetName(nameX.str().c_str());
150  histY->SetName(nameY.str().c_str());
151  histZ->SetName(nameZ.str().c_str());
152 
154 
155  TH2F* histWrite = tfs->make<TH2F>(*hist);
156  histWrite->Write();
157  TH2F* histWriteL = tfs->make<TH2F>(*histL);
158  histWriteL->GetZaxis()->SetRangeUser(0,10);
159  histWriteL->Write();
160  TH2F* histWriteX = tfs->make<TH2F>(*histX);
161  histWriteX->Write();
162  TH2F* histWriteY = tfs->make<TH2F>(*histY);
163  histWriteY->Write();
164  TH2F* histWriteZ = tfs->make<TH2F>(*histZ);
165  histWriteZ->Write();
166 
167  delete hist;
168  delete histWrite;
169  delete histL;
170  delete histWriteL;
171  delete histX;
172  delete histWriteX;
173  delete histY;
174  delete histWriteY;
175  delete histZ;
176  delete histWriteZ;
177 
178  }
179 
181 } // end namespace cvn
182 ////////////////////////////////////////////////////////////////////////
183 
184 
185 
186 
187 
188 
189 
static QCString name
Definition: declinfo.cpp:673
EventNumber_t event() const
Definition: DataViewImpl.cc:85
void analyze(const art::Event &evt) override
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
std::string string
Definition: nybbler.cc:12
void WriteMapTH2(const art::Event &evt, int slice, const PixelMap &pm)
Function to extract TH2 from PixelMap and write to TFile.
TH2F * SingleViewToTH2(const unsigned int &view) const
Definition: PixelMap.cxx:206
enum cvn::Interaction InteractionType
TH2F * ToLabTH2() const
Definition: PixelMap.cxx:186
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
PixelMap for CVN.
Utility class for truth labels.
TH2F * ToTH2() const
Return the pixel map as a 2D histogram for visualization.
Definition: PixelMap.cxx:166
PixelMap fPMap
PixelMap for the event.
Definition: TrainingData.h:59
def train(model, train_files, valid_files, maskpatterns, epochs, batchsize, info)
Definition: train.py:16
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
void reconfigure(const fhicl::ParameterSet &pset)
T get(std::string const &key) const
Definition: ParameterSet.h:271
p
Definition: test.py:223
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.
The TrainingData objects contains a PixelMap and the output class type, and any other bit that goes i...
Definition: TrainingData.h:20
PixelMap, basic input to CVN neural net.
Definition: PixelMap.h:22
TCEvent evt
Definition: DataStructs.cxx:7
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:297
QTextStream & endl(QTextStream &s)
CVNEventDumpProtoDUNE(fhicl::ParameterSet const &pset)