Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
tutorial::ReadSpacePointAndCnn Class Reference
Inheritance diagram for tutorial::ReadSpacePointAndCnn:
art::EDAnalyzer art::detail::Analyzer art::detail::LegacyModule art::Observer art::ModuleBase

Classes

struct  Config
 

Public Types

using Parameters = art::EDAnalyzer::Table< Config >
 
- Public Types inherited from art::EDAnalyzer
using WorkerType = WorkerT< EDAnalyzer >
 
using ModuleType = EDAnalyzer
 

Public Member Functions

 ReadSpacePointAndCnn (Parameters const &config)
 
 ReadSpacePointAndCnn (ReadSpacePointAndCnn const &)=delete
 
 ReadSpacePointAndCnn (ReadSpacePointAndCnn &&)=delete
 
ReadSpacePointAndCnnoperator= (ReadSpacePointAndCnn const &)=delete
 
ReadSpacePointAndCnnoperator= (ReadSpacePointAndCnn &&)=delete
 
void analyze (art::Event const &e) override
 
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 clear ()
 

Private Attributes

size_t fEvNumber
 
TTree * fEventTree
 
size_t fNHits [3]
 
size_t fNPoints
 
std::vector< unsigned char > fHitTpc [3]
 
std::vector< float > fHitWire [3]
 
std::vector< float > fHitTime [3]
 
std::vector< float > fHitCharge [3]
 
std::vector< float > fPointX
 
std::vector< float > fPointY
 
std::vector< float > fPointZ
 
std::vector< float > fPointCharge
 
std::vector< float > fPointEmScore
 
art::InputTag fHitsModuleLabel
 
art::InputTag fSpacePointModuleLabel
 
art::InputTag fCnnModuleLabel
 

Additional Inherited Members

- 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 36 of file ReadSpacePointAndCnn_module.cc.

Member Typedef Documentation

Definition at line 55 of file ReadSpacePointAndCnn_module.cc.

Constructor & Destructor Documentation

tutorial::ReadSpacePointAndCnn::ReadSpacePointAndCnn ( Parameters const &  config)
explicit

Definition at line 96 of file ReadSpacePointAndCnn_module.cc.

97  fHitsModuleLabel(config().HitsModuleLabel()),
98  fSpacePointModuleLabel(config().SpacePointModuleLabel()),
99  fCnnModuleLabel(config().CnnModuleLabel())
100 {
101 }
static Config * config
Definition: config.cpp:1054
tutorial::ReadSpacePointAndCnn::ReadSpacePointAndCnn ( ReadSpacePointAndCnn const &  )
delete
tutorial::ReadSpacePointAndCnn::ReadSpacePointAndCnn ( ReadSpacePointAndCnn &&  )
delete

Member Function Documentation

void tutorial::ReadSpacePointAndCnn::analyze ( art::Event const &  e)
overridevirtual

Implements art::EDAnalyzer.

Definition at line 145 of file ReadSpacePointAndCnn_module.cc.

146 {
147  clear();
148 
149  fEvNumber = evt.id().event();
150  mf::LogVerbatim("ReadSpacePointAndCnn") << "ReadSpacePointAndCnn module on event #" << fEvNumber;
151 
152  // store 2D hits info, sorted by plane (but not by TPC, you need to select
153  // on that later in your analysis)
154  auto hitsHandle = evt.getValidHandle< std::vector<recob::Hit> >(fHitsModuleLabel);
155  fNHits[0] = 0; fNHits[1] = 0; fNHits[2] = 0;
156 
157  for (const auto & h : *hitsHandle)
158  {
159  size_t p = h.WireID().Plane;
160  fHitTpc[p].push_back(h.WireID().TPC);
161  fHitWire[p].push_back(h.WireID().Wire);
162  fHitTime[p].push_back(h.PeakTime());
163  fHitCharge[p].push_back(h.Integral());
164  fNHits[p]++;
165  }
166 
167  // store SpacePoints basic info
168  auto spHandle = evt.getValidHandle< std::vector<recob::SpacePoint> >(fSpacePointModuleLabel);
169  auto qHandle = evt.getValidHandle< std::vector<recob::PointCharge> >(fSpacePointModuleLabel);
170  if (spHandle->size() != qHandle->size())
171  {
172  throw cet::exception("tutorial::ReadSpacePointAndCnn")
173  << "size of point and charge containers must be equal" << std::endl;
174  }
175 
176  fNPoints = spHandle->size();
177  fPointX.resize(fNPoints); fPointY.resize(fNPoints); fPointZ.resize(fNPoints);
178  fPointCharge.resize(fNPoints);
179  fPointEmScore.resize(fNPoints);
180 
181  for (size_t i = 0; i < spHandle->size(); ++i)
182  {
183  fPointX[i] = (*spHandle)[i].XYZ()[0];
184  fPointY[i] = (*spHandle)[i].XYZ()[1];
185  fPointZ[i] = (*spHandle)[i].XYZ()[2];
186  fPointCharge[i] = (*qHandle)[i].charge();
187  fPointEmScore[i] = 0.5; // neutral P(EM-like) value
188  }
189 
190  // and tag SpacePoints with EM-like scores calculated by CNN on the cluster level
191  // connect these scores to SpacePoints throuh hits, and choose the score of the
192  // largest cluster containing the hit associated to SpacePoint;
193  // other option could be e.g.: use CNN scores on the hit level, multiplying scores
194  // from hits in all planes
196  if (cluResults)
197  {
198  size_t emLikeIdx = cluResults->getIndex("em"); // at which index EM-like is stored in CNN output vector
199 
200  const art::FindManyP<recob::Hit> hitsFromClusters(cluResults->dataHandle(), evt, cluResults->dataTag());
201  const art::FindManyP<recob::SpacePoint> spFromHits(hitsHandle, evt, fSpacePointModuleLabel);
202 
203  std::vector<size_t> sizeScore(fNPoints, 0); // keep track of the max size of a cluster containing hit associated to spacepoint
204 
205  for (size_t c = 0; c < cluResults->size(); ++c)
206  {
207  //const recob::Cluster & clu = cluResults->item(c); // one can get the cluster object in this way, here not really used
208 
209  const std::vector< art::Ptr<recob::Hit> > & hits = hitsFromClusters.at(c);
210  std::array<float, MVA_LENGTH> cnn_out = cluResults->getOutput(c);
211 
212  for (const auto & hptr : hits)
213  {
214  const std::vector< art::Ptr<recob::SpacePoint> > & sp = spFromHits.at(hptr.key());
215  for (const auto & spptr : sp) // with SpacePointSolver should be just 1 hit, but be prepared for any other algorithm
216  {
217  if (hits.size() > sizeScore[spptr.key()])
218  {
219  sizeScore[spptr.key()] = hits.size();
220  fPointEmScore[spptr.key()] = cnn_out[emLikeIdx];
221  }
222  }
223  }
224  }
225  }
226 
227  fEventTree->Fill();
228 
229  clear();
230 }
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
unsigned int event
Definition: DataStructs.h:636
std::vector< unsigned char > fHitTpc[3]
p
Definition: test.py:223
TCEvent evt
Definition: DataStructs.cxx:7
static std::unique_ptr< MVAReader > create(const art::Event &evt, const art::InputTag &tag)
Definition: MVAReader.h:110
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)
void tutorial::ReadSpacePointAndCnn::beginJob ( )
overridevirtual

Reimplemented from art::EDAnalyzer.

Definition at line 103 of file ReadSpacePointAndCnn_module.cc.

104 {
105  art::ServiceHandle<art::TFileService> tfs; // TTree's are created in the memory managed by ROOT (you don't delete them)
106 
107  fEventTree = tfs->make<TTree>("EventTree", "event by event info");
108  fEventTree->Branch("event", &fEvNumber, "fEvNumber/I");
109  fEventTree->Branch("nhits", &fNHits, "fNHits[3]/I");
110  fEventTree->Branch("npoints", &fNPoints, "fNPoints/I");
111 
112  fEventTree->Branch("hit0tpc", &fHitTpc[0]);
113  fEventTree->Branch("hit0w", &fHitWire[0]);
114  fEventTree->Branch("hit0t", &fHitTime[0]);
115  fEventTree->Branch("hit0q", &fHitCharge[0]);
116 
117  fEventTree->Branch("hit1tpc", &fHitTpc[1]);
118  fEventTree->Branch("hit1w", &fHitWire[1]);
119  fEventTree->Branch("hit1t", &fHitTime[1]);
120  fEventTree->Branch("hit1q", &fHitCharge[1]);
121 
122  fEventTree->Branch("hit2tpc", &fHitTpc[2]);
123  fEventTree->Branch("hit2w", &fHitWire[2]);
124  fEventTree->Branch("hit2t", &fHitTime[2]);
125  fEventTree->Branch("hit2q", &fHitCharge[2]);
126 
127  fEventTree->Branch("pointx", &fPointX);
128  fEventTree->Branch("pointy", &fPointY);
129  fEventTree->Branch("pointz", &fPointZ);
130  fEventTree->Branch("pointq", &fPointCharge);
131  fEventTree->Branch("emscore", &fPointEmScore);
132 }
std::vector< unsigned char > fHitTpc[3]
void tutorial::ReadSpacePointAndCnn::clear ( )
private

Definition at line 134 of file ReadSpacePointAndCnn_module.cc.

135 {
136  for (size_t p = 0; p < 3; ++p)
137  {
138  fHitTpc[p].clear();
139  fHitWire[p].clear();
140  fHitTime[p].clear();
141  fHitCharge[p].clear();
142  }
143 }
std::vector< unsigned char > fHitTpc[3]
p
Definition: test.py:223
void tutorial::ReadSpacePointAndCnn::endJob ( )
overridevirtual

Reimplemented from art::EDAnalyzer.

Definition at line 232 of file ReadSpacePointAndCnn_module.cc.

233 {
234  mf::LogVerbatim("ReadSpacePointAndCnn") << "ReadSpacePointAndCnn finished job";
235 }
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
ReadSpacePointAndCnn& tutorial::ReadSpacePointAndCnn::operator= ( ReadSpacePointAndCnn const &  )
delete
ReadSpacePointAndCnn& tutorial::ReadSpacePointAndCnn::operator= ( ReadSpacePointAndCnn &&  )
delete

Member Data Documentation

art::InputTag tutorial::ReadSpacePointAndCnn::fCnnModuleLabel
private

Definition at line 93 of file ReadSpacePointAndCnn_module.cc.

TTree* tutorial::ReadSpacePointAndCnn::fEventTree
private

Definition at line 74 of file ReadSpacePointAndCnn_module.cc.

size_t tutorial::ReadSpacePointAndCnn::fEvNumber
private

Definition at line 72 of file ReadSpacePointAndCnn_module.cc.

std::vector<float> tutorial::ReadSpacePointAndCnn::fHitCharge[3]
private

Definition at line 83 of file ReadSpacePointAndCnn_module.cc.

art::InputTag tutorial::ReadSpacePointAndCnn::fHitsModuleLabel
private

Definition at line 91 of file ReadSpacePointAndCnn_module.cc.

std::vector<float> tutorial::ReadSpacePointAndCnn::fHitTime[3]
private

Definition at line 83 of file ReadSpacePointAndCnn_module.cc.

std::vector<unsigned char> tutorial::ReadSpacePointAndCnn::fHitTpc[3]
private

Definition at line 82 of file ReadSpacePointAndCnn_module.cc.

std::vector<float> tutorial::ReadSpacePointAndCnn::fHitWire[3]
private

Definition at line 83 of file ReadSpacePointAndCnn_module.cc.

size_t tutorial::ReadSpacePointAndCnn::fNHits[3]
private

Definition at line 77 of file ReadSpacePointAndCnn_module.cc.

size_t tutorial::ReadSpacePointAndCnn::fNPoints
private

Definition at line 78 of file ReadSpacePointAndCnn_module.cc.

std::vector<float> tutorial::ReadSpacePointAndCnn::fPointCharge
private

Definition at line 87 of file ReadSpacePointAndCnn_module.cc.

std::vector<float> tutorial::ReadSpacePointAndCnn::fPointEmScore
private

Definition at line 88 of file ReadSpacePointAndCnn_module.cc.

std::vector<float> tutorial::ReadSpacePointAndCnn::fPointX
private

Definition at line 86 of file ReadSpacePointAndCnn_module.cc.

std::vector<float> tutorial::ReadSpacePointAndCnn::fPointY
private

Definition at line 86 of file ReadSpacePointAndCnn_module.cc.

std::vector<float> tutorial::ReadSpacePointAndCnn::fPointZ
private

Definition at line 86 of file ReadSpacePointAndCnn_module.cc.

art::InputTag tutorial::ReadSpacePointAndCnn::fSpacePointModuleLabel
private

Definition at line 92 of file ReadSpacePointAndCnn_module.cc.


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