Esempio n. 1
0
//------------------------------------------//
// Problem 2: There is a requirement that 
// at least 400 DOMs launch.  I want to look 
// at the average, and maybe also the average 
// for given event range.
//------------------------------------------//
void checkNDOM(TTree* tree)
{

  // Plot the number of DOM's per event
  TString var = "DetectorResponseEvent_.totalNumberOfDom_";

  // Make canvas
  TCanvas* c  = makeCanvas("c");

  // Make a vector of TCuts
  vector<TString> cuts;
  cuts.push_back("1");   // 1%
  cuts.push_back("3");   // 3%
  cuts.push_back("10");  // 10%
  cuts.push_back("30");  // 30%
  cuts.push_back("51");  // 51%
  cuts.push_back("100"); // 100%

  // Create histogram holders
  TH1F* hists[6];
  int nbins = 100;
  int min   = 0;
  int max   = 2000;
  TString xtitle = "nDOMs";
  TString ytitle = "Entries";
  
  // Make legend
  TLegend* leg = makeLegend(0.7,0.8,0.6,0.9);
  leg->SetHeader("Luminosity");

  // Loop and draw
  float maximum = -999;
  for(unsigned int i=0; i<cuts.size(); ++i){
    // get cut value
    TString cutval = cuts.at(i); 
    // create histogram
    hists[i] = makeFrame("hist_"+cutval,nbins,min,max,
			 xtitle,ytitle);

    // cut the TCut object from value
    TCut cut = lumiCut(cutval);

    // Draw and set att
    tree->Draw((var+">>hist_"+cutval).Data(),cut,"hist");
    setAtt(hists[i],xtitle,ytitle,m_colors[i],m_markers[i]);
    setMax(hists[i],maximum);

    // Add to legend
    leg->AddEntry(hists[i],(cutval+"%").Data(),"l");
  }

  // Now draw the figures
  hists[0]->SetMaximum(maximum*1.1);
  hists[0]->Draw("hist");
  for(unsigned int i=1; i<cuts.size(); ++i)
    hists[i]->Draw("samehist");
  leg->Draw("same");

  c->SaveAs((savedir+"nDoms_perLumi.png").Data());
}
Esempio n. 2
0
//------------------------------------------//
// Plot nDOM with out any other reqs.
//------------------------------------------//
void plotNDOM(TTree* tree)
{

  // Plot the number of DOM's per event
  TString var = "DetectorResponseEvent_.totalNumberOfDom_";

  // Make canvas
  TCanvas* c  = makeCanvas("c");

  // Create histogram holders
  int nbins = 100;
  int min   = 0;
  int max   = 2000;
  TString xtitle = "nDOMs";
  TString ytitle = "Entries";
  TH1F* hist = makeFrame("hist",nbins,min,max,
			 xtitle,ytitle);

  // Make legend
  TLegend* leg = makeLegend(0.7,0.8,0.8,0.9);
  leg->SetHeader("Luminosity");

  // Draw
  tree->Draw((var+">>hist").Data(),"","hist");

  // Add to legend
  leg->AddEntry(hist, "All", "l");

  // Now draw the figures
  hist->Draw("hist");
  leg->Draw("same");

  c->SaveAs((savedir+"nDoms_total.png").Data());
}
Esempio n. 3
0
//--- function to divide histograms then draw---
void drawDivHist(const char* hn1, const char* hn2, const char* opt, const char* name, const char* title, const int nbin, const float min, const float max, bool log=false, const int lc=0, const int ls=0, const int lw=0)
{
   // find input histos
   if (!TString(opt).Contains("same")) printf("\n");
   printf("h1: %s. h2: %s. Draw: %s\n", hn1, hn2, name);
   TH1F * h1; TH1F * h2;
   if (gROOT->FindObject(hn1))
      h1 = dynamic_cast<TH1F*>(gROOT->FindObject(hn1));
   else {
      printf("%s is not found, please check the histogram name\n", hn1);
      return;
   }
   if (gROOT->FindObject(hn2))
      h2 = dynamic_cast<TH1F*>(gROOT->FindObject(hn2));
   else {
      printf("%s is not found, please check the histogram name\n", hn2);
      return;
   }

   //--- Make/set histogram ---
   printf("hist: %s %d %f %f\n",name,nbin,min,max);
   TH1F * h = createHist(name, title, nbin, min, max);
   setHist(h,lc,ls,lw);

   //--- Action ---
   h->Divide(h1,h2);

   //--- Draw ---
   TCanvas * c = makeCanvas(name,title,log,opt);
   h->Draw(opt);
}
Esempio n. 4
0
//------------------------------------------//
// Format amplitude plots
//------------------------------------------//
void npulsePlot(TFile* file, vector<TString> filters)
{

  // Specify the titles
  TString xtitle = "Number of Pulses";
  TString ytitle = "Entries";

  // Histogram name
  TString pname = "h_npulse";

  // Create canvas
  TCanvas* c = makeCanvas("c");
  
  // Make legend
  TLegend* leg = makeLegend(0.7,0.8,0.6,0.9);
  //TLegend* leg = makeLegend(0.7,0.8,0.8,0.9);

  // Loop and plot
  TH1* hist[6];
  float maximum = -999;
  for(unsigned int i=0; i<filters.size(); ++i){
    TString filter = filters.at(i);
    
    hist[i] = getHist(file,pname+"_"+filter,xtitle,ytitle,
		   m_colors[i], m_markers[i]);
    
    leg->AddEntry(hist[i],(filter+"%").Data(),"l");

    if( maximum < hist[i]->GetMaximum() )
      maximum = hist[i]->GetMaximum();

  }// end loop over filters
  /*
  for(unsigned int i=0; i<filters.size(); ++i){
    leg->Clear();
    leg->SetHeader("Filter");
    leg->AddEntry(hist[i],(filters.at(i)+"%").Data(),"l");
    hist[i]->Draw();
    leg->Draw("same");
    c->SaveAs((savedir+"npulse_filter"+filters.at(i)+".png").Data());
  }

  return;
  */

  // Set maximum correctly
  hist[0]->SetMaximum(1.1*maximum);
  hist[0]->Draw();
  for(unsigned int i=1; i<filters.size(); ++i){
    hist[i]->Draw("same");
  }

  // Draw legend
  leg->SetHeader("Filter");
  leg->Draw("same");
  
  c->SaveAs((savedir+"npulse_perLumi.png").Data());

}
Esempio n. 5
0
//----------------------------------------//
// Main
//----------------------------------------//
void CompareVP()
{

  // Specify the the files
  const int nFiles = 2;
  TFile* files[nFiles];
  files[0] = new TFile("rootfiles/beam40MeV_100000Prim.root");
  files[1] = new TFile("rootfiles/beam100e3MeV_40Prim.root");
  
  // Specify the plot names for legend
  TString fnames[nFiles];
  fnames[0] = "E_{e-}^{prim}=40 MeV, x10^{4}";
  fnames[1] = "E_{e-}^{prim}=100 GeV, x40";

  // Colors
  int colors[] = {kBlue, kRed};
  int markers[] = {20, 25};

  // Specify the hist name and the labels
  TString pname  = "VP_avg";
  TString xtitle = "time [ns]";
  TString ytitle = "|RA(#theta_{C},t)| [Vs]";

  // Make Canvas
  TCanvas* c = makeCanvas("c");
  c->SetLogy();

  // Make legend
  TLegend* leg = makeLegend(0.15,0.3,0.8,0.9);
  
  // Specify the minimum and maximum for x-range
  float xmin = -1; // ns
  float xmax = 1;  // ns

  // Loop over and plot profiles
  TProfile* profs[nFiles];
  float maximum = -999;
  for(int f=0; f<nFiles; ++f){
    profs[f] = getProfile(files[f],pname,xtitle,ytitle,colors[f],markers[f]);
    leg->AddEntry(profs[f], fnames[f].Data(), "lep");
    if( maximum < profs[f]->GetMaximum() )
      maximum = profs[f]->GetMaximum();
    profs[f]->GetXaxis()->SetRange( profs[f]->GetXaxis()->FindBin(xmin),
				    profs[f]->GetXaxis()->FindBin(xmax));
  }

  // Set maximum and draw
  profs[0]->SetMaximum(maximum*10);
  profs[0]->Draw();
  for(int f=1; f<nFiles; ++f)
    profs[f]->Draw("same");
  leg->Draw("same");
  
  c->SaveAs((savedir+"EnergyNParticleComp.png").Data());
  
  
}
Esempio n. 6
0
void SegmentationDemo( cv::Mat org_image) {
    const char * mod_window = "Segmentation (Otsu, KMean, EM)";
    cv::Mat first_image, segmented_image;
    std::vector<cv::Mat> all_image_vec;

    org_image.copyTo(first_image);
    drawText(first_image, "Original");
    all_image_vec.push_back(first_image);

    std::cout << "Otsu Segmentation..." << std::endl;
    // otsu segmentation
    std::vector<cv::Mat> otsu_segmented_vec = OtsuSegmentation( org_image, 2 );
    drawText(otsu_segmented_vec.at(1), "Otsu");
    all_image_vec.push_back(otsu_segmented_vec.at(1));
    segmented_image = makeCanvas(all_image_vec, org_image.rows * 1, 2);

    // create a window to display results
    namedWindow( mod_window, CV_WINDOW_AUTOSIZE );
    // show images
    imshow(mod_window, segmented_image);

    std::cout << "KMean Segmentation..." << std::endl;
    // kmeans segmentation
    std::vector<cv::Mat> kmean_segmented_vec = KMeanSegmentation( org_image, 2 );
    drawText(kmean_segmented_vec.at(1), "KMeans");
    all_image_vec.push_back(kmean_segmented_vec.at(1));
    segmented_image = makeCanvas(all_image_vec, org_image.rows * 2, 2);

    // show images
    imshow(mod_window, segmented_image);

    std::cout << "EM Segmentation..." << std::endl;
    // em segmentation
    std::vector<cv::Mat> em_segmented_vec = EMSegmentation( org_image, 2 );
    drawText(em_segmented_vec.at(1), "EM");
    all_image_vec.push_back(em_segmented_vec.at(1));
    segmented_image = makeCanvas(all_image_vec, org_image.rows * 2, 2);

    // show images
    imshow(mod_window, segmented_image);

    // wait for termination
    waitKey();
}
Esempio n. 7
0
//------------------------------------//
// Main
//------------------------------------//
void AnaEField()
{

  // Make Canvas 
  TCanvas* can = makeCanvas("can");
  can->SetLogy();
  can->SetGridx();
  can->SetGridy();

  // Define the function here with parameters:
  // [0] = L
  // [1] = freq
  // [2] = k
  // [3] = n
  // [4] = sqrt(2pi) * mu * mu0
  TString func = "[4]*[0]*[1]*sin(x/57.2957)*exp(-pow([2]*[0],2)*pow(cos(x/57.2957)-1/[3],2)/2)";
  //TString func = "[4]*[1]*sin(x/57.2957)*exp(-pow([2]*[0],2)*pow(cos(x/57.2957)-1/[3],2)/2)";
  //TString func = "[4]*[0]*[1]*exp(-pow([2]*[0],2)*pow(cos(x/57.2957)-1/[3],2)/2)";

  // Now fix some of the variables:
  double freq = 1e9; //600e6; // Hz
  double c    = 3e8;   // m/s
  double n    = 1.3; //1.78;
  double k    = 2*TMath::Pi() * n * freq/c; // 1/m
  double Const= sqrt(2*TMath::Pi()) * 4 * TMath::Pi() * 1e-7 * 1;

  // Make a dummy histogram
  TH1F* h = makeHist("h",100,0,90,"Angle [deg]", "Field Strength",kBlack,0);
  h->Fill(1e10);
  h->SetMinimum(10);
  h->SetMaximum(3000);
  h->Draw();

  // Make two instances of the function
  TF1* f0 = new TF1("f0",func.Data(),0,90);
  setParam(f0,1.2,freq,k,n,Const,kBlack);

  TF1* f1 = new TF1("f1",func.Data(),0,90);
  setParam(f1,0.1,freq,k,n,Const,kBlue);
 
  // Draw
  f0->Draw("same");
  f1->Draw("same");
  
  // Add Legend
  TLegend* leg = makeLegend(0.15,0.3,0.7,0.9);
  leg->SetHeader("f = 600 MHz");
  leg->AddEntry(f0,"L = 1.2m","l");
  leg->AddEntry(f1,"L = 0.1m","l");
  leg->Draw("same");
  
  //can->SaveAs("../plots/quickAnalytic_600MHz.png");

}
Esempio n. 8
0
//----------------------------------------//
// Plot generic
//----------------------------------------//
void plot(vector<TH1F*> hists, 
	  vector<TString> lnames,
	  TString savename,
	  float xmin=-999, float xmax=-999,
	  bool logy=false,
	  bool logx=false)
{

  // Make canvas
  TCanvas* c = makeCanvas("c");
  if(logy) c->SetLogy();
  if(logx) c->SetLogx();

  // Make legend
  TLegend* leg = makeLegend(0.6,0.80,0.93-0.05*hists.size(),0.93);
  
  // Get minimum and maximum
  float maximum = -999;
  float minimum = 999;
  for(unsigned int i=0; i<hists.size(); ++i){
    if( maximum < hists[i]->GetMaximum() )
      maximum = hists[i]->GetMaximum();
    if( minimum > hists[i]->GetMinimum() )
      minimum = hists[i]->GetMinimum();
  }

  // Set minimum and maximum y
  hists.at(0)->SetMaximum((logy ? 5 : 1.2)*maximum);
  if(logy) hists.at(0)->SetMinimum( 1e-5 * maximum);
  else     hists.at(0)->SetMinimum( 1.2*minimum );

  // Set the range to be plotted, if necessary
  if( xmin > 0 && xmax > 0){
    hists[0]->GetXaxis()->SetRange( hists[0]->FindBin(xmin),
				    hists[0]->FindBin(xmax));
  }

  // Draw
  hists.at(0)->Draw();
  leg->AddEntry(hists.at(0), lnames.at(0), "lep");
  for(unsigned int i=1; i<lnames.size(); ++i){
    hists.at(i)->Draw("same");
    leg->AddEntry(hists.at(i), lnames.at(i), "lep");
  }

  leg->Draw("same");

  // Save
  if(m_save)
    c->SaveAs((m_savedir+savename+".png"));

}
void vertex_distribution_dataMC() {

  bool print = false;

  TFile *file0 = TFile::Open("results/RecoRoutines_W-selection_WJetsMGZ238PU.root");
  TFile *file1 = TFile::Open("results/RecoRoutines_W-selection_dataskimnov4rereco_newJetColl.root");

  TCanvas * canvas = makeCanvas("vertexDistribution_dataMC");
  TH1D * mc = (TH1D*)file0->Get("RECO_PolPlots_50toinf/RECO_NumVerticesPerEvent");
  TH1D * data = (TH1D*)file1->Get("RECO_PolPlots_50toinf/RECO_NumVerticesPerEvent");

  mc->GetXaxis()->SetTitle("Vertex Multiplicity");
  mc->GetXaxis()->SetTitleSize(0.06);
  mc->GetXaxis()->SetLabelOffset(0.015);
  mc->GetXaxis()->SetTitleOffset(1.2);
  mc->GetXaxis()->SetRangeUser(0,10);
  mc->GetYaxis()->SetRangeUser(0,0.35);

  mc->GetYaxis()->SetTitle("Normalised");
  mc->GetYaxis()->SetTitleSize(0.06);
  mc->GetYaxis()->SetTitleOffset(0.85);

  mc->SetLineColor(kRed);
  data->SetLineColor(kBlack);

  mc->SetLineWidth(4);
  mc->SetLineStyle(2);
  data->SetLineWidth(4);
  data->SetLineStyle(1);

  leg = new TLegend(0.6426174,0.8074324,0.9010067,0.9273649,NULL,"brNDC");
  leg->AddEntry(mc,"MC","l");
  leg->AddEntry(data,"Data","l");
  leg->SetFillColor(kWhite);
  leg->SetBorderSize(0);
  leg->SetTextFont(62);

  canvas->cd();
  mc->DrawNormalized("h");
  data->DrawNormalized("sameh");
  leg->DrawClone();

  if(print) {
    canvas->Write();
  }

  file1->Close();
  file0->Close();
  return;
}
Esempio n. 10
0
//=============================== Main Functions =====================================
//--- function to draw histograms from TTree ---
void drawTree(TTree* nt, const char* draw, const char* cut, const char* opt, const char* name, const char* title, const int nbin, const float min, const float max, bool log=false, const int lc=0, const int ls=0, const int lw=0)
{
   //--- Print some info ---
   if (!TString(opt).Contains("same")) printf("\n");
   printf("%s, tree: %d. Draw: %s\n", name, nt, draw);
//   nt->Print();

   //--- Make/set histogram ---
   printf("hist: %s %d %f %f\n",name,nbin,min,max);
   TH1F * h = createHist(name, title, nbin, min, max);
   setHist(h,lc,ls,lw);

   //--- Draw ---
   TCanvas * c = makeCanvas(name,title,log,opt);
   nt->Draw(draw, cut, opt);
   printf("%s has: %f entries\n",name,h->GetEntries());
}
Esempio n. 11
0
//------------------------------------------//
// Basic plot
//------------------------------------------//
void basicPlot(TFile* file)
{

  // There are three basic plots to make
  vector<TString> pnames;
  pnames.push_back("amp");
  pnames.push_back("npulse");
  pnames.push_back("tDiff");
  pnames.push_back("maxTDiff");

  // Set x-titles
  vector<TString> xtitles;
  xtitles.push_back("Amplitude [V]");
  xtitles.push_back("Number of Pulses");
  xtitles.push_back("LEtime - wavetime [ns]");
  xtitles.push_back("Max(LEtime - wavetime) [ns]");

  // Only one ytitle
  TString ytitle = "Entries";

  // Make Canvas
  TCanvas* c = makeCanvas("c");

  // Loop and plot
  TH1* hist = NULL;
  for(unsigned int i=0; i<pnames.size(); ++i){

    // Get Hist
    TString pname = "h_"+pnames.at(i);
    hist = getHist(file,pname,xtitles[i],ytitle,kBlack,20);

    // Plot
    hist->Draw();

    // Save
    c->SaveAs((savedir+pnames[i]+"_total.png").Data());

  }// end loop

  delete hist;
  delete c;
    
}
Esempio n. 12
0
//------------------------------------------//
// Format amplitude plots
//------------------------------------------//
void ampPlot(TFile* file, vector<TString> filters)
{

  // Specify the titles
  TString xtitle = "Amplitude [v]";
  TString ytitle = "Entries";

  // Histogram name
  TString pname = "h_amp";

  // Create canvas
  TCanvas* c = makeCanvas("c");
  c->SetLogx();
  c->SetLogy();

  // Make legend
  TLegend* leg = makeLegend(0.7,0.8,0.8,0.9);

  // Loop and plot
  TH1* hist = NULL;
  for(unsigned int i=0; i<filters.size(); ++i){
    leg->Clear();
    leg->SetHeader("Filter");
    
    TString filter = filters.at(i);
    
    hist = getHist(file,pname+"_"+filter,xtitle,ytitle,
		   m_colors[i], m_markers[i]);
    
    leg->AddEntry(hist,(filter+"%").Data(),"l");
    hist->Draw();

    // Draw legend
    leg->Draw("same");

    c->SaveAs((savedir+"amp_filter"+filter+".png").Data());

  }// end loop over filters


	       
}
Esempio n. 13
0
void Fake100PeVShower(int opt)
{

  // opt == 0 implies save to root file
  // opt == 1 implies plot and save to canvas
  TFile* file = NULL;
  TCanvas* c  = NULL;

  if(opt == 0)
    file = new TFile("fake100PeVShower.root","recreate");
  if(opt == 1)
    c = makeCanvas("c");

  TString gaus = "1.5e7*TMath::Exp(-(pow(x-10,2)/9))";
  TString bump = "5e6*TMath::Exp(-(pow(x-17,2)/20))";
  TF1* f = new TF1("f",(gaus+"+"+bump).Data(),0,30);

  int nbins = 3000;
  float xmin  = 0;
  float xmax  = 30;
  TProfile* prof = new TProfile("prof","",nbins,xmin,xmax);
  prof->SetStats(0);
  prof->SetTitle("");
  prof->GetYaxis()->SetTitle("Charge excess / 1e7");
  prof->GetXaxis()->SetTitle("z [m]");

  float step = xmax / nbins;
  for(int i =0; i<nbins; ++i){
    float x = step * i;
    if(opt == 1 ) prof->Fill(x, f->Eval(x)/1e7);
    else          prof->Fill(x, f->Eval(x));
  }
    
  if(opt == 1){
    prof->Draw();
    c->SaveAs("JaimeCheck/FakeProfile100PeV.png");
  }
  if(opt == 0){
    file->Write();
    file->Close();
  }
}
Esempio n. 14
0
//------------------------------------------//
// Plotting the maximum time difference
// for the maximum amplitude wave
//------------------------------------------//
void tDiffMaxPlotForMaxV(TFile* file, vector<TString> filters)
{

  // Specify the titles
  TString xtitle = "Max(LEtime - wavetime) [ns]";
  TString ytitle = "Entries";

  // Histogram name
  TString pname = "h_maxTDiff_forMaxV";

  // Create canvas
  TCanvas* c = makeCanvas("c");
  //c->SetLogy();
  
  // Make legend
  TLegend* leg = makeLegend(0.7,0.8,0.8,0.9);

  // Loop and plot
  TH1* hist = NULL;
  for(unsigned int i=0; i<filters.size(); ++i){
    leg->Clear();
    leg->SetHeader("Filter");
    TString filter = filters.at(i);
    
    hist = getHist(file,pname+"_"+filter,xtitle,ytitle,
		   m_colors[i], m_markers[i]);
    
    leg->AddEntry(hist,(filter+"%").Data(),"l");
    hist->Draw();

    // Draw legend
    leg->Draw("same");

    // Save 
    //c->SaveAs((savedir+"maxTimeDiff_filter"+filter+"_nonlog.png").Data());
    //c->SaveAs((savedir+"maxTimeDiff_cutOnCounter_filter"+filter+"_nonlog.png").Data());

  }// end loop over filters

	       
}
Esempio n. 15
0
//------------------------------------------//
// Problem 1: there is a function called
// utctimes(...).  I want to figure out 
// where I should place cuts to seperate
// the various luminosities
//------------------------------------------//
void checkUTCTimes(TTree* tree)
{

  // Variables to plot
  TString varx = "startUTCDaqTime_/1.e15"; // scale by 1e15
  TString vary = "DetectorResponseEvent_.totalBestEstimatedNPE_/1000.";
  //TString vary = "AtwdResponseChannels_.estimatedNPE_";

  // Make canvas
  TCanvas* c = makeCanvas("c");
  
  // Make a histogram to save
  float xmin = isSC2 ? 279.98 : 276.67;
  float xmax = isSC2 ? 280.15 : 276.84;
  float ymin = 0;
  float ymax = isSC2 ? 900 : 160;
  TH2F* frame = new TH2F("frame","",1, xmin,xmax,1,ymin,ymax);
  setAtt(frame,"Start DAQ Time / 10^{14}","Total Best Estimated NPE / 10^{3}");
  frame->Draw();

  // Draw from tree
  tree->Draw((vary+":"+varx).Data(),"","same");
  
  // Add constant functions of time
  vector<double> times = isSC2 ? getTimesSC2() : getTimesSC1();
  TLine* line = new TLine(); 
  line->SetLineWidth(1);
  line->SetLineColor(kBlue);
  for(unsigned int t=0; t<times.size(); ++t){
    double time = times.at(t);
    line->DrawLine(time,ymin,time,ymax);
    line->Draw("same");
  }

  // Save the plot
  TString pname = "timeVsAmp.png";
  c->SaveAs((savedir+pname).Data());
  
}
Esempio n. 16
0
//----------------------------------------//
// Plot Two histograms
//----------------------------------------//
void plot(TFile* f_mix, TFile* f_g4, TString append)
{

  // Make Canvas
  TCanvas* c = makeCanvas("c");
  c->SetLogy();

  // Make Legend
  TLegend* leg = makeLegend(0.7,0.9,0.75,0.92);
  leg->SetTextSize(0.05);

  // Some plot particles
  TString xtitle = "Shower Depth [cm]";
  TString ytitle = "<N(e^{-}-e^{+})>";

  // Get profile from g4 results
  //TProfile* p_g4 = getProfile(f_g4,"NPartSum",xtitle,ytitle,kBlack,20);
  TProfile* p_g4 = getProfile(f_g4,"NPartDiff",xtitle,ytitle,kBlack,20);
  p_g4->SetMarkerSize(0.75);

  // Get profile from mixed file
  int nbins = p_g4->GetNbinsX();
  float xmin = p_g4->GetXaxis()->GetXmin();
  float xmax = p_g4->GetXaxis()->GetXmax();
  TProfile* p_mix = getMixProfile(f_mix,nbins,xmin,xmax,kBlue,25);

  // Add to legend
  leg->AddEntry(p_g4,"G4", "lep");
  leg->AddEntry(p_mix,"G4 Mixed", "lep");

  // Draw
  //p_g4->Draw();
  //p_mix->Draw("same");
  //leg->Draw("same");

  // Make ratio plot
  plotRatio(p_mix, p_g4, leg, c, "Mixed/G4", append);

}
Esempio n. 17
0
void KMeanDemo( cv::Mat org_image) {
    const char * org_window = "Original Image";
    const char * mod_window = "KMean Segmentation";

    // image segmentation
    std::vector<cv::Mat> segmented_vec = KMeanSegmentation( org_image, 2 );
    drawText(segmented_vec.at(0), "Background");
    drawText(segmented_vec.at(1), "Object");

    cv::Mat segmented_image = makeCanvas(segmented_vec, org_image.rows, 1);

    // create a window to display results
    namedWindow( org_window, CV_WINDOW_AUTOSIZE );
    namedWindow( mod_window, CV_WINDOW_AUTOSIZE );

    // show images
    imshow(org_window, org_image);
    imshow(mod_window, segmented_image);

    // wait for termination
    waitKey();
}
Esempio n. 18
0
void compare3839() {

  bool write = true;
  unsigned int rebin = 10;
  TFile *Output = new TFile("MC_38_vs_39_WJetsZ2_Madgraph_RECO.root","RECREATE");

  TFile *file0 = TFile::Open("results/RecoRoutines_W-selection_WJets_madgraph_Fall2010Z2_newJetColl_vw.root");
  TFile *file1 = TFile::Open("results/RecoRoutines_W-selection_WJetsMGZ239.root");

  TString basepath = "RECO_PolPlots_50toinf/";
  TString histname[8] = {"RECO_ICVarPFPlus", "RECO_ICVarPFMinus", "RECO_MuonPtPlus", "RECO_MuonPtMinus", "RECO_pfMTPlus", "RECO_pfMTMinus", "RECO_pfMETPlus", "RECO_pfMETMinus"};
  TString xaxisname[8] = {"LP(#mu^{+})", "LP(#mu^{-})", "P_{T}(#mu^{+})", "P_{T}(#mu^{-})", "M_{T}(+)", "M_{T}(-)", "MET(+)", "MET(-)"};
  TCanvas * canvas[8] = {makeCanvas("pLP_RECO"), makeCanvas("mLP_RECO"), makeCanvas("pPTmu_RECO"), makeCanvas("mPTmu_RECO"), makeCanvas("pMT_RECO"), makeCanvas("mMT_RECO"), makeCanvas("pMET_RECO"), makeCanvas("mMET_RECO")};

  for(unsigned int i=0; i<8; i++) {

  TH1F * phist38 = (TH1F*)file0->Get(basepath+histname[i]);
  TH1F * phist39 = (TH1F*)file1->Get(basepath+histname[i]);

  cout << "38 Integral: " << phist38->Integral() << endl;
  cout << "39 Integral: " << phist39->Integral() << endl;

  phist38->GetXaxis()->SetTitle(xaxisname[i]);
  phist38->Rebin(rebin);
  phist39->Rebin(rebin);
  phist38->SetLineColor(kRed);
  phist39->SetLineColor(kBlack);
  phist38->SetLineWidth(4);
  phist38->SetLineStyle(1);
  phist39->SetLineWidth(4);
  phist39->SetLineStyle(2);

  //pLP_LH->GetXaxis()->SetTitleSize(0.06);
  //pLP_LH->GetXaxis()->SetLabelOffset(0.015);
  //pLP_LH->GetXaxis()->SetTitleOffset(1.2);
  //pLP_LH->GetXaxis()->SetRange(21,46);

  //pLP_LH->GetYaxis()->SetTitle("Events (a.u.)");
  //pLP_LH->GetYaxis()->SetTitleSize(0.06);
  //pLP_LH->GetYaxis()->SetTitleOffset(0.85);

  leg = new TLegend(0.6426174,0.8074324,0.9010067,0.9273649,NULL,"brNDC");
  leg->AddEntry(phist38,"WJetsZ2_38","l");
  leg->AddEntry(phist39,"WJetsZ2_39","l");
  leg->SetFillColor(kWhite);
  leg->SetBorderSize(0);
  leg->SetTextFont(62);

  //Unfortunately, if you want to show the relative sizes of the templates from tau->mu, 
  //then DrawNormalized will only show the shape - use DrawCopy instead
  //TCanvas * c1 = new TCanvas("pLP_RECO","pLP_RECO",600,620);
  //c1->SetLeftMargin(0.12);
  //c1->SetRightMargin(0.06);
  //c1->SetTopMargin(0.04);
  //c1->SetBottomMargin(0.16);
  canvas[i]->cd();
  phist38->DrawCopy("h");
  phist39->DrawCopy("sameh");
  //pLP_LH->DrawCopy("h");
  //pLP_LO->DrawCopy("sameh");
  //pLP_RH->DrawCopy("sameh");
  //pLP_LH_tau->DrawCopy("sameh");
  //pLP_RH_tau->DrawCopy("sameh");
  //pLP_LO_tau->DrawCopy("sameh");
  leg->DrawClone();

  }

  if(write) {
    Output->cd();
    canvas[0]->Write();
    canvas[1]->Write();
    canvas[2]->Write();
    canvas[3]->Write();
    canvas[4]->Write();
    canvas[5]->Write();
    canvas[6]->Write();
    canvas[7]->Write();
    Output->Close();
  }

  file1->Close();
  file0->Close();
  return;
}
Esempio n. 19
0
//----------------------------------------//
// Plot ZHS and G4 on same figure
//----------------------------------------//
void plotWithRatio(vector<TString> f_zhs,
		   vector<TString> f_g4,
		   TString p_zhs,
		   TString p_g4,
		   vector<TString> savenames)
{

  // Make canvas
  TCanvas* c = makeCanvas("c");
  //c->SetLogy();

  // Make a legend
  TLegend* leg = makeLegend(0.15,0.3,0.79,0.92);  
  leg->SetTextSize(0.055);

  // Titles
  TString xtitle = "time [ns]";
  TString ytitle = "A [Vs/m]";    

  // Loop and get plots
  TProfile* prof_Z = NULL;
  TProfile* prof_G = NULL;
  TH1D* h_resetZ   = NULL;
  for(unsigned int i=0; i<f_zhs.size(); ++i){

    // Load ZHS profile
    TFile* file_Z = new TFile(f_zhs.at(i).Data());
    prof_Z = getProfile(file_Z, p_zhs, xtitle, ytitle, kBlue, 20);
    prof_Z->SetDirectory(0);
    file_Z->Close();
    leg->AddEntry(prof_Z,"ZHS","lep");

    // Load Geant profile
    TFile* file_G = new TFile(f_g4.at(i).Data());
    prof_G = getProfile(file_G, p_g4, xtitle, ytitle, kRed, 20);
    prof_G->SetDirectory(0);
    file_G->Close();
    leg->AddEntry(prof_G,"Geant4","lep");
    
    // Scale Geant4 profile up by factor of R
    //prof_G->Scale(m_R);
    
    // reset the zhs timing info
    //prof_Z = resetZHS(prof_Z, prof_G, kBlue, m_R);
    h_resetZ = resetZHS(prof_Z, prof_G, kBlue, m_R);
    //prof_Z->Scale(1/m_R);

    // Get maximum
    float maximum = prof_G->GetMaximum();
    if( maximum < h_resetZ->GetMaximum() )
      maximum = h_resetZ->GetMaximum();
    prof_G->SetMaximum(maximum*5);
    prof_G->SetMinimum(maximum*1e-5);

    // Make two pads
    TPad* top = NULL;
    TPad* bot = NULL;
    makePads(c, top, bot);

    // Set some attributes
    prof_G->GetYaxis()->SetLabelSize(0.05);
    prof_G->GetYaxis()->SetTitleSize(0.05);
    prof_G->GetYaxis()->SetTitleOffset(1.0);
    prof_G->GetXaxis()->SetLabelSize(0);

    // Draw top plots
    c->cd();
    top->Draw();
    top->cd();
    top->SetLogy();
    prof_G->Draw();
    //prof_Z->Draw("sameep");
    h_resetZ->Draw("sameep");
    leg->Draw("same");
    top->Update();

    // Draw bot ratio
    c->cd();
    bot->Draw();
    bot->cd();
    //TProfile* prof = prof_G->Clone("ratio");
    TH1D* prof = prof_G->ProjectionX("ratio");
    prof->SetLineColor(prof_G->GetLineColor());
    prof->SetMarkerColor(prof_G->GetMarkerColor());
    prof->SetStats(0);
    //prof->Divide(prof_Z);
    prof->Divide(h_resetZ);
    prof->GetYaxis()->SetTitle("G4/ZHS");
    prof->SetMinimum(0);
    //prof->SetMaximum(50);
    prof->SetMaximum(2);
    prof->GetXaxis()->SetLabelSize(0.1);
    prof->GetYaxis()->SetLabelSize(0.1);
    prof->GetXaxis()->SetTitleSize(0.12);
    prof->GetYaxis()->SetTitleSize(0.12);
    prof->GetYaxis()->SetTitleOffset(0.4);
    prof->GetYaxis()->SetNdivisions(405);
    prof->Draw();
    bot->Update();
    
    if(m_save){
      //TString save = m_savedir + p_g4 + "_ZHSCherAngle.png";
      //TString save = m_savedir + savenames.at(i) + "_ratio.png";
      TString save = m_savedir + savenames.at(i) + "_ratio_fixed.png";
      c->SaveAs(save.Data());
    }

  }// end loop over files


}
Esempio n. 20
0
void MT_datamc2() {
  TLatex *tplus = labelLatex(0.20,0.80,"7 TeV Data");
  gROOT->SetStyle("Plain"); 
  gStyle->SetOptStat(0);
  gStyle->SetPalette(1);
  //the correct W x-sec to use is 31314, c.f. 24170, 30380
  double w_scale = 43.0;//(31314.0 / 24170.0) * 35.0;
  double z_scale = w_scale;
  double qcd_scale = 14./1000.0;
  double data_scale = 1.;
  unsigned int rbin = 5;
  unsigned int numPlots = 4;
  bool doPrint = false;

  TString folder = "hltmu15_goodevsel";

  TFile *file0 = TFile::Open("results/" + folder + "/RecoRoutines_W-selection_realdata.root");
  TFile *file1 = TFile::Open("results/" + folder + "/RecoRoutines_W-selection_WJets_madgraph_June2010.root");
  //TFile *file1 = TFile::Open("results/" + folder + "/RecoRoutines_W-selection_WJets_sherpa.root");
  TFile *file2 = TFile::Open("results/hltmu9_goodevsel/RecoRoutines_W-selection_QCD_AllPtBins_7TeV_Pythia.root");
  TFile *file3 = TFile::Open("results/" + folder + "/RecoRoutines_W-selection_ZJets_madgraph_June2010.root");
  //TFile *file4 = TFile::Open("results/MuPt10/RecoRoutines_W-selection_TTbarJets_tauola_madgraph_June2010.root");

  //dynamic array size not allowed in CINT hehe
  TCanvas *canvas [4] = {makeCanvas("reco_wpt"), makeCanvas("muon_pt"), makeCanvas("pf_mt"), makeCanvas("lpvar")};
  TLegend *legend [4] = {makeLegend(), makeLegend(), makeLegend(), makeLegend()};
  TString plotnames[4] = {"RECO_PolPlots_50toinf/RECO_pfMHT", 
			  "RECO_PolPlots_50toinf/RECO_MuonPt", 
			  "RECO_PolPlots_50toinf/RECO_pfMT", 
			  "RECO_PolPlots_50toinf/RECO_ICVarPF"};
  
  TString plotlabels_m [4] = {"RECO P_{T}(W-) [GeV]", "P_{T}(#mu^{-}) [GeV]", "M_{T}- [GeV]", "LP(#mu^{-})"};
  TString plotlabels_p [4] = {"RECO P_{T}(W+) [GeV]", "P_{T}(#mu^{+}) [GeV]", "M_{T}+ [GeV]", "LP(#mu^{+})"};
  int rbinextra [4] = {2,4,2,4};
  double xmin_m [4] = {50., 20., 30., -0.5};
  double xmin_p [4] = {50., 20., 30., -0.5};
  double xmax_m [4] = {200., 170., 150., 1.5};
  double xmax_p [4] = {200., 170., 150., 1.5};
  double ymax_m [4] = {1500., 1200., 1500., 800.};
  double ymax_p [4] = {2000., 2000., 2000., 1200.};
  int skip [4] = {0,0,0,0};

  for(unsigned int i=0; i<numPlots; i++) {
    if(skip[i] == 0) {
      TH1D * data_p = (TH1D*)file0->Get(TString(plotnames[i]+"Plus"));
      TH1D * data_m = (TH1D*)file0->Get(TString(plotnames[i]+"Minus"));
      TH1D * w_p = (TH1D*)file1->Get(TString(plotnames[i]+"Plus"));
      TH1D * w_m = (TH1D*)file1->Get(TString(plotnames[i]+"Minus"));
      TH1D * qcd_p = (TH1D*)file2->Get(TString(plotnames[i]+"Plus"));
      TH1D * qcd_m = (TH1D*)file2->Get(TString(plotnames[i]+"Minus"));
      TH1D * z_p = (TH1D*)file3->Get(TString(plotnames[i]+"Plus"));
      TH1D * z_m = (TH1D*)file3->Get(TString(plotnames[i]+"Minus"));
      //TH1D * tt = (TH1D*)file4->Get(plotnames[i]);

    w_p->Rebin(rbin*rbinextra[i]);
    w_m->Rebin(rbin*rbinextra[i]);
    qcd_p->Rebin(rbin*rbinextra[i]);
    qcd_m->Rebin(rbin*rbinextra[i]);
    z_p->Rebin(rbin*rbinextra[i]);
    z_m->Rebin(rbin*rbinextra[i]);
    //tt->Rebin(rbin);
    data_p->Scale(data_scale);
    data_m->Scale(data_scale);
    data_p->Rebin(rbin*rbinextra[i]);
    data_m->Rebin(rbin*rbinextra[i]);

    w_p->Scale(w_scale);
    w_m->Scale(w_scale);
    z_p->Scale(z_scale);
    z_m->Scale(z_scale);
    //tt->Scale(lumi_scale);
    qcd_p->Scale(qcd_scale);
    qcd_m->Scale(qcd_scale);

    TH1D * mc_p = (TH1D*)qcd_p->Clone();
    mc_p->Add(w_p);
    mc_p->Add(z_p);
    mc_p->SetLineWidth(3);
    mc_p->SetLineColor(kGray);
    qcd_p->SetLineColor(kGreen);
    qcd_p->SetLineWidth(2);
    qcd_p->GetXaxis()->SetRangeUser(xmin_p[i],xmax_p[i]);
    qcd_p->GetXaxis()->SetTitle(plotlabels_p[i]);
    qcd_p->GetXaxis()->SetTitleSize(0.06);
    qcd_p->GetXaxis()->SetLabelSize(0.05);
    qcd_p->GetYaxis()->SetRangeUser(0.1,ymax_p[i]);
    qcd_p->GetYaxis()->SetTitle("Events / 35 pb^{-1}");
    qcd_p->GetYaxis()->SetTitleSize(0.06);
    qcd_p->GetYaxis()->SetTitleOffset(1.19);
    qcd_p->GetYaxis()->SetLabelSize(0.05);
    canvas[i]->cd(1);//->SetLogy();
    qcd_p->DrawCopy("h");
    w_p->SetLineColor(kBlue);
    w_p->SetLineWidth(2);
    w_p->DrawCopy("sameh");
    z_p->SetLineColor(kRed);
    z_p->SetLineWidth(2);
    z_p->DrawCopy("sameh");

    mc_p->DrawCopy("sameh");
    data_p->SetMarkerStyle(20);
    data_p->DrawCopy("samep");

    legend[i]->AddEntry(data_p, "7TeV Data", "p");
    legend[i]->AddEntry(mc_p, "All MC", "l");
    legend[i]->AddEntry(w_p, "W+Jets", "l");
    legend[i]->AddEntry(z_p, "Z+Jets", "l");
    legend[i]->AddEntry(qcd_p, "QCD", "l");
    legend[i]->DrawClone();

    TH1D * mc_m = (TH1D*)qcd_m->Clone();
    mc_m->Add(w_m);
    mc_m->Add(z_m);
    //mc->Add(tt);
    mc_m->SetLineWidth(3);
    //mc->SetLineStyle(9);
    mc_m->SetLineColor(kGray);
    qcd_m->SetLineColor(kGreen);
    qcd_m->SetLineWidth(2);
    qcd_m->GetXaxis()->SetRangeUser(xmin_m[i],xmax_m[i]);
    qcd_m->GetXaxis()->SetTitle(plotlabels_m[i]);
    qcd_m->GetXaxis()->SetTitleSize(0.06);
    qcd_m->GetXaxis()->SetLabelSize(0.05);
    qcd_m->GetYaxis()->SetRangeUser(0.1,ymax_m[i]);
    qcd_m->GetYaxis()->SetTitle("Events / 35 pb^{-1}");
    qcd_m->GetYaxis()->SetTitleSize(0.06);
    qcd_m->GetYaxis()->SetTitleOffset(1.19);
    qcd_m->GetYaxis()->SetLabelSize(0.05);
    canvas[i]->cd(2);//->SetLogy();
    qcd_m->DrawCopy("h");
    w_m->SetLineColor(kBlue);
    w_m->SetLineWidth(2);
    w_m->DrawCopy("sameh");
    z_m->SetLineColor(kRed);
    z_m->SetLineWidth(2);
    z_m->DrawCopy("sameh");

    mc_m->DrawCopy("sameh");
    data_m->SetMarkerStyle(20);
    data_m->DrawCopy("samep");
    //tplus->DrawClone("same");

    if(doPrint) canvas[i]->Print(".png");
    }
  }
  file2->Close();
  file1->Close();
  file0->Close();
  return;

}
Esempio n. 21
0
//----------------------------------------//
// Plot the peak of a few values
//----------------------------------------//
void plotPeakComp()
{

  // Make Canvas
  TCanvas* c = makeCanvas("c");
  c->SetLogy();
  //c->SetLogx();

  // G4 and ZHS plots
  TString g4pname = "A_AntNum_0_pos_827.371_0_561.656";
  TString zhspname = "VP_avg_55.829616";

  // Specify the G4 plots
  TString g4dir = "efieldroot/";
  vector<TString> g4files;
  g4files.push_back(g4dir+"Output_50Evt_1GeV_1Prim_HardCodedAntenna_R1000m_newV.root");
  g4files.push_back(g4dir+"Output_50Evt_10GeV_1Prim_HardCodedAntenna_R1000m_newV.root");
  g4files.push_back(g4dir+"Output_50Evt_100GeV_1Prim_HardCodedAntenna_R1000m_newV.root");
  g4files.push_back(g4dir+"Output_20Evt_1TeV_1Prim_HardCodedAntenna_R1000m_newV.root");
  //g4files.push_back(g4dir+"Output_20Evt_10TeV_1Prim_HardCodedAntenna_R1000m_newV.root");

  // Specify the G4 plots
  TString zhsdir = "../ZHS_ELSEnergy/rootfiles/";
  vector<TString> zhsfiles;
  zhsfiles.push_back(zhsdir+"beam1e3MeV_1Prim_50NEvt_Angular.root");
  zhsfiles.push_back(zhsdir+"beam10e3MeV_1Prim_50NEvt_Angular.root");
  zhsfiles.push_back(zhsdir+"beam100e3MeV_1Prim_50NEvt_Angular.root");
  zhsfiles.push_back(zhsdir+"beam1e6MeV_1Prim_20NEvt_Angular.root");


  // What energies correspond to file [GeV]
  vector<double> NRG;
  NRG.push_back(1);
  NRG.push_back(10);
  NRG.push_back(100);
  NRG.push_back(1000);
  NRG.push_back(10000);

  // Specify some histogram shiz
  TString xtitle = "log(Energy/GeV)";
  TString ytitle = "Max(A) [Vm/s]";
  TH1F* frame = makeHist("frame",1,-1,5,xtitle,ytitle,kBlack,20);

  // Now loop over files and get points
  int npoints = 0;
  double E[1000];
  double g4_max[1000];
  double zhs_max[1000];
  double maximum = -999;
  for(unsigned int i=0; i<g4files.size(); ++i){

    // Store energy 
    E[i] = log10(NRG.at(i));

    // Get G4 result
    TFile* f_g4 = new TFile(g4files.at(i).Data());
    TProfile* prof = getProfile(f_g4, g4pname,"","",kBlack,20);
    //g4_max[i] = prof->GetMaximum();
    g4_max[i] = getMax(prof);
    if( maximum < g4_max[i] ) maximum = g4_max[i];

    // Get G4 result
    TFile* f_zhs = new TFile(zhsfiles.at(i).Data());
    TProfile* prof = getProfile(f_zhs, zhspname,"","",kBlack,20);
    //zhs_max[i] = prof->GetMaximum() / 1000.;
    //zhs_max[i] = prof->GetMaximum() /1000. ;
    zhs_max[i] = getMax(prof) / 1000.;
    if( maximum < zhs_max[i] ) maximum = zhs_max[i];

    // Increment points
    npoints++;

  }

  // Make TGraph
  TGraph* gr_g4 = new TGraph(npoints, E, g4_max);
  gr_g4->SetLineWidth(1);
  gr_g4->SetMarkerSize(1);
  gr_g4->SetMarkerStyle(20);
  gr_g4->SetLineColor(kBlue);
  gr_g4->SetMarkerColor(kBlue);

  // Make TGraph
  TGraph* gr_zhs = new TGraph(npoints, E, zhs_max);
  gr_zhs->SetLineWidth(1);
  gr_zhs->SetMarkerSize(1);
  gr_zhs->SetMarkerStyle(20);
  gr_zhs->SetLineColor(kRed);
  gr_zhs->SetMarkerColor(kRed);

  // Draw graph
  frame->SetMaximum(5*maximum);
  frame->SetMinimum(1e-5*maximum);
  frame->Draw();
  gr_g4->Draw("samelp");
  gr_zhs->Draw("samelp");

  // Add some legend
  TLegend* leg = makeLegend(0.2,0.4,0.8,0.9);
  leg->AddEntry(gr_g4,"Geant4","lp");  
  leg->AddEntry(gr_zhs,"ZHS","lp");
  leg->Draw("same");

}
Esempio n. 22
0
void Zselection() {
  TLatex *tplus = labelLatex(0.20,0.80,"7 TeV Data");
  gROOT->SetStyle("Plain"); 
  gStyle->SetOptStat(0);
  gStyle->SetPalette(1);
  //the correct W x-sec to use is 31314, c.f. 24170, 30380
  double w_scale = 35.0;//(31314.0 / 24170.0) * 3.2;
  double z_scale = w_scale;
  double qcd_scale = 14./1000.0;
  double data_scale = 1.;
  unsigned int rbin = 5;
  unsigned int numPlots = 11;
  bool doPrint = false;

  TString folder = "hltmu15_goodevsel/Zselection";

  TFile *file0 = TFile::Open("results/" + folder + "/RecoRoutines_Z-selection_realdata.root");
  TFile *file1 = TFile::Open("results/" + folder + "/RecoRoutines_Z-selection_WJets_madgraph_June2010.root");
  //TFile *file1 = TFile::Open("results/" + folder + "/RecoRoutines_W-selection_WJets_sherpa.root");
  //TFile *file2 = TFile::Open("results/" + folder + "/RecoRoutines_W-selection_QCD_AllPtBins_7TeV_Pythia.root");
  TFile *file3 = TFile::Open("results/" + folder + "/RecoRoutines_Z-selection_ZJets_madgraph_June2010.root");
  //TFile *file4 = TFile::Open("results/MuPt10/RecoRoutines_W-selection_TTbarJets_tauola_madgraph_June2010.root");

  //dynamic array size not allowed in CINT hehe
  TCanvas *canvas [11] = {makeCanvas("reco_wpt_plus"), makeCanvas("reco_wpt_minus"), makeCanvas("reco_wpt"), makeCanvas("muon_pt_plus"), makeCanvas("muon_pt_minus"), makeCanvas("muon_pt"), makeCanvas("pf_mt_plus"), makeCanvas("pf_mt_minus"), makeCanvas("pf_mt"), makeCanvas("lpvar_plus"), makeCanvas("lpvar_minus")};
  TLegend *legend [11] = {makeLegend(), makeLegend(), makeLegend(), makeLegend(), makeLegend(), makeLegend(), makeLegend(), makeLegend(), makeLegend(), makeLegend(), makeLegend()};

  TString plotnames [11] = {"RECO_PolPlots_50toinf/RECO_pfMHTPlus",
                            "RECO_PolPlots_50toinf/RECO_pfMHTMinus",
                            "RECO_PolPlots_50toinf/RECO_pfMHT", 
                            "RECO_PolPlots_50toinf/RECO_MuonPtPlus", 
                            "RECO_PolPlots_50toinf/RECO_MuonPtMinus", 
                            "RECO_PolPlots_50toinf/RECO_MuonPt", 
                            "RECO_PolPlots_50toinf/RECO_pfMTPlus",
                            "RECO_PolPlots_50toinf/RECO_pfMTMinus",
                            "RECO_PolPlots_50toinf/RECO_pfMT", 
                            "RECO_PolPlots_50toinf/RECO_ICVarPlus", 
                            "RECO_PolPlots_50toinf/RECO_ICVarMinus"};
  TString plotlabels [11] = {"RECO P_{T}(W+) [GeV]", "RECO P_{T}(W-) [GeV]", "RECO P_{T}(W) [GeV]", "P_{T}(Muon+) [GeV]", "P_{T}(Muon-) [GeV]", "P_{T}(Muon) [GeV]", "M_{T}+ [GeV]", "M_{T}- [GeV]", "M_{T} [GeV]", "LP(+)", "LP(-)"};
  int rbinextra [11] = {2,2,2,4,4,4,2,2,2,4,4};
  double xmin [11] = {50., 50., 50., 0., 0., 0., 30., 30., 30., -0.5, -0.5};
  double xmax [11] = {120., 120., 120., 140., 140., 140., 90., 90., 90., 1.5, 1.5};
  double ymax [11] = {170., 150., 300., 150., 100., 250., 160., 130., 260., 150., 80.};
  int skip [11] = {0,0,0,0,0,0,0,0,0,0,0};


  for(unsigned int i=0; i<numPlots; i++) {
    if(skip[i] == 0) {
    TH1D * data = (TH1D*)file0->Get(plotnames[i]);
    TH1D * w = (TH1D*)file1->Get(plotnames[i]);
    //TH1D * qcd = (TH1D*)file2->Get(plotnames[i]);
    TH1D * z = (TH1D*)file3->Get(plotnames[i]);
    //TH1D * tt = (TH1D*)file4->Get(plotnames[i]);

    w->Rebin(rbin*rbinextra[i]);
    //qcd->Rebin(rbin*rbinextra[i]);
    z->Rebin(rbin*rbinextra[i]);
    //tt->Rebin(rbin);
    data->Scale(data_scale);
    data->Rebin(rbin*rbinextra[i]);

    w->Scale(w_scale);
    z->Scale(z_scale);
    //tt->Scale(lumi_scale);
    //qcd->Scale(qcd_scale);

    TH1D * mc = (TH1D*)w->Clone();
    //mc->Add(w);
    mc->Add(z);
    //mc->Add(tt);
    mc->SetLineWidth(3);
    //mc->SetLineStyle(9);
    mc->SetLineColor(kGray);
    //qcd->SetLineColor(kGreen);
    //qcd->SetLineWidth(2);
    //qcd->GetXaxis()->SetRangeUser(xmin[i],xmax[i]);
    //qcd->GetXaxis()->SetTitle(plotlabels[i]);
    //qcd->GetXaxis()->SetTitleSize(0.05);
    //qcd->GetYaxis()->SetRangeUser(0.1,ymax[i]);
    //qcd->GetYaxis()->SetTitle("Events / 2.8 pb^{-1}");
    //qcd->GetYaxis()->SetTitleSize(0.05);
    //qcd->GetYaxis()->SetTitleOffset(1.36);
    canvas[i]->cd(1);//->SetLogy();
    //qcd->DrawCopy("h");
    w->SetLineColor(kBlue);
    w->SetLineWidth(2);
    w->DrawCopy("h");
    z->SetLineColor(kRed);
    z->SetLineWidth(2);
    z->DrawCopy("sameh");
    //tt->SetLineColor(kGold);
    //tt->SetLineWidth(2);
    //tt->DrawCopy("sameh");

    mc->DrawCopy("sameh");
    data->SetMarkerStyle(20);
    data->DrawCopy("samep");
    //tplus->DrawClone("same");
    legend[i]->AddEntry(data, "7TeV Data", "p");
    legend[i]->AddEntry(mc, "All MC", "l");
    legend[i]->AddEntry(w, "W+Jets", "l");
    legend[i]->AddEntry(z, "Z+Jets", "l");
    //legend[i]->AddEntry(qcd, "QCD", "l");
    legend[i]->DrawClone();

    data->Divide(mc);
    canvas[i]->cd(2);
    data->GetXaxis()->SetRangeUser(xmin[i], xmax[i]);
    data->GetXaxis()->SetTitleSize(0.05);
    data->GetXaxis()->SetTitle(plotlabels[i]);
    data->GetYaxis()->SetTitle("Data / MC");
    data->GetYaxis()->SetTitleSize(0.05);
    data->GetYaxis()->SetTitleOffset(1.36);
    data->DrawCopy();

    if(doPrint) canvas[i]->Print(".png");
    }
  }
  //file2->Close();
  file1->Close();
  file0->Close();
  return;

}
Esempio n. 23
0
//--- function to draw histograms ---
void drawNormHist(TH1* h, const char* opt="", const char* title="", const char* xtitle = "", const char* ytitle = "", const double norm = 1, bool log = false, const int lc=0, const int ls=0, const int lw=0, const int msz=0, const int mst=0)
{
   setHist(h,lc,ls,lw,msz,mst,norm,xtitle,ytitle);
   makeCanvas(Form("normalized_%s",h->GetName()),title, log,opt);
   h->Draw(opt);
}
Esempio n. 24
0
//----------------------------------------//
// Plot ZHS and G4 on same figure
//----------------------------------------//
void plot(vector<TString> f_zhs,
	  vector<TString> f_g4,
	  TString p_zhs,
	  TString p_g4,
	  vector<TString> savenames)
{

  // Make canvas
  TCanvas* c = makeCanvas("c");
  c->SetLogy();

  // Make a legend
  TLegend* leg = makeLegend(0.15,0.3,0.8,0.92);  

  // Titles
  TString xtitle = "time [ns]";
  TString ytitle = "A [Vs/m]";    

  // Loop and get plots
  TProfile* prof_Z = NULL;
  TProfile* prof_G = NULL;
  TH1D* h_resestZ  = NULL;
  for(unsigned int i=0; i<f_zhs.size(); ++i){

    // Load ZHS profile
    TFile* file_Z = new TFile(f_zhs.at(i).Data());
    prof_Z = getProfile(file_Z, p_zhs, xtitle, ytitle, kBlue, 20);
    prof_Z->SetDirectory(0);
    file_Z->Close();
    leg->AddEntry(prof_Z,"ZHS","lep");

    // Load Geant profile
    TFile* file_G = new TFile(f_g4.at(i).Data());
    prof_G = getProfile(file_G, p_g4, xtitle, ytitle, kRed, 20);
    prof_G->SetDirectory(0);
    file_G->Close();
    leg->AddEntry(prof_G,"Geant4","lep");
    
    // Scale Geant4 profile up by factor of R
    //prof_G->Scale(m_R);
    
    // reset the zhs timing info
    //prof_Z = resetZHS(prof_Z, prof_G, kBlue, m_R);
    h_resetZ = resetZHS(prof_Z, prof_G, kBlue, m_R);

    // Get maximum
    float maximum = prof_G->GetMaximum();
    if( maximum < h_resetZ->GetMaximum() )
      maximum = h_resetZ->GetMaximum();
    prof_G->SetMaximum(maximum*5);
    prof_G->SetMinimum(maximum*1e-5);

    // Now plot
    prof_G->Draw();
    //prof_Z->Draw("sameep");
    h_resetZ->Draw("sameep");
    leg->Draw("same");
    //prof_G->Draw("same");

    if(m_save){
      //TString save = m_savedir + p_g4 + "_ZHSCherAngle.png";
      TString save = m_savedir + savenames.at(i) + ".png";
      c->SaveAs(save.Data());

      delete c;
      delete h_resetZ;
      delete leg;

    }

  }// end loop over files


}
Esempio n. 25
0
//---------------------------------------//
// Main
//---------------------------------------//
void PlotBeamProfile()
{

  // Generic things
  TCanvas* c = makeCanvas("c");  
  c->SetTopMargin(0.1);
  c->SetRightMargin(0.15);

  // Files to include
  vector<TString> fnames;
  fnames.push_back("beamProfile/Gauss.txt");
  fnames.push_back("beamProfile/Flat.txt");

  // Titles to add
  vector<TString> titles;
  titles.push_back("Gaussian #sigma = 3.5");
  titles.push_back("Uniform radius = 3.5");

  // Save names
  vector<TString> savenames;
  savenames.push_back("gauss");
  savenames.push_back("flat");

  // Histogram object
  TH2F* h = NULL;

  // Loop over
  for(unsigned int i=0; i<fnames.size(); ++i){
    
    // Make hist
    h = makeHist2("hist",100,-10,10,100,-10,10,"x [mm]","y [mm]","Entries/bin");
  
    double x = 0;
    double y = 0;
    ifstream input (fnames.at(i).Data());
  
    double prev = -9999;
    while( !input.eof() ){
    
      input >> x >> y;
    
      if( x == prev ) continue;
      prev = x;
    
      h->Fill(x,y);

    }// end loop over file

    
    // Draw
    h->SetTitle(titles.at(i).Data());
    h->Draw("colz");

    // Save
    c->SaveAs((m_savedir + savenames.at(i) + ".png").Data());
    delete h;
    input.close();

  }// end loop over files

}