Exemple #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());
}
Exemple #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());
}
Exemple #3
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());

}
Exemple #4
0
KJS::Value KstBindLegend::curves(KJS::ExecState *exec) const {
  KstViewLegendPtr d = makeLegend(_d);
  if (d) {
    KstReadLocker rl(d);
    return KJS::Object(new KstBindCurveCollection(exec, d));
  }
  return KJS::Null();
}
Exemple #5
0
KJS::Value KstBindLegend::textColor(KJS::ExecState *exec) const {
  KstViewLegendPtr d = makeLegend(_d);
  if (d) {
    KstReadLocker rl(d);
    return KJSEmbed::convertToValue(exec, d->foregroundColor());
  }
  return KJSEmbed::convertToValue(exec, QColor());
}
Exemple #6
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());
  
  
}
Exemple #7
0
KJS::Value KstBindLegend::vertical(KJS::ExecState *exec) const {
  Q_UNUSED(exec)
  KstViewLegendPtr d = makeLegend(_d);
  if (d) {
    KstReadLocker rl(d);
    return KJS::Boolean(d->vertical());
  }
  return KJS::Boolean(false);
}
Exemple #8
0
KJS::Value KstBindLegend::title(KJS::ExecState *exec) const {
  Q_UNUSED(exec)
  KstViewLegendPtr d = makeLegend(_d);
  if (d) {
    KstReadLocker rl(d);
    return KJS::String(d->title());
  }
  return KJS::Undefined();
}
Exemple #9
0
KJS::Value KstBindLegend::fontSize(KJS::ExecState *exec) const {
  Q_UNUSED(exec)
  KstViewLegendPtr d = makeLegend(_d);
  if (d) {
    KstReadLocker rl(d);
    return KJS::Number(d->fontSize());
  }
  return KJS::Number(0);
}
Exemple #10
0
KJS::Value KstBindLegend::font(KJS::ExecState *exec) const {
  Q_UNUSED(exec)
  KstViewLegendPtr d = makeLegend(_d);
  if (d) {
    KstReadLocker rl(d);
    return KJS::String(d->fontName());
  }
  return KJS::String();
}
Exemple #11
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");

}
Exemple #12
0
void KstBindLegend::setTitle(KJS::ExecState *exec, const KJS::Value& value) {
  if (value.type() != KJS::StringType) {
    return createPropertyTypeError(exec);
  }
  KstViewLegendPtr d = makeLegend(_d);
  if (d) {
    KstWriteLocker wl(d);
    d->setTitle(value.toString(exec).qstring());
    KstApp::inst()->paintAll(KstPainter::P_PAINT);
  }
}
Exemple #13
0
void KstBindLegend::setTextColor(KJS::ExecState *exec, const KJS::Value& value) {
  QVariant cv = KJSEmbed::convertToVariant(exec, value);
  if (!cv.canCast(QVariant::Color)) {
    return createPropertyTypeError(exec);
  }
  KstViewLegendPtr d = makeLegend(_d);
  if (d) {
    KstWriteLocker rl(d);
    d->setForegroundColor(cv.toColor());
    KstApp::inst()->paintAll(KstPainter::P_PAINT);
  }
}
Exemple #14
0
void KstBindLegend::setFontSize(KJS::ExecState *exec, const KJS::Value& value) {
  unsigned int i = 0;
  if (value.type() != KJS::NumberType || !value.toUInt32(i)) {
    return createPropertyTypeError(exec);
  }
  KstViewLegendPtr d = makeLegend(_d);
  if (d) {
    KstWriteLocker wl(d);
    d->setFontSize(i);
    KstApp::inst()->paintAll(KstPainter::P_PAINT);
  }
}
Exemple #15
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"));

}
Exemple #16
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


	       
}
Exemple #17
0
KJS::Value KstBindLegend::removeCurve(KJS::ExecState *exec, const KJS::List& args) {
  if (args.size() != 1) {
    return createSyntaxError(exec);
  }

  KstBaseCurvePtr curve;
  curve = extractVCurve(exec, args[0], false);
  if (curve) {
    KstViewLegendPtr d = makeLegend(_d);
    if (d) {
      KstWriteLocker wl(d);
      d->removeCurve(curve);
      KstApp::inst()->paintAll(KstPainter::P_PAINT);
    }
  } else {
    return createTypeError(exec, 0);
  }

  return KJS::Undefined();
}
Exemple #18
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

	       
}
Exemple #19
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);

}
Exemple #20
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


}
Exemple #21
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;

}
Exemple #22
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


}
Exemple #23
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");

}
Exemple #24
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;

}