7 #include "cetlib_except/exception.h" 13 #include "CoreUtils/ServiceUtil.h" 14 #include "Geometry/LocalTransformation.h" 30 fGeo = gar::providerFrom<geo::GeometryGAr>();
60 else if(fDet ==
"MuID") {
66 <<
"Detector system parameter incorrectly set. Should be ECAL or MuID -- Exiting!";
98 <<
"StripSplitterAlg::PrepareAlgo()";
110 unsigned int layer = hit->
Layer();
129 <<
"StripSplitterAlg::DoStripSplitting()";
132 std::vector <const gar::rec::CaloHit*> *toSplit;
139 for (
int icol = 0; icol < 2; icol++)
142 <<
"Start Loop " << icol;
161 for (
uint i = 0; i < toSplit->size(); i++)
167 if ( det_id != 1 && det_id != 2 && det_id != 4 )
170 <<
" Check det it " << det_id
171 <<
" Problem with Hit " << i
172 <<
" pointing at " << hit
173 <<
" at position ( " << hit->
Position()[0] <<
" cm , " << hit->
Position()[1] <<
" cm , " << hit->
Position()[2] <<
" cm )" 174 <<
" orientation " << (orientation ==
LONGITUDINAL ?
"LONGITUDINAL" :
"TRANSVERSE");
178 MF_LOG_DEBUG(
"StripSplitterAlg::DoStripSplitting") <<
"recohit " << hit
179 <<
" with cellID " << hit->
CellID()
184 std::vector <const gar::rec::CaloHit*> virtualhits;
185 bool isBarrel = (det_id == 0 || det_id == 4) ?
true :
false;
190 if (virtualhits.size() == 0)
194 <<
" Adding unsplit hit1 " << i
195 <<
" pointing at " << hit
196 <<
" orientation " << (orientation ==
LONGITUDINAL ?
"LONGITUDINAL" :
"TRANSVERSE");
202 for (
uint hh = 0; hh < virtualhits.size(); hh++)
206 <<
"adding virtual hit " << hh;
220 bool isBarrel, std::vector <const gar::rec::CaloHit*> &virtualhits)
223 <<
"StripSplitterAlg::getVirtualHits()";
229 int layer = hit->
Layer();
242 <<
" StripSplitterAlg::getVirtualHits()" 243 <<
" Strip splitted in " <<
fnVirtual <<
" virtual cells";
247 TVector3 stripDir = stripEnds.first - stripEnds.second;
252 ppp[0] = stripEnds.first.X();
253 ppp[1] = stripEnds.first.Y();
254 ppp[2] = stripEnds.first.Z();
259 ppp[0] = stripEnds.second.X();
260 ppp[1] = stripEnds.second.Y();
261 ppp[2] = stripEnds.second.Z();
268 int splitterOrientation;
269 std::vector <const gar::rec::CaloHit*> *splitterVec;
282 std::map <int, float> virtEnergy;
287 for (
int jj = 0; jj < 2; jj++)
289 std::vector <const gar::rec::CaloHit*> *splitter = splitterVec;
291 for (
uint i = 0; i < splitter->size(); i++)
296 int layer2 = hit2->
Layer();
300 int ddetid =
std::abs(detid2 - detid);
301 int dlayer =
std::abs(layer2 - layer);
302 int dstave =
std::abs(stave2 - stave);
303 int dmodule =
std::abs(module2 - module);
308 if(ddetid != 0)
continue;
313 if (dmodule == 0 && dstave == 0 && dlayer > 1)
continue;
318 if ( dstave == 0 && dmodule > 1 )
continue;
319 if ( dmodule == 0 && dstave > 1 )
continue;
320 if ( dstave == 0 && dlayer > 1)
continue;
328 dstave =
std::min( dstave, 4 - dstave);
329 if (dmodule != 0)
continue;
330 if (dstave > 1)
continue;
331 if (dlayer > 1)
continue;
335 <<
" Getting hit2 " << i
336 <<
" pointing at " << hit2
337 <<
" orientation " << (splitterOrientation ==
LONGITUDINAL ?
"LONGITUDINAL" :
"TRANSVERSE")
338 <<
" dtave " << dstave
339 <<
" dmodule " << dmodule
340 <<
" dlayer " << dlayer;
347 <<
" Distance between hit1 and hit2 " << dist
353 TVector3 stripDir2(0, 0, 0);
358 stripDir2 = stripEnds2.first - stripEnds2.second;
362 TVector3 intercept =
stripIntersect(hit, stripDir, hit2, stripDir2);
364 if (intercept.Mag() > 0)
368 for (
int ii = 0; ii < 3; ii++) {
369 float dx = stripEnds.second[ii] - stripEnds.first[ii];
370 if (std::fabs(dx) > 0.1) {
371 frac = ( intercept[ii] - stripEnds.first[ii] ) / dx;
376 if (frac >= 0.0 && frac <= 1.0)
379 if (segment >= 0 && segment < fnVirtual)
381 if (virtEnergy.find(segment) != virtEnergy.end())
383 virtEnergy[segment] += hit2->
Energy();
385 virtEnergy[segment] = hit2->
Energy();
391 pos[0] = intercept.X();
392 pos[1] = intercept.Y();
393 pos[2] = intercept.Z();
401 <<
"strange segment " << segment
402 <<
" frac = " << frac
407 <<
"strange frac " << frac;
414 <<
" Number of splitters " << nSplitters;
419 totenergy += it->second;
426 TVector3 virtualCentre = stripEnds.second - stripEnds.first;
427 virtualCentre *= (it->first + 0.5) /
fnVirtual;
428 virtualCentre += stripEnds.first;
431 pos[0] = virtualCentre.X();
432 pos[1] = virtualCentre.Y();
433 pos[2] = virtualCentre.Z();
439 <<
" Creating new virtual hit pointing at " << newhit
440 <<
" Energy " << energy
441 <<
" Position " << pos[0] <<
" " << pos[1] <<
" " << pos[2];
443 virtualhits.emplace_back(newhit);
456 TVector3 stripCentre[2];
465 TVector3 stripDir[2];
472 for (
int i = 0; i < 2; i++)
474 if ( stripDir[i].Mag() > 1
e-10 ) {
478 stripDir[i] = stripDir[1-i].Cross(stripCentre[i]);
481 stripDir[i] *= 1. / stripDir[i].Mag();
484 if (not isStrip[0]) {
486 <<
"first hit should be a strip";
491 for (
int j = 0; j < 2; j++) {
492 for (
int i = 0; i < 2; i++) {
494 p[j][i] = stripCentre[j] -
std::pow(-1, i) * 0.5 * ll * stripDir[j];
498 TVector3 pNorm[2][2];
499 for (
int j = 0; j < 2; j++) {
500 for (
int i = 0; i < 2; i++) {
501 float mm = p[j][i].Mag();
502 pNorm[j][i] = p[j][i];
503 pNorm[j][i] *= 1./
mm;
508 for (
int j = 0; j < 2; j++) {
509 inPlane[j] = p[j][0] - p[j][1];
513 TVector3 normal = inPlane[0].Cross(inPlane[1]);
514 float mag = normal.Mag();
518 TVector3 point(p[0][0] + p[0][1]);
524 for (
int i = 0; i < 2; i++) {
525 float d = ((point - p[1][i]).Dot(normal)) / (pNorm[1][i].Dot(normal));
526 qPrime[i] = p[1][i] + d * pNorm[1][i];
530 TVector3
a(p[0][1] - p[0][0]);
531 TVector3
b(qPrime[1] - qPrime[0]);
532 TVector3
c(qPrime[0] - p[0][0]);
534 float factor = ( c.Cross(b) ).Dot( a.Cross(b) ) / ( ( a.Cross(b) ).Mag2() );
536 TVector3
x = p[0][0] + a*factor;
539 bool intersect =
true;
540 for (
int ii = 0; ii < 2; ii++) {
541 for (
int j = 0; j < 3; j++) {
542 float d0 = ii ==0 ? x[j] - p[0][0][j] : x[j] - qPrime[0][j];
543 float d1 = ii ==0 ? x[j] - p[0][1][j] : x[j] - qPrime[1][j];
544 if ( d0 * d1 > 1
e-10 ) {
551 <<
"Intersection found " << intersect;
553 if (intersect)
return x;
554 else return TVector3(0,0,0);
gar::geo::GeometryCore const * fGeo
geometry information
std::pair< TVector3, TVector3 > GetStripEnds(const std::array< double, 3 > &point, const gar::raw::CellID_t &cID) const
const std::string GetMuIDCellIDEncoding() const
int GetECALInnerSymmetry() const
raw::CellID_t CellID() const
TVector3 stripIntersect(const gar::rec::CaloHit *hit0, const TVector3 &dir0, const gar::rec::CaloHit *hit1, const TVector3 &dir1)
std::vector< const gar::rec::CaloHit * > m_CaloHitVecEven
std::vector< const gar::rec::CaloHit * > m_CaloHitVecOdd
double getStripWidth(const std::array< double, 3 > &point) const
std::pair< float, float > Time() const
#define MF_LOG_ERROR(category)
static constexpr double MeV
double getStripLength(const std::array< double, 3 > &point, const gar::raw::CellID_t &cID) const
std::vector< const gar::rec::CaloHit * > fIntersectionHits
static bool SortByLayer(const gar::rec::CaloHit *rha, const gar::rec::CaloHit *rhb)
unsigned int Layer() const
StripSplitterAlg(fhicl::ParameterSet const &pset)
gar::geo::BitFieldCoder const * fFieldDecoder
static constexpr double GeV
Helper class for decoding and encoding a bit field of 64bits for convenient declaration.
T get(std::string const &key) const
std::vector< const gar::rec::CaloHit * > splitStripHits
std::vector< const gar::rec::CaloHit * > fStripEndsHits
Detector simulation of raw signals on wires.
General GArSoft Utilities.
long64 get(long64 bitfield, size_t index) const
const float * Position() const
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
const std::string GetECALCellIDEncoding() const
void PrepareAlgo(const std::vector< art::Ptr< gar::rec::CaloHit > > &hitVector)
static constexpr double mm
virtual ~StripSplitterAlg()
void reconfigure(fhicl::ParameterSet const &pset)
art framework interface to geometry description
int GetMuIDInnerSymmetry() const
std::vector< const gar::rec::CaloHit * > unSplitStripHits
cet::coded_exception< error, detail::translate > exception
void getVirtualHits(const gar::rec::CaloHit *hit, int orientation, bool isBarrel, std::vector< const gar::rec::CaloHit * > &virtualhits)