CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
ResolutionCreator Class Reference
Inheritance diagram for ResolutionCreator:
edm::EDAnalyzer edm::EDConsumerBase

Public Member Functions

 ResolutionCreator (const edm::ParameterSet &)
 
 ~ResolutionCreator () override
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
SerialTaskQueueglobalLuminosityBlocksQueue ()
 
SerialTaskQueueglobalRunsQueue ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
 ~EDAnalyzer () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

void analyze (const edm::Event &, const edm::EventSetup &) override
 
void beginJob () override
 
void endJob () override
 

Private Attributes

edm::EDGetTokenT< std::vector< pat::Electron > > electronsToken_
 
std::vector< double > etabinVals_
 
int etanrbins
 
TF1 * fResEtaBin [10][20]
 
TF1 * fResPtEtaBin [10][20][20]
 
edm::EDGetTokenT< TtGenEventgenEvtToken_
 
TH1F * hResEtaBin [10][20]
 
TH1F * hResPtEtaBin [10][20][20]
 
edm::EDGetTokenT< std::vector< pat::Jet > > jetsToken_
 
std::string labelName_
 
int matchingAlgo_
 
double maxDist_
 
edm::EDGetTokenT< std::vector< pat::MET > > metsToken_
 
double minDR_
 
edm::EDGetTokenT< std::vector< pat::Muon > > muonsToken_
 
int nrFilled
 
std::string objectType_
 
std::vector< double > pTbinVals_
 
int ptnrbins
 
edm::EDGetTokenT< std::vector< pat::Tau > > tausToken_
 
TTree * tResVar
 
bool useDeltaR_
 
bool useMaxDist_
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
static bool wantsGlobalLuminosityBlocks ()
 
static bool wantsGlobalRuns ()
 
static bool wantsStreamLuminosityBlocks ()
 
static bool wantsStreamRuns ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Definition at line 38 of file ResolutionCreator.cc.

Constructor & Destructor Documentation

ResolutionCreator::ResolutionCreator ( const edm::ParameterSet iConfig)
explicit

Definition at line 76 of file ResolutionCreator.cc.

References electronsToken_, etabinVals_, genEvtToken_, edm::ParameterSet::getParameter(), HLT_2018_cff::InputTag, jetsToken_, labelName_, metsToken_, minDR_, muonsToken_, nrFilled, objectType_, pTbinVals_, AlCaHLTBitMon_QueryRunRegistry::string, and tausToken_.

76  {
77  // input parameters
78  genEvtToken_ = consumes<TtGenEvent>(edm::InputTag("genEvt"));
79  objectType_ = iConfig.getParameter<std::string>("object");
80  labelName_ = iConfig.getParameter<std::string>("label");
81  if (objectType_ == "electron")
82  electronsToken_ = consumes<std::vector<pat::Electron> >(edm::InputTag(labelName_));
83  else if (objectType_ == "muon")
84  muonsToken_ = consumes<std::vector<pat::Muon> >(edm::InputTag(labelName_));
85  else if (objectType_ == "lJets" || objectType_ == "bJets")
86  jetsToken_ = consumes<std::vector<pat::Jet> >(edm::InputTag(labelName_));
87  else if (objectType_ == "met")
88  metsToken_ = consumes<std::vector<pat::MET> >(edm::InputTag(labelName_));
89  else if (objectType_ == "tau")
90  tausToken_ = consumes<std::vector<pat::Tau> >(edm::InputTag(labelName_));
91  if (objectType_ != "met") {
92  etabinVals_ = iConfig.getParameter<std::vector<double> >("etabinValues");
93  }
94  pTbinVals_ = iConfig.getParameter<std::vector<double> >("pTbinValues");
95  minDR_ = iConfig.getParameter<double>("minMatchingDR");
96 
97  nrFilled = 0;
98 }
T getParameter(std::string const &) const
edm::EDGetTokenT< TtGenEvent > genEvtToken_
edm::EDGetTokenT< std::vector< pat::Jet > > jetsToken_
edm::EDGetTokenT< std::vector< pat::Tau > > tausToken_
std::vector< double > etabinVals_
edm::EDGetTokenT< std::vector< pat::Electron > > electronsToken_
edm::EDGetTokenT< std::vector< pat::MET > > metsToken_
std::vector< double > pTbinVals_
edm::EDGetTokenT< std::vector< pat::Muon > > muonsToken_
ResolutionCreator::~ResolutionCreator ( )
override

Definition at line 100 of file ResolutionCreator.cc.

100 {}

Member Function Documentation

void ResolutionCreator::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 107 of file ResolutionCreator.cc.

References funct::abs(), b, bgen, electronAnalyzer_cfi::DeltaR, MillePedeFileConverter_cfg::e, pwdgSkimBPark_cfi::electrons, electronsToken_, reco::LeafCandidate::energy(), etabinVals_, etanrbins, TtGenEvtProducer_cfi::genEvt, genEvtToken_, edm::Event::getByToken(), hResPtEtaBin, TtGenEvent::isSemiLeptonic(), dqmiolumiharvest::j, singleTopDQM_cfi::jets, jetsToken_, visualization-live-secondInstance_cfg::m, singleTopDQM_cfi::mets, metsToken_, minDR_, reco::CompositeRefCandidateT< D >::mother(), reco::Candidate::mother(), PDWG_BPHSkim_cff::muons, muonsToken_, nrFilled, reco::CompositeRefCandidateT< D >::numberOfMothers(), reco::Candidate::numberOfMothers(), objectType_, AlCaHLTBitMon_ParallelJobs::p, reco::LeafCandidate::p4(), TopGenEvent::particles(), reco::Candidate::pdgId(), reco::LeafCandidate::pdgId(), hitfit::phidiff(), DiDispStaMuonMonitor_cfi::pt, pTbinVals_, multPhiCorr_741_25nsDY_cfi::px, multPhiCorr_741_25nsDY_cfi::py, TtGenEvent::singleNeutrino(), reco::LeafCandidate::status(), metsig::tau, Tau3MuMonitor_cff::taus, and tausToken_.

107  {
108  // Get the gen and cal object fourvector
109  std::vector<reco::Particle *> p4gen, p4rec;
110 
112  iEvent.getByToken(genEvtToken_, genEvt);
113 
114  if (genEvt->particles().size() < 10)
115  return;
116 
117  if (objectType_ == "electron") {
119  electrons; //to calculate the ResolutionCreator for the electrons, i used the TopElectron instead of the AOD information
120  iEvent.getByToken(electronsToken_, electrons);
121  for (size_t e = 0; e < electrons->size(); e++) {
122  for (size_t p = 0; p < genEvt->particles().size(); p++) {
123  if ((std::abs(genEvt->particles()[p].pdgId()) == 11) &&
124  (ROOT::Math::VectorUtil::DeltaR(genEvt->particles()[p].p4(), (*electrons)[e].p4()) < minDR_)) {
125  //p4gen.push_back(new reco::Particle(genEvt->particles()[p]));
126  //p4rec.push_back(new reco::Particle((pat::Electron)((*electrons)[e])));
127  }
128  }
129  }
130  } else if (objectType_ == "muon") {
132  iEvent.getByToken(muonsToken_, muons);
133  for (size_t m = 0; m < muons->size(); m++) {
134  for (size_t p = 0; p < genEvt->particles().size(); p++) {
135  if ((std::abs(genEvt->particles()[p].pdgId()) == 13) &&
136  (ROOT::Math::VectorUtil::DeltaR(genEvt->particles()[p].p4(), (*muons)[m].p4()) < minDR_)) {
137  //p4gen.push_back(new reco::Particle(genEvt->particles()[p]));
138  //p4rec.push_back(new reco::Particle((pat::Muon)((*muons)[m])));
139  }
140  }
141  }
142  } else if (objectType_ == "lJets") {
144  iEvent.getByToken(jetsToken_, jets);
145  if (jets->size() >= 4) {
146  for (unsigned int j = 0; j < 4; j++) {
147  for (size_t p = 0; p < genEvt->particles().size(); p++) {
148  if ((std::abs(genEvt->particles()[p].pdgId()) < 5) &&
149  (ROOT::Math::VectorUtil::DeltaR(genEvt->particles()[p].p4(), (*jets)[j].p4()) < minDR_)) {
150  //p4gen.push_back(new reco::Particle(genEvt->particles()[p]));
151  //p4rec.push_back(new reco::Particle((pat::Jet)(*jets)[j]));
152  }
153  }
154  }
155  }
156  } else if (objectType_ == "bJets") {
158  iEvent.getByToken(jetsToken_, jets);
159  if (jets->size() >= 4) {
160  for (unsigned int j = 0; j < 4; j++) {
161  for (size_t p = 0; p < genEvt->particles().size(); p++) {
162  if ((std::abs(genEvt->particles()[p].pdgId()) == 5) &&
163  (ROOT::Math::VectorUtil::DeltaR(genEvt->particles()[p].p4(), (*jets)[j].p4()) < minDR_)) {
164  //p4gen.push_back(new reco::Particle(genEvt->particles()[p]));
165  //p4rec.push_back(new reco::Particle((pat::Jet)(*jets)[j]));
166  }
167  }
168  }
169  }
170  } else if (objectType_ == "met") {
172  iEvent.getByToken(metsToken_, mets);
173  if (!mets->empty()) {
174  if (genEvt->isSemiLeptonic() && genEvt->singleNeutrino() != nullptr &&
175  ROOT::Math::VectorUtil::DeltaR(genEvt->singleNeutrino()->p4(), (*mets)[0].p4()) < minDR_) {
176  //p4gen.push_back(new reco::Particle(0,genEvt->singleNeutrino()->p4(),math::XYZPoint()));
177  //p4rec.push_back(new reco::Particle((pat::MET)((*mets)[0])));
178  }
179  }
180  } else if (objectType_ == "tau") {
182  iEvent.getByToken(tausToken_, taus);
183  for (std::vector<pat::Tau>::const_iterator tau = taus->begin(); tau != taus->end(); ++tau) {
184  // find the tau (if any) that matches a MC tau from W
185  reco::GenParticle genLepton = *(tau->genLepton());
186  if (std::abs(genLepton.pdgId()) == 15 && genLepton.status() == 2 && genLepton.numberOfMothers() > 0 &&
187  std::abs(genLepton.mother(0)->pdgId()) == 15 && genLepton.mother(0)->numberOfMothers() > 0 &&
188  std::abs(genLepton.mother(0)->mother(0)->pdgId()) == 24 &&
189  ROOT::Math::VectorUtil::DeltaR(genLepton.p4(), tau->p4()) < minDR_) {
190  }
191  //p4gen.push_back(new reco::Particle(genLepton));
192  //p4rec.push_back(new reco::Particle(*tau));
193  }
194  }
195  // Fill the object's value
196  for (unsigned m = 0; m < p4gen.size(); m++) {
197  double Egen = p4gen[m]->energy();
198  double Thetagen = p4gen[m]->theta();
199  double Phigen = p4gen[m]->phi();
200  double Etgen = p4gen[m]->et();
201  double Etagen = p4gen[m]->eta();
202  double Ecal = p4rec[m]->energy();
203  double Thetacal = p4rec[m]->theta();
204  double Phical = p4rec[m]->phi();
205  double Etcal = p4rec[m]->et();
206  double Etacal = p4rec[m]->eta();
207  double phidiff = Phical - Phigen;
208  if (phidiff > 3.14159)
209  phidiff = 2. * 3.14159 - phidiff;
210  if (phidiff < -3.14159)
211  phidiff = -phidiff - 2. * 3.14159;
212 
213  // find eta and et bin
214  int etabin = 0;
215  if (etanrbins > 1) {
216  for (unsigned int b = 0; b < etabinVals_.size() - 1; b++) {
217  if (fabs(Etacal) > etabinVals_[b])
218  etabin = b;
219  }
220  }
221 
222  int ptbin = 0;
223  for (unsigned int b = 0; b < pTbinVals_.size() - 1; b++) {
224  if (p4rec[m]->pt() > pTbinVals_[b])
225  ptbin = b;
226  }
227 
228  // calculate the resolution on "a", "b", "c" & "d" according to the definition (CMS-NOTE-2006-023):
229  // p = a*|p_meas|*u_1 + b*u_2 + c*u_3
230  // E(fit) = E_meas * d
231  //
232  // with u_1 = p/|p_meas|
233  // u_3 = (u_z x u_1)/|u_z x u_1|
234  // u_2 = (u_1 x u_3)/|u_1 x u_3|
235  //
236  // The initial parameters values are chosen like (a, b, c, d) = (1., 0., 0., 1.)
237 
238  // 1/ calculate the unitary vectors of the basis u_1, u_2, u_3
239  ROOT::Math::SVector<double, 3> pcalvec(p4rec[m]->px(), p4rec[m]->py(), p4rec[m]->pz());
240  ROOT::Math::SVector<double, 3> pgenvec(p4gen[m]->px(), p4gen[m]->py(), p4gen[m]->pz());
241 
242  ROOT::Math::SVector<double, 3> u_z(0, 0, 1);
243  ROOT::Math::SVector<double, 3> u_1 = ROOT::Math::Unit(pcalvec);
244  ROOT::Math::SVector<double, 3> u_3 = ROOT::Math::Cross(u_z, u_1) / ROOT::Math::Mag(ROOT::Math::Cross(u_z, u_1));
245  ROOT::Math::SVector<double, 3> u_2 = ROOT::Math::Cross(u_1, u_3) / ROOT::Math::Mag(ROOT::Math::Cross(u_1, u_3));
246  double acal = 1.;
247  double bcal = 0.;
248  double ccal = 0.;
249  double dcal = 1.;
250  double agen = ROOT::Math::Dot(pgenvec, u_1) / ROOT::Math::Mag(pcalvec);
251  double bgen = ROOT::Math::Dot(pgenvec, u_2);
252  double cgen = ROOT::Math::Dot(pgenvec, u_3);
253  double dgen = Egen / Ecal;
254 
255  //fill histograms
256  ++nrFilled;
257  hResPtEtaBin[0][etabin][ptbin]->Fill(acal - agen);
258  hResPtEtaBin[1][etabin][ptbin]->Fill(bcal - bgen);
259  hResPtEtaBin[2][etabin][ptbin]->Fill(ccal - cgen);
260  hResPtEtaBin[3][etabin][ptbin]->Fill(dcal - dgen);
261  hResPtEtaBin[4][etabin][ptbin]->Fill(Thetacal - Thetagen);
262  hResPtEtaBin[5][etabin][ptbin]->Fill(phidiff);
263  hResPtEtaBin[6][etabin][ptbin]->Fill(Etcal - Etgen);
264  hResPtEtaBin[7][etabin][ptbin]->Fill(Etacal - Etagen);
265 
266  delete p4gen[m];
267  delete p4rec[m];
268  }
269 }
int pdgId() const final
PDG identifier.
bool isSemiLeptonic(bool excludeTauLeptons=false) const
check if the event can be classified as semi-laptonic
Definition: TtGenEvent.h:38
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
size_t numberOfMothers() const override
number of mothers
virtual const Candidate * mother(size_type i=0) const =0
return pointer to mother
double phidiff(double phi)
Normalized difference in azimuthal angles to a range between .
Definition: fourvec.cc:220
edm::EDGetTokenT< TtGenEvent > genEvtToken_
double bgen
Definition: HydjetWrapper.h:44
edm::EDGetTokenT< std::vector< pat::Jet > > jetsToken_
edm::EDGetTokenT< std::vector< pat::Tau > > tausToken_
std::vector< double > etabinVals_
virtual int pdgId() const =0
PDG identifier.
virtual size_type numberOfMothers() const =0
number of mothers (zero or one in most of but not all the cases)
double energy() const final
energy
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const LorentzVector & p4() const final
four-momentum Lorentz vector
const reco::GenParticle * singleNeutrino(bool excludeTauLeptons=false) const
return single neutrino if available; 0 else
Definition: TtGenEvent.cc:139
TH1F * hResPtEtaBin[10][20][20]
edm::EDGetTokenT< std::vector< pat::Electron > > electronsToken_
double b
Definition: hdecay.h:118
const reco::GenParticleCollection & particles() const
return particles of decay chain
Definition: TopGenEvent.h:50
edm::EDGetTokenT< std::vector< pat::MET > > metsToken_
int status() const final
status word
std::vector< double > pTbinVals_
edm::EDGetTokenT< std::vector< pat::Muon > > muonsToken_
const Candidate * mother(size_type=0) const override
return mother at a given position, i = 0, ... numberOfMothers() - 1 (read only mode) ...
void ResolutionCreator::beginJob ( void  )
overrideprivatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 272 of file ResolutionCreator.cc.

References b, edm::errors::Configuration, defaults_cfi::etabins, etabinVals_, etanrbins, Exception, fResEtaBin, fResPtEtaBin, hResEtaBin, hResPtEtaBin, TFileService::make(), objectType_, LepHTMonitor_cff::ptbins, pTbinVals_, ptnrbins, and tResVar.

272  {
274  if (!fs)
275  throw edm::Exception(edm::errors::Configuration, "TFileService missing from configuration!");
276 
277  // input constants
278  TString resObsName[8] = {"_ares", "_bres", "_cres", "_dres", "_thres", "_phres", "_etres", "_etares"};
279  int resObsNrBins = 120;
280  if ((objectType_ == "muon") || (objectType_ == "electron"))
281  resObsNrBins = 80;
282  std::vector<double> resObsMin, resObsMax;
283  if (objectType_ == "electron") {
284  resObsMin.push_back(-0.15);
285  resObsMin.push_back(-0.2);
286  resObsMin.push_back(-0.1);
287  resObsMin.push_back(-0.15);
288  resObsMin.push_back(-0.0012);
289  resObsMin.push_back(-0.009);
290  resObsMin.push_back(-16);
291  resObsMin.push_back(-0.0012);
292  resObsMax.push_back(0.15);
293  resObsMax.push_back(0.2);
294  resObsMax.push_back(0.1);
295  resObsMax.push_back(0.15);
296  resObsMax.push_back(0.0012);
297  resObsMax.push_back(0.009);
298  resObsMax.push_back(16);
299  resObsMax.push_back(0.0012);
300  } else if (objectType_ == "muon") {
301  resObsMin.push_back(-0.15);
302  resObsMin.push_back(-0.1);
303  resObsMin.push_back(-0.05);
304  resObsMin.push_back(-0.15);
305  resObsMin.push_back(-0.004);
306  resObsMin.push_back(-0.003);
307  resObsMin.push_back(-8);
308  resObsMin.push_back(-0.004);
309  resObsMax.push_back(0.15);
310  resObsMax.push_back(0.1);
311  resObsMax.push_back(0.05);
312  resObsMax.push_back(0.15);
313  resObsMax.push_back(0.004);
314  resObsMax.push_back(0.003);
315  resObsMax.push_back(8);
316  resObsMax.push_back(0.004);
317  } else if (objectType_ == "tau") {
318  resObsMin.push_back(-1.);
319  resObsMin.push_back(-10.);
320  resObsMin.push_back(-10);
321  resObsMin.push_back(-1.);
322  resObsMin.push_back(-0.1);
323  resObsMin.push_back(-0.1);
324  resObsMin.push_back(-80);
325  resObsMin.push_back(-0.1);
326  resObsMax.push_back(1.);
327  resObsMax.push_back(10.);
328  resObsMax.push_back(10);
329  resObsMax.push_back(1.);
330  resObsMax.push_back(0.1);
331  resObsMax.push_back(0.1);
332  resObsMax.push_back(50);
333  resObsMax.push_back(0.1);
334  } else if (objectType_ == "lJets" || objectType_ == "bJets") {
335  resObsMin.push_back(-1.);
336  resObsMin.push_back(-10.);
337  resObsMin.push_back(-10.);
338  resObsMin.push_back(-1.);
339  resObsMin.push_back(-0.4);
340  resObsMin.push_back(-0.6);
341  resObsMin.push_back(-80);
342  resObsMin.push_back(-0.6);
343  resObsMax.push_back(1.);
344  resObsMax.push_back(10.);
345  resObsMax.push_back(10.);
346  resObsMax.push_back(1.);
347  resObsMax.push_back(0.4);
348  resObsMax.push_back(0.6);
349  resObsMax.push_back(80);
350  resObsMax.push_back(0.6);
351  } else {
352  resObsMin.push_back(-2.);
353  resObsMin.push_back(-150.);
354  resObsMin.push_back(-150.);
355  resObsMin.push_back(-2.);
356  resObsMin.push_back(-6);
357  resObsMin.push_back(-6);
358  resObsMin.push_back(-180);
359  resObsMin.push_back(-6);
360  resObsMax.push_back(3.);
361  resObsMax.push_back(150.);
362  resObsMax.push_back(150.);
363  resObsMax.push_back(3.);
364  resObsMax.push_back(6);
365  resObsMax.push_back(6);
366  resObsMax.push_back(180);
367  resObsMax.push_back(6);
368  }
369 
370  const char *resObsVsPtFit[8] = {"[0]+[1]*exp(-[2]*x)",
371  "[0]+[1]*exp(-[2]*x)",
372  "[0]+[1]*exp(-[2]*x)",
373  "[0]+[1]*exp(-[2]*x)",
374  "[0]+[1]*exp(-[2]*x)",
375  "[0]+[1]*exp(-[2]*x)",
376  "pol1",
377  "[0]+[1]*exp(-[2]*x)"};
378 
379  ptnrbins = pTbinVals_.size() - 1;
380  double *ptbins = new double[pTbinVals_.size()];
381  for (unsigned int b = 0; b < pTbinVals_.size(); b++)
382  ptbins[b] = pTbinVals_[b];
383  double *etabins;
384  if (objectType_ != "met") {
385  etanrbins = etabinVals_.size() - 1;
386  etabins = new double[etabinVals_.size()];
387  for (unsigned int b = 0; b < etabinVals_.size(); b++)
388  etabins[b] = etabinVals_[b];
389  } else {
390  etanrbins = 1;
391  etabins = new double[2];
392  etabins[0] = 0;
393  etabins[1] = 5.;
394  }
395 
396  //define the histograms booked
397  for (Int_t ro = 0; ro < 8; ro++) {
398  for (Int_t etab = 0; etab < etanrbins; etab++) {
399  for (Int_t ptb = 0; ptb < ptnrbins; ptb++) {
400  TString obsName = objectType_;
401  obsName += resObsName[ro];
402  obsName += "_etabin";
403  obsName += etab;
404  obsName += "_ptbin";
405  obsName += ptb;
406  hResPtEtaBin[ro][etab][ptb] = fs->make<TH1F>(obsName, obsName, resObsNrBins, resObsMin[ro], resObsMax[ro]);
407  fResPtEtaBin[ro][etab][ptb] = fs->make<TF1>("F_" + obsName, "gaus");
408  }
409  TString obsName2 = objectType_;
410  obsName2 += resObsName[ro];
411  obsName2 += "_etabin";
412  obsName2 += etab;
413  hResEtaBin[ro][etab] = fs->make<TH1F>(obsName2, obsName2, ptnrbins, ptbins);
414  fResEtaBin[ro][etab] =
415  fs->make<TF1>("F_" + obsName2, resObsVsPtFit[ro], pTbinVals_[0], pTbinVals_[pTbinVals_.size() - 1]);
416  }
417  }
418  tResVar = fs->make<TTree>("tResVar", "Resolution tree");
419 
420  delete[] etabins;
421  delete[] ptbins;
422 }
TF1 * fResEtaBin[10][20]
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
std::vector< double > etabinVals_
TH1F * hResEtaBin[10][20]
TF1 * fResPtEtaBin[10][20][20]
TH1F * hResPtEtaBin[10][20][20]
double b
Definition: hdecay.h:118
std::vector< double > pTbinVals_
void ResolutionCreator::endJob ( void  )
overrideprivatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 425 of file ResolutionCreator.cc.

References DEFINE_FWK_MODULE, relativeConstraints::error, PVValHelper::eta, etabinVals_, etanrbins, fResEtaBin, fResPtEtaBin, hResEtaBin, hResPtEtaBin, createfilelist::int, nrFilled, objectType_, DiDispStaMuonMonitor_cfi::pt, pTbinVals_, ptnrbins, FastTimerService_cff::range, tResVar, and relativeConstraints::value.

425  {
426  TString resObsName2[8] = {"a", "b", "c", "d", "theta", "phi", "et", "eta"};
427  Int_t ro = 0;
428  Double_t pt = 0.;
429  Double_t eta = 0.;
430  Double_t value, error;
431 
432  tResVar->Branch("Pt", &pt, "Pt/D");
433  tResVar->Branch("Eta", &eta, "Eta/D");
434  tResVar->Branch("ro", &ro, "ro/I");
435  tResVar->Branch("value", &value, "value/D");
436  tResVar->Branch("error", &error, "error/D");
437 
438  for (ro = 0; ro < 8; ro++) {
439  for (int etab = 0; etab < etanrbins; etab++) {
440  //CD set eta at the center of the bin
441  eta = etanrbins > 1 ? (etabinVals_[etab] + etabinVals_[etab + 1]) / 2. : 2.5;
442  for (int ptb = 0; ptb < ptnrbins; ptb++) {
443  //CD set pt at the center of the bin
444  pt = (pTbinVals_[ptb] + pTbinVals_[ptb + 1]) / 2.;
445  double maxcontent = 0.;
446  int maxbin = 0;
447  for (int nb = 1; nb < hResPtEtaBin[ro][etab][ptb]->GetNbinsX(); nb++) {
448  if (hResPtEtaBin[ro][etab][ptb]->GetBinContent(nb) > maxcontent) {
449  maxcontent = hResPtEtaBin[ro][etab][ptb]->GetBinContent(nb);
450  maxbin = nb;
451  }
452  }
453  int range = (int)(hResPtEtaBin[ro][etab][ptb]->GetNbinsX() / 6); //in order that ~1/3 of X-axis range is fitted
454  fResPtEtaBin[ro][etab][ptb]->SetRange(hResPtEtaBin[ro][etab][ptb]->GetBinCenter(maxbin - range),
455  hResPtEtaBin[ro][etab][ptb]->GetBinCenter(maxbin + range));
456  fResPtEtaBin[ro][etab][ptb]->SetParameters(hResPtEtaBin[ro][etab][ptb]->GetMaximum(),
457  hResPtEtaBin[ro][etab][ptb]->GetMean(),
458  hResPtEtaBin[ro][etab][ptb]->GetRMS());
459  hResPtEtaBin[ro][etab][ptb]->Fit(fResPtEtaBin[ro][etab][ptb]->GetName(), "RQ");
460  hResEtaBin[ro][etab]->SetBinContent(ptb + 1, fResPtEtaBin[ro][etab][ptb]->GetParameter(2));
461  hResEtaBin[ro][etab]->SetBinError(ptb + 1, fResPtEtaBin[ro][etab][ptb]->GetParError(2));
462  //CD: Fill the tree
463  value = fResPtEtaBin[ro][etab][ptb]->GetParameter(2); //parameter value
464  error = fResPtEtaBin[ro][etab][ptb]->GetParError(2); //parameter error
465  tResVar->Fill();
466  }
467  //CD: add a fake entry in pt=0 for the NN training
468  // for that, use a linear extrapolation.
469  pt = 0.;
470  value = ((pTbinVals_[0] + pTbinVals_[1]) / 2.) *
471  (fResPtEtaBin[ro][etab][0]->GetParameter(2) - fResPtEtaBin[ro][etab][1]->GetParameter(2)) /
472  ((pTbinVals_[2] - pTbinVals_[0]) / 2.) +
473  fResPtEtaBin[ro][etab][0]->GetParameter(2);
474  error = fResPtEtaBin[ro][etab][0]->GetParError(2) + fResPtEtaBin[ro][etab][1]->GetParError(2);
475  tResVar->Fill();
476  // standard fit
477  hResEtaBin[ro][etab]->Fit(fResEtaBin[ro][etab]->GetName(), "RQ");
478  }
479  }
480  if (objectType_ == "lJets" && nrFilled == 0)
481  edm::LogProblem("SummaryError") << "No plots filled for light jets \n";
482  if (objectType_ == "bJets" && nrFilled == 0)
483  edm::LogProblem("SummaryError") << "No plots filled for bjets \n";
484  if (objectType_ == "muon" && nrFilled == 0)
485  edm::LogProblem("SummaryError") << "No plots filled for muons \n";
486  if (objectType_ == "electron" && nrFilled == 0)
487  edm::LogProblem("SummaryError") << "No plots filled for electrons \n";
488  if (objectType_ == "tau" && nrFilled == 0)
489  edm::LogProblem("SummaryError") << "No plots filled for taus \n";
490  if (objectType_ == "met" && nrFilled == 0)
491  edm::LogProblem("SummaryError") << "No plots filled for met \n";
492 
493  edm::LogVerbatim("MainResults") << " \n\n";
494  edm::LogVerbatim("MainResults") << " ----------------------------------------------";
495  edm::LogVerbatim("MainResults") << " ----------------------------------------------";
496  edm::LogVerbatim("MainResults") << " Resolutions on " << objectType_ << " with nrfilled: " << nrFilled;
497  edm::LogVerbatim("MainResults") << " ----------------------------------------------";
498  edm::LogVerbatim("MainResults") << " ----------------------------------------------";
499  if (nrFilled != 0 && objectType_ != "met") {
500  for (ro = 0; ro < 8; ro++) {
501  edm::LogVerbatim("MainResults") << "-------------------- ";
502  edm::LogVerbatim("MainResults") << "\n Resolutions on " << resObsName2[ro] << "\n";
503  edm::LogVerbatim("MainResults") << "-------------------- ";
504  for (int etab = 0; etab < etanrbins; etab++) {
505  if (nrFilled != 0 && ro != 6) {
506  if (etab == 0) {
507  edm::LogVerbatim("MainResults")
508  << "if(fabs(eta)<" << etabinVals_[etab + 1] << ") res = " << fResEtaBin[ro][etab]->GetParameter(0)
509  << "+" << fResEtaBin[ro][etab]->GetParameter(1) << "*exp(-(" << fResEtaBin[ro][etab]->GetParameter(2)
510  << "*pt));";
511  } else {
512  edm::LogVerbatim("MainResults")
513  << "else if(fabs(eta)<" << etabinVals_[etab + 1] << ") res = " << fResEtaBin[ro][etab]->GetParameter(0)
514  << "+" << fResEtaBin[ro][etab]->GetParameter(1) << "*exp(-(" << fResEtaBin[ro][etab]->GetParameter(2)
515  << "*pt));";
516  }
517  } else if (nrFilled != 0 && ro == 6) {
518  if (etab == 0) {
519  edm::LogVerbatim("MainResults")
520  << "if(fabs(eta)<" << etabinVals_[etab + 1] << ") res = " << fResEtaBin[ro][etab]->GetParameter(0)
521  << "+" << fResEtaBin[ro][etab]->GetParameter(1) << "*pt;";
522  } else {
523  edm::LogVerbatim("MainResults")
524  << "else if(fabs(eta)<" << etabinVals_[etab + 1] << ") res = " << fResEtaBin[ro][etab]->GetParameter(0)
525  << "+" << fResEtaBin[ro][etab]->GetParameter(1) << "*pt;";
526  }
527  }
528  }
529  }
530  } else if (nrFilled != 0 && objectType_ == "met") {
531  for (ro = 0; ro < 8; ro++) {
532  edm::LogVerbatim("MainResults") << "-------------------- ";
533  edm::LogVerbatim("MainResults") << "\n Resolutions on " << resObsName2[ro] << "\n";
534  edm::LogVerbatim("MainResults") << "-------------------- ";
535  if (nrFilled != 0 && ro != 6) {
536  edm::LogVerbatim("MainResults") << "res = " << fResEtaBin[ro][0]->GetParameter(0) << "+"
537  << fResEtaBin[ro][0]->GetParameter(1) << "*exp(-("
538  << fResEtaBin[ro][0]->GetParameter(2) << "*pt));";
539  } else if (nrFilled != 0 && ro == 6) {
540  edm::LogVerbatim("MainResults") << "res = " << fResEtaBin[ro][0]->GetParameter(0) << "+"
541  << fResEtaBin[ro][0]->GetParameter(1) << "*pt;";
542  }
543  }
544  }
545 }
TF1 * fResEtaBin[10][20]
std::vector< double > etabinVals_
TH1F * hResEtaBin[10][20]
TF1 * fResPtEtaBin[10][20][20]
TH1F * hResPtEtaBin[10][20][20]
std::vector< double > pTbinVals_

Member Data Documentation

edm::EDGetTokenT<std::vector<pat::Electron> > ResolutionCreator::electronsToken_
private

Definition at line 51 of file ResolutionCreator.cc.

Referenced by analyze(), and ResolutionCreator().

std::vector<double> ResolutionCreator::etabinVals_
private

Definition at line 56 of file ResolutionCreator.cc.

Referenced by analyze(), beginJob(), endJob(), and ResolutionCreator().

int ResolutionCreator::etanrbins
private

Definition at line 62 of file ResolutionCreator.cc.

Referenced by analyze(), beginJob(), and endJob().

TF1* ResolutionCreator::fResEtaBin[10][20]
private

Definition at line 67 of file ResolutionCreator.cc.

Referenced by beginJob(), and endJob().

TF1* ResolutionCreator::fResPtEtaBin[10][20][20]
private

Definition at line 66 of file ResolutionCreator.cc.

Referenced by beginJob(), and endJob().

edm::EDGetTokenT<TtGenEvent> ResolutionCreator::genEvtToken_
private

Definition at line 49 of file ResolutionCreator.cc.

Referenced by analyze(), and ResolutionCreator().

TH1F* ResolutionCreator::hResEtaBin[10][20]
private

Definition at line 69 of file ResolutionCreator.cc.

Referenced by beginJob(), and endJob().

TH1F* ResolutionCreator::hResPtEtaBin[10][20][20]
private

Definition at line 68 of file ResolutionCreator.cc.

Referenced by analyze(), beginJob(), and endJob().

edm::EDGetTokenT<std::vector<pat::Jet> > ResolutionCreator::jetsToken_
private

Definition at line 53 of file ResolutionCreator.cc.

Referenced by analyze(), and ResolutionCreator().

std::string ResolutionCreator::labelName_
private

Definition at line 50 of file ResolutionCreator.cc.

Referenced by ResolutionCreator().

int ResolutionCreator::matchingAlgo_
private

Definition at line 58 of file ResolutionCreator.cc.

double ResolutionCreator::maxDist_
private

Definition at line 61 of file ResolutionCreator.cc.

edm::EDGetTokenT<std::vector<pat::MET> > ResolutionCreator::metsToken_
private

Definition at line 54 of file ResolutionCreator.cc.

Referenced by analyze(), and ResolutionCreator().

double ResolutionCreator::minDR_
private

Definition at line 57 of file ResolutionCreator.cc.

Referenced by analyze(), and ResolutionCreator().

edm::EDGetTokenT<std::vector<pat::Muon> > ResolutionCreator::muonsToken_
private

Definition at line 52 of file ResolutionCreator.cc.

Referenced by analyze(), and ResolutionCreator().

int ResolutionCreator::nrFilled
private

Definition at line 63 of file ResolutionCreator.cc.

Referenced by analyze(), endJob(), and ResolutionCreator().

std::string ResolutionCreator::objectType_
private

Definition at line 50 of file ResolutionCreator.cc.

Referenced by analyze(), beginJob(), endJob(), and ResolutionCreator().

std::vector<double> ResolutionCreator::pTbinVals_
private

Definition at line 56 of file ResolutionCreator.cc.

Referenced by analyze(), beginJob(), endJob(), and ResolutionCreator().

int ResolutionCreator::ptnrbins
private

Definition at line 62 of file ResolutionCreator.cc.

Referenced by beginJob(), and endJob().

edm::EDGetTokenT<std::vector<pat::Tau> > ResolutionCreator::tausToken_
private

Definition at line 55 of file ResolutionCreator.cc.

Referenced by analyze(), and ResolutionCreator().

TTree* ResolutionCreator::tResVar
private

Definition at line 70 of file ResolutionCreator.cc.

Referenced by beginJob(), and endJob().

bool ResolutionCreator::useDeltaR_
private

Definition at line 60 of file ResolutionCreator.cc.

bool ResolutionCreator::useMaxDist_
private

Definition at line 59 of file ResolutionCreator.cc.