Beispiel #1
0
//________________________________________________________
void GFHistManager::ColourStatsBoxes(GFHistArray *hists) const
{
  // colours stats boxes like hists' line colors and moves the next to each other
  if (!hists) return;
  Double_t x1 = fStatsX1, x2 = fStatsX2, y1 = fStatsY1, y2 = fStatsY2;
  for (Int_t iH = 0; iH < hists->GetEntriesFast(); ++iH) {
    TH1 *h = hists->At(iH);
    if (!h) continue;
    TObject *statObj = h->GetListOfFunctions()->FindObject("stats");
    if (statObj && statObj->InheritsFrom(TPaveStats::Class())) {
      TPaveStats *stats = static_cast<TPaveStats*>(statObj);
      stats->SetLineColor(hists->At(iH)->GetLineColor());
      stats->SetTextColor(hists->At(iH)->GetLineColor());
      stats->SetX1NDC(x1);
      stats->SetX2NDC(x2);
      stats->SetY1NDC(y1);
      stats->SetY2NDC(y2);
      y2 = y1 - 0.005; // shift down 2
      y1 = y2 - (fStatsY2 - fStatsY1); // shift down 1
      if (y1 < 0.) {
	y1 = fStatsY1; y2 = fStatsY2; // restart y-positions
	x2 = x1 - 0.005; // shift left 2
	x1 = x2 - (fStatsX2 - fStatsX1); // shift left 1
	if (x1 < 0.) { // give up, start again:
	  x1 = fStatsX1, x2 = fStatsX2, y1 = fStatsY1, y2 = fStatsY2;
	}
      }
    } else if (gStyle->GetOptStat() != 0) { // failure in case changed in list via TExec....
      this->Warning("ColourStatsBoxes", "No stats found for %s", hists->At(iH)->GetName());
    }
  }
}
//------------------------------------------------------------------------------
void PlotAlignmentValidation::plotSubDetResiduals(bool plotNormHisto,unsigned int subDetId)
{
  setNiceStyle();
 
  gStyle->SetOptStat(11111);
  gStyle->SetOptFit(0000);

  TCanvas *c = new TCanvas("c", "c", 600,600);
  c->SetTopMargin(0.15);
  TString histoName= "";
  if (plotNormHisto) {histoName= "h_NormXprime";}
  else histoName= "h_Xprime_";
  switch (subDetId){
  case 1 : histoName+="TPBBarrel_0";break;
  case 2 : histoName+="TPEendcap_1";break;
  case 3 : histoName+="TPEendcap_2";break;
  case 4 : histoName+="TIBBarrel_0";break;
  case 5 : histoName+="TIDEndcap_1";break;
  case 6 : histoName+="TIDEndcap_2";break;
  case 7 : histoName+="TOBBarrel_3";break;
  case 8 : histoName+="TECEndcap_4";break;
  case 9 : histoName+="TECEndcap_5";break;
  }
  int tmpcounter = 0;
  TH1 *sumHisto = 0;
  for(std::vector<TkOfflineVariables*>::iterator it = sourceList.begin();
      it != sourceList.end(); ++it) {
    if (tmpcounter == 0 ) {
      TFile *f= (*it)->getFile();
      sumHisto =(TH1*) f->FindKeyAny(histoName)->ReadObj();//FindObjectAny(histoName.Data());
      sumHisto->SetLineColor(tmpcounter+1);
      sumHisto->SetLineStyle(tmpcounter+1);
      sumHisto->GetFunction("tmp")->SetBit(TF1::kNotDraw);
      sumHisto->Draw();
      
      //get statistic box coordinate to plot all boxes one below the other
      //gStyle->SetStatY(0.91);
      //gStyle->SetStatW(0.15);
      //gStyle->SetStatBorderSize(1);
      //gStyle->SetStatH(0.10);
      
      
      tmpcounter++;
    } else {
      sumHisto = (TH1*) (*it)->getFile()->FindObjectAny(histoName);
      sumHisto->SetLineColor(tmpcounter+1);
      sumHisto->SetLineStyle(tmpcounter+1);
      sumHisto->GetFunction("tmp")->SetBit(TF1::kNotDraw);
      //hstack->Add(sumHisto);
      
      c->Update();
      tmpcounter++;  
    }
    TObject *statObj = sumHisto->GetListOfFunctions()->FindObject("stats");
    if (statObj && statObj->InheritsFrom(TPaveStats::Class())) {
      TPaveStats *stats = static_cast<TPaveStats*>(statObj);
      stats->SetLineColor(tmpcounter+1);
      stats->SetTextColor(tmpcounter+1);
      stats->SetFillColor(10);
      stats->SetX1NDC(0.91-tmpcounter*0.1);
      stats->SetX2NDC(0.15);
      stats->SetY1NDC(1);
      stats->SetY2NDC(0.10);
      sumHisto->Draw("sames");
    }
  }
  //hstack->Draw("nostack");
  char PlotName[1000];
  sprintf( PlotName, "%s/%s.eps", outputDir.c_str(), histoName.Data() );
  
  c->Print(PlotName);
  //delete c;
  //c=0;
    
}
Beispiel #3
0
// -----------------------------------------------------------------------------
// Create plots
void plot( std::string& path, 
	   std::string& type, 
	   std::string& sample, 
	   std::string& dir, 
	   std::string& histo,
	   double lumi,
	   bool scale ) {

  std::string canvas_name = histo + "_" + dir + "_" + type + "_" + sample;

  // Create canvas  
  TCanvas* canvas = new TCanvas(canvas_name.c_str(),"");
  canvas->SetFillColor(0);
  canvas->SetFrameBorderMode(0);
  canvas->SetFrameFillColor(0);
  canvas->SetTopMargin(0.10);
  canvas->SetBottomMargin(0.12);
  canvas->SetLeftMargin(0.12);
  canvas->SetRightMargin(0.15);

  // Retrieve histogram
  std::string file_name = path + type + "_" + sample + ".root";
  TFile* f =  new TFile(file_name.c_str(),"READ");
  TDirectory* d = (TDirectory*)f->Get(dir.c_str());
  TH2D* his = (TH1*)d->Get(histo.c_str());
  if ( !his ) return;

  //his->Rebin2D(2,2);

  if ( true ) { gPad->SetLogz(); }
  if ( scale ) his->Scale( lumi / 100. );
  his->SetMaximum(1.e4);
  his->SetMinimum(1.e-5);
  //his->SetMinimum( his->GetMinimum(1.e-12) );

//   his->SetMaximum( 20000. );
//   his->SetMinimum( 2.e-4 );

//   his->SetMaximum( 20000. );
//   his->SetMinimum( 20. );

  double xmin = his->GetXaxis()->GetXmin();
  double xmax = his->GetXaxis()->GetXmax();
  double ymin = his->GetYaxis()->GetXmin();
  double ymax = his->GetYaxis()->GetXmax();
  
  // Reset title
  std::string title = ";" + std::string(his->GetXaxis()->GetTitle()) + ";" + std::string(his->GetYaxis()->GetTitle());
  his->SetTitle(title.c_str());
  his->GetXaxis()->SetTitle("x_{2}");
  his->GetXaxis()->SetTitleOffset(1.2);
  his->GetYaxis()->SetTitle("x_{1}");
  his->GetYaxis()->SetTitleOffset(1.4);
  his->Draw("COLZ");
  gPad->Update();

  // Lumi
  if (1) { 
    std::stringstream ss;

    ss << "#int L dt = " << lumi << " pb^{-1}";
    double xpos = 0.05 * (xmax-xmin)+xmin;
    double ypos = 0.25 * (ymax-ymin)+ymin;
    TLatex* text1 = new TLatex(xpos,ypos,ss.str().c_str());
    text1->SetTextAlign(12); 
    text1->SetTextSize(0.035);
    text1->Draw();
  }

  // Jet type
  if (1) { 
    double xpos = 0.05 * (xmax-xmin)+xmin;
    double ypos = 0.15 * (ymax-ymin)+ymin;
    TText* text2 = new TText(xpos,ypos,type.c_str());
    text2->SetTextAlign(12); 
    text2->SetTextSize(0.035);
    text2->Draw();
  }

  // Sample
  if (1) {
    double xpos = 0.05 * (xmax-xmin)+xmin;
    double ypos = 0.10 * (ymax-ymin)+ymin;
    TText* text3 = new TText(xpos,ypos,sample.c_str());
    text3->SetTextAlign(12); 
    text3->SetTextSize(0.035);
    text3->Draw();
  }

  // Stats
  gStyle->SetOptStat("i");
  his->SetStats(1);
  TPaveStats* stats = (TPaveStats*)his->GetListOfFunctions()->FindObject("stats"); 
  std::string stats_pos = "br";
  if ( stats ) { 
    stats->SetFillColor(0);
    stats->SetLineColor(0); 
    stats->SetShadowColor(0); 
    if ( stats_pos == "tr" ) {
      stats->SetX1NDC(0.60); stats->SetY1NDC(0.68); stats->SetX2NDC(0.83); stats->SetY2NDC(0.88); 
    } else if ( stats_pos == "br" ) {
      stats->SetX1NDC(0.60); stats->SetY1NDC(0.18); stats->SetX2NDC(0.83); stats->SetY2NDC(0.28); 
    } else {
      stats->SetX1NDC(0.60); stats->SetY1NDC(0.68); stats->SetX2NDC(0.83); stats->SetY2NDC(0.88); 
    }
  }

   // Scale
  gStyle->SetPalette(1);
  TPaletteAxis* palette = (TPaletteAxis*)his->GetListOfFunctions()->FindObject("palette");
  if ( palette ) {
    palette->SetY1NDC(0.2);
    palette->SetY2NDC(0.8);
  }

  canvas->Modified();
  canvas->cd();
  canvas->SetSelected(canvas);
  canvas->SaveAs(std::string(canvas_name+".png").c_str());
  //canvas->Write();

}
Beispiel #4
0
//-------------------------------------------------------------------------------------
void MoveStatsAndDraw (TH1 *data, TH1 *mc, char *dataTitle, char* mcTitle, char* firstline, char* secondline, int log, int col, bool stat, TString cut1, TString cut2, bool movepave){
  c->SetLogy(log);
  mc->Draw();
  data->Draw("pesames");   
  gStyle->SetOptStat(00000000); 
  stat=0;  
  if(stat) gStyle->SetOptStat(1111111111); 

  /*  TPaveText *TITLE = new TPaveText(0.2,0.65,0.55,0.9,"blNDC");
  TITLE->SetFillStyle(4000);
  TITLE->SetFillColor(kWhite);
  TITLE->SetBorderSize(0.1);
  TITLE->SetTextFont(42);
  TITLE->AddText(firstline);
  TITLE->Draw();  */

  if(!movepave) {
  TPaveText *title = new TPaveText(0.2,0.7,0.55,0.93,"blNDC");
  } else {
    //  TPaveText *title = new TPaveText(0.6,0.58,0.95,0.83,"blNDC");
  TPaveText *title = new TPaveText(0.6,0.7,0.95,0.93,"blNDC");
  }
  title->SetFillStyle(4000);
  title->SetFillColor(kWhite);
  title->SetBorderSize(0.1);
  title->SetTextFont(42);
  title->AddText(firstline);
  title->AddText(secondline);
  title->AddText(cut1);
  title->AddText(cut2);
  title->Draw();  
  if(!movepave) {
    TLegend *leg = new TLegend(0.65,0.83,1.,0.93);
  } else {
    TLegend *leg = new TLegend(0.65,0.60,1.,0.7);
  }
  leg->SetFillStyle(4000);
  leg->SetFillColor(kWhite);
  leg->SetBorderSize(0.1);
  leg->SetTextFont(42);
  leg->AddEntry(data,dataTitle,"p");
  leg->AddEntry(mc,mcTitle,"f");
  leg->Draw();

  c->Modified();
  c->Update();



  if(stat){
  TPaveStats * ps = (TPaveStats *) mc->GetListOfFunctions()->FindObject("stats"); 
  TPaveStats * ps2 = (TPaveStats *) data->GetListOfFunctions()->FindObject("stats");
  Int_t ci; 
  ci = TColor::GetColor(col);
  if( ps ){ 
    ps->SetTextColor(1); 
    ps->SetLineColor(col);   
  }
  else std::cout << "Null pointer to TPaveStats: " << ps << std::endl; 
  ps->SetY1NDC(0.40);
  ps->SetY2NDC(0.68);
  if( ps2 ) ps2->SetTextColor(ci); else std::cout << "Null pointer to TPaveStats: " << ps2 << std::endl;
  }
}
Beispiel #5
0
void many_plots2(int first = 5808, int last = 11688, int mask = 0x801E)
{
	TH1D *h[12][2];
	int i, j;
	char str[64];
	TCanvas *cv[2];
	TPaveStats *st;
	float y, dy;
	
	gROOT->SetStyle("Plain");
	gStyle->SetOptStat(1000000);
	gStyle->SetOptFit();
	
	TFile *fRoot = new TFile("many_plots.root", "RECREATE");

	HPainter *p = new HPainter(mask, first, last);
	p->SetFile(fRoot);
	if (!p->IsOpen()) {
		printf("Something wrong with data files.\n");
		return;
	}
	
	TCut cVeto("gtFromVeto > 60");
	TCut cIso("(gtFromPrevious > 45 && gtToNext > 80 && EventsBetween == 0) || (gtFromPrevious == gtFromVeto)");
	TCut cX("PositronX[0] < 0 || (PositronX[0] > 2 && PositronX[0] < 94)");
	TCut cY("PositronX[1] < 0 || (PositronX[1] > 2 && PositronX[1] < 94)");
	TCut cZ("PositronX[2] > 3.5 && PositronX[2] < 95.5");
	TCut cXYZ = cX && cY && cZ;
	TCut cR("Distance < 100 && DistanceZ > -40 && DistanceZ < 40");
	TCut cT10("gtDiff > 1");
	TCut cT20("gtDiff > 2");
	TCut cT200("gtDiff < 20");						// strong cut
        TCut cGamma("AnnihilationEnergy < 1.5 && AnnihilationGammas < 9");
        TCut cPe("PositronEnergy > 1");
	TCut cXY("PositronX[0]>=0 && PositronX[1]>=0");
	TCut cN4("NeutronEnergy > 4 && NeutronHits >= 5");

	for (i=0; i<2; i++) {
		sprintf(str, "hR%d", i);
		h[0][i] = new TH1D(str, "Distance between positron and neutron;R, cm;mHz", 40, 0, 160);
		sprintf(str, "hRZ%d", i);
		h[1][i] = new TH1D(str, "Distance between positron and neutron, projection Z;R_{z}, cm;mHz", 100, -100, 100);
		sprintf(str, "hT%d", i);
		h[2][i] = new TH1D(str, "Time between positron and neutron;T, us;mHz", 50, 0, 50);
		sprintf(str, "hX%d", i);
		h[3][i] = new TH1D(str, "Positron vertex X;X, cm;mHz", 25, 0, 100);
		sprintf(str, "hY%d", i);
		h[4][i] = new TH1D(str, "Positron vertex Y;Y, cm;mHz", 25, 0, 100);
		sprintf(str, "hZ%d", i);
		h[5][i] = new TH1D(str, "Positron vertex Z;Z, cm;mHz", 100, 0, 100);
		sprintf(str, "hNE%d", i);
		h[6][i] = new TH1D(str, "Energy detected in neutron capture;E_{n}, MeV;mHz", 50, 0, 10);
		sprintf(str, "hNN%d", i);
		h[7][i] = new TH1D(str, "Number of hits in SiPM for neutron capture;N_{n};mHz", 20, 0, 20);
		sprintf(str, "hGE%d", i);
		h[8][i] = new TH1D(str, "Energy beyond positron cluster;E_{#gamma}, MeV;mHz", 15, 0, 3);
		sprintf(str, "hGN%d", i);
		h[9][i] = new TH1D(str, "Number of SiPM hits out of positron cluster;N_{#gamma};mHz", 10, 0, 10);
		sprintf(str, "hE%d", i);
		h[10][i] = new TH1D(str, "Positorn kinetic energy;E, MeV;mHz", 40, 0, 8);
		sprintf(str, "hEC%d", i);
		h[11][i] = new TH1D(str, "Positorn kinetic energy, strong background cuts;E, MeV;mHz", 40, 0, 8);
	}
	
	printf("Histograms are created\n");
	
	p->Project(h[0][0], "Distance", cVeto && cIso && cT20 && cGamma && cPe && cXYZ);
	p->Project(h[0][1], "Distance", !cVeto && cIso && cT20 && cGamma && cPe && cXYZ);
	printf("Distance.\n");
	p->Project(h[1][0], "DistanceZ", cVeto && cIso && cT20 && cGamma && cPe && cXYZ);
	p->Project(h[1][1], "DistanceZ", !cVeto && cIso && cT20 && cGamma && cPe && cXYZ);
	printf("DistanceZ.\n");
	p->Project(h[2][0], "gtDiff", cVeto && cIso && cT10 && cGamma && cPe && cXYZ && cR);
	p->Project(h[2][1], "gtDiff", !cVeto && cIso && cT10 && cGamma && cPe && cXYZ && cR);
	printf("gtDiff.\n");
	p->Project(h[3][0], "PositronX[0]+2", cVeto && cIso && cT20 && cGamma && cPe && cY && cZ && cR && "PositronX[0] >= 0");
	p->Project(h[3][1], "PositronX[0]+2", !cVeto && cIso && cT20 && cGamma && cPe && cY && cZ && cR && "PositronX[0] >= 0");
	printf("X.\n");
	p->Project(h[4][0], "PositronX[1]+2", cVeto && cIso && cT20 && cGamma && cPe && cX && cZ && cR && "PositronX[1] >= 0");
	p->Project(h[4][1], "PositronX[1]+2", !cVeto && cIso && cT20 && cGamma && cPe && cX && cZ && cR && "PositronX[1] >= 0");
	printf("Y.\n");
	p->Project(h[5][0], "PositronX[2]+0.5", cVeto && cIso && cT20 && cGamma && cPe && cX && cY && cR);
	p->Project(h[5][1], "PositronX[2]+0.5", !cVeto && cIso && cT20 && cGamma && cPe && cX && cY && cR);
	printf("Z.\n");
	p->Project(h[6][0], "NeutronEnergy", cVeto && cIso && cT20 && cGamma && cPe && cY && cZ && cR);
	p->Project(h[6][1], "NeutronEnergy", !cVeto && cIso && cT20 && cGamma && cPe && cY && cZ && cR);
	printf("NE.\n");
	p->Project(h[7][0], "NeutronHits", cVeto && cIso && cT20 && cGamma && cPe && cXYZ && cR);
	p->Project(h[7][1], "NeutronHits", !cVeto && cIso && cT20 && cGamma && cPe && cXYZ && cR);
	printf("NN.\n");
	p->Project(h[8][0], "AnnihilationEnergy", cVeto && cIso && cT20 && cPe && cXYZ && cR);
	p->Project(h[8][1], "AnnihilationEnergy", !cVeto && cIso && cT20 && cPe && cXYZ && cR);
	printf("AE.\n");
	p->Project(h[9][0], "AnnihilationGammas", cVeto && cIso && cT20 && cPe && cXYZ && cR);
	p->Project(h[9][1], "AnnihilationGammas", !cVeto && cIso && cT20 && cPe && cXYZ && cR);
	printf("AG.\n");
	p->Project(h[10][0], "PositronEnergy", cVeto && cIso && cT20 && cGamma && cPe && cXYZ && cR);
	p->Project(h[10][1], "PositronEnergy", !cVeto && cIso && cT20 && cGamma && cPe && cXYZ && cR);
	p->Project(h[11][0], "PositronEnergy", cVeto && cIso && cT20 && cGamma && cPe && cXYZ && cR && cN4 && cT200);
	p->Project(h[11][1], "PositronEnergy", !cVeto && cIso && cT20 && cGamma && cPe && cXYZ && cR && cN4 && cT200);
	
	printf("Projections are done\n");
	
	for (i=0; i<12; i++) {
		for (j=0; j<2; j++) h[i][j]->SetLineWidth(4);
		h[i][0]->SetLineColor(kGreen);
		h[i][1]->SetLineColor(kRed);
		h[i][0]->SetMinimum(0);
		h[i][1]->SetMinimum(0);
	}

//	h[1][0]->Fit("gaus", "0");
//	h[1][1]->Fit("gaus", "0");
	
//	TF1 *fdec = new TF1("FDEC", "[0]*(exp(-x/[1]) - exp(-x/[2]))", 3);
//	fdec->SetParNames("Const", "t_{CAPTURE}", "t_{THERM}");
//	fdec->SetParameters(h[2][0]->Integral()/4, 15, 5);
//	h[2][0]->Fit("FDEC", "0", "", 2, 50);

	for (i=0; i<2; i++) {
		sprintf(str, "CV%d", i);
		cv[i] = new TCanvas(str, "Plots", 1800, 1200);
		cv[i]->Divide(3, 2);
		for (j=0; j<6; j++) {
			cv[i]->cd(j+1);
			h[6*i+j][0]->Draw();
			h[6*i+j][1]->Draw("sames");
			gPad->Update();
			if (i == 0 && j == 1) {
				st = (TPaveStats *) h[6*i+j][0]->FindObject("stats");
				st->SetOptStat(1100);
				st->SetLineColor(kGreen);
				st->SetTextColor(kGreen);
				y = st->GetY1NDC();
				dy = st->GetY2NDC() - y;
				st->SetX1NDC(0.72);
				st = (TPaveStats *) h[6*i+j][1]->FindObject("stats");
				st->SetOptStat(1100);
				st->SetLineColor(kRed);
				st->SetTextColor(kRed);
				st->SetX1NDC(0.72);
				st->SetY2NDC(y);
				st->SetY1NDC(y - dy);
			} else {
				st = (TPaveStats *) h[6*i+j][0]->FindObject("stats");
				st->SetLineColor(kGreen);
				st->SetTextColor(kGreen);
				y = st->GetY1NDC();
				dy = st->GetY2NDC() - y;
				st->SetX1NDC(0.72);
				st->SetY1NDC(y + dy/2);
				st = (TPaveStats *) h[6*i+j][1]->FindObject("stats");
				st->SetLineColor(kRed);
				st->SetTextColor(kRed);
				st->SetX1NDC(0.72);
				st->SetY2NDC(y + dy/2);
			}
			if (h[6*i+j][0]->GetMaximum() > h[6*i+j][1]->GetMaximum()) {
				h[6*i+j][0]->Draw();
				h[6*i+j][1]->Draw("sames");
			} else {
				h[6*i+j][1]->Draw();
				h[6*i+j][0]->Draw("sames");
			}
			gPad->Update();
		}
		cv[i]->Update();
	}

	fRoot->cd();
	for (i=0; i<12; i++) for (j=0; j<2; j++) h[i][j]->Write();
	fRoot->Close();
}