-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
CalibrationTrackSelectorFromDetIdList.cc
169 lines (133 loc) · 6.33 KB
/
CalibrationTrackSelectorFromDetIdList.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
// -*- C++ -*-
//
// Package: CalibrationTrackSelectorFromDetIdList
// Class: CalibrationTrackSelectorFromDetIdList
//
/**\class CalibrationTrackSelectorFromDetIdList CalibrationTrackSelectorFromDetIdList.cc Calibration/TkAlCaRecoProducers/plugins/CalibrationTrackSelectorFromDetIdList.cc
Description: Selects tracks that have at leaast one valid hit on a given set of Tracker DetIds
*/
//
// Original Author: Marco Musich
// Created: Wed Aug 22 09:17:01 CEST 2018
//
//
// system include files
#include <memory>
// user include files
#include "CommonTools/UtilAlgos/interface/DetIdSelector.h"
#include "DataFormats/TrackCandidate/interface/TrackCandidateCollection.h"
#include "DataFormats/TrackReco/interface/Track.h"
#include "DataFormats/TrackReco/interface/TrackFwd.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
#include "TrackingTools/Records/interface/TransientRecHitRecord.h"
#include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
#include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
#include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHitBuilder.h"
//
// class decleration
//
class dso_hidden CalibrationTrackSelectorFromDetIdList final : public edm::stream::EDProducer<> {
public:
explicit CalibrationTrackSelectorFromDetIdList(const edm::ParameterSet&);
~CalibrationTrackSelectorFromDetIdList() override;
private:
void beginRun(edm::Run const& run, const edm::EventSetup&) override;
void produce(edm::Event&, const edm::EventSetup&) override;
edm::EDGetTokenT<reco::TrackCollection> m_label;
TrackCandidate makeCandidate(const reco::Track &tk, std::vector<std::unique_ptr<TrackingRecHit> >::iterator hitsBegin, std::vector<std::unique_ptr<TrackingRecHit> >::iterator hitsEnd);
std::vector<DetIdSelector> detidsels_;
bool m_verbose;
edm::ESHandle<TrackerGeometry> theGeometry;
edm::ESHandle<MagneticField> theMagField;
};
CalibrationTrackSelectorFromDetIdList::CalibrationTrackSelectorFromDetIdList(const edm::ParameterSet& iConfig): detidsels_() {
std::vector<edm::ParameterSet> selconfigs = iConfig.getParameter<std::vector<edm::ParameterSet> >("selections");
for(std::vector<edm::ParameterSet>::const_iterator selconfig=selconfigs.begin();selconfig!=selconfigs.end();++selconfig) {
DetIdSelector selection(*selconfig);
detidsels_.push_back(selection);
}
m_verbose = iConfig.getUntrackedParameter<bool>("verbose");
m_label = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("Input"));
produces<TrackCandidateCollection>();
}
CalibrationTrackSelectorFromDetIdList::~CalibrationTrackSelectorFromDetIdList() {}
//
// member functions
//
// ------------ method called to produce the data ------------
void CalibrationTrackSelectorFromDetIdList::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
using namespace edm;
using namespace std;
edm::Handle<std::vector<reco::Track> > tracks;
iEvent.getByToken(m_label, tracks);
auto output = std::make_unique<TrackCandidateCollection>();
// loop on tracks
for (std::vector<reco::Track>::const_iterator ittrk = tracks->begin(), edtrk = tracks->end(); ittrk != edtrk; ++ittrk) {
const reco::Track *trk = &(*ittrk);
std::vector<std::unique_ptr<TrackingRecHit> > hits;
bool saveTrack(false);
for (trackingRecHit_iterator ith = trk->recHitsBegin(), edh = trk->recHitsEnd(); ith != edh; ++ith) {
const TrackingRecHit * hit = (*ith); // ith is an iterator on edm::Ref to rechit
DetId detid = hit->geographicalId();
for (const auto &detidsel : detidsels_){
if(detidsel.isSelected(detid)) {
LogDebug("CalibrationTrackSelectorFromDetIdList") << "Selected by selection " << detid;
saveTrack=true;
break;
}
}
// here there will be the selection
hits.emplace_back(hit->clone());
}
if(saveTrack){
output->push_back( makeCandidate ( *ittrk, hits.begin(), hits.end() ) );
}
}
iEvent.put(std::move(output));
}
TrackCandidate
CalibrationTrackSelectorFromDetIdList::makeCandidate(const reco::Track &tk, std::vector<std::unique_ptr<TrackingRecHit> >::iterator hitsBegin, std::vector<std::unique_ptr<TrackingRecHit> >::iterator hitsEnd) {
PropagationDirection pdir = tk.seedDirection();
PTrajectoryStateOnDet state;
if ( pdir == anyDirection ) throw cms::Exception("UnimplementedFeature") << "Cannot work with tracks that have 'anyDirecton' \n";
if ( (pdir == alongMomentum) == ( (tk.outerPosition()-tk.innerPosition()).Dot(tk.momentum()) >= 0 ) ) {
// use inner state
TrajectoryStateOnSurface originalTsosIn(trajectoryStateTransform::innerStateOnSurface(tk, *theGeometry, &*theMagField));
state = trajectoryStateTransform::persistentState( originalTsosIn, DetId(tk.innerDetId()) );
} else {
// use outer state
TrajectoryStateOnSurface originalTsosOut(trajectoryStateTransform::outerStateOnSurface(tk, *theGeometry, &*theMagField));
state = trajectoryStateTransform::persistentState( originalTsosOut, DetId(tk.outerDetId()) );
}
TrajectorySeed seed(state, TrackCandidate::RecHitContainer(), pdir);
TrackCandidate::RecHitContainer ownHits;
ownHits.reserve(hitsEnd - hitsBegin);
for ( ; hitsBegin != hitsEnd; ++hitsBegin) {
ownHits.push_back( hitsBegin->release() );
}
TrackCandidate cand(ownHits, seed, state, tk.seedRef());
return cand;
}
void CalibrationTrackSelectorFromDetIdList::beginRun(edm::Run const& run, const edm::EventSetup& iSetup) {
iSetup.get<TrackerDigiGeometryRecord>().get(theGeometry);
iSetup.get<IdealMagneticFieldRecord>().get(theMagField);
if(m_verbose){
for (const auto &detidsel : detidsels_){
auto theDetIds = theGeometry.product()->detIds();
for(const auto &theDet : theDetIds){
if(detidsel.isSelected(theDet)) {
LogDebug("CalibrationTrackSelectorFromDetIdList") << "detid: " << theDet.rawId() << " is taken" << std::endl;
}
}
}
}
}
//define this as a plug-in
DEFINE_FWK_MODULE(CalibrationTrackSelectorFromDetIdList);