CMS 3D CMS Logo

HGCalTestPartialWaferHits.cc
Go to the documentation of this file.
3 
7 
14 
17 
21 
27 
28 #include <fstream>
29 #include <sstream>
30 #include <string>
31 #include <vector>
32 
34 public:
36  ~HGCalTestPartialWaferHits() override = default;
37  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
38 
39 protected:
40  void analyze(edm::Event const&, edm::EventSetup const&) override;
41  void beginJob() override {}
42  void endJob() override {}
43 
44 private:
48  std::vector<int> wafers_;
49  std::vector<int> dumpDets_;
50 };
51 
53  : g4Label_(ps.getParameter<std::string>("moduleLabel")),
54  caloHitSource_(ps.getParameter<std::string>("caloHitSource")),
55  nameSense_(ps.getParameter<std::string>("nameSense")),
56  missingFile_(ps.getParameter<std::string>("missingFile")),
57  tok_calo_(consumes<edm::PCaloHitContainer>(edm::InputTag(g4Label_, caloHitSource_))),
59  edm::LogVerbatim("HGCalSim") << "Test Hit ID using SimHits for " << nameSense_ << " with module Label: " << g4Label_
60  << " Hits: " << caloHitSource_ << " Missing Wafer file " << missingFile_;
61  if (!missingFile_.empty()) {
62  edm::FileInPath filetmp("SimG4CMS/Calo/data/" + missingFile_);
63  std::string fileName = filetmp.fullPath();
64  std::ifstream fInput(fileName.c_str());
65  if (!fInput.good()) {
66  edm::LogVerbatim("HGCalSim") << "Cannot open file " << fileName;
67  } else {
68  char buffer[80];
69  while (fInput.getline(buffer, 80)) {
70  std::vector<std::string> items = CaloSimUtils::splitString(std::string(buffer));
71  if (items.size() > 2) {
72  int layer = std::atoi(items[0].c_str());
73  int waferU = std::atoi(items[1].c_str());
74  int waferV = std::atoi(items[2].c_str());
75  wafers_.emplace_back(HGCalWaferIndex::waferIndex(layer, waferU, waferV, false));
76  } else if (items.size() == 1) {
77  int dumpdet = std::atoi(items[0].c_str());
78  dumpDets_.emplace_back(dumpdet);
79  edm::LogVerbatim("HGCalSim") << nameSense_ << " Dump detector " << dumpdet;
80  }
81  }
82  edm::LogVerbatim("HGCalSim") << "HGCalTestPartialWaferHits::Reads in " << wafers_.size() << ":"
83  << dumpDets_.size() << " wafer|detector information from " << fileName;
84  fInput.close();
85  }
86  }
87 }
88 
91  desc.add<std::string>("moduleLabel", "g4SimHits");
92  desc.add<std::string>("caloHitSource", "HGCHitsEE");
93  desc.add<std::string>("nameSense", "HGCalEESensitive");
94  desc.add<std::string>("missingFile", "");
95  descriptions.add("hgcalHitPartialEE", desc);
96 }
97 
99  // get HGCalGeometry
100  const HGCalGeometry* geom = &iS.getData(geomToken_);
101  const HGCalDDDConstants& hgc = geom->topology().dddConstants();
102  int firstLayer = hgc.getLayerOffset();
103  // get the hit collection
104  const edm::Handle<edm::PCaloHitContainer>& hitsCalo = e.getHandle(tok_calo_);
105  bool getHits = (hitsCalo.isValid());
106  uint32_t nhits = (getHits) ? hitsCalo->size() : 0;
107  uint32_t good(0), allSi(0), all(0), allSc(0), bad(0);
108  constexpr double tol = 2.0;
109  edm::LogVerbatim("HGCalSim") << "HGCalTestPartialWaferHits: Input flags Hits " << getHits << " with " << nhits
110  << " hits: Layer Offset " << firstLayer;
111 
112  if (getHits) {
113  std::vector<PCaloHit> hits;
114  hits.insert(hits.end(), hitsCalo->begin(), hitsCalo->end());
115  if (!hits.empty()) {
116  // Loop over all hits
117  for (auto hit : hits) {
118  ++all;
119  DetId id(hit.id());
120  bool valid = (geom->topology()).valid(id);
121  std::ostringstream st1;
122  if ((id.det() == DetId::HGCalEE) || (id.det() == DetId::HGCalHSi)) {
123  ++allSi;
124  HGCSiliconDetId hid(id);
125  st1 << hid;
126  if (((id.det() == DetId::HGCalEE) && (nameSense_ == "HGCalEESensitive")) ||
127  ((id.det() == DetId::HGCalHSi) && (nameSense_ == "HGCalHESiliconSensitive"))) {
128  std::string_view pid =
129  ((hgc.cassetteShiftSilicon(hid.layer(), hid.waferU(), hid.waferV())) ? "HGCSim" : "HGCalSim");
130  const auto& info = hgc.waferInfo(hid.layer(), hid.waferU(), hid.waferV());
131  if (!valid)
132  st1 << " Wafer Type:Part:Orient:Cassette " << info.type << ":" << info.part << ":" << info.orient << ":"
133  << info.cassette;
134  bool toCheck(false);
135  if (!wafers_.empty()) {
136  int indx = HGCalWaferIndex::waferIndex(firstLayer + hid.layer(), hid.waferU(), hid.waferV(), false);
137  if (std::find(wafers_.begin(), wafers_.end(), indx) != wafers_.end())
138  toCheck = true;
139  } else if (!dumpDets_.empty()) {
140  if ((std::find(dumpDets_.begin(), dumpDets_.end(), static_cast<int>(id.det())) != dumpDets_.end()) &&
141  (info.part != HGCalTypes::WaferFull))
142  toCheck = true;
143  } else {
144  // Only partial wafers
145  toCheck = (info.part != HGCalTypes::WaferFull);
146  }
147  if (toCheck) {
148  ++good;
149  GlobalPoint pos = geom->getPosition(id);
150  bool valid1 = geom->topology().valid(id);
151  bool valid2 = hgc.isValidHex8(hid.layer(), hid.waferU(), hid.waferV(), hid.cellU(), hid.cellV(), false);
152  auto xy = hgc.locateCell(hid, false);
153  double xx = (hid.zside() > 0) ? xy.first : -xy.first;
154  double dx = xx - pos.x();
155  double dy = xy.second - pos.y();
156  double diff = std::sqrt(dx * dx + dy * dy);
157  if ((diff > tol) || (!valid1) || (!valid2))
158  pid = "HGCalError";
159  edm::LogVerbatim(pid) << "Hit[" << all << ":" << allSi << ":" << good << "]" << hid
160  << " Wafer Type:Part:Orient:Cassette " << info.type << ":" << info.part << ":"
161  << info.orient << ":" << info.cassette << " at (" << pos.x() << ":" << xx << ":"
162  << dx << ", " << pos.y() << ":" << xy.second << ":" << dy << ", " << pos.z()
163  << ") Valid " << valid1 << ":" << valid2 << " Distance " << diff;
164  }
165  }
166  } else if (id.det() == DetId::HGCalHSc) {
167  ++allSc;
168  HGCScintillatorDetId hid(id);
169  st1 << hid;
170  if ((id.det() == DetId::HGCalHSc) && (nameSense_ == "HGCalHEScintillatorSensitive")) {
171  std::string_view pid = ((hgc.cassetteShiftScintillator(hid.layer(), hid.iphi())) ? "HGCSim" : "HGCalSim");
172  GlobalPoint pos = geom->getPosition(id);
173  bool valid1 = geom->topology().valid(id);
174  bool valid2 = hgc.isValidTrap(hid.zside(), hid.layer(), hid.ring(), hid.iphi());
175  if ((!valid1) || (!valid2))
176  pid = "HGCalError";
177  int cassette = hgc.cassetteTile(hid.iphi());
178  edm::LogVerbatim(pid) << "Hit[" << all << ":" << allSc << "] " << hid << " Cassette " << cassette << " at ("
179  << pos.x() << ", " << pos.y() << ", " << pos.z() << ") Valid " << valid1 << ":"
180  << valid2;
181  }
182  } else {
183  st1 << std::hex << id.rawId() << std::dec;
184  }
185  if (!valid) {
186  edm::LogVerbatim("HGCalError") << "Invalid ID " << st1.str();
187  ++bad;
188  }
189  }
190  }
191  }
192  edm::LogVerbatim("HGCalSim") << "Total hits = " << all << ":" << nhits << " Good Silicon DetIds = " << allSi << ":"
193  << good << " Scintitllator = " << allSc << " Invalid = " << bad;
194 }
195 
196 //define this as a plug-in
Log< level::Info, true > LogVerbatim
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
std::vector< PCaloHit > PCaloHitContainer
static const TGPicture * info(bool iBackgroundIsBlack)
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
def all(container)
workaround iterator generators for ROOT classes
Definition: cmstools.py:25
int32_t waferU(const int32_t index)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
void analyze(edm::Event const &, edm::EventSetup const &) override
constexpr std::array< uint8_t, layerIndexSize< TrackerTraits > > layer
static constexpr int32_t WaferFull
Definition: HGCalTypes.h:35
std::vector< std::string > splitString(const std::string &)
Definition: CaloSimUtils.cc:3
T sqrt(T t)
Definition: SSEVec.h:19
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
HGCalTestPartialWaferHits(const edm::ParameterSet &ps)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
int32_t waferIndex(int32_t layer, int32_t waferU, int32_t waferV, bool old=false)
unsigned int id
Definition: DetId.h:17
const edm::EDGetTokenT< edm::PCaloHitContainer > tok_calo_
~HGCalTestPartialWaferHits() override=default
void add(std::string const &label, ParameterSetDescription const &psetDescription)
bool isValid() const
Definition: HandleBase.h:70
HLT enums.
int32_t waferV(const int32_t index)
const edm::ESGetToken< HGCalGeometry, IdealGeometryRecord > geomToken_