CMS 3D CMS Logo

TopologicalAlgorithm.h
Go to the documentation of this file.
1 // ===========================================================================
2 //
3 // Filename: TopologicalAlgorithm.h
4 //
5 // Description: A base class for all the topological algorithms
6 //
7 // Version: 1.0
8 // Created: 03/03/2021 10:14:23 AM
9 // Revision: none
10 // Compiler: g++
11 //
12 // Author: Zhenbin Wu, zhenbin.wu@gmail.com
13 //
14 // ===========================================================================
15 
16 #ifndef PHASE2GMT_TOPOLOGICALALGORITHM
17 #define PHASE2GMT_TOPOLOGICALALGORITHM
18 
22 
23 #include <fstream>
24 
25 namespace Phase2L1GMT {
26 
27  class TopoAlgo {
28  public:
29  TopoAlgo();
30  ~TopoAlgo();
31  TopoAlgo(const TopoAlgo &cpy);
32  void load(std::vector<l1t::TrackerMuon> &trkMus, std::vector<ConvertedTTTrack> &convertedTracks);
33  void DumpInputs();
34 
35  int deltaEta(const int eta1, const int eta2);
36  int deltaZ0(const int Z01, const int Z02);
37  int deltaPhi(int phi1, int phi2);
38 
39  protected:
40  std::vector<l1t::TrackerMuon> *trkMus;
41  std::vector<ConvertedTTTrack> *convertedTracks;
42  std::ofstream dumpInput;
43  };
44 
45  inline TopoAlgo::TopoAlgo() {}
46 
47  inline TopoAlgo::~TopoAlgo() {}
48 
49  inline TopoAlgo::TopoAlgo(const TopoAlgo &cpy) {}
50 
51  // === FUNCTION ============================================================
52  // Name: TopoAlgo::load
53  // Description:
54  // ===========================================================================
55  inline void TopoAlgo::load(std::vector<l1t::TrackerMuon> &trkMus_, std::vector<ConvertedTTTrack> &convertedTracks_) {
56  trkMus = &trkMus_;
57  convertedTracks = &convertedTracks_;
58  } // ----- end of function TopoAlgo::load -----
59 
60  inline void TopoAlgo::DumpInputs() {
61  static int nevti = 0;
62  int totalsize = 0;
63  // Current setting
64  int constexpr exptotal = 12 + 18 * 100; // N_Muon + N_TRK_LINKS * NTRKperlinks
65  for (unsigned int i = 0; i < 12; ++i) {
66  if (i < trkMus->size())
67  dumpInput << " " << nevti << " 0 " << i << " " << trkMus->at(i).hwPt() * LSBpt << " "
68  << trkMus->at(i).hwEta() * LSBeta << " " << trkMus->at(i).hwPhi() * LSBphi << " "
69  << trkMus->at(i).hwZ0() * LSBGTz0 << " " << trkMus->at(i).charge() << std::endl;
70  else
71  dumpInput << " " << nevti << " 0 " << i << " " << 0 << " " << 0 << " " << 0 << " " << 0 << " " << 0
72  << std::endl;
73  totalsize++;
74  }
75  for (unsigned int i = 0; i < convertedTracks->size(); ++i) {
76  dumpInput << " " << nevti << " 1 " << i << " " << convertedTracks->at(i).pt() * LSBpt << " "
77  << convertedTracks->at(i).eta() * LSBeta << " " << convertedTracks->at(i).phi() * LSBphi << " "
78  << convertedTracks->at(i).z0() * LSBGTz0 << " " << convertedTracks->at(i).charge() << " "
79  << convertedTracks->at(i).quality() << std::endl;
80  totalsize++;
81  }
82  int ntrks = convertedTracks->size();
83  // Pat the remaining
84  while (totalsize < exptotal) {
85  dumpInput << " " << nevti << " 1 " << ntrks++ << " " << 0 << " " << 0 << " " << 0 << " " << 0 << " " << 0 << " "
86  << 0 << std::endl;
87  totalsize++;
88  }
89  nevti++;
90  }
91 
92  inline int TopoAlgo::deltaEta(const int eta1, const int eta2) {
93  static const int maxbits = (1 << BITSETA) - 1;
94  int deta = abs(eta1 - eta2);
95  deta &= maxbits;
96  return deta;
97  }
98 
99  inline int TopoAlgo::deltaZ0(const int Z01, const int Z02) {
100  static const int maxbits = (1 << BITSZ0) - 1;
101  int dZ0 = abs(Z01 - Z02);
102  dZ0 &= maxbits;
103  return dZ0;
104  }
105 
106  // Ideal the object should carry its own ap types once we finalize
107  inline int TopoAlgo::deltaPhi(int phi1, int phi2) {
108  static const int maxbits = (1 << BITSPHI) - 1;
109  static const int pibits = (1 << (BITSPHI - 1));
110  int dphi = abs(phi1 - phi2);
111  if (dphi >= pibits)
112  dphi = maxbits - dphi;
113  return dphi;
114  }
115 } // namespace Phase2L1GMT
116 
117 #endif // ----- #ifndef PHASE2GMT_TOPOLOGICALALGORITHM -----
size
Write out results.
const float LSBphi
Definition: Constants.h:81
const int BITSZ0
Definition: Constants.h:27
const float LSBGTz0
Definition: Constants.h:83
const float LSBpt
Definition: Constants.h:80
const int BITSETA
Definition: Constants.h:26
int deltaEta(const int eta1, const int eta2)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const int BITSPHI
Definition: Constants.h:25
std::vector< ConvertedTTTrack > * convertedTracks
const float LSBeta
Definition: Constants.h:82
std::vector< l1t::TrackerMuon > * trkMus
int deltaZ0(const int Z01, const int Z02)
int deltaPhi(int phi1, int phi2)
void load(std::vector< l1t::TrackerMuon > &trkMus, std::vector< ConvertedTTTrack > &convertedTracks)