File indexing completed on 2024-04-06 12:22:45
0001 #include "HistoFinder.cc"
0002 #include "TLegend.h"
0003 #include "THStack.h"
0004 #include <vector>
0005
0006
0007
0008
0009
0010 class BaseNormalized {
0011 public:
0012 BaseNormalized() {}
0013 ~BaseNormalized() {}
0014 BaseNormalized( const TString & name, const TString & title ) :
0015 name_(name),
0016 title_(title),
0017 canvas_(new TCanvas(name+"_canvas",title+" canvas",1000,800)),
0018 legend_(new TLegend(0.779429,0.715556,0.979429,0.955556))
0019 {
0020
0021 legend_->SetTextSize(0.04);
0022
0023 legend_->SetFillColor(0);
0024 }
0025 protected:
0026 TString name_;
0027 TString title_;
0028 TCanvas * canvas_;
0029 TLegend * legend_;
0030 std::vector<TH1*> histoList_;
0031 static Color_t colors_[4];
0032 };
0033
0034 Color_t BaseNormalized::colors_[] = {kBlack, kRed, kBlue, kGreen};
0035
0036
0037
0038
0039
0040 class Normalized : BaseNormalized {
0041 public:
0042
0043 Normalized( const TString & name, const TString & title ) : BaseNormalized( name, title ) {}
0044
0045 void Add( TH1 * histo, const TString & name ) {
0046 histoList_.push_back(histo);
0047 legend_->AddEntry(histo, name);
0048 }
0049
0050 void Draw( const TString & xTitle = "", const TString & yTitle = "", const bool errors = false ) {
0051
0052
0053
0054 THStack * stack = new THStack(name_, title_);
0055
0056 int colorIndex = 0;
0057 if( !(histoList_.empty()) ) {
0058 std::vector<TH1*>::iterator histoIter = histoList_.begin();
0059 for( ; histoIter != histoList_.end(); ++histoIter, ++colorIndex ) {
0060 TH1 * histo = *histoIter;
0061 if(errors) histo->Sumw2();
0062
0063 if( colorIndex < 4 ) histo->SetLineColor(colors_[colorIndex]);
0064 else histo->SetLineColor(colorIndex);
0065
0066 TString normalizedHistoName(histo->GetName());
0067 TH1 * normalizedHisto = (TH1*)histo->Clone(normalizedHistoName+"clone");
0068 normalizedHisto->Scale(1/normalizedHisto->Integral());
0069 stack->Add(normalizedHisto);
0070 }
0071
0072
0073 canvas_->Draw();
0074 canvas_->cd();
0075 stack->Draw("nostack");
0076 stack->GetYaxis()->SetTitleOffset(1.2);
0077 stack->GetYaxis()->SetTitle(yTitle);
0078 stack->GetXaxis()->SetTitle(xTitle);
0079 stack->GetXaxis()->SetTitleColor(kBlack);
0080 stack->Draw("nostack");
0081 legend_->Draw("same");
0082
0083 canvas_->Update();
0084 canvas_->Draw();
0085 canvas_->ForceUpdate();
0086
0087 canvas_->Write();
0088
0089 }
0090 }
0091 };
0092
0093
0094
0095
0096
0097
0098
0099 class Merged : public BaseNormalized {
0100 public:
0101 Merged( const TString & name, const TString & title ) : BaseNormalized(name, title) {}
0102
0103 void Add( TH1 * histo, const TString & name, const double & scaleFactorValue = 0 ) {
0104 histoList_.push_back(histo);
0105 legend_->AddEntry(histo, name);
0106 scaleFactor.push_back(scaleFactorValue);
0107 }
0108 void Draw( const TString & xTitle = "", const TString & yTitle = "", const bool errors = false ) {
0109 canvas_->cd();
0110 if( !(histoList_.empty()) ) {
0111 TString mergedName = histoList_[0]->GetName();
0112 mergedName+="_Merged";
0113 TH1 * histo_Merged = (TH1*)histoList_[0]->Clone(mergedName);
0114 histo_Merged->Reset();
0115 std::vector<TH1*>::iterator histoIter = histoList_.begin();
0116 int scaleFactorIndex = 0;
0117 for( ; histoIter != histoList_.end(); ++histoIter, ++scaleFactorIndex ) {
0118 TH1 * histo = *histoIter;
0119 if( scaleFactor[scaleFactorIndex] != 0 ) histo_Merged->Add(histo, scaleFactor[scaleFactorIndex]/histo->Integral());
0120 else histo_Merged->Add(histo);
0121 }
0122 if(errors) histo_Merged->Sumw2();
0123 histo_Merged->GetXaxis()->SetTitle(xTitle);
0124 histo_Merged->GetYaxis()->SetTitleOffset(1.2);
0125 histo_Merged->GetYaxis()->SetTitle(yTitle);
0126 histo_Merged->Draw();
0127 canvas_->Draw();
0128 canvas_->Write();
0129 }
0130 }
0131 protected:
0132 std::vector<double> scaleFactor;
0133 };
0134
0135
0136
0137
0138 void drawKinematics( TFile ** inputFileList, int * inputScaleList, const TString & name, const TString & title, const TString & xTitle = "", const TString & yTitle = "", const TString & yTitleMerged = "", const TString & legPreText = "" ) {
0139 std::cout << "Drawing: " << name << std::endl;
0140 HistoFinder finder;
0141
0142 TH1F * histoPt_JPsi = (TH1F*)finder(name, inputFileList[0]);
0143 TH1F * histoPt_Y = (TH1F*)finder(name, inputFileList[1]);
0144 TH1F * histoPt_Z = (TH1F*)finder(name, inputFileList[2]);
0145
0146 Normalized resonancePt( name, title );
0147 resonancePt.Add(histoPt_JPsi, legPreText+"J/#Psi");
0148 resonancePt.Add(histoPt_Y, legPreText+"Y");
0149 resonancePt.Add(histoPt_Z, legPreText+"Z");
0150 resonancePt.Draw(xTitle, yTitle);
0151
0152 if( inputScaleList != 0 ) {
0153 Merged resonancePtMerged( name+"Merged", title+" merged" );
0154 resonancePtMerged.Add(histoPt_JPsi, "J/#Psi", inputScaleList[0]);
0155 resonancePtMerged.Add(histoPt_Y, "Y", inputScaleList[1]);
0156 resonancePtMerged.Add(histoPt_Z, "Z", inputScaleList[2]);
0157 resonancePtMerged.Draw(xTitle, yTitleMerged);
0158 }
0159 }
0160
0161
0162
0163
0164 void KinematicsComparison() {
0165 gROOT->SetBatch(true);
0166 gROOT->SetStyle("Plain");
0167
0168 TFile * inputFileList[3] = {
0169 new TFile("ResolutionAnalyzer_JPsi.root","READ"),
0170 new TFile("ResolutionAnalyzer_Y.root","READ"),
0171 new TFile("ResolutionAnalyzer_Z.root","READ")
0172 };
0173
0174 TFile * outputFile = new TFile("KinematicsComparison.root", "RECREATE");
0175
0176 int inputScaleList[3] = { 126629, 48122, 1667 };
0177
0178 outputFile->cd();
0179
0180
0181
0182 TDirectory * resonancesDir = outputFile->mkdir("Resonances");
0183 resonancesDir->cd();
0184
0185
0186 drawKinematics( inputFileList, inputScaleList, "RecoResonance_Pt", "resonance Pt", "pt(GeV)", "arbitrary units", "expected number of events in 3.3/pb" );
0187
0188 drawKinematics( inputFileList, inputScaleList, "RecoResonance_Eta", "resonance #eta", "#eta", "arbitrary units", "expected number of events in 3.3/pb" );
0189
0190 drawKinematics( inputFileList, inputScaleList, "RecoResonance_Phi", "resonance #phi", "#phi", "arbitrary units", "expected number of events in 3.3/pb" );
0191
0192
0193
0194 TDirectory * resonancesMuonsDir = outputFile->mkdir("ResonanceMuons");
0195 resonancesMuonsDir->cd();
0196
0197 drawKinematics( inputFileList, 0, "RecoResonanceMuons_Pt", "pt of muons from resonance", "pt(GeV)", "arbitrary units", "", "muons from " );
0198
0199 drawKinematics( inputFileList, 0, "RecoResonanceMuons_Eta", "#eta of muons from resonance", "#eta", "arbitrary units", "", "muons from " );
0200
0201 drawKinematics( inputFileList, 0, "RecoResonanceMuons_Phi", "#phi of muons from resonance", "#phi", "arbitrary units", "", "muons from " );
0202
0203
0204
0205 TDirectory * resonancesMuonsDeltasDir = outputFile->mkdir("ResonanceMuonsDeltas");
0206 resonancesMuonsDeltasDir->cd();
0207
0208 drawKinematics( inputFileList, 0, "DeltaRecoResonanceMuons_DeltaCotgTheta", "#Delta Cotg(#theta) of muons from resonance", "Cotg(#theta)", "arbitrary units", "", "muons from " );
0209
0210 drawKinematics( inputFileList, 0, "DeltaRecoResonanceMuons_DeltaTheta", "#Delta#theta of muons from resonance", "#Delta#theta", "arbitrary units", "", "muons from " );
0211
0212 drawKinematics( inputFileList, 0, "DeltaRecoResonanceMuons_DeltaEta", "|#Delta#eta| of muons from resonance", "|#Delta#eta|", "arbitrary units", "", "muons from " );
0213
0214 drawKinematics( inputFileList, 0, "DeltaRecoResonanceMuons_DeltaEtaSign", "#Delta#eta with sign of muons from resonance", "#Delta#eta", "arbitrary units", "", "muons from " );
0215
0216 drawKinematics( inputFileList, 0, "DeltaRecoResonanceMuons_DeltaPhi", "#Delta#phi of muons from resonance", "#Delta#phi", "arbitrary units", "", "muons from " );
0217
0218 drawKinematics( inputFileList, 0, "DeltaRecoResonanceMuons_DeltaR", "#Delta R of muons from resonance", "#Delta R", "arbitrary units", "", "muons from " );
0219 }