1 #ifndef ERRORSANALYZER_CC
2 #define ERRORSANALYZER_CC
7 : treeFileName_(iConfig.getParameter<std::
string>(
"InputFileName")),
8 resolFitType_(iConfig.getParameter<int>(
"ResolFitType")),
9 maxEvents_(iConfig.getParameter<int>(
"MaxEvents")),
10 outputFileName_(iConfig.getParameter<std::
string>(
"OutputFileName")),
11 ptBins_(iConfig.getParameter<int>(
"PtBins")),
12 ptMin_(iConfig.getParameter<double>(
"PtMin")),
13 ptMax_(iConfig.getParameter<double>(
"PtMax")),
14 etaBins_(iConfig.getParameter<int>(
"EtaBins")),
15 etaMin_(iConfig.getParameter<double>(
"EtaMin")),
16 etaMax_(iConfig.getParameter<double>(
"EtaMax")),
17 debug_(iConfig.getParameter<bool>(
"Debug")),
18 ptMinCut_(iConfig.getUntrackedParameter<double>(
"PtMinCut", 0.)),
19 ptMaxCut_(iConfig.getUntrackedParameter<double>(
"PtMaxCut", 999999.)),
20 etaMinCut_(iConfig.getUntrackedParameter<double>(
"EtaMinCut", 0.)),
21 etaMaxCut_(iConfig.getUntrackedParameter<double>(
"EtaMaxCut", 100.)) {
27 std::cout <<
"Error: parameters and errors have different number of values" << std::endl;
45 new TProfile(
"sigmaMassVsPtMinusErrProfile",
"sigmaMassVsPtMinusErr",
ptBins_,
ptMin_,
ptMax_);
54 new TProfile(
"sigmaMassOverMassVsPtProfile",
"sigmaMassOverMassVsPt",
ptBins_,
ptMin_,
ptMax_);
56 new TProfile(
"sigmaMassOverMassVsPtPlusErrProfile",
"sigmaMassOverMassVsPtPlusErr",
ptBins_,
ptMin_,
ptMax_);
58 new TProfile(
"sigmaMassOverMassVsPtMinusErrProfile",
"sigmaMassOverMassVsPtMinusErr",
ptBins_,
ptMin_,
ptMax_);
63 new TProfile(
"sigmaMassOverMassVsEtaPlusErrProfile",
"sigmaMassOverMassVsEtaPlusErr",
etaBins_,
etaMin_,
etaMax_);
75 std::vector<double>::const_iterator parIt =
parameters_.begin();
76 std::vector<double>::const_iterator errIt =
errors_.begin();
77 std::vector<int>::const_iterator errFactorIt =
errorFactors_.begin();
79 for (; parIt !=
parameters_.end(); ++parIt, ++errIt, ++errFactorIt, ++
i) {
86 gROOT->SetStyle(
"Plain");
101 "sigmaMassOverMassVsEta",
106 "sigmaMassOverMassVsPt",
117 const TProfile* histoPlusErr,
118 const TProfile* histoMinusErr,
120 const TString& yLabel) {
121 TH1D* sigmaPtVsEtaTH1D =
122 new TH1D(type, type, histo->GetNbinsX(), histo->GetXaxis()->GetXmin(), histo->GetXaxis()->GetXmax());
123 TH1D* sigmaPtVsEtaPlusErrTH1D =
new TH1D(type +
"PlusErr",
126 histo->GetXaxis()->GetXmin(),
127 histo->GetXaxis()->GetXmax());
128 TH1D* sigmaPtVsEtaMinusErrTH1D =
new TH1D(type +
"MinusErr",
131 histo->GetXaxis()->GetXmin(),
132 histo->GetXaxis()->GetXmax());
134 TH1D* sigmaMassVsEtaTH1D =
135 new TH1D(type, type, histo->GetNbinsX(), histo->GetXaxis()->GetXmin(), histo->GetXaxis()->GetXmax());
136 TH1D* sigmaMassVsEtaPlusErrTH1D =
new TH1D(type +
"PlusErr",
139 histo->GetXaxis()->GetXmin(),
140 histo->GetXaxis()->GetXmax());
141 TH1D* sigmaMassVsEtaMinusErrTH1D =
new TH1D(type +
"MinusErr",
144 histo->GetXaxis()->GetXmin(),
145 histo->GetXaxis()->GetXmax());
147 TH1D* sigmaMassOverMassVsEtaTH1D =
148 new TH1D(type, type, histo->GetNbinsX(), histo->GetXaxis()->GetXmin(), histo->GetXaxis()->GetXmax());
149 TH1D* sigmaMassOverMassVsEtaPlusErrTH1D =
new TH1D(type +
"PlusErr",
152 histo->GetXaxis()->GetXmin(),
153 histo->GetXaxis()->GetXmax());
154 TH1D* sigmaMassOverMassVsEtaMinusErrTH1D =
new TH1D(type +
"MinusErr",
157 histo->GetXaxis()->GetXmin(),
158 histo->GetXaxis()->GetXmax());
160 TCanvas*
canvas =
new TCanvas(
"canvas" + type,
"canvas" + type, 1000, 800);
161 for (
int iBin = 1; iBin <= histo->GetNbinsX(); ++iBin) {
162 sigmaPtVsEtaTH1D->SetBinContent(iBin, histo->GetBinContent(iBin));
163 sigmaPtVsEtaPlusErrTH1D->SetBinContent(iBin, histoPlusErr->GetBinContent(iBin));
164 sigmaPtVsEtaMinusErrTH1D->SetBinContent(iBin, histoMinusErr->GetBinContent(iBin));
166 int numBins = sigmaPtVsEtaTH1D->GetNbinsX();
168 Double_t*
values = sigmaPtVsEtaTH1D->GetArray();
169 Double_t* valuesPlus = sigmaPtVsEtaPlusErrTH1D->GetArray();
170 Double_t* valuesMinus = sigmaPtVsEtaMinusErrTH1D->GetArray();
171 double* posErrors =
new double[numBins];
172 double* negErrors =
new double[numBins];
174 TGraphAsymmErrors* graphAsymmErrors =
new TGraphAsymmErrors(sigmaPtVsEtaTH1D);
175 TGraph* graph =
new TGraph(sigmaPtVsEtaTH1D);
177 for (
int i = 1;
i <= numBins; ++
i) {
179 posErrors[
i - 1] = valuesPlus[
i] - values[
i];
180 if (valuesMinus[
i] < 0)
181 negErrors[
i - 1] = values[
i];
183 negErrors[
i - 1] = values[
i] - valuesMinus[
i];
185 graphAsymmErrors->SetPointEYlow(
i - 1, negErrors[
i - 1]);
186 graphAsymmErrors->SetPointEYhigh(
i - 1, posErrors[
i - 1]);
194 graphAsymmErrors->SetTitle(
"");
195 graphAsymmErrors->SetFillColor(kGray);
196 graphAsymmErrors->Draw(
"A2");
200 graphAsymmErrors->GetXaxis()->SetTitle(title);
201 graphAsymmErrors->GetYaxis()->SetTitle(
"yLabel");
222 sigmaPtVsEtaPlusErrTH1D->Write();
223 sigmaPtVsEtaTH1D->Write();
224 sigmaPtVsEtaMinusErrTH1D->Write();
231 sigmaMassVsEtaPlusErrTH1D->Write();
232 sigmaMassVsEtaTH1D->Write();
233 sigmaMassVsEtaMinusErrTH1D->Write();
235 sigmaMassOverMassVsEtaPlusErrTH1D->Write();
236 sigmaMassOverMassVsEtaTH1D->Write();
237 sigmaMassOverMassVsEtaMinusErrTH1D->Write();
255 const std::vector<double>& parval,
256 const double& sigmaPt1,
257 const double& sigmaPt2) {
258 double*
p =
new double[(int)(parval.size())];
259 std::vector<double>::const_iterator it = parval.begin();
261 for (; it != parval.end(); ++it, ++
id) {
272 const double& sigmaPt1,
273 const double& sigmaPt2) {
275 double pt1 = mu1.Pt();
276 double phi1 = mu1.Phi();
277 double eta1 = mu1.Eta();
278 double theta1 = 2 * atan(
exp(-eta1));
279 double pt2 = mu2.Pt();
280 double phi2 = mu2.Phi();
281 double eta2 = mu2.Eta();
282 double theta2 = 2 * atan(
exp(-eta2));
289 pt2 * (
cos(phi1 - phi2) +
cos(theta1) *
cos(theta2) / (
sin(theta1) *
sin(theta2)))) /
294 pt1 * (
cos(phi2 - phi1) +
cos(theta2) *
cos(theta1) / (
sin(theta2) *
sin(theta1)))) /
296 double dmdphi1 = pt1 * pt2 / mass *
sin(phi1 - phi2);
297 double dmdphi2 = pt2 * pt1 / mass *
sin(phi2 - phi1);
298 double dmdcotgth1 = (pt1 * pt1 *
cos(theta1) /
sin(theta1) *
301 pt1 * pt2 *
cos(theta2) /
sin(theta2)) /
303 double dmdcotgth2 = (pt2 * pt2 *
cos(theta2) /
sin(theta2) *
306 pt2 * pt1 *
cos(theta1) /
sin(theta1)) /
313 double sigma_pt1 = sigmaPt1;
314 double sigma_pt2 = sigmaPt2;
323 double mass_res =
sqrt(
std::pow(dmdpt1 * sigma_pt1 * pt1, 2) +
std::pow(dmdpt2 * sigma_pt2 * pt2, 2) +
325 std::pow(dmdcotgth1 * sigma_cotgth1, 2) +
std::pow(dmdcotgth2 * sigma_cotgth2, 2) +
326 2 * dmdpt1 * dmdpt2 * cov_pt1pt2);
335 typedef std::vector<std::pair<lorentzVector, lorentzVector> >
MuonPairVector;
336 MuonPairVector savedPair;
337 std::vector<std::pair<unsigned int, unsigned long long> > evtRun;
352 MuonPairVector::iterator it = savedPair.begin();
353 std::cout <<
"Starting loop on " << savedPair.size() <<
" muons" << std::endl;
354 for (; it != savedPair.end(); ++it, ++
i) {
355 double pt1 = it->first.pt();
356 double eta1 = it->first.eta();
357 double pt2 = it->second.pt();
358 double eta2 = it->second.eta();
361 std::cout <<
"pt1 = " << pt1 <<
", eta1 = " << eta1 <<
", pt2 = " << pt2 <<
", eta2 = " << eta2 << std::endl;
366 if (pt1 == 0 && pt2 == 0 && eta1 == 0 && eta2 == 0)
391 double mass = (it->first + it->second).
mass();
394 std::cout <<
"sigmaPt1 = " << sigmaPt1 <<
" + " << sigmaPtPlusErr1 <<
" - " << sigmaPtMinusErr1 << std::endl;
395 std::cout <<
"sigmaPt2 = " << sigmaPt2 <<
" + " << sigmaPtPlusErr2 <<
" - " << sigmaPtMinusErr2 << std::endl;
396 std::cout <<
"sigmaMass = " << sigmaMass <<
" + " << sigmaMassPlusErr <<
" - " << sigmaMassMinusErr << std::endl;
408 if (sigmaPt1 != sigmaPt1)
410 if (sigmaPt2 != sigmaPt2)
412 if (sigmaPtPlusErr1 != sigmaPtPlusErr1)
414 if (sigmaPtPlusErr2 != sigmaPtPlusErr2)
416 if (sigmaPtMinusErr1 != sigmaPtMinusErr1)
418 if (sigmaPtMinusErr2 != sigmaPtMinusErr2)
420 if (sigmaMass != sigmaMass)
422 if (sigmaMassPlusErr != sigmaMassPlusErr)
424 if (sigmaMassMinusErr != sigmaMassMinusErr)
429 std::cout <<
"Muon pair number " << i << std::endl;
TProfile * sigmaPtVsEtaPlusErr_
TProfile * sigmaMassOverMassVsEta_
Returns ( sigmaPt/Pt(data)^2 - sigmaPt/Pt(MC)^2 )
~ErrorsPropagationAnalyzer() override
uint16_t *__restrict__ id
#define DEFINE_FWK_MODULE(type)
TProfile * sigmaMassOverMassVsPtPlusErr_
std::vector< double > valueMinusError_
static bool debugMassResol_
Sin< T >::type sin(const T &t)
TProfile * sigmaMassVsEtaMinusErr_
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)
TProfile * sigmaMassOverMassVsEtaMinusErr_
Exp< T >::type exp(const T &t)
etaMax_(conf.getParameter< double >("etaMax"))
std::vector< double > valuePlusError_
reco::Particle::LorentzVector lorentzVector
TProfile * sigmaMassVsPtPlusErr_
resolutionFunctionBase< double * > * resolutionFunctionService(const int identifier)
Service to build the resolution functor corresponding to the passed identifier.
virtual double sigmaPt(const double &pt, const double &eta, const T &parval)=0
ptMin_(conf.getParameter< double >("ptMin"))
TProfile * sigmaMassVsEtaPlusErr_
resolutionFunctionBase< std::vector< double > > * resolutionFunctionVecService(const int identifier)
Service to build the resolution functor corresponding to the passed identifier when receiving a std::...
TProfile * sigmaPtVsEtaMinusErr_
TProfile * sigmaMassOverMassVsPtMinusErr_
std::vector< int > errorFactors_
Cos< T >::type cos(const T &t)
TProfile * sigmaPtVsEtaDiff_
virtual double covPt1Pt2(const double &pt1, const double &eta1, const double &pt2, const double &eta2, const T &parval)
std::vector< double > parameters_
TProfile * sigmaPtVsPtMinusErr_
double squaredDiff(const double &eta)
double massResolution(const lorentzVector &mu1, const lorentzVector &mu2, const std::vector< double > &parval, const double &sigmaPt1, const double &sigmaPt2)
Modified method to take into account the error.
virtual double sigmaCotgTh(const double &pt, const double &eta, const T &parval)=0
TProfile * sigmaMassVsEta_
TProfile * sigmaMassOverMassVsPt_
T getParameter(std::string const &) const
void drawHistograms(const TProfile *histo, const TProfile *histoPlusErr, const TProfile *histoMinusErr, const TString &type, const TString &yLabel)
std::vector< std::pair< lorentzVector, lorentzVector > > MuonPairVector
TProfile * sigmaMassOverMassVsEtaPlusErr_
std::vector< double > errors_
ErrorsPropagationAnalyzer(const edm::ParameterSet &)
virtual double sigmaPhi(const double &pt, const double &eta, const T &parval)=0
static std::vector< int > resfind
TProfile * sigmaPtVsPtDiff_
TProfile * sigmaMassVsPtMinusErr_
virtual double sigmaPtError(const double &pt, const double &eta, const T &parval, const T &parError)
void analyze(const edm::Event &, const edm::EventSetup &) override
etaMin_(conf.getParameter< double >("etaMin"))
Power< A, B >::type pow(const A &a, const B &b)
TProfile * sigmaPtVsPtPlusErr_
static resolutionFunctionBase< double * > * resolutionFunction
TProfile * sigmaMassVsPt_