CMS 3D CMS Logo

CalibrationTrackSelectorFromDetIdList.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: CalibrationTrackSelectorFromDetIdList
4 // Class: CalibrationTrackSelectorFromDetIdList
5 //
12 //
13 // Original Author: Marco Musich
14 // Created: Wed Aug 22 09:17:01 CEST 2018
15 //
16 //
17 
18 // system include files
19 #include <memory>
20 
21 // user include files
38 
39 //
40 // class decleration
41 //
42 
44 public:
47 
48 private:
49  void beginRun(edm::Run const &run, const edm::EventSetup &) override;
50  void produce(edm::Event &, const edm::EventSetup &) override;
52  TrackCandidate makeCandidate(const reco::Track &tk,
53  std::vector<const TrackingRecHit *>::iterator hitsBegin,
54  std::vector<const TrackingRecHit *>::iterator hitsEnd);
55 
56  std::vector<DetIdSelector> detidsels_;
57  bool m_verbose;
58 
61 };
62 
64  : detidsels_() {
65  std::vector<edm::ParameterSet> selconfigs = iConfig.getParameter<std::vector<edm::ParameterSet>>("selections");
66 
67  for (std::vector<edm::ParameterSet>::const_iterator selconfig = selconfigs.begin(); selconfig != selconfigs.end();
68  ++selconfig) {
69  DetIdSelector selection(*selconfig);
70  detidsels_.push_back(selection);
71  }
72 
73  m_verbose = iConfig.getUntrackedParameter<bool>("verbose");
74  m_label = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("Input"));
75  produces<TrackCandidateCollection>();
76 }
77 
79 
80 //
81 // member functions
82 //
83 
84 // ------------ method called to produce the data ------------
86  using namespace edm;
87  using namespace std;
88 
89  edm::Handle<std::vector<reco::Track>> trackCollectionHandle;
90  iEvent.getByToken(m_label, trackCollectionHandle);
91  auto const &tracks = *trackCollectionHandle;
92 
93  auto output = std::make_unique<TrackCandidateCollection>();
94 
95  // loop on tracks
96  for (auto &trk : tracks) {
97  std::vector<const TrackingRecHit *> hits;
98 
99  bool saveTrack(false);
100 
101  for (auto const &hit : trk.recHits()) {
102  DetId detid = hit->geographicalId();
103 
104  for (const auto &detidsel : detidsels_) {
105  if (detidsel.isSelected(detid)) {
106  LogDebug("CalibrationTrackSelectorFromDetIdList") << "Selected by selection " << detid;
107  saveTrack = true;
108  break;
109  }
110  }
111 
112  // here there will be the selection
113  hits.emplace_back(hit);
114  }
115 
116  if (saveTrack) {
117  output->push_back(makeCandidate(trk, hits.begin(), hits.end()));
118  }
119  }
120  iEvent.put(std::move(output));
121 }
122 
124  const reco::Track &tk,
125  std::vector<const TrackingRecHit *>::iterator hitsBegin,
126  std::vector<const TrackingRecHit *>::iterator hitsEnd) {
128  PTrajectoryStateOnDet state;
129  if (pdir == anyDirection)
130  throw cms::Exception("UnimplementedFeature") << "Cannot work with tracks that have 'anyDirecton' \n";
131 
132  if ((pdir == alongMomentum) == ((tk.outerPosition() - tk.innerPosition()).Dot(tk.momentum()) >= 0)) {
133  // use inner state
134  TrajectoryStateOnSurface originalTsosIn(
136  state = trajectoryStateTransform::persistentState(originalTsosIn, DetId(tk.innerDetId()));
137  } else {
138  // use outer state
139  TrajectoryStateOnSurface originalTsosOut(
141  state = trajectoryStateTransform::persistentState(originalTsosOut, DetId(tk.outerDetId()));
142  }
145  ownHits.reserve(hitsEnd - hitsBegin);
146  for (; hitsBegin != hitsEnd; ++hitsBegin) {
147  ownHits.push_back((*hitsBegin)->clone());
148  }
149 
150  TrackCandidate cand(ownHits, seed, state, tk.seedRef());
151 
152  return cand;
153 }
154 
158 
159  if (m_verbose) {
160  for (const auto &detidsel : detidsels_) {
161  auto theDetIds = theGeometry.product()->detIds();
162  for (const auto &theDet : theDetIds) {
163  if (detidsel.isSelected(theDet)) {
164  LogDebug("CalibrationTrackSelectorFromDetIdList") << "detid: " << theDet.rawId() << " is taken" << std::endl;
165  }
166  }
167  }
168  }
169 }
170 
171 // define this as a plug-in
#define LogDebug(id)
const edm::RefToBase< TrajectorySeed > & seedRef() const
Definition: Track.h:218
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
TrajectoryStateOnSurface outerStateOnSurface(const reco::Track &tk, const TrackingGeometry &geom, const MagneticField *field, bool withErr=true)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
selection
main part
Definition: corrVsCorr.py:100
edm::EDGetTokenT< reco::TrackCollection > m_label
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
PropagationDirection
const Vector & momentum() const
track momentum vector
Definition: TrackBase.h:714
const math::XYZPoint & outerPosition() const
position of the outermost hit
Definition: Track.h:67
const math::XYZPoint & innerPosition() const
position of the innermost hit
Definition: Track.h:57
void push_back(D *&d)
Definition: OwnVector.h:290
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
TrackCandidate makeCandidate(const reco::Track &tk, std::vector< const TrackingRecHit * >::iterator hitsBegin, std::vector< const TrackingRecHit * >::iterator hitsEnd)
unsigned int outerDetId() const
DetId of the detector on which surface the outermost state is located.
Definition: Track.h:96
const DetIdContainer & detIds() const override
Returm a vector of all GeomDet DetIds (including those of GeomDetUnits)
void produce(edm::Event &, const edm::EventSetup &) override
#define dso_hidden
Definition: Visibility.h:12
Definition: DetId.h:18
const PropagationDirection & seedDirection() const
direction of how the hits were sorted in the original seed
Definition: Track.h:209
void beginRun(edm::Run const &run, const edm::EventSetup &) override
HLT enums.
T get() const
Definition: EventSetup.h:71
unsigned int innerDetId() const
DetId of the detector on which surface the innermost state is located.
Definition: Track.h:101
T const * product() const
Definition: ESHandle.h:86
def move(src, dest)
Definition: eostools.py:511
void reserve(size_t)
Definition: OwnVector.h:284
Definition: Run.h:45
TrajectoryStateOnSurface innerStateOnSurface(const reco::Track &tk, const TrackingGeometry &geom, const MagneticField *field, bool withErr=true)