Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-07 22:33:33

0001 #include "L1Trigger/TrackFindingTracklet/interface/ProjectionRouter.h"
0002 #include "L1Trigger/TrackFindingTracklet/interface/Settings.h"
0003 #include "L1Trigger/TrackFindingTracklet/interface/Globals.h"
0004 #include "L1Trigger/TrackFindingTracklet/interface/Tracklet.h"
0005 #include "L1Trigger/TrackFindingTracklet/interface/FPGAWord.h"
0006 #include "L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculator.h"
0007 
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 #include "FWCore/Utilities/interface/Exception.h"
0010 
0011 using namespace std;
0012 using namespace trklet;
0013 
0014 ProjectionRouter::ProjectionRouter(string name, Settings const& settings, Globals* global)
0015     : ProcessBase(name, settings, global), rinvbendlut_(settings) {
0016   layerdisk_ = initLayerDisk(3);
0017 
0018   vmprojs_.resize(settings_.nvmme(layerdisk_), nullptr);
0019 
0020   nrbits_ = 5;
0021   nphiderbits_ = 6;
0022 
0023   if (layerdisk_ >= N_LAYER) {
0024     rinvbendlut_.initProjectionBend(
0025         global->ITC_L1L2()->der_phiD_final.K(), layerdisk_ - N_LAYER, nrbits_, nphiderbits_);
0026   }
0027 }
0028 
0029 void ProjectionRouter::addOutput(MemoryBase* memory, string output) {
0030   if (settings_.writetrace()) {
0031     edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output "
0032                                  << output;
0033   }
0034   if (output == "allprojout") {
0035     auto* tmp = dynamic_cast<AllProjectionsMemory*>(memory);
0036     assert(tmp != nullptr);
0037     allproj_ = tmp;
0038     return;
0039   }
0040 
0041   unsigned int nproj = settings_.nallstubs(layerdisk_);
0042   unsigned int nprojvm = settings_.nvmme(layerdisk_);
0043 
0044   for (unsigned int iproj = 0; iproj < nproj; iproj++) {
0045     for (unsigned int iprojvm = 0; iprojvm < nprojvm; iprojvm++) {
0046       std::string name = "vmprojoutPHI";
0047       name += char(iproj + 'A');
0048       name += std::to_string(iproj * nprojvm + iprojvm + 1);
0049       if (output == name) {
0050         auto* tmp = dynamic_cast<VMProjectionsMemory*>(memory);
0051         assert(tmp != nullptr);
0052         vmprojs_[iprojvm] = tmp;
0053         return;
0054       }
0055     }
0056   }
0057 
0058   throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " could not find output: " << output;
0059 }
0060 
0061 void ProjectionRouter::addInput(MemoryBase* memory, string input) {
0062   if (settings_.writetrace()) {
0063     edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input "
0064                                  << input;
0065   }
0066   if (input.substr(0, 4) == "proj" && input.substr(input.size() - 2, 2) == "in") {
0067     auto* tmp = dynamic_cast<TrackletProjectionsMemory*>(memory);
0068     assert(tmp != nullptr);
0069     inputproj_.push_back(tmp);
0070     return;
0071   }
0072   throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " could not find input: " << input;
0073 }
0074 
0075 void ProjectionRouter::execute() {
0076   unsigned int allprojcount = 0;
0077 
0078   //These are just here to test that the order is correct. Does not affect the actual execution
0079 
0080   int lastTCID = -1;
0081 
0082   for (auto& iproj : inputproj_) {
0083     for (unsigned int i = 0; i < iproj->nTracklets(); i++) {
0084       if (allprojcount >= settings_.maxStep("PR"))
0085         continue;
0086 
0087       Tracklet* tracklet = iproj->getTracklet(i);
0088 
0089       FPGAWord fpgaphi;
0090 
0091       if (layerdisk_ < N_LAYER) {
0092         fpgaphi = tracklet->proj(layerdisk_).fpgaphiproj();
0093       } else {
0094         Projection& proj = tracklet->proj(layerdisk_);
0095         fpgaphi = proj.fpgaphiproj();
0096 
0097         //The next lines looks up the predicted bend based on:
0098         // 1 - r projections
0099         // 2 - phi derivative
0100         // 3 - the sign - i.e. if track is forward or backward
0101 
0102         int rindex = (proj.fpgarzproj().value() >> (proj.fpgarzproj().nbits() - nrbits_)) & ((1 << nrbits_) - 1);
0103 
0104         int phiderindex = (proj.fpgaphiprojder().value() >> (proj.fpgaphiprojder().nbits() - nphiderbits_)) &
0105                           ((1 << nphiderbits_) - 1);
0106 
0107         int signindex = (proj.fpgarzprojder().value() < 0);
0108 
0109         int bendindex = (signindex << (nphiderbits_ + nrbits_)) + (rindex << (nphiderbits_)) + phiderindex;
0110 
0111         int ibendproj = rinvbendlut_.lookup(bendindex);
0112 
0113         proj.setBendIndex(ibendproj);
0114       }
0115 
0116       unsigned int iphivm =
0117           fpgaphi.bits(fpgaphi.nbits() - settings_.nbitsallstubs(layerdisk_) - settings_.nbitsvmme(layerdisk_),
0118                        settings_.nbitsvmme(layerdisk_));
0119 
0120       //This block of code just checks that the configuration is consistent
0121       if (lastTCID >= tracklet->TCID()) {
0122         edm::LogPrint("Tracklet") << "Wrong TCID ordering for projections in " << getName();
0123       } else {
0124         lastTCID = tracklet->TCID();
0125       }
0126 
0127       allproj_->addTracklet(tracklet);
0128 
0129       vmprojs_[iphivm]->addTracklet(tracklet, allprojcount);
0130 
0131       if (settings_.debugTracklet()) {
0132         edm::LogVerbatim("Tracklet") << getName() << " projection to " << vmprojs_[iphivm]->getName() << " iphivm "
0133                                      << iphivm;
0134       }
0135 
0136       allprojcount++;
0137     }
0138   }
0139 
0140   if (settings_.writeMonitorData("AP")) {
0141     globals_->ofstream("allprojections.txt") << getName() << " " << allproj_->nTracklets() << endl;
0142   }
0143 
0144   if (settings_.writeMonitorData("VMP")) {
0145     ofstream& out = globals_->ofstream("chisq.txt");
0146     for (unsigned int i = 0; i < 8; i++) {
0147       if (vmprojs_[i] != nullptr) {
0148         out << vmprojs_[i]->getName() << " " << vmprojs_[i]->nTracklets() << endl;
0149       }
0150     }
0151   }
0152 }