CMS 3D CMS Logo

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