Skip to content

Commit

Permalink
Merge pull request cms-sw#49 from jkiesele/from-CMSSW_12_0_0
Browse files Browse the repository at this point in the history
From cmssw 12 0 0
  • Loading branch information
kdlong authored Oct 22, 2021
2 parents 0d84915 + 6b6aebf commit 443d11f
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions DPGAnalysis/CommonNanoAOD/plugins/HitPositionTableProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,66 @@ class HitPositionTableProducer : public edm::stream::EDProducer<> {
return position;
}

float radiusFromHit(const PCaloHit& hit) {
DetId id = hit.id();
return radiusFromDetId(id);
}

float radiusFromHit(const CaloRecHit& hit) {
return radiusFromDetId(hit.detid());
}

// Should really only be used for HGCAL, cartesian
float radiusFromDetId(DetId id) {
DetId::Detector det = id.det();
if (det == DetId::Hcal || det == DetId::HGCalEE || det == DetId::HGCalHSi || det == DetId::HGCalHSc) {
if(rhtools_.isSilicon(id)){
return rhtools_.getRadiusToSide(id);
}
else if(rhtools_.isScintillator(id)){
auto detadphi = rhtools_.getScintDEtaDPhi(id);
float dphi = detadphi.second;//same in both
auto pos = rhtools_.getPosition(id);
float r = pos.transverse();
return r * sin(dphi)/2.;//this is anyway approximate
}
else{
return 0.;
}

} else {
return 0; //no except here
}
}

float radiusFromHit(const PSimHit& hit) {
auto detId = DetId(hit.detUnitId());
return radiusFromDetId(detId);
}

void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override {
edm::Handle<T> objs;
iEvent.getByToken(src_, objs);

std::vector<float> xvals;
std::vector<float> yvals;
std::vector<float> zvals;
std::vector<float> hitrvals;
for (const auto& obj : *objs) {
if (cut_(obj)) {
auto position = positionFromHit(obj);
xvals.emplace_back(position.x());
yvals.emplace_back(position.y());
zvals.emplace_back(position.z());
hitrvals.emplace_back(radiusFromHit(obj));
}
}

auto tab = std::make_unique<nanoaod::FlatTable>(xvals.size(), name_, false, true);
tab->addColumn<float>("x", xvals, "x position");
tab->addColumn<float>("y", yvals, "y position");
tab->addColumn<float>("z", zvals, "z position");
tab->addColumn<float>("hitr", hitrvals, "radius");

iEvent.put(std::move(tab));
}
Expand Down

0 comments on commit 443d11f

Please sign in to comment.