** Warning **
Issuing rollback() due to DESTROY without explicit disconnect() of DBD::mysql::db handle dbname=lxr at /lxr/lib/LXR/Common.pm line 1103.
Last-Modified: Thu, 29 Jun 2022 02:26:11 GMT
Content-Type: text/html; charset=utf-8
/CMSSW_12_5_X_2022-06-28-2300/L1Trigger/L1TTwinMux/src/DTRPCBxCorrection.cc
File indexing completed on 2021-07-28 03:10:06
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <iostream>
0013 #include <iomanip>
0014 #include <iterator>
0015 #include <algorithm>
0016
0017 #include "L1Trigger /L1TTwinMux /interface /DTRPCBxCorrection.h "
0018 #include "L1Trigger /L1TTwinMux /interface /L1MuTMChambPhContainer.h "
0019
0020 using namespace std ;
0021
0022 DTRPCBxCorrection ::DTRPCBxCorrection (L1MuDTChambPhContainer inphiDTDigis, L1MuDTChambPhContainer inphiRPCDigis)
0023 : m_phiDTDigis (inphiDTDigis),
0024 m_phiRPCDigis (inphiRPCDigis){
0025
0026
0027 };
0028
0029 void DTRPCBxCorrection ::run (const L1TTwinMuxParams & tmParams ) {
0030 m_QualityLimit = tmParams .get_USERPCBXFORDTBELOWQUALITY ();
0031 m_DphiWindow = tmParams .get_DphiWindowBxShift ();
0032
0033 BxCorrection (0);
0034 BxCorrection (1);
0035
0036 m_dt_tsshifted .setContainer (m_l1ttma_out );
0037 }
0038
0039 void DTRPCBxCorrection ::BxCorrection (int track_seg) {
0040 L1MuTMChambPhContainer m_phiDTDigis_tm ;
0041
0042 const std ::vector <L1MuDTChambPhDigi >* phiChambVectorDT ;
0043 phiChambVectorDT = m_phiDTDigis .getContainer ();
0044 m_phiDTDigis_tm .setContainer (*phiChambVectorDT );
0045 L1MuTMChambPhContainer m_phiRPCDigis_tm ;
0046
0047 const std ::vector <L1MuDTChambPhDigi >* phiChambVectorRPC ;
0048 phiChambVectorRPC = m_phiRPCDigis .getContainer ();
0049 m_phiRPCDigis_tm .setContainer (*phiChambVectorRPC );
0050
0051 int ibx_dtm = 0, fbx_dtm = 0;
0052 int ibx_dtp = 0, fbx_dtp = 0;
0053
0054 for (int wheel = -2; wheel <= 2; wheel ++) {
0055 for (int sector = 0; sector < 12; sector ++) {
0056 for (int station = 1; station <= 4; station ++) {
0057 bool shifted [7] = {false , false , false , false , false , false , false };
0058 bool dups [7] = {false , false , false , false , false , false , false };
0059 bool secondTs [7] = {false , false , false , false , false , false , false };
0060 L1MuTMChambPhContainer shiftedPhiDTDigis ;
0061 L1MuDTChambPhDigi * dtts_sh2nd = nullptr ;
0062 for (int bx = 3; bx >= -3; bx --) {
0063 vector <int > delta_m , delta_p , delta_0 ;
0064 for (int rpcbx = bx - 1; rpcbx <= bx + 1; rpcbx ++) {
0065 L1MuDTChambPhDigi * dtts = nullptr ;
0066 L1MuDTChambPhDigi * rpcts1 = nullptr ;
0067 dtts = m_phiDTDigis_tm .chPhiSegm (wheel , station , sector , bx , track_seg);
0068
0069 if (!dtts )
0070 continue ;
0071 int nhits = nRPCHits (m_phiRPCDigis_tm , rpcbx , wheel , sector , station );
0072 for (int hit = 0; hit < nhits ; hit ++) {
0073 rpcts1 = m_phiRPCDigis_tm .chPhiSegm (wheel , station , sector , rpcbx , hit );
0074
0075 if (rpcts1 && dtts && dtts ->code () < m_QualityLimit &&
0076 deltaPhi (dtts ->phi (), rpcts1 ->phi ()) < m_DphiWindow ) {
0077 if ((dtts ->bxNum () - rpcbx ) == -1) {
0078 delta_m .push_back (deltaPhi (dtts ->phi (), rpcts1 ->phi ()));
0079 ibx_dtm = dtts ->bxNum ();
0080 fbx_dtm = rpcbx ;
0081 }
0082 if ((dtts ->bxNum () - rpcbx ) == 0) {
0083 delta_0 .push_back (deltaPhi (dtts ->phi (), rpcts1 ->phi ()));
0084 }
0085 if ((dtts ->bxNum () - rpcbx ) == 1) {
0086 delta_p .push_back (deltaPhi (dtts ->phi (), rpcts1 ->phi ()));
0087 ibx_dtp = dtts ->bxNum ();
0088 fbx_dtp = rpcbx ;
0089 }
0090 }
0091 }
0092 }
0093
0094
0095 vector <int > delta ;
0096 delta .insert (delta .end (), delta_0 .begin (), delta_0 .end ());
0097 delta .insert (delta .end (), delta_p .begin (), delta_p .end ());
0098 delta .insert (delta .end (), delta_m .begin (), delta_m .end ());
0099
0100 if (!delta .empty ()) {
0101 L1MuDTChambPhDigi * dtts = nullptr ;
0102 L1MuDTChambPhDigi * dttsnew = nullptr ;
0103 L1MuDTChambPhDigi * dtts_sh = nullptr ;
0104 std ::vector <L1MuDTChambPhDigi > l1ttma_outsh ;
0105
0106 unsigned int min_index = std ::distance (delta .begin (), std ::min_element (delta .begin (), delta .end ())) + 0;
0107 int init_bx = 0, final_bx = 0;
0108
0109 if (((delta_0 .size () <= min_index ) && (min_index < (delta_0 .size () + delta_p .size ())) &&
0110 !delta_p .empty ())) {
0111 init_bx = ibx_dtp ;
0112 final_bx = fbx_dtp ;
0113 } else if ((delta_0 .size () + delta_p .size ()) <= min_index && !delta_m .empty ()) {
0114 init_bx = ibx_dtm ;
0115 final_bx = fbx_dtm ;
0116 } else
0117 continue ;
0118
0119 dtts = m_phiDTDigis_tm .chPhiSegm (wheel , station , sector , init_bx , track_seg);
0120 dttsnew = m_phiDTDigis_tm .chPhiSegm (wheel , station , sector , final_bx , track_seg);
0121 bool shift_1 = false ;
0122 if (dtts && dtts ->code () < m_QualityLimit && (!dttsnew || shifted [final_bx + 3] || dups [final_bx + 3])) {
0123 dtts_sh = new L1MuDTChambPhDigi (final_bx ,
0124 dtts ->whNum (),
0125 dtts ->scNum (),
0126 dtts ->stNum (),
0127 dtts ->phi (),
0128 dtts ->phiB (),
0129 dtts ->code (),
0130 dtts ->Ts2Tag (),
0131 dtts ->BxCnt (),
0132 1);
0133 l1ttma_outsh .push_back (*dtts_sh );
0134 shifted [init_bx + 3] = true ;
0135 shift_1 = true ;
0136 }
0137 if (dtts && dtts ->code () < m_QualityLimit && dttsnew )
0138 dups [init_bx + 3] = true ;
0139
0140
0141 if (dtts && dtts ->code () < m_QualityLimit && dttsnew && !shift_1 &&
0142 !m_phiDTDigis_tm .chPhiSegm (wheel , station , sector , final_bx , flipBit (track_seg))) {
0143
0144
0145
0146
0147 if (sign (dtts ->phi ()) != sign (dttsnew ->phi ()) && deltaPhi (-(dtts ->phi ()), dttsnew ->phi ()) > 100) {
0148 dtts_sh2nd = new L1MuDTChambPhDigi (final_bx ,
0149 dtts ->whNum (),
0150 dtts ->scNum (),
0151 dtts ->stNum (),
0152 dtts ->phi (),
0153 dtts ->phiB (),
0154 dtts ->code (),
0155 flipBit (track_seg),
0156 dtts ->BxCnt (),
0157 1);
0158 secondTs [final_bx + 3] = true ;
0159 dups [init_bx + 3] = false ;
0160 shifted [init_bx + 3] = true ;
0161 }
0162 }
0163 shiftedPhiDTDigis .setContainer (l1ttma_outsh );
0164 }
0165 }
0166
0167 for (int bx = -3; bx <= 3; bx ++) {
0168 L1MuDTChambPhDigi * dtts = nullptr ;
0169 if (secondTs [bx + 3])
0170 if (dtts_sh2nd ) {
0171 m_l1ttma_out .push_back (*dtts_sh2nd );
0172 }
0173 dtts = shiftedPhiDTDigis .chPhiSegm (wheel , station , sector , bx , track_seg);
0174 if (dtts ) {
0175 m_l1ttma_out .push_back (*dtts );
0176 continue ;
0177 }
0178 if (dups [bx + 3])
0179 continue ;
0180
0181 dtts = m_phiDTDigis_tm .chPhiSegm (wheel , station , sector , bx , track_seg);
0182 if (!shifted [bx + 3] && dtts ) {
0183 m_l1ttma_out .push_back (*dtts );
0184 }
0185 }
0186
0187 }
0188 }
0189 }
0190 }
0191
0192 int DTRPCBxCorrection ::deltaPhi (int dt_phi, int rpc2dt_phi ) {
0193 int delta_phi = abs (dt_phi - rpc2dt_phi );
0194 return delta_phi ;
0195 }
0196
0197 int DTRPCBxCorrection ::sign (float inv ) {
0198 if (inv < 0)
0199 return -1;
0200 if (inv > 0)
0201 return 1;
0202 return 0;
0203 }
0204
0205 int DTRPCBxCorrection ::nRPCHits (L1MuTMChambPhContainer inCon, int bx , int wh , int sec , int st ) {
0206 int size = 0;
0207 const std ::vector <L1MuDTChambPhDigi >* vInCon = inCon.getContainer ();
0208 for (auto & i : *vInCon ) {
0209 if (bx == i .bxNum () && i .code () != 7 && i .whNum () == wh && i .scNum () == sec && i .stNum () == st )
0210 size ++;
0211 }
0212
0213 return size ;
0214 }
0215
0216 int DTRPCBxCorrection ::nRPCHits (L1MuDTChambPhContainer inCon, int bx , int wh , int sec , int st ) {
0217 int size = 0;
0218 const std ::vector <L1MuDTChambPhDigi >* vInCon = inCon.getContainer ();
0219 for (auto & i : *vInCon ) {
0220 if (bx == i .bxNum () && i .code () != 7 && i .whNum () == wh && i .scNum () == sec && i .stNum () == st )
0221 size ++;
0222 }
0223
0224 return size ;
0225 }