Skip to content

Commit

Permalink
Merge pull request #38562 from bsunanda/Phase2-sim120
Browse files Browse the repository at this point in the history
Phase2-sim120 Add test to check hits in partial wafers for V17 geometry
  • Loading branch information
cmsbuild authored Jul 6, 2022
2 parents 0eaa592 + 155ea4b commit 8c26f12
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 0 deletions.
103 changes: 103 additions & 0 deletions SimG4CMS/Calo/plugins/HGCalHitPartial.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"

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

#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/Utilities/interface/Exception.h"

#include "DataFormats/ForwardDetId/interface/HGCSiliconDetId.h"

#include "SimDataFormats/CaloHit/interface/PCaloHit.h"
#include "SimDataFormats/CaloHit/interface/PCaloHitContainer.h"

#include "Geometry/CaloTopology/interface/HGCalTopology.h"
#include "Geometry/HGCalGeometry/interface/HGCalGeometry.h"
#include "Geometry/HGCalCommonData/interface/HGCalDDDConstants.h"
#include "Geometry/HGCalCommonData/interface/HGCalParameters.h"
#include "Geometry/Records/interface/IdealGeometryRecord.h"

#include <string>
#include <vector>

class HGcalHitPartial : public edm::one::EDAnalyzer<> {
public:
HGcalHitPartial(const edm::ParameterSet& ps);
~HGcalHitPartial() override = default;
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

protected:
void analyze(edm::Event const&, edm::EventSetup const&) override;
void beginJob() override {}
void endJob() override {}

private:
const std::string g4Label_, caloHitSource_, nameSense_;
const edm::EDGetTokenT<edm::PCaloHitContainer> tok_calo_;
const edm::ESGetToken<HGCalGeometry, IdealGeometryRecord> geomToken_;
};

HGcalHitPartial::HGcalHitPartial(const edm::ParameterSet& ps)
: g4Label_(ps.getParameter<std::string>("moduleLabel")),
caloHitSource_(ps.getParameter<std::string>("caloHitSource")),
nameSense_(ps.getParameter<std::string>("nameSense")),
tok_calo_(consumes<edm::PCaloHitContainer>(edm::InputTag(g4Label_, caloHitSource_))),
geomToken_(esConsumes<HGCalGeometry, IdealGeometryRecord>(edm::ESInputTag{"", nameSense_})) {
edm::LogVerbatim("HGCalSim") << "Test Hit ID using SimHits for " << nameSense_ << " with module Label: " << g4Label_
<< " Hits: " << caloHitSource_;
}

void HGcalHitPartial::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add<std::string>("moduleLabel", "g4SimHits");
desc.add<std::string>("caloHitSource", "HGCHitsEE");
desc.add<std::string>("nameSense", "HGCalEESensitive");
descriptions.add("hgcalHitPartialEE", desc);
}

void HGcalHitPartial::analyze(const edm::Event& e, const edm::EventSetup& iS) {
// get hcalGeometry
const HGCalGeometry* geom = &iS.getData(geomToken_);
const HGCalDDDConstants& hgc = geom->topology().dddConstants();
// get the hit collection
const edm::Handle<edm::PCaloHitContainer>& hitsCalo = e.getHandle(tok_calo_);
bool getHits = (hitsCalo.isValid());
uint32_t nhits = (getHits) ? hitsCalo->size() : 0;
uint32_t good(0), allSi(0), all(0);
edm::LogVerbatim("HGCalSim") << "HGcalHitPartial: Input flags Hits " << getHits << " with " << nhits << " hits";

if (getHits) {
std::vector<PCaloHit> hits;
hits.insert(hits.end(), hitsCalo->begin(), hitsCalo->end());
if (!hits.empty()) {
// Loop over all hits
for (auto hit : hits) {
++all;
DetId id(hit.id());
if ((id.det() == DetId::HGCalEE) || (id.det() == DetId::HGCalHSi)) {
++allSi;
HGCSiliconDetId hid(id);
const auto& info = hgc.waferInfo(hid.layer(), hid.waferU(), hid.waferV());
// Only partial wafers
if (info.part != HGCalTypes::WaferFull) {
++good;
GlobalPoint pos = geom->getPosition(id);
edm::LogVerbatim("HGCalSim") << "Hit[" << all << ":" << allSi << ":" << good << "]" << HGCSiliconDetId(id)
<< " Wafer Type:Part:Orient:Cassette " << info.type << ":" << info.part << ":"
<< info.orient << ":" << info.cassette << " at (" << pos.x() << ", " << pos.y()
<< ", " << pos.z() << ")";
}
}
}
}
}
edm::LogVerbatim("HGCalSim") << "Total hits = " << all << ":" << nhits << " Good DetIds = " << allSi << ":" << good;
}

//define this as a plug-in
DEFINE_FWK_MODULE(HGcalHitPartial);
8 changes: 8 additions & 0 deletions SimG4CMS/Calo/python/hgcalHitPartial_cff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import FWCore.ParameterSet.Config as cms

from SimG4CMS.Calo.hgcalHitPartialEE_cfi import *

hgcalHitPartialHE = hgcalHitPartialEE.clone(
nameSense = "HGCalHESiliconSensitive",
caloHitSource = "HGCHitsHEfront"
)
74 changes: 74 additions & 0 deletions SimG4CMS/Calo/test/python/runHGC7_cfg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import FWCore.ParameterSet.Config as cms
from Configuration.Eras.Era_Phase2C11_cff import Phase2C11

process = cms.Process("PROD",Phase2C11)
process.load("SimGeneral.HepPDTESSource.pythiapdt_cfi")
process.load("IOMC.EventVertexGenerators.VtxSmearedGauss_cfi")
process.load("Configuration.Geometry.GeometryExtended2026D92Reco_cff")
process.load("Configuration.StandardSequences.MagneticField_cff")
process.load("Configuration.EventContent.EventContent_cff")
process.load('Configuration.StandardSequences.Generator_cff')
process.load('Configuration.StandardSequences.SimIdeal_cff')
process.load('FWCore.MessageService.MessageLogger_cfi')
process.load('SimG4CMS.Calo.hgcalHitPartial_cff')
process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
from Configuration.AlCa.GlobalTag import GlobalTag
process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:phase2_realistic_T21', '')

if hasattr(process,'MessageLogger'):
process.MessageLogger.HGCalGeom=dict()
process.MessageLogger.HGCalSim=dict()
process.MessageLogger.CaloSim=dict()

process.load("IOMC.RandomEngine.IOMC_cff")
process.RandomNumberGeneratorService.generator.initialSeed = 456789
process.RandomNumberGeneratorService.g4SimHits.initialSeed = 9876
process.RandomNumberGeneratorService.VtxSmeared.initialSeed = 123456789

process.Timing = cms.Service("Timing")

process.maxEvents = cms.untracked.PSet(
input = cms.untracked.int32(25)
)

process.source = cms.Source("EmptySource",
firstRun = cms.untracked.uint32(1),
firstEvent = cms.untracked.uint32(1)
)

process.generator = cms.EDProducer("FlatRandomEGunProducer",
PGunParameters = cms.PSet(
PartID = cms.vint32(211),
MinEta = cms.double(1.50),
MaxEta = cms.double(3.00),
MinPhi = cms.double(-3.1415926),
MaxPhi = cms.double(-1.5707963),
MinE = cms.double(100.00),
MaxE = cms.double(100.00)
),
Verbosity = cms.untracked.int32(0),
AddAntiParticle = cms.bool(True)
)

process.output = cms.OutputModule("PoolOutputModule",
process.FEVTSIMEventContent,
fileName = cms.untracked.string('hgcV17.root')
)

process.generation_step = cms.Path(process.pgen)
process.simulation_step = cms.Path(process.psim)
process.analysis_step = cms.Path(process.hgcalHitPartialEE+process.hgcalHitPartialHE)
process.out_step = cms.EndPath(process.output)

process.g4SimHits.Physics.type = 'SimG4Core/Physics/FTFP_BERT_EMM'

# Schedule definition
process.schedule = cms.Schedule(process.generation_step,
process.simulation_step,
process.analysis_step,
process.out_step
)

# filter all path with the production filter sequence
for path in process.paths:
getattr(process,path)._seq = process.generator * getattr(process,path)._seq

0 comments on commit 8c26f12

Please sign in to comment.