34 std::vector<const Muon::MuonSegment*> (&disqualifiedSegments)[2][4],
38 const float dRhoCutSegmentMatching = 1000;
39 const float dPhiCutSegmentMatching =
M_PI/8;
42 const int nMeasCutMdtMidstation = 5;
43 const int nMeasCutTGCMidPRD[2] = {2,2};
46 const float dPhiCut_Loose =
M_PI/8;
48 const float dPhiCutGlobal[2] = {
static_cast<float>(
M_PI/24),
static_cast<float>(
M_PI/12)};
49 const float dRhoCutGlobal[2] = { 0.08, 0.5};
51 const float dPhiCutSector[2] = { 0.2, 0.1};
52 const float dRhoCutSector[2] = { 300, 3000};
54 const float dPhiCutTPD[2] = { 0.15, 0.02};
55 const float dRhoCutTPD[2] = { 150, 3000};
60 int nValidatedSegm = 0;
65 bool canCheckSectorFill[4] = {0, 0, 0, 0};
70 int TGCstation_StationFEFill[4] = {-1,-1,-1,-1};
71 int TGCstation_StationEtaFill[4] = { 0, 0, 0, 0};
72 int TGCstation_StationPhiFill[4] = { 0, 0, 0, 0};
75 bool sectorhitregisteredFill[9][2] = {{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}};
77 bool skipSegm;
int nDisqualifiedSegm;
80 std::vector<const Muon::MuonSegment*> copyDisqualifiedSegments;
81 nDisqualifiedSegm=disqualifiedSegments[i][2].size();
82 copyDisqualifiedSegments.reserve(nDisqualifiedSegm);
83for(
int ndis=0;ndis<nDisqualifiedSegm;ndis++)copyDisqualifiedSegments.push_back(disqualifiedSegments[i][2].at(ndis));
87 int nSegm = sortedSegments[i][2].size();
88 for(
int n0=0; n0<nSegm;n0++){
94 nDisqualifiedSegm=copyDisqualifiedSegments.size();
95 for(
int ndis=0;ndis<nDisqualifiedSegm;ndis++)
if(segm0==copyDisqualifiedSegments.at(ndis))skipSegm=
true;
106 stationName = int(
m_idHelperSvc->mdtIdHelper().stationName(
id));
108 if((stationName==17)||(stationName==18))nMdtMeas++;
111 if(nMdtMeas<nMeasCutMdtMidstation){
112 copyDisqualifiedSegments.push_back(segm0);
117 for(
int n1=0; n1<nSegm;n1++){
125 nDisqualifiedSegm=copyDisqualifiedSegments.size();
126 for(
int ndis=0;ndis<nDisqualifiedSegm;ndis++)
if(segm1==copyDisqualifiedSegments.at(ndis))skipSegm=
true;
127 if(skipSegm)
continue;
130 bool failedGroupingCut =
false;
132 bool canCheckGlobal[4] = {
true,
true,
true,
false};
133 bool canCheckSector[4] = {
true,
true,
true,
false};
139 float segm1PosPhi = segm1Pos.phi();
140 float segm1PosThe = segm1Pos.theta();
141 float segm1PosZ = segm1Pos.z();
142 if(segm1PosPhi<0)segm1PosPhi+=2*
M_PI;
143 if(segm1PosThe>
M_PI/2) segm1PosThe=
M_PI-segm1PosThe;
150 int nTGCStrips[4] = { 0, 0, 0, 0};
156 stationName = int(
m_idHelperSvc->mdtIdHelper().stationName(
id));
159 if(((stationName==41)||(stationName==42))&&isStrip)nTGCStrips[0]++;
160 if(((stationName==43)||(stationName==44))&&isStrip)nTGCStrips[1]++;
161 if(((stationName==45)||(stationName==46))&&isStrip)nTGCStrips[2]++;
162 if(((stationName==47)||(stationName==48))&&isStrip)nTGCStrips[3]++;
166 if((nTGCStrips[1]==0)&&(nTGCStrips[2]==0)){canCheckSector[0]=
false;canCheckGlobal[0]=
false;}
167 if((nTGCStrips[0]==0)&&(nTGCStrips[2]==0)){canCheckSector[1]=
false;canCheckGlobal[1]=
false;}
168 if((nTGCStrips[0]==0)&&(nTGCStrips[1]==0)){canCheckSector[2]=
false;canCheckGlobal[2]=
false;}
174 for(
int n2=0; n2<nSegm;n2++){
181 nDisqualifiedSegm=disqualifiedSegments[i][2].size();
182 for(
int ndis=0;ndis<nDisqualifiedSegm;ndis++)
if(segm1==disqualifiedSegments[i][2].at(ndis))skipSegm=
true;
183 if(skipSegm)
continue;
187 float segm2PosRho = std::abs(segm2Pos.perp());
188 float segm2PosPhi = segm2Pos.phi();
189 float segm2PosZ = segm2Pos.z();
190 if(segm2PosPhi<0)segm2PosPhi+=2*
M_PI;
194 float dPhi_Segm1_Segm2 = segm1PosPhi-segm2PosPhi;
195 if(dPhi_Segm1_Segm2<-
M_PI)dPhi_Segm1_Segm2+=2*
M_PI;
196 if(dPhi_Segm1_Segm2>
M_PI)dPhi_Segm1_Segm2-=2*
M_PI;
197 if(std::abs(dPhi_Segm1_Segm2)<dPhiCutSegmentMatching){
198 failedGroupingCut=
true;
203 float dZ = std::abs(segm2PosZ)-std::abs(segm1PosZ);
205 float extrPosRho = std::abs(extrPos.perp());
206 float extrPosThe = extrPos.theta();
207 float extrPosPhi = extrPos.phi();
208 if(extrPosThe>
M_PI/2) extrPosThe=
M_PI-extrPosThe;
209 if(extrPosPhi<0)extrPosPhi+=2*
M_PI;
212 float dRho_Extr_Segm2 = extrPosRho-segm2PosRho;
213 float dPhi_Extr_Segm2 = extrPosPhi-segm2PosPhi;
214 if(dPhi_Extr_Segm2<-
M_PI)dPhi_Extr_Segm2+=2*
M_PI;
215 if(dPhi_Extr_Segm2>
M_PI)dPhi_Extr_Segm2-=2*
M_PI;
218 if((std::abs(dPhi_Extr_Segm2)<dPhiCutSegmentMatching)||
219 (std::abs(dRho_Extr_Segm2)<dRhoCutSegmentMatching)){
220 failedGroupingCut=
true;
224 if(failedGroupingCut)
continue;
229 int TGCStationNames[8] ={41, 42, 43, 44, 45, 46, 47, 48};
230 int TGCstation_StationFE[4] ={-1,-1,-1,-1};
231 int TGCstation_StationEta[4]={ 0, 0, 0, 0};
232 int TGCstation_StationPhi[4]={ 0, 0, 0, 0};
233 int nStationMatch[4] ={ 0, 0, 0, 0};
236 for(
int stationnameindex=0; stationnameindex<6; stationnameindex++){
238 int stationName = TGCStationNames[stationnameindex];
242 for(
int stationeta=1; stationeta<=8; stationeta++){
243 for(
int stationphi=1; stationphi<=48; stationphi++){
245 if(
m_TREarray[stationnameindex][i][stationeta][stationphi]==
nullptr)
continue;
250 float dZ_sector=std::abs(sectorZ)-std::abs(segm1PosZ);
252 Amg::Vector3D sectorExtrapolatedPos = segm1Pos+(segm1PosZunit*dZ_sector);
259 Amg::Vector2D sectorLocalPos2D(sectorLocalPos3D.y(),sectorLocalPos3D.z());
266 double tol1=-0.1*(avWidth/2);
267 double tol2=-0.1*(
length/2);
269 bool insideSectorBounds=tre->
bounds().
inside(sectorLocalPos2D,tol1,tol2);
270 if(!insideSectorBounds)
continue;
272 if(stationIndex<0)
continue;
273 TGCstation_StationFE[stationIndex]= (tre->
isForward()==
false);
274 TGCstation_StationEta[stationIndex]=stationeta;
275 TGCstation_StationPhi[stationIndex]=stationphi;
276 nStationMatch[stationIndex]++;
282 for(
int jTGC=0;jTGC<4;jTGC++){
283 if(nStationMatch[jTGC]==0){
284 canCheckSector[jTGC]=
false;
286 else if(nStationMatch[jTGC]>1){
287 canCheckSector[jTGC]=
false;
295 if((!canCheckGlobal[0])&&(!canCheckGlobal[1])&&(!canCheckGlobal[2])&&(!canCheckGlobal[3]))
continue;
299 bool sectorhitregistered[9][2] = {{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}};
300 std::vector<const Muon::TgcPrepData*> tpdVector[2];
311 prepitc!= prepitc_end;
320 int tgcAC=(tre->
sideA()==
false);
323 int stationName =
m_idHelperSvc->tgcIdHelper().stationName(tgcid);
329 if(tgcAC!=i)
continue;
330 if(stationName>46 || stationName<41)
continue;
335 if(stationIndex==3)
continue;
339 float tgcRho = std::abs(prdPos.perp());
340 float tgcPhi = prdPos.phi();
341 float tgcZ = prdPos.z();
342 if(tgcPhi<0)tgcPhi+=2*
M_PI;
345 float dZ = std::abs(tgcZ) - std::abs(segm1PosZ);
346 Amg::Vector3D tgcExtrapolatedPos = ((segm1Pos)+((segm1PosZunit)*dZ));
349 float tgcExtrRho = std::abs(tgcExtrapolatedPos.perp());
350 float tgcExtrPhi = tgcExtrapolatedPos.phi();
351 if(tgcExtrPhi<0)tgcExtrPhi+=2*
M_PI;
354 float dRho = tgcRho-tgcExtrRho;
355 float dPhi = tgcPhi-tgcExtrPhi;
360 if(std::abs(dPhi)<dPhiCut_Loose){
366 if(canCheckGlobal[stationIndex]){
367 float dRhoCut = dRhoCutGlobal[tgcWS]*tgcExtrRho;
368 if(std::abs(dPhi)<dPhiCutGlobal[tgcWS] && std::abs(dRho)<dRhoCut){
373 if(std::abs(dPhi)<dPhiCutSector[tgcWS] && std::abs(dRho)<dRhoCutSector[tgcWS]){
374 tpdVector[tgcWS].push_back(tpd);
377 if(canCheckSector[stationIndex]){
379 if((stationEta==TGCstation_StationEta[stationIndex])&&
380 (stationPhi==TGCstation_StationPhi[stationIndex])&&
381 (tgcFE==TGCstation_StationFE[stationIndex])){
383 if(std::abs(dPhi)<dPhiCutSector[tgcWS] && std::abs(dRho)<dRhoCutSector[tgcWS]){
384 if(layer>=0)sectorhitregistered[layer][tgcWS]=
true;
394 if((!canCheckGlobal[0])&&(!canCheckGlobal[1])&&(!canCheckGlobal[2])&&(!canCheckGlobal[3]))
continue;
400 std::vector<const Muon::TgcPrepData*> *bestTPDmatches[2];
401 bestTPDmatches[0] =
nullptr;
402 bestTPDmatches[1] =
nullptr;
403 if(bestTPDmatches[0]->
size()>0) bestTPDmatches[0]->clear();
404 if(bestTPDmatches[1]->
size()>0) bestTPDmatches[1]->clear();
405 int bestTPDlayerMatches[2][9] = {{0,0,0,0,0,0,0,0,0},
406 {0,0,0,0,0,0,0,0,0}};
408 for(
int k=0;k<2;k++){
414 int nTPD = tpdVector[k].size();
415 for(
int iTPD1=0;iTPD1<nTPD;iTPD1++){
417 std::vector<const Muon::TgcPrepData*> thisTPDmatches;
418 int thisTPDlayerMatches[9] = {0,0,0,0,0,0,0,0,0};
421 const Amg::Vector3D prdPos1 = tpdVector[k].at(iTPD1)->globalPosition();
423 float prd1Phi = prdPos1.phi();
424 float prd1Z = prdPos1.z();
425 if(prd1Phi<0)prd1Phi+=2*
M_PI;
429 Identifier tgcid1=(tpdVector[k].at(iTPD1))->identify();
430 int stationName1 =
m_idHelperSvc->tgcIdHelper().stationName(tgcid1);
433 if(layer1>=0)thisTPDlayerMatches[layer1]++;
436 for(
int iTPD2=0;iTPD2<nTPD;iTPD2++){
437 if(iTPD2==iTPD1)
continue;
440 const Amg::Vector3D prdPos2 = tpdVector[k].at(iTPD2)->globalPosition();
441 float prd2Rho = std::abs(prdPos2.perp());
442 float prd2Phi = prdPos2.phi();
443 float prd2Z = prdPos2.z();
444 if(prd2Phi<0)prd2Phi+=2*
M_PI;
447 float dZ = std::abs(prd2Z)- std::abs(prd1Z);
451 float prdExtrRho = std::abs(prdExtrPos.perp());
452 float prdExtrPhi = prdExtrPos.phi();
453 if(prdExtrPhi<0)prdExtrPhi+=2*
M_PI;
456 float dRho = prd2Rho-prdExtrRho;
457 float dPhi = prd2Phi-prdExtrPhi;
466 if(std::abs(dPhi)<dPhiCutTPD[k] && std::abs(dRho)<dRhoCutTPD[k]){
468 Identifier tgcid2=(tpdVector[k].at(iTPD2))->identify();
469 int stationName2 =
m_idHelperSvc->tgcIdHelper().stationName(tgcid2);
474 if(layer2>=0)thisTPDlayerMatches[layer2]++;
475 thisTPDmatches.push_back(tpdVector[k].at(iTPD2));
481 int nlayerCurrent = 0;
482 for(
int l=0;l<9;l++){
483 if(thisTPDlayerMatches[l]>0)nlayerCurrent++;
484 nPRDCurrent+=thisTPDlayerMatches[l];
488 if(nlayerMax <= nlayerCurrent){
489 if(nPRDMax < nPRDCurrent){
491 nlayerMax = nlayerCurrent;
492 nPRDMax = nPRDCurrent;
493 bestTPDmatches[k] = &thisTPDmatches;
494 for(
int l=0;l<9;l++){
495 bestTPDlayerMatches[k][l] = thisTPDlayerMatches[l];
502 if(nlayerMax==0)
continue;
503 if(bestTPDmatches[k]->
size()==0){
504 ATH_MSG_WARNING(
"MidstationOnly: empty bestTPDmatches["<<k<<
"] passed" );
509 for(
int jTGC1=0;jTGC1<3;jTGC1++){
512 for(
int l=0;l<9;l++){
514 if(jTGC1==jTGC2)
continue;
515 nMatchOther+=bestTPDlayerMatches[k][l];
519 if(nMatchOther<nMeasCutTGCMidPRD[k]){
520 canCheckGlobal[jTGC1]=
false;
521 canCheckSector[jTGC1]=
false;
527 if((!canCheckGlobal[0])&&(!canCheckGlobal[1])&&(!canCheckGlobal[2])&&(!canCheckGlobal[3]))
continue;
531 if(nValidatedSegm==0){
532 for(
int jTGC=0;jTGC<4;jTGC++){
538 canCheckSectorFill[jTGC] = canCheckSector[jTGC];
540 TGCstation_StationFEFill[jTGC] = TGCstation_StationFE[jTGC];
541 TGCstation_StationEtaFill[jTGC] = TGCstation_StationEta[jTGC];
542 TGCstation_StationPhiFill[jTGC] = TGCstation_StationPhi[jTGC];
544 for(
int l=0;l<9;l++){
545 for(
int k=0;k<2;k++){
546 sectorhitregisteredFill[l][k] = sectorhitregistered[l][k];
555 if(nValidatedSegm==1){
556 for(
int l=0;l<9;l++){
558 for(
int k=0;k<2;k++){
560 if(canCheckSectorFill[stationIndex]){
561 if((TGCstation_StationFEFill[stationIndex]<0)||(TGCstation_StationEtaFill[stationIndex]==0)||(TGCstation_StationPhiFill[stationIndex]==0)){
562 ATH_MSG_WARNING(
"MidstationOnly: canCheckSector passed for jTGC=" << stationIndex
563 <<
" but, FE="<<TGCstation_StationFEFill[stationIndex]
564 <<
" Eta="<<TGCstation_StationEtaFill[stationIndex]
565 <<
" Phi=" << TGCstation_StationPhiFill[stationIndex] );
569 int stationMap_EtaIndex=
getStationMapIndex(1, l, TGCstation_StationFEFill[stationIndex], TGCstation_StationEtaFill[stationIndex], TGCstation_StationPhiFill[stationIndex]);
570 int stationMap_PhiIndex=
getStationMapIndex(2, l, TGCstation_StationFEFill[stationIndex], TGCstation_StationEtaFill[stationIndex], TGCstation_StationPhiFill[stationIndex]);
573 if(sectorhitregisteredFill[l][k]){