Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "L1Trigger/TrackFindingTracklet/interface/FullMatchMemory.h"
0002 #include "L1Trigger/TrackFindingTracklet/interface/Tracklet.h"
0003 #include "L1Trigger/TrackFindingTracklet/interface/Stub.h"
0004 #include "L1Trigger/TrackFindingTracklet/interface/L1TStub.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 #include <iomanip>
0007 #include <filesystem>
0008 
0009 using namespace std;
0010 using namespace trklet;
0011 
0012 FullMatchMemory::FullMatchMemory(string name, Settings const& settings) : MemoryBase(name, settings) {
0013   size_t pos = find_nth(name, 0, "_", 1);
0014   assert(pos != string::npos);
0015   initLayerDisk(pos + 1, layer_, disk_);
0016 }
0017 
0018 void FullMatchMemory::addMatch(Tracklet* tracklet, const Stub* stub) {
0019   if (!settings_.doKF() || !settings_.doMultipleMatches()) {  //When using KF we allow multiple matches
0020     for (auto& match : matches_) {
0021       if (match.first == tracklet) {  //Better match, replace
0022         match.second = stub;
0023         return;
0024       }
0025     }
0026   }
0027   std::pair<Tracklet*, const Stub*> tmp(tracklet, stub);
0028   //Check that we have the right TCID order
0029   if (!matches_.empty()) {
0030     if ((!settings_.doKF() && matches_[matches_.size() - 1].first->TCID() >= tracklet->TCID()) ||
0031         (settings_.doKF() && matches_[matches_.size() - 1].first->TCID() > tracklet->TCID())) {
0032       edm::LogPrint("Tracklet") << "Wrong TCID ordering in " << getName() << " : "
0033                                 << matches_[matches_.size() - 1].first->TCID() << " " << tracklet->TCID() << " "
0034                                 << matches_[matches_.size() - 1].first->trackletIndex() << " "
0035                                 << tracklet->trackletIndex();
0036     }
0037   }
0038   matches_.push_back(tmp);
0039 }
0040 
0041 void FullMatchMemory::writeMC(bool first, unsigned int iSector) {
0042   iSector_ = iSector;
0043   const string dirM = settings_.memPath() + "Matches/";
0044 
0045   std::ostringstream oss;
0046   oss << dirM << "FullMatches_" << getName() << "_" << std::setfill('0') << std::setw(2) << (iSector_ + 1) << ".dat";
0047   auto const& fname = oss.str();
0048 
0049   openfile(out_, first, dirM, fname, __FILE__, __LINE__);
0050 
0051   out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl;
0052 
0053   for (unsigned int j = 0; j < matches_.size(); j++) {
0054     string match = (layer_ > 0) ? matches_[j].first->fullmatchstr(layer_) : matches_[j].first->fullmatchdiskstr(disk_);
0055     out_ << "0x";
0056     out_ << std::setfill('0') << std::setw(2);
0057     out_ << hex << j << dec;
0058     out_ << " " << match << " " << trklet::hexFormat(match) << endl;
0059   }
0060   out_.close();
0061 
0062   bx_++;
0063   event_++;
0064   if (bx_ > 7)
0065     bx_ = 0;
0066 }