CMS 3D CMS Logo

L1Validator.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1T
4 // Class: L1Validator
5 //
14 //
15 // Original Author: Scott Wilbur
16 // Created: Wed, 28 Aug 2013 09:42:55 GMT
17 // $Id$
18 //
19 //
20 
21 #include <string>
22 
24 
26 
28 
29 #include "TFile.h"
30 
31 //defining as a macro instead of a function because inheritance doesn't work:
32 #define FINDRECOPART(TYPE, COLLECTION1, COLLECTION2) \
33 const TYPE *RecoPart=NULL; \
34 double BestDist=999.; \
35 for(uint i=0; i < COLLECTION1->size(); i++){ \
36  const TYPE *ThisPart = &COLLECTION1->at(i); \
37  double ThisDist = reco::deltaR(GenPart->eta(), GenPart->phi(), ThisPart->eta(), ThisPart->phi()); \
38  if(ThisDist < 1.0 && ThisDist < BestDist){ \
39  BestDist = ThisDist; \
40  RecoPart = ThisPart; \
41  } \
42 } \
43 if(COLLECTION1.product() != COLLECTION2.product()){ \
44  for(uint i=0; i < COLLECTION2->size(); i++){ \
45  const TYPE *ThisPart = &COLLECTION2->at(i); \
46  double ThisDist = reco::deltaR(GenPart->eta(), GenPart->phi(), ThisPart->eta(), ThisPart->phi()); \
47  if(ThisDist < 1.0 && ThisDist < BestDist){ \
48  BestDist = ThisDist; \
49  RecoPart = ThisPart; \
50  } \
51  } \
52 }
53 
55  _dirName = iConfig.getParameter<std::string>("dirName");
56  _GenSource = consumes<reco::GenParticleCollection> (iConfig.getParameter<edm::InputTag>("GenSource"));
57 
58  _L1MuonBXSource = consumes<l1t::MuonBxCollection> (iConfig.getParameter<edm::InputTag>("L1MuonBXSource"));
59  _L1EGammaBXSource = consumes<l1t::EGammaBxCollection> (iConfig.getParameter<edm::InputTag>("L1EGammaBXSource"));
60  _L1TauBXSource = consumes<l1t::TauBxCollection> (iConfig.getParameter<edm::InputTag>("L1TauBXSource"));
61  _L1JetBXSource = consumes<l1t::JetBxCollection> (iConfig.getParameter<edm::InputTag>("L1JetBXSource"));
62  _srcToken = mayConsume<GenEventInfoProduct>( iConfig.getParameter<edm::InputTag>("srcToken") );
63  _L1GenJetSource = consumes<reco::GenJetCollection>( iConfig.getParameter<edm::InputTag>("L1GenJetSource"));
64 
65  //_fileName = iConfig.getParameter<std::string>("fileName");
66 }
67 
68 
70 }
71 
73  iBooker.setCurrentFolder(_dirName.c_str());
74  _Hists.Book(iBooker);
75 };
76 
78  using namespace edm;
79  using namespace std;
80  using namespace l1extra;
81  using namespace reco;
82 
88  Handle<GenEventInfoProduct> genEvtInfoProduct;
90 
91  bool GotEverything=true;
92 
93  if(!iEvent.getByToken(_GenSource, GenParticles)) GotEverything=false;
94  if(!iEvent.getByToken(_L1MuonBXSource, MuonsBX)) GotEverything=false;
95  if(!iEvent.getByToken(_L1EGammaBXSource, EGammasBX)) GotEverything=false;
96  if(!iEvent.getByToken(_L1TauBXSource, TausBX)) GotEverything=false;
97  if(!iEvent.getByToken(_L1JetBXSource, JetsBX)) GotEverything=false;
98  if(!iEvent.getByToken(_srcToken, genEvtInfoProduct)) GotEverything=false;
99  if(!iEvent.getByToken(_L1GenJetSource, GenJets)) GotEverything=false;
100 
101  if(!GotEverything) return;
102 
103  /*
104  std::string moduleName = "";
105  if( genEvtInfoProduct.isValid() ) {
106  const edm::Provenance& prov = iEvent.getProvenance(genEvtInfoProduct.id());
107  moduleName = edm::moduleName(prov);
108  //cout<<" generator name: "<<moduleName<<endl;
109  }
110  */
111 
112  _Hists.NEvents++;
113 
115  _Hists.FillNumber(L1ValidatorHists::Type::Egamma, EGammasBX->size());
118 
119  //For gen jet
120 
121  for(auto &Genjet : *GenJets ){
122 
123  // eta within calorimeter acceptance 4.7
124  if(fabs((&Genjet)->eta())>4.7) continue;
125 
126  double minDR = 999.0;
127 
128  // match L1T object
129  const l1t::Jet *L1Part=NULL;
130  for(int iBx = JetsBX->getFirstBX(); iBx<=JetsBX->getLastBX(); ++iBx){
131  if(iBx>0) continue;
132  for(std::vector<l1t::Jet>::const_iterator jet = JetsBX->begin(iBx); jet != JetsBX->end(iBx); ++jet){
133  double idR = reco::deltaR((&Genjet)->eta(), (&Genjet)->phi(), jet->eta(), jet->phi());
134  if( idR < minDR ){
135  minDR = idR;
136  L1Part = &(*jet);
137  }
138  }
139  }
140  _Hists.Fill(L1ValidatorHists::Type::Jet, &Genjet, L1Part);
141  }
142 
143 
144  for(uint i=0; i < GenParticles->size(); i++){
145  const GenParticle *GenPart = &GenParticles->at(i);
146 
147  int pdg = GenPart->pdgId(), status = GenPart->status();
148 
149  double minDR = 999.0;
150 
152  if(status==1 && abs(pdg)==13){ //Muon
153 
154  // eta within tracker acceptance 2.4
155  if(fabs(GenPart->eta())>2.4) continue;
156 
157  // match L1T object
158  const l1t::Muon *L1Part=NULL;
159  for(int iBx = MuonsBX->getFirstBX(); iBx<=MuonsBX->getLastBX(); ++iBx){
160  if(iBx>0) continue;
161  for(std::vector<l1t::Muon>::const_iterator mu = MuonsBX->begin(iBx); mu != MuonsBX->end(iBx); ++mu){
162  double idR = reco::deltaR(GenPart->eta(), GenPart->phi(), mu->eta(), mu->phi());
163  if(idR < minDR ){
164  minDR = idR;
165  L1Part = &(*mu);
166  }
167 
168  }
169  _Hists.Fill(L1ValidatorHists::Type::Muon, GenPart, L1Part);
170  }
171 
172 
174  } else if(status==1 && (abs(pdg)==11 || pdg==22)){ //Egamma
175 
176  // eta within EM calorimeter acceptance 2.5
177  if(fabs(GenPart->eta())>2.5) continue;
178 
179  // exclude the calorimeter barrel and endcap overlap region
180  if(fabs(GenPart->eta())>1.4442 && fabs(GenPart->eta())<1.5660) continue;
181 
182  // match L1T object
183  const l1t::EGamma *L1Part=NULL;
184  for(int iBx = EGammasBX->getFirstBX(); iBx<=EGammasBX->getLastBX(); ++iBx){
185  if(iBx>0) continue;
186  for(std::vector<l1t::EGamma>::const_iterator eg = EGammasBX->begin(iBx); eg != EGammasBX->end(iBx); ++eg){
187  double idR = reco::deltaR(GenPart->eta(), GenPart->phi(), eg->eta(), eg->phi());
188  if(idR < minDR ){
189  minDR = idR;
190  L1Part = &(*eg);
191  }
192  }
193  }
194  _Hists.Fill(L1ValidatorHists::Type::Egamma, GenPart, L1Part);
195 
196 
198  } else if(status==2 && abs(pdg)==15){ //Tau
199 
200  // eta within tracker acceptance 2.4
201  if(fabs(GenPart->eta())>2.4) continue;
202 
203  // match L1T object
204  const l1t::Tau *L1Part=NULL;
205  for(int iBx = TausBX->getFirstBX(); iBx<=TausBX->getLastBX(); ++iBx){
206  if(iBx>0) continue;
207  for(std::vector<l1t::Tau>::const_iterator tau = TausBX->begin(iBx); tau != TausBX->end(iBx); ++tau){
208  double idR = reco::deltaR(GenPart->eta(), GenPart->phi(), tau->eta(), tau->phi());
209  if(idR < minDR ){
210  minDR = idR;
211  L1Part = &(*tau);
212  }
213  }
214  }
215  _Hists.Fill(L1ValidatorHists::Type::Tau, GenPart, L1Part);
216 
217  }
218 
219  }
220 
221 }
222 
223 //The next three are exactly the same, but apparently inheritance doesn't work like I thought it did.
224 const reco::LeafCandidate *L1Validator::FindBest(const reco::GenParticle *GenPart, const std::vector<l1extra::L1EmParticle> *Collection1, const std::vector<l1extra::L1EmParticle> *Collection2=NULL){
225  const reco::LeafCandidate *BestPart=NULL;
226  double BestDR=999.;
227 
228  for(uint i=0; i < Collection1->size(); i++){
229  const reco::LeafCandidate *ThisPart = &Collection1->at(i);
230  double ThisDR = reco::deltaR(GenPart->eta(), GenPart->phi(), ThisPart->eta(), ThisPart->phi());
231  if(ThisDR < BestDR){
232  BestDR = ThisDR;
233  BestPart = ThisPart;
234  }
235  }
236 
237  if(Collection2==NULL) return BestPart;
238 
239  for(uint i=0; i < Collection2->size(); i++){
240  const reco::LeafCandidate *ThisPart = &Collection2->at(i);
241  double ThisDR = reco::deltaR(GenPart->eta(), GenPart->phi(), ThisPart->eta(), ThisPart->phi());
242  if(ThisDR < BestDR){
243  BestDR = ThisDR;
244  BestPart = ThisPart;
245  }
246  }
247 
248  return BestPart;
249 }
250 
251 const reco::LeafCandidate *L1Validator::FindBest(const reco::GenParticle *GenPart, const std::vector<l1extra::L1JetParticle> *Collection1, const std::vector<l1extra::L1JetParticle> *Collection2=NULL){
252  const reco::LeafCandidate *BestPart=NULL;
253  double BestDR=999.;
254 
255  for(uint i=0; i < Collection1->size(); i++){
256  const reco::LeafCandidate *ThisPart = &Collection1->at(i);
257  double ThisDR = reco::deltaR(GenPart->eta(), GenPart->phi(), ThisPart->eta(), ThisPart->phi());
258  if(ThisDR < BestDR){
259  BestDR = ThisDR;
260  BestPart = ThisPart;
261  }
262  }
263 
264  if(Collection2==NULL) return BestPart;
265 
266  for(uint i=0; i < Collection2->size(); i++){
267  const reco::LeafCandidate *ThisPart = &Collection2->at(i);
268  double ThisDR = reco::deltaR(GenPart->eta(), GenPart->phi(), ThisPart->eta(), ThisPart->phi());
269  if(ThisDR < BestDR){
270  BestDR = ThisDR;
271  BestPart = ThisPart;
272  }
273  }
274 
275  return BestPart;
276 }
277 
278 const reco::LeafCandidate *L1Validator::FindBest(const reco::GenParticle *GenPart, const std::vector<l1extra::L1MuonParticle> *Collection1){
279  const reco::LeafCandidate *BestPart=NULL;
280  double BestDR=999.;
281 
282  for(uint i=0; i < Collection1->size(); i++){
283  const reco::LeafCandidate *ThisPart = &Collection1->at(i);
284  double ThisDR = reco::deltaR(GenPart->eta(), GenPart->phi(), ThisPart->eta(), ThisPart->phi());
285  if(ThisDR < BestDR){
286  BestDR = ThisDR;
287  BestPart = ThisPart;
288  }
289  }
290 
291  return BestPart;
292 }
293 
294 
295 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
297  //The following says we do not know what parameters are allowed so do no validation
298  // Please change this to state exactly what you do use, even if it is no parameters
300  desc.setUnknown();
301  descriptions.addDefault(desc);
302 }
303 
304 //define this as a plug-in
void Fill(int, const reco::LeafCandidate *, const reco::LeafCandidate *)
const_iterator end(int bx) const
T getParameter(std::string const &) const
edm::EDGetTokenT< reco::GenJetCollection > _L1GenJetSource
Definition: L1Validator.h:90
unsigned size(int bx) const
virtual double eta() const final
momentum pseudorapidity
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
edm::EDGetTokenT< reco::GenParticleCollection > _GenSource
Definition: L1Validator.h:84
Definition: Tau.h:16
edm::EDGetTokenT< GenEventInfoProduct > _srcToken
Definition: L1Validator.h:89
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: L1Validator.cc:296
#define NULL
Definition: scimark2.h:8
virtual int status() const final
status word
L1Validator(const edm::ParameterSet &)
Definition: L1Validator.cc:54
void FillNumber(int, int)
virtual double phi() const final
momentum azimuthal angle
Definition: Jet.h:16
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
edm::EDGetTokenT< l1t::TauBxCollection > _L1TauBXSource
Definition: L1Validator.h:87
edm::EDGetTokenT< l1t::JetBxCollection > _L1JetBXSource
Definition: L1Validator.h:88
virtual int pdgId() const final
PDG identifier.
std::string _dirName
Definition: L1Validator.h:81
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:28
const int mu
Definition: Constants.h:22
edm::EDGetTokenT< l1t::MuonBxCollection > _L1MuonBXSource
Definition: L1Validator.h:85
Definition: Muon.h:16
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: L1Validator.cc:77
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: L1Validator.cc:72
int getFirstBX() const
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:277
L1ValidatorHists _Hists
Definition: L1Validator.h:92
const reco::LeafCandidate * FindBest(const reco::GenParticle *, const std::vector< l1extra::L1EmParticle > *, const std::vector< l1extra::L1EmParticle > *)
Definition: L1Validator.cc:224
fixed size matrix
HLT enums.
int getLastBX() const
edm::EDGetTokenT< l1t::EGammaBxCollection > _L1EGammaBXSource
Definition: L1Validator.h:86
void Book(DQMStore::IBooker &)
const_iterator begin(int bx) const
Definition: Run.h:42