89 consumes< std::vector<gar::rec::Hit> >(hitTag);
90 produces< std::vector<gar::rec::TPCCluster> >();
91 produces< art::Assns<gar::rec::Hit, gar::rec::TPCCluster> >();
102 float xtpccent = euclid->TPCXCent();
103 float ytpccent = euclid->TPCYCent();
104 float ztpccent = euclid->TPCZCent();
109 auto const& hits = *hitHandle;
113 std::unique_ptr<std::vector<gar::rec::TPCCluster> > TPCClusterCol (
new std::vector<gar::rec::TPCCluster> );
114 std::unique_ptr<art::Assns<gar::rec::Hit,gar::rec::TPCCluster> > hitClusterAssns(new ::art::Assns<gar::rec::Hit,gar::rec::TPCCluster>);
119 size_t nhits = hits.size();
120 std::vector<float> hptmp(nhits);
121 std::vector<int> hsi(nhits);
122 std::vector<int> used(nhits,0);
126 for (
size_t ihit=0;ihit<nhits;++ihit)
128 hptmp[ihit] = hits.at(ihit).Position()[0];
130 TMath::Sort( (
int) nhits, hptmp.data(), hsi.data() );
134 for (
size_t ihitx=0; ihitx< nhits; ++ihitx)
136 size_t ihit = hsi[ihitx];
137 if (used[ihit])
continue;
139 const float *xyz_fromhit = hits.at(ihit).Position();
140 float xyz[3] = {xyz_fromhit[0] -xtpccent, xyz_fromhit[1] -ytpccent, xyz_fromhit[2] -ztpccent};
143 std::vector<size_t> hitsinclus;
144 hitsinclus.push_back(ihit);
148 auto hitchan = hits.at(ihit).Channel();
149 float chanpos[3] = {0,0,0};
150 euclid->ChannelToPosition(hitchan, chanpos);
151 if (chanpos[0] > xtpccent)
166 std::cout <<
"Started a new TPC cluster. Pos= " << xyz[0] <<
" " << xyz[1] <<
" " << xyz[2] <<
std::endl;
167 std::cout <<
"Side: " << side <<
std::endl;
172 bool In_CROC = rHit < euclid->GetIROCInnerRadius();
173 bool In_IROC = euclid->GetIROCInnerRadius() < rHit && rHit < euclid->GetIROCOuterRadius();
174 bool InIOROC = euclid->GetOROCInnerRadius() < rHit && rHit < euclid->GetOROCPadHeightChangeRadius();
175 bool InOOROC = euclid->GetOROCPadHeightChangeRadius() < rHit && rHit < euclid->GetOROCOuterRadius();
177 for (
size_t ix = ihitx+1; ix<nhits; ++ix)
179 size_t ihc = hsi[ix];
180 if (used[ihc])
continue;
183 auto hitchantest = hits.at(ihc).Channel();
184 float chanpostest[3] = {0,0,0};
185 euclid->ChannelToPosition(hitchantest, chanpostest);
186 if (chanpostest[0] > xtpccent)
194 if (sidetest != side)
continue;
196 const float *xyz2_fromhit = hits.at(ihc).Position();
197 float xyz2[3] = {xyz2_fromhit[0] -xtpccent, xyz2_fromhit[1] -ytpccent, xyz2_fromhit[2] -ztpccent};
201 std::cout <<
" Testing a hit: " << xyz2[0] <<
" " << xyz2[1] <<
" " << xyz2[2] <<
" " << sidetest <<
" " 202 << used[ihc] <<
" " << ihc <<
" " << ix <<
std::endl;
214 float RhatY = xyz[1]/
std::hypot(xyz[1],xyz[2]);
215 float RhatZ = xyz[2]/
std::hypot(xyz[1],xyz[2]);
216 float clustDist =
std::hypot(xyz2[1] -xyz[1],xyz2[2] -xyz[2]);
217 float dR = TMath::Abs((xyz2[1] -xyz[1])*RhatY +(xyz2[2] -xyz[2])*RhatZ);
218 float Rdfi = sqrt(clustDist*clustDist -dR*dR);
233 hitsinclus.push_back(ihc);
237 std::cout <<
"Added hit with pos: " << xyz2[0] <<
" " << xyz2[1] <<
" " << xyz2[2] <<
std::endl;
244 double cpos[3] = {0,0,0};
250 double cov[3][3] = { {0,0,0}, {0,0,0}, {0,0,0} };
252 for (
size_t ix = 0; ix < hitsinclus.size(); ++ix)
254 size_t ihx = hitsinclus.at(ix);
255 double hsig = hits.at(ihx).Signal();
257 for (
size_t idim=0; idim<3; ++idim)
259 cpos[idim] += hsig * hits.at(ihx).Position()[idim];
261 ctime += hsig * hits.at(ihx).Time();
264 cstime = hits.at(ihx).StartTime();
265 cetime = hits.at(ihx).EndTime();
269 cstime = TMath::Min(cstime, (
double) hits.at(ihx).StartTime());
270 cetime = TMath::Max(cetime, (
double) hits.at(ihx).EndTime());
276 for (
size_t idim=0; idim<3; ++idim)
283 for (
size_t ix = 0; ix < hitsinclus.size(); ++ix)
285 size_t ihx = hitsinclus.at(ix);
286 double cfrac = hits.at(ihx).Signal()/csig;
287 const float *hpos = hits.at(ihx).Position();
288 for (
size_t idim=0; idim<3; ++idim)
290 for (
size_t jdim=0; jdim<3; ++jdim)
292 cov[idim][jdim] += cfrac*(hpos[idim]-cpos[idim])*(hpos[jdim]-cpos[jdim]);
295 cov[0][0] += cfrac*TMath::Sq(hits.at(ihx).RMS());
298 crms = TMath::Sqrt(cov[0][0]);
300 float fcpos[3] = {0,0,0};
301 for (
int i=0;i<3;++i)
305 float fccov[6] = {(
float) cov[0][0], (
float) cov[1][0], (
float) cov[2][0],
306 (
float) cov[1][1], (
float) cov[1][2], (
float) cov[2][2]};
308 TPCClusterCol->emplace_back(csig,
318 std::cout <<
"Made a TPC Cluster pos: " << fcpos[0] <<
" " << fcpos[1] <<
" " << fcpos[2] <<
319 " signal: " << csig <<
" nHits: " << hitsinclus.size() <<
std::endl;
321 auto const TPCClusterPointer = TPCClusterPtrMaker(TPCClusterCol->size()-1);
322 for (
size_t i=0; i<hitsinclus.size(); ++i)
324 auto const HitPointer = hitPtrMaker(hitsinclus.at(i));
325 hitClusterAssns->addSingle(HitPointer,TPCClusterPointer);
float fHitClusterDyDz
range in cm to look for hits to cluster in y and z
float fHitClusterDr_I
range in R to look for hits to cluster for IROC, in cm
std::string fHitLabel
label of module to get the hits from
EDProducer(fhicl::ParameterSet const &pset)
float fHitClusterDrOO
range in R to look for hits to cluster for OOROC, in cm
float fHitClusterDfi_I
range in R*dPhi to look for hits to cluster for IROC, in cm
std::enable_if_t< std::is_arithmetic_v< T >, T > hypot(T x, T y)
float fHitClusterDx
range in cm to look for hits to cluster in x
#define DEFINE_ART_MODULE(klass)
float fHitClusterDfiIO
range in R*dPhi to look for hits to cluster for IROC, in cm
float fHitClusterDrIO
range in R to look for hits to cluster for IOROC, in cm
float fHitClusterDfiOO
range in R*dPhi to look for hits to cluster for IROC, in cm
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
TPCHitCluster & operator=(TPCHitCluster const &)=delete
int fClusterHits
hit clustering algorithm number
General GArSoft Utilities.
TPCHitCluster(fhicl::ParameterSet const &p)
int fPrintLevel
debug printout: 0: none, 1: selected, 2: all
art framework interface to geometry description
QTextStream & endl(QTextStream &s)
void produce(art::Event &e) override