std::pair<float,float> getFitRange(TH1D& hist) {
  int maxBin = hist.GetMaximumBin();
  float targetVal = hist.GetBinContent( maxBin ) /2.;


  int nBins = hist.GetNbinsX();
  
  std::pair<float,float> results = {hist.GetBinLowEdge(1),hist.GetBinLowEdge(nBins+1)};

  int diff=0;
  while( maxBin-(++diff) >0) {
    if( hist.GetBinContent(maxBin-diff) < targetVal ){
      results.first = hist.GetBinCenter(maxBin-diff);
      break;
    }
  }

  diff=0;
  while( maxBin+(++diff) <=nBins) {
    if( hist.GetBinContent(maxBin+diff) < targetVal ){
      results.second = hist.GetBinCenter(maxBin+diff);
      break;
    }
  }
  
  
  return results;
}
TH1D* ratio_hist_to_func(TH1D* num, double par0, double par1, double par2) {
    cout<<"[Ratio to fit used]"<<endl;

    TH1D *hRatio = (TH1D*) num->Clone("hRatio");

    TF1 *f3 = new TF1("f3","[0]*(1+(sqrt(0.1396**2+x**2)-0.1396)/([1]*[2]))**(-[2])",0,6.5);
    f3->SetParameters(par0,par1,par2);
    //f3->SetLineColor(2);

    int nbin = num->GetEntries();
    for(int i=0; i<nbin; i++) {

        double cms_value = (double) f3->Eval(hRatio->GetBinCenter(i+1));

        if(hRatio->GetBinCenter(i+1)>0.4 && hRatio->GetBinCenter(i+1)<6.0) {
            //double ratio = cms_value/hRatio->GetBinContent(i+1);
            //double ratio_err = cms_value/hRatio->GetBinError(i+1);
            double ratio = hRatio->GetBinContent(i+1)/cms_value;
            double ratio_err = hRatio->GetBinError(i+1)/cms_value;
        } else {
            double ratio = -999;
            double ratio_err = 0.0;
        }
        //double ratio = hRatio->GetBinContent(i+1)/cms_value;
        //double ratio_err = hRatio->GetBinError(i+1)/cms_value;
        hRatio->SetBinContent(i+1,ratio);
        hRatio->SetBinError(i+1,ratio_err);
    }

    return hRatio;

}
Esempio n. 3
0
void testIntegration(){
	
	
	
	TFile* infile = new TFile("/Users/keithlandry/Desktop/testPtHist.root");

	TH1D * h = infile->Get("Pt");
	
	
	int bmin = 751;
	int bmax = bmin+1;
	
  double binval = 0;
	int numberOfPairs = 0;
	
	cout << "starting at bmin = " << bmin << "  bmax = " << bmax << endl;
	
	cout << (double)h->GetEntries()/9.0 << endl;
	
	for (int i=0; i < h->GetNbinsX()-bmin; i++)
	{
		bmax++;

		cout << " i = " << i << " bmax = " << bmax << endl;
		
		int integ = h->Integral(bmin,bmax);
		
		cout << bmax << "   " << integ << endl;
		
		binval += h->GetBinContent(bmax)*h->GetBinCenter(bmax);
		numberOfPairs += h->GetBinContent(bmax);

		if (integ > (double)h->GetEntries()/9.0)
		{
			cout << bmax << "   " << integ << endl;
			lastI = i;
			break;
		}
		
		if (bmax == 1000)
		{
			break;
		}
		
		
	}
	
	
	cout << "avg val of bin " << (double)binval/numberOfPairs << endl;
	
	cout << " Pt = " << h->GetBinCenter(bmax) << endl;
	
	
	
}
Esempio n. 4
0
TH1D *
GetITSsaSpectrum(TFile *file, Int_t part, Int_t charge, Int_t cent, Bool_t cutSpectrum = kTRUE, Bool_t addSystematicError = kTRUE)
{
  /* pt limits for combined spectra */
  Double_t ptMin[AliPID::kSPECIES] = {0., 0., 0.1, 0.2, 0.3};
  Double_t ptMax[AliPID::kSPECIES] = {0., 0., 0.6, 0.5, 0.6};

  TList *list = (TList *)file->Get("output");
  TH1D *hin = (TH1D *)list->FindObject(Form("h_%s_%s_cen_%d", ITSsaPartName[part], ITSsaChargeName[charge], cent));
  if (!hin) return NULL;  

  /* get systematics */
  TFile *fsys = TFile::Open("SPECTRASYS_ITSsa.root");
  TH1 *hsys = fsys->Get(Form("hSystTot%s%s", ITSsaChargeName[charge], ITSsaPartName[part]));
			
  TH1D *h = new TH1D(Form("hITSsa_cent%d_%s_%s", cent, AliPID::ParticleName(part), chargeName[charge]), "ITSsa", NptBins, ptBin);
  Double_t pt, width, value, error, sys;
  Int_t bin;
  for (Int_t ipt = 0; ipt < NptBins; ipt++) {
    /* get input bin */
    pt = h->GetBinCenter(ipt + 1);
    width = h->GetBinWidth(ipt + 1);
    bin = hin->FindBin(pt);
    /* sanity check */
    if (TMath::Abs(hin->GetBinCenter(bin) - pt) > 0.001 ||
	TMath::Abs(hin->GetBinWidth(bin) - width) > 0.001)
      continue;
    /* check pt limits */
    if (cutSpectrum && (pt < ptMin[part] || pt > ptMax[part])) continue;
    /* copy bin */
    value = hin->GetBinContent(bin);
    error = hin->GetBinError(bin);
    /*** TEMP ADD SYS ***/
    if (addSystematicError) {
      sys = hsys->GetBinContent(bin) * value;
      error = TMath::Sqrt(error * error + sys * sys);
    }
    h->SetBinContent(ipt + 1, value);
    h->SetBinError(ipt + 1, error);
  }

  h->SetTitle("ITSsa");
  h->SetLineWidth(1);
  h->SetLineColor(1);
  h->SetMarkerStyle(20);
  h->SetMarkerColor(1);
  h->SetFillStyle(0);
  h->SetFillColor(0);

  return h;
}
Esempio n. 5
0
TH1D *
GetITSTPCSpectrum(TFile *file, Int_t part, Int_t charge, Int_t cent)
{
  TList *list = (TList *)file->Get("output");
  TH1D *hin = (TH1D *)list->FindObject(Form("h_%s_%s_cen_%d", ITSTPCPartName[part], ITSTPCChargeName[charge], cent + 1));
  if (!hin) return NULL;

  TH1D *h = new TH1D(Form("hITSTPC_cent%d_%s_%s", cent, AliPID::ParticleName(part), chargeName[charge]), "ITSTPC", NptBins, ptBin);
  Double_t pt, width, value, error;
  Int_t bin;
  for (Int_t ipt = 0; ipt < NptBins; ipt++) {
    /* get input bin */
    pt = h->GetBinCenter(ipt + 1);
    width = h->GetBinWidth(ipt + 1);
    bin = hin->FindBin(pt);
    /* sanity check */
    if (TMath::Abs(hin->GetBinCenter(bin) - pt) > 0.001 ||
	TMath::Abs(hin->GetBinWidth(bin) - width) > 0.001)
      continue;
    /* copy bin */
    value = hin->GetBinContent(bin);
    error = hin->GetBinError(bin);
    h->SetBinContent(ipt + 1, value);
    h->SetBinError(ipt + 1, error);
  }
  
#if 0
  /* add systematic error */
  Double_t sys;
  if (part == 2) sys = 0.5;
  else sys = 0.1;
  Double_t cont, conte;
  for (Int_t ipt = 0; ipt < h->GetNbinsX(); ipt++) {
    cont = h->GetBinContent(ipt + 1);
    conte = h->GetBinError(ipt + 1);
    conte = TMath::Sqrt(conte * conte + sys * sys * cont * cont);
    h->SetBinError(ipt + 1, conte);
  }
#endif
  
  h->SetTitle("ITSTPC");
  h->SetLineWidth(1);
  h->SetLineColor(1);
  h->SetMarkerStyle(21);
  h->SetMarkerColor(2);
  h->SetFillStyle(0);
  h->SetFillColor(0);
  return h;
}
void createSysStatErrorHist(TH1D *hist_pre){

  TH1D *histErr = (TH1D*) hist_pre->Clone("histErr");
  hsyserr = (TH1D*) hist_pre->Clone("hsyserr"), hsyserr->Reset();
  hsyserr->Sumw2();

  cout<<""<<endl;
  for(int i=0;i<histErr->GetNbinsX();i++){ // last bin is meaningless
    double pt = histErr->GetBinCenter(i+1);
    double statferr = histErr->GetBinError(i+1)/histErr->GetBinContent(i+1);
    if(i==(histErr->GetNbinsX()-1)) statferr = 0.9;
    //double sysferr = fsyserr->Eval(pt);
    double sysferr = returnCombinedSysError(pt);
    double sumferr = sqrt(statferr*statferr + sysferr*sysferr);
    //double sumerr = 1.*(sumferr/100);
    double sumerr = 1.*sumferr;
    hsyserr->SetBinContent(i+1,1);
    hsyserr->SetBinError(i+1,sumerr);
    //hsyserr->SetBinError(i+1,0.5); 
    cout<<"[setSysStatError] stat err (frac): "<<statferr<<" syst err (fac): "<<sysferr<<" combined (frac): "<<sumferr<<endl;
  }

  //tsyserr = (TGraphErrors*) TgraphIt(hsyserr);

}
Esempio n. 7
0
TH2D* GetJetCorrFunc2D_ZYAM(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.35,1.57,"X");
                      double histminX = hcorrphi->GetBinCenter(hcorrphi->GetMinimumBin());
                      double histminY = hcorrphi->GetBinContent(hcorrphi->GetMinimumBin());
	   	      fitfunc = new TF1(Form("fitfunc_%d",ietabin),"[0]+[1]*(x-[2])*(x-[2])",0.6,1.2);		    
                      fitfunc->SetParameters(histminY,1,histminX);
                      fitfunc->SetParLimits(1,0,0.10000);
                  //    fitfunc->SetParLimits(2,0.35,1.57);
		      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);
		    }
                    
                    float max = hcorr_clone->GetBinContent(hcorr_clone->GetMaximumBin());
                    hcorr_clone->SetAxisRange(ymin,max*1.3,"Z");		    
                    return hcorr_clone;
}
Esempio n. 8
0
void compare(){

  TFile *fileJian=new TFile("InputsPurdue/PromptRAA_D0_PbPb_spectrum_fonll_effunpre_cent0to100_ptbin12_y1_dataplusfonll.root");
  TFile *fileRawJian=new TFile("InputsPurdue/Dspectrum_pbpb_data_ptbin_14_ptd_unpreMBtrig_0_cent0to100_y1.root");
  TH1D *hspectrumJian = (TH1D*)fileJian->Get("D0_pbpb_spectrum");
  TH1D *rawJian = (TH1D*)fileRawJian->Get("N_mb_expobkg_count");

  hspectrumJian->Scale(5.67*1e-9);
  
  TFile *fileMIT=new TFile("InputsMIT/alphaD0.root");
  TH1D *hspectrumMIT = (TH1D*)fileMIT->Get("hPtCor");
  TH1D *hrawMIT = (TH1D*)fileMIT->Get("hPt");
  hspectrumMIT->Scale(0.90*1./(2*0.0388*3.01781340000000000e+07));
  
  TCanvas*c=new TCanvas("c","",500,500);
  c->cd();
  c->SetLogy();
  hspectrumMIT->Draw();
  hspectrumMIT->SetLineWidth(4);
  hspectrumJian->Draw("same");
  
  
  
  
  TFile*fEffJian=new TFile("InputsPurdue/D0_PbPb_acc_eff_ptbin_14_ybin_6_prompt_FONLLweight_cent-0to100_dataptshape_y1_Ncollweight1.root");
  TH1D *EffJian = (TH1D*)fEffJian->Get("d0accxeff_pt");
  TH1D *EffMIT = (TH1D*)fileMIT->Get("hEff");
  
  cout<<"bin center MIT"<<EffMIT->GetBinCenter(1)<<"GeV, efficiency="<<EffMIT->GetBinContent(1)<<endl; 
  cout<<"bin center Jian"<<EffJian->GetBinCenter(4)<<"GeV, efficiency="<<EffJian->GetBinContent(4)<<endl; 
  cout<<"bin center MIT"<<hrawMIT->GetBinCenter(1)<<"GeV, raws="<<hrawMIT->GetBinContent(1)<<endl; 
  cout<<"bin center Jian"<<rawJian->GetBinCenter(4)<<"GeV, raws="<<rawJian->GetBinContent(4)<<endl; 
  cout<<"*************"<<endl;
  cout<<"bin center MIT"<<EffMIT->GetBinCenter(7)<<"GeV, efficiency="<<EffMIT->GetBinContent(7)<<endl; 
  cout<<"bin center Jian"<<EffJian->GetBinCenter(10)<<"GeV, efficiency="<<EffJian->GetBinContent(10)<<endl; 
  cout<<"bin center MIT"<<hrawMIT->GetBinCenter(7)<<"GeV, raws="<<hrawMIT->GetBinContent(7)<<endl; 
  cout<<"bin center Jian"<<rawJian->GetBinCenter(10)<<"GeV, raws="<<rawJian->GetBinContent(10)<<endl; 
  
  
  for (int i=1;i<11;i++){
  cout<<"pt centre="<<EffJian->GetBinCenter(i+3)<<",value="<<hspectrumMIT->GetBinContent(i)/hspectrumJian->GetBinContent(i+3)<<endl;
  
  
  
  
  }

  
  

}
//################################################################################################################################
 // Get the 68% confindence interval of mu1/mu2
void getPoissonIntervalls(double mu1, double mu2){

  double result = mu1/mu2;
  TH1D *expHist = new TH1D("mu1/mu2","mu1/mu2",1000,0,1);
  TRandom3 rand1(0);
  TRandom3 rand2(0);

  cout<<"mu1 = "<<mu1<<endl;
  cout<<"mu2 = "<<mu2<<endl;
  cout<<"ratio = "<<result<<endl;

  for(int i=0; i<10000000; i++){

    expHist->Fill(1.*rand1.Poisson(mu1)/rand2.Poisson(mu2));
  }

  // Get now the 68% upper and lower interval
  double errUp  = 0;
  double errLow = 0;
  for(int i=1; i<=expHist->GetNbinsX();i++){

    double upperIntegral = expHist->Integral(i,expHist->GetNbinsX());
    double lowerIntegral = expHist->Integral(1,i);

    if(abs(upperIntegral/expHist->Integral()-0.32)<0.02){
      cout<<"upper bound = "<<expHist->GetBinCenter(i)<<endl;
      errUp = expHist->GetBinCenter(i)-result;
    }
    if(abs(lowerIntegral/expHist->Integral()-0.32)<0.02){
      cout<<"lower bound = "<<expHist->GetBinCenter(i)<<endl;
      errLow = result - expHist->GetBinCenter(i);
    }
  }


  cout<<"error Up = "<<errUp<<endl;
  cout<<"error Low = "<<errLow<<endl;

  TCanvas *c = new TCanvas("cExp","cExp",0,0,500,500);
  c->cd();
  expHist->Draw();
}    
Esempio n. 10
0
TH1D *
GetTPCTOFSpectrum(TFile *file, Int_t part, Int_t charge, Int_t cent, Bool_t cutSpectrum = kTRUE)
{
  /* pt limits for combined spectra */
  Double_t ptMin[AliPID::kSPECIES] = {0., 0., 0., 0., 0.};
  Double_t ptMax[AliPID::kSPECIES] = {0., 0., 1.2, 1.2, 1.8};

  TH1D *hin = (TH1D *)file->Get(Form("%sFinal%s%d", TPCTOFPartName[part], TPCTOFChargeName[charge], cent));
  if (!hin) return NULL;

  TH1D *h = new TH1D(Form("hTPCTOF_cent%d_%s_%s", cent, AliPID::ParticleName(part), chargeName[charge]), "TPCTOF", NptBins, ptBin);
  Double_t pt, width, value, error;
  Int_t bin;
  for (Int_t ipt = 0; ipt < NptBins; ipt++) {
    /* get input bin */
    pt = h->GetBinCenter(ipt + 1);
    width = h->GetBinWidth(ipt + 1);
    bin = hin->FindBin(pt);
    /* sanity check */
    if (TMath::Abs(hin->GetBinCenter(bin) - pt) > 0.001 ||
	TMath::Abs(hin->GetBinWidth(bin) - width) > 0.001)
      continue;
    /* check pt limits */
    if (cutSpectrum && (pt < ptMin[part] || pt > ptMax[part])) continue;
    /* copy bin */
    value = hin->GetBinContent(bin);
    error = hin->GetBinError(bin);
    h->SetBinContent(ipt + 1, value);
    h->SetBinError(ipt + 1, error);
  }
  
  h->SetTitle("TPCTOF");
  h->SetLineWidth(1);
  h->SetLineColor(1);
  h->SetMarkerStyle(22);
  h->SetMarkerColor(8);
  h->SetFillStyle(0);
  h->SetFillColor(0);
  
  return h;
}
Esempio n. 11
0
void getMeanPtBins( Double_t * binArr, TF1* func) {
  Double_t atlas_Bin[nAtlasBin+1] = {8, 9.5, 11.5, 14, 20, 30};
  
  TH1D* firhist = (TH1D*)func->GetHistogram();
  for ( int i=1 ; i<= nAtlasBin ; i++) {
    float lowPtCut = atlas_Bin[i-1];
    float highPtCut = atlas_Bin[i];
    
    TH1D* tempHist = (TH1D*)firhist->Clone("tempHist");
    for ( int xbin = 1 ;xbin<=tempHist->GetNbinsX() ; xbin++) {
      if ( (tempHist->GetBinCenter(xbin) > highPtCut) || (tempHist->GetBinCenter(xbin) < lowPtCut) \
	   )
      tempHist->SetBinContent(xbin,0);
    }
    float meanPt = tempHist->GetMean();
    cout << " meanPt = " << meanPt << endl;
    binArr[i-1] = meanPt;
    delete tempHist;
    
  }
  
}
void getMeanPtBins( Double_t * binArr, TF1* func) {
  Double_t lhcb_Bin[nLHCbBin+1] = {0,1,2,3,4,5,6,7,14};
  
  TH1D* firhist = (TH1D*)func->GetHistogram();
  for ( int i=1 ; i<= nLHCbBin ; i++) {
    float lowPtCut = lhcb_Bin[i-1];
    float highPtCut = lhcb_Bin[i];

    TH1D* tempHist = (TH1D*)firhist->Clone("tempHist");
    for ( int xbin = 1 ;xbin<=tempHist->GetNbinsX() ; xbin++) {
      if ( (tempHist->GetBinCenter(xbin) > highPtCut) || (tempHist->GetBinCenter(xbin) < lowPtCut) )
	tempHist->SetBinContent(xbin,0);
    }
    float meanPt = tempHist->GetMean();
    if ( meanPt <0.1 )   // fit is not applied
      meanPt = (lowPtCut+highPtCut)/2.;

    cout << " meanPt = " << meanPt << endl;
    binArr[i-1] = meanPt;
    delete tempHist;

  }

}
Esempio n. 13
0
/** Personalized
build a TGraphError starting from a TH1F
*/
TGraphErrors buildGEfromH_Personalized (const TH1D & histo) 
{
 TVectorF xV(histo.GetNbinsX());
 TVectorF yV(histo.GetNbinsX());
 TVectorF errxV(histo.GetNbinsX());
 TVectorF erryV(histo.GetNbinsX());
 for (int iBin = 0; iBin<histo.GetNbinsX(); iBin++){
  xV[iBin] = histo.GetBinCenter(iBin);
  yV[iBin] = histo.GetBinContent(iBin);
  errxV[iBin] = 0;
//   histo.GetBinWidth(iBin);
  erryV[iBin] = histo.GetBinError(iBin);
 }  
 TGraphErrors g (xV, yV, errxV, erryV) ;
 return g ;
}
void writeDataBackgroundHistosForModel(const std::map<TString,TGraph*>& m_bkgds,
				       const std::vector<TH1D *>& vchans,
				       TFile  *allHistFile)
{
  for (std::map<TString,TGraph*>::const_iterator it = m_bkgds.begin();
       it != m_bkgds.end();
       it++) {
    const TString& name = it->first;

    // determine binning from the signal histogram for this channel
    // - (sigh) have to find it first...
    //
    TString channame = name.Copy().Remove(0,strlen("Bckgrndtot_"));
    TH1D *sigh=(TH1D*)0;
    for (int ichan=0; ichan<NUMCHAN; ichan++) {
      sigh = vchans.at(ichan);
      if (strstr(sigh->GetName(),channame.Data()))
	break;
    }
    assert (sigh);


    // for variable binning - all histos must have the same binning per channel
    TAxis *xax = sigh->GetXaxis();

    TVectorD xbins   = TVectorD(sigh->GetNbinsX(),xax->GetXbins()->GetArray());

    int lobin = xax->FindFixBin(sumwinmin);
    int hibin = xax->FindFixBin(sumwinmax)-1;
    int nbins = hibin-lobin+1;

    TVectorD xwindow = xbins.GetSub(lobin-1,hibin);
    
    printf("Booking TH1D(%s,%s,%d,xwindowarray)\n",
	   name.Data(),name.Data(),nbins);
    TH1D *h = new TH1D(name.Data(),name.Data(),nbins,xwindow.GetMatrixArray());

    for (int ibin=1; ibin <= nbins; ibin++)
      h->SetBinContent(ibin,
		       it->second->Eval(h->GetBinCenter(ibin))
		       * h->GetBinWidth(ibin)
		       );

    allHistFile->WriteTObject(h);
  }

}                                            //  writeDataBackgroundHistosForModel
Esempio n. 15
0
void poiss()
{
  TF1* func = new TF1("func","TMath::Poisson(x,0.06)",0,10);
  TH1D* h = new TH1D("h",";# of collisions",11,-0.5,10.5);
  for(int i=1;i<=11;i++) h->SetBinContent(i,func->Eval(h->GetBinCenter(i)));

  TCanvas* c = new TCanvas("c","c",550,500);
  c->SetLogy();
  h->GetXaxis()->CenterTitle();
  h->Draw("hist");

  TLatex* latex = new TLatex();
  latex->SetNDC();
  latex->SetTextSize(latex->GetTextSize()*0.75);
  latex->DrawLatex(0.43,0.87,"Poisson distribution, <#mu>=6%");

  SaveCanvas(c,"pPb/corr","Poisson_mu6");
}
Esempio n. 16
0
TF1* GetFitFunc_ZYAM_pp(TH1D* h)
{
                    TH1D* hcorrphi = (TH1D*)h->Clone(h->GetName());
//                    double histminY = hcorrphi->GetBinContent(hcorrphi->GetMinimumBin());
//                    double histminX = hcorrphi->GetBinCenter(hcorrphi->GetMinimumBin());
                    double histminY = hcorrphi->GetBinContent(hcorrphi->FindBin(1.2));
                    double histminX = hcorrphi->GetBinCenter(hcorrphi->FindBin(1.2));

                    //hcorrphi->SetAxisRange(-0.01,1.2,"X");
                    TF1* fitfunc = new TF1(Form("fitfunc_%s",h->GetName()),"[0]+[1]*(x-[2])*(x-[2])+[3]*abs((x-[2])*(x-[2])*(x-[2]))",0.5,2.5); //std 0.6 1.55 vs pT ; 0.6 1.8 vs eta
                    fitfunc->SetParameters(histminY,0.002,histminX,0.0);
                    fitfunc->SetParLimits(1,0,1000);
                    fitfunc->SetParLimits(2,0.2,2.0);
                   // fitfunc->SetParLimits(3,0,100);
                    fitfunc->FixParameter(3,0);

                    for(int ifit=0;ifit<3;ifit++) hcorrphi->Fit(Form("fitfunc_%s",h->GetName()),"NO","",histminX-0.6,histminX+0.6);
                    fitfunc->SetName(Form("fitfunc_%s_%.3f",h->GetName(),fitfunc->GetParameter(0)));
                    return fitfunc;
}
Esempio n. 17
0
void sinFittingTest(){


	double PI = 3.14159265359;
	int bins = 16;
	
	TH1D* hSin = new TH1D("hSin","hSin",bins,-PI,PI);
	
	
	TF1* func = new TF1("func","[0]*sin(x)",-PI*.5,PI*.5);
	
	
	
	

	double amp = 1.5;
	
	
	
	for (int i=0; i<bins; i++)
	{
		
		double binCenter = hSin->GetBinCenter(i+1);
		
		double val = amp*sin(binCenter);
		
		hSin->SetBinContent(i+1, val);
		
	}
		
	
	hSin->Draw();
	
	
	hSin->Fit("func", "R");



}
double CalcChiSqr(TH1D* hist, Double_t coeff, Double_t expo, Int_t xMin, Int_t xMax)
{
  {
    TH1D* myHist = hist->Clone();
    int bins = myHist->GetSize()-2;
    double chiSqr = 0;
    for(int i = xMin+1; i < xMax+1; i++)
      {
	double x = myHist->GetBinCenter(i);
	double o = myHist->GetBinContent(i);
	double e = coeff*(TMath::Power(x,expo));
	//cout << x << "\t" << o << "\t" << e;
	if(o != 0)
	  chiSqr += ((o-e)*(o-e))/o;
	//cout << "\tchiSqr: " << chiSqr << endl;
      }
    return chiSqr/2;
    
  }
  
  
}
Esempio n. 19
0
TH1D *getpuweights(TFile *file, TH1D *target) {
  
  TDirectory *dirmcpv = (TDirectory*)file->FindObjectAny("AnaFwkMod");
  TH1D *hnpu = (TH1D*)dirmcpv->Get("hNPU");
  TH1D *hpumc = (TH1D*)hnpu->Clone();
  
  hpumc->Sumw2();
  hpumc->Scale(1.0/hpumc->Integral(0,hpumc->GetNbinsX()+1));
  
  
  TH1D *htargettmp = new TH1D("htargettmp","", hpumc->GetNbinsX(), hpumc->GetXaxis()->GetXmin(), hpumc->GetXaxis()->GetXmax());
  htargettmp->Sumw2();
  for (int ibin = 0; ibin<=(htargettmp->GetNbinsX()+1); ++ibin) {
    htargettmp->Fill(htargettmp->GetBinCenter(ibin),target->GetBinContent(target->FindFixBin(htargettmp->GetBinCenter(ibin))));
  }
  htargettmp->Scale(1.0/htargettmp->Integral(0,htargettmp->GetNbinsX()+1));
  
  TH1D *puweights = new TH1D((*htargettmp)/(*hpumc));
    
  delete htargettmp;
  
  return puweights;
    
}
void balanceMetVsAj(TString infname = "dj_HCPR-J50U-hiGoodMergedTracks_OfficialSelv2_Final0_120_50.root",
                    TCut myCut = "cent<30", char *title = "",bool drawLegend = false,
                    bool drawSys = true
		    )
{
   // ===========================================================
   // Get Input
   // ===========================================================
   TFile *inf = new TFile(infname);
   TTree *t = (TTree*)inf->Get("ntjt");


   t->SetAlias("metxMergedAll","(metOutOfConex0+metOutOfConex1+metOutOfConex2+metOutOfConex3+metOutOfConex4+metOutOfConex5)");
   t->SetAlias("metxMerged0","(metOutOfConex0)");
   t->SetAlias("metxMerged1","(metOutOfConex1)");
   t->SetAlias("metxMerged2","(metOutOfConex2)");
   t->SetAlias("metxMerged3","(metOutOfConex3)");
   t->SetAlias("metxMerged4","(metOutOfConex4+metOutOfConex5)");

   // ===========================================================
   // Analysis Setup
   // ===========================================================
   const int nBin = 5;
   double bins[nBin+1] = {0.5,1.0,1.5,4,8,1000};
   int colors[5] = {kBlue-10,kYellow-7, kOrange-2,kGreen-5,kRed-3};
   
   const int nBinAj = 4;
   double ajBins[nBinAj+1] = {0.0001,0.11,0.22,0.33,0.49999};
   // Selection cut
   TCut evtCut = "nljet>120&&abs(nljetacorr)<2&&aljet>50&&abs(aljetacorr)<2&&jdphi>2./3*TMath::Pi()&&!maskEvt";
//   TCut evtCut = "nljet>120&&abs(nljetacorr)<2&&aljet>50&&abs(aljetacorr)<2&&jdphi>3&&!maskEvt";

   cout << "Sel evt: " << t->GetEntries(evtCut&&myCut) << endl;

   // ===========================================================
   // Find Average Weights
   // ===========================================================
   TH1D *hw[nBinAj];
   float meanWt[nBinAj];
   for ( int iaj = 0 ; iaj< nBinAj ; iaj++) {
      hw[iaj] = new TH1D(Form("hw_aj%d",iaj),"",1000,0,100);
      TCut ajCut = Form("Aj>%f && Aj<%f", ajBins[iaj],ajBins[iaj+1]);
      t->Draw(Form("weight>>hw_aj%d",iaj), evtCut&&myCut&&ajCut);
      meanWt[iaj] = hw[iaj]->GetMean();
      cout << " <Weight>: " << meanWt[iaj] << endl;
   }

   // ===========================================================
   // Draw Weighted Averages
   // ===========================================================
   TH1D *ppos[nBin];
   TH1D *pneg[nBin];
   TH1D *pe[nBin];
   for (int i=0;i<nBin;i++)
   {
      TH1D *h1 = new TH1D(Form("h1%d",i),"",nBinAj,ajBins);
      TH1D *h2 = new TH1D(Form("h2%d",i),"",nBinAj,ajBins);
      TH1D *he[nBinAj];
      
      // =================================
      // Get Weighted Mean for each Aj bin
      // =================================
      h1->Sumw2();
      h2->Sumw2();
      t->Draw(Form("Aj>>h1%d",i), "weight"*(evtCut&&myCut));
      t->Draw(Form("Aj>>h2%d",i), Form("((-weight*metxMerged%d))",i)*(evtCut&&myCut));
      
      pe[i]=(TH1D*)h2->Clone();
      pe[i]->SetName(Form("p%d",i));     
      pe[i]->Divide(h1);
      ppos[i] = new TH1D(Form("ppos%d",i),"",nBinAj,ajBins);
      ppos[i]->SetLineColor(1);     
      ppos[i]->SetMarkerColor(colors[i]);
      ppos[i]->SetFillColor(colors[i]);
      ppos[i]->SetFillStyle(1001);
      pneg[i] = new TH1D(Form("pneg%d",i),"",nBinAj,ajBins);
      pneg[i]->SetLineColor(1);     
      pneg[i]->SetMarkerColor(colors[i]);
      pneg[i]->SetFillColor(colors[i]);
      pneg[i]->SetFillStyle(1001);

      // =================================
      // Caculated Stat Error of the Mean
      // =================================
      cout << "Stat Error for pt bin " << i << ": ";
      for ( int iaj = 0 ; iaj< nBinAj ; iaj++) {
         he[iaj] = new TH1D(Form("he%d_aj%d",i,iaj),"",100,-200,200);
         TCut ajCut = Form("Aj>%f && Aj<%f", ajBins[iaj],ajBins[iaj+1]);
         t->Draw(Form("((metxMerged%d))>>he%d_aj%d",i,i,iaj), "weight" * evtCut&&myCut&&ajCut);
         float theError = he[iaj]->GetRMS()/ (sqrt(he[iaj]->GetEntries()));
	 cout << theError << " ";
	 pe[i]->SetBinError(iaj+1, theError);
      }
      cout << endl;
   }

   // Stack
   for (int i=nBin-1;i>=0;i--)
   {
      for(int iaj = 0 ; iaj< nBinAj ; iaj++) {
         double posVal=0, negVal=0;
         double posValErr=0, negValErr=0;
         if (i!=nBin-1) {
            posVal = ppos[i+1]->GetBinContent(iaj+1);
            posValErr = ppos[i+1]->GetBinError(iaj+1);
            negVal = pneg[i+1]->GetBinContent(iaj+1);
            negValErr = pneg[i+1]->GetBinError(iaj+1);
         }
         if (pe[i]->GetBinContent(iaj+1)<0) {
            negVal+=pe[i]->GetBinContent(iaj+1);
            negValErr=pe[i]->GetBinError(iaj+1);
            posValErr=0;
         } else if (pe[i]->GetBinContent(iaj+1)>0) {
            posVal+=pe[i]->GetBinContent(iaj+1);
            posValErr=pe[i]->GetBinError(iaj+1);
            negValErr=0;
         } 
         ppos[i]->SetBinContent(iaj+1,posVal);
         ppos[i]->SetBinError(iaj+1,posValErr);
         pneg[i]->SetBinContent(iaj+1,negVal);
         pneg[i]->SetBinError(iaj+1,negValErr);
      }
   }
   
   TH1D *pall;
   TH1D *pallE;
   TH1D *h1 = new TH1D(Form("hAll1"),"",nBinAj,ajBins);
   TH1D *h2 = new TH1D(Form("hAll2"),"",nBinAj,ajBins);

   h1->Sumw2();
   h2->Sumw2();
   t->Draw(Form("Aj>>hAll1"), "weight"*(evtCut&&myCut));
   t->Draw(Form("Aj>>hAll2"), Form("((-weight*metxMergedAll))")*(evtCut&&myCut));
   pall=(TH1D*)h2->Clone();
   pall->SetName("pall");
   pall->Divide(h1);

   // replace the sys error from pallE to pall 
   TH1D *he[nBinAj];
   cout << "Stat Error for All pt: ";
   for ( int iaj = 0 ; iaj< nBinAj ; iaj++) {
      he[iaj] = new TH1D(Form("heAll_aj%d",iaj),"",100,-200,200);
      TCut ajCut = Form("Aj>%f && Aj<%f", ajBins[iaj],ajBins[iaj+1]);
      t->Draw(Form("((metxMergedAll))>>heAll_aj%d",iaj), "weight" * evtCut&&myCut&&ajCut);
      float theError = he[iaj]->GetRMS()/ (sqrt(he[iaj]->GetEntries()));
      cout << theError << " ";
      pall->SetBinError(iaj+1,  theError);
   }
   cout << endl;

   pall->SetXTitle("A_{J}");
   pall->SetYTitle("<#slash{p}_{T}^{#parallel}> (GeV/c)");
   pall->GetXaxis()->CenterTitle();
   pall->GetYaxis()->CenterTitle();
   pall->GetXaxis()->SetLabelSize(22);
   pall->GetXaxis()->SetLabelFont(43);
   pall->GetXaxis()->SetTitleSize(24);
   pall->GetXaxis()->SetTitleFont(43);
   pall->GetYaxis()->SetLabelSize(22);
   pall->GetYaxis()->SetLabelFont(43);
   pall->GetYaxis()->SetTitleSize(24);
   pall->GetYaxis()->SetTitleFont(43);
   pall->GetXaxis()->SetTitleOffset(1.8);
   pall->GetYaxis()->SetTitleOffset(2.4);
   pall->SetNdivisions(505);
   pall->SetAxisRange(-59.9,59.9,"Y");
   pall->SetMarkerSize(1);
   pall->Draw("E");
   float addSys = 0;
   if ( drawSys==1)   addSys=0; // No sys error at this moment

   // ====================
   // Finally Draw
   // ====================
   for (int i=0;i<nBin;++i) {
      ppos[i]->SetLineWidth(1);
      ppos[i]->Draw("hist same");
      pneg[i]->SetLineWidth(1);
      pneg[i]->Draw("hist same");
   }
   
   // ====================
   // Draw Statistical Error bars
   // ====================
   for (int i=0;i<nBin;++i) {
      if ( i==0 )       drawErrorShift(ppos[i],-0.016, addSys);
      if ( i==1 || i==4)       drawErrorShift(ppos[i],-0.008,addSys);
      if ( i==2 )       drawErrorShift(ppos[i],0.008,addSys);
      if ( i==3 )       drawErrorShift(ppos[i],0.016,addSys);
      if ( i==0 )       drawErrorShift(pneg[i],-0.016, addSys);
      if ( i==1 || i==4)       drawErrorShift(pneg[i],-0.008,addSys);
      if ( i==2 )       drawErrorShift(pneg[i],0.008,addSys);
      if ( i==3 )       drawErrorShift(pneg[i],0.016,addSys);
   }
   pall->Draw("E same");
   
   // ====================
   // Draw Systematic Errors
   // ====================
   if (drawSys == 1) {
      for(int i = 0; i < nBinAj; ++i){
        double x = pall->GetBinCenter(i+1);
        double y = pall->GetBinContent(i+1);
        // Quote the difference between GEN and RECO in >8 Bin (20%) before adjusting eff as systematics
        double err = fabs(pe[nBin-1]->GetBinContent(i+1)*0.2);
        DrawTick(y,err,err,x,1,0.02,1);
      }
   }

   // ====================
   // Draw Legend
   // ====================
   TLegend *leg = new TLegend(0.10,0.68,0.70,0.96);
   leg->SetFillStyle(0);
   leg->SetBorderSize(0);
   leg->SetTextFont(63);
   leg->SetTextSize(16);
   leg->AddEntry(pall,Form("> %.1f GeV/c",bins[0]),"pl");
   for (int i=0;i<nBin;++i) {
      if (i!=nBin-1){
         leg->AddEntry(ppos[i],Form("%.1f - %.1f GeV/c",bins[i],bins[i+1]),"f");
      } else {
         leg->AddEntry(ppos[i],Form("> %.1f GeV/c",bins[i]),"f");
      }
   }

   if (drawLegend) leg->Draw();

   TLine * l0 = new TLine(0,0,0.5,0);
   l0->SetLineStyle(2);
   l0->Draw();


   TLine * l1 = new TLine(0.0001,-10,0.0001,10);
   l1->Draw();

   TText *titleText = new TText(0.3,30,title);
   titleText->Draw();
}
Esempio n. 21
0
TH1D *
GetTPCTOFRatio(TFile *file, Int_t num, Int_t den, Int_t cent, Bool_t cutSpectrum = kTRUE)
{
  /* pt limits for combined spectra */
  Double_t ptMin_[9] = {
    0.0, 0.0, 0.0, 
    0., 0., 0., 
    0.5, 0.5, 0.5
  };
  Double_t ptMax_[9] = {
    1.2, 1.2, 1.2, 
    1.2, 1.2, 1.2, 
    1.8, 1.8, 1.8
  };

  Double_t ptMin = TMath::Max(ptMin_[num], ptMin_[den]);
  Double_t ptMax = TMath::Min(ptMax_[num], ptMax_[den]);

  Int_t part = 0, charge = 0;
  if (num == kPiMinus && den == kPiPlus) {
    part = AliPID::kPion;
    charge = 1;
  }
  else if (num == kKaMinus && den == kKaPlus) {
    part = AliPID::kKaon;
    charge = 1;
  }
  else if (num == kPrMinus && den == kPrPlus) {
    part = AliPID::kProton;
    charge = 1;
  }
  else if (num == kKaMinus && den == kPiMinus) {
    part = AliPID::kKaon;
    charge = 1;
  }
  else if (num == kKaPlus && den == kPiPlus) {
    part = AliPID::kKaon;
    charge = 0;
  }
  else if (num == kPrMinus && den == kPiMinus) {
    part = AliPID::kProton;
    charge = 1;
  }
  else if (num == kPrPlus && den == kPiPlus) {
    part = AliPID::kProton;
    charge = 0;
  }

  TH1D *hin = (TH1D *)file->Get(Form("%sFinal%s%d", TPCTOFPartName[part], TPCTOFChargeName[charge], cent));
  if (!hin) return NULL;

  TH1D *h = new TH1D(Form("hTPCTOF_cent%d_%s_%s", cent, ratioName[num], ratioName[den]), "TPCTOF", NptBins, ptBin);
  Double_t pt, width, value, error;
  Int_t bin;
  for (Int_t ipt = 0; ipt < NptBins; ipt++) {
    /* get input bin */
    pt = h->GetBinCenter(ipt + 1);
    width = h->GetBinWidth(ipt + 1);
    bin = hin->FindBin(pt);
    /* sanity check */
    if (TMath::Abs(hin->GetBinCenter(bin) - pt) > 0.001 ||
	TMath::Abs(hin->GetBinWidth(bin) - width) > 0.001)
      continue;
    /* check pt limits */
    if (cutSpectrum && (pt < ptMin || pt > ptMax)) continue;
    /* copy bin */
    value = hin->GetBinContent(bin);
    error = hin->GetBinError(bin);
    h->SetBinContent(ipt + 1, value);
    h->SetBinError(ipt + 1, error);
  }
  
  h->SetTitle("TPCTOF");
  h->SetLineWidth(1);
  h->SetLineColor(1);
  h->SetMarkerStyle(22);
  h->SetMarkerColor(8);
  h->SetFillStyle(0);
  h->SetFillColor(0);
  
  return h;
}
Esempio n. 22
0
PostProcessQAV0(Bool_t lAttemptInvMassFit = kTRUE,
                Char_t *output            = "pdf"                          // "eps", "png" or "pdf"
               ){


  CustomGStyleSettings();  

  //==============================================================
  //Open Output File
  TFile* file = TFile::Open("AnalysisResults.root"), "READ");
  if (!file){
    cout<<"Output file not found!"<<endl;
    return;
  }
	file->cd("PWGLFQAV0_QA");
	TList* clist  = (TList*)file->FindObjectAny("clist");
  if (!clist){
    cout<<"File does not seem to hold QA list output!"<<endl;
    return;
  }  
  //==============================================================

  //==============================================================
  //Open Event Histogram: first canvas
  TH1D* fHistEvent = (TH1D*)clist->FindObject("fHistEvent");
  TCanvas *cHistEvent = new TCanvas("cHistEvent","",800,670); 
  cHistEvent->SetTopMargin(0.15);
  cHistEvent->SetGridx(); 
  cHistEvent->SetGridy();
  fHistEvent->Draw();

  fHistEvent->SetMarkerSize(1.35);
  fHistEvent->GetXaxis()->SetTitleOffset(1.2);
  fHistEvent->GetYaxis()->SetTitleOffset(1.2);
  fHistEvent->Draw("same text00");

  TLatex Tl;
  Tl.SetNDC();
  Tl.SetTextSize(0.05);
  Tl.DrawLatex(.35, .9277, "Event Counters")  ;  
  if      (output == "png") cHistEvent->SaveAs("LF_QAanalysis_V0_page1.png");  
  else if (output == "eps") cHistEvent->SaveAs("LF_QAanalysis_V0_page1.eps");
  else if (output == "pdf") cHistEvent->SaveAs("LF_QAanalysis_V0.pdf(");    

  //==============================================================

  //==============================================================
  //Invariant Mass Plots: Base, no dE/dx
  /*
  TH2D *f2dHistInvMassK0Short    = (TH2D*)clist->FindObject("f2dHistInvMassK0Short");
  TH2D *f2dHistInvMassLambda     = (TH2D*)clist->FindObject("f2dHistInvMassLambda");
  TH2D *f2dHistInvMassAntiLambda = (TH2D*)clist->FindObject("f2dHistInvMassAntiLambda");
    
  f2dHistInvMassK0Short     -> Scale ( 1. / ((Double_t)fHistEvent->GetBinContent(4) ) );
  f2dHistInvMassLambda      -> Scale ( 1. / ((Double_t)fHistEvent->GetBinContent(4) ) );
  f2dHistInvMassAntiLambda  -> Scale ( 1. / ((Double_t)fHistEvent->GetBinContent(4) ) );

  TCanvas *cInvMassK0Short = new TCanvas ( "cInvMassK0Short", "", 1200,800); 
  cInvMassK0Short->Divide(1,2); 
  cInvMassK0Short->cd(2)->Divide(3,1); 
  cInvMassK0Short->cd(1); 
  cInvMassK0Short->cd(1)->SetLogz();
  cInvMassK0Short->cd(1)->SetLeftMargin(0.065);
  cInvMassK0Short->cd(1)->SetTopMargin(0.13);
  cInvMassK0Short->cd(1)->SetBottomMargin(0.11);

  f2dHistInvMassK0Short->GetYaxis()->SetTitleSize(0.05);
  f2dHistInvMassK0Short->GetYaxis()->SetTitleOffset(0.6);
  f2dHistInvMassK0Short->GetXaxis()->SetTitleSize(0.05);
  f2dHistInvMassK0Short->GetXaxis()->SetTitle("p_{T} (GeV/c)");
  f2dHistInvMassK0Short->GetZaxis()->SetTitle("Counts / Event");
  f2dHistInvMassK0Short->GetZaxis()->SetTitleOffset(0.7);
  f2dHistInvMassK0Short->GetZaxis()->SetRangeUser( f2dHistInvMassK0Short->GetMinimum(1e-10)*0.9, f2dHistInvMassK0Short->GetMaximum()*1.2 );
  f2dHistInvMassK0Short->Draw("colz");
  Tl.DrawLatex(.35, .9277, "Mass under K^{0}_{S} hypothesis, no TPC dE/dx")  ;   

  TH1D *fLowPtK0ShortSample = (TH1D*) f2dHistInvMassK0Short->ProjectionY( "fLowPtK0ShortSample", 
    f2dHistInvMassK0Short->GetXaxis()->FindBin(0.5001),
    f2dHistInvMassK0Short->GetXaxis()->FindBin(0.9999) );

  TH1D *fMidPtK0ShortSample = (TH1D*) f2dHistInvMassK0Short->ProjectionY( "fMidPtK0ShortSample", 
    f2dHistInvMassK0Short->GetXaxis()->FindBin(1.5001),
    f2dHistInvMassK0Short->GetXaxis()->FindBin(2.4999) );

  TH1D *fHiPtK0ShortSample = (TH1D*) f2dHistInvMassK0Short->ProjectionY( "fHiPtK0ShortSample", 
    f2dHistInvMassK0Short->GetXaxis()->FindBin(5.0001),
    f2dHistInvMassK0Short->GetXaxis()->FindBin(9.9999) );

  for(Int_t ic = 1; ic<4; ic++){ 
    cInvMassK0Short->cd(2)->cd(ic)->SetTopMargin(0.14);
    cInvMassK0Short->cd(2)->cd(ic)->SetLeftMargin(0.15);
    cInvMassK0Short->cd(2)->cd(ic)->SetBottomMargin(0.11);
    cInvMassK0Short->cd(2)->cd(ic)->SetGridx(); 
    cInvMassK0Short->cd(2)->cd(ic)->SetGridy();
  }

  cInvMassK0Short->cd(2)->cd(1); 
  fLowPtK0ShortSample->GetXaxis()->SetTitleOffset(1.1);
  fLowPtK0ShortSample->GetYaxis()->SetTitleOffset(2.33);
  fLowPtK0ShortSample->GetYaxis()->SetTitle("Counts/Event");
  fLowPtK0ShortSample->Draw(); 
  Tl.DrawLatex(.25, .9277, "0.5 < p_{T} (GeV/c^{2}) < 1.0");

  cInvMassK0Short->cd(2)->cd(2); 
  fMidPtK0ShortSample->GetXaxis()->SetTitleOffset(1.1);
  fMidPtK0ShortSample->GetYaxis()->SetTitleOffset(2.33);
  fMidPtK0ShortSample->GetYaxis()->SetTitle("Counts/Event");
  fMidPtK0ShortSample->Draw(); 
  Tl.DrawLatex(.25, .9277, "1.5 < p_{T} (GeV/c^{2}) < 2.5");

  cInvMassK0Short->cd(2)->cd(3); 
  fHiPtK0ShortSample->GetXaxis()->SetTitleOffset(1.1);
  fHiPtK0ShortSample->GetYaxis()->SetTitleOffset(2.33);
  fHiPtK0ShortSample->GetYaxis()->SetTitle("Counts/Event");
  fHiPtK0ShortSample->Draw(); 
  Tl.DrawLatex(.25, .9277, "5 < p_{T} (GeV/c^{2}) < 10");  
  if      (output == "png") cInvMassK0Short->SaveAs("LF_QAanalysis_V0_pageX.png");
  else if (output == "eps") cInvMassK0Short->SaveAs("LF_QAanalysis_V0_pageX.eps");
  else if (output == "pdf") cInvMassK0Short->SaveAs("LF_QAanalysis_V0.pdf");

  */
  //==============================================================

  //==============================================================
  //Invariant Mass Plots: WITH dE/dx
  TH2D *f2dHistInvMassWithdEdxK0Short    = (TH2D*)clist->FindObject("f2dHistInvMassWithdEdxK0Short");
  TH2D *f2dHistInvMassWithdEdxLambda     = (TH2D*)clist->FindObject("f2dHistInvMassWithdEdxLambda");
  TH2D *f2dHistInvMassWithdEdxAntiLambda = (TH2D*)clist->FindObject("f2dHistInvMassWithdEdxAntiLambda");
    
  f2dHistInvMassWithdEdxK0Short     -> Scale ( 1. / ((Double_t)fHistEvent->GetBinContent(4) ) );
  f2dHistInvMassWithdEdxLambda      -> Scale ( 1. / ((Double_t)fHistEvent->GetBinContent(4) ) );
  f2dHistInvMassWithdEdxAntiLambda  -> Scale ( 1. / ((Double_t)fHistEvent->GetBinContent(4) ) );

  TCanvas *cInvMassK0ShortWithdEdx = new TCanvas ( "cInvMassK0ShortWithdEdx", "", 1200,800); 
  cInvMassK0ShortWithdEdx->Divide(1,2); 
  cInvMassK0ShortWithdEdx->cd(2)->Divide(3,1); 
  cInvMassK0ShortWithdEdx->cd(1); 
  cInvMassK0ShortWithdEdx->cd(1)->SetLogz();
  cInvMassK0ShortWithdEdx->cd(1)->SetLeftMargin(0.065);
  cInvMassK0ShortWithdEdx->cd(1)->SetTopMargin(0.13);
  cInvMassK0ShortWithdEdx->cd(1)->SetBottomMargin(0.11);

  f2dHistInvMassWithdEdxK0Short->GetYaxis()->SetTitleSize(0.05);
  f2dHistInvMassWithdEdxK0Short->GetYaxis()->SetTitleOffset(0.6);
  f2dHistInvMassWithdEdxK0Short->GetXaxis()->SetTitleSize(0.05);
  f2dHistInvMassWithdEdxK0Short->GetXaxis()->SetTitle("p_{T} (GeV/c)");
  f2dHistInvMassWithdEdxK0Short->GetZaxis()->SetTitle("Counts / Event");
  f2dHistInvMassWithdEdxK0Short->GetZaxis()->SetTitleOffset(0.7);
  f2dHistInvMassWithdEdxK0Short->GetZaxis()->SetRangeUser( f2dHistInvMassWithdEdxK0Short->GetMinimum(1e-10)*0.9, f2dHistInvMassWithdEdxK0Short->GetMaximum()*1.2 );
  f2dHistInvMassWithdEdxK0Short->Draw("colz");
  Tl.DrawLatex(.35, .9277, "Mass under K^{0}_{S} hypothesis, With TPC dE/dx")  ;   

  TH1D *fLowPtK0ShortSampleWithdEdx = (TH1D*) f2dHistInvMassWithdEdxK0Short->ProjectionY( "fLowPtK0ShortSampleWithdEdx", 
    f2dHistInvMassWithdEdxK0Short->GetXaxis()->FindBin(0.5001),
    f2dHistInvMassWithdEdxK0Short->GetXaxis()->FindBin(0.9999) );

  TH1D *fMidPtK0ShortSampleWithdEdx = (TH1D*) f2dHistInvMassWithdEdxK0Short->ProjectionY( "fMidPtK0ShortSampleWithdEdx", 
    f2dHistInvMassWithdEdxK0Short->GetXaxis()->FindBin(1.5001),
    f2dHistInvMassWithdEdxK0Short->GetXaxis()->FindBin(2.4999) );

  TH1D *fHiPtK0ShortSampleWithdEdx = (TH1D*) f2dHistInvMassWithdEdxK0Short->ProjectionY( "fHiPtK0ShortSampleWithdEdx", 
    f2dHistInvMassWithdEdxK0Short->GetXaxis()->FindBin(5.0001),
    f2dHistInvMassWithdEdxK0Short->GetXaxis()->FindBin(9.9999) );

  for(Int_t ic = 1; ic<4; ic++){ 
    cInvMassK0ShortWithdEdx->cd(2)->cd(ic)->SetTopMargin(0.14);
    cInvMassK0ShortWithdEdx->cd(2)->cd(ic)->SetLeftMargin(0.15);
    cInvMassK0ShortWithdEdx->cd(2)->cd(ic)->SetBottomMargin(0.11);
    cInvMassK0ShortWithdEdx->cd(2)->cd(ic)->SetGridx(); 
    cInvMassK0ShortWithdEdx->cd(2)->cd(ic)->SetGridy();
  }

  cInvMassK0ShortWithdEdx->cd(2)->cd(1); 
  fLowPtK0ShortSampleWithdEdx->GetXaxis()->SetTitleOffset(1.1);
  fLowPtK0ShortSampleWithdEdx->GetYaxis()->SetTitleOffset(2.33);
  fLowPtK0ShortSampleWithdEdx->GetYaxis()->SetTitle("Counts/Event");
  fLowPtK0ShortSampleWithdEdx->Draw(); 
  Tl.DrawLatex(.25, .9277, "0.5 < p_{T} (GeV/c^{2}) < 1.0");

  cInvMassK0ShortWithdEdx->cd(2)->cd(2); 
  fMidPtK0ShortSampleWithdEdx->GetXaxis()->SetTitleOffset(1.1);
  fMidPtK0ShortSampleWithdEdx->GetYaxis()->SetTitleOffset(2.33);
  fMidPtK0ShortSampleWithdEdx->GetYaxis()->SetTitle("Counts/Event");
  fMidPtK0ShortSampleWithdEdx->Draw(); 
  Tl.DrawLatex(.25, .9277, "1.5 < p_{T} (GeV/c^{2}) < 2.5");

  cInvMassK0ShortWithdEdx->cd(2)->cd(3); 
  fHiPtK0ShortSampleWithdEdx->GetXaxis()->SetTitleOffset(1.1);
  fHiPtK0ShortSampleWithdEdx->GetYaxis()->SetTitleOffset(2.33);
  fHiPtK0ShortSampleWithdEdx->GetYaxis()->SetTitle("Counts/Event");
  fHiPtK0ShortSampleWithdEdx->Draw(); 
  Tl.DrawLatex(.25, .9277, "5 < p_{T} (GeV/c^{2}) < 10");  

  TLatex Tli;
  Tli.SetNDC();
  Tli.SetTextSize(0.05);  

  if( lAttemptInvMassFit ){ 
    //Attempt rough signal extraction   
    TF1 *f1 = new TF1("f1","[0]+[1]*x+[2]*x*x+[3]*TMath::Gaus(x,[4],[5])",0.435, 0.565);
    //Reasonable first guess
    f1->SetParameter(0, fLowPtK0ShortSampleWithdEdx -> GetBinContent( fLowPtK0ShortSampleWithdEdx->FindBin(0.497-0.01) ) );
    f1->SetParameter(1, 0 );
    f1->SetParameter(2, 0 );
    f1->SetParameter(3, 0.5*fLowPtK0ShortSampleWithdEdx->GetMaximum() ); 
    f1->SetParameter(4, 0.497);
    f1->SetParameter(5, 0.0045);
    cout<<"Will now fit, please wait!"<<endl;
    fLowPtK0ShortSampleWithdEdx->Fit("f1","REM0");
    cInvMassK0ShortWithdEdx->cd(2)->cd(1); 
    f1->Draw("same"); 
    //Peak Position, Width: printout 
    fLowPtK0ShortSampleWithdEdx->GetYaxis()->SetRangeUser(0,fLowPtK0ShortSampleWithdEdx->GetMaximum() * 1.2);
    Tli.DrawLatex(0.2,0.8,Form("peak = %.4f #pm %.4f MeV/c^{2}",f1->GetParameter(4),f1->GetParameter(5)) ) ;
    
    //Attempt rough signal extraction   
    TF1 *f2 = new TF1("f2","[0]+[1]*x+[2]*x*x+[3]*TMath::Gaus(x,[4],[5])",0.375, 0.635);
    //Reasonable first guess
    f2->SetParameter(0, fMidPtK0ShortSampleWithdEdx -> GetBinContent( fMidPtK0ShortSampleWithdEdx->FindBin(0.497-0.01) ) );
    f2->SetParameter(1, 0 );
    f2->SetParameter(2, 0 );
    f2->SetParameter(3, 0.5*fMidPtK0ShortSampleWithdEdx->GetMaximum() ); 
    f2->SetParameter(4, 0.497);
    f2->SetParameter(5, 0.0045);
    cout<<"Will now fit, please wait!"<<endl;
    fMidPtK0ShortSampleWithdEdx->Fit("f2","REM0");
    cInvMassK0ShortWithdEdx->cd(2)->cd(2); 
    f2->Draw("same"); 
    //Peak Position, Width: printout 
    fMidPtK0ShortSampleWithdEdx->GetYaxis()->SetRangeUser(0,fMidPtK0ShortSampleWithdEdx->GetMaximum() * 1.2);
    Tli.DrawLatex(0.2,0.8,Form("peak = %.4f #pm %.4f MeV/c^{2}",f2->GetParameter(4),f2->GetParameter(5)) ) ;

    //Attempt rough signal extraction   
    TF1 *f3 = new TF1("f3","[0]+[1]*x+[2]*x*x+[3]*TMath::Gaus(x,[4],[5])",0.375, 0.665);
    //Reasonable first guess
    f3->SetParameter(0, fHiPtK0ShortSampleWithdEdx -> GetBinContent( fHiPtK0ShortSampleWithdEdx->FindBin(0.497-0.01) ) );
    f3->SetParameter(1, 0 );
    f3->SetParameter(2, 0 );
    f3->SetParameter(3, 0.5*fHiPtK0ShortSampleWithdEdx->GetMaximum() ); 
    f3->SetParameter(4, 0.497);
    f3->SetParameter(5, 0.0045);
    cout<<"Will now fit, please wait!"<<endl;
    fHiPtK0ShortSampleWithdEdx->Fit("f3","REM0");
    cInvMassK0ShortWithdEdx->cd(2)->cd(3); 
    f3->Draw("same"); 
    //Peak Position, Width: printout 
    fHiPtK0ShortSampleWithdEdx->GetYaxis()->SetRangeUser(0,fHiPtK0ShortSampleWithdEdx->GetMaximum() * 1.2);
    Tli.DrawLatex(0.2,0.8,Form("peak = %.4f #pm %.4f MeV/c^{2}",f3->GetParameter(4),f3->GetParameter(5)) ) ;
  }

  if      (output == "png") cInvMassK0ShortWithdEdx->SaveAs("LF_QAanalysis_V0_page2.png");      
  else if (output == "eps") cInvMassK0ShortWithdEdx->SaveAs("LF_QAanalysis_V0_page2.eps");
  else if (output == "pdf") cInvMassK0ShortWithdEdx->SaveAs("LF_QAanalysis_V0.pdf"); 

  //==============================================================  


  //==============================================================
  //Invariant Mass Plots: Base, no dE/dx
  /*
  TCanvas *cInvMassLambda = new TCanvas ( "cInvMassLambda", "", 1200,800); 
  cInvMassLambda->Divide(1,2); 
  cInvMassLambda->cd(2)->Divide(3,1); 
  cInvMassLambda->cd(1); 
  cInvMassLambda->cd(1)->SetLogz();
  cInvMassLambda->cd(1)->SetLeftMargin(0.065);
  cInvMassLambda->cd(1)->SetTopMargin(0.13);
  cInvMassLambda->cd(1)->SetBottomMargin(0.11);

  f2dHistInvMassLambda->GetYaxis()->SetTitleSize(0.05);
  f2dHistInvMassLambda->GetYaxis()->SetTitleOffset(0.6);
  f2dHistInvMassLambda->GetXaxis()->SetTitleSize(0.05);
  f2dHistInvMassLambda->GetXaxis()->SetTitle("p_{T} (GeV/c)");
  f2dHistInvMassLambda->GetZaxis()->SetTitle("Counts / Event");
  f2dHistInvMassLambda->GetZaxis()->SetTitleOffset(0.7);
  f2dHistInvMassLambda->GetZaxis()->SetRangeUser( f2dHistInvMassLambda->GetMinimum(1e-10)*0.9, f2dHistInvMassLambda->GetMaximum()*1.2 );
  f2dHistInvMassLambda->Draw("colz");
  Tl.DrawLatex(.35, .9277, "Mass under #Lambda hypothesis, no TPC dE/dx")  ;   

  TH1D *fLowPtLambdaSample = (TH1D*) f2dHistInvMassLambda->ProjectionY( "fLowPtLambdaSample", 
    f2dHistInvMassLambda->GetXaxis()->FindBin(0.5001),
    f2dHistInvMassLambda->GetXaxis()->FindBin(0.9999) );

  TH1D *fMidPtLambdaSample = (TH1D*) f2dHistInvMassLambda->ProjectionY( "fMidPtLambdaSample", 
    f2dHistInvMassLambda->GetXaxis()->FindBin(1.5001),
    f2dHistInvMassLambda->GetXaxis()->FindBin(2.4999) );

  TH1D *fHiPtLambdaSample = (TH1D*) f2dHistInvMassLambda->ProjectionY( "fHiPtLambdaSample", 
    f2dHistInvMassLambda->GetXaxis()->FindBin(5.0001),
    f2dHistInvMassLambda->GetXaxis()->FindBin(9.9999) );

  for(Int_t ic = 1; ic<4; ic++){ 
    cInvMassLambda->cd(2)->cd(ic)->SetTopMargin(0.14);
    cInvMassLambda->cd(2)->cd(ic)->SetLeftMargin(0.15);
    cInvMassLambda->cd(2)->cd(ic)->SetBottomMargin(0.11);
    cInvMassLambda->cd(2)->cd(ic)->SetGridx(); 
    cInvMassLambda->cd(2)->cd(ic)->SetGridy();
  }

  cInvMassLambda->cd(2)->cd(1); 
  fLowPtLambdaSample->GetXaxis()->SetTitleOffset(1.1);
  fLowPtLambdaSample->GetYaxis()->SetTitleOffset(2.33);
  fLowPtLambdaSample->GetYaxis()->SetTitle("Counts/Event");
  fLowPtLambdaSample->Draw(); 
  Tl.DrawLatex(.25, .9277, "0.5 < p_{T} (GeV/c^{2}) < 1.0");

  cInvMassLambda->cd(2)->cd(2); 
  fMidPtLambdaSample->GetXaxis()->SetTitleOffset(1.1);
  fMidPtLambdaSample->GetYaxis()->SetTitleOffset(2.33);
  fMidPtLambdaSample->GetYaxis()->SetTitle("Counts/Event");
  fMidPtLambdaSample->Draw(); 
  Tl.DrawLatex(.25, .9277, "1.5 < p_{T} (GeV/c^{2}) < 2.5");

  cInvMassLambda->cd(2)->cd(3); 
  fHiPtLambdaSample->GetXaxis()->SetTitleOffset(1.1);
  fHiPtLambdaSample->GetYaxis()->SetTitleOffset(2.33);
  fHiPtLambdaSample->GetYaxis()->SetTitle("Counts/Event");
  fHiPtLambdaSample->Draw(); 
  Tl.DrawLatex(.25, .9277, "5 < p_{T} (GeV/c^{2}) < 10");  
  if      (output == "png") cInvMassLambda->SaveAs("LF_QAanalysis_V0_pageY.png");
  else if (output == "eps") cInvMassLambda->SaveAs("LF_QAanalysis_V0_pageY.eps");
  else if (output == "pdf") cInvMassLambda->SaveAs("LF_QAanalysis_V0.pdf");

  */
  //==============================================================

  //==============================================================
  //Invariant Mass Plots: WITH dE/dx
  TCanvas *cInvMassLambdaWithdEdx = new TCanvas ( "cInvMassLambdaWithdEdx", "", 1200,800); 
  cInvMassLambdaWithdEdx->Divide(1,2); 
  cInvMassLambdaWithdEdx->cd(2)->Divide(3,1); 
  cInvMassLambdaWithdEdx->cd(1); 
  cInvMassLambdaWithdEdx->cd(1)->SetLogz();
  cInvMassLambdaWithdEdx->cd(1)->SetLeftMargin(0.065);
  cInvMassLambdaWithdEdx->cd(1)->SetTopMargin(0.13);
  cInvMassLambdaWithdEdx->cd(1)->SetBottomMargin(0.11);

  f2dHistInvMassWithdEdxLambda->GetYaxis()->SetTitleSize(0.05);
  f2dHistInvMassWithdEdxLambda->GetYaxis()->SetTitleOffset(0.6);
  f2dHistInvMassWithdEdxLambda->GetXaxis()->SetTitleSize(0.05);
  f2dHistInvMassWithdEdxLambda->GetXaxis()->SetTitle("p_{T} (GeV/c)");
  f2dHistInvMassWithdEdxLambda->GetZaxis()->SetTitle("Counts / Event");
  f2dHistInvMassWithdEdxLambda->GetZaxis()->SetTitleOffset(0.7);
  f2dHistInvMassWithdEdxLambda->GetZaxis()->SetRangeUser( f2dHistInvMassWithdEdxLambda->GetMinimum(1e-10)*0.9, f2dHistInvMassWithdEdxLambda->GetMaximum()*1.2 );
  f2dHistInvMassWithdEdxLambda->Draw("colz");
  Tl.DrawLatex(.35, .9277, "Mass under #Lambda hypothesis, With TPC dE/dx")  ;   

  TH1D *fLowPtLambdaSampleWithdEdx = (TH1D*) f2dHistInvMassWithdEdxLambda->ProjectionY( "fLowPtLambdaSampleWithdEdx", 
    f2dHistInvMassWithdEdxLambda->GetXaxis()->FindBin(0.5001),
    f2dHistInvMassWithdEdxLambda->GetXaxis()->FindBin(0.9999) );

  TH1D *fMidPtLambdaSampleWithdEdx = (TH1D*) f2dHistInvMassWithdEdxLambda->ProjectionY( "fMidPtLambdaSampleWithdEdx", 
    f2dHistInvMassWithdEdxLambda->GetXaxis()->FindBin(1.5001),
    f2dHistInvMassWithdEdxLambda->GetXaxis()->FindBin(2.4999) );

  TH1D *fHiPtLambdaSampleWithdEdx = (TH1D*) f2dHistInvMassWithdEdxLambda->ProjectionY( "fHiPtLambdaSampleWithdEdx", 
    f2dHistInvMassWithdEdxLambda->GetXaxis()->FindBin(5.0001),
    f2dHistInvMassWithdEdxLambda->GetXaxis()->FindBin(9.9999) );

  for(Int_t ic = 1; ic<4; ic++){ 
    cInvMassLambdaWithdEdx->cd(2)->cd(ic)->SetTopMargin(0.14);
    cInvMassLambdaWithdEdx->cd(2)->cd(ic)->SetLeftMargin(0.15);
    cInvMassLambdaWithdEdx->cd(2)->cd(ic)->SetBottomMargin(0.11);
    cInvMassLambdaWithdEdx->cd(2)->cd(ic)->SetGridx(); 
    cInvMassLambdaWithdEdx->cd(2)->cd(ic)->SetGridy();
  }

  cInvMassLambdaWithdEdx->cd(2)->cd(1); 
  fLowPtLambdaSampleWithdEdx->GetXaxis()->SetTitleOffset(1.1);
  fLowPtLambdaSampleWithdEdx->GetYaxis()->SetTitleOffset(2.33);
  fLowPtLambdaSampleWithdEdx->GetYaxis()->SetTitle("Counts/Event");
  fLowPtLambdaSampleWithdEdx->Draw(); 
  Tl.DrawLatex(.25, .9277, "0.5 < p_{T} (GeV/c^{2}) < 1.0");

  cInvMassLambdaWithdEdx->cd(2)->cd(2); 
  fMidPtLambdaSampleWithdEdx->GetXaxis()->SetTitleOffset(1.1);
  fMidPtLambdaSampleWithdEdx->GetYaxis()->SetTitleOffset(2.33);
  fMidPtLambdaSampleWithdEdx->GetYaxis()->SetTitle("Counts/Event");
  fMidPtLambdaSampleWithdEdx->Draw(); 
  Tl.DrawLatex(.25, .9277, "1.5 < p_{T} (GeV/c^{2}) < 2.5");

  cInvMassLambdaWithdEdx->cd(2)->cd(3); 
  fHiPtLambdaSampleWithdEdx->GetXaxis()->SetTitleOffset(1.1);
  fHiPtLambdaSampleWithdEdx->GetYaxis()->SetTitleOffset(2.33);
  fHiPtLambdaSampleWithdEdx->GetYaxis()->SetTitle("Counts/Event");
  fHiPtLambdaSampleWithdEdx->Draw(); 
  Tl.DrawLatex(.25, .9277, "5 < p_{T} (GeV/c^{2}) < 10"); 

  if( lAttemptInvMassFit ){ 
    //Attempt rough signal extraction   
    TF1 *fl1 = new TF1("fl1","[0]+[1]*x+[2]*x*x+[3]*TMath::Gaus(x,[4],[5])",1.095, 1.14);
    //Reasonable first guess
    fl1->SetParameter(0, fLowPtLambdaSampleWithdEdx -> GetBinContent( fLowPtLambdaSampleWithdEdx->FindBin(1.116+0.01) ) );
    fl1->SetParameter(1, 0 );
    fl1->SetParameter(2, 0 );
    fl1->SetParameter(3, 0.35*fLowPtLambdaSampleWithdEdx->GetMaximum() ); 
    fl1->SetParameter(4, 1.115683);
    fl1->SetParLimits(4,1.116-0.01,1.116+0.01);
    fl1->SetParameter(5, 0.002);
    fl1->SetParLimits(5,0.0005,0.01);
    cout<<"Will now fit, please wait!"<<endl;
    fLowPtLambdaSampleWithdEdx->Fit("fl1","REM0");
    cInvMassLambdaWithdEdx->cd(2)->cd(1); 
    fl1->Draw("same"); 
    //Peak Position, Width: printout 
    fLowPtLambdaSampleWithdEdx->GetYaxis()->SetRangeUser(0,fLowPtLambdaSampleWithdEdx->GetMaximum() * 1.2);
    Tli.DrawLatex(0.2,0.8,Form("peak = %.4f #pm %.4f MeV/c^{2}",fl1->GetParameter(4),fl1->GetParameter(5)) ) ;
    
    //Attempt rough signal extraction   
    TF1 *fl2 = new TF1("fl2","[0]+[1]*x+[2]*x*x+[3]*TMath::Gaus(x,[4],[5])",1.085, 1.15);
    //Reasonable first guess
    fl2->SetParameter(0, fMidPtLambdaSampleWithdEdx -> GetBinContent( fMidPtLambdaSampleWithdEdx->FindBin(1.116+0.01) ) );
    fl2->SetParameter(1, 0 );
    fl2->SetParameter(2, 0 );
    fl2->SetParameter(3, 0.6*fMidPtLambdaSampleWithdEdx->GetMaximum() ); 
    fl2->SetParLimits(4,1.116-0.01,1.116+0.01);
    fl2->SetParameter(4, 1.116);
    fl2->SetParameter(5, 0.0025);
    fl2->SetParLimits(5,0.0005,0.01);
    cout<<"Will now fit, please wait!"<<endl;
    fMidPtLambdaSampleWithdEdx->Fit("fl2","REM0");
    cInvMassLambdaWithdEdx->cd(2)->cd(2); 
    fl2->Draw("same"); 
    //Peak Position, Width: printout 
    fMidPtLambdaSampleWithdEdx->GetYaxis()->SetRangeUser(0,fMidPtLambdaSampleWithdEdx->GetMaximum() * 1.2);
    Tli.DrawLatex(0.2,0.8,Form("peak = %.4f #pm %.4f MeV/c^{2}",fl2->GetParameter(4),fl2->GetParameter(5)) ) ;

    //Attempt rough signal extraction   
    TF1 *fl3 = new TF1("fl3","[0]+[1]*x+[2]*x*x+[3]*TMath::Gaus(x,[4],[5])",1.095, 1.15);
    //Reasonable first guess
    fl3->SetParameter(0, fHiPtLambdaSampleWithdEdx -> GetBinContent( fHiPtLambdaSampleWithdEdx->FindBin(1.116+0.01) ) );
    fl3->SetParameter(1, 0 );
    fl3->SetParameter(2, 0 );
    fl3->SetParameter(3, 0.6*fHiPtLambdaSampleWithdEdx->GetMaximum() ); 
    fl3->SetParameter(4, 1.116);
    fl3->SetParLimits(4,1.116-0.005,1.116+0.005);
    fl3->SetParameter(5, 0.0035);
    fl3->SetParLimits(5,0.0005,0.01);
    cout<<"Will now fit, please wait!"<<endl;
    fHiPtLambdaSampleWithdEdx->Fit("fl3","REM0");
    cInvMassLambdaWithdEdx->cd(2)->cd(3); 
    fl3->Draw("same"); 
    //Peak Position, Width: printout 
    fHiPtLambdaSampleWithdEdx->GetYaxis()->SetRangeUser(0,fHiPtLambdaSampleWithdEdx->GetMaximum() * 1.2);
    Tli.DrawLatex(0.2,0.8,Form("peak = %.4f #pm %.4f MeV/c^{2}",fl3->GetParameter(4),fl3->GetParameter(5)) ) ;
  }

 
  if      (output == "png") cInvMassLambdaWithdEdx->SaveAs("LF_QAanalysis_V0_page3.png");
  else if (output == "eps") cInvMassLambdaWithdEdx->SaveAs("LF_QAanalysis_V0_page3.eps");
  else if (output == "pdf") cInvMassLambdaWithdEdx->SaveAs("LF_QAanalysis_V0.pdf");
  //==============================================================  

  //==============================================================
  //Invariant Mass Plots: Base, no dE/dx
  /*
  TCanvas *cInvMassAntiLambda = new TCanvas ( "cInvMassAntiLambda", "", 1200,800); 
  cInvMassAntiLambda->Divide(1,2); 
  cInvMassAntiLambda->cd(2)->Divide(3,1); 
  cInvMassAntiLambda->cd(1); 
  cInvMassAntiLambda->cd(1)->SetLogz();
  cInvMassAntiLambda->cd(1)->SetLeftMargin(0.065);
  cInvMassAntiLambda->cd(1)->SetTopMargin(0.13);
  cInvMassAntiLambda->cd(1)->SetBottomMargin(0.11);

  f2dHistInvMassAntiLambda->GetYaxis()->SetTitleSize(0.05);
  f2dHistInvMassAntiLambda->GetYaxis()->SetTitleOffset(0.6);
  f2dHistInvMassAntiLambda->GetXaxis()->SetTitleSize(0.05);
  f2dHistInvMassAntiLambda->GetXaxis()->SetTitle("p_{T} (GeV/c)");
  f2dHistInvMassAntiLambda->GetZaxis()->SetTitle("Counts / Event");
  f2dHistInvMassAntiLambda->GetZaxis()->SetTitleOffset(0.7);
  f2dHistInvMassAntiLambda->GetZaxis()->SetRangeUser( f2dHistInvMassAntiLambda->GetMinimum(1e-10)*0.9, f2dHistInvMassAntiLambda->GetMaximum()*1.2 );
  f2dHistInvMassAntiLambda->Draw("colz");
  Tl.DrawLatex(.35, .9277, "Mass under #bar{#Lambda} hypothesis, no TPC dE/dx")  ;   

  TH1D *fLowPtAntiLambdaSample = (TH1D*) f2dHistInvMassAntiLambda->ProjectionY( "fLowPtAntiLambdaSample", 
    f2dHistInvMassAntiLambda->GetXaxis()->FindBin(0.5001),
    f2dHistInvMassAntiLambda->GetXaxis()->FindBin(0.9999) );

  TH1D *fMidPtAntiLambdaSample = (TH1D*) f2dHistInvMassAntiLambda->ProjectionY( "fMidPtAntiLambdaSample", 
    f2dHistInvMassAntiLambda->GetXaxis()->FindBin(1.5001),
    f2dHistInvMassAntiLambda->GetXaxis()->FindBin(2.4999) );

  TH1D *fHiPtAntiLambdaSample = (TH1D*) f2dHistInvMassAntiLambda->ProjectionY( "fHiPtAntiLambdaSample", 
    f2dHistInvMassAntiLambda->GetXaxis()->FindBin(5.0001),
    f2dHistInvMassAntiLambda->GetXaxis()->FindBin(9.9999) );

  for(Int_t ic = 1; ic<4; ic++){ 
    cInvMassAntiLambda->cd(2)->cd(ic)->SetTopMargin(0.14);
    cInvMassAntiLambda->cd(2)->cd(ic)->SetLeftMargin(0.15);
    cInvMassAntiLambda->cd(2)->cd(ic)->SetBottomMargin(0.11);
    cInvMassAntiLambda->cd(2)->cd(ic)->SetGridx(); 
    cInvMassAntiLambda->cd(2)->cd(ic)->SetGridy();
  }

  cInvMassAntiLambda->cd(2)->cd(1); 
  fLowPtAntiLambdaSample->GetXaxis()->SetTitleOffset(1.1);
  fLowPtAntiLambdaSample->GetYaxis()->SetTitleOffset(2.33);
  fLowPtAntiLambdaSample->GetYaxis()->SetTitle("Counts/Event");
  fLowPtAntiLambdaSample->Draw(); 
  Tl.DrawLatex(.25, .9277, "0.5 < p_{T} (GeV/c^{2}) < 1.0");

  cInvMassAntiLambda->cd(2)->cd(2); 
  fMidPtAntiLambdaSample->GetXaxis()->SetTitleOffset(1.1);
  fMidPtAntiLambdaSample->GetYaxis()->SetTitleOffset(2.33);
  fMidPtAntiLambdaSample->GetYaxis()->SetTitle("Counts/Event");
  fMidPtAntiLambdaSample->Draw(); 
  Tl.DrawLatex(.25, .9277, "1.5 < p_{T} (GeV/c^{2}) < 2.5");

  cInvMassAntiLambda->cd(2)->cd(3); 
  fHiPtAntiLambdaSample->GetXaxis()->SetTitleOffset(1.1);
  fHiPtAntiLambdaSample->GetYaxis()->SetTitleOffset(2.33);
  fHiPtAntiLambdaSample->GetYaxis()->SetTitle("Counts/Event");
  fHiPtAntiLambdaSample->Draw(); 
  Tl.DrawLatex(.25, .9277, "5 < p_{T} (GeV/c^{2}) < 10");  
  if      (output == "png") cInvMassAntiLambda->SaveAs("LF_QAanalysis_V0_pageZ.png");
  else if (output == "eps") cInvMassAntiLambda->SaveAs("LF_QAanalysis_V0_pageZ.eps");
  else if (output == "pdf") cInvMassAntiLambda->SaveAs("LF_QAanalysis_V0.pdf");

  */
  //==============================================================

  //==============================================================
  //Invariant Mass Plots: WITH dE/dx
  TCanvas *cInvMassAntiLambdaWithdEdx = new TCanvas ( "cInvMassAntiLambdaWithdEdx", "", 1200,800); 
  cInvMassAntiLambdaWithdEdx->Divide(1,2); 
  cInvMassAntiLambdaWithdEdx->cd(2)->Divide(3,1); 
  cInvMassAntiLambdaWithdEdx->cd(1); 
  cInvMassAntiLambdaWithdEdx->cd(1)->SetLogz();
  cInvMassAntiLambdaWithdEdx->cd(1)->SetLeftMargin(0.065);
  cInvMassAntiLambdaWithdEdx->cd(1)->SetTopMargin(0.13);
  cInvMassAntiLambdaWithdEdx->cd(1)->SetBottomMargin(0.11);

  f2dHistInvMassWithdEdxAntiLambda->GetYaxis()->SetTitleSize(0.05);
  f2dHistInvMassWithdEdxAntiLambda->GetYaxis()->SetTitleOffset(0.6);
  f2dHistInvMassWithdEdxAntiLambda->GetXaxis()->SetTitleSize(0.05);
  f2dHistInvMassWithdEdxAntiLambda->GetXaxis()->SetTitle("p_{T} (GeV/c)");
  f2dHistInvMassWithdEdxAntiLambda->GetZaxis()->SetTitle("Counts / Event");
  f2dHistInvMassWithdEdxAntiLambda->GetZaxis()->SetTitleOffset(0.7);
  f2dHistInvMassWithdEdxAntiLambda->GetZaxis()->SetRangeUser( f2dHistInvMassWithdEdxAntiLambda->GetMinimum(1e-10)*0.9, f2dHistInvMassWithdEdxAntiLambda->GetMaximum()*1.2 );
  f2dHistInvMassWithdEdxAntiLambda->Draw("colz");
  Tl.DrawLatex(.35, .9277, "Mass under #bar{#Lambda} hypothesis, With TPC dE/dx")  ;   

  TH1D *fLowPtAntiLambdaSampleWithdEdx = (TH1D*) f2dHistInvMassWithdEdxAntiLambda->ProjectionY( "fLowPtAntiLambdaSampleWithdEdx", 
    f2dHistInvMassWithdEdxAntiLambda->GetXaxis()->FindBin(0.5001),
    f2dHistInvMassWithdEdxAntiLambda->GetXaxis()->FindBin(0.9999) );

  TH1D *fMidPtAntiLambdaSampleWithdEdx = (TH1D*) f2dHistInvMassWithdEdxAntiLambda->ProjectionY( "fMidPtAntiLambdaSampleWithdEdx", 
    f2dHistInvMassWithdEdxAntiLambda->GetXaxis()->FindBin(1.5001),
    f2dHistInvMassWithdEdxAntiLambda->GetXaxis()->FindBin(2.4999) );

  TH1D *fHiPtAntiLambdaSampleWithdEdx = (TH1D*) f2dHistInvMassWithdEdxAntiLambda->ProjectionY( "fHiPtAntiLambdaSampleWithdEdx", 
    f2dHistInvMassWithdEdxAntiLambda->GetXaxis()->FindBin(5.0001),
    f2dHistInvMassWithdEdxAntiLambda->GetXaxis()->FindBin(9.9999) );

  for(Int_t ic = 1; ic<4; ic++){ 
    cInvMassAntiLambdaWithdEdx->cd(2)->cd(ic)->SetTopMargin(0.14);
    cInvMassAntiLambdaWithdEdx->cd(2)->cd(ic)->SetLeftMargin(0.15);
    cInvMassAntiLambdaWithdEdx->cd(2)->cd(ic)->SetBottomMargin(0.11);
    cInvMassAntiLambdaWithdEdx->cd(2)->cd(ic)->SetGridx(); 
    cInvMassAntiLambdaWithdEdx->cd(2)->cd(ic)->SetGridy();
  }

  cInvMassAntiLambdaWithdEdx->cd(2)->cd(1); 
  fLowPtAntiLambdaSampleWithdEdx->GetXaxis()->SetTitleOffset(1.1);
  fLowPtAntiLambdaSampleWithdEdx->GetYaxis()->SetTitleOffset(2.33);
  fLowPtAntiLambdaSampleWithdEdx->GetYaxis()->SetTitle("Counts/Event");
  fLowPtAntiLambdaSampleWithdEdx->Draw(); 
  Tl.DrawLatex(.25, .9277, "0.5 < p_{T} (GeV/c^{2}) < 1.0");

  cInvMassAntiLambdaWithdEdx->cd(2)->cd(2); 
  fMidPtAntiLambdaSampleWithdEdx->GetXaxis()->SetTitleOffset(1.1);
  fMidPtAntiLambdaSampleWithdEdx->GetYaxis()->SetTitleOffset(2.33);
  fMidPtAntiLambdaSampleWithdEdx->GetYaxis()->SetTitle("Counts/Event");
  fMidPtAntiLambdaSampleWithdEdx->Draw(); 
  Tl.DrawLatex(.25, .9277, "1.5 < p_{T} (GeV/c^{2}) < 2.5");

  cInvMassAntiLambdaWithdEdx->cd(2)->cd(3); 
  fHiPtAntiLambdaSampleWithdEdx->GetXaxis()->SetTitleOffset(1.1);
  fHiPtAntiLambdaSampleWithdEdx->GetYaxis()->SetTitleOffset(2.33);
  fHiPtAntiLambdaSampleWithdEdx->GetYaxis()->SetTitle("Counts/Event");
  fHiPtAntiLambdaSampleWithdEdx->Draw(); 
  Tl.DrawLatex(.25, .9277, "5 < p_{T} (GeV/c^{2}) < 10"); 

  if( lAttemptInvMassFit ){ 
    //Attempt rough signal extraction   
    TF1 *fal1 = new TF1("fal1","[0]+[1]*x+[2]*x*x+[3]*TMath::Gaus(x,[4],[5])",1.095, 1.14);
    //Reasonable first guess
    fal1->SetParameter(0, fLowPtAntiLambdaSampleWithdEdx -> GetBinContent( fLowPtAntiLambdaSampleWithdEdx->FindBin(1.116+0.01) ) );
    fal1->SetParameter(1, 0 );
    fal1->SetParameter(2, 0 );
    fal1->SetParameter(3, 0.35*fLowPtAntiLambdaSampleWithdEdx->GetMaximum() ); 
    fal1->SetParameter(4, 1.115683);
    fal1->SetParLimits(4,1.116-0.01,1.116+0.01);
    fal1->SetParameter(5, 0.002);
    fal1->SetParLimits(5,0.0005,0.01);
    cout<<"Will now fit, please wait!"<<endl;
    fLowPtAntiLambdaSampleWithdEdx->Fit("fal1","REM0");
    cInvMassAntiLambdaWithdEdx->cd(2)->cd(1); 
    fal1->Draw("same"); 
    //Peak Position, Width: printout 
    fLowPtAntiLambdaSampleWithdEdx->GetYaxis()->SetRangeUser(0,fLowPtAntiLambdaSampleWithdEdx->GetMaximum() * 1.2);
    Tli.DrawLatex(0.2,0.8,Form("peak = %.4f #pm %.4f MeV/c^{2}",fal1->GetParameter(4),fal1->GetParameter(5)) ) ;
    
    //Attempt rough signal extraction   
    TF1 *fal2 = new TF1("fal2","[0]+[1]*x+[2]*x*x+[3]*TMath::Gaus(x,[4],[5])",1.085, 1.15);
    //Reasonable first guess
    fal2->SetParameter(0, fMidPtAntiLambdaSampleWithdEdx -> GetBinContent( fMidPtAntiLambdaSampleWithdEdx->FindBin(1.116+0.01) ) );
    fal2->SetParameter(1, 0 );
    fal2->SetParameter(2, 0 );
    fal2->SetParameter(3, 0.6*fMidPtAntiLambdaSampleWithdEdx->GetMaximum() ); 
    fal2->SetParLimits(4,1.116-0.01,1.116+0.01);
    fal2->SetParameter(4, 1.116);
    fal2->SetParameter(5, 0.0025);
    fal2->SetParLimits(5,0.0005,0.01);
    cout<<"Will now fit, please wait!"<<endl;
    fMidPtAntiLambdaSampleWithdEdx->Fit("fal2","REM0");
    cInvMassAntiLambdaWithdEdx->cd(2)->cd(2); 
    fal2->Draw("same"); 
    //Peak Position, Width: printout 
    fMidPtAntiLambdaSampleWithdEdx->GetYaxis()->SetRangeUser(0,fMidPtAntiLambdaSampleWithdEdx->GetMaximum() * 1.2);
    Tli.DrawLatex(0.2,0.8,Form("peak = %.4f #pm %.4f MeV/c^{2}",fal2->GetParameter(4),fal2->GetParameter(5)) ) ;

    //Attempt rough signal extraction   
    TF1 *fal3 = new TF1("fal3","[0]+[1]*x+[2]*x*x+[3]*TMath::Gaus(x,[4],[5])",1.095, 1.15);
    //Reasonable first guess
    fal3->SetParameter(0, fHiPtAntiLambdaSampleWithdEdx -> GetBinContent( fHiPtAntiLambdaSampleWithdEdx->FindBin(1.116+0.01) ) );
    fal3->SetParameter(1, 0 );
    fal3->SetParameter(2, 0 );
    fal3->SetParameter(3, 0.6*fHiPtAntiLambdaSampleWithdEdx->GetMaximum() ); 
    fal3->SetParameter(4, 1.116);
    fal3->SetParLimits(4,1.116-0.005,1.116+0.005);
    fal3->SetParameter(5, 0.0035);
    fal3->SetParLimits(5,0.0005,0.01);
    cout<<"Will now fit, please wait!"<<endl;
    fHiPtAntiLambdaSampleWithdEdx->Fit("fal3","REM0");
    cInvMassAntiLambdaWithdEdx->cd(2)->cd(3); 
    fal3->Draw("same"); 
    //Peak Position, Width: printout 
    fHiPtAntiLambdaSampleWithdEdx->GetYaxis()->SetRangeUser(0,fHiPtAntiLambdaSampleWithdEdx->GetMaximum() * 1.2);
    Tli.DrawLatex(0.2,0.8,Form("peak = %.4f #pm %.4f MeV/c^{2}",fal3->GetParameter(4),fal3->GetParameter(5)) ) ;
  }

 
  if      (output == "png") cInvMassAntiLambdaWithdEdx->SaveAs("LF_QAanalysis_V0_page4.png");
  else if (output == "eps") cInvMassAntiLambdaWithdEdx->SaveAs("LF_QAanalysis_V0_page4.eps");
  else if (output == "pdf") cInvMassAntiLambdaWithdEdx->SaveAs("LF_QAanalysis_V0.pdf");

  //==============================================================  

  //==============================================================  
  // Strict Lambda Analysis for dE/dx Calibration Check 
  TH2D *f2dHistdEdxSignalPionFromLambda    = (TH2D*)clist->FindObject("f2dHistdEdxSignalPionFromLambda");
  TH2D *f2dHistdEdxSignalProtonFromLambda  = (TH2D*)clist->FindObject("f2dHistdEdxSignalProtonFromLambda");
  TH2D *f2dHistResponsePionFromLambda      = (TH2D*)clist->FindObject("f2dHistResponsePionFromLambda");
  TH2D *f2dHistResponseProtonFromLambda    = (TH2D*)clist->FindObject("f2dHistResponseProtonFromLambda");

  f2dHistdEdxSignalPionFromLambda->Rebin2D(2,10);
  f2dHistdEdxSignalProtonFromLambda->Rebin2D(2,10);
    
  
  TH1D *fLowPtPionResponse = (TH1D*) f2dHistResponsePionFromLambda->ProjectionY( "fLowPtPionResponse", 
    f2dHistResponsePionFromLambda->GetXaxis()->FindBin(0.5001),
    f2dHistResponsePionFromLambda->GetXaxis()->FindBin(0.9999) );

  TH1D *fMidPtPionResponse = (TH1D*) f2dHistResponsePionFromLambda->ProjectionY( "fMidPtPionResponse", 
    f2dHistResponsePionFromLambda->GetXaxis()->FindBin(1.5001),
    f2dHistResponsePionFromLambda->GetXaxis()->FindBin(2.4999) );

  TH1D *fLowPtProtonResponse = (TH1D*) f2dHistResponseProtonFromLambda->ProjectionY( "fLowPtProtonResponse", 
    f2dHistResponseProtonFromLambda->GetXaxis()->FindBin(0.5001),
    f2dHistResponseProtonFromLambda->GetXaxis()->FindBin(0.9999) );

  TH1D *fMidPtProtonResponse = (TH1D*) f2dHistResponseProtonFromLambda->ProjectionY( "fMidPtProtonResponse", 
    f2dHistResponseProtonFromLambda->GetXaxis()->FindBin(1.5001),
    f2dHistResponseProtonFromLambda->GetXaxis()->FindBin(2.4999) );



  TCanvas *cdEdxPure = new TCanvas("cdEdxPure","",1500,800);
  cdEdxPure->Divide(4,2); 

  for(Int_t ic = 1; ic<9; ic++){ 
    cdEdxPure->SetLeftMargin(0.15);
    cdEdxPure->cd(ic)->SetLogz();
    //cdEdxPure->cd(ic)->SetTopMargin(0.133);
    if( ic%4 == 1 || ic%4 == 2){
      cdEdxPure->cd(ic)->SetRightMargin(0.133);
    }
    if( ic%4 != 1 && ic%4 != 2){
      cdEdxPure->cd(ic)->SetGridx();
      cdEdxPure->cd(ic)->SetGridy();
    }
  }



  cdEdxPure->cd(1); 
  f2dHistdEdxSignalPionFromLambda->Draw("colz"); 
  cdEdxPure->cd(2); 
  f2dHistResponsePionFromLambda->Draw("colz"); 
  cdEdxPure->cd(3); 
  fLowPtPionResponse->Draw();
  cdEdxPure->cd(4); 
  fMidPtPionResponse->Draw();

  cdEdxPure->cd(5); 
  f2dHistdEdxSignalProtonFromLambda->Draw("colz"); 
  cdEdxPure->cd(6); 
  f2dHistResponseProtonFromLambda->Draw("colz"); 
  cdEdxPure->cd(7); 
  fLowPtProtonResponse->Draw();
  cdEdxPure->cd(8); 
  fMidPtProtonResponse->Draw();



  //Write explanations on canvases
  cdEdxPure->cd(1); Tl.DrawLatex(.25, .9277, "#pi^{-} from #Lambda: TPC Signal");
  cdEdxPure->cd(2); Tl.DrawLatex(.15, .9277, "#pi^{-} from #Lambda: AliPIDResponse Value");
  cdEdxPure->cd(3); Tl.DrawLatex(.21, .9277, "#pi^{-} N#sigma, 0.5 < p_{T} (GeV/c) < 1.0");
  cdEdxPure->cd(4); Tl.DrawLatex(.21, .9277, "#pi^{-} N#sigma, 1.5 < p_{T} (GeV/c) < 2.5");

  cdEdxPure->cd(5); Tl.DrawLatex(.25, .9277, "p from #Lambda: TPC Signal");
  cdEdxPure->cd(6); Tl.DrawLatex(.15, .9277, "p from #Lambda: AliPIDResponse Value");
  cdEdxPure->cd(7); Tl.DrawLatex(.21, .9277, "p N#sigma, 0.5 < p_{T} (GeV/c) < 1.0");
  cdEdxPure->cd(8); Tl.DrawLatex(.21, .9277, "p N#sigma, 1.5 < p_{T} (GeV/c) < 2.5");

  Double_t lLowPtPeakPion         = fLowPtPionResponse->GetBinCenter( fLowPtPionResponse->GetMaximumBin() );
  Double_t lMidPtPeakPion         = fMidPtPionResponse->GetBinCenter( fMidPtPionResponse->GetMaximumBin() );
  Double_t lLowPtPeakProton       = fLowPtProtonResponse->GetBinCenter( fLowPtProtonResponse->GetMaximumBin() );
  Double_t lMidPtPeakProton       = fMidPtProtonResponse->GetBinCenter( fMidPtProtonResponse->GetMaximumBin() );

  //List Maximal Values
  cout<<"Maximal Value for pion from Lambda at low pt...............: " <<lLowPtPeakPion<<endl;
  cout<<"Maximal Value for pion from Lambda at mid pt...............: " <<lMidPtPeakPion<<endl;
  cout<<"Maximal Value for proton from Lambda at low pt.............: " <<lLowPtPeakProton<<endl;
  cout<<"Maximal Value for proton from Lambda at mid pt.............: " <<lMidPtPeakProton<<endl;

  if( TMath::Abs( lLowPtPeakPion ) > 0.3)   cout<<"*** WARNING: Check Low Pt pion PID Response! ***"<<endl;
  if( TMath::Abs( lMidPtPeakPion ) > 0.3)   cout<<"*** WARNING: Check Mid Pt pion PID Response! ***"<<endl;
  if( TMath::Abs( lLowPtPeakProton ) > 0.3) cout<<"*** WARNING: Check Low Pt proton PID Response! ***"<<endl;
  if( TMath::Abs( lMidPtPeakProton ) > 0.3) cout<<"*** WARNING: Check Mid Pt proton PID Response! ***"<<endl;

  TLatex Tlq;
  Tlq.SetNDC();
  Tlq.SetTextSize(0.06);

  //Draw Arrows to be sure!
  Double_t lFractionHeight = 0.33;
  cdEdxPure->cd(3);  
  TArrow *ar1 = new TArrow(lLowPtPeakPion,lFractionHeight * fLowPtPionResponse->GetMaximum(),lLowPtPeakPion,0.0, 0.008 ,"|>");
  ar1->SetLineWidth(2);
  ar1->Draw();
  if( TMath::Abs( lLowPtPeakPion ) < 0.3) {
    Tlq.SetTextColor(8); 
    Tlq.DrawLatex ( 0.15,0.8, "OK!");
  } else { 
    Tlq.SetTextColor(kRed); 
    Tlq.DrawLatex ( 0.15,0.8, "Prob.! Check dEd/x!");
  }

  cdEdxPure->cd(4);  
  TArrow *ar2 = new TArrow(lMidPtPeakPion,lFractionHeight * fMidPtPionResponse->GetMaximum(),lLowPtPeakPion,0.0, 0.008 ,"|>");
  ar2->SetLineWidth(2);
  ar2->Draw();
  if( TMath::Abs( lMidPtPeakPion ) < 0.3) {
    Tlq.SetTextColor(8); 
    Tlq.DrawLatex ( 0.15,0.8, "OK!");
  } else { 
    Tlq.SetTextColor(kRed); 
    Tlq.DrawLatex ( 0.15,0.8, "Prob.! Check dEd/x!");
  }
  
  cdEdxPure->cd(7);  
  TArrow *ar3 = new TArrow(lLowPtPeakProton,lFractionHeight * fLowPtProtonResponse->GetMaximum(),lLowPtPeakPion,0.0, 0.008 ,"|>");
  ar3->SetLineWidth(2);
  ar3->Draw();
  if( TMath::Abs( lLowPtPeakProton ) < 0.3) {
    Tlq.SetTextColor(8); 
    Tlq.DrawLatex ( 0.15,0.8, "OK!");
  } else { 
    Tlq.SetTextColor(kRed); 
    Tlq.DrawLatex ( 0.15,0.8, "Prob.! Check dEd/x!");
  }

  cdEdxPure->cd(8);  
  TArrow *ar4 = new TArrow(lMidPtPeakProton,lFractionHeight * fMidPtProtonResponse->GetMaximum(),lLowPtPeakPion,0.0, 0.008 ,"|>");
  ar4->SetLineWidth(2);
  ar4->Draw();
  if( TMath::Abs( lMidPtPeakProton ) < 0.3) {
    Tlq.SetTextColor(8); 
    Tlq.DrawLatex ( 0.15,0.8, "OK!");
  } else { 
    Tlq.SetTextColor(kRed); 
    Tlq.DrawLatex ( 0.15,0.8, "Prob.! Check dEd/x!");
  }

  if      (output == "png") cdEdxPure->SaveAs("LF_QAanalysis_V0_page5.png");
  else if (output == "eps") cdEdxPure->SaveAs("LF_QAanalysis_V0_page5.eps");
  else if (output == "pdf") cdEdxPure->SaveAs("LF_QAanalysis_V0.pdf");


  //==============================================================

  //==============================================================    
  //Topological variable QA
  // FIXME: This is still only a rough first version. 
  // Adjustments will be required for easy / long-term operation.
  TH1D *fHistTopDCAPosToPV      = (TH1D*)clist->FindObject("fHistSelectedTopDCAPosToPV");
  TH1D *fHistTopDCANegToPV      = (TH1D*)clist->FindObject("fHistSelectedTopDCANegToPV");
  TH1D *fHistTopDCAV0Daughters  = (TH1D*)clist->FindObject("fHistSelectedTopDCAV0Daughters");
  TH1D *fHistTopCosinePA        = (TH1D*)clist->FindObject("fHistSelectedTopCosinePA");
  TH1D *fHistTopV0Radius        = (TH1D*)clist->FindObject("fHistSelectedTopV0Radius");

  //Zoom in on selection in Cosine of pointing angle...
  Int_t iLowBin=-1; 
  Int_t iLowBin2 = -1; 
  Int_t iLowBin3 = -1; 

  //Normalize to per-event 
  fHistTopDCAPosToPV      -> Scale ( 1. / ((Double_t)fHistEvent->GetBinContent(4) ) );
  fHistTopDCANegToPV      -> Scale ( 1. / ((Double_t)fHistEvent->GetBinContent(4) ) );
  fHistTopDCAV0Daughters  -> Scale ( 1. / ((Double_t)fHistEvent->GetBinContent(4) ) );
  fHistTopCosinePA        -> Scale ( 1. / ((Double_t)fHistEvent->GetBinContent(4) ) );
  fHistTopV0Radius        -> Scale ( 1. / ((Double_t)fHistEvent->GetBinContent(4) ) );

  fHistTopDCAPosToPV      -> GetYaxis() -> SetTitle("Counts / Event");
  fHistTopDCANegToPV      -> GetYaxis() -> SetTitle("Counts / Event");
  fHistTopDCAV0Daughters  -> GetYaxis() -> SetTitle("Counts / Event");
  fHistTopCosinePA        -> GetYaxis() -> SetTitle("Counts / Event");
  fHistTopV0Radius        -> GetYaxis() -> SetTitle("Counts / Event");

  fHistTopDCAPosToPV      -> GetYaxis() -> SetTitleSize(0.05);
  fHistTopDCANegToPV      -> GetYaxis() -> SetTitleSize(0.05);
  fHistTopDCAV0Daughters  -> GetYaxis() -> SetTitleSize(0.05);
  fHistTopCosinePA        -> GetYaxis() -> SetTitleSize(0.05);
  fHistTopV0Radius        -> GetYaxis() -> SetTitleSize(0.05);

  fHistTopDCAPosToPV      -> GetXaxis() -> SetTitleSize(0.05);
  fHistTopDCANegToPV      -> GetXaxis() -> SetTitleSize(0.05);
  fHistTopDCAV0Daughters  -> GetXaxis() -> SetTitleSize(0.05);
  fHistTopCosinePA        -> GetXaxis() -> SetTitleSize(0.05);
  fHistTopV0Radius        -> GetXaxis() -> SetTitleSize(0.05);

  Double_t lMinimumCosPADraw = 1.-1.25*(1.-GetXForMinValue ( fHistTopCosinePA ) ); //assumes monotonically increasing dist
  cout<<"Function test: "<< lMinimumCosPADraw <<endl;
  fHistTopCosinePA->GetXaxis()->SetRangeUser(lMinimumCosPADraw,1.001);  

  Double_t lmin[5]; 
  Double_t lminPrecision[5]; 
  lmin[3] = GetXForMinValue ( fHistTopCosinePA );
  lmin[4] = GetXForMinValue ( fHistTopV0Radius );
  lmin[0] = GetXForMaxValue ( fHistTopDCAPosToPV );
  lmin[1] = GetXForMaxValue ( fHistTopDCANegToPV );
  lmin[2] = GetXForMinValue ( fHistTopDCAV0Daughters );

  lminPrecision[3] = fHistTopCosinePA        -> GetBinWidth(1);
  lminPrecision[4] = fHistTopV0Radius        -> GetBinWidth(1);
  lminPrecision[0] = fHistTopDCAPosToPV      -> GetBinWidth(1);
  lminPrecision[1] = fHistTopDCANegToPV      -> GetBinWidth(1);
  lminPrecision[2] = fHistTopDCAV0Daughters  -> GetBinWidth(1);

  cout<<"Minimum Values Found: "<<endl;
  cout<<"Cosine of Pointing Angle...........: "<<GetXForMinValue (fHistTopCosinePA )<<" precision = "<<lminPrecision[3]<<endl;
  cout<<"DCA Neg Daughter to PV.............: "<<GetXForMaxValue (fHistTopDCAPosToPV )<<" precision = "<<lminPrecision[1]<<endl;
  cout<<"DCA Pos Daughter to PV.............: "<<GetXForMaxValue (fHistTopDCANegToPV )<<" precision = "<<lminPrecision[0]<<endl;
  cout<<"DCA V0 Daughers....................: "<<GetXForMinValue (fHistTopDCAV0Daughters )<<" precision = "<<lminPrecision[2]<<endl;
  cout<<"V0 Decay Radius....................: "<<GetXForMinValue (fHistTopV0Radius )<<" precision = "<<lminPrecision[4]<<endl;


  TCanvas *cTopo = new TCanvas ("cTopo","",1200,800);
  cTopo->Divide(3,2); 
  for(Int_t ic = 1; ic<7; ic++){ 
    cTopo->cd(ic)->SetLeftMargin(0.15);
    cTopo->cd(ic)->SetGridx(); 
    cTopo->cd(ic)->SetGridy(); 
  }

  cTopo->cd(1);   
  fHistTopDCAPosToPV->Draw(); 
  cTopo->cd(2);   
  fHistTopDCANegToPV->Draw(); 
  cTopo->cd(3);   
  fHistTopDCAV0Daughters->Draw(); 
  cTopo->cd(4);   
  fHistTopCosinePA->Draw(); 
  cTopo->cd(5);   
  fHistTopV0Radius->Draw(); 

  TLatex Tlt;
  Tlt.SetNDC();
  Tlt.SetTextSize(0.05);
  cTopo->cd(6);
    
  Tlt.DrawLatex(.22, .9, "Boundary Checks")  ;


        
  TString lCut[5];
  lCut [ 0 ] = "Min DCA Pos D. To PV (cm)";
  lCut [ 1 ] = "Min DCA Neg D. To PV (cm)";
  lCut [ 2 ] = "Max DCA V0 Daughters (#sigma)";
  lCut [ 3 ] = "Min Cosine PA";
  lCut [ 4 ] = "Min 2D Decay Radius (cm)";

  TString lCutVal[5]; 
  TString lCutValPrec[5]; 
    
  Tlt.SetTextSize(0.04);
  Tlt.SetTextFont(42);

  Tlt.DrawLatex(.01, .80, "Topological Var.")  ;
  Tlt.DrawLatex(.6, .80, "Value")  ;
  Tlt.DrawLatex(.75, .80, "Precision")  ;

  for (Int_t il=0;il<5;il++){ 
    Tlt.DrawLatex(.01,0.72-((double)il)*0.075, lCut[il].Data() );
    lCutVal[il] = Form( "%.4f", lmin[il] );
    Tlt.DrawLatex(.5925,0.72-((double)il)*0.075, lCutVal[il].Data() );
    lCutValPrec[il] = Form( "%.4f", lminPrecision[il] );
    Tlt.DrawLatex(.7675,0.72-((double)il)*0.075, lCutValPrec[il].Data() );
  }

  Tlt.SetTextSize(0.05);
  Tlt.SetTextFont(42);

  //Try to make a wild guess... 
  if ( TMath::Abs( lmin[0] - 0.100 ) < 2*lminPrecision[0] &&
       TMath::Abs( lmin[1] - 0.100 ) < 2*lminPrecision[1] &&
       TMath::Abs( lmin[2] - 1.000 ) < 2*lminPrecision[2] &&
       TMath::Abs( lmin[3] - 0.998 ) < 2*lminPrecision[3] &&
       TMath::Abs( lmin[4] - 0.500 ) < 2*lminPrecision[4] ){
    Tlt.DrawLatex( 0.17, 0.275, "#bf{Autodetect Interpretation}: "); 
    Tlt.DrawLatex( 0.1, 0.2, "Typical #bf{Pb-Pb} Reconstruction Cuts");
  }
  if ( TMath::Abs( lmin[0] - 0.020 ) < 2*lminPrecision[0] &&
       TMath::Abs( lmin[1] - 0.020 ) < 2*lminPrecision[1] &&
       TMath::Abs( lmin[2] - 1.500 ) < 2*lminPrecision[2] &&
       TMath::Abs( lmin[3] - 0.98 )  < 2*lminPrecision[3] &&
       TMath::Abs( lmin[4] - 0.500 ) < 2*lminPrecision[4] ){
    Tlt.DrawLatex( 0.15, 0.29, "#bf{Autodetect Interpretation}: ");  
    Tlt.DrawLatex( 0.1, 0.2, "Typical pp Reconstruction Cuts"); //To be checked
  }

  if      (output == "png") cTopo->SaveAs("LF_QAanalysis_V0_page6.png");
  else if (output == "eps") cTopo->SaveAs("LF_QAanalysis_V0_page6.eps");
  else if (output == "pdf") cTopo->SaveAs("LF_QAanalysis_V0.pdf)");


}
Esempio n. 23
0
void AnalysisBase::findCutoutRegion(TH2F* h){

  cout << "===============================================================" << endl;
  cout << "findCutoutRegion(): Looking for cutout region in D type sensor " << endl;
  cout << "===============================================================" << endl;


  int ilx = h->GetXaxis()->FindBin(xMin) + 1;
  int ihx = h->GetXaxis()->FindBin(xMax) - 1;
  int ily = 1;//h->GetYaxis()->GetBinFindBin(yMin) - 10;
  int ihy = h->GetYaxis()->FindBin(yMax) + 10;
  if(ily < 0) ily = 0;
  if(ihy > h->GetYaxis()->GetNbins()) ihy = h->GetYaxis()->GetNbins();  
  int nb = h->GetXaxis()->GetNbins(); 

  double xlow = h->GetXaxis()->GetBinLowEdge(1);
  double xhi = h->GetXaxis()->GetBinLowEdge(nb)+h->GetXaxis()->GetBinWidth(1);

  TH1F *hpr = new TH1F("hpr","Y vs X, edge",nb,xlow,xhi);

  TH1D *hpy;
  int ipeak = 0;
  for(int i=ilx; i<ihx-1; i++){
    hpy = h->ProjectionY("hpy",i,i);
    double maxcon  = 0.0;
    double maxbin  = 0.0;
    for(int j=ily;j<ihy;j++){
      maxcon = maxcon + hpy->GetBinContent(j);
      if(hpy->GetBinContent(j) > maxbin) {
        maxbin = hpy->GetBinContent(j) ;
        ipeak = j;
      }
    }
    // Find the lower "edge"
    for(int j=ipeak; j>=ily; j--){
      double r0 = (hpy->GetBinContent(j-1)+hpy->GetBinContent(j-2))/2.0;
      double r1 = hpy->GetBinContent(j);
      double r2 = (hpy->GetBinContent(j+3)+hpy->GetBinContent(j+4))/2.0;
      if(r1<=2 && r0<=1.5 && r2>5*r1 && r2>8){
        hpr->SetBinContent(i,hpy->GetBinCenter(j)+2*hpy->GetBinWidth(j));
        hpr->SetBinError(i,hpy->GetBinWidth(1)/2.0);
        //cout << "found: " << i << " " << hpy->GetEntries() << " " << hpy->GetBinCenter(j) << " " 
        //     << hpy->GetBinContent(j) << " " << r0 << " " << r1 << " " << r2 << " " << endl;
        break;
      }
    }
    
  }

  TF1* poly2 = new TF1("poly2","[0]+[1]*x+[2]*x*x",xMin,xMax);
  poly2->SetParameters(-1.5,-0.17,-0.15);
  hpr->Fit(poly2,"R0");
  hpr->SetLineColor(kRed);

  holeQuadPar[0] = poly2->GetParameter(0);
  holeQuadPar[1] = poly2->GetParameter(1);
  holeQuadPar[2] = poly2->GetParameter(2);

  //return;
  

  delete poly2;
  delete hpr;
  delete hpy;
  
  return;
}
Esempio n. 24
0
void reconstruction(TString infile = "../build/reco_spr.root", 
					int num_events = 10000, 
					char *runtype = "data", 
					double tdiff = 1.5)
{
	gErrorIgnoreLevel = kWarning; // ignore 'Info in...' messages
	gStyle->SetOptFit(1111); // show fit parameters
	gStyle->SetOptStat(0);   // remove stats box
	TGaxis::SetMaxDigits(4); // put axis in scientific notation

	TFile *f = TFile::Open(infile); 
	TTree *t = (TTree*)f->Get("reco"); //Lee's Tree
	TTree *d = (TTree*)f->Get("dirc"); //Roman's Tree

	// set value of lens and alpha from dirc tree
	int lens(0);
	double angle(0),beam(0),yield(0),nph(0);
	d->SetBranchAddress("lens",&lens);
	d->SetBranchAddress("theta",&angle);
	d->SetBranchAddress("beam",&beam);
	d->SetBranchAddress("yield",&yield);
	d->SetBranchAddress("nph",&nph);
	d->GetEntry(0);

	// get time-expt peak value
	TH1D *diff = new TH1D("diff","diff",100,-5,5);
	t->Project("diff","diff");
	double diffmax = diff->GetBinCenter(diff->GetMaximumBin());

	// define cuts and save path
	char *sim_cut  = Form("abs(diff-%f)<%f",diffmax,tdiff);
	char *data_cut = Form("abs(diff-%f)<%f",diffmax,tdiff);
	char *savepath = "../macro/timecuts";

	// define cut and project from tree to histogram w/ proper cuts
	theta = new TH1D("theta","theta",100,0.6,1.0);
	if(runtype=="data") // do all the data things
	{
		// make counter histograms for cut
		TH1D *tof1 = new TH1D("time-tof1","time-tof1",1000,0,1000);
		TH1D *tof2 = new TH1D("time-tof2","time-tof2",1000,0,1000);
		TH1D *trig = new TH1D("time-trig","time-trig",1000,0,1000);

		// project onto counter histograms
		t->Project("time-tof1","time-tof1");
		t->Project("time-tof2","time-tof2");
		t->Project("time-trig","time-trig");
	
		// make cuts w/ counters
		cntrCut(tof1, data_cut, "time-tof1");
		cntrCut(tof2, data_cut, "time-tof2");
		cntrCut(trig, data_cut, "time-trig");
		//cout << "data cut\t" << data_cut << endl;

		/*
		// make counter hists pretty (and distinguishable)
		tof1->SetTitle(data_cut);
		tof1->SetTitleSize(0.5);
		tof1->SetLineColor(kBlue);
		tof2->SetLineColor(kRed);
		trig->SetLineColor(kGreen);

		// draw histograms and save canvas
		char *cname = Form("%s/reco_%s_%d_%d_ccuts.png",
					  savepath,runtype,lens,(int)angle);
		TCanvas *ccanv = new TCanvas();
		gPad->SetLogy();
		tof1->Draw();
		tof2->Draw("same");
		trig->Draw("same");
		ccanv->Print(cname);
		*/

		t->Project("theta","theta",data_cut);
	}
	else
		t->Project("theta","theta",sim_cut);

	// preliminary paramters for fit of theta
	double height = theta->GetMaximum();
	double center = theta->GetBinCenter(theta->GetMaximumBin());
	double sigma  = 0.015;
	double slope  = 1.0;
	double shift  = height/3;

	// define custom fit, set parameters, and fit to data
	TF1 *gaus0 = new TF1("gaus0", "gaus+[3]*x+[4]", 
						 center-0.05, center+0.05);
	gaus0->SetParameters(height,center,sigma,slope,shift);
	gaus0->SetParNames("height","mean","sigma","slope","const");
	theta->Fit("gaus0","QR");
	double truesig = 1000*gaus0->GetParameter("sigma");
	
	// define strings for picture and root file names
	char *namt = Form("theta_{c} lens %d angle %d diff %1.2f",
					  lens,(int)angle,tdiff);
	char *pict = Form("%s/reco_%s_%d_%d_%1.2f.png",
					  savepath,runtype,lens,(int)angle,tdiff);

	/*
	// format histogram for saving
	TCanvas *c1 = new TCanvas();
	c1->cd();
	double max = 1.1*theta->GetMaximum();
	theta->SetTitle("");
	theta->GetXaxis()->SetLabelSize(0.06);
	theta->GetYaxis()->SetLabelSize(0.06);
	theta->GetXaxis()->SetRangeUser(0.61,1);
	theta->GetYaxis()->SetRangeUser(0,max);
	theta->Draw();
	c1->Print(pict);

	// save histogram again without fit parameters
   	gStyle->SetOptFit(0);
	c1->cd();
	theta->Draw();
	pict = Form("%s/reco_%s_%d_%d_%1.2f_nofit.png",
				savepath,runtype,lens,(int)angle,tdiff);
	c1->Print(pict);
	*/

	// print relevant info to screen and file
	char *outnm = Form("../macro/timecut_%s.tsv",runtype);
	ofstream out;
	out.open(outnm, fstream::in | fstream::out | fstream::app);
	out << angle 
		<< "\t" << lens  
		<< "\t" << tdiff
		<< "\t" << truesig
		<< "\t" << yield 
		<< "\t" << nph << endl;
	out.close();
	cout << "\033[1;31m" 
		 << "\nangle:\t" << angle
		 << "\nlens:\t"  << lens
		 << "\ndiff:\t"  << tdiff
		 << "\npeak:\t"  << diffmax
		 << "\nsigma:\t" << truesig
		 << "\nhits/e:\t" << nph
		 << "\nphts/e:\t" << yield 
		 << "\033[0m" <<  endl;
	TFile *tfile = new TFile(Form("timecut_%1.1f_%d_%1.2f.root",
								  angle,lens,tdiff),"create");
	TTree *ttree = new TTree("tcut","tcut");
	ttree->Branch("angle",&angle,"angle/D");
	ttree->Branch("lens",&lens,"lens/I");
	ttree->Branch("tcut",&tdiff,"tcut/D");
	ttree->Branch("sigma",&truesig,"truesig/D");
	ttree->Branch("nph",&yield,"yield/D");

	ttree->Fill();
	ttree->Write();
	tfile->Delete();
}
TF1* GeneralCorrectionFunction(
								double ChannelRangeMin, double ChannelRangeMax,double ChannelPeakPos ,
								TH2D *h2DInputForCorrection ,
								int LineIndex,
								TString InputType="T10DeriMaxEnergy",
								TString CorrNumber="1",
								double XRangeMin=0, double XRangeMax=300,
								TString FitFuncCorr="pol2",
								double FitCorrRangeMin=10, double FitCorrRangeMax= 270,
								double TresholdForCorrection=10,
								TString FitFuncSlicesString="gaus(0)+[3]+gaus(4)"
								
								
)
{
	h2DInputForCorrection->GetYaxis()->SetRangeUser(ChannelRangeMin,ChannelRangeMax);
	char buf[60];
	sprintf(buf, "hMaxCorr%s_%s_%d",CorrNumber.Data(),InputType.Data(),LineIndex);
	TH1D *hMaxPosManually=new TH1D(buf,"",h2DInputForCorrection->GetNbinsX(),h2DInputForCorrection->GetXaxis()->GetXmin(),h2DInputForCorrection->GetXaxis()->GetXmax());
	sprintf(buf, "hMaxFitCorr%s_%s_%d",CorrNumber.Data(),InputType.Data(),LineIndex);
	TH1D *hMaxPosManuallyFit=new TH1D(buf,"",h2DInputForCorrection->GetNbinsX(),h2DInputForCorrection->GetXaxis()->GetXmin(),h2DInputForCorrection->GetXaxis()->GetXmax());
	sprintf(buf, "hGausSigmaCorr%s_%s_%d",CorrNumber.Data(),InputType.Data(),LineIndex);
	TH1D *hGausSigmaManually=new TH1D(buf,"",h2DInputForCorrection->GetNbinsX(),h2DInputForCorrection->GetXaxis()->GetXmin(),h2DInputForCorrection->GetXaxis()->GetXmax());
	for(int binX = h2DInputForCorrection->GetXaxis()->FindBin(XRangeMin);binX <= h2DInputForCorrection->GetXaxis()->FindBin(XRangeMax);binX++)
	//for(int binX = h2DInputForCorrection->GetXaxis()->FindBin(200);binX <= h2DInputForCorrection->GetXaxis()->FindBin(200);binX++)
	{
		TH1D *hProfileY =h2DInputForCorrection->ProjectionY("_py",binX,binX);	
		double MaxValue=hProfileY->GetBinCenter(hProfileY->GetMaximumBin());
		
		//hMaxPosManually->SetBinContent(binX, MaxValue);
		//h2DInputForCorrection
		//cout <<hProfileY->GetEntries()<<endl;
		//TF1* FitFuncSlices = new TF1("FitFuncSlices","gaus(0)+[3]",MaxValue-20,MaxValue+20);
		//cout << TMath::Max(MaxValue-20,double(ChannelRangeMin)) << "\t" << TMath::Min(MaxValue+20,double(ChannelRangeMax)) << "\t"<<endl;
		TF1* FitFuncGausSlices = new TF1("FitFuncGausSlices","gaus(0)",TMath::Max(MaxValue-20,double(ChannelRangeMin)),TMath::Min(MaxValue+20,double(ChannelRangeMax)));
		FitFuncGausSlices->SetParameters(hProfileY->GetBinContent(hProfileY->GetMaximumBin()),MaxValue,4);
		
		hProfileY->Fit(FitFuncGausSlices,"RNIQ");
		TF1* FitFuncSlices = new TF1("FitFuncSlices",FitFuncSlicesString.Data(),TMath::Max(MaxValue-3*FitFuncGausSlices->GetParameter(2),double(ChannelRangeMin)),TMath::Min(MaxValue+3*FitFuncGausSlices->GetParameter(2),double(ChannelRangeMax)));
		FitFuncSlices->SetParameters(FitFuncGausSlices->GetParameter(0),FitFuncGausSlices->GetParameter(1),FitFuncGausSlices->GetParameter(2),10,10,FitFuncGausSlices->GetParameter(1)-5,5);
		
		FitFuncSlices->SetParLimits(0,FitFuncGausSlices->GetParameter(0)*0.8,FitFuncGausSlices->GetParameter(0)*1.5);
		FitFuncSlices->SetParLimits(1,TMath::Max(FitFuncGausSlices->GetParameter(1)-10,double(ChannelRangeMin)),TMath::Min(FitFuncGausSlices->GetParameter(1)+10,double(ChannelRangeMax)));
		FitFuncSlices->SetParLimits(2,0,FitFuncGausSlices->GetParameter(2)*2);
		FitFuncSlices->SetParLimits(3,0,500);
		FitFuncSlices->SetParLimits(4,0,FitFuncGausSlices->GetParameter(0)*0.3);
		
		FitFuncSlices->SetParLimits(5,TMath::Max(FitFuncGausSlices->GetParameter(1)-10,double(ChannelRangeMin)),TMath::Min(MaxValue-1,double(ChannelRangeMax)));
		FitFuncSlices->SetParLimits(6,0,10);
		hProfileY->Fit(FitFuncSlices,"RINQ");
		//hProfileY->DrawCopy();
		
		//cout <<MaxValue<<"  " << FitFuncSlices->GetParameter(1) << "   " << FitFuncSlices->GetParError(1) <<endl;
		//cout <<MaxValue<<"  " << FitFuncSlices->GetParameter(1) << "   " << FitFuncSlices->GetMaximumX() <<endl;
		hMaxPosManually->SetBinContent(binX, (FitFuncSlices->GetParameter(1))/ChannelPeakPos);
		hMaxPosManually->SetBinError(binX, FitFuncSlices->GetParError(1)/ChannelPeakPos);
		hGausSigmaManually->SetBinContent(binX, FitFuncSlices->GetParameter(2));
		hGausSigmaManually->SetBinError(binX, FitFuncSlices->GetParError(2));
		if(FitFuncSlices->GetParameter(2)<TresholdForCorrection && FitFuncSlices->GetParError(2)<5)
		{
			hMaxPosManuallyFit->SetBinContent(binX, (FitFuncSlices->GetParameter(1))/ChannelPeakPos);
			hMaxPosManuallyFit->SetBinError(binX, FitFuncSlices->GetParError(1)/ChannelPeakPos);
		}
		//hSpectrumTDeriMax1090Rel_EnergyChannel_MaxPosManually->SetBinError(binX, FitFuncSlices->GetParameter(2)/ChannelPeakPos);
		hProfileY->Delete();
		//cin.ignore();
	}
	//write histos to file
		
	//sprintf(buf, "hMaxCorr%s_%s_%d",CorrNumber.Data(),InputType.Data(),LineIndex);
	hMaxPosManually->Write(0,TObject::kOverwrite);
	//sprintf(buf, "hGausSigmaCorr%s_%s_%d",CorrNumber.Data(),InputType.Data(),LineIndex);
	hGausSigmaManually->Write(0,TObject::kOverwrite);
	hMaxPosManuallyFit->Write(0,TObject::kOverwrite);
	sprintf(buf, "funcCorr%s_%sNorm_%d",CorrNumber.Data(),InputType.Data(),LineIndex);
	//fit corr function and write it to file
	TF1 *funcCorrNorm = new TF1(buf,FitFuncCorr.Data(),FitCorrRangeMin,FitCorrRangeMax);
	funcCorrNorm->SetParameters(1,0,-0);
	
	funcCorrNorm->SetParLimits(0,0.8,1);
	//funcCorrNorm->SetParLimits(2,-1E5,0);
	//if(LineIndex==2)
	//	hMaxPosManuallyFit->Fit(funcCorrNorm,"RBI");
	//else
		hMaxPosManuallyFit->Fit(funcCorrNorm,"RBQI");
	sprintf(buf, "funcCorr%s_%s_%d",CorrNumber.Data(),InputType.Data(),LineIndex);
	TF1 *funcCorr = new TF1(buf,FitFuncCorr.Data(),FitCorrRangeMin,FitCorrRangeMax);
	for(int i= 0; i<funcCorr->GetNpar();i++)
	{
		funcCorr->SetParameter(i,funcCorrNorm->GetParameter(i)*ChannelPeakPos);
	}
	//sprintf(buf, "funcCorr%s_%sNorm_%d",CorrNumber.Data(),InputType.Data(),LineIndex);
	funcCorrNorm->Write(0,TObject::kOverwrite);
	//sprintf(buf, "funcCorr%s_%s_%d",CorrNumber.Data(),InputType.Data(),LineIndex);
	funcCorr->Write(0,TObject::kOverwrite);
	h2DInputForCorrection->GetYaxis()->UnZoom();
	return funcCorr;
}
Esempio n. 26
0
TH1D *
GetITSsaRatio(TFile *file, Int_t num, Int_t den, Int_t cent, Bool_t cutSpectrum = kTRUE, Bool_t addSystematicError = kTRUE)
{
  /* pt limits for combined spectra */
  //  Double_t ptMin[AliPID::kSPECIES] = {0., 0., 0.1, 0.2, 0.3};
  //  Double_t ptMax[AliPID::kSPECIES] = {0., 0., 0.6, 0.5, 0.6};

  TH1 *hnum, *hden;
  Double_t ptMin = 0., ptMax = 10.;
  switch (num) {
  case kPiMinus:
    ptMin = TMath::Min(ptMin, 0.1);
    ptMax = TMath::Min(ptMax, 0.6);
    hnum = GetITSsaSpectrum(file, AliPID::kPion, 1, cent, kFALSE, kFALSE);
    break;
  case kPiPlus:
    ptMin = TMath::Min(ptMin, 0.1);
    ptMax = TMath::Min(ptMax, 0.6);
    hnum = GetITSsaSpectrum(file, AliPID::kPion, 0, cent, kFALSE, kFALSE);
    break;
  case kPi:
    ptMin = TMath::Min(ptMin, 0.1);
    ptMax = TMath::Min(ptMax, 0.6);
    hnum = GetITSsaSpectrum(file, AliPID::kPion, 1, cent, kFALSE, kFALSE);
    hnum->Add(GetITSsaSpectrum(file, AliPID::kPion, 0, cent, kFALSE, kFALSE));
    break;
  case kKaMinus:
    ptMin = TMath::Min(ptMin, 0.2);
    ptMax = TMath::Min(ptMax, 0.5);
    hnum = GetITSsaSpectrum(file, AliPID::kKaon, 1, cent, kFALSE, kFALSE);
    break;
  case kKaPlus:
    ptMin = TMath::Min(ptMin, 0.2);
    ptMax = TMath::Min(ptMax, 0.5);
    hnum = GetITSsaSpectrum(file, AliPID::kKaon, 0, cent, kFALSE, kFALSE);
    break;
  case kKa:
    ptMin = TMath::Min(ptMin, 0.2);
    ptMax = TMath::Min(ptMax, 0.5);
    hnum = GetITSsaSpectrum(file, AliPID::kKaon, 1, cent, kFALSE, kFALSE);
    hnum->Add(GetITSsaSpectrum(file, AliPID::kKaon, 0, cent, kFALSE, kFALSE));
    break;
  case kPrMinus:
    ptMin = TMath::Min(ptMin, 0.3);
    ptMax = TMath::Min(ptMax, 0.6);
    hnum = GetITSsaSpectrum(file, AliPID::kProton, 1, cent, kFALSE, kFALSE);
    break;
  case kPrPlus:
    ptMin = TMath::Min(ptMin, 0.3);
    ptMax = TMath::Min(ptMax, 0.6);
    hnum = GetITSsaSpectrum(file, AliPID::kProton, 0, cent, kFALSE, kFALSE);
    break;
  case kPr:
    ptMin = TMath::Min(ptMin, 0.3);
    ptMax = TMath::Min(ptMax, 0.6);
    hnum = GetITSsaSpectrum(file, AliPID::kProton, 1, cent, kFALSE, kFALSE);
    hnum->Add(GetITSsaSpectrum(file, AliPID::kProton, 0, cent, kFALSE, kFALSE));
    break;
  }
  switch (den) {
  case kPiMinus:
    ptMin = TMath::Max(ptMin, 0.1);
    ptMax = TMath::Min(ptMax, 0.6);
    hden = GetITSsaSpectrum(file, AliPID::kPion, 1, cent, kFALSE, kFALSE);
    break;
  case kPiPlus:
    ptMin = TMath::Max(ptMin, 0.1);
    ptMax = TMath::Min(ptMax, 0.6);
    hden = GetITSsaSpectrum(file, AliPID::kPion, 0, cent, kFALSE, kFALSE);
    break;
  case kPi:
    ptMin = TMath::Max(ptMin, 0.1);
    ptMax = TMath::Min(ptMax, 0.6);
    hden = GetITSsaSpectrum(file, AliPID::kPion, 1, cent, kFALSE, kFALSE);
    hden->Add(GetITSsaSpectrum(file, AliPID::kPion, 0, cent, kFALSE, kFALSE));
    break;
  case kKaMinus:
    ptMin = TMath::Max(ptMin, 0.2);
    ptMax = TMath::Min(ptMax, 0.5);
    hden = GetITSsaSpectrum(file, AliPID::kKaon, 1, cent, kFALSE, kFALSE);
    break;
  case kKaPlus:
    ptMin = TMath::Max(ptMin, 0.2);
    ptMax = TMath::Min(ptMax, 0.5);
    hden = GetITSsaSpectrum(file, AliPID::kKaon, 0, cent, kFALSE, kFALSE);
    break;
  case kKa:
    ptMin = TMath::Max(ptMin, 0.2);
    ptMax = TMath::Min(ptMax, 0.5);
    hden = GetITSsaSpectrum(file, AliPID::kKaon, 1, cent, kFALSE, kFALSE);
    hden->Add(GetITSsaSpectrum(file, AliPID::kKaon, 0, cent, kFALSE, kFALSE));
    break;
  case kPrMinus:
    ptMin = TMath::Max(ptMin, 0.3);
    ptMax = TMath::Min(ptMax, 0.6);
    hden = GetITSsaSpectrum(file, AliPID::kProton, 1, cent, kFALSE, kFALSE);
    break;
  case kPrPlus:
    ptMin = TMath::Max(ptMin, 0.3);
    ptMax = TMath::Min(ptMax, 0.6);
    hden = GetITSsaSpectrum(file, AliPID::kProton, 0, cent, kFALSE, kFALSE);
    break;
  case kPr:
    ptMin = TMath::Max(ptMin, 0.3);
    ptMax = TMath::Min(ptMax, 0.6);
    hden = GetITSsaSpectrum(file, AliPID::kProton, 1, cent, kFALSE, kFALSE);
    hden->Add(GetITSsaSpectrum(file, AliPID::kProton, 0, cent, kFALSE, kFALSE));
    break;
  }

  if (!hnum || !hden) return NULL;  

  Char_t sysname[1024];
  if (num == kPiMinus && den == kPiPlus)
    sprintf(sysname, "Pi_Pos2Neg");
  else if (num == kKaMinus && den == kKaPlus)
    sprintf(sysname, "K_Pos2Neg");
  else if (num == kPrMinus && den == kPrPlus)
    sprintf(sysname, "P_Pos2Neg");
  else if ((num == kKa || num == kKaPlus || num == kKaMinus)
	   && (den == kPi || den == kPiPlus || den == kPiMinus))
    sprintf(sysname, "K2Pi");
  else if ((num == kPr || num == kPrPlus || num == kPrMinus)
	   && (den == kPi || den == kPiPlus || den == kPiMinus))
    sprintf(sysname, "P2Pi");

  TH1D *hin = (TH1D *)hnum->Clone("hin");
  hin->Divide(hden);

  /* get systematics */
  TFile *fsys = TFile::Open("RATIOSYS_ITSsa.root");
  TH1 *hsys = fsys->Get(Form("hSystTot%s", sysname));
			
  TH1D *h = new TH1D(Form("hITSsa_cent%d_%s_%s", cent, ratioName[num], ratioName[den]), "ITSsa", NptBins, ptBin);
  Double_t pt, width, value, error, sys;
  Int_t bin;
  for (Int_t ipt = 0; ipt < NptBins; ipt++) {
    /* get input bin */
    pt = h->GetBinCenter(ipt + 1);
    width = h->GetBinWidth(ipt + 1);
    bin = hin->FindBin(pt);
    /* sanity check */
    if (TMath::Abs(hin->GetBinCenter(bin) - pt) > 0.001 ||
	TMath::Abs(hin->GetBinWidth(bin) - width) > 0.001) {
      //      printf("skipping %f because of sanity checks\n", pt);
      continue;
    }
    /* check pt limits */
    if (cutSpectrum && (pt < ptMin || pt > ptMax)) {
      //      printf("skipping %f because of limits\n", pt);
      continue;
    }
    /* copy bin */
    value = hin->GetBinContent(bin);
    error = hin->GetBinError(bin);
    /*** TEMP ADD SYS ***/
    if (addSystematicError) {
      sys = hsys->GetBinContent(bin) * value;
      error = TMath::Sqrt(error * error + sys * sys);
    }
    h->SetBinContent(ipt + 1, value);
    h->SetBinError(ipt + 1, error);
  }

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

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

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

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


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

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

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

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

  TH1D* modelT = new TH1D("modelT", "Pythia model", 5000, 0, 5);
  //Fill Histogram with points from Model
  for(i = 0; i < 20; i++) {
	//Track Values
	modelT->SetBinContent(1000*TrackAverage[i], TrackYpoints[i]);
        modelT->SetBinError(1000*TrackAverage[i], .01); }
  modelT->SetMarkerStyle(20);
  modelT->SetMarkerColor(kBlue);
  modelT->SetLineColor(kBlue);
  modelT->Draw("sameE");
  //Histogram for STAR Data Points
  TH1D* data = new TH1D("data", "CMS Data", 4000, 0, 4);
  data->SetMarkerStyle(20);
  data->SetMarkerColor(kRed);
  data->SetLineColor(kRed);
  data->SetBinContent(3262, 6.67);
  data->SetBinError(3262, .26);
  data->SetBinContent(2010, 3.12);
  data->SetBinError(2010, .15);
  data->SetBinContent(1240, 1.4);
  data->SetBinError(1240, .06);
  data->SetBinContent(630, .240);
  data->SetBinError(630, .01);
  data->Draw("sameE");
  TLegend* leg = new TLegend(.1,.74,.30,.9);
  leg->SetHeader("For |#eta| < 2.4");
  leg->AddEntry(modelT->DrawCopy("same"), "Pythia 8 Model", "l");
  leg->AddEntry(data->DrawCopy("same"), "CMS data", "l");
  leg->Draw("same");
  return; }
Esempio n. 28
0
TH1D *
GetTOFRatio(TFile *file, Int_t num, Int_t den, Int_t cent, Bool_t cutSpectrum = kTRUE)
{
  /* pt limits for combined spectra */
  Double_t ptMin_[9] = {
    0.5, 0.5, 0.5, 
    0.45, 0.45, 0.45, 
    0.5, 0.5, 0.5
  };
  Double_t ptMax_[9] = {
    3.0, 3.0, 3.0, 
    3.0, 3.0, 3.0, 
    4.5, 4.5, 4.5
  };

  Double_t ptMin = TMath::Max(ptMin_[num], ptMin_[den]);
  Double_t ptMax = TMath::Min(ptMax_[num], ptMax_[den]);
  
  TH1D *hin = (TH1D *)file->Get(Form("hRatio_cent%d_%s_%s", cent, ratioName[num], ratioName[den]));
  if (!hin) return NULL;


#if 0
  /* get matching systematics */
  TFile *fsys = TFile::Open(Form("MATCHSYS_TOF_%s.root", TOFChargeName[charge]));
  TH1 *hsys = fsys->Get(Form("hErr%sMatch", ITSsaPartName[part]));
  TF1 *ffsys = new TF1("fsys", "[0] + [1] * x + [2] * TMath::Exp(-[3] * x)");
  ffsys->SetParameter(0, 0.02);
  ffsys->FixParameter(1, 0.);
  ffsys->SetParameter(2, 0.5);
  ffsys->SetParameter(3, 10.);
  hsys->Fit(ffsys, "W");
  ffsys->ReleaseParameter(1);
  hsys->Fit(ffsys, "W");
  hsys->Fit(ffsys, "W");
  hsys->Fit(ffsys, "W");
  hsys->Draw();
#endif
			
  TH1D *h = new TH1D(Form("hTOF_cent%d_%s_%s", cent, ratioName[num], ratioName[den]), "TOF", NptBins, ptBin);
  Double_t pt, width, value, error, sys;
  Int_t bin;
  for (Int_t ipt = 0; ipt < NptBins; ipt++) {
    /* get input bin */
    pt = h->GetBinCenter(ipt + 1);
    width = h->GetBinWidth(ipt + 1);
    bin = hin->FindBin(pt);
    /* sanity check */
    if (TMath::Abs(hin->GetBinCenter(bin) - pt) > 0.001 ||
	TMath::Abs(hin->GetBinWidth(bin) - width) > 0.001)
      continue;
    /* check pt limits */
    if (cutSpectrum && (pt < ptMin || pt > ptMax)) continue;
    /* copy bin */
    value = hin->GetBinContent(bin);
    error = hin->GetBinError(bin);
    /*** TEMP ADD SYS ***/
    //    sys = ffsys->Eval(pt) * value;
    //    error = TMath::Sqrt(error * error + sys * sys);
    //    h->SetBinContent(ipt + 1, value);
    //    h->SetBinError(ipt + 1, error);

    h->SetBinContent(ipt + 1, value);
    h->SetBinError(ipt + 1, error);
  }
  
  h->SetTitle("TOF");
  h->SetLineWidth(1);
  h->SetLineColor(1);
  h->SetMarkerStyle(23);
  h->SetMarkerColor(4);
  h->SetFillStyle(0);
  h->SetFillColor(0);
  return h;
}
Esempio n. 29
0
void chipSummary(const char *dirName, int chipId)
{
        directory = TString(dirName);
	
	if (f && f->IsOpen()) f->Close();
	if (f1 && f1->IsOpen()) f1->Close();
	if (g && g->IsOpen()) g->Close();

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

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

	gROOT->ForceStyle();

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

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

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

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

	TH1D *h1;
	TH2D *h2;

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

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

	FILE *sCurveFile, *phLinearFile, *phTanhFile;

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

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

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

	int nRootFileProblems(0);

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

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

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

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

        if (hpm) {

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

	} else { 
	  
	  ++nRootFileProblems; 
	}


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

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

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

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

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

	if (!sCurveFile) {

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

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

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

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

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

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

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

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

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

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

	// -- Bump Map
	TH2D *hbm;

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

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

	else { ++nRootFileProblems; }

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

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

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

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

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


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

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

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

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

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

	else { ++nRootFileProblems; }

	// -- Address levels

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


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

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

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

	TH1D *htmp;

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

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

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

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

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

	  // -- Gain

	  c1->cd(11);

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

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

	  } else {

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

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

	  // -- Pedestal

	  c1->cd(12);

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

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

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

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

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


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

	  hp->DrawCopy();

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

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

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

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

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

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

		
	}

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

	over = 0.; under = 0.;

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

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


	  // -- Parameter 1

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

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



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

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

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

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

	else { ++nRootFileProblems; }

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


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

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

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



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

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

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

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

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

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

//  	  }
//  	}


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

		++nAddressProblems;

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

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

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

		++nThrDefect;

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

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

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

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

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

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

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

		++nGainDefect;

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

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

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

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

		++nPedDefect;

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

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

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

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

		++nPar1Defect;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

//
//  TCanvas *c2 = new TCanvas("c2","c2");
//  minp->DrawCopy();
    //cout<<minp->GetMean()<<endl;
}