Ejemplo n.º 1
0
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();
}
Ejemplo n.º 2
0
// this is the event loop
void BeamGas::loop() {

  // DO ANY SETUP HERE
  nTracks_ = new TH1D("hNTracks", "N_{trk}", 100, 0., 100.);
  nTracksHQ_ = new TH1D("hNTracksHQ", "N_{trkHQ}", 100, 0., 100.);

  nTracksNoVtx_ = new TH1D("hNTracksNoVtx", "N_{trk}", 100, 0., 100.);
  nTracksHQNoVtx_ = new TH1D("hNTracksHQNoVtx", "N_{trkHQ}", 100, 0., 100.);

  trackPFraction_ = new TH1D("hTrackPFraction", "", 100, 0., 2.);

  reset();
  nextEvent();

  for (unsigned long i=0; i<maxEvents_; ++i, nextEvent()) {

    // occasional print out
    if (i%100000==0) {
      std::cout << "Processing " << i << "th event of " <<maxEvents_<< std::endl;
    }

    // YOUR CODE HERE
    if (event_->jet_N>0 && event_->jetE[0]>50. && event_->jetEta[0]<1.3) {

      // count tracks of different types
      unsigned nTracks(0), nTracksHQ(0);
      for (unsigned j=0; j<event_->track_N; ++j) {
	nTracks++;
      	if (event_->trackQuality[0] == 1) nTracksHQ++;
      }
      
      nTracks_->Fill(nTracks);
      nTracksHQ_->Fill(nTracksHQ);

      if (event_->vtx_N == 0) {
	nTracksNoVtx_->Fill(nTracks);
	nTracksHQNoVtx_->Fill(nTracksHQ);
      }

      // leading jet/track ratio
      if (event_->track_N>0) {
	trackPFraction_->Fill(event_->trackP[0]/event_->jetE[0]);
      }

    }

  }


  // SAVE HISTOGRAMS HERE
  nTracks_->Write("",TObject::kOverwrite);
  nTracksHQ_->Write("",TObject::kOverwrite);
  nTracksNoVtx_->Write("",TObject::kOverwrite);
  nTracksHQNoVtx_->Write("",TObject::kOverwrite);
  trackPFraction_->Write("",TObject::kOverwrite);
  
}
Ejemplo n.º 3
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();
    }
  }
}
int produceEnergyHistos(CSPrereqs& csp)
{
    cout << endl << "Mapping " << csp.name << " TOF histogram to energy domain..." << endl;

    // open input file
    TFile* inputFile = new TFile(inputFileName.c_str(),"READ");
    if(!inputFile->IsOpen())
    {
        cerr << "Error: failed to open " << inputFileName << "  to fill histos." << endl;
        return 1;
    }

    // create output file
    TFile* outputFile = new TFile(outputFileName.c_str(),"RECREATE");

    for(auto& channelName : config.cs.DETECTOR_NAMES)
    {
        TDirectory* detectorDirectory = inputFile->GetDirectory(channelName.c_str());
        if(!detectorDirectory)
        {
            cerr << "Error: failed to find " << channelName << " directory in " << inputFileName << "." << endl;
            return 1;
        }

        TDirectory* outputDirectory = outputFile->mkdir(channelName.c_str(),channelName.c_str());

        // find TOF histograms in input file
        for(int i=0; i<config.target.TARGET_ORDER.size(); i++)
        {
            string targetName = config.target.TARGET_ORDER[i];
            string TOFHistoName = targetName + "TOFCorrected";

            detectorDirectory->cd();

            TH1D* TOF = (TH1D*)detectorDirectory->Get(TOFHistoName.c_str());
            if(!TOF)
            {
                cerr << "Error: failed to open " << TOFHistoName << " in " << inputFileName << endl;
                return 1;
            }

            outputDirectory->cd();

            TH1D* correctedEnergy = convertTOFtoEnergy(TOF, targetName + "Energy");
            TOF->Write();
            correctedEnergy->Write();
        }
    }

    outputFile->Close();
    inputFile->Close();

    return 0;
}
Ejemplo n.º 5
0
// Takes as input a given process with corresponding luminosity, as well as sample CME, cuts, directory location, and output file name - saves corresponding histogram in root file.
void processtree(TString sample, Double_t weight, TLorentzVector CME, TString filename, TString directory, TString param, TString cut, std::clock_t start, Int_t all){

    //Open File
    TFile *f = new TFile(directory);
    TTree *ttree = (TTree*)f->Get(sample);

    TString recohistname, paramhistname;
    if (all==0){
        recohistname = "_recoilmassHIST";
        paramhistname = "_parameterHIST";
    }
    if (all==1){
        recohistname = "_recoilmassHIST_all";
        paramhistname = "_parameterHIST_all";
    }

    TString histname = sample + recohistname;
    TH1D *recoilmassHIST   = new TH1D(histname,histname,CME.M()/2,0,CME.M());
    //recoilmassHIST->SetCanExtend(kAllAxes);
    ttree->Project(histname, "recoilmass", cut);

    histname = sample + paramhistname;
    TH1D *parameterHIST   = new TH1D(histname,histname,CME.M()/2,1,-1);
    //parameterHIST->SetCanExtend(kAllAxes);
    ttree->Project(histname, param, cut);

    //Normalize Hist
    recoilmassHIST->Scale(1/recoilmassHIST->GetMaximum());
    parameterHIST->Scale(1/parameterHIST->GetMaximum()) ;

    //Normalize Hist
//    recoilmassHIST->Scale(weight);
//    parameterHIST->Scale(weight) ;

    // Writes yield of each histogram for each cut to text file
    ofstream myfile;
    Double_t yield = recoilmassHIST->Integral(); 
    myfile.open ("yield.txt", ios::app);
        cout << "Yield for " << sample << " for Cut " << param << " is " << yield << endl;
        myfile << param << " " << all << " " << sample << " " << yield << "\n"; //write to file
    myfile.close();

    if (recoilmassHIST->Integral() == 0){
        recoilmassHIST->Fill(0);
    }
    if (parameterHIST->Integral() == 0){
        parameterHIST->Fill(0);
    }

    TFile g(filename, "update");
    recoilmassHIST->Write();
    parameterHIST->Write();
    g.Close();
}
Ejemplo n.º 6
0
void photonSpectra()
{
  TH1::SetDefaultSumw2();

  const Double_t PTBINS[] = {40, 50, 60, 80, 120, 300};
  const Int_t nPTBINS = 5;

  const TString DATA_FILE = "gammaJets_pA_Data.root";
  const TString MC_FILE = "gammaJets_pA_MC_allQCDPhoton.root";
  TFile *dataFile = TFile::Open(DATA_FILE);
  TTree *dataTree = (TTree*)dataFile->Get("photonTree");
  TFile *mcFile = TFile::Open(MC_FILE);
  TTree *mcTree = (TTree*)mcFile->Get("photonTree");

  TH1D *photonSpectra = new TH1D("photonSpectra","photonSpectra", nPTBINS, PTBINS);
  TH1D *correctedPhotonSpectra = (TH1D*)photonSpectra->Clone("correctedPhotonSpectra");

  const TCut photonEtaCut = "abs(photonTree.eta) < 1.44";
  const TCut isoCut = "ecalRecHitSumEtConeDR04 < 4.2  &&  hcalTowerSumEtConeDR04 < 2.2  &&  trkSumPtHollowConeDR04 < 2 && hadronicOverEm<0.1";
  const TCut genCut = "genCalIsoDR04<5 && abs(genMomId)<=22";
  const TCut sbCut = "(cc4+cr4+ct4PtCut20>10) && (cc4+cr4+ct4PtCut20<20) && hadronicOverEm<0.1";
  const TCut candidateCut = "sigmaIetaIeta<0.01";
  const TCut decayCut = "(sigmaIetaIeta>0.011) && (sigmaIetaIeta<0.017)";

  TCut photonPtCut = "photonTree.corrPt>40 && photonTree.corrPt<300";

  dataTree->Project(photonSpectra->GetName(),"corrPt",isoCut && photonEtaCut && photonPtCut && candidateCut);

  for(int i = 0; i<nPTBINS; ++i)
  {
    photonPtCut = Form("photonTree.corrPt>%f && photonTree.corrPt<%f", PTBINS[i], PTBINS[i+1]  );

    TCut dataCandidateCut = isoCut && photonEtaCut && photonPtCut;
    TCut sidebandCut =  sbCut && photonEtaCut && photonPtCut;
    TCut mcSignalCut = dataCandidateCut && genCut;

    fitResult fitr = getPurity(dataTree, mcTree,
  			       dataCandidateCut, sidebandCut,
  			       mcSignalCut);
    Double_t purity = fitr.purity;
    correctedPhotonSpectra->SetBinContent(i+1,photonSpectra->GetBinContent(i+1)*purity);
  }

  // TCanvas *c1 = new TCanvas();
  // photonSpectra->Draw();
  // correctedPhotonSpectra->Draw("same");

  TFile *outFile = new TFile("photonSpectra.root", "RECREATE");
  outFile->cd();
  photonSpectra->Write();
  correctedPhotonSpectra->Write();
  outFile->Close();
}
void savePlots2(const std::string& canvasName, TH1D& dataPlot, TH1D& fitPlot,
		TH1D& signalPlot, TH1D& bkgPlot) {
  TCanvas c(canvasName.c_str(), canvasName.c_str()) ;
  TPad mainPad("mainPad", "mainPad", 0., 0.2, 1., 1.) ;
  mainPad.Draw() ;
  TPad pullPad("pullPad", "pullPad", 0., 0., 1., 0.2) ;
  pullPad.Draw() ;

  mainPad.cd() ;
  dataPlot.SetStats(true) ;
  //dataPlot.SetOptStat(111111111);
  dataPlot.SetLineWidth(2) ;
  dataPlot.Draw() ;
  fitPlot.SetLineWidth(2) ;
  fitPlot.SetLineColor(kBlue) ;
  fitPlot.Draw("same") ;
  signalPlot.SetLineWidth(2) ;
  signalPlot.SetLineColor(kGreen) ;
  signalPlot.Draw("same") ;
  bkgPlot.SetLineColor(kRed) ;
  bkgPlot.SetLineWidth(2) ;
  bkgPlot.Draw("same") ;

  TLegend leg(0.6, 0.7, 0.9, 0.9) ;
  leg.AddEntry(&dataPlot, "Data") ;
  leg.AddEntry(&fitPlot, "Fit") ;
  leg.AddEntry(&signalPlot, "Signal") ;
  leg.AddEntry(&bkgPlot, "Background") ;
  leg.SetFillStyle(0) ;
  leg.SetBorderSize(0) ;
  leg.Draw() ;

  pullPad.cd() ;
  pullPad.SetGridy() ;
  TH1D* h_residuals(NULL), *h_pulls(NULL), *h_pullDistribution(NULL) ;
  FitterTools::makePullPlot(dataPlot, fitPlot, h_residuals, h_pulls, h_pullDistribution) ;
  h_pulls->Draw() ;

  c.Write() ;

  h_pulls->Write() ;
  delete h_pulls ;
  h_residuals->Write() ;
  delete h_residuals ;
  h_pullDistribution->Write() ;
  delete h_pullDistribution ;

  dataPlot.Write() ;
  fitPlot.Write() ;
}
Ejemplo n.º 8
0
void MCefficiency(TString inputmc, TString outputfile, TString tfend, TString selmcgen, TString cut, TString weight, Float_t centmin, Float_t centmax)
{
  Float_t hiBinMin,hiBinMax;
  hiBinMin = centmin*2;
  hiBinMax = centmax*2;

  selmcgen = Form("%s&&hiBin>=%f&&hiBin<%f",selmcgen.Data(),hiBinMin,hiBinMax);
  cut = Form("%s&&hiBin>=%f&&hiBin<%f",cut.Data(),hiBinMin,hiBinMax);

  TFile* infMC = new TFile(inputmc.Data());
  TTree* ntMC = (TTree*)infMC->Get("ntDkpi");
  ntMC->AddFriend("ntHi");
  ntMC->AddFriend("ntSkim");
  TTree* ntGen = (TTree*)infMC->Get("ntGen");
  ntGen->AddFriend("ntHi");
  ntGen->AddFriend("ntSkim");

  TH1D* hPtMC = new TH1D("hPtMC","",nPtBins,ptBins);
  TH1D* hPtGen = new TH1D("hPtGen","",nPtBins,ptBins);

  ntMC->Project("hPtMC","Dpt",TCut(weight)*(TCut(cut.Data())&&"(Dgen==23333)"));
  divideBinWidth(hPtMC);
  ntGen->Project("hPtGen","Gpt",TCut(weight)*(TCut(selmcgen.Data())));
  divideBinWidth(hPtGen);
  TH1D* hEff = (TH1D*)hPtMC->Clone("hEff");
  hEff->Divide(hPtGen);

  TFile* fout=new TFile(Form("%s_cent_%.0f_%.0f_%s.root",outputfile.Data(),centmin,centmax,tfend.Data()),"recreate");
  fout->cd();
  hEff->Write();
  fout->Close();
}
Ejemplo n.º 9
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();
Ejemplo n.º 10
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 ());
}
Ejemplo n.º 11
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();



}
Ejemplo n.º 12
0
void rebin (const char* filename, const char* histname, double rebin=2.0) {
        TFile* f = new TFile(filename,"update");
        TH1D* h = (TH1D*)f->Get(histname);
        h->Rebin(rebin);
        h->Scale(1.0/rebin);
        TFile* fileOut = new TFile(Form("rebin_%s",filename), "update");
        h->Write();
}
Ejemplo n.º 13
0
Archivo: merge.C Proyecto: XuQiao/HI
void merge(){
	TVectorD Nevent;	Nevent.ResizeTo(nbin);  Nevent.Zero();
     //   TVectorD totmultall;	totmultall.ResizeTo(nbin);      totmultall.Zero();
     //   TVectorD avgmultall;	avgmultall.ResizeTo(nbin);      avgmultall.Zero();
        TVectorD tottrk;	tottrk.ResizeTo(nbin);      tottrk.Zero();
//	TVectorD totptall;      totptall.ResizeTo(nbin);    totptall.Zero();
//	TVectorD totetaall;      totetaall.ResizeTo(nbin);    totetaall.Zero();
        TVectorD avgtrk;	avgtrk.ResizeTo(nbin);      avgtrk.Zero();
//	TVectorD avgmult;       avgmult.ResizeTo(nbin);
            
        TH2F* s[nbin];
        TH2F* b[nbin];
        for(int ibin=0;ibin<nbin;ibin++){
            s[ibin] = new TH2F(Form("s_%d",ibin),Form("signal",ibin),detastep,detamin,detamax,dphistep,dphimin,dphimax);
            s[ibin]->Sumw2();
            b[ibin]  = new TH2F(Form("b_%d",ibin), "background",detastep,detamin,detamax,dphistep,dphimin,dphimax);
            b[ibin]->Sumw2();
        }
        TFile *fout = new TFile(Form("Anav3_merged.root"),"Recreate");
        TFile *f[nFileAll];
        for(int ifile=; ifile<63; ifile++){
                f[ifile] = TFile::Open(Form("%s/Anav3_%d.root",outdir.Data(),ifile));
                if(!f[ifile]) continue;
		TVectorD* Nevent_t =  (TVectorD*)f[ifile]->Get(Form("Nevent"));
	//	TVectorD* totmultall_t =  (TVectorD*)f[ifile]->Get(Form("totmultall"));
		TVectorD* tottrk_t =  (TVectorD*)f[ifile]->Get(Form("tottrk"));
	//	TVectorD* totptall_t =  (TVectorD*)f[ifile]->Get(Form("totptall"));
//		TVectorD* totetaall_t =  (TVectorD*)f[ifile]->Get(Form("totetaall"));
		for(int ibin=0;ibin<nbin;ibin++){
			//	totptall[ibin] += (*totptall_t)[ibin];
			//	totetaall[ibin] += (*totetaall_t)[ibin];
			        Nevent[ibin] += (*Nevent_t)[ibin];
			  //      totmultall[ibin] += (*totmultall_t)[ibin];	
			        tottrk[ibin] += (*tottrk_t)[ibin];	
                                TH1D* s_t = (TH1D*)f[ifile]->Get(Form("signal_%d",ibin));
                                TH1D* b_t = (TH1D*)f[ifile]->Get(Form("background_%d",ibin));
                                s[ibin]->Add(s_t);
                                b[ibin]->Add(b_t);
		}
		f[ifile]->Close();
        }
    for(int ibin=0;ibin<nbin;ibin++){
    avgtrk[ibin] = tottrk[ibin]/Nevent[ibin];
    TH1D* hr = (TH1D*)s[ibin]->Clone("hr");
    hr->Divide(b[ibin]);
    hr->Scale(b[ibin]->GetBinContent(b[ibin]->FindBin(0,0)));

    fout->cd();
    Nevent.Write("Nevent");
    avgtrk.Write("avgtrk");
    TDirectory *dir0 = (TDirectory*)fout->mkdir(Form("D_%d",ibin));
    dir0->cd();
    s[ibin]->Write("s");
    b[ibin]->Write("b");
    hr->Write();
    }
}
Ejemplo n.º 14
0
int main(){
	TFile * data = TFile::Open("TreesMu_Data_plots.root");
	TH1D * dataMtop = (TH1D*)data->Get("antiEtaFwDTrue_allW/antiEtaFwDTrue_allWcosTheta");
	
	TFile * tt = TFile::Open("TreesMu_TTBar_RW.root");
	
	TH1D * ttMtop = (TH1D*)tt->Get("MtopOutWindowTrue_allW/MtopOutWindowTrue_allWcosTheta");
	
	TH2D * ttMtop2D = (TH2D*)tt->Get("MtopOutWindowTrue_allW/MtopOutWindowTrue_allWcosTheta2D");
	
  std::pair<TF1, WeightFunctionCreator*> WeightFuncUD(WeightFunctionCreator::getWeightFunction("WeightFuncUDF", F0, FL));
  std::pair<TF1, WeightFunctionCreator*> WeightFuncDU(WeightFunctionCreator::getWeightFunction("WeightFuncDUF", F0, FL));
  cout<<F0 + F0Sys<<"\t"<<FL - FLSys<<endl;
	WeightFuncUD.first.SetParameters(F0 + F0Sys, FL - FLSys);
	WeightFuncDU.first.SetParameters(F0 - F0Sys, FL + FLSys);
	
	TH1D * ttUD = myReweightor(ttMtop2D,WeightFuncUD,"WeightFuncUD_");
	cout<<"ratio: "<<ttMtop2D->Integral()/ttUD->Integral()<<endl;
	ttUD->Scale(ttMtop2D->Integral()/ttUD->Integral());
	ttUD->Add(ttMtop);
	TH1D * wUD = (TH1D*)ttUD->Clone("wUD");
	wUD->Scale(-1.);
	wUD->Add(dataMtop);
	
	TH1D * ttDU = myReweightor(ttMtop2D,WeightFuncDU,"WeightFuncDU_");
	cout<<"ratio: "<<ttMtop2D->Integral()/ttDU->Integral()<<endl;
	ttDU->Scale(ttMtop2D->Integral()/ttDU->Integral());
	ttDU->Add(ttMtop);
	TH1D * wDU = (TH1D*)ttDU->Clone("wDU");
	wDU->Scale(-1.);
	wDU->Add(dataMtop);
	
	TFile * out = new TFile("file.root","recreate");
	out->cd();
	WeightFuncUD.first.Write();
	WeightFuncDU.first.Write();
	ttUD->Write();
	ttDU->Write();	
	wUD->Write();
	wDU->Write();	
	out->Close();
	return 1;
}
Ejemplo n.º 15
0
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;
}
Ejemplo n.º 16
0
void fixLeptonBJet(char* filename)
{
    TH1D *lb;
    TFile f(filename, "UPDATE");
    f.GetObject("HypLeptonBAjetMass", lb);
    if (lb) {
        cout << "HypLeptonBAjetMass found, saving as HypLeptonBjetMass\n";
        lb->SetName("HypLeptonBjetMass");
        lb->Write();
    }
    f.Close();
}
Ejemplo n.º 17
0
void changeThis(TString s, TString name){
TFile * fOld = TFile::Open(s,"UPDATE");
TH1D * h = (TH1D*)((TH1D*)fOld->Get(name+"/"+name+"cosTheta"))->Clone("Default_allWcosTheta");


fOld->mkdir("Default_allW")->cd();
h->Write();
fOld->cd();
fOld->Close();


} //10976.661 //18068.028
Ejemplo n.º 18
0
void run() {
    // gROOT->ProcessLine(".L /Users/jdolen/Dropbox/Code/MyAnalysisRootFunctions_NEW.C");
    // gROOT->ProcessLine(".L /Users/jdolen/Dropbox/Code/JMAR/TopTagging/MyFunctions_TopTag.C");

    TFile *out = new TFile("ModMass_2015_09_22.root","RECREATE");

    // TFile *F_qcdpt170   = new TFile("ntuples/ntuple_QCD_Pt_170to300_RunIISpring15DR74-Asympt50ns_2015_09_22.root");
    TFile *F_qcdpt300   = new TFile("ntuples/ntuple_QCD_Pt_300to470_RunIISpring15DR74-Asympt50ns_2015_09_22c.root");
    TFile *F_qcdpt470   = new TFile("ntuples/ntuple_QCD_Pt_470to600_RunIISpring15DR74-Asympt50ns_2015_09_22.root");
    TFile *F_qcdpt600   = new TFile("ntuples/ntuple_QCD_Pt_600to800_RunIISpring15DR74-Asympt50ns_2015_09_22c.root");
    TFile *F_qcdpt800   = new TFile("ntuples/ntuple_QCD_Pt_800to1000_RunIISpring15DR74-Asympt50ns_2015_09_22b.root");
    TFile *F_qcdpt1000  = new TFile("ntuples/ntuple_QCD_Pt_1000to1400_RunIISpring15DR74-Asympt50ns_2015_09_22.root");
    TFile *F_qcdpt1400  = new TFile("ntuples/ntuple_QCD_Pt_1400to1800_RunIISpring15DR74-Asympt50ns_2015_09_22.root");
    TFile *F_qcdpt1800  = new TFile("ntuples/ntuple_QCD_Pt_1800to2400_RunIISpring15DR74-Asympt50ns_2015_09_22.root");
    TFile *F_qcdpt2400  = new TFile("ntuples/ntuple_QCD_Pt_2400to3200_RunIISpring15DR74-Asympt50ns_2015_09_22.root");
    TFile *F_qcdpt3200  = new TFile("ntuples/ntuple_QCD_Pt_3200toInf_RunIISpring15DR74-Asympt50ns_2015_09_22.root");


    std::vector <TFile* > rootFiles;
    // rootFiles.push_back( F_qcdpt170  );
    // rootFiles.push_back( F_qcdpt300  );
    rootFiles.push_back( F_qcdpt470  );
    rootFiles.push_back( F_qcdpt600  );
    rootFiles.push_back( F_qcdpt800  );
    rootFiles.push_back( F_qcdpt1000 );
    rootFiles.push_back( F_qcdpt1400 );
    rootFiles.push_back( F_qcdpt1800 );
    rootFiles.push_back( F_qcdpt2400 );
    rootFiles.push_back( F_qcdpt3200 );

    // for (unsigned int i=0; i<rootFiles.size(); i++){
    //   TH1D * h1 = (TH1D*)  rootFiles[i] -> Get( "h_mAK8_ModMass" );
    //   cout<<h1->Integral()<<endl;
    // }

    vector <string> histnames;
    histnames.push_back("h_mAK8_ModMass");
    histnames.push_back("h_mSDropAK8_ModMass");
    histnames.push_back("h_mAK8_ModMass_jet0");
    histnames.push_back("h_mSDropAK8_ModMass_jet0");
    histnames.push_back("h_mAK8_ModMass_jet1");
    histnames.push_back("h_mSDropAK8_ModMass_jet1");

    out->cd();
    for (unsigned int i=0; i<histnames.size(); i++) {
        TH1D  * hist = scaleHistsFromPtHatRootFilesReturnHist( histnames[i].c_str(), rootFiles) ;
        hist->SetName(histnames[i].c_str());
        hist->Write();
    }
    out->Write();
    out->Close();
}
Ejemplo n.º 19
0
void saveHist3pMinpt()
{
    real isMC=MC;
    TFile* infMCData = new TFile(infnameData3p[isMC].Data());
    TFile* infMCMC = new TFile(infnameMC3p[isMC].Data());
    TTree* ntMCData = (TTree*)infMCData->Get("ntDD0kpipi");
    TTree* ntMCMC = (TTree*)infMCMC->Get("ntDD0kpipi");

    ntMCData->AddFriend("ntHlt");
    if(isMC!=Data_MB||isMC!=Data) ntMCData->AddFriend("ntHi");
    ntMCMC->AddFriend("ntHlt");
    ntMCMC->AddFriend("ntHi");

    cout<<"  -- Filling histograms - MC"<<endl;
    cout<<"     "<<infnameData3p[isMC]<<endl;
    cout<<"     "<<infnameMC3p[isMC]<<endl;

    for(int i=0; i<nBins; i++)
    {
        cout<<setiosflags(ios::left)<<"   - Processing ptbin "<<setw(3)<<ptBins[i]<<endl;
        TH1D* h = new TH1D("h","",BINNUM,BINMIN,BINMAX);
        TH1D* hMCSignal = new TH1D("hMCSignal","",BINNUM,BINMIN,BINMAX);
        TH1D* hMCSwapped = new TH1D("hMCSwapped","",BINNUM,BINMIN,BINMAX);
        ntMCData->Project("h","Dmass-DtktkResmass",Form("%s*(%s&&%s&&Dpt>%f)",weightdata[isMC].Data(),seldata3p[isMC].Data(),triggerselectiondata[isMC].Data(),ptBins[i]));
        ntMCMC->Project("hMCSignal","Dmass-DtktkResmass",Form("%s*(%s&&%s&&Dpt>%f)",weightmc[isMC].Data(),selmc3p[isMC].Data(),triggerselectionmc[isMC].Data(),ptBins[i]));
        ntMCMC->Project("hMCSwapped","Dmass-DtktkResmass",Form("%s*(%s&&%s&&Dpt>%f)",weightmc[isMC].Data(),selswp3p[isMC].Data(),triggerselectionmc[isMC].Data(),ptBins[i]));
        TFile* outf = new TFile(Form("inputfiles/fmass_pp_3p_%s_%.0f.root",texData[isMC].Data(),ptBins[i]),"recreate");
        outf->cd();
        h->Write();
        hMCSignal->Write();
        hMCSwapped->Write();
        outf->Close();
        delete hMCSwapped;
        delete hMCSignal;
        delete h;
        delete outf;
    }
    cout<<endl;
}
Ejemplo n.º 20
0
void hist_class::Write()
{
  TString dataType;
  TString out_name;
  dataType = "MC";
  out_name=Form("%s%s%s_useskimSelfmatch.root",dataType.Data(),coll.Data(),algo.Data());

  TFile *out_file = new TFile(Form("/cms/store/user/qixu/jetRpA/RpA/NewMC/%s",out_name.Data()),"RECREATE");  
    jetpt->Write();
    jetpt_fake->Write();
    jetpt_real->Write();
    jetpt_selfmatch_fake->Write();
    jetpt_selfmatch_real->Write();
    jetpt_selfmatch1_fake->Write();
    jetpt_selfmatch1_real->Write();
    hNmatched->Write();
    hNmatched1->Write();
    hdeltaR->Write();
    hptdeltaptfrc->Write();
    hptdeltaptfrcmatch1->Write();
    hptdeltaptfrcmatch20->Write();
    hptdeltaptfrcmatch21->Write();
    hptgenpt->Write();
    hptgenptmatch1->Write();
    hptgenptmatch20->Write();
    hptgenptmatch21->Write();
    hdeltaRdeltaptfrcmatch1->Write();
    hdeltaRdeltaptfrcmatch20->Write();
    hdeltaRdeltaptfrcmatch21->Write();
    for(int ieta=0; ieta<netabin; ieta++){
	 jetptEtaBin[ieta]->Write(); 
         jetptEtaBin_fake[ieta]->Write();
         jetptEtaBin_real[ieta]->Write();
         jetptEtaBin_selfmatch_fake[ieta]->Write();
         jetptEtaBin_selfmatch1_fake[ieta]->Write();
 	 }
  out_file->Close();
  cout<<"Output file: "<<Form("%s",out_name.Data())<<endl;
}
Ejemplo n.º 21
0
void testCentralityFWLite(){

   TFile * centFile = new TFile("../data/CentralityTables.root");
   TFile* infile = new TFile("/net/hisrv0001/home/yetkin/pstore02/ana/Hydjet_MinBias_d20100222/DEF33D38-12E8-DE11-BA8F-0019B9CACF1A.root");
  fwlite::Event event(infile);
  TFile* outFile = new TFile("test.root","recreate");

  TH1D::SetDefaultSumw2();
  TH2D* hNpart = new TH2D("hNpart",";Npart Truth;Npart RECO",50,0,500,50,0,500);
  TH1D* hBins = new TH1D("hBins",";bins;events",44,-1,21);

  CentralityBins::RunMap HFhitBinMap = getCentralityFromFile(centFile,"makeCentralityTableTFile", "HFhitsAMPT_2760GeV", 149500, 155000);

  // loop the events
  unsigned int iEvent=0;
  for(event.toBegin(); !event.atEnd(); ++event, ++iEvent){
     edm::EventBase const & ev = event;
    if( iEvent % 10 == 0 ) cout<<"Processing event : "<<iEvent<<endl;
    edm::Handle<edm::GenHIEvent> mc;
    ev.getByLabel(edm::InputTag("heavyIon"),mc);
    edm::Handle<reco::Centrality> cent;
    ev.getByLabel(edm::InputTag("hiCentrality"),cent);

    double b = mc->b();
    double npart = mc->Npart();
    double ncoll = mc->Ncoll();
    double nhard = mc->Nhard();

    double hf = cent->EtHFhitSum();
    double hftp = cent->EtHFtowerSumPlus();
    double hftm = cent->EtHFtowerSumMinus();
    double eb = cent->EtEBSum();
    double eep = cent->EtEESumPlus();
    double eem = cent->EtEESumMinus();

    int run = ev.id().run();

    int bin = HFhitBinMap[run]->getBin(hf);
    hBins->Fill(bin);

    double npartMean = HFhitBinMap[run]->NpartMean(hf);
    double npartSigma = HFhitBinMap[run]->NpartSigma(hf);
    hNpart->Fill(npart,npartMean);
  }

  outFile->cd();
  hBins->Write();
  hNpart->Write();
  outFile->Write();
  
}
Ejemplo n.º 22
0
void SaveClosure(TH1D* prediction, TH1D* expectation, TDirectory* Folder) // prediction durch expectation
{
  TH1D* Closure = (TH1D*) prediction->Clone();
  Closure->Divide(prediction,expectation,1,1,"B");
  TString title = prediction->GetTitle();
  title +="_closure";
  // 	title = "#mu & e Control-Sample Ratio in Search Bins; Search bins; #mu / e CS";
  Closure->SetTitle(title);
  title = prediction->GetName();
  title+="_closure";
  Closure->SetName(title);
  Folder->cd();
  Closure->Write();
}
Ejemplo n.º 23
0
void fitpapvar(const char* infilename, const char* histname) {
  TFile* infile = new TFile(Form("%s",infilename),"read");
  TH1D* hcf = (TH1D*)infile->Get(histname);
  hcf->GetXaxis()->SetRangeUser(0,2);

   TF1 *fc2 = new TF1("fc2","[3]+[2]*TMath::Gaus(x,[0],[1])",0.4,1);
   fc2->SetParameters(1.5,0.3,-0.2,1);

  // TF1 *fc2 = new TF1("fc2","[1]+[0]*x*x",0,1);
  // fc2->SetParameters(-0.01,1.0);

  // TF1 *fc2 = new TF1("fc2","[2]+[1]*x*x*x*x*x",0,1);
  // fc2->SetParameters(-0.01,0.01,1.0);

  // TF1 *fc2 = new TF1("fc2","[3]+[2]*x*x+[1]*x*x*x+[0]*x*x*x*x",0.,1);
  // fc2->SetParameters(-0.01,0.01,1.0,1.0);

  hcf->Fit("fc2","r","",0.3,1);
  TH1D* hnew = new TH1D("hnew","hnew",hcf->GetNbinsX(),0,1);
  for(int i=1;i<=hcf->GetNbinsX();++i){
    // cout << i << endl;
    // cout << hcf->GetBinContent(i)/fc2->Eval(2.*i/hcf->GetNbinsX()) << endl;
    // cout << hcf->GetBinContent(i) << endl;
    // cout << fc2->Eval(2.*i/hcf->GetNbinsX()) << endl << endl;
    hnew->SetBinContent(i, hcf->GetBinContent(i)/fc2->Eval(1.*i/hcf->GetNbinsX()));
    hnew->SetBinError(i, hcf->GetBinError(i));

  }
  hnew->Draw("same");
  fc2->Draw("same");
  hnew->SetName(Form("divp4%s",histname));
  TFile* ofile = new TFile(Form("divp4%s",infilename),"update");
  hnew->Write();
  hcf->Write();
  ofile->Close();
}
Ejemplo n.º 24
0
void CompareCFLADiffCuts()
{
  TFile newFile("~/Analysis/lambda/AliAnalysisLambda/Results/2016-01/15-NoOppChargeCut/All/CFs.root");
  TDirectory *newDir = newFile.GetDirectory("Merged");
  vector<TH1D*> newCFs;
  newCFs.push_back((TH1D*)newDir->Get("CFLamALam010"));
  newCFs.push_back((TH1D*)newDir->Get("CFLamALam1030"));
  newCFs.push_back((TH1D*)newDir->Get("CFLamALam3050"));

  TFile oldFile("~/Analysis/lambda/AliAnalysisLambda/Results/2016-01/08-NewAvgSepCuts/All/CFs.root");
  TDirectory *oldDir = oldFile.GetDirectory("Merged");
  vector<TH1D*> oldCFs;
  oldCFs.push_back((TH1D*)oldDir->Get("CFLamALam010"));
  oldCFs.push_back((TH1D*)oldDir->Get("CFLamALam1030"));
  oldCFs.push_back((TH1D*)oldDir->Get("CFLamALam3050"));

  TFile *compareFile = new TFile("Compare.root","update");
  TDirectory *dir = compareFile->GetDirectory("Delta");
  if(!dir) dir = compareFile->mkdir("Delta");
  for(UInt_t i = 0; i < newCFs.size(); i++) {
    // TH1D *ratio = (TH1D*)newCFs[i]->Clone();
    // TString name = ratio->GetName();
    // ratio->SetName(name + "Ratio");
    // ratio->SetTitle(name + "Ratio");
    // ratio->Divide(oldCFs[i]);

    // TH1D *barlowRatio = ComputeRogerBarlowRatio(newCFs[i], oldCFs[i]);
    // barlowRatio->SetName(name + "BarlowRatio");
    // barlowRatio->SetTitle(name + "BarlowRatio");

    TString name = newCFs[i]->GetName();
    TH1D *barlowDifference = ComputeRogerBarlowDifference(newCFs[i], oldCFs[i]);
    barlowDifference->SetName(name + "BarlowDifference");
    barlowDifference->SetTitle(name + "BarlowDifference");
    
    dir->cd();
    // ratio->Write();
    // barlowRatio->Write();
    barlowDifference->Write(barlowDifference->GetName(), TObject::kOverwrite);
    Chi2TestWithZero(barlowDifference);
    FitWithConstant(barlowDifference, compareFile);
    // LookAtMean(barlowDifference);
    RebinHist(barlowDifference, compareFile);
    ManuallyRebin(barlowDifference, compareFile);
  }
    
  compareFile->Close();
}
Ejemplo n.º 25
0
/**
 * The main function.
 */
int main(int argc, char **argv){

  std::cout << "  ComPWA Copyright (C) 2013  Mathias Michel " << std::endl;
  std::cout << "  This program comes with ABSOLUTELY NO WARRANTY; for details see license.txt" << std::endl;
  std::cout << std::endl;

    cout << "DataIF Root 2Particles started " << endl << endl;

    string file = "test/2Part-4vecs.root";
    RootReader myReader(file,"data");
    unsigned int maxEvents = myReader.getNEvents();
    double masssq;
    TH1D* bw = new TH1D("bw","inv. mass of 2 particles",1000,0.,2.4);
    bw->GetXaxis()->SetTitle("m_{12} / GeV");
    bw->GetXaxis()->CenterTitle();
    bw->GetYaxis()->SetTitle("#");
    bw->GetYaxis()->CenterTitle();
    TH1D* bw2 = new TH1D("bw2","inv. mass-sq of 2 particles",1000,0.,4.);
    bw2->GetXaxis()->SetTitle("m_{12}^{2} / GeV^{2}");
    bw2->GetXaxis()->CenterTitle();
    bw2->GetYaxis()->SetTitle("#");
    bw2->GetYaxis()->CenterTitle();

    for(unsigned int i = 0; i < maxEvents; i++){
        Event event(myReader.getEvent(i));
        const Particle &a(event.getParticle(0));
        const Particle &b(event.getParticle(1));

    	//myReader.getEvent(-1, a, b, masssq);
    	//if(!myReader.getEvent(i, event)) continue; TODO: try read exception
    	//if(!event) continue;
    	//cout << "Event: \t" << i << "\t NParticles: \t" << event.getNParticles() << endl;
    	masssq = pow(a.E+b.E,2) - pow(a.px+b.px ,2) - pow(a.py+b.py ,2) - pow(a.pz+b.pz ,2);

        bw->Fill(sqrt(masssq));
    	bw2->Fill(masssq);
    }

    TFile output("test/InputTest.root","RECREATE","ROOT_Tree");
    bw->Write();
    bw2->Write();
    output.Write();
    output.Close();

    cout << "DataIF Root 2Particles finished " <<endl;

  return 0;
}
Ejemplo n.º 26
0
void ManuallyRebin(TH1D* h1, TFile *out)
{
  cout<<"Taking weighted average"<<endl;
  Int_t nCombine = 40; // Merge 100 bins into 1

  Int_t totalBins = h1->GetNbinsX();
  Int_t finalBins = totalBins/nCombine;
  cout<<"Final N bins:\t"<<finalBins<<endl;
  TString newName = h1->GetName();
  newName += "WgtAvg";
  TH1D *newH = new TH1D(newName, newName, finalBins,
			h1->GetXaxis()->GetXmin(),
			h1->GetXaxis()->GetXmax());
  newH->SetLineColor(kGreen);

  for(Int_t iNewBin = 0; iNewBin < finalBins; iNewBin++)
  {
    Double_t weightedSum = 0.;
    Double_t weights = 0.;
    
    for(Int_t iOldBin = 1; iOldBin < nCombine+1; iOldBin++)
    {
      Int_t binNum = iNewBin * nCombine + iOldBin;
      Double_t errorSq = pow(h1->GetBinError(binNum), 2.);
      Double_t content = h1->GetBinContent(binNum);

      weights += 1./errorSq;
      weightedSum += (1./errorSq) * content;
    }

    Double_t avg = weightedSum/weights;
    Double_t newErr = 1./sqrt(weights);

    newH->SetBinContent(iNewBin + 1, avg);
    newH->SetBinError(iNewBin + 1, newErr);
  }

  TDirectory *dir = out->GetDirectory("WeightedAvg");
  if(!dir) {
    dir = out->mkdir("WeightedAvg");
  }
  dir->cd();
  newH->SetDirectory(0);
  newH->Write(newH->GetName(), TObject::kOverwrite);
  
  // dir->Close();
  
}
Ejemplo n.º 27
0
TFile *createRootFile(TString fileName,TString STlepCut,TString HTCut,TH1D *hIn,TString histoName)  {

  TH1::SetDefaultSumw2();

  TFile *fout = new TFile(fileName,"UPDATE");
  fout->mkdir("ANplots"+STlepCut+"_NOLPsecondD"+HTCut);
  fout->ls(); 
  fout->cd("ANplots"+STlepCut+"_NOLPsecondD"+HTCut);
  fout->pwd();

  TH1D *hOut = (TH1D*)hIn->Clone(histoName); hOut->SetName(histoName);
  hOut->Write(histoName);
  fout->Close();

  return fout;
}
Ejemplo n.º 28
0
makeMCPUdistr(){

TFile * myFile = new TFile("PU3DMC.root", "recreate");
myFile->cd();


TH1D *  histoMCPU = new TH1D("histoMCPU", "histoMCPU", 25, -0.5, 24.5 );

Double_t probdistFlat10[25] = {
    0.0698146584,
    0.0698146584,
    0.0698146584,
    0.0698146584,
    0.0698146584,
    0.0698146584,
    0.0698146584,
    0.0698146584,
    0.0698146584,
    0.0698146584,
    0.0698146584,
    0.0630151648,
    0.0526654164,
    0.0402754482,
    0.0292988928,
    0.0194384503,
    0.0122016783,
    0.007207042,
    0.004003637,
    0.0020278322,
    0.0010739954,
    0.0004595759,
    0.0002229748,
    0.0001028162,
    4.58337152809607E-05
  };
  
  for(unsigned int i=1; i<=25; i++){
  
  histoMCPU->SetBinContent(i,probdistFlat10[i-1] );
  
  
  }
  histoMCPU->Write();


}
Ejemplo n.º 29
0
void CheckInitialESpectrum(std::string filename) {

  TFile* file = new TFile(filename.c_str(), "READ");
  TTree* tree = (TTree*) file->Get("tree");
  TFile* out_file = new TFile("plots.root", "UPDATE");

  double bin_width = 250; //keV
  double x_low = 0;
  double x_high = 25000;
  int n_bins_x = (x_high - x_low) / bin_width;
  
  TH1D* hInitialESpectrum = new TH1D("hInitialESpectrum", "Initial Energy Spectrum Generated", n_bins_x,x_low,x_high);
  hInitialESpectrum->SetXTitle("Energy [keV]");
  tree->Draw("(sqrt(i_px*i_px*1e6 + i_py*i_py*1e6 + i_pz*i_pz*1e6 + 938272*938272) - 938272)>>hInitialESpectrum");
  hInitialESpectrum->Write();

  out_file->Close();
}
Ejemplo n.º 30
0
void Histograms::WriteResults()
{
    fOutFile2 = new TFile(fOutFileName.c_str(),"RECREATE");
    fOutFile2->cd();

    TH1D *gq = gluonQuark->ProjectionX("gluonvsquark","");
    gq->Write();
    
    for (unsigned int i = 0; i != fractionProfilesGluon.size(); ++i){
        fractionProfilesGluon[i]->Write();
        fractionProfilesQuark[i]->Write();
        fractionProfilesLQuark[i]->Write();
        fractionProfilesHQuark[i]->Write();
        fractionProfilesAll[i]->Write();
    }
    
    fOutFile2->Close();
}