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


C++ THStack::Clone方法代码示例

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


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

示例1: if

void
Draw(string filename, bool norm, bool logy, bool eff, bool cum, TLine* line){
  if(debug) printf("  Draw (norm is %i) %s\n",norm, filename.c_str());

  TCanvas c1;
  if(logy) c1.SetLogy();

  string title;
  if(Data.size()){
    title = Data[0].hist->GetTitle();
    title += ";"; 
    title += Data[0].hist->GetXaxis()->GetTitle();
    title += ";";
    title += Data[0].hist->GetYaxis()->GetTitle();
  }else if(Bkg.size()){
    title = Bkg[0].hist->GetTitle();
    title += ";"; 
    title += Bkg[0].hist->GetXaxis()->GetTitle();
    title += ";";
    title += Bkg[0].hist->GetYaxis()->GetTitle();
  }
  TH1F* hData = NULL;
  for(uint i=0; i<Data.size(); i++){
    if(i==0) hData = (TH1F*)Data[i].hist->Clone("hData");
    else     hData->Add(Data[i].hist);
  }
  hData->SetMarkerSize(5);
  
  if(!eff){
    THStack* sBkg  = new THStack("sBkg",title.c_str());
    THStack* sSigs[Sig.size()];

    for(uint i=0; i<Bkg.size(); i++){
      sBkg->Add(Bkg[i].hist);
    } 
    
    for(uint i=0; i<Sig.size(); i++){
      sSigs[i] = (THStack*) sBkg->Clone();
      sSigs[i]->Add(Sig[i].hist);
    }
    
    Double_t max = sBkg->GetMaximum();
    sBkg->Draw("HIST");
    for(unsigned int i=0; i<Sig.size(); i++){
      max = TMath::Max(max, sSigs[i]->GetMaximum());
      sSigs[i]->Draw("HIST SAME");
    }
    if(hData){
      max = TMath::Max(max, hData->GetMaximum());
      hData->Draw("E1 SAME");
    }
    sBkg->SetMaximum(1.1*max);
    
  }else{
    THStack* hs = new THStack("hs",title.c_str());
    hs->Add(hData);
    
    for(unsigned int i=0; i<Bkg.size(); ++i){
      hs->Add(Bkg[i].hist);
    }
    for(unsigned int i=0; i<Sig.size(); ++i){
      hs->Add(Sig[i].hist);
    }
    hs->Draw("nostack HIST");
  }
  if(debug) cout<<"Title: "<<title<<endl;

  if(debug) cout<<"Creating Legend\n";
  TLegend *legend = new TLegend(0.65,0.50,0.88,0.89,"");
  
  if(Data.size()) legend->AddEntry(hData, "Data", "PLE");
  for(unsigned int i=0; i<Bkg.size(); ++i){
    legend->AddEntry(Bkg[i].hist,SampleNames[Bkg[i].name].c_str(), "L");
  }
  for(unsigned int i=0; i<Sig.size(); ++i){
    legend->AddEntry(Sig[i].hist,SampleNames[Sig[i].name].c_str(), "L");
  }
  
  if(norm){//????
    //TAxis* axis = samples[0]->at(0).hist->GetXaxis();
    //int first = axis->GetFirst();
    //int last  = axis->GetLast();
    //float sum = hists[i]->Integral(first,last); 
    //hists[i]->Scale(1./sum);
    //axis->SetRange(first,last);
  }
 
  //hs->GetXaxis()->SetNdivisions(10); 
  if(debug) printf("Setting title\n");  

  legend->SetTextSize(0.03);
	legend->SetBorderSize(0);
  legend->SetFillStyle(0);
  legend->Draw();

  if(line) line->Draw();

  c1.SaveAs(filename.c_str());
  c1.Print("Summary.pdf","pdf");	
}
开发者ID:cfantasia,项目名称:usercode,代码行数:100,代码来源:MakePlots.C

示例2: makePlots


//.........这里部分代码省略.........
  histo21->Scale( rate_data/histo21->Integral()  );
  histo22->Scale( rate_hw  /histo22->Integral()  );
  histo23->Scale( rate_hh  /histo23->Integral()  );
  histo3-> Scale( rate_qcd /histo3->Integral()  );

  histo1->Rebin( rebin );
  histo21->Rebin( rebin );
  histo22->Rebin( rebin );
  histo23->Rebin( rebin );
  histo3->Rebin( rebin );
  histoD1->Rebin( rebin );
  histoD2->Rebin( rebin );

  if (makeGraphs) {
    int bgColor = kBlue-9;
    int sigColor= kRed-9;
    TCanvas * tc = new TCanvas(); tc->Divide(3,2);
    int index=1;
    tc->cd(index++); histo1->Draw(); // black
    histo21->SetMarkerColor(kBlue);
    histo21->SetFillColor(kBlue);
    histo21->SetFillStyle(kBlue);
    tc->cd(index++);histo21->Draw();// blue
    tc->cd(index++);histo22->Draw();//red
    tc->cd(index++);histo23->Draw();//brown
    histo3->SetMarkerColor(kGreen);
    tc->cd(index++);histo3 ->Draw();//green
    histoD1->SetMarkerColor(kOrange);
    tc->cd(index++);histoD1 ->Draw();//orange
    tc->SaveAs("hplus_test.png");

    TH1F * sumBG =  new TH1F("sumBg","sumBg",40/rebin,0,400);
    TH1F * sumSig =  new TH1F("sumSig","sumSig",40/rebin,0,400);
    TH1F * sumData;
    TCanvas * tu = new TCanvas();
    sumBG->Add(histo1);
    sumBG->Add(histo3);
    // sumBG->SetMarkerColor(kBlue);
    // sumBG->SetFillColor(kBlue);
    sumBG->SetFillColor(bgColor);
    // sumBG->SetFillStyle(1001);
    // sumBG->SetMarkerStyle(2);
    // sumBG->Draw("hist");
    const double f=0.1;
    sumSig->Add(histo23,f*f);
    sumSig->Add(histo22,2.0*(1.0-f)*f);
    // sumSig->SetMarkerColor(kRed);
    sumSig->SetFillColor(sigColor);
    // sumSig->SetMarkerStyle(2);
    // sumSig->Draw("same");
    sumData =  (TH1F * ) histo21->Clone("sumData");
    sumData->SetMarkerColor(kBlack);
    // sumData->Draw("same");

    THStack * st = new THStack();
    st->Add(sumBG);
    st->Add(sumSig);
    st->Draw("histe");
    THStack * st2 = st->Clone();
    sumData->Draw("same");
    st2->Draw("same E");
   

    TLatex text;
    text.SetTextAlign(12);
    text.SetTextSize(0.04);
    text.SetNDC();
    // char tmpLabel[30];
    // sprintf(tmpLabel,"Peak at %.3f",
    //	 myhi->GetBinCenter(myhi->GetMaximumBin()));
    text.SetTextColor(bgColor);
    text.DrawLatex(0.4,0.85,"background (ewk+qcd)");
    text.SetTextColor(sigColor);
    text.DrawLatex(0.4,0.75,"bg + signal (HW+HH, br_{t#rightarrowH^{+}b}=0.1) ");
    text.SetTextColor(kBlack);
    text.DrawLatex(0.4,0.65,"data");

    tu->SaveAs("hplus_test_db.png");
  }

  histo1 ->SetName("Type1");
  histo21->SetName("data_obs");
  histo22->SetName("HW_1");
  histo23->SetName("HH_1");
  histo3 ->SetName("QCD");

  sprintf(tmp,"hplus_%.0f.root",mass);
  TFile * fileOut = new TFile(tmp,"recreate");
  histo1->Write();
  histo21->Write();
  histo22->Write();
  histo23->Write();
  histo3->Write();
  histoD1->Write();
  histoD2->Write();

  fileOut->Close();

  return 0;
}
开发者ID:aashaqshah,项目名称:cmssw-1,代码行数:101,代码来源:generateLandsRootFiles.C


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