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 }
46 
48 {}
49 
52  desc.add<edm::InputTag>(("recoEcalCandidateProducer"), edm::InputTag("hltRecoEcalSuperClusterActivityCandidate"));
53  desc.add<edm::InputTag>(("inputCollection"), edm::InputTag("hltActivityElectronGsfTracks"));
54  desc.add<edm::InputTag>(("beamSpotProducer"), edm::InputTag("hltOnlineBeamSpot"));
55  desc.add<int>(("upperTrackNrToRemoveCut"), 9999);
56  desc.add<int>(("lowerTrackNrToRemoveCut"), -1);
57  descriptions.add("hltEgammaHLTGsfTrackVarProducer", desc);
58 }
60 
61  trackExtrapolator_.setup(iSetup);
62 
63  // Get the HLT filtered objects
65  iEvent.getByToken(recoEcalCandTag_,recoEcalCandHandle);
66 
68  iEvent.getByToken(inputCollectionTag1_,electronHandle);
69 
71  if(!electronHandle.isValid())
72  iEvent.getByToken(inputCollectionTag2_, gsfTracksHandle);
73 
74  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
75  iEvent.getByToken(beamSpotTag_,recoBeamSpotHandle);
76  // gets its position
77  const reco::BeamSpot& beamSpot = *recoBeamSpotHandle;
78 
79  edm::ESHandle<MagneticField> theMagField;
80  iSetup.get<IdealMagneticFieldRecord>().get(theMagField);
81 
84 
85  for(reco::RecoEcalCandidateCollection::const_iterator iRecoEcalCand = recoEcalCandHandle->begin(); iRecoEcalCand != recoEcalCandHandle->end(); iRecoEcalCand++){
86  reco::RecoEcalCandidateRef recoEcalCandRef(recoEcalCandHandle,iRecoEcalCand-recoEcalCandHandle->begin());
87 
88  const reco::SuperClusterRef scRef = recoEcalCandRef->superCluster();
89 
90  //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
91  std::vector<const reco::GsfTrack*> gsfTracks;
92  if(electronHandle.isValid()){
93  for(reco::ElectronCollection::const_iterator eleIt = electronHandle->begin(); eleIt != electronHandle->end(); eleIt++){
94  if(eleIt->superCluster()==scRef){
95  gsfTracks.push_back(&*eleIt->gsfTrack());
96  }
97  }
98  }else{
99  for(reco::GsfTrackCollection::const_iterator trkIt =gsfTracksHandle->begin();trkIt!=gsfTracksHandle->end();++trkIt){
100  edm::RefToBase<TrajectorySeed> seed = trkIt->extra()->seedRef() ;
102  edm::RefToBase<reco::CaloCluster> caloCluster = elseed->caloCluster() ;
103  reco::SuperClusterRef scRefFromTrk = caloCluster.castTo<reco::SuperClusterRef>() ;
104  if(scRefFromTrk==scRef){
105  gsfTracks.push_back(&*trkIt);
106  }
107  }
108 
109  }
110  float dEtaInValue=999999;
111  float dPhiInValue=999999;
112 
113  if(static_cast<int>(gsfTracks.size())>=upperTrackNrToRemoveCut_){
114  dEtaInValue=0;
115  dPhiInValue=0;
116  }else if(static_cast<int>(gsfTracks.size())<=lowerTrackNrToRemoveCut_){
117  dEtaInValue=0;
118  dPhiInValue=0;
119  }else{
120  for(size_t trkNr=0;trkNr<gsfTracks.size();trkNr++){
121 
122  GlobalPoint scPos(scRef->x(),scRef->y(),scRef->z());
123  GlobalPoint trackExtrapToSC = trackExtrapolator_.extrapolateTrackPosToPoint(*gsfTracks[trkNr],scPos);
124  EleRelPointPair scAtVtx(scRef->position(),trackExtrapToSC,beamSpot.position());
125 
126  if(fabs(scAtVtx.dEta())<dEtaInValue) dEtaInValue=fabs(scAtVtx.dEta()); //we are allowing them to come from different tracks
127  if(fabs(scAtVtx.dPhi())<dPhiInValue) dPhiInValue=fabs(scAtVtx.dPhi());//we are allowing them to come from different tracks
128  }
129  }
130 
131  dEtaMap.insert(recoEcalCandRef, dEtaInValue);
132  dPhiMap.insert(recoEcalCandRef, dPhiInValue);
133  }
134 
135  std::auto_ptr<reco::RecoEcalCandidateIsolationMap> dEtaMapForEvent(new reco::RecoEcalCandidateIsolationMap(dEtaMap));
136  std::auto_ptr<reco::RecoEcalCandidateIsolationMap> dPhiMapForEvent(new reco::RecoEcalCandidateIsolationMap(dPhiMap));
137  iEvent.put(dEtaMapForEvent, "Deta" );
138  iEvent.put(dPhiMapForEvent, "Dphi" );
139 }
140 
141 
142 
144  cacheIDTDGeom_(rhs.cacheIDTDGeom_),
145  cacheIDMagField_(rhs.cacheIDMagField_),
146  magField_(rhs.magField_),
147  trackerHandle_(rhs.trackerHandle_),
148  mtsMode_(rhs.mtsMode_)
149 
150 {
152  else mtsTransform_ =0;
153 
154 }
155 
157 {
158  if(this!=&rhs){ //just to ensure we're not copying ourselves
159  cacheIDTDGeom_ = rhs.cacheIDTDGeom_;
160  cacheIDMagField_ = rhs.cacheIDMagField_;
161  magField_ = rhs.magField_;
162  trackerHandle_ = rhs.trackerHandle_;
163  mtsMode_ = rhs.mtsMode_;
164 
165  delete mtsTransform_;
166  if(rhs.mtsTransform_) mtsTransform_ = new MultiTrajectoryStateTransform(*rhs.mtsTransform_);
167  else mtsTransform_ =0;
168  }
169  return this;
170 }
171 
173 {
174  bool updateField(false);
175  if (cacheIDMagField_!=iSetup.get<IdealMagneticFieldRecord>().cacheIdentifier()){
176  updateField = true;
177  cacheIDMagField_=iSetup.get<IdealMagneticFieldRecord>().cacheIdentifier();
178  iSetup.get<IdealMagneticFieldRecord>().get(magField_);
179  }
180 
181  bool updateGeometry(false);
182  if (cacheIDTDGeom_!=iSetup.get<TrackerDigiGeometryRecord>().cacheIdentifier()){
183  updateGeometry = true;
184  cacheIDTDGeom_=iSetup.get<TrackerDigiGeometryRecord>().cacheIdentifier();
185  iSetup.get<TrackerDigiGeometryRecord>().get(trackerHandle_);
186  }
187 
188  if ( updateField || updateGeometry || !mtsTransform_ ) {
189  delete mtsTransform_;
190  mtsTransform_ = new MultiTrajectoryStateTransform(trackerHandle_.product(),magField_.product());
191  }
192 }
193 
195 {
196  TrajectoryStateOnSurface innTSOS = mtsTransform()->innerStateOnSurface(gsfTrack);
197  TrajectoryStateOnSurface posTSOS = mtsTransform()->extrapolatedState(innTSOS,pointToExtrapTo);
198  GlobalPoint extrapolatedPos;
199  mtsMode()->positionFromModeCartesian(posTSOS,extrapolatedPos);
200  return extrapolatedPos;
201 }
202 
204 {
205  TrajectoryStateOnSurface innTSOS = mtsTransform()->innerStateOnSurface(gsfTrack);
206  TrajectoryStateOnSurface posTSOS = mtsTransform()->extrapolatedState(innTSOS,pointToExtrapTo);
207  GlobalVector extrapolatedMom;
208  mtsMode()->momentumFromModeCartesian(posTSOS,extrapolatedMom);
209  return extrapolatedMom;
210 }
211 
212 //define this as a plug-in
213 //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:243
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