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 
55  _dirName = iConfig.getParameter<std::string>("dirName");
56  _GenSource = consumes<reco::GenParticleCollection> (iConfig.getParameter<edm::InputTag>("GenSource"));
57 
58  _L1ExtraIsoEGSource = consumes<l1extra::L1EmParticleCollection> (iConfig.getParameter<edm::InputTag>("L1ExtraIsoEGSource"));
59  _L1ExtraNonIsoEGSource = consumes<l1extra::L1EmParticleCollection> (iConfig.getParameter<edm::InputTag>("L1ExtraNonIsoEGSource"));
60  _L1ExtraCenJetSource = consumes<l1extra::L1JetParticleCollection> (iConfig.getParameter<edm::InputTag>("L1ExtraCenJetSource"));
61  _L1ExtraForJetSource = consumes<l1extra::L1JetParticleCollection> (iConfig.getParameter<edm::InputTag>("L1ExtraForJetSource"));
62  _L1ExtraTauJetSource = consumes<l1extra::L1JetParticleCollection> (iConfig.getParameter<edm::InputTag>("L1ExtraTauJetSource"));
63  _L1ExtraMuonSource = consumes<l1extra::L1MuonParticleCollection> (iConfig.getParameter<edm::InputTag>("L1ExtraMuonSource"));
64  //_L1ExtraMETSource = consumes<l1extra::L1EtMissParticleCollection> (iConfig.getParameter<edm::InputTag>("L1ExtraMETSource"));
65 
66  //_fileName = iConfig.getParameter<std::string>("fileName");
67 }
68 
69 
71 }
72 
74  iBooker.setCurrentFolder(_dirName.c_str());
75  _Hists.Book(iBooker);
76 };
77 
79  using namespace edm;
80  using namespace std;
81  using namespace l1extra;
82  using namespace reco;
83 
84  Handle<GenParticleCollection> GenParticles;
91  //Handle<L1EtMissParticleCollection> METs;
92 
93  bool GotEverything=true;
94 
95  if(!iEvent.getByToken(_GenSource, GenParticles)) GotEverything=false;
96  if(!iEvent.getByToken(_L1ExtraIsoEGSource, IsoEGs)) GotEverything=false;
97  if(!iEvent.getByToken(_L1ExtraNonIsoEGSource, NonIsoEGs)) GotEverything=false;
98  if(!iEvent.getByToken(_L1ExtraCenJetSource, CenJets)) GotEverything=false;
99  if(!iEvent.getByToken(_L1ExtraForJetSource, ForJets)) GotEverything=false;
100  if(!iEvent.getByToken(_L1ExtraTauJetSource, Taus)) GotEverything=false;
101  if(!iEvent.getByToken(_L1ExtraMuonSource, Muons)) GotEverything=false;
102 
103  if(!GotEverything) return;
104 
105 
106  _Hists.NEvents++;
107 
109  _Hists.FillNumber(L1ValidatorHists::Type::NonIsoEG, NonIsoEGs->size());
114 
115  for(uint i=0; i < GenParticles->size(); i++){
116  const GenParticle *GenPart = &GenParticles->at(i);
117 
118  int pdg = GenPart->pdgId(), status = GenPart->status();
119 
120  if(status==1 && (abs(pdg)==11 || pdg==22)){
121  FINDRECOPART(L1EmParticle, IsoEGs, NonIsoEGs)
122 
123  if(RecoPart==NULL){
125  _Hists.Fill(L1ValidatorHists::Type::NonIsoEG, GenPart, NULL);
126  }else if(RecoPart->type() == L1EmParticle::EmType::kIsolated){
127  _Hists.Fill(L1ValidatorHists::Type::IsoEG, GenPart, RecoPart);
128  _Hists.Fill(L1ValidatorHists::Type::NonIsoEG, GenPart, NULL);
129  }else if(RecoPart->type() == L1EmParticle::EmType::kNonIsolated){
131  _Hists.Fill(L1ValidatorHists::Type::NonIsoEG, GenPart, RecoPart);
132  }
133  }else if(status==1 && abs(pdg)==13){
134  FINDRECOPART(L1MuonParticle, Muons, Muons)
135 
136  _Hists.Fill(L1ValidatorHists::Type::Muon, GenPart, RecoPart);
137  }else if(status==3 && abs(pdg)==15){
138  FINDRECOPART(L1JetParticle, Taus, Taus)
139 
140  _Hists.Fill(L1ValidatorHists::Type::TauJet, GenPart, RecoPart);
141  }else if(status==3 && (abs(pdg)<=5 || pdg==21)){
142  FINDRECOPART(L1JetParticle, CenJets, ForJets)
143 
144  if(RecoPart==NULL){
147  }else if(RecoPart->type() == L1JetParticle::JetType::kCentral){
148  _Hists.Fill(L1ValidatorHists::Type::CenJet, GenPart, RecoPart);
150  }else if(RecoPart->type() == L1JetParticle::JetType::kForward){
152  _Hists.Fill(L1ValidatorHists::Type::ForJet, GenPart, RecoPart);
153  }
154  }else continue;
155 
156  //cout << GenPart->pt() << '\t' << GenPart->eta() << '\t' << GenPart->phi() << '\t' << GenPart->pdgId() << endl;
157  }
158 }
159 
160 //The next three are exactly the same, but apparently inheritance doesn't work like I thought it did.
161 const reco::LeafCandidate *L1Validator::FindBest(const reco::GenParticle *GenPart, const std::vector<l1extra::L1EmParticle> *Collection1, const std::vector<l1extra::L1EmParticle> *Collection2=NULL){
162  const reco::LeafCandidate *BestPart=NULL;
163  double BestDR=999.;
164 
165  for(uint i=0; i < Collection1->size(); i++){
166  const reco::LeafCandidate *ThisPart = &Collection1->at(i);
167  double ThisDR = reco::deltaR(GenPart->eta(), GenPart->phi(), ThisPart->eta(), ThisPart->phi());
168  if(ThisDR < BestDR){
169  BestDR = ThisDR;
170  BestPart = ThisPart;
171  }
172  }
173 
174  if(Collection2==NULL) return BestPart;
175 
176  for(uint i=0; i < Collection2->size(); i++){
177  const reco::LeafCandidate *ThisPart = &Collection2->at(i);
178  double ThisDR = reco::deltaR(GenPart->eta(), GenPart->phi(), ThisPart->eta(), ThisPart->phi());
179  if(ThisDR < BestDR){
180  BestDR = ThisDR;
181  BestPart = ThisPart;
182  }
183  }
184 
185  return BestPart;
186 }
187 
188 const reco::LeafCandidate *L1Validator::FindBest(const reco::GenParticle *GenPart, const std::vector<l1extra::L1JetParticle> *Collection1, const std::vector<l1extra::L1JetParticle> *Collection2=NULL){
189  const reco::LeafCandidate *BestPart=NULL;
190  double BestDR=999.;
191 
192  for(uint i=0; i < Collection1->size(); i++){
193  const reco::LeafCandidate *ThisPart = &Collection1->at(i);
194  double ThisDR = reco::deltaR(GenPart->eta(), GenPart->phi(), ThisPart->eta(), ThisPart->phi());
195  if(ThisDR < BestDR){
196  BestDR = ThisDR;
197  BestPart = ThisPart;
198  }
199  }
200 
201  if(Collection2==NULL) return BestPart;
202 
203  for(uint i=0; i < Collection2->size(); i++){
204  const reco::LeafCandidate *ThisPart = &Collection2->at(i);
205  double ThisDR = reco::deltaR(GenPart->eta(), GenPart->phi(), ThisPart->eta(), ThisPart->phi());
206  if(ThisDR < BestDR){
207  BestDR = ThisDR;
208  BestPart = ThisPart;
209  }
210  }
211 
212  return BestPart;
213 }
214 
215 const reco::LeafCandidate *L1Validator::FindBest(const reco::GenParticle *GenPart, const std::vector<l1extra::L1MuonParticle> *Collection1){
216  const reco::LeafCandidate *BestPart=NULL;
217  double BestDR=999.;
218 
219  for(uint i=0; i < Collection1->size(); i++){
220  const reco::LeafCandidate *ThisPart = &Collection1->at(i);
221  double ThisDR = reco::deltaR(GenPart->eta(), GenPart->phi(), ThisPart->eta(), ThisPart->phi());
222  if(ThisDR < BestDR){
223  BestDR = ThisDR;
224  BestPart = ThisPart;
225  }
226  }
227 
228  return BestPart;
229 }
230 
231 
232 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
234  //The following says we do not know what parameters are allowed so do no validation
235  // Please change this to state exactly what you do use, even if it is no parameters
237  desc.setUnknown();
238  descriptions.addDefault(desc);
239 }
240 
241 //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
virtual int pdgId() const
PDG identifier.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual int status() const
status word
edm::EDGetTokenT< reco::GenParticleCollection > _GenSource
Definition: L1Validator.h:76
virtual float phi() const
momentum azimuthal angle
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: L1Validator.cc:233
#define NULL
Definition: scimark2.h:8
double deltaR(const T1 &t1, const T2 &t2)
Definition: deltaR.h:48
L1Validator(const edm::ParameterSet &)
Definition: L1Validator.cc:54
void FillNumber(int, int)
edm::EDGetTokenT< l1extra::L1JetParticleCollection > _L1ExtraForJetSource
Definition: L1Validator.h:80
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
virtual float eta() const
momentum pseudorapidity
std::string _dirName
Definition: L1Validator.h:73
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define FINDRECOPART(TYPE, COLLECTION1, COLLECTION2)
Definition: L1Validator.cc:32
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: L1Validator.cc:78
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: L1Validator.cc:73
edm::EDGetTokenT< l1extra::L1JetParticleCollection > _L1ExtraTauJetSource
Definition: L1Validator.h:81
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:274
edm::EDGetTokenT< l1extra::L1MuonParticleCollection > _L1ExtraMuonSource
Definition: L1Validator.h:82
L1ValidatorHists _Hists
Definition: L1Validator.h:85
edm::EDGetTokenT< l1extra::L1EmParticleCollection > _L1ExtraIsoEGSource
Definition: L1Validator.h:77
const reco::LeafCandidate * FindBest(const reco::GenParticle *, const std::vector< l1extra::L1EmParticle > *, const std::vector< l1extra::L1EmParticle > *)
Definition: L1Validator.cc:161
edm::EDGetTokenT< l1extra::L1EmParticleCollection > _L1ExtraNonIsoEGSource
Definition: L1Validator.h:78
edm::EDGetTokenT< l1extra::L1JetParticleCollection > _L1ExtraCenJetSource
Definition: L1Validator.h:79
void Book(DQMStore::IBooker &)
tuple status
Definition: ntuplemaker.py:245
Definition: Run.h:41