Skip to content

Commit

Permalink
Merge pull request #32393 from bsunanda/Phase2-hgx269
Browse files Browse the repository at this point in the history
Phase2-hgx269 Make use of ESGetToken and remove usage of HCAL (in one app)
  • Loading branch information
cmsbuild authored Dec 10, 2020
2 parents 56ff0af + 91892e5 commit 8e64f55
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 177 deletions.
1 change: 0 additions & 1 deletion Geometry/HGCalGeometry/test/HGCalGeometryDump.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
Expand Down
1 change: 0 additions & 1 deletion Geometry/HGCalGeometry/test/HGCalTestRecHitTool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

Expand Down
61 changes: 7 additions & 54 deletions Validation/HGCalValidation/plugins/HGCGeometryValidation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
#include <iostream>

#include "Geometry/Records/interface/IdealGeometryRecord.h"
#include "Geometry/Records/interface/HcalSimNumberingRecord.h"
#include "Geometry/HGCalCommonData/interface/HGCalDDDConstants.h"
#include "Geometry/HcalCommonData/interface/HcalDDDSimConstants.h"
#include "Geometry/HcalCommonData/interface/HcalCellType.h"

#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/ForwardDetId/interface/ForwardSubdetector.h"
Expand All @@ -29,7 +26,6 @@
#include "SimDataFormats/CaloHit/interface/PCaloHit.h"
#include "SimDataFormats/CaloHit/interface/PCaloHitContainer.h"
#include "SimDataFormats/ValidationFormats/interface/PHGCalValidInfo.h"
#include "DataFormats/HcalDetId/interface/HcalTestNumbering.h"
#include "SimDataFormats/CaloTest/interface/HGCalTestNumbering.h"

#include "PhysicsTools/HepMCCandAlgos/interface/GenParticlesHelper.h"
Expand All @@ -56,10 +52,10 @@ class HGCGeometryValidation : public DQMEDAnalyzer {
edm::EDGetTokenT<PHGCalValidInfo> g4Token_;
std::vector<std::string> geometrySource_;
int verbosity_;
std::vector<edm::ESGetToken<HGCalDDDConstants, IdealGeometryRecord>> geomToken_;

//HGCal geometry scheme
std::vector<const HGCalDDDConstants *> hgcGeometry_;
const HcalDDDSimConstants *hcons_;

//histogram related stuff
MonitorElement *heedzVsZ, *heedyVsY, *heedxVsX;
Expand All @@ -79,10 +75,13 @@ class HGCGeometryValidation : public DQMEDAnalyzer {
MonitorElement *hebdX, *hebdY, *hebdZ;
};

HGCGeometryValidation::HGCGeometryValidation(const edm::ParameterSet &cfg) : hcons_(nullptr) {
HGCGeometryValidation::HGCGeometryValidation(const edm::ParameterSet &cfg) {
g4Token_ = consumes<PHGCalValidInfo>(cfg.getParameter<edm::InputTag>("g4Source"));
geometrySource_ = cfg.getUntrackedParameter<std::vector<std::string> >("geometrySource");
geometrySource_ = cfg.getUntrackedParameter<std::vector<std::string>>("geometrySource");
verbosity_ = cfg.getUntrackedParameter<int>("verbosity", 0);
for (const auto &name : geometrySource_)
geomToken_.emplace_back(
esConsumes<HGCalDDDConstants, IdealGeometryRecord, edm::Transition::BeginRun>(edm::ESInputTag{"", name}));
}

HGCGeometryValidation::~HGCGeometryValidation() {}
Expand All @@ -96,24 +95,7 @@ void HGCGeometryValidation::fillDescriptions(edm::ConfigurationDescriptions &des
void HGCGeometryValidation::dqmBeginRun(const edm::Run &iRun, const edm::EventSetup &iSetup) {
//initiating hgcnumbering
for (size_t i = 0; i < geometrySource_.size(); i++) {
if (geometrySource_[i].find("Hcal") != std::string::npos) {
edm::ESHandle<HcalDDDSimConstants> pHRNDC;
iSetup.get<HcalSimNumberingRecord>().get(pHRNDC);
if (pHRNDC.isValid()) {
hcons_ = &(*pHRNDC);
hgcGeometry_.push_back(nullptr);
} else {
edm::LogWarning("HGCalValid") << "Cannot initiate HGCalGeometry for " << geometrySource_[i];
}
} else {
edm::ESHandle<HGCalDDDConstants> hgcGeom;
iSetup.get<IdealGeometryRecord>().get(geometrySource_[i], hgcGeom);
if (hgcGeom.isValid()) {
hgcGeometry_.push_back(hgcGeom.product());
} else {
edm::LogWarning("HGCalValid") << "Cannot initiate HGCalGeometry for " << geometrySource_[i];
}
}
hgcGeometry_.emplace_back(&iSetup.getData(geomToken_[i]));
}
}

Expand Down Expand Up @@ -301,36 +283,7 @@ void HGCGeometryValidation::analyze(const edm::Event &iEvent, const edm::EventSe
hebdZ->Fill((hitVtxZ.at(i) - zz));
hebdY->Fill((hitVtxY.at(i) - yy));
}

} else if (hitDet.at(i) == (unsigned int)(DetId::Hcal)) {
int subdet, zside, depth, eta, phi, lay;
HcalTestNumbering::unpackHcalIndex(hitIdx.at(i), subdet, zside, depth, eta, phi, lay);
HcalCellType::HcalCell cell = hcons_->cell(subdet, zside, lay, eta, phi);

double zz = mmtocm * cell.rz; //mm --> cm
if (zside == 0)
zz = -zz;
double rho = zz * tan(2.0 * atan(exp(-cell.eta)));
double xx = rho * cos(cell.phi); //cm
double yy = rho * sin(cell.phi); //cm

hebdzVsZ->Fill(zz, (hitVtxZ.at(i) - zz));
hebdyVsY->Fill(yy, (hitVtxY.at(i) - yy));
hebdxVsX->Fill(xx, (hitVtxX.at(i) - xx));

hebXG4VsId->Fill(hitVtxX.at(i), xx);
hebYG4VsId->Fill(hitVtxY.at(i), yy);
hebZG4VsId->Fill(hitVtxZ.at(i), zz);

hebdzVsLayer->Fill(lay, (hitVtxZ.at(i) - zz));
hebdyVsLayer->Fill(lay, (hitVtxY.at(i) - yy));
hebdxVsLayer->Fill(lay, (hitVtxX.at(i) - xx));

hebdX->Fill((hitVtxX.at(i) - xx));
hebdZ->Fill((hitVtxZ.at(i) - zz));
hebdY->Fill((hitVtxY.at(i) - yy));
}

} //end G4 hits

} else {
Expand Down
92 changes: 28 additions & 64 deletions Validation/HGCalValidation/plugins/SimG4HGCalValidation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@

// to retreive hits
#include "DataFormats/DetId/interface/DetId.h"
#include "DataFormats/HcalDetId/interface/HcalSubdetector.h"
#include "DataFormats/ForwardDetId/interface/ForwardSubdetector.h"
#include "DataFormats/Math/interface/Point3D.h"
#include "SimDataFormats/ValidationFormats/interface/PHGCalValidInfo.h"
#include "SimDataFormats/CaloTest/interface/HGCalTestNumbering.h"
#include "DataFormats/HcalDetId/interface/HcalTestNumbering.h"
#include "SimG4CMS/Calo/interface/HGCNumberingScheme.h"
#include "SimG4CMS/Calo/interface/HGCalNumberingScheme.h"

Expand All @@ -28,9 +26,6 @@
#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include "Geometry/Records/interface/IdealGeometryRecord.h"
#include "Geometry/Records/interface/HcalSimNumberingRecord.h"
#include "Geometry/HcalCommonData/interface/HcalNumberingFromDDD.h"
#include "Geometry/HcalCommonData/interface/HcalDDDSimConstants.h"
#include "Geometry/HGCalCommonData/interface/HGCalGeometryMode.h"
#include "Geometry/HGCalCommonData/interface/HGCalDDDConstants.h"

Expand Down Expand Up @@ -79,9 +74,6 @@ class SimG4HGCalValidation : public SimProducer,
void clear();

private:
//Keep reference to instantiate HcalNumberingFromDDD later
HcalNumberingFromDDD* numberingFromDDD_;

//HGCal numbering scheme
std::vector<HGCNumberingScheme*> hgcNumbering_;
std::vector<HGCalNumberingScheme*> hgcalNumbering_;
Expand All @@ -103,8 +95,7 @@ class SimG4HGCalValidation : public SimProducer,
std::vector<double> hgchitX_, hgchitY_, hgchitZ_;
};

SimG4HGCalValidation::SimG4HGCalValidation(const edm::ParameterSet& p)
: numberingFromDDD_(nullptr), levelT1_(999), levelT2_(999), count_(0) {
SimG4HGCalValidation::SimG4HGCalValidation(const edm::ParameterSet& p) : levelT1_(999), levelT2_(999), count_(0) {
edm::ParameterSet m_Anal = p.getParameter<edm::ParameterSet>("SimG4HGCalValidation");
names_ = m_Anal.getParameter<std::vector<std::string> >("Names");
types_ = m_Anal.getParameter<std::vector<int> >("Types");
Expand All @@ -126,7 +117,6 @@ SimG4HGCalValidation::SimG4HGCalValidation(const edm::ParameterSet& p)
}

SimG4HGCalValidation::~SimG4HGCalValidation() {
delete numberingFromDDD_;
for (auto number : hgcNumbering_)
delete number;
for (auto number : hgcalNumbering_)
Expand Down Expand Up @@ -190,18 +180,8 @@ void SimG4HGCalValidation::update(const BeginOfJob* job) {
throw cms::Exception("Unknown", "ValidHGCal") << "Cannot find HGCalDDDConstants for " << nameX << "\n";
}
} else {
nameX = "HcalEndcap";
dets_.push_back((unsigned int)(DetId::Hcal));
subdet_.push_back((int)(HcalSubdetector::HcalEndcap));
edm::ESHandle<HcalDDDSimConstants> hdc;
es->get<HcalSimNumberingRecord>().get(hdc);
if (hdc.isValid()) {
numberingFromDDD_ = new HcalNumberingFromDDD(hdc.product());
layers = 18;
} else {
edm::LogError("ValidHGCal") << "Cannot find HcalDDDSimConstant";
throw cms::Exception("Unknown", "ValidHGCal") << "Cannot find HcalDDDSimConstant\n";
}
edm::LogError("ValidHGCal") << "Wrong Type " << types_[type];
throw cms::Exception("Unknown", "ValidHGCal") << "Wrong Type " << types_[type] << "\n";
}
if (detType == 0) {
for (int i = 0; i < layers; ++i)
Expand Down Expand Up @@ -272,51 +252,35 @@ void SimG4HGCalValidation::update(const G4Step* aStep) {
unsigned int index(0);
int layer(0);
G4ThreeVector hitPoint = aStep->GetPreStepPoint()->GetPosition();
if (types_[type] <= 1) {
// HGCal
G4ThreeVector localpos = touchable->GetHistory()->GetTopTransform().TransformPoint(hitPoint);
float globalZ = touchable->GetTranslation(0).z();
int iz(globalZ > 0 ? 1 : -1);
int module(-1), cell(-1);
if (types_[type] == 1) {
if (touchable->GetHistoryDepth() == levelT1_) {
layer = touchable->GetReplicaNumber(0);
} else {
layer = touchable->GetReplicaNumber(2);
module = touchable->GetReplicaNumber(1);
cell = touchable->GetReplicaNumber(0);
}
index =
hgcNumbering_[type]->getUnitID((ForwardSubdetector)(subdet_[type]), layer, module, cell, iz, localpos);
// HGCal
G4ThreeVector localpos = touchable->GetHistory()->GetTopTransform().TransformPoint(hitPoint);
float globalZ = touchable->GetTranslation(0).z();
int iz(globalZ > 0 ? 1 : -1);
int module(-1), cell(-1);
if (types_[type] == 1) {
if (touchable->GetHistoryDepth() == levelT1_) {
layer = touchable->GetReplicaNumber(0);
} else {
if ((touchable->GetHistoryDepth() == levelT1_) || (touchable->GetHistoryDepth() == levelT2_)) {
layer = touchable->GetReplicaNumber(0);
} else {
layer = touchable->GetReplicaNumber(3);
module = touchable->GetReplicaNumber(2);
cell = touchable->GetReplicaNumber(1);
}
double weight(0);
index = hgcalNumbering_[type]->getUnitID(layer, module, cell, iz, hitPoint, weight);
layer = touchable->GetReplicaNumber(2);
module = touchable->GetReplicaNumber(1);
cell = touchable->GetReplicaNumber(0);
}
if (verbosity_ > 1)
edm::LogVerbatim("ValidHGCal")
<< "HGCal: " << name << " Layer " << layer << " Module " << module << " Cell " << cell;
index =
hgcNumbering_[type]->getUnitID((ForwardSubdetector)(subdet_[type]), layer, module, cell, iz, localpos);
} else {
// Hcal
int depth = (touchable->GetReplicaNumber(0)) % 10 + 1;
int lay = (touchable->GetReplicaNumber(0) / 10) % 100 + 1;
int det = (touchable->GetReplicaNumber(1)) / 1000;
HcalNumberingFromDDD::HcalID tmp =
numberingFromDDD_->unitID(det, math::XYZVectorD(hitPoint.x(), hitPoint.y(), hitPoint.z()), depth, lay);
index = HcalTestNumbering::packHcalIndex(tmp.subdet, tmp.zside, tmp.depth, tmp.etaR, tmp.phis, tmp.lay);
layer = tmp.lay;
if (verbosity_ > 1)
edm::LogVerbatim("ValidHGCal")
<< "HCAL: " << det << ":" << depth << ":" << lay << " o/p " << tmp.subdet << ":" << tmp.zside << ":"
<< tmp.depth << ":" << tmp.etaR << ":" << tmp.phis << ":" << tmp.lay << " point " << hitPoint << " "
<< hitPoint.rho() << ":" << hitPoint.eta() << ":" << hitPoint.phi();
if ((touchable->GetHistoryDepth() == levelT1_) || (touchable->GetHistoryDepth() == levelT2_)) {
layer = touchable->GetReplicaNumber(0);
} else {
layer = touchable->GetReplicaNumber(3);
module = touchable->GetReplicaNumber(2);
cell = touchable->GetReplicaNumber(1);
}
double weight(0);
index = hgcalNumbering_[type]->getUnitID(layer, module, cell, iz, hitPoint, weight);
}
if (verbosity_ > 1)
edm::LogVerbatim("ValidHGCal") << "HGCal: " << name << " Layer " << layer << " Module " << module << " Cell "
<< cell;

double edeposit = aStep->GetTotalEnergyDeposit();
if (verbosity_ > 0)
Expand Down
26 changes: 0 additions & 26 deletions Validation/HGCalValidation/python/hgcGeometryValidationV6_cfi.py

This file was deleted.

26 changes: 0 additions & 26 deletions Validation/HGCalValidation/python/hgcGeometryValidationV9_cfi.py

This file was deleted.

10 changes: 5 additions & 5 deletions Validation/HGCalValidation/python/hgcGeometryValidation_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
g4SimHits.Watchers = cms.VPSet(cms.PSet(
SimG4HGCalValidation = cms.PSet(
Names = cms.vstring(
'HGCalEECell',
'HGCalHECell',
'HEScintillator',
'HGCalEESensitive',
'HGCalHESiliconSensitive',
'HGCalHEScintillatorSensitive',
),
Types = cms.vint32(1,1,2),
Types = cms.vint32(1,1,1),
LabelLayerInfo = cms.string("HGCalInfoLayer"),
),
type = cms.string('SimG4HGCalValidation')
Expand All @@ -20,7 +20,7 @@
geometrySource = cms.untracked.vstring(
'HGCalEESensitive',
'HGCalHESiliconSensitive',
'Hcal'),
'HGCalHEScintillatorSensitive'),
g4Source = cms.InputTag("g4SimHits","HGCalInfoLayer"),
verbosity= cms.int32(0),
)

0 comments on commit 8e64f55

Please sign in to comment.