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

Public Member Functions

 OpFlashFinderDualPhase (const fhicl::ParameterSet &)
 
virtual ~OpFlashFinderDualPhase ()
 
void beginJob ()
 
void endJob ()
 
void reconfigure (fhicl::ParameterSet const &pset)
 
void produce (art::Event &)
 
void RunFlashFinder (std::vector< recob::OpHit > const &HitVector, std::vector< recob::OpFlash > &FlashVector, std::vector< std::vector< int > > &AssocList, geo::GeometryCore const &geom, detinfo::DetectorClocksData const &ts, float const &TrigCoinc)
 
void AddHitContribution (recob::OpHit const &currentHit, double &MaxTime, double &MinTime, double &AveTime, double &FastToTotal, double &AveAbsTime, double &TotalPE, std::vector< double > &PEs)
 
void GetHitGeometryInfo (recob::OpHit const &currentHit, geo::GeometryCore const &geom, std::vector< double > &sumw, std::vector< double > &sumw2, double &sumy, double &sumy2, double &sumz, double &sumz2)
 
double CalculateWidth (double const &sum, double const &sum_squared, double const &weights_sum)
 
std::vector< int > getNeighbors (std::vector< recob::OpHit > const &HitVector, int hitnumber, std::vector< bool > &processed, float initimecluster, std::vector< int > &sorted, geo::GeometryCore const &geom)
 
void AssignHitsToFlash (std::vector< recob::OpHit > const &HitVector, std::vector< std::vector< int > > &HitsPerFlash, geo::GeometryCore const &geom)
 
void ConstructFlash (std::vector< int > const &HitsPerFlashVec, std::vector< recob::OpHit > const &HitVector, std::vector< recob::OpFlash > &FlashVector, geo::GeometryCore const &geom, detinfo::DetectorClocksData const &ts, float const &TrigCoinc)
 
- 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 Attributes

std::string fInputModule
 
Double_t fMaximumDistance
 
Double_t fMaximumTimeDistance
 
Double_t fMaximumTimeWindow
 
Double_t fTrigCoinc
 

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

Constructor & Destructor Documentation

opdet::OpFlashFinderDualPhase::OpFlashFinderDualPhase ( const fhicl::ParameterSet pset)
explicit

Definition at line 115 of file OpFlashFinderDualPhase_module.cc.

116  : EDProducer{pset}
117  {
118 
119  reconfigure(pset);
120 
121  produces< std::vector< recob::OpFlash > >();
122  produces< art::Assns< recob::OpFlash, recob::OpHit > >();
123 
124  }
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
void reconfigure(fhicl::ParameterSet const &pset)
opdet::OpFlashFinderDualPhase::~OpFlashFinderDualPhase ( )
virtual

Definition at line 142 of file OpFlashFinderDualPhase_module.cc.

143  {
144  }

Member Function Documentation

void opdet::OpFlashFinderDualPhase::AddHitContribution ( recob::OpHit const &  currentHit,
double &  MaxTime,
double &  MinTime,
double &  AveTime,
double &  FastToTotal,
double &  AveAbsTime,
double &  TotalPE,
std::vector< double > &  PEs 
)

Definition at line 331 of file OpFlashFinderDualPhase_module.cc.

338  {
339 
340  double PEThisHit = currentHit.PE();
341  double TimeThisHit = currentHit.PeakTime();
342  if (TimeThisHit > MaxTime) MaxTime = TimeThisHit;
343  if (TimeThisHit < MinTime) MinTime = TimeThisHit;
344 
345  // These quantities for the flash are defined
346  // as the weighted averages over the hits
347  AveTime += PEThisHit*TimeThisHit;
348  FastToTotal += PEThisHit*currentHit.FastToTotal();
349  AveAbsTime += PEThisHit*currentHit.PeakTimeAbs();
350 
351  // These are totals
352  TotalPE += PEThisHit;
353  PEs.at(static_cast< unsigned int >(currentHit.OpChannel())) += PEThisHit;
354 
355  }
void opdet::OpFlashFinderDualPhase::AssignHitsToFlash ( std::vector< recob::OpHit > const &  HitVector,
std::vector< std::vector< int > > &  HitsPerFlash,
geo::GeometryCore const &  geom 
)

Definition at line 438 of file OpFlashFinderDualPhase_module.cc.

441  {
442 
443  int ntothits=HitVector.size();
444  std::size_t n(0);
445  std::vector<int> sorted;
446  sorted.resize(ntothits);
447  std::generate(std::begin(sorted), std::end(sorted), [&]{ return n++; });
448  std::sort( std::begin(sorted), std::end(sorted), [&](int i1, int i2) { return HitVector[i1].PeakTime() < HitVector[i2].PeakTime(); });
449 
450  HitsPerFlash.clear();
451 
452  std::vector<bool> processed;
453  processed.resize(HitVector.size(),false);
454 
455  for (unsigned int h=0;h<HitVector.size();h++)
456  {
457  if(!processed[h])
458  {
459  processed[h]=true;
460  std::vector<int> N; N.clear();
461  std::vector<int> nb =getNeighbors(HitVector,h, processed, HitVector[sorted[h]].PeakTime(),sorted,geom);
462  N.insert( N.end(), nb.begin(), nb.end() );
463 
464  for (unsigned int i=0;i<N.size();i++)
465  {
466  std::vector<int> nb2 =getNeighbors(HitVector,N[i], processed, HitVector[sorted[h]].PeakTime(),sorted,geom);
467  N.insert( N.end(), nb2.begin(), nb2.end() );
468  }
469  N.push_back(sorted[h]);
470  HitsPerFlash.push_back(N);
471  }
472  }
473 
474  } // End AssignHitsToFlash
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
static constexpr double nb
Definition: Units.h:81
std::vector< int > getNeighbors(std::vector< recob::OpHit > const &HitVector, int hitnumber, std::vector< bool > &processed, float initimecluster, std::vector< int > &sorted, geo::GeometryCore const &geom)
std::void_t< T > n
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:72
void opdet::OpFlashFinderDualPhase::beginJob ( )
virtual

Reimplemented from art::EDProducer.

Definition at line 147 of file OpFlashFinderDualPhase_module.cc.

148  {
149  }
double opdet::OpFlashFinderDualPhase::CalculateWidth ( double const &  sum,
double const &  sum_squared,
double const &  weights_sum 
)

Definition at line 390 of file OpFlashFinderDualPhase_module.cc.

392  {
393 
394  if (sum_squared*weights_sum - sum*sum < 0) return 0;
395  else return std::sqrt(sum_squared*weights_sum - sum*sum)/weights_sum;
396 
397  }
void opdet::OpFlashFinderDualPhase::ConstructFlash ( std::vector< int > const &  HitsPerFlashVec,
std::vector< recob::OpHit > const &  HitVector,
std::vector< recob::OpFlash > &  FlashVector,
geo::GeometryCore const &  geom,
detinfo::DetectorClocksData const &  ts,
float const &  TrigCoinc 
)

Definition at line 240 of file OpFlashFinderDualPhase_module.cc.

245  {
246 
247  double MaxTime = -1e9;
248  double MinTime = 1e9;
249 
250  std::vector< double > PEs(geom.MaxOpChannel() + 1, 0.0);
251  unsigned int Nplanes = geom.Nplanes();
252  std::vector< double > sumw (Nplanes, 0.0);
253  std::vector< double > sumw2(Nplanes, 0.0);
254 
255  double TotalPE = 0;
256  double AveTime = 0;
257  double AveAbsTime = 0;
258  double FastToTotal = 0;
259  double sumy = 0;
260  double sumz = 0;
261  double sumy2 = 0;
262  double sumz2 = 0;
263 
264  for (auto const& HitID : HitsPerFlashVec) {
265  AddHitContribution(HitVector.at(HitID),
266  MaxTime,
267  MinTime,
268  AveTime,
269  FastToTotal,
270  AveAbsTime,
271  TotalPE,
272  PEs);
273  GetHitGeometryInfo(HitVector.at(HitID),
274  geom,
275  sumw,
276  sumw2,
277  sumy,
278  sumy2,
279  sumz,
280  sumz2);
281  }
282 
283  AveTime /= TotalPE;
284  AveAbsTime /= TotalPE;
285  FastToTotal /= TotalPE;
286 
287  double meany = sumy/TotalPE;
288  double meanz = sumz/TotalPE;
289 
290  double widthy = CalculateWidth(sumy, sumy2, TotalPE);
291  double widthz = CalculateWidth(sumz, sumz2, TotalPE);
292 
293  std::vector< double > WireCenters(Nplanes, 0.0);
294  std::vector< double > WireWidths(Nplanes, 0.0);
295 
296  for (size_t p = 0; p != Nplanes; ++p) {
297  WireCenters.at(p) = sumw.at(p)/TotalPE;
298  WireWidths.at(p) = CalculateWidth(sumw.at(p), sumw2.at(p), TotalPE);
299  }
300 
301  // Emprical corrections to get the Frame right.
302  // Eventual solution - remove frames
303  int Frame = ts.OpticalClock().Frame(AveAbsTime - 18.1);
304  if (Frame == 0) Frame = 1;
305 
306  int BeamFrame = ts.OpticalClock().Frame(ts.TriggerTime());
307  bool InBeamFrame = false;
308  if (!(ts.TriggerTime() < 0)) InBeamFrame = (Frame == BeamFrame);
309 
310  double TimeWidth = (MaxTime - MinTime)/2.0;
311 
312  int OnBeamTime = 0;
313  if (InBeamFrame && (std::abs(AveTime) < TrigCoinc)) OnBeamTime = 1;
314 
315  FlashVector.emplace_back(AveTime,
316  TimeWidth,
317  AveAbsTime,
318  Frame,
319  PEs,
320  InBeamFrame,
321  OnBeamTime,
322  FastToTotal,
323  meany,
324  widthy,
325  meanz,
326  widthz,
327  WireCenters,
328  WireWidths);
329 
330  }
void GetHitGeometryInfo(recob::OpHit const &currentHit, geo::GeometryCore const &geom, std::vector< double > &sumw, std::vector< double > &sumw2, double &sumy, double &sumy2, double &sumz, double &sumz2)
double CalculateWidth(double const &sum, double const &sum_squared, double const &weights_sum)
T abs(T value)
p
Definition: test.py:223
void AddHitContribution(recob::OpHit const &currentHit, double &MaxTime, double &MinTime, double &AveTime, double &FastToTotal, double &AveAbsTime, double &TotalPE, std::vector< double > &PEs)
void opdet::OpFlashFinderDualPhase::endJob ( )
virtual

Reimplemented from art::EDProducer.

Definition at line 152 of file OpFlashFinderDualPhase_module.cc.

153  {
154  }
void opdet::OpFlashFinderDualPhase::GetHitGeometryInfo ( recob::OpHit const &  currentHit,
geo::GeometryCore const &  geom,
std::vector< double > &  sumw,
std::vector< double > &  sumw2,
double &  sumy,
double &  sumy2,
double &  sumz,
double &  sumz2 
)

Definition at line 358 of file OpFlashFinderDualPhase_module.cc.

365  {
366 
367  double xyz[3];
368  geom.OpDetGeoFromOpChannel(currentHit.OpChannel()).GetCenter(xyz);
369  double PEThisHit = currentHit.PE();
370 
371  geo::TPCID tpc = geom.FindTPCAtPosition(xyz);
372  // if the point does not fall into any TPC,
373  // it does not contribute to the average wire position
374  if (tpc.isValid) {
375  for (size_t p = 0; p != geom.Nplanes(); ++p) {
376  geo::PlaneID const planeID(tpc, p);
377  unsigned int w = geom.NearestWire(xyz, planeID);
378  sumw.at(p) += PEThisHit*w;
379  sumw2.at(p) += PEThisHit*w*w;
380  }
381  } // if we found the TPC
382  sumy += PEThisHit*xyz[1];
383  sumy2 += PEThisHit*xyz[1]*xyz[1];
384  sumz += PEThisHit*xyz[2];
385  sumz2 += PEThisHit*xyz[2]*xyz[2];
386 
387  }
The data type to uniquely identify a Plane.
Definition: geo_types.h:472
bool isValid
Whether this ID points to a valid element.
Definition: geo_types.h:211
p
Definition: test.py:223
The data type to uniquely identify a TPC.
Definition: geo_types.h:386
std::vector< int > opdet::OpFlashFinderDualPhase::getNeighbors ( std::vector< recob::OpHit > const &  HitVector,
int  hitnumber,
std::vector< bool > &  processed,
float  initimecluster,
std::vector< int > &  sorted,
geo::GeometryCore const &  geom 
)

Definition at line 400 of file OpFlashFinderDualPhase_module.cc.

401  {
402 
403  int itTmin=0;
404  int itTmax=HitVector.size();
405  for (int h=hitnumber;h>0;h--) if(HitVector[sorted[h]].PeakTime() < HitVector[sorted[hitnumber]].PeakTime()-fMaximumTimeDistance)
406  {
407  itTmin=h; break;
408  }
409  for (unsigned int h=hitnumber;h<HitVector.size();h++) if(HitVector[sorted[h]].PeakTime() > HitVector[sorted[hitnumber]].PeakTime()+fMaximumTimeDistance)
410  {
411  itTmax=h; break;
412  }
413 
414  std::vector<int> neighbors;
415  float dx, dy, dz, dt, dtmax;
416  double xyz_hitnumber[3];
417  geom.OpDetGeoFromOpChannel(HitVector[sorted[hitnumber]].OpChannel()).GetCenter(xyz_hitnumber);
418 
419  for (int h=itTmin;h<itTmax;h++)
420  {
421  if(!processed[h])
422  {
423  double xyz_h[3];
424  geom.OpDetGeoFromOpChannel(HitVector[sorted[h]].OpChannel()).GetCenter(xyz_h);
425  dx = xyz_h[0] - xyz_hitnumber[0];
426  dy = xyz_h[1] - xyz_hitnumber[1];
427  dz = xyz_h[2] - xyz_hitnumber[2];
428  dt = TMath::Abs( HitVector[sorted[hitnumber]].PeakTime() - HitVector[sorted[h]].PeakTime() );
429  dtmax = TMath::Abs(initimecluster - HitVector[sorted[h]].PeakTime() );
430  float distance = dx*dx + dy*dy + dz*dz;
431 // std::cout << distance << " " << dt << " " << dtmax << std::endl; lets_pause();
432  if(distance<fMaximumDistance*fMaximumDistance && dt<fMaximumTimeDistance && dtmax<fMaximumTimeWindow){ neighbors.push_back(h);processed[h]=true;}
433  }
434  }
435  return neighbors;
436  }
Index OpChannel(Index detNum, Index channel)
double distance(double x1, double y1, double z1, double x2, double y2, double z2)
void opdet::OpFlashFinderDualPhase::produce ( art::Event evt)
virtual

Implements art::EDProducer.

Definition at line 157 of file OpFlashFinderDualPhase_module.cc.

158  {
159 
160  // These are the storage pointers we will put in the event
161  std::unique_ptr< std::vector< recob::OpFlash > >
162  flashPtr(new std::vector< recob::OpFlash >);
163  std::unique_ptr< art::Assns< recob::OpFlash, recob::OpHit > >
165 
166  // This will keep track of what flashes will assoc to what ophits
167  // at the end of processing
168  std::vector< std::vector< int > > assocList;
169 
170  auto const& geometry(*lar::providerFrom< geo::Geometry >());
171 
172  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
173 
174  // Get OpHits from the event
175  auto opHitHandle = evt.getHandle< std::vector< recob::OpHit > >(fInputModule);
176 
177  RunFlashFinder(*opHitHandle,
178  *flashPtr,
179  assocList,
180  geometry,
181  clockData,
182  fTrigCoinc);
183 
184 
185 
186 
187  // Make the associations which we noted we need
188  for (size_t i = 0; i != assocList.size(); ++i)
189  {
190  art::PtrVector< recob::OpHit > opHitPtrVector;
191  for (int const& hitIndex : assocList.at(i))
192  {
193  art::Ptr< recob::OpHit > opHitPtr(opHitHandle, hitIndex);
194  opHitPtrVector.push_back(opHitPtr);
195  }
196 
197  util::CreateAssn(*this, evt, *flashPtr, opHitPtrVector,
198  *(assnPtr.get()), i);
199  }
200 
201  // Store results into the event
202  evt.put(std::move(flashPtr));
203  evt.put(std::move(assnPtr));
204 
205  }
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
void push_back(Ptr< U > const &p)
Definition: PtrVector.h:435
void RunFlashFinder(std::vector< recob::OpHit > const &HitVector, std::vector< recob::OpFlash > &FlashVector, std::vector< std::vector< int > > &AssocList, geo::GeometryCore const &geom, detinfo::DetectorClocksData const &ts, float const &TrigCoinc)
def move(depos, offset)
Definition: depos.py:107
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
bool CreateAssn(PRODUCER const &prod, art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t indx=UINT_MAX)
Creates a single one-to-one association.
void opdet::OpFlashFinderDualPhase::reconfigure ( fhicl::ParameterSet const &  pset)

Definition at line 127 of file OpFlashFinderDualPhase_module.cc.

128  {
129 
130  // Indicate that the Input Module comes from .fcl
131  fInputModule = pset.get< std::string >("InputModule");
132 
133  fTrigCoinc = pset.get< double >("TrigCoinc");
134  fMaximumDistance = pset.get< double >("MaximumDistance");
135  fMaximumTimeDistance = pset.get< double >("MaximumTimeDistance");
136  fMaximumTimeWindow = pset.get< double >("MaximumTimeWindow");
137 
138  }
std::string string
Definition: nybbler.cc:12
void opdet::OpFlashFinderDualPhase::RunFlashFinder ( std::vector< recob::OpHit > const &  HitVector,
std::vector< recob::OpFlash > &  FlashVector,
std::vector< std::vector< int > > &  AssocList,
geo::GeometryCore const &  geom,
detinfo::DetectorClocksData const &  ts,
float const &  TrigCoinc 
)

Definition at line 207 of file OpFlashFinderDualPhase_module.cc.

212  {
213 
214  // Now start to create flashes.
215  // First, need vector to keep track of which hits belong to which flashes
216  std::vector< std::vector< int > > HitsPerFlash;
217 
218  AssignHitsToFlash(HitVector,
219  HitsPerFlash,
220  geom);
221 
222  // Now we have all our hits assigned to a flash.
223  // Make the recob::OpFlash objects
224  for (auto const& HitsPerFlashVec : HitsPerFlash)
225  ConstructFlash(HitsPerFlashVec,
226  HitVector,
227  FlashVector,
228  geom,
229  ts,
230  TrigCoinc);
231 
232  // Finally, write the association list.
233  // back_inserter tacks the result onto the end of AssocList
234  for (auto& HitIndicesThisFlash : HitsPerFlash)
235  AssocList.push_back(HitIndicesThisFlash);
236 
237  } // End RunFlashFinder
void AssignHitsToFlash(std::vector< recob::OpHit > const &HitVector, std::vector< std::vector< int > > &HitsPerFlash, geo::GeometryCore const &geom)
void ConstructFlash(std::vector< int > const &HitsPerFlashVec, std::vector< recob::OpHit > const &HitVector, std::vector< recob::OpFlash > &FlashVector, geo::GeometryCore const &geom, detinfo::DetectorClocksData const &ts, float const &TrigCoinc)

Member Data Documentation

std::string opdet::OpFlashFinderDualPhase::fInputModule
private

Definition at line 93 of file OpFlashFinderDualPhase_module.cc.

Double_t opdet::OpFlashFinderDualPhase::fMaximumDistance
private

Definition at line 96 of file OpFlashFinderDualPhase_module.cc.

Double_t opdet::OpFlashFinderDualPhase::fMaximumTimeDistance
private

Definition at line 97 of file OpFlashFinderDualPhase_module.cc.

Double_t opdet::OpFlashFinderDualPhase::fMaximumTimeWindow
private

Definition at line 98 of file OpFlashFinderDualPhase_module.cc.

Double_t opdet::OpFlashFinderDualPhase::fTrigCoinc
private

Definition at line 99 of file OpFlashFinderDualPhase_module.cc.


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