Exemple #1
1
void ratioPlots( TCanvas* c1, TH1* h_r, TH1* h_i, 
		 string xTitle, string yTitle, 	string savePath, 
		 double fitMin=-100000, double fitMax=100000, bool doubleColFit=0 ){

	double xMaximum = h_r->GetXaxis()->GetBinUpEdge(h_r->GetXaxis()->GetLast());
	double xMinimum = h_r->GetXaxis()->GetBinLowEdge(h_r->GetXaxis()->GetFirst());
	double yMaximum;
	double yMinimum;

	h_i->Sumw2();
	h_r->Sumw2();

	TLine* line1 = new TLine(xMinimum,1,xMaximum,1);
	line1->SetLineColor(1);
	line1->SetLineWidth(2);
	line1->SetLineStyle(7);
	
	TF1* fpol1  = new TF1("fpol1", "pol1", fitMin, fitMax);	
	fpol1->SetLineColor(2);
	fpol1->SetLineWidth(3);
	fpol1->SetLineStyle(7);
	
	TH1* hRatio = (TH1*)h_r->Clone("clone_record");
	hRatio->Divide(h_i);
	yMaximum = hRatio->GetMaximum();
	yMinimum = hRatio->GetMinimum(0);
	hRatio->GetYaxis()->SetRangeUser(yMinimum/2.5,yMaximum+yMaximum/5);
	hRatio->SetXTitle(xTitle.c_str());
	hRatio->SetYTitle(yTitle.c_str());
	hRatio->SetLineColor(9); 
	hRatio->SetLineWidth(2); 
	hRatio->SetMarkerStyle(8); 
	hRatio->Draw("e");
	hRatio->Fit("fpol1", "L");
	line1->Draw("SAME");
	
	if(doubleColFit){
		double p0=fpol1->GetParameter(0);
		double p1=fpol1->GetParameter(1);
		double endPoint=double(fitMax*p1)+p0;
		double p1new=(endPoint-1)/(fitMax-fitMin);
		char fun[100], text[100];
		sprintf(fun,"x*(%f)+1",p1new);	
		sprintf(text,"Tangent: %f",p1new);	
		TF1* fnew = new TF1("fnew", fun, fitMin, fitMax);
		fnew->SetLineColor(2);
		fnew->SetLineWidth(3);
		fnew->Draw("SAME");
	
			
		TText* Title = new TText( fitMax/12, yMinimum, text);
		Title->SetTextColor(2);
		Title->SetTextSize(0.035);
		Title->Draw("SAME");
	}

	c1->SaveAs(savePath.c_str());
	c1->cd();
}
Exemple #2
0
void greyscale()
{
   TCanvas *c = new TCanvas("grey", "Grey Scale", 500, 500);
   c->SetBorderMode(0);

   Int_t   n = 200;   // tunable parameter
   Float_t n1 = 1./n;
   for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
         TBox *b = new TBox(n1*j, n1*(n-1-i), n1*(j+1), n1*(n-i));
         Float_t grey = Float_t(i*n+j)/(n*n);
         b->SetFillColor(TColor::GetColor(grey, grey, grey));
         b->Draw();
      }
   }
   TPad *p = new TPad("p","p",0.3, 0.3, 0.7,0.7);
   const char *guibackground = gEnv->GetValue("Gui.BackgroundColor", "");
   p->SetFillColor(TColor::GetColor(guibackground));
   p->Draw();
   p->cd();
   TText *t = new TText(0.5, 0.5, "GUI Background Color");
   t->SetTextAlign(22);
   t->SetTextSize(.09);
   t->Draw();

   c->SetEditable(kFALSE);
}
Exemple #3
0
void PaintOverflow(TH1 *h)
{
   // This function paint the histogram h with an extra bin for overflows

   char* name  = h->GetName();
   char* title = h->GetTitle();
   Int_t nx    = h->GetNbinsX()+1;
   Double_t x1 = h->GetBinLowEdge(1);
   Double_t bw = h->GetBinWidth(nx);
   Double_t x2 = h->GetBinLowEdge(nx)+bw;

   // Book a temporary histogram having ab extra bin for overflows
   TH1F *htmp = new TH1F(name, title, nx, x1, x2);

   // Fill the new hitogram including the extra bin for overflows
   for (Int_t i=1; i<=nx; i++) {
      htmp->Fill(htmp->GetBinCenter(i), h->GetBinContent(i));
   }

   // Fill the underflows
   htmp->Fill(x1-1, h->GetBinContent(0));

   // Restore the number of entries
   htmp->SetEntries(h->GetEntries());

   // Draw the temporary histogram
   htmp->Draw();
   TText *t = new TText(x2-bw/2,h->GetBinContent(nx),"Overflow");
   t->SetTextAngle(90);
   t->SetTextAlign(12);
   t->SetTextSize(0.03);;
   t->Draw();
}
Exemple #4
0
void highlight1()
{
   TCanvas *ch = new TCanvas("ch", "ch", 0, 0, 700, 500);
   const Int_t n = 500;
   Double_t x[n], y[n];
   TH1F *h[n];

   for (Int_t i = 0; i < n; i++) {
      h[i] = new TH1F(TString::Format("h_%02d", i), "", 100, -3.0, 3.0);
      // in practice gaus need reset parameters
      h[i]->FillRandom("gaus", 1000);
      h[i]->Fit("gaus", "Q");
      h[i]->SetMaximum(250); // for n > 200
      x[i] = i;
      y[i] = h[i]->GetFunction("gaus")->GetParameter(2);
   }

   TGraph *g = new TGraph(n, x, y);
   g->SetMarkerStyle(6);
   for (Int_t i = 0; i < n; i++) g->AddHighlight(i, h[i]);
   g->Draw("AP");
   g->SetHighlight();

   TPad *ph = new TPad("ph", "ph", 0.3, 0.4, 1.0, 1.0);
   ph->SetFillColor(kBlue - 10);
   ph->Draw();
   ph->cd();
   TText *info = new TText(0.5, 0.5, "please move the mouse over the graph");
   info->SetTextAlign(22);
   info->Draw();
   ch->cd();

   TGraph::SetHighlightPad(ph);
}
Exemple #5
0
void CutFlow::standardCutFlowPlot(TH1D* data, THStack *hs, AllSamples samples, Variable variable){
	//Style
	TdrStyle style;
	style.setTDRStyle();

	//draw histos to files
	TCanvas *c1 = new TCanvas("Plot","Plot",900, 600);

	data->Draw();
	hs->Draw("hist");

	setBinLabels(hs, data);

	if(Globals::addHashErrors){
		TH1D* hashErrs = hashErrors(samples, variable);
		hashErrs->Draw("same e2");
	}

	data->Draw("E same");
	data->SetMarkerStyle(20);
	data->SetMarkerSize(0.5);

	hs->SetMaximum(data->GetBinContent(data->GetMaximumBin())*1.3);
	hs->GetXaxis()->SetLimits(variable.minX, variable.maxX);
	hs->GetXaxis()->SetTitle(variable.xTitle); hs->GetXaxis()->SetTitleSize(0.05);
	hs->GetYaxis()->SetTitle("Number of Events");hs->GetYaxis()->SetTitleSize(0.05);

	TLegend* leg = legend(samples);
	leg->Draw();

	TText* textChan = doChan(0.12,0.96);
	textChan->Draw();
	TText* textPrelim = doPrelim(0.58,0.96);
	textPrelim->Draw();

	c1->SetLogy();
	c1->SaveAs("Plots/ControlPlots/"+objName+"/Log/"+variable.name+".png");
	c1->SaveAs("Plots/ControlPlots/"+objName+"/Log/"+variable.name+".pdf");

	delete c1;
	delete leg;
	delete textChan;
	delete textPrelim;
}
Exemple #6
0
void	drift_chisq()
{
	int	i;

	events = (TTree*)f.Get("events");

	c1.Divide(2, 2, 0.01, 0.02);
	c2.Divide(2, 2, 0.01, 0.02);

	i = 0;
	c1.cd(++i);
	makehist("t3X", 2);
	c1.cd(++i);
	makehist("t4X", 2);
	c1.cd(++i);
	makehist("t3Y", 2);
	c1.cd(++i);
	makehist("t4Y", 2);

	i = 0;
	c2.cd(++i);
	makehist("t3X", 1);
	c2.cd(++i);
	makehist("t4X", 1);
	c2.cd(++i);
	makehist("t3Y", 1);
	c2.cd(++i);
	makehist("t4Y", 1);

	TText	*t;
	TTree	*info = (TTree*)f.FindObjectAny("info");
	TString	info_str = get_info_str(info);
	c1.cd(0);
	t = new TText(0.005, 0.005, info_str);
	t->SetTextSize(0.02);
	t->Draw();
	c2.cd(0);
	t = new TText(0.005, 0.005, info_str);
	t->SetTextSize(0.02);
	t->Draw();

	c1.Show();
	c2.Show();
}
Exemple #7
0
void do2DPlots(bool muon, TString variable, TString ytitle){

	TString leptonFolder;
	if(muon == true){
		leptonFolder = "MuonMET/";
	}else{
		leptonFolder = "ElectronMET/";
		}	
		
  	setTDRStyle();
  	gStyle->SetPalette(1);

	TString dir = "rootFilesV4/central/";
	TFile* tt_file = new TFile(dir + sample+"_19584pb_PFElectron_PFMuon_PF2PATJets_PFMET.root");

cout << "Getting histo: " << "Binning/"+leptonFolder+variable+"/GenMET_vs_RecoMET"<<endl;
	TH2D* tt_2d = (TH2D*) tt_file->Get("Binning/"+leptonFolder+variable+"/GenMET_vs_RecoMET_2btags");
	TH2D* tt_2d_3b = (TH2D*) tt_file->Get("Binning/"+leptonFolder+variable+"/GenMET_vs_RecoMET_3btags");
	TH2D* tt_2d_4b = (TH2D*) tt_file->Get("Binning/"+leptonFolder+variable+"/GenMET_vs_RecoMET_4orMoreBtags");

	tt_2d->Add(tt_2d_3b);
	tt_2d->Add(tt_2d_4b);

	tt_2d->Rebin2D(5,5);
  	tt_2d->GetYaxis()->SetTitle(ytitle);
  	tt_2d->GetXaxis()->SetTitle("Gen MET (GeV)");
	tt_2d->GetYaxis()->SetTitleOffset(1.8);
	tt_2d->GetXaxis()->SetTitleOffset(1.5);

        TCanvas *c= new TCanvas("c","c",10,10,800,600);
	tt_2d->Draw("COLZ");
			
	int bin[5] = {25, 45, 70, 100, 150};//MET
	for(int i = 0; i < 5; i++){
	TLine *line = new TLine(bin[i],0,bin[i],300);
	TLine *liney = new TLine(0,bin[i],300,bin[i]);
	//TLine *line = new TLine(bin[i],0,bin[i],500);
	//TLine *liney = new TLine(0,bin[i],500,bin[i]);
	line->SetLineWidth(2);
	liney->SetLineWidth(2);
	liney->Draw();
	line->Draw();
	}
	
	TText* textPrelim = doPrelim(0.2,0.96);
	textPrelim->Draw();
	
  	TString plotName("plots/"+leptonFolder);
        plotName += sample+"_"+variable;
        plotName += "_2btags.pdf";
 
  c->SaveAs(plotName);
  delete c;


}
Exemple #8
0
//______________________________________________________________________________
void DrawPeriod(int runmin, int runmax, int run1, int run2, double ymin, double ymax, const char* label)
{
  if ( run1 < runmin || run1 > runmax || run2 < runmin || run2 > runmax ) return;

  TBox* b = new TBox(run1,ymin,run2,ymax);
  b->SetFillColor(5);
  b->Draw();
  TText* text = new TText((run1+run2)/2.0,ymax*0.6,label);
  text->SetTextAlign(22);
  text->SetTextSize(0.02);
  text->Draw();
}
Exemple #9
0
void Plots2D::standardPlot(TH2D* ttbar, Variable variable){
	//Style
	TdrStyle style;
	style.setTDRStyle();
	gStyle->SetPalette(1);
	gStyle->SetPadRightMargin(0.12);
	//draw histos to files
	TCanvas *c1 = new TCanvas("Plot","Plot",900, 800);

	ttbar->Draw("COLZ");

//	ttbar->SetMaximum(ttbar->GetBinContent(ttbar->GetMaximumBin())*1.3);
	ttbar->SetAxisRange(variable.minX, variable.maxX, "X");
	ttbar->SetAxisRange(variable.minX, variable.maxX, "Y");
	ttbar->GetXaxis()->SetTitle("Gen " +variable.xTitle);
	ttbar->GetXaxis()->SetTitleSize(0.05);
	ttbar->GetYaxis()->SetTitle("Reco " +variable.xTitle);
	ttbar->GetYaxis()->SetTitleSize(0.05);

	for(unsigned int i = 0; i < bins.size(); i++){
 	TLine *line = new TLine(bins[i],variable.minX,bins[i], variable.maxX);
 	TLine *liney = new TLine(variable.minX,bins[i], variable.maxX, bins[i]);
	line->SetLineWidth(2);
	liney->SetLineWidth(2);
	liney->Draw();
	line->Draw();
	}

	TText* textChan = doChan(0.12,0.96);
	textChan->Draw();
	TText* textPrelim = doPrelim(0.58,0.96);
	textPrelim->Draw();

	c1->SaveAs("Plots/ControlPlots/2DPlots/"+variable.name+".png");
	c1->SaveAs("Plots/ControlPlots/2DPlots/"+variable.name+".pdf");

	delete c1;
	delete textChan;
	delete textPrelim;
}
Exemple #10
0
void postprocess(TCanvas* c2, const char* name, Int_t rWrite, Int_t rPerformance) {

        if (rPerformance){

                TLatex *alice = new TLatex(0.65,0.47,"Performance");
                alice->SetNDC();
                alice->SetTextColor(myDarkRed);
                alice->SetTextFont(42);
                alice->SetTextSize(0.05);
                alice->SetLineWidth(2);
                alice->Draw();

                TLatex *alice2 = new TLatex(0.62,0.41,"LHC10h - Pass2");
                alice2->SetNDC();
                alice2->SetTextColor(myDarkRed);
                alice->SetTextFont(42);
                alice2->SetTextSize(0.05);
                alice2->SetLineWidth(2);
                alice2->Draw();

                TText *date = new TText(0.68,0.35,cStamp2);
                date->SetNDC();
                date->SetTextFont(42);
                date->SetTextSize(0.04);
                date->Draw();

                //Acquire canvas proportions
                Double_t AliLogo_LowX = 0.67;
                Double_t AliLogo_LowY = 0.53;
                Double_t AliLogo_Height = 0.22;
                //ALICE logo is a png file that is 821x798 pixels->should be wider than a square
                Double_t AliLogo_Width  = (821./798.) * AliLogo_Height * gPad->GetWh() / gPad->GetWw();

                TPad *myPadLogo = new TPad("myPadLogo", "Pad for ALICE Logo",AliLogo_LowX,AliLogo_LowY,AliLogo_LowX+AliLogo_Width,AliLogo_LowY+AliLogo_Height);
                //    myPadLogo->SetFillColor(2); // color to first figure out where is the pad then comment !
                myPadSetUp(myPadLogo,0,0,0,0);
                //myPadLogo->SetFixedAspectRatio(1);
                myPadLogo->Draw();
                myPadLogo->cd();
                TASImage *myAliceLogo = new TASImage("alice_logo_transparent.png");
                myAliceLogo->Draw();
        }

        if (rWrite == 1)
                c2->SaveAs(Form("%s.png",name));

        if (rWrite == 2)
                c2->SaveAs(Form("%s.eps",name));

}
void fill_with_text(TGraph *real, TGraph *down, TGraph *up, TVirtualPad *can, int scantype, std::string scanx = "") {
  can->cd();
  float xpos_of_text = 0.22;
  TLegend* this_leg = new TLegend(xpos_of_text,0.6,0.38,0.75);
  //TLegend* this_leg = new TLegend(xpos_of_text,0.55,0.45,0.75,"n_{jets} #geq 3"); // this was the style of the paper. 
  this_leg->SetFillColor(0);
  this_leg->SetBorderSize(0);
  this_leg->SetTextSize(0.035);
  //this_leg->SetTextSize(0.04); // paper style. 
  if(scantype==PlottingSetup::SMS||scantype==PlottingSetup::GMSB) {
    //this_leg->AddEntry(real,"#sigma^{prod} = #sigma^{NLO-QCD}" , "l");
    //this_leg->AddEntry(up,"#sigma^{prod} = 3 #times #sigma^{NLO-QCD}" , "l");
    //this_leg->AddEntry(down,"#sigma^{prod} = 1/3 #times #sigma^{NLO-QCD}" , "l");
    this_leg->AddEntry(real,"#sigma^{NLO-QCD}" , "l");
    this_leg->AddEntry(up,"3 #times #sigma^{NLO-QCD}" , "l");
    this_leg->AddEntry(down,"1/3 #times #sigma^{NLO-QCD}" , "l");
  } else {
    write_warning(__FUNCTION__,"Not implemented yet for mSUGRA");
  }
    
  this_leg->Draw();
  TText *title = write_text(xpos_of_text+0.005,0.52,"JZB");
  title->SetTextSize(0.04);
  title->SetTextAlign(13);
  title->SetTextFont(62);
  title->Draw();
  
  write_SMS_text( scantype, scanx, xpos_of_text );
  
//  //string legT5zz="pp #rightarrow  #tilde{g} #tilde{g}, #tilde{g} #rightarrow 2j + #chi^{0}_{1}, #chi^{0}_{1} #rightarrow Z + #tilde{G}";
//  string legT5zz="pp #rightarrow  #tilde{g} #tilde{g}, #tilde{g} #rightarrow 2j + #chi^{0}_{2}, #chi^{0}_{2} #rightarrow Z #chi^{0}_{1}";
//  string legT5zzl2="m(#tilde{q}) >> m(#tilde{g}), x = "+scanx;
//  string legT5zzl3=" GMSB";
//  TText *title = write_text(xpos_of_text,0.85,legT5zz);
//  title->SetTextAlign(11);
//  title->SetTextSize(0.035);
//  if(scantype!=PlottingSetup::mSUGRA) title->Draw("same");
//  TText *title2 = write_text(xpos_of_text,0.79,legT5zzl2);
//  title2->SetTextAlign(11);
//  title2->SetTextSize(0.035);
//  if(scantype!=PlottingSetup::mSUGRA) title2->Draw("same");
//  TText *title3 = write_text(0.40,0.79,legT5zzl3);
//  title3->SetTextAlign(11);
//  title3->SetTextSize(0.035);
//  title3->SetTextColor(kRed);
////  if(scantype==PlottingSetup::GMSB) title3->Draw("same");
  DrawPrelim();
  draw_diagonal_xchange( scantype, scanx );
}
//--------------------------------------------------------------------------------------------------
void overlayFrame(TString text)
{
  // Overlay a linear frame from user coordinates (0 - 1, 0 - 1) and put the frame text

  // create new transparent pad for the text
  TPad *transPad = new TPad("transPad","Transparent Pad",0,0,1,1);
  transPad->SetFillStyle(4000);
  transPad->Draw();
  transPad->cd();

  // overlay the text in a well defined frame
  TText *plotText = new TText(0.01,0.01,text.Data());
  plotText->SetTextSize(0.04);
  plotText->SetTextColor(kBlue);
  plotText->Draw();

  return;
}
void write_SMS_text(int scantype, std::string& scanx, float xpos = 0.22 ) {
  string legT5zz="pp #rightarrow  #tilde{g} #tilde{g}, #tilde{g} #rightarrow 2j + #chi^{0}_{2}, #chi^{0}_{2} #rightarrow Z #chi^{0}_{1}";
  if ( scantype==PlottingSetup::GMSB) legT5zz="pp #rightarrow  #tilde{g} #tilde{g}, #tilde{g} #rightarrow 2j + #chi^{0}_{1}, #chi^{0}_{1} #rightarrow Z #tilde{G}";

  string legT5zzl2="m(#tilde{q}) >> m(#tilde{g})";
  if (scantype==PlottingSetup::SMS) legT5zzl2 += ", x = "+scanx;
  string legT5zzl3=" GMSB";

  TText *title = write_text(xpos,0.85,legT5zz);
  title->SetTextAlign(11);
  title->SetTextSize(0.035);
  if(scantype!=PlottingSetup::mSUGRA) title->Draw("same");
  TText *title2 = write_text(xpos,0.79,legT5zzl2);
  title2->SetTextAlign(11);
  title2->SetTextSize(0.035);
  if(scantype!=PlottingSetup::mSUGRA) title2->Draw("same");
  TText *title3 = write_text(0.40,0.79,legT5zzl3);
  title3->SetTextAlign(11);
  title3->SetTextSize(0.035);
  title3->SetTextColor(kRed);
  //  if(scantype==PlottingSetup::GMSB) title3->Draw("same");
}
Exemple #14
0
void hlHisto4()
{
   TCanvas *c1 = new TCanvas("c1", "", 0, 0, 600, 400);
   TF1 *f1 = new TF1("f1", "x*gaus(0) + [3]*abs(sin(x)/x)", -50.0, 50.0);
   f1->SetParameters(20.0, 4.0, 1.0, 20.0);
   TH1F *h1 = new TH1F("h1", "Test random numbers", 200, -50.0, 50.0);
   h1->FillRandom("f1", 100000);
   h1->Draw();
   h1->Fit(f1, "Q");
   gStyle->SetGridColor(kGray);
   c1->SetGrid();

   TText *info = new TText(0.0, h1->GetMaximum()*0.7, "please move the mouse over the frame");
   info->SetTextSize(0.04);
   info->SetTextAlign(22);
   info->SetTextColor(kRed-1);
   info->SetBit(kCannotPick);
   info->Draw();
   c1->Update();

   h1->SetHighlight();
   c1->HighlightConnect("HighlightZoom(TVirtualPad*,TObject*,Int_t,Int_t)");
}
Exemple #15
0
void doPlotsBtag_Log(bool logPlot){
setTDRStyle();

double lumi = 5800;
//stuff to choose
//bool logPlot = false; //true for log plot
int rebinFact = 1;

//isolation selection
//TString Isolation = "QCD No Iso/";
TString Isolation = "Ref selection/";
//TString Isolation = "QCD mu+jets PFRelIso/";
//TString Isolation = "QCD non iso mu+jets/";

TString Systematic = "central";

// number of btags
TString Nbtags = "2btags";  //standard  "2btags" , qcd "0btag"

//choose object
TString Obj = "";
//TString Obj = "MET/";

//muon variables
const int N = 2;
TString Variable;
TString Variables[N] = {"N_BJets", "N_BJets_reweighted"};
double MinXs[N] = {-0.5,-0.5};
double MaxXs[N] = {7.5,7.5};
TString XTitles[N] = {"B-tag Multiplicity", "B-tag Multiplicity"};



//loop over variables
for(int i = 0; i<2; i++){
double MinX = MinXs[i];
double MaxX = MaxXs[i];
Variable = Variables[i];
TString Xtitle = XTitles[i];

//Data
TH1D* data = getSample("SingleMu", 1, Obj, Variable, Isolation, rebinFact, "central");

//MC
TH1D* tt = getSample("TTJet", lumi*225.2/6920475, Obj, Variable, Isolation, rebinFact, Systematic);

TH1D* wjets = getSample("W1Jet", lumi*37509/57708550, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* w2jets = getSample("W2Jets", lumi*1750.0/34041404, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* w3jets = getSample("W3Jets", lumi*519.0/15536443, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* w4jets = getSample("W4Jets", lumi*214.0/13370904, Obj, Variable, Isolation, rebinFact, Systematic);

TH1D* zjets = getSample("DY1JetsToLL", lumi*5745.25/30457954, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* z2jets = getSample("DY2JetsToLL", lumi*181.0/21835749, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* z3jets = getSample("DY3JetsToLL", lumi*51.1/11010628, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* z4jets = getSample("DY4JetsToLL", lumi*23.04/6391785, Obj, Variable, Isolation, rebinFact, Systematic);

TH1D* qcd = getSample("QCD_Pt-15to20_MuEnrichedPt5",     lumi*34679.3/8500505, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd2 = getSample("QCD_Pt-20to30_MuEnrichedPt5",   lumi*2.87e8 * 0.0065/8486893, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd3 = getSample("QCD_Pt-30to50_MuEnrichedPt5",   lumi*6.609e7 * 0.0122/8928999, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd4 = getSample("QCD_Pt-50to80_MuEnrichedPt5",   lumi*8082000.0 * 0.0218/7256011, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd5 = getSample("QCD_Pt-80to120_MuEnrichedPt5",  lumi*1024000.0 * 0.0395/9030624, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd6 = getSample("QCD_Pt-120to170_MuEnrichedPt5", lumi*157800.0 * 0.0473/8500505, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd7 = getSample("QCD_Pt-170to300_MuEnrichedPt5", lumi*34020.0 * 0.0676/7662483, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd8 = getSample("QCD_Pt-300to470_MuEnrichedPt5", lumi*1757.0 * 0.0864/7797481, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd9 = getSample("QCD_Pt-470to600_MuEnrichedPt5", lumi*115.2 * 0.1024/2995767, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd10 = getSample("QCD_Pt-800to1000_MuEnrichedPt5",lumi*3.57 * 0.1033/4047142, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd11 = getSample("QCD_Pt-1000_MuEnrichedPt5",     lumi*0.774 * 0.1097/3807263, Obj, Variable, Isolation, rebinFact, Systematic);

TH1D* top_t = getSample("T_t-channel", lumi*56.4/3757707, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* top_tw = getSample("T_tW-channel", lumi*11.1/497395, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* top_s = getSample("T_s-channel", lumi*3.79/249516, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* tbar_t = getSample("Tbar_t-channel", lumi*30.7/1934817, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* tbar_tw = getSample("Tbar_tW-channel", lumi*11.1/493239, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* tbar_s = getSample("Tbar_s-channel", lumi*1.76/139948, Obj, Variable, Isolation, rebinFact, Systematic);

//make combined top and single top template
TH1D* sing_top = (TH1D*)top_t->Clone("top");
sing_top->Add(top_tw);sing_top->Add(top_s); sing_top->Add(tbar_t); sing_top->Add(tbar_tw);sing_top->Add(tbar_s);

zjets->Add(z2jets);
zjets->Add(z3jets);
zjets->Add(z4jets);  

wjets->Add(w2jets);
wjets->Add(w3jets);
wjets->Add(w4jets);

//make combined top and single top template
TH1D* qcd_all = (TH1D*)qcd->Clone("qcd_all");
qcd_all->Add(qcd2);
qcd_all->Add(qcd3);
qcd_all->Add(qcd4);
qcd_all->Add(qcd5);
qcd_all->Add(qcd6);
qcd_all->Add(qcd7);
qcd_all->Add(qcd8);
qcd_all->Add(qcd9);
qcd_all->Add(qcd10);
qcd_all->Add(qcd11);
  
THStack *hs = new THStack("hs","test");

qcd_all->SetLineColor(kBlack);
zjets->SetLineColor(kBlack);
wjets->SetLineColor(kBlack);	
sing_top->SetLineColor(kBlack);
tt->SetLineColor(kBlack);	

  hs->Add(qcd_all);
  hs->Add(zjets);
  hs->Add(wjets);
  hs->Add(sing_top);
  hs->Add(tt);

  //draw histos to files
  TCanvas *c1 = new TCanvas("Plot","Plot",900, 600);
		
  hs->SetMaximum(data->GetBinContent(data->GetMaximumBin())*1.2);
  hs->SetMinimum(1.);
  
  hs->Draw();
  data->Draw("E same");
  data->SetMarkerStyle(20);

//events:
cout << "ttbar: " << tt->Integral() << endl;
cout << "data: " << data->Integral() << endl;
  
  if(logPlot == true){
  hs->GetXaxis()->SetLimits(MinX, MaxX);
  }else{
  hs->GetXaxis()->SetLimits(MinX, 4.5);
  }
  
  hs->GetXaxis()->SetTitle(Xtitle); hs->GetXaxis()->SetTitleSize(0.05);
  hs->GetYaxis()->SetTitle("Number of Events");hs->GetYaxis()->SetTitleSize(0.05);
  
  
  	TLegend *tleg2;
	tleg2 = new TLegend(0.7,0.7,0.8,0.9);
	tleg2->SetTextSize(0.04);
	tleg2->SetBorderSize(0);
	tleg2->SetFillColor(10);
	tleg2->AddEntry(data , "2012 data", "lpe");
	tleg2->AddEntry(tt , "t#bar{t}", "f");
	tleg2->AddEntry(sing_top, "single top", "f");
	tleg2->AddEntry(wjets , "w+jets", "f");
	tleg2->AddEntry(zjets , "z+jets", "f");
	tleg2->AddEntry(qcd_all , "QCD", "f");
	
	//tleg2->AddEntry(singtEff, "single-t"      , "l");
	//tleg2->AddEntry(singtwEff, "single-tW"      , "l");
 	tleg2->Draw("same");	
	
	if(logPlot == true){
  	TText* textPrelim = doPrelim(0.12,0.96, "#geq 0 btags");
	textPrelim->Draw();
  	}else{
	TText* textPrelim = doPrelim(0.2,0.96, "");
	textPrelim->Draw();
	}
	
  if(logPlot ==true){
  c1->SetLogy();
  }	
  
  TString plotName("Plots/TTbarPlusVarAnalysis/Nbtags/");
  
  if(logPlot ==true){
    plotName += Variable+"_Log";  
  }else{
    plotName += Variable;  
  }
 
 
  c1->SaveAs(plotName+".pdf");
  c1->SaveAs(plotName+".png");
  delete c1;
  
  }
  	
}
void EMCDistribution(TString gain = "CALIB", bool log_scale = false)
{
  TText *t;
  TCanvas *c1 = new TCanvas(
      "EMCDistribution_" + gain + TString(log_scale ? "_Log" : "") + cuts,
      "EMCDistribution_" + gain + TString(log_scale ? "_Log" : "") + cuts, 1800,
      1000);
  c1->Divide(8, 8, 0., 0.01);
  int idx = 1;
  TPad *p;

  for (int iphi = 8 - 1; iphi >= 0; iphi--)
  {
    for (int ieta = 0; ieta < 8; ieta++)
    {
      p = (TPad *) c1->cd(idx++);
      c1->Update();

      p->SetLogy();
      p->SetGridx(0);
      p->SetGridy(0);

      TString hname = Form("hEnergy_ieta%d_iphi%d", ieta, iphi) + TString(log_scale ? "_Log" : "");

      TH1 *h = NULL;

      if (log_scale)
        h = new TH1F(hname,
                     Form(";Calibrated Tower Energy Sum (GeV);Count / bin"), 300,
                     5e-3, 3096);
      else
        //            h = new TH1F(hname,
        //                Form(";Calibrated Tower Energy Sum (GeV);Count / bin"), 196,
        //                1900, 2096);
        h = new TH1F(hname,
                     Form(";Calibrated Tower Energy Sum (GeV);Count / bin"), 596,
                     -96, 500);

      h->SetLineWidth(0);
      h->SetLineColor(kBlue + 3);
      h->SetFillColor(kBlue + 3);
      h->GetXaxis()->SetTitleSize(.09);
      h->GetXaxis()->SetLabelSize(.08);
      h->GetYaxis()->SetLabelSize(.08);

      if (log_scale)
        QAHistManagerDef::useLogBins(h->GetXaxis());

      T->Draw(
          "TOWER_" + gain + "_CEMC[].get_energy_power_law_exp()>>" + hname,
          Form(
              "TOWER_%s_CEMC[].get_bineta()==%d && TOWER_%s_CEMC[].get_binphi()==%d",
              gain.Data(), ieta, gain.Data(), iphi),
          "");

      TText *t = new TText(.9, .9, Form("Col%d Row%d", ieta, iphi));
      t->SetTextAlign(33);
      t->SetTextSize(.15);
      t->SetNDC();
      t->Draw();

      //          return;
    }
  }

  SaveCanvas(c1,
             TString(_file0->GetName()) + TString("_DrawPrototype3EMCalTower_") + TString(c1->GetName()), false);
}
Exemple #17
0
void Plot::FitSignal(int mode, int fitMode) {

	const int nPar = 6;
	TRandom ran;

	if(mode==0) {
		gStyle->SetOptLogy(1);
	} else {
		gStyle->SetOptLogy(0);
	}
	gStyle->SetOptStat(0);
	gStyle->SetOptTitle(0);
	const float limitBinSize = 2.0; // **** bin size here
	TCanvas* c = NewCanvas();
	c->Divide(1,2);

	gROOT->cd();
	TH1F* cc = new TH1F("CCSignal","CC Signal",500,0.0,1000.0);
	TH1F* ccBg = new TH1F("CCBgFit","CC Bg Fit",500,0.0,1000.0);
	TH1F* ccBgErr = new TH1F("CCBgErr","CC Bg Err",500,0.0,1000.0);
	TH1F* ccBgP = new TH1F("CCBgPlus","CC Bg Plus",500,0.0,1000.0);
	TH1F* ccBgM = new TH1F("CCBgMinus","CC Bg Minus",500,0.0,1000.0);
	TH1F* cp = new TH1F("CPSignal","CP Signal",500,0.0,1000.0);
	TH1F* cpBg = new TH1F("CPBgFit","CP Bg Fit",500,0.0,1000.0);
	TH1F* cpBgErr = new TH1F("CPBgErr","CP Bg Err",500,0.0,1000.0);
	TH1F* cpBgP = new TH1F("CPBgPlus","CP Bg Plus",500,0.0,1000.0);
	TH1F* cpBgM = new TH1F("CPBgMinus","CP Bg Minus",500,0.0,1000.0);
	TMatrixD matrix(nPar,nPar);

	fd->cd();

	TH1F* hInt,*hBgInt;
	char fitname[100];
	for(int ind=0; ind<2; ind++) {
		if(debug) printf("starting ind %i\n",ind);
		c->cd(ind+1);
		gStyle->SetOptLogy(1);
		printf("Starting %i ######################################\n",ind);

		TH1F* h;
		//char cind[20];
		//char handle[100];
		//sprintf(handle,"side_1exp_%02i_%02i_%02i",ind,mode,fitMode);
		TF1* fits[4];
		//TF1* dpx[4];
		if(debug) printf("looking for h %i\n",int(fd));
		if(ind==0) {
			h = (TH1F*)fd->FindObjectAny("pair_mass_2GeV1");
		} else if(ind==1) {
			h = (TH1F*)fd->FindObjectAny("pair_mass_2GeV3");
		}
		if(debug) printf("new h %i\n",int(h));

		if(debug) printf("new fit\n");
		sprintf(fitname,"hfit_%1i",ind);
		fits[ind] = new TF1(fitname,"([0]*pow((x-30.0),[1])+[3]*pow((x-30.0),0.2))*([2]*exp(-[2]*(x-30.0))+[4]*[5]*exp(-[5]*(x-30.0)))",30.0,500.0);
		//fits[ind] = new TF1(fitname,"([0]*((1-[3])*pow((x-30.0),[1])+[3]*pow((x-30.0),0.2)))*(exp(-[2]*(x-30.0))+[4]*exp(-[5]*(x-30.0)))",30.0,500.0);
		fits[ind]->SetParameter(0,0.0004);
		fits[ind]->SetParameter(1,2);
		fits[ind]->SetParameter(2,0.02);
		fits[ind]->SetParameter(3,0.005);
		//fits[ind]->SetParameter(3,0.5);
		fits[ind]->SetParameter(4,1.005);
		fits[ind]->SetParameter(5,0.05);

		float llim = 30.0;
		h->Fit(fits[ind],"LN","",llim,1000.0);

		double par[20],parMin[20],fval,fvalMin;
		for(int i=0; i<nPar; i++) parMin[i] = fits[ind]->GetParameter(i);

		gMinuit->Eval(nPar,0,fvalMin,parMin,0);
		//printf("got back %10.5f\n",fvalMin);

		// save the fit results in a histogram, for limit program
		for(int ibin=16; ibin<250; ibin++) {
			float xx = h->GetBinCenter(ibin);
			float yy = fits[ind]->Eval(xx);
			if(ind==0) {
				cc->SetBinContent(ibin,h->GetBinContent(ibin));
				ccBg->SetBinContent(ibin,yy);
				ccBgErr->SetBinContent(ibin,0.0);
				ccBgP->SetBinContent(ibin,0.0);
				ccBgM->SetBinContent(ibin,99999.0);
			} else {
				cp->SetBinContent(ibin,h->GetBinContent(ibin));
				cpBg->SetBinContent(ibin,yy);
				cpBgErr->SetBinContent(ibin,0.0);
				cpBgP->SetBinContent(ibin,0.0);
				cpBgM->SetBinContent(ibin,99999.0);
			}
		}

		//vary the parameters to find an error envelope
		double par2[20],fval2=1e10;
		int pslim = (ind==0?25000:150000);
		for(int ips=0; ips<pslim; ips++) {
			if(ips%10000==0) printf("Processing %d\n",ips);
			for(int i=0; i<nPar; i++) {
				par[i] = parMin[i];
			}
			for(int i=0; i<nPar; i++) {
				//int i = (ips%2==0?0:3);
				par[i] = parMin[i]+(2.0*(ran.Uniform()-0.5))*fits[ind]->GetParError(i);
			}
			fval = 0.0;
			gMinuit->Eval(nPar,0,fval,par,0);
			if((fval-fvalMin)<1.0) {
				printf("Found nearby min %10.5f\n",fval-fvalMin);
				float eOld,eNew;
				for(int ibin=16; ibin<250; ibin++) {
					float xx = h->GetBinCenter(ibin);
					for(int i=0; i<nPar; i++) fits[ind]->SetParameter(i,par[i]);
					float yy = fits[ind]->Eval(xx);
					for(int i=0; i<nPar; i++) fits[ind]->SetParameter(i,parMin[i]);
					float yyMin = fits[ind]->Eval(xx);
					TH1F *hBgErr,*hBgP,*hBgM;
					if(ind==0) {
						hBgErr = ccBgErr; hBgP = ccBgP; hBgM = ccBgM;
					} else {
						hBgErr = cpBgErr; hBgP = cpBgP; hBgM = cpBgM;
					}

					eOld = hBgErr->GetBinContent(ibin);
					eNew = yy - yyMin;
					if(eOld>fabs(eNew)) hBgErr->SetBinContent(ibin,fabs(eNew));
					eOld = hBgP->GetBinContent(ibin);
					if(yy>eOld)  hBgP->SetBinContent(ibin,yy);
					eOld = hBgM->GetBinContent(ibin);
					if(yy<eOld)  hBgM->SetBinContent(ibin,yy);
				}

			} // end if near maximum

			/*
				if(fval<fval2) {
				for(int i=0; i<nPar; i++) par2[i] = par[i];
				fval2 = fval;
				}
				*/
		}

		/*
			printf("forcing new fit..\n");
			for(int i=0; i<nPar; i++) {
			printf("old,new = %10.5f %10.5f\n",parMin[i],par2[i]);
			fits[ind]->SetParameter(i,par2[i]);
			}
			*/

		// restore original fit
		fval = 0.0;
		gMinuit->Eval(nPar,0,fval,parMin,0);
		for(int i=0; i<nPar; i++) fits[ind]->SetParameter(i,parMin[i]);



		//extract fit error matrix
		gMinuit->mnemat(matrix.GetMatrixArray(),nPar);
		matrix.Print();

		for(int i=0; i<nPar; i++) {
			for(int j=0; j<nPar; j++) {
				printf("%10.5f",matrix(i,j)/sqrt(matrix(i,i)*matrix(j,j)));
			}
			printf("\n");
		}
		//matrix.Draw("text");

		float hm = h->GetMaximum();
		if(mode==0) {
			//TAxis* ax = h->GetXaxis();
			//ax->SetRangeUser(24.1,199.9);
			h->SetMaximum(1.2*hm);
			//h->SetMinimum(0.0);
		} else if(mode==1) {
			TAxis* ax = h->GetXaxis();
			ax->SetRangeUser(20.0,500.0);
			h->SetMaximum(1.15*hm);
			h->SetMinimum(0.0);
		}


		h->Draw();
		fits[ind]->SetLineColor(1);
		fits[ind]->SetLineWidth(2.0);
		fits[ind]->Draw("SAME");
		// find chi2's and KS's
		//AnaChiKs(h,fits[ind]);



		TAxis* ax,*ay;
		ax = h->GetXaxis(); 
		ay = h->GetYaxis();
		ax->SetTitle("m(#gamma#gamma) (GeV/c^{2})"); 
		ay->SetTitle("Entries/2 GeV/c^{2}");
		ax->CenterTitle(); ay->CenterTitle();
		ax->SetTitleOffset(0.9);
		ay->SetTitleOffset(1.0);
		ax->SetTitleSize(0.08);
		ay->SetTitleSize(0.07);
		ax->SetLabelSize(0.07);
		ay->SetLabelSize(0.07);

		gPad->SetLeftMargin(0.16);
		gPad->SetBottomMargin(0.16);

		TText* text;
		text = new TLatex(0.5,0.8,"Diphoton Data");
		text->SetNDC(true);
		text->SetTextSize(0.06);
		text->Draw();
		if(ind==0)      text = new TLatex(0.5,0.72,"Central-Central");
		else if(ind==1) text = new TLatex(0.5,0.72,"Central-Plug");
		text->SetNDC(true);
		text->SetTextSize(0.06);
		text->Draw();
		if(ind==0) {
			text = new TLatex(0.15,0.92,"W/Z H#rightarrow X(#gamma#gamma)");
			text->SetNDC(true);
			text->SetTextSize(0.08);
			text->Draw();

			text = new TLatex(0.5,0.92,"CDF Run II Preliminary, 2.0 fb^{-1}");
			text->SetNDC(true);
			text->SetTextSize(0.06);
			text->Draw();
		}    

		/*
			if(debug) printf("start loop\n");
			int ibin;
			for(ibin=16; ibin<=250; ibin++) {
			if(debug) printf("start bin            %i\n",ibin);
			float xx = (ibin-0.5)*2.0; // *** bin width here
			if(debug) printf("-1 test ibin %i\n",ibin);
			float yy = fits[ind]->Eval(xx);
		//printf("%f  yy= %f \n",xx,yy);
		// the derivative of this yield wrt parameters
		if(debug) printf("0 test ibin %i\n",ibin);
		double y0 = yy;
		if(debug) printf("1 test ibin %i\n",ibin);
		TMatrixD vv(nPar,1);
		float dirSize = 0.5;
		for(int i=0; i<nPar; i++){
		int ipar = i;
		double par = fits[ind]->GetParameter(ipar);
		double spar = fits[ind]->GetParError(ipar);
		double parp = par + dirSize*spar;
		fits[ind]->SetParameter(ipar,parp);
		double yp = fits[ind]->Eval(xx);
		vv(i,0) = limitBinSize*(yp-y0)/(dirSize*spar);
		fits[ind]->SetParameter(ipar,par);
		//printf("%f %f %f\n",yp,y0,spar);
		}
		//vv.Print();
		if(debug) printf("start matrix %i\n",ibin);
		TMatrixD tempM(matrix, TMatrixDBase::kMult, vv);
		//matrix.Print();
		TMatrixD tempN(vv, TMatrixDBase::kTransposeMult, tempM);
		//tempN.Print();
		float bgSig = 0.0;
		if(tempN(0,0)>0.0) bgSig = sqrt(tempN(0,0));
		// ****** hack temp  **********
		bgSig = 0.3*y0;


		// file hists to be saved
		if(debug) printf("start fill %i\n",ibin);
		if(ind==0) {
		//printf("filling cc %i %f\n",ibin,h->GetBinContent(ibin));
		cc->SetBinContent(ibin,h->GetBinContent(ibin));
		//printf("getting cc %i %f\n",ibin,cc->GetBinContent(ibin));
		ccBg->SetBinContent(ibin,yy);
		ccBgErr->SetBinContent(ibin,bgSig);
		ccBgP->SetBinContent(ibin,yy+bgSig);
		ccBgM->SetBinContent(ibin,TMath::Max(yy-bgSig,float(0.0)));
		//if(ibin==27) {
		//printf("bg %f %f \n",yy,bgSig);
		//}
		} else {
		cp->SetBinContent(ibin,h->GetBinContent(ibin));
		cpBg->SetBinContent(ibin,yy);
		cpBgErr->SetBinContent(ibin,bgSig);
		cpBgP->SetBinContent(ibin,yy+bgSig);
		cpBgM->SetBinContent(ibin,TMath::Max(yy-bgSig,float(0.0)));
		}
		if(debug) printf("end fill %i\n",ibin);
		}
		*/

	}

	printf("cc plus  BG=%f\n",ccBgP->GetSum());
	printf("cc minus BG=%f\n",ccBgM->GetSum());
	printf("cp plus  BG=%f\n",cpBgP->GetSum());
	printf("cp minus BG=%f\n",cpBgM->GetSum());

	char fn[100];
	if(mode==0) {
		sprintf(fn,"FitSignal_%d",fitMode);
		savePlot(c,fn);
	} else if(mode==1) {
		sprintf(fn,"FitSignalLin_%d",fitMode);
		savePlot(c,fn);
	}

	//if(mode!=0) return;

	// plot of fit results
	gStyle->SetOptLogy(0);
	c = NewCanvas();
	c->Divide(1,2);

	c->cd(1);
	cc->Draw();
	ccBg->Draw("SAME");
	c->cd(2);
	ccBgErr->SetMinimum(0.0); ccBgErr->SetMaximum(4.0); 
	ccBgErr->Draw();
	ccBgP->SetLineStyle(2); ccBgP->Draw("SAME");
	ccBgM->SetLineStyle(2); ccBgM->Draw("SAME");

	savePlot(c,"FitSignalResultsCC");

	c = NewCanvas();
	c->Divide(1,2);

	c->cd(1);
	cp->Draw();
	cpBg->Draw("SAME");
	c->cd(2);
	cpBgErr->SetMinimum(0.0); cpBgErr->SetMaximum(4.0); 
	cpBgErr->Draw();
	cpBgP->SetLineStyle(2); cpBgP->Draw("SAME");
	cpBgM->SetLineStyle(2); cpBgM->Draw("SAME");

	savePlot(c,"FitSignalResultsCP");

	char title[100];
	if(name) {
		sprintf(title,"TPeaksHiggs_FitSignalHist_%s.root",name);
		TFile* ff = new TFile(title,"RECREATE");
		gROOT->GetList()->Write();
		ff->Close();
	}

}
Exemple #18
0
/*#include "TTree.h"
#include "TCanvas.h"
#include "TGraph.h"
#include "TMultiGraph.h"
#include "TRint.h"
#include <time.h>
#include <stdio.h>

const short MaxNN = 6;
*/
void make_scatterplot(TString data_file, TString plot_name, TString header)
{
	//TApplication program = new TRInt(); 
	//pull in data
	TTree *t = new TTree(); 
	t->ReadFile(data_file);
	t->SetName("t");
	
	//TString name = "run2.png";
	TCanvas *BG = new TCanvas("c1", "Read Velocity on Local Disk for CMS3 Files", 1920, 1080);
	BG->cd();
	TPad *c = new TPad("MainPad", "My main pad", 0, 0, 1, 0.9);
	c->Draw();
	c->Divide(2,2);

	//In first slot have Time vs. Buffer for 1 Concurrent Read
	c->cd(1);
	int n1 = t->Draw("VelocityMBps:BufferSize", "ConcurrentReads==1", "goff");
	TGraph *ghist1 = new TGraph(n1, t->GetV2(), t->GetV1());
	ghist1->SetName("ghist1");
	ghist1->SetMarkerStyle(3);
	ghist1->SetMarkerColor(1);
	ghist1->SetTitle("Single File Read");
	ghist1->GetXaxis()->SetTitle("Buffer Size (Bytes)");
	ghist1->GetYaxis()->SetTitle("Read Velocity (MB/s)");
	ghist1->Draw("ap");
	
	//In second slot have Time vs. Buffer for 3 Concurrent Reads
	c->cd(2);
	int n2 = t->Draw("VelocityMBps:BufferSize", "ConcurrentReads==3", "goff");
	TGraph *ghist2 = new TGraph(n2, t->GetV2(), t->GetV1());
	Double_t DP2x[n2], DP2y[n2];
	ghist2->SetName("ghist2");
	ghist2->SetMarkerStyle(3);
	ghist2->SetMarkerColor(1);
	ghist2->SetTitle("3 Concurrent Reads");
	ghist2->GetXaxis()->SetTitle("Buffer Size (Bytes)");
	ghist2->GetYaxis()->SetTitle("Read Velocity (MB/s)");
	ghist2->Draw("ap");
	
	//In third slot have Time vs. Buffer for 3 Concurrent Reads
	c->cd(3);
	int n3 = t->Draw("VelocityMBps:BufferSize", "ConcurrentReads==6", "goff");
	TGraph *ghist3 = new TGraph(n3, t->GetV2(), t->GetV1());
	Double_t DP3x[n3], DP3y[n3];
	ghist3->SetName("ghist3");
	ghist3->SetMarkerStyle(3);
	ghist3->SetMarkerColor(1);
	ghist3->SetTitle("6 Concurrent Reads");
	ghist3->GetXaxis()->SetTitle("Buffer Size (Bytes)");
	ghist3->GetYaxis()->SetTitle("Read Velocity (MB/s)");
	ghist3->Draw("ap");
	
	//In fourth slot have Time vs. Buffer for 10 Concurrent Reads
	c->cd(4);
	int n4 = t->Draw("VelocityMBps:BufferSize", "ConcurrentReads==10", "goff");
	TGraph *ghist4 = new TGraph(n4, t->GetV2(), t->GetV1());
	ghist4->SetMarkerStyle(3);
	ghist4->SetName("ghist4");
	ghist4->SetMarkerColor(1);
	ghist4->SetTitle("10 Concurrent Reads");
	ghist4->GetXaxis()->SetTitle("Buffer Size (Bytes)");
	ghist4->GetYaxis()->SetTitle("Read Velocity (MB/s)");
	ghist4->Draw("ap");
	
	//Draw to screen
	//Initialize Canvas
	
	c->cd(0);
	c->Draw();
	
	BG->cd();
	TText *title = new TText(.5,.95, header);
	title->SetTextAlign(22);
	title->Draw();
	
	gDirectory->Add(ghist1);
	gDirectory->Add(ghist2);
	gDirectory->Add(ghist3);
	gDirectory->Add(ghist4);
	gDirectory->Add(t);
	gPad->SaveAs(plot_name);
}
void make_SMS_exclusion(TH2F *rawlimits,TH2F *xsec,int scantype,std::string& scanx, bool isobserved) {
  TH2F *limits = prep_histo(rawlimits,scantype); // this is to be independent of the style used at creation time
  //here we get some limits and the cross section; we want to make an exclusion plot!
  TH2F *rellimits = (TH2F*)limits->Clone("rellimits");
  TH2F *rellimitsd3 = (TH2F*)limits->Clone("rellimitsd3"); // one third the cross section ("divided by 3" -> d3)
  TH2F *rellimitst3 = (TH2F*)limits->Clone("rellimitst3"); // three times the cross section ("times 3" -> t3)
  
  if(!xsec ) {
    cout << "Watch out, cross section map is invalid!" << endl;
    delete limits;
    return;
  }
  
  rellimits->Divide(xsec);
  
  
  for(int i=1;i<=rellimits->GetNbinsX();i++) {
    for(int j=1;j<=rellimits->GetNbinsY();j++) {
      rellimitst3->SetBinContent(i,j,(rellimits->GetBinContent(i,j))/3.0);
      rellimitsd3->SetBinContent(i,j,(rellimits->GetBinContent(i,j))*3.0);
    }
  }
  

//  TH2F *exclusionshape = make_exclusion_shape(rellimits,1);
//  TH2F *exclusionshapet3 = make_exclusion_shape(rellimitst3,2);
//  TH2F *exclusionshaped3 = make_exclusion_shape(rellimitsd3,3);
  
  //Now let's produce the plots!
  
  set_range(xsec,scantype,false);
  set_range(limits,scantype,false);
  limits->GetZaxis()->SetRangeUser(limits_lower_bound,limits_upper_bound);
  
  bool drawdoubleline=false; //draw nice thin line on top of thick outer line
  TGraph *exclline = MarcosExclusionLine(rellimits, scantype);
  TGraph *thinexcline = thin_line(exclline);
  
  TGraph *excllinet3 = MarcosExclusionLine(rellimitst3, scantype);
  excllinet3->SetLineStyle(2);
  TGraph *thinexclinet3 = thin_line(excllinet3);

  TGraph *excllined3 = MarcosExclusionLine(rellimitsd3, scantype);
  excllined3->SetLineStyle(3);
  TGraph *thinexclined3 = thin_line(excllined3);

//  produce_extensive_plots(xsec,limits,rellimits, rellimitst3, rellimitsd3,scantype);
  
  TCanvas *finalcanvas = new TCanvas("finalcanvas","finalcanvas");
  finalcanvas->SetLogz(1);
  finalcanvas->cd();
  limits->SetZTitle("95% CL upper limit on #sigma [pb]");
  limits->Draw("COLZ");

  TLine *desertline;
  if(drawefficiencydesertline) {
	desertline = new TLine(375,50,1200,875);
	desertline->SetLineWidth(3);
	//desertline->SetLineWidth(4); // paper style
	desertline->SetLineColor(kBlack);
	desertline->Draw("same");
  }


//  fill_with_text(exclline,excllined3,excllinet3,finalcanvas,scantype,scanx);
  stringstream real;
  real << "Limits/";
  if(!isobserved) real << "expected/expected_";
  real << "final_exclusion__" << limits->GetName();
  
  if(Contains(limits->GetName(),"bestlimits")) {
    cout << "----------> " << limits->GetName() << endl;
    TFile *f = new TFile("limits.root","RECREATE");
    thinexcline->SetName("ExclusionLine");
    limits->SetName("UpperLimits");
    limits->Write();
    thinexcline->Write();
    f->Close();
  }
  
  
  exclline->Draw("l");
  if(drawdoubleline) thinexcline->Draw("");
  excllinet3->Draw("");
  if(drawdoubleline) thinexclinet3->Draw("");
  excllined3->Draw("");
  if(drawdoubleline) thinexclined3->Draw("");
  
  CompleteSave(finalcanvas,real.str());

  
  
  //-------------------------------------- extensive plots 
  
  TCanvas *ca = new TCanvas("ca","ca",2400,1200);
  ca->Divide(4,2);
  ca->cd(1);
  ca->cd(1)->SetLogz(1);
  xsec->GetZaxis()->SetRangeUser(0.001,1000);
  xsec->Draw("COLZ");
  TText *title0 = write_title("Reference Cross Section");
  title0->Draw("same");
  ca->cd(2);
  ca->cd(2)->SetLogz(1);
  limits->GetZaxis()->SetRangeUser(limits_lower_bound,limits_upper_bound);
  limits->Draw("COLZ");
  TText *title = write_title("Cross Section Upper Limit");
  title->Draw("same");
  ca->cd(3);
  ca->cd(3)->SetLogz(1);
  TH2F *limit_ref = (TH2F*)limits->Clone("limit_ref");
  limit_ref->Divide(xsec);
  limit_ref->GetZaxis()->SetRangeUser(limits_ratio_lower_bound,limits_ratio_upper_bound);
  limit_ref->Draw("COLZ");
  TText *title2 = write_title("Cross Section UL / XS");
  title2->Draw("same");
  ca->cd(4);
  ca->cd(4)->SetLogz(1);
  limits->SetTitle("");
  limits->GetZaxis()->SetRangeUser(limits_lower_bound,limits_upper_bound);
  limits->SetZTitle("95% CL upper limit on #sigma [pb]");

  limits->Draw("COLZ");


  ca->cd(4);
  exclline->Draw();
  thinexcline->Draw();
  excllinet3->Draw();
  thinexclinet3->Draw();
  excllined3->Draw();
  thinexclined3->Draw();
  stringstream partial;
  partial << "Limits/";
  if(!isobserved) real << "expected/expected_";
  partial << "exclusion__" << limits->GetName();
  fill_with_text(exclline,excllined3,excllinet3,ca->cd(4),scantype);
//  CompleteSave(ca,partial.str());

  ca->cd(5);
  (hardlimit(rellimitsd3))->Draw("COL");
  TText *c = write_title("Exclusion shape for #sigma_{ref}/3");
  c->Draw();
  excllined3->Draw("same");
  
  ca->cd(6);
  (hardlimit(rellimits))->Draw("COL");
  exclline->Draw("same");
  TText *b = write_title("Exclusion shape for #sigma_{ref}");
  b->Draw();
  
  ca->cd(7);
  (hardlimit(rellimitst3))->Draw("COL");
  excllinet3->Draw("same");
  TText *a = write_title("Exclusion shape for 3x#sigma_{ref}");
  a->Draw();
  
  CompleteSave(ca,partial.str()+"__PlusInfo");
  delete ca;
  delete limits;
  
  //---------------------------------------</extensive plots>
  delete finalcanvas;
}
Exemple #20
0
void doPlotsMuon(){
setTDRStyle();

//loop over variables
for(int i = 0; i<1; i++){
double MinX = MinXs[i];
double MaxX = MaxXs[i];
Variable = Variables[i];
TString Xtitle = XTitles[i];

//Data
TH1D* data = getSample("SingleMu", 1, Obj, Variable, Isolation, rebinFact, "central");

//MC
TH1D* tt = getSample("TTJet", lumi*225.2/6920475, Obj, Variable, Isolation, rebinFact, Systematic);

//ttbar individual
// TH1D* tt_semi = getSample("TTJet_SemiLept", lumi*225.2/6920475, Obj, Variable, Isolation, rebinFact, Systematic);
// TH1D* tt_lep = getSample("TTJet_FullLept", lumi*225.2/6920475, Obj, Variable, Isolation, rebinFact, Systematic);
// TH1D* tt_had = getSample("TTJet_Hadronic", lumi*225.2/6920475, Obj, Variable, Isolation, rebinFact, Systematic);

TH1D* wjets = getSample("W1Jet", lumi*37509/57708550, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* w1jets = getSample("W1Jet", lumi*5400.0/23140779, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* w2jets = getSample("W2Jets", lumi*1750.0/34041404, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* w3jets = getSample("W3Jets", lumi*519.0/15536443, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* w4jets = getSample("W4Jets", lumi*214.0/13370904, Obj, Variable, Isolation, rebinFact, Systematic);

TH1D* zjets = getSample("DY1JetsToLL", lumi*5745.25/30457954, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* z1jets = getSample("DY1JetsToLL", lumi*561.0/24042904, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* z2jets = getSample("DY2JetsToLL", lumi*181.0/21835749, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* z3jets = getSample("DY3JetsToLL", lumi*51.1/11010628, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* z4jets = getSample("DY4JetsToLL", lumi*23.04/6391785, Obj, Variable, Isolation, rebinFact, Systematic);

TH1D* qcd = getSample("QCD_Pt-15to20_MuEnrichedPt5",     lumi*34679.3/8500505, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd1 = getSample("QCD_Pt-15to20_MuEnrichedPt5",   lumi*7.022e8 * 0.0039/1722678, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd2 = getSample("QCD_Pt-20to30_MuEnrichedPt5",   lumi*2.87e8 * 0.0065/8486893, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd3 = getSample("QCD_Pt-30to50_MuEnrichedPt5",   lumi*6.609e7 * 0.0122/8928999, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd4 = getSample("QCD_Pt-50to80_MuEnrichedPt5",   lumi*8082000.0 * 0.0218/7256011, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd5 = getSample("QCD_Pt-80to120_MuEnrichedPt5",  lumi*1024000.0 * 0.0395/9030624, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd6 = getSample("QCD_Pt-120to170_MuEnrichedPt5", lumi*157800.0 * 0.0473/8500505, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd7 = getSample("QCD_Pt-170to300_MuEnrichedPt5", lumi*34020.0 * 0.0676/7662483, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd8 = getSample("QCD_Pt-300to470_MuEnrichedPt5", lumi*1757.0 * 0.0864/7797481, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd9 = getSample("QCD_Pt-470to600_MuEnrichedPt5", lumi*115.2 * 0.1024/2995767, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd10 = getSample("QCD_Pt-800to1000_MuEnrichedPt5",lumi*3.57 * 0.1033/4047142, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* qcd11 = getSample("QCD_Pt-1000_MuEnrichedPt5",     lumi*0.774 * 0.1097/3807263, Obj, Variable, Isolation, rebinFact, Systematic);


TH1D* top_t = getSample("T_t-channel", lumi*56.4/3757707, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* top_tw = getSample("T_tW-channel", lumi*11.1/497395, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* top_s = getSample("T_s-channel", lumi*3.79/249516, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* tbar_t = getSample("Tbar_t-channel", lumi*30.7/1934817, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* tbar_tw = getSample("Tbar_tW-channel", lumi*11.1/493239, Obj, Variable, Isolation, rebinFact, Systematic);
TH1D* tbar_s = getSample("Tbar_s-channel", lumi*1.76/139948, Obj, Variable, Isolation, rebinFact, Systematic);

//make combined top and single top template
TH1D* sing_top = (TH1D*)top_t->Clone("top");
sing_top->Add(top_tw);sing_top->Add(top_s); sing_top->Add(tbar_t); sing_top->Add(tbar_tw);sing_top->Add(tbar_s);

  if(inclQ == true){
  qcd->Add(qcd);
  }else{
  qcd1->Add(qcd2);
  qcd1->Add(qcd3);
  qcd1->Add(qcd4);
  qcd1->Add(qcd5);
  qcd1->Add(qcd6);
  qcd1->Add(qcd7);
  qcd1->Add(qcd8);
  qcd1->Add(qcd9);
  qcd1->Add(qcd10);
  qcd1->Add(qcd11);
  }
  
TH1D* qcd_data = getQCD(Obj, Variable, rebinFact);
qcd_data->Scale(qcd1->Integral());

THStack *hs = new THStack("hs","test");
  if(inclQ == true){
  hs->Add(qcd_data);
  }else{
  hs->Add(qcd_data);
  }
    
  zjets->Add(z2jets);
  zjets->Add(z3jets);
  zjets->Add(z4jets);  

  wjets->Add(w2jets);
  wjets->Add(w3jets);
  wjets->Add(w4jets);
  
  hs->Add(zjets);
  hs->Add(wjets);
      
  hs->Add(top_t);
  hs->Add(top_tw);
  hs->Add(top_s);
  hs->Add(tbar_t);
  hs->Add(tbar_tw);
  hs->Add(tbar_s);
  
  hs->Add(tt);
  
  TH1D* allMC = (TH1D*)tt->Clone("allMC");
  allMC->Add(sing_top); allMC->Add(wjets); allMC->Add(zjets); allMC->Add(qcd1);
  
  cout << "tt: " << tt->Integral()  << " wjets: " << wjets->Integral() << " zjets: " << zjets->Integral() << " single top: " << sing_top->Integral() << " qcd: " << qcd1->Integral() << " all: " << allMC->Integral() << " data: " << data->Integral() << endl;
  	
  //draw histos to files
  TCanvas *c1 = new TCanvas("Plot","Plot",900, 600);

  hs->SetMaximum(data->GetBinContent(data->GetMaximumBin())*1.3);

  hs->Draw();
  data->Draw("E same");
  data->SetMarkerStyle(20);
  
  hs->GetXaxis()->SetLimits(MinX, MaxX);
  hs->GetXaxis()->SetTitle(Xtitle); hs->GetXaxis()->SetTitleSize(0.05);
  hs->GetYaxis()->SetTitle("Number of Events");hs->GetYaxis()->SetTitleSize(0.05);
  
  
  	TLegend *tleg2;
	tleg2 = new TLegend(0.6,0.6,0.8,0.9);
	tleg2->SetTextSize(0.04);
	tleg2->SetBorderSize(0);
	tleg2->SetFillColor(10);
	tleg2->AddEntry(data , "2012 data", "lpe");
	tleg2->AddEntry(tt , "t#bar{t} l+jets", "lf");
	//tleg2->AddEntry(tt_lep , "t#bar{t} di-lepton", "lf");
	tleg2->AddEntry(top_t, "single top", "lf");
	tleg2->AddEntry(wjets , "w+jets", "lf");
	tleg2->AddEntry(zjets , "z+jets", "lf");
	tleg2->AddEntry(qcd , "QCD", "lf");

	//tleg2->AddEntry(singtEff, "single-t"      , "l");
	//tleg2->AddEntry(singtwEff, "single-tW"      , "l");
 	tleg2->Draw("same");	

	TText* textPrelim = doPrelim(0.12,0.96);
	textPrelim->Draw();

  if(logPlot ==true){
  c1->SetLogy();
  }	
  
  TString plotName("plots/Control/Muon/");
  
  if(logPlot ==true){
    plotName += Variable+"Log";
    plotName += Nbtags+".pdf";
    
  }else{
    plotName += Variable;  
    plotName += Nbtags+".pdf";
  }
 
 
  c1->SaveAs(plotName);
  delete c1;
  
  }
  	
}
void process_syst_plot(TH2F *rhisto,string saveto,int scantype, std::string scanx = "") {
  TH2F *histo = prep_histo(rhisto,scantype); // this is to be independent of the style used at creation time
  float rightmargin=gStyle->GetPadRightMargin();
  gStyle->SetPadRightMargin(0.20);
  TString name = rhisto->GetName();
  if(name.Contains("Nevents")) gStyle->SetPadRightMargin(0.22);
  TCanvas *can = new TCanvas("syst_plot","Systematics Plot");
  set_range(histo,scantype,true);
  
  histo->GetZaxis()->CenterTitle();
  gStyle->SetStripDecimals(false);
  histo->GetXaxis()->SetDecimals(true);
  
  if(name.Contains("efficiency")) {
    histo->GetZaxis()->SetTitle("A #times #varepsilon (#geq 1 Z(ll))");
    histo->GetZaxis()->CenterTitle(0);
    //histo->GetZaxis()->SetRangeUser(0.0,0.15);
  }
  if(name.Contains("Nevents")) {
     histo->GetZaxis()->SetTitle("N(events)");
     histo->GetZaxis()->SetTitleOffset(histo->GetZaxis()->GetTitleOffset()+0.4);
  }
  if(name.Contains("sysjes")) {
    histo->GetZaxis()->SetTitle("Jet Energy Scale");
    histo->GetZaxis()->SetRangeUser(0.0,0.2);
  }
  if(name.Contains("sysjsu")) {
    histo->GetZaxis()->SetTitle("JZB Scale Uncertainty");
    histo->GetZaxis()->SetRangeUser(0.0,0.5);
  }
  if(name.Contains("sysresmap")) {
    histo->GetZaxis()->SetTitle("Resulution");
    histo->GetZaxis()->SetRangeUser(0.0,0.5);
  }
  if(name.Contains("sysstatmap")) {
    histo->GetZaxis()->SetTitle("Statistical Error");
    histo->GetZaxis()->SetRangeUser(0.0,0.01);
  }
  if(name.Contains("systotmap")) {
    histo->GetZaxis()->SetTitle("All Systematic Errors");
    histo->GetZaxis()->SetRangeUser(0.0,0.5);
  }
  
  
  histo->Draw("COLZ");
  DrawPrelim();
  float xpos_of_text = 0.22;
  if(name.Contains("_noscefficiencymap"))  {
    // Add some more decorations on these publication plots
    write_SMS_text( scantype, scanx, xpos_of_text );
    // Decode name and get JZB cut
    TPRegexp pat("\\d+$");
    size_t index = name.Index(pat,0);
    string cut = string("JZB > ")+(name(index,name.Length()-index).Data())+" GeV";
    //string cut = string("#splitline{JZB > ")+(name(index,name.Length()-index).Data())+" GeV}{n_{jets} #geq 3}"; //paper style
    TText *text = write_text(xpos_of_text,0.73,cut);
    text->SetTextAlign(11);
    text->SetTextSize(0.035);
    text->Draw();
    draw_diagonal_xchange( scantype, scanx );
  }
  
  CompleteSave(can,(saveto+(string)histo->GetName()));

  gStyle->SetPadRightMargin(rightmargin);
  
  delete can;
}
void run_radius_correction ()
{
    TStopwatch timer;
    timer.Start();

    gStyle->SetPalette(1,0);
    gStyle->SetHistLineWidth(2);

    // ----  Load libraries   -------------------------------------------------
    gROOT->LoadMacro("$VMCWORKDIR/gconfig/basiclibs.C");
    basiclibs();
    gROOT->LoadMacro("$VMCWORKDIR/macro/rich/cbmlibs.C");
    cbmlibs();

   // gROOT->LoadMacro("$VMCWORKDIR/macro/rich/setstyle.C");
   // setphdStyle();
    SetStyles();

    char fileMC[200], fileRec[200];

    sprintf(fileMC,"/d/cbm02/slebedev/rich/JUL09/correction/mc.00.root");
    cout<<fileMC<<endl;
    TFile *f1 = new TFile(fileMC,"R");
    TTree* t1 = f1->Get("cbmsim");
    TFolder *fd1 = f1->Get("cbmroot");
    TClonesArray* fMCTracks = (TClonesArray*) fd1->FindObjectAny("MCTrack");
    t1->SetBranchAddress(fMCTracks->GetName(),&fMCTracks);

    sprintf(fileRec, "/d/cbm02/slebedev/rich/JUL09/correction/reco.00.root");
    TFile *f = new TFile(fileRec,"R");
    TTree* t = f->Get("cbmsim");
    TFolder *fd = f->Get("cbmout");
    TClonesArray *fRichRings = (TClonesArray*) fd->FindObjectAny("RichRing");
    t->SetBranchAddress(fRichRings->GetName(),&fRichRings);
    TClonesArray *fRichMatches = (TClonesArray*) fd->FindObjectAny("RichRingMatch");
    t->SetBranchAddress(fRichMatches->GetName(),&fRichMatches);

    //Int_t fNofBinsX = 40;
    //Int_t fNofBinsY = 50;
    Int_t fNofBinsX = 25;
    Int_t fNofBinsY = 25;
    ///A axis
    TH2D* fh_axisAXYCount;
    TH2D* fh_axisAXYW;
    TH2D* fh_axisAXY;
    TH2D* fh_axisASigma;
    TH2D* mapaxisAXY;


    ///B axis
    TH2D* fh_axisBXYCount;
    TH2D* fh_axisBXYW;
    TH2D* fh_axisBXY;
    TH2D* fh_axisBSigma;
    TH2D* mapaxisBXY;

    mapaxisAXY = new TH2D("fh_mapaxisAXY","dA distribution (x,y);X, [cm];Y, [cm]",fNofBinsX,-200,200,fNofBinsY,-250,250);
    mapaxisBXY = new TH2D("fh_mapaxisBXY","dB distribution (x,y);X, [cm];Y, [cm]",fNofBinsX,-200,200,fNofBinsY,-250,250);
    fh_axisAXYCount = new TH2D("fh_axisAXYCount","A Count",fNofBinsX,-200,200,fNofBinsY,-250,250);
    fh_axisAXYW = new TH2D("fh_axisAXYW","",fNofBinsX,-200,200,fNofBinsY,-250,250);
    fh_axisBXYCount = new TH2D("fh_axisBXYCount","B Count",fNofBinsX,-200,200,fNofBinsY,-250,250);
    fh_axisBXYW = new TH2D("fh_axisBXYW","",fNofBinsX,-200,200,fNofBinsY,-250,250);
    fh_axisAXY = new TH2D("fh_axisAXY","A distribution (x,y);X, [cm];Y, [cm]",fNofBinsX,-200,200,fNofBinsY,-250,250);
    fh_axisBXY = new TH2D("fh_axisBXY","B distribution (x,y);X, [cm];Y, [cm]",fNofBinsX,-200,200,fNofBinsY,-250,250);

    Double_t fMinAaxis = 4.5;
    Double_t fMaxAaxis = 7.5;

    ///Set Mean value of A and B axeses, Compact RICH
    //Double_t fMeanAaxis = 5.06;
    //Double_t fMeanBaxis = 4.65;

    ///Set Mean value of A and B axeses, Large RICH
    Double_t fMeanAaxis = 6.17;
    Double_t fMeanBaxis = 5.6;

    Int_t nEvents=t->GetEntries();
    cout<<" nEvents ="<<nEvents<<endl;
    for(Int_t ievent=0;ievent<nEvents; ievent++ ) {
        cout<<"ievent = "<<ievent;
        CbmRichRing *ring=NULL;
        CbmRichRingMatch *match=NULL;
        t->GetEntry(ievent);
        t1->GetEntry(ievent);
        Int_t nofRings = fRichRings->GetEntries();
        cout<<"  nofRings = "<<nofRings;
        cout<<"  nofMatches = "<< fRichMatches->GetEntries() ;
        cout<<"  nofMCTracks = "<<fMCTracks->GetEntries() << endl;

        for(Int_t iRing=0; iRing < nofRings; iRing++){
            ring = (CbmRichRing*)fRichRings->At(iRing);
            if (!ring) continue;
            match = (CbmRichRingMatch*)fRichMatches->At(iRing);
            if (!match) continue;

            Int_t trackId = match->GetMCTrackID();
            if (trackId == -1) continue;
            if (trackId > fMCTracks->GetEntries()) continue;

            CbmMCTrack* mcTrack = (CbmMCTrack*)fMCTracks->At(trackId);
            if (!mcTrack) continue;
            Int_t pdg = TMath::Abs(mcTrack->GetPdgCode());
            Int_t motherId = mcTrack->GetMotherId();
            if (pdg != 11) continue;
            if (motherId != -1) continue;

            Double_t radius = ring->GetRadius();
            Double_t axisA = ring->GetAaxis();
            Double_t axisB = ring->GetBaxis();
            Double_t centerX = ring->GetCenterX();
            Double_t centerY = ring->GetCenterY();

            if (axisA > fMaxAaxis || axisB > fMaxAaxis) continue;
            if (axisA < fMinAaxis || axisB < fMinAaxis) continue;

            fh_axisAXYW->Fill(centerX, centerY, axisA);
            fh_axisAXYCount->Fill(centerX, centerY);

            fh_axisBXYW->Fill(centerX, centerY, axisB);
            fh_axisBXYCount->Fill(centerX, centerY);
        } //iRing
    } //iEvent

    fh_axisAXY->Divide(fh_axisAXYW,fh_axisAXYCount);
    fh_axisBXY->Divide(fh_axisBXYW,fh_axisBXYCount);


///create two correction maps
    for (Int_t iX = 1; iX < mapaxisAXY->GetNbinsX() + 1; iX++){
        for (Int_t iY = 1; iY < mapaxisAXY->GetNbinsY() + 1; iY++){
        	if (fh_axisAXYCount->GetBinContent(iX, iY) != 0){
        		mapaxisAXY->SetBinContent(iX, iY, fMeanAaxis - fh_axisAXY->GetBinContent(iX, iY) );
        	} else {
        		mapaxisAXY->SetBinContent(iX, iY, -99999999.);
        	}

        	if (fh_axisBXYCount->GetBinContent(iX, iY) != 0){
        		mapaxisBXY->SetBinContent(iX, iY, fMeanBaxis - fh_axisBXY->GetBinContent(iX, iY) );
        	} else {
        		mapaxisBXY->SetBinContent(iX, iY, -99999999.);
        	}
        }
    }

    c1_0 = new TCanvas("c1_0","c1_0",10,10,600,600);
    c1_0->Divide(1,2);
    c1_0->cd(1);
    fh_axisAXYCount->Draw("COLZ");
    c1_0->cd(2);
    fh_axisBXYCount->Draw("COLZ");

    c1 = new TCanvas("c1","c1",10,10,600,600);
    c1->Divide(1,2);
    c1->cd(1);
    fh_axisAXY->SetMinimum(5.0);
    fh_axisAXY->SetMaximum(6.4);
    fh_axisAXY->Draw("COLZ");
    c1->cd(2);
    fh_axisBXY->SetMinimum(5.0);
    fh_axisBXY->SetMaximum(6.0);
    fh_axisBXY->Draw("COLZ");

    c2 = new TCanvas("c2","c2",10,10,600,600);
    c2->Divide(1,2);
    c2->cd(1);
    mapaxisAXY->SetMinimum(-0.5);
    mapaxisAXY->SetMaximum(0.5);
    mapaxisAXY->Draw("COLZ");
    c2->cd(2);
    mapaxisBXY->SetMinimum(-0.5);
    mapaxisBXY->SetMaximum(0.5);
    mapaxisBXY->Draw("COLZ");


///// Check correction procedure
    TH1D* fh_Abefore = new TH1D("fh_Abefore","A before;A, [cm];yield", 300, 0., 9.);;
    TH1D* fh_Bbefore= new TH1D("fh_Bbefore","B before;B, [cm];yield", 300, 0., 9.);;

    TH1D* fh_A = new TH1D("fh_A","A after;A, [cm];yield", 300, 0., 9.);;
    TH1D* fh_B = new TH1D("fh_B","B after;B, [cm];yield", 300, 0., 9.);;

    cout <<"Check correction procedure......" << endl;
    for(Int_t ievent=0;ievent<nEvents;ievent++ ) {
        CbmRichRing *ring=NULL;
       // if (ievent % 100 == 0) cout << ievent << "   ";
        //t1->GetEntry(ievent);
        t->GetEntry(ievent);
        t1->GetEntry(ievent);
        Int_t nofRings = fRichRings->GetEntries();

        for(Int_t iRing=0; iRing < nofRings; iRing++){

            ring = (CbmRichRing*)fRichRings->At(iRing);
            if (!ring) continue;
            match = (CbmRichRingMatch*)fRichMatches->At(iRing);
            if (!match) continue;

            Int_t trackId = match->GetMCTrackID();
            if (trackId == -1) continue;
            if (trackId > fMCTracks->GetEntries()) continue;

            CbmMCTrack* mcTrack = (CbmMCTrack*)fMCTracks->At(trackId);
            if (!mcTrack) continue;
            Int_t pdg = TMath::Abs(mcTrack->GetPdgCode());
            Int_t motherId = mcTrack->GetMotherId();
            if (pdg != 11) continue;
            if (motherId != -1) continue;

            Double_t axisA = ring->GetAaxis();
            Double_t axisB = ring->GetBaxis();
            if (axisA > fMaxAaxis || axisB > fMaxAaxis) continue;
            if (axisA < fMinAaxis || axisB < fMinAaxis) continue;

            Double_t radius = ring->GetRadius();
            Double_t centerX = ring->GetCenterX();
            Double_t centerY = ring->GetCenterY();
            Double_t axisAbefore = ring->GetAaxis();
            Double_t axisBbefore = ring->GetBaxis();
            fh_Abefore->Fill(axisAbefore);
            fh_Bbefore->Fill(axisBbefore);

            Double_t axisA = ring->GetAaxis();
            Double_t axisB = ring->GetBaxis() ;

            axisA += mapaxisAXY->GetBinContent(mapaxisAXY->FindBin(centerX,centerY));
            axisB += mapaxisBXY->GetBinContent(mapaxisBXY->FindBin(centerX,centerY));

            fh_A->Fill(axisA);
            fh_B->Fill(axisB);
        } //iRing
    }//iEvent


  //  gStyle->SetOptStat(0);
    c3 = new TCanvas("c3","c3",10,10,600,600);
    c3->Divide(2,2);
    c3->cd(1);
    fh_Abefore->Scale(1./fh_Abefore->Integral());
    fh_Abefore->SetMaximum(fh_Abefore->GetMaximum()*1.3);
    fh_Abefore->Draw();
    fh_Abefore->SetAxisRange(fMinAaxis, fMaxAaxis);
    fh_Abefore->Fit("gaus");
    Double_t sigmaAb = fh_Abefore->GetFunction("gaus")->GetParameter("Sigma");
    char sigmaTxtAb[30];
    sprintf(sigmaTxtAb,"sigma = %.3f",sigmaAb);
    TText* txtAb = new TText(4.3, fh_Abefore->GetMaximum()*0.85, sigmaTxtAb);
    txtAb->SetTextSize(0.1);
    txtAb->Draw();
    gPad->SetGridx(true);
    gPad->SetGridy(true);

    c3->cd(2);
    fh_Bbefore->Scale(1./fh_Bbefore->Integral());
    fh_Bbefore->SetMaximum(fh_Bbefore->GetMaximum()*1.3);
    fh_Bbefore->Draw();
    fh_Bbefore->SetAxisRange(fMinAaxis, fMaxAaxis);
    fh_Bbefore->Fit("gaus");
    Double_t sigmaBb = fh_Bbefore->GetFunction("gaus")->GetParameter("Sigma");
    char sigmaTxtBb[30];
    sprintf(sigmaTxtBb,"sigma = %.3f",sigmaBb);
    TText* txtBb = new TText(4.3, fh_Bbefore->GetMaximum()*0.85, sigmaTxtBb);
    txtBb->SetTextSize(0.1);
    txtBb->Draw();
    gPad->SetGridx(true);
    gPad->SetGridy(true);

    c3->cd(3);
    fh_A->Scale(1./fh_A->Integral());
    fh_A->SetMaximum(fh_A->GetMaximum()*1.3);
    fh_A->SetAxisRange(fMinAaxis, fMaxAaxis);
    fh_A->Draw();
    fh_A->Fit("gaus");
    Double_t sigmaA = fh_A->GetFunction("gaus")->GetParameter("Sigma");
    char sigmaTxtA[30];
    sprintf(sigmaTxtA,"sigma = %.3f",sigmaA);
    TText* txtA = new TText(4.3, fh_A->GetMaximum()*0.85, sigmaTxtA);
    txtA->SetTextSize(0.1);
    txtA->Draw();
    gPad->SetGridx(true);
    gPad->SetGridy(true);

    c3->cd(4);
    fh_B->Scale(1./fh_B->Integral());
    fh_B->SetMaximum(fh_B->GetMaximum()*1.3);
    fh_B->SetAxisRange(fMinAaxis, fMaxAaxis);
    fh_B->Draw();
    fh_B->Fit("gaus");
    Double_t sigmaB = fh_B->GetFunction("gaus")->GetParameter("Sigma");
    char sigmaTxtB[30];
    sprintf(sigmaTxtB,"sigma = %.3f",sigmaB);
    TText* txtB = new TText(4.3, fh_B->GetMaximum()*0.85, sigmaTxtB);
    txtB->SetTextSize(0.1);
    txtB->Draw();
    gPad->SetGridx(true);
    gPad->SetGridy(true);


/// Write correction map to the file
    TFile *file = new TFile("radius_correction_map.root", "recreate");
    mapaxisAXY->Write();
    mapaxisBXY->Write();
    file->Close();

}
void EMCDistribution_PeakSample_Fast(bool full_gain = false)
{
  const TString gain = "RAW";

  TString hname = "EMCDistribution_" + gain + TString(full_gain ? "_FullGain" : "") + cuts;

  TH2 *h2 = NULL;
  {
    if (full_gain)
    {
      h2 = new TH2F(hname,
                    Form(";Calibrated Tower Energy Sum (ADC);Count / bin"), 100,
                    .05 * 100, 25 * 100, 64, -.5, 63.5);
      QAHistManagerDef::useLogBins(h2->GetXaxis());
    }
    else
    {
      h2 = new TH2F(hname,
                    Form(";Calibrated Tower Energy Sum (ADC);Count / bin"), 260,
                    -.2 * 100, 5 * 100, 64, -.5, 63.5);
    }
    T->Draw(
        "TOWER_" + gain + "_CEMC[].get_bineta() + 8* TOWER_" + gain + "_CEMC[].get_binphi():(TOWER_RAW_CEMC[].signal_samples[10] - TOWER_RAW_CEMC[].signal_samples[0])*(-1)>>" + hname, "", "goff");
  }

  TText *t;
  TCanvas *c1 = new TCanvas(
      "EMCDistribution_PeakSample_Fast_" + TString(full_gain ? "_FullGain" : "") + cuts,
      "EMCDistribution_PeakSample_Fast_" + TString(full_gain ? "_FullGain" : "") + cuts, 1800, 950);
  c1->Divide(8, 8, 0., 0.01);
  int idx = 1;
  TPad *p;

  for (int iphi = 8 - 1; iphi >= 0; iphi--)
  {
    for (int ieta = 0; ieta < 8; ieta++)
    {
      p = (TPad *) c1->cd(idx++);
      c1->Update();

      p->SetLogy();
      if (full_gain)
      {
        p->SetLogx();
      }
      p->SetGridx(0);
      p->SetGridy(0);

      TString hname = Form("hEnergy_ieta%d_iphi%d", ieta, iphi) + TString(full_gain ? "_FullGain" : "");

      TH1 *h = h2->ProjectionX(hname, ieta + 8 * iphi + 1,
                               ieta + 8 * iphi + 1);  // axis bin number is encoded as ieta+8*iphi+1

      h->SetLineWidth(0);
      h->SetLineColor(kBlue + 3);
      h->SetFillColor(kBlue + 3);

      h->GetXaxis()->SetTitleSize(.09);
      h->GetXaxis()->SetLabelSize(.08);
      h->GetYaxis()->SetLabelSize(.08);

      h->Draw();

      if (full_gain)
        h->Fit("x*gaus", "M");
      else
        h->Fit("landau", "M");

      double peak = -1;

      TF1 *fit = ((TF1 *) (h->GetListOfFunctions()->At(0)));
      if (fit)
      {
        fit->SetLineColor(kRed);
        peak = fit->GetParameter(1);
      }

      cout << Form("Finished <Col%d Row%d> = %.1f", ieta, iphi, peak)
           << endl;

      TText *t = new TText(.9, .9,
                           Form("<Col%d Row%d> = %.1f", ieta, iphi, peak));
      t->SetTextAlign(33);
      t->SetTextSize(.15);
      t->SetNDC();
      t->Draw();
    }
  }

  SaveCanvas(c1,
             TString(_file0->GetName()) + TString("_DrawPrototype3EMCalTower_") + TString(c1->GetName()), false);
}
Exemple #24
0
void fineBinPU(){
//setTDRStyle();

TFile* file_2011_64600 = new TFile("PileUp/PileUp_2011_truth_finebin_64600microbarn.root");
TFile* file_2011_68000 = new TFile("PileUp/PileUp_2011_truth_finebin_68000microbarn.root");
TFile* file_2011_71400 = new TFile("PileUp/PileUp_2011_truth_finebin_71400microbarn.root");

TFile* file_2012_65835 = new TFile("PileUp/PileUp_2012_65835_truth_finebin.root");
TFile* file_2012_69300 = new TFile("PileUp/PileUp_2012_69300_truth_finebin.root");
TFile* file_2012_72765 = new TFile("PileUp/PileUp_2012_72765_truth_finebin.root");

TH1D* plot_2011_64600 = (TH1D*) file_2011_64600->Get("pileup");
TH1D* plot_2011_68000 = (TH1D*) file_2011_68000->Get("pileup");
TH1D* plot_2011_71400 = (TH1D*) file_2011_71400->Get("pileup");

TH1D* plot_2012_65835 = (TH1D*) file_2012_65835->Get("pileup");
TH1D* plot_2012_69300 = (TH1D*) file_2012_69300->Get("pileup");
TH1D* plot_2012_72765 = (TH1D*) file_2012_72765->Get("pileup");


plot_2011_64600->Scale(1/plot_2011_64600->Integral());
plot_2011_68000->Scale(1/plot_2011_68000->Integral());
plot_2011_71400->Scale(1/plot_2011_71400->Integral());

plot_2012_65835->Scale(1/plot_2012_65835->Integral());
plot_2012_69300->Scale(1/plot_2012_69300->Integral());
plot_2012_72765->Scale(1/plot_2012_72765->Integral());

plot_2011_64600->SetLineColor(kRed);
plot_2011_68000->SetLineColor(kGreen);
plot_2011_71400->SetLineColor(kBlack);

plot_2012_65835->SetLineColor(kYellow);
plot_2012_69300->SetLineColor(kBlue);
plot_2012_72765->SetLineColor(kMagenta);

  //draw histos to files
  TCanvas *c1 = new TCanvas("Plot","Plot",900, 600);

  plot_2012_65835->Draw();
  plot_2012_69300->Draw("same");
  plot_2012_72765->Draw("same");
  plot_2011_64600->Draw("same");
  plot_2011_68000->Draw("same");
  plot_2011_71400->Draw("same");
  
  plot_2012_65835->SetMaximum(plot_2011_71400->GetBinContent(plot_2011_71400->GetMaximumBin())*1.2);
  plot_2012_65835->GetXaxis()->SetLimits(0, 50);
  plot_2012_65835->GetXaxis()->SetTitle("Number of interactions per crossing"); plot_2012_65835->GetXaxis()->SetTitleSize(0.05);
  plot_2012_65835->GetYaxis()->SetTitle("Normalised Events");plot_2012_65835->GetYaxis()->SetTitleSize(0.05);
  
  	TLegend *tleg2;
	tleg2 = new TLegend(0.5,0.6,0.9,0.9);
	tleg2->SetTextSize(0.04);
	tleg2->SetBorderSize(0);
	tleg2->SetFillColor(10);
	tleg2->AddEntry(plot_2012_65835 , "#sqrt{s} = 8 TeV, #sigma_{pp} = 65835 pb", "l");
	tleg2->AddEntry(plot_2012_69300 , "#sqrt{s} = 8 TeV, #sigma_{pp} = 69300 pb", "l");
	tleg2->AddEntry(plot_2012_72765 , "#sqrt{s} = 8 TeV, #sigma_{pp} = 72765 pb", "l");
	tleg2->AddEntry(plot_2011_64600 , "#sqrt{s} = 7 TeV, #sigma_{pp} = 64600 pb", "l");
	tleg2->AddEntry(plot_2011_68000 , "#sqrt{s} = 7 TeV, #sigma_{pp} = 68000 pb", "l");
	tleg2->AddEntry(plot_2011_71400 , "#sqrt{s} = 7 TeV, #sigma_{pp} = 71400 pb", "l");
 
 	tleg2->Draw("same");
		
	TText* textPrelim = doPrelim(0.3,0.96);
	textPrelim->Draw();
	
	c1->SaveAs("Plots/TTbarPlusVarAnalysis/PileUp/PileUp_2012_truth_data.pdf");
	c1->SaveAs("Plots/TTbarPlusVarAnalysis/PileUp/PileUp_2012_truth_data.png");
	delete c1;	
}
Exemple #25
0
PigsGUI::PigsGUI(const TGWindow *p) : TGMainFrame(p, fGUIsizeX, fGUIsizeY)  {
    // Creates the GUI
    if(fVerbose) std::cout<<__PRETTY_FUNCTION__ << std::endl;
    daq = 0; storage = 0; ev = 0;               // Initialize local variables
    year = month = day = hour = min = sec = 0;
    fAcqThread = 0;
    keepAcquiring  = kFALSE;
    useIntegration = kTRUE;
    const int32_t fHistColors[] = { kMagenta+1, kGreen+1, kBlue+1, kRed+1 };
    fAboutMsg = (char*)
"\n"
"\n"
"        _____  _____  ______ _______\n"
"       |_____]   |   |  ____ |______\n"
"       |       __|__ |_____| ______|\n"
"\n"
"\n"
" *** Position Indicating Gamma Sensor   ***\n"
"  * CAEN DT-5781 Data Acquisition System *\n"
"         Four Channel Version\n"
"\n"
"   by Ondrej Chvala <*****@*****.**>\n"
"        version 0.097, July 2015\n"
"   https://github.com/ondrejch/DAQ-DT5781\n"
"                 GNU/GPL";
    int32_t i = 0; // helper variable
    for (i=0; i<4; i++) {
        fScaleFactor[i] = 1.0;
        fNormAvgH[i] = 0;
    }
    fIntegralMin = 1;
    fIntegralMax = 16384;

    // *** Main GUI window ***
    fMainGUIFrame = new TGMainFrame(gClient->GetRoot(),10,10,kMainFrame | kVerticalFrame);
    #include "fpigsicon.xpm"
    TImage *tmpicon = TImage::Create();
    tmpicon->SetImageBuffer((char**)fpigsicon_xpm, TImage::kXpm);
    gVirtualX->SetIconPixmap(fMainGUIFrame->GetId(),tmpicon->GetPixmap());
    delete tmpicon;
    fMainGUIFrame->SetName("fMainGUIFrame");
    fMainGUIFrame->SetWindowName("F-PIGS");      // GUI window name
    fMainGUIFrame->SetLayoutBroken(kTRUE);
    ufont = gClient->GetFont("-*-*-bold-r-*-*-16-*-*-*-*-*-*-*");
    // ufont = gClient->GetFont("-*-helvetica-medium-r-normal-*-14-*-*-*-*-*-iso8859-1");
    // ufont = gClient->GetFont("-urw-nimbus sans l-bold-r-normal--0-0-0-0-p-0-iso8859-1");
    valTitle.fMask = kGCForeground | kGCBackground | kGCFillStyle | kGCFont | kGCGraphicsExposures;
    gClient->GetColorByName("#0000FF",valTitle.fForeground);
    gClient->GetColorByName("#e0e0e0",valTitle.fBackground);
    valTitle.fFillStyle = kFillSolid;
    valTitle.fFont = ufont->GetFontHandle();
    valTitle.fGraphicsExposures = kFALSE;
    uGC = gClient->GetGC(&valTitle, kTRUE);
    fMainTitle = new TGLabel(fMainGUIFrame,"Four-channel Position Identifying Gamma Sensor (F-PIGS)",
            uGC->GetGC(),ufont->GetFontStruct());
    fMainTitle->SetTextJustify(36);
    fMainTitle->SetMargins(0,0,0,0);
    fMainTitle->SetWrapLength(-1);
    fMainGUIFrame->AddFrame(fMainTitle, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
    fMainTitle->MoveResize(0,0,fGUIsizeX-4,32);
    fMainGUIFrame->Connect("CloseWindow()", "PigsGUI", this, "~PigsGUI()"); // call class destructor on alt+f4
    fMainGUIFrame->DontCallClose();

    // Buttons for main GUI
    fStartDAQ = new TGTextButton(fMainGUIFrame, "Start DAQ");     // start DAQ
    fStartDAQ->SetTextJustify(36);
    fStartDAQ->SetMargins(0,0,0,0);
    fStartDAQ->Resize(90,25);
    fMainGUIFrame->AddFrame(fStartDAQ, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
    fStartDAQ->MoveResize(50,fGUIsizeY-30,90,25);
    gClient->GetColorByName("green", fColor);
    fStartDAQ->ChangeBackground(fColor);
    fStartDAQ->SetState(kButtonDisabled);
    fStartDAQ->Connect("Clicked()","PigsGUI",this,"RunAcquisition()");

    fStopDAQ = new TGTextButton(fMainGUIFrame, "Stop DAQ");        // stop DAQ
    fStopDAQ->SetTextJustify(36);
    fStopDAQ->SetMargins(0,0,0,0);
    fStopDAQ->Resize(90,25);
    fMainGUIFrame->AddFrame(fStopDAQ, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
    fStopDAQ->MoveResize(fGUIsizeX-50-90,fGUIsizeY-30,90,25);
    gClient->GetColorByName("red", fColor);
    fStopDAQ->ChangeBackground(fColor);
    fStopDAQ->SetState(kButtonDisabled);
    fStopDAQ->Connect("Clicked()","PigsGUI",this,"StopAcquisition()");

    fExitDAQ = new TGTextButton(fMainGUIFrame, "Exit DAQ");        // exit DAQ
    fExitDAQ->SetTextJustify(36);
    fExitDAQ->SetMargins(0,0,0,0);
    fExitDAQ->Resize(90,25);
    fMainGUIFrame->AddFrame(fExitDAQ, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
    fExitDAQ->MoveResize(fGUIsizeX/2-45,fGUIsizeY-30,90,25);
    fExitDAQ->Connect("Clicked()","PigsGUI",this,"~PigsGUI()");

    // *** Tab widget ****
    fTabHolder = new TGTab(fMainGUIFrame,fGUIsizeX-4,fGUIsizeX-4);//,uGC->GetGC());

    // *** Container of "CurrentHistogram" ***
    fCurHistFrame = fTabHolder->AddTab("CurrentHistogram");
    fCurHistFrame->SetLayoutManager(new TGVerticalLayout(fCurHistFrame));
    // embedded canvas
    fLatestHistoCanvas = new TRootEmbeddedCanvas("CurrentHEC",fCurHistFrame,fGUIsizeX-10,fGUIsizeY-140);
    Int_t wfLatestHistoCanvas = fLatestHistoCanvas->GetCanvasWindowId();
    cCurrHCanvas = new TCanvas("cCurrHCanvas", 10, 10, wfLatestHistoCanvas);
    fLatestHistoCanvas->AdoptCanvas(cCurrHCanvas);
    cCurrHCanvas->Divide(2,2);
    fCurHistFrame->AddFrame(fLatestHistoCanvas, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
    fHCurrHProgressBar = new TGHProgressBar(fCurHistFrame,fGUIsizeX-5);
    fHCurrHProgressBar->SetFillType(TGProgressBar::kBlockFill);
    fHCurrHProgressBar->ChangeOptions(kSunkenFrame | kDoubleBorder | kOwnBackground);

    // will reflect user color changes
    gClient->GetColorByName("#ffffff",fColor);
    fHCurrHProgressBar->SetBackgroundColor(fColor);
    fHCurrHProgressBar->SetPosition(1);
    fCurHistFrame->AddFrame(fHCurrHProgressBar, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));

    // *** Container of "History" ***
    fTabHisto = fTabHolder->AddTab("History");
    fTabHisto->SetLayoutManager(new TGVerticalLayout(fTabHisto));
    // embedded canvas
    fLastMeas = new TRootEmbeddedCanvas("HistoryHEC",fTabHisto,fGUIsizeX-10,fGUIsizeY-110);
    Int_t wfLastNspectra = fLastMeas->GetCanvasWindowId();
    cLastMeas = new TCanvas("cLastMeas", 10, 10, wfLastNspectra);
    fLastMeas->AdoptCanvas(cLastMeas);
    fMG = new TMultiGraph("fMG","");
    for (i=0; i<4; i++) {
        fGraph[i] = new TGraph();
        fGraph[i]->SetName(Form("gCh%d",i));
        fGraph[i]->SetDrawOption("AP");
        fGraph[i]->SetMarkerColor(fHistColors[i]);
        fGraph[i]->SetMarkerStyle(21);
        fGraph[i]->SetMarkerSize(2.0);
        fGraph[i]->SetLineWidth(0.5);
        fGraph[i]->SetLineColor(i+12);
        fGraph[i]->SetFillStyle(0);
        fMG->Add(fGraph[i]);
    }
    fTabHisto->AddFrame(fLastMeas, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));

    // *** Container of "Average" ***
    fTabSum = fTabHolder->AddTab("Average");
    fTabSum->SetLayoutManager(new TGVerticalLayout(fTabSum));
    // embedded canvas
    fSumSpectra = new TRootEmbeddedCanvas("SumHEC",fTabSum,fGUIsizeX-10,fGUIsizeY-110);
    Int_t wfSumSpectra = fSumSpectra->GetCanvasWindowId();
    cSumSpectra = new TCanvas("cSumSpectra", 10, 10, wfSumSpectra);
    fSumSpectra->AdoptCanvas(cSumSpectra);
    cSumSpectra->Divide(2,2);
    for (i=1; i<5; i++) {
        cSumSpectra->GetPad(i)->SetLogx();
        cSumSpectra->GetPad(i)->SetLogy();
    }
    fTabSum->AddFrame(fSumSpectra, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));

    // *** Container of "Arrow" ***
    fTabArrow = fTabHolder->AddTab("Arrow");
    fTabArrow->SetLayoutManager(new TGVerticalLayout(fTabArrow));
    fArrowECanvas = new TRootEmbeddedCanvas("ArrowHEC",fTabArrow,fGUIsizeX-10,fGUIsizeY-110);
    Int_t wfArrowECanvas = fArrowECanvas->GetCanvasWindowId();
    cArrowCanvas = new TCanvas("cArrowCanvas", 5, 5, wfArrowECanvas);
    // Draw compass circle
    TEllipse *el1 = new TEllipse(0.5,0.5,0.48,0.48);
    el1->SetFillColor(14);
    el1->SetFillStyle(1001);
    el1->SetLineColor(1);
    el1->SetLineWidth(6);
    el1->Draw();
    // Add bearing labels
    TText *north = new TText(0.5,0.9,"N");
    north->SetTextColor(2);
    north->SetTextSize(0.1);
    north->SetTextAlign(12);
    north->SetTextAlign(21);
    north->Draw();
    TText *south = new TText(0.5,0.04,"S");
    south->SetTextSize(0.1);
    south->SetTextAlign(12);
    south->SetTextAlign(21);
    south->Draw();
    TText *east = new TText(0.92,0.5,"E");
    east->SetTextSize(0.1);
    east->SetTextAlign(12);
    east->SetTextAlign(21);
    east->Draw();
    TText *west = new TText(0.08,0.5,"W");
    west->SetTextSize(0.1);
    west->SetTextAlign(12);
    west->SetTextAlign(21);
    west->Draw();
    // Draw initial arrow pointing North
    ar1 = new TArrow(0.5,0.3,0.5,0.7,0.3,"|>");
    ar1->SetAngle(30);
    ar1->SetLineWidth(5);
    ar1->SetFillColor(4);
    ar1->Draw();
    fArrowECanvas->AdoptCanvas(cArrowCanvas);
    fTabArrow->AddFrame(fArrowECanvas, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));

    // *** Container of "Config" ***
    fTabConfig = fTabHolder->AddTab("Config");
    fTabConfig->SetLayoutManager(new TGVerticalLayout(fTabConfig));

    // Acquisition time settings
    fControlFrame = new TGGroupFrame(fTabConfig, "Acquisition time [sec]");
    fControlFrame->SetTitlePos(TGGroupFrame::kCenter);


    // Acquisition time entry
    fAcqTimeFrame = new TGCompositeFrame(fControlFrame, 200, 10, kHorizontalFrame); 
  
    fAcqTimeSlider = new TGHSlider(fAcqTimeFrame,300,kSlider1 | kScaleBoth,-1);
    //fAcqTimeSlider = new TGHSlider(fControlFrame,300,kSlider1 | kScaleBoth,-1);
    fAcqTimeSlider->Connect("PositionChanged(Int_t)", "PigsGUI", this, "SetAcquisitionLoopTimeSlider()");
    //fAcqTimeSlider->Connect("PositionChanged(Int_t)", "TGLabel", fAcqTimeLabel, "SetText(Int_t)");
    fAcqTimeSlider->SetRange(1,6000); // time in 100 ms increments => [0.1 - 600 sec]
    fAcqTimeSlider->SetPosition(fDefaultAcqTime*10); // 10 second acquire time by default


    fAcqTimeFrame->AddFrame(fAcqTimeSlider, new TGLayoutHints(kLHintsNormal, 5, 5, 5, 5));

    //fAcqTimeEntry = new TGNumberEntry(fControlFrame, (Double_t) fDefaultAcqTime ,5,-1, TGNumberFormat::kNESRealOne, TGNumberFormat::kNEAPositive,TGNumberFormat::kNELLimitMinMax, 0.1, 600);
    fAcqTimeEntry = new TGNumberEntry(fAcqTimeFrame, (Double_t) fDefaultAcqTime ,5,-1, TGNumberFormat::kNESRealOne, TGNumberFormat::kNEAPositive,TGNumberFormat::kNELLimitMinMax, 0.1, 600);
    fAcqTimeEntry->GetNumberEntry()->SetToolTipText("Time for one DAQ loop in seconds.");
    fAcqTimeEntry->GetNumberEntry()->Connect("TextChanged(char*)", "PigsGUI", this,
            "SetAcquisitionLoopTimeNumberEntry()");
    fAcqTimeEntry->GetNumberEntry()->Connect("ReturnPressed()", "PigsGUI", this,
            "SetAcquisitionLoopTimeNumberEntry()");
    
    fAcqTimeFrame->AddFrame(fAcqTimeEntry, new TGLayoutHints(kLHintsNormal, 5, 5, 5, 5));
    //fControlFrame->AddFrame(fAcqTimeEntry, new TGLayoutHints(kLHintsNormal, 5, 5, 5, 5));
    
    // Disable acquisition time adjustment until DAQ initialized
    fAcqTimeEntry->SetState(kFALSE);
    fAcqTimeSlider->SetState(kFALSE);
/*
    fAcqTimeLabelFrame = new TGCompositeFrame(fTabConfig, 100, 10, kHorizontalFrame); 
    fAcqTimeLabelText = new TGLabel(fAcqTimeLabelFrame,"Acquire time:",
            uGC->GetGC(),ufont->GetFontStruct());
    fAcqTimeLabelText->SetTextJustify(kTextLeft);
    fAcqTimeLabelText->SetWrapLength(-1);
    fAcqTimeLabel = new TGLabel(fAcqTimeLabelFrame,"    ",
            uGC->GetGC(),ufont->GetFontStruct());
    fAcqTimeLabel->SetTextColor(0x0066ff);
    fAcqTimeLabel->SetTextJustify(kTextCenterX);
    fAcqTimeLabel->SetWrapLength(-1);
    fAcqTimeLabel->SetMinWidth(3);
    fAcqTimeLabelFrame->AddFrame(fAcqTimeLabelText, new TGLayoutHints(kLHintsLeft, 10, 5, 10, 10));
    fAcqTimeLabelFrame->AddFrame(fAcqTimeLabel, new TGLayoutHints(kLHintsRight, 0, 10, 10, 10 ));
  */ 
    fControlFrame->AddFrame(fAcqTimeFrame, new TGLayoutHints(kLHintsTop, 10, 10, 5, 5));
   // fControlFrame->AddFrame(fAcqTimeLabelFrame, new TGLayoutHints(kLHintsBottom, 10, 10, 5, 5));
    fTabConfig->AddFrame(fControlFrame, new TGLayoutHints(kLHintsNormal, 10, 10, 10, 10));    

    // Scale Factor setting
    fScalerFrame = new TGGroupFrame(fTabConfig, "Channel gain compensation");
    fScalerFrame->SetTitlePos(TGGroupFrame::kCenter);
    for (i=0; i<4; i++){
        fScalerInput[i] = new PigsScalerInput(fScalerFrame, Form("ch %d scaling", i));
        fScalerInput[i]->GetEntry()->Connect("TextChanged(char*)", "PigsGUI", this,
                Form("SetGainScalerCh%d()",i));
        fScalerInput[i]->GetEntry()->SetToolTipText(
                "Channel gain is a multiplicative factor used in detector response calculation.");
        fScalerFrame->AddFrame(fScalerInput[i], new TGLayoutHints(kLHintsNormal, 0, 0, 2, 2));
    }
    fTabConfig->AddFrame(fScalerFrame, new TGLayoutHints(kLHintsNormal, 10, 10, 10, 10));
    // Integration Limits
    fIntLimFrame = new TGGroupFrame(fTabConfig, "ADC window for integration");
    fIntLimFrame->SetTitlePos(TGGroupFrame::kCenter);
    fUseIntegration = new TGCheckButton(fIntLimFrame, "Energy integration On/Off");
    fUseIntegration->SetOn(kFALSE);         // Start with regular counts
    fUseIntegration->SetToolTipText("If enabled, the detector response is calculated by integrating "
            "the energy deposited in ADC bins within the limits specidied below.\n"
            "If disabled, the hit count is used as a detector response.");
    fUseIntegration->Connect("Toggled(Bool_t)", "PigsGUI", this, "ToggleUseIntegration()");
    fIntLimFrame->AddFrame(fUseIntegration, new TGLayoutHints(kLHintsNormal, 0, 0, 2, 2));
    fIntLimInputMin = new PigsIntLimInput(fIntLimFrame, "Lower limit");
    fIntLimInputMin->GetEntry()->SetIntNumber(fIntegralMin);
    fIntLimInputMin->GetEntry()->Connect("TextChanged(char*)", "PigsGUI", this, "SetIntegralLimitMin()");
    fIntLimFrame->AddFrame(fIntLimInputMin, new TGLayoutHints(kLHintsNormal, 0, 0, 2, 2));
    fIntLimInputMax = new PigsIntLimInput(fIntLimFrame, "Upper limit");
    fIntLimInputMax->GetEntry()->SetIntNumber(fIntegralMax);
    fIntLimInputMax->GetEntry()->Connect("TextChanged(char*)", "PigsGUI", this, "SetIntegralLimitMax()");
    fIntLimFrame->AddFrame(fIntLimInputMax, new TGLayoutHints(kLHintsNormal, 0, 0, 2, 2));
    fTabConfig->AddFrame(fIntLimFrame, new TGLayoutHints(kLHintsNormal, 10, 10, 10, 10));
    this->ToggleUseIntegration();           // Updates the integration entries' status

    // *** Container of "DT5781" ***
    fTabDT5781 = fTabHolder->AddTab("DT5781");
    fTabDT5781->SetLayoutManager(new TGVerticalLayout(fTabDT5781));
    gClient->GetColorByName("white", fColor);
    fDTinfo = new TGTextView(fTabDT5781,fGUIsizeX-120,fGUIsizeY-150,"DAQ not initialized.",kSunkenFrame,fColor);
    fTabDT5781->AddFrame(fDTinfo, new TGLayoutHints(kLHintsNormal));
    fDTinfo->MoveResize(10,50,fGUIsizeX-120,fGUIsizeY-150);
    fInitDAQ = new TGTextButton(fTabDT5781, "Init DAQ");            // button InitDAQ
    fInitDAQ->SetTextJustify(36);
    fInitDAQ->SetMargins(0,0,0,0);
    fInitDAQ->Resize(90,25);
    fMainGUIFrame->AddFrame(fInitDAQ, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
    gClient->GetColorByName("light blue", fColor);
    fInitDAQ->ChangeBackground(fColor);
    fInitDAQ->MoveResize(fGUIsizeX-50-60,50,90,25);
    fInitDAQ->Connect("Clicked()","PigsGUI",this,"InitDAQ()");
    fDisconnectDAQ = new TGTextButton(fTabDT5781, "Disconnect DAQ");  // buttons DisconnectDAQ
    fDisconnectDAQ->SetTextJustify(36);
    fDisconnectDAQ->SetMargins(0,0,0,0);
    fDisconnectDAQ->Resize(90,25);
    fMainGUIFrame->AddFrame(fDisconnectDAQ, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
    gClient->GetColorByName("light blue", fColor);
    fDisconnectDAQ->MoveResize(fGUIsizeX-50-60,150,90,25);
    fDisconnectDAQ->ChangeBackground(fColor);
    fDisconnectDAQ->Connect("Clicked()","PigsGUI",this,"DisconnectDAQ()");

    // *** Container of "About" ***
    fTabAbout = fTabHolder->AddTab("About");
    fTabAbout->SetLayoutManager(new TGVerticalLayout(fTabAbout));
    ufont = gClient->GetFont("-*-fixed-medium-r-*-*-15-*-*-*-*-*-*-*");
    fAboutText = new TGTextView(fTabAbout,1,1,"SPIGS",kSunkenFrame);
    fAboutText->SetFont(ufont->GetFontStruct());
    fTabAbout->AddFrame(fAboutText, new TGLayoutHints(kLHintsNormal));
    fAboutText->LoadBuffer(fAboutMsg);

    //-------------------------------------------------------------------------

    // Change to the starting tab
    fTabHolder->SetTab("DT5781");

    // Display the GUI
    fTabHolder->Resize(fTabHolder->GetDefaultSize());
    fMainGUIFrame->AddFrame(fTabHolder, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
    fTabHolder->MoveResize(0,32,fGUIsizeX-2,fGUIsizeY-80);

    fMainGUIFrame->SetMWMHints(kMWMDecorAll, kMWMFuncAll, kMWMInputModeless);
    fMainGUIFrame->MapSubwindows();
    fMainGUIFrame->Resize(fMainGUIFrame->GetDefaultSize());
    fMainGUIFrame->MapWindow();
    fMainGUIFrame->Resize(fGUIsizeX,fGUIsizeY);

    static const int32_t tmpw = 410;        // Constants for About window placement
    static const int32_t tmph = 260;
    fAboutText->MoveResize((fGUIsizeX-tmpw)/2,(fGUIsizeY-tmph)/3,tmpw,tmph);
}
Exemple #26
0
void diffXsect() {

//choice of systematic to look at
    int choice = 0;
    bool writeFile =true;

//MET will need choice of variable at the top
// TString Variable ="_MET";
// int Nbins = 6;
// TString bins[6] = {"_bin_0-25", "_bin_25-45", "_bin_45-70", "_bin_70-100", "_bin_100-150", "_bin_150-inf"};
// double width[6] = {25, 20, 25, 30, 50, 100};
// double xbins[7] = {1,25,45,70,100,150, 250};
// TString varBin = "Binned_MET_Analysis/patType1CorrectedPFMet";
// TString Xtitle = "MET [GeV]";

//HT
// TString Variable ="_HT";
// int Nbins = 8;
// TString bins[8] = {"_bin_0-50", "_bin_50-150", "_bin_150-250", "_bin_250-350", "_bin_350-450", "_bin_450-650", "_bin_650-1100", "_bin_1100-inf"};
// double width[8] = {50,100,100,100,100,200,450,400};
// double xbins[9] = {1,50,150,250,350,450,650,1100, 1500};
// TString varBin = "Binned_HT_Analysis/HT";
// TString Xtitle = "HT [GeV]";

//ST
    TString Variable ="_ST";
    int Nbins = 8;
    TString bins[8] = {"_bin_0-150", "_bin_150-250", "_bin_250-350", "_bin_350-450", "_bin_450-550", "_bin_550-750", "_bin_750-1250", "_bin_1250-inf"};
    double width[8] = {150,100,100,100,100,200,500,500};
    double xbins[9] = {1,150,250,350,450,550,750,1250, 1750};
    TString varBin = "Binned_ST_Analysis/ST_with_patType1CorrectedPFMet";
    TString Xtitle = "ST [GeV]";

//MT
// TString Variable ="_MT";
// int Nbins = 5;
// TString bins[5] = {"_bin_0-40", "_bin_40-65", "_bin_65-85", "_bin_85-150", "_bin_150-inf"};
// double width[5] = {40,25,20,65,50};
// double xbins[6] = {1,40,65,85,150,200};
// TString varBin = "Binned_MT_Analysis/MT_with_patType1CorrectedPFMet";
// TString Xtitle = "M(W)_{T} [GeV]";

//int Nsys = 1;
    int Nsys = 27;

//from fit
    double NfitVal[Nbins][Nsys];
    double NfitErr[Nbins][Nsys];
    double NttbarVal[Nbins][Nsys];
    double NttbarErr[Nbins][Nsys];
    double sigmaVal[Nbins][Nsys];
    double sigmaErr[Nbins][Nsys];

//before fit
    double madgraphVals[Nbins][Nsys];
    double mcatnloVals[Nbins][Nsys];
    double powhegVals[Nbins][Nsys];

    double ttbarPre[Nbins][Nsys];
    double singletPre[Nbins][Nsys];
    double wjetsPre[Nbins][Nsys];
    double zjetsPre[Nbins][Nsys];
    double qcdPre[Nbins][Nsys];
    double BGscale[Nbins][Nsys];
    double totXsect[Nsys];

//sample
//TString dir = "central";
//TString dir = "JES_up";
    TString dirs[27] = {"central","JES_up","JES_down", "BJet_up", "BJet_down", "PU_up", "PU_down", "Scale_up_tt", "Scale_down_tt", "Scale_up", "Scale_down", "Match_up_tt", "Match_down_tt", "Match_up", "Match_down", "UnclusteredEnUp", "UnclusteredEnDown", "JetEnUp", "JetEnDown", "JetResUp", "JetResDown", "TauEnUp", "TauEnDown", "MuonEnUp", "MuonEnDown", "ElectronEnUp", "ElectronEnDown"};

//loop over systematics
    for(int sys = 0; sys < Nsys; sys++) {
        TString dir  = dirs[sys];

        totXsect[sys]= 0;

        int rebinFact = 1;
//for ttbar total
        TH1D* tt_tot = getSample("TTJet", lumi*225.197/6920475, rebinFact, "Muon", dir);
        TH1D* mcnlo_tot = getSample("TTJet_MCNLO", lumi*225.197/6920475, rebinFact, "Muon", "central");
        TH1D* powheg_tot = getSample("TTJet_POWHEG", lumi*225.197/6920475, rebinFact, "Muon", "central");
//loop over bins of distribution
        for(int i = 0; i < Nbins; i++) {

            TString bin = varBin;

            if(dir == "UnclusteredEnUp" || dir == "UnclusteredEnDown" || dir == "JetEnUp" || dir == "JetEnDown" || dir == "JetResUp" || dir == "JetResDown" || dir == "TauEnUp" || dir == "TauEnDown" || dir == "MuonEnUp" || dir == "MuonEnDown" || dir == "ElectronEnUp" || dir == "ElectronEnDown")
                bin += dir;

            bin += bins[i];


            bool inclZ = false;
            bool inclW = false;

            if(dir == "Scale_up" || dir == "Scale_down" || dir == "Match_up" || dir == "Match_down") {
                inclZ = true;
                inclW = true;
            }

            cout <<  bin << endl;
            TH1D* tt = getSample("TTJet", lumi*225.197/6920475, rebinFact, bin, dir);
            TH1D* tt_mcnlo = getSample("TTJet_MCNLO", lumi*225.197/6920475, rebinFact, bin, "central");
            TH1D* tt_powheg = getSample("TTJet_POWHEG", lumi*225.197/6920475, rebinFact, bin, "central");

            TH1D* top_t = getSample("T_t-channel", lumi*56.4/3757707, rebinFact, bin, dir);
            TH1D* top_tw = getSample("T_tW-channel", lumi*11.1/497395, rebinFact, bin, dir);
            TH1D* top_s = getSample("T_s-channel", lumi*3.79/249516, rebinFact, bin, dir);
            TH1D* tbar_t = getSample("Tbar_t-channel", lumi*30.7/1934817, rebinFact, bin, dir);
            TH1D* tbar_tw = getSample("Tbar_tW-channel", lumi*11.1/493239, rebinFact, bin, dir);
            TH1D* tbar_s = getSample("Tbar_s-channel", lumi*1.76/139948, rebinFact, bin, dir);


            TH1D* wjets;
//TH1D* w1jets = getSample("W1Jet", lumi*5400.0/23140779, rebinFact, bin, dir);
            TH1D* w2jets = getSample("W2Jets", lumi*1750.0/34041404, rebinFact, bin, dir);
            TH1D* w3jets = getSample("W3Jets", lumi*519.0/15536443, rebinFact, bin, dir);
            TH1D* w4jets = getSample("W4Jets", lumi*214.0/13370904, rebinFact, bin, dir);

            TH1D* zjets;
//TH1D* z1jets = getSample("DY1JetsToLL", lumi*561.0/24042904, rebinFact, bin, dir);
            TH1D* z2jets = getSample("DY2JetsToLL", lumi*181.0/21835749, rebinFact, bin, dir);
            TH1D* z3jets = getSample("DY3JetsToLL", lumi*51.1/11010628, rebinFact, bin, dir);
            TH1D* z4jets = getSample("DY4JetsToLL", lumi*23.04/6391785, rebinFact, bin, dir);

            TH1D* qcd_mc = getSample("QCD_Pt-15to20_MuEnrichedPt5",   lumi*7.022e8 * 0.0039/1722678, rebinFact, bin, dir);
            TH1D* qcd2 = getSample("QCD_Pt-20to30_MuEnrichedPt5",   lumi*2.87e8 * 0.0065/8486893, rebinFact, bin, dir);
            TH1D* qcd3 = getSample("QCD_Pt-30to50_MuEnrichedPt5",   lumi*6.609e7 * 0.0122/8928999, rebinFact, bin, dir);
            TH1D* qcd4 = getSample("QCD_Pt-50to80_MuEnrichedPt5",   lumi*8082000.0 * 0.0218/7256011, rebinFact, bin, dir);
            TH1D* qcd5 = getSample("QCD_Pt-80to120_MuEnrichedPt5",  lumi*1024000.0 * 0.0395/9030624, rebinFact, bin, dir);
            TH1D* qcd6 = getSample("QCD_Pt-120to170_MuEnrichedPt5", lumi*157800.0 * 0.0473/8500505, rebinFact, bin, dir);
            TH1D* qcd7 = getSample("QCD_Pt-170to300_MuEnrichedPt5", lumi*34020.0 * 0.0676/7662483, rebinFact, bin, dir);
            TH1D* qcd8 = getSample("QCD_Pt-300to470_MuEnrichedPt5", lumi*1757.0 * 0.0864/7797481, rebinFact, bin, dir);
            TH1D* qcd9 = getSample("QCD_Pt-470to600_MuEnrichedPt5", lumi*115.2 * 0.1024/2995767, rebinFact, bin, dir);
            TH1D* qcd10 = getSample("QCD_Pt-800to1000_MuEnrichedPt5",lumi*3.57 * 0.1033/4047142, rebinFact, bin, dir);
            TH1D* qcd11 = getSample("QCD_Pt-1000_MuEnrichedPt5",     lumi*0.774 * 0.1097/3807263, rebinFact, bin, dir);

            qcd_mc->Add(qcd2);
            qcd_mc->Add(qcd3);
            qcd_mc->Add(qcd4);
            qcd_mc->Add(qcd5);
            qcd_mc->Add(qcd6);
            qcd_mc->Add(qcd7);
            qcd_mc->Add(qcd8);
            qcd_mc->Add(qcd9);
            qcd_mc->Add(qcd10);
            qcd_mc->Add(qcd11);

            if(inclZ == true) {
                zjets = getSample("DYJetsToLL", lumi*5745.25/30457954, rebinFact, bin, dir);

            } else {
                zjets  = getSample("DY1JetsToLL", lumi*561.0/24042904, rebinFact, bin, dir);
                zjets->Add(z2jets);
                zjets->Add(z3jets);
                zjets->Add(z4jets);
            }

            if(inclW == true) {
                wjets = getSample("WJetsToLNu", lumi*37509/57708550, rebinFact, bin, dir);
            } else {
                wjets = getSample("W1Jet", lumi*5400.0/23140779, rebinFact, bin, dir);
                wjets->Add(w2jets);
                wjets->Add(w3jets);
                wjets->Add(w4jets);
            }

//sum single top into one
            TH1D* single_top = (TH1D*)top_t->Clone("single top");
            single_top->Add(top_tw);
            single_top->Add(top_s);
            single_top->Add(tbar_t);
            single_top->Add(tbar_tw);
            single_top->Add(tbar_s);

            NfitVal[i][sys] = etaFit(bin, "measured",dir);
            NfitErr[i][sys] = etaFit(bin, "measuredErr",dir);
            BGscale[i][sys] = etaFit(bin,"bgscale",dir);

            NttbarVal[i][sys] = NfitVal[i][sys]-single_top->Integral();
            NttbarErr[i][sys] = NfitErr[i][sys] ;

            sigmaVal[i][sys] = ((NfitVal[i][sys]-single_top->Integral())/tt_tot->Integral())*225.197;
            sigmaErr[i][sys] = (((NfitVal[i][sys]+NfitErr[i][sys]-single_top->Integral())/tt_tot->Integral())*225.197)-sigmaVal[i][sys];

//cout << "error: " << sigmaErr[i][sys] << endl;

            madgraphVals[i][sys] = (tt->Integral()/tt_tot->Integral())*225.197;
            mcatnloVals[i][sys] = (tt_mcnlo->Integral()/mcnlo_tot->Integral())*225.197;
            powhegVals[i][sys] = (tt_powheg->Integral()/powheg_tot->Integral())*225.197;

            ttbarPre[i][sys] = tt->Integral();
            singletPre[i][sys] = single_top->Integral();
            wjetsPre[i][sys] = wjets->Integral();
            zjetsPre[i][sys] = zjets->Integral();
            qcdPre[i][sys] = qcd_mc->Integral();

            totXsect[sys] += sigmaVal[i][sys];
        }

    }

    //will need to change MET for other variables
    TFile resultsfile("outFiles/diffResults"+Variable+".root", "UPDATE", "comment");

    for(int sys = 0; sys < Nsys; sys++) {
        TString dir  = dirs[sys];

        resultsfile.mkdir(dir+"_dir");
        resultsfile.cd(dir+"_dir");

        //measured histo will have to put name of systematic in here to write into file
        TH1D *muon_part  = new TH1D(dir+"_signal_fit", "", Nbins, xbins);  //muon
        TH1D *ttbar_fit  = new TH1D(dir+"_ttbar_fit", "", Nbins, xbins);  //muon
        TH1D *ttbar_prefit  = new TH1D(dir+"_ttbar_prefit", "", Nbins, xbins);  //muon
        TH1D *singlet_prefit  = new TH1D(dir+"_singlet_prefit", "", Nbins, xbins);  //muon
        TH1D *wjets_prefit  = new TH1D(dir+"_wjets_prefit", "", Nbins, xbins);  //muon
        TH1D *zjets_prefit  = new TH1D(dir+"_zjets_prefit", "", Nbins, xbins);  //muon
        TH1D *qcd_prefit  = new TH1D(dir+"_qcd_prefit", "", Nbins, xbins);  //muon
        TH1D *wjets_fit  = new TH1D(dir+"_wjets_fit", "", Nbins, xbins);  //mu
        TH1D *zjets_fit  = new TH1D(dir+"_zjets_fit", "", Nbins, xbins);  //mu
        TH1D *qcd_fit  = new TH1D(dir+"_qcd_fit", "", Nbins, xbins);  //muon

//	muon_part->SetDirectory(directory);
        //loop over bins of distribution
        for(int i = 0; i < Nbins; i++) {
            muon_part->SetBinContent(i+1,NfitVal[i][sys]);
            muon_part->SetBinError(i+1, NfitErr[i][sys]);
            ttbar_fit->SetBinContent(i+1,NttbarVal[i][sys]);
            ttbar_fit->SetBinError(i+1, NttbarErr[i][sys]);
            ttbar_prefit->SetBinContent(i+1,ttbarPre[i][sys]);
            singlet_prefit->SetBinContent(i+1,singletPre[i][sys]);
            wjets_prefit->SetBinContent(i+1, wjetsPre[i][sys]);
            zjets_prefit->SetBinContent(i+1, zjetsPre[i][sys]);
            qcd_prefit->SetBinContent(i+1,  qcdPre[i][sys]);
            wjets_fit->SetBinContent(i+1, wjetsPre[i][sys]*BGscale[i][sys]);
            zjets_fit->SetBinContent(i+1, zjetsPre[i][sys]*BGscale[i][sys]);
            qcd_fit->SetBinContent(i+1,  qcdPre[i][sys]*BGscale[i][sys]);

        }

        resultsfile.cd();
    }

    if(writeFile ==true)
        resultsfile.Write();

    resultsfile.Close();


    cout << "N fit: " << endl;
    for(int i = 0; i < Nbins; i++) {
        cout << bins[i] << ": " << " = " << NfitVal[i][choice] << " +- " << NfitErr[i][choice] << endl;
    }

    cout << "partial xsects: " << endl;
    for(int i = 0; i < Nbins; i++) {
        cout << bins[i] << ": " << " = " << sigmaVal[i][choice] << " +- " << sigmaErr[i][choice] << endl;
//cout << bins[i] << ": " << " = " << madgraphVals[i] << endl;
    }

    cout << "normalised xsects: " << endl;
    for(int i = 0; i < Nbins; i++) {
        cout << bins[i] << ": " << " = " << sigmaVal[i][choice]/totXsect[choice] << endl;
    }

    cout << "normalised differential: " << endl;
    for(int i = 0; i < Nbins; i++) {
        cout << bins[i] << ": " << " = " << sigmaVal[i][choice]/(totXsect[choice]*width[i]) << endl;
    }
    cout << "cross section is:  " <<  totXsect[choice] << endl;

    //measured histo will have to put name of systematic in here to write into file
    TH1D *muon_part  = new TH1D("central", "", Nbins, xbins);  //muon

    //different generators
    TH1D *madgraph  = new TH1D("madgraph", "", Nbins, xbins);
    TH1D *mcatnlo  = new TH1D("mcatnlo", "", Nbins, xbins);
    TH1D *powheg  = new TH1D("powheg", "", Nbins, xbins);

    madgraph->SetLineColor(kRed);
    mcatnlo->SetLineColor(kBlue);
    powheg->SetLineColor(kGreen+2);
    for(int i = 0; i < Nbins; i++) {
        muon_part->SetBinContent(i+1,sigmaVal[i][choice]);
        muon_part->SetBinError(i+1, sigmaErr[i][choice]);

        madgraph->SetBinContent(i+1,madgraphVals[i][choice]);
        madgraph->SetBinError(i+1,0.0);
        mcatnlo->SetBinContent(i+1,mcatnloVals[i][choice]);
        mcatnlo->SetBinError(i+1,0.0);
        powheg->SetBinContent(i+1,powhegVals[i][choice]);
        powheg->SetBinError(i+1,0.0);
    }


    //do the plots
    TCanvas *c= new TCanvas("c","c",10,10,800,600);

    muon_part->SetMarkerStyle(20);
    muon_part->Draw("E");
    muon_part->SetMaximum(muon_part->GetBinContent(muon_part->GetMaximumBin())*1.5);
    muon_part->SetMinimum(0.);


    mcatnlo->Draw("same");
    powheg->Draw("same");
    madgraph->Draw("same");
    TLegend *tleg;
    tleg = new TLegend(0.6,0.75,0.85,0.9);
    tleg->SetTextSize(0.03);
    tleg->SetBorderSize(0);
    tleg->SetFillColor(10);

    tleg->AddEntry(muon_part  , "data '12'"      , "lep");
    tleg->AddEntry(madgraph  , "MadGraph"      , "l");
    tleg->AddEntry(mcatnlo  , "MC@NLO"      , "l");
    tleg->AddEntry(powheg  , "POWHEG"      , "l");
    tleg->Draw();
    //titles
    muon_part->GetYaxis()->SetTitle("#partial #sigma [pb]");
    muon_part->GetYaxis()->SetTitleSize(0.05);
    muon_part->GetXaxis()->SetTitle(Xtitle);
    muon_part->GetXaxis()->SetTitleSize(0.05);


    TText* textPrelim = doPrelim(0.16,0.96);
    textPrelim->Draw();

    c->SaveAs("plots/Measurments/partialXsect"+Variable+".pdf");

    //normailise
    for(int i = 0; i < Nbins; i++) {

        muon_part->SetBinContent(i+1,sigmaVal[i][choice]/totXsect[choice]);
        muon_part->SetBinError(i+1,sigmaErr[i][choice]/totXsect[choice]);
//	muon_norm_diff->SetBinContent(i+1,sigmaVal[i]/(totXsect*width));

        madgraph->SetBinContent(i+1,madgraphVals[i][choice]/225.197);
        madgraph->SetBinError(i+1,0.0/225.197);
        mcatnlo->SetBinContent(i+1,mcatnloVals[i][choice]/225.197);
        mcatnlo->SetBinError(i+1,0.0/225.197);
        powheg->SetBinContent(i+1,powhegVals[i][choice]/225.197);
        powheg->SetBinError(i+1,0.0/225.197);

    }
    delete c;

    TCanvas *c2= new TCanvas("c2","c2",10,10,800,600);

    muon_part->SetMarkerStyle(20);

    muon_part->Draw("E");
    muon_part->SetMaximum(muon_part->GetBinContent(muon_part->GetMaximumBin())*1.5);


    mcatnlo->Draw("same");
    powheg->Draw("same");
    madgraph->Draw("same");

    tleg->Draw();

    //titles
    muon_part->GetYaxis()->SetTitle("#frac{1}{#sigma} #partial #sigma [pb GeV^{-1}]");
    muon_part->GetYaxis()->SetTitleSize(0.05);
    //muon_part->GetXaxis()->SetTitle(Xtitle);
    //muon_part->GetXaxis()->SetTitleSize(0.05);

    textPrelim->Draw();

    c2->SaveAs("plots/Measurments/partialXsectNorm"+Variable+".pdf");

    //normailise and differential
    for(int i = 0; i < Nbins; i++) {
        double width = muon_part->GetBinWidth(i+1);

        muon_part->SetBinContent(i+1,sigmaVal[i][choice]/(totXsect[choice]*width));
        muon_part->SetBinError(i+1,sigmaErr[i][choice]/(totXsect[choice]*width));

        madgraph->SetBinContent(i+1,madgraphVals[i][choice]/(225.197*width));
        madgraph->SetBinError(i+1,0.0/(225.197*width));
        mcatnlo->SetBinContent(i+1,mcatnloVals[i][choice]/(225.197*width));
        mcatnlo->SetBinError(i+1,0.0/(225.197*width));
        powheg->SetBinContent(i+1,powhegVals[i][choice]/(225.197*width));
        powheg->SetBinError(i+1,0.0/(225.197*width));
    }
    delete c2;

    TCanvas *c3= new TCanvas("c3","c3",10,10,800,600);

    muon_part->SetMarkerStyle(20);
    muon_part->Draw("E");
    muon_part->SetMaximum(muon_part->GetBinContent(muon_part->GetMaximumBin())*1.5);


    mcatnlo->Draw("same");
    powheg->Draw("same");
    madgraph->Draw("same");

    tleg->Draw();

    //titles
    muon_part->GetYaxis()->SetTitle("#frac{1}{#sigma} #frac{#partial #sigma}{#partial MET} 				[GeV^{-1}]");
    muon_part->GetYaxis()->SetTitleSize(0.05);
    //muon_part->GetXaxis()->SetTitle("MET [GeV]");
    //muon_part->GetXaxis()->SetTitleSize(0.05);

    textPrelim->Draw();

    c3->SaveAs("plots/Measurments/partialXsectNormDiff"+Variable+".pdf");
    delete c3;


}
Exemple #27
0
void tree() {
   //
   // This macro displays the Tree data structures
   //Author: Rene Brun
   TCanvas* c1 = new TCanvas("c1","Tree Data Structure",200,10,750,940);
   c1->Range(0,-0.1,1,1.15);

   gBenchmark->Start("tree");

   Int_t branchcolor = 26;
   Int_t leafcolor   = 30;
   Int_t basketcolor = 42;
   Int_t offsetcolor = 43;
   TPaveLabel* title = new TPaveLabel(.3,1.05,.8,1.13,c1->GetTitle());
   title->SetFillColor(16);
   title->Draw();
   TPaveText* treePave = new TPaveText(.01,.75,.15,1.00);
   treePave->SetFillColor(18);
   treePave->SetTextAlign(12);
   TText *tnt = treePave->AddText("Tree");
   tnt->SetTextAlign(22);
   tnt->SetTextSize(0.030);
   treePave->AddText("fScanField");
   treePave->AddText("fMaxEventLoop");
   treePave->AddText("fMaxVirtualSize");
   treePave->AddText("fEntries");
   treePave->AddText("fDimension");
   treePave->AddText("fSelectedRows");
   treePave->Draw();
   TPavesText* farm = new TPavesText(.01,1.02,.15,1.1,9,"tr");
   TText *tfarm = farm->AddText("CHAIN");
   tfarm->SetTextSize(0.024);
   farm->AddText("Collection");
   farm->AddText("of Trees");
   farm->Draw();
   TLine* llink = new TLine(.15,.92,.80,.92);
   llink->SetLineWidth(2);
   llink->SetLineColor(1);
   llink->Draw();
   llink->DrawLine(.21,.87,.21,.275);
   llink->DrawLine(.23,.87,.23,.375);
   llink->DrawLine(.25,.87,.25,.775);
   llink->DrawLine(.41,.25,.41,-.025);
   llink->DrawLine(.43,.25,.43,.075);
   llink->DrawLine(.45,.25,.45,.175);
   TPaveLabel* branch0 = new TPaveLabel(.20,.87,.35,.97,"Branch 0");
   branch0->SetTextSize(0.35);
   branch0->SetFillColor(branchcolor);
   branch0->Draw();
   TPaveLabel* branch1 = new TPaveLabel(.40,.87,.55,.97,"Branch 1");
   branch1->SetTextSize(0.35);
   branch1->SetFillColor(branchcolor);
   branch1->Draw();
   TPaveLabel* branch2 = new TPaveLabel(.60,.87,.75,.97,"Branch 2");
   branch2->SetTextSize(0.35);
   branch2->SetFillColor(branchcolor);
   branch2->Draw();
   TPaveLabel* branch3 = new TPaveLabel(.80,.87,.95,.97,"Branch 3");
   branch3->SetTextSize(0.35);
   branch3->SetFillColor(branchcolor);
   branch3->Draw();
   TPaveLabel* leaf0 = new TPaveLabel(.4,.75,.5,.8,"Leaf 0");
   leaf0->SetFillColor(leafcolor);
   leaf0->Draw();
   TPaveLabel* leaf1 = new TPaveLabel(.6,.75,.7,.8,"Leaf 1");
   leaf1->SetFillColor(leafcolor);
   leaf1->Draw();
   TPaveLabel* leaf2 = new TPaveLabel(.8,.75,.9,.8,"Leaf 2");
   leaf2->SetFillColor(leafcolor);
   leaf2->Draw();
   TPaveText* firstevent = new TPaveText(.4,.35,.9,.4);
   firstevent->AddText("First event of each basket");
   firstevent->AddText("Array of fMaxBaskets Integers");
   firstevent->SetFillColor(basketcolor);
   firstevent->Draw();
   TPaveLabel* basket0 = new TPaveLabel(.4,.25,.5,.3,"Basket 0");
   basket0->SetFillColor(basketcolor);
   basket0->Draw();
   TPaveLabel* basket1 = new TPaveLabel(.6,.25,.7,.3,"Basket 1");
   basket1->SetFillColor(basketcolor);
   basket1->Draw();
   TPaveLabel* basket2 = new TPaveLabel(.8,.25,.9,.3,"Basket 2");
   basket2->SetFillColor(basketcolor);
   basket2->Draw();

   TPaveText* offset = new TPaveText(.55,.15,.9,.2);
   offset->AddText("Offset of events in fBuffer");
   offset->AddText("Array of fEventOffsetLen Integers");
   offset->AddText("(if variable length structure)");
   offset->SetFillColor(offsetcolor);
   offset->Draw();
   TPaveText* buffer = new TPaveText(.55,.05,.9,.1);
   buffer->AddText("Basket buffer");
   buffer->AddText("Array of fBasketSize chars");
   buffer->SetFillColor(offsetcolor);
   buffer->Draw();
   TPaveText* zipbuffer = new TPaveText(.55,-.05,.75,.0);
   zipbuffer->AddText("Basket compressed buffer");
   zipbuffer->AddText("(if compression)");
   zipbuffer->SetFillColor(offsetcolor);
   zipbuffer->Draw();
   TArrow* ar1 = new TArrow();
   ar1->SetLineWidth(2);
   ar1->SetLineColor(1);
   ar1->SetFillStyle(1001);
   ar1->SetFillColor(1);
   ar1->DrawArrow(.21,.275,.39,.275,0.015,"|>");
   ar1->DrawArrow(.23,.375,.39,.375,0.015,"|>");
   ar1->DrawArrow(.25,.775,.39,.775,0.015,"|>");
   ar1->DrawArrow(.50,.775,.59,.775,0.015,"|>");
   ar1->DrawArrow(.70,.775,.79,.775,0.015,"|>");
   ar1->DrawArrow(.50,.275,.59,.275,0.015,"|>");
   ar1->DrawArrow(.70,.275,.79,.275,0.015,"|>");
   ar1->DrawArrow(.45,.175,.54,.175,0.015,"|>");
   ar1->DrawArrow(.43,.075,.54,.075,0.015,"|>");
   ar1->DrawArrow(.41,-.025,.54,-.025,0.015,"|>");
   TLine* ldot = new TLine(.95,.92,.99,.92);
   ldot->SetLineStyle(3);
   ldot->Draw();
   ldot->DrawLine(.9,.775,.99,.775);
   ldot->DrawLine(.9,.275,.99,.275);
   ldot->DrawLine(.55,.05,.55,0);
   ldot->DrawLine(.9,.05,.75,0);
   TText* pname = new TText(.46,.21,"fEventOffset");
   pname->SetTextFont(72);
   pname->SetTextSize(0.018);
   pname->Draw();
   pname->DrawText(.44,.11,"fBuffer");
   pname->DrawText(.42,.01,"fZipBuffer");
   pname->DrawText(.26,.81,"fLeaves = TObjArray of TLeaf");
   pname->DrawText(.24,.40,"fBasketEvent");
   pname->DrawText(.22,.31,"fBaskets = TObjArray of TBasket");
   pname->DrawText(.20,1.0,"fBranches = TObjArray of TBranch");
   TPaveText* ntleaf = new TPaveText(0.30,.42,.62,.7);
   ntleaf->SetTextSize(0.014);
   ntleaf->SetFillColor(leafcolor);
   ntleaf->SetTextAlign(12);
   ntleaf->AddText("fLen: number of fixed elements");
   ntleaf->AddText("fLenType: number of bytes of data type");
   ntleaf->AddText("fOffset: relative to Leaf0-fAddress");
   ntleaf->AddText("fNbytesIO: number of bytes used for I/O");
   ntleaf->AddText("fIsPointer: True if pointer");
   ntleaf->AddText("fIsRange: True if leaf has a range");
   ntleaf->AddText("fIsUnsigned: True if unsigned");
   ntleaf->AddText("*fLeafCount: points to Leaf counter");
   ntleaf->AddText(" ");
   ntleaf->AddLine(0,0,0,0);
   ntleaf->AddText("fName = Leaf name");
   ntleaf->AddText("fTitle = Leaf type (see Type codes)");
   ntleaf->Draw();
   TPaveText* type = new TPaveText(.65,.42,.95,.7);
   type->SetTextAlign(12);
   type->SetFillColor(leafcolor);
   type->AddText(" ");
   type->AddText("C : a character string");
   type->AddText("B : an 8 bit signed integer");
   type->AddText("b : an 8 bit unsigned integer");
   type->AddText("S : a 16 bit signed short integer");
   type->AddText("s : a 16 bit unsigned short integer");
   type->AddText("I : a 32 bit signed integer");
   type->AddText("i : a 32 bit unsigned integer");
   type->AddText("F : a 32 bit floating point");
   type->AddText("D : a 64 bit floating point");
   type->AddText("TXXXX : a class name TXXXX");
   type->Draw();
   TPaveLabel* typecode = new TPaveLabel(.7,.68,.9,.72,"fType codes");
   typecode->SetFillColor(leafcolor);
   typecode->Draw();
   ldot->DrawLine(.4,.75,.30,.7);
   ldot->DrawLine(.5,.75,.62,.7);
   TPaveText* ntbasket = new TPaveText(0.02,-0.07,0.35,.25);
   ntbasket->SetFillColor(basketcolor);
   ntbasket->SetTextSize(0.014);
   ntbasket->SetTextAlign(12);
   ntbasket->AddText("fNbytes: Size of compressed Basket");
   ntbasket->AddText("fObjLen: Size of uncompressed Basket");
   ntbasket->AddText("fDatime: Date/Time when written to store");
   ntbasket->AddText("fKeylen: Number of bytes for the key");
   ntbasket->AddText("fCycle : Cycle number");
   ntbasket->AddText("fSeekKey: Pointer to Basket on file");
   ntbasket->AddText("fSeekPdir: Pointer to directory on file");
   ntbasket->AddText("fClassName: 'TBasket'");
   ntbasket->AddText("fName: Branch name");
   ntbasket->AddText("fTitle: TreePave name");
   ntbasket->AddText(" ");
   ntbasket->AddLine(0,0,0,0);
   ntbasket->AddText("fNevBuf: Number of events in Basket");
   ntbasket->AddText("fLast: pointer to last used byte in Basket");
   ntbasket->Draw();
   ldot->DrawLine(.4,.3,0.02,0.25);
   ldot->DrawLine(.5,.25,0.35,-.07);
   ldot->DrawLine(.5,.3,0.35,0.25);
   TPaveText* ntbranch = new TPaveText(0.02,0.40,0.18,0.68);
   ntbranch->SetFillColor(branchcolor);
   ntbranch->SetTextSize(0.015);
   ntbranch->SetTextAlign(12);
   ntbranch->AddText("fBasketSize");
   ntbranch->AddText("fEventOffsetLen");
   ntbranch->AddText("fMaxBaskets");
   ntbranch->AddText("fEntries");
   ntbranch->AddText("fAddress of Leaf0");
   ntbranch->AddText(" ");
   ntbranch->AddLine(0,0,0,0);
   ntbranch->AddText("fName: Branchname");
   ntbranch->AddText("fTitle: leaflist");
   ntbranch->Draw();
   ldot->DrawLine(.2,.97,.02,.68);
   ldot->DrawLine(.35,.97,.18,.68);
   ldot->DrawLine(.35,.87,.18,.40);
   TPavesText* basketstore = new TPavesText(.8,-0.088,0.952,-0.0035,7,"tr");
   basketstore->SetFillColor(28);
   basketstore->AddText("Baskets");
   basketstore->AddText("Stores");
   basketstore->Draw();
   c1->Update();

   gBenchmark->Show("treePave");
}
Exemple #28
0
void plot2d(int hid) {
  gStyle->SetOptStat(0);
  char c[50];
  c1->Clear();
  if(hid!=2 && hid!=4){
    c1->Divide(2,3);
    for(int disc=0; disc<kFgtNumDiscs; disc++){
      TPad *pad = c1->cd(disc+1);
      pad->SetLogz(1);
      pad->SetTopMargin(0.01);   pad->SetBottomMargin(0.02);
      sprintf(c,"Disc%1d%s",disc+1,c2dHist[hid]);
      //printf("Getting %s\n",c);
      TH2F *h = hist2[disc][hid] = (TH2F*)file->Get(c);
      h->Draw("COLZ");  
    }
  }else if(hid==2){  // special case for timing per APVboard
    gStyle->SetOptTitle(0);
    gStyle->SetOptFit(0);
    c1->Divide(2,1);
    char txt[100];
    //int disc=3; char name[100]="MaxAdc";
    int disc=4; char name[100]="LandauMPV";
    //int disc=5; char name[100]="LandauMPV-3Sing";
    TVirtualPad *pad2 = c1->cd(1);
    pad2->Divide(1,2); 
    TVirtualPad *pad3=pad2->cd(1);
    pad3->SetLogz(1);  pad2->SetLogz(0); 
    sprintf(c,"Disc%1d%s",disc,c2dHist[hid]);
    TH2F *h = hist2[disc][hid] = (TH2F*)file->Get(c);
    h->Draw("COLZ");
    TText *tt1= new TText(0.05,0.1,"(RDO-1)*12+ARM*2+GRP"); tt1->SetTextAngle(90); tt1->SetNDC(); tt1->Draw();    
    sprintf(txt,"Tbin for %s",name);
    TText *tt2= new TText(0.3,0,txt); tt2->SetNDC(); tt2->Draw();
    
    TVirtualPad* pad4 = c1->cd(2);
    pad4->SetTopMargin(0.01); pad4->SetBottomMargin(0.1);
    int maxid=0;
    float off,max=0;
    TH1D *h1[24];
    float mean[24];
    for(int i=0; i<24; i++){
      char ccc[10]; sprintf(ccc,"_%d_%d",disc,i);
      h1[i] = h->ProjectionX(ccc,i+1,i+1); 
      if(h1[i]->GetMaximum() > max && i!=0) {max=h1[i]->GetMaximum(); maxid=i; }
    }
    off=max/4.0;
    printf("max=%f off=%f\n",max,off);
    for(int i=0; i<24; i++){
      h1[i]->GetXaxis()->SetRangeUser(2,11);
      int res = h1[i]->Fit("gaus","0Q");
      TF1* f=h1[i]->GetFunction("gaus");
      if(h1[i]->GetMaximum()>max/3 && res==0){
	mean[i] = f->GetParameter(1);
	//mean[i]=h1[i]->GetMean();
      }else{mean[i]=0;};
      //printf("%d mean=%f\n",i,mean[i]);
    }
    //h1[maxid]->SetLineColor(maxid+1); h1[maxid]->SetLineWidth(2); h1[maxid]->Draw("PL");
    for(int rdo=1; rdo<=2; rdo++){
      for(int arm=0; arm<6; arm++){
	for(int grp=0; grp<2; grp++){
	  i=(rdo-1)*12+arm*2+grp;
	  int nb=h1[i]->GetNbinsX();
	  for(int t=0; t<nb; t++){ h1[i]->AddBinContent(t+1,off*i); }
	  h1[i]->SetLineColor(i%6+1); h1[i]->SetLineWidth(3);
	  if(i==0) {
	    h1[i]->SetMinimum(0);
	    h1[i]->SetMaximum(max*6.5);
	    h1[i]->Draw("PL");
	  } else {h1[i]->Draw("PL same");}	
	  char name[100]; 
	  sprintf(name,"Rdo%1dArm%1dGrp%1d",rdo,arm,grp);
	  TText *tx = new TText(8.5,(max/4.0)*(i+0.2),name); tx->SetTextColor(i%6+1); tx->SetTextSize(0.03);
	  tx->Draw();
	}
      }
    }
    //    TText *tt3= new TText(0.95,0.1,"offsets added by (RDO-1)*12+ARM*2+GRP"); tt3->SetTextAngle(90); tt3->SetNDC(); tt3->Draw();
    TText *tt4= new TText(0.4,0,txt); tt4->SetNDC(); tt4->Draw();
    
    //correlation
    float t2[24]={-8.47, -5.16, -0.21, -2.23,  1.11, -4.09, 
		  -3.13, -9.08, -5.88, -7.01, -6.22, -9.79,  
		  0.75, -8.91,  0.16,  1.12, -0.99, -4.56,  
		  7.57, -3.68,  7.12, -6.54, -4.08, -8.21};
    TGraph *g= new TGraph(1);
    int j=0;
    for(int i=0; i<24; i++){
      if(mean[i]>0) {g->SetPoint(j,(mean[i]-6.0)*27,t2[i]); j++;}
    }
    TVirtualPad* pad5=pad2->cd(2);
    g->SetMarkerStyle(20+i/6); g->SetMarkerSize(1);
    g->Draw("ap");
    for(int i=0; i<24; i++){
      TGraph *g2= new TGraph(1);
      if(mean[i]>0) {g2->SetPoint(j,(mean[i]-6.0)*27,t2[i]); j++;}
      g2->SetMarkerStyle(20+i/6); g2->SetMarkerSize(2); g2->SetMarkerColor(i%6+1);
      g2->Draw("p");
    }
    
    TText *tt5= new TText(0.05,0.1,"(VPHASE_ADC-1.2V)/0.95V*27nsec/2"); tt5->SetTextAngle(90); tt5->SetNDC(); tt5->Draw();
    TText *tt6= new TText(0.5,0,"(Tbin-6)*27nsec"); tt6->SetNDC(); tt6->Draw(); 
  }else{  // special case for timing per APVboard
    gStyle->SetOptTitle(0);
    gStyle->SetOptFit(0);
    c1->Divide(4,6);
    char txt[100];
    //int disc=3; char name[100]="MaxAdc";
    int disc=4; char name[100]="LandauMPV";
    //int disc=5; char name[100]="LandauMPV-3Sing";
    sprintf(c,"Disc%1d%s",disc,c2dHist[2]);
    TH2F *h = hist2[disc][2] = (TH2F*)file->Get(c);
    TH1D *h1[24];
    float mean[24];
    for(int rdo=1; rdo<=2; rdo++){
      for(int arm=0; arm<6; arm++){
	for(int grp=0; grp<2; grp++){   
	  int i=(rdo-1)*12+arm*2+grp;
	  TVirtualPad *pad2 = c1->cd(i+1);
	  pad2->SetTopMargin(0.01); pad2->SetBottomMargin(0.1);
	  char ccc[10]; sprintf(ccc,"_%d_%d",disc,i);
	  h1[i]=h->ProjectionX(ccc,i+1,i+1);       
	  h1[i]->GetXaxis()->SetRangeUser(2,12); h1[i]->SetFillColor(4);
	  h1[i]->GetXaxis()->SetLabelSize(0.1); h1[i]->GetYaxis()->SetLabelSize(0.1);
	  h1[i]->Draw(); 
	  int res = h1[i]->Fit("gaus","Q");
	  TF1* f=h1[i]->GetFunction("gaus"); f->SetLineColor(2); f->SetLineWidth(2);
	  if(res==0){
	    mean[i] = f->GetParameter(1);
	  }else{mean[i]=0;};
	  char name[100]; 
	  sprintf(name,"Rdo%1dArm%1d-%1d",rdo,arm,grp);
	  TText *tx = new TText(0.5,0.85,name); tx->SetTextSize(0.1); tx->SetNDC();
	  tx->Draw();
	  if(mean[i]>0){
	    sprintf(name,"peak=%4.1f",mean[i]);
	    TText *tx2 = new TText(0.55,0.75,name); tx2->SetTextSize(0.12); tx2->SetNDC();
	    tx2->Draw();
	  }
	}
      }
    }
  }
  c1->Update();
  save(c2dHist[hid]);
}
void balanceMetVsAj(TString infname = "dj_HCPR-J50U-hiGoodMergedTracks_OfficialSelv2_Final0_120_50.root",
                    TCut myCut = "cent<30", char *title = "",bool drawLegend = false,
                    bool drawSys = true
		    )
{
   // ===========================================================
   // Get Input
   // ===========================================================
   TFile *inf = new TFile(infname);
   TTree *t = (TTree*)inf->Get("ntjt");


   t->SetAlias("metxMergedAll","(metOutOfConex0+metOutOfConex1+metOutOfConex2+metOutOfConex3+metOutOfConex4+metOutOfConex5)");
   t->SetAlias("metxMerged0","(metOutOfConex0)");
   t->SetAlias("metxMerged1","(metOutOfConex1)");
   t->SetAlias("metxMerged2","(metOutOfConex2)");
   t->SetAlias("metxMerged3","(metOutOfConex3)");
   t->SetAlias("metxMerged4","(metOutOfConex4+metOutOfConex5)");

   // ===========================================================
   // Analysis Setup
   // ===========================================================
   const int nBin = 5;
   double bins[nBin+1] = {0.5,1.0,1.5,4,8,1000};
   int colors[5] = {kBlue-10,kYellow-7, kOrange-2,kGreen-5,kRed-3};
   
   const int nBinAj = 4;
   double ajBins[nBinAj+1] = {0.0001,0.11,0.22,0.33,0.49999};
   // Selection cut
   TCut evtCut = "nljet>120&&abs(nljetacorr)<2&&aljet>50&&abs(aljetacorr)<2&&jdphi>2./3*TMath::Pi()&&!maskEvt";
//   TCut evtCut = "nljet>120&&abs(nljetacorr)<2&&aljet>50&&abs(aljetacorr)<2&&jdphi>3&&!maskEvt";

   cout << "Sel evt: " << t->GetEntries(evtCut&&myCut) << endl;

   // ===========================================================
   // Find Average Weights
   // ===========================================================
   TH1D *hw[nBinAj];
   float meanWt[nBinAj];
   for ( int iaj = 0 ; iaj< nBinAj ; iaj++) {
      hw[iaj] = new TH1D(Form("hw_aj%d",iaj),"",1000,0,100);
      TCut ajCut = Form("Aj>%f && Aj<%f", ajBins[iaj],ajBins[iaj+1]);
      t->Draw(Form("weight>>hw_aj%d",iaj), evtCut&&myCut&&ajCut);
      meanWt[iaj] = hw[iaj]->GetMean();
      cout << " <Weight>: " << meanWt[iaj] << endl;
   }

   // ===========================================================
   // Draw Weighted Averages
   // ===========================================================
   TH1D *ppos[nBin];
   TH1D *pneg[nBin];
   TH1D *pe[nBin];
   for (int i=0;i<nBin;i++)
   {
      TH1D *h1 = new TH1D(Form("h1%d",i),"",nBinAj,ajBins);
      TH1D *h2 = new TH1D(Form("h2%d",i),"",nBinAj,ajBins);
      TH1D *he[nBinAj];
      
      // =================================
      // Get Weighted Mean for each Aj bin
      // =================================
      h1->Sumw2();
      h2->Sumw2();
      t->Draw(Form("Aj>>h1%d",i), "weight"*(evtCut&&myCut));
      t->Draw(Form("Aj>>h2%d",i), Form("((-weight*metxMerged%d))",i)*(evtCut&&myCut));
      
      pe[i]=(TH1D*)h2->Clone();
      pe[i]->SetName(Form("p%d",i));     
      pe[i]->Divide(h1);
      ppos[i] = new TH1D(Form("ppos%d",i),"",nBinAj,ajBins);
      ppos[i]->SetLineColor(1);     
      ppos[i]->SetMarkerColor(colors[i]);
      ppos[i]->SetFillColor(colors[i]);
      ppos[i]->SetFillStyle(1001);
      pneg[i] = new TH1D(Form("pneg%d",i),"",nBinAj,ajBins);
      pneg[i]->SetLineColor(1);     
      pneg[i]->SetMarkerColor(colors[i]);
      pneg[i]->SetFillColor(colors[i]);
      pneg[i]->SetFillStyle(1001);

      // =================================
      // Caculated Stat Error of the Mean
      // =================================
      cout << "Stat Error for pt bin " << i << ": ";
      for ( int iaj = 0 ; iaj< nBinAj ; iaj++) {
         he[iaj] = new TH1D(Form("he%d_aj%d",i,iaj),"",100,-200,200);
         TCut ajCut = Form("Aj>%f && Aj<%f", ajBins[iaj],ajBins[iaj+1]);
         t->Draw(Form("((metxMerged%d))>>he%d_aj%d",i,i,iaj), "weight" * evtCut&&myCut&&ajCut);
         float theError = he[iaj]->GetRMS()/ (sqrt(he[iaj]->GetEntries()));
	 cout << theError << " ";
	 pe[i]->SetBinError(iaj+1, theError);
      }
      cout << endl;
   }

   // Stack
   for (int i=nBin-1;i>=0;i--)
   {
      for(int iaj = 0 ; iaj< nBinAj ; iaj++) {
         double posVal=0, negVal=0;
         double posValErr=0, negValErr=0;
         if (i!=nBin-1) {
            posVal = ppos[i+1]->GetBinContent(iaj+1);
            posValErr = ppos[i+1]->GetBinError(iaj+1);
            negVal = pneg[i+1]->GetBinContent(iaj+1);
            negValErr = pneg[i+1]->GetBinError(iaj+1);
         }
         if (pe[i]->GetBinContent(iaj+1)<0) {
            negVal+=pe[i]->GetBinContent(iaj+1);
            negValErr=pe[i]->GetBinError(iaj+1);
            posValErr=0;
         } else if (pe[i]->GetBinContent(iaj+1)>0) {
            posVal+=pe[i]->GetBinContent(iaj+1);
            posValErr=pe[i]->GetBinError(iaj+1);
            negValErr=0;
         } 
         ppos[i]->SetBinContent(iaj+1,posVal);
         ppos[i]->SetBinError(iaj+1,posValErr);
         pneg[i]->SetBinContent(iaj+1,negVal);
         pneg[i]->SetBinError(iaj+1,negValErr);
      }
   }
   
   TH1D *pall;
   TH1D *pallE;
   TH1D *h1 = new TH1D(Form("hAll1"),"",nBinAj,ajBins);
   TH1D *h2 = new TH1D(Form("hAll2"),"",nBinAj,ajBins);

   h1->Sumw2();
   h2->Sumw2();
   t->Draw(Form("Aj>>hAll1"), "weight"*(evtCut&&myCut));
   t->Draw(Form("Aj>>hAll2"), Form("((-weight*metxMergedAll))")*(evtCut&&myCut));
   pall=(TH1D*)h2->Clone();
   pall->SetName("pall");
   pall->Divide(h1);

   // replace the sys error from pallE to pall 
   TH1D *he[nBinAj];
   cout << "Stat Error for All pt: ";
   for ( int iaj = 0 ; iaj< nBinAj ; iaj++) {
      he[iaj] = new TH1D(Form("heAll_aj%d",iaj),"",100,-200,200);
      TCut ajCut = Form("Aj>%f && Aj<%f", ajBins[iaj],ajBins[iaj+1]);
      t->Draw(Form("((metxMergedAll))>>heAll_aj%d",iaj), "weight" * evtCut&&myCut&&ajCut);
      float theError = he[iaj]->GetRMS()/ (sqrt(he[iaj]->GetEntries()));
      cout << theError << " ";
      pall->SetBinError(iaj+1,  theError);
   }
   cout << endl;

   pall->SetXTitle("A_{J}");
   pall->SetYTitle("<#slash{p}_{T}^{#parallel}> (GeV/c)");
   pall->GetXaxis()->CenterTitle();
   pall->GetYaxis()->CenterTitle();
   pall->GetXaxis()->SetLabelSize(22);
   pall->GetXaxis()->SetLabelFont(43);
   pall->GetXaxis()->SetTitleSize(24);
   pall->GetXaxis()->SetTitleFont(43);
   pall->GetYaxis()->SetLabelSize(22);
   pall->GetYaxis()->SetLabelFont(43);
   pall->GetYaxis()->SetTitleSize(24);
   pall->GetYaxis()->SetTitleFont(43);
   pall->GetXaxis()->SetTitleOffset(1.8);
   pall->GetYaxis()->SetTitleOffset(2.4);
   pall->SetNdivisions(505);
   pall->SetAxisRange(-59.9,59.9,"Y");
   pall->SetMarkerSize(1);
   pall->Draw("E");
   float addSys = 0;
   if ( drawSys==1)   addSys=0; // No sys error at this moment

   // ====================
   // Finally Draw
   // ====================
   for (int i=0;i<nBin;++i) {
      ppos[i]->SetLineWidth(1);
      ppos[i]->Draw("hist same");
      pneg[i]->SetLineWidth(1);
      pneg[i]->Draw("hist same");
   }
   
   // ====================
   // Draw Statistical Error bars
   // ====================
   for (int i=0;i<nBin;++i) {
      if ( i==0 )       drawErrorShift(ppos[i],-0.016, addSys);
      if ( i==1 || i==4)       drawErrorShift(ppos[i],-0.008,addSys);
      if ( i==2 )       drawErrorShift(ppos[i],0.008,addSys);
      if ( i==3 )       drawErrorShift(ppos[i],0.016,addSys);
      if ( i==0 )       drawErrorShift(pneg[i],-0.016, addSys);
      if ( i==1 || i==4)       drawErrorShift(pneg[i],-0.008,addSys);
      if ( i==2 )       drawErrorShift(pneg[i],0.008,addSys);
      if ( i==3 )       drawErrorShift(pneg[i],0.016,addSys);
   }
   pall->Draw("E same");
   
   // ====================
   // Draw Systematic Errors
   // ====================
   if (drawSys == 1) {
      for(int i = 0; i < nBinAj; ++i){
        double x = pall->GetBinCenter(i+1);
        double y = pall->GetBinContent(i+1);
        // Quote the difference between GEN and RECO in >8 Bin (20%) before adjusting eff as systematics
        double err = fabs(pe[nBin-1]->GetBinContent(i+1)*0.2);
        DrawTick(y,err,err,x,1,0.02,1);
      }
   }

   // ====================
   // Draw Legend
   // ====================
   TLegend *leg = new TLegend(0.10,0.68,0.70,0.96);
   leg->SetFillStyle(0);
   leg->SetBorderSize(0);
   leg->SetTextFont(63);
   leg->SetTextSize(16);
   leg->AddEntry(pall,Form("> %.1f GeV/c",bins[0]),"pl");
   for (int i=0;i<nBin;++i) {
      if (i!=nBin-1){
         leg->AddEntry(ppos[i],Form("%.1f - %.1f GeV/c",bins[i],bins[i+1]),"f");
      } else {
         leg->AddEntry(ppos[i],Form("> %.1f GeV/c",bins[i]),"f");
      }
   }

   if (drawLegend) leg->Draw();

   TLine * l0 = new TLine(0,0,0.5,0);
   l0->SetLineStyle(2);
   l0->Draw();


   TLine * l1 = new TLine(0.0001,-10,0.0001,10);
   l1->Draw();

   TText *titleText = new TText(0.3,30,title);
   titleText->Draw();
}
drawMultiplicity(const char* infilename, const char* system, Int_t rWrite, Int_t rPerformance) {

        prepareAll();

        TFile *f = new TFile(infilename, "read");

        int minMultBin = 0; // 0, 2, 3
        int maxMultBin = 6; // 2, 6, 8

        double EvMultall = 0;

        for (int i = minMultBin; i < maxMultBin; i++) {

                if (i == minMultBin)
                        TH1D* hEvMult =(TH1D*)f->Get(Form("EvMultcutPass%stpcM%i",system,i));
                else
                        hEvMult->Add((TH1D*)f->Get(Form("EvMultcutPass%stpcM%i",system,i)));

                EvMultall += ((TH1D*)f->Get(Form("EvMultcutPass%stpcM%i",system,i)))->GetEntries();
                cout << "MultBin " << i << " " << ((TH1D*)f->Get(Form("EvMultcutPass%stpcM%i",system,i)))->GetEntries() << endl;
                //delete hEvMult;
        }

        cout << "Number of events (all bins): " << EvMultall << endl;

        TCanvas *c2 = new TCanvas("mult", "Event Multiplicity");
        c2->SetGridx();
        c2->SetGridy();
        c2->SetFillColor(10);
        c2->SetLogy();

        hEvMult->GetXaxis()->SetTitle("multiplicity");
        hEvMult->GetYaxis()->SetTitle("number of events");
        hEvMult->GetXaxis()->SetRangeUser(0,4000);
        hEvMult->Draw("");

        if (rPerformance){
                TLatex *alice = new TLatex(0.35,0.27,"Performance");
                alice->SetNDC();
                alice->SetTextColor(myDarkRed);
                alice->SetTextFont(42);
                alice->SetTextSize(0.05);
                alice->SetLineWidth(2);
                alice->Draw();

                TLatex *alice2 = new TLatex(0.32,0.21,"LHC10h - Pass2");
                alice2->SetNDC();
                alice2->SetTextColor(myDarkRed);
                alice->SetTextFont(42);
                alice2->SetTextSize(0.05);
                alice2->SetLineWidth(2);
                alice2->Draw();

                TText *date = new TText(0.38,0.15,cStamp2);
                date->SetNDC();
                date->SetTextFont(42);
                date->SetTextSize(0.04);
                date->Draw();

                //Acquire canvas proportions
                Double_t AliLogo_LowX = 0.37;
                Double_t AliLogo_LowY = 0.33;
                Double_t AliLogo_Height = 0.22;
                //ALICE logo is a png file that is 821x798 pixels->should be wider than a square
                Double_t AliLogo_Width  = (821./798.) * AliLogo_Height * gPad->GetWh() / gPad->GetWw();

                TPad *myPadLogo = new TPad("myPadLogo", "Pad for ALICE Logo",AliLogo_LowX,AliLogo_LowY,AliLogo_LowX+AliLogo_Width,AliLogo_LowY+AliLogo_Height);
                //    myPadLogo->SetFillColor(2); // color to first figure out where is the pad then comment !
                myPadSetUp(myPadLogo,0,0,0,0);
                //myPadLogo->SetFixedAspectRatio(1);
                myPadLogo->Draw();
                myPadLogo->cd();
                TASImage *myAliceLogo = new TASImage("alice_logo_transparent.png");
                myAliceLogo->Draw();
        }

        if (rWrite == 1)
                c2->SaveAs(Form("multiplicity%s.png",system));

        if (rWrite == 2)
                c2->SaveAs(Form("multiplicity%s.eps",system));

}