Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:37:03

0001 //-------------------------------------------------
0002 //
0003 //   Class: DTRPCBxCorrection
0004 //
0005 //   DTRPCBxCorrection
0006 //
0007 //
0008 //   Author :
0009 //   G. Flouris               U Ioannina    Mar. 2015
0010 //modifications:  G Karathanasis   U Athens
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), m_phiRPCDigis(inphiRPCDigis) {}
0024 
0025 void DTRPCBxCorrection::run(const L1TTwinMuxParams& tmParams) {
0026   m_QualityLimit = tmParams.get_USERPCBXFORDTBELOWQUALITY();
0027   m_DphiWindow = tmParams.get_DphiWindowBxShift();
0028 
0029   BxCorrection(0);
0030   BxCorrection(1);
0031 
0032   m_dt_tsshifted.setContainer(m_l1ttma_out);
0033 }
0034 
0035 void DTRPCBxCorrection::BxCorrection(int track_seg) {
0036   L1MuTMChambPhContainer m_phiDTDigis_tm;
0037   //std::shared_ptr<L1MuTMChambPhContainer> m_phiDTDigis_tm (new L1MuTMChambPhContainer);
0038   const std::vector<L1MuDTChambPhDigi>* phiChambVectorDT;
0039   phiChambVectorDT = m_phiDTDigis.getContainer();
0040   m_phiDTDigis_tm.setContainer(*phiChambVectorDT);
0041   L1MuTMChambPhContainer m_phiRPCDigis_tm;
0042   //std::shared_ptr<L1MuTMChambPhContainer> m_phiRPCDigis_tm (new L1MuTMChambPhContainer);
0043   const std::vector<L1MuDTChambPhDigi>* phiChambVectorRPC;
0044   phiChambVectorRPC = m_phiRPCDigis.getContainer();
0045   m_phiRPCDigis_tm.setContainer(*phiChambVectorRPC);
0046 
0047   int ibx_dtm = 0, fbx_dtm = 0;
0048   int ibx_dtp = 0, fbx_dtp = 0;
0049 
0050   for (int wheel = -2; wheel <= 2; wheel++) {
0051     for (int sector = 0; sector < 12; sector++) {
0052       for (int station = 1; station <= 4; station++) {
0053         bool shifted[7] = {false, false, false, false, false, false, false};
0054         bool dups[7] = {false, false, false, false, false, false, false};
0055         bool secondTs[7] = {false, false, false, false, false, false, false};
0056         L1MuTMChambPhContainer shiftedPhiDTDigis;
0057         L1MuDTChambPhDigi* dtts_sh2nd = nullptr;
0058         for (int bx = 3; bx >= -3; bx--) {
0059           vector<int> delta_m, delta_p, delta_0;
0060           for (int rpcbx = bx - 1; rpcbx <= bx + 1; rpcbx++) {
0061             L1MuDTChambPhDigi* dtts = nullptr;
0062             L1MuDTChambPhDigi* rpcts1 = nullptr;
0063             dtts = m_phiDTDigis_tm.chPhiSegm(wheel, station, sector, bx, track_seg);
0064 
0065             if (!dtts)
0066               continue;
0067             int nhits = nRPCHits(m_phiRPCDigis_tm, rpcbx, wheel, sector, station);
0068             for (int hit = 0; hit < nhits; hit++) {
0069               rpcts1 = m_phiRPCDigis_tm.chPhiSegm(wheel, station, sector, rpcbx, hit);
0070               //Store in vectors the dphi of matched dt/rpc
0071               if (rpcts1 && dtts && dtts->code() < m_QualityLimit &&
0072                   deltaPhi(dtts->phi(), rpcts1->phi()) < m_DphiWindow) {
0073                 if ((dtts->bxNum() - rpcbx) == -1) {
0074                   delta_m.push_back(deltaPhi(dtts->phi(), rpcts1->phi()));
0075                   ibx_dtm = dtts->bxNum();
0076                   fbx_dtm = rpcbx;
0077                 }
0078                 if ((dtts->bxNum() - rpcbx) == 0) {
0079                   delta_0.push_back(deltaPhi(dtts->phi(), rpcts1->phi()));
0080                 }
0081                 if ((dtts->bxNum() - rpcbx) == 1) {
0082                   delta_p.push_back(deltaPhi(dtts->phi(), rpcts1->phi()));
0083                   ibx_dtp = dtts->bxNum();
0084                   fbx_dtp = rpcbx;
0085                 }
0086               }  //end if dtts and quality
0087             }
0088           }  //end of rpc bx and dtts, rpcts1, dttsnew go out of scope
0089 
0090           ///Concatanate all vectors in one
0091           vector<int> delta;
0092           delta.insert(delta.end(), delta_0.begin(), delta_0.end());
0093           delta.insert(delta.end(), delta_p.begin(), delta_p.end());
0094           delta.insert(delta.end(), delta_m.begin(), delta_m.end());
0095           ///Shift primitives if vector>0
0096           if (!delta.empty()) {
0097             L1MuDTChambPhDigi* dtts = nullptr;
0098             L1MuDTChambPhDigi* dttsnew = nullptr;
0099             L1MuDTChambPhDigi* dtts_sh = nullptr;
0100             std::vector<L1MuDTChambPhDigi> l1ttma_outsh;
0101             //Find the pair the min dphi(rpc,dt)
0102             unsigned int min_index = std::distance(delta.begin(), std::min_element(delta.begin(), delta.end())) + 0;
0103             int init_bx = 0, final_bx = 0;
0104 
0105             if (((delta_0.size() <= min_index) && (min_index < (delta_0.size() + delta_p.size())) &&
0106                  !delta_p.empty())) {
0107               init_bx = ibx_dtp;
0108               final_bx = fbx_dtp;
0109             } else if ((delta_0.size() + delta_p.size()) <= min_index && !delta_m.empty()) {
0110               init_bx = ibx_dtm;
0111               final_bx = fbx_dtm;
0112             } else
0113               continue;
0114             //Primitve to be shifted in place of dttsnew
0115             dtts = m_phiDTDigis_tm.chPhiSegm(wheel, station, sector, init_bx, track_seg);
0116             dttsnew = m_phiDTDigis_tm.chPhiSegm(wheel, station, sector, final_bx, track_seg);
0117             bool shift_1 = false;
0118             if (dtts && dtts->code() < m_QualityLimit && (!dttsnew || shifted[final_bx + 3] || dups[final_bx + 3])) {
0119               dtts_sh = new L1MuDTChambPhDigi(final_bx,
0120                                               dtts->whNum(),
0121                                               dtts->scNum(),
0122                                               dtts->stNum(),
0123                                               dtts->phi(),
0124                                               dtts->phiB(),
0125                                               dtts->code(),
0126                                               dtts->Ts2Tag(),
0127                                               dtts->BxCnt(),
0128                                               1);
0129               l1ttma_outsh.push_back(*dtts_sh);
0130               shifted[init_bx + 3] = true;
0131               shift_1 = true;
0132             }
0133             if (dtts && dtts->code() < m_QualityLimit && dttsnew)
0134               dups[init_bx + 3] = true;
0135 
0136             //dtts exists and qual lt m_QualityLimit and dttsnew exists and the previous (shift_1) prim was not shifted and there is empty space in second TS
0137             if (dtts && dtts->code() < m_QualityLimit && dttsnew && !shift_1 &&
0138                 !m_phiDTDigis_tm.chPhiSegm(wheel, station, sector, final_bx, flipBit(track_seg))) {
0139               ///XXX: Source of discrepancies
0140               ///in order to send as second TS the two prims must come from different halves of the station
0141               ///this information does not exist in data
0142               ///'simulate' this information by requiring different sign in phis and dphi>100
0143               if (sign(dtts->phi()) != sign(dttsnew->phi()) && deltaPhi(-(dtts->phi()), dttsnew->phi()) > 100) {
0144                 dtts_sh2nd = new L1MuDTChambPhDigi(final_bx,
0145                                                    dtts->whNum(),
0146                                                    dtts->scNum(),
0147                                                    dtts->stNum(),
0148                                                    dtts->phi(),
0149                                                    dtts->phiB(),
0150                                                    dtts->code(),
0151                                                    flipBit(track_seg),
0152                                                    dtts->BxCnt(),
0153                                                    1);
0154                 secondTs[final_bx + 3] = true;
0155                 dups[init_bx + 3] = false;
0156                 shifted[init_bx + 3] = true;
0157               }
0158             }
0159             shiftedPhiDTDigis.setContainer(l1ttma_outsh);
0160           }
0161         }  //end of bx
0162 
0163         for (int bx = -3; bx <= 3; bx++) {
0164           L1MuDTChambPhDigi* dtts = nullptr;
0165           if (secondTs[bx + 3])
0166             if (dtts_sh2nd) {
0167               m_l1ttma_out.push_back(*dtts_sh2nd);
0168             }
0169           dtts = shiftedPhiDTDigis.chPhiSegm(wheel, station, sector, bx, track_seg);
0170           if (dtts) {
0171             m_l1ttma_out.push_back(*dtts);
0172             continue;
0173           }
0174           if (dups[bx + 3])
0175             continue;
0176           ///if there is no shift then put the original primitive
0177           dtts = m_phiDTDigis_tm.chPhiSegm(wheel, station, sector, bx, track_seg);
0178           if (!shifted[bx + 3] && dtts) {
0179             m_l1ttma_out.push_back(*dtts);
0180           }
0181         }
0182 
0183       }  //end of station
0184     }  //end of sc
0185   }  //end of wheel
0186 }
0187 
0188 int DTRPCBxCorrection::deltaPhi(int dt_phi, int rpc2dt_phi) {
0189   int delta_phi = abs(dt_phi - rpc2dt_phi);
0190   return delta_phi;
0191 }
0192 
0193 int DTRPCBxCorrection::sign(float inv) {
0194   if (inv < 0)
0195     return -1;
0196   if (inv > 0)
0197     return 1;
0198   return 0;
0199 }
0200 
0201 int DTRPCBxCorrection::nRPCHits(L1MuTMChambPhContainer inCon, int bx, int wh, int sec, int st) {
0202   int size = 0;
0203   const std::vector<L1MuDTChambPhDigi>* vInCon = inCon.getContainer();
0204   for (auto& i : *vInCon) {
0205     if (bx == i.bxNum() && i.code() != 7 && i.whNum() == wh && i.scNum() == sec && i.stNum() == st)
0206       size++;
0207   }
0208 
0209   return size;
0210 }
0211 
0212 int DTRPCBxCorrection::nRPCHits(L1MuDTChambPhContainer inCon, int bx, int wh, int sec, int st) {
0213   int size = 0;
0214   const std::vector<L1MuDTChambPhDigi>* vInCon = inCon.getContainer();
0215   for (auto& i : *vInCon) {
0216     if (bx == i.bxNum() && i.code() != 7 && i.whNum() == wh && i.scNum() == sec && i.stNum() == st)
0217       size++;
0218   }
0219 
0220   return size;
0221 }