472 for(
unsigned int icl = 0; icl < clsVecHandle->size(); ++icl) {
479 if(sTick > eTick)
std::swap(sTick, eTick);
480 float dTick = eTick - sTick;
482 std::vector<art::Ptr<recob::Hit> > clsHits;
483 clsHitsFind.get(icl, clsHits);
484 if(clsHits.size() == 0)
continue;
485 unsigned short tpc = clsHits[0]->WireID().TPC;
488 unsigned short nhist = 1 + (
unsigned short)(dTick /
fTicksPerBin);
490 if(clsHits.size() <
fMinHits)
continue;
501 std::vector<double> tck(nhist), ave(nhist), cnt(nhist),
err(nhist);
502 std::vector<float> minChg(nhist, 0);
503 std::vector<float> maxChg(nhist, 10000);
504 for(
unsigned short nit = 0; nit < 2; ++nit) {
505 for(
unsigned short ihist = 0; ihist < nhist; ++ihist) {
512 for(
auto& pht : clsHits) {
513 unsigned short ihist = (pht->PeakTime() - sTick) /
fTicksPerBin;
514 if(ihist > nhist - 1)
continue;
515 float chg = pht->Integral();
516 if(chg < minChg[ihist] || chg > maxChg[ihist])
continue;
517 tck[ihist] += pht->PeakTime() - sTick;
519 err[ihist] += chg * chg;
522 for(
unsigned short ihist = 0; ihist < nhist; ++ihist) if(cnt[ihist] > 0) {
523 tck[ihist] /= cnt[ihist];
524 ave[ihist] /= cnt[ihist];
528 for(
unsigned short ihist = 0; ihist < nhist; ++ihist) {
530 if(cnt[ihist] < 5)
continue;
531 maxChg[ihist] =
fChgCuts[1] * ave[ihist];
532 minChg[ihist] =
fChgCuts[0] * ave[ihist];
537 for(
unsigned short ihist = 0; ihist < nhist; ++ihist) {
538 if(cnt[ihist] < 3)
continue;
539 double arg =
err[ihist] - cnt[ihist] * ave[ihist] * ave[ihist];
545 err[ihist] = sqrt(arg / (cnt[ihist] - 1));
547 err[ihist] /= sqrt(cnt[ihist]);
553 unsigned short nok = 0;
554 for(
auto& icnt : cnt)
if(icnt > 4) ++nok;
574 double xx, yy, wght, arg;
577 for(
unsigned short ihist = 0; ihist < nhist; ++ihist) {
578 if(cnt[ihist] < 3)
continue;
579 if(
err[ihist] == 0)
continue;
580 xx = (tck[ihist] - tck[0]) * msPerTick;
581 yy = log(ave[ihist]);
583 arg = ave[ihist] /
err[ihist];
588 sumx2 += wght * xx * xx;
589 sumxy += wght * xx * yy;
590 sumy2 += wght * yy * yy;
594 double delta = sum * sumx2 - sumx * sumx;
595 if(delta == 0.)
continue;
596 double A = (sumx2 * sumy - sumx * sumxy) / delta;
598 double B = (sumxy * sum - sumx * sumy) / delta;
601 double ndof = fitcnt - 2;
602 double varnce = (sumy2 + A*A*sum + B*B*sumx2 - 2 * (A*sumy + B*sumxy - A*B*sumx)) / ndof;
603 if(varnce == 0)
continue;
612 for(
unsigned short ihist = 0; ihist < nhist; ++ihist) {
613 if(cnt[ihist] < 3)
continue;
614 if(
err[ihist] == 0)
continue;
615 xx = (tck[ihist] - tck[0]) * msPerTick;
616 yy = exp(A - xx * lifeInv);
617 arg = (yy - ave[ihist]) /
err[ihist];
629 fLife->Fill(1./lifeInv);
633 for(
auto& hcnt : cnt) selHits += hcnt;
634 selHits /= (double)(clsHits.size());
640 std::vector<std::pair<unsigned int, float>> chanPedRMS;
642 for(
unsigned int witer = 0; witer < wireVecHandle->size(); ++witer) {
645 for(
const auto& range : signalROI.
get_ranges()) {
646 const std::vector<float>& signal = range.data();
648 if(signal.size() != 1)
continue;
650 float rms = signal[0];
651 if(rms < 0.001) rms = 0.001;
652 chanPedRMS.push_back(std::make_pair(thisWire->Channel(),
rms));
658 for(
unsigned int icl = 0; icl < clsVecHandle->size(); ++icl) {
667 std::vector<art::Ptr<recob::Hit> > clsHits;
668 clsHitsFind.get(icl, clsHits);
670 unsigned short tpc = clsHits[0]->WireID().TPC;
674 for(
auto&
hit : clsHits) {
676 for(
auto& chrms : chanPedRMS) {
677 if(chrms.first !=
hit->Channel())
continue;
678 pedRMS = chrms.second;
681 if(pedRMS < 0)
continue;
682 float snr =
hit->PeakAmplitude() / pedRMS;
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
double rms(sqlite3 *db, std::string const &table_name, std::string const &column_name)
float StartWire() const
Returns the wire coordinate of the start of the cluster.
const range_list_t & get_ranges() const
Returns the internal list of non-void ranges.
float EndTick() const
Returns the tick coordinate of the end of the cluster.
geo::PlaneID Plane() const
Returns the plane ID this cluster lies on.
float StartAngle() const
Returns the starting angle of the cluster.
double signalToNoiseCnt[12]
void swap(Handle< T > &a, Handle< T > &b)
const std::array< size_t, 13 > tpcMapping
TProfile * fLifeInv_Angle
unsigned int signalToNoiseClsCnt[12]
PlaneID_t Plane
Index of the plane within its TPC.
void err(const char *fmt,...)
Detector simulation of raw signals on wires.
std::string fClusterModuleLabel
std::vector< float > fChgCuts
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
float StartTick() const
Returns the tick coordinate of the start of the cluster.
float EndWire() const
Returns the wire coordinate of the end of the cluster.