CMS 3D CMS Logo

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