1 #ifndef RESOLUTIONANALYZER_CC 2 #define RESOLUTIONANALYZER_CC 20 : theMuonLabel_(iConfig.getParameter<
edm::
InputTag>(
"MuonLabel")),
21 theMuonType_(iConfig.getParameter<
int>(
"MuonType")),
22 theRootFileName_(iConfig.getUntrackedParameter<
std::
string>(
"OutputFileName")),
23 theCovariancesRootFileName_(iConfig.getUntrackedParameter<
std::
string>(
"InputFileName")),
24 debug_(iConfig.getUntrackedParameter<
bool>(
"Debug")),
25 resonance_(iConfig.getParameter<
bool>(
"Resonance")),
26 readCovariances_(iConfig.getParameter<
bool>(
"ReadCovariances")),
27 treeFileName_(iConfig.getParameter<
std::
string>(
"InputTreeName")),
28 maxEvents_(iConfig.getParameter<
int>(
"MaxEvents")),
29 ptMax_(iConfig.getParameter<double>(
"PtMax")) {
34 int resolFitType = iConfig.
getParameter<
int>(
"ResolFitType");
72 typedef std::vector<std::pair<lorentzVector, lorentzVector> >
MuonPairVector;
73 MuonPairVector savedPairVector;
74 MuonPairVector genPairVector;
76 std::vector<std::pair<unsigned int, unsigned long long> > evtRun;
78 MuonPairVector::iterator savedPair = savedPairVector.begin();
79 MuonPairVector::iterator genPair = genPairVector.begin();
80 std::cout <<
"Starting loop on " << savedPairVector.size() <<
" muons" << std::endl;
81 for (; savedPair != savedPairVector.end(); ++savedPair, ++genPair) {
98 mapHisto_[
"DeltaGenMotherMuons"]->Fill(genPair->first, genPair->second);
99 mapHisto_[
"GenMotherMuons"]->Fill(genPair->first);
100 mapHisto_[
"GenMotherMuons"]->Fill(genPair->second);
105 mapHisto_[
"PtResolutionGenVSMu"]->Fill(recMu1, (-genPair->first.Pt() + recMu1.Pt()) / genPair->first.Pt(), -1);
106 mapHisto_[
"ThetaResolutionGenVSMu"]->Fill(recMu1, (-genPair->first.Theta() + recMu1.Theta()), -1);
107 mapHisto_[
"CotgThetaResolutionGenVSMu"]->Fill(
109 (-
cos(genPair->first.Theta()) /
sin(genPair->first.Theta()) +
cos(recMu1.Theta()) /
sin(recMu1.Theta())),
111 mapHisto_[
"EtaResolutionGenVSMu"]->Fill(recMu1, (-genPair->first.Eta() + recMu1.Eta()), -1);
116 deltaPtOverPt_->Fill((recMu1.Pt() - genPair->first.Pt()) / genPair->first.Pt());
117 if (fabs(recMu1.Eta()) > 1 && fabs(recMu1.Eta()) < 1.2) {
124 recMu2, (-genPair->second.Pt() + recMu2.Pt()) / genPair->second.Pt(), +1);
125 mapHisto_[
"ThetaResolutionGenVSMu"]->Fill(recMu2, (-genPair->second.Theta() + recMu2.Theta()), +1);
126 mapHisto_[
"CotgThetaResolutionGenVSMu"]->Fill(
128 (-
cos(genPair->second.Theta()) /
sin(genPair->second.Theta()) +
cos(recMu2.Theta()) /
sin(recMu2.Theta())),
130 mapHisto_[
"EtaResolutionGenVSMu"]->Fill(recMu2, (-genPair->second.Eta() + recMu2.Eta()), +1);
135 deltaPtOverPt_->Fill((recMu2.Pt() - genPair->second.Pt()) / genPair->second.Pt());
136 if (fabs(recMu2.Eta()) > 1 && fabs(recMu2.Eta()) < 1.2) {
146 if (genPair->first != nullLorentzVector && genPair->second != nullLorentzVector &&
148 double recoMass = (recMu1 + recMu2).
mass();
149 double genMass = (genPair->first + genPair->second).
mass();
151 mapHisto_[
"MassResolution"]->Fill(recMu1, -1, genPair->first, recMu2, +1, genPair->second, recoMass, genMass);
155 mapHisto_[
"RecoResonance"]->Fill(recoResonance);
156 mapHisto_[
"DeltaRecoResonanceMuons"]->Fill(recMu1, recMu2);
157 mapHisto_[
"RecoResonanceMuons"]->Fill(recMu1);
158 mapHisto_[
"RecoResonanceMuons"]->Fill(recMu2);
163 double diffMass = recoMass - genMass;
165 double pt1 = recMu1.pt();
166 double eta1 = recMu1.eta();
167 double pt2 = recMu2.pt();
168 double eta2 = recMu2.eta();
170 if (diffMass == diffMass) {
174 std::cout <<
"Error, there is a nan: recoMass = " << recoMass <<
", genMass = " << genMass << std::endl;
189 mapHisto_[
"hFunctionResolCotgTheta"]->Fill(
201 mapHisto_[
"hFunctionResolCotgTheta"]->Fill(
213 double mass = (recMu1 + recMu2).
mass();
214 double pt1 = recMu1.Pt();
215 double phi1 = recMu1.Phi();
216 double eta1 = recMu1.Eta();
217 double theta1 = 2 * atan(
exp(-eta1));
218 double pt2 = recMu2.Pt();
219 double phi2 = recMu2.Phi();
220 double eta2 = recMu2.Eta();
221 double theta2 = 2 * atan(
exp(-eta2));
226 pt2 * (
cos(phi1 - phi2) +
cos(theta1) *
cos(theta2) / (
sin(theta1) *
sin(theta2)))) /
230 pt1 * (
cos(phi2 - phi1) +
cos(theta2) *
cos(theta1) / (
sin(theta2) *
sin(theta1)))) /
232 double dmdphi1 = pt1 * pt2 / mass *
sin(phi1 - phi2);
233 double dmdphi2 = pt2 * pt1 / mass *
sin(phi2 - phi1);
235 (pt1 * pt1 *
cos(theta1) /
sin(theta1) *
237 pt1 * pt2 *
cos(theta2) /
sin(theta2)) /
240 (pt2 * pt2 *
cos(theta2) /
sin(theta2) *
242 pt2 * pt1 *
cos(theta1) /
sin(theta1)) /
247 double dmdpt[2] = {dmdpt1 * recMu1.Pt(), dmdpt2 * recMu2.Pt()};
248 double dmdphi[2] = {dmdphi1, dmdphi2};
249 double dmdcotgth[2] = {dmdcotgth1, dmdcotgth2};
256 double fullMassRes = 0.;
257 double massRes1 = 0.;
258 double massRes2 = 0.;
259 double massRes3 = 0.;
260 double massRes4 = 0.;
261 double massRes5 = 0.;
262 double massRes6 = 0.;
263 double massResPtAndPt12 = 0.;
265 for (
int i = 0;
i < 2; ++
i) {
266 double ptVariance =
mapHisto_[
"ReadCovariances"]->Get(*(recMu[
i]),
"Pt");
267 double cotgThetaVariance =
mapHisto_[
"ReadCovariances"]->Get(*(recMu[i]),
"CotgTheta");
268 double phiVariance =
mapHisto_[
"ReadCovariances"]->Get(*(recMu[i]),
"Phi");
269 double pt_cotgTheta =
mapHisto_[
"ReadCovariances"]->Get(*(recMu[i]),
"Pt-CotgTheta");
270 double pt_phi =
mapHisto_[
"ReadCovariances"]->Get(*(recMu[i]),
"Pt-Phi");
271 double cotgTheta_phi =
mapHisto_[
"ReadCovariances"]->Get(*(recMu[i]),
"CotgTheta-Phi");
273 double pt1_pt2 =
mapHisto_[
"ReadCovariances"]->Get(*(recMu[i]),
"Pt1-Pt2");
274 double cotgTheta1_cotgTheta2 =
mapHisto_[
"ReadCovariances"]->Get(*(recMu[i]),
"CotgTheta1-CotgTheta2");
275 double phi1_phi2 =
mapHisto_[
"ReadCovariances"]->Get(*(recMu[i]),
"Phi1-Phi2");
276 double pt12_cotgTheta21 =
mapHisto_[
"ReadCovariances"]->Get(*(recMu[i]),
"Pt12-CotgTheta21");
277 double pt12_phi21 =
mapHisto_[
"ReadCovariances"]->Get(*(recMu[i]),
"Pt12-Phi21");
278 double cotgTheta12_phi21 =
mapHisto_[
"ReadCovariances"]->Get(*(recMu[i]),
"CotgTheta12-Phi21");
281 mapHisto_[
"MassResolutionPt"]->Fill(*(recMu[i]), ptVariance *
std::pow(dmdpt[i], 2), charge[i]);
282 mapHisto_[
"MassResolutionCotgTheta"]->Fill(
283 *(recMu[i]), cotgThetaVariance *
std::pow(dmdcotgth[i], 2), charge[i]);
284 mapHisto_[
"MassResolutionPhi"]->Fill(*(recMu[i]), phiVariance *
std::pow(dmdphi[i], 2), charge[i]);
285 mapHisto_[
"MassResolutionPt-CotgTheta"]->Fill(
286 *(recMu[i]), 2 * pt_cotgTheta * dmdpt[i] * dmdcotgth[i], charge[i]);
287 mapHisto_[
"MassResolutionPt-Phi"]->Fill(*(recMu[i]), 2 * pt_phi * dmdpt[i] * dmdphi[i], charge[i]);
288 mapHisto_[
"MassResolutionCotgTheta-Phi"]->Fill(
289 *(recMu[i]), 2 * cotgTheta_phi * dmdcotgth[i] * dmdphi[i], charge[i]);
291 mapHisto_[
"MassResolutionPt1-Pt2"]->Fill(*(recMu[i]), pt1_pt2 * dmdpt[0] * dmdpt[1], charge[i]);
292 mapHisto_[
"MassResolutionCotgTheta1-CotgTheta2"]->Fill(
293 *(recMu[i]), cotgTheta1_cotgTheta2 * dmdcotgth[0] * dmdcotgth[1], charge[i]);
294 mapHisto_[
"MassResolutionPhi1-Phi2"]->Fill(*(recMu[i]), phi1_phi2 * dmdphi[0] * dmdphi[1], charge[i]);
296 mapHisto_[
"MassResolutionPt12-CotgTheta21"]->Fill(
297 *(recMu[i]), pt12_cotgTheta21 * dmdpt[0] * dmdcotgth[1], charge[i]);
298 mapHisto_[
"MassResolutionPt12-CotgTheta21"]->Fill(
299 *(recMu[i]), pt12_cotgTheta21 * dmdpt[1] * dmdcotgth[0], charge[i]);
300 mapHisto_[
"MassResolutionPt12-Phi21"]->Fill(*(recMu[i]), pt12_phi21 * dmdpt[0] * dmdphi[1], charge[i]);
301 mapHisto_[
"MassResolutionPt12-Phi21"]->Fill(*(recMu[i]), pt12_phi21 * dmdpt[1] * dmdphi[0], charge[i]);
302 mapHisto_[
"MassResolutionCotgTheta12-Phi21"]->Fill(
303 *(recMu[i]), cotgTheta12_phi21 * dmdcotgth[0] * dmdphi[1], charge[i]);
304 mapHisto_[
"MassResolutionCotgTheta12-Phi21"]->Fill(
305 *(recMu[i]), cotgTheta12_phi21 * dmdcotgth[1] * dmdphi[0], charge[i]);
308 mapHisto_[
"sigmaPtFromVariance"]->Fill(*(recMu[i]),
sqrt(ptVariance), charge[i]);
309 mapHisto_[
"sigmaCotgThetaFromVariance"]->Fill(*(recMu[i]),
sqrt(cotgThetaVariance), charge[i]);
310 mapHisto_[
"sigmaPhiFromVariance"]->Fill(*(recMu[i]),
sqrt(phiVariance), charge[i]);
313 mapHisto_[
"MassResolutionPtFromFunction"]->Fill(
320 fullMassRes += ptVariance *
std::pow(dmdpt[i], 2) + cotgThetaVariance *
std::pow(dmdcotgth[i], 2) +
321 phiVariance *
std::pow(dmdphi[i], 2) +
324 2 * pt_cotgTheta * dmdpt[
i] * dmdcotgth[
i] + 2 * pt_phi * dmdpt[
i] * dmdphi[
i] +
325 2 * cotgTheta_phi * dmdcotgth[
i] * dmdphi[
i] +
327 pt1_pt2 * dmdpt[0] * dmdpt[1] + cotgTheta1_cotgTheta2 * dmdcotgth[0] * dmdcotgth[1] +
328 phi1_phi2 * dmdphi[0] * dmdphi[1] +
331 pt12_cotgTheta21 * dmdpt[0] * dmdcotgth[1] + pt12_cotgTheta21 * dmdpt[1] * dmdcotgth[0] +
332 pt12_phi21 * dmdpt[0] * dmdphi[1] + pt12_phi21 * dmdpt[1] * dmdphi[0] +
333 cotgTheta12_phi21 * dmdcotgth[0] * dmdphi[1] + cotgTheta12_phi21 * dmdcotgth[1] * dmdphi[0];
335 massRes1 += ptVariance *
std::pow(dmdpt[i], 2);
336 massRes2 += ptVariance *
std::pow(dmdpt[i], 2) + cotgThetaVariance *
std::pow(dmdcotgth[i], 2);
337 massRes3 += ptVariance *
std::pow(dmdpt[i], 2) + cotgThetaVariance *
std::pow(dmdcotgth[i], 2) +
338 phiVariance *
std::pow(dmdphi[i], 2);
339 massRes4 += ptVariance *
std::pow(dmdpt[i], 2) + cotgThetaVariance *
std::pow(dmdcotgth[i], 2) +
340 phiVariance *
std::pow(dmdphi[i], 2) + pt1_pt2 * dmdpt[0] * dmdpt[1] +
341 2 * pt_cotgTheta * dmdpt[
i] * dmdcotgth[
i] + 2 * pt_phi * dmdpt[
i] * dmdphi[
i] +
342 2 * cotgTheta_phi * dmdcotgth[
i] * dmdphi[
i];
343 massRes5 += ptVariance *
std::pow(dmdpt[i], 2) + cotgThetaVariance *
std::pow(dmdcotgth[i], 2) +
344 phiVariance *
std::pow(dmdphi[i], 2) + pt1_pt2 * dmdpt[0] * dmdpt[1] +
345 2 * pt_cotgTheta * dmdpt[
i] * dmdcotgth[
i] + 2 * pt_phi * dmdpt[
i] * dmdphi[
i] +
346 2 * cotgTheta_phi * dmdcotgth[
i] * dmdphi[
i] +
347 cotgTheta1_cotgTheta2 * dmdcotgth[0] * dmdcotgth[1] + phi1_phi2 * dmdphi[0] * dmdphi[1];
348 massRes6 += ptVariance *
std::pow(dmdpt[i], 2) + cotgThetaVariance *
std::pow(dmdcotgth[i], 2) +
349 phiVariance *
std::pow(dmdphi[i], 2) + pt1_pt2 * dmdpt[0] * dmdpt[1] +
350 2 * pt_cotgTheta * dmdpt[
i] * dmdcotgth[
i] + 2 * pt_phi * dmdpt[
i] * dmdphi[
i] +
351 2 * cotgTheta_phi * dmdcotgth[
i] * dmdphi[
i] +
352 cotgTheta1_cotgTheta2 * dmdcotgth[0] * dmdcotgth[1] + phi1_phi2 * dmdphi[0] * dmdphi[1] +
353 pt12_cotgTheta21 * dmdpt[0] * dmdcotgth[1] + pt12_cotgTheta21 * dmdpt[1] * dmdcotgth[0] +
354 pt12_phi21 * dmdpt[0] * dmdphi[1] + pt12_phi21 * dmdpt[1] * dmdphi[0] +
355 cotgTheta12_phi21 * dmdcotgth[0] * dmdphi[1] + cotgTheta12_phi21 * dmdcotgth[1] * dmdphi[0];
357 massResPtAndPt12 += ptVariance *
std::pow(dmdpt[i], 2) + pt1_pt2 * dmdpt[0] * dmdpt[1];
360 mapHisto_[
"DerivativePt"]->Fill(*(recMu[i]), dmdpt[i], charge[i]);
361 mapHisto_[
"DerivativeCotgTheta"]->Fill(*(recMu[i]), dmdcotgth[i], charge[i]);
362 mapHisto_[
"DerivativePhi"]->Fill(*(recMu[i]), dmdphi[i], charge[i]);
365 mapHisto_[
"FullMassResolution"]->Fill(*(recMu[0]), fullMassRes, charge[0]);
366 mapHisto_[
"FullMassResolution"]->Fill(*(recMu[1]), fullMassRes, charge[1]);
368 mapHisto_[
"MassRes1"]->Fill(*(recMu[0]), massRes1, charge[0]);
369 mapHisto_[
"MassRes1"]->Fill(*(recMu[1]), massRes1, charge[1]);
370 mapHisto_[
"MassRes2"]->Fill(*(recMu[0]), massRes2, charge[0]);
371 mapHisto_[
"MassRes2"]->Fill(*(recMu[1]), massRes2, charge[1]);
372 mapHisto_[
"MassRes3"]->Fill(*(recMu[0]), massRes3, charge[0]);
373 mapHisto_[
"MassRes3"]->Fill(*(recMu[1]), massRes3, charge[1]);
374 mapHisto_[
"MassRes4"]->Fill(*(recMu[0]), massRes4, charge[0]);
375 mapHisto_[
"MassRes4"]->Fill(*(recMu[1]), massRes4, charge[1]);
376 mapHisto_[
"MassRes5"]->Fill(*(recMu[0]), massRes5, charge[0]);
377 mapHisto_[
"MassRes5"]->Fill(*(recMu[1]), massRes5, charge[1]);
378 mapHisto_[
"MassRes6"]->Fill(*(recMu[0]), massRes6, charge[0]);
379 mapHisto_[
"MassRes6"]->Fill(*(recMu[1]), massRes6, charge[1]);
380 mapHisto_[
"MassResPtAndPt12"]->Fill(*(recMu[0]), massResPtAndPt12, charge[0]);
381 mapHisto_[
"MassResPtAndPt12"]->Fill(*(recMu[1]), massResPtAndPt12, charge[1]);
384 mapHisto_[
"Covariances"]->Fill(recMu1, genPair->first, recMu2, genPair->second);
475 mapHisto_[
"CotgThetaResolutionGenVSMu"] =
495 recoPtVsgenPt_ =
new TH2D(
"recoPtVsgenPt",
"recoPtVsgenPt", 100, 0, ptMax, 100, 0, ptMax);
496 recoPtVsgenPtEta12_ =
new TH2D(
"recoPtVsgenPtEta12",
"recoPtVsgenPtEta12", 100, 0, ptMax, 100, 0, ptMax);
497 deltaPtOverPt_ =
new TH1D(
"deltaPtOverPt",
"deltaPtOverPt", 100, -0.1, 0.1);
519 mapHisto_[
"MassResolutionPt-CotgTheta"] =
523 mapHisto_[
"MassResolutionCotgTheta-Phi"] =
527 mapHisto_[
"MassResolutionCotgTheta1-CotgTheta2"] =
531 mapHisto_[
"MassResolutionPt12-CotgTheta21"] =
535 mapHisto_[
"MassResolutionCotgTheta12-Phi21"] =
539 mapHisto_[
"sigmaCotgThetaFromVariance"] =
549 mapHisto_[
"MassResolutionPtFromFunction"] =
568 (*histo).second->Write();
583 ((recMu.Eta() - genMu.Eta()) * (recMu.Eta() - genMu.Eta())));
587 std::cout <<
"Reco muon " << recMu <<
" with eta " << recMu.Eta() <<
" and phi " << recMu.Phi() << std::endl
588 <<
" DOES NOT MATCH with generated muon from resonance: " << std::endl
589 << genMu <<
" with eta " << genMu.Eta() <<
" and phi " << genMu.Phi() << std::endl;
596 #endif // RESOLUTIONANALYZER_CC 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.
HCovarianceVSxy * massResolutionVsPtEta_
void analyze(const edm::Event &, const edm::EventSetup &) override
void fillHistoMap()
Used to fill the map with the histograms needed.
#define DEFINE_FWK_MODULE(type)
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
std::string theCovariancesRootFileName_
bool checkDeltaR(const reco::Particle::LorentzVector &genMu, const reco::Particle::LorentzVector &recMu)
Returns true if the two particles have DeltaR < cut.
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 &)