14#include "GaudiKernel/MsgStream.h"
15#include "GaudiKernel/ServiceHandle.h"
16#include "CLHEP/Vector/ThreeVector.h"
44(
const std::string& t,
const std::string& n,
const IInterface* p)
47 declareInterface<ITRT_SeededSpacePointFinder>(
this);
70 msg(MSG::FATAL) <<
"Could not get SCT_ID helper !" <<
endmsg;
71 return StatusCode::FAILURE;
94 StatusCode
sc = AthAlgTool::finalize();
return sc;
102std::unique_ptr<InDet::ITRT_SeededSpacePointFinder::IEventData>
105 std::unique_ptr<InDet::TRT_SeededSpacePointFinder_ATL::EventData> event_data_p = std::make_unique<InDet::TRT_SeededSpacePointFinder_ATL::EventData>();
111 std::vector< std::vector<const Trk::SpacePoint*> > r_Sorted;
112 r_Sorted.resize(event_data_p->m_r_size);
118 if (spacepointsPix.
isValid()) {
122 for(; spc != spce; ++spc) {
126 for(;
sp != spe; ++
sp) {
129 int ir = int(
r*irstep);
131 r_Sorted[
ir].push_back(sps);
132 ++event_data_p->m_r_map[
ir];
133 if(event_data_p->m_r_map[
ir]==1) event_data_p->m_r_index[event_data_p->m_nr++] =
ir;
134 ++event_data_p->m_ns;
143 if (!prd_to_track_map.
isValid()) {
144 ATH_MSG_ERROR(
"Failed to read PRD to track association map.");
150 if (spacepointsSCT.
isValid()) {
156 for(; spc != spce; ++spc) {
160 for(;
sp != spe; ++
sp) {
162 if(prd_to_track_map.
cptr()){
163 bool u1=
false;
bool u2=
false;
164 const Trk::PrepRawData* p1=(*sp)->clusterList().first; u1=prd_to_track_map->isUsed(*p1);
165 const Trk::PrepRawData* p2=(*sp)->clusterList().second;u2=prd_to_track_map->isUsed(*p2);
166 if(u1 || u2){
continue;}
170 int ir = int(
r*irstep);
172 r_Sorted[
ir].push_back(sps); ++event_data_p->m_r_map[
ir];
173 if(event_data_p->m_r_map[
ir]==1) event_data_p->m_r_index[event_data_p->m_nr++] =
ir;
174 ++event_data_p->m_ns;
182 if (spacepointsOverlap.
isValid()) {
186 for (;
sp!=spe; ++
sp) {
188 if(prd_to_track_map.
cptr()){
189 bool u1=
false;
bool u2=
false;
190 const Trk::PrepRawData* p1=(*sp)->clusterList().first; u1=prd_to_track_map->isUsed(*p1);
191 const Trk::PrepRawData* p2=(*sp)->clusterList().second;u2=prd_to_track_map->isUsed(*p2);
192 if(u1 || u2){
continue;}
196 int ir = int(
r*irstep);
198 r_Sorted[
ir].push_back(sps); ++event_data_p->m_r_map[
ir];
199 if(event_data_p->m_r_map[
ir]==1) event_data_p->m_r_index[event_data_p->m_nr++] =
ir;
200 ++event_data_p->m_ns;
205 return std::unique_ptr<InDet::ITRT_SeededSpacePointFinder::IEventData>(event_data_p.release());
213(
const std::vector<IdentifierHash>& vPixel,
const std::vector<IdentifierHash>& vSCT)
const
215 std::unique_ptr<InDet::TRT_SeededSpacePointFinder_ATL::EventData> event_data_p = std::make_unique<InDet::TRT_SeededSpacePointFinder_ATL::EventData>();
218 std::vector< std::vector<const Trk::SpacePoint*> > r_Sorted;
219 r_Sorted.resize(event_data_p->m_r_size);
227 if (spacepointsPix.
isValid()) {
228 std::vector<IdentifierHash>::const_iterator l = vPixel.begin(), le = vPixel.end();
235 if(w==
nullptr)
continue;
238 for(;
sp != spe; ++
sp) {
241 int ir = int(
r*irstep);
243 r_Sorted[
ir].push_back(sps); ++event_data_p->m_r_map[
ir];
244 if(event_data_p->m_r_map[
ir]==1) event_data_p->m_r_index[event_data_p->m_nr++] =
ir;
245 ++event_data_p->m_ns;
256 if (spacepointsSCT.
isValid()) {
261 if (!prd_to_track_map.
isValid()) {
262 ATH_MSG_ERROR(
"Failed to read PRD to track association map.");
265 std::vector<IdentifierHash>::const_iterator l = vSCT.begin(), le = vSCT.end();
273 if(w==
nullptr)
continue;
276 for(;
sp != spe; ++
sp) {
278 if(prd_to_track_map.
cptr()){
279 bool u1=
false;
bool u2=
false;
280 const Trk::PrepRawData* p1=(*sp)->clusterList().first; u1=prd_to_track_map->isUsed(*p1);
281 const Trk::PrepRawData* p2=(*sp)->clusterList().second;u2=prd_to_track_map->isUsed(*p2);
282 if(u1 || u2){
continue;}
286 int ir = int(
r*irstep);
288 r_Sorted[
ir].push_back(sps); ++event_data_p->m_r_map[
ir];
289 if(event_data_p->m_r_map[
ir]==1) event_data_p->m_r_index[event_data_p->m_nr++] =
ir;
290 ++event_data_p->m_ns;
297 return std::unique_ptr<InDet::ITRT_SeededSpacePointFinder::IEventData>(event_data_p.release());
305std::list<std::pair<const Trk::SpacePoint*, const Trk::SpacePoint*> >
312 const double pi2 = 2.*
M_PI;
315 std::list<std::pair<const Trk::SpacePoint*,const Trk::SpacePoint*> > outputListBuffer;
320 F=atan2(GPy,GPx);
if(
F<0.)
F+=pi2;
321 int f = int(
F*event_data.
m_sF);
324 else if (f > event_data.
m_fNmax)
336 if(outputListBuffer.size()>10000.) outputListBuffer.clear();
338 return outputListBuffer;
349 std::string s1;
for(
int i=0; i<n; ++i) s1.append(
" "); s1.append(
"|");
351 std::string s3;
for(
int i=0; i<n; ++i) s3.append(
" "); s3.append(
"|");
353 std::string s4;
for(
int i=0; i<n; ++i) s4.append(
" "); s4.append(
"|");
355 std::string fieldmode[9] ={
"NoField" ,
"ConstantField",
"SolenoidalField",
356 "ToroidalField" ,
"Grid3DField" ,
"RealisticField" ,
357 "UndefinedField",
"AthenaField" ,
"?????" };
360 if(mode<0 || mode>8 ) mode = 8;
362 n = 62-fieldmode[mode].size();
363 std::string s5;
for(
int i=0; i<n; ++i) s5.append(
" "); s5.append(
"|");
365 out<<
"|---------------------------------------------------------------------|"
373 out<<
"| Magnetic field mode | "<<fieldmode[mode]<<s5
375 out<<
"| pTmin (mev) | "
376 <<std::setw(12)<<std::setprecision(5)<<
m_ptmin
378 out<<
"| max radius SP | "
379 <<std::setw(12)<<std::setprecision(5)<<
m_r_rmax
381 out<<
"| radius step | "
382 <<std::setw(12)<<std::setprecision(5)<<
m_r_rstep
384 out<<
"| min radius second SP(3) | "
385 <<std::setw(12)<<std::setprecision(5)<<
m_r2min
387 out<<
"| min radius first SP(3) | "
388 <<std::setw(12)<<std::setprecision(5)<<
m_r12min
390 out<<
"| max radius first SP(3) | "
391 <<std::setw(12)<<std::setprecision(4)<<
m_r1max
393 out<<
"| min seeds dZ/dR | "
394 <<std::setw(12)<<std::setprecision(5)<<
m_dzdrmin
396 out<<
"| max seeds dZ/dR | "
397 <<std::setw(12)<<std::setprecision(5)<<
m_dzdrmax
399 out<<
"| momentum chi2 cut | "
400 <<std::setw(12)<<std::setprecision(5)<<
m_xiC
402 out<<
"| polar angle chi2 cut | "
403 <<std::setw(12)<<std::setprecision(5)<<
m_xiTC
405 out<<
"| azimuthal angle chi2 cut | "
406 <<std::setw(12)<<std::setprecision(5)<<
m_xiFC
408 out<<
"|---------------------------------------------------------------------|"
420 explicit StreamState(std::ostream& out)
421 : m_out(out), m_prec(out.precision())
427 m_out.precision(m_prec);
432 std::streamsize m_prec;
438 const double pi2 = 2.*
M_PI;
439 out<<
"|---------------------------------------------------------------------|"
442 <<std::setw(12)<<event_data.
m_ns
444 out<<
"|---------------------------------------------------------------------|"
447 if(
msgLvl(MSG::DEBUG))
return out;
449 out<<
"|-------------|--------|-------|-------|-------|-------|-------|";
450 out<<
"-------|-------|-------|-------|-------|-------|"
453 out<<
"| Azimuthal | n | z[ 0] | z[ 1] | z[ 2] | z[ 3] | z[4] |";
454 out<<
" z[ 5] | z[ 6] | z[ 7] | z[ 8] | z[ 9] | z[10] |"
456 out<<
"|-------------|--------|-------|-------|-------|-------|-------|";
457 out<<
"-------|-------|-------|-------|-------|-------|"
460 double sF1 = pi2/double(event_data.
m_fNmax+1);
463 auto prec(out.precision());
464 for(
int f=0; f<=event_data.
m_fNmax; ++f) {
466 <<std::setw(10)<<std::setprecision(4)<<sF1*double(f)<<
" | "
467 <<std::setw(6)<<event_data.
m_rf_map[f]<<
" |";
470 out<<
"|-------------|--------|-------|-------|-------|-------|-------|";
471 out<<
"-------|-------|-------|-------|-------|-------|"
503 m_r_size = int((r_rmax+.1)/r_rstep);
510 const double pi2 = 2.*
M_PI ;
511 const int NFmax = 530 ;
512 const double sFmax = double(NFmax )/pi2;
526 assert(
static_cast<size_t>(event_data.
m_r_size) == r_Sorted.size());
527 const double pi2 = 2.*
M_PI;
529 for(
int i=0; i!= event_data.
m_r_size; ++i) {
530 if(!event_data.
m_r_map[i])
continue;
535 double F = space_point->phi();
if(
F<0.)
F+=pi2;
536 int f = int(
F*event_data.
m_sF);
539 else if (f > event_data.
m_fNmax)
541 int isBRL = 1000;
int isLYR = 1000;
int DD = 1000;
543 geoInfo(space_point,isBRL,isLYR);
547 DD = ((isBRL+3) << 4) + (isLYR & 15);
549 event_data.
m_rf_Sorted[f].emplace_back(space_point,DD);
566 for(
int i=0; i!=
m_nrf; ++i) {
589 double rquadrant = rotations*4.0;
590 long quadrant = (long)rquadrant & 3;
592 if ((quadrant & 1) != 0) {
599 quadrant -= ((quadrant & 2) << 1);
600 return quadrant + twist;
612 double *
min,
double *
max) {
629 long asign_x = (long)(
x < 0.0);
630 long asign_y = (long)(
y < 0.0);
631 long quadrant = -(asign_y << 1) + (asign_y ^ asign_x);
634 double denominator = x2 + y2;
635 double numerator = ((quadrant & 1) != 0) ? x2 : y2;
636 return (
double)quadrant + numerator/denominator;
643 std::list<std::pair<const Trk::SpacePoint*,const Trk::SpacePoint*> > &outputListBuffer,
646 uint64_t spcount = 0;
654 double sPhi = (*vCM)(2,2) ;
655 double sTheta = (*vCM)(3,3);
656 double sp = (*vCM)(4,4) ;
658 double ipdelta = sqrt(
m_xiC*
sp);
661 tmp_invar_bypass.
invp_min = pTS[4] - ipdelta;
662 tmp_invar_bypass.
invp_max = pTS[4] + ipdelta;
667 double theta_center = pTS[3];
668 double theta_delta = sqrt(
m_xiTC*sTheta);
670 double phi_center = pTS[2];
671 double phi_delta = sqrt(
m_xiFC*sPhi);
684 double H[3];
double gP[3] = {x0,y0,z0};
689 if (fieldCondObj ==
nullptr) {
702 std::list<std::pair<const Trk::SpacePoint*,int> >::iterator r0,r0e,
r,
re, rb;
708 int fmin=
phi;
int fmax=
phi;
710 for(
int f=fmin; f<=fmax; ++f) {
719 for(; r0!=r0e; ++r0){
720 if((((*r0).first)->r() >
m_r1max) ||
721 (((*r0).first)->r() <
m_r2min)) {
730 int fmin=
phi;
int fmax=
phi;
731 for(
int f=fmin; f<=fmax; ++f) {
740 for(; r0!=r0e; ++r0){
741 if((((*r0).first)->r()>
m_r1max) || (((*r0).first)->r()<
m_r2min)) {
760 std::vector<bypass_struct> tmp_prod_bypass;
761 std::vector<const Trk::SpacePoint *> vrp;
762 std::vector<double> rk;
763 std::vector<long> geo_info;
764 std::vector<double> zSP;
765 tmp_prod_bypass.reserve(spcount);
766 vrp.reserve(spcount);
768 geo_info.reserve(spcount);
769 zSP.reserve(spcount);
772 for (;
r !=
re; ++
r) {
775 geo_info.push_back((*r).second);
777 rk.push_back(vrpi->
r());
783 double Z = zSPi - z0;
785 double RR = X*X + Y*Y;
792 tmp_prod_bypass.emplace_back();
793 tmp_prod_bypass.back().X = X;
794 tmp_prod_bypass.back().Y = Y;
795 tmp_prod_bypass.back().Z = Z;
797 tmp_prod_bypass.back().R = R;
798 tmp_prod_bypass.back().invR = invR;
800 tmp_prod_bypass.back().a =
a;
801 tmp_prod_bypass.back().b = b;
809 for (
long i = 0; i < (long)spcount; i++) {
812 for (
long j = i + 1; j < (long)spcount; j++) {
815 outputListBuffer.emplace_back(up, SpToPair);
818 outputListBuffer.emplace_back(up, up);
823 for (
long i = 0; i < (long)spcount; i++) {
831 long geoi = geo_info[i];
832 int isBU = (geoi >> 4)-3;
833 int eleU = geoi & 15;
835 for (
long j = i + 1; j < (long)spcount; j++) {
839 long geoj = geo_info[j];
840 int isBB = (geoj >> 4)-3;
841 int eleB = geoj & 15;
851 int Bd = (isBU - isBB) | (isBB - isBU);
852 int Ed = (eleB - eleU);
853 int BUzero = (isBU | -isBU);
854 if (((BUzero | ~Bd) & (Bd | Ed) & (((
unsigned)(-1) >> 1) + 1))
864 if (dZ < dz_min || dZ > dz_max) {
868 if(!
cutTPb(tmp_invar_bypass, tmp_prod_bypass,i, j,
H[2])) {
873 outputListBuffer.emplace_back(up, SpToPair);
876 outputListBuffer.emplace_back(up, up);
892 const std::vector<bypass_struct> &tmp_prod_bypass,
893 long bSP1,
long bSP2,
double H)
const
896 double inv_r2 = tmp_prod_bypass[bSP2].invR;
897 double inv_r1 = tmp_prod_bypass[bSP1].invR;
898 double r1 = tmp_prod_bypass[bSP1].R;
900 double inv_rr2 = inv_r2*inv_r2;
901 double x2 = tmp_prod_bypass[bSP2].X;
902 double y2 = tmp_prod_bypass[bSP2].Y;
903 double a1 = tmp_prod_bypass[bSP1].a;
904 double b1 = tmp_prod_bypass[bSP1].b;
906 double u2 = (a1*x2 + b1*y2)*inv_rr2;
907 double v2 = (a1*y2 - b1*x2)*inv_rr2;
909 double A = v2/(u2 - inv_r1);
910 double B = 2.0*(v2 -
A*u2);
911 double CC = B*B/(1.0 +
A*
A);
912 double rcrc = CC*r1*r1;
913 double z1 = tmp_prod_bypass[bSP1].Z;
914 double T = -z1/(r1*(1.0 + 0.04*rcrc));
916 if(
H==0.)
return false;
918 double invpSignature = B*
H;
920 double invP2 = CC/(0.03*0.03*
H*
H*(1.0 + T*T));
926 double invp_min = tmp_invar_bypass.
invp_min;
927 double invp_max = tmp_invar_bypass.
invp_max;
929 double invp_min2 = tmp_invar_bypass.
invp_min2;
930 double invp_max2 = tmp_invar_bypass.
invp_max2;
933 if (invpSignature < 0 || invP2 < invp_min2) {
938 if (invpSignature < 0 && invP2 > invp_min2) {
943 if (invpSignature >= 0 && invP2 > invp_max2) {
948 if (invpSignature >= 0 || invP2 < invp_max2) {
956 double tmin = tmp_invar_bypass.
min_theta;
957 double tmax = tmp_invar_bypass.
max_theta;
960#ifndef ANGLE_DISCO_COMPAT
962 if (theta_rating >= 0) {
970 if (tmin + tmax <= 0) {
981 if (theta_rating < tmin || theta_rating > tmax) {
985 double phi_rating =
rotrating(-(b1 + a1*
A), -(a1 - b1*
A));
986 double pmin = tmp_invar_bypass.
min_phi;
987 double pmax = tmp_invar_bypass.
max_phi;
990#ifndef ANGLE_DISCO_COMPAT
992 if (phi_rating >= 0) {
1000 if (pmin + pmax <= 0) {
1011 return phi_rating >= pmin && phi_rating <= pmax;
1032 id=c1->detectorElement()->identify();
const boost::regex re(r_e)
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define AmgSymMatrix(dim)
This is an Identifier helper class for the SCT subdetector.
Handle class for reading from StoreGate.
double angle(const GeoTrf::Vector2D &a, const GeoTrf::Vector2D &b)
double rotrating(double y, double x)
void bracket_angle(double angle, double delta, double *min, double *max)
double rollrating(double angle)
const ServiceHandle< StoreGateSvc > & detStore() const
bool msgLvl(const MSG::Level lvl) const
void getInitializedCache(MagField::AtlasFieldCache &cache) const
get B field cache for evaluation as a function of 2-d or 3-d position.
DataModel_detail::const_iterator< DataVector > const_iterator
Sorting function according to space point radial position.
std::list< std::pair< const Trk::SpacePoint *, int > > m_newRfi_Sorted
std::list< std::pair< const Trk::SpacePoint *, int > > m_rf_Sorted[530]
void buildFrameWork(double r_rmax, double r_rstep, double ptmin)
BooleanProperty m_loadFull
std::unique_ptr< InDet::ITRT_SeededSpacePointFinder::IEventData > newEvent() const
Method to initialize tool for new event.
static constexpr double m_dzdrmax
Min R-z direction cut.
DoubleProperty m_ptmin
Seed selection criteria.
SG::ReadHandleKey< SpacePointOverlapCollection > m_spacepointsOverlapname
static constexpr double m_r_rmax
Minimum SCT radius to be searched.
virtual StatusCode finalize()
DoubleProperty m_xiC
Max R-z direction cut.
static constexpr double m_r1max
Step size for space point storage.
std::list< std::pair< const Trk::SpacePoint *, const Trk::SpacePoint * > > find2Sp(const EventContext &ctx, const Trk::TrackParameters &, ITRT_SeededSpacePointFinder::IEventData &event_data) const
Main method of seed production.
static constexpr double m_dzdrmin
Min radius to search for SP pairs.
const SCT_ID * m_sctId
Magnetic field properties.
SG::ReadHandleKey< SpacePointContainer > m_spacepointsPixname
Space points containers.
TRT_SeededSpacePointFinder_ATL(const std::string &, const std::string &, const IInterface *)
Standard tool methods.
virtual StatusCode initialize()
SG::ReadHandleKey< Trk::PRDtoTrackMap > m_prdToTrackMap
static constexpr double m_r2min
Min radius of last SCT layer.
virtual ~TRT_SeededSpacePointFinder_ATL()
void magneticFieldInit()
Get magnetic field properties.
SG::ReadHandleKey< SpacePointContainer > m_spacepointsSCTname
static constexpr double m_r12min
Max radius of last SCT layer.
void geoInfo(const Trk::SpacePoint *, int &, int &) const
Obtain geo model info for a specific space point.
MsgStream & dumpConditions(MsgStream &out) const
Protected methods.
void fillLists(std::vector< std::vector< const Trk::SpacePoint * > > &r_Sorted, InDet::TRT_SeededSpacePointFinder_ATL::EventData &event_data) const
Fill the space point container lists at beginning of each event.
void production2Spb(const EventContext &ctx, const Trk::TrackParameters &, int, std::list< std::pair< const Trk::SpacePoint *, const Trk::SpacePoint * > > &outputListBuffer, InDet::TRT_SeededSpacePointFinder_ATL::EventData &event_data) const
Form possible space point combinations within allowed radial and pseudorapidity ranges.
MsgStream & dumpEvent(MsgStream &out, InDet::TRT_SeededSpacePointFinder_ATL::EventData &event_data) const
bool cutTPb(const invar_bypass_struct &invar_bypass, const std::vector< bypass_struct > &prod_bypass, long, long, double) const
Cut on chi2 based on TRT segment qOverP, theta and phi track parameters.
static constexpr double m_r_rstep
Maximum STC radius to be searched.
static constexpr double m_r_rmin
SG::ReadCondHandleKey< AtlasFieldCacheCondObj > m_fieldCondObjInputKey
std::unique_ptr< InDet::ITRT_SeededSpacePointFinder::IEventData > newRegion(const std::vector< IdentifierHash > &, const std::vector< IdentifierHash > &) const
StringProperty m_fieldmode
Protected data and methods.
Trk::MagneticFieldProperties m_fieldprop
MsgStream & dump(MsgStream &out) const
Print internal tool parameters and status.
BooleanProperty m_doCosmics
Local cache for magnetic field (based on MagFieldServices/AtlasFieldSvcTLS.h)
bool solenoidOn() const
status of the magnets
void getField(const double *ATH_RESTRICT xyz, double *ATH_RESTRICT bxyz, double *ATH_RESTRICT deriv=nullptr)
get B field value at given position xyz[3] is in mm, bxyz[3] is in kT if deriv[9] is given,...
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
static EventData & getPrivateEventData(InDet::ITRT_SeededSpacePointFinder::IEventData &virt_event_data)
magnetic field properties to steer the behavior of the extrapolation
const Amg::Vector3D & position() const
Access method for the position.
virtual const Amg::Vector3D & globalPosition() const override final
Interface method to get the global Position.
double r() const
returns the r value of the SpacePoint's position (in cylindrical coordinates).
const std::pair< const PrepRawData *, const PrepRawData * > & clusterList() const
return the pair of cluster pointers by reference
int ir
counter of the current depth
@ FastField
call the fast field access method of the FieldSvc
@ NoField
Field is set to 0., 0., 0.,.
@ FullField
Field is set to be realistic, but within a given Volume.
ParametersBase< TrackParametersDim, Charged > TrackParameters
hold the test vectors and ease the comparison