CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch2/src/L1TriggerConfig/DTTPGConfig/src/DTConfigTSPhi.cc

Go to the documentation of this file.
00001 //-------------------------------------------------
00002 //
00003 //   Class: DTConfigSectColl
00004 //
00005 //   Description: Configurable parameters and constants 
00006 //   for Level1 Mu DT Trigger - TS Phi
00007 //
00008 //
00009 //   Author List:
00010 //   C. Battilana
00011 //
00012 //-----------------------------------------------------------------------
00013 
00014 //-----------------------
00015 // This Class's Header --
00016 //-----------------------
00017 #include "L1TriggerConfig/DTTPGConfig/interface/DTConfigTSPhi.h"
00018 
00019 //---------------
00020 // C++ Headers --
00021 //---------------
00022 #include <iostream>
00023 #include <cstring>
00024 
00025 //-------------------------------
00026 // Collaborating Class Headers --
00027 //-------------------------------
00028 
00029 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00030 
00031 //----------------
00032 // Constructors --
00033 //----------------
00034 DTConfigTSPhi::DTConfigTSPhi(const edm::ParameterSet& ps) { 
00035 
00036   setDefaults(ps);
00037   if (debug()) print();
00038 }
00039 
00040 DTConfigTSPhi::DTConfigTSPhi(bool debugTS, unsigned short int tss_buffer[7][31], int ntss, unsigned short int tsm_buffer[9]) { 
00041 
00042   m_ntss = 0;
00043   m_ntsm = 0;
00044 
00045   if (ntss == 0)
00046     return;
00047 
00048   m_debug = debugTS;
00049 
00050   bool tstren[24];
00051   bool tsscgs2, tsscgs1, tsscce1, tsshte1, tssnoe1, carrytss; 
00052   bool tsscce2, tsshte2, tssnoe2, tssccec, tsshtec, tssnoec;
00053   unsigned short  tssgs1, tssgs2, tssmsk1, tssmsk2;
00054 
00055   tsscgs2 = tsscgs1 = tsscce1 = tsshte1 = tssnoe1 = carrytss = 0;
00056   tsscce2 = tsshte2 = tssnoe2 = tssccec = tsshtec = tssnoec  = 0;
00057   tssgs1 = tssgs2 = tssmsk1 = tssmsk2 = 0;
00058 
00059   memset(tstren,true,24*sizeof(bool));
00060 
00061   // TSS unpacking
00062   for (int itss=0; itss<ntss; itss++) {     
00063     unsigned short int memory_tss[27];
00064 
00065     for(int ts=0;ts<27;ts++){
00066       memory_tss[ts] = tss_buffer[itss][ts+4];
00067       //std::cout << std::hex << memory_tss[ts] << " ";
00068     }
00069       
00070     tstren[itss*4]   = !(memory_tss[1]&0x08);
00071     tstren[itss*4+1] = !(memory_tss[1]&0x80);
00072     tstren[itss*4+2] = !(memory_tss[2]&0x08);
00073     tstren[itss*4+3] = !(memory_tss[2]&0x80);
00074 
00075     if(!itss) {
00076       tsscgs2 = !(memory_tss[0]&0x08);
00077       tssgs2  = memory_tss[0]&0x04 ? 0 : 1;
00078       tsscgs1 = !(memory_tss[0]&0x02);
00079       tssgs1  = memory_tss[0]&0x01 ? 0 : 1;
00080       tsscce1 = !(memory_tss[4]&0x04); 
00081       tsshte1 = !(memory_tss[4]&0x02); 
00082       tssnoe1 = !(memory_tss[4]&0x01);
00083       tsscce2 = !(memory_tss[3]&0x40); 
00084       tsshte2 = !(memory_tss[3]&0x20); 
00085       tssnoe2 = !(memory_tss[3]&0x10); 
00086       tssccec = !(memory_tss[3]&0x04); 
00087       tsshtec = !(memory_tss[3]&0x02); 
00088       tssnoec = !(memory_tss[3]&0x01);
00089       carrytss= !(memory_tss[4]&0x40);
00090       tssmsk1  = memory_tss[4]&0x10 ? 132 : 312;
00091       tssmsk2  = memory_tss[4]&0x20 ? 132 : 312;
00092     }
00093     
00094     m_ntss++;
00095 
00096   }
00097 
00098   // TSM unpacking
00099   unsigned short int memory_tsms[2], memory_tsmdu[2], memory_tsmdd[2];
00100 
00101   for(int ts=0;ts<2;ts++){
00102     memory_tsms[ts]  = tsm_buffer[ts+3];
00103     memory_tsmdu[ts] = tsm_buffer[ts+5];
00104     memory_tsmdd[ts] = tsm_buffer[ts+7];
00105     //std::cout << std::hex << memory_tsms[ts] << " " 
00106     //<< memory_tsmdu[ts] << " " << memory_tsmdd[ts] << " " << std::endl;
00107   }
00108 
00109   bool tsmcgs1 = true;
00110   unsigned short  tsmgs1  = memory_tsms[1]&0x02 ? 0 : 1;
00111   bool tsmcgs2 = true;
00112   unsigned short  tsmgs2  = 1;
00113   bool tsmcce1 = true; 
00114   bool tsmhte1 = true;  
00115   bool tsmnoe1 = true; 
00116   bool tsmcce2 = true; 
00117   bool tsmhte2 = true; 
00118   bool tsmnoe2 = true;
00119   bool tsmccec = true; 
00120   bool tsmhtec = true; 
00121   bool tsmnoec = true;
00122   bool carrytsms = !(memory_tsms[1]&0x01);
00123   unsigned short tsmmsk1  = memory_tsms[1]&0x08 ? 321 : 312;
00124   unsigned short tsmmsk2  = tsmmsk1;
00125   bool tsmword[8];
00126   tsmword[0] = !((memory_tsmdu[0]&0x80)&&(memory_tsmdd[0]&0x80)); 
00127   tsmword[1] = !(memory_tsms[0]&0x01); 
00128   tsmword[2] = !(memory_tsms[0]&0x02);
00129   tsmword[3] = !(memory_tsms[0]&0x04);
00130   tsmword[4] = !(memory_tsms[0]&0x08); 
00131   tsmword[5] = !(memory_tsms[0]&0x10);
00132   tsmword[6] = !(memory_tsms[0]&0x20); 
00133   tsmword[7] = !(memory_tsms[0]&0x40); 
00134   bool carrytsmd = !((memory_tsmdu[0]&0x10)&&(memory_tsmdd[0]&0x10));
00135     
00136   unsigned short tsmhsp = carrytss && carrytsms && carrytsmd;
00137 
00138   m_ntsm++;
00139 
00140   if (debug()) {
00141     std::cout << "TSS :" << std::dec << std::endl << "tstren= " ;
00142     for (int i=0; i<24 ;i++) std::cout << tstren[i] << " ";
00143     std::cout << " tsscgs1="  << tsscgs1
00144               << " tssgs1="   << tssgs1
00145               << " tsscgs2="  << tsscgs2
00146               << " tssgs2="   << tssgs2
00147               << " tsscce1="  << tsscce1
00148               << " tsshte1="  << tsshte1
00149               << " tssnoe1="  << tssnoe1
00150               << " tsscce2="  << tsscce2
00151               << " tsshte2="  << tsshte2
00152               << " tssnoe2="  << tssnoe2
00153               << " tssccec="  << tssccec
00154               << " tsshtec="  << tsshtec
00155               << " tssnoec="  << tssnoec
00156               << " carrytss=" << carrytss
00157               << " tssmsk1="  << tssmsk1
00158               << " tssmsk2="  << tssmsk2 << std::endl;
00159 
00160     std::cout << "TSM : "<< std::endl
00161               << "tsmcgs1="  << tsmcgs1
00162               << " tsmgs1="   << tsmgs1
00163               << " tsmcgs2="  << tsmcgs2
00164               << " tsmgs2="   << tsmgs2
00165               << " tsmcce1="  << tsmcce1
00166               << " tsmhte1="  << tsmhte1
00167               << " tsmnoe1="  << tsmnoe1
00168               << " tsmcce2="  << tsmcce2
00169               << " tsmhte2="  << tsmhte2
00170               << " tsmnoe2="  << tsmnoe2
00171               << " tsmccec="  << tsmccec
00172               << " tsmhtec="  << tsmhtec
00173               << " tsmnoec="  << tsmnoec
00174               << " tsmhsp=" << tsmhsp
00175               << " carrytsms=" << carrytsms
00176               << " carrytsmd=" << carrytsmd
00177               << " tsmword="; 
00178     for (int i=0;i<8;i++) std::cout << tsmword[i] << " ";
00179     std::cout << " tsmmsk1="  << tsmmsk1
00180               << " tsmmsk2="  << tsmmsk2 << std::endl;
00181   }
00182 
00183   setTssMasking(tssmsk1,1);
00184   setTssMasking(tssmsk2,2);
00185   setTssHtrigEna(tsshte1,1);
00186   setTssHtrigEna(tsshte2,2);
00187   setTssHtrigEnaCarry(tsshtec);
00188   setTssInOutEna(tssnoe1,1);
00189   setTssInOutEna(tssnoe2,2);
00190   setTssInOutEnaCarry(tssnoec);
00191   setTssCorrEna(tsscce1,1);
00192   setTssCorrEna(tsscce2,2);
00193   setTssCorrEnaCarry(tssccec);
00194   setTssGhost1Flag(tssgs1);
00195   setTssGhost2Flag(tssgs2);
00196   setTssGhost1Corr(tsscgs1);
00197   setTssGhost2Corr(tsscgs2);
00198 
00199   setTsmMasking(tsmmsk1,1);
00200   setTsmMasking(tsmmsk2,2);
00201   setTsmHtrigEna(tsmhte1,1);
00202   setTsmHtrigEna(tsmhte2,2);
00203   setTsmHtrigEnaCarry(tsmhtec);
00204   setTsmInOutEna(tsmnoe1,1);
00205   setTsmInOutEna(tsmnoe2,2);
00206   setTsmInOutEnaCarry(tsmnoec);
00207   setTsmCorrEna(tsmcce1,1);
00208   setTsmCorrEna(tsmcce2,2);
00209   setTsmCorrEnaCarry(tsmccec);
00210   setTsmGhost1Flag(tsmgs1);
00211   setTsmGhost2Flag(tsmgs2);
00212   setTsmGhost1Corr(tsmcgs1);
00213   setTsmGhost2Corr(tsmcgs2);
00214   setTsmCarryFlag(tsmhsp);
00215 
00216   for (int i=0;i<24;i++) setUsedTraco(i,tstren[i]);
00217   for (int i=0;i<8;i++) setTsmStatus(i,tsmword[i]);
00218   
00219     
00220 }
00221 
00222 //--------------
00223 // Destructor --
00224 //--------------
00225 DTConfigTSPhi::~DTConfigTSPhi() {}
00226 
00227 //--------------
00228 // Operations --
00229 //--------------
00230 
00231 void
00232 DTConfigTSPhi::setDefaults(const edm::ParameterSet& ps) {
00233 
00234   m_ntss = 1; //dummy param used only in DB config
00235   m_ntsm = 1; //dummy param used only in DB config
00236 
00237   // Debug flag 
00238   m_debug = ps.getUntrackedParameter<bool>("Debug");
00239   
00240   // Order of quaity bits in TSS for sort1
00241   int mymsk = ps.getParameter<int>("TSSMSK1");
00242   if (checkMask(mymsk)) 
00243     m_tssmsk[0] = mymsk;
00244   else {
00245     edm::LogVerbatim("DTTPG") << "DTConfigTSPhi::setDefaults : TSSMSK1 not in correct form: " << mymsk << std::endl;
00246   }
00247   
00248   // Order of quaity bits in TSS for sort2
00249   mymsk= ps.getParameter<int>("TSSMSK2");  
00250   if (checkMask(mymsk)) 
00251     m_tssmsk[1] = mymsk;
00252   else {
00253     edm::LogVerbatim("DTTPG") << "DTConfigTSPhi::setDefaults : TSSMSK2 not in correct form: " << mymsk << std::endl;
00254   }
00255   
00256   // Htrig checking in TSS for sort1
00257   m_tsshte[0] = ps.getParameter<bool>("TSSHTE1");
00258   
00259   // Htrig checking in TSS for sort2
00260   m_tsshte[1] = ps.getParameter<bool>("TSSHTE2");
00261 
00262   // Htrig checking in TSS for carry
00263   m_tsshte[2] = ps.getParameter<bool>("TSSHTEC");
00264 
00265   // Inner SL checking in TSS for sort1
00266   m_tssnoe[0] = ps.getParameter<bool>("TSSNOE1");
00267   
00268   // Inner SL checking in TSS for sort2
00269   m_tssnoe[1] = ps.getParameter<bool>("TSSNOE2");
00270  
00271   // Inner SL checking in TSS for carry
00272   m_tssnoe[2] = ps.getParameter<bool>("TSSNOEC");
00273 
00274   // Correlation checking in TSS for sort1
00275   m_tsscce[0] = ps.getParameter<bool>("TSSCCE1");
00276 
00277   // Correlation checking in TSS for sort2
00278   m_tsscce[1] = ps.getParameter<bool>("TSSCCE2");
00279  
00280   // Correlation checking in TSS for carry
00281   m_tsscce[2] = ps.getParameter<bool>("TSSCCEC");
00282 
00283   // Ghost 1 supperssion option in TSS
00284   int mygs = ps.getParameter<int>("TSSGS1");
00285   if (mygs>=0 && mygs<3)
00286     m_tssgs1 = mygs;
00287   else {
00288     edm::LogVerbatim("DTTPG") << "DTConfigTSPhi::setDefaults : TSSGS1 value is not correct: " << mygs << std::endl;
00289   }
00290   
00291   // Ghost 2 supperssion option in TSS
00292   mygs= ps.getParameter<int>("TSSGS2");
00293   if (mygs>=0 && mygs<5)
00294     m_tssgs2 = mygs;
00295   else {
00296     edm::LogVerbatim("DTTPG") << "DTConfigTSPhi::setDefaults : TSSGS2 value is not correct: " << mygs << std::endl;
00297   }
00298 
00299   // Correlated ghost 1 supperssion option in TSS
00300   m_tsscgs1 = ps.getParameter<bool>("TSSCGS1");
00301   
00302   // Correlated ghost 2 supperssion option in TSS
00303   m_tsscgs2 = ps.getParameter<bool>("TSSCGS2");
00304 
00305   // Order of quaity bits in TSM for sort1
00306   mymsk = ps.getParameter<int>("TSMMSK1");
00307   if (checkMask(mymsk)) 
00308     m_tsmmsk[0] = mymsk;
00309   else {
00310     edm::LogVerbatim("DTTPG") << "DTConfigTSPhi::setDefaults : TSMMSK1 not in correct form: " << mymsk << std::endl;
00311   }
00312 
00313   // Order of quaity bits in TSM for sort2
00314   mymsk= ps.getParameter<int>("TSMMSK2");
00315   if (checkMask(mymsk)) 
00316     m_tsmmsk[1] = mymsk;
00317   else {
00318     edm::LogVerbatim("DTTPG") << "DTConfigTSPhi::setDefaults : TSMMSK2 not in correct form: " << mymsk << std::endl;
00319   }
00320   
00321   // Htrig checking in TSM for sort1
00322   m_tsmhte[0] = ps.getParameter<bool>("TSMHTE1");
00323   
00324   // Htrig checking in TSM for sort2
00325   m_tsmhte[1] = ps.getParameter<bool>("TSMHTE2");
00326  
00327   // Htrig checking in TSM for carry
00328   m_tsmhte[2] = ps.getParameter<bool>("TSMHTEC");
00329   
00330   // Inner SL checking in TSM for sort1
00331   m_tsmnoe[0] = ps.getParameter<bool>("TSMNOE1");
00332   
00333   // Inner SL checking in TSM for sort2
00334   m_tsmnoe[1] = ps.getParameter<bool>("TSMNOE2");
00335  
00336   // Inner SL checking in TSM for carry
00337   m_tsmnoe[2] = ps.getParameter<bool>("TSMNOEC");
00338 
00339   // Correlation checking in TSM for sort1
00340   m_tsmcce[0] = ps.getParameter<bool>("TSMCCE1");
00341   
00342   // Correlation checking in TSM for sort2
00343   m_tsmcce[1] = ps.getParameter<bool>("TSMCCE2");
00344  
00345   // Correlation checking in TSM for carry
00346   m_tsmcce[2] = ps.getParameter<bool>("TSMCCEC");
00347 
00348   // Ghost 1 supperssion option in TSM
00349   mygs = ps.getParameter<int>("TSMGS1");
00350   if (mygs>=0 && mygs<3)
00351     m_tsmgs1 = mygs;
00352   else {
00353     edm::LogVerbatim("DTTPG") << "DTConfigTSPhi::setDefaults : TSMGS1 value is not correct: " << mygs << std::endl;
00354   }
00355 
00356   // Ghost 2 supperssion option in TSM
00357   mygs= ps.getParameter<int>("TSMGS2");
00358   if (mygs>=0 && mygs<5)
00359     m_tsmgs2 = mygs;
00360   else {
00361     edm::LogVerbatim("DTTPG") << "DTConfigTSPhi::setDefaults : TSMGS2 value is not correct: " << mygs << std::endl;
00362   }
00363 
00364   // Correlated ghost 1 supperssion option in TSM
00365   m_tsmcgs1 = ps.getParameter<bool>("TSMCGS1");
00366   
00367   // Correlated ghost 2 supperssion option in TSM
00368   m_tsmcgs2 = ps.getParameter<bool>("TSMCGS2");
00369 
00370   // Handling carry in case of pile-up
00371   int myhsp = ps.getParameter<int>("TSMHSP");
00372   if (myhsp>=0 && myhsp<3)
00373     m_tsmhsp = myhsp;
00374   else {
00375     edm::LogVerbatim("DTTPG") << "DTConfigTSPhi::setDefaults : TSMHSP value is not correct: " << myhsp << std::endl;
00376   }
00377 
00378   // Handling TSMS masking parameters
00379   m_tsmword.one();
00380   int word = ps.getParameter<int>("TSMWORD");
00381   if (word<0 || word>255){
00382     edm::LogVerbatim("DTTPG") << "DTConfigTSPhi::setDefaults : TSMWORD value is not correct: " << word << std::endl;
00383   }
00384   for (int i=0;i<7;i++){
00385     short int bit = word%2;
00386     word /= 2;
00387     if (bit==0) m_tsmword.unset(i);
00388   }
00389 
00391   m_tstren.one();
00392   for (int i=0;i<24;i++){
00393     std::stringstream os;
00394     os << "TSTREN" << i;
00395     if (ps.getParameter<bool>(os.str())== 0)
00396       m_tstren.unset(i);
00397   }
00398                   
00399 }
00400 
00401 int 
00402 DTConfigTSPhi::TSSinTSMD(int stat, int sect) { //CB it should set value when constructor is called (it should be done when we have station by station config)  
00403 
00404   // Number of TSS for each TSMD (it changes from station to station) The DT stations are indicated in parenthesis
00405   // in the DT column.
00406   //
00407   //      MB                    nb.TSS        nb.TTS per TSMD
00408   //      1                       3             2   
00409   //      2                       4             2  
00410   //      3                       5             3  
00411   //      4(1,2,3,5,6,7)          6             3   
00412   //      4(8,12)                 6             3   
00413   //      4(9,11)                 3             2     
00414   //      4(4L)                   5             3    
00415   //      4(4R)                   5             3    
00416   //      4(10L)                  4             2     
00417   //      4(10R)                  4             2     
00418   
00419   if( stat==1 ||
00420       stat==2 ||
00421       ( stat==4 && (sect==9 || sect==11 ||
00422                     sect==10))) {
00423     m_ntsstsmd = 2;
00424   } else {
00425     m_ntsstsmd = 3;
00426   }
00427 
00428   return (int)m_ntsstsmd;
00429 
00430 }
00431 
00432 void 
00433 DTConfigTSPhi::print() const {
00434 
00435   std::cout << "******************************************************************************" << std::endl;
00436   std::cout << "*              DTTrigger configuration : TSPhi chips                         *" << std::endl;
00437   std::cout << "******************************************************************************" << std::endl << std::endl;
00438   std::cout << "Debug flag : " <<  debug() << std::endl;
00439   std::cout << "               TSS Parameters:" << std::endl;
00440   std::cout <<  "TSSMSK 1/2:" << TssMasking(0) << " " <<  TssMasking(1) << std::endl;
00441   std::cout << "TSSHTE 1/2/carry :" << TssHtrigEna(0) << " " << TssHtrigEna(1) << " " << TssHtrigEnaCarry() << std::endl;
00442   std::cout << "TSSNOE 1/2/carry :" << TssInOutEna(0) << " " << TssInOutEna(1) << " " << TssInOutEnaCarry() << std::endl;
00443   std::cout << "TSSCCE 1/2/carry :" << TssCorrEna(0)  << " " << TssCorrEna(1)  << " " << TssCorrEnaCarry()  << std::endl;
00444   std::cout << "TSSGS 1/2:" << TssGhost1Flag() << " " << TssGhost2Flag() << std::endl;
00445   std::cout << "TSSCGS 1/2:" << TssGhost1Corr() << " " << TssGhost2Corr() << std::endl;
00446   std::cout << "               TSM Parameters:" << std::endl;
00447   std::cout << "TSMMSK 1/2:" << TsmMasking(0) << " " <<  TsmMasking(1) << std::endl;
00448   std::cout << "TSMHTE 1/2/carry :" << TsmHtrigEna(0) << " " << TsmHtrigEna(1) << " " << TsmHtrigEnaCarry() << std::endl;
00449   std::cout << "TSMNOE 1/2/carry :" << TsmInOutEna(0) << " " << TsmInOutEna(1) << " " << TsmInOutEnaCarry() << std::endl;
00450   std::cout << "TSMCCE 1/2/carry :" << TsmCorrEna(0)  << " " << TsmCorrEna(1)  << " " << TsmCorrEnaCarry()  << std::endl;
00451   std::cout << "TSMGS 1/2:" <<  TsmGhost1Flag() << " " << TsmGhost2Flag() << std::endl;
00452   std::cout << "TSMCGS 1/2:" <<  TsmGhost1Corr() << " " << TsmGhost2Corr() << std::endl;
00453   std::cout << "TSMHSP :" << TsmGetCarryFlag() << std::endl;
00454   std::cout << "TSTREN[i] :";
00455   for (int i=1;i<25;i++) std::cout << usedTraco(i) << " ";
00456   std::cout << std::endl;
00457   std::cout << "TSMWORD :";
00458   TsmStatus().print();
00459   std::cout << std::endl;
00460 //   int stat=4, sect=5;
00461 //   std::cout << "TSSTSMD(4,14 :" <<  TSSinTSMD(stat,sect) << std::endl;
00462   std::cout << "******************************************************************************" << std::endl;
00463 
00464 }
00465   
00466 
00467 int 
00468 DTConfigTSPhi::nValidTSS() {
00469 
00470   bool isMaskValid = checkMask(TssMasking(0)) && checkMask(TssMasking(1));
00471   bool isGsValid = (TssGhost1Flag()>=0 && TssGhost1Flag()<3) && (TssGhost2Flag()>=0 &&  TssGhost2Flag()<5);
00472   int nValidTSS = static_cast<int>(isMaskValid && isGsValid ? m_ntss : 0);   
00473 
00474   return nValidTSS;
00475 }
00476 
00477 int 
00478 DTConfigTSPhi::nValidTSM() {
00479 
00480   bool isMaskValid = checkMask( TsmMasking(0)) && checkMask(TsmMasking(1));
00481   bool isGsValid = (TsmGhost1Flag()>=0 && TsmGhost1Flag()<3) && (TsmGhost2Flag()>=0 &&  TsmGhost2Flag()<5);
00482   bool isCarryValid =  TsmGetCarryFlag()>=0 && TsmGetCarryFlag()<3;
00483   int nValidTSM = static_cast<int>(isMaskValid && isGsValid && isCarryValid ? m_ntsm : 0); 
00484   
00485   return nValidTSM;
00486 
00487 }
00488 
00489 bool
00490 DTConfigTSPhi::checkMask(unsigned short msk){
00491   
00492   bool hasone = false;
00493   bool hastwo = false;
00494   bool hasthree = false;
00495   for(int i=0;i<3;i++){
00496     int mynum = msk%10;
00497     switch (mynum){
00498     case 1:
00499       hasone = true;
00500       break;
00501     case 2:
00502       hastwo = true;
00503       break;
00504     case 3:
00505       hasthree =true;
00506       break;
00507     }
00508     msk /= 10;
00509   }
00510   if (hasone==true && hastwo==true && hasthree==true) return true;
00511   return false;
00512 
00513 }
00514 
00515