コード例 #1
0
TH1D* returnRelDiff(TH1D* h, TH1D* b, TString name) {
  TH1D* hRelDiff = new TH1D(name, "", h->GetNbinsX(), h->GetXaxis()->GetXmin(), h->GetXaxis()->GetXmax());
  hRelDiff->SetLineColor(h->GetLineColor());
  hRelDiff->SetLineStyle(h->GetLineStyle());
  hRelDiff->SetLineWidth(h->GetLineWidth());

  hRelDiff->GetYaxis()->SetTitleOffset(0.42);
  hRelDiff->GetYaxis()->SetTitleSize(0.13);
  hRelDiff->GetYaxis()->SetLabelSize(0.10);
  hRelDiff->GetXaxis()->SetTitleOffset(1.2);
  hRelDiff->GetXaxis()->SetTitleSize(0.13);
  hRelDiff->GetXaxis()->SetLabelSize(0.12);
  //hRelDiff->GetXaxis()->CenterTitle();                                                                                   
  hRelDiff->GetYaxis()->CenterTitle();
  hRelDiff->GetYaxis()->SetNdivisions(303,kTRUE);

  // (mc-data)/mc, uncertainty is √data
  for (Int_t i=1; i<h->GetNbinsX()+1; i++) {
    Double_t y = b->GetBinContent(i);
    Double_t val = h->GetBinContent(i) - y;
    if (y!=0) { hRelDiff->SetBinContent(i, val/h->GetBinContent(i)); hRelDiff->SetBinError(i,TMath::Sqrt(b->GetBinContent(i))/h->GetBinContent(i)); }
    else hRelDiff->SetBinContent(i, 0);
  }
  return hRelDiff;
}
コード例 #2
0
ファイル: drawPaPt.C プロジェクト: CmsHI/gammaJetAnalysis
void drawPaPt(){
  
  TCanvas* c1 = new TCanvas("c1","",500,500);
 
  TFile* f1 = new TFile("/home/jazzitup/analysis/photonJetAnalysis2013/histogramProducer/ffFiles/photonTrackCorr_ppbDATA_output_photonPtThr40_to_50_jetPtThr30_20130906.root");
  TH1D* hd1 = (TH1D*)f1->Get("jetPt_icent1_final");
  TFile* f2 = new TFile("/home/jazzitup/analysis/photonJetAnalysis2013/histogramProducer/ffFiles/photonTrackCorr_ppbDATA_output_photonPtThr50_to_60_jetPtThr30_20130906.root");
  TH1D* hd2 = (TH1D*)f2->Get("jetPt_icent1_final");
  TFile* f3 = new TFile("/home/jazzitup/analysis/photonJetAnalysis2013/histogramProducer/ffFiles/photonTrackCorr_ppbDATA_output_photonPtThr60_to_80_jetPtThr30_20130906.root");
  TH1D* hd3 = (TH1D*)f3->Get("jetPt_icent1_final");
  TFile* f4 = new TFile("/home/jazzitup/analysis/photonJetAnalysis2013/histogramProducer/ffFiles/photonTrackCorr_ppbDATA_output_photonPtThr80_to_9999_jetPtThr30_20130906.root");
  TH1D* hd4 = (TH1D*)f4->Get("jetPt_icent1_final");

  TFile* f1m = new TFile("/home/jazzitup/analysis/photonJetAnalysis2013/histogramProducer/ffFiles/photonTrackCorr_ppbMC_output_photonPtThr40_to_50_jetPtThr30_20130906.root");
  TH1D* hm1 = (TH1D*)f1m->Get("jetPt_icent1_final");
  TFile* f2m = new TFile("/home/jazzitup/analysis/photonJetAnalysis2013/histogramProducer/ffFiles/photonTrackCorr_ppbMC_output_photonPtThr50_to_60_jetPtThr30_20130906.root");
  TH1D* hm2 = (TH1D*)f2m->Get("jetPt_icent1_final");
  TFile* f3m = new TFile("/home/jazzitup/analysis/photonJetAnalysis2013/histogramProducer/ffFiles/photonTrackCorr_ppbMC_output_photonPtThr60_to_80_jetPtThr30_20130906.root");
  TH1D* hm3 = (TH1D*)f3m->Get("jetPt_icent1_final");
  TFile* f4m = new TFile("/home/jazzitup/analysis/photonJetAnalysis2013/histogramProducer/ffFiles/photonTrackCorr_ppbMC_output_photonPtThr80_to_9999_jetPtThr30_20130906.root");
  TH1D* hm4 = (TH1D*)f4m->Get("jetPt_icent1_final");

  double ptBinPaDraw[5] = { 40.5 ,49.5, 58.5,  76.5,  123. } ;
  TH1D* hd = new TH1D("ptmeanDAta",";p_{T}^{#gamma}; <p_{T}^{Jet}>",4,ptBinPaDraw);
  hd->SetBinContent(1, hd1->GetMean());
  hd->SetBinContent(2, hd2->GetMean());
  hd->SetBinContent(3, hd3->GetMean());
  hd->SetBinContent(4, hd4->GetMean());
  hd->SetBinError(1, hd1->GetMeanError());
  hd->SetBinError(2, hd2->GetMeanError());
  hd->SetBinError(3, hd3->GetMeanError());
  hd->SetBinError(4, hd4->GetMeanError());

  TH1D* hm = new TH1D("ptmeanDAta",";p_{T}^{#gamma}; <p_{T}^{Jet}>",4,ptBinPaDraw);
  hm->SetBinContent(1, hm1->GetMean());
  hm->SetBinContent(2, hm2->GetMean());
  hm->SetBinContent(3, hm3->GetMean());
  hm->SetBinContent(4, hm4->GetMean());
  hm->SetBinError(1, hm1->GetMeanError());
  hm->SetBinError(2, hm2->GetMeanError());
  hm->SetBinError(3, hm3->GetMeanError());
  hm->SetBinError(4, hm4->GetMeanError());



  handsomeTH1(hd,2);
  handsomeTH1(hm,1);
  hm->SetMarkerStyle(24);
  hd->SetAxisRange(30,95,"Y");
  hm->SetAxisRange(30,95,"Y");
  hm->Draw();
  hd->Draw("same");
  TLegend *l1 = new TLegend(0.2399194,0.7288136,0.7862903,0.9322034,NULL,"brNDC");
  easyLeg(l1,"5.02TeV pPb MinBias");
  l1->AddEntry(hd, "DATA","p");
  l1->AddEntry(hm, "MC","p");
  l1->Draw();

  c1->SaveAs("pT_dependence_jetPt_ppb.pdf");
}
コード例 #3
0
ファイル: acceptance02.C プロジェクト: frmeier/usercode
void acceptance02(){
  AcceptanceCuts="((mu1eta<1.3 && mu1pT>3.3)||(mu1eta>1.3 && mu1eta<2.2 && mu1p>2.9)||(mu1eta>2.2 && mu1eta<2.4 && mu1pT>0.8))";
  AcceptanceCuts+=" && ((mu2eta<1.3 && mu2pT>3.3)||(mu2eta>1.3 && mu2eta<2.2 && mu2p>2.9)||(mu2eta>2.2 && mu2eta<2.4 && mu2pT>0.8))";
  //  AcceptanceCuts+=" && (p_pT>1 && p_eta<2.3 && pi_eta<2.3 && pi_pT>0.4) ";
  AcceptanceCuts += " && sqrt(p_Vx*p_Vx+p_Vy*p_Vy)>1.0 && sqrt(p_Vx*p_Vx+p_Vy*p_Vy)<35.0 && p_Vz<100.0";
  Double_t n_nocuts=0;
  Double_t n_cuts=0;
  stringstream buffer;
  TString pt_cut;
  Double_t acceptance;
  Int_t events;

  t->Draw("lambdaB_pt>>LambdaB_pt",AcceptanceCuts);
  for(Int_t i=1; i<12; i++){
    buffer.str("");
    buffer << "lambdaB_pt > "<<x[i-1] << " && lambdaB_pt < "<<x[i]; 
    pt_cut = TString(buffer.str());  
    n_nocuts = (Double_t) t->GetEntries(pt_cut);
    n_cuts = (Double_t) t->GetEntries(AcceptanceCuts + "&& "+pt_cut);
    if(n_nocuts>0) acceptance = n_cuts/n_nocuts;
    else acceptance =0.0;
    Acc.SetBinContent(i,acceptance);
    Events.SetBinContent(i,n_cuts/(x[i]-x[i-1]));
  }
  Acc.Draw();
}
コード例 #4
0
ファイル: fitWm.C プロジェクト: ksung25/UserCode
//--------------------------------------------------------------------------------------------------
TH1D *makeDiffHist(TH1D* hData, TH1D* hFit, const TString name)
{
  TH1D *hDiff = new TH1D(name,"",hData->GetNbinsX(),hData->GetXaxis()->GetXmin(),hData->GetXaxis()->GetXmax());
  for(Int_t ibin=1; ibin<=hData->GetNbinsX(); ibin++) {
    
    Double_t diff = (hData->GetBinContent(ibin)-hFit->GetBinContent(ibin));
    
    Double_t err = sqrt(hData->GetBinContent(ibin));
    if(err==0) err= sqrt(hFit->GetBinContent(ibin));
    
    if(err>0) hDiff->SetBinContent(ibin,diff/err);
    else      hDiff->SetBinContent(ibin,0);
    hDiff->SetBinError(ibin,1);   
  }
  
  hDiff->GetYaxis()->SetTitleOffset(0.42);
  hDiff->GetYaxis()->SetTitleSize(0.13);
  hDiff->GetYaxis()->SetLabelSize(0.10);
  hDiff->GetYaxis()->SetNdivisions(104);
  hDiff->GetYaxis()->CenterTitle();
  hDiff->GetXaxis()->SetTitleOffset(1.2);
  hDiff->GetXaxis()->SetTitleSize(0.13);
  hDiff->GetXaxis()->SetLabelSize(0.12);
  hDiff->GetXaxis()->CenterTitle();
  
  return hDiff;
}
コード例 #5
0
ファイル: makeTable.C プロジェクト: geonmo/cmg-cmssw
void fitSlices(TH2* hCorr, TF1* func){

   int nBins = hCorr->GetNbinsX();

   TH1D* hMean = new TH1D(Form("%s_1",hCorr->GetName()),"",nBins,hCorr->GetXaxis()->GetXmin(),hCorr->GetXaxis()->GetXmax());
   TH1D* hSigma = new TH1D(Form("%s_2",hCorr->GetName()),"",nBins,hCorr->GetXaxis()->GetXmin(),hCorr->GetXaxis()->GetXmax());

   for(int i = 1; i < nBins+1; ++i){
      int bin = nBins - i;
      TH1D* h = hCorr->ProjectionY(Form("%s_bin%d",hCorr->GetName(),bin),i,i);

      func->SetParameter(0,h->GetMaximum());
      func->SetParameter(1,h->GetMean());
      func->SetParameter(2,h->GetRMS());

      if(useFits) h->Fit(func);

      hMean->SetBinContent(i,func->GetParameter(1));
      hMean->SetBinError(i,func->GetParError(1));
      hSigma->SetBinContent(i,func->GetParameter(2));
      hSigma->SetBinError(i,func->GetParError(2));
      
      if(onlySaveTable){
	 h->Delete();
      }
   }
}
コード例 #6
0
ファイル: spr_plot.C プロジェクト: aashaqshah/cmssw-1
// Modes: linear or log
plotHistogram(const char* canvas, const char* mode, const char* title,
	      double xlo, double xhi, int nbin,
	      double* sig, double* sigerr, double* bgr, double* bgrerr)
{
  TCanvas *c 
    = new TCanvas(canvas,"SPR Classifier Output",200,10,600,400);
  gStyle->SetPalette(1);
  TLegend *leg = new TLegend(0.1,0.85,0.5,1.,"Classifier Output","NDC");
  double dx = (xhi-xlo) / nbin;
  TH1D* hs = new TH1D("signal",    title,nbin,xlo,xhi);
  TH1D* hb = new TH1D("background",title,nbin,xlo,xhi);
  leg->AddEntry(hs,"Signal","L");
  leg->AddEntry(hb,"Background","L");
  for( int i=0;i<nbin;i++ ) {
    hs->SetBinContent(i+1,sig[i]);
    hs->SetBinError(i+1,sigerr[i]);
    hb->SetBinContent(i+1,bgr[i]);
    hb->SetBinError(i+1,bgrerr[i]);
  }
  TPad* pad = new TPad("pad","pad",0,0,1,1);
  if( strcmp(mode,"log") == 0 ) pad->SetLogy(1);
  pad->Draw();
  pad->cd();
  hs->SetLineColor(2);
  hs->SetLineWidth(3);
  hb->SetLineColor(4);
  hb->SetLineWidth(3);
  hb->Draw();
  hs->Draw("same");
  leg->Draw();
}
コード例 #7
0
ファイル: makeSmearedTable.C プロジェクト: KiSooLee/TnP_B
//------------------------------------------------------------------------
void fitSlices(TH2* hCorr, TF1* func){

   int nBins = hCorr->GetNbinsX();

   TH1D* hMean = new TH1D(Form("%s_1",hCorr->GetName()),"",nBins,hCorr->GetXaxis()->GetXmin(),hCorr->GetXaxis()->GetXmax());
   TH1D* hSigma = new TH1D(Form("%s_2",hCorr->GetName()),"",nBins,hCorr->GetXaxis()->GetXmin(),hCorr->GetXaxis()->GetXmax());

   for(int i = 1; i < nBins+1; i++){
      int bin = nBins - i;
      TH1D* h = hCorr->ProjectionY(Form("%s_bin%d",hCorr->GetName(),bin),i,i);

      func->SetParameter(0,h->GetMaximum());
      func->SetParameter(1,h->GetMean());
      func->SetParameter(2,h->GetRMS());

      h->Fit(func,"Q");

      /*hMean->SetBinContent(i,func->GetParameter(1));
      hMean->SetBinError(i,func->GetParError(1));
      hSigma->SetBinContent(i,func->GetParameter(2));
      hSigma->SetBinError(i,func->GetParError(2));*/

      hMean->SetBinContent(i,h->GetMean());
      hMean->SetBinError(i,func->GetParError(1)); //errors are not use later for the actual table
      hSigma->SetBinContent(i,h->GetRMS());
      hSigma->SetBinError(i,func->GetParError(2));

   }
}
コード例 #8
0
ファイル: stat.C プロジェクト: radziej/findsusyb3
void loglikdistrib(Int_t ntrials = 10000, Bool_t print = kFALSE)
{
  // compute distribution of log likelihood value
  TH1D * hmc   = gStack[gPadNr][gOrder[gPadNr][0]];
  TH1D * hdata = gStack[gPadNr][gMaxProcess-1];
  Int_t nbins = hmc->GetNbinsX();
  Double_t loglik = loglikelihood(hmc, hdata, 1, nbins);
  TH1D * htest = new TH1D(*hdata);
  TH1D * lldistrib = new TH1D("lldistrib", "log(Likelihood) distribution", 
			      1000, loglik-200, loglik+200);
  setopt(lldistrib);
  for (Int_t n = 0; n < ntrials; n++) {
    // generate poisson around theorie
    for (Int_t i = 1; i <= nbins; i++) {
      htest->SetBinContent(i, gRandom->Poisson(hmc->GetBinContent(i)));
    }
    lldistrib->Fill(loglikelihood(hmc, htest, 1, nbins));
  }
  TCanvas * llcanvas = new TCanvas("llcanvas", "Log(Likelihood) distribution", 
				   40, 40, 800, 600);
  setopt(llcanvas);
  lldistrib->SetFillColor(kYellow);
  lldistrib->Draw();
  lldistrib->GetYaxis()->SetTitle("Anzahl Ereignisse");
  lldistrib->GetXaxis()->SetTitle("-ln L");
  // autozoom
  Int_t lowbin = 1;
  while (lldistrib->GetBinContent(lowbin) == 0)
    lowbin++;
  Int_t highbin = lldistrib->GetNbinsX();
  while (lldistrib->GetBinContent(highbin) == 0)
    highbin--;
  lldistrib->SetAxisRange(lldistrib->GetBinLowEdge(lowbin), 
			  lldistrib->GetBinLowEdge(highbin));
  TH1D * hworse = (TH1D *) lldistrib->Clone();
  for (Int_t nbin = 1; nbin < 501; nbin++) {
    hworse->SetBinContent(nbin, 0);
  }
  hworse->SetFillColor(95);
  hworse->Draw("same");
  Double_t pvalue = lldistrib->Integral(501,1000) / lldistrib->Integral();
  TLatex * tex = new TLatex(0.18, 0.96, Form("-ln L_{obs} = %5.2f", loglik));
  tex->SetNDC();
  tex->SetTextAlign(13);
  tex->Draw();
  tex = new TLatex(0.18, 0.86, Form("CL_{obs} = %.3f", pvalue));
  tex->SetNDC();
  tex->SetTextAlign(13);
  tex->Draw();
  TLine * l = new TLine(loglik, 0, loglik, lldistrib->GetMaximum());
  l->SetLineWidth(3);
  l->SetLineColor(kBlue);
  l->Draw();
  llcanvas->Modified();
  llcanvas->Update();
  if (print)
    llcanvas->Print("lldistrib.pdf");
  cd(gPadNr+1);
}
コード例 #9
0
void takeDirectlyFromMC(TFile* fin, TFile* fout, TString gentype) {

  TList* listOfDirs = fin->GetListOfKeys();
  for (auto k : *listOfDirs) {
    TString srname = k->GetName();
    if (!srname.Contains("sr")) continue;
    if (srname.Contains("base") || srname.Contains("incl") || srname.Contains("sb")) continue;
    if (gentype == "_1lepW" && !srname.EndsWith("2") && !srname.EndsWith("3")) continue;

    auto indir = (TDirectoryFile*) fin->Get(srname);
    auto outdir = (TDirectory*) fout->mkdir(srname);
    auto hlist = indir->GetListOfKeys();

    for (auto h : *hlist) {
      TString hname = h->GetName();
      if (!hname.BeginsWith("h_metbins" + gentype)) continue;
      TH1D* hin = (TH1D*) indir->Get(hname);
      outdir->cd();
      TH1D* hout = (TH1D*) hin->Clone(TString(hname).ReplaceAll(gentype, ""));
      for (int i = 1; i <= hout->GetNbinsX(); ++i) {
        // zero out negative yields
        if (hout->GetBinContent(i) < 0) {
          hout->SetBinContent(i, 0);
          hout->SetBinError(i, 0);
        }
      }
      hout->Write();

      if (yearSeparateSyst && (hname.EndsWith("Up") || hname.EndsWith("Dn"))) {
        for (int i = 1; i < 4; ++i) {
          TH1D* hcen_yi = (TH1D*) fbkgs[i]->Get(srname+"/h_metbins"+gentype);
          TH1D* hsys_yi = (TH1D*) fbkgs[i]->Get(srname+"/"+hname);
          if (hsys_yi && !hcen_yi) {
            cout << "Find " << srname+"/"+hname << " from " << fbkgs[i]->GetName() << " but not hcen " << srname+"/h_metbins"+gentype << " Should not happen?" << endl;
          }
          TH1D* hout_yi = (TH1D*) fin->Get(srname+"/h_metbins"+gentype)->Clone(TString(hname).Insert(hname.Length()-2, Form("%d", 15+i)).ReplaceAll(gentype, ""));
          if (hcen_yi) hout_yi->Add(hcen_yi, -1);
          if (hsys_yi) hout_yi->Add(hsys_yi);
          hout_yi->Write();
        }
      }
    }
    if (!outdir->Get("h_metbins")) {
      cout << "Didn't find yield hist for " << gentype << " in " << fin->GetName() << ":" << srname << "/. Faking a 0 one!" << endl;
      outdir->cd();
      // Get the MET binning from h_metbins, which shall always exist, and then set all bins to 0
      TH1D* hout = (TH1D*) fin->Get(srname + "/h_metbins")->Clone("h_metbins");
      for (int i = 1; i <= hout->GetNbinsX(); ++i) {
        hout->SetBinContent(i, 0);
        hout->SetBinError(i, 0);
      }
      hout->Write();
    }
  }
}
コード例 #10
0
ファイル: Run_ZgSelectorMC.C プロジェクト: aashaqshah/cmssw-1
void Run_ZgSelectorMC(Int_t eleID, Int_t phoID,Float_t DelRCut){

   gROOT->LoadMacro("Zg_SelectorMC.C+");

   FILE *Table = fopen("Input_table_Sig", "r");
   char filename[200];
   char tmp[100];
   int  flag = 1;
   int  nfile(0);
   double EvtWeight[40];
   double nevt[40];
   double luminosity(1.0);
   TString ProcessTag[40];

   //Load Input table 
   cout<<"<<< File Table >>>"<<endl;
   while (flag != -1){
      flag=fscanf(Table, "%s", tmp);
      if (flag == -1) continue;
      ProcessTag[nfile] = tmp;
      flag=fscanf(Table, "%s", filename);
      flag=fscanf(Table, "%s", tmp);
      double cross=atof(tmp);
      flag=fscanf(Table, "%s", tmp);
      double evt=atof(tmp);

      EvtWeight[nfile] = 0;
      EvtWeight[nfile] = cross/evt*luminosity;
      if (nfile == 0) nevt[nfile] = evt;
      else nevt[nfile] = evt + nevt[nfile-1];
      cout<<">>> "<<nfile<<" : "<<filename<<endl;
      cout<<"    "<<ProcessTag[nfile]<<"  "<<cross<<"  "<<evt<<"  "<<nevt[nfile]<<"  "<<EvtWeight[nfile]<<endl;
      nfile += 1;
   }
   fclose(Table);

   cout<<"  "<<endl;
   TString TSaveFileName = Form("Test_eID%d_pID%d_dR07",eleID,phoID);
   TH1D *hInfo  = new TH1D("hInfo","Event Information",15,0,15);
   hInfo->SetBinContent(1,nfile);
   hInfo->SetBinContent(2,eleID);
   hInfo->SetBinContent(3,phoID);

   TFile *f1 = new TFile(TSaveFileName+".root","RECREATE");
   f1->cd();
   hInfo->Write();
   f1->Close();

   for (Int_t iSample=0;iSample<nfile;iSample++) {
     cout<<"Now Running....sample:"<<iSample<<", Weight:"<<EvtWeight[iSample]<<endl;
     Zg_SelectorMC t(iSample);
     t.Loop(iSample,phoID,eleID,EvtWeight[iSample],ProcessTag[iSample],TSaveFileName,DelRCut);
   }
   cout<<"Done!"<<endl;
}
コード例 #11
0
ファイル: make_sig_plots.cpp プロジェクト: manuelfs/ucsb_code
TH1D GetSOverSqrtB(TH1D sig, TH1D back){
  if(sig.GetNbinsX()!=back.GetNbinsX()) return sig;
  sig.GetYaxis()->SetTitle("S/#sqrt{B}");
  for(int i(1); i<=sig.GetNbinsX(); ++i){
    if(back.GetBinContent(i)>0.0 && sig.GetBinContent(i)>0.0){
      sig.SetBinContent(i,sig.GetBinContent(i)/sqrt(back.GetBinContent(i)));
    }else{
      sig.SetBinContent(i,0.0);
    }
  }
  return sig;
}
コード例 #12
0
ファイル: bfractionFit.C プロジェクト: kurtejung/bJetTools
void ptDependence()
{
   TFile *inf = new TFile("histos/ppMC.root");
   TTree *t = (TTree*) inf->Get("nt");

   const int nBins = 4;
   double ptBin[nBins+1] = {100,120,140,160,200};
//   const int nBins = 1;
//   double ptBin[nBins+1] = {100,400};
   
   TH1D *hProb = new TH1D("hProb","",nBins,ptBin);
   TH1D *hCSV = new TH1D("hCSV","",nBins,ptBin);
   TH1D *hSVTXM = new TH1D("hSVTXM","",nBins,ptBin);
   TProfile *pGen = new TProfile("pGen","",nBins,ptBin);
   
   for (int n=0; n<nBins;n++)
   {
      RooRealVar f1 = bfractionFit("discr_prob",0,3.5,ptBin[n],ptBin[n+1]);
      RooRealVar f2 = bfractionFit("discr_csvSimple",0,1,ptBin[n],ptBin[n+1]);
      RooRealVar f3 = bfractionFit("svtxm",0,6,ptBin[n],ptBin[n+1]);
      hProb->SetBinContent(n+1,f1.getVal());    
      hProb->SetBinError(n+1,f1.getError());    
      hCSV->SetBinContent(n+1,f2.getVal());    
      hCSV->SetBinError(n+1,f2.getError());    
      hSVTXM->SetBinContent(n+1,f3.getVal());    
      hSVTXM->SetBinError(n+1,f3.getError());    
   }
   
   TCanvas *c2 = new TCanvas("c2","",600,600);
   hProb->SetAxisRange(0,0.05,"Y");
   hProb->SetXTitle("Jet p_{T} (GeV/c)");
   hProb->SetYTitle("b-jet fraction");
   hProb->SetTitleOffset(1.5,"Y");
   hProb->Draw();
   hCSV->SetLineColor(2);
   hCSV->SetMarkerColor(2);
   hCSV->SetMarkerStyle(24);
   hCSV->Draw("same");
   hSVTXM->SetLineColor(4);
   hSVTXM->SetMarkerColor(4);
   hSVTXM->SetMarkerStyle(24);
//   hSVTXM->Draw("same");
   t->Draw("abs(refparton_flavorForB)==5:jtpt","","prof same");
   
   TLegend *leg = new TLegend(0.2,0.7,0.5,0.9);
   leg->SetBorderSize(0);
   leg->SetFillStyle(0);
   leg->SetFillColor(0);
   leg->AddEntry(hProb,"Jet Probability","pl");
   leg->AddEntry(hCSV,"CSV","pl");
//   leg->AddEntry(hSVTXM,"SV mass","pl");
   leg->Draw();
}
コード例 #13
0
ファイル: residu.C プロジェクト: star-bnl/star-sti
// Loop through detector layers to report 
// various parameters
residu(TString baseName, double min=-1.5, double max=1.5)
{
  double xMin, xMax;
  TString name;
  name = baseName;
  name += "_a";     TH1D * amp  = new TH1D(name,name,55,0,54.);
  name = baseName;
  name += "_mean";  TH1D * mean = new TH1D(name,name,55,0,54.);
  name = baseName;
  name += "_rms";   TH1D * rms = new TH1D(name,name,55,0,54.);
  TString thisL;
  TH1D *h=0;
  TF1 * f;
  int ii;
  for(int i=0; i<51;i++)
    {
      thisL=baseName+i;
      if (i<6)
	{
	  xMin = -0.2;
	  xMax = 0.2;
	}
      else
	{
	  xMin = min;
	  xMax = max;
	}
      h=(TH1D*)gDirectory->Get(thisL);
      h->Fit("gaus","","",xMin,xMax);
      double entries = h->GetEntries();
      if (entries>0)
	{
	  ii = i+1;
	  f = h->GetFunction("gaus");
	  double a = f->GetParameter("Constant"); double ea = f->GetParError(0);
	  double m = f->GetParameter("Mean");double em = f->GetParError(1);
	  double r = f->GetParameter("Sigma");double er = f->GetParError(2);
	  amp->SetBinContent(ii,a);amp->SetBinError(ii,ea);
	  mean->SetBinContent(ii,m);mean->SetBinError(ii,em);
	  rms->SetBinContent(ii,r);rms->SetBinError(ii,er);
	}
    }
  cout << "Fitting completed" << endl;

  c1->Clear();
  c1->Divide(1,3);
  c1->cd(1); amp->Draw();
  c1->cd(2); mean->Draw();
  c1->cd(3); rms->Draw();
  
}
コード例 #14
0
void GaussianProfile::getTruncatedMeanRMS(TH1* hist, float& mean, float& mean_error, float& rms, float& rms_error) {
  int nBins = hist->GetNbinsX();
  double xMin = hist->GetXaxis()->GetXmin();
  double xMax = hist->GetXaxis()->GetXmax();
  //double binWidth = (xMax - xMin) / (double) nBins; //WARNING: this works only if bins are of the same size
  double integral = hist->Integral();

  int maxBin = 0;
  TF1* gaussian = new TF1("gaussian", "gaus");
  fitProjection(hist, gaussian, 1.5, "RQN");
  //maxBin = (int) ceil((gaussian->GetParameter(1) - xMin) / binWidth);
  maxBin = hist->FindBin(gaussian->GetParameter(1));
  delete gaussian;

  TH1D* newHisto = new TH1D("newHisto", "", nBins, xMin, xMax);
  newHisto->SetBinContent(maxBin, hist->GetBinContent(maxBin));
  newHisto->SetBinError(maxBin, hist->GetBinError(maxBin));
  int iBin = maxBin;
  int delta_iBin = 1;
  int sign  = 1;

  while (newHisto->Integral() < 0.99 * integral) {
    iBin += sign * delta_iBin;

    newHisto->SetBinContent(iBin, hist->GetBinContent(iBin));
    newHisto->SetBinError(iBin, hist->GetBinError(iBin));

    delta_iBin += 1;
    sign *= -1;
  }

  rms = newHisto->GetRMS();
  rms_error = newHisto->GetRMSError();

  while (newHisto->Integral() < 0.99 * integral) {
    iBin += sign * delta_iBin;

    newHisto->SetBinContent(iBin, hist->GetBinContent(iBin));
    newHisto->SetBinError(iBin, hist->GetBinError(iBin));

    delta_iBin += 1;
    sign *= -1;
  }

  mean = newHisto->GetMean();
  mean_error = newHisto->GetMeanError();

  delete newHisto;
}
コード例 #15
0
ファイル: utilities.cpp プロジェクト: ald77/ra4_draw
void MergeOverflow(TH1D &h, bool merge_underflow, bool merge_overflow) {
    if(merge_underflow) {
        h.SetBinContent(1, h.GetBinContent(0)+h.GetBinContent(1));
        h.SetBinContent(0, 0.);
        h.SetBinError(1, hypot(h.GetBinError(0), h.GetBinError(1)));
        h.SetBinError(0, 0.);
    }
    int nbins = h.GetNbinsX();
    if(merge_overflow) {
        h.SetBinContent(nbins, h.GetBinContent(nbins)+h.GetBinContent(nbins+1));
        h.SetBinContent(nbins+1, 0.);
        h.SetBinError(nbins, hypot(h.GetBinError(nbins), h.GetBinError(nbins+1)));
        h.SetBinError(nbins+1, 0.);
    }
}
コード例 #16
0
void
getLimits (TH1D *cutFlow, TDirectoryFile *dir)
{
  string histName = cutFlow->GetName ();
  TH1D *lowerLimit = (TH1D *) cutFlow->Clone ((histName + "LowerLimit").c_str ()),
       *upperLimit = (TH1D *) cutFlow->Clone ((histName + "UpperLimit").c_str ());

  TAxis *x = cutFlow->GetXaxis ();
  for (int i = 1; i <= x->GetNbins (); i++)
    {
      double events = cutFlow->GetBinContent (i), eventsLowerLimit, eventsUpperLimit;

      // The calculation of upper and lower limits is taken from the PDG Statistics chapter.  
      // "Poisson or binomal data", section 37.4.2.3 in 2013 version; Eqns. 37.71a, 37.71b.  
      // Here ALPHA is the confidence level, so ALPHA = 0.68 corresponds to a 68% C.L.
      // The PDG uses a different convention:  the C.L is 1 - \alpha.  
      // For example, the 68% CL upper limit on an observation of 0 events is:
      // 0.5 * TMath::ChisquareQuantile (0.68, 2) = 1.139  
      eventsLowerLimit = 0.5 * TMath::ChisquareQuantile (1 - ALPHA, 2 * events);
      eventsUpperLimit = 0.5 * TMath::ChisquareQuantile (ALPHA, 2 * (events + 1));
      lowerLimit->SetBinContent (i, eventsLowerLimit);
      upperLimit->SetBinContent (i, eventsUpperLimit);
    }
  dir->cd ();
  lowerLimit->Write ((histName + "LowerLimit").c_str ());
  upperLimit->Write ((histName + "UpperLimit").c_str ());
}
コード例 #17
0
ファイル: QinvKstar.C プロジェクト: maszyman/FitResCorr
void QinvKstar (const char* filename, const char* histname) {

	TFile*  fileIn = new TFile(filename,"update");
	TH1D* hist = (TH1D*)fileIn->Get(histname);
	TH1D* histnew = new TH1D(Form("kstar_%s",histname),"",hist->GetNbinsX(),0,0.25);//(TH1D*)fileIn->Get(histname);

//   for (int ibins = 1; ibins <= hist->GetNbinsX()*2; ibins++ ) {
//     hist->SetBinContent(ibins, hist->GetBinContent(ibins));
//     //    hist->SetBinContent(ibins, hist->GetBinContent(ibins));
//   }

	int bin=2;//1

	for (double kstar = 0.00375; kstar <= 0.25; kstar += 0.0025 ) {

//	for (double kstar = 0.00375; kstar <= 0.25; kstar += 0.0025 ) {
		//  for (double kstar = 0.005; kstar <= 0.25; kstar += 0.01 ) {
		//        hist->Fill(kstar,hist->GetBinContent(hist->FindBin(kstar*2)));

		histnew->SetBinContent(bin,hist->GetBinContent(hist->FindFixBin(kstar*2)));
		histnew->SetBinError(bin++,hist->GetBinError(hist->FindFixBin(kstar*2)));

		//    hist->SetBinContent(ibins, hist->GetBinContent(ibins));
		//    hist->SetBinContent(ibins, hist->GetBinContent(ibins));
	}

	TFile* fileOut = new TFile(Form("kstar_%s",filename), "update");
	hist->Write();
	histnew->Write();
}
コード例 #18
0
void RunTest(const char* name, const char* uselesstitle, int numentries, int BufferSize) {
   TString title;
   title += numentries;
   title.Append(" events, 10 branches, 10 floats in brunch, Basket size = ");
   title += ( BufferSize*10*10*4 );
   TH1D* histoRes = new TH1D(name, title, 10, 0.5, 10.5);
   histoRes->GetXaxis()->SetTitle("Number of active branches");
   histoRes->GetYaxis()->SetTitle("Real time (s)");
   histoRes->SetDirectory(0);
   histoRes->SetStats(kFALSE);
   ProduceTree("TreeFile.root","TestTree", numentries, 0, 10, 10, BufferSize);

   Float_t RealTime, CpuTime;
    
   for(int ActiveBranches=1;ActiveBranches<=10;ActiveBranches++) {
      PurgeMemory();  
      cout << "Buffer size = " << BufferSize*sizeof(Float_t)*10 << " ActiveBranches = " << ActiveBranches << endl;
      MakeDelay(5);
      TestTree("TreeFile.root","TestTree", 10, 10, ActiveBranches, RealTime, CpuTime);
      histoRes->SetBinContent(ActiveBranches, RealTime);
   } 
    
   TCanvas* c1 = new TCanvas(TString(name)+"_canvas",title);
   histoRes->Draw();
   c1->SaveAs(TString(name)+".gif");
}
コード例 #19
0
void Pileup_reweight_gen() {

   TFile *f1 = new TFile("MyDataPileupHistogram_true.root");
   TH1D *hPU_data = (TH1D*)f1->Get("pileup");  

   TFile *f2 = new TFile("PU_MC_histo.root");
   TH1D *hPU_MC = (TH1D*)f2->Get("PU_MC");

   hPU_data->Scale(1.0/hPU_data->Integral());
   hPU_MC->Scale(1.0/hPU_MC->Integral());

   TH1D *pileupWeights = new TH1D("pileupWeights", "Computed Weights", 52, 0., 52);


  std::vector<double> weights(hPU_data->GetNbinsX()+1, 1.0);

  for (int i = 1, n = weights.size(); i < n; ++i) {
        double nMC = hPU_MC->GetBinContent(i), nData = hPU_data->GetBinContent(i);
        weights[i-1] = (nMC > 0 ? nData/nMC : 1.0);
        pileupWeights->SetBinContent(i,weights[i-1]);
    }

  
     pileupWeights->Draw(); 

   TFile *outFile = new TFile("pileupWeights.root", "RECREATE");
   outFile->cd();
   pileupWeights->Write();
   outFile->Close();



}
コード例 #20
0
ファイル: etaFit.C プロジェクト: nikberry/DailyCScripts
TH1D* getQCD(int rebinFact){
	TString dir = "rootFiles/";
	
	TFile* file = new TFile(dir +"qcdest.root");		
	TH1D* plot = (TH1D*) file->Get("muon_AbsEta_0btag");

// 	for(int i = 1; i <= plot->GetNbinsX(); i++){
// 	plot->SetBinError(i, 0.0);
// 	}

	plot->SetFillColor(kYellow);
	plot->SetLineColor(kYellow);
	plot->SetMarkerStyle(1);
		
	TH1D* copyplot = new TH1D("qcd plot", "qcd plot", 30, 0.0, 3.0);
	
	for(int i = 1; i <= plot->GetNbinsX(); i++){
	copyplot->SetBinContent(i, plot->GetBinContent(i));
	//copyplot->SetBinError(i, plot->GetBinError(i));
	}
	copyplot->SetFillColor(kYellow);
	copyplot->SetLineColor(kYellow);
	copyplot->SetMarkerStyle(1);
	copyplot->Scale(1./copyplot->Integral());	
	copyplot->Rebin(rebinFact);
	
	//file->Close("R");
	return copyplot;
	//file->Close();
}
コード例 #21
0
void RunTest(const char* name, int numentries, int BufferSize) {
   char title[200];
   sprintf(title, "%d events, 10 branches, 10 floats in brunch, Basket size = %d", numentries, BufferSize*sizeof(Float_t)*10);

   TH1D* histoRes = new TH1D(name, title, 10, 0.5, 10.5);
   histoRes->GetXaxis()->SetTitle("Number of active branches");
   histoRes->GetYaxis()->SetTitle("Real time (s)");
   histoRes->SetDirectory(0);
   histoRes->SetStats(kFALSE);
   ProduceTree("TreeFile.root","TestTree", numentries, 0, 10, 10, BufferSize);

   Float_t RealTime, CpuTime;
    
   for(int ActiveBranches=1;ActiveBranches<=10;ActiveBranches++) {
      ReadDummyTree();
      cout << "Buffer size = " << BufferSize*sizeof(Float_t)*10 << " ActiveBranches = " << ActiveBranches << endl;
      MakeDelay(10);
      TestTree("TreeFile.root","TestTree", 10, 10, ActiveBranches, &RealTime, &CpuTime);
      histoRes->SetBinContent(ActiveBranches, RealTime);
   } 
   
   TCanvas* c1 = new TCanvas(TString(name)+"_canvas", title);
   histoRes->Draw();
   c1->SaveAs(TString(name)+".gif");
}
コード例 #22
0
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;

}
コード例 #23
0
void doJob(std::string name,std::string nominame){
	std::vector<TH1D*> histUp = hists("up","Up");
	std::vector<TH1D*> histDown = hists("down","Down");
	TH1D * nominal = GetNominal(nominame);
	TH1D * h = new TH1D(name.c_str(), name.c_str(), histUp[0]->GetXaxis()->GetNbins(), -1.,1.);
	cout<<"before loop "<<h->GetXaxis()->GetNbins()<<endl;
	for(int iBin = 0; iBin < h->GetXaxis()->GetNbins(); iBin++){
		double sum = 0;
		cout<<"Bin "<<iBin+1<<"\t"<<histDown.size()<<"\t"<<histUp.size()<<endl;
		for(unsigned int i = 0; i < histDown.size(); i++){
			cout<<"---------- file "<< i+1<<"\t"<<histDown[i]<<"\t"<<histUp[i]<<endl;
			cout<<nominal->GetBinContent(iBin + 1)<<"\t"<<histDown[i]->GetXaxis()->GetNbins()<<endl;
			cout<<"\t"<<histUp[i]->GetBinContent(iBin + 1)<<endl;
			cout<<histDown[i]->GetBinContent(iBin + 1); 
			double iDown = fabs(histDown[i]->GetBinContent(iBin + 1) - nominal->GetBinContent(iBin + 1));
			double iUp = fabs(histUp[i]->GetBinContent(iBin + 1) - nominal->GetBinContent(iBin + 1));
			double iAvg = (iUp + iDown)/2.;
			sum+= pow(iAvg,2);
			cout<<iDown<<"\t"<<iUp<<"\t"<<iAvg<<"\t"<<sum<<endl;
		}
		h->SetBinContent(iBin + 1, nominal->GetBinContent(iBin + 1));
		h->SetBinError(iBin + 1, sqrt(sum));
	}
	cout<<"After loop"<<endl;
	TFile * final = new TFile(name.c_str(),"recreate");
	TDirectory * d = final->mkdir("Default_allW");
	h->SetName("Default_allWcosTheta");
	d->cd();
	h->Write();
	final->Close();
コード例 #24
0
ファイル: fitBarea.C プロジェクト: KiSooLee/Bntuple
void fitBarea(TString infname="",bool doweight = 1)
{
  if (doweight==0) weight="1";
  if (infname=="") infname=inputdata.Data();
  TFile *inf = new TFile(infname.Data());
  TTree *nt = (TTree*) inf->Get("ntKp");

  TFile *infMC = new TFile(inputmc.Data());
  TTree *ntGen = (TTree*)infMC->Get("ntGen");
  TTree *ntGen2 = (TTree*)inf->Get("ntGen");
  TTree *ntMC = (TTree*)infMC->Get("ntKp");
    
  ntGen->AddFriend(ntMC);
  ntGen2->AddFriend(ntMC);
    
  const int nBins = 1;
  double ptBins[nBins+1] = {10,60};
//  const int nBins = 1;
//  double ptBins[nBins+1] = {10,60};
  TH1D *hPt = new TH1D("hPt","",nBins,ptBins);

  for (int i=0;i<nBins;i++)
    {
      TF1 *f = fit(nt,ntMC,ptBins[i],ptBins[i+1]);
      double yield = f->Integral(5,6)/0.02;
      double yieldErr = f->Integral(5,6)/0.02*f->GetParError(0)/f->GetParameter(0);
      hPt->SetBinContent(i+1,yield/(ptBins[i+1]-ptBins[i]));
      hPt->SetBinError(i+1,yieldErr/(ptBins[i+1]-ptBins[i]));
    }
  
}
コード例 #25
0
TH1D *makeDiffHist(TH1D* hData, TH1D* hFit, const TString name)
{
  TH1D *hDiff = (TH1D*)hData->Clone("hDiff");
  hDiff->SetName(name);
  for(Int_t ibin=1; ibin<=hData->GetNbinsX(); ibin++) {
    
    Double_t diff=0;
    Double_t err=0;
    if(hData->GetBinContent(ibin)!=0)
      {
	diff = hFit->GetBinContent(ibin)/hData->GetBinContent(ibin);
	err = hFit->GetBinError(ibin)/hData->GetBinContent(ibin);
      }
    hDiff->SetBinContent(ibin,diff);
    hDiff->SetBinError(ibin,err);   
  }
  
  hDiff->GetYaxis()->SetTitleOffset(0.55);
  hDiff->GetYaxis()->SetTitleSize(0.13);
  hDiff->GetYaxis()->SetLabelSize(0.10);
  hDiff->GetYaxis()->SetNdivisions(104);
  hDiff->GetYaxis()->CenterTitle();
  hDiff->GetXaxis()->SetTitleOffset(1.2);
  hDiff->GetXaxis()->SetTitleSize(0.13);
  hDiff->GetXaxis()->SetLabelSize(0.12);
  hDiff->GetXaxis()->CenterTitle();
  
  return hDiff;
}
コード例 #26
0
ファイル: drawPaEta.C プロジェクト: CmsHI/gammaJetAnalysis
void drawPaEta( bool saveFigures=false) {
  TFile * fData = new TFile("../histogramProducer/ffFiles/photonTrackCorr_ppbDATA_output_photonPtThr40_to_9999_jetPtThr30_20130829.root");
  TH1D* hD1 = (TH1D*)fData->Get("etaJg_icent1_final");
  TH1D* hD2 = (TH1D*)fData->Get("etaJg_icent2_final");
  TH1D* hD3 = (TH1D*)fData->Get("etaJg_icent3_final");

  TFile * fMC = new TFile("../histogramProducer/ffFiles/photonTrackCorr_ppbMC_output_photonPtThr40_to_9999_jetPtThr30_20130829.root");
  TH1D* hM1 = (TH1D*)fMC->Get("etaJg_icent1_final");
  TH1D* hM2 = (TH1D*)fMC->Get("etaJg_icent2_final");
  TH1D* hM3 = (TH1D*)fMC->Get("etaJg_icent3_final");

  TCanvas* c1 = new TCanvas("c1","",500,500);
  handsomeTH1(hD1,1);
  handsomeTH1(hD2,4);
  handsomeTH1(hD3,2);
  hD1->Rebin(10);
  hD2->Rebin(10);
  hD3->Rebin(10);

  hD1->Draw();
  hD2->Draw("same");
  hD3->Draw("same");

  TCanvas* c2 = new TCanvas("c2","",400,400);
  TH1D* hmData = new TH1D("hmData",";HF energy;",nCentBinPa,centBinPa);
  hmData->SetBinContent(1, hD1->GetMean());
  hmData->SetBinContent(2, hD2->GetMean());
  hmData->SetBinContent(3, hD3->GetMean());
  hmData->SetBinError(1, hD1->GetMeanError());
  hmData->SetBinError(2, hD2->GetMeanError());
  hmData->SetBinError(3, hD3->GetMeanError());
  TH1D* hmMc = new TH1D("hmMc",";HF energy;",nCentBinPa,centBinPa);
  hmMc->SetBinContent(1, hM1->GetMean());
  hmMc->SetBinContent(2, hM2->GetMean());
  hmMc->SetBinContent(3, hM3->GetMean());
  hmMc->SetBinError(1, hM1->GetMeanError());
  hmMc->SetBinError(2, hM2->GetMeanError());
  hmMc->SetBinError(3, hM3->GetMeanError());
  handsomeTH1(hmData,2);
  handsomeTH1(hmMc,1);
  hmMc->SetMarkerStyle(24);
  hmMc->Draw();
  hmData->Draw("same");
  

}
コード例 #27
0
ファイル: PlotDrmCorr.C プロジェクト: xcheung/AnaSubjetsMC
//_____________________________________________________________________________
TH1D *SetRMS(TH2D *h2, const TString s)
{
  TH1D *h = h2->ProjectionX(s.Data()); h->Reset();
  for (Int_t kx=1; kx<=h2->GetNbinsX(); kx++) {
    TH1D *hTmp = h2->ProjectionY(Form("hTmp_%d",kx), kx, kx);

    if (hTmp->Integral()<=0.)
      h->SetBinContent(kx, 0.);
    else
      h->SetBinContent(kx, hTmp->GetRMS());

      cout << h->GetBinContent(kx) << endl;
    delete hTmp; hTmp = 0;
  }

  return h;
}
コード例 #28
0
ファイル: fft.C プロジェクト: svn2github/Go4
///////////////////////////////////////////////////////////////////
//////// Go4 GUI example script fft.C
//          J.Adamczewski, gsi, 30 May 2012
// NOTE: to be run in Go4 GUI local command line only!
//       NEVER call this script in remote analysis process!!!
/////// Functionality:
// perfroms fft on histogram of name1 using the option as explained in root TVirtualFFT:FFT
/////// Usage:
// The draw flag switches if the results are displayed each time this macro is called
// if display is switched off, the result histogram is just updated in browser and existing displays
///////
Bool_t fft(const char* name1, Option_t*  opt = "R2C M", Bool_t draw=kTRUE)
{
   if(TGo4AbstractInterface::Instance()==0 || go4!=TGo4AbstractInterface::Instance()) {
      std::cout <<"FATAL: Go4 gui macro executed outside Go4 GUI!! returning." << std::endl;
      return kFALSE;
   }
   TString newname;
   TString fullname1 = go4->FindItem(name1);
   TObject* ob1 = go4->GetObject(fullname1,1000); // 1000=timeout to get object from analysis in ms

   if ((ob1==0) || !ob1->InheritsFrom("TH1")) {
     std::cout <<"fft could not get histogram "<<fullname1 << std::endl;
     return kFALSE;
   }

   if(ob1->InheritsFrom("TH2") || ob1->InheritsFrom("TH3")){  // 2d
      std::cout <<"fft does not support 2d/3d histogram "<<fullname1 << std::endl;
      return kFALSE;
   }

   TH1* his1=(TH1*)ob1;
   TString n1=his1->GetName();
   TString t1=his1->GetTitle();
   newname.Form("_fft_%s",opt);
   TString finalname = n1+newname;
   TString finaltitle = t1+newname;


   // do fft here:
   Int_t N = his1->GetNbinsX();
   TH1D* result = new TH1D(finalname, finaltitle,N,0,N);
   result->SetName(finalname);
   result->SetTitle(finaltitle);
   result->Reset("");
   Double_t *in = new Double_t[N];
   // since we do not know type of input histo, we copy contents to Double array:
   for(Int_t ix=0; ix<N;++ix)
   {
      in[ix]=his1->GetBinContent(ix+1);
   }
   TVirtualFFT *thefft = TVirtualFFT::FFT(1, &N, opt);
   thefft->SetPoints(in);
   thefft->Transform();
   Double_t re, im;
   for (Int_t i=0; i<N; i++) {
      thefft->GetPointComplex(i, re, im);
      result->SetBinContent(i+1,TMath::Sqrt(re*re + im*im));
   }
   result->SetDirectory(0);

   TString rname = go4->SaveToMemory("FFT", result, kTRUE);
   std::cout<< "Saved result histogram to " << rname.Data() <<std::endl;
   if(draw){
      ViewPanelHandle vpanel = go4->StartViewPanel();
      go4->DrawItem(rname, vpanel);
   }
   return kTRUE;
}
コード例 #29
0
void transferxSecFromTextToROOT(std::string inputStr="xSec_T3G.txt"){

   ifstream fin(inputStr.c_str());
   char line[200];
   TFile *xSecProspinoFile =0;
   TH1D *xSecProspino =0; 
   int minMom = 1000000, maxMom = 0;
   int nBins = 0;

   std::vector<int> momVec; std::vector<double> xSecVec, xSecErrVec;
   while( fin.getline(line, 200) ){
      TString lineT(line);
      if( lineT.Contains("Interactions") ) continue;
      TObjArray *vlist = lineT.Tokenize(" ");
      int nEntries = vlist->GetEntries();
      int mMom;
      double xSec =0, xSecRelErr =0;
      for(int ie=0; ie<nEntries; ie++){
         TObjString* perObj = dynamic_cast<TObjString*>(vlist->At(ie));
         TString perStr = perObj->GetString();
         if( ie==0 ){
            mMom = perStr.Atoi();
            if( minMom > mMom ) minMom = mMom;
            if( maxMom < mMom ) maxMom = mMom;
         }
         if( ie==1 ) xSec = perStr.Atof();
         if( ie==2 ) xSecRelErr = perStr.Atof();
      }
      nBins ++;
      momVec.push_back(mMom); xSecVec.push_back(xSec); xSecErrVec.push_back(xSec*xSecRelErr/100.);
//      std::cout<<"mMom : "<<mMom<<"  xSec : "<<xSec<<"  xSecRelErr : "<<xSecRelErr<<std::endl;
   }
   double divBin = 1.0*(maxMom - minMom)/(nBins-1);
   double lowMom = minMom-divBin/2.0, highMom = maxMom+divBin/2.0;
   std::cout<<"nBins : "<<nBins<<"  minMom : "<<minMom<<"  maxMom : "<<maxMom<<"  divBin : "<<divBin<<"  lowMom : "<<lowMom<<"  highMom : "<<highMom<<std::endl;

   TString rootStrT(inputStr);
   rootStrT.ReplaceAll("txt", "root");

   std::cout<<"root file : "<<rootStrT<<std::endl;
   xSecProspinoFile = new TFile(rootStrT, "RECREATE");

   if( rootStrT.Contains("T1") ) xSecProspino = new TH1D("gluino_xsection", "gluino_xsection", nBins, lowMom, highMom);
   if( rootStrT.Contains("T2") ) xSecProspino = new TH1D("squark_xsection", "squark_xsection", nBins, lowMom, highMom);
   if( rootStrT.Contains("T3G") ) xSecProspino = new TH1D("stop_xsection", "stop_xsection", nBins, lowMom, highMom);

   for(int iv=0; iv<(int)momVec.size(); iv++){
      double mMom = (double)momVec[iv];
      int ib = xSecProspino->FindFixBin(mMom);
      xSecProspino->SetBinContent(ib, xSecVec[iv]);
      xSecProspino->SetBinError(ib, xSecErrVec[iv]);
   }

//   xSecProspino->Write();
   xSecProspinoFile->Write(); xSecProspinoFile->Close();

}
コード例 #30
0
// Draw 1D histos
TH1D *plot1Dhisto(double intLumi,TFile *fileName,TString folderName,TString histoName,int color,int rebin,float xMin,float xMax,TString xName, TString yName,TString sampleName,bool mc) {  
  
  TH1D *hTemp = (TH1D*)fileName->Get(folderName+"/"+histoName);
  hTemp->SetName(histoName+"_"+sampleName);
  if (mc){ 
    hTemp->Scale(intLumi/100.);
  }
  hTemp->Rebin(rebin);
  hTemp->SetLineColor(color);
  hTemp->SetLineWidth(5);
  hTemp->GetXaxis()->SetRangeUser(xMin,xMax);
  hTemp->GetXaxis()->SetTitle(xName);
  hTemp->GetXaxis()->SetTitleSize(0.06);
  hTemp->GetXaxis()->SetLabelSize(0.06);
  hTemp->GetYaxis()->SetTitle(yName);
  hTemp->GetYaxis()->SetTitleSize(0.06);
  hTemp->GetYaxis()->SetLabelSize(0.06);
  hTemp->SetTitleOffset(1.5, "Y");
  // last/first bin: put over/underflow
  hTemp->SetBinContent(hTemp->FindBin(xMax),hTemp->Integral(hTemp->FindBin(xMax),hTemp->GetNbinsX()+1));
  hTemp->SetBinContent(hTemp->FindBin(xMin),hTemp->Integral(-1,hTemp->FindBin(xMin)));  

  hTemp->SetBinError(hTemp->FindBin(xMax),sqrt(hTemp->Integral(hTemp->FindBin(xMax),hTemp->GetNbinsX()+1)));
  hTemp->SetBinError(hTemp->FindBin(xMin),sqrt(hTemp->Integral(-1,hTemp->FindBin(xMin))));
  //fileName->Close();

  /*
  if (histoName != "LP_tot") {
    if (histoName != "SumLepPt_tot") {
      if ((folderName == "ANplots150_NOLP")) { hTemp->GetXaxis()->SetRangeUser(0.,300.); } 
      if ((folderName == "ANplots250_NOLP")) { hTemp->GetXaxis()->SetRangeUser(0.,400.); }
      if ((folderName == "ANplots350_NOLP")) { hTemp->GetXaxis()->SetRangeUser(0.,500.); }
      if ((folderName == "ANplots450_NOLP")) { hTemp->GetXaxis()->SetRangeUser(0.,1000.); }
    }
    else {
      if ((folderName == "ANplots150_NOLP")) { hTemp->GetXaxis()->SetRangeUser(100.,300.); } 
      if ((folderName == "ANplots250_NOLP")) { hTemp->GetXaxis()->SetRangeUser(200.,400.); }
      if ((folderName == "ANplots350_NOLP")) { hTemp->GetXaxis()->SetRangeUser(300.,500.); }
      if ((folderName == "ANplots450_NOLP")) { hTemp->GetXaxis()->SetRangeUser(400.,1000.); }
    }
  } 
  */ 
  return hTemp;
} // ~ end of plot1Dhisto function