File indexing completed on 2024-04-06 12:22:44
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 draw( const TString & resolName, TDirectory * resolDir, TDirectory * resolDirMisaligned,
0014 const TString & functionResolName, TDirectory * functionResolDir, TDirectory * functionResolDirMisaligned,
0015 const TString & canvasNameMC, const TString & canvasNameFunc, TFile * outputFile,
0016 const TString & title = "", const TString & xAxisTitle = "", const TString & yAxisTitle = "", double Ymax,
0017 TDirectory * functionResolDirSmeared = 0, TDirectory * resolDirSmeared = 0, double Xmin = 0, double Xmax = 80)
0018 {
0019 TProfile * functionResolVSpt = (TProfile*) functionResolDir->Get(functionResolName);
0020 TProfile * functionResolVSptMisaligned = (TProfile*) functionResolDirMisaligned->Get(functionResolName);
0021
0022 TProfile * functionResolVsptSmeared = 0;
0023 if( functionResolDirSmeared != 0 ) functionResolVSptSmeared = (TProfile*) functionResolDirSmeared->Get(functionResolName);
0024 TH1D * resolVSpt = (TH1D*) resolDir->Get(resolName);
0025 TH1D * resolVSptMisaligned = (TH1D*) resolDirMisaligned->Get(resolName);
0026 TH1D * resolVSptSmeared = 0;
0027 if( resolDirSmeared != 0 ) {
0028 resolVSptSmeared = (TH1D*) resolDirSmeared->Get(resolName);
0029 }
0030
0031 TString resolVSptName("from reco-gen comparison");
0032 TCanvas * c = new TCanvas(canvasNameMC, canvasNameMC, 1000, 800);
0033 c->cd();
0034 TLegend * legend = new TLegend(0.55,0.71,0.98,1.);
0035 legend->SetTextSize(0.03);
0036 legend->SetFillColor(0);
0037 if( resolDirSmeared == 0 ) legend->AddEntry(resolVSpt, resolVSptName);
0038 else legend->AddEntry(resolVSpt, resolVSptName+" ideal");
0039 resolVSpt->SetTitle(title);
0040 resolVSpt->Draw();
0041 resolVSpt->GetXaxis()->SetTitle(xAxisTitle);
0042 resolVSpt->GetYaxis()->SetTitle(yAxisTitle);
0043 resolVSpt->GetXaxis()->SetRangeUser(Xmin,Xmax);
0044 resolVSpt->SetMaximum(Ymax);
0045 resolVSpt->SetMinimum(0);
0046 resolVSpt->Draw();
0047 resolVSptMisaligned->SetLineColor(kRed);
0048 legend->AddEntry(resolVSptMisaligned, resolVSptName + " fake data");
0049 resolVSptMisaligned->Draw("SAME");
0050 if( resolDirSmeared != 0 ) {
0051 resolVSptSmeared->SetLineColor(kBlue);
0052 legend->AddEntry(resolVSptSmeared, resolVSptName + " smeared");
0053 resolVSptSmeared->Draw("SAME");
0054 }
0055 legend->Draw();
0056 outputFile->cd();
0057 c->Write();
0058
0059 TCanvas * c2 = new TCanvas(canvasNameFunc, canvasNameFunc, 1000, 800);
0060 c2->cd();
0061 TLegend * legend2 = new TLegend(0.55,0.71,0.98,1.);
0062 legend2->SetTextSize(0.03);
0063 legend2->SetFillColor(0);
0064 TString functionLegendName("from resolution function");
0065 TString functionLegendNameIdeal;
0066 TString functionLegendNameSmeared;
0067 TString functionLegendNameMisaligned;
0068
0069 functionLegendNameIdeal = functionLegendName + " ideal";
0070 legend2->AddEntry(functionResolVSpt, functionLegendNameIdeal);
0071 functionResolVSpt->GetXaxis()->SetTitle(xAxisTitle);
0072 functionResolVSpt->GetYaxis()->SetTitle(yAxisTitle);
0073 functionResolVSpt->GetXaxis()->SetRangeUser(Xmin,Xmax);
0074 functionResolVSpt->SetMaximum(Ymax);
0075 functionResolVSpt->SetMinimum(0);
0076 functionResolVSpt->Draw();
0077
0078 functionLegendNameMisaligned = functionLegendName + " fake data";
0079 functionResolVSptMisaligned->SetMarkerColor(kRed);
0080 functionResolVSptMisaligned->SetLineColor(kRed);
0081 legend2->AddEntry(functionResolVSptMisaligned, functionLegendNameMisaligned);
0082 functionResolVSptMisaligned->Draw("same");
0083
0084 functionLegendNameSmeared = functionLegendName + " smeared";
0085 functionResolVSptSmeared->SetMarkerColor(kBlue);
0086 functionResolVSptSmeared->SetLineColor(kBlue);
0087 legend2->AddEntry(functionResolVSptSmeared, functionLegendNameSmeared);
0088 functionResolVSptSmeared->Draw("same");
0089
0090 legend2->Draw();
0091
0092 outputFile->cd();
0093 c2->Write();
0094 }
0095
0096 TF1 * expRelativisticBWintPhotFit(const std::string & index)
0097 {
0098 ExpRelativisticBWwithZGammaInterferenceAndPhotonPropagator * fobj = new ExpRelativisticBWwithZGammaInterferenceAndPhotonPropagator;
0099 TF1 * functionToFit = new TF1(("functionToFit"+index).c_str(), fobj, 60, 120, fobj->parNum(), "ExpRelativisticBWwithZGammaInterferenceAndPhotonPropagator");
0100 functionToFit->SetParameter(0, 2.);
0101 functionToFit->SetParameter(1, 90.);
0102 functionToFit->SetParameter(2, 800.);
0103 functionToFit->SetParameter(3, 1.);
0104 functionToFit->SetParameter(4, 0.);
0105 functionToFit->SetParameter(5, 0.);
0106
0107 functionToFit->SetParLimits(3, 0., 1.);
0108 functionToFit->SetParLimits(4, 0., 1.);
0109
0110 return functionToFit;
0111 }
0112
0113
0114
0115 class ExpRelativisticBWwithZGammaInterferenceAndPhotonPropagator
0116 {
0117 public:
0118 ExpRelativisticBWwithZGammaInterferenceAndPhotonPropagator()
0119 {
0120 parNum_ = 6;
0121 twoOverPi_ = 2./TMath::Pi();
0122 }
0123 double operator() (double *x, double *p)
0124 {
0125
0126
0127
0128 double squaredMassDiff = pow((x[0]*x[0] - p[1]*p[1]), 2);
0129 double denominator = squaredMassDiff + pow(x[0], 4)*pow(p[0]/p[1], 2);
0130 return p[2]*exp(-p[5]*x[0])*( p[3]*twoOverPi_*pow(p[1]*p[0], 2)/denominator + (1-p[3]-p[4])*p[1]*squaredMassDiff/denominator + p[4]/(x[0]*x[0]));
0131 }
0132 int parNum() const { return parNum_; }
0133 protected:
0134 int parNum_;
0135 double twoOverPi_;
0136 };
0137
0138 drawZ( const TString & HistoName, TFile * AlignedFile, TFile * MisalignedFile,
0139 const TString & canvasName, TFile * outputFile, const TString & stringName,
0140 const TString & title = "", const TString & xAxisTitle = "", const TString & yAxisTitle = "", double Xmin = 0, double Xmax = 120, int rebinX = 1,
0141 TFile * SmearedFile = 0 )
0142 {
0143 TH1F * Aligned = (TH1F*) AlignedFile->Get(HistoName);
0144 TH1F * Misaligned = (TH1F*) MisalignedFile->Get(HistoName);
0145
0146 TH1F * Smeared = 0;
0147 if( SmearedFile != 0 ) Smeared = (TH1F*) SmearedFile->Get(HistoName);
0148
0149 TCanvas * c = new TCanvas(canvasName, canvasName, 1000, 800);
0150 c->Divide(1,2);
0151 c->cd(1);
0152 TLegend * legend3 = new TLegend(0.65,0.55,0.98,1.);
0153 legend3->SetTextSize(0.06);
0154 legend3->SetFillColor(0);
0155 TString LegendName(stringName);
0156 TString LegendNameAligned;
0157 TString LegendNameSmeared;
0158 TString LegendNameMisaligned;
0159
0160 LegendNameAligned = LegendName + "ideal MC";
0161 legend3->AddEntry(Aligned, LegendNameAligned);
0162 Aligned->Rebin(rebinX);
0163 Aligned->GetXaxis()->SetRangeUser(Xmin,Xmax);
0164
0165 Aligned->GetXaxis()->SetTitle(xAxisTitle);
0166 Aligned->GetYaxis()->SetTitle(yAxisTitle);
0167 Aligned->Draw("e");
0168 if(HistoName == "hRecBestRes_Mass"){
0169 TF1 * functionToFitId = expRelativisticBWintPhotFit("Ideal");
0170 Aligned->Fit(functionToFitId, "MN", "", 60, 120);
0171 functionToFitId->Draw("same");
0172 }
0173
0174 LegendNameMisaligned = LegendName + "fake data";
0175 Misaligned->SetMarkerColor(kRed);
0176 Misaligned->SetLineColor(kRed);
0177 legend3->AddEntry(Misaligned, LegendNameMisaligned);
0178 Misaligned->Rebin(rebinX);
0179
0180 Misaligned->Draw("esames");
0181 if(HistoName == "hRecBestRes_Mass"){
0182 TF1 * functionToFitFake = expRelativisticBWintPhotFit("Fake");
0183 Misaligned->Fit(functionToFitFake, "MN", "", 60, 120);
0184 functionToFitFake->SetLineColor(kRed);
0185 functionToFitFake->Draw("same");
0186 }
0187
0188 LegendNameSmeared = LegendName + "smeared MC";
0189 Smeared->SetMarkerColor(kBlue);
0190 Smeared->SetLineColor(kBlue);
0191 legend3->AddEntry(Smeared, LegendNameSmeared);
0192 Smeared->Rebin(rebinX);
0193
0194 Smeared->Draw("esames");
0195 if(HistoName == "hRecBestRes_Mass"){
0196 TF1 * functionToFitSmear = expRelativisticBWintPhotFit("Smear");
0197 Smeared->Fit(functionToFitSmear, "MN", "", 60, 120);
0198 functionToFitSmear->SetLineColor(kBlue);
0199 functionToFitSmear->Draw("same");
0200 }
0201
0202 legend3->Draw();
0203
0204 c->cd(2);
0205 TH1F *RatioIdFake = (TH1F*) Aligned->Clone();
0206 TH1F *RatioSmeFake = (TH1F*) Aligned->Clone();
0207
0208 TString LegendNameRatio1, LegendNameRatio2;
0209 TLegend * legend4 = new TLegend(0.65,0.71,0.98,1.);
0210 LegendNameRatio1 = "Z pt MC/Z pt fake";
0211 RatioIdFake->Add(Aligned,Misaligned,1,-1);
0212
0213
0214
0215 RatioIdFake->SetLineColor(kRed);
0216 RatioIdFake->Draw("");
0217 legend4->AddEntry(RatioIdFake,LegendNameRatio1);
0218 LegendNameRatio2 = "Z pt MC smeared/Z pt fake";
0219 RatioSmeFake->Add(Smeared,Misaligned,1,-1);
0220
0221 RatioSmeFake->SetLineColor(kBlue);
0222 RatioSmeFake->SetTitle("diff");
0223 RatioSmeFake->Draw("sames");
0224 legend4->AddEntry(RatioSmeFake,LegendNameRatio2);
0225 legend4->Draw();
0226
0227 outputFile->cd();
0228 c->Write();
0229
0230 }
0231
0232
0233
0234
0235
0236
0237 void ComparisonAfterSmearing(const TString & stringNumAligned = "Ideal", const TString & stringNumMisaligned = "Fake", const TString & stringNumSmeared = "Smear") {
0238
0239
0240 gStyle->SetOptStat(0);
0241
0242 TFile * outputFile = new TFile("ComparisonAfterSmearing.root", "RECREATE");
0243
0244 TFile * resolFileAligned = new TFile("redrawed_"+stringNumAligned+".root", "READ");
0245 TFile * resolFileMisaligned = new TFile("redrawed_"+stringNumMisaligned+".root", "READ");
0246 TFile * resolFileSmeared = 0;
0247 resolFileSmeared = new TFile("redrawed_"+stringNumSmeared+".root", "READ");
0248 TFile * functionResolFileAligned = new TFile(stringNumAligned+"_MuScleFit.root", "READ");
0249 TFile * functionResolFileMisaligned = new TFile(stringNumMisaligned+"_MuScleFit.root", "READ");
0250 TFile * functionResolFileSmeared = new TFile(stringNumSmeared+"_MuScleFit.root", "READ");
0251
0252 TDirectory * resolDirAligned = 0;
0253 TDirectory * resolDirMisaligned = 0;
0254 TDirectory * resolDirSmeared = 0;
0255 TDirectory * functionResolDirAligned = 0;
0256 TDirectory * functionResolDirMisaligned = 0;
0257 TDirectory * functionResolDirSmeared = 0;
0258
0259
0260
0261 drawZ("hRecBestRes_Mass", functionResolFileAligned, functionResolFileMisaligned ,
0262 "ZMass", outputFile, "Z Mass from ",
0263 "Di-muon Mass", "Di-muon Mass [GeV]", "a.u.", 60, 120, 20,
0264 functionResolFileSmeared);
0265
0266 drawZ("hRecBestRes_Pt", functionResolFileAligned, functionResolFileMisaligned ,
0267 "ZPt", outputFile, "Z pt from ",
0268 "Z Transverse momentum", "Z pt [GeV]", "a.u.", 1, 100, 1,
0269 functionResolFileSmeared);
0270
0271
0272
0273 resolDirAligned = (TDirectory*) resolFileAligned->Get("DeltaMassOverGenMassVsPt");
0274 resolDirMisaligned = (TDirectory*) resolFileMisaligned->Get("DeltaMassOverGenMassVsPt");
0275 if( resolFileSmeared == 0 ) resolDirSmeared = 0;
0276 else resolDirSmeared = (TDirectory*) resolFileSmeared->Get("DeltaMassOverGenMassVsPt");
0277 functionResolDirAligned = (TDirectory*) functionResolFileAligned->Get("hFunctionResolMassVSMu");
0278 functionResolDirMisaligned = (TDirectory*) functionResolFileMisaligned->Get("hFunctionResolMassVSMu");
0279 functionResolDirSmeared = (TDirectory*) functionResolFileSmeared->Get("hFunctionResolMassVSMu");
0280
0281 draw("DeltaMassOverGenMassVsPt_resol", resolDirAligned, resolDirMisaligned,
0282 "hFunctionResolMassVSMu_ResoVSPt_prof", functionResolDirAligned, functionResolDirMisaligned,
0283 "massResolVSptMC","massResolVSptFunc", outputFile,
0284 "resolution on mass vs pt",
0285 "muon pt(GeV)", "res #sigmaM/M",0.09,
0286 functionResolDirSmeared, resolDirSmeared );
0287
0288 resolDirAligned = (TDirectory*) resolFileAligned->Get("DeltaMassOverGenMassVsEta");
0289 resolDirMisaligned = (TDirectory*) resolFileMisaligned->Get("DeltaMassOverGenMassVsEta");
0290
0291 if( resolFileSmeared == 0 ) resolDirSmeared = 0;
0292 else resolDirSmeared = (TDirectory*) resolFileSmeared->Get("DeltaMassOverGenMassVsEta");
0293 draw("DeltaMassOverGenMassVsEta_resol", resolDirAligned, resolDirMisaligned,
0294 "hFunctionResolMassVSMu_ResoVSEta_prof", functionResolDirAligned, functionResolDirMisaligned,
0295 "massResolVSetaMC", "massResolVSetaFunc", outputFile,
0296 "resolution on mass vs #eta",
0297 "muon #eta", "#sigmaM/M",0.09,
0298 functionResolDirSmeared, resolDirSmeared, -3, 3 );
0299
0300
0301
0302
0303 resolDirAligned = (TDirectory*) resolFileAligned->Get("hResolPtGenVSMu");
0304 resolDirMisaligned = (TDirectory*) resolFileMisaligned->Get("hResolPtGenVSMu");
0305
0306 if( resolFileSmeared == 0 ) resolDirSmeared = 0;
0307 else resolDirSmeared = (TDirectory*) resolFileSmeared->Get("hResolPtGenVSMu");
0308 functionResolDirAligned = (TDirectory*) functionResolFileAligned->Get("hFunctionResolPt");
0309 functionResolDirMisaligned = (TDirectory*) functionResolFileMisaligned->Get("hFunctionResolPt");
0310 functionResolDirSmeared = (TDirectory*) functionResolFileSmeared->Get("hFunctionResolPt");
0311
0312
0313
0314 draw("hResolPtGenVSMu_ResoVSPt_resol", resolDirAligned, resolDirMisaligned,
0315 "hFunctionResolPt_ResoVSPt_prof", functionResolDirAligned, functionResolDirMisaligned,
0316 "resolPtVSptMC", "resolPtVSptFunc", outputFile,
0317 "resolution on pt vs pt",
0318 "muon pt(GeV)", "#sigmapt/pt",0.09,
0319 functionResolDirSmeared, resolDirSmeared );
0320
0321 draw("hResolPtGenVSMu_ResoVSPt_resolRMS", resolDirAligned, resolDirMisaligned,
0322 "hFunctionResolPt_ResoVSPt_prof", functionResolDirAligned, functionResolDirMisaligned,
0323 "resolPtVSptRMSMC", "resolPtVSptRMSFunc", outputFile,
0324 "resolution on pt vs pt",
0325 "muon pt(GeV)", "#sigmapt/pt",0.09,
0326 functionResolDirSmeared, resolDirSmeared );
0327
0328
0329
0330 draw("hResolPtGenVSMu_ResoVSPt_Bar_resol", resolDirAligned, resolDirMisaligned,
0331 "hFunctionResolPt_ResoVSPt_Bar_prof", functionResolDirAligned, functionResolDirMisaligned,
0332 "resolPtVSptBarMC", "resolPtVSptBarFunc", outputFile,
0333 "resolution on pt vs pt, barrel",
0334 "muon pt(GeV)", "#sigmapt/pt",0.09,
0335 functionResolDirSmeared, resolDirSmeared );
0336
0337 draw("hResolPtGenVSMu_ResoVSPt_Bar_resolRMS", resolDirAligned, resolDirMisaligned,
0338 "hFunctionResolPt_ResoVSPt_Bar_prof", functionResolDirAligned, functionResolDirMisaligned,
0339 "resolPtVSptBarRMSMC", "resolPtVSptBarRMSFunc", outputFile,
0340 "resolution on pt vs pt, barrel",
0341 "muon pt(GeV)", "#sigmapt/pt",0.09,
0342 functionResolDirSmeared, resolDirSmeared );
0343
0344
0345
0346
0347
0348
0349
0350
0351
0352
0353
0354
0355
0356
0357
0358
0359
0360
0361
0362
0363
0364
0365
0366
0367
0368
0369
0370
0371
0372
0373
0374
0375
0376
0377
0378
0379
0380
0381
0382
0383
0384
0385
0386
0387
0388
0389
0390
0391
0392
0393
0394
0395
0396 draw("hResolPtGenVSMu_ResoVSPt_Ovlap_resol", resolDirAligned, resolDirMisaligned,
0397 "hFunctionResolPt_ResoVSPt_Ovlap_prof", functionResolDirAligned, functionResolDirMisaligned,
0398 "resolPtVSptOvlapMC", "resolPtVSptOvlapFunc", outputFile,
0399 "resolution on pt vs pt, overlap",
0400 "muon pt(GeV)", "#sigmapt/pt",0.09,
0401 functionResolDirSmeared, resolDirSmeared );
0402
0403 draw("hResolPtGenVSMu_ResoVSPt_Ovlap_resolRMS", resolDirAligned, resolDirMisaligned,
0404 "hFunctionResolPt_ResoVSPt_Ovlap_prof", functionResolDirAligned, functionResolDirMisaligned,
0405 "resolPtVSptOvlapRMSMC", "resolPtVSptOvlapRMSFunc", outputFile,
0406 "resolution on pt vs pt",
0407 "muon pt(GeV)", "#sigmapt/pt",0.09,
0408 functionResolDirSmeared, resolDirSmeared );
0409
0410
0411 draw("hResolPtGenVSMu_ResoVSEta_resol", resolDirAligned, resolDirMisaligned,
0412 "hFunctionResolPt_ResoVSEta_prof", functionResolDirAligned, functionResolDirMisaligned,
0413 "resolPtVSetaMC", "resolPtVSetaFunc", outputFile,
0414 "resolution on pt vs #eta",
0415 "muon #eta", "#sigmapt/pt",0.15,
0416 functionResolDirSmeared, resolDirSmeared, -3, 3 );
0417
0418 draw("hResolPtGenVSMu_ResoVSEta_resolRMS", resolDirAligned, resolDirMisaligned,
0419 "hFunctionResolPt_ResoVSEta_prof", functionResolDirAligned, functionResolDirMisaligned,
0420 "resolPtVSetaRMSMC", "resolPtVSetaRMSFunc", outputFile,
0421 "resolution on pt vs #eta",
0422 "muon #eta", "#sigmapt/pt",0.15,
0423 functionResolDirSmeared, resolDirSmeared, -3, 3 );
0424
0425
0426 }