Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-04-01 23:54:07

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 "L1Trigger/Phase2L1GMT/interface/ConvertedTTTrack.h"
0021 #include "L1Trigger/Phase2L1GMT/interface/Constants.h"
0022 
0023 #include <fstream>
0024 
0025 namespace Phase2L1GMT {
0026 
0027   class TopoAlgo {
0028   public:
0029     TopoAlgo();
0030     ~TopoAlgo();
0031     TopoAlgo(const TopoAlgo &cpy);
0032     void load(std::vector<l1t::TrackerMuon> &trkMus, std::vector<ConvertedTTTrack> &convertedTracks);
0033     void DumpInputs();
0034 
0035     int deltaEta(const int eta1, const int eta2);
0036     int deltaZ0(const int Z01, const int Z02);
0037     int deltaPhi(int phi1, int phi2);
0038 
0039   protected:
0040     std::vector<l1t::TrackerMuon> *trkMus;
0041     std::vector<ConvertedTTTrack> *convertedTracks;
0042     std::ofstream dumpInput;
0043   };
0044 
0045   inline TopoAlgo::TopoAlgo() {}
0046 
0047   inline TopoAlgo::~TopoAlgo() {}
0048 
0049   inline TopoAlgo::TopoAlgo(const TopoAlgo &cpy) {}
0050 
0051   // ===  FUNCTION  ============================================================
0052   //         Name:  TopoAlgo::load
0053   //  Description:
0054   // ===========================================================================
0055   inline void TopoAlgo::load(std::vector<l1t::TrackerMuon> &trkMus_, std::vector<ConvertedTTTrack> &convertedTracks_) {
0056     trkMus = &trkMus_;
0057     convertedTracks = &convertedTracks_;
0058   }  // -----  end of function TopoAlgo::load  -----
0059 
0060   inline void TopoAlgo::DumpInputs() {
0061     static int nevti = 0;
0062     int totalsize = 0;
0063     // Current setting
0064     int constexpr exptotal = 12 + 18 * 100;  // N_Muon + N_TRK_LINKS * NTRKperlinks
0065     for (unsigned int i = 0; i < 12; ++i) {
0066       if (i < trkMus->size())
0067         dumpInput << " " << nevti << " 0 " << i << " " << trkMus->at(i).hwPt() * LSBpt << " "
0068                   << trkMus->at(i).hwEta() * LSBeta << " " << trkMus->at(i).hwPhi() * LSBphi << " "
0069                   << trkMus->at(i).hwZ0() * LSBGTz0 << " " << trkMus->at(i).charge() << std::endl;
0070       else
0071         dumpInput << " " << nevti << " 0 " << i << " " << 0 << " " << 0 << " " << 0 << " " << 0 << " " << 0
0072                   << std::endl;
0073       totalsize++;
0074     }
0075     for (unsigned int i = 0; i < convertedTracks->size(); ++i) {
0076       dumpInput << " " << nevti << " 1 " << i << " " << convertedTracks->at(i).pt() * LSBpt << " "
0077                 << convertedTracks->at(i).eta() * LSBeta << " " << convertedTracks->at(i).phi() * LSBphi << " "
0078                 << convertedTracks->at(i).z0() * LSBGTz0 << " " << convertedTracks->at(i).charge() << " "
0079                 << convertedTracks->at(i).quality() << std::endl;
0080       totalsize++;
0081     }
0082     int ntrks = convertedTracks->size();
0083     // Pat the remaining
0084     while (totalsize < exptotal) {
0085       dumpInput << " " << nevti << " 1 " << ntrks++ << " " << 0 << " " << 0 << " " << 0 << " " << 0 << " " << 0 << " "
0086                 << 0 << std::endl;
0087       totalsize++;
0088     }
0089     nevti++;
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 -----