48 theTrackPairFinder_(0),
101 theLikelihoodCalc_->setWeightsFile(path_mvaWeightFile.fullPath().c_str());
168 bool validBarrelSCHandle=
true;
171 if (!scBarrelHandle.isValid()) {
173 validBarrelSCHandle=
false;
177 bool validEndcapSCHandle=
true;
180 if (!scEndcapHandle.isValid()) {
182 validEndcapSCHandle=
false;
187 bool validTrackInputs=
true;
190 if (!outInTrkHandle.isValid()) {
192 edm::LogError(
"ConvertedPhotonProducer") <<
"Error! Can't get the conversionOITrack " <<
"\n";
193 validTrackInputs=
false;
201 if (!outInTrkSCAssocHandle.isValid()) {
204 validTrackInputs=
false;
210 if (!inOutTrkHandle.isValid()) {
212 edm::LogError(
"ConvertedPhotonProducer") <<
"Error! Can't get the conversionIOTrack " <<
"\n";
213 validTrackInputs=
false;
222 theEvent.
getByLabel(
"generalTracks", generalTrkHandle);
223 if (!generalTrkHandle.isValid()) {
225 edm::LogError(
"ConvertedPhotonProducer") <<
"Error! Can't get the genralTracks " <<
"\n";
232 if (!inOutTrkSCAssocHandle.isValid()) {
235 validTrackInputs=
false;
244 if (!bcBarrelHandle.isValid()) {
252 if (!bcEndcapHandle.isValid()) {
265 if ( validTrackInputs ) {
267 std::vector<reco::TransientTrack> t_outInTrk = ( *theTransientTrackBuilder_ ).build(outInTrkHandle );
268 std::vector<reco::TransientTrack> t_inOutTrk = ( *theTransientTrackBuilder_ ).build(inOutTrkHandle );
273 allPairs =
theTrackPairFinder_->
run(t_outInTrk, outInTrkHandle, outInTrkSCAssocHandle, t_inOutTrk, inOutTrkHandle, inOutTrkSCAssocHandle );
276 buildCollections(theEventSetup, scBarrelHandle, bcBarrelHandle, hcalTowersHandle, generalTrkHandle, allPairs, outputConvPhotonCollection);
277 buildCollections(theEventSetup, scEndcapHandle, bcEndcapHandle, hcalTowersHandle, generalTrkHandle, allPairs, outputConvPhotonCollection);
281 outputConvPhotonCollection_p->assign(outputConvPhotonCollection.begin(),outputConvPhotonCollection.end());
289 cleanedConversionCollection);
292 cleanedConversionCollection);
295 cleanedConversionCollection_p->assign(cleanedConversionCollection.begin(),cleanedConversionCollection.end());
318 std::vector<reco::TransientTrack> t_generalTrk;
319 if (
recoverOneTrackCase_ ) t_generalTrk = ( *theTransientTrackBuilder_ ).build(generalTrkHandle );
325 for (
unsigned i = 0;
i < scHandle->size(); ++
i ) {
329 if (aClus->energy()/cosh(aClus->eta()) <=
minSCEt_)
continue;
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;
357 if ( allPairs.size() ) {
362 for (
std::map<std::vector<reco::TransientTrack>,
reco::CaloClusterPtr>::const_iterator iPair= allPairs.begin(); iPair!= allPairs.end(); ++iPair ) {
367 if ( !( aClus == caloPtr ) )
continue;
372 std::vector<math::XYZPointF> trkPositionAtEcal = theEcalImpactPositionFinder.
find( iPair->first, bcHandle );
373 std::vector<reco::CaloClusterPtr> matchingBC = theEcalImpactPositionFinder.
matchingBC();
377 const std::string
metname =
"ConvertedPhotons|ConvertedPhotonProducer";
378 if ( (iPair->first).size() > 1 ) {
387 edm::LogWarning(metname) <<
"cms::Exception caught in ConvertedPhotonProducer::produce\n"
412 trackPairRef.clear();
418 for ( std::vector<reco::TransientTrack>::const_iterator iTk=(iPair->first).begin(); iTk!= (iPair->first).
end(); ++iTk) {
426 trackInnPos.push_back(
toFConverterP(myTkRef->innerPosition()));
427 trackPin.push_back(
toFConverterV( myTkRef->innerMomentum()));
428 trackPout.push_back(
toFConverterV(myTkRef->outerMomentum()));
430 trackPairRef.push_back(myTkRef);
438 if( theConversionVertex.
isValid() ) {
449 reco::Conversion newCandidate(scPtrVec, trackPairRef, trkPositionAtEcal, theConversionVertex, matchingBC, minAppDist, trackInnPos, trackPin, trackPout, like, algo);
454 outputConvPhotonCollection.push_back(newCandidate);
466 trackPairRef.clear();
470 std::vector<reco::TransientTrack>::const_iterator iTk=(iPair->first).
begin();
475 trackInnPos.push_back(
toFConverterP(myTk->innerPosition()));
479 trackPairRef.push_back(myTk);
483 float theta1 = myTk->innerMomentum().Theta();
485 float dCotTheta=-999.;
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) {
491 if ( trRef->charge()*myTk->charge() > 0 )
continue;
492 float dEta = trRef->eta() - myTk->eta();
493 float dPhi = trRef->phi() - myTk->phi();
495 float theta2 = trRef->innerMomentum().Theta();
496 dCotTheta = 1./
tan(theta1) - 1./
tan(theta2) ;
498 if ( fabs(dCotTheta) < dCot ) {
499 dCot = fabs(dCotTheta);
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 );
517 std::vector<reco::TransientTrack> mypair;
518 mypair.push_back(*iTk);
519 mypair.push_back(*iGoodGenTran);
527 edm::LogWarning(metname) <<
"cms::Exception caught in ConvertedPhotonProducer::produce\n"
537 reco::Conversion newCandidate(scPtrVec, trackPairRef, trkPositionAtEcal, theConversionVertex, matchingBC, minAppDist, trackInnPos, trackPin, trackPout, like, algo);
540 outputConvPhotonCollection.push_back(newCandidate);
572 for(
unsigned int lSC=0; lSC < scHandle->size(); lSC++) {
578 if (aClus->energy()/cosh(aClus->eta()) <=
minSCEt_)
continue;
581 if ( conversionHandle.
isValid() ) {
584 std::vector<reco::ConversionRef> bestRef=
solveAmbiguity( conversionHandle , aClus);
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);
597 for(
unsigned int icp = 0; icp < conversionHandle->size(); 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);
620 std::multimap<double, reco::ConversionRef, std::greater<double> > convMap;
622 for (
unsigned int icp=0; icp< conversionHandle->size(); icp++) {
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;
631 convMap.insert ( std::make_pair(like,cpRef) );
637 std::multimap<double, reco::ConversionRef>::iterator iMap;
638 std::vector<reco::ConversionRef> bestRefs;
639 for (iMap=convMap.begin(); iMap!=convMap.end(); iMap++) {
641 bestRefs.push_back( iMap->second );
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;
665 dist =
sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)) - radius1 - radius2;
674 x1 = tk->innerPosition().x();
675 y1 = tk->innerPosition().y();
676 phi = tk->innerMomentum().phi();
677 const int charge = tk->charge();
virtual void beginRun(edm::Run &r, edm::EventSetup const &es)
T getParameter(std::string const &) const
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
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)
TransientVertex run(std::vector< reco::TransientTrack > pair)
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)
virtual void endRun(edm::Run &r, edm::EventSetup const &es)
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_
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)
double getTowerESum(const reco::Candidate *, const std::vector< CaloTowerDetId > *detIdToExclude=0) const
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.
~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_
ConversionLikelihoodCalculator * theLikelihoodCalc_
math::XYZTLorentzVector LorentzVector
Lorentz vector.
edm::InputTag bcEndcapCollection_
bool recoverOneTrackCase_
void getCircleCenter(const reco::TrackRef &tk, double r, double &x0, double &y0)