CMS 3D CMS Logo

HcalTestSimHitID.cc
Go to the documentation of this file.
3 
13 
26 
27 #include <memory>
28 #include <iostream>
29 #include <fstream>
30 #include <vector>
31 #include <string>
32 
34 public:
36 
37  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
38 
39 protected:
40  void beginJob() override {}
41  void endJob() override {}
42  void analyze(const edm::Event& e, const edm::EventSetup& c) override;
43 
44 private:
46  const bool testN_, dumpHits_;
47  const int maxEvent_;
48  int nevt_;
53 };
54 
56  : g4Label_(ps.getUntrackedParameter<std::string>("moduleLabel", "g4SimHits")),
57  hitLab_(ps.getUntrackedParameter<std::string>("hcCollection", "HcalHits")),
58  testN_(ps.getUntrackedParameter<bool>("testNumbering", false)),
59  dumpHits_(ps.getUntrackedParameter<bool>("dumpHits", false)),
60  maxEvent_(ps.getUntrackedParameter<int>("maxEvent", 100)),
61  nevt_(0) {
62  // register for data access
63  toks_calo_ = consumes<edm::PCaloHitContainer>(edm::InputTag(g4Label_, hitLab_));
64  tok_hrdd_ = esConsumes<HcalDDDRecConstants, HcalRecNumberingRecord>();
65  tok_topo_ = esConsumes<HcalTopology, HcalRecNumberingRecord>();
66  tok_geom_ = esConsumes<CaloGeometry, CaloGeometryRecord>();
67 
68  std::cout << "HcalTestSimHitID::Module Label: " << g4Label_ << " Hits: " << hitLab_ << " MaxEvent: " << maxEvent_
69  << " Numbering scheme: " << testN_ << " (0 normal; 1 test)\n";
70 }
71 
74  desc.addUntracked<std::string>("moduleLabel", "g4SimHits");
75  desc.addUntracked<std::string>("hcCollection", "HcalHits");
76  desc.addUntracked<bool>("testNumbering", false);
77  desc.addUntracked<bool>("dumpHits", false);
78  desc.addUntracked<int>("maxEvent", 100);
79  descriptions.add("hcalTestSimHitID", desc);
80 }
81 
83  ++nevt_;
84  std::cout << "HcalTestSimHitID::Serial # " << nevt_ << " Run # " << e.id().run() << " Event # " << e.id().event()
85  << std::endl;
87  const HcalDDDRecConstants* hcr = pHRNDC.product();
89  const HcalTopology* theHBHETopology = htopo.product();
91  const CaloGeometry* caloGeom = geom.product();
92  const HcalGeometry* hcalGeom =
93  static_cast<const HcalGeometry*>(caloGeom->getSubdetectorGeometry(DetId::Hcal, HcalBarrel));
94 
95  if (nevt_ <= maxEvent_) {
96  std::vector<PCaloHit> hcHits;
98  e.getByToken(toks_calo_, hitsCalo);
99  if (hitsCalo.isValid()) {
100  std::vector<PCaloHit> hits;
101  hits.insert(hits.end(), hitsCalo->begin(), hitsCalo->end());
102  std::cout << "HcalValidation: Hit buffer " << hits.size() << std::endl;
103 
104  //Now the testing
105  unsigned int good(0);
106  for (unsigned int i = 0; i < hits.size(); i++) {
107  unsigned int id = hits[i].id();
108  HcalDetId hid;
109  GlobalPoint p1, p2;
110  if (testN_) {
111  p1 = hcalGeom->getPosition(id, true);
112  hid = HcalDetId(HcalHitRelabeller::relabel(id, hcr));
113  } else {
114  hid = HcalDetId(id);
115  }
116  p2 = hcalGeom->getPosition(DetId(hid));
117  if (theHBHETopology->validHcal(hid)) {
118  ++good;
119  if (dumpHits_) {
120  std::cout << "Hit[" << i << "] " << hid << " \n";
121  if (testN_)
122  std::cout << "Test " << p1 << " from HcalDetId " << p2 << "\n";
123  }
124  } else {
125  std::cout << "Hit[" << i << "] " << hid << " ***** ERROR *****\n";
126  }
127  }
128  std::cout << "HcalTestSimHitID:: " << good << " among " << hits.size() << " hits\n";
129  }
130  }
131 }
132 
133 //define this as a plug-in
ConfigurationDescriptions.h
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
HcalTestSimHitID::analyze
void analyze(const edm::Event &e, const edm::EventSetup &c) override
Definition: HcalTestSimHitID.cc:82
electrons_cff.bool
bool
Definition: electrons_cff.py:366
mps_fire.i
i
Definition: mps_fire.py:428
HcalTestSimHitID::toks_calo_
edm::EDGetTokenT< edm::PCaloHitContainer > toks_calo_
Definition: HcalTestSimHitID.cc:49
MessageLogger.h
HcalTopology::validHcal
bool validHcal(const HcalDetId &id) const
Definition: HcalTopology.cc:230
funct::false
false
Definition: Factorize.h:29
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
ESHandle.h
edm::EDGetTokenT< edm::PCaloHitContainer >
gather_cfg.cout
cout
Definition: gather_cfg.py:144
HcalTopology
Definition: HcalTopology.h:26
DetId::Hcal
Definition: DetId.h:28
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
CaloGeometry::getSubdetectorGeometry
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:34
HcalTestSimHitID::HcalTestSimHitID
HcalTestSimHitID(const edm::ParameterSet &ps)
Definition: HcalTestSimHitID.cc:55
HcalRecNumberingRecord.h
EDAnalyzer.h
HcalTestNumbering.h
HcalBarrel
Definition: HcalAssistant.h:33
HcalTestSimHitID::maxEvent_
const int maxEvent_
Definition: HcalTestSimHitID.cc:47
edm::Handle
Definition: AssociativeIterator.h:50
HcalTestSimHitID::dumpHits_
const bool dumpHits_
Definition: HcalTestSimHitID.cc:46
HcalGeometry.h
edm::EDAnalyzer
Definition: EDAnalyzer.h:28
HcalTestSimHitID::tok_topo_
edm::ESGetToken< HcalTopology, HcalRecNumberingRecord > tok_topo_
Definition: HcalTestSimHitID.cc:51
HcalTestSimHitID::endJob
void endJob() override
Definition: HcalTestSimHitID.cc:41
DetId
Definition: DetId.h:17
MakerMacros.h
CaloGeometry
Definition: CaloGeometry.h:21
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
HcalTestSimHitID::nevt_
int nevt_
Definition: HcalTestSimHitID.cc:48
edm::ESHandle
Definition: DTSurvey.h:22
p2
double p2[4]
Definition: TauolaWrapper.h:90
relativeConstraints.geom
geom
Definition: relativeConstraints.py:72
Point3DBase< float, GlobalTag >
HcalTestSimHitID::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: HcalTestSimHitID.cc:72
CaloGeometryRecord.h
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HcalTestSimHitID::tok_hrdd_
edm::ESGetToken< HcalDDDRecConstants, HcalRecNumberingRecord > tok_hrdd_
Definition: HcalTestSimHitID.cc:50
CaloSubdetectorGeometry.h
edm::ParameterSet
Definition: ParameterSet.h:47
HcalGeometry::getPosition
GlobalPoint getPosition(const DetId &id) const
Definition: HcalGeometry.cc:179
Event.h
HcalTestSimHitID::testN_
const bool testN_
Definition: HcalTestSimHitID.cc:46
HcalDetId.h
HcalHitRelabeller.h
PCaloHit.h
HcalDetId
Definition: HcalDetId.h:12
createfilelist.int
int
Definition: createfilelist.py:10
edm::EventSetup::getHandle
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:155
p1
double p1[4]
Definition: TauolaWrapper.h:89
edm::EventSetup
Definition: EventSetup.h:58
edm::ESGetToken< HcalDDDRecConstants, HcalRecNumberingRecord >
InputTag.h
HcalTestSimHitID::beginJob
void beginJob() override
Definition: HcalTestSimHitID.cc:40
HcalHitRelabeller::relabel
DetId relabel(const uint32_t testId) const
Definition: HcalHitRelabeller.cc:49
HcalTestSimHitID::tok_geom_
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > tok_geom_
Definition: HcalTestSimHitID.cc:52
HcalTopology.h
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
std
Definition: JetResolutionObject.h:76
Frameworkfwd.h
CaloGeometry.h
HcalDDDRecConstants.h
HcalTestSimHitID
Definition: HcalTestSimHitID.cc:33
EventSetup.h
Exception.h
PCaloHitContainer.h
HcalTestSimHitID::hitLab_
const std::string hitLab_
Definition: HcalTestSimHitID.cc:45
HcalDDDRecConstants
Definition: HcalDDDRecConstants.h:23
ParameterSet.h
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::Event
Definition: Event.h:73
HcalGeometry
Definition: HcalGeometry.h:17
HcalTestSimHitID::g4Label_
const std::string g4Label_
Definition: HcalTestSimHitID.cc:45
edm::InputTag
Definition: InputTag.h:15
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37