10 #ifndef OpFlashFinderDualPhase_H 11 #define OpFlashFinderDualPhase_H 1 55 std::vector< recob::OpFlash >& FlashVector,
59 float const& TrigCoinc);
67 std::vector< double >& PEs);
70 std::vector< double >& sumw,
71 std::vector< double >& sumw2,
77 double const& sum_squared,
78 double const& weights_sum);
79 std::vector<int>
getNeighbors( std::vector< recob::OpHit >
const& HitVector,
81 std::vector<bool> &processed,
float initimecluster, std::vector<int> &sorted,
geo::GeometryCore const& geom);
85 std::vector< recob::OpHit >
const& HitVector,
86 std::vector< recob::OpFlash >& FlashVector,
89 float const& TrigCoinc);
121 produces< std::vector< recob::OpFlash > >();
122 produces< art::Assns< recob::OpFlash, recob::OpHit > >();
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 > >
168 std::vector< std::vector< int > > assocList;
170 auto const& geometry(*lar::providerFrom< geo::Geometry >());
188 for (
size_t i = 0; i != assocList.size(); ++i)
191 for (
int const& hitIndex : assocList.at(i))
198 *(assnPtr.get()), i);
208 std::vector< recob::OpFlash >& FlashVector,
212 float const& TrigCoinc) {
216 std::vector< std::vector< int > > HitsPerFlash;
224 for (
auto const& HitsPerFlashVec : HitsPerFlash)
234 for (
auto& HitIndicesThisFlash : HitsPerFlash)
235 AssocList.push_back(HitIndicesThisFlash);
241 std::vector< recob::OpHit >
const&
HitVector,
242 std::vector< recob::OpFlash >& FlashVector,
245 float const& TrigCoinc) {
247 double MaxTime = -1e9;
248 double MinTime = 1e9;
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);
257 double AveAbsTime = 0;
258 double FastToTotal = 0;
264 for (
auto const& HitID : HitsPerFlashVec) {
284 AveAbsTime /= TotalPE;
285 FastToTotal /= TotalPE;
287 double meany = sumy/TotalPE;
288 double meanz = sumz/TotalPE;
293 std::vector< double > WireCenters(Nplanes, 0.0);
294 std::vector< double > WireWidths(Nplanes, 0.0);
296 for (
size_t p = 0;
p != Nplanes; ++
p) {
297 WireCenters.at(
p) = sumw.at(
p)/TotalPE;
304 if (Frame == 0) Frame = 1;
307 bool InBeamFrame =
false;
308 if (!(ts.
TriggerTime() < 0)) InBeamFrame = (Frame == BeamFrame);
310 double TimeWidth = (MaxTime - MinTime)/2.0;
313 if (InBeamFrame && (
std::abs(AveTime) < TrigCoinc)) OnBeamTime = 1;
315 FlashVector.emplace_back(AveTime,
338 std::vector< double >& PEs) {
340 double PEThisHit = currentHit.
PE();
341 double TimeThisHit = currentHit.
PeakTime();
342 if (TimeThisHit > MaxTime) MaxTime = TimeThisHit;
343 if (TimeThisHit < MinTime) MinTime = TimeThisHit;
347 AveTime += PEThisHit*TimeThisHit;
352 TotalPE += PEThisHit;
353 PEs.at(static_cast< unsigned int >(currentHit.
OpChannel())) += PEThisHit;
360 std::vector< double >& sumw,
361 std::vector< double >& sumw2,
369 double PEThisHit = currentHit.
PE();
375 for (
size_t p = 0;
p != geom.
Nplanes(); ++
p) {
378 sumw.at(
p) += PEThisHit*
w;
379 sumw2.at(
p) += PEThisHit*w*
w;
382 sumy += PEThisHit*xyz[1];
383 sumy2 += PEThisHit*xyz[1]*xyz[1];
384 sumz += PEThisHit*xyz[2];
385 sumz2 += PEThisHit*xyz[2]*xyz[2];
391 double const& sum_squared,
392 double const& weights_sum) {
394 if (sum_squared*weights_sum - sum*sum < 0)
return 0;
395 else return std::sqrt(sum_squared*weights_sum - sum*sum)/weights_sum;
404 int itTmax=HitVector.size();
405 for (
int h=hitnumber;
h>0;
h--)
if(HitVector[sorted[
h]].PeakTime() < HitVector[sorted[hitnumber]].PeakTime()-
fMaximumTimeDistance)
409 for (
unsigned int h=hitnumber;
h<HitVector.size();
h++)
if(HitVector[sorted[
h]].PeakTime() > HitVector[sorted[hitnumber]].PeakTime()+
fMaximumTimeDistance)
414 std::vector<int> neighbors;
415 float dx, dy, dz, dt, dtmax;
416 double xyz_hitnumber[3];
419 for (
int h=itTmin;
h<itTmax;
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;
443 int ntothits=HitVector.size();
445 std::vector<int> sorted;
446 sorted.resize(ntothits);
448 std::sort(
std::begin(sorted),
std::end(sorted), [&](
int i1,
int i2) {
return HitVector[i1].PeakTime() < HitVector[i2].PeakTime(); });
450 HitsPerFlash.clear();
452 std::vector<bool> processed;
453 processed.resize(HitVector.size(),
false);
455 for (
unsigned int h=0;
h<HitVector.size();
h++)
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() );
464 for (
unsigned int i=0;i<N.size();i++)
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() );
469 N.push_back(sorted[h]);
470 HitsPerFlash.push_back(N);
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
double FastToTotal() const
Index OpChannel(Index detNum, Index channel)
static constexpr double nb
void GetHitGeometryInfo(recob::OpHit const ¤tHit, 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)
Handle< PROD > getHandle(SelectorBase const &) const
void produce(art::Event &)
EDProducer(fhicl::ParameterSet const &pset)
OpFlashFinderDualPhase(const fhicl::ParameterSet &)
The data type to uniquely identify a Plane.
bool isValid
Whether this ID points to a valid element.
Double_t fMaximumTimeWindow
void GetCenter(double *xyz, double localz=0.0) const
constexpr int Frame() const noexcept
Returns the number of the frame containing the clock current time.
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)
art framework interface to geometry description
geo::TPCID FindTPCAtPosition(double const worldLoc[3]) const
Returns the ID of the TPC at specified location.
unsigned int Nplanes(unsigned int tpc=0, unsigned int cstat=0) const
Returns the total number of wire planes in the specified TPC.
#define DEFINE_ART_MODULE(klass)
void push_back(Ptr< U > const &p)
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)
virtual ~OpFlashFinderDualPhase()
T get(std::string const &key) const
geo::WireID::WireID_t NearestWire(geo::Point_t const &point, geo::PlaneID const &planeid) const
Returns the index of wire closest to position in the specified TPC.
Double_t fMaximumTimeDistance
ElecClock const & OpticalClock() const noexcept
Borrow a const Optical clock with time set to Trigger time [us].
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
unsigned int MaxOpChannel() const
Largest optical channel number.
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.
double distance(double x1, double y1, double z1, double x2, double y2, double z2)
The data type to uniquely identify a TPC.
Description of geometry of one entire detector.
double TriggerTime() const
Trigger electronics clock time in [us].
std::vector< reco::ClusterHit2D * > HitVector
What follows are several highly useful typedefs which we want to expose to the outside world...
void AssignHitsToFlash(std::vector< recob::OpHit > const &HitVector, std::vector< std::vector< int > > &HitsPerFlash, geo::GeometryCore const &geom)
Contains all timing reference information for the detector.
void reconfigure(fhicl::ParameterSet const &pset)
double PeakTimeAbs() const
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Double_t fMaximumDistance
void AddHitContribution(recob::OpHit const ¤tHit, double &MaxTime, double &MinTime, double &AveTime, double &FastToTotal, double &AveAbsTime, double &TotalPE, std::vector< double > &PEs)
OpDetGeo const & OpDetGeoFromOpChannel(unsigned int OpChannel) const
Returns the geo::OpDetGeo object for the given channel number.
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)