CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
LateralityCoarsedProvider Class Reference

#include <LateralityCoarsedProvider.h>

Inheritance diagram for LateralityCoarsedProvider:
LateralityProvider

Public Member Functions

void finish () override
 
void initialise (const edm::EventSetup &iEventSetup) override
 
 LateralityCoarsedProvider (const edm::ParameterSet &pset, edm::ConsumesCollector &iC)
 
void run (edm::Event &iEvent, const edm::EventSetup &iEventSetup, MuonPathPtrs &inMpath, std::vector< lat_vector > &lateralities) override
 
 ~LateralityCoarsedProvider () override
 
- Public Member Functions inherited from LateralityProvider
 LateralityProvider (const edm::ParameterSet &pset, edm::ConsumesCollector &iC)
 
virtual ~LateralityProvider ()
 

Private Member Functions

void analyze (MuonPathPtr &inMPath, std::vector< lat_vector > &lateralities)
 
std::vector< short > coarsify_times (MuonPathPtr &inMPath)
 
std::vector< std::vector< short > > convertString (std::string chain)
 
void fill_lat_combinations ()
 

Private Attributes

const bool debug_
 
std::vector< lat_coarsed_combinationlat_combinations
 
edm::FileInPath laterality_filename_
 

Additional Inherited Members

- Public Attributes inherited from LateralityProvider
lat_vector LAT_VECTOR_NULL = {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}
 

Detailed Description

Definition at line 21 of file LateralityCoarsedProvider.h.

Constructor & Destructor Documentation

◆ LateralityCoarsedProvider()

LateralityCoarsedProvider::LateralityCoarsedProvider ( const edm::ParameterSet pset,
edm::ConsumesCollector iC 
)

Definition at line 11 of file LateralityCoarsedProvider.cc.

References debug_, fill_lat_combinations(), and LogDebug.

12  : LateralityProvider(pset, iC),
13  debug_(pset.getUntrackedParameter<bool>("debug")),
14  laterality_filename_(pset.getParameter<edm::FileInPath>("laterality_filename")) {
15  if (debug_)
16  LogDebug("LateralityCoarsedProvider") << "LateralityCoarsedProvider: constructor";
17 
19 }
LateralityProvider(const edm::ParameterSet &pset, edm::ConsumesCollector &iC)
#define LogDebug(id)

◆ ~LateralityCoarsedProvider()

LateralityCoarsedProvider::~LateralityCoarsedProvider ( )
override

Definition at line 21 of file LateralityCoarsedProvider.cc.

References debug_, and LogDebug.

21  {
22  if (debug_)
23  LogDebug("LateralityCoarsedProvider") << "LateralityCoarsedProvider: destructor";
24 }
#define LogDebug(id)

Member Function Documentation

◆ analyze()

void LateralityCoarsedProvider::analyze ( MuonPathPtr inMPath,
std::vector< lat_vector > &  lateralities 
)
private

Definition at line 56 of file LateralityCoarsedProvider.cc.

References lat_combination::cellLayout, coarsify_times(), debug_, lat_combinations, LateralityProvider::LAT_VECTOR_NULL, lat_combination::latcombs, LogDebug, and lat_combination::missing_layer.

Referenced by run().

56  {
57  if (debug_)
58  LogDebug("LateralityCoarsedProvider") << "DTp2:analyze \t\t\t\t starts";
59 
60  auto coarsified_times = coarsify_times(inMPath);
61 
62  for (auto &lat_combination : lat_combinations) {
63  if (inMPath->missingLayer() == lat_combination.missing_layer &&
64  inMPath->cellLayout()[0] == lat_combination.cellLayout[0] &&
65  inMPath->cellLayout()[1] == lat_combination.cellLayout[1] &&
66  inMPath->cellLayout()[2] == lat_combination.cellLayout[2] &&
67  inMPath->cellLayout()[3] == lat_combination.cellLayout[3] &&
68  coarsified_times[0] == lat_combination.coarsed_times[0] &&
69  coarsified_times[1] == lat_combination.coarsed_times[1] &&
70  coarsified_times[2] == lat_combination.coarsed_times[2] &&
71  coarsified_times[3] == lat_combination.coarsed_times[3]) {
72  lateralities.push_back(lat_combination.latcombs);
73  return;
74  }
75  }
76  lateralities.push_back(LAT_VECTOR_NULL);
77  return;
78 }
std::vector< lat_coarsed_combination > lat_combinations
std::vector< short > coarsify_times(MuonPathPtr &inMPath)
#define LogDebug(id)
short cellLayout[cmsdt::NUM_LAYERS]

◆ coarsify_times()

std::vector< short > LateralityCoarsedProvider::coarsify_times ( MuonPathPtr inMPath)
private

Definition at line 80 of file LateralityCoarsedProvider.cc.

References createfilelist::int, cmsdt::LAT_MSB_BITS, cmsdt::LAT_P0_3H, cmsdt::LAT_P0_4H, cmsdt::LAT_P1_3H, cmsdt::LAT_P1_4H, cmsdt::LAT_P2_3H, cmsdt::LAT_P2_4H, cmsdt::LAT_TOTAL_BITS, nano_mu_digi_cff::layer, cmsdt::LHC_CLK_FREQ, cmsdt::NUM_LAYERS, and cmsdt::TIME_TO_TDC_COUNTS.

Referenced by analyze().

80  {
81  int max_time = -999;
82  // obtain the maximum time to do the coarsification
83  for (int layer = 0; layer < cmsdt::NUM_LAYERS; layer++) {
84  if (inMPath->missingLayer() == layer)
85  continue;
86  if (inMPath->primitive(layer)->tdcTimeStamp() > max_time)
87  max_time = inMPath->primitive(layer)->tdcTimeStamp();
88  }
89 
90  // do the coarsification
91  std::vector<short> coarsified_times;
92  for (int layer = 0; layer < cmsdt::NUM_LAYERS; layer++) {
93  if (inMPath->missingLayer() == layer) {
94  coarsified_times.push_back(-1);
95  continue;
96  }
97  auto coarsified_time = max_time - inMPath->primitive(layer)->tdcTimeStamp();
98  // transform into tdc counts
99  coarsified_time = (int)round(((float)TIME_TO_TDC_COUNTS / (float)LHC_CLK_FREQ) * coarsified_time);
100  // keep the LAT_MSB_BITS
101  coarsified_time = coarsified_time >> (LAT_TOTAL_BITS - LAT_MSB_BITS);
102 
103  if (inMPath->missingLayer() == -1) { // 4-hit candidates
104  if (coarsified_time <= LAT_P0_4H)
105  coarsified_times.push_back(0);
106  else if (coarsified_time <= LAT_P1_4H)
107  coarsified_times.push_back(1);
108  else if (coarsified_time <= LAT_P2_4H)
109  coarsified_times.push_back(2);
110  else
111  coarsified_times.push_back(3);
112  } else { // 3-hit candidates
113  if (coarsified_time <= LAT_P0_3H)
114  coarsified_times.push_back(0);
115  else if (coarsified_time <= LAT_P1_3H)
116  coarsified_times.push_back(1);
117  else if (coarsified_time <= LAT_P2_3H)
118  coarsified_times.push_back(2);
119  else
120  coarsified_times.push_back(3);
121  }
122  }
123  return coarsified_times;
124 }
constexpr int LAT_P0_3H
Definition: constants.h:241
constexpr int LAT_P1_4H
Definition: constants.h:238
constexpr int LAT_P1_3H
Definition: constants.h:242
constexpr int LAT_P2_3H
Definition: constants.h:243
constexpr int LAT_P0_4H
Definition: constants.h:237
constexpr int LAT_P2_4H
Definition: constants.h:239
constexpr int TIME_TO_TDC_COUNTS
Definition: constants.h:235
constexpr int LHC_CLK_FREQ
Definition: constants.h:222
constexpr int LAT_TOTAL_BITS
Definition: constants.h:233
constexpr int NUM_LAYERS
Definition: constants.h:358
constexpr int LAT_MSB_BITS
Definition: constants.h:234

◆ convertString()

std::vector< std::vector< short > > LateralityCoarsedProvider::convertString ( std::string  chain)
private

Definition at line 247 of file LateralityCoarsedProvider.cc.

References watchdog::group, mps_fire::i, dqmiolumiharvest::j, and mps_fire::result.

Referenced by fill_lat_combinations().

247  {
248  std::vector<std::vector<short>> result;
249 
250  for (size_t i = 0; i < chain.size(); i += 4) {
251  std::vector<short> group;
252  for (size_t j = 0; j < 4; j++) {
253  group.push_back(chain[i + j] - '0'); // Convert the character to integer
254  }
255  result.push_back(group);
256  }
257 
258  return result;
259 }

◆ fill_lat_combinations()

void LateralityCoarsedProvider::fill_lat_combinations ( )
private

Definition at line 126 of file LateralityCoarsedProvider.cc.

References DMR_cfg::cerr, convertString(), Exception, edm::FileInPath::fullPath(), lat_combinations, laterality_filename_, makeLayoutFileForGui::layout, mps_splice::line, NUM_LAYERS, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by LateralityCoarsedProvider().

126  {
127  std::ifstream latFile(laterality_filename_.fullPath()); // Open file
128  if (latFile.fail()) {
129  throw cms::Exception("Missing Input File")
130  << "LateralityCoarsedProvider::fill_lat_combinations() - Cannot find " << laterality_filename_.fullPath();
131  return;
132  }
133 
135 
136  short line_counter = 0; // Line counter
137 
138  // Bit masks for every parameter
139  int _12bitMask = 0xFFF; // 12 bits
140  int _layoutMask = 0xE00; // 3 bits
141  int _is4HitMask = 0x100; // 1 bit
142  int _coarsedMask = 0xFF; // 8 bits
143  int _layerMask = 0xC0; // 2 bits
144 
145  while (std::getline(latFile, line)) {
146  if (line == "000000000000") {
147  line_counter++;
148  continue;
149  } //skip zeros
150 
151  if (line.size() == 12) {
152  std::vector<std::vector<short>> transformedVector = convertString(line);
153  latcomb lat0 = {
154  transformedVector[0][0], transformedVector[0][1], transformedVector[0][2], transformedVector[0][3]};
155  latcomb lat1 = {
156  transformedVector[1][0], transformedVector[1][1], transformedVector[1][2], transformedVector[1][3]};
157  latcomb lat2 = {
158  transformedVector[2][0], transformedVector[2][1], transformedVector[2][2], transformedVector[2][3]};
159 
160  //Transforming line number to binary
161  short address = line_counter & _12bitMask; // 12 bits
162 
163  short layout =
164  (address & _layoutMask) >> 9; //Doing AND and displacing 9 bits to the right to obtain 3 bits of layout
165  short is4Hit = (address & _is4HitMask) >> 8;
166  short coarsed = address & _coarsedMask;
167 
168  short bit1Layout = (layout & (1));
169  short bit2Layout = (layout & (1 << 1)) >> 1;
170  short bit3Layout = (layout & (1 << 2)) >> 2;
171 
172  //Logic implementation
173  short missingLayer = -1;
174  short layout_comb[NUM_LAYERS] = {bit3Layout, bit2Layout, bit1Layout, -1};
175  short coarsedTimes[NUM_LAYERS] = {0, 0, 0, 0};
176 
177  if (is4Hit != 1) { //3 hit case
178  missingLayer =
179  (coarsed & _layerMask) >> 6; //Missing layer is given by the two most significative bits of coarsed vector
180  coarsedTimes[missingLayer] = -1; //Missing layer set to -1
181  }
182 
183  // Filling coarsedTimes vector without the missing layer
184  if (missingLayer != -1) {
185  switch (missingLayer) {
186  case 0:
187  coarsedTimes[1] = (coarsed & 0x30) >> 4;
188  coarsedTimes[2] = (coarsed & 0x0C) >> 2;
189  coarsedTimes[3] = coarsed & 0x03;
190  lat0 = {-1, transformedVector[0][1], transformedVector[0][2], transformedVector[0][3]};
191  lat1 = {-1, transformedVector[1][1], transformedVector[1][2], transformedVector[1][3]};
192  lat2 = {-1, transformedVector[2][1], transformedVector[2][2], transformedVector[2][3]};
193  break;
194  case 1:
195  coarsedTimes[0] = (coarsed & 0x30) >> 4;
196  coarsedTimes[2] = (coarsed & 0x0C) >> 2;
197  coarsedTimes[3] = coarsed & 0x03;
198  lat0 = {transformedVector[0][0], -1, transformedVector[0][2], transformedVector[0][3]};
199  lat1 = {transformedVector[1][0], -1, transformedVector[1][2], transformedVector[1][3]};
200  lat2 = {transformedVector[2][0], -1, transformedVector[2][2], transformedVector[2][3]};
201  break;
202  case 2:
203  coarsedTimes[0] = (coarsed & 0x30) >> 4;
204  coarsedTimes[1] = (coarsed & 0x0C) >> 2;
205  coarsedTimes[3] = coarsed & 0x03;
206  lat0 = {transformedVector[0][0], transformedVector[0][1], -1, transformedVector[0][3]};
207  lat1 = {transformedVector[1][0], transformedVector[1][1], -1, transformedVector[1][3]};
208  lat2 = {transformedVector[2][0], transformedVector[2][1], -1, transformedVector[2][3]};
209  break;
210  case 3:
211  coarsedTimes[0] = (coarsed & 0x30) >> 4;
212  coarsedTimes[1] = (coarsed & 0x0C) >> 2;
213  coarsedTimes[2] = coarsed & 0x03;
214  lat0 = {transformedVector[0][0], transformedVector[0][1], transformedVector[0][2], -1};
215  lat1 = {transformedVector[1][0], transformedVector[1][1], transformedVector[1][2], -1};
216  lat2 = {transformedVector[2][0], transformedVector[2][1], transformedVector[2][2], -1};
217  break;
218 
219  default:
220  break;
221  }
222 
223  } else { //4 hit case
224  coarsedTimes[0] = (coarsed & 0xC0) >> 6;
225  coarsedTimes[1] = (coarsed & 0x30) >> 4;
226  coarsedTimes[2] = (coarsed & 0x0C) >> 2;
227  coarsedTimes[3] = coarsed & 0x03;
228  }
229 
230  lat_coarsed_combination lat_temp = {missingLayer,
231  {layout_comb[0], layout_comb[1], layout_comb[2], layout_comb[3]},
232  {coarsedTimes[0], coarsedTimes[1], coarsedTimes[2], coarsedTimes[3]},
233  {lat0, lat1, lat2}};
234  lat_combinations.push_back(lat_temp);
235 
236  } else { //size different from 12
237  std::cerr << "Error: line " << line_counter << " does not contain 12 bits." << std::endl;
238  }
239  line_counter++;
240  };
241 
242  //closing lateralities file
243  latFile.close();
244 };
std::string fullPath() const
Definition: FileInPath.cc:161
std::vector< short > latcomb
std::vector< lat_coarsed_combination > lat_combinations
std::vector< std::vector< short > > convertString(std::string chain)

◆ finish()

void LateralityCoarsedProvider::finish ( )
overridevirtual

Reimplemented from LateralityProvider.

Definition at line 47 of file LateralityCoarsedProvider.cc.

References debug_, and LogDebug.

Referenced by progressbar.ProgressBar::__next__().

47  {
48  if (debug_)
49  LogDebug("LateralityCoarsedProvider") << "LateralityCoarsedProvider: finish";
50 };
#define LogDebug(id)

◆ initialise()

void LateralityCoarsedProvider::initialise ( const edm::EventSetup iEventSetup)
overridevirtual

Reimplemented from LateralityProvider.

Definition at line 29 of file LateralityCoarsedProvider.cc.

References debug_, and LogDebug.

29  {
30  if (debug_)
31  LogDebug("LateralityCoarsedProvider") << "LateralityCoarsedProvider::initialiase";
32 }
#define LogDebug(id)

◆ run()

void LateralityCoarsedProvider::run ( edm::Event iEvent,
const edm::EventSetup iEventSetup,
MuonPathPtrs inMpath,
std::vector< lat_vector > &  lateralities 
)
overridevirtual

Implements LateralityProvider.

Definition at line 34 of file LateralityCoarsedProvider.cc.

References analyze(), debug_, and LogDebug.

37  {
38  if (debug_)
39  LogDebug("LateralityCoarsedProvider") << "LateralityCoarsedProvider: run";
40 
41  // fit per SL (need to allow for multiple outputs for a single mpath)
42  for (auto &muonpath : muonpaths) {
43  analyze(muonpath, lateralities);
44  }
45 }
void analyze(MuonPathPtr &inMPath, std::vector< lat_vector > &lateralities)
#define LogDebug(id)

Member Data Documentation

◆ debug_

const bool LateralityCoarsedProvider::debug_
private

◆ lat_combinations

std::vector<lat_coarsed_combination> LateralityCoarsedProvider::lat_combinations
private

Definition at line 46 of file LateralityCoarsedProvider.h.

Referenced by analyze(), and fill_lat_combinations().

◆ laterality_filename_

edm::FileInPath LateralityCoarsedProvider::laterality_filename_
private

Definition at line 47 of file LateralityCoarsedProvider.h.

Referenced by fill_lat_combinations().