Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:21:58

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()) {
0020     // When allowing only one stub per track per layer (or no KF implying same).
0021     for (auto& match : matches_) {
0022       if (match.first == tracklet) {  //Better match: replace existing one
0023         match.second = stub;
0024         return;
0025       }
0026     }
0027   }
0028   std::pair<Tracklet*, const Stub*> tmp(tracklet, stub);
0029   //Check that we have the right TCID order
0030   if (!matches_.empty()) {
0031     if ((!settings_.doKF() && matches_[matches_.size() - 1].first->TCID() >= tracklet->TCID()) ||
0032         (settings_.doKF() && matches_[matches_.size() - 1].first->TCID() > tracklet->TCID())) {
0033       edm::LogPrint("Tracklet") << "Wrong TCID ordering in " << getName() << " : "
0034                                 << matches_[matches_.size() - 1].first->TCID() << " " << tracklet->TCID() << " "
0035                                 << matches_[matches_.size() - 1].first->trackletIndex() << " "
0036                                 << tracklet->trackletIndex();
0037     }
0038   }
0039   matches_.push_back(tmp);
0040 }
0041 
0042 void FullMatchMemory::writeMC(bool first, unsigned int iSector) {
0043   iSector_ = iSector;
0044   const string dirM = settings_.memPath() + "Matches/";
0045 
0046   std::ostringstream oss;
0047   oss << dirM << "FullMatches_" << getName() << "_" << std::setfill('0') << std::setw(2) << (iSector_ + 1) << ".dat";
0048   auto const& fname = oss.str();
0049 
0050   openfile(out_, first, dirM, fname, __FILE__, __LINE__);
0051 
0052   out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl;
0053 
0054   for (unsigned int j = 0; j < matches_.size(); j++) {
0055     string match = (layer_ > 0) ? matches_[j].first->fullmatchstr(layer_) : matches_[j].first->fullmatchdiskstr(disk_);
0056     out_ << hexstr(j) << " " << match << " " << trklet::hexFormat(match) << endl;
0057   }
0058   out_.close();
0059 
0060   bx_++;
0061   event_++;
0062   if (bx_ > 7)
0063     bx_ = 0;
0064 }