CMS 3D CMS Logo

CosmicRegionalSeedGenerator.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <memory>
3 #include <string>
4 
8 
10 
11 #include <TMath.h>
12 
13 using namespace std;
14 using namespace trigger;
15 using namespace reco;
16 using namespace edm;
17 
19  : magfieldToken_(iC.esConsumes()) {
20  edm::LogInfo("CosmicRegionalSeedGenerator") << "Begin Run:: Constructing CosmicRegionalSeedGenerator";
21 
22  edm::ParameterSet regionPSet = conf.getParameter<edm::ParameterSet>("RegionPSet");
23  ptMin_ = regionPSet.getParameter<double>("ptMin");
24  rVertex_ = regionPSet.getParameter<double>("rVertex");
25  zVertex_ = regionPSet.getParameter<double>("zVertex");
26  deltaEta_ = regionPSet.getParameter<double>("deltaEtaRegion");
27  deltaPhi_ = regionPSet.getParameter<double>("deltaPhiRegion");
28 
29  edm::ParameterSet toolsPSet = conf.getParameter<edm::ParameterSet>("ToolsPSet");
30  propagatorToken_ = iC.esConsumes(edm::ESInputTag("", toolsPSet.getParameter<std::string>("thePropagatorName")));
31  regionBase_ = toolsPSet.getParameter<std::string>("regionBase");
32 
33  edm::ParameterSet collectionsPSet = conf.getParameter<edm::ParameterSet>("CollectionsPSet");
34  recoMuonsCollection_ = collectionsPSet.getParameter<edm::InputTag>("recoMuonsCollection");
35  recoTrackMuonsCollection_ = collectionsPSet.getParameter<edm::InputTag>("recoTrackMuonsCollection");
36  recoL2MuonsCollection_ = collectionsPSet.getParameter<edm::InputTag>("recoL2MuonsCollection");
37 
38  edm::ParameterSet regionInJetsCheckPSet = conf.getParameter<edm::ParameterSet>("RegionInJetsCheckPSet");
39  doJetsExclusionCheck_ = regionInJetsCheckPSet.getParameter<bool>("doJetsExclusionCheck");
40  deltaRExclusionSize_ = regionInJetsCheckPSet.getParameter<double>("deltaRExclusionSize");
41  jetsPtMin_ = regionInJetsCheckPSet.getParameter<double>("jetsPtMin");
42  recoCaloJetsCollection_ = regionInJetsCheckPSet.getParameter<edm::InputTag>("recoCaloJetsCollection");
47  measurementTrackerEventToken_ = iC.consumes<MeasurementTrackerEvent>(edm::InputTag("MeasurementTrackerEvent"));
48 
49  edm::LogInfo("CosmicRegionalSeedGenerator") << "Reco muons collection: " << recoMuonsCollection_ << "\n"
50  << "Reco tracks muons collection: " << recoTrackMuonsCollection_ << "\n"
51  << "Reco L2 muons collection: " << recoL2MuonsCollection_;
52 }
53 
54 std::vector<std::unique_ptr<TrackingRegion>> CosmicRegionalSeedGenerator::regions(const edm::Event& event,
55  const edm::EventSetup& es) const {
56  std::vector<std::unique_ptr<TrackingRegion>> result;
57 
61  event.getByToken(measurementTrackerEventToken_, hmte);
62  measurementTracker = hmte.product();
63  }
64 
65  //get the propagator
66  auto const& propagator = es.getData(propagatorToken_);
67  auto const& magfield = es.getData(magfieldToken_);
68 
69  //________________________________________
70  //
71  //Seeding on Sta muon (MC && Datas)
72  //________________________________________
73 
74  if (regionBase_ == "seedOnStaMuon" || regionBase_.empty()) {
75  LogDebug("CosmicRegionalSeedGenerator") << "Seeding on stand alone muons ";
76 
77  //get collections
78  //+++++++++++++++
79 
80  //get the muon collection
82  event.getByToken(recoMuonsToken_, muonsHandle);
83  if (!muonsHandle.isValid()) {
84  edm::LogError("CollectionNotFound") << "Error::No reco muons collection (" << recoMuonsCollection_
85  << ") in the event - Please verify the name of the muon collection";
86  return result;
87  }
88 
89  LogDebug("CosmicRegionalSeedGenerator") << "Muons collection size = " << muonsHandle->size();
90 
91  //get the jet collection
92  edm::Handle<CaloJetCollection> caloJetsHandle;
93  event.getByToken(recoCaloJetsToken_, caloJetsHandle);
94 
95  //definition of the region
96  //+++++++++++++++++++++++++
97 
98  for (reco::MuonCollection::const_iterator staMuon = muonsHandle->begin(); staMuon != muonsHandle->end();
99  ++staMuon) {
100  //select sta muons
101  if (!staMuon->isStandAloneMuon()) {
102  LogDebug("CosmicRegionalSeedGenerator") << "This muon is not a stand alone muon";
103  continue;
104  }
105 
106  //bit 25 as a coverage -1.4 < eta < 1.4
107  if (abs(staMuon->standAloneMuon()->eta()) > 1.5)
108  continue;
109 
110  //debug
111  LogDebug("CosmicRegionalSeedGenerator") << "Muon stand alone found in the collection - in muons chambers: \n "
112  << "Position = " << staMuon->standAloneMuon()->outerPosition() << "\n "
113  << "Momentum = " << staMuon->standAloneMuon()->outerMomentum() << "\n "
114  << "Eta = " << staMuon->standAloneMuon()->eta() << "\n "
115  << "Phi = " << staMuon->standAloneMuon()->phi();
116 
117  //initial position, momentum, charge
118 
119  GlobalPoint initialRegionPosition(staMuon->standAloneMuon()->referencePoint().x(),
120  staMuon->standAloneMuon()->referencePoint().y(),
121  staMuon->standAloneMuon()->referencePoint().z());
122  GlobalVector initialRegionMomentum(staMuon->standAloneMuon()->momentum().x(),
123  staMuon->standAloneMuon()->momentum().y(),
124  staMuon->standAloneMuon()->momentum().z());
125  int charge = (int)staMuon->standAloneMuon()->charge();
126 
127  LogDebug("CosmicRegionalSeedGenerator") << "Initial region - Reference point of the sta muon: \n "
128  << "Position = " << initialRegionPosition << "\n "
129  << "Momentum = " << initialRegionMomentum << "\n "
130  << "Eta = " << initialRegionPosition.eta() << "\n "
131  << "Phi = " << initialRegionPosition.phi() << "\n "
132  << "Charge = " << charge;
133 
134  //propagation on the last layers of TOB
135  if (staMuon->standAloneMuon()->outerPosition().y() > 0)
136  initialRegionMomentum *= -1;
137  GlobalTrajectoryParameters glb_parameters(
138  initialRegionPosition, initialRegionMomentum, charge, propagator.magneticField());
139  FreeTrajectoryState fts(glb_parameters);
140  StateOnTrackerBound onBounds(&propagator);
141  TrajectoryStateOnSurface outer = onBounds(fts);
142 
143  if (!outer.isValid()) {
144  //edm::LogError("FailedPropagation") << "Trajectory state on surface not valid" ;
145  LogDebug("CosmicRegionalSeedGenerator") << "Trajectory state on surface not valid";
146  continue;
147  }
148 
149  //final position & momentum
150  GlobalPoint regionPosition = outer.globalPosition();
151  GlobalVector regionMom = outer.globalMomentum();
152 
153  LogDebug("CosmicRegionalSeedGenerator")
154  << "Region after propagation: \n "
155  << "Position = " << outer.globalPosition() << "\n "
156  << "Momentum = " << outer.globalMomentum() << "\n "
157  << "R = " << regionPosition.perp() << " ---- z = " << regionPosition.z() << "\n "
158  << "Eta = " << outer.globalPosition().eta() << "\n "
159  << "Phi = " << outer.globalPosition().phi();
160 
161  //step back
162  double stepBack = 1;
163  GlobalPoint center = regionPosition + stepBack * regionMom.unit();
164  GlobalVector v = stepBack * regionMom.unit();
165  LogDebug("CosmicRegionalSeedGenerator") << "Step back vector = " << v << "\n";
166 
167  //exclude region built in jets
168  if (doJetsExclusionCheck_) {
169  double delta_R_min = 1000.;
170  for (CaloJetCollection::const_iterator jet = caloJetsHandle->begin(); jet != caloJetsHandle->end(); jet++) {
171  if (jet->pt() < jetsPtMin_)
172  continue;
173 
174  double deta = center.eta() - jet->eta();
175  double dphi = fabs(center.phi() - jet->phi());
176  if (dphi > TMath::Pi())
177  dphi = 2 * TMath::Pi() - dphi;
178 
179  double delta_R = sqrt(deta * deta + dphi * dphi);
180  if (delta_R < delta_R_min)
181  delta_R_min = delta_R;
182 
183  } //end loop on jets
184 
185  if (delta_R_min < deltaRExclusionSize_) {
186  LogDebug("CosmicRegionalSeedGenerator") << "Region built too close from a jet";
187  continue;
188  }
189  } //end if doJetsExclusionCheck
190 
191  //definition of the region
192 
193  result.push_back(std::make_unique<CosmicTrackingRegion>(
194  (-1) * regionMom, center, ptMin_, rVertex_, zVertex_, deltaEta_, deltaPhi_, magfield, measurementTracker));
195 
196  LogDebug("CosmicRegionalSeedGenerator")
197  << "Final CosmicTrackingRegion \n "
198  << "Position = " << center << "\n "
199  << "Direction = " << result.back()->direction() << "\n "
200  << "Distance from the region on the layer = " << (regionPosition - center).mag() << "\n "
201  << "Eta = " << center.eta() << "\n "
202  << "Phi = " << center.phi();
203 
204  } //end loop on muons
205 
206  } //end if SeedOnStaMuon
207 
208  //________________________________________
209  //
210  //Seeding on cosmic muons (MC && Datas)
211  //________________________________________
212 
213  if (regionBase_ == "seedOnCosmicMuon") {
214  LogDebug("CosmicRegionalSeedGenerator") << "Seeding on cosmic muons tracks";
215 
216  //get collections
217  //+++++++++++++++
218 
219  //get the muon collection
220  edm::Handle<reco::TrackCollection> cosmicMuonsHandle;
221  event.getByToken(recoTrackMuonsToken_, cosmicMuonsHandle);
222  if (!cosmicMuonsHandle.isValid()) {
223  edm::LogError("CollectionNotFound")
224  << "Error::No cosmic muons collection (" << recoTrackMuonsCollection_
225  << ") in the event - Please verify the name of the muon reco track collection";
226  return result;
227  }
228 
229  LogDebug("CosmicRegionalSeedGenerator") << "Cosmic muons tracks collection size = " << cosmicMuonsHandle->size();
230 
231  //get the jet collection
232  edm::Handle<CaloJetCollection> caloJetsHandle;
233  event.getByToken(recoCaloJetsToken_, caloJetsHandle);
234 
235  //definition of the region
236  //+++++++++++++++++++++++++
237 
238  for (reco::TrackCollection::const_iterator cosmicMuon = cosmicMuonsHandle->begin();
239  cosmicMuon != cosmicMuonsHandle->end();
240  ++cosmicMuon) {
241  //bit 25 as a coverage -1.4 < eta < 1.4
242  if (abs(cosmicMuon->eta()) > 1.5)
243  continue;
244 
245  //initial position, momentum, charge
246  GlobalPoint initialRegionPosition(
247  cosmicMuon->referencePoint().x(), cosmicMuon->referencePoint().y(), cosmicMuon->referencePoint().z());
248  GlobalVector initialRegionMomentum(
249  cosmicMuon->momentum().x(), cosmicMuon->momentum().y(), cosmicMuon->momentum().z());
250  int charge = (int)cosmicMuon->charge();
251 
252  LogDebug("CosmicRegionalSeedGenerator") << "Position and momentum of the muon track in the muon chambers: \n "
253  << "x = " << cosmicMuon->outerPosition().x() << "\n "
254  << "y = " << cosmicMuon->outerPosition().y() << "\n "
255  << "y = " << cosmicMuon->pt() << "\n "
256  << "Initial region - Reference point of the cosmic muon track: \n "
257  << "Position = " << initialRegionPosition << "\n "
258  << "Momentum = " << initialRegionMomentum << "\n "
259  << "Eta = " << initialRegionPosition.eta() << "\n "
260  << "Phi = " << initialRegionPosition.phi() << "\n "
261  << "Charge = " << charge;
262 
263  //propagation on the last layers of TOB
264  if (cosmicMuon->outerPosition().y() > 0 && cosmicMuon->momentum().y() < 0)
265  initialRegionMomentum *= -1;
266  GlobalTrajectoryParameters glb_parameters(
267  initialRegionPosition, initialRegionMomentum, charge, propagator.magneticField());
268  FreeTrajectoryState fts(glb_parameters);
269  StateOnTrackerBound onBounds(&propagator);
270  TrajectoryStateOnSurface outer = onBounds(fts);
271 
272  if (!outer.isValid()) {
273  //edm::LogError("FailedPropagation") << "Trajectory state on surface not valid" ;
274  LogDebug("CosmicRegionalSeedGenerator") << "Trajectory state on surface not valid";
275  continue;
276  }
277 
278  //final position & momentum
279  GlobalPoint regionPosition = outer.globalPosition();
280  GlobalVector regionMom = outer.globalMomentum();
281 
282  LogDebug("CosmicRegionalSeedGenerator")
283  << "Region after propagation: \n "
284  << "Position = " << outer.globalPosition() << "\n "
285  << "Momentum = " << outer.globalMomentum() << "\n "
286  << "R = " << regionPosition.perp() << " ---- z = " << regionPosition.z() << "\n "
287  << "Eta = " << outer.globalPosition().eta() << "\n "
288  << "Phi = " << outer.globalPosition().phi();
289 
290  //step back
291  double stepBack = 1;
292  GlobalPoint center = regionPosition + stepBack * regionMom.unit();
293  GlobalVector v = stepBack * regionMom.unit();
294  LogDebug("CosmicRegionalSeedGenerator") << "Step back vector = " << v << "\n";
295 
296  //exclude region built in jets
297  if (doJetsExclusionCheck_) {
298  double delta_R_min = 1000.;
299  for (CaloJetCollection::const_iterator jet = caloJetsHandle->begin(); jet != caloJetsHandle->end(); jet++) {
300  if (jet->pt() < jetsPtMin_)
301  continue;
302 
303  double deta = center.eta() - jet->eta();
304  double dphi = fabs(center.phi() - jet->phi());
305  if (dphi > TMath::Pi())
306  dphi = 2 * TMath::Pi() - dphi;
307 
308  double delta_R = sqrt(deta * deta + dphi * dphi);
309  if (delta_R < delta_R_min)
310  delta_R_min = delta_R;
311 
312  } //end loop on jets
313 
314  if (delta_R_min < deltaRExclusionSize_) {
315  LogDebug("CosmicRegionalSeedGenerator") << "Region built too close from a jet";
316  continue;
317  }
318  } // end if doJetsExclusionCheck
319 
320  //definition of the region
321  result.push_back(std::make_unique<CosmicTrackingRegion>(
322  (-1) * regionMom, center, ptMin_, rVertex_, zVertex_, deltaEta_, deltaPhi_, magfield, measurementTracker));
323 
324  LogDebug("CosmicRegionalSeedGenerator")
325  << "Final CosmicTrackingRegion \n "
326  << "Position = " << center << "\n "
327  << "Direction = " << result.back()->direction() << "\n "
328  << "Distance from the region on the layer = " << (regionPosition - center).mag() << "\n "
329  << "Eta = " << center.eta() << "\n "
330  << "Phi = " << center.phi();
331 
332  } //end loop on muons
333 
334  } //end if SeedOnCosmicMuon
335 
336  //________________________________________
337  //
338  //Seeding on L2 muons (MC && Datas)
339  //________________________________________
340 
341  if (regionBase_ == "seedOnL2Muon") {
342  LogDebug("CosmicRegionalSeedGenerator") << "Seeding on L2 muons";
343 
344  //get collections
345  //+++++++++++++++
346 
347  //get the muon collection
349  event.getByToken(recoL2MuonsToken_, L2MuonsHandle);
350 
351  if (!L2MuonsHandle.isValid()) {
352  edm::LogError("CollectionNotFound") << "Error::No L2 muons collection (" << recoL2MuonsCollection_
353  << ") in the event - Please verify the name of the L2 muon collection";
354  return result;
355  }
356 
357  LogDebug("CosmicRegionalSeedGenerator") << "L2 muons collection size = " << L2MuonsHandle->size();
358 
359  //definition of the region
360  //+++++++++++++++++++++++++
361 
362  for (reco::RecoChargedCandidateCollection::const_iterator L2Muon = L2MuonsHandle->begin();
363  L2Muon != L2MuonsHandle->end();
364  ++L2Muon) {
365  reco::TrackRef tkL2Muon = L2Muon->get<reco::TrackRef>();
366 
367  //bit 25 as a coverage -1.4 < eta < 1.4
368  if (abs(tkL2Muon->eta()) > 1.5)
369  continue;
370 
371  //initial position, momentum, charge
372  GlobalPoint initialRegionPosition(
373  tkL2Muon->referencePoint().x(), tkL2Muon->referencePoint().y(), tkL2Muon->referencePoint().z());
374  GlobalVector initialRegionMomentum(tkL2Muon->momentum().x(), tkL2Muon->momentum().y(), tkL2Muon->momentum().z());
375  int charge = (int)tkL2Muon->charge();
376 
377  LogDebug("CosmicRegionalSeedGenerator") << "Position and momentum of the L2 muon track in the muon chambers: \n "
378  << "x = " << tkL2Muon->outerPosition().x() << "\n "
379  << "y = " << tkL2Muon->outerPosition().y() << "\n "
380  << "y = " << tkL2Muon->pt() << "\n "
381  << "Initial region - Reference point of the L2 muon track: \n "
382  << "Position = " << initialRegionPosition << "\n "
383  << "Momentum = " << initialRegionMomentum << "\n "
384  << "Eta = " << initialRegionPosition.eta() << "\n "
385  << "Phi = " << initialRegionPosition.phi() << "\n "
386  << "Charge = " << charge;
387 
388  //seeding only in the bottom
389  if (tkL2Muon->outerPosition().y() > 0) {
390  LogDebug("CosmicRegionalSeedGenerator") << "L2 muon in the TOP --- Region not created";
391  return result;
392  }
393 
394  GlobalTrajectoryParameters glb_parameters(
395  initialRegionPosition, initialRegionMomentum, charge, propagator.magneticField());
396  FreeTrajectoryState fts(glb_parameters);
397  StateOnTrackerBound onBounds(&propagator);
398  TrajectoryStateOnSurface outer = onBounds(fts);
399 
400  if (!outer.isValid()) {
401  //edm::LogError("FailedPropagation") << "Trajectory state on surface not valid" ;
402  LogDebug("CosmicRegionalSeedGenerator") << "Trajectory state on surface not valid";
403  continue;
404  }
405 
406  //final position & momentum
407  GlobalPoint regionPosition = outer.globalPosition();
408  GlobalVector regionMom = outer.globalMomentum();
409 
410  LogDebug("CosmicRegionalSeedGenerator")
411  << "Region after propagation: \n "
412  << "Position = " << outer.globalPosition() << "\n "
413  << "Momentum = " << outer.globalMomentum() << "\n "
414  << "R = " << regionPosition.perp() << " ---- z = " << regionPosition.z() << "\n "
415  << "Eta = " << outer.globalPosition().eta() << "\n "
416  << "Phi = " << outer.globalPosition().phi();
417 
418  //step back
419  double stepBack = 1;
420  GlobalPoint center = regionPosition + stepBack * regionMom.unit();
421  GlobalVector v = stepBack * regionMom.unit();
422  LogDebug("CosmicRegionalSeedGenerator") << "Step back vector = " << v << "\n";
423 
424  //definition of the region
425  result.push_back(std::make_unique<CosmicTrackingRegion>(
426  (-1) * regionMom, center, ptMin_, rVertex_, zVertex_, deltaEta_, deltaPhi_, magfield, measurementTracker));
427 
428  LogDebug("CosmicRegionalSeedGenerator")
429  << "Final L2TrackingRegion \n "
430  << "Position = " << center << "\n "
431  << "Direction = " << result.back()->direction() << "\n "
432  << "Distance from the region on the layer = " << (regionPosition - center).mag() << "\n "
433  << "Eta = " << center.eta() << "\n "
434  << "Phi = " << center.phi();
435 
436  } //end loop on muons
437 
438  } //end if SeedOnL2Muon
439 
440  return result;
441 }
edm::EDGetTokenT< reco::TrackCollection > recoTrackMuonsToken_
const double Pi
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
T perp() const
Definition: PV3DBase.h:69
edm::EDGetTokenT< reco::CaloJetCollection > recoCaloJetsToken_
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
T z() const
Definition: PV3DBase.h:61
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
T eta() const
Definition: PV3DBase.h:73
T const * product() const
Definition: Handle.h:70
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:98
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magfieldToken_
Log< level::Error, false > LogError
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
std::vector< std::unique_ptr< TrackingRegion > > regions(const edm::Event &event, const edm::EventSetup &es) const override
edm::ESGetToken< Propagator, TrackingComponentsRecord > propagatorToken_
T sqrt(T t)
Definition: SSEVec.h:23
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::EDGetTokenT< reco::MuonCollection > recoMuonsToken_
double delta_R(double eta1, double phi1, double eta2, double phi2)
Definition: AnglesUtil.h:106
edm::EDGetTokenT< MeasurementTrackerEvent > measurementTrackerEventToken_
Log< level::Info, false > LogInfo
std::vector< RecoChargedCandidate > RecoChargedCandidateCollection
collectin of RecoChargedCandidate objects
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
bool isValid() const
Definition: HandleBase.h:70
fixed size matrix
HLT enums.
Vector3DBase unit() const
Definition: Vector3DBase.h:54
edm::EDGetTokenT< reco::RecoChargedCandidateCollection > recoL2MuonsToken_
CosmicRegionalSeedGenerator(const edm::ParameterSet &conf, edm::ConsumesCollector &&iC)
Definition: event.py:1
std::vector< CaloJet > CaloJetCollection
collection of CaloJet objects
#define LogDebug(id)