Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:25:53

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/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0010 #include "FWCore/Utilities/interface/InputTag.h"
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012 #include "FWCore/Utilities/interface/Exception.h"
0013 
0014 #include "DataFormats/HGCDigi/interface/HGCDigiCollections.h"
0015 #include "DataFormats/HGCRecHit/interface/HGCRecHitCollections.h"
0016 #include "DataFormats/ForwardDetId/interface/HGCSiliconDetId.h"
0017 
0018 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
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/CaloGeometryRecord.h"
0024 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0025 
0026 #include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h"
0027 
0028 #include <string>
0029 #include <vector>
0030 
0031 class HGCalRecHitToolsPartialWafer : public edm::one::EDAnalyzer<> {
0032 public:
0033   HGCalRecHitToolsPartialWafer(const edm::ParameterSet& ps);
0034   ~HGCalRecHitToolsPartialWafer() override = default;
0035 
0036   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0037 
0038 protected:
0039   void analyze(edm::Event const&, edm::EventSetup const&) override;
0040   void beginJob() override {}
0041   void endJob() override {}
0042 
0043 private:
0044   template <class T>
0045   void analyze(const T& collection, const HGCalGeometry* geom);
0046 
0047   const edm::InputTag source_;
0048   const std::string nameSense_;
0049   const bool checkDigi_;
0050   const edm::EDGetTokenT<HGCalDigiCollection> digiToken_;
0051   const edm::EDGetTokenT<HGCRecHitCollection> recHitToken_;
0052   const edm::ESGetToken<CaloGeometry, CaloGeometryRecord> geomToken_;
0053   hgcal::RecHitTools tool_;
0054 };
0055 
0056 HGCalRecHitToolsPartialWafer::HGCalRecHitToolsPartialWafer(const edm::ParameterSet& ps)
0057     : source_(ps.getParameter<edm::InputTag>("source")),
0058       nameSense_(ps.getParameter<std::string>("nameSense")),
0059       checkDigi_(ps.getParameter<bool>("checkDigi")),
0060       digiToken_(consumes<HGCalDigiCollection>(source_)),
0061       recHitToken_(consumes<HGCRecHitCollection>(source_)),
0062       geomToken_(esConsumes<CaloGeometry, CaloGeometryRecord>()) {
0063   edm::LogVerbatim("HGCalSim") << "Test Hit ID using Digi(1)/RecHit(0): " << checkDigi_ << " for " << nameSense_
0064                                << " with module Label: " << source_;
0065 }
0066 
0067 void HGCalRecHitToolsPartialWafer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0068   edm::ParameterSetDescription desc;
0069   desc.add<edm::InputTag>("source", edm::InputTag("simHGCalUnsuppressedDigis", "EE"));
0070   desc.add<std::string>("nameSense", "HGCalEESensitive");
0071   desc.add<bool>("checkDigi", true);
0072   descriptions.add("hgcalCheckToolDigiEE", desc);
0073 }
0074 
0075 void HGCalRecHitToolsPartialWafer::analyze(const edm::Event& e, const edm::EventSetup& iS) {
0076   // get HGCal geometry constant
0077   const CaloGeometry geo = iS.getData(geomToken_);
0078   const HGCalGeometry* geom = (nameSense_ == "HGCalEESensitive")
0079                                   ? static_cast<const HGCalGeometry*>(
0080                                         geo.getSubdetectorGeometry(DetId::HGCalEE, ForwardSubdetector::ForwardEmpty))
0081                                   : static_cast<const HGCalGeometry*>(
0082                                         geo.getSubdetectorGeometry(DetId::HGCalHSi, ForwardSubdetector::ForwardEmpty));
0083   //Setup the tool
0084   tool_.setGeometry(geo);
0085 
0086   // get the hit collection
0087   if (checkDigi_) {
0088     const auto& collection = e.getHandle(digiToken_);
0089     if (collection.isValid()) {
0090       edm::LogVerbatim("HGCalSim") << "HGCalRecHitToolsPartialWafer: Finds Digi Collection for " << nameSense_
0091                                    << " with " << collection->size() << " hits";
0092       analyze(*(collection.product()), geom);
0093     } else {
0094       edm::LogVerbatim("HGCalSim") << "HGCalRecHitToolsPartialWafer: Cannot find Digi collection for " << nameSense_;
0095     }
0096   } else {
0097     const auto& collection = e.getHandle(recHitToken_);
0098     if (collection.isValid()) {
0099       edm::LogVerbatim("HGCalSim") << "HGCalRecHitToolsPartialWafer: Finds RecHit Collection for " << nameSense_
0100                                    << " with " << collection->size() << " hits";
0101       analyze(*(collection.product()), geom);
0102     } else {
0103       edm::LogVerbatim("HGCalSim") << "HGCalRecHitToolsPartialWafer: Cannot find RecHit collection for " << nameSense_;
0104     }
0105   }
0106 }
0107 
0108 template <class T>
0109 void HGCalRecHitToolsPartialWafer::analyze(const T& collection, const HGCalGeometry* geom) {
0110   const HGCalDDDConstants& hgc = geom->topology().dddConstants();
0111   uint32_t nhits = collection.size();
0112   uint32_t good(0), allSi(0), all(0);
0113 
0114   // Loop over all hits
0115   for (const auto& it : collection) {
0116     ++all;
0117     DetId id(it.id());
0118     if ((id.det() == DetId::HGCalEE) || (id.det() == DetId::HGCalHSi)) {
0119       ++allSi;
0120       HGCSiliconDetId hid(id);
0121       const auto& info = hgc.waferInfo(hid.layer(), hid.waferU(), hid.waferV());
0122       // Only partial wafers
0123       if (info.part != HGCalTypes::WaferFull) {
0124         ++good;
0125         GlobalPoint pos1 = geom->getPosition(id);
0126         GlobalPoint pos2 = tool_.getPosition(id);
0127         edm::LogVerbatim("HGCalSim") << "Hit[" << all << ":" << allSi << ":" << good << "]" << HGCSiliconDetId(id)
0128                                      << " Wafer Type:Part:Orient:Cassette " << info.type << ":" << info.part << ":"
0129                                      << info.orient << ":" << info.cassette << " at (" << pos1.x() << ", " << pos1.y()
0130                                      << ", " << pos1.z() << ") or (" << pos2.x() << ", " << pos2.y() << ", " << pos2.z()
0131                                      << ")";
0132       }
0133     }
0134   }
0135   edm::LogVerbatim("HGCalSim") << "Total hits = " << all << ":" << nhits << " Good DetIds = " << allSi << ":" << good;
0136 }
0137 
0138 //define this as a plug-in
0139 DEFINE_FWK_MODULE(HGCalRecHitToolsPartialWafer);