Classes | Functions
rootgINukeVal.C File Reference
#include <iostream>
#include <fstream>
#include <sstream>
#include <list>
#include <TMath.h>
#include <TCanvas.h>
#include <TError.h>
#include <TTree.h>
#include <string>
#include <TCollection.h>
#include <TNtuple.h>
#include <vector>
#include <typeinfo>
#include <genieStyle.C>

Go to the source code of this file.

Classes

class  DataFile
 
class  FormatFile
 

Functions

string trim (string in)
 
int rootgINukeVal (char *fFile, char *dataDir=".", char *ROOTDir=".", char *saveDir=".")
 

Function Documentation

int rootgINukeVal ( char *  fFile,
char *  dataDir = ".",
char *  ROOTDir = ".",
char *  saveDir = "." 
)

Definition at line 458 of file rootgINukeVal.C.

References genie::units::A, FormatFile::binFactor, canMan::cans, DataFile::color, DataFile::cols, convert(), om::cout, DataFile::cut, DataFile::dataTree, DataFile::dataTuple, DataFile::dcth, allTimeWatchdog::endl, FormatFile::fetchGTitle(), DataFile::filename, novadaq::HexUtils::format(), update_sam_good_runs_metadata::good, hist1, calib::j, leg1, FormatFile::logx, FormatFile::logy, FormatFile::makeDataFile(), FormatFile::mtitle, num, FormatFile::numOfType(), FormatFile::process(), FormatFile::savename, gen_flatrecord::size, compareCafs::tFile, DataFile::title, FormatFile::type, DataFile::valid(), FormatFile::xl, FormatFile::xu, y1, FormatFile::yl, and FormatFile::yu.

459 {
460  string tFile (fFile);
461  string dDir (dataDir);
462  int legendSize; //counting entries in legend
463  float TextSize, y1; //adjusted font size and lower bound on legend
465  TCanvas* cans;
466  set_root_env();
467  size_t curRecord=1;
468  bool doCurrent = false;
469  doCurrent = format.process(curRecord);
470  if(doCurrent == false){
471  //This if statement shouldn't be necessary, but if it
472  // isn't here, the while loop tries to execute anyways...
473  cout<<"Format File not found"<<endl;
474  return 0;
475  }
476  while(doCurrent == true){
477  cout<<format.numOfType("GENIE")<<" root files and "<<format.numOfType("EXPERIMENTAL")<<" published data files "<<endl;
478 
479  int legendSize = format.numOfType("GENIE") + format.numOfType("EXPERIMENTAL");
480  stringstream convert;
481  //gStyle->SetErrorX(0);
482  //gStyle->SetStyle(genieStyle);
483  set_root_env();
484  Double_t size = 0;
485  Int_t num = 0;
486  Int_t target = 0;
487  Int_t A = 0;
488  Double_t factor = 0;
489  TH1F* htemp = 0;
490  bool good = false;
491  //gROOT->SetStyle("T2K");
492 
493  //the FormatFile class holds the graph limits as strings, converting here
494  Double_t xl, yl, xu, yu;
495  convert.str(format.xl); convert.clear();
496  convert >> xl;
497  convert.str(format.yl); convert.clear();
498  convert >> yl;
499  convert.str(format.xu); convert.clear();
500  convert >> xu;
501  convert.str(format.yu); convert.clear();
502  convert >> yu;
503 
504  //Creating a new canvas and setting some parameters
505  string canName;
506  canName.assign(curRecord,'*');
507  cans= new TCanvas(canName.c_str(),format.fetchGTitle().c_str());
508  cans->cd();
509  TPad* curP = gPad;
510  if(format.logx==true){gPad->SetLogx(1);}
511  if(format.logy==true){gPad->SetLogy(1);}
512 
513  TextSize = .035;
514  y1 = 1.05-(.075*legendSize);//1, .075
515 
516  TLegend* leg1 = new TLegend(.52,y1,1,1,"");//.6
517  leg1->SetTextSize(TextSize);
518  //TLegend* leg1 = new TLegend(.6,.8,1,1,"");
519 
520  //Get the frame, set parameters, redraw frame
521  TH1F* hf1 = (TH1F*) cans->DrawFrame(xl,yl,xu,yu);
522  hf1->SetTitle(format.mtitle.c_str());
523  if(format.type.compare("Angle")==0){
524  hf1->GetXaxis()->SetTitle("cos(#theta)");
525  hf1->GetYaxis()->SetTitle("#frac{d#sigma}{d#Omega} [#frac{mb}{sr}]");
526  }
527  else if(format.type.compare("Momentum")==0){
528  hf1->GetXaxis()->SetTitle("Momentum [Mev]");
529  hf1->GetYaxis()->SetTitle("#frac{d#sigma}{dp} [#frac{mb}{MeV}]");
530  }
531  else if(format.type.compare("XS")==0){
532  hf1->GetXaxis()->SetTitle("Energy [MeV]");
533  hf1->GetYaxis()->SetTitle("#sigma (mb)");
534  }
535  else{
536  hf1->GetXaxis()->SetTitle("Energy [MeV]");
537  hf1->GetYaxis()->SetTitle("#frac{d#sigma}{d#OmegadE} [#frac{mb}{sr#upointMev}]");
538  }
539  //hf1->GetXaxis()->SetNdivisions(-50202);
540  hf1->GetYaxis()->CenterTitle();
541  hf1->Draw();
542 
543 
544  //Loop over each GINUKE file, scaling and drawing each
545  int numRoots = format.numOfType("GENIE");
546  int k;
547  int markerStyle=20;
548 
549 
550  for(k=0;k<numRoots;k++){
551  DataFile* simData = format.makeDataFile(k,ROOTDir,"GENIE");
552  if(format.type.compare("XS")==0){
553  cans->cd();
554  //Do things completely differently
555  int curCol = simData->color;
556  simData->dataTuple->SetMarkerColor(curCol);
557  simData->dataTuple->SetMarkerStyle(markerStyle);
558  markerStyle++;
559  simData->dataTuple->SetLineStyle(2);//2
560  simData->dataTuple->SetLineColor(curCol);
561  cout<<"About to draw tuple"<<endl;
562  //simData->dataTuple->Draw();
563  cout<<simData->cut.c_str()<<endl;
564  simData->dataTuple->Draw(simData->cut.c_str(),"","line psame L");
565  leg1->AddEntry(simData->dataTuple,simData->title.c_str(),"P");
566  cout<<"Tuple drawn"<<endl;
567  }
568  else{
569  TCanvas* tempVas = new TCanvas("tempName","No title");
570  tempVas->cd();
571  //TPad* curP = gPad;
572  string newCut = simData->cut;
573  newCut = newCut +"&&"+simData->cols+"<="+format.xu;
574  newCut = newCut + "&&"+simData->cols+">"+format.xl;
575  simData->dataTree->Draw(simData->cols.c_str(),newCut.c_str(), "L");
576  //tempVas is used in order to not clobber cans's htemp
577  if(simData->valid()){
578 
579  //Grab the associated histogram from tempVas, apply scaling factor
580  htemp = (TH1F*) gPad->GetPrimitive("htemp");
581  TH1F* hist1;
582  TH1F* hist1error;
583  good=false;
584  //Make sure that something actually existed in the cut
585  if (htemp != 0x0) {
586  good=true;
587  hist1 = (TH1F*) htemp->Clone("hist1");
588  size = hist1->GetBinWidth(1);
589  hist1->Sumw2();
590  hist1->Rebin(format.binFactor);
591  num = simData->dataTree->GetEntries();
592  simData->dataTree->SetBranchAddress("tgt",&target);
593  simData->dataTree->GetEntry(1);
594  A = (target/10) - (target/10000)*1000;
595  factor = TMath::Power(3*1.4*TMath::Power(A,(1.0/3.0)),2)*10.0/(2*num*simData->dcth);
596  hist1->Scale(factor,"width");
597  int curCol = simData->color;
598  hist1->SetMarkerColor(curCol);
599  hist1->SetMarkerStyle(markerStyle);
600  markerStyle++;
601  hist1->SetLineStyle(2);
602  hist1->SetLineColor(curCol);
603  }
604  else{
605  cout<<"Nothing was found in the cut of "<<simData->filename<<endl;
606  }
607  if(good){
608  //Draw a copy of histogram to cans on top of any other histograms already there
609  cans->cd();
610  //TPad* curP = gPad;
611  leg1->AddEntry(hist1,simData->title.c_str());
612  hist1->DrawCopy("e1 psame");//e1 psame
613  hist1->Draw("hist l same");
614 
615  //make and draw an extra histogram to have solid error bars
616  hist1error = (TH1F*) hist1->Clone("hist1error");
617  hist1error->SetLineStyle(1);
618  hist1error->DrawCopy("e1 same");
619  }
620  }
621  else{
622  cout<<"Something is wrong with data file "<<simData->filename<<endl;
623  cans->cd();
624  }
625  tempVas->Close();
626  }
627  }
628 
629  //Draw all of the Experimental files, I'm pretty sure that this will only handle
630  // the simple tree type generated from the .txt type data files.
631  cans->cd();
632  TPad* curP = gPad;
633  int numFiles = format.numOfType("EXPERIMENTAL");
634 
635  /*
636  int j = 0;
637 
638  for(j=0;j<3;j++){
639  DataFile* experimental = format.makeDataFile(0,dDir,"EXPERIMENTAL");
640  TGraphErrors* data1;
641  if(format.type.compare("XS")==0){
642  experimental->dataTuple->Draw(experimental->cut.c_str(),"","goff");
643  data1 = new TGraphErrors(experimental->dataTuple->GetSelectedRows(),experimental->dataTuple->GetV1(), experimental->dataTuple->GetV2(),experimental->dataTuple->GetV3(),experimental->dataTuple->GetV4());
644  }
645  else{
646  experimental->dataTree->Draw(experimental->cols.c_str(),"","goff");
647  data1 = new TGraphErrors(experimental->dataTree->GetSelectedRows(),experimental->dataTree->GetV2(), experimental->dataTree->GetV1(),0,experimental->dataTree->GetV3());
648  }
649  //data1->SetLineStyle(0);
650  data1->SetMarkerColor(experimental->color);
651  data1->SetMarkerStyle(markerStyle);
652  markerStyle++;
653  leg1->AddEntry(data1,experimental->title.c_str(),"P");
654  data1->Draw("p same");
655  }
656  */
657 
658  for(j=0;j<numFiles;j++){
659  DataFile* experimental = format.makeDataFile(j,dDir,"EXPERIMENTAL");
660  TGraphErrors* data1;
661  if(format.type.compare("XS")==0){
662  experimental->dataTuple->Draw(experimental->cut.c_str(),"","goff");
663  data1 = new TGraphErrors(experimental->dataTuple->GetSelectedRows(),experimental->dataTuple->GetV1(), experimental->dataTuple->GetV2(),experimental->dataTuple->GetV3(),experimental->dataTuple->GetV4());
664  }
665  else{
666  experimental->dataTree->Draw(experimental->cols.c_str(),"","goff");
667  data1 = new TGraphErrors(experimental->dataTree->GetSelectedRows(),experimental->dataTree->GetV2(), experimental->dataTree->GetV1(),0,experimental->dataTree->GetV3());
668  }
669  data1->SetLineStyle(3);
670  data1->SetMarkerColor(experimental->color);
671  data1->SetMarkerStyle(markerStyle);
672  markerStyle++;
673  leg1->AddEntry(data1,experimental->title.c_str(),"P");
674  data1->Draw("p same");
675  }
676 
677 
678  //Draw the legend
679 
680  //set_root_env();
681  leg1->SetLineWidth(2);
682  leg1->Draw();
683 
684  //add_plot_label("THIS IS A TEST #alpha #Alpha#gamma", .5, .5, .05);
685 
686  //Save the record
687  string saveName(saveDir);
688  saveName = saveName+"/"+format.savename+".png";
689  cans->SaveAs(saveName.c_str());
690 
691  //Try to find the next record
692  curRecord++;
693  cout<<"\nLooking for next record:"<<endl;
694  doCurrent = format.process(curRecord);
695  }
696  cout<<"No more records found, exiting"<<endl;
697  //delete [] entryArray;
698  return 0;
699 }
bool valid()
Definition: rootgINukeVal.C:96
const XML_Char * target
Definition: expat.h:268
Float_t y1[n_points_granero]
Definition: compare.C:5
string cols
Definition: rootgINukeVal.C:83
TLegend * leg1
Definition: plot_hist.C:105
string cut
Definition: rootgINukeVal.C:85
void convert(std::string dir="cc_numu/C12")
Definition: convert.C:107
float dcth
Definition: rootgINukeVal.C:86
TH1D * hist1
Definition: plotHisto.C:9
string title
Definition: rootgINukeVal.C:82
TNtuple * dataTuple
Definition: rootgINukeVal.C:99
const double j
Definition: BetheBloch.cxx:29
std::string format(const int32_t &value, const int &ndigits=8)
Definition: HexUtils.cpp:14
list cans
Definition: canMan.py:12
TTree * dataTree
Definition: rootgINukeVal.C:98
OStream cout
Definition: OStream.cxx:6
static const double A
Definition: Units.h:82
int num
Definition: f2_nu.C:119
string filename
Definition: rootgINukeVal.C:80
string trim ( string  in)