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 
20 #include "ConvertedTTTrack.h"
22 
23 #include <fstream>
24 #include <memory>
25 
26 namespace Phase2L1GMT {
27 
28  class TopoAlgo {
29  public:
30  TopoAlgo();
31  ~TopoAlgo();
32  TopoAlgo(const TopoAlgo &cpy);
33  void load(std::vector<l1t::TrackerMuon> &trkMus, std::vector<ConvertedTTTrack> &convertedTracks);
34  void DumpInputs();
35 
36  int deltaEta(const int eta1, const int eta2);
37  int deltaZ0(const int Z01, const int Z02);
38  int deltaPhi(int phi1, int phi2);
39 
40  protected:
41  std::vector<l1t::TrackerMuon> *trkMus;
42  std::vector<ConvertedTTTrack> *convertedTracks;
43  std::ofstream dumpInput;
44  };
45 
46  inline TopoAlgo::TopoAlgo() {}
47 
48  inline TopoAlgo::~TopoAlgo() {}
49 
50  inline TopoAlgo::TopoAlgo(const TopoAlgo &cpy) {}
51 
52  // === FUNCTION ============================================================
53  // Name: TopoAlgo::load
54  // Description:
55  // ===========================================================================
56  inline void TopoAlgo::load(std::vector<l1t::TrackerMuon> &trkMus_, std::vector<ConvertedTTTrack> &convertedTracks_) {
57  trkMus = &trkMus_;
58  convertedTracks = &convertedTracks_;
59  } // ----- end of function TopoAlgo::load -----
60 
61  inline void TopoAlgo::DumpInputs() {
62  static std::atomic<int> nevti = 0;
63  auto evti = nevti++;
64  int totalsize = 0;
65  // Current setting
66  int constexpr exptotal = 12 + 18 * 100; // N_Muon + N_TRK_LINKS * NTRKperlinks
67  for (unsigned int i = 0; i < 12; ++i) {
68  if (i < trkMus->size())
69  dumpInput << " " << evti << " 0 " << i << " " << trkMus->at(i).hwPt() * LSBpt << " "
70  << trkMus->at(i).hwEta() * LSBeta << " " << trkMus->at(i).hwPhi() * LSBphi << " "
71  << trkMus->at(i).hwZ0() * LSBGTz0 << " " << trkMus->at(i).charge() << std::endl;
72  else
73  dumpInput << " " << evti << " 0 " << i << " " << 0 << " " << 0 << " " << 0 << " " << 0 << " " << 0 << std::endl;
74  totalsize++;
75  }
76  for (unsigned int i = 0; i < convertedTracks->size(); ++i) {
77  dumpInput << " " << evti << " 1 " << i << " " << convertedTracks->at(i).pt() * LSBpt << " "
78  << convertedTracks->at(i).eta() * LSBeta << " " << convertedTracks->at(i).phi() * LSBphi << " "
79  << convertedTracks->at(i).z0() * LSBGTz0 << " " << convertedTracks->at(i).charge() << " "
80  << convertedTracks->at(i).quality() << std::endl;
81  totalsize++;
82  }
83  int ntrks = convertedTracks->size();
84  // Pat the remaining
85  while (totalsize < exptotal) {
86  dumpInput << " " << evti << " 1 " << ntrks++ << " " << 0 << " " << 0 << " " << 0 << " " << 0 << " " << 0 << " "
87  << 0 << std::endl;
88  totalsize++;
89  }
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:92
const int BITSZ0
Definition: Constants.h:27
const float LSBGTz0
Definition: Constants.h:94
const float LSBpt
Definition: Constants.h:91
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:93
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)