45 std::ifstream counterfile(filename);
48 if(counterfile.is_open()){
58 while(std::getline(counterfile,line)){
61 if(line.at(0) !=
'#'){
64 geometry.push_back(std::vector<double>());
65 ncounter = geometry.size()-1;
68 std::istringstream issline(line);
71 while(issline >> value){
74 geometry[ncounter].push_back(value);
97 if(geometry.size() != 0){
101 for(
unsigned int i=0; i<geometry.size(); i++){
105 if(geometry[i].
size() < 11){
116 if((geometry[i].
size()-2) % 3 != 0){
143 TVector3 trackpoint, TVector3 trackdirection,
157 int counterFlag = -1;
160 for(
unsigned int igeo=0; igeo<geometry.size(); igeo++){
163 counterID = geometry[igeo][0];
164 counterFlag = geometry[igeo][1];
167 if(counterFlag != 0){
171 TVector3 insectionPoint(0.,0.,0.);
173 int inside =
testTrackInCounter(trackpoint, trackdirection, geometry[igeo], insectionPoint);
181 hitcounters.push_back(std::vector<double>());
182 int ncounter = hitcounters.size()-1;
185 hitcounters[ncounter].push_back(counterID);
186 hitcounters[ncounter].push_back(counterFlag);
187 hitcounters[ncounter].push_back(trackID);
188 hitcounters[ncounter].push_back(insectionPoint.X());
189 hitcounters[ncounter].push_back(insectionPoint.Y());
190 hitcounters[ncounter].push_back(insectionPoint.Z());
198 return hitcounters.size();
205 std::vector<double> &singlecountergeometry,
206 TVector3 &intersectionpoint){
220 std::vector<TVector3> points;
224 for(
unsigned int icoord=2; icoord<singlecountergeometry.size(); icoord=icoord+3){
226 TVector3 temppoint(singlecountergeometry[icoord],singlecountergeometry[icoord+1],
227 singlecountergeometry[icoord+2]);
229 points.push_back(temppoint);
238 double a = points[0].Y()*(points[1].Z()-points[2].Z())
239 + points[1].
Y()*(points[2].Z()-points[0].Z())
240 + points[2].
Y()*(points[0].Z()-points[1].Z());
242 double b = points[0].Z()*(points[1].X()-points[2].X())
243 + points[1].
Z()*(points[2].X()-points[0].X())
244 + points[2].
Z()*(points[0].X()-points[1].X());
246 double c = points[0].X()*(points[1].Y()-points[2].Y())
247 + points[1].
X()*(points[2].Y()-points[0].Y())
248 + points[2].
X()*(points[0].Y()-points[1].Y());
250 double d = - points[0].X()*(points[1].Y()*points[2].Z() - points[2].Y()*points[1].Z())
251 - points[1].
X()*(points[2].Y()*points[0].Z() - points[0].Y()*points[2].Z())
252 - points[2].
X()*(points[0].Y()*points[1].Z() - points[1].Y()*points[0].Z());
258 for(
unsigned int p=3;
p<points.size();
p++){
260 double plane = a*points[
p].X() + b*points[
p].Y() + c*points[
p].Z() +
d;
273 double mag = sqrt(a*a + b*b + c*c);
286 TVector3 planepoint = points[2];
287 TVector3 planenorm(a, b, c);
291 TVector3 diff = planepoint - trackpoint;
297 double num = diff * planenorm;
302 double den = trackdirection * planenorm;
311 int found_plane_intersection = 0;
315 TVector3 planeinterpoint(0.,0.,0.);
317 if(fabs(den) > 0.0001){
326 planeinterpoint = r*trackdirection + trackpoint;
330 found_plane_intersection = 1;
346 if(found_plane_intersection){
350 double xdiff = 0.;
double xdiffmax = 0;
351 double ydiff = 0.;
double ydiffmax = 0;
352 double zdiff = 0.;
double zdiffmax = 0;
354 for(
unsigned int p=1;
p<points.size();
p++){
356 xdiff = points[
p].X() - points[
p-1].X();
357 if(xdiff > xdiffmax) xdiffmax = xdiff;
359 ydiff = points[
p].Y() - points[
p-1].Y();
360 if(ydiff > ydiffmax) ydiffmax = ydiff;
362 zdiff = points[
p].Z() - points[
p-1].Z();
363 if(zdiff > zdiffmax) zdiffmax = zdiff;
374 double *vert1 = NULL;
375 vert1 = (
double*) realloc(vert1,points.size()*
sizeof(double));
377 double *vert2 = NULL;
378 vert2 = (
double*) realloc(vert2,points.size()*
sizeof(double));
380 if(vert1 != NULL && vert2 != NULL){
382 for(
unsigned int i=0; i<points.size(); i++){
394 if(xdiffmax < ydiffmax && xdiffmax <= zdiffmax){
398 for(
unsigned int i=0; i<points.size(); i++){
400 vert1[i] = points[i].Y();
401 vert2[i] = points[i].Z();
405 test1 = planeinterpoint.Y();
406 test2 = planeinterpoint.Z();
409 else if(ydiffmax < xdiffmax && ydiffmax <= zdiffmax){
413 for(
unsigned int i=0; i<points.size(); i++){
415 vert1[i] = points[i].X();
416 vert2[i] = points[i].Z();
420 test1 = planeinterpoint.X();
421 test2 = planeinterpoint.Z();
424 else if (zdiffmax < xdiffmax && zdiffmax < ydiffmax){
428 for(
unsigned int i=0; i<points.size(); i++){
430 vert1[i] = points[i].X();
431 vert2[i] = points[i].Y();
435 test1 = planeinterpoint.X();
436 test2 = planeinterpoint.Y();
454 if(intersect) intersectionpoint = planeinterpoint;
467 double testx,
double testy){
479 for(i = 0, j = nvert - 1; i < nvert; j = i++){
481 if( ((verty[i] > testy) != (verty[j] > testy)) &&
482 (testx < (vertx[j]-vertx[i]) * (testy-verty[i]) / (verty[j]-verty[i]) + vertx[i]) ){
MuonCounter35Alg(fhicl::ParameterSet const &p)
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
static int testTrackInCounter(TVector3 trackpoint, TVector3 trackvector, std::vector< double > &singlecountergeometry, TVector3 &intersectionpoint)
static int loadMuonCounterGeometry(char *filename, std::vector< std::vector< double > > &geometry)
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
static int testPointInPolygon(int nvert, double *vertx, double *verty, double testx, double testy)
Interface to algorithm class for DUNE 35t muon counters.
void line(double t, double *p, double &x, double &y, double &z)
static int testTrackInAllCounters(int trackID, TVector3 trackpoint, TVector3 trackvector, std::vector< std::vector< double > > &geometry, std::vector< std::vector< double > > &hitcounters)
LArSoft geometry interface.
virtual ~MuonCounter35Alg()