CMS 3D CMS Logo

EgammaHLTGsfTrackVarProducer.cc
Go to the documentation of this file.
1 
10 
13 
17 
21 
24 
32 
34  recoEcalCandTag_ (consumes<reco::RecoEcalCandidateCollection>(config.getParameter<edm::InputTag>("recoEcalCandidateProducer"))),
35  inputCollectionTag1_ (consumes<reco::ElectronCollection>(config.getParameter<edm::InputTag>("inputCollection"))),
36  inputCollectionTag2_ (consumes<reco::GsfTrackCollection>(config.getParameter<edm::InputTag>("inputCollection"))),
37  beamSpotTag_ (consumes<reco::BeamSpot>(config.getParameter<edm::InputTag>("beamSpotProducer"))),
38  upperTrackNrToRemoveCut_ (config.getParameter<int>("upperTrackNrToRemoveCut")),
39  lowerTrackNrToRemoveCut_ (config.getParameter<int>("lowerTrackNrToRemoveCut")) {
40 
41  //register your products
42  produces < reco::RecoEcalCandidateIsolationMap >( "Deta" ).setBranchAlias( "deta" );
43  produces < reco::RecoEcalCandidateIsolationMap >( "DetaSeed" ).setBranchAlias( "detaseed" );
44  produces < reco::RecoEcalCandidateIsolationMap >( "Dphi" ).setBranchAlias( "dphi" );
45  produces < reco::RecoEcalCandidateIsolationMap >( "OneOESuperMinusOneOP" );
46  produces < reco::RecoEcalCandidateIsolationMap >( "OneOESeedMinusOneOP" );
47  produces < reco::RecoEcalCandidateIsolationMap >( "MissingHits" ).setBranchAlias( "missinghits" );
48  produces < reco::RecoEcalCandidateIsolationMap >( "Chi2" ).setBranchAlias( "chi2" );
49  produces < reco::RecoEcalCandidateIsolationMap >( "ValidHits" ).setBranchAlias( "validhits" );
50 }
51 
53 {}
54 
57  desc.add<edm::InputTag>(("recoEcalCandidateProducer"), edm::InputTag("hltRecoEcalSuperClusterActivityCandidate"));
58  desc.add<edm::InputTag>(("inputCollection"), edm::InputTag("hltActivityElectronGsfTracks"));
59  desc.add<edm::InputTag>(("beamSpotProducer"), edm::InputTag("hltOnlineBeamSpot"));
60  desc.add<int>(("upperTrackNrToRemoveCut"), 9999);
61  desc.add<int>(("lowerTrackNrToRemoveCut"), -1);
62  descriptions.add("hltEgammaHLTGsfTrackVarProducer", desc);
63 }
65 
66  trackExtrapolator_.setup(iSetup);
67 
68  // Get the HLT filtered objects
70  iEvent.getByToken(recoEcalCandTag_,recoEcalCandHandle);
71 
73  iEvent.getByToken(inputCollectionTag1_,electronHandle);
74 
76  if(!electronHandle.isValid())
77  iEvent.getByToken(inputCollectionTag2_, gsfTracksHandle);
78 
79  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
80  iEvent.getByToken(beamSpotTag_,recoBeamSpotHandle);
81  // gets its position
82  const reco::BeamSpot& beamSpot = *recoBeamSpotHandle;
83 
84  edm::ESHandle<MagneticField> theMagField;
85  iSetup.get<IdealMagneticFieldRecord>().get(theMagField);
86 
87  reco::RecoEcalCandidateIsolationMap dEtaMap(recoEcalCandHandle);
88  reco::RecoEcalCandidateIsolationMap dEtaSeedMap(recoEcalCandHandle);
89  reco::RecoEcalCandidateIsolationMap dPhiMap(recoEcalCandHandle);
90  reco::RecoEcalCandidateIsolationMap oneOverESuperMinusOneOverPMap(recoEcalCandHandle);
91  reco::RecoEcalCandidateIsolationMap oneOverESeedMinusOneOverPMap(recoEcalCandHandle);
92  reco::RecoEcalCandidateIsolationMap missingHitsMap(recoEcalCandHandle);
93  reco::RecoEcalCandidateIsolationMap validHitsMap(recoEcalCandHandle);
94  reco::RecoEcalCandidateIsolationMap chi2Map(recoEcalCandHandle);
95 
96  for(reco::RecoEcalCandidateCollection::const_iterator iRecoEcalCand = recoEcalCandHandle->begin(); iRecoEcalCand != recoEcalCandHandle->end(); iRecoEcalCand++){
97  reco::RecoEcalCandidateRef recoEcalCandRef(recoEcalCandHandle,iRecoEcalCand-recoEcalCandHandle->begin());
98 
99  const reco::SuperClusterRef scRef = recoEcalCandRef->superCluster();
100 
101  //the idea is that we can take the tracks from properly associated electrons or just take all gsf tracks with that sc as a seed
102  std::vector<const reco::GsfTrack*> gsfTracks;
103  if(electronHandle.isValid()){
104  for(reco::ElectronCollection::const_iterator eleIt = electronHandle->begin(); eleIt != electronHandle->end(); eleIt++){
105  if(eleIt->superCluster()==scRef){
106  gsfTracks.push_back(&*eleIt->gsfTrack());
107  }
108  }
109  }else{
110  for(reco::GsfTrackCollection::const_iterator trkIt =gsfTracksHandle->begin();trkIt!=gsfTracksHandle->end();++trkIt){
111  edm::RefToBase<TrajectorySeed> seed = trkIt->extra()->seedRef() ;
113  edm::RefToBase<reco::CaloCluster> caloCluster = elseed->caloCluster() ;
114  reco::SuperClusterRef scRefFromTrk = caloCluster.castTo<reco::SuperClusterRef>() ;
115  if(scRefFromTrk==scRef){
116  gsfTracks.push_back(&*trkIt);
117  }
118  }
119 
120  }
121 
122  int validHitsValue = 9999999;
123  float chi2Value = 9999999.;
124  float missingHitsValue = 9999999;
125  float dEtaInValue=999999;
126  float dEtaSeedInValue=999999;
127  float dPhiInValue=999999;
128  float oneOverESuperMinusOneOverPValue=999999;
129  float oneOverESeedMinusOneOverPValue=999999;
130 
131  if(static_cast<int>(gsfTracks.size())>=upperTrackNrToRemoveCut_){
132  dEtaInValue=0;
133  dEtaSeedInValue=0;
134  dPhiInValue=0;
135  missingHitsValue = 0;
136  validHitsValue = 0;
137  chi2Value = 0;
138  }else if(static_cast<int>(gsfTracks.size())<=lowerTrackNrToRemoveCut_){
139  dEtaInValue=0;
140  dEtaSeedInValue=0;
141  dPhiInValue=0;
142  missingHitsValue = 0;
143  validHitsValue = 0;
144  chi2Value = 0;
145  }else{
146  for(size_t trkNr=0;trkNr<gsfTracks.size();trkNr++){
147 
148  GlobalPoint scPos(scRef->x(),scRef->y(),scRef->z());
149  GlobalPoint trackExtrapToSC = trackExtrapolator_.extrapolateTrackPosToPoint(*gsfTracks[trkNr],scPos);
150  EleRelPointPair scAtVtx(scRef->position(),trackExtrapToSC,beamSpot.position());
151 
152  float trkP = gsfTracks[trkNr]->p();
153  if(scRef->energy()!=0 && trkP!=0){
154  if(fabs(1/scRef->energy() - 1/trkP)<oneOverESuperMinusOneOverPValue) oneOverESuperMinusOneOverPValue =fabs(1/scRef->energy() - 1/trkP);
155  }
156  if(scRef->seed().isNonnull() && scRef->seed()->energy()!=0 && trkP!=0){
157  if(fabs(1/scRef->seed()->energy() - 1/trkP)<oneOverESeedMinusOneOverPValue) oneOverESeedMinusOneOverPValue =fabs(1/scRef->seed()->energy() - 1/trkP);
158  }
159 
160 
161  if (gsfTracks[trkNr]->hitPattern().numberOfLostHits(reco::HitPattern::MISSING_INNER_HITS) < missingHitsValue)
162  missingHitsValue = gsfTracks[trkNr]->hitPattern().numberOfLostHits(reco::HitPattern::MISSING_INNER_HITS);
163 
164  if (gsfTracks[trkNr]->numberOfValidHits() < validHitsValue)
165  validHitsValue = gsfTracks[trkNr]->numberOfValidHits();
166 
167  if (gsfTracks[trkNr]->numberOfValidHits() < chi2Value)
168  chi2Value = gsfTracks[trkNr]->normalizedChi2();
169 
170  if (fabs(scAtVtx.dEta())<dEtaInValue)
171  dEtaInValue=fabs(scAtVtx.dEta()); //we are allowing them to come from different tracks
172 
173  if (fabs(scAtVtx.dEta())<dEtaSeedInValue)
174  dEtaSeedInValue = fabs(scAtVtx.dEta()-scRef->position().eta()+scRef->seed()->position().eta());
175 
176  if (fabs(scAtVtx.dPhi())<dPhiInValue)
177  dPhiInValue=fabs(scAtVtx.dPhi());//we are allowing them to come from different tracks
178  }
179  }
180 
181  dEtaMap.insert(recoEcalCandRef, dEtaInValue);
182  dEtaSeedMap.insert(recoEcalCandRef, dEtaSeedInValue);
183  dPhiMap.insert(recoEcalCandRef, dPhiInValue);
184  oneOverESuperMinusOneOverPMap.insert(recoEcalCandRef,oneOverESuperMinusOneOverPValue);
185  oneOverESeedMinusOneOverPMap.insert(recoEcalCandRef,oneOverESeedMinusOneOverPValue);
186  missingHitsMap.insert(recoEcalCandRef, missingHitsValue);
187  validHitsMap.insert(recoEcalCandRef, validHitsValue);
188  chi2Map.insert(recoEcalCandRef, chi2Value);
189  }
190 
191  auto dEtaMapForEvent = std::make_unique<reco::RecoEcalCandidateIsolationMap>(dEtaMap);
192  auto dEtaSeedMapForEvent = std::make_unique<reco::RecoEcalCandidateIsolationMap>(dEtaSeedMap);
193  auto dPhiMapForEvent = std::make_unique<reco::RecoEcalCandidateIsolationMap>(dPhiMap);
194  auto oneOverESuperMinusOneOverPMapForEvent = std::make_unique<reco::RecoEcalCandidateIsolationMap>(oneOverESuperMinusOneOverPMap);
195  auto oneOverESeedMinusOneOverPMapForEvent = std::make_unique<reco::RecoEcalCandidateIsolationMap>(oneOverESeedMinusOneOverPMap);
196  auto missingHitsForEvent = std::make_unique<reco::RecoEcalCandidateIsolationMap>(missingHitsMap);
197  auto validHitsForEvent = std::make_unique<reco::RecoEcalCandidateIsolationMap>(validHitsMap);
198  auto chi2ForEvent = std::make_unique<reco::RecoEcalCandidateIsolationMap>(chi2Map);
199 
200  iEvent.put(std::move(dEtaMapForEvent), "Deta" );
201  iEvent.put(std::move(dEtaSeedMapForEvent), "DetaSeed" );
202  iEvent.put(std::move(dPhiMapForEvent), "Dphi" );
203  iEvent.put(std::move(oneOverESuperMinusOneOverPMapForEvent), "OneOESuperMinusOneOP");
204  iEvent.put(std::move(oneOverESeedMinusOneOverPMapForEvent), "OneOESeedMinusOneOP");
205  iEvent.put(std::move(missingHitsForEvent), "MissingHits");
206  iEvent.put(std::move(validHitsForEvent), "ValidHits");
207  iEvent.put(std::move(chi2ForEvent), "Chi2");
208 }
209 
210 
212  cacheIDTDGeom_(rhs.cacheIDTDGeom_),
213  cacheIDMagField_(rhs.cacheIDMagField_),
214  magField_(rhs.magField_),
215  trackerHandle_(rhs.trackerHandle_),
216  mtsMode_(rhs.mtsMode_)
217 
218 {
220  else mtsTransform_ =nullptr;
221 
222 }
223 
225 {
226  if(this!=&rhs){ //just to ensure we're not copying ourselves
229  magField_ = rhs.magField_;
231  mtsMode_ = rhs.mtsMode_;
232 
233  delete mtsTransform_;
235  else mtsTransform_ =nullptr;
236  }
237  return this;
238 }
239 
241 {
242  bool updateField(false);
244  updateField = true;
245  cacheIDMagField_=iSetup.get<IdealMagneticFieldRecord>().cacheIdentifier();
246  iSetup.get<IdealMagneticFieldRecord>().get(magField_);
247  }
248 
249  bool updateGeometry(false);
251  updateGeometry = true;
252  cacheIDTDGeom_=iSetup.get<TrackerDigiGeometryRecord>().cacheIdentifier();
254  }
255 
256  if ( updateField || updateGeometry || !mtsTransform_ ) {
257  delete mtsTransform_;
259  }
260 }
261 
263 {
265  TrajectoryStateOnSurface posTSOS = mtsTransform()->extrapolatedState(innTSOS,pointToExtrapTo);
266  GlobalPoint extrapolatedPos;
267  mtsMode()->positionFromModeCartesian(posTSOS,extrapolatedPos);
268  return extrapolatedPos;
269 }
270 
272 {
274  TrajectoryStateOnSurface posTSOS = mtsTransform()->extrapolatedState(innTSOS,pointToExtrapTo);
275  GlobalVector extrapolatedMom;
276  mtsMode()->momentumFromModeCartesian(posTSOS,extrapolatedMom);
277  return extrapolatedMom;
278 }
279 
280 //define this as a plug-in
281 //DEFINE_FWK_MODULE(EgammaHLTTrackIsolationProducers);
unsigned long long cacheIdentifier() const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
bool positionFromModeCartesian(const TrajectoryStateOnSurface tsos, GlobalPoint &position) const
const MultiTrajectoryStateMode * mtsMode() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
Definition: config.py:1
bool momentumFromModeCartesian(const TrajectoryStateOnSurface tsos, GlobalVector &momentum) const
const MultiTrajectoryStateTransform * mtsTransform() const
const edm::EDGetTokenT< reco::RecoEcalCandidateCollection > recoEcalCandTag_
GlobalPoint extrapolateTrackPosToPoint(const reco::GsfTrack &gsfTrack, const GlobalPoint &pointToExtrapTo)
const edm::EDGetTokenT< reco::GsfTrackCollection > inputCollectionTag2_
GlobalVector extrapolateTrackMomToPoint(const reco::GsfTrack &gsfTrack, const GlobalPoint &pointToExtrapTo)
int iEvent
Definition: GenABIO.cc:230
TrajectoryStateOnSurface extrapolatedState(const TrajectoryStateOnSurface tsos, const GlobalPoint &point) const
const edm::EDGetTokenT< reco::BeamSpot > beamSpotTag_
std::vector< GsfTrack > GsfTrackCollection
collection of GsfTracks
Definition: GsfTrackFwd.h:9
EgammaHLTGsfTrackVarProducer(const edm::ParameterSet &)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:74
std::vector< Electron > ElectronCollection
collectin of Electron objects
Definition: ElectronFwd.h:9
void produce(edm::Event &, const edm::EventSetup &) override
const edm::EDGetTokenT< reco::ElectronCollection > inputCollectionTag1_
TrackExtrapolator * operator=(const TrackExtrapolator &rhs)
void insert(const key_type &k, const data_type &v)
insert an association
REF castTo() const
Definition: RefToBase.h:286
const T & get() const
Definition: EventSetup.h:58
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
TrajectoryStateOnSurface innerStateOnSurface(const reco::GsfTrack &tk) const
std::vector< RecoEcalCandidate > RecoEcalCandidateCollection
collectin of RecoEcalCandidate objects
fixed size matrix
HLT enums.
const Point & position() const
position
Definition: BeamSpot.h:62
T const * product() const
Definition: ESHandle.h:86
def move(src, dest)
Definition: eostools.py:510