Create segment out of a seed.
801{
802
804
805 double shift=0.;
806 double phimin=10.;
807 double phimax=-10.;
808
811
812 std::vector<const InDet::TRT_DriftCircle*>::iterator vit,vitE;
813
816
818 for(;vit!=vitE;++vit){
820 const Amg::Vector3D&
sc = (*vit)->detectorElement()->strawCenter(straw);
821
824
826 return;
827 }
828
829 event_data.m_a_z[
count]=
sc.z();
830 event_data.m_a_phi[
count]=
sc.phi();
831 event_data.m_a_tan[
count]=std::tan(
sc.phi());
832 const auto cosPhi{std::cos(
sc.phi())};
833 event_data.m_a_tan_err[
count]=(1.15/700.)/(cosPhi*cosPhi);
834 event_data.m_a_z_err[
count]=1.15;
835 event_data.m_a_phi_err[
count]=1.15/700.;
836
839
842
844 }
845
846 shift=(phimax+phimin)/2.-M_PI_4;
847 ATH_MSG_VERBOSE(
"Phimin="<<phimin<<
" Phimax="<<phimax<<
" shift="<<shift);
848
849
850 if(phimin<-M_PI_2 && phimax>M_PI_2){
851 shift=3.*M_PI_4;
852 ATH_MSG_VERBOSE(
"Boundary between pi and -pi!!! use the following shift: "<<shift);
853 }
854
855
856
857
859 double orig=event_data.m_a_phi[
i];
860
861 double corr=orig-shift;
864
865 event_data.m_a_phi[
i]=corr;
866 event_data.m_a_tan[
i]=std::tan(corr);
867 const auto cosCorr{std::cos(corr)};
868 event_data.m_a_tan_err[
i]=(1.15/700.)/(cosCorr*cosCorr);
869 }
870
872 if(!fit) return;
873
874 std::list<const InDet::TRT_DriftCircle*>::iterator lit,litE;
875
876
877 lit=event_data.m_goodHits.begin();
878 litE=event_data.m_goodHits.end();
879
880 std::vector<const InDet::TRT_DriftCircle*> tobeadded;
881
882
883 for(;lit!=litE;++lit){
885 const Amg::Vector3D&
sc = (*lit)->detectorElement()->strawCenter(straw);
886
887 double fitted_phi=
fit->Eval(
sc.z(),0.,0.);
888 fitted_phi+=shift;
889
890 if (fitted_phi >
M_PI) fitted_phi = std::fmod(fitted_phi+
M_PI,2.*
M_PI)-
M_PI;
891 else if(fitted_phi <-
M_PI) fitted_phi = std::fmod(fitted_phi-
M_PI,2.*
M_PI)+
M_PI;
892
894
895
898 bool new_hit=true;
899 for(;vit!=vitE && new_hit;++vit){
900 if((*vit)==(*lit)){
901 new_hit=false;
902 }
903 }
904 if(new_hit){
905 ATH_MSG_VERBOSE(
"\t\t good hit matched! fitted_phi="<<fitted_phi<<
" z=" <<
sc.z());
906
907 if(
sc.z()>zmin-200 &&
sc.z()<zmax+200){
910
911 seed->push_back(*lit);
912 }else{
913
914 tobeadded.push_back(*lit);
915 }
916 }
917 }
918 }
919
921
923
924 double z1=-1e5;
925
928 for(vit=tobeadded.begin();vit!=tobeadded.end();++vit){
930 const Amg::Vector3D&
sc = (*vit)->detectorElement()->strawCenter(straw);
932
933 if(
sc.z()<zmin &&
sc.z()>z1) {
936 }
937 if(
sc.z()>zmax && index2==-1) {
939 }
941 }
942
944
945 if(index2>=0){
948 const Amg::Vector3D&
sc = tobeadded[
i]->detectorElement()->strawCenter(straw);
951 seed->push_back(tobeadded[i]);
953 }else{
956 }
957 }
958 }
959 if(index1>=0){
960 for(
int i=index1;
i>=0;
i--){
962 const Amg::Vector3D&
sc = tobeadded[
i]->detectorElement()->strawCenter(straw);
965 seed->push_back(tobeadded[i]);
967 }else{
970 }
971 }
972 }
973 tobeadded.clear();
974
975
976
977
979
982
984 for(;vit!=vitE;++vit){
986 const Amg::Vector3D&
sc = (*vit)->detectorElement()->strawCenter(straw);
987
989 return;
990 }
991
992 event_data.m_a_z[
count]=
sc.z();
993 event_data.m_a_phi[
count]=
sc.phi();
994 event_data.m_a_tan[
count]=std::tan(
sc.phi());
995 const auto cosPhi{std::cos(
sc.phi())};
996 event_data.m_a_tan_err[
count]=(1.15/700.)/(cosPhi*cosPhi);
997 event_data.m_a_z_err[
count]=1.15;
998 event_data.m_a_phi_err[
count]=1.15/700.;
999
1002
1005
1007 }
1008
1009 shift=(phimax+phimin)/2.-M_PI_4;
1010 ATH_MSG_VERBOSE(
"Phimin="<<phimin<<
" Phimax="<<phimax<<
" shift="<<shift);
1011
1012
1013 if(phimin<-M_PI_2 && phimax>M_PI_2){
1014 shift=3.*M_PI_4;
1015 ATH_MSG_VERBOSE(
"Boundary between pi and -pi!!! use the following shift: "<<shift);
1016 }
1017
1018
1019
1021 double orig=event_data.m_a_phi[
i];
1022 double corr=orig-shift;
1023
1026
1027 event_data.m_a_phi[
i]=corr;
1028 event_data.m_a_tan[
i]=std::tan(corr);
1029 const auto cosCorr{std::cos(corr)};
1030 event_data.m_a_tan_err[
i]=(1.15/700.)/(cosCorr*cosCorr);
1031 }
1032
1033
1035 if(!fit) return;
1036
1037
1038 lit=event_data.m_noiseHits.begin();
1039 litE=event_data.m_noiseHits.end();
1040
1041 for(;lit!=litE;++lit){
1042
1043
1044
1046 const Amg::Vector3D&
sc = (*lit)->detectorElement()->strawCenter(straw);
1047
1049 double phi=
sc.phi();
1050 double fitted_phi=
fit->Eval(
sc.z(),0.,0.);
1051 fitted_phi+=shift;
1052
1053 if (fitted_phi >
M_PI) fitted_phi = std::fmod(fitted_phi+
M_PI,2.*
M_PI)-
M_PI;
1054 else if(fitted_phi <-
M_PI) fitted_phi = std::fmod(fitted_phi-
M_PI,2.*
M_PI)+
M_PI;
1055
1056
1057 if(
z*event_data.m_a_z[0]<0)
continue;
1058
1062 bool new_hit=true;
1063 for(;vit!=vitE && new_hit;++vit){
1064 if((*vit)==(*lit)){
1065 new_hit=false;
1066 }
1067 }
1068 if(new_hit){
1069 if(
sc.z()>zmin-50 &&
sc.z()<zmax+50){
1070 ATH_MSG_VERBOSE(
"\t\t noise hit matched! fitted_phi="<<fitted_phi<<
" z=" <<
sc.z());
1071 seed->push_back(*lit);
1072 }else{
1073 ATH_MSG_VERBOSE(
"\t\t noise hit matched but too far away! fitted_phi="<<fitted_phi<<
" z=" <<
sc.z());
1074 }
1075 }
1076 }
1077 }
1078
1079
1081
1082
1083 Amg::Vector3D firststraw=((*seed)[0]->detectorElement()->strawCenter(
m_trtid->straw((*seed)[0]->identify()) ));
1084 Amg::Vector3D laststraw=((*seed)[
seed->size()-1]->detectorElement()->strawCenter(
m_trtid->straw((*seed)[
seed->size()-1]->identify()) ));
1085 z1=firststraw.z();
1086 double z2=laststraw.z();
1087 double yfirst=firststraw.y();
1088 double ylast=laststraw.y();
1089
1091
1093 int state=0;
1094
1095
1096 if (std::abs(yfirst-ylast)>50){
1097 if(z1>z2) {
1099 }else{
1101 }
1102 }
1103 else {
1106 }
1107 firststraw=(*seed)[0]->detectorElement()->strawCenter(
m_trtid->straw((*seed)[0]->identify()) );
1108 laststraw=(*seed)[
seed->size()-1]->detectorElement()->strawCenter(
m_trtid->straw((*seed)[
seed->size()-1]->identify()) );
1109 z1=firststraw.z();
1110 z2=laststraw.z();
1111
1112
1113 if(z1>z2) {
1114 Theta=
M_PI-std::atan2(400.,std::abs(z1-z2));
1115 state=2;
1116 }else{
1117 Theta=std::atan2(400.,std::abs(z1-z2));
1118 state=1;
1119 }
1120
1121 double globaly=((*seed)[0]->detectorElement()->strawCenter(
m_trtid->straw((*seed)[0]->identify()) )).y();
1122 double firstphi=((*seed)[0]->detectorElement()->strawCenter(
m_trtid->straw((*seed)[0]->identify()) )).phi();
1123
1124
1126
1127
1128
1129
1130 const Amg::Vector3D& sc_first = ((*seed)[0]->detectorElement()->strawCenter(
m_trtid->straw((*seed)[0]->identify()) ));
1131 const Amg::Vector3D& sc_last = ((*seed)[
seed->size()-1]->detectorElement()->strawCenter(
m_trtid->straw((*seed)[
seed->size()-1]->identify()) ));
1132
1133
1134 double tx1,tx2,ty1,ty2;
1135
1136 tx1=1050*std::cos(sc_first.phi());
1137 ty1=1050*std::sin(sc_first.phi());
1138
1139 tx2=650*std::cos(sc_last.phi());
1140 ty2=650*std::sin(sc_last.phi());
1141
1142 double tphi=std::atan2(ty2-ty1,tx2-tx1);
1143
1144
1146
1147
1150
1151
1152
1153
1154 if(tphi>0)
1156
1157
1158
1159 while(Theta<0)
1161
1164
1166
1167 ATH_MSG_VERBOSE(
"globaly = "<<globaly<<
" phi="<<firstphi<<
" theta="<<Theta<<
" --> state = "<<state);
1168
1169
1172
1174 for(;vit!=vitE;++vit){
1177 const Amg::Vector3D&
sc = (*vit)->detectorElement()->strawCenter(straw);
1179 }
1180
1181
1183
1185
1186
1187
1188
1190
1193
1194 for(;vit!=vitE;++vit){
1196 const Amg::Vector3D&
sc = (*vit)->detectorElement()->strawCenter(straw);
1197
1198 double fitted_phi=
fit->Eval(
sc.z(),0.,0.);
1199 fitted_phi+=shift;
1200
1201 if (fitted_phi >
M_PI) fitted_phi = std::fmod(fitted_phi+
M_PI,2.*
M_PI)-
M_PI;
1202 else if(fitted_phi <-
M_PI) fitted_phi = std::fmod(fitted_phi-
M_PI,2.*
M_PI)+
M_PI;
1203
1205 if(fitted_phi<
sc.phi())
sign=-1;
1206
1207
1209 double drifte = 2*std::sqrt((*vit)->localCovariance()(0,0));
1210
1211 double straw_r=640+400./std::abs(z2-z1)*std::abs(
sc.z()-z1);
1212
1213 double dphi=
sign*driftr/straw_r;
1214
1215
1216 event_data.m_a_z[
count]=
sc.z();
1217 event_data.m_a_phi[
count]=
sc.phi()+dphi;
1218 event_data.m_a_phi_err[
count]=drifte/straw_r;
1219
1220 event_data.m_a_tan[
count]=std::tan(event_data.m_a_phi[
count]-shift);
1221 const auto cosPhiMinShift{std::cos(event_data.m_a_phi[
count]-shift)};
1222 event_data.m_a_tan_err[
count]=(event_data.m_a_phi_err[
count])/( cosPhiMinShift
1223 * cosPhiMinShift);
1224
1225 event_data.m_a_z_err[
count]=0.;
1226
1229 }
1230
1232
1234 if(!fit) return;
1235
1236
1237
1240
1242 for(;vit!=vitE;++vit){
1244 const Amg::Vector3D&
sc = (*vit)->detectorElement()->strawCenter(straw);
1245 double fitted_phi=
fit->Eval(
sc.z(),0.,0.);
1246 fitted_phi+=shift;
1247
1249 double drifte = 2*std::sqrt((*vit)->localCovariance()(0,0));
1251
1252 if(fitted_phi<
sc.phi())
sign=-1;
1253
1254 double straw_r=640+400./std::abs(z2-z1)*std::abs(
sc.z()-z1);
1255 double dphi=
sign*driftr/straw_r;
1256
1258 return;
1259 }
1260
1261 if (
msgLvl(MSG::VERBOSE))
msg()<<
"z="<<
sc.z()<<
" phi="<<
sc.phi()<<
" fitted_phi = "<<fitted_phi<<
endmsg;
1264
1265 event_data.m_a_z[
count]=
sc.z();
1266 event_data.m_a_phi[
count]=
sc.phi()+dphi;
1267 event_data.m_a_phi_err[
count]=drifte/straw_r;
1268
1269 event_data.m_a_tan[
count]=std::tan(event_data.m_a_phi[
count]-shift);
1270 const auto cosPhiMinShift{ std::cos(event_data.m_a_phi[
count]-shift)};
1271 event_data.m_a_tan_err[
count]=(event_data.m_a_phi_err[
count])/( cosPhiMinShift
1272 *cosPhiMinShift);
1273
1274 event_data.m_a_z_err[
count]=0.;
1276
1277 }
1278 }
1279
1280
1281
1283
1286 if(!fit) return;
1287 }
1288
1291
1293 for(;vit!=vitE;++vit){
1295 const Amg::Vector3D&
sc = (*vit)->detectorElement()->strawCenter(straw);
1296
1297 double fitted_phi=
fit->Eval(
sc.z(),0.,0.);
1298 fitted_phi+=shift;
1299
1300 if (fitted_phi >
M_PI) fitted_phi = std::fmod(fitted_phi+
M_PI,2.*
M_PI)-
M_PI;
1301 else if(fitted_phi <-
M_PI) fitted_phi = std::fmod(fitted_phi-
M_PI,2.*
M_PI)+
M_PI;
1302
1304 double drifte = 2*std::sqrt((*vit)->localCovariance()(0,0));
1306
1307 if(fitted_phi<
sc.phi())
sign=-1;
1308
1309 double straw_r=640+400./std::abs(z2-z1)*std::abs(
sc.z()-z1);
1310 double dphi=
sign*driftr/straw_r;
1311
1312
1317 }
1318 }
1319
1321
1322 }
1323
1324
1325
1326
1327
1328
1330
1331 if(
count>=400)
return;
1332
1333
1334
1335
1336
1337 auto rio = DataVector<const Trk::MeasurementBase>{};
1338
1341
1343
1344 double initial_r=-10.;
1345 double initial_locz=0.;
1346
1348 for(;vit!=vitE;++vit){
1349 const Trk::StraightLineSurface*
line =
static_cast<const Trk::StraightLineSurface*
>
1350 (&((*vit)->detectorElement())->surface( (*vit)->identify()));
1351
1352
1354 const Amg::Vector3D&
sc = (*vit)->detectorElement()->strawCenter(straw);
1355
1357
1358
1359 double locz=0.;
1360
1361 if(std::abs(z2-z1)>0.000001){
1362 if(state==1){
1363 locz=400./std::abs(z2-z1)*std::abs(
z-z1)-200.;
1364 }else{
1365 locz=200.-400./std::abs(z2-z1)*std::abs(
z-z1);
1366 }
1367 }
1368 double fitted_phi=
fit->Eval(
z,0.,0.);
1369 fitted_phi+=shift;
1370
1371 if (fitted_phi >
M_PI) fitted_phi = std::fmod(fitted_phi+
M_PI,2.*
M_PI)-
M_PI;
1372 else if(fitted_phi <-
M_PI) fitted_phi = std::fmod(fitted_phi-
M_PI,2.*
M_PI)+
M_PI;
1373
1374 double fitted_r=(
phidiff(fitted_phi,
sc.phi()))*(840+locz);
1375 double temp_phi=fitted_phi;
1376
1377 if(initial_r==-10. && std::abs(fitted_r)<4.0){
1378 initial_r=fitted_r;
1379 initial_locz=locz;
1380 }
1381
1384
1386
1387
1388 fitted_r*=-1.0;
1389
1390
1391 temp_phi=firstphi;
1392
1394
1395
1396
1397
1398
1399
1400 bool useDrift=false;
1401
1404 double drifte = 2*std::sqrt((*vit)->localCovariance()(0,0));
1406
1407 if(fitted_phi<
sc.phi())
sign=-1;
1408
1409 double straw_r=640+400./std::abs(z2-z1)*std::abs(
sc.z()-z1);
1410 double dphi=
sign*driftr/straw_r;
1411
1412 if(std::abs(
phidiff(fitted_phi,
sc.phi()-dphi)) < 3* drifte/straw_r){
1413 useDrift=true;
1414 chi2+=(std::abs(fitted_r)-std::abs(driftr))*(std::abs(fitted_r)-std::abs(driftr))/(drifte*drifte);
1415 }
1416
1417 }
1418
1419
1420 if(useDrift){
1422 rio.push_back(
m_riomakerD->correct(*(*vit),
Tp, Gaudi::Hive::currentContext()));
1423 }else{
1425 chi2+=(fitted_r/1.15)*(fitted_r/1.15);
1427 rio.push_back(
m_riomakerN->correct(*(*vit),
Tp, Gaudi::Hive::currentContext()));
1428 }
1429
1431
1432
1435 Trk::LocalParameters
par(dp);
1438
1439
1441
1442 if(state==2 || state==3){
1444 }else{
1446 }
1448 Trk::StraightLineSurface* surface = new Trk::StraightLineSurface(T);
1449
1450
1451 Trk::PseudoMeasurementOnTrack *pseudo=new Trk::PseudoMeasurementOnTrack(
1452 std::move(par),
1453 std::move(cov),
1454 *surface);
1455
1456 delete surface;
1457
1458 rio.push_back(pseudo);
1459
1460 }
1461 }
1462
1463
1464
1465
1466 Trk::FitQuality * fqu =
new Trk::FitQuality(
chi2,
count-2);
1467 const Trk::Surface * sur = &((*seed)[0]->detectorElement())->surface((*seed)[0]->
identify());
1468
1469
1470
1471
1472 if(firstphi>0) firstphi=-firstphi;
1473
1474
1480
1481 std::array<Trk::DefinedParameter,5> defPar = {dp0,dp1,dp2,dp3,dp4};
1482
1483 Trk::LocalParameters
par(defPar);
1484
1485
1487
1488 double universal=1.15;
1489
1490
1493 universal*universal, 0., 0., 0., 0.,
1494 0. , 160000./12., 0., 0., 0.,
1495 0. , 0., 0.1, 0., 0.,
1496 0. , 0., 0., 1., 0.,
1497 0. , 0., 0., 0., 1.;
1498 Trk::TrackSegment* segment = new Trk::TrackSegment(
1500
1501
1502
1504 event_data.m_segments.push_back(segment);
1505
1506
1507}
Scalar phi() const
phi method
#define ATH_MSG_VERBOSE(x)
bool msgLvl(const MSG::Level lvl) const
BooleanProperty m_useDriftTime
ToolHandle< Trk::IRIO_OnTrackCreator > m_riomakerN
DoubleProperty m_scaleFactorDrift
DoubleProperty m_scaleTube
ToolHandle< Trk::IRIO_OnTrackCreator > m_riomakerD
TF1 * perform_fit(int count, TRT_TrackSegmentsMaker_ECcosmics::EventData &event_data) const
Perform the fit and return a function that provides the fitted phi information.
DoubleProperty m_scaleTubeNoise
IntegerProperty m_minDCSeed
double chi2(TH1 *h0, TH1 *h1)
int count(std::string s, const std::string ®x)
count how many occurances of a regx are in a string
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Eigen::Affine3d Transform3D
Eigen::Translation< double, 3 > Translation3D
bool CompareDCy(const InDet::TRT_DriftCircle *x, const InDet::TRT_DriftCircle *y)
bool CompareDCzreverse(const InDet::TRT_DriftCircle *x, const InDet::TRT_DriftCircle *y)
bool CompareDCz(const InDet::TRT_DriftCircle *x, const InDet::TRT_DriftCircle *y)
ParametersT< TrackParametersDim, Charged, StraightLineSurface > AtaStraightLine
std::pair< double, ParamDefs > DefinedParameter
Typedef to of a std::pair<double, ParamDefs> to identify a passed-through double as a specific type o...
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
const Identifier & identify(const UncalibratedMeasurement *meas)
Returns the associated identifier from the muon measurement.