CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
56  _dirName = iConfig.getParameter<std::string>("dirName");
57  _GenSource = consumes<reco::GenParticleCollection> (iConfig.getParameter<edm::InputTag>("GenSource"));
58 
59  _L1ExtraIsoEGSource = consumes<l1extra::L1EmParticleCollection> (iConfig.getParameter<edm::InputTag>("L1ExtraIsoEGSource"));
60  _L1ExtraNonIsoEGSource = consumes<l1extra::L1EmParticleCollection> (iConfig.getParameter<edm::InputTag>("L1ExtraNonIsoEGSource"));
61  _L1ExtraCenJetSource = consumes<l1extra::L1JetParticleCollection> (iConfig.getParameter<edm::InputTag>("L1ExtraCenJetSource"));
62  _L1ExtraForJetSource = consumes<l1extra::L1JetParticleCollection> (iConfig.getParameter<edm::InputTag>("L1ExtraForJetSource"));
63  _L1ExtraTauJetSource = consumes<l1extra::L1JetParticleCollection> (iConfig.getParameter<edm::InputTag>("L1ExtraTauJetSource"));
64  _L1ExtraMuonSource = consumes<l1extra::L1MuonParticleCollection> (iConfig.getParameter<edm::InputTag>("L1ExtraMuonSource"));
65  //_L1ExtraMETSource = consumes<l1extra::L1EtMissParticleCollection> (iConfig.getParameter<edm::InputTag>("L1ExtraMETSource"));
66 
67  //_fileName = iConfig.getParameter<std::string>("fileName");
68 
70 }
71 
72 
74 }
75 
77  using namespace edm;
78  using namespace std;
79  using namespace l1extra;
80  using namespace reco;
81 
82  Handle<GenParticleCollection> GenParticles;
89  //Handle<L1EtMissParticleCollection> METs;
90 
91  bool GotEverything=true;
92 
93  if(!iEvent.getByToken(_GenSource, GenParticles)) GotEverything=false;
94  if(!iEvent.getByToken(_L1ExtraIsoEGSource, IsoEGs)) GotEverything=false;
95  if(!iEvent.getByToken(_L1ExtraNonIsoEGSource, NonIsoEGs)) GotEverything=false;
96  if(!iEvent.getByToken(_L1ExtraCenJetSource, CenJets)) GotEverything=false;
97  if(!iEvent.getByToken(_L1ExtraForJetSource, ForJets)) GotEverything=false;
98  if(!iEvent.getByToken(_L1ExtraTauJetSource, Taus)) GotEverything=false;
99  if(!iEvent.getByToken(_L1ExtraMuonSource, Muons)) GotEverything=false;
100 
101  if(!GotEverything) return;
102 
103 
104  _Hists->NEvents++;
105 
107  _Hists->FillNumber(L1ValidatorHists::Type::NonIsoEG, NonIsoEGs->size());
112 
113  for(uint i=0; i < GenParticles->size(); i++){
114  const GenParticle *GenPart = &GenParticles->at(i);
115 
116  int pdg = GenPart->pdgId(), status = GenPart->status();
117 
118  if(status==1 && (abs(pdg)==11 || pdg==22)){
119  FINDRECOPART(L1EmParticle, IsoEGs, NonIsoEGs)
120 
121  if(RecoPart==NULL){
123  _Hists->Fill(L1ValidatorHists::Type::NonIsoEG, GenPart, NULL);
124  }else if(RecoPart->type() == L1EmParticle::EmType::kIsolated){
125  _Hists->Fill(L1ValidatorHists::Type::IsoEG, GenPart, RecoPart);
126  _Hists->Fill(L1ValidatorHists::Type::NonIsoEG, GenPart, NULL);
127  }else if(RecoPart->type() == L1EmParticle::EmType::kNonIsolated){
129  _Hists->Fill(L1ValidatorHists::Type::NonIsoEG, GenPart, RecoPart);
130  }
131  }else if(status==1 && abs(pdg)==13){
132  FINDRECOPART(L1MuonParticle, Muons, Muons)
133 
134  _Hists->Fill(L1ValidatorHists::Type::Muon, GenPart, RecoPart);
135  }else if(status==3 && abs(pdg)==15){
136  FINDRECOPART(L1JetParticle, Taus, Taus)
137 
138  _Hists->Fill(L1ValidatorHists::Type::TauJet, GenPart, RecoPart);
139  }else if(status==3 && (abs(pdg)<=5 || pdg==21)){
140  FINDRECOPART(L1JetParticle, CenJets, ForJets)
141 
142  if(RecoPart==NULL){
145  }else if(RecoPart->type() == L1JetParticle::JetType::kCentral){
146  _Hists->Fill(L1ValidatorHists::Type::CenJet, GenPart, RecoPart);
148  }else if(RecoPart->type() == L1JetParticle::JetType::kForward){
150  _Hists->Fill(L1ValidatorHists::Type::ForJet, GenPart, RecoPart);
151  }
152  }else continue;
153 
154  //cout << GenPart->pt() << '\t' << GenPart->eta() << '\t' << GenPart->phi() << '\t' << GenPart->pdgId() << endl;
155  }
156 }
157 
158 
159 // ------------ method called once each job just before starting event loop ------------
160 /*
161 void L1Validator::beginJob(){
162 }
163 */
164 
165 // ------------ method called once each job just after ending the event loop ------------
167 
168  //TFile OutFile(_fileName.c_str(), "recreate");
169  //_Hists->Write();
170  //OutFile.Close();
171 }
172 
173 // ------------ method called when starting to processes a run ------------
175  _dbe->setCurrentFolder(_dirName.c_str());
176  _Hists->Book();
177 }
178 
179 // ------------ method called when ending the processing of a run ------------
180 
182  //_Hists->Normalize();
183 }
184 
185 
186 // ------------ method called when starting to processes a luminosity block ------------
187 /*
188 void L1Validator::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
189 {
190 }
191 */
192 
193 // ------------ method called when ending the processing of a luminosity block ------------
194 /*
195 void L1Validator::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
196 {
197 }
198 */
199 
200 
201 //The next three are exactly the same, but apparently inheritance doesn't work like I thought it did.
202 const reco::LeafCandidate *L1Validator::FindBest(const reco::GenParticle *GenPart, const std::vector<l1extra::L1EmParticle> *Collection1, const std::vector<l1extra::L1EmParticle> *Collection2=NULL){
203  const reco::LeafCandidate *BestPart=NULL;
204  double BestDR=999.;
205 
206  for(uint i=0; i < Collection1->size(); i++){
207  const reco::LeafCandidate *ThisPart = &Collection1->at(i);
208  double ThisDR = reco::deltaR(GenPart->eta(), GenPart->phi(), ThisPart->eta(), ThisPart->phi());
209  if(ThisDR < BestDR){
210  BestDR = ThisDR;
211  BestPart = ThisPart;
212  }
213  }
214 
215  if(Collection2==NULL) return BestPart;
216 
217  for(uint i=0; i < Collection2->size(); i++){
218  const reco::LeafCandidate *ThisPart = &Collection2->at(i);
219  double ThisDR = reco::deltaR(GenPart->eta(), GenPart->phi(), ThisPart->eta(), ThisPart->phi());
220  if(ThisDR < BestDR){
221  BestDR = ThisDR;
222  BestPart = ThisPart;
223  }
224  }
225 
226  return BestPart;
227 }
228 
229 const reco::LeafCandidate *L1Validator::FindBest(const reco::GenParticle *GenPart, const std::vector<l1extra::L1JetParticle> *Collection1, const std::vector<l1extra::L1JetParticle> *Collection2=NULL){
230  const reco::LeafCandidate *BestPart=NULL;
231  double BestDR=999.;
232 
233  for(uint i=0; i < Collection1->size(); i++){
234  const reco::LeafCandidate *ThisPart = &Collection1->at(i);
235  double ThisDR = reco::deltaR(GenPart->eta(), GenPart->phi(), ThisPart->eta(), ThisPart->phi());
236  if(ThisDR < BestDR){
237  BestDR = ThisDR;
238  BestPart = ThisPart;
239  }
240  }
241 
242  if(Collection2==NULL) return BestPart;
243 
244  for(uint i=0; i < Collection2->size(); i++){
245  const reco::LeafCandidate *ThisPart = &Collection2->at(i);
246  double ThisDR = reco::deltaR(GenPart->eta(), GenPart->phi(), ThisPart->eta(), ThisPart->phi());
247  if(ThisDR < BestDR){
248  BestDR = ThisDR;
249  BestPart = ThisPart;
250  }
251  }
252 
253  return BestPart;
254 }
255 
256 const reco::LeafCandidate *L1Validator::FindBest(const reco::GenParticle *GenPart, const std::vector<l1extra::L1MuonParticle> *Collection1){
257  const reco::LeafCandidate *BestPart=NULL;
258  double BestDR=999.;
259 
260  for(uint i=0; i < Collection1->size(); i++){
261  const reco::LeafCandidate *ThisPart = &Collection1->at(i);
262  double ThisDR = reco::deltaR(GenPart->eta(), GenPart->phi(), ThisPart->eta(), ThisPart->phi());
263  if(ThisDR < BestDR){
264  BestDR = ThisDR;
265  BestPart = ThisPart;
266  }
267  }
268 
269  return BestPart;
270 }
271 
272 
273 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
275  //The following says we do not know what parameters are allowed so do no validation
276  // Please change this to state exactly what you do use, even if it is no parameters
278  desc.setUnknown();
279  descriptions.addDefault(desc);
280 }
281 
282 //define this as a plug-in
void Fill(int, const reco::LeafCandidate *, const reco::LeafCandidate *)
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
virtual void endJob() override
Definition: L1Validator.cc:166
virtual int pdgId() const GCC11_FINAL
PDG identifier.
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
edm::EDGetTokenT< reco::GenParticleCollection > _GenSource
Definition: L1Validator.h:83
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: L1Validator.cc:274
#define NULL
Definition: scimark2.h:8
virtual void endRun(edm::Run const &, edm::EventSetup const &) override
Definition: L1Validator.cc:181
L1Validator(const edm::ParameterSet &)
Definition: L1Validator.cc:54
void FillNumber(int, int)
virtual float phi() const GCC11_FINAL
momentum azimuthal angle
edm::EDGetTokenT< l1extra::L1JetParticleCollection > _L1ExtraForJetSource
Definition: L1Validator.h:87
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
virtual int status() const GCC11_FINAL
status word
L1ValidatorHists * _Hists
Definition: L1Validator.h:92
std::string _dirName
Definition: L1Validator.h:80
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:30
DQMStore * _dbe
Definition: L1Validator.h:79
#define FINDRECOPART(TYPE, COLLECTION1, COLLECTION2)
Definition: L1Validator.cc:32
virtual float eta() const GCC11_FINAL
momentum pseudorapidity
edm::EDGetTokenT< l1extra::L1JetParticleCollection > _L1ExtraTauJetSource
Definition: L1Validator.h:88
edm::EDGetTokenT< l1extra::L1MuonParticleCollection > _L1ExtraMuonSource
Definition: L1Validator.h:89
edm::EDGetTokenT< l1extra::L1EmParticleCollection > _L1ExtraIsoEGSource
Definition: L1Validator.h:84
const reco::LeafCandidate * FindBest(const reco::GenParticle *, const std::vector< l1extra::L1EmParticle > *, const std::vector< l1extra::L1EmParticle > *)
Definition: L1Validator.cc:202
edm::EDGetTokenT< l1extra::L1EmParticleCollection > _L1ExtraNonIsoEGSource
Definition: L1Validator.h:85
virtual void beginRun(edm::Run const &, edm::EventSetup const &) override
Definition: L1Validator.cc:174
edm::EDGetTokenT< l1extra::L1JetParticleCollection > _L1ExtraCenJetSource
Definition: L1Validator.h:86
void analyze(const edm::Event &, const edm::EventSetup &)
Definition: L1Validator.cc:76
tuple status
Definition: ntuplemaker.py:245
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:677
Definition: Run.h:41