1 |
#include "PhysicsTools/LeptonIsolation/interface/PropagateToCal.h"
|
2 |
|
3 |
PropagateToCal::PropagateToCal(const edm::ParameterSet & cfg)
|
4 |
{
|
5 |
theIgnoreMaterial_ = cfg.getParameter<bool>( "IgnoreMaterial" );
|
6 |
radius_ = cfg.getParameter<double>("CalRadius");
|
7 |
maxZ_ = cfg.getParameter<double>("CalMaxZ");
|
8 |
minZ_ = cfg.getParameter<double>("CalMinZ");
|
9 |
|
10 |
if (maxZ_ < minZ_) {
|
11 |
throw cms::Exception("BadConfig") << "PropagateToCal: CalMaxZ (" << maxZ_
|
12 |
<< ") smaller than CalMinZ (" << minZ_ << ").";
|
13 |
}
|
14 |
}
|
15 |
|
16 |
PropagateToCal::~PropagateToCal()
|
17 |
{
|
18 |
}
|
19 |
|
20 |
|
21 |
bool PropagateToCal::propagate(const GlobalPoint& vertex,
|
22 |
GlobalVector& Cand, int charge, const edm::EventSetup &setup) const
|
23 |
{
|
24 |
///the code is inspired by Gero's CosmicGenFilterHelix class:
|
25 |
bool result = true;
|
26 |
const MagneticField * field = getMagneticField(setup);
|
27 |
typedef std::pair<TrajectoryStateOnSurface, double> TsosPath;
|
28 |
|
29 |
SteppingHelixPropagator propagator(field); // should we somehow take it from ESetup???
|
30 |
propagator.setMaterialMode(theIgnoreMaterial_); // no material effects if set to true
|
31 |
propagator.setNoErrorPropagation(true);
|
32 |
|
33 |
const FreeTrajectoryState fts(GlobalTrajectoryParameters(vertex, Cand, charge, field));
|
34 |
const Surface::RotationType dummyRot;
|
35 |
|
36 |
/// target cylinder, around z-axis
|
37 |
Cylinder::ConstCylinderPointer theTargetCylinder =
|
38 |
Cylinder::build(Surface::PositionType(0.,0.,0.), dummyRot, radius_);
|
39 |
|
40 |
/// plane closing cylinder at 'negative' side
|
41 |
Plane::ConstPlanePointer theTargetPlaneMin =
|
42 |
Plane::build(Surface::PositionType(0.,0.,minZ_), dummyRot);
|
43 |
|
44 |
/// plane closing cylinder at 'positive' side
|
45 |
Plane::ConstPlanePointer theTargetPlaneMax =
|
46 |
Plane::build(Surface::PositionType(0.,0.,maxZ_), dummyRot);
|
47 |
|
48 |
TsosPath aTsosPath(propagator.propagateWithPath(fts, *theTargetCylinder));
|
49 |
if (!aTsosPath.first.isValid()) {
|
50 |
result = false;
|
51 |
} else if (aTsosPath.first.globalPosition().z() < theTargetPlaneMin->position().z()) {
|
52 |
// If on cylinder, but outside minimum z, try minimum z-plane:
|
53 |
// (Would it be possible to miss rdius on plane, but reach cylinder afterwards in z-range?
|
54 |
// No, at least not in B-field parallel to z-axis which is cylinder axis.)
|
55 |
aTsosPath = propagator.propagateWithPath(fts, *theTargetPlaneMin);
|
56 |
if (!aTsosPath.first.isValid()
|
57 |
|| aTsosPath.first.globalPosition().perp() > theTargetCylinder->radius()) {
|
58 |
result = false;
|
59 |
}
|
60 |
} else if (aTsosPath.first.globalPosition().z() > theTargetPlaneMax->position().z()) {
|
61 |
// Analog for outside maximum z:
|
62 |
aTsosPath = propagator.propagateWithPath(fts, *theTargetPlaneMax);
|
63 |
if (!aTsosPath.first.isValid()
|
64 |
|| aTsosPath.first.globalPosition().perp() > theTargetCylinder->radius()) {
|
65 |
result = false;
|
66 |
}
|
67 |
}
|
68 |
///The result is the vector connecting the extrapolation endPoint on the Calorimeter surface and
|
69 |
///the origin of the coordinate system, point (0,0,0).
|
70 |
if (result) {
|
71 |
Cand = GlobalVector(aTsosPath.first.globalPosition().x(),
|
72 |
aTsosPath.first.globalPosition().y(),
|
73 |
aTsosPath.first.globalPosition().z() );
|
74 |
}
|
75 |
return result;///Successfully propagated to the calorimeter or not
|
76 |
}
|
77 |
|
78 |
|
79 |
const MagneticField* PropagateToCal::getMagneticField(const edm::EventSetup &setup) const
|
80 |
{
|
81 |
edm::ESHandle<MagneticField> fieldHandle;
|
82 |
setup.get<IdealMagneticFieldRecord>().get(fieldHandle);
|
83 |
|
84 |
return fieldHandle.product();
|
85 |
}
|