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.zside(), hid.layer(), hid.waferU(), hid.waferV())) ? "HGCSim"
130  : "HGCalSim");
131  const auto& info = hgc.waferInfo(hid.layer(), hid.waferU(), hid.waferV());
132  if (!valid)
133  st1 << " Wafer Type:Part:Orient:Cassette " << info.type << ":" << info.part << ":" << info.orient << ":"
134  << info.cassette;
135  bool toCheck(false);
136  if (!wafers_.empty()) {
137  int indx = HGCalWaferIndex::waferIndex(firstLayer + hid.layer(), hid.waferU(), hid.waferV(), false);
138  if (std::find(wafers_.begin(), wafers_.end(), indx) != wafers_.end())
139  toCheck = true;
140  } else if (!dumpDets_.empty()) {
141  if ((std::find(dumpDets_.begin(), dumpDets_.end(), static_cast<int>(id.det())) != dumpDets_.end()) &&
142  (info.part != HGCalTypes::WaferFull))
143  toCheck = true;
144  } else {
145  // Only partial wafers
146  toCheck = (info.part != HGCalTypes::WaferFull);
147  }
148  if (toCheck) {
149  ++good;
150  GlobalPoint pos = geom->getPosition(id);
151  bool valid1 = geom->topology().valid(id);
152  bool valid2 = hgc.isValidHex8(hid.layer(), hid.waferU(), hid.waferV(), hid.cellU(), hid.cellV(), false);
153  auto xy = hgc.locateCell(hid, false);
154  double xx = (hid.zside() > 0) ? xy.first : -xy.first;
155  double dx = xx - pos.x();
156  double dy = xy.second - pos.y();
157  double diff = std::sqrt(dx * dx + dy * dy);
158  if ((diff > tol) || (!valid1) || (!valid2))
159  pid = "HGCalError";
160  edm::LogVerbatim(pid) << "Hit[" << all << ":" << allSi << ":" << good << "]" << hid
161  << " Wafer Type:Part:Orient:Cassette " << info.type << ":" << info.part << ":"
162  << info.orient << ":" << info.cassette << " at (" << pos.x() << ":" << xx << ":"
163  << dx << ", " << pos.y() << ":" << xy.second << ":" << dy << ", " << pos.z()
164  << ") Valid " << valid1 << ":" << valid2 << " Distance " << diff;
165  }
166  }
167  } else if (id.det() == DetId::HGCalHSc) {
168  ++allSc;
169  HGCScintillatorDetId hid(id);
170  st1 << hid;
171  if ((id.det() == DetId::HGCalHSc) && (nameSense_ == "HGCalHEScintillatorSensitive")) {
172  std::string_view pid =
173  ((hgc.cassetteShiftScintillator(hid.zside(), hid.layer(), hid.iphi())) ? "HGCSim" : "HGCalSim");
174  GlobalPoint pos = geom->getPosition(id);
175  bool valid1 = geom->topology().valid(id);
176  bool valid2 = hgc.isValidTrap(hid.zside(), hid.layer(), hid.ring(), hid.iphi());
177  if ((!valid1) || (!valid2))
178  pid = "HGCalError";
179  int cassette = hgc.cassetteTile(hid.iphi());
180  edm::LogVerbatim(pid) << "Hit[" << all << ":" << allSc << "] " << hid << " Cassette " << cassette << " at ("
181  << pos.x() << ", " << pos.y() << ", " << pos.z() << ") Valid " << valid1 << ":"
182  << valid2;
183  }
184  } else {
185  st1 << std::hex << id.rawId() << std::dec;
186  }
187  if (!valid) {
188  edm::LogVerbatim("HGCalError") << "Invalid ID " << st1.str();
189  ++bad;
190  }
191  }
192  }
193  }
194  edm::LogVerbatim("HGCalSim") << "Total hits = " << all << ":" << nhits << " Good Silicon DetIds = " << allSi << ":"
195  << good << " Scintitllator = " << allSc << " Invalid = " << bad;
196 }
197 
198 //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
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:23
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_