CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HLTAlphaTFilter.cc
Go to the documentation of this file.
1 
14 #include <vector>
15 
27 
28 typedef ROOT::Math::LorentzVector<ROOT::Math::PtEtaPhiM4D<double> > LorentzV ;
29 
30 //
31 // constructors and destructor
32 //
33 template<typename T>
35 {
36  inputJetTag_ = iConfig.getParameter< edm::InputTag > ("inputJetTag");
37  inputJetTagFastJet_ = iConfig.getParameter< edm::InputTag > ("inputJetTagFastJet");
38  minPtJet_ = iConfig.getParameter<std::vector<double> > ("minPtJet");
39  etaJet_ = iConfig.getParameter<std::vector<double> > ("etaJet");
40  maxNJets_ = iConfig.getParameter<unsigned int> ("maxNJets");
41  minHt_ = iConfig.getParameter<double> ("minHt");
42  minAlphaT_ = iConfig.getParameter<double> ("minAlphaT");
43  triggerType_ = iConfig.getParameter<int>("triggerType");
44  dynamicAlphaT_ = iConfig.getParameter<bool>("dynamicAlphaT");
45  setDHtZero_ = iConfig.getParameter<bool>("setDHtZero");
46  // sanity checks
47 
48  if ( (minPtJet_.size() != etaJet_.size())
49  || ( (minPtJet_.size()<1) || (etaJet_.size()<1) )
50  || ( ((minPtJet_.size()<2) || (etaJet_.size()<2))))
51  {
52  edm::LogError("HLTAlphaTFilter") << "inconsistent module configuration!";
53  }
54 
55  //register your products
56  m_theRecoJetToken = consumes<std::vector<T>>(inputJetTag_);
57  m_theFastJetToken = consumes<std::vector<T>>(inputJetTagFastJet_);
58 }
59 
60 template<typename T>
62 
63 template<typename T>
66  makeHLTFilterDescription(desc);
67  desc.add<edm::InputTag>("inputJetTag",edm::InputTag("hltMCJetCorJetIcone5HF07"));
68  desc.add<edm::InputTag>("inputJetTagFastJet",edm::InputTag("hltMCJetCorJetIcone5HF07"));
69 
70  {
71  std::vector<double> temp1;
72  temp1.reserve(2);
73  temp1.push_back(20.0);
74  temp1.push_back(20.0);
75  desc.add<std::vector<double> >("minPtJet",temp1);
76  }
77  desc.add<int>("minNJet",0);
78  {
79  std::vector<double> temp1;
80  temp1.reserve(2);
81  temp1.push_back(9999.0);
82  temp1.push_back(9999.0);
83  desc.add<std::vector<double> >("etaJet",temp1);
84  }
85  desc.add<unsigned int>("maxNJets",32);
86  desc.add<double>("minHt",0.0);
87  desc.add<double>("minAlphaT",0.0);
88  desc.add<int>("triggerType",trigger::TriggerJet);
89  desc.add<bool>("dynamicAlphaT",true); //Set to reproduce old behaviour
90  desc.add<bool>("setDHtZero",false); //Set to reproduce old behaviour
91  descriptions.add(defaultModuleLabel<HLTAlphaTFilter<T>>(), desc);
92 }
93 
94 
95 
96 // ------------ method called to produce the data ------------
97 template<typename T>
99 {
100 
101  using namespace std;
102  using namespace edm;
103  using namespace reco;
104  using namespace trigger;
105 
106  typedef vector<T> TCollection;
107  typedef Ref<TCollection> TRef;
108 
109  // The filter object
110  if (saveTags()) filterproduct.addCollectionTag(inputJetTag_);
111 
112  TRef ref;
113  // Get the Candidates
114  Handle<TCollection> recojets;
115  iEvent.getByToken(m_theRecoJetToken,recojets);
116 
117  // We have to also look at the L1 FastJet Corrections, at the same time we look at our other jets.
118  // We calcualte our HT from the FastJet collection and AlphaT from the standard collection.
119  CaloJetRef ref_FastJet;
120  // Get the Candidates
121  Handle<TCollection> recojetsFastJet;
122  iEvent.getByToken(m_theFastJetToken,recojetsFastJet);
123 
124 
125  int n(0);
126 
127  //OLD - DYNAMIC ALPHAT BEHAVIOUR
128  //Produce AlphaT dynamically, first on two jets, then three etc until it does
129  //or doesn't pass
130  if (dynamicAlphaT_){
131  // look at all candidates, check cuts and add to filter object
132  int flag(0);
133  double htFast = 0.;
134  double aT =0.;
135  unsigned int njets(0);
136 
137  if(recojets->size() > 1){
138  // events with at least two jets, needed for alphaT
139  // Make a vector of Lorentz Jets for the AlphaT calcualtion
140  std::vector<LorentzV> jets;
141  typename TCollection::const_iterator ijet = recojets->begin();
142  typename TCollection::const_iterator ijetFast = recojetsFastJet->begin();
143  typename TCollection::const_iterator jjet = recojets->end();
144 
145 
146 
147  for( ; ijet != jjet; ijet++, ijetFast++ ) {
148  if( flag == 1) break;
149  // Do Some Jet selection!
150  if( std::abs(ijet->eta()) > etaJet_.at(0) ) continue;
151  if( ijet->et() < minPtJet_.at(0) ) continue;
152  njets++;
153 
154  if (njets > maxNJets_) //to keep timing reasonable - if too many jets passing pt / eta cuts, just accept the event
155  flag = 1;
156 
157  else {
158 
159  if( std::abs(ijetFast->eta()) < etaJet_.at(1) ){
160  if( ijetFast->et() > minPtJet_.at(1) ) {
161  // Add to HT
162  htFast += ijetFast->et();
163  }
164  }
165 
166  // Add to JetVector
167  LorentzV JetLVec(ijet->pt(),ijet->eta(),ijet->phi(),ijet->mass());
168  jets.push_back( JetLVec );
169  aT = AlphaT(jets,setDHtZero_).value();
170  if(htFast > minHt_ && aT > minAlphaT_){
171  // set flat to one so that we don't carry on looping though the jets
172  flag = 1;
173  }
174  }
175 
176  }
177 
178  //If passed, add jets to the filter product for the DQM
179  if (flag==1) {
180  for (typename TCollection::const_iterator recojet = recojets->begin(); recojet!=jjet; recojet++) {
181  if (recojet->et() > minPtJet_.at(0)) {
182  ref = TRef(recojets,distance(recojets->begin(),recojet));
183  filterproduct.addObject(triggerType_,ref);
184  n++;
185  }
186  }
187  }
188  }// events with at least two jet
189 
190  // filter decision
191  bool accept(n>0);
192 
193  return accept;
194  }
195  // NEW - STATIC ALPHAT BEHAVIOUR
196  // just reproduce
197  else{
198  // look at all candidates, check cuts and add to filter object
199  int flag(0);
200  typename TCollection::const_iterator ijet = recojets->begin();
201  typename TCollection::const_iterator jjet = recojets->end();
202 
203 
204  if( (recojets->size() > 1) && (recojetsFastJet->size() > 1) ){
205 
206  // events with at least two jets, needed for alphaT
207  double htFast = 0.;
208  typename TCollection::const_iterator ijetFast = recojetsFastJet->begin();
209  typename TCollection::const_iterator jjetFast = recojetsFastJet->end();
210  for( ; ijetFast != jjetFast; ijetFast++ ) {
211  if( std::abs(ijetFast->eta()) < etaJet_.at(1) ){
212  if( ijetFast->et() > minPtJet_.at(1) ) {
213  // Add to HT
214  htFast += ijetFast->et();
215  }
216  }
217  }
218 
219  if(htFast > minHt_){
220 
221  unsigned int njets(0);
222  // Make a vector of Lorentz Jets for the AlphaT calcualtion
223  std::vector<LorentzV> jets;
224  for( ; ijet != jjet; ijet++ ) {
225  if( std::abs(ijet->eta()) > etaJet_.at(0) ) continue;
226  if( ijet->et() < minPtJet_.at(0) ) continue;
227  njets++;
228 
229  if (njets > maxNJets_) { //to keep timing reasonable - if too many jets passing pt / eta cuts, just accept the event
230  flag = 1;
231  break; //Added for efficiency
232  }
233 
234  // Add to JetVector
235  LorentzV JetLVec(ijet->pt(),ijet->eta(),ijet->phi(),ijet->mass());
236  jets.push_back( JetLVec );
237 
238  }
239 
240  if(flag!=1){ //Added for efficiency
241  //Calculate the value for alphaT
242  float aT = AlphaT(jets,setDHtZero_).value();
243 
244  // Trigger decision!
245  if(aT > minAlphaT_){
246  flag = 1;
247  }
248  }
249 
250  //If passed, add the jets to the filterproduct for DQM
251  if (flag==1) {
252  for (typename TCollection::const_iterator recojet = recojets->begin(); recojet!=jjet; recojet++) {
253  if (recojet->et() > minPtJet_.at(0)) {
254  ref = TRef(recojets,distance(recojets->begin(),recojet));
255  filterproduct.addObject(triggerType_,ref);
256  n++;
257  }
258  }
259  }
260  }
261  }// events with at least two jet
262 
263  // filter decision
264  bool accept(n>0);
265 
266  return accept;
267  }
268 
269  // THIS WILL NEVER HAPPEN
270  return true;
271 }
T getParameter(std::string const &) const
std::string defaultModuleLabel()
edm::EDGetTokenT< std::vector< T > > m_theRecoJetToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
edm::InputTag inputJetTagFastJet_
virtual bool hltFilter(edm::Event &, const edm::EventSetup &, trigger::TriggerFilterObjectWithRefs &filterproduct) const override
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:24
void addObject(int id, const reco::RecoEcalCandidateRef &ref)
setters for L3 collections: (id=physics type, and Ref&lt;C&gt;)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int iEvent
Definition: GenABIO.cc:230
edm::InputTag inputJetTag_
vector< PseudoJet > jets
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
HLTAlphaTFilter(const edm::ParameterSet &)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > LorentzV
edm::EDGetTokenT< std::vector< T > > m_theFastJetToken
void addCollectionTag(const edm::InputTag &collectionTag)
collectionTags
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< double > minPtJet_
std::vector< double > etaJet_
unsigned int maxNJets_