CMS 3D CMS Logo

HLTDeDxFilter.cc
Go to the documentation of this file.
1 
9 
11 
13 
15 
16 //#include "DataFormats/JetReco/interface/CaloJetCollection.h"
19 
23 //#include "DataFormats/Math/interface/deltaPhi.h"
29 #include <vector>
32 
33 //
34 // constructors and destructor
35 //
37 {
38  minDEDx_ = iConfig.getParameter<double> ("minDEDx");
39  minPT_ = iConfig.getParameter<double> ("minPT");
40  minNOM_ = iConfig.getParameter<double> ("minNOM");
41  maxETA_ = iConfig.getParameter<double> ("maxETA");
42  minNumValidHits_ = iConfig.getParameter<double> ("minNumValidHits");
43  maxNHitMissIn_ = iConfig.getParameter<double> ("maxNHitMissIn");
44  maxNHitMissMid_ = iConfig.getParameter<double> ("maxNHitMissMid");
45  maxRelTrkIsoDeltaRp3_ = iConfig.getParameter<double> ("maxRelTrkIsoDeltaRp3");
46  relTrkIsoDeltaRSize_ = iConfig.getParameter<double> ("relTrkIsoDeltaRSize");
47  maxAssocCaloE_ = iConfig.getParameter<double> ("maxAssocCaloE");
48  maxAssocCaloEDeltaRSize_ = iConfig.getParameter<double> ("maxAssocCaloEDeltaRSize");
49  inputTracksTag_ = iConfig.getParameter< edm::InputTag > ("inputTracksTag");
50  inputdedxTag_ = iConfig.getParameter< edm::InputTag > ("inputDeDxTag");
51  caloTowersTag_ = iConfig.getParameter<edm::InputTag>("caloTowersTag");
52 
53  if(maxAssocCaloE_ >= 0) caloTowersToken_ = consumes<CaloTowerCollection> (iConfig.getParameter<edm::InputTag>("caloTowersTag"));
54  inputTracksToken_ = consumes<reco::TrackCollection>(iConfig.getParameter< edm::InputTag > ("inputTracksTag"));
55  inputdedxToken_ = consumes<edm::ValueMap<reco::DeDxData> >(iConfig.getParameter< edm::InputTag > ("inputDeDxTag"));
56 
57  thisModuleTag_ = edm::InputTag(iConfig.getParameter<std::string>("@module_label"));
58 
59  //register your products
60  produces<reco::RecoChargedCandidateCollection>();
61 }
62 
63 
65 
68  desc.add<bool>("saveTags",false);
69  desc.add<double>("minDEDx",0.0);
70  desc.add<double>("minPT",0.0);
71  desc.add<double>("minNOM",0.0);
72  desc.add<double>("maxETA",5.5);
73  desc.add<double>("minNumValidHits",0);
74  desc.add<double>("maxNHitMissIn",99);
75  desc.add<double>("maxNHitMissMid",99);
76  desc.add<double>("maxRelTrkIsoDeltaRp3", -1);
77  desc.add<double>("relTrkIsoDeltaRSize", 0.3);
78  desc.add<double>("maxAssocCaloE", -99);
79  desc.add<double>("maxAssocCaloEDeltaRSize", 0.5);
80  desc.add<edm::InputTag>("caloTowersTag",edm::InputTag("hltTowerMakerForAll"));
81  desc.add<edm::InputTag>("inputTracksTag",edm::InputTag("hltL3Mouns"));
82  desc.add<edm::InputTag>("inputDeDxTag",edm::InputTag("HLTdedxHarm2"));
83  descriptions.add("hltDeDxFilter",desc);
84 }
85 
86 
87 
88 // ------------ method called to produce the data ------------
89 bool
91 {
92  using namespace std;
93  using namespace edm;
94  using namespace reco;
95  using namespace trigger;
96 
97  auto chargedCandidates = std::make_unique<std::vector<RecoChargedCandidate>>();
98 
99  ModuleDescription moduleDesc_;
100 
101  if (saveTags()){
102  filterproduct.addCollectionTag(thisModuleTag_);
103  filterproduct.addCollectionTag(inputTracksTag_);
104  filterproduct.addCollectionTag(inputdedxTag_);
105  }
106 
107  edm::Handle<reco::TrackCollection> trackCollectionHandle;
108  iEvent.getByToken(inputTracksToken_,trackCollectionHandle);
109  const reco::TrackCollection &trackCollection = *trackCollectionHandle.product();
110 
112  iEvent.getByToken(inputdedxToken_, dEdxTrackHandle);
113  const edm::ValueMap<reco::DeDxData> &dEdxTrack = *dEdxTrackHandle.product();
114 
115  edm::Handle<CaloTowerCollection> caloTowersHandle;
116  if(maxAssocCaloE_ >= 0) iEvent.getByToken(caloTowersToken_, caloTowersHandle);
117 
118  bool accept=false;
119  int NTracks = 0;
120  //fill local arrays for eta, phi, and pt
121  float eta[trackCollection.size()], phi[trackCollection.size()], pt[trackCollection.size()];
122  for(unsigned int i=0; i<trackCollection.size(); i++){
123  eta[i] = trackCollection[i].eta();
124  phi[i] = trackCollection[i].phi();
125  pt[i] = trackCollection[i].pt();
126  }
127  for(unsigned int i=0; i<trackCollection.size(); i++){
128  reco::TrackRef track = reco::TrackRef( trackCollectionHandle, i );
129  if(pt[i]>minPT_ && fabs(eta[i])<maxETA_ && dEdxTrack[track].numberOfMeasurements()>minNOM_ && dEdxTrack[track].dEdx()>minDEDx_){
130  NTracks++;
131  if(track->numberOfValidHits() < minNumValidHits_) continue;
132  if(track->hitPattern().trackerLayersWithoutMeasurement( reco::HitPattern::MISSING_INNER_HITS) > maxNHitMissIn_) continue;
133  if(track->hitPattern().trackerLayersWithoutMeasurement( reco::HitPattern::TRACK_HITS) > maxNHitMissMid_) continue;
134  if (saveTags()){
135  Particle::Charge q = track->charge();
136  //SAVE DEDX INFORMATION AS IF IT WAS THE MASS OF THE PARTICLE
137  Particle::LorentzVector p4(track->px(), track->py(), track->pz(), sqrt(pow(track->p(),2) + pow(dEdxTrack[track].dEdx(),2)));
138  Particle::Point vtx(track->vx(),track->vy(), track->vz());
139  //SAVE NOH, NOM, NOS INFORMATION AS IF IT WAS THE PDGID OF THE PARTICLE
140  int Hits = ((dEdxTrack[track].numberOfSaturatedMeasurements()&0xFF)<<16) | ((dEdxTrack[track].numberOfMeasurements()&0xFF)<<8) | (track->found()&0xFF);
141  RecoChargedCandidate cand(q, p4, vtx, Hits, 0);
142  cand.setTrack(track);
143  chargedCandidates->push_back(cand);
144  }
145 
146  //calculate relative trk isolation only if parameter maxRelTrkIsoDeltaRp3 is greater than 0
147  if(maxRelTrkIsoDeltaRp3_ >= 0){
148  auto ptCone = trackCollection[i].pt();
149  for(unsigned int j=0; j<trackCollection.size(); j++){
150  if (i==j) continue; // do not compare track to itself
151  auto trkDeltaR2 = deltaR2(eta[i], phi[i], eta[j], phi[j]);
152  if (trkDeltaR2 < relTrkIsoDeltaRSize_ * relTrkIsoDeltaRSize_){
153  ptCone+=pt[j];
154  }
155  }
156  double relTrkIso = (ptCone - pt[i])/(pt[i]);
157  if (relTrkIso > maxRelTrkIsoDeltaRp3_) continue;
158  }
159 
160  //calculate the calorimeter energy associated with the track if maxAssocCaloE_ >= 0
161  if(maxAssocCaloE_ >= 0){
162  //Access info about Calo Towers
163  double caloEMDeltaRp5 = 0;
164  double caloHadDeltaRp5 = 0;
165  const CaloTowerCollection &caloTower = *caloTowersHandle.product();
166  for (CaloTowerCollection::const_iterator j=caloTower.begin(); j!=caloTower.end(); j++) {
167  auto caloDeltaR2 = deltaR2(eta[i], phi[i], j->eta(), j->phi());
168  double Eem = j->emEnergy();
169  double Ehad = j->hadEnergy();
170 
171  if (caloDeltaR2 < (maxAssocCaloEDeltaRSize_ * maxAssocCaloEDeltaRSize_) ) {
172  caloEMDeltaRp5 += Eem;
173  caloHadDeltaRp5 += Ehad;
174  }
175  }
176  if (caloEMDeltaRp5 + caloHadDeltaRp5 > maxAssocCaloE_) continue;
177  }
178 
179  accept=true;
180  }
181  }
182 
183  // put filter object into the Event
184  if(saveTags()){
185  edm::OrphanHandle<RecoChargedCandidateCollection> chargedCandidatesHandle = iEvent.put(std::move(chargedCandidates));
186  for(int i=0; i<NTracks; i++){
187  filterproduct.addObject(TriggerMuon,RecoChargedCandidateRef(chargedCandidatesHandle,i));
188  }
189  }
190 
191  return accept;
192 }
193 
194 //define this as a plug-in
T getParameter(std::string const &) const
edm::EDGetToken inputdedxToken_
Definition: HLTDeDxFilter.h:45
double maxNHitMissMid_
Definition: HLTDeDxFilter.h:38
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
edm::EDGetToken inputTracksToken_
Definition: HLTDeDxFilter.h:43
double relTrkIsoDeltaRSize_
Definition: HLTDeDxFilter.h:40
double maxAssocCaloEDeltaRSize_
Definition: HLTDeDxFilter.h:42
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:15
std::vector< CaloTower >::const_iterator const_iterator
edm::Ref< RecoChargedCandidateCollection > RecoChargedCandidateRef
reference to an object in a collection of RecoChargedCandidate objects
edm::EDGetToken caloTowersToken_
Definition: HLTDeDxFilter.h:44
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:30
std::pair< double, double > Point
Definition: CaloEllipse.h:18
HLTDeDxFilter(const edm::ParameterSet &)
edm::InputTag inputdedxTag_
Definition: HLTDeDxFilter.h:48
edm::InputTag thisModuleTag_
Definition: HLTDeDxFilter.h:49
void addObject(int id, const reco::RecoEcalCandidateRef &ref)
setters for L3 collections: (id=physics type, and Ref<C>)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
double maxRelTrkIsoDeltaRp3_
Definition: HLTDeDxFilter.h:39
T sqrt(T t)
Definition: SSEVec.h:18
double p4[4]
Definition: TauolaWrapper.h:92
edm::InputTag inputTracksTag_
Definition: HLTDeDxFilter.h:47
edm::InputTag caloTowersTag_
Definition: HLTDeDxFilter.h:46
double maxAssocCaloE_
Definition: HLTDeDxFilter.h:41
ParameterDescriptionBase * add(U const &iLabel, T const &value)
const_iterator end() const
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
T const * product() const
Definition: Handle.h:74
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:21
void addCollectionTag(const edm::InputTag &collectionTag)
collectionTags
void add(std::string const &label, ParameterSetDescription const &psetDescription)
bool hltFilter(edm::Event &, const edm::EventSetup &, trigger::TriggerFilterObjectWithRefs &filterproduct) const override
fixed size matrix
bool saveTags() const
Definition: HLTFilter.h:45
HLT enums.
~HLTDeDxFilter() override
double minNumValidHits_
Definition: HLTDeDxFilter.h:36
void setTrack(const reco::TrackRef &r)
set reference to track
double maxNHitMissIn_
Definition: HLTDeDxFilter.h:37
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
def move(src, dest)
Definition: eostools.py:511
const_iterator begin() const
math::PtEtaPhiELorentzVectorF LorentzVector