void Draw(const int &rebin=1) { Color_t _sampleColor[nSamples]; //_sampleColor[iHWW ] = kRed+1; //_sampleColor[iWW ] = kAzure-9; //_sampleColor[iZJets] = kGreen+2; //_sampleColor[iZTau] = kGreen+2; //_sampleColor[iTop ] = kYellow; //_sampleColor[iWZ ] = kAzure-2; //_sampleColor[iWJets] = kGray+1; //_sampleColor[iWJets] = kViolet-9; //_sampleColor[iWJets] = kCyan; _sampleColor[itH ] = kRed; _sampleColor[iWZ ] = kAzure-9; _sampleColor[iZZ ] = kAzure-5; _sampleColor[iWW ] = kAzure-1; _sampleColor[itt ] = kGray; _sampleColor[ittw ] = kOrange+7; _sampleColor[ittz ] = kOrange+1; _sampleColor[iwww ] = kSpring+9; _sampleColor[iwwz ] = kSpring+3; _sampleColor[iwzz ] = kSpring-7; _sampleColor[idyl ] = kViolet-1; _sampleColor[idy ] = kViolet-1; //setUpStyle(); if(!gPad) new TCanvas(); THStack* hstack = new THStack(); for (int i=0; i<nSamples; i++) { // in case the user doesn't set it if( !_hist[i] ) continue; _hist[i]->Rebin(rebin); _hist[i]->SetLineColor(_sampleColor[i]); // signal gets overlaid if (i == itH) continue; _hist[i]->SetFillColor(_sampleColor[i]); _hist[i]->SetFillStyle(1001); hstack->Add(_hist[i]); } if(_hist[itH]) _hist[itH]->SetLineWidth(3); if(_data) _data->Rebin(rebin); if(_data) _data->SetLineColor (kBlack); if(_data) _data->SetMarkerStyle(kFullCircle); if(_nostack) { for(int ihist=0;ihist<(int)_hist.size();ihist++) { _hist[ihist]->SetFillStyle(0); _hist[ihist]->SetLineWidth(2); } hstack->Draw("hist,nostack"); if(_hist[itH]) _hist[itH]->Draw("hist,same"); if(_data) _data->Draw("ep,same"); } else { hstack->Draw("hist"); if(_hist[itH]) _hist[itH]->Draw("hist,same"); if(_data) _data->Draw("ep,same"); } //hstack->SetTitle("CMS preliminary"); Float_t theMax = hstack->GetMaximum(); Float_t theMin = hstack->GetMinimum(); theMax = 1.0; //Float_t theMin = hstack->GetMinimum(); if (_hist[itH]) { if (_hist[itH]->GetMaximum() > theMax) theMax = _hist[itH]->GetMaximum(); if (_hist[itH]->GetMinimum() < theMin) theMin = _hist[itH]->GetMinimum(); } if (_data) { Float_t dataMax = GetMaximumIncludingErrors(_data); if (dataMax > theMax) theMax = dataMax; } if (gPad->GetLogy()) { hstack->SetMaximum(500 * theMax); hstack->SetMinimum(0.05); } else { hstack->SetMaximum(1.55 * theMax); } if(_breakdown) { THStackAxisFonts(hstack, "y", "entries"); hstack->GetHistogram()->LabelsOption("v"); } else { THStackAxisFonts(hstack, "x", TString::Format("%s [%s]",_xLabel.Data(),_units.Data())); if(_units.Sizeof() == 1) { THStackAxisFonts(hstack, "x", _xLabel.Data()); THStackAxisFonts(hstack, "y", "entries"); } else { THStackAxisFonts(hstack, "x", TString::Format("%s [%s]",_xLabel.Data(),_units.Data())); THStackAxisFonts(hstack, "y", TString::Format("entries / %.0f %s", _hist[iWZ]->GetBinWidth(0),_units.Data())); } } // total mess to get it nice, should be redone size_t j=0; TString higgsLabel = " tH x 100"; //if(_mass != 0) higgsLabel.Form(" m_{H}=%d",_mass); if(_data ) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _data, " data", "lp"); j++; } if(_hist[itH ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[itH ], higgsLabel, "l" ); j++; } if(_hist[iWZ ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[iWZ ], " WZ", "f" ); j++; } if(_hist[iZZ ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[iZZ ], " ZZ", "f" ); j++; } if(_hist[iWW ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[iWW ], " WW", "f" ); j++; } if(_hist[itt ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[itt ], " tt", "f" ); j++; } if(_hist[ittw ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[ittw ], " ttW", "f" ); j++; } if(_hist[ittz ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[ittz ], " ttZ", "f" ); j++; } if(_hist[iwww ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[iwww ], " WWW", "f" ); j++; } if(_hist[iwwz ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[iwwz ], " WWZ", "f" ); j++; } if(_hist[iwzz ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[iwzz ], " WZZ", "f" ); j++; } if(_hist[idy ]) { DrawLegend(xPos[j], 0.84 - yOff[j]*_yoffset, _hist[idy ], " Drell-Yan","f" ); j++; } //TLatex* luminosity = new TLatex(0.9, 0.815, TString::Format("L = %.1f fb^{-1}",_lumi)); TLatex* luminosity = new TLatex(0.9, 0.95, TString::Format("CMS Preliminary \\sqrt{s} = 8 TeV, L = %.1f fb^{-1}",_lumi)); luminosity->SetNDC(); luminosity->SetTextAlign(32); luminosity->SetTextFont(42); luminosity->SetTextSize(_tsize); luminosity->Draw("same"); // if(_extraLabel) _extraLabel->Draw("same"); // return hstack->GetHistogram(); }
THStack* BasePlot::GetStack(bool isLog) { THStack* hstack = new THStack(); float binWidth = 0; for (int i=0; i<nSamples; i++) if( _hist[i] && i != iHWW) { _hist[i]->SetLineColor(sampleColor[i]); _hist[i]->SetFillColor(sampleColor[i]); _hist[i]->SetFillStyle(1001); binWidth = _hist[i]->GetBinWidth(1); hstack->Add(_hist[i]); } for (size_t i=0; i<_autreHists.size(); i++) { _autreHists[i].second->SetLineColor(autreColors[i]); _autreHists[i].second->SetFillColor(autreColors[i]); _autreHists[i].second->SetFillStyle(1001); hstack->Add(_autreHists[i].second); } hstack->Draw("GOFF"); if(_prelim) hstack->SetTitle("CMS preliminary"); else hstack->SetTitle("CMS, #sqrt{s} = 7 TeV"); Float_t theMax = hstack->GetMaximum(); Float_t theMin = hstack->GetMinimum(); if (_hist[iHWW]) { if (_hist[iHWW]->GetMaximum() > theMax) theMax = _hist[iHWW]->GetMaximum(); if (_hist[iHWW]->GetMinimum() < theMin) theMin = _hist[iHWW]->GetMinimum(); } if (_data) { Float_t dataMax = GetMaximumIncludingErrors(_data); if (dataMax > theMax) theMax = dataMax; } int sampCount = GetSampCount(); float scaleBy = 1.35 + 0.2*(sampCount>6) + 0.2*(sampCount>10) + 0.2*(sampCount>14); // Min --- only need to change if log theMin = theMin==0?0.1:theMin/10; if(isLog) hstack->SetMinimum(theMin); // Max if (_myMax != -1) { hstack->SetMaximum(_myMax); } else if (isLog) { hstack->SetMaximum(pow(10,(log(theMax)/log(10)-log(theMin)/log(10)+1)*scaleBy+log(theMin)/log(10)-1)); } else { hstack->SetMaximum(scaleBy * theMax); } if(_breakdown) { THStackAxisFonts(hstack, "y", "entries"); hstack->GetHistogram()->LabelsOption("v"); } else { THStackAxisFonts(hstack, "x", TString::Format("%s [%s]",_xLabel.Data(),_units.Data())); THStackAxisFonts(hstack, "y", TString::Format("entries / %.1f %s", binWidth,_units.Data())); if(_units.Sizeof() == 1) { THStackAxisFonts(hstack, "x", _xLabel.Data()); // THStackAxisFonts(hstack, "y", "entries"); } } return hstack; }