CMS 3D CMS Logo

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