Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "L1Trigger/TrackFindingTracklet/interface/Stub.h"
0002 #include "L1Trigger/TrackFindingTracklet/interface/Globals.h"
0003 #include "L1Trigger/TrackFindingTracklet/interface/SLHCEvent.h"
0004 
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 #include "FWCore/Utilities/interface/Exception.h"
0007 #include "DataFormats/Math/interface/deltaPhi.h"
0008 
0009 #include <cmath>
0010 #include <bitset>
0011 
0012 using namespace std;
0013 using namespace trklet;
0014 
0015 Stub::Stub(Settings const& settings) : settings_(settings) {}
0016 
0017 Stub::Stub(L1TStub& stub, Settings const& settings, Globals& globals) : settings_(settings) {
0018   const string& stubwordhex = stub.stubword();
0019 
0020   const string stubwordbin = convertHexToBin(stubwordhex);
0021 
0022   layerdisk_ = stub.layerdisk();
0023 
0024   int nbendbits = stub.isPSmodule() ? N_BENDBITS_PS : N_BENDBITS_2S;
0025 
0026   int nalphabits = 0;
0027 
0028   int nrbits = settings_.nrbitsstub(layerdisk_);
0029   int nzbits = settings_.nzbitsstub(layerdisk_);
0030   int nphibits = settings_.nphibitsstub(layerdisk_);
0031 
0032   if (layerdisk_ >= N_LAYER && !stub.isPSmodule()) {
0033     nalphabits = settings.nbitsalpha();
0034     nrbits = 7;
0035   }
0036 
0037   assert(nbendbits + nalphabits + nrbits + nzbits + nphibits == 36);
0038 
0039   bitset<32> rbits(stubwordbin.substr(0, nrbits));
0040   bitset<32> zbits(stubwordbin.substr(nrbits, nzbits));
0041   bitset<32> phibits(stubwordbin.substr(nrbits + nzbits, nphibits));
0042   bitset<32> alphabits(stubwordbin.substr(nphibits + nzbits + nrbits, nalphabits));
0043   bitset<32> bendbits(stubwordbin.substr(nphibits + nzbits + nrbits + nalphabits, nbendbits));
0044 
0045   int newbend = bendbits.to_ulong();
0046 
0047   int newr = rbits.to_ulong();
0048   if (layerdisk_ < N_LAYER) {
0049     if (newr >= (1 << (nrbits - 1)))
0050       newr = newr - (1 << nrbits);
0051   }
0052 
0053   int newz = zbits.to_ulong();
0054   if (newz >= (1 << (nzbits - 1)))
0055     newz = newz - (1 << nzbits);
0056 
0057   int newphi = phibits.to_ulong();
0058 
0059   int newalpha = alphabits.to_ulong();
0060   if (newalpha >= (1 << (nalphabits - 1)))
0061     newalpha = newalpha - (1 << nalphabits);
0062 
0063   l1tstub_ = &stub;
0064 
0065   bend_.set(newbend, nbendbits, true, __LINE__, __FILE__);
0066 
0067   phi_.set(newphi, nphibits, true, __LINE__, __FILE__);
0068   phicorr_.set(newphi, nphibits, true, __LINE__, __FILE__);
0069   bool pos = false;
0070   if (layerdisk_ >= N_LAYER) {
0071     pos = true;
0072     int disk = layerdisk_ - N_LAYER + 1;
0073     if (stub.z() < 0.0)
0074       disk = -disk;
0075     disk_.set(disk, 4, false, __LINE__, __FILE__);
0076     if (!stub.isPSmodule()) {
0077       alpha_.set(newalpha, nalphabits, false, __LINE__, __FILE__);
0078       nrbits = 4;
0079     }
0080     int negdisk = (disk < 0) ? 1 : 0;
0081     negdisk_.set(negdisk, 1, true, __LINE__, __FILE__);
0082   } else {
0083     disk_.set(0, 4, false, __LINE__, __FILE__);
0084     layer_.set(layerdisk_, 3, true, __LINE__, __FILE__);
0085   }
0086   r_.set(newr, nrbits, pos, __LINE__, __FILE__);
0087   z_.set(newz, nzbits, false, __LINE__, __FILE__);
0088 
0089   if (settings.writeMonitorData("StubBend")) {
0090     unsigned int nsimtrks = globals.event()->nsimtracks();
0091 
0092     for (unsigned int isimtrk = 0; isimtrk < nsimtrks; isimtrk++) {
0093       const L1SimTrack& simtrk = globals.event()->simtrack(isimtrk);
0094       if (stub.tpmatch2(simtrk.trackid())) {
0095         double dr = 0.18;
0096         double rinv = simtrk.charge() * 0.01 * settings_.c() * settings_.bfield() / simtrk.pt();
0097         double pitch = settings_.stripPitch(stub.isPSmodule());
0098         double bend = stub.r() * dr * 0.5 * rinv / pitch;
0099 
0100         globals.ofstream("stubbend.dat") << layerdisk_ << " " << stub.isPSmodule() << " "
0101                                          << simtrk.pt() * simtrk.charge() << " " << bend << " " << newbend << " "
0102                                          << settings.benddecode(newbend, layerdisk_, stub.isPSmodule()) << " "
0103                                          << settings.bendcut(newbend, layerdisk_, stub.isPSmodule()) << endl;
0104       }
0105     }
0106   }
0107 }
0108 
0109 FPGAWord Stub::iphivmFineBins(int VMbits, int finebits) const {
0110   unsigned int finephi = (phicorr_.value() >> (phicorr_.nbits() - VMbits - finebits)) & ((1 << finebits) - 1);
0111   return FPGAWord(finephi, finebits, true, __LINE__, __FILE__);
0112 }
0113 
0114 unsigned int Stub::phiregionaddress() const {
0115   int iphi = (phicorr_.value() >> (phicorr_.nbits() - settings_.nbitsallstubs(layerdisk())));
0116   return (iphi << 7) + stubindex_.value();
0117 }
0118 
0119 std::string Stub::phiregionaddressstr() const {
0120   int iphi = (phicorr_.value() >> (phicorr_.nbits() - settings_.nbitsallstubs(layerdisk())));
0121   FPGAWord phiregion(iphi, 3, true, __LINE__, __FILE__);
0122   return phiregion.str() + stubindex_.str();
0123 }
0124 
0125 std::string Stub::phiregionstr() const {
0126   int iphi = (phicorr_.value() >> (phicorr_.nbits() - settings_.nbitsallstubs(layerdisk())));
0127   FPGAWord phiregion(iphi, 3, true, __LINE__, __FILE__);
0128   return phiregion.str();
0129 }
0130 
0131 void Stub::setAllStubIndex(int nstub) {
0132   if (nstub >= (1 << N_BITSMEMADDRESS)) {
0133     if (settings_.debugTracklet())
0134       edm::LogPrint("Tracklet") << "Warning too large stubindex!";
0135     nstub = (1 << N_BITSMEMADDRESS) - 1;
0136   }
0137 
0138   stubindex_.set(nstub, N_BITSMEMADDRESS);
0139 }
0140 
0141 void Stub::setPhiCorr(int phiCorr) {
0142   int iphicorr = phi_.value() - phiCorr;
0143 
0144   if (iphicorr < 0)
0145     iphicorr = 0;
0146   if (iphicorr >= (1 << phi_.nbits()))
0147     iphicorr = (1 << phi_.nbits()) - 1;
0148 
0149   phicorr_.set(iphicorr, phi_.nbits(), true, __LINE__, __FILE__);
0150 }
0151 
0152 double Stub::rapprox() const {
0153   if (disk_.value() == 0) {
0154     int lr = 1 << (8 - settings_.nrbitsstub(layer_.value()));
0155     return r_.value() * settings_.kr() * lr + settings_.rmean(layer_.value());
0156   }
0157   if (!l1tstub_->isPSmodule()) {
0158     if (abs(disk_.value()) <= 2)
0159       return settings_.rDSSinner(r_.value());
0160     else
0161       return settings_.rDSSouter(r_.value());
0162   }
0163   return r_.value() * settings_.kr();
0164 }
0165 
0166 double Stub::zapprox() const {
0167   if (disk_.value() == 0) {
0168     int lz = 1;
0169     if (layer_.value() >= 3) {
0170       lz = 16;
0171     }
0172     return z_.value() * settings_.kz() * lz;
0173   }
0174   int sign = 1;
0175   if (disk_.value() < 0)
0176     sign = -1;
0177   if (sign < 0) {
0178     //Should understand why this is needed to get agreement with integer calculations
0179     return (z_.value() + 1) * settings_.kz() + sign * settings_.zmean(abs(disk_.value()) - 1);
0180   } else {
0181     return z_.value() * settings_.kz() + sign * settings_.zmean(abs(disk_.value()) - 1);
0182   }
0183 }
0184 
0185 double Stub::phiapprox(double phimin, double) const {
0186   int lphi = 1;
0187   if (layer_.value() >= 3) {
0188     lphi = 8;
0189   }
0190   return reco::reduceRange(phimin + phi_.value() * settings_.kphi() / lphi);
0191 }
0192 
0193 unsigned int Stub::layerdisk() const {
0194   if (layer_.value() == -1)
0195     return N_LAYER - 1 + abs(disk_.value());
0196   return layer_.value();
0197 }