示例#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();
}
//--------------------------------------------------------------------------------------------------
void overlayFrame(TString text, bool align)
{
  // 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();
  plotText->SetTextColor(kBlue);
  plotText->SetTextSize(0.04);
  plotText->SetNDC();

  // Draw text at top right
  if (align) {
    plotText->SetTextColor(kBlack);
    plotText->SetTextAlign(33);
    plotText->DrawText(0.92,0.95,text.Data());
  }
  // Draw text at bottom left
  else
    plotText->DrawText(0.01,0.01,text.Data());

  return;
}
void drawHistos(TCanvas * C, TString filename, TString category, TTree* Tmine, TTree* Tother,TString var, int nbins, float xmin, float xmax, TString selection, TString myGroup, TString myRootFile, TString group, TString groupRootFile,TString mySel="1",TString groupSel="1"){
  TH1F* Hmine = new TH1F(TString("Hmine")+var,"",nbins,xmin,xmax); 
  Hmine->GetYaxis()->SetTitle(category);
  Hmine->GetXaxis()->SetTitle(var);
  Hmine->SetLineColor(1);
  Hmine->SetStats(0);
  TH1F* Hother = new TH1F(TString("Hother")+var,"",nbins,xmin,xmax); 
  Hother->GetYaxis()->SetTitle(category);
  Hother->GetXaxis()->SetTitle(var);
  Hother->SetLineColor(2);
  Hother->SetStats(0);

  TText TXmine;
  TXmine.SetTextColor(1);
  TXmine.SetTextSize(.04);
  TText TXother;
  TXother.SetTextColor(2);
  TXother.SetTextSize(.04);

  Tmine->Draw(var+">>"+Hmine->GetName(),selection+"*("+mySel+")");
  Tother->Draw(var+">>"+Hother->GetName(),selection+"*("+groupSel+")");

  ////Draw one histogram on top of the other
  C->Clear();
  //Hmine->Scale(1./Hmine->Integral());
  //Hother->Scale(1./Hother->Integral()); 
  //Hother->Scale(968134./688134.); //GGH e-tau
  if(Hmine->GetMaximum()>Hother->GetMaximum())
    Hmine->GetYaxis()->SetRangeUser(0,Hmine->GetMaximum()*1.1);
  else Hmine->GetYaxis()->SetRangeUser(0,Hother->GetMaximum()*1.1);
  Hmine->Draw("hist");
  Hother->Draw("histsame");

//   ///Draw the difference of the historgrams
//   TH1F*HDiff=(TH1F*)Hmine->Clone("HDiff");
//   HDiff->Add(Hother,-1);
//   int max= abs(HDiff->GetMaximum())>abs( HDiff->GetMinimum()) ?   abs(HDiff->GetMaximum()): abs( HDiff->GetMinimum());
//   HDiff->GetYaxis()->SetRangeUser(-2*(max>0?max:1),2*(max>0?max:1));
//   HDiff->Draw("hist");
//   TLine line;
//   line.DrawLine(HDiff->GetXaxis()->GetXmin(),0,HDiff->GetXaxis()->GetXmax(),0);

  //Print the integrals of the histograms a the top
  //TXmine.DrawTextNDC(.2,.965,myGroup+"_"+myRootFile+": "+(long)(Hmine->Integral(0,Hmine->GetNbinsX()+1)));
  //TXother.DrawTextNDC(.2,.93,group+"_"+groupRootFile+": "+(long)(Hother->Integral(0,Hother->GetNbinsX()+1)));
  TXmine.DrawTextNDC(.2,.965,myGroup+" : "+(long)(Hmine->Integral(0,Hmine->GetNbinsX()+1)));
  TXother.DrawTextNDC(.2,.93,group+": "+(long)(Hother->Integral(0,Hother->GetNbinsX()+1)));
  C->Print(filename);

  delete Hmine;
  delete Hother;
}
示例#4
0
TH1F* mix(int run=21, int cut=1, int bin1=3, int bin2=1, int plot=1, int method=1, TH1F* mix0=0, TH1F* mix1=0){
    readfile(OPT,run);
    TH1F* h1= (TH1F*)mTFile->Get(Form("phi1_%1d%1d_c%d",bin1,bin2,cut));
    TH1F* h2= (TH1F*)mTFile->Get(Form("phi2_%1d%1d_c%d",bin1,bin2,cut));
    TH1F* h3= (TH1F*)mTFile->Get(Form("dphi_%1d%1d_c%d",bin1,bin2,cut));
    TH1F* h4= (TH1F*)h3->Clone(Form("mix_%1d%1d_c%d",bin1,bin2,cut));
    TH1F* h5= (TH1F*)h3->Clone(Form("dphi_corr_%1d%1d_c%d",bin1,bin2,cut));
    h4->Reset();
    h5->Reset();
    mixing(h1,h2,h3,h4,1);
    h5->Divide(h3,h4);
    mix0=h4;

    TH1F* h11= (TH1F*)mTFile->Get(Form("phi0_%1d_c%d",bin1,cut));
    TH1F* h12= (TH1F*)mTFile->Get(Form("phi0_%1d_c%d",bin2,cut));
    TH1F* h13= (TH1F*)mTFile->Get(Form("dphi_%1d%1d_c%d",bin1,bin2,cut));
    TH1F* h14= (TH1F*)h3->Clone(Form("mix2_%1d%1d_c%d",bin1,bin2,cut));
    TH1F* h15= (TH1F*)h3->Clone(Form("dphi_corr2_%1d%1d_c%d",bin1,bin2,cut));
    h14->Reset();
    h15->Reset();
    mixing(h11,h12,h13,h14,0);
    h15->Divide(h13,h14);
    mix1=h14; 

    if(plot==1){
	TText* t;
	gStyle->SetOptStat(0);
	c1->Divide(2,2);
	c1->cd(1); h1->SetMinimum(0); h1->SetLineWidth(2); h1->Draw();
	h11->Scale(h1->GetEntries()/h11->GetEntries()); h11->SetLineWidth(2); h11->SetLineColor(6); h11->Draw("same");
	t = new TText(0.2, 0.85,Form("%s %s",CBEAM,CCUT[cut])); t->SetNDC(); t->SetTextSize(0.06); t->SetTextColor(1); t->Draw();
	c1->cd(2); h2->SetMinimum(0); h2->SetLineWidth(2); h2->Draw();
	if(h11!=h12)h12->Scale(h2->GetEntries()/h12->GetEntries()); 
	h12->SetLineWidth(2); h12->SetLineColor(6); h12->Draw("same");
	float m4=h4->GetMaximum();
	c1->cd(4); h4->SetMinimum(0); h4->SetLineWidth(2); h4->SetMaximum(m4*1.1); h4->Draw();
	h14->SetLineWidth(2); h4->SetLineColor(6); h14->Draw("same");
	c1->cd(3); 
	h3->Rebin(2); h5->Rebin(2); h15->Rebin(2);
	float m3=h3->GetBinContent(h3->GetNbinsX()*3/4);
	h3->SetMinimum(0); h3->SetLineWidth(2); h3->SetMaximum(m3*1.5); h3->SetLineColor(1); h3->Draw();
	h5->SetLineWidth(2);  h5->SetLineColor(2);  h5->Draw("same");
	h15->SetLineWidth(2); h15->SetLineColor(6); h15->Draw("same");
	t= new TText(0.20, 0.25,"UnCorrected"); t->SetTextSize(0.05); t->SetTextColor(1); t->SetNDC(); t->Draw();
	t= new TText(0.20, 0.20,"Corrected");   t->SetTextSize(0.05); t->SetTextColor(2); t->SetNDC(); t->Draw();
	t= new TText(0.20, 0.15,"Corrected2");  t->SetTextSize(0.05); t->SetTextColor(6); t->SetNDC(); t->Draw();
	c1->SaveAs(Form("plot/mix_%s_%1d%1d_c%d.png",CBEAM,bin1,bin2,cut));
    }

    if(method==0) return h5;
    else return h15;
}
TCanvas* pHitSpecPos( )
{
  TCanvas* c = new TCanvas("cHitSpecPos","cHitSpecPos",1000,1100);
  c->Divide(2,2);
  TVirtualPad* p; TH2D *h;
  TText t; t.SetTextColor(4);

  p =c->cd(1); p->SetLogy(); p->SetGrid(1,0);
  h = (TH2D*)gROOT->FindObject("hHitSpec_PtVsPhi_BarMinus"); 
  h->GetYaxis()->SetRange(4,33);
  h->DrawCopy("box");
  t.DrawTextNDC(0.17,0.15, "BARREL MU MINUS");

  p =c->cd(2); p->SetLogy(); p->SetGrid(1,0);
  h = (TH2D*)gROOT->FindObject("hHitSpec_PtVsPhi_BarPlus"); 
  h->GetYaxis()->SetRange(4,32);
  h->DrawCopy("box");
  t.DrawTextNDC(0.17,0.15, "BARREL MU PLUS");

  p =c->cd(3); p->SetLogy(); p->SetGrid(1,0);
  h = (TH2D*)gROOT->FindObject("hHitSpec_PtVsPhi_EndMinus"); 
  h->GetYaxis()->SetRange(4,32);
  h->DrawCopy("box");
  t.DrawTextNDC(0.17,0.15, "ENDCAP MU MINUS");

  p =c->cd(4); p->SetLogy(); p->SetGrid(1,0);
  h = (TH2D*)gROOT->FindObject("hHitSpec_PtVsPhi_EndPlus"); 
  h->GetYaxis()->SetRange(4,32);
  h->DrawCopy("box");
  t.DrawTextNDC(0.17,0.15, "ENDCAP MU PLUS");

  return c;
}
示例#6
0
void s_intersection()
{
   gROOT->GetListOfCanvases()->Delete();
   TCanvas *c = new TCanvas("composite shape", "Intersection boolean operation", 700, 1000);

   c->Divide(1,2,0,0);
   c->cd(2);
   gPad->SetPad(0,0,1,0.4);
   c->cd(1);
   gPad->SetPad(0,0.4,1,1);
   
   if (gGeoManager) delete gGeoManager;
   
   new TGeoManager("xtru", "poza12");
   TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7);
   TGeoMedium *med = new TGeoMedium("MED",1,mat);
   TGeoVolume *top = gGeoManager->MakeBox("TOP",med,100,100,100);
   gGeoManager->SetTopVolume(top);

   // define shape components with names
   TGeoBBox *box = new TGeoBBox("bx", 40., 40., 40.); 
   TGeoSphere *sph = new TGeoSphere("sph", 40., 45.);
   // define named geometrical transformations with names
   TGeoTranslation *tr = new TGeoTranslation(0., 0., 45.);
   tr->SetName("tr");
   // register all used transformations
   tr->RegisterYourself();
   // create the composite shape based on a Boolean expression
   TGeoCompositeShape *cs = new TGeoCompositeShape("mir", "sph:tr * bx");

   TGeoVolume *vol = new TGeoVolume("COMP2",cs);
   top->AddNode(vol,1);
   gGeoManager->CloseGeometry();
   gGeoManager->SetNsegments(100);
   top->Draw();
   MakePicture();

   c->cd(2);

   TPaveText *pt = new TPaveText(0.01,0.01,0.99,0.99);

   pt->SetLineColor(1);

   TText *text = pt->AddText("TGeoCompositeShape - composite shape class");

   text->SetTextColor(2);
   pt->AddText("----- Here is an example of boolean intersection operation : A * B");
   pt->AddText("----- A == sphere (with inner radius non-zero), B == box");
   pt->AddText(" ");
   pt->SetAllWith("-----","color",4);
   pt->SetAllWith("-----","font",72);
   pt->SetAllWith("-----","size",0.04);
   pt->SetTextAlign(12);
   pt->SetTextSize(0.044);
   pt->Draw();
   c->cd(1);
}
示例#7
0
void s_difference()
{
   gROOT->GetListOfCanvases()->Delete();
   TCanvas *c = new TCanvas("composite shape", "Difference boolean operation", 700, 1000);

   c->Divide(1,2,0,0);
   c->cd(2);
   gPad->SetPad(0,0,1,0.4);
   c->cd(1);
   gPad->SetPad(0,0.4,1,1);
   
   if (gGeoManager) delete gGeoManager;
   
   new TGeoManager("xtru", "poza12");
   TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7);
   TGeoMedium *med = new TGeoMedium("MED",1,mat);
   TGeoVolume *top = gGeoManager->MakeBox("TOP",med,100,100,100);
   gGeoManager->SetTopVolume(top);

   // define shape components with names
   TGeoTorus *tor = new TGeoTorus("tor", 45., 15., 20., 45., 145.); 
   TGeoSphere *sph = new TGeoSphere("sph", 20., 45., 0., 180., 0., 270.);
   // create the composite shape based on a Boolean expression
   TGeoCompositeShape *cs = new TGeoCompositeShape("mir", "sph - tor");

   TGeoVolume *vol = new TGeoVolume("COMP3",cs);
   top->AddNode(vol,1);
   gGeoManager->CloseGeometry();
   gGeoManager->SetNsegments(60);
   top->Draw();
   MakePicture();

   c->cd(2);

   TPaveText *pt = new TPaveText(.01, .01, .99, .99);

   pt->SetLineColor(1);

   TText *text = pt->AddText("TGeoCompositeShape - composite shape class");

   text->SetTextColor(2);

   pt->AddText("----- It's an example of boolean difference: A - B");
   pt->AddText("----- A == part of sphere (0-180, 0-270), B == partial torus (45-145)");
   pt->AddText(" ");
   pt->SetAllWith("-----","color",4);
   pt->SetAllWith("-----","font",72);
   pt->SetAllWith("-----","size",0.04);
   pt->SetTextAlign(12);
   pt->SetTextSize(0.044);
   pt->Draw();
   c->cd(1);
}
void drawSignalDiff(TCanvas* C,TString Group1,TFile* F1,TString Group2,TFile* F2,TString channel,TString category,TString signal){
  //     drawSignalDiff(         C,        Group1,       F1,         Group2      ,F2,        channel,       "boost_high",     "ggH");
  C->Clear();
  
  TGraph G1;
  TGraph G2;
  float max=0.;
  for(Int_t i=0;i<8;i++){
    long mass=110+i*5;
    TH1F* H1 = (TH1F*) F1->Get(channel+"_"+category+"/"+signal+mass);
    TH1F* H2 = (TH1F*) F2->Get(channel+"_"+category+"/"+signal+mass);
    G1.SetPoint(i,mass,H1->Integral());
    G2.SetPoint(i,mass,H2->Integral());
    if(H1->Integral()>max)max=H1->Integral();
  }
  
  G1.GetYaxis()->SetRangeUser(0.,max*1.1);
  G1.SetTitle(category+"  "+signal);
  G1.GetYaxis()->SetTitle("signal yield");
  G1.GetXaxis()->SetTitle("m_{H}");
  G1.Draw("ap");
  G2.SetLineColor(2);
  G2.Draw("lsame");


  TText TXmine;
  TXmine.SetTextColor(1);
  TXmine.SetTextSize(.04);
  TXmine.DrawTextNDC(.25,.845,Group1); 

  TText TXother;
  TXother.SetTextColor(2);
  TXother.SetTextSize(.04);
  TXother.DrawTextNDC(.25,.81,Group2);


  C->Print(TString(C->GetName())+".pdf");
}
示例#9
0
文件: benchmarks.C 项目: MycrofD/root
void bexec(TString &dir,const char *macro)
{
   if (gROOT->IsBatch()) printf("Processing benchmark: %s%s\n",dir.Data(),macro);
   TPaveText *summary = (TPaveText*)bench1->GetPrimitive("TPave");
   TText *tmacro = summary->GetLineWith(macro);
   if (tmacro) tmacro->SetTextColor(4);
   bench1->Modified(); bench1->Update();

   gROOT->Macro(Form("%s%s",dir.Data(),macro));

   TPaveText *summary2 = (TPaveText*)bench1->GetPrimitive("TPave");
   TText *tmacro2 = summary2->GetLineWith(macro);
   if (tmacro2) tmacro2->SetTextColor(2);
   bench1->Modified(); bench1->Update();
}
TCanvas* pHitSpecDet(const std::string& s)
{
  TCanvas* c = new TCanvas( ("HitSpecDet"+s).c_str(), ("HitSpecDet"+s).c_str(), -2);
  c->SetLogx();
  TH2D* h = (TH2D*)gROOT->FindObject(s.c_str());
  h->GetXaxis()->SetRange(4,32);
  std::stringstream str;
  str<<h->GetTitle();
  TText t;
  t.SetTextColor(4);
  t.SetTextAlign(11);
  t.SetTextSize(0.035);
  h->DrawCopy("box");
  t.DrawTextNDC(0.17,0.2, str.str().c_str());
  return c;
}
示例#11
0
//______________________________________________________________________________
void bexec2(char *macro)
{
   printf("in bexec dir=%s\n",pwd());
   if (gROOT->IsBatch()) printf("Processing benchmark: %s\n",macro);
   TPaveText *summary = (TPaveText*)bench->GetPrimitive("TPave");
   TText *tmacro = summary->GetLineWith(macro);
   if (tmacro) tmacro->SetTextColor(4);
   bench->Modified(); bench->Update();

   gROOT->Macro(macro);

   TPaveText *summary2 = (TPaveText*)bench->GetPrimitive("TPave");
   TText *tmacro2 = summary2->GetLineWith(macro);
   if (tmacro2) tmacro2->SetTextColor(2);
   bench->Modified(); bench->Update();
}
示例#12
0
//______________________________________________________________________________
void AddText(TPaveText *pave, TObject *pf, Int_t iaxis)
{
   char line[128];
   TGeoPatternFinder *finder = (TGeoPatternFinder*)pf;
   if (!pave || !pf) return;
   for (Int_t i=0; i<128; i++) line[i] = ' ';
   TGeoVolume *volume = finder->GetVolume();
   TGeoShape *sh = volume->GetShape();
   sprintf(line, "Division of %s on axis %d (%s)", volume->GetName(), iaxis,sh->GetAxisName(iaxis));
   TText *text = pave->AddText(line);
   text->SetTextColor(3);
   text->SetTextAlign(12);
   AddText(pave, "fNdiv",finder->GetNdiv(),"number of divisions");
   AddText(pave, "fStart",finder->GetStart(),"start divisioning position");
   AddText(pave, "fStep",finder->GetStep(),"division step");
}
示例#13
0
//--------------------------------------------------------------------------------------------------
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;
}
示例#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)");
}
示例#15
0
void comp(int run, int pt1, int pt2, TCanvas* cvs, int fit=0){   
    int bin0=1;
    char c[100];
    char c2[100];
    readfile(OPT,run);
    gStyle->SetOptStat(0);
    gStyle->SetOptFit(0);
    gStyle->SetOptTitle(0);
    cvs->Clear();
    float ptcut[kNPtBin+1]={0.5,1.0,1.5,2.0,2.5,3.0,10.0};
    float col[NCUT+1]={0,1,4,3,4,38,6,9,8,kGreen+3,kOrange,kPink+9,kOrange+7,kGreen+3,3,2,1,2};
    memset(PAR,0,sizeof(PAR));
    TText* t;    
    int cmax=NCUT;
    if(run==20) cmax++;
    int iy=0;
    for(int cc=1; cc<cmax; cc++){
	TH1F *h,*h2,*h3,*h4;	
	if(run==11 && cc==5) continue;
	if(run==11 && cc>14) continue;
	//if(run==20 && cc!=2 && cc!=9 && cc!=10 && cc!=11 && cc!=cmax-3) continue;
	if(run==20 && cc!=2 && cc!=14  && cc!=cmax-3) continue;
	//get normalizations
	sprintf(c,"m0_%1d_c%d",pt1,cc);
	TH1F* h0 = (TH1F*)mTFile->Get(c);
	float norm0 = h0->GetEntries();
	sprintf(c,"m1_%1d%1d_c%d",pt1,pt2,cc);
	TH1F* h1 = (TH1F*)mTFile->Get(c);
	float norm1 = h1->GetEntries();
	float norm2=norm1/norm0;
	float norm3=norm2/ZggCut;
	printf("cut=%2d n0=%d n1=%d n2=%f\n",cc,norm0,norm1,norm2);
	
	sprintf(c,"dphi_%1d%1d_c%d",pt1,pt2,cc);
	h = (TH1F*)mTFile->Get(c);
	int nbin = h->GetNbinsX();
	if(cc==cmax-3){
	    h->Scale(1.0/norm0*nbin/2.0/PI);
	}else{
	    h->Scale(1.0/norm0*nbin/2.0/PI/ZggCut);
	}
	h->SetLineColor(col[cc]);
	h->SetLineWidth(2);
	h->SetMinimum(0.0);
	if(iy==0) {
	    h->SetMaximum(h->GetMaximum()*1.5);
	    h->Draw("l");
	}else{
	    h->Draw("lsame");
	}	
	if(run==20 && cc==cmax-3) cc=cmax-1;
	t = new TText(0.7, 0.85-iy*0.03,CCUT[cc]); t->SetNDC(); t->SetTextSize(0.02); t->SetTextColor(col[cc]); t->Draw();
	iy++;
    }
    float xx=0.45, yy=0.80, dy=0.03;
    t = new TText(xx, yy,    Form("pT1=%3.1f-%3.1f",ptcut[pt1],ptcut[pt1+1])); t->SetNDC(); t->SetTextSize(0.03); t->Draw();
    t = new TText(xx, yy-dy, Form("pT2=%3.1f-%3.1f",ptcut[pt2],ptcut[pt2+1])); t->SetNDC(); t->SetTextSize(0.03); t->Draw();

    if     (run==1 || run==11) {sprintf(c,"plot/dipi0_pp_compdphi.png");}
    else if(run==2 || run==12) {sprintf(c,"plot/dipi0_pau_compdphi.png");}
    else if(run==3 || run==13) {sprintf(c,"plot/dipi0_pal_compdphi.png");}
    else if(run==20)           {sprintf(c,"plot/dipi0_pythia_compdphi.png");}
    else                       {sprintf(c,"plot/dipi0_%d_compdphi.png",run);}
    printf("Saving %s\n",c);
    cvs->SaveAs(c);
}
示例#16
0
void plotauto(TString infilename) {

  TString plname = infilename+".ps";
  TCanvas* cc = new TCanvas("validate","validate",500,370);
  cc->Print(plname+"[");

  TText tt;
  tt.SetTextColor(2);
  tt.SetTextSize(0.02);

  gStyle->SetMarkerSize(0.1);
  gStyle->SetTitleSize(0.15,"ff");
  gStyle->SetTitleTextColor(4);

  std::vector < TString > vnames;
  vnames.push_back("Sim_HitEn");
  vnames.push_back("Sim_HitTime");
  vnames.push_back("Sim_posXY");
  vnames.push_back("Sim_posXZ");
  vnames.push_back("Sim_posYZ");
  vnames.push_back("Sim_posRZ");

  std::vector <TString> exts;
  exts.push_back("");
  exts.push_back("_posZ");
  exts.push_back("_negZ");

  TH1F* h;
  TH2F* hh;
  TKey *key;
  TIter next;
  TKey *key2;
  TIter next2;

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

  // overall geometry
  TDirectory* td = (TDirectory*) infile->Get("ALLCollections");
  cc->Clear();
  cc->Divide(3,3);
  cc->cd(1);
  hh = (TH2F*) td->Get("ALLCollections_overallhitZR");
  hh->Draw("box");
  cc->cd(2);
  int icol=1;
  bool first=true;
  TLegend* tl = new TLegend(0., 0., 1, 1);
  next = td->GetListOfKeys();
  while ((key = (TKey*)next())) {
    TClass *cll = gROOT->GetClass(key->GetClassName());
    if (cll->InheritsFrom("TH2F")) {
      hh = (TH2F*)key->ReadObj();
      TString hn = hh->GetName();
      if ( hn.Contains("ALL") ) continue;
      if ( hn.Contains("_Log") ) continue;
      hh->SetLineColor(icol);
      if ( first ) {hh->Draw("box"); first=false;}
      else hh->Draw("same;box");
      icol++;
      if (icol==10) icol=1;
      TString ss = hn.ReplaceAll( "_overallhitZR", "");
      tl->AddEntry(hh, ss , "l");
    }
  }
  // the legend
  cc->cd(3);
  tl->Draw();

  cc->cd(4);
  hh = (TH2F*) td->Get("ALLCollections_Log_overallhitZR");
  hh->Draw("box");
  cc->cd(5);
  icol=1;
  first=true;
  next = td->GetListOfKeys();
  while ((key = (TKey*)next())) {
    TClass *cll = gROOT->GetClass(key->GetClassName());
    if (cll->InheritsFrom("TH2F")) {
      hh = (TH2F*)key->ReadObj();
      TString hn = hh->GetName();
      if ( hn.Contains("ALL" ) ) continue;
      if ( ! hn.Contains("_Log_") ) continue;
      hh->SetLineColor(icol);
      if ( first ) {hh->Draw("box"); first=false;}
      else hh->Draw("same;box");
      icol++;
      if (icol==10) icol=1;
    }
  }

  cc->cd(7);
  hh = (TH2F*) td->Get("ALLCollections_LogLog_overallhitZR");
  hh->Draw("box");
  cc->cd(8);
  icol=1;
  first=true;
  next = td->GetListOfKeys();
  while ((key = (TKey*)next())) {
    TClass *cll = gROOT->GetClass(key->GetClassName());
    if (cll->InheritsFrom("TH2F")) {
      hh = (TH2F*)key->ReadObj();
      TString hn = hh->GetName();
      if ( hn.Contains("ALL" ) ) continue;
      if ( ! hn.Contains("_LogLog_") ) continue;
      hh->SetLineColor(icol);
      if ( first ) {hh->Draw("box"); first=false;}
      else hh->Draw("same;box");
      icol++;
      if (icol==10) icol=1;
    }
  }


  cc->Print(plname);

  // now collection-by-collection

  next = infile->GetListOfKeys();
  while ((key = (TKey*)next())) {
    TClass *cll = gROOT->GetClass(key->GetClassName());
    if (cll->InheritsFrom("TDirectory")) {
      td = (TDirectory*)key->ReadObj();
      TString dirname = td->GetName();
      if ( dirname=="ALLCollections" ) continue;

      // is it an endcap collection?
      bool isEndcap = td->Get(dirname+"_hitXY_posZ");

      // first overall geometry
      cc->Clear();
      cc->Divide(3,2);

	cc->cd(1);
	( (TH2F*) td->Get(dirname+"_hitEn"))->Draw("box");
	cc->cd(4)->SetLogy();
	( (TH2F*) td->Get(dirname+"_hitTime"))->Draw("box");

      if ( isEndcap ) {
	cc->cd(2);
	( (TH2F*) td->Get(dirname+"_hitXY_posZ"))->Draw("box");
	cc->cd(3);
	( (TH2F*) td->Get(dirname+"_hitXY_negZ"))->Draw("box");
	cc->cd(5);
	((TH2F*) td->Get(dirname+"_hitZR_posZ"))->Draw("box");
	cc->cd(6);
	((TH2F*) td->Get(dirname+"_hitZR_negZ"))->Draw("box");
      } else {
	cc->cd(2);
	( (TH2F*) td->Get(dirname+"_hitXY"))->Draw("box");
	cc->cd(3);
	( (TH2F*) td->Get(dirname+"_hitZR"))->Draw("box");
      }

      cc->Print(plname);


      // then the cell indices

      // work out how many indices/variables we're dealing with
      std::vector < TString > indices;
      std::vector < TString > variables;
      next2 = td->GetListOfKeys();
      while ((key2 = (TKey*)next2())) {
	cll = gROOT->GetClass(key2->GetClassName());
	if (cll->InheritsFrom("TH2F")) {
	  hh = (TH2F*) key2->ReadObj();
	  TString hn = hh->GetName();
	  if ( hn.Contains("Indx") ) {
	    TString ss = hn.ReplaceAll(dirname+"_", "");
	    TString asas = ((TObjString*) (ss.Tokenize("_") -> At(0)))->GetString();
	    if ( find( indices.begin(), indices.end(), asas )==indices.end() ) indices.push_back(asas);
	    asas = ((TObjString*) (ss.Tokenize("_") -> At(1)))->GetString();
	    if ( find( variables.begin(), variables.end(), asas )==variables.end() ) variables.push_back(asas);
	  }
	}
      }

      if ( indices.size()==0 || variables.size()==0 ) continue;


      for (int inp=0; inp<2; inp++) {
	if ( !isEndcap && inp==1 ) continue;
	cc->Clear();
	cc->Divide(indices.size(), variables.size());
	int ic=1;
	next2 = td->GetListOfKeys();
	while ((key2 = (TKey*)next2())) {
	  cll = gROOT->GetClass(key2->GetClassName());
	  if (cll->InheritsFrom("TH2F")) {
	    hh = (TH2F*) key2->ReadObj();
	    TString hn = hh->GetName();
	    if ( isEndcap ) {
	      if      ( inp==0 && ! hn.Contains("posZ") ) continue;
	      else if ( inp==1 && ! hn.Contains("negZ") ) continue;
	    }
	    if ( hn.Contains("Indx") ) {
	      TString asas = ((TObjString*) (hn.Tokenize("_") -> At(1)))->GetString();
	      asas = asas(4,asas.Length());
	      cc->cd(ic++);
	      hh->Draw("box");
	    }
	  }
	}

	cc->cd();
	for ( size_t k=0; k<variables.size(); k++) {
	  tt.DrawTextNDC( 0.0, 0.9 - (1.0*k)/(variables.size()), variables[k] );
	}

	for ( size_t k=0; k<indices.size(); k++) {
	  tt.DrawTextNDC( 0.05 + (1.0*k)/(indices.size()), 0.02, indices[k].ReplaceAll("Indx","Indx_") );
	}

	tt.DrawTextNDC( 0.1, 0.99, dirname);
	if ( isEndcap ) {
	  if (inp==0 ) tt.DrawTextNDC( 0.35, 0.99, "posZ");
	  else         tt.DrawTextNDC( 0.35, 0.99, "negZ");
	}

	cc->Print(plname);
      }
    }
  }

  infile->Close();

  cc->Print(plname+"]");
}
示例#17
0
void gluinoMass(double lumi=-1., double maxInstLumi=-1.) {
	
  if (lumi<0)
    lumi=877.;
  if (maxInstLumi<0)
    maxInstLumi=1300.;
  LimitPlots plots(lumi);
  
  plots.calculateCrossSections(7,4,39,9);
	
  // expected limit (1 and 2 sigma bands)
  TGraph* g_exp = plots.getExpMassLimitGluino();
  TGraphAsymmErrors* g_exp1 = plots.getExpMassLimitGluino1Sig();
  TGraphAsymmErrors* g_exp2 = plots.getExpMassLimitGluino2Sig();
  
  // three points on counting expt curve
  TGraph* g_gluino = plots.getMassLimitGluino();
  TGraph* g_stop = plots.getMassLimitStop();
  
  // one point from lifetime fit
  TGraph* g_tp = plots.getMassLimitGluinoTP();
  
  // theory prediction
  TGraph* g_thGluino = plots.getGluinoTheory();
  TGraph* g_thStop = plots.getStopTheory();
  
  TCanvas* canvas = new TCanvas("canvas");
  
  //canvas->SetGrid();
  canvas->SetLogy();
  
  TH1 * h;
  h = canvas->DrawFrame(300., .02, 1000., 1e2);
  //h->SetTitle("Beamgap Expt;m_{#tilde{g}} [GeV/c^{2}]; Stopped HSCP Cross Section #times BR [pb]");
  h->SetTitle("Beamgap Expt;m_{#tilde{g}} [GeV/c^{2}]; #sigma(pp #rightarrow #tilde{g}#tilde{g}) #times BR(#tilde{g} #rightarrow g#tilde{#chi}^{0}) [pb]");
  
  // not covered region
  TBox* nc = new TBox(100., .1, 150., 5e2);
  nc->SetFillStyle(3354);
  nc->SetFillColor(kRed-4);
  //nc->Draw();
  
  // details
  TPaveText* blurb = new TPaveText(300., 2, 550., 1e2);
  blurb->AddText("CMS Preliminary 2012");

  std::stringstream label;
  label<<"#int L dt = "<<lumi<<" fb^{-1}";
  blurb->AddText(label.str().c_str());
  label.str("");
  double peakInstLumi=maxInstLumi;
  int exponent=30;
  while (peakInstLumi>10) {
    peakInstLumi/=10.;
    ++exponent;
  }
  label<<"L^{max}_{inst} = "<<peakInstLumi<<" x 10^{"<<exponent<<"} cm^{-2}s^{-1}";
  blurb->AddText(label.str().c_str());
  label.str("");
  label << "#sqrt{s} = " << ENERGY << " TeV";
  blurb->AddText(label.str().c_str());
  blurb->AddText("m_{#tilde{g}} - m_{#tilde{#chi}^{0}} = 100 GeV/c^{2}");
  //blurb->AddText("m_{#tilde{t}} - m_{#tilde{#chi}^{0}} = 200 GeV/c^{2}");	
  blurb->SetTextFont(42);
  blurb->SetBorderSize(0);
  blurb->SetFillColor(0);
  blurb->SetShadowColor(0);
  blurb->SetTextAlign(12);
  blurb->SetTextSize(0.032);

  
  // legend
  TBox *legbg = new TBox(600., 2., 900., 1e2);
  legbg->Draw();
  TLegend *leg = new TLegend(600., 2., 900., 1e2,"95% C.L. Limits","");
  leg->SetTextSize(0.028);
  leg->SetBorderSize(0);
  leg->SetTextFont(42);
  leg->SetFillColor(0);
  leg->AddEntry(g_exp, "Expected: 10 #mus - 1000 s Counting Exp. ", "l");
  leg->AddEntry(g_exp1, "Expected #pm1#sigma: 10 #mus - 1000 s Counting Exp. ", "f");
  leg->AddEntry(g_exp2, "Expected #pm2#sigma: 10 #mus - 1000 s Counting Exp. ", "f");
  //	  leg->AddEntry(graph3, "Obs.: 10^{6} s Counting Exp.", "l");
  leg->AddEntry(g_gluino, "Obs.: 10 #mus - 1000 s Counting Exp. ", "l");
  leg->AddEntry(g_tp, "Obs.: 10 #mus Timing Profile ", "l");
  //leg->AddEntry(g_stop, "Obs.: 10 #mus - 1000 s Counting Exp. (#tilde{t})", "l");
  //leg->AddEntry(graph_em, "Obs.: 10 #mus - 1000 s Counting Exp. (EM only)", "l");
  //  leg->AddEntry(graph1, "Obs.: 570 ns Counting Exp.", "l");
  leg->Draw();
  
  
  
  // 2 sigma expected band
  g_exp2->SetLineColor(0);
  g_exp2->SetLineStyle(0);
  g_exp2->SetLineWidth(0);
  g_exp2->SetFillColor(5);
  g_exp2->SetFillStyle(1001);
  g_exp2->Draw("3");
  
  // 1 sigma expected band
  g_exp1->SetLineColor(0);
  g_exp1->SetLineStyle(0);
  g_exp1->SetLineWidth(0);
  g_exp1->SetFillColor(3);
  g_exp1->SetFillStyle(1001);
  g_exp1->Draw("3");  
  
  // expected line
  g_exp->SetLineStyle(2);
  g_exp->SetLineWidth(1);
  g_exp->Draw("l");
  
 
  // plateau limit - 1 ms
  g_gluino->SetLineColor(1);
  g_gluino->SetLineStyle(1);
  g_gluino->SetLineWidth(2);
  g_gluino->Draw("l");
  
  // stop curve
  g_stop->SetLineColor(1);
  g_stop->SetLineStyle(5);
  g_stop->SetLineWidth(2);
  //g_stop->Draw("l");
 

  // 1 mus lifetime fit limit
  g_tp->SetLineColor(kRed);
  g_tp->SetLineStyle(1);
  g_tp->SetLineWidth(2);
  g_tp->Draw("l");
  
  // theory line
  g_thGluino->SetLineColor(kBlue);
  g_thGluino->SetLineStyle(1);
  g_thGluino->SetLineWidth(2);
  g_thGluino->SetFillStyle(3001);
  g_thGluino->SetFillColor(kBlue-4);
  g_thGluino->Draw("l3");
  
  g_thStop->SetLineColor(kRed);
  g_thStop->SetLineStyle(1);
  g_thStop->SetLineWidth(2);
  g_thStop->SetFillStyle(3001);
  g_thStop->SetFillColor(kRed-4);
  //g_thStop->Draw("l3");


  // theory line label
  TLatex* th = new TLatex(600., .3, "NLO+NLL #tilde{g}");
  th->SetTextColor(kBlue);
  th->SetTextFont(42);
  th->SetTextSize(0.035);
  th->Draw();

  TLatex* ths = new TLatex(330., 2., "NLO+NLL #tilde{t}");
  ths->SetTextColor(kRed);
  ths->SetTextFont(42);
  ths->SetTextSize(0.035);
  //ths->Draw();

  // not explored label
  TText* ne = new TText(125., .2, "Not Sensitive");
  ne->SetTextColor(kRed+1);
  ne->SetTextFont(42);
  ne->SetTextAngle(90);
  ne->SetTextSize(0.035);
  //ne->Draw();

  blurb->Draw();

  canvas->RedrawAxis();

  canvas->Print("gluinoMassLimit.pdf");
  canvas->Print("gluinoMassLimit.C");

  plots.calculateIntercepts();
  
}
示例#18
0
void DrawMLPoutputMovie( TFile* file, const TString& methodType, const TString& methodTitle )
{
   gROOT->SetBatch( 1 );

   // define Canvas layout here!
   const Int_t width = 600;   // size of canvas

   // this defines how many canvases we need
   TCanvas* c = 0;

   Float_t nrms = 4;
   Float_t xmin = -1.2;
   Float_t xmax = 1.2;
   Float_t ymin = 0;
   Float_t ymax = 0;
   Float_t maxMult = 6.0;
   Int_t   countCanvas = 0;
   Bool_t  first = kTRUE;
            
   TString     dirname  = methodType + "/" + methodTitle + "/" + "EpochMonitoring";
   TDirectory *epochDir = (TDirectory*)file->Get( dirname );
   if (!epochDir) {
      cout << "Big troubles: could not find directory \"" << dirname << "\"" << endl;
      exit(1);
   }

   // now read all evolution histograms
   TIter keyItTit(epochDir->GetListOfKeys());
   TKey *titkeyTit;
   while ((titkeyTit = (TKey*)keyItTit())) {
      
      if (!gROOT->GetClass(titkeyTit->GetClassName())->InheritsFrom("TH1F")) continue;
      TString name = titkeyTit->GetName();
      
      if (!name.BeginsWith("convergencetest___")) continue;
      if (!name.Contains("_train_"))              continue; // only for training so far
      if (name.EndsWith( "_B"))                   continue;
      
      // must be signal histogram
      if (!name.EndsWith( "_S")) {
         cout << "Big troubles with histogram: " << name << " -> should end with _S" << endl;
         exit(1);
      }
      
      // create canvas
      countCanvas++;
      TString ctitle = Form("TMVA response %s",methodTitle.Data());
      c = new TCanvas( Form("canvas%d", countCanvas), ctitle, 0, 0, width, (Int_t)width*0.78 ); 
      
      TH1F* sig = (TH1F*)titkeyTit->ReadObj();
      sig->SetTitle( Form("TMVA response for classifier: %s", methodTitle.Data()) );
      
      TString dataType = (name.Contains("_train_") ? "(training sample)" : "(test sample)");
      
      // find background
      TString nbn = sig->GetName(); nbn[nbn.Length()-1] = 'B';            
      TH1F* bgd = dynamic_cast<TH1F*>(epochDir->Get( nbn ));
      if (bgd == 0) {
         cout << "Big troubles with histogram: " << bgd << " -> cannot find!" << endl;
         exit(1);
      }
      
      cout << "sig = " << sig->GetName() << endl;
      cout << "bgd = " << bgd->GetName() << endl;
      
      // set the histogram style
      TMVAGlob::SetSignalAndBackgroundStyle( sig, bgd );
      
      // normalise both signal and background
      TMVAGlob::NormalizeHists( sig, bgd );
      
      // set only first time, then same for all plots
      if (first) {
         if (xmin == 0 && xmax == 0) {
            xmin = TMath::Max( TMath::Min(sig->GetMean() - nrms*sig->GetRMS(), 
                                          bgd->GetMean() - nrms*bgd->GetRMS() ),
                               sig->GetXaxis()->GetXmin() );
            xmax = TMath::Min( TMath::Max(sig->GetMean() + nrms*sig->GetRMS(), 
                                          bgd->GetMean() + nrms*bgd->GetRMS() ),
                               sig->GetXaxis()->GetXmax() );
         }
         ymin = 0;
         ymax = TMath::Max( sig->GetMaximum(), bgd->GetMaximum() )*maxMult;
         first = kFALSE;
      }
      
      // build a frame
      Int_t nb = 100;
      TString hFrameName(TString("frame") + methodTitle);
      TObject *o = gROOT->FindObject(hFrameName);
      if(o) delete o;
      TH2F* frame = new TH2F( hFrameName, sig->GetTitle(), 
                              nb, xmin, xmax, nb, ymin, ymax );
      frame->GetXaxis()->SetTitle( methodTitle + " response" );
      frame->GetYaxis()->SetTitle("(1/N) dN^{ }/^{ }dx");
      TMVAGlob::SetFrameStyle( frame );
      
      // find epoch number (4th token)
      TObjArray* tokens = name.Tokenize("_");
      TString es = ((TObjString*)tokens->At(4))->GetString();
      if (!es.IsFloat()) {
         cout << "Big troubles in epoch parsing: \"" << es << "\" is not float" << endl;
         exit(1);
      }
      Int_t epoch = es.Atoi();
      
      // eventually: draw the frame
      frame->Draw();  
      
      c->GetPad(0)->SetLeftMargin( 0.105 );
      frame->GetYaxis()->SetTitleOffset( 1.2 );
      
      // Draw legend               
      TLegend *legend= new TLegend( c->GetLeftMargin(), 1 - c->GetTopMargin() - 0.12, 
                                    c->GetLeftMargin() + 0.5, 1 - c->GetTopMargin() );
      legend->SetFillStyle( 1 );
      legend->AddEntry(sig,TString("Signal ")     + dataType, "F");
      legend->AddEntry(bgd,TString("Background ") + dataType, "F");
      legend->SetBorderSize(1);
      legend->SetMargin( 0.15 );
      legend->Draw("same");
      
      TText* t = new TText();            
      t->SetTextSize( 0.04 );
      t->SetTextColor( 1 );
      t->SetTextAlign( 31 );
      t->DrawTextNDC( 1 - c->GetRightMargin(), 1 - c->GetTopMargin() + 0.015, Form( "Epoch: %i", epoch) );
      
      // overlay signal and background histograms
      sig->Draw("samehist");
      bgd->Draw("samehist");
      
      // save to file
      TString dirname  = "movieplots";
      TString foutname = dirname + "/" + name;
      foutname.Resize( foutname.Length()-2 );
      foutname.ReplaceAll("convergencetest___","");
      foutname += ".gif";
      
      cout << "storing file: " << foutname << endl;
      
      c->Update();
      c->Print(foutname);            
   }
}
示例#19
0
// -----------------------------------------------------------------------------
//
TCanvas* createPlot( TDirectory* output_file,
		     std::string output_canvas, 
		     //std::vector< std::vector<std::string> > input_files, 
		     std::vector<std::string> input_files, 
		     std::vector<std::string> input_histos, 
		     std::vector<std::string> input_legend, 
 		     std::vector<int> marker_style, 
 		     std::vector<int> marker_colour, 
 		     std::vector<float> marker_size, 
 		     std::vector<float> lumis, 
		     double lumi,
		     int rebin, 
		     bool norm, 
		     bool log,
		     double min = -1.,
		     double max = -1.,
		     int integral = -1 )
{

  // SetSomeStyles();

  // Check integral
  if ( integral >= input_files.size() ) { integral = -1; }

  // Loop through histogram names
  std::vector<TH1D*> his;
  for ( uint ihis = 0; ihis < input_histos.size(); ++ihis ) {
    if ( integral < 0 || ihis <= integral ) {
      his.push_back( (TH1D*)getHisto( input_files[ihis], input_histos[ihis], "QcdBkgdEst", rebin ) );
    } else {
      his.back()->Add( (TH1D*)getHisto( input_files[ihis], input_histos[ihis], "QcdBkgdEst", rebin ) );
    }
  }
  
  // Create legend
  TLegend* legend = new TLegend( 0.65, 0.52-0.03*his.size(), 0.9, 0.52,  NULL, "brNDC" );
  legend->SetFillColor(0);
  legend->SetLineColor(0); 
  legend->SetTextAlign(31);
  legend->SetTextSize(0.025);
  
  // Create canvas
  TCanvas* aCanvas = createCanvas( output_canvas, output_file, log );
  
  TPaveText* stats = new TPaveText( 0.65, 0.54, 0.9, 0.54+0.03*his.size(), "brNDC" );
  stats->SetFillColor(0);
  stats->SetLineColor(0);

  TLatex* prelim = new TLatex( 0.15, 0.96, "#scale[0.8]{CMS preliminary 2011}" );
  prelim->SetTextSize(0.03);
  prelim->SetNDC();
  std::stringstream ssl; ssl << "#scale[0.8]{#int L dt = " << lumi/1000. << " fb^{-1}, #sqrt{s} = 7 TeV}";
  TLatex* lumistxt = new TLatex( 0.95, 0.96, ssl.str().c_str() );
  lumistxt->SetTextSize(0.03);
  lumistxt->SetNDC();
  lumistxt->SetTextAlign(31);
  
  // For Ted
  bool print_ted = true;
  std::stringstream ted;
  if ( print_ted ) { ted << "self._htMeans = ("; }

  // Loop through histograms
  double aMax = 0.;
  double aMin = 1.e12;
  for ( uint ihis = 0; ihis < his.size(); ++ihis ) {
    if ( !his[ihis] ) { continue; }
    
    // Line colour and fill
    his[ihis]->Scale(lumis[ihis]/100.);
    his[ihis]->SetMarkerStyle(marker_style[ihis]);
    his[ihis]->SetMarkerColor(marker_colour[ihis]);
    his[ihis]->SetMarkerSize(marker_size[ihis]);
    his[ihis]->SetLineColor(marker_colour[ihis]);
    his[ihis]->SetLineStyle(0);
    his[ihis]->SetLineWidth(0);
    
    // Populate legend
    if ( input_legend.size() > ihis ) { legend->AddEntry( his[ihis], input_legend[ihis].c_str(), "ep" ); }
    else                              { legend->AddEntry( his[ihis], input_histos[ihis].c_str(), "ep" ); }

    // Populate stats box
    std::stringstream ss;
    //ss << "Mean=" << int(his[ihis]->GetMean()*100.)/100. << ", RMS=" << int(his[ihis]->GetRMS()*100.)/100.;
    ss << "Entries=" << his[ihis]->GetEntries();
    TText* text = stats->AddText(ss.str().c_str());
    text->SetTextAlign(11);
    text->SetTextSize(0.025);
    text->SetTextColor(marker_colour[ihis]);

    // For Ted
    if ( print_ted ) ted << std::setw(9) << std::scientific << std::setprecision(3) << his[ihis]->GetMean() << ", ";
    
    // Calc min/max number of entries
    if ( his[ihis]->GetMaximum() > aMax ) { aMax = his[ihis]->GetMaximum(); }
    if ( his[ihis]->GetMinimum(1.e-12) < aMin ) { aMin = his[ihis]->GetMinimum(1.e-12); }

  }

  // For Ted
  if ( print_ted ) { 
    ted << ")" << std::endl;
    std::cout << ted.str() << std::endl;
  }

  if ( !his.empty() ) {
    if ( his[0] ) his[0]->GetYaxis()->SetTitleOffset(1.43);
    if ( his[0] ) his[0]->GetYaxis()->SetTitleSize(0.06);
    if ( his[0] ) his[0]->GetXaxis()->SetTitleSize(0.06);
    if ( his[0] ) his[0]->GetXaxis()->SetTitleOffset(0.9);
  }

  // First histo be drawn
  bool first = true;
  for ( uint ihis = 0; ihis < his.size(); ++ihis ) {

    if ( !his[ihis] ) { continue; }
    
    //his[ihis]->GetYaxis()->SetTitle("a.u.");
    
    if ( log ) {
      his[ihis]->SetMaximum( aMax * 10. );
      his[ihis]->SetMinimum( aMin * 0.1 );
    } else {
      his[ihis]->SetMaximum( aMax * 1.1 );
      his[ihis]->SetMinimum( aMin * 0.9 );
    }

    if ( min > 0. ) his[ihis]->SetMinimum( min );
    if ( max > 0. ) his[ihis]->SetMaximum( max );
    
    if ( norm ) {
      std::string options = "";
      if ( first ) { options = "Ehist"; first = false; }
      else { options = "psame"; }
      if ( his[ihis]->GetEntries() > 0. ) { his[ihis]->DrawNormalized(options.c_str()); }
    } else {
      std::string options = "";
      if ( first ) { options = "Ehist"; first = false; }
      else { options = "psame"; }
      his[ihis]->Draw(options.c_str());
    }
    
  } // Loop through histos

  output_file->cd();
  legend->Draw("same");
  stats->Draw("same");
  prelim->Draw("same");
  lumistxt->Draw("same");
  aCanvas->Modified();
  //aCanvas->SaveAs( std::string(output_canvas+".png").c_str() );
  aCanvas->SaveAs( std::string(output_canvas+".pdf").c_str() );
  aCanvas->SaveAs( std::string(output_canvas+".C").c_str() );
  aCanvas->Write();
  return aCanvas;

}
示例#20
0
// all users - please change the name of this file to lhcbStyle.C
// Commits to lhcbdocs svn of .C files are not allowed
void lhcbStyle(){

  // define names for colours
  Int_t black  = 1;
  Int_t red    = 2;
  Int_t green  = 3;
  Int_t blue   = 4;
  Int_t yellow = 5; 
  Int_t magenta= 6;
  Int_t cyan   = 7;
  Int_t purple = 9;
  

////////////////////////////////////////////////////////////////////
// PURPOSE:
//
// This macro defines a standard style for (black-and-white) 
// "publication quality" LHCb ROOT plots. 
//
// USAGE:
//
// Include the lines
//   gROOT->ProcessLine(".L lhcbstyle.C");
//   lhcbStyle();
// at the beginning of your root macro.
//
// Example usage is given in myPlot.C
//
// COMMENTS:
//
// Font:
// 
// The font is chosen to be 132, this is Times New Roman (like the text of
//  your document) with precision 2.
//
// "Landscape histograms":
//
// The style here is designed for more or less square plots.
// For longer histograms, or canvas with many pads, adjustements are needed. 
// For instance, for a canvas with 1x5 histograms:
//  TCanvas* c1 = new TCanvas("c1", "L0 muons", 600, 800);
//  c1->Divide(1,5);
//  Adaptions like the following will be needed:
//  gStyle->SetTickLength(0.05,"x");
//  gStyle->SetTickLength(0.01,"y");
//  gStyle->SetLabelSize(0.15,"x");
//  gStyle->SetLabelSize(0.1,"y");
//  gStyle->SetStatW(0.15);
//  gStyle->SetStatH(0.5);
//
// Authors: Thomas Schietinger, Andrew Powell, Chris Parkes, Niels Tuning
// Maintained by Editorial board member (currently Niels)
///////////////////////////////////////////////////////////////////

  // Use times new roman, precision 2 
  Int_t lhcbFont        = 132;  // Old LHCb style: 62;
  // Line thickness
  Double_t lhcbWidth    = 2.00; // Old LHCb style: 3.00;
  // Text size
  Double_t lhcbTSize    = 0.06; 
  
  // use plain black on white colors
  gROOT->SetStyle("Plain"); 
  TStyle *lhcbStyle= new TStyle("lhcbStyle","LHCb plots style");
  
  //lhcbStyle->SetErrorX(0); //  don't suppress the error bar along X

  lhcbStyle->SetFillColor(1);
  lhcbStyle->SetFillStyle(1001);   // solid
  lhcbStyle->SetFrameFillColor(0);
  lhcbStyle->SetFrameBorderMode(0);
  lhcbStyle->SetPadBorderMode(0);
  lhcbStyle->SetPadColor(0);
  lhcbStyle->SetCanvasBorderMode(0);
  lhcbStyle->SetCanvasColor(0);
  lhcbStyle->SetStatColor(0);
  lhcbStyle->SetLegendBorderSize(0);

  // If you want the usual gradient palette (blue -> red)
  lhcbStyle->SetPalette(1);
  // If you want colors that correspond to gray scale in black and white:
  int colors[8] = {0,5,7,3,6,2,4,1};
  lhcbStyle->SetPalette(8,colors);

  // set the paper & margin sizes
  lhcbStyle->SetPaperSize(20,26);
  lhcbStyle->SetPadTopMargin(0.05);
  lhcbStyle->SetPadRightMargin(0.05); // increase for colz plots
  lhcbStyle->SetPadBottomMargin(0.16);
  lhcbStyle->SetPadLeftMargin(0.14);
  
  // use large fonts
  lhcbStyle->SetTextFont(lhcbFont);
  lhcbStyle->SetTextSize(lhcbTSize);
  lhcbStyle->SetLabelFont(lhcbFont,"x");
  lhcbStyle->SetLabelFont(lhcbFont,"y");
  lhcbStyle->SetLabelFont(lhcbFont,"z");
  lhcbStyle->SetLabelSize(lhcbTSize,"x");
  lhcbStyle->SetLabelSize(lhcbTSize,"y");
  lhcbStyle->SetLabelSize(lhcbTSize,"z");
  lhcbStyle->SetTitleFont(lhcbFont);
  lhcbStyle->SetTitleFont(lhcbFont,"x");
  lhcbStyle->SetTitleFont(lhcbFont,"y");
  lhcbStyle->SetTitleFont(lhcbFont,"z");
  lhcbStyle->SetTitleSize(1.2*lhcbTSize,"x");
  lhcbStyle->SetTitleSize(1.2*lhcbTSize,"y");
  lhcbStyle->SetTitleSize(1.2*lhcbTSize,"z");

  // use medium bold lines and thick markers
  lhcbStyle->SetLineWidth(lhcbWidth);
  lhcbStyle->SetFrameLineWidth(lhcbWidth);
  lhcbStyle->SetHistLineWidth(lhcbWidth);
  lhcbStyle->SetFuncWidth(lhcbWidth);
  lhcbStyle->SetGridWidth(lhcbWidth);
  lhcbStyle->SetLineStyleString(2,"[12 12]"); // postscript dashes
  lhcbStyle->SetMarkerStyle(20);
  lhcbStyle->SetMarkerSize(1.0);

  // label offsets
  lhcbStyle->SetLabelOffset(0.010,"X");
  lhcbStyle->SetLabelOffset(0.010,"Y");

  // by default, do not display histogram decorations:
  //lhcbStyle->SetOptStat(0);  
  lhcbStyle->SetOptStat("emr");  // show only nent -e , mean - m , rms -r
  // full opts at http://root.cern.ch/root/html/TStyle.html#TStyle:SetOptStat
  lhcbStyle->SetStatFormat("6.3g"); // specified as c printf options
  lhcbStyle->SetOptTitle(0);
  lhcbStyle->SetOptFit(0);
  //lhcbStyle->SetOptFit(1011); // order is probability, Chi2, errors, parameters
  //titles
  lhcbStyle->SetTitleOffset(0.95,"X");
  lhcbStyle->SetTitleOffset(0.95,"Y");
  lhcbStyle->SetTitleOffset(1.2,"Z");
  lhcbStyle->SetTitleFillColor(0);
  lhcbStyle->SetTitleStyle(0);
  lhcbStyle->SetTitleBorderSize(0);
  lhcbStyle->SetTitleFont(lhcbFont,"title");
  lhcbStyle->SetTitleX(0.0);
  lhcbStyle->SetTitleY(1.0); 
  lhcbStyle->SetTitleW(1.0);
  lhcbStyle->SetTitleH(0.05);
  
  // look of the statistics box:
  lhcbStyle->SetStatBorderSize(0);
  lhcbStyle->SetStatFont(lhcbFont);
  lhcbStyle->SetStatFontSize(0.05);
  lhcbStyle->SetStatX(0.9);
  lhcbStyle->SetStatY(0.9);
  lhcbStyle->SetStatW(0.25);
  lhcbStyle->SetStatH(0.15);

  // put tick marks on top and RHS of plots
  lhcbStyle->SetPadTickX(1);
  lhcbStyle->SetPadTickY(1);

  // histogram divisions: only 5 in x to avoid label overlaps
  lhcbStyle->SetNdivisions(505,"x");
  lhcbStyle->SetNdivisions(510,"y");
  
  gROOT->SetStyle("lhcbStyle");
  gROOT->ForceStyle();
/*
  // add LHCb label
  lhcbName = new TPaveText(gStyle->GetPadLeftMargin() + 0.05,
                           0.87 - gStyle->GetPadTopMargin(),
                           gStyle->treeGetPadLeftMargin() + 0.20,
                           0.95 - gStyle->GetPadTopMargin(),
                           "BRNDC");
  lhcbName->AddText("LHCb");
  lhcbName->SetFillColor(0);
  lhcbName->SetTextAlign(12);
  lhcbName->SetBorderSize(0);
*/
  TText *lhcbLabel = new TText();
  lhcbLabel->SetTextFont(lhcbFont);
  lhcbLabel->SetTextColor(1);
  lhcbLabel->SetTextSize(lhcbTSize);
  lhcbLabel->SetTextAlign(12);

  TLatex *lhcbLatex = new TLatex();
  lhcbLatex->SetTextFont(lhcbFont);
  lhcbLatex->SetTextColor(1);
  lhcbLatex->SetTextSize(lhcbTSize);
  lhcbLatex->SetTextAlign(12);

  //std::cout << "-------------------------" << std::endl;  
  //std::cout << "Set LHCb Style - Feb 2012" << std::endl;
  //std::cout << "-------------------------" << std::endl;  
  
}
示例#21
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);
}
示例#22
0
void complex_1()
{
   gROOT->GetListOfCanvases()->Delete();
   TCanvas *c = new TCanvas("composite shape", "A * B - C", 700, 1000);

   c->Divide(1,2,0,0);
   c->cd(2);
   gPad->SetPad(0,0,1,0.4);
   c->cd(1);
   gPad->SetPad(0,0.4,1,1);
   
   if (gGeoManager) delete gGeoManager;
   
   new TGeoManager("xtru", "poza12");
   TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7);
   TGeoMedium *med = new TGeoMedium("MED",1,mat);
   TGeoVolume *top = gGeoManager->MakeBox("TOP",med,100,100,100);
   gGeoManager->SetTopVolume(top);

   // define shape components with names
   TGeoBBox *box = new TGeoBBox("box", 20., 20., 20.); 
   TGeoBBox *box1 = new TGeoBBox("box1", 5., 5., 5.); 
   TGeoSphere *sph = new TGeoSphere("sph", 5., 25.);
   TGeoSphere *sph1 = new TGeoSphere("sph1", 1., 15.);
   // create the composite shape based on a Boolean expression
   TGeoTranslation *tr = new TGeoTranslation(0., 30., 0.);
   TGeoTranslation *tr1 = new TGeoTranslation(0., 40., 0.);
   TGeoTranslation *tr2 = new TGeoTranslation(0., 30., 0.);
   TGeoTranslation *tr3 = new TGeoTranslation(0., 30., 0.);
   tr->SetName("tr");
   tr1->SetName("tr1");
   tr2->SetName("tr2");
   tr3->SetName("tr3");
   // register all used transformations
   tr->RegisterYourself();
   tr1->RegisterYourself();
   tr2->RegisterYourself();
   tr3->RegisterYourself();

   TGeoCompositeShape *cs = new TGeoCompositeShape("mir", "(sph * box) + (sph1:tr - box1:tr1)");

   TGeoVolume *vol = new TGeoVolume("COMP4",cs);
//   vol->SetLineColor(randomColor());
   top->AddNode(vol,1);
   gGeoManager->CloseGeometry();
   gGeoManager->SetNsegments(80);
   top->Draw();
   MakePicture();

   c->cd(2);
   TPaveText *pt = new TPaveText(0.01,0.01,0.99,0.99);
   pt->SetLineColor(1);
   TText *text = pt->AddText("TGeoCompositeShape - composite shape class");
   text->SetTextColor(2);
   pt->AddText("----- (sphere * box) + (sphere - box) ");

   pt->AddText(" ");
   pt->SetAllWith("-----","color",4);
   pt->SetAllWith("-----","font",72);
   pt->SetAllWith("-----","size",0.04);
   pt->SetTextAlign(12);
   pt->SetTextSize(0.044);
   pt->Draw();
   c->cd(1);

}
//--------------------------------------------------------------------------------------------------
void plot(long int xStart, long int xEnd, TString text, TString pngFileName)
{
  // Make sure we have the right styles
  MitRootStyle::Init();
  MitRootStyle::SetStyleWide();
  gStyle->SetPadRightMargin(0.07); // to make sure the exponent is on the picture

  // will execute a shell command to get the data
  TString timeSeriesFile("timeSeriesOfRates.txt");

  // Now open our database output
  ifstream input;
  input.open(timeSeriesFile.Data());

  Int_t time=0, nConn=0, nLines=0;
  Double_t rate=0, xMin=double(xStart), xMax=double(xEnd), maxRate=1.0;

  // First loop to determine the boundaries (could be done in one round, dynamically)
  //---------------------------------------------------------------------------------
  while (1) {
    // read in 
    input >> time >> rate >> nConn;
    // check it worked
    if (! input.good())
      break;

    //printf(" Min / Time / Max: %d %d %d\n",xStart,time,xEnd);

    // check whether in our requested time window
    if (xStart>0 && xStart>time)
      continue;
    if (xEnd>0 && xEnd<time)
      continue;
    
    // Show what we are reading
    if (nLines < 5)
      printf(" time=%d, rate=%8f nConnections=%d\n",time, rate, nConn);

    // Determine plot maximum
    if (rate > maxRate)
      maxRate = rate;
    if (nConn > maxRate)
      maxRate = double(nConn);

    nLines++;
  }
  input.close();

  printf(" \n");
  printf(" Found %d measurements.\n",nLines);
  printf(" Maximum tranfer rate at: %6.2f MB/sec\n",maxRate);
  printf(" \n");

  // Open a canvas
  TCanvas *cv = new TCanvas();
  cv->Draw();

  if (nLines<1) {
    printf(" WARNING - no measurements selected.\n");
    plotFrame(double(xStart),double(xEnd));
    double dX = double(xEnd)-double(xStart);
    TText *plotText = new TText(xMin-dX*0.14,0.-(maxRate*1.2*0.14),text.Data());
    printf("Text size: %f\n",plotText->GetTextSize());
    plotText->SetTextSize(0.04);
    plotText->SetTextColor(kBlue);
    plotText->Draw();
    cv->SaveAs(pngFileName.Data());
    return;
  }

  const int numVals = nLines;
  double xVals[numVals];
  double y1Vals[numVals];
  double y2Vals[numVals];

  input.open(timeSeriesFile.Data());

  // Second loop to register the measured values
  //--------------------------------------------
  Int_t i = 0;
  while (1) {
    // read in 
    input >> time >> rate >> nConn;
    // check it worked
    if (!input.good())
      break;

    // check whether in our requested time window
    if (xStart>0 && xStart>time)
      continue;
    if (xEnd>0 && xEnd<time)
      continue;

    xVals[i] = time;
    y1Vals[i] = rate;
    y2Vals[i] = nConn;

    i++;
  }
  input.close();

  // Make a good frame
  plotFrame(xMin,xMax,maxRate);
  double dX = double(xEnd)-double(xStart);
  TText *plotText = new TText(xMin-dX*0.14,0.-(maxRate*1.2*0.14),text.Data());
  plotText->SetTextSize(0.04);
  plotText->SetTextColor(kBlue);
  plotText->Draw();

  // Prepare our graphs
  TGraph* graph1 = new TGraph(numVals, xVals, y1Vals);
  graph1->SetLineColor(2);
  graph1->SetLineWidth(2);
  graph1->SetMarkerColor(4);
  graph1->SetMarkerStyle(21);
  graph1->SetMarkerSize(0.4);
  TGraph* graph2 = new TGraph(numVals, xVals, y2Vals);
  graph2->SetLineColor(3);
  graph2->SetLineWidth(2);
  graph2->SetMarkerColor(4);
  graph2->SetMarkerStyle(20);
  graph2->SetMarkerSize(0.4);

  // Through them into the multigraph
  TMultiGraph *mg = new TMultiGraph();
  mg->Add(graph1,"lp");
  mg->Add(graph2,"lp");

  // Draw the graphs
  mg->Draw("CP");

  // Add a nice legend to the picture
  TLegend *leg = new TLegend(0.4,0.6,0.89,0.89);
  //leg->SetTextSize(0.036);
  leg->SetX1(0.15);
  leg->SetX2(0.30);
  leg->SetY1(0.95);
  leg->SetY2(0.85);
  leg->SetBorderSize(0);
  leg->SetFillStyle(0);
  leg->AddEntry(graph2,"number of tranfers","lp");
  leg->AddEntry(graph1,"data tranfer rate","lp");
  leg->Draw();

  cv->SaveAs(pngFileName);
}
示例#24
0
文件: analyze.C 项目: MycrofD/root
void analyze() {
   TCanvas *c1 = new TCanvas("c1","Analyze.mac",620,790);
   c1->Range(-1,0,19,30);
   TPaveLabel *pl1 = new TPaveLabel(0,27,3.5,29,"Analyze");
   pl1->SetFillColor(42);
   pl1->Draw();
   TPaveText *pt1 = new TPaveText(0,22.8,4,25.2);
   TText *t1  = pt1->AddText("Parenthesis matching");
   TText *t2  = pt1->AddText("Remove unnecessary");
   TText *t2a = pt1->AddText("parenthesis");
   pt1->Draw();
   TPaveText *pt2 = new TPaveText(6,23,10,25);
   TText *t3 = pt2->AddText("break of");
   TText *t4 = pt2->AddText("Analyze");
   pt2->Draw();
   TPaveText *pt3 = new TPaveText(0,19,4,21);
   t4=pt3->AddText("look for simple");
   TText *t5 = pt3->AddText("operators");
   pt3->Draw();
   TPaveText *pt4 = new TPaveText(0,15,4,17);
   TText *t6 = pt4->AddText("look for an already");
   TText *t7 = pt4->AddText("defined expression");
   pt4->Draw();
   TPaveText *pt5 = new TPaveText(0,11,4,13);
   TText *t8 = pt5->AddText("look for usual");
   TText *t9 = pt5->AddText("functions :cos sin ..");
   pt5->Draw();
   TPaveText *pt6 = new TPaveText(0,7,4,9);
   TText *t10 = pt6->AddText("look for a");
   TText *t11 = pt6->AddText("numeric value");
   pt6->Draw();
   TPaveText *pt7 = new TPaveText(6,18.5,10,21.5);
   TText *t12 = pt7->AddText("Analyze left and");
   TText *t13 = pt7->AddText("right part of");
   TText *t14 = pt7->AddText("the expression");
   pt7->Draw();
   TPaveText *pt8 = new TPaveText(6,15,10,17);
   TText *t15 = pt8->AddText("Replace expression");
   pt8->Draw();
   TPaveText *pt9 = new TPaveText(6,11,10,13);
   TText *t16 = pt9->AddText("Analyze");
   pt9->SetFillColor(42);
   pt9->Draw();
   TPaveText *pt10 = new TPaveText(6,7,10,9);
   TText *t17 = pt10->AddText("Error");
   TText *t18 = pt10->AddText("Break of Analyze");
   pt10->Draw();
   TPaveText *pt11 = new TPaveText(14,22,17,24);
   pt11->SetFillColor(42);
   TText *t19  = pt11->AddText("Analyze");
   TText *t19a = pt11->AddText("Left");
   pt11->Draw();
   TPaveText *pt12 = new TPaveText(14,19,17,21);
   pt12->SetFillColor(42);
   TText *t20  = pt12->AddText("Analyze");
   TText *t20a = pt12->AddText("Right");
   pt12->Draw();
   TPaveText *pt13 = new TPaveText(14,15,18,18);
   TText *t21 = pt13->AddText("StackNumber++");
   TText *t22 = pt13->AddText("operator[StackNumber]");
   TText *t23 = pt13->AddText("= operator found");
   pt13->Draw();
   TPaveText *pt14 = new TPaveText(12,10.8,17,13.2);
   TText *t24 = pt14->AddText("StackNumber++");
   TText *t25 = pt14->AddText("operator[StackNumber]");
   TText *t26 = pt14->AddText("= function found");
   pt14->Draw();
   TPaveText *pt15 = new TPaveText(6,7,10,9);
   TText *t27 = pt15->AddText("Error");
   TText *t28 = pt15->AddText("break of Analyze");
   pt15->Draw();
   TPaveText *pt16 = new TPaveText(0,2,7,5);
   TText *t29 = pt16->AddText("StackNumber++");
   TText *t30 = pt16->AddText("operator[StackNumber] = 0");
   TText *t31 = pt16->AddText("value[StackNumber] = value found");
   pt16->Draw();
   TArrow *ar = new TArrow(2,27,2,25.4,0.012,"|>");
   ar->SetFillColor(1);
   ar->Draw();
   ar->DrawArrow(2,22.8,2,21.2,0.012,"|>");
   ar->DrawArrow(2,19,2,17.2,0.012,"|>");
   ar->DrawArrow(2,15,2,13.2,0.012,"|>");
   ar->DrawArrow(2,11,2, 9.2,0.012,"|>");
   ar->DrawArrow(2, 7,2, 5.2,0.012,"|>");
   ar->DrawArrow(4,24,6,24,0.012,"|>");
   ar->DrawArrow(4,20,6,20,0.012,"|>");
   ar->DrawArrow(4,16,6,16,0.012,"|>");
   ar->DrawArrow(4,12,6,12,0.012,"|>");
   ar->DrawArrow(4, 8,6, 8,0.012,"|>");
   ar->DrawArrow(10,20,14,20,0.012,"|>");
   ar->DrawArrow(12,23,14,23,0.012,"|>");
   ar->DrawArrow(12,16.5,14,16.5,0.012,"|>");
   ar->DrawArrow(10,12,12,12,0.012,"|>");
   TText *ta = new TText(2.2,22.2,"err = 0");
   ta->SetTextFont(71);
   ta->SetTextSize(0.015);
   ta->SetTextColor(4);
   ta->SetTextAlign(12);
   ta->Draw();
   ta->DrawText(2.2,18.2,"not found");
   ta->DrawText(2.2,6.2,"found");
   TText *tb = new TText(4.2,24.1,"err != 0");
   tb->SetTextFont(71);
   tb->SetTextSize(0.015);
   tb->SetTextColor(4);
   tb->SetTextAlign(11);
   tb->Draw();
   tb->DrawText(4.2,20.1,"found");
   tb->DrawText(4.2,16.1,"found");
   tb->DrawText(4.2,12.1,"found");
   tb->DrawText(4.2, 8.1,"not found");
   TLine *l1 = new TLine(12,16.5,12,23);
   l1->Draw();
}
示例#25
0
// main method
void LEDRef_evtdis(const int runno = 615,
		   const int gainv = 0,  /*0=low, 1=high*/
		   const int evtnum= -10,
		   int ymax=1023, // set the scale of plots
		   const int delay = 1)  // -1=no delay, wait for input, X>=0 => sleep aprox. X sec. after making plot
{
  // set ranges to plot
  const int strip_f = 0; // first
  const int strip_l = NSTRIPS - 1;
  
  const int nsamples = 65; // number of ADC time samples per channel and event
  
  const int saveplot = 0;
  const int numbering      = 1; // 0: no numbering, 1: nubering on each plot
  const int dofit = 0; // 0: no fit, 1: try to fit the spectra 
  const int debug    = 0;
  const float gammaN = 2;
  // end of setup    
  
  // Assume we are just interested in the 1st segment, _0.root below for fname*
  Char_t fname[256];
  sprintf(fname, "/local/data/Run_%09d.Seq_1A.Stream_0.root",runno);
  cout << "TOTCHAN " << TOTCHAN << endl;

  // set up a raw reader of the data
  AliRawReader *rawReader = NULL;
  rawReader = new AliRawReaderRoot(fname);
  AliCaloRawStream *in = NULL; 
  in = new AliCaloRawStream(rawReader,"EMCAL");

  // set up histograms
  TH1F *hfit[TOTCHAN];
  TF1 *f1[TOTCHAN];
  char ch_label[TOTCHAN][100];
  char buff1[100];
  char name[80];
  for(int i=0; i<TOTCHAN; i++) {
    sprintf(buff1,"hfit_%d",i);
    hfit[i] = new TH1F(buff1,"hfit", nsamples , -0.5, nsamples - 0.5);
    hfit[i]->SetDirectory(0);
    sprintf(name,"f1_%d",i);
    f1[i] = new TF1(name,fitfun,0,70,5);
    f1[i]->SetLineWidth(2);
    f1[i]->SetLineColor(2);

    //	int idx = istrip + NSTRIPS * gain; // encoding used later
    int gain = i / (NSTRIPS);
    int istrip = i % NSTRIPS;
    sprintf(ch_label[i], "Strip%02d", istrip);
  }
  
  TCanvas *cc1 = new TCanvas("cc1","3 columns of 8 strips each",600,800);
  int numcol = NSETS;
  int numrow = NSTRIPS_IN_SET;
  cc1->Divide(numcol, numrow);
  
  TText *t = new TText;
  t->SetTextSize(0.17);
  int clr[2] = {4,2}; // colors
  
  // figure out which events we should look at
  int firstevent = evtnum;
  int lastevent = evtnum;
  if (evtnum < 0) { // get a bunch of events
    firstevent = 0;
    lastevent = - evtnum;
  }
  if (evtnum == 0) { // get all events
    firstevent = 0;
    lastevent = 1000000;
  }
  
  Int_t iev =0;
  AliRawEventHeaderBase *aliHeader=NULL;    
  while ( rawReader->NextEvent() && iev < firstevent) {
    aliHeader = (AliRawEventHeaderBase*) rawReader->GetEventHeader();
    iev++;
  }
  
  // loop over selected events
  while ( rawReader->NextEvent() && iev <= lastevent) {
    aliHeader = (AliRawEventHeaderBase*) rawReader->GetEventHeader();
    int runNumber = aliHeader->Get("RunNb"); 
    
    cout << "Found run number " << runNumber << endl;
    
    // reset histograms
    for(int i=0; i<TOTCHAN; i++) {
      hfit[i]->Reset();
    }
    
    // get events (the "1" ensures that we actually select all events for now)
    if ( 1 || aliHeader->Get("Type") == AliRawEventHeaderBase::kPhysicsEvent ) {
      const UInt_t * evtId = aliHeader->GetP("Id");
      int evno_raw = (int) evtId[0];
      int timestamp = aliHeader->Get("Timestamp");
      
      cout << " evno " << evno_raw
	   << " size " << aliHeader->GetEventSize()
	   << " type " << aliHeader->Get("Type")
	   << " type name " << aliHeader->GetTypeName()
	   << " timestamp " << timestamp
	   << endl;
      
      /// process_event stream
      while ( in->Next() ) {
	
	int strip = in->GetColumn();
	int gain = in->GetRow();
	
	if (in->IsLEDMonData()) {
	  
	  int idx = strip + NSTRIPS*gain;
	  //cout << "hist idx " << idx << endl;
	  
	  if (idx < 0 || idx > TOTCHAN) { 
	    cout << "Hist idx out of range: " << idx << endl;
	  }
	  else { // reasonable range of idx
	    hfit[idx]->SetBinContent(in->GetTime(), in->GetSignal());
	  }

	} // LED Ref data only

      } // Raw data read
    
      // Next: let's actually plot the data..
      for (Int_t strip = strip_f; strip <= strip_l; strip++) {
	
	int idx = strip + NSTRIPS*gainv;
	
	// which set/column does the strip belong in
	int iset = strip / NSTRIPS_IN_SET; 	  
	int within_set = strip % NSTRIPS_IN_SET; 	  
	// on which pad should we plot it?
	int pad_id = (NSTRIPS_IN_SET-1-within_set)*NSETS + iset + 1;
	
	cout << "strip " << strip 
	     << ". set="<< iset << ", within_set=" << within_set
	     << ", pad=" << pad_id << endl;
	cc1->cd(pad_id);
	hfit[idx]->SetTitle("");
	hfit[idx]->SetFillColor(5);
	hfit[idx]->SetMaximum(ymax);
	hfit[idx]->SetMinimum(0);
	// we may or may not decide to fit the data
	if (dofit) {
	  f1[i]->SetParameter(0, 0); // initial guess; zero amplitude :=)
	  hfit[idx]->Fit(f1[i]);
	}
	hfit[idx]->Draw();
	if( numbering ) {
	  t->SetTextColor(clr[gainv]);
	  t->DrawTextNDC(0.65,0.65,ch_label[idx]);
	}
      }

      // add some extra text on the canvas
      // print a box showing run #, evt #, and timestamp
      cc1->cd();
      // first draw transparent pad
      TPad *trans = new TPad("trans","",0,0,1,1);
      trans->SetFillStyle(4000);
      trans->Draw();
      trans->cd();
      // then draw text
      TPaveText *label = new TPaveText(.2,.11,.8,.14,"NDC"); 
      //  label->Clear();
      label->SetBorderSize(1);
      label->SetFillColor(0);
      label->SetLineColor(clr[gainv]);
      label->SetTextColor(clr[gainv]);
      //label->SetFillStyle(0);
      TDatime d;
      d.Set(timestamp);
      sprintf(name,"Run %d, Event %d, Hist Max %d, %s",runno,iev,ymax,d.AsString());
      label->AddText(name);
      label->Draw();
      cc1->Update();
      cout << "Done" << endl;
      
      // some shenanigans to hold the plotting, if requested
      if (firstevent != lastevent) {
	if (delay == -1) {
	  // wait for character input before proceeding
	  cout << " enter y to proceed " << endl;
	  char dummy[2];
	  cin >> dummy;
	  cout << " read " << dummy << endl;
	  if (strcmp(dummy, "y")==0) {
	    cout << " ok, continuing with event " << iev+1 << endl;
	  }
	  else {
	    cout << " ok, exiting " << endl;
	    //exit(1);
	  }
	}
	else {
	  cout << "Sleeping for " << delay * 500 << endl;
	  gSystem->Sleep(delay * 500);
	}
      }

      // save plot, if setup/requested to do so
      char plotname[100];
      if (saveplot==1) {
	sprintf(plotname,"Run_%d_LEDRef_Ev%d_Gain%d_MaxHist%d.gif",
		runno,iev,gainv,ymax);  
	cout <<"SAVING plot:"<< plotname << endl;
	cc1->SaveAs(plotname);
      }

    } // event selection
示例#26
0
void drawHisto(TCanvas* C,TString Group1,TFile* F1,TString Group2,TFile* F2,TString channel,TString category,TString sample,bool PrintDiff){
  C->Clear();
  
  TH1F* H1 = (TH1F*) F1->Get(channel+"_"+category+"/"+sample);
  TH1F* H2 = (TH1F*) F2->Get(channel+"_"+category+"/"+sample);
  
  if(!H1||!H2||H1->Integral()!=H1->Integral()||H2->Integral()!=H2->Integral()){

    if(H1&&H1->Integral()==H1->Integral())H1->Draw("histpe");
    if(H2&&H2->Integral()==H2->Integral())H2->Draw("histpe");

    TText cat;
    cat.DrawTextNDC(.2,.5,channel+"_"+category+"/"+sample);
    if(!H1||H1->Integral()!=H1->Integral()) cat.DrawTextNDC(.2,.4,Group1+" is missing or 0");
    if(!H2||H2->Integral()!=H2->Integral()) cat.DrawTextNDC(.2,.4,Group2+" is missing or 0");

    if(PrintDiff)printf("| %.1f ",100);
    C->Print(TString(C->GetName())+".pdf");
    return;
  }
//   cout<<channel<<" "<<category<<" "<<sample<<endl;
//   cout<<H1->Integral()<<" "<<H2->Integral()<<endl;
//   TText cat;
//   cat.DrawTextNDC(.2,.5,channel+"_"+category+"/"+sample);
//   C->Print(TString(C->GetName())+".pdf");
//   return;


 
  TPad pad1("pad1","",0,0.2,1,1);
  TPad pad2("pad2","",0,0,1,0.2);
    
  ////////////////////////////////////////////
  pad1.cd();


  //H1->SetTitle("");
  H1->SetTitle(channel+"  "+category+"  "+sample);
  H1->GetXaxis()->SetTitle("mass");
  H1->GetYaxis()->SetTitle("");
  H1->GetYaxis()->SetRangeUser(0,(H1->GetMaximum()>H2->GetMaximum() ? H1->GetMaximum() : H2->GetMaximum())*1.2);
  H1->SetLineWidth(3);
  H1->SetLineColor(1);
  H1->SetFillColor(0);
  H1->Draw("histpe");
  H2->SetMarkerSize(0.01);
  H2->SetLineWidth(3);
  H2->SetLineColor(2);
  H2->SetFillColor(0);
  H2->Draw("histesame");
  
  TText TXmine;
  TXmine.SetTextColor(1);
  TXmine.SetTextSize(.04);
  TText TXother;
  TXother.SetTextColor(2);
  TXother.SetTextSize(.04);
  TText TXdiff;
  TXdiff.SetTextColor(4);
  TXdiff.SetTextSize(.03);
  char yield1[100];
  sprintf(yield1,"%.2f",H1->Integral(1,H1->GetNbinsX()));
  char yield2[100];
  sprintf(yield2,"%.2f",H2->Integral(1,H2->GetNbinsX()));
  TXmine.DrawTextNDC(.55,.845,Group1+" : "+yield1);
  TXother.DrawTextNDC(.55,.81,Group2+" : "+yield2);
  char txt[100];
  float diff=100*2*fabs(H1->Integral(1,H1->GetNbinsX())-H2->Integral(1,H2->GetNbinsX()))/(H1->Integral(1,H1->GetNbinsX())+H2->Integral(1,H2->GetNbinsX()));
  sprintf(txt,"Difference = %.1f",diff);
  TXdiff.DrawTextNDC(.25,.85,TString(txt)+"%");

  ////////////////////////////////////////////
  pad2.cd();
  ///Draw the ratio of the historgrams
  TH1F*HDiff=(TH1F*)H2->Clone("HDiff");
  HDiff->Divide(H1);
  HDiff->GetYaxis()->SetRangeUser(0.8,1.2);
  HDiff->GetYaxis()->SetNdivisions(3);
  HDiff->GetYaxis()->SetLabelSize(0.1);
  HDiff->GetYaxis()->SetTitleSize(0.1);
  HDiff->GetYaxis()->SetTitleOffset(0.5);
  //HDiff->GetYaxis()->SetTitle(myGroup + " / " + group);
  HDiff->GetYaxis()->SetTitle("Ratio");
  HDiff->GetXaxis()->SetNdivisions(-1);
  HDiff->GetXaxis()->SetTitle("");
  HDiff->GetXaxis()->SetLabelSize(0.0001);
  HDiff->SetMarkerSize(0.1);
  HDiff->Draw("histpe");
  TLine line;
  line.DrawLine(HDiff->GetXaxis()->GetXmin(),1,HDiff->GetXaxis()->GetXmax(),1);




  C->Clear();
  pad1.Draw();
  pad2.Draw();



  //cout<<setiosflags(ios::fixed)<<precision(2);
  //cout<<"| "<<diff<<" "<<endl;
  //if(PrintDiff)printf("| %.1f ",diff);
  C->Print(TString(C->GetName())+".pdf");

  //delete H1;
  //delete H2;
  delete HDiff;
}
示例#27
0
void massPlot(double lumi=-1., double maxInstLumi=-1.) {

  setTDRStyle();
  //tdrGrid(false, tdrStyle);

  writeExtraText = true;
  //extraText  = "Preliminary Simulation"; 
  //lumi_8TeV = ""; 
  int iPeriod = 2; // 1=7TeV, 2=8TeV, 3=7+8TeV, 7=7+8+13TeV 
  //int iPos=0;
  int iPos=11;
  //int iPos=22;
	
  if (lumi<0)
    lumi=LUMI;
  if (maxInstLumi<0)
    maxInstLumi=MAXINSTLUMI;
  DifferentXSLimitPlots plots(lumi);

  //mchamp index 0 is used, corresponds to 0th mass point = 100 GeV
  plots.calculateCrossSections(0,0,0,39,9);
    
  // three points on counting expt curve
  //TGraph* g_obs_gluino = plots.getMassLimitGluino();
  TGraph* g_gluino = plots.getExpMassLimitGluino();

  //TGraph* g_obs_stop = plots.getMassLimitStop();
  TGraph* g_stop = plots.getExpMassLimitStop();

  TGraph* g_obs_mchamp = plots.getMassLimitMchamp();
  TGraph* g_mchamp = plots.getExpMassLimitMchamp();

  //TGraphAsymmErrors* g_expGluino_1sig = plots.getExpMassLimitGluino1Sig();  
  //TGraphAsymmErrors* g_expGluino_2sig = plots.getExpMassLimitGluino2Sig();  

  //TGraphAsymmErrors* g_expStop_1sig = plots.getExpMassLimitStop1Sig();  
  //TGraphAsymmErrors* g_expStop_2sig = plots.getExpMassLimitStop2Sig();  

  TGraphAsymmErrors* g_exp_1sig = plots.getExpMassLimitMchamp1Sig();  
  TGraphAsymmErrors* g_exp_2sig = plots.getExpMassLimitMchamp2Sig();  

  // one point from lifetime fit
  TGraph* g_tpg = plots.getMassLimitGluinoTP();
  TGraph* g_tps = plots.getMassLimitStopTP();
  
  // theory prediction
  TGraph* g_thGluino = plots.getGluinoTheory();
  TGraph* g_thStop = plots.getStopTheory();
  TGraph* g_thMchamp = plots.getMchampTheory();
  
  TCanvas* canvas = new TCanvas("canvas","",10,10,575,500);

  Double_t x[10], yMinus[10], x2[10], y[10], yPlus[10], z[10];
  cout<<"MCHAMP LIMITS ARE: "<<endl;
  for(Int_t i=0; i<g_mchamp->GetN(); i++){
    g_mchamp->GetPoint(i, x[i], y[i]);
    yPlus[i] = g_exp_1sig->GetErrorYhigh(i);
    yMinus[i] = g_exp_1sig->GetErrorYlow(i);
    g_obs_mchamp->GetPoint(i, x2[i], z[i]);
    cout<<" mass is: "<<x[i]<<", expected limit is: "<<y[i]<<", expected +1 sigma is: "<<yPlus[i]<<", expected -1 sigma is: "<<yMinus[i]<<", observed limit is: "<<z[i]<<endl;
  }

  //canvas->SetGrid();
  canvas->SetLogy();
  
  TH1 * h;
  //h = canvas->DrawFrame(100., 1e-5, 1500., 1e6); //2DSA gluios and stops
  h = canvas->DrawFrame(100., 1e-5, 1000., 1e3); //2DSA
  //h = canvas->DrawFrame(100., 1e-5, 1000., 1e4); //1DSA
  //h->SetTitle(";m [GeV];#sigma [pb]");
  h->SetTitle(";m_{mchamp} [GeV];#sigma(pp #rightarrow mchamp mchamp) [pb]");
  //h->SetTitle(";m_{mchamp} [GeV];#sigma(pp #rightarrow mch mch) #times BF(mch #rightarrow #mu#mu)  [pb]");
  //h->SetTitle("Beamgap Expt;m_{#tilde{g}} [GeV/c^{2}]; #sigma(pp #rightarrow #tilde{g}#tilde{g}) #times BR(#tilde{g} #rightarrow g#tilde{#chi}^{0}) [pb]");
  
  // not covered region
  TBox* nc = new TBox(100., .1, 150., 5e2);
  nc->SetFillStyle(3354);
  nc->SetFillColor(kRed-4);
  //nc->Draw();
  
  /*
  // details
  //TPaveText* blurb = new TPaveText(305., 1.e1, 550., 4.5e2);
  TPaveText* blurb = new TPaveText(0.25, 0.70, 0.50, 0.92, "NDC");
  blurb->AddText("CMS Preliminary 2012");
  
  std::stringstream label;
  label<<"#int L dt = 19.7 fb^{-1}";
  blurb->AddText(label.str().c_str());
  label.str("");
  double peakInstLumi=maxInstLumi;
  int exponent=30;
  while (peakInstLumi>10) {
    peakInstLumi/=10.;
    ++exponent;
  }
  //label<<"L^{max}_{inst} = "<<peakInstLumi<<" x 10^{"<<exponent<<"} cm^{-2}s^{-1}";
  //blurb->AddText(label.str().c_str());
  //label.str("");
  label << "#sqrt{s} = " << ENERGY << " TeV";
  blurb->AddText(label.str().c_str());
  //blurb->AddText("m_{#tilde{g}} - m_{#tilde{#chi}^{0}} = 100 GeV/c^{2}");
  //blurb->AddText("m_{#tilde{t}} - m_{#tilde{#chi}^{0}} = 180 GeV/c^{2}");	
  blurb->SetTextFont(42);
  blurb->SetBorderSize(0);
  blurb->SetFillColor(0);
  blurb->SetShadowColor(0);
  blurb->SetTextAlign(12);
  blurb->SetTextSize(0.033);
  */
  
  // legend
  TBox *legbg = new TBox(600., 1.e1, 900., 4e2);
  //legbg->Draw();
  //TLegend *leg = new TLegend(600., 1.e1, 900., 4e2,"95% C.L. Limits","");
  //TLegend* leg = new TLegend(0.67, 0.70, 0.82, 0.92,"95% CL Limits:","NDC");
  /////////TLegend* leg = new TLegend(0.52, 0.70, 0.77, 0.92,"95% CL Limits:","NDC");
  TLegend* leg = new TLegend(0.45, 0.70, 0.70, 0.92,"95% CL Limits:","NDC");
  leg->SetTextSize(0.033);
  leg->SetBorderSize(0);
  leg->SetTextFont(42);
  leg->SetFillColor(0);

  leg->AddEntry(g_obs_mchamp, "Observed, 10 #mus - 1000 s", "lp");
  leg->AddEntry(g_mchamp, "Expected, 10 #mus - 1000 s", "l");
  leg->AddEntry(g_exp_1sig, "Expected #pm1#sigma, 10 #mus - 1000 s", "lf");
  leg->AddEntry(g_exp_2sig, "Expected #pm2#sigma, 10 #mus - 1000 s", "lf");
  leg->AddEntry(g_thMchamp, "LO Prediction", "l");
  /*
  leg->AddEntry(g_gluino, "Expected Gluino Limit, 10 #mus - 1000 s", "l");
  leg->AddEntry(g_thGluino, "Gluino LO Prediction", "l");
  leg->AddEntry(g_stop, "Expected Stop Limit, 10 #mus - 1000 s", "l");
  leg->AddEntry(g_thStop, "Stop LO Prediction", "l");
  */
  //leg->AddEntry(g_thGluino, "NLO+NLL #tilde{g}", "l");
  //leg->AddEntry(g_gluino, "Obs.: 10 #mus - 1000 s Counting Exp. (#tilde{g})", "l");
  //leg->AddEntry(g_tpg, "Obs.: 10 #mus Timing Profile (#tilde{g})", "l");
  //leg->AddEntry(g_thStop, "NLO+NLL #tilde{t}", "l");
  //leg->AddEntry(g_stop, "Obs.: 10 #mus - 1000 s Counting Exp. (#tilde{t})", "l");
  //leg->AddEntry(g_tps, "Obs.: 10 #mus Timing Profile (#tilde{t})", "l");
  //leg->AddEntry(graph_em, "Obs.: 10 #mus - 1000 s Counting Exp. (EM only)", "l");
  //  leg->AddEntry(graph1, "Obs.: 570 ns Counting Exp.", "l");
  leg->Draw();
  
  
  
  /*
  // gluino curves
  g_gluino->SetLineColor(kBlue);
  g_gluino->SetLineStyle(2);
  g_gluino->SetLineWidth(3);
  g_gluino->Draw("l");

  g_tpg->SetLineColor(kBlue);
  g_tpg->SetLineStyle(3);
  g_tpg->SetLineWidth(3);
  //g_tpg->Draw("l");

  // theory line
  g_thGluino->SetLineColor(kGreen);
  g_thGluino->SetLineStyle(1);
  g_thGluino->SetLineWidth(2);
  g_thGluino->SetFillStyle(3001);
  g_thGluino->SetFillColor(kGreen-4);
  g_thGluino->Draw("l3");


  
   // stop curves
  g_stop->SetLineColor(kRed);
  g_stop->SetLineStyle(2);
  g_stop->SetLineWidth(2);
  g_stop->Draw("l");

  g_tps->SetLineColor(kRed);
  g_tps->SetLineStyle(3);
  g_tps->SetLineWidth(3);
  //g_tps->Draw("l");
   
  g_thStop->SetLineColor(kOrange);
  g_thStop->SetLineStyle(1);
  g_thStop->SetLineWidth(2);
  g_thStop->SetFillStyle(3001);
  g_thStop->SetFillColor(kOrange-4);
  g_thStop->Draw("l3");
  */

  // mchamp curves
  // 2 sigma band
  g_exp_2sig->SetLineColor(0);
  g_exp_2sig->SetLineStyle(0);
  g_exp_2sig->SetLineWidth(0);
  g_exp_2sig->SetFillColor(kYellow);
  g_exp_2sig->SetFillStyle(1001);
  g_exp_2sig->Draw("3");

  // 1 sigma band 
  // g_exp_1sig->SetLineColor(8);                                                                                                                                                           
  g_exp_1sig->SetLineColor(0);
  g_exp_1sig->SetLineStyle(0);
  g_exp_1sig->SetLineWidth(0);
  // g_exp_1sig->SetFillColor(8);                                                                                                                                                           
  g_exp_1sig->SetFillColor(kGreen);
  g_exp_1sig->SetFillStyle(1001);
  // g_exp_1sig->SetFillStyle(3005);                                                                                                                                                        
  g_exp_1sig->Draw("3");
  // g_exp_1sig->Draw("lX");                                                                                                                                                                

  g_obs_mchamp->SetLineStyle(1);
  g_obs_mchamp->SetLineWidth(2);
  g_obs_mchamp->SetMarkerStyle(20);
  g_obs_mchamp->SetMarkerSize(1);
  g_obs_mchamp->Draw("pl");

  //g_mchamp->SetLineColor(kBlue);
  g_mchamp->SetLineStyle(2);
  //g_mchamp->SetLineStyle(1);
  g_mchamp->SetLineWidth(3);
  g_mchamp->SetMarkerStyle(20);
  g_mchamp->SetMarkerSize(1);
  g_mchamp->Draw("l");

  // theory line
  g_thMchamp->SetLineColor(kRed);
  g_thMchamp->SetLineStyle(1);
  g_thMchamp->SetLineWidth(2);
  g_thMchamp->SetFillStyle(3001);
  g_thMchamp->SetFillColor(kRed-4);
  g_thMchamp->Draw("l3");

  // theory line label
  TLatex* th = new TLatex(480., 4., "NLO+NLL #tilde{g}");
  th->SetTextColor(kBlue);
  th->SetTextFont(42);
  th->SetTextSize(0.035);
  //th->Draw();

  TLatex* ths = new TLatex(330., 2., "NLO+NLL #tilde{t}");
  ths->SetTextColor(kRed);
  ths->SetTextFont(42);
  ths->SetTextSize(0.035);
  //ths->Draw();

  TLatex* thm = new TLatex(480., 4., "NLO+NLL mchamp");
  //thm->SetTextColor(kBlue);
  thm->SetTextFont(42);
  thm->SetTextSize(0.035);
  //thm->Draw();

  // not explored label
  TText* ne = new TText(125., .2, "Not Sensitive");
  ne->SetTextColor(kRed+1);
  ne->SetTextFont(42);
  ne->SetTextAngle(90);
  ne->SetTextSize(0.035);
  //ne->Draw();

  //blurb->Draw();

  canvas->RedrawAxis();

  CMS_lumi(canvas, iPeriod, iPos);

  canvas->Print("massLimit.pdf");
  canvas->Print("massLimit.png");
  canvas->Print("massLimit.C");

  plots.calculateIntercepts();

  TFile* fnew = new TFile("histos.root", "recreate");
  fnew->cd();
  g_obs_mchamp->Write();
  g_mchamp->Write();
  g_thMchamp->Write();

}
示例#28
0
文件: style.C 项目: renqgl90/Seeding
void style()
{
  ////////////////////////////////////////////////////////////////////
  // PURPOSE:
  //
  // This macro defines a reasonable style for (black-and-white)
  // "publication quality" ROOT plots. The default settings contain
  // many features that are either not desirable for printing on white
  // paper or impair the general readibility of plots.
  //
  // USAGE:
  //
  // Simply include the line
  //   gROOT->ProcessLine(".x $LHCBSTYLE/root/lhcbstyle.C");
  // at the beginning of your root macro.
  //
  // SOME COMMENTS:
  //
  // Statistics and fit boxes:
  //
  // "Decorative" items around the histogram are kept to a minimum.
  // In particular there is no box with statistics or fit information.
  // You can easily change this either by editing your private copy
  // of this style file or by calls to "gStyle" in your macro.
  // For example,
  //   gStyle->SetOptFit(1011);
  // will add some fit information.
  //
  // Font:
  //
  // The font is chosen to be 62, i.e.helvetica-bold-r-normal with
  // precision 2. Font is of course a matter of taste, but most people
  // will probably agree that Helvetica bold gives close to optimal
  // readibility in presentations. It appears to be the ROOT default,
  // and since there are still some features in ROOT that simply won't
  // respond to any font requests, it is the wise choice to avoid
  // ugly font mixtures on the same plot... The precision of the font (2)
  // is chosen in order to have a rotatable and scalable font. Be sure
  // to use true-type fonts! I.e.
  // Unix.*.Root.UseTTFonts: true  in your .rootrc file.
  //
  // "Landscape histograms":
  //
  // The style here is designed for more or less quadratic plots.
  // For very long histograms, adjustements are needed. For instance,
  // for a canvas with 1x5 histograms:
  //  TCanvas* c1 = new TCanvas("c1", "L0 muons", 600, 800);
  //  c1->Divide(1,5);
  // adaptions like the following will be needed:
  //  gStyle->SetTickLength(0.05,"x");
  //  gStyle->SetTickLength(0.01,"y");
  //  gStyle->SetLabelSize(0.15,"x");
  //  gStyle->SetLabelSize(0.1,"y");
  //  gStyle->SetStatW(0.15);
  //  gStyle->SetStatH(0.5);
  //
  ////////////////////////////////////////////////////////////////////
  /*cout << "executing lhcbStyle.C:" << endl;
    cout << "                      " << endl;
    cout << "                      " << endl;
    cout << "                         $      $   $   $$$   $    " << endl;
    cout << "                         $      $   $  $      $    " << endl;
    cout << "                         $      $$$$$  $      $$$  " << endl;
    cout << "                         $      $   $  $      $  $ " << endl;
    cout << "                         $$$$$  $   $   $$$   $$$  " << endl;
    cout << " " << endl;
    cout << "                           LHCb ROOT style file " << endl;
    cout << " " << endl;
    cout <<
    "     Problems, suggestions, contributions to [email protected]" << endl;
    cout << " " << endl;*/
  //gROOT->Reset();
  TStyle *lhcbStyle= new TStyle("lhcbStyle","Thomas personal plots style");
  // use helvetica-bold-r-normal, precision 2 (rotatable)
  Int_t lhcbFont = 62;
  // line thickness
  Double_t lhcbWidth = 3.00;
  // use plain black on white colors
  lhcbStyle->SetFrameBorderMode(0);
  lhcbStyle->SetCanvasBorderMode(0);
  lhcbStyle->SetPadBorderMode(0);
  lhcbStyle->SetPadColor(0);
  lhcbStyle->SetCanvasColor(0);
  lhcbStyle->SetStatColor(0);
  lhcbStyle->SetPalette(1);
  //lhcbStyle->SetTitleColor(0);
  //lhcbStyle->SetFillColor(0);
  // set the paper & margin sizes
  lhcbStyle->SetPaperSize(20,26);
  lhcbStyle->SetPadTopMargin(0.05);
  lhcbStyle->SetPadRightMargin(0.05); // increase for colz plots!!
  lhcbStyle->SetPadBottomMargin(0.16);
  lhcbStyle->SetPadLeftMargin(0.14);
  // use large fonts
  lhcbStyle->SetTextFont(lhcbFont);
  lhcbStyle->SetTextSize(0.08);
  lhcbStyle->SetLabelFont(lhcbFont,"x");
  lhcbStyle->SetLabelFont(lhcbFont,"y");
  lhcbStyle->SetLabelFont(lhcbFont,"z");
  lhcbStyle->SetLabelSize(0.03,"x");
  lhcbStyle->SetLabelSize(0.03,"y");
  lhcbStyle->SetLabelSize(0.03,"z");
  lhcbStyle->SetTitleFont(lhcbFont);
  lhcbStyle->SetTitleSize(0.06,"x");
  lhcbStyle->SetTitleSize(0.06,"y");
  lhcbStyle->SetTitleSize(0.06,"z");
  // use bold lines and markers
  lhcbStyle->SetLineWidth(lhcbWidth);
  lhcbStyle->SetFrameLineWidth(lhcbWidth);
  lhcbStyle->SetHistLineWidth(lhcbWidth);
  lhcbStyle->SetFuncWidth(lhcbWidth);
  lhcbStyle->SetGridWidth(lhcbWidth);
  lhcbStyle->SetLineStyleString(2,"[12 12]"); // postscript dashes
  //lhcbStyle->SetMarkerStyle(15);
  lhcbStyle->SetMarkerStyle(20);
  lhcbStyle->SetMarkerSize(1.2);
  // label offsets
  lhcbStyle->SetLabelOffset(0.020);
  // by default, do not display histogram decorations:
  lhcbStyle->SetOptStat(0);
  lhcbStyle->SetOptStat(1110);  // show only nent, mean, rms
  //lhcbStyle->SetOptTitle(0);
  lhcbStyle->SetOptFit(0);
  //lhcbStyle->SetOptFit(1011); // show probability, parameters and errors
  // look of the statistics box:
  lhcbStyle->SetStatBorderSize(1);
  lhcbStyle->SetStatFont(lhcbFont);
  lhcbStyle->SetStatFontSize(0.05);
  lhcbStyle->SetStatX(0.9);
  lhcbStyle->SetStatY(0.9);
  lhcbStyle->SetStatW(0.25);
  lhcbStyle->SetStatH(0.15);
  // put tick marks on top and RHS of plots
  lhcbStyle->SetPadTickX(1);
  lhcbStyle->SetPadTickY(1);
  // histogram divisions: only 5 in x to avoid label overlaps
  lhcbStyle->SetNdivisions(505,"x");
  lhcbStyle->SetNdivisions(510,"y");
  TPaveText *lhcbName = new TPaveText(0.65,0.8,0.9,0.9,"BRNDC");
  lhcbName->SetFillColor(0);
  lhcbName->SetTextAlign(12);
  lhcbName->SetBorderSize(0);
  lhcbName->AddText("LHCb");
  // TPaveText *lhcbPrelimR = new TPaveText(0.70 - lhcbStyle->GetPadRightMargin(),
  //                                        0.80 - lhcbStyle->GetPadTopMargin(),
  //                                        0.95 - lhcbStyle->GetPadRightMargin(),
  //                                        0.85 - lhcbStyle->GetPadTopMargin(),
  //                                        "BRNDC");
  // lhcbPrelimR->SetFillColor(0);
  // lhcbPrelimR->SetTextAlign(12);
  // lhcbPrelimR->SetBorderSize(0);
  // lhcbPrelimR->AddText("#splitline{LHCb}{#scale[1.0]{Preliminary}}");
  // TPaveText *lhcbPrelimL = new TPaveText(lhcbStyle->GetPadLeftMargin() + 0.05,
  //                                        0.87 - lhcbStyle->GetPadTopMargin(),
  //                                        lhcbStyle->GetPadLeftMargin() + 0.30,
  //                                        0.95 - lhcbStyle->GetPadTopMargin(),
  //                                        "BRNDC");
  // lhcbPrelimL->SetFillColor(0);
  // lhcbPrelimL->SetTextAlign(12);
  // lhcbPrelimL->SetBorderSize(0);
  // lhcbPrelimL->AddText("#splitline{LHCb}{#scale[1.0]{Preliminary}}");
  // TPaveText *lhcb7TeVPrelimR = new TPaveText(0.70 - lhcbStyle->GetPadRightMargin(),
  //                                            0.75 - lhcbStyle->SetPadTopMargin(0.05),
  //                                            0.95 - lhcbStyle->GetPadRightMargin(),
  //                                            0.85 - lhcbStyle->SetPadTopMargin(0.05),
  //                                            "BRNDC");
  // lhcb7TeVPrelimR->SetFillColor(0);
  // lhcb7TeVPrelimR->SetTextAlign(12);
  // lhcb7TeVPrelimR->SetBorderSize(0);
  // lhcb7TeVPrelimR->AddText("#splitline{#splitline{LHCb}{Preliminary}}{#scale[0.7]{#sqrt{s} = 7 TeV Data}}");
  // TPaveText *lhcb7TeVPrelimL = new TPaveText(lhcbStyle->GetPadLeftMargin() + 0.05,
  //                                            0.78 - lhcbStyle->SetPadTopMargin(0.05),
  //                                            lhcbStyle->GetPadLeftMargin() + 0.30,
  //                                            0.88 - lhcbStyle->SetPadTopMargin(0.05),
  //                                            "BRNDC");
  // lhcb7TeVPrelimL->SetFillColor(0);
  // lhcb7TeVPrelimL->SetTextAlign(12);
  // lhcb7TeVPrelimL->SetBorderSize(0);
  // lhcb7TeVPrelimL->SetTextSize(0.06);
  // lhcb7TeVPrelimL->AddText("#splitline{#splitline{LHCb}{Preliminary}}{#scale[0.7]{#sqrt{s} = 7 TeV Data}}");
  // TPaveText *lhcb7TeVPrelimR = new TPaveText(0.70 - lhcbStyle->GetPadRightMargin(),
  //                                            0.75 - lhcbStyle->SetPadTopMargin(0.05),
  //                                            0.95 - lhcbStyle->GetPadRightMargin(),
  //                                            0.85 - lhcbStyle->SetPadTopMargin(0.05),
  //                                            "BRNDC");
  // lhcb7TeVPrelimR->SetFillColor(0);
  // lhcb7TeVPrelimR->SetTextAlign(12);
  // lhcb7TeVPrelimR->SetBorderSize(0);
  // lhcb7TeVPrelimR->AddText("#splitline{#splitline{LHCb}{Preliminary}}{#scale[0.7]{#sqrt{s} = 900 eV Data}}");
  // TPaveText *lhcb0_9TeVPrelimL = new TPaveText(lhcbStyle->GetPadLeftMargin() + 0.05,
  //                                              0.78 - lhcbStyle->SetPadTopMargin(0.05),
  //                                              lhcbStyle->GetPadLeftMargin() + 0.30,
  //                                              0.88 - lhcbStyle->SetPadTopMargin(0.05),
  //                                              "BRNDC");
  // lhcb0_9TeVPrelimL->SetFillColor(0);
  // lhcb0_9TeVPrelimL->SetTextAlign(12);
  // lhcb0_9TeVPrelimL->SetBorderSize(0);
  // lhcb0_9TeVPrelimL->SetTextSize(0.06);
  // lhcb0_9TeVPrelimL->AddText("#splitline{#splitline{LHCb}{Preliminary}}{#scale[0.7]{#sqrt{s} = 900 GeV Data}}");
  TText *lhcbLabel = new TText();
  lhcbLabel->SetTextFont(lhcbFont);
  lhcbLabel->SetTextColor(1);
  lhcbLabel->SetTextSize(0.04);
  lhcbLabel->SetTextAlign(12);
  TLatex *lhcbLatex = new TLatex();
  lhcbLatex->SetTextFont(lhcbFont);
  lhcbLatex->SetTextColor(1);
  lhcbLatex->SetTextSize(0.04);
  lhcbLatex->SetTextAlign(12);
  gROOT->SetStyle("lhcbStyle");
  gROOT->ForceStyle();
}
示例#29
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]);
}
示例#30
0
void plotpurity()
{

 Bool_t dolines = kFALSE;
 //Bool_t dolines = kTRUE;
 TString lines = "";

 TString xn = "";
 //TString xn = "_onlyQCD";
 //TString xn = "_onlyGJ";
 //TString xn = "_denominator";
 if(dolines){lines="/lines";}

 std::vector<TString> rebins;
 rebins.push_back("");
// rebins.push_back("rebin1");
// rebins.push_back("rebin2");
// rebins.push_back("rebin3");
// rebins.push_back("rebin4");
// rebins.push_back("rebin5");

 std::vector<TString> ptranges;
// ptranges.push_back("90to120");
// ptranges.push_back("120to155");
// ptranges.push_back("155to175");
 ptranges.push_back("175to190");
 ptranges.push_back("190to250");
 ptranges.push_back("250to400");
 ptranges.push_back("400to700");
 ptranges.push_back("700to1000");
 ptranges.push_back("175to1000");
 //ptranges.push_back("250to1000");
 //ptranges.push_back("400to1000");

 std::vector<TString> isovars;
 //isovars.push_back("wchiso");
 isovars.push_back("chiso");
// isovars.push_back("sieieF5x5");
// isovars.push_back("sieipF5x5");
// isovars.push_back("sipipF5x5");
// isovars.push_back("rho");
// isovars.push_back("nVtx");
// isovars.push_back("phoet");
// isovars.push_back("pfMET");

 std::vector<TString> cuts;
 cuts.push_back("a_idnc");
 cuts.push_back("b_idnc_mL30");
 cuts.push_back("c_idnc_trig");
 cuts.push_back("d_idnc_mL30_trig");
 cuts.push_back("e_idnc_t175");
 cuts.push_back("f_idnc_mL30_t175");
 cuts.push_back("g_idnc_t250");
 cuts.push_back("h_idnc_mL30_t250");
 cuts.push_back("i_idnc_mL30_allt");
// cuts.push_back("oldj");

 TString inpath = "/afs/hep.wisc.edu/cms/tperry/LoneG_slc6_491_CMSSW_7_4_14/src/LoneGamma/qcdStudy/gitignore/Lire/analyzed";
 TString outpath = "/afs/hep.wisc.edu/cms/tperry/LoneG_slc6_491_CMSSW_7_4_14/src/LoneGamma/qcdStudy/gitignore/Lire/plots";
 TString wwwpath = "/afs/hep.wisc.edu/home/tperry/www/MonoPhoton/qcdPlots/Lire/purity";

 TString inname_GJ  = inpath+"/purity_GJets_Merged.root";
 TString inname_QCD = inpath+"/purity_QCD_Merged.root";
// TString inname_GJ  = inpath+"/purity_mrg4bins_GJets.root";
// TString inname_QCD = inpath+"/purity_mrg4bins_QCD.root";
 //TString inname_GJ  = inpath+"/purity_mrg3bins_GJets.root";
 //TString inname_QCD = inpath+"/purity_mrg3bins_QCD.root";
 
 TFile *infile_GJ  = new TFile(inname_GJ);
 TFile *infile_QCD = new TFile(inname_QCD);
 
 ofstream log;
 ofstream log_latex;
 log.open (outpath+"/Purity_log"+xn+".txt");
 log_latex.open (outpath+"/Purity_log_latex"+xn+".txt");

 Int_t fillcolor = 3;
 gStyle->SetOptStat(0);
 gStyle->SetOptTitle(0);
 gStyle->SetFrameLineWidth(3);
 gStyle->SetLineWidth(2);

 TCanvas* canvas = new TCanvas("canvas","canvas",900,100,500,500);
 gStyle->SetOptStat(0);
 gPad->SetTickx();
 gPad->SetTicky();
 gStyle->SetLineWidth(3);


 TText* title = new TText(1,1,"") ;
 title->SetTextSize(0.07);
 title->SetTextColor(kBlack);
 title->SetTextAlign(13);
 title->SetTextFont(62);

 TText* extra = new TText(1,1,"") ;
 extra->SetTextSize(0.05);
 extra->SetTextColor(kBlack);
 extra->SetTextAlign(13);
 extra->SetTextFont(52);

 TText* lumi = new TText(1,1,"") ;
 lumi->SetTextSize(0.05);
 lumi->SetTextColor(kBlack);
 lumi->SetTextAlign(31);
 lumi->SetTextFont(42);

 int c_sig = 4;
 int c_bkg = 2;
 int c_den = 8;
 int ls_cmb = 1;
 int ls_gj  = 2;
 int ls_qcd = 3;

 //for(std::vector<TString>::iterator it = ptranges.begin(); it != ptranges.end(); ++it) {
 for(unsigned i=0; i<ptranges.size(); i++) {
  for(unsigned j=0; j<isovars.size(); j++) {
   for(unsigned k=0; k<cuts.size(); k++) {
    for(unsigned l=0; l<rebins.size(); l++) {

     TString ptrange = ptranges.at(i);
     TString isovar = isovars.at(j);
     TString cut = cuts.at(k);
     TString rebin = rebins.at(l);

     TString cutname;
     if(cut=="idnc"){cutname="ID";}
     if(cut=="idnc_mL30"){cutname="ID+MET";}
     if(cut=="idnc_trig"){cutname="ID+Trigger";}
     if(cut=="idnc_mL30_trig"){cutname="ID+MET+Trigger";}

     TString bwidth;
     if(rebin=="rebin1"){bwidth="width=0.5";}
     if(rebin=="rebin2"){bwidth="width=1.0";}
     if(rebin=="rebin3"){bwidth="width=1.5";}
     if(rebin=="rebin4"){bwidth="width=2.0";}
     if(rebin=="rebin5"){bwidth="width=2.5";}

     std::cout<<boost::format("%8s %15s %7s %7s ") % ptrange % cut % isovar % rebin<<std::endl;

     //Signal purity
     TH1F* h_Nsig_GJ  = (TH1F*)infile_GJ->Get("h_Nsig_"+isovar+"_"+ptrange+"_"+cut);
     TH1F* h_Nsig_QCD = (TH1F*)infile_QCD->Get("h_Nsig_"+isovar+"_"+ptrange+"_"+cut);
     h_Nsig_GJ->Rebin(3); h_Nsig_QCD->Rebin(3); //h_Nsig_GJ->Rebin(l+1); h_Nsig_QCD->Rebin(l+1);
             //TH1F* h_Nsig  = (TH1F*)h_Nsig_QCD->Clone("h_Nsig");
     TH1F* h_Nsig  = (TH1F*)h_Nsig_GJ->Clone("h_Nsig");
     h_Nsig->Add(h_Nsig_QCD);
     h_Nsig->SetLineColor(c_sig); h_Nsig_GJ->SetLineColor(c_sig); h_Nsig_QCD->SetLineColor(c_sig);
     h_Nsig->SetLineStyle(ls_cmb); h_Nsig_GJ->SetLineStyle(ls_gj); h_Nsig_QCD->SetLineStyle(ls_qcd);
     h_Nsig->SetLineWidth(2); h_Nsig_GJ->SetLineWidth(2); h_Nsig_QCD->SetLineWidth(2);
     //Background purity
     TH1F* h_Nbkg_GJ  = (TH1F*)infile_GJ->Get("h_Nbkg_"+isovar+"_"+ptrange+"_"+cut);
     TH1F* h_Nbkg_QCD = (TH1F*)infile_QCD->Get("h_Nbkg_"+isovar+"_"+ptrange+"_"+cut);
     h_Nbkg_GJ->Rebin(3); h_Nbkg_QCD->Rebin(3);
             //TH1F* h_Nbkg  = (TH1F*)h_Nbkg_QCD->Clone("h_Nbkg");
     TH1F* h_Nbkg  = (TH1F*)h_Nbkg_GJ->Clone("h_Nbkg");
     h_Nbkg->Add(h_Nbkg_QCD);
     h_Nbkg->SetLineColor(c_bkg); h_Nbkg_GJ->SetLineColor(c_bkg); h_Nbkg_QCD->SetLineColor(c_bkg);
     h_Nbkg->SetLineStyle(ls_cmb); h_Nbkg_GJ->SetLineStyle(ls_gj); h_Nbkg_QCD->SetLineStyle(ls_qcd);
     h_Nbkg->SetLineWidth(2); h_Nbkg_GJ->SetLineWidth(2); h_Nbkg_QCD->SetLineWidth(2);

     //Denominator
     TH1F* h_Deno_GJ  = (TH1F*)h_Nsig_GJ->Clone("h_Deno_GJ");
     h_Deno_GJ->Add(h_Nbkg_GJ);

     TH1F* h_Deno_QCD  = (TH1F*)h_Nsig_QCD->Clone("h_Deno_QCD");
     h_Deno_QCD->Add(h_Nbkg_QCD);

//     TH1F* h_Deno_GJ  = (TH1F*)infile_GJ->Get("h_Deno_"+isovar+"_"+ptrange+"_"+cut);
//     TH1F* h_Deno_QCD = (TH1F*)infile_QCD->Get("h_Deno_"+isovar+"_"+ptrange+"_"+cut);
//     h_Deno_GJ->Rebin(3); h_Deno_QCD->Rebin(3);
//             //TH1F* h_Deno  = (TH1F*)h_Deno_QCD->Clone("h_Deno");
     TH1F* h_Deno  = (TH1F*)h_Deno_GJ->Clone("h_Deno");
     h_Deno->Add(h_Deno_QCD);

     h_Deno->SetLineColor(c_den); h_Deno_GJ->SetLineColor(c_den); h_Deno_QCD->SetLineColor(c_den);
     h_Deno->SetLineStyle(ls_cmb); h_Deno_GJ->SetLineStyle(ls_gj); h_Deno_QCD->SetLineStyle(ls_qcd);
     h_Deno->SetLineWidth(1); h_Deno_GJ->SetLineWidth(1); h_Deno_QCD->SetLineWidth(1);

     // should probably add these as last bin..
     h_Nsig->ClearUnderflowAndOverflow();
     h_Nbkg->ClearUnderflowAndOverflow();
     h_Deno->ClearUnderflowAndOverflow();
     
     //Define purity
     TGraphAsymmErrors *purity_signal     = new TGraphAsymmErrors(h_Nsig,h_Deno,"n");
     purity_signal->SetLineWidth(2);
     purity_signal->SetLineColor(4);
     purity_signal->SetMarkerColor(4);
     purity_signal->SetMarkerStyle(20);
     
     TGraphAsymmErrors *purity_background = new TGraphAsymmErrors(h_Nbkg,h_Deno,"n");
     purity_background->SetLineWidth(2);
     purity_background->SetLineColor(2);
     purity_background->SetMarkerColor(2);
     purity_background->SetMarkerStyle(24);

     //-----------------------------------------------------
     // Calculations
     log<<boost::format("%8s %15s %7s %7s ") % ptrange % cut % isovar % rebin  ;

     // Start lower bound calculation
     Int_t nbins;
     nbins = purity_background->GetN();
     log<<boost::format("(%2i bins) \n") % nbins ; 

     std::vector<Double_t> thresholds, xsatthresh, ysatthresh, xsatqt, avgpur;
     std::vector<Int_t> batthresh, batqt;

     thresholds.clear(); // purity thresholds
     xsatthresh.clear(); // x st. f(x) > thresh
     ysatthresh.clear(); // y = f(x)x at thresh
     batthresh.clear();  // bin corresponding to x

     batqt.clear();      // bin at upper threshold
     xsatqt.clear();     // x value at upper thresh

     avgpur.clear();     // average purity over range

     thresholds.push_back(0.50);
     thresholds.push_back(0.55);
     thresholds.push_back(0.60);
     thresholds.push_back(0.65);
     thresholds.push_back(0.70);
     Int_t nthreshs;
     nthreshs = thresholds.size();

     // find purity lower bounds = x st. f(x)>thresh
     Double_t pointx, pointy;     
     for(int m=0; m<nbins; ++m){
      purity_background->GetPoint(m, pointx, pointy);
      //log<<boost::format(" %2i %2.2f %2.2f \n") % i % pointx % pointy;
      
      for(int n=0; n<nthreshs; ++n){
       if(pointy > thresholds.at(n) && ysatthresh.size()==n ){
        ysatthresh.push_back(pointy);
        xsatthresh.push_back(pointx);
        batthresh.push_back(h_Nsig->FindBin(pointx));
       }
      }
     }

     // for thresholds never reached, fill with content of xmax
     purity_background->GetPoint(nbins-1,pointx,pointy);
     Int_t nrnpassthresh = 0;
     nrnpassthresh = nthreshs - ysatthresh.size();
     for(int n=0; n<nrnpassthresh; ++n){
       ysatthresh.push_back(pointy);
       xsatthresh.push_back(pointx);
       batthresh.push_back(h_Nsig->FindBin(pointx));
     }

     //// dump lower bound threshold info
     //for(int n=0; n<nthreshs; ++n){
     // log<<boost::format("  Threshold: %.2f  %2i (%2.2f, %0.2f)\n")
     //  % thresholds.at(n) % batthresh.at(n) % xsatthresh.at(n) % ysatthresh.at(n) ;
     //}

     log<<boost::format("   Threshold bin (xx.x,yy.y) TotalSize   above|below\n");
     // Start upper bound calculation
     Double_t fullsize = h_Nbkg->Integral(0,-1);
     for(int n=0; n<nthreshs; ++n){
      Double_t sizedown = h_Nbkg->Integral(0,batthresh.at(n)-1);
      Double_t sizeup =   h_Nbkg->Integral(batthresh.at(n),-1);
      log<<boost::format("    %7.2f %3i (%2.1f,%1.2f)    %4.1f  %6.1f|%6.1f \n")
       % thresholds.at(n) % batthresh.at(n) % xsatthresh.at(n) % ysatthresh.at(n)    
       % fullsize % sizeup % sizedown ;
     }

     // upper bound calculation 
     // keep adding contents of bins starting at threshbin 
      // until sum > fraction (1/4) of full integral
     Double_t goalsize = fullsize / 4.;

     for(int n=0; n<nthreshs; ++n){
      Double_t thissize = 0.;
      int thisbin = batthresh.at(n);
      while( thisbin < nbins+1 ){
       thissize += h_Nbkg->GetBinContent(thisbin); 
       if(thissize > goalsize){
        break;
        }
       thisbin++;
      }
      batqt.push_back(thisbin);
      xsatqt.push_back(h_Nbkg->GetBinCenter(thisbin));
     }

    log<<"       Target Eventcount: "<<goalsize<<" = fullsize/4 = "<<fullsize<<"/4 \n";
     log<<boost::format("   Threshold blo bhi (xlo,xhi) Int(blo,bhi) Int(blo,bhi+1) Int(blo,bhi-1)\n");

    // find average purity over range
    // must weight each purity bin by nr. events in bin
    for(int n=0; n<nthreshs; ++n){
     int nbins = batqt.at(n) - batthresh.at(n);
     //std::cout<<nbins<<" "<<batthresh.at(n)<<" "<<batqt.at(n)<<std::endl;
     Double_t sumpurs, sumweights;
     sumpurs = 0.;
     sumweights = 0.;
     for(int o=0; o<nbins+1; ++o){
      int thisbin = batthresh.at(n) + o;
      int thispoint = thisbin - 1;  // bin nr = point nr + 1
      purity_background->GetPoint(thispoint, pointx,pointy);
      sumpurs += pointy*h_Nbkg->GetBinContent(thisbin);
      sumweights += h_Nbkg->GetBinContent(thisbin);
      //std::cout<<" "<<thispoint<<"|"<<pointy<<"|"<<h_Nbkg->GetBinContent(thisbin)<<" "<<std::endl;;
     }
     //std::cout<<std::endl;
     //std::cout<<sumpurs/sumweights<<std::endl<<std::endl;;
     avgpur.push_back( sumpurs/sumweights );
    }
     log_latex<<"\\begin{tabular}{r|r|r|r|r|r|r|r}\n";
     log_latex<<boost::format("\\multicolumn{2}{c|}{%8s} & \\multicolumn{2}{c|}{%15s} & \\multicolumn{2}{c|}{%7s} & \\multicolumn{2}{c|}{%7s} \\\\ \\hline \\hline  \n") % ptrange % cutname % isovar % bwidth  ;
     log_latex<<boost::format("   %10s & %5s & %5s & %10s & %5s & %8s & %15s & %10s  \\\\  \\hline \n")
      % "Threshold" 
      % "x lo" % "x hi" 
      % "avg purity"
      % "err \\%" 
      % "evts. tot." 
      % "evts. > x lo" 
      % "evts in rng." ;

     ///log_latex<<"\\begin{tabular}{r|r|r|r|r}\n";
     ///log_latex<<boost::format("%8s & \\multicolumn{2}{c}{%15s} & %7s & %7s \\\\  \n \\hline \\hline \n") % ptrange % cutname % isovar % bwidth  ;
     ///log_latex<<boost::format("   %10s & %5s & %5s & %10s & %5s \\\\ \n \\hline \n")
     /// % "Threshold" 
     /// % "x lo" % "x hi" 
     /// % "avg purity"
     /// % "err \\%" ;
    for(int n=0; n<nthreshs; ++n){
     log<<boost::format("    %7.2f %3i %3i (%2.1f,%1.2f) %10.2f %10.2f %10.2f  \n")
      % thresholds.at(n) % batthresh.at(n) %batqt.at(n)
      % xsatthresh.at(n) % xsatqt.at(n) 
      % h_Nbkg->Integral(batthresh.at(n),batqt.at(n))
      % h_Nbkg->Integral(batthresh.at(n),batqt.at(n)+1)
      % h_Nbkg->Integral(batthresh.at(n),batqt.at(n)-1) ;

     Double_t nrevents, errevents, pcterr;
     nrevents = h_Nbkg->IntegralAndError(batthresh.at(n),batqt.at(n),errevents);
     pcterr = errevents/nrevents;
     log_latex<<boost::format("   %10.2f & %5.2f & %5.2f & %10.4f &  %5.2f &  %8.1f & %15.1f & %10.1f  \\\\  \n")
      % thresholds.at(n) 
      % h_Nbkg->GetBinLowEdge(h_Nbkg->FindBin(xsatthresh.at(n))) % h_Nbkg->GetBinLowEdge(h_Nbkg->FindBin(xsatqt.at(n) ))
      //% xsatthresh.at(n) % xsatqt.at(n) 
      % avgpur.at(n)
      % (pcterr*100) 
      % fullsize 
      % h_Nbkg->Integral(batthresh.at(n),-1)
      % h_Nbkg->Integral(batthresh.at(n),batqt.at(n));

     ///log_latex<<boost::format("   %10.2f & %5.2f & %5.2f & %7.3f &  %5.2f  \\\\  \n")
     /// % thresholds.at(n) 
     /// % xsatthresh.at(n) % xsatqt.at(n) 
     /// % avgpur.at(n)
     /// % (pcterr*100) ;
    }
     log_latex<<"\\hline \n  \\end{tabular}\n";

     //-----------------------------------------------------
     // all set, now to start thinking about plotting
     //Make lower bound lines (purity)
     Double_t frac = 1./nthreshs;
     TLine *lgb_lo0 = new TLine(xsatthresh.at(0), 0*frac, xsatthresh.at(0), 1*frac);
     TLine *lgb_lo1 = new TLine(xsatthresh.at(1), 1*frac, xsatthresh.at(1), 2*frac);
     TLine *lgb_lo2 = new TLine(xsatthresh.at(2), 2*frac, xsatthresh.at(2), 3*frac);
     TLine *lgb_lo3 = new TLine(xsatthresh.at(3), 3*frac, xsatthresh.at(3), 4*frac);
     TLine *lgb_lo4 = new TLine(xsatthresh.at(4), 4*frac, xsatthresh.at(4), 5*frac);
     TLine *lgc_lo0 = new TLine(xsatthresh.at(0), 0*frac, xsatthresh.at(0), 1*frac);
     TLine *lgc_lo1 = new TLine(xsatthresh.at(1), 1*frac, xsatthresh.at(1), 2*frac);
     TLine *lgc_lo2 = new TLine(xsatthresh.at(2), 2*frac, xsatthresh.at(2), 3*frac);
     TLine *lgc_lo3 = new TLine(xsatthresh.at(3), 3*frac, xsatthresh.at(3), 4*frac);
     TLine *lgc_lo4 = new TLine(xsatthresh.at(4), 4*frac, xsatthresh.at(4), 5*frac);

     lgb_lo0->SetLineColor(1);
     lgb_lo1->SetLineColor(1);
     lgb_lo2->SetLineColor(1);
     lgb_lo3->SetLineColor(1);
     lgb_lo4->SetLineColor(1);
     lgc_lo0->SetLineColor(2);
     lgc_lo1->SetLineColor(3);
     lgc_lo2->SetLineColor(4);
     lgc_lo3->SetLineColor(5);
     lgc_lo4->SetLineColor(6);

     lgb_lo0->SetLineWidth(4);
     lgb_lo1->SetLineWidth(4);
     lgb_lo2->SetLineWidth(4);
     lgb_lo3->SetLineWidth(4);
     lgb_lo4->SetLineWidth(4);
     lgc_lo0->SetLineWidth(2);
     lgc_lo1->SetLineWidth(2);
     lgc_lo2->SetLineWidth(2);
     lgc_lo3->SetLineWidth(2);
     lgc_lo4->SetLineWidth(2);

     //Make upper bound lines (purity)
     TLine *lgb_hi0 = new TLine(xsatqt.at(0), 0*frac, xsatqt.at(0), 1*frac);
     TLine *lgb_hi1 = new TLine(xsatqt.at(1), 1*frac, xsatqt.at(1), 2*frac);
     TLine *lgb_hi2 = new TLine(xsatqt.at(2), 2*frac, xsatqt.at(2), 3*frac);
     TLine *lgb_hi3 = new TLine(xsatqt.at(3), 3*frac, xsatqt.at(3), 4*frac);
     TLine *lgb_hi4 = new TLine(xsatqt.at(4), 4*frac, xsatqt.at(4), 5*frac);
     TLine *lgc_hi0 = new TLine(xsatqt.at(0), 0*frac, xsatqt.at(0), 1*frac);
     TLine *lgc_hi1 = new TLine(xsatqt.at(1), 1*frac, xsatqt.at(1), 2*frac);
     TLine *lgc_hi2 = new TLine(xsatqt.at(2), 2*frac, xsatqt.at(2), 3*frac);
     TLine *lgc_hi3 = new TLine(xsatqt.at(3), 3*frac, xsatqt.at(3), 4*frac);
     TLine *lgc_hi4 = new TLine(xsatqt.at(4), 4*frac, xsatqt.at(4), 5*frac);

     lgb_hi0->SetLineColor(1);
     lgb_hi1->SetLineColor(1);
     lgb_hi2->SetLineColor(1);
     lgb_hi3->SetLineColor(1);
     lgb_hi4->SetLineColor(1);
     lgc_hi0->SetLineColor(2);
     lgc_hi1->SetLineColor(3);
     lgc_hi2->SetLineColor(4);
     lgc_hi3->SetLineColor(5);
     lgc_hi4->SetLineColor(6);

     lgb_hi0->SetLineWidth(4);
     lgb_hi1->SetLineWidth(4);
     lgb_hi2->SetLineWidth(4);
     lgb_hi3->SetLineWidth(4);
     lgb_hi4->SetLineWidth(4);
     lgc_hi0->SetLineWidth(2);
     lgc_hi1->SetLineWidth(2);
     lgc_hi2->SetLineWidth(2);
     lgc_hi3->SetLineWidth(2);
     lgc_hi4->SetLineWidth(2);

     lgc_hi0->SetLineStyle(2);
     lgc_hi1->SetLineStyle(2);
     lgc_hi2->SetLineStyle(2);
     lgc_hi3->SetLineStyle(2);
     lgc_hi4->SetLineStyle(2);

     //Make avg purity horizontal lines
     TLine *lgb_pur0 = new TLine(xsatthresh.at(0), avgpur.at(0), xsatqt.at(0), avgpur.at(0));
     TLine *lgb_pur1 = new TLine(xsatthresh.at(1), avgpur.at(1), xsatqt.at(1), avgpur.at(1));
     TLine *lgb_pur2 = new TLine(xsatthresh.at(2), avgpur.at(2), xsatqt.at(2), avgpur.at(2));
     TLine *lgb_pur3 = new TLine(xsatthresh.at(3), avgpur.at(3), xsatqt.at(3), avgpur.at(3));
     TLine *lgb_pur4 = new TLine(xsatthresh.at(4), avgpur.at(4), xsatqt.at(4), avgpur.at(4));
     TLine *lgc_pur0 = new TLine(xsatthresh.at(0), avgpur.at(0), xsatqt.at(0), avgpur.at(0));
     TLine *lgc_pur1 = new TLine(xsatthresh.at(1), avgpur.at(1), xsatqt.at(1), avgpur.at(1));
     TLine *lgc_pur2 = new TLine(xsatthresh.at(2), avgpur.at(2), xsatqt.at(2), avgpur.at(2));
     TLine *lgc_pur3 = new TLine(xsatthresh.at(3), avgpur.at(3), xsatqt.at(3), avgpur.at(3));
     TLine *lgc_pur4 = new TLine(xsatthresh.at(4), avgpur.at(4), xsatqt.at(4), avgpur.at(4));

     lgb_pur0->SetLineColor(1);
     lgb_pur1->SetLineColor(1);
     lgb_pur2->SetLineColor(1);
     lgb_pur3->SetLineColor(1);
     lgb_pur4->SetLineColor(1);
     //lgb_pur0->SetLineColor(2);
     //lgb_pur1->SetLineColor(3);
     //lgb_pur2->SetLineColor(4);
     //lgb_pur3->SetLineColor(5);
     //lgb_pur4->SetLineColor(6);
     lgc_pur0->SetLineColor(2);
     lgc_pur1->SetLineColor(3);
     lgc_pur2->SetLineColor(4);
     lgc_pur3->SetLineColor(5);
     lgc_pur4->SetLineColor(6);

     lgb_pur0->SetLineWidth(4);
     lgb_pur1->SetLineWidth(4);
     lgb_pur2->SetLineWidth(4);
     lgb_pur3->SetLineWidth(4);
     lgb_pur4->SetLineWidth(4);
     lgc_pur0->SetLineWidth(2);
     lgc_pur1->SetLineWidth(2);
     lgc_pur2->SetLineWidth(2);
     lgc_pur3->SetLineWidth(2);
     lgc_pur4->SetLineWidth(2);

     //lgc_pur0->SetLineStyle(2);
     //lgc_pur1->SetLineStyle(2);
     //lgc_pur2->SetLineStyle(2);
     //lgc_pur3->SetLineStyle(2);
     //lgc_pur4->SetLineStyle(2);

     //-----------------------------------------------------
     Double_t themax = 0 ;
     themax = std::max(themax, h_Nsig->GetMaximum());
     themax = std::max(themax, h_Nbkg->GetMaximum());
     themax = std::max(themax, h_Deno->GetMaximum());

     //Make lower bound lines (hist)
     Double_t logmax;
     Double_t logmin;
     logmax = std::log(themax);
     logmin = std::log(1);
     Double_t spacing = (logmax-logmin)/nthreshs;
     //std::cout<<spacing<<std::endl;

     //Double_t fifmax = themax/5.;
     TLine *lhb_lo0 = new TLine(xsatthresh.at(0), exp(logmin+0*spacing), xsatthresh.at(0), exp(logmin+1*spacing));
     TLine *lhb_lo1 = new TLine(xsatthresh.at(1), exp(logmin+1*spacing), xsatthresh.at(1), exp(logmin+2*spacing));
     TLine *lhb_lo2 = new TLine(xsatthresh.at(2), exp(logmin+2*spacing), xsatthresh.at(2), exp(logmin+3*spacing));
     TLine *lhb_lo3 = new TLine(xsatthresh.at(3), exp(logmin+3*spacing), xsatthresh.at(3), exp(logmin+4*spacing));
     TLine *lhb_lo4 = new TLine(xsatthresh.at(4), exp(logmin+4*spacing), xsatthresh.at(4), exp(logmin+5*spacing));
     TLine *lhc_lo0 = new TLine(xsatthresh.at(0), exp(logmin+0*spacing), xsatthresh.at(0), exp(logmin+1*spacing));
     TLine *lhc_lo1 = new TLine(xsatthresh.at(1), exp(logmin+1*spacing), xsatthresh.at(1), exp(logmin+2*spacing));
     TLine *lhc_lo2 = new TLine(xsatthresh.at(2), exp(logmin+2*spacing), xsatthresh.at(2), exp(logmin+3*spacing));
     TLine *lhc_lo3 = new TLine(xsatthresh.at(3), exp(logmin+3*spacing), xsatthresh.at(3), exp(logmin+4*spacing));
     TLine *lhc_lo4 = new TLine(xsatthresh.at(4), exp(logmin+4*spacing), xsatthresh.at(4), exp(logmin+5*spacing));

     lhb_lo0->SetLineColor(1);
     lhb_lo1->SetLineColor(1);
     lhb_lo2->SetLineColor(1);
     lhb_lo3->SetLineColor(1);
     lhb_lo4->SetLineColor(1);
     lhc_lo0->SetLineColor(2);
     lhc_lo1->SetLineColor(3);
     lhc_lo2->SetLineColor(4);
     lhc_lo3->SetLineColor(5);
     lhc_lo4->SetLineColor(6);

     lhb_lo0->SetLineWidth(4);
     lhb_lo1->SetLineWidth(4);
     lhb_lo2->SetLineWidth(4);
     lhb_lo3->SetLineWidth(4);
     lhb_lo4->SetLineWidth(4);
     lhc_lo0->SetLineWidth(2);
     lhc_lo1->SetLineWidth(2);
     lhc_lo2->SetLineWidth(2);
     lhc_lo3->SetLineWidth(2);
     lhc_lo4->SetLineWidth(2);

     //Make upper bound lines (hist)
     TLine *lhb_hi0 = new TLine(xsatqt.at(0), exp(logmin+0*spacing), xsatqt.at(0), exp(logmin+1*spacing));
     TLine *lhb_hi1 = new TLine(xsatqt.at(1), exp(logmin+1*spacing), xsatqt.at(1), exp(logmin+2*spacing));
     TLine *lhb_hi2 = new TLine(xsatqt.at(2), exp(logmin+2*spacing), xsatqt.at(2), exp(logmin+3*spacing));
     TLine *lhb_hi3 = new TLine(xsatqt.at(3), exp(logmin+3*spacing), xsatqt.at(3), exp(logmin+4*spacing));
     TLine *lhb_hi4 = new TLine(xsatqt.at(4), exp(logmin+4*spacing), xsatqt.at(4), exp(logmin+5*spacing));
     TLine *lhc_hi0 = new TLine(xsatqt.at(0), exp(logmin+0*spacing), xsatqt.at(0), exp(logmin+1*spacing));
     TLine *lhc_hi1 = new TLine(xsatqt.at(1), exp(logmin+1*spacing), xsatqt.at(1), exp(logmin+2*spacing));
     TLine *lhc_hi2 = new TLine(xsatqt.at(2), exp(logmin+2*spacing), xsatqt.at(2), exp(logmin+3*spacing));
     TLine *lhc_hi3 = new TLine(xsatqt.at(3), exp(logmin+3*spacing), xsatqt.at(3), exp(logmin+4*spacing));
     TLine *lhc_hi4 = new TLine(xsatqt.at(4), exp(logmin+4*spacing), xsatqt.at(4), exp(logmin+5*spacing));

     lhb_hi0->SetLineColor(1);
     lhb_hi1->SetLineColor(1);
     lhb_hi2->SetLineColor(1);
     lhb_hi3->SetLineColor(1);
     lhb_hi4->SetLineColor(1);
     lhc_hi0->SetLineColor(2);
     lhc_hi1->SetLineColor(3);
     lhc_hi2->SetLineColor(4);
     lhc_hi3->SetLineColor(5);
     lhc_hi4->SetLineColor(6);

     lhb_hi0->SetLineWidth(4);
     lhb_hi1->SetLineWidth(4);
     lhb_hi2->SetLineWidth(4);
     lhb_hi3->SetLineWidth(4);
     lhb_hi4->SetLineWidth(4);
     lhc_hi0->SetLineWidth(2);
     lhc_hi1->SetLineWidth(2);
     lhc_hi2->SetLineWidth(2);
     lhc_hi3->SetLineWidth(2);
     lhc_hi4->SetLineWidth(2);

     lhc_hi0->SetLineStyle(2);
     lhc_hi1->SetLineStyle(2);
     lhc_hi2->SetLineStyle(2);
     lhc_hi3->SetLineStyle(2);
     lhc_hi4->SetLineStyle(2);
     //-----------------------------------------------------


     //-----------------------------------------------------
     //Draw Histograms
     TLegend *meg = new TLegend(0.4,0.6,0.88,0.88);
     //meg->SetTextSize(0.04) ;
     meg->SetFillColor(0); meg->SetShadowColor(0);meg->SetBorderSize(2);
     meg->SetTextFont(22.);
     meg->AddEntry(h_Nsig,"Signal","l");
     meg->AddEntry(h_Nsig_GJ,"Signal (GJ MC)","l");
     meg->AddEntry(h_Nsig_QCD,"Signal (QCD MC)","l");
     meg->AddEntry(h_Nbkg,"Background","l");
     meg->AddEntry(h_Nbkg_GJ,"Background (GJ MC)","l");
     meg->AddEntry(h_Nbkg_QCD,"Background (QCD MC)","l");
     meg->AddEntry(h_Deno,"Denominator","l");
     meg->AddEntry(h_Deno_GJ,"Denominator (GJ MC)","l");
     meg->AddEntry(h_Deno_QCD,"Denominator (QCD MC)","l");
     
     TString leg_h0;  leg_h0.Form("Purity > %0.2f (%2.1f-%2.1f)", thresholds.at(0), xsatthresh.at(0), xsatqt.at(0));
     TString leg_h1;  leg_h1.Form("Purity > %0.2f (%2.1f-%2.1f)", thresholds.at(1), xsatthresh.at(1), xsatqt.at(1));
     TString leg_h2;  leg_h2.Form("Purity > %0.2f (%2.1f-%2.1f)", thresholds.at(2), xsatthresh.at(2), xsatqt.at(2));
     TString leg_h3;  leg_h3.Form("Purity > %0.2f (%2.1f-%2.1f)", thresholds.at(3), xsatthresh.at(3), xsatqt.at(3));
     TString leg_h4;  leg_h4.Form("Purity > %0.2f (%2.1f-%2.1f)", thresholds.at(4), xsatthresh.at(4), xsatqt.at(4));

     TLegend *neg = new TLegend(0.15,0.5,0.4,0.75);
     //meg->SetTextSize(0.04) ;
     neg->SetFillColor(0); neg->SetShadowColor(0);neg->SetBorderSize(2);
     neg->SetTextFont(22.);
     neg->AddEntry(lhc_lo0,leg_h0,"l");
     neg->AddEntry(lhc_lo1,leg_h1,"l");
     neg->AddEntry(lhc_lo2,leg_h2,"l");
     neg->AddEntry(lhc_lo3,leg_h3,"l");
     neg->AddEntry(lhc_lo4,leg_h4,"l");

     h_Nsig->SetTitle(cut);
     h_Nsig->SetXTitle(h_Nsig->GetTitle());
     h_Nsig->SetYTitle("Events ");
     h_Nsig->SetMaximum(1000*themax);
     h_Nsig->SetMinimum(1);

     h_Nsig->Draw("hist");
     h_Nsig_GJ->Draw("hist,same");
     h_Nsig_QCD->Draw("hist,same");
     h_Nbkg->Draw("hist,same");
     h_Nbkg_GJ->Draw("hist,same");
     h_Nbkg_QCD->Draw("hist,same");
     h_Deno->Draw("hist,same");
     h_Deno_GJ->Draw("hist,same");
     h_Deno_QCD->Draw("hist,same");

     meg->SetHeader("photon p_{T}: "+ptrange);
     meg->Draw();
     if(dolines){
      neg->Draw();
     }
     title->DrawTextNDC(0.17,0.87,"CMS");
     extra->DrawTextNDC(0.17,0.81,"Preliminary");
     lumi->DrawTextNDC(0.9,0.91,"2.32 /fb (13 TeV)");

     if(dolines){
      lhb_lo0->Draw();
      lhb_lo1->Draw();
      lhb_lo2->Draw();
      lhb_lo3->Draw();
      lhb_lo4->Draw();
      
      lhb_hi0->Draw();
      lhb_hi1->Draw();
      lhb_hi2->Draw();
      lhb_hi3->Draw();
      lhb_hi4->Draw();

      lhc_lo0->Draw();
      lhc_lo1->Draw();
      lhc_lo2->Draw();
      lhc_lo3->Draw();
      lhc_lo4->Draw();
      
      lhc_hi0->Draw();
      lhc_hi1->Draw();
      lhc_hi2->Draw();
      lhc_hi3->Draw();
      lhc_hi4->Draw();
     }

     gPad->SetLogy();

     canvas->SaveAs(outpath+"/Histos_"+isovar+"_"+ptrange+"_"+cut+rebin+xn+".pdf");
     canvas->SaveAs(wwwpath+"/pdf/"+ptrange+"/"+isovar+"/"+cut+lines+"/Histos_"+isovar+"_"+ptrange+"_"+cut+rebin+xn+".pdf");
     canvas->SaveAs(wwwpath+"/png/"+ptrange+"/"+isovar+"/"+cut+lines+"/Histos_"+isovar+"_"+ptrange+"_"+cut+rebin+xn+".png");
     canvas->Clear();
     gPad->SetLogy(kFALSE);
     //-----------------------------------------------------
     //-----------------------------------------------------
     //Draw Purity
     TLegend *leg = new TLegend(0.5,0.75,0.88,0.88);
     leg->SetTextSize(0.04) ;
     leg->SetFillColor(0); leg->SetShadowColor(0);leg->SetBorderSize(0);
     leg->SetTextFont(22.);
     leg->AddEntry(purity_signal,"Signal","lep");
     leg->AddEntry(purity_background,"Background","lep");

     float xmin ; //= 0.;
     float xmax ; //= 25.;
     xmin = h_Nsig->GetXaxis()->GetXmin();
     xmax = h_Nsig->GetXaxis()->GetXmax();
     TLine *lowline = new TLine(xmin,0,xmax,0);
     TLine *hiline = new TLine(xmin,1,xmax,1);
     lowline->SetLineWidth(1); lowline->SetLineColor(1); lowline->SetLineStyle(3);         
     hiline->SetLineWidth(1); hiline->SetLineColor(1); hiline->SetLineStyle(3);         

     TH1F *hframe = canvas->DrawFrame(xmin,-0.05,xmax,1.4,"");
     lowline->Draw();
     hiline->Draw();
     title->DrawTextNDC(0.17,0.87,"CMS");
     extra->DrawTextNDC(0.17,0.81,"Preliminary");
     lumi->DrawTextNDC(0.9,0.91,"2.32 /fb (13 TeV)");
     hframe->SetTitle(cut);
     hframe->SetXTitle(isovar);
     hframe->SetYTitle("Purity");
     
     // draw points
     purity_signal->Draw("P");
     purity_background->Draw("P");
     leg->SetHeader("photon p_{T}: "+ptrange);
     leg->Draw();

     //canvas->SaveAs(outpath+"/Purity_"+isovar+"_"+ptrange+"_"+cut+"_"+rebin+xn+".pdf");

     if(dolines){
      lgb_lo0->Draw();
      lgb_lo1->Draw();
      lgb_lo2->Draw();
      lgb_lo3->Draw();
      lgb_lo4->Draw();
      
      lgb_hi0->Draw();
      lgb_hi1->Draw();
      lgb_hi2->Draw();
      lgb_hi3->Draw();
      lgb_hi4->Draw();
      
      lgc_lo0->Draw();
      lgc_lo1->Draw();
      lgc_lo2->Draw();
      lgc_lo3->Draw();
      lgc_lo4->Draw();
      
      lgc_hi0->Draw();
      lgc_hi1->Draw();
      lgc_hi2->Draw();
      lgc_hi3->Draw();
      lgc_hi4->Draw();

      lgb_pur0->Draw();
      lgb_pur1->Draw();
      lgb_pur2->Draw();
      lgb_pur3->Draw();
      lgb_pur4->Draw();
      lgc_pur0->Draw();
      lgc_pur1->Draw();
      lgc_pur2->Draw();
      lgc_pur3->Draw();
      lgc_pur4->Draw();
     }
     
     canvas->SaveAs(outpath+"/Purity_"+isovar+"_"+ptrange+"_"+cut+rebin+xn+".pdf");
     canvas->SaveAs(wwwpath+"/pdf/"+ptrange+"/"+isovar+"/"+cut+lines+"/Purity_"+isovar+"_"+ptrange+"_"+cut+rebin+xn+".pdf");
     canvas->SaveAs(wwwpath+"/png/"+ptrange+"/"+isovar+"/"+cut+lines+"/Purity_"+isovar+"_"+ptrange+"_"+cut+rebin+xn+".png");

     canvas->Clear();
     //-----------------------------------------------------

     // clean your room!
     h_Nsig->Delete();
     h_Nsig_GJ->Delete();
     h_Nsig_QCD->Delete();
     h_Nbkg->Delete();
     h_Nbkg_GJ->Delete();
     h_Nbkg_QCD->Delete();
     h_Deno->Delete();
     h_Deno_GJ->Delete();
     h_Deno_QCD->Delete();
    }
   log<<"--------------------------------------\n";
   log_latex<<"--------------------------------------\n";
   }
  }
 }
 log.close();
 log_latex.close();
}