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]);
158 graphAsymmErrors->SetTitle(
"");
159 graphAsymmErrors->SetFillColor(kGray);
160 graphAsymmErrors->Draw(
"A2");
162 if( type ==
"Eta" ) title =
"#eta";
163 graphAsymmErrors->GetXaxis()->SetTitle(title);
164 graphAsymmErrors->GetYaxis()->SetTitle(
"yLabel");
185 sigmaPtVsEtaPlusErrTH1D->Write();
186 sigmaPtVsEtaTH1D->Write();
187 sigmaPtVsEtaMinusErrTH1D->Write();
194 sigmaMassVsEtaPlusErrTH1D->Write();
195 sigmaMassVsEtaTH1D->Write();
196 sigmaMassVsEtaMinusErrTH1D->Write();
198 sigmaMassOverMassVsEtaPlusErrTH1D->Write();
199 sigmaMassOverMassVsEtaTH1D->Write();
200 sigmaMassOverMassVsEtaMinusErrTH1D->Write();
220 const std::vector< double >& parval,
221 const double& sigmaPt1,
222 const double& sigmaPt2)
224 double *
p =
new double[(
int)(parval.size())];
225 std::vector<double>::const_iterator it = parval.begin();
227 for ( ; it!=parval.end(); ++it, ++
id) {
230 double massRes =
massResolution (mu1, mu2, p, sigmaPt1, sigmaPt2);
238 const double & sigmaPt1,
239 const double & sigmaPt2)
242 double pt1 = mu1.Pt();
243 double phi1 = mu1.Phi();
244 double eta1 = mu1.Eta();
245 double theta1 = 2*atan(
exp(-eta1));
246 double pt2 = mu2.Pt();
247 double phi2 = mu2.Phi();
248 double eta2 = mu2.Eta();
249 double theta2 = 2*atan(
exp(-eta2));
254 pt2*(
cos(phi1-phi2)+
cos(theta1)*
cos(theta2)/(
sin(theta1)*
sin(theta2))))/mass;
256 pt1*(
cos(phi2-phi1)+
cos(theta2)*
cos(theta1)/(
sin(theta2)*
sin(theta1))))/mass;
257 double dmdphi1 = pt1*pt2/mass*
sin(phi1-phi2);
258 double dmdphi2 = pt2*pt1/mass*
sin(phi2-phi1);
259 double dmdcotgth1 = (pt1*pt1*
cos(theta1)/
sin(theta1)*
261 pt1*pt2*
cos(theta2)/
sin(theta2))/mass;
262 double dmdcotgth2 = (pt2*pt2*
cos(theta2)/
sin(theta2)*
264 pt2*pt1*
cos(theta1)/
sin(theta1))/mass;
270 double sigma_pt1 = sigmaPt1;
271 double sigma_pt2 = sigmaPt2;
283 2*dmdpt1*dmdpt2*cov_pt1pt2);
294 typedef std::vector<std::pair<lorentzVector,lorentzVector> >
MuonPairVector;
295 MuonPairVector savedPair;
296 std::vector<std::pair<unsigned int, unsigned long long> > evtRun;
311 MuonPairVector::iterator it = savedPair.begin();
312 std::cout <<
"Starting loop on " << savedPair.size() <<
" muons" << std::endl;
313 for( ; it != savedPair.end(); ++it, ++
i ) {
314 double pt1 = it->first.pt();
315 double eta1 = it->first.eta();
316 double pt2 = it->second.pt();
317 double eta2 = it->second.eta();
320 std::cout <<
"pt1 = " << pt1 <<
", eta1 = " << eta1 <<
", pt2 = " << pt2 <<
", eta2 = " << eta2 << std::endl;
325 if( pt1 == 0 && pt2 == 0 && eta1 == 0 && eta2 == 0 )
continue;
350 double mass = (it->first + it->second).
mass();
353 std::cout <<
"sigmaPt1 = " << sigmaPt1 <<
" + " << sigmaPtPlusErr1 <<
" - " << sigmaPtMinusErr1 << std::endl;
354 std::cout <<
"sigmaPt2 = " << sigmaPt2 <<
" + " << sigmaPtPlusErr2 <<
" - " << sigmaPtMinusErr2 << std::endl;
355 std::cout <<
"sigmaMass = " << sigmaMass <<
" + " << sigmaMassPlusErr <<
" - " << sigmaMassMinusErr << std::endl;
359 if( pt1 != pt1 )
continue;
360 if( pt2 != pt2 )
continue;
361 if( eta1 != eta1 )
continue;
362 if( eta2 != eta2 )
continue;
363 if( sigmaPt1 != sigmaPt1 )
continue;
364 if( sigmaPt2 != sigmaPt2 )
continue;
365 if( sigmaPtPlusErr1 != sigmaPtPlusErr1 )
continue;
366 if( sigmaPtPlusErr2 != sigmaPtPlusErr2 )
continue;
367 if( sigmaPtMinusErr1 != sigmaPtMinusErr1 )
continue;
368 if( sigmaPtMinusErr2 != sigmaPtMinusErr2 )
continue;
369 if( sigmaMass != sigmaMass )
continue;
370 if( sigmaMassPlusErr != sigmaMassPlusErr )
continue;
371 if( sigmaMassMinusErr != sigmaMassMinusErr )
continue;
372 if( mass == 0 )
continue;
374 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
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_
#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::...
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_