14 #include "../MdtVsTgcRawDataValAlg.h"
35 std::vector<const Muon::MuonSegment*> (&disqualifiedSegments)[2][4],
39 const float dRhoCutSegmentMatching = 1000;
40 const float dPhiCutSegmentMatching =
M_PI/8;
43 const int nMeasCutMdtMidstation = 5;
44 const int nMeasCutTGCMidPRD[2] = {2,2};
47 const float dPhiCut_Loose =
M_PI/8;
49 const float dPhiCutGlobal[2] = {
static_cast<float>(
M_PI/24),
static_cast<float>(
M_PI/12)};
50 const float dRhoCutGlobal[2] = { 0.08, 0.5};
52 const float dPhiCutSector[2] = { 0.2, 0.1};
53 const float dRhoCutSector[2] = { 300, 3000};
55 const float dPhiCutTPD[2] = { 0.15, 0.02};
56 const float dRhoCutTPD[2] = { 150, 3000};
61 int nValidatedSegm = 0;
66 bool canCheckSectorFill[4] = {0, 0, 0, 0};
71 int TGCstation_StationFEFill[4] = {-1,-1,-1,-1};
72 int TGCstation_StationEtaFill[4] = { 0, 0, 0, 0};
73 int TGCstation_StationPhiFill[4] = { 0, 0, 0, 0};
76 bool sectorhitregisteredFill[9][2] = {{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}};
78 bool skipSegm;
int nDisqualifiedSegm;
81 std::vector<const Muon::MuonSegment*> copyDisqualifiedSegments;
82 nDisqualifiedSegm=disqualifiedSegments[
i][2].size();
83 copyDisqualifiedSegments.reserve(nDisqualifiedSegm);
84 for(
int ndis=0;ndis<nDisqualifiedSegm;ndis++)copyDisqualifiedSegments.push_back(disqualifiedSegments[
i][2].at(ndis));
88 int nSegm = sortedSegments[
i][2].size();
89 for(
int n0=0; n0<nSegm;n0++){
95 nDisqualifiedSegm=copyDisqualifiedSegments.size();
96 for(
int ndis=0;ndis<nDisqualifiedSegm;ndis++)
if(segm0==copyDisqualifiedSegments.at(ndis))skipSegm=
true;
112 if(nMdtMeas<nMeasCutMdtMidstation){
113 copyDisqualifiedSegments.push_back(segm0);
118 for(
int n1=0;
n1<nSegm;
n1++){
126 nDisqualifiedSegm=copyDisqualifiedSegments.size();
127 for(
int ndis=0;ndis<nDisqualifiedSegm;ndis++)
if(segm1==copyDisqualifiedSegments.at(ndis))skipSegm=
true;
128 if(skipSegm)
continue;
131 bool failedGroupingCut =
false;
133 bool canCheckGlobal[4] = {
true,
true,
true,
false};
134 bool canCheckSector[4] = {
true,
true,
true,
false};
140 float segm1PosPhi = segm1Pos.phi();
141 float segm1PosThe = segm1Pos.theta();
142 float segm1PosZ = segm1Pos.z();
143 if(segm1PosPhi<0)segm1PosPhi+=2*
M_PI;
144 if(segm1PosThe>
M_PI/2) segm1PosThe=
M_PI-segm1PosThe;
151 int nTGCStrips[4] = { 0, 0, 0, 0};
167 if((nTGCStrips[1]==0)&&(nTGCStrips[2]==0)){canCheckSector[0]=
false;canCheckGlobal[0]=
false;}
168 if((nTGCStrips[0]==0)&&(nTGCStrips[2]==0)){canCheckSector[1]=
false;canCheckGlobal[1]=
false;}
169 if((nTGCStrips[0]==0)&&(nTGCStrips[1]==0)){canCheckSector[2]=
false;canCheckGlobal[2]=
false;}
175 for(
int n2=0; n2<nSegm;n2++){
182 nDisqualifiedSegm=disqualifiedSegments[
i][2].size();
183 for(
int ndis=0;ndis<nDisqualifiedSegm;ndis++)
if(segm1==disqualifiedSegments[
i][2].at(ndis))skipSegm=
true;
184 if(skipSegm)
continue;
188 float segm2PosRho = std::abs(segm2Pos.perp());
189 float segm2PosPhi = segm2Pos.phi();
190 float segm2PosZ = segm2Pos.z();
191 if(segm2PosPhi<0)segm2PosPhi+=2*
M_PI;
195 float dPhi_Segm1_Segm2 = segm1PosPhi-segm2PosPhi;
196 if(dPhi_Segm1_Segm2<-
M_PI)dPhi_Segm1_Segm2+=2*
M_PI;
197 if(dPhi_Segm1_Segm2>
M_PI)dPhi_Segm1_Segm2-=2*
M_PI;
198 if(std::abs(dPhi_Segm1_Segm2)<dPhiCutSegmentMatching){
199 failedGroupingCut=
true;
204 float dZ = std::abs(segm2PosZ)-std::abs(segm1PosZ);
206 float extrPosRho = std::abs(extrPos.perp());
207 float extrPosThe = extrPos.theta();
208 float extrPosPhi = extrPos.phi();
209 if(extrPosThe>
M_PI/2) extrPosThe=
M_PI-extrPosThe;
210 if(extrPosPhi<0)extrPosPhi+=2*
M_PI;
213 float dRho_Extr_Segm2 = extrPosRho-segm2PosRho;
214 float dPhi_Extr_Segm2 = extrPosPhi-segm2PosPhi;
215 if(dPhi_Extr_Segm2<-
M_PI)dPhi_Extr_Segm2+=2*
M_PI;
216 if(dPhi_Extr_Segm2>
M_PI)dPhi_Extr_Segm2-=2*
M_PI;
219 if((std::abs(dPhi_Extr_Segm2)<dPhiCutSegmentMatching)||
220 (std::abs(dRho_Extr_Segm2)<dRhoCutSegmentMatching)){
221 failedGroupingCut=
true;
225 if(failedGroupingCut)
continue;
230 int TGCStationNames[8] ={41, 42, 43, 44, 45, 46, 47, 48};
231 int TGCstation_StationFE[4] ={-1,-1,-1,-1};
232 int TGCstation_StationEta[4]={ 0, 0, 0, 0};
233 int TGCstation_StationPhi[4]={ 0, 0, 0, 0};
234 int nStationMatch[4] ={ 0, 0, 0, 0};
237 for(
int stationnameindex=0; stationnameindex<6; stationnameindex++){
239 int stationName = TGCStationNames[stationnameindex];
243 for(
int stationeta=1; stationeta<=8; stationeta++){
244 for(
int stationphi=1; stationphi<=48; stationphi++){
246 if(
m_TREarray[stationnameindex][
i][stationeta][stationphi]==
nullptr)
continue;
251 float dZ_sector=std::abs(sectorZ)-std::abs(segm1PosZ);
253 Amg::Vector3D sectorExtrapolatedPos = segm1Pos+(segm1PosZunit*dZ_sector);
260 Amg::Vector2D sectorLocalPos2D(sectorLocalPos3D.y(),sectorLocalPos3D.z());
267 double tol1=-0.1*(avWidth/2);
268 double tol2=-0.1*(
length/2);
270 bool insideSectorBounds=tre->
bounds().
inside(sectorLocalPos2D,tol1,tol2);
271 if(!insideSectorBounds)
continue;
273 if(stationIndex<0)
continue;
274 TGCstation_StationFE[stationIndex]= (tre->
isForward()==
false);
275 TGCstation_StationEta[stationIndex]=stationeta;
276 TGCstation_StationPhi[stationIndex]=stationphi;
277 nStationMatch[stationIndex]++;
283 for(
int jTGC=0;jTGC<4;jTGC++){
284 if(nStationMatch[jTGC]==0){
285 canCheckSector[jTGC]=
false;
287 else if(nStationMatch[jTGC]>1){
288 canCheckSector[jTGC]=
false;
296 if((!canCheckGlobal[0])&&(!canCheckGlobal[1])&&(!canCheckGlobal[2])&&(!canCheckGlobal[3]))
continue;
300 bool sectorhitregistered[9][2] = {{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}};
301 std::vector<const Muon::TgcPrepData*> tpdVector[2];
312 prepitc!= prepitc_end;
321 int tgcAC=(tre->
sideA()==
false);
330 if(tgcAC!=
i)
continue;
336 if(stationIndex==3)
continue;
340 float tgcRho = std::abs(prdPos.perp());
341 float tgcPhi = prdPos.phi();
342 float tgcZ = prdPos.z();
343 if(tgcPhi<0)tgcPhi+=2*
M_PI;
346 float dZ = std::abs(tgcZ) - std::abs(segm1PosZ);
347 Amg::Vector3D tgcExtrapolatedPos = ((segm1Pos)+((segm1PosZunit)*dZ));
350 float tgcExtrRho = std::abs(tgcExtrapolatedPos.perp());
351 float tgcExtrPhi = tgcExtrapolatedPos.phi();
352 if(tgcExtrPhi<0)tgcExtrPhi+=2*
M_PI;
355 float dRho = tgcRho-tgcExtrRho;
356 float dPhi = tgcPhi-tgcExtrPhi;
361 if(std::abs(
dPhi)<dPhiCut_Loose){
367 if(canCheckGlobal[stationIndex]){
368 float dRhoCut = dRhoCutGlobal[tgcWS]*tgcExtrRho;
369 if(std::abs(
dPhi)<dPhiCutGlobal[tgcWS] && std::abs(dRho)<dRhoCut){
374 if(std::abs(
dPhi)<dPhiCutSector[tgcWS] && std::abs(dRho)<dRhoCutSector[tgcWS]){
375 tpdVector[tgcWS].push_back(tpd);
378 if(canCheckSector[stationIndex]){
380 if((
stationEta==TGCstation_StationEta[stationIndex])&&
381 (
stationPhi==TGCstation_StationPhi[stationIndex])&&
382 (tgcFE==TGCstation_StationFE[stationIndex])){
384 if(std::abs(
dPhi)<dPhiCutSector[tgcWS] && std::abs(dRho)<dRhoCutSector[tgcWS]){
385 if(
layer>=0)sectorhitregistered[
layer][tgcWS]=
true;
395 if((!canCheckGlobal[0])&&(!canCheckGlobal[1])&&(!canCheckGlobal[2])&&(!canCheckGlobal[3]))
continue;
401 std::vector<const Muon::TgcPrepData*> *bestTPDmatches[2];
402 bestTPDmatches[0] =
nullptr;
403 bestTPDmatches[1] =
nullptr;
404 if(bestTPDmatches[0]->
size()>0) bestTPDmatches[0]->clear();
405 if(bestTPDmatches[1]->
size()>0) bestTPDmatches[1]->clear();
406 int bestTPDlayerMatches[2][9] = {{0,0,0,0,0,0,0,0,0},
407 {0,0,0,0,0,0,0,0,0}};
409 for(
int k=0;
k<2;
k++){
415 int nTPD = tpdVector[
k].size();
416 for(
int iTPD1=0;iTPD1<nTPD;iTPD1++){
418 std::vector<const Muon::TgcPrepData*> thisTPDmatches;
419 int thisTPDlayerMatches[9] = {0,0,0,0,0,0,0,0,0};
422 const Amg::Vector3D prdPos1 = tpdVector[
k].at(iTPD1)->globalPosition();
424 float prd1Phi = prdPos1.phi();
425 float prd1Z = prdPos1.z();
426 if(prd1Phi<0)prd1Phi+=2*
M_PI;
431 int stationName1 =
m_idHelperSvc->tgcIdHelper().stationName(tgcid1);
434 if(layer1>=0)thisTPDlayerMatches[layer1]++;
437 for(
int iTPD2=0;iTPD2<nTPD;iTPD2++){
438 if(iTPD2==iTPD1)
continue;
441 const Amg::Vector3D prdPos2 = tpdVector[
k].at(iTPD2)->globalPosition();
442 float prd2Rho = std::abs(prdPos2.perp());
443 float prd2Phi = prdPos2.phi();
444 float prd2Z = prdPos2.z();
445 if(prd2Phi<0)prd2Phi+=2*
M_PI;
448 float dZ = std::abs(prd2Z)- std::abs(prd1Z);
452 float prdExtrRho = std::abs(prdExtrPos.perp());
453 float prdExtrPhi = prdExtrPos.phi();
454 if(prdExtrPhi<0)prdExtrPhi+=2*
M_PI;
457 float dRho = prd2Rho-prdExtrRho;
458 float dPhi = prd2Phi-prdExtrPhi;
467 if(std::abs(
dPhi)<dPhiCutTPD[
k] && std::abs(dRho)<dRhoCutTPD[
k]){
470 int stationName2 =
m_idHelperSvc->tgcIdHelper().stationName(tgcid2);
475 if(layer2>=0)thisTPDlayerMatches[layer2]++;
476 thisTPDmatches.push_back(tpdVector[
k].at(iTPD2));
482 int nlayerCurrent = 0;
483 for(
int l=0;
l<9;
l++){
484 if(thisTPDlayerMatches[
l]>0)nlayerCurrent++;
485 nPRDCurrent+=thisTPDlayerMatches[
l];
489 if(nlayerMax <= nlayerCurrent){
490 if(nPRDMax < nPRDCurrent){
492 nlayerMax = nlayerCurrent;
493 nPRDMax = nPRDCurrent;
494 bestTPDmatches[
k] = &thisTPDmatches;
495 for(
int l=0;
l<9;
l++){
496 bestTPDlayerMatches[
k][
l] = thisTPDlayerMatches[
l];
503 if(nlayerMax==0)
continue;
504 if(bestTPDmatches[
k]->
size()==0){
510 for(
int jTGC1=0;jTGC1<3;jTGC1++){
513 for(
int l=0;
l<9;
l++){
515 if(jTGC1==jTGC2)
continue;
516 nMatchOther+=bestTPDlayerMatches[
k][
l];
520 if(nMatchOther<nMeasCutTGCMidPRD[
k]){
521 canCheckGlobal[jTGC1]=
false;
522 canCheckSector[jTGC1]=
false;
528 if((!canCheckGlobal[0])&&(!canCheckGlobal[1])&&(!canCheckGlobal[2])&&(!canCheckGlobal[3]))
continue;
532 if(nValidatedSegm==0){
533 for(
int jTGC=0;jTGC<4;jTGC++){
539 canCheckSectorFill[jTGC] = canCheckSector[jTGC];
541 TGCstation_StationFEFill[jTGC] = TGCstation_StationFE[jTGC];
542 TGCstation_StationEtaFill[jTGC] = TGCstation_StationEta[jTGC];
543 TGCstation_StationPhiFill[jTGC] = TGCstation_StationPhi[jTGC];
545 for(
int l=0;
l<9;
l++){
546 for(
int k=0;
k<2;
k++){
547 sectorhitregisteredFill[
l][
k] = sectorhitregistered[
l][
k];
556 if(nValidatedSegm==1){
557 for(
int l=0;
l<9;
l++){
559 for(
int k=0;
k<2;
k++){
561 if(canCheckSectorFill[stationIndex]){
562 if((TGCstation_StationFEFill[stationIndex]<0)||(TGCstation_StationEtaFill[stationIndex]==0)||(TGCstation_StationPhiFill[stationIndex]==0)){
563 ATH_MSG_WARNING(
"MidstationOnly: canCheckSector passed for jTGC=" << stationIndex
564 <<
" but, FE="<<TGCstation_StationFEFill[stationIndex]
565 <<
" Eta="<<TGCstation_StationEtaFill[stationIndex]
566 <<
" Phi=" << TGCstation_StationPhiFill[stationIndex] );
570 int stationMap_EtaIndex=
getStationMapIndex(1,
l, TGCstation_StationFEFill[stationIndex], TGCstation_StationEtaFill[stationIndex], TGCstation_StationPhiFill[stationIndex]);
571 int stationMap_PhiIndex=
getStationMapIndex(2,
l, TGCstation_StationFEFill[stationIndex], TGCstation_StationEtaFill[stationIndex], TGCstation_StationPhiFill[stationIndex]);
574 if(sectorhitregisteredFill[
l][
k]){