Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:22:45

0001 // #include "TFile.h"
0002 // #include "TDirectory.h"
0003 // #include "TCanvas.h"
0004 // #include "TH1D.h"
0005 // #include "TProfile.h"
0006 
0007 /**
0008  * This uncompiled macro draws the resolution histograms superimposed on the same canvas for the various quantities. <br>
0009  * It draws the reco-gen derived resolution (true resolution), those from the resolution functions from 0_MuScleFit.root
0010  * and those from the resolution functions from 1_MuScleFit.root for a comparison of the change before and after the fit.
0011  */
0012 
0013 draw( const TString & resolName, TDirectory * resolDir,
0014       const TString & functionResolName, TDirectory * functionResolDir,
0015       const TString & canvasName, TFile * outputFile,
0016       const TString & title = "", const TString & xAxisTitle = "", const TString & yAxisTitle = "", double Ymax,
0017       TDirectory * functionResolDirAfter = 0, TDirectory * resolDirAfter = 0 )
0018 {
0019 
0020   TProfile * functionResolVSpt = 0;
0021   if( functionResolDir != 0 ) {
0022     functionResolVSpt = (TProfile*) functionResolDir->Get(functionResolName);
0023   }
0024   TProfile * functionResolVsptAfter = 0;
0025   if( functionResolDirAfter != 0 ) functionResolVSptAfter = (TProfile*) functionResolDirAfter->Get(functionResolName);
0026   TH1D * resolVSpt = (TH1D*) resolDir->Get(resolName);
0027   TH1D * resolVSptAfter = 0;
0028   if( resolDirAfter != 0 ) {
0029     resolVSptAfter = (TH1D*) resolDirAfter->Get(resolName);
0030   }
0031 
0032   TString resolVSptName("from reco-gen comparison");
0033   TCanvas * c = new TCanvas(canvasName, canvasName, 1000, 800);
0034   c->cd();
0035   TLegend * legend = new TLegend(0.7,0.71,0.98,1.);
0036   legend->SetTextSize(0.02);
0037   legend->SetFillColor(0); // Have a white background
0038   if( resolDirAfter == 0 ) legend->AddEntry(resolVSpt, resolVSptName);
0039   // else legend->AddEntry(resolVSpt, resolVSptName+" before");
0040   resolVSpt->SetTitle(title);
0041   resolVSpt->Draw();
0042   resolVSpt->GetXaxis()->SetTitle(xAxisTitle);
0043   resolVSpt->GetYaxis()->SetTitle(yAxisTitle);
0044   resolVSpt->SetMaximum(Ymax);
0045   //  resolVSpt->SetMinimum(-Ymax/2);
0046   resolVSpt->SetMinimum(0);
0047   resolVSpt->Draw();
0048   if( resolDirAfter != 0 ) {
0049     resolVSptAfter->SetLineColor(kGreen);
0050     legend->AddEntry(resolVSptAfter, resolVSptName + " after");
0051     resolVSptAfter->SetName(TString(resolVSptAfter->GetName())+"_after");
0052     resolVSptAfter->Draw("SAME");
0053   }
0054 
0055   TString functionLegendName("from resolution function");
0056   TString functionLegendNameAfter;
0057   if( functionResolVSpt != 0 ) {
0058     functionResolVSpt->SetMarkerColor(kRed);
0059     functionResolVSpt->SetLineColor(kRed);
0060     legend->AddEntry(functionResolVSpt, functionLegendName);
0061     functionResolVSpt->Draw("same");
0062   }
0063   if( functionResolDirAfter != 0 ) {
0064     functionLegendNameAfter = functionLegendName + " after";
0065     functionLegendName += " before";
0066     functionResolVSptAfter->SetMarkerColor(kBlue);
0067     functionResolVSptAfter->SetLineColor(kBlue);
0068     legend->AddEntry(functionResolVSptAfter, functionLegendNameAfter);
0069     functionResolVSptAfter->Draw("same");
0070   }
0071 
0072   legend->Draw("same");
0073   // c->Draw();
0074   outputFile->cd();
0075   c->Write();
0076 }
0077 
0078 /**
0079  * This macro compares the resolutions found with the resolution functions with those
0080  * obtained from recMu-genMu comparison in MuScleFit.
0081  * The true resolutions are writted in the "redrawed.root" file by the ResolDraw.cc macro.
0082  */
0083 void ResolCompare(const TString & stringNumBefore = "0", const TString & stringNumAfter = "1", const bool probBefore = true) {
0084 
0085   // Remove the stat box
0086   gStyle->SetOptStat(0);
0087 
0088   TFile * outputFile = new TFile("ComparedResol.root", "RECREATE");
0089 
0090   TFile * resolFileBefore = new TFile("redrawed_"+stringNumBefore+".root", "READ");
0091   TFile * resolFileAfter = 0;
0092   resolFileAfter = new TFile("redrawed_"+stringNumAfter+".root", "READ");
0093   TFile * functionResolFileBefore = new TFile(stringNumBefore+"_MuScleFit.root", "READ");
0094   TFile * functionResolFileAfter = new TFile(stringNumAfter+"_MuScleFit.root", "READ");
0095 
0096   TDirectory * resolDirBefore = 0;
0097   TDirectory * resolDirAfter = 0;
0098   TDirectory * functionResolDirBefore = 0;
0099   TDirectory * functionResolDirAfter = 0;
0100 
0101 
0102   // SigmaMass/Mass
0103   // --------------
0104   resolDirBefore = (TDirectory*) resolFileBefore->Get("DeltaMassOverGenMass");
0105   if( resolFileAfter == 0 ) resolDirAfter = 0;
0106   else resolDirAfter = (TDirectory*) resolFileAfter->Get("DeltaMassOverGenMass");
0107   if( probBefore ) {
0108     functionResolDirBefore = (TDirectory*) functionResolFileBefore->Get("hFunctionResolMassVSMu");
0109   }
0110   functionResolDirAfter = (TDirectory*) functionResolFileAfter->Get("hFunctionResolMassVSMu");
0111   // Vs Pt
0112   draw("DeltaMassOverGenMassVsPt_resol", resolDirBefore,
0113        "hFunctionResolMassVSMu_ResoVSPt_prof", functionResolDirBefore,
0114        "massResolVSPt", outputFile,
0115        "resolution on mass vs pt",
0116        "muon pt(GeV)", "#sigmaM/M",0.15,
0117        functionResolDirAfter, resolDirAfter );
0118   // VsEta
0119   resolDirBefore = (TDirectory*) resolFileBefore->Get("DeltaMassOverGenMass");
0120   if( resolFileAfter == 0 ) resolDirAfter = 0;
0121   else resolDirAfter = (TDirectory*) resolFileAfter->Get("DeltaMassOverGenMass");
0122   draw("DeltaMassOverGenMassVsEta_resol", resolDirBefore,
0123        "hFunctionResolMassVSMu_ResoVSEta_prof", functionResolDirBefore,
0124        "massResolVSEta", outputFile,
0125        "resolution on mass vs eta",
0126        "muon #eta", "#sigmaM/M",0.09,
0127        functionResolDirAfter, resolDirAfter );
0128 
0129 
0130   // sigmaPt/Pt
0131   // ----------
0132   resolDirBefore = (TDirectory*) resolFileBefore->Get("hResolPtGenVSMu");
0133   if( resolFileAfter == 0 ) resolDirAfter = 0;
0134   else resolDirAfter = (TDirectory*) resolFileAfter->Get("hResolPtGenVSMu");
0135   functionResolDirBefore = (TDirectory*) functionResolFileBefore->Get("hFunctionResolPt");
0136   functionResolDirAfter = (TDirectory*) functionResolFileAfter->Get("hFunctionResolPt");
0137 
0138   //=====> All
0139   // VS Pt
0140   draw("hResolPtGenVSMu_ResoVSPt_resol", resolDirBefore,
0141        "hFunctionResolPt_ResoVSPt_prof", functionResolDirBefore,
0142        "resolPtVSPt", outputFile,
0143        "resolution on pt vs pt",
0144        "muon pt(GeV)", "#sigmapt/pt",0.09,
0145        functionResolDirAfter, resolDirAfter );
0146   // VS Pt RMS
0147   draw("hResolPtGenVSMu_ResoVSPt_resolRMS", resolDirBefore,
0148        "hFunctionResolPt_ResoVSPt_prof", functionResolDirBefore,
0149        "resolPtVSPtRMS", outputFile,
0150        "resolution on pt vs pt",
0151        "muon pt(GeV)", "#sigmapt/pt",0.09,
0152        functionResolDirAfter, resolDirAfter );
0153 
0154   //=====> Barrel
0155   // VS Pt
0156   draw("hResolPtGenVSMu_ResoVSPt_Bar_resol", resolDirBefore,
0157        "hFunctionResolPt_ResoVSPt_Bar_prof", functionResolDirBefore,
0158        "resolPtVSPtBar", outputFile,
0159        "resolution on pt vs pt, barrel",
0160        "muon pt(GeV)", "#sigmapt/pt",0.09,
0161        functionResolDirAfter, resolDirAfter );
0162   // VS Pt RMS
0163   draw("hResolPtGenVSMu_ResoVSPt_Bar_resolRMS", resolDirBefore,
0164        "hFunctionResolPt_ResoVSPt_Bar_prof", functionResolDirBefore,
0165        "resolPtVSPtBarRMS", outputFile,
0166        "resolution on pt vs pt, barrel",
0167        "muon pt(GeV)", "#sigmapt/pt",0.09,
0168        functionResolDirAfter, resolDirAfter );
0169 
0170   //=====> Endcap 1
0171   // VS Pt
0172   draw("hResolPtGenVSMu_ResoVSPt_Endc_1.7_resol", resolDirBefore,
0173        "hFunctionResolPt_ResoVSPt_Endc_1.7_prof", functionResolDirBefore,
0174        "resolPtVSPtEndc_1.7", outputFile,
0175        "resolution on pt vs pt, endcap",
0176        "muon pt(GeV)", "#sigmapt/pt",0.09,
0177        functionResolDirAfter, resolDirAfter );
0178   // VS Pt RMS
0179   draw("hResolPtGenVSMu_ResoVSPt_Endc_1.7_resolRMS", resolDirBefore,
0180        "hFunctionResolPt_ResoVSPt_Endc_1.7_prof", functionResolDirBefore,
0181        "resolPtVSPtEndc1.7RMS", outputFile,
0182        "resolution on pt vs pt, endcap",
0183        "muon pt(GeV)", "#sigmapt/pt",0.09,
0184        functionResolDirAfter, resolDirAfter );
0185 
0186   //=====> Endcap 2
0187   // VS Pt
0188   draw("hResolPtGenVSMu_ResoVSPt_Endc_2.0_resol", resolDirBefore,
0189        "hFunctionResolPt_ResoVSPt_Endc_2.0_prof", functionResolDirBefore,
0190        "resolPtVSPtEndc2.0", outputFile,
0191        "resolution on pt vs pt, endcap",
0192        "muon pt(GeV)", "#sigmapt/pt",0.09,
0193        functionResolDirAfter, resolDirAfter );
0194   // VS Pt RMS
0195   draw("hResolPtGenVSMu_ResoVSPt_Endc_2.0_resolRMS", resolDirBefore,
0196        "hFunctionResolPt_ResoVSPt_Endc_2.0_prof", functionResolDirBefore,
0197        "resolPtVSPtEndc2.0RMS", outputFile,
0198        "resolution on pt vs pt, endcap",
0199        "muon pt(GeV)", "#sigmapt/pt",0.09,
0200        functionResolDirAfter, resolDirAfter );
0201 
0202   //=====> Endcap 3
0203   // VS Pt
0204   draw("hResolPtGenVSMu_ResoVSPt_Endc_2.4_resol", resolDirBefore,
0205        "hFunctionResolPt_ResoVSPt_Endc_2.4_prof", functionResolDirBefore,
0206        "resolPtVSPtEndc2.4", outputFile,
0207        "resolution on pt vs pt, endcap",
0208        "muon pt(GeV)", "#sigmapt/pt",0.09,
0209        functionResolDirAfter, resolDirAfter );
0210   // VS Pt RMS
0211   draw("hResolPtGenVSMu_ResoVSPt_Endc_2.4_resolRMS", resolDirBefore,
0212        "hFunctionResolPt_ResoVSPt_Endc_2.4_prof", functionResolDirBefore,
0213        "resolPtVSPtEndc2.4RMS", outputFile,
0214        "resolution on pt vs pt, endcap",
0215        "muon pt(GeV)", "#sigmapt/pt",0.09,
0216        functionResolDirAfter, resolDirAfter );
0217 
0218 
0219   //=====> overlap
0220   // VS Pt
0221   draw("hResolPtGenVSMu_ResoVSPt_Ovlap_resol", resolDirBefore,
0222        "hFunctionResolPt_ResoVSPt_Ovlap_prof", functionResolDirBefore,
0223        "resolPtVSPtOvlap", outputFile,
0224        "resolution on pt vs pt, overlap",
0225        "muon pt(GeV)", "#sigmapt/pt",0.09,
0226        functionResolDirAfter, resolDirAfter );
0227   // VS Pt RMS
0228   draw("hResolPtGenVSMu_ResoVSPt_Ovlap_resolRMS", resolDirBefore,
0229        "hFunctionResolPt_ResoVSPt_Ovlap_prof", functionResolDirBefore,
0230        "resolPtVSPtOvlapRMS", outputFile,
0231        "resolution on pt vs pt",
0232        "muon pt(GeV)", "#sigmapt/pt",0.09,
0233        functionResolDirAfter, resolDirAfter );
0234 
0235   // VS Eta
0236   draw("hResolPtGenVSMu_ResoVSEta_resol", resolDirBefore,
0237        "hFunctionResolPt_ResoVSEta_prof", functionResolDirBefore,
0238        "resolPtVSEta", outputFile,
0239        "resolution on pt vs #eta",
0240        "muon #eta", "#sigmapt/pt",0.15,
0241        functionResolDirAfter, resolDirAfter );
0242   // VS Eta RMS
0243   draw("hResolPtGenVSMu_ResoVSEta_resolRMS", resolDirBefore,
0244        "hFunctionResolPt_ResoVSEta_prof", functionResolDirBefore,
0245        "resolPtVSEtaRMS", outputFile,
0246        "resolution on pt vs #eta",
0247        "muon #eta", "#sigmapt/pt",0.15,
0248        functionResolDirAfter, resolDirAfter );
0249 
0250   // sigmaCotgTheta
0251   // --------------
0252   resolDirBefore = (TDirectory*) resolFileBefore->Get("hResolCotgThetaGenVSMu");
0253   if( resolFileAfter == 0 ) resolDirAfter = 0;
0254   else resolDirAfter = (TDirectory*) resolFileAfter->Get("hResolCotgThetaGenVSMu");
0255   functionResolDirBefore = (TDirectory*) functionResolFileBefore->Get("hFunctionResolCotgTheta");
0256   functionResolDirAfter = (TDirectory*) functionResolFileAfter->Get("hFunctionResolCotgTheta");
0257   // VS Pt
0258   draw("hResolCotgThetaGenVSMu_ResoVSPt_resol", resolDirBefore,
0259        "hFunctionResolCotgTheta_ResoVSPt_prof", functionResolDirBefore,
0260        "resolCotgThetaVSPt", outputFile,
0261        "resolution on cotg(#theta) vs pt",
0262        "muon pt(GeV)", "#sigmacotg(#theta)",0.01,
0263        functionResolDirAfter, resolDirAfter );
0264   // VS Eta
0265   draw("hResolCotgThetaGenVSMu_ResoVSEta_resol", resolDirBefore,
0266        "hFunctionResolCotgTheta_ResoVSEta_prof", functionResolDirBefore,
0267        "resolCotgThetaVSEta", outputFile,
0268        "resolution on cotg(#theta) vs #eta",
0269        "muon #eta", "#sigmacotg(#theta)",0.01,
0270        functionResolDirAfter, resolDirAfter );
0271   // sigmaPhi
0272   // --------
0273   resolDirBefore = (TDirectory*) resolFileBefore->Get("hResolPhiGenVSMu");
0274   if( resolFileAfter == 0 ) resolDirAfter = 0;
0275   else resolDirAfter = (TDirectory*) resolFileAfter->Get("hResolPhiGenVSMu");
0276   functionResolDirBefore = (TDirectory*) functionResolFileBefore->Get("hFunctionResolPhi");
0277   functionResolDirAfter = (TDirectory*) functionResolFileAfter->Get("hFunctionResolPhi");
0278   // VS Pt
0279   draw("hResolPhiGenVSMu_ResoVSPt_resol", resolDirBefore,
0280        "hFunctionResolPhi_ResoVSPt_prof", functionResolDirBefore,
0281        "resolPhiVSPt", outputFile,
0282        "resolution on #phi vs pt",
0283        "muon pt(GeV)", "#sigma#phi",0.01,
0284        functionResolDirAfter, resolDirAfter );
0285   // VS Eta
0286   draw("hResolPhiGenVSMu_ResoVSEta_resol", resolDirBefore,
0287        "hFunctionResolPhi_ResoVSEta_prof", functionResolDirBefore,
0288        "resolPhiVSEta", outputFile,
0289        "resolution on #phi vs #eta",
0290        "muon #eta", "#sigma#phi",0.01,
0291        functionResolDirAfter, resolDirAfter );
0292 }