コード例 #1
0
ファイル: drawHFTime.C プロジェクト: Andrej-CMS/cmssw
void drawHFTime(char file[100]="/uscms_data/d1/sunanda/CMSSW_1_3_3/src/SimG4CMS/Calo/test/vcal5x5.root", int mode=0, float xmax=1000) {

  setTDRStyle();
  TFile *File1 = new TFile(file);
  TTree *em = File1->Get("h3");
  TTree *had = File1->Get("h8");
  TH1F *h1 = new TH1F("EM","Time (EM)",500,0,xmax);
  TH1F *h2 = new TH1F("Had","Time (Had)",500,0,xmax);
  if (mode <=0) {
    em->Project("EM","It");
    had->Project("Had","It");
  } else {
    em->Project("EM","T");
    had->Project("Had","T");
  }
  h1->GetXaxis()->SetTitle("Time (EM)");
  h2->GetXaxis()->SetTitle("Time (Had)");

  TCanvas *em1 = new TCanvas("em1","",800,500);
  gPad->SetLogy(1);
  h1->Draw();

  TCanvas *had1 = new TCanvas("had1","",800,500);
  gPad->SetLogy(1);
  h2->Draw();
}
コード例 #2
0
ファイル: jetPlot.C プロジェクト: SridharaDasu/L1TCaloSummary
void jetPlot(std::string runNumber = "276282") {

  std::string fileName = "/data/dasu/l1tCaloSummary-" + runNumber + ".root";

  TFile file1(fileName.c_str());

  TTree *tree = (TTree*) file1.Get("Events");

  TH1F *cJetPT = new TH1F("CentralJetPT", "PT Distribution", 300, 0, 300);
  tree->Project("CentralJetPT", "l1extraL1JetParticles_uct2016EmulatorDigis_Central_L1TCaloSummaryTest.obj.m_state.p4Polar_.fCoordinates.fPt");
  cJetPT->SetLineColor(kBlue);

  TH1F *fJetPT = new TH1F("ForwardJetPT", "PT Distribution", 300, 0, 300);
  tree->Project("ForwardJetPT", "l1extraL1JetParticles_uct2016EmulatorDigis_Forward_L1TCaloSummaryTest.obj.m_state.p4Polar_.fCoordinates.fPt");
  fJetPT->SetLineColor(kRed);


  TCanvas *canvas = new TCanvas();
  gPad->SetLogy(1);
  gStyle->SetOptStat(0);
  cJetPT->Draw("HIST,E1");
  fJetPT->Draw("SAME,HIST,E1");

  TLegend *lg=new TLegend(0.55,0.55,0.85,0.85);
  lg->SetFillColor(kWhite);
  lg->AddEntry(cJetPT,"Central Jet PT","lf");
  lg->AddEntry(fJetPT,"Forward Jet PT","lf");
  lg->Draw();

  fileName = "JetPlot-" + runNumber + ".png";
  canvas->SaveAs(fileName.c_str());

}
コード例 #3
0
ファイル: MCefficiency.C プロジェクト: boundino/DntupleVn
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();
}
コード例 #4
0
ファイル: weightMCPbPb.C プロジェクト: ginnocen/DntupleRunII
void weightPbPbvertex(){

TFile*fMC=new TFile("/data/HeavyFlavourRun2/MC2015/Dntuple/PbPb/ntD_EvtBase_20160513_DfinderMC_PbPb_20160502_dPt1tkPt0p5_D0_prompt_Dpt2Dy1p1tkPt0p7tkEta2Decay2p9Dalpha0p14Skim_pthatweight.root");
TTree *ntDkpiMC = (TTree*)fMC->Get("ntDkpi");
TTree *ntSkimMC = (TTree*)fMC->Get("ntSkim");
TTree *ntHiMC = (TTree*)fMC->Get("ntHi");
ntDkpiMC->AddFriend(ntSkimMC);
ntDkpiMC->AddFriend(ntHiMC);

TFile*fData=new TFile("/data/jisun/PbPb2015/HF2and_ncand_skim_Dntuple_crab_PbPb_HIMinimumBias1to7_ForestAOD_D0y1p1_tkpt0p7eta1p5_goldenjson_EvtPlaneCali_03182015.root");
TTree *ntDkpiData = (TTree*)fData->Get("ntDkpi");
TTree *ntSkimData = (TTree*)fData->Get("ntSkim");
TTree *ntHiData = (TTree*)fData->Get("ntHi");
TTree *ntHltData = (TTree*)fData->Get("ntHlt");
ntDkpiData->AddFriend(ntSkimData);
ntDkpiData->AddFriend(ntHiData);
ntDkpiData->AddFriend(ntHltData);

TH1F*hpzData=new TH1F("hpzData","hpzData",200,-15,15);
TH1F*hpzMC=new TH1F("hpzMC","hpzMC",200,-15,15);

TCut weighpthat="1";
TString cut="abs(PVz)<15&&pclusterCompatibilityFilter&&pprimaryVertexFilter&&phfCoincFilter3";
TString hlt="HLT_HIL1MinimumBiasHF2AND_part1_v1||HLT_HIL1MinimumBiasHF2AND_part2_v1||HLT_HIL1MinimumBiasHF2AND_part3_v1";

TCut weighttest="1";
//TCut weighttest="1.26077+PVz*(0.00887442)+PVz*PVz*(-0.00782056)+PVz*PVz*PVz*(-3.51063e-05)+PVz*PVz*PVz*PVz*(-3.51063e-05)";

ntDkpiMC->Project("hpzMC","PVz",TCut(weighpthat)*(TCut(cut.Data()*TCut(weighttest))));
ntDkpiData->Project("hpzData","PVz",(TCut(cut.Data())*TCut(hlt.Data())));

hpzMC->Scale(1./hpzMC->Integral(hpzMC->FindBin(-15.),hpzMC->FindBin(15)));
hpzData->Scale(1./hpzData->Integral(hpzMC->FindBin(-15.),hpzMC->FindBin(15)));

TCanvas*cRatioVtx=new TCanvas("cRatioVtx","cRatioVtx",500,500);
cRatioVtx->Divide(2,1);
cRatioVtx->cd(1);
hpzMC->SetLineColor(2);
hpzMC->Draw();
hpzData->Draw("same");
cRatioVtx->cd(2);
TH1D*hRatioVertex=(TH1D*)hpzData->Clone("hRatioVertex");
hRatioVertex->Divide(hpzMC);
hRatioVertex->Draw();


TF1 *myfit = new TF1("myfit","[0]+[1]*x+x*x*[2]+x*x*x*[3]+x*x*x*x*[4]", -15, 15);  
hRatioVertex->Fit("myfit","","",-15,15);
double par0=myfit->GetParameter(0);
double par1=myfit->GetParameter(1);
double par2=myfit->GetParameter(2);
double par3=myfit->GetParameter(3);
double par4=myfit->GetParameter(4);
std::cout<<"weight="<<par0<<"+PVz*("<<par1<<")+PVz*PVz*("<<par2<<")+PVz*PVz*PVz*("<<par3<<")+PVz*PVz*PVz*PVz*("<<par4<<")"<<endl;

}
コード例 #5
0
ファイル: n1_tree_hist.C プロジェクト: aandriat/MIT-FCCee
// 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();
}
コード例 #6
0
void plots_for_config(string toyfile, string smsfile, string massGlu, string massLSP) {

  gROOT->SetStyle("Plain");
  bool do_fat_line=false; // if you want to have HistLineWidth=1 and FuncWidth=1 as it was before instead of 2
  setTDRStyle(do_fat_line);
  gStyle->SetTextFont(42);
  
  string massCut_ = "MassGlu==" + massGlu + "&&MassLSP==" + massLSP;
  string massCut2_ = "massGlu==" + massGlu + "&&massLSP==" + massLSP;
  TCut massCut(massCut_.c_str());
  TCut massCut2(massCut2_.c_str());

  string comp = "comparison_" + massGlu + "_" + massLSP;

  TFile *_file = TFile::Open(smsfile.c_str());
  TTree *point = (TTree*)_file->Get("events");
  TH1F *jzb = new TH1F("jzb", "", 50, -600, 800);
  point->Project("jzb", "jzb[1]", "id1==id2&&pfJetGoodNum>2&&abs(mll-91.2)<20" + massCut, "gof");

  TFile *_filepa = TFile::Open(toyfile.c_str());
  TTree *pointpa = (TTree*)_filepa->Get("events");
  TH1F *jzbpa = new TH1F("jzbpa", "", 50, -600, 800);
  pointpa->Project("jzbpa", "jzb", "njets>2 && nleptons==2" + massCut2);


  jzbpa->SetLineColor(kRed);
  jzbpa->GetXaxis()->SetTitle("JZB [GeV]");
  jzb->GetXaxis()->SetTitle("JZB [GeV]");


  TLegend *l1 = new TLegend(0.7, 0.75, 0.9, 0.85);
  l1->SetFillColor(kWhite);
  l1->SetTextFont(42);
  l1->SetLineWidth(0);
  l1->SetBorderSize(0);
  l1->AddEntry(jzb, "SMS", "L");
  l1->AddEntry(jzbpa, "SMS TOY", "L");
  TCanvas *m1 = new TCanvas("m1");
  m1->GetPad(0)->SetLogy(1);
  m1->cd();
  jzb->DrawNormalized();
  jzbpa->DrawNormalized("SAME");
  l1->Draw(); 
  CompleteSave(m1,"Plots/" + comp);
  delete m1;

  return;

}
コード例 #7
0
ファイル: ROCTnP.C プロジェクト: dygyun/KoPFA
void ROCTnP(){
  gROOT->LoadMacro("tdrstyle.C");
  setTDRStyle();

  TFile * fbkg = new TFile("/home/tjkim/ntuple/iso/data/QCD_tight/vallot.root");
  TTree * tbkg = (TTree *) fbkg->Get("MuonAna/tree");

  //from normalized histos
  TFile * fhisto = new TFile("MuonAna_backup.root");
  TH1F * h_TTbar = (TH1F *) fhisto->Get("Step_1/hMCSig_TTbar_Step_1_relIso");
  TH1F * h_Wm = (TH1F *) fhisto->Get("Step_1/hMC_Wm_Step_1_relIso");
  TH1F * h_Zmm = (TH1F *) fhisto->Get("Step_1/hMC_Zmumu_Step_1_relIso");
  TH1F * h_QCD = (TH1F *) fhisto->Get("Step_1/hMC_QCD_Step_1_relIso");
  TH1F * h_Data = (TH1F *) fhisto->Get("Step_1/hData_Step_1_relIso");

  h_QCD->Add(h_TTbar);  
  h_QCD->Add(h_Wm);  
  h_QCD->Add(h_Zmm);  

  TCut cutbkg = "pt > 20 && pt < 50"; 
  
  TH1* h_bkg = new TH1F("h_bkg","h_bkg",50,0,0.5);
  tbkg->Project("h_bkg","(chIsoOpt04+phIsoOpt04+nhIsoOpt04)/pt", cutbkg);

  //Data vs PU
  plot(h_Data, h_QCD, "Data (T&P)", "MC (T&P)" , "QCD_MC_pt20_50_PU" , "p_{T}=20-50 GeV" );
  
}
コード例 #8
0
ファイル: leadFrag.C プロジェクト: CmsHI/CVS_SavedFMa
void leadFrag(char *infname = "dj_HCPR-J50U-hiGoodMergedTracks_OfficialSelv2_Final0.root",
    TCut myCut = "cent<30",
    TString module="djcalo_tower")
{
   TFile *inf = new TFile(infname);
   TTree *t = (TTree*)inf->Get(module+"/djTree");

   const int nBin = 5;
   double bins[nBin+1] = {0.5,1.5,4,8,20,1000};  
   double colors[nBin] = {kGray,kBlue-3,38,kOrange-8,kRed-6};

   // Selection cut
   TCut evtCut = "nljet>120&&abs(nljeta)<2&&aljet>50&&abs(aljeta)<2&&jdphi>2./3*TMath::Pi()";
   t->SetAlias("Aj","(nljet-aljet)/(nljet+aljet)");

   // histograms
   TH2D * hFrag_LJEt = new TH2D("hFrag_LJEt",";p_{T}^{J1};p_{T}^{Tower}/p_{T}^{J1}",50,120,300,50,0,1);
   hFrag_LJEt->GetXaxis()->CenterTitle();
   hFrag_LJEt->GetYaxis()->CenterTitle();
   TH2D * hLeadFrag_LJEt = new TH2D("hLeadFrag_LJEt",";p_{T}^{J1};p_{T}^{Highest Tower}/p_{T}^{J1}",50,120,300,50,0,1);
   hLeadFrag_LJEt->GetXaxis()->CenterTitle();
   hLeadFrag_LJEt->GetYaxis()->CenterTitle();

   // project tree
   t->Project("hLeadFrag_LJEt","lppt[0]/nljet:nljet",evtCut);
   t->Project("hFrag_LJEt","ppt/nljet:nljet",evtCut);


   // plot
   TCanvas *c2 = new TCanvas("c2","",600,600);
   c2->SetRightMargin(0.15);
   c2->SetLogz();
   hFrag_LJEt->Draw("colz");

   TCanvas *c3 = new TCanvas("c3","",600,600);
   c3->SetRightMargin(0.15);
   c3->SetLogz();
   hLeadFrag_LJEt->Draw("colz");

   TCanvas *c4 = new TCanvas("c4","",600,600);
   hLeadFrag_LJEt->ProfileX()->Draw("E");
   TH1D * hLeadFrag_LJEt_pfx = (TH1D*)gDirectory->Get("hLeadFrag_LJEt_pfx");
   hLeadFrag_LJEt_pfx->SetAxisRange(0,0.6,"Y");
   hFrag_LJEt->ProfileX()->Draw("same hist");
   TH1D * hFrag_LJEt_pfx = (TH1D*)gDirectory->Get("hFrag_LJEt_pfx");
}
コード例 #9
0
ファイル: utilities.cpp プロジェクト: manuelfs/analysis_code
void get_count_and_uncertainty(TTree& tree,
                               const string& cut,
                               double& count,
                               double& uncertainty) {
    const string hist_name("temp");
    TH1D temp(hist_name.c_str(), "", 1, -1.0, 1.0);
    tree.Project(hist_name.c_str(), "0.0", cut.c_str());
    count=temp.IntegralAndError(0,2,uncertainty);
}
コード例 #10
0
ファイル: addbcsv.C プロジェクト: YoungKwonJo/TTbar2b
void addbcsv(){

  gROOT->ProcessLine(".L $CMSSW_BASE/src/KoPFA/CommonTools/macros/tdrstyle.C");
  defaultStyle();

  TFile * f = new TFile("/afs/cern.ch/work/y/youngjo/public/For8Tev/v20130612_genjet/vallot_TTbarFullLepMGDecays.root");
  TTree * t = (TTree*) f->Get("MuEl/tree");
  
  TH1F * h_bfromtop =  new TH1F("h_bfromtop","h_bfromtop",20,0,1);
  TH1F * h_bnotfromtop =  new TH1F("h_bnotfromtop","h_bnotfromtop",20,0,1);

  t->Project("h_bfromtop","jets_bDiscriminatorCSV","jets_fromtop == 1 && abs(jets_flavor) == 5");
  t->Project("h_bnotfromtop","jets_bDiscriminatorCSV","jets_fromtop == 0 && abs(jets_flavor) == 5");

  h_bfromtop->Scale(1.0/h_bfromtop->Integral());
  h_bnotfromtop->Scale(1.0/h_bnotfromtop->Integral());

  TCanvas * c = new TCanvas("c","c",1);

  h_bfromtop->Draw();
  h_bfromtop->SetStats(0);
  h_bfromtop->SetTitle("");
  h_bfromtop->SetLineColor(2);
  h_bfromtop->SetLineWidth(2);
  h_bnotfromtop->Draw("same");
  h_bnotfromtop->SetLineColor(4);
  h_bnotfromtop->SetLineWidth(2);

  TLegend *l = new TLegend(0.48,0.65,0.58,0.80);
  l->AddEntry(h_bfromtop,"b from top","L");
  l->AddEntry(h_bnotfromtop,"b not from top","L");
  l->SetTextSize(0.04);
  l->SetFillColor(0);
  l->SetLineColor(0);

  l->Draw();

  TLatex *label= new TLatex;
  label->SetNDC();
  label->SetTextSize(0.05);
  label->DrawLatex(0.20,0.82,"CMS Simulation, at #sqrt{s} = 8 TeV");

  c->Print("csvshape_addb.eps");
}
コード例 #11
0
ファイル: utilities.cpp プロジェクト: ald77/ra4_stats
void GetCountAndUncertainty(TTree &tree,
                            const Cut &cut,
                            double &count,
                            double &uncertainty){
  const string hist_name{"temp"};
  TH1D temp{hist_name.c_str(), "", 1, -1.0, 1.0};
  temp.Sumw2();
  tree.Project(hist_name.c_str(), "0.", static_cast<const char *>(cut));
  count=temp.IntegralAndError(0,2,uncertainty);
}
コード例 #12
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();
}
コード例 #13
0
ファイル: cdcHits.C プロジェクト: noemi8a/sim-recon
void cdcHits(void)
{
	gROOT->Reset();
	gStyle->SetErrorX(0.0);

	TCanvas *c1 = new TCanvas("c1");
	c1->SetTicky();
	c1->SetTickx();
	c1->SetGridy();
	c1->Draw();
	
	TFile *f = new TFile("cdc_hits.root");
	TTree *t = (TTree*)gROOT->FindObject("cdcHits");
	double Nevents_thrown = (double)t->GetEntries();
	double timewindow = 1.0E-6;
	double total_integrated_time = timewindow*Nevents_thrown;
	double tagged_rate = 1.0E7;
	cout<<"Number of events thrown: "<<(int)Nevents_thrown<<endl;
	cout<<"Assuming "<<timewindow/1.0E-6<<" microsecond time window"<<endl;
	cout<<"Total beam time represented by simulation:"<<total_integrated_time<<" seconds"<<endl;
	cout<<"Assuming rates correspond to "<<tagged_rate<<" tagged photons/sec beam"<<endl;
	
	// Number of straws in each "ring"
	int n_straws[]={43,50,57,64,71,78,85,99,106,113,120,127,134,141,148,155,166,173,182,187,194,201,208,215,222};
	
	TH1D *nstraws = new TH1D("nstraws","Straws per ring", 25, 0.5, 25.5);
	for(int i=0;i<25; i++){
		nstraws->SetBinContent(i+1, n_straws[i]);
		nstraws->SetBinError(i+1, 0.0);
	}

	TH1D *hits_per_straw = new TH1D("hits_per_straw","CDC Hits per layer", 25, 0.5, 25.5);
	t->Project("hits_per_straw","ring");
	hits_per_straw->Divide(nstraws);
	
	TH1D *rate_per_straw = hits_per_straw->Clone("rate_per_straw");
	char str[256];
	sprintf(str, "Rate per straw at %g tags/sec (kHz)", tagged_rate);
	rate_per_straw->Scale(1.0E-3/total_integrated_time);
	rate_per_straw->SetXTitle("CDC layer");
	rate_per_straw->SetYTitle(str);
	rate_per_straw->SetStats(0);
	rate_per_straw->SetLineColor(kRed);
	rate_per_straw->SetLineWidth(2.0);
	rate_per_straw->SetMarkerColor(kRed);
	rate_per_straw->SetMarkerStyle(20);
	rate_per_straw->SetMarkerSize(1.5);
	rate_per_straw->Draw("P");
	
	c1->SaveAs("cdc_hit_rate.gif");
	c1->SaveAs("cdc_hit_rate.pdf");
}
コード例 #14
0
ファイル: saveHist3pMinpt.C プロジェクト: boundino/Dntuple
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;
}
コード例 #15
0
ファイル: timeWindow.C プロジェクト: hyperbolee/prtdirc
void timeWindow( TFile *infile, double w0, double w1, double w2, double w3)
{
	// w0 -> w1 = time window around peak of time-expt
	// w2 -> w0 = window to left of w01
	// w1 -> w3 = window to right of w01

	// grab trees from infile
	TTree *dirc = infile->Get("dirc");
	TTree *reco = infile->Get("reco");

	// get lens, bar angle, and beam momentum
	int lens(0);
	double alpha(0),beam(0);
	dirc->SetBranchAddress("lens",&lens);
	dirc->SetBranchAddress("theta",&alpha);
	dirc->GetEntry(0);

	// define histograms of diff, outside diff, and counters
	TH1D *diff = new TH1D("diff","diff",1000,-50,50);
	TH1D *dout = new TH1D("dout","dout",1000,-50,50);
	TH1D *tof1 = new TH1D("time-tof1","time-tof1",1000,0,1000);
	TH1D *tof2 = new TH1D("time-tof2","time-tof2",1000,0,1000);
	TH1D *trig = new TH1D("time-trig","time-trig",1000,0,1000);

	// project to histograms
	reco->Project("diff","diff");
	reco->Project("dout","diff");
	reco->Project("time-tof1","time-tof1");
	reco->Project("time-tof2","time-tof2");
	reco->Project("time-trig","time-trig");

	// get diff value at peak and define initial cut
	double diffpeak = diff->GetMaximumBin();
	diffpeak = (diffpeak-500)/10;
	char *diffcut = Form("%f<diff-%f && diff-%f<%f",w0,diffpeak,diffpeak,w1);
	cout << "Initial cut\t" << diffcut << endl;
	
	
}
コード例 #16
0
ファイル: crossXmass.C プロジェクト: YoungKwonJo/TopAnalyzer
TH1F* getTruthCrossSection(TFile *file, double x, TString name){

  TTree* genTree = (TTree*)file->Get("ttbarGenAna/tree");
  TH1D* h = new TH1D(Form("h_%s",name.Data()),"h",nGen, genBins);
  genTree->Project(Form("h_%s",name.Data()), "mTT");
  TH1F* hSigma = new TH1F(Form("hSigma_%s",name.Data()),"hSigma", nGen, genBins);

  for(int i=1; i <= nGen; i++){
    double dsigma = x * h->GetBinContent(i) / ( h->GetBinWidth(i) * h->Integral() );
    hSigma->SetBinContent(i,dsigma);
  }

  return hSigma;

}
コード例 #17
0
void setPedestal( const std::string& fileName, int runNumber, const std::string& type, std::vector<TH1D*> vh_peds ) {

    int nBoard=-1;
    int nChannels=-1;
    int firstChannel=-1;
    if( type=="cef3" ) {
        nBoard       = CEF3_ADC_BOARD;
        nChannels    = CEF3_CHANNELS;
        firstChannel = CEF3_ADC_START_CHANNEL;
    } else if( type=="bgo" ) {
        nBoard       = BGO_ADC_BOARD;
        nChannels    = BGO_CHANNELS;
        firstChannel = BGO_ADC_START_CHANNEL;
    } else if( type=="hodox" ) {
        nBoard       = HODOX_ADC_BOARD;
        nChannels    = HODOX_CHANNELS;
        firstChannel = HODOX_ADC_START_CHANNEL;
    } else if( type=="hodoy" ) {
        nBoard       = HODOY_ADC_BOARD;
        nChannels    = HODOY_CHANNELS;
        firstChannel = HODOY_ADC_START_CHANNEL;
    } else {
        std::cout << "ERROR! Unkown type '" << type << "'!" << std::endl;
        std::cout << "Don't know what pedestals you're looking for." << std::endl;
        std::cout << "Exiting." << std::endl;
        exit(77);
    }



    TFile* file = TFile::Open(fileName.c_str());
    if( file==0 ) return;
    TTree* tree = (TTree*)file->Get("eventRawData");

    std::vector< std::pair<float, float> > peds;
    for( unsigned i=0; i<nChannels; ++i ) {
        int iChannel = firstChannel+i;
        TH1D* h1_ped = new TH1D("ped", "", 500, 0., 500.);
        tree->Project( "ped", "adcData", Form("adcBoard==%d && adcChannel==%d", nBoard, iChannel) );
        vh_peds[i]->SetBinContent( runNumber, h1_ped->GetMean() );
        vh_peds[i]->SetBinError( runNumber, h1_ped->GetRMS() );
        delete h1_ped;
    }

    file->Close();

}
コード例 #18
0
ファイル: quickDphi.C プロジェクト: CmsHI/gammaJetAnalysis
void quickDphi()
{
  TH1::SetDefaultSumw2();
  
  TFile *pAFile = TFile::Open("gammaJets_pA_Data.root");
  TTree *jets = (TTree*)pAFile->Get("jetTree");
  jets->AddFriend("photonTree","gammaJets_pA_Data.root");

  TH1D *hfp20 = new TH1D("hfp20",";#Delta #phi_{J#gamma}", 50, 0, TMath::Pi());
  TH1D *hfl20 = (TH1D*)hfp20->Clone("hfl20");

  TCut anaCut = "photonTree.hadronicOverEm<0.1 && abs(photonTree.eta)<1.44 && abs(jetTree.eta)<1.6 && jetTree.pt>30 && photonTree.ecalRecHitSumEtConeDR04 <4.2  &&  photonTree.hcalTowerSumEtConeDR04 < 2.2  &&  photonTree.trkSumPtHollowConeDR04 < 2";

  // jets->Project("hfl20","dPhi",anaCut&&"(photonTree.HFplusEta4+photonTree.HFminusEta4 < 20)");
  // jets->Project("hfp20","dPhi",anaCut&&"(photonTree.HFplusEta4+photonTree.HFminusEta4 > 20)");
  jets->Project("hfl20","dPhi",anaCut&&"(photonTree.pt > 40)");
  jets->Project("hfp20","dPhi",anaCut&&"(photonTree.pt > 60)");
  
  hfp20->Scale(1./hfp20->GetEntries());
  hfl20->Scale(1./hfl20->GetEntries());

  TCanvas *c1 = new TCanvas();
  c1->SetLogy();

  // hfp20->Draw();
  // hfp20->GetXaxis()->CenterTitle();
  // hfl20->SetMarkerColor(kBlue);
  // hfl20->SetLineColor(kBlue);
  // hfl20->Draw("same");

  // TLegend *leg = new TLegend(0.15,0.5,0.5,0.8);
  // leg->SetFillColor(0);
  // // leg->AddEntry(hfp20,"E^{HF |#eta|>4} > 20","l");
  // // leg->AddEntry(hfl20,"E^{HF |#eta|>4} < 20","l");
  // leg->AddEntry(hfp20,"#gamma p_{T} > 60GeV","l");
  // leg->AddEntry(hfl20,"#gamma p_{T} > 40GeV","l");
  // leg->Draw();

  TH1D *ratio = (TH1D*)hfp20->Clone("ratio");
  //ratio->SetYTitle("(E^{HF |#eta|>4} > 20)/(E^{HF |#eta|>4} < 20)");
  ratio->Divide(hfp20,hfl20,1,1);
  ratio->Draw();
}
コード例 #19
0
ファイル: nbx_check_2.C プロジェクト: c-dilks/scalers11t
void nbx_check_2(const char * filename="counts.root")
{
  TFile * infile = new TFile(filename,"READ");
  TTree * tr = (TTree*) infile->Get("sca");

  Int_t NRUNS_tmp = tr->GetMaximum("i");
  const Int_t NRUNS = NRUNS_tmp;
  TH1D * h[NRUNS];
  char h_n[NRUNS][256];
  char h_t[NRUNS][256];
  char cut[NRUNS][256];

  TCanvas * c = new TCanvas("c","c",1400,1000);

  Double_t max;

  for(Int_t i=0; i<NRUNS; i++)
  {
    printf("i=%d\n",i);

    sprintf(h_n[i],"nbx_bx_%d",i+1);
    sprintf(h_t[i],"N_{bx} vs. bXing for i=%d",i+1);
    h[i] = new TH1D(h_n[i],h_n[i],120,0,120);
    sprintf(cut[i],"tot_bx*(i==%d)",i+1);
    tr->Project(h_n[i],"bx",cut[i]);

    max = h[i]->GetMaximum();
    h[i]->Scale(1/max);

    c->Clear();
    c->SetGrid(1,1);
    h[i]->Draw();

    if(i==0) c->Print("nbx_check/nbx_vs_bxing.pdf(","pdf");
    else if(i+1==NRUNS) c->Print("nbx_check/nbx_vs_bxing.pdf)","pdf");
    else c->Print("nbx_check/nbx_vs_bxing.pdf");
  };
};
コード例 #20
0
ファイル: render.C プロジェクト: tomstroman/TelescopeArray
void render(const char* infile=NULL, const char* title=NULL) {
  gStyle->SetNumberContours(50);
  TCanvas *cam;
  if (!infile) {
    printf("generating empty camera face and exiting\n");
    cam = camFaceCanvas();
    return;
  }
  
  char *graphTitle;
  graphTitle = title?(char *)title:(char *)infile;

  TTree *rays = new TTree();
  char infile_format[64] = "cam/I:pmt:x/F:y";
  rays->ReadFile(infile, infile_format);
  TH2F *map = sqmmHeatMap();
  map->SetTitle(Form("%s;-x (m);y (m)", graphTitle));
  rays->Project("map", "y:-x");
//   rays->Draw("y:-x", "", "same");
  cam = camFaceCanvas(map, 0);
//   map->Draw("colz");
  cam->Print(Form("%s.pdf", infile));
}
コード例 #21
0
ファイル: DrawTree.C プロジェクト: nsahoo/cmssw-1
void DrawTree::Project(Params& A) {

    char name[128];
    sprintf(name,"drawTree%d_%d",fN,_countAdd++);
    A._Hname=name;
    _tree->Project(name,A._varexp.c_str(),A._selection.c_str(),A._option.c_str(),A._nentries,A._firstentry);

    TH1* h = (TH1*)gDirectory->Get(A._Hname.c_str());

    h->SetMarkerStyle(_MarkerStyle+(_MarkerCount0++));
    h->SetMarkerColor(_MarkerColor+(_MarkerCount1++));

    A._TH=h;
    _stack.Add(h);
    cout << A._legend.c_str() << endl;
    _legend->AddEntry(h,A._legend.c_str(),"P");

    float axmin=h->GetXaxis()->GetXmin();
    float axmax=h->GetXaxis()->GetXmax();

    if (xmin>axmin)
        xmin=axmin;
    if (xmax<axmax)
        xmax=axmax;

    if (A._varexp.find(":") != string::npos) {
        A._1D=false;
        float aymin=h->GetYaxis()->GetXmin();
        float aymax=h->GetYaxis()->GetXmax();

        if (ymin>aymin)
            ymin=aymin;
        if (ymax<aymax)
            ymax=aymax;

    }
}
void analysisMacroSingleCanv(){
	TFile *withPDCAFile=new TFile("full_analysis_outputs/withPDCA/AnalysisResults.root","READ");
	TFile *noPDCAFile=new TFile("full_analysis_outputs/noPDCA/AnalysisResults.root","READ");

	TFile *outputHistoFile=new TFile("outputHistos.root","RECREATE");


	TList *withPDCAProcessedNumberList;
	withPDCAFile->GetObject("MultSelection/cListMultSelection",withPDCAProcessedNumberList);
	TList *withPDCAList;
	withPDCAFile->GetObject("Upsilonfirst/UpsilonOutfirst",withPDCAList);

	TList *noPDCAProcessedNumberList;
	noPDCAFile->GetObject("MultSelection/cListMultSelection",noPDCAProcessedNumberList);
	TList *noPDCAList;
	noPDCAFile->GetObject("Upsilonfirst/UpsilonOutfirst",noPDCAList);


	TH1D *withPDCAProcessedHisto;
	withPDCAProcessedHisto=(TH1D*)withPDCAProcessedNumberList->FindObject("fHistEventCounter");
	TTree *withPDCATree;
	withPDCATree=(TTree*)withPDCAList->FindObject("MuonData");

	TH1D *noPDCAProcessedHisto;
	noPDCAProcessedHisto=(TH1D*)noPDCAProcessedNumberList->FindObject("fHistEventCounter");
	TTree *noPDCATree;
	noPDCATree=(TTree*)noPDCAList->FindObject("MuonData");

	Double_t processedWithPDCA=withPDCAProcessedHisto->GetBinContent(1);
	Double_t processedNoPDCA=noPDCAProcessedHisto->GetBinContent(1);
	Double_t normalizationFactor=processedWithPDCA/processedNoPDCA;

///////////////////////////////////////////////////////////////////

	TCanvas *canvHistos090=new TCanvas("canvHistos090","canvHistos090");
	canvHistos090->SetFrameBorderMode(0);
	TPad *Pad1=canvHistos090->cd();
	Pad1->Divide(1,2,0.01,0.0);
	Pad1->cd(1)->SetLogy();
	TH1D *histoInvariantMassWithPDCA090FullRap=new TH1D("Invariant mass 0%-90% 2.5<eta<4.0 PDCA","Invariant mass 0%-90% 2.5<eta<4.0 PDCA",250,2.5,15.);
	withPDCATree->Project("Invariant mass 0%-90% 2.5<eta<4.0 PDCA","dimuon_mass","enevt_centrality>0 && enevt_centrality<90 && dimuon_rapidity>-4. && dimuon_rapidity<-2.5 && highest_muon_transverse_momentum>0. && lowest_muon_transverse_momentum>0.");
//  histoInvariantMassWithPDCA090FullRap->ShowPeaks();
	histoInvariantMassWithPDCA090FullRap->Draw();
	outputHistoFile->cd();
	histoInvariantMassWithPDCA090FullRap->Write();

	TH1D *histoInvariantMassNoPDCA090FullRap=new TH1D("Invariant mass 0%-90% 2.5<eta<4.0","Invariant mass 0%-90% 2.5<eta<4.0",250,2.5,15.);
	noPDCATree->Project("Invariant mass 0%-90% 2.5<eta<4.0","dimuon_mass","enevt_centrality>0 && enevt_centrality<90 && dimuon_rapidity>-4. && dimuon_rapidity<-2.5 && highest_muon_transverse_momentum>0. && lowest_muon_transverse_momentum>0.");
//  histoInvariantMassNoPDCA090FullRap->ShowPeaks();
	histoInvariantMassNoPDCA090FullRap->SetLineColor(kRed);
	histoInvariantMassNoPDCA090FullRap->Draw("SAME");
	outputHistoFile->cd();
	histoInvariantMassNoPDCA090FullRap->Write();

	Pad1->cd(2);
	TH1D *histoInvariantMass090FullRapRatio=new TH1D("Ratio PDCA/NoPDCA 0%-90% 2.5<eta<4.0","Invariant mass 0%-90% 2.5<eta<4.0 PDCA",250,2.5,15.);
	histoInvariantMass090FullRapRatio->Add(histoInvariantMassWithPDCA090FullRap,histoInvariantMassNoPDCA090FullRap,1.,-1.*normalizationFactor);
	histoInvariantMass090FullRapRatio->Divide(histoInvariantMass090FullRapRatio,histoInvariantMassNoPDCA090FullRap);
	histoInvariantMass090FullRapRatio->SetLineColor(kBlack);
	histoInvariantMass090FullRapRatio->Draw();
	histoInvariantMass090FullRapRatio->Write();

///////////////////////////////////////////////////////////////////
	TCanvas *canvHistosAll=new TCanvas("canvHistosAll","canvHistosAll");
	canvHistosAll->SetFrameBorderMode(0);
	TPad *Pad2=canvHistosAll->cd();
	TH1D *histoInvariantMassWithPDCA=new TH1D("All entries PDCA","All entries PDCA",250,2.5,15.);
	withPDCATree->Project("All entries PDCA","dimuon_mass");
//  histoInvariantMassWithPDCA->ShowPeaks();
	histoInvariantMassWithPDCA->Draw();
	outputHistoFile->cd();
	histoInvariantMassWithPDCA->Write();

	TH1D *histoInvariantMassNoPDCA=new TH1D("All entries","All entries",250,2.5,15.);
	noPDCATree->Project("All entries","dimuon_mass");
//  histoInvariantMassNoPDCA->ShowPeaks();
	histoInvariantMassNoPDCA->SetLineColor(kRed);
	histoInvariantMassNoPDCA->Draw("SAME");  
	outputHistoFile->cd();
	histoInvariantMassNoPDCA->Write();  

///////////////////////////////////////////////////////////////////
	TCanvas *canvHistos020=new TCanvas("canvHistos020","canvHistos020");
	canvHistos020->SetFrameBorderMode(0);
	TPad *Pad3=canvHistos020->cd();
	Pad3->Divide(1,2,0.01,0.0);
	Pad3->cd(1)->SetLogy();
	TH1D *histoInvariantMassWithPDCA020FullRap=new TH1D("Invariant mass 0%-20% 2.5<eta<4.0 PDCA","Invariant mass 0%-20% 2.5<eta<4.0 PDCA",250,2.5,15.);
	withPDCATree->Project("Invariant mass 0%-20% 2.5<eta<4.0 PDCA","dimuon_mass","enevt_centrality>0 && enevt_centrality<20 && dimuon_rapidity>-4. && dimuon_rapidity<-2.5 && highest_muon_transverse_momentum>0. && lowest_muon_transverse_momentum>0.");
//  histoInvariantMassWithPDCA020FullRap->ShowPeaks();
	histoInvariantMassWithPDCA020FullRap->Draw();
	outputHistoFile->cd();
	histoInvariantMassWithPDCA020FullRap->Write();

	TH1D *histoInvariantMassNoPDCA020FullRap=new TH1D("Invariant mass 0%-20% 2.5<eta<4.0","Invariant mass 0%-20% 2.5<eta<4.0",250,2.5,15.);
	noPDCATree->Project("Invariant mass 0%-20% 2.5<eta<4.0","dimuon_mass","enevt_centrality>0 && enevt_centrality<20 && dimuon_rapidity>-4. && dimuon_rapidity<-2.5 && highest_muon_transverse_momentum>0. && lowest_muon_transverse_momentum>0.");
//  histoInvariantMassNoPDCA020FullRap->ShowPeaks();
	histoInvariantMassNoPDCA020FullRap->SetLineColor(kRed);
	histoInvariantMassNoPDCA020FullRap->Draw("SAME");  
	outputHistoFile->cd();
	histoInvariantMassNoPDCA020FullRap->Write();  

	Pad3->cd(2);
	TH1D *histoInvariantMass020FullRapRatio=new TH1D("Ratio PDCA/NoPDCA 0%-20% 2.5<eta<4.0","Invariant mass 0%-20% 2.5<eta<4.0 PDCA",250,2.5,15.);
	histoInvariantMass020FullRapRatio->Add(histoInvariantMassWithPDCA020FullRap,histoInvariantMassNoPDCA020FullRap,1.,-1.*normalizationFactor);
	histoInvariantMass020FullRapRatio->Divide(histoInvariantMass020FullRapRatio,histoInvariantMassNoPDCA020FullRap);
	histoInvariantMass020FullRapRatio->SetLineColor(kBlack);
	histoInvariantMass020FullRapRatio->Draw();
	outputHistoFile->cd();
	histoInvariantMass020FullRapRatio->Write();

///////////////////////////////////////////////////////////////////
	TCanvas *canvHistos2090=new TCanvas("canvHistos2090","canvHistos2090");
	canvHistos2090->SetFrameBorderMode(0);
	TPad *Pad4=canvHistos2090->cd();
	Pad4->Divide(1,2,0.01,0.0);
	Pad4->cd(1)->SetLogy();
	TH1D *histoInvariantMassWithPDCA2090FullRap=new TH1D("20%-90% 2.5<eta<4.0 PDCA","20%-90% 2.5<eta<4.0 PDCA",250,2.5,15.);
	withPDCATree->Project("20%-90% 2.5<eta<4.0 PDCA","dimuon_mass","enevt_centrality>20 && enevt_centrality<90 && dimuon_rapidity>-4. && dimuon_rapidity<-2.5 && highest_muon_transverse_momentum>0. && lowest_muon_transverse_momentum>0.");
//  histoInvariantMassWithPDCA2090FullRap->ShowPeaks();
	histoInvariantMassWithPDCA2090FullRap->Draw();
	outputHistoFile->cd();
	histoInvariantMassWithPDCA2090FullRap->Write();

	TH1D *histoInvariantMassNoPDCA2090FullRap=new TH1D("20%-90% 2.5<eta<4.0","20%-90% 2.5<eta<4.0",250,2.5,15.);
	noPDCATree->Project("20%-90% 2.5<eta<4.0","dimuon_mass","enevt_centrality>20 && enevt_centrality<90 && dimuon_rapidity>-4. && dimuon_rapidity<-2.5 && highest_muon_transverse_momentum>0. && lowest_muon_transverse_momentum>0.");
//  histoInvariantMassNoPDCA2090FullRap->ShowPeaks();
	histoInvariantMassNoPDCA2090FullRap->SetLineColor(kRed);
	histoInvariantMassNoPDCA2090FullRap->Draw("SAME");  
	outputHistoFile->cd();
	histoInvariantMassNoPDCA2090FullRap->Write();  

	Pad4->cd(2);
	TH1D *histoInvariantMass2090FullRapRatio=new TH1D("20%-90% 2.5<eta<4.0","20%-90% 2.5<eta<4.0 PDCA",250,2.5,15.);
	histoInvariantMass2090FullRapRatio->Add(histoInvariantMassWithPDCA2090FullRap,histoInvariantMassNoPDCA2090FullRap,1.,-1.*normalizationFactor);
	histoInvariantMass2090FullRapRatio->Divide(histoInvariantMass2090FullRapRatio,histoInvariantMassNoPDCA2090FullRap);
	histoInvariantMass2090FullRapRatio->SetLineColor(kBlack);
	histoInvariantMass2090FullRapRatio->Draw();
	outputHistoFile->cd();
	histoInvariantMass2090FullRapRatio->Write();

///////////////////////////////////////////////////////////////////
	TCanvas *canvHistos090r1=new TCanvas("canvHistos090r1","canvHistos090r1");
	canvHistos090r1->SetFrameBorderMode(0);
	TPad *Pad5=canvHistos090r1->cd();
	Pad5->Divide(1,2,0.01,0.0);
	Pad5->cd(1)->SetLogy();
	TH1D *histoInvariantMassWithPDCA090SecondRap=new TH1D("Invariant mass 0%-90% 2.5<eta<3.2 PDCA","Invariant mass 0%-90% 2.5<eta<3.2 PDCA",250,2.5,15.);
	withPDCATree->Project("Invariant mass 0%-90% 2.5<eta<3.2 PDCA","dimuon_mass","enevt_centrality>0 && enevt_centrality<90 && dimuon_rapidity>-3.2 && dimuon_rapidity<-2.5 && highest_muon_transverse_momentum>0. && lowest_muon_transverse_momentum>0.");
//  histoInvariantMassWithPDCA090SecondRap->ShowPeaks();
	histoInvariantMassWithPDCA090SecondRap->Draw();
	outputHistoFile->cd();
	histoInvariantMassWithPDCA090SecondRap->Write();

	TH1D *histoInvariantMassNoPDCA090SecondRap=new TH1D("Invariant mass 0%-90% 2.5<eta<3.2","Invariant mass 0%-90% 2.5<eta<3.2",250,2.5,15.);
	noPDCATree->Project("Invariant mass 0%-90% 2.5<eta<3.2","dimuon_mass","enevt_centrality>0 && enevt_centrality<90 && dimuon_rapidity>-3.2 && dimuon_rapidity<-2.5 && highest_muon_transverse_momentum>0. && lowest_muon_transverse_momentum>0.");
//  histoInvariantMassNoPDCA090SecondRap->ShowPeaks();
	histoInvariantMassNoPDCA090SecondRap->SetLineColor(kRed);
	histoInvariantMassNoPDCA090SecondRap->Draw("SAME");
	outputHistoFile->cd();
	histoInvariantMassNoPDCA090SecondRap->Write();

	Pad5->cd(2);
	TH1D *histoInvariantMass090SecondRapRatio=new TH1D("Ratio PDCA/NoPDCA 0%-90% 2.5<eta<3.2","Invariant mass 0%-90% 2.5<eta<3.2 PDCA",250,2.5,15.);
	histoInvariantMass090SecondRapRatio->Add(histoInvariantMassWithPDCA090SecondRap,histoInvariantMassNoPDCA090SecondRap,1.,-1.*normalizationFactor);
	histoInvariantMass090SecondRapRatio->Divide(histoInvariantMass090SecondRapRatio,histoInvariantMassNoPDCA090SecondRap);
	histoInvariantMass090SecondRapRatio->SetLineColor(kBlack);
	histoInvariantMass090SecondRapRatio->Draw();
	outputHistoFile->cd();
	histoInvariantMass090SecondRapRatio->Write();

///////////////////////////////////////////////////////////////////
	TCanvas *canvHistos090r2=new TCanvas("canvHistos090r2","canvHistos090r2");
	canvHistos090r2->SetFrameBorderMode(0);
	TPad *Pad6=canvHistos090r2->cd();
	Pad6->Divide(1,2,0.01,0.0);
	Pad6->cd(1)->SetLogy();
	TH1D *histoInvariantMassWithPDCA090FirstRap=new TH1D("Invariant mass 0%-90% 3.2<eta<4.0 PDCA","Invariant mass 0%-90% 3.2<eta<4.0 PDCA",250,2.5,15.);
	withPDCATree->Project("Invariant mass 0%-90% 3.2<eta<4.0 PDCA","dimuon_mass","enevt_centrality>0 && enevt_centrality<90 && dimuon_rapidity>-4. && dimuon_rapidity<-3.2 && highest_muon_transverse_momentum>0. && lowest_muon_transverse_momentum>0.");
//  histoInvariantMassWithPDCA090FirstRap->ShowPeaks();
	histoInvariantMassWithPDCA090FirstRap->Draw();
	outputHistoFile->cd();
	histoInvariantMassWithPDCA090FirstRap->Write();

	TH1D *histoInvariantMassNoPDCA090FirstRap=new TH1D("Invariant mass 0%-90% 3.2<eta<4.0","Invariant mass 0%-90% 3.2<eta<4.0",250,2.5,15.);
	noPDCATree->Project("Invariant mass 0%-90% 3.2<eta<4.0","dimuon_mass","enevt_centrality>0 && enevt_centrality<90 && dimuon_rapidity>-4. && dimuon_rapidity<-3.2 && highest_muon_transverse_momentum>0. && lowest_muon_transverse_momentum>0.");
//  histoInvariantMassNoPDCA090FirstRap->ShowPeaks();
	histoInvariantMassNoPDCA090FirstRap->SetLineColor(kRed);
	histoInvariantMassNoPDCA090FirstRap->Draw("SAME");
	outputHistoFile->cd();
	histoInvariantMassNoPDCA090FirstRap->Write();

	Pad6->cd(2);
	TH1D *histoInvariantMass090FirstRapRatio=new TH1D("Ratio PDCA/NoPDCA 0%-90% 3.2<eta<4.0","Invariant mass 0%-90% 3.2<eta<4.0 PDCA",250,2.5,15.);
	histoInvariantMass090FirstRapRatio->Add(histoInvariantMassWithPDCA090FirstRap,histoInvariantMassNoPDCA090FirstRap,1.,-1.*normalizationFactor);
	histoInvariantMass090FirstRapRatio->Divide(histoInvariantMass090FirstRapRatio,histoInvariantMassNoPDCA090FirstRap);
	histoInvariantMass090FirstRapRatio->SetLineColor(kBlack);
	histoInvariantMass090FirstRapRatio->Draw();
	outputHistoFile->cd();
	histoInvariantMass090FirstRapRatio->Write();
}
コード例 #23
0
void number_of_events_table_xi1690_cc(TString inFile=""){

	//*** In file

	TFile * input = new TFile(inFile, "READ");

	TTree * ntpMC = (TTree*) input->Get("ntpMC");
	TTree * ntpPiMinus = (TTree*) input->Get("ntpPiMinus");
	TTree * ntpPiPlus = (TTree*) input->Get("ntpPiPlus");
	TTree * ntpkaonplus = (TTree*) input->Get("ntpKaonPlus");
	TTree * ntpProton = (TTree*) input->Get("ntpProton");
	TTree * ntpAntiProton = (TTree*) input->Get("ntpAntiProton");
	TTree * ntpLambda0 = (TTree*) input->Get("ntpLambda0");
	TTree * ntpAntiLambda0 = (TTree*) input->Get("ntpAntiLambda0");
	TTree * ntpXiPlus1690 = (TTree*) input->Get("ntpXiPlus1690");
	TTree * ntpXiMinus = (TTree*) input->Get("ntpXiMinus");
	TTree * ntpXiSys = (TTree*) input->Get("ntpXiSys");


	double nevents_mc = ntpMC->GetEntriesFast();
	TString cuts = " McTruthMatch && VtxFit_HowGood==1 && MassFit_prob>0.01";
	TString VtxCut = " McTruthMatch && VtxFit_HowGood==1 & HitTag==1";
	TString cut4c = "McTruthMatch && 4CFit_prob>0.01";


	cout << "particle|   #evts (uncut)|    #evts (ratio in %)|   MC ratio in %|   dp/p in %" << endl;


	//**** PiMinus(Lambda0)
	TH1D * h_piminus_tht_uncut = new TH1D("h_piminus_tht_uncut", "h_piminus_tht", 100, 0,10);
	ntpPiMinus->Project("h_piminus_tht_uncut", "piminus_tht", "McTruthMatch && Mother==3122");
	double piminus_uncut =  h_piminus_tht_uncut->GetEntries();

	TH1D * h_piminus_tht = new TH1D("h_piminus_tht", "h_piminus_tht", 100, 0,10);
	ntpPiMinus->Project("h_piminus_tht", "piminus_tht", "McTruthMatch && piminus_HitTag && Mother==3122");
	int piminus =  h_piminus_tht->GetEntries();

	TH1D * h_piminus_dp = new TH1D("h_piminus_dp", "h_piminus_dp", 250, -0.1,0.1);
	ntpPiMinus->Project("h_piminus_dp", "(piminus_p-piminus_MC_p)/piminus_MC_p", "McTruthMatch && piminus_HitTag && Mother==3122");

	Double_t param[6] = jenny::GetFitParameterDoubleFit(h_piminus_dp, false, 0.02,0.1, true);
	//jenny::CreateDrawAndSaveHistogramDoulbeFit(h_piminus_dp, "","", false, false, false, 0.02,0.1, true);


	double ratio_piminus_cut = piminus/piminus_uncut;
	double ratio_piminus_mc = piminus/nevents_mc;

	cout << "PiMinus(L0)|   " <<  piminus_uncut << "|   " <<  piminus << "(" << ratio_piminus_cut*100 << ")|   " << ratio_piminus_mc*100 << endl;//<< "|   " << param[2]*100 << endl;



	//**** piminus (Xi)
	TH1D * h_piminus2_tht_uncut2 = new TH1D("h_piminus2_tht_uncut2", "h_piminus2_tht", 100, 0,10);
	ntpPiMinus->Project("h_piminus2_tht_uncut2", "piminus_tht", "McTruthMatch && Mother==3312");
	double piminus_uncut2 =  h_piminus2_tht_uncut2->GetEntries();

	TH1D * h_piminus2_tht = new TH1D("h_piminus2_tht", "h_piminus2_tht", 100, 0,10);
	ntpPiMinus->Project("h_piminus2_tht", "piminus_tht", "McTruthMatch && piminus_HitTag && Mother==3312");
	int piminus2 =  h_piminus2_tht->GetEntries();

	TH1D * h_piminus2_dp = new TH1D("h_piminus2_dp", "h_piminus2_dp", 250, -0.1,0.1);
	ntpPiMinus->Project("h_piminus2_dp", "(piminus_p-piminus_MC_p)/piminus_MC_p", "McTruthMatch && piminus_HitTag && Mother==3312");

	Double_t parampip2[6] = jenny::GetFitParameterDoubleFit(h_piminus2_dp, false, 0.02,0.1, true);
	//jenny::CreateDrawAndSaveHistogramDoulbeFit(h_piminus2_dp, "","", false, false, false, 0.02,0.1, true);

	double ratio_piminus_cut2 = piminus2/piminus_uncut2;
	double ratio_piminus_mc2 = piminus2/nevents_mc;

	cout << "PiMinus(Xi)|   " <<  piminus_uncut2 << "|   " <<  piminus2 << "(" << ratio_piminus_cut2*100 << ")|   " << ratio_piminus_mc2*100<< endl;// << "|   " << parampip2[2]*100 << endl;


	//**** PiPlus (AntiLambda0)
	TH1D * h_piplus_tht_uncut = new TH1D("h_piplus_tht_uncut", "h_piplus_tht", 100, 0,10);
	ntpPiPlus->Project("h_piplus_tht_uncut", "piplus_tht", "McTruthMatch && Mother==-3122");
	double piplus_uncut =  h_piplus_tht_uncut->GetEntries();

	TH1D * h_piplus_tht = new TH1D("h_piplus_tht", "h_piplus_tht", 100, 0,10);
	ntpPiPlus->Project("h_piplus_tht", "piplus_tht", "McTruthMatch && piplus_HitTag && Mother==-3122");
	int piplus =  h_piplus_tht->GetEntries();

	TH1D * h_piplus_dp = new TH1D("h_piplus_dp", "h_piplus_dp", 250, -0.1,0.1);
	ntpPiPlus->Project("h_piplus_dp", "(piplus_p-piplus_MC_p)/piplus_MC_p", "McTruthMatch && piplus_HitTag && Mother==-3122");

	Double_t parampip[6] = jenny::GetFitParameterDoubleFit(h_piplus_dp, false, 0.02,0.1, true);
	//jenny::CreateDrawAndSaveHistogramDoulbeFit(h_piplus_dp, "","", false, false, false, 0.02,0.1, true);

	double ratio_piplus_cut = piplus/piplus_uncut;
	double ratio_piplus_mc = piplus/nevents_mc;

	cout << "PiPlus(AL0)|   " <<  piplus_uncut << "|   " <<  piplus << "(" << ratio_piplus_cut*100 << ")|   " << ratio_piplus_mc*100 << endl;//<< "|   " << parampip[2]*100 << endl;




	//**** kaonplus
	TH1D * h_kaonplus_tht_uncut = new TH1D("h_kaonplus_tht_uncut", "h_kaonplus_tht", 100, 0,10);
	ntpkaonplus->Project("h_kaonplus_tht_uncut", "kaonplus_tht", "McTruthMatch && Mother==-13314");
	double kaonplus_uncut =  h_kaonplus_tht_uncut->GetEntries();

	TH1D * h_kaonplus_tht = new TH1D("h_kaonplus_tht", "h_kaonplus_tht", 100, 0,10);
	ntpkaonplus->Project("h_kaonplus_tht", "kaonplus_tht", "McTruthMatch && kaonplus_HitTag && Mother==-13314");
	int kaonplus =  h_kaonplus_tht->GetEntries();

	TH1D * h_kaonplus_dp = new TH1D("h_kaonplus_dp", "h_kaonplus_dp", 250, -0.1,0.1);
	ntpkaonplus->Project("h_kaonplus_dp", "(kaonplus_p-kaonplus_MC_p)/kaonplus_MC_p", "McTruthMatch && kaonplus_HitTag && Mother==-13314");

	Double_t paramk[6] = jenny::GetFitParameterDoubleFit(h_kaonplus_dp, false, 0.02,0.1, true);
	//jenny::CreateDrawAndSaveHistogramDoulbeFit(h_kaonplus_dp, "","", false, false, false, 0.02,0.1, true);

	double ratio_kaonplus_cut = kaonplus/kaonplus_uncut;
	double ratio_kaonplus_mc = kaonplus/nevents_mc;

	cout << "kaonplus|   " <<  kaonplus_uncut << "|   " <<  kaonplus << "(" << ratio_kaonplus_cut*100 << ")|   " << ratio_kaonplus_mc*100 << endl;//<< "|   " << paramk[2]*100 << endl;



	//**** Proton
	TH1D * h_proton_tht_uncut = new TH1D("h_proton_tht_uncut", "h_proton_tht", 100, 0,10);
	ntpProton->Project("h_proton_tht_uncut", "proton_tht", "McTruthMatch && Mother==3122");
	double proton_uncut =  h_proton_tht_uncut->GetEntries();

	TH1D * h_proton_tht = new TH1D("h_proton_tht", "h_proton_tht", 100, 0,10);
	ntpProton->Project("h_proton_tht", "proton_tht", "McTruthMatch && proton_HitTag && Mother==3122");
	int proton =  h_proton_tht->GetEntries();

	TH1D * h_proton_dp = new TH1D("h_proton_dp", "h_proton_dp", 250, -0.1,0.1);
	ntpProton->Project("h_proton_dp", "(proton_p-proton_MC_p)/proton_MC_p", "McTruthMatch && proton_HitTag && Mother==3122");

	Double_t paramProt[6] = jenny::GetFitParameterDoubleFit(h_proton_dp, false, 0.02,0.1, true);
	//jenny::CreateDrawAndSaveHistogramDoulbeFit(h_proton_dp, "","", false, false, false, 0.02,0.1, true);

	double ratio_proton_cut = proton/proton_uncut;
	double ratio_proton_mc = proton/nevents_mc;

	cout << "proton|   " <<  proton_uncut << "|   " <<  proton << "(" << ratio_proton_cut*100 << ")|   " << ratio_proton_mc*100 << endl;//<< "|   " << paramProt[2]*100 << endl;




	//**** AntiProton
	TH1D * h_AntiProton_tht_uncut = new TH1D("h_AntiProton_tht_uncut", "h_AntiProton_tht", 100, 0,10);
	ntpAntiProton->Project("h_AntiProton_tht_uncut", "AntiProton_tht", "McTruthMatch");
	double AntiProton_uncut =  h_AntiProton_tht_uncut->GetEntries();

	TH1D * h_AntiProton_tht = new TH1D("h_AntiProton_tht", "h_AntiProton_tht", 100, 0,10);
	ntpAntiProton->Project("h_AntiProton_tht", "AntiProton_tht", "McTruthMatch && AntiProton_HitTag");
	int AntiProton =  h_AntiProton_tht->GetEntries();

	TH1D * h_AntiProton_dp = new TH1D("h_AntiProton_dp", "h_AntiProton_dp", 250, -0.1,0.1);
	ntpAntiProton->Project("h_AntiProton_dp", "(AntiProton_p-AntiProton_MC_p)/AntiProton_MC_p", "McTruthMatch && AntiProton_HitTag");

	Double_t paramAProt[6] = jenny::GetFitParameterDoubleFit(h_AntiProton_dp, false, 0.02,0.1, true);
	//jenny::CreateDrawAndSaveHistogramDoulbeFit(h_AntiProton_dp, "","", false, false, false, 0.02,0.1, true);

	double ratio_AntiProton_cut = AntiProton/AntiProton_uncut;
	double ratio_AntiProton_mc = AntiProton/nevents_mc;

	cout << "AntiProton|   " <<  AntiProton_uncut << "|   " <<  AntiProton << "(" << ratio_AntiProton_cut*100 << ")|   " << ratio_AntiProton_mc*100 << endl;//<< "|   " << paramAProt[2]*100 << endl;



	//**** lambda0
	TH1D * h_Lambda0_tht_uncut = new TH1D("h_Lambda0_tht_uncut", "h_Lambda0_tht", 100, 0,10);
	ntpLambda0->Project("h_Lambda0_tht_uncut", "Lambda0_tht", "McTruthMatch & HitTag==1");
	double Lambda0_uncut =  h_Lambda0_tht_uncut->GetEntries();

	TH1D * h_Lambda0_tht = new TH1D("h_Lambda0_tht", "h_Lambda0_tht", 100, 0,10);
	ntpLambda0->Project("h_Lambda0_tht", "Lambda0_tht", "HitTag && "+cuts);
	int lambda0 =  h_Lambda0_tht->GetEntries();

	TH1D * h_Lambda0_dp = new TH1D("h_Lambda0_dp", "h_Lambda0_dp", 250, -0.1,0.1);
	ntpLambda0->Project("h_Lambda0_dp", "(Lambda0_p-McTruth_p)/McTruth_p", "HitTag && "+cuts );

	Double_t paraml0[6] = jenny::GetFitParameterDoubleFit(h_Lambda0_dp, false, 0.02,0.1, true);
	//jenny::CreateDrawAndSaveHistogramDoulbeFit(h_Lambda0_dp, "","", false, false, false, 0.02,0.1, true);

	double ratio_Lambda0_cut = lambda0/Lambda0_uncut;
	double ratio_Lambda0_mc = lambda0/nevents_mc;

	cout << "lambda0|   " <<  Lambda0_uncut << "|   " <<  lambda0 << "(" << ratio_Lambda0_cut*100 << ")|   " << ratio_Lambda0_mc*100 << endl;//<< "|   " << paraml0[2]*100 << endl;



	//**** AntiLambda0
	TH1D * h_antiLambda0_tht_uncut = new TH1D("h_antiLambda0_tht_uncut", "h_antiLambda0_tht", 100, 0,10);
	ntpAntiLambda0->Project("h_antiLambda0_tht_uncut", "antiLambda0_tht", "McTruthMatch & HitTag==1");
	double antiLambda0_uncut =  h_antiLambda0_tht_uncut->GetEntries();

	TH1D * h_antiLambda0_tht = new TH1D("h_antiLambda0_tht", "h_antiLambda0_tht", 100, 0,10);
	ntpAntiLambda0->Project("h_antiLambda0_tht", "antiLambda0_tht", "HitTag && "+cuts);
	int AntiLambda0 =  h_antiLambda0_tht->GetEntries();

	TH1D * h_antiLambda0_dp = new TH1D("h_antiLambda0_dp", "h_antiLambda0_dp", 250, -0.1,0.1);
	ntpAntiLambda0->Project("h_antiLambda0_dp", "(antiLambda0_p-McTruth_p)/McTruth_p", "HitTag && "+cuts);

	Double_t paramAL0[6] = jenny::GetFitParameterDoubleFit(h_antiLambda0_dp, false, 0.02,0.1, true);
	//jenny::CreateDrawAndSaveHistogramDoulbeFit(h_antiLambda0_dp, "","", false, false, false, 0.02,0.1, true);

	double ratio_antiLambda0_cut = AntiLambda0/antiLambda0_uncut;
	double ratio_antiLambda0_mc = AntiLambda0/nevents_mc;

	cout << "AntiLambda0|   " <<  antiLambda0_uncut << "|   " <<  AntiLambda0 << "(" << ratio_antiLambda0_cut*100 << ")|   " << ratio_antiLambda0_mc*100<< endl;// << "|   " << paramAL0[2]*100 << endl;


	//**** XiPlus1690
	TH1D * h_xiplus_tht_uncut = new TH1D("h_xiplus_tht_uncut", "h_xiplus_tht", 100, 0,10);
	ntpXiPlus1690->Project("h_xiplus_tht_uncut", "xiplus_tht", "McTruthMatch & HitTag==1");
	double xiplus_uncut =  h_xiplus_tht_uncut->GetEntries();

	TH1D * h_xiplus_tht = new TH1D("h_xiplus_tht", "h_xiplus_tht", 100, 0,10);
	ntpXiPlus1690->Project("h_xiplus_tht", "xiplus_tht", VtxCut);
	int XiPlus =  h_xiplus_tht->GetEntries();

	TH1D * h_xiplus_dp = new TH1D("h_xiplus_dp", "h_xiplus_dp", 250, -0.1,0.1);
	ntpXiPlus1690->Project("h_xiplus_dp", "(xiplus_p-MCTruth_p)/MCTruth_p", VtxCut);

	Double_t paramxip[6] = jenny::GetFitParameterDoubleFit(h_xiplus_dp, false, 0.02,0.1, true);
	//jenny::CreateDrawAndSaveHistogramDoulbeFit(h_xiplus_dp, "","", false, false, false, 0.02,0.1, true);

	double ratio_xiplus_cut = XiPlus/xiplus_uncut;
	double ratio_XiPlus_McTruth = XiPlus/nevents_mc;

	cout << "XiPlus1690|   " <<  xiplus_uncut << "|   " <<  XiPlus << "(" << ratio_xiplus_cut*100 << ")|   " << ratio_XiPlus_McTruth*100<< endl;// << "|   " << paramxip[2]*100 << endl;


	//**** XiMinus
	TH1D * h_XiMinus_tht_uncut = new TH1D("h_XiMinus_tht_uncut", "h_XiMinus_tht", 100, 0,10);
	ntpXiMinus->Project("h_XiMinus_tht_uncut", "VtxFit_tht", "McTruthMatch & HitTag==1");
	double XiMinus_uncut =  h_XiMinus_tht_uncut->GetEntries();

	TH1D * h_XiMinus_tht = new TH1D("h_XiMinus_tht", "h_XiMinus_tht", 100, 0,10);
	ntpXiMinus->Project("h_XiMinus_tht", "VtxFit_tht", cuts+"& HitTag==1");
	int XiMinus1820 =  h_XiMinus_tht->GetEntries();

	TH1D * h_xiMinus_dp = new TH1D("h_xiMinus_dp", "h_xiMinus_dp", 250, -0.1,0.1);
	ntpXiMinus->Project("h_xiMinus_dp", "VtxFit_p-MCTruth_p");

	//jenny::CreateDrawAndSaveHistogramDoulbeFit(h_xiMinus_dp, " ", " ", false, false, false, 0.02 , 0.1, true);
	Double_t paramxim[6] = jenny::GetFitParameterDoubleFit(h_xiMinus_dp, false, 0.02,0.1, true);

	double ratio_XiMinus_cut = XiMinus1820/XiMinus_uncut;
	double ratio_XiMinus_mc = XiMinus1820/nevents_mc;

	cout << "XiMinus|   " <<  XiMinus_uncut << "|   " <<  XiMinus1820 << "(" << ratio_XiMinus_cut*100 << ")|   " << ratio_XiMinus_mc*100 << endl;// "|   " << paramxim[2]*100 << endl;


	//**** XiSys
	TH1D * h_XiSys_tht_uncut = new TH1D("h_XiSys_tht_uncut", "h_XiSys_tht", 100, 0,10);
	ntpXiSys->Project("h_XiSys_tht_uncut", "XiSys_tht", "McTruthMatch");
	double XiSys_uncut =  h_XiSys_tht_uncut->GetEntries();

	TH1D * h_XiSys_tht = new TH1D("h_XiSys_tht", "h_XiSys_tht", 100, 0,10);
	ntpXiSys->Project("h_XiSys_tht", "XiSys_tht", cut4c);
	int XiSys =  h_XiSys_tht->GetEntries();

	TH1D * h_XiSys_dp = new TH1D("h_XiSys_dp", "h_XiSys_dp", 250, -0.1,0.1);
	ntpXiSys->Project("h_XiSys_dp", "(XiSys_p-McTruth_p)/McTruth_p", cut4c);

	Double_t paramxisys[6] = jenny::GetFitParameterDoubleFit(h_XiSys_dp, false, 0.02,0.1, true);


	double ratio_XiSys_cut = XiSys/XiSys_uncut;
	double ratio_XiSys_mc = XiSys/nevents_mc;

	cout << "XiSys|   " <<  XiSys_uncut << "|   " <<  XiSys << "(" << ratio_XiSys_cut*100 << ")|   " << ratio_XiSys_mc*100<< endl;// << "|   " << paramxisys[2]*100 << endl;


}
コード例 #24
0
void PlotRakeBunch( const TString &sim, Int_t time, Int_t index = 0, const TString &options="") {
  
#ifdef __CINT__  
  gSystem->Load("libplasma.so");
#endif

  PlasmaGlob::Initialize();

  TString opt = options;
 
  // Palettes!
  gROOT->Macro("PlasmaPalettes.C");

  if(opt.Contains("grid")) {
    gStyle->SetPadGridX(1);
    gStyle->SetPadGridY(1);
  }
  gStyle->SetLabelFont(42,"xyz");
  gStyle->SetTextFont(62);
 

  // Load PData
  PData *pData = PData::Get(sim.Data());
  pData->LoadFileNames(time);
  if(!pData->IsInit()) return;

  Bool_t CYL = kFALSE;
  if(sim.Contains("cyl")) CYL = kTRUE; 
    
  Bool_t ThreeD = kFALSE;
  if(sim.Contains("3D")) ThreeD = kTRUE; 

  // Some plasma constants
  Double_t n0 = pData->GetPlasmaDensity();
  Double_t kp = pData->GetPlasmaK();
  Double_t skindepth = 1.;
  if(kp!=0.0) skindepth = 1/kp;
  Double_t E0 = pData->GetPlasmaE0();

  // Time in OU
  Float_t Time = pData->GetRealTime();
  // z start of the plasma in normalized units.
  Float_t zStartPlasma = pData->GetPlasmaStart()*kp;
  // z start of the beam in normalized units.
  Float_t zStartBeam = pData->GetBeamStart()*kp;
  
  opt += "comovcenter";

  // Centering time and z position:
  Double_t shiftz = pData->Shift(opt);
  TString sshiftz = Form("(x1-%f)",shiftz);

  if(opt.Contains("center")) {
    Time -= zStartPlasma;
    if(opt.Contains("comov"))      // Centers on the head of the beam.
      Time += zStartBeam;
  } 
  
  // Spatial coordinates intervals:
  Float_t x1Min = -4.3;
  Float_t x1Max = -3.9;
  Float_t x2Min = -0.5;
  Float_t x2Max =  0.5;
  Float_t x3Min = -0.5;
  Float_t x3Max =  0.5;

  // Momentum coordinates intervals:
  Float_t p1Min =  6500.01;
  Float_t p1Max =  10099.99;
  Float_t p2Min = -20.0;
  Float_t p2Max =  20.0;
  Float_t p3Min = -20.0;
  Float_t p3Max =  20.0;

  // Bining, intervals, labels, etc.
  Int_t xNbin = 200;
  Int_t yNbin = 200;

  if(sim.Contains("DR")) {
    xNbin = 200;
    yNbin = 200;
   
    // p1Min =  2200.01;
    // p1Max =  3399.99;
    // p1Min =  3500.01;
    // p1Max =  4999.99;
    p1Min =  1800.01;
    p1Max =  3999.99;

    // x1Min = -4.0;
    // x1Max = -3.2;
    x1Min = 8637.0;
    x1Max = 8639.0;
    x2Min = -0.5;
    x2Max =  0.5;
    x3Min = -0.5;
    x3Max =  0.5;
  } else if(sim.Contains("flash") && sim.Contains(".G.") ) {
    
    x1Min = -6.3;
    x1Max = -5.0;

    //p1Min =  0.001;
    p1Min =  650.001;
    p1Max =  1499.99;
    
  } else if(sim.Contains("facet_v23kA.G.A")) {
    x1Min = -7.8;
    x1Max = -7.1;

    x2Min = -1.0;
    x2Max =  1.0;
    x3Min = -1.0;
    x3Max =  1.0;
    // t=150
    p1Min =  1100.001;
    p1Max =  1999.99;
  } else if(sim.Contains("facet_v23kA.G")) {
    x1Min = -7.8;
    x1Max = -7.0;

    x2Min = -1.0;
    x2Max =  1.0;
    x3Min = -1.0;
    x3Max =  1.0;
    // t=60
     p1Min =  350.01;
     p1Max =  799.99;
    // t = 100
    // p1Min =  700.01;
    // p1Max =  1399.99;
    // t=105
    //p1Min =  800.001;
    //p1Max =  1399.99;
    // t=183
    // p1Min =  1500.001;
    // p1Max =  2499.99;
    // t=235
    // p1Min =  2000.01;
    // p1Max =  3499.99; 
    // t=310
    // p1Min =  2800.01;
    // p1Max =  4799.99; 
  }
  
  
  // Get phasespace histos
  Int_t Nspecies = pData->NSpecies();
  if(index>Nspecies-1) {
    return;
  }
  if(!pData->GetRawFileName(index)) {
    return;    
  }
  TH1F *hX1 = NULL;
  TH1F *hP1 = NULL;
  TH2F *hP1X1 = NULL;
  TH2F *hP2X2 = NULL;


  cout << Form("\n1. Getting data... ") << endl; 
  char cutString[512];
  sprintf(cutString,"TMath::Abs(q)*(%s > %.1f && %s < %.1f && x2 > %.1f && x2 < %.1f && x3 > %.1f && x3 < %.1f)",sshiftz.Data(),x1Min,sshiftz.Data(),x1Max,x2Min,x2Max,x3Min,x3Max); 
  TCut Cut = cutString;
  cout << Form("   (applied cut: \n %s)",cutString) << endl;
  TTree *tree = pData->GetTreeRaw(pData->GetRawFileName(index)->c_str(),opt);
  
  char hName[24];
  char dCommand[128];

  cout << Form("\n2. Dumping 1D histograms.. ") << endl;
  
  sprintf(hName,"hX1");
  hX1 = (TH1F*) gROOT->FindObject(hName);
  if(hX1) delete hX1;
  hX1 = new TH1F(hName,"",xNbin,x1Min,x1Max);
  sprintf(dCommand,"%s>>%s",sshiftz.Data(),hName);
  cout << Form("   - x1. ") << endl;    
  tree->Draw(dCommand,Cut,"goff");

  sprintf(hName,"hP1");
  hP1 = (TH1F*) gROOT->FindObject(hName);
  if(hP1) delete hP1;
  hP1 = new TH1F(hName,"",yNbin,p1Min,p1Max);
  sprintf(dCommand,"p1>>%s",hName);
  cout << Form("   - p1. ") << endl;    
  tree->Draw(dCommand,Cut,"goff");

  cout << Form("\n3. Dumping 2D histograms.. ") << endl;

  sprintf(hName,"hP1X1");
  hP1X1 = (TH2F*) gROOT->FindObject(hName);
  if(hP1X1) delete hP1X1;
  hP1X1 = new TH2F(hName,"",xNbin,x1Min,x1Max,yNbin,p1Min,p1Max);
  sprintf(dCommand,"p1:%s>>%s",sshiftz.Data(),hName);
  cout << Form("   - p1 vs. x1 ") << endl;    
  tree->Draw(dCommand,Cut,"goff");
  
  sprintf(hName,"hP2X2");
  hP2X2 = (TH2F*) gROOT->FindObject(hName);
  if(hP2X2) delete hP2X2;
  hP2X2 = new TH2F(hName,"",xNbin,x2Min,x2Max,yNbin,p2Min,p2Max);
  sprintf(dCommand,"p2:x2>>%s",hName);
  cout << Form("   - p2 vs. x2 ") << endl;    
  tree->Draw(dCommand,Cut,"goff");
  
  hX1->GetXaxis()->CenterTitle();
  hX1->GetYaxis()->CenterTitle();
  hX1->GetZaxis()->CenterTitle();
  hP1X1->GetXaxis()->CenterTitle();
  hP1X1->GetYaxis()->CenterTitle();
  hP1X1->GetZaxis()->CenterTitle();
  hP2X2->GetXaxis()->CenterTitle();
  hP2X2->GetYaxis()->CenterTitle();
  hP2X2->GetZaxis()->CenterTitle();
   
  // Integrated long. emittance:

  cout << Form("\n4. Calculating integrated quantities.. ") << endl;

  Double_t xmean = 0.0;
  Double_t ymean = 0.0;
  Double_t x2mean = 0.0;
  Double_t y2mean = 0.0;
  Double_t xymean = 0.0;
  Double_t Ntotal = 0.0;
  for(Int_t i=1;i<=xNbin;i++) {
    Double_t x = hP1X1->GetXaxis()->GetBinCenter(i);
    // if(x<xmin || x>xmax) continue;
    for(Int_t j=1;j<=yNbin;j++) {
      Double_t y = hP1X1->GetYaxis()->GetBinCenter(j);
      // if(y<ymin || y>ymax) continue;
      Double_t value = TMath::Abs(hP1X1->GetBinContent(i,j));
      xmean += x*value;
      ymean += y*value;
      x2mean += x*x*value;
      y2mean += y*y*value;
      xymean += x*y*value;

      Ntotal += value;
    }
  }
  
  xmean  /= Ntotal;
  ymean  /= Ntotal;
  x2mean /= Ntotal;
  y2mean /= Ntotal;
  xymean /= Ntotal;

  Double_t xrms2  = x2mean - xmean*xmean;
  Double_t yrms2  = y2mean - ymean*ymean;
  Double_t xrms   = TMath::Sqrt(xrms2);
  Double_t yrms   = TMath::Sqrt(yrms2);
  Double_t xyrms2 = xymean - xmean*ymean;

  Double_t emittance = TMath::Sqrt(xrms2*yrms2 - xyrms2*xyrms2);
  
  // cout << " xrms = " << xrms << endl;
  
  // Sliced emittance:
  // --------------------------------------------------------------------------

  cout << Form("\n5. Slicing ") << endl;


  // Bining for sliced quantities:
  // const Int_t SNbin = 7;
  // Float_t sBinLim[SNbin+1] = {-4.16,-4.14,-4.12,-4.10,-4.08,-4.06,-4.04,-4.02};
  // const Int_t SNbin = 7;
  // Float_t sBinLim[SNbin+1] = {-4.20,-4.17,-4.14,-4.12,-4.10,-4.08,-4.06,-4.00};
  // const Int_t SNbin = 8;
  // Float_t sBinLim[SNbin+1] = {-3.93,-3.87,-3.81,-3.75,-3.69,-3.63,-3.57,-3.51,-3.45};
  
  Int_t SNbin = 7;
  Float_t nsigma = 2;
  Float_t x1BinMin = -4.16;
  Float_t x1BinMax = -4.02;
  if(sim.Contains("DR")) {
    SNbin = 150; 
    nsigma = 1.4;
  } else if(sim.Contains("facet_v23kA.G.A")) {
    SNbin = 46;
    nsigma = 1;
    x1BinMin = -7.55;
    x1BinMax = -7.25;
  } else if(sim.Contains("facet_v23kA.G")) {
    SNbin = 10;
    nsigma = 1;
    x1BinMin = -7.55;
    x1BinMax = -7.15;
  }
  
  Float_t *sBinLim = new Float_t[SNbin+1];

  if(opt.Contains("rms")) {
    sBinLim[0] = xmean - nsigma*xrms;
    sBinLim[SNbin] = xmean + nsigma*xrms;
  } else {
    sBinLim[0] = x1BinMin;
    sBinLim[SNbin] = x1BinMax;
  }

  Float_t slbinSize = (sBinLim[SNbin] - sBinLim[0])/SNbin;
  
  for(Int_t i=1;i<SNbin;i++) {
    sBinLim[i] = sBinLim[i-1] + slbinSize;
  }
  
  TH1F **hP1sl = new TH1F*[SNbin];
  TH2F **hP2X2sl = new TH2F*[SNbin];

  cout << Form("\n   - Dumping in %i bins ",SNbin) << endl;

  
  for(Int_t k=0;k<SNbin;k++) {

    cout<< Form("k = %i : (x1 > %f && x1 < %f)",k,sBinLim[k],sBinLim[k+1]) << endl; 

    sprintf(hName,"hP2X2sl_%2i",k);
    hP2X2sl[k] = (TH2F*) gROOT->FindObject(hName);
    if(hP2X2sl[k]) delete hP2X2sl[k];
    hP2X2sl[k] = new TH2F(hName,"",xNbin,x2Min,x2Max,yNbin,p2Min,p2Max);

    char zCutString[128];
    sprintf(zCutString,"(%s > %f && %s < %f)",sshiftz.Data(),sBinLim[k],sshiftz.Data(),sBinLim[k+1]); 
    TCut zCut = zCutString;
    tree->Project(hName,"p2:x2",Cut + zCut);

    sprintf(hName,"hP1sl_%2i",k);
    hP1sl[k] = (TH1F*) gROOT->FindObject(hName);
    if(hP1sl[k]) delete hP1sl[k];
    hP1sl[k] = new TH1F(hName,"",yNbin,p1Min,p1Max);
    tree->Project(hName,"p1",Cut + zCut);

  }
  

  cout << Form("\n6. Calculating sliced quantities.. ") << endl;

  TGraph *gemit = NULL;
  TGraph *gYrms = NULL;
  TGraph *gErms = NULL;
  TGraph *gErmsB = NULL;
 
  Double_t * sxmean = new Double_t[SNbin];
  Double_t * symean = new Double_t[SNbin];
  Double_t * sx2mean = new Double_t[SNbin];
  Double_t * sy2mean = new Double_t[SNbin];
  Double_t * sxymean = new Double_t[SNbin];
  Double_t * sNtotal = new Double_t[SNbin];
  Double_t * sxrms2 = new Double_t[SNbin];  
  Double_t * syrms2 = new Double_t[SNbin]; 
  Double_t * sxrms = new Double_t[SNbin];  
  Double_t * syrms = new Double_t[SNbin];  
  Double_t * sxyrms2 = new Double_t[SNbin];
 
  Double_t * xbin = new Double_t[SNbin];
  Double_t * semittance = new Double_t[SNbin];

  Double_t * sNEtotal = new Double_t[SNbin]; 
  Double_t * sEmean = new Double_t[SNbin];
  Double_t * sE2mean = new Double_t[SNbin];
  Double_t * sErms = new Double_t[SNbin];

  for(Int_t k=0;k<SNbin;k++) {
    sxmean[k] = symean[k] = sx2mean[k] = sy2mean[k] = sxymean[k] 
      = sNtotal[k] = sxrms2[k] = syrms2[k] = sxrms[k] = syrms[k]
      = sxyrms2[k] = xbin[k] = semittance[k] = 0.0;
    sNEtotal[k] = sEmean[k] = sE2mean[k] = sErms[k] = 0.0;
    
    xbin[k] = (sBinLim[k] + sBinLim[k+1])/2.;
    
    for(Int_t i=1;i<=xNbin;i++) {
      Double_t x = hP2X2sl[k]->GetXaxis()->GetBinCenter(i);
      // if(x<xmin || x>xmax) continue;
      for(Int_t j=1;j<=yNbin;j++) {
	Double_t y = hP2X2sl[k]->GetYaxis()->GetBinCenter(j);
	// if(y<ymin || y>ymax) continue;
	Double_t value = TMath::Abs(hP2X2sl[k]->GetBinContent(i,j));
	sxmean[k] += x*value;
	symean[k] += y*value;
	sx2mean[k] += x*x*value;
	sy2mean[k] += y*y*value;
	sxymean[k] += x*y*value;
	
	sNtotal[k] += value;
      }	
    }
    
    for(Int_t i=1;i<=yNbin;i++) {
      Double_t y = hP1sl[k]->GetXaxis()->GetBinCenter(i);
      Double_t value = TMath::Abs(hP1sl[k]->GetBinContent(i));
      sEmean[k] += y*value;
      sE2mean[k] += y*y*value;
      sNEtotal[k] += value;
    }
    
    sxmean[k]  /= sNtotal[k];
    symean[k]  /= sNtotal[k];
    sx2mean[k] /= sNtotal[k];
    sy2mean[k] /= sNtotal[k];
    sxymean[k] /= sNtotal[k];
      
    sxrms2[k]  = sx2mean[k] - sxmean[k]*sxmean[k];
    syrms2[k]  = sy2mean[k] - symean[k]*symean[k];
    sxrms[k]   = TMath::Sqrt(sxrms2[k]);
    syrms[k]   = TMath::Sqrt(syrms2[k]);
    sxyrms2[k] = sxymean[k] - sxmean[k]*symean[k];
      
    semittance[k] = TMath::Sqrt(sxrms2[k]*syrms2[k] - sxyrms2[k]*sxyrms2[k]);

    sEmean[k]  /= sNEtotal[k];
    sE2mean[k] /= sNEtotal[k];
    sErms[k]   =  TMath::Sqrt(sE2mean[k] - sEmean[k]*sEmean[k]);
    
    
    cout << " Bunch properties: " << endl;
    cout << Form("  xMean = %7.3f   yMean = %7.3f",sxmean[k],symean[k]) << endl;
    cout << Form("  xRms  = %7.3f   yRms  = %7.3f",sxrms[k],syrms[k]) << endl;
    cout << Form("  Emittance = %7.3f",semittance[k]) << endl;

    cout << Form("  Emean = %7.3f   Erms = %7.3f",sEmean[k],sErms[k]) << endl;
    

  }

  // Charge
  Double_t dx1 = pData->GetDX(0);
  Double_t dx2 = pData->GetDX(1);
  Double_t dx3 = pData->GetDX(2);
  
  hX1->Scale(dx1*dx2*dx3);
  Double_t Charge = hX1->Integral();
  
  // Charge *= dx1*dx2*dx3;
 
  if(opt.Contains("units")) {
    Double_t dV = skindepth * skindepth * skindepth;
    Charge *= n0 * dV * (PConst::ElectronCharge/PUnits::picocoulomb);
    cout << Form(" Integrated charge (RAW) of specie %3i = %8f pC",index,Charge) << endl;
  } else {
    cout << Form(" Integrated charge (RAW) of specie %3i = %8.4f n0 * kp^-3",index,Charge) << endl;
  }
  

  // Chaning to user units: 
  // --------------------------
  
  if(opt.Contains("units") && n0) {
    
    Int_t NbinsX = hP1X1->GetNbinsX();
    Double_t xMin = skindepth * hP1X1->GetXaxis()->GetXmin() / PUnits::um;
    Double_t xMax = skindepth * hP1X1->GetXaxis()->GetXmax() / PUnits::um;
    Int_t NbinsY = hP1X1->GetNbinsY();
    Double_t yMin = hP1X1->GetYaxis()->GetXmin() * pData->GetBeamMass() / PUnits::GeV;
    Double_t yMax = hP1X1->GetYaxis()->GetXmax() * pData->GetBeamMass() / PUnits::GeV;
    hP1X1->SetBins(NbinsX,xMin,xMax,NbinsY,yMin,yMax);
    // Converting electron density
    Double_t dVb = skindepth * skindepth * skindepth;
    Double_t dX = (xMax-xMin)/NbinsX; 
    Double_t dE = (yMax-yMin)/NbinsY; 
    for(Int_t j=0;j<hP1X1->GetNbinsX();j++) {
      for(Int_t k=0;k<hP1X1->GetNbinsY();k++) {
	Double_t binValue =  fabs(hP1X1->GetBinContent(j,k) * dx1 * dx2 * dx3 * dVb * n0 *
				  (PConst::ElectronCharge/PUnits::picocoulomb));
     	//cout << Form(" value = %f",binValue) << endl;
	hP1X1->SetBinContent(j,k,binValue);
	
      }
    }
    
    if(opt.Contains("comov"))
      hP1X1->GetXaxis()->SetTitle("#zeta [#mum]");
    else
      hP1X1->GetXaxis()->SetTitle("z [#mum]");
    
    hP1X1->GetYaxis()->SetTitle("p_{z} [GeV/c]");
    
    hP1X1->GetZaxis()->SetTitle("dQ/d#zetadp_{z} [pC]");

    hP1->SetBins(NbinsY,yMin,yMax);
    hP1->GetYaxis()->SetTitle("p_{z} [GeV/c]");

    hX1->SetBins(NbinsX,xMin,xMax);
    Double_t binSize = (xMax - xMin)/NbinsX;

    Double_t dV = skindepth * skindepth * skindepth;
    Double_t  lightspeed =  PConst::c_light / (PUnits::um/PUnits::femtosecond);
    cout << Form("Speed of light = %f",lightspeed) << endl;
    hX1->Scale(TMath::Abs(n0 * dV * (PConst::ElectronCharge/PUnits::picocoulomb) * (lightspeed/binSize)));
    
    // hX1->Scale(TMath::Abs((PUnits::um/skindepth)*(PConst::ElectronCharge/PUnits::picocoulomb)*PConst::c_light));
    
    // hX1->GetYaxis()->SetTitle("I[kA]");
    hX1->GetYaxis()->SetTitle("");
    if(opt.Contains("comov"))
      hX1->GetXaxis()->SetTitle("#zeta [#mum]");
    else
      hX1->GetXaxis()->SetTitle("z [#mum]");
    
    
    xmean *= skindepth / PUnits::um;
    xrms  *= skindepth / PUnits::um;
    ymean *= pData->GetBeamMass() / PUnits::GeV;
    yrms  *= pData->GetBeamMass() / PUnits::GeV;
    
    emittance *= (skindepth / PUnits::um);
    
    for(Int_t k=0;k<SNbin;k++) {
      xbin[k] *= skindepth / PUnits::um;

      sxmean[k] *= skindepth / PUnits::um;
      sxrms[k]  *= skindepth / PUnits::um;
      symean[k] *= pData->GetBeamMass() / PUnits::MeV;
      syrms[k] *= pData->GetBeamMass() / PUnits::MeV;
      
      semittance[k] *= (skindepth / PUnits::um);

      sEmean[k] *= pData->GetBeamMass() / PUnits::GeV;
      sErms[k]  *= 100 * pData->GetBeamMass() / PUnits::GeV / ymean; //sEmean[k];
      // sErms[k]  *= pData->GetBeamMass() / PUnits::GeV;

    }

  }


  // Create the graph with the emittances:
  gemit = new TGraph(SNbin,xbin,semittance);
  gYrms = new TGraph(SNbin,xbin,sxrms);
  gErms = new TGraph(SNbin,xbin,sErms);
  
  
  // Profile energy for p1 vs x1:
  TString pname = hP1X1->GetName();
  pname += "_pfx";
  TProfile *hP1X1prof = (TProfile*) gROOT->FindObject(pname.Data());
  if(hP1X1prof) { delete hP1X1prof; hP1X1prof = NULL; }
  hP1X1prof = hP1X1->ProfileX("_pfx",1,-1,"s");

  // get the errors from the profile:
  Int_t NP1X1Bins = hP1X1prof->GetNbinsX();
  Double_t *x1bins = new Double_t[NP1X1Bins];
  Double_t *eRms   = new Double_t[NP1X1Bins];
  for(Int_t i=1;i<=hP1X1prof->GetNbinsX();i++) {
    x1bins[i] = hP1X1prof->GetBinCenter(i);
    eRms[i] = 100 * hP1X1prof->GetBinError(i) / hP1X1prof->GetBinContent(i);
  }
  gErmsB = new TGraph(NP1X1Bins,x1bins,eRms);
  
  // Vertical Energy histogram:
  // --------------------------------------------------------------------------------   
  TGraph *gP1left = NULL;
  if(hP1) {
    Double_t *yarray   = new Double_t[yNbin];
    Double_t *xarray   = new Double_t[yNbin];
    
    // This is for the right side:
    // Double_t xMax = x1Min + (x1Max-x1Min) * 0.9;
    // Double_t xMin = x1Max;
    // And this for left:
    Double_t xMin = hX1->GetXaxis()->GetXmin();
    Double_t xMax = hX1->GetXaxis()->GetXmin() + (hX1->GetXaxis()->GetXmax()
						  -hX1->GetXaxis()->GetXmin()) * 0.2;
    Double_t EneMax = hP1->GetMaximum();
    // cout << Form("  EneMax = %f ", EneMax) << endl;
 
    for(Int_t j=0; j<yNbin; j++) {
      yarray[j] = hP1->GetBinCenter(j+1);
      xarray[j] = ((xMax-xMin)/EneMax)*hP1->GetBinContent(j+1) + xMin;

      // cout << Form("  x = %f  y = %f ", xarray[j],yarray[j]) << endl;
    }

    gP1left = new TGraph(yNbin,xarray,yarray);
    gP1left->SetLineColor(PlasmaGlob::elecLine);
    gP1left->SetLineWidth(2);
    gP1left->SetFillStyle(1001);
    gP1left->SetFillColor(PlasmaGlob::elecFill);
       
  }

  

  // Plotting
  // -----------------------------------------------
    
  // Canvas setup
  // Create the canvas and the pads before the Frame loop
  // Resolution:
  Int_t sizex = 800;
  Int_t sizey = 600;
  if(opt.Contains("hres")) {
    Int_t sizex = 1600;
    Int_t sizey = 1200;    
  }
  
  TCanvas *C = new TCanvas("C1","Evolution of Injection",sizex,sizey);
  C->cd();

  // Set palette:
  PPalette * pPalette = (PPalette*) gROOT->FindObject("electron");
  pPalette->cd();

  // Float_t Max  = hP1X1->GetMaximum();
  // Float_t Min  = hP1X1->GetMinimum();
  
  // hP1X1->GetZaxis()->SetRangeUser(Min,Max); 


  // Text objects
  TPaveText *textTime = new TPaveText(0.55,0.8,0.82,0.9,"NDC");
  PlasmaGlob::SetPaveTextStyle(textTime,32); 
  textTime->SetTextColor(kGray+2);
  char ctext[128];
  if(opt.Contains("units") && pData->GetPlasmaDensity()) 
    sprintf(ctext,"z = %5.1f mm", Time * skindepth / PUnits::mm);
  else
    sprintf(ctext,"t = %5.1f #omega_{p}^{-1}",Time);
  textTime->AddText(ctext);
 
  TPaveText *textDen = new TPaveText(0.15,0.85,0.48,0.9,"NDC");
  PlasmaGlob::SetPaveTextStyle(textDen,12); 
  textDen->SetTextColor(kOrange+10);
  if(opt.Contains("units") && pData->GetPlasmaDensity())
    sprintf(ctext,"n_{0} = %5.2f x 10^{17} / cc", n0 / (1e17/PUnits::cm3));
  else if(pData->GetBeamDensity() && pData->GetPlasmaDensity())
    sprintf(ctext,"n_{b}/n_{0} = %5.2f", pData->GetBeamDensity()/n0);
  textDen->AddText(ctext);

  TPaveText *textWav = new TPaveText(0.15,0.2,0.48,0.25,"NDC");
  PlasmaGlob::SetPaveTextStyle(textWav,12); 
  textWav->SetTextColor(kGray+2);
  sprintf(ctext,"#lambda_{p} = %5.2f #mum", pData->GetPlasmaWaveLength() / PUnits::um);
  textWav->AddText(ctext);

  TPaveText *textCharge = new TPaveText(0.15,0.25,0.48,0.3,"NDC");
  PlasmaGlob::SetPaveTextStyle(textCharge,12); 
  textCharge->SetTextColor(kGray+2);
  if(opt.Contains("units") && pData->GetPlasmaDensity())
    sprintf(ctext,"Charge = %5.2f pC", Charge);
  else
    sprintf(ctext,"Charge = %5.2f n0#timeskp^{-3}", Charge);    
  textCharge->AddText(ctext);

  TPaveText *textMom = new TPaveText(0.55,0.03,0.82,0.13,"NDC");
  PlasmaGlob::SetPaveTextStyle(textMom,32); 
  textMom->SetTextColor(kGray+3);
  textMom->SetTextFont(62);
  if(opt.Contains("units") && pData->GetPlasmaDensity())
    sprintf(ctext,"#LTp_{z}#GT = %5.2f GeV/c", ymean);
  else
    sprintf(ctext,"Mom = %5.2f mc", ymean);    
  textMom->AddText(ctext);


  TPaveText *textInfo = new TPaveText(0.55,0.52,0.82,0.75,"NDC");
  PlasmaGlob::SetPaveTextStyle(textInfo,32); 
  textInfo->SetTextColor(kGray+2);
  textInfo->SetTextFont(42);
  sprintf(ctext,"Charge = %5.2f pC",Charge);
  textInfo->AddText(ctext);
  sprintf(ctext,"#LT#zeta#GT_{rms} = %5.2f #mum",xrms);
  textInfo->AddText(ctext);
  sprintf(ctext,"#LTp_{z}#GT_{rms} = %5.2f GeV/c",yrms);
  textInfo->AddText(ctext);
  // sprintf(ctext,"#epsilon_{N} = %5.2f #mum",emittance);
  // textInfo->AddText(ctext);
  
  // Setup Pad layout:
  const Int_t NFrames = 2;
  TPad **pad = new TPad*[NFrames];
  TH1F *hFrame[NFrames];

  Double_t lMargin = 0.15;
  Double_t rMargin = 0.18;
  Double_t bMargin = 0.15;
  Double_t tMargin = 0.04;
  Double_t vSpacing = 0.00; 
  Double_t hStep = (1.-lMargin-rMargin);
  Double_t vStep = (1.- bMargin - tMargin - (NFrames-1) * vSpacing) / NFrames;
  
  Float_t vposd = 0.0;
  Float_t vposu = 0.0;
  Float_t vmard = 0.0;
  Float_t vmaru = 0.0;
  Float_t vfactor = 0.0;
  Float_t hposl = 0.0;
  Float_t hposr = 1.0;
  Float_t hmarl = lMargin;
  Float_t hmarr = rMargin;
  Float_t hfactor = 1.0;
  
  // Actual Plotting!
  // ------------------------------------------------------------
  
  
  for(Int_t k=0;k<NFrames;k++) {

    // PLOTTING!
    if(k==0) {
      vposd = 0.0;
      vposu = bMargin + vStep;
      vfactor = vposu-vposd;  
      vmard = bMargin / vfactor;
      vmaru = 0.0;
    } else if(k == NFrames-1) {
      vposd = vposu + vSpacing;
      vposu = vposd + vStep + tMargin;
      vfactor = vposu-vposd;   
      vmard = 0.0;
      vmaru = tMargin / (vposu-vposd);
    } else {
      vposd = vposu + vSpacing;
      vposu = vposd + vStep; 
      vfactor = vposu-vposd;
      vmard = 0.0;
      vmaru = 0.0;
    } 
    hfactor = hposl-hposr;

    char name[16];
    sprintf(name,"pad_%i",k);
    pad[k] = new TPad(name,"",hposl,vposd,hposr,vposu);
    // // cout << Form("%f %f %f %f",hposl,vposd,hposr,vposu) << endl;
    // // cout << Form("%f %f %f %f",hmarl,vmard,hmarr,vmaru) << endl;
    pad[k]->SetLeftMargin(hmarl);
    pad[k]->SetRightMargin(hmarr);  
    pad[k]->SetBottomMargin(vmard);
    pad[k]->SetTopMargin(vmaru);
    pad[k]->SetFrameLineWidth(3);
    
    sprintf(name,"hFrame_%i",k);  
    hFrame[k] = (TH1F*) gROOT->FindObject(name);
    if(hFrame[k]) delete hFrame[k];
    hFrame[k] = (TH1F*) hX1->Clone(name);
    hFrame[k]->Reset();
    
    hFrame[k]->GetXaxis()->CenterTitle();
    hFrame[k]->GetYaxis()->CenterTitle();
    hFrame[k]->GetZaxis()->CenterTitle();
    hFrame[k]->SetLabelFont(42,"xyz");
    hFrame[k]->SetTitleFont(42,"xyz");
  
    hFrame[k]->SetNdivisions(505,"xyz");
  
    hFrame[k]->SetTickLength(0.04,"xyz");
    hFrame[k]->SetTickLength(0.04*vfactor,"y");
  
    hFrame[k]->GetYaxis()->SetLabelSize(0.04/vfactor);
    hFrame[k]->GetYaxis()->SetLabelOffset(0.02);
  
    hFrame[k]->GetYaxis()->SetTitleSize(0.05/vfactor);
    hFrame[k]->GetYaxis()->SetTitleOffset(1.2*vfactor);

    if(k==0) {  
      hFrame[k]->GetXaxis()->SetLabelSize(0.08);
      hFrame[k]->GetXaxis()->SetLabelOffset(0.02);
      hFrame[k]->GetXaxis()->SetTitleSize(0.12);
      hFrame[k]->GetXaxis()->SetTitleOffset(1.0);
    } else {
      hFrame[k]->GetXaxis()->SetLabelSize(0.0);
      hFrame[k]->GetXaxis()->SetTitleSize(0.0);
    }


  }

  // Ranges!!
  Double_t yMin =  999.9;
  Double_t yMax =  -999.9;
  for(Int_t k=0;k<SNbin;k++) {
    if(semittance[k]<yMin)
      yMin = semittance[k];
    
    if(semittance[k]>yMax)
      yMax = semittance[k];

    if(sErms[k]<yMin)
      yMin = sErms[k];
    
    if(sErms[k]>yMax)
      yMax = sErms[k];
  }

  for(Int_t k=1;k<=xNbin;k++) {
    Double_t value = hX1->GetBinContent(k);
    if(value<yMin)
      yMin = value;
    
    if(value>yMax)
      yMax = value;

  }
  
  C->cd();

  pad[1]->Draw();
  pad[1]->cd();

  if(opt.Contains("logz")) {
    gPad->SetLogz(1);
  } else {
    gPad->SetLogz(0);
  }
  
  hFrame[1]->GetYaxis()->SetRangeUser(hP1X1->GetYaxis()->GetXmin(),hP1X1->GetYaxis()->GetXmax());

  if(opt.Contains("units"))
    hFrame[1]->GetYaxis()->SetTitle("p_{z} [GeV/c]");
  
  hFrame[1]->Draw();

  gP1left->SetLineWidth(2);
  gP1left->Draw("F");
  gP1left->Draw("L");

  TLine lZmean(xmean,hP1X1->GetYaxis()->GetXmin(),xmean,hP1X1->GetYaxis()->GetXmax());
  lZmean.SetLineColor(kGray+2);
  lZmean.SetLineStyle(2);
  lZmean.Draw();

  TLine lPmean(hP1X1->GetXaxis()->GetXmin(),ymean,hP1X1->GetXaxis()->GetXmax(),ymean);
  lPmean.SetLineColor(kGray+2);
  lPmean.SetLineStyle(2);
  lPmean.Draw();


  hP1X1->GetYaxis()->SetNdivisions(503);
  hP1X1->GetZaxis()->SetNdivisions(503);
  hP1X1->GetZaxis()->SetRangeUser(0.001*hP1X1->GetMaximum(),hP1X1->GetMaximum());
  hP1X1->GetZaxis()->SetLabelSize(0.05);
  hP1X1->GetZaxis()->SetTitleSize(0.04);
  hP1X1->GetZaxis()->SetTitleFont(42);

  hP1X1->Draw("colzsame");
  // hP1X1->SetContour(20);
  // hP1X1->Draw("contzsame");
  // hP1X1prof->SetMarkerStyle(1);
  // hP1X1prof->SetLineWidth(2);
  // hP1X1prof->Draw("zsame");

  //hP1->Draw("C");
  
  gPad->Update();

  TPaletteAxis *palette = (TPaletteAxis*)hP1X1->GetListOfFunctions()->FindObject("palette");
  if(palette) {
    Float_t y1 = gPad->GetBottomMargin();
    Float_t y2 = 1 - gPad->GetTopMargin();
    Float_t x1 = 1 - gPad->GetRightMargin();
    palette->SetY2NDC(y2 - 0.04);
    palette->SetY1NDC(y1 + 0.04);
    palette->SetX1NDC(x1 + 0.01);
    palette->SetX2NDC(x1 + 0.04);
    
    palette->SetLabelFont(42);
    
    palette->SetLabelSize(0.08);
    //palette->SetLabelOffset(0.005/vfactor);
    palette->SetTitleSize(0.10);
    //    palette->SetTitleOffset(9999.0*vfactor);
    palette->SetTitleOffset(0.6);
    
    palette->SetBorderSize(2);
    palette->SetLineColor(1);
  }


  textTime->Draw();
  textInfo->Draw();
  // textCharge->Draw();
  textMom->Draw();
   
  gPad->RedrawAxis(); 

  // Bottom plot -----------------------------------------

  C->cd();

  pad[0]->Draw();
  pad[0]->cd();

  hFrame[0]->GetYaxis()->SetRangeUser(0.0,1.1*yMax);
  hFrame[0]->Draw();
    

  hX1->SetLineWidth(2);
  hX1->SetFillStyle(1001);
  hX1->SetFillColor(PlasmaGlob::elecFill);
  // hX1->SetLineColor(kBlue);
  hX1->Draw("FL same");
  //hX1->Draw("C");

  TLine lZmean2(xmean,0.0,xmean,1.1*yMax);
  lZmean2.SetLineColor(kGray+2);
  lZmean2.SetLineStyle(2);
  lZmean2.Draw();

  Int_t markerSize = 1.2; 
  Int_t lineWidth  = 2.0;   

  gYrms->SetMarkerStyle(20);
  gYrms->SetLineStyle(1);
  gYrms->SetMarkerColor(kGray+1);
  gYrms->SetMarkerSize(markerSize); 
  gYrms->SetLineColor(kGray+1);
  gYrms->SetLineWidth(lineWidth);
  gYrms->Draw("PL");
  
  // hP2X2sl[0]->Draw("colz");
  gemit->SetMarkerStyle(20);
  //  gemit->SetMarkerColor(kMagenta-2);
  gemit->SetMarkerColor(kGray+2);
  gemit->SetMarkerSize(markerSize);
  gemit->SetLineWidth(lineWidth);
  gemit->SetLineColor(kGray+2);
  gemit->Draw("PL");

  gErms->SetMarkerStyle(20);
  gErms->SetMarkerSize(markerSize);
  gErms->SetMarkerColor(kOrange+10);
  gErms->SetLineColor(kOrange+10);
  gErms->SetLineWidth(lineWidth);
  gErms->Draw("PL");


  TLegend *Leg;
  if(!sim.Contains("DR")) 
    Leg=new TLegend(0.55,0.60,1 - gPad->GetRightMargin() - 0.02,0.95);
  else
    Leg=new TLegend(gPad->GetLeftMargin() + 0.02, 1.0-gPad->GetTopMargin()-0.20,
		    gPad->GetLeftMargin() + 0.30, 1.0-gPad->GetTopMargin()-0.02);
  
  
  PlasmaGlob::SetPaveStyle(Leg);
  Leg->SetTextAlign(12);
  Leg->SetTextColor(kGray+3);
  Leg->SetTextFont(42);
  Leg->SetLineColor(1);
  Leg->SetBorderSize(0);
  Leg->SetFillColor(0);
  Leg->SetFillStyle(1001);
  Leg->SetFillStyle(0); // Hollow
 
  Leg->AddEntry(hX1  ,"Current [kA]","L");
  //  Leg->AddEntry(gErms,"Energy spread (GeV)","PL");
  Leg->AddEntry(gErms,"Energy spread [%]","PL");
  Leg->AddEntry(gemit,"Emittance [#mum]","PL");
  Leg->AddEntry(gYrms,"Bunch width [#mum]","PL");
 
  Leg->Draw();

  gPad->RedrawAxis(); 

  gPad->Update();
  

  // Print to file --------------------------------------
  
  C->cd();
  
  // Print to a file
  // Output file
  TString fOutName = Form("./%s/Plots/RakeBunch/RakeBunch",sim.Data());
  fOutName += Form("-%s_%i",sim.Data(),time);

  PlasmaGlob::imgconv(C,fOutName,opt);
  // ---------------------------------------------------------
  
}
コード例 #25
0
ファイル: savehisto.C プロジェクト: boundino/BntupleRunII
void savehisto(TString inputdata="",
                   TString inputmc="",
                   TString trgselection="",
                   TString cut="",
                   int isMC=0, int doweight=0, TString collsyst="pp",
		   float centMin=0,
                   float centMax=100,
	           TString outputfile="outHisto")
{

  collisionsystem=collsyst;
  centmin = centMin;
  centmax = centMax;
  hiBinMin = centMin*2;
  hiBinMax = centMax*2;

  isPbPb = true;
  if(collisionsystem=="pp") isPbPb = false;
  // if(!doweight) weight="1";

  TFile* inf = new TFile(inputdata.Data());
  TFile* infMC = new TFile(inputmc.Data());

  if(!isPbPb) seldata = Form("%s&&%s",trgselection.Data(),cut.Data());
  else seldata = Form("%s&&%s&&hiBin>=%f&&hiBin<=%f",trgselection.Data(),cut.Data(),hiBinMin,hiBinMax);
  selmc = Form("%s",cut.Data());  
  
  TTree* nt = (TTree*)inf->Get("ntKp");
  nt->AddFriend("ntHlt");
  nt->AddFriend("ntHi");
  nt->AddFriend("ntSkim");
  nt->AddFriend("bdtTree");

  TTree* ntGen = (TTree*)infMC->Get("ntGen");
  ntGen->AddFriend("ntHlt");
  ntGen->AddFriend("ntHi");

  TTree* ntMC = (TTree*)infMC->Get("ntKp");
  ntMC->AddFriend("ntHlt");
  ntMC->AddFriend("ntHi");
  ntMC->AddFriend("ntSkim");
  ntMC->AddFriend("bdtTree");
  ntMC->AddFriend(ntGen);

  if(!isPbPb) seldata = Form("%s&&%s",trgselection.Data(),cut.Data());
  else seldata = Form("%s&&%s&&hiBin>=%f&&hiBin<=%f",trgselection.Data(),cut.Data(),hiBinMin,hiBinMax);
  selmc = Form("%s",cut.Data());  
  
  cout<<"  -- Filling histograms"<<endl;
  cout<<"     "<<inputdata<<endl;
  cout<<"     "<<inputmc<<endl;
  for(int i=0;i<nBins;i++)
    {
      cout<<setiosflags(ios::left)<<"   - Processing ptbin "<<setw(3)<<ptBins[i]<<" "<<setw(3)<<ptBins[i+1]<<endl;
      TH1D* h = new TH1D("h","", nbinsmasshisto,minhisto,maxhisto);
      h->Sumw2();
      TH1D* hMCSignal = new TH1D("hMCSignal","",nbinsmasshisto,minhisto,maxhisto);
      hMCSignal->Sumw2();
      TH1D* hMCSwapped = new TH1D("hMCSwapped","",nbinsmasshisto,minhisto,maxhisto);
      hMCSwapped->Sumw2(); 

      if(isPbPb) nt->Project("h","Bmass",Form("%s*(%s&&Bpt>%f&&Bpt<%f&&hiBin>=%f&&hiBin<=%f)",weight.Data(),seldata.Data(),ptBins[i],ptBins[i+1],hiBinMin,hiBinMax));
      else nt->Project("h","Bmass",Form("%s*(%s&&Bpt>%f&&Bpt<%f)",weight.Data(),seldata.Data(),ptBins[i],ptBins[i+1]));
      ntMC->Project("hMCSignal","Bmass",Form("%s*(%s&&Bpt>%f&&Bpt<%f&&(Bgen==23333))",weightMC.Data(),selmc.Data(),ptBins[i],ptBins[i+1]));   
      ntMC->Project("hMCSwapped","Bmass",Form("%s*(%s&&Bpt>%f&&Bpt<%f&&(Bgen==23344))",weightMC.Data(),selmc.Data(),ptBins[i],ptBins[i+1])); 

      TFile* outf = new TFile(Form("%s/%s_%.0f_%.0f.root",outputfile.Data(),collisionsystem.Data(),ptBins[i],ptBins[i+1]),"recreate");
       
      outf->cd();
      h->Write();
      hMCSignal->Write();
      hMCSwapped->Write();
      outf->Close();
      delete h;
      delete hMCSignal;
      delete hMCSwapped;
    }

  cout<<endl;
}
コード例 #26
0
void fitDstar5pMinpt(Bool_t genmatchpoint=true)
{
  gStyle->SetTextSize(0.05);
  gStyle->SetTextFont(42);
  gStyle->SetPadRightMargin(0.043);
  gStyle->SetPadLeftMargin(0.18);
  gStyle->SetPadTopMargin(0.1);
  gStyle->SetPadBottomMargin(0.145);
  gStyle->SetTitleX(.0f);

  void clean0(TH1D* h);  
  TF1* fitDstar(TTree* nt, TTree* ntMC, Float_t ptmin, Bool_t plotgenmatch);

  TFile* infData = new TFile(infnameData5p[isData].Data());
  TFile* infMC = new TFile(infnameMC5p[isData].Data());

  TTree* ntData = (TTree*)infData->Get("ntDD0kpipipipi");
  TTree* ntMC = (TTree*)infMC->Get("ntDD0kpipipipi");
  TTree* ntGen = (TTree*)infMC->Get("ntGen");
  
  ntData->AddFriend("ntHlt");
  if(isData!=Data_MB&&isData!=Data) ntData->AddFriend("ntHi");
  ntMC->AddFriend("ntHlt");
  ntMC->AddFriend("ntHi");
  ntGen->AddFriend("ntHlt");
  ntGen->AddFriend("ntHi");

  Float_t aZero[nBins];
  for(int i=0;i<nBins;i++) aZero[i]=0;
  Float_t aPt[nBins],aPtErr[nBins],aGen[nBins],aGenErr[nBins];
  TH1F* hPt = new TH1F("hPt","",nBins,ptBinsPlus);
  TH1F* hGen = new TH1F("hGen","",nBins,ptBinsPlus);

  for(int i=0;i<nBins;i++)
    {
      TF1* fData = fitDstar(ntData,ntMC,ptBins[i],genmatchpoint);
      Float_t yieldData = fData->Integral(BINMIN,BINMAX)/BINWID;
      Float_t yieldDataErr = fData->Integral(BINMIN,BINMAX)/BINWID*fData->GetParError(0)/fData->GetParameter(0);      
      aPt[i] = yieldData;
      aPtErr[i] = yieldDataErr;
      hPt->SetBinContent(i+1,aPt[i]);
      hPt->SetBinError(i+1,aPtErr[i]);
      TH1D* hGenFill = new TH1D(Form("hGenFill_%.0f",ptBins[i]),"",1,ptBins[i],1.e+3);
      hGenFill->Sumw2();
      ntGen->Project(Form("hGenFill_%.0f",ptBins[i]),"Gpt",TCut("%s",weightmc[isData].Data())*Form("%s&&%s",selgen5p.Data(),triggerselectionmc[isData].Data()));
      aGen[i] = hGenFill->GetBinContent(1);
      aGenErr[i] = hGenFill->GetBinError(1);
      hGen->SetBinContent(i+1,aGen[i]);
      hGen->SetBinError(i+1,aGenErr[i]);
    }

  TGraphErrors* gPt = new TGraphErrors(nBins,ptBins,aPt,aZero,aPtErr);
  gPt->SetName("gPt");
  TGraphErrors* gGen = new TGraphErrors(nBins,ptBins,aGen,aZero,aGenErr);
  gGen->SetName("gGen");

  TFile* outputfile = new TFile(Form("outputfiles/output_5p_%s_Minpt.root",texData[isData].Data()),"recreate");
  outputfile->cd();
  gPt->Write();
  gGen->Write();
  hPt->Write();
  hGen->Write();
  outputfile->Close();
}
コード例 #27
0
ファイル: macro_2Dhisto.C プロジェクト: oiorio/NAAnaFW
void macro_2Dhisto(TString channel, TString njmt, TString syst, TString region, TString BDT1_name, TString BDT2_name, TString lep){
  if((lep=="electron"||lep=="electronantiiso")&& channel=="QCDMuPt20toInf") return;
  if((lep=="muonantiiso"||lep=="electronantiiso") && channel=="TT_sd") return;
  if((channel.Contains("hdamp")||channel.Contains("psq2"))&&((lep=="muonantiiso"||lep=="electronantiiso")||(syst!=""))) return;
  TFile * f=TFile::Open("trees_lumi/"+lep+"/trees_"+channel+"_"+lep+".root");
  TString treename, histoname;
  TH2F * h2 = new TH2F("h2", "h2",10,-1,1,10,-1,1);
  //  Float_t BDT1, BDT2, etajprime, mtw, w, w_nominal, var_syst; 
  gStyle->SetOptStat(0);
  TString outfilename, taglio, selection;
  selection = "BDT_"+BDT1_name+":BDT_"+BDT2_name;
  if(syst.EqualTo("jesUp")||syst.EqualTo("jesDown")||syst.EqualTo("jerUp")||syst.EqualTo("jerDown")) treename = "events_"+njmt+"_"+syst;
  else treename = "events_"+njmt;
  TTree * t =(TTree*)f->Get(treename);
  if(region=="cr") taglio = "(mtw>50 && etajprime<2.4";
  else taglio = "(mtw>50 && etajprime>2.4";
  if(lep=="electronantiiso") taglio += " &&mlb>30";
  if(syst.EqualTo("")){
    histoname = "h2D_"+njmt+"_"+channel+"_"+region;
    t->Project("h2",selection,taglio+")*w*w_nominal");
  }
  else{
    if(syst.EqualTo("jesUp")||syst.EqualTo("jesDown")||syst.EqualTo("jerUp")||syst.EqualTo("jerDown")){
      histoname = "h2D_"+njmt+"_"+channel+"_"+region+"_"+syst;
      t->Project("h2",selection,taglio+")*w*w_nominal");
    }
    else{
      histoname = "h2D_"+njmt+"_"+channel+"_"+region+"_"+syst;
      t->Project("h2",selection,taglio+")*w*"+syst);
    }
  }
  h2->SetName(histoname);
  TCanvas * c = new TCanvas( "c1"," ");
  Float_t newMargin1 = 0.13;
  Float_t newMargin2 = 0.15;
  c->SetGrid();
  c->SetTicks();
  c->SetLeftMargin  ( newMargin2 );
  c->SetBottomMargin( newMargin2 );
  c->SetRightMargin ( newMargin1 );
  c->SetTopMargin   ( newMargin1 );
  gStyle->SetPalette( 1, 0 );
  gStyle->SetPaintTextFormat( "3g" );

  h2->SetMarkerSize( 1.5 );
  h2->SetMarkerColor( 0 );
  Float_t labelSize = 0.040;
  h2->GetXaxis()->SetLabelSize( labelSize );
  h2->GetYaxis()->SetLabelSize( labelSize );
  h2->GetXaxis()->SetTitle( "BDT_"+BDT1_name );
  h2->GetYaxis()->SetTitle( "BDT_"+BDT2_name );
  //  h2->LabelsOption( "d" );
  h2->SetLabelOffset( 0.011 );// label offset on x axis    
  h2->Draw("colz"); // color pads   
  c->Update();
  // modify properties of paletteAxis
  TPaletteAxis * paletteAxis = (TPaletteAxis*)h2->GetListOfFunctions()->FindObject( "palette" );
  paletteAxis->SetLabelSize( 0.03 );
  paletteAxis->SetX1NDC( paletteAxis->GetX1NDC() + 0.02 );

  h2->Draw("textsame");  // add text
  // TMVAGlob::plot_logo( );
  c->Update();
  outfilename = "Plot/histo2D_"+lep+".root";
  TFile * fout = TFile::Open(outfilename, "UPDATE");
  h2->Write();
  c->SaveAs("Plot2D/"+histoname+"_"+lep+".pdf");
}
コード例 #28
0
void MCefficiencyCent(int isPbPb=0,TString inputmc="/data/wangj/MC2015/Dntuple/pp/revised/ntD_pp_Dzero_kpi_prompt/ntD_EvtBase_20160303_Dfinder_20160302_pp_Pythia8_prompt_D0_dPt0tkPt0p5_pthatweight.root", TString selmcgen="((GisSignal==1||GisSignal==2)&&(Gy>-1&&Gy<1))",TString selmcgenacceptance="((GisSignal==1||GisSignal==2)&&(Gy>-1&&Gy<1))&&abs(Gtk1eta)<2.0&&abs(Gtk2eta)<2.0&&Gtk1pt>2.0&&Gtk2pt>2.0", TString cut_recoonly="Dy>-1.&&Dy<1.&&Dtrk1highPurity&&Dtrk2highPurity&&Dtrk1Pt>2.0&&Dtrk2Pt>2.0&&Dtrk1PtErr/Dtrk1Pt<0.1&&Dtrk2PtErr/Dtrk2Pt<0.1&&abs(Dtrk1Eta)<2.0&&abs(Dtrk2Eta)<2.0&&Dtrk1Algo>3&&Dtrk1Algo<8&&(Dtrk1PixelHit+Dtrk1StripHit)>=11", TString cut="Dy>-1.&&Dy<1.&&Dtrk1highPurity&&Dtrk2highPurity&&Dtrk1Pt>2.0&&Dtrk2Pt>2.0&&(DsvpvDistance/DsvpvDisErr)>3.5&&(DlxyBS/DlxyBSErr)>1.5&&Dchi2cl>0.05&&Dalpha<0.12&&Dtrk1PtErr/Dtrk1Pt<0.1&&Dtrk2PtErr/Dtrk2Pt<0.1&&abs(Dtrk1Eta)<2.0&&abs(Dtrk2Eta)<2.0&&Dtrk1Algo>3&&Dtrk1Algo<8&&Dtrk2Algo>3&&Dtrk2Algo<8&&(Dtrk1PixelHit+Dtrk1StripHit)>=11&&(Dtrk1Chi2ndf/(Dtrk1nStripLayer+Dtrk1nPixelLayer)<0.15)&&(Dtrk2Chi2ndf/(Dtrk2nStripLayer+Dtrk2nPixelLayer)<0.15)",TString label="PP",TString outputfile="test", int useweight=1,Float_t centmin=0., Float_t centmax=100.)
{ 
 
  hiBinMin = centmin*2;
  hiBinMax = centmax*2;
  centMin = centmin;
  centMax = centmax;
  
  if(isPbPb==1)
    {
      selmcgen = selmcgen+Form("&&hiBin>=%f&&hiBin<=%f",hiBinMin,hiBinMax);
      selmcgenacceptance=selmcgenacceptance+Form("&&hiBin>=%f&&hiBin<=%f",hiBinMin,hiBinMax);
      cut_recoonly=cut_recoonly+Form("&&hiBin>=%f&&hiBin<=%f",hiBinMin,hiBinMax);
      cut=cut+Form("&&hiBin>=%f&&hiBin<=%f",hiBinMin,hiBinMax);
    }

     std::cout<<"selmcgen="<<selmcgen<<std::endl;
     std::cout<<"selmcgenacceptance="<<selmcgenacceptance<<std::endl;
     std::cout<<"cut_recoonly"<<cut_recoonly<<std::endl;
     std::cout<<"cut="<<cut<<std::endl;

   std::cout<<"option="<<useweight<<std::endl;
  gStyle->SetOptTitle(0);
  gStyle->SetOptStat(0);
  gStyle->SetEndErrorSize(0);
  gStyle->SetMarkerStyle(20);
 
  TFile* infMC = new TFile(inputmc.Data());
  TTree* ntMC = (TTree*)infMC->Get("ntKp");
  TTree* ntGen = (TTree*)infMC->Get("ntGen");
  TTree* ntSkim = (TTree*)infMC->Get("ntSkim");
  TTree* ntmvaTree = (TTree*)infMC->Get("mvaTree");
  TTree* ntHlt = (TTree*)infMC->Get("ntHlt");

  ntMC->AddFriend(ntmvaTree);
  ntMC->AddFriend(ntGen);
  ntMC->AddFriend(ntSkim);
  ntMC->AddFriend(ntHlt);

  TTree* nthi = (TTree*)infMC->Get("ntHi");
  ntGen->AddFriend(nthi);
  ntGen->AddFriend(ntSkim);
  ntGen->AddFriend(ntHlt);
  nthi->AddFriend(ntMC);
  ntMC->AddFriend(nthi);

  // optimal weigths
  TCut weighpthat = "1";
  TCut weightGpt = "1";
  TCut weightBgenpt = "1";
  TCut weightHiBin = "1";
  if(useweight==0) {
    weightfunctiongen="1";
    weightfunctionreco="1";
    weighpthat = "pthatweight";
    weightGpt = "(pow(10,-0.094152+0.008102*Gpt+Gpt*Gpt*0.000171+Gpt*Gpt*Gpt*-0.000005+Gpt*Gpt*Gpt*Gpt*-0.000000+Gpt*Gpt*Gpt*Gpt*Gpt*0.000000))";
    weightBgenpt = "(pow(10,-0.094152+0.008102*Bgenpt+Bgenpt*Bgenpt*0.000171+Bgenpt*Bgenpt*Bgenpt*-0.000005+Bgenpt*Bgenpt*Bgenpt*Bgenpt*-0.000000+Bgenpt*Bgenpt*Bgenpt*Bgenpt*Bgenpt*0.000000))";
    }
  
  if(useweight==1) {
    weightfunctiongen="6.08582+hiBin*(-0.155739)+hiBin*hiBin*(0.00149946)+hiBin*hiBin*hiBin*(-6.41629e-06)+hiBin*hiBin*hiBin*hiBin*(1.02726e-08)";
    weightfunctionreco="6.08582+hiBin*(-0.155739)+hiBin*hiBin*(0.00149946)+hiBin*hiBin*hiBin*(-6.41629e-06)+hiBin*hiBin*hiBin*hiBin*(1.02726e-08)";
    weighpthat = "pthatweight";
    weightGpt = "(pow(10,-0.107832+0.010248*Gpt+Gpt*Gpt*0.000079+Gpt*Gpt*Gpt*-0.000003+Gpt*Gpt*Gpt*Gpt*-0.000000+Gpt*Gpt*Gpt*Gpt*Gpt*0.000000))";
    weightBgenpt = "(pow(10,-0.107832+0.010248*Bgenpt+Bgenpt*Bgenpt*0.000079+Bgenpt*Bgenpt*Bgenpt*-0.000003+Bgenpt*Bgenpt*Bgenpt*Bgenpt*-0.000000+Bgenpt*Bgenpt*Bgenpt*Bgenpt*Bgenpt*0.000000))";
    weightHiBin = "(6.08582+hiBin*(-0.155739)+hiBin*hiBin*(0.00149946)+hiBin*hiBin*hiBin*(-6.41629e-06)+hiBin*hiBin*hiBin*hiBin*(1.02726e-08))";
    }

  std::cout<<"fit function parameters="<<weightfunctiongen<<std::endl;

  TH1D* hPtMC = new TH1D("hPtMC","",_nBins,_ptBins);
  TH1D* hPtMCrecoonly = new TH1D("hPtMCrecoonly","",_nBins,_ptBins);
  TH1D* hPtGen = new TH1D("hPtGen","",_nBins,_ptBins);
  TH1D* hPtGenAcc = new TH1D("hPtGenAcc","",_nBins,_ptBins);
  TH1D* hPtGenAccWeighted = new TH1D("hPtGenAccWeighted","",_nBins,_ptBins);
  TH1D* hPthat = new TH1D("hPthat","",100,0,500);
  TH1D* hPthatweight = new TH1D("hPthatweight","",100,0,500);

  //ntMC->Project("hPtMC","hiBin",TCut(weightfunctionreco)*(TCut(cut.Data())&&"(Bgen==23333)"));
  ntMC->Project("hPtMC","hiBin",TCut(weighpthat)*TCut(weightBgenpt)*TCut(weightHiBin)*(TCut(cut.Data())&&"(Bgen==23333)"));
  divideBinWidth(hPtMC);
  //ntMC->Project("hPtMCrecoonly","hiBin",TCut(weightfunctionreco)*(TCut(cut_recoonly.Data())&&"(Bgen==23333)"));
  ntMC->Project("hPtMCrecoonly","hiBin",TCut(weighpthat)*TCut(weightBgenpt)*TCut(weightHiBin)*(TCut(cut_recoonly.Data())&&"(Bgen==23333)"));
  divideBinWidth(hPtMCrecoonly);
  //ntGen->Project("hPtGen","hiBin",(TCut(selmcgen.Data())));
  ntGen->Project("hPtGen","hiBin",TCut(weighpthat)*TCut(weightGpt)*(TCut(selmcgen.Data())));
  divideBinWidth(hPtGen);
  //ntGen->Project("hPtGenAcc","hiBin",(TCut(selmcgenacceptance.Data())));
  ntGen->Project("hPtGenAcc","hiBin",TCut(weighpthat)*TCut(weightGpt)*(TCut(selmcgenacceptance.Data())));
  divideBinWidth(hPtGenAcc);
  //ntGen->Project("hPtGenAccWeighted","hiBin",TCut(weightfunctiongen)*(TCut(selmcgenacceptance.Data())));
  ntGen->Project("hPtGenAccWeighted","hiBin",TCut(weighpthat)*TCut(weightGpt)*TCut(weightHiBin)*(TCut(selmcgenacceptance.Data())));
  divideBinWidth(hPtGenAccWeighted);

  ntMC->Project("hPthat","pthat","1");
  ntMC->Project("hPthatweight","pthat",TCut("1"));

  hPtMC->Sumw2();
  hPtGenAcc->Sumw2();
  hPtMCrecoonly->Sumw2();
  //Acceptance
  TH1D* hEffAcc = (TH1D*)hPtGenAcc->Clone("hEffAcc");
  hEffAcc->Sumw2();
  hEffAcc->Divide(hEffAcc,hPtGen,1,1,"b");
  //Selection
  TH1D* hEffSelection = (TH1D*)hPtMC->Clone("hEffSelection");
  hEffSelection->Sumw2();
  hEffSelection->Divide(hEffSelection,hPtGenAccWeighted,1,1,"b");
  //Acc * Eff (one shot)
  TH1D* hEffReco = (TH1D*)hPtMCrecoonly->Clone("hEffReco");
  hEffReco->Sumw2();
  hEffReco->Divide(hEffReco,hPtGen,1,1,"b");
  //Acc * Eff
  TH1D* hEff = (TH1D*)hEffSelection->Clone("hEff");
  hEff->Sumw2();
  //hEff->Divide(hPtMC,hPtGen,1,1,"");
  hEff->Multiply(hEff,hEffAcc,1,1);

  TH2F* hemptyEff=new TH2F("hemptyEff","",50,_ptBins[0]-5.,_ptBins[_nBins]+5.,10.,0,1.0);  
  hemptyEff->GetXaxis()->CenterTitle();
  hemptyEff->GetYaxis()->CenterTitle();
  //hemptyEff->GetYaxis()->SetTitle("acceptance x #epsilon_{reco} x #epsilon_{sel} ");
  hemptyEff->GetYaxis()->SetTitle("#alpha x #epsilon");
  hemptyEff->GetXaxis()->SetTitle("Centrality");
  hemptyEff->GetXaxis()->SetTitleOffset(0.9);
  hemptyEff->GetYaxis()->SetTitleOffset(0.95);
  hemptyEff->GetXaxis()->SetTitleSize(0.05);
  hemptyEff->GetYaxis()->SetTitleSize(0.05);
  hemptyEff->GetXaxis()->SetTitleFont(42);
  hemptyEff->GetYaxis()->SetTitleFont(42);
  hemptyEff->GetXaxis()->SetLabelFont(42);
  hemptyEff->GetYaxis()->SetLabelFont(42);
  hemptyEff->GetXaxis()->SetLabelSize(0.035);
  hemptyEff->GetYaxis()->SetLabelSize(0.035);  
  hemptyEff->SetMaximum(2);
  hemptyEff->SetMinimum(0.);
  hemptyEff->Draw();

  TH2F* hemptyEffAcc=(TH2F*)hemptyEff->Clone("hemptyEffAcc");
  TH2F* hemptyEffReco=(TH2F*)hemptyEff->Clone("hemptyEffReco");
  TH2F* hemptyEffSelection=(TH2F*)hemptyEff->Clone("hemptyEffSelection");
 

  TCanvas*canvasEff=new TCanvas("canvasEff","canvasEff",1000.,500);
  canvasEff->Divide(2,1);
  canvasEff->cd(1);
  
  hemptyEffAcc->SetYTitle("#alpha");
  hemptyEffAcc->Draw();
  hEffAcc->Draw("same");
  canvasEff->cd(2);
  hemptyEff->Draw();
  hEff->Draw("same");
  canvasEff->SaveAs(Form("plotEff/canvasEff_study%s_Cent.pdf",Form(label.Data())));
  
  TH2F* hemptyPthat=new TH2F("hemptyPthat","",50,0.,500.,10,1e-5,1e9);  
  hemptyPthat->GetXaxis()->CenterTitle();
  hemptyPthat->GetYaxis()->CenterTitle();
  hemptyPthat->GetYaxis()->SetTitle("Entries");
  hemptyPthat->GetXaxis()->SetTitle("pthat");
  hemptyPthat->GetXaxis()->SetTitleOffset(0.9);
  hemptyPthat->GetYaxis()->SetTitleOffset(0.95);
  hemptyPthat->GetXaxis()->SetTitleSize(0.05);
  hemptyPthat->GetYaxis()->SetTitleSize(0.05);
  hemptyPthat->GetXaxis()->SetTitleFont(42);
  hemptyPthat->GetYaxis()->SetTitleFont(42);
  hemptyPthat->GetXaxis()->SetLabelFont(42);
  hemptyPthat->GetYaxis()->SetLabelFont(42);
  hemptyPthat->GetXaxis()->SetLabelSize(0.035);
  hemptyPthat->GetYaxis()->SetLabelSize(0.035);  
  hemptyPthat->SetMaximum(2);
  hemptyPthat->SetMinimum(0.);


  TH2F* hemptySpectra=new TH2F("hemptySpectra","",50,0.,130.,10,1,1e5);  
  hemptySpectra->GetXaxis()->CenterTitle();
  hemptySpectra->GetYaxis()->CenterTitle();
  hemptySpectra->GetYaxis()->SetTitle("Entries");
  hemptySpectra->GetXaxis()->SetTitle("Centrality");
  hemptySpectra->GetXaxis()->SetTitleOffset(0.9);
  hemptySpectra->GetYaxis()->SetTitleOffset(0.95);
  hemptySpectra->GetXaxis()->SetTitleSize(0.05);
  hemptySpectra->GetYaxis()->SetTitleSize(0.05);
  hemptySpectra->GetXaxis()->SetTitleFont(42);
  hemptySpectra->GetYaxis()->SetTitleFont(42);
  hemptySpectra->GetXaxis()->SetLabelFont(42);
  hemptySpectra->GetYaxis()->SetLabelFont(42);
  hemptySpectra->GetXaxis()->SetLabelSize(0.035);
  hemptySpectra->GetYaxis()->SetLabelSize(0.035);  

  TH2F* hemptyPthatWeighted=(TH2F*)hemptyPthat->Clone("hemptyPthatWeighted");
  hemptyPthatWeighted->GetXaxis()->SetTitle("pthat reweighted");
  
  TCanvas*canvasPthat=new TCanvas("canvasPthat","canvasPthat",1000.,500);
  canvasPthat->Divide(2,1);
  canvasPthat->cd(1);
  gPad->SetLogy();
  hemptyPthat->Draw("same");
  hPthat->Draw("same");
  canvasPthat->cd(2);
  gPad->SetLogy();
  hemptyPthatWeighted->Draw();
  hPthatweight->Draw("same");
  canvasPthat->SaveAs(Form("plotEff/canvasPthat_%s_Cent.pdf",Form(label.Data())));
  
  TCanvas*canvasSpectra=new TCanvas("canvasSpectra","canvasSpectra",1000.,500);
  canvasSpectra->Divide(2,1);
  canvasSpectra->cd(1);
  gPad->SetLogy();
  hemptySpectra->Draw();
  hPtMC->Draw("same");
  canvasSpectra->cd(2);
  gPad->SetLogy();
  hemptySpectra->Draw();
  hPtGen->Draw("same");
  canvasSpectra->SaveAs(Form("plotEff/canvasSpectra_%s_Cent.pdf",Form(label.Data())));

  //### 1D histogram
  //hEff = hPtMC / hPtGen
  //hEffReco = hPtMCrecoonly / hPtGen
  //hEffAcc = hPtGenAcc / hPtGen
  //hEffSelection = hPtMC / hPtMCrecoonly
 
/*
  ntMC->Project("hPtMC","hiBin",TCut(weightfunctionreco)*(TCut(cut.Data())&&"(Bgen==23333)"));
  ntMC->Project("hPtMCrecoonly","hiBin",TCut(weightfunctionreco)*(TCut(cut_recoonly.Data())&&"(Bgen==23333)"));
  ntGen->Project("hPtGen","hiBin",TCut(weightfunctiongen)*(TCut(selmcgen.Data())));
  ntGen->Project("hPtGenAcc","hiBin",TCut(weightfunctiongen)*(TCut(selmcgenacceptance.Data())));
*/  
  TCanvas*canvas1D=new TCanvas("canvas1D","",600,600);
  canvas1D->cd();
  gPad->SetLogy();
  hemptySpectra->SetYTitle("Entries of hPtMC");
  hemptySpectra->Draw(); 
  hPtMC->Draw("same");
  canvas1D->SaveAs(Form("plotEff/canvas1DhPtMC_%s_Cent.pdf",Form(label.Data())));
  canvas1D->Clear();

  canvas1D=new TCanvas("canvas1D","",600,600);
  canvas1D->cd();
  gPad->SetLogy();
  hemptySpectra->SetYTitle("Entries of hPtMCrecoonly");
  hemptySpectra->Draw(); 
  hPtMCrecoonly->Draw("same");
  canvas1D->SaveAs(Form("plotEff/canvas1DhPtMCrecoonly_%s_Cent.pdf",Form(label.Data())));
  canvas1D->Clear();

  canvas1D=new TCanvas("canvas1D","",600,600);
  canvas1D->cd();
  gPad->SetLogy();
  hemptySpectra->SetYTitle("Entries of hPtGen");
  hemptySpectra->Draw(); 
  hPtGen->Draw("same");
  canvas1D->SaveAs(Form("plotEff/canvas1DhPtGen_%s_Cent.pdf",Form(label.Data())));
  canvas1D->Clear();

  canvas1D=new TCanvas("canvas1D","",600,600);
  canvas1D->cd();
  gPad->SetLogy();
  hemptySpectra->SetYTitle("Entries of hPtGenAcc");
  hemptySpectra->Draw(); 
  hPtGenAcc->Draw("same");
  canvas1D->SaveAs(Form("plotEff/canvas1DhPtGenAcc_%s_Cent.pdf",Form(label.Data())));
  canvas1D->Clear();

  canvas1D=new TCanvas("canvas1D","",600,600);
  canvas1D->cd();
  gPad->SetLogy(0);
  hemptyEff->SetYTitle("hPtMC / hPtGen");
  hemptyEff->Draw(); 
  hEff->Draw("same");
  canvas1D->SaveAs(Form("plotEff/canvas1DhEff_%s_Cent.pdf",Form(label.Data())));
  canvas1D->Clear();

  canvas1D=new TCanvas("canvas1D","",600,600);
  canvas1D->cd();
  hemptyEff->SetYTitle("hPtMCrecoonly / hPtGen");
  hemptyEff->Draw(); 
  hEffReco->Draw("same");
  canvas1D->SaveAs(Form("plotEff/canvas1DhEffReco_%s_Cent.pdf",Form(label.Data())));
  canvas1D->Clear();

  canvas1D=new TCanvas("canvas1D","",600,600);
  canvas1D->cd();
  hemptyEff->SetYTitle("hPtGenAcc / hPtGen");
  hemptyEff->Draw(); 
  hEffAcc->Draw("same");
  canvas1D->SaveAs(Form("plotEff/canvas1DhEffAcc_%s_Cent.pdf",Form(label.Data())));
  canvas1D->Clear();

  canvas1D=new TCanvas("canvas1D","",600,600);
  canvas1D->cd();
  hemptyEff->SetYTitle("hPtMC / hPtGenAcc");
  hemptyEff->Draw(); 
  hEffSelection->Draw("same");
  canvas1D->SaveAs(Form("plotEff/canvas1DhEffSelection_%s_Cent.pdf",Form(label.Data())));
  canvas1D->Clear();

  gStyle->SetPalette(55);
  TCanvas* canvas2D=new TCanvas("canvas2D","",600,600);

  TFile *fout=new TFile(outputfile.Data(),"recreate");
  fout->cd();
  hPtGen->Write();
  hEffAcc->Write();
  hEffReco->Write();
  hEffSelection->Write();
  hEff->Write();
  hPtMC->Write();
  fout->Close();  

}
コード例 #29
0
ファイル: plotVariables.C プロジェクト: boundino/Dntuple
void plot(TString var, TString varlatex, TString varname, Int_t nbins, Double_t vmin, Double_t vmax)
{
  cout<<"---- Processing - "<<var<<endl;
  cout<<"  -- Fill histograms"<<endl;
  TFile* ifBkg = new TFile(infnameBkg[isChannel]);
  TTree* ntBkg = (TTree*)ifBkg->Get(texNtuple[isChannel]);
  ntBkg->AddFriend("ntHlt");
  TFile* ifSgl = new TFile(infnameSgl[isChannel]);
  TTree* ntSgl = (TTree*)ifSgl->Get(texNtuple[isChannel]);
  ntSgl->AddFriend("ntHlt");
  ntSgl->AddFriend("ntHi");

  TH1D* hBkg = new TH1D(Form("hBkg_%s",varname.Data()),"",nbins,vmin,vmax);
  TH1D* hSgl = new TH1D(Form("hSgl_%s",varname.Data()),"",nbins,vmin,vmax);

  ntBkg->Project(Form("hBkg_%s",varname.Data()),var,Form("%s&&%s",selTriggerBkg[isChannel].Data(),selBkg[isChannel].Data()));
  ntSgl->Project(Form("hSgl_%s",varname.Data()),var,TCut(weight[isChannel])*Form("%s&&%s",selTriggerSgl[isChannel].Data(),selSgl[isChannel].Data()));

  cout<<"  -- Calculate normalization"<<endl;
  Double_t normBkg=0,normSgl=0;
  //normBkg = hBkg->GetEntries();
  //normSgl = hSgl->GetEntries();
  normBkg = hBkg->Integral(vmin,vmax);
  normSgl = hSgl->Integral(vmin,vmax);
  cout<<"     normBkg: "<<normBkg<<" ;   normSgl: "<<normSgl<<endl;

  cout<<"  -- Normalize histograms"<<endl;
  hBkg->Scale(1./normBkg);
  hSgl->Scale(1./normSgl); 

  cout<<"  -- Plot"<<endl;
  hBkg->SetXTitle(varlatex);
  hBkg->SetYTitle("#Probability");
  hBkg->SetTitleOffset(1.5,"Y");
  Double_t hisMax = (hBkg->GetMaximum()>hSgl->GetMaximum())?hBkg->GetMaximum():hSgl->GetMaximum();
  hBkg->SetMaximum(hisMax*1.2);

  hBkg->SetLineColor(kBlue+1);
  hBkg->SetFillStyle(1001);
  hBkg->SetFillColor(kBlue-9);
  hBkg->SetLineWidth(3);
  hBkg->SetStats(0);

  TH1D* hSglplot = new TH1D(Form("hSglplot_%s",varname.Data()),"",nbins,vmin,vmax);
  for(int ib=0;ib<nbins;ib++) hSglplot->SetBinContent(ib+1,hSgl->GetBinContent(ib+1));
  hSglplot->SetLineColor(kRed);
  hSglplot->SetFillStyle(3004);
  hSglplot->SetFillColor(kRed);
  hSglplot->SetLineWidth(3);
  hSglplot->SetStats(0);

  TCanvas* c = new TCanvas(Form("c_%s",varname.Data()),"",600,600);
  hBkg->Draw();
  hSglplot->Draw("same");

  cout<<"  -- Plot legends"<<endl;
  TLatex* tex = new TLatex(0.18,0.935,Form("5.02TeV %s",texPP[isChannel].Data()));
  tex->SetNDC();
  tex->SetTextFont(42);
  tex->SetTextSize(0.055);
  tex->Draw();
  TLatex* texp;
  texp = new TLatex(0.68,0.935,texDecay[isChannel]);
  texp->SetNDC();
  texp->SetTextFont(42);
  texp->SetTextSize(0.055);
  texp->Draw();
  TLegend* leg = new TLegend(0.56,0.70,0.86,0.86);
  leg->AddEntry(hBkg,"Background","f");
  leg->AddEntry(hSglplot,"Signal","f");
  leg->SetBorderSize(0);
  leg->SetFillStyle(0);
  leg->Draw("same");

  cout<<"  -- Save plots"<<endl;
  c->SaveAs(Form("plots/%s_%s/c_%s.pdf",texPP[isChannel].Data(),texNtuple[isChannel].Data(),varname.Data()));
  cout<<endl;
}
コード例 #30
0
void MCDataComparisonProject(TString inputdata="/data/dmeson2015/DataDntuple/nt_20160112_DfinderData_pp_20160111_dPt0tkPt1_D0Dstar3p5p_DCSJSON_v2.root", TString inputmc="/afs/cern.ch/work/w/wangj/public/Dmeson/ntD_20151110_DfinderMC_20151110_EvtMatching_Pythia_D0pt15p0_Pthat15_TuneZ2_5020GeV_GENSIM_75x_1015_20151110_ppGlobaTrackingPPmenuHFlowpuv11_MBseed_twang-Pythia_1107.root", TString trgselection="((HLT_DmesonPPTrackingGlobal_Dpt15_v1&&Dpt>25&&Dpt<40)||(HLT_DmesonPPTrackingGlobal_Dpt30_v1&&Dpt>40&&Dpt<60)||(HLT_DmesonPPTrackingGlobal_Dpt50_v1&&Dpt>60))",  TString cut="Dy>-1.&&Dy<1.&&(Dtrk1highPurity&&Dtrk2highPurity)&&(DsvpvDistance/DsvpvDisErr)>3.5&&Dchi2cl>0.05&&Dalpha<0.12&&Dtrk1Pt>1.5&&Dtrk2Pt>1.5", TString selmcgen="((GisSignal==1||GisSignal==2)&&(Gy>-1&&Gy<1))", int isMC=0, Double_t luminosity=26., int doweight=0, TString collsyst="PbPb", TString outputfile="mytest.root")
{

	//inputdata="/data/yjlee/dmeson/2015/trigger/mb.root";
	
	//inputmc="/data/wangj/MC2015/Dntuple/pp/ntD_pp_Dzero_kpi/ntD_EvtBase_20160203_Dfinder_20160201_pp_Pythia8_prompt_D0_dPt0tkPt0p5_pthatweight.root";
	//inputmc="/data/wangj/MC2015/Dntuple/pp/ntD_pp_Dzero_kpi_promptNnonprompt/ntD_EvtBase_20160216_Dfinder_20160201_pp_Pythia8_promptNnonprompt_D0_dPt0tkPt0p5_pthatweight.root";
	inputmc="/data/wangj/MC2015/Dntuple/pp/ntD_pp_Dzero_kpi_promptNnonprompt/ntD_EvtBase_20160216_Dfinder_20160201_pp_Pythia8_promptNnonprompt_D0_dPt0tkPt0p5_pthatweight_skim_20160224.root";
	//skim
	//inputdata="/data/dmeson2015/DataDntuple/nt_20160112_DfinderData_pp_20160111_dPt0tkPt1_D0Dstar3p5p_DCSJSON_v2.root";
	inputdata="/data/wangj/Data2015/Dntuple/pp/nt_20160112_DfinderData_pp_20160111_dPt0tkPt1_D0Dstar3p5p_DCSJSON_v2_skim_20160224.root";
	
	trgselection="((HLT_DmesonPPTrackingGlobal_Dpt15_v1&&Dpt>15&&Dpt<40)||(HLT_DmesonPPTrackingGlobal_Dpt30_v1&&Dpt>40&&Dpt<60)||(HLT_DmesonPPTrackingGlobal_Dpt50_v1&&Dpt>60))";
	//cut="Dy>-1.&&Dy<1.&&(Dtrk1highPurity&&Dtrk2highPurity)&&(DsvpvDistance/DsvpvDisErr)>3.5&&Dchi2cl>0.05&&Dalpha<0.12&&Dtrk1Pt>1.5&&Dtrk2Pt>1.5";
//	cut="Dy>-1.&&Dy<1.&&Dtrk1highPurity&&Dtrk2highPurity&&Dtrk1Pt>2.0&&Dtrk2Pt>2.0&&(DsvpvDistance/DsvpvDisErr)>3.5&&(DlxyBS/DlxyBSErr)>1.5&&Dchi2cl>0.05&&Dalpha<0.12&&Dtrk1PtErr/Dtrk1Pt<0.1&&Dtrk2PtErr/Dtrk2Pt<0.1&&abs(Dtrk1Eta)<2.0&&abs(Dtrk2Eta)<2.0&&Dtrk1Algo>3&&Dtrk1Algo<8&&Dtrk2Algo>3&&Dtrk2Algo<8&&(Dtrk1PixelHit+Dtrk1StripHit)>=11&&(Dtrk1Chi2ndf/(Dtrk1nStripLayer+Dtrk1nPixelLayer)<0.15)&&(Dtrk2Chi2ndf/(Dtrk2nStripLayer+Dtrk2nPixelLayer)<0.15)";
//	cut="Dy>-1.&&Dy<1.&&Dtrk1highPurity&&Dtrk2highPurity&&Dtrk1Pt>2.0&&Dtrk2Pt>2.0&&(DsvpvDistance/DsvpvDisErr)>3.5&&(DlxyBS/DlxyBSErr)>1.5&&Dchi2cl>0.05&&Dalpha<0.12&&Dtrk1PtErr/Dtrk1Pt<0.1&&Dtrk2PtErr/Dtrk2Pt<0.1&&abs(Dtrk1Eta)<2.0&&abs(Dtrk2Eta)<2.0&&Dtrk1Algo>3&&Dtrk1Algo<8&&Dtrk2Algo>3&&Dtrk2Algo<8&&(Dtrk1PixelHit+Dtrk1StripHit)>=11&&(Dtrk1Chi2ndf/(Dtrk1nStripLayer+Dtrk1nPixelLayer)<0.15)&&(Dtrk2Chi2ndf/(Dtrk2nStripLayer+Dtrk2nPixelLayer)<0.15)&&(Dpt)>15";
	cut="Dy>-1.&&Dy<1.&&Dtrk1highPurity&&Dtrk2highPurity&&Dtrk1Pt>2.0&&Dtrk2Pt>2.0&&(DsvpvDistance/DsvpvDisErr)>3.5&&(DlxyBS/DlxyBSErr)>1.5&&Dchi2cl>0.05&&Dalpha<0.12&&Dtrk1PtErr/Dtrk1Pt<0.1&&Dtrk2PtErr/Dtrk2Pt<0.1&&abs(Dtrk1Eta)<2.0&&abs(Dtrk2Eta)<2.0&&Dtrk1Algo>3&&Dtrk1Algo<8&&Dtrk2Algo>3&&Dtrk2Algo<8&&(Dtrk1PixelHit+Dtrk1StripHit)>=11&&(Dtrk1Chi2ndf/(Dtrk1nStripLayer+Dtrk1nPixelLayer)<0.15)&&(Dtrk2Chi2ndf/(Dtrk2nStripLayer+Dtrk2nPixelLayer)<0.15)&&(Dpt)>15&&(Dpt)<40";
//	cut="Dy>-1.&&Dy<1.&&Dtrk1highPurity&&Dtrk2highPurity&&Dtrk1Pt>2.0&&Dtrk2Pt>2.0&&(DsvpvDistance/DsvpvDisErr)>3.5&&(DlxyBS/DlxyBSErr)>1.5&&Dchi2cl>0.05&&Dalpha<0.12&&Dtrk1PtErr/Dtrk1Pt<0.1&&Dtrk2PtErr/Dtrk2Pt<0.1&&abs(Dtrk1Eta)<2.0&&abs(Dtrk2Eta)<2.0&&Dtrk1Algo>3&&Dtrk1Algo<8&&Dtrk2Algo>3&&Dtrk2Algo<8&&(Dtrk1PixelHit+Dtrk1StripHit)>=11&&(Dtrk1Chi2ndf/(Dtrk1nStripLayer+Dtrk1nPixelLayer)<0.15)&&(Dtrk2Chi2ndf/(Dtrk2nStripLayer+Dtrk2nPixelLayer)<0.15)&&(Dpt)>30&&(Dpt)<50";
	selmcgen="((GisSignal==1||GisSignal==2)&&(Gy>-1&&Gy<1))";
	isMC=0;
	luminosity=26.31;
	doweight=1;
	collsyst="PP";
	outputfile="hPtSpectrumDzeroPP.root";

	collisionsystem=collsyst;
	seldata = Form("%s&&%s",trgselection.Data(),cut.Data());
	//seldata = Form("%s",cut.Data());
	selmc = Form("%s",cut.Data());
	
	gStyle->SetTextSize(0.05);
	gStyle->SetTextFont(42);
	gStyle->SetPadRightMargin(0.043);
	gStyle->SetPadLeftMargin(0.18);
	gStyle->SetPadTopMargin(0.1);
	gStyle->SetPadBottomMargin(0.145);
	gStyle->SetTitleX(.0f);

	if(!doweight) weight="1";
	TFile* inf = new TFile(inputdata.Data());
	TFile* infMC = new TFile(inputmc.Data());
	
	TTree* nt = (TTree*) inf->Get("ntDkpi");
	TTree* HltTree = (TTree*) inf->Get("ntHlt");
	HltTree->AddFriend(nt);
	nt->AddFriend(HltTree);
	
	TTree* ntMC = (TTree*)infMC->Get("ntDkpi");
	TTree* ntGen = (TTree*)infMC->Get("ntGen");
	TTree* ntHi = (TTree*)infMC->Get("ntHi");
	ntMC->AddFriend("ntHi");
	//TTree* MCHltTree;
	//if (collisionsystem=="PP") MCHltTree= (TTree*)infMC->Get("ntHlt");
	//else MCHltTree= (TTree*)infMC->Get("HltTree");
	//MCHltTree= (TTree*)infMC->Get("ntHlt");
	//ntGen->AddFriend(ntMC);
	//MCHltTree->AddFriend(ntMC);
	
	TCanvas *c[_varSize];
	TH1D *h1[_varSize];
	TH1D *h2[_varSize];
	TH1D *h3[_varSize];
	TH1D *h4[_varSize];
	TH1D *h11[_varSize];
	TH1D *h12[_varSize];
	TH1D *h13[_varSize];
	TH1D *h14[_varSize];
	TH1D *h21[_varSize];
	TH1D *h22[_varSize];
	TH1D *h23[_varSize];
	TH1D *hRatio[_varSize];
	TH1D *ptR =  new TH1D((myVars[_Dpt].title+"Ratio").c_str(), myVars[_Dpt].title.c_str(), myVars[_Dpt].nBin, myVars[_Dpt].xMin, myVars[_Dpt].xMax);
	int nentries = 1000000000;
//	nentries = 2000000;
	float pa0 = 1;	
	float pa1 = 0;	
	float pa2 = 0;	
	TString ptWeight = Form("%f+%f*Dpt+%f*Dpt*Dpt", pa0, pa1, pa2);
	for (int i = 0 ; i < _varSize; i++){
		printf("processing %s\n", myVars[i].var.c_str());
		ptWeight = Form("%f+%f*Dpt+%f*Dpt*Dpt", pa0, pa1, pa2);
		cout<<ptWeight<<endl;
//		if(i > _Dpt) continue;
		c[i] =  new TCanvas(("c"+myVars[i].var).c_str(),"",600,600);
		h1[i] =  new TH1D((myVars[i].title+"1").c_str(), myVars[i].title.c_str(), myVars[i].nBin, myVars[i].xMin, myVars[i].xMax);
		h2[i] =  new TH1D((myVars[i].title+"2").c_str(), myVars[i].title.c_str(), myVars[i].nBin, myVars[i].xMin, myVars[i].xMax);
		h3[i] =  new TH1D((myVars[i].title+"3").c_str(), myVars[i].title.c_str(), myVars[i].nBin, myVars[i].xMin, myVars[i].xMax);
		h4[i] =  new TH1D((myVars[i].title+"4").c_str(), myVars[i].title.c_str(), myVars[i].nBin, myVars[i].xMin, myVars[i].xMax);
		h11[i] = new TH1D((myVars[i].title+"11").c_str(), myVars[i].title.c_str(), myVars[i].nBin, myVars[i].xMin, myVars[i].xMax);
		h12[i] = new TH1D((myVars[i].title+"12").c_str(), myVars[i].title.c_str(), myVars[i].nBin, myVars[i].xMin, myVars[i].xMax);
		h13[i] = new TH1D((myVars[i].title+"13").c_str(), myVars[i].title.c_str(), myVars[i].nBin, myVars[i].xMin, myVars[i].xMax);
		h14[i] = new TH1D((myVars[i].title+"14").c_str(), myVars[i].title.c_str(), myVars[i].nBin, myVars[i].xMin, myVars[i].xMax);
		h21[i] = new TH1D((myVars[i].title+"21").c_str(), myVars[i].title.c_str(), myVars[i].nBin, myVars[i].xMin, myVars[i].xMax);
		h22[i] = new TH1D((myVars[i].title+"22").c_str(), myVars[i].title.c_str(), myVars[i].nBin, myVars[i].xMin, myVars[i].xMax);
		h23[i] = new TH1D((myVars[i].title+"23").c_str(), myVars[i].title.c_str(), myVars[i].nBin, myVars[i].xMin, myVars[i].xMax);
		hRatio[i] = new TH1D((myVars[i].title+"_ratio").c_str(), (myVars[i].title+"_ratio").c_str(), myVars[i].nBin, myVars[i].xMin, myVars[i].xMax);
	
		ntMC->Project((myVars[i].title+"1").c_str(), myVars[i].var.c_str(), TCut(weight)*TCut(ptWeight)*(TCut((selmc+"&&"+signalRegion).Data())), "", nentries);
		ntMC->Project((myVars[i].title+"2").c_str(), myVars[i].var.c_str(), TCut(weight)*TCut(ptWeight)*(TCut((selmc+"&&"+sidebandRegion).Data())), "", nentries);
		ntMC->Project((myVars[i].title+"4").c_str(), myVars[i].var.c_str(), TCut(weight)*TCut(ptWeight)*(TCut((selmc+"&&"+signalRegion).Data())&&"(Dgen==23333)"), "", nentries);

		ntMC->Project((myVars[i].title+"11").c_str(), myVars[i].var.c_str(), TCut("pthatweight")*TCut(ptWeight)*TCut(weight)*(TCut((selmc+"&&"+signalRegion).Data())), "", nentries);
		ntMC->Project((myVars[i].title+"12").c_str(), myVars[i].var.c_str(), TCut("pthatweight")*TCut(ptWeight)*TCut(weight)*(TCut((selmc+"&&"+sidebandRegion).Data())), "", nentries);
		ntMC->Project((myVars[i].title+"14").c_str(), myVars[i].var.c_str(), TCut("pthatweight")*TCut(ptWeight)*TCut(weight)*(TCut((selmc+"&&"+signalRegion).Data())&&"(Dgen==23333)"), "", nentries);

		nt->  Project((myVars[i].title+"21").c_str(), myVars[i].var.c_str(), TCut(weight)*(TCut((seldata+"&&"+signalRegion).Data())), "", nentries);
		nt->  Project((myVars[i].title+"22").c_str(), myVars[i].var.c_str(), TCut(weight)*(TCut((seldata+"&&"+sidebandRegion).Data())), "", nentries);

		h3[i] = (TH1D*)h1[i]->Clone();
		h3[i]->Add(h2[i],-wfactor);

		h13[i] = (TH1D*)h11[i]->Clone();
		h13[i]->Add(h12[i],-wfactor);

		h23[i] = (TH1D*)h21[i]->Clone();
		h23[i]->Add(h22[i],-wfactor);

		if(i == _Dpt){
		    h23[i]->Sumw2();
		    h13[i]->Sumw2();
		    h23[i]->Scale(1/h23[i]->Integral());
		    h13[i]->Scale(1/h13[i]->Integral());
			ptR = (TH1D*)h23[i]->Clone();
			ptR->Divide(h13[i]);
			TCanvas* cptR =  new TCanvas("cptR","",600,600);
  			TF1* f = new TF1(Form("f%d",i),"[0]+[1]*x+[2]*x*x", 15, 40);
			f->SetParameter(0,ptR->GetMaximum()*0.8);
			f->SetParLimits(0,0,ptR->GetMaximum());
			f->SetParameter(1,0.1);
			f->SetParLimits(1,-10,10);
			f->SetParameter(2,0.1);
			f->SetParLimits(1,-10,10);
			ptR->Fit(Form("f%d",i),"Lq","",15, 40);
			ptR->Fit(Form("f%d",i),"Lq","",15, 40);
			f->SetLineColor(kRed);
			f->SetLineWidth(3);
			ptR->Draw("p");
			f->Draw("l same ");
			cptR->SaveAs("plotsProject/ptR.pdf");
			pa0 = f->GetParameter(0);
			pa1 = f->GetParameter(1);
			pa2 = f->GetParameter(2);
			std::cout<<f->GetParameter(0)<<endl;
			std::cout<<f->GetParameter(1)<<endl;
			std::cout<<f->GetParameter(2)<<endl;
		}
		
		overlapTH1(c[i], h14[i], h13[i], h23[i], h21[i], myVars[i].xtitle, hRatio[i]);
		c[i]->SaveAs(("plotsProject/"+myVars[i].plotName+".pdf").c_str());
	}
	TH1D *hMCMass = new TH1D("MCDmass", "MCDmass", 100, 1.7, 2);
	TH1D *hMCMassGM = new TH1D("MCDmassGM", "MCDmassGM", 100, 1.7, 2);
	TH1D *hMCMassGMW = new TH1D("MCDmassGMW", "MCDmassGMW", 100, 1.7, 2);
	TH1D *hDataMass = new TH1D("DataDmass", "DataDmass", 100, 1.7, 2);
	TH1D *hMassRatio = new TH1D("DmassRatio", "DmassRatio", 100, 1.7, 2);
	TH1D *hempty = new TH1D("empty", "empty", 100, 1.7, 2);
    ntMC->Project("MCDmassGM", "Dmass", TCut(weight)*(TCut( (selmc) .Data())&&"(Dgen==23333)"), "", nentries);
    ntMC->Project("MCDmassGMW", "Dmass", TCut("pthatweight")*TCut(weight)*(TCut( (selmc) .Data())&&"(Dgen==23333)"), "", nentries);
    ntMC->Project("MCDmass", "Dmass", TCut(weight)*(TCut( (selmc) .Data())), "", nentries);
    nt->  Project("DataDmass", "Dmass", TCut(weight)*(TCut( (seldata).Data())), "", nentries);
    TCanvas* cMass =  new TCanvas("cMass","",600,600);
    overlapTH1(cMass, hMCMassGM, hMCMassGMW, hMCMass, hDataMass, "Dmass", hMassRatio, 1);
	cMass->SaveAs("plotsProject/mass.pdf");

	
}