CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SoftPFElectronTagInfoProducer.cc
Go to the documentation of this file.
18 
19 // Transient Track and IP
25 #include <cmath>
28 
29 
31 {
32  token_jets = consumes<edm::View<reco::Jet> >(conf.getParameter<edm::InputTag>("jets"));
33  token_elec = consumes<edm::View<reco::GsfElectron> >(conf.getParameter<edm::InputTag>("electrons"));
34  token_primaryVertex = consumes<reco::VertexCollection>(conf.getParameter<edm::InputTag>("primaryVertex"));
35  token_BeamSpot = consumes<reco::BeamSpot>(edm::InputTag("offlineBeamSpot"));
36  token_allConversions= consumes<reco::ConversionCollection>(edm::InputTag("allConversions"));
37  DeltaRElectronJet = conf.getParameter<double>("DeltaRElectronJet");
38  MaxSip3Dsig = conf.getParameter<double>("MaxSip3Dsig");
39  produces<reco::CandSoftLeptonTagInfoCollection>();
40 }
41 
43 {
44 
45 }
46 
48 {
49  std::auto_ptr<reco::CandSoftLeptonTagInfoCollection> theElecTagInfo(new reco::CandSoftLeptonTagInfoCollection);
51  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", builder);
53 
55  iEvent.getByToken(token_primaryVertex, PVCollection);
56  if(!PVCollection.isValid()) return;
57  if(!PVCollection->empty()){
58  goodvertex = true;
59  vertex=&PVCollection->front();
60  }else goodvertex = false;
62  iEvent.getByToken(token_allConversions, hConversions);
63 
64  edm::Handle<edm::View<reco::Jet> > theJetCollection;
65  iEvent.getByToken(token_jets, theJetCollection);
66 
67  edm::Handle<edm::View<reco::GsfElectron > > theGEDGsfElectronCollection;
68  iEvent.getByToken(token_elec, theGEDGsfElectronCollection);
69 
71  iEvent.getByToken(token_BeamSpot, bsHandle);
72  const reco::BeamSpot &beamspot = *bsHandle.product();
73 
74  for (unsigned int i = 0; i < theJetCollection->size(); i++){
75  edm::RefToBase<reco::Jet> jetRef = theJetCollection->refAt(i);
77  tagInfo.setJetRef(jetRef);
78  std::vector<const reco::GsfElectron *> Elec;
79  for(unsigned int ie=0, ne=theGEDGsfElectronCollection->size(); ie<ne; ++ie){
80  //Get the edm::Ptr and the GsfElectron
81  edm::Ptr<reco::Candidate> lepPtr=theGEDGsfElectronCollection->ptrAt(ie);
82  const reco::GsfElectron* recoelectron=theGEDGsfElectronCollection->refAt(ie).get();
83  const pat::Electron* patelec=dynamic_cast<const pat::Electron*>(recoelectron);
84  if(patelec){
85  if(!patelec->passConversionVeto()) continue;
86  }
87  else{
88  if(ConversionTools::hasMatchedConversion(*(recoelectron),hConversions,beamspot.position())) continue;
89  }
90  //Make sure that the electron is inside the jet
91  if(reco::deltaR2((*recoelectron),(*jetRef))>DeltaRElectronJet*DeltaRElectronJet) continue;
92  // Need a gsfTrack
93  if(recoelectron->gsfTrack().get()==NULL) continue;
94  reco::SoftLeptonProperties properties;
95  // reject if it has issues with the track
96  if(!isElecClean(iEvent,recoelectron) ) continue;
97  //Compute the TagInfos members
98  math::XYZVector pel=recoelectron->p4().Vect();
99  math::XYZVector pjet=jetRef->p4().Vect();
100  reco::TransientTrack transientTrack=transientTrackBuilder->build(recoelectron->gsfTrack());
101  Measurement1D ip2d = IPTools::signedTransverseImpactParameter(transientTrack, GlobalVector(jetRef->px(), jetRef->py(), jetRef->pz()), *vertex).second;
102  Measurement1D ip3d = IPTools::signedImpactParameter3D(transientTrack, GlobalVector(jetRef->px(), jetRef->py(), jetRef->pz()), *vertex).second;
103  properties.sip2dsig = ip2d.significance();
104  properties.sip3dsig = ip3d.significance();
105  properties.sip2d = ip2d.value();
106  properties.sip3d = ip3d.value();
107  properties.deltaR = reco::deltaR((*jetRef), (*recoelectron));
108  properties.ptRel = ( (pjet-pel).Cross(pel) ).R() / pjet.R();
109  float mag = pel.R()*pjet.R();
110  float dot = recoelectron->p4().Dot(jetRef->p4());
111  properties.etaRel = -log((mag - dot)/(mag + dot)) / 2.;
112  properties.ratio = recoelectron->pt() / jetRef->pt();
113  properties.ratioRel = recoelectron->p4().Dot(jetRef->p4()) / pjet.Mag2();
114  properties.p0Par = boostedPPar(recoelectron->momentum(), jetRef->momentum());
115  properties.elec_mva = recoelectron->mva_e_pi();
116  if(std::abs(properties.sip3dsig)>MaxSip3Dsig) continue;
117  // Fill the TagInfos
118  tagInfo.insert(lepPtr, properties );
119  }
120  theElecTagInfo->push_back(tagInfo);
121  }
122  iEvent.put(theElecTagInfo);
123 }
124 
126 {
127  using namespace reco;
128  const HitPattern &hitPattern = candidate->gsfTrack().get()->hitPattern();
129  uint32_t hit = hitPattern.getHitPattern(HitPattern::TRACK_HITS, 0);
130  bool hitCondition = !(HitPattern::validHitFilter(hit)
131  && ((HitPattern::pixelBarrelHitFilter(hit)
132  && HitPattern::getLayer(hit) < 3)
133  || HitPattern::pixelEndcapHitFilter(hit)));
134  if(hitCondition) return false;
135 
136  return true;
137 }
138 
140  static const double lepton_mass = 0.00;
141  static const double jet_mass = 5.279;
142  ROOT::Math::LorentzVector<ROOT::Math::PxPyPzM4D<double> > lepton(vector.Dot(axis) / axis.r(), ROOT::Math::VectorUtil::Perp(vector, axis), 0., lepton_mass);
143  ROOT::Math::LorentzVector<ROOT::Math::PxPyPzM4D<double> > jet( axis.r(), 0., 0., jet_mass );
144  ROOT::Math::BoostX boost( -jet.Beta() );
145  return boost(lepton).x();
146 }
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
float boostedPPar(const math::XYZVector &, const math::XYZVector &)
edm::EDGetTokenT< reco::ConversionCollection > token_allConversions
edm::EDGetTokenT< edm::View< reco::GsfElectron > > token_elec
const LorentzVector & p4(P4Kind kind) const
Definition: GsfElectron.cc:223
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
std::pair< bool, Measurement1D > signedTransverseImpactParameter(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:50
edm::EDGetTokenT< reco::BeamSpot > token_BeamSpot
virtual Vector momentum() const
spatial momentum vector
reco::TransientTrack build(const reco::Track *p) const
std::pair< bool, Measurement1D > signedImpactParameter3D(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:71
#define NULL
Definition: scimark2.h:8
double deltaR(const T1 &t1, const T2 &t2)
Definition: deltaR.h:48
void setJetRef(const edm::Ref< T > &jetRef)
Definition: JetTagInfo.h:25
virtual double pt() const
transverse momentum
SoftPFElectronTagInfoProducer(const edm::ParameterSet &conf)
virtual void produce(edm::Event &, const edm::EventSetup &)
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
std::vector< CandSoftLeptonTagInfo > CandSoftLeptonTagInfoCollection
bool isElecClean(edm::Event &, const reco::GsfElectron *)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double deltaR2(const T1 &t1, const T2 &t2)
Definition: deltaR.h:36
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:244
bool isValid() const
Definition: HandleBase.h:75
static bool hasMatchedConversion(const reco::GsfElectron &ele, const edm::Handle< reco::ConversionCollection > &convCol, const math::XYZPoint &beamspot, bool allowCkfMatch=true, float lxyMin=2.0, float probMin=1e-6, unsigned int nHitsBeforeVtxMax=0)
tuple conf
Definition: dbtoconf.py:185
void insert(const REF &lepton, const SoftLeptonProperties &properties)
double significance() const
Definition: Measurement1D.h:32
T const * product() const
Definition: Handle.h:81
virtual double px() const
x coordinate of momentum vector
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
edm::EDGetTokenT< reco::VertexCollection > token_primaryVertex
Analysis-level electron class.
Definition: Electron.h:52
double value() const
Definition: Measurement1D.h:28
bool passConversionVeto() const
vertex fit combined with missing number of hits method
Definition: Electron.h:243
virtual double pz() const
z coordinate of momentum vector
float mva_e_pi() const
Definition: GsfElectron.h:629
T dot(const Basic3DVector &v) const
Scalar product, or &quot;dot&quot; product, with a vector of same type.
const Point & position() const
position
Definition: BeamSpot.h:62
virtual const LorentzVector & p4() const
four-momentum Lorentz vector
Definition: LeafCandidate.h:99
edm::EDGetTokenT< edm::View< reco::Jet > > token_jets
virtual double py() const
y coordinate of momentum vector
const TransientTrackBuilder * transientTrackBuilder
Global3DVector GlobalVector
Definition: GlobalVector.h:10
virtual GsfTrackRef gsfTrack() const
reference to a GsfTrack
Definition: GsfElectron.h:183
tuple log
Definition: cmsBatch.py:341