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  useDefaultValuesForBarrel_ (config.getParameter<bool>("useDefaultValuesForBarrel")),
41  useDefaultValuesForEndcap_ (config.getParameter<bool>("useDefaultValuesForEndcap"))
42 {
43 
44  //register your products
45  produces < reco::RecoEcalCandidateIsolationMap >( "Deta" ).setBranchAlias( "deta" );
46  produces < reco::RecoEcalCandidateIsolationMap >( "DetaSeed" ).setBranchAlias( "detaseed" );
47  produces < reco::RecoEcalCandidateIsolationMap >( "Dphi" ).setBranchAlias( "dphi" );
48  produces < reco::RecoEcalCandidateIsolationMap >( "OneOESuperMinusOneOP" );
49  produces < reco::RecoEcalCandidateIsolationMap >( "OneOESeedMinusOneOP" );
50  produces < reco::RecoEcalCandidateIsolationMap >( "MissingHits" ).setBranchAlias( "missinghits" );
51  produces < reco::RecoEcalCandidateIsolationMap >( "Chi2" ).setBranchAlias( "chi2" );
52  produces < reco::RecoEcalCandidateIsolationMap >( "ValidHits" ).setBranchAlias( "validhits" );
53 }
54 
56 {}
57 
60  desc.add<edm::InputTag>(("recoEcalCandidateProducer"), edm::InputTag("hltRecoEcalSuperClusterActivityCandidate"));
61  desc.add<edm::InputTag>(("inputCollection"), edm::InputTag("hltActivityElectronGsfTracks"));
62  desc.add<edm::InputTag>(("beamSpotProducer"), edm::InputTag("hltOnlineBeamSpot"));
63  desc.add<int>(("upperTrackNrToRemoveCut"), 9999);
64  desc.add<int>(("lowerTrackNrToRemoveCut"), -1);
65  desc.add<bool>(("useDefaultValuesForBarrel"),false);
66  desc.add<bool>(("useDefaultValuesForEndcap"),false);
67 
68  descriptions.add("hltEgammaHLTGsfTrackVarProducer", desc);
69 }
71 
72  trackExtrapolator_.setup(iSetup);
73 
74  // Get the HLT filtered objects
76  iEvent.getByToken(recoEcalCandTag_,recoEcalCandHandle);
77 
79  iEvent.getByToken(inputCollectionTag1_,electronHandle);
80 
82  if(!electronHandle.isValid())
83  iEvent.getByToken(inputCollectionTag2_, gsfTracksHandle);
84 
85  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
86  iEvent.getByToken(beamSpotTag_,recoBeamSpotHandle);
87  // gets its position
88  const reco::BeamSpot& beamSpot = *recoBeamSpotHandle;
89 
90  edm::ESHandle<MagneticField> theMagField;
91  iSetup.get<IdealMagneticFieldRecord>().get(theMagField);
92 
93  reco::RecoEcalCandidateIsolationMap dEtaMap(recoEcalCandHandle);
94  reco::RecoEcalCandidateIsolationMap dEtaSeedMap(recoEcalCandHandle);
95  reco::RecoEcalCandidateIsolationMap dPhiMap(recoEcalCandHandle);
96  reco::RecoEcalCandidateIsolationMap oneOverESuperMinusOneOverPMap(recoEcalCandHandle);
97  reco::RecoEcalCandidateIsolationMap oneOverESeedMinusOneOverPMap(recoEcalCandHandle);
98  reco::RecoEcalCandidateIsolationMap missingHitsMap(recoEcalCandHandle);
99  reco::RecoEcalCandidateIsolationMap validHitsMap(recoEcalCandHandle);
100  reco::RecoEcalCandidateIsolationMap chi2Map(recoEcalCandHandle);
101 
102  for(reco::RecoEcalCandidateCollection::const_iterator iRecoEcalCand = recoEcalCandHandle->begin(); iRecoEcalCand != recoEcalCandHandle->end(); iRecoEcalCand++){
103  reco::RecoEcalCandidateRef recoEcalCandRef(recoEcalCandHandle,iRecoEcalCand-recoEcalCandHandle->begin());
104 
105  const reco::SuperClusterRef scRef = recoEcalCandRef->superCluster();
106  bool isBarrel = std::abs(recoEcalCandRef->eta())<1.479;
107  //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
108  std::vector<const reco::GsfTrack*> gsfTracks;
109  if(electronHandle.isValid()){
110  for(reco::ElectronCollection::const_iterator eleIt = electronHandle->begin(); eleIt != electronHandle->end(); eleIt++){
111  if(eleIt->superCluster()==scRef){
112  gsfTracks.push_back(&*eleIt->gsfTrack());
113  }
114  }
115  }else{
116  for(reco::GsfTrackCollection::const_iterator trkIt =gsfTracksHandle->begin();trkIt!=gsfTracksHandle->end();++trkIt){
117  edm::RefToBase<TrajectorySeed> seed = trkIt->extra()->seedRef() ;
119  edm::RefToBase<reco::CaloCluster> caloCluster = elseed->caloCluster() ;
120  reco::SuperClusterRef scRefFromTrk = caloCluster.castTo<reco::SuperClusterRef>() ;
121  if(scRefFromTrk==scRef){
122  gsfTracks.push_back(&*trkIt);
123  }
124  }
125 
126  }
127 
128  int validHitsValue = 0;
129  float chi2Value = 9999999.;
130  float missingHitsValue = 9999999;
131  float dEtaInValue=999999;
132  float dEtaSeedInValue=999999;
133  float dPhiInValue=999999;
134  float oneOverESuperMinusOneOverPValue=999999;
135  float oneOverESeedMinusOneOverPValue=999999;
136 
137  const int nrTracks = gsfTracks.size();
138  const bool rmCutsDueToNrTracks = nrTracks <= lowerTrackNrToRemoveCut_ ||
139  nrTracks >= upperTrackNrToRemoveCut_;
140  //to use the default values, we require at least one track...
141  const bool useDefaultValues = isBarrel ? useDefaultValuesForBarrel_ && nrTracks>=1 : useDefaultValuesForEndcap_ && nrTracks>=1;
142 
143  if(rmCutsDueToNrTracks || useDefaultValues){
144  dEtaInValue=0;
145  dEtaSeedInValue=0;
146  dPhiInValue=0;
147  missingHitsValue = 0;
148  validHitsValue = 100;
149  chi2Value = 0;
150  oneOverESuperMinusOneOverPValue = 0;
151  oneOverESeedMinusOneOverPValue = 0;
152  }else{
153  for(size_t trkNr=0;trkNr<gsfTracks.size();trkNr++){
154 
155  GlobalPoint scPos(scRef->x(),scRef->y(),scRef->z());
156  GlobalPoint trackExtrapToSC = trackExtrapolator_.extrapolateTrackPosToPoint(*gsfTracks[trkNr],scPos);
157  EleRelPointPair scAtVtx(scRef->position(),trackExtrapToSC,beamSpot.position());
158 
159  float trkP = gsfTracks[trkNr]->p();
160  if(scRef->energy()!=0 && trkP!=0){
161  if(fabs(1/scRef->energy() - 1/trkP)<oneOverESuperMinusOneOverPValue) oneOverESuperMinusOneOverPValue =fabs(1/scRef->energy() - 1/trkP);
162  }
163  if(scRef->seed().isNonnull() && scRef->seed()->energy()!=0 && trkP!=0){
164  if(fabs(1/scRef->seed()->energy() - 1/trkP)<oneOverESeedMinusOneOverPValue) oneOverESeedMinusOneOverPValue =fabs(1/scRef->seed()->energy() - 1/trkP);
165  }
166 
167 
168  if (gsfTracks[trkNr]->hitPattern().numberOfLostHits(reco::HitPattern::MISSING_INNER_HITS) < missingHitsValue)
169  missingHitsValue = gsfTracks[trkNr]->hitPattern().numberOfLostHits(reco::HitPattern::MISSING_INNER_HITS);
170 
171  if (gsfTracks[trkNr]->numberOfValidHits() < validHitsValue)
172  validHitsValue = gsfTracks[trkNr]->numberOfValidHits();
173 
174  if (gsfTracks[trkNr]->numberOfValidHits() < chi2Value)
175  chi2Value = gsfTracks[trkNr]->normalizedChi2();
176 
177  if (fabs(scAtVtx.dEta())<dEtaInValue)
178  dEtaInValue=fabs(scAtVtx.dEta()); //we are allowing them to come from different tracks
179 
180  if (fabs(scAtVtx.dEta())<dEtaSeedInValue)
181  dEtaSeedInValue = fabs(scAtVtx.dEta()-scRef->position().eta()+scRef->seed()->position().eta());
182 
183  if (fabs(scAtVtx.dPhi())<dPhiInValue)
184  dPhiInValue=fabs(scAtVtx.dPhi());//we are allowing them to come from different tracks
185  }
186  }
187 
188  dEtaMap.insert(recoEcalCandRef, dEtaInValue);
189  dEtaSeedMap.insert(recoEcalCandRef, dEtaSeedInValue);
190  dPhiMap.insert(recoEcalCandRef, dPhiInValue);
191  oneOverESuperMinusOneOverPMap.insert(recoEcalCandRef,oneOverESuperMinusOneOverPValue);
192  oneOverESeedMinusOneOverPMap.insert(recoEcalCandRef,oneOverESeedMinusOneOverPValue);
193  missingHitsMap.insert(recoEcalCandRef, missingHitsValue);
194  validHitsMap.insert(recoEcalCandRef, validHitsValue);
195  chi2Map.insert(recoEcalCandRef, chi2Value);
196  }
197 
198  auto dEtaMapForEvent = std::make_unique<reco::RecoEcalCandidateIsolationMap>(dEtaMap);
199  auto dEtaSeedMapForEvent = std::make_unique<reco::RecoEcalCandidateIsolationMap>(dEtaSeedMap);
200  auto dPhiMapForEvent = std::make_unique<reco::RecoEcalCandidateIsolationMap>(dPhiMap);
201  auto oneOverESuperMinusOneOverPMapForEvent = std::make_unique<reco::RecoEcalCandidateIsolationMap>(oneOverESuperMinusOneOverPMap);
202  auto oneOverESeedMinusOneOverPMapForEvent = std::make_unique<reco::RecoEcalCandidateIsolationMap>(oneOverESeedMinusOneOverPMap);
203  auto missingHitsForEvent = std::make_unique<reco::RecoEcalCandidateIsolationMap>(missingHitsMap);
204  auto validHitsForEvent = std::make_unique<reco::RecoEcalCandidateIsolationMap>(validHitsMap);
205  auto chi2ForEvent = std::make_unique<reco::RecoEcalCandidateIsolationMap>(chi2Map);
206 
207  iEvent.put(std::move(dEtaMapForEvent), "Deta" );
208  iEvent.put(std::move(dEtaSeedMapForEvent), "DetaSeed" );
209  iEvent.put(std::move(dPhiMapForEvent), "Dphi" );
210  iEvent.put(std::move(oneOverESuperMinusOneOverPMapForEvent), "OneOESuperMinusOneOP");
211  iEvent.put(std::move(oneOverESeedMinusOneOverPMapForEvent), "OneOESeedMinusOneOP");
212  iEvent.put(std::move(missingHitsForEvent), "MissingHits");
213  iEvent.put(std::move(validHitsForEvent), "ValidHits");
214  iEvent.put(std::move(chi2ForEvent), "Chi2");
215 }
216 
217 
219  cacheIDTDGeom_(rhs.cacheIDTDGeom_),
220  cacheIDMagField_(rhs.cacheIDMagField_),
221  magField_(rhs.magField_),
222  trackerHandle_(rhs.trackerHandle_),
223  mtsMode_(rhs.mtsMode_)
224 
225 {
227  else mtsTransform_ =nullptr;
228 
229 }
230 
232 {
233  if(this!=&rhs){ //just to ensure we're not copying ourselves
236  magField_ = rhs.magField_;
238  mtsMode_ = rhs.mtsMode_;
239 
240  delete mtsTransform_;
242  else mtsTransform_ =nullptr;
243  }
244  return this;
245 }
246 
248 {
249  bool updateField(false);
251  updateField = true;
252  cacheIDMagField_=iSetup.get<IdealMagneticFieldRecord>().cacheIdentifier();
253  iSetup.get<IdealMagneticFieldRecord>().get(magField_);
254  }
255 
256  bool updateGeometry(false);
258  updateGeometry = true;
259  cacheIDTDGeom_=iSetup.get<TrackerDigiGeometryRecord>().cacheIdentifier();
261  }
262 
263  if ( updateField || updateGeometry || !mtsTransform_ ) {
264  delete mtsTransform_;
266  }
267 }
268 
270 {
272  TrajectoryStateOnSurface posTSOS = mtsTransform()->extrapolatedState(innTSOS,pointToExtrapTo);
273  GlobalPoint extrapolatedPos;
274  mtsMode()->positionFromModeCartesian(posTSOS,extrapolatedPos);
275  return extrapolatedPos;
276 }
277 
279 {
281  TrajectoryStateOnSurface posTSOS = mtsTransform()->extrapolatedState(innTSOS,pointToExtrapTo);
282  GlobalVector extrapolatedMom;
283  mtsMode()->momentumFromModeCartesian(posTSOS,extrapolatedMom);
284  return extrapolatedMom;
285 }
286 
287 //define this as a plug-in
288 //DEFINE_FWK_MODULE(EgammaHLTTrackIsolationProducers);
unsigned long long cacheIdentifier() const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
bool positionFromModeCartesian(const TrajectoryStateOnSurface tsos, GlobalPoint &position) const
const MultiTrajectoryStateMode * mtsMode() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
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
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
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:289
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.
T get() const
Definition: EventSetup.h:68
const Point & position() const
position
Definition: BeamSpot.h:62
T const * product() const
Definition: ESHandle.h:84
def move(src, dest)
Definition: eostools.py:511