Esempio n. 1
0
TH2D* GetJetCorrFunc2D_doublegaussian(int itrg, int jass)
{
                    TH2D* hcorr = (TH2D*)GetRawCorrFunc2D_ratio(itrg,jass);
                    TH2D* hcorr_clone = (TH2D*)hcorr->Clone(Form("corr_clone_itrg%d_jass%d",itrg,jass));
                    hcorr_clone->Reset();
		    for(int ietabin=1;ietabin<=hcorr->GetNbinsX();ietabin++)
		    {
                      TH1D* hcorrphi = (TH1D*)hcorr->ProjectionY(Form("corrphi_%d",ietabin),ietabin,ietabin,"e");  
                      float min = hcorrphi->GetMinimum();
                      hcorrphi->SetAxisRange(-1,1,"X");
                      float nearmax = hcorrphi->GetMaximum();
                      hcorrphi->SetAxisRange(PI-1,PI+1,"X");
                      float awaymax = hcorrphi->GetMaximum();

		      TF1* fitfunc = new TF1("fitfunc",doubleGaussian,-PI/2.,3.*PI/2.,5);		    
                      fitfunc->SetParameters(min,nearmax-min,0.3,awaymax-min,0.5);  
                      fitfunc->SetParLimits(0,0,100000);
                      fitfunc->SetParLimits(1,0,100000);
                      fitfunc->SetParLimits(2,0,100000);
                      fitfunc->SetParLimits(3,0,100000);
                      fitfunc->SetParLimits(4,0,100000);		    
		      for(int ifit=0;ifit<3;ifit++) hcorrphi->Fit(Form("fitfunc_%d",ietabin),"RNO");                     
		      float level = fitfunc->GetParameter(0);

		      for(int iphibin=1;iphibin<=hcorr->GetNbinsY();iphibin++) 
                        hcorr_clone->SetBinContent(ietabin,iphibin,hcorr->GetBinContent(ietabin,iphibin)-level);                      
                      delete fitfunc;
		    }

                    float max = hcorr_clone->GetBinContent(hcorr_clone->GetMaximumBin());
                    hcorr_clone->SetAxisRange(ymin,max*1.3,"Z");
                    return hcorr_clone;
}
Esempio n. 2
0
void plotgvsr_MC(){
gStyle->SetOptStat(kFALSE);
TCanvas *c1 = new TCanvas();
c1->SetLogy();
TH1D* hFrame = new TH1D("","",1000,0,1);
hFrame->GetYaxis()->SetRangeUser(5e-9,1);
hFrame->GetXaxis()->SetRangeUser(0.15,0.50);
hFrame->GetXaxis()->SetTitle("r");
hFrame->GetYaxis()->SetTitle("|G^{#theta}(ir)|^{2}");
hFrame->SetTitle("");
hFrame->Draw();
TGraph *gr[nnu];
double r0[nnu];
double G2[nnu];
TLine *l[nnu];
for(int i=0;i<nnu;i++){
gr[i]=plotGF(i,xtheta,r0+i,G2+i,marker[i],color[i]);
gr[i]->Draw("Psame");
}
gcl->Draw("same");
TLegend *tg = new TLegend(0.75,0.70-0.10*nnu,0.90,0.70);
tg->SetFillColor(0);
tg->SetBorderSize(0);
tg->SetTextSize(0.04);
for(int i=0;i<nnu;i++)
if(i==0)
tg->AddEntry(gr[i],Form("Prod"),"lp");
else
tg->AddEntry(gr[i],Form("Sum"),"lp");
tg->AddEntry(gcl,Form("Theory"),"lp");
tg->Draw("same");
TLatex *t= new TLatex();
t->SetNDC();
t->SetTextSize(0.05);
t->SetTextFont(42);
if(xtheta==0)
    t->DrawLatex(0.6,0.2,Form("mult = %d, theta = %d", (trkbin[xbin+1]+trkbin[xbin])/2,xtheta));
    else
    t->DrawLatex(0.6,0.2,Form("mult = %d, theta = #frac{%d}{%d}#pi", (trkbin[xbin+1]+trkbin[xbin])/2,xtheta,ntheta*nn));

for(int i=0;i<nnu;i++){
l[i] = new TLine(r0[i],0,r0[i],G2[i]);
l[i]->SetLineStyle(2);
l[i]->SetLineColor(color[i]);
l[i]->Draw("same");
}
linv->SetLineStyle(2);
linv->SetLineColor(2);
linv->SetY1(hFrame->GetMinimum());
linv->Draw("same");
c1->Print("gvsr_thetas_MC.png");


}
Esempio n. 3
0
TH1D* GetJetCorrFunc1D_ZYA1(int itrg, int jass)
{
                    TH1D* hcorrphi = (TH1D*)GetRawCorrFunc1D_ratio(itrg,jass);
                    TH1D* hcorrphi_clone = (TH1D*)hcorrphi->Clone(Form("corrphi_clone_itrg%d_jass%d",itrg,jass));
                    hcorrphi->SetAxisRange(0.5,2.0,"X");
                    double histminY = hcorrphi->GetMinimum();
		    TF1* fitfunc = new TF1("fitfunc","[0]+[1]*x",0.8,1.2);		    
                    fitfunc->SetParameters(histminY,0);
                    fitfunc->FixParameter(1,0);
		    for(int ifit=0;ifit<3;ifit++) hcorrphi->Fit("fitfunc","RNO");                     
		    float level = fitfunc->GetParameter(0);
		    for(int ibin=1;ibin<=hcorrphi_clone->GetNbinsX();ibin++) hcorrphi_clone->SetBinContent(ibin,hcorrphi_clone->GetBinContent(ibin)-level);
                    float max = hcorrphi_clone->GetBinContent(hcorrphi_clone->GetMaximumBin());
                    hcorrphi_clone->SetAxisRange(ymin,max*1.3,"Y");
		    hcorrphi_clone->SetAxisRange(-PI/2.,3.*PI/2.,"X");
                    delete fitfunc;
                    return hcorrphi_clone;
}
Esempio n. 4
0
TH1D* GetJetCorrFunc1D_doublegaussian(int itrg, int jass)
{
                    TH1D* hcorrphi = (TH1D*)GetRawCorrFunc1D_ratio(itrg,jass);
		    TF1* fitfunc = new TF1("fitfunc",doubleGaussian,-PI/2.,3.*PI/2.,5);		    
                    fitfunc->SetParameters(hcorrphi->GetMinimum(),hcorrphi->GetMaximum()-hcorrphi->GetMinimum(),0.3,hcorrphi->GetMaximum(hcorrphi->GetMaximum())-hcorrphi->GetMinimum(),0.5);  
                    fitfunc->SetParLimits(0,0,100000);
                    fitfunc->SetParLimits(1,0,100000);
                    fitfunc->SetParLimits(2,0,100000);
                    fitfunc->SetParLimits(3,0,100000);
                    fitfunc->SetParLimits(4,0,100000);		    
		    for(int ifit=0;ifit<3;ifit++) hcorrphi->Fit("fitfunc","RNO");                     
		    TH1D* hcorrphi_clone = (TH1D*)hcorrphi->Clone(Form("corrphi_clone_itrg%d_jass%d",itrg,jass));
		    float level = fitfunc->GetParameter(0);
		    for(int ibin=1;ibin<=hcorrphi_clone->GetNbinsX();ibin++) hcorrphi_clone->SetBinContent(ibin,hcorrphi_clone->GetBinContent(ibin)-level);
                    float max = hcorrphi_clone->GetBinContent(hcorrphi_clone->GetMaximumBin());
                    hcorrphi_clone->SetAxisRange(ymin,max*1.3,"Y");
                    delete fitfunc;
                    return hcorrphi_clone;
}
Esempio n. 5
0
TH2D* GetJetCorrFunc2D_ZYA1(int itrg, int jass)
{
                    TH2D* hcorr = (TH2D*)GetRawCorrFunc2D_ratio(itrg,jass);
                    TH2D* hcorr_clone = (TH2D*)hcorr->Clone(Form("corr_clone_itrg%d_jass%d",itrg,jass));
                    hcorr_clone->Reset();
		    for(int ietabin=1;ietabin<=hcorr->GetNbinsX();ietabin++)
		    {
                      TH1D* hcorrphi = (TH1D*)hcorr->ProjectionY(Form("corrphi_%d",ietabin),ietabin,ietabin,"e");  
                      hcorrphi->SetAxisRange(0.5,2.0,"X");
                      double histminY = hcorrphi->GetMinimum();
		      fitfunc = new TF1("fitfunc","[0]+[1]*x",0.8,1.2);		    
                      fitfunc->SetParameters(histminY,0);
                      fitfunc->FixParameter(1,0);
		      for(int ifit=0;ifit<3;ifit++) hcorrphi->Fit(Form("fitfunc_%d",ietabin),"RNO");                     
		      float level = fitfunc->GetParameter(0);
		      for(int iphibin=1;iphibin<=hcorrphi->GetNbinsY();iphibin++)
                        hcorr_clone->SetBinContent(ietabin,iphibin,hcorr->GetBinContent(ietabin,iphibin)-level);
                      delete fitfunc;
		    }

                    float max = hcorr_clone->GetBinContent(hcorr_clone->GetMaximumBin());
                    hcorr_clone->SetAxisRange(ymin,max*1.3,"Z");
                    return hcorr_clone;
}
Esempio n. 6
0
// Called once for each event in the main event loop
// Return non-zero to indicate a problem and terminate the event loop
int TemplateCreator::ProcessEntry(TGlobalData* gData, const TSetupData* setup){

  // Prepare a few variables
  std::string bankname, detname;
  PulseIslandList thePulseIslands;
  StringPulseIslandMap::const_iterator it;

  // Loop over each detector
  for(it = gData->fPulseIslandToChannelMap.begin(); it != gData->fPulseIslandToChannelMap.end(); ++it){

    // Get the bank and detector names for this detector
    bankname = it->first;
    detname = setup->GetDetectorName(bankname);

    // See if we already have a converged template for this detector
    if (fConvergedStatuses[detname] == true) {
      continue;
    }

    // Create the pulse candidate finder for this detector
    PulseCandidateFinder* pulse_candidate_finder = new PulseCandidateFinder(detname, fOpts);

    // Create the TemplateFitter that we will use for this channel
    fTemplateFitter = new TemplateFitter(detname, fRefineFactor);

    // Get the TPIs
    thePulseIslands = it->second;
    if (thePulseIslands.size() == 0) continue; // no pulses here..

    // Try and get the template (it may have been created in a previous event)
    std::string template_name = "hTemplate_" + detname;
    TH1D* hTemplate = NULL;
    if (fTemplates.find(detname) != fTemplates.end()) {
      hTemplate = fTemplates[detname];
    }

    // Store a couple of numbers to get an idea of how many successful fits there are
    int& n_fit_attempts = fNFitAttempts[detname]; // number of pulses we try to fit to
    int& n_successful_fits = fNSuccessfulFits[detname];
    int& n_pulses_in_template = fNPulsesInTemplate[detname];

    // Loop through all the pulses
    for (PulseIslandList::iterator pulseIter = thePulseIslands.begin(); pulseIter != thePulseIslands.end(); ++pulseIter) {

      // First we will see how many candidate pulses there are on the TPI
      pulse_candidate_finder->FindPulseCandidates(*pulseIter);
      int n_pulse_candidates = pulse_candidate_finder->GetNPulseCandidates();

      // only continue if there is one pulse candidate on the TPI
      if (n_pulse_candidates == 1) {

	TPulseIsland* pulse = *pulseIter;

        // Add the first pulse directly to the template (although we may try and choose a random pulse to start with)
	if (hTemplate == NULL) {
	  std::string histname = "hTemplate_" + detname;
	  std::string histtitle = "Template Histogram for the " + detname + " channel";

	  int pulse_length = pulse->GetSamples().size();
	  if (pulse->GetPeakSample() >= pulse_length - pulse_length/5.0) {
	    if (Debug()) {
	      std::cout << "TemplateCreator: Pulse #" << pulseIter - thePulseIslands.begin() << " is too close to one end of the island and so won't be used as the first pulse in the template." << std::endl;
	    }
	    continue;
	  }
	  hTemplate = CreateRefinedPulseHistogram(pulse, histname.c_str(), histtitle.c_str(), true);
	  ++n_pulses_in_template;

	  if (Debug()) {
	    std::cout << "TemplateCreator: Adding " << detname << " Pulse #" << pulseIter - thePulseIslands.begin() << " directly to the template" << std::endl;
	  }
	  fTemplates[detname] = hTemplate;
	  continue;
	}

	// Get the samples so we can check for digitiser overflow
	const std::vector<int>& theSamples = (pulse)->GetSamples();
	int n_samples = theSamples.size();

	// Calculate the maximum ADC value for this digitiser
	int n_bits = TSetupData::Instance()->GetNBits(bankname);
	double max_adc_value = std::pow(2, n_bits);

	// Loop through the samples and check for digitizer overflow
	bool overflowed = false;
	for (int i = 0; i < n_samples; ++i) {
	  int sample_value = theSamples.at(i);
	  if (sample_value >= max_adc_value-1 && sample_value <= max_adc_value+1) {
	    if (Debug()) {
	      std::cout << "TemplateCreator: Pulse #" << pulseIter - thePulseIslands.begin() << " has overflowed the digitizer and won't be added to the template" << std::endl;
	    }
	    overflowed = true;
	    break;
	  }
	  else if (sample_value == 0) {
	    if (Debug()) {
	      std::cout << "TemplateCreator: Pulse #" << pulseIter - thePulseIslands.begin() << " has underflowed the digitizer and won't be added to the template" << std::endl;
	    }
	    overflowed = true;
	    break;
	  }
	}
	if (overflowed) {
	  continue; // skip this pulse
	}

	// Create the refined pulse waveform
	TH1D* hPulseToFit = CreateRefinedPulseHistogram(pulse, "hPulseToFit", "hPulseToFit", false);

	// Create some histograms that monitor the progression of the template
	if (fErrorVsPulseAddedHistograms.find(detname) == fErrorVsPulseAddedHistograms.end()) {
	  std::string error_histname = "hErrorVsPulseAdded_" + detname;
	  std::string error_histtitle = "Plot of the Error as each new Pulse is added to the template for the " + detname + " channel";
	  int n_bins = 10000;
	  TH1D* error_hist = new TH1D(error_histname.c_str(), error_histtitle.c_str(), n_bins,0,n_bins);
	  fErrorVsPulseAddedHistograms[detname] = error_hist;
	}

	// all the other pulses will be fitted to the template and then added to it
	// Get some initial estimates for the fitter
	double template_pedestal = hTemplate->GetBinContent(1);
	double template_amplitude;
	double template_time;

	double pulse_pedestal = hPulseToFit->GetBinContent(1);
	double pulse_amplitude;
	double pulse_time;

	double pedestal_offset_estimate = pulse_pedestal; // now we're dealing with actual pulses since we subtract the template_pedestal in the transformation
	double amplitude_scale_factor_estimate;
	double time_offset_estimate;
	if (TSetupData::Instance()->GetTriggerPolarity(bankname) == 1) { 
	  template_amplitude = (hTemplate->GetMaximum() - template_pedestal);
	  template_time = hTemplate->GetMaximumBin() - 1; // go from bin numbering (1, n_samples) to clock ticks (0, n_samples-1)

	  pulse_amplitude = (hPulseToFit->GetMaximum() - pulse_pedestal);
	  pulse_time = hPulseToFit->GetMaximumBin() - 1;

	  amplitude_scale_factor_estimate = pulse_amplitude / template_amplitude;  // estimated scale factor
	  time_offset_estimate = pulse_time - template_time;
	}
	else if (TSetupData::Instance()->GetTriggerPolarity(bankname) == -1) {
	  template_amplitude = (template_pedestal - hTemplate->GetMinimum());
	  template_time = hTemplate->GetMinimumBin() - 1; // go from bin numbering (1, n_samples) to clock ticks (0, n_samples-1)

	  pulse_amplitude = (pulse_pedestal - hPulseToFit->GetMinimum());
	  pulse_time = hPulseToFit->GetMinimumBin() - 1; // go from bin numbering (1, n_samples) to clock ticks (0, n_samples-1)

	  amplitude_scale_factor_estimate = pulse_amplitude / template_amplitude;  // estimated scale factor
	  time_offset_estimate = pulse_time - template_time;
	}

	fTemplateFitter->SetInitialParameterEstimates(pedestal_offset_estimate, amplitude_scale_factor_estimate, time_offset_estimate);
	
	if (Debug()) {
	  std::cout << "TemplateCreator: " << detname << "(" << bankname << "): Pulse #" << pulseIter - thePulseIslands.begin() << ": " << std::endl
		    << "TemplateCreator: Template: pedestal = " << template_pedestal << ", amplitude = " << template_amplitude << ", time = " << template_time << std::endl
		    << "TemplateCreator: Pulse: pedestal = " << pulse_pedestal << ", amplitude = " << pulse_amplitude << ", time = " << pulse_time << std::endl
		    << "TemplateCreator: Initial Estimates: pedestal = " << pedestal_offset_estimate << ", amplitude = " << amplitude_scale_factor_estimate 
		    << ", time = " << time_offset_estimate << std::endl;
	}

	int fit_status = fTemplateFitter->FitPulseToTemplate(hTemplate, hPulseToFit, bankname);
	++n_fit_attempts;
	if (fit_status != 0) {
	  if (Debug()) {
	    std::cout << "TemplateCreator: Problem with fit (status = " << fit_status << ")" << std::endl;
	  }
	  delete hPulseToFit; // delete this here since it is no longer needed
	  continue;
	}
	++n_successful_fits;

	if (Debug()) {
	  std::cout << "Template Creator: Fitted Parameters: PedOffset = " << fTemplateFitter->GetPedestalOffset() << ", AmpScaleFactor = " << fTemplateFitter->GetAmplitudeScaleFactor()
	            << ", TimeOffset = " << fTemplateFitter->GetTimeOffset() << ", Chi2 = " << fTemplateFitter->GetChi2() << ", NDoF = " << fTemplateFitter->GetNDoF() 
		    << ", Prob = " << TMath::Prob(fTemplateFitter->GetChi2(), fTemplateFitter->GetNDoF()) << std::endl << std::endl;
	}

	if (fPulseDebug) {
	  // Print out some templates as we go along
	  if (n_pulses_in_template <= 10 || 
	      (n_pulses_in_template <= 100 && n_pulses_in_template%10 == 0) ||
	      (n_pulses_in_template%100 == 0) ) {
	    std::stringstream newhistname;
	    newhistname << "hTemplate_" << n_pulses_in_template << "Pulses_" << detname;
	    TH1D* new_template = (TH1D*) hTemplate->Clone(newhistname.str().c_str());
	  }
	}

	// Add the pulse to the template (we'll do correct the sample values there)
	AddPulseToTemplate(hTemplate, hPulseToFit, bankname);
	++n_pulses_in_template;
	

	if (fPulseDebug) {
	  // Print out the uncorrected and corrected pulse that has been added to the template

	  // Create the histograms that we will use to plot the corrected and uncorrected pulses
	  std::stringstream histname;
	  histname << template_name << "_Event" << EventNavigator::Instance().EntryNo() << "_Pulse" << pulseIter - thePulseIslands.begin() << "_" << n_pulses_in_template << "Added";
	  TH1D* hUncorrectedPulse = (TH1D*) hPulseToFit->Clone(histname.str().c_str());
	  histname << "_Corrected";
	  TH1D* hCorrectedPulse = (TH1D*) hPulseToFit->Clone(histname.str().c_str());
	  hCorrectedPulse->SetEntries(0); // set entries back to 0
	  
	  double pedestal_error = SetupNavigator::Instance()->GetNoise(bankname);

	  // Loop through the bins of the uncorrected pulse and set the values in the corrected pulse histogram
	  for (int iPulseBin = 1; iPulseBin <= hPulseToFit->GetNbinsX(); ++iPulseBin) {
	    
	    double uncorrected_value = hPulseToFit->GetBinContent(iPulseBin);
	    double corrected_value = CorrectSampleValue(uncorrected_value, template_pedestal);
	    
	    hCorrectedPulse->SetBinContent(iPulseBin +0.5 - fTemplateFitter->GetTimeOffset(), corrected_value); 
	    hCorrectedPulse->SetBinError(iPulseBin +0.5 - fTemplateFitter->GetTimeOffset(), pedestal_error);
	  }
	}

	delete hPulseToFit;

	// we keep on adding pulses until adding pulses has no effect on the template
	bool converged = CheckConvergence(hTemplate, bankname);
	if (converged) {
	  fConvergedStatuses[detname] = true;
	  std::cout << "TemplateCreator: " << detname << " template terminated at iteration " << n_pulses_in_template << std::endl;
	  break; // break from the for loop
	}
      } // end if only one pulse candidate
    } //end for loop through channels
  }

  return 0;
}
Esempio n. 7
0
// -----------------------------------------------------------------------------
//
TCanvas* createPlot( TString path, 
		     TString canvas_name, 
		     TString name, 
		     TString dirmame, 
		     int rebin, 
		     bool norm, 
		     bool log,
		     TDirectory* file )
{

  // SetSomeStyles();

  float lumi = 250.0;// 15.04;//10.9;//6.8;
 
  // Create legend
  TLegend* legend = new TLegend(0.75, 0.6, 0.99, 0.99, "", "brNDC" );
  legend->SetFillColor(0);
  legend->SetLineColor(0); 
  legend->SetShadowColor(0);
  TLatex* prelim = new TLatex(0.6,0.54,"#scale[0.8]{CMS preliminary 2010}");
  prelim->SetNDC();
  TLatex* alumi = new TLatex(0.6,.45,"#scale[0.8]{#int L dt = 35 pb^{-1}, #sqrt{s} = 7 TeV}");
  alumi->SetNDC();

  // Create canvas 
  TCanvas* aCanvas = createCanvas( canvas_name, file, log );

  // Create histogram
  TString aname("nAll");
  // TH1D* data1    = getHisto( path+"S14datacleaned/Edward_Data_Skim/",name,"data.root",aname,rebin);
  // TH1D* data    = getHisto( path+"S14datacleaned/Edward_Data_Skim/",name,"data.root",dirmame,rebin);
 
  TH1D* data    = getHisto( path+"", name, "tt.root", dirmame, rebin );
  TH1D* qcd     = getHisto( path+"", name, "lm1.root", dirmame, rebin );
  TH1D* w_jets  = getHisto( path+"", name, "w.root", dirmame, rebin );
  TH1D* tt_jets = getHisto( path+"", name, "tt.root", dirmame, rebin );
  TH1D* z_jets  = getHisto( path+"", name, "z.root", dirmame, rebin );
  TH1D* lm3     = getHisto( path+"", name, "lm3.root", dirmame, rebin );
  TH1D* lm1     = getHisto( path+"", name, "lm1.root", dirmame, rebin );
  TH1D* lm6     = getHisto( path+"", name, "data.root", dirmame, rebin );
  TH1D* wm     = getHisto( path+"", name, "w.root", dirmame, rebin );
  data->Scale(lumi/100.);
  qcd->Scale(lumi/100.);
  tt_jets->Scale(lumi/100);
  w_jets->Scale(lumi/100);
  //  w_jets->Scale(10);
  //  z_inv->Scale(lumi/100);
  //  lm6->Scale(lumi/100);
  lm1->Scale(lumi/100);
  lm3->Scale(lumi/100);
  z_jets->Scale(lumi/100);
  wm->Scale(lumi/100);
  // Combine Z+jets and Z->inv
  // TH1D* z_all = z_inv->Clone(); 
  //  z_all->Add(z_jets,1);
  //z_jets->Add(z_inv,1);
  TH1D* total = tt_jets->Clone();
  total->Add(w_jets);
  total->Add(z_jets);

  // total->
 
  Int_t binMax =   total->GetNbinsX();
  Double_t& err = new Double_t(0.);
  total->IntegralAndError(10,binMax ,err);
  Double_t& errW = new Double_t(0.);
  w_jets->IntegralAndError(10,binMax ,errW);
  Double_t& errtt = new Double_t(0.);
  tt_jets->IntegralAndError(10,binMax ,errtt);
  Double_t& errZ = new Double_t(0.);
  z_jets->IntegralAndError(10,binMax ,errZ);
  Double_t& errQCD = new Double_t(0.);
  qcd->IntegralAndError(10,binMax ,errQCD );


  cout  <<endl;
  //  cout << "MC:" <<  total->IntegralAndError(11,binMax ,err) <<" && " <<  w_jets->Integral(11,binMax)<<" && "<<tt_jets->Integral(11,binMax) << "&&  "<<z_jets->Integral(11,binMax)<<" && "<< "\/\ /\hline"<<endl;
  //  cout << total->IntegralAndError(0,binMax ,err) <<" & " << lm1->Integral(0,binMax) <<" & " << lm3->Integral(0,binMax)<<" & " << lm6->Integral(0,binMax)   <<"\\\\ \\hline"<<endl;
  //  cout <<"270: " <<  total->IntegralAndError(27,binMax ,err) <<" & " << lm1->Integral(27,binMax) <<" & " << lm3->Integral(27,binMax)<<" & " << lm6->Integral(27,binMax)   <<"\\\\ \\hline"<<endl;


  cout <<"250& " <<  total->IntegralAndError(6,binMax ,err) <<" & " << lm1->Integral(6,binMax) <<" & " << lm3->Integral(6,binMax)<<" & " << lm6->Integral(6,binMax)   <<"\\\\ \\hline"<<endl;
 
  // cout << "300: " <<  total->IntegralAndError(7,binMax ,err) <<" & " << lm1->Integral(7,binMax) <<" & " << lm3->Integral(7,binMax)<<" &" << lm6->Integral(7,binMax)   <<"\\\\ \\hline"<<endl;

  cout <<"350& " <<  total->IntegralAndError(8,binMax ,err) <<" & " << lm1->Integral(8,binMax) <<" & " << lm3->Integral(8,binMax)<<" & " << lm6->Integral(8,binMax)    <<"\\\\ \\hline"<<endl;

  //   cout << "400: " <<  total->IntegralAndError(9,binMax ,err) <<" & " << lm1->Integral(9,binMax) <<" & " << lm3->Integral(9,binMax)<<" & " << lm6->Integral(9,binMax)    <<"\\\\ \\hline"<<endl;

cout << "450& " <<  total->IntegralAndError(10,binMax ,err) <<" & " << lm1->Integral(10,binMax) <<" & " << lm3->Integral(10,binMax)<<" & " << lm6->Integral(10,binMax)    <<"\\\\ \\hline"<<endl;

//cout << "500: " <<   total->IntegralAndError(11,binMax ,err) <<" & " << lm1->Integral(11,binMax) <<" & " << lm3->Integral(11,binMax)<<" & " << lm6->Integral(11,binMax)    <<"\\\\ \\hline"<<endl;

  cout <<"550& " <<  total->IntegralAndError(12,binMax ,err) <<" & " << lm1->Integral(12,binMax) <<" & " << lm3->Integral(12,binMax)<<" & " << lm6->Integral(12,binMax)    <<"\\\\ \\hline"<<endl;
  /*
 cout << "MC:" <<  total->IntegralAndError(7,binMax ,err) <<" && " << lm1->Integral(7,binMax) <<" && " << lm3->Integral(7,binMax)<<" && " << lm6->Integral(6,binMax)   <<"/\/\ /\hline"<<endl;
  cout << "MC:" <<  total->IntegralAndError(8,binMax ,err) <<" && " << lm1->Integral(8,binMax) <<" && " << lm3->Integral(8,binMax)<<" && " << lm6->Integral(7,binMax)   <<"/\/\ /\hline"<<endl;
  cout << "MC:" <<  total->IntegralAndError(10,binMax ,err) <<" && " << lm1->Integral(10,binMax) <<" && " << lm3->Integral(10,binMax)<<" && " << lm6->Integral(10,binMax)   <<"/\/\ /\hline"<<endl;
 cout << "MC:" <<  total->IntegralAndError(11,binMax ,err) <<" && " << lm1->Integral(11,binMax) <<" && " << lm3->Integral(11,binMax)<<" && " << lm6->Integral(11,binMax)   <<"/\/\ /\hline"<<endl;
 cout << "MC:" <<  total->IntegralAndError(12,binMax ,err) <<" && " << lm1->Integral(12,binMax) <<" && " << lm3->Integral(12,binMax)<<" && " << lm6->Integral(12,binMax)   <<"/\/\ /\hline"<<endl;
  // cout << "MC:" << err  <<", W: " << errW<<", tt: "<<errtt << ", Z: "<<errZ<<", QCD: "<<  errQCD<< endl;
  */

  //  cout << "data:" << data->Integral() << endl;


  TH1D* hcen = total->Clone();
  TH1D* herr = total->Clone();
  
  herr->SetLineColor(kTeal+3);
  herr->SetMarkerColor(kAzure+6);
  herr->SetFillColor(kAzure+6);
  herr->SetLineWidth(3);
  
  total->SetLineWidth(3);
  total->SetFillColor(kAzure+2);
  total->SetLineColor(kAzure+2);
  total->SetFillStyle(3245);
 
  hcen->SetFillStyle(0);
  hcen->SetMarkerColor(kTeal+3);
  hcen->SetLineColor(kTeal+3);
  hcen->SetLineWidth(3);

  // Merge Z+jets and Z->inv
  bool combine = false;
  
  // Line colour and fill
  qcd->SetLineColor(kPink+4);
  qcd->SetLineWidth(3);
  tt_jets->SetLineColor(kBlue+1);
  tt_jets->SetLineWidth(3);
  
  w_jets->SetLineColor(kPink+7);
  w_jets->SetLineWidth(3);

  z_jets->SetLineWidth(3);
  z_jets->SetLineColor(kTeal-7);
  
  if ( combine ) {
    z_all->SetLineColor(kBlack);
    z_all->SetLineStyle(3);
    z_all->SetLineWidth(1);
  } else {
    data->SetLineColor(1);
    data->SetLineStyle(1);
    data->SetLineWidth(3);
    data->SetMarkerStyle(20);
    data->SetFillColor(0);
  }
  //  lm0->SetLineColor(kRed);
  //  lm0->SetLineWidth(3);
  // lm1->SetLineColor(kRed+3);
  // lm1->SetLineWidth(3);

  // Populate legend
  // legend->AddEntry( data, "tt fully leptonic/", "LP" );
   legend->AddEntry( herr, "full SM", "LP" );
    legend->AddEntry( z_jets, " Z+jets ", "LP" );
    legend->AddEntry( w_jets, " W+jets", "LP" );
    legend->AddEntry( tt_jets, " t#bar{t}", "LP" );
    //  legend->AddEntry( lm3, " SUSY LM3", "LP" );
    //   legend->AddEntry( lm1, " SUSY LM1", "LP" );
    legend->AddEntry( lm6, " data", "LP" );
    // legend->AddEntry(wm,"W Mad","lp");
    
  // Calc maximum number of entries
  double aMax = 0.;
  if( data->GetMaximum()     > aMax ) { aMax = data->GetMaximum()+data->GetBinError(data->GetMaximumBin()); }
  if ( qcd->GetMaximum()     > aMax ) { aMax = qcd->GetMaximum(); }
  //  if ( lm0->GetMaximum()     > aMax ) { aMax = lm0->GetMaximum(); }
  //  if ( lm1->GetMaximum()     > aMax ) { aMax = lm1->GetMaximum(); }
  if ( tt_jets->GetMaximum() > aMax ) { aMax = tt_jets->GetMaximum(); }  
  if ( w_jets->GetMaximum()  > aMax ) { aMax = w_jets->GetMaximum(); }  
  if ( combine ) {
    if ( z_all->GetMaximum()  > aMax ) { aMax = z_all->GetMaximum(); }  
  } else {
    //   if ( data->GetMaximum()   > aMax ) { aMax = z_inv->GetMaximum(); }  
    if ( z_jets->GetMaximum()  > aMax ) { aMax = z_jets->GetMaximum(); }  
  }

  // Calc minimum number of entries
  double aMin = 1.e12;
  if ( qcd->GetMinimum(1.e-12)     < aMin ) { aMin = qcd->GetMinimum(1.e-12); }
  //  if ( lm0->GetMinimum(1.e-12)     < aMin ) { aMin = lm0->GetMinimum(1.e-12); }
  //  if ( lm1->GetMinimum(1.e-12)     < aMin ) { aMin = lm1->GetMinimum(1.e-12); }
  if ( tt_jets->GetMinimum(1.e-12) < aMin ) { aMin = tt_jets->GetMinimum(1.e-12); }  
  if ( w_jets->GetMinimum(1.e-12)  < aMin ) { aMin = w_jets->GetMinimum(1.e-12); }  
  if ( combine ) {
    if ( z_all->GetMinimum(1.e-12)   < aMin ) { aMin = z_all->GetMinimum(1.e-12); }  
  } else {
    // if ( data->GetMinimum(1.e-12)   < aMin ) { aMin = z_inv->GetMinimum(1.e-12); }  
    if ( z_jets->GetMinimum(1.e-12)  < aMin ) { aMin = z_jets->GetMinimum(1.e-12); }  
  }

  if ( qcd ) qcd->GetYaxis()->SetTitleOffset(1.43);
  if ( qcd ) qcd->GetYaxis()->SetTitleSize(0.06);
  if ( qcd ) qcd->GetXaxis()->SetTitleSize(0.06);
  if ( qcd ) qcd->GetXaxis()->SetTitleOffset(0.9);

 
  if ( log ) {
    if ( qcd ) herr->SetMaximum( aMax * 10. );
    //   if ( qcd ) herr->SetMinimum( aMin * 0.1 );
    if ( qcd ) herr->SetMinimum( 0.005);
  } else {
    if ( qcd ) herr->SetMaximum( aMax * 1.1 );
    //   if ( qcd ) herr->SetMinimum( aMin * 0.9 );
  if ( qcd ) herr->SetMinimum( 0.005);

  }

  /*  TPad* mainPad = new TPad("","",0.01,0.25,0.99,0.99);
  mainPad->SetNumber(1);
  mainPad->SetFillColor(0);
  // mainPad->Range(-288.2483,-2.138147,1344.235,6.918939);
  mainPad->SetFillColor(0);
  mainPad->SetBorderMode(0);
  mainPad->SetBorderSize(2);
  if ( log == true)mainPad->SetLogy();
   mainPad->SetLeftMargin(0.1765705);
  mainPad->SetRightMargin(0.05772496);
  mainPad->SetTopMargin(0.04778761);
  mainPad->SetBottomMargin(0.1256637);
  mainPad->SetFrameFillStyle(0);
  mainPad->SetFrameLineWidth(2);
  mainPad->SetFrameBorderMode(0);
  mainPad->SetFrameFillStyle(0);
  mainPad->SetFrameLineWidth(2);
  mainPad->SetFrameBorderMode(0);
  if ( log == true)mainPad->SetLogy();
  mainPad->Draw();
  TPad*  ratioPad = new TPad("","",0.01,0.01,0.99,0.25);
  ratioPad->SetNumber(2);
  ratioPad->SetFillColor(0);
  ratioPad->SetFillColor(0);
  ratioPad->SetBorderMode(0);
  ratioPad->SetBorderSize(2);
  // if ( log == true)ratioPad->SetLogy();
   ratioPad->SetLeftMargin(0.1765705);
  ratioPad->SetRightMargin(0.05772496);
  ratioPad->SetTopMargin(0.04778761);
  ratioPad->SetBottomMargin(0.1256637);
  ratioPad->SetFrameFillStyle(0);
  ratioPad->SetFrameLineWidth(2);
  ratioPad->SetFrameBorderMode(0);
  ratioPad->SetFrameFillStyle(0);
  ratioPad->SetFrameLineWidth(2);
  ratioPad->SetFrameBorderMode(0);
  //  if ( log == true)ratioPad->SetLogy();
  ratioPad->Draw();
 

  aCanvas->cd(1);
  */

  herr->GetYaxis()->SetTitle("events");


  if ( norm ) {
    if ( qcd ) qcd->DrawNormalized("Ehist");
    // if ( lm0->GetEntries() > 0. )     { lm0->DrawNormalized("hsame"); }
    if ( lm1->GetEntries() > 0. )     { lm1->DrawNormalized("hsame"); }
    if ( tt_jets->GetEntries() > 0. ) { tt_jets->DrawNormalized("hsame"); }
    if ( w_jets->GetEntries() > 0. )  { w_jets->DrawNormalized("hsame"); }
    if ( combine ) {
      if ( z_all->GetEntries() > 0. )   { z_all->DrawNormalized("hsame"); }
    } else {
      if ( data->GetEntries() > 0. )   { z_inv->DrawNormalized("hsame"); }
      if ( z_jets->GetEntries() > 0. )  { z_jets->DrawNormalized("hsame"); }
    }
  } else {
     herr->Draw("hist");
   
   
     // qcd->SetFillStyle(3240);
     // qcd->SetFillColor(kPink+4);
    // qcd->Draw("hist");
    w_jets->Draw("hSameh");
    z_jets->Draw("9Sameh");
    w_jets->Draw("9Sameh");
    tt_jets->Draw("9SAMEh");
    //data1->Draw("9SAMEh");
     //lm0->Draw("9SAMEh");
     lm1->SetLineColor(12);
     lm1->SetLineStyle(2);
     lm1->SetLineWidth(2);
     //     lm1->Draw("9SAMEh");
     lm3->SetLineColor(14);
     lm3->SetLineStyle(2);
     lm3->SetLineWidth(2);
     //  lm3->Draw("9SAMEh");
     lm6->Draw("9SAMEh");
     wm->SetLineStyle(2);
     wm->SetLineColor(kPink+7);
     // wm->Draw("9Sameh");

     // total->DrawNormalized("9E2same");
     //      data->Draw("SAMEh");
    //  tt_jets->Divide(data);
    //  tt_jets->Draw("h");
  //  data->SetLineColor(kRed);
  //  data->Draw("sameh");
     //     data1->SetLineColor(kRed);
     //  data1->Draw("9SAMEP");
  }
  
    legend->Draw();
  // prelim->Draw();
  // alumi->Draw();



  /*  TH1D* ratioBottom = total->Clone();
  TH1D* ratioTop = data->Clone();
  ratioTop->GetYaxis()->SetTitle("data / sim");
  ratioTop->Divide(ratioBottom);
  
  aCanvas->cd(1)->Update();
 
  aCanvas->cd(2);

  ratioTop->SetTitleSize(0.1, "XYZ");
  ratioTop->SetTitleOffset(0.55, "X");
  ratioTop->SetTitleOffset(0.3, "Y");
  ratioTop->SetLabelSize(0.06,"XY");
    
  // ratioTop->GetXaxis().SetRangeUser(MinX,MaxX);
  ratioTop->GetYaxis()->SetRangeUser(0.,2.0);
  ratioTop->Draw();*/
  /* TBox* unity = TBox(ratioTop->GetXaxis()->GetBinLowEdge(ratioTop->GetXaxis()->GetFirst()), 0.89,ratioTop->GetXaxis()->GetBinLowEdge(ratioTop->GetXaxis()->GetLast()), 1.11);
  unity->SetLineWidth(2);
   
  unity->SetLineColor(2);
  unity->SetFillColor(2);
  unity->SetFillStyle(3002);
  unity->Draw();

  */
  file->cd();
 
  aCanvas->SaveAs( std::string(canvas_name+".pdf").c_str() );
  aCanvas->Write();



  //   aCanvas->Print(".png");
 return aCanvas;

}
Esempio n. 8
0
TH1D* readData(TString dataset, TString name, TString wavel, Double_t peak1, Double_t peak2, Double_t intTime, Double_t shift){

    TString fileName = "./Data/" + dataset + ".txt";

    Double_t histoMin = 99999, histoMax = 0;

    ifstream ifs(fileName); if(!ifs.is_open()){cout << "Error. File " << fileName << " not found. Exiting...\n"; return NULL;}

    Double_t entry, wavelength, photons, stepsize;
    
    while(ifs >> entry >> wavelength >> photons){

        if(entry == 1) stepsize = wavelength;
        else if(entry == 2) stepsize = wavelength - stepsize;
        
        if(wavelength < histoMin) histoMin = wavelength;
        if(wavelength > histoMax) histoMax = wavelength;

    }

    ifs.close();

    TH1D *histo = new TH1D(name + wavel + TString::Format(" %1.2f", shift), name + wavel + TString::Format(" %1.2f", shift), Nint(entry), histoMin + shift - stepsize/2.0, histoMax + shift + stepsize/2.0);


    ifs.open(fileName); if(!ifs.is_open()){cout << "Error. File " << fileName << " not found. Exiting...\n"; return NULL;}
    
    while(ifs >> entry >> wavelength >> photons){
        
        for(Int_t x = 0; x< photons/(1000.0/intTime); x++){
            histo->Fill(wavelength + shift);
        }

    }

    ifs.close();

    TF1 *f;
    if(peak2 == 0.){
        f = new TF1("fit", "[0]+[1]*TMath::Voigt(x-[2],[3],[4])");
        f->SetParameter(0, histo->GetMinimum());
        f->SetParameter(1, histo->GetMaximum()/25.);
        f->SetParameter(2, peak1 + shift);
        f->SetParameter(3, .02);
        f->SetParameter(4, .02);
        f->SetParName(0, "Offset");
        f->SetParName(1, "Normalization");
        f->SetParName(2, "Mean");
        f->SetParName(3, "Sigma");
        f->SetParName(4, "Gamma");
    }
    else{
        f = new TF1("fit", "[0]+[1]*TMath::Voigt(x-[2],[3],[4])+[5]*TMath::Voigt(x-[6],[7],[8])");
        f->SetParameter(0, histo->GetMinimum());
        f->SetParameter(1, histo->GetMaximum()/20.);
        f->SetParameter(2, peak1+shift-0.1);
        f->SetParameter(3, .02);
        f->SetParameter(4, .02);
        f->SetParameter(5, histo->GetMaximum()/20.);
        f->SetParameter(6, peak2+shift+0.1);
        f->SetParameter(7, .02);
        f->SetParameter(8, .02);
        f->SetParName(0, "Offset");
        f->SetParName(1, "Normalization 1");
        f->SetParName(2, "Mean 1");
        f->SetParName(3, "Sigma 1");
        f->SetParName(4, "Gamma 1");
        f->SetParName(5, "Normalization 2");
        f->SetParName(6, "Mean 2");
        f->SetParName(7, "Sigma 2");
        f->SetParName(8, "Gamma 2");
    }

    histo->SetLineWidth(2);
    histo->SetMarkerStyle(20);
    histo->SetMarkerSize(1.5);
    histo->SetMarkerColor(kRed);
    histo->SetLineColor(kBlack);
    histo->GetXaxis()->SetTitle("Wavelength (#AA)");
    histo->GetXaxis()->CenterTitle();
    histo->GetXaxis()->SetTitleSize(0.045);
    histo->GetXaxis()->SetTitleOffset(1.00);
    histo->GetXaxis()->SetLabelOffset(0.010);
    histo->GetXaxis()->SetLabelSize(0.045);
    histo->GetYaxis()->SetTitle("Photon count");
    histo->GetYaxis()->CenterTitle();
    histo->GetYaxis()->SetTitleSize(0.050);
    histo->GetYaxis()->SetTitleOffset(0.95);
    histo->GetYaxis()->SetLabelSize(0.045);
    gStyle->SetTitleSize(0.070, "t");
    if(peak2 == 0.) histo->SetTitle(name + TString::Format(" %4.2f #AA", f->GetParameter(2)));
    else histo->SetTitle(name + TString::Format(" %4.2f / %4.2f #AA", f->GetParameter(2), f->GetParameter(6)));
    //histo->SetTitle("Sodium 5890.522 / 5890.567 #AA");
    cout << shift << endl;

    f->SetLineColor(kBlue);
    f->SetLineWidth(4);
    cout << "Fitting " << name << endl;
    histo->Fit(f, "ME");

    return histo;

}
Esempio n. 9
0
// -----------------------------------------------------------------------------
//
TCanvas* aDrawBkgdPlots( TString path, 
			 TString canvas_name, 
			 TString name, 
			 TString dirmame, 
			 int rebin, 
			 bool norm, 
			 bool log,
			 TDirectory* file )
{

  // SetSomeStyles();

  // Create legend
  TLegend* legend = new TLegend( 0.75, 0.65, 0.92, 0.92, NULL, "brNDC" );
  legend->SetFillColor(0);
  legend->SetLineColor(0); 
  
  // Create canvas
  TCanvas* aCanvas = getaCanvas( canvas_name, file, log );
  
  // Create histograms
  TH1D* qcd     = readHist( path, name, "IC5Calo_QCD_Pythia_Merged.root", dirmame, rebin );
  TH1D* tt_jets = readHist( path, name, "IC5Calo_TTbarJets.root", dirmame, rebin );
  TH1D* w_jets  = readHist( path, name, "IC5Calo_WJets.root", dirmame, rebin );
  TH1D* z_inv   = readHist( path, name, "IC5Calo_Zinv.root", dirmame, rebin );
  TH1D* z_jets  = readHist( path, name, "IC5Calo_ZJets.root", dirmame, rebin );
  TH1D* lm0     = readHist( path, name, "IC5Calo_LM0.root", dirmame, rebin );
  TH1D* lm1     = readHist( path, name, "IC5Calo_LM1.root", dirmame, rebin );

  // Combine Z+jets and Z->inv
  TH1D* z_all = z_inv->Clone(); 
  z_all->Add(z_jets,1);

//   TH1D* z_all = 0;
//   if ( z_inv && z_jets ) { 
//     z_all = z_inv->Clone(); 
//     z_all->Add(z_jets,1);
//   } else if ( z_inv ) { 
//     z_all = z_inv->Clone(); 
//   } else if ( z_jets ) { 
//     z_all = z_jets->Clone(); 
//   }
  
  // Select Z+jets and Z->inv separate or not
  bool combine = true;
  
  // Line colour and fill
  if ( qcd ) qcd->SetLineColor(kGreen+2);
  if ( qcd ) qcd->SetFillColor(kGreen+2);
  if ( qcd ) qcd->SetFillStyle(3003);
  if ( tt_jets ) tt_jets->SetLineColor(kBlue);
  if ( tt_jets ) tt_jets->SetLineStyle(1);
  if ( tt_jets ) tt_jets->SetLineWidth(1);
  w_jets->SetLineColor(kBlue);
  w_jets->SetLineStyle(3);
  w_jets->SetLineWidth(1);
  if ( combine ) {
    z_all->SetLineColor(kBlack);
    z_all->SetLineStyle(3);
    z_all->SetLineWidth(1);
  } else {
    z_inv->SetLineColor(kBlack);
    z_inv->SetLineStyle(1);
    z_inv->SetLineWidth(1);
    z_jets->SetLineColor(kBlack);
    z_jets->SetLineStyle(3);
    z_jets->SetLineWidth(1);
  }
  lm0->SetLineColor(kRed);
  lm0->SetLineStyle(1);
  lm0->SetLineWidth(2);
  lm1->SetLineColor(kRed);
  lm1->SetLineStyle(3);
  lm1->SetLineWidth(2);

  // Populate legend
  legend->AddEntry( qcd, " QCD", "f" );
  legend->AddEntry( lm0, " SUSY LM0", "L" );
  legend->AddEntry( lm1, " SUSY LM1", "L" );
  legend->AddEntry( tt_jets, " t#bar{t}+jets", "L" );
  legend->AddEntry( w_jets, " W+jets", "L" );
  if ( combine ) {
    legend->AddEntry( z_all, " Z", "L" );
  } else {
    legend->AddEntry( z_jets, " Z+jets", "L" );
    legend->AddEntry( z_inv, " Z#rightarrow#nu#nu", "L" );
  }

  // Calc maximum number of entries
  double aMax = 0.;
  if ( qcd->GetMaximum()     > aMax ) { aMax = qcd->GetMaximum(); }
  if ( lm0->GetMaximum()     > aMax ) { aMax = lm0->GetMaximum(); }
  if ( lm1->GetMaximum()     > aMax ) { aMax = lm1->GetMaximum(); }
  if ( tt_jets->GetMaximum() > aMax ) { aMax = tt_jets->GetMaximum(); }  
  if ( w_jets->GetMaximum()  > aMax ) { aMax = w_jets->GetMaximum(); }  
  if ( combine ) {
    if ( z_all->GetMaximum()  > aMax ) { aMax = z_all->GetMaximum(); }  
  } else {
    if ( z_inv->GetMaximum()   > aMax ) { aMax = z_inv->GetMaximum(); }  
    if ( z_jets->GetMaximum()  > aMax ) { aMax = z_jets->GetMaximum(); }  
  }

  // Calc minimum number of entries
  double aMin = 1.e12;
  if ( qcd->GetMinimum(1.e-12)     < aMin ) { aMin = qcd->GetMinimum(1.e-12); }
  if ( lm0->GetMinimum(1.e-12)     < aMin ) { aMin = lm0->GetMinimum(1.e-12); }
  if ( lm1->GetMinimum(1.e-12)     < aMin ) { aMin = lm1->GetMinimum(1.e-12); }
  if ( tt_jets->GetMinimum(1.e-12) < aMin ) { aMin = tt_jets->GetMinimum(1.e-12); }  
  if ( w_jets->GetMinimum(1.e-12)  < aMin ) { aMin = w_jets->GetMinimum(1.e-12); }  
  if ( combine ) {
    if ( z_all->GetMinimum(1.e-12)   < aMin ) { aMin = z_all->GetMinimum(1.e-12); }  
  } else {
    if ( z_inv->GetMinimum(1.e-12)   < aMin ) { aMin = z_inv->GetMinimum(1.e-12); }  
    if ( z_jets->GetMinimum(1.e-12)  < aMin ) { aMin = z_jets->GetMinimum(1.e-12); }  
  }

  if ( qcd ) qcd->GetYaxis()->SetTitleOffset(1.43);
  if ( qcd ) qcd->GetYaxis()->SetTitleSize(0.06);
  if ( qcd ) qcd->GetXaxis()->SetTitleSize(0.06);
  if ( qcd ) qcd->GetXaxis()->SetTitleOffset(0.9);

  if ( log ) {
    if ( qcd ) qcd->SetMaximum( aMax * 10. );
    if ( qcd ) qcd->SetMinimum( aMin * 0.1 );
  } else {
    if ( qcd ) qcd->SetMaximum( aMax * 1.1 );
    if ( qcd ) qcd->SetMinimum( aMin * 0.9 );
  }

  if ( norm ) {
    if ( qcd ) qcd->DrawNormalized("Ehist");
    if ( lm0->GetEntries() > 0. )     { lm0->DrawNormalized("hsame"); }
    if ( lm1->GetEntries() > 0. )     { lm1->DrawNormalized("hsame"); }
    if ( tt_jets->GetEntries() > 0. ) { tt_jets->DrawNormalized("hsame"); }
    if ( w_jets->GetEntries() > 0. )  { w_jets->DrawNormalized("hsame"); }
    if ( combine ) {
      if ( z_all->GetEntries() > 0. )   { z_all->DrawNormalized("hsame"); }
    } else {
      if ( z_inv->GetEntries() > 0. )   { z_inv->DrawNormalized("hsame"); }
      if ( z_jets->GetEntries() > 0. )  { z_jets->DrawNormalized("hsame"); }
    }
  } else {
    if ( qcd ) qcd->Draw("h");
    lm0->Draw("sameH");
    lm1->Draw("sameH");
    if ( tt_jets ) tt_jets->Draw("sameh");
    w_jets->Draw("sameH");
    if ( combine ) {
      z_all->Draw("sameH");
    } else {
      z_inv->Draw("sameH");
      z_jets->Draw("sameH");
    }
  }
  
  file->cd();
  legend->Draw("same");
  aCanvas->Write();
  return aCanvas;

}
Esempio n. 10
0
void plot_Comb(void) {

    gROOT->ProcessLine(".L ../tools/plottools.C");
    gStyle->SetPadGridX(kFALSE);
    gStyle->SetPadGridY(kFALSE);

    //SET UP FINE THEORY
    ifstream in_xsec_massNNLO4("../style/DY/root/Plain/NNLO/8TeV_CTEQ12NNLO_41.txt",ios::in);
    const int nbins4  = 339+179+25;
    double mass_xbin4[nbins4] = {0.};
    double initial = 14.0;
    for( int i = 0; i < nbins4; i++ ) {
        if( i >= 0 && i < 11 ) {
            initial += 1.0;
        }
        else if( i >= 11 && i < 18 ) {
            initial += 5.0;
        }
        else if( i >= 18 && i < 118 ) {
            initial += 1.0;
        }
        else if( i >= 118 && i < 338 ) {
            initial += 2.0;
        }
        else if (i >= 338 && i < 542-24) {
            initial += 5.0;
        } else {
            initial += 20.0;
        }
        mass_xbin4[i] = initial;
    }
    TH1D* h_theory4  = new TH1D("xsec4_NNLO","xsec4_NNLO",nbins4-1,mass_xbin4);
    TH1D* h_theory4_band  = new TH1D("xsec4_bandNNLO","xsec4_bandNNLO",nbins4-1,mass_xbin4);
    double xsec_mass4[nbins4-1];
    double xsec_err_mass4[nbins4-1];

    for( int i = 0; i < nbins4-1; i++ ) {
        double dm_ = mass_xbin4[i+1]-mass_xbin4[i];

        //NNLO
        in_xsec_massNNLO4 >> xsec_mass4[i] >>  xsec_err_mass4[i] ;
        //FIXME fix the kink at high mass, artificially
        xsec_mass4[i] *= weightProducer(mass_xbin4[i+1]);

        double peak = 1137.2;
        if (IS_RSHAPE) {
            h_theory4_band->SetBinContent(i+1,xsec_mass4[i]/dm_/peak);
            //controls error band
            h_theory4_band->SetBinError(i+1,0.1*h_theory4_band->GetBinContent(i+1));///peak);
            h_theory4->SetBinContent(i+1,xsec_mass4[i]/dm_/peak);
            h_theory4->SetBinError(i+1,0.0);//sqrt(pow(xsec_mass4[i]*10./peak_val_theory/peak_val_theory,2)));
        } else {
            h_theory4_band->SetBinContent(i+1,xsec_mass4[i]/dm_);
            h_theory4_band->SetBinError(i+1,0.1*h_theory4_band->GetBinContent(i+1));
            h_theory4->SetBinContent(i+1,xsec_mass4[i]/dm_);
            h_theory4->SetBinError(i+1,0.0);//sqrt(pow(xsec_mass4[i]*10./peak_val_theory/peak_val_theory,2)));
        }
    }
    average(h_theory4_band);
    average(h_theory4);

    //ACCESS VALUES
    TFile* f;
    if (IS_7TEV) f = new TFile("../Inputs/Theory/1Dabsxsec_NNLO_CTEQ12NNLO_7TeV.root");
    else f = new TFile("../Inputs/Theory/1Dabsxsec_NNLO_CTEQ12NNLO"+has41+".root");
    f->cd();
    TH1D* theory = (TH1D*)gDirectory->Get("invm_FEWZ"+has41);
    double peak_th = theory->Integral(10,22);
    for (int i = 0; i < 41; i++) {
        theory->SetBinContent(i+1,theory->GetBinContent(i+1)/theory->GetBinWidth(i+1));
    }
    TH1D* rshape_theory = (TH1D*)theory->Clone();
    for (int i = 0; i < 41; i++) {
        rshape_theory->SetBinContent(i+1,theory->GetBinContent(i+1)/peak_th);
        rshape_theory->SetBinError(i+1,theory->GetBinError(i+1)/peak_th);
    }
    if (IS_RSHAPE) theory = rshape_theory;

    TFile* g;
    if (!IS_RSHAPE) {
        if (IS_7TEV)  g = new TFile("/group/cms/users/asvyatko/CMSSW_4_2_8/src/DYPackage/Outputs/absex_full2011.root");
        else g = new TFile("../Outputs/absex_full_comb_PI_Bayesian.root");
    } else {
        if (IS_7TEV) g = new TFile("/group/cms/users/asvyatko/CMSSW_4_2_8/src/DYPackage/Outputs/rshape_full_mumuCurrentMarch.root");
        else g = new TFile("../Outputs/absex_full_comb_PI_Bayesian.root");
    }
    g->cd();
    TH1D* data = (TH1D*)hxsec->Clone();
    double peak = 0;
    double peak_err = 0.01; //1% approx, for the plot only
    for (int i = 9; i < 22; i++) {
        peak += data->GetBinContent(i+1)*data->GetBinWidth(i+1);
    }
    cout << "Peak comb data: " << peak<< endl;
    TH1D* rshape_data = (TH1D*)hxsec->Clone();
    for (int i = 0; i < 41; i++) {
        //Note: it is already pre-divided by the bin width
        rshape_data->SetBinContent(i+1,data->GetBinContent(i+1)/peak);
        rshape_data->SetBinError(i+1,sqrt(pow(data->GetBinError(i+1)/peak,2)+pow(peak_err*rshape_data->GetBinContent(i+1),2)));
    }
    if (IS_RSHAPE && !IS_7TEV) data = rshape_data;

    TGraphAsymmErrors* gdata = new TGraphAsymmErrors(nbin-1);
    for( size_t ii=0; ii<nbin; ii++ )
    {
        double x_ = fake_par[ii];
        double y_ = data->GetBinContent(ii+1);
        double exl_ = fake_par[ii]-mass_xbin[ii];
        double exh_ = mass_xbin[ii+1]-fake_par[ii];
        double eyl_ = data->GetBinError(ii+1);
        double eyh_ = eyl_;
        gdata->SetPoint(ii,x_,y_);
        gdata->SetPointError(ii,exl_,exh_,eyl_,eyh_);
    }

//FIXME need ratio plots
    TCanvas *c1 = new TCanvas("CrossSect1D","CrossSect1D",600,600);
    c1->Draw();
    c1->cd();
    TPad *p1 = new TPad("p1", "",0.0,0.25,1.0,0.98,0,0,0);
    p1->Draw();
    p1->cd();
    //p1->SetTickx(kFALSE);

    //TAxis *xaxis = h_theory4->GetXaxis();
    //xaxis->SetMoreLogLabels();
    //xaxis->SetNoExponent();

    TAxis *axis = h_theory4->GetYaxis();
    axis->SetTickLength(axis->GetTickLength()/1.35);
    //axis->SetNdivisions(506);


    p1->SetRightMargin(0.055);
    p1->SetBottomMargin(0.01);
    p1->SetTopMargin(0.1);
    p1->SetLogy();
    p1->SetLogx();
    h_theory4->GetXaxis()->SetMoreLogLabels();
    if (IS_RSHAPE) h_theory4->GetYaxis()->SetTitle("1/#sigma_{Z}d#sigma/dm [GeV^{-1}]");
    else h_theory4->GetYaxis()->SetTitle("d#sigma/dm [pb/GeV]");
    h_theory4->GetXaxis()->SetTitle("m_{#mu#mu} [GeV]");
    h_theory4->SetLineColor(kBlue);
    h_theory4->SetLineWidth(0.1);
    h_theory4->SetMarkerSize(0);
    //h_theory4->SetMaximum(h_theory4->GetMaximum()*100.);
    h_theory4->GetYaxis()->SetRangeUser(h_theory4->GetMinimum()/10.,h_theory4->GetMaximum()*10.);
    h_theory4->SetMinimum(1.5*10E-9);
    h_theory4->Draw("L");

    TH1D* h_theory4_clone = (TH1D*)h_theory4->Clone();
    h_theory4_clone->SetLineWidth(1.5);
    //h_theory4_clone->GetXaxis()->SetRangeUser(40,180);
    h_theory4_clone->Draw("Lsame");
    h_theory4_band->SetLineColor(kBlue);
    h_theory4_band->SetLineWidth(3);
    h_theory4_band->SetMarkerSize(0);
    h_theory4_band->SetFillColor(kBlue);
    h_theory4_band->Draw("E3same");
    //data->Draw("Psame");

    gdata->SetMarkerStyle(20);
    gdata->SetMarkerSize(0.7);
    gdata->Draw("Psame");

    double yminl_ = h_theory4->GetMinimum();
    double ymaxl_ = h_theory4->GetMaximum();
    //draw_bin_grid2( yminl_, 1.7*yminl_ );
    //draw_bin_grid( yminl_, 1.2*yminl_ );
    //draw_bin_grid2( ymaxl_/1.7, ymaxl_ );
    //draw_bin_grid( ymaxl_/1.2, ymaxl_ );

    // text2
    size_t ntxt = 3;
    TString txt[3];
    float txtSize[3];
    float txtX[3];
    float txtY[3];
    int   txtAlign[3];
    int   txtFont[3];

    txt[0] = "CMS"; // Preliminary";
    txtSize[0] = 0.072;
    txtX[0] = 0.27;
    txtY[0] = 0.82;
    txtAlign[0] = 21;
    txtFont[0] = 61;

    //txt[1] = "19.7 fb^{-1} at #sqrt{s} = 8 TeV";
    txt[1] = "19.7 fb^{-1} ee and #mu#mu (8 TeV)";
    txtSize[1] = 0.042;
    txtX[1] = 0.79;
    txtY[1] = 0.91;
    txtAlign[1] = 21;
    txtFont[1] = 42;

    txt[2] = "#gamma*/Z #rightarrow e^{+}e^{-}, #mu^{+}#mu^{-}";
    //txt[2] = "#gamma*/Z #rightarrow #font[11]{l#lower[-0.72]{^{#font[122]{+}}}l^{#font[122]{-}}}");
    txtSize[2] = 0.05;
    txtX[2] = 0.80;
    txtY[2] = 0.82;
    txtAlign[2] = 21;
    txtFont[2] = 42;

    TLatex latex;
    latex.SetNDC();
    for( size_t ii=0; ii<ntxt; ii++ ) {
        latex.SetTextFont(txtFont[ii]);
        latex.SetTextSize(txtSize[ii]);
        latex.SetTextAlign(txtAlign[ii]);
        latex.DrawLatex(txtX[ii],txtY[ii],txt[ii]);
    }

    TLegend *leg= new TLegend(0.21,0.10,0.51,0.30);
    leg->SetTextFont(42);
    leg->SetTextSize(0.055);
    //leg->SetTextAlign(31);
    leg->SetBorderSize(0);
    leg->SetFillColor(0);
    leg->AddEntry(gdata,"data","lp");
    leg->AddEntry(h_theory4_band,"FEWZ, NNLO CT10","f");
    leg->Draw("same");

    TH1D* ratio = (TH1D*)theory->Clone();
    ratio->Divide(data,theory);

    //cout << "XX " << ratio->GetNbinsX() << " " << theory->GetNbinsX() << endl;
    //for (int i = 0; i < ratio->GetNbinsX(); i++) {
    //   cout << i+1 << ratio->GetBinContent(i+1) << endl;
    //}

    //ratio should be a graph
    TGraphAsymmErrors* gratio = new TGraphAsymmErrors(nbin-1);
    for( size_t ii=0; ii<nbin; ii++ )
    {
        double x_ = fake_par[ii];
        double y_ = ratio->GetBinContent(ii+1);
        double exl_ = fake_par[ii]-mass_xbin[ii];
        double exh_ = mass_xbin[ii+1]-fake_par[ii];
        double eyl_ = ratio->GetBinError(ii+1);
        double eyh_ = eyl_;
        gratio->SetPoint(ii,x_,y_);
        gratio->SetPointError(ii,exl_,exh_,eyl_,eyh_);
    }

    gStyle->SetOptTitle(0);
    TPad *p2 = new TPad("p2", "",0.0,0.01,1.0,0.249,0,0,0);
    c1->cd();
    p2->Draw();
    p2->cd();
    p2->SetLogx();
    p2->SetTopMargin(0.007);
    p2->SetBottomMargin(0.32);
    p2->SetRightMargin(0.055);
    //p2->SetTickx(kFALSE);
    TAxis* ay_ = ratio->GetYaxis();

    //ax_->SetNdivisions(0);
    //ax_->SetTitleOffset(1.15);
    //ax_->SetLabelOffset(99);

//ay_->SetTitle(ytitle);
    //  ay_->CenterTitle();
    ay_->SetNdivisions(506); //506);
    ay_->SetLabelOffset(0.019);

    ratio->GetYaxis()->SetTitle("Data/theory");
    ratio->GetXaxis()->SetTitle("m [GeV]");
    ratio->SetStats(kFALSE);
    ratio->GetYaxis()->SetTitleOffset(0.41);
    ratio->GetXaxis()->SetMoreLogLabels();
    ratio->GetYaxis()->SetTitleSize(0.15);
    ratio->GetXaxis()->SetTitleSize(0.155);
    ratio->GetYaxis()->SetLabelSize(0.15);
    ratio->GetXaxis()->SetLabelSize(0);//0.15);
    ratio->GetXaxis()->SetTickLength(0.08);
    ratio->GetXaxis()->SetNoExponent(kTRUE);

    ratio->SetMarkerSize(0);
    ratio->SetMaximum(1.7);  //1.48); //1.75); //1.52);
    ratio->SetMinimum(0.3); ////0.52); //0.25);//0.4);
    ratio->SetLineColor(kBlack);
    ratio->Draw("hist");
    //draw_bin_grid(ratio->GetMinimum(),ratio->GetMaximum());
    yminl_ = ratio->GetMinimum();
    ymaxl_ = ratio->GetMaximum();
    //draw_bin_grid2( yminl_, 1.5*yminl_ );
    //draw_bin_grid( yminl_, 1.2*yminl_ );
    //draw_bin_grid2( ymaxl_/1.07, ymaxl_ );
    //draw_bin_grid( ymaxl_/1.03, ymaxl_ );
    float r0_ = 1.;
    float dr_ = 0.75;
    //draw_axis_labels(r0_-1.09*dr_,0.15);
    draw_axis_labels(r0_-1.0*dr_,0.15);
    gratio->SetMarkerColor(kViolet);
    gratio->SetMarkerSize(0.9);
    gratio->SetLineColor(kBlack);
    gratio->SetMarkerStyle(20);
    gratio->Draw("epsame");
    p2->Update();
    TLine *line=new TLine();
    line->SetLineColor(kBlue);
    line->SetLineWidth(2);
    line->DrawLine(15,1,2000,1);
    //c1->SaveAs(etaclass+run+".pdf"); //_DR53X_HCP2012.png");

    double chisquared = 0.;

    for (int i =0; i < data->GetNbinsX(); i++) {
        chisquared+=pow((data->GetBinContent(i+1)-theory->GetBinContent(i+1)),2)/(data->GetBinError(i+1)*data->GetBinError(i+1));
        //std::cout << data->GetBinError(i+1) << " " << theory->GetBinError(i+1) << std::endl;
        //chisquared+=(ee8->GetBinContent(i+1)-mumu8->GetBinContent(i+1))/sqrt(ee8->GetBinError(i+1)*mumu8->GetBinError(i+1));
    }
    cout << "Full chi2 " << chisquared/double(data->GetNbinsX()) << " " << TMath::Prob(chisquared,data->GetNbinsX())<< endl;

}
void
makeUnfoldingSystematicsComparisonPlots (int whichobservable, int whichjet, int whichlepton, int inclusive)
{
  //Open the file and form the name
  string fileSystematics; 
  string suffix="/gpfs/cms/data/2011/Systematics/postApproval_v58_Journal/";
  //string suffix="/tmp/";

  if (whichlepton==1) suffix=suffix+"ele/";
  if (whichlepton==2) suffix=suffix+"muo/";

  //  setTDRStyle ();
  gStyle->SetErrorX(0);
  gStyle->SetPadGridX(0);
  gStyle->SetPadGridY(0);

  bool absoluteNormalization = true;
  int lepton = 3; //1 -> electron,  2-> muon , 3 -> combined reults!
  bool addLumiUncertainties = true;
  double lumiError = 0.025;
  int use_case = whichobservable;
  int whichjet = whichjet;
  string version = "_v2_32";

  //string s         = "/afs/infn.it/ts/user/marone/html/ZJets/FinalPlotsForAN/v41/SVDBayes/";
  string s="/afs/infn.it/ts/user/marone/html/ZJets/FinalPlotsForAN/v58_Journal/UnfoldingSyst/ele/";
  //  string s         = "/gpfs/cms/users/schizzi/EleMuComparisonPlots/PostUnfolding/";
  string  eleplotpath = "/gpfs/cms/users/schizzi/Systematics/ele/";
  string  muoplotpath = "/gpfs/cms/users/schizzi/Systematics/muo/";

  gStyle->SetOptStat (0);

  TCanvas *plots = new TCanvas ("plots", "EB", 200, 100, 600, 800);

  //DATA:
  //string elepathFile   ="/gpfs/cms/data/2011/Unfolding/testReferenceMu.root";
  //string muopathFile   ="/gpfs/cms/data/2011/Unfolding/testMu.root";
  string elepathFile   ="/gpfs/cms/data/2011/Unfolding/UnfoldingOfficialV58_afterCWR.root";
  string muopathFile   ="/gpfs/cms/data/2011/Unfolding/UnfoldingOfficialV58_BinWidth.root";
  string thirdpathFile   ="/gpfs/cms/data/2011/Unfolding/UnfoldingOfficialV58_SherpaV2.root";

  if (whichlepton==2){
  elepathFile   ="/gpfs/cms/data/2011/Unfolding/UnfoldingOfficialV58_afterCWRMu.root";
  muopathFile   ="/gpfs/cms/data/2011/Unfolding/UnfoldingOfficialV58_BinWidthMu.root";
thirdpathFile   ="/gpfs/cms/data/2011/Unfolding/UnfoldingOfficialV58_SherpaV2Mu.root";
  s="/afs/infn.it/ts/user/marone/html/ZJets/FinalPlotsForAN/v58_Journal/UnfoldingSyst/muo/";
  }
  //string elepathFile   ="/gpfs/cms/data/2011/Unfolding/UnfoldingOfficialV57_3NoSQRT.root";
  //string muopathFile   ="/gpfs/cms/data/2011/Unfolding/UnfoldingOfficialV57_3NoMCToy.root";
    
  TFile *histof = TFile::Open (elepathFile.c_str ());
  histof->cd ("");
  TDirectory *dir = gDirectory;
  TList *mylist = (TList *) dir->GetListOfKeys ();
  TIter iter (mylist);
  TObject *tobj = 0;

  TFile *histof2 = TFile::Open (thirdpathFile.c_str ());
  histof2->cd ("");
  TDirectory *dir2 = gDirectory;
  TList *mylist2 = (TList *) dir2->GetListOfKeys ();
  TIter iter2 (mylist);
  TObject *tobj2 = 0;


  TFile *histofmuo = TFile::Open (muopathFile.c_str ());


  string stringmatch;
  string systPathFile;
  string systPathFileMuo;

  histof->cd ("");

  int i = 0;			// solo di servizio quando debuggo...
  while ((tobj = iter.Next ()))
    {
      string name = tobj->GetName ();

      if (use_case == 1) 
	{ // Jet Multiplicity
	  stringmatch = "JetMultiplicityUnfolded";
	  systPathFile = eleplotpath + "systematicsEff_jetMult" + version + ".txt";
	  systPathFileMuo = muoplotpath + "systematicsEff_jetMult" + version + ".txt";
	  fileSystematics = suffix+"systematicsUnfReweight_jetMult" + version + ".txt"; 
	}

      if (use_case == 2) 
	{ // Jet Pt
	  if (whichjet == 1)
	    {
	      stringmatch = "jReco_leading";
	      systPathFile = eleplotpath + "systematicsEff_jet1Pt" + version + ".txt";
	      systPathFileMuo = muoplotpath + "systematicsEff_jet1Pt" + version + ".txt";
	      fileSystematics = suffix+"systematicsUnfReweight_jet1Pt" + version + ".txt"; 
	    }
	  
	  if (whichjet == 2)
	    {
	      stringmatch = "jReco_subleading";
	      systPathFile = eleplotpath + "systematicsEff_jet2Pt" + version + ".txt";
	      systPathFileMuo = muoplotpath + "systematicsEff_jet2Pt" + version + ".txt";
	      fileSystematics = suffix+"systematicsUnfReweight_jet2Pt" + version + ".txt"; 
	    }
	  
	  if (whichjet == 3)
	    {
	      stringmatch = "jReco_subsubleading";
	      systPathFile = eleplotpath + "systematicsEff_jet3Pt" + version + ".txt";
	      systPathFileMuo = muoplotpath + "systematicsEff_jet3Pt" + version + ".txt";
	      fileSystematics = suffix+"systematicsUnfReweight_jet3Pt" + version + ".txt"; 
	    }
	  
	  if (whichjet == 4)
	    {
	      stringmatch = "jReco_subsubsubleading";
	      systPathFile = eleplotpath + "systematicsEff_jet4Pt" + version + ".txt";
	      systPathFileMuo = muoplotpath + "systematicsEff_jet4Pt" + version + ".txt";
	      fileSystematics = suffix+"systematicsUnfReweight_jet4Pt" + version + ".txt"; 
	    }
	}
      
      if (use_case == 3) { // Jet Eta
	if (whichjet == 1)
	  {
	    stringmatch = "jReco_leadingeta";
	    systPathFile = eleplotpath + "systematicsEff_jet1Eta" + version + ".txt";
	    systPathFileMuo = muoplotpath + "systematicsEff_jet1Eta" + version + ".txt";
	    fileSystematics = suffix+"systematicsUnfReweight_jet1Eta" + version + ".txt"; 
	  }
	
	if (whichjet == 2)
	  {
	    stringmatch = "jReco_subleadingeta";
	    systPathFile = eleplotpath + "systematicsEff_jet2Eta" + version + ".txt";
	    systPathFileMuo = muoplotpath + "systematicsEff_jet2Eta" + version + ".txt";
	    fileSystematics = suffix+"systematicsUnfReweight_jet2Eta" + version + ".txt"; 
	  }

	if (whichjet == 3)
	  {
	    stringmatch = "jReco_subsubleadingeta";
	    systPathFile = eleplotpath + "systematicsEff_jet3Eta" + version + ".txt";
	    systPathFileMuo = muoplotpath + "systematicsEff_jet3Eta" + version + ".txt";
	    fileSystematics = suffix+"systematicsUnfReweight_jet3Eta" + version + ".txt"; 
	  }
	
	if (whichjet == 4)
	  {
	    stringmatch = "jReco_subsubsubleadingeta";
	    systPathFile = eleplotpath + "systematicsEff_jet4Eta" + version + ".txt";
	    systPathFileMuo = muoplotpath + "systematicsEff_jet4Eta" + version + ".txt";
	    fileSystematics = suffix+"systematicsUnfReweight_jet4Eta" + version + ".txt"; 
	  }
      }
      
      if (use_case == 4) { // Ht
	if (whichjet == 1)
	  {
	    stringmatch = "HReco_leading";
	    systPathFile = eleplotpath + "systematicsEff_jet1Ht" + version + ".txt";
	    systPathFileMuo = muoplotpath + "systematicsEff_jet1Ht" + version + ".txt";
	    fileSystematics = suffix+"systematicsUnfReweight_jet1Ht" + version + ".txt"; 
	  }
	if (whichjet == 2)
	  {
	    stringmatch = "HReco_subleading";
	    systPathFile = eleplotpath + "systematicsEff_jet2Ht" + version + ".txt";
	    systPathFileMuo = muoplotpath + "systematicsEff_jet2Ht" + version + ".txt";
	    fileSystematics = suffix+"systematicsUnfReweight_jet2Ht" + version + ".txt"; 
	  }
	
	if (whichjet == 3)
	  {
	    stringmatch = "HReco_subsubleading";
	    systPathFile = eleplotpath + "systematicsEff_jet3Ht" + version + ".txt";
	    systPathFileMuo = muoplotpath + "systematicsEff_jet3Ht" + version + ".txt";
	    fileSystematics = suffix+"systematicsUnfReweight_jet3Ht" + version + ".txt"; 
	  }

	if (whichjet == 4)
	  {
	    stringmatch = "HReco_subsubsubleading";
	    fileSystematics = suffix+"systematicsUnfReweight_jet4Ht" + version + ".txt"; 
	    systPathFile = eleplotpath + "systematicsEff_jet4Ht" + version + ".txt";
	    systPathFileMuo = muoplotpath + "systematicsEff_jet4Ht" + version + ".txt";
	  }
      }

      
      if (name == stringmatch) {

	cout << "CONFIGURATION:" << endl;
	cout << "stringmatch: " <<stringmatch<< endl;
	cout << "systPathFile: " <<systPathFile<< endl;

	TH1D *leading;
	gDirectory->GetObject (name.c_str (), leading);
	leading->SetMarkerSize(0.9);
	leading->Sumw2();

	histofmuo->cd ("");
	TH1D *leadingmuo;
	gDirectory->GetObject (name.c_str (), leadingmuo);
	leadingmuo->SetMarkerSize(0.9);
	leadingmuo->Sumw2();

	histof2->cd ("");
	TH1D *leadingthird;
	gDirectory->GetObject (name.c_str (), leadingthird);
	leadingmuo->SetMarkerSize(0.9);
	leadingmuo->Sumw2();
	
	if (inclusive==1){
	  TH1D* leadingIncl=turnExclusiveHistoInInclusive(leading);
	  TH1D* leadingmuoIncl=turnExclusiveHistoInInclusive(leadingmuo);
	  TH1D* leadingthirdIncl=turnExclusiveHistoInInclusive(leadingthird);
	  leading=leadingIncl;
	  leadingmuo=leadingmuoIncl;
	  leadingthird=leadingthirdIncl;
	}
	//	/// EFFICIENCY Systematics:
	//	for (int nnbins=1;nnbins<=leading->GetNbinsX ();nnbins++) {
	  //	  cout << fabs(leading->GetBinContent(nnbins)-leadingmuo->GetBinContent(nnbins))/(2*leading->GetBinContent(nnbins)) << endl;
	  //	  cout << leading->GetBinContent(nnbins)-leadingmuo->GetBinContent(nnbins) << endl;
	//	}

	// read from file ---------------------------------------------
	double dat;
	ifstream inM;
	cout << "reading ...  " << systPathFile << endl;
	inM.open (systPathFile.c_str ());
	std::vector < double >systTmpM;
	while (1)
	  {
	    inM >> dat;
	    if (!inM.good ())
	      break;
	    systTmpM.push_back (dat);
	  }
	inM.close ();
	// ------------------------------------------------------------
	// read from file ---------------------------------------------
	ifstream inM2;
	cout << "reading ...  " << systPathFileMuo << endl;
	inM2.open (systPathFileMuo.c_str ());
	std::vector < double >systTmpMmuo;
	while (1)
	  {
	    inM2 >> dat;
	    if (!inM2.good ())
	      break;
	    systTmpMmuo.push_back (dat);
	  }
	inM2.close ();
	// ------------------------------------------------------------

        TH1D *leadingRatioSystematics;
	leadingRatioSystematics = (TH1D *) leading->Clone ("leading");

	if (systTmpM.size () != leadingRatioSystematics->GetNbinsX ())
	  cout << "TE SON MONA! WRONG NUMBER OF BINS (# syst from file->" <<systTmpM.size()<<" - # bins->"<<leadingRatioSystematics->GetNbinsX()<<")"<<endl;
	for (int i = 0; i < leadingRatioSystematics->GetNbinsX (); i++)
	  {
	    //leadingRatioSystematics->SetBinContent(i + 1, 1.0);
	    //leadingRatioSystematics->SetBinError (i + 1,sqrt(systTmpM[i]*systTmpM[i] + systTmpMmuo[i]*systTmpMmuo[i]));
	    //	    leadingRatioSystematics->SetBinContent(i + 1, 1.0);
	    //	    leadingRatioSystematics->SetBinError (i + 1,max(systTmpM[i]/100.0,systTmpMmuo[i]/100.0));
	  }

	plots->cd ();
	TPad *pad1 = new TPad("pad1","pad1",0.01,0.3,0.99,0.99);

	pad1->Draw();
	pad1->cd();
	pad1->SetTopMargin(0.1);
	pad1->SetBottomMargin(0.0);
	pad1->SetLeftMargin(0.2);
	pad1->SetRightMargin(0.0);
	pad1->SetFillStyle(0);
	if (use_case !=3) pad1->SetLogy(1); 
	else pad1->SetLogy(0);

	if (use_case ==3){
	  leading->SetMinimum((0.5-0.05*(whichjet-1))*leading->GetMinimum());
	  leading->SetMaximum((1.25+0.35*(whichjet-1))*leading->GetMaximum());
	}
	leading->SetLineColor (kRed+1);
	leading->SetMarkerStyle (20);
	leading->SetFillColor (kRed+1);
	leading->SetMarkerColor (kRed+1);

	leading->GetXaxis ()->SetTitleOffset (1.1);
	leading->GetXaxis ()->SetTitleSize (0.05);
	leading->GetXaxis ()->SetLabelSize (0.0);
	leading->GetXaxis ()->SetLabelFont (42);
	leading->GetXaxis ()->SetTitleFont (42);

	leading->GetYaxis ()->SetTitleOffset (1.);
	leading->GetYaxis ()->SetTitleSize (0.07);
	leading->GetYaxis ()->SetLabelSize (0.06);
	leading->GetYaxis ()->SetLabelFont (42);
	leading->GetYaxis ()->SetTitleFont (42);

	leading->SetTitle ();
	leading->GetXaxis ()->SetTitle ();
	    

	if (use_case ==1) {
	  if (absoluteNormalization) leading->GetYaxis ()->SetTitle ("d#sigma/dN [pb]");
	  else {
	    if (lepton == 1) leading->GetYaxis ()->SetTitle ("(1/#sigma_{Z #rightarrow e^{+}e^{-}}) d#sigma/dN");
	    if (lepton == 2) leading->GetYaxis ()->SetTitle ("(1/#sigma_{Z #rightarrow #mu^{+}#mu^{-}}) d#sigma/dN");
	    if (lepton == 3) leading->GetYaxis ()->SetTitle ("(1/#sigma_{Z #rightarrow l^{+}l^{-}}) d#sigma/dN");
	  }
	}

	if (use_case ==2) {
	  if (absoluteNormalization) leading->GetYaxis ()->SetTitle ("d#sigma/dp_{T} [pb/GeV]");
	  else {
	    if (lepton == 1) leading->GetYaxis ()->SetTitle ("(1/#sigma_{Z #rightarrow e^{+}e^{-}}) d#sigma/dp_{T}");
	    if (lepton == 2) leading->GetYaxis ()->SetTitle ("(1/#sigma_{Z #rightarrow #mu^{+}#mu^{-}}) d#sigma/dp_{T}");
	    if (lepton == 3) leading->GetYaxis ()->SetTitle ("(1/#sigma_{Z #rightarrow l^{+}l^{-}}) d#sigma/dp_{T}");
	  }
	}

	if (use_case ==3) {
	  if (absoluteNormalization) leading->GetYaxis ()->SetTitle ("d#sigma/d#eta [pb]");
	  else {
	    if (lepton == 1) leading->GetYaxis ()->SetTitle ("(1/#sigma_{Z #rightarrow e^{+}e^{-}}) d#sigma/d#eta");
	    if (lepton == 2) leading->GetYaxis ()->SetTitle ("(1/#sigma_{Z #rightarrow #mu^{+}#mu^{-}}) d#sigma/d#eta");
	    if (lepton == 3) leading->GetYaxis ()->SetTitle ("(1/#sigma_{Z #rightarrow l^{+}l^{-}}) d#sigma/d#eta");
	  }
	}
	  
	if (use_case ==4) {
	  if (absoluteNormalization) leading->GetYaxis ()->SetTitle ("d#sigma/dH_{T} [pb/GeV]");
	  else {
	    if (lepton == 1) leading->GetYaxis ()->SetTitle ("(1/#sigma_{Z #rightarrow e^{+}e^{-}}) d#sigma/dH_{T}");
	    if (lepton == 2) leading->GetYaxis ()->SetTitle ("(1/#sigma_{Z #rightarrow #mu^{+}#mu^{-}}) d#sigma/dH_{T}");
	    if (lepton == 3) leading->GetYaxis ()->SetTitle ("(1/#sigma_{Z #rightarrow l^{+}l^{-}}) d#sigma/dH_{T}");
	  }
	}
	  
	leading->SetFillColor (kBlack);
	leading->SetFillStyle (3001);
	leading->SetMarkerColor (kBlack);
	leading->SetLineColor (kBlack);
	leading->SetMarkerStyle (20);
	leading->Draw ("E1");

	leadingmuo->SetFillColor (kBlue);
	leadingmuo->SetFillStyle (3001);
	leadingmuo->SetMarkerColor (kBlue);
	leadingmuo->SetLineColor (kBlue);
	leadingmuo->SetMarkerStyle (21);
	leadingmuo->Draw ("E1SAME");

	leadingthird->SetFillColor (kRed);
	leadingthird->SetFillStyle (3001);
	leadingthird->SetMarkerColor (kRed);
	leadingthird->SetLineColor (kRed);
	leadingthird->SetMarkerStyle (21);
	leadingthird->Sumw2();
	//for (int j=1; j<=leadingthird->GetNbinsX();j++){
	  
	  //leadingmuo->SetBinError(j,leadingmuo->GetBinError(j)/4980.0);
	  //leadingthird->SetBinError(j,sqrt(leadingthird->GetBinContent(j))/(4980.0*100));
	//}
	leadingthird->Draw ("E1SAME");


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

	TLegend *legendsx_d;
	legendsx_d = new TLegend (0.74, 0.6, 0.98, 0.88);	   

	legendsx_d->SetFillColor (kWhite);
	legendsx_d->SetBorderSize (1);
	legendsx_d->SetNColumns(1);
	legendsx_d->SetTextSize(.040);
	legendsx_d->AddEntry (leading, "Central", "PEL");
	legendsx_d->AddEntry (leadingmuo, "Sherpa", "PEL");
	legendsx_d->AddEntry (leadingthird, "Reweighting", "PEL");
	legendsx_d->Draw ("same");

	// Draw the ratio plot: ----------------------

	leadingRatio = (TH1D *) leading->Clone ("leading");
	leadingRatio->Divide(leadingmuo);

	leadingRatio2 = (TH1D *) leading->Clone ("leading");
	leadingRatio2->Divide(leadingthird);

	for (int mem=1; mem<=leadingRatio->GetNbinsX(); mem++) {
	  cout << "Syst for bin nr." << mem << ":\t" << fabs(leadingRatio->GetBinContent(mem)-1.0)/2 << endl;
	}

	plots->cd();
	TPad *pad3 = new TPad("pad3","pad3",0.01,0.01,0.99,0.30);
	pad3->Draw();
	pad3->cd();
	pad3->SetTopMargin(0.0);
	pad3->SetBottomMargin(0.3);
	pad3->SetLeftMargin(0.2);
	pad3->SetRightMargin(0);
	pad3->SetFillStyle(0);

	leadingRatio->GetXaxis()->SetLabelFont (42);
	leadingRatio->GetXaxis()->SetTitleFont (42);
	leadingRatio->GetXaxis()->SetTitleSize(0.11);
	leadingRatio->GetXaxis()->SetLabelSize(0.11);
	leadingRatio->GetXaxis()->SetTitleOffset (1.1);
	leadingRatio->GetYaxis()->SetTitleSize(0.11);
	leadingRatio->GetYaxis()->SetLabelSize(0.10);
	leadingRatio->GetYaxis()->SetTitleOffset(0.65);
	leadingRatio->GetYaxis()->SetTitle("Ratio");   
	leadingRatio->GetYaxis()->SetNdivisions(5);
	leadingRatio->GetYaxis()->SetRangeUser(0.4,1.6);


	if (use_case ==1) {
	  leadingRatio->GetXaxis ()->SetTitle ("Exclusive jet multiplicity");
	}
	if (use_case ==2) {
	  if (whichjet == 1) leadingRatio->GetXaxis ()->SetTitle ("Leading jet p_{T} [GeV]");
	  if (whichjet == 2) leadingRatio->GetXaxis ()->SetTitle ("Second jet p_{T} [GeV]");
	  if (whichjet == 3) leadingRatio->GetXaxis ()->SetTitle ("Third jet p_{T} [GeV]");
	  if (whichjet == 4) leadingRatio->GetXaxis ()->SetTitle ("Fourth jet p_{T} [GeV]");
	}
	if (use_case ==3) {
	  if (whichjet == 1) leadingRatio->GetXaxis ()->SetTitle ("Leading jet #eta");
	  if (whichjet == 2) leadingRatio->GetXaxis ()->SetTitle ("Second jet #eta");
	  if (whichjet == 3) leadingRatio->GetXaxis ()->SetTitle ("Third jet #eta");
	  if (whichjet == 4) leadingRatio->GetXaxis ()->SetTitle ("Fourth jet #eta");
	}
	if (use_case ==4) {
	  if (whichjet == 1) leadingRatio->GetXaxis ()->SetTitle ("H_{T}, N_{jet} >= 1 [GeV]");
	  if (whichjet == 2) leadingRatio->GetXaxis ()->SetTitle ("H_{T}, N_{jet} >= 2 [GeV]");
	  if (whichjet == 3) leadingRatio->GetXaxis ()->SetTitle ("H_{T}, N_{jet} >= 3 [GeV]");
	  if (whichjet == 4) leadingRatio->GetXaxis ()->SetTitle ("H_{T}, N_{jet} >= 4 [GeV]");
	}

	leadingRatio->SetFillColor (kRed+2);
	leadingRatio->SetMarkerColor (kRed+2);
	leadingRatio->SetLineColor (kRed+2);
	leadingRatio->Draw ("E0");

	leadingRatioSystematics->SetFillColor (kGreen+3);
	leadingRatioSystematics->SetFillStyle (3004);
	leadingRatioSystematics->SetMarkerColor (kGreen+3);
	leadingRatioSystematics->SetLineColor (kGreen+3);
	leadingRatioSystematics->SetMarkerStyle (1);
	//leadingRatioSystematics->Draw ("E3SAME");

	leadingRatio->Draw ("E1SAME");
	leadingRatio2->SetMarkerColor(kBlue);
	leadingRatio2->SetLineColor(kBlue);
	leadingRatio2->Draw ("E1SAME");

	myfile.open (fileSystematics.c_str());
	cout<<"TXT file saved in "<<fileSystematics<<endl;
	loopAndDumpEntries(leadingRatio,leadingmuo);

	TLine *OLine2 = new TLine(leading->GetXaxis()->GetXmin(),1.,leading->GetXaxis()->GetXmax(),1.);
	OLine2->SetLineColor(kBlack);
	OLine2->SetLineStyle(2);
	OLine2->Draw();
	  
	//latexLabel->SetTextSize(0.09);
	//	latexLabel->DrawLatex(0.2,0.35,"Ratio");	  

	/////////////////////////////////////////////////////
	  
	string title1;
	title1 = s + "DifferentialX" + stringmatch + ".pdf";
	cout << title1 << endl;
	plots->Print (title1.c_str ());
	plots->Draw();
	return;
      }
    }
Esempio n. 12
0
void MakeMinvMix(Int_t cen=6){

  TFile fout("raw_MBmix.root","update") ;
  TFile * f = new TFile("LHC13bc_MB.root") ; //result of data scan
  

  TH1F * hev = (TH1F*)f->Get("hSelEvents") ;
  TH1F * hCentrality1  = (TH1F*)f->Get("hCentrality") ;
  
  printf("TotSelEvents: %f \n",hev->GetBinContent(7)) ;
  printf("Centrality:   %f \n",hCentrality1->Integral()) ;

   Int_t nbin=33 ;
   Double_t xa[34] ={0.8,1.0,1.2,1.4,1.6, 1.8,2.0,2.2,2.4,2.6, 2.8,3.0,3.2,3.4,3.6, 3.8,4.0,4.5,5.0,5.5, 6.,7.,8.,10.,12.,16.,20.,22.,  24.,26.,28.,30.,35.,  40.};
//    Int_t nbin=26 ;
//    Double_t xa[27] ={0.8,1.0,1.2,1.4,1.6, 1.8,2.0,2.2,2.4,2.6, 2.8,3.0,3.2,3.4,3.6, 3.8,4.0,4.5,5.0,5.5, 6.,7.,8.,10.,12.,16.,20.};
   
  const Int_t nPID=4 ;
  char cPID[14][15] ;
  snprintf(cPID[0],15,"Emin3_All") ;
  snprintf(cPID[1],15,"Emin3_Disp");
  snprintf(cPID[2],15,"Emin3_CPV") ;
  snprintf(cPID[3],15,"Emin3_Both"); 

  TH2F * hRe[20] ;
  TH2F * hMi[20] ;
  TH2F * tmp = 0x0 ;
  if(cen==6){ //6:0-20, 7:0-10
      for(Int_t iPID=0;iPID<nPID;iPID++){
	hRe[iPID] = (TH2F*)f->Get(Form("hInvM_Re_%s_cent0",cPID[iPID])) ;
        tmp = (TH2F*)f->Get(Form("hInvM_Re_%s_cent1",cPID[iPID])) ;
        hRe[iPID]->Add(tmp) ;delete tmp ;
        tmp = (TH2F*)f->Get(Form("hInvM_Re_%s_cent2",cPID[iPID])) ;
        hRe[iPID]->Add(tmp) ;delete tmp ;
        tmp = (TH2F*)f->Get(Form("hInvM_Re_%s_cent3",cPID[iPID])) ;
        hRe[iPID]->Add(tmp) ;delete tmp ;
        tmp = (TH2F*)f->Get(Form("hInvM_Re_%s_cent4",cPID[iPID])) ;
        hRe[iPID]->Add(tmp) ;delete tmp ;
        hRe[iPID]->Sumw2() ;	
	
	hMi[iPID] = (TH2F*)f->Get(Form("hInvM_Mi_%s_cent0",cPID[iPID])) ;
        tmp = (TH2F*)f->Get(Form("hInvM_Mi_%s_cent1",cPID[iPID])) ;
        hMi[iPID]->Add(tmp) ;delete tmp ;
        tmp = (TH2F*)f->Get(Form("hInvM_Mi_%s_cent2",cPID[iPID])) ;
        hMi[iPID]->Add(tmp) ;delete tmp ;
        tmp = (TH2F*)f->Get(Form("hInvM_Mi_%s_cent3",cPID[iPID])) ;
        hMi[iPID]->Add(tmp) ;delete tmp ;
        tmp = (TH2F*)f->Get(Form("hInvM_Mi_%s_cent4",cPID[iPID])) ;
        hMi[iPID]->Add(tmp) ;delete tmp ;
        hMi[iPID]->Sumw2() ;	
      }
  }
  else{
      for(Int_t iPID=0;iPID<nPID;iPID++){
	hRe[iPID] = (TH2F*)f->Get(Form("hInvM_Re_%s_cent%d",cPID[iPID],cen)) ;	
        hRe[iPID]->Sumw2() ;	
	hMi[iPID] = (TH2F*)f->Get(Form("hInvM_Mi_%s_cent%d",cPID[iPID],cen)) ;
        hMi[iPID]->Sumw2() ;	
      }    
  }
      
  PPRstyle();
  gStyle->SetPadLeftMargin(0.14);
  gStyle->SetPadRightMargin(0.01);
  gStyle->SetPadTopMargin(0.01);
  gStyle->SetPadBottomMargin(0.08);


  //Gaus
  TH1D *mr1[nPID],*sr1[nPID],*nr1[nPID],*nr1int[nPID] ;
  for(Int_t iPID=0;iPID<nPID;iPID++){
    mr1[iPID] = new TH1D(Form("mass1_GS_%s_cen%d",cPID[iPID],cen),"Mass",nbin,xa) ;
    sr1[iPID] = new TH1D(Form("width1_GS_%s_cen%d",cPID[iPID],cen),"Width",nbin,xa) ;
    nr1[iPID] = new TH1D(Form("yeild1_GS_%s_cen%d",cPID[iPID],cen),"Raw yield",nbin,xa) ;
    nr1int[iPID] = new TH1D(Form("yeild1_int_GS_%s_cen%d",cPID[iPID],cen),"Raw yield, integrated",nbin,xa) ;
  }

  //CB
  TH1D *mr2[nPID],*sr2[nPID],*nr2[nPID],*nr2int[nPID] ;
  for(Int_t iPID=0;iPID<nPID;iPID++){  
    mr2[iPID] = new TH1D(Form("mass2_CB_%s_cen%d",cPID[iPID],cen),"Mass",nbin,xa) ;
    sr2[iPID] = new TH1D(Form("width2_CB_%s_cen%d",cPID[iPID],cen),"Width",nbin,xa) ;
    nr2[iPID] = new TH1D(Form("yeild2_CB_%s_cen%d",cPID[iPID],cen),"Raw yield",nbin,xa) ;
    nr2int[iPID] = new TH1D(Form("yeild2_int_CB_%s_cen%d",cPID[iPID],cen),"Raw yield, integrated",nbin,xa) ;
  }

  TF1 * fun1 = new TF1("ft1",CB1,0.,1.,8) ;
  fun1->SetParName(0,"A") ;
  fun1->SetParName(1,"m_{0}") ;
  fun1->SetParName(2,"#sigma") ;
  fun1->SetParName(3,"n") ;
  fun1->SetParName(4,"#alpha") ;
  fun1->SetParName(5,"a_{0}") ;
  fun1->SetParName(6,"a_{1}") ;
  fun1->SetParName(7,"a_{2}") ;
  fun1->FixParameter(3,3.28) ;
  fun1->FixParameter(4,1.56) ;
  fun1->SetLineWidth(2) ;
  fun1->SetLineColor(4) ;
  fun1->SetLineStyle(2) ;

  TF1 * fun2 = new TF1("ft2",CB2,0.,1.,9) ;
  fun2->SetParName(0,"A") ;
  fun2->SetParName(1,"m_{0}") ;
  fun2->SetParName(2,"#sigma") ;
  fun2->SetParName(3,"n") ;
  fun2->SetParName(4,"#alpha") ;
  fun2->SetParName(5,"a_{0}") ;
  fun2->SetParName(6,"a_{1}") ;
  fun2->SetParName(7,"a_{2}") ;
  fun2->SetParName(8,"a_{3}") ;
  fun2->FixParameter(3,3.28) ;
  fun2->FixParameter(4,1.56) ;
  fun2->SetLineWidth(2) ;
  fun2->SetLineColor(4) ;
  fun2->SetLineStyle(2) ;
  
  TF1 * funGS1 = new TF1("ft1",GS1,0.,1.,6) ;
  funGS1->SetParName(0,"A") ;
  funGS1->SetParName(1,"m_{0}") ;
  funGS1->SetParName(2,"#sigma") ;
  funGS1->SetParName(3,"a_{0}") ;
  funGS1->SetParName(4,"a_{1}") ;
  funGS1->SetParName(5,"a_{2}") ;
  funGS1->SetLineWidth(2) ;
  funGS1->SetLineColor(8) ;
//   funGS1->SetLineStyle(2) ;

  TF1 * funGS2 = new TF1("ft2",GS2,0.,1.,7) ;
  funGS2->SetParName(0,"A") ;
  funGS2->SetParName(1,"m_{0}") ;
  funGS2->SetParName(2,"#sigma") ;
  funGS2->SetParName(3,"a_{0}") ;
  funGS2->SetParName(4,"a_{1}") ;
  funGS2->SetParName(5,"a_{2}") ;
  funGS2->SetParName(6,"a_{3}") ;
  funGS2->SetLineWidth(2) ;
  funGS2->SetLineColor(8) ;
//   funGS2->SetLineStyle(2) ;
  
  
  
  TF1 * fit1=0x0 ;
  TF1 * fit2=0x0 ;
  
  TF1 * fbgP0 = new TF1("bg",BG,0.,1.,2) ;
  TF1 * fbgP1 = new TF1("bg1",BG1,0.,1.,3) ;
  TF1 * fbgP2 = new TF1("bg2",BG2,0.,1.,4) ;
  TF1 * fbg1=0x0 ;
  TF1 * fbg2=0x0 ;
  TF1 * fgs = new TF1("gs",GSs,0.,1.,4) ;
  TF1 * fcb = new TF1("cb",CBs,0.,1.,6) ;
  fgs->SetLineColor(8) ;
  fgs->SetLineWidth(2) ;
  fcb->SetLineColor(4) ;
  fcb->SetLineWidth(2) ;
  fcb->SetLineStyle(2) ;
  fcb->FixParameter(3,3.28) ;
  fcb->FixParameter(4,1.56) ;

  TCanvas * c1[nPID] ;
  TCanvas * c2[nPID] ;
  TCanvas * c1b[nPID] ;
  TCanvas * c2b[nPID] ;
  for(Int_t iPID=0;iPID<nPID;iPID++){
    c1[iPID] = new TCanvas(Form("Ratio_%s",cPID[iPID]),Form("Ratio_%s",cPID[iPID]),10+10*iPID,10,1200+10*iPID,800) ;
    c1[iPID]->Divide(4,4) ;
    c2[iPID] = new TCanvas(Form("Signal_%s",cPID[iPID]),Form("Signal_%s",cPID[iPID]),10+10*iPID,10,1200+10*iPID,800) ;
    c2[iPID]->Divide(4,4) ;
    c1b[iPID] = new TCanvas(Form("RatioB_%s",cPID[iPID]),Form("Ratio_%s",cPID[iPID]),10+10*iPID,10,1200+10*iPID,800) ;
    c1b[iPID]->Divide(4,3) ;
    c2b[iPID] = new TCanvas(Form("SignalB_%s",cPID[iPID]),Form("Signal_%s",cPID[iPID]),10+10*iPID,10,1200+10*iPID,800) ;
    c2b[iPID]->Divide(4,3) ;
  }
  c1[0]->cd(0) ;

  TAxis * pta=hRe[0]->GetYaxis() ;
  TAxis * ma=hRe[0]->GetXaxis() ;
    
  for(Int_t i=1;i<=nbin;i++){
    Int_t imin=pta->FindBin(xa[i-1]+0.0001);
    Int_t imax=pta->FindBin(xa[i]-0.0001) ;
    TH1D *hp;
    Double_t pt=(xa[i]+xa[i-1])/2. ;
        
    for(Int_t iPID=0;iPID<nPID;iPID++){
      if(i<17)
        c1[iPID]->cd(i) ;
      else
        c1b[iPID]->cd(i-16) ;
      hp = hRe[iPID]->ProjectionX(Form("re%d_%d",i,iPID),imin,imax) ;
//      hp->Sumw2() ;
      hpm= hMi[iPID]->ProjectionX(Form("mi%d_%d",i,iPID),imin,imax) ;
//      hpm->Sumw2() ;
      if(pt>12.){
    hp ->Rebin(2) ;
    hpm->Rebin(2) ;
      }
    if(pt<2.){ //2pol,3pol
      fit1=funGS2 ;
      fit2=fun2 ;
      fbg1=fbgP2 ;
      fbg2=fbgP2 ;
      
    }
    else{ //pol1,pol2
      fit1=funGS1 ;
      fit2=fun1 ;
      fbg1=fbgP1 ;
      fbg2=fbgP1 ;
      
    }
    
//      for(Int_t ib=1; ib<=hp->GetNbinsX();ib++){if(hp ->GetBinContent(ib)==0)hp ->SetBinError(ib,1.);}
//      for(Int_t ib=1; ib<=hp->GetNbinsX();ib++){if(hpm->GetBinContent(ib)==0)hpm->SetBinError(ib,1.);}
      TH1D * hpm2   = (TH1D*)hpm->Clone(Form("Bg1_%d",iPID)) ;
      TH1D * hpcopy = (TH1D*)hp ->Clone(Form("hpcopy_%d",iPID)) ;
      TH1D * hp2    = (TH1D*)hp ->Clone(Form("hp2_%d",iPID)) ;
      hpcopy->SetXTitle("M_{#gamma#gamma} (GeV/c^{2})");
      hp2   ->SetXTitle("M_{#gamma#gamma} (GeV/c^{2})");
      hpcopy->Divide(hpm) ;
      hpcopy->SetTitle(Form("%3.1f<p_{T}<%3.1f GeV/c",xa[i-1],xa[i])) ;
      hpcopy->SetMarkerStyle(20) ;
      hpcopy->SetMarkerSize(0.7) ;
      hpcopy->GetXaxis()->SetRangeUser(0.05,0.25) ;
      
//      fit1->SetParameters(0.0002+0.0001*i*i,0.136,0.011,0.0002,-0.002,0.0) ;
      fit1->SetParameters(0.0002+0.0001*i*i,0.136,0.005,0.0002,-0.002,0.0) ;
//      fit1->SetParameters(0.0002,0.136,0.011,0.0002,-0.002,0.0) ;
      if(cen==0)
        fit1->SetParameters(0.001,0.146,0.005,0.12,-0.002,0.0) ;
      fit1->SetParLimits(0,0.000,2.*hpcopy->GetMaximum()) ;
      fit1->SetParLimits(1,0.125,0.145) ;
      fit1->SetParLimits(2,0.0045,0.010) ;

      Double_t rangeMin=0.07 ;//TMath::Max(0.06,0.11-0.01*i) ;
      Double_t rangeMax=0.22; //TMath::Min(0.25,0.18+0.01*i) ;
//       if(pt>10){
//         rangeMax=0.18; 
//         rangeMin=0.10; 
//       }
//      Double_t rangeMin=TMath::Max(0.06,0.12-0.01*i) ;
//      Double_t rangeMax=TMath::Min(0.25,0.16+0.01*i) ;

      hpcopy->Fit(fit1,"Q","",rangeMin,rangeMax) ;
      hpcopy->Fit(fit1,"MQ","",rangeMin,rangeMax) ;

      fit2->SetParameters(fit1->GetParameters()) ;
      fit2->SetParameter(3,3.2) ;
      fit2->SetParameter(4,1.56) ;
      fit2->SetParameter(5,fit1->GetParameter(3)) ;
      fit2->SetParameter(6,fit1->GetParameter(4)) ;
      fit2->SetParameter(7,fit1->GetParameter(5)) ;      
      fit2->SetParLimits(0,0.000,2.*hpcopy->GetMaximum()) ;
      fit2->SetParLimits(1,0.125,0.145) ;
      fit2->SetParLimits(2,0.0045,0.010) ;
      
      hpcopy->Fit(fit2,"+QN","",rangeMin,rangeMax) ;
      hpcopy->Fit(fit2,"+MQ","",rangeMin,rangeMax) ;
      c1[iPID]->cd(i) ;
      hpcopy->Draw() ;
      if(i<17)
        c1[iPID]->Update() ;
      else
        c1b[iPID]->Update() ;

      if(i<17)
        c2[iPID]->cd(i) ;
      else
        c2b[iPID]->cd(i-16) ;
      
      fbg1->SetParameters(fit1->GetParameter(3),fit1->GetParameter(4),fit1->GetParameter(5),fit1->GetParameter(6)); 
      fbg2->SetParameters(fit2->GetParameter(5),fit2->GetParameter(6),fit2->GetParameter(7),fit2->GetParameter(8)); 
      
      Double_t intRangeMin = PeakPosition(pt)-3.*PeakWidth(pt) ;
      Double_t intRangeMax = PeakPosition(pt)+3.*PeakWidth(pt) ;
      Int_t    intBinMin   = hp->GetXaxis()->FindBin(intRangeMin) ;
      Int_t    intBinMax   = hp->GetXaxis()->FindBin(intRangeMax) ;
      Double_t errStat     = hpm->Integral(intBinMin,intBinMax); 

      hpm ->Multiply(fbg1) ;
      hpm2->Multiply(fbg2) ;
      if(pt<10.){
        hp  ->Add(hpm ,-1.) ;
        hp2 ->Add(hpm2,-1.) ;
      }
      
      Int_t binPi0 = hp->FindBin(kMean);
      fgs->SetParameters(hp->Integral(binPi0-1,binPi0+1)/3.,fit1->GetParameter(1),0.006) ;
      fgs->SetParLimits(0,0.000,10.*hp->GetMaximum()) ;
      fgs->SetParLimits(1,0.120,0.175) ;
      fgs->SetParLimits(2,0.0055,0.010) ;
      hp->Fit(fgs,"QL","",rangeMin,rangeMax) ;   
      hp->Fit(fgs,"QML","",rangeMin,rangeMax) ;   
      hp->SetMaximum(hp->GetMaximum()*1.4) ;
      hp->SetMinimum(hp->GetMinimum()*1.1) ;
      hp->SetMarkerStyle(20) ;
      hp->SetMarkerSize(0.7) ;
      mr1[iPID]->SetBinContent(i,fgs->GetParameter(1)) ;
      mr1[iPID]->SetBinError  (i,fgs->GetParError(1) ) ;
      sr1[iPID]->SetBinContent(i,TMath::Abs(fgs->GetParameter(2))) ;
      sr1[iPID]->SetBinError  (i,fgs->GetParError(2) ) ;

      Double_t y=fgs->GetParameter(0)/hp->GetXaxis()->GetBinWidth(1) ;
      nr1[iPID]->SetBinContent(i,y) ;
      Double_t ey=fgs->GetParError(0)/hp->GetXaxis()->GetBinWidth(1) ;
      nr1[iPID]->SetBinError(i,ey) ;

      Double_t npiInt = hp->Integral(intBinMin,intBinMax)-(intBinMax-intBinMin)*fgs->GetParameter(3) ;
      Double_t norm   = fbg1->GetParameter(0) ;
      Double_t normErr= fbg1->GetParError(0) ;
      if(npiInt>0.){
        nr1int[iPID]->SetBinContent(i,npiInt) ;
        nr1int[iPID]->SetBinError(i,TMath::Sqrt(npiInt + norm*errStat + normErr*normErr*errStat*errStat + norm*norm*errStat)) ;
      }
      
//printf(" Nint1 =%f+-%f \n",npiInt,TMath::Sqrt(npiInt + norm*errStat + normErr*normErr*errStat*errStat + norm*norm*errStat)) ;
      hp2->GetXaxis()->SetRangeUser(rangeMin,rangeMax) ;
      hp2->SetMaximum(hp2->GetMaximum()*1.4) ;
      hp2->SetMinimum(hp2->GetMinimum()*1.1) ;
      hp2->SetMarkerStyle(24) ;
      hp2->SetMarkerSize(0.8) ;

      fcb->SetParameters(hp->Integral(binPi0-1,binPi0+1)/3.,fit2->GetParameter(1),0.006,fit2->GetParameter(3),fit2->GetParameter(4)) ;
      fcb->SetParLimits(0,0.000,10.*hp->GetMaximum()) ;
      fcb->SetParLimits(1,0.120,0.175) ;
      fcb->SetParLimits(2,0.005,0.010) ;
      hp2->Fit(fcb,"QL","",rangeMin,rangeMax) ;
      hp2->Fit(fcb,"QML","",rangeMin,rangeMax) ;
      mr2[iPID]->SetBinContent(i,fcb->GetParameter(1)) ;
      mr2[iPID]->SetBinError  (i,fcb->GetParError(1)) ;
      sr2[iPID]->SetBinContent(i,TMath::Abs(fcb->GetParameter(2))) ;
      sr2[iPID]->SetBinError  (i,fcb->GetParError(2)) ;
      
      y=(fcb->Integral(0.05,0.25)-fcb->GetParameter(5)*(0.25-0.05))/hp->GetXaxis()->GetBinWidth(1) ;
      nr2[iPID]->SetBinContent(i,y) ;
      Double_t ey=fcb->IntegralError(0.05,0.25)/hp->GetXaxis()->GetBinWidth(1) ;
      nr2[iPID]->SetBinError(i,ey) ;
   
      npiInt=hp2->Integral(intBinMin,intBinMax)-(intBinMax-intBinMin)*fgs->GetParameter(3) ;
      norm=fbg2->GetParameter(0) ;
      normErr=fbg2->GetParError(0) ;
      if(npiInt>0.){
        nr2int[iPID]->SetBinContent(i,npiInt) ;
        nr2int[iPID]->SetBinError(i,TMath::Sqrt(npiInt + norm*errStat + normErr*normErr*errStat*errStat + norm*norm*errStat)) ;
      } 
//printf(" Nint2 =%f+-%f \n",npiInt,TMath::Sqrt(npiInt + norm*errStat + normErr*normErr*errStat*errStat + norm*norm*errStat)) ;
      hp2->SetTitle(Form("%3.1f<p_{T}<%3.1f GeV/c",xa[i-1],xa[i])) ;
      hp2->Draw() ;
      hp->SetMarkerColor(6) ;
      hp->Draw("same") ;
      hp2->Draw("same") ;
      c2[iPID]->Update() ;

//      delete hp ;
//    delete hp2 ;
//    delete hpcopy ;
      delete hpm ;
//      delete hpm2 ;
      
    }
  }
/*  
  for(Int_t iPID=0; iPID<4; iPID++){
   c1[iPID]->Print(Form("Ratio_%s_cen%d.eps",cPID[iPID],cen)) ;
   c2[iPID]->Print(Form("Signal_%s_cen%d.eps",cPID[iPID],cen)) ;
  }
*/  
  //Normalize by the number of events
  Int_t cMin,cMax;
  if      (cen == 0) {
    cMin=1;
    cMax=20;
  }
  else if (cen == 1) {
    cMin=21;
    cMax=40;
  }
  else if (cen == 2) {
    cMin=41;
    cMax=60;
  }
  else if (cen == 3) {
    cMin=61;
    cMax=80;
  }
  else if (cen == 4) {
    cMin=81;
    cMax=100;
  }
  else if (cen == 5) {
    cMin=61;
    cMax=80;
  }
  else if (cen == 6) {
    cMin=1;
    cMax=100;
  }
  else if (cen == 7) {
    cMin=1;
    cMax=10;
  }
  else if (cen == 8) {
    cMin=41;
    cMax=80;
  }
  else if (cen == 9) {
    cMin=1;
    cMax=40;
  }
  Double_t nevents = hCentrality1->Integral(cMin,cMax);
  printf("Nevents=%f \n",nevents) ;
  for(Int_t iPID=0;iPID<nPID;iPID++){
    nr1[iPID]   ->Scale(1./nevents) ;
    nr1int[iPID]->Scale(1./nevents) ;
    nr2[iPID]   ->Scale(1./nevents) ;
    nr2int[iPID]->Scale(1./nevents) ;
    nr1[iPID]->SetMarkerStyle(20) ;
    nr1[iPID]->SetMarkerColor(2) ;
    nr1[iPID]->SetTitle("#pi^{0} raw yield per event") ;
    nr2[iPID]->SetTitle("#pi^{0} raw yield per event") ;
  }
  
  fout.cd() ;
  for(Int_t iPID=0;iPID<nPID;iPID++){
    nr1[iPID]->Write(0,TObject::kOverwrite) ;
    nr2[iPID]->Write(0,TObject::kOverwrite) ;
    nr1int[iPID]->Write(0,TObject::kOverwrite) ;
    nr2int[iPID]->Write(0,TObject::kOverwrite) ;
    mr1[iPID]->Write(0,TObject::kOverwrite) ;
    mr2[iPID]->Write(0,TObject::kOverwrite) ;
    sr1[iPID]->Write(0,TObject::kOverwrite) ;
    sr2[iPID]->Write(0,TObject::kOverwrite) ;
  }
  fout.Close() ;



}
Esempio n. 13
0
int compare(int centbin, int type, int isjf, const string frun10, const string fout)//frun10:"run10_output_old.lst"
{
  string frun11; 

  if(isjf){
    if(type == 0) frun11 = "/direct/phenix+u/hge/offline/AnalysisTrain/Correlation/macros/makejfs_inc_fold_taxi5286.root";
    if(type == 1) frun11 = "/direct/phenix+u/hge/offline/AnalysisTrain/Correlation/macros/makejfs_pi0_fold_taxi5286.root";
    if(type == 2) frun11 = "/direct/phenix+u/hge/offline/AnalysisTrain/Correlation/macros/makejfs_dec_fold_taxi5286.root";
    if(type == 3) frun11 = "/direct/phenix+u/hge/offline/AnalysisTrain/Correlation/macros/makedirs_taxi5286.root";
  }
  else{
    if(type == 0) frun11 = "/direct/phenix+u/hge/offline/AnalysisTrain/Correlation/macros/makecfs_inc_fold_taxi5286.root";
    if(type == 1) frun11 = "/direct/phenix+u/hge/offline/AnalysisTrain/Correlation/macros/makecfs_pi0_fold_taxi5286.root";
    if(type == 2) frun11 = "/direct/phenix+u/hge/offline/AnalysisTrain/Correlation/macros/makecfs_dec_fold_taxi5286.root";
  }

  TFile* f11 = new TFile(frun11.c_str());
  
  vector<string> Run10FileList;
  char buffer[256];
  cout<<"opening run10 input file list: " << frun10.c_str() << endl;
  ifstream flist(frun10.c_str());
  if( !flist.is_open()) return -1;

  while (flist.getline(buffer, 256, '\n')){
    cout<<"in the while loop"<<endl;
    char this_file[512];
    strcpy(this_file, buffer);
    cout<<"this_file: "<<this_file<<endl;
    string s (this_file);
    cout<<"s: "<<s.c_str()<<endl;
    Run10FileList.push_back(s);
  }
  cout << "Done making Run10FileList vector." << endl;
  const int Nfiles = Run10FileList.size();
  cout<<"Nfiles = "<<Nfiles<<endl;

  TFile* foutput = new TFile(fout.c_str(), "recreate");
  foutput->cd();

  TH1D *my_corr;
  TH1D *corr;
  TH1D *ratio;
  string file_string;
  string photon_bin_string;
  string hadron_bin_string;
  int photon_bin;
  int hadron_bin;
  ostringstream bin;
  ostringstream cbin;
  ostringstream cfname;
  ostringstream jfname;
  ostringstream dirname;
  ostringstream can_name;
  ostringstream latex_name;
  string ratio_name;

  cout<<"define canvases."<<endl;
  TCanvas *can[4];
  TCanvas *can_ratio[4];
  for(int i=0; i<4; i++){
    can_name.str("");
    can_name << "can_p"<<i;
    can[i] = new TCanvas(can_name.str().c_str(),can_name.str().c_str());
    can[i]->Divide(3,2);
    can_name.str("");
    can_name << "can_ratio_p"<<i;
    can_ratio[i] = new TCanvas(can_name.str().c_str(),can_name.str().c_str());
    can_ratio[i]->Divide(3,2);
  }

  TH1D* ttest_CF = new TH1D("ttest_CF","ttest_CF",50,-5,5);
  ttest_CF->GetXaxis()->SetTitle("t");
  TH1D* tprob_CF = new TH1D("tprob_CF","tprob_CF",50,0,1);
  tprob_CF->GetXaxis()->SetTitle("prob");
  TH1D* chitest_CF = new TH1D("chitest_CF","chitest_CF",50,0,5);
  chitest_CF->GetXaxis()->SetTitle("#chi^{2}/NDF");
  TH1D* chiprob_CF = new TH1D("chiprob_CF","chiprob_CF",50,0,1);
  chiprob_CF->GetXaxis()->SetTitle("prob");

  cout<<"start looping run10 files."<<endl;
  for(int ifile = 0; ifile < Nfiles; ifile++){
    cout<<"Run10FileList ["<<ifile<<"] = "<<Run10FileList[ifile]<<endl;
    file_string = Run10FileList[ifile];
    int p1 = file_string.find_last_of("/");
    cout<<"p1 = "<<p1<<endl;
    photon_bin_string = file_string.substr(p1+6,1);
    photon_bin = atoi(photon_bin_string.c_str());
    int p2 = file_string.find_last_of(".");
    cout<<"p2 = "<<p2<<endl;
    hadron_bin_string = file_string.substr(p2-1,1);
    hadron_bin = atoi(hadron_bin_string.c_str());

    cout<<"photon_bin: "<<photon_bin<<" hadron_bin: "<<hadron_bin<<endl;
    cbin.str("");
    cbin << centbin;
    cfname.str("");
    jfname.str("");
    dirname.str("");
    can_name.str("");
    switch(photon_bin){
    case 5:
      cout<<"photon case 5"<<endl;
      latex_name.str("");
      latex_name << "5-7 #times ";
      switch(hadron_bin){
      case 1:
	latex_name << "0.5-1 GeV/c";
	cfname << "CF_c"<<cbin.str()<<"_p0_h0";
	jfname << "JF_c"<<cbin.str()<<"_p0_h0";
	dirname << "DIR_JF_c"<<cbin.str()<<"_p0_h0";
	can[0]->cd(1);
	break;
      case 2:
	latex_name << "1-2 GeV/c";
	cfname << "CF_c"<<cbin.str()<<"_p0_h1";
	jfname << "JF_c"<<cbin.str()<<"_p0_h1";
	dirname << "DIR_JF_c"<<cbin.str()<<"_p0_h1";
	can[0]->cd(2);
	break;
      case 3:
	latex_name << "2-3 GeV/c";
	cfname << "CF_c"<<cbin.str()<<"_p0_h2";
	jfname << "JF_c"<<cbin.str()<<"_p0_h2";
	dirname << "DIR_JF_c"<<cbin.str()<<"_p0_h2";
	can[0]->cd(3);
	break;
      case 5:
	latex_name << "3-5 GeV/c";
	cfname << "CF_c"<<cbin.str()<<"_p0_h3";
	jfname << "JF_c"<<cbin.str()<<"_p0_h3";
	dirname << "DIR_JF_c"<<cbin.str()<<"_p0_h3";
	can[0]->cd(4);
	break;
	
      case 0:
	latex_name << "5-7 GeV/c";
	cfname << "CF_c"<<cbin.str()<<"_p0_h4";
	jfname << "JF_c"<<cbin.str()<<"_p0_h4";
	dirname << "DIR_JF_c"<<cbin.str()<<"_p0_h4";
	can[0]->cd(5);
	break;
	
      }
      break;

    case 7:
      cout<<"photon case 7"<<endl;
      latex_name.str("");
      latex_name << "7-9 #times ";
      switch(hadron_bin){
      case 1:
	latex_name << "0.5-1 GeV/c";
	cfname << "CF_c"<<cbin.str()<<"_p1_h0";
	jfname << "JF_c"<<cbin.str()<<"_p1_h0";
	dirname << "DIR_JF_c"<<cbin.str()<<"_p1_h0";
	can[1]->cd(1);
	break;
      case 2:
	latex_name << "1-2 GeV/c";
	cfname << "CF_c"<<cbin.str()<<"_p1_h1";
	jfname << "JF_c"<<cbin.str()<<"_p1_h1";
	dirname << "DIR_JF_c"<<cbin.str()<<"_p1_h1";
	can[1]->cd(2);
	break;
      case 3:
	latex_name << "2-3 GeV/c";
	cfname << "CF_c"<<cbin.str()<<"_p1_h2";
	jfname << "JF_c"<<cbin.str()<<"_p1_h2";
	dirname << "DIR_JF_c"<<cbin.str()<<"_p1_h2";
	can[1]->cd(3);
	break;
      case 5:
	latex_name << "3-5 GeV/c";
	cfname << "CF_c"<<cbin.str()<<"_p1_h3";
	jfname << "JF_c"<<cbin.str()<<"_p1_h3";
	dirname << "DIR_JF_c"<<cbin.str()<<"_p1_h3";
	can[1]->cd(4);
	break;
	
      case 0:
	latex_name << "5-7 GeV/c";
        cfname << "CF_c"<<cbin.str()<<"_p1_h4";
	jfname << "JF_c"<<cbin.str()<<"_p1_h4";
	dirname << "DIR_JF_c"<<cbin.str()<<"_p1_h4";
	can[1]->cd(5);
	break;
	
      }
      break;

    case 9:
      cout<<"photon case 9"<<endl;
      latex_name.str("");
      latex_name << "9-12 #times ";
      switch(hadron_bin){
      case 1:
	latex_name << "0.5-1 GeV/c";
	cfname << "CF_c"<<cbin.str()<<"_p2_h0";
	jfname << "JF_c"<<cbin.str()<<"_p2_h0";
	dirname << "DIR_JF_c"<<cbin.str()<<"_p2_h0";
	can[2]->cd(1);
	break;
      case 2:
	latex_name << "1-2 GeV/c";
	cfname << "CF_c"<<cbin.str()<<"_p2_h1";
	jfname << "JF_c"<<cbin.str()<<"_p2_h1";
	dirname << "DIR_JF_c"<<cbin.str()<<"_p2_h1";
	can[2]->cd(2);
	break;
      case 3:
	latex_name << "2-3 GeV/c";
	cfname << "CF_c"<<cbin.str()<<"_p2_h2";
	jfname << "JF_c"<<cbin.str()<<"_p2_h2";
	dirname << "DIR_JF_c"<<cbin.str()<<"_p2_h2";
	can[2]->cd(3);
	break;
      case 5:
	latex_name << "3-5 GeV/c";
	cfname << "CF_c"<<cbin.str()<<"_p2_h3";
	jfname << "JF_c"<<cbin.str()<<"_p2_h3";
	dirname << "DIR_JF_c"<<cbin.str()<<"_p2_h3";
	can[2]->cd(4);
	break;
	
      case 0:
	latex_name << "5-7 GeV/c";
	cfname << "CF_c"<<cbin.str()<<"_p2_h4";
	jfname << "JF_c"<<cbin.str()<<"_p2_h4";
	dirname << "DIR_JF_c"<<cbin.str()<<"_p2_h4";
	can[2]->cd(5);
	break;
	
      }
      break;

    case 1:
      cout<<"photon case 12"<<endl;
      latex_name.str("");
      latex_name << "12-15 #times ";
      switch(hadron_bin){
      case 1:
	latex_name << "0.5-1 GeV/c";
	cfname << "CF_c"<<cbin.str()<<"_p3_h0";
	jfname << "JF_c"<<cbin.str()<<"_p3_h0";
	dirname << "DIR_JF_c"<<cbin.str()<<"_p3_h0";
	can[3]->cd(1);
	break;
      case 2:
	latex_name << "1-2 GeV/c";
	cfname << "CF_c"<<cbin.str()<<"_p3_h1";
	jfname << "JF_c"<<cbin.str()<<"_p3_h1";
	dirname << "DIR_JF_c"<<cbin.str()<<"_p3_h1";
	can[3]->cd(2);
	break;
      case 3:
	latex_name << "2-3 GeV/c";
	cfname << "CF_c"<<cbin.str()<<"_p3_h2";
	jfname << "JF_c"<<cbin.str()<<"_p3_h2";
	dirname << "DIR_JF_c"<<cbin.str()<<"_p3_h2";
	can[3]->cd(3);
	break;
      case 5:
	latex_name << "3-5 GeV/c";
	cfname << "CF_c"<<cbin.str()<<"_p3_h3";
	jfname << "JF_c"<<cbin.str()<<"_p3_h3";
	dirname << "DIR_JF_c"<<cbin.str()<<"_p3_h3";
	can[3]->cd(4);
	break;
	
      case 0:
	latex_name << "5-7 GeV/c";
	cfname << "CF_c"<<cbin.str()<<"_p3_h4";
	jfname << "JF_c"<<cbin.str()<<"_p3_h4";
	dirname << "DIR_JF_c"<<cbin.str()<<"_p3_h4";
        can[3]->cd(5);
	break;
	
      }
      break;
    default:
      cout << "no such photon bin!" << endl;
    }

    TFile* file = new TFile(file_string.c_str());
    if (! file->IsOpen() ) {
      cout << "cannot open file '" << file_string << "'\n";
      continue;
    }
    cout<<"f11 CF: "<<cfname.str().c_str()<<endl;
    cout<<"f11 JF: "<<jfname.str().c_str()<<endl;
    cout<<"f11 DIR: "<<dirname.str().c_str()<<endl;
    cout<<"f10: "<<file_string.c_str()<<endl;

    if(isjf){
      if(type==3) my_corr = new TH1D (*(TH1D*)f11->Get(dirname.str().c_str()));
      else my_corr = new TH1D (*(TH1D*)f11->Get(jfname.str().c_str()));
      if(type == 0) corr = new TH1D (*(TH1D*)file->Get("JF_INC"));
      if(type == 1) corr = new TH1D (*(TH1D*)file->Get("JF_PI0"));
      if(type == 2) corr = new TH1D (*(TH1D*)file->Get("JF_DEC"));
      if(type == 3) corr = new TH1D (*(TH1D*)file->Get("JF_DIR"));
    }
    else{
       my_corr = new TH1D (*(TH1D*)f11->Get(cfname.str().c_str()));
      if(type == 0) corr = new TH1D (*(TH1D*)file->Get("hDPHI_INC"));
      if(type == 1) corr = new TH1D (*(TH1D*)file->Get("hDPHI_PI0"));
      if(type == 2) corr = new TH1D (*(TH1D*)file->Get("hDPHI_DEC"));
    }
    
    int nReb;
    if(photon_bin == 5) nReb = 3;
    else if(photon_bin == 7) nReb = 5;
    else nReb = 6;
    corr->Rebin(nReb);
    my_corr->Rebin(nReb);
    
    // if(!isjf){
      double my_R = my_corr->Integral("width")/PI;
      cout<<"my_R = "<<my_R<<endl;
      my_corr->Scale(1./my_R);
      double R = corr->Integral("width")/PI;
      cout<<"R = "<<R<<endl;
      //corr->Sumw2();
      cout<<"my_R/R = "<<my_R/R<<endl;
      corr->Scale(1./R);
      //   }
    
    corr->SetMarkerStyle(20);
    corr->SetMarkerSize(0.8);
    my_corr->SetMarkerColor(1);
    my_corr->SetLineColor(1);
    if(isjf){
      double ymin = corr->GetMinimum();
      double ymax = corr->GetMaximum();
      if(my_corr->GetMaximum() > ymax) ymax = my_corr->GetMaximum();
      if(my_corr->GetMinimum() < ymin) ymin = my_corr->GetMinimum();
      corr->SetAxisRange(ymin-0.01, 1.2*ymax,"Y");
    }
    corr->GetYaxis()->SetTitleOffset(1.9);
    corr->Draw();
    my_corr->Draw("same");

    TLegend *l1 = new TLegend(0.7,0.7,0.9,0.9,"","brNDC");
    l1->AddEntry(my_corr,"Run11","lpf");
    l1->AddEntry(corr,"Run10","lpf");
    if(hadron_bin==0) l1->Draw("same");

    TLatex *la = new TLatex(0.3, 0.75, latex_name.str().c_str());
    la->SetNDC();
    la->Draw("same"); 
      
    string pbin_string = cfname.str().substr(7,1);
    string hbin_string = cfname.str().substr(10,1);
    if(pbin_string.compare("0") == 0){
      if(hbin_string.compare("0") == 0) can_ratio[0]->cd(1);
      if(hbin_string.compare("1") == 0) can_ratio[0]->cd(2);
      if(hbin_string.compare("2") == 0) can_ratio[0]->cd(3);
      if(hbin_string.compare("3") == 0) can_ratio[0]->cd(4);
      if(hbin_string.compare("4") == 0) can_ratio[0]->cd(5);
    }
    if(pbin_string.compare("1") == 0){
      if(hbin_string.compare("0") == 0) can_ratio[1]->cd(1);
      if(hbin_string.compare("1") == 0) can_ratio[1]->cd(2);
      if(hbin_string.compare("2") == 0) can_ratio[1]->cd(3);
      if(hbin_string.compare("3") == 0) can_ratio[1]->cd(4);
      if(hbin_string.compare("4") == 0) can_ratio[1]->cd(5);
    }
    if(pbin_string.compare("2") == 0){
      if(hbin_string.compare("0") == 0) can_ratio[2]->cd(1);
      if(hbin_string.compare("1") == 0) can_ratio[2]->cd(2);
      if(hbin_string.compare("2") == 0) can_ratio[2]->cd(3);
      if(hbin_string.compare("3") == 0) can_ratio[2]->cd(4);
      if(hbin_string.compare("4") == 0) can_ratio[2]->cd(5);
    }
    if(pbin_string.compare("3") == 0){
      if(hbin_string.compare("0") == 0) can_ratio[3]->cd(1);
      if(hbin_string.compare("1") == 0) can_ratio[3]->cd(2);
      if(hbin_string.compare("2") == 0) can_ratio[3]->cd(3);
      if(hbin_string.compare("3") == 0) can_ratio[3]->cd(4);
      if(hbin_string.compare("4") == 0) can_ratio[3]->cd(5);
    }
    if(isjf) ratio_name = "ratio_" + jfname.str();
    else ratio_name = "ratio_" + cfname.str();
    ratio = new TH1D (*(TH1D*)my_corr);
    ratio->SetName(ratio_name.c_str());
    cout<<"before dividing"<<endl;
    ratio->Divide(corr);
    if(isjf) ratio->SetAxisRange(-3.0, 5.0, "Y");
    ratio->Draw();
    la->Draw("same"); 

    if(isjf){ 
      ratio_name = "ratio_fit_" + jfname.str();
      /*  
      ratio_fit = new TF1(ratio_name.c_str(),"pol0(0)");
      ratio->Fit(ratio_name.c_str(),"BQ");
      double fitconst = Round(ratio_fit->GetParameter(0));
      bin.str("");
      bin << "ratio #approx "<<fitconst;
      TLatex *la_const = new TLatex(0.6, 0.25, bin.str().c_str());
      la_const->SetNDC();
      la_const->Draw("same");
      double fit_chi2 = ratio_fit->GetChisquare();
      int fit_ndf = ratio_fit->GetNDF();
      double chi2 = Round(fit_chi2/fit_ndf);      
      bin.str("");
      bin << "#chi^{2} = "<<chi2;
      TLatex *la_chi2 = new TLatex(0.6, 0.2, bin.str().c_str());
      la_chi2->SetNDC();
      la_chi2->Draw("same");
      */
    }
       
    //        if(!isjf){         
      //Do a chisquare test for CF comparison.
    double prob = 0; double t = 0; double chi2 = 0;
    double nbins = (double)corr->GetNbinsX();
    double ncounts1 = my_corr->GetEntries();
    double ncounts2 = corr->GetEntries();
    double var1 = 0; double var2 = 0;
    double mean1 = 0; double mean2 = 0;
    double sumw7 = 0;  double sumw10 = 0;
    
    my_corr->IntegralAndError(1,nbins,sumw7);
    my_corr->IntegralAndError(1,nbins,sumw10);
    for( int ib = 1; ib <= nbins; ib++ )
      {
	double err1 = my_corr->GetBinError(ib);
	mean1 += my_corr->GetBinContent(ib);
	double err2 = corr->GetBinError(ib);
	mean2 += corr->GetBinContent(ib);
	chi2 += GetChiSquare(my_corr->GetBinContent(ib),corr->GetBinContent(ib),err1,err2);
	var1 += err1*err1;
	var2 += err2*err2;
      }
    std::cout << std::endl;
    std::cout << "t-test for " << ncounts1 << "," << ncounts2 << " counts with means of " << mean1/nbins << "," << mean2/nbins << " and uncertainties of " <<  sqrt(var1) << "," << sqrt(var2) << std::endl;
    //var1 += pow(JF_INC_run7->GetMeanError(),2);
    //var2 += pow(JF_INC_run10->GetMeanError(),2);

    DoTtest(nbins,nbins,mean1/nbins,mean2/nbins,sqrt(var1),sqrt(var2),t,prob);
    ttest_CF->Fill(t);
    tprob_CF->Fill(prob);

    double cprob = GetChiSquareProb(nbins,chi2);
    double reducedchi2 = chi2/nbins;
    cout<<"reducedchi2 = "<<reducedchi2<<endl;

    reducedchi2 = Round(reducedchi2);
    cout<<reducedchi2<<endl;
    cprob = Round(cprob);

    latex_name.str("");
    latex_name << "#chi^{2} = "<<reducedchi2;
    TLatex *la_chi2 = new TLatex(0.6, 0.2, latex_name.str().c_str());
    la_chi2->SetNDC();
    la_chi2->Draw("same");
    latex_name.str("");
    latex_name << "p = "<<cprob;
    TLatex *la_cprob = new TLatex(0.6, 0.15, latex_name.str().c_str());
    la_cprob->SetNDC();
    la_cprob->Draw("same");
    
    chitest_CF->Fill(chi2/nbins);
    chiprob_CF->Fill(cprob);
    //        }
    
  }
  
  
 
  foutput->cd();
  for(int i=0; i<4; i++){
    can[i]->Write();
    can_ratio[i]->Write();
  }
    
  if(!isjf){
    ttest_CF->Write();
    tprob_CF->Write();
    chitest_CF->Write();
    chiprob_CF->Write();
  }
  
  
  cout<<"finish writing out."<<endl;
  return 0;
}