示例#1
0
void zeeAnaDiff(TH1D* hsee, TCut addCut,TH1D* hseeMc) {
  
  TFile *f1=new TFile(fname1.Data());
  TTree *zp = (TTree*)f1->Get("tz");
  zp->AddFriend("yEvt=yongsunHiEvt"       ,fname1.Data());
  zp->AddFriend("ySkim=yongsunSkimTree"   ,fname1.Data());
  zp->AddFriend("yHlt=yongsunHltTree"     ,fname1.Data());
  zp->AddFriend("tgj",                     fname1.Data());
  
  TH1D* hmass = new TH1D("hmass",";inv. mass (GeV);event fraction",34,30,200);
  hmass->Sumw2();

  zp->Draw("invm>>hmass",addCut && "isEle1==1 && isEle2==1");
  TH1D* htemp = (TH1D*)hsee->Clone("htemp");   htemp->Reset();
  zp->Draw("see1>>htemp",addCut && "isEle1==1 && isEle2==1" && "invm>80 && invm<100" );
  hsee->Reset();
  hsee->Add(htemp);
  handsomeTH1(hmass,2);
  scaleInt(hmass);
  
  TH1D* htempMC;
  TFile *f1mc;
  TTree *zpmc ;
  f1mc=new TFile(fname1MC.Data());
  zpmc = (TTree*)f1mc->Get("tz");
  zpmc->AddFriend("yEvt=yongsunHiEvt"       ,fname1MC.Data());
  zpmc->AddFriend("ySkim=yongsunSkimTree"   ,fname1MC.Data());
  zpmc->AddFriend("yHlt=yongsunHltTree"     ,fname1MC.Data());
  zpmc->AddFriend("yPho=yongsunPhotonTree"     ,fname1MC.Data());
  zpmc->AddFriend("tgj",                     fname1MC.Data());
  hseeMc->Sumw2();
  htempMC = (TH1D*)hseeMc->Clone("htempMc");   htempMC->Reset();
  TH1D* hmassMC = new TH1D("hmassMC11",";inv. mass (GeV);event fraction",34,30,200);
  hmassMC->Sumw2();
  zpmc->Draw("invm>>hmassMC11",Form("(%s) *yPho.ncoll",addCut.GetTitle()));
  zpmc->Draw("see1>>htempMc",Form("(%s) *yPho.ncoll", (addCut && "invm>80 && invm<100").GetTitle()) );
  hseeMc->Reset();
  hseeMc->Add(htempMC);
  handsomeTH1(hmassMC,1);
  scaleInt(hmassMC);
  
  
  hmassMC->SetAxisRange(0,0.6,"Y");
  hmassMC->DrawCopy();
  hmass->DrawCopy("same");                                                                                             
  TLegend* leg1 =  new TLegend(0.5580645,0.5381356,0.8923387,0.7648305,NULL,"brNDC");
  easyLeg(leg1,"Z->ee mass");
  leg1->AddEntry(hmass,"DATA","pl");
  leg1->AddEntry(hmassMC,"MC","pl");
  leg1->Draw();
  
}
示例#2
0
文件: mc2ibd.C 项目: lab305itep/digi
void mc2ibd_NE(TChain *tMC, TFile *fBgnd, TCanvas *cv)
{
	char str[1024];
	TLatex *txt = new TLatex();

	TH1D *hExp = (TH1D *) fBgnd->Get("hNEA-diff");
	if (!hExp) {
		printf("Histogram hNEA-diff not found in %s\n", fBgnd->GetName());
		return;
	}
	hExp->SetTitle("Delayed event energy;MeV;Events/200 keV");
	hExp->SetLineColor(kBlack);
	hExp->SetLineWidth(3);

	gROOT->cd();
	TH1D *hMC = new TH1D("hNEMC", "Delayed event energy (MC);MeV;Events/200 keV", 45, 3, 12);
	hMC->SetLineColor(kBlue);
	tMC->Project(hMC->GetName(), "NeutronEnergy", cX && cY && cZ && cR && c20 && cGamma && cGammaMax && cPe);
	hMC->Sumw2();
	hMC->Scale(hExp->Integral(15, 45) / hMC->Integral(15,45));
	
	cv->Clear();
	hMC->Draw("hist");
	hExp->DrawCopy("same");
	TLegend *lg = new TLegend(0.65, 0.8, 0.89, 0.89);
	lg->AddEntry(hExp, "IBD", "LE");
	lg->AddEntry(hMC, "MC", "L");
	lg->Draw();
}
示例#3
0
文件: mc2ibd.C 项目: lab305itep/digi
void mc2ibd_R2(TChain *tMC, TFile *fBgnd, TCanvas *cv)
{
	char str[1024];
	TLatex *txt = new TLatex();

	TH1D *hExp = (TH1D *) fBgnd->Get("hR2A-diff");
	if (!hExp) {
		printf("Histogram hR2A-diff not found in %s\n", fBgnd->GetName());
		return;
	}
	hExp->SetTitle("Distance between positron and neutron, 3D case;cm;Events/4cm");
	hExp->SetLineColor(kBlack);
	hExp->SetLineWidth(3);

	gROOT->cd();
	TH1D *hMC = new TH1D("hR2MC", "Distance between positron and neutron, 3D case (MC);cm;Events/4cm", 40, 0, 160);
	hMC->SetLineColor(kBlue);
	tMC->Project(hMC->GetName(), "Distance", cX && cY && cZ && cRXY && c20 && cGamma && cGammaMax && cPe && cN);
	hMC->Sumw2();
	hMC->Scale(hExp->Integral() / hMC->Integral());
	
	cv->Clear();
	hExp->DrawCopy();
	hMC->Draw("hist,same");
	TLegend *lg = new TLegend(0.65, 0.8, 0.89, 0.89);
	lg->AddEntry(hExp, "IBD", "LE");
	lg->AddEntry(hMC, "MC", "L");
	lg->Draw();
}
void PlotWriteErrors(TFile* input, TFile* output, TString output_folder, TString canvas, TString Hist, TString Opt="")
{

  // Setup the canvas
  TCanvas *c1= new TCanvas(canvas,canvas,800,700);

  // Get the histograms from the files
  TH1D *Data = (TH1D*)input->Get(Hist);

  //check to make sure there are some events before setting the log scale
  if(Data->Integral() == 0 ) c1->SetLogy(0);
  else  c1->SetLogy(1);

  // Fill for histogram
  Data->SetFillColor(kBlue);
  Data->GetXaxis()->SetTitleSize(0.06);
  Data->GetXaxis()->SetTitleOffset(0.75);
  Data->GetYaxis()->SetTitleSize(0.05);
  Data->GetYaxis()->SetTitleOffset(1.00);

  // plot them
  Data->DrawCopy("hist");

  gPad->RedrawAxis();

  //write canvas as png
  c1->Print(TString(output_folder+canvas+".png"));  

  //write canvas to output file
  output->cd();
  c1->Write();
  return;
}
void DrawHisto(TH1* h_orig, TString name,  Option_t *drawopt){
	TH1D* h = (TH1D*)h_orig->Clone(name);
	TString canvname = "canv_"+name;
	TCanvas *col = new TCanvas(canvname, "", 0, 0, 500, 500);
	col->SetFillStyle(0);
	col->SetFrameFillStyle(0);
	gPad->SetFillStyle(0);
	gStyle->SetPalette(1);
	gPad->SetRightMargin(0.15);
	h->DrawCopy(drawopt);
}
void DrawHisto(TH1* h_orig, TString name,  Option_t *drawopt, Channel* channel){
	TH1D* h = (TH1D*)h_orig->Clone(name);
	TString canvname = "canv_"+name;
	TCanvas *col = new TCanvas(canvname, "", 0, 0, 500, 500);
	col->SetFillStyle(0);
	col->SetFrameFillStyle(0);
	gPad->SetFillStyle(0);
	gStyle->SetPalette(1);
	gPad->SetRightMargin(0.15);
	h->DrawCopy(drawopt);
//	gPad->RedrawAxis();
	if(fSaveResults){
		col->Write();
	}
}
TCanvas* pMenu(std::string what)
{
  TCanvas* c = new TCanvas(("cMenu"+what).c_str(),("cMenu"+what).c_str(),1500,400); 
  c->SetBottomMargin(0.6);
  c->SetLeftMargin(0.04);
  c->SetRightMargin(0.01);
  TH1D* h = (TH1D*)gROOT->FindObject(("hMenuAlgos"+what).c_str());
  h->SetLineColor(4);
  h->SetFillColor(4);
  h->SetFillStyle(3003);
  h->LabelsOption("v");
  h->GetYaxis()->SetLabelOffset(0.005);
//  h->GetXaxis()->SetRange(550,680);
  h->DrawCopy();
  return c;
}
示例#8
0
void PlotErrors(TFile* data, TString Hist, TString Opt="")
{

    // Get the histograms from the files
    TH1D *Data = (TH1D*)data->Get(Hist);

    //check to make sure there are some events for log scale
    if(Data->Integral() == 0 ) c1->SetLogy(0);
    else  c1->SetLogy(1);

    // Fill for histogram
    Data->SetFillColor(kBlue);

    // plot them
    Data->DrawCopy("hist");

    gPad->RedrawAxis();

}
void photonEnergyValidate   (sampleType collision = kHIMC) {
  TH1::SetDefaultSumw2(); 
  
  TFile* f = new TFile("photonEnergyScaleTable_lowPt_v6.root");
  TF1* curve[2][4];  // [ conversion 0 or 1 ] [ centrality bin 1,2,3] 
  for ( int icent = 1 ; icent<=3 ; icent++) {
    curve[0][icent] = (TF1*)f->Get(Form("fit_hscale_r9gt94_%d",icent));   // Not converted
    curve[1][icent] = (TF1*)f->Get(Form("fit_hscale_r9lt94_%d",icent));  // Converted
    curve[1][icent]->SetLineStyle(7);
  }
  TH1D* htemp = new TH1D("htemp",";p_{T}^{#gamma} (GeV); Residual correction",200,35,200);
  
  TCanvas* c1 = new TCanvas("c1","",500,500);

  handsomeTH1(htemp,0);
  htemp->SetAxisRange(0.97,1.12,"Y");
  htemp->DrawCopy();
  
  for (int icent = 1 ;icent<=3 ; icent++) {
    curve[0][icent]->Draw("same");
    curve[1][icent]->Draw("same");
    //    onSun(35,1,200,1);
  }
  TLegend *l0 =  new TLegend(0.4910859,0.5132576,1,0.7102273,NULL,"brNDC");
  easyLeg(l0,"r9 > 0.94 : Not Conv");
  l0->AddEntry(curve[0][1],"0-10%","l");
  l0->AddEntry(curve[0][2],"10-30%","l");
  l0->AddEntry(curve[0][3],"30-100%","l");
  l0->Draw();
  
  TLegend *l1 = new TLegend(0.4910859,0.7443182,1,0.9318182,NULL,"brNDC");
   easyLeg(l1,"r9 < 0.94 : Conv");
  l1->AddEntry(curve[1][1],"0-10%","l");
  l1->AddEntry(curve[1][2],"10-30%","l");
  l1->AddEntry(curve[1][3],"30-100%","l");
  l1->Draw();
  

       

}
示例#10
0
void drawJacob(string fnm="../../output/thinRadiator/o_msc_L001um_03MeV_1e5ev.root"){
  TFile *fin=TFile::Open(fnm.c_str(),"READ");
  TTree *t=(TTree*)fin->Get("t");
  int material, pType, trackID, parentID;
  double pX, pY, pZ;
  
  t->SetBranchAddress("pType", &pType);
  t->SetBranchAddress("material", &material);
  t->SetBranchAddress("trackID", &trackID);
  t->SetBranchAddress("parentID", &parentID);
  t->SetBranchAddress("postMomX", &pX);
  t->SetBranchAddress("postMomY", &pY);
  t->SetBranchAddress("postMomZ", &pZ);

  int nev = t->GetEntries();
  TH1D *scatAng = new TH1D("scatAng","Rate/sin(theta); scattering angle [deg]", 400,0,100);
  double pi = acos(-1);
  cout<<"pi "<<pi<<endl;
  for(int i=0;i<nev;i++){
    t->GetEntry(i);

    if(pType!=11) continue;
    if(material != 1) continue;
    if(trackID != 1 || parentID!=0) continue;

    double r = sqrt( pX*pX + pY*pY + pZ*pZ);
    if(r==0) continue;

    double thetaRad = acos(pZ/r);
    double theta = thetaRad * 180/pi;
    if(theta<0.01) continue;
    
    scatAng->Fill(theta, 1./sin(thetaRad));
    
  }
  gStyle->SetOptStat("eMRou");
  scatAng->DrawCopy();
  fin->Close();
}
示例#11
0
void draw_graphs(void)
{
	const char title[4][20] = {"Na_mean;um", "Na_sigma;um", "Co_mean;um", "Co_sigma;um"};
	const double tgt[4] = {1.787, 0.394, 2.082, 0.473};
	const double mc[4][4] = {{2.008, 1.985, 1.974, 1.933}, {0.319, 0.326, 0.330, 0.336}, 
		{2.233, 2.211, 2.185, 2.149}, {0.377, 0.385, 0.394, 0.405}};
	const double dl[4] = {0, 50, 100, 200};
	const double mm[4][2] = {{1.7, 2.1}, {0.3, 0.4}, {2.0, 2.3}, {0.35, 0.5}};
	TGraph *gr;
	TLine *ln;
	TH1D *h;
	TLegend *lg;
	int i;
	
	TCanvas *cv = new TCanvas;
	cv->Divide(2,2);
	gr = new TGraph;
	ln = new TLine;
	gr->SetMarkerStyle(kFullCircle);
	gr->SetMarkerSize(1.5);
	gr->SetMarkerColor(kBlue);
	ln->SetLineWidth(4);
	ln->SetLineColor(kRed);
	lg = new TLegend(0.65, 0.65, 0.95, 0.85);
	lg->AddEntry(ln, "Exp.", "L");
	lg->AddEntry(gr, "MC", "P");
	for (i=0; i<4; i++) {
		cv->cd(i+1);
		
		h = new TH1D(title[i], title[i], 100, 0, 200);
		h->SetMinimum(mm[i][0]);
		h->SetMaximum(mm[i][1]);
		h->DrawCopy();
		gr->DrawGraph(4, dl, mc[i], "P");
		ln->DrawLine(0, tgt[i], 200, tgt[i]);
		lg->Draw();
		delete h;
	}
}
//*************************************************************************************************
//Main part of the macro
//*************************************************************************************************
void AnalyzeYYPhotonEvent(const string InputFilename) {

  
  TTree* YYTree = getTreeFromFile(InputFilename.c_str());
  assert(YYTree);    
  YYPhotonEvent photon(YYTree);
      
  TH1D *plot = new TH1D("hPlot", ";XAxis; Number of Events ", 6, -3,3);

  for (int n=0;n<YYTree->GetEntries();n++) { 
    photon.GetEntry(n);

    Double_t weight = photon.photon_branch_weight;    
    //cout << weight << " " << photon.photon_branch_NPhotons << endl;
    if (photon.photon_branch_NPhotons > 0 ) {
      plot->Fill(photon.photon_branch_Photon1Eta);
    }

  }

  TCanvas *c = new TCanvas("canvas" , "canvas" , 800, 600);
  plot->DrawCopy();
  
}
示例#13
0
void chipSummary(const char *dirName, int chipId)
{
        directory = TString(dirName);
	
	if (f && f->IsOpen()) f->Close();
	if (f1 && f1->IsOpen()) f1->Close();
	if (g && g->IsOpen()) g->Close();

	gROOT->SetStyle("Plain");
	gStyle->SetPalette(1);
	gStyle->SetOptStat(0);
	gStyle->SetTitle(0);

	gStyle->SetStatFont(132);
	gStyle->SetTextFont(132);
	gStyle->SetLabelFont(132, "X");
	gStyle->SetLabelFont(132, "Y");
	gStyle->SetLabelSize(0.08, "X");
	gStyle->SetLabelSize(0.08, "Y");
	gStyle->SetNdivisions(6, "X");
	gStyle->SetNdivisions(8, "Y");
	gStyle->SetTitleFont(132);

	gROOT->ForceStyle();

	tl = new TLatex;
	tl->SetNDC(kTRUE);
	tl->SetTextSize(0.09);

	ts = new TLatex;
	ts->SetNDC(kTRUE);
	ts->SetTextSize(0.08);

	line = new TLine;
	line->SetLineColor(kRed);
	line->SetLineStyle(kSolid);
	
	box = new TBox;
	box->SetFillColor(kRed);
	box->SetFillStyle(3002);

	f = new TFile(Form("%s/%s", dirName, fileName), "READ");
	
	if (strcmp(fileName, adFileName) == 0) f1 = f;
	else f1 = new TFile(Form("%s/%s", dirName, adFileName), "READ");
	
	if (strcmp(fileName, trimFileName) == 0) g = f;
	else g = new TFile(Form("%s/%s", dirName, trimFileName), "READ");
 
	sprintf(fname, "%s/../../macros/criteria-full.dat", dirName);
	if ( !readCriteria(fname) ) { 
	  
	  printf("\nchipSummary> ----> COULD NOT READ GRADING CRITERIA !!!");
	  printf("chipSummary> ----> Aborting execution of chipgSummaryPage.C ... \n\n", fileName, dirName);  
	  break;
	}

	TH1D *h1;
	TH2D *h2;

	c1 = new TCanvas("c1", "", 800, 800);
	c1->Clear();
	c1->Divide(4,4, 0.01, 0.04);

  //	shrinkPad(0.1, 0.1, 0.1, 0.3);

	FILE *sCurveFile, *phLinearFile, *phTanhFile;

        TString noslash(dirName);
        noslash.ReplaceAll("/", " ");
        noslash.ReplaceAll(".. ", "");
	
	char string[200];
	int pixel_alive;

	int nDeadPixel(0);
	int nIneffPixel(0);
	int nMaskDefect(0);
	int nNoisy1Pixel(0);
	int nDeadBumps(0);
	int nDeadTrimbits(0);
	int nAddressProblems(0);

	int nNoisy2Pixel(0);
	int nThrDefect(0);
	int nGainDefect(0);
	int nPedDefect(0);
	int nPar1Defect(0);

	int nRootFileProblems(0);

	int nDoubleFunctCounts(0);
	int nDoublePerfCounts(0);
	int nDoubleCounts(0);
	int nDoubleTrims(0);
	int nDoublePHs(0);

        int vcal = dac_findParameter(dirName, "Vcal", chipId);
	
	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	// Row 1
	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	// -- Dead pixels
	c1->cd(1);

	TH2D *hpm;
	hpm = (TH2D*)f->Get(Form("PixelMap_C%i", chipId));

        if (hpm) {

	  for (int icol = 0; icol < 52; ++icol) {
	    for (int irow = 0; irow < 80; ++irow) {      
	      
	      hpm->SetTitle("");
	      hpm->Draw("colz");
	      tl->DrawLatex(0.1, 0.92, "Pixel Map");
	    }
	  }

	} else { 
	  
	  ++nRootFileProblems; 
	}


	// -- sCurve width and noise level
	TH1D *hw = new TH1D("hw", "", 100, 0., 600.);
	TH1D *hd = new TH1D("hd", "", 100, 0., 600.);  // Noise in unbonded pixel (not displayed)
	TH2D *ht = new TH2D("ht", "", 52, 0., 52., 80, 0., 80.);
	TH1D *htmp;

	float mN(0.), sN(0.), nN(0.), nN_entries(0.);
	int over(0), under(0);

	double htmax(255.), htmin(0.);
	
	float thr, sig;
	int a,b;

	double minThrDiff(-5.);
	double maxThrDiff(5.);

	h2 = (TH2D*)f->Get(Form("vcals_xtalk_C%i", chipId));
        
	sprintf(string, "%s/SCurve_C%i.dat", dirName, chipId);
	sCurveFile = fopen(string, "r");

	if (!sCurveFile) {

	  printf("chipSummary> !!!!!!!!!  ----> SCurve: Could not open file %s to read fit results\n", string);
	
	} else {
	  
	  for (int i = 0; i < 2; i++) fgets(string, 200, sCurveFile);
	  
	  for (int icol = 0; icol < 52; ++icol)	{
	    for (int irow = 0; irow < 80; ++irow) {
	      
	      fscanf(sCurveFile, "%e %e %s %2i %2i", &thr, &sig, string, &a, &b);
	      //  				printf("chipSummary> sig %e thr %e\n", sig, thr);
	      
	      hw->Fill(sig);
	      thr = thr / 65.;
	      
	      ht->SetBinContent(icol+1, irow+1, thr); 
	      
	      if ( h2 ) {
		if( h2->GetBinContent(icol+1, irow+1)  >= minThrDiff) {
		  
		  hd->Fill(sig);
		}
	      }
	    }
	  }
	  
	  fclose(sCurveFile);

	  c1->cd(2);
	  hw->Draw();
	  tl->DrawLatex(0.1, 0.92, "S-Curve widths: Noise (e^{-})");
	  
	  
	  /*		c1->cd(15);
			hd->SetLineColor(kRed);
			hd->Draw();
			tl->DrawLatex(0.1, 0.92, "S-Curve widths of dead bumps");
			if ( hd->GetEntries() > 0 ) {
			ts->DrawLatex(0.55, 0.82, Form("entries: %4.0f", hd->GetEntries()));
			ts->DrawLatex(0.55, 0.74, Form("#mu:%4.2f", hd->GetMean()));
			ts->DrawLatex(0.55, 0.66, Form("#sigma: %4.2f", hd->GetRMS()));
			}
	  */
	  
	  mN =  hw->GetMean();
	  sN =  hw->GetRMS();
	  nN =  hw->Integral(hw->GetXaxis()->GetFirst(), hw->GetXaxis()->GetLast());
	  nN_entries =  hw->GetEntries();
	  
	  under = hw->GetBinContent(0);
	  over  = hw->GetBinContent(hw->GetNbinsX()+1);
	  
	  
	  ts->DrawLatex(0.65, 0.82, Form("N: %4.0f", nN));
	  ts->DrawLatex(0.65, 0.74, Form("#mu: %4.1f", mN));
	  ts->DrawLatex(0.65, 0.66, Form("#sigma: %4.1f", sN));
	  
	  if ( under ) ts->DrawLatex(0.15, 0.55, Form("<= %i", under));			               
	  if ( over  ) ts->DrawLatex(0.75, 0.55, Form("%i =>", over ));
	  
	  c1->cd(3);
	  if ( ht->GetMaximum() < htmax ) { 
	    htmax = ht->GetMaximum();
	  }
	  if ( ht->GetMinimum() > htmin ) {
	    htmin = ht->GetMinimum();
	  }
	  ht->GetZaxis()->SetRangeUser(htmin,htmax);
	  ht->Draw("colz");
	  tl->DrawLatex(0.1, 0.92, "Vcal Threshold Untrimmed");
	  
	}
	
	// -- Noise level map
	c1->cd(4);
        gPad->SetLogy(1);
 	gStyle->SetOptStat(1);

	float mV(0.), sV(0.), nV(0.), nV_entries(0.);
	over = 0.; under = 0.;

	if (!g->IsZombie())
	{
	      h1 = (TH1D*)g->Get(Form("VcalThresholdMap_C%iDistribution;7", chipId));
              if (h1) {
		h1->SetTitle("");
		h1->SetAxisRange(0., 100.);
		h1->Draw();

		mV = h1->GetMean();
		sV = h1->GetRMS();
		nV = h1->Integral(h1->GetXaxis()->GetFirst(), h1->GetXaxis()->GetLast());
		nV_entries = h1->GetEntries();

		under = h1->GetBinContent(0);
		over  = h1->GetBinContent(h1->GetNbinsX()+1);
              }
              else {

	        ++nRootFileProblems;
		mV = 0.;
		sV = 0.;
               
              }

	      ts->DrawLatex(0.15, 0.82, Form("N: %4.0f", nV));
	      ts->DrawLatex(0.15, 0.74, Form("#mu: %4.1f", mV));
	      ts->DrawLatex(0.15, 0.66, Form("#sigma: %4.1f", sV));
	      
	      if ( under ) ts->DrawLatex(0.15, 0.55, Form("<= %i", under));			               
	      if ( over  ) ts->DrawLatex(0.75, 0.55, Form("%i =>", over ));
	}

	tl->DrawLatex(0.1, 0.92, "Vcal Threshold Trimmed");

	
	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	// Row 2
	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	// -- Bump Map
	TH2D *hbm;

	c1->cd(5);
	gStyle->SetOptStat(0);
	hbm = (TH2D*)f->Get(Form("vcals_xtalk_C%i", chipId));
        
        if (hbm) {

	  h2->SetTitle("");
	  h2->GetZaxis()->SetRangeUser(minThrDiff, maxThrDiff);
	  h2->Draw("colz");
	  tl->DrawLatex(0.1, 0.92, "Bump Bonding Problems");
	}

	else { ++nRootFileProblems; }

	// -- Bump Map
	c1->cd(6);  
	gPad->SetLogy(1);
	//gStyle->SetOptStat(1);
	h1 = (TH1D*)f->Get(Form("vcals_xtalk_C%iDistribution", chipId));

        if (h1) {
  	  h1->SetTitle("");
	  h1->GetXaxis()->SetRangeUser(-50., 50.);
	  h1->GetYaxis()->SetRangeUser(0.5, 5.0*h1->GetMaximum());
	  h1->DrawCopy();
	  tl->DrawLatex(0.1, 0.92, "Bump Bonding");
	
	} else { 
	  
	  ++nRootFileProblems; 
	}
	
	// -- Trim bits
	int trimbitbins(3);
	c1->cd(7); 
	gPad->SetLogy(1);
	h1 = (TH1D*)f->Get(Form("TrimBit14_C%i", chipId));
	if (h1) {
	  h1->SetTitle("");
	  h1->SetAxisRange(0., 60.);
	  h1->SetMinimum(0.5);
	  h1->Draw("");
	  tl->DrawLatex(0.1, 0.92, "Trim Bit Test");          
	}
	else { ++nRootFileProblems; }

	h1 = (TH1D*)f->Get(Form("TrimBit13_C%i", chipId));
	if (h1) {
	  h1->SetLineColor(kRed);
	  h1->Draw("same");
	}
	else { ++nRootFileProblems; }

	h1 = (TH1D*)f->Get(Form("TrimBit11_C%i", chipId));
	if (h1) {
	  h1->SetLineColor(kBlue);
	  h1->Draw("same");
	}
	else { ++nRootFileProblems; }

	h1 = (TH1D*)f->Get(Form("TrimBit7_C%i", chipId));
	if (h1) {
	  h1->SetLineColor(kGreen);
	  h1->Draw("same");
	}	
	else { ++nRootFileProblems; }
	
	// -- For numerics and titels see at end


	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	// Row 3
	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	// -- Address decoding	
	// --------------------

	TH2D *ham;
	ham = (TH2D*)f1->Get(Form("AddressDecoding_C%i", chipId));

	c1->cd(9);
	gStyle->SetOptStat(0);
        if (ham) {

	  ham->SetTitle("");
	  ham->Draw("colz");
	  tl->DrawLatex(0.1, 0.92, "Address decoding");
	}

	else { ++nRootFileProblems; }

	// -- Address levels

	c1->cd(10); 
	gPad->SetLogy(1);
	h1 = (TH1D*)f1->Get(Form("AddressLevels_C%i", chipId));
        if (h1) {
	  h1->SetTitle("");
	  h1->SetAxisRange(-1500., 1500.);
	  h1->Draw();
	  tl->DrawLatex(0.1, 0.92, "Address Levels");
	
	} else { 
	  
	  ++nRootFileProblems; 
	}


	// -- PHCalibration: Linear Fit (Gain & Pedesdtal)
	// -----------------------------------------------

	TH1D *hg = new TH1D("hg", "", 300, -2.0, 5.5);
	TH2D *hgm = new TH2D("hgm", "", 52, 0., 52., 80, 0., 80.);
	
	TH1D *hp = new TH1D("hp", "", 900, -300., 600.);
	hp->StatOverflows(kTRUE);

	TH1D *rp = new TH1D("rp", "", 900, -300., 600.);
	rp->StatOverflows(kFALSE);

	TH1D *htmp;

	float par0, par1, par2, par3, par4, par5; // Parameters of Vcal vs. Pulse Height Fit

	float mG(0.), sG(0.), nG(0.), nG_entries(0.);
	float mP(0.), sP(0.), nP(0.), nP_entries(0.); 
	over = 0.; under = 0.;

	float ped, gain;
	int a,b;
	
	int mPbin(0), xlow(-100), xup(255), extra(0);       // for restricted RMS
	float pedMin(0), pedMax(1000);
	double integral(0.);

	sprintf(string, "%s/phCalibrationFit_C%i.dat", dirName, chipId);
	phLinearFile = fopen(string, "r");

	if (!phLinearFile) {
	  
	  printf("chipSummary> !!!!!!!!!  ----> phCal: Could not open file %s to read fit results\n", string);
	
	} else {
		
	  for (int i = 0; i < 2; i++) fgets(string, 200, phLinearFile);
	  
	  for (int icol = 0; icol < 52; ++icol)	{
	    for (int irow = 0; irow < 80; ++irow) {
	      fscanf(phLinearFile, "%e %e %e %e %e %e %s %2i %2i", 
		     &par0, &par1, &par2, &par3, &par4, &par5, string, &a, &b);
	      
	      if (par2 != 0.)  {  // dead pixels have par2 == 0.
		
		gain = 1./par2;
		ped = par3;
		hp->Fill(ped);
		hg->Fill(gain);
		hgm->SetBinContent(icol + 1, irow + 1, gain);
	      }
	    }
	  }
	  
	  fclose(phLinearFile);
	  

	  // -- Gain

	  c1->cd(11);

	  mG =  hg->GetMean();
	  sG =  hg->GetRMS();
	  nG =  hg->Integral(hg->GetXaxis()->GetFirst(), hg->GetXaxis()->GetLast());
	  nG_entries = hg->GetEntries();
	  
	  under = hg->GetBinContent(0);
	  over  = hg->GetBinContent(hp->GetNbinsX()+1);
	  	  
	  gPad->SetLogy(1);
	  hg->GetYaxis()->SetRangeUser(0.5, 5.0*hg->GetMaximum());
	  hg->Draw();
	  tl->DrawLatex(0.1, 0.92, "PH Calibration: Gain (ADC/DAC)");
	  
	  if ( hg->GetMean() > 1.75 ) {

	    ts->DrawLatex(0.15, 0.80, Form("N: %4.0f", nG));
	    ts->DrawLatex(0.15, 0.72, Form("#mu: %4.2f", mG));
	    ts->DrawLatex(0.15, 0.64, Form("#sigma: %4.2f", sG));

	  } else {

	    ts->DrawLatex(0.65, 0.80, Form("N: %4.0f", nG));
	    ts->DrawLatex(0.65, 0.72, Form("#mu: %4.2f", mG));
	    ts->DrawLatex(0.65, 0.64, Form("#sigma: %4.2f", sG));
	  }
	  
	    
	  if ( under ) ts->DrawLatex(0.15, 0.55, Form("<= %i", under));			               
	  if ( over  ) ts->DrawLatex(0.75, 0.55, Form("%i =>", over ));
	  
	  c1->cd(15);

	  hgm->Draw("colz");
	  tl->DrawLatex(0.1, 0.92, "PH Calibration: Gain (ADC/DAC)");

	  // -- Pedestal

	  c1->cd(12);

	  mP =  hp->GetMean();
	  sP =  hp->GetRMS();
	  nP =  hp->Integral(hp->GetXaxis()->GetFirst(), hp->GetXaxis()->GetLast());
	  nP_entries = hp->GetEntries();
	  
	  if ( nP > 0 ) {
	    
	    // -- restricted RMS
	    integral = 0.;
	    mPbin = -1000; xlow = -1000; xup = 1000;
	    over = 0.; under = 0.;
	    
	    mPbin = hp->GetXaxis()->FindBin(mP);
	    
	    for (int i = 0; integral <  pedDistr; i++) { 
		    
	      xlow = mPbin-i;
	      xup =  mPbin+i;
	      integral = hp->Integral(xlow, xup)/nP;
		    
	    }
		  
	    extra = xup - xlow;
	  }
	  else {

	    xlow = -300; xup = 600; extra = 0;
	    over = 0.; under = 0.;
	  }

  	  under = hp->Integral(0, xlow - extra);
  	  over  = hp->Integral(xup + 1.5*extra, hp->GetNbinsX());
		  
	  hp->GetXaxis()->SetRange(xlow - extra, xup + 1.5*extra);

	  nP    = hp->Integral(hp->GetXaxis()->GetFirst(), hp->GetXaxis()->GetLast());

	  pedMin = hp->GetBinCenter(xlow-extra);
	  pedMax = hp->GetBinCenter(xup+1.5*extra);


	  cout<< " ========> Ped min  " << pedMin << " Ped max " << pedMax 
	      << ", over: " << over << " under: " << under << endl;		

	  hp->DrawCopy();

	  rp->Add(hp);
	  rp->GetXaxis()->SetRange(xlow, xup);

	  mP =  rp->GetMean();
	  sP =  rp->GetRMS();

	  // box->DrawBox( rp->GetBinCenter(xlow), 0, rp->GetBinCenter(xup), 1.05*rp->GetMaximum());
	  rp->SetFillColor(kRed);
	  rp->SetFillStyle(3002);
	  rp->Draw("same");
	  line->DrawLine(rp->GetBinCenter(xlow), 0, rp->GetBinCenter(xlow), 0.6*rp->GetMaximum());
	  line->DrawLine(rp->GetBinCenter(xup),  0, rp->GetBinCenter(xup),  0.6*rp->GetMaximum());
	 
	  tl->DrawLatex(0.1, 0.92, "PH Calibration: Pedestal (DAC)");
		
	  if ( hp->GetMean() < 126. ) {

	    ts->DrawLatex(0.65, 0.82, Form("N: %4.0f", nP));
	    ts->SetTextColor(kRed);
	    ts->DrawLatex(0.65, 0.74, Form("#mu: %4.1f", mP));
	    ts->DrawLatex(0.65, 0.66, Form("#sigma: %4.1f", sP));
				
	  } else {

	    ts->DrawLatex(0.16, 0.82, Form("N: %4.0f", nP));
	    ts->SetTextColor(kRed);
	    ts->DrawLatex(0.16, 0.74, Form("#mu: %4.1f", mP));
	    ts->DrawLatex(0.16, 0.66, Form("#sigma: %4.1f", sP));
	  }

	  if ( under ) ts->DrawLatex(0.15, 0.55, Form("<= %i", under));			               
	  if ( over  ) ts->DrawLatex(0.75, 0.55, Form("%i =>", over ));
	  ts->SetTextColor(kBlack);
	  

		
	}

	
	// -- PHCalibration: Tanh Fit (Parameter1)
	// ----------------------------------------
	
	c1->cd(11);

	over = 0.; under = 0.;

	float nPar1(0.), nPar1_entries(0.), mPar1(0.), sPar1(0.);
	
        TH1D *hPar1 = new TH1D("par1", "", 350, -1., 6.);

	sprintf(string, "%s/phCalibrationFitTan_C%i.dat", dirName, chipId);
	phTanhFile = fopen(string, "r");
	
	if (!phTanhFile) {
	  
	  printf("chipSummary> !!!!!!!!!  ----> phCal: Could not open file %s to read fit results\n", string);
	
	} else {
	  
	  for (int i = 0; i < 2; i++) fgets(string, 200, phTanhFile);
	  
	  for (int icol = 0; icol < 52; ++icol) {
	    for (int irow = 0; irow < 80; ++irow) {
	      
	      fscanf(phTanhFile, "%e %e %e %e %s %2i %2i", &par0, &par1, &par2, &par3, string, &a, &b);		
	      hPar1->Fill(par1);
	    }
	  }
	  
	  fclose(phTanhFile);	


	  // -- Parameter 1

	  hPar1->SetLineColor(kBlue);
	  hPar1->Draw("same");
	  
	  mPar1 =  hPar1->GetMean();
	  sPar1 =  hPar1->GetRMS();
	  nPar1 =  hPar1->Integral(hPar1->GetXaxis()->GetFirst(), hPar1->GetXaxis()->GetLast());	
	  nPar1_entries = hPar1->GetEntries();
	  
	  under = hPar1->GetBinContent(0);
	  over  = hPar1->GetBinContent(hPar1->GetNbinsX()+1);
	  
	  ts->SetTextColor(kBlue);
	  
	  if ( hg->GetMean() > 1.75 ) {
	  
	    ts->DrawLatex(0.15, 0.40, "Par1:");
	    ts->DrawLatex(0.15, 0.30, Form("N: %4.0f", nPar1));
	    ts->DrawLatex(0.15, 0.22, Form("#mu: %4.2f", mPar1));
	    ts->DrawLatex(0.15, 0.14, Form("#sigma: %4.2f", sPar1));
	  
	  } else {

	    ts->DrawLatex(0.65, 0.40, "Par1:");
	    ts->DrawLatex(0.65, 0.30, Form("N: %4.0f", nPar1));
	    ts->DrawLatex(0.65, 0.22, Form("#mu: %4.2f", mPar1));
	    ts->DrawLatex(0.65, 0.14, Form("#sigma: %4.2f", sPar1));
	  }
	  
	    
	  if ( under ) ts->DrawLatex(0.15, 0.48, Form("<= %i", under));			               
	  if ( over  ) ts->DrawLatex(0.75, 0.48, Form("%i =>", over ));
	  ts->SetTextColor(kBlack);
	}



	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	// Row 4
	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	
	// Trim Bits
	// ----------

	TH2D *htm = new TH2D("htm", "", 80, 0., 80., 52, 0., 52.);

	c1->cd(13);
	
	gStyle->SetOptStat(0);
	h2 = (TH2D*)f->Get(Form("TrimMap_C%i;8", chipId));

        if (h2) {
	  for (int icol = 0; icol < 52; ++icol) {
	    for (int irow = 0; irow < 80; ++irow) {
	      
	      htm->SetBinContent(irow+1, icol+1, h2->GetBinContent(icol+1, irow+1));
	    }
	  }
  	  h2->SetTitle("");
	  h2->GetZaxis()->SetRangeUser(0., 16.);
	  h2->Draw("colz");
	}

	else { ++nRootFileProblems; }

	tl->DrawLatex(0.1, 0.92, "Trim Bits");


	FILE *tCalFile;
	sprintf(string, "%s/../T-calibration/TemperatureCalibration_C%i.dat", dirName, chipId);
	tCalFile = fopen(string, "r");
	char tCalDir[200];
	sprintf(tCalDir, "%s/../T-calibration", dirName);

	if ( tCalFile ) {
	
	  analyse(tCalDir, chipId);
	}
	else {

	  c1->cd(14);
	  TGraph *graph = (TGraph*)f->Get(Form("TempCalibration_C%i", chipId));
	  if ( graph ) { graph->Draw("A*"); }
	  else { ++nRootFileProblems; }
	  tl->DrawLatex(0.1, 0.92, "Temperature calibration");
	}



	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	// -- Count defects and double counting
	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	float fl0, fl1, fl2, fl3, fl4, fl5, tmp;
	int   i1, i2;
	char hname[200];

//  	TH2D *get = 0, *hget = 0, *htb0 = 0, *htb1 = 0, *htb2 = 0, *htb3 = 0, *htb4 = 0;

//  	for (int i = 1; i < 6; ++i) {
	  
//  	  get = (TH2D*)f->Get(Form("CalThresholdMap_C%i;%i", chipId, i));

//  	  if (get) {
//  	    hget = (TH2D*)get->Clone();
//  	    hget->SetName(Form("TB0C%i", i));

//  	    if (i == 1) htb0 = hget;
//  	    if (i == 2) htb1 = hget;
//  	    if (i == 3) htb2 = hget;
//  	    if (i == 4) htb3 = hget;
//  	    if (i == 5) htb4 = hget;

//  	  }
//  	}


 	TH2D *htb[5];
 	for (int i = 0; i < 5; ++i) {

 	  htb[i] = (TH2D*)f->Get(Form("CalThresholdMap_C%i;%i", chipId, i+1));
	  htb[i]->SetName(Form("tbC%i%i", chipId, i+1));
 	}

	TH2D *htthr = 0;
 	htthr = (TH2D*)f->Get(Form("VcalThresholdMap_C%d;8", chipId));

	sprintf(string, "%s/SCurve_C%i.dat", dirName, chipId);
	sCurveFile = fopen(string, "r");

	sprintf(string, "%s/phCalibrationFit_C%i.dat", dirName, chipId);
	phLinearFile = fopen(string, "r");
	
	sprintf(string, "%s/phCalibrationFitTan_C%i.dat", dirName, chipId);
	phTanhFile = fopen(string, "r");
	
	if (sCurveFile)   for (int i = 0; i < 2; i++) fgets(string, 200, sCurveFile);
	if (phLinearFile) for (int i = 0; i < 2; i++) fgets(string, 200, phLinearFile);
	if (phTanhFile)   for (int i = 0; i < 2; i++) fgets(string, 200, phTanhFile);

	int px_counted    = 0;
	int px_funct_counted    = 0;
	int px_perf_counted    = 0;
	int trim_counted    = 0;
	int ph_counted    = 0;
	float tb_diff = 0;
	float tb, tb0;
	    
	for (int icol = 0; icol < 52; ++icol) {
	  for (int irow = 0; irow < 80; ++irow) {
	    
	    pixel_alive   = 1;
	    px_funct_counted = 0;
	    px_perf_counted = 0;
	    px_counted = 0;

	    trim_counted = 0;
	    ph_counted = 0;
	    
	    // -- Pixel alive
	    if (hpm && hpm->GetBinContent(icol+1, irow+1)  == 0)  { 
	      
	      pixel_alive = 0; 
	      
	      ++nDeadPixel;   
	      cout << Form("chipSummary> dead pixel %3d %3d: %7.5f", 
			   icol, irow, hpm->GetBinContent(icol+1, irow+1)) << endl;
	    }

	    if (hpm && hpm->GetBinContent(icol+1,irow+1)  > 10) { ++nNoisy1Pixel; px_counted = 1; px_funct_counted = 1;}
	    if (hpm && hpm->GetBinContent(icol+1, irow+1)  < 0) { ++nMaskDefect;  px_counted = 1; px_funct_counted = 1;}

	    if (hpm && (hpm->GetBinContent(icol+1, irow+1) < 10) 
		  && (hpm->GetBinContent(icol+1, irow+1) > 0) ) { ++nIneffPixel;  px_counted = 1; px_funct_counted = 1;}
	    
	    
	    // -- Bump bonding
	    if ( pixel_alive && hbm ) {
	      if ( hbm->GetBinContent(icol+1, irow+1)  >= minThrDiff ) {

		if ( px_counted )      nDoubleCounts++;
		px_counted = 1;

		if ( px_funct_counted ) nDoubleFunctCounts++;
		px_funct_counted = 1;
		
		++nDeadBumps;	
		
		cout << Form("chipSummary> bump defect %3d %3d: %7.5f", 
			     icol, irow, hbm->GetBinContent(icol+1, irow+1)) << endl;
	      }
	    }
	    
	    
	    // -- Trim bits 1 - 4
	    if ( pixel_alive && htb[0] ) {

	      tb0 = htb[0]->GetBinContent(icol+1, irow+1);
	      
	      for ( int i = 1; i <= 4; i++ ) {

		if ( htb[i] ) {
		  
		  tb = htb[i]->GetBinContent(icol+1, irow+1);

		  tb_diff = TMath::Abs(tb-tb0);

		  if (tb_diff  <= 2) {
		    
		    if ( px_counted ) nDoubleCounts++;
		    px_counted = 1;
		    
		    if ( px_funct_counted ) nDoubleFunctCounts++;
		    px_funct_counted = 1;
		    
		    if ( trim_counted ) nDoubleTrims++;
		    trim_counted = 1;
		    
		    ++nDeadTrimbits;
		    
		    cout << Form("chipSummary> trim bit defect %3d %3d: %4.2f", icol, irow, tb_diff) << endl;
		  }
		}
	      }
	    }

	    // -- Address decoding
	    if (pixel_alive && ham) {

	      if( ham->GetBinContent(icol+1, irow+1) < 1 ) {

		if ( px_counted ) nDoubleCounts++;
		px_counted = 1;
		    
		if ( px_funct_counted ) nDoubleFunctCounts++;
		px_funct_counted = 1;

		++nAddressProblems;

		cout << Form("chipSummary> address problem %3d %3d: %7.5f", 
			     icol, irow, ham->GetBinContent(icol+1, irow+1)) << endl;
	      }
	    }
	    
	    // -- Threshold
	    if (pixel_alive && htthr) {

	      if ( TMath::Abs(htthr->GetBinContent(icol+1, irow+1) - vcalTrim) > tthrTol ) {

		if ( px_counted ) nDoubleCounts++;
		px_counted = 1;
		    
		if ( px_perf_counted ) nDoublePerfCounts++;
		px_perf_counted = 1;

		++nThrDefect;

		cout << Form("chipSummary> threshold problem %3d %3d: %7.5f", 
			     icol, irow, htthr->GetBinContent(icol+1, irow+1)) << endl;
	      }
	    }

	    // -- Noise
	    fscanf(sCurveFile, "%e %e %s %2i %2i", &fl1, &fl2, string, &i1, &i2);

	    if (pixel_alive) {
	      if ( (fl2 < noiseMin) 
		   || (fl2 > noiseMax) ) {
		
		if ( px_counted ) nDoubleCounts++;
		px_counted = 1;
		    
		if ( px_perf_counted ) nDoublePerfCounts++;
		px_perf_counted = 1;
		
		++nNoisy2Pixel; 

		cout << Form("chipSummary> noise defect %3d %3d: %7.5f (%2i %2i)", 
			     icol, irow, fl2, i1, i2) << endl;
	      } 
	    }
	    
	    // -- Gain & Pedestal
	    fscanf(phLinearFile, "%e %e %e %e %e %e %s %2i %2i", 
		   &fl0, &fl1, &fl2, &fl3, &fl4, &fl5, string, &i1, &i2);

	    if (pixel_alive) {
	      
	      if (fl2 != 0) gain = 1./fl2;
	      ped = fl3;

	      if ( (gain < gainMin) || (gain > gainMax) ) {
		
		if ( px_counted ) nDoubleCounts++;
		px_counted = 1;
		    
		if ( px_perf_counted ) nDoublePerfCounts++;
		px_perf_counted = 1;

		if ( ph_counted ) nDoublePHs++;
		ph_counted = 1;

		++nGainDefect;

		cout << Form("chipSummary> gain defect %3d %3d: %7.5f (%2i %2i)", 
			     icol, irow, gain, i1, i2) << endl;
	      }

	      if ( (ped < pedMin) 
		   || (ped > pedMax) ) {
		
		if ( px_counted ) nDoubleCounts++;
		px_counted = 1;

		if ( px_perf_counted ) nDoublePerfCounts++;
		px_perf_counted = 1;

		if ( ph_counted ) nDoublePHs++;
		ph_counted = 1;

		++nPedDefect;

		cout << Form("chipSummary> pedestal defect %3d %3d: %7.5f (%2i %2i)", 
			     icol, irow, ped, i1, i2) << endl;
	      }
		
	      
	    }
	    

	    // -- Par1
	    fscanf(phTanhFile, "%e %e %e %e %s %2i %2i", 
		   &fl0, &fl1, &fl2, &fl3, string, &i1, &i2);
	    
	    if (pixel_alive && phTanhFile) {
	      
	      if ( (fl1 < par1Min) 
		   || (fl1 > par1Max) ) {
		
		if ( px_counted ) nDoubleCounts++;
		px_counted = 1;

		if ( px_perf_counted ) nDoublePerfCounts++;
		px_perf_counted = 1;

		if ( ph_counted ) nDoublePHs++;
		ph_counted = 1;

		++nPar1Defect;

		cout << Form("chipSummary> par1 defect %3d %3d: %7.5f (%2i %2i)", 
			     icol, irow, par1, i1, i2) << endl;
	      }
	    }
	    
	  }
	}
			
	fclose(sCurveFile); 
	fclose(phLinearFile);
	fclose(phTanhFile);
	      

	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	// Numerics and Titles
	// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	// -- Compute the final verdict on this chip  //?? FIXME (below is pure randomness)
	float finalVerdict(0);
	if (nDeadTrimbits > 0)    finalVerdict += 1;
	if (nDeadPixel > 0)       finalVerdict += 10;
	if (nNoisy1Pixel > 0)     finalVerdict += 10;
	if (nAddressProblems > 0) finalVerdict += 10;
	if (nDeadBumps > 0)       finalVerdict += 100;
	if (nNoisy2Pixel > 0)     finalVerdict += 1000;
	if (nThrDefect > 0)       finalVerdict += 10000;
	if (nGainDefect > 0)      finalVerdict += 100000;
	if (nPedDefect > 0)       finalVerdict += 100000;
	if (nPar1Defect > 0)      finalVerdict += 100000;

	// -- Defects
	c1->cd(8);
	tl->SetTextSize(0.10);
	tl->SetTextFont(22);
	double y = 0.98;

	y -= 0.11;
	tl->DrawLatex(0.1, y, "Summary");
// 	tl->DrawLatex(0.6, y, Form("%06d", finalVerdict));

	tl->SetTextFont(132);
	tl->SetTextSize(0.09);
	y -= 0.11;
	tl->DrawLatex(0.1, y, Form("Dead Pixels: "));
	tl->DrawLatex(0.7, y, Form("%4d", nDeadPixel));

// 	y -= 0.10;
// 	tl->DrawLatex(0.1, y, Form("Noisy Pixels 1: "));
// 	tl->DrawLatex(0.7, y, Form("%4d", nNoisy1Pixel));
	
	y -= 0.10;
	tl->DrawLatex(0.1, y, "Mask defects: ");
	tl->DrawLatex(0.7, y, Form("%4d", nMaskDefect));

	y -= 0.10;
	tl->DrawLatex(0.1, y, "Dead Bumps: ");
	tl->DrawLatex(0.7, y, Form("%4d", nDeadBumps));

	y -= 0.10;
	tl->DrawLatex(0.1, y, "Dead Trimbits: ");
	tl->DrawLatex(0.7, y, Form("%4d", nDeadTrimbits));

	y -= 0.10;
	tl->DrawLatex(0.1, y, "Address Probl: ");
	tl->DrawLatex(0.7, y, Form("%4d", nAddressProblems));

	y -= 0.10;
	tl->DrawLatex(0.1, y, Form("Noisy Pixels 2: "));
	tl->DrawLatex(0.7, y, Form("%4d", nNoisy2Pixel));

	y -= 0.10;
	tl->DrawLatex(0.1, y, Form("Trim Probl.: "));
	tl->DrawLatex(0.7, y, Form("%4d", nThrDefect));

	y -= 0.10;
	tl->DrawLatex(0.1, y, Form("PH defects: "));
	tl->DrawLatex(0.5, y, Form("%4d/", nGainDefect));

	tl->SetTextColor(kRed);
	tl->DrawLatex(0.6, y, Form("%4d/",nPedDefect));
	tl->SetTextColor(kBlack);

	tl->SetTextColor(kBlue);
	tl->DrawLatex(0.7, y, Form("%4d",nPar1Defect));
	tl->SetTextColor(kBlack);

// 	y -= 0.10;
// 	tl->DrawLatex(0.1, y, Form("Par1 defect: "));
// 	tl->DrawLatex(0.7, y, Form("%4d", nPar1Defect));


	// -- Operation Parameters
	c1->cd(16);
	
	y = 0.92;
	tl->SetTextSize(0.10);
	tl->SetTextFont(22);
	y -= 0.11;
	tl->DrawLatex(0.1, y, Form("Op. Parameters"));

	tl->SetTextFont(132);
	tl->SetTextSize(0.09);

	y -= 0.11;
	int vana(-1.);
        vana = dac_findParameter(dirName, "Vana", chipId);
	tl->DrawLatex(0.1, y, "VANA: ");
	if (vana >= 0.) tl->DrawLatex(0.6, y, Form("%3i DAC", vana));
	else tl->DrawLatex(0.7, y, "N/A");

	y -= 0.10;
	int caldel(-1.);
        caldel = dac_findParameter(dirName, "CalDel", chipId);
	tl->DrawLatex(0.1, y, "CALDEL: ");
	if (vana >= 0.) tl->DrawLatex(0.6, y, Form("%3d DAC", caldel));
	else tl->DrawLatex(0.7, y, "N/A");

	y -= 0.10;
	int vthrcomp(-1.);
        vthrcomp = dac_findParameter(dirName, "VthrComp", chipId);
	tl->DrawLatex(0.1, y, "VTHR: ");
	if (vana >= 0.) tl->DrawLatex(0.6, y, Form("%3d DAC", vthrcomp));
	else tl->DrawLatex(0.7, y, "N/A");

	y -= 0.10;
	int vtrim(-1.);
        vtrim = dac_findParameter(dirName, "Vtrim", chipId);
	tl->DrawLatex(0.1, y, "VTRIM: ");
	if (vana >= 0.) tl->DrawLatex(0.6, y, Form("%3d DAC", vtrim));
	else tl->DrawLatex(0.7, y, "N/A");
	
	y -= 0.10;
	int ibias(-1.);
        ibias = dac_findParameter(dirName, "Ibias_DAC", chipId);
	tl->DrawLatex(0.1, y, "IBIAS_DAC: ");
	if (vana >= 0.) tl->DrawLatex(0.6, y, Form("%3d DAC", ibias));
	else tl->DrawLatex(0.7, y, "N/A");
       
	y -= 0.10;
	int voffset(-1.);
        voffset = dac_findParameter(dirName, "VoffsetOp", chipId);
	tl->DrawLatex(0.1, y, "VOFFSETOP: ");
	if (vana >= 0.) tl->DrawLatex(0.6, y, Form("%3d DAC", voffset));
	else tl->DrawLatex(0.7, y, "N/A");

	// -- Page title
	c1->cd(0);
	tl->SetTextSize(0.04);
	tl->SetTextFont(22);
	tl->DrawLatex(0.02, 0.97, Form("%s (C%i)", noslash.Data(), chipId));

	TDatime date;
	tl->SetTextSize(0.02);
	tl->DrawLatex(0.75, 0.97, Form("%s", date.AsString()));

	c1->SaveAs(Form("%s/chipSummary_C%i.ps", dirName, chipId));
	c1->SaveAs(Form("%s/C%i.png", dirName, chipId));
		

	// -- Dump into logfile
	ofstream OUT(Form("%s/summary_C%i.txt", dirName, chipId));
	OUT << "nDeadPixel: "         << nDeadPixel << endl;
	OUT << "nNoisy1Pixel: "       << nNoisy1Pixel << endl;
	OUT << "nDeadTrimbits: "      << nDeadTrimbits << endl;
	OUT << "nDeadBumps: "         << nDeadBumps << endl;
	OUT << "nMaskDefect: "        << nMaskDefect << endl;
	OUT << "nAddressProblems: "   << nAddressProblems << endl;
	OUT << "nNoisy2Pixel: "       << nNoisy2Pixel << endl;
	OUT << "nTThrDefect: "        << nThrDefect << endl;
	OUT << "nGainDefect: "        << nGainDefect << endl;
	OUT << "nPedDefect: "         << nPedDefect << endl;
	OUT << "nParDefect: "         << nPar1Defect << endl;
	OUT << "nDoubleCounts: "      << nDoubleCounts << endl;
	OUT << "nDoubleFunctCounts: " << nDoubleFunctCounts << endl;
	OUT << "nDoublePerfCounts: "  << nDoublePerfCounts << endl;
	OUT << "nDoubleTrims: "       << nDoubleTrims << endl;
	OUT << "nDoublePHs: "         << nDoublePHs << endl;
        OUT << "nRootFileProblems: "  << nRootFileProblems << endl;
	OUT << "SCurve "              << nN_entries    << " " << mN << " " << sN << endl;
	OUT << "Threshold "           << nV_entries    << " " << mV  << " " << sV << endl;
	OUT << "Gain "                << nG_entries    << " " << mG << " " << sG << endl;
	OUT << "Pedestal "            << nP_entries    << " " << mP << " " << sP << endl;
	OUT << "Parameter1 "          << nPar1_entries << " " << mPar1 << " " << sPar1 << endl;
	OUT.close();
	
}
示例#14
0
void scan2() {

    /*  TFile f1("hist.root");
      TFile f2("SysTot.root");

      TH1D *datahist = (TH1D*)f1.Get("datahist");
      TH1D *fithist = (TH1D*)f1.Get("fithist");

      TH1D *totlow = (TH1D*)f2.Get("totlow");
      TH1D *tothigh = (TH1D*)f2.Get("tothigh");
    */

    TF1 *fun1 = new TF1("fun",fun,0,1000,3);

    TFile f("Output.root");
    TH1F *datahist = dynamic_cast<TH1F*> (f.Get("InvMass"));
    TH1F *fithist = dynamic_cast<TH1F*> (f.Get("hist_err"));
    TH1F *tothigh = dynamic_cast<TH1F*> (f.Get("SystPlus"));
    TH1F *totlow = dynamic_cast<TH1F*> (f.Get("SystMinus"));
    new TCanvas();
    datahist->DrawCopy();
    fithist->DrawCopy("same");
    gPad->SetEditable(0);

    /*	if (datahist->IsZombie()) { std::cout << "Err! datahist not found " << std::endl; return; }
    	if (fithist->IsZombie()) { std::cout << "Err! err_hist not found " << std::endl; return; }
    	if (tothigh->IsZombie()) { std::cout << "Err! syst_plus hist not found " << std::endl; return; }
    	if (totlow->IsZombie()) { std::cout << "Err! syst_minus hist not found " << std::endl; return; }
    */

    TH1D *p = new TH1D("p","Probability",100,150,900);

    for (int i = 1; i<=fithist->GetNbinsX(); i++)
    {
        double mass = fithist->GetBinCenter(i);

        if (mass>440 && mass<450)
        {
            double sigma = sqrt(2.0)*sqrt(pow(0.135*sqrt(mass/2.0),2)+
                                          pow(0.02*(mass/2.0),2));
            cout<< " ===================== mass +/- sigma = " << mass<<"+/-"<<sigma<<endl;
            int bin1 = fithist->FindBin(mass-sigma/2);
            int bin2 = fithist->FindBin(mass+sigma/2);
            cout<<mass<<" "<<bin1<<" "<<bin2<<endl;
            double data = 0;
            double bg = 0;
            double err = 0;

            for (int j = bin1; j<=bin2; j++)
            {
                data+=datahist->GetBinContent(j);
                bg+=fithist->GetBinContent(j);
                double err1 = -totlow->GetBinContent(j);
                double err2 = tothigh->GetBinContent(j);
                err+=TMath::Max(err1,err2)*bg; //why multiply by bg???
            }
            cout << "Total Data/Bg+/-err in mass window[" << mass << "] = "<< data <<"/ "<< bg << "+/-" << err <<endl;
            double prob = 0;
            fun1->SetParameter(0,bg);
            fun1->SetParameter(1,err);

            for (int j = int(data+0.001); j<100; j++) {
                fun1->SetParameter(2,j);
                //fun1->Print();
                //cout << "Evaluating Intrgral for j = " << j << " from x0= " << TMath::Max(0.0,bg-10*err) << " to x1 = " << bg+10*err << endl;
                double val = fun1->Integral(TMath::Max(0.0,bg-10*err),bg+10*err);
                //double val = fun1->Integral(TMath::Max(0.0,bg-2*err),bg+2*err);
                /*for (int z=TMath::Max(0.0,bg-2*err); z < bg+2*err; ++z)
                {
                	if (c<4)
                	{
                	std::cout << "func at [" << z << "]=" << 	fun1->Eval(z) << std::endl;
                	}
                }
                */
                prob += val;
            }
            cout<< "Prob for mass[" << mass<<"]="<< prob <<endl;
            p->SetBinContent(p->FindBin(mass),prob);
        }
    }
    /*
    delete gRandom;
    gRandom = (TRandom*) new TRandom3;
    gRandom->SetSeed(3);

    TH1D *minp = new TH1D("minp","Minimum Probability of Each PseudoExpt",100,0,0.2);

    //int nexp = 50000;
    int nexp = 10;

    TH1D *htemp = (TH1D*)datahist->Clone("htemp");

    for (int iexp = 0; iexp<nexp; iexp++){
      //if (iexp%10==0) cout<<iexp<<endl;
      //generate pseudo-experiments
      htemp->Reset();
      for (int i = 1; i<=htemp->GetNbinsX(); i++){
        double mass = htemp->GetBinCenter(i);
        if (mass>150&&mass<650){
    double bg = fithist->GetBinContent(i);
    double err1 = -totlow->GetBinContent(i);
    double err2 = tothigh->GetBinContent(i);
    double err = TMath::Max(err1,err2)*bg;
    double mean = gRandom->Gaus(bg,err);
    if (mean<0) mean = 0;
    htemp->SetBinContent(i,gRandom->Poisson(mean));
        }
      }
      double minprob = 2.;
      for (int i = 1; i<=fithist->GetNbinsX(); i++){
        double mass = fithist->GetBinCenter(i);
        if (mass>150&&mass<650){
    double sigma = sqrt(2.0)*sqrt(pow(0.135*sqrt(mass/2.0),2)+
    			      pow(0.02*(mass/2.0),2));
    //cout<<mass<<" "<<sigma<<endl;
    int bin1 = fithist->FindBin(mass-sigma/2);
    int bin2 = fithist->FindBin(mass+sigma/2);
    //cout<<mass<<" "<<bin1<<" "<<bin2<<endl;
    double data = 0;
    double bg = 0;
    double err = 0;
    for (int j = bin1; j<=bin2; j++){
      data+=htemp->GetBinContent(j);
      bg+=fithist->GetBinContent(j);
      double err1 = -totlow->GetBinContent(j);
      double err2 = tothigh->GetBinContent(j);
      err+=TMath::Max(err1,err2)*bg;
    }
    //cout<<mass<<" "<<data<<" "<<bg<<" "<<err<<endl;
    double prob = 0;
    fun1->SetParameter(0,bg);
    fun1->SetParameter(1,err);
    for (int j = int(data+0.001); j<100; j++){
      fun1->SetParameter(2,j);
      prob += fun1->Integral(TMath::Max(0.0,bg-10*err),bg+10*err);
    }
    if (prob<minprob) minprob=prob;
        }
      }
      minp->Fill(minprob);
    }
    */
    TCanvas *c1 = new TCanvas("c1","c1");
    TH2D *fr = new TH2D("fr","",100,150,900,100,1e-5,2);
    fr->SetStats(0);
    fr->SetXTitle("M(#gamma,lead jet)(GeV)");
    fr->SetYTitle("Prob of fluctuation #geq N_{obs}");
    fr->GetXaxis()->CenterTitle();
    fr->GetYaxis()->CenterTitle();
    fr->DrawCopy();
    p->SetLineWidth(2);
    p->DrawCopy("same");
    double minp=0;
    double mgg=0;
    double minc = 10;
    for (int i = 1; i<=p->GetNbinsX(); i++) {
        double bin = p->GetBinCenter(i);
        double binc = p->GetBinContent(i);
        if (binc<minc) {
            minp = binc;
            mgg = bin;
            minc = binc;
        }
    }
    cout<<mgg<<" "<<minp<<endl;
    gPad->SetLogy();
    double p1s = 0.00458319;
    double m1s = 0.0435982;
    double s3s = 0.000100319;
    TLine *l1 = new TLine(150,p1s,900,p1s);
    TLine *l2 = new TLine(150,m1s,900,m1s);
    TLine *l3 = new TLine(150,s3s,900,s3s);
    l1->SetLineColor(4);
    l2->SetLineColor(4);
    l3->SetLineColor(2);
    l1->SetLineWidth(2);
    l2->SetLineWidth(2);
    l3->SetLineWidth(2);
    l1->Draw();
    l2->Draw();
    l3->Draw();
    TLatex *t1 = new TLatex(250,m1s/4,"Expected Range for Min. Obs. Prob.");
    t1->SetTextColor(4);
    t1->SetTextSize(0.05);
    t1->Draw();
    TLatex *t2 = new TLatex(350,s3s*1.5,"3 #sigma evidence level");
    t2->SetTextColor(2);
    t2->SetTextSize(0.05);
    t2->Draw();

    TLatex *t3 = new TLatex(0.3,0.93,"CDF Run II Preliminary, 2.0 fb^{-1}");
    t3->SetNDC(true);
    t3->SetTextSize(0.06);
    t3->Draw();

//
//  TCanvas *c2 = new TCanvas("c2","c2");
//  minp->DrawCopy();
    //cout<<minp->GetMean()<<endl;
}
void get_nn_ptpt_FROM_FB_TREE() // TString inputFileName = "MergedOutput.root")
{
    //            TFile *myFile = new TFile( "/Users/macbook/alice/aliceAnalysis/results/task_2016_02_09_PbPb_Data_AOD_3etaWins_phi1_pt02_20_FB_TREE_blocks123/block1/AnalysisResults.139465.root" );
    TFile *myFile = new TFile( "/Users/macbook/alice/aliceAnalysis/results/task_2016_02_21_PbPb_Data_AOD_3etaWins_phi1_pt02_20_FB_TREE_TEST_NEW_DATA_5_02TeV_tryAOD2/MergedOutput.root" );
    if (!myFile)
    {
        cout << "No input file!" << endl;
        return;
    }
    myFile->ls();
    TList *listKeys = myFile->GetListOfKeys();
    cout << "going into list: " << listKeys->At(1)->GetName() << endl;

    //return;
    myFile->cd( listKeys->At(1)->GetName() );
    TList *listKeys2 = gDirectory->GetListOfKeys();
    TList *myTask = (TList*) gDirectory->Get( listKeys2->At(0)->GetName() );
    TTree *t1 = (TTree*)  myTask->FindObject( "treeFB" );


    //    cout << t1->GetEntries() << endl;
    //t1->Print();
    //return;
    //    TFile *f = new TFile( "file_event_tree_merged_impPar_2files.root" );
    //    TTree *t1 = (TTree*) f->Get( "t1" );

    //    TFile *f = new TFile( "output_1_list.grid.root" );
    //    TList *list = (TList*) f->Get( "coutput_V0_mult_0.000000_100000.000000" );
    //    TTree *t1 = (TTree*) list->FindObject( "t1" );

    //other vars:
    //    const int nVars = 3;
    //    TString strVarName[] = {
    //        "centr_V0M" ,
    //        "centr_CL1" ,
    //        "centr_ZEMvsZDC"     ,
    //    };
    //    Float_t varBranch[nVars];

    //    for(Int_t var = 0; var < nVars; var++)
    //        t1->SetBranchAddress(strVarName[var],&varBranch[var]);

    Float_t brV0M;
    //    t1->SetBranchAddress( "centr_V0M", &brV0M );
    t1->SetBranchAddress( "centrV0M_NEW_MULT_SEL", &brV0M );

    Float_t brZEMvsZDC;
    t1->SetBranchAddress( "centr_ZEMvsZDC", &brZEMvsZDC );

    //        const int nCW = 1; //nCentrWidths
    //        const double cWidths[nCW] = { 10 }; //width of the centrality bins
    //        const double cStep[nCW] = { 5 }; //centrality bins step
    //        const int nCentrBins[nCW] = { 17 }; //n centrality bins

//    const int nCW = 2; //nCentrWidths
//    const double cWidths[nCW] = { 10, 5.001 }; //width of the centrality bins
//    const double cStep[nCW] = { 5, 2.5 }; //centrality bins step
//    const int nCentrBins[nCW] = { 17, 35 }; //n centrality bins

    const int nCW = 2; //nCentrWidths
    const double cWidths[nCW] = { 10, 5 }; //width of the centrality bins
    const double cStep[nCW] = { 10, 5 }; //centrality bins step
    const int nCentrBins[nCW] = { 9, 18 }; //n centrality bins


    //    const int nCW = 5; //nCentrWidths
    //    const double cWidths[nCW] = { 10, 5, 2.5, 1.0, 0.5 }; //width of the centrality bins
    //    const double cStep[nCW] = { 5, 2.5, 2.5, 1.0, 1.0 }; //centrality bins step
    //    const int nCentrBins[nCW] = { 17, 35, 36, 90, 90 }; //n centrality bins

    const int nEtaWins = 3;
    const int nPhiWins = 1;

    const int maxNCentrBins = 100; //TMath::MaxElement(nCW, &nCentrBins);
    WinPair wins[nCW][maxNCentrBins][nEtaWins][nPhiWins];
    CentralityOccupancy cOccupancy[nCW][maxNCentrBins];

    for ( int cW = 0; cW < nCW; cW++ )
        for ( int cBin = 0; cBin < nCentrBins[cW]; cBin++ )
        {
            float cBinMin = cStep[cW] * cBin;
            float cBinMax = cWidths[cW] + cStep[cW] * cBin;

            cOccupancy[cW][cBin].cBinMin = cBinMin;
            cOccupancy[cW][cBin].cBinMax = cBinMax;

            for ( int etaW = 0; etaW < nEtaWins; etaW++ )
                for ( int phiW = 0; phiW < nPhiWins; phiW++ )
                    wins[cW][cBin][etaW][phiW].init(cBinMin, cBinMax, etaW, phiW);
        }


    BranchFB br[nEtaWins][nPhiWins];

    for ( int etaW = 0; etaW < nEtaWins; etaW++ )
        for ( int phiW = 0; phiW < nPhiWins; phiW++ )
        {
            int ptW = 0;
            TString brNamePostfix = Form("eta_%d_phi%d_pt_%d"
                                         , etaW, phiW, ptW );
            t1->SetBranchAddress( Form("nF_%s", brNamePostfix.Data() ),  &br[etaW][phiW].nF );
            t1->SetBranchAddress( Form("nB_%s", brNamePostfix.Data() ),  &br[etaW][phiW].nB );
            t1->SetBranchAddress( Form("PtF_%s", brNamePostfix.Data() ), &br[etaW][phiW].PtF );
            t1->SetBranchAddress( Form("PtB_%s", brNamePostfix.Data() ), &br[etaW][phiW].PtB );
        }



    TH1D *hist1D_QA_percentilesEstimator = new TH1D( "hist1D_QA_percentilesEstimator", "hist1D_QA_percentilesEstimator;percentile;entries", 3001, -0.5, 300.5);
    TH1D *hist1D_QA_multALL = new TH1D( "hist1D_QA_multALL", "hist1D_QA_multALL;mult;entries", 3001, -0.5, 3000.5);


    // ##### prepare for tree loop
    int nEvents = t1->GetEntries();
    cout <<"nEvents = " << nEvents << endl;

    //    float **BS_Nf = new float*[nPhiWins];
    //    float **BS_Nb = new float*[nPhiWins];
    //    for ( int w = 0; w < nPhiWins; w++ )
    //    {
    //        BS_Nf[w] = new float[nEvents];
    //        BS_Nb[w] = new float[nEvents];
    //    }

    // ##### main loop over events
    int flag_V0M_ZDC = 0;//1;
    int nAccepted = 0;
    for (Long64_t i=0; i < nEvents; i++)
    {
        if ( i % 100000 == 0 )
            cout << "getting " << (int)i << endl;
        //                cout <<"getting " << (int)i << "\r"; cout.flush();

        t1->GetEntry( i );
        //            t1->GetEntry( TMath::Nint( gRandom->Uniform(-0.5,nEvents-0.5) ) );

        float cEstimator = -1;
        if ( flag_V0M_ZDC==0 )
        {
            if ( brV0M > 90 ) //V0M cut
                continue;
            cEstimator = brV0M;
        }
        else
        {
            if ( brZEMvsZDC > 50 ) //ZDCvsZEM cut
                continue;
            cEstimator = brZEMvsZDC;
        }
        hist1D_QA_percentilesEstimator->Fill(cEstimator);


        //calc mult in whole TPC using wins:
        int multTPC = 0;
        for ( int phiW = 0; phiW < nPhiWins; phiW++ )
            multTPC += (br[0][phiW].nF + br[2][phiW].nF) + (br[0][phiW].nB + br[2][phiW].nB);
        hist1D_QA_multALL->Fill(multTPC);


        //        for ( int w = 0; w < nPhiWins; w++ )
        //        {
        //            BS_Nf[w][nAccepted] = Nf[w];
        //            BS_Nb[w][nAccepted] = Nb[w];
        //        }

        for ( int cW = 0; cW < nCW; cW++ )
            for ( int cBin = 0; cBin < nCentrBins[cW]; cBin++ )
            {
                cOccupancy[cW][cBin].fill(brV0M, brZEMvsZDC);
                for ( int etaW = 0; etaW < nEtaWins; etaW++ )
                    for ( int phiW = 0; phiW < nPhiWins; phiW++ )
                        wins[cW][cBin][etaW][phiW].fill( cEstimator, br[etaW][phiW].nF, br[etaW][phiW].nB, br[etaW][phiW].PtF, br[etaW][phiW].PtB );
            }

        nAccepted++;


    } // end of events
    cout << "nAccepted = " << nAccepted << endl;
    cout << "nAccepted/nAll = " << (float)nAccepted/nEvents << endl;


    // ########## QA PLOTTING:
    TCanvas *canv_estimatorPercentiles_QA_all = new TCanvas("canv_estimatorPercentiles_QA_all","canv_estimatorPercentiles_QA_all",0,0,700,600 );
    hist1D_QA_percentilesEstimator->DrawCopy();

    TCanvas *canv_hist1D_QA_multALL = new TCanvas("canv_hist1D_QA_multALL","canv_hist1D_QA_multALL",50,50,700,600 );
    hist1D_QA_multALL->DrawCopy();


    // MULT BINNING:
    int nCentrBinsMult = 10;
    cout << "nCentrBins=" << nCentrBinsMult << endl;
    double *estBounds = new double[nCentrBinsMult]; // array to contain the quantiles
    getQuantiles(hist1D_QA_multALL, nCentrBinsMult, estBounds);
    drawCanvasWithClasses( hist1D_QA_multALL, "byMultTPC", nCentrBinsMult, estBounds );




    // ##########MAIN PLOTTING FOR CORRS:

    TGraphErrors *grNN [nCW][nEtaWins];
    TGraphErrors *grPtPt[nCW][nEtaWins];
    TGraphErrors *grPtN[nCW][nEtaWins];

    TGraphErrors *grFractEstByV0M[nCW];
    TGraphErrors *grFractEstByZDC[nCW];

    for ( int cW = 0; cW < nCW; cW++ )
    {
        grFractEstByV0M[cW] = new TGraphErrors;
        grFractEstByZDC[cW] = new TGraphErrors;
        for ( int etaW = 0; etaW < nEtaWins; etaW++ )
        {
            grNN[cW][etaW] = new TGraphErrors;
            grPtPt[cW][etaW] = new TGraphErrors;
            grPtN[cW][etaW] = new TGraphErrors;
        }
    }


    //calc (1) - occupancies in centr bins, (2) - corr coeffs
    for ( int cW = 0; cW < nCW; cW++ )
        for ( int cBin = 0; cBin < nCentrBins[cW]; cBin++ )
        {
            if ( cOccupancy[cW][cBin].nEventsV0M > 0 )
            {
                CentralityOccupancy *c = &cOccupancy[cW][cBin];
                float centr = c->cBinMin + (c->cBinMax - c->cBinMin)/2;
                float cRatio = 0;
                if (c->nEventsV0M>0)
                    cRatio = (float)c->nEventsV0M_and_ZDCZEM / c->nEventsV0M;
                grFractEstByV0M[cW]->SetPoint(grFractEstByV0M[cW]->GetN(), centr, cRatio);
                if (c->nEventsZDCZEM>0)
                    cRatio = (float)c->nEventsV0M_and_ZDCZEM / c->nEventsZDCZEM;
                grFractEstByZDC[cW]->SetPoint(grFractEstByZDC[cW]->GetN(), centr, cRatio);
            }
            for ( int etaW = 0; etaW < nEtaWins; etaW++ )
                for ( int phiW = 0; phiW < nPhiWins; phiW++ )
                {
                    WinPair *w = &wins[cW][cBin][etaW][phiW];
                    float centr = w->cBinMin + (w->cBinMax - w->cBinMin)/2;
                    w->calcCorrCoeffs();
                    if(0)cout << "cMin=" << w->cBinMin << ", cMax=" << w->cBinMax << ", etaW=" << etaW
                              << ", NN_bCorr= " << w->NN_bCorr
                              << ", PtPt_bCorr= " << w->PtPt_bCorr
                              << endl;

                    //fill graphs
                    TGraphErrors *gr;
                    //gr NN
                    gr = grNN[cW][etaW];
                    if ( fabs(w->NN_bCorr) < 10 )
                        gr->SetPoint(gr->GetN(), centr, w->NN_bCorr);
                    //gr PtPt
                    gr = grPtPt[cW][etaW];
                    if ( fabs(w->PtPt_bCorr) < 10 )
                        gr->SetPoint(gr->GetN(), centr, w->PtPt_bCorr);
                    //gr PtN
                    gr = grPtN[cW][etaW];
                    if ( fabs(w->PtN_bCorr) < 10 )
                        gr->SetPoint(gr->GetN(), centr, w->PtN_bCorr);

                }
        }

    int colors[] = { kBlack, kBlack, kBlue, kRed, kMagenta };
    int markers[] = { 20, 24, 5, 2, 21 };

    // NN
    TCanvas *canv_grNN = new TCanvas("canv_grNN","canv_grNN",20,50,700,600 );
    tuneCanvas(canv_grNN);
    grNN[0][0]->SetTitle( ";centrality percentile;b_{corr}" ); //C_{2}
    tuneGraphAxisLabels(grNN[0][0]);


    //centr 10
    drawGraph(grNN[0][0], 20, kBlack, "AP");
    //    drawGraph(grNN[0][1], 21, kBlack, "P");
    //    drawGraph(grNN[0][2], 22, kBlack, "P");

    for ( int cW = 1; cW < nCW; cW++ )
        drawGraph(grNN[cW][0], markers[cW], colors[cW], "P");

    grNN[0][0]->SetMinimum( 0 );

    TLegend *leg = new TLegend(0.65,0.65,0.999,0.95);
    leg->SetFillColor(kWhite);
    leg->SetFillStyle(0);
    leg->SetBorderSize(0);
    for ( int cW = 0; cW < nCW; cW++ )
        leg->AddEntry(grNN[cW][0], Form("class width %.1f", cWidths[cW]), "p");
    leg->Draw();

    TLatex *tex = new TLatex(0.7,0.4, "#eta_{gap}=0.8, #delta#eta=0.4");
    drawTex(tex, 0.045);

    tex = new TLatex(0.4,0.89, "NN");
    drawTex(tex, 0.045);


    TString strPostfix;

    if (flag_V0M_ZDC==0)
        strPostfix = Form("V0M.eps");
    else
        strPostfix = Form("ZDCZEM.eps");

    canv_grNN->SaveAs( Form("NN_%s", strPostfix.Data() ) );

    // PtPt
    TCanvas *canv_grPtPt = new TCanvas("canv_grPtPt","canv_grPtPt",250,50,700,600 );
    tuneCanvas(canv_grPtPt);
    grPtPt[0][0]->SetTitle( ";centrality percentile;b_{corr}" ); //C_{2}
    tuneGraphAxisLabels(grPtPt[0][0]);


    //centr 10
    drawGraph(grPtPt[0][0], 20, kBlack, "AP");
    //    drawGraph(grPtPt[0][1], 21, kBlack, "P");
    //    drawGraph(grPtPt[0][2], 22, kBlack, "P");

    for ( int cW = 1; cW < nCW; cW++ )
        drawGraph(grPtPt[cW][0], markers[cW], colors[cW], "P");

    grPtPt[0][0]->SetMinimum( 0 );

    leg = new TLegend(0.65,0.65,0.999,0.95);
    leg->SetFillColor(kWhite);
    leg->SetFillStyle(0);
    leg->SetBorderSize(0);
    for ( int cW = 0; cW < nCW; cW++ )
        leg->AddEntry(grPtPt[cW][0], Form("class width %.1f", cWidths[cW]), "p");
    leg->Draw();

    tex = new TLatex(0.7,0.4, "#eta_{gap}=0.8, #delta#eta=0.4");
    drawTex(tex, 0.045);

    tex = new TLatex(0.4,0.89, "PtPt");
    drawTex(tex, 0.045);


    canv_grNN->SaveAs( Form("PtPt_%s", strPostfix.Data() ) );

    // PtN
    TCanvas *canv_grPtN = new TCanvas("canv_grPtN","canv_grPtN",450,50,700,600 );
    tuneCanvas(canv_grPtN);
    grPtN[0][0]->SetTitle( ";centrality percentile;b_{corr}" ); //C_{2}
    tuneGraphAxisLabels(grPtN[0][0]);


    //centr 10
    drawGraph(grPtN[0][0], 20, kBlack, "AP");
    //    drawGraph(grPtN[0][1], 21, kBlack, "P");
    //    drawGraph(grPtN[0][2], 22, kBlack, "P");

    for ( int cW = 1; cW < nCW; cW++ )
        drawGraph(grPtN[cW][0], markers[cW], colors[cW], "P");

    grPtN[0][0]->SetMinimum( 0 );
    leg = new TLegend(0.65,0.65,0.999,0.95);
    leg->SetFillColor(kWhite);
    leg->SetFillStyle(0);
    leg->SetBorderSize(0);
    for ( int cW = 0; cW < nCW; cW++ )
        leg->AddEntry(grPtN[cW][0], Form("class width %.1f", cWidths[cW]), "p");
    leg->Draw();

    tex = new TLatex(0.7,0.4, "#eta_{gap}=0.8, #delta#eta=0.4");
    drawTex(tex, 0.045);

    tex = new TLatex(0.4,0.89, "PtN");
    drawTex(tex, 0.045);


    canv_grNN->SaveAs( Form("PtN_%s", strPostfix.Data() ) );



    TCanvas *canv_grPtN_2D = new TCanvas("canv_grPtN_2D","canv_grPtN_2D",450,50,700,600 );
    tuneCanvas(canv_grPtN_2D);


    //    wins[0][0][0][0].hist2D_PtN->DrawCopy();
    wins[0][0][0][0].hist2D_PtN->ProfileX()->DrawCopy();



    // CENTR ESTIMATOR EVENT RATIO:
    TCanvas *canv_grCentrRatio = new TCanvas("canv_grCentrRatio","canv_grCentrRatio",450,250,700,600 );
    tuneCanvas(canv_grCentrRatio);
    grFractEstByV0M[0]->SetTitle(";centrality percentile;ratio");
    tuneGraphAxisLabels(grFractEstByV0M[0]);
    //centr 10
    drawGraph(grFractEstByV0M[0], 20, kBlack, "AP");
    //    drawGraph(grFractEstByZDC[0], 20, kBlack, "L");

    for ( int cW = 1; cW < nCW; cW++ )
        drawGraph(grFractEstByV0M[cW], markers[cW], colors[cW], "P");

    leg = new TLegend(0.65,0.65,0.999,0.95,"ratio #frac{V0M-and-ZEMZDC}{V0M}");
    leg->SetFillColor(kWhite);
    leg->SetFillStyle(0);
    leg->SetBorderSize(0);

    for ( int cW = 0; cW < nCW; cW++ )
        leg->AddEntry(grFractEstByV0M[cW], Form("class width %.1f", cWidths[cW]), "p");
    leg->Draw();
    //    leg->SetHeader("ratio #frac{V0M-and-ZEMZDC}/{V0M}");

    canv_grCentrRatio->SaveAs("ratio_V0M-and-ZEMZDC_by_V0M.eps");

    // CENTR ESTIMATOR PERCENTILES QA:
    TCanvas *canv_estimatorPercentiles_QA = new TCanvas("canv_estimatorPercentiles_QA","canv_estimatorPercentiles_QA",50,350,700,600 );
    for ( int cBin = 0; cBin < nCentrBins[0]; cBin++ )
    {
        TH1D *h = wins[0][cBin][0][0].hist1D_EstimatorEntries;
        h->SetLineColor(kOrange-9+cBin);
        if ( cBin == 0 )
            h->DrawCopy();
        else
            h->DrawCopy("same");
    }


    // MULT F IN CENTR CLASSES QA:
    TCanvas *canv_mult_F_in_centr_QA = new TCanvas("canv_mult_F_in_centr_QA","canv_mult_F_in_centr_QA",50,400,700,600 );
    gPad->SetLogy();
    for ( int cBin = 0; cBin < nCentrBins[0]; cBin++ )
    {
        TH1D *h = wins[0][cBin][0][0].hist1D_multDistrF;
        h->SetLineColor(kOrange-9+cBin);

        if ( cBin == 0 )
        {
            h->SetLineColor(kRed);
            h->GetYaxis()->SetRangeUser(1,100000);
        }

        if ( cBin == 0 )
            h->DrawCopy();
        else
            h->DrawCopy("same");
    }


    // Check entries in centrality bins:
    for ( int cW = 0; cW < nCW; cW++ )
    {
        cout << " ###### cW = " << cW << endl;
        for ( int cBin = 0; cBin < nCentrBins[cW]; cBin++ )
        {
            TH1D *h = wins[cW][cBin][0][0].hist1D_multDistrF;
            cout << "cBin = " << h->GetEntries() << endl;
//            h->SetLineColor(kOrange-9+cBin);
//            if ( cBin == 0 )
//                h->DrawCopy();
//            else
//                h->DrawCopy("same");
        }
    }

    return;
}
void TestEnergy() {
  TFile *file = TFile::Open("PPCollisionUps1sMilNoTune.root");
  TFile *file2 = TFile::Open("PPCollisionMilNoTune.root");
  TNtuple* PPTupleUps = (TNtuple*)file->Get("PPTuple");
  TNtuple* PPTupleND = (TNtuple*)file2->Get("PPTuple");
  TH1D* NCharUps = new TH1D("NCharUps", "Sum of Energy at mid rapdity", 30000, 0, 300);
  PPTupleUps->Draw("(ETmid-mu1pT-mu2pT)>>NCharUps", "NChar>2 && abs(deta1) < 1.93 && abs(deta2) < 1.93  && mu1pT > 4 && mu2pT > 4");
//  NCharUps->Scale(3.35e-6);
  double sum, percent = 0, centAr[21];
  int c, centa[21], i;
  sum = 0;
  centAr[0] = 180;
  centAr[20] = 0;
  c = 1;
	//Find Activity Ranges
  double min = 0, average[20], bins;
  i = 0;
  //Activity Range Calculations for Track Count
  TH1D* Tracks = new TH1D("Tracks", "Number of Tracks", 10000, 0, 300);
  PPTupleND->Draw("ETmid>>Tracks", "NChar > 0");
  double MinBiasEvents;
  MinBiasEvents = Tracks->GetEntries();
  NCharUps->Draw();
  Tracks->Draw();
  Tracks->Scale(1./Tracks->GetEntries());
  int TrackCent[21];
  percent = .02;
  TrackCent[0] = 300;
  TrackCent[20] = 0;
  c = 1;
  double Ranges[12];
  int counter = 1;
  Ranges[0] = 0;
	//Loop To Get Activity Range Values
  for (i=0; percent <= .02; percent += .02) {
        sum = 0;
  	cout << c << "		";
        for(i=0; sum < percent && i != 10000; i++) {
                sum += Tracks->GetBinContent(10000-i); }
       	 cout << 100*percent - 2 << "-" << 100*percent << "%" << "      " << MinBiasEvents*sum  << "      " << i << " " << Tracks->GetBinCenter(10000-i) << "\n"; // Use to check Activity Range Values
	Ranges[counter] = sum;
	counter++;		
        TrackCent[c] = Tracks->GetBinCenter(10000-i);
        c++;}
  percent = .08;
  for (i=0; percent <= .08; percent += .02) {
        sum = 0;
        cout << c << "		";
        for(i=0; sum < percent || percent == 1; i++) {
                sum += Tracks->GetBinContent(10000-i); }
                         cout << 100*percent - 2 << "-" << 100*percent << "%" << "      " << MinBiasEvents*sum  << "      " << i << " " << Tracks->GetBinCenter(10000-i) << "\n"; // Use to check Activity Range Values
	Ranges[counter] = sum;
        counter++;
        TrackCent[c] = Tracks->GetBinCenter(10000-i);
        c++;}
  percent = .20;
  for (i=0; percent <= .20; percent += .04) {
        sum = 0;
        cout << c << "		";
        for(i=0; sum < percent || percent == 1; i++) {
                sum += Tracks->GetBinContent(10000-i); }
                         cout << 100*percent - 4 << "-" << 100*percent << "%" << "      " << MinBiasEvents*sum  << "      " << i << " " << Tracks->GetBinCenter(10000-i) << "\n"; // Use to check Activity Range Values
	Ranges[counter] = sum;
        counter++;
        TrackCent[c] = Tracks->GetBinCenter(10000-i);
        c++;}
	percent = .30;
//  for (i=0; percent <= .30; percent += .05) {
  //      sum = 0;
//	cout << c << "\n";
//        for(i=0; sum < percent || percent == 1; i++) {
 //               sum += Tracks->GetBinContent(10000-i); }
  //                       cout << 100*percent - 5 << "-" << 100*percent << "%" << "      " << sum  << "      " << i << " " << Tracks->GetBinCenter(10000-i) << "\n"; // Use to check Activity Range Values
 //       TrackCent[c] = Tracks->GetBinCenter(10000-i) + .5;
   //     c++; }
//	percent = .40;
  for (i=0; percent <= 1; percent += .10) {
        sum = 0;
	cout << c << "		";
        for(i=0; sum <= percent && i != 10000; i++) {
                sum += Tracks->GetBinContent(10000-i); }
                         cout << 100*percent - 10 << "-" << 100*percent << "%" << "      " << MinBiasEvents*sum  << "      " << i << " " << Tracks->GetBinCenter(10000-i) << "\n"; // Use to check Activity Range Values
	Ranges[counter] = sum;
        counter++;
        TrackCent[c] = Tracks->GetBinCenter(10000-i);
        c++; }
  cout << "\n" << "Activity Range Values from Array" << "\n";
  for(c = 0; c < 11; c++) {
    	cout << c << ")   "  << TrackCent[c] << "\n"; }
  min = 0;
  double TrackAverage[20];

  cout << "\n" << NCharUps->GetBinCenter(30000) << "\n";

  i = 0;
  double TotalUps = 0;
  //cout << "\n" << "Activity Bin Averages" << "\n";
	//Loop To Get Average In Each Activity Region
  for(c = 0; NCharUps->GetBinCenter(30000-i) > TrackCent[c+1] && NCharUps->GetBinCenter(30000-i) <= TrackCent[c]; c++) {
        sum = 0;
        bins = 0;
        for(i = min; (NCharUps->GetBinCenter(30000-i) > TrackCent[c+1] && NCharUps->GetBinCenter(30000-i) <= TrackCent[c]) && i != 30000; i++) {
                sum += NCharUps->GetBinContent(30000-i)*(NCharUps->GetBinCenter(30000-i));
                bins += NCharUps->GetBinContent(30000-i); }
        TrackAverage[c] = sum/bins;
	TotalUps += bins;
	cout << "Point " << c << ": " << bins << " +- " << sqrt(bins) << "   Upsilons" << "\n";
        min = i; }
	cout << NCharUps->GetBinCenter(100) << "\n";
       	// cout << 10*c << "-" << 10*(c+1) << "%" << "     " << TrackAverage[c] << "\n";  }
  cout << "Total number of Upsilons: " << TotalUps << "\n";
  cout << "\n" << "Corrected X/Y Track values" << "\n";
  double TrackYpoints[20];
  for(i = 0; i < 12; i++) {
	cout << (Ranges[i+1] - Ranges[i])*MinBiasEvents << "\n"; }

	//Take Average Values and Divide by ND Average to Get X points
 // for(c = 0; c < 4; c++) {
//	TrackAverage[c] = TrackAverage[c]/Tracks->GetMean();
//	TrackYpoints[c] = (50./NCharUps->Integral(0,25000))*NCharUps->Integral(TrackCent[c+1], TrackCent[c]-1 );
//	cout << "(" <<TrackAverage[c] << "," << TrackYpoints[c] <<  ")" <<  "\n"; }
  //for(c = 4; c < 7; c++) {
    //    TrackAverage[c] = TrackAverage[c]/Tracks->GetMean();
  //      TrackYpoints[c] = (25./NCharUps->Integral(0,25000))*NCharUps->Integral(TrackCent[c+1], TrackCent[c]-1 );
    //    cout << "(" <<TrackAverage[c] << "," << TrackYpoints[c] <<  ")" <<  "\n"; }
//  for(c = 7; c < 10; c++) {
 //       TrackAverage[c] = TrackAverage[c]/Tracks->GetMean();
   //     TrackYpoints[c] = (20./NCharUps->Integral(0,25000))*NCharUps->Integral(TrackCent[c+1], TrackCent[c]-1 );
//	cout << "(" <<TrackAverage[c] << "," << TrackYpoints[c] <<  ")" <<  "\n"; }


TrackAverage[0] = TrackAverage[0]/Tracks->GetMean();
        TrackYpoints[0] = (50./NCharUps->Integral(0,30000))*NCharUps->Integral(100*TrackCent[1], 100*(TrackCent[0]-1) );
	cout << "(" <<TrackAverage[0] << "," << TrackYpoints[0] <<  ")" <<  "\n";

TrackAverage[1] = TrackAverage[1]/Tracks->GetMean();
        TrackYpoints[1] = (16.67/NCharUps->Integral(0,30000))*NCharUps->Integral(100*TrackCent[2], 100*TrackCent[1]-100 );
	cout << "(" <<TrackAverage[1] << "," << TrackYpoints[1] <<  ")" <<  "\n";

TrackAverage[2] = TrackAverage[2]/Tracks->GetMean();
        TrackYpoints[2] = (8.33/NCharUps->Integral(0,30000))*NCharUps->Integral(100*TrackCent[3], 100*TrackCent[2]-100 );
	cout << "(" <<TrackAverage[2] << "," << TrackYpoints[2] <<  ")" <<  "\n";

 for(c = 3; c < 14; c++) {
        TrackAverage[c] = TrackAverage[c]/Tracks->GetMean();
        TrackYpoints[c] = (10./NCharUps->Integral(0,30000))*NCharUps->Integral(100*TrackCent[c+1], 100*TrackCent[c]-100 );
        cout << "(" <<TrackAverage[c] << "," << TrackYpoints[c] <<  ")" <<  "\n"; } 
  TF1* line = new TF1("line", "x", 0, 4.5);
  TF1* line2 = new TF1("line2", "1.8*x", 0, 4.5);
  line2->SetLineColor(kWhite);
  sum = 0;
  double scaledSumE = 0, scaleSumT = 0;
  scaleSumT = NCharUps->Integral(0,30000);
  TCanvas* can2 = new TCanvas("can2", "Centrality");
  can2->cd();
  line->SetLineColor(1);
  line2->GetYaxis()->SetTitle("#varUpsilon(1S)/<#varUpsilon(1S)>");
  line2->GetXaxis()->SetTitle("#Sigma E_{T}^{|#eta| < 2.4}/<#Sigma E_{E}^{|#eta| < 2.4}>");
  line2->SetTitle("#varUpsilon(1S) Cross Section vs Track Multiplicity");
  line2->Draw();
  line->SetLineStyle(3);
  line->Draw("same");
   for(c = 0; c < 18; c++) { cout << TrackCent[c] << "           Bin Average: " << 10.32*TrackAverage[c] <<  "\n";}
  double Test, Testaverage, Testsum, Testbin, count = 0, TestY = 0;
  Test = NCharUps->Integral(38,100);
  for(i = 38; i < 100; i++) {
	Testsum += NCharUps->GetBinContent(i)*NCharUps->GetBinCenter(i);
	Testbin += NCharUps->GetBinContent(i); }
  Testaverage = Testsum/Testbin;
  TestY = (10./NCharUps->Integral(0,30000))*NCharUps->Integral(38, 100);
  cout << "\n" << "\n" << TestY << "\n" << "\n";

  TH1D* modelT = new TH1D("modelT", "Pythia model", 5000, 0, 5);
  //Fill Histogram with points from Model
  for(i = 0; i < 20; i++) {
	//Track Values
	modelT->SetBinContent(1000*TrackAverage[i], TrackYpoints[i]);
        modelT->SetBinError(1000*TrackAverage[i], .01); }
  modelT->SetMarkerStyle(20);
  modelT->SetMarkerColor(kBlue);
  modelT->SetLineColor(kBlue);
  modelT->Draw("sameE");
  //Histogram for STAR Data Points
  TH1D* data = new TH1D("data", "CMS Data", 4000, 0, 4);
  data->SetMarkerStyle(20);
  data->SetMarkerColor(kRed);
  data->SetLineColor(kRed);
  data->SetBinContent(3262, 6.67);
  data->SetBinError(3262, .26);
  data->SetBinContent(2010, 3.12);
  data->SetBinError(2010, .15);
  data->SetBinContent(1240, 1.4);
  data->SetBinError(1240, .06);
  data->SetBinContent(630, .240);
  data->SetBinError(630, .01);
  data->Draw("sameE");
  TLegend* leg = new TLegend(.1,.74,.30,.9);
  leg->SetHeader("For |#eta| < 2.4");
  leg->AddEntry(modelT->DrawCopy("same"), "Pythia 8 Model", "l");
  leg->AddEntry(data->DrawCopy("same"), "CMS data", "l");
  leg->Draw("same");
  return; }
void MidRapAnalysis() {
  //Set up Canvas Area
  TCanvas* can2 = new TCanvas("can2", "Centrality");

  double xAverage[] = {3.42, 2.62, 1.96, 1.45, 1.12, .87, .67, .49, .39, .28, .23};
  double yAverage[] = {5.22, 3.33, 2.21, 1.40, 1.06, .72, .49, .22, .16, .06, .03};
  double yError[] = {.36, .25, .12, .06, .01, .12, .04, .03, .01, .01, 0};
  double xError[] = {0,0,0,0,0,0,0,0,0,0};
  TGraphErrors* Emodel = new TGraphErrors(10, xAverage, yAverage, xError, yError);
  Emodel->SetFillStyle(3001);
  Emodel->SetFillColor(kBlue);

  double xAverageE[] = {4.19, 2.92, 2.03, 1.40, 1.04, .77, .57, .42, .32, .24};
  double yAverageE[] = {5.39, 3.36, 2.14, 1.33, .90, .56, .37, .16, .14, .01};
  double yErrorE[] = {.31, .24, .08, .07, .01, .01, .02, .06, .07, .01};
  double xErrorE[] = {0,0,0,0,0,0,0,0,0,0};
  TGraphErrors* EmodelE = new TGraphErrors(10, xAverageE, yAverageE, xErrorE, yErrorE);
  EmodelE->SetFillStyle(3001);
  EmodelE->SetFillColor(kGreen);

  can2->cd();
  TH1F* frame = can2->DrawFrame(0, 0, 3.5, 7.2);
  TF1* line = new TF1("line", "x", 0, 4.3);
  TF1* line2 = new TF1("line2", "1.6*x", 0, 4.3);
  line2->SetLineColor(kWhite);
  line->SetLineColor(1);
  line2->GetYaxis()->SetTitle("#varUpsilon(1S)/<#varUpsilon(1S)>");
//  line2->GetXaxis()->SetTitle("N_{Ch}^{|#eta|<2.4}/<N_{Ch}^{|#eta|<2.4}>");
  line2->SetTitle("#varUpsilon(1S) Cross Section vs Event Activity");
  line2->Draw();
  Emodel->Draw("P3");
  EmodelE->Draw("3");
 //line2->Draw("same");
  line->SetLineStyle(3);
  line->SetLineColor(kBlack);
  line->Draw("same");
  
  TH1D* mod = new TH1D("mod", "Pythia Model", 400, 0, 4);
  mod->SetLineColor(kBlue);
  TH1D* modEnergy = new TH1D("modEnergy", "Pythia Energy Model", 400, 0, 4);
  modEnergy->SetLineColor(kGreen);

  TH1D* data = new TH1D("data", "CMS Data", 4000, 0, 4);
  data->SetMarkerStyle(20);
  data->SetMarkerColor(kRed);
  //Manually Entering CMS Data Points with Error
  data->SetBinContent(3262, 6.67);
  data->SetBinError(3262, .26);
  data->SetBinContent(2010, 3.12);
  data->SetBinError(2010, .15);
  data->SetBinContent(1240, 1.4);
  data->SetBinError(1240, .06);
  data->SetBinContent(630, .240);
  data->SetBinError(630, .01);
  //data->SetMarkerColor(kBlue);
  data->SetMarkerSize(1);
  data->SetLineColor(kRed);
  data->Draw("sameE");

  TLegend* leg = new TLegend(.1,.7,.38,.9);
  leg->SetHeader("For |#eta| < 2.4");
  leg->AddEntry(modEnergy->DrawCopy("same"), "Pythia 8 - #Sigma E_{T}/<#Sigma E_{T}>", "l");
  leg->AddEntry(mod->DrawCopy("same"), "Pythia 8 - N_{Ch}/<N_{Ch}>", "l");
  leg->AddEntry(data->DrawCopy("sameE"), "CMS data - N_{Ch}/<N_{Ch}>", "l");
  leg->Draw("same");
  mod->SetLineColor(kBlack);
  mod->Draw("same");
  return; }
示例#18
0
AntiparticleParticleRatio(Int_t part, Int_t cent, Bool_t cutSpectra = kTRUE)
{

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

  
  TFile *itssafile = TFile::Open(itssafilename);
  //  TFile *itstpcfile = TFile::Open(itstpcfilename);
  TFile *tpctoffile = TFile::Open(tpctoffilename);
  TFile *toffile = TFile::Open(toffilename);
  //  TFile *hydrofile = TFile::Open(hydrofilename);

  TCanvas *cCanvas = new TCanvas("cCanvas");
  if (cent == -1) cCanvas->Divide(5, 2);
  TCanvas *cCanvasCombined = new TCanvas("cCanvasCombined");
  if (cent == -1) cCanvasCombined->Divide(5, 2);
  TCanvas *cCanvasRatio = new TCanvas("cCanvasRatio");
  if (cent == -1) cCanvasRatio->Divide(5, 2);
  TCanvas *cCanvasRatioFit = new TCanvas("cCanvasRatioFit");
  if (cent == -1) cCanvasRatioFit->Divide(5, 2);
  TH1D *hITSsa[2], *hITSTPC[2], *hTPCTOF[2], *hTOF[2];
  TGraphErrors *gCombined[2][10];
  TProfile *pCombined[2][10];
  TH1D *hCombined[2][10];
  TH1D *hRatio_ITSsa[10];
  TH1D *hRatio_ITSTPC[10];
  TH1D *hRatio_TPCTOF[10];
  TH1D *hRatio_TOF[10];
  TH1D *hRatio_COMB[10];
  for (Int_t icent = 0; icent < 10; icent++) {
    
    if (cent != -1 && icent != cent) continue;
    
    for (Int_t icharge = 0; icharge < 2; icharge++) {
      gCombined[icharge][icent] = new TGraphErrors();
      pCombined[icharge][icent] = new TProfile(Form("pCombined_charge%d_cent%d", icharge, icent), "", NptBins, ptBin);
      hCombined[icharge][icent] = new TH1D(Form("hCombined_charge%d_cent%d", icharge, icent), "", NptBins, ptBin);
      TObjArray spectraArray;
      hITSsa[icharge] = GetITSsaSpectrum(itssafile, part, icharge, icent, cutSpectra);
      hITSTPC[icharge] = NULL;//GetITSTPCSpectrum(itstpcfile, part, icharge, icent, cutSpectra);
      hTPCTOF[icharge] = GetTPCTOFSpectrum(tpctoffile, part, icharge, icent, cutSpectra);
      hTOF[icharge] = GetTOFSpectrum(toffile, part, icharge, icent, cutSpectra);
      //    hHydro = GetHydroSpectrum(hydrofile, part, charge, icent);
      Double_t minimum = 0.;
      Double_t maximum = 0.;
      if (hITSsa[icharge]) {
	//	AddPointsToGraph(hITSsa[icharge], gCombined[icharge][icent]);
	//	AddPointsToProfile(hITSsa[icharge], pCombined[icharge][icent]);
	spectraArray.Add(hITSsa[icharge]);
	//	hITSsa[icharge]->DrawCopy("same");
	//	if (hITSsa[icharge]->GetMaximum() > maximum) maximum = hITSsa[icharge]->GetMaximum();
	//	if (hITSsa[icharge]->GetMinimum() < minimum) minimum = hITSsa[icharge]->GetMinimum();
      }
      if (hITSTPC[icharge]) {
	//	AddPointsToGraph(hITSTPC[icharge], gCombined[icharge][icent]);
	//	AddPointsToProfile(hITSTPC[icharge], pCombined[icharge][icent]);
	spectraArray.Add(hITSTPC[icharge]);
	//	hITSTPC[icharge]->DrawCopy("same");
	//	if (hITSTPC[icharge]->GetMaximum() > maximum) maximum = hITSTPC[icharge]->GetMaximum();
	//	if (hITSTPC[icharge]->GetMinimum() < minimum) minimum = hITSTPC[icharge]->GetMinimum();
      }
      if (hTPCTOF[icharge]) {
	//	AddPointsToGraph(hTPCTOF[icharge], gCombined[icharge][icent]);
	//	AddPointsToProfile(hTPCTOF[icharge], pCombined[icharge][icent]);
	spectraArray.Add(hTPCTOF[icharge]);
	//	hTPCTOF[icharge]->DrawCopy("same");
	//	if (hTPCTOF[icharge]->GetMaximum() > maximum) maximum = hTPCTOF[icharge]->GetMaximum();
	//	if (hTPCTOF[icharge]->GetMinimum() < minimum) minimum = hTPCTOF[icharge]->GetMinimum();
      }
      if (hTOF[icharge]) {
	//	AddPointsToGraph(hTOF[icharge], gCombined[icharge][icent]);
	//	AddPointsToProfile(hTOF[icharge], pCombined[icharge][icent]);
	spectraArray.Add(hTOF[icharge]);
	//	hTOF[icharge]->DrawCopy("same");
	//	if (hTOF[icharge]->GetMaximum() > maximum) maximum = hTOF[icharge]->GetMaximum();
	//	if (hTOF[icharge]->GetMinimum() < minimum) minimum = hTOF[icharge]->GetMinimum();
      }
      
      CombineSpectra(hCombined[icharge][icent], &spectraArray);

    }

    /* antiparticle/particle ratios */

    Char_t title[1024];
    sprintf(title, "%s/%s (%s);p_{T} (GeV/c);%s/%s;", partChargeName[part][1], partChargeName[part][0], centName[icent], partChargeName[part][1], partChargeName[part][0]);

    TH1D *hArea = new TH1D(Form("hArea_%d", icent), title, 100, ptMin[part], ptMax[part]);
    hArea->SetMaximum(1.2);
    hArea->SetMinimum(0.8);

    if (cent == -1)
      cCanvas->cd(icent + 1);
    else
      cCanvas->cd();

    hArea->DrawCopy();

    if (hITSsa[0] && hITSsa[1]) {
      hRatio_ITSsa[icent] = new TH1D(*hITSsa[1]);
      hRatio_ITSsa[icent]->Divide(hITSsa[0]);
      hRatio_ITSsa[icent]->DrawCopy("same");
    }

    if (hTPCTOF[0] && hTPCTOF[1]) {
      hRatio_TPCTOF[icent] = new TH1D(*hTPCTOF[1]);
      hRatio_TPCTOF[icent]->Divide(hTPCTOF[0]);
      hRatio_TPCTOF[icent]->DrawCopy("same");
    }

    if (hTOF[0] && hTOF[1]) {
      hRatio_TOF[icent] = new TH1D(*hTOF[1]);
      hRatio_TOF[icent]->Divide(hTOF[0]);
      hRatio_TOF[icent]->DrawCopy("same");
    }

    //    TLegend *legend = cCanvas->BuildLegend();
    //    legend->SetFillStyle(0);
    //    legend->SetFillColor(0);
    //    legend->DeleteEntry();

    if (cent == -1)
      cCanvasCombined->cd(icent + 1);
    else
      cCanvasCombined->cd();

    if (hCombined[0][icent] && hCombined[1][icent]) {
      hRatio_COMB[icent] = new TH1D(*hCombined[1][icent]);
      hRatio_COMB[icent]->Divide(hCombined[0][icent]);
      hRatio_COMB[icent]->SetMarkerStyle(20);
      hRatio_COMB[icent]->SetMarkerColor(2);
      hRatio_COMB[icent]->Fit("pol0", "");
      hRatio_COMB[icent]->SetMinimum(0.5);
      hRatio_COMB[icent]->SetMaximum(1.5);
      hRatio_COMB[icent]->SetTitle(title);
      //      hRatio_COMB[icent]->Draw("PHIST");
      //      pol0->SetRange(0., 5.);
      //      pol0->DrawCopy("same");
      //      hArea->DrawCopy();
      //      hRatio_COMB[icent]->Draw("same");
    
    }


  }

}
示例#19
0
void drawIaa( bool saveFigures=true) {

    const int nPtBin = 4;
    int ptBin[nPtBin+1] = {40, 50,60,80,9999};
    double ptBinPaDraw[nPtBin+1] = { 40.5 ,49.5, 58.5,  76.5,  123. } ;
    // double AvePtBin[nPtBin+1] = { 45, 54.1479, 67.4204, 99.6956, 9999};
    
    const int nCentBinHI = 2;
    const int centBinHI[nCentBinHI +1] = {-1, 10030, 13099}; 

    TH1D* hJetPt[7][10][6]; // [Collision][centrality][pt]
    TH1D* hIaa[10][6]; // [centrality][pt]
    
    for (int icent=1 ; icent<= 10 ; icent++) {
      for (int ipt=1 ; ipt<=nPtBin ; ipt++) {
	
	hIaa[icent][ipt] = NULL;
	for (int icoll=0 ; icoll<6  ; icoll++) {
	  hJetPt[icoll][icent][ipt] = NULL;
	}
	
      }
    }
    
    TFile* histFile[7][6];  // [Collision][pt]                                                                                          
    for (int ipt=1 ; ipt<=nPtBin ; ipt++) {
      for (int icoll=0 ; icoll<6 ; icoll++) {
	TString sampleName = getSampleName( icoll ) ;

	char* fname =  Form("ffFiles/jetEnergyResL2L3_smeared/photonTrackCorr_%s_output_photonPtThr%d_to_%d_jetPtThr30_20131018.root",sampleName.Data(), (int)ptBin[ipt-1], 9999);
	//	char* fname =  Form("ffFiles/centralValue/photonTrackCorr_%s_output_photonPtThr%d_to_%d_jetPtThr30_20131011.root",sampleName.Data(), (int)ptBin[ipt-1], 9999);
	//	char* fname =  Form("ffFiles/centralOct16th/photonTrackCorr_%s_output_photonPtThr%d_to_%d_jetPtThr30_20131016.root",sampleName.Data(), (int)ptBin[ipt-1], 9999);
	//	char* fname =  Form("ffFiles/jetEnergyResCorrectedOct16th/photonTrackCorr_%s_output_photonPtThr%d_to_%d_jetPtThr30_20131016.root",sampleName.Data(), (int)ptBin[ipt-1], 9999);
	//	char* fname =  Form("ffFiles/jetEnergyScaledMinus2percentOct17/photonTrackCorr_%s_output_photonPtThr%d_to_%d_jetPtThr30_20131017.root",sampleName.Data(), (int)ptBin[ipt-1], 9999);
	//	char* fname =  Form("ffFiles/ak5Cone/photonTrackCorr_%s_output_photonPtThr%d_to_%d_jetPtThr30_20131017.root",sampleName.Data(), (int)ptBin[ipt-1], 9999);
	//char* fname =  Form("ffFiles/jetEnergyResCorrected/photonTrackCorr_%s_output_photonPtThr%d_to_%d_jetPtThr30_20131011.root",sampleName.Data(), (int)ptBin[ipt-1], 9999);
	//char* fname =  Form("ffFiles/jetEnergyScaledPlus2percent/photonTrackCorr_%s_output_photonPtThr%d_to_%d_jetPtThr30_20131011.root",sampleName.Data(), (int)ptBin[ipt-1], 9999);
	//	char* fname =  Form("ffFiles/jetEnergyScaledMinus2percent/photonTrackCorr_%s_output_photonPtThr%d_to_%d_jetPtThr30_20131011.root",sampleName.Data(), (int)ptBin[ipt-1], 9999);
	//	char* fname =  Form("ffFiles/noElectronRejection/photonTrackCorr_%s_output_photonPtThr%d_to_%d_jetPtThr30_20131011.root",sampleName.Data(), (int)ptBin[ipt-1], 9999);
	//char* fname =  Form("ffFiles/leadingJetAnalysis/photonTrackCorr_%s_output_photonPtThr%d_to_%d_jetPtThr30_20131011.root",sampleName.Data(), (int)ptBin[ipt-1], 9999);
	//	char* fname =  Form("ffFiles/jetEnergySmearedBy10percent/photonTrackCorr_%s_output_photonPtThr%d_to_%d_jetPtThr30_20131011.root",sampleName.Data(), (int)ptBin[ipt-1], 9999);
	//	char* fname =  Form("ffFiles/photonEnergyScaled/photonTrackCorr_%s_output_photonPtThr%d_to_%d_jetPtThr30_20131011_photonEnergyScaledBy-0.015.root",sampleName.Data(), (int)ptBin[ipt-1], 9999);


	histFile[icoll][ipt] = new TFile(fname) ;
	cout << " Reading file : " << fname << endl;
	if ( histFile[icoll][ipt]->IsZombie()  == false ) {
	  cout << " Success." << endl;
	  if ( (icoll == kPPDATA) || (icoll == kPPMC) )   {  //  PP
	    int icent = 7 ; 
	    hJetPt[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt]->Get(Form("jetPtForIaa_icent%d_final", icent)) ;
	    cout << " Getting histogram : " << Form("jetPt_icent%d_final", icent) << endl;
	    //	    hJetPt[icoll][7][ipt]->Rebin(10);
	    // hJetPt[icoll][7][ipt]->Scale(1./10);
	    
	  }
	  if ( ( icoll == kHIDATA) ||  (icoll == kHIMC) ) { // PbPb
	    for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
	      hJetPt[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt]->Get(Form("jetPtForIaa_icent%d_final", centBinHI[icent] ) );
	      cout << " Getting histogram : " << Form("jetPt_icent%d_final", centBinHI[icent] ) << endl;
	      //	      hJetPt[icoll][icent][ipt]->Rebin(10);
	      //hJetPt[icoll][icent][ipt]->Scale(1/10.);
	    }
	  }
	}
	else  
	  cout << " no such file " << endl;
      }
    }

    // Calculation of IAA
    for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
      for (int ipt=1 ; ipt<=nPtBin ; ipt++) {
	hIaa[icent][ipt] = (TH1D*)hJetPt[kHIDATA][icent][ipt]->Clone(Form("iaa_%s",hJetPt[kHIDATA][icent][ipt]->GetName()));
	hIaa[icent][ipt]->Divide(hJetPt[kPPDATA][7][ipt]);
      }
    }
    
    
    TH1D* hTempPt = new TH1D("hTemp",";p_{T}^{#gamma} (GeV);",200,10,300);
    
    TCanvas* c2 = new TCanvas("c2","",1000,450);
    makeMultiPanelCanvas(c2,nPtBin,2,0.0,0.0,0.2,0.15,0.02);
    for ( int ipt = 1 ; ipt<=nPtBin  ; ipt++) {

        c2->cd(ipt);

        // draw pp
        hTempPt->SetXTitle("p_{T}^{Jet} (GeV)");
        hTempPt->SetYTitle("#frac{dN}{dp_{T}} #frac{1}{N^{#gamma}}");
        hTempPt->SetAxisRange(30,200,"X");
	//        hTempPt->SetAxisRange(0,0.025,"Y");
	hTempPt->SetAxisRange(0.00007,0.11,"Y");
        handsomeTH1(hTempPt,0);
        hTempPt->DrawCopy();
	gPad->SetLogy();
	

        handsomeTH1(hJetPt[kPPDATA][7][ipt], 1);
        hJetPt[kPPDATA][7][ipt]->SetMarkerStyle(24);
	hJetPt[kPPDATA][7][ipt]->Draw("same");

        // draw pbpb 
        for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
            handsomeTH1(hJetPt[kHIDATA][icent][ipt],kRed);
	    if ( icent == 2 ) hJetPt[kHIDATA][icent][ipt]->SetMarkerStyle(24);
	    hJetPt[kHIDATA][icent][ipt]->Draw("same");
        }
       
        double dx1=0.15;

	drawText(Form("p_{T}^{#gamma} > %dGeV, ", (int)ptBin[ipt-1]), 0.12+dx1+0.25,0.85,1,15);
	/*
	  if ( ipt == nPtBin ) 
	  drawText(Form("p_{T}^{#gamma} > %dGeV, ", (int)ptBin[ipt-1]), 0.12+dx1+0.25,0.85,1,15);
	  else
	  drawText(Form("%dGeV < p_{T}^{#gamma} < %dGeV, ", (int)ptBin[ipt-1], (int)ptBin[ipt]), 0.12+dx1,0.85,1,15);
	*/
	
        onSun(30,0,200,0);

        c2->cd(ipt + nPtBin);
	hTempPt->SetAxisRange(0,2.5,"Y");
	hTempPt->SetYTitle("Ratio of Yield PbPb/pp");
	handsomeTH1(hTempPt,0);
        hTempPt->DrawCopy();
                                                                                                               
        for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
	  handsomeTH1(hIaa[icent][ipt],kRed);
	  if ( icent == 2 )         hIaa[icent][ipt]->SetMarkerStyle(24);
	  // if ( icent == 1 )   
	    hIaa[icent][ipt]->Draw("same");
	  jumSun(30,1,200,1);
        }
	
	
	
	
    }
    

    c2->cd(1);
    
    TLegend *l2 = new TLegend(0.5933981,0.3877892,0.9981436,0.7857262,NULL,"brNDC");
    easyLeg(l2,"2.76TeV");
    l2->AddEntry(hJetPt[kPPDATA][7][1],"pp", "p");
    l2->AddEntry(hJetPt[kHIDATA][2][1],"PbPb 30-100%", "p");
    l2->AddEntry(hJetPt[kHIDATA][1][1],"PbPb 0-30%", "p");
    l2->Draw();
    if (saveFigures)   c2->SaveAs("figures/pT_dependence_IAA_figure1.pdf");
    if (saveFigures)   c2->SaveAs("figures/pT_dependence_IAA_figure1.gif");


    TFile * fResults =  new TFile("resultHistograms.root","update");

    for ( int ipt = 1 ; ipt<=nPtBin  ; ipt++) {
      hJetPt[kPPDATA][7][ipt]->SetName(Form("dNdJetPt_forIaa_pp_ptBin%dAndHigher",ipt));
      hJetPt[kPPDATA][7][ipt]->Write();

      for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
        hJetPt[kHIDATA][icent][ipt]->SetName(Form("dNdJetPt_forIaa_pbpb_centralityBin%d_ptBin%dAndHigher",icent,ipt));
	hJetPt[kHIDATA][icent][ipt]->Write();
	
        hIaa[icent][ipt]->SetName(Form("Ryaa_centralityBin%d_ptBin%dAndHigher",icent,ipt));
	hIaa[icent][ipt]->Write();
      }

    }
    fResults->Close();
    
    
    
}
void drawPtDependencePPSmeared(int centBin = 10030, TString dirName="nominal", int prodDate=20131021, int jetPtCut=30) {
  TH1::SetDefaultSumw2();

  const int nPtBin = 4;
  double ptBin[nPtBin+1] = {40, 50,60,80,9999}; 
  double ptBinPaDraw[nPtBin+1] = { 40.5 ,49.5, 58.5,  76.5,  123. } ;
  // double AvePtBin[nPtBin+1] = { 45, 54.1479, 67.4204, 99.6956, 9999};
    
  const int nCentBinHI = 2;
  const int centBinHI[nCentBinHI +1] = {-1, 10030, 13099}; 

  TH1D* hxjg[7][10][6]; // [Collision][centrality][pt]
  TH1D* hJetPt[7][10][6]; // [Collision][centrality][pt]
  TH1D* hJetPtIaaBin[7][10][6]; // [Collision][centrality][pt]
  TH1D* hDphi[7][10][6]; // [Collision][centrality][pt]
  TH1D* hEta[7][10][6]; // [Collision][centrality][pt]
  TH1D* meanXjg[7][10];      // [Collision][centrality]
  TH1D* meanJetPt[7][10];      // [Collisi on][centrality]

  TH1D* rjg[7][10];     //  [Collision][centrality]
  for (int icoll=0 ; icoll<6  ; icoll++) {
    for (int icent=1 ; icent<= 10 ; icent++) {
      meanXjg[icoll][icent] = new TH1D( Form("meanXjg_icoll%d_icent%d",icoll,icent), ";p_{T}^{#gamma} (GeV); <X_{J#gamma}>",nPtBin,ptBinPaDraw);
      meanJetPt[icoll][icent] = new TH1D( Form("meanJetPt_icoll%d_icent%d",icoll,icent), ";p_{T}^{#gamma} (GeV); <p_{T}^{Jet}>",nPtBin,ptBinPaDraw);
      rjg[icoll][icent] = new TH1D( Form("rjg_icoll%d_icent%d",icoll,icent), ";p_{T}^{#gamma} (GeV); R_{J#gamma}",nPtBin,ptBinPaDraw);

      for (int ipt=1 ; ipt<=nPtBin ; ipt++) {
	hxjg[icoll][icent][ipt] = NULL;
	hJetPt[icoll][icent][ipt] = NULL;
	hJetPtIaaBin[icoll][icent][ipt] = NULL;
	hDphi[icoll][icent][ipt] = NULL;
	hEta[icoll][icent][ipt] = NULL;
      }

    }
  }

  TFile* histFile[7][6];  // [Collision][pt]                                                                                          
  for (int ipt=1 ; ipt<=nPtBin ; ipt++) {
    for (int icoll=0 ; icoll<6 ; icoll++) {
      TString sampleName = getSampleName( icoll ) ;
      char* fname =  Form("ffFiles/%s/photonTrackCorr_%s_output_photonPtThr%d_to_%d_jetPtThr%d_%d.root",dirName.Data(), sampleName.Data(), (int)ptBin[ipt-1], (int)ptBin[ipt], (int)jetPtCut, prodDate);

      histFile[icoll][ipt] = new TFile(fname) ;
      cout << " Reading file : " << fname << endl;

      if ( histFile[icoll][ipt]->IsZombie()  == false ) {
	cout << " Success." << endl;
	if ( (icoll == kPPDATA) || (icoll == kPPMC) )   {  //  PP
	  int icent = 7 ; 
	  hxjg[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt]->Get(Form("xjg_icent%d_final", centBin));
	  cout << " Getting histogram : " << Form("xjg_icent%d_final", icent) << endl;
	  hJetPt[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt]->Get(Form("jetPt_icent%d_final", centBin));
	  cout << " Getting histogram : " << Form("jetPt_icent%d_final", icent) << endl;
	  hJetPtIaaBin[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt]->Get(Form("jetPtForIaa_icent%d_final", centBin));
	  cout << " Getting histogram : " << Form("jetPtForIaa_icent%d_final", icent) << endl;
	  hDphi[icoll][icent][ipt]  = (TH1D*)histFile[icoll][ipt]->Get(Form("jetDphi_icent%d_final", centBin));
	  cout << " Getting histogram : " << Form("jetDphi_icent%d_final", icent) << endl;
	  hEta[icoll][icent][ipt]  = (TH1D*)histFile[icoll][ipt]->Get(Form("etaJg_icent%d_final", centBin)) ;
	  cout << " Getting histogram : " << Form("etaJg_icent%d_final", centBin) << endl;

	}

	if ( ( icoll == kHIDATA) ||  (icoll == kHIMC) ) { // PbPb
	  for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
	    hxjg[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt]->Get(Form("xjg_icent%d_final", centBinHI[icent] )) ;
	    cout << " Getting histogram : " << Form("xjg_icent%d_final", centBinHI[icent] ) << endl;
	    hJetPt[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt]->Get(Form("jetPt_icent%d_final", centBinHI[icent] ) );
	    cout << " Getting histogram : " << Form("jetPt_icent%d_final", centBinHI[icent] ) << endl;
	    hJetPtIaaBin[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt]->Get(Form("jetPtForIaa_icent%d_final", centBinHI[icent] ) );
	    cout << " Getting histogram : " << Form("jetPtForIaa_icent%d_final", centBinHI[icent] ) << endl;
	    hDphi[icoll][icent][ipt]  = (TH1D*)histFile[icoll][ipt]->Get(Form("jetDphi_icent%d_final", centBinHI[icent] ) ) ;
	    cout << " Getting histogram : " << Form("jetDphi_icent%d_final", icent)<< endl;
	    hEta[icoll][icent][ipt]  = (TH1D*)histFile[icoll][ipt]->Get(Form("etaJg_icent%d_final", centBinHI[icent] ) ) ;
	    cout << " Getting histogram : " << Form("etaJg_icent%d_final", icent)<< endl;
	  }
	}
      }
      else  
	cout << " no such file " << endl;
    }
  }

  for (int ipt=1 ; ipt<=nPtBin ; ipt++) {
    for (int icoll=0 ; icoll<6 ; icoll++) {
      for (int icent=1 ; icent<= 10 ; icent++ ) { 
	if ( hxjg[icoll][icent][ipt] == NULL ) 
	  continue;   // emtpy histogram 
	double rVal, rErr;

	rVal = hxjg[icoll][icent][ipt]->IntegralAndError(1, hxjg[icoll][icent][ipt]->GetNbinsX(), rErr, "width");
	printf("icoll: %d icent: %d ipt: %d rval: %lf\n",icoll, icent, ipt, rVal);
	rjg[icoll][icent]->SetBinContent( ipt, rVal );
	rjg[icoll][icent]->SetBinError  ( ipt, rErr );

	meanXjg[icoll][icent]->SetBinContent( ipt, hxjg[icoll][icent][ipt]->GetMean() );
	meanXjg[icoll][icent]->SetBinError  ( ipt, hxjg[icoll][icent][ipt]->GetMeanError() );

	meanJetPt[icoll][icent]->SetBinContent( ipt, hJetPt[icoll][icent][ipt]->GetMean() );
	meanJetPt[icoll][icent]->SetBinError  ( ipt, hJetPt[icoll][icent][ipt]->GetMeanError() );


      }
    }
  }

  TCanvas* c1 = new TCanvas("c1","",1200,350);
  makeMultiPanelCanvas(c1,nPtBin,1,0.0,0.0,0.2,0.15,0.02);
  for ( int ipt = 1 ; ipt<=nPtBin  ; ipt++) {

    c1->cd(ipt);

    // draw pp
    handsomeTH1(hDphi[kPPDATA][7][ipt], 1);
    hDphi[kPPDATA][7][ipt]->SetXTitle("#Delta#phi_{J#gamma}");
    hDphi[kPPDATA][7][ipt]->SetYTitle("Normalized entries");
    hDphi[kPPDATA][7][ipt]->SetMarkerStyle(24);
    hDphi[kPPDATA][7][ipt]->Scale(1./hDphi[kPPDATA][7][ipt]->Integral("width"));       
    hDphi[kPPDATA][7][ipt]->SetAxisRange(0,3.141592,"X");
    hDphi[kPPDATA][7][ipt]->SetAxisRange(0.01,30,"Y");
    hDphi[kPPDATA][7][ipt]->Draw();
    // draw pbpb 
    for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
      handsomeTH1(hDphi[kHIDATA][icent][ipt],kRed);
      if ( icent == 2 ) hDphi[kHIDATA][icent][ipt]->SetMarkerStyle(24);
      hDphi[kHIDATA][icent][ipt]->Scale(1./hDphi[kHIDATA][icent][ipt]->Integral("width"));
      hDphi[kHIDATA][icent][ipt]->Draw("same");

    }

    gPad->SetLogy();
    //    onSun(30,0,200,0);
  }
  c1->cd(1);
  TLegend *ly = new TLegend(0.4913112,0.6561548,0.9997611,0.9431145,NULL,"brNDC");
  easyLeg(ly,"2.76TeV");
  ly->AddEntry(hDphi[kPPDATA][7][1],"pp ","p");
  ly->AddEntry(hDphi[kHIDATA][2][1],"PbPb 0-30%","p");

  TLegend *l1 = new TLegend(0.1995968,0.7097458,0.7076613,0.9237288,NULL,"brNDC");
  easyLeg(l1,"2.76TeV");
  l1->AddEntry(hDphi[kPPDATA][7][1],"pp ","p");
  l1->AddEntry(hDphi[kHIDATA][2][1],"PbPb 30-100%","p");
  l1->AddEntry(hDphi[kHIDATA][1][1],"PbPb 0-30%","p");
  l1->Draw();

  // c1->SaveAs("figures/pT_dependence_dphi_pp_pbpb_figure1.pdf");
  // c1->SaveAs("figures/pT_dependence_dphi_pp_pbpb_figure1.gif");





  TH1D* hTempPt = new TH1D("hTemp",";p_{T}^{#gamma} (GeV);",200,10,300);

  TCanvas* c2 = new TCanvas("c2","",1200,350);
  makeMultiPanelCanvas(c2,nPtBin,1,0.0,0.0,0.2,0.15,0.02);
  for ( int ipt = 1 ; ipt<=nPtBin  ; ipt++) {

    c2->cd(ipt);

    // draw pp
    hTempPt->SetXTitle("p_{T}^{Jet} (GeV)");
    hTempPt->SetYTitle("#frac{dN}{dp_{T}} #frac{1}{N}");
    hTempPt->SetAxisRange(10,150,"X");
    //        hTempPt->SetAxisRange(0,0.025,"Y");
    hTempPt->SetAxisRange(0,0.08,"Y");
    handsomeTH1(hTempPt,0);
    hTempPt->DrawCopy();
	
    //    hJetPt[kPPDATA][7][ipt]->Scale(1./rjg[kPPDATA][7]->GetBinContent(ipt)); // rjg normalization                      
		

    handsomeTH1(hJetPt[kPPDATA][7][ipt], 1);
    hJetPt[kPPDATA][7][ipt]->SetMarkerStyle(24);
    hJetPt[kPPDATA][7][ipt]->Draw("same");

    // draw pbpb 
    for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
      handsomeTH1(hJetPt[kHIDATA][icent][ipt],kRed);
      //      hJetPt[kHIDATA][icent][ipt]->Scale(1./rjg[kHIDATA][icent]->GetBinContent(ipt));  // rjg normalization
      //      hJetPt[kHIDATA][icent][ipt]->Rebin(10);
      //     hJetPt[kHIDATA][icent][ipt]->Scale(1/10.);
      if ( icent == 2 ) hJetPt[kHIDATA][icent][ipt]->SetMarkerStyle(24);
      if ( icent == 2 ) hJetPt[kHIDATA][icent][ipt]->Draw("same");
      if ( icent == 1 ) hJetPt[kHIDATA][icent][ipt]->Draw("same");
    }
       
    double dx1=0.15;
    if ( ipt == nPtBin ) 
      drawText(Form("p_{T}^{#gamma} > %dGeV, ", (int)ptBin[ipt-1]), 0.12+dx1+0.25,0.85,1,15);//yeonju 130823
    else
      drawText(Form("%dGeV < p_{T}^{#gamma} < %dGeV, ", (int)ptBin[ipt-1], (int)ptBin[ipt]), 0.12+dx1,0.85,1,15);//yeonju 130823

    onSun(30,0,200,0);
  }
  c2->cd(1);
  l1->Draw();  

  c2->SaveAs("figures/pT_dependence_jetPt_pp_pbpb_figure1.pdf");
  c2->SaveAs("figures/pT_dependence_jetPt_pp_pbpb_figure1.gif");

  TLegend *l2 = new TLegend(0.2116935,0.7012712,0.6149194,0.904661,NULL,"brNDC");
  easyLeg(l2,"2.76TeV");
  l2->AddEntry(hDphi[kPPDATA][7][1],"pp ","p");
  l2->AddEntry(hDphi[kHIDATA][1][1],"PbPb 30-100%","p");
  l2->AddEntry(hDphi[kHIDATA][2][1],"PbPb 0-30%","p");

  TCanvas* c21 = new TCanvas("c21","",500,500);
  handsomeTH1(meanJetPt[kPPDATA][7], 1);
  meanJetPt[kPPDATA][7]->SetYTitle("<p_{T}^{Jet}>  (>30GeV)");
  meanJetPt[kPPDATA][7]->SetMarkerStyle(24);
  //  meanJetPt[kPPDATA][7]->SetAxisRange(-2,2,"X");
  meanJetPt[kPPDATA][7]->SetAxisRange(40,90,"Y");
  meanJetPt[kPPDATA][7]->Draw();

  for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
    handsomeTH1(meanJetPt[kHIDATA][icent],kRed);
    if ( icent == 2 ) meanJetPt[kHIDATA][icent]->SetMarkerStyle(24);
    //if ( icent == 2 ) meanJetPt[kHIDATA][icent]->Draw("same");
    meanJetPt[kHIDATA][icent]->Draw("same");
  }
  l1 ->Draw();
  c21->SaveAs("figures/pT_dependence_jetPt_pp_pbpb_figure2.pdf");
  c21->SaveAs("figures/pT_dependence_jetPt_pp_pbpb_figure2.gif");

  TCanvas* c3 = new TCanvas("c3","",1200,350);
  makeMultiPanelCanvas(c3,nPtBin,1,0.0,0.0,0.2,0.15,0.02);
  for ( int ipt = 1 ; ipt<=nPtBin  ; ipt++) {

    c3->cd(ipt);

    // draw pp
    handsomeTH1(hxjg[kPPDATA][7][ipt], 1);
    hxjg[kPPDATA][7][ipt]->SetXTitle("x_{J#gamma}");
    hxjg[kPPDATA][7][ipt]->SetYTitle("#frac{dN}{dp_{T}} #frac{1}{N}");
    hxjg[kPPDATA][7][ipt]->SetMarkerStyle(24);

    //    hxjg[kPPDATA][7][ipt]->Scale(1./rjg[kPPDATA][7]->GetBinContent(ipt)); // rjg normalization 

    //    hxjg[kPPDATA][7][ipt]->Rebin(10);
    //    hxjg[kPPDATA][7][ipt]->Scale(1./10);
    hxjg[kPPDATA][7][ipt]->SetAxisRange(0,2.5,"X");
    hxjg[kPPDATA][7][ipt]->SetAxisRange(0,3,"Y");
    hxjg[kPPDATA][7][ipt]->Draw();

    // draw pbpb
    for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
      handsomeTH1(hxjg[kHIDATA][icent][ipt],kRed);
      //      hxjg[kHIDATA][icent][ipt]->Scale(1./rjg[kHIDATA][icent]->GetBinContent(ipt)); // rjg normalization    
      //      hxjg[kHIDATA][icent][ipt]->Rebin(10);
      //   hxjg[kHIDATA][icent][ipt]->Scale(1./10);
      if ( icent == 2 ) hxjg[kHIDATA][icent][ipt]->SetMarkerStyle(24);
      if ( icent == 2 ) hxjg[kHIDATA][icent][ipt]->Draw("same");
      if ( icent == 1 ) hxjg[kHIDATA][icent][ipt]->Draw("same");

    }
    double dx1=0.15;
    if ( ipt == nPtBin ) 
      drawText(Form("p_{T}^{#gamma} > %dGeV, ", (int)ptBin[ipt-1]), 0.12+dx1+0.25,0.85,1,15);//yeonju 130823
    else
      drawText(Form("%dGeV < p_{T}^{#gamma} < %dGeV, ", (int)ptBin[ipt-1], (int)ptBin[ipt]), 0.12+dx1,0.85,1,15);//yeonju 130823

 
    onSun(30,0,200,0);
  }
  c3->cd(1);
  l1->Draw();  

  c3->SaveAs("figures/pT_dependence_xjg_pp_pbpb_figure1.pdf");
  c3->SaveAs("figures/pT_dependence_xjg_pp_pbpb_figure1.gif");

  TCanvas* c31 = new TCanvas("c31","",500,500);
  handsomeTH1(meanXjg[kPPDATA][7], 1);
  meanXjg[kPPDATA][7]->SetYTitle("<x_{J#gamma}>  (>30GeV)");
  meanXjg[kPPDATA][7]->SetMarkerStyle(24);
  //  meanXjg[kPPDATA][7]->SetAxisRange(-2,2,"X");
  meanXjg[kPPDATA][7]->SetAxisRange(0.6,1.2,"Y");
  meanXjg[kPPDATA][7]->Draw();

  for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
    handsomeTH1(meanXjg[kHIDATA][icent],kRed);
    if ( icent == 2 ) meanXjg[kHIDATA][icent]->SetMarkerStyle(24);
    //if ( icent != 2 ) meanXjg[kHIDATA][icent]->Draw("same");
    meanXjg[kHIDATA][icent]->Draw("same");
  }
  l1->Draw();
     c31->SaveAs("figures/pT_dependence_xjg_pp_pbpb_figure1.pdf");
     c31->SaveAs("figures/pT_dependence_xjg_pp_pbpb_figure1.gif");
    

  TCanvas* c_rjg = new TCanvas("c_rjg","",500,500);
  handsomeTH1(rjg[kPPDATA][7], 1);
  rjg[kPPDATA][7]->SetYTitle("r_{J#gamma}");
  rjg[kPPDATA][7]->SetMarkerStyle(24);
  //  rjg[kPPDATA][7]->SetAxisRange(-2,2,"X");
  rjg[kPPDATA][7]->SetAxisRange(0.0,1.1,"Y");
  rjg[kPPDATA][7]->Draw();

  for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
    handsomeTH1(rjg[kHIDATA][icent],kRed);
    if ( icent == 2 ) rjg[kHIDATA][icent]->SetMarkerStyle(24);
    //        if ( icent != 2 ) rjg[kHIDATA][icent]->Draw("same");
    rjg[kHIDATA][icent]->Draw("same");
  }
  l1->Draw();
  c_rjg->SaveAs("figures/pT_dependence_rjg_pp_pbpb_figure1.pdf");
  c_rjg->SaveAs("figures/pT_dependence_rjg_pp_pbpb_figure1.gif");
  
  
  
  // Save the final root histogram files
  TFile * fResults =  new TFile(Form("resultHistograms_ppSmeared%d.root",centBin),"update");
  
  
  // pp 
    
  meanJetPt[kPPDATA][7]->SetName(Form("meanJetPt_pp"));
  meanJetPt[kPPDATA][7]->Write();

  meanXjg[kPPDATA][7]->SetName(Form("meanXjg_pp"));
  meanXjg[kPPDATA][7]->Write();
    
  rjg[kPPDATA][7]->SetName(Form("meanRjg_pp"));
  rjg[kPPDATA][7]->Write();
    
  for ( int ipt = 1 ; ipt<=nPtBin  ; ipt++) {
    hJetPt[kPPDATA][7][ipt]->SetName(Form("dNdJetPt_pp_ptBin%d",ipt));
    hJetPt[kPPDATA][7][ipt]->Write();
    hJetPtIaaBin[kPPDATA][7][ipt]->SetName(Form("dNdJetPt_IaaBin_pp_ptBin%d",ipt));
    hJetPtIaaBin[kPPDATA][7][ipt]->Write();
      
    hxjg[kPPDATA][7][ipt]->SetName(Form("dNdXjg_pp_ptBin%d",ipt));
    hxjg[kPPDATA][7][ipt]->Write();

    hDphi[kPPDATA][7][ipt]->SetName(Form("dNdphi_pp_ptBin%d",ipt));
    hDphi[kPPDATA][7][ipt]->Write();
      
      
  }
    

  // PbPb 
    
  for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
    for ( int ipt = 1 ; ipt<=nPtBin  ; ipt++) {
      hJetPt[kHIDATA][icent][ipt]->SetName(Form("dNdJetPt_pbpb_centralityBin%d_ptBin%d",icent,ipt));
      hJetPt[kHIDATA][icent][ipt]->Write();	
      hJetPtIaaBin[kHIDATA][icent][ipt]->SetName(Form("dNdJetPt_IaaBin_pbpb_centralityBin%d_ptBin%d",icent,ipt));
      hJetPtIaaBin[kHIDATA][icent][ipt]->Write();	
  
      hxjg[kHIDATA][icent][ipt]->SetName(Form("dNdXjg_pbpb_centralityBin%d_ptBin%d",icent,ipt));
      hxjg[kHIDATA][icent][ipt]->Write();

      hDphi[kHIDATA][icent][ipt]->SetName(Form("dNdphi_pbpb_centralityBin%d_ptBin%d",icent,ipt));
      hDphi[kHIDATA][icent][ipt]->Write();
	
    }
      
    meanJetPt[kHIDATA][icent]->SetName(Form("meanJetPt_pbpb_centralityBin%d",icent));
    meanJetPt[kHIDATA][icent]->Write();
    meanXjg[kHIDATA][icent]->SetName(Form("meanXjg_pbpb_centralityBin%d",icent));
    meanXjg[kHIDATA][icent]->Write();
      
    rjg[kHIDATA][icent]->SetName(Form("meanRjg_pbpb_centralityBin%d",icent));
    rjg[kHIDATA][icent]->Write();
  }
    
  fResults->Close();
    
    
}
示例#21
0
文件: DrawEff_DS.C 项目: XuQiao/HI
void DrawEff_DS(){
gStyle->SetOptStat(kFALSE);
gStyle->SetErrorX(0);
//bool isweight=kFALSE;
bool isweight=kTRUE;
bool isHF=kTRUE;
//bool isHF=kFALSE;
if(isweight)
TString dir="weight";
else
TString dir="noweight";
const int Nhist=4;	const int NGen=1; const int Ncent=6;
//const double HFbin[]={0,0.1,0.2,0.4,0.6,0.8,1,2,4,6,9,12,15,20,30,50,75,100};
const double xerr[Ncent]={0,0,0,0,0,0};
/*
const double HFbin_cent[Nhist][Ncent+1]={
{0,2.92,10.1,19.3,23.7,30.2,100},
{0,1.03,5.00,11.6,15.0,20.3,100},
{0,2.7,12.6,28.6,36.9,49.6,100}};
*/
const double HFbin_cent[Nhist][Ncent+1]={
{0,2.725,10.065,19.565,23.975,30.455,100},
{0,0.975,5.005,11.775,15.285,20.725,100},
{0,2.515,12.465,28.855,37.235,50.085,100}};
const double cent[Ncent]={95,75,45,25,15,5};
const int nHFbin=sizeof(HFbin)/sizeof(double)-1;
//double color[NGen][Nhist]={{2,1,4},{2,1,4}};
//double Style[NGen][Nhist]={{20,24,28},{20,24,28}};
double color[NGen][Nhist]={{2,1,4}};
double Style[NGen][Nhist]={{20,24,28}};
//TString Gen[NGen]={"Hijing","Epos"};
TString Gen[NGen]={"Hijing"};
TString histoname[Nhist]={"HFEnergy4","HFEnergyPlus4","HFEnergyPlus","Ntrk"};
TString etarange[Nhist]={" HF E_{T} |#eta|>4"," HF E_{T} #eta>4"," HF E_{T} #eta>0",""};
TString filename[NGen];
TFile* f[NGen];
TH1F* h_or[NGen][Nhist];	TH1F* reh_or[NGen][Nhist];
TH1F* h_tr[NGen][Nhist];	TH1F* reh_tr[NGen][Nhist];
TH1F* h_ds[NGen][Nhist];	TH1F* reh_ds[NGen][Nhist];
TH1F* h_eff[NGen][Nhist];	TH1F* reh_eff[NGen][Nhist];

TLatex* T1[Nhist];	TLatex* T2;	TLatex* T3[NGen];
TF1 *fitEff[NGen][Nhist];
//TGraphAsymmErrors *gEff[NGen][Nhist];
TGraph *gEff[NGen][Nhist];
c1 = new TCanvas("c1"," ",800,500);
c2 = new TCanvas("c2"," ",800,700);
makeMultiPanelCanvas(c1,NGen,1,0.03,0.03,0.14,0.14,0.03);
makeMultiPanelCanvas(c2,1,1,0.03,0.03,0.03,0.03,0.03);

//for |eta|>4 HFEnergy:
/*
for(int k=0;k<NGen;k++)
for(int j=0;j<Nhist;j++)
fitEff[k][j]= new TF1(Form("fitEff_%s%s",Gen[k].Data(),histoname[j]),"[0]-[1]*exp([2]*x)-[3]*exp(-[4]*x)",0,300);

fitEff[0][0]->SetParameters(0.999876,0.44648,-1.78911,0.242036,0.549932);
fitEff[0][1]->SetParameters(1.,0.367894,-3.36629,0.104605,0.690272);
fitEff[0][2]->SetParameters(0.99981,0.697501,-2.59569,0.15323,0.411757);
fitEff[1][0]->SetParameters(0.999918,0.691843,-0.785042,0.0352768,0.449521);
fitEff[1][1]->SetParameters(0.999929,0.284,-2.25636,0.264114,0.951221);
fitEff[1][2]->SetParameters(0.999887,0.5,-2.39395,0.373215,0.550851);
*/

for(int k=0;k<NGen;k++){
T3[k]=new TLatex(0.45,0.93,Gen[k]);
T3[k]->SetNDC();
T3[k]->SetTextAlign(12);
T3[k]->SetTextSize(0.05);
T3[k]->SetTextColor(1);
T3[k]->SetTextFont(42);
}
for(int j=0;j<Nhist;j++){
T1[j]=new TLatex(0.4,0.85,etarange[j]);
T1[j]->SetNDC();
T1[j]->SetTextAlign(12);
T1[j]->SetTextSize(0.05);
T1[j]->SetTextColor(1);
T1[j]->SetTextFont(42);
}
T2=new TLatex(0.2,0.25,"Double Side");
T2->SetNDC();
T2->SetTextAlign(12);
T2->SetTextSize(0.06);
T2->SetTextColor(1);
T2->SetTextFont(42);
j=3;
for(int k=0;k<NGen;k++){
//for(int j=0;j<Nhist;j++){
filename[k]=Form("output/%s/pPbHist_%s_DS",dir.Data(),Gen[k].Data());
f[k]=TFile::Open(Form("%s.root",filename[k].Data()));
h_or[k][j]=(TH1F*)f[k]->Get(Form("h%s",histoname[j].Data()));
h_tr[k][j]=(TH1F*)f[k]->Get(Form("h%s_tr",histoname[j].Data()));
h_ds[k][j]=(TH1F*)f[k]->Get(Form("h%s_DS",histoname[j].Data()));
h_eff[k][j]=(TH1F*)f[k]->Get(Form("hEff_%s",histoname[j].Data()));
fixedFontHist(h_or[k][j],1.8,2);
fixedFontHist(h_tr[k][j],1.8,2);
fixedFontHist(h_ds[k][j],1.8,2);
//reh_or[k][j]=(TH1F*)h_or[k][j]->Clone(Form("re%s%s",Gen[k].Data(),histoname[j].Data()));
//reh_tr[k][j]=(TH1F*)h_tr[k][j]->Clone(Form("re%s%s_tr",Gen[k].Data(),histoname[j].Data()));
//reh_ds[k][j]=(TH1F*)h_ds[k][j]->Clone(Form("re%s%s_ds",Gen[k].Data(),histoname[j].Data()));

//reh_or[k][j]=(TH1F*)h_or[k][j]->Rebin(Ncent,Form("re%s%s",Gen[k].Data(),histoname[j].Data()),HFbin_cent[j]);
//reh_tr[k][j]=(TH1F*)h_tr[k][j]->Rebin(Ncent,Form("re%s%s_tr",Gen[k].Data(),histoname[j].Data()),HFbin_cent[j]);
//reh_ds[k][j]=(TH1F*)h_ds[k][j]->Rebin(Ncent,Form("re%s%s_ds",Gen[k].Data(),histoname[j].Data()),HFbin_cent[j]);
reh_or[k][j]=(TH1F*)h_or[k][j]->Rebin(nHFbin,Form("re%s%s",Gen[k].Data(),histoname[j].Data()),HFbin);
reh_tr[k][j]=(TH1F*)h_tr[k][j]->Rebin(nHFbin,Form("re%s%s_tr",Gen[k].Data(),histoname[j].Data()),HFbin);
reh_ds[k][j]=(TH1F*)h_ds[k][j]->Rebin(nHFbin,Form("re%s%s_ds",Gen[k].Data(),histoname[j].Data()),HFbin);
//normalizeByBinWidth(reh_or[k][j]);
//normalizeByBinWidth(reh_tr[k][j]);
//normalizeByBinWidth(reh_ds[k][j]);

//gEff[k][j]=new TGraphAsymmErrors();
gEff[k][j]=new TGraph(h_eff[k][j]);
gEff[k][j]->SetPoint(0,0,1);
gEff[k][j]->SetName(Form("gEff_%s%s",Gen[k].Data(),histoname[j].Data()));
//gEff[k][j]->BayesDivide(reh_tr[k][j],reh_ds[k][j]);
gEff[k][j]->SetMarkerColor(color[k][j]);
gEff[k][j]->SetLineColor(color[k][j]);
gEff[k][j]->SetMarkerStyle(Style[k][j]);
gEff[k][j]->SetMarkerSize(1.2);
gEff[k][j]->GetXaxis()->SetLimits(0.01,99.9);
gEff[k][j]->SetTitle("");
//}
}

TH1D * hFrame = new TH1D("","",100,0,100.);
if(!isHF){
   hFrame->GetXaxis()->SetLabelOffset(999);
   hFrame->GetXaxis()->SetTickLength(0);}
   hFrame->GetYaxis()->SetTitle("Event Selection Efficiency");
	hFrame->SetMaximum(1.09);
	hFrame->SetMinimum(0);
if(isHF)
hFrame->GetXaxis()->SetTitle("HF E_{T} (GeV/c)");
if(j==3)
hFrame->GetXaxis()->SetTitle("track Mult");
   hFrame->GetYaxis()->SetTitleSize(0.05);
        fixedFontHist(hFrame);
  hFrame->GetYaxis()->SetTitleOffset(1.5);

for(k=0;k<NGen;k++){
if(isHF)
c1->cd(k+1)->SetLogx();
else
c1->cd(k+1);
TLegend *leg=new TLegend(0.60,0.2,0.75,0.4);
if(k!=0){
hFrame->GetYaxis()->SetTitle("");
hFrame->GetYaxis()->SetLabelSize(0);
}
hFrame->DrawCopy();
//for(j=0;j<Nhist;j++){
if(isHF)
gEff[k][j]->Draw("Psame");
else{
ReverseXAxis(gEff[k][j],0.05);
ReverseXGraph(gEff[k][j]);
}
//fitEff[k][j]->SetLineStyle(color[k][j]);
//fitEff[k][j]->SetLineColor(color[k][j]);
//fitEff[k][j]->Draw("same");
leg->AddEntry(gEff[k][j],etarange[j],"lp");
//}
leg->SetTextSize(0.05);
leg->SetBorderSize(0);
leg->SetFillColor(0);
TLine *l=new TLine(0,1,100,1);
l->SetLineStyle(2);

l->Draw("same");
leg->Draw("same");
T3[k]->Draw("same");
}
if(isHF)
c1->Print(Form("pic/OwnBinning/pPbHist_%s_DS_HF.png",dir.Data()));
else
c1->Print(Form("pic/OwnBinning/pPbHist_%s_DS_cent.png",dir.Data()));


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

if(isHF)
//c2->cd()->SetLogx();
//else
c2->cd();
TLegend *leg=new TLegend(0.7,0.2,0.85,0.4);
hFrame->GetYaxis()->SetTitle("Event Selection Efficiency");
hFrame->GetYaxis()->SetLabelSize(18);
hFrame->GetYaxis()->SetTitleOffset(1);
hFrame->DrawCopy();
for(k=0;k<NGen;k++){
if(k==0){
gEff[k][j]->SetMarkerColor(1);
gEff[k][j]->SetLineColor(1);
gEff[k][j]->SetMarkerStyle(20);
gEff[k][j]->SetMarkerSize(1.6);
}
else{
gEff[k][j]->SetMarkerColor(2);
gEff[k][j]->SetLineColor(2);
gEff[k][j]->SetMarkerStyle(24);
gEff[k][j]->SetMarkerSize(1.6);
}
if(isHF)
gEff[k][j]->Draw("Psame");
else{
ReverseXAxis(gEff[k][j],0.05);
ReverseXGraph(gEff[k][j]);
}
leg->SetTextSize(0.05);
leg->SetBorderSize(0);
leg->SetFillColor(0);
leg->AddEntry(gEff[k][j],Gen[k],"p");
TLine *l=new TLine(0,1,100,1);
l->SetLineStyle(2);
}
T1[j]->Draw("same");
leg->Draw("same");
l->Draw("same");

if(isHF)
c2->Print(Form("pic/OwnBinning/pPbHist_%s_DS_%s_HF.png",dir.Data(),histoname[j].Data()));
else
c2->Print(Form("pic/OwnBinning/pPbHist_%s_DS_%s_cent.png",dir.Data(),histoname[j].Data()));

}
示例#22
0
void photonTemplateProducer(int cutOpt=3, int ppHI = kHI, int isoChoice = kSumIso, int isoCut = -100, bool onlygjEvents=false, float specialSbCut=10, float mcSigShift=0, float sbBkgShift=0) {
  
  CutAndBinCollection cab;
  cab.setCuts(cutOpt);
  int nPtBin = cab.getNPtBin();
  vector<double> ptBinVector = cab.getPtBin();
  double ptBin[100];
  for ( int i = 0 ; i<=nPtBin ;i++) {
    ptBin[i] = ptBinVector[i];
  }
  
  int nCentBin = cab.getNCentBin();
  vector<double> centBinVector = cab.getCentBin();
  double centBin[100];
  for ( int i = 0 ; i<=nCentBin ;i++) {
    centBin[i] = centBinVector[i];
  }
  
  TString pphiLabel = "";
  if ( ppHI == kPP) pphiLabel = "pp";
  
  TCanvas* c1[5];
    
   TH1D* hData[5][5];
   TH1D* hSig[5][5];
   TH1D* hBkg[5][5];
   
   //   TH1D* hDatapp[5];
   //   TH1D* hSigpp[5];
   //   TH1D* hBkgpp[5];
   
   TH1D* hBkgMCsr[5][5];
   TH1D* hBkgMCsb[5][5];
      
   TH1D* rawSpectra[5];
   TH1D* finSpectra[5];
    
   TH2D* hPurity2D = new TH2D("hPurity2D",";pT(GeV);Centrality bin",nPtBin,ptBin,nCentBin,centBin);
   
   int nCent(-1);
   if ( ppHI == kHI ) nCent = nCentBin;
   if ( ppHI == kPP ) nCent = 1;
   
   for ( int icent = 1 ; icent<=nCent ; icent++) {
      rawSpectra[icent] = new TH1D(Form("rawSpec_icent%d_%s",icent,getIsoLabel(isoChoice).Data()),"",nPtBin,ptBin);
   }

   
   for (int ipt = 1; ipt <= nPtBin ; ipt++) { 
      c1[ipt] = new TCanvas(Form("c1_ipt%d",ipt),"",700,700);
      if ( ppHI == kHI )  makeMultiPanelCanvas(c1[ipt],nCent/2,2,0.0,0.0,0.2,0.15,0.02);

      TCut ptCut = Form("corrPt>%.2f && corrPt<%.2f",(float)ptBin[ipt-1],(float)ptBin[ipt]); 
      

      for ( int icent = 1 ; icent<=nCent ; icent++) { 
	 int lowCent =  centBinVector[icent-1];    
	 int highCent = centBinVector[icent]-1;
	 
	 hData[icent][ipt]  = new TH1D(Form("hData_cent%d_pt%d",icent,ipt),";shower shape (#sigma_{#eta#eta});Entries per photon candidate;",25,0,0.025);
	 hSig[icent][ipt]   = (TH1D*)hData[icent][ipt]->Clone(Form("hSig_cent%d_pt%d",icent,ipt));
	 hBkg[icent][ipt]   = (TH1D*)hData[icent][ipt]->Clone(Form("hBkg_cent%d_pt%d",icent,ipt));
	 hBkgMCsr[icent][ipt] = (TH1D*)hData[icent][ipt]->Clone(Form("hBkgMCsr_cent%d_pt%d",icent,ipt));
	 hBkgMCsb[icent][ipt] =(TH1D*)hData[icent][ipt]->Clone(Form("hBkgMCsb_cent%d_pt%d",icent,ipt));
	
	 TString fNamedata = fNameHIdata;
	 if ( ppHI == kPP ) fNamedata = fNamePPdata;
	 
	 getTemplate(ppHI, hSig[icent][ipt],"meaningless",isoChoice,isoCut, kSig,lowCent,highCent,ptCut,onlygjEvents,specialSbCut,mcSigShift);
	 getTemplate(ppHI, hData[icent][ipt],fNamedata ,isoChoice,isoCut, kData,lowCent,highCent,ptCut,onlygjEvents,specialSbCut);
	 if ( ppHI == kHI) {
	   getTemplate(ppHI, hBkg[icent][ipt], fNamedata ,isoChoice,isoCut, kSBB,lowCent,highCent,ptCut,onlygjEvents,specialSbCut,sbBkgShift);
	 }
	 if ( ppHI == kPP)
           getTemplate(ppHI, hBkg[icent][ipt], fNamedata ,isoChoice,isoCut, kSBBpp,lowCent,highCent,ptCut,onlygjEvents,specialSbCut);
	 
      }
            
      
      for ( int icent = 1 ; icent<=nCent ; icent++) {
	int lowerCent = centBinVector[icent-1];
	int upperCent =centBinVector[icent]-1;
	 
	 c1[ipt]->cd(nCent - icent+1);
	 fitResult fitr = doFit ( hSig[icent][ipt], hBkg[icent][ipt], hData[icent][ipt], 0.005,0.025);
	 if ( icent== nCent) drawPatch(0,0,0.05,0.14,0,1001, "ndc");
	 
	 cout << " shift = " << mcSigShift << endl;
	 cout << " purity = " << fitr.purity010 << endl;

	 
	 if ( ptBin[ipt]> 200)
	    drawText(Form(" E_{T}^{#gamma} > %d GeV", (int)ptBin[ipt-1]),0.5680963,0.529118);
	 else
	    drawText(Form("%d - %d GeV", (int)ptBin[ipt-1], (int)ptBin[ipt]),0.5680963,0.529118);
	 
	 if ( ppHI == kHI) {
	   drawText(Form("%.0f%% - %.0f%%", float((float)lowerCent*2.5), float((float)(upperCent+1)*2.5)),0.5680963,0.4369118);
	 }
	 else if ( ppHI == kPP) {
	   drawText("7TeV pp",0.5680963,0.4369118);
         }
	 
	 
	 
	 if ( (icent == nCent) || (icent == 2)) 
	   drawText(Form("Purity(#sigma_{#eta#eta} < 0.01) : %.0f%%", (float)fitr.purity010*100),0.5680963,0.3569118,1,15);
	 else 
	   drawText(Form("Purity(#sigma_{#eta#eta} < 0.01) : %.0f%%", (float)fitr.purity010*100),0.4980963,0.3569118,1,15);
	 
	 drawText(Form("#pm %.0f%% (stat)", float( 100. * fitr.purity010 * (float)fitr.nSigErr / (float)fitr.nSig ) ),0.6680963,0.2869118,1,15);
	 
	 
	 hPurity2D->SetBinContent(ipt,icent,fitr.purity010);
	 hPurity2D->SetBinError  (ipt,icent,fitr.purity010* fitr.nSigErr/fitr.nSig);

	 rawSpectra[icent]->SetBinContent( ipt, fitr.nSig);
	 rawSpectra[icent]->SetBinError(   ipt,fitr.nSigErr);

	 TString aa = "";
	 if (isoChoice == kSumIso)  aa = "Sum Iso Method";
	 if (isoChoice == k3dIso)   aa = "3d Cut Method";
	 if (isoChoice == kFisher)  aa = "Fisher Method";
	 
	 if ( (ppHI == kHI)  && ( icent==nCent -1) )
	   drawText(aa.Data(),0.1980963,0.8569118,1,20);
	 else if ( ppHI == kPP) 
	   drawText(aa.Data(),0.1980963,0.8569118,1,20);
	 
	 if ( icent<= 2) drawPatch(0,0,0.05,0.14,0,1001, ndcOpt);
	 //	 drawPatch(0.9,0.05,1.01,0.14,0,1001,ndcOpt);
	 if  ( (ppHI == kPP) && ( mcSigShift != 0 )) 
           drawText(Form("Signal template shifted by %f",mcSigShift),0.1980963,0.7569118,1,15);
	 if  ( (ppHI == kHI) && ( mcSigShift != 0 ) && (icent==3))
	   drawText(Form("Signal template shifted by %f",mcSigShift),0.1980963,0.7569118,1,15);


      }   
      
      TString ppLabel ="";  
      if ( ppHI == kPP) ppLabel = "_pp";
      TString shiftLabel="";
      if ( mcSigShift != 0 )  shiftLabel = Form("_%fSigShifted",(float)mcSigShift);
      c1[ipt]->SaveAs(Form("fittingPurity%s_%s_pt%d%s.pdf",ppLabel.Data(), getIsoLabel(isoChoice).Data(),ipt,shiftLabel.Data()));

   }
   
   // efficiency plots          
   TCanvas* c2  = new TCanvas("c2","",700,700); //100 + nCent_std*300,400);
   if ( ppHI == kHI) makeMultiPanelCanvas(c2,nCent/2,2,0.0,0.0,0.2,0.15,0.02);
   
   TH1D* heff[7][5];
   TH1D* heffGj[5];
   TH1D* heffDphi[5];
   TH1D* effSingleBin = new TH1D("effSingleBin","",1,60,100000);
   TGraphAsymmErrors* geff[7][5];
   TGraphAsymmErrors* gSingleBin = new TGraphAsymmErrors();
   TGraphAsymmErrors* geffGj[5];
   TGraphAsymmErrors* geffDphi[5];
   
   for (int icent = 1; icent <=nCent; icent++) {
     for ( int iid=1 ; iid<=5; iid++) {
       heff[icent][iid] = new TH1D(Form("heff_icent%d_id%d",icent,iid),";photon E_{T} (GeV);Efficiency",nPtBin, ptBin);
       if ( isoChoice == kSumIso2)
	 heff[icent][iid]->SetName(Form("heff_icent%d_id%d_isoCut%d",icent,iid,(int)isoCut));
       if ( isoChoice == kSumIso3)
	 heff[icent][iid]->SetName(Form("heff_icent%d_id%d_sbIsoCut%d",icent,iid,(int)specialSbCut));
       
       geff[icent][iid] = new TGraphAsymmErrors();
       geff[icent][iid]->SetName(Form("geff_%s",heff[icent][iid]->GetName()));
     }
     heffGj[icent]   = new TH1D(Form("heff_icent%d_Gj",  icent),";x_J#gamma;Efficiency",10,0,2);
     heffDphi[icent] = new TH1D(Form("heff_icent%d_Dphi",icent),";#Delta#phi of pair;Efficiency",9,0.3141592,3.141592);
     geffGj[icent] = new TGraphAsymmErrors();
     geffDphi[icent] = new TGraphAsymmErrors();

   }
   
   TCut srIsoCut = getIsoCut(isoChoice,isoCut);
   int nId=4;
   for (int icent = 1; icent <=nCent ; icent++) {
     int lowCent = centBinVector[icent-1];
     int highCent = centBinVector[icent]-1;
     TCut centCut      = Form("yEvt.hiBin >= %d && yEvt.hiBin<= %d",lowCent,highCent);
     if ( ppHI == kPP ) centCut = "";
     getEff("genMatchedPt",heff[icent][1],geff[icent][1],centCut, "swissCrx<0.90 && seedTime<4");
     getEff("genMatchedPt",heff[icent][2],geff[icent][2],centCut, "swissCrx<0.90 && seedTime<4 && hadronicOverEm<0.1");
     getEff("genMatchedPt",heff[icent][3],geff[icent][3],centCut, "swissCrx<0.90 && seedTime<4 && hadronicOverEm<0.1" && srIsoCut);
     getEff("genMatchedPt",heff[icent][4],geff[icent][4],centCut, "swissCrx<0.90 && seedTime<4 && hadronicOverEm<0.1 && sigmaIetaIeta<0.010"&& srIsoCut);
     effSingleBin->Reset();
     getEff("genMatchedPt",effSingleBin, gSingleBin, centCut, "swissCrx<0.90 && seedTime<4 && hadronicOverEm<0.1" && srIsoCut);
     
     
     cout << " here Gj" << endl;
     getEff("yJet.jtpt/photonEt",heffGj[icent],geffGj[icent], centCut && " genIso<5 && abs(genMomId)<=22 && photonEt>60 && abs(yJet.jteta)<2 && yJet.jtpt>30 && acos(cos(photonPhi-yJet.jtphi))>2.749", "hovere<0.1 && sigmaIetaIeta<0.010 && (cc4+cr4+ct4PtCut20)/0.9<1",true);
     getEff("acos(cos(photonPhi-yJet.jtphi))",heffDphi[icent],geffDphi[icent],centCut && " genIso<5 && abs(genMomId)<=22 && photonEt>60 && abs(yJet.jteta)<2 && yJet.jtpt>30", "hovere<0.1 && sigmaIetaIeta<0.010 && (cc4+cr4+ct4PtCut20)/0.9<1",true);
   }
   
   for (int icent = 1; icent <=nCent; icent++) {
     for ( int iid=1 ; iid<=nId ; iid++) {
       handsomeTH1(heff[icent][iid],ycolor[iid]);
       handsomeTGraph(geff[icent][iid],ycolor[iid]);
     }
   }
   

   
   
   
   TH1D* htmp = (TH1D*)heff[1][1]->Clone("htmp");
   htmp->Reset();
   htmp->SetAxisRange(0,1.3,"Y");
   htmp->SetYTitle("Efficiency");
   handsomeTH1(htmp);
   
   for (int icent = 1; icent <=nCent; icent++) {
      int lowerCent = centBinVector[icent-1];
      int upperCent = centBinVector[icent]-1;
      if ( ppHI == kHI) c2->cd(nCent - icent + 1);
      htmp->DrawCopy();
      for ( int iid=1 ; iid<=nId ; iid++) {
         heff[icent][iid]->Draw("p same");
         geff[icent][iid]->Draw("p");
	 
      }
      if ( ( icent == nCent ) ||   ( ppHI == kPP)  )
         {
            TLegend* leg1 =  new TLegend(0.25,0.20,0.95,0.55,NULL,"brNDC");
            easyLeg(leg1,"Photon ID efficiency");
            leg1->AddEntry(heff[icent][1],"spike rejection","lp");
            leg1->AddEntry(heff[icent][2],"+ H/E < 0.1","lp");
	    if (isoChoice == kSumIso)
	      leg1->AddEntry(heff[icent][3],"+ SumIso cut","lp");
	    if (isoChoice == kFisher) 
	      leg1->AddEntry(heff[icent][3],"+ Fisher cut","lp");
	    leg1->AddEntry(heff[icent][4],"+ #sigma_{#eta#eta} <0.010","lp");
            leg1->Draw();
         }
      drawText(Form("%.0f%% - %.0f%%", float((float)lowerCent*2.5), float((float)(upperCent+1)*2.5)),0.5680963,0.8369118);
      if ( icent<=2) drawPatch(0,0,0.05,0.14,0,1001,ndcOpt);
      //  drawPatch(0.9,0.05,1.01,0.14,0,1001,ndcOpt);
      
   }
   
   
   c2->SaveAs(Form("photonID_efficiency_%s.pdf",getIsoLabel(isoChoice).Data()));  

   TCanvas* c2b  = new TCanvas("c2b","",1000,500); //100 + nCent_std*300,400);                                             
   c2b->Divide(2,1);
   c2b->cd(1);
   TH1D* htmpG = (TH1D*)heffGj[1]->Clone("htmpG");
   htmpG->Reset();
   htmpG->SetAxisRange(0,1.3,"Y");
   htmpG->SetYTitle("Efficiency");
   handsomeTH1(htmpG);   
      
   TLegend* legCent = new TLegend(0.4657258,0.2245763,1,0.4512712,NULL,"brNDC");
   easyLeg(legCent,"Centrality");
   if (isoChoice == kSumIso)  easyLeg(legCent,"SumIso Method");
   if (isoChoice == kFisher)  easyLeg(legCent,"Fisher Method");
   cout<< " heffGj "<< endl << endl<< endl;
   for (int icent = 1; icent <=nCent; icent++) {
     handsomeTH1(heffGj[icent],ycolor[icent]);
     heffGj[icent]->Fit("pol1");
     heffGj[icent]->GetFunction("pol1")->SetLineColor(ycolor[icent]);
     heffGj[icent]->GetFunction("pol1")->SetLineStyle(7);
   }
   htmpG->DrawCopy();
   for (int icent = 1; icent <=nCent; icent++) {
     heffGj[icent]->Draw("same");
     int lowerCent = centBinVector[icent-1];     int upperCent = centBinVector[icent]-1;
     legCent->AddEntry(heffGj[icent],Form("%.0f%% - %.0f%%", float((float)lowerCent*2.5), float((float)(upperCent+1)*2.5)),"pl");
   }
   legCent->Draw();

   c2b->cd(2);
   TH1D* htmpDp = new TH1D("htmpDp",";#Delta#phi of pair;Efficiency",10,0,3.14);
   htmpDp->Reset();
   htmpDp->SetAxisRange(0,1.3,"Y");
   htmpDp->SetYTitle("Efficiency");
   handsomeTH1(htmpDp);
   cout << " heffDphi " << endl << endl << endl ;
   for (int icent = 1; icent <=nCent; icent++) {
     handsomeTH1(heffDphi[icent],ycolor[icent]);
     heffDphi[icent]->Fit("pol1");
     heffDphi[icent]->GetFunction("pol1")->SetLineColor(ycolor[icent]);
     heffDphi[icent]->GetFunction("pol1")->SetLineStyle(7);
   }
   htmpDp->DrawCopy();
   for (int icent = 1; icent <=nCent; icent++) {
     heffDphi[icent]->Draw("same");
   }
   legCent->Draw();
   
   c2b->SaveAs(Form("photonID_efficiency_%s_2.pdf",getIsoLabel(isoChoice).Data()));
   
   
   TCanvas* c3 = new TCanvas("cPurity","",500,500);

   TH1D* hPurity[10];
   for (int icent = 1; icent <=nCent; icent++) {
     hPurity[icent] = (TH1D*)hPurity2D->ProjectionX(Form("purity1D_icent%d",icent),icent,icent);
     hPurity[icent]->Fit("pol1");
     hPurity[icent]->GetFunction("pol1")->SetLineColor(ycolor[icent]);
     hPurity[icent]->GetFunction("pol1")->SetLineStyle(7);
   }
   TH1D* tempPurity = (TH1D*)hPurity[1]->Clone("purityTemp");
   tempPurity->Reset();
   handsomeTH1(tempPurity,1);
   tempPurity->SetXTitle("pT (Gev)");
   tempPurity->SetYTitle("Purity");
   tempPurity->SetAxisRange(0.45,1.2,"Y");

   tempPurity->Draw();
   for (int icent = 1; icent <=nCent; icent++) {
     handsomeTH1(hPurity[icent],ycolor[icent]);
     hPurity[icent]->Draw("same");
   }
   TLegend* legPurity = new TLegend(0.4657258,0.2245763,1,0.4512712,NULL,"brNDC");
   easyLeg(legPurity,"Purity");
   if (isoChoice == kSumIso)  easyLeg(legPurity,"SumIso Method");
   if (isoChoice == kFisher)  easyLeg(legPurity,"Fisher Method");
   for (int icent = 1; icent <=nCent; icent++){
     int lowerCent = centBinVector[icent-1];     int upperCent = centBinVector[icent]-1;
     legPurity->AddEntry(hPurity[icent],Form("%.0f%% - %.0f%%", float((float)lowerCent*2.5), float((float)(upperCent+1)*2.5)),"pl");
   }
   legPurity->Draw();
   
   if ( !onlygjEvents) 
     drawText("inclusive photon",0.25,0.2);
   
   c3->SaveAs(Form("purity_%s.pdf",getIsoLabel(isoChoice).Data()));
  
   
   TCanvas* c4 = new TCanvas("efficiencyCorrection","",1000,500);
   c4->Divide(2,1);
   c4->cd(1);
   for (int icent = 1; icent <=nCent; icent++) {
      TH1ScaleByWidth(rawSpectra[icent]);    // divide by width
      finSpectra[icent] = (TH1D*)rawSpectra[icent]->Clone(Form("finSpec_icent%d_%s",icent,getIsoLabel(isoChoice).Data()));
      if ( isoChoice == kSumIso2)
	 finSpectra[icent]->SetName(Form("finSpec_icent%d_%s_isoCut%d",icent,getIsoLabel(isoChoice).Data(),(int)isoCut));
      if ( isoChoice == kSumIso3)
         finSpectra[icent]->SetName(Form("finSpec_icent%d_%s_sbisoCut%d",icent,getIsoLabel(isoChoice).Data(),(int)specialSbCut));
      
      finSpectra[icent]->Divide(heff[icent][3]);
      handsomeTH1(finSpectra[icent],ycolor[icent]);
   }
   // TAA and centrality 
   //

   TFile outf = TFile(cab.getPurityFileName(),"recreate");
   hPurity2D->Write();
   for ( int icent=1 ; icent<=nCent ; icent++) {
      heff[icent][3]->Write();
      heff[icent][4]->Write();
      finSpectra[icent]->Write();
      hPurity[icent]->Write();
      for (int ipt = 1; ipt <= nPtBin ; ipt++) {
	hData[icent][ipt]->Write();
      }
      //      hBkgMCRatioFit[icent][1]->Write();

   }



   outf.Close();
}
示例#23
0
void drawPtDependencePA(TString dirName, int prodDate, int jetPtCut, TString fNameSuffix, TString outNameSuffix){
  bool saveFigures=true;

  const int nPtBin = 4;
  double ptBin[nPtBin+1] = {40, 50,60,80,9999};
  double ptBinPaDraw[nPtBin+1] = { 40.5 ,49.5, 58.5,  76.5,  123. } ;
  // double AvePtBin[nPtBin+1] = { 45, 54.1479, 67.4204, 99.6956, 9999};

  const int nCentBinHI = 2;
  const int centBinHI[nCentBinHI +1] = {-1, 10030, 13099};

  TH1D* hxjg[7][10][6]; // [Collision][centrality][pt]
  TH1D* hJetPt[7][10][6]; // [Collision][centrality][pt]
  TH1D* hJetPtIaaBin[7][10][6]; // [Collision][centrality][pt]
  TH1D* hDphi[7][10][6]; // [Collision][centrality][pt]
  TH1D* meanXjg[7][10];      // [Collision][centrality]
  TH1D* meanJetPt[7][10];      // [Collisi on][centrality]

  TH1D* rjg[7][5];     //  [Collision][centrality]
  for (int icoll=0 ; icoll<6  ; icoll++) {
      for (int icent=1 ; icent<= 10 ; icent++) {
          meanXjg[icoll][icent] = new TH1D( Form("meanXjg_icoll%d_icent%d",icoll,icent), ";p_{T}^{#gamma} (GeV); <X_{J#gamma}>",nPtBin,ptBinPaDraw);
          meanJetPt[icoll][icent] = new TH1D( Form("meanJetPt_icoll%d_icent%d",icoll,icent), ";p_{T}^{#gamma} (GeV); <p_{T}^{Jet}>",nPtBin,ptBinPaDraw);
          rjg[icoll][icent] = new TH1D( Form("rjg_icoll%d_icent%d",icoll,icent), ";p_{T}^{#gamma} (GeV); R_{J#gamma}",nPtBin,ptBinPaDraw);

          for (int ipt=1 ; ipt<=nPtBin ; ipt++) {
              hxjg[icoll][icent][ipt] = NULL;
              hJetPt[icoll][icent][ipt] = NULL;
              hJetPtIaaBin[icoll][icent][ipt] = NULL;
              hDphi[icoll][icent][ipt] = NULL;
          }

      }
  }

  TFile* histFile[7][6];  // [Collision][pt]
  for (int ipt=1 ; ipt<=nPtBin ; ipt++) {
      for (int icoll=0 ; icoll<6 ; icoll++) {
          TString sampleName = getSampleName( icoll ) ;
          char* fname;
          if (fNameSuffix.EqualTo(""))  {  // if no explicit suffix for the input file name is specified
              fname =  Form("ffFiles/%s/photonTrackCorr_%s_output_photonPtThr%d_to_%d_jetPtThr%d_%d.root",dirName.Data(), sampleName.Data(), (int)ptBin[ipt-1], (int)ptBin[ipt], (int)jetPtCut, prodDate);
          }
          else {
              fname =  Form("ffFiles/%s/photonTrackCorr_%s_output_photonPtThr%d_to_%d_jetPtThr%d_%d_%s.root",dirName.Data(), sampleName.Data(), (int)ptBin[ipt-1], (int)ptBin[ipt], (int)jetPtCut, prodDate, fNameSuffix.Data());
          }

          histFile[icoll][ipt] = new TFile(fname) ;
          cout << " Reading file : " << fname << endl;

          if ( histFile[icoll][ipt]->IsZombie()  == false ) {
              cout << " Success." << endl;
              if ( (icoll == kPPDATA) || (icoll == kPPMC) )   {  //  PP
                  int icent = 7 ;
                  hxjg[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt]->Get(Form("xjg_icent%d_final", icent)) ;
                  cout << " Getting histogram : " << Form("xjg_icent%d_final", icent) << endl;
                  hJetPt[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt]->Get(Form("jetPt_icent%d_final", icent)) ;
                  cout << " Getting histogram : " << Form("jetPt_icent%d_final", icent) << endl;
                  hJetPtIaaBin[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt]->Get(Form("jetPtForIaa_icent%d_final", icent)) ;
                  cout << " Getting histogram : " << Form("jetPtForIaa_icent%d_final", icent) << endl;
                  hDphi[icoll][icent][ipt]  = (TH1D*)histFile[icoll][ipt]->Get(Form("jetDphi_icent%d_final", icent)) ;
                  cout << " Getting histogram : " << Form("jetDphi_icent%d_final", icent) << endl;
                  //hEta[icoll][icent][ipt]  = (TH1D*)histFile[icoll][ipt]->Get(Form("etaJg_icent%d_final", icent)) ;
                  //cout << " Getting histogram : " << Form("etaJg_icent%d_final", icent) << endl;

              }

              if ( (icoll == kPADATA) || (icoll == kPAMC) )   {  //  PA
                  int icent = 1 ;
                  hxjg[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt]->Get(Form("xjg_icent%d_final", icent)) ;
                  cout << " Getting histogram : " << Form("xjg_icent%d_final", icent) << endl;
                  hJetPt[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt]->Get(Form("jetPt_icent%d_final", icent)) ;
                  cout << " Getting histogram : " << Form("jetPt_icent%d_final", icent) << endl;
                  hJetPtIaaBin[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt]->Get(Form("jetPtForIaa_icent%d_final", icent ) ) ;
                  cout << " Getting histogram : " << Form("jetPtForIaa_icent%d_final", icent ) << endl;

                  hDphi[icoll][icent][ipt]  = (TH1D*)histFile[icoll][ipt]->Get(Form("jetDphi_icent%d_final", icent)) ;
                  cout << " Getting histogram : " << Form("jetDphi_icent%d_final", icent) << endl;
                  //hEta[icoll][icent][ipt]  = (TH1D*)histFile[icoll][ipt]->Get(Form("etaJg_icent%d_final", icent)) ;
                  //cout << " Getting histogram : " << Form("etaJg_icent%d_final", icent) << endl;

              }

              if ( ( icoll == kHIDATA) ||  (icoll == kHIMC) ) { // PbPb
                  for ( int icent = 1; icent <= nCentBinHI ; icent++ ) {
                      hxjg[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt]->Get(Form("xjg_icent%d_final", centBinHI[icent] )) ;
                      cout << " Getting histogram : " << Form("xjg_icent%d_final", centBinHI[icent] ) << endl;
                      hJetPt[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt]->Get(Form("jetPt_icent%d_final", centBinHI[icent] ) );
                      cout << " Getting histogram : " << Form("jetPt_icent%d_final", centBinHI[icent] ) << endl;
                      hJetPtIaaBin[icoll][icent][ipt] = (TH1D*)histFile[icoll][ipt]->Get(Form("jetPtForIaa_icent%d_final", centBinHI[icent] ) );
                      cout << " Getting histogram : " << Form("jetPtForIaa_icent%d_final", centBinHI[icent] ) << endl;
                      hDphi[icoll][icent][ipt]  = (TH1D*)histFile[icoll][ipt]->Get(Form("jetDphi_icent%d_final", centBinHI[icent] ) ) ;
                      cout << " Getting histogram : " << Form("jetDphi_icent%d_final", centBinHI[icent])<< endl;
                      //hEta[icoll][icent][ipt]  = (TH1D*)histFile[icoll][ipt]->Get(Form("etaJg_icent%d_final", centBinHI[icent] ) ) ;
                      //cout << " Getting histogram : " << Form("etaJg_icent%d_final", centBinHI[icent])<< endl;
                  }
              }
          }
          else
              cout << " no such file " << endl;
      }
  }

  for (int ipt=1 ; ipt<=nPtBin ; ipt++) {
      for (int icoll=0 ; icoll<6 ; icoll++) {
          for (int icent=1 ; icent<= 10 ; icent++ ) {

              if ( hxjg[icoll][icent][ipt] == NULL )  continue;   // emtpy histogram

              double rVal, rErr;
              rVal = hxjg[icoll][icent][ipt]->IntegralAndError(1, hxjg[icoll][icent][ipt]->GetNbinsX(), rErr, "width");
              rjg[icoll][icent]->SetBinContent( ipt, rVal );
              rjg[icoll][icent]->SetBinError  ( ipt, rErr );

              meanXjg[icoll][icent]->SetBinContent( ipt, hxjg[icoll][icent][ipt]->GetMean() );
              meanXjg[icoll][icent]->SetBinError  ( ipt, hxjg[icoll][icent][ipt]->GetMeanError() );

              meanJetPt[icoll][icent]->SetBinContent( ipt, hJetPt[icoll][icent][ipt]->GetMean() );
              meanJetPt[icoll][icent]->SetBinError  ( ipt, hJetPt[icoll][icent][ipt]->GetMeanError() );
          }
      }
  }

  TCanvas* c1 = new TCanvas("c1","",1200,350);
  makeMultiPanelCanvas(c1,nPtBin,1,0.0,0.0,0.2,0.15,0.02);
  for ( int ipt = 1 ; ipt<=nPtBin  ; ipt++) {

      c1->cd(ipt);

      handsomeTH1(hDphi[kPAMC][1][ipt], 1);
      hDphi[kPAMC][1][ipt]->SetXTitle("#Delta#phi_{J#gamma}");
      hDphi[kPAMC][1][ipt]->SetYTitle("Normalized entries");
      hDphi[kPAMC][1][ipt]->SetMarkerStyle(24);
      hDphi[kPAMC][1][ipt]->Scale(1./hDphi[kPAMC][1][ipt]->Integral("width"));
      hDphi[kPAMC][1][ipt]->SetAxisRange(0,3.141592,"X");
      hDphi[kPAMC][1][ipt]->SetAxisRange(0.01,30,"Y");
      hDphi[kPAMC][1][ipt]->Draw();

      handsomeTH1(hDphi[kPADATA][1][ipt], kRed);
      hDphi[kPADATA][1][ipt]->Scale(1./hDphi[kPADATA][1][ipt]->Integral("width"));
      hDphi[kPADATA][1][ipt]->Draw("same");

      gPad->SetLogy();

      double dx1=0.15;
      if ( ipt == nPtBin )
          drawText(Form("p_{T}^{#gamma} > %dGeV, ", (int)ptBin[ipt-1]), 0.12+dx1+0.25,0.85,1,15);//yeonju 130823
      else
          drawText(Form("%dGeV < p_{T}^{#gamma} < %dGeV, ", (int)ptBin[ipt-1], (int)ptBin[ipt]), 0.12+dx1,0.85,1,15);//yeonju 130823

  }
  c1->cd(1);

  TLegend *l1 = new TLegend(0.2199474,0.5971384,0.7283974,0.8119819,NULL,"brNDC");
  easyLeg(l1,"5.02TeV");
  l1->AddEntry(hDphi[kPAMC][1][1],"pA pythia+HIJING ","p");
  l1->AddEntry(hDphi[kPADATA][1][1],"pA Data","p");
  l1->Draw();

  if (saveFigures) {
      if(outNameSuffix.EqualTo("")){
          c1->SaveAs("figures/pT_dependence_dphi_pA_figure1.pdf");
          c1->SaveAs("figures/pT_dependence_dphi_pA_figure1.gif");
      }
      else {
          c1->SaveAs(Form("figures/pT_dependence_dphi_pA_figure1_%s.pdf", outNameSuffix.Data()));
          c1->SaveAs(Form("figures/pT_dependence_dphi_pA_figure1_%s.gif", outNameSuffix.Data()));
      }
  }


  TH1D* hTempPt = new TH1D("hTemp",";p_{T}^{#gamma} (GeV);",200,10,300);

  TCanvas* c2 = new TCanvas("c2","",1200,350);
  makeMultiPanelCanvas(c2,nPtBin,1,0.0,0.0,0.2,0.15,0.02);
  for ( int ipt = 1 ; ipt<=nPtBin  ; ipt++) {

      c2->cd(ipt);

      hTempPt->SetXTitle("p_{T}^{Jet} (GeV)");
      hTempPt->SetYTitle("#frac{dN}{dp_{T}} #frac{1}{N}");
      hTempPt->SetAxisRange(10,150,"X");
      //        hTempPt->SetAxisRange(0,0.025,"Y");
      hTempPt->SetAxisRange(0,0.08,"Y");
      handsomeTH1(hTempPt,0);
      hTempPt->DrawCopy();

      //	hJetPt[kPAMC][1][ipt]->Scale(1./rjg[kPAMC][1]->GetBinContent(ipt)); // rjg normalization

      handsomeTH1(hJetPt[kPAMC][1][ipt], 1);
      hJetPt[kPAMC][1][ipt]->SetMarkerStyle(24);
      hJetPt[kPAMC][1][ipt]->Draw("same");

      handsomeTH1(hJetPt[kPADATA][1][ipt],kRed);
      //	hJetPt[kPADATA][1][ipt]->Scale(1./rjg[kPADATA][1]->GetBinContent(ipt));

      hJetPt[kPADATA][1][ipt]->Draw("same");


      double dx1=0.15;
      if ( ipt == nPtBin )
          drawText(Form("p_{T}^{#gamma} > %dGeV, ", (int)ptBin[ipt-1]), 0.12+dx1+0.25,0.85,1,15);//yeonju 130823
      else
          drawText(Form("%dGeV < p_{T}^{#gamma} < %dGeV, ", (int)ptBin[ipt-1], (int)ptBin[ipt]), 0.12+dx1,0.85,1,15);//yeonju 130823

      onSun(30,0,200,0);
  }
  c2->cd(1);
  l1->Draw();

  if (saveFigures) {
      if(outNameSuffix.EqualTo("")){
          c2->SaveAs("figures/pT_dependence_jetPt_pA_figure1.pdf");
          c2->SaveAs("figures/pT_dependence_jetPt_pA_figure1.gif");
      }
      else {
          c2->SaveAs(Form("figures/pT_dependence_jetPt_pA_figure1_%s.pdf", outNameSuffix.Data()));
          c2->SaveAs(Form("figures/pT_dependence_jetPt_pA_figure1_%s.gif", outNameSuffix.Data()));
      }
  }

  TLegend *l2 = new TLegend(0.2116935,0.7012712,0.6149194,0.904661,NULL,"brNDC");
  easyLeg(l2,"5.02TeV");

  l2->AddEntry(hDphi[kPAMC][1][1],"pPb pythia+HIJING","p");
  l2->AddEntry(hDphi[kPADATA][1][1],"pPb Data","p");


  TCanvas* c21 = new TCanvas("c21","",500,500);
  handsomeTH1(meanJetPt[kPAMC][1], 1);
  meanJetPt[kPAMC][1]->SetYTitle("<p_{T}^{Jet}>  (>30GeV)");
  meanJetPt[kPAMC][1]->SetMarkerStyle(24);
  //  meanJetPt[kPAMC][1]->SetAxisRange(-2,2,"X");
  meanJetPt[kPAMC][1]->SetAxisRange(40,115,"Y");
  meanJetPt[kPAMC][1]->Draw();

  handsomeTH1(meanJetPt[kPADATA][1],kRed);
  meanJetPt[kPADATA][1]->Draw("same");

  l1 ->Draw();

  if (saveFigures) {
      if(outNameSuffix.EqualTo("")){
          c21->SaveAs("figures/pT_dependence_jetPt_pA_figure2.pdf");
          c21->SaveAs("figures/pT_dependence_jetPt_pA_figure2.gif");
      }
      else {
          c21->SaveAs(Form("figures/pT_dependence_jetPt_pA_figure2_%s.pdf", outNameSuffix.Data()));
          c21->SaveAs(Form("figures/pT_dependence_jetPt_pA_figure2_%s.gif", outNameSuffix.Data()));
      }
  }


  TCanvas* c3 = new TCanvas("c3","",1200,350);
  makeMultiPanelCanvas(c3,nPtBin,1,0.0,0.0,0.2,0.15,0.02);
  for ( int ipt = 1 ; ipt<=nPtBin  ; ipt++) {

      c3->cd(ipt);

      handsomeTH1(hxjg[kPAMC][1][ipt], 1);
      hxjg[kPAMC][1][ipt]->SetXTitle("x_{J#gamma}");
      hxjg[kPAMC][1][ipt]->SetYTitle("#frac{dN}{dp_{T}} #frac{1}{N}");
      hxjg[kPAMC][1][ipt]->SetMarkerStyle(24);

      //	hxjg[kPAMC][1][ipt]->Scale(1./rjg[kPAMC][1]->GetBinContent(ipt)); // rjg normalization


      hxjg[kPAMC][1][ipt]->SetAxisRange(0,2,"X");
      hxjg[kPAMC][1][ipt]->Draw();

      handsomeTH1(hxjg[kPADATA][1][ipt],kRed);
      //	hxjg[kPADATA][1][ipt]->Scale(1./rjg[kPADATA][1]->GetBinContent(ipt)); // rjg normalization


      hxjg[kPADATA][1][ipt]->Draw("same");

      double dx1=0.15;
      if ( ipt == nPtBin )
          drawText(Form("p_{T}^{#gamma} > %dGeV, ", (int)ptBin[ipt-1]), 0.12+dx1+0.25,0.85,1,15);//yeonju 130823
      else
          drawText(Form("%dGeV < p_{T}^{#gamma} < %dGeV, ", (int)ptBin[ipt-1], (int)ptBin[ipt]), 0.12+dx1,0.85,1,15);//yeonju 130823


      onSun(30,0,200,0);
  }
  c3->cd(1);
  l1->Draw();

  if (saveFigures) {
      if(outNameSuffix.EqualTo("")){
          c3->SaveAs("figures/pT_dependence_xjg_pA_figure1.pdf");
          c3->SaveAs("figures/pT_dependence_xjg_pA_figure1.gif");
      }
      else {
          c3->SaveAs(Form("figures/pT_dependence_xjg_pA_figure1_%s.pdf", outNameSuffix.Data()));
          c3->SaveAs(Form("figures/pT_dependence_xjg_pA_figure1_%s.gif", outNameSuffix.Data()));
      }
  }

  TCanvas* c31 = new TCanvas("c31","",500,500);
  handsomeTH1(meanXjg[kPAMC][1], 1);
  meanXjg[kPAMC][1]->SetYTitle("<x_{J#gamma}>  (>30GeV)");
  meanXjg[kPAMC][1]->SetMarkerStyle(24);
  //  meanXjg[kPAMC][1]->SetAxisRange(-2,2,"X");
  meanXjg[kPAMC][1]->SetAxisRange(0.6,1.2,"Y");
  meanXjg[kPAMC][1]->Draw();

  handsomeTH1(meanXjg[kPADATA][1],kRed);
  meanXjg[kPADATA][1]->Draw("same");

  l1->Draw();

  if (saveFigures) {
      if(outNameSuffix.EqualTo("")){
          c31->SaveAs("figures/pT_dependence_xjg_pA_figure2.pdf");
          c31->SaveAs("figures/pT_dependence_xjg_pA_figure2.gif");
      }
      else {
          c31->SaveAs(Form("figures/pT_dependence_xjg_pA_figure2_%s.pdf", outNameSuffix.Data()));
          c31->SaveAs(Form("figures/pT_dependence_xjg_pA_figure2_%s.gif", outNameSuffix.Data()));
      }
  }

  TCanvas* c_rjg = new TCanvas("c_rjg","",500,500);
  handsomeTH1(rjg[kPAMC][1], 1);
  rjg[kPAMC][1]->SetYTitle("R_{J#gamma}");
  rjg[kPAMC][1]->SetMarkerStyle(24);
  //  rjg[kPAMC][1]->SetAxisRange(-2,2,"X");
  rjg[kPAMC][1]->SetAxisRange(0.0,1.1,"Y");
  rjg[kPAMC][1]->Draw();

  handsomeTH1(rjg[kPADATA][1],kRed);
  rjg[kPADATA][1]->Draw("same");


  l1->Draw();

  if (saveFigures) {
      if(outNameSuffix.EqualTo("")){
          c_rjg->SaveAs("figures/pT_dependence_rjg_pA_figure1.pdf");
          c_rjg->SaveAs("figures/pT_dependence_rjg_pA_figure1.gif");
      }
      else {
          c_rjg->SaveAs(Form("figures/pT_dependence_rjg_pA_figure1_%s.pdf", outNameSuffix.Data()));
          c_rjg->SaveAs(Form("figures/pT_dependence_rjg_pA_figure1_%s.gif", outNameSuffix.Data()));
      }
  }

  // Save the final root histogram files
  TFile* fResults;
  if(outNameSuffix.EqualTo("")){
      fResults =  new TFile("resultHistograms.root", "update");
  }
  else   {
      fResults =  new TFile(Form("resultHistograms_%s.root", outNameSuffix.Data()), "update");
  }
  //    TFile * fResults =  new TFile("resultHistograms_ppb_photonEnergy_ScaledBy0.015.root","update");

  meanJetPt[kPADATA][1]->SetName(Form("meanJetPt_ppb"));
  meanJetPt[kPADATA][1]->Write();

  meanXjg[kPADATA][1]->SetName(Form("meanXjg_ppb"));
  meanXjg[kPADATA][1]->Write();

  rjg[kPADATA][1]->SetName(Form("meanRjg_ppb"));
  rjg[kPADATA][1]->Write();

  for ( int ipt = 1 ; ipt<=nPtBin  ; ipt++) {
      hJetPt[kPADATA][1][ipt]->SetName(Form("dNdJetPt_ppb_ptBin%d",ipt));
      hJetPt[kPADATA][1][ipt]->Write();

      hJetPtIaaBin[kPADATA][1][ipt]->SetName(Form("dNdJetPt_IaaBin_ppb_ptBin%d",ipt));
      hJetPtIaaBin[kPADATA][1][ipt]->Write();

      hxjg[kPADATA][1][ipt]->SetName(Form("dNdXjg_ppb_ptBin%d",ipt));
      hxjg[kPADATA][1][ipt]->Write();

      hDphi[kPADATA][1][ipt]->SetName(Form("dNdphi_ppb_ptBin%d",ipt));
      hDphi[kPADATA][1][ipt]->Write();
  }

  fResults->Close();
}
示例#24
0
void NewCosmicstest(){
	//gROOT->Reset();	
	
	TStopwatch *clock0 = new TStopwatch();
	TFile *fout = new TFile("Cosmictest.root","RECREATE");
	bool high = 1;
	
	//Float_t z0 = 1400;
	Float_t z0 = 0;
	Float_t yTop = 600;
	Float_t xTop = 300;
	Float_t zTop = 3650;
	
	Float_t xdist = 3000;
	Float_t zdist = 9000;
	
	TH2D *StartXZ = new TH2D("xz","xz;x[cm];z[cm]",30,-(xdist/2),xdist/2,90,z0 - 4500,z0 + 4500);
	TH1D *StartTheta = new TH1D("#theta","#theta; #theta_Zenith",100,0,2);
	TH1D *StartPhi = new TH1D("#phi","#phi; #phi",50,0,7);
	TH1D *StartPHigh = new TH1D("PHigh","P; P[GeV]",100,-1,3);
	TH1D *StartP = new TH1D("P","P;P[GeV]",100,-1,3);
	TH1D *StartPLow = new TH1D("PLow","P;P[GeV]",100,-1,3);
	//TH1D *StartP = new TH1D("P","P;P[GeV]",100,0.1,1000);
	BinLogX(StartP);
	BinLogX(StartPHigh);
	BinLogX(StartPLow);
	
	TH2D *StartPTheta = new TH2D("P,Theta","P-Theta;P[GeV];#theta",150,-1,3,50,0,2);
	BinLogX(StartPTheta);
	
	TH2D *MCXZ = new TH2D("MCxz","xz;x[cm];z[cm]",30,-(xdist/2),xdist/2,90,z0 - 4500,z0 + 4500);
	TH1D *MCTheta = new TH1D("MC#theta","#theta; #theta",100,0,2);
	TH1D *MCPhi = new TH1D("MC#phi","#phi, #phi",50,0,7);
	
	TH1I *MCnTry = new TH1I("nTry","nTry",100,4.6,5);
	
	Double_t totalweightsum=0;
	Double_t px,py,pz,x,y,z,w, weighttest, weight;
	Int_t nTry,nInside,nEvent,nTest;	
	Co3Rng *fRandomEngine = new Co3Rng();
	
	int EVENTS = 400000;
	Int_t kmax = 40000;
	float weight1,weight1Low,weight1High;
	weight1Low = 123*xdist*zdist/EVENTS/10000; // expected #muons per spill/ #simulated events per spill 174*30*90/500000
	cout<<weight1Low<<endl;
	
	double I = fRandomEngine->fSpectrumH->Integral(100,1000);
	weight1High = 2*TMath::Pi()/3*I*xdist*zdist/EVENTS/10000;
		//weight2 = 900/I; // 1/(mean momentum weight), P_max-P_min/(3*0.3044/2pi)
	
	cout<< weight1High<<endl;
	Float_t weight3 = 4.833931503; // MC average of nTry/nEvents 4.833949997 +- 0.000010494			
	weight1 = 1;								
	weight = weight1 / weight3;
	
	nInside = 0; nEvent = 0; nTest = 0; weighttest = 0;
	y = 1900; //20m over beam axis

	w = weight/kmax;
	clock0->Start();
	for(Int_t k = 0;k<kmax;k++){
		cout<<k<<endl;
		nTry =0;
		for(Int_t i=0;i<EVENTS;i++){
		   Bool_t hit = 0;   
		   do{
				// shower characteristics
			   double phi = fRandomEngine->Uniform(0,2*TMath::Pi());
			   double theta = fRandomEngine->fTheta->GetRandom();
			  				  			    		 
	   	   //momentum components
				px = TMath::Sin(phi)*TMath::Sin(theta); 
				pz = TMath::Cos(phi)*TMath::Sin(theta);
				py = -TMath::Cos(theta);
				
				// start position, area 1120m^2
				x = fRandomEngine->Uniform(-xdist/2,xdist/2);
				z = fRandomEngine->Uniform(z0 - zdist/2, z0 + zdist/2);
				
				// claim for flight close to the actual detector
				if((abs(x-(y+yTop)*px/py) < xTop && abs(z-z0-(y+yTop)*pz/py) < zTop) || (abs(x-(y-yTop)*px/py) < xTop && abs(z-z0-(y-yTop)*pz/py) <  zTop)|| abs(y-(x+xTop)*py/px)<yTop && abs(z-z0-(x+xTop)*pz/px)<zTop || abs(y-(x-xTop)*py/px)<yTop && abs(z-z0-(x-xTop)*pz/px)<zTop){
					
					// muon momentum
					double P;
					//if (!high) {P = fRandomEngine->NEWstest(theta);}
					//else {P = fRandomEngine->fSpectrumH->GetRandom();}
					// high
					P = fRandomEngine->fSpectrumH->GetRandom();
					w = weight1High/weight3/kmax;
					StartP->Fill(P,w);
					StartPHigh->Fill(P,w);
					StartPTheta->Fill(P,theta,w);
					// low
					P = fRandomEngine->NEWstest(theta);
					w = weight1Low/weight3/kmax;
					StartP->Fill(P,w);
					StartPLow->Fill(P,w);
					StartPTheta->Fill(P,theta,w);
					
					
					px = px*P;
					py = py*P;
					pz = pz*P;
					
					//muon or anti-muon
					hit = 1; nInside++; 
					// StartP->Fill(P,w);
					
					w = weight1Low/weight3/kmax + weight1High/weight3/kmax;
					
					StartTheta->Fill(theta,w); // kein Weight!
					StartPhi->Fill(phi,w);	// kein Weight!	
					StartXZ->Fill(x,z,w); // kein Weight!	
					StartPTheta->Fill(P,theta,w);	
			   }
			   nTry++;
				weighttest += w;
				MCTheta->Fill(theta,w); // kein Weight!
				MCPhi->Fill(phi,w);
				MCXZ->Fill(x,z,w);
				nTest++;
			}while(!hit);
			nEvent++;
		}
		MCnTry->Fill(1.0*nTry/EVENTS);
	}
	clock0->Stop();
	
	delete fRandomEngine;
	cout<<nEvent<<" events have been generated."<<endl;
	cout<<"There is a total of "<<nInside<<"/"<<nTest<<" muons that passed close enough to the detector."<<endl;
	cout<<"Including the given weight this corresponds to ";
	cout<<kmax*weighttest/xdist/zdist*10000/123.3044<<" spills (1 spill = "<<xdist*zdist*123.3044/10000;
	cout<<" real cosmic muons = "<<EVENTS<<" simulated events)."<<endl;
   
   cout<<weighttest<<endl;
   clock0->Print();
   
   Double_t meanflux = 0;
   Int_t binsum = 0;
   for (Int_t ix = 2; ix<29;ix++){
	   for (Int_t iz = 2; iz<89;iz++){
		 	binsum++;
		   meanflux += MCXZ->GetBinContent(ix,iz);
		}
	}
	cout<< "meanflux: "<<meanflux/binsum<<"  "<< meanflux<<endl<<endl;
   printf("MCnTry: %.9f +- %.9f",MCnTry->GetMean(),MCnTry->GetMeanError());
   cout<<endl<<endl;
     
    TCanvas *c1 = new TCanvas("c1","c1",400,400);
	 c1->Divide(1,1);
	 c1->cd(1);
	 MCnTry->DrawCopy();
	
	 TCanvas *c4 = new TCanvas("c4","c4",400,400);
	 c4->Divide(1,1);
	 c4->cd(1);
	 StartPTheta->DrawCopy("SURF2");
	 gPad->SetLogx();
	
	 //TCanvas *c2 = new TCanvas("c2","c2",400,400);
	 //c2->Divide(1,1);
	 //c2->cd(1);
	 //gPad->SetLogy();
	 //wei->DrawCopy();
	
    TCanvas *c3 = new TCanvas("c3","c3",1600,800);
	 c3->Divide(4,2);
	 c3->cd(1);
	 StartXZ->DrawCopy("COLZ");
	 c3->cd(2);
	 //MCP->SetLineColor(kGreen);
	// MCP->DrawCopy();
	 //StartP->DrawCopy();
	 //TF1 *fs = new TF1("fs",NEWs,1,100,2);
	 //fs->FixParameter(0, 0);
	 //fs->FixParameter(1, 500);
	 //StartP->Add(fs,-1);
	 StartP->DrawCopy();
	 //StartP->Fit(fs,"I");
	 
	 
	// 
	 //fs->DrawCopy("SAME");
	 
	 //gPad->SetLogy();
	 gPad->SetLogx();
	 c3->cd(3);
	 MCTheta->SetLineColor(kGreen);
	 MCTheta->DrawCopy();
	 StartTheta->DrawCopy("SAME");
	 //TF1 *f1 = new TF1("f1","[0]*cos(x)*cos(x)",1.57,3.14);
	 //StartTheta->Fit(f1,"","",1.57,3.14);	
	 gPad->SetLogy(0);
	 gPad->SetLogx(0);
	 c3->cd(4);
	 MCPhi->SetLineColor(kGreen);
	 MCPhi->DrawCopy();
	 StartPhi->DrawCopy("SAME");
	//TF1 *f1 = new TF1("f1","[0]*cos(x)*cos(x)",1.57,3.14);
	//StartTheta->Fit(f1,"","",1.57,3.14);	
	 gPad->SetLogy(0);
	 gPad->SetLogx(0);
	 c3->cd(5);
	 MCXZ->DrawCopy("COLZ");
	 c3->cd(6);
	 //MCP->Divide(StartP);
	// MCP->DrawCopy();
	 gPad->SetLogy(0);
	 gPad->SetLogx(0);
	 c3->cd(7);
	 //MCTheta->Divide(StartTheta);
	 MCTheta->DrawCopy();
	 gPad->SetLogy();
	 gPad->SetLogx(0);
	 c3->cd(8);
	 //MCPhi->Divide(StartPhi);
	 MCPhi->DrawCopy();
	 gPad->SetLogy(0);
	 gPad->SetLogx(0);
	 c3->Update();
	 c3->SaveAs("Start.png");
	 
	 
	 
	 
	 StartXZ->Write();
	 StartTheta->Write();
	 StartPhi->Write();
	 StartP->Write();
	 StartPLow->Write();
	 StartPHigh->Write();
	
    StartPTheta->Write();
		
	 MCXZ->Write();
	 MCTheta->Write();
	 MCPhi->Write();
	
	 MCnTry->Write();
	 fout ->Close();
	 
	 
  
}
示例#25
0
void drawResults(bool drawSinglePanels = false) {
  // const int kPPcentral = 1;
  // const int kPPperipheral =2 ;
  // const int kHIcentral =  3;
  // const int kHIperipheral = 4;
  // const int kPADATA = 5;
  // const int kPAMC = 6;
  //const int nPtBin = 4;
  // double ptBin[nPtBin+1] = {40, 50,60,80,9999};

  TH1D* meanJetPt[8];   // [collision] [Before/After variation]
  TH1D* meanJetPtSys[8];   // [collision] [Before/After variation]

  TH1D* meanXjg[8];   // [collision] [Before/After variation]
  TH1D* meanXjgSys[8];   // [collision] [Before/After variation]

  TH1D* meanRjg[8];
  TH1D* meanRjgSys[8];

  TFile * f = new TFile("../resultHistograms/resultHistograms_ppSmeared10030.root");
  meanJetPt[1]  =(TH1D*)f->Get(Form("meanJetPt_pp"));
  meanXjg[1]    =(TH1D*)f->Get(Form("meanXjg_pp"));
  meanRjg[1]  =(TH1D*)f->Get(Form("meanRjg_pp"));

  f   = new TFile("../resultHistograms/resultHistograms_ppSmeared13099.root");
  meanJetPt[2]  =(TH1D*)f->Get(Form("meanJetPt_pp"));
  meanXjg[2]    =(TH1D*)f->Get(Form("meanXjg_pp"));
  meanRjg[2]  =(TH1D*)f->Get(Form("meanRjg_pp"));

  // pbpb
  f =   new TFile("../resultHistograms/resultHistograms_nominal_vtxCentWeighted.root");

  meanJetPt[7]  =(TH1D*)f->Get(Form("meanJetPt_pp"));
  meanXjg[7]  =(TH1D*)f->Get(Form("meanXjg_pp"));
  meanRjg[7]  =(TH1D*)f->Get(Form("meanRjg_pp"));

  meanJetPt[3]  =(TH1D*)f->Get(Form("meanJetPt_pbpb_centralityBin1"));
  meanXjg[3]  =(TH1D*)f->Get(Form("meanXjg_pbpb_centralityBin1"));
  meanRjg[3]  =(TH1D*)f->Get(Form("meanRjg_pbpb_centralityBin1"));

  meanJetPt[4]  =(TH1D*)f->Get(Form("meanJetPt_pbpb_centralityBin2"));
  meanXjg[4]  =(TH1D*)f->Get(Form("meanXjg_pbpb_centralityBin2"));
  meanRjg[4]  =(TH1D*)f->Get(Form("meanRjg_pbpb_centralityBin2"));

  // pPb
  meanJetPt[5]  =(TH1D*)f->Get(Form("meanJetPt_ppb"));
  meanXjg[5]  =(TH1D*)f->Get(Form("meanXjg_ppb"));
  meanRjg[5]  =(TH1D*)f->Get(Form("meanRjg_ppb"));

  f =   new TFile("../resultHistograms/resultHistograms_MCrecoIso_vtxCentWeighted.root"); //pythia+hijing
  meanJetPt[6]  =(TH1D*)f->Get(Form("meanJetPt_ppb"));
  meanXjg[6]  =(TH1D*)f->Get(Form("meanXjg_ppb"));
  meanRjg[6]  =(TH1D*)f->Get(Form("meanRjg_ppb"));


  TFile* fSys = new TFile("../relativeSys/relativeSys_merged.root");

  meanJetPtSys[1]  =(TH1D*)fSys->Get("meanJetPt_pp_uncertainty_merged");
  meanRjgSys[1]  =(TH1D*)fSys->Get(Form("meanRjg_pp_uncertainty_merged"));
  meanXjgSys[1]  =(TH1D*)fSys->Get(Form("meanXjg_pp_uncertainty_merged"));

  meanJetPtSys[2] = (TH1D*)meanJetPtSys[1]->Clone(Form("%s_2",meanJetPtSys[1]->GetName()));
  meanRjgSys[2] = (TH1D*)meanRjgSys[1]->Clone(Form("%s_2",meanRjgSys[1]->GetName()));
  meanXjgSys[2] = (TH1D*)meanXjgSys[1]->Clone(Form("%s_2",meanXjgSys[1]->GetName()));

  meanJetPtSys[3]  =(TH1D*)fSys->Get("meanJetPt_pbpb_centralityBin1_uncertainty_merged");
  meanXjgSys[3]  =(TH1D*)fSys->Get(Form("meanXjg_pbpb_centralityBin1_uncertainty_merged"));
  meanRjgSys[3]  =(TH1D*)fSys->Get(Form("meanRjg_pbpb_centralityBin1_uncertainty_merged"));

  meanJetPtSys[4]  =(TH1D*)fSys->Get("meanJetPt_pbpb_centralityBin2_uncertainty_merged");
  meanXjgSys[4]  =(TH1D*)fSys->Get(Form("meanXjg_pbpb_centralityBin2_uncertainty_merged"));
  meanRjgSys[4]  =(TH1D*)fSys->Get(Form("meanRjg_pbpb_centralityBin2_uncertainty_merged"));

  meanJetPtSys[5]  =(TH1D*)fSys->Get("meanJetPt_ppb_uncertainty_merged");
  meanXjgSys[5]  =(TH1D*)fSys->Get(Form("meanXjg_ppb_uncertainty_merged"));
  meanRjgSys[5]  =(TH1D*)fSys->Get(Form("meanRjg_ppb_uncertainty_merged"));


  // RJG!!
  TCanvas* c2; 
  //c2->Divide(3,1);
  if( !drawSinglePanels)
  {
    c2 = new TCanvas("c1","",1300,500);
    makeMultiPanelCanvas(c2,3,1,0.0,0.0, 0.15, 0.15, 0.025);
  }
  else
  {
    c2 = new TCanvas("c1","",1450,500);
    c2->Divide(3,1);
    //makeMultiPanelCanvas(c2,3,1,0.2,0.2, 0.15, 0.15, 0.025);
  }
  c2->cd(3);
  handsomeTH1(meanRjg[1],1,1,21);
  //  drawSys(TH1 *h,TH1 *sys, Int_t theColor= newYellow, Int_t fillStyle = -1, Int_t lineStyle = -1)
  TH1D* tempR = new TH1D("tempR",";p_{T}^{#gamma} (GeV);R_{J#gamma}",1000,40,130);
  tempR->Reset();
  handsomeTH1(tempR,0);
  //tempR->SetAxisRange(0,1.2,"Y");
  tempR->SetAxisRange(0,1.0,"Y");
  tempR->SetAxisRange(40.01,109.99,"X");
  tempR->GetYaxis()->SetNdivisions(505);
  tempR->Draw();
  drawSys(meanRjg[1], meanRjgSys[1], kGreen,3001);
  drawSys(meanRjg[3], meanRjgSys[3]);
  handsomeTH1(meanRjg[1],1,1,21);
  meanRjg[1]->DrawCopy("same");
  handsomeTH1(meanRjg[3],2,1,20);
  meanRjg[3]->DrawCopy("same");
  meanRjg[1]->SetFillStyle(3001);
  meanRjg[1]->SetFillColor(kGreen);
  meanRjg[3]->SetFillColor(90);
  meanRjg[3]->SetFillStyle(1001);
  meanRjg[1]->SetLineColor(0);
  meanRjg[3]->SetLineColor(0);
  if ( 1==1 ){
    TLegend *ly = new  TLegend(0.4,0.2,0.75,0.4,NULL,"brNDC");
    //easyLeg(ly,"2.76TeV");
    easyLeg(ly);
    ly->AddEntry(meanRjg[3],"PbPb 0-30%","fp");
    ly->AddEntry(meanRjg[1],"Smeared pp reference","fp");
    ly->Draw();
  }
  if(!drawSinglePanels)
    drawCMSppPbPbDist(0.04,0.9);
  else
    drawCMSppPbPbDist(0.2,0.9);


  c2->cd(2);
  tempR->Draw();
  drawSys(meanRjg[2], meanRjgSys[2], kGreen,3001);
  drawSys(meanRjg[4], meanRjgSys[4]);
  //  meanRjg[2]->SetMarkerStyle(25);
  handsomeTH1(meanRjg[2],1,1,25);
  meanRjg[2]->DrawCopy("same");
  handsomeTH1(meanRjg[4],2,1,24);
  //  meanRjg[4]->SetMarkerStyle(24);
  meanRjg[4]->DrawCopy("same");
  meanRjg[2]->SetFillStyle(3001);
  meanRjg[2]->SetFillColor(kGreen);
  meanRjg[4]->SetFillColor(90);
  meanRjg[4]->SetFillStyle(1001);
  meanRjg[2]->SetLineColor(0);
  meanRjg[4]->SetLineColor(0);
  if ( 1==1 ){
    TLegend *ly = new  TLegend(0.4,0.2,0.75,0.4,NULL,"brNDC");
    easyLeg(ly);
    ly->AddEntry(meanRjg[4],"PbPb 30-100%","fp");
    ly->AddEntry(meanRjg[2],"Smeared pp reference","fp");
    ly->Draw();
  }
  if(!drawSinglePanels)
    drawCMSppPbPbDist(0.04,0.9);
  else
    drawCMSppPbPbDist(0.2,0.9);

  c2->cd(1);
  tempR->SetAxisRange(40,109.99,"X");
  tempR->DrawCopy();
  tempR->SetAxisRange(40.01,109.99,"X");
  drawSys(meanRjg[5], meanRjgSys[5], newYellow);
  drawSys(meanRjg[7], meanRjgSys[2], kGreen, 3001);
  //  handsomeTH1(meanRjg[5],9,1,34);
  handsomeTH1(meanRjg[5],2,1,34);
  handsomeTH1(meanRjg[6],1,1,25);
  handsomeTH1(meanRjg[7],1,1);
  meanRjg[6]->DrawCopy("same");
  meanRjg[7]->DrawCopy("same");
  meanRjg[5]->DrawCopy("same");
  meanRjg[7]->SetFillStyle(3001);
  meanRjg[7]->SetFillColor(kGreen);
  meanRjg[5]->SetFillColor(90);
  meanRjg[5]->SetFillStyle(1001);
  meanRjg[7]->SetLineColor(0);
  meanRjg[5]->SetLineColor(0);

  if ( 1==1 ) {
    TLegend *ly = new TLegend(0.5,0.2,0.85,0.42,NULL,"brNDC");//0.4,0.2,0.75,0.4
    easyLeg(ly);
    ly->AddEntry(meanRjg[5],"pPb DATA","fp");
    ly->AddEntry(meanRjg[7],"pp DATA (2.76 TeV)","fp");
    ly->AddEntry(meanRjg[6],"PYTHIA+HIJING","p");
    ly->Draw();
  }
  drawCMSpPbDist(0.2,0.9);
  
  c2->SaveAs("pT_dependence_rjg_pp_pbpb.pdf");
  c2->SaveAs("pT_dependence_rjg_pp_pbpb.gif");
  //c2->SaveAs("pT_dependence_rjg_pp_pbpb.png");

  // ppPbPb meanJetPt
  TCanvas* c3 = new TCanvas("c3","",1300,500);
  if(!drawSinglePanels)
    makeMultiPanelCanvas(c3,3,1,0.0,0.0, 0.15, 0.15, 0.025);
  else
    c3->Divide(3,1);
    //makeMultiPanelCanvas(c3,3,1,0.2,0.2, 0.15, 0.15, 0.025);
  c3->cd(1);
  handsomeTH1(meanRjg[1],1);
  //  drawSys(TH1 *h,TH1 *sys, Int_t theColor= newYellow, Int_t fillStyle = -1, Int_t lineStyle = -1)
  //  tempR->Draw();
  TH1D* tempJ = new TH1D("tempJ",";p_{T}^{#gamma}; <p_{T}^{Jet}>",10000,40,130);
  tempJ->Reset();
  handsomeTH1(tempJ,0);
  tempJ->SetAxisRange(40.01,109.99,"Y");
  tempJ->SetAxisRange(40.,109.99,"X");
  tempJ->DrawCopy();
  tempJ->SetAxisRange(40.01,109.99,"X");
  drawSys(meanJetPt[5], meanJetPtSys[5], newYellow);
  drawSys(meanJetPt[7], meanJetPtSys[1], kGreen,3001);
  //  handsomeTH1(meanJetPt[5],9,1,34);
  handsomeTH1(meanJetPt[5],2,1,34);
  handsomeTH1(meanJetPt[6],1,1,25);
  handsomeTH1(meanJetPt[7],1,1);
  meanJetPt[6]->DrawCopy("same");
  meanJetPt[7]->DrawCopy("same");
  meanJetPt[5]->DrawCopy("same");
  if ( 1==1 ) {
    TLegend *ly = new TLegend(0.53,0.18,0.88,0.4,NULL,"brNDC");
    easyLeg(ly);
    ly->AddEntry(meanJetPt[5],"pPb DATA","p");
    ly->AddEntry(meanJetPt[7],"pp DATA (2.76 TeV)","p");
    ly->AddEntry(meanJetPt[6],"PYTHIA+HIJING","p");
    ly->Draw();
  }
  drawCMSpPbDist(0.2,0.9);

  
  c3->cd(3);
  handsomeTH1(meanJetPt[1],1,1,21);
  //  drawSys(TH1 *h,TH1 *sys, Int_t theColor= newYellow, Int_t fillStyle = -1, Int_t lineStyle = -1)
  tempJ->Draw();
  drawSys(meanJetPt[3], meanJetPtSys[3]);
  drawSys(meanJetPt[1], meanJetPtSys[1], kGreen,3001);
  handsomeTH1(meanJetPt[3],2 );
  meanJetPt[1]->Draw("same");
  meanJetPt[3]->Draw("same");
  if ( 1==1 ){
    TLegend *ly = new  TLegend(0.58,0.18,0.93,0.4,NULL,"brNDC");
    easyLeg(ly);
    ly->AddEntry(meanJetPt[3],"PbPb 0-30%","p");
    ly->AddEntry(meanJetPt[1],"pp (smeared)","p");
    ly->Draw();
  }
  drawCMSppPbPbDist(0.1,0.9);

  c3->cd(2);
  tempJ->Draw();
  drawSys(meanJetPt[2], meanJetPtSys[2], kGreen,3001);
  drawSys(meanJetPt[4], meanJetPtSys[4]);
  //  meanJetPt[2]->SetMarkerStyle(25);
  meanJetPt[2]->Draw("same");
  handsomeTH1(meanJetPt[4],2 );
  //  meanJetPt[4]->SetMarkerStyle(24);
  meanJetPt[4]->Draw("same");
  if ( 1==1 ){
    TLegend *ly = new  TLegend(0.58,0.18,0.93,0.4,NULL,"brNDC");
    easyLeg(ly);
    ly->AddEntry(meanJetPt[4],"PbPb 30-100%","p");
    ly->AddEntry(meanJetPt[2],"pp (smeared)","p");
    ly->Draw();
  }
  drawCMSppPbPbDist(0.1,0.9);
  c3->SaveAs("pT_dependence_jetPt_pp_pbpb.pdf");
  c3->SaveAs("pT_dependence_jetPt_pp_pbpb.gif");
  //c3->SaveAs("pT_dependence_jetPt_pp_pbpb.png");


  // mean xjg
  TCanvas* c7; 
  if(!drawSinglePanels)
  {
    c7 = new TCanvas("c7","",1300,500);
    makeMultiPanelCanvas(c7,3,1,0.0,0.0, 0.15, 0.15, 0.025);
  }
  else
  {
    c7 = new TCanvas("c7","",1450,500);
    c7->Divide(3,1);
    //makeMultiPanelCanvas(c7,3,1,0.2,0.2, 0.15, 0.15, 0.025);
  }
  c7->cd(3);
  handsomeTH1(meanXjg[1],1,1,24);
  //  drawSys(TH1 *h,TH1 *sys, Int_t theColor= newYellow, Int_t fillStyle = -1, Int_t lineStyle = -1)
  TH1D* tempX = new TH1D("tempX",";p_{T}^{#gamma} (GeV);<X_{J#gamma}>;",10000,40,130);
  tempX->Reset();
  handsomeTH1(tempX,0);
  tempX->SetAxisRange(0.6,1.1,"Y");
  tempX->SetAxisRange(40.01,109.99,"X");
  tempX->GetYaxis()->SetNdivisions(606);
  tempX->Draw();
  drawSys(meanXjg[3], meanXjgSys[3]);
  drawSys(meanXjg[1], meanXjgSys[1], kGreen,3001);
  //  meanXjg[1]->SetMarkerStyle(21);
  handsomeTH1(meanXjg[1],1,1,21);
  meanXjg[1]->DrawCopy("same");
  handsomeTH1(meanXjg[3],2,1,20);
  meanXjg[3]->DrawCopy("same");
  meanXjg[1]->SetFillStyle(3001);
  meanXjg[1]->SetFillColor(kGreen);
  meanXjg[3]->SetFillColor(90);
  meanXjg[3]->SetFillStyle(1001);
  meanXjg[1]->SetLineColor(0);
  meanXjg[3]->SetLineColor(0);

  Float_t xpos = 0.022;
  if(drawSinglePanels)
    xpos = 0.15;
  if ( 1==1 ){
    TLegend *ly = new TLegend(xpos,0.1861745,0.578901,0.3788434,NULL,"brNDC");
    easyLeg(ly);
    ly->AddEntry(meanXjg[3],"PbPb 0-30%","fp");
    ly->AddEntry(meanXjg[1],"Smeared pp reference","fp");
    ly->Draw();
  }
  drawCMSppPbPbDist(0.6,0.9);


  c7->cd(2);
  tempX->Draw();
  drawSys(meanXjg[4], meanXjgSys[4]);
  drawSys(meanXjg[2], meanXjgSys[2], kGreen,3001);
  //  meanXjg[2]->SetMarkerStyle(25);
  handsomeTH1(meanXjg[2],1,1,25);
  meanXjg[2]->DrawCopy("same");
  handsomeTH1(meanXjg[4],2,1,24 );
  //  meanXjg[4]->SetMarkerStyle(24);
  meanXjg[4]->DrawCopy("same");
  meanXjg[2]->SetFillStyle(3001);
  meanXjg[2]->SetFillColor(kGreen);
  meanXjg[4]->SetFillColor(90);
  meanXjg[4]->SetFillStyle(1001);
  meanXjg[2]->SetLineColor(0);
  meanXjg[4]->SetLineColor(0);

  if ( 1==1 ){
    TLegend *ly = new TLegend(xpos,0.1861745,0.578901,0.3788434,NULL,"brNDC");
    easyLeg(ly);
    ly->AddEntry(meanXjg[4],"PbPb 30-100%","fp");
    ly->AddEntry(meanXjg[2],"Smeared pp reference","fp");
    ly->Draw();
  }
  drawCMSppPbPbDist(0.6,0.9);

  c7->cd(1);
  tempX->SetAxisRange(40.0,109.99,"X");
  tempX->DrawCopy();
  tempX->SetAxisRange(40.01,109.99,"X");
  drawSys(meanXjg[5], meanXjgSys[5], newYellow);
  drawSys(meanXjg[7], meanXjgSys[2], kGreen, 3001);
  //  handsomeTH1(meanXjg[5],9,1,34);
  handsomeTH1(meanXjg[5],2,1,34);
  handsomeTH1(meanXjg[6],1,1,25);
  handsomeTH1(meanXjg[7],1,1);
  meanXjg[6]->DrawCopy("same");
  meanXjg[7]->DrawCopy("same");
  meanXjg[5]->DrawCopy("same");
  meanXjg[7]->SetFillStyle(3001);
  meanXjg[7]->SetFillColor(kGreen);
  meanXjg[5]->SetFillColor(90);
  meanXjg[5]->SetFillStyle(1001);
  meanXjg[7]->SetLineColor(0);
  meanXjg[5]->SetLineColor(0);

  if ( 1==1 ) {
    TLegend *ly = new TLegend(0.1722123,0.1861,0.4788343,0.3788,NULL,"brNDC");
    easyLeg(ly);
    ly->AddEntry(meanXjg[5],"pPb DATA","fp");
    ly->AddEntry(meanXjg[7],"pp DATA (2.76 TeV)","fp");    
    ly->AddEntry(meanXjg[6],"PYTHIA+HIJING","p");
    ly->Draw();
  }
  drawCMSpPbDist(0.65,0.90);
  
  c7->SaveAs("pT_dependence_meanXjg_pp_pbpb.pdf");
  c7->SaveAs("pT_dependence_meanXjg_pp_pbpb.gif");
  //c7->SaveAs("pT_dependence_meanXjg_pp_pbpb.png");

  // TCanvas* c10 = new TCanvas("c10","",1200,350);
  // makeMultiPanelCanvas(c10,nPtBin,1,0.0,0.0,0.2,0.15,0.02);
  // for ( int ipt = 1 ; ipt<=nPtBin  ; ipt++) {
  //   c10->cd(ipt);

  //   hTempPt->SetAxisRange(20,200,"X");
  //   hTempPt->SetAxisRange(0,2.5,"Y");
  //   hTempPt->SetYTitle("Yield^{JeT} Ratio");
  //   handsomeTH1(hTempPt,0);
  //   hTempPt->DrawCopy();
  //   IaaRatio[4][ipt] = (TH1D*)Iaa[4][ipt]->Clone(Form("%s_ratio",Iaa[4][ipt]->GetName()) );
  //   IaaRatio[4][ipt]->Divide(Iaa[2][ipt]);
  //   IaaRatioSys[4][ipt] = mergeSys( IaaSys[2][ipt], IaaSys[4][ipt]) ;

  //   drawSys(IaaRatio[4][ipt], IaaRatioSys[4][ipt], newYellow);
  //   jumSun(20,1,200,1);
  //   handsomeTH1(IaaRatio[4][ipt],2);
  //   IaaRatio[4][ipt]->SetMarkerStyle(24);
  //   IaaRatio[4][ipt]->Draw("same");
  //   double dx1=0.15;
  //   drawText(Form("p_{T}^{#gamma} > %dGeV ", (int)ptBin[ipt-1]), 0.12+dx1+0.25,0.85,1,15);//yeonju 130823
  //   drawText(Form("(PbPb)/(pp smeared)  30-100%%"), 0.12+dx1+0.05,0.69,1,15);//yeonju 130823
  // }

  // c10->SaveAs("pT_dependence_iAA_ratio2.pdf");



}
示例#26
0
void AnalyzeData(char *DataFile = "drs4_peds_5buffers.dat", Int_t nevt,
		Int_t startEv = 1, char *PedFile, Int_t DrawExtraGraphs = 0) {


	// Redefine DOMINO Depth in ADC counts
	const Float_t DominoDepthADC = pow(2, DOMINO_DEPTH);

	// open file

	FILE *fdata = OpenDataFile(DataFile);
	struct channel_struct *p;
	struct channel_struct *dep;

	// create histograms
	// create list of histograms for channels and distribution

	TList *DistChList = new TList();
	TH1F *distch; // histo with distribution of cell-charge, for each channel

	TList *DistChSubList = new TList();
	TH1F *distchsub; // histo with distribution of cell-charge, pedestals subtracted, for each channel

	TList *DistCh0SubList = new TList();
	TH1F *distch0sub; // histo with distribution of cell-charge, pedestals subtracted,
	// channel 0 subtracted for each channel

	TList *grPedList = new TList();
	TGraphErrors *grPed; // for each channel, pedestal value and RMS for each cell is plotted

	TList *hCellList = new TList();
	TH1F *hCell; // charge distribution for each cell (DOMINO_NCELL x DOMINO_NCH histos)
	TList *hCellSubList = new TList();
	TH1F *hCellSub; // charge distribution for each cell (DOMINO_NCELL x DOMINO_NCH histos), pedestal subtracted

	TList *hRMSList = new TList();
	TH1F *hRMSdist; // histo with RMS distribution (statistical RMS of distribution)
	TList *hRMSFitList = new TList();
	TH1F *hRMSFitdist; // histo with RMS distribution (RMS of Gaussian fit)

	TList *grDataList = new TList();
	TGraphErrors *grData; // charge-cell and RMS for each cell is plotted

	TList *grDataSubList = new TList();
	TGraphErrors *grDataSub; // pedestal subtracted charge-cell and RMS for each cell is plotted


	for (int h = 0; h < DOMINO_NCH; h++) {
		//
		TString title = "Data Dist channel";
		title += h;
		distch = new TH1F(title, title, DominoDepthADC, 0., DominoDepthADC);
		DistChList->Add(distch);
		//
		TString title = "Data Dist Ped Sub channel";
		title += h;
		distchsub = new TH1F(title, title, DominoDepthADC, -DominoDepthADC/2, DominoDepthADC/2);
		DistChSubList->Add(distchsub);
		//
		TString title = "Data Dist Ped Ch0 Sub channel";
		title += h;
		distch0sub = new TH1F(title, title, DominoDepthADC, -DominoDepthADC/2, DominoDepthADC/2);
		DistCh0SubList->Add(distch0sub);
		//
		TString title = "Pedestal ch";
		title += h;
		grPed = new TGraphErrors(DOMINO_NCELL);
		grPed->SetTitle(title);
		grPedList->Add(grPed);
		//
		TString title = "Data ch";
		title += h;
		grData = new TGraphErrors(DOMINO_NCELL);
		grData->SetTitle(title);
		grDataList->Add(grData);
		//
		// Mean data and RMS for each channel and cell
		TString title = "Data PedSubtracted ch";
		title += h;
		grDataSub = new TGraphErrors(DOMINO_NCELL);
		grDataSub->SetTitle(title);
		grDataSubList->Add(grDataSub);
		//
		for (int ch = 0; ch < DOMINO_NCELL; ch++) {
			// data distribution histos
			TString title = "Data ch";
			title += h;
			title += " cell";
			title += ch;
			hCell = new TH1F(title, title, DominoDepthADC, 0., DominoDepthADC);
			hCellList->Add(hCell);
			// data (ped subtracted) distribution histos
			TString title = "Data PedSub ch";
			title += h;
			title += " cell ";
			title += ch;
			hCellSub = new TH1F(title, title, 2 * DominoDepthADC, -1
					* DominoDepthADC, DominoDepthADC);
			hCellSubList->Add(hCellSub);
		}
		// Data-RMS distribution histos
		TString title = "RMSDist channel";
		title += h;
		hRMSdist = new TH1F(title, title, 100, 0, 20.);
		hRMSList->Add(hRMSdist);
		// Data-RMS (calculated through a fit) distribution histos
		TString title = "RMSFitDist channel";
		title += h;
		hRMSFitdist = new TH1F(title, title, 100, 0, 20.);
		hRMSFitList->Add(hRMSFitdist);
	}
	//--------------
	//
	// calculate or read pedestals from file
	grPedList = OpenPedestals(PedFile);

	//    return;
	//
	// ====== Read data file and subtract the pedestals
	//
	// Count number of events in data file
	int nevtDataMax = 0;
	while (!feof(fdata)) {
		fread((void *) &event_data, 1, sizeof(event_data), fdata);
		nevtDataMax++;
	}
	printf("nevtDataMax: %d\n", nevtDataMax);

	if (nevt > (nevtDataMax - startEv) || nevt == 0)
		nevt = nevtDataMax - startEv;
	cout << endl << "==>> Processing " << nevt << " events from file "
			<< DataFile << endl;

	rewind(fdata);

	Int_t ievt = 1;
	// go to first event (startEv)
	while (ievt < startEv) {
		fread((void *) &event_data, 1, sizeof(event_data), fdata);
		if (feof(fdata))
			break;
		ievt++;
	}
	// filling
	ievt = 1;
	Int_t flagEnd = 0;
	Double_t chtmp;
	Double_t PedVal, itmp, Ch0Val;
	// loop on events
	cout << endl << " --- read DATA file:" << fdata << endl;
	while (ievt <= nevt && !flagEnd) {
		fread((void *) &event_data, 1, sizeof(event_data), fdata);
		if (feof(fdata))
			flagEnd = 1;
		if (ievt % (nevt / 10 + 1) == 0)
			cout << "*" << endl;
		p = (struct channel_struct *) &event_data.ch[0]; // read bunch of data
		dep = (struct channel_struct *) &event_data.ch[1]; // read bunch of data

		TGraphErrors *grCh0 = new TGraphErrors(DOMINO_NCELL);

		// loop on channels
		for (int h = 0; h < DOMINO_NCH; h++) {
			// loop on cells
			distch = (TH1F *) DistChList->At(h);
			distchsub = (TH1F *) DistChSubList->At(h);
			grPed = (TGraphErrors *) grPedList->At(h);
			distch0sub = (TH1F *) DistCh0SubList->At(h);
			if(h==0) {
				for(i = 0; i < DOMINO_NCELL;i++) {
					grPed->GetPoint(i, itmp, PedVal);
					chtmp = (Double_t)(p->data[i]);
					chtmp = chtmp - PedVal;
					grCh0->SetPoint(i,itmp, chtmp);
				}
			}
			for (int i = 0; i < DOMINO_NCELL; i++) {
				// Read pedestal value for this cell
				grPed->GetPoint(i, itmp, PedVal);
				grCh0->GetPoint(i, itmp, Ch0Val);
				//                cout << itmp << ", " << PedVal << endl;
				// Read calibration correction for this cell
				//                CalFact =

				//charge distribution for each cell, pedestal subtracted
				chtmp = (Double_t)(p->data[i]); // data value
				//                cout  << "tcell, tcell, depth: " << chtmp << ","  << p->data[i] << "," << deptmp << endl;
				distch->Fill(chtmp);
				// Check data value: must be within DOMINO Depth
				//                if(chtmp > DominoDepthADC)
				//                    cout << " === WARNING!!! Channel " << h << " Cell " << i << " has value " << chtmp << endl;
				//                cout << "Charge: " << p->data[i] << endl;
				((TH1 *) hCellList->At(h * DOMINO_NCELL + i))->Fill(chtmp);
				// Now the pedestal is subtracted
				chtmp = chtmp - PedVal;
				distchsub->Fill(chtmp);
				((TH1 *) hCellSubList->At(h * DOMINO_NCELL + i))->Fill(chtmp);
				chtmp = chtmp - Ch0Val;
				distch0sub->Fill(chtmp);
			}
			p++; // next channel
		}
		ievt++; // next event
	}
	cout << endl;

	// now mean and RMS for each cell are computed and save in histos and graphs
	cout << " --- filling data histos and grphs " << endl;
	TF1 *fgauss = new TF1("fgauss", Gauss, -10., 10., 3);
	fgauss->SetParLimits(0, 0.1, 10000.);
	fgauss->SetParLimits(1, 0., 4096.);
	fgauss->SetParLimits(2, 0.1, 20.);
	Float_t mean, rms, meansub, rmssub;
	for (int h = 0; h < DOMINO_NCH; h++) {
		//        for (int h=5; h<6; h++){
		cout << " Channel:" << h << endl;
		hRMSdist = (TH1F *) hRMSList->At(h);
		hRMSFitdist = (TH1F *) hRMSFitList->At(h);
		grData = (TGraphErrors *) grDataList->At(h);
		grDataSub = (TGraphErrors *) grDataSubList->At(h);
		for (int ch = 0; ch < DOMINO_NCELL; ch++) {
			// data distribution histos
			//            cout << "cell:" << ch << " index:" << h*DOMINO_NCELL+ch << " Mean,RMS:"<<hCell->GetMean()<< "," << hCell->GetRMS()<<endl;
			hCell = (TH1F *) hCellList->At(h * DOMINO_NCELL + ch);
			mean = hCell->GetMean();
			rms = hCell->GetRMS();
			hCellSub = (TH1F *) hCellSubList->At(h * DOMINO_NCELL + ch);
			meansub = hCellSub->GetMean();
			rmssub = hCellSub->GetRMS();
			fgauss->SetParameter(0, (Double_t) nevt / 4.);
			fgauss->SetParameter(1, mean);
			fgauss->SetParameter(2, rms);
			//            hCell->Fit("fgauss","QN0");
			grData->SetPoint(ch, ch, mean);
			grData->SetPointError(ch, 0, rms);
			grDataSub->SetPoint(ch, ch, meansub);
			//            grDataSub->SetPointError(ch,0.5,rmssub);
			grDataSub->SetPointError(ch, 0.5, 2.1);
			hRMSdist->Fill(rms);
			hRMSFitdist->Fill(fgauss->GetParameter(2));
			//           cout << "cell:" << ch << " index:" << h*DOMINO_NCELL+ch << " Mean,RMS:"<< mean << "," << rms<<endl;
		}
	}

	Double_t x, y, chtmp, x1, x2, y1, y2;

	/*TList *grCellCalibList = OpenCalibFile("CalibrationData1000events.root");

	TGraphErrors *grCellCalib;
	TGraphErrors *grDataSubCalib = new TGraphErrors(DOMINO_NCELL);
	grDataSubCalib->SetTitle("Data after calibration correction");
	grDataSub = (TGraphErrors *) grDataSubList->At(anaChannel);


	for(ch = 0; ch < DOMINO_NCELL; ch++) {
		grCellCalib = ((TGraphErrors *) grCellCalibList->At(ch));
		grCellCalib->Fit("pol3", "Q");
		TF1 *pol3fit = ((TF1 *) grCellCalib->GetFunction("pol3"));
		grDataSub->GetPoint(ch, x, y);
		chtmp = y - (Double_t)(pol3fit->Eval(y/3.25));
		grDataSubCalib->SetPoint(ch, x, chtmp);
	}

	TCanvas *cGrTest = new TCanvas("grTest", "test per vedere i dati", 1000,1000);

	grDataSubCalib->Draw("APEL");*/


	TString Title = "Charge Distribution per channel";
	gStyle->SetOptFit(111);
	TCanvas *cdistch = new TCanvas("cdistch", Title, 1000, 1000);
	cdistch->Divide(3, 3);
	for (int i = 0; i < DOMINO_NCH; i++) {
		cdistch->cd(i + 1);
		TH1 *dhist = (TH1 *) DistChList->At(i);
		dhist->DrawCopy();
		dhist->SetLineWidth(1);
		dhist->Fit("gaus", "Q");
		dhist->GetFunction("gaus")->SetLineColor(4);
		dhist->GetFunction("gaus")->SetLineWidth(2);
	}

	TString Title = "Charge Distribution Pedestals Subtracted per channel";
	TCanvas *cdistchsub = new TCanvas("cdistchsub", Title, 1000, 1000);
	cdistchsub->Divide(3, 3);
	for (int i = 0; i < DOMINO_NCH; i++) {
		cdistchsub->cd(i + 1);
		TH1 *dsubhist = (TH1 *) DistChSubList->At(i);
		dsubhist->DrawCopy();
		dsubhist->SetLineWidth(1);
		dsubhist->Fit("gaus", "Q");
		dsubhist->GetFunction("gaus")->SetLineColor(4);
		dsubhist->GetFunction("gaus")->SetLineWidth(2);
	}

	TString Title = "Charge Distribution Pedestals and Ch0 Subtracted per channel";
	TCanvas *cdistch0sub = new TCanvas("cdistch0sub", Title, 1000, 1000);
	cdistch0sub->Divide(3, 3);
	for (int i = 0; i < DOMINO_NCH; i++) {
		cdistch0sub->cd(i + 1);
		TH1 *dch0subhist = (TH1 *) DistCh0SubList->At(i);
		dch0subhist->DrawCopy();
		dch0subhist->SetLineWidth(1);
		dch0subhist->Fit("gaus", "Q");
		dch0subhist->GetFunction("gaus")->SetLineColor(4);
		dch0subhist->GetFunction("gaus")->SetLineWidth(2);
	}

	TCanvas *cDataSubTest = new TCanvas("cDataSubTest", "Data after pedestal subtraction", 1000, 1000);
	cDataSubTest->Divide(1,8);
	for (h = 0; h< DOMINO_NCH; h++) {
		grDataSub = (TGraphErrors *) grDataSubList->At(h);
		cDataSubTest->cd(h+1);
		grDataSub->GetYaxis()->SetLabelSize(0.06);
		grDataSub->GetXaxis()->SetLabelSize(0.06);
		grDataSub->Draw("APE");
	}

	TCanvas *cDataSubTestCh5 = new TCanvas("cDataSubTestCh5", "Data after pedestal subtraction Ch5", 1200, 800);
	grDataSub = (TGraphErrors *) grDataSubList->At(anaChannel);
	grDataSub->GetYaxis()->SetLabelSize(0.06);
	grDataSub->GetYaxis()->SetTitle("ADC Counts");
	grDataSub->GetXaxis()->SetTitle("Cell");
	grDataSub->GetXaxis()->SetLabelSize(0.06);
	TLine *refval = new TLine(0,350,1024,350);
	refval->SetLineWidth(3);
	refval->SetLineStyle(2);
	refval->SetLineColor(2);
	TLine *i1 = new TLine(121,-50,121,800);
	i1->SetLineStyle(2);
	TLine *i2 = new TLine(291,-50,291,800);
	i2->SetLineStyle(2);
	TLine *i3 = new TLine(461,-50,461,800);
	i3->SetLineStyle(2);
	TLine *i4 = new TLine(632,-50,632,800);
	i4->SetLineStyle(2);
	TLine *i5 = new TLine(803,-50,803,800);
	i5->SetLineStyle(2);
	TLine *i6 = new TLine(975,-50,975,800);
	i6->SetLineStyle(2);
	TLine *ireal1 = new TLine(121+20,600,121+20,800);
	ireal1->SetLineWidth(3);
	ireal1->SetLineColor(4);
	TLine *ireal2 = new TLine(291-20,600,291-20,800);
	ireal2->SetLineWidth(3);
	ireal2->SetLineColor(4);
	TLine *ireal3 = new TLine(461+20,600,461+20,800);
	ireal3->SetLineWidth(3);
	ireal3->SetLineColor(4);
	TLine *ireal4 = new TLine(632-20,600,632-20,800);
	ireal4->SetLineWidth(3);
	ireal4->SetLineColor(4);
	TLine *ireal5 = new TLine(803+20,600,803+20,800);
	ireal5->SetLineWidth(3);
	ireal5->SetLineColor(4);
	TLine *ireal6 = new TLine(975-20,600,975-20,800);
	ireal6->SetLineWidth(3);
	ireal6->SetLineColor(4);
	grDataSub->Draw("APE");
	refval->Draw("SAME");
	i1->Draw("SAME");
	i2->Draw("SAME");
	i3->Draw("SAME");
	i4->Draw("SAME");
	i5->Draw("SAME");
	i6->Draw("SAME");
	ireal1->Draw("SAME");
	ireal2->Draw("SAME");
	ireal3->Draw("SAME");
	ireal4->Draw("SAME");
	ireal5->Draw("SAME");
	ireal6->Draw("SAME");


	TCanvas *cDataTest = new TCanvas("cDataTest", "Raw Data", 1000,1000);
	cDataTest->Divide(1,8);
	for(h = 0; h < DOMINO_NCH; h++) {
		cDataTest->cd(h+1);
		grData = (TGraphErrors *) grDataList->At(h);
		grData->SetMarkerStyle(20);
		grData->SetMarkerSize(0.5);
		grData->Draw("APE");

	}

	// save root file with graph containing channel 5 data after pedestals subtraction.
	/*
	cout << "test" << endl;

	TString OutFile = DataSubFile;
	TFile *f = new TFile(OutFile,"RECREATE");
	int h = anaChannel;
	TString key="DataSubGraph";
	key += h;
	((TGraphErrors*)grDataSubList->At(h))->Write(key);
	f->Close();
	cout << " ---- Write data on file " << endl;
	 */

	// =======================================================//
	// =====================Matteo's Code=====================//
	// =======================================================//
	/*
	Int_t cht, incCht, decCht, xflag, nPeriods, iMax, iMin;
	Double_t xdiff, incDiff, decDiff, incDiffTemp, decDiffTemp, incXDiff, decXDiff;
	Double_t fitMax, fitMin, fitPeriod, chisquare;
	Double_t DominoXval[DOMINO_NCELL];
	Double_t DominoYval[DOMINO_NCELL];
	Double_t FitXval[DOMINO_NCELL];
	Double_t FitYval[DOMINO_NCELL];


        // opens grDataSub.root

        TString FileName = DataSubFile;
        TGraphErrors *grDataSub;
        int h = anaChannel;
        TFile *f = new TFile(FileName);
        TString key = "DataSubGraph";
        key += h;
        grDataSub = (TGraphErrors *) f->Get(key);
        f->Close();


	// Create a new graph with channel 5 data
	TGraphErrors *grDataSubAnaCh;
	int h = anaChannel;
	grDataSubAnaCh = (TGraphErrors *) grDataSubList->At(h);

	TGraphErrors *grDataSubFix = grDataSubAnaCh->Clone();
	TGraphErrors *grRes = new TGraphErrors(DOMINO_NCELL);
	TList *grResPeriodList = new TList();



	Double_t xtemp, ytemp, DominoMax, DominoMin;

	for (int ch = 0; ch < DOMINO_NCELL; ch++){
		// get domino-output point and save in array
		grDataSubAnaCh->GetPoint(ch, DominoXval[ch], DominoYval[ch]);
	}

	// find the domino point with max y-value
	iMax = 0;
	for(int ch = 0; ch < DOMINO_NCELL; ch++) {
		if(DominoYval[ch] > DominoYval[iMax]) {
			DominoMax = DominoYval[ch];
			iMax = ch;
		}
	}

	cout << "DominoMax e': " << DominoMax << endl;

	// find the domino point with min y-value
	iMin = 0;
	for (int ch = 0; ch < DOMINO_NCELL; ch++) {
		if(DominoYval[ch] < DominoYval[iMin]) {
			DominoMin = DominoYval[ch];
			iMin = ch;
		}
	}

	cout << "DominoMin e': " << DominoMin << endl;

	// remove points from the graph that will be used for fit
	for (int ch = 0; ch < DOMINO_NCELL; ch++){
		grDataSubFix->GetPoint(ch, xtemp, ytemp);
		if(ytemp > 0.8*DominoMax || ytemp < 0.2*DominoMin)
			grDataSubFix->RemovePoint(ch);
	}


	TF1 *fsin = new TF1("fsin", sigSin, 0., 1024., 4);
	fsin->SetParameters(600., DOMINO_NCELL / 4., 150., 150.);
	fsin->SetParNames("amplitude", "Period", "Phase", "DC-Offset");
	grDataSubFix->Fit("fsin");
	TF1 *fsinFit = grDataSubFix->GetFunction("fsin");
	fsinFit->SetParNames("amplitude", "Period", "Phase", "DC-Offset");
	chisquare = grDataSub->Chisquare(fsinFit);
	cout << "il chi quadro della funzione di fit e' : " << chisquare << endl;

	for (int ch = 0; ch < DOMINO_NCELL; ch++) {
		// get Fit-value and save in array
		FitXval[ch] = DominoXval[ch];
		FitYval[ch] = fsinFit->Eval(FitXval[ch]);
	}

	fitPeriod = fsinFit->GetParameter("Period");
	cout << "il periodo della funzione e': " << fitPeriod << endl;

	nPeriods = (Int_t) (DOMINO_NCELL/fitPeriod);
	cout << "il numero di periodi della funzione e': " << nPeriods << endl;

	fitMax = fsinFit->GetMaximum();
	cout << "il massimo della funzione e': " << fitMax << endl;

	fitMin = fsinFit->GetMinimum();
	cout << "il minimo della funzione e': " << fitMin << endl;




	// computes the y difference between the ch-domino point and the i-fit point
	// and stops when the difference changes sign
	//
	// first and last points are not included in the cicle
	//
	// if the fit point y-value is bigger or smaller than the fit function max*0.8 or min*0.2
	// the point is removed

	for (int ch = 1; ch < DOMINO_NCELL - 1; ch++) {

		if(FitYval[ch] > 0.8*fitMax || FitYval[ch] < 0.2*fitMin) {
			grRes->RemovePoint(ch);
			continue;
		}

		incDiff = DominoYval[ch] - FitYval[ch];
		incDiffTemp = DominoYval[ch] - FitYval[ch + 1];

		decDiff = DominoYval[ch] - FitYval[ch];
		decDiffTemp = DominoYval[ch] - FitYval[ch - 1];

		if(abs(incDiffTemp) < abs(incDiff) || (sign(incDiff) != sign(incDiffTemp) && abs(decDiffTemp) > abs(decDiff))) {
			for (int i = ch; i < DOMINO_NCELL; i++, incDiff = incDiffTemp) {
				incDiffTemp = DominoYval[ch] - FitYval[i];

				if (sign(incDiff) != sign(incDiffTemp)) {
					if(abs(incDiffTemp) < abs(incDiff))
						incCht = i;
					else
						incCht = i - 1;
					break;
				}
			}
			xflag = 1;
		}
		else if(abs(decDiffTemp) < abs(decDiff) || (sign(decDiff) != sign(decDiffTemp) && abs(incDiffTemp) > abs(incDiff))) {
			for (int j = ch; j >= 0 ; j--, decDiff = decDiffTemp) {
				decDiffTemp = DominoYval[ch] - FitYval[j];

				if (sign(decDiff) != sign(decDiffTemp)) {
					if(abs(decDiffTemp) < abs(decDiff))
						decCht = j;
					else
						decCht = j + 1;
					break;
				}
			}
			xflag = -1;
		}

		if(xflag == 1)
			xdiff = FitXval[incCht] - DominoXval[ch];
		else
			xdiff = FitXval[decCht] - DominoXval[ch];

		grRes->SetPoint(ch, (Double_t) ch, xdiff);
	}

	cout << "Draw Time Residuals" << endl;
	TString Title = "Time Residuals";
	TCanvas *timeres = new TCanvas("timeres", Title, 1200, 780);
	grRes->SetMarkerStyle(20);
	grRes->SetMarkerSize(0.3);
	grRes->GetYaxis()->SetLabelSize(0.12);
	grRes->GetXaxis()->SetLabelSize(0.12);
	grRes->Draw("APE");


	// The previous graph is now split in N graphs, where N is the number of fit periods

	// this will be needed to set the function phase
	//
    //    iMax = 0;
	//
    //    for(ch = 0; ch < fitPeriod - 1; ch++) {
    //            if(FitYval[ch] > FitYval[iMax]) iMax = ch;
    //    }

	cout << "il primo massimo ha l'indice : " << iMax << endl;

	for (i = 0; i < nPeriods; i++) {
		TGraphErrors *grResPeriod = new TGraphErrors((Int_t) fitPeriod);
		grResPeriodList->Add(grResPeriod);

		for(ch = i*fitPeriod + 1; ch < fitPeriod + (i*fitPeriod); ch++) {

			if(FitYval[ch] > 0.8*fitMax || FitYval[ch] < 0.2*fitMin) {
				grResPeriod->RemovePoint(ch);
				continue;
			}

			incDiff = DominoYval[ch] - FitYval[ch];
			incDiffTemp = DominoYval[ch] - FitYval[ch + 1];

			decDiff = DominoYval[ch] - FitYval[ch];
			decDiffTemp = DominoYval[ch] - FitYval[ch - 1];

			if(abs(incDiffTemp) < abs(incDiff) || (sign(incDiff) != sign(incDiffTemp) && abs(decDiffTemp) > abs(decDiff))) {
				for (int k = ch; k < k*fitPeriod + fitPeriod; k++, incDiff = incDiffTemp) {
					incDiffTemp = DominoYval[ch] - FitYval[k];

					if (sign(incDiff) != sign(incDiffTemp)) {
						if(abs(incDiffTemp) < abs(incDiff))
							incCht = k;
						else
							incCht = k - 1;
						break;
					}
				}
				xflag = 1;
			}
			else if(abs(decDiffTemp) < abs(decDiff) || (sign(decDiff) != sign(decDiffTemp) && abs(incDiffTemp) > abs(incDiff))) {
				for (int j = ch; j > i*fitPeriod; j--, decDiff = decDiffTemp) {
					decDiffTemp = DominoYval[ch] - FitYval[j];

					if (sign(decDiff) != sign(decDiffTemp)) {
						if(abs(decDiffTemp) < abs(decDiff))
							decCht = j;
						else
							decCht = j + 1;
						break;
					}
				}
				xflag = -1;
			}

			if(xflag == 1)
				xdiff = FitXval[incCht] - DominoXval[ch];
			else
				xdiff = FitXval[decCht] - DominoXval[ch];

			grResPeriod->SetPoint(ch - i*fitPeriod, (Double_t) (ch - i*fitPeriod), xdiff);
		}
	}

	TCanvas *timeresperiod = new TCanvas("timeresperiod", "Time Residuals Period", 1200, 780);
	for(i = 0; i < nPeriods; i++) {
		grResPeriod = ((TGraphErrors *) grResPeriodList->At(i));
		grResPeriod->SetMarkerStyle(20);
		grResPeriod->SetMarkerSize(0.3);
		grResPeriod->GetYaxis()->SetLabelSize(0.12);
		grResPeriod->GetXaxis()->SetLabelSize(0.12);
		grResPeriod->Draw("APEsame");
	}

	cout << "Draw Data - Pedestals Subtracted" << endl;
	TString Title = "Average Charge - Pedestal subtracted";
	TCanvas *csubdata = new TCanvas("csubdata", Title, 1200, 780);
	grDataSubAnaCh->SetMarkerStyle(20);
	grDataSubAnaCh->SetMarkerSize(0.3);
	grDataSubAnaCh->GetYaxis()->SetLabelSize(0.12);
	grDataSubAnaCh->GetXaxis()->SetLabelSize(0.12);
	grDataSubAnaCh->Draw("APE");
	fsinFit->Draw("same");
	 */
	// draw extra graphs
	if (DrawExtraGraphs == 1) {
		cout << " ----- DRAW Results ------" << endl;
		//================ DRAW Results ==================

		TCanvas *c = new TCanvas("ctmp", "test", 800, 800);
		c->Divide(3, 3);
		for (int pad = 1; pad < 10; pad++) {
			c->cd(pad);
			((TH1 *) hCellList->At(pad * 512 + 219))->DrawCopy();
			hCellSub = (TH1F *) hCellSubList->At(pad * 512 + 219);
			hCellSub->SetLineColor(2);
			hCellSub->DrawCopy("same");
		}

		cout << "Draw RMS distributions" << endl;
		TString Title = "RMS distributions per channel";
		TCanvas *c4 = new TCanvas("c4", Title, 700, 700);
		c4->Divide(3, 3);
		for (int i = 0; i < DOMINO_NCH; i++) {
			c4->cd(i + 2);
			hRMSdist = (TH1F *) hRMSList->At(i);
			hRMSFitdist = (TH1F *) hRMSFitList->At(i);
			hRMSFitdist->SetLineColor(2);
			hRMSFitdist->DrawCopy();
			hRMSdist->DrawCopy("same");
		}


		TList *grDataCh0SubList = new TList();
		TGraphErrors *grDataCh0Sub;
		for(h = 0; h< DOMINO_NCELL; h++) {
			grDataCh0Sub = new TGraphErrors(DOMINO_NCELL);
			grDataCh0SubList->Add(grDataCh0Sub);
		}

		TGraphErrors *grDataSubCh0 = (TGraphErrors *) grDataSubList->At(6);
		for(h = 0; h < DOMINO_NCH; h++) {
			grDataSub = (TGraphErrors *) grDataSubList->At(h);
			grDataCh0Sub = (TGraphErrors *) grDataCh0SubList->At(h);
			for(ch = 0; ch < DOMINO_NCELL; ch++) {
				grDataSubCh0->GetPoint(ch, x1, y1);
				grDataSub->GetPoint(ch, x2, y2);
				grDataCh0Sub->SetPoint(ch, x1 , y2 - y1);
			}
		}

		TCanvas *cDataCH0Sub = new TCanvas("cDataCH0Sub","cDataCH0Sub", 1000,1000);
		cDataCH0Sub->Divide(1,8);
		for(h = 0; h < DOMINO_NCH; h++) {
			cDataCH0Sub->cd(h+1);
			grDataCh0Sub = (TGraphErrors *) grDataCh0SubList->At(h);
			grDataCh0Sub->GetYaxis()->SetLabelSize(0.12);
			grDataCh0Sub->GetXaxis()->SetLabelSize(0.12);
			grDataCh0Sub->Draw("APEL");
		}



		cout << "Draw Data - Pedestals Subtracted" << endl;
		TString Title = "Average Charge - Pedestal subtracted";
		TCanvas *csubdata = new TCanvas("csubdata", Title, 1000, 1000);
		csubdata->Divide(3,3);

		for(h = 0; h < DOMINO_NCH; h++) {
			csubdata->cd(h+1);
			TString title = "DataSub channel ";
			title += h;
			TH1F *hCellDataSub = new TH1F(title, title, 100, -20, 20);
			grDataSub = (TGraphErrors *) grDataSubList->At(h);
			for(ch = 0; ch < DOMINO_NCELL; ch++) {
				grDataSub->GetPoint(ch, x, y);
				hCellDataSub->Fill(y);
			}
			hCellDataSub->Fit("gaus", "Q");
			hCellDataSub->GetXaxis()->SetTitle("ADC Counts");
			hCellDataSub->GetFunction("gaus")->SetLineColor(4);
			hCellDataSub->DrawCopy();
		}

		cout << "breakpoint" << endl;
		TCanvas *csubdata2 = new TCanvas("csubdata2", "DataSub for every channel", 1000, 1000);
		TString title = "DataSub every channel ";
		TH1F *hCellChDataSubTot = new TH1F(title, title, 100, -20, 20);
		for(h = 0; h < DOMINO_NCH; h++) {
			grDataSub = (TGraphErrors *) grDataSubList->At(h);
			for(ch = 0; ch < DOMINO_NCELL; ch++) {
				grDataSub->GetPoint(ch, x, y);
				hCellChDataSubTot->Fill(y);
			}
			hCellChDataSubTot->Fit("gaus", "Q");
			hCellChDataSubTot->GetXaxis()->SetTitle("ADC Counts");
			hCellChDataSubTot->GetFunction("gaus")->SetLineColor(4);
			hCellChDataSubTot->Draw();
		}

		cout << "Draw Pedestals" << endl;
		TString Title = "Pedestals";
		TCanvas *c2 = new TCanvas("c2", Title, 1050, 780);
		c2->SetBorderMode(0);
		c2->SetBorderSize(0.);
		c2->Divide(1, 8);
		//    gStyle->SetCanvasBorderMode(0.);
		//    gStyle->SetCanvasBorderSize(0.);
		Double_t x, y;
		for (int h = 0; h < DOMINO_NCH; h++) {
			c2->cd(h + 1);
			grPed = ((TGraphErrors *) grPedList->At(h));
			grPed->SetMarkerStyle(20);
			grPed->SetMarkerSize(0.5);
			grPed->GetYaxis()->SetLabelSize(0.12);
			grPed->GetXaxis()->SetLabelSize(0.12);
			//        cout <<  " err:" << grPed->GetErrorY(102) << " " ;
			//        cout << x << "--" << y << endl;
			grPed->Draw("APE");
		}

		cout << "Draw Data - Average charge" << endl;
		TString Title = "Average_Charge";
		TCanvas *cdata = new TCanvas("cdata", Title, 1050, 780);
		cdata->Divide(1, 8);
		Double_t x, y;
		for (int h = 0; h < DOMINO_NCH; h++) {
			cdata->cd(h + 1);
			grData = ((TGraphErrors *) grDataList->At(h));
			grData->SetMarkerStyle(20);
			grData->SetMarkerSize(0.3);
			grData->GetYaxis()->SetLabelSize(0.12);
			grData->GetXaxis()->SetLabelSize(0.12);
			grData->GetPoint(10, x, y);
			//        cout << x << "-" << y << endl;
			grData->Draw("APE");
		}

		cout << "Draw Data - Pedestals Subtracted" << endl;
		TString Title = "Average Charge - Pedestal subtracted";
		TCanvas *csubdata = new TCanvas("csubdata", Title, 1200, 780);
		csubdata->Divide(1, 8);
		TF1 *fsin = new TF1("fsin", sigSin, 0., 1024., 4);
		TH1D *resDist = new TH1D("resDist", "Residuals Signal", 100, -100., 100.);

		cout << "Draw Data - Pedestals Subtracted" << endl;
		TString Title = "Residuals";
		TCanvas *residuals = new TCanvas("residuals", Title, 1200, 780);
		resDist->DrawCopy();

	}

	fclose(fdata);

	hCellList->Delete();
	hCellSubList->Delete();
	hRMSList->Delete();
	hRMSFitList->Delete();
}
示例#27
0
文件: C.cpp 项目: jsmallcombe/jaent
int main(int argc, char *argv[]){	
// int argcb;
// char **argvb;	
TApplication *app = new TApplication("app", &argc, argv);
TH1::AddDirectory(kFALSE);//avoid name overwrites but could cause other memory histogram issues
//        h->SetDirectory(0);          for the current histogram h
	
	double worldsize=80;
	exp_core experiment(worldsize);
	
	//
	// Set the option you wish to run
	//
	int control =0;
	// 0 = EVERYTHING
	// 1 = geometry
	// 2 = Rutherford
	// 3 = Decay position
	// 4 = Distribution hits
	// 5 = Draw events for real time viewing
	
	bool save_text=true;//saves terminal output but no terminal output until completion
	
	//
	// Set the target
	//
	double density_targ=1.55;
	double density_back=19.32;
	target tharget(20,40,1000,180.0,0,10000,79,197);
	experiment.set_targ(tharget);
	
	//
	// Set the beam
	//
	double ebeam=120; //MeV
	experiment.set_beam(18,36,ebeam);	
		
	//
	// Input your physics
	//
	double excited_Z=34;
	double excited_A=70;
	double initial_state_MeV = 1.4;
	double transition_keV = 200;
	bool excited_beam_like=false;
	double halflife=0.003;//in ns
	string dist="";// leave blank for a uniform distribution

	//
	// Setup Detectors
	//	
	
	int config=0; // 0 normal, 1 stopper, 2 old
	int S3=1; // 0 off, 1 S3 simple, 2 S3 rings , 3 pin
	double overr=0; // mm >0 non-default S3 / pin position
	

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////// END OF USER INPUT ////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	double t_d=0.2,t_u=0.35*pi;

	///////// First we sort output files ////////
	
	// Create the names 
	stringstream ss;
	ss<<"outputs/SPICE_"<<experiment.channelnames(experiment.get_BZ(),experiment.get_BA());
	ss<<"_"<<experiment.channelnames(experiment.get_TZ(),experiment.get_TA());
	if(tharget.backing_thickness>0)
		ss<<"_"<<experiment.channelnames(tharget.backing_Z,tharget.backing_A)<<"_backed";
	ss<<"_"<<ebeam<<"MeV";
	string file_title=ss.str();
	
	// Check if the root file exists already 
	bool exist=false;
	TFile* outfile= new TFile((file_title+".root").c_str(),"READ");
	if(outfile->IsOpen()){exist=true;outfile->Close();delete outfile;}
	
	// Open the file root file to right, whether or not it exists
	outfile= new TFile((file_title+".root").c_str(),"UPDATE");//Open an existing file for writing. If no file exists, it is created.
	gROOT->cd();// 

// This code is for capturing the terminal output
std::streambuf *psbuf, *backup;
std::ofstream filestr;	
if(save_text){
	// Append if the root file is being
	if(exist){filestr.open(file_title+".txt",std::ofstream::app);filestr<<endl<<"/////// APPEND //////"<<endl;} //appended
	else filestr.open(file_title+".txt");
	backup = std::cout.rdbuf();     // back up cout's streambuf
	psbuf = filestr.rdbuf();        // get file's streambuf
	std::cout.rdbuf(psbuf);         // assign streambuf to cout
}

	// Create the canvas that is used as an inbetween for the whole program
	TCanvas * can_view = new TCanvas("can_view", "can_view", 1200, 600);
	gStyle->SetOptStat(0);
	can_view->cd();
	
	/////////////////////////////////////////////////////
	////////////////// Draw Geometry ////////////////////
	/////////////////////////////////////////////////////
	
	// This loop outputs graphics of the chosen detector geography
	if(control==0||control==1){spice_auto_setup(experiment,config,S3,overr);

		if(!outfile->GetDirectory("Geometry"))outfile->mkdir("Geometry");
		gROOT->cd();
		
		can_view->cd();can_view->Clear();
		experiment.draw_exp();
		outfile->cd("Geometry");
		can_view->SetName("3Dview");can_view->Write("3Dview",TObject::kOverwrite);
		gROOT->cd();
		
		can_view->cd();can_view->Clear();
		experiment.draw_exp(2);
		outfile->cd("Geometry");
		can_view->SetName("side_view");can_view->Write("side_view",TObject::kOverwrite);
		gROOT->cd();
		
		can_view->cd();can_view->Clear();
		experiment.draw_exp(3);
		outfile->cd("Geometry");
		can_view->SetName("beam_view");can_view->Write("beam_view",TObject::kOverwrite);
		gROOT->cd();
		
		can_view->cd();can_view->Clear();
		experiment.draw_phi();
		outfile->cd("Geometry");
		can_view->SetName("theta_view");can_view->Write("theta_view",TObject::kOverwrite);
		gROOT->cd();
	}
	
	/////////////////////////////////////////////////////	
	//////// Calculate Rutherford and Kinematics ////////
	/////////////////////////////////////////////////////

	// This loop calculates the basic beam target kinematics and Rutherford scattering rates
	if(control==0||control==2){spice_auto_setup(experiment,config,S3,overr);
		//experiment.set_rutherford();//sets reaction
		experiment.set_elastic();
		
		can_view->Clear();
		can_view->Divide(2);
		can_view->cd(1);
		experiment.set_ruthmask(t_d,t_u,true,false);// Cut down on wasted simulations by only focusing on the region of interest
		experiment.draw_hit_pattern_2D(1,1000000,1,1,0);
		((TH2D*)gPad->GetPrimitive("Hit_Map_copy"))->SetTitle("Target");
		can_view->cd(2);
		experiment.set_ruthmask(t_d,t_u,false,true);
		experiment.draw_hit_pattern_2D(1,1000000,1,0,1);
		((TH2D*)gPad->GetPrimitive("Hit_Map_copy"))->SetTitle("Beam");
		outfile->cd();
		can_view->SetName("Hit_map_rutherford");can_view->Write("Hit_map_rutherford",TObject::kOverwrite);
		gROOT->cd();
		
		can_view->Clear();can_view->cd();
		experiment.draw_primary_kinematics();
		outfile->cd();
		can_view->SetName("Kinematics");can_view->Write("Kinematics",TObject::kOverwrite);
		gROOT->cd();
		
		experiment.auto_rutherford_OTT(100000,true);
		if(S3==2){spice_auto_setup(experiment,config,1,overr);experiment.auto_rutherford_OTT(100000,true);}
	}
	

	
	/////////////////////////////////////////////////////	
	////// Experimental Interaction and Detection ///////
	/////////////////////////////////////////////////////

	// This loop calculates data for the reaction of interest
	// 
	if(control==0||control==3||control==4||control==5){
		if(excited_Z<0||excited_A<0){
			if(excited_beam_like){
				experiment.set_reco(experiment.get_BZ(),experiment.get_BA());
			}else{
				experiment.set_elastic();
			}			
		}else{
			experiment.set_reco(excited_Z,excited_A);
		}
		
		// Now we set the target interaction and decay information		
		experiment.set_target_interaction(2);//E^2 is a reasonably approximation for most of our stuff
		
		experiment.set_E_star(initial_state_MeV);
		
		experiment.set_ICE(transition_keV);
		// experiment.density_targ=density_targ;// experiment.density_back=density_back;
		if(halflife>0) experiment.set_halflife_ns(halflife,density_targ,density_back); // Can set the densities directly as well

		//set some distribution
		if(dist.size()>0){
			experiment.set_primary_dist(dist);
		}else{
			//experiment.set_uniform(t_d,t_u);
			TFormula fot("fot","sin(x)");
			experiment.set_primary_dist(&fot);//using this one so we can use the same masking for both
		}
		
		if(excited_beam_like)experiment.reverse_primary_dist();//because distribution defined for beam like by default but RECOIL is excited
		
		experiment.set_implant_escape(-1); //SET THIS so things dont escape when they go wack into things
		
		int z=2;// Detector number of the first heavy ion detector
		if(S3==2)z++;// If S3, skip the PCB. PCBs left out for the diodes in spice_auto_setup
		
		//////////////////////////////
		////// FINISHED SET UP ///////
		//////////////////////////////
		
		experiment.print_reaction();
		experiment.print_target();
		experiment.print_decay();
// 		experiment.print_detectables();
		
		outfile->cd();
			experiment.dist_target_KE_beam.Write("KE_though_target",TObject::kOverwrite);
		gROOT->cd();	
		
		if(control==0||control==3){spice_auto_setup(experiment,config,S3,overr);
			experiment.basic_decay_check(100000);

			// Draw the target and decay things
			// quite important to check things are set and working right
			can_view->Clear();can_view->Divide(2);
			can_view->cd(1);
			experiment.draw_decay_Z(0,true,10);
			can_view->cd(2);
			experiment.draw_target_interaction(0,true);
			outfile->cd();
			can_view->SetName("Ungated_Decay_Position");can_view->Write("Ungated_Decay_Position",TObject::kOverwrite);
			gROOT->cd();
			
			for(int i=z;i<experiment.detN();i++){ //set only the daughter recoil as valid in the S3 or pins
				experiment.set_valid_part(i,0,0,1,0);
			}
			string n=experiment.channelnames(experiment.get_D1Z(),experiment.get_D1A())+"_Gated_Decay_Position";
			experiment.mask_manual(t_d,t_u,true,false);//saves on wasted computation

			can_view->Clear();can_view->Divide(2);
			can_view->cd(1);
			experiment.draw_decay_Z(1,true,10);
			can_view->cd(2);
			experiment.draw_target_interaction(1,true);
			outfile->cd();
			can_view->SetName(n.c_str());can_view->Write(n.c_str(),TObject::kOverwrite);
			gROOT->cd();		
			
			
			for(int i=z;i<experiment.detN();i++){ //set only the ejectile as valid in the S3 or pins
				experiment.set_valid_part(i,0,1,0,0);
			}		
			string N=experiment.channelnames(experiment.get_EZ(),experiment.get_EA())+"_Gated_Decay_Position";
			experiment.mask_manual(t_d,t_u,false,true);//saves on wasted computation

			
			can_view->Clear();can_view->Divide(2);
			can_view->cd(1);
			experiment.draw_decay_Z(1,true,10);
			can_view->cd(2);
			experiment.draw_target_interaction(1,true);
			outfile->cd();
			can_view->SetName(N.c_str());can_view->Write(N.c_str(),TObject::kOverwrite);
			gROOT->cd();
		}
		
		// Distribution hit loops
		if(control==0||control==4){spice_auto_setup(experiment,config,S3,overr);
			can_view->Clear();
			can_view->cd();
			
			experiment.mask_manual(t_d,t_u,true,true);
			double ra=experiment.manual_primary_dist_hist.Integral();//Ask what fraction we have masked too, as unmask integral = 1	
			// Print a basic output of fractions of hits
			cout<<endl<<endl<<"Multiply by fraction "<<ra;
			experiment.basic_hit_count(100000,true,1,1,0,0);
						
			string r=experiment.channelnames(experiment.get_RZ(),experiment.get_RA());
			string e=experiment.channelnames(experiment.get_EZ(),experiment.get_EA());
			experiment.manual_primary_dist_hist.SetLineWidth(2);			
			
			TH1D full;
			// Get theta CM for different hit conditions					
			// Fetch the manual CM distribution histogram and the speed masked one
			// We want to show the mask so we know we havent cut it too small			
			can_view->Clear();
			can_view->Divide(2);
			can_view->cd(1);
				experiment.mask_manual(t_d,t_u,true,false);//saves on wasted computation
				full=experiment.manual_primary_dist_store;
				ra=experiment.manual_primary_dist_hist.Integral();//Ask what fraction we have masked too, as unmask integral = 1			
				full.SetTitle(("CM_theta_dist_"+r+"_gated").c_str());
				
				//Get theta CM for different hit condition	
				TH1D recoh=experiment.theta_hist(500000,true,1,0,0,0);
				recoh.SetLineColor(2);		
				recoh.Scale(ra*(full.GetBinWidth(1)/recoh.GetBinWidth(1)));//Some basic scaling to match distribution histogram	

				full.DrawCopy();
				experiment.manual_primary_dist_hist.DrawCopy("same");
				recoh.DrawCopy("same");
			can_view->cd(2);
				experiment.mask_manual(t_d,t_u,false,true);//saves on wasted computation
				full=experiment.manual_primary_dist_store;
				ra=experiment.manual_primary_dist_hist.Integral();
				full.SetTitle(("CM_theta_dist_"+e+"_gated").c_str());
				
				TH1D ejech=experiment.theta_hist(500000,true,0,1,0,0);
				ejech.SetLineColor(2);				
				ejech.Scale(ra*(full.GetBinWidth(1)/ejech.GetBinWidth(1)));
				
				full.DrawCopy();
				experiment.manual_primary_dist_hist.DrawCopy("same");
				ejech.DrawCopy("same");
			outfile->cd();
			can_view->SetName("CM_angles");can_view->Write("CM_angles",TObject::kOverwrite);
			gROOT->cd(); 			
			
			can_view->Clear();
			can_view->Divide(2);
			can_view->cd(1);
			experiment.mask_manual(t_d,t_u,true,false);//saves on wasted computation
				experiment.draw_hit_pattern_2D(1,500000,1,1,0);
				((TH2D*)gPad->GetPrimitive("Hit_Map_copy"))->SetTitle(r.c_str());
			can_view->cd(2);
				experiment.mask_manual(t_d,t_u,false,true);//saves on wasted computation
				experiment.draw_hit_pattern_2D(1,500000,1,0,1);
				((TH2D*)gPad->GetPrimitive("Hit_Map_copy"))->SetTitle(e.c_str());
			outfile->cd();
			can_view->SetName("Hit_map_ditribution");can_view->Write("Hit_map_ditribution",TObject::kOverwrite);
			gROOT->cd(); 		
			
			
			can_view->Clear();
			can_view->cd();
				experiment.mask_manual(t_d,t_u,true,true);//saves on wasted computation
				experiment.auto_E_theta(500000,1,1,1);
			outfile->cd();
			can_view->SetName("Theta_E");can_view->Write("Theta_E",TObject::kOverwrite);
			gROOT->cd(); 

		}
		
		if(control==5){spice_auto_setup(experiment,config,S3,overr);
			can_view->Clear();
			can_view->cd();
			experiment.draw_hits_3D(2);
		}
	}
	
	
	

	
	
	
	
	
	
// 
// 	// Next we spend 20 seconds drawing events so that if something is very wrong it can be corrected
// 	// We set multiplicity=1 so it will only show us S3 good events
// 	experiment.draw_hits_3D(2,1,true,0.5,1,true,20);
// 	//draw_hits_3D(projection,hit_multiplicity,obstructions,display_time,refresh_rate,draw_misses,run_time)
// 
// 	
// 	


	
	
	
	
if(save_text){
	std::cout.rdbuf(backup);        // restore cout's original streambuf
	filestr.close();
		
	string x;
	ifstream inFile(file_title+".txt");
	while (getline(inFile,x)){
	cout << x << endl ;
	}
	inFile.close();

	outfile->cd();
	TMacro mac((file_title+".txt").c_str()); 
	mac.Write("terminal.txt",TObject::kOverwrite);
}	


	outfile->Close();
	cout<<endl<<"/////////////////////////////////////////////////////////////////////////"<<endl;	
	app->Run();
	return 0;
}	
void drawSys_merged() {
  //  TH1::SetDefaultSumw2();
    gStyle -> SetOptStat(0);
    const int kPPcentral = 1;
    const int kPPperipheral =2 ;
    const int kHIcentral =  3;
    const int kHIperipheral = 4;
    const int kPADATA = 5;
    const int kPAMC = 6;

  TH1D* dNdJetPt[7][5]; // [collision] [ ptbin]  [Before/After variation]
  TH1D* dNdJetPtSys[7][5]; // [collision] [ ptbin]  [Before/After variation]
  TH1D* dNdJetPtSysIaa[7][5]; // [collision] [ ptbin]  [Before/After variation]
  TH1D* meanJetPt[7];   // [collision] [Before/After variation]
  TH1D* meanJetPtSys[7];   // [collision] [Before/After variation]
  TH1D* meanRjg[7];
  TH1D* meanRjgSys[7];
  
  TH1D* bmeanJetPt[7];   // [collision] [Before/After variation]
  TH1D* bmeanJetPtSys[7];   // [collision] [Before/After variation]
  TH1D* bmeanRjg[7];
  TH1D* bmeanRjgSys[7];
  
  TFile * f = new TFile("../resultHistograms_ppSmeared10030.root");
  bmeanJetPt[1]  =(TH1D*)f->Get(Form("meanJetPt_pp"));
  bmeanRjg[1]  =(TH1D*)f->Get(Form("meanRjg_pp"));
  for ( int ipt = 1 ; ipt <=nPtBin ; ipt++) {
    dNdJetPt[1][ipt] = (TH1D*)f->Get(Form("dNdJetPt_pp_ptBin%d", ipt ));
  }  

  f   = new TFile("../resultHistograms_ppSmeared13099.root");
  bmeanJetPt[2]  =(TH1D*)f->Get(Form("meanJetPt_pp"));
  bmeanRjg[2]  =(TH1D*)f->Get(Form("meanRjg_pp"));
  for ( int ipt = 1 ; ipt <=nPtBin ; ipt++) {
    dNdJetPt[2][ipt] = (TH1D*)f->Get(Form("dNdJetPt_pp_ptBin%d", ipt ));
  }  
  
  // pbpb
  f =   new TFile("../resultHistograms_jetResCorrection.root");
  bmeanJetPt[3]  =(TH1D*)f->Get(Form("meanJetPt_pbpb_centralityBin1"));
  bmeanRjg[3]  =(TH1D*)f->Get(Form("meanRjg_pbpb_centralityBin1"));
  for ( int ipt = 1 ; ipt <=nPtBin ; ipt++) {
    dNdJetPt[3][ipt] = (TH1D*)f->Get(Form("dNdJetPt_pbpb_centralityBin1_ptBin%d", ipt ));
  }
  bmeanJetPt[4]  =(TH1D*)f->Get(Form("meanJetPt_pbpb_centralityBin2"));
  bmeanRjg[4]  =(TH1D*)f->Get(Form("meanRjg_pbpb_centralityBin2"));
  for ( int ipt = 1 ; ipt <=nPtBin ; ipt++) {
    dNdJetPt[4][ipt] = (TH1D*)f->Get(Form("dNdJetPt_pbpb_centralityBin2_ptBin%d", ipt ));
  }
  // pPb
  f =   new TFile("../resultHistograms_jetResCorrection.root");
  bmeanJetPt[5]  =(TH1D*)f->Get(Form("meanJetPt_ppb"));
  bmeanRjg[5]  =(TH1D*)f->Get(Form("meanRjg_ppb"));
  for ( int ipt = 1 ; ipt <=nPtBin ; ipt++) {
    dNdJetPt[5][ipt] = (TH1D*)f->Get(Form("dNdJetPt_ppb_ptBin%d", ipt ));
  }
  
  f =   new TFile("../resultHistograms_MC_recoIsoPhoton.root");
  bmeanJetPt[6]  =(TH1D*)f->Get(Form("meanJetPt_ppb"));
  bmeanRjg[6]  =(TH1D*)f->Get(Form("meanRjg_ppb"));
  for ( int ipt = 1 ; ipt <=nPtBin ; ipt++) {
    dNdJetPt[6][ipt] = (TH1D*)f->Get(Form("dNdJetPt_ppb_ptBin%d", ipt ));
  }  
  
  
  TFile* fSys = new TFile("../merged/relativeSys_merged.root");
  
  bmeanJetPtSys[1]  =(TH1D*)fSys->Get("meanJetPt_pp_uncertainty_merged");
  bmeanRjgSys[1]  =(TH1D*)fSys->Get(Form("meanRjg_pp_uncertainty_merged"));
  for ( int ipt = 1 ; ipt <=nPtBin ; ipt++) {
    dNdJetPtSysIaa[1][ipt] = (TH1D*)fSys->Get(Form("dNdJetPt_IaaBin_pp_ptBin%d_uncertainty_merged",  ipt ));
  }
  bmeanJetPtSys[2] = (TH1D*)bmeanJetPtSys[1]->Clone(Form("%s_2",bmeanJetPtSys[1]->GetName()));
  bmeanRjgSys[2] = (TH1D*)bmeanRjgSys[1]->Clone(Form("%s_2",bmeanRjgSys[1]->GetName()));
  for ( int ipt = 1 ; ipt <=nPtBin ; ipt++) {
    dNdJetPtSysIaa[2][ipt] = (TH1D*)dNdJetPtSysIaa[1][ipt]->Clone(Form("%s_2",dNdJetPtSysIaa[1][ipt]->GetName()));
  }
  bmeanJetPtSys[3]  =(TH1D*)fSys->Get("meanJetPt_pbpb_centralityBin1_uncertainty_merged");
  bmeanRjgSys[3]  =(TH1D*)fSys->Get(Form("meanRjg_pbpb_centralityBin1_uncertainty_merged"));
  for ( int ipt = 1 ; ipt <=nPtBin ; ipt++) {
    dNdJetPtSysIaa[3][ipt] = (TH1D*)fSys->Get(Form("dNdJetPt_IaaBin_pbpb_centralityBin1_ptBin%d_uncertainty_merged",  ipt ));
  }
  bmeanJetPtSys[4]  =(TH1D*)fSys->Get("meanJetPt_pbpb_centralityBin2_uncertainty_merged");
  bmeanRjgSys[4]  =(TH1D*)fSys->Get(Form("meanRjg_pbpb_centralityBin2_uncertainty_merged"));
  for ( int ipt = 1 ; ipt <=nPtBin ; ipt++) {
    dNdJetPtSysIaa[4][ipt] = (TH1D*)fSys->Get(Form("dNdJetPt_IaaBin_pbpb_centralityBin2_ptBin%d_uncertainty_merged",  ipt ));
  }
  bmeanJetPtSys[5]  =(TH1D*)fSys->Get("meanJetPt_ppb_uncertainty_merged");
  bmeanRjgSys[5]  =(TH1D*)fSys->Get(Form("meanRjg_ppb_uncertainty_merged"));
  for ( int ipt = 1 ; ipt <=nPtBin ; ipt++) {
    dNdJetPtSysIaa[5][ipt] = (TH1D*)fSys->Get(Form("dNdJetPt_IaaBin_ppb_ptBin%d_uncertainty_merged",  ipt ));
  }


  
  // transplant the uncertainty  
  for ( int coll = 1 ; coll<=5 ; coll++) {
    for ( int ipt = 1 ; ipt <=nPtBin ; ipt++) {
      dNdJetPtSys[coll][ipt] = (TH1D*) dNdJetPt[coll][ipt]->Clone(Form("dNdJetPtSys_coll%d_ipt%d",coll,ipt));
      dNdJetPtSys[coll][ipt]->Reset();
      for ( int ibin = 1 ; ibin<= dNdJetPtSys[coll][ipt]->GetNbinsX() ; ibin++) {
	float xx = dNdJetPtSys[coll][ipt]->GetBinCenter(ibin);
	float yy = dNdJetPtSysIaa[coll][ipt]->GetBinContent ( dNdJetPtSysIaa[coll][ipt]->FindBin(xx) );
	if ( yy>1 ) yy = 1;
	dNdJetPtSys[coll][ipt]->SetBinContent(ibin,yy);

      }
    }
  }

  for(int icoll=1; icoll<=6; icoll++){
      meanJetPt[icoll] = new TH1D(Form("%s_corrected", bmeanJetPt[icoll]->GetName()), "", nPtBin, ptBinPaDraw);
      meanRjg[icoll] = new TH1D(Form("%s_corrected", bmeanRjg[icoll]->GetName()), "", nPtBin, ptBinPaDraw);
      if(icoll<6){
          meanJetPtSys[icoll] = new TH1D(Form("%s_corrected", bmeanJetPtSys[icoll]->GetName()), "", nPtBin, ptBinPaDraw);
          meanRjgSys[icoll] = new TH1D(Form("%s_corrected", bmeanRjgSys[icoll]->GetName()), "", nPtBin, ptBinPaDraw);
      }
  }

  for(int icoll=1; icoll<=6; icoll++){ 
      meanPtHist(bmeanJetPt[icoll], meanJetPt[icoll]);    
      meanPtHist(bmeanRjg[icoll],  meanRjg[icoll]); 
      if(icoll<6){
          meanPtHist(bmeanJetPtSys[icoll],meanJetPtSys[icoll]) ;  
          meanPtHist(bmeanRjgSys[icoll], meanRjgSys[icoll]); 
      }
  } 

  // RJG!!
  TCanvas* c2 = new TCanvas("c1","",1000,500);
  c2->Divide(2,1);
  c2->cd(2);
  handsomeTH1(meanRjg[1],1);
  //  drawSys(TH1 *h,TH1 *sys, Int_t theColor= kYellow, Int_t fillStyle = -1, Int_t lineStyle = -1)
  TH1D* tempR = new TH1D("tempR",";p_{T}^{#gamma};R_{j#gamma}",100,40,130);
  tempR->Reset();  
  handsomeTH1(tempR,0);
  tempR->SetAxisRange(0,1.2,"Y");
  tempR->Draw();
  drawSys(meanRjg[1], meanRjgSys[1], kGreen);
  drawSys(meanRjg[3], meanRjgSys[3]);
  meanRjg[1]->Draw("same");
  handsomeTH1(meanRjg[3],2 );
//  meanRjg[3]->SetMarkerStyle(24);
  meanRjg[3]->Draw("same");
  if ( 1==1 ){ 
    TLegend *ly = new  TLegend(0.4937249,0.262193,0.8493139,0.4740574,NULL,"brNDC");    
    easyLeg(ly,"2.76TeV");
    ly->AddEntry(meanRjg[3],"PbPb 0-30%","p");
    ly->AddEntry(meanRjg[1],"pp (smeared)","p");
    ly->Draw();
  }


  c2->cd(1);
  tempR->Draw();
  handsomeTH1(meanRjg[2],1 );
  drawSys(meanRjg[2], meanRjgSys[2], kGreen);
  drawSys(meanRjg[4], meanRjgSys[4]);
  meanRjg[2]->Draw("same");
  handsomeTH1(meanRjg[4],2 );
  meanRjg[4]->SetMarkerStyle(24);
  meanRjg[4]->Draw("same");
  if ( 1==1 ){ 
    TLegend *ly = new  TLegend(0.4937249,0.262193,0.8493139,0.4740574,NULL,"brNDC");    
    easyLeg(ly,"2.76TeV");
    ly->AddEntry(meanRjg[4],"PbPb 30-100%","p");
    ly->AddEntry(meanRjg[2],"pp (smeared)","p");
    ly->Draw();
  }
  c2->SaveAs("pT_depedence_rjg_pp_pbpb.pdf");

  
  TCanvas* c2pa = new TCanvas("c1pa","",500,500);
  handsomeTH1(meanRjg[1],1);
  //  drawSys(TH1 *h,TH1 *sys, Int_t theColor= kYellow, Int_t fillStyle = -1, Int_t lineStyle = -1)                         
  //  tempR->Draw();
  TH1D* tempJ = new TH1D("tempJ",";p_{T}^{#gamma}; <p_{T}^{Jet}>",100,40,130);
  tempJ->Reset();
  handsomeTH1(tempJ,0);
  tempJ->SetAxisRange(0,100,"Y");
  tempJ->Draw();
  drawSys(meanJetPt[5], meanJetPtSys[5], kYellow);
  handsomeTH1(meanJetPt[5],2);
  handsomeTH1(meanJetPt[6],1);
  meanJetPt[5]->Draw("same");
  meanJetPt[6]->Draw("same");
  if ( 1==1 ) {
    TLegend *ly = new TLegend(0.4484643,0.3088445,0.9140673,0.50102941,NULL,"brNDC");
    easyLeg(ly,"5.02TeV pPb");
    ly->AddEntry(meanJetPt[5],"DATA","p");
    ly->AddEntry(meanJetPt[6],"PYTHIA+HIJING","p");
    ly->Draw();
  }
  c2pa->SaveAs("pT_dependence_rjg_pA_figure1.pdf");

  TCanvas* c3pa = new TCanvas("c3pa","",500,500);
  tempR->Draw();
  drawSys(meanRjg[5], meanRjgSys[5], kYellow);
  handsomeTH1(meanRjg[5],2);
  handsomeTH1(meanRjg[6],1);
  meanRjg[5]->Draw("same");
  meanRjg[6]->Draw("same");
  if ( 1==1 ) {
    TLegend *ly = new TLegend(0.4484643,0.3088445,0.9140673,0.50102941,NULL,"brNDC");
    easyLeg(ly,"5.02TeV pPb");
    ly->AddEntry(meanRjg[5],"DATA","p");
    ly->AddEntry(meanRjg[6],"PYTHIA+HIJING","p");
    ly->Draw();
  }  
  c3pa->SaveAs("pT_dependence_jetPt_pA_figure2.pdf");

  TCanvas* c3 = new TCanvas("c3","",1000,500);
  c3->Divide(2,1);
  c3->cd(2);
  handsomeTH1(meanJetPt[1],1);
  //  drawSys(TH1 *h,TH1 *sys, Int_t theColor= kYellow, Int_t fillStyle = -1, Int_t lineStyle = -1)                                                       
   tempJ->Draw();
  drawSys(meanJetPt[1], meanJetPtSys[1], kGreen);
  drawSys(meanJetPt[3], meanJetPtSys[3]);
  meanJetPt[1]->Draw("same");
  handsomeTH1(meanJetPt[3],2 );
  meanJetPt[3]->Draw("same");
  if ( 1==1 ){
    TLegend *ly = new  TLegend(0.4937249,0.262193,0.8493139,0.4740574,NULL,"brNDC");
    easyLeg(ly,"2.76TeV");
    ly->AddEntry(meanJetPt[3],"PbPb 0-30%","p");
    ly->AddEntry(meanJetPt[1],"pp (smeared)","p");
    ly->Draw();
  }
  
  c3->cd(1);
  tempJ->Draw();
  handsomeTH1(meanJetPt[2],1 );
//  meanJetPt[2]->Draw();
  drawSys(meanJetPt[2], meanJetPtSys[2], kGreen);
  drawSys(meanJetPt[4], meanJetPtSys[4]);
  meanJetPt[2]->Draw("same");
  handsomeTH1(meanJetPt[4],2 );
  meanJetPt[4]->SetMarkerStyle(24);
  meanJetPt[4]->Draw("same");
  if ( 1==1 ){
    TLegend *ly = new  TLegend(0.4937249,0.262193,0.8493139,0.4740574,NULL,"brNDC");
    easyLeg(ly,"2.76TeV");
    ly->AddEntry(meanJetPt[4],"PbPb 30-100%","p");
    ly->AddEntry(meanJetPt[2],"pp (smeared)","p");
    ly->Draw();
  }
  c3->SaveAs("pT_dependence_jetPt_pp_pbpb.pdf");
  
  TH1D* hTempPt = new TH1D("hTemp",";p_{T}^{#gamma} (GeV);",200,10,300);
  TCanvas* c5 = new TCanvas("c5","",1200,700);
  makeMultiPanelCanvas(c5,nPtBin,2,0.0,0.0,0.2,0.15,0.02);
  for ( int ipt = 1 ; ipt<=nPtBin  ; ipt++) {
    c5->cd(ipt+nPtBin);
    // draw pp                                                                                                                                           
    hTempPt->SetXTitle("p_{T}^{Jet} (GeV)");
    hTempPt->SetYTitle("#frac{dN}{dp_{T}} #frac{1}{N}");
    hTempPt->SetAxisRange(10,150,"X");
    //        hTempPt->SetAxisRange(0,0.025,"Y");                                                                                                        
    hTempPt->SetAxisRange(0,0.07,"Y");
    handsomeTH1(hTempPt,0);
    hTempPt->DrawCopy();

    drawSys(dNdJetPt[1][ipt], dNdJetPtSys[1][ipt], kGreen);
    drawSys(dNdJetPt[3][ipt], dNdJetPtSys[3][ipt], kYellow);
    handsomeTH1(dNdJetPt[3][ipt],2);
    dNdJetPt[1][ipt]->Draw("same");
    dNdJetPt[3][ipt]->Draw("same");
    if ( ipt == 1 ) {
      TLegend *ly = new TLegend(0.4484643,0.6988445,0.9140673,0.9102941,NULL,"brNDC");
      easyLeg(ly,"2.76TeV");
      ly->AddEntry(meanJetPt[1],"PbPb 0-30%","p");
      ly->AddEntry(meanJetPt[3],"pp (smeared)","p");
      ly->Draw();
    }
 

    c5->cd(ipt);
    hTempPt->DrawCopy();

    drawSys(dNdJetPt[2][ipt], dNdJetPtSys[2][ipt], kGreen);
    drawSys(dNdJetPt[4][ipt], dNdJetPtSys[4][ipt], kYellow);
    handsomeTH1(dNdJetPt[4][ipt],2);
    dNdJetPt[4][ipt]->SetMarkerStyle(24);
    dNdJetPt[2][ipt]->Draw("same");
    dNdJetPt[4][ipt]->Draw("same");
    if ( ipt==1 ){
      TLegend *ly = new TLegend(0.4484643,0.5088445,0.9140673,0.75102941,NULL,"brNDC");
      easyLeg(ly,"2.76TeV");
      ly->AddEntry(meanJetPt[4],"PbPb 30-100%","p");
      ly->AddEntry(meanJetPt[2],"pp (smeared)","p");
      ly->Draw();
    }

    double dx1=0.15;
    if ( ipt == nPtBin )
      drawText(Form("p_{T}^{#gamma} > %dGeV, ", (int)ptBin[ipt-1]), 0.12+dx1+0.25,0.85,1,15);//yeonju 130823                                           
    else
      drawText(Form("%dGeV < p_{T}^{#gamma} < %dGeV, ", (int)ptBin[ipt-1], (int)ptBin[ipt]), 0.12+dx1,0.85,1,15);//yeonju 130823                       

    
  }
  c5->SaveAs("pT_dependence_jetPt_pp_pbpb_distribution.pdf");

  TCanvas* c5pa = new TCanvas("c5pa","",1200,350);
  makeMultiPanelCanvas(c5pa,nPtBin,1,0.0,0.0,0.2,0.15,0.02);
  for ( int ipt = 1 ; ipt<=nPtBin  ; ipt++) {
    c5pa->cd(ipt);
    // draw pp                                                                                                                                           
    hTempPt->SetXTitle("p_{T}^{Jet} (GeV)");
    hTempPt->SetYTitle("#frac{dN}{dp_{T}} #frac{1}{N}");
    hTempPt->SetAxisRange(10,150,"X");
    //        hTempPt->SetAxisRange(0,0.025,"Y");                                                                                                        
    hTempPt->SetAxisRange(0,0.07,"Y");
    handsomeTH1(hTempPt,0);
    hTempPt->DrawCopy();

    drawSys(dNdJetPt[5][ipt], dNdJetPtSys[5][ipt], kYellow);
    handsomeTH1(dNdJetPt[5][ipt],2);
    dNdJetPt[6][ipt]->Draw("same");
    dNdJetPt[5][ipt]->Draw("same");
    if ( ipt == 1 ) {
      TLegend *ly = new TLegend(0.4855983,0.5529059,0.9512013,0.7645899,NULL,"brNDC");
      easyLeg(ly,"5.02TeV pPb");
      ly->AddEntry(meanJetPt[5],"Data","p");
      ly->AddEntry(meanJetPt[6],"PYTHIA+HIJING","p");
      ly->Draw();
    }
    double dx1=0.15;
    if ( ipt == nPtBin )
      drawText(Form("p_{T}^{#gamma} > %dGeV, ", (int)ptBin[ipt-1]), 0.12+dx1+0.25,0.85,1,15);//yeonju 130823                                           
    else
      drawText(Form("%dGeV < p_{T}^{#gamma} < %dGeV, ", (int)ptBin[ipt-1], (int)ptBin[ipt]), 0.12+dx1,0.85,1,15);//yeonju 130823                       
    
    
  }
  c5pa->SaveAs("pT_dependence_jetPt_pA_distribution.pdf");
  
  
  
}
示例#29
0
文件: DrawTHStack.C 项目: XuQiao/HI
void DrawTHStack(){
        static const int nColor = 9;
        static const int colorCode[nColor] = {
        1,2,3,6,4,8,1,9,5};
	gStyle->SetOptStat(kFALSE);
	int sth=0; int Gth=0;
	TFile *f = TFile::Open(outG);
	TObjArray *hs[3];
        std::vector<TH1D*> h[3];
	TCanvas *c1 = new TCanvas("c1","stacked hists",10,10,600,600);
	c1->SetLogy();
	TString dirname;
	TString name;	
        TH1D* hFrame = new TH1D("","",4000,0,4000);
	hFrame->GetXaxis()->SetRangeUser(0,500);
	hFrame->GetYaxis()->SetRangeUser(1,1e5);
	hFrame->GetXaxis()->SetTitle("N_{part}");
	hFrame->GetYaxis()->SetTitle("# of Events");
        hFrame->DrawCopy();
       	if(Gth==0)
        	name = "G0";
        else if(Gth<nGlau && Gth>0)
        	name = Form("Glau_%d",Gth);
        else
        	name = Form("bin_%d",Gth-nGlau+1);
        TVectorD *centbin = (TVectorD*)f->Get(Form("std/G0/centbin"));
        TVectorD *kpoint = (TVectorD*)f->Get(Form("std/G0/kpoint"));

	for(int sth=0; sth<1; sth++){
        	if(sth==0){dirname = "std";}
        	else if(sth==1){dirname ="Gri055";}
        	else {dirname ="Gri101";}
		hs[sth] = (TObjArray*)f->Get(Form("%s/%s/Npartdis",dirname.Data(),name.Data()));
                h[sth].resize(N);
                for(int i=0;i<N;i++){
//		h[sth][i] = (TH1D*)hs[sth]->GetStack()->At(N-1);
		h[sth][i] = (TH1D*)hs[sth]->At(i);
		h[sth][i]->SetLineColor(colorCode[i]);
		h[sth][i]->SetMarkerSize(1.0);
		h[sth][i]->SetMarkerStyle(20);
		h[sth][i]->SetMarkerColor(colorCode[i]);
		h[sth][i]->Draw("Psame");
//                hs[sth]->Draw("Psame");
                }
	}
    std::vector<TString> label(N);
	TLegend *leg0 = new TLegend(0.60,0.60,0.90,0.88);
    leg0->SetFillColor(10);
    leg0->SetBorderSize(0);
    leg0->SetTextFont(42);
    leg0->SetTextSize(0.030);
    for(int i=0;i<N;i++){
	if(method==0)label[i] = Form("%.2f-%.2f%%",(*centbin)[i]*100,(*centbin)[i+1]*100);
	else label[i] = Form("%.2f-%.2f",(*kpoint)[i],(*kpoint)[i+1]);
//    leg0->AddEntry(h[0][i],"standard","p");
    leg0->AddEntry(h[0][i],label[i],"p");
    }
 //   leg0->AddEntry(h[1],"Gribov #Omega=0.55","p");
 //   leg0->AddEntry(h[2],"Gribov #Omega=1.01","p");
        leg0->Draw();
c1->Print("Npartdis.pdf");
c1->Print("Npartdis.png");
}
示例#30
-1
void MCtoSTATerrors() {
  TLatex *tplus = labelLatex(0.1364943,0.8114407,"MC sample");

  TFile *file0 = TFile::Open("results/StandardCutflow/allmc.root");

  TCanvas *c1 = new TCanvas();
  //TCanvas *c2 = new TCanvas();
  TH1D * LPplus = (TH1D*)file0->Get("RECO_PolPlots_50toinf/RECO_ICVarPFPlus");
  TH1D * LPminus = (TH1D*)file0->Get("RECO_PolPlots_50toinf/RECO_ICVarPFMinus");

  LPplus->Rebin(20);
  LPminus->Rebin(20);

  LPplus->Scale(0.3);
  LPminus->Scale(0.3);

  TH1D * newLPplus = (TH1D*)LPplus->Clone();
  TH1D * newLPminus = (TH1D*)LPminus->Clone();

  for(unsigned int i=1; i < LPplus->GetXaxis()->GetNbins(); i++) {
    newLPplus->SetBinError(i, TMath::Sqrt(LPplus->GetBinContent(i)));
    newLPminus->SetBinError(i, TMath::Sqrt(LPminus->GetBinContent(i)));
  }

  c1->cd();
  newLPplus->GetYaxis()->SetTitle("Events / 300 nb^{-1}");
  //newLPplus->GetXaxis()->SetTitle("LP(#mu^{+})");
  newLPplus->GetXaxis()->SetTitle("LP(#mu)");
  newLPplus->GetXaxis()->SetRangeUser(-1.0,2.0);
  newLPplus->SetLineWidth(3);
  newLPplus->SetLineStyle(2);
  newLPplus->SetLineColor(kRed);
  newLPplus->DrawCopy();
  tplus->DrawClone("same");

//   c2->cd();
//   newLPminus->GetYaxis()->SetTitle("Events / 100 nb^{-1}");
//   newLPminus->GetXaxis()->SetTitle("LP(#mu^{-})");
  newLPminus->SetLineWidth(3);
  newLPminus->SetLineStyle(2);
  newLPminus->SetLineColor(kBlack);
  newLPminus->DrawCopy("same");
//   tplus->DrawClone("same");

  leg = new TLegend(0.762931,0.720339,0.8649425,0.8622881,NULL,"brNDC");
  leg->AddEntry(newLPplus,"#mu^{+}","l");
  leg->AddEntry(newLPminus,"#mu^{-}","l");

  leg->SetFillColor(kWhite);
  leg->SetBorderSize(0);
  leg->SetTextFont(62);
  leg->DrawClone();

  file0->Close();

  return;
}