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.) )
28 std::cout <<
"Error: parameters and errors have different number of values" << std::endl;
67 std::vector<double>::const_iterator parIt =
parameters_.begin();
68 std::vector<double>::const_iterator errIt =
errors_.begin();
69 std::vector<int>::const_iterator errFactorIt =
errorFactors_.begin();
71 for( ; parIt !=
parameters_.end(); ++parIt, ++errIt, ++errFactorIt, ++
i ) {
79 gROOT->SetStyle(
"Plain");
102 const TProfile * histoMinusErr,
const TString &
type,
103 const TString & yLabel)
105 TH1D * sigmaPtVsEtaTH1D =
new TH1D(type, type, histo->GetNbinsX(),
106 histo->GetXaxis()->GetXmin(), histo->GetXaxis()->GetXmax());
107 TH1D * sigmaPtVsEtaPlusErrTH1D =
new TH1D(type+
"PlusErr", type+
"PlusErr", histo->GetNbinsX(),
108 histo->GetXaxis()->GetXmin(), histo->GetXaxis()->GetXmax());
109 TH1D * sigmaPtVsEtaMinusErrTH1D =
new TH1D(type+
"MinusErr", type+
"MinusErr", histo->GetNbinsX(),
110 histo->GetXaxis()->GetXmin(), histo->GetXaxis()->GetXmax());
112 TH1D * sigmaMassVsEtaTH1D =
new TH1D(type, type, histo->GetNbinsX(),
113 histo->GetXaxis()->GetXmin(), histo->GetXaxis()->GetXmax());
114 TH1D * sigmaMassVsEtaPlusErrTH1D =
new TH1D(type+
"PlusErr", type+
"PlusErr", histo->GetNbinsX(),
115 histo->GetXaxis()->GetXmin(), histo->GetXaxis()->GetXmax());
116 TH1D * sigmaMassVsEtaMinusErrTH1D =
new TH1D(type+
"MinusErr", type+
"MinusErr", histo->GetNbinsX(),
117 histo->GetXaxis()->GetXmin(), histo->GetXaxis()->GetXmax());
119 TH1D * sigmaMassOverMassVsEtaTH1D =
new TH1D(type, type, histo->GetNbinsX(),
120 histo->GetXaxis()->GetXmin(), histo->GetXaxis()->GetXmax());
121 TH1D * sigmaMassOverMassVsEtaPlusErrTH1D =
new TH1D(type+
"PlusErr", type+
"PlusErr", histo->GetNbinsX(),
122 histo->GetXaxis()->GetXmin(), histo->GetXaxis()->GetXmax());
123 TH1D * sigmaMassOverMassVsEtaMinusErrTH1D =
new TH1D(type+
"MinusErr", type+
"MinusErr", histo->GetNbinsX(),
124 histo->GetXaxis()->GetXmin(), histo->GetXaxis()->GetXmax());
126 TCanvas *
canvas =
new TCanvas(
"canvas"+type,
"canvas"+type, 1000, 800);
127 for(
int iBin = 1; iBin <= histo->GetNbinsX(); ++iBin ) {
128 sigmaPtVsEtaTH1D->SetBinContent(iBin, histo->GetBinContent(iBin));
129 sigmaPtVsEtaPlusErrTH1D->SetBinContent(iBin, histoPlusErr->GetBinContent(iBin));
130 sigmaPtVsEtaMinusErrTH1D->SetBinContent(iBin, histoMinusErr->GetBinContent(iBin));
132 int numBins = sigmaPtVsEtaTH1D->GetNbinsX();
134 Double_t *
values = sigmaPtVsEtaTH1D->GetArray();
135 Double_t * valuesPlus = sigmaPtVsEtaPlusErrTH1D->GetArray();
136 Double_t * valuesMinus = sigmaPtVsEtaMinusErrTH1D->GetArray();
137 double * posErrors =
new double[numBins];
138 double * negErrors =
new double[numBins];
140 TGraphAsymmErrors * graphAsymmErrors =
new TGraphAsymmErrors(sigmaPtVsEtaTH1D);
141 TGraph * graph =
new TGraph(sigmaPtVsEtaTH1D);
143 for(
int i=1;
i<=numBins; ++
i ) {
145 posErrors[
i-1] = valuesPlus[
i] - values[
i];
146 if( valuesMinus[
i] < 0 ) negErrors[
i-1] = values[
i];
147 else negErrors[
i-1] = values[
i] - valuesMinus[
i];
149 graphAsymmErrors->SetPointEYlow(
i-1, negErrors[
i-1]);
150 graphAsymmErrors->SetPointEYhigh(
i-1, posErrors[
i-1]);
155 graphAsymmErrors->SetTitle(
"");
156 graphAsymmErrors->SetFillColor(kGray);
157 graphAsymmErrors->Draw(
"A2");
159 if( type ==
"Eta" ) title =
"#eta";
160 graphAsymmErrors->GetXaxis()->SetTitle(title);
161 graphAsymmErrors->GetYaxis()->SetTitle(
"yLabel");
182 sigmaPtVsEtaPlusErrTH1D->Write();
183 sigmaPtVsEtaTH1D->Write();
184 sigmaPtVsEtaMinusErrTH1D->Write();
191 sigmaMassVsEtaPlusErrTH1D->Write();
192 sigmaMassVsEtaTH1D->Write();
193 sigmaMassVsEtaMinusErrTH1D->Write();
195 sigmaMassOverMassVsEtaPlusErrTH1D->Write();
196 sigmaMassOverMassVsEtaTH1D->Write();
197 sigmaMassOverMassVsEtaMinusErrTH1D->Write();
217 const std::vector< double >& parval,
218 const double& sigmaPt1,
219 const double& sigmaPt2)
221 double *
p =
new double[(
int)(parval.size())];
222 std::vector<double>::const_iterator it = parval.begin();
224 for ( ; it!=parval.end(); ++it, ++
id) {
227 double massRes =
massResolution (mu1, mu2, p, sigmaPt1, sigmaPt2);
235 const double & sigmaPt1,
236 const double & sigmaPt2)
239 double pt1 = mu1.Pt();
240 double phi1 = mu1.Phi();
241 double eta1 = mu1.Eta();
242 double theta1 = 2*atan(
exp(-eta1));
243 double pt2 = mu2.Pt();
244 double phi2 = mu2.Phi();
245 double eta2 = mu2.Eta();
246 double theta2 = 2*atan(
exp(-eta2));
251 pt2*(
cos(phi1-phi2)+
cos(theta1)*
cos(theta2)/(
sin(theta1)*
sin(theta2))))/mass;
253 pt1*(
cos(phi2-phi1)+
cos(theta2)*
cos(theta1)/(
sin(theta2)*
sin(theta1))))/mass;
254 double dmdphi1 = pt1*pt2/mass*
sin(phi1-phi2);
255 double dmdphi2 = pt2*pt1/mass*
sin(phi2-phi1);
256 double dmdcotgth1 = (pt1*pt1*
cos(theta1)/
sin(theta1)*
258 pt1*pt2*
cos(theta2)/
sin(theta2))/mass;
259 double dmdcotgth2 = (pt2*pt2*
cos(theta2)/
sin(theta2)*
261 pt2*pt1*
cos(theta1)/
sin(theta1))/mass;
267 double sigma_pt1 = sigmaPt1;
268 double sigma_pt2 = sigmaPt2;
280 2*dmdpt1*dmdpt2*cov_pt1pt2);
291 typedef std::vector<std::pair<lorentzVector,lorentzVector> >
MuonPairVector;
292 MuonPairVector savedPair;
293 std::vector<std::pair<unsigned int, unsigned long long> > evtRun;
308 MuonPairVector::iterator it = savedPair.begin();
309 std::cout <<
"Starting loop on " << savedPair.size() <<
" muons" << std::endl;
310 for( ; it != savedPair.end(); ++it, ++
i ) {
311 double pt1 = it->first.pt();
312 double eta1 = it->first.eta();
313 double pt2 = it->second.pt();
314 double eta2 = it->second.eta();
317 std::cout <<
"pt1 = " << pt1 <<
", eta1 = " << eta1 <<
", pt2 = " << pt2 <<
", eta2 = " << eta2 << std::endl;
322 if( pt1 == 0 && pt2 == 0 && eta1 == 0 && eta2 == 0 )
continue;
347 double mass = (it->first + it->second).
mass();
350 std::cout <<
"sigmaPt1 = " << sigmaPt1 <<
" + " << sigmaPtPlusErr1 <<
" - " << sigmaPtMinusErr1 << std::endl;
351 std::cout <<
"sigmaPt2 = " << sigmaPt2 <<
" + " << sigmaPtPlusErr2 <<
" - " << sigmaPtMinusErr2 << std::endl;
352 std::cout <<
"sigmaMass = " << sigmaMass <<
" + " << sigmaMassPlusErr <<
" - " << sigmaMassMinusErr << std::endl;
356 if( pt1 != pt1 )
continue;
357 if( pt2 != pt2 )
continue;
358 if( eta1 != eta1 )
continue;
359 if( eta2 != eta2 )
continue;
360 if( sigmaPt1 != sigmaPt1 )
continue;
361 if( sigmaPt2 != sigmaPt2 )
continue;
362 if( sigmaPtPlusErr1 != sigmaPtPlusErr1 )
continue;
363 if( sigmaPtPlusErr2 != sigmaPtPlusErr2 )
continue;
364 if( sigmaPtMinusErr1 != sigmaPtMinusErr1 )
continue;
365 if( sigmaPtMinusErr2 != sigmaPtMinusErr2 )
continue;
366 if( sigmaMass != sigmaMass )
continue;
367 if( sigmaMassPlusErr != sigmaMassPlusErr )
continue;
368 if( sigmaMassMinusErr != sigmaMassMinusErr )
continue;
369 if( mass == 0 )
continue;
371 std::cout <<
"Muon pair number " << i << std::endl;
T getParameter(std::string const &) const
TProfile * sigmaPtVsEtaPlusErr_
TProfile * sigmaMassOverMassVsEta_
Returns ( sigmaPt/Pt(data)^2 - sigmaPt/Pt(MC)^2 )
~ErrorsPropagationAnalyzer() override
#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_
std::vector< double > valuePlusError_
reco::Particle::LorentzVector lorentzVector
TProfile * sigmaMassVsPtPlusErr_
virtual double sigmaPt(const double &pt, const double &eta, const T &parval)=0
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_
std::vector< std::pair< lorentzVector, lorentzVector > > MuonPairVector
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_
void drawHistograms(const TProfile *histo, const TProfile *histoPlusErr, const TProfile *histoMinusErr, const TString &type, const TString &yLabel)
TProfile * sigmaMassOverMassVsEtaPlusErr_
resolutionFunctionBase< double * > * resolutionFunctionService(const int identifier)
Service to build the resolution functor corresponding to the passed identifier.
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
Power< A, B >::type pow(const A &a, const B &b)
TProfile * sigmaPtVsPtPlusErr_
static resolutionFunctionBase< double * > * resolutionFunction
TProfile * sigmaMassVsPt_