CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/FastSimDataFormats/L1GlobalMuonTrigger/src/SimpleL1MuGMTCand.cc

Go to the documentation of this file.
00001 // This class header:
00002 #include "FastSimDataFormats/L1GlobalMuonTrigger/interface/SimpleL1MuGMTCand.h"
00003 
00004 // Fast Simulation headers
00005 #include "SimDataFormats/Track/interface/SimTrack.h"
00006 
00007 // The muon scales
00008 
00009 //CMSSW headers 
00010 
00011 // STL headers 
00012 #include <iomanip>
00013 
00014 
00015 SimpleL1MuGMTCand::SimpleL1MuGMTCand() :
00016               m_name("FastL1MuCand"), m_empty(true), 
00017               m_phi(0), m_eta(31), m_pt(0), m_charge(0), m_quality(0),               
00018               m_rank(0), m_smearedPt(0) { }
00019 
00020 SimpleL1MuGMTCand::SimpleL1MuGMTCand(const SimpleL1MuGMTCand& mu) :
00021               m_name(mu.m_name), m_empty(mu.m_empty),
00022               m_phi(mu.m_phi), m_eta(mu.m_eta), m_pt(mu.m_pt), 
00023               m_charge(mu.m_charge), m_quality(mu.m_quality),
00024               m_rank(mu.m_rank), m_smearedPt(mu.m_smearedPt) {
00025   setMomentum(mu.getMomentum());
00026   setQuality(m_quality & 7);
00027   setEtaPacked(m_eta & 63);
00028   setPhiPacked(m_phi & 255);
00029   setCharge(m_charge);
00030   setPtPacked(m_pt & 31);
00031 }
00032 
00033 SimpleL1MuGMTCand::SimpleL1MuGMTCand(const SimpleL1MuGMTCand* mu) :
00034                m_name(mu->m_name), m_empty(mu->m_empty),
00035                m_phi(mu->m_phi), m_eta(mu->m_eta), m_pt(mu->m_pt), 
00036                m_charge(mu->m_charge), m_quality(mu->m_quality),
00037                m_rank(mu->m_rank), m_smearedPt(mu->m_smearedPt) {
00038   setMomentum(mu->getMomentum());
00039   setQuality(m_quality & 7);
00040   setEtaPacked(m_eta & 63);
00041   setPhiPacked(m_phi & 255);
00042   setCharge(m_charge);
00043   setPtPacked(m_pt & 31);
00044 }
00045 
00046 SimpleL1MuGMTCand::SimpleL1MuGMTCand(const SimTrack* p) { 
00047   //  setMomentum(p->momentum());
00048   LorentzVector toBeRemoved(p->momentum().x(),p->momentum().y(),p->momentum().z(),p->momentum().t());
00049   setMomentum(toBeRemoved);
00050   m_name = "FastL1MuCand";
00051   m_empty = false;
00052   m_quality = 7;
00053   setQuality(m_quality);
00054   m_rank = 0;
00055   setEta(myMomentum.Eta());
00056   setPhi(myMomentum.Phi());
00057   setCharge(int(p->charge()));
00058   setPt(myMomentum.Pt());
00059   setBx(0);
00060   if ( fabs(myMomentum.eta()) > 1.04 ) 
00061     setFwdBit(1);
00062   else
00063     setFwdBit(0);
00064   setRPCBit(0);
00065 
00066 }
00067 
00068 SimpleL1MuGMTCand::SimpleL1MuGMTCand(const SimTrack* p,
00069                                      unsigned etaIndex, 
00070                                      unsigned phiIndex,
00071                                      unsigned pTIndex,
00072                                      float etaValue,
00073                                      float phiValue,
00074                                      float pTValue) { 
00075   //  setMomentum(p->momentum());
00076   LorentzVector toBeRemoved(p->momentum().x(),p->momentum().y(),p->momentum().z(),p->momentum().t());
00077   setMomentum(toBeRemoved);
00078   m_name = "FastL1MuCand";
00079   m_empty = false;
00080   m_quality = 7;
00081   setQuality(m_quality);
00082   m_rank = 0;
00083   m_phi=phiIndex;
00084   setPhiPacked(phiIndex);
00085   setPhiValue(phiValue);
00086   m_eta=etaIndex;
00087   setEtaPacked(etaIndex);
00088   setEtaValue(etaValue);
00089   setCharge(int(p->charge()));
00090   m_pt = pTIndex;
00091   setPtPacked(pTIndex);
00092   setPtValue(pTValue);
00093   m_smearedPt = myMomentum.Pt();
00094   setBx(0);
00095   if ( fabs(etaValue) > 1.04 ) 
00096     setFwdBit(1);
00097   else
00098     setFwdBit(0);
00099   setRPCBit(0);
00100 
00101 }
00102 
00103 SimpleL1MuGMTCand::~SimpleL1MuGMTCand() {
00104 
00105   reset();
00106   
00107 }
00108 
00109 
00110 //
00111 void SimpleL1MuGMTCand::reset() {
00112 
00113   m_empty   = true;
00114   m_phi     = 0;
00115   m_eta     = 31;
00116   m_pt      = 0;
00117   m_charge  = 0;
00118   m_quality = 0;
00119   m_rank = 0;
00120   m_smearedPt = 0;
00121 
00122 }
00123 
00124 
00125 //
00126 // set phi-value of muon candidate
00127 //
00128 void SimpleL1MuGMTCand::setPhi(float phi) {
00129 
00130   int index = 0;
00131   float mindiff = 1000.0;
00132   
00133   if (phi < 0.) {phi = 2* M_PI + phi; }
00134   for ( int i = 0; i < 144; i++ ) {
00135     float diff = fabs(SimpleL1MuGMTCand::phiScale[i]-phi); 
00136     if ( diff <= mindiff ) {
00137       mindiff = diff; 
00138       index = i;
00139     }
00140   }
00141   
00142   m_phi = index;
00143   setPhiPacked(m_phi & 255 );
00144   setPhiValue(phiScale[m_phi]);
00145 
00146 }
00147 
00148 
00149 //
00150 // set eta-value of muon candidate
00151 //
00152 void SimpleL1MuGMTCand::setEta(float eta) {
00153 
00154   int index = 0;
00155   float mindiff = 1000.0;
00156   
00157   for ( int i = 0; i < 63; i++ ) {
00158     float diff = fabs(SimpleL1MuGMTCand::etaScale[i]-eta); 
00159     if ( diff <= mindiff ) {
00160       mindiff = diff; 
00161       index = i;
00162     }
00163   }
00164   
00165   m_eta = index;
00166   setEtaPacked(m_eta & 63 );
00167   setEtaValue(etaScale[m_eta]);
00168 
00169 }
00170 
00171 
00172 //
00173 // set pt (value!!) of muon candidate
00174 //
00175 void SimpleL1MuGMTCand::setPt(float pt) {
00176 
00177   int index = 0;
00178   m_smearedPt = pt;
00179   
00180   float mindiff = 1000.0;
00181   
00182   for ( int i = 0; i < 32; i++ ) {
00183     float diff = fabs(SimpleL1MuGMTCand::ptScale[i]-pt); 
00184     if ( diff <= mindiff ) {
00185       mindiff = diff; 
00186       index = i;
00187     }
00188   }
00189 
00190   m_pt = index;
00191   setPtPacked(m_pt & 31 );
00192   setPtValue(ptScale[m_pt]);
00193 
00194 }
00195 
00196 
00197 //
00198 // set charge and packed code of muon candidate
00199 //
00200 void SimpleL1MuGMTCand::setCharge(int charge) {
00201 
00202  m_charge = charge;
00203  setChargePacked(charge == 1 ? 0 : 1);
00204 
00205 }
00206     
00207 
00208 
00209 //
00210 // set generator particle of muon candidate
00211 //
00212 /*
00213 void SimpleL1MuGMTCand::setGenPart(const HepMC::GenParticle * rhp) {
00214 
00215    myGenParticle = rhp;
00216 }
00217 */
00218 
00219 
00220 //
00221 // Assignment operator
00222 //
00223 SimpleL1MuGMTCand& SimpleL1MuGMTCand::operator=(const SimpleL1MuGMTCand& cand) {
00224 
00225   if ( this != &cand ) {
00226    
00227     m_empty     = cand.m_empty;     
00228     m_phi = cand.m_phi;
00229     m_eta = cand.m_eta;
00230     m_pt = cand.m_pt;
00231     m_charge = cand.m_charge;
00232     m_quality   = cand.m_quality;    
00233     m_rank      = cand.m_rank;
00234     m_smearedPt = cand.m_smearedPt;
00235    
00236   }
00237   return *this;
00238 
00239 }
00240 
00241 
00242 //
00243 // Assignment operator for SimTrack's
00244 //
00245 SimpleL1MuGMTCand* SimpleL1MuGMTCand::operator=(const SimTrack* p) {
00246 
00247   m_empty = false;
00248   setEta(p->momentum().eta());
00249   setPhi(p->momentum().phi());
00250   setCharge(int(p->charge()));
00251   setPt(std::sqrt(p->momentum().perp2()));
00252   
00253   return this;
00254 }
00255 
00256 //
00257 // Equal operator
00258 //
00259 bool SimpleL1MuGMTCand::operator==(const SimpleL1MuGMTCand& cand) const {
00260 
00261   if ( m_empty     != cand.m_empty )     return false;
00262   if ( m_phi       != cand.m_phi )       return false;
00263   if ( m_eta       != cand.m_eta )       return false;
00264   if ( m_pt        != cand.m_pt )        return false;
00265   if ( m_charge    != cand.m_charge )    return false;
00266   if ( m_quality   != cand.m_quality )   return false;
00267   if ( m_rank      != cand.m_rank )      return false;
00268   return true;
00269 
00270 }
00271 
00272 
00273 //
00274 // Unequal operator
00275 //
00276 bool SimpleL1MuGMTCand::operator!=(const SimpleL1MuGMTCand& cand) const {
00277 
00278   if ( m_empty     != cand.m_empty )     return true;
00279   if ( m_phi       != cand.m_phi )       return true;
00280   if ( m_eta       != cand.m_eta )       return true;
00281   if ( m_pt        != cand.m_pt )        return true;
00282   if ( m_charge    != cand.m_charge )    return true;
00283   if ( m_quality   != cand.m_quality )   return true;
00284   if ( m_rank      != cand.m_rank )      return true;
00285   return false;
00286 
00287 }
00288 
00289 
00290 //
00291 // print parameters of track candidate
00292 //
00293 void SimpleL1MuGMTCand::print() const {
00294 
00295   using namespace std;
00296 
00297   if ( !empty() ) {
00298     cout.setf(ios::showpoint);
00299     cout.setf(ios::right,ios::adjustfield);
00300     cout << setiosflags(ios::showpoint | ios::fixed)
00301          << "pt = "  << setw(5) << setprecision(1) << ptValue() << " GeV  "
00302          << "charge = " << setw(2) << charge() << " "
00303          << "eta = " << setw(5) << setprecision(2) << etaValue() << "  "
00304          << "phi = " << setw(5) << setprecision(3) << phiValue() << " rad  "
00305          << "rank = " << setw(6) << rank() << endl;
00306   }
00307 
00308 }
00309 
00310 
00311 //
00312 // output stream operator for track candidate
00313 //
00314 std::ostream& operator<<(std::ostream& s, const SimpleL1MuGMTCand& id) {
00315 
00316   using namespace std;
00317 
00318   if ( !id.empty() ) {
00319     s << setiosflags(ios::showpoint | ios::fixed) 
00320       << "pt = "  << setw(5) << setprecision(1) << id.ptValue() << " GeV  "
00321       << "charge = " << setw(2) << id.charge() << " " 
00322       << "eta = " << setw(5) << setprecision(2) << id.etaValue() << "  " 
00323       << "phi = " << setw(5) << setprecision(3) << id.phiValue() << " rad  ";
00324       
00325   }
00326   return s;
00327 
00328 }
00329 
00330 //static
00331 
00332 
00333 // pt scale in GeV
00334 // low edges of pt bins
00335 const float SimpleL1MuGMTCand::ptScale[32] = { 
00336             0.0,   0.0,   1.5,   2.0,   2.5,   3.0,   3.5,   4.0,
00337             4.5,   5.0,   6.0,   7.0,   8.0,  10.0,  12.0,  14.0,  
00338            16.0,  18.0,  20.0,  25.0,  30.0,  35.0,  40.0,  45.0, 
00339            50.0,  60.0,  70.0,  80.0,  90.0, 100.0, 120.0, 140.0 };
00340 
00341 // eta scale           
00342 const float SimpleL1MuGMTCand::etaScale[63] = {
00343            -2.40, -2.35, -2.30, -2.25, -2.20, -2.15, -2.10, -2.05,
00344            -2.00, -1.95, -1.90, -1.85, -1.80, -1.75, -1.70, -1.60,
00345            -1.50, -1.40, -1.30, -1.20, -1.10, -1.00, -0.90, -0.80, 
00346            -0.70, -0.60, -0.50, -0.40, -0.30, -0.20, -0.10,  0.00,
00347             0.10,  0.20,  0.30,  0.40,  0.50,  0.60,  0.70,  0.80, 
00348             0.90,  1.00,  1.10,  1.20,  1.30,  1.40,  1.50,  1.60,
00349             1.70,  1.75,  1.80,  1.85,  1.90,  1.95,  2.00,  2.05,
00350             2.10,  2.15,  2.20,  2.25,  2.30,  2.35,  2.40 };
00351 
00352 // phi scale
00353 const float SimpleL1MuGMTCand::phiScale[144] = {
00354   0.0000,   0.0436,   0.0873,   0.1309,   0.1745,   0.2182, 
00355   0.2618,   0.3054,   0.3491,   0.3927,   0.4363,   0.4800, 
00356   0.5236,   0.5672,   0.6109,   0.6545,   0.6981,   0.7418, 
00357   0.7854,   0.8290,   0.8727,   0.9163,   0.9599,   1.0036, 
00358   1.0472,   1.0908,   1.1345,   1.1781,   1.2217,   1.2654, 
00359   1.3090,   1.3526,   1.3963,   1.4399,   1.4835,   1.5272, 
00360   1.5708,   1.6144,   1.6581,   1.7017,   1.7453,   1.7890, 
00361   1.8326,   1.8762,   1.9199,   1.9635,   2.0071,   2.0508, 
00362   2.0944,   2.1380,   2.1817,   2.2253,   2.2689,   2.3126, 
00363   2.3562,   2.3998,   2.4435,   2.4871,   2.5307,   2.5744, 
00364   2.6180,   2.6616,   2.7053,   2.7489,   2.7925,   2.8362, 
00365   2.8798,   2.9234,   2.9671,   3.0107,   3.0543,   3.0980, 
00366   3.1416,   3.1852,   3.2289,   3.2725,   3.3161,   3.3598, 
00367   3.4034,   3.4470,   3.4907,   3.5343,   3.5779,   3.6216, 
00368   3.6652,   3.7088,   3.7525,   3.7961,   3.8397,   3.8834, 
00369   3.9270,   3.9706,   4.0143,   4.0579,   4.1015,   4.1452, 
00370   4.1888,   4.2324,   4.2761,   4.3197,   4.3633,   4.4070, 
00371   4.4506,   4.4942,   4.5379,   4.5815,   4.6251,   4.6688, 
00372   4.7124,   4.7560,   4.7997,   4.8433,   4.8869,   4.9306, 
00373   4.9742,   5.0178,   5.0615,   5.1051,   5.1487,   5.1924, 
00374   5.2360,   5.2796,   5.3233,   5.3669,   5.4105,   5.4542, 
00375   5.4978,   5.5414,   5.5851,   5.6287,   5.6723,   5.7160, 
00376   5.7596,   5.8032,   5.8469,   5.8905,   5.9341,   5.9778, 
00377   6.0214,   6.0650,   6.1087,   6.1523,   6.1959,   6.2396 };