-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
TrackRefitter.cc
149 lines (131 loc) · 7.28 KB
/
TrackRefitter.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include "RecoTracker/TrackProducer/plugins/TrackRefitter.h"
// system include files
#include <memory>
// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "TrackingTools/PatternTools/interface/Trajectory.h"
#include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
TrackRefitter::TrackRefitter(const edm::ParameterSet& iConfig):
KfTrackProducerBase(iConfig.getParameter<bool>("TrajectoryInEvent"),
iConfig.getParameter<bool>("useHitsSplitting")),
theAlgo(iConfig)
{
setConf(iConfig);
setSrc( consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>( "src" )),
consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>( "beamSpot" )),
consumes<MeasurementTrackerEvent>(iConfig.getParameter<edm::InputTag>( "MeasurementTrackerEvent") ));
setAlias( iConfig.getParameter<std::string>( "@module_label" ) );
std::string constraint_str = iConfig.getParameter<std::string>( "constraint" );
edm::InputTag trkconstrcoll = iConfig.getParameter<edm::InputTag>( "srcConstr" );
if (constraint_str == "") constraint_ = none;
else if (constraint_str == "momentum") { constraint_ = momentum; trkconstrcoll_ = consumes<TrackMomConstraintAssociationCollection>(trkconstrcoll); }
else if (constraint_str == "vertex") { constraint_ = vertex; trkconstrcoll_ = consumes<TrackVtxConstraintAssociationCollection>(trkconstrcoll); }
else if (constraint_str == "trackParameters") { constraint_ = trackParameters; trkconstrcoll_ = consumes<TrackParamConstraintAssociationCollection>(trkconstrcoll); }
else {
edm::LogError("TrackRefitter")<<"constraint: "<<constraint_str<<" not understood. Set it to 'momentum', 'vertex', 'trackParameters' or leave it empty";
throw cms::Exception("TrackRefitter") << "unknown type of contraint! Set it to 'momentum', 'vertex', 'trackParameters' or leave it empty";
}
//register your products
produces<reco::TrackCollection>().setBranchAlias( alias_ + "Tracks" );
produces<reco::TrackExtraCollection>().setBranchAlias( alias_ + "TrackExtras" );
produces<TrackingRecHitCollection>().setBranchAlias( alias_ + "RecHits" );
produces<std::vector<Trajectory> >() ;
produces<TrajTrackAssociationCollection>();
}
void TrackRefitter::produce(edm::Event& theEvent, const edm::EventSetup& setup)
{
LogDebug("TrackRefitter") << "Analyzing event number: " << theEvent.id() << "\n";
//
// create empty output collections
//
std::auto_ptr<TrackingRecHitCollection> outputRHColl (new TrackingRecHitCollection);
std::auto_ptr<reco::TrackCollection> outputTColl(new reco::TrackCollection);
std::auto_ptr<reco::TrackExtraCollection> outputTEColl(new reco::TrackExtraCollection);
std::auto_ptr<std::vector<Trajectory> > outputTrajectoryColl(new std::vector<Trajectory>);
//
//declare and get stuff to be retrieved from ES
//
edm::ESHandle<TrackerGeometry> theG;
edm::ESHandle<MagneticField> theMF;
edm::ESHandle<TrajectoryFitter> theFitter;
edm::ESHandle<Propagator> thePropagator;
edm::ESHandle<MeasurementTracker> theMeasTk;
edm::ESHandle<TransientTrackingRecHitBuilder> theBuilder;
getFromES(setup,theG,theMF,theFitter,thePropagator,theMeasTk,theBuilder);
//
//declare and get TrackCollection to be retrieved from the event
//
AlgoProductCollection algoResults;
reco::BeamSpot bs;
switch(constraint_){
case none :
{
edm::Handle<reco::TrackCollection> theTCollection;
getFromEvt(theEvent,theTCollection,bs);
LogDebug("TrackRefitter") << "TrackRefitter::produce(none):Number of Trajectories:" << (*theTCollection).size();
if (theTCollection.failedToGet()){
edm::LogError("TrackRefitter")<<"could not get the reco::TrackCollection."; break;}
LogDebug("TrackRefitter") << "run the algorithm" << "\n";
try {
theAlgo.runWithTrack(theG.product(), theMF.product(), *theTCollection,
theFitter.product(), thePropagator.product(),
theBuilder.product(), bs, algoResults);
}catch (cms::Exception &e){ edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithTrack." << "\n" << e << "\n"; throw; }
break;
}
case momentum :
{
edm::Handle<TrackMomConstraintAssociationCollection> theTCollectionWithConstraint;
theEvent.getByToken(trkconstrcoll_,theTCollectionWithConstraint);
edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
theEvent.getByToken(bsSrc_,recoBeamSpotHandle);
bs = *recoBeamSpotHandle;
if (theTCollectionWithConstraint.failedToGet()){
//edm::LogError("TrackRefitter")<<"could not get TrackMomConstraintAssociationCollection product.";
break;}
LogDebug("TrackRefitter") << "run the algorithm" << "\n";
try {
theAlgo.runWithMomentum(theG.product(), theMF.product(), *theTCollectionWithConstraint,
theFitter.product(), thePropagator.product(), theBuilder.product(), bs, algoResults);
}catch (cms::Exception &e){ edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithTrack." << "\n" << e << "\n"; throw; }
break;
}
case vertex :
{
edm::Handle<TrackVtxConstraintAssociationCollection> theTCollectionWithConstraint;
theEvent.getByToken(trkconstrcoll_,theTCollectionWithConstraint);
edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
theEvent.getByToken(bsSrc_,recoBeamSpotHandle);
bs = *recoBeamSpotHandle;
if (theTCollectionWithConstraint.failedToGet()){
edm::LogError("TrackRefitter")<<"could not get TrackVtxConstraintAssociationCollection product."; break;}
LogDebug("TrackRefitter") << "run the algorithm" << "\n";
try {
theAlgo.runWithVertex(theG.product(), theMF.product(), *theTCollectionWithConstraint,
theFitter.product(), thePropagator.product(), theBuilder.product(), bs, algoResults);
}catch (cms::Exception &e){ edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithTrack." << "\n" << e << "\n"; throw; }
}
case trackParameters :
{
edm::Handle<TrackParamConstraintAssociationCollection> theTCollectionWithConstraint;
theEvent.getByToken(trkconstrcoll_,theTCollectionWithConstraint);
edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
theEvent.getByToken(bsSrc_,recoBeamSpotHandle);
bs = *recoBeamSpotHandle;
if (theTCollectionWithConstraint.failedToGet()){
//edm::LogError("TrackRefitter")<<"could not get TrackParamConstraintAssociationCollection product.";
break;}
LogDebug("TrackRefitter") << "run the algorithm" << "\n";
try {
theAlgo.runWithTrackParameters(theG.product(), theMF.product(), *theTCollectionWithConstraint,
theFitter.product(), thePropagator.product(), theBuilder.product(), bs, algoResults);
}catch (cms::Exception &e){ edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithTrack." << "\n" << e << "\n"; throw; }
}
//default... there cannot be any other possibility due to the check in the ctor
}
//put everything in th event
putInEvt(theEvent, thePropagator.product(), theMeasTk.product(), outputRHColl, outputTColl, outputTEColl, outputTrajectoryColl, algoResults,theBuilder.product());
LogDebug("TrackRefitter") << "end" << "\n";
}