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 (unsigned i = 0; i < scHandle->size(); ++i ) {
344  reco::CaloClusterPtr aClus= scHandle->ptrAt(i);
345 
346  // preselection based in Et and H/E cut
347  if (aClus->energy()/cosh(aClus->eta()) <= minSCEt_) continue;
348  const reco::CaloCluster* pClus=&(*aClus);
349  const reco::SuperCluster* sc=dynamic_cast<const reco::SuperCluster*>(pClus);
350  const CaloTowerCollection* hcalTowersColl = hcalTowersHandle.product();
351  EgammaTowerIsolation towerIso(hOverEConeSize_,0.,0.,-1,hcalTowersColl) ;
352  double HoE=towerIso.getTowerESum(sc)/sc->energy();
353  if (HoE>=maxHOverE_) continue;
355 
356 
357  std::vector<edm::Ref<reco::TrackCollection> > trackPairRef;
358  std::vector<math::XYZPointF> trackInnPos;
359  std::vector<math::XYZVectorF> trackPin;
360  std::vector<math::XYZVectorF> trackPout;
361  float minAppDist=-99;
362 
363  //LogDebug("ConvertedPhotonProducer") << "ConvertedPhotonProducer SC energy " << aClus->energy() << " eta " << aClus->eta() << " phi " << aClus->phi() << "\n";
364 
365 
367  const reco::Particle::Point vtx( 0, 0, 0 );
368 
369 
370  math::XYZVector direction =aClus->position() - vtx;
371  math::XYZVector momentum = direction.unit() * aClus->energy();
372  const reco::Particle::LorentzVector p4(momentum.x(), momentum.y(), momentum.z(), aClus->energy() );
373 
374  int nFound=0;
375  if ( !allPairs.empty() ) {
376 
377  nFound=0;
378 
379 
380  for ( std::map<std::vector<reco::TransientTrack>, reco::CaloClusterPtr>::const_iterator iPair= allPairs.begin(); iPair!= allPairs.end(); ++iPair ) {
381  scPtrVec.clear();
382 
383  reco::Vertex theConversionVertex;
384  reco::CaloClusterPtr caloPtr=iPair->second;
385  if ( !( aClus == caloPtr ) ) continue;
386 
387  scPtrVec.push_back(aClus);
388  nFound++;
389 
390  std::vector<math::XYZPointF> trkPositionAtEcal = theEcalImpactPositionFinder.find( iPair->first, bcHandle );
391  std::vector<reco::CaloClusterPtr> matchingBC = theEcalImpactPositionFinder.matchingBC();
392 
393 
394  minAppDist=-99;
395  const std::string metname = "ConvertedPhotons|ConvertedPhotonProducer";
396  if ( (iPair->first).size() > 1 ) {
397  try{
398 
399  theVertexFinder_->run(iPair->first, theConversionVertex );
400 
401 
402  }
403  catch ( cms::Exception& e ) {
404  //std::cout << " cms::Exception caught in ConvertedPhotonProducer::produce" << "\n" ;
405  edm::LogWarning(metname) << "cms::Exception caught in ConvertedPhotonProducer::produce\n"
406  << e.explainSelf();
407 
408  }
409 
410  // Old TwoTrackMinimumDistance md;
411  // Old md.calculate ( (iPair->first)[0].initialFreeState(), (iPair->first)[1].initialFreeState() );
412  // Old minAppDist = md.distance();
413 
414 
415 
416 
417 
418 
419 
420  /*
421  for ( unsigned int i=0; i< matchingBC.size(); ++i) {
422  if ( matchingBC[i].isNull() ) std::cout << " This ref to BC is null: skipping " << "\n";
423  else
424  std::cout << " BC energy " << matchingBC[i]->energy() << "\n";
425  }
426  */
427 
428 
430  trackPairRef.clear();
431  trackInnPos.clear();
432  trackPin.clear();
433  trackPout.clear();
434 
435 
436  for ( std::vector<reco::TransientTrack>::const_iterator iTk=(iPair->first).begin(); iTk!= (iPair->first).end(); ++iTk) {
437  //LogDebug("ConvertedPhotonProducer") << " ConvertedPhotonProducer Transient Tracks in the pair charge " << iTk->charge() << " Num of RecHits " << iTk->recHitsSize() << " inner momentum " << iTk->track().innerMomentum() << "\n";
438 
439  const reco::TrackTransientTrack* ttt = dynamic_cast<const reco::TrackTransientTrack*>(iTk->basicTransientTrack());
440  reco::TrackRef myTkRef= ttt->persistentTrackRef();
441 
442  //LogDebug("ConvertedPhotonProducer") << " ConvertedPhotonProducer Ref to Rec Tracks in the pair charge " << myTkRef->charge() << " Num of RecHits " << myTkRef->recHitsSize() << " inner momentum " << myTkRef->innerMomentum() << "\n";
443  if ( myTkRef->extra().isNonnull() ) {
444  trackInnPos.push_back( toFConverterP(myTkRef->innerPosition()));
445  trackPin.push_back( toFConverterV( myTkRef->innerMomentum()));
446  trackPout.push_back( toFConverterV(myTkRef->outerMomentum()));
447  }
448  trackPairRef.push_back(myTkRef);
449 
450  }
451 
452  // std::cout << " ConvertedPhotonProducer trackPin size " << trackPin.size() << std::endl;
453  //LogDebug("ConvertedPhotonProducer") << " ConvertedPhotonProducer SC energy " << aClus->energy() << "\n";
454  //LogDebug("ConvertedPhotonProducer") << " ConvertedPhotonProducer photon p4 " << p4 << "\n";
455  //LogDebug("ConvertedPhotonProducer") << " ConvertedPhotonProducer vtx " << vtx.x() << " " << vtx.y() << " " << vtx.z() << "\n";
456  if( theConversionVertex.isValid() ) {
457 
458  //LogDebug("ConvertedPhotonProducer") << " ConvertedPhotonProducer theConversionVertex " << theConversionVertex.position().x() << " " << theConversionVertex.position().y() << " " << theConversionVertex.position().z() << "\n";
459 
460  }
461  //LogDebug("ConvertedPhotonProducer") << " ConvertedPhotonProducer trackPairRef " << trackPairRef.size() << "\n";
462 
463 
464  minAppDist=calculateMinApproachDistance( trackPairRef[0], trackPairRef[1]);
465 
466  double like = -999.;
467  reco::Conversion newCandidate(scPtrVec, trackPairRef, trkPositionAtEcal, theConversionVertex, matchingBC, minAppDist, trackInnPos, trackPin, trackPout, like, algo);
468 // like = theLikelihoodCalc_->calculateLikelihood(newCandidate, es );
469  like = theLikelihoodCalc_->calculateLikelihood( newCandidate );
470 // std::cout << "like = " << like << std::endl;
471  newCandidate.setMVAout(like);
472  outputConvPhotonCollection.push_back(newCandidate);
473 
474 
475  myCands++;
476  //LogDebug("ConvertedPhotonProducer") << " ConvertedPhotonProducer Put the ConvertedPhotonCollection a candidate in the Barrel " << "\n";
477 
478  } else {
479 
480 
481  // std::cout << " ConvertedPhotonProducer case with only one track found " << "\n";
482 
483  //std::cout << " ConvertedPhotonProducer recovering one track " << "\n";
484  trackPairRef.clear();
485  trackInnPos.clear();
486  trackPin.clear();
487  trackPout.clear();
488  std::vector<reco::TransientTrack>::const_iterator iTk=(iPair->first).begin();
489  //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";
490  const reco::TrackTransientTrack* ttt = dynamic_cast<const reco::TrackTransientTrack*>(iTk->basicTransientTrack());
491  reco::TrackRef myTk= ttt->persistentTrackRef();
492  if ( myTk->extra().isNonnull() ) {
493  trackInnPos.push_back( toFConverterP(myTk->innerPosition()));
494  trackPin.push_back( toFConverterV(myTk->innerMomentum()));
495  trackPout.push_back( toFConverterV(myTk->outerMomentum()));
496  }
497  trackPairRef.push_back(myTk);
498  //std::cout << " Provenance " << myTk->algoName() << std::endl;
499 
500  if ( recoverOneTrackCase_ ) {
501  float theta1 = myTk->innerMomentum().Theta();
502  float dCot=999.;
503  float dCotTheta=-999.;
504  reco::TrackRef goodRef;
505  std::vector<reco::TransientTrack>::const_iterator iGoodGenTran;
506  for ( std::vector<reco::TransientTrack>::const_iterator iTran= t_generalTrk.begin(); iTran != t_generalTrk.end(); ++iTran) {
507  const reco::TrackTransientTrack* ttt = dynamic_cast<const reco::TrackTransientTrack*>(iTran->basicTransientTrack());
508  reco::TrackRef trRef= ttt->persistentTrackRef();
509  if ( trRef->charge()*myTk->charge() > 0 ) continue;
510  float dEta = trRef->eta() - myTk->eta();
511  float dPhi = trRef->phi() - myTk->phi();
512  if ( sqrt (dEta*dEta + dPhi*dPhi) > dRForConversionRecovery_ ) continue;
513  float theta2 = trRef->innerMomentum().Theta();
514  dCotTheta = 1./tan(theta1) - 1./tan(theta2) ;
515  // std::cout << " ConvertedPhotonProducer recovering general transient track charge " << trRef->charge() << " momentum " << trRef->innerMomentum() << " dcotTheta " << fabs(dCotTheta) << std::endl;
516  if ( fabs(dCotTheta) < dCot ) {
517  dCot = fabs(dCotTheta);
518  goodRef = trRef;
519  iGoodGenTran=iTran;
520  }
521  }
522 
523  if ( goodRef.isNonnull() ) {
524 
525  minAppDist=calculateMinApproachDistance( myTk, goodRef);
526 
527  // std::cout << " ConvertedPhotonProducer chosen dCotTheta " << fabs(dCotTheta) << std::endl;
528  if ( fabs(dCotTheta) < deltaCotCut_ && minAppDist > minApproachDisCut_ ) {
529  trackInnPos.push_back( toFConverterP(goodRef->innerPosition()));
530  trackPin.push_back( toFConverterV(goodRef->innerMomentum()));
531  trackPout.push_back( toFConverterV(goodRef->outerMomentum()));
532  trackPairRef.push_back( goodRef );
533  // std::cout << " ConvertedPhotonProducer adding opposite charge track from generalTrackCollection charge " << goodRef ->charge() << " pt " << sqrt(goodRef->innerMomentum().perp2()) << " trackPairRef size " << trackPairRef.size() << std::endl;
534  //std::cout << " Track Provenenance " << goodRef->algoName() << std::endl;
535  std::vector<reco::TransientTrack> mypair;
536  mypair.push_back(*iTk);
537  mypair.push_back(*iGoodGenTran);
538 
539  try{
540  theVertexFinder_->run(iPair->first, theConversionVertex );
541 
542  }
543  catch ( cms::Exception& e ) {
544  //std::cout << " cms::Exception caught in ConvertedPhotonProducer::produce" << "\n" ;
545  edm::LogWarning(metname) << "cms::Exception caught in ConvertedPhotonProducer::produce\n"
546  << e.explainSelf();
547 
548  }
549  }
550 
551  }
552 
553  } // bool On/Off one track case recovery using generalTracks
554  double like = -999.;
555  reco::Conversion newCandidate(scPtrVec, trackPairRef, trkPositionAtEcal, theConversionVertex, matchingBC, minAppDist, trackInnPos, trackPin, trackPout, like, algo);
556  like = theLikelihoodCalc_->calculateLikelihood(newCandidate);
557  newCandidate.setMVAout(like);
558  outputConvPhotonCollection.push_back(newCandidate);
559 
560 
561 
562 
563  } // case with only on track: looking in general tracks
564 
565 
566 
567 
568  }
569 
570  }
571 
572 
573 
574 
575  }
576 
577 
578 
579 
580 
581 }
582 
583 
586  reco::ConversionCollection & outputConversionCollection) {
587 
588 
589  reco::Conversion* newCandidate=nullptr;
590  for(unsigned int lSC=0; lSC < scHandle->size(); lSC++) {
591 
592  // get pointer to SC
593  reco::CaloClusterPtr aClus= scHandle->ptrAt(lSC);
594 
595  // SC energy preselection
596  if (aClus->energy()/cosh(aClus->eta()) <= minSCEt_) continue;
597 
598 
599  if ( conversionHandle.isValid() ) {
600 
601  if ( risolveAmbiguity_ ) {
602  std::vector<reco::ConversionRef> bestRef=solveAmbiguity( conversionHandle , aClus);
603 
604  for ( std::vector<reco::ConversionRef>::iterator iRef=bestRef.begin(); iRef!=bestRef.end(); iRef++ ) {
605  if ( iRef->isNonnull() ) {
606  newCandidate= (*iRef)->clone();
607  outputConversionCollection.push_back(*newCandidate);
608  delete newCandidate;
609  }
610  }
611 
612  } else {
613 
614 
615  for( unsigned int icp = 0; icp < conversionHandle->size(); icp++) {
616  reco::ConversionRef cpRef(reco::ConversionRef(conversionHandle,icp));
617  if (!( aClus.id() == cpRef->caloCluster()[0].id() && aClus.key() == cpRef->caloCluster()[0].key() )) continue;
618  if ( !cpRef->isConverted() ) continue;
619  if ( cpRef->nTracks() <2 ) continue;
620  newCandidate= (&(*cpRef))->clone();
621  outputConversionCollection.push_back(*newCandidate);
622  delete newCandidate;
623 
624  }
625 
626  } // solve or not the ambiguity of many conversion candidates
627 
628  }
629 
630 
631  }
632 }
633 
634 
635 
636 
638  std::multimap<double, reco::ConversionRef, std::greater<double> > convMap;
639 
640  for ( unsigned int icp=0; icp< conversionHandle->size(); icp++) {
641  reco::ConversionRef cpRef(reco::ConversionRef(conversionHandle,icp));
642 
643  //std::cout << " cpRef " << cpRef->nTracks() << " " << cpRef ->caloCluster()[0]->energy() << std::endl;
644  if (!( scRef.id() == cpRef->caloCluster()[0].id() && scRef.key() == cpRef->caloCluster()[0].key() )) continue;
645  if ( !cpRef->isConverted() ) continue;
646  double like = cpRef->MVAout();
647  if ( cpRef->nTracks() <2 ) continue;
648  // std::cout << " Like " << like << std::endl;
649  convMap.insert ( std::make_pair(like,cpRef) );
650 
651  }
652 
653  // std::cout << " convMap size " << convMap.size() << std::endl;
654 
655  std::multimap<double, reco::ConversionRef>::iterator iMap;
656  std::vector<reco::ConversionRef> bestRefs;
657  for (iMap=convMap.begin(); iMap!=convMap.end(); iMap++) {
658  // std::cout << " Like list in the map " << iMap->first << " " << (iMap->second)->EoverP() << std::endl;
659  bestRefs.push_back( iMap->second );
660  if ( int(bestRefs.size()) == maxNumOfCandidates_ ) break;
661  }
662 
663 
664  return bestRefs;
665 
666 
667 }
668 
669 
670 
671 
672 
674  float dist=9999.;
675 
676  double x1, x2, y1, y2;
677  double xx_1 = track1->innerPosition().x(), yy_1 = track1->innerPosition().y(), zz_1 = track1->innerPosition().z();
678  double xx_2 = track2->innerPosition().x(), yy_2 = track2->innerPosition().y(), zz_2 = track2->innerPosition().z();
679  double radius1 = track1->innerMomentum().Rho()/(.3*(theMF_->inTesla(GlobalPoint(xx_1, yy_1, zz_1)).z()))*100;
680  double radius2 = track2->innerMomentum().Rho()/(.3*(theMF_->inTesla(GlobalPoint(xx_2, yy_2, zz_2)).z()))*100;
681  getCircleCenter(track1, radius1, x1, y1);
682  getCircleCenter(track2, radius2, x2, y2);
683  dist = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)) - radius1 - radius2;
684 
685  return dist;
686 
687 }
688 
689 
690 void ConvertedPhotonProducer::getCircleCenter(const reco::TrackRef& tk, double r, double& x0, double& y0){
691  double x1, y1, phi;
692  x1 = tk->innerPosition().x();//inner position and inner momentum need track Extra!
693  y1 = tk->innerPosition().y();
694  phi = tk->innerMomentum().phi();
695  const int charge = tk->charge();
696  x0 = x1 + r*sin(phi)*charge;
697  y0 = y1 - r*cos(phi)*charge;
698 
699 }
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:137
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:253
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:579
const std::string metname
virtual std::string explainSelf() const
Definition: Exception.cc:146
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
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:265
#define nullptr
std::vector< Conversion > ConversionCollection
collectin of Conversion objects
Definition: ConversionFwd.h:9
ProductID id() const
Accessor for product ID.
Definition: Ref.h:259
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
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:81
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.
std::vector< reco::ConversionRef > solveAmbiguity(const edm::OrphanHandle< reco::ConversionCollection > &conversionHandle, reco::CaloClusterPtr &sc)
T get() const
Definition: EventSetup.h:63
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:510
Definition: Run.h:44
void getCircleCenter(const reco::TrackRef &tk, double r, double &x0, double &y0)