CMS 3D CMS Logo

HGCalMouseBiteTester.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: HGCalMouseBiteTester
4 // Class: HGCalMouseBiteTester
5 //
14 //
15 // Original Author: Sunanda Banerjee, Pruthvi Suryadevara
16 // Created: Mon 2023/11/30
17 //
18 //
19 
20 // system include files
21 #include <cmath>
22 #include <cstdlib>
23 #include <fstream>
24 #include <iostream>
25 #include <memory>
26 #include <string>
27 #include <vector>
28 //#include <chrono>
29 
30 // user include files
33 
34 #include <CLHEP/Vector/ThreeVector.h>
51 #include "G4ThreeVector.hh"
52 
54 public:
55  explicit HGCalMouseBiteTester(const edm::ParameterSet&);
56  ~HGCalMouseBiteTester() override = default;
57  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
58 
59  void beginJob() override {}
60  void analyze(edm::Event const& iEvent, edm::EventSetup const&) override;
61  void endJob() override {}
62 
63 private:
65  const int waferU_;
66  const int waferV_;
67  const int nTrials_;
68  const int layer_;
70  std::ofstream outputFile;
71 };
72 
74  : nameSense_(iC.getParameter<std::string>("nameSense")),
75  waferU_(iC.getParameter<int>("waferU")),
76  waferV_(iC.getParameter<int>("waferV")),
77  nTrials_(iC.getParameter<int>("numbberOfTrials")),
78  layer_(iC.getParameter<int>("layer")),
80  edm::LogVerbatim("HGCalGeom") << "Test Guard_Ring for wafer in layer" << layer_ << " U " << waferU_ << " V "
81  << waferV_ << " with " << nTrials_ << " trials";
82 
83  outputFile.open("full1.csv");
84  if (!outputFile.is_open()) {
85  edm::LogError("HGCalGeom") << "Could not open output file.";
86  } else {
87  outputFile << "x,y,u,v,\n";
88  }
89 }
90 
93  desc.add<std::string>("nameSense", "HGCalEESensitive");
94  desc.add<int>("waferU", 1);
95  desc.add<int>("waferV", 9);
96  desc.add<int>("numbberOfTrials", 1000000);
97  desc.add<int>("layer", 1);
98  descriptions.add("hgcalMouseBiteTester", desc);
99 }
100 
101 // ------------ method called to produce the data ------------
103  const HGCalDDDConstants& hgcons_ = iSetup.getData(dddToken_);
104  double waferSize_(hgcons_.waferSize(false));
105  int zside(1);
106  int layertype = hgcons_.layerType(layer_);
107  int frontBack = HGCalTypes::layerFrontBack(layertype);
108  const std::vector<double> angle_{90.0, 30.0};
110  int partialType_ = HGCalWaferType::getPartial(index, hgcons_.getParameter()->waferInfoMap_);
112  int placeIndex_ = HGCalCell::cellPlacementIndex(zside, frontBack, orient);
113  int waferType_ = HGCalWaferType::getType(index, hgcons_.getParameter()->waferInfoMap_);
114  double mouseBiteCut_ = waferSize_ * tan(30.0 * CLHEP::deg) - 5.0;
115  bool v17OrLess = hgcons_.v17OrLess();
116  HGCGuardRing guardRing_(hgcons_);
117  HGCGuardRingPartial guardRingPartial_(hgcons_);
118  HGCMouseBite mouseBite_(hgcons_, angle_, mouseBiteCut_, true);
119  const int nFine(12), nCoarse(8);
120  double r2 = 0.5 * waferSize_;
121  double R2 = 2 * r2 / sqrt(3);
122  int nCells = (waferType_ == 0) ? nFine : nCoarse;
123  std::cout << "start" << std::endl;
124  HGCalCellUV wafer(waferSize_, 0.0, nFine, nCoarse);
125  HGCalCell wafer2(waferSize_, nFine, nCoarse);
126  std::pair<double, double> xy = hgcons_.waferPosition(layer_, waferU_, waferV_, false, false);
127  double x0 = (zside > 0) ? xy.first : -xy.first;
128  double y0 = xy.second;
129  std::ofstream guard_ring("Guard_ring.csv");
130  std::ofstream guard_ring_partial("Guard_ring_partial.csv");
131  std::ofstream mouse_bite("Mouse_bite.csv");
132  std::ofstream selected("Selected.csv");
133  edm::LogVerbatim("HGCalGeom") << "\nHGCalMouseBiteTester:: nCells " << nCells << " FrontBack " << frontBack
134  << " Wafer Size " << waferSize_ << " and placement index " << placeIndex_
135  << " WaferType " << waferType_ << " Partial " << partialType_ << " WaferX " << x0
136  << " WaferY " << y0 << "\n\n";
138  std::cout << "v17 ? " << hgcons_.v17OrLess() << std::endl;
139  for (int i = 0; i < nTrials_; i++) {
140  double xi = (2 * r2 * static_cast<double>(rand()) / RAND_MAX) - r2;
141  double yi = (2 * R2 * static_cast<double>(rand()) / RAND_MAX) - R2;
142  bool goodPoint = true;
143  int ug = 0;
144  int vg = 0;
145  if (partialType_ == 11 || partialType_ == 13 || partialType_ == 15 || partialType_ == 21 || partialType_ == 23 ||
146  partialType_ == 25 || partialType_ == 0) {
147  ug = 0;
148  vg = 0;
149  } else if (partialType_ == 12 || partialType_ == 14 || partialType_ == 16 || partialType_ == 22 ||
150  partialType_ == 24) {
151  ug = nCells + 1;
152  vg = 2 * (nCells - 1);
153  }
154  std::pair<double, double> xyg = wafer2.cellUV2XY2(ug, vg, placeIndex_, waferType_);
155  std::vector<std::pair<double, double> > wxy =
156  HGCalWaferMask::waferXY(0, placeIndex_, waferSize_, 0.0, 0.0, 0.0, v17OrLess);
157  for (unsigned int i = 0; i < (wxy.size() - 1); ++i) {
158  double xp1 = wxy[i].first;
159  double yp1 = wxy[i].second;
160  double xp2 = wxy[i + 1].first;
161  double yp2 = wxy[i + 1].second;
162  if ((((xi - xp1) / (xp2 - xp1)) - ((yi - yp1) / (yp2 - yp1))) *
163  (((xyg.first - xp1) / (xp2 - xp1)) - ((xyg.second - yp1) / (yp2 - yp1))) <=
164  0) {
165  goodPoint = false;
166  }
167  }
168  if (goodPoint) { //Only allowing (x, y) inside a partial wafer 11, placement index 2
169  G4ThreeVector point(xi, yi, 0.0);
170  std::pair<int32_t, int32_t> uv5;
171  if (hgcons_.v17OrLess()) {
172  uv5 = wafer.cellUVFromXY1(xi, yi, placeIndex_, waferType_, partialType_, true, false);
173  } else {
174  uv5 = wafer.cellUVFromXY2(xi, yi, placeIndex_, waferType_, partialType_, true, false);
175  }
176  if (guardRing_.exclude(point, zside, frontBack, layer_, waferU_, waferV_)) {
177  guard_ring << xi << "," << yi << std::endl;
178  }
179 
180  if (guardRingPartial_.exclude(point, zside, frontBack, layer_, waferU_, waferV_)) {
181  guard_ring_partial << xi << "," << yi << std::endl;
182  } else if (mouseBite_.exclude(point, zside, layer_, waferU_, waferV_)) {
183  mouse_bite << xi << "," << yi << std::endl;
184  } else {
185  selected << xi << "," << yi << std::endl;
186  outputFile << xi << "," << yi << "," << uv5.first << "," << uv5.second << "," << std::endl;
187  }
188  }
189  }
190  guard_ring.close();
191  guard_ring_partial.close();
192  mouse_bite.close();
193  selected.close();
194  outputFile.close();
196  auto diff_t = end_t - start_t;
197  edm::LogVerbatim("HGCalGeom") << "Execution time for " << nTrials_
198  << " events = " << std::chrono::duration<double, std::milli>(diff_t).count() << " ms";
199 }
200 
201 // define this as a plug-in
Log< level::Info, true > LogVerbatim
const std::string nameSense_
static int32_t cellPlacementIndex(int32_t iz, int32_t frontBack, int32_t orient)
Definition: HGCalCell.cc:239
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
static const char layer_[]
static int getType(int index, const HGCalParameters::waferInfo_map &wafers)
bool exclude(G4ThreeVector &point, int zside, int layer, int waferU, int waferV)
Definition: HGCMouseBite.cc:34
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
const HGCalParameters * getParameter() const
const edm::ESGetToken< HGCalDDDConstants, IdealGeometryRecord > dddToken_
std::pair< int32_t, int32_t > cellUVFromXY1(double xloc, double yloc, int32_t placement, int32_t type, bool extend, bool debug) const
Definition: HGCalCellUV.cc:46
static int getPartial(int index, const HGCalParameters::waferInfo_map &wafers)
int zside(DetId const &)
Log< level::Error, false > LogError
static std::vector< std::pair< double, double > > waferXY(const int &part, const int &orient, const int &zside, const double &waferSize, const double &offset, const double &xpos, const double &ypos, const bool &v17)
bool v17OrLess() const
static int getOrient(int index, const HGCalParameters::waferInfo_map &wafers)
void analyze(edm::Event const &iEvent, edm::EventSetup const &) override
int iEvent
Definition: GenABIO.cc:224
HGCalMouseBiteTester(const edm::ParameterSet &)
T sqrt(T t)
Definition: SSEVec.h:23
bool exclude(G4ThreeVector &point, int zside, int frontBack, int layer, int waferU, int waferV)
Definition: HGCGuardRing.cc:26
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
int32_t waferIndex(int32_t layer, int32_t waferU, int32_t waferV, bool old=false)
~HGCalMouseBiteTester() override=default
std::pair< double, double > waferPosition(int wafer, bool reco) const
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::pair< double, double > cellUV2XY2(int32_t u, int32_t v, int32_t placementIndex, int32_t type)
Definition: HGCalCell.cc:79
HLT enums.
ALPAKA_FN_ACC ALPAKA_FN_INLINE void uint32_t const uint32_t CACellT< TrackerTraits > uint32_t * nCells
waferInfo_map waferInfoMap_
bool exclude(G4ThreeVector &point, int zside, int frontBack, int layer, int waferU, int waferV)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5
double waferSize(bool reco) const
int layerType(int lay) const
std::pair< int32_t, int32_t > cellUVFromXY2(double xloc, double yloc, int32_t placement, int32_t type, bool extend, bool debug) const
Definition: HGCalCellUV.cc:89
static constexpr int32_t layerFrontBack(int32_t layerOrient)
Definition: HGCalTypes.h:137