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 
69  outInTrackSCAssociationCollection_ = conf_.getParameter<std::string>("outInTrackSCAssociation");
70  inOutTrackSCAssociationCollection_ = conf_.getParameter<std::string>("inOutTrackSCAssociation");
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 
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 
134 }
135 
136 
138 
139 
140  //LogDebug("ConvertedPhotonProducer") << "ConvertedPhotonProducer::endJob Processed " << nEvt_ << " events " << "\n";
141 
142 
143 }
144 
145 
146 
147 void ConvertedPhotonProducer::produce(edm::Event& theEvent, const edm::EventSetup& theEventSetup) {
148 
149  using namespace edm;
150  nEvt_++;
151 
152 
153  // LogDebug("ConvertedPhotonProducer") << "ConvertedPhotonProduce::produce event number " << theEvent.id() << " Global counter " << nEvt_ << "\n";
154  // std::cout << "ConvertedPhotonProduce::produce event number " << theEvent.id() << " Global counter " << nEvt_ << "\n";
155 
156  //
157  // create empty output collections
158  //
159  // Converted photon candidates
160  reco::ConversionCollection outputConvPhotonCollection;
161  std::auto_ptr<reco::ConversionCollection> outputConvPhotonCollection_p(new reco::ConversionCollection);
162  // Converted photon candidates
163  reco::ConversionCollection cleanedConversionCollection;
164  std::auto_ptr<reco::ConversionCollection> cleanedConversionCollection_p(new reco::ConversionCollection);
165 
166 
167  // Get the Super Cluster collection in the Barrel
168  bool validBarrelSCHandle=true;
170  theEvent.getByLabel(scHybridBarrelProducer_,scBarrelHandle);
171  if (!scBarrelHandle.isValid()) {
172  edm::LogError("ConvertedPhotonProducer") << "Error! Can't get the product "<<scHybridBarrelProducer_.label();
173  validBarrelSCHandle=false;
174  }
175 
176  // Get the Super Cluster collection in the Endcap
177  bool validEndcapSCHandle=true;
179  theEvent.getByLabel(scIslandEndcapProducer_,scEndcapHandle);
180  if (!scEndcapHandle.isValid()) {
181  edm::LogError("ConvertedPhotonProducer") << "Error! Can't get the product "<<scIslandEndcapProducer_.label();
182  validEndcapSCHandle=false;
183  }
184 
185 
187  bool validTrackInputs=true;
188  Handle<reco::TrackCollection> outInTrkHandle;
189  theEvent.getByLabel(conversionOITrackProducer_, outInTrkHandle);
190  if (!outInTrkHandle.isValid()) {
191  //std::cout << "Error! Can't get the conversionOITrack " << "\n";
192  edm::LogError("ConvertedPhotonProducer") << "Error! Can't get the conversionOITrack " << "\n";
193  validTrackInputs=false;
194  }
195  // LogDebug("ConvertedPhotonProducer")<< "ConvertedPhotonProducer outInTrack collection size " << (*outInTrkHandle).size() << "\n";
196 
197 
199  Handle<reco::TrackCaloClusterPtrAssociation> outInTrkSCAssocHandle;
201  if (!outInTrkSCAssocHandle.isValid()) {
202  // std::cout << "Error! Can't get the product " << outInTrackSCAssociationCollection_.c_str() <<"\n";
203  edm::LogError("ConvertedPhotonProducer") << "Error! Can't get the product " << outInTrackSCAssociationCollection_.c_str() <<"\n";
204  validTrackInputs=false;
205  }
206 
208  Handle<reco::TrackCollection> inOutTrkHandle;
209  theEvent.getByLabel(conversionIOTrackProducer_, inOutTrkHandle);
210  if (!inOutTrkHandle.isValid()) {
211  // std::cout << "Error! Can't get the conversionIOTrack " << "\n";
212  edm::LogError("ConvertedPhotonProducer") << "Error! Can't get the conversionIOTrack " << "\n";
213  validTrackInputs=false;
214  }
215  // LogDebug("ConvertedPhotonProducer") << " ConvertedPhotonProducer inOutTrack collection size " << (*inOutTrkHandle).size() << "\n";
216 
217 
219 
220  Handle<reco::TrackCollection> generalTrkHandle;
221  if ( recoverOneTrackCase_ ) {
222  theEvent.getByLabel("generalTracks", generalTrkHandle);
223  if (!generalTrkHandle.isValid()) {
224  //std::cout << "Error! Can't get the genralTracks " << "\n";
225  edm::LogError("ConvertedPhotonProducer") << "Error! Can't get the genralTracks " << "\n";
226  }
227  }
228 
230  Handle<reco::TrackCaloClusterPtrAssociation> inOutTrkSCAssocHandle;
232  if (!inOutTrkSCAssocHandle.isValid()) {
233  //std::cout << "Error! Can't get the product " << inOutTrackSCAssociationCollection_.c_str() <<"\n";
234  edm::LogError("ConvertedPhotonProducer") << "Error! Can't get the product " << inOutTrackSCAssociationCollection_.c_str() <<"\n";
235  validTrackInputs=false;
236  }
237 
238 
239 
240 
241  // Get the basic cluster collection in the Barrel
243  theEvent.getByLabel( bcBarrelCollection_, bcBarrelHandle);
244  if (!bcBarrelHandle.isValid()) {
245  edm::LogError("ConvertedPhotonProducer") << "Error! Can't get the product "<<bcBarrelCollection_.label();
246  }
247 
248 
249  // Get the basic cluster collection in the Endcap
251  theEvent.getByLabel( bcEndcapCollection_, bcEndcapHandle);
252  if (!bcEndcapHandle.isValid()) {
253  edm::LogError("ConvertedPhotonProducer") << "Error! Can't get the product "<<bcEndcapCollection_.label();
254  }
255 
256 
257 // get Hcal towers collection
258  Handle<CaloTowerCollection> hcalTowersHandle;
259  theEvent.getByLabel(hcalTowers_, hcalTowersHandle);
260 
261  // get the geometry from the event setup:
262  theEventSetup.get<CaloGeometryRecord>().get(theCaloGeom_);
263 
264 
265  if ( validTrackInputs ) {
266  //do the conversion:
267  std::vector<reco::TransientTrack> t_outInTrk = ( *theTransientTrackBuilder_ ).build(outInTrkHandle );
268  std::vector<reco::TransientTrack> t_inOutTrk = ( *theTransientTrackBuilder_ ).build(inOutTrkHandle );
269 
270 
272  std::map<std::vector<reco::TransientTrack>, reco::CaloClusterPtr, CompareTwoTracksVectors> allPairs;
273  allPairs = theTrackPairFinder_->run(t_outInTrk, outInTrkHandle, outInTrkSCAssocHandle, t_inOutTrk, inOutTrkHandle, inOutTrkSCAssocHandle );
274  //LogDebug("ConvertedPhotonProducer") << "ConvertedPhotonProducer allPairs.size " << allPairs.size() << "\n";
275 
276  buildCollections(theEventSetup, scBarrelHandle, bcBarrelHandle, hcalTowersHandle, generalTrkHandle, allPairs, outputConvPhotonCollection);
277  buildCollections(theEventSetup, scEndcapHandle, bcEndcapHandle, hcalTowersHandle, generalTrkHandle, allPairs, outputConvPhotonCollection);
278  }
279 
280  // put the product in the event
281  outputConvPhotonCollection_p->assign(outputConvPhotonCollection.begin(),outputConvPhotonCollection.end());
282  //LogDebug("ConvertedPhotonProducer") << " ConvertedPhotonProducer Putting in the event converted photon candidates " << (*outputConvPhotonCollection_p).size() << "\n";
284 
285 
286  // Loop over barrel and endcap SC collections and fill the photon collection
287  if ( validBarrelSCHandle) cleanCollections(scBarrelHandle,
289  cleanedConversionCollection);
290  if ( validEndcapSCHandle) cleanCollections(scEndcapHandle,
292  cleanedConversionCollection);
293 
294 
295  cleanedConversionCollection_p->assign(cleanedConversionCollection.begin(),cleanedConversionCollection.end());
296  theEvent.put( cleanedConversionCollection_p, CleanedConvertedPhotonCollection_);
297 
298 
299 }
300 
301 
303  const edm::Handle<edm::View<reco::CaloCluster> > & scHandle,
304  const edm::Handle<edm::View<reco::CaloCluster> > & bcHandle,
305  const edm::Handle<CaloTowerCollection> & hcalTowersHandle,
306  const edm::Handle<reco::TrackCollection> & generalTrkHandle,
307  std::map<std::vector<reco::TransientTrack>, reco::CaloClusterPtr, CompareTwoTracksVectors>& allPairs,
308  reco::ConversionCollection & outputConvPhotonCollection)
309 
310 {
311 
312  // instantiate the algorithm for finding the position of the track extrapolation at the Ecal front face
313  ConversionTrackEcalImpactPoint theEcalImpactPositionFinder( &(*theMF_) );
314 
315 
317 
318  std::vector<reco::TransientTrack> t_generalTrk;
319  if ( recoverOneTrackCase_ ) t_generalTrk = ( *theTransientTrackBuilder_ ).build(generalTrkHandle );
320  //const CaloGeometry* geometry = theCaloGeom_.product();
321 
322  // Loop over SC in the barrel and reconstruct converted photons
323  int myCands=0;
325  for (unsigned i = 0; i < scHandle->size(); ++i ) {
326  reco::CaloClusterPtr aClus= scHandle->ptrAt(i);
327 
328  // preselection based in Et and H/E cut
329  if (aClus->energy()/cosh(aClus->eta()) <= minSCEt_) continue;
330  const reco::CaloCluster* pClus=&(*aClus);
331  const reco::SuperCluster* sc=dynamic_cast<const reco::SuperCluster*>(pClus);
332  const CaloTowerCollection* hcalTowersColl = hcalTowersHandle.product();
333  EgammaTowerIsolation towerIso(hOverEConeSize_,0.,0.,-1,hcalTowersColl) ;
334  double HoE=towerIso.getTowerESum(sc)/sc->energy();
335  if (HoE>=maxHOverE_) continue;
337 
338 
339  std::vector<edm::Ref<reco::TrackCollection> > trackPairRef;
340  std::vector<math::XYZPointF> trackInnPos;
341  std::vector<math::XYZVectorF> trackPin;
342  std::vector<math::XYZVectorF> trackPout;
343  float minAppDist=-99;
344 
345  //LogDebug("ConvertedPhotonProducer") << "ConvertedPhotonProducer SC energy " << aClus->energy() << " eta " << aClus->eta() << " phi " << aClus->phi() << "\n";
346 
347 
349  const reco::Particle::Point vtx( 0, 0, 0 );
350 
351 
352  math::XYZVector direction =aClus->position() - vtx;
353  math::XYZVector momentum = direction.unit() * aClus->energy();
354  const reco::Particle::LorentzVector p4(momentum.x(), momentum.y(), momentum.z(), aClus->energy() );
355 
356  int nFound=0;
357  if ( allPairs.size() ) {
358 
359  nFound=0;
360 
361 
362  for ( std::map<std::vector<reco::TransientTrack>, reco::CaloClusterPtr>::const_iterator iPair= allPairs.begin(); iPair!= allPairs.end(); ++iPair ) {
363  scPtrVec.clear();
364 
365  reco::Vertex theConversionVertex;
366  reco::CaloClusterPtr caloPtr=iPair->second;
367  if ( !( aClus == caloPtr ) ) continue;
368 
369  scPtrVec.push_back(aClus);
370  nFound++;
371 
372  std::vector<math::XYZPointF> trkPositionAtEcal = theEcalImpactPositionFinder.find( iPair->first, bcHandle );
373  std::vector<reco::CaloClusterPtr> matchingBC = theEcalImpactPositionFinder.matchingBC();
374 
375 
376  minAppDist=-99;
377  const std::string metname = "ConvertedPhotons|ConvertedPhotonProducer";
378  if ( (iPair->first).size() > 1 ) {
379  try{
380 
381  theVertexFinder_->run(iPair->first, theConversionVertex );
382 
383 
384  }
385  catch ( cms::Exception& e ) {
386  //std::cout << " cms::Exception caught in ConvertedPhotonProducer::produce" << "\n" ;
387  edm::LogWarning(metname) << "cms::Exception caught in ConvertedPhotonProducer::produce\n"
388  << e.explainSelf();
389 
390  }
391 
392  // Old TwoTrackMinimumDistance md;
393  // Old md.calculate ( (iPair->first)[0].initialFreeState(), (iPair->first)[1].initialFreeState() );
394  // Old minAppDist = md.distance();
395 
396 
397 
398 
399 
400 
401 
402  /*
403  for ( unsigned int i=0; i< matchingBC.size(); ++i) {
404  if ( matchingBC[i].isNull() ) std::cout << " This ref to BC is null: skipping " << "\n";
405  else
406  std::cout << " BC energy " << matchingBC[i]->energy() << "\n";
407  }
408  */
409 
410 
412  trackPairRef.clear();
413  trackInnPos.clear();
414  trackPin.clear();
415  trackPout.clear();
416 
417 
418  for ( std::vector<reco::TransientTrack>::const_iterator iTk=(iPair->first).begin(); iTk!= (iPair->first).end(); ++iTk) {
419  //LogDebug("ConvertedPhotonProducer") << " ConvertedPhotonProducer Transient Tracks in the pair charge " << iTk->charge() << " Num of RecHits " << iTk->recHitsSize() << " inner momentum " << iTk->track().innerMomentum() << "\n";
420 
421  const reco::TrackTransientTrack* ttt = dynamic_cast<const reco::TrackTransientTrack*>(iTk->basicTransientTrack());
422  reco::TrackRef myTkRef= ttt->persistentTrackRef();
423 
424  //LogDebug("ConvertedPhotonProducer") << " ConvertedPhotonProducer Ref to Rec Tracks in the pair charge " << myTkRef->charge() << " Num of RecHits " << myTkRef->recHitsSize() << " inner momentum " << myTkRef->innerMomentum() << "\n";
425  if ( myTkRef->extra().isNonnull() ) {
426  trackInnPos.push_back( toFConverterP(myTkRef->innerPosition()));
427  trackPin.push_back( toFConverterV( myTkRef->innerMomentum()));
428  trackPout.push_back( toFConverterV(myTkRef->outerMomentum()));
429  }
430  trackPairRef.push_back(myTkRef);
431 
432  }
433 
434  // std::cout << " ConvertedPhotonProducer trackPin size " << trackPin.size() << std::endl;
435  //LogDebug("ConvertedPhotonProducer") << " ConvertedPhotonProducer SC energy " << aClus->energy() << "\n";
436  //LogDebug("ConvertedPhotonProducer") << " ConvertedPhotonProducer photon p4 " << p4 << "\n";
437  //LogDebug("ConvertedPhotonProducer") << " ConvertedPhotonProducer vtx " << vtx.x() << " " << vtx.y() << " " << vtx.z() << "\n";
438  if( theConversionVertex.isValid() ) {
439 
440  //LogDebug("ConvertedPhotonProducer") << " ConvertedPhotonProducer theConversionVertex " << theConversionVertex.position().x() << " " << theConversionVertex.position().y() << " " << theConversionVertex.position().z() << "\n";
441 
442  }
443  //LogDebug("ConvertedPhotonProducer") << " ConvertedPhotonProducer trackPairRef " << trackPairRef.size() << "\n";
444 
445 
446  minAppDist=calculateMinApproachDistance( trackPairRef[0], trackPairRef[1]);
447 
448  double like = -999.;
449  reco::Conversion newCandidate(scPtrVec, trackPairRef, trkPositionAtEcal, theConversionVertex, matchingBC, minAppDist, trackInnPos, trackPin, trackPout, like, algo);
450 // like = theLikelihoodCalc_->calculateLikelihood(newCandidate, es );
451  like = theLikelihoodCalc_->calculateLikelihood( newCandidate );
452 // std::cout << "like = " << like << std::endl;
453  newCandidate.setMVAout(like);
454  outputConvPhotonCollection.push_back(newCandidate);
455 
456 
457  myCands++;
458  //LogDebug("ConvertedPhotonProducer") << " ConvertedPhotonProducer Put the ConvertedPhotonCollection a candidate in the Barrel " << "\n";
459 
460  } else {
461 
462 
463  // std::cout << " ConvertedPhotonProducer case with only one track found " << "\n";
464 
465  //std::cout << " ConvertedPhotonProducer recovering one track " << "\n";
466  trackPairRef.clear();
467  trackInnPos.clear();
468  trackPin.clear();
469  trackPout.clear();
470  std::vector<reco::TransientTrack>::const_iterator iTk=(iPair->first).begin();
471  //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";
472  const reco::TrackTransientTrack* ttt = dynamic_cast<const reco::TrackTransientTrack*>(iTk->basicTransientTrack());
473  reco::TrackRef myTk= ttt->persistentTrackRef();
474  if ( myTk->extra().isNonnull() ) {
475  trackInnPos.push_back( toFConverterP(myTk->innerPosition()));
476  trackPin.push_back( toFConverterV(myTk->innerMomentum()));
477  trackPout.push_back( toFConverterV(myTk->outerMomentum()));
478  }
479  trackPairRef.push_back(myTk);
480  //std::cout << " Provenance " << myTk->algoName() << std::endl;
481 
482  if ( recoverOneTrackCase_ ) {
483  float theta1 = myTk->innerMomentum().Theta();
484  float dCot=999.;
485  float dCotTheta=-999.;
486  reco::TrackRef goodRef;
487  std::vector<reco::TransientTrack>::const_iterator iGoodGenTran;
488  for ( std::vector<reco::TransientTrack>::const_iterator iTran= t_generalTrk.begin(); iTran != t_generalTrk.end(); ++iTran) {
489  const reco::TrackTransientTrack* ttt = dynamic_cast<const reco::TrackTransientTrack*>(iTran->basicTransientTrack());
490  reco::TrackRef trRef= ttt->persistentTrackRef();
491  if ( trRef->charge()*myTk->charge() > 0 ) continue;
492  float dEta = trRef->eta() - myTk->eta();
493  float dPhi = trRef->phi() - myTk->phi();
494  if ( sqrt (dEta*dEta + dPhi*dPhi) > dRForConversionRecovery_ ) continue;
495  float theta2 = trRef->innerMomentum().Theta();
496  dCotTheta = 1./tan(theta1) - 1./tan(theta2) ;
497  // std::cout << " ConvertedPhotonProducer recovering general transient track charge " << trRef->charge() << " momentum " << trRef->innerMomentum() << " dcotTheta " << fabs(dCotTheta) << std::endl;
498  if ( fabs(dCotTheta) < dCot ) {
499  dCot = fabs(dCotTheta);
500  goodRef = trRef;
501  iGoodGenTran=iTran;
502  }
503  }
504 
505  if ( goodRef.isNonnull() ) {
506 
507  minAppDist=calculateMinApproachDistance( myTk, goodRef);
508 
509  // std::cout << " ConvertedPhotonProducer chosen dCotTheta " << fabs(dCotTheta) << std::endl;
510  if ( fabs(dCotTheta) < deltaCotCut_ && minAppDist > minApproachDisCut_ ) {
511  trackInnPos.push_back( toFConverterP(goodRef->innerPosition()));
512  trackPin.push_back( toFConverterV(goodRef->innerMomentum()));
513  trackPout.push_back( toFConverterV(goodRef->outerMomentum()));
514  trackPairRef.push_back( goodRef );
515  // std::cout << " ConvertedPhotonProducer adding opposite charge track from generalTrackCollection charge " << goodRef ->charge() << " pt " << sqrt(goodRef->innerMomentum().perp2()) << " trackPairRef size " << trackPairRef.size() << std::endl;
516  //std::cout << " Track Provenenance " << goodRef->algoName() << std::endl;
517  std::vector<reco::TransientTrack> mypair;
518  mypair.push_back(*iTk);
519  mypair.push_back(*iGoodGenTran);
520 
521  try{
522  theVertexFinder_->run(iPair->first, theConversionVertex );
523 
524  }
525  catch ( cms::Exception& e ) {
526  //std::cout << " cms::Exception caught in ConvertedPhotonProducer::produce" << "\n" ;
527  edm::LogWarning(metname) << "cms::Exception caught in ConvertedPhotonProducer::produce\n"
528  << e.explainSelf();
529 
530  }
531  }
532 
533  }
534 
535  } // bool On/Off one track case recovery using generalTracks
536  double like = -999.;
537  reco::Conversion newCandidate(scPtrVec, trackPairRef, trkPositionAtEcal, theConversionVertex, matchingBC, minAppDist, trackInnPos, trackPin, trackPout, like, algo);
538  like = theLikelihoodCalc_->calculateLikelihood(newCandidate);
539  newCandidate.setMVAout(like);
540  outputConvPhotonCollection.push_back(newCandidate);
541 
542 
543 
544 
545  } // case with only on track: looking in general tracks
546 
547 
548 
549 
550  }
551 
552  }
553 
554 
555 
556 
557  }
558 
559 
560 
561 
562 
563 }
564 
565 
568  reco::ConversionCollection & outputConversionCollection) {
569 
570 
571  reco::Conversion* newCandidate=0;
572  for(unsigned int lSC=0; lSC < scHandle->size(); lSC++) {
573 
574  // get pointer to SC
575  reco::CaloClusterPtr aClus= scHandle->ptrAt(lSC);
576 
577  // SC energy preselection
578  if (aClus->energy()/cosh(aClus->eta()) <= minSCEt_) continue;
579 
580 
581  if ( conversionHandle.isValid() ) {
582 
583  if ( risolveAmbiguity_ ) {
584  std::vector<reco::ConversionRef> bestRef=solveAmbiguity( conversionHandle , aClus);
585 
586  for ( std::vector<reco::ConversionRef>::iterator iRef=bestRef.begin(); iRef!=bestRef.end(); iRef++ ) {
587  if ( iRef->isNonnull() ) {
588  newCandidate= (*iRef)->clone();
589  outputConversionCollection.push_back(*newCandidate);
590  delete newCandidate;
591  }
592  }
593 
594  } else {
595 
596 
597  for( unsigned int icp = 0; icp < conversionHandle->size(); icp++) {
598  reco::ConversionRef cpRef(reco::ConversionRef(conversionHandle,icp));
599  if (!( aClus.id() == cpRef->caloCluster()[0].id() && aClus.key() == cpRef->caloCluster()[0].key() )) continue;
600  if ( !cpRef->isConverted() ) continue;
601  if ( cpRef->nTracks() <2 ) continue;
602  newCandidate= (&(*cpRef))->clone();
603  outputConversionCollection.push_back(*newCandidate);
604  delete newCandidate;
605 
606  }
607 
608  } // solve or not the ambiguity of many conversion candidates
609 
610  }
611 
612 
613  }
614 }
615 
616 
617 
618 
620  std::multimap<double, reco::ConversionRef, std::greater<double> > convMap;
621 
622  for ( unsigned int icp=0; icp< conversionHandle->size(); icp++) {
623  reco::ConversionRef cpRef(reco::ConversionRef(conversionHandle,icp));
624 
625  //std::cout << " cpRef " << cpRef->nTracks() << " " << cpRef ->caloCluster()[0]->energy() << std::endl;
626  if (!( scRef.id() == cpRef->caloCluster()[0].id() && scRef.key() == cpRef->caloCluster()[0].key() )) continue;
627  if ( !cpRef->isConverted() ) continue;
628  double like = cpRef->MVAout();
629  if ( cpRef->nTracks() <2 ) continue;
630  // std::cout << " Like " << like << std::endl;
631  convMap.insert ( std::make_pair(like,cpRef) );
632 
633  }
634 
635  // std::cout << " convMap size " << convMap.size() << std::endl;
636 
637  std::multimap<double, reco::ConversionRef>::iterator iMap;
638  std::vector<reco::ConversionRef> bestRefs;
639  for (iMap=convMap.begin(); iMap!=convMap.end(); iMap++) {
640  // std::cout << " Like list in the map " << iMap->first << " " << (iMap->second)->EoverP() << std::endl;
641  bestRefs.push_back( iMap->second );
642  if ( int(bestRefs.size()) == maxNumOfCandidates_ ) break;
643  }
644 
645 
646  return bestRefs;
647 
648 
649 }
650 
651 
652 
653 
654 
656  float dist=9999.;
657 
658  double x1, x2, y1, y2;
659  double xx_1 = track1->innerPosition().x(), yy_1 = track1->innerPosition().y(), zz_1 = track1->innerPosition().z();
660  double xx_2 = track2->innerPosition().x(), yy_2 = track2->innerPosition().y(), zz_2 = track2->innerPosition().z();
661  double radius1 = track1->innerMomentum().Rho()/(.3*(theMF_->inTesla(GlobalPoint(xx_1, yy_1, zz_1)).z()))*100;
662  double radius2 = track2->innerMomentum().Rho()/(.3*(theMF_->inTesla(GlobalPoint(xx_2, yy_2, zz_2)).z()))*100;
663  getCircleCenter(track1, radius1, x1, y1);
664  getCircleCenter(track2, radius2, x2, y2);
665  dist = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)) - radius1 - radius2;
666 
667  return dist;
668 
669 }
670 
671 
672 void ConvertedPhotonProducer::getCircleCenter(const reco::TrackRef& tk, double r, double& x0, double& y0){
673  double x1, y1, phi;
674  x1 = tk->innerPosition().x();//inner position and inner momentum need track Extra!
675  y1 = tk->innerPosition().y();
676  phi = tk->innerMomentum().phi();
677  const int charge = tk->charge();
678  x0 = x1 + r*sin(phi)*charge;
679  y0 = y1 - r*cos(phi)*charge;
680 
681 }
virtual void beginRun(edm::Run &r, edm::EventSetup const &es)
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
edm::ESHandle< CaloGeometry > theCaloGeom_
std::map< std::vector< reco::TransientTrack >, reco::CaloClusterPtr, CompareTwoTracksVectors > run(std::vector< reco::TransientTrack > outIn, const edm::Handle< reco::TrackCollection > &outInTrkHandle, const edm::Handle< reco::TrackCaloClusterPtrAssociation > &outInTrackSCAssH, std::vector< reco::TransientTrack > inOut, const edm::Handle< reco::TrackCollection > &inOutTrkHandle, const edm::Handle< reco::TrackCaloClusterPtrAssociation > &inOutTrackSCAssH)
ConversionTrackPairFinder * theTrackPairFinder_
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:167
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
TransientVertex run(std::vector< reco::TransientTrack > pair)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
T sqrt(T t)
Definition: SSEVec.h:46
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
virtual void endRun(edm::Run &r, edm::EventSetup const &es)
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
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
std::string inOutTrackSCAssociationCollection_
edm::ESHandle< MagneticField > theMF_
Conversion * clone() const
returns a clone of the candidate
Definition: Conversion.cc:175
double calculateLikelihood(reco::ConversionRef conversion)
double getTowerESum(const reco::Candidate *, const std::vector< CaloTowerDetId > *detIdToExclude=0) const
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:25
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
LimitAlgo * algo
Definition: Combine.cc:60
std::vector< reco::CaloClusterPtr > matchingBC() const
ConversionLikelihoodCalculator * theLikelihoodCalc_
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:25
Definition: Run.h:33
Definition: DDAxes.h:10
void getCircleCenter(const reco::TrackRef &tk, double r, double &x0, double &y0)