Public Member Functions | Private Member Functions | Private Attributes | List of all members
shs::ShowerHitSeparator Class Reference
Inheritance diagram for shs::ShowerHitSeparator:
art::EDProducer art::detail::Producer art::detail::LegacyModule art::Modifier art::ModuleBase art::ProductRegistryHelper

Public Member Functions

 ShowerHitSeparator (fhicl::ParameterSet const &pset)
 
void reconfigure (fhicl::ParameterSet const &p)
 
void produce (art::Event &evt)
 
void beginJob ()
 
void endJob ()
 
- Public Member Functions inherited from art::EDProducer
 EDProducer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 EDProducer (Table< Config > const &config)
 
std::string workerType () const
 
- Public Member Functions inherited from art::detail::Producer
virtual ~Producer () noexcept
 
 Producer (fhicl::ParameterSet const &)
 
 Producer (Producer const &)=delete
 
 Producer (Producer &&)=delete
 
Produceroperator= (Producer const &)=delete
 
Produceroperator= (Producer &&)=delete
 
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::Modifier
 ~Modifier () noexcept
 
 Modifier ()
 
 Modifier (Modifier const &)=delete
 
 Modifier (Modifier &&)=delete
 
Modifieroperator= (Modifier const &)=delete
 
Modifieroperator= (Modifier &&)=delete
 
- 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

template<size_t N>
void ReadMVA (std::vector< float > &weights, art::Event &evt)
 
void SaveTree (std::vector< recob::Hit > const &shwHits, std::vector< recob::Hit > const &trkHits)
 

Private Attributes

std::string fMVALabel
 
std::string fHitLabel
 
double fMVAOutputCut
 
bool fSaveTree
 
std::string fMVAClusterLabel
 
TTree * fOutTree
 
Int_t fOutEvent
 
Int_t fOutRun
 
Int_t fOutSubrun
 
Int_t fOutTPC
 
Int_t fOutCryo
 
Int_t fOutPlane
 
Int_t fOutTime
 
Int_t fOutWire
 
bool fOutIsShw
 
bool fOutIsTrk
 
art::Handle< std::vector< recob::Cluster > > fMVAClusters
 

Additional Inherited Members

- Public Types inherited from art::EDProducer
using ModuleType = EDProducer
 
using WorkerType = WorkerT< EDProducer >
 
- Public Types inherited from art::detail::Producer
template<typename UserConfig , typename KeysToIgnore = void>
using Table = Modifier::Table< UserConfig, KeysToIgnore >
 
- Public Types inherited from art::Modifier
template<typename UserConfig , typename UserKeysToIgnore = void>
using Table = ProducerTable< UserConfig, detail::ModuleConfig, UserKeysToIgnore >
 
- Static Public Member Functions inherited from art::EDProducer
static void commitEvent (EventPrincipal &ep, Event &e)
 
- 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 46 of file ShowerHitSeparator_module.cc.

Constructor & Destructor Documentation

shs::ShowerHitSeparator::ShowerHitSeparator ( fhicl::ParameterSet const &  pset)
explicit

Definition at line 83 of file ShowerHitSeparator_module.cc.

83  : EDProducer{pset} {
84 
85  this->reconfigure(pset);
86 
87  // Let HitCollectionCreator declare that we are going to produce
88  // hits and associations with wires and raw digits
91 
92  // Define some histograms if we want the plots
93  if(fSaveTree){
94 
96 
97  fOutTree = tfs->make<TTree>("cnnHitTree","cnnHitTree");
98 
99  fOutTree->Branch("Event",&fOutEvent,"Event/I");
100  fOutTree->Branch("Run",&fOutRun,"Run/I");
101  fOutTree->Branch("Subrun",&fOutSubrun,"Subrun/I");
102  fOutTree->Branch("TPC",&fOutTPC,"TPC/I");
103  fOutTree->Branch("Cryostat",&fOutCryo,"Cryostat/I");
104  fOutTree->Branch("Plane",&fOutPlane,"Plane/I");
105  fOutTree->Branch("Time",&fOutTime,"Time/I");
106  fOutTree->Branch("Wire",&fOutWire,"Wire/I");
107  fOutTree->Branch("IsShower",&fOutIsShw,"IsShower/O");
108  fOutTree->Branch("IsTrack",&fOutIsTrk,"IsTrack/O");
109  }
110  }
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
static void declare_products(art::ProducesCollector &collector, std::string instance_name="", bool doWireAssns=true, bool doRawDigitAssns=true)
Declares the hit products we are going to fill.
Definition: HitCreator.cxx:248
ProducesCollector & producesCollector() noexcept
void reconfigure(fhicl::ParameterSet const &p)

Member Function Documentation

void shs::ShowerHitSeparator::beginJob ( )
inlinevirtual

Reimplemented from art::EDProducer.

Definition at line 51 of file ShowerHitSeparator_module.cc.

51 {};
void shs::ShowerHitSeparator::endJob ( )
inlinevirtual

Reimplemented from art::EDProducer.

Definition at line 52 of file ShowerHitSeparator_module.cc.

52 {};
void shs::ShowerHitSeparator::produce ( art::Event evt)
virtual

Implements art::EDProducer.

Definition at line 159 of file ShowerHitSeparator_module.cc.

159  {
160 
161  // We want to produce two hit collections
162  recob::HitCollectionCreator showerHits(evt,"showerhits",true,true);
163  recob::HitCollectionCreator trackHits(evt,"trackhits",true,true);
164 
165  // These are the MVA weights
166  std::vector<float> mvaWeights;
167 
168  // Access the MVA. It could have 4 or 3 outputs so try to see which.
169  ReadMVA<4>(mvaWeights,evt);
170  if(mvaWeights.size() == 0){
171  // If we didn't get any weights then try the version with three outputs instead
172  ReadMVA<3>(mvaWeights,evt);
173  }
174 
175  // If we get some weights then separate the hits into two collections
176  if(mvaWeights.size() != 0){
177 
178  const art::FindManyP<recob::Hit> hitsFromClusters(fMVAClusters, evt,fMVAClusterLabel);
179 
180  // We also need the hit selection that was used by the CNN
181  auto inputHits = evt.getHandle<std::vector<recob::Hit> >(fHitLabel);
182  art::FindOneP<raw::RawDigit> rawDigits(inputHits,evt,fHitLabel);
183  art::FindOneP<recob::Wire> recoWires(inputHits,evt,fHitLabel);
184 
185  // At this stage we have the hits from the clusters and the tag for each cluster.
186  // Loop over the clusters and add the hits to the shower-like hit collection.
187  for (size_t c = 0; c != fMVAClusters->size(); ++c){
188 
189  // Get the hits from this cluster
190  auto const& hits = hitsFromClusters.at(c);
191 
192  // Now we must copy each hit and reassociate it to the raw digits and wires
193  for (auto const & h : hits){
194  // The art pointer key gives us the position of "h" in the hit collection
195  recob::Hit thisHit = (*h);
196  auto digit = rawDigits.at(h.key());
197  auto wire = recoWires.at(h.key());
198  // Add the hit and its associated raw digit and wire to the collection.
199  if(mvaWeights[c] < fMVAOutputCut){
200  showerHits.emplace_back(thisHit,wire,digit);
201  }
202  else{
203  trackHits.emplace_back(thisHit,wire,digit);
204  }
205  } // End loop over hits
206  } // End for loop over clusters
207  }
208 
209  std::cout << "CNN output splitter: " << std::endl;
210  std::cout << " - Found " << showerHits.size() << " shower-like hits" << std::endl;
211  std::cout << " - Found " << trackHits.size() << " track-like hits" << std::endl;
212 
213  // Fill the output tree if requested to do so.
214  if(fSaveTree){
215  fOutEvent = evt.event();
216  fOutRun = evt.run();
217  fOutSubrun = evt.subRun();
218  SaveTree(showerHits.peek(),trackHits.peek());
219  }
220 
221  // Put the hit collections and associations into the event
222  showerHits.put_into(evt);
223  trackHits.put_into(evt);
224 
225  }
EventNumber_t event() const
Definition: DataViewImpl.cc:85
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
A class handling a collection of hits and its associations.
Definition: HitCreator.h:508
void SaveTree(std::vector< recob::Hit > const &shwHits, std::vector< recob::Hit > const &trkHits)
SubRunNumber_t subRun() const
Definition: DataViewImpl.cc:78
RunNumber_t run() const
Definition: DataViewImpl.cc:71
art::Handle< std::vector< recob::Cluster > > fMVAClusters
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:48
TCEvent evt
Definition: DataStructs.cxx:7
QTextStream & endl(QTextStream &s)
template<size_t N>
void shs::ShowerHitSeparator::ReadMVA ( std::vector< float > &  weights,
art::Event evt 
)
private

Definition at line 123 of file ShowerHitSeparator_module.cc.

123  {
124  // Access the MVA. It could have 4 or 3 outputs so try to see which.
126  if (!cluResults){
127  // We don't seem to have an MVA.
128  return;
129  }
130 
131  // This is the best way to get hold of the MVA clusters and tag used to associate the clusters
132  // back to the underlying hit objects.
133  fMVAClusters = cluResults->dataHandle();
134  fMVAClusterLabel = cluResults->dataTag();
135 
136  // Now we have the MVA, we need to access the outputs
137  int trkLikeIdx = cluResults->getIndex("track");
138  int emLikeIdx = cluResults->getIndex("em");
139  if ((trkLikeIdx < 0) || (emLikeIdx < 0)) {
140  // If the variables we want don't exist then we have a problem.
141  return;
142  }
143 
144  // Actually extract the weights
145  const auto & cnnOuts = cluResults->outputs();
146  for (size_t i = 0; i < cnnOuts.size(); ++i){
147 
148  double trkOrEm = cnnOuts[i][trkLikeIdx] + cnnOuts[i][emLikeIdx];
149  double val = 0;
150  if (trkOrEm > 0){
151  // Make sure output is normalised to fall between 0 and 1.
152  val = cnnOuts[i][trkLikeIdx] / trkOrEm;
153  }
154  weights.push_back(val);
155  }
156 
157  }
art::Handle< std::vector< recob::Cluster > > fMVAClusters
static std::unique_ptr< MVAReader > create(const art::Event &evt, const art::InputTag &tag)
Definition: MVAReader.h:110
void shs::ShowerHitSeparator::reconfigure ( fhicl::ParameterSet const &  p)

Definition at line 112 of file ShowerHitSeparator_module.cc.

112  {
113 
114  // Get the parameters from the fcl file
115  fMVALabel = p.get<std::string>("MVALabel");
116  fHitLabel = p.get<std::string>("HitLabel");
117  fMVAOutputCut = p.get<double>("MVAOutputCut");
118  fSaveTree = p.get<bool>("SaveTree");
119 
120  }
std::string string
Definition: nybbler.cc:12
p
Definition: test.py:223
void shs::ShowerHitSeparator::SaveTree ( std::vector< recob::Hit > const &  shwHits,
std::vector< recob::Hit > const &  trkHits 
)
private

Definition at line 227 of file ShowerHitSeparator_module.cc.

227  {
228 
229  // Event, Run and Subrun set outside of this function. Take care of everything else here.
230 
231  for(auto const shwHit : shwHits){
232  fOutTPC = shwHit.WireID().TPC;
233  fOutCryo = shwHit.WireID().Cryostat;
234  fOutPlane = shwHit.WireID().planeID().Plane;
235  fOutTime = shwHit.StartTick();
236  fOutWire = shwHit.WireID().Wire;
237  fOutIsShw = true;
238  fOutIsTrk = false;
239 
240  fOutTree->Fill();
241  }
242 
243  for(auto const trkHit : trkHits){
244  fOutTPC = trkHit.WireID().TPC;
245  fOutCryo = trkHit.WireID().Cryostat;
246  fOutPlane = trkHit.WireID().planeID().Plane;
247  fOutTime = trkHit.StartTick();
248  fOutWire = trkHit.WireID().Wire;
249  fOutIsShw = false;
250  fOutIsTrk = true;
251 
252  fOutTree->Fill();
253  }
254 
255  }

Member Data Documentation

std::string shs::ShowerHitSeparator::fHitLabel
private

Definition at line 59 of file ShowerHitSeparator_module.cc.

std::string shs::ShowerHitSeparator::fMVAClusterLabel
private

Definition at line 63 of file ShowerHitSeparator_module.cc.

art::Handle<std::vector<recob::Cluster> > shs::ShowerHitSeparator::fMVAClusters
private

Definition at line 78 of file ShowerHitSeparator_module.cc.

std::string shs::ShowerHitSeparator::fMVALabel
private

Definition at line 58 of file ShowerHitSeparator_module.cc.

double shs::ShowerHitSeparator::fMVAOutputCut
private

Definition at line 60 of file ShowerHitSeparator_module.cc.

Int_t shs::ShowerHitSeparator::fOutCryo
private

Definition at line 71 of file ShowerHitSeparator_module.cc.

Int_t shs::ShowerHitSeparator::fOutEvent
private

Definition at line 67 of file ShowerHitSeparator_module.cc.

bool shs::ShowerHitSeparator::fOutIsShw
private

Definition at line 75 of file ShowerHitSeparator_module.cc.

bool shs::ShowerHitSeparator::fOutIsTrk
private

Definition at line 76 of file ShowerHitSeparator_module.cc.

Int_t shs::ShowerHitSeparator::fOutPlane
private

Definition at line 72 of file ShowerHitSeparator_module.cc.

Int_t shs::ShowerHitSeparator::fOutRun
private

Definition at line 68 of file ShowerHitSeparator_module.cc.

Int_t shs::ShowerHitSeparator::fOutSubrun
private

Definition at line 69 of file ShowerHitSeparator_module.cc.

Int_t shs::ShowerHitSeparator::fOutTime
private

Definition at line 73 of file ShowerHitSeparator_module.cc.

Int_t shs::ShowerHitSeparator::fOutTPC
private

Definition at line 70 of file ShowerHitSeparator_module.cc.

TTree* shs::ShowerHitSeparator::fOutTree
private

Definition at line 66 of file ShowerHitSeparator_module.cc.

Int_t shs::ShowerHitSeparator::fOutWire
private

Definition at line 74 of file ShowerHitSeparator_module.cc.

bool shs::ShowerHitSeparator::fSaveTree
private

Definition at line 61 of file ShowerHitSeparator_module.cc.


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