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 
11 // Framework
18 
21 //#include "DataFormats/EgammaCandidates/interface/ElectronIsolationAssociation.h"
27 
31 
36 //#include "CondFormats/DataRecord/interface/BeamSpotObjectsRcd.h"//needed?
37 //#include "CondFormats/BeamSpotObjects/interface/BeamSpotObjects.h"//needed?
38 
41 
43 
50 
52 {
53  recoEcalCandTag_ = config.getParameter<edm::InputTag>("recoEcalCandidateProducer");
54  inputCollectionTag_ = config.getParameter<edm::InputTag>("inputCollection");
55  beamSpotTag_ = config.getParameter<edm::InputTag>("beamSpotProducer");
56  upperTrackNrToRemoveCut_ = config.getParameter<int>("upperTrackNrToRemoveCut"); //zeros out dEtaIn,dPhiIn if nrTracks>= this
57  lowerTrackNrToRemoveCut_ = config.getParameter<int>("lowerTrackNrToRemoveCut"); //zeros out dEtaIn,dPhiIn if nrTracks<= this
58 
59 
60 
61  //register your products
62  produces < reco::RecoEcalCandidateIsolationMap >( "Deta" ).setBranchAlias( "deta" );
63  produces < reco::RecoEcalCandidateIsolationMap >( "Dphi" ).setBranchAlias( "dphi" );
64 }
65 
67 
68 
69 //
70 // member functions
71 //
72 
73 // ------------ method called to produce the data ------------
74 void
76 {
77 
78  trackExtrapolator_.setup(iSetup);
79 
80  // Get the HLT filtered objects
82  iEvent.getByLabel(recoEcalCandTag_,recoEcalCandHandle);
83 
85  iEvent.getByLabel(inputCollectionTag_,electronHandle);
86 
88  if(!electronHandle.isValid()) iEvent.getByLabel (inputCollectionTag_,gsfTracksHandle);
89 
90  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
91  iEvent.getByLabel(beamSpotTag_,recoBeamSpotHandle);
92  // gets its position
93  const reco::BeamSpot& beamSpot = *recoBeamSpotHandle;
94 
95  edm::ESHandle<MagneticField> theMagField;
96  iSetup.get<IdealMagneticFieldRecord>().get(theMagField);
97 
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 
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  float dEtaInValue=999999;
127  float dPhiInValue=999999;
128 
129  if(static_cast<int>(gsfTracks.size())>=upperTrackNrToRemoveCut_){
130  dEtaInValue=0;
131  dPhiInValue=0;
132  }else if(static_cast<int>(gsfTracks.size())<=lowerTrackNrToRemoveCut_){
133  dEtaInValue=0;
134  dPhiInValue=0;
135  }else{
136  for(size_t trkNr=0;trkNr<gsfTracks.size();trkNr++){
137 
138  GlobalPoint scPos(scRef->x(),scRef->y(),scRef->z());
139  GlobalPoint trackExtrapToSC = trackExtrapolator_.extrapolateTrackPosToPoint(*gsfTracks[trkNr],scPos);
140  EleRelPointPair scAtVtx(scRef->position(),trackExtrapToSC,beamSpot.position());
141 
142  if(fabs(scAtVtx.dEta())<dEtaInValue) dEtaInValue=fabs(scAtVtx.dEta()); //we are allowing them to come from different tracks
143  if(fabs(scAtVtx.dPhi())<dPhiInValue) dPhiInValue=fabs(scAtVtx.dPhi());//we are allowing them to come from different tracks
144  }
145  }
146 
147  dEtaMap.insert(recoEcalCandRef, dEtaInValue);
148  dPhiMap.insert(recoEcalCandRef, dPhiInValue);
149  }
150 
151  std::auto_ptr<reco::RecoEcalCandidateIsolationMap> dEtaMapForEvent(new reco::RecoEcalCandidateIsolationMap(dEtaMap));
152  std::auto_ptr<reco::RecoEcalCandidateIsolationMap> dPhiMapForEvent(new reco::RecoEcalCandidateIsolationMap(dPhiMap));
153  iEvent.put(dEtaMapForEvent, "Deta" );
154  iEvent.put(dPhiMapForEvent, "Dphi" );
155 
156 }
157 
158 
159 
161  cacheIDTDGeom_(rhs.cacheIDTDGeom_),
162  cacheIDMagField_(rhs.cacheIDMagField_),
163  magField_(rhs.magField_),
164  trackerHandle_(rhs.trackerHandle_),
165  mtsMode_(rhs.mtsMode_)
166 
167 {
169  else mtsTransform_ =0;
170 
171 }
172 
174 {
175  if(this!=&rhs){ //just to ensure we're not copying ourselves
176  cacheIDTDGeom_ = rhs.cacheIDTDGeom_;
177  cacheIDMagField_ = rhs.cacheIDMagField_;
178  magField_ = rhs.magField_;
179  trackerHandle_ = rhs.trackerHandle_;
180  mtsMode_ = rhs.mtsMode_;
181 
182  delete mtsTransform_;
183  if(rhs.mtsTransform_) mtsTransform_ = new MultiTrajectoryStateTransform(*rhs.mtsTransform_);
184  else mtsTransform_ =0;
185  }
186  return this;
187 }
188 
190 {
191  bool updateField(false);
192  if (cacheIDMagField_!=iSetup.get<IdealMagneticFieldRecord>().cacheIdentifier()){
193  updateField = true;
194  cacheIDMagField_=iSetup.get<IdealMagneticFieldRecord>().cacheIdentifier();
195  iSetup.get<IdealMagneticFieldRecord>().get(magField_);
196  }
197 
198  bool updateGeometry(false);
199  if (cacheIDTDGeom_!=iSetup.get<TrackerDigiGeometryRecord>().cacheIdentifier()){
200  updateGeometry = true;
201  cacheIDTDGeom_=iSetup.get<TrackerDigiGeometryRecord>().cacheIdentifier();
202  iSetup.get<TrackerDigiGeometryRecord>().get(trackerHandle_);
203  }
204 
205  if ( updateField || updateGeometry || !mtsTransform_ ) {
206  delete mtsTransform_;
207  mtsTransform_ = new MultiTrajectoryStateTransform(trackerHandle_.product(),magField_.product());
208  }
209 }
210 
212 {
213  TrajectoryStateOnSurface innTSOS = mtsTransform()->innerStateOnSurface(gsfTrack);
214  TrajectoryStateOnSurface posTSOS = mtsTransform()->extrapolatedState(innTSOS,pointToExtrapTo);
215  GlobalPoint extrapolatedPos;
216  mtsMode()->positionFromModeCartesian(posTSOS,extrapolatedPos);
217  return extrapolatedPos;
218 }
219 
221 {
222  TrajectoryStateOnSurface innTSOS = mtsTransform()->innerStateOnSurface(gsfTrack);
223  TrajectoryStateOnSurface posTSOS = mtsTransform()->extrapolatedState(innTSOS,pointToExtrapTo);
224  GlobalVector extrapolatedMom;
225  mtsMode()->momentumFromModeCartesian(posTSOS,extrapolatedMom);
226  return extrapolatedMom;
227 }
228 
229 //define this as a plug-in
230 //DEFINE_FWK_MODULE(EgammaHLTTrackIsolationProducers);
T getParameter(std::string const &) const
unsigned long long cacheIdentifier() const
virtual void produce(edm::Event &, const edm::EventSetup &)
GlobalPoint extrapolateTrackPosToPoint(const reco::GsfTrack &gsfTrack, const GlobalPoint &pointToExtrapTo)
GlobalVector extrapolateTrackMomToPoint(const reco::GsfTrack &gsfTrack, const GlobalPoint &pointToExtrapTo)
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
EgammaHLTGsfTrackVarProducer(const edm::ParameterSet &)
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
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
const Point & position() const
position
Definition: BeamSpot.h:63