Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:21:20

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),
0024       m_phiRPCDigis(inphiRPCDigis){
0025           //  m_phiDTDigis=inphiDTDigis;
0026           //  m_phiRPCDigis=inphiRPCDigis;
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   //std::shared_ptr<L1MuTMChambPhContainer> m_phiDTDigis_tm (new L1MuTMChambPhContainer);
0042   const std::vector<L1MuDTChambPhDigi>* phiChambVectorDT;
0043   phiChambVectorDT = m_phiDTDigis.getContainer();
0044   m_phiDTDigis_tm.setContainer(*phiChambVectorDT);
0045   L1MuTMChambPhContainer m_phiRPCDigis_tm;
0046   //std::shared_ptr<L1MuTMChambPhContainer> m_phiRPCDigis_tm (new L1MuTMChambPhContainer);
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               //Store in vectors the dphi of matched dt/rpc
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               }  //end if dtts and quality
0091             }
0092           }  //end of rpc bx and dtts, rpcts1, dttsnew go out of scope
0093 
0094           ///Concatanate all vectors in one
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           ///Shift primitives if vector>0
0100           if (!delta.empty()) {
0101             L1MuDTChambPhDigi* dtts = nullptr;
0102             L1MuDTChambPhDigi* dttsnew = nullptr;
0103             L1MuDTChambPhDigi* dtts_sh = nullptr;
0104             std::vector<L1MuDTChambPhDigi> l1ttma_outsh;
0105             //Find the pair the min dphi(rpc,dt)
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             //Primitve to be shifted in place of dttsnew
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             //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
0141             if (dtts && dtts->code() < m_QualityLimit && dttsnew && !shift_1 &&
0142                 !m_phiDTDigis_tm.chPhiSegm(wheel, station, sector, final_bx, flipBit(track_seg))) {
0143               ///XXX: Source of discrepancies
0144               ///in order to send as second TS the two prims must come from different halves of the station
0145               ///this information does not exist in data
0146               ///'simulate' this information by requiring different sign in phis and dphi>100
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         }  //end of bx
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           ///if there is no shift then put the original primitive
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       }  //end of station
0188     }    //end of sc
0189   }      //end of wheel
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 }