void hist_to_png_h1(TH1F * h_c, TH1F* h_e, TH1F* h_f, TString saveTitle, TString type_string)
{
  TCanvas *cPNG = new TCanvas(saveTitle,"",700,500);
  TImage *img = TImage::Create();
  char * type = type_string.Data();
  gStyle->SetOptStat(0);
  gPad->SetLogy();
  auto legend = new TLegend(0.7,0.7,0.9,0.9);
  legend->SetTextSize(0.06);
  legend->AddEntry(h_c,"CEMC","l");
  legend->AddEntry(h_e,"EEMC","l");
  legend->AddEntry(h_f,"FEMC","l");
  
  if(strcmp(type,"spatial")==0)
    {  
      h_e->GetXaxis()->SetTitle("Extrapolation distance from cluster [cm]");
      h_e->GetYaxis()->SetTitle("Counts");
    }
  h_e->Draw();
  h_c->Draw("SAME");
  h_f->Draw("SAME");
  legend->Draw();
  img->FromPad(cPNG);
  img->WriteImage(saveTitle);
}
示例#2
0
void SaveOpenSpectras() {
	char *spectra_names[] =
		{"CB-Spectra",
		 "TAPS-BaF2-Spectra",
		 "TAPS-PbWO4-Spectra",
		 "TAPS-Veto-Spectra",
		 "Tagger-Spectra",
		 "EPT-Spectra",
		 "PID-Spectra",
		 "MWPC-Spectra",
		 "Scaler-Spectra", // aka trigger spectra...
		 "Livetimes-Spectra",
		 "Physics-Spectra",
		 0};

	// clean up directory...
	printf("\nDelete all PNG images on daq-master:/home/a2cb/OnlineSpectra\n");
	stringstream CmdStr;
	CmdStr << "rm /home/a2cb/acqu/OnlineSpectra/*.png";
	system(CmdStr.str().c_str());

	// prepare elog command, note the blank space at every line!
	stringstream elog_cmd;
	elog_cmd << "echo Run " << gAR->GetRunNumber() << " Online Spectra | ";
	elog_cmd << "elog -h elog.office.a2.kph -u a2online a2messung ";
	elog_cmd << "-l 'Main Group Logbook' -a Experiment='EPT test 2014-07' ";
	elog_cmd << "-a Author='PLEASE FILL IN' -a Type=Routine ";
	elog_cmd << "-a Subject='Online Spectra Run " << gAR->GetRunNumber() << "' ";
	
	// Save Spectra
	UInt_t i = 0;
	char spectra_title[50];
	char spectra_filename[100];
	
	while (spectra_names[i]){
		sprintf(spectra_title, "%s", spectra_names[i]);
		sprintf(spectra_filename, "/home/a2cb/acqu/OnlineSpectra/%02i_%s.png", i, spectra_names[i]);
		gSystem->ProcessEvents();

		if (gROOT->FindObject(spectra_title)) {

			TImage *img = TImage::Create();
			img->FromPad((TVirtualPad*)gROOT->FindObject(spectra_title));
			img->WriteImage(spectra_filename);
			delete img;
			elog_cmd << "-f " << spectra_filename << " ";
			printf("Spectra saved: %s\n", spectra_title);
		} else {
			printf("Spectra not found: %s\n", spectra_title);
		}
		i++;
	}


	printf("\nPosting all PNG images to the Elog\n");
	system(elog_cmd.str().c_str());
	printf("\nPLEASE EDIT THE ELOG ENTRY TO MAKE IT COMPLETE!\n\n");
}
示例#3
0
/**
 * \brief saves the plotted image
 * Saves the plotter image to the given filename
 * \param std::string filename - output filename for the image also determines the image type ( ".png" -> png etc.)
 * \return bool on success
 */
bool Plotter::save_image(std::string filename){
  try{
    TImage *img = TImage::Create();
    img->FromPad(canvas);
    img->WriteImage(filename.c_str());
    return true;
  }catch(std::runtime_error &e){
    std::cerr << e.what() << std::endl;
    return false;
  }
}
示例#4
0
文件: pad2png.C 项目: MycrofD/root
void pad2png()
{
   TCanvas *c = new TCanvas;
   TH1F *h = new TH1F("gaus", "gaus", 100, -5, 5);
   h->FillRandom("gaus", 10000);
   h->Draw();

   gSystem->ProcessEvents();

   TImage *img = TImage::Create();

   img->FromPad(c);

   img->WriteImage("canvas.png");
}
void hist_to_png(TH2F * h, TString saveTitle, TString type_string)
{
  TCanvas *cPNG = new TCanvas(saveTitle,"",700,500);
  TImage *img = TImage::Create();
  char * type = type_string.Data();
  gPad->SetLogz();
  gStyle->SetOptStat(0);
  if(strcmp(type,"phi")==0)
    {
      h->GetXaxis()->SetTitle("Track Phi");
      h->GetYaxis()->SetTitle("Cluster Phi");
    }
  else if(strcmp(type,"eta")==0)
    {
      h->GetXaxis()->SetTitle("Track Eta");
      h->GetYaxis()->SetTitle("Cluster Eta"); 
    }
  else if(strcmp(type,"theta")==0)
    {
      h->GetXaxis()->SetTitle("Track Theta");
      h->GetYaxis()->SetTitle("Cluster Theta");
    }
  else if(strcmp(type,"mom")==0)
    {
      h->GetXaxis()->SetTitle("Track Momentum [GeV]");
      h->GetYaxis()->SetTitle("Cluster Momentum [GeV]");
    }
  else if(strcmp(type,"posx")==0)
    {
      h->GetXaxis()->SetTitle("Track Position X [cm]");
      h->GetYaxis()->SetTitle("Cluster Position X [cm]");
    }
  else if(strcmp(type,"posy")==0)
    {
      h->GetXaxis()->SetTitle("Track Position Y [cm]");
      h->GetYaxis()->SetTitle("Cluster Position Y [cm]");
    }
  else if(strcmp(type,"posz")==0)
    {  
      h->GetXaxis()->SetTitle("Track Position Z [cm]");
      h->GetYaxis()->SetTitle("Cluster Position Z [cm]");
    }
  h->Draw("colz9");
  img->FromPad(cPNG);
  img->WriteImage(saveTitle);

  delete img;
}
示例#6
0
void pad2png()
{
   // Create a canvas and save as png.
   //Author: Valeriy Onuchin

   TCanvas *c = new TCanvas;
   TH1F *h = new TH1F("gaus", "gaus", 100, -5, 5);
   h->FillRandom("gaus", 10000);
   h->Draw();

   gSystem->ProcessEvents();

   TImage *img = TImage::Create();

   //img->FromPad(c, 10, 10, 300, 200);
   img->FromPad(c);

   img->WriteImage("canvas.png");

   delete h;
   delete c;
   delete img;
}
示例#7
0
// Example displaying two histograms and their ratio.
// Author: Olivier Couet
void ratioplot2 () {
   // Define two gaussian histograms. Note the X and Y title are defined
   // at booking time using the convention "Hist_title ; X_title ; Y_title"
   /*
    *TH1F *h1 = new TH1F("h1", "Two gaussian plots and their ratio;x title; h1 and h2 gaussian histograms", 100, -5, 5);
    *TH1F *h2 = new TH1F("h2", "h2", 100, -5, 5);
    *h1->FillRandom("gaus");
    *h2->FillRandom("gaus");
	*/
	vector<TString> Cut;
	Cut.push_back("isGLB");
	Cut.push_back("isPF");
	Cut.push_back("chi2dof");
	Cut.push_back("muonHits");
	Cut.push_back("nMatches");
	Cut.push_back("dxyVTX");
	Cut.push_back("dzVTX");
	Cut.push_back("pixelHits");
	Cut.push_back("trackerLayers");
	Cut.push_back("trkiso");

	vector<TString> Type;
	Type.push_back("Pt_");
	Type.push_back("eta");
	Type.push_back("mass");

	
	

	//Double_t Factor = 569.0171*2008.4*3/4.5275/10; // Wrong value;
	Double_t Factor = ((569.0171*2008.4)*3)/(4.5275*(1e11));

	TFile *f1;
	TH1D *h1, *h2;
	TH1F *h3;
	//TCanvas *c;
	TCanvas *c = new TCanvas("c", "canvas", 800,800);
	TPad *pad1 = new TPad("pad1", "pad1", 0, 0.3, 1, 1.0);
	TPad *pad2 = new TPad("pad2", "pad2", 0, 0.05, 1, 0.3);
	TImage *img = TImage::Create();
	
	Int_t i = 0;
	Int_t j = 1;
	for (Int_t i = 0; i < 10; i++)
	{	
		f1 = new TFile ("MuonTight_"+Cut[i]+".root");

		for (Int_t j = 0; j < 3; j++)
		{

			c = new TCanvas("c", "canvas", 800, 800);
			cout << Type[j] << " drawing.." <<  endl;

			h1 = (TH1D *)f1->Get("h_"+Type[j]+"_Data");
			h2 = (TH1D *)f1->Get("h_"+Type[j]+"_DYMuMu");
			h2->Scale(Factor);

			cout << Type[j] << " h1, h2 constructed" << endl;

			//h1->
			// Define the Canvas
			//TCanvas *c = new TCanvas("c", "canvas", 800, 800);

			// Upper plot will be in pad1
			pad1 = new TPad("pad1", "pad1", 0, 0.3, 1, 1.0);
			pad1->SetBottomMargin(0); // Upper and lower plot are joined
			pad1->SetGridx();         // Vertical grid
			pad1->Draw();             // Draw the upper pad: pad1
			pad1->cd();               // pad1 becomes the current pad
			//h1->SetStats(0);          // No statistics on upper plot

			cout << "h1, h2 before draw" << endl;
			h2->Draw();               // Draw h1
			h1->Draw("same");         // Draw h2 on top of h1
			
			cout << "h1, h2 draw.." << endl;
			// Do not draw the Y axis label on the upper plot and redraw a small
			// axis instead, in order to avoid the first label (0) to be clipped.
			//h1->GetYaxis()->SetLabelSize(0.);
			//TGaxis *axis = new TGaxis( -5, 20, -5, 220, 20,220,510,"");
			//TGaxis *axis = (TGaxis *)h1->GetGaxis();
			//axis->SetLabelFont(43); // Absolute font size in pixel (precision 3)
			//axis->SetLabelSize(15);
			//axis->Draw();

			// lower plot will be in pad
			c->cd();          // Go back to the main canvas before defining pad2
			pad2 = new TPad("pad2", "pad2", 0, 0.05, 1, 0.3);
			pad2->SetTopMargin(0.01);
			pad2->SetBottomMargin(0.2);
			pad2->SetGridx(); // vertical grid
			pad2->Draw();
			pad2->cd();       // pad2 becomes the current pad

			// Define the ratio plot
			h3 = (TH1F*)h1->Clone("h3");
			h3->SetLineColor(kBlack);
			h3->SetMinimum(0);  // Define Y ..
			h3->SetMaximum(2); // .. range
			h3->Sumw2();
			h3->SetStats(0);      // No statistics on lower plot
			h3->Divide(h2);
			h3->SetMarkerStyle(21);
			h3->Draw("ep");       // Draw the ratio plot

			// h1 settings
			h1->SetLineColor(kBlue+1);
			h1->SetLineWidth(2);

			// Y axis h1 plot settings
			h1->GetYaxis()->SetTitleSize(20);
			h1->GetYaxis()->SetTitleFont(43);
			h1->GetYaxis()->SetTitleOffset(1.55);

			// h2 settings
			h2->SetLineColor(kRed);
			h2->SetLineWidth(2);

			// Ratio plot (h3) settings
			h3->SetTitle(""); // Remove the ratio title

			// Y axis ratio plot settings
			//h3->GetYaxis()->SetTitle("ratio h1/h2 ");
			h3->GetYaxis()->SetNdivisions(505);
			h3->GetYaxis()->SetTitleSize(20);
			h3->GetYaxis()->SetTitleFont(43);
			h3->GetYaxis()->SetTitleOffset(1.55);
			h3->GetYaxis()->SetLabelFont(43); // Absolute font size in pixel (precision 3)
			h3->GetYaxis()->SetLabelSize(15);

			// X axis ratio plot settings
			h3->GetXaxis()->SetTitleSize(20);
			h3->GetXaxis()->SetTitleFont(43);
			h3->GetXaxis()->SetTitleOffset(4.);
			h3->GetXaxis()->SetLabelFont(43); // Absolute font size in pixel (precision 3)
			h3->GetXaxis()->SetLabelSize(15);

			//TImage *img = TImage::Create();

			img->FromPad(c);
			img->WriteImage(Type[j]+"_Tightminus_"+Cut[i]+".png");

			cout << Type[j] << "_Tightminus_" << Cut[i] << ".png output" << endl;
			//delete h3;
			//delete h2;
			//delete h1;
			//delete pad1;
			//delete pad2;
			delete c;


			//delete f1;

			cout << "file closed" << endl;
		} // iteration Type end
	} // iteration Cut end
}
void multiDrawComp2(const char *file1, const char *dataset1, const char *file2, const char* dataset2,
		    const char *profname1, const char *id1, const char *profname2, const char *id2, const char *histtitle, const char *xtitle,  const char *ytitle, const char *outfile,
		    const char *file3 = "none", const char *dataset3 = "none", const char *file4 ="none", const char *dataset4 = "none", const char *profNum = "double"){

  bool single = false;

   Int_t ci;      // for color index setting
   TColor *color; // for color definition with alpha

   Int_t prof1_1 = 1;
   Int_t prof2_1 = 12;

   //Int_t prof1_1 = 214;
   //Int_t prof2_1 = 216;

   Int_t prof1_2 = 2;
   Int_t prof2_2 = 208;

   Int_t prof1_3 = 3;
   Int_t prof2_3 = 84;

   //Int_t prof1_3 = 210;
   //Int_t prof2_3 = 212;

   Int_t prof1_4 = 222;
   Int_t prof2_4 = 224;

   Int_t marker1 = 20;
   Int_t marker2 = 25;
   Int_t marker3 = 26;
   Int_t marker4 = 28;

   /*
   Int_t line1 = 1;
   Int_t fill1 = 18;

   Int_t line2 = 2;
   Int_t fill2 = 0;

   Int_t line3 = 4;
   Int_t fill3 = 0;

   Int_t line4 = 32;
   Int_t fill4 = 0;
   */


   int filenum = 2;
   if(strcmp(file3,"none")&&strcmp(dataset3,"none")){
     filenum = 3;
   }

   if(strcmp(file4,"none")&&strcmp(dataset4,"none")){
     filenum = 4;
   }

   if(!strcmp(profNum,"single")) single = true;

   cout << "Files: " << filenum << endl;

  TCanvas *c = new TCanvas();
  c->SetGridx();
  c->SetGridy();
  gStyle->SetOptStat(0);

  TFile *f1 = new TFile(file1);
  if(f1->IsZombie()){
    cout << "Root file: " << file1 << " not found!" << endl;
    return;
  }

  TFile *f2 = new TFile(file2);
  if(f2->IsZombie()){
    cout << "Root file: " << file2 << " not found!" << endl;
    return;
  }

  f1->cd("");

  TProfile *p1_1 = (TProfile*)f1->Get(profname1);
  if(!p1_1){
    cout << "Failed to load " << profname1 << " from " << file1 << "!";
    return;
  }
  TProfile *p2_1;
  if(!single) p2_1 = (TProfile*)f1->Get(profname2);

  f2->cd("");

  TProfile *p1_2 = (TProfile*)f2->Get(profname1);
  TProfile *p2_2;
  if(!single) p2_2 = (TProfile*)f2->Get(profname2);

  TProfile *p1_3;
  TProfile *p2_3;

  TProfile *p1_4;
  TProfile *p2_4;

  TFile *f3;
  TFile *f4;

  cout << "Try to open additional files. filenum = " << filenum << endl;

  if(filenum >= 3){
    cout << "Trying to open: " << file3 << endl;
    f3 = new TFile(file3);
    cout << "Created new TFile object" << endl;
    if(f3->IsZombie()){
      cout << "Root file: " << file3 << " not found!" << endl;
      return;
    }
    cout << "Successfully opened " << file3 << endl;
    f3->cd();
    p1_3 = (TProfile*)f3->Get(profname1);
    if(p1_3) cout << "Pointer to p1_3 object" << endl;
    if(!single) p2_3 = (TProfile*)f3->Get(profname2);
    if(p2_3) cout << "Pointer to p2_3 object" << endl;
  }

  cout << "Checking parameters for 4th dataset." << endl;

 if(filenum >= 4){
   cout << "Attempting to open fourth file: " << file4 << endl;
   
    f4 = new TFile(file4);
    if(f4->IsZombie()){
      cout << "Root file: " << file4 << " not found!" << endl;
      return;
    }
    f4->cd();
    p1_4 = (TProfile*)f4->Get(profname1);
    if(!single) p2_4 = (TProfile*)f4->Get(profname2);
 }

 cout << "Done opening root files" << endl;

 cout << "Loading starting bins" << endl;

 cout << "Loading p1_1 named: " << profname1 << endl;
 int start1_1 = p1_1->FindFirstBinAbove(0.00005);
 int start2_1;
 if(!single){
   start2_1 = p2_1->FindFirstBinAbove(0.00005);
   cout << "Loading p2_1" << endl;
 }
 cout << "Loading p1_2" << endl;
 int start1_2 = p1_2->FindFirstBinAbove(0.00005);
 int start2_2;
 if(!single){
   start2_2 = p2_2->FindFirstBinAbove(0.00005);
   cout << "Loading p2_2" << endl;
 }
 int start1_3;
 int start2_3;
 int start1_4;
 int start2_4;

 int startplot;

 cout << "Done loading starting bins for datasets 1&2" << endl;

 startplot = (start1_1 < start1_2 ? start1_1 : start1_2);
 if(!single){
   startplot = (startplot < start2_1 ? startplot : start2_1);
   startplot = (startplot < start2_2 ? startplot : start2_2);
 }

 if(!single) startplot = (startplot < start2_2 ? startplot : start2_2);

 if(filenum >= 3){
   cout << "Looking for lower bin in 3rd datset" << endl;
   start1_3 = p1_3->FindFirstBinAbove(0.00005);
   cout << "Loaded first bin from first profile." << endl;
   if(!single) start2_3 = p2_3->FindFirstBinAbove(0.00005);
   cout << "Loaded first bin from second profile." << endl;
   startplot = (startplot < start1_3 ? startplot : start1_3);
   if(!single) startplot = (startplot < start2_3 ? startplot : start2_3);
 }

 if(filenum >= 4){
   cout << "Looking for lower bin in 4th dataset" << endl;
   start1_4 = p1_4->FindFirstBinAbove(0.00005);
   if(!single) start2_4 = p2_4->FindFirstBinAbove(0.00005);
   startplot = (startplot < start1_4 ? startplot : start1_4);
   if(!single) startplot = (startplot < start2_4 ? startplot : start2_4);
 }

 cout << "Begining search for upper bin" << endl;

 int end1_1 = p1_1->FindLastBinAbove(0.00005);
 int end1_2 = p1_2->FindLastBinAbove(0.00005);
 int end1_3;
 int end1_4;
 int end2_1;
 int end2_2;
 if(!single) end2_1 = p2_1->FindLastBinAbove(0.00005);
 if(!single) end2_2 = p2_2->FindLastBinAbove(0.00005);
 int end2_3;
 int end2_4;

 int endplot;

 cout << "Done loading ending bins for datasets 1&2" << endl;

 endplot = (end1_1 > end1_2 ? end1_1 : end1_2);
 if(!single){
   endplot = (endplot > end2_1 ? endplot : end2_1);
   endplot = (endplot > end2_2 ? endplot : end2_2);
 }

 cout << "Upper bin search complete for first two datasets." << endl;

 if(filenum >= 3){
   cout << "Looking for upper bin in 3rd dataset" << endl;
   end1_3 = p1_3->FindLastBinAbove(0.00005);
   if(!single) end2_3 = p2_3->FindLastBinAbove(0.00005);
   endplot = (endplot > end1_3 ? endplot : end1_3);
   if(!single) endplot = (endplot > end2_3 ? endplot : end2_3);
 }

 if(filenum >= 4){
   end1_4 = p1_4->FindLastBinAbove(0.00005);
   if(!single) end2_4 = p2_4->FindLastBinAbove(0.00005);
   endplot = (endplot > end1_4 ? endplot : end1_4);
   if(!single) endplot = (endplot > end2_4 ? endplot : end2_4);
 }

 int plotspace = (endplot - startplot) / 10;

 cout << "Start Bin: " << startplot << " End Bin : " << endplot << endl;

 startplot = (startplot - plotspace > 0 ? startplot - plotspace : 1);
 endplot = endplot + plotspace;

 cout << "Start Bin: " << startplot << " End Bin : " << endplot << endl;

 

  float yrange;

  if(!single) {
    yrange = (p1_1->GetBinContent(p1_1->GetMaximumBin()) > p2_1->GetBinContent(p2_1->GetMaximumBin()) ? p1_1->GetBinContent(p1_1->GetMaximumBin()) : p2_1->GetBinContent(p2_1->GetMaximumBin()));
  }else{
    yrange = (p1_1->GetBinContent(p1_1->GetMaximumBin()) > p1_2->GetBinContent(p1_2->GetMaximumBin()) ? p1_1->GetBinContent(p1_1->GetMaximumBin()) : p1_2->GetBinContent(p1_2->GetMaximumBin()));
  }
  yrange = (yrange > p1_2->GetBinContent(p1_2->GetMaximumBin()) ? yrange : p1_2->GetBinContent(p1_2->GetMaximumBin()));
  if(!single) yrange = (yrange > p2_2->GetBinContent(p2_2->GetMaximumBin()) ? yrange : p2_2->GetBinContent(p2_2->GetMaximumBin()));

  if(filenum >= 3){
    yrange = (yrange > p1_3->GetBinContent(p1_3->GetMaximumBin()) ? yrange : p1_3->GetBinContent(p1_3->GetMaximumBin()));
    if(!single) yrange = (yrange > p2_3->GetBinContent(p2_3->GetMaximumBin()) ? yrange : p2_3->GetBinContent(p2_3->GetMaximumBin()));
  }

  if(filenum >= 4){
    yrange = (yrange > p1_4->GetBinContent(p1_4->GetMaximumBin()) ? yrange : p1_4->GetBinContent(p1_4->GetMaximumBin()));
    if(!single) yrange = (yrange > p2_4->GetBinContent(p2_4->GetMaximumBin()) ? yrange : p2_4->GetBinContent(p2_4->GetMaximumBin()));
  }

  //Start Drawing
  char profname[30] = {0};
  strcat(profname, dataset1);
  strcat(profname, " ");
  strcat(profname, id1);

  p1_1->SetName(profname);
  p1_1->SetTitle(histtitle);
  p1_1->SetMaximum(yrange*1.3);

  p1_1->SetLineColor(prof1_1);
  p1_1->SetMarkerColor(prof1_1);
  p1_1->SetMarkerStyle(marker1);

  p1_1->GetXaxis()->SetTitle(xtitle);
  p1_1->GetXaxis()->SetLabelFont(42);
  p1_1->GetXaxis()->SetLabelSize(0.035);
  p1_1->GetXaxis()->SetTitleSize(0.045);
  p1_1->GetXaxis()->SetTitleFont(42);
  p1_1->GetYaxis()->SetTitle(ytitle);
  p1_1->GetYaxis()->SetLabelFont(42);
  p1_1->GetYaxis()->SetLabelSize(0.035);
  p1_1->GetYaxis()->SetTitleSize(0.045);
  p1_1->GetYaxis()->SetTitleFont(42);
  p1_1->GetXaxis()->SetRange(startplot,endplot);
  p1_1->GetZaxis()->SetLabelFont(42);
  p1_1->GetZaxis()->SetLabelSize(0.035);
  p1_1->GetZaxis()->SetTitleSize(0.035);
  p1_1->GetZaxis()->SetTitleFont(42);
  p1_1->Draw("hist p");  

  gPad->Update();

  if(!single){ 
  profname[0] = '\0';
  strcat(profname, dataset1);
  strcat(profname, " ");
  strcat(profname, id2);

  p2_1->SetName(profname);
  p2_1->SetTitle(histtitle);
  p2_1->SetMaximum(yrange*1.3);

  p2_1->SetLineColor(prof2_1);
  p2_1->SetMarkerColor(prof2_1);
  p2_1->SetMarkerStyle(marker1);
  p2_1->SetMarkerSize(.7);

  p2_1->GetXaxis()->SetTitle(xtitle);
  p2_1->GetXaxis()->SetLabelFont(42);
  p2_1->GetXaxis()->SetLabelSize(0.035);
  p2_1->GetXaxis()->SetTitleSize(0.045);
  p2_1->GetXaxis()->SetTitleFont(42);
  p2_1->GetYaxis()->SetTitle(ytitle);
  p2_1->GetYaxis()->SetLabelFont(42);
  p2_1->GetYaxis()->SetLabelSize(0.035);
  p2_1->GetYaxis()->SetTitleSize(0.045);
  p2_1->GetYaxis()->SetTitleFont(42);
  p2_1->GetXaxis()->SetRange(startplot,endplot);
  p2_1->GetZaxis()->SetLabelFont(42);
  p2_1->GetZaxis()->SetLabelSize(0.035);
  p2_1->GetZaxis()->SetTitleSize(0.035);
  p2_1->GetZaxis()->SetTitleFont(42);
  p2_1->Draw("hist p sames");  

  gPad->Update();
  } //Second profile

  //Now draw the second dataset

  profname[0] = '\0';
  strcat(profname, dataset2);
  strcat(profname, " ");
  strcat(profname, id1);

  p1_2->SetName(profname);
  p1_2->SetTitle(histtitle);
  p1_2->SetMaximum(yrange*1.3);

  p1_2->SetLineColor(prof1_2);
  p1_2->SetMarkerColor(prof1_2);
  p1_2->SetMarkerStyle(marker2);

  p1_2->GetXaxis()->SetTitle(xtitle);
  p1_2->GetXaxis()->SetLabelFont(42);
  p1_2->GetXaxis()->SetLabelSize(0.035);
  p1_2->GetXaxis()->SetTitleSize(0.045);
  p1_2->GetXaxis()->SetTitleFont(42);
  p1_2->GetYaxis()->SetTitle(ytitle);
  p1_2->GetYaxis()->SetLabelFont(42);
  p1_2->GetYaxis()->SetLabelSize(0.035);
  p1_2->GetYaxis()->SetTitleSize(0.045);
  p1_2->GetYaxis()->SetTitleFont(42);
  p1_2->GetXaxis()->SetRange(startplot,endplot);
  p1_2->GetZaxis()->SetLabelFont(42);
  p1_2->GetZaxis()->SetLabelSize(0.035);
  p1_2->GetZaxis()->SetTitleSize(0.035);
  p1_2->GetZaxis()->SetTitleFont(42);
  p1_2->Draw("hist p sames");  

  gPad->Update();

  if(!single){
  profname[0] = '\0';
  strcat(profname, dataset2);
  strcat(profname, " ");
  strcat(profname, id2);

  p2_2->SetName(profname);
  p2_2->SetTitle(histtitle);
  p2_2->SetMaximum(yrange*1.3);

  p2_2->SetLineColor(prof2_2);
  p2_2->SetMarkerColor(prof2_2);
  p2_2->SetMarkerStyle(marker2);
  p2_2->SetMarkerSize(.7);

  p2_2->GetXaxis()->SetTitle(xtitle);
  p2_2->GetXaxis()->SetLabelFont(42);
  p2_2->GetXaxis()->SetLabelSize(0.035);
  p2_2->GetXaxis()->SetTitleSize(0.045);
  p2_2->GetXaxis()->SetTitleFont(42);
  p2_2->GetYaxis()->SetTitle(ytitle);
  p2_2->GetYaxis()->SetLabelFont(42);
  p2_2->GetYaxis()->SetLabelSize(0.035);
  p2_2->GetYaxis()->SetTitleSize(0.045);
  p2_2->GetYaxis()->SetTitleFont(42);
  p2_2->GetXaxis()->SetRange(startplot,endplot);
  p2_2->GetZaxis()->SetLabelFont(42);
  p2_2->GetZaxis()->SetLabelSize(0.035);
  p2_2->GetZaxis()->SetTitleSize(0.035);
  p2_2->GetZaxis()->SetTitleFont(42);
  p2_2->Draw("hist p sames");  

  gPad->Update();
  } //Second profile


  //Now we draw the third dataset
  if(filenum >= 3){
    profname[0] = '\0';
    strcat(profname, dataset3);
    strcat(profname, " ");
    strcat(profname, id1);

    p1_3->SetName(profname);
    p1_3->SetTitle(histtitle);
    p1_3->SetMaximum(yrange*1.3);

    p1_3->SetLineColor(prof1_3);
    p1_3->SetMarkerColor(prof1_3);
    p1_3->SetMarkerStyle(marker3);

    p1_3->GetXaxis()->SetTitle(xtitle);
    p1_3->GetXaxis()->SetLabelFont(42);
    p1_3->GetXaxis()->SetLabelSize(0.035);
    p1_3->GetXaxis()->SetTitleSize(0.045);
    p1_3->GetXaxis()->SetTitleFont(42);
    p1_3->GetYaxis()->SetTitle(ytitle);
    p1_3->GetYaxis()->SetLabelFont(42);
    p1_3->GetYaxis()->SetLabelSize(0.035);
    p1_3->GetYaxis()->SetTitleSize(0.045);
    p1_3->GetYaxis()->SetTitleFont(42);
    p1_3->GetXaxis()->SetRange(startplot,endplot);
    p1_3->GetZaxis()->SetLabelFont(42);
    p1_3->GetZaxis()->SetLabelSize(0.035);
    p1_3->GetZaxis()->SetTitleSize(0.035);
    p1_3->GetZaxis()->SetTitleFont(42);
    p1_3->Draw("hist p sames");  

    gPad->Update();
    
    if(!single){ 
    profname[0] = '\0';
    strcat(profname, dataset3);
    strcat(profname, " ");
    strcat(profname, id2);

    p2_3->SetName(profname);
    p2_3->SetTitle(histtitle);
    p2_3->SetMaximum(yrange*1.3);
    
    p2_3->SetLineColor(prof2_3);
    p2_3->SetMarkerColor(prof2_3);
    p2_3->SetMarkerStyle(marker3);
    p2_3->SetMarkerSize(.7);
    
    p2_3->GetXaxis()->SetTitle(xtitle);
    p2_3->GetXaxis()->SetLabelFont(42);
    p2_3->GetXaxis()->SetLabelSize(0.035);
    p2_3->GetXaxis()->SetTitleSize(0.045);
    p2_3->GetXaxis()->SetTitleFont(42);
    p2_3->GetYaxis()->SetTitle(ytitle);
    p2_3->GetYaxis()->SetLabelFont(42);
    p2_3->GetYaxis()->SetLabelSize(0.035);
    p2_3->GetYaxis()->SetTitleSize(0.045);
    p2_3->GetYaxis()->SetTitleFont(42);
    p2_3->GetXaxis()->SetRange(startplot,endplot);
    p2_3->GetZaxis()->SetLabelFont(42);
    p2_3->GetZaxis()->SetLabelSize(0.035);
    p2_3->GetZaxis()->SetTitleSize(0.035);
    p2_3->GetZaxis()->SetTitleFont(42);
    p2_3->Draw("hist p sames");  

    gPad->Update();
    }//Second Profile
  }

  //Now we draw the fourth dataset
  if(filenum >= 4){
    profname[0] = '\0';
    strcat(profname, dataset4);
    strcat(profname, " ");
    strcat(profname, id1);

    p1_4->SetName(profname);
    p1_4->SetTitle(histtitle);
    p1_4->SetMaximum(yrange*1.3);

    p1_4->SetLineColor(prof1_4);
    p1_4->SetMarkerColor(prof1_4);
    p1_4->SetMarkerStyle(marker4);

    p1_4->GetXaxis()->SetTitle(xtitle);
    p1_4->GetXaxis()->SetLabelFont(42);
    p1_4->GetXaxis()->SetLabelSize(0.035);
    p1_4->GetXaxis()->SetTitleSize(0.045);
    p1_4->GetXaxis()->SetTitleFont(42);
    p1_4->GetYaxis()->SetTitle(ytitle);
    p1_4->GetYaxis()->SetLabelFont(42);
    p1_4->GetYaxis()->SetLabelSize(0.035);
    p1_4->GetYaxis()->SetTitleSize(0.045);
    p1_4->GetYaxis()->SetTitleFont(42);
    p1_4->GetXaxis()->SetRange(startplot,endplot);
    p1_4->GetZaxis()->SetLabelFont(42);
    p1_4->GetZaxis()->SetLabelSize(0.035);
    p1_4->GetZaxis()->SetTitleSize(0.035);
    p1_4->GetZaxis()->SetTitleFont(42);
    p1_4->Draw("hist p sames");  

    gPad->Update();
    
    if(!single) {
    profname[0] = '\0';
    strcat(profname, dataset4);
    strcat(profname, " ");
    strcat(profname, id2);

    p2_4->SetName(profname);
    p2_4->SetTitle(histtitle);
    p2_4->SetMaximum(yrange*1.3);
    
    p2_4->SetLineColor(prof2_4);
    p2_4->SetMarkerColor(prof2_4);
    p2_4->SetMarkerStyle(marker4);
    p2_4->SetMarkerSize(.7);
    
    p2_4->GetXaxis()->SetTitle(xtitle);
    p2_4->GetXaxis()->SetLabelFont(42);
    p2_4->GetXaxis()->SetLabelSize(0.035);
    p2_4->GetXaxis()->SetTitleSize(0.045);
    p2_4->GetXaxis()->SetTitleFont(42);
    p2_4->GetYaxis()->SetTitle(ytitle);
    p2_4->GetYaxis()->SetLabelFont(42);
    p2_4->GetYaxis()->SetLabelSize(0.035);
    p2_4->GetYaxis()->SetTitleSize(0.045);
    p2_4->GetYaxis()->SetTitleFont(42);
    p2_4->GetXaxis()->SetRange(startplot,endplot);
    p2_4->GetZaxis()->SetLabelFont(42);
    p2_4->GetZaxis()->SetLabelSize(0.035);
    p2_4->GetZaxis()->SetTitleSize(0.035);
    p2_4->GetZaxis()->SetTitleFont(42);
    p2_4->Draw("hist p sames");  

    gPad->Update();
    }//Second Profile
  }

 
  TLegend *leg = new TLegend(0.5043103,0.6666667,0.8821839,0.8776371,NULL,"brNDC");
  leg->SetBorderSize(1);
  leg->SetLineColor(1);
  leg->SetLineStyle(1);
  leg->SetLineWidth(1);
  leg->SetFillColor(0);
  leg->SetFillStyle(1001);
  leg->AddEntry(p1_1,p1_1->GetName(),"lp");
  if(!single) leg->AddEntry(p2_1,p2_1->GetName(),"lp");
  leg->AddEntry(p1_2,p1_2->GetName(),"lp");
  if(!single) leg->AddEntry(p2_2,p2_2->GetName(),"lp");

  if(filenum >= 3){
    leg->AddEntry(p1_3,p1_3->GetName(),"lp");
    if(!single) leg->AddEntry(p2_3,p2_3->GetName(),"lp");
  }

  if(filenum >= 4){
    leg->AddEntry(p1_4,p1_4->GetName(),"lp");
    if(!single) leg->AddEntry(p2_4,p2_4->GetName(),"lp");
  }
  
  leg->Draw();
  
  c->Modified();
  c->cd();
  c->SetSelected(c);
  
  TImage *img = TImage::Create();
  
  img->FromPad(c);
  img->WriteImage(outfile);
  

}
示例#9
0
文件: hw1.C 项目: DingXuefeng/hw1
int hw1(){
  //define landau formula
  TF1* myf = new TF1("mylandau",landauf,-3,10,3);
  myf->SetParameters(1.0,2,1);

  //get ready to initial hist
  /*
  const int num = 3;
  string histvName[num] = {"ld_1e2","ld_1e3","ld_1e4"};
  string histvTitle[num] = {"Landau 100 entris","Landau 1000 entris","Landau 10000 entris"};
  int histEntries[num] = {100,1000,10000};

  //new hist and fill them
  TCanvas* canvas = new TCanvas("myc","HW1",800,600);
  TMultiGraph* mg = new TMultiGraph();
  for(int i = 0;i<num;i++){
    TH1F* tmp=new TH1F(histvName[i].c_str(),histvTitle[i].c_str(),100,-3,10);
    tmp->FillRandom("mylandau",histEntries[i]);
  }

  gDirectory->Get(histvName[2])->Draw("e");
  gDirectory->Get(histvName[1])->Draw("esame");
  gDirectory->Get(histvName[0])->Draw("esame");
  */
  TCanvas* canvas = new TCanvas("myc","HW1",800,600);

  TH1F* h1 = new TH1F("h1","Landau 100 entries",15,-3,10);
  TH1F* h2 = new TH1F("h2","Landau 1000 entries",60,-3,10);
  TH1F* h3 = new TH1F("h3","Landau 10000 entries",200,-3,10);
  h1->FillRandom("mylandau",100);
  h2->FillRandom("mylandau",1000);
  h3->FillRandom("mylandau",10000);
  h3->GetXaxis()->SetTitle("x");
  h3->GetXaxis()->CenterTitle(true);
  h3->GetYaxis()->SetTitle("Entries");
  h3->GetYaxis()->CenterTitle(true);
  h3->SetStats(kFALSE);

  TF1* fit3 = new TF1("fit3",landauf,-3,10,3);
  fit3->SetParameters(1.0,2,1);
  h3->SetMarkerColor(kRed);
  h3->SetLineColor(kRed);
  fit3->SetLineColor(kRed+2);
  h3->Fit("fit3","q","e");

  TF1* fit2 = new TF1("fit2",landauf,-3,10,3);
  fit2->SetParameters(1.0,2,1);
  h2->SetMarkerColor(kBlue);
  h2->SetLineColor(kBlue);
  fit2->SetLineColor(kBlue+2);
  h2->Fit("fit2","q","esame");

  TF1* fit1 = new TF1("fit1",landauf,-3,10,3);
  fit1->SetParameters(1.0,2,1);
  h1->SetMarkerColor(kGreen);
  h1->SetLineColor(kGreen);
  fit1->SetLineColor(kGreen+2);
  h1->Fit("fit1","q","esame");

  double h1M = h1->GetMean();
  double h1R = h1->GetRMS();
  double h1S = h1->GetSkewness();
  double h2M = h2->GetMean();
  double h2R = h2->GetRMS();
  double h2S = h2->GetSkewness();
  double h3M = h3->GetMean();
  double h3R = h3->GetRMS();
  double h3S = h3->GetSkewness();

  cout<<setprecision(4);
  cout<<"+----+--------+--------+--------+"<<endl;
  cout<<"|hist|  Mean  |  RMS   |skewness|"<<endl;
  cout<<"+----+--------+--------+--------+"<<endl;
  cout<<"+  1 |"<<setw(8)<<h1M<<"|"<<setw(8)<<h1R<<"|"<<setw(8)<<h1S<<"|"<<endl;
  cout<<"+----+--------+--------+--------+"<<endl;
  cout<<"+  2 |"<<setw(8)<<h2M<<"|"<<setw(8)<<h2R<<"|"<<setw(8)<<h2S<<"|"<<endl;
  cout<<"+----+--------+--------+--------+"<<endl;
  cout<<"+  3 |"<<setw(8)<<h3M<<"|"<<setw(8)<<h3R<<"|"<<setw(8)<<h3S<<"|"<<endl;
  cout<<"+----+--------+--------+--------+"<<endl;

  TPaveStats *ptstats = new TPaveStats(0.5747126,0.6334746,0.9353448,0.934322,"brNDC");
  ptstats->SetName("stats");
  ptstats->SetBorderSize(1);
  ptstats->SetFillColor(0);
  ptstats->SetLineWidth(2);
  ptstats->SetTextAlign(12);
  ptstats->SetTextFont(132);
  ptstats->AddText(" hist   Mean     RMS    skewness ");
  ostringstream os;
  cout<<setprecision(4);
  os<<"   1  "<<setw(8)<<h1M<<" "<<setw(8)<<h1R<<" "<<setw(8)<<h1S<<" ";
  ptstats->AddText(os.str().c_str());
  os.str(string());
  os<<"   2  "<<setw(8)<<h2M<<" "<<setw(8)<<h2R<<" "<<setw(8)<<h2S<<" ";
  ptstats->AddText(os.str().c_str());
  os.str(string());
  os<<"   3  "<<setw(8)<<h3M<<" "<<setw(8)<<h3R<<" "<<setw(8)<<h3S<<" ";
  ptstats->AddText(os.str().c_str());
  ptstats->SetOptStat(0);
  ptstats->SetOptFit(111);
  ptstats->Draw();
  h1->GetListOfFunctions()->Add(ptstats);
  ptstats->SetParent(h1);

  TLegend *leg = new TLegend(0.1582915,0.7237762,0.3580402,0.9230769,NULL,"brNDC");
  leg->AddEntry(h1,"100 entries","pe");
  leg->AddEntry(h2,"1000 entries","pe");
  leg->AddEntry(h3,"10000 entries","pe");
  leg->SetFillColor(0);
  leg->Draw();

  //export png
  TImage *img = TImage::Create();
  img->FromPad(canvas);
  img->WriteImage("hw1.png");
  //delete img;


  //return
  return 0;
}
void eventviewer::viewEvent_1() //Event viewer
{
    //open beta
    gStyle->SetOptStat(0);
    aida_beta.GetTreeBETA(sinfile);
    if (aida_beta.fChain==0) return;
    //output
    TFile* rootfile=new TFile(soutfile,"RECREATE");
    //histograms
    TCanvas* c1=new TCanvas("ss","ss",600,600);
    TCanvas *c2rot = new TCanvas("c2rot","c2rot",300,300);
    c1->Divide(2,2);
    TH1F* hisx=new TH1F("hisX","hisX",128,0,128);
    TH1F* hisy=new TH1F("hisY","hisY",128,0,128);

    TH2F* hisxy=new TH2F("hisXY","hisXY",128,0,128,128,0,128);

    TH1I* hisTX=new TH1I("hisTX","hisTX",200,-1500,1500);
    TH1I* hisTY=new TH1I("hisTY","hisTY",200,-1500,1500);

    //Start reading input file!
    Long64_t nentries = aida_beta.GetEntries();
    cout<<"Total entries="<<nentries<<endl;
    Long64_t nbytes = 0, nb = 0;
    Long64_t entriestobreak=nentries+10;
    for (Long64_t jentry=0; jentry<nentries;jentry++) {
        Long64_t ientry=aida_beta.LoadTree(jentry);
        if (ientry<0) break;
        nb=aida_beta.GetEntry(jentry);nbytes+=nb;
        Double_t percent_complete=(Double_t)jentry/(Double_t)nentries*100;
        if (jentry%3000==0) cout<<percent_complete<<" % data piece proceeded"<<endl;
        //if (rawaida.Cut(ientry) < 0) continue;
        if (jentry>entriestobreak) break;

        hisx->Reset();
        hisy->Reset();
        hisxy->Reset();
        hisTX->Reset();
        hisTY->Reset();

        hisx->SetTitle(Form("hisX%d",(Int_t)jentry));
        hisy->SetTitle(Form("hisY%d",(Int_t)jentry));
        hisxy->SetTitle(Form("hisXY%d",(Int_t)jentry));

        Double_t totalExy=0;
        //if (aida_beta.dssd_Z_mult[0]>0){
        //if (aida_beta.pos_index_beta[0]==0&&aida_beta.npos_beta[0]>0){
            for (Int_t i=0;i<128;i++){
                Double_t ex=(Double_t)aida_beta.dssdH_E_X[0][i][0];
                Double_t ey=(Double_t)aida_beta.dssdH_E_Y[0][i][0];
                if (ex<0) ex=0.;
                if (ey<0) ey=0.;
                hisx->Fill(i,ex);
                hisy->Fill(i,ey);
                if (ex>0) hisTX->Fill(aida_beta.dssdH_T_X[0][i][0]-aida_beta.timestamp,ex);
                if (ey>0) hisTY->Fill(aida_beta.dssdH_T_Y[0][i][0]-aida_beta.timestamp,ey);
                for (Int_t j=0;j<128;j++){
                  Double_t eyy=(Double_t)aida_beta.dssdH_E_Y[0][j][0];
                  if (eyy<0) eyy=0.;
                    Double_t exy=ex+eyy;
                    hisxy->Fill(i,j,exy);
                    totalExy+=exy;
                }
            }
            //perform operation here
            //Draw to Canvas
            //if (totalExy>0){
            //if (aida_beta.dssd_Z_mult[0]>0){
            c2rot->cd();
            hisy->SetFillColor(3);
            hisy->SetLineColor(3);
            hisy->GetYaxis()->SetRangeUser(0,3000);
            hisy->Draw();
            c2rot->Update();
            TImage *img = TImage::Create();
            img->FromPad(c2rot);
            cout<<"Entry="<<jentry<<endl;
            c1->cd(1);
            img->Flip(90);
            img->Draw("x");
            //hisy->Draw("his");
            c1->cd(2);
            hisxy->SetMaximum(3000);
            hisxy->Draw("colz");
            //Draw hit position
            /*
            //Get Hit position
            Int_t beta_mult;
            map<Int_t, vector<pair<pair<Double_t,Double_t>,pair<Double_t,Double_t> > > > map_beta;
            map<Int_t, vector<pair<pair<Double_t,Double_t>,pair<Double_t,Double_t> > > >::iterator imap_beta;
            map_beta.clear();
            aida_beta.BetaGetPosNEW(0.3,beta_mult,map_beta);

            TMarker* mk[beta_mult];
            imap_beta = map_beta.find(0);
            if(imap_beta != map_beta.end()){
                Int_t beta_x = -1,beta_y = -1;
                for(unsigned int jj=0; jj<imap_beta->second.size(); jj++){
                    beta_x=imap_beta->second[jj].first.first;
                    beta_y=imap_beta->second[jj].second.first;
                    cout<<imap_beta->second[jj].first.second<<"-"<<imap_beta->second[jj].second.second<<endl;
                    mk[jj]=new TMarker(beta_x,beta_y,20);
                    mk[jj]->SetMarkerSize(1.);
                    mk[jj]->SetMarkerColor(2);
                    mk[jj]->Draw();
                }
            }
            */
            TMarker* mk=new TMarker(aida_beta.dssd_x[0],aida_beta.dssd_y[0],20);
            cout<<aida_beta.dssdH_E_X[0][aida_beta.dssd_X[0]][0]<<"-"<<aida_beta.dssdH_E_Y[0][aida_beta.dssd_Y[0]][0]<<endl;
            mk->SetMarkerSize(1.);
            mk->SetMarkerColor(2);
            mk->Draw();

            c1->cd(3);
            hisTX->SetFillColor(2);
            hisTX->SetLineColor(2);
            hisTX->GetYaxis()->SetRangeUser(0,3000);
            hisTX->Draw("his");
            hisTY->SetFillColor(3);
            hisTY->SetLineColor(3);
            hisTY->GetYaxis()->SetRangeUser(0,3000);
            hisTY->Draw("his same");

            c1->cd(4);
            hisx->GetYaxis()->SetRangeUser(0,3000);
            hisx->SetFillColor(2);
            hisx->SetLineColor(2);
            hisx->Draw("his");
            c1->Update();
            std::string name;
            std::getline (std::cin,name);
            if (name=="q") break;
        //}
        //---
    }//end of event loop



    c1->Write();
    rootfile->Close();
}
示例#11
0
void diaphragm_spectrum()
{
    gROOT->Reset();
    TFile * tfin = new TFile("data/kaon_mcraytracing.root");
    TH2D * hphotons;
    tfin->GetObject( "CedarMCTester/Photons/RayTracing/Diaphragm", hphotons );

    TCanvas c("c","c", 600, 600 );
    c.cd();
    gStyle->SetOptStat(0);
    gStyle->SetGridColor( kGray);
    c.SetRightMargin(0.15);
    c.SetLeftMargin(0.12);
    c.SetGrid();

    plot_diaphragm_spectrum( hphotons);

    c.Print("output/diaphragm_photons.pdf", "pdf" );

    TH2D * hphotoelectrons;
    tfin->GetObject( "CedarMCTester/Photoelectrons/RayTracing/Diaphragm", hphotoelectrons );
    plot_diaphragm_spectrum( hphotoelectrons);

    c.Print("output/diaphragm_photoelectrons.pdf", "pdf" );

    TCanvas * c2 = new TCanvas( "c2", "c2", 900, 300 );
    c2->cd();
    TFile * tfinpion = new TFile("data/pion_mcraytracing.root");
    TH2D * hpepion;
    tfinpion->GetObject( "CedarMCTester/Photoelectrons/RayTracing/Diaphragm", hpepion );

    gROOT->GetColor( kRed+2)->SetAlpha(0.02);
    hphotoelectrons->SetMarkerColor( kRed+2 );
    hphotoelectrons->Draw();
    hphotoelectrons->GetXaxis()->SetRangeUser(98, 104 );
    gROOT->GetColor( kBlue+2)->SetAlpha(0.02);
    hpepion->SetMarkerColor( kBlue+2 );
    hpepion->Draw("same");


    c2->SetGrid();
    c2->Print("output/diaphragm_pionvskaon.pdf", "pdf" );

    TImage * img = TImage::Create();
    img->FromPad(c2);
    img->WriteImage( "output/diaphragm_pionvskaon.png" );

    TH1D * hkaon = hphotoelectrons->ProjectionX( "hkaon", 0, -1 );
    TH1D * hpion = hpepion->ProjectionX( "hpion", 0, -1 );

    TCanvas * c3 = new TCanvas( "c2", "c2", 900, 500 );
    c3->cd();
    gROOT->GetColor( kRed+2)->SetAlpha(1);
    gROOT->GetColor( kBlue+2)->SetAlpha(1);
    hkaon->SetLineColor( kRed+2);
    hkaon->Scale(1.0/11.0);
    hpion->SetLineColor( kBlue+2);
    hpion->GetXaxis()->SetRangeUser(98,104);
    hpion->SetBit( TH1::kNoTitle, true );
    hpion->Draw();
    hkaon->SetBit( TH1::kNoTitle, true );
    hkaon->Draw("same");
    c3->SetGrid();
    c3->Print("output/diaphragm_pkcomp.pdf", "pdf" );
}
示例#12
0
int main(int argc , char* argv[]){
		
		//Program Options

	po::options_description desc("Allowed Options");
	desc.add_options()
		 ("help,h", "Produce this help message")
		 ("startwl,s",po::value<double>(),"Set the start Wavelength for the Analysis")
		 ("stopwl,p",po::value<double>(),"Set the stop Wavelength for the Analysis")
		 ("non-interactive,n","Runs the program in Noninteractive mode. It quits when it's finished")
		 ("version,v","Prints Version")
	;
		 
	po::variables_map vm;
		 po::store(po::parse_command_line(argc,argv,desc),vm);
		 po::notify(vm);
	if (vm.count("help")) {
		std::cout << desc<< std::endl;
		return 3;
	}
	if (vm.count("version")) {
		std::cout << "VCSEL Laser Analysis Version " << _VERSION << std::endl;
		std::cout << "Using ROOT version " << _ROOT_VERSION << " and Boost version " << _BOOST_VERSION << std::endl;
		return 0;
	}
	
	if (argc < 4) {
		std::cout << desc;
		return 2;
	}	
	double startwl, stopwl;
	startwl = 842.;
	stopwl = 860.;
	bool run = true;
	if (vm.count("startwl")) {
		startwl = vm["startwl"].as<double>();
		NUM_ARGS +=2;
	}
	if (vm.count("stopwl")) {
		double tmp =  vm["stopwl"].as<double>();
		stopwl =tmp;
		NUM_ARGS +=2;
	}
	if (vm.count("non-interactive")) {
		run = false;
		NUM_ARGS++;
	}
	
	
	//checking filetypes must be txt, csv or CSV
	if (!check_extensions(argc, argv)) {
		return 1;
	}
	std::cout <<"startwl: "<< startwl << '\t' << "stopwl: " << stopwl << std::endl;
	
	Double_t max = -210;
	Double_t maxwl = 0;
	int _argc = argc;
	TApplication *t = new TApplication("big",&_argc,argv);
	std::cout << "Running with boost and ROOT" <<std::endl;
	std::vector<double> _x,_y;
	Double_t x[LINES], y[LINES], _inta[LINES], _intb[LINES]; 
	
	Double_t *cmp_int = new Double_t[argc];
	Double_t *argc_ary = new Double_t[argc];
	Double_t *cmp_int_root = new Double_t[argc];
	Double_t *asymmety_ary = new Double_t[argc];
	Double_t *width_ary = new Double_t [argc];
	

	
	TGraph2D *gr = new TGraph2D(LINES*(argc-1));
		//Setting up canvas for plot of all sectrums (is it called spectrums? ;) )
	TCanvas *c1 = new TCanvas("All Plots","All Plots",10,10,3000,1500);
	TH1F *integral_hist = new TH1F("Asymmerty", "Asymmetry", 100,0, 100);
	

	if(!(argc % ROWS)){
		c1->Divide(argc/ROWS,ROWS);
		
	}else{
		c1->Divide(argc/ROWS+(argc %ROWS -1),ROWS);
	}
	
	for (Int_t i = NUM_ARGS +1; i < argc ; i++){
		try{ 
			
			max = -211;
			maxwl = 0;
			argc_ary[i] = i-NUM_ARGS;
			
			std::ifstream in;
			in.seekg(0, std::ios::beg);
				// voodoo keep this;
			char **arg1 = t->Argv() ;
			std::string tmp = arg1[i];
			in.open(tmp.c_str());
			
			std::cout<< "file: " << tmp << std::endl;
			std::string line;
			int cline = 0;
			std::vector<double> a,b, inta, intb;
			
				//reading file
			
			while(getline(in,line)){
				read_file(line, a, b, inta, intb);
				cline++;
			}
			
			if (cline < LINES){
				for(int i = cline ; i < LINES ; i++){
					a.push_back(100);
					b.push_back(-70);
				}
			}
			std::cout<< "\n\ncline: " << cline<< std::endl; 
			cline =(cline > LINES) ? LINES :cline;
			
			for(Int_t j = 0; j <LINES ;j++){
				x[j] = a[j];
				y[j] = b[j];
				_inta[j] = inta[j];
				_intb[j]= (intb[j] < 0)? 0:intb[j];
			}
			
			
			
			double s_integral = 0;
			
			std::cout <<"size of int " <<  intb.size()<< std::endl;
			for (size_t it = 0; it < intb.size() - 1; it++){
				double y_val = (intb[it]+intb[it+1])/2;
				assert (y_val >= 0);
				double area = 0.002*y_val;
				if(area > 0 )
					s_integral += area;
			}
			
			
			
			
			std::cout << "Simpson integral: " <<s_integral <<std::endl;
			integral_hist->Fill(s_integral);
			cmp_int[i] = s_integral;
			Int_t lines = (Int_t)intb.size();
			TGraph *r_integral = new TGraph(lines, _inta, _intb);
			
			std::cout << "ROOT integral: " << r_integral->Integral() << std::endl;
			cmp_int_root[i] = r_integral->Integral();
			
				//expanding
				//expand(y, THRS_EXPAND, RATIO_EXPAND, LINES);
			
			
				//Filling TGraph2D
			
			for(Int_t j = 0; j <LINES ; j++){
				if (y[j] > max){
					max = y[j];
					maxwl = x[j];
				}
				gr->SetPoint(j+i*LINES, x[j],i,y[j]);
			}
			
			
			in.seekg(0, std::ios::beg);
			in.close();
			
				//Plotting each spectrum
			
			TGraph *_gr = new TGraph(LINES,x,y);
			_gr->GetHistogram()->GetXaxis()->SetTitle("#lambda in nm");
			_gr->GetHistogram()->GetYaxis()->SetTitle("Intensity in dB");
			c1->cd(i-NUM_ARGS);
			_gr->Draw("AP");
			_gr->GetYaxis()->SetRangeUser(-80.,-10.);
			_gr->GetXaxis()->SetRangeUser(startwl,stopwl);
			_gr->SetTitle(tmp.c_str());
			c1->Update();
			
			
				//Calculating asymmetry
			std::cout << "maximum: " << max << std::endl;
			double leftlimit, rightlimit = 1;
			leftlimit = findlower(x,y, max);
			rightlimit = findupper(x,y, max);
			if (leftlimit != 1 && rightlimit != 1){
				width_ary[i] = (leftlimit +rightlimit)/2;
			}else{
				width_ary[i] = maxwl;
			}
			double calced_asy = (maxwl-leftlimit)/(rightlimit-maxwl);
			asymmety_ary[i-NUM_ARGS] = calced_asy;
			
			std::cout << "Asymmetry: " << calced_asy << std::endl;
			
		}catch(std::exception e){
			std::cout << e.what()<< std::endl;
		}
	}
	
	
		//Setting style for 3D Plot
	TCanvas *d = new TCanvas("big","big",10,10,1500,800);
	d->Divide(2,2);
	d->cd(1);
	TGraph *the_ints = new TGraph(argc-1,argc_ary,cmp_int);
	the_ints->Draw("A*");
	the_ints->SetTitle("My Ints");
	d->Update();
	d->cd(2);
	std::cout << "Fitting\n\n";
	integral_hist->SetFillColor(kBlue);
		//settig everything to print fitresuts
	gStyle->SetOptStat(1211);
	gStyle->SetOptFit(1111);
	integral_hist->Draw();
	integral_hist->Fit("gaus","W","" ,10,100);
		//integral_hist->Draw("SAME");
	d->Update();
	d->cd(3);
	
	TGraph *roots_int = new TGraph(argc-1, argc_ary, cmp_int_root);
	roots_int->SetTitle("ROOTS Int");
	roots_int->Draw("A*");
	d->Update();
	d->cd(4);
	d->Update();
		//gROOT->SetStyle("modern");
	gr->SetTitle("big");
	gr->GetHistogram("empty")->GetXaxis()->SetTitle("#lambda in nm");
	gr->GetHistogram("empty")->GetXaxis()->SetLimits(startwl,stopwl);
	gr->GetHistogram("empty")->GetYaxis()->SetTitle("Messurement"); 
	gr->GetHistogram("empty")->GetZaxis()->SetTitle("Intensity in dB");
	gr->GetHistogram("empty")->GetXaxis()->SetTitleOffset(1.5);
	gr->GetHistogram("empty")->GetYaxis()->SetTitleOffset(1.5);
	gr->GetHistogram("empty")->GetZaxis()->SetTitleOffset(1.5);
	gr->GetHistogram("empty")->GetZaxis()->SetRangeUser(-70.,max);
	gr->GetHistogram("empty")->GetXaxis()->CenterTitle();
	gr->GetHistogram("empty")->GetYaxis()->CenterTitle();
	gr->GetHistogram("empty")->GetZaxis()->CenterTitle();
	gr->Draw("PCOL");
	d->SetFillColor(16);
	
	
#ifdef RENDER
		//Render 3D animation
	const Int_t kUPDATE = 1;
	TSlider *slider = 0;
	
	for (Int_t i = 1; i <= 125; i++){
		TView3D *v = new TView3D();
		v->RotateView(5+i,45+i,d);
			//d->Update();
		
		if(i && (i%kUPDATE)== 0){
			if (i == kUPDATE){
				gr->Draw("PCOL");
				d->Update();
				slider = new TSlider("slider","test",850,-70,856,max);
			}
			if (slider) slider->SetRange(0,Float_t(i)/10000.);
			d->Modified();
			d->Update();
			d->Print("3d.gif+");
		} 
	}
	d->Update();
	d->Print("3d.gif++");
#endif
	
	
		//Saving image
	TImage *img = TImage::Create();
	boost::filesystem::path p(t->Argv(3));
	std::string file = p.parent_path().string();
	file += "_big.png";
	img->FromPad(d);
	img->WriteImage(file.c_str());
		//cleaning
	
	TCanvas *e = new TCanvas("Asymmetry","Asymmetry",10,10,1500,800);
	e->Divide(2,1);
	TGraph *asy_plot = new TGraph(argc-1, argc_ary, asymmety_ary);
	e->cd(1);
	asy_plot->SetTitle("Asymmetry");
	asy_plot->GetHistogram()->GetXaxis()->SetTitle("# Meassurement");
	asy_plot->GetHistogram()->GetYaxis()->SetTitle("Asymmetry");
	asy_plot->GetHistogram()->GetXaxis()->SetRange(1, argc);
	asy_plot->Draw("A*");
	e->Update();
	e->cd(2);
	
	
	TGraph *center_plot = new TGraph(argc-1 , argc_ary, width_ary);
	center_plot->GetHistogram()->GetXaxis()->SetTitle("# Meassurement");
	center_plot->GetHistogram()->GetYaxis()->SetTitle("Center in nm");
	center_plot->GetHistogram()->GetYaxis()->SetRangeUser(startwl, stopwl);
	center_plot->SetTitle("Center");
	center_plot->Draw("A*");
	e->Update();
		//Saving Images
	TImage *secimg = TImage::Create();
	boost::filesystem::path p2(t->Argv(3));
	file = p2.parent_path().string();
	file += "_asy_cent.png";
	secimg->FromPad(e);
	secimg->WriteImage(file.c_str());
	
	TImage *thrdimg = TImage::Create();
	boost::filesystem::path p3(t->Argv(3));
	file = p3.parent_path().string();
	file += "_allplots.png";
	thrdimg->FromPad(c1);
	thrdimg->WriteImage(file.c_str());
	
		//detecting Gradients
	gradient(asymmety_ary, width_ary,cmp_int, argc-1,c1);
	std::cout << "\n\n\nDone !!\nYou can quit now using CTRL+C \n" ;
	
	if (run == true){
		t->Run();
	}
	std::cout << "With \n" ;
	
	delete[] cmp_int;
	delete[] argc_ary; 
	delete[] cmp_int_root;
	delete[] asymmety_ary;
	delete[] width_ary;
	return 0;
}
示例#13
0
void PtrelByFittingPlots (const char * mfile, const char * mcfile)
{
    char name[256];

    gROOT->SetStyle("Plain");

    TFile * measurement = new TFile(mfile, "READ");
    TFile * mctruth = new TFile(mcfile, "READ");

    TCanvas * c1 = new TCanvas("c1", "PtrelSolver apply to TC");
    TImage *img = TImage::Create();

    c1->Divide(3,2);

    c1->cd(1);
    plot(measurement, "/measurements/measurement_n_pT_ntag_pT_TCL_b", mctruth, "/mctruth/mctruth_n_pT_b_ntag_pT_b_TCL");

    c1->cd(2);
    plot(measurement, "/measurements/measurement_n_pT_ntag_pT_TCM_b", mctruth, "/mctruth/mctruth_n_pT_b_ntag_pT_b_TCM");

    c1->cd(3);
    plot(measurement, "/measurements/measurement_n_pT_ntag_pT_TCT_b", mctruth, "/mctruth/mctruth_n_pT_b_ntag_pT_b_TCT");

    c1->cd(4);
    plot(measurement, "/measurements/measurement_n_eta_ntag_eta_TCL_b", mctruth, "/mctruth/mctruth_n_eta_b_ntag_eta_b_TCL");

    c1->cd(5);
    plot(measurement, "/measurements/measurement_n_eta_ntag_eta_TCM_b", mctruth, "/mctruth/mctruth_n_eta_b_ntag_eta_b_TCM");

    c1->cd(6);
    plot(measurement, "/measurements/measurement_n_eta_ntag_eta_TCT_b", mctruth, "/mctruth/mctruth_n_eta_b_ntag_eta_b_TCT");

    sprintf(name, "%s.TC.png", mfile);
    img->FromPad(c1);
    img->WriteImage(name);

    TCanvas * c2 = new TCanvas("c2", "PtrelSolver apply to JP");

    c2->Divide(3,2);

    c2->cd(1);
    plot(measurement, "/measurements/measurement_n_pT_ntag_pT_JPL_b", mctruth, "/mctruth/mctruth_n_pT_b_ntag_pT_b_JPL");

    c2->cd(2);
    plot(measurement, "/measurements/measurement_n_pT_ntag_pT_JPM_b", mctruth, "/mctruth/mctruth_n_pT_b_ntag_pT_b_JPM");

    c2->cd(3);
    plot(measurement, "/measurements/measurement_n_pT_ntag_pT_JPT_b", mctruth, "/mctruth/mctruth_n_pT_b_ntag_pT_b_JPT");

    c2->cd(4);
    plot(measurement, "/measurements/measurement_n_eta_ntag_eta_JPL_b", mctruth, "/mctruth/mctruth_n_eta_b_ntag_eta_b_JPL");

    c2->cd(5);
    plot(measurement, "/measurements/measurement_n_eta_ntag_eta_JPM_b", mctruth, "/mctruth/mctruth_n_eta_b_ntag_eta_b_JPM");

    c2->cd(6);
    plot(measurement, "/measurements/measurement_n_eta_ntag_eta_JPT_b", mctruth, "/mctruth/mctruth_n_eta_b_ntag_eta_b_JPT");

    sprintf(name, "%s.JP.png", mfile);
    img->FromPad(c2);
    img->WriteImage(name);

    TCanvas * c3 = new TCanvas("c3", "PtrelSolver apply to SV");

    c3->Divide(3,2);

    c3->cd(1);
    plot(measurement, "/measurements/measurement_n_pT_ntag_pT_SVL_b", mctruth, "/mctruth/mctruth_n_pT_b_ntag_pT_b_SVL");

    c3->cd(2);
    plot(measurement, "/measurements/measurement_n_pT_ntag_pT_SVM_b", mctruth, "/mctruth/mctruth_n_pT_b_ntag_pT_b_SVM");

    c3->cd(3);
    plot(measurement, "/measurements/measurement_n_pT_ntag_pT_SVT_b", mctruth, "/mctruth/mctruth_n_pT_b_ntag_pT_b_SVT");

    c3->cd(4);
    plot(measurement, "/measurements/measurement_n_eta_ntag_eta_SVL_b", mctruth, "/mctruth/mctruth_n_eta_b_ntag_eta_b_SVL");

    c3->cd(5);
    plot(measurement, "/measurements/measurement_n_eta_ntag_eta_SVM_b", mctruth, "/mctruth/mctruth_n_eta_b_ntag_eta_b_SVM");

    c3->cd(6);
    plot(measurement, "/measurements/measurement_n_eta_ntag_eta_SVT_b", mctruth, "/mctruth/mctruth_n_eta_b_ntag_eta_b_SVT");

    sprintf(name, "%s.SV.png", mfile);
    img->FromPad(c3);
    img->WriteImage(name);

    TCanvas * c4 = new TCanvas("c4", "PtrelSolver apply to CSV");

    c4->Divide(3,2);

    c4->cd(1);
    plot(measurement, "/measurements/measurement_n_pT_ntag_pT_CSVL_b", mctruth, "/mctruth/mctruth_n_pT_b_ntag_pT_b_CSVL");

    c4->cd(2);
    plot(measurement, "/measurements/measurement_n_pT_ntag_pT_CSVM_b", mctruth, "/mctruth/mctruth_n_pT_b_ntag_pT_b_CSVM");

    c4->cd(3);
    plot(measurement, "/measurements/measurement_n_pT_ntag_pT_CSVT_b", mctruth, "/mctruth/mctruth_n_pT_b_ntag_pT_b_CSVT");

    c4->cd(4);
    plot(measurement, "/measurements/measurement_n_eta_ntag_eta_CSVL_b", mctruth, "/mctruth/mctruth_n_eta_b_ntag_eta_b_CSVL");

    c4->cd(5);
    plot(measurement, "/measurements/measurement_n_eta_ntag_eta_CSVM_b", mctruth, "/mctruth/mctruth_n_eta_b_ntag_eta_b_CSVM");

    c4->cd(6);
    plot(measurement, "/measurements/measurement_n_eta_ntag_eta_CSVT_b", mctruth, "/mctruth/mctruth_n_eta_b_ntag_eta_b_CSVT");

    sprintf(name, "%s.CSV.png", mfile);
    img->FromPad(c4);
    img->WriteImage(name);

    TCanvas * c5 = new TCanvas("c5", "PtrelSolver apply to JBP");

    c5->Divide(3,2);

    c5->cd(1);
    plot(measurement, "/measurements/measurement_n_pT_ntag_pT_JBPL_b", mctruth, "/mctruth/mctruth_n_pT_b_ntag_pT_b_JBPL");

    c5->cd(2);
    plot(measurement, "/measurements/measurement_n_pT_ntag_pT_JBPM_b", mctruth, "/mctruth/mctruth_n_pT_b_ntag_pT_b_JBPM");

    c5->cd(3);
    plot(measurement, "/measurements/measurement_n_pT_ntag_pT_JBPT_b", mctruth, "/mctruth/mctruth_n_pT_b_ntag_pT_b_JBPT");

    c5->cd(4);
    plot(measurement, "/measurements/measurement_n_eta_ntag_eta_JBPL_b", mctruth, "/mctruth/mctruth_n_eta_b_ntag_eta_b_JBPL");

    c5->cd(5);
    plot(measurement, "/measurements/measurement_n_eta_ntag_eta_JBPM_b", mctruth, "/mctruth/mctruth_n_eta_b_ntag_eta_b_JBPM");

    c5->cd(6);
    plot(measurement, "/measurements/measurement_n_eta_ntag_eta_JBPT_b", mctruth, "/mctruth/mctruth_n_eta_b_ntag_eta_b_JBPT");

    sprintf(name, "%s.JBP.png", mfile);
    img->FromPad(c5);
    img->WriteImage(name);

}
void multiHistoDraw(const char *file, const char *histname1, const char *desc1,
		const char *histname2, const char *desc2, 
		const char *histtitle, const char *xtitle,  const char *ytitle, const char *outfile,
		const char *histname3 = "none", const char *desc3 = "none", 
		const char *histname4 = "none", const char *desc4 = "none", const char *sbox = "True"){

   Int_t ci;      // for color index setting
   TColor *color; // for color definition with alpha
   Int_t line1 = 1;
   Int_t fill1 = 18;

   Int_t line2 = 2;
   Int_t fill2 = 0;

   Int_t line3 = 4;
   Int_t fill3 = 0;

   Int_t line4 = 32;
   Int_t fill4 = 0;

   bool drawSBox = true;

   if(strcmp(sbox,"True")){
     gStyle->SetOptStat(0);
     drawSBox = false;
   }


   int filenum = 2;
   if(strcmp(histname3,"none")&&strcmp(desc3,"none")){
     filenum = 3;
   }

   if(strcmp(histname4,"none")&&strcmp(desc4,"none")){
     filenum = 4;
   }   

  TCanvas *c = new TCanvas();
  c->SetLogy();
  c->SetGridx();
  c->SetGridy();

  TFile *f1 = new TFile(file);
  if(f1->IsZombie()){
    cout << "Root file: " << file << " not found!" << endl;
    return;
  }

  TH1F *h1 = (TH1F*)f1->Get(histname1);
  TH1F *h2 = (TH1F*)f1->Get(histname2);

  TH1F *h3;
  TH1F *h4;

  if(filenum >= 3){
    h3 = (TH1F*)f1->Get(histname3);
  }

 if(filenum >= 4){
    h4 = (TH1F*)f1->Get(histname4);
  }

 int start1 = h1->FindFirstBinAbove(0.00005);
 int start2 = h2->FindFirstBinAbove(0.00005);
 int start3;
 int start4;

 int startplot = (start1 < start2 ? start1 : start2);
 if(filenum >= 3){
   start3 = h3->FindFirstBinAbove(0.00005);
   startplot = (startplot < start3 ? startplot : start3);
 }

 if(filenum >= 4){
   start4 = h4->FindFirstBinAbove(0.00005);
   startplot = (startplot < start4 ? startplot : start4);
 }

 int end1 = h1->FindLastBinAbove(0.00005);
 int end2 = h2->FindLastBinAbove(0.00005);
 int end3;
 int end4;

 int endplot = (end1 > end2 ? end1 : end2);
 if(filenum >= 3){
   end3 = h3->FindLastBinAbove(0.00005);
   endplot = (endplot > end3 ? endplot : end3);
 }

 if(filenum >= 4){
   end4 = h4->FindFirstBinAbove(0.00005);
   endplot = (endplot > end4 ? endplot : end4);
 }

 int plotspace = (endplot - startplot) / 4;

 //cout << "Start Bin: " << startplot << " End Bin : " << endplot << endl;

 startplot = (startplot - plotspace > 0 ? startplot - plotspace : 1);
 endplot = endplot + plotspace;

 //cout << "Start Bin: " << startplot << " End Bin : " << endplot << endl;

 

  float yrange;

  if(h1->GetBinContent(h1->GetMaximumBin()) > h2->GetBinContent(h2->GetMaximumBin())){
    yrange = h1->GetBinContent(h1->GetMaximumBin());
  }else{
    yrange = h2->GetBinContent(h2->GetMaximumBin());
  }

  if(filenum >= 3) yrange = (yrange > h3->GetBinContent(h3->GetMaximumBin()) ? yrange : h3->GetBinContent(h3->GetMaximumBin()));
  if(filenum >= 4) yrange = (yrange > h4->GetBinContent(h4->GetMaximumBin()) ? yrange : h4->GetBinContent(h4->GetMaximumBin()));

  //Start Drawing
  h1->SetName(desc1);
  h1->SetTitle(histtitle);
  h1->SetMaximum(yrange*1.3);
   ci = TColor::GetColor("#ccccff");
   h1->SetFillColor(fill1);

   ci = TColor::GetColor("#000099");
   h1->SetLineColor(line1);
   h1->SetLineWidth(2);
   h1->GetXaxis()->SetTitle(xtitle);
   h1->GetXaxis()->SetLabelFont(42);
   h1->GetXaxis()->SetLabelSize(0.035);
   h1->GetXaxis()->SetTitleSize(0.045);
   h1->GetXaxis()->SetTitleFont(42);
   h1->GetYaxis()->SetTitle(ytitle);
   h1->GetYaxis()->SetLabelFont(42);
   h1->GetYaxis()->SetLabelSize(0.035);
   h1->GetYaxis()->SetTitleSize(0.045);
   h1->GetYaxis()->SetTitleFont(42);
   h1->GetXaxis()->SetRange(startplot,endplot);
   h1->GetZaxis()->SetLabelFont(42);
   h1->GetZaxis()->SetLabelSize(0.035);
   h1->GetZaxis()->SetTitleSize(0.035);
   h1->GetZaxis()->SetTitleFont(42);
   h1->Draw("");

   TPaveStats *st1;
   TPaveStats *st2;
   TPaveStats *st3;
   TPaveStats *st4;

   gPad->Update();
   if(drawSBox){
     st1 = (TPaveStats*)h1->FindObject("stats");
     if(!st1){
       cout << "Failed to load statbox!" << endl;
       return;
     }
   }

   float y1 = st1->GetY1NDC();
   float y2 = st1->GetY2NDC();
   float stHeight = y2 - y1;
   float stSpacing = stHeight / 6;

   h2->SetName(desc2);

   ci = TColor::GetColor("#ffcccc");
   h2->SetFillColor(fill2);
   h2->SetFillStyle(3001);
   h2->SetLineColor(line2);
   h2->SetLineWidth(3);
   h2->GetXaxis()->SetLabelFont(42);
   h2->GetXaxis()->SetLabelSize(0.035);
   h2->GetXaxis()->SetTitleSize(0.035);
   h2->GetXaxis()->SetTitleFont(42);
   h2->GetYaxis()->SetLabelFont(42);
   h2->GetYaxis()->SetLabelSize(0.035);
   h2->GetYaxis()->SetTitleSize(0.035);
   h2->GetYaxis()->SetTitleFont(42);
   h2->GetZaxis()->SetLabelFont(42);
   h2->GetZaxis()->SetLabelSize(0.035);
   h2->GetZaxis()->SetTitleSize(0.035);
   h2->GetZaxis()->SetTitleFont(42);
   h2->Draw("sames");

   gPad->Update();
   if(drawSBox){
     st2 = (TPaveStats*)h2->FindObject("stats");
     st2->SetY1NDC(y1-stSpacing-stHeight);
     st2->SetY2NDC(y1-stSpacing);

     st3;
     st4;
   }

   if(filenum >= 3){
     if(drawSBox){
       y1 = st2->GetY1NDC();
       y2 = st2->GetY2NDC();
     }
     stHeight = y2 - y1;
     stSpacing = stHeight / 6;

     h3->SetName(desc3);

     ci = TColor::GetColor("#ffcccc");
     h3->SetFillColor(fill3);
     h3->SetFillStyle(3001);
     h3->SetLineColor(line3);
     h3->SetLineWidth(2);
     h3->GetXaxis()->SetLabelFont(42);
     h3->GetXaxis()->SetLabelSize(0.035);
     h3->GetXaxis()->SetTitleSize(0.035);
     h3->GetXaxis()->SetTitleFont(42);
     h3->GetYaxis()->SetLabelFont(42);
     h3->GetYaxis()->SetLabelSize(0.035);
     h3->GetYaxis()->SetTitleSize(0.035);
     h3->GetYaxis()->SetTitleFont(42);
     h3->GetZaxis()->SetLabelFont(42);
     h3->GetZaxis()->SetLabelSize(0.035);
     h3->GetZaxis()->SetTitleSize(0.035);
     h3->GetZaxis()->SetTitleFont(42);
     h3->Draw("sames");

     gPad->Update();
     if(drawSBox){
       st3 = (TPaveStats*)h3->FindObject("stats");
       st3->SetY1NDC(y1-stSpacing-stHeight);
       st3->SetY2NDC(y1-stSpacing);
     }
   }

   if(filenum >= 4){
     if(drawSBox){
       y1 = st3->GetY1NDC();
       y2 = st3->GetY2NDC();
       stHeight = y2 - y1;
       stSpacing = stHeight / 6;
     }

     h4->SetName(desc4);

     ci = TColor::GetColor("#ffcccc");
     h4->SetFillColor(fill4);
     h4->SetFillStyle(3001);
     h4->SetLineColor(line4);
     h4->SetLineWidth(2);
     h4->GetXaxis()->SetLabelFont(42);
     h4->GetXaxis()->SetLabelSize(0.035);
     h4->GetXaxis()->SetTitleSize(0.035);
     h4->GetXaxis()->SetTitleFont(42);
     h4->GetYaxis()->SetLabelFont(42);
     h4->GetYaxis()->SetLabelSize(0.035);
     h4->GetYaxis()->SetTitleSize(0.035);
     h4->GetYaxis()->SetTitleFont(42);
     h4->GetZaxis()->SetLabelFont(42);
     h4->GetZaxis()->SetLabelSize(0.035);
     h4->GetZaxis()->SetTitleSize(0.035);
     h4->GetZaxis()->SetTitleFont(42);
     h4->Draw("sames");

     gPad->Update();
     if(drawSBox){
       st4 = (TPaveStats*)h4->FindObject("stats");
       st4->SetY1NDC(y1-stSpacing-stHeight);
       st4->SetY2NDC(y1-stSpacing);
     }
   }

   TLegend *leg = new TLegend(0.3913858,0.6656347,0.7696629,0.876161,NULL,"brNDC");
   leg->SetBorderSize(1);
   leg->SetLineColor(1);
   leg->SetLineStyle(1);
   leg->SetLineWidth(1);
   leg->SetFillColor(0);
   leg->SetFillStyle(1001);
   //TLegendEntry *entry=leg->AddEntry("NULL","Datasets","h");
   //entry->SetLineColor(1);
   //entry->SetLineStyle(1);
   //entry->SetLineWidth(1);
   //entry->SetMarkerColor(1);
   //entry->SetMarkerStyle(21);
   //entry->SetMarkerSize(1);
   //entry->SetTextFont(42);
   TLegendEntry *entry=leg->AddEntry(desc1,desc1,"lpf");

   ci = TColor::GetColor("#ccccff");
   entry->SetFillColor(ci);
   entry->SetFillStyle(1001);

   ci = TColor::GetColor("#000099");
   entry->SetLineColor(ci);
   entry->SetLineStyle(1);
   entry->SetLineWidth(2);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(1);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry(desc2,desc2,"lpf");

   ci = TColor::GetColor("#ffcccc");
   entry->SetFillColor(ci);
   entry->SetFillStyle(3001);
   entry->SetLineColor(2);
   entry->SetLineStyle(2);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(1);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);

   if(filenum >= 3){
     entry=leg->AddEntry(desc3,desc3,"lpf");

     ci = TColor::GetColor("#ffcccc");
     entry->SetFillColor(ci);
     entry->SetFillStyle(3001);
     entry->SetLineColor(2);
     entry->SetLineStyle(2);
     entry->SetLineWidth(1);
     entry->SetMarkerColor(1);
     entry->SetMarkerStyle(1);
     entry->SetMarkerSize(1);
     entry->SetTextFont(42);
   }

   if(filenum >=4){
     entry=leg->AddEntry(desc4,desc4,"lpf");

     ci = TColor::GetColor("#ffcccc");
     entry->SetFillColor(ci);
     entry->SetFillStyle(3001);
     entry->SetLineColor(2);
     entry->SetLineStyle(2);
     entry->SetLineWidth(1);
     entry->SetMarkerColor(1);
     entry->SetMarkerStyle(1);
     entry->SetMarkerSize(1);
     entry->SetTextFont(42);
   }

   leg->Draw();
   c->Modified();
   c->cd();
   c->SetSelected(c);

   TImage *img = TImage::Create();

   img->FromPad(c);
   img->WriteImage(outfile);


}