Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:22:15

0001 //-------------------------------------------------
0002 //
0003 //   Class: DTConfigSectColl
0004 //
0005 //   Description: Configurable parameters and constants
0006 //   for Level1 Mu DT Trigger - TS Phi
0007 //
0008 //
0009 //   Author List:
0010 //   C. Battilana
0011 //
0012 //-----------------------------------------------------------------------
0013 
0014 //-----------------------
0015 // This Class's Header --
0016 //-----------------------
0017 #include "L1TriggerConfig/DTTPGConfig/interface/DTConfigTSPhi.h"
0018 
0019 //---------------
0020 // C++ Headers --
0021 //---------------
0022 #include <iostream>
0023 #include <cstring>
0024 
0025 //-------------------------------
0026 // Collaborating Class Headers --
0027 //-------------------------------
0028 
0029 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0030 
0031 //----------------
0032 // Constructors --
0033 //----------------
0034 DTConfigTSPhi::DTConfigTSPhi(const edm::ParameterSet& ps) {
0035   setDefaults(ps);
0036   if (debug())
0037     print();
0038 }
0039 
0040 DTConfigTSPhi::DTConfigTSPhi(bool debugTS,
0041                              unsigned short int tss_buffer[7][31],
0042                              int ntss,
0043                              unsigned short int tsm_buffer[9]) {
0044   m_ntss = 0;
0045   m_ntsm = 0;
0046 
0047   if (ntss == 0)
0048     return;
0049 
0050   m_debug = debugTS;
0051 
0052   bool tstren[24];
0053   bool tsscgs2, tsscgs1, tsscce1, tsshte1, tssnoe1, carrytss;
0054   bool tsscce2, tsshte2, tssnoe2, tssccec, tsshtec, tssnoec;
0055   unsigned short tssgs1, tssgs2, tssmsk1, tssmsk2;
0056 
0057   tsscgs2 = tsscgs1 = tsscce1 = tsshte1 = tssnoe1 = carrytss = false;
0058   tsscce2 = tsshte2 = tssnoe2 = tssccec = tsshtec = tssnoec = false;
0059   tssgs1 = tssgs2 = tssmsk1 = tssmsk2 = 0;
0060 
0061   memset(tstren, true, 24 * sizeof(bool));
0062 
0063   // TSS unpacking
0064   for (int itss = 0; itss < ntss; itss++) {
0065     unsigned short int memory_tss[27];
0066 
0067     for (int ts = 0; ts < 27; ts++) {
0068       memory_tss[ts] = tss_buffer[itss][ts + 4];
0069       //std::cout << std::hex << memory_tss[ts] << " ";
0070     }
0071 
0072     tstren[itss * 4] = !(memory_tss[1] & 0x08);
0073     tstren[itss * 4 + 1] = !(memory_tss[1] & 0x80);
0074     tstren[itss * 4 + 2] = !(memory_tss[2] & 0x08);
0075     tstren[itss * 4 + 3] = !(memory_tss[2] & 0x80);
0076 
0077     if (!itss) {
0078       tsscgs2 = !(memory_tss[0] & 0x08);
0079       tssgs2 = memory_tss[0] & 0x04 ? 0 : 1;
0080       tsscgs1 = !(memory_tss[0] & 0x02);
0081       tssgs1 = memory_tss[0] & 0x01 ? 0 : 1;
0082       tsscce1 = !(memory_tss[4] & 0x04);
0083       tsshte1 = !(memory_tss[4] & 0x02);
0084       tssnoe1 = !(memory_tss[4] & 0x01);
0085       tsscce2 = !(memory_tss[3] & 0x40);
0086       tsshte2 = !(memory_tss[3] & 0x20);
0087       tssnoe2 = !(memory_tss[3] & 0x10);
0088       tssccec = !(memory_tss[3] & 0x04);
0089       tsshtec = !(memory_tss[3] & 0x02);
0090       tssnoec = !(memory_tss[3] & 0x01);
0091       carrytss = !(memory_tss[4] & 0x40);
0092       tssmsk1 = memory_tss[4] & 0x10 ? 132 : 312;
0093       tssmsk2 = memory_tss[4] & 0x20 ? 132 : 312;
0094     }
0095 
0096     m_ntss++;
0097   }
0098 
0099   // TSM unpacking
0100   unsigned short int memory_tsms[2], memory_tsmdu[2], memory_tsmdd[2];
0101 
0102   for (int ts = 0; ts < 2; ts++) {
0103     memory_tsms[ts] = tsm_buffer[ts + 3];
0104     memory_tsmdu[ts] = tsm_buffer[ts + 5];
0105     memory_tsmdd[ts] = tsm_buffer[ts + 7];
0106     //std::cout << std::hex << memory_tsms[ts] << " "
0107     //<< memory_tsmdu[ts] << " " << memory_tsmdd[ts] << " " << std::endl;
0108   }
0109 
0110   bool tsmcgs1 = true;
0111   unsigned short tsmgs1 = memory_tsms[1] & 0x02 ? 0 : 1;
0112   bool tsmcgs2 = true;
0113   unsigned short tsmgs2 = 1;
0114   bool tsmcce1 = true;
0115   bool tsmhte1 = true;
0116   bool tsmnoe1 = true;
0117   bool tsmcce2 = true;
0118   bool tsmhte2 = true;
0119   bool tsmnoe2 = true;
0120   bool tsmccec = true;
0121   bool tsmhtec = true;
0122   bool tsmnoec = true;
0123   bool carrytsms = !(memory_tsms[1] & 0x01);
0124   unsigned short tsmmsk1 = memory_tsms[1] & 0x08 ? 321 : 312;
0125   unsigned short tsmmsk2 = tsmmsk1;
0126   bool tsmword[8];
0127   tsmword[0] = !((memory_tsmdu[0] & 0x80) && (memory_tsmdd[0] & 0x80));
0128   tsmword[1] = !(memory_tsms[0] & 0x01);
0129   tsmword[2] = !(memory_tsms[0] & 0x02);
0130   tsmword[3] = !(memory_tsms[0] & 0x04);
0131   tsmword[4] = !(memory_tsms[0] & 0x08);
0132   tsmword[5] = !(memory_tsms[0] & 0x10);
0133   tsmword[6] = !(memory_tsms[0] & 0x20);
0134   tsmword[7] = !(memory_tsms[0] & 0x40);
0135   bool carrytsmd = !((memory_tsmdu[0] & 0x10) && (memory_tsmdd[0] & 0x10));
0136 
0137   unsigned short tsmhsp = carrytss && carrytsms && carrytsmd;
0138 
0139   m_ntsm++;
0140 
0141   if (debug()) {
0142     std::cout << "TSS :" << std::dec << std::endl << "tstren= ";
0143     for (int i = 0; i < 24; i++)
0144       std::cout << tstren[i] << " ";
0145     std::cout << " tsscgs1=" << tsscgs1 << " tssgs1=" << tssgs1 << " tsscgs2=" << tsscgs2 << " tssgs2=" << tssgs2
0146               << " tsscce1=" << tsscce1 << " tsshte1=" << tsshte1 << " tssnoe1=" << tssnoe1 << " tsscce2=" << tsscce2
0147               << " tsshte2=" << tsshte2 << " tssnoe2=" << tssnoe2 << " tssccec=" << tssccec << " tsshtec=" << tsshtec
0148               << " tssnoec=" << tssnoec << " carrytss=" << carrytss << " tssmsk1=" << tssmsk1 << " tssmsk2=" << tssmsk2
0149               << std::endl;
0150 
0151     std::cout << "TSM : " << std::endl
0152               << "tsmcgs1=" << tsmcgs1 << " tsmgs1=" << tsmgs1 << " tsmcgs2=" << tsmcgs2 << " tsmgs2=" << tsmgs2
0153               << " tsmcce1=" << tsmcce1 << " tsmhte1=" << tsmhte1 << " tsmnoe1=" << tsmnoe1 << " tsmcce2=" << tsmcce2
0154               << " tsmhte2=" << tsmhte2 << " tsmnoe2=" << tsmnoe2 << " tsmccec=" << tsmccec << " tsmhtec=" << tsmhtec
0155               << " tsmnoec=" << tsmnoec << " tsmhsp=" << tsmhsp << " carrytsms=" << carrytsms
0156               << " carrytsmd=" << carrytsmd << " tsmword=";
0157     for (int i = 0; i < 8; i++)
0158       std::cout << tsmword[i] << " ";
0159     std::cout << " tsmmsk1=" << tsmmsk1 << " tsmmsk2=" << tsmmsk2 << std::endl;
0160   }
0161 
0162   setTssMasking(tssmsk1, 1);
0163   setTssMasking(tssmsk2, 2);
0164   setTssHtrigEna(tsshte1, 1);
0165   setTssHtrigEna(tsshte2, 2);
0166   setTssHtrigEnaCarry(tsshtec);
0167   setTssInOutEna(tssnoe1, 1);
0168   setTssInOutEna(tssnoe2, 2);
0169   setTssInOutEnaCarry(tssnoec);
0170   setTssCorrEna(tsscce1, 1);
0171   setTssCorrEna(tsscce2, 2);
0172   setTssCorrEnaCarry(tssccec);
0173   setTssGhost1Flag(tssgs1);
0174   setTssGhost2Flag(tssgs2);
0175   setTssGhost1Corr(tsscgs1);
0176   setTssGhost2Corr(tsscgs2);
0177 
0178   setTsmMasking(tsmmsk1, 1);
0179   setTsmMasking(tsmmsk2, 2);
0180   setTsmHtrigEna(tsmhte1, 1);
0181   setTsmHtrigEna(tsmhte2, 2);
0182   setTsmHtrigEnaCarry(tsmhtec);
0183   setTsmInOutEna(tsmnoe1, 1);
0184   setTsmInOutEna(tsmnoe2, 2);
0185   setTsmInOutEnaCarry(tsmnoec);
0186   setTsmCorrEna(tsmcce1, 1);
0187   setTsmCorrEna(tsmcce2, 2);
0188   setTsmCorrEnaCarry(tsmccec);
0189   setTsmGhost1Flag(tsmgs1);
0190   setTsmGhost2Flag(tsmgs2);
0191   setTsmGhost1Corr(tsmcgs1);
0192   setTsmGhost2Corr(tsmcgs2);
0193   setTsmCarryFlag(tsmhsp);
0194 
0195   for (int i = 0; i < 24; i++)
0196     setUsedTraco(i, tstren[i]);
0197   for (int i = 0; i < 8; i++)
0198     setTsmStatus(i, tsmword[i]);
0199 }
0200 
0201 //--------------
0202 // Destructor --
0203 //--------------
0204 DTConfigTSPhi::~DTConfigTSPhi() {}
0205 
0206 //--------------
0207 // Operations --
0208 //--------------
0209 
0210 void DTConfigTSPhi::setDefaults(const edm::ParameterSet& ps) {
0211   m_ntss = 1;  //dummy param used only in DB config
0212   m_ntsm = 1;  //dummy param used only in DB config
0213 
0214   // Debug flag
0215   m_debug = ps.getUntrackedParameter<bool>("Debug");
0216 
0217   // Order of quaity bits in TSS for sort1
0218   int mymsk = ps.getParameter<int>("TSSMSK1");
0219   if (checkMask(mymsk))
0220     m_tssmsk[0] = mymsk;
0221   else {
0222     edm::LogVerbatim("DTTPG") << "DTConfigTSPhi::setDefaults : TSSMSK1 not in correct form: " << mymsk << std::endl;
0223   }
0224 
0225   // Order of quaity bits in TSS for sort2
0226   mymsk = ps.getParameter<int>("TSSMSK2");
0227   if (checkMask(mymsk))
0228     m_tssmsk[1] = mymsk;
0229   else {
0230     edm::LogVerbatim("DTTPG") << "DTConfigTSPhi::setDefaults : TSSMSK2 not in correct form: " << mymsk << std::endl;
0231   }
0232 
0233   // Htrig checking in TSS for sort1
0234   m_tsshte[0] = ps.getParameter<bool>("TSSHTE1");
0235 
0236   // Htrig checking in TSS for sort2
0237   m_tsshte[1] = ps.getParameter<bool>("TSSHTE2");
0238 
0239   // Htrig checking in TSS for carry
0240   m_tsshte[2] = ps.getParameter<bool>("TSSHTEC");
0241 
0242   // Inner SL checking in TSS for sort1
0243   m_tssnoe[0] = ps.getParameter<bool>("TSSNOE1");
0244 
0245   // Inner SL checking in TSS for sort2
0246   m_tssnoe[1] = ps.getParameter<bool>("TSSNOE2");
0247 
0248   // Inner SL checking in TSS for carry
0249   m_tssnoe[2] = ps.getParameter<bool>("TSSNOEC");
0250 
0251   // Correlation checking in TSS for sort1
0252   m_tsscce[0] = ps.getParameter<bool>("TSSCCE1");
0253 
0254   // Correlation checking in TSS for sort2
0255   m_tsscce[1] = ps.getParameter<bool>("TSSCCE2");
0256 
0257   // Correlation checking in TSS for carry
0258   m_tsscce[2] = ps.getParameter<bool>("TSSCCEC");
0259 
0260   // Ghost 1 supperssion option in TSS
0261   int mygs = ps.getParameter<int>("TSSGS1");
0262   if (mygs >= 0 && mygs < 3)
0263     m_tssgs1 = mygs;
0264   else {
0265     edm::LogVerbatim("DTTPG") << "DTConfigTSPhi::setDefaults : TSSGS1 value is not correct: " << mygs << std::endl;
0266   }
0267 
0268   // Ghost 2 supperssion option in TSS
0269   mygs = ps.getParameter<int>("TSSGS2");
0270   if (mygs >= 0 && mygs < 5)
0271     m_tssgs2 = mygs;
0272   else {
0273     edm::LogVerbatim("DTTPG") << "DTConfigTSPhi::setDefaults : TSSGS2 value is not correct: " << mygs << std::endl;
0274   }
0275 
0276   // Correlated ghost 1 supperssion option in TSS
0277   m_tsscgs1 = ps.getParameter<bool>("TSSCGS1");
0278 
0279   // Correlated ghost 2 supperssion option in TSS
0280   m_tsscgs2 = ps.getParameter<bool>("TSSCGS2");
0281 
0282   // Order of quaity bits in TSM for sort1
0283   mymsk = ps.getParameter<int>("TSMMSK1");
0284   if (checkMask(mymsk))
0285     m_tsmmsk[0] = mymsk;
0286   else {
0287     edm::LogVerbatim("DTTPG") << "DTConfigTSPhi::setDefaults : TSMMSK1 not in correct form: " << mymsk << std::endl;
0288   }
0289 
0290   // Order of quaity bits in TSM for sort2
0291   mymsk = ps.getParameter<int>("TSMMSK2");
0292   if (checkMask(mymsk))
0293     m_tsmmsk[1] = mymsk;
0294   else {
0295     edm::LogVerbatim("DTTPG") << "DTConfigTSPhi::setDefaults : TSMMSK2 not in correct form: " << mymsk << std::endl;
0296   }
0297 
0298   // Htrig checking in TSM for sort1
0299   m_tsmhte[0] = ps.getParameter<bool>("TSMHTE1");
0300 
0301   // Htrig checking in TSM for sort2
0302   m_tsmhte[1] = ps.getParameter<bool>("TSMHTE2");
0303 
0304   // Htrig checking in TSM for carry
0305   m_tsmhte[2] = ps.getParameter<bool>("TSMHTEC");
0306 
0307   // Inner SL checking in TSM for sort1
0308   m_tsmnoe[0] = ps.getParameter<bool>("TSMNOE1");
0309 
0310   // Inner SL checking in TSM for sort2
0311   m_tsmnoe[1] = ps.getParameter<bool>("TSMNOE2");
0312 
0313   // Inner SL checking in TSM for carry
0314   m_tsmnoe[2] = ps.getParameter<bool>("TSMNOEC");
0315 
0316   // Correlation checking in TSM for sort1
0317   m_tsmcce[0] = ps.getParameter<bool>("TSMCCE1");
0318 
0319   // Correlation checking in TSM for sort2
0320   m_tsmcce[1] = ps.getParameter<bool>("TSMCCE2");
0321 
0322   // Correlation checking in TSM for carry
0323   m_tsmcce[2] = ps.getParameter<bool>("TSMCCEC");
0324 
0325   // Ghost 1 supperssion option in TSM
0326   mygs = ps.getParameter<int>("TSMGS1");
0327   if (mygs >= 0 && mygs < 3)
0328     m_tsmgs1 = mygs;
0329   else {
0330     edm::LogVerbatim("DTTPG") << "DTConfigTSPhi::setDefaults : TSMGS1 value is not correct: " << mygs << std::endl;
0331   }
0332 
0333   // Ghost 2 supperssion option in TSM
0334   mygs = ps.getParameter<int>("TSMGS2");
0335   if (mygs >= 0 && mygs < 5)
0336     m_tsmgs2 = mygs;
0337   else {
0338     edm::LogVerbatim("DTTPG") << "DTConfigTSPhi::setDefaults : TSMGS2 value is not correct: " << mygs << std::endl;
0339   }
0340 
0341   // Correlated ghost 1 supperssion option in TSM
0342   m_tsmcgs1 = ps.getParameter<bool>("TSMCGS1");
0343 
0344   // Correlated ghost 2 supperssion option in TSM
0345   m_tsmcgs2 = ps.getParameter<bool>("TSMCGS2");
0346 
0347   // Handling carry in case of pile-up
0348   int myhsp = ps.getParameter<int>("TSMHSP");
0349   if (myhsp >= 0 && myhsp < 3)
0350     m_tsmhsp = myhsp;
0351   else {
0352     edm::LogVerbatim("DTTPG") << "DTConfigTSPhi::setDefaults : TSMHSP value is not correct: " << myhsp << std::endl;
0353   }
0354 
0355   // Handling TSMS masking parameters
0356   m_tsmword.one();
0357   int word = ps.getParameter<int>("TSMWORD");
0358   if (word < 0 || word > 255) {
0359     edm::LogVerbatim("DTTPG") << "DTConfigTSPhi::setDefaults : TSMWORD value is not correct: " << word << std::endl;
0360   }
0361   for (int i = 0; i < 7; i++) {
0362     short int bit = word % 2;
0363     word /= 2;
0364     if (bit == 0)
0365       m_tsmword.unset(i);
0366   }
0367 
0368   //! Enabled TRACOs in TS
0369   m_tstren.one();
0370   for (int i = 0; i < 24; i++) {
0371     std::stringstream os;
0372     os << "TSTREN" << i;
0373     if (ps.getParameter<bool>(os.str()) == 0)
0374       m_tstren.unset(i);
0375   }
0376 }
0377 
0378 int DTConfigTSPhi::TSSinTSMD(int stat, int sect)
0379     const {  //CB it should set value when constructor is called (it should be done when we have station by station config)
0380 
0381   // Number of TSS for each TSMD (it changes from station to station) The DT stations are indicated in parenthesis
0382   // in the DT column.
0383   //
0384   //      MB                    nb.TSS        nb.TTS per TSMD
0385   //      1                       3             2
0386   //      2                       4             2
0387   //      3                       5             3
0388   //      4(1,2,3,5,6,7)          6             3
0389   //      4(8,12)                 6             3
0390   //      4(9,11)                 3             2
0391   //      4(4L)                   5             3
0392   //      4(4R)                   5             3
0393   //      4(10L)                  4             2
0394   //      4(10R)                  4             2
0395 
0396   if (stat == 1 || stat == 2 || (stat == 4 && (sect == 9 || sect == 11 || sect == 10))) {
0397     return 2;
0398   }
0399   return 3;
0400 }
0401 
0402 void DTConfigTSPhi::print() const {
0403   std::cout << "******************************************************************************" << std::endl;
0404   std::cout << "*              DTTrigger configuration : TSPhi chips                         *" << std::endl;
0405   std::cout << "******************************************************************************" << std::endl
0406             << std::endl;
0407   std::cout << "Debug flag : " << debug() << std::endl;
0408   std::cout << "               TSS Parameters:" << std::endl;
0409   std::cout << "TSSMSK 1/2:" << TssMasking(0) << " " << TssMasking(1) << std::endl;
0410   std::cout << "TSSHTE 1/2/carry :" << TssHtrigEna(0) << " " << TssHtrigEna(1) << " " << TssHtrigEnaCarry()
0411             << std::endl;
0412   std::cout << "TSSNOE 1/2/carry :" << TssInOutEna(0) << " " << TssInOutEna(1) << " " << TssInOutEnaCarry()
0413             << std::endl;
0414   std::cout << "TSSCCE 1/2/carry :" << TssCorrEna(0) << " " << TssCorrEna(1) << " " << TssCorrEnaCarry() << std::endl;
0415   std::cout << "TSSGS 1/2:" << TssGhost1Flag() << " " << TssGhost2Flag() << std::endl;
0416   std::cout << "TSSCGS 1/2:" << TssGhost1Corr() << " " << TssGhost2Corr() << std::endl;
0417   std::cout << "               TSM Parameters:" << std::endl;
0418   std::cout << "TSMMSK 1/2:" << TsmMasking(0) << " " << TsmMasking(1) << std::endl;
0419   std::cout << "TSMHTE 1/2/carry :" << TsmHtrigEna(0) << " " << TsmHtrigEna(1) << " " << TsmHtrigEnaCarry()
0420             << std::endl;
0421   std::cout << "TSMNOE 1/2/carry :" << TsmInOutEna(0) << " " << TsmInOutEna(1) << " " << TsmInOutEnaCarry()
0422             << std::endl;
0423   std::cout << "TSMCCE 1/2/carry :" << TsmCorrEna(0) << " " << TsmCorrEna(1) << " " << TsmCorrEnaCarry() << std::endl;
0424   std::cout << "TSMGS 1/2:" << TsmGhost1Flag() << " " << TsmGhost2Flag() << std::endl;
0425   std::cout << "TSMCGS 1/2:" << TsmGhost1Corr() << " " << TsmGhost2Corr() << std::endl;
0426   std::cout << "TSMHSP :" << TsmGetCarryFlag() << std::endl;
0427   std::cout << "TSTREN[i] :";
0428   for (int i = 1; i < 25; i++)
0429     std::cout << usedTraco(i) << " ";
0430   std::cout << std::endl;
0431   std::cout << "TSMWORD :";
0432   TsmStatus().print();
0433   std::cout << std::endl;
0434   //   int stat=4, sect=5;
0435   //   std::cout << "TSSTSMD(4,14 :" <<  TSSinTSMD(stat,sect) << std::endl;
0436   std::cout << "******************************************************************************" << std::endl;
0437 }
0438 
0439 int DTConfigTSPhi::nValidTSS() const {
0440   bool isMaskValid = checkMask(TssMasking(0)) && checkMask(TssMasking(1));
0441   bool isGsValid = (TssGhost1Flag() >= 0 && TssGhost1Flag() < 3) && (TssGhost2Flag() >= 0 && TssGhost2Flag() < 5);
0442   int nValidTSS = static_cast<int>(isMaskValid && isGsValid ? m_ntss : 0);
0443 
0444   return nValidTSS;
0445 }
0446 
0447 int DTConfigTSPhi::nValidTSM() const {
0448   bool isMaskValid = checkMask(TsmMasking(0)) && checkMask(TsmMasking(1));
0449   bool isGsValid = (TsmGhost1Flag() >= 0 && TsmGhost1Flag() < 3) && (TsmGhost2Flag() >= 0 && TsmGhost2Flag() < 5);
0450   bool isCarryValid = TsmGetCarryFlag() >= 0 && TsmGetCarryFlag() < 3;
0451   int nValidTSM = static_cast<int>(isMaskValid && isGsValid && isCarryValid ? m_ntsm : 0);
0452 
0453   return nValidTSM;
0454 }
0455 
0456 bool DTConfigTSPhi::checkMask(unsigned short msk) const {
0457   bool hasone = false;
0458   bool hastwo = false;
0459   bool hasthree = false;
0460   for (int i = 0; i < 3; i++) {
0461     int mynum = msk % 10;
0462     switch (mynum) {
0463       case 1:
0464         hasone = true;
0465         break;
0466       case 2:
0467         hastwo = true;
0468         break;
0469       case 3:
0470         hasthree = true;
0471         break;
0472     }
0473     msk /= 10;
0474   }
0475   if (hasone == true && hastwo == true && hasthree == true)
0476     return true;
0477   return false;
0478 }