47 : conf_(config), theTrackPairFinder_(
nullptr), theVertexFinder_(
nullptr), theLikelihoodCalc_(
nullptr) {
67 edm::InputTag oitracks(oitrackprod), oitracksassoc(oitrackprod, oitrackassoc), iotracks(iotrackprod),
68 iotracksassoc(iotrackprod, iotrackassoc);
104 theLikelihoodCalc_->setWeightsFile(path_mvaWeightFile.fullPath().c_str());
139 auto outputConvPhotonCollection_p = std::make_unique<reco::ConversionCollection>();
142 auto cleanedConversionCollection_p = std::make_unique<reco::ConversionCollection>();
145 bool validBarrelSCHandle =
true;
148 if (!scBarrelHandle.
isValid()) {
149 edm::LogError(
"ConvertedPhotonProducer") <<
"Error! Can't get the scHybridBarrelProducer";
150 validBarrelSCHandle =
false;
154 bool validEndcapSCHandle =
true;
157 if (!scEndcapHandle.
isValid()) {
158 edm::LogError(
"ConvertedPhotonProducer") <<
"Error! Can't get the scIslandEndcapProducer";
159 validEndcapSCHandle =
false;
163 bool validTrackInputs =
true;
166 if (!outInTrkHandle.
isValid()) {
168 edm::LogError(
"ConvertedPhotonProducer") <<
"Error! Can't get the conversionOITrack " 170 validTrackInputs =
false;
177 if (!outInTrkSCAssocHandle.
isValid()) {
179 edm::LogError(
"ConvertedPhotonProducer") <<
"Error! Can't get the outInTrackSCAssociationCollection)";
180 validTrackInputs =
false;
186 if (!inOutTrkHandle.
isValid()) {
188 edm::LogError(
"ConvertedPhotonProducer") <<
"Error! Can't get the conversionIOTrack " 190 validTrackInputs =
false;
199 if (!generalTrkHandle.
isValid()) {
201 edm::LogError(
"ConvertedPhotonProducer") <<
"Error! Can't get the genralTracks " 209 if (!inOutTrkSCAssocHandle.
isValid()) {
211 edm::LogError(
"ConvertedPhotonProducer") <<
"Error! Can't get the inOutTrackSCAssociationCollection_.c_str()";
212 validTrackInputs =
false;
218 if (!bcBarrelHandle.
isValid()) {
219 edm::LogError(
"ConvertedPhotonProducer") <<
"Error! Can't get the bcBarrelCollection";
225 if (!bcEndcapHandle.
isValid()) {
226 edm::LogError(
"ConvertedPhotonProducer") <<
"Error! Can't get the bcEndcapCollection";
236 if (validTrackInputs) {
238 std::vector<reco::TransientTrack> t_outInTrk = (*theTransientTrackBuilder_).build(outInTrkHandle);
239 std::vector<reco::TransientTrack> t_inOutTrk = (*theTransientTrackBuilder_).build(inOutTrkHandle);
244 t_outInTrk, outInTrkHandle, outInTrkSCAssocHandle, t_inOutTrk, inOutTrkHandle, inOutTrkSCAssocHandle);
253 outputConvPhotonCollection);
260 outputConvPhotonCollection);
264 outputConvPhotonCollection_p->assign(outputConvPhotonCollection.begin(), outputConvPhotonCollection.end());
270 if (validBarrelSCHandle)
271 cleanCollections(scBarrelHandle, conversionHandle, cleanedConversionCollection);
272 if (validEndcapSCHandle)
273 cleanCollections(scEndcapHandle, conversionHandle, cleanedConversionCollection);
275 cleanedConversionCollection_p->assign(cleanedConversionCollection.begin(), cleanedConversionCollection.end());
294 std::vector<reco::TransientTrack> t_generalTrk;
296 t_generalTrk = (*theTransientTrackBuilder_).build(generalTrkHandle);
302 for (
auto const& aClus : scHandle->ptrs()) {
304 if (aClus->energy() / cosh(aClus->eta()) <=
minSCEt_)
315 std::vector<edm::Ref<reco::TrackCollection> > trackPairRef;
316 std::vector<math::XYZPointF> trackInnPos;
317 std::vector<math::XYZVectorF> trackPin;
318 std::vector<math::XYZVectorF> trackPout;
319 float minAppDist = -99;
331 if (!allPairs.empty()) {
335 iPair != allPairs.end();
341 if (!(aClus == caloPtr))
347 std::vector<math::XYZPointF> trkPositionAtEcal = theEcalImpactPositionFinder.
find(iPair->first, bcHandle);
348 std::vector<reco::CaloClusterPtr> matchingBC = theEcalImpactPositionFinder.
matchingBC();
352 if ((iPair->first).size() > 1) {
358 edm::LogWarning(metname) <<
"cms::Exception caught in ConvertedPhotonProducer::produce\n" 375 trackPairRef.clear();
380 for (std::vector<reco::TransientTrack>::const_iterator iTk = (iPair->first).begin();
381 iTk != (iPair->first).
end();
391 trackInnPos.push_back(
toFConverterP(myTkRef->innerPosition()));
393 trackPout.push_back(
toFConverterV(myTkRef->outerMomentum()));
395 trackPairRef.push_back(myTkRef);
402 if (theConversionVertex.
isValid()) {
425 outputConvPhotonCollection.push_back(newCandidate);
434 trackPairRef.clear();
438 std::vector<reco::TransientTrack>::const_iterator iTk = (iPair->first).
begin();
448 trackPairRef.push_back(myTk);
452 float theta1 = myTk->innerMomentum().Theta();
454 float dCotTheta = -999.;
456 std::vector<reco::TransientTrack>::const_iterator iGoodGenTran;
457 for (std::vector<reco::TransientTrack>::const_iterator iTran = t_generalTrk.begin();
458 iTran != t_generalTrk.end();
463 if (trRef->charge() * myTk->charge() > 0)
465 float dEta = trRef->eta() - myTk->eta();
466 float dPhi = trRef->phi() - myTk->phi();
469 float theta2 = trRef->innerMomentum().Theta();
470 dCotTheta = 1. /
tan(theta1) - 1. /
tan(theta2);
472 if (fabs(dCotTheta) < dCot) {
473 dCot = fabs(dCotTheta);
475 iGoodGenTran = iTran;
484 trackInnPos.push_back(
toFConverterP(goodRef->innerPosition()));
486 trackPout.push_back(
toFConverterV(goodRef->outerMomentum()));
487 trackPairRef.push_back(goodRef);
490 std::vector<reco::TransientTrack> mypair;
491 mypair.push_back(*iTk);
492 mypair.push_back(*iGoodGenTran);
499 edm::LogWarning(metname) <<
"cms::Exception caught in ConvertedPhotonProducer::produce\n" 520 outputConvPhotonCollection.push_back(newCandidate);
532 for (
auto const& aClus : scHandle->ptrs()) {
534 if (aClus->energy() / cosh(aClus->eta()) <=
minSCEt_)
537 if (conversionHandle.
isValid()) {
539 std::vector<reco::ConversionRef> bestRef =
solveAmbiguity(conversionHandle, aClus);
541 for (std::vector<reco::ConversionRef>::iterator iRef = bestRef.begin(); iRef != bestRef.end(); iRef++) {
542 if (iRef->isNonnull()) {
543 newCandidate = (*iRef)->
clone();
544 outputConversionCollection.push_back(*newCandidate);
550 for (
unsigned int icp = 0; icp < conversionHandle->size(); icp++) {
552 if (!(aClus.id() == cpRef->caloCluster()[0].
id() && aClus.key() == cpRef->caloCluster()[0].
key()))
554 if (!cpRef->isConverted())
556 if (cpRef->nTracks() < 2)
558 newCandidate = (&(*cpRef))->
clone();
559 outputConversionCollection.push_back(*newCandidate);
570 std::multimap<double, reco::ConversionRef, std::greater<double> > convMap;
572 for (
unsigned int icp = 0; icp < conversionHandle->size(); icp++) {
576 if (!(scRef.
id() == cpRef->caloCluster()[0].
id() && scRef.
key() == cpRef->caloCluster()[0].
key()))
578 if (!cpRef->isConverted())
580 double like = cpRef->MVAout();
581 if (cpRef->nTracks() < 2)
584 convMap.insert(std::make_pair(like, cpRef));
589 std::multimap<double, reco::ConversionRef>::iterator iMap;
590 std::vector<reco::ConversionRef> bestRefs;
591 for (iMap = convMap.begin(); iMap != convMap.end(); iMap++) {
593 bestRefs.push_back(iMap->second);
606 double xx_1 = track1->innerPosition().x(), yy_1 = track1->innerPosition().y(), zz_1 = track1->innerPosition().z();
607 double xx_2 = track2->innerPosition().x(), yy_2 = track2->innerPosition().y(), zz_2 = track2->innerPosition().z();
612 dist =
sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) - radius1 - radius2;
619 x1 = tk->innerPosition().x();
620 y1 = tk->innerPosition().y();
621 phi = tk->innerMomentum().phi();
622 const int charge = tk->charge();
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.
bool isNonnull() const
Checks for non-null.
TransientVertex run(const std::vector< reco::TransientTrack > &pair)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
const std::string metname
virtual std::string explainSelf() const
void push_back(Ptr< T > const &iPtr)
edm::EDGetTokenT< reco::TrackCollection > conversionIOTrackProducer_
edm::ESHandle< TransientTrackBuilder > theTransientTrackBuilder_
bool isValid() const
Tells whether the vertex is valid.
Sin< T >::type sin(const T &t)
ConversionVertexFinder * theVertexFinder_
Global3DPoint GlobalPoint
edm::EDGetTokenT< edm::View< reco::CaloCluster > > scIslandEndcapProducer_
std::string CleanedConvertedPhotonCollection_
static ConversionAlgorithm algoByName(const std::string &name)
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
key_type key() const
Accessor for product key.
std::vector< Conversion > ConversionCollection
collectin of Conversion objects
ProductID id() const
Accessor for product ID.
double minApproachDisCut_
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)
Cos< T >::type cos(const T &t)
edm::EDGetTokenT< CaloTowerCollection > hcalTowers_
Tan< T >::type tan(const T &t)
math::XYZPoint Point
point in the space
std::vector< reco::ConversionRef > solveAmbiguity(const edm::OrphanHandle< reco::ConversionCollection > &conversionHandle, reco::CaloClusterPtr const &sc)
double dRForConversionRecovery_
float calculateMinApproachDistance(const reco::TrackRef &track1, const reco::TrackRef &track2)
double energy() const
cluster energy
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)
std::string likelihoodWeights_
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.
std::string ConvertedPhotonCollection_
edm::ESHandle< MagneticField > theMF_
Conversion * clone() const
returns a clone of the candidate
double calculateLikelihood(reco::ConversionRef conversion)
edm::EDGetTokenT< edm::View< reco::CaloCluster > > bcBarrelCollection_
edm::EDGetTokenT< edm::View< reco::CaloCluster > > scHybridBarrelProducer_
T const * product() const
XYZVectorD XYZVector
spatial vector with cartesian internal representation
void produce(edm::Event &evt, const edm::EventSetup &es) override
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
void setMVAout(const float &mva)
set the value of the TMVA output
ProductID id() const
Accessor for product ID.
ConvertedPhotonProducer(const edm::ParameterSet &ps)
void clear()
Clear the PtrVector.
~ConvertedPhotonProducer() override
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.
bool recoverOneTrackCase_
void getCircleCenter(const reco::TrackRef &tk, double r, double &x0, double &y0)