test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EgammaHLTGsfTrackVarProducer.cc
Go to the documentation of this file.
1 
10 
13 
17 
21 
24 
32 
34 {
35  recoEcalCandTag_ = consumes<reco::RecoEcalCandidateCollection>(config.getParameter<edm::InputTag>("recoEcalCandidateProducer"));
36  inputCollectionTag1_ = consumes<reco::ElectronCollection>(config.getParameter<edm::InputTag>("inputCollection"));
37  inputCollectionTag2_ = consumes<reco::GsfTrackCollection>(config.getParameter<edm::InputTag>("inputCollection"));
38  beamSpotTag_ = consumes<reco::BeamSpot>(config.getParameter<edm::InputTag>("beamSpotProducer"));
39  upperTrackNrToRemoveCut_ = config.getParameter<int>("upperTrackNrToRemoveCut");
40  lowerTrackNrToRemoveCut_ = config.getParameter<int>("lowerTrackNrToRemoveCut");
41 
42  //register your products
43  produces < reco::RecoEcalCandidateIsolationMap >( "Deta" ).setBranchAlias( "deta" );
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 }
49 
51 {}
52 
55  desc.add<edm::InputTag>(("recoEcalCandidateProducer"), edm::InputTag("hltRecoEcalSuperClusterActivityCandidate"));
56  desc.add<edm::InputTag>(("inputCollection"), edm::InputTag("hltActivityElectronGsfTracks"));
57  desc.add<edm::InputTag>(("beamSpotProducer"), edm::InputTag("hltOnlineBeamSpot"));
58  desc.add<int>(("upperTrackNrToRemoveCut"), 9999);
59  desc.add<int>(("lowerTrackNrToRemoveCut"), -1);
60  descriptions.add("hltEgammaHLTGsfTrackVarProducer", desc);
61 }
63 
64  trackExtrapolator_.setup(iSetup);
65 
66  // Get the HLT filtered objects
68  iEvent.getByToken(recoEcalCandTag_,recoEcalCandHandle);
69 
71  iEvent.getByToken(inputCollectionTag1_,electronHandle);
72 
74  if(!electronHandle.isValid())
75  iEvent.getByToken(inputCollectionTag2_, gsfTracksHandle);
76 
77  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
78  iEvent.getByToken(beamSpotTag_,recoBeamSpotHandle);
79  // gets its position
80  const reco::BeamSpot& beamSpot = *recoBeamSpotHandle;
81 
82  edm::ESHandle<MagneticField> theMagField;
83  iSetup.get<IdealMagneticFieldRecord>().get(theMagField);
84 
87  reco::RecoEcalCandidateIsolationMap oneOverESuperMinusOneOverPMap;
88  reco::RecoEcalCandidateIsolationMap oneOverESeedMinusOneOverPMap;
90 
91  for(reco::RecoEcalCandidateCollection::const_iterator iRecoEcalCand = recoEcalCandHandle->begin(); iRecoEcalCand != recoEcalCandHandle->end(); iRecoEcalCand++){
92  reco::RecoEcalCandidateRef recoEcalCandRef(recoEcalCandHandle,iRecoEcalCand-recoEcalCandHandle->begin());
93 
94  const reco::SuperClusterRef scRef = recoEcalCandRef->superCluster();
95 
96  //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
97  std::vector<const reco::GsfTrack*> gsfTracks;
98  if(electronHandle.isValid()){
99  for(reco::ElectronCollection::const_iterator eleIt = electronHandle->begin(); eleIt != electronHandle->end(); eleIt++){
100  if(eleIt->superCluster()==scRef){
101  gsfTracks.push_back(&*eleIt->gsfTrack());
102  }
103  }
104  }else{
105  for(reco::GsfTrackCollection::const_iterator trkIt =gsfTracksHandle->begin();trkIt!=gsfTracksHandle->end();++trkIt){
106  edm::RefToBase<TrajectorySeed> seed = trkIt->extra()->seedRef() ;
108  edm::RefToBase<reco::CaloCluster> caloCluster = elseed->caloCluster() ;
109  reco::SuperClusterRef scRefFromTrk = caloCluster.castTo<reco::SuperClusterRef>() ;
110  if(scRefFromTrk==scRef){
111  gsfTracks.push_back(&*trkIt);
112  }
113  }
114 
115  }
116 
117  float missingHitsValue = 9999999;
118  float dEtaInValue=999999;
119  float dPhiInValue=999999;
120  float oneOverESuperMinusOneOverPValue=999999;
121  float oneOverESeedMinusOneOverPValue=999999;
122 
123  if(static_cast<int>(gsfTracks.size())>=upperTrackNrToRemoveCut_){
124  dEtaInValue=0;
125  dPhiInValue=0;
126  missingHitsValue = 0;
127  }else if(static_cast<int>(gsfTracks.size())<=lowerTrackNrToRemoveCut_){
128  dEtaInValue=0;
129  dPhiInValue=0;
130  missingHitsValue = 0;
131  }else{
132  for(size_t trkNr=0;trkNr<gsfTracks.size();trkNr++){
133 
134  GlobalPoint scPos(scRef->x(),scRef->y(),scRef->z());
135  GlobalPoint trackExtrapToSC = trackExtrapolator_.extrapolateTrackPosToPoint(*gsfTracks[trkNr],scPos);
136  EleRelPointPair scAtVtx(scRef->position(),trackExtrapToSC,beamSpot.position());
137 
138 
139  float trkP = gsfTracks[trkNr]->p();
140  if(scRef->energy()!=0 && trkP!=0){
141  if(fabs(1/scRef->energy() - 1/trkP)<oneOverESuperMinusOneOverPValue) oneOverESuperMinusOneOverPValue =fabs(1/scRef->energy() - 1/trkP);
142  }
143  if(scRef->seed().isNonnull() && scRef->seed()->energy()!=0 && trkP!=0){
144  if(fabs(1/scRef->seed()->energy() - 1/trkP)<oneOverESeedMinusOneOverPValue) oneOverESeedMinusOneOverPValue =fabs(1/scRef->seed()->energy() - 1/trkP);
145  }
146 
147  if (gsfTracks[trkNr]->trackerExpectedHitsInner().numberOfLostHits() < missingHitsValue)
148  missingHitsValue = gsfTracks[trkNr]->trackerExpectedHitsInner().numberOfLostHits();
149  if (fabs(scAtVtx.dEta())<dEtaInValue)
150  dEtaInValue=fabs(scAtVtx.dEta()); //we are allowing them to come from different tracks
151  if (fabs(scAtVtx.dPhi())<dPhiInValue)
152  dPhiInValue=fabs(scAtVtx.dPhi());//we are allowing them to come from different tracks
153  }
154  }
155 
156  dEtaMap.insert(recoEcalCandRef, dEtaInValue);
157  dPhiMap.insert(recoEcalCandRef, dPhiInValue);
158  oneOverESuperMinusOneOverPMap.insert(recoEcalCandRef,oneOverESuperMinusOneOverPValue);
159  oneOverESeedMinusOneOverPMap.insert(recoEcalCandRef,oneOverESeedMinusOneOverPValue);
160  missingHitsMap.insert(recoEcalCandRef, missingHitsValue);
161  }
162 
163  std::auto_ptr<reco::RecoEcalCandidateIsolationMap> dEtaMapForEvent(new reco::RecoEcalCandidateIsolationMap(dEtaMap));
164  std::auto_ptr<reco::RecoEcalCandidateIsolationMap> dPhiMapForEvent(new reco::RecoEcalCandidateIsolationMap(dPhiMap));
165  std::auto_ptr<reco::RecoEcalCandidateIsolationMap> oneOverESuperMinusOneOverPMapForEvent(new reco::RecoEcalCandidateIsolationMap(oneOverESuperMinusOneOverPMap));
166  std::auto_ptr<reco::RecoEcalCandidateIsolationMap> oneOverESeedMinusOneOverPMapForEvent(new reco::RecoEcalCandidateIsolationMap(oneOverESeedMinusOneOverPMap));
167  std::auto_ptr<reco::RecoEcalCandidateIsolationMap> missingHitsForEvent(new reco::RecoEcalCandidateIsolationMap(missingHitsMap));
168  iEvent.put(dEtaMapForEvent, "Deta" );
169  iEvent.put(dPhiMapForEvent, "Dphi" );
170  iEvent.put(oneOverESuperMinusOneOverPMapForEvent,"OneOESuperMinusOneOP");
171  iEvent.put(oneOverESeedMinusOneOverPMapForEvent,"OneOESeedMinusOneOP");
172  iEvent.put(missingHitsForEvent, "MissingHits");
173 }
174 
175 
177  cacheIDTDGeom_(rhs.cacheIDTDGeom_),
178  cacheIDMagField_(rhs.cacheIDMagField_),
179  magField_(rhs.magField_),
180  trackerHandle_(rhs.trackerHandle_),
181  mtsMode_(rhs.mtsMode_)
182 
183 {
185  else mtsTransform_ =0;
186 
187 }
188 
190 {
191  if(this!=&rhs){ //just to ensure we're not copying ourselves
192  cacheIDTDGeom_ = rhs.cacheIDTDGeom_;
193  cacheIDMagField_ = rhs.cacheIDMagField_;
194  magField_ = rhs.magField_;
195  trackerHandle_ = rhs.trackerHandle_;
196  mtsMode_ = rhs.mtsMode_;
197 
198  delete mtsTransform_;
199  if(rhs.mtsTransform_) mtsTransform_ = new MultiTrajectoryStateTransform(*rhs.mtsTransform_);
200  else mtsTransform_ =0;
201  }
202  return this;
203 }
204 
206 {
207  bool updateField(false);
208  if (cacheIDMagField_!=iSetup.get<IdealMagneticFieldRecord>().cacheIdentifier()){
209  updateField = true;
210  cacheIDMagField_=iSetup.get<IdealMagneticFieldRecord>().cacheIdentifier();
211  iSetup.get<IdealMagneticFieldRecord>().get(magField_);
212  }
213 
214  bool updateGeometry(false);
215  if (cacheIDTDGeom_!=iSetup.get<TrackerDigiGeometryRecord>().cacheIdentifier()){
216  updateGeometry = true;
217  cacheIDTDGeom_=iSetup.get<TrackerDigiGeometryRecord>().cacheIdentifier();
218  iSetup.get<TrackerDigiGeometryRecord>().get(trackerHandle_);
219  }
220 
221  if ( updateField || updateGeometry || !mtsTransform_ ) {
222  delete mtsTransform_;
223  mtsTransform_ = new MultiTrajectoryStateTransform(trackerHandle_.product(),magField_.product());
224  }
225 }
226 
228 {
229  TrajectoryStateOnSurface innTSOS = mtsTransform()->innerStateOnSurface(gsfTrack);
230  TrajectoryStateOnSurface posTSOS = mtsTransform()->extrapolatedState(innTSOS,pointToExtrapTo);
231  GlobalPoint extrapolatedPos;
232  mtsMode()->positionFromModeCartesian(posTSOS,extrapolatedPos);
233  return extrapolatedPos;
234 }
235 
237 {
238  TrajectoryStateOnSurface innTSOS = mtsTransform()->innerStateOnSurface(gsfTrack);
239  TrajectoryStateOnSurface posTSOS = mtsTransform()->extrapolatedState(innTSOS,pointToExtrapTo);
240  GlobalVector extrapolatedMom;
241  mtsMode()->momentumFromModeCartesian(posTSOS,extrapolatedMom);
242  return extrapolatedMom;
243 }
244 
245 //define this as a plug-in
246 //DEFINE_FWK_MODULE(EgammaHLTTrackIsolationProducers);
T getParameter(std::string const &) const
unsigned long long cacheIdentifier() const
virtual void produce(edm::Event &, const edm::EventSetup &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
edm::EDGetTokenT< reco::ElectronCollection > inputCollectionTag1_
edm::EDGetTokenT< reco::GsfTrackCollection > inputCollectionTag2_
GlobalPoint extrapolateTrackPosToPoint(const reco::GsfTrack &gsfTrack, const GlobalPoint &pointToExtrapTo)
GlobalVector extrapolateTrackMomToPoint(const reco::GsfTrack &gsfTrack, const GlobalPoint &pointToExtrapTo)
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
EgammaHLTGsfTrackVarProducer(const edm::ParameterSet &)
edm::EDGetTokenT< reco::RecoEcalCandidateCollection > recoEcalCandTag_
edm::EDGetTokenT< reco::BeamSpot > beamSpotTag_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:76
TrackExtrapolator * operator=(const TrackExtrapolator &rhs)
void insert(const key_type &k, const data_type &v)
insert an association
const T & get() const
Definition: EventSetup.h:55
REF castTo() const
cast to a concrete type
Definition: RefToBase.h:241
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
const Point & position() const
position
Definition: BeamSpot.h:62