CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/L1Trigger/RPCTrigger/src/RPCConst.cc

Go to the documentation of this file.
00001 #include <cmath>
00002 #include <iostream> 
00003 #include <sstream> 
00004 #include <cstdio>
00005 #include "L1Trigger/RPCTrigger/interface/RPCConst.h"
00006 #include "L1Trigger/RPCTrigger/interface/RPCException.h"
00007 
00008 #define m_pi 3.14159265358979
00009 
00010 int RPCConst::iptFromPt(const double pt) {
00011   if(pt == 0.)return 0;
00012   if(pt<m_pts[0]) {
00013     //edm::LogError("RPCTrigger")<<"** RPCConst ** iptFromPt called with illegal pt="<<pt;
00014     std::string msg = "[RPCConst::iptFromPt] called with illegal pt=";
00015     std::ostringstream ostr;
00016     ostr<<pt;
00017     msg += ostr.str();
00018     throw RPCException(msg.c_str());
00019     return 0;
00020   }
00021  int ipt=RPCConst::IPT_MAX;
00022  while (pt < m_pts[ipt]) { ipt--; };
00023  return ipt;
00024 
00025 }
00026 
00027 
00028 double RPCConst::ptFromIpt(const int ipt) {
00029   
00030   if ( ipt<0 || ipt>RPCConst::IPT_MAX ) {
00031     //edm::LogError("RPCTrigger") <<"**RPCConst::ptFromIpt** problem with ipt: "<<ipt;
00032     std::string msg = "[RPCConst::ptFromIpt] problem with ipt: ";
00033     std::ostringstream ostr;
00034     ostr<<ipt;
00035     msg += ostr.str();
00036     throw RPCException(msg.c_str());
00037     return 0.;
00038   }
00039   else return m_pts[ipt];
00040 }
00041 
00042 
00043 double RPCConst::etaFromTowerNum(const int atower){
00044 
00045   int iabsitow = (atower >= 0)? atower: -atower;
00046   if (0==iabsitow) return 0.;
00047   if( iabsitow>RPCConst::ITOW_MAX) {
00048     //edm::LogError("RPCTrigger") << "**RPCConst::etaFromTowerNum** iabsitow>ITOW_MAX for m_tower:"
00049     //     << atower ;
00050     std::string msg = "[RPCConst::etaFromTowerNum] iabsitow>ITOW_MAX for m_tower:";
00051     std::ostringstream ostr;
00052     ostr<<atower;
00053     msg += ostr.str();
00054     throw RPCException(msg.c_str());
00055     return 0.;
00056   }
00057   double eta = (m_etas[iabsitow]+m_etas[iabsitow+1])/2.;
00058   return (atower>= 0) ? eta : -eta;
00059 }
00060 
00061 
00062 int RPCConst::towerNumFromEta(const double eta){
00063   int m_tower=0;
00064   double abseta = (eta >=0.) ? eta:-eta;
00065   while (m_tower<=ITOW_MAX){
00066       if(m_etas[m_tower] <= abseta && abseta< m_etas[m_tower+1])break;
00067       m_tower++;
00068   }
00069   if(m_tower > ITOW_MAX)
00070     m_tower = ITOW_MAX;
00071   return (eta>=0) ? m_tower:-m_tower; 
00072 }
00073 
00074 double RPCConst::phiFromSegmentNum(const int iseg) {
00075   double phi = OFFSET + 2.*m_pi*(iseg)/ (double) RPCConst::NSEG;
00076   return (phi <2.*m_pi) ? phi: phi-2.*m_pi;
00077 }
00078 
00079 double RPCConst::phiFromLogSegSec(const int logSegment, const int logSector) {
00080   int iseg = logSegment*12 + logSector;
00081   double phi = OFFSET + 2.*m_pi*(iseg)/ (double) RPCConst::NSEG;
00082   return (phi <2.*m_pi) ? phi: phi-2.*m_pi;
00083 }
00084 
00085 int RPCConst::segmentNumFromPhi(const double phi) {
00086   double iphi;
00087   if(phi-OFFSET < 0) {
00088     iphi = 2*m_pi + phi;
00089   }    
00090   else {
00091     iphi = phi-OFFSET;    
00092   }    
00093   int iseg = (int)(iphi * RPCConst::NSEG/(2.*m_pi));
00094   return iseg;
00095 }
00096 
00097 /*
00098 int RPCConst::checkBarrel(const int atower) {
00099   int iabsitow = (atower >= 0)? atower: -atower;
00100   if(iabsitow <= RPCConst::ITOW_MAX_LOWPT) {
00101     return 1;
00102   } else if (iabsitow <= RPCConst::ITOW_MAX) {
00103     return 0;
00104   }
00105   return -1;
00106 } */
00107 
00108 double RPCConst::vxMuRate(int ptCode) {  
00109   double pt_ev = RPCConst::ptFromIpt(ptCode);
00110   if (pt_ev == 0)
00111     return 0.0;
00112   const double lum = 2.0e33; //defoult is 1.0e34;
00113   const double dabseta = 1.0;
00114   const double dpt = 1.0;
00115   const double afactor = 1.0e-34*lum*dabseta*dpt;
00116   const double a  = 2*1.3084E6;
00117   const double mu=-0.725;
00118   const double sigma=0.4333;
00119   const double s2=2*sigma*sigma;
00120   
00121   double ptlog10;
00122   ptlog10 = log10(pt_ev);
00123   double ex = (ptlog10-mu)*(ptlog10-mu)/s2;
00124   double rate = (a * exp(-ex) * afactor); 
00125 
00126   //edm::LogError("RPCTrigger")<<ptCode<<" "<<rate;//<<<<<<<<<<<<<<<<<<<<<<<<
00127   return rate;
00128 }
00129 
00130 //muon rate for pt from ptCode to ptCode + 1
00131 //i.e for ptCode bin
00132 double RPCConst::vxIntegMuRate(int ptCode, double etaFrom, double etaTo) {  
00133   //calkowanie metoda trapezow - nie do konca dobre
00134   double rate = 0.5 * (vxMuRate(ptCode) + vxMuRate(ptCode+1))*
00135                (RPCConst::ptFromIpt(ptCode + 1) - RPCConst::ptFromIpt(ptCode));
00136 
00137   rate = rate * (etaTo - etaFrom);
00138 
00139   //edm::LogError("RPCTrigger")<<ptCode<<" "<<rate;//<<<<<<<<<<<<<<<<<<<<<<<<
00140   return rate;
00141 }
00142 
00143 //muon rate for pt from ptCode to ptCode + 1 in a given m_tower - only one!!! (mutliply by 2 to take oalso negative!!!)
00144 //i.e for ptCode bin
00145 double RPCConst::vxIntegMuRate(int ptCode, int m_tower) {  
00146   //calkowanie metoda trapezow - nie do konca dobre
00147   double rate = vxIntegMuRate(ptCode, RPCConst::m_etas[abs(m_tower)], RPCConst::m_etas[abs(m_tower)+1]);
00148 
00149   //edm::LogError("RPCTrigger")<<ptCode<<" "<<rate;//<<<<<<<<<<<<<<<<<<<<<<<<
00150   return rate;
00151 }
00152 
00153 
00154 /*
00155 const int RPCConst::IPT_THRESHOLD [2][RPCConst::ITOW_MAX+1]={
00156 //0   1   2   3   4     5   6   7   8   9    10  11  12  13  14  15  16  m_Tower
00157 {17, 17, 17, 17, 17,   16, 16, 15, 17, 14,   12, 11, 12, 17, 16, 15, 15}, //LOW
00158 {12, 12, 12, 12, 12,   11, 8,  11, 12, 9,    9,  8,  7,  11, 11, 11, 11} //VLOW
00159 };
00160 */
00161 
00162 
00163 
00164 const double RPCConst::m_pts[RPCConst::IPT_MAX+1]={
00165                         0.0,  0.01,    //<<<<<<<<<<<<<<<<<dla ptCode = 1 bylo 0, ale to powoduje problemy w vxMuRate
00166                         1.5,  2.0, 2.5,  3.0,  3.5,  4.0,  4.5, 
00167                         5.,   6.,   7.,   8.,  
00168                         10.,  12., 14.,  16.,  18.,  
00169                         20.,  25.,  30., 35.,  40.,  45., 
00170                         50.,  60.,  70., 80.,  90.,  100., 120., 140.};
00171 
00172 // m_etas contain approximate lower egges of eta towers
00173 // 0:ITOW_MAX  +additionaly upper edge  of last m_tower
00174 const double RPCConst::m_etas[RPCConst::ITOW_MAX+2]=
00175                                          {0.00, 0.07, 0.27, 0.44, 0.58, 0.72,
00176                                           0.83, 0.93, 1.04, 1.14, 1.24, 1.36,
00177                                           1.48, 1.61, 1.73, 1.85, 1.97, 2.10};
00178 
00179 // imported constants
00180 
00181     const std::string RPCConst::m_LOGPLANE_STR[RPCConst::m_LOGPLANES_COUNT] = {
00182       "m_LOGPLANE1", "m_LOGPLANE2", "m_LOGPLANE3", "m_LOGPLANE4", "m_LOGPLANE5", "m_LOGPLANE6"
00183     }; 
00184     
00185     const unsigned int RPCConst::m_LOGPLANE_SIZE[m_TOWER_COUNT][m_LOGPLANES_COUNT] = {
00186     //LOGPLANE  1,  2,  3   4   5   6
00187               {72, 56,  8, 40, 40, 24}, //TOWER 0
00188               {72, 56,  8, 40, 40, 24}, //TOWER 1
00189               {72, 56,  8, 40, 40, 24}, //TOWER 2
00190               {72, 56,  8, 40, 40, 24}, //TOWER 3
00191               {72, 56,  8, 40, 40, 24}, //TOWER 4
00192               {72, 56, 40,  8, 40, 24}, //TOWER 5
00193               {56, 72, 40,  8, 24,  0}, //TOWER 6
00194               {72, 56, 40,  8, 24,  0}, //TOWER 7
00195               {72, 24, 40,  8,  0,  0}, //TOWER 8
00196               {72,  8, 40,  0,  0,  0}, //TOWER 9
00197               {72,  8, 40, 24,  0,  0}, //TOWER 10
00198               {72,  8, 40, 24,  0,  0}, //TOWER 11
00199               {72,  8, 40, 24,  0,  0}, //TOWER 12
00200               {72,  8, 40, 24,  0,  0}, //TOWER 13
00201               {72,  8, 40, 24,  0,  0}, //TOWER 14
00202               {72,  8, 40, 24,  0,  0}, //TOWER 15
00203               {72,  8, 40, 24,  0,  0}  //TOWER 16
00204     };  
00205 
00206 
00207 
00208     const int RPCConst::m_VLPT_PLANES_COUNT[m_TOWER_COUNT] = {
00209       4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3,  3,  3,  3,  3,  3,  3
00210     };
00211 
00212     const int RPCConst::m_USED_PLANES_COUNT[m_TOWER_COUNT] = {
00213     //0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
00214       6, 6, 6, 6, 6, 6, 5, 5, 4, 3, 4,  4,  4,  4,  4,  4,  4
00215     };
00216 
00217     const int RPCConst::m_REF_PLANE[m_TOWER_COUNT] = {
00218     //     0,         1,         2,         3,         4,
00219       m_LOGPLANE3, m_LOGPLANE3, m_LOGPLANE3, m_LOGPLANE3, m_LOGPLANE3,
00220     //     5,         6,         7,         8,
00221       m_LOGPLANE4,  m_LOGPLANE4, m_LOGPLANE4, m_LOGPLANE4,
00222     //     9,         10,       11,        12,        13,        14,         15,        16,
00223       m_LOGPLANE2, m_LOGPLANE2, m_LOGPLANE2, m_LOGPLANE2, m_LOGPLANE2,  m_LOGPLANE2, m_LOGPLANE2, m_LOGPLANE2
00224     };
00225     
00226     
00227 /*    
00228     const int m_PT_CODE_MAX = 31; //!< Pt_code range = 0-m_PT_CODE_MAX
00229     
00230     const int m_LOGPLANE1 = 0; //!< The Logic Planes are named starting from '1', but in varoius loop indeks are from '0', that's why always use these consts 
00231     const int m_LOGPLANE2 = 1;
00232     const int m_LOGPLANE3 = 2;
00233     const int m_LOGPLANE4 = 3;
00234     const int m_LOGPLANE5 = 4;
00235     const int m_LOGPLANE6 = 5;
00236     
00237     const int m_FIRST_PLANE = m_LOGPLANE1; //!< Use ase a first index in loops.
00238     const int m_LAST_PLANE  = m_LOGPLANE6; //!< Use ase a last index in loops.
00239 */
00240     
00241 //------- imported fucntions
00242 
00243 int RPCConst::stringToInt(std::string str) {
00244   for(unsigned int i = 0; i < str.size(); i++)
00245     if(str[i] < '0' || str[i] > '9')
00246       throw RPCException("Error in stringToInt(): the string cannot be converted to a number");
00247       //edm::LogError("RPCTrigger")<< "Error in stringToInt(): the string cannot be converted to a number";
00248   return atoi(str.c_str());
00249 }
00250 
00251 //inline
00252 std::string RPCConst::intToString(int number) {
00253   std::string str;
00254   /* Some problems. AK
00255   std::ostringstream ostr;
00256   ostr<<number;
00257   str = ostr.str();
00258   edm::LogError("RPCTrigger")<<"std::string intToString(int number)";
00259   edm::LogError("RPCTrigger")<<str;
00260   */
00261   char tmp[20];
00262   sprintf(tmp,"%d",number);
00263   str.append(tmp);
00264   return str;
00265 }
00266 
00267  bool RPCConst::l1RpcConeCrdnts::operator <(const l1RpcConeCrdnts& cone) const{
00268   if(m_Tower != cone.m_Tower)
00269     return (m_Tower < cone.m_Tower);
00270   if(m_LogSector != cone.m_LogSector)
00271     return (m_LogSector < cone.m_LogSector);
00272   if(m_LogSegment != cone.m_LogSegment)
00273     return (m_LogSegment < cone.m_LogSegment);
00274 
00275   return false;
00276 }
00277 
00278  bool RPCConst::l1RpcConeCrdnts::operator ==(const l1RpcConeCrdnts& cone) const{
00279   if(m_Tower != cone.m_Tower)
00280     return false;
00281   if(m_LogSector != cone.m_LogSector)
00282     return false;
00283   if(m_LogSegment != cone.m_LogSegment)
00284     return false;
00285 
00286   return true;
00287 }
00288 
00289 
00290