コード例 #1
0
ファイル: treegraph.C プロジェクト: bdorney/TurboSoftware
void treegraph(TString filename) {
   gROOT->SetStyle("Plain");
   gStyle->SetOptDate();


   Double_t x, y;
   Int_t nlines = 0;
   TFile *f = new TFile("graph.root","RECREATE");

   TCanvas *canvas_graph = new TCanvas("canvas_graph", "y vs x",467,89,400,700);

   TTree t;
   t.ReadFile(filename,"x:y");
   t.Draw("x:y","","goff");

   TGraph *g = new TGraph(t.GetSelectedRows(),t.GetV1(),t.GetV2());
   g->SetTitle(filename+": Y vs X");
   g->GetXaxis()->SetTitle("x[a.u.]");
   g->GetYaxis()->SetTitle("y[a.u.]");

   g->SetMarkerStyle(21);
   g->Draw("AP");

   f->Write();
}
コード例 #2
0
/*
 * The Ferromagnet_Scan function reads in
 * a data file of magentic field scans
 * from within the ferromagnet and returns
 * a graph of the magnetic permeability
 * of the ferromagnet vs the external field
 * provided by the Helmholtz coil.
 */
TGraphErrors* plot_uvB(
			 const TString scan_file,
			 TF1* calib_fit,
			 double R,
			 double R_sig
)
{

  /*Read in Data File to ROOT Tree*/
  cout<< "processing file " << scan_file <<endl;
  TTree *TData = new TTree();
  TData->ReadFile(scan_file, "t/D:I:B");
  /*Use TTree Draw command to write branches to usable arrays*/
  int n = TData->Draw("I:TMath::Abs(B):0.0:0.005", "", "goff");

  vector<double> B_ext, B_in, Bratio, u;
  for(int i = 0; i < n; i++)
    {
      B_ext.push_back( calib_fit->Eval(TData->GetV1()[i]) );
      B_in.push_back( TData->GetV2()[i] );
      Bratio.push_back( B_in[i] / B_ext[i]);
      u.push_back( (Bratio[i]*(R**2) + Bratio[i] - 2 - 2*sqrt((Bratio[i]**2)*(R**2) - Bratio[i]*(R**2) - Bratio[i] + 1 ) ) / (Bratio[i]*(R**2) - Bratio[i]) );

    }

  TGraphErrors *g_uvB = new TGraphErrors(n, &B_ext[0], &u[0], TData->GetV3(), TData->GetV4());

  /*  
  g_uvB->Fit("pol1", "", "", 10, 60);
  cout << "Permeability at 50: " << g_uvB->GetFunction("pol1")->Eval(50) << endl;
  cout << "Permeability at 40: " << g_uvB->GetFunction("pol1")->Eval(40) << endl;
  cout << "Permeability at 30: " << g_uvB->GetFunction("pol1")->Eval(30) << endl;
  */
  return g_uvB;
}
コード例 #3
0
makePlot_check_all()
{

  gStyle->SetOptStat(0);

  vector< TString > v_infile;
  //  v_infile.push_back( TString("output/fitResults_run001_1layer_sheath.root") );
  //  v_infile.push_back( TString("output/fitResults_run002_1layer_sheath.root") );
  v_infile.push_back( TString("output/fitResults_run003_1layer_sheath.root") );
  v_infile.push_back( TString("output/fitResults_run004_2layer_sheath.root") );
  v_infile.push_back( TString("output/fitResults_run005_2layer_sheath.root") );
  v_infile.push_back( TString("output/fitResults_run006_3layer_sheath.root") );
  v_infile.push_back( TString("output/fitResults_run007_4layer_sheath.root") );
  v_infile.push_back( TString("output/fitResults_run008_2layer_cylinder.root") );
  v_infile.push_back( TString("output/fitResults_run009_2layer_cylinder.root") );
  //  v_infile.push_back( TString("output/fitResults_run010_1layer_sheath.root") );
  v_infile.push_back( TString("output/fitResults_run011_1layer_sheath.root") );
  v_infile.push_back( TString("output/fitResults_run012_1layer_sheath.root") );
  v_infile.push_back( TString("output/fitResults_run013_1layer_sheath.root") );
  v_infile.push_back( TString("output/fitResults_run014_1layer_sheath.root") );
  v_infile.push_back( TString("output/fitResults_run015_1layer_sheath.root") );
  v_infile.push_back( TString("output/fitResults_run016_1layer_sheath.root") );
  v_infile.push_back( TString("output/fitResults_run017_2layer_sheath.root") );
  v_infile.push_back( TString("output/fitResults_run018_1layer_sheath.root") );
  v_infile.push_back( TString("output/fitResults_run019_1layer_sheath.root") );
  v_infile.push_back( TString("output/fitResults_run020_1layer_sheath.root") );
  v_infile.push_back( TString("output/fitResults_run021_1layer.root") );
  for ( unsigned f = 0; f < v_infile.size(); f++ )
    {
      cout << "Plot " << v_infile.at(f) << endl;

      TCanvas *c0 = new TCanvas();

      TFile *fin = new TFile( v_infile.at(f) );
      TTree *tin = (TTree*)fin->Get("fitResults");
      tin->Draw("bshield:bext:bshield_err:bext_err");

      TGraphErrors *gshield = new TGraphErrors( tin->GetEntries(), tin->GetV2(), tin->GetV1(), tin->GetV4(), tin->GetV3() );
      gshield->SetTitle(v_infile.at(f));
      gshield->GetXaxis()->SetTitle("B_{ext} [mT]");
      gshield->GetYaxis()->SetTitle("B_{shield} [mT]");

      gshield->Draw("AP");

      fin->Close();

      if ( f == 0 )
        c0->Print("plot_check_all.ps(");
      else if ( f == v_infile.size() - 1 )
        c0->Print("plot_check_all.ps)");
      else
        c0->Print("plot_check_all.ps");

    }



}
コード例 #4
0
/*
 * The Calibration function reads in the
 * calibration file and returns a graph
 * that is used to find the relation
 * between current and magentic field
 * for the Helmholtz coil.
 */
TF1* Calibrate(
		    const char* f_calib
		    )
{
  /*Read in Calibration File*/
  cout<< "processing file " << f_calib <<endl;
  TTree *TCalib = new TTree();
  TCalib->ReadFile(f_calib, "t/D:I:B");
  int n = TCalib->Draw("I:TMath::Abs(B)", "", "goff");
  TGraph *g_calib = new TGraph(n, TCalib->GetV1(), TCalib->GetV2() );
  g_calib->SetTitle("");
  // g_calib->Draw("AP");
  g_calib->Fit("pol1", "q");
  TF1* calib_fit = g_calib->GetFunction("pol1");

  return calib_fit;

}
コード例 #5
0
TGraphErrors* plot_ramp(
			 const TString scan_file,
			 double R,
			 double R_sig
)
{

  /*Read in Data File to ROOT Tree*/
  cout<< "processing file " << scan_file <<endl;
  TTree *TData = new TTree();
  TData->ReadFile(scan_file, "t/D:x:y:z:B1:B1Range:B2:B2Range:B3:B3Range:V:T1:T2:T3:T4:T5:T6:T7:T8");
  /*Use TTree Draw command to write branches to usable vector*/
  int n = TData->Draw("TMath::Abs(B2):TMath::Abs(B3):0.0:0.005", "", "goff");

  vector<double> B_ext, B_in, Bratio, u, u_err;
  for(int i = 0; i < n; i++)
    {
  //     if(i == 0)
  //     {
  //     	B_ext.push_back(100.00);
  //     }
  //     else{
  //     	  B_ext.push_back( TData->GetV1()[i]);
  //     }
      B_ext.push_back( TData->GetV1()[i] );
      B_in.push_back( TData->GetV2()[i]);
      // B_in.push_back( 90.53);
      // if(TMath::Abs(B_in[i]) <= TMath::Abs(B_ext[i]))
      // {
	Bratio.push_back( B_in[i] / B_ext[i]);
	u.push_back( (Bratio[i]*(R**2) + Bratio[i] - 2 - 2*sqrt((Bratio[i]**2)*(R**2) - Bratio[i]*(R**2) - Bratio[i] + 1 ) ) / (Bratio[i]*(R**2) - Bratio[i]) );
	// u_err.push_back( u[i]*( 5.5*((0.005/Bratio[i])**2.) + 10*((R_sig/R)**2.)  )**0.5 );
	u_err.push_back( 0.01 );
	// u_err.push_back( u[i]*( 5.5*((0.01/Bratio[i])**2.))  )**0.5 );
	// }
      }

  TGraphErrors *g_uvB = new TGraphErrors(n, &B_ext[0], &u[0], TData->GetV3(), &u_err[0]);

  return g_uvB;
}
コード例 #6
0
int evaluate( std::string filelist, std::string outfile )
{
  gStyle->SetOptStat(0);

  TCanvas *ctemp = new TCanvas();

  TCanvas *cres = new TCanvas("TimeDependence");
  TH1F* hres = new TH1F("hres","",100,0,650);
  hres->GetYaxis()->SetRangeUser(0,50);
  hres->SetTitle("");
  hres->GetXaxis()->SetTitle("time (s)");
  hres->GetYaxis()->SetTitle("B_{int} (mT)");
  hres->Draw();
  leg = new TLegend(0.2,0.6,0.9,0.9);
//  leg->SetHeader("The Legend Title"); // option "C" allows to center the header
  leg->SetNColumns(5);

  vector< double > v_Bint;
  vector< double > v_BintErr;
  vector< double > v_Bext;
  vector< double > v_BextErr;

  /* Loop over all lines in input file */
  std::ifstream infilelist(filelist);
  std::string line;

  unsigned colorcounter=38;

  while (std::getline(infilelist, line))
  {
    // skip lines with '#' and empty lines
    if ( line.find("#") != string::npos )
      {
        cout << "Skip line " << line << endl;
        continue;
      }

    if ( line == "" )
      continue;

    //cout << "Processing file " << line << endl;


    TString infilename("data_calib/");
    infilename.Append(line);

    TFile *fin = new TFile( infilename );
    TTree *tin = (TTree*)fin->Get("t");

    ctemp->cd();
    tin->Draw("Bi:time");
    TGraph *gtime = new TGraph(tin->GetEntries(), &(tin->GetV2()[0]), &(tin->GetV1()[0]));
    gtime->SetLineColor(colorcounter);
    colorcounter++;

    TH1F* hBext = new TH1F("hBext","",100,0,1000);
    tin->Draw("Bo >> hBext");

    cres->cd();
    gtime->Draw("lsame");

    double Bext_i = hBext->GetMean();
    double BextErr_i = hBext->GetRMS();

    double Bint_i = gtime->Eval(590);
    double BintErr_i = 0;

    /* add legend entry */
    TString legname("B_ext ~ ");
    legname += (int)Bext_i;
    leg->AddEntry(gtime,legname,"l");

    cout << "B_ext: " << Bext_i << " \t B_int: " << Bint_i << endl;

    v_Bint.push_back(Bint_i);
    v_BintErr.push_back(BintErr_i);
    v_Bext.push_back(Bext_i);
    v_BextErr.push_back(BextErr_i);

  }

  cres->cd();
  leg->Draw();

  TGraphErrors *gfinal = new TGraphErrors(v_Bext.size(), &(v_Bext[0]), &(v_Bint[0]), &(v_BextErr[0]), &(v_BintErr[0]));
  gfinal->Sort();
  gfinal->SetName("Bint_Vs_Bext");
  gfinal->SetTitle("");
  gfinal->GetXaxis()->SetTitle("B_{ext} (mT)");
  gfinal->GetYaxis()->SetTitle("B_{int} (mT)");

  TCanvas *cfinal = new TCanvas();
  gfinal->Draw("APL");

  /* Save output graph */
  TString outfilename("output/");
  outfilename.Append(outfile);
  TFile *fout = new TFile(outfilename,"RECREATE");

  cres->Write();
  gfinal->Write();

  fout->Close();

  /* Write result to txt output file */
  TString outfilenametxt = outfilename;
  outfilenametxt.ReplaceAll(".root",".txt");

  ofstream foutxt;
  foutxt.open( outfilenametxt );
  foutxt <<  "# Bo sig_Bo Bi sig_Bi shield sig_shield sf sig_sf time_dependent" << endl;

  for ( int i = 0; i < gfinal->GetN(); i++ )
  {
    double Bo = gfinal->GetX()[i];
    double sig_Bo = gfinal->GetEX()[i];
    double Bi = gfinal->GetY()[i];
    double sig_Bi = gfinal->GetEY()[i];
    double shield = 0;
    double sig_shield = 0;
    double sf = 0;
    double sig_sf = 0;
    double time_dependent = 0;

    foutxt <<  Bo << " " << sig_Bo << " " << Bi << " " << sig_Bi << " "
         << shield << " " << sig_shield << " " << sf << " " << sig_sf
         << " " << time_dependent << endl;
  }

  return 0;
}
コード例 #7
0
ファイル: make_scatterplot.c プロジェクト: bth5032/CMS
/*#include "TTree.h"
#include "TCanvas.h"
#include "TGraph.h"
#include "TMultiGraph.h"
#include "TRint.h"
#include <time.h>
#include <stdio.h>

const short MaxNN = 6;
*/
void make_scatterplot(TString data_file, TString plot_name, TString header)
{
	//TApplication program = new TRInt(); 
	//pull in data
	TTree *t = new TTree(); 
	t->ReadFile(data_file);
	t->SetName("t");
	
	//TString name = "run2.png";
	TCanvas *BG = new TCanvas("c1", "Read Velocity on Local Disk for CMS3 Files", 1920, 1080);
	BG->cd();
	TPad *c = new TPad("MainPad", "My main pad", 0, 0, 1, 0.9);
	c->Draw();
	c->Divide(2,2);

	//In first slot have Time vs. Buffer for 1 Concurrent Read
	c->cd(1);
	int n1 = t->Draw("VelocityMBps:BufferSize", "ConcurrentReads==1", "goff");
	TGraph *ghist1 = new TGraph(n1, t->GetV2(), t->GetV1());
	ghist1->SetName("ghist1");
	ghist1->SetMarkerStyle(3);
	ghist1->SetMarkerColor(1);
	ghist1->SetTitle("Single File Read");
	ghist1->GetXaxis()->SetTitle("Buffer Size (Bytes)");
	ghist1->GetYaxis()->SetTitle("Read Velocity (MB/s)");
	ghist1->Draw("ap");
	
	//In second slot have Time vs. Buffer for 3 Concurrent Reads
	c->cd(2);
	int n2 = t->Draw("VelocityMBps:BufferSize", "ConcurrentReads==3", "goff");
	TGraph *ghist2 = new TGraph(n2, t->GetV2(), t->GetV1());
	Double_t DP2x[n2], DP2y[n2];
	ghist2->SetName("ghist2");
	ghist2->SetMarkerStyle(3);
	ghist2->SetMarkerColor(1);
	ghist2->SetTitle("3 Concurrent Reads");
	ghist2->GetXaxis()->SetTitle("Buffer Size (Bytes)");
	ghist2->GetYaxis()->SetTitle("Read Velocity (MB/s)");
	ghist2->Draw("ap");
	
	//In third slot have Time vs. Buffer for 3 Concurrent Reads
	c->cd(3);
	int n3 = t->Draw("VelocityMBps:BufferSize", "ConcurrentReads==6", "goff");
	TGraph *ghist3 = new TGraph(n3, t->GetV2(), t->GetV1());
	Double_t DP3x[n3], DP3y[n3];
	ghist3->SetName("ghist3");
	ghist3->SetMarkerStyle(3);
	ghist3->SetMarkerColor(1);
	ghist3->SetTitle("6 Concurrent Reads");
	ghist3->GetXaxis()->SetTitle("Buffer Size (Bytes)");
	ghist3->GetYaxis()->SetTitle("Read Velocity (MB/s)");
	ghist3->Draw("ap");
	
	//In fourth slot have Time vs. Buffer for 10 Concurrent Reads
	c->cd(4);
	int n4 = t->Draw("VelocityMBps:BufferSize", "ConcurrentReads==10", "goff");
	TGraph *ghist4 = new TGraph(n4, t->GetV2(), t->GetV1());
	ghist4->SetMarkerStyle(3);
	ghist4->SetName("ghist4");
	ghist4->SetMarkerColor(1);
	ghist4->SetTitle("10 Concurrent Reads");
	ghist4->GetXaxis()->SetTitle("Buffer Size (Bytes)");
	ghist4->GetYaxis()->SetTitle("Read Velocity (MB/s)");
	ghist4->Draw("ap");
	
	//Draw to screen
	//Initialize Canvas
	
	c->cd(0);
	c->Draw();
	
	BG->cd();
	TText *title = new TText(.5,.95, header);
	title->SetTextAlign(22);
	title->Draw();
	
	gDirectory->Add(ghist1);
	gDirectory->Add(ghist2);
	gDirectory->Add(ghist3);
	gDirectory->Add(ghist4);
	gDirectory->Add(t);
	gPad->SaveAs(plot_name);
}
コード例 #8
0
ファイル: spTree.C プロジェクト: kalanand/UserCode
void fillGraphFromTreeVar(std::string& treedrawspec,int index,wGraph_t *&pwg)
{
  // Sample treedrawspec:
  // mytree:"TDCwinstart[%d]:runnum","evtnum==1","P"
  //
  vector<string> v_tokens;
  string tid;
  TString drawspec;
  Tokenize(treedrawspec,v_tokens,":",true);
  if( (v_tokens.size() < 2) ||
      (!v_tokens[0].size())  ||
      (!v_tokens[2].size())    ) {
    cerr << "malformed root tree draw spec treeid:\"varexp\",\"selection\",option: " << treedrawspec << endl;
    return;
  }

  tid = v_tokens[0];
  for (size_t i=2; i<v_tokens.size(); i++) {
    drawspec += v_tokens[i];
  }
  int fmtcnt = drawspec.CountChar('%');

  if (fmtcnt) { // use index for tree array var
    switch(fmtcnt) {
    case 1: drawspec = Form(drawspec,index); break;
    case 2: drawspec = Form(drawspec,index,index); break;
    case 3: drawspec = Form(drawspec,index,index,index); break;
    case 4: drawspec = Form(drawspec,index,index,index,index); break;
    case 5: drawspec = Form(drawspec,index,index,index,index,index); break;
    case 6: drawspec = Form(drawspec,index,index,index,index,index,index); break;
    default:
      cerr << "More than six fmt specifiers in drawspec found, fix me! " << drawspec <<endl;
      exit(-1);
    }
  }
  if( gl_verbose)
    cout<<"drawspec="<<drawspec<<endl;

  TTree *tree = findTree(tid);
  assert (tree);

  // can't use comma as delimiter since histo with binning spec may be supplied
  TObjArray *tokens = drawspec.Tokenize("\"");
  TString hname;

  TString varexp = ((TObjString *)(*tokens)[0])->GetString();

  if( gl_verbose)
    cout<<"varexp="<<varexp<<endl;
  switch(tokens->GetEntriesFast()) {
  case 1:
    tree->Draw(varexp,"","goff");
    break;
  case 3:
    {
      TString cut = ((TObjString *)(*tokens)[2])->GetString();
      tree->Draw(varexp,cut,"goff"); 
    }
    break;
  case 4: // assume the cut string is blank
    {
      TString gopt = ((TObjString *)(*tokens)[3])->GetString();
      gopt = gopt + " goff";
      tree->Draw(varexp,"",gopt);
    }
    break;
  case 5:
    {
      TString cut  = ((TObjString *)(*tokens)[2])->GetString();
      TString gopt = ((TObjString *)(*tokens)[4])->GetString();
      gopt = gopt + " goff";
      tree->Draw(varexp,cut,gopt);
    }
    break;
  default:
    cerr << "malformed root tree draw spec treeid:varexp,selection,option";
    for (int i=0; i<tokens->GetEntriesFast(); i++)
      cerr << i<<": "<< ((TObjString *)(*tokens)[i])->GetString() << " ";
    cerr << endl;
    break;
  }

  assert(tree->GetSelectedRows());

  if (!pwg)
    pwg = new wGraph_t();

  assert(pwg);
  pwg->gr = new TGraph(tree->GetSelectedRows(),
		       tree->GetV2(), tree->GetV1());

}                                                // fillGraphFromTreeVar
コード例 #9
0
int
plot_compare_fun4all_eicroot()
{
  /**** Chose input files ****/
  /* File with IR mangets configuration*/
  TString fname_irmag("example/proton-magnets-250GeV-opt2.dat");
  /* File with Fun4All output*/
  TString fname_fun4all("example/eRHIC_proton-magnets-250GeV-opt2_250GeV_0mrad.root");
  /* File with EICROOT output*/
  TString fname_eicroot("example/eicroot-track_proton-magnets-250GeV-opt2_250GeV_0mrad.txt");

  /* Open iput file with trajectories from GEANT4 */
  TFile *fin = new TFile(fname_fun4all);

  /* Get tree from file */
  TTree *tin = (TTree*)fin->Get("T");

  int nhits = 0;
  tin->SetBranchAddress("n_G4HIT_FWDDISC",&nhits);

  /* create graph of particle trajectory */
  /* Use only first event (for now) */
  tin->GetEntry(0);
  cout << "hits: " << nhits << endl;

  tin->Draw("G4HIT_FWDDISC.x:G4HIT_FWDDISC.z","Entry$==0","");

  TGraph* g1 = new TGraph(nhits*2, &(tin->GetV2()[0]), &(tin->GetV1()[0]));
  g1->SetMarkerStyle(7);
  g1->SetMarkerSize(1);
  g1->SetMarkerColor(kRed);

  /* Get tree from file */
  TTree *tin2 = new TTree();
  tin2->ReadFile(fname_eicroot,"x/F:y:z");

  int nhits = tin2->GetEntries();
  tin2->Draw("x:z","","");

  TGraph* g2 = new TGraph(nhits, &(tin2->GetV2()[0]), &(tin2->GetV1()[0]));
  g2->SetMarkerStyle(7);
  g2->SetMarkerSize(1);
  g2->SetMarkerColor(kGreen+1);

  /* Create frame histogram for plot */
  TH1F *h1 = new TH1F("h1","",10,0,15000);
  h1->GetXaxis()->SetRangeUser(0,5000);
  h1->GetYaxis()->SetRangeUser(-50,70);
  h1->GetXaxis()->SetTitle("Z(cm)");
  h1->GetYaxis()->SetTitle("X(cm)");

  /* Plot frame histogram */
  TCanvas *c1 = new TCanvas();
  h1->Draw("AXIS");

  /* Read IR configuration file- this needs to go somewhere else using parameters and a .root file to store them */
  ifstream irstream(fname_irmag);

  if(!irstream.is_open())
    {
      cout << "ERROR: Could not open IR configuration file " << fname_irmag << endl;
      return -1;
    }

  while(!irstream.eof()){
    string str;
    getline(irstream, str);
    if(str[0] == '#') continue; //for comments
    stringstream ss(str);

    string name;
    double center_z, center_x, center_y, aperture_radius, length, angle, B, gradient;

    ss >> name >> center_z >> center_x >> center_y >> aperture_radius >> length >> angle >> B >> gradient;

    if ( name == "" ) continue; //for empty lines

    // convert units from m to cm
    center_x *= 100;
    center_y *= 100;
    center_z *= 100;
    aperture_radius *= 100;
    length *= 100;

    // define magnet outer radius
    float outer_radius = 30.0; // cm

    //flip sign of dipole field component- positive y axis in Geant4 is defined as 'up',
    // positive z axis  as the hadron-going direction
    // in a right-handed coordinate system x,y,z
    B *= -1;

    // convert angle from millirad to rad
    angle = (angle / 1000.);

    // Place IR component
    cout << "New IR component: " << name << " at z = " << center_z << endl;

    string volname = "IRMAGNET_";
    volname.append(name);

    /* Draw box for magnet position on canvas */
    TPolyLine *b1 = TraceBox( angle, center_z, center_x, length, aperture_radius, outer_radius ); //upper box
    TPolyLine *b2 = TraceBox( angle, center_z, center_x, length, -1 * aperture_radius, -1 * outer_radius ); //lower box

    if(B != 0 && gradient == 0.0){
      //dipole magnet
      b1->SetFillColor(kOrange+1);
      b2->SetFillColor(kOrange+1);
    }
    else if( B == 0 && gradient != 0.0){
      //quad magnet
      b1->SetFillColor(kBlue+1);
      b2->SetFillColor(kBlue+1);
    }
    else{
      //placeholder magnet
      b1->SetFillColor(kGray+1);
      b2->SetFillColor(kGray+1);
    }
    b1->Draw("Fsame");
    b2->Draw("Fsame");
  }

  /* draw particle trajectory */
  g2->Draw("LPsame");
  g1->Draw("LPsame");

  return 0;
}
コード例 #10
0
plot_stability_mean(){

  gStyle->SetOptStat(0);

  TTree *tfit = new TTree();
  tfit->ReadFile("pi0peak_fit_Run13pp510ERT_reformat.txt","run_index/F:run_number:nevents:sector:mean:dmean:sigma:dsigma:chisquare");

  TTree *tfit_raw = new TTree();
  tfit_raw->ReadFile("pi0peak_fit_raw_Run13pp510ERT_reformat.txt","run_index/F:run_number:nevents:sector:mean:dmean:sigma:dsigma:chisquare");

  TLine *lpi0 = new TLine( 0, 0.137, tfit->GetEntries("sector==0"), 0.137 );
  lpi0->SetLineColor(kRed);

  // frame
  TH1F* hframe = new TH1F("hframe","",875,0,875);
  hframe->GetYaxis()->SetRangeUser(0.12,0.16);
  hframe->GetXaxis()->SetTitle("run");
  hframe->GetYaxis()->SetTitle("mean [GeV]");
  hframe->SetLineColor(kWhite);

  // sectors PbSc-West
  tfit->Draw("mean:run_index:dmean","sector==0");
  TGraphErrors *g_mean_PbScW = new TGraphErrors( tfit->GetEntries("sector==0"), tfit->GetV2(), tfit->GetV1(), 0, tfit->GetV3());

  tfit_raw->Draw("mean:run_index:dmean","sector==0");
  TGraphErrors *g_mean_PbScW_raw = new TGraphErrors( tfit_raw->GetEntries("sector==0"), tfit_raw->GetV2(), tfit_raw->GetV1(), 0, tfit_raw->GetV3());

  // sectors PbSc-East
  tfit->Draw("mean:run_index:dmean","sector==1");
  TGraphErrors *g_mean_PbScE = new TGraphErrors( tfit->GetEntries("sector==1"), tfit->GetV2(), tfit->GetV1(), 0, tfit->GetV3());

  tfit_raw->Draw("mean:run_index:dmean","sector==1");
  TGraphErrors *g_mean_PbScE_raw = new TGraphErrors( tfit_raw->GetEntries("sector==1"), tfit_raw->GetV2(), tfit_raw->GetV1(), 0, tfit_raw->GetV3());

  // sectors PbGl-East
  tfit->Draw("mean:run_index:dmean","sector==2");
  TGraphErrors *g_mean_PbGlE = new TGraphErrors( tfit->GetEntries("sector==2"), tfit->GetV2(), tfit->GetV1(), 0, tfit->GetV3());

  tfit_raw->Draw("mean:run_index:dmean","sector==2");
  TGraphErrors *g_mean_PbGlE_raw = new TGraphErrors( tfit_raw->GetEntries("sector==2"), tfit_raw->GetV2(), tfit_raw->GetV1(), 0, tfit_raw->GetV3());


  // Plotting
  TCanvas *c_PbScW = new TCanvas();
  hframe->Draw();
  g_mean_PbScW->Draw("Psame");
  lpi0->Draw("same");
  c_PbScW->Print("plots-escale-check/mpi0_mean_PbScW.png");

  TCanvas *c_PbScW_raw = new TCanvas();
  hframe->Draw();
  g_mean_PbScW_raw->Draw("Psame");
  lpi0->Draw("same");
  c_PbScW_raw->Print("plots-escale-check/mpi0_mean_PbScW_raw.png");

  TCanvas *c_PbScE = new TCanvas();
  hframe->Draw();
  g_mean_PbScE->Draw("Psame");
  lpi0->Draw("same");
  c_PbScE->Print("plots-escale-check/mpi0_mean_PbScE.png");

  TCanvas *c_PbScE_raw = new TCanvas();
  hframe->Draw();
  g_mean_PbScE_raw->Draw("Psame");
  lpi0->Draw("same");
  c_PbScE_raw->Print("plots-escale-check/mpi0_mean_PbScE_raw.png");

  TCanvas *c_PbGlE = new TCanvas();
  hframe->Draw();
  g_mean_PbGlE->Draw("Psame");
  lpi0->Draw("same");
  c_PbGlE->Print("plots-escale-check/mpi0_mean_PbGlE.png");

  TCanvas *c_PbGlE_raw = new TCanvas();
  hframe->Draw();
  g_mean_PbGlE_raw->Draw("Psame");
  lpi0->Draw("same");
  c_PbGlE_raw->Print("plots-escale-check/mpi0_mean_PbGlE_raw.png");

}
コード例 #11
0
int plot_Fun4All_All_DeltaEta_DeltaPhi()
{
	const std::string inFile = "LeptoAna_1000events_All.root";
	const std::string inDirectory = "/gpfs/mnt/gpfs02/phenix/scratch/jlab/Leptoquark/";
	std::string inputFile = inDirectory+inFile;

	TFile *f = TFile::Open(inputFile.c_str());
	TTree *t = (TTree*)f->Get("ntp_leptoquark");

//	const int Nevent = t->GetMaximum("event");
	const int Nevent = 100;
	cout << "Running " << Nevent << " events" << endl;
	const int Nentries1 = t->Draw("isMaxEnergyJet","(isMaxEnergyJet<10)*(calorimeterid<10)","goff");
		Double_t *arr_jet = t->GetV1();
		vector<int> v_jet(Nentries1);
		for(int i = 0; i < Nentries1; i++)
		{
			v_jet[i] = (int)arr_jet[i];
		}
	const int Nentries = t->Draw("towereta:towerphi:towerenergy:event","(isMaxEnergyJet<10)*(calorimeterid<10)","goff");
		Double_t *arr_eta = t->GetV1();
		Double_t *arr_phi = t->GetV2();
		Double_t *arr_e = t->GetV3();
		Double_t *arr_event = t->GetV4();


	if(Nentries1 != Nentries)
	{
		cerr << "ERROR: Draw commands to not return the same dimensions. Check that your logical expressions are the same." << endl;
		return -1;
	}

	vector<double> v_DeltaEta, v_DeltaPhi, v_DeltaTheta, v_Energy;
	vector<double> v_DeltaEta_j2, v_DeltaPhi_j2, v_DeltaTheta_j2, v_Energy_j2;

	for(int i = 0; i < Nevent; i++)
	{
		double Emax = 0;
		int Emax_i = 0;

		double Emax_j2 = 0;
		int Emax_i_j2 = 0;

		for(int j = 0; j < Nentries; j++)
		{
			if((t->GetV4()[j]-1 == i) && (v_jet[j] == 1))
			{
				if(t->GetV3()[j] > Emax) 
				{
					Emax = t->GetV3()[j];
					Emax_i = j;
				}
			}
			if((t->GetV4()[j]-1 == i) && (v_jet[j] == 2))
			{
				if(t->GetV3()[j] > Emax_j2) 
				{
					Emax_j2 = t->GetV3()[j];
					Emax_i_j2 = j;
				}
			}
		}

		for(int j = 0; j < Nentries; j++)
		{
			if((t->GetV4()[j]-1 == i) && (v_jet[j] == 1))
			{
				v_DeltaEta.push_back(t->GetV1()[j] - t->GetV1()[Emax_i]);
				v_DeltaTheta.push_back(2*TMath::ATan(TMath::Power(TMath::E(),-1*t->GetV1()[j])) - 2*TMath::ATan(TMath::Power(TMath::E(),-1*t->GetV1()[Emax_i])));
				v_DeltaPhi.push_back(t->GetV2()[j] - t->GetV2()[Emax_i]);
				v_Energy.push_back(t->GetV3()[j]);
			}
			if((t->GetV4()[j]-1 == i) && (v_jet[j] == 2))
			{
				v_DeltaEta_j2.push_back(t->GetV1()[j] - t->GetV1()[Emax_i_j2]);
				v_DeltaTheta_j2.push_back(2*TMath::ATan(TMath::Power(TMath::E(),-1*t->GetV1()[j])) - 2*TMath::ATan(TMath::Power(TMath::E(),-1*t->GetV1()[Emax_i_j2])));
				v_DeltaPhi_j2.push_back(t->GetV2()[j] - t->GetV2()[Emax_i_j2]);
				v_Energy_j2.push_back(t->GetV3()[j]);
			}
		}
	}


//-----------------------------------------------------------------------------------------------------------

	gStyle->SetOptStat(0);

	double xmin = -1;
	double xmax = 1;
	double ymin = -0.5;
	double ymax = 0.5;

	std::string title = "isMaxJetEnergy = 1";
	TCanvas *c1 = new TCanvas();
	TH2D *h1 = new TH2D("h1",title.c_str(),40,xmin,xmax,40,ymin,ymax);
	for(int i = 0; (unsigned)i < v_DeltaEta.size(); i++)
	{
		h1->Fill(v_DeltaEta[i],v_DeltaPhi[i], v_Energy[i]/Nevent);
	}
	c1->SetLogz();
	h1->Draw("colz");
//		h1->SetMinimum(1);
//		h1->SetMaximum(1000);
		h1->GetXaxis()->SetTitle("#Delta#eta");
		h1->GetYaxis()->SetTitle("#Delta#phi");
	c1->Update();

//-----------------------------------------------------------------------------------------------------------


	std::string title2 = "isMaxJetEnergy = 2";
	TCanvas *c2 = new TCanvas();
	TH2D *h2 = new TH2D("h2",title2.c_str(),40,xmin,xmax,40,ymin,ymax);
	for(int i = 0; (unsigned)i < v_DeltaEta_j2.size(); i++)
	{
		h2->Fill(v_DeltaEta_j2[i],v_DeltaPhi_j2[i], v_Energy_j2[i]/Nevent);
	}
	c2->SetLogz();
	h2->Draw("colz");
//		h2->SetMinimum(1);
//		h2->SetMaximum(1000);
		h2->GetXaxis()->SetTitle("#Delta#eta");
		h2->GetYaxis()->SetTitle("#Delta#phi");
	c2->Update();


//-----------------------------------------------------------------------------------------------------------


	TCanvas *c3 = new TCanvas();
	TH1D *h3 = h1->ProjectionY();
		h3->SetLineColor(kGreen+3);
	TH1D *h4 = h2->ProjectionY();
		h4->SetLineColor(kBlue);

	TF1 *f3 = new TF1("f3", "gaus", ymin, ymax);
		f3->SetLineColor(kGreen+3);
	h3->Fit("f3","Q R");

	TF1 *f4 = new TF1("f4", "gaus", ymin, ymax);
		f4->SetLineColor(kBlue+2);
	h4->Fit("f4","Q R");

	h3->Draw();
	h4->Draw("SAME");
	TLegend *leg = new TLegend(0.2,0.9,0.7,0.75);
		leg->SetBorderSize(1);
		leg->AddEntry(h3,title.c_str(),"l");
		leg->AddEntry(h4,title2.c_str(),"l");
	leg->Draw("SAME");
	c3->Update();

	cout << endl;
	cout << "*******************************************************" << endl;

	cout << "Ratio of Gaussian Width to Max Energy:" << endl;
	cout << "     for: " << title << " -> " << f3->GetParameter(2) << " / " << h3->GetBinContent(h3->GetMaximumBin()) 
		<< " = " << f3->GetParameter(2) /  h3->GetBinContent(h3->GetMaximumBin()) << endl;
	cout << "     for: " << title2 << " -> " << f4->GetParameter(2) << " / " << h4->GetBinContent(h4->GetMaximumBin()) 
		<< " = " << f4->GetParameter(2) /  h4->GetBinContent(h4->GetMaximumBin()) << endl;
	cout << "     Ratio of ratios: " << (f3->GetParameter(2) /  h3->GetBinContent(h3->GetMaximumBin())) / (f4->GetParameter(2) /  h4->GetBinContent(h4->GetMaximumBin())) << endl;

	cout << "*******************************************************" << endl;
	cout << endl;

	c1->Close();
	c2->Close();
	c3->Close();

//-----------------------------------------------------------------------------------------------------------

	vector<double> v_Ratios;

	for(int i = 0; i < Nevent; i++)
	{
		TH1D *h5 = new TH1D("h5","",20,ymin*2,ymax*2);
		TH1D *h6 = new TH1D("h6","",20,ymin*2,ymax*2);

		for(int j = 0; j < Nentries/100; j++)
		{
			if((t->GetV4()[j]-1 == i) && (v_jet[j] == 1))
			{
				h5->Fill(v_DeltaPhi[j], v_Energy[j]);
			}
			if((t->GetV4()[j]-1 == i) && (v_jet[j] == 2))
			{
				h6->Fill(v_DeltaPhi_j2[j], v_Energy_j2[j]);
			}
		}

		TF1 *f5 = new TF1("f5", "gaus", ymin, ymax);
			f3->SetLineColor(kGreen+3);
		h5->Fit("f5","Q");

		TF1 *f6 = new TF1("f6", "gaus", ymin, ymax);
			f6->SetLineColor(kBlue+2);
		h6->Fit("f6","Q");

		TCanvas *c5 = new TCanvas();
		h5->Draw();

		TCanvas *c6 = new TCanvas();
		h6->Draw();

//		cout << endl;
//		cout << "Ratio of Gaussian Width to Max Energy:" << endl;
//		cout << "     for: " << title << " -> " << f5->GetParameter(2) << " / " << h5->GetBinContent(h5->GetMaximumBin()) 
//			<< " = " << f5->GetParameter(2) /  h5->GetBinContent(h5->GetMaximumBin()) << endl;
//		cout << "     for: " << title2 << " -> " << f6->GetParameter(2) << " / " << h6->GetBinContent(h6->GetMaximumBin()) 
//			<< " = " << f6->GetParameter(2) /  h6->GetBinContent(h6->GetMaximumBin()) << endl;
		cout << "     Ratio of ratios for event " << i+1 << " : " << (f5->GetParameter(2) /  h5->GetBinContent(h5->GetMaximumBin())) /
			 (f6->GetParameter(2) /  h6->GetBinContent(h6->GetMaximumBin())) << endl;

		if((f5->GetParameter(2) /  h5->GetBinContent(h5->GetMaximumBin())) /
                         (f6->GetParameter(2) /  h6->GetBinContent(h6->GetMaximumBin())) != NAN)
		v_Ratios.push_back((f5->GetParameter(2) /  h5->GetBinContent(h5->GetMaximumBin())) /
                         (f6->GetParameter(2) /  h6->GetBinContent(h6->GetMaximumBin())));

		delete h5;
		delete h6;
		c5->Close();
		c6->Close();
	}

	TCanvas *c7 = new TCanvas();
	TH1D *h7 = new TH1D("h7","",400,-200,200);
	for(int i = 0; (unsigned)i < v_Ratios.size(); i++)
	{
		h7->Fill(v_Ratios[i]);
	}
	h7->Draw();









	return 0;
}
コード例 #12
0
ファイル: plot_track_multi.C プロジェクト: kurthill/analysis
int
plot_track_multi()
{

  /* Select input files (output from Fun4All) for plotting
   */
  vector<string> v_filenames;
  v_filenames.push_back( "data/eRHIC_updated-magnets-2017_proton_275GeV_22mrad.root" );
  v_filenames.push_back( "data/eRHIC_updated-magnets-2017_proton_275GeV_27mrad.root" );
  v_filenames.push_back( "data/eRHIC_updated-magnets-2017_proton_275GeV_17mrad.root" );

  TObjArray* graphs = new TObjArray();

  for ( i = 0; i < v_filenames.size(); i++ )
    {
      /* Open iput file with trajectories from GEANT4 */
      TFile *fin = new TFile( v_filenames.at(i).c_str(), "OPEN" );

      /* Get tree from file */
      TTree *tin = (TTree*)fin->Get("T");

      int nhits = 0;
      tin->SetBranchAddress("n_G4HIT_FWDDISC",&nhits);

      /* create graph of particle trajectory */
      /* Use only first event (for now) */
      tin->GetEntry(0);
      cout << "hits: " << nhits << endl;

      tin->Draw("G4HIT_FWDDISC.x:G4HIT_FWDDISC.z","Entry$==0","");

      TGraph* g1 = new TGraph(nhits*2, &(tin->GetV2()[0]), &(tin->GetV1()[0]));
      g1->SetMarkerStyle(7);
      g1->SetMarkerSize(1);

      graphs->Add( g1 );

    }


  /* Create frame histogram for plot */
  TH1F *h1 = new TH1F("h1","",10,0,15000);
  h1->GetXaxis()->SetRangeUser(0,12000);
  h1->GetYaxis()->SetRangeUser(-50,200);
  h1->GetXaxis()->SetTitle("Z(cm)");
  h1->GetYaxis()->SetTitle("X(cm)");

  /* Plot frame histogram */
  TCanvas *c1 = new TCanvas();
  h1->Draw("AXIS");

  /* Read IR configuration file- this needs to go somewhere else using parameters and a .root file to store them */
  string irfile = "data/updated-magnets-2017.dat";
  ifstream irstream(irfile.c_str());

  while(!irstream.eof()){
    string str;
    getline(irstream, str);
    if(str[0] == '#') continue; //for comments
    stringstream ss(str);

    string name;
    double center_z, center_x, center_y, aperture_radius, length, angle, B, gradient;

    ss >> name >> center_z >> center_x >> center_y >> aperture_radius >> length >> angle >> B >> gradient;

    if ( name == "" ) continue; //for empty lines

    // convert units from m to cm
    center_x *= 100;
    center_y *= 100;
    center_z *= 100;
    aperture_radius *= 100;
    length *= 100;

    // define magnet outer radius
    float outer_radius = 30.0; // cm

    //flip sign of dipole field component- positive y axis in Geant4 is defined as 'up',
    // positive z axis  as the hadron-going direction
    // in a right-handed coordinate system x,y,z
    B *= -1;

    // convert angle from millirad to rad
    angle = (angle / 1000.);

    // Place IR component
    cout << "New IR component: " << name << " at z = " << center_z << endl;

    string volname = "IRMAGNET_";
    volname.append(name);

    /* Draw box for magnet position on canvas */
    TPolyLine *b1 = TraceBox( angle, center_z, center_x, length, aperture_radius, outer_radius ); //upper box
    TPolyLine *b2 = TraceBox( angle, center_z, center_x, length, -1 * aperture_radius, -1 * outer_radius ); //lower box

    if(B != 0 && gradient == 0.0){
      //dipole magnet
      b1->SetFillColor(kOrange+1);
      b2->SetFillColor(kOrange+1);
    }
    else if( B == 0 && gradient != 0.0){
      //quad magnet
      b1->SetFillColor(kBlue+1);
      b2->SetFillColor(kBlue+1);
    }
    else{
      //placeholder magnet
      b1->SetFillColor(kGray+1);
      b2->SetFillColor(kGray+1);
    }
    b1->Draw("Fsame");
    b2->Draw("Fsame");
  }

  /* draw particle trajectory */
  for ( int i = 0; i < graphs->GetEntries(); i++ )
    {
      graphs->At(i)->Draw("LPsame");
    }

  c1->Print("multitrack_new.eps");

  return 0;
}
コード例 #13
0
int
TrackParametrization( TString csvfile="fitslices_out.csv" )
{

  /* Read data from input file */
  TTree *tres = new TTree();
  tres->ReadFile( csvfile, "ptrue:etatrue:psig:psig_err:pmean:pmean_err:norm", ',' );

  /* Print read-in tree */
  tres->Print();

  /* colors array */
  unsigned colors[8] = {1,2,3,4,6,7,14,16};

  /* Create vector of theta values to include for visualization*/
  vector< double > etas_vis;
  etas_vis.push_back(-2.75);
  etas_vis.push_back(-2.25);
  etas_vis.push_back(-1.75);
  etas_vis.push_back(-0.25);
  etas_vis.push_back( 0.25);
  etas_vis.push_back( 1.75);
  etas_vis.push_back( 2.25);

//  etas_vis.push_back(-3.25);
//  etas_vis.push_back(-2.25);
//  etas_vis.push_back(-1.25);
//  etas_vis.push_back(-0.25);
//  etas_vis.push_back( 0.25);
//  etas_vis.push_back( 1.25);
//  etas_vis.push_back( 2.25);
//  etas_vis.push_back( 3.25);

  /* Create vector of theta values to include for fitting*/
  vector< double > etas_fit;
  for ( double eta = -4.45; eta < 4.5; eta += 0.1 )
    etas_fit.push_back( eta );

  /* Create fit function */
  TF1* f_momres = new TF1("f_momres", "sqrt( [0]*[0] + [1]*[1]*x*x )" );

  cout << "\nFit function: " << f_momres->GetTitle() << "\n" << endl;

  /* Create scratch canvas */
  TCanvas *cscratch = new TCanvas("cscratch");

  /* Create framehistogram */
  TH1F* hframe = new TH1F("hframe","",100,0,40);
  hframe->GetYaxis()->SetRangeUser(0,0.15);
  hframe->GetYaxis()->SetNdivisions(505);
  hframe->GetXaxis()->SetTitle("Momentum (GeV/c)");
  hframe->GetYaxis()->SetTitle("#sigma_{p}/p");

  /* create combined canvas plot */
  TCanvas *c1 = new TCanvas();
  hframe->Draw();

  /* Create legend */
  TLegend* leg_eta = new TLegend( 0.2, 0.6, 0.5, 0.9);
  leg_eta->SetNColumns(2);

  /* Create ofstream to write fit parameter results */
  ofstream ofsfit("track_momres_new.csv");
  ofsfit<<"eta,par1,par1err,par2,par2err"<<endl;

  /* Create resolution-vs-momentum plot with fits for each selected theta value */
  for ( int i = 0; i < etas_fit.size(); i++ )
    {
      /* Switch to scratch canvas */
      cscratch->cd();

      double eta = etas_fit.at(i);

      /* No tracking outside -4 < eta < 4 */
      if ( eta < -4 || eta > 4 )
	continue;

      cout << "\n***Eta = " << eta << endl;

      /* Define range of theta because float comparison with fixed value doesn't work
	 too well for cuts in ROOT trees */
      double eta_min = eta * 0.999;
      double eta_max = eta * 1.001;

      /* Cut for tree */
      TCut cutx( Form("ptrue > 1 && ( (etatrue > 0 && (etatrue > %f && etatrue < %f)) || (etatrue < 0 && (etatrue < %f && etatrue > %f)) )", eta_min, eta_max, eta_min, eta_max) );

      /* "Draw" tree on scratch canvas to fill V1...V4 arrays */
      tres->Draw("psig:ptrue:psig_err:0", cutx );

      /* Create TGraphErrors with selected data from tree */
      TGraphErrors *gres = new TGraphErrors( tres->GetEntries(cutx),
					     &(tres->GetV2())[0],
					     &(tres->GetV1())[0],
					     &(tres->GetV4())[0],
					     &(tres->GetV3())[0] );

      /* reset function parameters before fit */
      f_momres->SetParameter(0,0.1);
      f_momres->SetParameter(1,0.1);

      /* Only plot pseudorapidities listed on etas_vis; if not plotting, still do the fit */
      bool vis = false;
      int vi = 0;

      for ( vi = 0; vi < etas_vis.size(); vi++ )
	{
	  if ( abs( etas_vis.at(vi) - eta ) < 0.001 )
	    {
	      vis = true;
	      break;
	    }
	}

      if ( vis )
	{
	  /* Add graph to legend */
	  leg_eta->AddEntry(gres, Form("#eta = %.1f", eta), "P");

	  /* Add graph to plot */
	  c1->cd();
	  gres->SetMarkerColor(colors[vi]);
	  gres->Draw("Psame");
	  f_momres->SetLineColor(colors[vi]);
	  gres->Fit(f_momres);
	}
      else
	{
	  gres->Fit(f_momres);
	}

      /* Write fir results to file */
      double par1 = f_momres->GetParameter(0);
      double par1err = f_momres->GetParError(0);
      double par2 = f_momres->GetParameter(1);
      double par2err = f_momres->GetParError(1);
      ofsfit << eta << "," << par1 << "," << par1err << "," << par2 << "," << par2err << endl;

    }

  /* Draw legend */
  c1->cd();
  //TCanvas *c2 = new TCanvas();
  //hframe->Draw();
  leg_eta->Draw();

  /* Print plots */
  c1->Print("track_momres_vareta.eps");
  //c2->Print("track_momres_vareta_legend.eps");

  /* Close output stream */
  ofsfit.close();

  return 0;
}