Example #1
0
File: Draw.C Project: XuQiao/HI
void Draw(){
    gStyle->SetOptStat(kFALSE);
    TFile *f = TFile::Open(Form("Anav3_merged.root"));
    int xbin=0;
    TH2F* hr = (TH2F*)f->Get(Form("D_%d/hr",xbin));
    TH2F* s = (TH2F*)f->Get(Form("D_%d/s",xbin));
    TH2F* b = (TH2F*)f->Get(Form("D_%d/b",xbin));
    TVectorD* vavgtrk = (TVectorD*)f->Get(Form("avgtrk"));
    hr->SetTitle("");
    hr->GetXaxis()->SetRangeUser(-4,4);
    hr->GetYaxis()->SetRangeUser(-1.5,4);
 //   hr->GetZaxis()->SetRangeUser(0,3e6);
    hr->GetXaxis()->SetTitle("#Delta#eta");
    hr->GetXaxis()->CenterTitle();
    hr->GetYaxis()->SetTitle("#Delta#phi");
    hr->GetYaxis()->CenterTitle();
    hr->GetZaxis()->SetTitle("#frac{1}{N_{trig}}#frac{d^{2}N^{pair}}{d#Delta#eta d#Delta#phi}");
    TCanvas *c1 = new TCanvas();
    hr->Draw("surf1");
    TLatex l;
    l.SetNDC();
    l.SetTextSize(0.04);
    l.DrawLatex(0.1,0.9,Form("%d < N_{trk}^{offline} <%d",trkbin[xbin],trkbin[xbin+1]));
    l.DrawLatex(0.5,0.9,Form("Average N_{trk}^{offline} = %.1f",(*vavgtrk)[xbin]));
    l.DrawLatex(0.1,0.85,Form("%.1f < p_{T}^{trig} < %.1f",pttrigmin,pttrigmax));
    l.DrawLatex(0.5,0.85,Form("%.1f < #eta^{trig} < %.1f",etatrigmin,etatrigmax));
    l.DrawLatex(0.1,0.80,Form("%.1f < p_{T}^{ass} < %.1f",ptassmin,ptassmax));
    l.DrawLatex(0.5,0.80,Form("%.1f < #eta^{ass} < %.1f",etaassmin,etaassmax));
    c1->Print("ridgev3.png");
    TCanvas *c2 = new TCanvas();
    s->SetTitle("");
    s->GetXaxis()->SetRangeUser(-4,4);
    s->GetYaxis()->SetRangeUser(-1.5,4);
  //  s->GetZaxis()->SetRangeUser(0,3e6);
    s->GetXaxis()->SetTitle("#Delta#eta");
    s->GetXaxis()->CenterTitle();
    s->GetYaxis()->SetTitle("#Delta#phi");
    s->GetYaxis()->CenterTitle();
    s->GetZaxis()->SetTitle("#frac{1}{N_{trig}}#frac{d^{2}N^{pair}}{d#Delta#eta d#Delta#phi}");
    s->Draw("surf1");
    l.DrawLatex(0.5,0.80,Form("signal"));
    c2->Print("signal_v3.png");
    TCanvas *c3 = new TCanvas();
    b->SetTitle("");
    b->GetXaxis()->SetRangeUser(-4,4);
    b->GetYaxis()->SetRangeUser(-1.5,4);
  //  b->GetZaxis()->SetRangeUser(0,3e9);
    b->GetXaxis()->SetTitle("#Delta#eta");
    b->GetXaxis()->CenterTitle();
    b->GetYaxis()->SetTitle("#Delta#phi");
    b->GetYaxis()->CenterTitle();
    b->GetZaxis()->SetTitle("#frac{1}{N_{trig}}#frac{d^{2}N^{pair}}{d#Delta#eta d#Delta#phi}");
    b->Draw("surf1");
    l.DrawLatex(0.5,0.80,Form("background"));
    c3->Print("background_v3.png");
}
Example #2
0
//------------------------------------------------------------//
// Get 2D histogram
//------------------------------------------------------------//
TH2F* getHist2(TFile* file, TString pname, TString xtitle,
	       TString ytitle, TString ztitle)
{
  
  TH2F* hist = (TH2F*) (file->Get(pname.Data())->Clone());
  hist->GetXaxis()->SetTitle(xtitle.Data());
  hist->GetYaxis()->SetTitle(ytitle.Data());
  hist->GetZaxis()->SetTitle(ztitle.Data());
  hist->SetTitle("");
  hist->SetStats(0);
  hist->GetYaxis()->SetTitleOffset(1.5);
  hist->GetZaxis()->SetTitleOffset(1.);
  hist->SetLineWidth(2);

  return hist;

}
Example #3
0
TH2F *prof2d(TTree *tree, TString var1Name, TString var2Name, TString nllName, TString binning="(40,0,0.05,40,0,0.2)", bool delta=false){

  var1Name.ReplaceAll("-","_");
  var2Name.ReplaceAll("-","_");
  //  tree->Print();
  TString histName="h";
  std::cout << var1Name << "\t" << var2Name << "\t" << histName << std::endl;
  tree->Draw(var1Name+":"+var2Name+">>"+histName+binning);
  TH2F *hEntries = (TH2F*)gROOT->FindObject(histName);
  if(hEntries==NULL) return NULL;
  //std::cerr << "e qui ci sono?" << std::endl;
  tree->Draw(var1Name+":"+var2Name+">>shervin"+binning,nllName);

  TH2F *h = (TH2F*)gROOT->FindObject("shervin");
  if(h==NULL) return NULL;
  h->Divide(hEntries);


  //std::cerr << "io sono qui" << std::endl;    
  delete hEntries;
  Double_t min=1e20, max=0;

  if(delta){
    for(Int_t iBinX=1; iBinX <= h->GetNbinsX(); iBinX++){
      for(Int_t iBinY=1; iBinY <= h->GetNbinsY(); iBinY++){
	Double_t binContent=h->GetBinContent(iBinX, iBinY);
	if(min>binContent && binContent!=0) min=binContent;
	if(max<binContent) max=binContent;
      }
    }
    std::cout << "min=" << min << "\tmax=" << max<<std::endl;    
    for(Int_t iBinX=1; iBinX <= h->GetNbinsX(); iBinX++){
      for(Int_t iBinY=1; iBinY <= h->GetNbinsY(); iBinY++){
	Double_t binContent=h->GetBinContent(iBinX, iBinY);
	//std::cout << binContent << std::endl;
	if(binContent!=0) binContent-=min;
	else binContent=-1;
	h->SetBinContent(iBinX,iBinY,binContent);
      }
    }
  }
  h->GetZaxis()->SetRangeUser(0,500);
  //std::cerr << "io sono qui 3" << std::endl;    
  return h;
//   Double_t variables[2];
//   Double_t nll;
//   tree->SetBranchAddress(var1Name, &(variables[0]));
//   tree->SetBranchAddress(var2Name, &(variables[1]));
//   tree->SetBranchAddress(nllName, &(nll));

  
//   Long64_t nEntries=tree->GetEntries();
//   for(Long64_t jentry=0; jentry<nEntries; jentry++){
    
}
Example #4
0
TH2F *hardlimit(TH2F *limit) {
  TH2F *co = (TH2F*)limit->Clone("hcopy");
  for(int i=1;i<=limit->GetNbinsX();i++) {
    for(int j=1;j<=limit->GetNbinsY();j++) {
       if(limit->GetBinContent(i,j)<1&&limit->GetBinContent(i,j)>0) co->SetBinContent(i,j,1);
       else co->SetBinContent(i,j,0);
    }
  }
  co->GetZaxis()->SetRangeUser(0,100);//this is to make the exclusion shape blue :-)
  return co;
}
Example #5
0
drawMyPlot(TString nom, TString title){
	/*UInt_t Number = 2;
	Double_t Red[2]    = { 1.00, 0.00};
	Double_t Green[2]  = { 1.00, 0.00};
	Double_t Blue[2]   = { 1.00, 1.00};
	Double_t Length[2] = { 0.00, 1.0};
	Int_t nb=50;
	TColor::CreateGradientColorTable(Number,Length,Red,Green,Blue,nb);*/
    
	TH2F *theHisto = (TH2F*) myFile->Get(nom);
	
	TCanvas *c0 = new TCanvas("c0","coucou",600,600);
	c0->SetFillColor(0);
    theHisto->SetTitle(title);
	theHisto->GetXaxis()->SetTitle("#mu_{1} p_{T} (GeV/c)");
	theHisto->GetXaxis()->SetNoExponent();
	theHisto->GetXaxis()->SetMoreLogLabels();
    theHisto->GetYaxis()->SetNoExponent();
	theHisto->GetYaxis()->SetMoreLogLabels();
	theHisto->GetYaxis()->SetTitle("#mu_{2} p_{T} (GeV/c)");
	theHisto->GetZaxis()->SetTitle("");
	theHisto->GetZaxis()->SetLabelSize(0.01);
	theHisto->SetAxisRange(0.5,1.5,"Z");
	theHisto->SetMarkerSize(1.7);
	theHisto->SetMarkerColor(kBlack);
	theHisto->Draw("COLZTEXTE");
    
    /*TLatex t;
    t.SetNDC();
    t.SetTextSize(0.04);
    t.DrawLatex(0.3,0.93,title);*/
	
	//c0->Print("effPlots/"+nom+".pdf");
	
	c0->SetLogy();
	c0->SetLogx();
    c0->Print("SFplots/"+nom+"_log.pdf");
    
	
}
Example #6
0
void QAnalysis::PlotTemperatureDistribution(double qtime, int numPhi, bool scale) {
  int zbin = 60;
  int rbin = 19;
  TH2F*  hist = new TH2F(Form("tempDis%.1f", qtime), Form("tempDis%.1f", qtime), zbin, 0, 60, rbin, 0, 19);
  TTree* tree = ReadTree(file);
  
  for (int i=0; i<tree->GetEntries(); i++) {
    tree->GetEntry(i);
	if ( time==qtime && posID[1]==numPhi ) 
      hist->Fill(posID[0], posID[2], temp);
  }
  
  if (scale==true) hist->GetZaxis()->SetRangeUser(0., GetMaximum("temp"));
  hist->SetTitle(Form("time = %.1f [sec]; Z; R; Temperature [K]", qtime));
  hist->Draw("colz");
}
Example #7
0
drawThePlot(TString nom){
	TH2F *theHisto = (TH2F*) myFile->Get(nom);
	
	TCanvas *c0 = new TCanvas("c0","coucou",600,600);
	c0->SetFillColor(0);
	theHisto->GetXaxis()->SetTitle("muon |#eta|");
	theHisto->GetYaxis()->SetTitle("muon p_{T} (GeV/c)");
	theHisto->GetZaxis()->SetLabelSize(0.02);
	theHisto->SetAxisRange(0.9,1.1,"Z");
	theHisto->Draw("COLZTEXTE");
	c0->SetLogy();
	
	c0->Print("effPlots/"+nom+".png");
	
//c0->Print("effPlots/"+nom+"_log.png");

	
}
Example #8
0
TCanvas *Plot2D_my(TChain *data, TString branchname, TString binning,TString selection,TString opt,TString xLabel, TString yLabel){
  //type == 0: data only
  //type == 1: MC only
  //type == 2: data/MC
   
  TCanvas *c = new TCanvas();
  c->SetRightMargin(0.2);
  //  data->Draw(branchname+">>data_hist"+binning, selection,opt);
  data->Draw(branchname+">>data_hist"+binning,selection,opt);
  TH2F *d = (TH2F *) gROOT->FindObject("data_hist");
  d->GetYaxis()->SetTitle(yLabel);
  d->GetXaxis()->SetTitle(xLabel);
  d->GetZaxis()->SetTitle("Events");
  d->GetZaxis()->SetNdivisions(510);
  d->Draw("colz");

  return c;
}
Example #9
0
File: Draw.C Project: XuQiao/HI
void Draw(){
    gStyle->SetOptStat(kFALSE);
    TFile *f = TFile::Open(Form("correlationSTEG.root"));
    TH2F* hr = (TH2F*)f->Get(Form("correlation"));
    hr->SetTitle("");
    hr->GetXaxis()->SetRangeUser(-4,4);
    hr->GetYaxis()->SetRangeUser(-1.5,4);
 //   hr->GetZaxis()->SetRangeUser(0,3e6);
    hr->GetXaxis()->SetTitle("#Delta#eta");
    hr->GetXaxis()->CenterTitle();
    hr->GetYaxis()->SetTitle("#Delta#phi");
    hr->GetYaxis()->CenterTitle();
    hr->GetZaxis()->SetTitle("#frac{1}{N_{trig}}#frac{d^{2}N^{pair}}{d#Delta#eta d#Delta#phi}");
    TCanvas *c1 = new TCanvas();
    hr->Draw("surf1");
    TLatex l;
    l.SetNDC();
    l.SetTextSize(0.04);
    c1->Print("ridge.png");
}
Example #10
0
TH2F *plotEff2D(RooDataSet *a, TString b) {
    const RooArgSet *set = a->get();
    RooRealVar *yAx = (RooRealVar*)set->find("pt");
    RooRealVar *xAx = (RooRealVar*)set->find("eta");
    RooRealVar *eff = (RooRealVar*)set->find("efficiency");

//    const int xnbins = xAx->getBinning().numBins();
//    const int ynbins = yAx->getBinning().numBins();

    //double xbins[] = {-2.4, -1.6, -0.8, 0.0, 0.8, 1.6, 2.4};
    //double ybins[] = {0, 2, 3, 5, 8, 10, 20};

    const double *xvbins = xAx->getBinning().array();
    const double *yvbins = yAx->getBinning().array();

    TH2F* h = new TH2F(b, "", xAx->getBinning().numBins(), xvbins, yAx->getBinning().numBins(), yvbins);

    gStyle->SetPaintTextFormat("5.2f");
    gStyle->SetPadRightMargin(0.12);
    gStyle->SetPalette(1);
    h->SetOption("colztexte");
    h->GetZaxis()->SetRangeUser(-0.001,1.001);
    h->SetStats(kFALSE);
    h->GetYaxis()->SetTitle("p_{T} [GeV/c]");
    h->GetXaxis()->SetTitle("#eta");
    h->GetXaxis()->CenterTitle();
    h->GetYaxis()->CenterTitle();
    h->GetXaxis()->SetTitleSize(0.05);
    h->GetYaxis()->SetTitleSize(0.05);
    h->GetYaxis()->SetTitleOffset(0.8);
    h->GetXaxis()->SetTitleOffset(0.9);
    for(int i=0; i<a->numEntries(); i++) {
        a->get(i);
        h->SetBinContent(h->FindBin(xAx->getVal(), yAx->getVal()), eff->getVal());
        h->SetBinError(h->FindBin(xAx->getVal(), yAx->getVal()), (eff->getErrorHi()-eff->getErrorLo())/2.);
    }

    return h;

}
Example #11
0
int main (int argc, char** argv)
{
  gROOT->ProcessLine("#include <vector>"); //needed by ROOT to deal with standard vectors

  //HACK to use the dictionary easily
  std::string fullFileName = "";
  // Code taken from: http://www.gamedev.net/community/forums/topic.asp?topic_id=459511
  std::string path = "";
  pid_t pid = getpid();
  char buf[20] = {0};
  sprintf(buf,"%d",pid);
  std::string _link = "/proc/";
  _link.append( buf );
  _link.append( "/exe");
  char proc[512];
  int ch = readlink(_link.c_str(),proc,512);
  if (ch != -1) {
    proc[ch] = 0;
    path = proc;
    std::string::size_type t = path.find_last_of("/");
    path = path.substr(0,t);
  }
  fullFileName = path + std::string("/");
  //now even worse, assuming the executable is in build and the .C macro in code
  // std::string command = ".L " + fullFileName.substr(0,fullFileName.size()-7) + "/code/structDictionary.C+";
  std::string command = ".L " + fullFileName + "structDictionary.C+";
  // std::cout << fullFileName << std::endl;
  // std::cout << "command " << command << std::endl;
  gROOT->ProcessLine(command.c_str());


  //-------------------
  // Input Files
  //-------------------
  TChain *tree =  new TChain("tree"); // read input files
  for (int i = 1 ; i < argc ; i++)
  {
    std::cout << "Adding file " << argv[i] << std::endl;
    tree->Add(argv[i]);
  }
  // find the number of channels directly from the tchain file
  // before creating the variables
  // first, get the list of leaves
  TObjArray *leavescopy = tree->GetListOfLeaves();
  int nLeaves = leavescopy->GetEntries();
  std::vector<std::string> leavesName;
  // fill a vector with the leaves names
  for(int i = 0 ; i < nLeaves ; i++)
  {
    leavesName.push_back(leavescopy->At(i)->GetName());
  }
  // count the entries that start with "ch"
  int numOfCh = 0;
  // int numOfCry = 0;
  std::string det_prefix("detector");
  // std::string cry_prefix("cry");
  for(int i = 0 ; i < nLeaves ; i++)
  {
    //     leavesName.push_back(leavescopy->At(i)->GetName());
    if (!leavesName[i].compare(0, det_prefix.size(), det_prefix))
    numOfCh++;
    // if (!leavesName[i].compare(0, cry_prefix.size(), cry_prefix))
    // numOfCry++;
  }
  //the string "cry" appears 4 times per crystal..
  // numOfCry = numOfCry / 4;
  std::cout << "Detector Channels \t= " << numOfCh << std::endl;
  // std::cout << "Number of Crystals \t= "<< numOfCry << std::endl;


  //------------------
  // Input TTree
  //------------------

  //create the branches in the input ttree and connect to the variables

  // global variables
  // these are 1 number per TTree entry - so 1 number per gamma shot
  Long64_t Seed;                      // seed of the simulation (read every time, but always the same)
  int Run;                            // run id (usually just 1)(read every time, but always the same)
  int Event;                          // event id
  float totalEnergyDeposited;         // total energy deposited in this event, in all the matrix
  int NumOptPhotons;                  // number of optical photons generated in this event, in the entire matrix
  int NumCherenkovPhotons;            // number of Cherenkov photons generated in this event, in the entire matrix

  // energy deposition, each gamma 511 event has a std::vector of struct (type enDep) with all the data of each energy deposition
  std::vector<enDep> *energyDeposition = 0;

  // Total number of photons detected in this event
  // for each TTree entry, a simple number saying how many optical photons entered that
  // specific detector, passed the PDE check and where "detected" (i.e. saved)
  Short_t  *detector;
  detector = new Short_t [numOfCh];

  // optical photons. for each gamma 511 event, every optical photon detected is a struct of type optPhot. a std::vector<optPhot> is saved for each gamma 511
  std::vector<optPhot> *photons = 0;

  //------------------------
  // Set Branch Addresses
  //------------------------
  tree->SetBranchAddress("Seed",&Seed);
  tree->SetBranchAddress("Run",&Run);
  tree->SetBranchAddress("Event",&Event);
  tree->SetBranchAddress("totalEnergyDeposited",&totalEnergyDeposited);
  tree->SetBranchAddress("NumOptPhotons",&NumOptPhotons);
  tree->SetBranchAddress("NumCherenkovPhotons",&NumCherenkovPhotons);

  tree->SetBranchAddress("optical",&photons);
  tree->SetBranchAddress("energyDeposition",&energyDeposition);

  for (int i = 0 ; i < numOfCh ; i++)
  {
    std::stringstream snames;
    snames << "detector" << i;
    tree->SetBranchAddress(snames.str().c_str(),&detector[i]);
  }

  //output ttree
  // long long int DeltaTimeTag,ExtendedTimeTag;
  // Short_t charge[32]; //adc type is always 32 channels
  // Float_t RealX,RealY,RealZ;
  // Short_t CrystalsHit;
  // Short_t NumbOfInteractions;
  //
  // TTree* t1 = new TTree("adc","adc");
  //
  // t1->Branch("ExtendedTimeTag",&ExtendedTimeTag,"ExtendedTimeTag/l"); 	//absolute time tag of the event
  // t1->Branch("DeltaTimeTag",&DeltaTimeTag,"DeltaTimeTag/l"); 			//delta time from previous event
  // //branches of the 32 channels data
  // for (int i = 0 ; i < 32 ; i++)
  // {
  //   //empty the stringstreams
  //   std::stringstream snames,stypes;
  //   charge[i] = 0;
  //   snames << "ch" << i;
  //   stypes << "ch" << i << "/S";
  //   t1->Branch(snames.str().c_str(),&charge[i],stypes.str().c_str());
  // }
  // t1->Branch("RealX",&RealX,"RealX/F");
  // t1->Branch("RealY",&RealY,"RealY/F");
  // t1->Branch("RealZ",&RealZ,"RealZ/F");
  // t1->Branch("CrystalsHit",&CrystalsHit,"CrystalsHit/S");
  // t1->Branch("NumbOfInteractions",&NumbOfInteractions,"NumbOfInteractions/S");
  long long int DeltaTimeTag,ExtendedTimeTag;
  Short_t charge[16];

  // correct geometry for 4x4 mppc
  // Double_t xmppc[16]={-4.8,-1.6,1.6,4.8,-4.8,-1.6,1.6,4.8,-4.8,-1.6,1.6,4.8,-4.8,-1.6,1.6,4.8};
  // Double_t ymppc[16]={-4.8,-4.8,-4.8,-4.8,-1.6,-1.6,-1.6,-1.6,1.6,1.6,1.6,1.6,4.8,4.8,4.8,4.8};

  Double_t xmppc[16]={-4.8,-4.8,-4.8,-4.8,-1.6,-1.6,-1.6,-1.6,1.6,1.6,1.6,1.6,4.8,4.8,4.8,4.8};
  Double_t ymppc[16]={-4.8,-1.6,1.6,4.8,-4.8,-1.6,1.6,4.8,-4.8,-1.6,1.6,4.8,-4.8,-1.6,1.6,4.8};

  TH2F *flood = new TH2F("FloodHisto","FloodHisto",1000,-7,7,1000,-7,7);
  flood->GetXaxis()->SetTitle("X [mm]");
  flood->GetYaxis()->SetTitle("Y [mm]");
  flood->GetZaxis()->SetTitle("N");
  //   recClean->SetTitle("Reconstruction of entire dataset");
  //   varStream << "FloodY_" << k << ":FloodX_" << k << ">>" << histoString ;

  // TH2F *positions = new TH2F("Positions","Positions",1000,-7,7,1000,-7,7);
  // positions->GetXaxis()->SetTitle("X [mm]");
  // positions->GetYaxis()->SetTitle("Y [mm]");
  // positions->GetZaxis()->SetTitle("N");


  // TH2F *HitPositions = new TH2F("HitPositions","HitPositions",1000,-7,7,1000,-7,7);
  // HitPositions->GetXaxis()->SetTitle("X [mm]");
  // HitPositions->GetYaxis()->SetTitle("Y [mm]");
  // HitPositions->GetZaxis()->SetTitle("N");
  double columsum = 0;
  double rowsum = 0;
  double total = 0;
  double floodx = 0;
  double floody = 0;
  double floodz = 0;


  // TBranch *b_floodx = tree->Branch("FloodX",&floodx,"floodx/F");
  // TBranch *b_floody = tree->Branch("FloodY",&floody,"floody/F");
  // TBranch *b_floodz = tree->Branch("FloodZ",&floodz,"floodz/F");

  //----------------------------------------//
  //             LOOP ON EVENTS             //
  //----------------------------------------//
  long int counter = 0;
  int nEntries = tree->GetEntries();
  std::cout << "nEntries = " << nEntries << std::endl;


  TH1F *histoSigmaX = new TH1F("histoSigmaX","Sigma x distribution",1000,0,1);
  histoSigmaX->GetXaxis()->SetTitle("Sigma x [mm]");

  TH1F *histoSigmaY = new TH1F("histoSigmaY","Sigma y distribution",1000,0,1);
  histoSigmaY->GetXaxis()->SetTitle("Sigma y [mm]");

  TH1F *histoSigmaZ = new TH1F("histoSigmaZ","Sigma z distribution",1000,0,1);
  histoSigmaZ->GetXaxis()->SetTitle("Sigma z [mm]");

  TH1F *DeltaR = new TH1F("DeltaR","Delta r distribution",1000,-30,30);
  DeltaR->GetXaxis()->SetTitle("Delta r [mm]");

  TH1F *DeltaR_xy = new TH1F("DeltaR_xy","Delta r_xy distribution",1000,-30,30);
  DeltaR_xy->GetXaxis()->SetTitle("Delta r_xy [mm]");

  TH1F *DeltaZ = new TH1F("DeltaZ","Delta z distribution",1000,-15,15);
  DeltaZ->GetXaxis()->SetTitle("Delta z [mm]");

  TH1F *DeltaE = new TH1F("DeltaE","Delta E distribution",1000,-0.511,0.511);
  DeltaE->GetXaxis()->SetTitle("Delta E [MeV]");

  TH2F *DeltaEvsDeltaZ = new TH2F("DeltaZvsDeltaE","DeltaE vs DeltaZ",1000,-15,15,1000,-0.511,0.511);
  DeltaEvsDeltaZ->GetXaxis()->SetTitle("Delta z [mm]");
  DeltaEvsDeltaZ->GetYaxis()->SetTitle("Delta E [MeV]");


  TH2F *averageZvsRatio = new TH2F("AverageZ vs Ratio","AverageZ vs Ratio",100,0,1,100,-8,8);
  averageZvsRatio->GetXaxis()->SetTitle("Ratio (Fi/(Fi+Bi))");
  averageZvsRatio->GetYaxis()->SetTitle("AverageZ [mm]");

  TH2F *normalizedZvsRatio = new TH2F("NormalizedZ vs Ratio","NormalizedZ vs Ratio",100,0,1,100,0,1);
  normalizedZvsRatio->GetXaxis()->SetTitle("Ratio (Fi/(Fi+Bi))");
  normalizedZvsRatio->GetYaxis()->SetTitle("NormalizedZ [fraction of crystal z]");

  TH2F *wivsRatio = new TH2F("wi vs Ratio","wi vs Ratio",100,0,1,100,0,1);
  wivsRatio->GetXaxis()->SetTitle("Ratio (Fi/(Fi+Bi))");
  wivsRatio->GetYaxis()->SetTitle("Wi");

  TH2F *wMeasuredvsRatioW = new TH2F("wMeasuredvsRatioW","Measured w vs. Weighted average w_0 w_1",100,0,1,100,0,1);
  wMeasuredvsRatioW->GetXaxis()->SetTitle("RatioW = Sum_i(Wi*Ei/Etot)");
  wMeasuredvsRatioW->GetYaxis()->SetTitle("Measured W");

  TH2F *uMeasuredVsRatioU = new TH2F("uMeasuredVsRatioU","Measured u vs. Weighted average u_0 u_1",100,-1.3,-1,100,-1.3,-1);
  uMeasuredVsRatioU->GetXaxis()->SetTitle("RatioU = Sum_i(Ui*Ei/Etot)");
  uMeasuredVsRatioU->GetYaxis()->SetTitle("Measured U");

  TH2F *vMeasuredVsRatioV = new TH2F("vMeasuredVsRatioV","Measured v vs. Weighted average v_0 v_1",100,1,2,100,1,2);
  vMeasuredVsRatioV->GetXaxis()->SetTitle("RatioV = Sum_i(Vi*Ei/Etot)");
  vMeasuredVsRatioV->GetYaxis()->SetTitle("Measured V");

  TH2F *averageZvsWi = new TH2F("AverageZ vs Wi","AverageZ vs Wi",100,0,1,100,-8,8);
  averageZvsWi->GetXaxis()->SetTitle("Wi");
  averageZvsWi->GetYaxis()->SetTitle("AverageZ [mm]");

  TH2F *kMeasuredvsRatioF = new TH2F("kMeasuredveRatioF","kMeasuredveRatioF",100,0,1,100,0,1);
  kMeasuredvsRatioF->GetXaxis()->SetTitle("RatioF");
  kMeasuredvsRatioF->GetYaxis()->SetTitle("Measured K");

  TH2F *pmaxiVsRatioF = new TH2F("pmaxiVsRatioF","Pmax_i vs. F_i",100,0,2000,100,0,2000);
  pmaxiVsRatioF->GetXaxis()->SetTitle("F");
  pmaxiVsRatioF->GetYaxis()->SetTitle("Pmax_i");

  TH2F *kMeasuredvsPmaxi = new TH2F("kMeasuredvsPmaxi","k vs. Ratio(Pmax_i)",100,0,1,100,0,1);
  kMeasuredvsPmaxi->GetXaxis()->SetTitle("Ratio(Pmax_i)");
  kMeasuredvsPmaxi->GetYaxis()->SetTitle("Measured K");



  // for(int i =0 ; i < 2; i++)
  // {
  //   std::stringstream name;
  //   name << "AverageZ vs. (Fi/(Fi+Bi)) - Crystal " << i
  //   averageZvsRatio[i] = new TH2F()
  // }
  long int foundCandidate = 0;
  long int singleCounter = 0;
  long int doubleCounter = 0;
  long int tripleCounter = 0;
  long int multipleCounter = 0;
  // int firstCrystal[64];
  // int secondCrystal[64];
  //
  // for (int i = 0 ; i < 64 ; i++)
  // {
  //   firstCrystal[i] = 0;
  //   secondCrystal[i] = 0;
  // }


  long int globalReturned = 0;
  for(int iEvent = 0; iEvent < nEntries ; iEvent++)
  // for(int iEvent = 5; iEvent < 6 ; iEvent++)
  {
    tree->GetEvent(iEvent);
    // std::cout << "iEvent "<<iEvent << std::endl;
    columsum = 0;
    rowsum = 0;
    total = 0;
    floodx = 0;
    floody = 0;
    floodz = 0;



    //first clean the array
    // for(int i = 0; i < 16 ; i++)
    // {
    //   charge[i] = 0;
    // }

    //then fill it with the detector data
    // for(int i = 0; i < numOfCh ; i++)
    // {
    //   charge[i] = detector[i];
    // }

    //calculate weighted energy and fill 2d histo
    for(int i = 0; i < 16 ; i++)
    {
      columsum += detector[i]*ymppc[i];
      rowsum += detector[i]*xmppc[i];
      total += detector[i];
    }
    floodx = rowsum/total;
    floody = columsum/total;
    // b_floodx->Fill();

    flood->Fill(floodx,floody);




    std::vector<int> crystals;
    // std::vector<enDep> EventDepositions;



    // stackingaction is last-in-first-out so we need to sort energyDeposition before we check what crystal was hit first
    // check crystal sequence, check for returning gammas, calculate an average xyz per crystal
    std::sort(energyDeposition->begin(), energyDeposition->end(), compareByTime);
    std::vector<std::vector < enDep > > separatedEnDep;
    // float EnDepPerCrystal = 0.0;
    int CurrentID = -1;
    // bool newcrystal = false;
    float RealX = 0.0;
    float RealY = 0.0;
    float RealZ = 0.0;
    std::vector < enDep > CrystalEnDepCollection;

    for(int eEvent = 0; eEvent < energyDeposition->size(); eEvent++) //run on energy depositions and find in how many crystals energy was deposited
    {
      //read the crystal where energy was deposited
      int cry = energyDeposition->at(eEvent).CrystalID;
      //create temp enDep variable and copy this eEvent into it

      //DEBUG
      // std::cout << eEvent <<" ";
      // std::cout << energyDeposition->at(eEvent).CrystalID << " ";
      // std::cout << energyDeposition->at(eEvent).EnergyDeposited<< " ";
      // std::cout << energyDeposition->at(eEvent).DepositionTime<< " ";
      // std::cout << energyDeposition->at(eEvent).DepositionX<< " ";
      // std::cout << energyDeposition->at(eEvent).DepositionY<< " ";
      // std::cout << energyDeposition->at(eEvent).DepositionZ<< std::endl;
      //---DEBUG

      enDep tempCrystalEnDep;
      tempCrystalEnDep = energyDeposition->at(eEvent);

      // std::cout << eEvent <<" ";
      // std::cout << tempCrystalEnDep.CrystalID << " ";
      // std::cout << tempCrystalEnDep.EnergyDeposited<< " ";
      // std::cout << tempCrystalEnDep.DepositionTime<< " ";
      // std::cout << tempCrystalEnDep.DepositionX<< " ";
      // std::cout << tempCrystalEnDep.DepositionY<< " ";
      // std::cout << tempCrystalEnDep.DepositionZ<< std::endl;

      //if the crystal is changing
      if(eEvent == 0) CurrentID = cry;
      if(cry != CurrentID) // changes everytime the gamma enters a new crystal
      {
        separatedEnDep.push_back(CrystalEnDepCollection); // save the collection of this crystal into the std::vector of collections
        CrystalEnDepCollection.clear(); //clear this collection
        CurrentID = cry; //change the current id
      }

      CrystalEnDepCollection.push_back(tempCrystalEnDep); // save this enDep event into the collection if this crystal

      if(eEvent == energyDeposition->size() -1)
      {
        separatedEnDep.push_back(CrystalEnDepCollection);
      }
      //loop in the crystals found
      //look for the same id
      bool sameID = false;
      for(int j = 0 ; j < crystals.size(); j++)
      {
        if(crystals[j] == cry) sameID = true;
      }
      if(!sameID) crystals.push_back(cry);
    }
    // std::cout << separatedEnDep.size() << std::endl;

    //DEBUG
    // for(int iColl = 0 ; iColl < separatedEnDep.size(); iColl++)
    // {
    //   std::cout << separatedEnDep.at(iColl).size()<< std::endl;
    //   for(int iEndep = 0; iEndep < separatedEnDep.at(iColl).size(); iEndep++)
    //   {
    //     std::cout << iColl << " " << iEndep << " " ;
    //     std::cout << separatedEnDep.at(iColl).at(iEndep).CrystalID << " ";
    //     std::cout << separatedEnDep.at(iColl).at(iEndep).EnergyDeposited<< " ";
    //     std::cout << separatedEnDep.at(iColl).at(iEndep).DepositionTime<< " ";
    //     std::cout << separatedEnDep.at(iColl).at(iEndep).DepositionX<< " ";
    //     std::cout << separatedEnDep.at(iColl).at(iEndep).DepositionY<< " ";
    //     std::cout << separatedEnDep.at(iColl).at(iEndep).DepositionZ<< std::endl;
    //   }
    // }
    //---DEBUG


    std::vector<avgCryEnergyDep> averageDepEvents;
    // now the en dep events are collected by crystal
    // run on each collection and find average
    for(int iColl = 0 ; iColl < separatedEnDep.size(); iColl++)
    {
      avgCryEnergyDep tempAvgEnDep;

      tempAvgEnDep.id = separatedEnDep.at(iColl).at(0).CrystalID;
      tempAvgEnDep.x = 0;
      tempAvgEnDep.y = 0;
      tempAvgEnDep.z = 0;
      tempAvgEnDep.time = 0;
      tempAvgEnDep.energy = 0;
      tempAvgEnDep.sx = 0;
      tempAvgEnDep.sy = 0;
      tempAvgEnDep.sz = 0;
      for(int iEndep = 0; iEndep < separatedEnDep.at(iColl).size(); iEndep++)
      {
        tempAvgEnDep.energy += separatedEnDep.at(iColl).at(iEndep).EnergyDeposited;
        // std::cout << separatedEnDep.at(iColl).at(iEndep).EnergyDeposited << std::endl;
        tempAvgEnDep.x += separatedEnDep.at(iColl).at(iEndep).DepositionX * separatedEnDep.at(iColl).at(iEndep).EnergyDeposited;
        tempAvgEnDep.y += separatedEnDep.at(iColl).at(iEndep).DepositionY * separatedEnDep.at(iColl).at(iEndep).EnergyDeposited;
        tempAvgEnDep.z += separatedEnDep.at(iColl).at(iEndep).DepositionZ * separatedEnDep.at(iColl).at(iEndep).EnergyDeposited;
        tempAvgEnDep.time += separatedEnDep.at(iColl).at(iEndep).DepositionTime * separatedEnDep.at(iColl).at(iEndep).EnergyDeposited;
      }
      tempAvgEnDep.x = tempAvgEnDep.x / tempAvgEnDep.energy;
      tempAvgEnDep.y = tempAvgEnDep.y / tempAvgEnDep.energy;
      tempAvgEnDep.z = tempAvgEnDep.z / tempAvgEnDep.energy;
      tempAvgEnDep.time = tempAvgEnDep.time / tempAvgEnDep.energy;
      float varx = 0.0;
      float vary = 0.0;
      float varz = 0.0;
      for(int iEndep = 0; iEndep < separatedEnDep.at(iColl).size(); iEndep++)
      {
        varx += (separatedEnDep.at(iColl).at(iEndep).EnergyDeposited * pow(separatedEnDep.at(iColl).at(iEndep).DepositionX  - tempAvgEnDep.x,2)) / tempAvgEnDep.energy;
        vary += (separatedEnDep.at(iColl).at(iEndep).EnergyDeposited * pow(separatedEnDep.at(iColl).at(iEndep).DepositionY  - tempAvgEnDep.y,2)) / tempAvgEnDep.energy;
        varz += (separatedEnDep.at(iColl).at(iEndep).EnergyDeposited * pow(separatedEnDep.at(iColl).at(iEndep).DepositionZ  - tempAvgEnDep.z,2)) / tempAvgEnDep.energy;
      }
      tempAvgEnDep.sx = sqrt(varx);
      tempAvgEnDep.sy = sqrt(vary);
      tempAvgEnDep.sz = sqrt(varz);

      averageDepEvents.push_back(tempAvgEnDep);

    }
    //DEBUG
    // for (int iAvg = 0 ; iAvg < averageDepEvents.size() ; iAvg++)
    // {
    //   std::cout << "----------------------" << std::endl;
    //   std::cout << averageDepEvents.at(iAvg).id << " " << averageDepEvents.at(iAvg).energy << " " << averageDepEvents.at(iAvg).time << std::endl;
    //   std::cout << "(" << averageDepEvents.at(iAvg).x << "," << averageDepEvents.at(iAvg).y << "," << averageDepEvents.at(iAvg).z <<  ") " << std::endl;
    //   std::cout << "(" << averageDepEvents.at(iAvg).sx << "," << averageDepEvents.at(iAvg).sy << "," << averageDepEvents.at(iAvg).sx <<  ") " << std::endl;
    //
    // }
    //---DEBUG

    //fill a global histogram of energy deposition sigmas in the crystals
    for (int iAvg = 0 ; iAvg < averageDepEvents.size() ; iAvg++)
    {
      // std::cout << "----------------------" << std::endl;
      // std::cout << averageDepEvents.at(iAvg).id << " " << averageDepEvents.at(iAvg).energy << " " << averageDepEvents.at(iAvg).time << std::endl;
      // std::cout << "(" << averageDepEvents.at(iAvg).x << "," << averageDepEvents.at(iAvg).y << "," << averageDepEvents.at(iAvg).z <<  ") " << std::endl;
      // std::cout << "(" << averageDepEvents.at(iAvg).sx << "," << averageDepEvents.at(iAvg).sy << "," << averageDepEvents.at(iAvg).sx <<  ") " << std::endl;
      histoSigmaX->Fill(averageDepEvents.at(iAvg).sx);
      histoSigmaY->Fill(averageDepEvents.at(iAvg).sy);
      histoSigmaZ->Fill(averageDepEvents.at(iAvg).sz);
    }


    //two crystals or more hit, but a crystal is hit more than once (like, 28 -> 36 -> 28)
    std::vector <int> checkReturning; // this std::vector has same size of averageDepEvents if there is no returning, smaller if there is
    int returned = 0;
    for (int iAvg = 0 ; iAvg < averageDepEvents.size() ; iAvg++)
    {
      int cry = averageDepEvents.at(iAvg).id;
      bool sameID = false;
      for(int i = 0 ; i < checkReturning.size(); i++)
      {
        if(cry == checkReturning[i])
        {
          sameID = true;
          returned++;
        }
      }
      if(!sameID) checkReturning.push_back(cry);
    }
    globalReturned += returned;

    if(totalEnergyDeposited > 0.400)
    {
      if(averageDepEvents.size() == 2)
      {
        DeltaZ->Fill(averageDepEvents[0].z - averageDepEvents[1].z);
        DeltaE->Fill(averageDepEvents[0].energy - averageDepEvents[1].energy);
        DeltaEvsDeltaZ->Fill(averageDepEvents[0].z - averageDepEvents[1].z,averageDepEvents[0].energy - averageDepEvents[1].energy);
        DeltaR->Fill(sqrt(pow(averageDepEvents[0].x - averageDepEvents[1].x,2)+pow(averageDepEvents[0].y - averageDepEvents[1].y,2)+pow(averageDepEvents[0].z - averageDepEvents[1].z,2)));
        DeltaR_xy->Fill(sqrt(pow(averageDepEvents[0].x - averageDepEvents[1].x,2)+pow(averageDepEvents[0].y - averageDepEvents[1].y,2)));
      }
    }


    //now take only events where energy was deposited in 2 crystals and total energy deposited is around 511KeV
    //very not general, but this is only for testing: choose crystals 28 and 29 (2 crystals on the same mppc)
    //and run only on the 9 relevant mppcs to compute w_near
    // if((crystals[0] == 27 && crystals[1] == 28) | (crystals[0] == 28 && crystals[1] == 27))

    // if(true)
    // std::cout << counter << " " << crystals[0] << " " << crystals[1] << std::endl;
    // if(totalEnergyDeposited > 0.510)
    // {
      // if(crystals.size() == 2)
      // {
      //   firstCrystal[crystals[0]]++;
      //   secondCrystal[crystals[1]]++;
      // }
    // }

    if((crystals[0] == 28 && crystals[1] == 29) /*| (crystals[0] == 29 && crystals[1] == 28)*/)
    {

      if(totalEnergyDeposited > 0.510)
      {
        if(crystals.size() == 2 )
        {

          //consider only non-lateral crystals - not needed if it's restricted to 28 and 29...
          bool isCandidate = true;
          for(int eEvent = 0; eEvent < energyDeposition->size(); eEvent++) //run on energy depositions and check is not on borders
          {
            bool check_b = energyDeposition->at(eEvent).CrystalI < 2 | energyDeposition->at(eEvent).CrystalI > 5 | energyDeposition->at(eEvent).CrystalJ < 2 | energyDeposition->at(eEvent).CrystalJ > 5;
            if(check_b)
            {
              isCandidate = false;
            }
          }
          if(isCandidate)
          {
            //calculate average Z of production in the 2 crystals
            // foundCandidate++;

            //calculate the measured W
            int Measured_pmaxID = 0;
            int Measured_pmax = 0;
            int Measured_pSecond = 0;
            int Measured_totalDetCounts = 0;
            std::vector<int> vToSort;
            for(int i = 0; i < numOfCh ; i++)
            {
              if(i == 1 | i == 2 | i == 3 | i == 5 | i == 6 | i == 7 | i == 9 | i == 10 | i == 11) //just channel 6 (where 28 and 29 are) and surrounding
              {
                Measured_totalDetCounts+=detector[i];
              }
              vToSort.push_back(detector[i]);
            }
            std::sort (vToSort.begin(),vToSort.end());
            Measured_pmax = vToSort[vToSort.size()-1];
            Measured_pSecond = vToSort[vToSort.size()-2];

            // {
            //   Measured_totalDetCounts += detector[i];
            //   if(detector[i] > Measured_pmax1)
            //   {
            //     Measured_pmax1 = detector[i];
            //     Measured_pmaxID = i;
            //   }
            // }



            double Measured_w = ((double) Measured_pmax) / ((double)Measured_totalDetCounts);
            // double Measured_w = ((double) Measured_pmax + (double)Measured_pSecond) / (2.0*(double)Measured_totalDetCounts);
            // double Measured_w = ((double) Measured_pmax + (double)Measured_pSecond) / ((double)Measured_totalDetCounts);
            double RatioW = 0.0;
            double RatioF = 0.0;

            //compute k

            // we have u v coordinates for this event (floodx and floody)
            // we roughly measured the center of the two spots,
            // P28 = (-1.087,1.17) - P29 = (-1.087,1.97)
            // now we should calculate the line connecting the two spots in u,v, then the normal, then intersection and bla bla.
            // but we took same x for the two points, so the only coordinate that matters is y
            double SpotsDistance = 1.97 - 1.17;
            // std::cout << floodx << " "<<  floody << std::endl;
            double kDistance = fabs(floody - 1.97);// 28 is 0, 29 is 1 - but maybe i've inverted. whatever
            double Measured_k = kDistance/SpotsDistance;


            std::vector<double> totalEnergyPerCrystal;
            std::vector<double> averageZ;
            std::vector<double> normalizedZ;
            std::vector<double> wi;
            std::vector<double> ratio;
            std::vector<long int> Fi;
            std::vector<long int> Bi;
            std::vector<double> pmax_i;
            std::vector<double> ui;
            std::vector<double> vi;

            for(int j = 0 ; j < crystals.size() ; j++) // we are in a specific crystal
            {
              double temp_totalEnergyPerCrystal = 0.0;
              for(int eEvent = 0; eEvent < energyDeposition->size(); eEvent++)
              {

                if(energyDeposition->at(eEvent).CrystalID == crystals[j])
                temp_totalEnergyPerCrystal += energyDeposition->at(eEvent).EnergyDeposited;
              }

              double temp_averageZ = 0.0;
              for(int eEvent = 0; eEvent < energyDeposition->size(); eEvent++)
              {
                if(energyDeposition->at(eEvent).CrystalID == crystals[j])
                temp_averageZ += (energyDeposition->at(eEvent).DepositionZ *  energyDeposition->at(eEvent).EnergyDeposited)/temp_totalEnergyPerCrystal;
              }

              // now on opticals
              // 1.is averageZ correlated to Fi/(Fi+Bi)?
              // count Fi and Bi for this crystal

              // 2. next, is wi correlated with ratio (actually are they the same?)?
              // so calculate wi
              // divide opticals on the basis of origin crystal
              // count the photons detected by each detector for both origins
              // compute the two wi
              long int temp_Fi = 0;
              long int temp_Bi = 0;
              short detectorSorted[numOfCh];
              for(int iDet = 0; iDet < numOfCh ;iDet++)
              {
                detectorSorted[iDet] = 0;
              }

              for(int oEvent = 0; oEvent < photons->size(); oEvent++)
              {
                // calc origin crystal ID
                int OriginCrystalID = photons->at(oEvent).OriginCrystalI * 8 +  photons->at(oEvent).OriginCrystalJ;
                if(OriginCrystalID == crystals[j])
                {
                  if(photons->at(oEvent).ExitFace == 1)
                    temp_Fi++;
                  if(photons->at(oEvent).ExitFace == 2)
                    temp_Bi++;
                  //the array of detectors
                  // std::cout << photons->at(oEvent).PositionX << " "<< (int) ((photons->at(oEvent).PositionX + 6.3) /  3.2) << std::endl;
                  int iDetector = (int) ((photons->at(oEvent).PositionX + 6.3) /  3.2);
                  int jDetector = (int) ((photons->at(oEvent).PositionY + 6.3) /  3.2);
                  int detectorID = iDetector * 4 +  jDetector;
                  detectorSorted[detectorID]++;
                }
              }

              int pmaxID = 0;
              int pmax = 0;
              int totalDetCounts = 0;
              int allDetCounts = 0;
              double temp_floodx = 0;
              double temp_floody = 0;

              for(int i = 0; i < numOfCh ; i++)
              {
                if(i == 1 | i == 2 | i == 3 | i == 5 | i == 6 | i == 7 | i == 9 | i == 10 | i == 11) //just channel 6 (where 28 and 29 are) and surrounding
                {
                  totalDetCounts += detectorSorted[i];

                }

                allDetCounts += detectorSorted[i];
                temp_floodx += xmppc[i]*detectorSorted[i];
                temp_floody += ymppc[i]*detectorSorted[i];

                if(detectorSorted[i] > pmax)
                {
                  pmax = detectorSorted[i];
                  pmaxID = i;
                }
              }
              temp_floodx = temp_floodx/( (double) allDetCounts);
              temp_floody = temp_floody/( (double) allDetCounts);
              pmax_i.push_back(pmax);
              ui.push_back(temp_floodx);
              vi.push_back(temp_floody);
              double temp_wi = ((double) pmax) / ((double)totalDetCounts);
              double temp_ratio = ((double) temp_Fi)/((double) temp_Fi+ (double) temp_Bi);
              Fi.push_back(temp_Fi);
              Bi.push_back(temp_Bi);
              wi.push_back(temp_wi);
              totalEnergyPerCrystal.push_back(temp_totalEnergyPerCrystal);
              ratio.push_back(temp_ratio);
              averageZ.push_back(temp_averageZ);
              normalizedZ.push_back((temp_averageZ + 7.5) / 15.0);
              // RatioW += (wi * totalEnergyPerCrystal) / totalEnergyDeposited;

            }

            bool doubleAccepted = true;
            for(int countCry = 0; countCry < wi.size() ;countCry++ )
            {
              if(totalEnergyPerCrystal[countCry] < 0.05) doubleAccepted = false;
            }
            if(doubleAccepted)
            {
              foundCandidate++;
              RatioF = ((double) Fi[0])/(( (double) Fi[0])+( (double) Fi[1]));
              double RatioP = ((double) pmax_i[0])/(((double) pmax_i[0])+( (double) pmax_i[1]));
              double RatioU = (totalEnergyPerCrystal[0] * ui[0] + totalEnergyPerCrystal[1] * ui[1] )/ totalEnergyDeposited;
              double RatioV = (totalEnergyPerCrystal[0] * vi[0] + totalEnergyPerCrystal[1] * vi[1] )/ totalEnergyDeposited;
              for(int countCry = 0; countCry < wi.size() ;countCry++ )
              {
                averageZvsRatio->Fill(ratio[countCry],averageZ[countCry]);
                normalizedZvsRatio->Fill(ratio[countCry],normalizedZ[countCry]);
                wivsRatio->Fill(ratio[countCry],wi[countCry]);
                averageZvsWi->Fill(wi[countCry],averageZ[countCry]);
                RatioW += (wi[countCry] * totalEnergyPerCrystal[countCry]) / totalEnergyDeposited;
                // std::cout << pmax_i[countCry] << " " << Fi[countCry] << std::endl;
                pmaxiVsRatioF->Fill(Fi[countCry],pmax_i[countCry]);
              }
              wMeasuredvsRatioW->Fill(RatioW,Measured_w);
              kMeasuredvsRatioF->Fill(RatioF,Measured_k);
              kMeasuredvsPmaxi->Fill(RatioP,Measured_k);
              uMeasuredVsRatioU->Fill(RatioU,floodx);
              vMeasuredVsRatioV->Fill(RatioV,floody);
            }

          }
        }
      }
    }

    if(totalEnergyDeposited > 0.510)
    {
      if(crystals.size() == 1) singleCounter++;
      if(crystals.size() == 2) doubleCounter++;
      if(crystals.size() == 3) tripleCounter++;
      if(crystals.size() > 3)  multipleCounter++;
    }
    // std::cout << "Event " << iEvent << " - Dep in crystals = " << crystals.size() << std::endl;




    //calculate the average x and y deposition position
    // double averageX = 0;
    // double averageY = 0;
    // double energyColumnSum = 0;
    // double energyRowSum = 0;
    //
    // for(int i = 0; i < nCrystals ; i++)
    // {
    //   for (int j = 0 ; j < pEdep[i]->size() ; j++)
    //   {
    //     energyRowSum    += px[i]->at(j) * pEdep[i]->at(j);
    //     energyColumnSum += py[i]->at(j) * pEdep[i]->at(j);
    //   }
    // }
    // averageX = energyRowSum / totalEnergyDeposited;
    // averageY = energyColumnSum / totalEnergyDeposited ;
    //
    // positions->Fill(averageX,averageY);
    //t1->Fill();


    // ExtendedTimeTag = 1e-9;
    // DeltaTimeTag = 1e-9;
    //
    // NumbOfInteractions = 0;
    // CrystalsHit = 0;
    //
    //
    // for(int i = 0; i < numOfCh ; i++)
    // {
    //   //convert to ADC channels, as if it was data from a digitizer
    //   //mppc gain = 1.25e6
    //   //adc channel binning 156e-15 C
    //   double adcCh = detector[i]*1.25e6*1.6e-19/156e-15;
    //   charge[i*2] = (Short_t) adcCh;
    // }
    //
    // RealX = RealY = RealZ = 0;
    //
    // // calculate a weigthed energy deposition in x,y,z
    // for(int i = 0; i < numOfCry ; i++) //first total energy deposited
    // {
    //   NumbOfInteractions += px[i]->size();
    //   if(px[i]->size()) CrystalsHit++;
    //   for(int j = 0; j < px[i]->size(); j++)
    //   {
    //     RealX += (px[i]->at(j) * pEdep[i]->at(j))/totalEnergyDeposited;
    //   }
    //   for(int j = 0; j < px[i]->size(); j++)
    //   {
    //     RealY += (py[i]->at(j) * pEdep[i]->at(j))/totalEnergyDeposited;
    //   }
    //   for(int j = 0; j < px[i]->size(); j++)
    //   {
    //     RealZ += (pz[i]->at(j) * pEdep[i]->at(j))/totalEnergyDeposited;
    //   }
    // }
    //
    // if(NumbOfInteractions > 0) // discard events with no energy deposition (they would never trigger the detectors anyway..)
    // {
    //   t1->Fill();
    // }

    counter++;
    // std::cout << std::endl;
    // std::cout << "============================================"<< std::endl;
    // std::cout << std::endl;


    int perc = ((100*counter)/nEntries); //should strictly have not decimal part, written like this...
    if( (perc % 10) == 0 )
    {
      std::cout << "\r";
      std::cout << perc << "% done... ";
      //std::cout << counter << std::endl;
    }


  }

  std::cout << std::endl;
  // int sumFirst = 0;
  // int sumSecond = 0;
  // for (int i = 0 ; i < 64; i++)
  // {
  //   std::cout << "First["<< i <<  "] = " << firstCrystal[i] << std::endl;
  //   std::cout << "Second["<< i <<  "] = " << secondCrystal[i] << std::endl;
  //   sumFirst += firstCrystal[i];
  //   sumSecond += secondCrystal[i];
  // }
  // std::cout << "sumFirst = " << sumFirst << " sumSecond = " << sumSecond << std::endl;
  std::cout << "1 cry [511 KeV deposition] events = "    << singleCounter << std::endl;
  std::cout << "2 cry [511 KeV deposition] events = "    << doubleCounter << std::endl;
  std::cout << "3 cry [511 KeV deposition] events = "    << tripleCounter << std::endl;
  std::cout << "Multi cry [511 KeV deposition] events = "<< multipleCounter << std::endl;
  std::cout << "Returned = " << globalReturned << std::endl;
  std::cout << "Candidates = "<< foundCandidate << std::endl;

  TF1 *line = new TF1("line","x",-7,7);
  line->SetLineColor(kRed);
  TF1 *line2 = new TF1("line2","x",0,2000);
  line2->SetLineColor(kRed);



  std::string outFile = "FileOut.root";
  TFile* fOut = new TFile(outFile.c_str(),"recreate");


  histoSigmaX->Write();
  histoSigmaY->Write();
  histoSigmaZ->Write();
  DeltaZ->Write();
  DeltaE->Write();
  DeltaR->Write();
  DeltaR_xy->Write();
  DeltaEvsDeltaZ->Write();
  TCanvas *C_flood = new TCanvas("C_flood","C_flood",800,800);
  flood->Draw("COLZ");
  C_flood->Write();
  TCanvas *C_averageZvsRatio = new TCanvas("C_averageZvsRatio","C_averageZvsRatio",800,800);
  C_averageZvsRatio->cd();
  averageZvsRatio->Draw();
  C_averageZvsRatio->Write();

  TCanvas *C_normalizedZvsRatio = new TCanvas("C_normalizedZvsRatio","C_normalizedZvsRatio",800,800);
  C_normalizedZvsRatio->cd();
  normalizedZvsRatio->Draw();
  C_normalizedZvsRatio->Write();

  TCanvas *C_averageZvsWi = new TCanvas("C_averageZvsWi","C_averageZvsWi",800,800);
  C_averageZvsWi->cd();
  averageZvsWi->Draw();
  C_averageZvsWi->Write();

  TCanvas *C_wivsRatio = new TCanvas("C_wivsRatio","C_wivsRatio",800,800);
  C_wivsRatio->cd();
  wivsRatio->Draw();
  line->Draw("same");
  C_wivsRatio->Write();

  TCanvas *C_wMeasuredvsRatioW = new TCanvas("C_wMeasuredvsRatioW","C_wMeasuredvsRatioW",800,800);
  C_wMeasuredvsRatioW->cd();
  wMeasuredvsRatioW->Draw();
  line->Draw("same");
  C_wMeasuredvsRatioW->Write();

  TCanvas *C_uMeasuredVsRatioU = new TCanvas("C_uMeasuredVsRatioU","C_uMeasuredVsRatioU",800,800);
  C_uMeasuredVsRatioU->cd();
  uMeasuredVsRatioU->Draw();
  line->Draw("same");
  C_uMeasuredVsRatioU->Write();

  TCanvas *C_vMeasuredVsRatioV = new TCanvas("C_vMeasuredVsRatioV","C_vMeasuredVsRatioV",800,800);
  C_vMeasuredVsRatioV->cd();
  vMeasuredVsRatioV->Draw();
  line->Draw("same");
  C_vMeasuredVsRatioV->Write();




  TCanvas *C_kMeasuredvsRatioF = new TCanvas("C_kMeasuredvsRatioF","C_kMeasuredvsRatioF",800,800);
  C_kMeasuredvsRatioF->cd();
  kMeasuredvsRatioF->Draw();
  line->Draw("same");
  C_kMeasuredvsRatioF->Write();

  TCanvas *C_kMeasuredvsPmaxi = new TCanvas("C_kMeasuredvsPmaxi","C_kMeasuredvsPmaxi",800,800);
  C_kMeasuredvsPmaxi->cd();
  kMeasuredvsPmaxi->Draw();
  line->Draw("same");
  C_kMeasuredvsPmaxi->Write();

  TCanvas *C_pmaxiVsRatioF = new TCanvas("C_pmaxiVsRatioF","C_pmaxiVsRatioF",800,800);
  C_pmaxiVsRatioF->cd();
  pmaxiVsRatioF->Draw();
  line2->Draw("same");
  C_pmaxiVsRatioF->Write();


  // t1->Write();

  //   f1->Close();

  // std::string outFile = "analysis_OUT.root";
  // TFile* fOut = new TFile(outFile.c_str(),"recreate");

  // flood->Write();
  // positions->Write();
  //   f1->Close();

  fOut->Close();



  return 0;
}
Example #12
0
void make_SMS_exclusion(TH2F *rawlimits,TH2F *xsec,int scantype,std::string& scanx, bool isobserved) {
  TH2F *limits = prep_histo(rawlimits,scantype); // this is to be independent of the style used at creation time
  //here we get some limits and the cross section; we want to make an exclusion plot!
  TH2F *rellimits = (TH2F*)limits->Clone("rellimits");
  TH2F *rellimitsd3 = (TH2F*)limits->Clone("rellimitsd3"); // one third the cross section ("divided by 3" -> d3)
  TH2F *rellimitst3 = (TH2F*)limits->Clone("rellimitst3"); // three times the cross section ("times 3" -> t3)
  
  if(!xsec ) {
    cout << "Watch out, cross section map is invalid!" << endl;
    delete limits;
    return;
  }
  
  rellimits->Divide(xsec);
  
  
  for(int i=1;i<=rellimits->GetNbinsX();i++) {
    for(int j=1;j<=rellimits->GetNbinsY();j++) {
      rellimitst3->SetBinContent(i,j,(rellimits->GetBinContent(i,j))/3.0);
      rellimitsd3->SetBinContent(i,j,(rellimits->GetBinContent(i,j))*3.0);
    }
  }
  

//  TH2F *exclusionshape = make_exclusion_shape(rellimits,1);
//  TH2F *exclusionshapet3 = make_exclusion_shape(rellimitst3,2);
//  TH2F *exclusionshaped3 = make_exclusion_shape(rellimitsd3,3);
  
  //Now let's produce the plots!
  
  set_range(xsec,scantype,false);
  set_range(limits,scantype,false);
  limits->GetZaxis()->SetRangeUser(limits_lower_bound,limits_upper_bound);
  
  bool drawdoubleline=false; //draw nice thin line on top of thick outer line
  TGraph *exclline = MarcosExclusionLine(rellimits, scantype);
  TGraph *thinexcline = thin_line(exclline);
  
  TGraph *excllinet3 = MarcosExclusionLine(rellimitst3, scantype);
  excllinet3->SetLineStyle(2);
  TGraph *thinexclinet3 = thin_line(excllinet3);

  TGraph *excllined3 = MarcosExclusionLine(rellimitsd3, scantype);
  excllined3->SetLineStyle(3);
  TGraph *thinexclined3 = thin_line(excllined3);

//  produce_extensive_plots(xsec,limits,rellimits, rellimitst3, rellimitsd3,scantype);
  
  TCanvas *finalcanvas = new TCanvas("finalcanvas","finalcanvas");
  finalcanvas->SetLogz(1);
  finalcanvas->cd();
  limits->SetZTitle("95% CL upper limit on #sigma [pb]");
  limits->Draw("COLZ");

  TLine *desertline;
  if(drawefficiencydesertline) {
	desertline = new TLine(375,50,1200,875);
	desertline->SetLineWidth(3);
	//desertline->SetLineWidth(4); // paper style
	desertline->SetLineColor(kBlack);
	desertline->Draw("same");
  }


//  fill_with_text(exclline,excllined3,excllinet3,finalcanvas,scantype,scanx);
  stringstream real;
  real << "Limits/";
  if(!isobserved) real << "expected/expected_";
  real << "final_exclusion__" << limits->GetName();
  
  if(Contains(limits->GetName(),"bestlimits")) {
    cout << "----------> " << limits->GetName() << endl;
    TFile *f = new TFile("limits.root","RECREATE");
    thinexcline->SetName("ExclusionLine");
    limits->SetName("UpperLimits");
    limits->Write();
    thinexcline->Write();
    f->Close();
  }
  
  
  exclline->Draw("l");
  if(drawdoubleline) thinexcline->Draw("");
  excllinet3->Draw("");
  if(drawdoubleline) thinexclinet3->Draw("");
  excllined3->Draw("");
  if(drawdoubleline) thinexclined3->Draw("");
  
  CompleteSave(finalcanvas,real.str());

  
  
  //-------------------------------------- extensive plots 
  
  TCanvas *ca = new TCanvas("ca","ca",2400,1200);
  ca->Divide(4,2);
  ca->cd(1);
  ca->cd(1)->SetLogz(1);
  xsec->GetZaxis()->SetRangeUser(0.001,1000);
  xsec->Draw("COLZ");
  TText *title0 = write_title("Reference Cross Section");
  title0->Draw("same");
  ca->cd(2);
  ca->cd(2)->SetLogz(1);
  limits->GetZaxis()->SetRangeUser(limits_lower_bound,limits_upper_bound);
  limits->Draw("COLZ");
  TText *title = write_title("Cross Section Upper Limit");
  title->Draw("same");
  ca->cd(3);
  ca->cd(3)->SetLogz(1);
  TH2F *limit_ref = (TH2F*)limits->Clone("limit_ref");
  limit_ref->Divide(xsec);
  limit_ref->GetZaxis()->SetRangeUser(limits_ratio_lower_bound,limits_ratio_upper_bound);
  limit_ref->Draw("COLZ");
  TText *title2 = write_title("Cross Section UL / XS");
  title2->Draw("same");
  ca->cd(4);
  ca->cd(4)->SetLogz(1);
  limits->SetTitle("");
  limits->GetZaxis()->SetRangeUser(limits_lower_bound,limits_upper_bound);
  limits->SetZTitle("95% CL upper limit on #sigma [pb]");

  limits->Draw("COLZ");


  ca->cd(4);
  exclline->Draw();
  thinexcline->Draw();
  excllinet3->Draw();
  thinexclinet3->Draw();
  excllined3->Draw();
  thinexclined3->Draw();
  stringstream partial;
  partial << "Limits/";
  if(!isobserved) real << "expected/expected_";
  partial << "exclusion__" << limits->GetName();
  fill_with_text(exclline,excllined3,excllinet3,ca->cd(4),scantype);
//  CompleteSave(ca,partial.str());

  ca->cd(5);
  (hardlimit(rellimitsd3))->Draw("COL");
  TText *c = write_title("Exclusion shape for #sigma_{ref}/3");
  c->Draw();
  excllined3->Draw("same");
  
  ca->cd(6);
  (hardlimit(rellimits))->Draw("COL");
  exclline->Draw("same");
  TText *b = write_title("Exclusion shape for #sigma_{ref}");
  b->Draw();
  
  ca->cd(7);
  (hardlimit(rellimitst3))->Draw("COL");
  excllinet3->Draw("same");
  TText *a = write_title("Exclusion shape for 3x#sigma_{ref}");
  a->Draw();
  
  CompleteSave(ca,partial.str()+"__PlusInfo");
  delete ca;
  delete limits;
  
  //---------------------------------------</extensive plots>
  delete finalcanvas;
}
Example #13
0
void draw_mSUGRA_exclusion(TH2F *ocrosssection, TH2F *oFilterEfficiency, TH2F *oabsXS, TH2F *limitmap, TH2F *expmap, TH2F *expplusmap, TH2F *expminusmap, TH2F *exp2plusmap, TH2F *exp2minusmap, bool isobserved) {
  TH2F *crosssection = (TH2F*)ocrosssection->Clone("crosssection");
//  TH2F *limitmap = (TH2F*)olimitmap->Clone(((string)olimitmap->GetName()+"clone").c_str());
  TH2F *cleanhisto = (TH2F*)limitmap->Clone("clean");
  for(int ix=1;ix<=cleanhisto->GetNbinsX();ix++) {
    for(int iy=1;iy<=cleanhisto->GetNbinsY();iy++) {
      cleanhisto->SetBinContent(ix,iy,0);
    }
  }
  
  
  TH2F *FilterEfficiency;
  TH2F *absXS;

  
  
  
  write_warning(__FUNCTION__,"You'll want to switch off 'wrongwaytodothis')");
  
  if(wrongwaytodothis) {
    //this part is the one you want to remove.
    TFile *Efficiencies = new TFile("FilterEfficiencyv3.root");
    FilterEfficiency = cast_into_shape((TH2F*) Efficiencies->Get("FilterEfficiency"),limitmap);
    assert(FilterEfficiency);
    assert(crosssection);
    absXS=(TH2F*)crosssection->Clone("absXS");
    crosssection->Multiply(FilterEfficiency);
  } else {
    //this part is the one you want to keep!
    FilterEfficiency=(TH2F*)oFilterEfficiency->Clone("FilterEfficiency");
    absXS=(TH2F*)oabsXS->Clone("absXS");
  }
    
  

  TH2F *limits = (TH2F*)limitmap->Clone("limits");
  set_range(limits,true,false);
  limitmap->Divide(crosssection);
  expminusmap->Divide(crosssection);
  expplusmap->Divide(crosssection);
  exp2minusmap->Divide(crosssection);
  exp2plusmap->Divide(crosssection);
  expmap->Divide(crosssection);
  TGraph *observed = get_mSUGRA_exclusion_line(limitmap, PlottingSetup::mSUGRA);
  observed->SetLineColor(kRed);
  TGraph *expminus = get_mSUGRA_exclusion_line(expminusmap, PlottingSetup::mSUGRA);
  TGraph *expplus  = get_mSUGRA_exclusion_line(expplusmap, PlottingSetup::mSUGRA);
  TGraph *exp2minus;
  if(draw2sigma) exp2minus = get_mSUGRA_exclusion_line(exp2minusmap, PlottingSetup::mSUGRA);
  TGraph *exp2plus;
  if(draw2sigma) exp2plus = get_mSUGRA_exclusion_line(exp2plusmap, PlottingSetup::mSUGRA);

  TGraph *expected = new TGraph(expminus->GetN()+expplus->GetN());
  TGraph *expected2; 
  if(draw2sigma) expected2 = new TGraph(exp2minus->GetN()+exp2plus->GetN());
  for(int i=0;i<=expminus->GetN();i++) {
    Double_t x,y;
    expminus->GetPoint(i,x,y);
    expected->SetPoint(i,x,y);
  }
    
  for(int i=0;i<=exp2minus->GetN();i++) {
    Double_t x,y;
    exp2minus->GetPoint(i,x,y);
    expected2->SetPoint(i,x,y);
  }
  for(int i=exp2plus->GetN()-1;i>=0;i--) {
    Double_t x,y;
    exp2plus->GetPoint(i,x,y);
    expected2->SetPoint(exp2minus->GetN()+(exp2plus->GetN()-i),x,y);
  }
  for(int i=expplus->GetN()-1;i>=0;i--) {
    Double_t x,y;
    expplus->GetPoint(i,x,y);
    expected->SetPoint(expminus->GetN()+(expplus->GetN()-i),x,y);
  }
  expected->SetFillColor(TColor::GetColor("#9FF781"));
  if(draw2sigma) expected2->SetFillColor(TColor::GetColor("#F3F781"));
  
  smooth_line(observed);
  smooth_line(expected);
  if(draw2sigma) smooth_line(expected2);
  
  TCanvas *te = new TCanvas("te","te");
  te->SetRightMargin(standardmargin);
//  decorate_mSUGRA(cleanhisto,te,expected,expected2,observed);
  TH2F *noh = new TH2F("noh","noh",1,1,2,1,1,2);
  SugarCoatThis(te,10,noh,observed);
//  expected->Draw("c");
//  observed->Draw("c");
  stringstream saveas;
  if((int)((string)limitmap->GetName()).find("limitmap")>0) {
    saveas << "Limits/";
    if(!isobserved) saveas << "expected/expected_";
    saveas << "final_exclusion_for_JZB_geq_" << ((string)limitmap->GetName()).substr(((string)limitmap->GetName()).find("limitmap")+8,10);
  } else {
    saveas << "Limits/";
    if(!isobserved) saveas << "expected/expected";
    saveas << "final_exclusion_for_bestlimits";
  }
  CompleteSave(te,saveas.str());
  delete te;
  
  TCanvas *overview = new TCanvas("overview","overview",1500,1000);
  
  set_range(crosssection,true,false);
  set_range(limits,true,false);
  set_range(limitmap,true,false);
  
  overview->Divide(3,2);
  overview->cd(1);
  overview->cd(1)->SetLogz(1);
  absXS->GetZaxis()->SetRangeUser(0.0001,100);
  absXS->Draw("COLZ");
  TText *title0 = write_title("Cross Section");
  title0->Draw("same");
  overview->cd(2);
  FilterEfficiency->GetZaxis()->SetRangeUser(0.01,0.7);
  FilterEfficiency->Draw("COLZ");
  TText *title0aa = write_title("Filter #epsilon");
  title0aa->Draw("same");
  overview->cd(3);
  overview->cd(3)->SetLogz(1);
  crosssection->GetZaxis()->SetRangeUser(0.0001,100);
  crosssection->Draw("COLZ");
  TText *title0a = write_title("Filter #epsilon x Cross Section");
  title0a->Draw("same");
  
  overview->cd(4);
  overview->cd(4)->SetLogz(1);
  limits->GetZaxis()->SetRangeUser(0.01,100);
  limits->Draw("COLZ");
  TText *title1 = write_title("Cross Section Upper Limit");
  title1->Draw("same");
  overview->cd(5);
  limitmap->Draw("COLZ");
  TText *title2 = write_title("UL/XS");
  title2->Draw("same");
  observed->Draw("c");
  overview->cd(6);
  overview->cd(6)->SetRightMargin(standardmargin);
//  decorate_mSUGRA(cleanhisto,overview->cd(4),expected,expected2,observed);
  SugarCoatThis(overview->cd(6),10,noh,observed);
//  observed->Draw("c");
  stringstream saveas2;
  if((int)((string)limitmap->GetName()).find("limitmap")>0) {
    saveas2 << "Limits/";
    if(!isobserved) saveas << "expected/expected_";
    saveas2 << "exclusion_overview_for_JZB_geq_" << ((string)limitmap->GetName()).substr(((string)limitmap->GetName()).find("limitmap")+8,10);
  } else {
    saveas2 << "Limits/";
    if(!isobserved) saveas << "expected/expected_";
    saveas2 << "exclusion_overview_for_bestlimits";
  }
  CompleteSave(overview,saveas2.str());
  delete overview;
  delete noh;
  delete crosssection;
  delete absXS;
  delete FilterEfficiency;
  
}
Example #14
0
void process_syst_plot(TH2F *rhisto,string saveto,int scantype, std::string scanx = "") {
  TH2F *histo = prep_histo(rhisto,scantype); // this is to be independent of the style used at creation time
  float rightmargin=gStyle->GetPadRightMargin();
  gStyle->SetPadRightMargin(0.20);
  TString name = rhisto->GetName();
  if(name.Contains("Nevents")) gStyle->SetPadRightMargin(0.22);
  TCanvas *can = new TCanvas("syst_plot","Systematics Plot");
  set_range(histo,scantype,true);
  
  histo->GetZaxis()->CenterTitle();
  gStyle->SetStripDecimals(false);
  histo->GetXaxis()->SetDecimals(true);
  
  if(name.Contains("efficiency")) {
    histo->GetZaxis()->SetTitle("A #times #varepsilon (#geq 1 Z(ll))");
    histo->GetZaxis()->CenterTitle(0);
    //histo->GetZaxis()->SetRangeUser(0.0,0.15);
  }
  if(name.Contains("Nevents")) {
     histo->GetZaxis()->SetTitle("N(events)");
     histo->GetZaxis()->SetTitleOffset(histo->GetZaxis()->GetTitleOffset()+0.4);
  }
  if(name.Contains("sysjes")) {
    histo->GetZaxis()->SetTitle("Jet Energy Scale");
    histo->GetZaxis()->SetRangeUser(0.0,0.2);
  }
  if(name.Contains("sysjsu")) {
    histo->GetZaxis()->SetTitle("JZB Scale Uncertainty");
    histo->GetZaxis()->SetRangeUser(0.0,0.5);
  }
  if(name.Contains("sysresmap")) {
    histo->GetZaxis()->SetTitle("Resulution");
    histo->GetZaxis()->SetRangeUser(0.0,0.5);
  }
  if(name.Contains("sysstatmap")) {
    histo->GetZaxis()->SetTitle("Statistical Error");
    histo->GetZaxis()->SetRangeUser(0.0,0.01);
  }
  if(name.Contains("systotmap")) {
    histo->GetZaxis()->SetTitle("All Systematic Errors");
    histo->GetZaxis()->SetRangeUser(0.0,0.5);
  }
  
  
  histo->Draw("COLZ");
  DrawPrelim();
  float xpos_of_text = 0.22;
  if(name.Contains("_noscefficiencymap"))  {
    // Add some more decorations on these publication plots
    write_SMS_text( scantype, scanx, xpos_of_text );
    // Decode name and get JZB cut
    TPRegexp pat("\\d+$");
    size_t index = name.Index(pat,0);
    string cut = string("JZB > ")+(name(index,name.Length()-index).Data())+" GeV";
    //string cut = string("#splitline{JZB > ")+(name(index,name.Length()-index).Data())+" GeV}{n_{jets} #geq 3}"; //paper style
    TText *text = write_text(xpos_of_text,0.73,cut);
    text->SetTextAlign(11);
    text->SetTextSize(0.035);
    text->Draw();
    draw_diagonal_xchange( scantype, scanx );
  }
  
  CompleteSave(can,(saveto+(string)histo->GetName()));

  gStyle->SetPadRightMargin(rightmargin);
  
  delete can;
}
Example #15
0
void MakePlots(TString filename, float zmax=30, int nSmooth=10, TString opt="", TString energy="8TeV", TString lumi=""){
  TString outDir=filename; outDir.Remove(outDir.Last('/')); outDir+="/img/"+opt;
  //outDir="tmp/k5b/";
  //std::map<TString, TH2F *> deltaNLL_map;
  
  /*------------------------------ Plotto */
  TCanvas *c = new TCanvas("c","c");
  
  TFile f_in(filename, "read");
  if(f_in.IsZombie()){
    std::cerr << "File opening error: " << filename << std::endl;
    return;
  }
  
  TList *KeyList = f_in.GetListOfKeys();
  std::cout << KeyList->GetEntries() << std::endl;
  for(int i =0; i <  KeyList->GetEntries(); i++){
    c->Clear();
    TKey *key = (TKey *)KeyList->At(i);
    if(TString(key->GetClassName())!="RooDataSet") continue;
    RooDataSet *dataset = (RooDataSet *) key->ReadObj();
    if(dataset==NULL){
      std::cerr << "[WARNING] No dataset for " << key->GetName() << "\t" << key->GetTitle() << std::endl;
      continue;
    }
    TString constTermName = dataset->GetName();
    TString alphaName=constTermName; alphaName.ReplaceAll("constTerm","alpha");

    if(constTermName.Contains("absEta_1_1.4442-gold")) continue;
    if(constTermName.Contains("rho") || constTermName.Contains("phi")) continue;
        if(constTermName.Contains("scale")) continue;
    TTree *tree = dataset2tree(dataset);
    TGraphErrors bestFit_ = bestFit(tree, alphaName, constTermName);
    //    TString binning="(241,-0.0005,0.2405,60,0.00025,0.03025)"; 
    TString binning="(241,-0.0005,0.2405,301,-0.00005,0.03005)"; 
    
    TH2F *hist = prof2d(tree, constTermName, alphaName, "nll", binning, true,nSmooth, opt);
//     std::cout << "Bin width = " << hist->GetXaxis()->GetBinWidth(10) << "\t" << hist->GetYaxis()->GetBinWidth(10) << std::endl; 
//     std::cout << "Bin 1 center = " << hist->GetXaxis()->GetBinCenter(1) << "\t" << hist->GetYaxis()->GetBinCenter(1) << std::endl; 
//     std::cout << "Bin 10 center = " << hist->GetXaxis()->GetBinCenter(10) << "\t" << hist->GetYaxis()->GetBinCenter(10) << std::endl; 
//     return;
    hist->Draw("colz");
    hist->GetZaxis()->SetRangeUser(0,zmax);
    hist->GetXaxis()->SetRangeUser(0,0.15);
    hist->GetYaxis()->SetRangeUser(0,0.018);

    hist->GetXaxis()->SetTitle("#Delta S");
    hist->GetYaxis()->SetTitle("#Delta C");

    Int_t iBinX, iBinY;
    Double_t x,y;
    hist->GetBinWithContent2(0.0002,iBinX,iBinY,1,-1,1,-1,0.0000001);
    x= hist->GetXaxis()->GetBinCenter(iBinX);
    y= hist->GetYaxis()->GetBinCenter(iBinY);
    std::cout << "Best Fit: " << x << "\t" << y << std::endl;
    TGraph nllBestFit(1,&x,&y);

    TString fileName=outDir+"/"+constTermName;
    fileName+="-"; fileName+=nSmooth;
    
    nllBestFit.SetMarkerStyle(3);
    nllBestFit.SetMarkerColor(kRed);
    nllBestFit.Draw("P same");

    std::cout << fileName << std::endl;
    ofstream fout(fileName+".dat", ios_base::app);
    fout << constTermName << "\t" << x << "\t" << y << std::endl;


    c->SaveAs(fileName+".png");
    c->SaveAs(fileName+".eps");
    if(fileName.Contains("constTerm")) c->SaveAs(fileName+".C");

    fileName+="-zoom";
    hist->GetZaxis()->SetRangeUser(0,1);
    //hist->GetXaxis()->SetRangeUser(0.00,0.12);
    //hist->GetYaxis()->SetRangeUser(0,0.005);
    c->SaveAs(fileName+".png");
    c->SaveAs(fileName+".eps");


//     hist->SaveAs(outDir+"/deltaNLL-"+constTermName+".root");
//     hist->Draw("colz");
//     bestFit_.Draw("P same");
//     bestFit_.SetMarkerSize(2);


    
//     nllBestFit.SetMarkerStyle(3);
//     nllBestFit.SetMarkerColor(kRed);
//     TList* contour68 = contourFromTH2(hist, 0.68);

//     hist->Draw("colz");
//     hist->GetZaxis()->SetRangeUser(0,zmax);
//     //bestFit_.Draw("P same");
//     nllBestFit.Draw("P same");
//     //contour68->Draw("same");
    delete hist;
    RooAbsPdf *histPdf = NULL;
    if(!opt.Contains("keys")){
      hist = prof2d(tree, alphaName, constTermName, "nll", 
		    binning, false, nSmooth, opt);
      histPdf = nllToL(hist);
    }else{
      hist = prof2d(tree, alphaName, constTermName, "nll", 
		    binning, false,nSmooth);
      histPdf = Smooth(hist,1,"keys");
    }
    delete hist;


//     RooDataSet *gen_dataset=histPdf->generate(*histPdf->getVariables(),1000000,kTRUE,kFALSE);
//     TTree *genTree = dataset2tree(gen_dataset);
//     genTree->SaveAs(fileName+"-genTree.root");
//     delete gen_dataset;
//     delete histPdf;
    
//     TGraphErrors toyGraph = g(genTree, constTermName);
//     TGraphErrors bestFitGraph = g(tree,alphaName, constTermName);
//     TGraphErrors bestFitScanGraph = g(y, x);
//     delete genTree;
//     delete tree;
//     toyGraph.SetFillColor(kGreen);
//     toyGraph.SetLineColor(kBlue);
//     toyGraph.SetLineStyle(2);
//     bestFitGraph.SetLineColor(kBlack);
//     bestFitScanGraph.SetLineColor(kRed);
//     bestFitScanGraph.SetLineWidth(2);


    
//     TMultiGraph g_multi("multigraph","");
//     g_multi.Add(&toyGraph,"L3");
//     g_multi.Add(&toyGraph,"L");
//     g_multi.Add(&bestFitGraph, "L");
//     g_multi.Add(&bestFitScanGraph, "L");
   
//     g_multi.Draw("A");

//     c->Clear();
//     g_multi.Draw("A");
//     c->SaveAs(outDir+"/smearing_vs_energy-"+constTermName+".png");
//     c->SaveAs(outDir+"/smearing_vs_energy-"+constTermName+".eps");
//     //    TPaveText *pv = new TPaveText(0.7,0.7,1, 0.8);    
// //     TLegend *legend = new TLegend(0.7,0.8,0.95,0.92);
// //     legend->SetFillStyle(3001);
// //     legend->SetFillColor(1);
// //     legend->SetTextFont(22); // 132
// //     legend->SetTextSize(0.04); // l'ho preso mettendo i punti con l'editor e poi ho ricavato il valore con il metodo GetTextSize()
// //   //  legend->SetFillColor(0); // colore di riempimento bianco
// //     legend->SetMargin(0.4);  // percentuale della larghezza del simbolo
//     //    SetLegendStyle(legend);
	
//     //Plot(c, data,mc,mcSmeared,legend, region, filename, energy, lumi);
  }
  
  f_in.Close();
  
  return;
}
Example #16
0
void do_layer_maxmap(std::string filename,int layer)
{
  // First get the data
  // by merging all the available files

  gStyle->SetOptStat(0);
  gStyle->SetOptTitle(0);

  int count_p[58000];
 
  double n_lad_barrel[6]  = {16,24,34,48,62,76};
  double n_mod_barrel[6]  = {63,55,54,24,24,24};


  TFile *oldfile = TFile::Open(filename.c_str());
  TTree *newtree = (TTree*)oldfile->Get("L1Rates");

  newtree->SetBranchAddress("STUB_b_max",  &count_p);
  newtree->GetEntry(0);

  int idx;
  float maxval = 0;
  float rate = 0;
  int maxmod = 0;

  for (int i=0;i<7;++i)
  { 
    for (int j=(layer-5)*10000;j<(layer-5)*10000+8000;++j)
    { 
      rate = float(count_p[j]);

      if (rate>maxval) 
      {
	maxval = rate;
	maxmod = j;
      }
    }
  }

  cout << "max module for layer " << layer << " is " << maxmod << endl;  

  //  do_module_map(filename,layer+5, int ladder, int module)

  TH2F *cadre = new TH2F("zz","zz",n_mod_barrel[layer-5],0.,n_mod_barrel[layer-5],n_lad_barrel[layer-5],0.,n_lad_barrel[layer-5]);
  TH2F *cadre2 = new TH2F("zz","zz",n_mod_barrel[layer-5]+1,0.,n_mod_barrel[layer-5]+1,n_lad_barrel[layer-5],0.,n_lad_barrel[layer-5]);

  cadre2->Fill(n_mod_barrel[layer-5]+0.5,0.5,0.);
  cadre2->Fill(n_mod_barrel[layer-5]+0.5,0.5,maxval);

  for (int j=0;j<n_mod_barrel[layer-5];++j)
  {
    for (int i=0;i<n_lad_barrel[layer-5];++i)
    {
      idx = 10000*(layer-5) + 100*i + j;
      rate= count_p[idx];

      cadre2->Fill(j+0.5,i+0.5,rate);
    }
  }

  const Int_t NRGBs = 5;
  const Int_t NCont = 255;
  
  Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
  Double_t red[NRGBs]   = { 0.00, 0.00, 0.87, 1.00, 0.51 };
  Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 };
  Double_t blue[NRGBs]  = { 0.51, 1.00, 0.12, 0.00, 0.00 };
  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
  gStyle->SetNumberContours(NCont);


  c1 = new TCanvas("c1","Layer map",201,77,1470,858);
  gStyle->SetOptStat(0);
  gStyle->SetOptTitle(0);
  c1->Range(-5.887851,-1.930603,70.65421,17.37543);
  c1->SetFillColor(0);
  c1->SetBorderMode(0);
  c1->SetBorderSize(2);
  c1->SetGridx();
  c1->SetGridy();
  c1->SetLeftMargin(0.07692308);
  c1->SetTopMargin(0.07124352);
  c1->SetFrameBorderMode(0);
  c1->SetFrameBorderMode(0);
  

  cadre->GetXaxis()->SetTitle("Barrel module index");
  cadre->GetXaxis()->SetNdivisions(n_mod_barrel[layer-5]);
  cadre->GetXaxis()->SetLabelFont(42);
  cadre->GetXaxis()->SetLabelSize(0.02);
  cadre->GetXaxis()->SetTitleSize(0.035);
  cadre->GetXaxis()->SetTickLength(1);
  cadre->GetXaxis()->SetTitleFont(42);
  cadre->GetYaxis()->SetTitle("Barrel ladder index");
  cadre->GetYaxis()->SetNdivisions(n_lad_barrel[layer-5]);
  cadre->GetYaxis()->SetLabelFont(42);
  cadre->GetYaxis()->SetLabelOffset(0.004);
  cadre->GetYaxis()->SetLabelSize(0.02);
  cadre->GetYaxis()->SetTitleSize(0.03);
  cadre->GetYaxis()->SetTickLength(0.99);
  cadre->GetYaxis()->SetTitleFont(42);
  cadre->GetZaxis()->SetLabelFont(42);
  cadre->GetZaxis()->SetLabelSize(0.035);
  cadre->GetZaxis()->SetTitleSize(0.035);
  cadre->GetZaxis()->SetTitleFont(42);  

  cadre->Draw();
  cadre2->Draw("colzsame");
   
  TPaveText *pt = new TPaveText(-0.249009,16.26533,10.45435,17.25477,"br");
  TPaveText *pt = new TPaveText(0.,n_lad_barrel[layer-5],10./55.*n_mod_barrel[layer-5],17./16.*n_lad_barrel[layer-5],"br");

  char buffer[50];
  sprintf (buffer, "Barrel Layer %d",layer);

  ci = TColor::GetColor("#ccccff");
  pt->SetFillColor(ci);
  pt->SetTextSize(0.03125);
  TText *text = pt->AddText(buffer);
  pt->Draw();
  c1->Modified();

  c1->Update();

  sprintf (buffer, "Barrel_%d_rate_140.eps", layer);
  c1->Print(buffer);

  sprintf (buffer, "Barrel_%d_rate_140.png", layer);
  c1->Print(buffer);

  c1->Update();
}
Example #17
0
void create_exclusion_plots(vector<TH2F*> limits, int scantype, std::string& scanx) {
  TFile *xsecfile;
  if(scantype!=PlottingSetup::mSUGRA) {
    xsecfile = new TFile(xsecfilename.c_str());
    if(xsecfile->IsZombie()&&(scantype!=PlottingSetup::mSUGRA)) {
      write_error(__FUNCTION__,"Cross section file is invalid!!!!");
      return;
    }
    xsecfile->Close();
  }
  if(scantype!=PlottingSetup::mSUGRA) for(int i=0;i<(int)limits.size();i++) limits[i]->Scale(1./0.19); // because for T5zz we forced one z to decay leptonically
    
  vector<TH2F*> explimits;
  vector<TH2F*> exp1mlimits;
  vector<TH2F*> exp1plimits;
  vector<TH2F*> exp2mlimits;
  vector<TH2F*> exp2plimits;
  vector<TH2F*> obslimits;
  vector<TH2F*> flipmaps;
  vector<TH2F*> crosssections;
  vector<TH2F*> AbsCrossSection;
  vector<TH2F*> FilterEfficiencies;
  for(int ilim=0;ilim<(int)limits.size();ilim++) {
    if(TString(limits[ilim]->GetName()).Contains("_explimitmap")) explimits.push_back(limits[ilim]);
    if(scantype==PlottingSetup::mSUGRA && TString(limits[ilim]->GetName()).Contains("_exp1plimitmap")) exp1plimits.push_back(limits[ilim]);
    if(scantype==PlottingSetup::mSUGRA && TString(limits[ilim]->GetName()).Contains("_exp1mlimitmap")) exp1mlimits.push_back(limits[ilim]);
    if(scantype==PlottingSetup::mSUGRA && TString(limits[ilim]->GetName()).Contains("_exp2plimitmap")) exp2plimits.push_back(limits[ilim]);
    if(scantype==PlottingSetup::mSUGRA && TString(limits[ilim]->GetName()).Contains("_exp2mlimitmap")) exp2mlimits.push_back(limits[ilim]);
//    if(scantype==PlottingSetup::mSUGRA && TString(limits[ilim]->GetName()).Contains("_XS")) crosssections.push_back(limits[ilim]);
    if(scantype==PlottingSetup::mSUGRA && TString(limits[ilim]->GetName()).Contains("_absXS")) AbsCrossSection.push_back(limits[ilim]);
    if(scantype==PlottingSetup::mSUGRA && TString(limits[ilim]->GetName()).Contains("_FilterEfficiency")) FilterEfficiencies.push_back(limits[ilim]);
    if(wrongwaytodothis) {
      if(scantype==PlottingSetup::mSUGRA && TString(limits[ilim]->GetName()).Contains("_XS")) AbsCrossSection.push_back(limits[ilim]);
      if(scantype==PlottingSetup::mSUGRA && TString(limits[ilim]->GetName()).Contains("_absXS")) crosssections	.push_back(limits[ilim]);
      if(scantype==PlottingSetup::mSUGRA && TString(limits[ilim]->GetName()).Contains("_XS")) FilterEfficiencies.push_back(limits[ilim]);
    }
    if(TString(limits[ilim]->GetName()).Contains("_limitmap")) obslimits.push_back(limits[ilim]);
//    if(TString(limits[ilim]->GetName()).Contains("_limitflipmap")) flipmaps.push_back(limits[ilim]);
  }
    
cout << "Size: " << AbsCrossSection.size() << endl;
  TH2F *xsec;
  if(scantype!=PlottingSetup::mSUGRA) xsec = adjust_histo(get_XS(xsecfilename,"gluino",obslimits[0]),obslimits[0]);
  vector<TH2F*> bestexplimits;
  TH2F *bestlimits = make_best_limits(explimits,obslimits,scantype, scanx, exp1mlimits, exp1plimits, exp2mlimits, exp2plimits, bestexplimits);
  bestlimits->GetZaxis()->SetRangeUser(limits_lower_bound,limits_upper_bound);

  for(int ilim=0;ilim<(int)limits.size();ilim++) {
    limits[ilim]->GetZaxis()->SetRangeUser(limits_lower_bound,limits_upper_bound);
  }
  
  if(scantype!=PlottingSetup::mSUGRA) {
    for(int ilim=0;ilim<(int)obslimits.size();ilim++) make_SMS_exclusion(obslimits[ilim],xsec,scantype,scanx,true);
    for(int ilim=0;ilim<(int)obslimits.size();ilim++) make_SMS_exclusion(explimits[ilim],xsec,scantype,scanx,false);//plotting expected limits
    make_SMS_exclusion(bestlimits,xsec,scantype,scanx,true);
  } else {
    for(int ilim=0;ilim<(int)obslimits.size();ilim++) {
      draw_mSUGRA_exclusion(crosssections[0],FilterEfficiencies[0],AbsCrossSection[0],obslimits[ilim], explimits[ilim], exp1mlimits[ilim], exp1plimits[ilim], exp2mlimits[ilim], exp2plimits[ilim],true);
      draw_mSUGRA_exclusion(crosssections[0],FilterEfficiencies[0],AbsCrossSection[0],explimits[ilim], explimits[ilim], exp1mlimits[ilim], exp1plimits[ilim], exp2mlimits[ilim], exp2plimits[ilim],false);
    }
    draw_mSUGRA_exclusion(crosssections[0],FilterEfficiencies[0],AbsCrossSection[0],bestlimits, bestexplimits[0], bestexplimits[1], bestexplimits[2], bestexplimits[3], bestexplimits[4],true);
  }
  delete bestlimits;
}
Example #18
0
void mass4Chan(){
//=========Macro generated from canvas: ccc/
//=========  (Thu Mar  7 22:11:11 2013) by ROOT version5.34/03
   TCanvas *ccc = new TCanvas("ccc", "",0,0,600,600);
   gStyle->SetOptFit(1);
   gStyle->SetOptStat(0);
   gStyle->SetOptTitle(0);
   ccc->Range(86.5625,-1.875,92.8125,10.625);
   ccc->SetFillColor(0);
   ccc->SetBorderMode(0);
   ccc->SetBorderSize(2);
   ccc->SetLeftMargin(0.15);
   ccc->SetRightMargin(0.05);
   ccc->SetTopMargin(0.05);
   ccc->SetBottomMargin(0.15);
   ccc->SetFrameFillStyle(0);
   ccc->SetFrameBorderMode(0);
   ccc->SetFrameFillStyle(0);
   ccc->SetFrameBorderMode(0);
   
  

   
   TH2F *hframe = new TH2F("hframe","",100,85,96,100,0,10);
   hframe->SetLineStyle(0);
   hframe->SetMarkerStyle(20);
   hframe->GetXaxis()->SetTitle(" m_{Z} (GeV)");
   hframe->GetXaxis()->SetNdivisions(510);
   hframe->GetXaxis()->SetLabelFont(42);
   hframe->GetXaxis()->SetLabelOffset(0.01);
   hframe->GetXaxis()->SetLabelSize(0.05);
   hframe->GetXaxis()->SetTitleSize(0.05);
   hframe->GetXaxis()->SetTitleOffset(1.15);
   hframe->GetXaxis()->SetTitleFont(42);
   hframe->GetYaxis()->SetTitle(" -2#Delta ln L");
   hframe->GetYaxis()->SetLabelFont(42);
   hframe->GetYaxis()->SetLabelOffset(0.01);
   hframe->GetYaxis()->SetLabelSize(0.05);
   hframe->GetYaxis()->SetTitleSize(0.05);
   hframe->GetYaxis()->SetTitleOffset(1.4);
   hframe->GetYaxis()->SetTitleFont(42);
   hframe->GetZaxis()->SetLabelFont(42);
   hframe->GetZaxis()->SetLabelOffset(0.007);
   hframe->GetZaxis()->SetLabelSize(0.045);
   hframe->GetZaxis()->SetTitleSize(0.05);
   hframe->GetZaxis()->SetTitleFont(42);
   hframe->Draw("");
   
   //4e
   TGraph *graph = new TGraph(211);
   graph->SetName("Graph");
   graph->SetTitle("Graph");
   graph->SetLineColor(kGreen+1);
   graph->SetLineWidth(3);
   graph->SetMarkerStyle(20);
   graph->SetPoint(0,88.01999664,7.234320164);
   graph->SetPoint(1,88.05999756,7.121326923);
   graph->SetPoint(2,88.09999847,7.008939743);
   graph->SetPoint(3,88.13999939,6.897168636);
   graph->SetPoint(4,88.18000031,6.786022186);
   graph->SetPoint(5,88.22000122,6.67550993);
   graph->SetPoint(6,88.26000214,6.565642357);
   graph->SetPoint(7,88.30000305,6.456428051);
   graph->SetPoint(8,88.33999634,6.347877979);
   graph->SetPoint(9,88.37999725,6.240002632);
   graph->SetPoint(10,88.41999817,6.1328125);
   graph->SetPoint(11,88.45999908,6.026317596);
   graph->SetPoint(12,88.5,5.920529366);
   graph->SetPoint(13,88.54000092,5.815458775);
   graph->SetPoint(14,88.58000183,5.711116314);
   graph->SetPoint(15,88.62000275,5.607512951);
   graph->SetPoint(16,88.66000366,5.504659653);
   graph->SetPoint(17,88.69999695,5.402567387);
   graph->SetPoint(18,88.73999786,5.301246643);
   graph->SetPoint(19,88.77999878,5.200707436);
   graph->SetPoint(20,88.81999969,5.100960732);
   graph->SetPoint(21,88.81999969,5.100960732);
   graph->SetPoint(22,88.86000061,5.002016068);
   graph->SetPoint(23,88.90000153,4.903883457);
   graph->SetPoint(24,88.94000244,4.806572437);
   graph->SetPoint(25,88.98000336,4.710093021);
   graph->SetPoint(26,89.01999664,4.614454269);
   graph->SetPoint(27,89.05999756,4.519664764);
   graph->SetPoint(28,89.09999847,4.425733089);
   graph->SetPoint(29,89.13999939,4.332668304);
   graph->SetPoint(30,89.18000031,4.240478516);
   graph->SetPoint(31,89.22000122,4.149171829);
   graph->SetPoint(32,89.26000214,4.058755875);
   graph->SetPoint(33,89.30000305,3.969237804);
   graph->SetPoint(34,89.33999634,3.880625486);
   graph->SetPoint(35,89.37999725,3.792925596);
   graph->SetPoint(36,89.41999817,3.706145048);
   graph->SetPoint(37,89.45999908,3.620290518);
   graph->SetPoint(38,89.5,3.535368204);
   graph->SetPoint(39,89.54000092,3.451384068);
   graph->SetPoint(40,89.58000183,3.368344069);
   graph->SetPoint(41,89.62000275,3.286253691);
   graph->SetPoint(42,89.62000275,3.286253691);
   graph->SetPoint(43,89.66000366,3.205118656);
   graph->SetPoint(44,89.69999695,3.124943733);
   graph->SetPoint(45,89.73999786,3.045734167);
   graph->SetPoint(46,89.77999878,2.967494488);
   graph->SetPoint(47,89.81999969,2.890229225);
   graph->SetPoint(48,89.86000061,2.813942432);
   graph->SetPoint(49,89.90000153,2.738638639);
   graph->SetPoint(50,89.94000244,2.664321423);
   graph->SetPoint(51,89.98000336,2.590994596);
   graph->SetPoint(52,90.01999664,2.518661499);
   graph->SetPoint(53,90.05999756,2.447325468);
   graph->SetPoint(54,90.09999847,2.376989603);
   graph->SetPoint(55,90.13999939,2.307657003);
   graph->SetPoint(56,90.18000031,2.23933053);
   graph->SetPoint(57,90.22000122,2.172012329);
   graph->SetPoint(58,90.26000214,2.105705023);
   graph->SetPoint(59,90.30000305,2.040410995);
   graph->SetPoint(60,90.33999634,1.976132512);
   graph->SetPoint(61,90.37999725,1.912871242);
   graph->SetPoint(62,90.41999817,1.85062921);
   graph->SetPoint(63,90.41999817,1.85062921);
   graph->SetPoint(64,90.45999908,1.789408088);
   graph->SetPoint(65,90.5,1.729209423);
   graph->SetPoint(66,90.54000092,1.670034766);
   graph->SetPoint(67,90.58000183,1.611885428);
   graph->SetPoint(68,90.62000275,1.554762602);
   graph->SetPoint(69,90.66000366,1.498667479);
   graph->SetPoint(70,90.69999695,1.443601012);
   graph->SetPoint(71,90.73999786,1.389564157);
   graph->SetPoint(72,90.77999878,1.336557865);
   graph->SetPoint(73,90.81999969,1.284582734);
   graph->SetPoint(74,90.86000061,1.233639359);
   graph->SetPoint(75,90.90000153,1.183728576);
   graph->SetPoint(76,90.94000244,1.134850621);
   graph->SetPoint(77,90.98000336,1.087006092);
   graph->SetPoint(78,91.01999664,1.040195346);
   graph->SetPoint(79,91.05999756,0.9944185615);
   graph->SetPoint(80,91.09999847,0.9496760368);
   graph->SetPoint(81,91.13999939,0.9059679508);
   graph->SetPoint(82,91.18000031,0.8632944226);
   graph->SetPoint(83,91.22000122,0.8216554523);
   graph->SetPoint(84,91.22000122,0.8216554523);
   graph->SetPoint(85,91.26000214,0.7810510397);
   graph->SetPoint(86,91.30000305,0.7414811254);
   graph->SetPoint(87,91.33999634,0.70294559);
   graph->SetPoint(88,91.37999725,0.6654443145);
   graph->SetPoint(89,91.41999817,0.6289771199);
   graph->SetPoint(90,91.45999908,0.5935436487);
   graph->SetPoint(91,91.5,0.5591436625);
   graph->SetPoint(92,91.54000092,0.5257768631);
   graph->SetPoint(93,91.58000183,0.4934427738);
   graph->SetPoint(94,91.62000275,0.462141037);
   graph->SetPoint(95,91.66000366,0.431871146);
   graph->SetPoint(96,91.69999695,0.4026326835);
   graph->SetPoint(97,91.73999786,0.3744250238);
   graph->SetPoint(98,91.77999878,0.3472476304);
   graph->SetPoint(99,91.81999969,0.3210999072);
   graph->SetPoint(100,91.86000061,0.2959812582);
   graph->SetPoint(101,91.90000153,0.2718909979);
   graph->SetPoint(102,91.94000244,0.2488284409);
   graph->SetPoint(103,91.98000336,0.2267929316);
   graph->SetPoint(104,92.01999664,0.2057837248);
   graph->SetPoint(105,92.01999664,0.2057837248);
   graph->SetPoint(106,92.05999756,0.1858001053);
   graph->SetPoint(107,92.09999847,0.1668412983);
   graph->SetPoint(108,92.13999939,0.1489065737);
   graph->SetPoint(109,92.18000031,0.1319951713);
   graph->SetPoint(110,92.22000122,0.1161063388);
   graph->SetPoint(111,92.26000214,0.1012392938);
   graph->SetPoint(112,92.30000305,0.08739329875);
   graph->SetPoint(113,92.33999634,0.07456759363);
   graph->SetPoint(114,92.37999725,0.06276145577);
   graph->SetPoint(115,92.41999817,0.05197418481);
   graph->SetPoint(116,92.45999908,0.04220509902);
   graph->SetPoint(117,92.5,0.03345353901);
   graph->SetPoint(118,92.54000092,0.02571888082);
   graph->SetPoint(119,92.58000183,0.01900054142);
   graph->SetPoint(120,92.62000275,0.01329800207);
   graph->SetPoint(121,92.66000366,0.008610763587);
   graph->SetPoint(122,92.69999695,0.004938419908);
   graph->SetPoint(123,92.73999786,0.002280603396);
   graph->SetPoint(124,92.77999878,0.0006370125338);
   graph->SetPoint(125,92.81999969,7.419047051e-06);
   //graph->SetPoint(126,92.81999969,7.419047961e-06);
   graph->SetPoint(127,92.82485199,0);
   graph->SetPoint(128,92.82485199,0);
   graph->SetPoint(129,92.82485199,0);
   graph->SetPoint(130,92.82485199,0);
   graph->SetPoint(131,92.82485199,0);
   graph->SetPoint(132,92.82485199,0);
   graph->SetPoint(133,92.82485199,0);
   graph->SetPoint(134,93.05999756,0.01752127893);
   graph->SetPoint(135,93.09999847,0.02399016172);
   graph->SetPoint(136,93.13999939,0.0314742066);
   graph->SetPoint(137,93.18000031,0.03997394815);
   graph->SetPoint(138,93.22000122,0.04949002713);
   graph->SetPoint(139,93.26000214,0.06002314016);
   graph->SetPoint(140,93.30000305,0.07157406956);
   graph->SetPoint(141,93.33999634,0.08414366841);
   graph->SetPoint(142,93.37999725,0.09773286432);
   graph->SetPoint(143,93.41999817,0.1123426482);
   graph->SetPoint(144,93.45999908,0.1279740632);
   graph->SetPoint(145,93.5,0.144628197);
   graph->SetPoint(146,93.54000092,0.1623062044);
   graph->SetPoint(147,93.58000183,0.1810092628);
   graph->SetPoint(148,93.62000275,0.200738579);
   graph->SetPoint(149,93.62000275,0.200738579);
   graph->SetPoint(150,93.66000366,0.2214953899);
   graph->SetPoint(151,93.69999695,0.2432809174);
   graph->SetPoint(152,93.73999786,0.2660964429);
   graph->SetPoint(153,93.77999878,0.2899431586);
   graph->SetPoint(154,93.81999969,0.3148224056);
   graph->SetPoint(155,93.86000061,0.3407353461);
   graph->SetPoint(156,93.90000153,0.367683202);
   graph->SetPoint(157,93.94000244,0.3956672251);
   graph->SetPoint(158,93.98000336,0.4246885478);
   graph->SetPoint(159,94.01999664,0.4547482729);
   graph->SetPoint(160,94.05999756,0.4858476222);
   graph->SetPoint(161,94.09999847,0.5179876089);
   graph->SetPoint(162,94.13999939,0.5511692166);
   graph->SetPoint(163,94.18000031,0.585393548);
   graph->SetPoint(164,94.22000122,0.6206615567);
   graph->SetPoint(165,94.26000214,0.6569740772);
   graph->SetPoint(166,94.30000305,0.6943320632);
   graph->SetPoint(167,94.33999634,0.7327364087);
   graph->SetPoint(168,94.37999725,0.772187829);
   graph->SetPoint(169,94.41999817,0.8126871586);
   graph->SetPoint(170,94.41999817,0.8126871586);
   graph->SetPoint(171,94.45999908,0.8542351723);
   graph->SetPoint(172,94.5,0.8968324661);
   graph->SetPoint(173,94.54000092,0.940479815);
   graph->SetPoint(174,94.58000183,0.985177815);
   graph->SetPoint(175,94.62000275,1.030927062);
   graph->SetPoint(176,94.66000366,1.077728152);
   graph->SetPoint(177,94.69999695,1.125581622);
   graph->SetPoint(178,94.73999786,1.174487948);
   graph->SetPoint(179,94.77999878,1.224447489);
   graph->SetPoint(180,94.81999969,1.27546072);
   graph->SetPoint(181,94.86000061,1.327528);
   graph->SetPoint(182,94.90000153,1.380649686);
   graph->SetPoint(183,94.94000244,1.434825897);
   graph->SetPoint(184,94.98000336,1.490056992);
   graph->SetPoint(185,95.01999664,1.546342969);
   graph->SetPoint(186,95.05999756,1.603683949);
   graph->SetPoint(187,95.09999847,1.66207993);
   graph->SetPoint(188,95.13999939,1.721530676);
   graph->SetPoint(189,95.18000031,1.782036185);
   graph->SetPoint(190,95.22000122,1.843595982);
   graph->SetPoint(191,95.22000122,1.843595982);
   graph->SetPoint(192,95.26000214,1.906209826);
   graph->SetPoint(193,95.30000305,1.969877124);
   graph->SetPoint(194,95.33999634,2.034597158);
   graph->SetPoint(195,95.37999725,2.100369453);
   graph->SetPoint(196,95.41999817,2.167192936);
   graph->SetPoint(197,95.45999908,2.235066652);
   graph->SetPoint(198,95.5,2.30398941);
   graph->SetPoint(199,95.54000092,2.37395978);
   graph->SetPoint(200,95.58000183,2.44497633);
   graph->SetPoint(201,95.62000275,2.517037392);
   graph->SetPoint(202,95.66000366,2.590141296);
   graph->SetPoint(203,95.69999695,2.66428566);
   graph->SetPoint(204,95.73999786,2.739468575);
   graph->SetPoint(205,95.77999878,2.815687418);
   graph->SetPoint(206,95.81999969,2.892939568);
   graph->SetPoint(207,95.86000061,2.971222401);
   graph->SetPoint(208,95.90000153,3.050532341);
   graph->SetPoint(209,95.94000244,3.130866289);
   graph->SetPoint(210,95.98000336,3.212220907);


   graph->Sort();

   cout << "4e: " << graph->Eval(91.1876) << endl;


   //2e2mu
   TGraph *graph1 = new TGraph(211);
   graph1->SetName("Graph1");
   graph1->SetTitle("Graph1");
   graph1->SetFillColor(1);
   graph1->SetLineWidth(3);
   graph1->SetLineColor(kBlue);
   graph1->SetMarkerStyle(20);
   graph1->SetPoint(0,88.01999664,8.795412064);
   graph1->SetPoint(1,88.05999756,8.61370182);
   graph1->SetPoint(2,88.09999847,8.43285656);
   graph1->SetPoint(3,88.13999939,8.252916336);
   graph1->SetPoint(4,88.18000031,8.073918343);
   graph1->SetPoint(5,88.22000122,7.895903111);
   graph1->SetPoint(6,88.26000214,7.718908787);
   graph1->SetPoint(7,88.30000305,7.542974472);
   graph1->SetPoint(8,88.33999634,7.36813879);
   graph1->SetPoint(9,88.37999725,7.194441795);
   graph1->SetPoint(10,88.41999817,7.021921158);
   graph1->SetPoint(11,88.45999908,6.850616932);
   graph1->SetPoint(12,88.5,6.680567265);
   graph1->SetPoint(13,88.54000092,6.51181221);
   graph1->SetPoint(14,88.58000183,6.344389915);
   graph1->SetPoint(15,88.62000275,6.178339481);
   graph1->SetPoint(16,88.66000366,6.013700008);
   graph1->SetPoint(17,88.69999695,5.850510597);
   graph1->SetPoint(18,88.73999786,5.688809872);
   graph1->SetPoint(19,88.77999878,5.528635979);
   graph1->SetPoint(20,88.81999969,5.370028496);
   graph1->SetPoint(21,88.81999969,5.370028496);
   graph1->SetPoint(22,88.86000061,5.21302557);
   graph1->SetPoint(23,88.90000153,5.057665825);
   graph1->SetPoint(24,88.94000244,4.903987885);
   graph1->SetPoint(25,88.98000336,4.752028942);
   graph1->SetPoint(26,89.01999664,4.601828575);
   graph1->SetPoint(27,89.05999756,4.4534235);
   graph1->SetPoint(28,89.09999847,4.306852341);
   graph1->SetPoint(29,89.13999939,4.162151814);
   graph1->SetPoint(30,89.18000031,4.019360065);
   graph1->SetPoint(31,89.22000122,3.87851429);
   graph1->SetPoint(32,89.26000214,3.739651203);
   graph1->SetPoint(33,89.30000305,3.602807283);
   graph1->SetPoint(34,89.33999634,3.468019247);
   graph1->SetPoint(35,89.37999725,3.335323095);
   graph1->SetPoint(36,89.41999817,3.204754591);
   graph1->SetPoint(37,89.45999908,3.076349258);
   graph1->SetPoint(38,89.5,2.950142145);
   graph1->SetPoint(39,89.54000092,2.82616806);
   graph1->SetPoint(40,89.58000183,2.704461336);
   graph1->SetPoint(41,89.62000275,2.58505559);
   graph1->SetPoint(42,89.62000275,2.58505559);
   graph1->SetPoint(43,89.66000366,2.467984438);
   graph1->SetPoint(44,89.69999695,2.353280783);
   graph1->SetPoint(45,89.73999786,2.240977049);
   graph1->SetPoint(46,89.77999878,2.131105185);
   graph1->SetPoint(47,89.81999969,2.023696423);
   graph1->SetPoint(48,89.86000061,1.918781519);
   graph1->SetPoint(49,89.90000153,1.816390634);
   graph1->SetPoint(50,89.94000244,1.716553092);
   graph1->SetPoint(51,89.98000336,1.619297981);
   graph1->SetPoint(52,90.01999664,1.524653077);
   graph1->SetPoint(53,90.05999756,1.432646155);
   graph1->SetPoint(54,90.09999847,1.343303561);
   graph1->SetPoint(55,90.13999939,1.256651402);
   graph1->SetPoint(56,90.18000031,1.17271471);
   graph1->SetPoint(57,90.22000122,1.091517925);
   graph1->SetPoint(58,90.26000214,1.013084531);
   graph1->SetPoint(59,90.30000305,0.9374370575);
   graph1->SetPoint(60,90.33999634,0.864597559);
   graph1->SetPoint(61,90.37999725,0.7945868969);
   graph1->SetPoint(62,90.41999817,0.727425158);
   graph1->SetPoint(63,90.41999817,0.727425158);
   graph1->SetPoint(64,90.45999908,0.6631317139);
   graph1->SetPoint(65,90.5,0.6017247438);
   graph1->SetPoint(66,90.54000092,0.5432218313);
   graph1->SetPoint(67,90.58000183,0.4876395166);
   graph1->SetPoint(68,90.62000275,0.4349934459);
   graph1->SetPoint(69,90.66000366,0.3852983713);
   graph1->SetPoint(70,90.69999695,0.3385681808);
   graph1->SetPoint(71,90.73999786,0.2948157787);
   graph1->SetPoint(72,90.77999878,0.2540532351);
   graph1->SetPoint(73,90.81999969,0.2162916809);
   graph1->SetPoint(74,90.86000061,0.1815413088);
   graph1->SetPoint(75,90.90000153,0.1498114169);
   graph1->SetPoint(76,90.94000244,0.1211103573);
   graph1->SetPoint(77,90.98000336,0.09544557333);
   graph1->SetPoint(78,91.01999664,0.07282357663);
   graph1->SetPoint(79,91.05999756,0.05324992537);
   graph1->SetPoint(80,91.09999847,0.0367292501);
   graph1->SetPoint(81,91.13999939,0.02326522022);
   graph1->SetPoint(82,91.18000031,0.01286056917);
   graph1->SetPoint(83,91.22000122,0.005517064128);
   graph1->SetPoint(84,91.22000122,0.005517064128);
   graph1->SetPoint(85,91.26000214,0.001235519536);
   graph1->SetPoint(86,91.29593658,0);
   graph1->SetPoint(87,91.29593658,0);
   graph1->SetPoint(88,91.29593658,0);
   graph1->SetPoint(89,91.29593658,0);
   graph1->SetPoint(90,91.29593658,0);
   graph1->SetPoint(91,91.29593658,0);
   graph1->SetPoint(92,91.29593658,0);
   graph1->SetPoint(93,91.5,0.03977194428);
   graph1->SetPoint(94,91.54000092,0.05686627701);
   graph1->SetPoint(95,91.58000183,0.07699460536);
   graph1->SetPoint(96,91.62000275,0.1001491994);
   graph1->SetPoint(97,91.66000366,0.1263214052);
   graph1->SetPoint(98,91.69999695,0.1555016339);
   graph1->SetPoint(99,91.73999786,0.1876795292);
   graph1->SetPoint(100,91.77999878,0.2228437364);
   graph1->SetPoint(101,91.81999969,0.260982126);
   graph1->SetPoint(102,91.86000061,0.3020817041);
   graph1->SetPoint(103,91.90000153,0.3461286724);
   graph1->SetPoint(104,91.94000244,0.3931084573);
   graph1->SetPoint(105,91.98000336,0.443005681);
   graph1->SetPoint(106,92.01999664,0.4958042502);
   //graph1->SetPoint(107,92.01999664,0.4958042204);
   graph1->SetPoint(108,92.05999756,0.551487267);
   graph1->SetPoint(109,92.09999847,0.6100373268);
   graph1->SetPoint(110,92.13999939,0.671436131);
   graph1->SetPoint(111,92.18000031,0.7356648445);
   graph1->SetPoint(112,92.22000122,0.802703917);
   graph1->SetPoint(113,92.26000214,0.872533381);
   graph1->SetPoint(114,92.30000305,0.945132494);
   graph1->SetPoint(115,92.33999634,1.020480037);
   graph1->SetPoint(116,92.37999725,1.098554254);
   graph1->SetPoint(117,92.41999817,1.179333091);
   graph1->SetPoint(118,92.45999908,1.262793779);
   graph1->SetPoint(119,92.5,1.348913193);
   graph1->SetPoint(120,92.54000092,1.437667727);
   graph1->SetPoint(121,92.58000183,1.52903378);
   graph1->SetPoint(122,92.62000275,1.622986913);
   graph1->SetPoint(123,92.66000366,1.719502687);
   graph1->SetPoint(124,92.69999695,1.818556309);
   graph1->SetPoint(125,92.73999786,1.920122623);
   graph1->SetPoint(126,92.77999878,2.024176359);
   graph1->SetPoint(127,92.81999969,2.130692005);
   graph1->SetPoint(128,92.81999969,2.130692005);
   graph1->SetPoint(129,92.86000061,2.239643812);
   graph1->SetPoint(130,92.90000153,2.351006031);
   graph1->SetPoint(131,92.94000244,2.464752674);
   graph1->SetPoint(132,92.98000336,2.580857754);
   graph1->SetPoint(133,93.01999664,2.699294806);
   graph1->SetPoint(134,93.05999756,2.820037603);
   graph1->SetPoint(135,93.09999847,2.94306016);
   graph1->SetPoint(136,93.13999939,3.068335533);
   graph1->SetPoint(137,93.18000031,3.195837736);
   graph1->SetPoint(138,93.22000122,3.325540066);
   graph1->SetPoint(139,93.26000214,3.457416296);
   graph1->SetPoint(140,93.30000305,3.591439486);
   graph1->SetPoint(141,93.33999634,3.727583647);
   graph1->SetPoint(142,93.37999725,3.865821838);
   graph1->SetPoint(143,93.41999817,4.006127834);
   graph1->SetPoint(144,93.45999908,4.148474216);
   graph1->SetPoint(145,93.5,4.292835712);
   graph1->SetPoint(146,93.54000092,4.439184189);
   graph1->SetPoint(147,93.58000183,4.587494373);
   graph1->SetPoint(148,93.62000275,4.737738609);
   graph1->SetPoint(149,93.62000275,4.737738609);
   graph1->SetPoint(150,93.66000366,4.889890194);
   graph1->SetPoint(151,93.69999695,5.043922424);
   graph1->SetPoint(152,93.73999786,5.199808598);
   graph1->SetPoint(153,93.77999878,5.357521057);
   graph1->SetPoint(154,93.81999969,5.517033577);
   graph1->SetPoint(155,93.86000061,5.678318024);
   graph1->SetPoint(156,93.90000153,5.841347694);
   graph1->SetPoint(157,93.94000244,6.006094933);
   graph1->SetPoint(158,93.98000336,6.172532082);
   graph1->SetPoint(159,94.01999664,6.340631485);
   graph1->SetPoint(160,94.05999756,6.510365486);
   graph1->SetPoint(161,94.09999847,6.681705952);
   graph1->SetPoint(162,94.13999939,6.854624748);
   graph1->SetPoint(163,94.18000031,7.029093266);
   graph1->SetPoint(164,94.22000122,7.205083847);
   graph1->SetPoint(165,94.26000214,7.382567883);
   graph1->SetPoint(166,94.30000305,7.561516285);
   graph1->SetPoint(167,94.33999634,7.741900921);
   graph1->SetPoint(168,94.37999725,7.923692226);
   graph1->SetPoint(169,94.41999817,8.106862068);
   graph1->SetPoint(170,94.41999817,8.106862068);
   graph1->SetPoint(171,94.45999908,8.291379929);
   graph1->SetPoint(172,94.5,8.477218628);
   graph1->SetPoint(173,94.54000092,8.664347649);
   graph1->SetPoint(174,94.58000183,8.85273838);
   graph1->SetPoint(175,94.62000275,9.042361259);
   graph1->SetPoint(176,94.66000366,9.233187675);
   graph1->SetPoint(177,94.69999695,9.425187111);
   graph1->SetPoint(178,94.73999786,9.618330002);
   graph1->SetPoint(179,94.77999878,9.812587738);
   graph1->SetPoint(180,94.81999969,10.00793171);
   graph1->SetPoint(181,94.86000061,10.20433044);
   graph1->SetPoint(182,94.90000153,10.40175724);
   graph1->SetPoint(183,94.94000244,10.60017967);
   graph1->SetPoint(184,94.98000336,10.79957104);
   graph1->SetPoint(185,95.01999664,10.99990082);
   graph1->SetPoint(186,95.05999756,11.20113945);
   graph1->SetPoint(187,95.09999847,11.40325832);
   graph1->SetPoint(188,95.13999939,11.60622883);
   graph1->SetPoint(189,95.18000031,11.81002045);
   graph1->SetPoint(190,95.22000122,12.01460457);
   graph1->SetPoint(191,95.22000122,12.01460457);
   graph1->SetPoint(192,95.26000214,12.21995258);
   graph1->SetPoint(193,95.30000305,12.42603588);
   graph1->SetPoint(194,95.33999634,12.63282394);
   graph1->SetPoint(195,95.37999725,12.84028816);
   graph1->SetPoint(196,95.41999817,13.04840088);
   graph1->SetPoint(197,95.45999908,13.25713253);
   graph1->SetPoint(198,95.5,13.46645451);
   graph1->SetPoint(199,95.54000092,13.6763382);
   graph1->SetPoint(200,95.58000183,13.88675499);
   graph1->SetPoint(201,95.62000275,14.09767723);
   graph1->SetPoint(202,95.66000366,14.3090744);
   graph1->SetPoint(203,95.69999695,14.5209198);
   graph1->SetPoint(204,95.73999786,14.73318481);
   graph1->SetPoint(205,95.77999878,14.94584179);
   graph1->SetPoint(206,95.81999969,15.15886116);
   graph1->SetPoint(207,95.86000061,15.37221718);
   graph1->SetPoint(208,95.90000153,15.58588123);
   graph1->SetPoint(209,95.94000244,15.79982567);
   graph1->SetPoint(210,95.98000336,16.01402283);

   
   graph1->Sort();
   
   cout<< "2e2mu: " << graph1->Eval(91.1876) << endl;


   //4mu
   TGraph *graph2 = new TGraph(216);
   graph2->SetName("Graph2");
   graph2->SetTitle("Graph2");
   graph2->SetFillColor(1);
   graph2->SetLineWidth(3);
   graph2->SetLineColor(kRed);
   graph2->SetMarkerStyle(20);
   graph2->SetPoint(0,88.01999664,42.99673462);
   graph2->SetPoint(1,88.05999756,42.01807404);
   graph2->SetPoint(2,88.09999847,41.04578781);
   graph2->SetPoint(3,88.13999939,40.08004379);
   graph2->SetPoint(4,88.18000031,39.12101746);
   graph2->SetPoint(5,88.22000122,38.16888046);
   graph2->SetPoint(6,88.26000214,37.22380447);
   graph2->SetPoint(7,88.30000305,36.2859726);
   graph2->SetPoint(8,88.33999634,35.35555267);
   graph2->SetPoint(9,88.37999725,34.43272781);
   graph2->SetPoint(10,88.41999817,33.51767731);
   graph2->SetPoint(11,88.45999908,32.61057281);
   graph2->SetPoint(12,88.5,31.71160507);
   graph2->SetPoint(13,88.54000092,30.82094765);
   graph2->SetPoint(14,88.58000183,29.93878746);
   graph2->SetPoint(15,88.62000275,29.06530762);
   graph2->SetPoint(16,88.66000366,28.20069313);
   graph2->SetPoint(17,88.69999695,27.34512901);
   graph2->SetPoint(18,88.73999786,26.49880409);
   graph2->SetPoint(19,88.77999878,25.66190529);
   graph2->SetPoint(20,88.81999969,24.83462334);
   graph2->SetPoint(21,88.81999969,24.83462334);
   graph2->SetPoint(22,88.86000061,24.01715088);
   graph2->SetPoint(23,88.90000153,23.20967865);
   graph2->SetPoint(24,88.94000244,22.41239929);
   graph2->SetPoint(25,88.98000336,21.62551308);
   graph2->SetPoint(26,89.01999664,20.84921074);
   graph2->SetPoint(27,89.05999756,20.08369446);
   graph2->SetPoint(28,89.09999847,19.32916451);
   graph2->SetPoint(29,89.13999939,18.58581734);
   graph2->SetPoint(30,89.18000031,17.85385895);
   graph2->SetPoint(31,89.22000122,17.13349152);
   graph2->SetPoint(32,89.26000214,16.42491913);
   graph2->SetPoint(33,89.30000305,15.72835064);
   graph2->SetPoint(34,89.33999634,15.04399014);
   graph2->SetPoint(35,89.37999725,14.37204742);
   graph2->SetPoint(36,89.41999817,13.71273041);
   graph2->SetPoint(37,89.45999908,13.0662508);
   graph2->SetPoint(38,89.5,12.43281651);
   graph2->SetPoint(39,89.54000092,11.81264019);
   graph2->SetPoint(40,89.58000183,11.20593262);
   graph2->SetPoint(41,89.62000275,10.6129055);
   graph2->SetPoint(42,89.62000275,10.6129055);
   graph2->SetPoint(43,89.66000366,10.03376961);
   graph2->SetPoint(44,89.69999695,9.468736649);
   graph2->SetPoint(45,89.73999786,8.918016434);
   graph2->SetPoint(46,89.77999878,8.381820679);
   graph2->SetPoint(47,89.81999969,7.860357285);
   graph2->SetPoint(48,89.86000061,7.353835583);
   graph2->SetPoint(49,89.90000153,6.862462997);
   graph2->SetPoint(50,89.94000244,6.386445045);
   graph2->SetPoint(51,89.98000336,5.92598629);
   graph2->SetPoint(52,90.01999664,5.481288433);
   graph2->SetPoint(53,90.05999756,5.0525527);
   graph2->SetPoint(54,90.09999847,4.639976501);
   graph2->SetPoint(55,90.13999939,4.243755817);
   graph2->SetPoint(56,90.18000031,3.864083052);
   graph2->SetPoint(57,90.22000122,3.501147509);
   graph2->SetPoint(58,90.26000214,3.155135393);
   graph2->SetPoint(59,90.30000305,2.826228619);
   graph2->SetPoint(60,90.33999634,2.514605522);
   graph2->SetPoint(61,90.37999725,2.220438957);
   graph2->SetPoint(62,90.41999817,1.943897605);
   graph2->SetPoint(63,90.41999817,1.943897605);
   graph2->SetPoint(64,90.45999908,1.685144305);
   graph2->SetPoint(65,90.5,1.444335938);
   graph2->SetPoint(66,90.54000092,1.221622825);
   graph2->SetPoint(67,90.58000183,1.017148852);
   graph2->SetPoint(68,90.62000275,0.8310500383);
   graph2->SetPoint(69,90.66000366,0.663454473);
   graph2->SetPoint(70,90.69999695,0.5144816637);
   graph2->SetPoint(71,90.73999786,0.3842421472);
   graph2->SetPoint(72,90.77999878,0.2728365958);
   graph2->SetPoint(73,90.81999969,0.1803556085);
   graph2->SetPoint(74,90.86000061,0.1068789586);
   graph2->SetPoint(75,90.90000153,0.05247514695);
   graph2->SetPoint(76,90.94000244,0.01720083691);
   graph2->SetPoint(77,90.98000336,0.00110038009);
   graph2->SetPoint(78,90.9935379,0);
   graph2->SetPoint(79,90.9935379,0);
   graph2->SetPoint(80,90.9935379,0);
   graph2->SetPoint(81,90.9935379,0);
   graph2->SetPoint(82,90.9935379,0);
   graph2->SetPoint(83,90.9935379,0);
   graph2->SetPoint(84,90.9935379,0);
   graph2->SetPoint(85,91.01999664,0.004205350298);
   graph2->SetPoint(86,91.05999756,0.02653408609);
   graph2->SetPoint(87,91.09999847,0.06809128821);
   graph2->SetPoint(88,91.13999939,0.1288676411);
   graph2->SetPoint(89,91.18000031,0.208839491);
   graph2->SetPoint(90,91.22000122,0.3079685569);
   graph2->SetPoint(91,91.22000122,0.3079685569);
   graph2->SetPoint(92,91.26000214,0.4262017608);
   graph2->SetPoint(93,91.30000305,0.5634709001);
   graph2->SetPoint(94,91.33999634,0.7196927667);
   graph2->SetPoint(95,91.37999725,0.8947688341);
   graph2->SetPoint(96,91.41999817,1.088585615);
   graph2->SetPoint(97,91.45999908,1.301014304);
   graph2->SetPoint(98,91.5,1.531911612);
   graph2->SetPoint(99,91.54000092,1.781119347);
   graph2->SetPoint(100,91.58000183,2.048465252);
   graph2->SetPoint(101,91.62000275,2.333762884);
   graph2->SetPoint(102,91.66000366,2.636813402);
   graph2->SetPoint(103,91.69999695,2.957404137);
   graph2->SetPoint(104,91.73999786,3.295311213);
   graph2->SetPoint(105,91.77999878,3.650299788);
   graph2->SetPoint(106,91.81999969,4.022123814);
   graph2->SetPoint(107,91.86000061,4.410528183);
   graph2->SetPoint(108,91.90000153,4.815249443);
   graph2->SetPoint(109,91.94000244,5.23601675);
   graph2->SetPoint(110,91.98000336,5.672553062);
   graph2->SetPoint(111,92.01999664,6.124575138);
   graph2->SetPoint(112,92.01999664,6.124575138);
   graph2->SetPoint(113,92.05999756,6.591795921);
   graph2->SetPoint(114,92.09999847,7.073926449);
   graph2->SetPoint(115,92.13999939,7.570672989);
   graph2->SetPoint(116,92.18000031,8.08174324);
   graph2->SetPoint(117,92.22000122,8.606842995);
   graph2->SetPoint(118,92.26000214,9.145680428);
   graph2->SetPoint(119,92.30000305,9.697964668);
   graph2->SetPoint(120,92.33999634,10.26340675);
   graph2->SetPoint(121,92.37999725,10.84172058);
   graph2->SetPoint(122,92.41999817,11.43262482);
   graph2->SetPoint(123,92.45999908,12.03584099);
   graph2->SetPoint(124,92.5,12.65109539);
   graph2->SetPoint(125,92.54000092,13.27812099);
   graph2->SetPoint(126,92.58000183,13.91665268);
   graph2->SetPoint(127,92.62000275,14.56643105);
   graph2->SetPoint(128,92.66000366,15.22720337);
   graph2->SetPoint(129,92.69999695,15.89872169);
   graph2->SetPoint(130,92.73999786,16.58073997);
   graph2->SetPoint(131,92.77999878,17.2730217);
   graph2->SetPoint(132,92.81999969,17.97533035);
   graph2->SetPoint(133,92.81999969,17.97533035);
   graph2->SetPoint(134,92.86000061,18.68743896);
   graph2->SetPoint(135,92.90000153,19.40911865);
   graph2->SetPoint(136,92.94000244,20.14015007);
   graph2->SetPoint(137,92.98000336,20.88031387);
   graph2->SetPoint(138,93.01999664,21.62939453);
   graph2->SetPoint(139,93.05999756,22.38718414);
   graph2->SetPoint(140,93.09999847,23.15346909);
   graph2->SetPoint(141,93.13999939,23.92804527);
   graph2->SetPoint(142,93.18000031,24.71071243);
   graph2->SetPoint(143,93.22000122,25.50126266);
   graph2->SetPoint(144,93.26000214,26.29950333);
   graph2->SetPoint(145,93.30000305,27.10523224);
   graph2->SetPoint(146,93.33999634,27.91825485);
   graph2->SetPoint(147,93.37999725,28.73837852);
   graph2->SetPoint(148,93.41999817,29.56540871);
   graph2->SetPoint(149,93.45999908,30.39915657);
   graph2->SetPoint(150,93.5,31.23942947);
   graph2->SetPoint(151,93.54000092,32.0860405);
   graph2->SetPoint(152,93.58000183,32.93880081);
   graph2->SetPoint(153,93.62000275,33.79752731);
   graph2->SetPoint(154,93.62000275,33.79752731);
   graph2->SetPoint(155,93.66000366,34.66203308);
   graph2->SetPoint(156,93.69999695,35.53213501);
   graph2->SetPoint(157,93.73999786,36.40764999);
   graph2->SetPoint(158,93.77999878,37.28839874);
   graph2->SetPoint(159,93.81999969,38.17420197);
   graph2->SetPoint(160,93.86000061,39.06488037);
   graph2->SetPoint(161,93.90000153,39.96025848);
   graph2->SetPoint(162,93.94000244,40.86016464);
   graph2->SetPoint(163,93.98000336,41.76441956);
   graph2->SetPoint(164,94.01999664,42.67286301);
   graph2->SetPoint(165,94.05999756,43.5853157);
   graph2->SetPoint(166,94.09999847,44.50161362);
   graph2->SetPoint(167,94.13999939,45.42160034);
   graph2->SetPoint(168,94.18000031,46.34510422);
   graph2->SetPoint(169,94.22000122,47.27197266);
   graph2->SetPoint(170,94.26000214,48.20204544);
   graph2->SetPoint(171,94.30000305,49.13516998);
   graph2->SetPoint(172,94.33999634,50.07119751);
   graph2->SetPoint(173,94.37999725,51.00997925);
   graph2->SetPoint(174,94.41999817,51.95137024);
   graph2->SetPoint(175,94.41999817,51.95137024);
   graph2->SetPoint(176,94.45999908,52.89523315);
   graph2->SetPoint(177,94.5,53.84142303);
   graph2->SetPoint(178,94.54000092,54.789814);
   graph2->SetPoint(179,94.58000183,55.74026871);
   graph2->SetPoint(180,94.62000275,56.69266129);
   graph2->SetPoint(181,94.66000366,57.64687347);
   graph2->SetPoint(182,94.69999695,58.60277939);
   graph2->SetPoint(183,94.73999786,59.5602684);
   graph2->SetPoint(184,94.77999878,60.51922989);
   graph2->SetPoint(185,94.81999969,61.47954941);
   graph2->SetPoint(186,94.86000061,62.44112778);
   graph2->SetPoint(187,94.90000153,63.40386581);
   graph2->SetPoint(188,94.94000244,64.36766815);
   graph2->SetPoint(189,94.98000336,65.33243561);
   graph2->SetPoint(190,95.01999664,66.29808044);
   graph2->SetPoint(191,95.05999756,67.264534);
   graph2->SetPoint(192,95.09999847,68.23168945);
   graph2->SetPoint(193,95.13999939,69.19949341);
   graph2->SetPoint(194,95.18000031,70.16786194);
   graph2->SetPoint(195,95.22000122,71.13671875);
   graph2->SetPoint(196,95.22000122,71.13671875);
   graph2->SetPoint(197,95.26000214,72.10600281);
   graph2->SetPoint(198,95.30000305,73.07565308);
   graph2->SetPoint(199,95.33999634,74.04560852);
   graph2->SetPoint(200,95.37999725,75.01580811);
   graph2->SetPoint(201,95.41999817,75.98619843);
   graph2->SetPoint(202,95.45999908,76.95672607);
   graph2->SetPoint(203,95.5,77.92734528);
   graph2->SetPoint(204,95.54000092,78.89801788);
   graph2->SetPoint(205,95.58000183,79.86868286);
   graph2->SetPoint(206,95.62000275,80.83930969);
   graph2->SetPoint(207,95.66000366,81.80986023);
   graph2->SetPoint(208,95.69999695,82.7802887);
   graph2->SetPoint(209,95.73999786,83.7505722);
   graph2->SetPoint(210,95.77999878,84.72067261);
   graph2->SetPoint(211,95.81999969,85.69055176);
   graph2->SetPoint(212,95.86000061,86.6601944);
   graph2->SetPoint(213,95.90000153,87.62956238);
   graph2->SetPoint(214,95.94000244,88.59862518);
   graph2->SetPoint(215,95.98000336,89.56736755);



   cout<< "4mu: " << graph2->Eval(91.1876) << endl;


   //4l
   TGraph *graph3 = new TGraph(212);
   graph3->SetName("Graph3");
   graph3->SetTitle("Graph3");
   graph3->SetFillColor(1);
   graph3->SetLineWidth(3);
   graph3->SetMarkerStyle(20);
   graph3->SetPoint(0,88.01999664,57.33911514);
   graph3->SetPoint(1,88.05999756,56.08871841);
   graph3->SetPoint(2,88.09999847,54.84604263);
   graph3->SetPoint(3,88.13999939,53.61128998);
   graph3->SetPoint(4,88.18000031,52.38465881);
   graph3->SetPoint(5,88.22000122,51.1663475);
   graph3->SetPoint(6,88.26000214,49.95656586);
   graph3->SetPoint(7,88.30000305,48.75551605);
   graph3->SetPoint(8,88.33999634,47.56340408);
   graph3->SetPoint(9,88.37999725,46.38043976);
   graph3->SetPoint(10,88.41999817,45.20683289);
   graph3->SetPoint(11,88.45999908,44.04279709);
   graph3->SetPoint(12,88.5,42.88854218);
   graph3->SetPoint(13,88.54000092,41.74428558);
   graph3->SetPoint(14,88.58000183,40.61024094);
   graph3->SetPoint(15,88.62000275,39.48662186);
   graph3->SetPoint(16,88.66000366,38.37365723);
   graph3->SetPoint(17,88.69999695,37.27156067);
   graph3->SetPoint(18,88.73999786,36.18055725);
   graph3->SetPoint(19,88.77999878,35.10086823);
   graph3->SetPoint(20,88.81999969,34.03272247);
   graph3->SetPoint(21,88.81999969,34.03272247);
   graph3->SetPoint(22,88.86000061,32.97634506);
   graph3->SetPoint(23,88.90000153,31.93196487);
   graph3->SetPoint(24,88.94000244,30.89981461);
   graph3->SetPoint(25,88.98000336,29.88012505);
   graph3->SetPoint(26,89.01999664,28.87313271);
   graph3->SetPoint(27,89.05999756,27.87907028);
   graph3->SetPoint(28,89.09999847,26.8981781);
   graph3->SetPoint(29,89.13999939,25.93069649);
   graph3->SetPoint(30,89.18000031,24.97686577);
   graph3->SetPoint(31,89.22000122,24.03692818);
   graph3->SetPoint(32,89.26000214,23.11112785);
   graph3->SetPoint(33,89.30000305,22.19971466);
   graph3->SetPoint(34,89.33999634,21.30293083);
   graph3->SetPoint(35,89.37999725,20.42103004);
   graph3->SetPoint(36,89.41999817,19.55426025);
   graph3->SetPoint(37,89.45999908,18.70287132);
   graph3->SetPoint(38,89.5,17.86711502);
   graph3->SetPoint(39,89.54000092,17.04724693);
   graph3->SetPoint(40,89.58000183,16.24351692);
   graph3->SetPoint(41,89.62000275,15.45617962);
   graph3->SetPoint(42,89.62000275,15.45617962);
   graph3->SetPoint(43,89.66000366,14.6854887);
   graph3->SetPoint(44,89.69999695,13.93169785);
   graph3->SetPoint(45,89.73999786,13.19505882);
   graph3->SetPoint(46,89.77999878,12.47582531);
   graph3->SetPoint(47,89.81999969,11.77424908);
   graph3->SetPoint(48,89.86000061,11.09057903);
   graph3->SetPoint(49,89.90000153,10.4250679);
   graph3->SetPoint(50,89.94000244,9.777960777);
   graph3->SetPoint(51,89.98000336,9.149505615);
   graph3->SetPoint(52,90.01999664,8.539945602);
   graph3->SetPoint(53,90.05999756,7.949523926);
   graph3->SetPoint(54,90.09999847,7.378479958);
   graph3->SetPoint(55,90.13999939,6.827050209);
   graph3->SetPoint(56,90.18000031,6.295467854);
   graph3->SetPoint(57,90.22000122,5.783964634);
   graph3->SetPoint(58,90.26000214,5.292765617);
   graph3->SetPoint(59,90.30000305,4.82209301);
   graph3->SetPoint(60,90.33999634,4.37216568);
   graph3->SetPoint(61,90.37999725,3.943194866);
   graph3->SetPoint(62,90.41999817,3.535388231);
   graph3->SetPoint(63,90.41999817,3.535388231);
   graph3->SetPoint(64,90.45999908,3.148947239);
   graph3->SetPoint(65,90.5,2.784065962);
   graph3->SetPoint(66,90.54000092,2.440932035);
   graph3->SetPoint(67,90.58000183,2.119725466);
   graph3->SetPoint(68,90.62000275,1.820617914);
   graph3->SetPoint(69,90.66000366,1.543772101);
   graph3->SetPoint(70,90.69999695,1.28934145);
   graph3->SetPoint(71,90.73999786,1.057468891);
   graph3->SetPoint(72,90.77999878,0.8482871056);
   graph3->SetPoint(73,90.81999969,0.6619167924);
   graph3->SetPoint(74,90.86000061,0.4984668195);
   graph3->SetPoint(75,90.90000153,0.3580331504);
   graph3->SetPoint(76,90.94000244,0.240698427);
   graph3->SetPoint(77,90.98000336,0.1465311348);
   graph3->SetPoint(78,91.01999664,0.07558509707);
   graph3->SetPoint(79,91.05999756,0.02789884619);
   graph3->SetPoint(80,91.09999847,0.003495044075);
   graph3->SetPoint(81,91.12191772,0);
   graph3->SetPoint(82,91.12191772,0);
   graph3->SetPoint(83,91.12191772,0);
   graph3->SetPoint(84,91.12191772,0);
   graph3->SetPoint(85,91.12191772,0);
   graph3->SetPoint(86,91.12191772,0);
   graph3->SetPoint(87,91.12191772,0);
   graph3->SetPoint(88,91.26000214,0.1385737211);
   graph3->SetPoint(89,91.30000305,0.230332002);
   graph3->SetPoint(90,91.33999634,0.345148921);
   graph3->SetPoint(91,91.37999725,0.4829240143);
   graph3->SetPoint(92,91.41999817,0.643538177);
   graph3->SetPoint(93,91.45999908,0.8268537521);
   graph3->SetPoint(94,91.5,1.032714605);
   graph3->SetPoint(95,91.54000092,1.260946751);
   graph3->SetPoint(96,91.58000183,1.511358023);
   graph3->SetPoint(97,91.62000275,1.783738732);
   graph3->SetPoint(98,91.66000366,2.07786274);
   graph3->SetPoint(99,91.69999695,2.39348793);
   graph3->SetPoint(100,91.73999786,2.730356455);
   graph3->SetPoint(101,91.77999878,3.088196516);
   graph3->SetPoint(102,91.81999969,3.466723442);
   graph3->SetPoint(103,91.86000061,3.865639925);
   graph3->SetPoint(104,91.90000153,4.284637928);
   graph3->SetPoint(105,91.94000244,4.723400593);
   graph3->SetPoint(106,91.98000336,5.181601524);
   graph3->SetPoint(107,92.01999664,5.658910275);
   graph3->SetPoint(108,92.01999664,5.658910275);
   graph3->SetPoint(109,92.05999756,6.154988289);
   graph3->SetPoint(110,92.09999847,6.669495583);
   graph3->SetPoint(111,92.13999939,7.202087879);
   graph3->SetPoint(112,92.18000031,7.752422333);
   graph3->SetPoint(113,92.22000122,8.32015419);
   graph3->SetPoint(114,92.26000214,8.904941559);
   graph3->SetPoint(115,92.30000305,9.506444931);
   graph3->SetPoint(116,92.33999634,10.12432957);
   graph3->SetPoint(117,92.37999725,10.75826359);
   graph3->SetPoint(118,92.41999817,11.40792084);
   graph3->SetPoint(119,92.45999908,12.07298279);
   graph3->SetPoint(120,92.5,12.75313663);
   graph3->SetPoint(121,92.54000092,13.44807529);
   graph3->SetPoint(122,92.58000183,14.15750027);
   graph3->SetPoint(123,92.62000275,14.88112068);
   graph3->SetPoint(124,92.66000366,15.61865044);
   graph3->SetPoint(125,92.69999695,16.36981392);
   graph3->SetPoint(126,92.73999786,17.13433838);
   graph3->SetPoint(127,92.77999878,17.91196251);
   graph3->SetPoint(128,92.81999969,18.70242691);
   graph3->SetPoint(129,92.81999969,18.70242691);
   graph3->SetPoint(130,92.86000061,19.50548172);
   graph3->SetPoint(131,92.90000153,20.32088089);
   graph3->SetPoint(132,92.94000244,21.14838409);
   graph3->SetPoint(133,92.98000336,21.98775864);
   graph3->SetPoint(134,93.01999664,22.83877182);
   graph3->SetPoint(135,93.05999756,23.70119667);
   graph3->SetPoint(136,93.09999847,24.57481003);
   graph3->SetPoint(137,93.13999939,25.45939636);
   graph3->SetPoint(138,93.18000031,26.35473442);
   graph3->SetPoint(139,93.22000122,27.2606163);
   graph3->SetPoint(140,93.26000214,28.17682648);
   graph3->SetPoint(141,93.30000305,29.10315895);
   graph3->SetPoint(142,93.33999634,30.03940773);
   graph3->SetPoint(143,93.37999725,30.98536491);
   graph3->SetPoint(144,93.41999817,31.94083023);
   graph3->SetPoint(145,93.45999908,32.9056015);
   graph3->SetPoint(146,93.5,33.87947845);
   graph3->SetPoint(147,93.54000092,34.86225891);
   graph3->SetPoint(148,93.58000183,35.85375214);
   graph3->SetPoint(149,93.62000275,36.85375214);
   graph3->SetPoint(150,93.62000275,36.85375214);
   graph3->SetPoint(151,93.66000366,37.86207199);
   graph3->SetPoint(152,93.69999695,38.87851334);
   graph3->SetPoint(153,93.73999786,39.90288162);
   graph3->SetPoint(154,93.77999878,40.93498611);
   graph3->SetPoint(155,93.81999969,41.97463608);
   graph3->SetPoint(156,93.86000061,43.02164078);
   graph3->SetPoint(157,93.90000153,44.07581329);
   graph3->SetPoint(158,93.94000244,45.13696671);
   graph3->SetPoint(159,93.98000336,46.20491409);
   graph3->SetPoint(160,94.01999664,47.27947617);
   graph3->SetPoint(161,94.05999756,48.360466);
   graph3->SetPoint(162,94.09999847,49.44770813);
   graph3->SetPoint(163,94.13999939,50.54101944);
   graph3->SetPoint(164,94.18000031,51.64023209);
   graph3->SetPoint(165,94.22000122,52.74516296);
   graph3->SetPoint(166,94.26000214,53.85564804);
   graph3->SetPoint(167,94.30000305,54.97151947);
   graph3->SetPoint(168,94.33999634,56.09260941);
   graph3->SetPoint(169,94.37999725,57.21875763);
   graph3->SetPoint(170,94.41999817,58.34980011);
   graph3->SetPoint(171,94.41999817,58.34980011);
   graph3->SetPoint(172,94.45999908,59.48558426);
   graph3->SetPoint(173,94.5,60.62595749);
   graph3->SetPoint(174,94.54000092,61.77076721);
   graph3->SetPoint(175,94.58000183,62.91986847);
   graph3->SetPoint(176,94.62000275,64.07312012);
   graph3->SetPoint(177,94.66000366,65.2303772);
   graph3->SetPoint(178,94.69999695,66.39151001);
   graph3->SetPoint(179,94.73999786,67.55638123);
   graph3->SetPoint(180,94.77999878,68.72486877);
   graph3->SetPoint(181,94.81999969,69.89684296);
   graph3->SetPoint(182,94.86000061,71.07218933);
   graph3->SetPoint(183,94.90000153,72.25079346);
   graph3->SetPoint(184,94.94000244,73.43252563);
   graph3->SetPoint(185,94.98000336,74.61729431);
   graph3->SetPoint(186,95.01999664,75.80497742);
   graph3->SetPoint(187,95.05999756,76.99549103);
   graph3->SetPoint(188,95.09999847,78.18872833);
   graph3->SetPoint(189,95.13999939,79.38459015);
   graph3->SetPoint(190,95.18000031,80.58299255);
   graph3->SetPoint(191,95.22000122,81.78383636);
   graph3->SetPoint(192,95.22000122,81.78383636);
   graph3->SetPoint(193,95.26000214,82.98705292);
   graph3->SetPoint(194,95.30000305,84.19254303);
   graph3->SetPoint(195,95.33999634,85.40024567);
   graph3->SetPoint(196,95.37999725,86.61006927);
   graph3->SetPoint(197,95.41999817,87.82195282);
   graph3->SetPoint(198,95.45999908,89.03581238);
   graph3->SetPoint(199,95.5,90.25159454);
   graph3->SetPoint(200,95.54000092,91.46923065);
   graph3->SetPoint(201,95.58000183,92.68865204);
   graph3->SetPoint(202,95.62000275,93.90979767);
   graph3->SetPoint(203,95.66000366,95.13261414);
   graph3->SetPoint(204,95.69999695,96.35704803);
   graph3->SetPoint(205,95.73999786,97.58303833);
   graph3->SetPoint(206,95.77999878,98.81052399);
   graph3->SetPoint(207,95.81999969,100.0394745);
   graph3->SetPoint(208,95.86000061,101.2698212);
   graph3->SetPoint(209,95.90000153,102.5015259);
   graph3->SetPoint(210,95.94000244,103.7345352);
   graph3->SetPoint(211,95.98000336,104.9688034);



   TH1F *Graph_Graph1 = new TH1F("Graph_Graph1","Graph",212,84.03,95.97);
   Graph_Graph1->SetMinimum(0);
   Graph_Graph1->SetMaximum(57.47094);
   Graph_Graph1->SetDirectory(0);
   Graph_Graph1->SetStats(0);
   Graph_Graph1->SetLineStyle(0);
   Graph_Graph1->SetMarkerStyle(20);
   Graph_Graph1->GetXaxis()->SetLabelFont(42);
   Graph_Graph1->GetXaxis()->SetLabelOffset(0.01);
   Graph_Graph1->GetXaxis()->SetLabelSize(0.045);
   Graph_Graph1->GetXaxis()->SetTitleSize(0.055);
   Graph_Graph1->GetXaxis()->SetTitleOffset(0.9);
   Graph_Graph1->GetXaxis()->SetTitleFont(42);
   Graph_Graph1->GetYaxis()->SetLabelFont(42);
   Graph_Graph1->GetYaxis()->SetLabelOffset(0.01);
   Graph_Graph1->GetYaxis()->SetLabelSize(0.045);
   Graph_Graph1->GetYaxis()->SetTitleSize(0.055);
   Graph_Graph1->GetYaxis()->SetTitleOffset(1.25);
   Graph_Graph1->GetYaxis()->SetTitleFont(42);
   Graph_Graph1->GetZaxis()->SetLabelFont(42);
   Graph_Graph1->GetZaxis()->SetLabelOffset(0.01);
   Graph_Graph1->GetZaxis()->SetLabelSize(0.045);
   Graph_Graph1->GetZaxis()->SetTitleSize(0.055);
   Graph_Graph1->GetZaxis()->SetTitleFont(42);
   Graph_Graph1->GetXaxis()->SetNdivisions(510);
   
   graph->SetHistogram(Graph_Graph1);
   graph->Draw("cx");
   graph1->Draw("cx");
   graph2->Draw("cx");
   graph3->Draw("cx");

   TPaveText *pt = new TPaveText(0.1577181,0.95,0.9580537,0.99,"brNDC");
   pt->SetBorderSize(0);
   pt->SetFillStyle(0);
   pt->SetTextAlign(12);
   pt->SetTextFont(42);
   pt->SetTextSize(0.03);
   TText *text = pt->AddText(0.01,0.5,"CMS");
   text = pt->AddText(0.3,0.6,"#sqrt{s} = 7 TeV, L = 5.1 fb^{-1}  #sqrt{s} = 8 TeV, L = 19.7 fb^{-1}");
   pt->Draw();
   

   TLegend *leg = new TLegend(0.73,0.77,0.94,0.94);
   leg->SetTextSize(0.035);
   leg->SetTextFont(42);
   leg->SetFillColor(kWhite);
   //leg->SetBorderSize(0);
   //leg->SetFillStyle(0);

   leg->AddEntry(graph3,"Combined","L");
   leg->AddEntry(graph,"Z#rightarrow 4e","L");
   leg->AddEntry(graph2,"Z#rightarrow 4#mu","L");
   leg->AddEntry(graph1,"Z#rightarrow 2e2#mu","L");






   double yLow = 0.5;

   

   pt = new TPaveText(0.11,yLow,0.4,yLow+0.04,"brNDC");
   pt->SetBorderSize(0);
   pt->SetFillStyle(0);
   pt->SetTextAlign(12);
   pt->SetTextFont(42);
   pt->SetTextSize(0.03);
   pt->SetTextColor(kBlue);
   text = pt->AddText(0.2,0.2,"m_{2e2#mu} = 91.24 #pm 0.46 GeV");
   //text = pt->AddText(0.2,0.2,"m_{2e2#mu} = 91.24 #pm 0.40 #pm 0.16 GeV");
   //stat 91.4315 +0.405948-0.397679
   cout << "Syst 2e2mu: " << findSystErr(0.43,0.40) << endl;
   //pt->Draw();

   pt = new TPaveText(0.11,yLow+0.06,0.4,yLow+0.1,"brNDC");
   pt->SetBorderSize(0);
   pt->SetFillStyle(0);
   pt->SetTextAlign(12);
   pt->SetTextFont(42);
   pt->SetTextSize(0.03);
   pt->SetTextColor(kRed);
   text = pt->AddText(0.2,0.2,"m_{4#mu} = 91.00 #pm 0.26 GeV");
   //text = pt->AddText(0.2,0.2,"m_{4#mu} = 91.00 #pm 0.25 #pm 0.09 GeV");
   //stat 91.0078 +0.255715-0.25533
   cout << "Syst 4mu: " << findSystErr(0.27,0.255) << endl;
   //pt->Draw();

   pt = new TPaveText(0.11,yLow+0.12,0.4,yLow+0.16,"brNDC");
   pt->SetBorderSize(0);
   pt->SetFillStyle(0);
   pt->SetTextAlign(12);
   pt->SetTextFont(42);
   pt->SetTextSize(0.03);
   pt->SetTextColor(kGreen+1);
   text = pt->AddText(0.2,0.2,"m_{4e} = 93.67 #pm 1.08 GeV");
   //text = pt->AddText(0.2,0.2,"m_{4e} = 9 #pm 0.74 #pm 0.30 GeV");
   //stat 91.8026 +0.745333-0.740755
   cout << "Syst 4e: " << findSystErr(0.8,0.74) << endl;
   //pt->Draw();

   pt = new TPaveText(0.11,yLow+0.18,0.4,yLow+0.22,"brNDC");
   pt->SetBorderSize(0);
   pt->SetFillStyle(0);
   pt->SetTextAlign(12);
   pt->SetTextFont(42);
   pt->SetTextSize(0.03);
   text = pt->AddText(0.2,0.2,"m_{4l} = 91.15 #pm 0.23 GeV");
   //text = pt->AddText(0.2,0.2,"m_{4l} = 91.17 #pm 0.18 #pm 0.13 GeV");
   //stat  91.1724 +0.168014-0.204439
   cout << "Syst 4l: " << findSystErr(0.22,0.18) << endl;
   //pt->Draw();

   pt = new TPaveText(0.18,yLow+0.24,0.4,yLow+0.28,"brNDC");
   pt->SetBorderSize(0);
   pt->SetFillStyle(0);
   pt->SetTextAlign(12);
   pt->SetTextFont(42);
   pt->SetTextSize(0.035);
   text = pt->AddText(0.2,0.2,"#chi^{2}/ndof = 1.38/3");
   //pt->Draw();
   
   gPad->SetTicks(1,1);

   TLine *line95 = new TLine(88,3.84,96,3.84);
   line95->SetLineColor(kRed);
   line95->SetLineWidth(2);
   line95->Draw();

   TLine *line68 = new TLine(88,1,96,1);
   line68->SetLineColor(kRed);
   line68->SetLineWidth(3);
   line68->Draw();
   
   TLine *lineZ = new TLine(91.1876,0,91.1876,10);
   lineZ->SetLineColor(kGray+2);
   lineZ->SetLineStyle(7);
   lineZ->Draw();

   leg->Draw();
   hframe->GetXaxis()->SetRangeUser(88,96);
   ccc->Modified();
   ccc->cd();
   ccc->SetSelected(ccc);

   ccc->SaveAs("massZ4lScan_MZ2gt12_Legacy_split.eps");
   ccc->SaveAs("massZ4lScan_MZ2gt12_Legacy_split.png");
}
Example #19
0
void do_layer_map(std::string filename,int layer, float pri, float sec, float fak)
{
  // First get the data
  // by merging all the available files

  gStyle->SetOptStat(0);
  gStyle->SetOptTitle(0);

  float count_p[58000];
  float count_f[58000];
  float count_s[58000];
  float count_c[58000];

  double n_lad_barrel[6]  = {16,24,34,48,62,76};
  double n_mod_barrel[6]  = {63,55,54,24,24,24};


  TFile *oldfile = TFile::Open(filename.c_str());
  TTree *newtree = (TTree*)oldfile->Get("L1Rates");

  newtree->SetBranchAddress("STUB_b_rates_prim",  &count_p);
  newtree->SetBranchAddress("STUB_b_rates_sec",   &count_f);
  newtree->SetBranchAddress("STUB_b_rates_f",     &count_s);
  newtree->SetBranchAddress("CLUS_b_rates",       &count_c);
  newtree->GetEntry(0);

  int idx;
  float maxval  = 0;
  float maxcval = 0;
  float rate = 0;
  int maxmod = 0;
  float ratio = 0;
  float maxratio = 0;

  for (int i=0;i<7;++i)
  { 
    for (int j=(layer-5)*10000;j<(layer-5)*10000+8000;++j)
    { 
      rate = pri*count_p[j]+fak*count_f[j]+sec*count_s[j];

      if (rate!=0.)
      {
	ratio = count_c[j]/rate;
	if (ratio>maxratio) maxratio=ratio;  
      }

      if (rate>maxval) 
      {
	maxval = rate;
	maxmod = j;
      }

      if (count_c[j]>maxcval) 
      {
	maxcval = count_c[j];
      }
    }
  }

  cout << "max module for layer " << layer << " is " << maxmod << endl;  

  TH2F *cadre = new TH2F("zz","zz",n_mod_barrel[layer-5],0.,n_mod_barrel[layer-5],n_lad_barrel[layer-5],0.,n_lad_barrel[layer-5]);
  TH2F *cadre2 = new TH2F("zz","zz",n_mod_barrel[layer-5]+1,0.,n_mod_barrel[layer-5]+1,n_lad_barrel[layer-5],0.,n_lad_barrel[layer-5]);
  TH2F *cadre3 = new TH2F("zz","zz",n_mod_barrel[layer-5]+1,0.,n_mod_barrel[layer-5]+1,n_lad_barrel[layer-5],0.,n_lad_barrel[layer-5]);
  TH2F *cadre4 = new TH2F("zz","zz",n_mod_barrel[layer-5]+1,0.,n_mod_barrel[layer-5]+1,n_lad_barrel[layer-5],0.,n_lad_barrel[layer-5]);

  cadre2->Fill(n_mod_barrel[layer-5]+0.5,0.5,0.);
  cadre2->Fill(n_mod_barrel[layer-5]+0.5,0.5,maxval);

  cadre3->Fill(n_mod_barrel[layer-5]+0.5,0.5,0.);
  cadre3->Fill(n_mod_barrel[layer-5]+0.5,0.5,maxcval);

  cadre4->Fill(n_mod_barrel[layer-5]+0.5,0.5,0.);
  cadre4->Fill(n_mod_barrel[layer-5]+0.5,0.5,maxratio);

  for (int j=0;j<n_mod_barrel[layer-5];++j)
  {
    for (int i=0;i<n_lad_barrel[layer-5];++i)
    {
      idx = 10000*(layer-5) + 100*i + j;
      rate= pri*count_p[idx]+fak*count_f[idx]+sec*count_s[idx];

      cadre2->Fill(j+0.5,i+0.5,rate);
      cadre3->Fill(j+0.5,i+0.5,count_c[idx]);

      if (rate!=0) cadre4->Fill(j+0.5,i+0.5,count_c[idx]/rate);
    }
  }

  const Int_t NRGBs = 5;
  const Int_t NCont = 255;
  
  Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
  Double_t red[NRGBs]   = { 0.00, 0.00, 0.87, 1.00, 0.51 };
  Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 };
  Double_t blue[NRGBs]  = { 0.51, 1.00, 0.12, 0.00, 0.00 };
  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
  gStyle->SetNumberContours(NCont);


  c1 = new TCanvas("c1","Layer map",201,77,1470,858);
  gStyle->SetOptStat(0);
  gStyle->SetOptTitle(0);
  c1->Range(-5.887851,-1.930603,70.65421,17.37543);
  c1->SetFillColor(0);
  c1->SetBorderMode(0);
  c1->SetBorderSize(2);
  c1->SetGridx();
  c1->SetGridy();
  c1->SetLeftMargin(0.07692308);
  c1->SetTopMargin(0.07124352);
  c1->SetFrameBorderMode(0);
  c1->SetFrameBorderMode(0);
  

  cadre->GetXaxis()->SetTitle("Module Z index");
  cadre->GetXaxis()->SetNdivisions(n_mod_barrel[layer-5]);
  cadre->GetXaxis()->SetLabelFont(42);
  cadre->GetXaxis()->SetLabelSize(0.02);
  cadre->GetXaxis()->SetTitleSize(0.035);
  cadre->GetXaxis()->SetTickLength(1);
  cadre->GetXaxis()->SetTitleFont(42);
  cadre->GetYaxis()->SetTitle("Module #phi index");
  cadre->GetYaxis()->SetNdivisions(n_lad_barrel[layer-5]);
  cadre->GetYaxis()->SetLabelFont(42);
  cadre->GetYaxis()->SetLabelOffset(0.004);
  cadre->GetYaxis()->SetLabelSize(0.02);
  cadre->GetYaxis()->SetTitleSize(0.03);
  cadre->GetYaxis()->SetTickLength(0.99);
  cadre->GetYaxis()->SetTitleFont(42);
  cadre->GetZaxis()->SetLabelFont(42);
  cadre->GetZaxis()->SetLabelSize(0.035);
  cadre->GetZaxis()->SetTitleSize(0.035);
  cadre->GetZaxis()->SetTitleFont(42);  

  cadre->Draw();
  cadre2->Draw("colzsame");
   
  TPaveText *pt = new TPaveText(0.,n_lad_barrel[layer-5],18./55.*n_mod_barrel[layer-5],17./16.*n_lad_barrel[layer-5],"br");

  char buffer[50];
  sprintf (buffer, "Barrel Layer %d stub rate (in Stub/Module/BX)",layer);

  TLatex Tl;
  Tl.SetTextSize(0.02);

  Tl.DrawLatex(40./55.*n_mod_barrel[layer-5], 16.5/16.*n_lad_barrel[layer-5], "CMS Preliminary Simulation");  

  //  ci = TColor::GetColor("#ccccff");
  pt->SetFillColor(0);
  pt->SetTextSize(0.02);
  TText *text = pt->AddText(buffer);
  pt->Draw();
  c1->Modified();

  c1->Update();

  sprintf (buffer, "Barrel_%d_rate_140.eps", layer);
  c1->Print(buffer);

  sprintf (buffer, "Barrel_%d_rate_140.png", layer);
  c1->Print(buffer);

  c1->Update();


  c2 = new TCanvas("c2","Cluster map",201,77,1470,858);
  gStyle->SetOptStat(0);
  gStyle->SetOptTitle(0);
  c2->Range(-5.887851,-1.930603,70.65421,17.37543);
  c2->SetFillColor(0);
  c2->SetBorderMode(0);
  c2->SetBorderSize(2);
  c2->SetGridx();
  c2->SetGridy();
  c2->SetLeftMargin(0.07692308);
  c2->SetTopMargin(0.07124352);
  c2->SetFrameBorderMode(0);
  c2->SetFrameBorderMode(0);
  

  cadre->GetXaxis()->SetTitle("Module Z index");
  cadre->GetXaxis()->SetNdivisions(n_mod_barrel[layer-5]);
  cadre->GetXaxis()->SetLabelFont(42);
  cadre->GetXaxis()->SetLabelSize(0.02);
  cadre->GetXaxis()->SetTitleSize(0.035);
  cadre->GetXaxis()->SetTickLength(1);
  cadre->GetXaxis()->SetTitleFont(42);
  cadre->GetYaxis()->SetTitle("Module #phi index");
  cadre->GetYaxis()->SetNdivisions(n_lad_barrel[layer-5]);
  cadre->GetYaxis()->SetLabelFont(42);
  cadre->GetYaxis()->SetLabelOffset(0.004);
  cadre->GetYaxis()->SetLabelSize(0.02);
  cadre->GetYaxis()->SetTitleSize(0.03);
  cadre->GetYaxis()->SetTickLength(0.99);
  cadre->GetYaxis()->SetTitleFont(42);
  cadre->GetZaxis()->SetLabelFont(42);
  cadre->GetZaxis()->SetLabelSize(0.035);
  cadre->GetZaxis()->SetTitleSize(0.035);
  cadre->GetZaxis()->SetTitleFont(42);  

  cadre->Draw();
  cadre3->Draw("colzsame");
   
  TPaveText *pt = new TPaveText(0.,n_lad_barrel[layer-5],18./55.*n_mod_barrel[layer-5],17./16.*n_lad_barrel[layer-5],"br");

  char buffer[50];
  sprintf (buffer, "Barrel Layer %d cluster rate (in Cluster/Module/BX)",layer);


  Tl.DrawLatex(40./55.*n_mod_barrel[layer-5], 16.5/16.*n_lad_barrel[layer-5], "CMS Preliminary Simulation");  
  //  ci = TColor::GetColor("#ccccff");
  pt->SetFillColor(0);
  pt->SetTextSize(0.02);
  TText *text = pt->AddText(buffer);
  pt->Draw();
  c2->Modified();

  c2->Update();

  sprintf (buffer, "Barrel_%d_clus_rate_140.eps", layer);
  c2->Print(buffer);

  sprintf (buffer, "Barrel_%d_clus_rate_140.png", layer);
  c2->Print(buffer);

  c2->Update();


  c3 = new TCanvas("c3","Cluster over Stub map",201,77,1470,858);
  gStyle->SetOptStat(0);
  gStyle->SetOptTitle(0);
  c3->Range(-5.887851,-1.930603,70.65421,17.37543);
  c3->SetFillColor(0);
  c3->SetBorderMode(0);
  c3->SetBorderSize(2);
  c3->SetGridx();
  c3->SetGridy();
  c3->SetLeftMargin(0.07692308);
  c3->SetTopMargin(0.07124352);
  c3->SetFrameBorderMode(0);
  c3->SetFrameBorderMode(0);
  

  cadre->GetXaxis()->SetTitle("Module Z index");
  cadre->GetXaxis()->SetNdivisions(n_mod_barrel[layer-5]);
  cadre->GetXaxis()->SetLabelFont(42);
  cadre->GetXaxis()->SetLabelSize(0.02);
  cadre->GetXaxis()->SetTitleSize(0.035);
  cadre->GetXaxis()->SetTickLength(1);
  cadre->GetXaxis()->SetTitleFont(42);
  cadre->GetYaxis()->SetTitle("Module #phi index");
  cadre->GetYaxis()->SetNdivisions(n_lad_barrel[layer-5]);
  cadre->GetYaxis()->SetLabelFont(42);
  cadre->GetYaxis()->SetLabelOffset(0.004);
  cadre->GetYaxis()->SetLabelSize(0.02);
  cadre->GetYaxis()->SetTitleSize(0.03);
  cadre->GetYaxis()->SetTickLength(0.99);
  cadre->GetYaxis()->SetTitleFont(42);
  cadre->GetZaxis()->SetLabelFont(42);
  cadre->GetZaxis()->SetLabelSize(0.035);
  cadre->GetZaxis()->SetTitleSize(0.035);
  cadre->GetZaxis()->SetTitleFont(42);  

  cadre->Draw();
  cadre4->Draw("colzsame");


  TPaveText *pt = new TPaveText(0.,n_lad_barrel[layer-5],18./55.*n_mod_barrel[layer-5],17./16.*n_lad_barrel[layer-5],"br");

  char buffer[50];
  sprintf (buffer, "Barrel Layer %d cluster/stub ratio",layer);

  Tl.DrawLatex(40./55.*n_mod_barrel[layer-5], 16.5/16.*n_lad_barrel[layer-5], "CMS Preliminary Simulation");  

  //  ci = TColor::GetColor("#ccccff");
  pt->SetFillColor(0);
  pt->SetTextSize(0.02);
  TText *text = pt->AddText(buffer);
  pt->Draw();
  c3->Modified();

  c3->Update();

  sprintf (buffer, "Barrel_%d_ratio_140.eps", layer);
  c3->Print(buffer);

  sprintf (buffer, "Barrel_%d_ratio_140.png", layer);
  c3->Print(buffer);

  c3->Update();

}
Example #20
0
// This ROOT macro plots the stopping depth of the muons in local coordinates
void StoppingDepth(std::string filename) {

  TCanvas* c1 = new TCanvas("c1", "c1");
  c1->SetRightMargin(0.15);
  int n_entries = 100000;

  TFile* file = new TFile(filename.c_str(), "READ");
  TTree* tree = (TTree*) file->Get("tree");
  double n_input_muons = tree->GetEntries();

  size_t secondslash = filename.rfind("/")+1; // don't want to include the slash
  size_t firstdot = filename.rfind(".");
  size_t n_chars = firstdot - secondslash;
  std::string base_filename = filename.substr(secondslash, n_chars);
  std::string histtitle = "Plot of the Stopping Depth of Muons in " + base_filename;
  TH2F* hStopDepth = new TH2F("hStopDepth", histtitle.c_str(), 120,-6,6, 120,-5,55);
  hStopDepth->GetYaxis()->SetTitle("Local Z [#mum]");
  hStopDepth->GetXaxis()->SetTitle("Local X [cm]");
  hStopDepth->GetZaxis()->SetTitle("N_{stop-#mu} / N_{input-#mu}");
  hStopDepth->Scale(1.0 / n_input_muons);
  hStopDepth->SetStats(false);

  tree->Draw("-1*((M_local_Oz*10000)-25):M_local_Ox>>hStopDepth", "M_particleName==\"mu-\" && M_volName==\"Target\" && M_stopped == 1", "COLZ", n_entries);
  
  c1->Update();
  std::string canvasname = "hStopDepth_" + base_filename + ".png";
  //  c1->Print(canvasname.c_str());

  TH1D* hStopZDepth = hStopDepth->ProjectionY();
  hStopZDepth->Draw();
  hStopZDepth->SetStats(false);
  hStopZDepth->GetYaxis()->SetTitle("N_{stop-#mu} / N_{input-#mu}");
  //  hStopZDepth->Scale(1.0 / n_input_muons);
  c1->Update();
  canvasname = "hStopZDepth_" + base_filename + ".png";
  //  c1->Print(canvasname.c_str());

  TH2F* hStopDepthVsTime = new TH2F("hStopDepthVsTime", histtitle.c_str(), 120,-30,30, 120,0,12);
  hStopDepthVsTime->GetXaxis()->SetTitle("Local Z [#mum]");
  hStopDepthVsTime->GetYaxis()->SetTitle("Time [ns]");
  hStopDepthVsTime->GetZaxis()->SetTitle("N_{stop-#mu} / N_{input-#mu}");
  hStopDepthVsTime->Scale(1.0 / n_input_muons);
  hStopDepthVsTime->SetStats(false);

  //  tree->Draw("M_Ot:M_local_Oz*10000>>hStopDepthVsTime", "M_particleName==\"mu-\" && M_volName==\"Target\" && M_stopped == 1", "COLZ", n_entries);
  
  c1->Update();
  canvasname = "hStopDepthVsTime_" + base_filename + ".png";
  //  c1->Print(canvasname.c_str());

  TH2F* hStopDepthVsMomentum = new TH2F("hStopDepthVsMomentum", histtitle.c_str(), 120,-30,30, 120,0,30);
  hStopDepthVsMomentum->GetXaxis()->SetTitle("Local Z [#mum]");
  hStopDepthVsMomentum->GetYaxis()->SetTitle("Momentum [MeV]");
  hStopDepthVsMomentum->GetZaxis()->SetTitle("N_{stop-#mu} / N_{input-#mu}");
  hStopDepthVsMomentum->Scale(1.0 / n_input_muons);
  hStopDepthVsMomentum->SetStats(false);

  //  tree->Draw("sqrt(M_px*M_px + M_py*M_py+ M_pz*M_pz)*1000:M_local_Oz*10000>>hStopDepthVsMomentum", "M_particleName==\"mu-\" && M_volName==\"Target\" && M_stopped == 1", "COLZ", n_entries);
  
  c1->Update();
  canvasname = "hStopDepthVsMomentum_" + base_filename + ".png";
  //  c1->Print(canvasname.c_str());
  //  file->Close();

  std::string outfilename = "plot_" + base_filename + ".root";
  TFile* output = new TFile(outfilename.c_str(), "RECREATE");
  hStopDepth->Write();
  hStopZDepth->Write();
  hStopDepthVsTime->Write();
  hStopDepthVsMomentum->Write();
  output->Close();
}
int main (int argc, char **argv)
{
  /// Mc Ntuplas
  TString input = Form("/data1/rgerosa/NTUPLES_FINAL_CALIB/MC/WJetsToLNu_DYJetsToLL_7TeV-madgraph-tauola_Fall11_All.root"); 
  /// MC Calibration result E/p
  TString input2 = Form("/data1/rgerosa/L3_Weight/MC_WJets/EB_Z_recoFlag/WJetsToLNu_DYJetsToLL_7TeV-madgraph-tauola_Fall11_Z_noEP.root"); 

  TApplication* theApp = new TApplication("Application",&argc, argv);

  TFile *f = new TFile(input,"");
  TTree *inputTree = (TTree*)f->Get("ntu");

  TFile *f2 = new TFile(input2,"");
  TH2F *h_scale_EB = (TH2F*)f2->Get("h_scale_EB");
  TH2F *hcmap = (TH2F*) h_scale_EB->Clone("hcmap");
  
  hcmap -> Reset("ICEMS");
  hcmap -> ResetStats();
  
  /// Taking infos

  std::vector<float>* ele1_recHit_E=0;
  std::vector<float>* ele2_recHit_E=0;
  std::vector<int>* ele1_recHit_hashedIndex=0;
  std::vector<int>* ele2_recHit_hashedIndex=0;
  std::vector<int>* ele1_recHit_flag=0;
  std::vector<int>* ele2_recHit_flag=0;
  float ele1_E_true,ele2_E_true;
  float ele1_tkP,ele2_tkP;
  int ele1_isEB, ele2_isEB;
  float   ele1_fbrem,ele2_fbrem;
  int isW, isZ;
  
  inputTree->SetBranchAddress("ele1_recHit_E", &ele1_recHit_E);
  inputTree->SetBranchAddress("ele2_recHit_E", &ele2_recHit_E);
  inputTree->SetBranchAddress("ele1_recHit_hashedIndex", &ele1_recHit_hashedIndex);
  inputTree->SetBranchAddress("ele2_recHit_hashedIndex", &ele2_recHit_hashedIndex);
  inputTree->SetBranchAddress("ele1_recHit_flag", &ele1_recHit_flag);
  inputTree->SetBranchAddress("ele2_recHit_flag", &ele2_recHit_flag);
  inputTree->SetBranchAddress("ele1_E_true", &ele1_E_true);
  inputTree->SetBranchAddress("ele2_E_true", &ele2_E_true);
  inputTree->SetBranchAddress("ele1_tkP", &ele1_tkP);
  inputTree->SetBranchAddress("ele2_tkP", &ele2_tkP);
  inputTree->SetBranchAddress("ele1_isEB", &ele1_isEB);
  inputTree->SetBranchAddress("ele2_isEB", &ele2_isEB);
  inputTree->SetBranchAddress("ele1_fbrem", &ele1_fbrem);
  inputTree->SetBranchAddress("ele2_fbrem", &ele2_fbrem);
  inputTree->SetBranchAddress("isW", &isW);
  inputTree->SetBranchAddress("isZ", &isZ);
 
  TProfile2D* mapMomentum = new TProfile2D("mapMomentum","mapMomentum",360,0,360,170,-85,85);
  TProfile2D* mapfbrem = new TProfile2D("mapfbrem","mapfbrem",360,0,360,170,-85,85);

  /// Make fbrem and p/ptrue map cycling on MC --> all the events 

  for(Long64_t i=0; i< inputTree->GetEntries(); i++)
  {
   inputTree->GetEntry(i);
   if (!(i%100000))std::cerr<<i;
   if (!(i%10000)) std::cerr<<".";
       
   if (ele1_isEB == 1 && (isW==1 || isZ==1)) {
  
      double E_seed=0;
      int seed_hashedIndex, iseed;

      for (unsigned int iRecHit = 0; iRecHit < ele1_recHit_E->size(); iRecHit++ ) {
            
            if(ele1_recHit_E -> at(iRecHit) > E_seed &&  ele1_recHit_flag->at(iRecHit) < 4 ) /// control if this recHit is good
            {
              seed_hashedIndex=ele1_recHit_hashedIndex -> at(iRecHit);
              iseed=iRecHit;
              E_seed=ele1_recHit_E -> at(iRecHit);  ///! Seed search

            }
      }
    
   int eta_seed = GetIetaFromHashedIndex(seed_hashedIndex);
   int phi_seed = GetIphiFromHashedIndex(seed_hashedIndex);
   if(ele1_tkP>0 && ele1_E_true>0 && abs(ele1_tkP/ele1_E_true)<2. && abs(ele1_tkP/ele1_E_true)>0.5) mapMomentum->Fill(phi_seed,eta_seed,abs(ele1_tkP/ele1_E_true));
   mapfbrem->Fill(phi_seed,eta_seed,abs(ele1_fbrem)); 
   }
   
   if (ele2_isEB == 1 && isZ==1) {

      double E_seed=0;
      int seed_hashedIndex, iseed;

      for (unsigned int iRecHit = 0; iRecHit < ele2_recHit_E->size(); iRecHit++ ) {
            
            if(ele2_recHit_E -> at(iRecHit) > E_seed &&  ele2_recHit_flag->at(iRecHit) < 4 ) /// control if this recHit is good
            {
              seed_hashedIndex=ele2_recHit_hashedIndex -> at(iRecHit);
              iseed=iRecHit;
              E_seed=ele2_recHit_E -> at(iRecHit);  ///! Seed search

            }
      }
    
   int eta_seed = GetIetaFromHashedIndex(seed_hashedIndex);
   int phi_seed = GetIphiFromHashedIndex(seed_hashedIndex);
   if(ele2_tkP>0 && ele2_E_true>0 && abs(ele2_tkP/ele2_E_true)<2. && abs(ele2_tkP/ele2_E_true)>0.5) mapMomentum->Fill(phi_seed,eta_seed,abs(ele2_tkP/ele2_E_true));
   mapfbrem->Fill(phi_seed,eta_seed,abs(ele2_fbrem));

   }
 }

 /// Map of IC normalized in eta rings

 std::vector< std::pair<int,int> > TT_centre ;
 
 TT_centre.push_back(std::pair<int,int> (58,49));
 TT_centre.push_back(std::pair<int,int> (53,109));
 TT_centre.push_back(std::pair<int,int> (8,114));
 TT_centre.push_back(std::pair<int,int> (83,169));
 TT_centre.push_back(std::pair<int,int> (53,174));
 TT_centre.push_back(std::pair<int,int> (63,194));
 TT_centre.push_back(std::pair<int,int> (83,224));
 TT_centre.push_back(std::pair<int,int> (73,344));
 TT_centre.push_back(std::pair<int,int> (83,358));
 TT_centre.push_back(std::pair<int,int> (-13,18));
 TT_centre.push_back(std::pair<int,int> (-18,23));
 TT_centre.push_back(std::pair<int,int> (-8,53));
 TT_centre.push_back(std::pair<int,int> (-3,63));
 TT_centre.push_back(std::pair<int,int> (-53,128));
 TT_centre.push_back(std::pair<int,int> (-53,183));
 TT_centre.push_back(std::pair<int,int> (-83,193));
 TT_centre.push_back(std::pair<int,int> (-74,218));
 TT_centre.push_back(std::pair<int,int> (-8,223));
 TT_centre.push_back(std::pair<int,int> (-68,303));
 TT_centre.push_back(std::pair<int,int> (-43,328));
 
 /// Mean over phi corrected skipping dead channel 

 for (int iEta = 1 ; iEta < h_scale_EB->GetNbinsY()+1; iEta ++)
 {
   float SumIC = 0;
   int numIC = 0;
   
   for(int iPhi = 1 ; iPhi < h_scale_EB->GetNbinsX()+1 ; iPhi++)
   {
    bool isGood = CheckxtalIC(h_scale_EB,iPhi,iEta);
    bool isGoodTT = CheckxtalTT(iPhi,iEta,TT_centre);
 
     if(isGood && isGoodTT)
     {
      SumIC = SumIC + h_scale_EB->GetBinContent(iPhi,iEta);
      numIC ++ ;
     }
    }
   //fede: skip bad channels and bad TTs
   for (int iPhi = 1; iPhi< h_scale_EB->GetNbinsX()+1  ; iPhi++)
   { 
     if(numIC==0 || SumIC==0) continue;

     bool isGood = CheckxtalIC(h_scale_EB,iPhi,iEta);
     bool isGoodTT = CheckxtalTT(iPhi,iEta,TT_centre);
     if (!isGood || !isGoodTT) continue;

     hcmap->SetBinContent(iPhi,iEta,h_scale_EB->GetBinContent(iPhi,iEta)/(SumIC/numIC));
   }
  }

 /// ratio map

 TH2F* ratioMap = (TH2F*) hcmap -> Clone("ratioMap");
 ratioMap->Reset();

 for( int i =0 ; i<hcmap->GetNbinsX() ; i++){
  for( int j=0; j<hcmap->GetNbinsY() ; j++){
   if(hcmap->GetBinContent(i,j)!=0 && mapMomentum->GetBinContent(i,j)!=0)
    ratioMap->SetBinContent(i+1,j+1,mapMomentum->GetBinContent(i,j)/hcmap->GetBinContent(i,j));
  }
 }

 /// Profile along phi taking into account dead channels
 TGraphErrors *coeffEBp = new TGraphErrors();
 TGraphErrors *coeffEBm = new TGraphErrors();

 for (int iPhi =1; iPhi< hcmap->GetNbinsX()+1 ; iPhi++){
  double SumEBp =0, SumEBm=0;
  double iEBp=0, iEBm=0;
  for(int iEta = 1; iEta<hcmap->GetNbinsY()+1 ; iEta++){
     if(hcmap->GetBinContent(iPhi,iEta)==0)continue;
     if(iEta>85) {SumEBp=SumEBp+mapMomentum->GetBinContent(iPhi,iEta)/hcmap->GetBinContent(iPhi,iEta);
                  iEBp++;}
     else{ SumEBm=SumEBm+mapMomentum->GetBinContent(iPhi,iEta)/hcmap->GetBinContent(iPhi,iEta);
           iEBm++;}
     }
  coeffEBp->SetPoint(iPhi-1,iPhi-1,SumEBp/iEBp);
  coeffEBm->SetPoint(iPhi-1,iPhi-1,SumEBm/iEBm);

  }
     
 TFile* outputGraph = new TFile("output/GraphFor_P_Correction.root","RECREATE");
 outputGraph->cd();

 coeffEBp->Write("coeffEBp");
 coeffEBm->Write("coeffEBm");
 outputGraph->Close();
     
 gROOT->Reset();
 gROOT->SetStyle("Plain");

 gStyle->SetPadTickX(1);
 gStyle->SetPadTickY(1);
 gStyle->SetOptTitle(1); 
 gStyle->SetOptStat(0); 
 gStyle->SetOptFit(0); 
 gStyle->SetFitFormat("6.3g"); 
 gStyle->SetPalette(1); 
  
 gStyle->SetTextFont(42);
 gStyle->SetTextSize(0.05);
 gStyle->SetTitleFont(42,"xyz");
 gStyle->SetTitleSize(0.05);
 gStyle->SetLabelFont(42,"xyz");
 gStyle->SetLabelSize(0.05);
 gStyle->SetTitleXOffset(0.8);
 gStyle->SetTitleYOffset(1.1);
 gROOT->ForceStyle();
 
 TCanvas* c1 = new TCanvas("mapMomentum","mapMomentum",1);
 c1->cd();
 mapMomentum->GetXaxis()->SetTitle("#phi");
 mapMomentum->GetXaxis()->SetNdivisions(20);
 c1->SetGridx(); 
 mapMomentum->GetYaxis()->SetTitle("#eta");
 mapMomentum->GetZaxis()->SetRangeUser(0.7,1.3);
 mapMomentum->Draw("colz");

 TCanvas* c2 = new TCanvas("mapfbrem","mapfbrem",1);
 c2->cd();
 mapfbrem->GetXaxis()->SetTitle("#phi");
 mapfbrem->GetYaxis()->SetTitle("#eta");
 mapfbrem->GetXaxis()->SetNdivisions(20);
 c2->SetGridx(); 
 mapfbrem->GetZaxis()->SetRangeUser(0.,0.7);
 mapfbrem->Draw("colz");

 TCanvas* c3 = new TCanvas("ratioMap","ratioMap",1);
 c3->cd();
 ratioMap->GetXaxis()->SetTitle("#phi");
 ratioMap->GetYaxis()->SetTitle("#eta");
 ratioMap->GetXaxis()->SetNdivisions(20);
 c3->SetGridx(); 
 ratioMap->GetZaxis()->SetRangeUser(0.7,1.3);
 ratioMap->Draw("colz");

 TCanvas* c4 = new TCanvas("coeffEB","coeffEB",1);
 c4->cd();
 coeffEBp->GetXaxis()->SetTitle("#phi");
 coeffEBp->GetYaxis()->SetTitle("p/p_{true}");
 coeffEBp -> SetMarkerStyle(20);
 coeffEBp -> SetMarkerSize(1);
 coeffEBp -> SetMarkerColor(kRed+1); 
 coeffEBp -> SetLineColor(kRed+1); 
 c4->SetGridx(); 
 c4->SetGridy(); 
 ratioMap->Draw("ap");

 coeffEBm->GetXaxis()->SetTitle("#phi");
 coeffEBm->GetYaxis()->SetTitle("p/p_{true}");
 coeffEBm -> SetMarkerStyle(20);
 coeffEBm -> SetMarkerSize(1);
 coeffEBm -> SetMarkerColor(kBlue+1); 
 coeffEBm -> SetLineColor(kBlue+1); 
 coeffEBm->Draw("ap same");


 theApp->Run();
 return 0;
}
Example #22
0
void sigma_plots_mass_4D(int sigMass, double cut_pt1IN, double cut_pt2IN, double cut_metIN,double cut_ptggIN, double ptLead_cutIN, double DPHI_cutIN, double maxDPHIJet_cutIN,double minDPHIJet_cutIN){

  gStyle->SetPadTickY(1);
  gStyle->SetPadTickX(1);



  /*
  TFile *sig = TFile::Open(Form("./50ns_betaV4/NewWeightDMHtoGG_M%d.root",sigMass),"READ");
  TFile *bkg1 =  TFile::Open("./50ns_betaV4/NewWeightDiPhoton.root","READ"); 
  TFile *bkg2 =  TFile::Open("./50ns_betaV4/NewWeightDYJetsToLL.root","READ");
  TFile *bkg3 =  TFile::Open("./50ns_betaV4/NewWeightGJets.root","READ");  
  TFile *bkg4 =  TFile::Open("./50ns_betaV4/NewWeightGluGluHToGG.root","READ");
  TFile *bkg5 =  TFile::Open("./50ns_betaV4/NewWeightQCD.root","READ");
  TFile *bkg6 =  TFile::Open("./50ns_betaV4/NewWeightVH.root","READ");
  */  
  TFile *data =  TFile::Open("./25ns_2246inv_v3/DoubleEG.root","READ"); 
  TFile *sig = TFile::Open(Form("./25ns_2246inv_v3/2HDM_mZP%d.root",sigMass),"READ");
  if(sig == NULL) cout<<"sig fails"<<endl;
  TFile *bkg1 =  TFile::Open("./25ns_2246inv_v3/DiPhoton.root","READ"); 
  if(bkg1 == NULL) cout<<"bkg1 fails"<<endl;
  TFile *bkg2 =  TFile::Open("./25ns_2246inv_v3/DYJetsToLL.root","READ");
  if(bkg2 == NULL) cout<<"bkg2 fails"<<endl;
  TFile *bkg3 =  TFile::Open("./25ns_2246inv_v3/GJets.root","READ");  
  if(bkg3 == NULL) cout<<"bkg3 fails"<<endl;
  TFile *bkg4 =  TFile::Open("./25ns_2246inv_v3/GluGluHToGG.root","READ");
  if(bkg4 == NULL) cout<<"bkg4 fails"<<endl;
  TFile *bkg5 =  TFile::Open("./25ns_2246inv_v3/QCD.root","READ");
  if(bkg5 == NULL) cout<<"bkg5 fails"<<endl;
  TFile *bkg6 =  TFile::Open("./25ns_2246inv_v3/VH.root","READ");
  if(bkg6 == NULL) cout<<"bkg6 fails"<<endl;
  TFile *bkg7 =  TFile::Open("./25ns_2246inv_v3/ttHJetToGG.root","READ");
  TFile *bkg8 =  TFile::Open("./25ns_2246inv_v3/VBFHToGG.root","READ");
  TFile *bkg9 =  TFile::Open("./25ns_2246inv_v3/TGJets.root","READ");
  TFile *bkg10 =  TFile::Open("./25ns_2246inv_v3/TTGJets.root","READ");
  TFile *bkg11 =  TFile::Open("./25ns_2246inv_v3/WGToLNuG.root","READ");
  TFile *bkg12 =  TFile::Open("./25ns_2246inv_v3/ZGTo2LG.root","READ");


 
  TTree *tree_data = (TTree*) data->Get("DiPhotonTree"); 
  TTree *tree_sig = (TTree*) sig->Get("DiPhotonTree"); 
  TTree *tree_bkg1 = (TTree*) bkg1->Get("DiPhotonTree");
  TTree *tree_bkg2 = (TTree*) bkg2->Get("DiPhotonTree");
  TTree *tree_bkg3 = (TTree*) bkg3->Get("DiPhotonTree");
  TTree *tree_bkg4 = (TTree*) bkg4->Get("DiPhotonTree");
  TTree *tree_bkg5 = (TTree*) bkg5->Get("DiPhotonTree");
  TTree *tree_bkg6 = (TTree*) bkg6->Get("DiPhotonTree");
  TTree *tree_bkg7 = (TTree*) bkg7->Get("DiPhotonTree");
  TTree *tree_bkg8 = (TTree*) bkg8->Get("DiPhotonTree");
  TTree *tree_bkg9 = (TTree*) bkg9->Get("DiPhotonTree");
  TTree *tree_bkg10 = (TTree*) bkg10->Get("DiPhotonTree");
  TTree *tree_bkg11 = (TTree*) bkg11->Get("DiPhotonTree");
  TTree *tree_bkg12 = (TTree*) bkg12->Get("DiPhotonTree");


  TCut Cut_pt1;
  TCut Cut_pt2;
  TCut Cut_met;
  TCut Cut_ptgg;
  TCut mggmax = "mgg<130";
  TCut mggmin = "mgg>120";
  TCut eveto1 = "eleveto1 == 1";
  TCut eveto2 = "eleveto2 == 1";
  TCut eveto = eveto1 && eveto2;
  TCut genmatch = "((genmatch1==1 && genmatch2==0)||(genmatch1==0 && genmatch2==1)||(genmatch1==0 && genmatch2==0))";  

  TCut DPHIcut = Form("FDelta(pt1,eta1,phi1,0.,pt2,eta2,phi2,0.,t1pfmetPhi)>%lf",DPHI_cutIN);
  TCut maxDPHIJetcut = Form("MAX(ptJetLead,phiJetLead,ptJetSubLead,phiJetSubLead,ptJet3,phiJet3,ptJet4,phiJet4,t1pfmetPhi)<%lf",maxDPHIJet_cutIN);
  TCut minDPHIJetcut = Form("myMIN(ptJetLead,phiJetLead,ptJetSubLead,phiJetSubLead,ptJet3,phiJet3,ptJet4,phiJet4,t1pfmetPhi)>%lf",minDPHIJet_cutIN);
  TCut nMuonCut = "nMuons == 0";
  TCut nEleCut = "nEle <= 1";  

  TCanvas *canvas = new TCanvas("canvas","",600,400);   
  int i = 0;
  int j = 0;
  int k = 0;
  int l = 0;
  double cut_pt1 = 0;
  double cut_pt2 = 0;
  double cut_met = 0;
  double cut_ptgg = 0;
   
  
  double Stot_pt1 = 0;
  double Stot_pt2 = 0;
  double Stot_met = 0;
  double Stot_ptgg = 0;
  double S = 0;
  double F1 = 0;
  double F2 = 0;
  double F3 = 0;
  double F4 = 0;
  double F5 = 0;
  double F6 = 0;
  double F7 = 0;
  double F8 = 0;
  double F9 = 0;
  double F10 = 0;
  double F11 = 0;
  double F12 = 0;
  double B = 0;
  double Eff = 0;
  
  double Sig3 = 0;
  double Sig5 = 0;
  int NstepsPt1 = 20; 
  int NstepsPt2 = 20; 
  int NstepsMET = 20; 
 int NstepsPtgg = 20; 
  double temp = 0;

  double firstCutPt1 = cut_pt1IN  - 0.05*NstepsPt1/2; 
  double firstCutPt2 = 1./4.;
  double firstCutMET = cut_metIN - 5*NstepsMET/2;
double firstCutPtgg = cut_ptggIN - 5*NstepsPtgg/2;
  
  double crossSec = 1.; 
  double N = 0.;
     

   
  cout<<"############Segnale M"<<sigMass<<endl;
  cout<<"120 < mgg < 130"<<endl;  
  ios_base::fmtflags oldflags = std::cout.flags();
  TH2F *hpt1VSpt2 = new TH2F("hpt1VSpt2","",NstepsPt1,firstCutPt1,firstCutPt1+0.05*NstepsPt1,NstepsPt2,firstCutPt2,firstCutPt2+0.05*NstepsPt2);
  TH2F *hpt1VSmet = new TH2F("hpt1VSmet","",NstepsPt1,firstCutPt1,firstCutPt1+0.05*NstepsPt1,NstepsMET,firstCutMET,firstCutMET+5*NstepsMET);
TH2F *hptggVSmet = new TH2F("hptggVSmet","",NstepsPtgg,firstCutPtgg,firstCutPtgg+5*NstepsPtgg,NstepsMET,firstCutMET,firstCutMET+5*NstepsMET);
  TH2F *hmetVSpt2 = new TH2F("metVSpt2","",NstepsMET,firstCutMET,firstCutMET+5*NstepsMET,NstepsPt2,firstCutPt2,firstCutPt2+0.05*NstepsPt2);
 TH2F *hptggVSpt2 = new TH2F("ptggVSpt2","",NstepsPtgg,firstCutPtgg,firstCutPtgg+5*NstepsPtgg,NstepsPt2,firstCutPt2,firstCutPt2+0.05*NstepsPt2);
   TH2F *hpt1VSptgg = new TH2F("hpt1VSptgg","",NstepsPt1,firstCutPt1,firstCutPt1+0.05*NstepsPt1,NstepsPtgg,firstCutPtgg,firstCutPtgg+5*NstepsPtgg);
  
  tree_sig->Draw("(pt1)>>pt1_tot1(30,0,1000)","weight"*(mggmin && mggmax && eveto));
  TH1F *pt1_tot1 =(TH1F*)gPad->GetPrimitive("pt1_tot1");
  pt1_tot1->Scale(crossSec); 
  Stot_pt1 = pt1_tot1->Integral();
  

  Cut_met = Form("t1pfmet>%lf",cut_metIN);
  Cut_ptgg = Form("ptgg>%lf",cut_ptggIN);
  for(i = 0; i<NstepsPt1;i++){
    cut_pt1 = firstCutPt1 + 0.05*i +0.001;
    Cut_pt1 = Form("pt1/mgg>%lf",cut_pt1);   
    for(j = 0; j<NstepsPt2;j++){
      cut_pt2 = firstCutPt2 + 0.05*j +0.001;
      Cut_pt2 = Form("pt2/mgg>%lf",cut_pt2);
      tree_data->Draw("(pt1)>>pt1_data(30,0,1000)","(mgg<115||mgg>135)"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut && nMuonCut && nEleCut ));                                           
      TH1F *pt1_data =(TH1F*)gPad->GetPrimitive("pt1_data");
      N = pt1_data->GetEntries();
      Sig5= 0.;
      if(N>=0){
      
	   
      tree_sig->Draw("(pt1)>>pt1_1(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto &&  maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut));
      TH1F *pt1_1 =(TH1F*)gPad->GetPrimitive("pt1_1"); 
      pt1_1->Scale(crossSec);      
      S = pt1_1->Integral();   
      tree_bkg1->Draw("(pt1)>>pt1_bkg1(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut));
      TH1F *pt1_bkg1 =(TH1F*)gPad->GetPrimitive("pt1_bkg1");
      
      F1 = pt1_bkg1->Integral();   
      tree_bkg2->Draw("(pt1)>>pt1_bkg2(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut));
      TH1F *pt1_bkg2 =(TH1F*)gPad->GetPrimitive("pt1_bkg2");
      
      F2 = pt1_bkg2->Integral();
      if(F2<0) F2 = 0;          
      tree_bkg3->Draw("(pt1)>>pt1_bkg3(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut && genmatch));
      TH1F *pt1_bkg3 =(TH1F*)gPad->GetPrimitive("pt1_bkg3");
      
      F3 = pt1_bkg3->Integral();  
      tree_bkg4->Draw("(pt1)>>pt1_bkg4(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut));
      TH1F *pt1_bkg4 =(TH1F*)gPad->GetPrimitive("pt1_bkg4");
      
      F4 = pt1_bkg4->Integral();    
      tree_bkg5->Draw("(pt1)>>pt1_bkg5(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut && genmatch));
      TH1F *pt1_bkg5 =(TH1F*)gPad->GetPrimitive("pt1_bkg5");
      
      F5 = pt1_bkg5->Integral();    
      tree_bkg6->Draw("(pt1)>>pt1_bkg6(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut)); 
      TH1F *pt1_bkg6 =(TH1F*)gPad->GetPrimitive("pt1_bkg6");
      F6 = pt1_bkg6->Integral();  
      tree_bkg7->Draw("(pt1)>>pt1_bkg7(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut && minDPHIJetcut && nMuonCut && nEleCut ));                                             
      TH1F *pt1_bkg7 =(TH1F*)gPad->GetPrimitive("pt1_bkg7");
      F7 = pt1_bkg7->Integral();
      tree_bkg8->Draw("(pt1)>>pt1_bkg8(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut && minDPHIJetcut && nMuonCut && nEleCut ));                                            
      TH1F *pt1_bkg8 =(TH1F*)gPad->GetPrimitive("pt1_bkg8");
      F8 = pt1_bkg8->Integral();
      tree_bkg9->Draw("(pt1)>>pt1_bkg9(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut && minDPHIJetcut && nMuonCut && nEleCut ));                                             
      TH1F *pt1_bkg9 =(TH1F*)gPad->GetPrimitive("pt1_bkg9");
      F9 = pt1_bkg9->Integral();
      if(F9<0) F9=0;
      tree_bkg10->Draw("(pt1)>>pt1_bkg10(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut && nMuonCut && nEleCut ));                                           
      TH1F *pt1_bkg10 =(TH1F*)gPad->GetPrimitive("pt1_bkg10");
      F10 = pt1_bkg10->Integral();
      tree_bkg11->Draw("(pt1)>>pt1_bkg11(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut && minDPHIJetcut && nMuonCut && nEleCut ));                                       
      TH1F *pt1_bkg11 =(TH1F*)gPad->GetPrimitive("pt1_bkg11");
      F11 = pt1_bkg11->Integral();
      tree_bkg12->Draw("(pt1)>>pt1_bkg12(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut && nMuonCut && nEleCut ));                                           
      TH1F *pt1_bkg12 =(TH1F*)gPad->GetPrimitive("pt1_bkg12");
      F12 = pt1_bkg12->Integral();
      
      
      
      B = F1+F2+F3+F4+F5+F6+F7+F8+F9+F10+F11+F12;
      Eff = S/Stot_pt1;
      Sig3 = Eff/(1.5+sqrt(B));
      Sig5 = Eff/(2.5+sqrt(B));
      }
      hpt1VSpt2->Fill(cut_pt1,cut_pt2,Sig5);
    }
  }
  
  /////////////////////////////////////////////////////////
Cut_pt2 = Form("pt2/mgg>%lf",cut_pt2IN);
Cut_ptgg = Form("ptgg>%lf",cut_ptggIN);
  for(i = 0; i<NstepsPt1;i++){
    cut_pt1 = firstCutPt1 + 0.05*i +0.001;
    Cut_pt1 = Form("pt1/mgg>%lf",cut_pt1);
      for(j = 0; j<NstepsMET;j++){
	cut_met = firstCutMET + 5*j;
	Cut_met = Form("t1pfmet>%lf",cut_met);
   tree_data->Draw("(pt1)>>pt1_data(30,0,1000)","(mgg<115||mgg>135)"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut && nMuonCut && nEleCut ));                                           
      TH1F *pt1_data =(TH1F*)gPad->GetPrimitive("pt1_data");
      N = pt1_data->GetEntries();
      Sig5= 0.;
      if(N>=0){


	tree_sig->Draw("(pt1)>>pt1_1(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_met && Cut_pt2 && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut));
	TH1F *pt1_1 =(TH1F*)gPad->GetPrimitive("pt1_1"); 
	pt1_1->Scale(crossSec);   
	S = pt1_1->Integral();   
	tree_bkg1->Draw("(pt1)>>pt1_bkg1(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_met && Cut_pt2 && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut));
	TH1F *pt1_bkg1 =(TH1F*)gPad->GetPrimitive("pt1_bkg1");

	F1 = pt1_bkg1->Integral();   
	tree_bkg2->Draw("(pt1)>>pt1_bkg2(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_met && Cut_pt2 && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut));
	TH1F *pt1_bkg2 =(TH1F*)gPad->GetPrimitive("pt1_bkg2");

	F2 = pt1_bkg2->Integral();
	if(F2<0) F2 = 0;     
	tree_bkg3->Draw("(pt1)>>pt1_bkg3(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_met && Cut_pt2 && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut && genmatch));
	TH1F *pt1_bkg3 =(TH1F*)gPad->GetPrimitive("pt1_bkg3");

	F3 = pt1_bkg3->Integral();  
	tree_bkg4->Draw("(pt1)>>pt1_bkg4(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_met && Cut_pt2 && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut));
	TH1F *pt1_bkg4 =(TH1F*)gPad->GetPrimitive("pt1_bkg4");

	F4 = pt1_bkg4->Integral();    
	tree_bkg5->Draw("(pt1)>>pt1_bkg5(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_met && Cut_pt2 && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut && genmatch));
	TH1F *pt1_bkg5 =(TH1F*)gPad->GetPrimitive("pt1_bkg5");

	F5 = pt1_bkg5->Integral();   
 	tree_bkg6->Draw("(pt1)>>pt1_bkg6(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_met && Cut_pt2 && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut)); 
	TH1F *pt1_bkg6 =(TH1F*)gPad->GetPrimitive("pt1_bkg6");
	F6 = pt1_bkg6->Integral();  
	tree_bkg7->Draw("(pt1)>>pt1_bkg7(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_met && Cut_pt2 && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut)); 
  TH1F *pt1_bkg7 =(TH1F*)gPad->GetPrimitive("pt1_bkg7");
	   F7 = pt1_bkg7->Integral();
	   tree_bkg8->Draw("(pt1)>>pt1_bkg8(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut && minDPHIJetcut && nMuonCut && nEleCut ));                                            
	   TH1F *pt1_bkg8 =(TH1F*)gPad->GetPrimitive("pt1_bkg8");
	   F8 = pt1_bkg8->Integral();
	   tree_bkg9->Draw("(pt1)>>pt1_bkg9(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut && minDPHIJetcut && nMuonCut && nEleCut ));                                             
	   TH1F *pt1_bkg9 =(TH1F*)gPad->GetPrimitive("pt1_bkg9");
	   F9 = pt1_bkg9->Integral();
	   if(F9<0) F9 = 0;
	   tree_bkg10->Draw("(pt1)>>pt1_bkg10(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut && nMuonCut && nEleCut ));                                           
	   TH1F *pt1_bkg10 =(TH1F*)gPad->GetPrimitive("pt1_bkg10");
	   F10 = pt1_bkg10->Integral();
	   tree_bkg11->Draw("(pt1)>>pt1_bkg11(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut && minDPHIJetcut && nMuonCut && nEleCut ));                                       
	   TH1F *pt1_bkg11 =(TH1F*)gPad->GetPrimitive("pt1_bkg11");
	   F11 = pt1_bkg11->Integral();
	   tree_bkg12->Draw("(pt1)>>pt1_bkg12(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut && nMuonCut && nEleCut ));                                           
	   TH1F *pt1_bkg12 =(TH1F*)gPad->GetPrimitive("pt1_bkg12");
	   F12 = pt1_bkg12->Integral();



	   B = F1+F2+F3+F4+F5+F6+F7+F8+F9+F10+F11+F12;




   
	Eff = S/Stot_pt1;
	Sig3 = Eff/(1.5+sqrt(B));
	Sig5 = Eff/(2.5+sqrt(B));
      }
	hpt1VSmet->Fill(cut_pt1,cut_met,Sig5);
      }
  }



  /////////////////////////////////////////////////////////
Cut_pt1 = Form("pt1/mgg>%lf",cut_pt1IN);
Cut_ptgg = Form("ptgg>%lf",cut_ptggIN);
  for(i = 0; i<NstepsPt2;i++){
    cut_pt2 = firstCutPt2 + 0.05*i+0.001;
    Cut_pt2 = Form("pt2/mgg>%lf",cut_pt2);
    for(j = 0; j<NstepsMET;j++){
	cut_met = firstCutMET + 5*j;
	Cut_met = Form("t1pfmet>%lf",cut_met);
	tree_data->Draw("(pt1)>>pt1_data(30,0,1000)","(mgg<115||mgg>135)"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut && nMuonCut && nEleCut ));                                           
	TH1F *pt1_data =(TH1F*)gPad->GetPrimitive("pt1_data");
	N = pt1_data->GetEntries();
	Sig5= 0.;
	if(N>=0){
	tree_sig->Draw("(pt1)>>pt1_1(30,0,1000)","weight"*(Cut_pt2 && Cut_met && Cut_pt1 && Cut_ptgg && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut));
	TH1F *pt1_1 =(TH1F*)gPad->GetPrimitive("pt1_1"); 
	pt1_1->Scale(crossSec);   	
	S = pt1_1->Integral();   
	tree_bkg1->Draw("(pt1)>>pt1_bkg1(30,0,1000)","weight"*(Cut_pt2 && Cut_met && Cut_pt1 && Cut_ptgg && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut));
	TH1F *pt1_bkg1 =(TH1F*)gPad->GetPrimitive("pt1_bkg1");
	
	F1 = pt1_bkg1->Integral();   
	tree_bkg2->Draw("(pt1)>>pt1_bkg2(30,0,1000)","weight"*(Cut_pt2 && Cut_met && Cut_pt1 && Cut_ptgg && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut));
	TH1F *pt1_bkg2 =(TH1F*)gPad->GetPrimitive("pt1_bkg2");
	
	F2 = pt1_bkg2->Integral();
	if(F2<0) F2 = 0;     
	tree_bkg3->Draw("(pt1)>>pt1_bkg3(30,0,1000)","weight"*(Cut_pt2 && Cut_met && Cut_pt1 && Cut_ptgg && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut && genmatch));
	TH1F *pt1_bkg3 =(TH1F*)gPad->GetPrimitive("pt1_bkg3");

	F3 = pt1_bkg3->Integral();  
	tree_bkg4->Draw("(pt1)>>pt1_bkg4(30,0,1000)","weight"*(Cut_pt2 && Cut_met && Cut_pt1 && Cut_ptgg && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut));
	TH1F *pt1_bkg4 =(TH1F*)gPad->GetPrimitive("pt1_bkg4");
	
	F4 = pt1_bkg4->Integral();    
	tree_bkg5->Draw("(pt1)>>pt1_bkg5(30,0,1000)","weight"*(Cut_pt2 && Cut_met && Cut_pt1 && Cut_ptgg && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut && genmatch));
	TH1F *pt1_bkg5 =(TH1F*)gPad->GetPrimitive("pt1_bkg5");
	
	F5 = pt1_bkg5->Integral();    
	tree_bkg6->Draw("(pt1)>>pt1_bkg6(30,0,1000)","weight"*(Cut_pt2 && Cut_met && Cut_pt1 && Cut_ptgg && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut)); 
	TH1F *pt1_bkg6 =(TH1F*)gPad->GetPrimitive("pt1_bkg6");

	F6 = pt1_bkg6->Integral();  
	
	tree_bkg7->Draw("(pt1)>>pt1_bkg7(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut && minDPHIJetcut && nMuonCut && nEleCut ));                                             
	TH1F *pt1_bkg7 =(TH1F*)gPad->GetPrimitive("pt1_bkg7");
	F7 = pt1_bkg7->Integral();
	tree_bkg8->Draw("(pt1)>>pt1_bkg8(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut && minDPHIJetcut && nMuonCut && nEleCut ));                                            
	TH1F *pt1_bkg8 =(TH1F*)gPad->GetPrimitive("pt1_bkg8");
	F8 = pt1_bkg8->Integral();
	tree_bkg9->Draw("(pt1)>>pt1_bkg9(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut && minDPHIJetcut && nMuonCut && nEleCut ));                                             
	TH1F *pt1_bkg9 =(TH1F*)gPad->GetPrimitive("pt1_bkg9");
	F9 = pt1_bkg9->Integral();
	if(F9<0) F9=0;
	tree_bkg10->Draw("(pt1)>>pt1_bkg10(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut && nMuonCut && nEleCut ));                                           
	TH1F *pt1_bkg10 =(TH1F*)gPad->GetPrimitive("pt1_bkg10");
	F10 = pt1_bkg10->Integral();
	tree_bkg11->Draw("(pt1)>>pt1_bkg11(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut && minDPHIJetcut && nMuonCut && nEleCut ));                                       
	TH1F *pt1_bkg11 =(TH1F*)gPad->GetPrimitive("pt1_bkg11");
	F11 = pt1_bkg11->Integral();
	tree_bkg12->Draw("(pt1)>>pt1_bkg12(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut && nMuonCut && nEleCut ));                                           
	TH1F *pt1_bkg12 =(TH1F*)gPad->GetPrimitive("pt1_bkg12");
	F12 = pt1_bkg12->Integral();
	
      
      
	B = F1+F2+F3+F4+F5+F6+F7+F8+F9+F10+F11+F12;
	
	
	Eff = S/Stot_pt1;
	Sig3 = Eff/(1.5+sqrt(B));
	Sig5 = Eff/(2.5+sqrt(B));
	}
	hmetVSpt2->Fill(cut_met,cut_pt2,Sig5);
      }
  }




  /////////////////////////////////////////////////////////
Cut_pt2 = Form("pt2/mgg>%lf",cut_pt2IN);
Cut_pt1 = Form("pt1/mgg>%lf",cut_pt1IN);
  for(i = 0; i<NstepsPtgg;i++){
    cut_ptgg = firstCutPtgg + 5*i;
    Cut_ptgg = Form("ptgg>%lf",cut_ptgg);
    for(j = 0; j<NstepsMET;j++){
	cut_met = firstCutMET + 5*j;
	Cut_met = Form("t1pfmet>%lf",cut_met);
	tree_data->Draw("(pt1)>>pt1_data(30,0,1000)","(mgg<115||mgg>135)"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut && nMuonCut && nEleCut ));                                           
	TH1F *pt1_data =(TH1F*)gPad->GetPrimitive("pt1_data");
	N = pt1_data->GetEntries();
	Sig5= 0.;
	if(N>=0){
	tree_sig->Draw("(pt1)>>pt1_1(30,0,1000)","weight"*(Cut_pt2 && Cut_met && Cut_pt1 && Cut_ptgg && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut));
	TH1F *pt1_1 =(TH1F*)gPad->GetPrimitive("pt1_1"); 
	pt1_1->Scale(crossSec);   	
	S = pt1_1->Integral();   
	tree_bkg1->Draw("(pt1)>>pt1_bkg1(30,0,1000)","weight"*(Cut_pt2 && Cut_met && Cut_pt1 && Cut_ptgg && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut));
	TH1F *pt1_bkg1 =(TH1F*)gPad->GetPrimitive("pt1_bkg1");
	
	F1 = pt1_bkg1->Integral();   
	tree_bkg2->Draw("(pt1)>>pt1_bkg2(30,0,1000)","weight"*(Cut_pt2 && Cut_met && Cut_pt1 && Cut_ptgg && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut));
	TH1F *pt1_bkg2 =(TH1F*)gPad->GetPrimitive("pt1_bkg2");
	
	F2 = pt1_bkg2->Integral();
	if(F2<0) F2 = 0;     
	tree_bkg3->Draw("(pt1)>>pt1_bkg3(30,0,1000)","weight"*(Cut_pt2 && Cut_met && Cut_pt1 && Cut_ptgg && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut && genmatch));
	TH1F *pt1_bkg3 =(TH1F*)gPad->GetPrimitive("pt1_bkg3");

	F3 = pt1_bkg3->Integral();  
	tree_bkg4->Draw("(pt1)>>pt1_bkg4(30,0,1000)","weight"*(Cut_pt2 && Cut_met && Cut_pt1 && Cut_ptgg && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut));
	TH1F *pt1_bkg4 =(TH1F*)gPad->GetPrimitive("pt1_bkg4");
	
	F4 = pt1_bkg4->Integral();    
	tree_bkg5->Draw("(pt1)>>pt1_bkg5(30,0,1000)","weight"*(Cut_pt2 && Cut_met && Cut_pt1 && Cut_ptgg && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut && genmatch));
	TH1F *pt1_bkg5 =(TH1F*)gPad->GetPrimitive("pt1_bkg5");
	
	F5 = pt1_bkg5->Integral();    
	tree_bkg6->Draw("(pt1)>>pt1_bkg6(30,0,1000)","weight"*(Cut_pt2 && Cut_met && Cut_pt1 && Cut_ptgg && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut)); 
	TH1F *pt1_bkg6 =(TH1F*)gPad->GetPrimitive("pt1_bkg6");

	F6 = pt1_bkg6->Integral();  
	
	tree_bkg7->Draw("(pt1)>>pt1_bkg7(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut && minDPHIJetcut && nMuonCut && nEleCut ));                                             
	TH1F *pt1_bkg7 =(TH1F*)gPad->GetPrimitive("pt1_bkg7");
	F7 = pt1_bkg7->Integral();
	tree_bkg8->Draw("(pt1)>>pt1_bkg8(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut && minDPHIJetcut && nMuonCut && nEleCut ));                                            
	TH1F *pt1_bkg8 =(TH1F*)gPad->GetPrimitive("pt1_bkg8");
	F8 = pt1_bkg8->Integral();
	tree_bkg9->Draw("(pt1)>>pt1_bkg9(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut && minDPHIJetcut && nMuonCut && nEleCut ));                                             
	TH1F *pt1_bkg9 =(TH1F*)gPad->GetPrimitive("pt1_bkg9");
	F9 = pt1_bkg9->Integral();
	if(F9<0) F9=0;
	tree_bkg10->Draw("(pt1)>>pt1_bkg10(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut && nMuonCut && nEleCut ));                                           
	TH1F *pt1_bkg10 =(TH1F*)gPad->GetPrimitive("pt1_bkg10");
	F10 = pt1_bkg10->Integral();
	tree_bkg11->Draw("(pt1)>>pt1_bkg11(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut && minDPHIJetcut && nMuonCut && nEleCut ));                                       
	TH1F *pt1_bkg11 =(TH1F*)gPad->GetPrimitive("pt1_bkg11");
	F11 = pt1_bkg11->Integral();
	tree_bkg12->Draw("(pt1)>>pt1_bkg12(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut && nMuonCut && nEleCut ));                                           
	TH1F *pt1_bkg12 =(TH1F*)gPad->GetPrimitive("pt1_bkg12");
	F12 = pt1_bkg12->Integral();
	
      
      
	B = F1+F2+F3+F4+F5+F6+F7+F8+F9+F10+F11+F12;
	
	
	Eff = S/Stot_pt1;
	Sig3 = Eff/(1.5+sqrt(B));
	Sig5 = Eff/(2.5+sqrt(B));
	}
	hptggVSmet->Fill(cut_ptgg,cut_met,Sig5);
      }
  }


  /////////////////////////////////////////////////////////
Cut_met = Form("t1pfmet>%lf",cut_metIN);
Cut_pt1 = Form("pt1/mgg>%lf",cut_pt1IN);
  for(i = 0; i<NstepsPtgg;i++){
    cut_ptgg = firstCutPtgg + 5*i;
    Cut_ptgg = Form("ptgg>%lf",cut_ptgg);
    for(j = 0; j<NstepsPt2;j++){
	cut_pt2 = firstCutPt2 + 0.05*j+0.001;
	Cut_pt2 = Form("pt2/mgg>%lf",cut_pt2);
	tree_data->Draw("(pt1)>>pt1_data(30,0,1000)","(mgg<115||mgg>135)"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut && nMuonCut && nEleCut ));                                           
	TH1F *pt1_data =(TH1F*)gPad->GetPrimitive("pt1_data");
	N = pt1_data->GetEntries();
	Sig5= 0.;
	if(N>=0){
	tree_sig->Draw("(pt1)>>pt1_1(30,0,1000)","weight"*(Cut_pt2 && Cut_met && Cut_pt1 && Cut_ptgg && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut));
	TH1F *pt1_1 =(TH1F*)gPad->GetPrimitive("pt1_1"); 
	pt1_1->Scale(crossSec);   	
	S = pt1_1->Integral();   
	tree_bkg1->Draw("(pt1)>>pt1_bkg1(30,0,1000)","weight"*(Cut_pt2 && Cut_met && Cut_pt1 && Cut_ptgg && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut));
	TH1F *pt1_bkg1 =(TH1F*)gPad->GetPrimitive("pt1_bkg1");
	
	F1 = pt1_bkg1->Integral();   
	tree_bkg2->Draw("(pt1)>>pt1_bkg2(30,0,1000)","weight"*(Cut_pt2 && Cut_met && Cut_pt1 && Cut_ptgg && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut));
	TH1F *pt1_bkg2 =(TH1F*)gPad->GetPrimitive("pt1_bkg2");
	
	F2 = pt1_bkg2->Integral();
	if(F2<0) F2 = 0;     
	tree_bkg3->Draw("(pt1)>>pt1_bkg3(30,0,1000)","weight"*(Cut_pt2 && Cut_met && Cut_pt1 && Cut_ptgg && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut && genmatch));
	TH1F *pt1_bkg3 =(TH1F*)gPad->GetPrimitive("pt1_bkg3");

	F3 = pt1_bkg3->Integral();  
	tree_bkg4->Draw("(pt1)>>pt1_bkg4(30,0,1000)","weight"*(Cut_pt2 && Cut_met && Cut_pt1 && Cut_ptgg && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut));
	TH1F *pt1_bkg4 =(TH1F*)gPad->GetPrimitive("pt1_bkg4");
	
	F4 = pt1_bkg4->Integral();    
	tree_bkg5->Draw("(pt1)>>pt1_bkg5(30,0,1000)","weight"*(Cut_pt2 && Cut_met && Cut_pt1 && Cut_ptgg && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut && genmatch));
	TH1F *pt1_bkg5 =(TH1F*)gPad->GetPrimitive("pt1_bkg5");
	
	F5 = pt1_bkg5->Integral();    
	tree_bkg6->Draw("(pt1)>>pt1_bkg6(30,0,1000)","weight"*(Cut_pt2 && Cut_met && Cut_pt1 && Cut_ptgg && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut)); 
	TH1F *pt1_bkg6 =(TH1F*)gPad->GetPrimitive("pt1_bkg6");

	F6 = pt1_bkg6->Integral();  
	
	tree_bkg7->Draw("(pt1)>>pt1_bkg7(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut && minDPHIJetcut && nMuonCut && nEleCut ));                                             
	TH1F *pt1_bkg7 =(TH1F*)gPad->GetPrimitive("pt1_bkg7");
	F7 = pt1_bkg7->Integral();
	tree_bkg8->Draw("(pt1)>>pt1_bkg8(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut && minDPHIJetcut && nMuonCut && nEleCut ));                                            
	TH1F *pt1_bkg8 =(TH1F*)gPad->GetPrimitive("pt1_bkg8");
	F8 = pt1_bkg8->Integral();
	tree_bkg9->Draw("(pt1)>>pt1_bkg9(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut && minDPHIJetcut && nMuonCut && nEleCut ));                                             
	TH1F *pt1_bkg9 =(TH1F*)gPad->GetPrimitive("pt1_bkg9");
	F9 = pt1_bkg9->Integral();
	if(F9<0) F9=0;
	tree_bkg10->Draw("(pt1)>>pt1_bkg10(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut && nMuonCut && nEleCut ));                                           
	TH1F *pt1_bkg10 =(TH1F*)gPad->GetPrimitive("pt1_bkg10");
	F10 = pt1_bkg10->Integral();
	tree_bkg11->Draw("(pt1)>>pt1_bkg11(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut && minDPHIJetcut && nMuonCut && nEleCut ));                                       
	TH1F *pt1_bkg11 =(TH1F*)gPad->GetPrimitive("pt1_bkg11");
	F11 = pt1_bkg11->Integral();
	tree_bkg12->Draw("(pt1)>>pt1_bkg12(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut && nMuonCut && nEleCut ));                                           
	TH1F *pt1_bkg12 =(TH1F*)gPad->GetPrimitive("pt1_bkg12");
	F12 = pt1_bkg12->Integral();
	
      
      
	B = F1+F2+F3+F4+F5+F6+F7+F8+F9+F10+F11+F12;
	
	
	Eff = S/Stot_pt1;
	Sig3 = Eff/(1.5+sqrt(B));
	Sig5 = Eff/(2.5+sqrt(B));
	}
	hptggVSpt2->Fill(cut_ptgg,cut_pt2,Sig5);
      }
  }

  /////////////////////////////////////////////////////////
Cut_met = Form("t1pfmet>%lf",cut_metIN);
Cut_pt2 = Form("pt2/mgg>%lf",cut_pt2IN);
  for(i = 0; i<NstepsPtgg;i++){
    cut_ptgg = firstCutPtgg + 5*i;
    Cut_ptgg = Form("ptgg>%lf",cut_ptgg);
    for(j = 0; j<NstepsPt1;j++){
	cut_pt1 = firstCutPt1 + 0.05*j+0.001;
	Cut_pt1 = Form("pt1/mgg>%lf",cut_pt1);
	tree_data->Draw("(pt1)>>pt1_data(30,0,1000)","(mgg<115||mgg>135)"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut && nMuonCut && nEleCut ));                                           
	TH1F *pt1_data =(TH1F*)gPad->GetPrimitive("pt1_data");
	N = pt1_data->GetEntries();
	Sig5= 0.;
	if(N>=0){
	tree_sig->Draw("(pt1)>>pt1_1(30,0,1000)","weight"*(Cut_pt2 && Cut_met && Cut_pt1 && Cut_ptgg && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut));
	TH1F *pt1_1 =(TH1F*)gPad->GetPrimitive("pt1_1"); 
	pt1_1->Scale(crossSec);   	
	S = pt1_1->Integral();   
	tree_bkg1->Draw("(pt1)>>pt1_bkg1(30,0,1000)","weight"*(Cut_pt2 && Cut_met && Cut_pt1 && Cut_ptgg && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut));
	TH1F *pt1_bkg1 =(TH1F*)gPad->GetPrimitive("pt1_bkg1");
	
	F1 = pt1_bkg1->Integral();   
	tree_bkg2->Draw("(pt1)>>pt1_bkg2(30,0,1000)","weight"*(Cut_pt2 && Cut_met && Cut_pt1 && Cut_ptgg && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut));
	TH1F *pt1_bkg2 =(TH1F*)gPad->GetPrimitive("pt1_bkg2");
	
	F2 = pt1_bkg2->Integral();
	if(F2<0) F2 = 0;     
	tree_bkg3->Draw("(pt1)>>pt1_bkg3(30,0,1000)","weight"*(Cut_pt2 && Cut_met && Cut_pt1 && Cut_ptgg && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut && genmatch));
	TH1F *pt1_bkg3 =(TH1F*)gPad->GetPrimitive("pt1_bkg3");

	F3 = pt1_bkg3->Integral();  
	tree_bkg4->Draw("(pt1)>>pt1_bkg4(30,0,1000)","weight"*(Cut_pt2 && Cut_met && Cut_pt1 && Cut_ptgg && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut));
	TH1F *pt1_bkg4 =(TH1F*)gPad->GetPrimitive("pt1_bkg4");
	
	F4 = pt1_bkg4->Integral();    
	tree_bkg5->Draw("(pt1)>>pt1_bkg5(30,0,1000)","weight"*(Cut_pt2 && Cut_met && Cut_pt1 && Cut_ptgg && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut && genmatch));
	TH1F *pt1_bkg5 =(TH1F*)gPad->GetPrimitive("pt1_bkg5");
	
	F5 = pt1_bkg5->Integral();    
	tree_bkg6->Draw("(pt1)>>pt1_bkg6(30,0,1000)","weight"*(Cut_pt2 && Cut_met && Cut_pt1 && Cut_ptgg && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut &&nMuonCut &&nEleCut)); 
	TH1F *pt1_bkg6 =(TH1F*)gPad->GetPrimitive("pt1_bkg6");

	F6 = pt1_bkg6->Integral();  
	
	tree_bkg7->Draw("(pt1)>>pt1_bkg7(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut && minDPHIJetcut && nMuonCut && nEleCut ));                                             
	TH1F *pt1_bkg7 =(TH1F*)gPad->GetPrimitive("pt1_bkg7");
	F7 = pt1_bkg7->Integral();
	tree_bkg8->Draw("(pt1)>>pt1_bkg8(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut && minDPHIJetcut && nMuonCut && nEleCut ));                                            
	TH1F *pt1_bkg8 =(TH1F*)gPad->GetPrimitive("pt1_bkg8");
	F8 = pt1_bkg8->Integral();
	tree_bkg9->Draw("(pt1)>>pt1_bkg9(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut && minDPHIJetcut && nMuonCut && nEleCut ));                                             
	TH1F *pt1_bkg9 =(TH1F*)gPad->GetPrimitive("pt1_bkg9");
	F9 = pt1_bkg9->Integral();
	if(F9<0) F9=0;
	tree_bkg10->Draw("(pt1)>>pt1_bkg10(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut && nMuonCut && nEleCut ));                                           
	TH1F *pt1_bkg10 =(TH1F*)gPad->GetPrimitive("pt1_bkg10");
	F10 = pt1_bkg10->Integral();
	tree_bkg11->Draw("(pt1)>>pt1_bkg11(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut && minDPHIJetcut && nMuonCut && nEleCut ));                                       
	TH1F *pt1_bkg11 =(TH1F*)gPad->GetPrimitive("pt1_bkg11");
	F11 = pt1_bkg11->Integral();
	tree_bkg12->Draw("(pt1)>>pt1_bkg12(30,0,1000)","weight"*(Cut_pt1 && Cut_ptgg && Cut_pt2 && Cut_met && mggmin && mggmax && eveto && maxDPHIJetcut  && DPHIcut &&minDPHIJetcut && nMuonCut && nEleCut ));                                           
	TH1F *pt1_bkg12 =(TH1F*)gPad->GetPrimitive("pt1_bkg12");
	F12 = pt1_bkg12->Integral();
	
      
      
	B = F1+F2+F3+F4+F5+F6+F7+F8+F9+F10+F11+F12;
	
	
	Eff = S/Stot_pt1;
	Sig3 = Eff/(1.5+sqrt(B));
	Sig5 = Eff/(2.5+sqrt(B));
	}
	hpt1VSptgg->Fill(cut_pt1,cut_ptgg,Sig5);
      }
  }
  
   
  const Int_t NRGBs = 5;
  const Int_t NCont = 255;
  Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
  Double_t red[NRGBs]   = { 0.00, 0.00, 0.87, 1.00, 0.51 };
  Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 };
  Double_t blue[NRGBs]  = { 0.51, 1.00, 0.12, 0.00, 0.00 };
  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
  gStyle->SetNumberContours(NCont);
 
  int iPos=0; 

  TCanvas *fancycanvas1 = new TCanvas("fancycanvas1","",550,500);

  fancycanvas1->SetRightMargin(0.17);   
  hpt1VSpt2->GetXaxis()->SetTitle("p_{T1}/m_{#gamma#gamma}");  
  hpt1VSpt2->GetYaxis()->SetTitle("p_{T2}/m_{#gamma#gamma}");  
  hpt1VSpt2->GetZaxis()->SetTitle("Sign(5#sigma)");  

  hpt1VSpt2->GetZaxis()->SetTitleOffset(1.6);  
  hpt1VSpt2->GetYaxis()->SetTitleOffset(1.2);  
  hpt1VSpt2->Draw("colz");
  CMS_lumi( fancycanvas1,true,iPos,true );
  gStyle->SetOptStat(0); 

  
  TCanvas *fancycanvas2 = new TCanvas("fancycanvas2","",550,500);


  fancycanvas2->SetRightMargin(0.17);   
  hpt1VSmet->GetXaxis()->SetTitle("p_{T1}/m_{#gamma#gamma}");  
  hpt1VSmet->GetYaxis()->SetTitle("MET [GeV]");  
  hpt1VSmet->GetZaxis()->SetTitle("Sign(5#sigma)");  
  hpt1VSmet->GetZaxis()->SetTitleOffset(1.6);  
  hpt1VSmet->GetYaxis()->SetTitleOffset(1.2);  
  hpt1VSmet->Draw("colz");
  CMS_lumi( fancycanvas2,true,iPos,true );
  gStyle->SetOptStat(0);  
  
  
  TCanvas *fancycanvas3 = new TCanvas("fancycanvas3","",550,500); 


  fancycanvas3->SetRightMargin(0.17);   
  hmetVSpt2->GetXaxis()->SetTitle("MET [GeV]");  
  hmetVSpt2->GetYaxis()->SetTitle("p_{T2}/m_{#gamma#gamma}");  
  hmetVSpt2->GetZaxis()->SetTitle("Sign(5#sigma)");  

  hmetVSpt2->GetZaxis()->SetTitleOffset(1.6);  
  hmetVSpt2->GetYaxis()->SetTitleOffset(1.2);  
  hmetVSpt2->Draw("colz");
  CMS_lumi( fancycanvas3,true,iPos,true );

  gStyle->SetOptStat(0);  


 TCanvas *fancycanvas4 = new TCanvas("fancycanvas4","",550,500); 


  fancycanvas4->SetRightMargin(0.17);   
  hptggVSmet->GetXaxis()->SetTitle("p_{T#gamma#gamma} [GeV]");  
  hptggVSmet->GetYaxis()->SetTitle("MET [GeV]");  
  hptggVSmet->GetZaxis()->SetTitle("Sign(5#sigma)");  

  hptggVSmet->GetZaxis()->SetTitleOffset(1.6);  
  hptggVSmet->GetYaxis()->SetTitleOffset(1.2);  
  hptggVSmet->Draw("colz");
  CMS_lumi( fancycanvas4,true,iPos,true );

  gStyle->SetOptStat(0);  


 TCanvas *fancycanvas5 = new TCanvas("fancycanvas5","",550,500); 


  fancycanvas5->SetRightMargin(0.17);   
  hptggVSpt2->GetXaxis()->SetTitle("p_{T#gamma#gamma} [GeV]");  
  hptggVSpt2->GetYaxis()->SetTitle("p_{T2}/m_{#gamma#gamma}");  
  hptggVSpt2->GetZaxis()->SetTitle("Sign(5#sigma)");  

  hptggVSpt2->GetZaxis()->SetTitleOffset(1.6);  
  hptggVSpt2->GetYaxis()->SetTitleOffset(1.2);  
  hptggVSpt2->Draw("colz");
  CMS_lumi( fancycanvas5,true,iPos,true );

  gStyle->SetOptStat(0);  


 TCanvas *fancycanvas6 = new TCanvas("fancycanvas6","",550,500); 


  fancycanvas6->SetRightMargin(0.17);   
  hpt1VSptgg->GetXaxis()->SetTitle("p_{T1}/m_{#gamma#gamma}");  
  hpt1VSptgg->GetYaxis()->SetTitle("p_{T#gamma#gamma} [GeV]");  
  hpt1VSptgg->GetZaxis()->SetTitle("Sign(5#sigma)");  

  hpt1VSptgg->GetZaxis()->SetTitleOffset(1.6);  
  hpt1VSptgg->GetYaxis()->SetTitleOffset(1.2);  
  hpt1VSptgg->Draw("colz");
  CMS_lumi( fancycanvas6,true,iPos,true );

  gStyle->SetOptStat(0);  

  
  fancycanvas1->SaveAs(Form("./25ns_2246inv_v3/plots/cuts_MassDep/M%d_CutsPt1vsPt2_mass_DPHIandLepVeto_all4D.png",sigMass));
  fancycanvas2->SaveAs(Form("./25ns_2246inv_v3/plots/cuts_MassDep/M%d_CutsPt1vsMET_mass_DPHIandLepVeto_all4D.png",sigMass));
  fancycanvas3->SaveAs(Form("./25ns_2246inv_v3/plots/cuts_MassDep/M%d_CutsMETvsPt2_mass_DPHIandLepVeto_all4D.png",sigMass));
  fancycanvas4->SaveAs(Form("./25ns_2246inv_v3/plots/cuts_MassDep/M%d_CutsPtggvsMET_mass_DPHIandLepVeto_all4D.png",sigMass));
  fancycanvas5->SaveAs(Form("./25ns_2246inv_v3/plots/cuts_MassDep/M%d_CutsPtggvsPt2_mass_DPHIandLepVeto_all4D.png",sigMass));
  fancycanvas6->SaveAs(Form("./25ns_2246inv_v3/plots/cuts_MassDep/M%d_CutsPt1vsPtgg_mass_DPHIandLepVeto_all4D.png",sigMass));
  fancycanvas1->SaveAs(Form("./25ns_2246inv_v3/plots/cuts_MassDep/M%d_CutsPt1vsPt2_mass_DPHIandLepVeto_all4D.pdf",sigMass));
  fancycanvas2->SaveAs(Form("./25ns_2246inv_v3/plots/cuts_MassDep/M%d_CutsPt1vsMET_mass_DPHIandLepVeto_all4D.pdf",sigMass));
  fancycanvas3->SaveAs(Form("./25ns_2246inv_v3/plots/cuts_MassDep/M%d_CutsMETvspt2_mass_DPHIandLepVeto_all4D.pdf",sigMass));
  fancycanvas4->SaveAs(Form("./25ns_2246inv_v3/plots/cuts_MassDep/M%d_CutsPtggvsMET_mass_DPHIandLepVeto_all4D.pdf",sigMass));
  fancycanvas5->SaveAs(Form("./25ns_2246inv_v3/plots/cuts_MassDep/M%d_CutsPtggvsPt2_mass_DPHIandLepVeto_all4D.pdf",sigMass));
  fancycanvas6->SaveAs(Form("./25ns_2246inv_v3/plots/cuts_MassDep/M%d_CutsPt1vsPtgg_mass_DPHIandLepVeto_all4D.pdf",sigMass));
  


}
Example #23
0
void drawICmap(const string& wwwPath = "",
	       const string& eosPath = "", 
	       const string& dirName = "", 
	       const string& iterNumber = "", 
	       const string& tagName = "") {

  gStyle->SetPalette(1, 0);  // raibow palette                                                
  gStyle->SetNumberContours(50); // default is 20 

  string filename = "root://eoscms//eos/cms" + eosPath + dirName + "/" + iterNumber + "/" + tagName + "calibMap.root";

  TFile* f = TFile::Open(filename.c_str(),"READ");
  if (!f || !f->IsOpen()) {
    cout<<"*******************************"<<endl;
    cout<<"Error opening file \""<<filename<<"\".\nApplication will be terminated."<<endl;
    cout<<"*******************************"<<endl;
    exit(EXIT_FAILURE);
  }

  TH2F *mapEB = (TH2F*) f->Get("calibMap_EB");
  TH2F *h = NULL;
  h = (TH2F*) f->Get("calibMap_EEp");
  TH2F *mapEEp = (TH2F*) h->Clone();
  h = (TH2F*) f->Get("calibMap_EEm");
  TH2F *mapEEm = (TH2F*) h->Clone();

  if (!mapEB || !mapEEp || !mapEEm) {
    cout << "Error: could not get one or more histograms. End of programme" << endl;
    exit(EXIT_FAILURE);
  }

  TH2F *mapEB_new = new TH2F("mapEB_new","EB calib coefficients", 360, 0.5, 360.5, 171,-85.5,85.5 );

  // profile along ieta. ieta goea from -85 to 85, exluding 0, for a total of 170 non empty bins (they are 171 including ieta = 0 which is actually empty)
  // in the profile, ieta = 30 is the bin with x from 29.5 to 30.5
  // simila logic for profile along iphi
  TProfile * EB_ieta_profile = new TProfile("EB_ieta_profile","EB calib coefficients - i#eta profile",171,-85.5,85.5);
  TProfile * EB_iphi_profile = new TProfile("EB_iphi_profile","EB calib coefficients - i#phi profile",360,0.5,360.5);


  Int_t nbinsX = mapEB->GetNbinsX(); // ieta
  Int_t nbinsY = mapEB->GetNbinsY(); // iphi

  for (Int_t i = 1; i <= nbinsX; i++) {

      for (Int_t j = 1; j <= nbinsY; j++) {
	
	mapEB_new->Fill(j,(i-86.0),mapEB->GetBinContent(i,j));
	EB_ieta_profile->Fill((i-86.0),mapEB->GetBinContent(i,j));
	EB_iphi_profile->Fill(j,mapEB->GetBinContent(i,j));

      }

  }

  string wwwAllPath = wwwPath + dirName + "/" + iterNumber + "/2DMaps/";
  string name = "";
  TPaletteAxis *palette = NULL;

  //EB
  TCanvas *cEB = new TCanvas("cEB","IC map EB");
  mapEB_new->Draw("COLZ");
  mapEB_new->GetXaxis()->SetTitle("i #phi");
  mapEB_new->GetXaxis()->SetTitleSize(0.06);
  mapEB_new->GetXaxis()->SetTitleOffset(0.7);
  mapEB_new->GetYaxis()->SetTitle("i #eta");
  mapEB_new->GetYaxis()->SetTitleSize(0.06);
  mapEB_new->GetYaxis()->SetTitleOffset(0.8);
  mapEB_new->GetZaxis()->SetRangeUser(0.9,1.1);
  mapEB_new->SetStats(0);
  gPad->Update();
  palette = (TPaletteAxis*)mapEB_new->GetListOfFunctions()->FindObject("palette");
  // the following lines move the palette. Choose the values you need for the position.                                                                              
  palette->SetX1NDC(0.91);
  palette->SetX2NDC(0.94);
  gPad->Modified();
  gPad->Update();
  // end of palette fixes                                                                                                                                             
  name = wwwAllPath + "Barrel/IC_calibMapEB";
  cEB->SaveAs((name + ".pdf").c_str());
  cEB->SaveAs((name + ".png").c_str());

  TCanvas *cEB_ietaProfile = new TCanvas("cEB_ietaProfile","IC map EB - i#eta profile");
  EB_ieta_profile->Draw("HIST");
  EB_ieta_profile->GetXaxis()->SetTitle("i #eta");
  EB_ieta_profile->GetXaxis()->SetTitleSize(0.06);
  EB_ieta_profile->GetXaxis()->SetTitleOffset(0.7);
  EB_ieta_profile->GetYaxis()->SetTitle("IC");
  EB_ieta_profile->GetYaxis()->SetTitleSize(0.06);
  EB_ieta_profile->GetYaxis()->SetTitleOffset(0.8);
  // Double_t maxY = EB_ieta_profile->GetBinContent(EB_ieta_profile->GetMaximumBin());
  // Double_t scale_factor = 1.1;
  // Double_t minY = 999.9; // minimum would be 0, corresponding to ieta = 0; look for minimum excluding ieta = 0
  // for (Int_t ieta = -85; ieta<= 85; ieta++) {
  //   if (ieta == 0) continue;
  //   minY = (EB_ieta_profile->GetBinContent(ieta+86) < minY) ? EB_ieta_profile->GetBinContent(ieta+86) : minY;
  // }
  // Double_t offset = scale_factor * (maxY -minY); 
  // EB_ieta_profile->GetYaxis()->SetRangeUser(minY - offset, maxY + offset);
  EB_ieta_profile->GetYaxis()->SetRangeUser(0.89,0.99);
  EB_ieta_profile->SetStats(0);
  gPad->Update();
  name = wwwAllPath + "Barrel/IC_calibMapEB_ietaProfile";
  cEB_ietaProfile->SaveAs((name + ".pdf").c_str());
  cEB_ietaProfile->SaveAs((name + ".png").c_str());


  TCanvas *cEB_iphiProfile = new TCanvas("cEB_iphiProfile","IC map EB - i#phi profile");
  EB_iphi_profile->Draw("HIST");
  EB_iphi_profile->GetXaxis()->SetTitle("i #phi");
  EB_iphi_profile->GetXaxis()->SetTitleSize(0.06);
  EB_iphi_profile->GetXaxis()->SetTitleOffset(0.7);
  EB_iphi_profile->GetYaxis()->SetTitle("IC");
  EB_iphi_profile->GetYaxis()->SetTitleSize(0.06);
  EB_iphi_profile->GetYaxis()->SetTitleOffset(0.8);
  // maxY = EB_iphi_profile->GetBinContent(EB_iphi_profile->GetMaximumBin());
  // minY = EB_iphi_profile->GetBinContent(EB_iphi_profile->GetMinimumBin()); 
  // offset = scale_factor * (maxY -minY); 
  // EB_iphi_profile->GetYaxis()->SetRangeUser(minY - offset, maxY + offset);
  EB_iphi_profile->GetYaxis()->SetRangeUser(0.91,0.97);
  EB_iphi_profile->SetStats(0);
  gPad->Update();
  name = wwwAllPath + "Barrel/IC_calibMapEB_iphiProfile";
  cEB_iphiProfile->SaveAs((name + ".pdf").c_str());
  cEB_iphiProfile->SaveAs((name + ".png").c_str());


  //EE+
  TCanvas *cEEp = new TCanvas("cEEp","IC map EE+");
  mapEEp->Draw("COLZ");
  mapEEp->GetXaxis()->SetTitle("iX");
  mapEEp->GetXaxis()->SetTitleSize(0.06);
  mapEEp->GetXaxis()->SetTitleOffset(0.7);
  mapEEp->GetYaxis()->SetTitle("iY");
  mapEEp->GetYaxis()->SetTitleSize(0.06);
  mapEEp->GetYaxis()->SetTitleOffset(0.8);
  mapEEp->GetZaxis()->SetRangeUser(0.75,1.25);
  mapEEp->SetStats(0);
  gPad->Update();
  palette = (TPaletteAxis*)mapEEp->GetListOfFunctions()->FindObject("palette");
  // the following lines move the palette. Choose the values you need for the position.                    
  palette->SetX1NDC(0.91);
  palette->SetX2NDC(0.94);
  gPad->Modified();
  gPad->Update();
  // end of palette fixes                                    
  name = wwwAllPath + "Endcap/EEp/IC_calibMapEEp";
  cEEp->SaveAs((name + ".pdf").c_str());
  cEEp->SaveAs((name + ".png").c_str());

  //EE-
  TCanvas *cEEm = new TCanvas("cEEm","IC map EE-");
  mapEEm->Draw("COLZ");
  mapEEm->GetXaxis()->SetTitle("iX");
  mapEEm->GetXaxis()->SetTitleSize(0.06);
  mapEEm->GetXaxis()->SetTitleOffset(0.7);
  mapEEm->GetYaxis()->SetTitle("iY");
  mapEEm->GetYaxis()->SetTitleSize(0.06);
  mapEEm->GetYaxis()->SetTitleOffset(0.8);
  mapEEm->GetZaxis()->SetRangeUser(0.75,1.25);
  mapEEm->SetStats(0);
  gPad->Update();
  palette = (TPaletteAxis*)mapEEm->GetListOfFunctions()->FindObject("palette");
  // the following lines move the palette. Choose the values you need for the position.                    
  palette->SetX1NDC(0.91);
  palette->SetX2NDC(0.94);
  gPad->Modified();
  gPad->Update();
  // end of palette fixes                                    
  name = wwwAllPath + "Endcap/EEm/IC_calibMapEEm";
  cEEm->SaveAs((name + ".pdf").c_str());
  cEEm->SaveAs((name + ".png").c_str());

  


}
void display(){
  
  gROOT->ProcessLine(".x lhcbStyle.C");
  gStyle->SetPalette(1);
	
  string filename = "../analysed/SET9THL914.root";
	TFile* file = new TFile(filename.c_str(),"OPEN");

	int nBinsX=32; int nBinsY=32;
	int nPixelsX=64; int nPixelsY=64;
	
  std::cout<<"Making global intercept tot map"<<std::endl;
  // Global intercept map (not per pixel)
	TH2F* hToTMap = new TH2F("hToTMap","hToTMap",nBinsX,0,nPixelsX,nBinsY,0,nPixelsY);
	for(int x=0;x<nBinsX;x++){
		for(int y=0;y<nBinsY;y++){
			int id = x + y*nBinsX;
			// Get the ToT distribution for this location
			string histoname = "/tpanal/ClicpixAnalysis/hClusterTOTAssociated1pixMap"+makestring(id);
			TH1F* totMapHisto = 0;
			totMapHisto = (TH1F*)gDirectory->Get(histoname.c_str());
			if(totMapHisto == 0) continue;
			if(totMapHisto->GetEntries() < 20) continue;
	
			// Fit the tot distribution and enter the value in the ToT map
			totMapHisto->Fit("gaus","0q");
			TF1* fit = totMapHisto->GetFunction("gaus");
			hToTMap->Fill(x*floor(nPixelsX/nBinsX),y*floor(nPixelsY/nBinsY),fit->GetParameter(1));
			
			delete fit; delete totMapHisto;
		}
	}
	// Plot the map of ToT
	TCanvas* canv = new TCanvas();
	hToTMap->GetXaxis()->SetTitle("Column");
	hToTMap->GetYaxis()->SetTitle("Row");
  hToTMap->GetZaxis()->SetTitle("Mean charge (ToT)");
	hToTMap->SetMaximum(9);
	hToTMap->SetMinimum(5);
	hToTMap->DrawCopy("colz");

  
  std::cout<<"Making per pixel tot map"<<std::endl;
  // Per pixel map
  TH2F* hToTMapPerPixel = new TH2F("hToTMapPerPixel","hToTMapPerPixel",nPixelsX,0,nPixelsX,nPixelsY,0,nPixelsY);
  for(int x=0;x<nPixelsX;x++){
    for(int y=0;y<nPixelsY;y++){
      int id = x + y*nPixelsX;
      // Get the ToT distribution for this location
      string histoname = "/tpanal/ClicpixAnalysis/hClusterTOTAssociated1pixPixel"+makestring(id);
      TH1F* totMapHisto = 0;
      totMapHisto = (TH1F*)gDirectory->Get(histoname.c_str());
      if(totMapHisto == 0) continue;
      if(totMapHisto->GetEntries() < 10) continue;
      
      // Fit the tot distribution and enter the value in the ToT map
      totMapHisto->Fit("gaus","0q");
      TF1* fit = totMapHisto->GetFunction("gaus");
      hToTMapPerPixel->Fill(x,y,fit->GetParameter(1));
      
      delete fit; delete totMapHisto;
    }
  }
  // Plot the map of ToT
  TCanvas* canv2 = new TCanvas();
  hToTMapPerPixel->GetXaxis()->SetTitle("Column");
  hToTMapPerPixel->GetYaxis()->SetTitle("Row");
  hToTMapPerPixel->GetZaxis()->SetTitle("Mean charge (ToT)");
  hToTMapPerPixel->SetMaximum(10);
  hToTMapPerPixel->SetMinimum(0);
  hToTMapPerPixel->DrawCopy("colz");

  std::cout<<"Making pixel response tot maps"<<std::endl;
  // Pixel response maps
  int responseBins=100;
  double responseWidth=0.05;
  TH2F* hToTMapPixelResponseX = new TH2F("hToTMapPixelResponseX","hToTMapPixelResponseX",responseBins+1,-responseWidth,responseWidth,15,0,15);
  for(double rID=0;rID<responseBins;rID++){
    // Get the ToT distribution for this location
    string histoname = "/tpanal/ClicpixAnalysis/hClusterTOTAssociated1pixResponseX"+makestringD(rID);
    TH1F* totMapHisto = 0;
    totMapHisto = (TH1F*)gDirectory->Get(histoname.c_str());
    if(totMapHisto == 0) continue;
    if(totMapHisto->GetEntries() < 1) continue;
 		// loop over all tot bins
    for(int i=0;i<45;i++){
      hToTMapPixelResponseX->Fill(2.*responseWidth*(rID/100.)-responseWidth,i,totMapHisto->GetBinContent(totMapHisto->FindBin(i)));
    }
    delete totMapHisto;
  }
  // Plot the map of ToT
  TCanvas* canv3 = new TCanvas();
  hToTMapPixelResponseX->GetXaxis()->SetTitle("Track distance x (mm)");
  hToTMapPixelResponseX->GetYaxis()->SetTitle("ToT");
  hToTMapPixelResponseX->DrawCopy("colz");

  TH1F* hToTProfilePixelResponseY = new TH1F("hToTProfilePixelResponseY","hToTProfilePixelResponseY",responseBins+1,-responseWidth,responseWidth);
  TH2F* hToTMapPixelResponseY = new TH2F("hToTMapPixelResponseY","hToTMapPixelResponseY",responseBins+1,-responseWidth,responseWidth,16,0,16);
  for(double rID=0;rID<responseBins;rID++){
    // Get the ToT distribution for this location
    string histoname = "/tpanal/ClicpixAnalysis/hClusterTOTAssociated1pixResponseY"+makestringD(rID);
    TH1F* totMapHisto = 0;
    totMapHisto = (TH1F*)gDirectory->Get(histoname.c_str());
    if(totMapHisto == 0) continue;
    if(totMapHisto->GetEntries() < 1) continue;
    // loop over all tot bins
    for(int i=0;i<45;i++){
      hToTMapPixelResponseY->Fill(2.*responseWidth*(rID/100.)-responseWidth,i,totMapHisto->GetBinContent(totMapHisto->FindBin(i)));
    }
    hToTProfilePixelResponseY->Fill(2.*responseWidth*(rID/100.)-responseWidth+0.001,totMapHisto->GetXaxis()->GetBinCenter(totMapHisto->GetMaximumBin()));
    delete totMapHisto;
  }
  // Plot the map of ToT
  TCanvas* canv4 = new TCanvas();
  hToTMapPixelResponseY->GetXaxis()->SetTitle("Track distance y (mm)");
  hToTMapPixelResponseY->GetYaxis()->SetTitle("ToT");
  hToTMapPixelResponseY->GetZaxis()->SetTitle("Number of events");
  hToTMapPixelResponseY->DrawCopy("colz");
//  drawline(-0.03,1,7);
//  drawline(0.03,1,7);
	
  TCanvas* canv6 = new TCanvas();
  hToTProfilePixelResponseY->GetXaxis()->SetTitle("Track distance y (mm)");
  hToTProfilePixelResponseY->GetYaxis()->SetTitle("Most probable ToT");
  hToTProfilePixelResponseY->DrawCopy("");



  
  TCanvas* canv5 = new TCanvas();
  TH1F* sidebandLow = (TH1F*)gDirectory->Get("/tpanal/ClicpixAnalysis/hClusterTOTAssociated1pixResponseY20");
  TH1F* sidebandHigh = (TH1F*)gDirectory->Get("/tpanal/ClicpixAnalysis/hClusterTOTAssociated1pixResponseY80");
  sidebandHigh->GetXaxis()->SetTitle("ToT (single pixel)");
  sidebandHigh->GetXaxis()->SetRangeUser(0,20);
  sidebandHigh->DrawCopy("");
  sidebandLow->SetLineColor(2);
  sidebandLow->DrawCopy("same");

}
Example #25
0
void MakePlots(TString filename, TString energy="8TeV", TString lumi=""){
  TString outDir=filename; outDir.ReplaceAll("fitres","img");
  outDir="tmp/";
  //std::map<TString, TH2F *> deltaNLL_map;
  
  /*------------------------------ Plotto */
  TCanvas *c = new TCanvas("c","c");
  
  TFile f_in(filename, "read");
  if(f_in.IsZombie()){
    std::cerr << "File opening error: " << filename << std::endl;
    return;
  }
  
  TList *KeyList = f_in.GetListOfKeys();
  std::cout << KeyList->GetEntries() << std::endl;
  for(int i =0; i <  KeyList->GetEntries(); i++){
    c->Clear();
    TKey *key = (TKey *)KeyList->At(i);
    if(TString(key->GetClassName())!="RooDataSet") continue;
    RooDataSet *dataset = (RooDataSet *) key->ReadObj();
    
    TString constTermName = dataset->GetName();
    TString alphaName=constTermName; alphaName.ReplaceAll("constTerm","alpha");

    TTree *tree = dataset2tree(dataset);
    TGraphErrors bestFit_ = bestFit(tree, alphaName, constTermName);
    TH2F *hist = prof2d(tree, alphaName, constTermName, "nll", "(12,-0.0005,0.0115,29,-0.0025,0.1425)",true);

//     //    deltaNLL_map.insert(std::pair <TString, TH2F *>(keyName,hist));
    hist->SaveAs(outDir+"/deltaNLL-"+constTermName+".root");
    hist->Draw("colz");
    bestFit_.Draw("P same");
    bestFit_.SetMarkerSize(2);

    Int_t iBinX, iBinY;
    Double_t x,y;
    hist->GetBinWithContent2(0,iBinX,iBinY);
    x= hist->GetXaxis()->GetBinCenter(iBinX);
    y= hist->GetYaxis()->GetBinCenter(iBinY);
    TGraph nllBestFit(1,&x,&y);

    nllBestFit.SetMarkerStyle(3);
    nllBestFit.SetMarkerColor(kRed);
    TList* contour68 = contourFromTH2(hist, 0.68);

    hist->Draw("colz");
    hist->GetZaxis()->SetRangeUser(0,50);
    bestFit_.Draw("P same");
    nllBestFit.Draw("P same");
    //contour68->Draw("same");
    c->SaveAs(outDir+"/deltaNLL-"+constTermName+".png");
    hist->SaveAs("tmp/hist-"+constTermName+".root");
    nllBestFit.SaveAs("tmp/nllBestFit.root");
    contour68->SaveAs("tmp/contour68.root");
    delete hist;
    hist = prof2d(tree, alphaName, constTermName, "nll", "(12,-0.0005,0.0115,29,-0.0025,0.1425)");
    RooHistPdf *histPdf = nllToL(hist);
    delete hist;
    RooDataSet *gen_dataset=histPdf->generate(*histPdf->getVariables(),1000000,kTRUE,kFALSE);
    TTree *genTree = dataset2tree(gen_dataset);
    genTree->SaveAs("tmp/genTree-"+constTermName+".root");
    delete gen_dataset;
    delete histPdf;
    
    TGraphErrors toyGraph = g(genTree, constTermName);
    TGraphErrors bestFitGraph = g(tree,alphaName, constTermName);
    TGraphErrors bestFitScanGraph = g(y, x);
    delete genTree;
    delete tree;
    toyGraph.SetFillColor(kGreen);
    toyGraph.SetLineColor(kBlue);
    toyGraph.SetLineStyle(2);
    bestFitGraph.SetLineColor(kBlack);
    bestFitScanGraph.SetLineColor(kRed);
    bestFitScanGraph.SetLineWidth(2);


    
    TMultiGraph g_multi("multigraph","");
    g_multi.Add(&toyGraph,"L3");
    g_multi.Add(&toyGraph,"L");
    g_multi.Add(&bestFitGraph, "L");
    g_multi.Add(&bestFitScanGraph, "L");
   
    g_multi.Draw("A");

    c->Clear();
    g_multi.Draw("A");
    c->SaveAs(outDir+"/smearing_vs_energy-"+constTermName+".png");

    //    TPaveText *pv = new TPaveText(0.7,0.7,1, 0.8);    
//     TLegend *legend = new TLegend(0.7,0.8,0.95,0.92);
//     legend->SetFillStyle(3001);
//     legend->SetFillColor(1);
//     legend->SetTextFont(22); // 132
//     legend->SetTextSize(0.04); // l'ho preso mettendo i punti con l'editor e poi ho ricavato il valore con il metodo GetTextSize()
//   //  legend->SetFillColor(0); // colore di riempimento bianco
//     legend->SetMargin(0.4);  // percentuale della larghezza del simbolo
    //    SetLegendStyle(legend);
	
    //Plot(c, data,mc,mcSmeared,legend, region, filename, energy, lumi);
  }
  
  f_in.Close();
  
  return;
}
void readTimeConstants()
 {

 // read basic.dat file
 //  file has 5 coulumns of data
 //  but we want to read only first 4 collumns
 
 TString dir = gSystem->UnixPathName(gInterpreter->GetCurrentMacroName());
 dir.ReplaceAll("readTimeConstants.C","");
 dir.ReplaceAll("/./","/");
 ifstream in;
 //in.open(Form("%sbasic.dat",dir.Data()));
 in.open(Form("dumpConstants-0.dat",dir.Data()));

  int x;
  int y;
  int z;
 Float_t t, id;
 Int_t nlines = 0;

 TFile *f = new TFile("TimeCalibs.root","RECREATE");
 TH2F* calibMapEB = new TH2F("calibMapEB","Mean Time map EB [ns];i#phi;i#eta",360,1.,361.,171,-85,86);
 calibMapEB->Sumw2();
 TH2F* calibMapEEM = new TH2F("calibMapEEM","Mean Time map EE-; ix; iy",100,1,101,100,1,101);
 calibMapEEM->Sumw2();
 TH2F* calibMapEEP = new TH2F("calibMapEEP","Mean Time map EE+ ;ix;iy",100,1,101,100,1,101);
 calibMapEEP->Sumw2();

 //while (!in.eof()) {
 while (1) {
      in >> x >> y >> z >> t >> id ;
      if (!in.good()) break;
     // if (nlines < 5)  printf("x=%3i, y=%3i, z=%1i\n, t=%8f\n",x,y,z,t);continue;
      if(z == 0) { 
                     calibMapEB->Fill(y,x,t);
		     //printf("x=%3i, y=%3i, z=%1i\n, t=%8f\n",x,y,z,t);
		     }
      else{
          if( z < 1) { calibMapEEM->Fill(x,y, t);}
	  else{ calibMapEEP->Fill(x,y,t);}
	  }
      nlines++;

   }   


 printf(" found %d points\n",nlines);
 in.close();


//Move empty bins out of the way -- EB
  int nxbins = calibMapEB->GetNbinsX();
  int nybins = calibMapEB->GetNbinsY();
  for (int p=1;p<=nxbins;++p)
  {
    for (int q=1;q<=nybins;++q)
    {
      double binentsM = calibMapEB->GetBinContent(p,q);
      if(binentsM==0)
      {
        calibMapEB->SetBinContent(p,q,-1000);
      }
    }
  }

  //Move empty bins out of the way -- EE
  nxbins = calibMapEEM->GetNbinsX();
  nybins = calibMapEEM->GetNbinsY();
  for (int n=1;n<=nxbins;++n)
  {
    for (int m=1;m<=nybins;++m)
    {
      double binentsM = calibMapEEM->GetBinContent(n,m);
      if(binentsM==0)
      {
        calibMapEEM->SetBinContent(n,m,-1000);
      }
      double binentsP = calibMapEEP->GetBinContent(n,m);
      if(binentsP==0)
      {
        calibMapEEP->SetBinContent(n,m,-1000);
      }
    }
  }

int min = -10;

int max = 10;

calibMapEB->GetZaxis()->SetRangeUser(min, max); // ... set the range ...
calibMapEEM->GetZaxis()->SetRangeUser(min, max); // ... set the range ...
calibMapEEP->GetZaxis()->SetRangeUser(min, max); // ... set the range ...
 f->Write();

 }
void PlotChargeFieldFocus2D( const TString &sim, Int_t time, Int_t zoom=2, Int_t Nbins=2, const TString &options="") {
  
#ifdef __CINT__  
  gSystem->Load("libplasma.so");
#endif

  PlasmaGlob::Initialize();

  // Palettes!
  gROOT->Macro("PlasmaPalettes.C");

  // Init Units table
  PUnits::UnitsTable::Get();
  
  // Load PData
  PData *pData = PData::Get(sim.Data());
  pData->LoadFileNames(time);
  if(!pData->IsInit()) return;

  TString opt = options;
 
  // More makeup
  if(opt.Contains("grid")) {
    gStyle->SetPadGridX(1);
    gStyle->SetPadGridY(1);
  }
 
  gStyle->SetTitleFont(42);
  gStyle->SetStatFont(42);
  gStyle->SetTextFont(42);
  gStyle->SetTitleFont(42,"xyz");
  gStyle->SetLabelFont(42,"xyz");

  // Some plasma constants
  Double_t n0 = pData->GetPlasmaDensity();
  Double_t kp = pData->GetPlasmaK();
  Double_t skindepth = 1.;
  if(kp!=0.0) skindepth = 1/kp;
  Double_t E0 = pData->GetPlasmaE0();

  // Some beam properties:
  Float_t Ebeam = pData->GetBeamEnergy() * PUnits::MeV;
  Float_t gamma = Ebeam / PConst::ElectronMassE;
  Float_t vbeam = TMath::Sqrt(1 - 1/(gamma*gamma));
  // cout << Form(" - Bunch gamma      = %8.4f", gamma ) << endl;
  // cout << Form(" - Bunch velocity   = %8.4f c", vbeam ) << endl;
  Float_t nb = pData->GetBeamDensity();
  
  // Time in OU
  Float_t Time = pData->GetRealTime();
  // z start of the plasma in normalized units.
  Float_t zStartPlasma = pData->GetPlasmaStart()*kp;
  // z start of the beam in normalized units.
  Float_t zStartBeam = pData->GetBeamStart()*kp;
  // z start of the neutral in normalized units.
  Float_t zStartNeutral = pData->GetNeutralStart()*kp;
  // z end of the neutral in normalized units.
  Float_t zEndNeutral = pData->GetNeutralEnd()*kp;
  
  if(opt.Contains("center")) {
    Time -= zStartPlasma;
    if(opt.Contains("comov"))      // Centers on the head of the beam.
      Time += zStartBeam;
  }
  Float_t shiftz = pData->Shift(opt);
  //  cout << "Shift = " << shiftz << endl;
  
  // Calculate the "axis range" in number of bins. If Nbins==0 a RMS width is taken.
  Double_t rms0 = pData->GetBeamRmsY() * kp;
  if(pData->IsCyl())  rms0  = pData->GetBeamRmsR() * kp;
  
  Int_t FirstyBin = 0;
  Int_t LastyBin = 0;
  if(Nbins==0) { 
    Nbins =  TMath::Nint(rms0 / pData->GetDX(1));
  }
  
  // Slice width limits.
  if(!pData->IsCyl()) {
    FirstyBin = pData->GetNX(1)/2 + 1 - Nbins;
    LastyBin =  pData->GetNX(1)/2 + Nbins;
  } else {
    FirstyBin = 1; 
    LastyBin  = Nbins;
  }
  // -------------------------------------------------------------------------------

  // Get charge density histos
  Int_t Nspecies = pData->NSpecies();
  TH2F **hDen2D = new TH2F*[Nspecies];
  TH1F **hDen1D = new TH1F*[Nspecies];
  for(Int_t i=0;i<Nspecies;i++) {

    hDen2D[i] = NULL;
    hDen1D[i] = NULL;
    
    if(!pData->GetChargeFileName(i)) 
      continue;

    cout << Form(" Getting charge density of specie: ") << i << endl;

    
    char hName[24];
    sprintf(hName,"hDen2D_%i",i);
    hDen2D[i] = (TH2F*) gROOT->FindObject(hName);
    if(hDen2D[i]) delete hDen2D[i];

    if(!pData->Is3D())
      hDen2D[i] = pData->GetCharge(i,opt);
    else
      hDen2D[i] = pData->GetCharge2DSliceZY(i,-1,Nbins,opt+"avg");

    //  cout << Form(" Charge density of specie '%s' loaded into histogram '%s'",pData->GetSpeciesName(i).c_str(),hName) << endl;
    
    hDen2D[i]->SetName(hName);
    hDen2D[i]->GetXaxis()->CenterTitle();
    hDen2D[i]->GetYaxis()->CenterTitle();
    hDen2D[i]->GetZaxis()->CenterTitle();
    
    if(opt.Contains("comov"))
      hDen2D[i]->GetXaxis()->SetTitle("#zeta [c/#omega_{p}]");
    else
      hDen2D[i]->GetXaxis()->SetTitle("z [c/#omega_{p}]");
    
    if(pData->IsCyl()) 
      hDen2D[i]->GetYaxis()->SetTitle("r [c/#omega_{p}]");
    else
      hDen2D[i]->GetYaxis()->SetTitle("y [c/#omega_{p}]");

    hDen2D[i]->GetZaxis()->SetTitle("n [n_{0}]");
    
    if(!opt.Contains("1dline")) continue;
    
    sprintf(hName,"hDen1D_%i",i);
    hDen1D[i] = (TH1F*) gROOT->FindObject(hName);
    if(hDen1D[i]) delete hDen1D[i];
    
    if(pData->Is3D()) {
      hDen1D[i] = pData->GetH1SliceZ3D(pData->GetChargeFileName(i)->c_str(),"charge",-1,Nbins,-1,Nbins,opt+"avg");
    } else if(pData->IsCyl()) { // Cylindrical: The first bin with r>0 is actually the number 1 (not the 0).
      hDen1D[i] = pData->GetH1SliceZ(pData->GetChargeFileName(i)->c_str(),"charge",1,Nbins,opt+"avg");
    } else { // 2D cartesian
      hDen1D[i] = pData->GetH1SliceZ(pData->GetChargeFileName(i)->c_str(),"charge",-1,Nbins,opt+"avg");
    }
    
    //  cout << Form(" Charge density of specie '%s' loaded into histogram '%s'",pData->GetSpeciesName(i).c_str(),hName) << endl;
    
    hDen1D[i]->SetName(hName);
    hDen1D[i]->GetXaxis()->CenterTitle();
    hDen1D[i]->GetYaxis()->CenterTitle();
       
    if(opt.Contains("comov"))
      hDen1D[i]->GetXaxis()->SetTitle("#zeta [c/#omega_{p}]");
    else
      hDen1D[i]->GetXaxis()->SetTitle("z [c/#omega_{p}]");
    
    hDen1D[i]->GetYaxis()->SetTitle("n [n_{0}]");


  }
  
  // Get electric fields
  const Int_t Nfields = 3;
  TH2F **hE2D = new TH2F*[Nfields];
  TH1F **hE1D = new TH1F*[Nfields];
  for(Int_t i=0;i<Nfields;i++) {
    hE2D[i] = NULL;
    hE1D[i] = NULL;

    if(!pData->GetEfieldFileName(i))
      continue;

    cout << Form(" Getting electric field number ") << i+1 << endl;


    char hName[24];
    sprintf(hName,"hE2D_%i",i);
    hE2D[i] = (TH2F*) gROOT->FindObject(hName);
    if(hE2D[i]) delete hE2D[i];

    if(!pData->Is3D())
      hE2D[i] = pData->GetEField(i,opt);
    else
      hE2D[i] = pData->GetEField2DSliceZY(i,-1,Nbins,opt+"avg");
    
   
    hE2D[i]->SetName(hName);   
    hE2D[i]->GetXaxis()->CenterTitle();
    hE2D[i]->GetYaxis()->CenterTitle();
    hE2D[i]->GetZaxis()->CenterTitle();
    if(opt.Contains("comov"))
      hE2D[i]->GetXaxis()->SetTitle("#zeta [c/#omega_{p}]");
    else
      hE2D[i]->GetXaxis()->SetTitle("z [c/#omega_{p}]");
    
    if(pData->IsCyl()) 
      hE2D[i]->GetYaxis()->SetTitle("r [c/#omega_{p}]");
    else
      hE2D[i]->GetYaxis()->SetTitle("y [c/#omega_{p}]");
    
    if(i==0)
      hE2D[i]->GetZaxis()->SetTitle("E_{z} [E_{0}]");
    else if(i==1)
      hE2D[i]->GetZaxis()->SetTitle("E_{y} [E_{0}]");
    else if(i==2)
      hE2D[i]->GetZaxis()->SetTitle("E_{x} [E_{0}]");

    if(!opt.Contains("1dline")) continue;
     
    sprintf(hName,"hE1D_%i",i);
    hE1D[i] = (TH1F*) gROOT->FindObject(hName);
    if(hE1D[i]) delete hE1D[i];
    
    // 1D histograms
    char nam[3]; sprintf(nam,"e%i",i+1);
    if(pData->Is3D()) {
      
      if(i==0) 
	hE1D[i] = pData->GetH1SliceZ3D(pData->GetEfieldFileName(i)->c_str(),nam,-1,Nbins,-1,Nbins,opt+"avg");
      else  
	hE1D[i] = pData->GetH1SliceZ3D(pData->GetEfieldFileName(i)->c_str(),nam,-Nbins,Nbins,-Nbins,Nbins,opt+"avg");
      
    } else if(pData->IsCyl()) { // Cylindrical: The first bin with r>0 is actually the number 1 (not the 0).
      
      hE1D[i] = pData->GetH1SliceZ(pData->GetEfieldFileName(i)->c_str(),nam,1,Nbins,opt+"avg");
      
    } else { // 2D cartesian
      
      if(i==0) 
	hE1D[i] = pData->GetH1SliceZ(pData->GetEfieldFileName(i)->c_str(),nam,-1,Nbins,opt+"avg");
      else 
	hE1D[i] = pData->GetH1SliceZ(pData->GetEfieldFileName(i)->c_str(),nam,-Nbins,Nbins,opt+"avg");    
      
    }
    
    hE1D[i]->SetName(hName);
    if(opt.Contains("comov"))
      hE1D[i]->GetXaxis()->SetTitle("#zeta [c/#omega_{p}]");
    else
      hE1D[i]->GetXaxis()->SetTitle("z [c/#omega_{p}]");
    
    if(i==0)
      hE1D[i]->GetYaxis()->SetTitle("E_{z} [E_{0}]");
    else if(i==1)
      hE1D[i]->GetYaxis()->SetTitle("E_{y} [E_{0}]");
    else if(i==2)
      hE1D[i]->GetYaxis()->SetTitle("E_{x} [E_{0}]");
    
  }
  
  // Now, combine the electric field components into the total |E|
  // and calculate ionization probability for He:
  // Outter Helium electron
  Double_t Eion0 = 24.59 * PUnits::eV;
  Double_t Z     = 1;
  Double_t l     = 0;
  Double_t m     = 0;
  
  TH1F *hIonProb1D = NULL;
  if(opt.Contains("ionprob")) {
    hIonProb1D = (TH1F*) hE1D[0]->Clone("hIonProb1D");
    hIonProb1D->Reset();
    Int_t NbinsX = hE1D[0]->GetNbinsX();
    for(Int_t j=1;j<=NbinsX;j++) {
      Double_t E1 = hE1D[0]->GetBinContent(j);
      Double_t E2 = hE1D[1]->GetBinContent(j);
      Double_t E3 = hE1D[2]->GetBinContent(j);
      Double_t E  = TMath::Sqrt(E1*E1+E2*E2+E3*E3);
      
      E *= E0;
      
      Double_t IonProb = (PFunc::ADK(E,Eion0,Z,l,m)/PUnits::atomictime)*PUnits::femtosecond;
      hIonProb1D->SetBinContent(j,IonProb);
    }
    hIonProb1D->GetYaxis()->SetTitle("W_{ADK} [fs^{-1}]");
  }
  
  // Tunning the Histograms
  // ---------------------
  
  // Chaning to user units: 
  // --------------------------
  
  if(opt.Contains("units") && n0) {
    
    for(Int_t i=0;i<Nspecies;i++) {

      if(!hDen2D[i]) continue;

      Int_t NbinsX = hDen2D[i]->GetNbinsX();
      Float_t xMin = skindepth * hDen2D[i]->GetXaxis()->GetXmin() / PUnits::um;
      Float_t xMax = skindepth * hDen2D[i]->GetXaxis()->GetXmax() / PUnits::um;
      Int_t NbinsY = hDen2D[i]->GetNbinsY();
      Float_t yMin = skindepth * hDen2D[i]->GetYaxis()->GetXmin() / PUnits::um;
      Float_t yMax = skindepth * hDen2D[i]->GetYaxis()->GetXmax() / PUnits::um;
      hDen2D[i]->SetBins(NbinsX,xMin,xMax,NbinsY,yMin,yMax);
      // for(Int_t j=0;j<hDen2D[i]->GetNbinsX();j++) {
      // 	for(Int_t k=0;k<hDen2D[i]->GetNbinsY();k++) {
      // 	  hDen2D[i]->SetBinContent(j,k, hDen2D[i]->GetBinContent(j,k) * n0 / (1e15/PUnits::cm3) );
      // 	}
      // }

      if(pData->IsCyl())
	hDen2D[i]->GetYaxis()->SetTitle("r [#mum]");      
      else
	hDen2D[i]->GetYaxis()->SetTitle("y [#mum]");      

      if(opt.Contains("comov"))
	hDen2D[i]->GetXaxis()->SetTitle("#zeta [#mum]");
      else
	hDen2D[i]->GetXaxis()->SetTitle("z [#mum]");
      
      //      hDen2D[i]->GetZaxis()->SetTitle("n [10^{15}/cm^{3}]");
      
      if(!hDen1D[i]) continue;
      
      hDen1D[i]->SetBins(NbinsX,xMin,xMax);
      
      if(opt.Contains("comov"))
    	hDen1D[i]->GetXaxis()->SetTitle("#zeta [#mum]");
      else
    	hDen1D[i]->GetXaxis()->SetTitle("z [#mum]");
      
    }

    for(Int_t i=0;i<Nfields;i++) {
      Int_t NbinsX = hE2D[i]->GetNbinsX();
      Float_t xMin = skindepth * hE2D[i]->GetXaxis()->GetXmin() / PUnits::um;
      Float_t xMax = skindepth * hE2D[i]->GetXaxis()->GetXmax() / PUnits::um;
      Int_t NbinsY = hE2D[i]->GetNbinsY();
      Float_t yMin = skindepth * hE2D[i]->GetYaxis()->GetXmin() / PUnits::um;
      Float_t yMax = skindepth * hE2D[i]->GetYaxis()->GetXmax() / PUnits::um;
      hE2D[i]->SetBins(NbinsX,xMin,xMax,NbinsY,yMin,yMax);
      if(hE1D[i]) 
	hE1D[i]->SetBins(NbinsX,xMin,xMax);
	

      for(Int_t j=0;j<hE2D[i]->GetNbinsX();j++) {	
	for(Int_t k=0;k<hE2D[i]->GetNbinsY();k++) {
	  hE2D[i]->SetBinContent(j,k, hE2D[i]->GetBinContent(j,k) * ( E0 / (PUnits::GV/PUnits::m) ) );
	}
	
	if(!hE1D[i]) continue;
	hE1D[i]->SetBinContent(j, hE1D[i]->GetBinContent(j) * ( E0 / (PUnits::GV) ) );
	
      }
      
      if(pData->IsCyl())
	hE2D[i]->GetYaxis()->SetTitle("r [#mum]");      
      else
	hE2D[i]->GetYaxis()->SetTitle("y [#mum]");      
 
      if(opt.Contains("comov"))
	hE2D[i]->GetXaxis()->SetTitle("#zeta [#mum]");
      else
	hE2D[i]->GetXaxis()->SetTitle("z [#mum]");
      
      if(i==0)
	hE2D[i]->GetZaxis()->SetTitle("E_{z} [GV/m]");
      else if(i==1)
	hE2D[i]->GetZaxis()->SetTitle("E_{y} [GV/m]");
      else if(i==2)
	hE2D[i]->GetZaxis()->SetTitle("E_{x} [GV/m]");


      if(!hE1D[i]) continue;
      if(opt.Contains("comov"))
	hE1D[i]->GetXaxis()->SetTitle("#zeta [mm]");
      else
	hE1D[i]->GetXaxis()->SetTitle("z [mm]");
      
      if(i==0)
	hE1D[i]->GetYaxis()->SetTitle("E_{z} [GV/m]");
      else if(i==1)
	hE1D[i]->GetYaxis()->SetTitle("E_{y} [GV/m]");
      else if(i==2)
	hE1D[i]->GetYaxis()->SetTitle("E_{x} [GV/m]");
      
      
    }
    if(hIonProb1D) {
      Int_t NbinsX = hIonProb1D->GetNbinsX();
      Float_t xMin = skindepth * hIonProb1D->GetXaxis()->GetXmin() / PUnits::um;
      Float_t xMax = skindepth * hIonProb1D->GetXaxis()->GetXmax() / PUnits::um;
      hIonProb1D->SetBins(NbinsX,xMin,xMax);
    }
  }
  
  // --------------------------------------------------- Vertical Zoom ------------

  Float_t range    = (hDen2D[0]->GetYaxis()->GetXmax() - hDen2D[0]->GetYaxis()->GetXmin())/zoom;
  Float_t midPoint = (hDen2D[0]->GetYaxis()->GetXmax() + hDen2D[0]->GetYaxis()->GetXmin())/2.;
  Double_t ymin = midPoint-range/2;
  Double_t ymax = midPoint+range/2;
  if(pData->IsCyl()) {
    ymin = hDen2D[0]->GetYaxis()->GetXmin();
    ymax = range;
  }
  hDen2D[0]->GetYaxis()->SetRangeUser(ymin,ymax);
  hE2D[0]->GetYaxis()->SetRangeUser(ymin,ymax);
  hE2D[1]->GetYaxis()->SetRangeUser(ymin,ymax);
  
  // ------------- z Zoom --------------------------------- Plasma palette -----------
  // Set the range of the plasma charge density histogram for maximum constrast 
  // using a dynamic palette wich adjust the nominal value to a certain color.
  

  Float_t density = 1;
  // if(opt.Contains("units") && n0)
  //   density = n0 / (1e17/PUnits::cm3);
  Float_t Base  = density;
  Float_t BaseB =  TMath::Nint(100*(nb/n0))/100.0;

  Float_t gMax  = hDen2D[0]->GetMaximum();
  Float_t gMin  = (0.1001) * Base;
  if(BaseB<Base) gMin  = (0.1001) * BaseB;

  if(gMax<Base) gMax = 1.1*Base;

  Float_t *Max = new Float_t[Nspecies];
  Float_t *Min = new Float_t[Nspecies];

  for(Int_t i=0;i<Nspecies;i++) {
    if(!hDen2D[i]) continue;
   
    Max[i] = hDen2D[i]->GetMaximum();
    Min[i] = 0.01*Max[i];
    //   if(i==1) = Min[i] = 1.001E-4;
    if(i==2) Min[i] = 1.001E-3;
    if(Max[i]>gMax) gMax = Max[i];
    
    hDen2D[i]->GetZaxis()->SetRangeUser(Min[i],Max[i]);
  }
  
  hDen2D[0]->GetZaxis()->SetRangeUser(gMin,gMax); 
  
  // if(hDen2D[1]) {
  //   hDen2D[1]->GetZaxis()->SetRangeUser(gMin,Max[1]);
  // } 

  // if(Nspecies>=3) {
  //   if(hDen2D[2]) {
  //     hDen2D[2]->GetZaxis()->SetRangeUser(gMin,Max[2]);
  //   } 
  // }
  
  // Dynamic plasma palette
  const Int_t plasmaDNRGBs = 3;
  const Int_t plasmaDNCont = 128;
  Double_t basePos = 0.5;
  if(gMax!=gMin) {
    if(opt.Contains("logz")) {
      Float_t a = 1.0/(TMath::Log10(gMax)-TMath::Log10(gMin));
      Float_t b = TMath::Log10(gMin);
      basePos = a*(TMath::Log10(Base) - b);
      
    } else {
      basePos = (1.0/(gMax-gMin))*(Base - gMin);
    }
  }

  Double_t plasmaDStops[plasmaDNRGBs] = { 0.00, basePos, 1.00 };
  Double_t plasmaDRed[plasmaDNRGBs]   = { 0.99, 0.90, 0.00 };
  Double_t plasmaDGreen[plasmaDNRGBs] = { 0.99, 0.90, 0.00 };
  Double_t plasmaDBlue[plasmaDNRGBs]  = { 0.99, 0.90, 0.00 };
   
  PPalette * plasmaPalette = (PPalette*) gROOT->FindObject("plasma");
  plasmaPalette->CreateGradientColorTable(plasmaDNRGBs, plasmaDStops, 
					  plasmaDRed, plasmaDGreen, plasmaDBlue, plasmaDNCont);
  
  // Change the range of z axis for the fields to be symmetric.
  Float_t Emax = hE2D[0]->GetMaximum();
  Float_t Emin = hE2D[0]->GetMinimum();
  if(Emax > TMath::Abs(Emin))
    Emin = -Emax;
  else
    Emax = -Emin;
  hE2D[0]->GetZaxis()->SetRangeUser(Emin,Emax); 

  Emax = hE2D[1]->GetMaximum();
  Emin = hE2D[1]->GetMinimum();
  if(Emax > TMath::Abs(Emin))
    Emin = -Emax;
  else
    Emax = -Emin;
  hE2D[1]->GetZaxis()->SetRangeUser(Emin,Emax); 
    

  
  // "Axis range" in Osiris units:
  Double_t ylow  = hDen2D[1]->GetYaxis()->GetBinLowEdge(FirstyBin);
  Double_t yup = hDen2D[1]->GetYaxis()->GetBinUpEdge(LastyBin);
  Double_t xmin = hDen2D[1]->GetXaxis()->GetXmin();
  Double_t xmax = hDen2D[1]->GetXaxis()->GetXmax();

  TLine *lineYzero = new TLine(xmin,0.0,xmax,0.0);
  lineYzero->SetLineColor(kGray+2);
  lineYzero->SetLineStyle(2);

  TLine *lineYup = new TLine(xmin,yup,xmax,yup);
  lineYup->SetLineColor(kGray+1);
  lineYup->SetLineStyle(2);
 
  TLine *lineYdown = new TLine(xmin,ylow,xmax,ylow);
  lineYdown->SetLineColor(kGray+1);
  lineYdown->SetLineStyle(2);

  zStartPlasma -= shiftz; 
  zStartNeutral -= shiftz; 
  zEndNeutral -= shiftz; 
  
  if(opt.Contains("units")) {
    zStartPlasma *= skindepth / PUnits::um;
    zStartNeutral *= skindepth / PUnits::um;
    zEndNeutral *= skindepth / PUnits::um;
  }

  //  cout << "Start plasma = " << zStartPlasma << endl;
  TLine *lineStartPlasma = new TLine(zStartPlasma,ymin,zStartPlasma,ymax);
  lineStartPlasma->SetLineColor(kRed);
  lineStartPlasma->SetLineStyle(1);
  lineStartPlasma->SetLineWidth(2);

  //  cout << "Start plasma = " << zStartNeutral << endl;
  TLine *lineStartNeutral = new TLine(zStartNeutral,ymin,zStartNeutral,ymax);
  lineStartNeutral->SetLineColor(kGray+1);
  lineStartNeutral->SetLineStyle(1);
  lineStartNeutral->SetLineWidth(2);

  //  cout << "End plasma = " << zEndNeutral << endl;
  TLine *lineEndNeutral = new TLine(zEndNeutral,ymin,zEndNeutral,ymax);
  lineEndNeutral->SetLineColor(kGray+1);
  lineEndNeutral->SetLineStyle(2);
  lineEndNeutral->SetLineWidth(2);
  
  // Plotting
  // -----------------------------------------------

  // Canvas setup
  TCanvas *C;
  if(opt.Contains("hres") && !opt.Contains("pdf")) // high resolution for plain grahics output.
    C = new TCanvas("C","2D Charge density, Accelerating and focusing fields",1500,2000);
  else
    C = new TCanvas("C","2D Charge density, Accelerating and focusing fields",750,1000);
 
  // Palettes setup
  TExec *exPlasma = new TExec("exPlasma","plasmaPalette->cd();");
  TExec *exHot    = new TExec("exHot","hotPalette->cd();");
  TExec *exElec   = new TExec("exElec","electronPalette->cd();");
  TExec *exField  = new TExec("exField","rbow2Palette->cd();");
  
  // Text objects
  TPaveText *textTime = new TPaveText(0.7,0.83,0.85,0.90,"NDC");
  PlasmaGlob::SetPaveTextStyle(textTime,32); 
  char ctext[128];
  if(opt.Contains("units") && n0) 
    sprintf(ctext,"z = %5.1f #mum", Time * skindepth / PUnits::um);
  else
    sprintf(ctext,"t = %5.1f #omega_{p}^{-1}",Time);
  textTime->AddText(ctext);
  
  TPaveText *textDen = new TPaveText(0.13,0.83,0.38,0.90,"NDC");
  PlasmaGlob::SetPaveTextStyle(textDen,12); 
  textDen->SetTextColor(kOrange+10);
  if(opt.Contains("units") && n0)
    sprintf(ctext,"n_{0} = %5.2f x 10^{15} / cm^{3}", 1e-15 * n0 * PUnits::cm3);
  else if(pData->GetBeamDensity() && n0)
    sprintf(ctext,"n_{b}/n_{0} = %5.2f", pData->GetBeamDensity()/n0);
  textDen->AddText(ctext);
  
  TPaveText *textWav = new TPaveText(0.13,0.75,0.38,0.82,"NDC");
  PlasmaGlob::SetPaveTextStyle(textWav,12); 
  textWav->SetTextColor(kGray+2);
  sprintf(ctext,"#lambda_{p} = %5.3f mm", skindepth * TMath::TwoPi() / PUnits::um);
  textWav->AddText(ctext);
  
  
  // Actual Plotting!
  // ------------------------------------------------------------

  // Output file
  TString fOutName = Form("./%s/Plots/ChargeFieldFocus2D/ChargeFieldFocus2D",pData->GetPath().c_str());
  fOutName += Form("-%s_%i",pData->GetName(),time);


  // Setup Pad layout:
  Double_t lMargin = 0.10;
  Double_t rMargin = 0.12;
  Double_t bMargin = 0.10;
  Double_t tMargin = 0.02;
  Double_t vSpacing = 0.01; 
  Double_t hStep = (1.-lMargin-rMargin);
  Double_t vStep = (1.-bMargin-tMargin)/3.;
 
  TPad *pad[3];

  // top plots
  pad[0] = new TPad("padt", "padt",0.00, bMargin + 2.*vStep + vSpacing,
		    lMargin+hStep+rMargin, 1.00);
  pad[0]->SetLeftMargin(1./(lMargin+hStep)*lMargin);
  pad[0]->SetRightMargin(1./(rMargin+hStep)*rMargin);  
  pad[0]->SetBottomMargin(0.0);                                   
  pad[0]->SetTopMargin(1./(tMargin+vStep)*tMargin);
  pad[0]->Draw();

  // middle plots
  pad[1] = new TPad("padm", "padm",0.00, bMargin + vStep + vSpacing,
		    lMargin + hStep + rMargin, bMargin + 2.*vStep );
  pad[1]->SetLeftMargin(1./(lMargin+hStep)*lMargin);
  pad[1]->SetRightMargin((1./(rMargin+hStep)*rMargin));
  pad[1]->SetBottomMargin(0.0);                                   
  pad[1]->SetTopMargin(0.);
  pad[1]->Draw();          

  // bottom plots
  pad[2] = new TPad("padb", "padb",0.00, 0.,lMargin+hStep+rMargin,bMargin+vStep);
  pad[2]->SetLeftMargin(1./(lMargin+hStep)*lMargin);
  pad[2]->SetRightMargin((1./(rMargin+hStep)*rMargin));
  pad[2]->SetBottomMargin(1./(bMargin+vStep)*bMargin);
  pad[2]->SetTopMargin(0.);
  pad[2]->Draw();       
  
  // Draw!
  pad[0]->cd(); // <---------------------------------------------- Top Plot ---------
  if(opt.Contains("logz")) {
    pad[0]->SetLogz(1);
  } else {
    pad[0]->SetLogz(0);
  }
  pad[0]->SetFrameLineWidth(3);  

  TH2F *hFrame = (TH2F*) gROOT->FindObject("hFrame1");
  if(hFrame) delete hFrame;
  hFrame = (TH2F*) hDen2D[0]->Clone("hFrame1");
  hFrame->Reset();

  hFrame->GetXaxis()->SetLabelOffset(999);

  hFrame->GetYaxis()->SetTitleSize(0.075);
  hFrame->GetYaxis()->SetTitleOffset(0.65);
  hFrame->GetYaxis()->SetLabelSize(0.065);
  hFrame->GetYaxis()->SetLabelOffset(0.02);
  hFrame->GetYaxis()->SetTickLength(0.02);
 
  hFrame->GetZaxis()->SetTitleSize(0.06);                        
  hFrame->GetZaxis()->SetTitleOffset(0.45);
  hFrame->GetZaxis()->SetLabelSize(0.06);  
  hFrame->GetZaxis()->SetTickLength(0.02);
  //  hFrame->GetZaxis()->SetNdivisions(505);

  hFrame->Draw("col");            

  if(Nspecies>=3) {
    if(hDen2D[2]) {
      exHot->Draw();
      hDen2D[2]->Draw("colz same");
    }
  }

  exPlasma->Draw();
  hDen2D[0]->Draw("colz same");
  
  if(hDen2D[1]) {
    exElec->Draw();
    hDen2D[1]->Draw("colz same");
  }
  
  if(opt.Contains("1dline")) {
    lineYzero->Draw();
    lineYdown->Draw();
    lineYup->Draw();
  }

  if(zStartPlasma>xmin && zStartPlasma<xmax)
    lineStartPlasma->Draw();
  if(zStartNeutral>xmin && zStartNeutral<xmax)
    lineStartNeutral->Draw();
  if(zEndNeutral>xmin && zEndNeutral<xmax)
    lineEndNeutral->Draw();
  
  pad[0]->Update();
  TPaletteAxis *palette = NULL;
  for(Int_t i=0;i<Nspecies;i++) {
    
    if(!hDen2D[i]) continue;
    palette = (TPaletteAxis*) hDen2D[i]->GetListOfFunctions()->FindObject("palette");
    if(!palette) continue;

    Float_t y1 = gPad->GetBottomMargin();
    Float_t y2 = 1 - gPad->GetTopMargin();
    Float_t x1 = gPad->GetLeftMargin();
    Float_t x2 = 1 - gPad->GetRightMargin();
    palette->SetY2NDC( (i+1)*(y2-y1)/Nspecies + y1);
    palette->SetY1NDC( i*(y2-y1)/Nspecies + y1);
    palette->SetX1NDC(x2 + 0.005);
    palette->SetX2NDC(x2 + 0.03);
    palette->SetTitleOffset(0.65);
    palette->SetTitleSize(0.07);
    palette->SetLabelSize(0.065);
    palette->SetBorderSize(2);
    palette->SetLineColor(1);
  
  }


  // 1D charge density plots:
  Float_t yaxismin  =  pad[0]->GetUymin();
  Float_t yaxismax  =  pad[0]->GetUymin() + 0.33*(pad[0]->GetUymax() - pad[0]->GetUymin()) - 0.00;
  
  //  Float_t denmin = (0.1001) * density;
  Float_t denmin = gMin;
  Float_t denmax = gMax;
  if(opt.Contains("logz")) {
    denmin = TMath::Log10(denmin);
    denmax = TMath::Log10(denmax);
  }
  
  for(Int_t i=0;i<Nspecies;i++) {
    if(!hDen1D[i]) continue;
    
    Float_t slope = (yaxismax - yaxismin)/(denmax - denmin);
    
    for(Int_t j=0;j<hDen1D[i]->GetNbinsX();j++) {
      Float_t content = hDen1D[i]->GetBinContent(j+1);
      if(opt.Contains("logz")) content = TMath::Log10(content); 
      
      if(content<denmin) 
	hDen1D[i]->SetBinContent(j+1,yaxismin);
      else 
	hDen1D[i]->SetBinContent(j+1,(content - denmin) * slope + yaxismin);
    }    

    hDen1D[i]->SetLineWidth(2);
    if(i==1) {
      hDen1D[i]->SetLineColor(PlasmaGlob::elecLine);
      hDen1D[i]->Draw("same C");
    } else if (i==2) {
      hDen1D[i]->SetLineColor(kOrange+8);
      hDen1D[i]->Draw("same C");
    }
  }
    
  textTime->Draw();
  //  textDen->Draw();
  //  textWav->Draw();
  
  pad[0]->RedrawAxis(); 

 
  pad[1]->cd(); // <--------------------------------------------- Mid Plot
  pad[1]->SetFrameLineWidth(3);  
    
  TH2F *hFrame2 = (TH2F*) gROOT->FindObject("hFrame2");
  if(hFrame2) delete hFrame2;
  hFrame2 = (TH2F*) hE2D[0]->Clone("hFrame2");
  hFrame2->Reset();

  Float_t yFactor = pad[0]->GetAbsHNDC()/pad[1]->GetAbsHNDC(); 

  hFrame2->GetXaxis()->SetLabelOffset(999);

  hFrame2->GetYaxis()->SetTitleSize(0.075*yFactor);
  hFrame2->GetYaxis()->SetTitleOffset(0.65/yFactor);
  hFrame2->GetYaxis()->SetLabelSize(0.0650*yFactor);
  hFrame2->GetYaxis()->SetLabelOffset(0.02/yFactor);
  hFrame2->GetYaxis()->SetTickLength(0.02/yFactor);
  
  hE2D[0]->GetZaxis()->SetTitleSize(0.06*yFactor);                        
  hE2D[0]->GetZaxis()->SetTitleOffset(0.45/yFactor);
  hE2D[0]->GetZaxis()->SetLabelSize(0.06*yFactor);  
  hE2D[0]->GetZaxis()->SetTickLength(0.02/yFactor);
  // hFrame2->GetZaxis()->SetNdivisions(505);
  
  hFrame2->Draw("col");

  exField->Draw();
  hE2D[0]->Draw("colz same");

  if(opt.Contains("1dline")) {
    lineYzero->Draw();
    lineYdown->Draw();
    lineYup->Draw();
  }
  if(zStartPlasma>xmin && zStartPlasma<xmax)
    lineStartPlasma->Draw();
  if(zStartNeutral>xmin && zStartNeutral<xmax)
    lineStartNeutral->Draw();
  if(zEndNeutral>xmin && zEndNeutral<xmax)
    lineEndNeutral->Draw();
  
  pad[1]->Update();
  
  palette = (TPaletteAxis*) hE2D[0]->GetListOfFunctions()->FindObject("palette");
  
  Float_t y1 = pad[1]->GetBottomMargin();
  Float_t y2 = 1 - pad[1]->GetTopMargin();
  Float_t x2 = 1 - pad[1]->GetRightMargin();
  palette->SetY2NDC(y2 - 0.01);
  palette->SetY1NDC(y1 + 0.01);
  palette->SetX1NDC(x2 + 0.005);
  palette->SetX2NDC(x2 + 0.03);
  palette->SetTitleSize(0.07*yFactor);
  palette->SetTitleOffset(0.65/yFactor);
  palette->SetLabelSize(0.065*yFactor);
  palette->SetBorderSize(2);
  palette->SetLineColor(1);
  
  
  // 1D electric field plots:
  if(hE1D[0]) {
    // yaxismin  =  pad[1]->GetUymin() + 0.16666*(pad[1]->GetUymax() - pad[1]->GetUymin());
    // yaxismax  =  pad[1]->GetUymax() - 0.16666*(pad[1]->GetUymax() - pad[1]->GetUymin());
    Float_t yaxismin  =  pad[1]->GetUymin();
    Float_t yaxismax  =  pad[1]->GetUymax();
    
    Float_t emin = hE1D[0]->GetMinimum();
    Float_t emax = hE1D[0]->GetMaximum();
    
    //Float_t slope = (yaxismax - yaxismin)/(emax - emin);
    Float_t slope = yaxismin/emin;
    
    for(Int_t j=0;j<hE1D[0]->GetNbinsX();j++) {
      Float_t content = hE1D[0]->GetBinContent(j+1);
      hE1D[0]->SetBinContent(j+1,(content - emin) * slope + yaxismin);
  }    
    
    hE1D[0]->SetLineWidth(2);
    hE1D[0]->SetLineColor(PlasmaGlob::elecLine);
    // hE1D[0]->SetLineColor(kGray+2);
    hE1D[0]->Draw("same C");
  }

  // Plot ionization probability:
  if(hIonProb1D) {
    Float_t ionmin = 0;
    Float_t ionmax = hIonProb1D->GetMaximum();
    
    Float_t slope = yaxismax/ionmax;
    
    for(Int_t j=0;j<hIonProb1D->GetNbinsX();j++) {
      Float_t content = hIonProb1D->GetBinContent(j+1);
      hIonProb1D->SetBinContent(j+1,content * slope);
    }    
    
    hIonProb1D->SetLineWidth(2);
    hIonProb1D->SetLineColor(kGray+2);
    hIonProb1D->Draw("same C");
  }
  

  pad[1]->RedrawAxis(); 

  pad[2]->cd();  // <--------------------------------------------- Bottom Plot
  pad[2]->SetFrameLineWidth(3);  
  
  TH2F *hFrame3 = (TH2F*) gROOT->FindObject("hFrame3");
  if(hFrame3) delete hFrame3;
  hFrame3 = (TH2F*) hE2D[1]->Clone("hFrame3");
  hFrame3->Reset();

  yFactor = pad[0]->GetAbsHNDC()/pad[2]->GetAbsHNDC();
  
  hFrame3->GetXaxis()->SetTitleSize(0.075);
  hFrame3->GetXaxis()->SetLabelSize(0.070);

  hFrame3->GetYaxis()->SetTitleSize(0.075*yFactor);
  hFrame3->GetYaxis()->SetTitleOffset(0.65/yFactor);
  hFrame3->GetYaxis()->SetLabelSize(0.0650*yFactor);
  hFrame3->GetYaxis()->SetLabelOffset(0.02/yFactor);
  hFrame3->GetYaxis()->SetTickLength(0.02/yFactor);

  hE2D[1]->GetZaxis()->SetTitleSize(0.06*yFactor);                        
  hE2D[1]->GetZaxis()->SetTitleOffset(0.45/yFactor);
  hE2D[1]->GetZaxis()->SetLabelSize(0.06*yFactor);  
  hE2D[1]->GetZaxis()->SetTickLength(0.02/yFactor);
  // hE2D[1]->GetZaxis()->SetNdivisions(505);
  
  hFrame3->Draw("col");

  exField->Draw();
  hE2D[1]->Draw("colz same");

  if(opt.Contains("1dline")) {
    lineYzero->Draw();
    lineYup->Draw();
  }

  if(zStartPlasma>xmin && zStartPlasma<xmax)
    lineStartPlasma->Draw();
  if(zStartNeutral>xmin && zStartNeutral<xmax)
    lineStartNeutral->Draw();
  if(zEndNeutral>xmin && zEndNeutral<xmax)
    lineEndNeutral->Draw();

  pad[2]->Update();
  palette = (TPaletteAxis*)hE2D[1]->GetListOfFunctions()->FindObject("palette");
  
  y1 = pad[2]->GetBottomMargin();
  y2 = 1 - pad[2]->GetTopMargin();
  x2 = 1 - pad[2]->GetRightMargin();
  palette->SetY2NDC(y2 - 0.01);
  palette->SetY1NDC(y1 + 0.01);
  palette->SetX1NDC(x2 + 0.005);
  palette->SetX2NDC(x2 + 0.03);
  palette->SetTitleSize(0.07*yFactor);
  palette->SetTitleOffset(0.65/yFactor);
  palette->SetLabelSize(0.065*yFactor);
  palette->SetBorderSize(2);
  palette->SetLineColor(1);

  // 1D electric field plots:
  if(hE1D[1]) {
    // yaxismin  =  pad[2]->GetUymin() + 0.16666*(pad[2]->GetUymax() - pad[2]->GetUymin());
    // yaxismax  =  pad[2]->GetUymax() - 0.16666*(pad[2]->GetUymax() - pad[2]->GetUymin());
    Float_t yaxismin  =  pad[2]->GetUymin();
    Float_t yaxismax  =  pad[2]->GetUymax();
    
    Float_t emin = hE1D[1]->GetMinimum();
    Float_t emax = hE1D[1]->GetMaximum();
    
    Float_t slope = yaxismin/emin;
    
    for(Int_t j=0;j<hE1D[1]->GetNbinsX();j++) {
      Float_t content = hE1D[1]->GetBinContent(j+1);
      hE1D[1]->SetBinContent(j+1,(content - emin) * slope + yaxismin);
    }    
    
    hE1D[1]->SetLineWidth(2);
    //hE1D[1]->SetLineStyle(2);
    // hE1D[1]->SetLineColor(kGray+2);
    hE1D[1]->SetLineColor(PlasmaGlob::elecLine);
    hE1D[1]->Draw("same C");
  }

  // Plot ionization probability:
  if(hIonProb1D) {
    Float_t ionmin = 0;
    Float_t ionmax = hIonProb1D->GetMaximum();
    
    Float_t slope = yaxismax/ionmax;
    
    for(Int_t j=0;j<hIonProb1D->GetNbinsX();j++) {
      Float_t content = hIonProb1D->GetBinContent(j+1);
      hIonProb1D->SetBinContent(j+1,content * slope);
    }    
    
    hIonProb1D->SetLineWidth(2);
    hIonProb1D->SetLineColor(kGray+2);
    hIonProb1D->Draw("same C");
  }

   
  pad[2]->RedrawAxis(); 

  C->cd();

  // Print to a file
  PlasmaGlob::imgconv(C,fOutName,opt);
  // ---------------------------------------------------------

}
Example #28
0
void PlotEvolutionsWIII(const TString &sim, UInt_t mask = 3, const TString &options="png") { 
  
#ifdef __CINT__  
  gSystem->Load("libptools.so");
#endif

  string imask = DecToBin(mask);
  cout << Form("\n Plotting Evolultion with mask: %s",imask.c_str()) << endl; 

  PGlobals::Initialize();
  
  // Palettes!
  gROOT->Macro("PPalettes.C");

  TString opt = options;
  
  // More makeup            
  Float_t margins[4] = {0.15,0.15,0.20,0.10};
  gStyle->SetPadLeftMargin(margins[0]);  // Margin left axis  
  gStyle->SetPadRightMargin(margins[2]);
  gStyle->SetPadTopMargin(margins[3]);  // Margin left axis  
  gStyle->SetPadBottomMargin(margins[1]);

  gStyle->SetPadTickX(0);
  gStyle->SetPadTickY(0);


  if(opt.Contains("grid")) {
    gStyle->SetPadGridX(1);
    gStyle->SetPadGridY(1);
  }

  // Load first simulation data (for instance)
  PData *pData = PData::Get(sim.Data());
  Double_t E0 = pData->GetPlasmaE0();
  
  Float_t maxEcross = -999.;
  Float_t minEcross = 999.;
  Float_t maxEextr  = -999.;
  Float_t minEextr  = 999.;
  Float_t maxEdephas  = -999.;
  Float_t minEdephas  = 999.;
 
  const Int_t Nfields = 2; // E_z, E_x 
  TH2F   *hEvsTime[Nfields];
  Int_t NCross[Nfields];
  TGraph **gEcross[Nfields]; 
  TGraph **gEextr[Nfields]; 
  TGraph **gEdephas[Nfields]; 
  TGraph *gTRatio;

  TH2F   *hFvsTime;
  TGraph **gFcross = NULL;
  TGraph **gFextr = NULL;

  TH2F   *hETvsTime;
  TGraph **gETcross = NULL;
  TGraph **gETextr = NULL;

  TH2F   *hVvsTime;
  TGraph **gVcross = NULL;
  TGraph **gVextr = NULL;

  const Int_t NAtoms = 3;
  char atNames[NAtoms][4] = {"H","He","He2"};
  TH2F   *hIonProbvsTime[NAtoms]; // For H, He and He+. 
  TGraph *gIonProb10[NAtoms];
  TGraph *gIonProb100[NAtoms];
  Float_t IonTh[NAtoms] = {33.8,92.75,234.96} ;  // GV/m
  // if(!opt.Contains("units")) 
  //   for(Int_t i=0;i<NAtoms;i++) IonTh[i]  /= ( E0 / (PUnits::GV/PUnits::m));

  char hName[24];
  char gName[24];
  
  TString filename;
  filename = Form("./%s/Plots/Evolutions/Evolutions-%s.root",sim.Data(),sim.Data());
  
  TFile  *ifile = (TFile*) gROOT->GetListOfFiles()->FindObject(filename.Data());
  if (!ifile) ifile = new TFile(filename,"READ");

  TH2F *hDen1DvsTime = NULL;
  sprintf(hName,"hDenvsTime_1"); 
  hDen1DvsTime = (TH2F*) ifile->Get(hName);

  TH2F *hRmsvsTime = NULL;
  sprintf(hName,"hRmsvsTime_1"); 
  hRmsvsTime = (TH2F*) ifile->Get(hName);
    
  for(Int_t i=0;i<Nfields;i++) {
    
    sprintf(hName,"hEvsTime_%i",i); 
    hEvsTime[i] = (TH2F*) ifile->Get(hName);
    if(!hEvsTime[i]) continue;
    
    cout << Form("ANALYZING FIELD %i ...",i) << endl;

    Int_t NTBins = hEvsTime[i]->GetNbinsX();
    for(Int_t it=NTBins;it>0;it--) {
      
      // 1D field at certain timestep "it".
      TH1F *hE1D = (TH1F*) hEvsTime[i]->ProjectionY("_py",it,it);
      
      Int_t MAXCROSS = 2;
      Float_t *Cross = new Float_t[MAXCROSS];
      Float_t *Extr = new Float_t[MAXCROSS];
      memset(Cross,0,sizeof(Float_t)*MAXCROSS);
      memset(Extr,0,sizeof(Float_t)*MAXCROSS);

      Int_t auxNcross = PGlobals::HCrossings(hE1D,Cross,Extr,MAXCROSS,0.,0.);
      // cout << Form("  -> Number of crossings for histogram \"%s\" : %i ",hE1D->GetName(),auxNcross) << endl;
      // for(Int_t ic=0;ic<auxNcross;ic++) {
      // 	cout << Form(" %2i:  cross = %6.4f  extreme = %6.4f", ic, Cross[ic], Extr[ic]) << endl; 
      // }
      
      if(it==NTBins) {
	NCross[i] = auxNcross;
	
	gEcross[i] = new TGraph*[NCross[i]];
	gEextr[i] = new TGraph*[NCross[i]];

	for(Int_t ic = 0;ic<NCross[i];ic++) {
	  gEcross[i][ic] = new TGraph(NTBins);
	  sprintf(gName,"gEcross_%i_%i",i,ic); 
	  gEcross[i][ic]->SetName(gName);
	  
	  gEextr[i][ic] = new TGraph(NTBins);
	  sprintf(gName,"gEextr_%i_%i",i,ic); 
	  gEextr[i][ic]->SetName(gName);
	}

      }

      Float_t time = hEvsTime[i]->GetXaxis()->GetBinCenter(it);
      // cout << Form("Time step %i (%.2f): %i crossings",it,time,NCross[i]) << endl;
     
      for(Int_t ic=0;ic<NCross[i];ic++) {
	// cout << Form("  - Adding %i crossing: cross = %6.4f extreme = %6.4f",ic,Cross[ic],Extr[ic]) << endl;
	
	gEcross[i][ic]->SetPoint(it-1,time,Cross[ic]);
	gEextr[i][ic]->SetPoint(it-1,time,Extr[ic]);
      }
      
    }

    
    // Calculate the max and min of every crossing.
    // Also calculates dephasing:
    gEdephas[i] = new TGraph*[NCross[i]];
    for(Int_t ic = 0;ic<NCross[i];ic++) {

      Int_t Npoints = gEcross[i][ic]->GetN();
      Double_t *yEcross = gEcross[i][ic]->GetY();
      Double_t *yEextr  = gEextr[i][ic]->GetY();
      Double_t *xEextr  = gEextr[i][ic]->GetX();
      
      Double_t *yEdephas = new Double_t[Npoints];
      for(Int_t j=0;j<Npoints;j++) {
	yEdephas[j] = yEcross[j] - yEcross[0];
      }
      gEdephas[i][ic] = new TGraph(Npoints,xEextr,yEdephas);
      sprintf(gName,"gEdephas_%i_%i",i,ic); 
      gEdephas[i][ic]->SetName(gName);
      
      for(Int_t j=0;j<Npoints;j++) {
	if(yEcross[j]>maxEcross)
	  maxEcross = yEcross[j];
	if(yEcross[j]<minEcross)
	  minEcross = yEcross[j];
	
	if(yEextr[j]>maxEextr)
	  maxEextr = yEextr[j];
	if(yEextr[j]<minEextr)
	  minEextr = yEextr[j];
      
	// Only takes into account the minimums of the accelerating field:
	if(ic%2 || i!=0) continue;
	if(yEdephas[j]>maxEdephas)
	  maxEdephas = yEdephas[j];
	if(yEdephas[j]<minEdephas)
	  minEdephas = yEdephas[j];
	
      }
    
    }
  }

  // Transformer ratio vs time:
  // Take the ratio of the minimum over the maximum of the first oscillation of the Ez.
  {
    Int_t Npoints = gEextr[0][1]->GetN();
    Double_t *TR = new Double_t[Npoints];
    Double_t *yExtrPrev = gEextr[0][0]->GetY();
    Double_t *yExtr = gEextr[0][1]->GetY();
    Double_t *xExtr = gEextr[0][1]->GetX();
    for(Int_t j=0;j<Npoints;j++) {
      TR[j] = TMath::Abs(yExtr[j]/yExtrPrev[j]);	
    }
    
    gTRatio = new TGraph(Npoints,xExtr,TR);
    sprintf(gName,"gTRatio"); 
    gTRatio->SetName(gName);
  }
  

  sprintf(hName,"hVvsTime"); 
  hVvsTime = (TH2F*) ifile->Get(hName);
  Int_t NVCross = 0;
  cout << Form("ANALYZING POTENTIAL") << endl;

  Int_t NTBins = hVvsTime->GetNbinsX();
  for(Int_t it=NTBins;it>0;it--) {
      
    // 1D field at certain timestep "it".
    TH1F *hV1D = (TH1F*) hVvsTime->ProjectionY("_py",it,it);
      
    Int_t MAXCROSS = 2;
    Float_t *Cross = new Float_t[MAXCROSS];
    Float_t *Extr = new Float_t[MAXCROSS];
    memset(Cross,0,sizeof(Float_t)*MAXCROSS);
    memset(Extr,0,sizeof(Float_t)*MAXCROSS);
    
    Int_t auxNcross = PGlobals::HCrossings(hV1D,Cross,Extr,MAXCROSS,0.,20.);
    // cout << Form("  -> Number of crossings for histogram \"%s\" : %i ",hV1D->GetName(),auxNcross) << endl;
    // for(Int_t ic=0;ic<auxNcross;ic++) {
    // 	cout << Form(" %2i:  cross = %6.4f  extreme = %6.4f", ic, Cross[ic], Extr[ic]) << endl; 
    // }
    
    if(it==NTBins) {
      NVCross = auxNcross;
	
      gVcross = new TGraph*[NVCross];
      gVextr = new TGraph*[NVCross];

      for(Int_t ic = 0;ic<NVCross;ic++) {
	gVcross[ic] = new TGraph(NTBins);
	sprintf(gName,"gVcross_%i",ic); 
	gVcross[ic]->SetName(gName);
	  
	gVextr[ic] = new TGraph(NTBins);
	sprintf(gName,"gVextr_%i",ic); 
	gVextr[ic]->SetName(gName);
      }

    }

    Float_t time = hVvsTime->GetXaxis()->GetBinCenter(it);
    // cout << Form("Time step %i (%.2f): %i crossings",it,time,NVCross) << endl;
     
    for(Int_t ic=0;ic<NVCross;ic++) {
      // cout << Form("  - Adding %i crossing: cross = %6.4f extreme = %6.4f",ic,Cross[ic],Extr[ic]) << endl;
	
      gVcross[ic]->SetPoint(it-1,time,Cross[ic]);
      gVextr[ic]->SetPoint(it-1,time,Extr[ic]);
    }
      
  }


  sprintf(hName,"hETotalvsTime"); 
  hETvsTime = (TH2F*) ifile->Get(hName);
  Int_t NETCross = 0;
  cout << Form("ANALYZING TOTAL ELECTRIC FIELD") << endl;

  NTBins = hETvsTime->GetNbinsX();
  for(Int_t it=NTBins;it>0;it--) {
      
    // 1D field at certain timestep "it".
    TH1F *hET1D = (TH1F*) hETvsTime->ProjectionY("_py",it,it);
      
    Int_t MAXCROSS = 2;
    Float_t *Cross = new Float_t[MAXCROSS];
    Float_t *Extr = new Float_t[MAXCROSS];
    memset(Cross,0,sizeof(Float_t)*MAXCROSS);
    memset(Extr,0,sizeof(Float_t)*MAXCROSS);

    Float_t baseline = 0.5;
    if(opt.Contains("units"))
      baseline *= E0 / (PUnits::GV/PUnits::m);
    
    Int_t auxNcross = PGlobals::HCrossings(hET1D,Cross,Extr,MAXCROSS,baseline,-999,-999,"cum");
    // cout << Form("  -> Number of crossings for histogram \"%s\" : %i ",hET1D->GetName(),auxNcross) << endl;
    // for(Int_t ic=0;ic<auxNcross;ic++) {
    // 	cout << Form(" %2i:  cross = %6.4f  extreme = %6.4f", ic, Cross[ic], Extr[ic]) << endl; 
    // }
    
    if(it==NTBins) {
      NETCross = auxNcross;
	
      gETcross = new TGraph*[NETCross];
      gETextr = new TGraph*[NETCross];

      for(Int_t ic = 0;ic<NETCross;ic++) {
	gETcross[ic] = new TGraph(NTBins);
	sprintf(gName,"gETcross_%i",ic); 
	gETcross[ic]->SetName(gName);
	  
	gETextr[ic] = new TGraph(NTBins);
	sprintf(gName,"gETextr_%i",ic); 
	gETextr[ic]->SetName(gName);
      }

    }

    Float_t time = hETvsTime->GetXaxis()->GetBinCenter(it);
    // if(it==1)
    //   cout << Form("Time step %i (%.2f): %i crossings",it,time,NETCross) << endl;
     
    for(Int_t ic=0;ic<NETCross;ic++) {
      //if(it==1)
      //	cout << Form("  - Adding %i crossing: cross = %6.4f extreme = %6.4f",ic,Cross[ic],Extr[ic]) << endl;
	
      gETcross[ic]->SetPoint(it-1,time,Cross[ic]);
      gETextr[ic]->SetPoint(it-1,time,Extr[ic]);
      

    }
    
  }

  sprintf(hName,"hFocusvsTime"); 
  hFvsTime = (TH2F*) ifile->Get(hName);
  Int_t NFCross = 0;
  cout << Form("ANALYZING FOCUSING") << endl;

  NTBins = hFvsTime->GetNbinsX();
  for(Int_t it=NTBins;it>0;it--) {
      
    // 1D field at certain timestep "it".
    TH1F *hF1D = (TH1F*) hFvsTime->ProjectionY("_py",it,it);
      
    Int_t MAXCROSS = 2;
    Float_t *Cross = new Float_t[MAXCROSS];
    Float_t *Extr = new Float_t[MAXCROSS];
    memset(Cross,0,sizeof(Float_t)*MAXCROSS);
    memset(Extr,0,sizeof(Float_t)*MAXCROSS);

    Int_t auxNcross = PGlobals::HCrossings(hF1D,Cross,Extr,MAXCROSS,0.,0.);
    // cout << Form("  -> Number of crossings for histogram \"%s\" : %i ",hF1D->GetName(),auxNcross) << endl;
    // for(Int_t ic=0;ic<auxNcross;ic++) {
    // 	cout << Form(" %2i:  cross = %6.4f  extreme = %6.4f", ic, Cross[ic], Extr[ic]) << endl; 
    // }
    
    if(it==NTBins) {
      NFCross = auxNcross;
	
      gFcross = new TGraph*[NFCross];
      gFextr = new TGraph*[NFCross];

      for(Int_t ic = 0;ic<NFCross;ic++) {
	gFcross[ic] = new TGraph(NTBins);
	sprintf(gName,"gFcross_%i",ic); 
	gFcross[ic]->SetName(gName);
	  
	gFextr[ic] = new TGraph(NTBins);
	sprintf(gName,"gFextr_%i",ic); 
	gFextr[ic]->SetName(gName);
      }

    }

    Float_t time = hFvsTime->GetXaxis()->GetBinCenter(it);
    // cout << Form("Time step %i (%.2f): %i crossings",it,time,NFCross) << endl;
     
    for(Int_t ic=0;ic<NFCross;ic++) {
      // cout << Form("  - Adding %i crossing: cross = %6.4f extreme = %6.4f",ic,Cross[ic],Extr[ic]) << endl;
	
      gFcross[ic]->SetPoint(it-1,time,Cross[ic]);
      gFextr[ic]->SetPoint(it-1,time,Extr[ic]);
      

    }
    
  }
  

  for(Int_t i=0;i<NAtoms;i++) {
    sprintf(hName,"hIonProbvsTime_%s",atNames[i]); 
    hIonProbvsTime[i] = (TH2F*) ifile->Get(hName);
    if(!hIonProbvsTime[i]) continue;
    
    cout << Form("ANALYZING Ionization probability %i ...",i) << endl;

    Int_t NTBins = hIonProbvsTime[i]->GetNbinsX();
    for(Int_t it=NTBins;it>0;it--) {
      
      // 1D field at certain timestep "it".
      TH1F *hIonProb1D = (TH1F*) hIonProbvsTime[i]->ProjectionY("_py",it,it);
      
      Int_t MAXCROSS = 2;
      Float_t *Cross = new Float_t[MAXCROSS];
      Float_t *Extr = new Float_t[MAXCROSS];
      memset(Cross,0,sizeof(Float_t)*MAXCROSS);
      memset(Extr,0,sizeof(Float_t)*MAXCROSS);
      
      Int_t auxNcross = PGlobals::HCrossings(hIonProb1D,Cross,Extr,MAXCROSS,10.0);

      if(it==NTBins) {
	gIonProb10[i] = new TGraph(NTBins);
	sprintf(gName,"gIonProb10_%i",i); 
	gIonProb10[i]->SetName(gName);
      }

      Float_t time = hIonProbvsTime[i]->GetXaxis()->GetBinCenter(it);
      gIonProb10[i]->SetPoint(it-1,time,Cross[0]);
     
      memset(Cross,0,sizeof(Float_t)*MAXCROSS);
      memset(Extr,0,sizeof(Float_t)*MAXCROSS);
      auxNcross = PGlobals::HCrossings(hIonProb1D,Cross,Extr,MAXCROSS,99.0);
      
      if(it==NTBins) {
	gIonProb100[i] = new TGraph(NTBins);
	sprintf(gName,"gIonProb100_%i",i); 
	gIonProb100[i]->SetName(gName);
      }
      
      gIonProb100[i]->SetPoint(it-1,time,Cross[0]);
    }
  }

  // Set the color of the different evolutions according to a palette
  // UInt_t np = 50;
  // PPalette * colorPalette = (PPalette*) gROOT->FindObject("colorPalette");
  // if(!colorPalette) {
  //   const UInt_t Number = 3;
  //   Double_t Red[Number] = { 1.00, 0.00, 0.00};
  //   Double_t Green[Number]  = { 0.00, 1.00, 0.00};
  //   Double_t Blue[Number]   = { 1.00, 0.00, 1.00};
  //   Double_t Length[Number] = { 0.00, 0.50, 1.00 };
  //   colorPalette = new PPalette("colorPalette");
  //   colorPalette->CreateGradientColorTable(Number,Length,Red,Green,Blue,np);
  // }
  
  // for(Int_t i=0;i<Nfields;i++) { 
  //   for(Int_t ic=0;ic<Ncross;ic++) {
  //     Float_t step = (np/Nosc);
  //     Int_t icolor = TMath::Nint( ((ic+1)/2) * step - 1 );
  //     gEextr[i][ic]->SetLineColor(colorPalette->GetColor(icolor));
  //     gEextr[i][ic]->SetLineWidth(2);
  //     gEdephas[i][ic]->SetLineColor(colorPalette->GetColor(icolor));
  //     gEdephas[i][ic]->SetLineWidth(2);
  //   }
  // }
  // --------------------------------------------------------------------------

  // Manual coloring:
  const Int_t NCOLORS = 5;
  //  Int_t colors[NCOLORS] = {kMagenta+2,kRed,kBlue,kYellow+2,kCyan+2};
  Int_t colors[NCOLORS] = {kGray+3,kGray+2,kGray+1,kGray};
  for(Int_t i=0;i<Nfields;i++) { 
    for(Int_t ic=0;ic<NCross[i];ic++) {

      if( !gEcross[i][ic] || !gEextr[i][ic] ) continue;
            
      Int_t index = ic/2;
      if(index>=NCOLORS) index = NCOLORS-1;
      gEcross[i][ic]->SetLineColor(colors[index]);
      gEextr[i][ic]->SetLineColor(colors[index]);
      gEextr[i][ic]->SetLineWidth(1);
      gEdephas[i][ic]->SetLineColor(colors[index]);
      gEdephas[i][ic]->SetLineWidth(1);

      // cout << "EEEOOO" << endl;
      // if(ic%2) { 
      // 	gEcross[i][ic]->SetLineStyle(2);
      // 	gEextr[i][ic]->SetLineStyle(2);
      // 	gEdephas[i][ic]->SetLineStyle(2);
      // } else {
      // 	gEcross[i][ic]->SetLineStyle(1);
      // 	gEextr[i][ic]->SetLineStyle(1);
      // 	gEdephas[i][ic]->SetLineStyle(1);
      // }
      
      
    }
  }


  for(Int_t ic = 0;ic<NFCross;ic++) {
    // Graph's attributes
    Int_t index = ic/2;
    if(index>=NCOLORS) index = NCOLORS-1;
    gFcross[ic]->SetLineColor(colors[index]);
    if(ic%2-1) { 
      gFcross[ic]->SetLineStyle(2);
      gFextr[ic]->SetLineStyle(2);
      
    } else {
      gFcross[ic]->SetLineStyle(1);
      gFextr[ic]->SetLineStyle(1);
    }
  }

  for(Int_t ic = 0;ic<NVCross;ic++) {
    // Graph's attributes
    Int_t index = ic/2;
    if(index>=NCOLORS) index = NCOLORS-1;
    gVcross[ic]->SetLineColor(colors[index]);
    gVcross[ic]->SetLineStyle(3);
    gVextr[ic]->SetLineStyle(1);
  }
  
  for(Int_t ic = 0;ic<NETCross;ic++) {
    // Graph's attributes
    Int_t index = ic/2;
    if(index>=NCOLORS) index = NCOLORS-1;
    gETcross[ic]->SetLineColor(colors[index]);
    if(ic%2-1) { 
      gETcross[ic]->SetLineStyle(2);
      gETextr[ic]->SetLineStyle(2);
      
    } else {
      gETcross[ic]->SetLineStyle(1);
      gETextr[ic]->SetLineStyle(1);
    }
  }
  
  for(Int_t i=0;i<NAtoms;i++) {
    gIonProb10[i]->SetLineStyle(2);
    gIonProb10[i]->SetLineColor(kGray+2);

    gIonProb100[i]->SetLineStyle(1);
    gIonProb100[i]->SetLineColor(kGray+2);
  }
  

  // Plotting
  // ------------------------------------------------------------
  
  // Canvas setup
  UInt_t NPad = BitCounter(mask);
  if(NPad==0) NPad = 1;
  Float_t ypadsize = 250;
  Float_t ymarginsize = 200;
  if(NPad==1) ypadsize = 300;
  Float_t ysize = ypadsize * NPad + ymarginsize; 
  Float_t boom = 1.2;
  if(opt.Contains("boom"))
    ysize *= boom;
  TCanvas *C = new TCanvas("C","Snapshot",1050,ysize);
  C->SetFillStyle(4000);

  UInt_t lineColor = kOrange+10;
  //UInt_t lineColor =  TColor::GetColor(196,30,78);
  
  // Setup Pad layout:
  TPad **pad = new TPad*[NPad];
  TH2F **hFrame = new TH2F*[NPad];
  Float_t bMargin = 0.12 * (950/ysize);
  Float_t tMargin = 0.04 * (950/ysize);
  Float_t lMargin = 0.14;
  Float_t rMargin = 0.18;
  Float_t mMargin = 0.015 * (950/ysize);
  Float_t pfactor = 1.0;
  if(opt.Contains("nomar"))
    bMargin = tMargin = lMargin = rMargin = mMargin = 0.0;
  if(NPad==1)
    PGlobals::CanvasPartition(C,NPad,lMargin,rMargin,bMargin,tMargin,mMargin);
  else
    PGlobals::CanvasAsymPartition(C,NPad,lMargin,rMargin,bMargin,tMargin,pfactor,mMargin);
 
  // Define the frames for plotting
  Int_t fonttype = 43;
  Int_t fontsize = 32;
  Int_t tfontsize = 38;
  Int_t txsize = tfontsize+6;
  Int_t lxsize = fontsize;
  Int_t tysize = tfontsize;
  Int_t lysize = fontsize-2;
  Int_t tzsize = tfontsize-4;
  Int_t lzsize = fontsize-2;
  Float_t txoffset = (250/ypadsize) * 2.4 / (950/ysize);
  Float_t lxoffset = 0.015;
  Float_t tyoffset = 1.2 / (950/ysize);
  Float_t lyoffset = 0.01;
  Float_t tzoffset = 1.4 / (950/ysize);
  Float_t lzoffset = 0.01;
  Float_t tylength = 0.015;
  Float_t txlength = 0.04;
  for(Int_t i=NPad-1;i>=0;i--) {
    char name[16];
    sprintf(name,"pad_%i",i);
    pad[i] = (TPad*) gROOT->FindObject(name);
    pad[i]->SetFrameLineWidth(2);  
    pad[i]->SetTickx(1);
    pad[i]->SetTicky(1);
    if(opt.Contains("trans"))
      pad[i]->SetFillStyle(4000);
    pad[i]->SetFrameFillStyle(4000);

    sprintf(name,"hFrame_%i",i);
    hFrame[i] = (TH2F*) gROOT->FindObject(name);
    if(hFrame[i]) delete hFrame[i];
    hFrame[i] = (TH2F*) hEvsTime[0]->Clone(name);
    hFrame[i]->Reset();
    
    Float_t xFactor = pad[NPad-1]->GetAbsWNDC()/pad[i]->GetAbsWNDC();
    Float_t yFactor = pad[NPad-1]->GetAbsHNDC()/pad[i]->GetAbsHNDC();

    // Format for y axis
    hFrame[i]->GetYaxis()->SetLabelFont(fonttype);
    hFrame[i]->GetYaxis()->SetLabelSize(lysize);
    hFrame[i]->GetYaxis()->SetLabelOffset(lyoffset);
    hFrame[i]->GetYaxis()->SetTitleFont(fonttype);
    hFrame[i]->GetYaxis()->SetTitleSize(tysize);
    hFrame[i]->GetYaxis()->SetTitleOffset(tyoffset);

    hFrame[i]->GetYaxis()->SetTickLength(xFactor*tylength/yFactor);

    // Format for x axis
    hFrame[i]->GetXaxis()->SetLabelFont(fonttype);
    hFrame[i]->GetXaxis()->SetLabelSize(lxsize);
    hFrame[i]->GetXaxis()->SetLabelOffset(lxoffset);
    hFrame[i]->GetXaxis()->SetTitleFont(fonttype);
    hFrame[i]->GetXaxis()->SetTitleSize(txsize);
    hFrame[i]->GetXaxis()->SetTitleOffset(txoffset);
    
    hFrame[i]->GetXaxis()->SetTickLength(yFactor*txlength/xFactor);      

    if(i>0) { // skip x axis labels except for the lowest one
      hFrame[i]->GetXaxis()->SetLabelSize(0.0);
      hFrame[i]->GetXaxis()->SetTitleSize(0.0);
    }

    if(opt.Contains("nomar")) {
      hFrame[i]->GetYaxis()->SetTickLength(0.0);
      hFrame[i]->GetXaxis()->SetTickLength(0.0);      
    }

    // Labels for the frames

  }

  // Access to color Palettes 
  TExec *exPlasma = new TExec("exPlasma","plasmaPalette->cd();");
  TExec *exElec   = new TExec("exElec","electron0Palette->cd();");
  TExec *exHot    = new TExec("exHot","hotPalette->cd();");
  TExec *exField  = new TExec("exField","rbowwhitePalette->cd();");
  TExec *exFieldT = new TExec("exFieldT","red0Palette->cd();");
  TExec *exIonP   = new TExec("exIonP","redelectron0Palette->cd();");
  TExec *exPot    = new TExec("exPot","rbowinvPalette->cd();");

  

  // Actual Plotting!
  // ------------------------------------------------------------

  C->cd(0);

  Float_t x1,x2,y1,y2;
  Float_t gap = 0.01;
  TPaletteAxis *palette = NULL;
  UInt_t ip = NPad-1;

  if(mask & 0x1) {

    pad[ip]->Draw();
    pad[ip]->cd(); 
    if(opt.Contains("logz")) {
      pad[ip]->SetLogz(1);
    } else {
      pad[ip]->SetLogz(0);
    }

    hFrame[ip]->Draw("col");

    //  hDen1DvsTime->GetZaxis()->SetNdivisions(503);
    hDen1DvsTime->GetZaxis()->SetTitleFont(fonttype);
    Float_t xFactor = pad[0]->GetAbsWNDC()/pad[ip]->GetAbsWNDC();
    Float_t yFactor = pad[0]->GetAbsHNDC()/pad[ip]->GetAbsHNDC();
    hDen1DvsTime->GetZaxis()->SetTickLength(xFactor*tylength/yFactor);
    
    exElec->Draw();
    hDen1DvsTime->Draw("colz same");

    pad[ip]->Update();
  
    y1 = pad[ip]->GetBottomMargin();
    y2 = 1 - pad[ip]->GetTopMargin();
    x1 = pad[ip]->GetLeftMargin();
    x2 = 1 - pad[ip]->GetRightMargin();
  
    palette = (TPaletteAxis*) hDen1DvsTime->GetListOfFunctions()->FindObject("palette");  
    if(palette) {
      palette->SetY2NDC(y2 - gap);
      palette->SetY1NDC(y1 + gap);
      palette->SetX1NDC(x2 + 0.005);
      palette->SetX2NDC(x2 + 0.03);
      palette->SetTitleOffset(tzoffset);
      palette->SetTitleSize(tzsize);
      palette->SetLabelFont(fonttype);
      palette->SetLabelSize(lzsize);
      palette->SetLabelOffset(lyoffset);
      palette->SetBorderSize(2);
      palette->SetLineColor(1);
    }
   
    pad[ip]->RedrawAxis(); 

    ip--;
    C->cd(0);
    
  }

  if(mask & 0x2) {

    pad[ip]->Draw();
    pad[ip]->cd(); 
    if(opt.Contains("logz")) {
      pad[ip]->SetLogz(1);
    } else {
      pad[ip]->SetLogz(0);
    }

    hFrame[ip]->Draw("col");

    //  hRmsvsTime->GetZaxis()->SetNdivisions(503);
    hRmsvsTime->GetZaxis()->SetTitleFont(fonttype);
    Float_t xFactor = pad[0]->GetAbsWNDC()/pad[ip]->GetAbsWNDC();
    Float_t yFactor = pad[0]->GetAbsHNDC()/pad[ip]->GetAbsHNDC();
    hRmsvsTime->GetZaxis()->SetTickLength(xFactor*tylength/yFactor);
    
    exElec->Draw();
    hRmsvsTime->Draw("colz same");

    pad[ip]->Update();
  
    y1 = pad[ip]->GetBottomMargin();
    y2 = 1 - pad[ip]->GetTopMargin();
    x1 = pad[ip]->GetLeftMargin();
    x2 = 1 - pad[ip]->GetRightMargin();
  
    palette = (TPaletteAxis*) hRmsvsTime->GetListOfFunctions()->FindObject("palette");  
    if(palette) {
      palette->SetY2NDC(y2 - gap);
      palette->SetY1NDC(y1 + gap);
      palette->SetX1NDC(x2 + 0.005);
      palette->SetX2NDC(x2 + 0.03);
      palette->SetTitleOffset(tzoffset);
      palette->SetTitleSize(tzsize);
      palette->SetLabelFont(fonttype);
      palette->SetLabelSize(lzsize);
      palette->SetLabelOffset(lyoffset);
      palette->SetBorderSize(2);
      palette->SetLineColor(1);
    }
   
    pad[ip]->RedrawAxis(); 

    ip--;
    C->cd(0);
    
  }

  if(mask & 0x4) {

    pad[ip]->Draw();
    pad[ip]->cd(); 
    if(opt.Contains("logz")) {
      pad[ip]->SetLogz(1);
    } else {
      pad[ip]->SetLogz(0);
    }

    hFrame[ip]->Draw("col");

    //  hEvsTime[0]->GetZaxis()->SetNdivisions(503);
    hEvsTime[0]->GetZaxis()->SetTitleFont(fonttype);
    Float_t xFactor = pad[0]->GetAbsWNDC()/pad[ip]->GetAbsWNDC();
    Float_t yFactor = pad[0]->GetAbsHNDC()/pad[ip]->GetAbsHNDC();
    hEvsTime[0]->GetZaxis()->SetTickLength(xFactor*tylength/yFactor);
    
    exField->Draw();
    hEvsTime[0]->Draw("colz same");

    pad[ip]->Update();
  
    y1 = pad[ip]->GetBottomMargin();
    y2 = 1 - pad[ip]->GetTopMargin();
    x1 = pad[ip]->GetLeftMargin();
    x2 = 1 - pad[ip]->GetRightMargin();
  
    palette = (TPaletteAxis*) hEvsTime[0]->GetListOfFunctions()->FindObject("palette");  
    if(palette) {
      palette->SetY2NDC(y2 - gap);
      palette->SetY1NDC(y1 + gap);
      palette->SetX1NDC(x2 + 0.005);
      palette->SetX2NDC(x2 + 0.03);
      palette->SetTitleOffset(tzoffset);
      palette->SetTitleSize(tzsize);
      palette->SetLabelFont(fonttype);
      palette->SetLabelSize(lzsize);
      palette->SetLabelOffset(lyoffset);
      palette->SetBorderSize(2);
      palette->SetLineColor(1);
    }

    if(!opt.Contains("nocross")) {
    
      for(Int_t ic=0;ic<NVCross;ic++) {
	if( gVcross[ic] )
	  gVcross[ic]->Draw("L");
      }

      if(gEcross[1][0]) {
	gEcross[1][0]->SetLineStyle(4);
	gEcross[1][0]->Draw("L");
      }
    }

    pad[ip]->RedrawAxis(); 

    ip--;
    C->cd(0);
    
  }

  if(mask & 0x8) {

    pad[ip]->Draw();
    pad[ip]->cd(); 
    if(opt.Contains("logz")) {
      pad[ip]->SetLogz(1);
    } else {
      pad[ip]->SetLogz(0);
    }

    hFrame[ip]->Draw("col");

    //  hEvsTime[1]->GetZaxis()->SetNdivisions(503);
    hEvsTime[1]->GetZaxis()->SetTitleFont(fonttype);
    Float_t xFactor = pad[0]->GetAbsWNDC()/pad[ip]->GetAbsWNDC();
    Float_t yFactor = pad[0]->GetAbsHNDC()/pad[ip]->GetAbsHNDC();
    hEvsTime[1]->GetZaxis()->SetTickLength(xFactor*tylength/yFactor);
    
    exField->Draw();
    hEvsTime[1]->Draw("colz same");

    pad[ip]->Update();
  
    y1 = pad[ip]->GetBottomMargin();
    y2 = 1 - pad[ip]->GetTopMargin();
    x1 = pad[ip]->GetLeftMargin();
    x2 = 1 - pad[ip]->GetRightMargin();
  
    palette = (TPaletteAxis*) hEvsTime[1]->GetListOfFunctions()->FindObject("palette");  
    if(palette) {
      palette->SetY2NDC(y2 - gap);
      palette->SetY1NDC(y1 + gap);
      palette->SetX1NDC(x2 + 0.005);
      palette->SetX2NDC(x2 + 0.03);
      palette->SetTitleOffset(tzoffset);
      palette->SetTitleSize(tzsize);
      palette->SetLabelFont(fonttype);
      palette->SetLabelSize(lzsize);
      palette->SetLabelOffset(lyoffset);
      palette->SetBorderSize(2);
      palette->SetLineColor(1);
    }
   
    pad[ip]->RedrawAxis(); 

    ip--;
    C->cd(0);
    
  }

  if(mask & 0x10) {

    pad[ip]->Draw();
    pad[ip]->cd(); 
    if(opt.Contains("logz")) {
      pad[ip]->SetLogz(1);
    } else {
      pad[ip]->SetLogz(0);
    }

    hFrame[ip]->Draw("col");

    //  hETvsTime->GetZaxis()->SetNdivisions(503);
    hETvsTime->GetZaxis()->SetTitleFont(fonttype);
    Float_t xFactor = pad[0]->GetAbsWNDC()/pad[ip]->GetAbsWNDC();
    Float_t yFactor = pad[0]->GetAbsHNDC()/pad[ip]->GetAbsHNDC();
    hETvsTime->GetZaxis()->SetTickLength(xFactor*tylength/yFactor);
    
    exFieldT->Draw();
    hETvsTime->Draw("colz same");

    pad[ip]->Update();
  
    y1 = pad[ip]->GetBottomMargin();
    y2 = 1 - pad[ip]->GetTopMargin();
    x1 = pad[ip]->GetLeftMargin();
    x2 = 1 - pad[ip]->GetRightMargin();
  
    palette = (TPaletteAxis*) hETvsTime->GetListOfFunctions()->FindObject("palette");  
    if(palette) {
      palette->SetY2NDC(y2 - gap);
      palette->SetY1NDC(y1 + gap);
      palette->SetX1NDC(x2 + 0.005);
      palette->SetX2NDC(x2 + 0.03);
      palette->SetTitleOffset(tzoffset);
      palette->SetTitleSize(tzsize);
      palette->SetLabelFont(fonttype);
      palette->SetLabelSize(lzsize);
      palette->SetLabelOffset(lyoffset);
      palette->SetBorderSize(2);
      palette->SetLineColor(1);
    }

    if(!opt.Contains("nocross")) {
    
      for(Int_t ic=0;ic<NVCross;ic++) {
	if( gVcross[ic] )
	  gVcross[ic]->Draw("L");
      }

      if(gEcross[1][0]) {
	gEcross[1][0]->SetLineStyle(4);
	gEcross[1][0]->Draw("L");
      }
    }
     
    pad[ip]->RedrawAxis(); 

    ip--;
    C->cd(0);
    
  }

  if(mask & 0x20) {

    pad[ip]->Draw();
    pad[ip]->cd(); 
    if(opt.Contains("logz")) {
      pad[ip]->SetLogz(1);
    } else {
      pad[ip]->SetLogz(0);
    }

    hFrame[ip]->Draw("col");

    //  hVvsTime->GetZaxis()->SetNdivisions(503);
    hVvsTime->GetZaxis()->SetTitleFont(fonttype);
    Float_t xFactor = pad[0]->GetAbsWNDC()/pad[ip]->GetAbsWNDC();
    Float_t yFactor = pad[0]->GetAbsHNDC()/pad[ip]->GetAbsHNDC();
    hVvsTime->GetZaxis()->SetTickLength(xFactor*tylength/yFactor);
    
    exPot->Draw();
    hVvsTime->Draw("colz same");

    pad[ip]->Update();
  
    y1 = pad[ip]->GetBottomMargin();
    y2 = 1 - pad[ip]->GetTopMargin();
    x1 = pad[ip]->GetLeftMargin();
    x2 = 1 - pad[ip]->GetRightMargin();
  
    palette = (TPaletteAxis*) hVvsTime->GetListOfFunctions()->FindObject("palette");  
    if(palette) {
      palette->SetY2NDC(y2 - gap);
      palette->SetY1NDC(y1 + gap);
      palette->SetX1NDC(x2 + 0.005);
      palette->SetX2NDC(x2 + 0.03);
      palette->SetTitleOffset(tzoffset);
      palette->SetTitleSize(tzsize);
      palette->SetLabelFont(fonttype);
      palette->SetLabelSize(lzsize);
      palette->SetLabelOffset(lyoffset);
      palette->SetBorderSize(2);
      palette->SetLineColor(1);
    }
   
    pad[ip]->RedrawAxis(); 

    ip--;
    C->cd(0);
    
  }
  

  if(mask & 0x40) {

    pad[ip]->Draw();
    pad[ip]->cd(); 
    if(opt.Contains("logz")) {
      pad[ip]->SetLogz(1);
    } else {
      pad[ip]->SetLogz(0);
    }

    hFrame[ip]->Draw("col");

    hIonProbvsTime[1]->GetZaxis()->SetNdivisions(503);
    hIonProbvsTime[1]->GetZaxis()->SetTitleFont(fonttype);
    Float_t xFactor = pad[0]->GetAbsWNDC()/pad[ip]->GetAbsWNDC();
    Float_t yFactor = pad[0]->GetAbsHNDC()/pad[ip]->GetAbsHNDC();
    hIonProbvsTime[1]->GetZaxis()->SetTickLength(xFactor*tylength/yFactor);
    hIonProbvsTime[1]->GetZaxis()->SetRangeUser(0.,0.12);
    
    // exFieldT->Draw();
    // exPlasma->Draw();
    exIonP->Draw();
    hIonProbvsTime[1]->Draw("colz same");

    pad[ip]->Update();
  
    y1 = pad[ip]->GetBottomMargin();
    y2 = 1 - pad[ip]->GetTopMargin();
    x1 = pad[ip]->GetLeftMargin();
    x2 = 1 - pad[ip]->GetRightMargin();
  
    palette = (TPaletteAxis*) hIonProbvsTime[1]->GetListOfFunctions()->FindObject("palette");  
    if(palette) {
      palette->SetY2NDC(y2 - gap);
      palette->SetY1NDC(y1 + gap);
      palette->SetX1NDC(x2 + 0.005);
      palette->SetX2NDC(x2 + 0.03);
      palette->SetTitleOffset(tzoffset);
      palette->SetTitleSize(tzsize);
      palette->SetLabelFont(fonttype);
      palette->SetLabelSize(lzsize);
      palette->SetLabelOffset(lyoffset);
      palette->SetBorderSize(2);
      palette->SetLineColor(1);
    }

    if(!opt.Contains("nocross")) {
      
      for(Int_t ic=0;ic<NVCross;ic++) {
	if( gVcross[ic] )
	  gVcross[ic]->Draw("L");
      }
      
      if(gEcross[1][0]) {
	gEcross[1][0]->SetLineStyle(4);
	gEcross[1][0]->Draw("L");
      }
    }
     
    pad[ip]->RedrawAxis(); 

    ip--;
    C->cd(0);
    
  }
  
  // Print to a file
  // Output file
  TString fOutName = Form("./%s/Plots/Evolutions/Evolutions%s-WII-%s",sim.Data(),imask.c_str(),sim.Data());
  PGlobals::imgconv(C,fOutName,opt);
  // ---------------------------------------------------------

  
  ifile->Close();
  cout << endl;
}
Example #29
0
void combinePlots(char* sample = "T2tt" , int x = 1, bool print = false){

  bool  shift       = true;
  bool  smooth      = false;
  char* filename    = "";
  char* outfilename = "";
  char* label       = "";
  float xaxismin    = 0;
  float yaxismax    = 250.0;

  if( TString(sample).Contains("T2tt") ){
    label       = "pp #rightarrow #tilde{t} #tilde{t}, #tilde{t} #rightarrow t #chi_{1}^{0}";
    outfilename = "combinePlots_T2tt.root";
    xaxismin    = 200.0;
    yaxismax    = 250.0;
    filename    = "T2tt_histos_trigweight.root";
  }

  else if( TString(sample).Contains("T2bw") ){

    label       = "pp #rightarrow #tilde{t} #tilde{t}, #tilde{t} #rightarrow b #chi_{1}^{#pm} #rightarrow b W #chi_{1}^{0}";

    if( x==25 ){
      xaxismin = 360.0;
      outfilename = "combinePlots_T2bw_x25.root";
      filename    = "T2bw_x25_histos.root";
    }
    if( x==50 ){
      xaxismin = 180.0;
      outfilename = "combinePlots_T2bw_x75.root";
      filename    = "T2bw_x50_histos.root";
    }
    if( x==75 ){
      xaxismin = 120.0;
      outfilename = "combinePlots_T2bw_x75.root";
      filename    = "T2bw_x75_histos.root";
      smooth      = true;
    }
  }

  else{
    cout << "ERROR! unrecognized sample " << sample << endl;
    exit(0);
  }

  cout << "--------------------------------------" << endl;
  cout << "Opening    " << filename << endl;
  cout << "Writing to " << outfilename << endl;
  cout << "Label      " << label << endl;
  cout << "--------------------------------------" << endl;

  TFile *file = TFile::Open(filename);

  const unsigned int ncuts = 7;

  TH2F* hxsec[ncuts];
  TH2F* hxsec_exp[ncuts];
  TH2F* hxsec_expp1[ncuts];
  TH2F* hxsec_expm1[ncuts];
  TH2F* hxsec_best;
  TH2F* hbest;
  TH2F* hxsec_best_exp;
  TH2F* hxsec_best_expp1;
  TH2F* hxsec_best_expm1;

  for( unsigned int i = 0 ; i < ncuts ; ++i ){
    hxsec[i]       = (TH2F*) file->Get(Form("hxsec_%i",i));
    hxsec_exp[i]   = (TH2F*) file->Get(Form("hxsec_exp_%i",i));
    hxsec_expp1[i] = (TH2F*) file->Get(Form("hxsec_expp1_%i",i));
    hxsec_expm1[i] = (TH2F*) file->Get(Form("hxsec_expm1_%i",i));

    if( i == 0 ){
      hxsec_best = (TH2F*) hxsec[i]->Clone("hxsec_best");
      hxsec_best->Reset();
      hbest = (TH2F*) hxsec[i]->Clone("hbest");
      hbest->Reset();
      hxsec_best_exp = (TH2F*) hxsec[i]->Clone("hxsec_best_exp");
      hxsec_best_exp->Reset();
      hxsec_best_expp1 = (TH2F*) hxsec[i]->Clone("hxsec_best_expp1");
      hxsec_best_expp1->Reset();
      hxsec_best_expm1 = (TH2F*) hxsec[i]->Clone("hxsec_best_expm1");
      hxsec_best_expm1->Reset();
    }


  }

  for( int xbin = 1 ; xbin <= hxsec_best->GetXaxis()->GetNbins() ; ++xbin ){
    for( int ybin = 1 ; ybin <= hxsec_best->GetYaxis()->GetNbins() ; ++ybin ){

      cout << "xbin ybin " << xbin << " " << ybin << endl;
     
      if( hxsec_exp[0]->GetBinContent(xbin,ybin) < 1e-10 ) continue;
      
      int   best_ul    = 0;
      float min_exp_ul = hxsec_exp[0]->GetBinContent(xbin,ybin);

      cout << "exp0 " << hxsec_exp[0]->GetBinContent(xbin,ybin) << endl;

      for( unsigned int i = 1 ; i < ncuts ; ++i ){

	if( hxsec_exp[i]->GetBinContent(xbin,ybin) < 1e-10 ) continue;

	cout << "exp" << i << " " << hxsec_exp[i]->GetBinContent(xbin,ybin) << endl;

	if( hxsec_exp[i]->GetBinContent(xbin,ybin) < min_exp_ul ){
	  min_exp_ul = hxsec_exp[i]->GetBinContent(xbin,ybin);
	  best_ul    = i;
	}

      }

      hxsec_best->SetBinContent(xbin,ybin,hxsec[best_ul]->GetBinContent(xbin,ybin));
      hxsec_best_exp->SetBinContent(xbin,ybin,hxsec_exp[best_ul]->GetBinContent(xbin,ybin));
      hxsec_best_expp1->SetBinContent(xbin,ybin,hxsec_expp1[best_ul]->GetBinContent(xbin,ybin));
      hxsec_best_expm1->SetBinContent(xbin,ybin,hxsec_expm1[best_ul]->GetBinContent(xbin,ybin));
      hbest->SetBinContent(xbin,ybin,best_ul+1);

      cout << "best ul " << best_ul << " " << min_exp_ul << endl;
      cout << "obs limit " << hxsec[best_ul]->GetBinContent(xbin,ybin) << endl << endl << endl;
      
 
    }
  }

  TCanvas *can1 = new TCanvas("can1","",800,600);
  can1->cd();

  TLatex *t = new TLatex();
  t->SetNDC();

  //-------------------------------
  // cross section limit
  //-------------------------------

  if( smooth ){
    smoothHist( hxsec_best );
    smoothHist( hbest );
  }

  blankHist( hxsec_best , 200 );
  TH2F* hxsec_best_shifted = shiftHist( hxsec_best );
  TH2F* hdummy = (TH2F*) hxsec_best->Clone("hdummy");
  hdummy->Reset();

  //hxsec_best->Reset();
  // if( shift ){
  //   hxsec_best = shiftHist( hxsec_best );
  //}

  // cout << endl << "observed" << endl;
  // plot1D( hxsec_best );
  // cout << endl << "observed (+1)" << endl;
  // plot1D( hxsec_best_obsp1 );
  // cout << endl << "observed (-1)" << endl;
  // plot1D( hxsec_best_obsm1 );
  // cout << endl << "expected" << endl;
  // plot1D( hxsec_best_exp );
  // cout << endl << "expected (+1)" << endl;
  // plot1D( hxsec_best_expp1 );
  // cout << endl << "expected (-1)" << endl;
  // plot1D( hxsec_best_expm1 );

  gPad->SetTopMargin(0.1);
  gPad->SetRightMargin(0.2);
  gPad->SetLogz();
  hdummy->GetXaxis()->SetLabelSize(0.035);
  hdummy->GetYaxis()->SetLabelSize(0.035);
  hdummy->GetZaxis()->SetLabelSize(0.035);
  hdummy->GetYaxis()->SetTitle("m_{#chi^{0}_{1}} [GeV]");
  hdummy->GetYaxis()->SetTitleOffset(0.9);
  hdummy->GetXaxis()->SetTitle("m_{ #tilde{t}} [GeV]");
  hdummy->GetZaxis()->SetTitle("95% CL UL on #sigma#timesBF [pb]");
  hdummy->GetZaxis()->SetTitleOffset(0.8);
  hdummy->GetXaxis()->SetRangeUser(xaxismin,590);
  hdummy->GetYaxis()->SetRangeUser(0,yaxismax);
  //hdummy->Draw("colz");
  hdummy->SetMinimum(0.01);
  hdummy->SetMaximum(10);
  hxsec_best_shifted->SetMinimum(0.01);
  hxsec_best_shifted->SetMaximum(10);
  hdummy->SetMaximum(10);
  hdummy->Draw();
  hxsec_best_shifted->Draw("samecolz");
  hdummy->Draw("axissame");
  
  // TGraph* gr        = getRefXsecGraph(hxsec_best       , "T2tt", 1.0);
  // TGraph* gr_exp    = getRefXsecGraph(hxsec_best_exp   , "T2tt", 1.0);
  // TGraph* gr_expp1  = getRefXsecGraph(hxsec_best_expp1 , "T2tt", 1.0);
  // TGraph* gr_expm1  = getRefXsecGraph(hxsec_best_expm1 , "T2tt", 1.0);
  // TGraph* gr_obsp1  = getRefXsecGraph(hxsec_best       , "T2tt", 1.15);
  // TGraph* gr_obsm1  = getRefXsecGraph(hxsec_best       , "T2tt", 0.85);


  TGraph* gr       = new TGraph();
  TGraph* gr_exp   = new TGraph();
  TGraph* gr_expp1 = new TGraph();
  TGraph* gr_expm1 = new TGraph();
  TGraph* gr_obsp1 = new TGraph();
  TGraph* gr_obsm1 = new TGraph();

  if( TString(sample).Contains("T2tt") ){
    gr       = T2tt_observed();
    gr_exp   = T2tt_expected();
    gr_expp1 = T2tt_expectedP1();
    gr_expm1 = T2tt_expectedM1();
    gr_obsp1 = T2tt_observedP1();
    gr_obsm1 = T2tt_observedM1();
  }
  else if( TString(sample).Contains("T2bw") && x==75 ){
    gr       = T2bw_x75_observed();
    gr_exp   = T2bw_x75_expected();
    gr_expp1 = T2bw_x75_expectedP1();
    gr_expm1 = T2bw_x75_expectedM1();
    gr_obsp1 = T2bw_x75_observedP1();
    gr_obsm1 = T2bw_x75_observedM1();
  }
  else if( TString(sample).Contains("T2bw") && x==50 ){
    gr       = T2bw_x50_observed();
    gr_exp   = T2bw_x50_expected();
    gr_expp1 = T2bw_x50_expectedP1();
    gr_expm1 = T2bw_x50_expectedM1();
    gr_obsp1 = T2bw_x50_observedP1();
    gr_obsm1 = T2bw_x50_observedM1();
  }

  gr->SetLineWidth(6);

  gr_exp->SetLineWidth(4);
  gr_exp->SetLineStyle(7);

  gr_expp1->SetLineWidth(3);
  gr_expp1->SetLineStyle(3);
  gr_expm1->SetLineWidth(3);
  gr_expm1->SetLineStyle(3);

  gr_exp->SetLineColor(4);
  gr_expp1->SetLineColor(4);
  gr_expm1->SetLineColor(4);

  gr_obsp1->SetLineStyle(2);
  gr_obsm1->SetLineStyle(2);
  gr_obsp1->SetLineWidth(3);
  gr_obsm1->SetLineWidth(3);

  gr_exp->Draw();
  gr_expp1->Draw();
  gr_expm1->Draw();
  gr_obsp1->Draw();
  gr_obsm1->Draw();
  gr->Draw();

  // cout << endl << "observed" << endl;
  // printGraph(gr);
  // cout << endl << "observed (+1)" << endl;
  // printGraph(gr_obsp1);
  // cout << endl << "observed (-1)" << endl;
  // printGraph(gr_obsm1);
  // cout << endl << "expected" << endl;
  // printGraph(gr_exp);
  // cout << endl << "expected (+1)" << endl;
  // printGraph(gr_expp1);
  // cout << endl << "expected (-1)" << endl;
  // printGraph(gr_expm1);

  // TLegend *leg = new TLegend(0.2,0.6,0.65,0.8);
  // leg->AddEntry(gr,       "observed","l");
  // leg->AddEntry(gr_exp,   "median expected (#pm1#sigma)","l");
  // //leg->AddEntry(gr_expp1, "expected (#pm1#sigma)","l");
  // leg->SetFillColor(0);
  // leg->SetBorderSize(0);
  // leg->Draw();

  /*
  t->SetTextSize(0.04);
  t->DrawLatex(0.20,0.72  ,"NLO-NLL exclusions");
  t->DrawLatex(0.27,0.67,"Observed #pm1#sigma^{theory}");
  t->DrawLatex(0.27,0.62,"Expected #pm1#sigma");

  t->DrawLatex(0.19,0.84,label);
  t->DrawLatex(0.19,0.79,"unpolarized top quarks");
  */
  t->SetTextSize(0.035);
  t->DrawLatex(0.18,0.79,"50 / 50 t_{L} / t_{R} mixture");
  t->DrawLatex(0.18,0.84,label);
  t->SetTextSize(0.04);
  t->DrawLatex(0.50,0.85  ,"NLO-NLL exclusions");
  t->DrawLatex(0.55,0.80,"Observed #pm1#sigma^{theory}");
  t->DrawLatex(0.55,0.75,"Expected #pm1#sigma");


  t->SetTextSize(0.045);
  if( TString(sample).Contains("T2bw") && x==25 ) t->DrawLatex(0.15,0.04,"m_{#chi_{1}^{#pm}} = 0.25 m_{ #tilde{t}} + 0.75 m_{#chi_{1}^{0}}");
  if( TString(sample).Contains("T2bw") && x==50 ) t->DrawLatex(0.15,0.04,"m_{#chi_{1}^{#pm}} = 0.5 m_{ #tilde{t}} + 0.5 m_{#chi_{1}^{0}}");
  if( TString(sample).Contains("T2bw") && x==75 ) t->DrawLatex(0.15,0.04,"m_{#chi_{1}^{#pm}} = 0.75 m_{ #tilde{t}} + 0.25 m_{#chi_{1}^{0}}");

  //float offset = 40.0;
  float xoffset = 405.0;
  float yoffset = 213.0;
  float length  =  30.0;
  float yspace1 =     5;
  float yspace2 =    17;

  if( TString(sample).Contains("T2bw") && x==75 ) xoffset -= 30.0;
  
  // median expected
  //TLine *line22 = new TLine(xaxismin+xoffset+25, 310-yoffset, xaxismin+xoffset+65, 310-yoffset);
  TLine *line22 = new TLine(xoffset,yoffset,xoffset+length,yoffset);
  line22->SetLineWidth(4);
  line22->SetLineColor(4);
  line22->SetLineStyle(7);
  line22->Draw();
 
  // expected +/-1sigma
  //TLine *line23 = new TLine(xaxismin+xoffset+25, 317-yoffset, xaxismin+xoffset+65, 317-yoffset);
  TLine *line23 = new TLine(xoffset,yoffset+yspace1,xoffset+length,yoffset+yspace1);
  line23->SetLineWidth(3);
  line23->SetLineColor(4);
  line23->SetLineStyle(3);
  line23->Draw();

  // expected +/-1sigma  
  //TLine *line24 = new TLine(xaxismin+xoffset+25, 303-yoffset, xaxismin+xoffset+65, 303-yoffset);
  TLine *line24 = new TLine(xoffset,yoffset-yspace1,xoffset+length,yoffset-yspace1);
  line24->SetLineWidth(3);
  line24->SetLineColor(4);
  line24->SetLineStyle(3);
  line24->Draw();

  // median observed
  //TLine *line25 = new TLine(xaxismin+xoffset+25, 335-yoffset, xaxismin+xoffset+65, 335-yoffset);
  TLine *line25 = new TLine(xoffset,yoffset+yspace2,xoffset+length,yoffset+yspace2);
  line25->SetLineWidth(6);
  line25->SetLineColor(1);
  line25->SetLineStyle(1);
  line25->Draw();
 
  //TLine *line26 = new TLine(xaxismin+xoffset+25, 342-yoffset, xaxismin+xoffset+65, 342-yoffset);
  TLine *line26 = new TLine(xoffset,yoffset+yspace1+yspace2,xoffset+length,yoffset+yspace1+yspace2);
  line26->SetLineWidth(2);
  line26->SetLineColor(1);
  line26->SetLineStyle(2);
  line26->Draw();
  
  //TLine *line27 = new TLine(xaxismin+xoffset+25, 328-yoffset, xaxismin+xoffset+65, 328-yoffset);
  TLine *line27 = new TLine(xoffset,yoffset-yspace1+yspace2,xoffset+length,yoffset-yspace1+yspace2);
  line27->SetLineWidth(2);
  line27->SetLineColor(1);
  line27->SetLineStyle(2);
  line27->Draw();



  t->SetTextSize(0.04);
  t->DrawLatex(0.18,0.94,"CMS Preliminary                 #sqrt{s} = 8 TeV, #scale[0.6]{#int}Ldt = 9.7 fb^{-1}");
  
  /*
  //-------------------------------
  // best signal region
  //-------------------------------

  TCanvas *can2 = new TCanvas("can2","",600,600);
  can2->cd();
  
  hbest->Draw("colz");
  hbest->Draw("sametext");
  gPad->SetTopMargin(0.1);
  gPad->SetRightMargin(0.2);
  hbest->SetMaximum(7);
  hbest->GetXaxis()->SetLabelSize(0.035);
  hbest->GetYaxis()->SetLabelSize(0.035);
  hbest->GetZaxis()->SetLabelSize(0.035);
  hbest->GetYaxis()->SetTitle("m_{#chi^{0}_{1}} [GeV]");
  hbest->GetXaxis()->SetTitle("m_{ #tilde{t}} [GeV]");
  hbest->GetXaxis()->SetRangeUser(xaxismin,590);
  hbest->GetYaxis()->SetRangeUser(0,400);
  hbest->GetZaxis()->SetTitle("best signal region");

  t->SetTextSize(0.035);
  t->DrawLatex(0.18,0.92,"CMS Preliminary   #sqrt{s} = 8 TeV, #scale[0.6]{#int}Ldt = 9.7 fb^{-1}");
  
  t->SetTextSize(0.04);
  t->DrawLatex(0.19,0.83,label);

  t->DrawLatex(0.2,0.75,"1 = SRA");
  t->DrawLatex(0.2,0.70,"2 = SRB");
  t->DrawLatex(0.2,0.65,"3 = SRC");
  t->DrawLatex(0.2,0.60,"4 = SRD");
  t->DrawLatex(0.2,0.55,"5 = SRE");
  t->DrawLatex(0.2,0.50,"6 = SRF");
  t->DrawLatex(0.2,0.45,"7 = SRG");

  if( TString(sample).Contains("T2bw") && x==25 ) t->DrawLatex(0.15,0.03,"m_{#chi_{1}^{#pm}} = 0.25 m_{ #tilde{t}} + 0.75 m_{#chi_{1}^{0}}");
  if( TString(sample).Contains("T2bw") && x==50 ) t->DrawLatex(0.15,0.03,"m_{#chi_{1}^{#pm}} = 0.5 m_{ #tilde{t}} + 0.5 m_{#chi_{1}^{0}}");
  if( TString(sample).Contains("T2bw") && x==75 ) t->DrawLatex(0.15,0.03,"m_{#chi_{1}^{#pm}} = 0.75 m_{ #tilde{t}} + 0.25 m_{#chi_{1}^{0}}");




  //-------------------------------
  // excluded regions
  //-------------------------------

  int   nbinsx  =   120;
  float xmin    =    -5;
  float xmax    =  1195;
  int   nbinsy  =   120;
  float ymin    =    -5;
  float ymax    =  1195;

  TFile* f = TFile::Open("stop_xsec.root");
  TH1F* refxsec = (TH1F*) f->Get("h_stop_xsec");

  TH2F* hexcl       = new TH2F("hexcl"         , "hexcl"        , nbinsx , xmin , xmax , nbinsy , ymin , ymax );
  TH2F* hexcl_obsp1 = new TH2F("hexcl_obsp1"   , "hexcl_obsp1"  , nbinsx , xmin , xmax , nbinsy , ymin , ymax );
  TH2F* hexcl_obsm1 = new TH2F("hexcl_obsm1"   , "hexcl_obsm1"  , nbinsx , xmin , xmax , nbinsy , ymin , ymax );
  TH2F* hexcl_exp   = new TH2F("hexcl_exp"     , "hexcl_exp"    , nbinsx , xmin , xmax , nbinsy , ymin , ymax );
  TH2F* hexcl_expp1 = new TH2F("hexcl_expp1"   , "hexcl_expp1"  , nbinsx , xmin , xmax , nbinsy , ymin , ymax );
  TH2F* hexcl_expm1 = new TH2F("hexcl_expm1"   , "hexcl_expm1"  , nbinsx , xmin , xmax , nbinsy , ymin , ymax );

  
  for( unsigned int ibin = 1 ; ibin <= nbinsx ; ibin++ ){
    for( unsigned int jbin = 1 ; jbin <= nbinsy ; jbin++ ){

      //float mg      = hxsec_best->GetXaxis()->GetBinCenter(ibin);
      float mg      = hexcl->GetXaxis()->GetBinCenter(ibin);
      int   bin     = refxsec->FindBin(mg);
      float xsec    = refxsec->GetBinContent(bin);

      float xsec_up = refxsec->GetBinContent(bin) + refxsec->GetBinError(bin);
      float xsec_dn = refxsec->GetBinContent(bin) - refxsec->GetBinError(bin);
      
      float xsecul       = hxsec_best->GetBinContent(ibin,jbin);
      float xsecul_exp   = hxsec_best_exp->GetBinContent(ibin,jbin);
      float xsecul_expp1 = hxsec_best_expp1->GetBinContent(ibin,jbin);
      float xsecul_expm1 = hxsec_best_expm1->GetBinContent(ibin,jbin);

      // cout << endl;
      // cout << "mg xsec " << mg << " " << xsec << endl;
      // cout << "xsec: obs exp expp1 expm1 " << xsecul << " " << xsecul_exp << " " << xsecul_expp1 << " " << xsecul_expm1 << endl;

      if( xsecul < 1.e-10 ) continue;

      hexcl->SetBinContent(ibin,jbin,0);
      if( xsec > xsecul )   hexcl->SetBinContent(ibin,jbin,1);

      hexcl_exp->SetBinContent(ibin,jbin,0);
      if( xsec > xsecul_exp )   hexcl_exp->SetBinContent(ibin,jbin,1);
      
      hexcl_expp1->SetBinContent(ibin,jbin,0);
      if( xsec > xsecul_expp1 )   hexcl_expp1->SetBinContent(ibin,jbin,1);
      
      hexcl_expm1->SetBinContent(ibin,jbin,0);
      if( xsec > xsecul_expm1 )   hexcl_expm1->SetBinContent(ibin,jbin,1);
      
      hexcl_obsp1->SetBinContent(ibin,jbin,0);
      if( xsec_up > xsecul )   hexcl_obsp1->SetBinContent(ibin,jbin,1);
      
      hexcl_obsm1->SetBinContent(ibin,jbin,0);
      if( xsec_dn > xsecul )   hexcl_obsm1->SetBinContent(ibin,jbin,1);
    }
  }

  TCanvas *can3 = new TCanvas("can3","can3",1200,800);
  can3->Divide(3,2);

  t->SetTextSize(0.07);

  gr->SetMarkerColor(6);
  gr_obsp1->SetMarkerColor(6);
  gr_obsm1->SetMarkerColor(6);
  gr_exp->SetMarkerColor(6);
  gr_expp1->SetMarkerColor(6);
  gr_expm1->SetMarkerColor(6);

  can3->cd(1);
  gPad->SetGridx();
  gPad->SetGridy();
  hexcl->GetXaxis()->SetTitle("stop mass [GeV]");
  hexcl->GetYaxis()->SetTitle("#chi_{1}^{0} mass [GeV]");
  hexcl->GetXaxis()->SetRangeUser(xaxismin,600);
  hexcl->GetYaxis()->SetRangeUser(0,200);
  hexcl->Draw("colz");
  gr->Draw("lp");
  t->DrawLatex(0.3,0.8,"observed");

  can3->cd(2);
  gPad->SetGridx();
  gPad->SetGridy();
  hexcl_obsp1->GetXaxis()->SetTitle("stop mass [GeV]");
  hexcl_obsp1->GetYaxis()->SetTitle("#chi_{1}^{0} mass [GeV]");
  hexcl_obsp1->GetXaxis()->SetRangeUser(xaxismin,600);
  hexcl_obsp1->GetYaxis()->SetRangeUser(0,200);
  hexcl_obsp1->Draw("colz");
  gr_obsp1->Draw("lp");
  t->DrawLatex(0.3,0.8,"observed (+1#sigma)");

  can3->cd(3);
  gPad->SetGridx();
  gPad->SetGridy();
  hexcl_obsm1->GetXaxis()->SetTitle("stop mass [GeV]");
  hexcl_obsm1->GetYaxis()->SetTitle("#chi_{1}^{0} mass [GeV]");
  hexcl_obsm1->GetXaxis()->SetRangeUser(xaxismin,600);
  hexcl_obsm1->GetYaxis()->SetRangeUser(0,200);
  hexcl_obsm1->Draw("colz");
  gr_obsm1->Draw("lp");
  t->DrawLatex(0.3,0.8,"observed (-1#sigma)");

  can3->cd(4);
  gPad->SetGridx();
  gPad->SetGridy();
  hexcl_exp->GetXaxis()->SetTitle("stop mass [GeV]");
  hexcl_exp->GetYaxis()->SetTitle("#chi_{1}^{0} mass [GeV]");
  hexcl_exp->GetXaxis()->SetRangeUser(xaxismin,600);
  hexcl_exp->GetYaxis()->SetRangeUser(0,200);
  hexcl_exp->Draw("colz");
  gr_exp->Draw("lp");
  t->DrawLatex(0.3,0.8,"expected");

  can3->cd(5);
  gPad->SetGridx();
  gPad->SetGridy();
  hexcl_expp1->GetXaxis()->SetTitle("stop mass [GeV]");
  hexcl_expp1->GetYaxis()->SetTitle("#chi_{1}^{0} mass [GeV]");
  hexcl_expp1->GetXaxis()->SetRangeUser(xaxismin,600);
  hexcl_expp1->GetYaxis()->SetRangeUser(0,200);
  hexcl_expp1->Draw("colz");
  gr_expp1->Draw("lp");
  t->DrawLatex(0.3,0.8,"expected (+1#sigma)");

  can3->cd(6);
  gPad->SetGridx();
  gPad->SetGridy();
  hexcl_expm1->GetXaxis()->SetTitle("stop mass [GeV]");
  hexcl_expm1->GetYaxis()->SetTitle("#chi_{1}^{0} mass [GeV]");
  hexcl_expm1->GetXaxis()->SetRangeUser(xaxismin,600);
  hexcl_expm1->GetYaxis()->SetRangeUser(0,200);
  hexcl_expm1->Draw("colz");
  gr_expm1->Draw("lp");
  t->DrawLatex(0.3,0.8,"expected (-1#sigma)");
*/

  if( print ){
    if     ( TString(sample).Contains("T2tt") ){
      can1->Print("../../plots/combinePlots_T2tt.pdf");
      //can2->Print("../../plots/combinePlots_T2tt_bestSignalRegion.pdf");
      //can3->Print("../../plots/combinePlots_T2tt_excludedPoints.pdf");
    }
    else if( TString(sample).Contains("T2bw") ){
      can1->Print(Form("../../plots/combinePlots_T2bw_x%i.pdf",x));
      //can2->Print(Form("../../plots/combinePlots_T2bw_x%i_bestSignalRegion.pdf",x));
      //can3->Print(Form("../../plots/combinePlots_T2bw_x%i_excludedPoints.pdf",x));
    }
  }

  TFile* fout = TFile::Open(Form("%s_x%icombinePlots.root",sample,x),"RECREATE");
  fout->cd();
  hxsec_best->Write();
  hxsec_best_exp->Write();
  gr->Write();
  fout->Close();

}
void DrawFits(TemplateFIT * FIT,FileSaver finalHistos,FileSaver Plots){

	std::string pathdata  = (FIT->GetName() + "/Fit Results/Data");
	std::string pathtemplP= (FIT->GetName() + "/Fit Results/ScaledTemplatesP");
	std::string pathtemplD= (FIT->GetName() + "/Fit Results/ScaledTemplatesD");	
	std::string pathtemplHe=(FIT->GetName() + "/Fit Results/ScaledTemplatesHe");	

	std::string pathfit   = (FIT->GetName() + "/Fit Results/FractionFits");
	std::string pathtrans = (FIT->GetName() + "/Fit Results/TrasnferFunctions");
	std::string pathres   = (FIT->GetName() + "/Fit Results/");
	
	TFile * infile = finalHistos.GetFile();	


	for(int i=1; i<FIT->GetBinning().size();i++){
		
		std::string pathbinP    = pathtemplP + "/Bin"+to_string(i);
		std::string pathbinD    = pathtemplD + "/Bin"+to_string(i);
		std::string pathbinHe   = pathtemplHe+ "/Bin"+to_string(i);
		std::string pathbindata = pathdata   + "/Bin"+to_string(i);
		std::string pathbinfit  = pathfit    + "/Bin"+to_string(i);

		std::vector<TH1F*> TemplatesP=GetListOfTemplates(infile, pathbinP);
		std::vector<TH1F*> TemplatesD=GetListOfTemplates(infile, pathbinD);		
		std::vector<TH1F*> TemplatesHe=GetListOfTemplates(infile, pathbinHe);		
		std::vector<TH1F*> Datas     =GetListOfTemplates(infile, pathbindata);
		std::vector<TH1F*> Fits      =GetListOfTemplates(infile, pathbinfit);
		std::vector<TH1F*> Transfer  =GetListOfTemplates(infile, pathtrans);

		cout<<pathbinHe<<" "<<TemplatesHe.size()<<" "<<TemplatesHe[0]<<endl;
	

		TCanvas * c1 = new TCanvas("Modified Templates");
		c1->SetCanvasSize(2000,1500);

		for(int j=TemplatesP.size()-1;j>=0;j--){
			if(j==0) PlotDistribution(gPad, TemplatesP[j],"Reconstructed Mass [GeV/c^2]","Counts",1,"same",1,TemplatesP[j]->GetBinContent(TemplatesP[j]->GetMaximumBin())*1.13,10);
			else     PlotDistribution(gPad, TemplatesP[j],"Reconstructed Mass [GeV/c^2]","Counts",colorbase + j,"same",1,TemplatesP[j]->GetBinContent(TemplatesP[j]->GetMaximumBin())*1.13,7,"",false,false,true);		
		}
	
		Plots.Add(c1);
		Plots.writeObjsInFolder((FIT->GetName()+"/Fits/Bin"+to_string(i)).c_str());	


		TCanvas * c2 = new TCanvas("Modified T. Fits");
                c2->SetCanvasSize(2000,1500);

		PlotDistribution(gPad, TemplatesP[0], "Reconstructed Mass [GeV/c^2]","Counts",2,"same",1,Datas[0]->GetBinContent(Datas[0]->GetMaximumBin())*1.13,10,"Original Protons MC Template");
		PlotDistribution(gPad, TemplatesD[0], "Reconstructed Mass [GeV/c^2]","Counts",4,"same",1,1e5,10,"Original Deuterons MC Template");
		PlotDistribution(gPad, TemplatesHe[0],"Reconstructed Mass [GeV/c^2]","Counts",3,"same",1,1e5,10,"Original He Fragm. MC Template");

		for(int j=TemplatesP.size()-1;j>=1;j--){
                        PlotDistribution(gPad, TemplatesP[j],"Reconstructed Mass [GeV/c^2]","Counts",2,"same",1,1e5,1,"",false,false,true);
			PlotDistribution(gPad, TemplatesD[j],"Reconstructed Mass [GeV/c^2]","Counts",4,"same",1,1e5,1,"",false,false,true);
                	//PlotDistribution(gPad, TemplatesHe[j],"Reconstructed Mass [GeV/c^2]","Counts",3,"same",1,1e5,1,"",false,false,true);
		}
		PlotDistribution(gPad, Datas[0],"Reconstructed Mass [GeV/c^2]","Counts",1,"ePsame",1,1e5,3,"ISS data",false,true);
	


		Plots.Add(c2);
                Plots.writeObjsInFolder((FIT->GetName()+"/Fits/Bin"+to_string(i)).c_str());
		
		
		TCanvas * c3 = new TCanvas("Template Fits");
                c3->SetCanvasSize(2000,1500);

		PlotDistribution(gPad, TemplatesP[0] ,"Reconstructed Mass [GeV/c^2]","Counts",2,"same",1,Datas[0]->GetBinContent(Datas[0]->GetMaximumBin())*1.13,2,"Original Protons MC Template");
		PlotDistribution(gPad, TemplatesD[0] ,"Reconstructed Mass [GeV/c^2]","Counts",4,"same",1,1e5,2,"Original Deuterons MC Template");
		PlotDistribution(gPad, TemplatesHe[0],"Reconstructed Mass [GeV/c^2]","Counts",3,"same",1,1e5,2,"Original He Fragm. MC Template");
		PlotDistribution(gPad, TemplatesP[1] ,"Reconstructed Mass [GeV/c^2]","Counts",2,"same",1,Datas[0]->GetBinContent(Datas[0]->GetMaximumBin())*1.13,10,"Best #chi^{2} Protons MC Template");
		PlotDistribution(gPad, TemplatesD[1] ,"Reconstructed Mass [GeV/c^2]","Counts",4,"same",1,1e5,10,"Best #chi^{2} Deuterons MC Template");
		PlotDistribution(gPad, TemplatesHe[1],"Reconstructed Mass [GeV/c^2]","Counts",3,"same",1,1e5,10,"Best #chi^{2} he Fragm. MC Template");
		

		PlotDistribution(gPad, Datas[0],"Reconstructed Mass [GeV/c^2]","Counts",1,"ePsame",1,1e5,3,"ISS data",false,true);
		if(Fits.size()>0) PlotDistribution(gPad, Fits[0],"Reconstructed Mass [gev/c^2]","counts",6,"same",1,1e5,4,"Fraction Fit");
	

		Plots.Add(c3);
                Plots.writeObjsInFolder((FIT->GetName()+"/Fits/Bin"+to_string(i)).c_str());

		TCanvas * c5 = new TCanvas("Transfer Functions");
                c5->SetCanvasSize(2000,1500);

		for(int j=0;j<Transfer.size();j++){
			Transfer[j]->Smooth(3);
			PlotDistribution(gPad, Transfer[j],"Reconstructed Mass [GeV/c^2]","Prim. / (Prim. + Sec.)",j,"hist,same",0,1,7,("Bin. "+to_string(j)).c_str(),false,false);
		}

		Plots.Add(c5);
                Plots.writeObjsInFolder((FIT->GetName()+"/Fits").c_str());

	

		TCanvas * c4 = new TCanvas("ChiSquare");
                c4->SetCanvasSize(2000,1500);
		gPad->SetLogz();	
		TH2F * Chi = (TH2F*) infile->Get((FIT->GetName()+"/Fit Results/Spreads/ChiSquare/ChiSquare Bin "+to_string(i)).c_str());
                Chi->GetZaxis()->SetRangeUser(0.2,100);
                PlotTH2F(gPad, Chi, "Additive #sigma","Mean shift", "colz");	


		Plots.Add(c4);
                Plots.writeObjsInFolder((FIT->GetName()+"/Fits/Bin"+to_string(i)).c_str());

		TCanvas * c6 = new TCanvas("OverCutoff Events");
                c6->SetCanvasSize(2000,1500);
			
		TH1F * OverCutoffP = (TH1F *) TemplatesP[1]->Clone();
		OverCutoffP->Multiply(Transfer[i]);
		TH1F * OverCutoffD = (TH1F *) TemplatesD[1]->Clone();
		OverCutoffD->Multiply(Transfer[i]);
		TH1F * NoCutoffP = (TH1F *) TemplatesP[1]->Clone();

		NoCutoffP->Scale(
			OverCutoffP->GetBinContent(OverCutoffP->GetMaximumBin())/
			NoCutoffP->GetBinContent(NoCutoffP->GetMaximumBin()) );

		PlotDistribution(gPad, NoCutoffP,"Reconstructed Mass [GeV/c^2]","Primary Counts",2,"same",1,Datas[1]->GetBinContent(Datas[1]->GetMaximumBin())*1.13,3,"Best #chi^{2} Protons MC Template");
		PlotDistribution(gPad, OverCutoffP,"Reconstructed Mass [GeV/c^2]","Counts",2,"same",1,Datas[0]->GetBinContent(Datas[0]->GetMaximumBin())*1.13,10,"Best #chi^{2} Protons MC (Cutoff filtered)");
		PlotDistribution(gPad, OverCutoffD,"Reconstructed Mass [GeV/c^2]","Counts",4,"same",1,Datas[0]->GetBinContent(Datas[0]->GetMaximumBin())*1.13,10,"Best #chi^{2} Deutons MC (Cutoff filtered)");
		PlotDistribution(gPad, Datas[1],"Reconstructed Mass [GeV/c^2]","Primary Counts",1,"ePsame",1,Datas[1]->GetBinContent(Datas[1]->GetMaximumBin())*1.13,3,"ISS data",false,true);
	

		Plots.Add(c6);
                Plots.writeObjsInFolder((FIT->GetName()+"/Fits/Bin"+to_string(i)).c_str());


	

	}

	return;

}