Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-01-08 23:51:02

0001 #include "FWCore/Framework/interface/Frameworkfwd.h"
0002 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0003 
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/Framework/interface/EventSetup.h"
0006 #include "FWCore/Framework/interface/MakerMacros.h"
0007 
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 #include "FWCore/ParameterSet/interface/FileInPath.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0012 #include "FWCore/Utilities/interface/InputTag.h"
0013 #include "FWCore/Utilities/interface/Exception.h"
0014 
0015 #include "DataFormats/DetId/interface/DetId.h"
0016 #include "DataFormats/ForwardDetId/interface/HGCSiliconDetId.h"
0017 #include "DataFormats/HGCRecHit/interface/HGCRecHitCollections.h"
0018 
0019 #include "Geometry/CaloTopology/interface/HGCalTopology.h"
0020 #include "Geometry/HGCalGeometry/interface/HGCalGeometry.h"
0021 #include "Geometry/HGCalCommonData/interface/HGCalDDDConstants.h"
0022 #include "Geometry/HGCalCommonData/interface/HGCalParameters.h"
0023 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0024 #include "SimG4CMS/Calo/interface/CaloSimUtils.h"
0025 
0026 #include <fstream>
0027 #include <string>
0028 #include <vector>
0029 
0030 class HGCalTestPartialWaferRecHits : public edm::one::EDAnalyzer<> {
0031 public:
0032   HGCalTestPartialWaferRecHits(const edm::ParameterSet& ps);
0033   ~HGCalTestPartialWaferRecHits() override = default;
0034   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0035 
0036 protected:
0037   void analyze(edm::Event const&, edm::EventSetup const&) override;
0038   void beginJob() override {}
0039   void endJob() override {}
0040 
0041 private:
0042   const std::string nameDetector_, missingFile_;
0043   const edm::InputTag source_;
0044   const edm::EDGetTokenT<HGCRecHitCollection> recHitSource_;
0045   const edm::ESGetToken<HGCalGeometry, IdealGeometryRecord> tok_hgcGeom_;
0046   std::vector<int> wafers_;
0047   std::vector<int> dumpDets_;
0048 };
0049 
0050 HGCalTestPartialWaferRecHits::HGCalTestPartialWaferRecHits(const edm::ParameterSet& ps)
0051     : nameDetector_(ps.getParameter<std::string>("detectorName")),
0052       missingFile_(ps.getParameter<std::string>("missingFile")),
0053       source_(ps.getParameter<edm::InputTag>("source")),
0054       recHitSource_(consumes<HGCRecHitCollection>(source_)),
0055       tok_hgcGeom_(esConsumes<HGCalGeometry, IdealGeometryRecord>(edm::ESInputTag{"", nameDetector_})) {
0056   edm::LogVerbatim("HGCalSim") << "Test Hit ID using RecHits for " << nameDetector_ << " with module Label: " << source_
0057                                << " Missing Wafer file " << missingFile_;
0058   if (!missingFile_.empty()) {
0059     edm::FileInPath filetmp("SimG4CMS/Calo/data/" + missingFile_);
0060     std::string fileName = filetmp.fullPath();
0061     std::ifstream fInput(fileName.c_str());
0062     if (!fInput.good()) {
0063       edm::LogVerbatim("HGCalSim") << "Cannot open file " << fileName;
0064     } else {
0065       char buffer[80];
0066       while (fInput.getline(buffer, 80)) {
0067         std::vector<std::string> items = CaloSimUtils::splitString(std::string(buffer));
0068         if (items.size() > 2) {
0069           int layer = std::atoi(items[0].c_str());
0070           int waferU = std::atoi(items[1].c_str());
0071           int waferV = std::atoi(items[2].c_str());
0072           wafers_.emplace_back(HGCalWaferIndex::waferIndex(layer, waferU, waferV, false));
0073         } else if (items.size() == 1) {
0074           int dumpdet = std::atoi(items[0].c_str());
0075           dumpDets_.emplace_back(dumpdet);
0076           edm::LogVerbatim("HGCalSim") << nameDetector_ << " Dump detector " << dumpdet;
0077         }
0078       }
0079       edm::LogVerbatim("HGCalSim") << "HGCalTestPartialWaferRecHits::Reads in " << wafers_.size() << ":"
0080                                    << dumpDets_.size() << " wafer|detector information from " << fileName;
0081       fInput.close();
0082     }
0083   }
0084 }
0085 
0086 void HGCalTestPartialWaferRecHits::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0087   edm::ParameterSetDescription desc;
0088   desc.add<std::string>("detectorName", "HGCalEESensitive");
0089   desc.add<std::string>("missingFile", "");
0090   desc.add<edm::InputTag>("source", edm::InputTag("HGCalRecHit", "HGCEERecHits"));
0091   descriptions.add("hgcalRecHitPartialEE", desc);
0092 }
0093 
0094 void HGCalTestPartialWaferRecHits::analyze(const edm::Event& e, const edm::EventSetup& iS) {
0095   // get hgcalGeometry
0096   const HGCalGeometry* geom = &iS.getData(tok_hgcGeom_);
0097   const HGCalDDDConstants& hgc = geom->topology().dddConstants();
0098   int firstLayer = hgc.getLayerOffset();
0099   // get the hit collection
0100   const edm::Handle<HGCRecHitCollection>& theRecHitContainers = e.getHandle(recHitSource_);
0101   bool getHits = (theRecHitContainers.isValid());
0102   uint32_t nhits = (getHits) ? theRecHitContainers->size() : 0;
0103   uint32_t good(0), allSi(0), all(0);
0104   edm::LogVerbatim("HGCalSim") << "HGCalTestPartialWaferRecHits: Input flags Hits " << getHits << " with " << nhits
0105                                << " hits: Layer Offset " << firstLayer;
0106 
0107   if (getHits) {
0108     // Loop over all hits
0109     for (const auto& it : *(theRecHitContainers.product())) {
0110       ++all;
0111       DetId id(it.id());
0112       if ((id.det() == DetId::HGCalEE) || (id.det() == DetId::HGCalHSi)) {
0113         ++allSi;
0114         HGCSiliconDetId hid(id);
0115         const auto& info = hgc.waferInfo(hid.layer(), hid.waferU(), hid.waferV());
0116         bool toCheck(false);
0117         if (!wafers_.empty()) {
0118           int indx = HGCalWaferIndex::waferIndex(firstLayer + hid.layer(), hid.waferU(), hid.waferV(), false);
0119           if (std::find(wafers_.begin(), wafers_.end(), indx) != wafers_.end())
0120             toCheck = true;
0121         } else if (!dumpDets_.empty()) {
0122           if ((std::find(dumpDets_.begin(), dumpDets_.end(), static_cast<int>(id.det())) != dumpDets_.end()) &&
0123               (info.part != HGCalTypes::WaferFull))
0124             toCheck = true;
0125         } else {
0126           // Only partial wafers
0127           toCheck = (info.part != HGCalTypes::WaferFull);
0128         }
0129         if (toCheck) {
0130           ++good;
0131           GlobalPoint pos = geom->getPosition(id);
0132           bool valid1 = geom->topology().valid(id);
0133           bool valid2 = hgc.isValidHex8(hid.layer(), hid.waferU(), hid.waferV(), hid.cellU(), hid.cellV(), false);
0134           edm::LogVerbatim("HGCalSim") << "Hit[" << all << ":" << allSi << ":" << good << "]" << hid
0135                                        << " Wafer Type:Part:Orient:Cassette " << info.type << ":" << info.part << ":"
0136                                        << info.orient << ":" << info.cassette << " at (" << pos.x() << ", " << pos.y()
0137                                        << ", " << pos.z() << ") Validity " << valid1 << ":" << valid2;
0138         }
0139       }
0140     }
0141   }
0142   edm::LogVerbatim("HGCalSim") << "Total hits = " << all << ":" << nhits << " Good DetIds = " << allSi << ":" << good;
0143 }
0144 
0145 //define this as a plug-in
0146 DEFINE_FWK_MODULE(HGCalTestPartialWaferRecHits);