CMS 3D CMS Logo

ConvertedPhotonProducer.cc
Go to the documentation of this file.
1 
40 
41 #include <vector>
42 
44 public:
46 
47  void beginRun(edm::Run const&, const edm::EventSetup& es) final;
48  void produce(edm::Event& evt, const edm::EventSetup& es) override;
49 
50 private:
51  void buildCollections(
52  edm::EventSetup const& es,
53  const edm::Handle<edm::View<reco::CaloCluster> >& scHandle,
54  const edm::Handle<edm::View<reco::CaloCluster> >& bcHandle,
56  const edm::Handle<reco::TrackCollection>& trkHandle,
57  std::map<std::vector<reco::TransientTrack>, reco::CaloClusterPtr, CompareTwoTracksVectors>& allPairs,
58  reco::ConversionCollection& outputConvPhotonCollection);
61  reco::ConversionCollection& outputCollection);
62 
64  reco::CaloClusterPtr const& sc);
65 
66  float calculateMinApproachDistance(const reco::TrackRef& track1, const reco::TrackRef& track2);
67  void getCircleCenter(const reco::TrackRef& tk, double r, double& x0, double& y0);
68 
71 
74 
76 
77  // Register the product
80 
86 
89 
93 
97 
99  double maxHOverE_;
100  double minSCEt_;
103  double deltaCotCut_;
107 
110 
112 
114 };
115 
118 
120  : conversionOITrackProducer_{consumes(config.getParameter<std::string>("conversionOITrackProducer"))},
121  conversionIOTrackProducer_{consumes(config.getParameter<std::string>("conversionIOTrackProducer"))},
122  outInTrackSCAssociationCollection_{consumes({config.getParameter<std::string>("conversionOITrackProducer"),
123  config.getParameter<std::string>("outInTrackSCAssociation")})},
124  inOutTrackSCAssociationCollection_{consumes({config.getParameter<std::string>("conversionIOTrackProducer"),
125  config.getParameter<std::string>("inOutTrackSCAssociation")})},
126 
127  generalTrackProducer_{consumes(config.getParameter<edm::InputTag>("generalTracksSrc"))},
128  convertedPhotonCollectionPutToken_{
129  produces<reco::ConversionCollection>(config.getParameter<std::string>("convertedPhotonCollection"))},
130  cleanedConvertedPhotonCollectionPutToken_{
131  produces<reco::ConversionCollection>(config.getParameter<std::string>("cleanedConvertedPhotonCollection"))},
132 
133  bcBarrelCollection_{consumes(config.getParameter<edm::InputTag>("bcBarrelCollection"))},
134  bcEndcapCollection_{consumes(config.getParameter<edm::InputTag>("bcEndcapCollection"))},
135  scHybridBarrelProducer_{consumes(config.getParameter<edm::InputTag>("scHybridBarrelProducer"))},
136  scIslandEndcapProducer_{consumes(config.getParameter<edm::InputTag>("scIslandEndcapProducer"))},
137  hcalTowers_{consumes(config.getParameter<edm::InputTag>("hcalTowers"))},
138  caloGeomToken_{esConsumes()},
139  mFToken_{esConsumes<MagneticField, IdealMagneticFieldRecord, edm::Transition::BeginRun>()},
140  transientTrackToken_{esConsumes<TransientTrackBuilder, TransientTrackRecord, edm::Transition::BeginRun>(
141  edm::ESInputTag("", "TransientTrackBuilder"))},
142  vertexFinder_{config},
143  algoName_{config.getParameter<std::string>("AlgorithmName")},
144 
145  hOverEConeSize_{config.getParameter<double>("hOverEConeSize")},
146  maxHOverE_{config.getParameter<double>("maxHOverE")},
147  minSCEt_{config.getParameter<double>("minSCEt")},
148  recoverOneTrackCase_{config.getParameter<bool>("recoverOneTrackCase")},
149  dRForConversionRecovery_{config.getParameter<double>("dRForConversionRecovery")},
150  deltaCotCut_{config.getParameter<double>("deltaCotCut")},
151  minApproachDisCut_{config.getParameter<double>("minApproachDisCut")},
152 
153  maxNumOfCandidates_{config.getParameter<int>("maxNumOfCandidates")},
154  risolveAmbiguity_{config.getParameter<bool>("risolveConversionAmbiguity")},
155  likelihoodWeights_{config.getParameter<std::string>("MVA_weights_location")} {
156  // instantiate the Track Pair Finder algorithm
157  likelihoodCalc_.setWeightsFile(edm::FileInPath{likelihoodWeights_.c_str()}.fullPath().c_str());
158 }
159 
160 void ConvertedPhotonProducer::beginRun(edm::Run const& r, edm::EventSetup const& theEventSetup) {
161  magneticField_ = &theEventSetup.getData(mFToken_);
162 
163  // Transform Track into TransientTrack (needed by the Vertex fitter)
165 }
166 
167 void ConvertedPhotonProducer::produce(edm::Event& theEvent, const edm::EventSetup& theEventSetup) {
168  //
169  // create empty output collections
170  //
171  // Converted photon candidates
172  reco::ConversionCollection outputConvPhotonCollection;
173  // Converted photon candidates
174  reco::ConversionCollection cleanedConversionCollection;
175 
176  // Get the Super Cluster collection in the Barrel
177  bool validBarrelSCHandle = true;
178  auto scBarrelHandle = theEvent.getHandle(scHybridBarrelProducer_);
179  if (!scBarrelHandle.isValid()) {
180  edm::LogError("ConvertedPhotonProducer") << "Error! Can't get the scHybridBarrelProducer";
181  validBarrelSCHandle = false;
182  }
183 
184  // Get the Super Cluster collection in the Endcap
185  bool validEndcapSCHandle = true;
187  theEvent.getByToken(scIslandEndcapProducer_, scEndcapHandle);
188  if (!scEndcapHandle.isValid()) {
189  edm::LogError("ConvertedPhotonProducer") << "Error! Can't get the scIslandEndcapProducer";
190  validEndcapSCHandle = false;
191  }
192 
194  bool validTrackInputs = true;
195  auto outInTrkHandle = theEvent.getHandle(conversionOITrackProducer_);
196  if (!outInTrkHandle.isValid()) {
197  //std::cout << "Error! Can't get the conversionOITrack " << "\n";
198  edm::LogError("ConvertedPhotonProducer") << "Error! Can't get the conversionOITrack "
199  << "\n";
200  validTrackInputs = false;
201  }
202  // LogDebug("ConvertedPhotonProducer")<< "ConvertedPhotonProducer outInTrack collection size " << (*outInTrkHandle).size() << "\n";
203 
205  auto outInTrkSCAssocHandle = theEvent.getHandle(outInTrackSCAssociationCollection_);
206  if (!outInTrkSCAssocHandle.isValid()) {
207  // std::cout << "Error! Can't get the product " << outInTrackSCAssociationCollection_.c_str() <<"\n";
208  edm::LogError("ConvertedPhotonProducer") << "Error! Can't get the outInTrackSCAssociationCollection)";
209  validTrackInputs = false;
210  }
211 
213  auto inOutTrkHandle = theEvent.getHandle(conversionIOTrackProducer_);
214  if (!inOutTrkHandle.isValid()) {
215  // std::cout << "Error! Can't get the conversionIOTrack " << "\n";
216  edm::LogError("ConvertedPhotonProducer") << "Error! Can't get the conversionIOTrack "
217  << "\n";
218  validTrackInputs = false;
219  }
220  // LogDebug("ConvertedPhotonProducer") << " ConvertedPhotonProducer inOutTrack collection size " << (*inOutTrkHandle).size() << "\n";
221 
223 
224  edm::Handle<reco::TrackCollection> generalTrkHandle;
225  if (recoverOneTrackCase_) {
226  theEvent.getByToken(generalTrackProducer_, generalTrkHandle);
227  if (!generalTrkHandle.isValid()) {
228  //std::cout << "Error! Can't get the genralTracks " << "\n";
229  edm::LogError("ConvertedPhotonProducer") << "Error! Can't get the genralTracks "
230  << "\n";
231  }
232  }
233 
235  auto inOutTrkSCAssocHandle = theEvent.getHandle(inOutTrackSCAssociationCollection_);
236  if (!inOutTrkSCAssocHandle.isValid()) {
237  //std::cout << "Error! Can't get the product " << inOutTrackSCAssociationCollection_.c_str() <<"\n";
238  edm::LogError("ConvertedPhotonProducer") << "Error! Can't get the inOutTrackSCAssociationCollection_.c_str()";
239  validTrackInputs = false;
240  }
241 
242  // Get the basic cluster collection in the Barrel
244  theEvent.getByToken(bcBarrelCollection_, bcBarrelHandle);
245  if (!bcBarrelHandle.isValid()) {
246  edm::LogError("ConvertedPhotonProducer") << "Error! Can't get the bcBarrelCollection";
247  }
248 
249  // Get the basic cluster collection in the Endcap
251  theEvent.getByToken(bcEndcapCollection_, bcEndcapHandle);
252  if (!bcEndcapHandle.isValid()) {
253  edm::LogError("ConvertedPhotonProducer") << "Error! Can't get the bcEndcapCollection";
254  }
255 
256  // get Hcal towers collection
257  auto const& hcalTowers = theEvent.get(hcalTowers_);
258 
259  if (validTrackInputs) {
260  //do the conversion:
261  std::vector<reco::TransientTrack> t_outInTrk = transientTrackBuilder_->build(outInTrkHandle);
262  std::vector<reco::TransientTrack> t_inOutTrk = transientTrackBuilder_->build(inOutTrkHandle);
263 
265  std::map<std::vector<reco::TransientTrack>, reco::CaloClusterPtr, CompareTwoTracksVectors> allPairs;
266  allPairs = trackPairFinder_.run(
267  t_outInTrk, outInTrkHandle, outInTrkSCAssocHandle, t_inOutTrk, inOutTrkHandle, inOutTrkSCAssocHandle);
268  //LogDebug("ConvertedPhotonProducer") << "ConvertedPhotonProducer allPairs.size " << allPairs.size() << "\n";
269 
270  buildCollections(theEventSetup,
271  scBarrelHandle,
272  bcBarrelHandle,
273  hcalTowers,
274  generalTrkHandle,
275  allPairs,
276  outputConvPhotonCollection);
277  buildCollections(theEventSetup,
278  scEndcapHandle,
279  bcEndcapHandle,
280  hcalTowers,
281  generalTrkHandle,
282  allPairs,
283  outputConvPhotonCollection);
284  }
285 
286  // put the product in the event
287  auto const conversionHandle =
288  theEvent.emplace(convertedPhotonCollectionPutToken_, std::move(outputConvPhotonCollection));
289 
290  // Loop over barrel and endcap SC collections and fill the photon collection
291  if (validBarrelSCHandle)
292  cleanCollections(scBarrelHandle, conversionHandle, cleanedConversionCollection);
293  if (validEndcapSCHandle)
294  cleanCollections(scEndcapHandle, conversionHandle, cleanedConversionCollection);
295 
296  theEvent.emplace(cleanedConvertedPhotonCollectionPutToken_, std::move(cleanedConversionCollection));
297 }
298 
300  edm::EventSetup const& es,
301  const edm::Handle<edm::View<reco::CaloCluster> >& scHandle,
302  const edm::Handle<edm::View<reco::CaloCluster> >& bcHandle,
304  const edm::Handle<reco::TrackCollection>& generalTrkHandle,
305  std::map<std::vector<reco::TransientTrack>, reco::CaloClusterPtr, CompareTwoTracksVectors>& allPairs,
306  reco::ConversionCollection& outputConvPhotonCollection)
307 
308 {
309  // instantiate the algorithm for finding the position of the track extrapolation at the Ecal front face
310  ConversionTrackEcalImpactPoint theEcalImpactPositionFinder(magneticField_);
311 
313 
314  std::vector<reco::TransientTrack> t_generalTrk;
316  t_generalTrk = transientTrackBuilder_->build(generalTrkHandle);
317 
318  // Loop over SC in the barrel and reconstruct converted photons
319  int myCands = 0;
321  for (auto const& aClus : scHandle->ptrs()) {
322  // preselection based in Et and H/E cut
323  if (aClus->energy() / cosh(aClus->eta()) <= minSCEt_)
324  continue;
325  const reco::CaloCluster* pClus = &(*aClus);
326  auto const* sc = dynamic_cast<const reco::SuperCluster*>(pClus);
327  EgammaTowerIsolation towerIso(hOverEConeSize_, 0., 0., -1, &hcalTowers);
328  double HoE = towerIso.getTowerESum(sc) / sc->energy();
329  if (HoE >= maxHOverE_)
330  continue;
332 
333  std::vector<edm::Ref<reco::TrackCollection> > trackPairRef;
334  std::vector<math::XYZPointF> trackInnPos;
335  std::vector<math::XYZVectorF> trackPin;
336  std::vector<math::XYZVectorF> trackPout;
337  float minAppDist = -99;
338 
339  //LogDebug("ConvertedPhotonProducer") << "ConvertedPhotonProducer SC energy " << aClus->energy() << " eta " << aClus->eta() << " phi " << aClus->phi() << "\n";
340 
342  const reco::Particle::Point vtx(0, 0, 0);
343 
344  math::XYZVector direction = aClus->position() - vtx;
345  math::XYZVector momentum = direction.unit() * aClus->energy();
346  const reco::Particle::LorentzVector p4(momentum.x(), momentum.y(), momentum.z(), aClus->energy());
347 
348  int nFound = 0;
349  if (!allPairs.empty()) {
350  nFound = 0;
351 
352  for (auto iPair = allPairs.begin(); iPair != allPairs.end(); ++iPair) {
353  scPtrVec.clear();
354 
355  reco::Vertex theConversionVertex;
356  reco::CaloClusterPtr caloPtr = iPair->second;
357  if (!(aClus == caloPtr))
358  continue;
359 
360  scPtrVec.push_back(aClus);
361  nFound++;
362 
363  std::vector<math::XYZPointF> trkPositionAtEcal = theEcalImpactPositionFinder.find(iPair->first, bcHandle);
364  std::vector<reco::CaloClusterPtr> matchingBC = theEcalImpactPositionFinder.matchingBC();
365 
366  minAppDist = -99;
367  const std::string metname = "ConvertedPhotons|ConvertedPhotonProducer";
368  if ((iPair->first).size() > 1) {
369  try {
370  vertexFinder_.run(iPair->first, theConversionVertex);
371 
372  } catch (cms::Exception& e) {
373  //std::cout << " cms::Exception caught in ConvertedPhotonProducer::produce" << "\n" ;
374  edm::LogWarning(metname) << "cms::Exception caught in ConvertedPhotonProducer::produce\n"
375  << e.explainSelf();
376  }
377 
378  // Old TwoTrackMinimumDistance md;
379  // Old md.calculate ( (iPair->first)[0].initialFreeState(), (iPair->first)[1].initialFreeState() );
380  // Old minAppDist = md.distance();
381 
382  /*
383  for ( unsigned int i=0; i< matchingBC.size(); ++i) {
384  if ( matchingBC[i].isNull() ) std::cout << " This ref to BC is null: skipping " << "\n";
385  else
386  std::cout << " BC energy " << matchingBC[i]->energy() << "\n";
387  }
388  */
389 
391  trackPairRef.clear();
392  trackInnPos.clear();
393  trackPin.clear();
394  trackPout.clear();
395 
396  for (std::vector<reco::TransientTrack>::const_iterator iTk = (iPair->first).begin();
397  iTk != (iPair->first).end();
398  ++iTk) {
399  //LogDebug("ConvertedPhotonProducer") << " ConvertedPhotonProducer Transient Tracks in the pair charge " << iTk->charge() << " Num of RecHits " << iTk->recHitsSize() << " inner momentum " << iTk->track().innerMomentum() << "\n";
400 
401  auto const* ttt = dynamic_cast<const reco::TrackTransientTrack*>(iTk->basicTransientTrack());
402  reco::TrackRef myTkRef = ttt->persistentTrackRef();
403 
404  //LogDebug("ConvertedPhotonProducer") << " ConvertedPhotonProducer Ref to Rec Tracks in the pair charge " << myTkRef->charge() << " Num of RecHits " << myTkRef->recHitsSize() << " inner momentum " << myTkRef->innerMomentum() << "\n";
405  if (myTkRef->extra().isNonnull()) {
406  trackInnPos.push_back(toFConverterP(myTkRef->innerPosition()));
407  trackPin.push_back(toFConverterV(myTkRef->innerMomentum()));
408  trackPout.push_back(toFConverterV(myTkRef->outerMomentum()));
409  }
410  trackPairRef.push_back(myTkRef);
411  }
412 
413  // std::cout << " ConvertedPhotonProducer trackPin size " << trackPin.size() << std::endl;
414  //LogDebug("ConvertedPhotonProducer") << " ConvertedPhotonProducer SC energy " << aClus->energy() << "\n";
415  //LogDebug("ConvertedPhotonProducer") << " ConvertedPhotonProducer photon p4 " << p4 << "\n";
416  //LogDebug("ConvertedPhotonProducer") << " ConvertedPhotonProducer vtx " << vtx.x() << " " << vtx.y() << " " << vtx.z() << "\n";
417  if (theConversionVertex.isValid()) {
418  //LogDebug("ConvertedPhotonProducer") << " ConvertedPhotonProducer theConversionVertex " << theConversionVertex.position().x() << " " << theConversionVertex.position().y() << " " << theConversionVertex.position().z() << "\n";
419  }
420  //LogDebug("ConvertedPhotonProducer") << " ConvertedPhotonProducer trackPairRef " << trackPairRef.size() << "\n";
421 
422  minAppDist = calculateMinApproachDistance(trackPairRef[0], trackPairRef[1]);
423 
424  double like = -999.;
425  reco::Conversion newCandidate(scPtrVec,
426  trackPairRef,
427  trkPositionAtEcal,
428  theConversionVertex,
429  matchingBC,
430  minAppDist,
431  trackInnPos,
432  trackPin,
433  trackPout,
434  like,
435  algo);
436  like = likelihoodCalc_.calculateLikelihood(newCandidate);
437  // std::cout << "like = " << like << std::endl;
438  newCandidate.setMVAout(like);
439  outputConvPhotonCollection.push_back(newCandidate);
440 
441  myCands++;
442  //LogDebug("ConvertedPhotonProducer") << " ConvertedPhotonProducer Put the ConvertedPhotonCollection a candidate in the Barrel " << "\n";
443 
444  } else {
445  // std::cout << " ConvertedPhotonProducer case with only one track found " << "\n";
446 
447  //std::cout << " ConvertedPhotonProducer recovering one track " << "\n";
448  trackPairRef.clear();
449  trackInnPos.clear();
450  trackPin.clear();
451  trackPout.clear();
452  std::vector<reco::TransientTrack>::const_iterator iTk = (iPair->first).begin();
453  //std::cout << " ConvertedPhotonProducer Transient Tracks in the pair charge " << iTk->charge() << " Num of RecHits " << iTk->recHitsSize() << " inner momentum " << iTk->track().innerMomentum() << " pt " << sqrt(iTk->track().innerMomentum().perp2()) << "\n";
454  auto const* ttt = dynamic_cast<const reco::TrackTransientTrack*>(iTk->basicTransientTrack());
455  reco::TrackRef myTk = ttt->persistentTrackRef();
456  if (myTk->extra().isNonnull()) {
457  trackInnPos.push_back(toFConverterP(myTk->innerPosition()));
458  trackPin.push_back(toFConverterV(myTk->innerMomentum()));
459  trackPout.push_back(toFConverterV(myTk->outerMomentum()));
460  }
461  trackPairRef.push_back(myTk);
462  //std::cout << " Provenance " << myTk->algoName() << std::endl;
463 
464  if (recoverOneTrackCase_) {
465  float theta1 = myTk->innerMomentum().Theta();
466  float dCot = 999.;
467  float dCotTheta = -999.;
468  reco::TrackRef goodRef;
469  for (auto const& tran : t_generalTrk) {
470  auto const* ttt = dynamic_cast<const reco::TrackTransientTrack*>(tran.basicTransientTrack());
471  reco::TrackRef trRef = ttt->persistentTrackRef();
472  if (trRef->charge() * myTk->charge() > 0)
473  continue;
474  float dEta = trRef->eta() - myTk->eta();
475  float dPhi = trRef->phi() - myTk->phi();
477  continue;
478  float theta2 = trRef->innerMomentum().Theta();
479  dCotTheta = 1. / tan(theta1) - 1. / tan(theta2);
480  // std::cout << " ConvertedPhotonProducer recovering general transient track charge " << trRef->charge() << " momentum " << trRef->innerMomentum() << " dcotTheta " << fabs(dCotTheta) << std::endl;
481  if (fabs(dCotTheta) < dCot) {
482  dCot = fabs(dCotTheta);
483  goodRef = trRef;
484  }
485  }
486 
487  if (goodRef.isNonnull()) {
488  minAppDist = calculateMinApproachDistance(myTk, goodRef);
489 
490  // std::cout << " ConvertedPhotonProducer chosen dCotTheta " << fabs(dCotTheta) << std::endl;
491  if (fabs(dCotTheta) < deltaCotCut_ && minAppDist > minApproachDisCut_) {
492  trackInnPos.push_back(toFConverterP(goodRef->innerPosition()));
493  trackPin.push_back(toFConverterV(goodRef->innerMomentum()));
494  trackPout.push_back(toFConverterV(goodRef->outerMomentum()));
495  trackPairRef.push_back(goodRef);
496  // std::cout << " ConvertedPhotonProducer adding opposite charge track from generalTrackCollection charge " << goodRef ->charge() << " pt " << sqrt(goodRef->innerMomentum().perp2()) << " trackPairRef size " << trackPairRef.size() << std::endl;
497  //std::cout << " Track Provenenance " << goodRef->algoName() << std::endl;
498 
499  try {
500  vertexFinder_.run(iPair->first, theConversionVertex);
501 
502  } catch (cms::Exception& e) {
503  //std::cout << " cms::Exception caught in ConvertedPhotonProducer::produce" << "\n" ;
504  edm::LogWarning(metname) << "cms::Exception caught in ConvertedPhotonProducer::produce\n"
505  << e.explainSelf();
506  }
507  }
508  }
509 
510  } // bool On/Off one track case recovery using generalTracks
511  const double like = -999.;
512  outputConvPhotonCollection.emplace_back(scPtrVec,
513  trackPairRef,
514  trkPositionAtEcal,
515  theConversionVertex,
516  matchingBC,
517  minAppDist,
518  trackInnPos,
519  trackPin,
520  trackPout,
521  like,
522  algo);
523  auto& newCandidate = outputConvPhotonCollection.back();
524  newCandidate.setMVAout(likelihoodCalc_.calculateLikelihood(newCandidate));
525 
526  } // case with only on track: looking in general tracks
527  }
528  }
529  }
530 }
531 
534  reco::ConversionCollection& outputConversionCollection) {
535  reco::Conversion* newCandidate = nullptr;
536  for (auto const& aClus : scHandle->ptrs()) {
537  // SC energy preselection
538  if (aClus->energy() / cosh(aClus->eta()) <= minSCEt_)
539  continue;
540 
541  if (conversionHandle.isValid()) {
542  if (risolveAmbiguity_) {
543  std::vector<reco::ConversionRef> bestRef = solveAmbiguity(conversionHandle, aClus);
544 
545  for (std::vector<reco::ConversionRef>::iterator iRef = bestRef.begin(); iRef != bestRef.end(); iRef++) {
546  if (iRef->isNonnull()) {
547  newCandidate = (*iRef)->clone();
548  outputConversionCollection.push_back(*newCandidate);
549  delete newCandidate;
550  }
551  }
552 
553  } else {
554  for (unsigned int icp = 0; icp < conversionHandle->size(); icp++) {
556  if (!(aClus.id() == cpRef->caloCluster()[0].id() && aClus.key() == cpRef->caloCluster()[0].key()))
557  continue;
558  if (!cpRef->isConverted())
559  continue;
560  if (cpRef->nTracks() < 2)
561  continue;
562  newCandidate = (&(*cpRef))->clone();
563  outputConversionCollection.push_back(*newCandidate);
564  delete newCandidate;
565  }
566 
567  } // solve or not the ambiguity of many conversion candidates
568  }
569  }
570 }
571 
572 std::vector<reco::ConversionRef> ConvertedPhotonProducer::solveAmbiguity(
574  std::multimap<double, reco::ConversionRef, std::greater<double> > convMap;
575 
576  for (unsigned int icp = 0; icp < conversionHandle->size(); icp++) {
578 
579  //std::cout << " cpRef " << cpRef->nTracks() << " " << cpRef ->caloCluster()[0]->energy() << std::endl;
580  if (!(scRef.id() == cpRef->caloCluster()[0].id() && scRef.key() == cpRef->caloCluster()[0].key()))
581  continue;
582  if (!cpRef->isConverted())
583  continue;
584  double like = cpRef->MVAout();
585  if (cpRef->nTracks() < 2)
586  continue;
587  // std::cout << " Like " << like << std::endl;
588  convMap.emplace(like, cpRef);
589  }
590 
591  // std::cout << " convMap size " << convMap.size() << std::endl;
592 
593  std::vector<reco::ConversionRef> bestRefs;
594  for (auto iMap = convMap.begin(); iMap != convMap.end(); iMap++) {
595  // std::cout << " Like list in the map " << iMap->first << " " << (iMap->second)->EoverP() << std::endl;
596  bestRefs.push_back(iMap->second);
597  if (int(bestRefs.size()) == maxNumOfCandidates_)
598  break;
599  }
600 
601  return bestRefs;
602 }
603 
605  const reco::TrackRef& track2) {
606  double x1, x2, y1, y2;
607  double xx_1 = track1->innerPosition().x(), yy_1 = track1->innerPosition().y(), zz_1 = track1->innerPosition().z();
608  double xx_2 = track2->innerPosition().x(), yy_2 = track2->innerPosition().y(), zz_2 = track2->innerPosition().z();
609  double radius1 =
610  track1->innerMomentum().Rho() / (.3 * (magneticField_->inTesla(GlobalPoint(xx_1, yy_1, zz_1)).z())) * 100;
611  double radius2 =
612  track2->innerMomentum().Rho() / (.3 * (magneticField_->inTesla(GlobalPoint(xx_2, yy_2, zz_2)).z())) * 100;
613  getCircleCenter(track1, radius1, x1, y1);
614  getCircleCenter(track2, radius2, x2, y2);
615 
616  return std::sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) - radius1 - radius2;
617 }
618 
619 void ConvertedPhotonProducer::getCircleCenter(const reco::TrackRef& tk, double r, double& x0, double& y0) {
620  double x1, y1, phi;
621  x1 = tk->innerPosition().x(); //inner position and inner momentum need track Extra!
622  y1 = tk->innerPosition().y();
623  phi = tk->innerMomentum().phi();
624  const int charge = tk->charge();
625  x0 = x1 + r * sin(phi) * charge;
626  y0 = y1 - r * cos(phi) * charge;
627 }
TrackExtra.h
reco::Vertex::isValid
bool isValid() const
Tells whether the vertex is valid.
Definition: Vertex.h:72
reco::Conversion
Definition: Conversion.h:23
Handle.h
MagneticField::inTesla
virtual GlobalVector inTesla(const GlobalPoint &gp) const =0
Field value ad specified global point, in Tesla.
ConvertedPhotonProducer::magneticField_
MagneticField const * magneticField_
Definition: ConvertedPhotonProducer.cc:87
edm::ESInputTag
Definition: ESInputTag.h:87
ConvertedPhotonProducer::scIslandEndcapProducer_
edm::EDGetTokenT< edm::View< reco::CaloCluster > > scIslandEndcapProducer_
Definition: ConvertedPhotonProducer.cc:84
MessageLogger.h
ConversionLikelihoodCalculator
Definition: ConversionLikelihoodCalculator.h:9
ConversionTrackEcalImpactPoint::find
std::vector< math::XYZPointF > find(const std::vector< reco::TransientTrack > &tracks, const edm::Handle< edm::View< reco::CaloCluster > > &bcHandle)
Definition: ConversionTrackEcalImpactPoint.cc:56
TrackerGeometry.h
ConvertedPhotonProducer::minApproachDisCut_
double minApproachDisCut_
Definition: ConvertedPhotonProducer.cc:104
ConvertedPhotonProducer::beginRun
void beginRun(edm::Run const &, const edm::EventSetup &es) final
Definition: ConvertedPhotonProducer.cc:160
ConvertedPhotonProducer::generalTrackProducer_
edm::EDGetTokenT< reco::TrackCollection > generalTrackProducer_
Definition: ConvertedPhotonProducer.cc:75
edm::Run
Definition: Run.h:45
edm::EDGetTokenT< reco::TrackCollection >
testProducerWithPsetDescEmpty_cfi.x2
x2
Definition: testProducerWithPsetDescEmpty_cfi.py:28
edm::EDPutTokenT< reco::ConversionCollection >
ConvertedPhotonProducer::mFToken_
edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > mFToken_
Definition: ConvertedPhotonProducer.cc:91
ConversionLikelihoodCalculator::calculateLikelihood
double calculateLikelihood(reco::ConversionRef conversion)
Definition: ConversionLikelihoodCalculator.cc:23
ConversionVertexFinder.h
EDProducer.h
edm::SortedCollection< CaloTower >
ConvertedPhotonProducer
Definition: ConvertedPhotonProducer.cc:43
printConversionInfo.conversionHandle
conversionHandle
Definition: printConversionInfo.py:15
ConvertedPhotonProducer::getCircleCenter
void getCircleCenter(const reco::TrackRef &tk, double r, double &x0, double &y0)
Definition: ConvertedPhotonProducer.cc:619
TransientTrack.h
ConvertedPhotonProducer::hcalTowers_
edm::EDGetTokenT< CaloTowerCollection > hcalTowers_
Definition: ConvertedPhotonProducer.cc:85
HLT_FULL_cff.dPhi
dPhi
Definition: HLT_FULL_cff.py:13703
ConvertedPhotonProducer::cleanCollections
void cleanCollections(const edm::Handle< edm::View< reco::CaloCluster > > &scHandle, const edm::OrphanHandle< reco::ConversionCollection > &conversionHandle, reco::ConversionCollection &outputCollection)
Definition: ConvertedPhotonProducer.cc:532
edm::Ptr::key
key_type key() const
Definition: Ptr.h:163
edm::Handle
Definition: AssociativeIterator.h:50
ConvertedPhotonProducer::transientTrackToken_
edm::ESGetToken< TransientTrackBuilder, TransientTrackRecord > transientTrackToken_
Definition: ConvertedPhotonProducer.cc:92
ESGetToken.h
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
ConvertedPhotonProducer::conversionOITrackProducer_
edm::EDGetTokenT< reco::TrackCollection > conversionOITrackProducer_
Definition: ConvertedPhotonProducer.cc:69
reco::CaloClusterPtr
edm::Ptr< CaloCluster > CaloClusterPtr
Definition: CaloClusterFwd.h:21
ConvertedPhotonProducer::inOutTrackSCAssociationCollection_
edm::EDGetTokenT< reco::TrackCaloClusterPtrAssociation > inOutTrackSCAssociationCollection_
Definition: ConvertedPhotonProducer.cc:73
reco::Particle::LorentzVector
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:21
ConversionTrackPairFinder
Definition: ConversionTrackPairFinder.h:44
edm::Ref< TrackCollection >
reco::ConversionCollection
std::vector< Conversion > ConversionCollection
collectin of Conversion objects
Definition: ConversionFwd.h:9
ConversionVertexFinder
Definition: ConversionVertexFinder.h:29
reco::Conversion::setMVAout
void setMVAout(const float &mva)
set the value of the TMVA output
Definition: Conversion.h:161
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
ConversionTrackPairFinder::run
std::map< std::vector< reco::TransientTrack >, reco::CaloClusterPtr, CompareTwoTracksVectors > run(const std::vector< reco::TransientTrack > &outIn, const edm::Handle< reco::TrackCollection > &outInTrkHandle, const edm::Handle< reco::TrackCaloClusterPtrAssociation > &outInTrackSCAssH, const std::vector< reco::TransientTrack > &inOut, const edm::Handle< reco::TrackCollection > &inOutTrkHandle, const edm::Handle< reco::TrackCaloClusterPtrAssociation > &inOutTrackSCAssH)
Definition: ConversionTrackPairFinder.cc:26
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
config
Definition: config.py:1
cmsdt::algo
algo
Definition: constants.h:165
edm::FileInPath
Definition: FileInPath.h:64
MakerMacros.h
ConvertedPhotonProducer::algoName_
std::string algoName_
Definition: ConvertedPhotonProducer.cc:96
Photon.h
testProducerWithPsetDescEmpty_cfi.x1
x1
Definition: testProducerWithPsetDescEmpty_cfi.py:33
testProducerWithPsetDescEmpty_cfi.y1
y1
Definition: testProducerWithPsetDescEmpty_cfi.py:29
EgammaTowerIsolation::getTowerESum
double getTowerESum(const reco::Candidate *cand, const std::vector< CaloTowerDetId > *detIdToExclude=nullptr) const
Definition: EgammaTowerIsolation.h:209
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Track.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ConvertedPhotonProducer::dRForConversionRecovery_
double dRForConversionRecovery_
Definition: ConvertedPhotonProducer.cc:102
clone
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
edm::PtrVector< CaloCluster >
ConvertedPhotonProducer::convertedPhotonCollectionPutToken_
edm::EDPutTokenT< reco::ConversionCollection > convertedPhotonCollectionPutToken_
Definition: ConvertedPhotonProducer.cc:78
ConvertedPhotonProducer::caloGeomToken_
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeomToken_
Definition: ConvertedPhotonProducer.cc:90
reco::CaloCluster
Definition: CaloCluster.h:31
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
ConvertedPhotonProducer::conversionIOTrackProducer_
edm::EDGetTokenT< reco::TrackCollection > conversionIOTrackProducer_
Definition: ConvertedPhotonProducer.cc:70
ConvertedPhotonProducer::likelihoodCalc_
ConversionLikelihoodCalculator likelihoodCalc_
Definition: ConvertedPhotonProducer.cc:108
mps_fire.end
end
Definition: mps_fire.py:242
IdealMagneticFieldRecord.h
ConvertedPhotonProducer::risolveAmbiguity_
bool risolveAmbiguity_
Definition: ConvertedPhotonProducer.cc:106
ConvertedPhotonProducer::produce
void produce(edm::Event &evt, const edm::EventSetup &es) override
Definition: ConvertedPhotonProducer.cc:167
ConvertedPhotonProducer::vertexFinder_
ConversionVertexFinder vertexFinder_
Definition: ConvertedPhotonProducer.cc:95
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:535
GlobalPoint
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
EgammaTowerIsolation.h
edm::Event::emplace
OrphanHandle< PROD > emplace(EDPutTokenT< PROD > token, Args &&... args)
puts a new product
Definition: Event.h:429
ConvertedPhotonProducer::bcBarrelCollection_
edm::EDGetTokenT< edm::View< reco::CaloCluster > > bcBarrelCollection_
Definition: ConvertedPhotonProducer.cc:81
CaloGeometryRecord.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
Vertex.h
edm::PtrVector::push_back
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:149
ALCARECOTkAlJpsiMuMu_cff.charge
charge
Definition: ALCARECOTkAlJpsiMuMu_cff.py:47
ConvertedPhotonProducer::maxHOverE_
double maxHOverE_
Definition: ConvertedPhotonProducer.cc:99
testProducerWithPsetDescEmpty_cfi.y2
y2
Definition: testProducerWithPsetDescEmpty_cfi.py:30
ConvertedPhotonProducer::trackPairFinder_
ConversionTrackPairFinder trackPairFinder_
Definition: ConvertedPhotonProducer.cc:94
edm::View
Definition: CaloClusterFwd.h:14
ConvertedPhotonProducer::transientTrackBuilder_
TransientTrackBuilder const * transientTrackBuilder_
Definition: ConvertedPhotonProducer.cc:88
ConversionVertexFinder::run
TransientVertex run(const std::vector< reco::TransientTrack > &pair)
Definition: ConversionVertexFinder.cc:135
TransientTrackBuilder.h
edm::ParameterSet
Definition: ParameterSet.h:47
math::XYZPoint
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
edm::Ptr::id
ProductID id() const
Accessor for product ID.
Definition: Ptr.h:158
ConvertedPhotonProducer::buildCollections
void buildCollections(edm::EventSetup const &es, const edm::Handle< edm::View< reco::CaloCluster > > &scHandle, const edm::Handle< edm::View< reco::CaloCluster > > &bcHandle, CaloTowerCollection const &hcalTowers, const edm::Handle< reco::TrackCollection > &trkHandle, std::map< std::vector< reco::TransientTrack >, reco::CaloClusterPtr, CompareTwoTracksVectors > &allPairs, reco::ConversionCollection &outputConvPhotonCollection)
Definition: ConvertedPhotonProducer.cc:299
Event.h
edm::Ref::isNonnull
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
math::XYZVector
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
EgammaTowerIsolation
Definition: EgammaTowerIsolation.h:197
funct::tan
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
ConvertedPhotonProducer::toFConverterP
math::XYZPointF toFConverterP(const math::XYZPoint &val)
Definition: ConvertedPhotonProducer.cc:111
TrackTransientTrack.h
ConvertedPhotonProducer::hOverEConeSize_
double hOverEConeSize_
Definition: ConvertedPhotonProducer.cc:98
p4
double p4[4]
Definition: TauolaWrapper.h:92
ConversionTrackEcalImpactPoint.h
edm::stream::EDProducer
Definition: EDProducer.h:38
ConvertedPhotonProducer::toFConverterV
math::XYZVectorF toFConverterV(const math::XYZVector &val)
Definition: ConvertedPhotonProducer.cc:113
TransientTrackBuilder
Definition: TransientTrackBuilder.h:16
reco::Conversion::clone
Conversion * clone() const
returns a clone of the candidate
Definition: Conversion.cc:148
MagneticField.h
ConvertedPhotonProducer::maxNumOfCandidates_
int maxNumOfCandidates_
Definition: ConvertedPhotonProducer.cc:105
edm::EventSetup
Definition: EventSetup.h:58
ConvertedPhotonProducer::deltaCotCut_
double deltaCotCut_
Definition: ConvertedPhotonProducer.cc:103
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
edm::PtrVectorBase::clear
void clear()
Clear the PtrVector.
Definition: PtrVectorBase.h:79
TransientTrackRecord.h
ConvertedPhotonProducer::solveAmbiguity
std::vector< reco::ConversionRef > solveAmbiguity(const edm::OrphanHandle< reco::ConversionCollection > &conversionHandle, reco::CaloClusterPtr const &sc)
Definition: ConvertedPhotonProducer.cc:572
edm::ESGetToken< CaloGeometry, CaloGeometryRecord >
reco::Conversion::ConversionAlgorithm
ConversionAlgorithm
Definition: Conversion.h:25
conversions_cfi.hcalTowers
hcalTowers
Definition: conversions_cfi.py:21
edm::Ptr< CaloCluster >
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:127
alignCSCRings.r
r
Definition: alignCSCRings.py:93
CaloTowerCollection.h
DDAxes::phi
edm::Ref::id
ProductID id() const
Accessor for product ID.
Definition: Ref.h:244
TrackCaloClusterAssociation.h
reco::Conversion::algoByName
static ConversionAlgorithm algoByName(const std::string &name)
Definition: Conversion.cc:139
heppy_batch.val
val
Definition: heppy_batch.py:351
eostools.move
def move(src, dest)
Definition: eostools.py:511
edm::OrphanHandle
Definition: EDProductfwd.h:39
ConvertedPhotonProducer::cleanedConvertedPhotonCollectionPutToken_
edm::EDPutTokenT< reco::ConversionCollection > cleanedConvertedPhotonCollectionPutToken_
Definition: ConvertedPhotonProducer.cc:79
extraflags_cff.vtx
vtx
Definition: extraflags_cff.py:18
HLT_FULL_cff.dEta
dEta
Definition: HLT_FULL_cff.py:13702
ConvertedPhotonProducer::calculateMinApproachDistance
float calculateMinApproachDistance(const reco::TrackRef &track1, const reco::TrackRef &track2)
Definition: ConvertedPhotonProducer.cc:604
ConvertedPhotonProducer::scHybridBarrelProducer_
edm::EDGetTokenT< edm::View< reco::CaloCluster > > scHybridBarrelProducer_
Definition: ConvertedPhotonProducer.cc:83
SuperCluster.h
ConvertedPhotonProducer::likelihoodWeights_
std::string likelihoodWeights_
Definition: ConvertedPhotonProducer.cc:109
ConvertedPhotonProducer::minSCEt_
double minSCEt_
Definition: ConvertedPhotonProducer.cc:100
CaloGeometry.h
ConvertedPhotonProducer::bcEndcapCollection_
edm::EDGetTokenT< edm::View< reco::CaloCluster > > bcEndcapCollection_
Definition: ConvertedPhotonProducer.cc:82
CompareTwoTracksVectors
Definition: ConversionTrackPairFinder.h:38
math::XYZVectorF
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< float > > XYZVectorF
spatial vector with cartesian internal representation
Definition: Vector3D.h:16
EventSetup.h
ConvertedPhotonProducer::recoverOneTrackCase_
bool recoverOneTrackCase_
Definition: ConvertedPhotonProducer.cc:101
Exception.h
ConversionTrackEcalImpactPoint::matchingBC
std::vector< reco::CaloClusterPtr > matchingBC() const
Definition: ConversionTrackEcalImpactPoint.h:46
reco::Particle::Point
math::XYZPoint Point
point in the space
Definition: Particle.h:25
ConversionTrackEcalImpactPoint
Definition: ConversionTrackEcalImpactPoint.h:37
edm::Ref::key
key_type key() const
Accessor for product key.
Definition: Ref.h:250
TransientTrackBuilder::build
reco::TransientTrack build(const reco::Track *p) const
Definition: TransientTrackBuilder.cc:20
ConvertedPhotonProducer::outInTrackSCAssociationCollection_
edm::EDGetTokenT< reco::TrackCaloClusterPtrAssociation > outInTrackSCAssociationCollection_
Definition: ConvertedPhotonProducer.cc:72
cms::Exception
Definition: Exception.h:70
genParticles_cff.map
map
Definition: genParticles_cff.py:11
View.h
ParameterSet.h
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
ConvertedPhotonProducer::ConvertedPhotonProducer
ConvertedPhotonProducer(const edm::ParameterSet &ps)
Definition: ConvertedPhotonProducer.cc:119
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
math::XYZPointF
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< float > > XYZPointF
point in space with cartesian internal representation
Definition: Point3D.h:10
edm::Event
Definition: Event.h:73
MagneticField
Definition: MagneticField.h:19
ConversionLikelihoodCalculator.h
ConversionTrackPairFinder.h
edm::Event::get
bool get(ProductID const &oid, Handle< PROD > &result) const
Definition: Event.h:342
edm::Event::getHandle
Handle< PROD > getHandle(EDGetTokenT< PROD > token) const
Definition: Event.h:559
edm::InputTag
Definition: InputTag.h:15
reco::Vertex
Definition: Vertex.h:35
edm::FileInPath::fullPath
std::string fullPath() const
Definition: FileInPath.cc:161
CaloCluster.h
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
metname
const std::string metname
Definition: MuonSeedOrcaPatternRecognition.cc:40
edm::ProductID::id
ProductIndex id() const
Definition: ProductID.h:35
Conversion.h