コード例 #1
0
void testTThreadedObjectAutoMemManagement() {
   ROOT::EnableThreadSafety();
   const auto filename = "testTThreadedObjectAutoMemManagement.root";
   const auto nentries = 5000;
   {
      TFile f(filename,"RECREATE");
      ROOT::TThreadedObject<TH1F> h("h","h",64,-2,2);
      auto fillh = [&h](){
         h->FillRandom("gaus",nentries);
      };
      auto t1 = std::thread(fillh);
      auto t2 = std::thread(fillh);
      fillh();
      t1.join();
      t2.join();
      auto mh = h.Merge();
      mh->Write();
   }
   // Check content
   TFile f(filename);
   TH1F* h;
   f.GetObject("h",h);
   if (!h) {
      std::cerr << "Cannot find merged histo on disk!\n";
      return 1;
   }

   if (nentries*3 != h->GetEntries()) {
      std::cerr << "Wrong number of entries: " << h->GetEntries() << "!\n";
      return 1;
   }
   return 0;
}
コード例 #2
0
ファイル: ZAnalysis_2011.C プロジェクト: dfigueiredo/Torino
void CheckEHF()
{

 
  TH1F * HDat;
  TH1F * HDatnoPUAft;
  TH1F * HDatnoPUBef;

  //  TFile *fzee = new TFile("ZDiffOutputfile_73Weight2010.root");
  TFile *fzee = new TFile("ZDiffOutputfile_Data2011_noPU.root");
  // TFile *fzee = new TFile("ZDiffOutputfile.root");
  HDat  =  (TH1F*)fzee->Get("NVTX1_minEHFZoom_DATA10");
  HDatnoPUAft  =  (TH1F*)fzee->Get("NVTX1noPUAft_minEHFZoom_DATA10");
  HDatnoPUBef  =  (TH1F*)fzee->Get("NVTX1noPUBef_minEHFZoom_DATA10");

  HDat->Scale(1./HDat->GetEntries());
  HDatnoPUAft->Add(HDatnoPUBef);
  HDatnoPUAft->Scale(1./HDatnoPUAft->GetEntries());
  HDatnoPUBef->Scale(1./HDatnoPUBef->GetEntries());
  HDatnoPUAft->SetMinimum(0.);
  NHSetMarker(HDatnoPUAft,2,20,0.8);
  NHSetLine(HDatnoPUAft,2,1,1.);
  HDatnoPUAft->Draw("E1");
  HDatnoPUAft->SetTitle("2011 Z->ee Data, minHF Energy");
  NSetTitle(HDatnoPUAft,"HF Energy [GeV]", "Fraction");


  NHSetMarker(HDatnoPUBef,6,20,0.8);
  NHSetLine(HDatnoPUBef,6,1,1.);
  // HDatnoPUBef->Draw("SAMEP");

  NHSetMarker(HDat,4,20,0.8);
  NHSetLine(HDat,1,1,1.);
  HDat->Draw("SAMEP");

  TLegend *legend = new TLegend(0.6,0.1,0.75,0.4);
  legend->SetTextFont(72);
  legend->SetTextSize(0.04);
  legend->SetBorderSize(0);

  legend->AddEntry(HDatnoPUBef,"No PU before or after","p");
  //  legend->AddEntry(HDatnoPUBef,"No PU before","p");
  // legend->AddEntry(HDatnoPUAft,"No PU after","p");
  legend->AddEntry(HDat,"PU before && after","p");
  legend->Draw();






  //  NHSetLine(HDatnoPUBef,3,2,1.);
  // HDatnoPUBef->Draw("SAME HIST");

}
コード例 #3
0
ファイル: scale.C プロジェクト: hkaushalya/CDFPhoJets
//testing how the TH1::Integral() values change when a hist is scaled
void scale()
{
	gSystem->Load("../RootTools/CommonTools.C.so");
	gStyle->SetOptStat("nemouri");
	
	TH1F *h = new TH1F("H1","Test Integral",100,0,10);
	h->Fill (1);
	h->Fill (1);
	h->Fill (1);
	h->Fill (1);
	//TH1F *h2 = new TH1F("H2","Test Integral copy",100,0,1);
	//h->FillRandom("gaus",10000);
	//h2->FillRandom("gaus",10000);

//	std::cout << "nbins, Entries, Integral = " << h->GetNbinsX() << ", " 
//				<< h->GetEntries() << ", " << h->Integral("width") << std::endl;
	//h = (TH1F*) MakeVariableBinHist(h, 0, 0.2, 0.6, 0.8, 1, 0.1, 0.2, 0.2, 0.2);
	//std::cout << "nbins, Entries, Integral = " << h->GetNbinsX() << ", " 
	//			<< h->GetEntries() << ", " << h->Integral("width") << std::endl;

	new TCanvas();
	h->Draw();
	//new TCanvas();
	//h2->Draw();

	//h->Scale(1,"width"); //this replaces the loop below
	/*
	for (int bin = 1; bin <= h->GetNbinsX(); ++bin)
	{
		const double val = h->GetBinContent(bin);
		const double err = h->GetBinError(bin);
		const double width = h->GetBinWidth(bin);
		h->SetBinContent(bin,val/width);
		h->SetBinError(bin,err/width);
	}
	*/
	//h->DrawClone("E");
	h->Print();
	
	std::cout << "nbins, Entries, Integral = " << h->GetNbinsX() << ", " 
				<< h->GetEntries() << ", " << h->Integral("width") << std::endl;


	//h->Scale(10);
	h->Scale(10/(double)h->Integral());
	//h_copy->Scale(h2_copy->Integral()/(double) h2->Integral());
	//h_copy->Draw();

	std::cout << "after scaling to " << 10 << std::endl;
	h->Print();
	std::cout << "nbins, Entries, Integral = " << h->GetNbinsX() << ", " 
				<< h->GetEntries() << ", " << h->Integral("width") << std::endl;
	
};
コード例 #4
0
TGraph *draw_tof(TDirectory *d, const char *opt, Double_t *intg, Double_t *tof)
{
    static Int_t markercolor = 0;
    markercolor ++;

    TParameter<Double_t> *p_mpv_t       = (TParameter<Double_t>*)d->Get("p_mpv_t");
    TParameter<Double_t> *p_intg_t_axyt = (TParameter<Double_t>*)d->Get("p_intg_t_axyt");
    Double_t mpv_t       = p_mpv_t->GetVal();
    Double_t intg_t_axyt = p_intg_t_axyt->GetVal();
    *tof = mpv_t;
    *intg = intg_t_axyt;

    TH1F *htof = (TH1F*)d->Get("htof");
    Double_t err_t = TMath::Sqrt(htof->GetEntries());

    cout << "  T "
         << TString::Format("%10.2f", mpv_t) << " "
         << TString::Format("%10.2f", intg_t_axyt) << endl;

    gStyle->SetMarkerColor(markercolor);
    gStyle->SetLineColor(markercolor);
    gStyle->SetMarkerStyle(20);

    const Int_t n_t = 1;
    Double_t xt[] = { mpv_t };
    Double_t xte[] = { 0 };
    Double_t yte[] = { 0 };

    Double_t yt_axyt[] = { intg_t_axyt };
    TGraphErrors *gintg_t_axyt = new TGraphErrors(n_t, xt, yt_axyt, xte, yte);
    gintg_t_axyt->Draw(opt);

    return gintg_t_axyt;
}
コード例 #5
0
TGraph *draw_lambda(TDirectory *d, const char *opt = "", Double_t *intg, Double_t *lambda)
{
    static Int_t markercolor = 0;
    markercolor ++;

    // lambda
    TParameter<Double_t> *p_mpv_l       = (TParameter<Double_t>*)d->Get("p_mpv_l");
    TParameter<Double_t> *p_intg_l_axyt = (TParameter<Double_t>*)d->Get("p_intg_l_axyt");
    Double_t mpv_l       = p_mpv_l->GetVal();
    Double_t intg_l_axyt = p_intg_l_axyt->GetVal();
    *lambda = mpv_l;
    *intg = intg_l_axyt;

    TH1F *hlambda = (TH1F*)d->Get("hlambda");
    Double_t err_l = TMath::Sqrt(hlambda->GetEntries());

    cout << "  L "
         << TString::Format("%10.2f", mpv_l) << " "
         << TString::Format("%10.2f", intg_l_axyt) << endl;

    gStyle->SetMarkerColor(markercolor);
    gStyle->SetLineColor(markercolor);
    gStyle->SetMarkerStyle(20);

    const Int_t n_l = 1;
    Double_t xl[] = { mpv_l };
    Double_t xle[] = { 0 };
    Double_t yle[] = { 0 };

    Double_t yl_axyt[1] = { intg_l_axyt };
    TGraphErrors *gintg_l_axyt = new TGraphErrors(n_l, xl, yl_axyt, xle, yle);
    gintg_l_axyt->Draw(opt);

    return gintg_l_axyt;
}
コード例 #6
0
 void norm (double total = 0)
   {
     double factor = m_XS / m_h_MWW->GetEntries () ;
     if (total != 0) factor = m_XS / total ;
     m_h_MWW->Scale (factor) ;
     m_h_scale->Scale (factor) ;
   }
コード例 #7
0
ファイル: plot.cpp プロジェクト: rmurrells/VertexBuilderTest
  TH1F * getpdgs(std::string const & dr, std::string const & we) {
    
    TCanvas * canvas_temp = new TCanvas("temp");
    tree->Draw((dr+">>h").c_str(), we.c_str());
    TH1F * hist = (TH1F*)gDirectory->Get("h");
    int const min = hist->GetBinLowEdge(hist->FindFirstBinAbove(0));
    int const max = hist->GetBinLowEdge(hist->FindLastBinAbove(0)) +
      hist->GetBinWidth(hist->FindLastBinAbove(0)) + 1;
    int const binno = max - min;
    delete canvas_temp;
    delete hist;

    canvas_temp = new TCanvas("temp");
    tree->Draw(Form((dr+">>h(%d,%d,%d)").c_str(), binno, min, max), we.c_str());
    ofile->cd();
    delete canvas_temp; 
    TH1F * histb = (TH1F*)gDirectory->Get("h");

    if(histb->GetEntries() == 0) {
      delete histb;
      return nullptr;
    }    

    return histb;
    
  }
コード例 #8
0
ファイル: bkg_bias_fun.C プロジェクト: CMSROMA/BiasStudy
TGraphAsymmErrors *MakeGraph(TTree *tree, std::vector<int> mass_vec, TString genFun, TString fitFun, TString varName, TString option="mean"){

  //  TMultiGraph *graph = new TMultiGraph();
  TGraphAsymmErrors *graph = new TGraphAsymmErrors();

//   TCanvas c_graph("c_graph","c_graph");
//   c_graph.cd();

  for(std::vector<int>::const_iterator mass_itr=mass_vec.begin();
      mass_itr!=mass_vec.end();
      mass_itr++){

    //    std::cout << *mass_itr << std::endl;
    TString mass_string;
    mass_string+=(*mass_itr);
    //	mass_string.Print();
    TCut mass_cut("mass == "+mass_string);
    //	mass_cut.Print();
    TCut cut=mass_cut;
    cut+="genFun==\""+genFun+"\"";
    cut+="fitFun==\""+fitFun+"\"";
#ifdef REMOVEBADFIT
    cut+="mu>-15 && mu<15";
#endif
#ifdef REMOBELOWSIGMA
    cut+="sigma_mu>1e-2";
#endif
    cut.Print();


    if(varName.CompareTo("mu")==0) tree->Draw(varName+">>hist(600,-15,15)",cut);
    if(varName.CompareTo("bkgSig1fwhm/bkgTrue1fwhm")==0) tree->Draw(varName+">>hist(300,-5,5)",cut);
    if(varName.CompareTo("bkgErrSig1fwhm/bkgTrue1fwhm")==0) tree->Draw(varName+">>hist(400,0.,2.)",cut);
    if(varName.CompareTo("(bkgSig1fwhm-bkgTrue1fwhm)/bkgErrSig1fwhm")==0) tree->Draw(varName+">>hist(400,-3,3.)",cut);
    if(varName.CompareTo("(bkgSig2fwhm-bkgTrue2fwhm)/bkgErrSig2fwhm")==0) tree->Draw(varName+">>hist(400,-3,3.)",cut);
    if(varName.CompareTo("sigma_mu")==0) tree->Draw(varName+">>hist(400,0,20)",cut);
    if(varName.CompareTo("(mu-muTruth)/sigma_mu")==0) tree->Draw(varName+">>hist(300,-3,3)",cut);
    if(varName.CompareTo("(mu-muTruth)/bkgErrNormSig2fwhm")==0) tree->Draw(varName+">>hist(400,-8,8)",cut);
    if(varName.CompareTo("bkgErrNormSig2fwhm")==0) tree->Draw(varName+">>hist(200,0.,10.)",cut);

    
    TH1F *hist = (TH1F *) gROOT->FindObject("hist");
   
    if(hist==NULL || hist->GetEntries()==0){
      std::cerr << "no entries for cut: " << std::endl;
      cut.Print();
    } else     AddPoint(graph, *mass_itr, hist, genFun, fitFun, option);
    //    graph->SetMinimum(-100);
    //    graph->SetMaximum(100);

    delete hist;
  }
  
  
//       std::cout << "Np = " << i_point << std::endl;
//       }
//       c.cd();

  return graph;
}
コード例 #9
0
ファイル: plotEvtSelEff.C プロジェクト: CmsHI/CVS_edwenger
void plotEvtSelEff() {

  gStyle->SetOptStat(0);

  TFile *f = new TFile("../test/ROOTupleMC_HighPurity.root");
  TH1F *hNSD = (TH1F*) f->Get("preTrgAna/hGenMultNSD");
  TH1F *hNSDtrg = (TH1F*) f->Get("postTrgAna/hGenMultNSD");
  TH1F *hNSDevt = (TH1F*) f->Get("postEvtSelAna/hGenMultNSD");
  TH1F *hNSDvtx = (TH1F*) f->Get("postVtxAna/hGenMultNSD");
  TH1F *hNSDtrkvtx = (TH1F*) f->Get("postTrkVtxAna/hGenMultNSD");

  TGraphAsymmErrors *gNSDtrg = new TGraphAsymmErrors();
  TGraphAsymmErrors *gNSDevt = new TGraphAsymmErrors();
  TGraphAsymmErrors *gNSDvtx = new TGraphAsymmErrors();
  TGraphAsymmErrors *gNSDtrkvtx = new TGraphAsymmErrors();

  gNSDtrg->BayesDivide(hNSDtrg,hNSD);
  gNSDevt->BayesDivide(hNSDevt,hNSD);
  gNSDvtx->BayesDivide(hNSDvtx,hNSD);
  gNSDtrkvtx->BayesDivide(hNSDtrkvtx,hNSD);

  TH1F *dum1 = new TH1F("dum1",";Charged-particle multiplicity;Fraction of events",100,0,100);
  dum1->SetMaximum(0.05);
  dum1->GetYaxis()->SetTitleOffset(1.8);
  TH1F *dum2 = new TH1F("dum2",";Charged-particle multiplicity;Selection efficiency",100,0,60);

  TCanvas *c1 = new TCanvas("c1","Event Selection",900,500);
  c1->Divide(2,1);

  c1->cd(1);
  dum1->Draw();
  hNSDtrkvtx->Sumw2();
  hNSDtrkvtx->Scale(1./hNSDtrkvtx->GetEntries());
  hNSDtrkvtx->SetMarkerStyle(24);
  hNSDtrkvtx->Draw("pzsame");
  hNSDvtx->Sumw2();
  hNSDvtx->Scale(1./hNSDvtx->GetEntries());
  hNSDvtx->SetMarkerStyle(20);
  hNSDvtx->Draw("pzsame");

  c1->cd(2);
  dum2->Draw();
  gNSDtrkvtx->SetMarkerStyle(24);
  gNSDtrkvtx->Draw("pzsame");
  gNSDvtx->SetMarkerStyle(20);
  gNSDvtx->Draw("pzsame");
}
コード例 #10
0
std::vector<GaussFitInfo> saveGaussians(TH2F* hp, TList* l, TString savedir)
{
  // Each xbin of the TH2F can be viewed as a 1D histogram of the y info.
  // Fit the histograms in each xbin with a gaussian and save them into a tlist. 
  // Save the histograms as png files as well.

  // Get the title info from the mother histogram.
  TString title = hp->GetTitle();

  // This is only used to align the statboxes.
  DiMuPlottingSystem* dps = new DiMuPlottingSystem();

  // Do the fitting and gather the histos into the tlist.
  std::vector<GaussFitInfo> gfis = std::vector<GaussFitInfo>();
  gfis = dps->plotVarVsGaussFit(hp, l, 1);

  TCanvas* c = new TCanvas();
  c->SetGridx(kTRUE);
  c->SetGridy(kTRUE);

  // Iterate through the list and save the histos as pictures. 
  TIter next(l);
  TObject* obj = 0;
  int i = 0;
  int total = 0;
  while( (obj = next()) )
    {
      TH1F* h = (TH1F*) obj;
      h->SetName(Form("%s_%d_%s", title.Data(), i, hp->GetName()));
      c->cd();
      h->Draw("");
      total+=h->GetEntries();
      std::cout << "    " << i << " num: "<< h->GetEntries() << std::endl;
      dps->arrangeStatBox(c);
      c->Print(savedir+Form("%s_%s_gauss_bins_%d.png", hp->GetName(), title.Data(), i));
      //        c->Print(savedir+Form("%s_%s_gauss_bins.gif+500", hp->GetName(), title.Data()));
      i++;
    }
  c->cd();
  //    c->Print(savedir+Form("%s_%s_gauss_bins.gif++", hp->GetName(), title.Data()));
  std::cout << "nentries total: " << total << std::endl;

  delete c;
  //    delete dps;
  return gfis;
}
コード例 #11
0
bool check_complete(TString fn="output_ana.root", TString fn2="ana_target.root", double minP = 0.03, int minev = 3, int maxfail=3)
{
	bool fTest=kFALSE;
        TString templateFile = gSystem->Getenv("VMCWORKDIR");
        templateFile += "/macro/run/";
        templateFile += fn2;
	
	TFile *f=new TFile(fn,"READ");
	if (!f->IsZombie())
	{
		TFile *f2=new TFile(templateFile,"READ");
			
		TKey *key;
		TIter next(f->GetListOfKeys());
		
		int failcount = 0;
		
		while ( (key = (TKey*)next()) )
		{
			TObject *obj = key->ReadObj();
			
			// only check TH1Fs
			if (!obj->InheritsFrom("TH1F")) continue;
			
			TString name = obj->GetName();
			TH1F* h  = (TH1F*) obj; 
			TH1F* h2 = (TH1F*) f2->Get(name);
			
			if ( h->GetEntries()<minev ) 
			{
				cout << "Histogram (almost) empty : " << name << " \"" << h2->GetTitle() << "\":  N = " <<  h->GetEntries() << endl;
				failcount++;
			}
			else  
			{
				double P = h2->KolmogorovTest(h);
				if ( P<minP )
				{
					cout << "Incompatible distribution: " << name << " \"" << h2->GetTitle() << "\":  P = " << P << endl;
					failcount++;
				}
			}
		
		}
		
		if (failcount<maxfail) fTest = kTRUE;
	}
	
	if (fTest){
		cout << " Test passed" << endl;
		cout << " All ok " << endl;  
	}else{
		cout << " Test Failed" << endl;
		cout << " Not Ok " << endl;         
	}
    
    exit(fTest);
}
コード例 #12
0
ファイル: qualityStudies.C プロジェクト: Andrej-CMS/cmssw
TH1F * getTH1Histo(TChain *Events, const char * name,  const string varToPlot,  unsigned int nBins, double fMin, double fMax, TCut cut) {

  TH1F * h = new TH1F(name, name, nBins, fMin, fMax);
  //  Events->Draw("zGoldenMass");
  Events->Project(name, varToPlot.c_str(), cut );
  cout<<"Number of entrie for "<< name << " : "<< h->GetEntries()<<endl;
  setGraphics(h);
  return h;
}
コード例 #13
0
ファイル: DisplayEvent.C プロジェクト: jixie/KalRTPC
int GetEntries(const char *var,TCut cut)
{
  TTree *t=(TTree*) gROOT->FindObject("t");

  TH1F *htemp = (TH1F*) gROOT->FindObject("htemp");
  if(htemp) delete htemp;
  t->Draw(Form("%s>>htemp",var),cut);
  htemp = (TH1F*) gROOT->FindObject("htemp");
  //cout<<"Number of entries = "<<htemp->GetEntries()<<endl;
  return htemp->GetEntries();
}
コード例 #14
0
ファイル: make_hist.C プロジェクト: chernyavskaya/Hbb
void make_hist(TString type, TString physics_type, TString sample_str){
	
	const int num_samples = 12;
	int sample = atoi(sample_str);
	
	TFile *file = new TFile("../application/v13/main_tmva_v13_Data_4_"+physics_type+type+".root");
   TTree *tree = (TTree*)file->Get("tree");
	Int_t events_generated;
	TH1F *countPos;
	TH1F *countNeg;
	if (sample!=11){
		countPos = (TH1F*)file->Get("CountPosWeight");
 		countNeg = (TH1F*)file->Get("CountNegWeight");
 		events_generated = countPos->GetEntries()-countNeg->GetEntries();
	} else events_generated = 1;

///	TString file_names[nfiles] = {"QCD_HT100to200", "QCD_HT200to300", "QCD_HT300to500","QCD_HT500to700", "QCD_HT700to1000", "QCD_HT1000to1500", "QCD_HT1500to2000", "QCD_HT2000toInf", "VBFHToBB_M-125_13TeV_powheg", "VBFHToBB_M-130_13TeV_powheg", "VBFHToBB_M125_13TeV_amcatnlo","data"};
	Float_t xsec[num_samples] = { 2.75E07,  1.74E06,  3.67E05, 2.94E04, 6.52E03,1.064E03,   121.5,  2.54E01,2.16 ,1.96,2.16,1./15.47};

	float lumi=10000; //in pb
	float BDT;
	float genweight=1.;

	tree->SetBranchAddress("BDT_VBF",&BDT);
	tree->SetBranchAddress("genWeight",&genweight);

	TH1F *BDT_output = new TH1F("BDT_output","",400,-1.,1.);
	
	int nentries = tree->GetEntries();
	for (int entry=0;entry<nentries;entry++){
		tree->GetEntry(entry);
		genweight=TMath::Sign(1.,genweight);
		genweight/=events_generated/(xsec[sample]*lumi); //10 fb^-1 normalization
		BDT_output->Fill(BDT,genweight);
	}

	TFile *f_output = new TFile("output_hist/v13/BDT_hist_"+physics_type+type+".root","recreate");
	f_output->cd();
   BDT_output->Write();
   f_output->Write();
}
コード例 #15
0
TH1F* scaled(const char *dirname, TString file, TString tag_one, TString h_entries, TString hist)
{
  TFile* f1  = new TFile(dirname+file+".root","READ");

  TH1F* h1 = (TH1F*)f1->Get(tag_one+"/"+tag_one+"_"+hist);
  TH1F* entries = (TH1F*)f1->Get(tag_one+"/"+tag_one+"_"+h_entries);

  //cout<<entries->GetEntries()<<endl;
  h1->Scale(1/entries->GetEntries());

  return h1;
}
コード例 #16
0
ファイル: AnalysisBase.C プロジェクト: yabezsh/Tb
void AnalysisBase::getBeamLoc(){

  TH1F* haStrip = new TH1F("haStrip","Strip # of cluster with track",512,0.0,512);
  //TH1F* hb = new TH1F("hb","Strip # of cluster with track",512,0.0,512);
  Long64_t nentries = fChain->GetEntriesFast();
  //cout << "nentries " << nentries << endl;
  float lo = 0, hi = 0;
  int istrip;

  Long64_t nbytes = 0, nb = 0;
  std::cout << "======================================= " << std::endl;
  std::cout << "getBeamLoc(): Determining Beam Position " << nentries << std::endl;
  std::cout << "======================================= " << std::endl;
  for (Long64_t jentry=0; jentry<max(50000,(int)nentries);jentry++) {
    Long64_t ientry = LoadTree(jentry);
    if (ientry < 0) break;
    nb = fChain->GetEntry(jentry);   nbytes += nb;
    //cout << clusterNumberPerEvent << endl;
    
    for(int j=0; j<min((int)clusterNumberPerEvent,10); j++){
      if(polarity*clustersCharge[j] < kClusterChargeMin) continue;
      int iChan = clustersSeedPosition[j];
      if(polarity*clustersCharge[j]<4*noise[iChan]) continue;
      istrip = clustersSeedPosition[j];
      if(badStrips[istrip]==0) continue; // exclude bad strips
      if(clustersPosition[j]>0.1&&clustersSize[j]==1) haStrip->Fill(clustersPosition[j]);
      if(clustersPosition[j]>0.1&&clustersSize[j]==2) haStrip->Fill(clustersPosition[j]);
    }
  }
     
  int num = haStrip->GetEntries();
  for(int i=0; i<1000; i++){
    //cout << "num is " << num << endl;
    if(num < 1000) continue;
    break;
  }

  if(num < 1000){
    std::cout << "ERROR: Something wrong here, insufficient entries in GetBeamLoc(), nEntries =  " << num << std::endl;
    //exit(1);
  }
   
  //haStrip->Draw();
  getBeamLocation(haStrip,lo,hi);
  iLo = lo;
  iHi = hi;
  std::cout << "====> Beam is between strips " << iLo << " -- " << iHi << std::endl;
  delete haStrip;

  return;

}
コード例 #17
0
ファイル: toyMC.C プロジェクト: CmsHI/CVS_MitHig
void test(int nhit1)
{
    TH1F *h = (TH1F*) f->FindObjectAny(Form("dNdEtaHits1_%02d",nhit1));
    TH1F *g = new TH1F("toymc","",100,-3,3);

    for (int i=0;i<h->GetEntries();i++){
       g->Fill(h->GetRandom());
    }
    
    g->SetLineColor(2);
    h->Draw();
    g->Draw("same");
}
コード例 #18
0
ファイル: NtupleSummary.C プロジェクト: Andrej-CMS/cmssw
void NtupleSummary(const char * file, const char * treepath = "l1UpgradeEmuTree/L1UpgradeTree"){
  cout << "INFO: summary of content in file " << file << "\n";
  TFile input(file);
  TTree * tree  = (TTree*) input.Get(treepath);
  if (! tree) {
    cout << "ERROR: could not open tree.\n";
    input.ls();
    return;
  }
  tree->Print();

  TH1F * fjetEt = new TH1F("fjetEt","", 20, 0.0, 200.0);
  tree->Draw("jetEt>>fjetEt","(jetEt > 10.0) && (abs(jetEta) > 3.0)");
  cout << "forward jet count:  " << fjetEt->GetEntries() << "\n";

  TH1F * jetEt = new TH1F("jetEt","", 20, 0.0, 200.0);
  tree->Draw("jetEt>>jetEt","jetEt > 10.0");
  cout << "jet count:  " << jetEt->GetEntries() << "\n";

  TH1F * egEt = new TH1F("egEt","", 20, 0.0, 200.0);
  tree->Draw("egEt>>egEt","egEt > 10.0");
  cout << "eg count:  " << egEt->GetEntries() << "\n";

  TH1F * tauEt = new TH1F("tauEt","", 20, 0.0, 200.0);
  tree->Draw("tauEt>>tauEt","tauEt > 10.0");
  cout << "tau count:  " << tauEt->GetEntries() << "\n";

  TH1F * muonEt = new TH1F("muonEt","", 20, 0.0, 200.0);
  tree->Draw("muonEt>>muonEt","muonEt > 1.0");
  cout << "muon count:  " << muonEt->GetEntries() << "\n";  

  




}
コード例 #19
0
/**
 * Returns the number of events in a file as defined by convention through the
 * content of the histogram "numberOfEvents".
 *
 * @param inputFilename
 *                      name of the input root file.
 * @return
 *                      the number of events in histogram "numberOfEvents"
 */
int
numberOfEvents(const TString& inputFilename)
{
// {{{
    TH1F *h = 0;
    LoadHistogramTH1F("numberOfEvents", inputFilename, 1.0, h);
    int nEvents = 1;
    if (h)
    {
        nEvents = h->GetEntries();
        delete h;
    }
    return nEvents;
// }}}
};
コード例 #20
0
ファイル: BackgroundFit.C プロジェクト: tj710/TTEmulator
void BackgroundFit() {
    TFile* inputFile = new TFile("0_MuScleFit.root", "READ");
    TH1F* histo = (TH1F*)inputFile->FindObjectAny("hRecBestRes_Mass");
    histo->Rebin(30);
    histo->Scale(1/histo->GetEntries());

    // TF1 * functionToFit = lorentzianFit();
    // TF1 * functionToFit = crystalBallFit();
    // TF1 * functionToFit = powerLawFit();
    // TF1 * functionToFit = lorentzianAndPowerLaw();
    // TF1 * functionToFit = exponentialFit();
    TF1 * functionToFit = lorenzianAndExponentialFit();

    histo->Fit(functionToFit, "M", "", 42, 160);

}
コード例 #21
0
ファイル: savedfrankTools.C プロジェクト: CmsHI/CVS_SavedFMa
//=============================== Main Functions =====================================
//--- function to draw histograms from TTree ---
void drawTree(TTree* nt, const char* draw, const char* cut, const char* opt, const char* name, const char* title, const int nbin, const float min, const float max, bool log=false, const int lc=0, const int ls=0, const int lw=0)
{
   //--- Print some info ---
   if (!TString(opt).Contains("same")) printf("\n");
   printf("%s, tree: %d. Draw: %s\n", name, nt, draw);
//   nt->Print();

   //--- Make/set histogram ---
   printf("hist: %s %d %f %f\n",name,nbin,min,max);
   TH1F * h = createHist(name, title, nbin, min, max);
   setHist(h,lc,ls,lw);

   //--- Draw ---
   TCanvas * c = makeCanvas(name,title,log,opt);
   nt->Draw(draw, cut, opt);
   printf("%s has: %f entries\n",name,h->GetEntries());
}
コード例 #22
0
void PlotAlignmentValidation::
plotDMRHistogram(PlotAlignmentValidation::DMRPlotInfo& plotinfo, int direction, int layer)
{
  TH1F* h = 0;
  std::string histoname;
  if (direction == -1) { histoname = "myhisto1"; }
  else if (direction == 1) { histoname = "myhisto2"; }
  else { histoname = "myhisto"; }
  std::string plotVariable = getVariableForDMRPlot(histoname, plotinfo.variable, plotinfo.nbins, plotinfo.min, plotinfo.max);
  std::string selection = getSelectionForDMRPlot(plotinfo.minHits, plotinfo.subDetId, direction, layer);
  plotinfo.vars->getTree()->Draw(plotVariable.c_str(), selection.c_str(), "goff");
  if (gDirectory) gDirectory->GetObject(histoname.c_str(), h);
  if (h && h->GetEntries() > 0) {
    if (direction == -1) { plotinfo.h1 = h; }
    else if (direction == 1) { plotinfo.h2 = h; }
    else { plotinfo.h = h; }
  }
}
コード例 #23
0
ファイル: Getvn.C プロジェクト: XuQiao/phenix
void FillGoodRun(int ihar){
    float pi = acos(-1.0);
    TString str;
    TFile *fin;
    int nrun = GetTotalRun();
    if(nrun<0) exit(1);
     for(int icent=0;icent<ncent;icent++){
 //     for(int ihar=0;ihar<nhar;ihar++){
 //         if(ihar!=1) continue;
       for(int isub=0;isub<nsub;isub++){
            str = choosesub(isub);
            if(str=="ABORT") continue;
            for(int irun=0;irun<nrun;irun++){
      //std::cout<<icent<<" "<<ihar<<" "<<isub<<" "<<irun<<std::endl;
        //fin = TFile::Open(Form("/phenix/plhf/xuq/taxi/%s%s/%d/data/%s.root",dataset.Data(),pro.Data(),taxi,GetRun(irun).Data()));
         fin = TFile::Open(Form("/gpfs/mnt/gpfs02/phenix/plhf/plhf1/xuq/phenix/flow/Run16dAu/work/62GeV/output/%s",GetRun(irun).Data()));
        TH1F* hpsi = new TH1F("psi","psi",100,-pi,pi);
        for(int ibbcz=0;ibbcz<nbbcz;ibbcz++){
          TH1F* hpsitemp = (TH1F*)fin->Get(Form("psiFla_0_0_%d_%d_%d_%d",icent,ibbcz,ihar,isub));
          hpsi->Add(hpsitemp);
        }
        TF1 *fun = new TF1("fun","pol0",-pi,pi);
      if(hpsi->GetEntries()>1000){
	//hpsi->SetMarkerStyle(20);
	//hpsi->SetMarkerSize(0.6);
	//hpsi->SetMarkerColor(4);
	hpsi->SetMinimum(10);
	hpsi->Fit("fun","QR0");
	//float par=fun->GetParameter(0);
	//hpsi->SetMaximum(1.5*par);
	//hpsi->Draw();
	GoodRunFit[icent][ihar][isub][irun] = fun->GetChisquare()/fun->GetNDF();
        fin->Close();
      }
      else{
        GoodRunFit[icent][ihar][isub][irun] = -9999;
        fin->Close();
     }
     // GoodRunFit[icent][ihar][isub][irun] = 1.;
    }
       }
   //   }
     }
}
コード例 #24
0
void efficiencies(){
  //TFile * f_ttbar= new TFile("ttbar-output-2014-06-22.root");
  TFile * f_ttbar= new TFile("/afs/cern.ch/work/m/mcitron/public/TTBAR/140622/ttbar_output.root");
  TFile * f_out= new TFile("./effTest.root","recreate");
  TTree * tree_ttbar = f_ttbar->Get("demo/L1Tree");
  std::vector<TString> jetnum;
  jetnum.push_back("0");
  jetnum.push_back("1");
  jetnum.push_back("2");
  jetnum.push_back("3");
  std::vector<TString> jetType;
  jetType.push_back("5400_calib_nopus");
  jetType.push_back("5450_calib_nopus");
  jetType.push_back("5450_calib_donut");
  jetType.push_back("5400_calib_donut");
  jetType.push_back("5400_calib_global");
  //jetType.push_back("calib_gct");
  TString bins = "(1000,0,1000)";
  for (iNum = jetnum.begin();iNum != jetnum.end(); iNum++)
  {
    TDirectory * jnum = f_out->mkdir("jetNumber_"+*iNum);
    jnum->cd();
    TCut genptcut = "jetPt_ak4_gen["+*iNum+"]>50";
    tree_ttbar->Draw("jetPt_ak4_gen["+*iNum+"]>>overall_"+*iNum,genptcut,"");
    TH1F *overall = (TH1F*)gPad->GetPrimitive("overall_"+*iNum);
    double overallNorm = overall->GetEntries();
    for (iType = jetType.begin();iType != jetType.end(); iType++)
    {

      TCut matchedcut = "jetMatchedPt_"+*iType+"["+*iNum+"]!=-1";


      tree_ttbar->Draw("jetPt_"+*iType+"["+*iNum+"]>>"+*iType+"_"+*iNum+bins,genptcut&&matchedcut,"");
      TH1F *test = (TH1F*)gPad->GetPrimitive(*iType+"_"+*iNum);
      test->Write();
      test->SetName(*iType+"_"+*iNum+"_"+"Efficiency");

      TH1F* cumuplot = makeCumu(test,overallNorm);
      cumuplot->Write();
    }
  }
  f_out->Close();
  return;
}
コード例 #25
0
ファイル: compareNtuples.C プロジェクト: cmstas/NtupleTools
void doSinglePlots(vector <std::string> branches, bool isNew, TTree* tree){

  TH1F* empty = new TH1F("","", 1, 0, 1);

  for (unsigned int i = 0; i < branches.size(); i++){  

    //isLorentz
    TBranch *branch = tree->GetBranch(tree->GetAlias(branches[i].c_str()));
    TString branchname(branch->GetName());
    bool isLorentz = branchname.Contains("p4") || branchname.Contains("MathLorentzVectors"); 

    //Draw
    string alias = branches.at(i);

    //Table of contents
    myfile << "\\subsection*{" << alias << "}\\addcontentsline{toc}{subsection}{" << alias << "}" << endl;

    tree->Draw(Form("%s%s>>hist", branches[i].c_str(), isLorentz ? ".Pt()" : ""), "", "", max_events); 
    TH1F *hist = (TH1F*)gDirectory->Get("hist");
    if(hist==NULL){
      cout << "********** Branch " << branches.at(i) << " exists, but is undrawable for some reason. Skipping this branch" << endl;
      continue; 
    }

    //Scale
    hist->Scale(1./hist->GetEntries());

    //Print plot, update ToC
    vector<TH1F*> hvec;
    hvec.push_back(hist);
    vector<string> titles;
    titles.push_back(isNew ? "New" : "Old");
    dataMCplotMaker(empty, hvec, titles, "", alias, Form("--isLinear --noDivisionLabel --xAxisOverride --outputName hists/uncommon%d", plotNum));
    myfile << "\\begin{figure}[H]" << endl
           << Form("\\includegraphics[width=0.6\\textwidth]{./hists/uncommon%d.pdf}", plotNum) << endl
           << "\\end{figure}" << endl;
    plotNum++;
    delete hist;
  }

  delete empty;
}
コード例 #26
0
ファイル: DataSet.cpp プロジェクト: aashaqshah/cmssw-1
void DataSet::LoadFile()
{
  TFile F(RootFilePath_);
  
  //  F.ls();
  TH1F *RefHistogram = (TH1F*) F.Get(ReferenceHistogramPath_);
  
  SetNumberOfGeneratedEvents( RefHistogram->GetEntries()) ;
  
  if(NumberOfGeneratedEvents())
    SetScaleFactor( Luminosity() * CrossSection() / NumberOfGeneratedEvents() );
  else
    std::cout << "ERROR :  No Events/Entries in Reference Histogram with name " << ReferenceHistogramPath_ << endl;


  SetNumberOfScaledEvents( NumberOfGeneratedEvents() * ScaleFactor() );
  F.Close();


}
コード例 #27
0
ファイル: testMergeCont.C プロジェクト: iahmad-khan/root
void testMergeCont()
{
   // Macro to test merging of containers.

   gROOT->LoadMacro("$ROOTSYS/tutorials/hsimple.C");
   TList *list = (TList *)GetCollection();
   TList *inputs = new TList();
   for (Int_t i=0; i<10; i++) {
      inputs->AddAt(GetCollection(),0);
      list->Merge(inputs);
      inputs->Delete();
      f->Close();
   }
   delete inputs;
   TH1F *hpx = (TH1F*)(((TList*)list->At(1))->At(0));
   printf("============================================\n");
   printf("Total  hpx: %d entries\n", (int)hpx->GetEntries());
   hpx->Draw();
   list->Delete();
   delete list;
}
コード例 #28
0
ファイル: produceHisto.C プロジェクト: ramankhurana/usercode
void makePlot(vector<TTree*> sigTree,vector<double> sigWeight,
	      vector<int> ptHatLo, vector<int> ptHatHi,
              std::string var,TCut cut,TH1F* h,bool norm)
{
   TH1F *hRes = (TH1F*)h->Clone();
   hRes->SetName("hRes");
   hRes->Sumw2();
  
   char tmp[300];
   for (unsigned int i=0; i<sigTree.size(); i++)
     {
       // first determine the pthat cut
       
       sprintf(tmp, "ptHat >= %d && ptHat <= %d",ptHatLo[i], ptHatHi[i]);
       TCut ptHatCut = tmp;
       TCut allCut = cut + ptHatCut;
       cout << "Current cut = " << allCut.GetTitle() << endl;
       TH1F *htmp = (TH1F*)h->Clone();
       htmp->SetName("htmp");
       sigTree[i]->Draw(Form("%s>>htmp",var.data()),allCut);
       htmp->Sumw2();
       htmp->Scale(sigWeight[i]);
       cout << "scale = " << sigWeight[i] << endl;
       cout << "After scaling htmp -> entries() " << htmp->GetEntries() << endl;
       cout << "After scaling htmp -> Integral() " << htmp->Integral() << endl;
       cout << "After scaling htmp -> GetMean()  " << htmp->GetMean() << endl;
       cout << "After scaling htmp -> GetRMS()  " << htmp->GetRMS() << endl;
       hRes->Add(htmp);
       delete htmp;
   }
   h->Sumw2();
   h->Add(hRes);
   if(norm)h->Scale(1.0/(double)h->Integral(0,1000));
   cout << "After scaling h-> entries() " << h->GetEntries() << endl;
   cout << "After scaling h-> Integral() " << h->Integral() << endl;
   cout << "After scaling h -> GetMean()  " << h->GetMean() << endl;
   cout << "After scaling h -> GetRMS()  " << h->GetRMS() << endl;
   
   delete hRes;
}
コード例 #29
0
ファイル: Getdphi.C プロジェクト: XuQiao/HI
void FillGoodRun(int icent,int ihar){
    float pi = acos(-1.0);
    TString str;
    TFile *fin;
    int nrun = GetTotalRun();
    if(nrun<0) exit(1);
       for(int isub=0;isub<nsub;isub++){
            str = choosesub(isub);
            if(str=="ABORT") continue;
            for(int irun=0;irun<nrun;irun++){
      std::cout<<icent<<" "<<ihar<<" "<<isub<<" "<<irun<<std::endl;
         fin = TFile::Open(Form("/store/user/qixu/flow/Run16dAu/62GeV/%s",GetRun(irun).Data()));
        TH1F* hpsi = new TH1F("psi","psi",100,-pi,pi);
        for(int ibbcz=0;ibbcz<nbbcz;ibbcz++){
          TH1F* hpsitemp = (TH1F*)fin->Get(Form("psiFla_%d_%d_%d_%d",icent,ibbcz,ihar,isub));
          hpsi->Add(hpsitemp);
        }
        TF1 *fun = new TF1("fun","pol0",-pi,pi);
      if(hpsi->GetEntries()>1000){
	//hpsi->SetMarkerStyle(20);
	//hpsi->SetMarkerSize(0.6);
	//hpsi->SetMarkerColor(4);
	hpsi->SetMinimum(10);
	hpsi->Fit("fun","QR0");
	//float par=fun->GetParameter(0);
	//hpsi->SetMaximum(1.5*par);
	//hpsi->Draw();
	GoodRunFit[icent][ihar][isub][irun] = fun->GetChisquare()/fun->GetNDF();
        fin->Close();
      }
      else{
        GoodRunFit[icent][ihar][isub][irun] = -9999;
        fin->Close();
     }
     // GoodRunFit[icent][ihar][isub][irun] = 1.;
    }
       }
}
コード例 #30
0
ファイル: Getvn.C プロジェクト: XuQiao/phenix
float GoodRun(int icent, int ihar, int isub, int irun){
    float pi = acos(-1);
    TF1 *fun = new TF1("fun","pol0",-pi,pi);
    TString str;
    TFile *fin;

     ofstream fout;
        if(isub==1){
         str = "FVTX1S";
        }
        else if(isub==2){
         str = "FVTX2S";
        }
        else return -9999;
         fin = TFile::Open(Form("Run15pAu200MinBias/output_fvtxwithcntEP_%d.root",GetRun(irun)));
        TH1F* hpsi = new TH1F("psi","psi",100,-pi,pi);
        for(int ibbcz=0;ibbcz<nbbcz;ibbcz++){
          hpsitemp = (TH1F*)fin->Get(Form("psi_%d_%d_%d_%d",icent,ibbcz,ihar,isub));
          hpsi->Add(hpsitemp);
        }
      if(hpsi->GetEntries()>10000){
	hpsi->SetMarkerStyle(20);
	hpsi->SetMarkerSize(0.6);
	hpsi->SetMarkerColor(4);
	hpsi->SetMinimum(10);
	hpsi->Fit("fun","QR0");
	float par=fun->GetParameter(0);
	hpsi->SetMaximum(1.5*par);
	//hpsi->Draw();
        fin->Close();
	return fun->GetChisquare()/fun->GetNDF();
      }
      else{
        fin->Close();
        return -9999;
      }
    }