58 constexpr
float square(
float x) {
return x *
x; };
68 return std::make_unique<convbremhelpers::HeavyObjectCache>(conf);
88 std::vector<unsigned int>& secondaries,
95 bool& bothGsfEcalDriven,
103 bool& bothGsfTrackerDriven,
114 std::vector<reco::GsfPFRecTrack>& gsfPFRecTrackPrimary,
115 const std::map<
unsigned int, std::vector<reco::GsfPFRecTrack> >& MapPrimSec);
176 using namespace reco;
202 produces<GsfPFRecTrackCollection>();
203 produces<GsfPFRecTrackCollection>(
"Secondary").setBranchAlias(
"secondary");
235 auto gsfPFRecTrackCollection = std::make_unique<GsfPFRecTrackCollection>();
237 auto gsfPFRecTrackCollectionSecondary = std::make_unique<GsfPFRecTrackCollection>();
252 auto trackEtaPhiTable = makeLazy<edm::soa::EtaPhiTable>(*thePfRecTrackCollection);
279 vector<Trajectory> tjvec(0);
286 vector<reco::GsfPFRecTrack> selGsfPFRecTracks;
287 vector<reco::GsfPFRecTrack> primaryGsfPFRecTracks;
288 std::map<unsigned int, std::vector<reco::GsfPFRecTrack> > GsfPFMap;
290 for (
unsigned igsf = 0; igsf < gsftracks.size(); igsf++) {
301 for (
unsigned int igsf = 0; igsf < gsftracks.size(); igsf++) {
304 int kf_ind =
findPfRef(*thePfRecTrackCollection, gsftracks[igsf], trackEtaPhiTable.value());
312 bool isEcalDriven =
true;
313 bool isTrackerDriven =
true;
315 if (trackRef->seedRef().
get() ==
nullptr) {
316 isEcalDriven =
false;
317 isTrackerDriven =
false;
319 auto const& SeedFromRef =
static_cast<ElectronSeed const&
>(*(trackRef->extra()->seedRef()));
320 if (SeedFromRef.caloCluster().isNull())
321 isEcalDriven =
false;
322 if (SeedFromRef.ctfTrack().isNull())
323 isTrackerDriven =
false;
346 bool validgsfbrem =
false;
357 if (validgsfbrem && passSel)
358 selGsfPFRecTracks.push_back(
pftrack_);
361 unsigned int count_primary = 0;
362 if (!selGsfPFRecTracks.empty()) {
363 for (
unsigned int ipfgsf = 0; ipfgsf < selGsfPFRecTracks.size(); ipfgsf++) {
364 vector<unsigned int> secondaries(0);
369 keepGsf =
resolveGsfTracks(selGsfPFRecTracks, ipfgsf, secondaries, theEcalClusters);
373 if (keepGsf ==
true) {
376 thePrimaryVertexColl,
385 selGsfPFRecTracks[ipfgsf])) {
386 const vector<PFRecTrackRef>& convBremPFRecTracks(
convBremFinder_->getConvBremPFRecTracks());
387 for (
unsigned int ii = 0;
ii < convBremPFRecTracks.size();
ii++) {
388 selGsfPFRecTracks[ipfgsf].addConvBremPFRecTrackRef(convBremPFRecTracks[
ii]);
394 primaryGsfPFRecTracks.push_back(selGsfPFRecTracks[ipfgsf]);
399 unsigned int primGsfIndex = selGsfPFRecTracks[ipfgsf].trackId();
400 vector<reco::GsfPFRecTrack> trueGsfPFRecTracks;
401 if (!secondaries.empty()) {
403 for (
unsigned int isecpfgsf = 0; isecpfgsf < secondaries.size(); isecpfgsf++) {
404 PFRecTrackRef refsecKF = selGsfPFRecTracks[(secondaries[isecpfgsf])].kfPFRecTrackRef();
406 unsigned int secGsfIndex = selGsfPFRecTracks[(secondaries[isecpfgsf])].trackId();
407 GsfTrackRef secGsfRef = selGsfPFRecTracks[(secondaries[isecpfgsf])].gsfTrackRef();
420 bool validgsfbrem =
false;
429 gsfPFRecTrackCollectionSecondary->push_back(
secpftrack_);
434 GsfPFMap.insert(pair<
unsigned int, std::vector<reco::GsfPFRecTrack> >(count_primary, trueGsfPFRecTracks));
435 trueGsfPFRecTracks.clear();
447 for (
unsigned int iGSF = 0; iGSF < primaryGsfPFRecTracks.size(); iGSF++) {
448 gsfPFRecTrackCollection->push_back(primaryGsfPFRecTracks[iGSF]);
452 selGsfPFRecTracks.clear();
454 primaryGsfPFRecTracks.clear();
462 std::vector<reco::GsfPFRecTrack>& gsfPFRecTrackPrimary,
463 const std::map<
unsigned int, std::vector<reco::GsfPFRecTrack> >& MapPrimSec) {
464 unsigned int cgsf = 0;
465 unsigned int csecgsf = 0;
466 for (
std::map<
unsigned int, std::vector<reco::GsfPFRecTrack> >::const_iterator igsf = MapPrimSec.begin();
467 igsf != MapPrimSec.end();
469 vector<reco::GsfPFRecTrack> SecGsfPF = igsf->second;
470 for (
unsigned int iSecGsf = 0; iSecGsf < SecGsfPF.size(); iSecGsf++) {
472 gsfPFRecTrackPrimary[cgsf].addConvBremGsfPFRecTrackRef(refgprt);
488 constexpr
float maxDR2 =
square(0.05
f);
491 float gsftkEta = gsftk.
eta();
492 float gsftkPhi = gsftk.
phi();
497 if (electronSeedFromRef.ctfTrack().isNull()) {
498 unsigned int i_pf = 0;
500 unsigned int ish_max = 0;
501 float dr2_min =
square(1000.
f);
505 for (
auto const& pft : trackEtaPhiTable) {
506 unsigned int ish = 0;
512 for (
auto const& hhit : pfRTkColl[i_pf].trackRef()->
recHits()) {
513 if (!hhit->isValid())
515 for (
auto const&
hit : gsftkHits) {
521 if ((ish > ish_max) || ((ish == ish_max) && (dr2 < dr2_min))) {
531 return ((ish_max == 0) || (dr2_min > maxDR2)) ? -1 : ibest;
535 unsigned int i_pf = 0;
537 for (
auto const& pft : pfRTkColl) {
539 if (pft.trackRef() == electronSeedFromRef.ctfTrack()) {
554 bool passCut =
false;
555 if (ElSeedFromRef.ctfTrack().isNull()) {
556 if (ElSeedFromRef.caloCluster().isNull())
558 auto const* scRef =
static_cast<SuperCluster const*
>(ElSeedFromRef.caloCluster().get());
561 float caloEne = scRef->energy();
563 float fphi = fabs(scRef->phi() - gsftk.
phiMode());
577 vector<unsigned int>& secondaries,
580 bool n_keepGsf =
true;
584 if (nGsfTrack->seedRef().
get() ==
nullptr)
586 auto const& nElSeedFromRef =
static_cast<ElectronSeed const&
>(*(nGsfTrack->extra()->seedRef()));
599 float neta = nGsfTrack->innerMomentum().eta();
600 float nphi = nGsfTrack->innerMomentum().phi();
603 cout <<
" PFElecTkProducer:: considering track " << nGsfTrack->pt() <<
" eta,phi " << nGsfTrack->eta() <<
", " 604 << nGsfTrack->phi() << endl;
606 for (
unsigned int igsf = 0; igsf < GsfPFVec.size(); igsf++) {
611 cout <<
" PFElecTkProducer:: and comparing with track " << iGsfTrack->pt() <<
" eta,phi " << iGsfTrack->eta()
612 <<
", " << iGsfTrack->phi() << endl;
614 float ieta = iGsfTrack->innerMomentum().eta();
615 float iphi = iGsfTrack->innerMomentum().phi();
622 if (
feta < 0.5 && fabs(fphi) < 1.0) {
624 cout <<
" Entering angular superloose preselection " << endl;
637 if (iGsfTrack->seedRef().
get() ==
nullptr)
639 auto const& iElSeedFromRef =
static_cast<ElectronSeed const&
>(*(iGsfTrack->extra()->seedRef()));
643 bool areBothGsfEcalDriven =
false;
645 bool isSameSC =
isSameEgSC(nElSeedFromRef, iElSeedFromRef, areBothGsfEcalDriven,
SCEnergy);
648 if (areBothGsfEcalDriven) {
653 cout <<
" Entering SAME supercluster case " 654 <<
" nEP " << nEP <<
" iEP " << iEP << endl;
660 bool isSameLayer =
false;
664 cout <<
" iGsf is InnerMostWithLostHits " << iGsfInnermostWithLostHits <<
" isSameLayer " << isSameLayer
667 if (iGsfInnermostWithLostHits) {
670 }
else if (isSameLayer) {
671 if (fabs(iEP - 1) < fabs(nEP - 1)) {
675 secondaries.push_back(igsf);
679 secondaries.push_back(igsf);
684 float minBremDphi =
minTangDist(GsfPFVec[ngsf], GsfPFVec[igsf]);
687 bool isBothGsfTrackerDriven =
false;
688 bool nEcalDriven =
false;
689 bool iEcalDriven =
false;
695 isBothGsfTrackerDriven,
702 bool isSameLayer =
false;
709 cout <<
" Sharing ECAL energy passed " 710 <<
" nEtot " << nETot <<
" iEtot " << iETot << endl;
711 if (isBothGsfTrackerDriven)
712 cout <<
" Both Track are trackerDriven " << endl;
716 if (iGsfInnermostWithLostHits) {
719 }
else if (isSameLayer) {
727 if (isBothGsfTrackerDriven ==
false) {
733 secondaries.push_back(igsf);
740 if (nETot != iETot) {
748 float nEP = ETot / nPin;
749 float iEP = ETot / iPin;
752 cout <<
" nETot " << nETot <<
" iETot " << iETot <<
" ETot " << ETot << endl
753 <<
" nPin " << nPin <<
" iPin " << iPin <<
" nEP " << nEP <<
" iEP " << iEP << endl;
755 if (fabs(iEP - 1) < fabs(nEP - 1)) {
759 secondaries.push_back(igsf);
763 secondaries.push_back(igsf);
767 bool secPushedBack =
false;
768 if (nEcalDriven ==
false && nETot == 0.) {
771 }
else if (iEcalDriven ==
false && iETot == 0.) {
772 secondaries.push_back(igsf);
773 secPushedBack =
true;
776 cout <<
" Close Tracks " 777 <<
" feta " <<
feta <<
" fabs(fphi) " << fabs(fphi) <<
" minBremDphi " << minBremDphi <<
" nETot " 778 << nETot <<
" iETot " << iETot <<
" nLostHits " << nGsfTrack->missingInnerHits() <<
" iLostHits " 779 << iGsfTrack->missingInnerHits() << endl;
783 if (iGsfInnermostWithLostHits) {
786 }
else if (isSameLayer ==
false) {
787 if (secPushedBack ==
false)
788 secondaries.push_back(igsf);
791 }
else if (
feta < 0.1 && minBremDphi < 0.2) {
795 cout <<
" Close Tracks and failed all the conditions " 796 <<
" feta " <<
feta <<
" fabs(fphi) " << fabs(fphi) <<
" minBremDphi " << minBremDphi <<
" nETot " 797 << nETot <<
" iETot " << iETot <<
" nLostHits " << nGsfTrack->missingInnerHits() <<
" iLostHits " 798 << iGsfTrack->missingInnerHits() << endl;
800 if (nEcalDriven ==
false && nETot == 0.) {
816 std::vector<reco::PFBrem> primPFBrem = primGsf.
PFRecBrem();
817 std::vector<reco::PFBrem> secPFBrem = secGsf.
PFRecBrem();
819 unsigned int cbrem = 0;
820 for (
unsigned isbrem = 0; isbrem < secPFBrem.size(); isbrem++) {
821 if (secPFBrem[isbrem].indTrajPoint() == 99)
829 unsigned int sbrem = 0;
830 for (
unsigned ipbrem = 0; ipbrem < primPFBrem.size(); ipbrem++) {
831 if (primPFBrem[ipbrem].indTrajPoint() == 99)
841 float dphi = fabs(primPhi - secPhi);
858 bool& bothGsfEcalDriven,
860 bool isSameSC =
false;
866 if (nscRef && iscRef) {
867 bothGsfEcalDriven =
true;
868 if (nscRef == iscRef) {
882 bool& bothGsfTrackerDriven,
887 bool isSharingEnergy =
false;
890 bool oneEcalDriven =
true;
897 nEnergy = scRef->
energy();
899 gsfPfTrack = iGsfPFRecTrack;
903 iEnergy = scRef->
energy();
905 gsfPfTrack = nGsfPFRecTrack;
907 oneEcalDriven =
false;
913 vector<PFCluster> vecPFClusters;
914 vecPFClusters.clear();
916 for (PFClusterCollection::const_iterator clus = theEClus.begin(); clus != theEClus.end(); clus++) {
927 if (deta < 0.5 && fabs(dphi) < 1.0) {
934 iEnergy += clust.
energy();
936 nEnergy += clust.
energy();
937 vecPFClusters.push_back(clust);
941 vector<PFBrem> primPFBrem = gsfPfTrack.
PFRecBrem();
942 for (
unsigned ipbrem = 0; ipbrem < primPFBrem.size(); ipbrem++) {
943 if (primPFBrem[ipbrem].indTrajPoint() == 99)
951 iEnergy += clust.
energy();
953 nEnergy += clust.
energy();
954 vecPFClusters.push_back(clust);
960 if (!vecPFClusters.empty()) {
961 for (
unsigned int pf = 0;
pf < vecPFClusters.size();
pf++) {
964 isSharingEnergy =
true;
972 bothGsfTrackerDriven =
true;
973 vector<PFCluster> nPFCluster;
974 vector<PFCluster> iPFCluster;
979 for (PFClusterCollection::const_iterator clus = theEClus.begin(); clus != theEClus.end(); clus++) {
989 if (ndeta < 0.5 && fabs(ndphi) < 1.0) {
994 nPFCluster.push_back(clust);
995 nEnergy += clust.
energy();
997 const vector<PFBrem>& primPFBrem = nGsfPFRecTrack.
PFRecBrem();
998 for (
unsigned ipbrem = 0; ipbrem < primPFBrem.size(); ipbrem++) {
999 if (primPFBrem[ipbrem].indTrajPoint() == 99)
1006 nPFCluster.push_back(clust);
1007 nEnergy += clust.
energy();
1020 if (ideta < 0.5 && fabs(idphi) < 1.0) {
1025 iPFCluster.push_back(clust);
1026 iEnergy += clust.
energy();
1028 vector<PFBrem> primPFBrem = iGsfPFRecTrack.
PFRecBrem();
1029 for (
unsigned ipbrem = 0; ipbrem < primPFBrem.size(); ipbrem++) {
1030 if (primPFBrem[ipbrem].indTrajPoint() == 99)
1035 iPFCluster.push_back(clust);
1036 iEnergy += clust.
energy();
1044 if (!nPFCluster.empty() && !iPFCluster.empty()) {
1045 for (
unsigned int npf = 0; npf < nPFCluster.size(); npf++) {
1046 for (
unsigned int ipf = 0; ipf < iPFCluster.size(); ipf++) {
1049 isSharingEnergy =
true;
1053 if (isSharingEnergy)
1059 return isSharingEnergy;
1071 int gsfHitCounter1 = 0;
1072 for (
auto const&
hit : nGsfTrack->recHits()) {
1078 int gsfHitCounter2 = 0;
1079 for (
auto const&
hit : iGsfTrack->recHits()) {
1085 uint32_t gsfHit1 = gsfHitPattern1.
getHitPattern(HitPattern::TRACK_HITS, gsfHitCounter1);
1086 uint32_t gsfHit2 = gsfHitPattern2.
getHitPattern(HitPattern::TRACK_HITS, gsfHitCounter2);
1090 }
else if (gsfHitPattern1.
getLayer(gsfHit1) != gsfHitPattern2.
getLayer(gsfHit2)) {
1091 return (gsfHitPattern2.
getLayer(gsfHit2) < gsfHitPattern1.
getLayer(gsfHit1));
1101 unsigned int nLostHits = nGsfTrack->missingInnerHits();
1102 unsigned int iLostHits = iGsfTrack->missingInnerHits();
1104 if (nLostHits != iLostHits) {
1105 return (nLostHits > iLostHits);
bool trajinev_
Trajectory of GSfTracks in the event?
const math::XYZPoint & position() const
cluster centroid position
reconstructed track used as an input to particle flow
edm::EDGetTokenT< reco::PFRecTrackCollection > pfTrackLabel_
static uint32_t getLayer(uint16_t pattern)
const REPPoint & positionREP() const
trajectory position in (rho, eta, phi) base
T getParameter(std::string const &) const
static bool overlap(const reco::CaloCluster &sc1, const reco::CaloCluster &sc, float minfrac=0.01, bool debug=false)
edm::EDGetTokenT< reco::GsfTrackCollection > gsfTrackLabel_
const edm::ESGetToken< TransientTrackBuilder, TransientTrackRecord > transientTrackToken_
void createGsfPFRecTrackRef(const edm::OrphanHandle< reco::GsfPFRecTrackCollection > &gsfPfHandle, std::vector< reco::GsfPFRecTrack > &gsfPFRecTrackPrimary, const std::map< unsigned int, std::vector< reco::GsfPFRecTrack > > &MapPrimSec)
Particle flow cluster, see clustering algorithm in PFClusterAlgo.
double mvaConvBremFinderIDEndcapsLowPt_
RecHitRange recHits() const
bool isNonnull() const
Checks for non-null.
bool useFifthStepForTrackDriven_
std::string path_mvaWeightFileConvBremEndcapsLowPt_
#define DEFINE_FWK_MODULE(type)
int findPfRef(const reco::PFRecTrackCollection &pfRTkColl, const reco::GsfTrack &, edm::soa::EtaPhiTableView trackEtaPhiTable)
static std::unique_ptr< convbremhelpers::HeavyObjectCache > initializeGlobalCache(const edm::ParameterSet &conf)
T const * product() const
double etaMode() const
pseudorapidity of momentum vector from mode
bool isNonnull() const
Checks for non-null.
bool applySelection(const reco::GsfTrack &)
const edm::RefToBase< TrajectorySeed > & seedRef() const
reco::GsfPFRecTrack secpftrack_
std::unique_ptr< ConvBremPFTrackFinder > convBremFinder_
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tkerGeomToken_
key_type key() const
Accessor for product key.
void swap(Association< C > &lhs, Association< C > &rhs)
edm::EDGetTokenT< reco::VertexCollection > primVtxLabel_
std::string path_mvaWeightFileConvBremBarrelHighPt_
double mvaConvBremFinderIDBarrelLowPt_
bool isValid() const
is this point valid ?
void calculatePositionREP()
computes posrep_ once and for all
edm::EDGetTokenT< reco::PFV0Collection > pfV0_
const std::vector< reco::PFBrem > & PFRecBrem() const
std::string path_mvaWeightFileConvBremEndcapsHighPt_
std::vector< GsfTrack > GsfTrackCollection
collection of GsfTracks
double energy() const
cluster energy
double phi() const
azimuthal angle of momentum vector
edm::EDGetTokenT< reco::PFDisplacedTrackerVertexCollection > pfNuclear_
bool getData(T &iHolder) const
bool isSameEgSC(const reco::ElectronSeed &nSeed, const reco::ElectronSeed &iSeed, bool &bothGsfEcalDriven, float &SCEnergy)
uint16_t getHitPattern(HitCategory category, int position) const
static uint32_t getSubStructure(uint16_t pattern)
bool isInnerMostWithLostHits(const reco::GsfTrackRef &nGsfTrack, const reco::GsfTrackRef &iGsfTrack, bool &sameLayer)
PFElecTkProducer(const edm::ParameterSet &, const convbremhelpers::HeavyObjectCache *)
Constructor.
double energy() const
cluster energy
void endRun(const edm::Run &, const edm::EventSetup &) override
double eta() const
pseudorapidity of momentum vector
edm::soa::ViewFromTable_t< EtaPhiTable > EtaPhiTableView
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
const reco::PFTrajectoryPoint & extrapolatedPoint(unsigned layerid) const
std::string path_mvaWeightFileConvBremBarrelLowPt_
bool resolveGsfTracks(const std::vector< reco::GsfPFRecTrack > &GsfPFVec, unsigned int ngsf, std::vector< unsigned int > &secondaries, const reco::PFClusterCollection &theEClus)
XYZVectorD XYZVector
spatial vector with cartesian internal representation
const CaloClusterRef & caloCluster() const
double phiMode() const
azimuthal angle of momentum vector from mode
static double square(double x)
double mvaConvBremFinderIDBarrelHighPt_
double mvaConvBremFinderIDEndcapsHighPt_
edm::EDGetTokenT< reco::PFConversionCollection > pfConv_
std::vector< Trajectory > TrajectoryCollection
void beginRun(const edm::Run &, const edm::EventSetup &) override
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magFieldToken_
const reco::GsfTrackRef & gsfTrackRef() const
bool useFifthStepForEcalDriven_
reco::GsfPFRecTrack pftrack_
T const * get() const
Returns C++ pointer to the item.
void produce(edm::Event &, const edm::EventSetup &) override
Produce the PFRecTrack collection.
bool useConvBremFinder_
Conv Brem Finder.
std::vector< PFCluster > PFClusterCollection
collection of PFCluster objects
A PFTrack holds several trajectory points, which basically contain the position and momentum of a tra...
std::unique_ptr< PFTrackTransformer > pfTransformer_
PFTrackTransformer.
std::vector< double > gsfInnerMomentumCache_
bool momentumFromModeCartesian(TrajectoryStateOnSurface const &tsos, GlobalVector &momentum)
static double testTrackAndClusterByRecHit(const reco::PFRecTrack &track, const reco::PFCluster &cluster, bool isBrem=false, bool debug=false)
float minTangDist(const reco::GsfPFRecTrack &primGsf, const reco::GsfPFRecTrack &secGsf)
value_type const * get() const
std::vector< PFRecTrack > PFRecTrackCollection
collection of PFRecTrack objects
edm::EDGetTokenT< reco::PFClusterCollection > pfEcalClusters_
bool isSharingEcalEnergyWithEgSC(const reco::GsfPFRecTrack &nGsfPFRecTrack, const reco::GsfPFRecTrack &iGsfPFRecTrack, const reco::ElectronSeed &nSeed, const reco::ElectronSeed &iSeed, const reco::PFClusterCollection &theEClus, bool &bothGsfTrackerDriven, bool &nEcalDriven, bool &iEcalDriven, float &nEnergy, float &iEnergy)
bool applyAngularGsfClean_
const TrackExtraRef & extra() const
reference to "extra" object
MultiTrajectoryStateTransform mtsTransform_
static void globalEndJob(convbremhelpers::HeavyObjectCache const *)
bool isInnerMost(const reco::GsfTrackRef &nGsfTrack, const reco::GsfTrackRef &iGsfTrack, bool &sameLayer)