Skip to content

Commit

Permalink
Propagate to HGCal instead of EndcapECal for phase2
Browse files Browse the repository at this point in the history
  • Loading branch information
mbluj committed Sep 15, 2020
1 parent be8750d commit 09eab8d
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 17 deletions.
3 changes: 3 additions & 0 deletions RecoTauTag/RecoTau/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<use name="MagneticField/Engine"/>
<use name="MagneticField/Records"/>
<use name="Geometry/CaloTopology"/>
<use name="Geometry/CaloGeometry"/>
<use name="CondFormats/EgammaObjects"/>
<use name="CondFormats/DataRecord"/>
<use name="CondFormats/EcalObjects"/>
Expand All @@ -22,6 +23,8 @@
<use name="PhysicsTools/JetMCUtils"/>
<use name="CommonTools/Utils"/>
<use name="CommonTools/BaseParticlePropagator"/>
<use name="TrackPropagation/RungeKutta"/>
<use name="RecoLocalCalo/HGCalRecAlgos"/>
<use name="roottmva"/>
<use name="PhysicsTools/TensorFlow"/>
<export>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

#include "FWCore/Framework/interface/EventSetup.h"
#include "DataFormats/Candidate/interface/Candidate.h"
#include "RecoLocalCalo/HGCalRecAlgos/interface/RecHitTools.h"

class MagneticField;

class PositionAtECalEntranceComputer {
public:
Expand All @@ -24,10 +27,14 @@ class PositionAtECalEntranceComputer {
void beginEvent(const edm::EventSetup&);

//To do: it seems to more practical to put this to the ES
reco::Candidate::Point operator()(const reco::Candidate* particle, bool& success) const;
reco::Candidate::Point operator()(const reco::Candidate* particle, bool& success, bool isPhase2 = false) const;

private:
double bField_z_;
MagneticField const* bField_;
hgcal::RecHitTools recHitTools_;
float hgcalFace_z_;
static constexpr float ecalBarrelEndcapEtaBorder_ = 1.479;
};

#endif // RecoTauTag_RecoTau_PositionAtECalEntranceComputer_h
125 changes: 109 additions & 16 deletions RecoTauTag/RecoTau/src/PositionAtECalEntranceComputer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,130 @@

#include "MagneticField/Engine/interface/MagneticField.h"
#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
#include "Geometry/CaloGeometry/interface/CaloGeometry.h"
#include "Geometry/Records/interface/CaloGeometryRecord.h"
#include "CommonTools/BaseParticlePropagator/interface/BaseParticlePropagator.h"
#include "DataFormats/GeometrySurface/interface/Plane.h"
#include "TrackPropagation/RungeKutta/interface/defaultRKPropagator.h"

#include <cassert>

//HGCal helper classes
//MB: looks be copy of HGCal utils: L1Trigger/L1THGCalUtilities/plugins/ntuples/HGCalTriggerNtupleGen.cc
namespace HGCal_helpers {
class SimpleTrackPropagator {
public:
SimpleTrackPropagator(MagneticField const* f) : field_(f), prod_(field_, alongMomentum, 5.e-5), absz_target_(0) {
ROOT::Math::SMatrixIdentity id;
AlgebraicSymMatrix55 C(id);
C *= 0.001;
err_ = CurvilinearTrajectoryError(C);
}
void setPropagationTargetZ(const float& z);

bool propagate(const double& px,
const double& py,
const double& pz,
const double& x,
const double& y,
const double& z,
const float& charge,
reco::Candidate::Point& output) const;

private:
SimpleTrackPropagator() : field_(nullptr), prod_(field_, alongMomentum, 5e-5), absz_target_(0) {}
const RKPropagatorInS& RKProp() const { return prod_.propagator; }
Plane::PlanePointer targetPlaneForward_, targetPlaneBackward_;
MagneticField const* field_;
CurvilinearTrajectoryError err_;
defaultRKPropagator::Product prod_;
float absz_target_;
};
void SimpleTrackPropagator::setPropagationTargetZ(const float& z) {
targetPlaneForward_ = Plane::build(Plane::PositionType(0, 0, std::abs(z)), Plane::RotationType());
targetPlaneBackward_ = Plane::build(Plane::PositionType(0, 0, -std::abs(z)), Plane::RotationType());
absz_target_ = std::abs(z);
}
bool SimpleTrackPropagator::propagate(const double& px,
const double& py,
const double& pz,
const double& x,
const double& y,
const double& z,
const float& charge,
reco::Candidate::Point& output) const {
typedef TrajectoryStateOnSurface TSOS;
GlobalPoint startingPosition(x, y, z);
GlobalVector startingMomentum(px, py, pz);
Plane::PlanePointer startingPlane = Plane::build(Plane::PositionType(x, y, z), Plane::RotationType());
TSOS startingStateP(
GlobalTrajectoryParameters(startingPosition, startingMomentum, charge, field_), err_, *startingPlane);
TSOS trackStateP;
if (pz > 0) {
trackStateP = RKProp().propagate(startingStateP, *targetPlaneForward_);
} else {
trackStateP = RKProp().propagate(startingStateP, *targetPlaneBackward_);
}
if (trackStateP.isValid()) {
output.SetXYZ(
trackStateP.globalPosition().x(), trackStateP.globalPosition().y(), trackStateP.globalPosition().z());
return true;
}
output.SetXYZ(0, 0, 0);
return false;
}
} // namespace HGCal_helpers

PositionAtECalEntranceComputer::PositionAtECalEntranceComputer() : bField_z_(-1.) {}

PositionAtECalEntranceComputer::~PositionAtECalEntranceComputer() {}

void PositionAtECalEntranceComputer::beginEvent(const edm::EventSetup& es) {
edm::ESHandle<MagneticField> bField;
es.get<IdealMagneticFieldRecord>().get(bField);
bField_z_ = bField->inTesla(GlobalPoint(0., 0., 0.)).z();
edm::ESHandle<MagneticField> bFieldH;
es.get<IdealMagneticFieldRecord>().get(bFieldH);
bField_z_ = bFieldH->inTesla(GlobalPoint(0., 0., 0.)).z();
bField_ = &(*bFieldH);
edm::ESHandle<CaloGeometry> caloGeoH;
es.get<CaloGeometryRecord>().get(caloGeoH);
recHitTools_.setGeometry(*caloGeoH);
hgcalFace_z_ = recHitTools_.getPositionLayer(1).z(); // HGCal 1st layer
}

reco::Candidate::Point PositionAtECalEntranceComputer::operator()(const reco::Candidate* particle,
bool& success) const {
bool& success,
bool isPhase2) const {
assert(bField_z_ != -1.);
BaseParticlePropagator propagator = BaseParticlePropagator(
RawParticle(particle->p4(),
math::XYZTLorentzVector(particle->vertex().x(), particle->vertex().y(), particle->vertex().z(), 0.),
particle->charge()),
0.,
0.,
bField_z_);
propagator.propagateToEcalEntrance(false);
reco::Candidate::Point position;
if (propagator.getSuccess() != 0) {
position = propagator.particle().vertex().Vect();
success = true;
} else {
if (!isPhase2 || std::abs(particle->eta()) < ecalBarrelEndcapEtaBorder_) { // ECal
BaseParticlePropagator propagator = BaseParticlePropagator(
RawParticle(particle->p4(),
math::XYZTLorentzVector(particle->vertex().x(), particle->vertex().y(), particle->vertex().z(), 0.),
particle->charge()),
0.,
0.,
bField_z_);
propagator.propagateToEcalEntrance(false);
if (propagator.getSuccess() != 0) {
position = propagator.particle().vertex().Vect();
success = true;
} else {
success = false;
}
} else { // HGCal
success = false;
if (std::abs(particle->vertex().z()) >= hgcalFace_z_)
return position;

HGCal_helpers::SimpleTrackPropagator propagator(bField_);
propagator.setPropagationTargetZ(hgcalFace_z_);
success = propagator.propagate(particle->px(),
particle->py(),
particle->pz(),
particle->vertex().x(),
particle->vertex().y(),
particle->vertex().z(),
particle->charge(),
position);
}
return position;
}

0 comments on commit 09eab8d

Please sign in to comment.