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