Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:55:49

0001 // ===========================================================================
0002 //
0003 //       Filename:  TopologicalAlgorithm.h
0004 //
0005 //    Description:  A base class for all the topological algorithms
0006 //
0007 //        Version:  1.0
0008 //        Created:  03/03/2021 10:14:23 AM
0009 //       Revision:  none
0010 //       Compiler:  g++
0011 //
0012 //         Author:  Zhenbin Wu, zhenbin.wu@gmail.com
0013 //
0014 // ===========================================================================
0015 
0016 #ifndef PHASE2GMT_TOPOLOGICALALGORITHM
0017 #define PHASE2GMT_TOPOLOGICALALGORITHM
0018 
0019 #include "DataFormats/L1TMuonPhase2/interface/TrackerMuon.h"
0020 #include "ConvertedTTTrack.h"
0021 #include "DataFormats/L1TMuonPhase2/interface/Constants.h"
0022 
0023 #include <fstream>
0024 #include <memory>
0025 
0026 namespace Phase2L1GMT {
0027 
0028   class TopoAlgo {
0029   public:
0030     TopoAlgo();
0031     ~TopoAlgo();
0032     TopoAlgo(const TopoAlgo &cpy);
0033     void load(std::vector<l1t::TrackerMuon> &trkMus, std::vector<ConvertedTTTrack> &convertedTracks);
0034     void DumpInputs();
0035 
0036     int deltaEta(const int eta1, const int eta2);
0037     int deltaZ0(const int Z01, const int Z02);
0038     int deltaPhi(int phi1, int phi2);
0039 
0040   protected:
0041     std::vector<l1t::TrackerMuon> *trkMus;
0042     std::vector<ConvertedTTTrack> *convertedTracks;
0043     std::ofstream dumpInput;
0044   };
0045 
0046   inline TopoAlgo::TopoAlgo() {}
0047 
0048   inline TopoAlgo::~TopoAlgo() {}
0049 
0050   inline TopoAlgo::TopoAlgo(const TopoAlgo &cpy) {}
0051 
0052   // ===  FUNCTION  ============================================================
0053   //         Name:  TopoAlgo::load
0054   //  Description:
0055   // ===========================================================================
0056   inline void TopoAlgo::load(std::vector<l1t::TrackerMuon> &trkMus_, std::vector<ConvertedTTTrack> &convertedTracks_) {
0057     trkMus = &trkMus_;
0058     convertedTracks = &convertedTracks_;
0059   }  // -----  end of function TopoAlgo::load  -----
0060 
0061   inline void TopoAlgo::DumpInputs() {
0062     static std::atomic<int> nevti = 0;
0063     auto evti = nevti++;
0064     int totalsize = 0;
0065     // Current setting
0066     int constexpr exptotal = 12 + 18 * 100;  // N_Muon + N_TRK_LINKS * NTRKperlinks
0067     for (unsigned int i = 0; i < 12; ++i) {
0068       if (i < trkMus->size())
0069         dumpInput << " " << evti << " 0 " << i << " " << trkMus->at(i).hwPt() * LSBpt << " "
0070                   << trkMus->at(i).hwEta() * LSBeta << " " << trkMus->at(i).hwPhi() * LSBphi << " "
0071                   << trkMus->at(i).hwZ0() * LSBGTz0 << " " << trkMus->at(i).charge() << std::endl;
0072       else
0073         dumpInput << " " << evti << " 0 " << i << " " << 0 << " " << 0 << " " << 0 << " " << 0 << " " << 0 << std::endl;
0074       totalsize++;
0075     }
0076     for (unsigned int i = 0; i < convertedTracks->size(); ++i) {
0077       dumpInput << " " << evti << " 1 " << i << " " << convertedTracks->at(i).pt() * LSBpt << " "
0078                 << convertedTracks->at(i).eta() * LSBeta << " " << convertedTracks->at(i).phi() * LSBphi << " "
0079                 << convertedTracks->at(i).z0() * LSBGTz0 << " " << convertedTracks->at(i).charge() << " "
0080                 << convertedTracks->at(i).quality() << std::endl;
0081       totalsize++;
0082     }
0083     int ntrks = convertedTracks->size();
0084     // Pat the remaining
0085     while (totalsize < exptotal) {
0086       dumpInput << " " << evti << " 1 " << ntrks++ << " " << 0 << " " << 0 << " " << 0 << " " << 0 << " " << 0 << " "
0087                 << 0 << std::endl;
0088       totalsize++;
0089     }
0090   }
0091 
0092   inline int TopoAlgo::deltaEta(const int eta1, const int eta2) {
0093     static const int maxbits = (1 << BITSETA) - 1;
0094     int deta = abs(eta1 - eta2);
0095     deta &= maxbits;
0096     return deta;
0097   }
0098 
0099   inline int TopoAlgo::deltaZ0(const int Z01, const int Z02) {
0100     static const int maxbits = (1 << BITSZ0) - 1;
0101     int dZ0 = abs(Z01 - Z02);
0102     dZ0 &= maxbits;
0103     return dZ0;
0104   }
0105 
0106   // Ideal the object should carry its own ap types once we finalize
0107   inline int TopoAlgo::deltaPhi(int phi1, int phi2) {
0108     static const int maxbits = (1 << BITSPHI) - 1;
0109     static const int pibits = (1 << (BITSPHI - 1));
0110     int dphi = abs(phi1 - phi2);
0111     if (dphi >= pibits)
0112       dphi = maxbits - dphi;
0113     return dphi;
0114   }
0115 }  // namespace Phase2L1GMT
0116 
0117 #endif  // ----- #ifndef PHASE2GMT_TOPOLOGICALALGORITHM -----