CMS 3D CMS Logo

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