23 #include <CLHEP/Vector/LorentzVector.h> 37 #include "HepMC/GenEvent.h" 38 #include "HepMC/GenParticle.h" 39 #include "HepPDT/ParticleDataTable.hh" 40 #include "HepPDT/TableBuilder.hh" 41 #include "HepPDT/defs.h" 68 std::vector<reco::LeafCandidate>
muons;
69 typename std::vector<T>::const_iterator
track;
76 <<
": initial value Pt = " <<
mu.Pt() << std::endl;
125 : theMuonLabel_(iConfig.getParameter<
edm::
InputTag>(
"MuonLabel")),
126 theMuonType_(iConfig.getParameter<
int>(
"MuonType")),
127 theRootFileName_(iConfig.getUntrackedParameter<
std::
string>(
"OutputFileName")),
128 theCovariancesRootFileName_(iConfig.getUntrackedParameter<
std::
string>(
"InputFileName")),
129 debug_(iConfig.getUntrackedParameter<
bool>(
"Debug")),
130 resonance_(iConfig.getParameter<
bool>(
"Resonance")),
131 readCovariances_(iConfig.getParameter<
bool>(
"ReadCovariances")),
132 treeFileName_(iConfig.getParameter<
std::
string>(
"InputTreeName")),
133 maxEvents_(iConfig.getParameter<
int>(
"MaxEvents")),
134 ptMax_(iConfig.getParameter<double>(
"PtMax")) {
139 int resolFitType = iConfig.
getParameter<
int>(
"ResolFitType");
177 typedef std::vector<std::pair<lorentzVector, lorentzVector> >
MuonPairVector;
181 std::vector<std::pair<unsigned int, unsigned long long> > evtRun;
183 MuonPairVector::iterator savedPair = savedPairVector.begin();
184 MuonPairVector::iterator genPair = genPairVector.begin();
185 std::cout <<
"Starting loop on " << savedPairVector.size() <<
" muons" << std::endl;
186 for (; savedPair != savedPairVector.end(); ++savedPair, ++genPair) {
203 mapHisto_[
"DeltaGenMotherMuons"]->Fill(genPair->first, genPair->second);
204 mapHisto_[
"GenMotherMuons"]->Fill(genPair->first);
205 mapHisto_[
"GenMotherMuons"]->Fill(genPair->second);
210 mapHisto_[
"PtResolutionGenVSMu"]->Fill(recMu1, (-genPair->first.Pt() + recMu1.Pt()) / genPair->first.Pt(), -1);
211 mapHisto_[
"ThetaResolutionGenVSMu"]->Fill(recMu1, (-genPair->first.Theta() + recMu1.Theta()), -1);
212 mapHisto_[
"CotgThetaResolutionGenVSMu"]->Fill(
214 (-
cos(genPair->first.Theta()) /
sin(genPair->first.Theta()) +
cos(recMu1.Theta()) /
sin(recMu1.Theta())),
216 mapHisto_[
"EtaResolutionGenVSMu"]->Fill(recMu1, (-genPair->first.Eta() + recMu1.Eta()), -1);
221 deltaPtOverPt_->Fill((recMu1.Pt() - genPair->first.Pt()) / genPair->first.Pt());
222 if (fabs(recMu1.Eta()) > 1 && fabs(recMu1.Eta()) < 1.2) {
229 recMu2, (-genPair->second.Pt() + recMu2.Pt()) / genPair->second.Pt(), +1);
230 mapHisto_[
"ThetaResolutionGenVSMu"]->Fill(recMu2, (-genPair->second.Theta() + recMu2.Theta()), +1);
231 mapHisto_[
"CotgThetaResolutionGenVSMu"]->Fill(
233 (-
cos(genPair->second.Theta()) /
sin(genPair->second.Theta()) +
cos(recMu2.Theta()) /
sin(recMu2.Theta())),
235 mapHisto_[
"EtaResolutionGenVSMu"]->Fill(recMu2, (-genPair->second.Eta() + recMu2.Eta()), +1);
240 deltaPtOverPt_->Fill((recMu2.Pt() - genPair->second.Pt()) / genPair->second.Pt());
241 if (fabs(recMu2.Eta()) > 1 && fabs(recMu2.Eta()) < 1.2) {
251 if (genPair->first != nullLorentzVector && genPair->second != nullLorentzVector &&
253 double recoMass = (recMu1 + recMu2).
mass();
254 double genMass = (genPair->first + genPair->second).
mass();
256 mapHisto_[
"MassResolution"]->Fill(recMu1, -1, genPair->first, recMu2, +1, genPair->second, recoMass, genMass);
260 mapHisto_[
"RecoResonance"]->Fill(recoResonance);
261 mapHisto_[
"DeltaRecoResonanceMuons"]->Fill(recMu1, recMu2);
262 mapHisto_[
"RecoResonanceMuons"]->Fill(recMu1);
263 mapHisto_[
"RecoResonanceMuons"]->Fill(recMu2);
268 double diffMass = recoMass - genMass;
270 double pt1 = recMu1.pt();
271 double eta1 = recMu1.eta();
272 double pt2 = recMu2.pt();
273 double eta2 = recMu2.eta();
275 if (diffMass == diffMass) {
279 std::cout <<
"Error, there is a nan: recoMass = " << recoMass <<
", genMass = " << genMass << std::endl;
294 mapHisto_[
"hFunctionResolCotgTheta"]->Fill(
306 mapHisto_[
"hFunctionResolCotgTheta"]->Fill(
318 double mass = (recMu1 + recMu2).
mass();
319 double pt1 = recMu1.Pt();
320 double phi1 = recMu1.Phi();
321 double eta1 = recMu1.Eta();
322 double theta1 = 2 * atan(
exp(-
eta1));
323 double pt2 = recMu2.Pt();
324 double phi2 = recMu2.Phi();
325 double eta2 = recMu2.Eta();
326 double theta2 = 2 * atan(
exp(-
eta2));
352 double dmdpt[2] = {dmdpt1 * recMu1.Pt(), dmdpt2 * recMu2.Pt()};
353 double dmdphi[2] = {dmdphi1, dmdphi2};
354 double dmdcotgth[2] = {dmdcotgth1, dmdcotgth2};
361 double fullMassRes = 0.;
362 double massRes1 = 0.;
363 double massRes2 = 0.;
364 double massRes3 = 0.;
365 double massRes4 = 0.;
366 double massRes5 = 0.;
367 double massRes6 = 0.;
368 double massResPtAndPt12 = 0.;
370 for (
int i = 0;
i < 2; ++
i) {
371 double ptVariance =
mapHisto_[
"ReadCovariances"]->Get(*(recMu[
i]),
"Pt");
372 double cotgThetaVariance =
mapHisto_[
"ReadCovariances"]->Get(*(recMu[
i]),
"CotgTheta");
373 double phiVariance =
mapHisto_[
"ReadCovariances"]->Get(*(recMu[
i]),
"Phi");
374 double pt_cotgTheta =
mapHisto_[
"ReadCovariances"]->Get(*(recMu[
i]),
"Pt-CotgTheta");
375 double pt_phi =
mapHisto_[
"ReadCovariances"]->Get(*(recMu[
i]),
"Pt-Phi");
376 double cotgTheta_phi =
mapHisto_[
"ReadCovariances"]->Get(*(recMu[
i]),
"CotgTheta-Phi");
378 double pt1_pt2 =
mapHisto_[
"ReadCovariances"]->Get(*(recMu[
i]),
"Pt1-Pt2");
379 double cotgTheta1_cotgTheta2 =
mapHisto_[
"ReadCovariances"]->Get(*(recMu[
i]),
"CotgTheta1-CotgTheta2");
380 double phi1_phi2 =
mapHisto_[
"ReadCovariances"]->Get(*(recMu[
i]),
"Phi1-Phi2");
381 double pt12_cotgTheta21 =
mapHisto_[
"ReadCovariances"]->Get(*(recMu[
i]),
"Pt12-CotgTheta21");
382 double pt12_phi21 =
mapHisto_[
"ReadCovariances"]->Get(*(recMu[
i]),
"Pt12-Phi21");
383 double cotgTheta12_phi21 =
mapHisto_[
"ReadCovariances"]->Get(*(recMu[
i]),
"CotgTheta12-Phi21");
387 mapHisto_[
"MassResolutionCotgTheta"]->Fill(
390 mapHisto_[
"MassResolutionPt-CotgTheta"]->Fill(
391 *(recMu[
i]), 2 * pt_cotgTheta * dmdpt[
i] * dmdcotgth[
i],
charge[
i]);
392 mapHisto_[
"MassResolutionPt-Phi"]->Fill(*(recMu[
i]), 2 * pt_phi * dmdpt[
i] * dmdphi[
i],
charge[
i]);
393 mapHisto_[
"MassResolutionCotgTheta-Phi"]->Fill(
394 *(recMu[
i]), 2 * cotgTheta_phi * dmdcotgth[
i] * dmdphi[
i],
charge[
i]);
396 mapHisto_[
"MassResolutionPt1-Pt2"]->Fill(*(recMu[
i]), pt1_pt2 * dmdpt[0] * dmdpt[1],
charge[
i]);
397 mapHisto_[
"MassResolutionCotgTheta1-CotgTheta2"]->Fill(
398 *(recMu[
i]), cotgTheta1_cotgTheta2 * dmdcotgth[0] * dmdcotgth[1],
charge[
i]);
399 mapHisto_[
"MassResolutionPhi1-Phi2"]->Fill(*(recMu[
i]), phi1_phi2 * dmdphi[0] * dmdphi[1],
charge[
i]);
401 mapHisto_[
"MassResolutionPt12-CotgTheta21"]->Fill(
402 *(recMu[
i]), pt12_cotgTheta21 * dmdpt[0] * dmdcotgth[1],
charge[
i]);
403 mapHisto_[
"MassResolutionPt12-CotgTheta21"]->Fill(
404 *(recMu[
i]), pt12_cotgTheta21 * dmdpt[1] * dmdcotgth[0],
charge[
i]);
405 mapHisto_[
"MassResolutionPt12-Phi21"]->Fill(*(recMu[
i]), pt12_phi21 * dmdpt[0] * dmdphi[1],
charge[
i]);
406 mapHisto_[
"MassResolutionPt12-Phi21"]->Fill(*(recMu[
i]), pt12_phi21 * dmdpt[1] * dmdphi[0],
charge[
i]);
407 mapHisto_[
"MassResolutionCotgTheta12-Phi21"]->Fill(
408 *(recMu[
i]), cotgTheta12_phi21 * dmdcotgth[0] * dmdphi[1],
charge[
i]);
409 mapHisto_[
"MassResolutionCotgTheta12-Phi21"]->Fill(
410 *(recMu[
i]), cotgTheta12_phi21 * dmdcotgth[1] * dmdphi[0],
charge[
i]);
418 mapHisto_[
"MassResolutionPtFromFunction"]->Fill(
425 fullMassRes += ptVariance *
std::pow(dmdpt[
i], 2) + cotgThetaVariance *
std::pow(dmdcotgth[
i], 2) +
429 2 * pt_cotgTheta * dmdpt[
i] * dmdcotgth[
i] + 2 * pt_phi * dmdpt[
i] * dmdphi[
i] +
430 2 * cotgTheta_phi * dmdcotgth[
i] * dmdphi[
i] +
432 pt1_pt2 * dmdpt[0] * dmdpt[1] + cotgTheta1_cotgTheta2 * dmdcotgth[0] * dmdcotgth[1] +
433 phi1_phi2 * dmdphi[0] * dmdphi[1] +
436 pt12_cotgTheta21 * dmdpt[0] * dmdcotgth[1] + pt12_cotgTheta21 * dmdpt[1] * dmdcotgth[0] +
437 pt12_phi21 * dmdpt[0] * dmdphi[1] + pt12_phi21 * dmdpt[1] * dmdphi[0] +
438 cotgTheta12_phi21 * dmdcotgth[0] * dmdphi[1] + cotgTheta12_phi21 * dmdcotgth[1] * dmdphi[0];
440 massRes1 += ptVariance *
std::pow(dmdpt[
i], 2);
441 massRes2 += ptVariance *
std::pow(dmdpt[
i], 2) + cotgThetaVariance *
std::pow(dmdcotgth[
i], 2);
442 massRes3 += ptVariance *
std::pow(dmdpt[
i], 2) + cotgThetaVariance *
std::pow(dmdcotgth[
i], 2) +
444 massRes4 += ptVariance *
std::pow(dmdpt[
i], 2) + cotgThetaVariance *
std::pow(dmdcotgth[
i], 2) +
445 phiVariance *
std::pow(dmdphi[
i], 2) + pt1_pt2 * dmdpt[0] * dmdpt[1] +
446 2 * pt_cotgTheta * dmdpt[
i] * dmdcotgth[
i] + 2 * pt_phi * dmdpt[
i] * dmdphi[
i] +
447 2 * cotgTheta_phi * dmdcotgth[
i] * dmdphi[
i];
448 massRes5 += ptVariance *
std::pow(dmdpt[
i], 2) + cotgThetaVariance *
std::pow(dmdcotgth[
i], 2) +
449 phiVariance *
std::pow(dmdphi[
i], 2) + pt1_pt2 * dmdpt[0] * dmdpt[1] +
450 2 * pt_cotgTheta * dmdpt[
i] * dmdcotgth[
i] + 2 * pt_phi * dmdpt[
i] * dmdphi[
i] +
451 2 * cotgTheta_phi * dmdcotgth[
i] * dmdphi[
i] +
452 cotgTheta1_cotgTheta2 * dmdcotgth[0] * dmdcotgth[1] + phi1_phi2 * dmdphi[0] * dmdphi[1];
453 massRes6 += ptVariance *
std::pow(dmdpt[
i], 2) + cotgThetaVariance *
std::pow(dmdcotgth[
i], 2) +
454 phiVariance *
std::pow(dmdphi[
i], 2) + pt1_pt2 * dmdpt[0] * dmdpt[1] +
455 2 * pt_cotgTheta * dmdpt[
i] * dmdcotgth[
i] + 2 * pt_phi * dmdpt[
i] * dmdphi[
i] +
456 2 * cotgTheta_phi * dmdcotgth[
i] * dmdphi[
i] +
457 cotgTheta1_cotgTheta2 * dmdcotgth[0] * dmdcotgth[1] + phi1_phi2 * dmdphi[0] * dmdphi[1] +
458 pt12_cotgTheta21 * dmdpt[0] * dmdcotgth[1] + pt12_cotgTheta21 * dmdpt[1] * dmdcotgth[0] +
459 pt12_phi21 * dmdpt[0] * dmdphi[1] + pt12_phi21 * dmdpt[1] * dmdphi[0] +
460 cotgTheta12_phi21 * dmdcotgth[0] * dmdphi[1] + cotgTheta12_phi21 * dmdcotgth[1] * dmdphi[0];
462 massResPtAndPt12 += ptVariance *
std::pow(dmdpt[
i], 2) + pt1_pt2 * dmdpt[0] * dmdpt[1];
470 mapHisto_[
"FullMassResolution"]->Fill(*(recMu[0]), fullMassRes,
charge[0]);
471 mapHisto_[
"FullMassResolution"]->Fill(*(recMu[1]), fullMassRes,
charge[1]);
485 mapHisto_[
"MassResPtAndPt12"]->Fill(*(recMu[0]), massResPtAndPt12,
charge[0]);
486 mapHisto_[
"MassResPtAndPt12"]->Fill(*(recMu[1]), massResPtAndPt12,
charge[1]);
489 mapHisto_[
"Covariances"]->Fill(recMu1, genPair->first, recMu2, genPair->second);
580 mapHisto_[
"CotgThetaResolutionGenVSMu"] =
602 deltaPtOverPt_ =
new TH1D(
"deltaPtOverPt",
"deltaPtOverPt", 100, -0.1, 0.1);
624 mapHisto_[
"MassResolutionPt-CotgTheta"] =
628 mapHisto_[
"MassResolutionCotgTheta-Phi"] =
632 mapHisto_[
"MassResolutionCotgTheta1-CotgTheta2"] =
636 mapHisto_[
"MassResolutionPt12-CotgTheta21"] =
640 mapHisto_[
"MassResolutionCotgTheta12-Phi21"] =
644 mapHisto_[
"sigmaCotgThetaFromVariance"] =
654 mapHisto_[
"MassResolutionPtFromFunction"] =
673 (*histo).second->Write();
688 ((recMu.Eta() - genMu.Eta()) * (recMu.Eta() - genMu.Eta())));
692 std::cout <<
"Reco muon " << recMu <<
" with eta " << recMu.Eta() <<
" and phi " << recMu.Phi() << std::endl
693 <<
" DOES NOT MATCH with generated muon from resonance: " << std::endl
694 << genMu <<
" with eta " << genMu.Eta() <<
" and phi " << genMu.Phi() << std::endl;
static double deltaPhiNoFabs(const double &phi1, const double &phi2)
Without fabs at the end, used to have a symmetric distribution for the resolution fits and variance c...
T getParameter(std::string const &) const
std::map< std::string, Histograms * > mapHisto_
std::string theRootFileName_
TH2D * recoPtVsgenPtEta12_
static std::vector< double > parResol
Sin< T >::type sin(const T &t)
void Fill(const double &x, const double &y, const double &a, const double &b) override
void readTree(const int maxEvents, const TString &fileName, MuonPairVector *savedPair, const int muonType, std::vector< std::pair< unsigned int, unsigned long long > > *evtRun, MuonPairVector *genPair=nullptr)
reco::Particle::LorentzVector lorentzVector
resolutionFunctionBase< double * > * resolutionFunctionService(const int identifier)
Service to build the resolution functor corresponding to the passed identifier.
std::vector< reco::LeafCandidate > fillMuonCollection(const std::vector< T > &tracks)
HCovarianceVSxy * massResolutionVsPtEta_
void analyze(const edm::Event &, const edm::EventSetup &) override
void fillHistoMap()
Used to fill the map with the histograms needed.
resolutionFunctionBase< std::vector< double > > * resolutionFunctionVecService(const int identifier)
Service to build the resolution functor corresponding to the passed identifier when receiving a std::...
static double massResolution(const lorentzVector &mu1, const lorentzVector &mu2)
void writeHistoMap()
Writes the histograms in the map.
Cos< T >::type cos(const T &t)
~ResolutionAnalyzer() override
#define DEFINE_FWK_MODULE(type)
std::string theCovariancesRootFileName_
bool checkDeltaR(const reco::Particle::LorentzVector &genMu, const reco::Particle::LorentzVector &recMu)
Returns true if the two particles have DeltaR < cut.
auto const & tracks
cannot be loose
std::vector< std::pair< lorentzVector, lorentzVector > > MuonPairVector
TH1D * deltaPtOverPtForEta12_
static double deltaPhi(const double &phi1, const double &phi2)
static std::vector< int > resfind
static resolutionFunctionBase< std::vector< double > > * resolutionFunctionForVec
math::XYZTLorentzVector LorentzVector
Lorentz vector.
A set of histograms for resolution.
Power< A, B >::type pow(const A &a, const B &b)
static resolutionFunctionBase< double * > * resolutionFunction
ResolutionAnalyzer(const edm::ParameterSet &)
edm::InputTag theMuonLabel_