当前位置: 首页>>代码示例>>C++>>正文


C++ TH1D::Clear方法代码示例

本文整理汇总了C++中TH1D::Clear方法的典型用法代码示例。如果您正苦于以下问题:C++ TH1D::Clear方法的具体用法?C++ TH1D::Clear怎么用?C++ TH1D::Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TH1D的用法示例。


在下文中一共展示了TH1D::Clear方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: genAnalysis


//.........这里部分代码省略.........
  if(infilenamev.size() != infilecatv.size()) assert(0);

  Float_t fMVACut[4][4];
  InitializeJetIdCuts(fMVACut);
 
  TFile *fPUFile = TFile::Open(Form("%s",puPath.Data()));
  TH1D *fhDPU = (TH1D*)(fPUFile->Get("puWeights"));
  assert(fhDPU);
  fhDPU->SetDirectory(0);
  delete fPUFile;

  double xmin = 0.0;
  double xmax = 1.0;
  int nBinPlot      = 200;
  double xminPlot   = 0.0;
  double xmaxPlot   = 200.0;
  const int allPlots = 160;
  TH1D* histo[allPlots];

  for(int thePlot=0; thePlot<allPlots; thePlot++){
    if     (thePlot >=  0 && thePlot <= 39) {nBinPlot =  20; xminPlot = 0.0; xmaxPlot = 100.0;}
    else if(thePlot >= 40 && thePlot <= 79) {nBinPlot =   5; xminPlot = 0.0; xmaxPlot =   2.5;}
    else if(thePlot >= 80 && thePlot <= 80) {nBinPlot =   5; xminPlot =-0.5; xmaxPlot =   4.5;}
    else if(thePlot >= 81 && thePlot <= 90) {nBinPlot = 100; xminPlot = 0.0; xmaxPlot =   1.0;}
    else if(thePlot >=100 && thePlot <=109) {nBinPlot =  50; xminPlot = 0.0; xmaxPlot = 100.0;}
    else if(thePlot >=110 && thePlot <=119) {nBinPlot =  50; xminPlot = 0.0; xmaxPlot =   5.0;}
    else if(thePlot >=120 && thePlot <=129) {nBinPlot =  50; xminPlot = 0.0; xmaxPlot = 100.0;}
    else if(thePlot >=130 && thePlot <=139) {nBinPlot =  50; xminPlot = 0.0; xmaxPlot =   5.0;}
    else if(thePlot >=140 && thePlot <=149) {nBinPlot =  50; xminPlot = 0.0; xmaxPlot = 100.0;}
    else if(thePlot >=150 && thePlot <=159) {nBinPlot =  50; xminPlot = 0.0; xmaxPlot =   5.0;}
    TH1D* histos = new TH1D("histos", "histos", nBinPlot, xminPlot, xmaxPlot);
    histos->Sumw2();
    histo[thePlot] = (TH1D*) histos->Clone(Form("histo%d",thePlot));
    histos->Clear();
  }

  //*******************************************************
  // Chain Loop
  //*******************************************************
  for(UInt_t ifile=0; ifile<infilenamev.size(); ifile++) {

    TFile the_input_file(infilenamev[ifile]);
    TTree *the_input_tree = (TTree*)the_input_file.FindObjectAny("events");
    //TTree *the_input_all  = (TTree*)the_input_file.FindObjectAny("all");

    BareEvent eventEvent;
    eventEvent.setBranchAddresses(the_input_tree);

    BareJets eventJets;
    eventJets.setBranchAddresses(the_input_tree);

    BareLeptons eventLeptons;
    eventLeptons.setBranchAddresses(the_input_tree);

    BareTaus eventTaus;
    eventTaus.setBranchAddresses(the_input_tree);

    BareMet eventMet;
    eventMet.SetExtend();
    eventMet.setBranchAddresses(the_input_tree);

    BareTrigger eventTrigger;
    eventTrigger.setBranchAddresses(the_input_tree);

    BareVertex eventVertex;
    eventVertex.setBranchAddresses(the_input_tree);
开发者ID:calderona,项目名称:MitAnalysisRunII,代码行数:67,代码来源:genAnalysis.C

示例2: QCDAnalysis


//.........这里部分代码省略.........

  //infilenamev.push_back(Form("nero.root"));     infilecatv.push_back(0);

  if(infilenamev.size() != infilecatv.size()) assert(0);

  Float_t fMVACut[4][4];
  InitializeJetIdCuts(fMVACut);
 
  TFile *fPUFile = TFile::Open(Form("%s",puPath.Data()));
  TH1D *fhDPU = (TH1D*)(fPUFile->Get("puWeights"));
  assert(fhDPU);
  fhDPU->SetDirectory(0);
  delete fPUFile;

  double xmin = 0.0;
  double xmax = 1.0;
  int nBinPlot      = 200;
  double xminPlot   = 0.0;
  double xmaxPlot   = 200.0;
  const int allPlots = 11;
  const int histBins = 8;
  TH1D* histo[allPlots][histBins];

  for(int thePlot=0; thePlot<allPlots; thePlot++){
    if     (thePlot >=  0 && thePlot <=  5) {nBinPlot = 200; xminPlot = 0.0; xmaxPlot = 200.0;}
    else if(thePlot >=  6 && thePlot <=  6) {nBinPlot =   7; xminPlot =-0.5; xmaxPlot =   6.5;}
    else if(thePlot >=  7 && thePlot <=  7) {nBinPlot =  40; xminPlot = 0.0; xmaxPlot =  40.0;}
    else if(thePlot >=  8 && thePlot <=  8) {nBinPlot =  40; xminPlot =-0.5; xmaxPlot =  39.5;}
    else if(thePlot >=  9 && thePlot <=  9) {nBinPlot =  50; xminPlot = 0.0; xmaxPlot =  50.0;}
    else if(thePlot >= 10 && thePlot <= 10) {nBinPlot =  50; xminPlot = 0.0; xmaxPlot =   2.5;}
    TH1D* histos = new TH1D("histos", "histos", nBinPlot, xminPlot, xmaxPlot);
    histos->Sumw2();
    for(int i=0; i<histBins; i++) histo[thePlot][i] = (TH1D*) histos->Clone(Form("histo%d",i));
    histos->Clear();
  }

  //*******************************************************
  // Chain Loop
  //*******************************************************
  for(UInt_t ifile=0; ifile<infilenamev.size(); ifile++) {

    TFile the_input_file(infilenamev[ifile]);
    TTree *the_input_tree = (TTree*)the_input_file.FindObjectAny("events");
    //TTree *the_input_all  = (TTree*)the_input_file.FindObjectAny("all");

    BareMonteCarlo eventMonteCarlo;
    eventMonteCarlo.setBranchAddresses(the_input_tree);

    BareEvent eventEvent;
    eventEvent.setBranchAddresses(the_input_tree);

    BareJets eventJets;
    eventJets.setBranchAddresses(the_input_tree);

    BareLeptons eventLeptons;
    eventLeptons.setBranchAddresses(the_input_tree);

    BareTaus eventTaus;
    eventTaus.setBranchAddresses(the_input_tree);

    BareMet eventMet;
    eventMet.SetExtend();
    eventMet.setBranchAddresses(the_input_tree);

    BareTrigger eventTrigger;
    eventTrigger.setBranchAddresses(the_input_tree);
开发者ID:calderona,项目名称:MitAnalysisRunII,代码行数:67,代码来源:QCDAnalysis.C

示例3: CR5


//.........这里部分代码省略.........

    peakPosth[iSample] = new TH1D( TString("peakPost") + sample[iSample], TString("peakPost") + sample[iSample], 1, 0., 1.);
    peakSFPosth[iSample] = new TH1D( TString("peakSFPost") + sample[iSample], TString("peakSFPost") + sample[iSample], 1, 0., 1.);

    tailh[iSample] = new TH1D( TString("tail") + sample[iSample], TString("tail") + sample[iSample], 1, 0., 1.);
  }

  int N = srTree->GetEntries();

  TFile* inFile[NSamples];
  TDirectory* inBaseDir[NSamples];
  TH1D* mth[NSamples];
  for (int iSample = 0; iSample < NSamples; iSample++){
    TString inFileName = "./MakeHistos/"+sample[iSample]+".root";
    inFile[iSample]= new TFile( inFileName,"READ");
  }

  TH1D* numh = new TH1D( "num", "num", 1, 0., 1.);      
  TH1D* denh = new TH1D( "den", "den", 1, 0., 1.);
  TH1D* tmph = new TH1D( "tmp", "tmp", 1, 0., 1.);

  for (int ilep = 0; ilep < NLep; ilep++){
    for ( int iSR = 0; iSR < N; iSR++){      
      srTree->GetEntry(iSR);
      
      TString baseDirName = ""; baseDirName += iSR;
      for (int iSample = 0; iSample < NSamples; iSample++)
	inBaseDir[iSample] =  inFile[iSample]->GetDirectory(baseDirName);
      
      ////////////////////
      // Cleaning
      ////////////////////
      
      numh->Clear(); numh->Reset();
      denh->Clear(); denh->Reset();
      tmph->Clear(); tmph->Reset();

      SFh->Clear(); SFh->Reset();
      for ( int iSample = 0; iSample < NSamples; iSample++){
	peakPreh[iSample]->Clear();   peakPreh[iSample]->Reset();
	peakSFPreh[iSample]->Clear(); peakSFPreh[iSample]->Reset();
	
	peakPosth[iSample]->Clear();   peakPosth[iSample]->Reset();
	peakSFPosth[iSample]->Clear(); peakSFPosth[iSample]->Reset();
	
	tailh[iSample]->Clear(); tailh[iSample]->Reset();
      }

      ////////////////////
      // Reading input
      ////////////////////

      for (int iSample = 0; iSample < NSamples; iSample++){
	TString histoName = lep[ilep]; histoName += "-SearchRegionPreIsoTrackVeto/Mt";
	inBaseDir[iSample]->GetObject(histoName, mth[iSample]);

	n1 = mth[0]->FindBin(50.);
	n2 = mth[0]->FindBin(79.99); 
	n3 = mth[0]->FindBin(mtCut);
	n4 = mth[0]->GetNbinsX() + 1;

	integral = mth[iSample]->IntegralAndError( n1, n2, error);
	peakPreh[iSample]->SetBinContent(1, integral);
	peakPreh[iSample]->SetBinError(1, error);
      }
开发者ID:fcostanz,项目名称:StopAnalysis,代码行数:66,代码来源:CR5.C

示例4: compareTrig

void compareTrig(){
  
  TFile *f1 = TFile::Open("hltmenu_1TeV_1.0e10_startup_run122314_PD_MinBias_ohlt_all_2009_12_3.root");
  TFile *f2 = TFile::Open("hltmenu_1TeV_1.0e10_startup_pythiaD6T_ohlt_30k_2009_12_3.root");

  TH2F *overlap_data = (TH2F *) f1->Get("overlap");
  TH2F *overlap_mc = (TH2F *) f2->Get("overlap");  
  TH2F *num_data = (TH2F *) f1->Get("trigCorrNum");
  TH2F *num_mc = (TH2F *) f2->Get("trigCorrNum");

  int nbin = num_data->GetNbinsY();
 
  for(int i=1 ; i <= nbin ;i++){ 
    string t = int2string(i);
    string name = "c"+t;
    TCanvas *c = new TCanvas(name.c_str(),"c",1);
    char *na = num_data->GetYaxis()->GetBinLabel(i);
    TH1D *x = overlap_data->ProjectionY("xh",i,i);
    TH1D *y = overlap_mc->ProjectionY("yh",i,i);

    //get denominators 
    double de_data = num_data->GetBinContent(i,i);
    double de_mc = num_mc->GetBinContent(i,i);

    if(debug) { 
      cout << na << endl;
      cout << "data= " << de_data << " mc= " << de_mc << endl;
    }
    //Set error from overlap plot
    for(int j=1; j <= nbin; j++){
      //get numerators
      double nu_data = num_data->GetBinContent(i,j);
      double nu_mc = num_mc->GetBinContent(i,j);

      double xerr = sigma(nu_data, de_data, 3);
      double yerr = sigma(nu_mc, de_mc, 3);
 
      if(debug){
        cout << "data= " << nu_data << " err= " << xerr << endl;
        cout << "mc= " << nu_mc << " err= " << yerr << endl;  
      }
      x->SetBinError(j,xerr);
      y->SetBinError(j,yerr);

    }

    //Set histograms 
    x->SetStats(0);
    x->Draw("P");
    y->Draw("PSame");
    x->SetMarkerStyle(20);
    y->SetMarkerStyle(22);
    x->SetMarkerSize(1.2);
    y->SetMarkerSize(1.2);
    x->SetMarkerColor(2);
    y->SetMarkerColor(4);
    x->SetLineColor(2);
    y->SetLineColor(4);
    x->GetXaxis()->LabelsOption("v");
    y->GetXaxis()->LabelsOption("v");

    c->SetBottomMargin(0.35);

  
    TLegend *l= new TLegend(0.6,0.91,1.0,1.0);
    l->SetHeader(na);
    l->AddEntry(x,"Data","pl");
    l->AddEntry(y,"MC","pl");
    l->SetFillColor(0);
    l->SetLineColor(0);
    l->Draw();

    x->Clear();
    y->Clear();
    
  }

}
开发者ID:monttj,项目名称:usercode,代码行数:78,代码来源:compareTrig.C

示例5: fitX

void fitX(TString infname="/data/twang/BfinderRun2/DoubleMu/BfinderData_pp_20151202_bPt0jpsiPt0tkPt0p5/finder_pp_merged.root")
{
   
   TFile *inf = new TFile(infname.Data());
   TTree *ntmix = (TTree*) inf->Get("Bfinder/ntmix");
   TH1D *h = new TH1D("h","",40,3.6,4);
   TCut cutTrk = "1";   //original YJ
   //TCut cutTrk = "Btrk1PixelHit>=2&&Btrk1StripHit>=7&&Btrk1Chi2ndf<5&&Btrk2PixelHit>=2&&Btrk2StripHit>=7&&Btrk2Chi2ndf<5";
   TCut cutTotal="Btype==7&&Bpt>10&&abs(Beta)<10&&sqrt((Bmumueta-Btrk1Eta)*(Bmumueta-Btrk1Eta)+(Bmumuphi-Btrk1Phi)*(Bmumuphi-Btrk1Phi))<9999"&&cutTrk;

   TCanvas *c = new TCanvas("c","",750,600);
    ntmix->Draw("Bmass>>h",cutTotal);

    
    TFile*output=new TFile("histoX.root","recreate");
    output->cd();
    h->Write();
    output->Close();

   h->Sumw2();
   TF1 *f = new TF1("f","[0]+[1]*x+[2]*x*x+[8]*x*x*x+[9]*x*x*x*x+[3]*Gaus(x,[4],[5])+[6]*Gaus(x,[7],[5])");
   f->SetLineColor(4);
   f->SetParameters(-2.2597e4,1.326e4,-1.727e3,50,3.686,0.00357,1,3.8725,0.0054);
   f->FixParameter(4,3.686);
   f->FixParameter(5,0.00357);
   f->FixParameter(7,3.8725);
   h->Fit("f","LL");
   h->Fit("f","");
   h->Fit("f","LL");
   h->Fit("f","LL","",3.65,3.94);
   h->Fit("f","LL","",3.65,3.94);
   f->ReleaseParameter(4);
   f->ReleaseParameter(5);
   f->ReleaseParameter(7);
   h->Fit("f","LL","",3.65,3.94);
   h->SetXTitle("m(J/#psi#pi^{+}#pi^{-}) [GeV]");
   h->SetYTitle("Entries");
   h->SetStats(0);
   h->SetAxisRange(0,h->GetMaximum()*1.3	,"Y");
   TF1 *f2 = new TF1("f2","[0]+[1]*x+[2]*x*x+0*Gaus(x,[4],[5])+0*Gaus(x,[7],[5])");
   f2->SetParameter(0,f->GetParameter(0));
   f2->SetParameter(1,f->GetParameter(1));
   f2->SetParameter(2,f->GetParameter(2));
   TF1 *f3 = new TF1("f3","[3]*Gaus(x,[4],[5])+[6]*Gaus(x,[7],[5])");
   f3->SetParameter(3,f->GetParameter(3));
   f3->SetParameter(4,f->GetParameter(4));
   f3->SetParameter(5,f->GetParameter(5));
   f3->SetParameter(6,f->GetParameter(6));
   f3->SetParameter(7,f->GetParameter(7));
   f3->SetParameter(8,f->GetParameter(8));

   f->SetLineColor(4);
   f2->SetLineColor(4);
   f3->SetRange(3.65,3.94);
   f2->SetRange(3.65,3.94);
   f2->SetLineStyle(2);
   f3->SetLineStyle(2);
   f2->Draw("same");
   f3->SetLineColor(2);
   f3->SetFillStyle(3004);
   f3->SetFillColor(2);
   f3->Draw("same");
   TLatex *l = new TLatex(3.7,70./80*h->GetMaximum(),"#psi(2S)");
   l->Draw();
   TLatex *l2 = new TLatex(3.875,50./80*h->GetMaximum(),"X(3872)");
   l2->Draw();
   TLatex *l3 = new TLatex(3.812,70./80*h->GetMaximum(),"CMS Preliminary");
   l3->Draw();
   TLatex *l4 = new TLatex(3.78,60./80*h->GetMaximum(),"pp #sqrt{s_{NN}}=5.02 TeV");
  l4->Draw();
   cout<<ntmix->GetEntries()<<endl;
   
   TH1D *hProj = (TH1D*)h->Clone("hProj");
   hProj->Clear();
   f->SetRange(3.6,4);
   for (int i=0;i<h->GetEntries()*11;i++)
   {
      hProj->Fill(f->GetRandom());
   } 
   
   TCanvas *c2 = new TCanvas("c2","",750,600);
   hProj->SetTitle("Estimated Projection");
   hProj->Draw("e");
}
开发者ID:HyunchulKim,项目名称:BntupleRunII,代码行数:84,代码来源:fitX.C


注:本文中的TH1D::Clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。