bool DetectorModule::couldHit(const XYZVector& direction, double zError) const { double eta = direction.Eta(); double phi = direction.Phi(); double shiftPhi = phi + 2*M_PI; bool withinEta = false; bool withinPhi = false; // Eta region covered by module if (eta > minEtaWithError(zError) && eta < maxEtaWithError(zError)) withinEta = true; // Phi region is from <-pi;+3*pi> due to crossline at +pi -> need to check phi & phi+2*pi if ( (phi >=minPhi() && phi <=maxPhi()) || (shiftPhi>=minPhi() && shiftPhi<=maxPhi()) ) withinPhi = true; // Checking that hit within a module region works for barrel-type modules only!!! if (this->shape()==ModuleShape::RECTANGULAR) return (withinEta && withinPhi); // ATTENTION: For wedge shaped modules, min, max procedure will not work correctly -> return true to avoid errors --> will be implemented in the future else return true; }
int testVector3D() { std::cout << "\n************************************************************************\n " << " Vector 3D Test" << "\n************************************************************************\n"; //CINT cannot autoload classes known only via a typedef (here XYZVector) gSystem->Load("libGenVector"); XYZVector v1(0.01, 0.02, 16); //XYZVector v1(1.0, 2.0, 3.0); // XYZVector v1(1.0, 2.0, 30.0); // double R = sqrt (v1.X()*v1.X() + v1.Y()*v1.Y() + v1.Z()*v1.Z()); // // this formula in not precise enough // // double Theta = R>0 ? acos ( v1.Z()/r ) : 0; // double Rho = sqrt (v1.X()*v1.X() + v1.Y()*v1.Y()); // double Theta = v1.Z() == 0 || Rho == 0 ? 0 : atan2( Rho, v1.Z() ); // double Phi = Rho>0 ? atan2 (v1.Y(), v1.X()) : 0; std::cout << "Test Cartesian-Polar : " ; Polar3DVector v2(v1.R(), v1.Theta(), v1.Phi() ); ok = 0; ok+= compare(v1.X(), v2.X(), "x"); ok+= compare(v1.Y(), v2.Y(), "y"); ok+= compare(v1.Z(), v2.Z(), "z"); ok+= compare(v1.Phi(), v2.Phi(), "phi"); ok+= compare(v1.Theta(), v2.Theta(), "theta"); ok+= compare(v1.R(), v2.R(), "r"); ok+= compare(v1.Eta(), v2.Eta(), "eta"); ok+= compare(v1.Rho(), v2.Rho(), "rho"); if (ok == 0) std::cout << "\t OK " << std::endl; std::cout << "Test Cartesian-CylindricalEta : "; RhoEtaPhiVector v3( v1.Rho(), v1.Eta(), v1.Phi() ); ok = 0; ok+= compare(v1.X(), v3.X(), "x"); ok+= compare(v1.Y(), v3.Y(), "y"); ok+= compare(v1.Z(), v3.Z(), "z"); ok+= compare(v1.Phi(), v3.Phi(), "phi"); ok+= compare(v1.Theta(), v3.Theta(), "theta"); ok+= compare(v1.R(), v3.R(), "r"); ok+= compare(v1.Eta(), v3.Eta(), "eta"); ok+= compare(v1.Rho(), v3.Rho(), "rho"); if (ok == 0) std::cout << "\t OK " << std::endl; std::cout << "Test Cartesian-Cylindrical : "; RhoZPhiVector v4( v1.Rho(), v1.Z(), v1.Phi() ); ok = 0; ok+= compare(v1.X(), v4.X(), "x"); ok+= compare(v1.Y(), v4.Y(), "y"); ok+= compare(v1.Z(), v4.Z(), "z"); ok+= compare(v1.Phi(), v4.Phi(), "phi"); ok+= compare(v1.Theta(), v4.Theta(), "theta"); ok+= compare(v1.R(), v4.R(), "r"); ok+= compare(v1.Eta(), v4.Eta(), "eta"); ok+= compare(v1.Rho(), v4.Rho(), "rho"); if (ok == 0) std::cout << "\t OK " << std::endl; std::cout << "Test Operations : " ; ok = 0; double Dot = v1.Dot(v2); ok+= compare( Dot, v1.Mag2(),"dot" ); XYZVector vcross = v1.Cross(v2); ok+= compare( vcross.R(), 0,"cross" ); //std::cout << "\nTest Unit & scaling : " ; XYZVector vscale1 = v1*10; XYZVector vscale2 = vscale1/10; ok+= compare( v1.R(), vscale2.R(), "scale"); XYZVector vu = v1.Unit(); ok+= compare(v2.Phi(),vu.Phi(),"unit Phi"); ok+= compare(v2.Theta(),vu.Theta(),"unit Theta"); ok+= compare(1.0,vu.R(),"unit "); XYZVector q1 = v1; // RhoEtaPhiVector q2 = v1; ! copy onstructor between different vector does not work yet) RhoEtaPhiVector q2(1.0,1.0,1.0); XYZVector q3 = q1 + q2; XYZVector q4 = q3 - q2; ok+= compare( q4.X(), q1.X(), "op X" ); ok+= compare( q4.Y(), q1.Y(), "op Y" ); ok+= compare( q4.Z(), q1.Z(), "op Z" ); // test operator == XYZVector w1 = v1; Polar3DVector w2 = v2; RhoEtaPhiVector w3 = v3; RhoZPhiVector w4 = v4; ok+= compare( w1 == v1, static_cast<double>(true), "== XYZ"); ok+= compare( w2 == v2, static_cast<double>(true), "== Polar"); ok+= compare( w3 == v3, static_cast<double>(true), "== RhoEtaPhi"); ok+= compare( w4 == v4, static_cast<double>(true), "== RhoZPhi"); if (ok == 0) std::cout << "\t OK " << std::endl; //test setters std::cout << "Test Setters : " ; q2.SetXYZ(q1.X(), q1.Y(), q1.Z() ); ok+= compare( q2.X(), q1.X(), "setXYZ X" ); ok+= compare( q2.Y(), q1.Y(), "setXYZ Y" ); ok+= compare( q2.Z(), q1.Z(), "setXYZ Z" ); q2.SetCoordinates( 2.0*q1.Rho(), q1.Eta(), q1.Phi() ); XYZVector q1s = 2.0*q1; ok+= compare( q2.X(), q1s.X(), "set X" ); ok+= compare( q2.Y(), q1s.Y(), "set Y" ); ok+= compare( q2.Z(), q1s.Z(), "set Z" ); if (ok == 0) std::cout << "\t\t OK " << std::endl; std::cout << "Test Linear Algebra conversion: " ; XYZVector vxyz1(1.,2.,3.); TVectorD vla1(3); vxyz1.Coordinates().GetCoordinates(vla1.GetMatrixArray() ); TVectorD vla2(3); vla2[0] = 1.; vla2[1] = -2.; vla2[2] = 1.; XYZVector vxyz2; vxyz2.SetCoordinates(&vla2[0]); ok = 0; double prod1 = vxyz1.Dot(vxyz2); double prod2 = vla1*vla2; ok+= compare( prod1, prod2, "la test" ); if (ok == 0) std::cout << "\t\t OK " << std::endl; return ok; }