CMS 3D CMS Logo

HGCalTestPartialWaferHits.cc
Go to the documentation of this file.
3 
7 
14 
16 
20 
26 
27 #include <fstream>
28 #include <string>
29 #include <vector>
30 
32 public:
34  ~HGCalTestPartialWaferHits() override = default;
35  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
36 
37 protected:
38  void analyze(edm::Event const&, edm::EventSetup const&) override;
39  void beginJob() override {}
40  void endJob() override {}
41 
42 private:
46  std::vector<int> wafers_;
47  std::vector<int> dumpDets_;
48 };
49 
51  : g4Label_(ps.getParameter<std::string>("moduleLabel")),
52  caloHitSource_(ps.getParameter<std::string>("caloHitSource")),
53  nameSense_(ps.getParameter<std::string>("nameSense")),
54  missingFile_(ps.getParameter<std::string>("missingFile")),
55  tok_calo_(consumes<edm::PCaloHitContainer>(edm::InputTag(g4Label_, caloHitSource_))),
57  edm::LogVerbatim("HGCalSim") << "Test Hit ID using SimHits for " << nameSense_ << " with module Label: " << g4Label_
58  << " Hits: " << caloHitSource_ << " Missing Wafer file " << missingFile_;
59  if (!missingFile_.empty()) {
60  edm::FileInPath filetmp("SimG4CMS/Calo/data/" + missingFile_);
61  std::string fileName = filetmp.fullPath();
62  std::ifstream fInput(fileName.c_str());
63  if (!fInput.good()) {
64  edm::LogVerbatim("HGCalSim") << "Cannot open file " << fileName;
65  } else {
66  char buffer[80];
67  while (fInput.getline(buffer, 80)) {
68  std::vector<std::string> items = CaloSimUtils::splitString(std::string(buffer));
69  if (items.size() > 2) {
70  int layer = std::atoi(items[0].c_str());
71  int waferU = std::atoi(items[1].c_str());
72  int waferV = std::atoi(items[2].c_str());
73  wafers_.emplace_back(HGCalWaferIndex::waferIndex(layer, waferU, waferV, false));
74  } else if (items.size() == 1) {
75  int dumpdet = std::atoi(items[0].c_str());
76  dumpDets_.emplace_back(dumpdet);
77  edm::LogVerbatim("HGCalSim") << nameSense_ << " Dump detector " << dumpdet;
78  }
79  }
80  edm::LogVerbatim("HGCalSim") << "HGCalTestPartialWaferHits::Reads in " << wafers_.size() << ":"
81  << dumpDets_.size() << " wafer|detector information from " << fileName;
82  fInput.close();
83  }
84  }
85 }
86 
89  desc.add<std::string>("moduleLabel", "g4SimHits");
90  desc.add<std::string>("caloHitSource", "HGCHitsEE");
91  desc.add<std::string>("nameSense", "HGCalEESensitive");
92  desc.add<std::string>("missingFile", "");
93  descriptions.add("hgcalHitPartialEE", desc);
94 }
95 
97  // get HGCalGeometry
98  const HGCalGeometry* geom = &iS.getData(geomToken_);
99  const HGCalDDDConstants& hgc = geom->topology().dddConstants();
100  int firstLayer = hgc.getLayerOffset();
101  // get the hit collection
102  const edm::Handle<edm::PCaloHitContainer>& hitsCalo = e.getHandle(tok_calo_);
103  bool getHits = (hitsCalo.isValid());
104  uint32_t nhits = (getHits) ? hitsCalo->size() : 0;
105  uint32_t good(0), allSi(0), all(0);
106  edm::LogVerbatim("HGCalSim") << "HGCalTestPartialWaferHits: Input flags Hits " << getHits << " with " << nhits
107  << " hits: Layer Offset " << firstLayer;
108 
109  if (getHits) {
110  std::vector<PCaloHit> hits;
111  hits.insert(hits.end(), hitsCalo->begin(), hitsCalo->end());
112  if (!hits.empty()) {
113  // Loop over all hits
114  for (auto hit : hits) {
115  ++all;
116  DetId id(hit.id());
117  if ((id.det() == DetId::HGCalEE) || (id.det() == DetId::HGCalHSi)) {
118  ++allSi;
119  HGCSiliconDetId hid(id);
120  const auto& info = hgc.waferInfo(hid.layer(), hid.waferU(), hid.waferV());
121  bool toCheck(false);
122  if (!wafers_.empty()) {
123  int indx = HGCalWaferIndex::waferIndex(firstLayer + hid.layer(), hid.waferU(), hid.waferV(), false);
124  if (std::find(wafers_.begin(), wafers_.end(), indx) != wafers_.end())
125  toCheck = true;
126  } else if (!dumpDets_.empty()) {
127  if ((std::find(dumpDets_.begin(), dumpDets_.end(), static_cast<int>(id.det())) != dumpDets_.end()) &&
128  (info.part != HGCalTypes::WaferFull))
129  toCheck = true;
130  } else {
131  // Only partial wafers
132  toCheck = (info.part != HGCalTypes::WaferFull);
133  }
134  if (toCheck) {
135  ++good;
136  GlobalPoint pos = geom->getPosition(id);
137  bool valid1 = geom->topology().valid(id);
138  bool valid2 = hgc.isValidHex8(hid.layer(), hid.waferU(), hid.waferV(), hid.cellU(), hid.cellV());
139  edm::LogVerbatim("HGCalSim") << "Hit[" << all << ":" << allSi << ":" << good << "]" << HGCSiliconDetId(id)
140  << " Wafer Type:Part:Orient:Cassette " << info.type << ":" << info.part << ":"
141  << info.orient << ":" << info.cassette << " at (" << pos.x() << ", " << pos.y()
142  << ", " << pos.z() << ") Validity " << valid1 << ":" << valid2;
143  }
144  }
145  }
146  }
147  }
148  edm::LogVerbatim("HGCalSim") << "Total hits = " << all << ":" << nhits << " Good DetIds = " << allSi << ":" << good;
149 }
150 
151 //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)
def all(container)
workaround iterator generators for ROOT classes
Definition: cmstools.py:25
int32_t waferU(const int32_t index)
int cellU() const
get the cell #&#39;s in u,v or in x,y
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
constexpr std::array< uint8_t, layerIndexSize > layer
void analyze(edm::Event const &, edm::EventSetup const &) override
int layer() const
get the layer #
static constexpr int32_t WaferFull
Definition: HGCalTypes.h:35
std::vector< std::string > splitString(const std::string &)
Definition: CaloSimUtils.cc:3
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
HGCalTestPartialWaferHits(const edm::ParameterSet &ps)
int waferU() const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
bool getData(T &iHolder) const
Definition: EventSetup.h:122
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_
int waferV() const
auto const good
min quality of good
~HGCalTestPartialWaferHits() override=default
void add(std::string const &label, ParameterSetDescription const &psetDescription)
int cellV() const
bool isValid() const
Definition: HandleBase.h:70
HLT enums.
int32_t waferV(const int32_t index)
const edm::ESGetToken< HGCalGeometry, IdealGeometryRecord > geomToken_