48 theTrackPairFinder_(0),
101 theLikelihoodCalc_->setWeightsFile(path_mvaWeightFile.fullPath().c_str());
155 bool validBarrelSCHandle=
true;
158 if (!scBarrelHandle.isValid()) {
160 validBarrelSCHandle=
false;
164 bool validEndcapSCHandle=
true;
167 if (!scEndcapHandle.isValid()) {
169 validEndcapSCHandle=
false;
174 bool validTrackInputs=
true;
177 if (!outInTrkHandle.isValid()) {
179 edm::LogError(
"ConvertedPhotonProducer") <<
"Error! Can't get the conversionOITrack " <<
"\n";
180 validTrackInputs=
false;
188 if (!outInTrkSCAssocHandle.isValid()) {
191 validTrackInputs=
false;
197 if (!inOutTrkHandle.isValid()) {
199 edm::LogError(
"ConvertedPhotonProducer") <<
"Error! Can't get the conversionIOTrack " <<
"\n";
200 validTrackInputs=
false;
209 theEvent.
getByLabel(
"generalTracks", generalTrkHandle);
210 if (!generalTrkHandle.isValid()) {
212 edm::LogError(
"ConvertedPhotonProducer") <<
"Error! Can't get the genralTracks " <<
"\n";
219 if (!inOutTrkSCAssocHandle.isValid()) {
222 validTrackInputs=
false;
231 if (!bcBarrelHandle.isValid()) {
239 if (!bcEndcapHandle.isValid()) {
252 if ( validTrackInputs ) {
254 std::vector<reco::TransientTrack> t_outInTrk = ( *theTransientTrackBuilder_ ).build(outInTrkHandle );
255 std::vector<reco::TransientTrack> t_inOutTrk = ( *theTransientTrackBuilder_ ).build(inOutTrkHandle );
260 allPairs =
theTrackPairFinder_->
run(t_outInTrk, outInTrkHandle, outInTrkSCAssocHandle, t_inOutTrk, inOutTrkHandle, inOutTrkSCAssocHandle );
263 buildCollections(theEventSetup, scBarrelHandle, bcBarrelHandle, hcalTowersHandle, generalTrkHandle, allPairs, outputConvPhotonCollection);
264 buildCollections(theEventSetup, scEndcapHandle, bcEndcapHandle, hcalTowersHandle, generalTrkHandle, allPairs, outputConvPhotonCollection);
268 outputConvPhotonCollection_p->assign(outputConvPhotonCollection.begin(),outputConvPhotonCollection.end());
276 cleanedConversionCollection);
279 cleanedConversionCollection);
282 cleanedConversionCollection_p->assign(cleanedConversionCollection.begin(),cleanedConversionCollection.end());
305 std::vector<reco::TransientTrack> t_generalTrk;
306 if (
recoverOneTrackCase_ ) t_generalTrk = ( *theTransientTrackBuilder_ ).build(generalTrkHandle );
312 for (
unsigned i = 0;
i < scHandle->size(); ++
i ) {
316 if (aClus->energy()/cosh(aClus->eta()) <=
minSCEt_)
continue;
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;
344 if ( allPairs.size() ) {
349 for (
std::map<std::vector<reco::TransientTrack>,
reco::CaloClusterPtr>::const_iterator iPair= allPairs.begin(); iPair!= allPairs.end(); ++iPair ) {
354 if ( !( aClus == caloPtr ) )
continue;
359 std::vector<math::XYZPointF> trkPositionAtEcal = theEcalImpactPositionFinder.
find( iPair->first, bcHandle );
360 std::vector<reco::CaloClusterPtr> matchingBC = theEcalImpactPositionFinder.
matchingBC();
365 if ( (iPair->first).size() > 1 ) {
374 edm::LogWarning(metname) <<
"cms::Exception caught in ConvertedPhotonProducer::produce\n"
399 trackPairRef.clear();
405 for ( std::vector<reco::TransientTrack>::const_iterator iTk=(iPair->first).begin(); iTk!= (iPair->first).
end(); ++iTk) {
413 trackInnPos.push_back(
toFConverterP(myTkRef->innerPosition()));
414 trackPin.push_back(
toFConverterV( myTkRef->innerMomentum()));
415 trackPout.push_back(
toFConverterV(myTkRef->outerMomentum()));
417 trackPairRef.push_back(myTkRef);
425 if( theConversionVertex.
isValid() ) {
436 reco::Conversion newCandidate(scPtrVec, trackPairRef, trkPositionAtEcal, theConversionVertex, matchingBC, minAppDist, trackInnPos, trackPin, trackPout, like, algo);
441 outputConvPhotonCollection.push_back(newCandidate);
453 trackPairRef.clear();
457 std::vector<reco::TransientTrack>::const_iterator iTk=(iPair->first).
begin();
462 trackInnPos.push_back(
toFConverterP(myTk->innerPosition()));
466 trackPairRef.push_back(myTk);
470 float theta1 = myTk->innerMomentum().Theta();
472 float dCotTheta=-999.;
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) {
478 if ( trRef->charge()*myTk->charge() > 0 )
continue;
479 float dEta = trRef->eta() - myTk->eta();
480 float dPhi = trRef->phi() - myTk->phi();
482 float theta2 = trRef->innerMomentum().Theta();
483 dCotTheta = 1./
tan(theta1) - 1./
tan(theta2) ;
485 if ( fabs(dCotTheta) < dCot ) {
486 dCot = fabs(dCotTheta);
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 );
504 std::vector<reco::TransientTrack> mypair;
505 mypair.push_back(*iTk);
506 mypair.push_back(*iGoodGenTran);
514 edm::LogWarning(metname) <<
"cms::Exception caught in ConvertedPhotonProducer::produce\n"
524 reco::Conversion newCandidate(scPtrVec, trackPairRef, trkPositionAtEcal, theConversionVertex, matchingBC, minAppDist, trackInnPos, trackPin, trackPout, like, algo);
527 outputConvPhotonCollection.push_back(newCandidate);
559 for(
unsigned int lSC=0; lSC < scHandle->size(); lSC++) {
565 if (aClus->energy()/cosh(aClus->eta()) <=
minSCEt_)
continue;
568 if ( conversionHandle.
isValid() ) {
571 std::vector<reco::ConversionRef> bestRef=
solveAmbiguity( conversionHandle , aClus);
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);
584 for(
unsigned int icp = 0; icp < conversionHandle->size(); 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);
607 std::multimap<double, reco::ConversionRef, std::greater<double> > convMap;
609 for (
unsigned int icp=0; icp< conversionHandle->size(); icp++) {
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;
618 convMap.insert ( std::make_pair(like,cpRef) );
624 std::multimap<double, reco::ConversionRef>::iterator iMap;
625 std::vector<reco::ConversionRef> bestRefs;
626 for (iMap=convMap.begin(); iMap!=convMap.end(); iMap++) {
628 bestRefs.push_back( iMap->second );
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;
652 dist =
sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)) - radius1 - radius2;
661 x1 = tk->innerPosition().x();
662 y1 = tk->innerPosition().y();
663 phi = tk->innerMomentum().phi();
664 const int charge = tk->charge();
T getParameter(std::string const &) const
edm::ESHandle< CaloGeometry > theCaloGeom_
ConversionTrackPairFinder * theTrackPairFinder_
TransientVertex run(const std::vector< reco::TransientTrack > &pair)
const std::string metname
virtual std::string explainSelf() const
void push_back(Ptr< T > const &iPtr)
edm::ESHandle< TransientTrackBuilder > theTransientTrackBuilder_
bool isValid() const
Tells whether the vertex is valid.
Sin< T >::type sin(const T &t)
ConversionVertexFinder * theVertexFinder_
Global3DPoint GlobalPoint
std::string CleanedConvertedPhotonCollection_
edm::InputTag bcBarrelCollection_
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
std::vector< Conversion > ConversionCollection
collectin of Conversion objects
double minApproachDisCut_
bool isNonnull() const
Checks for non-null.
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)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
std::string conversionIOTrackProducer_
ProductID id() const
Accessor for product ID.
Cos< T >::type cos(const T &t)
Tan< T >::type tan(const T &t)
math::XYZPoint Point
point in the space
double dRForConversionRecovery_
float calculateMinApproachDistance(const reco::TrackRef &track1, const reco::TrackRef &track2)
double energy() const
cluster energy
edm::InputTag scHybridBarrelProducer_
std::vector< math::XYZPointF > find(const std::vector< reco::TransientTrack > &tracks, const edm::Handle< edm::View< reco::CaloCluster > > &bcHandle)
std::string likelihoodWeights_
std::string conversionOITrackProducer_
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
std::string ConvertedPhotonCollection_
std::string inOutTrackSCAssociationCollection_
edm::ESHandle< MagneticField > theMF_
Conversion * clone() const
returns a clone of the candidate
double calculateLikelihood(reco::ConversionRef conversion)
XYZVectorD XYZVector
spatial vector with cartesian internal representation
key_type key() const
Accessor for product key.
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
void setMVAout(const float &mva)
set the value of the TMVA output
T const * product() const
ConvertedPhotonProducer(const edm::ParameterSet &ps)
virtual void produce(edm::Event &evt, const edm::EventSetup &es)
void clear()
Clear the PtrVector.
virtual ~ConvertedPhotonProducer()
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.
edm::InputTag hcalTowers_
std::vector< reco::CaloClusterPtr > matchingBC() const
edm::InputTag scIslandEndcapProducer_
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.
edm::InputTag bcEndcapCollection_
bool recoverOneTrackCase_
void getCircleCenter(const reco::TrackRef &tk, double r, double &x0, double &y0)