예제 #1
0
// ============================================================================
StatusCode Gaudi::Utils::Histos::fromXml
( TH3F& result , const std::string& input )
{
  //
  result.Reset() ;                                 // RESET old histogram
  //
  _Xml<TH3F> _xml ;
  std::auto_ptr<TH3F> histo = _xml ( input ) ;
  if ( 0 == histo.get() ) { return StatusCode::FAILURE ; }        // RETURN
  //
  result.Reset() ;
  histo->Copy ( result ) ;
  //
  return StatusCode::SUCCESS ;
}
예제 #2
0
TH1D* Template::getProjected1DTemplate(unsigned int axis)
/*****************************************************************/
{
    if(axis>=numberOfDimensions())
    {
        stringstream error;
        error << "Template::getProjected1DTemplate(): Projection requested on axis "<<axis<<" for "<<numberOfDimensions()<<"D template '"<<m_name<<"'\n";
        throw runtime_error(error.str());
    }
    unsigned int nbins1 = 0;
    unsigned int nbins2 = 0;
    if(axis==0)      
    {
        nbins1 = m_template->GetNbinsY();
        nbins2 = m_template->GetNbinsZ();
    }
    else if(axis==1) 
    {
        nbins1 = m_template->GetNbinsX();
        nbins2 = m_template->GetNbinsZ();
    }
    else if(axis==2) 
    {
        nbins1 = m_template->GetNbinsX();
        nbins2 = m_template->GetNbinsY();
    }

    stringstream projName;
    projName << m_template->GetName() << "_projFromTmp"<< axis;
    TH1D* projectedTemplate = NULL;

    if(numberOfDimensions()==2)
    {
        TH2F* tmp = dynamic_cast<TH2F*>(m_template);
        if(axis==0)      projectedTemplate = tmp->ProjectionX(projName.str().c_str(), 1, nbins1, "e");
        else if(axis==1) projectedTemplate = tmp->ProjectionY(projName.str().c_str(), 1, nbins1, "e");
    }
    if(numberOfDimensions()==3)
    {
        TH3F* tmp = dynamic_cast<TH3F*>(m_template);
        if(axis==0)      projectedTemplate = tmp->ProjectionX(projName.str().c_str(), 1, nbins1, 1, nbins2, "e");
        else if(axis==1) projectedTemplate = tmp->ProjectionY(projName.str().c_str(), 1, nbins1, 1, nbins2, "e");
        else if(axis==2) projectedTemplate = tmp->ProjectionZ(projName.str().c_str(), 1, nbins1, 1, nbins2, "e");
    }

    return projectedTemplate;
}
예제 #3
0
TH2D* Template::getProjected2DTemplate(unsigned int axis1, unsigned int axis2)
/*****************************************************************/
{
    if(axis1>=numberOfDimensions() || axis2>=numberOfDimensions())
    {
        stringstream error;
        error << "Template::getProjected2DTemplate(): Projection requested on axes "<<axis1<<" and "<<axis2<<" for "<<numberOfDimensions()<<"D template '"<<m_name<<"'\n";
        throw runtime_error(error.str());
    }
    if(numberOfDimensions()!=3)
    {
        stringstream error;
        error << "Template::getProjected2DTemplate(): Cannot do a 2D projection for "<<numberOfDimensions()<<"D template '"<<m_name<<"'\n";
        throw runtime_error(error.str());
    }
    unsigned int axis = 0;
    if(axis1==0 && axis2==1)      
    {
        axis = 2;
    }
    else if(axis1==0 && axis2==2) 
    {
        axis = 1;
    }
    else if(axis1==1 && axis2==2) 
    {
        axis = 0;
    }

    stringstream projName;
    projName << m_template->GetName() << "_proj2dFromTmp"<< axis;
    TH2D* projectedTemplate = NULL;

    if(numberOfDimensions()==3)
    {
        TH3F* tmp = dynamic_cast<TH3F*>(m_template);
        if(axis1==0 && axis2==1)      projectedTemplate = dynamic_cast<TH2D*>(tmp->Project3D("xye"));
        else if(axis1==0 && axis2==2) projectedTemplate = dynamic_cast<TH2D*>(tmp->Project3D("xze"));
        else if(axis1==1 && axis2==2) projectedTemplate = dynamic_cast<TH2D*>(tmp->Project3D("yze"));
        projectedTemplate->SetName(projName.str().c_str());
    }

    return projectedTemplate;
}
예제 #4
0
TH1D * getSpectrum(TFile * f, char * type, int minCent, int maxCent, double etaMin, double etaMax )
{
  TH3F *h = (TH3F*) f->Get(Form("%s",type));
  h->GetZaxis()->SetRangeUser( minCent+0.001, maxCent-0.001);
  TH2F * ch = (TH2F*) h->Project3D("yxe");

  TH1D* hPt;
  TH1D* hPtN;
  Int_t etabin10m=ch->GetXaxis()->FindBin(etaMin+0.01);
  Int_t etabin10p=ch->GetXaxis()->FindBin(etaMax-0.01);
  Int_t Netabin10p=ch->GetXaxis()->FindBin(-etaMin-0.01);
  Int_t Netabin10m=ch->GetXaxis()->FindBin(-etaMax+0.01);
  hPt = (TH1D*) ch->ProjectionY(Form("hPt_%d",rand()),etabin10m,etabin10p,"e");
  hPtN = (TH1D*) ch->ProjectionY("hPtN",Netabin10m,Netabin10p,"e");
  hPt->Add( hPtN, 1.0);

  delete h;
  delete ch;
  delete hPtN;

  return hPt;
}
예제 #5
0
void doit(bool small) {
   Int_t blowup = 1;
   if (!small) blowup = 4;
   Int_t nbins[] = {10 * blowup, 20 * blowup, 14 * blowup};
   Double_t xmin[] = {0., -1., 0.};
   Double_t xmax[] = {1., 1., 10.};
         
   THnSparse* sparse = new THnSparseF("sparse" ,"sparse TH3", 3,
                                      nbins, xmin, xmax);
   sparse->Sumw2();

   TH3F* h = new TH3F("h", "nonsparse TH3", nbins[0], xmin[0], xmax[0],
                      nbins[1], xmin[1], xmax[1],
                      nbins[2], xmin[2], xmax[2]);
   h->Sumw2();

   for (Int_t entries = 0; entries < 10000; ++entries) {
      Double_t x[3];
      for (Int_t d = 0; d < 3; ++d)
         // 10% overshoot to tests overflows
         x[d] = gRandom->Rndm()*(xmax[d]*1.2 - xmin[d]*1.2) + xmin[d]*1.1;
      sparse->Fill(x);
      h->Fill(x[0], x[1], x[2]);
   }

   CheckFillProjection(h, sparse);
   CheckProjection1(h, sparse);
   CheckProjection2(h, sparse);
   CheckScale(h, sparse);
   CheckClone(h, sparse);
   CheckSubtract(h, sparse);
   CheckDivide(h, sparse);
   CheckErrors(h, sparse);
   CheckBinomial(h, sparse);
   CheckMerge(h, sparse);

   delete h;
   delete sparse;
}
void quickMakeHisto() {

  
  new TCanvas();
  TChain *nocontainerTree = new TChain("pcaTree");
  nocontainerTree->Add("/home/rjn/creamtea/data/nocontainer/pca_nocontainer_0_1000files.root");
  nocontainerTree->Add("/home/rjn/creamtea/data/nocontainer/pca_nocontainer_1000_2000files.root");
  nocontainerTree->Add("/home/rjn/creamtea/data/nocontainer/pca_nocontainer_3000_4000files.root");

  TFile *fpNocontainer = new TFile("nocontainer.root","RECREATE");
  TH3F *histNocontainer = new TH3F("histNoContainer","histNoContainer",100,-6000,+6000,100,-6000,+6000,100,-6000,+6000);
  
  nocontainerTree->Draw("xPosTrue:yPosTrue:zPosTrue>>histNoContainer","abs(zPosTrue)<3000 && abs(xPosTrue)<6000 && abs(yPosTrue)<6000 && thetaTrue>0.00","");
  histNocontainer->Write();


  new TCanvas();
  TChain *containerTree = new TChain("pcaTree");
  containerTree->Add("/home/rjn/creamtea/data/container13m/pca_container_1_1000files.root");
  containerTree->Add("/home/rjn/creamtea/data/container13m/pca_container_1001_2000files.root");
  containerTree->Add("/home/rjn/creamtea/data/container13m/pca_container_2001_3000files.root");

  TFile *fpcontainer = new TFile("container.root","RECREATE");
  TH3F *histcontainer = new TH3F("histContainer","histContainer",100,-6000,+6000,100,-6000,+6000,100,-6000,+6000);
  
  containerTree->Draw("xPosTrue:yPosTrue:zPosTrue>>histContainer","abs(zPosTrue)<3000 && abs(xPosTrue)<6000 && abs(yPosTrue)<6000 && thetaTrue>0.00","");
  histcontainer->Write();


  new TCanvas();
  TChain *targetTree = new TChain("pcaTree");
  targetTree->Add("/home/rjn/creamtea/data/target/pca_container_1_1000files.root");
  targetTree->Add("/home/rjn/creamtea/data/target/pca_container_1001_2000files.root");
  targetTree->Add("/home/rjn/creamtea/data/target/pca_container_2001_3000files.root");

  TFile *fptarget = new TFile("target.root","RECREATE");
  TH3F *histtarget = new TH3F("histTarget","histTarget",100,-6000,+6000,100,-6000,+6000,100,-6000,+6000);
  
  targetTree->Draw("xPosTrue:yPosTrue:zPosTrue>>histTarget","abs(zPosTrue)<3000 && abs(xPosTrue)<6000 && abs(yPosTrue)<6000 && thetaTrue>0.00","");
  histtarget->Write();



}
예제 #7
0
void PlotV2ForJetAndTrack(){


  /* Variable */
  double ETMIN = 15;
  
  /* File Loading */
  TFile *f1 = new TFile("../root_files/ANA_spectAnaGEN_March26_PtAll_Ntot400K_proq20_FullExt_Large_VariedN.root");

  TFile *f2=0, *f3=0, *f4=0;
  f2 = new TFile("../root_files/ANA_spectAnaGEN_March26_PtAll_Ntot400K_proq20_FullExt_Large_VariedN_jetQ_fractLog2.00_phidep_a7.00_b10.00.root");

  /* Histogram Loading */
  TH1F *hdnevtminpthat = (TH1F*) f1->Get("dNevtMinPtHat");

  TH1F *hjetspecv0 = (TH1F*) f1->Get("dNJetdEt");

  TH2F *hjetspecdphiv0 = (TH2F*) f1->Get("dNJetdEtdPhi");
  TH2F *hjetspecdphiv0_q1 = (TH2F*) f2->Get("dNJetdEtdPhi");
  TH2F *hjetspecdcos2phiv0_q1 = (TH2F*) f2->Get("dNJetdEtdCos2Phi");

  TH2F *hdntrkdptdpthat = (TH2F*) f1->Get("dNTrkdPtdPtHat");

  TH3F *hdntrkdptdjetetdphi = (TH3F*) f1->Get("dNTrkdPtdJetEtdPhi");
  TH3F *hdntrkdptdpthatdjetet = (TH3F*) f1->Get("dNTrkdPtdPtHatdJetEt");
  

  double small = 1e-3;
  double tot_evt_minpthat = hdnevtminpthat->GetEntries();

  cout<<"Number of min_pt_hat event sample = "<<tot_evt_minpthat<<endl;

  if(tot_evt_minpthat<1E-22){
    cout<<"This sample doesn't include the minimum pt hat bin sample!"<<endl;
    return;
  }

  /* Overall Normalization */
  hjetspecv0->Scale(1./tot_evt_minpthat);
  hjetspecdphiv0->Scale(1./tot_evt_minpthat);
  hjetspecdphiv0_q1->Scale(1./tot_evt_minpthat);
  hdntrkdptdpthat->Scale(1./tot_evt_minpthat);
  hdntrkdptdjetetdphi->Scale(1./tot_evt_minpthat);
  hdntrkdptdpthatdjetet->Scale(1./tot_evt_minpthat);

  /* Dividing By Bin Width */
  divideByWidth(hjetspecv0);


  /* Duplications of Some Histograms */
  TH2F *hjetspecdphiv0_cln = (TH2F*) hjetspecdphiv0->Clone("hjetspecdphiv0_cln");
  TH2F *hjetspecdphiv0_q1_cln = (TH2F*) hjetspecdphiv0_q1->Clone("hjetspecdphiv0_q1_cln");
  TH3F *hdntrkdptdjetetdphi_cln = (TH3F*) hdntrkdptdjetetdphi->Clone("hdntrkdptdjetetdphi_cln");


  /* Dum Histograms */
  TH1D *hdum = new TH1D("hdum","",200,-3.2,3.2);
  hdum->SetStats(0);
  hdum->SetAxisRange(-0.001,0.1,"Y");
  hdum->GetXaxis()->SetTitle("#phi - #psi (rad)");
  hdum->GetXaxis()->CenterTitle();
  hdum->GetYaxis()->SetTitle("A.U");
  hdum->GetYaxis()->CenterTitle();
  hdum->GetXaxis()->SetMoreLogLabels();
  setHist(hdum);

  TH1D *hdum_1 = (TH1D*) hdum->Clone("hdum_1");
  hdum_1->SetAxisRange(0.0,2.0,"X");
  hdum_1->SetAxisRange(-0.001,0.2,"Y");
  hdum_1->GetXaxis()->SetTitle("2cos(#phi - #psi (rad))");
  

  /* ------------ Jet V2 --------------- */

  cout<<"Number of ET bins = "<<hjetspecdphiv0_q1->GetNbinsX()<<endl;

  TCanvas *c0 = new TCanvas("c0","",1250,930);
  makeMultiPanelCanvas(c0,5,4,0.0,0.0,0.2,0.2,0.02);

  TCanvas *c0_1 = new TCanvas("c0_1","",1250,930);
  makeMultiPanelCanvas(c0_1,5,4,0.0,0.0,0.2,0.2,0.02);


  int index = 0;
  hjetspecdphiv0_q1->RebinX(10);  // as original bin is too fine
  hjetspecdcos2phiv0_q1->RebinX(10);

  TH1D *hjetspecdphiv0_q1_projx= (TH1D*) hjetspecdphiv0_q1->ProjectionX("hjetspecdphiv0_q1_projx",0,-1,"e");
  TH1D *hjetspecdcos2phiv0_q1_projx= (TH1D*) hjetspecdcos2phiv0_q1->ProjectionX("hjetspecdcos2phiv0_q1_projx",0,-1,"e");

  for(int i=0;i<hjetspecdphiv0_q1->GetNbinsX();i++){
    
    double etmin = hjetspecdphiv0_q1->GetXaxis()->GetBinLowEdge(i+1);
    double etmax = hjetspecdphiv0_q1->GetXaxis()->GetBinUpEdge(i+1);

    // dPhi distribution of Jet
    TH1D *hjetspec_dphi = (TH1D*) hjetspecdphiv0_q1->ProjectionY("",i+1,i+1,"e");
    hjetspec_dphi->SetName(Form("hjetspec_dphi_et%1.0fto%1.0f",etmin,etmax));     

    // cos(dPhi) distribution of Jet
    TH1D *hjetspec_dcosphi = (TH1D*) hjetspecdcos2phiv0_q1->ProjectionY("",i+1,i+1,"e");
    hjetspec_dcosphi->SetName(Form("hjetspec_dcosphi_et%1.0fto%1.0f",etmin,etmax));

    // --> rebinning
    hjetspec_dphi->Rebin(4);
    hjetspec_dphi->Scale(1./4.);
    
    hjetspec_dcosphi->Rebin(4);
    hjetspec_dcosphi->Scale(1./4.);

    // --> dN/dphi (not necessary, though)
    //divideByWidth(hjetspec_dphi);

    // --> Normalization 
    hjetspec_dphi->Scale(1./hjetspec_dphi->Integral());
    hjetspec_dcosphi->Scale(1./hjetspec_dcosphi->Integral());


    // Draw
    if(etmin<ETMIN) continue;
    if(i%2+1) index++;
    if(index<20) {

      // Fitting methods
      c0->cd(index);
      hdum->Draw("");
      hjetspec_dphi->SetMarkerStyle(20);
      hjetspec_dphi->SetMarkerSize(1.0);
      hjetspec_dphi->Draw("pzsame");

      TLatex *tl_jet = new TLatex(0.5,0.8,Form("%1.1f<E_{T}<%1.1f",etmin,etmax));
      tl_jet->SetTextFont(63);
      tl_jet->SetTextSize(16);
      tl_jet->SetTextColor(kBlack);
      tl_jet->SetLineWidth(1);
      tl_jet->SetNDC();
      tl_jet->Draw("");

      // Fitting
      TF1 *fit1 = new TF1("fit1",FourierDecomp,-3.2,3.2,7);
      //for(int k=0;k<7;k++) fit1->SetParLimits(k,0,10);
      hjetspec_dphi->Fit(fit1,"RNQ");
      
      fit1->SetLineColor(kRed);
      fit1->SetLineWidth(2);
      fit1->Draw("same");

      double par1[7];
      const int binn = sizeof(par1)/sizeof(double) - 1;
      for(int j=0;j<binn;j++) par1[j] = 0.0;
      par1[0] = fit1->GetParameter(0);
      par1[2] = fit1->GetParameter(2);
      //cout<<"par1[2] = "<<par1[2]<<endl;

      TF1 *fit1_v2 = new TF1("fit1_v2",FourierDecomp,-3.2,3.2,7);
      fit1_v2->SetParameters(par1);
      fit1_v2->SetLineColor(kBlue);
      fit1_v2->SetLineWidth(2);
      fit1_v2->Draw("same");
      
      // Extracting methods
      c0_1->cd(index);
      hdum_1->Draw("");
      hjetspec_dcosphi->SetMarkerStyle(20);
      hjetspec_dcosphi->SetMarkerSize(1.0);
      hjetspec_dcosphi->Draw("pzsame");

      cout<<"PAR0 = "<<fit1->GetParameter(0)<<" PAR1 = "<<fit1->GetParameter(1)
	  <<" PAR2 = "<<fit1->GetParameter(2)<<" PAR3 = "<<fit1->GetParameter(3)<<endl;
      //cout<<"fit1->GetParameter(2) = "<<fit1->GetParameter(2)<<endl;
      //cout<<" hjetspec_dcosphi = "<<hjetspec_dcosphi->GetMean()<<endl;
      
      // v2 vs pT
      hjetspecdphiv0_q1_projx->SetBinContent(i+1,fit1->GetParameter(2));
      hjetspecdcos2phiv0_q1_projx->SetBinContent(i+1,GetMeanV2(hjetspec_dcosphi));
      //hjetspecdcos2phiv0_q1_projx->SetBinContent(i+1,hjetspec_dcosphi->Integral()/hjetspec_dcosphi->GetEntries());
      //hjetspecdcos2phiv0_q1_projx->SetBinContent(i+1,hjetspec_dcosphi->GetMean());
    }

    
  }

  // Drawing V2 (pT)
  TCanvas *c1 =new TCanvas("c1","v_{2} as a function of p_{T}",500,500);
  hjetspecdphiv0_q1_projx->SetStats(0);
  //hjetspecdphiv0_q1_projx->SetAxisRange(-0.0001,0.001,"Y");
  hjetspecdphiv0_q1_projx->SetAxisRange(-0.0001,2.0,"Y");    
  hjetspecdphiv0_q1_projx->SetAxisRange(ETMIN,300,"X");
  hjetspecdphiv0_q1_projx->GetYaxis()->SetTitle("Jet v_{2}");
  hjetspecdphiv0_q1_projx->GetXaxis()->SetTitle("Jet E_{T}");
  hjetspecdphiv0_q1_projx->GetXaxis()->CenterTitle();
  hjetspecdphiv0_q1_projx->GetYaxis()->CenterTitle();
  hjetspecdphiv0_q1_projx->GetXaxis()->SetMoreLogLabels();
  hjetspecdphiv0_q1_projx->SetMarkerSize(1.2);
  hjetspecdphiv0_q1_projx->Draw("");
  
  hjetspecdcos2phiv0_q1_projx->SetMarkerColor(kRed);
  hjetspecdcos2phiv0_q1_projx->SetMarkerSize(1.2);
  hjetspecdcos2phiv0_q1_projx->Draw("pzsame");



  /* ---------------- Convoluting Jet Spectra with FF ---------------- */

  // Obtain FF 
  // - 3D of (track pt, pthat, jet et) 
  // - 1D of dN/dET 

  //ObtainFF(hdntrkdptdpthatdjetet, hjetspecv0);
  Obtain2DFF(hdntrkdptdjetetdphi, hjetspecv0);
  
  TH2D *hdntrkdptdphi_cln = (TH2D*) hdntrkdptdjetetdphi_cln->Project3D("zxe");
  hdntrkdptdphi_cln->Reset();

  for(int ij=0;ij<hjetspecdphiv0_cln->GetNbinsX();ij++){

    double etmin = hjetspecdphiv0_cln->GetXaxis()->GetBinLowEdge(ij+1);
    double etmax = hjetspecdphiv0_cln->GetXaxis()->GetBinUpEdge(ij+1);

    // dPhi distribution of Jet
    TH1D *hjetspec_dphi_cln = (TH1D*) hjetspecdphiv0_q1_cln->ProjectionY("",ij+1,ij+1,"e");
    hjetspec_dphi_cln->SetName(Form("hjetspec_dphi_cln_et%1.0fto%1.0f",etmin,etmax));

    // FF (pt,phi) 
    TH2D *hdntrkdpt_2dff_cln2 = (TH2D*) gDirectory->Get(Form("hdntrkdpt_2dff_et%1.0fto%1.0f",etmin,etmax));
    if(hdntrkdpt_2dff_cln2==0) continue;  // don't use empty histograms  

    // Loop over phi in each jet ET bin 
    for(int ijk=0;ijk<hjetspec_dphi_cln->GetNbinsX();ijk++){ 
      
      double phimin = hjetspec_dphi_cln->GetXaxis()->GetBinLowEdge(ijk+1);
      double phimax = hjetspec_dphi_cln->GetXaxis()->GetBinUpEdge(ijk+1);

      //cout<<"phi: "<<phimin<<" to "<<phimax<<endl;

      //TH1D *hdntrkdpt_1dff_cln2 = (TH1D*) hdntrkdpt_2dff_cln2->ProjectionY("",ijk,ijk,"e");
      //hdntrkdpt_1dff_cln2->SetName(Form("hdntrkdpt_1dff_cln2_phi%1.0fto%1.0f",phimin,phimax));

      double dsigma_v0 = hjetspec_dphi_cln->GetBinContent(ijk+1);
      //hdntrkdpt_1dff_cln2->Scale(dsigma_v0);

      // Scale each (pt,phi) 
      for(int m=0;m<hdntrkdpt_2dff_cln2->GetNbinsX();m++){

	double ffval = hdntrkdpt_2dff_cln2->GetBinContent(m,ijk);
	double ffvalerr = hdntrkdpt_2dff_cln2->GetBinError(m,ijk);

	hdntrkdpt_2dff_cln2->SetBinContent(m,ijk,ffval*dsigma_v0);
	hdntrkdpt_2dff_cln2->SetBinError(m,ijk,ffvalerr*dsigma_v0);
      } // end of m

    }// end of ijk

    hdntrkdptdphi_cln->Add(hdntrkdpt_2dff_cln2);

  }// end of convolution

  /* ----------------------- Charged Particle V2 ----------------- */
  TCanvas *c2 =new TCanvas("c2","Track p_{T} vs #phi",500,500);
  hdntrkdptdphi_cln->Draw("COLZ");
  //hdntrkdptdphi_cln->ProjectionX()->Draw("");
  //hdntrkdptdphi_cln->ProjectionY()->Draw("");   
  

  TCanvas *c0_2 = new TCanvas("c0_2","",1250,930);
  makeMultiPanelCanvas(c0_2,5,4,0.0,0.0,0.2,0.2,0.02);


  for(int n=0;n<hdntrkdptdphi_cln->GetNbinsX();n++){
    
    
  }
  



}
예제 #8
0
void plotHist3D() {

  RiceStyle();

  gStyle->SetOptStat(0);

  TFile *f = new TFile("../rootfile/PbPb_eff_MC_v1.root");

  char ndir[256] = "HITrackCorrections";
  double ptmax = 300.;

  // sim-to-reco hists
  TH3F *hSim = (TH3F*) f->Get(Form("%s/hsim3D",ndir)); hSim->GetYaxis()->SetRangeUser(0.2,ptmax);
  TH3F *hEff = (TH3F*) f->Get(Form("%s/heff3D",ndir)); hEff->GetYaxis()->SetRangeUser(0.2,ptmax);
  TH3F *hMul = (TH3F*) f->Get(Form("%s/hmul3D",ndir)); hMul->GetYaxis()->SetRangeUser(0.2,ptmax);

  // reco-to-sim hists
  TH3F *hRec = (TH3F*) f->Get(Form("%s/hrec3D",ndir)); hRec->GetYaxis()->SetRangeUser(0.2,ptmax);
  TH3F *hFak = (TH3F*) f->Get(Form("%s/hfak3D",ndir)); hFak->GetYaxis()->SetRangeUser(0.2,ptmax);
  TH3F *hSec = (TH3F*) f->Get(Form("%s/hsec3D",ndir)); hSec->GetYaxis()->SetRangeUser(0.2,ptmax);

  // ratio histograms
  TH3F *rEff = (TH3F*) hEff->Clone("rEff");
  TH3F *rMul = (TH3F*) hMul->Clone("rMul");
  TH3F *rFak = (TH3F*) hFak->Clone("rFak");
  TH3F *rSec = (TH3F*) hSec->Clone("rSec");

  //---------------------------------------------
  //---------------------------------------------

  // find bins corresponding to projections for below
  int ptbin04=hSim->GetYaxis()->FindBin(0.41);
  int ptbin10=hSim->GetYaxis()->FindBin(1.01);
  int ptbins=hSim->GetYaxis()->GetNbins();

  int etabin24m=hSim->GetXaxis()->FindBin(-2.39);
  int etabin24p=hSim->GetXaxis()->FindBin(2.39);
  int etabin10m=hSim->GetXaxis()->FindBin(-0.99);
  int etabin10p=hSim->GetXaxis()->FindBin(0.99);

  int occbin0 = hSim->GetZaxis()->FindBin(0);
  int occbin50 = hSim->GetZaxis()->FindBin(99);
  int occbin51 = hSim->GetZaxis()->FindBin(100);
  int occbin100 = hSim->GetZaxis()->FindBin(199);

  cout << "etabin10m: " << etabin10m << " etabin10p: " << etabin10p << endl;
  cout << "etabin10m: " << etabin24m << " etabin10p: " << etabin24p << endl;
  cout << "occbin0: " << occbin0 << "occbin50: " << occbin50 << endl;

  // projected hists: pt > 1.0 GeV/c, cBin (0,50%)
  TH1D* hSimEta = (TH1D*) hSim->ProjectionX("hSimEta",ptbin10,ptbins,occbin0,occbin50,"e");
  TH1D* hEffEta = (TH1D*) hEff->ProjectionX("hEffEta",ptbin10,ptbins,occbin0,occbin50,"e");
  TH1D* hMulEta = (TH1D*) hMul->ProjectionX("hMulEta",ptbin10,ptbins,occbin0,occbin50,"e");
  TH1D* hRecEta = (TH1D*) hRec->ProjectionX("hRecEta",ptbin10,ptbins,occbin0,occbin50,"e");
  TH1D* hFakEta = (TH1D*) hFak->ProjectionX("hFakEta",ptbin10,ptbins,occbin0,occbin50,"e");
  TH1D* hSecEta = (TH1D*) hSec->ProjectionX("hSecEta",ptbin10,ptbins,occbin0,occbin50,"e");

  // projected hists: pt > 1.0 GeV/c. cBin (50-100%)
  TH1D* hSimEta2 = (TH1D*) hSim->ProjectionX("hSimEta2",ptbin10,ptbins,occbin50,occbin100,"e");
  TH1D* hEffEta2 = (TH1D*) hEff->ProjectionX("hEffEta2",ptbin10,ptbins,occbin50,occbin100,"e");
  TH1D* hMulEta2 = (TH1D*) hMul->ProjectionX("hMulEta2",ptbin10,ptbins,occbin50,occbin100,"e");
  TH1D* hRecEta2 = (TH1D*) hRec->ProjectionX("hRecEta2",ptbin10,ptbins,occbin50,occbin100,"e");
  TH1D* hFakEta2 = (TH1D*) hFak->ProjectionX("hFakEta2",ptbin10,ptbins,occbin50,occbin100,"e");
  TH1D* hSecEta2 = (TH1D*) hSec->ProjectionX("hSecEta2",ptbin10,ptbins,occbin50,occbin100,"e");

  TH1D* hDumEta = new TH1D("hDumEta",";#eta",60,-2.4,2.4); hDumEta->SetMaximum(1.0); hDumEta->SetTitle("p_{T} > 1.0");
  hDumEta->GetXaxis()->CenterTitle(); hDumEta->GetYaxis()->SetTitleOffset(1.8);
  TH1D* hDumEta2 = (TH1D*) hDumEta->Clone("hDumEta2"); hDumEta2->SetMaximum(0.1); 
  TH1D* hDumEta3 = (TH1D*) hDumEta->Clone("hDumEta3"); hDumEta3->SetMaximum(0.00049); 

  // projected hists: abs(eta) < 1.0, cBin(0-50%)
  TH1D* hSimPt  = (TH1D*) hSim->ProjectionY("hSimPt",etabin10m,etabin10p,occbin0,occbin50,"e");
  TH1D* hEffPt  = (TH1D*) hEff->ProjectionY("hEffPt",etabin10m,etabin10p,occbin0,occbin50,"e");
  TH1D* hMulPt  = (TH1D*) hMul->ProjectionY("hMulPt",etabin10m,etabin10p,occbin0,occbin50,"e");
  TH1D* hRecPt  = (TH1D*) hRec->ProjectionY("hRecPt",etabin10m,etabin10p,occbin0,occbin50,"e");
  TH1D* hFakPt  = (TH1D*) hFak->ProjectionY("hFakPt",etabin10m,etabin10p,occbin0,occbin50,"e");
  TH1D* hSecPt  = (TH1D*) hSec->ProjectionY("hSecPt",etabin10m,etabin10p,occbin0,occbin50,"e");

  // projected hists: abs(eta) < 1.0, cBin(50-100%)
  TH1D* hSimPt2  = (TH1D*) hSim->ProjectionY("hSimPt2",etabin10m,etabin10p,occbin50,occbin100,"e");
  TH1D* hEffPt2  = (TH1D*) hEff->ProjectionY("hEffPt2",etabin10m,etabin10p,occbin50,occbin100,"e");
  TH1D* hMulPt2  = (TH1D*) hMul->ProjectionY("hMulPt2",etabin10m,etabin10p,occbin50,occbin100,"e");
  TH1D* hRecPt2  = (TH1D*) hRec->ProjectionY("hRecPt2",etabin10m,etabin10p,occbin50,occbin100,"e");
  TH1D* hFakPt2  = (TH1D*) hFak->ProjectionY("hFakPt2",etabin10m,etabin10p,occbin50,occbin100,"e");
  TH1D* hSecPt2  = (TH1D*) hSec->ProjectionY("hSecPt2",etabin10m,etabin10p,occbin50,occbin100,"e");
  
  TH1D* hDumPt = new TH1D("hDumPt",";p_{T} [GeV/c]",80,0.1,300.0); hDumPt->SetMaximum(1.0);
  hDumPt->GetXaxis()->CenterTitle(); hDumPt->GetYaxis()->SetTitleOffset(1.8); hDumPt->SetTitle("|#eta| < 1");
  TH1D* hDumPt2 = (TH1D*) hDumPt->Clone("hDumPt2"); hDumPt2->SetMaximum(0.1); 
  TH1D* hDumPt3 = (TH1D*) hDumPt->Clone("hDumPt3"); hDumPt3->SetMaximum(0.00049); 

  // Efficiency
  TGraphAsymmErrors *gEffEta = new TGraphAsymmErrors(); gEffEta->SetName("gEffEta");
  gEffEta->BayesDivide(hEffEta,hSimEta);
  gEffEta->SetMarkerStyle(25);
  gEffEta->SetLineStyle(2);
  gEffEta->SetLineColor(2);
  gEffEta->SetMarkerColor(2);

  TGraphAsymmErrors *gEffPt = new TGraphAsymmErrors(); gEffPt->SetName("gEffPt");
  gEffPt->BayesDivide(hEffPt,hSimPt);
  gEffPt->SetMarkerStyle(25);
  gEffPt->SetLineColor(2);
  gEffPt->SetMarkerColor(2);

  TGraphAsymmErrors *gEffEta2 = new TGraphAsymmErrors(); gEffEta2->SetName("gEffEta2");
  gEffEta2->BayesDivide(hEffEta2,hSimEta2);
  gEffEta2->SetMarkerStyle(24);
  gEffEta2->SetLineColor(4);
  gEffEta2->SetMarkerColor(4);

  TGraphAsymmErrors *gEffPt2 = new TGraphAsymmErrors(); gEffPt2->SetName("gEffPt2");
  gEffPt2->BayesDivide(hEffPt2,hSimPt2);
  gEffPt2->SetMarkerStyle(24);
  gEffPt2->SetLineStyle(4);
  gEffPt2->SetLineColor(4);
  gEffPt2->SetMarkerColor(4);

  TLegend *legEta = new TLegend(0.35,0.15,0.65,0.30);
  legEta->SetFillColor(0); legEta->SetBorderSize(0);
  legEta->AddEntry(gEffEta,"0-50%","lp");
  legEta->AddEntry(gEffEta2,"50-100%","lp");

  TLegend *legPt = new TLegend(0.35,0.2,0.65,0.35);
  legPt->SetFillColor(0); legPt->SetBorderSize(0);
  legPt->AddEntry(gEffPt,"0-50%","lp");
  legPt->AddEntry(gEffPt2,"50-100%","lp");

  TCanvas* c7 = makeMultiCanvas("c7", "Efficiency Fraction", 2,1 );
  hDumEtaEff=(TH1F*) hDumEta->Clone("hDumEtaEff"); fixedFontHist1D(hDumEtaEff,1.05,1.2);
  hDumEtaEff->GetYaxis()->SetTitle("Absolute efficiency");
  hDumPtEff=(TH1F*) hDumPt->Clone("hDumPtEff"); fixedFontHist1D(hDumPtEff,1.05,1.2);
  hDumPtEff->GetYaxis()->SetTitle("Absolute efficiency");
  c7->cd(1); gPad->SetTicks(); c7->GetPad(1)->SetLeftMargin(0.12); c7->GetPad(1)->SetBottomMargin(0.13); c7->GetPad(1)->SetLogx(0); hDumEtaEff->Draw(); gEffEta->Draw("pc"); gEffEta2->Draw("pc"); legEta->Draw();
  c7->cd(2); gPad->SetTicks(); c7->GetPad(2)->SetLeftMargin(0.12); c7->GetPad(2)->SetBottomMargin(0.13); c7->GetPad(2)->SetLogx(); hDumPtEff->Draw(); gEffPt->Draw("pc"); gEffPt2->Draw("pc"); legPt->Draw();
  saveCanvas(c7, "files", "AbsoluteEfficiency3D");

  // Multiple Reco
  TGraphAsymmErrors *gMulEta = new TGraphAsymmErrors(); gMulEta->SetName("gMulEta");
  gMulEta->BayesDivide(hMulEta,hSimEta);
  gMulEta->SetMarkerStyle(25);
  gMulEta->SetLineStyle(2);
  gMulEta->SetLineColor(2);
  gMulEta->SetMarkerColor(2);

  TGraphAsymmErrors *gMulPt = new TGraphAsymmErrors(); gMulPt->SetName("gMulPt");
  gMulPt->BayesDivide(hMulPt,hSimPt);
  gMulPt->SetMarkerStyle(25);
  gMulPt->SetLineColor(2);
  gMulPt->SetMarkerColor(2);

  TGraphAsymmErrors *gMulEta2 = new TGraphAsymmErrors(); gMulEta2->SetName("gMulEta2");
  gMulEta2->BayesDivide(hMulEta2,hSimEta2);
  gMulEta2->SetMarkerStyle(24);
  gMulEta2->SetLineColor(4);
  gMulEta2->SetMarkerColor(4);

  TGraphAsymmErrors *gMulPt2 = new TGraphAsymmErrors(); gMulPt2->SetName("gMulPt2");
  gMulPt2->BayesDivide(hMulPt2,hSimPt2);
  gMulPt2->SetMarkerStyle(24);
  gMulPt2->SetLineStyle(4);
  gMulPt2->SetLineColor(4);
  gMulPt2->SetMarkerColor(4);

  TCanvas *c8 = makeMultiCanvas("c8","Multiple Fraction", 2,1);
  hDumEtaMul=(TH1F*) hDumEta3->Clone("hDumEtaMul"); fixedFontHist1D(hDumEtaMul, 1.05,1.2); hDumEtaMul->GetYaxis()->SetRangeUser(0,0.0009);
  hDumEtaMul->GetYaxis()->SetTitle("Multiple Reconstruction Fraction");
  hDumPtMul=(TH1F*) hDumPt3->Clone("hDumPtMul"); fixedFontHist1D(hDumPtMul, 1.05, 1.2); hDumPtMul->GetYaxis()->SetRangeUser(0,0.0009);
  hDumPtMul->GetYaxis()->SetTitle("Multiple Reconstruction Fraction");
  legEta2 = (TLegend*) legEta->Clone(); legEta2->SetY1(0.65); legEta2->SetY2(0.85);
  legPt2 = (TLegend*) legPt->Clone(); legPt2->SetY1(0.65); legPt2->SetY2(0.85);
  c8->cd(1); gPad->SetLogx(0); gPad->SetTicks(); c8->GetPad(1)->SetLeftMargin(0.12); c8->GetPad(1)->SetBottomMargin(0.13); hDumEtaMul->Draw(); gMulEta->Draw("pc"); gMulEta2->Draw("pc"); legEta2->Draw();
  c8->cd(2); gPad->SetLogx(1); gPad->SetTicks(); c8->GetPad(2)->SetLeftMargin(0.12); c8->GetPad(2)->SetBottomMargin(0.13); hDumPtMul->Draw(); gMulPt->Draw("pc"); gMulPt2->Draw("pc"); legPt2->Draw();
  saveCanvas(c8, "files", "MultipleReconstruction3D");
  
  // Fakes
  TGraphAsymmErrors *gFakEta = new TGraphAsymmErrors();  gFakEta->SetName("gFakEta");
  gFakEta->BayesDivide(hFakEta,hRecEta);
  gFakEta->SetMarkerStyle(25);
  gFakEta->SetLineStyle(2);
  gFakEta->SetLineColor(2);
  gFakEta->SetMarkerColor(2);

  TGraphAsymmErrors *gFakPt = new TGraphAsymmErrors(); gFakPt->SetName("gFakPt");
  gFakPt->BayesDivide(hFakPt,hRecPt);
  gFakPt->SetMarkerStyle(25);
  gFakPt->SetLineColor(2);
  gFakPt->SetMarkerColor(2);

  TGraphAsymmErrors *gFakEta2 = new TGraphAsymmErrors(); gFakEta2->SetName("gFakEta2");
  gFakEta2->BayesDivide(hFakEta2,hRecEta2);
  gFakEta2->SetMarkerStyle(24);
  gFakEta2->SetLineColor(4);
  gFakEta2->SetMarkerColor(4);

  TGraphAsymmErrors *gFakPt2 = new TGraphAsymmErrors();  gFakPt2->SetName("gFakPt2");
  gFakPt2->BayesDivide(hFakPt2,hRecPt2);
  gFakPt2->SetMarkerStyle(24);
  gFakPt2->SetLineStyle(4);
  gFakPt2->SetLineColor(4);
  gFakPt2->SetMarkerColor(4);

  TCanvas* c9 = makeMultiCanvas("c9", "Fake Fraction", 2,1);
  hDumEtaFak=(TH1F*) hDumEta2->Clone("hDumEtaMul"); fixedFontHist1D(hDumEtaFak, 1.05,1.2); hDumEtaFak->GetYaxis()->SetRangeUser(0.,0.09);
  hDumEtaFak->GetYaxis()->SetTitle("Fake Reconstruction Fraction");
  hDumPtFak=(TH1F*) hDumPt2->Clone("hDumPtMul"); fixedFontHist1D(hDumPtFak, 1.05,1.2); hDumPtFak->GetYaxis()->SetRangeUser(0,1);
  hDumPtFak->GetYaxis()->SetTitle("Fake Reconstruction Fraction");
  c9->cd(1); hDumEtaFak->Draw(); gFakEta->Draw("pc"); gFakEta2->Draw("pc"); legEta2->Draw();
  gPad->SetTicks(); gPad->SetLeftMargin(0.12); gPad->SetBottomMargin(0.13);
  c9->cd(2); hDumPtFak->Draw(); gFakPt->Draw("pc"); gFakPt2->Draw("pc"); legPt2->Draw();
  gPad->SetTicks(); gPad->SetLeftMargin(0.12); gPad->SetBottomMargin(0.13); gPad->SetLogx(1);
  saveCanvas(c9, "files", "FakeRate3D");

  // Secondaries
  TGraphAsymmErrors *gSecEta = new TGraphAsymmErrors(); gSecEta->SetName("gSecEta");
  gSecEta->BayesDivide(hSecEta,hRecEta);
  gSecEta->SetMarkerStyle(25);
  gSecEta->SetLineStyle(2);
  gSecEta->SetLineColor(2);
  gSecEta->SetMarkerColor(2);

  TGraphAsymmErrors *gSecPt = new TGraphAsymmErrors(); gSecPt->SetName("gSecPt");
  gSecPt->BayesDivide(hSecPt,hRecPt);
  gSecPt->SetMarkerStyle(25);
  gSecPt->SetLineColor(2);
  gSecPt->SetMarkerColor(2);

  TGraphAsymmErrors *gSecEta2 = new TGraphAsymmErrors(); gSecEta2->SetName("gSecEta2");
  gSecEta2->BayesDivide(hSecEta2,hRecEta2);
  gSecEta2->SetMarkerStyle(24);
  gSecEta2->SetLineColor(4);
  gSecEta2->SetMarkerColor(4);

  TGraphAsymmErrors *gSecPt2 = new TGraphAsymmErrors();  gSecPt2->SetName("gSecPt2");
  gSecPt2->BayesDivide(hSecPt2,hRecPt2);
  gSecPt2->SetMarkerStyle(24);
  gSecPt2->SetLineStyle(4);
  gSecPt2->SetLineColor(4);
  gSecPt2->SetMarkerColor(4);

  TCanvas* c10 = makeMultiCanvas("c10", "Secondary Fraction", 2, 1);
  hDumEtaSec=(TH1F*) hDumEta2->Clone("hDumEtaMul"); fixedFontHist1D(hDumEtaSec, 1.05,1.3); hDumEtaSec->GetYaxis()->SetRangeUser(0.,0.012);
  hDumEtaSec->GetYaxis()->SetTitle("Non-Primary Reconstruction Fraction");
  hDumPtSec=(TH1F*) hDumPt2->Clone("hDumPtMul"); fixedFontHist1D(hDumPtSec, 1.05, 1.3);hDumPtSec->GetYaxis()->SetRangeUser(0.,0.1);
  hDumPtSec->GetYaxis()->SetTitle("Non-Primary Reconstruction Fraction");
  c10->cd(1); hDumEtaSec->Draw(); gSecEta->Draw("pc"); gSecEta2->Draw("pc"); legEta2->Draw();
  gPad->SetTicks(); gPad->SetLeftMargin(0.15); gPad->SetBottomMargin(0.13); 
  c10->cd(2); hDumPtSec->Draw(); gSecPt->Draw("pc"); gSecPt2->Draw("pc"); legPt2->Draw();
  gPad->SetTicks(); gPad->SetLeftMargin(0.15); gPad->SetBottomMargin(0.13); gPad->SetLogx(1);
  saveCanvas(c10, "files", "SecondaryReconstruction3D");

  TFile *fout = new TFile("test.root","RECREATE");
  gEffPt->Write(); gEffPt2->Write(); gEffEta->Write(); gEffEta2->Write();
  gMulPt->Write(); gMulPt2->Write(); gMulEta->Write(); gMulEta2->Write();
  gFakPt->Write(); gFakPt2->Write(); gFakEta->Write(); gFakEta2->Write();
  gSecPt->Write(); gSecPt2->Write(); gSecEta->Write(); gSecEta2->Write();
  fout->Close();
}
예제 #9
0
파일: ToyIter.C 프로젝트: pellicci/UserCode
int main(int argc, char* argv[])
{
  char *filename;
  Int_t nexp = 0, nev = 0, SEED = 0;
  Double_t c1val = 0., c2val = 0.;
  Double_t c1pval = 0., c2pval = 0.;
  Double_t c1mval = 0., c2mval = 0.;

  for(Int_t i=1;i<argc;i++){
    char *pchar = argv[i];

    switch(pchar[0]){

    case '-':{

      switch(pchar[1]){
      case 'f':
	filename = argv[i+1];
	cout << "File name used in this toy " << filename << endl;
	break;

      case 'e':
	nexp = atoi(argv[i+1]);
	cout << "Number of experiments " << nexp << endl;
	break;

      case 'n':
	nev = atoi(argv[i+1]);
	cout << "Number of events per experiment " << nev << endl;
	break;

      case 's':
        SEED = atoi(argv[i+1]);
        break;

      case '1':
	c1pval = atof(argv[i+1]);
	cout << "The c1 value is " << c1pval << endl;
        break;

      case '2':
	c1mval = atof(argv[i+1]);
	cout << "The c1 value is " << c1mval << endl;
        break;

      case '3':
        c2pval = atof(argv[i+1]);
	cout << "The c2 values is " << c2pval << endl;
        break;

     case '4':
        c2mval = atof(argv[i+1]);
	cout << "The c2 values is " << c2mval << endl;
        break;

      case 'x':
        c1val = atof(argv[i+1]);
	cout << "The c1 value is " << c1pval << endl;
        break;

      case 'y':
        c2val = atof(argv[i+1]);
        cout << "The c2 values is " << c2pval << endl;
        break;
      }
    }
    }

  }

  //set the seed and the generator used by EvtGen
  RooRandom::randomGenerator()->SetSeed(SEED);
  cout << "  Toy seed ............. " << (RooRandom::randomGenerator()->GetSeed()) << endl;

  //define DalitzSpace for generation
  EvtPDL pdl;
  pdl.readPDT("evt.pdl");
  EvtDecayMode mode("D0 -> K- pi+ pi0");
  EvtDalitzPlot dalitzSpace(mode);

  Bool_t doGen = kFALSE;
  Bool_t doFit = kTRUE;
  Bool_t extract = kFALSE;

  RooRealVar tau("tau","tau",0.4099);
  RooRealVar m2Kpi_d0mass("m2Kpi_d0mass","m2Kpi_d0mass",1.,dalitzSpace.qAbsMin(EvtCyclic3::AB),dalitzSpace.qAbsMax(EvtCyclic3::AB));
  RooRealVar m2Kpi0_d0mass("m2Kpi0_d0mass","m2Kpi0_d0mass",1.,dalitzSpace.qAbsMin(EvtCyclic3::AC),dalitzSpace.qAbsMax(EvtCyclic3::AC));
  RooRealVar d0Lifetime("d0Lifetime","d0Lifetime",-2.,4.);
  RooRealVar d0LifetimeErr("d0LifetimeErr","d0LifetimeErr",0.0000001,0.5);
  RooCategory D0flav("D0flav","D0flav");
  D0flav.defineType("D0",-1);
  D0flav.defineType("antiD0",1);

  RooRealVar scalefact1("scalefact1","scalefact1",3.20);
  RooRealVar scalefact2("scalefact2","scalefact2",1.42);
  RooRealVar scalefact3("scalefact3","scalefact3",0.94);

  RooRealVar c1("c1","c1",c1val,-3.,3.);
  RooRealVar c2("c2","c2",c2val,-3.,3.);
  RooRealVar c1p("c1p","c1p",c1pval,-3.,3.);
  RooRealVar c2p("c2p","c2p",c2pval,-3.,3.);
  RooRealVar c1m("c1m","c1m",c1mval,-3.,3.);
  RooRealVar c2m("c2m","c2m",c2mval,-3.,3.);

  c1p.setConstant(kTRUE);
  c2p.setConstant(kTRUE);

  m2Kpi_d0mass.setBins(10);
  m2Kpi0_d0mass.setBins(10);
  d0Lifetime.setBins(8);
  d0LifetimeErr.setBins(10);

  //Construct signal pdf
  RooRealVar bias("bias","bias",0.0047);
  RooRealVar one("one","one",1.);

  //consider the resolution or the truth model
  RooGaussModel gm1("gm1","gauss model 1",d0Lifetime,bias,d0LifetimeErr,one,scalefact1) ;
  RooGaussModel gm2("gm2","gauss model 2",d0Lifetime,bias,d0LifetimeErr,one,scalefact2) ;
  RooGaussModel gm3("gm3","gauss model 3",d0Lifetime,bias,d0LifetimeErr,one,scalefact3) ;
  //RooTruthModel gm("gm","truth model",d0Lifetime);

  RooRealVar N1("N1","N1",0.0052);
  RooRealVar N2("N2","N2",0.179);

  RooFormulaVar f2("f2","f2","(1-@0)*@1",RooArgList(N1,N2));
  RooFormulaVar f3("f3","f3","(1-@0)*(1-@1)",RooArgList(N1,N2));
  RooAddModel gm("gm","gm",RooArgList(gm2,gm3,gm1),RooArgList(f2,f3));

  string dirname = "configmaps/effmapping_std/";

  RooTimepdf TOTsigD0("TOTsigD0","TOTsigD0",d0Lifetime,m2Kpi_d0mass,m2Kpi0_d0mass,gm,&dalitzSpace,tau,c1p,c2p,-1,dirname);
  RooTimepdf TOTsigantiD0("TOTsigantiD0","TOTsigantiD0",d0Lifetime,m2Kpi_d0mass,m2Kpi0_d0mass,gm,&dalitzSpace,tau,c1p,c2p,-1,dirname);
 
  RooSimultaneous TOTTime("TOTTime","TOTTime",D0flav);
  TOTTime.addPdf(TOTsigD0,"D0");
  TOTTime.addPdf(TOTsigantiD0,"antiD0");

  //////////////////////////
  // BACKGROUND
  /////////////////////////

  TFile RSfile("DataSet_out_reduced_RS.root");
  gROOT->cd();
  RooDataSet *RSdata = (RooDataSet*)RSfile.Get("fulldata");

  m2Kpi_d0mass.setBins(150);
  m2Kpi0_d0mass.setBins(150);
  d0Lifetime.setBins(70);
  d0LifetimeErr.setBins(20);
  /*
  TH3F *mis_h = m2Kpi_d0mass.createHistogram("mis_h",m2Kpi0_d0mass,d0Lifetime,"");
  RSdata->fillHistogram(mis_h,RooArgList(m2Kpi_d0mass,m2Kpi0_d0mass,d0Lifetime));
  mis_h->Sumw2();
  RooDataHist *mis_hist = new RooDataHist("mis_hist","mis_hist",RooArgList(m2Kpi_d0mass,m2Kpi0_d0mass,d0Lifetime),mis_h);
  RooHistPdf Tot_mis("Tot_mis","Tot_mis",RooArgList(m2Kpi_d0mass,m2Kpi0_d0mass,d0Lifetime),*mis_hist);
  */
  TH3F *mis_hp = m2Kpi_d0mass.createHistogram("mis_hp",m2Kpi0_d0mass,d0Lifetime,"");
  RSdata->fillHistogram(mis_hp,RooArgList(m2Kpi_d0mass,m2Kpi0_d0mass,d0Lifetime),"D0flav == 1");
  mis_hp->Sumw2();
  RooDataHist *mis_histp = new RooDataHist("mis_histp","mis_histp",RooArgList(m2Kpi_d0mass,m2Kpi0_d0mass,d0Lifetime),mis_hp);
  RooHistPdf Tot_misp("Tot_misp","Tot_misp",RooArgList(m2Kpi_d0mass,m2Kpi0_d0mass,d0Lifetime),*mis_histp);

  TH3F *mis_hm = m2Kpi_d0mass.createHistogram("mis_hm",m2Kpi0_d0mass,d0Lifetime,"");
  RSdata->fillHistogram(mis_hm,RooArgList(m2Kpi_d0mass,m2Kpi0_d0mass,d0Lifetime),"D0flav == -1");
  mis_hm->Sumw2();
  RooDataHist *mis_histm = new RooDataHist("mis_histm","mis_histm",RooArgList(m2Kpi_d0mass,m2Kpi0_d0mass,d0Lifetime),mis_hm);
  RooHistPdf Tot_mism("Tot_mism","Tot_mism",RooArgList(m2Kpi_d0mass,m2Kpi0_d0mass,d0Lifetime),*mis_histm);

  RooSimultaneous Tot_mis("Tot_mis","Tot_mis",D0flav);
  Tot_mis.addPdf(Tot_misp,"D0");
  Tot_mis.addPdf(Tot_mism,"antiD0");

  cout << "///////////////" << endl;
  cout << "Sample of D0bar RS : " << mis_histp->numEntries(kTRUE) << endl;
  cout << "Sample of D0 RS : " << mis_histm->numEntries(kTRUE) << endl;
  cout << "///////////////" << endl;

  m2Kpi_d0mass.setBins(10);
  m2Kpi0_d0mass.setBins(10);
  d0Lifetime.setBins(8);
  d0LifetimeErr.setBins(10);

  RooArgSet observ(d0Lifetime,m2Kpi_d0mass,m2Kpi0_d0mass);
  RooArgSet tot_var(d0Lifetime,m2Kpi_d0mass,m2Kpi0_d0mass,d0LifetimeErr,D0flav);

  TFile WSfile("DataSet_out_reduced_WS.root");
  gROOT->cd();
  RooDataSet *databkg = (RooDataSet*)WSfile.Get("fulldata");
  RooDataSet *leftdata = (RooDataSet*)databkg->reduce("d0Mass > 1.74 && d0Mass < 1.78");
  RooDataSet *rightdata = (RooDataSet*)databkg->reduce("d0Mass > 1.94 && d0Mass < 1.98");
  databkg->setWeightVar(0);
  rightdata->setWeightVar(0);
  leftdata->setWeightVar(0);

  TH3F *lefth = m2Kpi_d0mass.createHistogram("lefth",m2Kpi0_d0mass,d0Lifetime,"");
  leftdata->fillHistogram(lefth,RooArgList(m2Kpi_d0mass,m2Kpi0_d0mass,d0Lifetime));
  TH3F *righth = m2Kpi_d0mass.createHistogram("righth",m2Kpi0_d0mass,d0Lifetime,"");
  rightdata->fillHistogram(righth,RooArgList(m2Kpi_d0mass,m2Kpi0_d0mass,d0Lifetime));
  righth->Scale(lefth->Integral()/righth->Integral());
  lefth->Sumw2();
  righth->Sumw2();
  lefth->Add(righth);
  lefth->Sumw2();

  RooDataHist *lefthist = new RooDataHist("lefthist","lefthist",RooArgList(m2Kpi_d0mass,m2Kpi0_d0mass,d0Lifetime),lefth);
  RooHistPdf Tot_comb("Tot_comb","Tot_comb",RooArgList(m2Kpi_d0mass,m2Kpi0_d0mass,d0Lifetime),*lefthist);

  Float_t totnonorm = 1508. + 791. + 663. + 47.;
  Float_t ratio = nev/totnonorm;

  RooRealVar Nsig("Nsig","Nsig",1508.*ratio);
  RooRealVar Nmis("Nmis","Nmis",791.*ratio);
  RooRealVar Ncomb("Ncomb","Ncomb",(663. + 47.)*ratio);

  d0LifetimeErr.setBins(100);
  RooDataSet *ProtoData_err = (RooDataSet*)RSdata->reduce(RooArgSet(d0LifetimeErr));
  TH1F *err_sig_h = (TH1F*)d0LifetimeErr.createHistogram("err_sig_h");
  ProtoData_err->fillHistogram(err_sig_h,RooArgSet(d0LifetimeErr));
  RooDataHist terr_sig("terr_sig","terr_sig",RooArgSet(d0LifetimeErr),err_sig_h);
  RooHistPdf terr_sig_pdf("terr_sig_pdf","terr_sig_pdf",RooArgSet(d0LifetimeErr),terr_sig,3);
  d0LifetimeErr.setBins(10);

  RooDataSet *ProtoData_bkg = (RooDataSet*)databkg->reduce(RooArgSet(d0LifetimeErr));
  TH1F *err_bkg_h = (TH1F*)d0LifetimeErr.createHistogram("err_bkg_h");
  ProtoData_bkg->fillHistogram(err_bkg_h,RooArgSet(d0LifetimeErr));
  err_bkg_h->Scale(err_sig_h->Integral()/err_bkg_h->Integral());
  RooDataHist terr_bkg("terr_bkg","terr_bkg",RooArgSet(d0LifetimeErr),err_bkg_h);
  RooHistPdf terr_bkg_pdf("terr_bkg_pdf","terr_bkg_pdf",RooArgSet(d0LifetimeErr),terr_bkg,3);

  RooDataSet *ProtoData_flav_1 = (RooDataSet*)RSdata->reduce(RooArgSet(D0flav));
  RooDataSet *ProtoData_flav = (RooDataSet*)ProtoData_flav_1->reduce(EventRange(1,(Int_t)((1508 + 791)*ratio)));
  //RooDataHist flav_sig("flav_sig","flav_sig",RooArgSet(D0flav),*ProtoData_flav);
  //RooHistPdf flav_sig_pdf("flav_sig_pdf","flav_sig_pdf",RooArgSet(D0flav),flav_sig);

  RooDataSet *ProtoData_flav_bkg_1 = (RooDataSet*)databkg->reduce(RooArgSet(D0flav));
  RooDataSet *ProtoData_flav_bkg = (RooDataSet*)ProtoData_flav_bkg_1->reduce(EventRange(1,(Int_t)((663 + 47)*ratio)));
  //RooDataHist flav_bkg("flav_bkg","flav_bkg",RooArgSet(D0flav),*ProtoData_flav_bkg);
  //RooHistPdf flav_bkg_pdf("flav_bkg_pdf","flav_bkg_pdf",RooArgSet(D0flav),flav_bkg);

  ProtoData_flav->append(*ProtoData_flav_bkg);

  RooProdPdf totsig_norm("totsig_norm","totsig_norm",RooArgSet(terr_sig_pdf),Conditional(TOTTime,observ));
  RooProdPdf totmis_norm("totmis_norm","totmis_norm",RooArgSet(terr_sig_pdf),Conditional(Tot_mis,observ));
  RooProdPdf totbkg_norm("totbkg_norm","totbkg_norm",RooArgSet(terr_bkg_pdf),Conditional(Tot_comb,observ));
  /*
  RooProdPdf totsig_norm("totsig_norm","totsig_norm",RooArgSet(terr_sig_pdf),Conditional(TOTsigD0,observ));
  RooProdPdf totmis_norm("totmis_norm","totmis_norm",RooArgSet(terr_sig_pdf),Conditional(Tot_mis,observ));
  RooProdPdf totbkg_norm("totbkg_norm","totbkg_norm",RooArgSet(terr_bkg_pdf),Conditional(Tot_comb,observ));
  */
  //Signal + background
  RooAddPdf TOTpdf("TOTpdf","TOTpdf",RooArgList(totsig_norm,totmis_norm,totbkg_norm),RooArgList(Nsig,Nmis,Ncomb));

  RooMCStudy mgr(totsig_norm,tot_var,FitOptions(Save(1),Extended(0),Minos(0)),Extended(0),ConditionalObservables(D0flav),RooFit::ProtoData(*ProtoData_flav,1));
  //RooMCStudy mgr(totsig_norm,tot_var,FitOptions(ConditionalObservables(RooArgSet(D0flav)),Save(1),Extended(0)),Extended(0),RooFit::ProtoData(*ConditDataset,1));

  TString dataname(filename);
  dataname.Append(".dat");
  TString toyname(filename);
  toyname.Append("_fixed.root");

  if(doGen && !doFit) mgr.generate(nexp,nev,kFALSE,dataname);
  if(doFit && !doGen) mgr.fit(nexp,dataname);
  if(doGen && doFit) mgr.generateAndFit(nexp,nev,kFALSE,dataname);

  if(doFit){
  TFile f(toyname,"RECREATE");
  f.cd();
  (RooFitResult*)mgr.fitResult(0)->Write();
  mgr.fitParDataSet().tree().Write();
  f.Close();
  }

  if(extract){

  RooFitResult *theRes = (RooFitResult*)mgr.fitResult(0);

    RooRealVar myc1("myc1","myc1",-10.,10.);
    RooRealVar myc2("myc2","myc2",-10.,10.);
    RooRealVar myratio("myratio","myratio",0.,0.,1.);
    RooRealVar myx("myx","myx",0.,-1.,1.);
    RooRealVar myy("myy","myy",0.,-1.,1.);

    Double_t NrsNws = 2760./1198329;
    Double_t ratioerr = sqrt(pow(96.,2.) + pow(NrsNws,2.)*pow(2760.,2.))/1198329.;
    RooDataSet *parFloat = new RooDataSet("parFloat","parFloat",RooArgList(myratio,myx,myy));

    RooTimepdf mysigD0("mysigD0","mysigD0",d0Lifetime,m2Kpi_d0mass,m2Kpi0_d0mass,gm,&dalitzSpace,tau,c1,c2,-1,dirname);
    Double_t myDenom = mysigD0.createIntegral(RooArgSet(m2Kpi_d0mass,m2Kpi0_d0mass,d0Lifetime))->getVal();

    cout << "x' " << c2.getVal()*sqrt(NrsNws/myDenom) << endl;
    cout << "y' " << c1.getVal()*sqrt(NrsNws/myDenom) << endl;
    cout << "r0^2 " << NrsNws/myDenom << endl;

    for(Int_t j=0;j<1000;j++){
      cout << "Performing step number " << j << endl;
      RooArgList floated = theRes->randomizePars();
      myc1.setVal(((RooAbsReal*)floated.find("c1"))->getVal());
      myc2.setVal(((RooAbsReal*)floated.find("c2"))->getVal());

      Double_t myDenom = mysigD0.createIntegral(RooArgSet(m2Kpi_d0mass,m2Kpi0_d0mass,d0Lifetime))->getVal();
      Double_t myNum = RooRandom::randomGenerator()->Gaus(NrsNws,ratioerr);

      myratio.setVal(myNum/myDenom);
      myx.setVal(myc2.getVal()*sqrt((myNum/myDenom)));
      myy.setVal(myc1.getVal()*sqrt((myNum/myDenom)));

      parFloat->add(RooArgSet(myratio,myx,myy));
    }

    TString floatname(filename);
    floatname.Append("_float.root");

    TFile *f1 = new TFile(floatname,"RECREATE");
    f1->cd();
    parFloat->Write();
    f1->Close();
  }

  return 0;
}
예제 #10
0
void analyze_tracklet(char * infile){
  TFile* inf = new  TFile(infile);
  TTree* t = dynamic_cast<TTree*>(inf->Get("ana/PixelTree"));

  int zbins = 1;
  int hitbins = 100;
  int nbins = zbins*hitbins;
  
  // Selection on Hits and events
  SelectionCriteria cuts;
  cuts.drCut   = 0.4;      // to remove double hit
  cuts.dPhiCut = 0.04;     // to remove double hit
  cuts.vzCut   = 10;       // vertex cut

  cuts.verbose_ = false;
  cuts.useDeltaPhi_ = false;
  cuts.checkSecondLayer_ = true;
  
  // Output PDF
  TFile* outf = new TFile("output.root","recreate");
  TNtuple *ntmatched = new TNtuple("ntmatched","","eta1:matchedeta:phi1:matchedphi:deta:dphi:signalCheck:tid:r1id:r2id:evtid:nhit1:sid:ptype:vz");
  TNtuple *ntmult = new TNtuple("ntmult","","mult:nhit1:nhit2");

  vector<TH1D*> layer1HitEta;
  layer1HitEta.reserve(nbins);
  vector<TH1D*> layer1HitPhi;
  layer1HitPhi.reserve(nbins);

  vector<TH1D*> layer2HitEta;
  layer2HitEta.reserve(nbins);
  vector<TH1D*> layer2HitPhi;
  layer2HitPhi.reserve(nbins);
    
  for(int i = 0; i< nbins; ++i){
    layer1HitEta[i] = new TH1D(Form("dNdEtaHits1_%02d",i),"dNdEta Hits Layer 1",500,-3,3);
    layer2HitEta[i] = new TH1D(Form("dNdEtaHits2_%02d",i),"dNdEta Hits Layer 2",500,-3,3);
    layer1HitPhi[i] = new TH1D(Form("dNdPhiHits1_%02d",i),"dNdPhi Hits Layer 1",500,-3.2,3.2);
    layer2HitPhi[i] = new TH1D(Form("dNdPhiHits2_%02d",i),"dNdPhi Hits Layer 2",500,-3.2,3.2);
  }
  
  TH1D* hm1 = new TH1D("hm1","Number of Hits Layer 1",50,0,50);

  TH3F* nhits = new TH3F("nhits","",100,0,100,100,0,100,100,0,100);
  
  // Parameters for the tree:
  Parameters par;  

  t->SetBranchAddress("eta1",par.eta1);
  t->SetBranchAddress("phi1",par.phi1);
  t->SetBranchAddress("r1",par.r1);
  t->SetBranchAddress("eta2",par.eta2);
  t->SetBranchAddress("phi2",par.phi2);
  t->SetBranchAddress("r2",par.r2);
  t->SetBranchAddress("nhits1",&par.nhits1);
  t->SetBranchAddress("nhits2",&par.nhits2);
  t->SetBranchAddress("mult",&par.mult);
  t->SetBranchAddress("vz",par.vz);
  t->SetBranchAddress("nv",&par.nv);

  cout <<"Number of Events: "<<t->GetEntries()<<endl;

  // Main loop
  for(int i = 0; i< t->GetEntries(); ++i){    
    t->GetEntry(i);
    if (i % 1000 == 0) cout <<"Event "<<i<<endl;    
    // Selection on Events
    if (fabs(par.vz[1])>cuts.vzCut) continue;

    hm1->Fill(par.mult);

    // Process the first layer
    vector<RecoHit> layer1 = removeDoubleHits(par, cuts,1);
    double mult = 0;
    for(int ihit = 0; ihit< (int)layer1.size(); ++ihit) {
      int hitbin1 = (int)layer1.size();
      if (hitbin1 > 99) hitbin1 = 99;
      layer1HitEta[hitbin1]->Fill(layer1[ihit].eta);
      layer1HitPhi[hitbin1]->Fill(layer1[ihit].phi);
      if(fabs(layer1[ihit].eta)<1) mult++;
    }

    // Process the second layer
    vector<RecoHit> layer2 = removeDoubleHits(par, cuts,2);

    for(int ihit = 0; ihit< (int)layer2.size(); ++ihit) {
      int hitbin2 = (int)layer2.size();
      if (hitbin2 > 99) hitbin2 = 99;
      layer2HitEta[hitbin2]->Fill(layer2[ihit].eta);
      layer2HitPhi[hitbin2]->Fill(layer2[ihit].phi);
    }

    // Form Tracklets        
    vector<Tracklet> protoTracklets = recoProtoTracklets(layer1,layer2);
    vector<Tracklet> recoTracklets = cleanTracklets(protoTracklets,0,cuts);

    // Fill Ntuple
    for (int j=0;j<(int)recoTracklets.size();j++)
    {
        float var[100];
	var[0] = recoTracklets[j].eta1();
	var[1] = recoTracklets[j].eta2();
	var[2] = recoTracklets[j].phi1();
	var[3] = recoTracklets[j].phi2();
	var[4] = recoTracklets[j].deta();
	var[5] = recoTracklets[j].dphi();
	var[6] = 0;
	var[7] = recoTracklets[j].getId();
	var[8] = recoTracklets[j].getId1();
	var[9] = recoTracklets[j].getId2();
	var[10] = i;
	var[11] = (int)par.mult;
	var[12] = recoTracklets[j].getSId();
	var[13] = recoTracklets[j].getType();
	var[14] = par.vz[1];
        ntmatched->Fill(var);
    }

    nhits->Fill(mult,layer1.size(),layer2.size());
    ntmult->Fill(mult,layer1.size(),layer2.size());
  }

  outf->Write();
  outf->Close(); 
}
예제 #11
0
int main(int argc, char **argv){
	TApplication *fApp = new TApplication("Test", NULL, NULL);
	int xbins = 10;
	int ybins = 10;
	int zbins = 10;
	int xlow = 0, xhigh = 10.;
	int ylow = 0, yhigh = 10.;
	int zlow = 0, zhigh = 10.;
	TCanvas *c = new TCanvas("TestCanvas", "ScatteringAngleCanvas", 800, 600);
	c->Divide(4,2);
	TH3F *hist = new TH3F("Test3DHist","Test3DHist",xbins,xlow,xhigh,ybins,ylow,yhigh,zbins,zlow,zhigh);
	for(int i = 0 ; i < 10 ; i++){
		for(int j = 0 ; j < 10; j++){
			for(int k = 0 ; k < 10 ; k++){
				hist->Fill(2,3,4);
				//hist->Fill(2,3,8);
			}
		}
	}


	TRandom t;
	TH3F *histValue = new TH3F("Test3DHistvalue","Test3DHistvalue",xbins,xlow,xhigh,ybins,ylow,yhigh,zbins,zlow,zhigh);
	int count = 0;
	float sum = 0.;
	for(int i = 0 ; i < 2 ; i++){
			for(int j = 0 ; j < 3; j++){
				for(int k = 0 ; k < 3 ; k++){
					count++;
					float val = t.Uniform(1,1010);
					std::cout<<"Count : " << count <<" : Val : "<< val << std::endl;
					sum += val;
					histValue->Fill(2,3,4,val);
					//hist->Fill(2,3,8);
				}
			}
		}

	std::cout<<"Sum : " << sum <<" : Average : " << (sum/1000) << std::endl;



	c->cd(1);
	hist->Draw();
	c->cd(2);
	hist->Project3D("x")->Draw();
	c->cd(3);
	hist->Project3D("y")->Draw();
	c->cd(4);
	hist->Project3D("yz")->Draw("0lego1 PFC");
	c->cd(5);
	histValue->Draw();
	histValue->Divide(hist);
	c->cd(6);
	histValue->Draw();

	sum = 0.;
	count = 0;
	TH2F *hist2DValue = new TH2F("Test2DHistvalue","Test2DHistvalue",xbins,xlow,xhigh,ybins,ylow,yhigh);
	for(int j = 0 ; j < 3; j++){
					for(int k = 0 ; k < 3 ; k++){
						count++;
						float val = t.Uniform(1,1010);
						std::cout<<"Count : " << count <<" : Val : "<< val << std::endl;
						sum += val;
						hist2DValue->Fill(2,3,val);
						//hist->Fill(2,3,8);
					}
				}

	std::cout<<"Sum : " << sum <<" : Average : " << (sum/count) << std::endl;

	c->cd(7);
	hist2DValue->Draw();

	fApp->Run();

}
예제 #12
0
int main(int argc, char* argv[])
{
  string name;

  for(Int_t i=1;i<argc;i++){
    char *pchar = argv[i];

    switch(pchar[0]){

    case '-':{

      switch(pchar[1]){
      case 'n':
        name = argv[i+1];
        cout << "Name of the configuration key " << name << endl;
        break;
      }
    }
    }
  }

  Bool_t doFit = kFALSE;
  Bool_t extract = kFALSE;
  Bool_t doFrac = kFALSE;
  Bool_t doPlots = kTRUE;
  Bool_t doChi2 = kFALSE;

  BaBarStyle p;
  p.SetBaBarStyle();
  gROOT->GetStyle("BABAR")->SetPalette(1);
  gROOT->GetStyle("BABAR")->SetPadTopMargin(0.04);
  gROOT->GetStyle("BABAR")->SetPadLeftMargin(0.17);
  gROOT->GetStyle("BABAR")->SetPadBottomMargin(0.19);
  gROOT->GetStyle("BABAR")->SetTitleSize(0.08,"xyz"); // set the 3 axes title size 

  //define DalitzSpace for generation
  EvtPDL pdl;
  pdl.readPDT("evt.pdl");
  EvtDecayMode mode("D0 -> K- pi+ pi0");
  EvtDalitzPlot dalitzSpace(mode);

  RooRealVar tau("tau","tau",0.4099);
  RooRealVar m2Kpi_d0mass("m2Kpi_d0mass","m2Kpi_d0mass",1.,dalitzSpace.qAbsMin(EvtCyclic3::AB),dalitzSpace.qAbsMax(EvtCyclic3::AB));
  RooRealVar m2Kpi0_d0mass("m2Kpi0_d0mass","m2Kpi0_d0mass",1.,dalitzSpace.qAbsMin(EvtCyclic3::AC),dalitzSpace.qAbsMax(EvtCyclic3::AC));
  RooRealVar m2pipi0_d0mass("m2pipi0_d0mass","m2pipi0_d0mass",1.,dalitzSpace.qAbsMin(EvtCyclic3::BC),dalitzSpace.qAbsMax(EvtCyclic3::BC));
  RooRealVar d0Lifetime("d0Lifetime","d0Lifetime",-2.,4.);
  RooRealVar d0LifetimeErr("d0LifetimeErr","d0LifetimeErr",0.0000001,0.5);
  RooCategory D0flav("D0flav","D0flav");
  D0flav.defineType("D0",-1);
  D0flav.defineType("antiD0",1);

  RooRealVar scalefact1("scalefact1","scalefact1",3.20);
  RooRealVar scalefact2("scalefact2","scalefact2",1.42);
  RooRealVar scalefact3("scalefact3","scalefact3",0.94);

  RooRealVar c1("c1","c1",-2.,2.);
  RooRealVar c2("c2","c2",-2.,2.);
  RooUnblindOffset c1_unblind("c1_unblind","c1 (unblind)","VaffanculoS",1.,c1) ;
  RooUnblindOffset c2_unblind("c2_unblind","c2 (unblind)","VaffanculoS",1.,c2) ;

  TFile fWS("DataSet_out_tmp.root");
  gROOT->cd();
  RooDataSet *data = (RooDataSet*)fWS.Get("fulldata");
  RooDataSet *data_clean = (RooDataSet*)data->reduce("d0LifetimeErr < 0.5 && d0Lifetime > -2. && d0Lifetime < 4. && deltaMass > 0.1449 && deltaMass < 0.1459");
  RooDataSet *dataWS_2 = (RooDataSet*)data_clean->reduce("isWS == 1");
  RooDataSet *dataWS = (RooDataSet*)dataWS_2->reduce("d0Mass > 1.8495 && d0Mass < 1.8795");
  RooDataSet *RSdata = (RooDataSet*)data_clean->reduce("isWS == 0 && d0Mass > 1.8495 && d0Mass < 1.8795");

  Double_t low12,hig12,low13,hig13,low23,hig23;
  Bool_t m12bool = dataWS->getRange(m2Kpi_d0mass,low12,hig12);
  Bool_t m13bool = dataWS->getRange(m2Kpi0_d0mass,low13,hig13);
  Bool_t m23bool = dataWS->getRange(m2pipi0_d0mass,low23,hig23);
  m2Kpi_d0mass.setRange(low12,hig12);
  m2Kpi0_d0mass.setRange(low13,hig13);
  m2pipi0_d0mass.setRange(low23,hig23);

  m2Kpi_d0mass.setBins(10);
  m2Kpi0_d0mass.setBins(10);
  d0Lifetime.setBins(8);
  d0LifetimeErr.setBins(10);
  m2pipi0_d0mass.setBins(10);

  Float_t total = pow(dalitzSpace.bigM(),2) + pow(dalitzSpace.mA(),2) + pow(dalitzSpace.mB(),2) + pow(dalitzSpace.mC(),2);
  RooRealVar totalm("totalm","totalm",total);
  RooFormulaVar mass13a("mass13a","@0-@1-@2",RooArgSet(totalm,m2Kpi_d0mass,m2pipi0_d0mass));

  //Construct signal pdf
  RooRealVar bias("bias","bias",0.0047) ;
  RooRealVar one("one","one",1.);

  //consider the resolution or the truth model
  RooGaussModel gm1("gm1","gauss model 1",d0Lifetime,bias,d0LifetimeErr,one,scalefact1) ;
  RooGaussModel gm2("gm2","gauss model 2",d0Lifetime,bias,d0LifetimeErr,one,scalefact2) ;
  RooGaussModel gm3("gm3","gauss model 3",d0Lifetime,bias,d0LifetimeErr,one,scalefact3) ;

  RooRealVar N1("N1","N1",0.0052);
  RooRealVar N2("N2","N2",0.179);

  RooFormulaVar f2("f2","f2","(1-@0)*@1",RooArgList(N1,N2));
  RooFormulaVar f3("f3","f3","(1-@0)*(1-@1)",RooArgList(N1,N2));
  RooAddModel gm("gm","gm",RooArgList(gm2,gm3,gm1),RooArgList(f2,f3));

  string dirname = "configmaps/effmapping_" + name + "/";

  RooTimepdf TOTsigD0("TOTsigD0","TOTsigD0",d0Lifetime,m2Kpi_d0mass,m2Kpi0_d0mass,gm,&dalitzSpace,tau,c1,c2,-1,dirname);
  //RooTimepdf TOTsigantiD0("TOTsigantiD0","TOTsigantiD0",d0Lifetime,m2Kpi_d0mass,m2Kpi0_d0mass,gm,&dalitzSpace,tau,c1_unblind,c2_unblind,1);
 
  //RooSimultaneous TOTTime("TOTTime","TOTTime",D0flav);
  //TOTTime.addPdf(TOTsigD0,"D0");
  //TOTTime.addPdf(TOTsigantiD0,"antiD0");

  RooTimepdf TOTsigD023("TOTsigD023","TOTsigD023",d0Lifetime,m2Kpi_d0mass,mass13a,gm,&dalitzSpace,tau,c1,c2,-1,dirname);

  //////////////////////////
  // BACKGROUND
  /////////////////////////

  //Mistag parametrization
  m2Kpi_d0mass.setBins(150);
  m2Kpi0_d0mass.setBins(150);
  m2pipi0_d0mass.setBins(150);
  d0Lifetime.setBins(70);

  TH3F *mis_h = m2Kpi_d0mass.createHistogram("mis_h",m2Kpi0_d0mass,d0Lifetime,"");
  RSdata->fillHistogram(mis_h,RooArgList(m2Kpi_d0mass,m2Kpi0_d0mass,d0Lifetime));
  mis_h->Sumw2();
  RooDataHist *mis_hist = new RooDataHist("mis_hist","mis_hist",RooArgList(m2Kpi_d0mass,m2Kpi0_d0mass,d0Lifetime),mis_h);
  RooHistPdf Tot_mis("Tot_mis","Tot_mis",RooArgList(m2Kpi_d0mass,m2Kpi0_d0mass,d0Lifetime),*mis_hist);

  TH3F *mis_h23 = m2Kpi_d0mass.createHistogram("mis_h",m2pipi0_d0mass,d0Lifetime,"");
  RSdata->fillHistogram(mis_h23,RooArgList(m2Kpi_d0mass,m2pipi0_d0mass,d0Lifetime));
  mis_h23->Sumw2();
  RooDataHist *mis_hist23 = new RooDataHist("mis_hist23","mis_hist23",RooArgList(m2Kpi_d0mass,m2pipi0_d0mass,d0Lifetime),mis_h23);
  RooHistPdf Tot_mis23("Tot_mis23","Tot_mis23",RooArgList(m2Kpi_d0mass,m2pipi0_d0mass,d0Lifetime),*mis_hist23);

  m2Kpi_d0mass.setBins(10);
  m2Kpi0_d0mass.setBins(10);
  m2pipi0_d0mass.setBins(10);
  d0Lifetime.setBins(8);
  d0LifetimeErr.setBins(10);

  RooArgSet observ(d0Lifetime,m2Kpi_d0mass,m2Kpi0_d0mass);
  RooArgSet observ23(d0Lifetime,m2Kpi_d0mass,m2pipi0_d0mass);
  RooArgSet tot_var(d0Lifetime,m2Kpi_d0mass,m2Kpi0_d0mass,d0LifetimeErr);

  //combinatoric
  RooDataSet *leftdata = (RooDataSet*)dataWS_2->reduce("d0Mass > 1.75 && d0Mass < 1.77");
  RooDataSet *rightdata = (RooDataSet*)dataWS_2->reduce("d0Mass > 1.95 && d0Mass < 1.97");
  RooDataSet *bkgdata = (RooDataSet*)dataWS_2->reduce("d0Mass > 1.95 || d0Mass < 1.77");
  rightdata->setWeightVar(0);
  leftdata->setWeightVar(0);

  TH3F *lefth = m2Kpi_d0mass.createHistogram("lefth",m2Kpi0_d0mass,d0Lifetime,"");
  leftdata->fillHistogram(lefth,RooArgList(m2Kpi_d0mass,m2Kpi0_d0mass,d0Lifetime));
  TH3F *righth = m2Kpi_d0mass.createHistogram("righth",m2Kpi0_d0mass,d0Lifetime,"");
  rightdata->fillHistogram(righth,RooArgList(m2Kpi_d0mass,m2Kpi0_d0mass,d0Lifetime));
  righth->Scale(lefth->Integral()/righth->Integral());
  lefth->Sumw2();
  righth->Sumw2();
  lefth->Add(righth);
  lefth->Sumw2();
  RooDataHist *lefthist = new RooDataHist("lefthist","lefthist",RooArgList(m2Kpi_d0mass,m2Kpi0_d0mass,d0Lifetime),lefth);
  RooHistPdf Tot_comb("Tot_comb","Tot_comb",RooArgList(m2Kpi_d0mass,m2Kpi0_d0mass,d0Lifetime),*lefthist);

  TH3F *lefth23 = m2Kpi_d0mass.createHistogram("lefth23",m2pipi0_d0mass,d0Lifetime,"");
  leftdata->fillHistogram(lefth23,RooArgList(m2Kpi_d0mass,m2pipi0_d0mass,d0Lifetime));
  TH3F *righth23 = m2Kpi_d0mass.createHistogram("righth23",m2pipi0_d0mass,d0Lifetime,"");
  rightdata->fillHistogram(righth23,RooArgList(m2Kpi_d0mass,m2pipi0_d0mass,d0Lifetime));
  righth23->Scale(lefth23->Integral()/righth23->Integral());
  lefth23->Sumw2();
  righth23->Sumw2();
  lefth23->Add(righth23);
  lefth23->Sumw2();
  RooDataHist *lefthist23 = new RooDataHist("lefthist23","lefthist23",RooArgList(m2Kpi_d0mass,m2pipi0_d0mass,d0Lifetime),lefth23);
  RooHistPdf Tot_comb23("Tot_comb23","Tot_comb23",RooArgList(m2Kpi_d0mass,m2pipi0_d0mass,d0Lifetime),*lefthist23);

  RooRealVar Nsig("Nsig","Nsig",1508.);
  RooRealVar Nmis("Nmis","Nmis",791.);
  RooRealVar Ncomb("Ncomb","Ncomb",(663. + 47.));

  d0LifetimeErr.setBins(100);
  RooDataSet *ProtoData_err = (RooDataSet*)RSdata->reduce(RooArgSet(d0LifetimeErr));
  TH1F *err_sig_h = (TH1F*)d0LifetimeErr.createHistogram("err_sig_h");
  ProtoData_err->fillHistogram(err_sig_h,RooArgSet(d0LifetimeErr));
  RooDataHist terr_sig("terr_sig","terr_sig",RooArgSet(d0LifetimeErr),err_sig_h);
  RooHistPdf terr_sig_pdf("terr_sig_pdf","terr_sig_pdf",RooArgSet(d0LifetimeErr),terr_sig,3);
  d0LifetimeErr.setBins(10);

  RooDataSet *ProtoData_bkg = (RooDataSet*)bkgdata->reduce(RooArgSet(d0LifetimeErr));
  TH1F *err_bkg_h = (TH1F*)d0LifetimeErr.createHistogram("err_bkg_h");
  ProtoData_bkg->fillHistogram(err_bkg_h,RooArgSet(d0LifetimeErr));
  err_bkg_h->Scale(err_sig_h->Integral()/err_bkg_h->Integral());
  RooDataHist terr_bkg("terr_bkg","terr_bkg",RooArgSet(d0LifetimeErr),err_bkg_h);
  RooHistPdf terr_bkg_pdf("terr_bkg_pdf","terr_bkg_pdf",RooArgSet(d0LifetimeErr),terr_bkg,3);

  RooProdPdf totsig_norm("totsig_norm","totsig_norm",RooArgSet(terr_sig_pdf),Conditional(TOTsigD0,observ));
  RooProdPdf totmis_norm("totmis_norm","totmis_norm",RooArgSet(terr_sig_pdf),Conditional(Tot_mis,observ));
  RooProdPdf totbkg_norm("totbkg_norm","totbkg_norm",RooArgSet(terr_bkg_pdf),Conditional(Tot_comb,observ));

  RooProdPdf totsig_norm23("totsig_norm23","totsig_norm23",RooArgSet(terr_sig_pdf),Conditional(TOTsigD023,observ23));
  RooProdPdf totmis_norm23("totmis_norm23","totmis_norm23",RooArgSet(terr_sig_pdf),Conditional(Tot_mis23,observ23));
  RooProdPdf totbkg_norm23("totbkg_norm23","totbkg_norm23",RooArgSet(terr_bkg_pdf),Conditional(Tot_comb23,observ23));

  //Signal + background
  RooAddPdf TOTpdf("TOTpdf","TOTpdf",RooArgList(totsig_norm,totmis_norm,totbkg_norm),RooArgList(Nsig,Nmis,Ncomb));
  RooAddPdf TOTpdf23("TOTpdf23","TOTpdf23",RooArgList(totsig_norm23,totmis_norm23,totbkg_norm23),RooArgList(Nsig,Nmis,Ncomb));

  if(doFit){

    RooFitResult *theRes = TOTpdf.fitTo(*dataWS,Save(1),Minos(0),Extended(0));

    string filename = "syst_root/fit_WS_" + name + ".root";
    TFile fout(filename.c_str(),"RECREATE");
    fout.cd();
    theRes->Write();
    fout.Close();
  }

  if(extract){
    TFile f("fitWS.root");
    RooFitResult* theRes = (RooFitResult*)f.Get("nll");
 
    RooRealVar myc1("myc1","myc1",-10.,10.);
    RooRealVar myc2("myc2","myc2",-10.,10.);
    RooRealVar myratio("myratio","myratio",0.,0.,1.);
    RooRealVar myx("myx","myx",0.,-1.,1.);
    RooRealVar myy("myy","myy",0.,-1.,1.);
 
    Double_t NrsNws = 2562./1132332.;
    Double_t ratioerr = sqrt(pow(89.,2.) + pow(NrsNws,2.)*pow(2862.,2.))/1132332.;
    RooDataSet *parFloat = new RooDataSet("parFloat","parFloat",RooArgList(myratio,myx,myy));
 
    for(Int_t j=0;j<400;j++){
      cout << "Performing step number " << j << endl;
      RooArgList floated = theRes->randomizePars();
      myc1.setVal(((RooAbsReal*)floated.find("c1"))->getVal());
      myc2.setVal(((RooAbsReal*)floated.find("c2"))->getVal());
 
      RooTimepdf mysigD0("mysigD0","mysigD0",d0Lifetime,m2Kpi_d0mass,m2Kpi0_d0mass,gm,&dalitzSpace,tau,myc1,myc2,-1,dirname);
      Double_t myDenom = mysigD0.createIntegral(RooArgSet(m2Kpi_d0mass,m2Kpi0_d0mass,d0Lifetime))->getVal();
      Double_t myNum = RooRandom::randomGenerator()->Gaus(NrsNws,ratioerr);
 
      myratio.setVal(myNum/myDenom);
      myx.setVal(myc2.getVal()*sqrt((myNum/myDenom)));
      myy.setVal(myc1.getVal()*sqrt((myNum/myDenom)));
 
      parFloat->add(RooArgSet(myratio,myx,myy));
    }
 
    TFile *f1 = new TFile("fitWS_float.root","RECREATE");
    f1->cd();
    parFloat->Write();
    f1->Close();
  }

  if(doChi2){
 
    m2Kpi_d0mass.setBins(40);
    m2Kpi0_d0mass.setBins(40);
 
    RooDataSet *dterr_ds = (RooDataSet*)dataWS->reduce(RooArgSet(d0LifetimeErr));
 
    TH2F *dphist_data = (TH2F*)m2Kpi_d0mass.createHistogram("dphist_data",m2Kpi0_d0mass);
    dataWS->fillHistogram(dphist_data,RooArgSet(m2Kpi_d0mass,m2Kpi0_d0mass));
 
    RooDataSet *pdf_ds = (RooDataSet*)TOTpdf.generate(RooArgSet(m2Kpi_d0mass,m2Kpi0_d0mass,d0Lifetime),dataWS->numEntries(),RooFit::ProtoData(*dterr_ds,1));
    TH2F *dphist = (TH2F*)m2Kpi_d0mass.createHistogram("dphist",m2Kpi0_d0mass);
    pdf_ds->fillHistogram(dphist,RooArgSet(m2Kpi_d0mass,m2Kpi0_d0mass));
 
    Int_t binx = m2Kpi_d0mass.getBinning().numBins();
    Int_t biny = m2Kpi0_d0mass.getBinning().numBins();
    Double_t chi2 = 0.;
    Int_t myBins = 0;
    Int_t nBin = 1;
 
    TH2F *pull_dal = (TH2F*)m2Kpi_d0mass.createHistogram("pull_dal",m2Kpi0_d0mass);
 
    dphist->Sumw2();
    dphist->Scale(dphist_data->Integral()/dphist->Integral());
    dphist->Sumw2();
 
    for(Int_t i=0;i<binx*biny;i++){
 
      Double_t chi_tmp = (dphist->GetBinContent(i)-dphist_data->GetBinContent(i))/dphist->GetBinError(i);
      Double_t nEv = dphist_data->GetBinContent(i);
      if(nEv == 0.) chi_tmp = 0.;
      pull_dal->SetBinContent(i,chi_tmp);
 
      if(nBin > 1){
	nBin--;
	//Double_t chi_tmp = (dphist->GetBinContent(i)-dphist_data->GetBinContent(i))/dphist->GetBinError(i);
	//pull_dal->SetBinContent(i,chi_tmp);
	continue;
      }
 
      if(nEv == 0.) continue;
      Double_t ndata = dphist_data->GetBinContent(i);
      Double_t npdf = dphist->GetBinContent(i);
      Double_t err = dphist->GetBinError(i);
      myBins++;
 
      while(nEv < 9.){
	if(dphist_data->GetBinContent(i+nBin) == 0. || dphist->GetBinError(i+nBin) == 0.){
	  nBin++;
	  continue;
	}
	ndata += dphist_data->GetBinContent(i+nBin);
	npdf += dphist->GetBinContent(i+nBin);
	err += sqrt(pow(err,2.) + pow(dphist->GetBinError(i+nBin),2.));
	nEv += dphist_data->GetBinContent(i+nBin);
	nBin++;
      }
 
      chi2 += pow((ndata-npdf)/err,2.);
    }
 
    Double_t chi2_root = dphist_data->Chi2Test(dphist,"UW");
 
    cout << "chi2 = " << chi2 << endl;
    cout << "chi2/ndof = " << chi2/(myBins -1.) << endl;
    cout << "mybins = " << myBins << endl;
    cout << "chi2 for root = " << chi2_root << endl;
 
    dphist_data->Sumw2();
    dphist->Sumw2();
    dphist_data->Add(dphist,-1.);
    dphist_data->SetMaximum(15.);

    dphist_data->SetMinimum(-15.);

    TCanvas c;
    c.Divide(1,2);
    c.cd(1);dphist_data->Draw("COLZ");
    c.cd(2);pull_dal->Draw("COLZ");
    c.SaveAs("WScomparison.eps");
    TFile fp("prova.root","RECREATE");
    dphist_data->Write();
    pull_dal->Write();
    fp.Close();
  }

  if(doPlots){
 
    m2Kpi_d0mass.setBins(20);
    m2Kpi0_d0mass.setBins(20);
    m2pipi0_d0mass.setBins(20);
    d0Lifetime.setBins(70);
 
    RooDataHist *dshist = new RooDataHist("dshist","dshist",RooArgSet(d0LifetimeErr),*dataWS);

    TH2F *lefth_t = m2Kpi_d0mass.createHistogram("lefth_t",m2Kpi0_d0mass);
    leftdata->fillHistogram(lefth_t,RooArgList(m2Kpi_d0mass,m2Kpi0_d0mass));
    TH2F *righth_t = m2Kpi_d0mass.createHistogram("righth_t",m2Kpi0_d0mass);
    rightdata->fillHistogram(righth_t,RooArgList(m2Kpi_d0mass,m2Kpi0_d0mass));
    righth_t->Scale(lefth_t->Integral()/righth_t->Integral());
    lefth_t->Sumw2();
    righth_t->Sumw2();
    lefth_t->Add(righth);
    lefth_t->Sumw2();
    TH1F *left_t = (TH1F*)d0Lifetime.createHistogram("left_t");
    leftdata->fillHistogram(left_t,RooArgList(d0Lifetime));
    TH1F *right_t = (TH1F*)d0Lifetime.createHistogram("right_t");
    rightdata->fillHistogram(right_t,RooArgList(d0Lifetime));
    right_t->Scale(left_t->Integral()/right_t->Integral());
    left_t->Sumw2();
    right_t->Sumw2();
    left_t->Add(right_t);
    left_t->Sumw2();
 
    RooDataHist *lefthist_d = new RooDataHist("lefthist_d","lefthist_d",RooArgList(m2Kpi_d0mass,m2Kpi0_d0mass),lefth_t);
    RooDataHist *lefthist_t = new RooDataHist("lefthist_t","lefthist_t",RooArgList(d0Lifetime),left_t);
    RooHistPdf left_plot("left_plot","left_plot",RooArgSet(m2Kpi_d0mass,m2Kpi0_d0mass),*lefthist_d,6);
    RooHistPdf left_t_plot("left_t_plot","left_t_plot",RooArgSet(d0Lifetime),*lefthist_t,6);
 
    RooProdPdf tot_plot("tot_plot","tot_plot",left_plot,left_t_plot);
 
    RooProdPdf totbkg_norm_plot("totbkg_norm_plot","totbkg_norm_plot",RooArgSet(terr_bkg_pdf),Conditional(tot_plot,observ));
    RooAddPdf TOTpdf_plot("TOTpdf_plot","TOTpdf_plot",RooArgList(totsig_norm,totmis_norm,totbkg_norm_plot),RooArgList(Nsig,Nmis,Ncomb));

    RooPlot* tframe = d0Lifetime.frame();
    dataWS->plotOn(tframe,MarkerSize(0.1),DrawOption("z"));
    //TOTpdf.plotOn(tframe,Project(RooArgSet(m2Kpi_d0mass,m2Kpi0_d0mass,d0LifetimeErr)),ProjWData(*dshist));
    TOTpdf_plot.plotOn(tframe);
    Double_t chi2t = tframe->chiSquare();
    TOTpdf_plot.plotOn(tframe,Components(RooArgSet(totmis_norm,totbkg_norm_plot)),DrawOption("F"),FillColor(kBlue));       //FillColor(17));
    TOTpdf_plot.plotOn(tframe,Components(RooArgSet(totbkg_norm_plot)),DrawOption("F"),FillColor(kRed));                       //FillColor(14));
    tframe->getAttLine()->SetLineWidth(1);
    tframe->getAttLine()->SetLineStyle(1);
    tframe->SetTitle("");
    tframe->GetXaxis()->SetTitle("t_{K^{+}#pi^{-}#pi^{0}} [ps]");
    tframe->GetYaxis()->SetTitle("Events/0.08 ps");

    TPaveText *boxt = new TPaveText(2.5,2.5,2.7,2.7,"");
    boxt->AddText("(d)");
    boxt->SetFillColor(10);

    cout << "Chi2 for t = " << chi2t << endl;
    TCanvas ct("t","t",300,300);
    ct.cd();tframe->Draw();boxt->Draw("SAME");
    ct.SaveAs("WSfit_t.eps");

    //When we plot the 1D projection, need to calculate the 1D integral
    //set the precision here
    //cout << "config integrator " << endl;
    RooNumIntConfig *cfg = RooAbsReal::defaultIntegratorConfig();
    cfg->setEpsAbs(1E-5);
    cfg->setEpsRel(1E-5);
    cfg->method1D().setLabel("RooSegmentedIntegrator1D");
    //cfg.getConfigSection("RooSegmentedIntegrator1D").setRealValue("numSeg",3);
    //cfg->method1D()->Print("v");
    TOTsigD0.setIntegratorConfig(*cfg);
    //TOTsigantiD0.setIntegratorConfig(*cfg);
    TOTsigD023.setIntegratorConfig(*cfg);
    //TOTsigantiD023.setIntegratorConfig(*cfg);

    RooPlot* xframe = m2Kpi_d0mass.frame(53);  //was 19
    dataWS->plotOn(xframe,MarkerSize(0.1),DrawOption("z"));
    TOTpdf.plotOn(xframe,Project(RooArgSet(m2Kpi0_d0mass,d0Lifetime,d0LifetimeErr)),ProjWData(*dshist));
    xframe->getAttLine()->SetLineWidth(1);
    xframe->getAttLine()->SetLineStyle(1);
    xframe->SetTitle("");
    xframe->GetXaxis()->SetTitle("m^{2}_{K^{+}#pi^{-}}  [GeV^{2}/c^{4}]");
    xframe->GetYaxis()->SetTitle("Events/0.05 GeV^{2}/c^{4}");
    Double_t chi2Kpi = xframe->chiSquare();
    TOTpdf.plotOn(xframe,Project(RooArgSet(m2Kpi0_d0mass,d0Lifetime,d0LifetimeErr)),ProjWData(*dshist),Components(RooArgSet(totmis_norm,totbkg_norm)),DrawOption("F"),FillColor(kBlue)); //FillColor(17));
    TOTpdf.plotOn(xframe,Project(RooArgSet(m2Kpi0_d0mass,d0Lifetime,d0LifetimeErr)),ProjWData(*dshist),Components(RooArgSet(totbkg_norm)),DrawOption("F"),FillColor(kRed)); //FillColor(14));
    dataWS->plotOn(xframe,MarkerSize(0.1),DrawOption("z"));

    xframe->GetYaxis()->SetTitleOffset(1.3);

    TPaveText *box_m12 = new TPaveText(2.5,2.5,2.7,2.7,"");
    box_m12->AddText("(b)");
    box_m12->SetFillColor(10);

    TCanvas c1("c1","c1",300,300);
    c1.cd();xframe->Draw();box_m12->Draw("SAME");
    c1.SaveAs("WSfit_m2Kpi.eps");

    m2Kpi0_d0mass.setBins(50);

    RooPlot* yframe = m2Kpi0_d0mass.frame(49);
    dataWS->plotOn(yframe,MarkerSize(0.1),DrawOption("z"));
    TOTpdf.plotOn(yframe,Project(RooArgSet(m2Kpi_d0mass,d0Lifetime,d0LifetimeErr)),ProjWData(*dshist));
    yframe->getAttLine()->SetLineWidth(1);
    yframe->getAttLine()->SetLineStyle(1);
    yframe->SetTitle("");
    yframe->GetYaxis()->SetTitle("Events/0.05 GeV^{2}/c^{4}");
    yframe->GetXaxis()->SetTitle("m^{2}_{K^{+}#pi^{0}}  [GeV^{2}/c^{4}]");
    Double_t chi2Kpi0 = yframe->chiSquare();
    TOTpdf.plotOn(yframe,Project(RooArgSet(m2Kpi_d0mass,d0Lifetime,d0LifetimeErr)),ProjWData(*dshist),Components(RooArgSet(totmis_norm,totbkg_norm)),DrawOption("F"),FillColor(kBlue)); //FillColor(17));
    TOTpdf.plotOn(yframe,Project(RooArgSet(m2Kpi_d0mass,d0Lifetime,d0LifetimeErr)),ProjWData(*dshist),Components(RooArgSet(totbkg_norm)),DrawOption("F"),FillColor(kRed));  //FillColor(14));

    yframe->GetYaxis()->SetTitleOffset(1.3);

    TPaveText *box_m13 = new TPaveText(2.5,2.5,2.7,2.7,"");
    box_m13->AddText("(c)");
    box_m13->SetFillColor(10);

    TCanvas c2("c2","c2",300,300);
    c2.cd();yframe->Draw();box_m13->Draw("SAME");
    c2.SaveAs("WSfit_m2Kpi0.eps");

    m2Kpi0_d0mass.setBins(20);

    RooPlot* zframe = m2pipi0_d0mass.frame(50);
    dataWS->plotOn(zframe,MarkerSize(0.1),DrawOption("z"));
    TOTpdf23.plotOn(zframe,Project(RooArgSet(m2Kpi_d0mass,d0Lifetime,d0LifetimeErr)),ProjWData(*dshist));
    zframe->getAttLine()->SetLineWidth(1);
    zframe->getAttLine()->SetLineStyle(1);
    zframe->SetTitle("");
    zframe->GetYaxis()->SetTitle("Events/0.08 GeV^{2}/c^{4}");
    zframe->GetXaxis()->SetTitle("m^{2}_{#pi^{-}#pi^{0}} [GeV/c^{2}]");
    Double_t chi2pipi0 = zframe->chiSquare();
    TOTpdf23.plotOn(zframe,Project(RooArgSet(m2Kpi_d0mass,d0Lifetime,d0LifetimeErr)),ProjWData(*dshist),Components(RooArgSet(totmis_norm23,totbkg_norm23)),DrawOption("F"),FillColor(kBlue));
    TOTpdf23.plotOn(zframe,Project(RooArgSet(m2Kpi_d0mass,d0Lifetime,d0LifetimeErr)),ProjWData(*dshist),Components(RooArgSet(totbkg_norm23)),DrawOption("F"),FillColor(kRed));

    cout << "Chi2 for Kpi = " << chi2Kpi << endl;
    cout << "Chi2 for Kpi0 = " << chi2Kpi0 << endl;
    cout << "Chi2 for pipi0 = " << chi2pipi0 << endl;

    TCanvas *c = new TCanvas("c","allevents",1200,400);
    c->Divide(3,1);
    c->cd(1);xframe->Draw();
    c->cd(2);yframe->Draw();
    c->cd(3);zframe->Draw();
    c->SaveAs("WSfit.eps");

  }

  if(doFrac){
    cout << "Calculating fit fractions" << endl;
    TFile f("fitWS.root");
    RooFitResult* fitRes = (RooFitResult*)f.Get("nll");
 
    //now calculate the fit fractions
    const Int_t nRes = TOTsigD0.getManager()->getnRes();
 
    //recalculate the normalization if necessary
    //TOTsigD0.getManager()->calNorm();
 
    EvtComplex normarray[nRes][nRes];
 
    const Int_t myRes = 7;
    TH1F fitty[myRes];
 
    //read the integral value from the cache file.
    //In this way we don't need to compute the normalization everytime during MIGRAD
    char int_name[50];
    TOTsigD0.getManager()->getFileName(int_name);
 
    ifstream f1;
    f1.open(int_name);
    if (!f1){
      cout << "Error opening file " << endl;
      assert(0);
    }
   
    Double_t re=0.,im=0.;
    //Read in the cache file and store back to array
    for(Int_t j=0;j<nRes;j++) {
      char thname[100];
      sprintf(thname,"thname_%d",j);
      if(j < myRes) fitty[j] = TH1F(thname,thname,30,0.,1.);
      for(Int_t k=0;k<nRes;k++){
	f1 >> re >> im;       
	normarray[j][k] = EvtComplex(re,im);
      }
    }   
    EvtComplex mynorm[myRes][myRes];
    Int_t m = 0, l = 0;
    for(Int_t i=0;i<myRes;i++){
      for(Int_t j=0;j<myRes;j++){
	if(i==0) l = 11;
	else if(i==1) l = 5;
	else if(i==2) l = 3;
	else if(i==3) l = 10;
	else if(i==4) l = 8;
	else if(i==5) l = 2;
	else if(i==6) l = 0;
 
	if(j==0) m = 11;
	else if(j==1) m = 5;
	else if(j==2) m = 3;
	else if(j==3) m = 10;
	else if(j==4) m = 8;
	else if(j==5) m = 2;
	else if(j==6) m = 0;
 
	mynorm[i][j] = normarray[l][m];
      }
    }
 
    //do 100 experiments and extract parameters using covariance matrix
    for(Int_t l=0;l<200;l++){
      RooArgList listpar = fitRes->randomizePars();
      if(l==0) listpar.Print();

      Double_t mynormD0 = 0.;
      EvtComplex coeff_i(0.,0.), coeff_j(0.,0.);
      for(Int_t i=0;i<2*myRes;i++){
        for(Int_t j=0;j<2*myRes;j++){
          if(i==(2*myRes - 2)) coeff_i = EvtComplex(1.,0.);
          else coeff_i = EvtComplex(((RooAbsReal*)listpar.at(i))->getVal()*cos(((RooAbsReal*)listpar.at(i+1))->getVal()),
                                    ((RooAbsReal*)listpar.at(i))->getVal()*sin(((RooAbsReal*)listpar.at(i+1))->getVal()));

          if(j==(2*myRes - 2)) coeff_j = EvtComplex(1.,0.);
          else coeff_j = EvtComplex(((RooAbsReal*)listpar.at(j))->getVal()*cos(((RooAbsReal*)listpar.at(j+1))->getVal()),
                                    ((RooAbsReal*)listpar.at(j))->getVal()*sin(((RooAbsReal*)listpar.at(j+1))->getVal()));
          mynormD0 += real(coeff_i*conj(coeff_j)*(mynorm[i/2][j/2]));
          j++;
        }
        i++;
      }

      //now calculate the fit fractions
      for(Int_t i=0;i<2*myRes;i++){
        Double_t fitfrac = 0.;
        if(i==(2*myRes - 2)) fitfrac = abs(mynorm[i/2][i/2])/mynormD0;
        else fitfrac = abs2( ((RooAbsReal*)listpar.at(i))->getVal())*abs(mynorm[i/2][i/2])/mynormD0;
        fitty[i/2].Fill(fitfrac);
        i++;
      }
    }// nexperiments

    Double_t tot_frac = 0.;
    for(Int_t i=0;i<myRes;i++){
      tot_frac += fitty[i].GetMean();
      cout << "Resonance " << i << ": fit fraction = " << fitty[i].GetMean() << " +/- " << fitty[i].GetRMS() << endl;
    }
    cout << "Total fit fraction = " << tot_frac << endl;
    cout << "///////////////////////////" << endl;
  }

  return 0;
}
void threeDlinearcombination(TH3F* first, int firsttype, TH3F* second, int secondtype, TH3F* input, int inputtype, TH3F* finaloutput, int outputtype, TH3F* finaloutput2, int output2type){
	TH3F* output = (TH3F*) input->Clone();
	TH3F* output2 = (TH3F*) output->Clone();
	if(outputtype==kIntHist || outputtype==kSigHist){
		if(inputtype==kBSI25Hist && firsttype==kSigHist && secondtype==kBkgHist){
			output->Add(first, -25.0);
			output->Add(second, -1.0);
			output->Scale(0.2);
			if (outputtype == kSigHist){ delete output; output = (TH3F*) first->Clone(); }

			output2->Add(first, -25.0);
			output2->Add(second, -1.0);
			output2->Scale(0.2);
			if (output2type == kSigHist){ delete output2; output2 = (TH3F*) first->Clone(); }
		}
		if(inputtype==kBSI25Hist && firsttype==kBSIHist && secondtype==kBkgHist){
			for (int binx = 1; binx <= output->GetNbinsX(); binx++){
				for (int biny = 1; biny <= output->GetNbinsY(); biny++){
					for (int binz = 1; binz <= output->GetNbinsZ(); binz++){
						double bsi = first->GetBinContent(binx, biny, binz);
						double bkg = second->GetBinContent(binx, biny, binz);
						double bsi25 = output->GetBinContent(binx, biny, binz);

						double weight = doLinearCombination(bsi25, 25, bsi, 1, bkg, outputtype);
						output->SetBinContent(binx, biny, binz, weight);
						if (finaloutput2 != 0){
							double weight2 = doLinearCombination(bsi25, 25, bsi, 1, bkg, output2type);
							output2->SetBinContent(binx, biny, binz, weight2);
						}
					}
				}
			}
		}		
		if(inputtype==kBSI25Hist && firsttype==kBSI10Hist && secondtype==kBkgHist){
			//double scaleval = 1./(-50. + 25.*sqrt(10.));
			for (int binx = 1; binx <= output->GetNbinsX(); binx++){
				for (int biny = 1; biny <= output->GetNbinsY(); biny++){
					for (int binz = 1; binz <= output->GetNbinsZ(); binz++){
						double bsi10 = first->GetBinContent(binx, biny, binz);
						double bkg = second->GetBinContent(binx, biny, binz);
						double bsi25 = output->GetBinContent(binx, biny, binz);

						double weight = doLinearCombination(bsi25, 25, bsi10, 10, bkg, outputtype);
						output->SetBinContent(binx, biny, binz, weight);
						if (finaloutput2 != 0){
							double weight2 = doLinearCombination(bsi25, 25, bsi10, 10, bkg, output2type);
							output2->SetBinContent(binx, biny, binz, weight2);
						}
					}
				}
			}
		}
		if(inputtype==kBSI10Hist && firsttype==kBSIHist && secondtype==kBkgHist){
			//double scaleval = 1./(10 - sqrt(10));
			for (int binx = 1; binx <= output->GetNbinsX(); binx++){
				for (int biny = 1; biny <= output->GetNbinsY(); biny++){
					for (int binz = 1; binz <= output->GetNbinsZ(); binz++){
						double bsi = first->GetBinContent(binx, biny, binz);
						double bkg = second->GetBinContent(binx, biny, binz);
						double bsi10 = output->GetBinContent(binx, biny, binz);

						double weight = doLinearCombination(bsi10, 10, bsi, 1, bkg, outputtype);
						output->SetBinContent(binx, biny, binz, weight);
						if (finaloutput2 != 0){
							double weight2 = doLinearCombination(bsi10, 10, bsi, 1, bkg, output2type);
							output2->SetBinContent(binx, biny, binz, weight2);
						}
					}
				}
			}
		}
		for (int binx = 1; binx <= output->GetNbinsX(); binx++){
			for (int biny = 1; biny <= output->GetNbinsY(); biny++){
				for (int binz = 1; binz <= output->GetNbinsZ(); binz++){
					finaloutput->SetBinContent(binx, biny, binz, output->GetBinContent(binx, biny, binz));
					if (finaloutput2 != 0) finaloutput2->SetBinContent(binx,biny,binz,output2->GetBinContent(binx,biny,binz));
				}
			}
		}
	}
	else{cout<<"Option not yet supported. Exiting..."<<endl; assert(0);};
	delete output;
	delete output2;
}
예제 #14
0
void TreeFiller(string inFiles, string outFile, string histName) {

	
	TChain *origFiles = new TChain("treeVars", "treeVars");
	origFiles->Add(inFiles.c_str());
	
	int nEntries = origFiles->GetEntries();
	cout << "The old chain contains " << nEntries << " entries." << endl;
	
	
	float puWeight, jet1Eta, jet2Eta, deltaY, genTopPt1, genTopPt2, jet1Mass, jet2Mass, jet1MinMass, jet2MinMass, jet1BDisc, jet2BDisc, jet1SubjetMaxBDisc, jet2SubjetMaxBDisc,
			jet1tau32, jet2tau32, jet1Pt, jet2Pt, jet1bSF, jet2bSF, jet1bSFErrUp, jet2bSFErrUp, jet1bSFErrDn, jet2bSFErrDn, jetPtForMistag, mttMass, mttMassPred, mistagWt, mistagWtErr, mistagWtAll, mistagWtNsubAll, mistagWtNsub, NNoutput, ptReweight, cutflow, index, trigWt;
	int jet1NSubjets, jet2NSubjets, jet1Parton, jet2Parton, npv;
		
	origFiles->SetBranchAddress("npv", &npv);
	origFiles->SetBranchAddress("jet1Eta", &jet1Eta);
	origFiles->SetBranchAddress("jet2Eta", &jet2Eta);
	origFiles->SetBranchAddress("deltaY", &deltaY);
	origFiles->SetBranchAddress("jet1Mass", &jet1Mass);
	origFiles->SetBranchAddress("jet2Mass", &jet2Mass);
	origFiles->SetBranchAddress("jet1minMass", &jet1MinMass);
	origFiles->SetBranchAddress("jet2minMass", &jet2MinMass);
	origFiles->SetBranchAddress("jet1Nsubj", &jet1NSubjets);
	origFiles->SetBranchAddress("jet2Nsubj", &jet2NSubjets);
	origFiles->SetBranchAddress("jet1BDisc", &jet1BDisc);
	origFiles->SetBranchAddress("jet2BDisc", &jet2BDisc);
	origFiles->SetBranchAddress("jet1SubjetMaxBDisc", &jet1SubjetMaxBDisc);
	origFiles->SetBranchAddress("jet2SubjetMaxBDisc", &jet2SubjetMaxBDisc);
	origFiles->SetBranchAddress("jet1tau32", &jet1tau32);
	origFiles->SetBranchAddress("jet2tau32", &jet2tau32);
	origFiles->SetBranchAddress("jet1Pt", &jet1Pt);
	origFiles->SetBranchAddress("jet2Pt", &jet2Pt);
	origFiles->SetBranchAddress("jetPtForMistag", &jetPtForMistag);
	origFiles->SetBranchAddress("mttMass", &mttMass);
	origFiles->SetBranchAddress("mttMassPred", &mttMassPred);
	origFiles->SetBranchAddress("index", &index);
	origFiles->SetBranchAddress("cutflow", &cutflow);
	origFiles->SetBranchAddress("NNoutput", &NNoutput);
	origFiles->SetBranchAddress("mistagWt", &mistagWt);
	origFiles->SetBranchAddress("genTopPt1", &genTopPt1);	
	origFiles->SetBranchAddress("genTopPt2", &genTopPt2);
	origFiles->SetBranchAddress("jet1Parton", &jet1Parton);
	origFiles->SetBranchAddress("jet2Parton", &jet2Parton);	
	origFiles->SetBranchAddress("trigWt", &trigWt);
	
	TFile *newFile = new TFile(outFile.c_str(), "RECREATE");
	TTree *newTree = origFiles->CloneTree(0);
	newTree->Branch("mistagWtNsub", &mistagWtNsub, "mistagWtNsub/F");
	newTree->Branch("mistagWtNsubAll", &mistagWtNsubAll, "mistagWtNsubAll/F");
	newTree->Branch("mistagWtAll", &mistagWtAll, "mistagWtAll/F");
	newTree->Branch("ptReweight", &ptReweight, "ptReweight/F");
	newTree->Branch("puWeight", &puWeight, "puWeight/F");
	newTree->Branch("jet1bSF", &jet1bSF, "jet1bSF/F");
	newTree->Branch("jet2bSF", &jet2bSF, "jet2bSF/F");
	newTree->Branch("jet1bSFErrUp", &jet1bSFErrUp, "jet1bSFErrUp/F");
	newTree->Branch("jet2bSFErrUp", &jet2bSFErrUp, "jet2bSFErrUp/F");
	newTree->Branch("jet1bSFErrDn", &jet1bSFErrDn, "jet1bSFErrDn/F");
	newTree->Branch("jet2bSFErrDn", &jet2bSFErrDn, "jet2bSFErrDn/F");
	newTree->Branch("mistagWtErr", &mistagWtErr, "mistagWtErr/F");

	newTree->SetBranchAddress("mistagWtNsub", &mistagWtNsub);
	newTree->SetBranchAddress("misagWtNsubAll", &mistagWtNsubAll);
	newTree->SetBranchAddress("mistagWtAll", &mistagWtAll);
	newTree->SetBranchAddress("ptReweight", &ptReweight);
	newTree->SetBranchAddress("puWeight", &puWeight);
	newTree->SetBranchAddress("mistagWtErr", &mistagWtErr);

/*	
	TMVA::Reader* reader = new TMVA::Reader();
	reader->AddVariable("jet1Eta", &jet1Eta);
	reader->AddVariable("jet2Eta", &jet2Eta);
	reader->AddVariable("deltaY", &deltaY);
	reader->AddVariable("jet1Mass", &jet1Mass);
	reader->AddVariable("jet2Mass", &jet2Mass);
	reader->AddVariable("jet1BDisc", &jet1BDisc);
	reader->AddVariable("jet2BDisc", &jet2BDisc);
	reader->AddVariable("jet1SubjetMaxBDisc", &jet1SubjetMaxBDisc);
	reader->AddVariable("jet2SubjetMaxBDisc", &jet2SubjetMaxBDisc);
	reader->AddVariable("jet1tau32", &jet1tau32);
	reader->AddVariable("jet2tau32", &jet2tau32);
	reader->AddVariable("jet1Pt", &jet1Pt);
	reader->AddVariable("jet2Pt", &jet2Pt);
	reader->AddVariable("mttMass", &mttMass);

	reader->BookMVA("MLP", "weights/TMVA_tt_Zp_MLP.weightsZp10_cut4.xml");
*/	
	//TFile *mistagFileLow = new TFile("notCSVL_notCSVM_mistag.root");
	//TFile *mistagFileMed = new TFile("CSVL_notCSVM_mistag.root");
	//TFile *mistagFileHi = new TFile("CSVM_mistag.root");
	TFile *mistagFile = new TFile("Jul3_mistag.root");//data_AllBscore_mistag_Dec16.root");
	histName = "MISTAG_RATE_SUB_TTBAR_Inclusive";
	TFile *triggerFile = new TFile("trigger_weights.root");
	TH1F *triggerHist = (TH1F *) triggerFile->Get("triggerHist");
	TH3F *mistagRateHistAll = (TH3F *) mistagFile->Get( histName.c_str() )->Clone();	
	cout << histName << endl;
	cout << "Entries " << mistagRateHistAll->Integral() << endl;	
	TFile *puFile = new TFile("puHists.root");
	TH1F *puWeightsHist = (TH1F *) puFile->Get("weightsH");
	
	for (int i = 0; i < origFiles->GetEntries(); i++){
	
		origFiles->GetEntry(i);
		if  (i % 1000000 == 0) cout << 100*(float(i) / float(nEntries)) << " Percent Complete." << endl;
		mistagWt = 0.000;
		mistagWtNsub = 30.0000;
		puWeight = puWeightsHist->GetBinContent(npv); 	
		triggerWt = triggerHist->GetBinContent( triggerHist->FindBin( jet1Pt + jet2Pt ) );

		if (cutflow == 4 || index == 1){
		
			if (genTopPt1 > 400) genTopPt1 = 400;
			if (genTopPt2 > 400) genTopPt2 = 400;
			//NNoutput =  reader->EvaluateMVA("MLP");
			ptReweight = sqrt( exp(0.156 - 0.00137*genTopPt1)*exp(0.156 - 0.00137*genTopPt2) );			
		
			
			jet1bSF = 1.0;
			jet1bSFErrUp = 1.0;
			jet1bSFErrDn = 1.0;
			jet2bSF = 1.0;
			jet2bSFErrUp = 1.0;
			jet2bSFErrDn = 1.0;

			if (jet1BDisc > 0.679){
				jet1bSF = findBSF(jet1Pt, jet1Eta, jet1Parton, 0);
				jet1bSFErrUp = findBSF(jet1Pt, jet1Eta, jet1Parton, 1);
				jet1bSFErrDn = findBSF(jet1Pt, jet1Eta, jet1Parton, -1);
			}
			if (jet2BDisc > 0.679){
				jet2bSF = findBSF(jet2Pt, jet2Eta, jet2Parton, 0);
				jet2bSFErrUp = findBSF(jet2Pt, jet2Eta, jet2Parton, 1);
				jet2bSFErrDn = findBSF(jet2Pt, jet2Eta, jet2Parton, -1);
			}

	
			if (index == 1) {
				
				float bScore = -9.99;
				float tauScore = 9.99;
				int probeJet = 0;
				if (jet1Pt == jetPtForMistag) {
					probeJet = 1;
					bScore = jet1SubjetMaxBDisc;
					tauScore = jet1tau32;
				}
				if (jet2Pt == jetPtForMistag) {
					bScore = jet2SubjetMaxBDisc;
					tauScore = jet2tau32;
					probeJet = 2;
				}

				int bin = mistagRateHistAll->FindBin( ptMap(jetPtForMistag),bMap(bScore),tauMap(tauScore) );
				mistagWt = mistagRateHistAll->GetBinContent( bin );
				mistagWtErr = mistagRateHistAll->GetBinError( bin );
			}
		
			newTree->Fill();
		
		}
		

	}


	
	
	


	newFile->cd();
	newTree->Write();
	newFile->Write();
	newFile->Close();
	
}
// ********* MAIN
int main(int argc, char** argv)
{
  using namespace std;

  char* inputFile = argv[1];
  if(!inputFile)
  {
    cout << "Error: Missing input file." << endl;
    return -1;
  }

  gROOT->Macro("../rootstyle.C");

  TFile* inputTFile = new TFile(inputFile);
  inputTFile->cd();

  TFile* outputTFile = new TFile("plotDeDxSingleHitEtaSlices.root","recreate");

  //int nPBins = 200;
  const int nEtaBins = 25;

  TH1F* dedxNomCombined320Hists[nEtaBins];
  TH1F* dedxNomCombined500Hists[nEtaBins];
  TH1F* dedxNomCombinedAllHists[nEtaBins];

  string dir = "dedxHistsInNomBins";
  inputTFile->cd();
  string name320 = "dedxSingleHit320";
  string fullpath320 = dir;
  fullpath320+="/";
  fullpath320+=name320;
  TH3F* rawHist320 = (TH3F*) inputTFile->Get(fullpath320.c_str());
  string name500 = "dedxSingleHit500";
  string fullpath500 = dir;
  fullpath500+="/";
  fullpath500+=name500;
  TH3F* rawHist500 = (TH3F*) inputTFile->Get(fullpath500.c_str());
  string nameAll = "dedxSingleHitAll";
  string fullpathAll = dir;
  fullpathAll+="/";
  fullpathAll+=nameAll;
  TH3F* rawHistAll = (TH3F*) inputTFile->Get(fullpathAll.c_str());

  // loop over eta bins
  for(int etaBin=1; etaBin<nEtaBins+1; ++etaBin)
  {
    rawHist320->GetZaxis()->SetRange(etaBin,etaBin);
    //XXX Set P range to low P sideband (0-->100 GeV)
    //rawHist->GetYaxis()->SetRange(1,20);
    string projName = "x";
    projName+="_EtaBin";
    projName+=intToString(etaBin);
    dedxNomCombined320Hists[etaBin-1] = (TH1F*)rawHist320->Project3D(projName.c_str());

    rawHist500->GetZaxis()->SetRange(etaBin,etaBin);
    //XXX Set P range to low P sideband (0-->100 GeV)
    //rawHist->GetYaxis()->SetRange(1,20);
    string projName2 = "x";
    projName2+="_EtaBin";
    projName2+=intToString(etaBin);
    dedxNomCombined500Hists[etaBin-1] = (TH1F*)rawHist500->Project3D(projName2.c_str());

    rawHistAll->GetZaxis()->SetRange(etaBin,etaBin);
    //XXX Set P range to low P sideband (0-->100 GeV)
    //rawHist->GetYaxis()->SetRange(1,20);
    string projName3 = "x";
    projName3+="_EtaBin";
    projName3+=intToString(etaBin);
    dedxNomCombinedAllHists[etaBin-1] = (TH1F*)rawHistAll->Project3D(projName3.c_str());
  }


  outputTFile->cd();
  for(int etaBin=1; etaBin<nEtaBins+1; ++etaBin)
  {
    dedxNomCombined500Hists[etaBin-1]->Write();
    dedxNomCombined320Hists[etaBin-1]->Write();
    dedxNomCombinedAllHists[etaBin-1]->Write();
  }

}
예제 #16
0
파일: toyMC.C 프로젝트: CmsHI/CVS_MitHig
void toyMC(int run,int nevt)
{
    f = new TFile("output.root");

    // Random Seed
    gRandom->SetSeed( run );

    TH3F *nhits = (TH3F*) f->FindObjectAny("nhits");

    TFile *outf = new TFile (Form("exp-%05d.root",run),"recreate");
    TNtuple *ntmatched = new TNtuple("ntmatched","","eta1:matchedeta:phi1:matchedphi:deta:dphi:signalCheck:tid:r1id:r2id:evtid:nhit1:sid:ptype");
    TNtuple *ntHit1 = new TNtuple("ntHit1","","eta1:phi1:nhit1");
    TNtuple *ntHit2 = new TNtuple("ntHit2","","eta2:phi2:nhit1");

    for (int i=0;i<nevt;i++) {
       vector<double> hits1;
       vector<double> hits2;
       vector<Tracklet> protoTracklets;
       vector<Tracklet> recoTracklets;
       double mult,nhit1,nhit2;
       nhits->GetRandom3(mult,nhit1,nhit2);
       hits1.clear();
       hits2.clear();
       if (i% 1000 == 000 ) cout <<"Run: "<<run<<" Event "<<i<<" "<<(int)mult<<" "<<(int)nhit1<<" "<<hits1.size()<<" "<<(int)nhit2<<" "<<hits2.size()<<endl;
       genLayer1((int)nhit1,hits1);
       genLayer2((int)nhit2,hits2);
       
       for (int j=0;j<(int) hits1.size();j+=2)
       {
          ntHit1->Fill(hits1[j],hits1[j+1],mult);
          for (int k=0;k<(int)hits2.size();k+=2)
	  {
             ntHit2->Fill(hits2[k],hits2[k+1],mult);
	     Tracklet mytracklet(hits1[j],hits2[k],hits1[j+1],hits2[k+1]);
	     mytracklet.setIt1(j/2);
	     mytracklet.setIt2(k/2);
	     protoTracklets.push_back(mytracklet); 
	  }
       }
       recoTracklets = cleanTracklets(protoTracklets,0);
       for (int j=0;j<(int)recoTracklets.size();j++)
       {
           float var[100];
	   var[0] = recoTracklets[j].eta1();
	   var[1] = recoTracklets[j].eta2();
	   var[2] = recoTracklets[j].phi1();
	   var[3] = recoTracklets[j].phi2();
	   var[4] = recoTracklets[j].deta();
	   var[5] = recoTracklets[j].dphi();
	   var[6] = 0;
	   var[7] = recoTracklets[j].getId();
	   var[8] = recoTracklets[j].getId1();
	   var[9] = recoTracklets[j].getId2();
	   var[10] = i;
	   var[11] = (int)mult;
	   var[12] = recoTracklets[j].getSId();
	   var[13] = recoTracklets[j].getType();
	   ntmatched->Fill(var);
       }
    }

    ntmatched->Write();
    ntHit1->Write();
    ntHit2->Write();
    outf->Close();
}
예제 #17
0
void PET_Analyse()
{
   gROOT->Reset();
	TFile *f = new TFile("data_PET.root");
   
	TTree *Coincidences = (TTree*)gDirectory->Get("Coincidences");
   //TTree *Gate = (TTree*)gDirectory->Get("Gate");
   //TTree *Hits = (TTree*)gDirectory->Get("Hits");
   //TTree *Singles = (TTree*)gDirectory->Get("Singles");
   

   
//creation of a histo 1 Dim.
TH1F *gamma1 = new TH1F("gamma1","",80,0.2,.8);  
TH1F *gamma2 = new TH1F("gamma2","",100,0.2,.8);  

 
//creation of histo 3 Dim. 
TH3F *position = new TH3F("position","",200,-400,400,200,-400,400,200,-400,400);  

  
//
//Declaration of leaves types - TTree Coincidences
//  
   Float_t         axialPos;
   Char_t          comptVolName1[40];
   Char_t          comptVolName2[40];
   Int_t           comptonPhantom1;
   Int_t           comptonPhantom2;
   Int_t           comptonCrystal1;
   Int_t           comptonCrystal2;   
   Int_t           crystalID1;
   Int_t           crystalID2;
   //Int_t           blockID1;
   //Int_t           blockID2;
   Float_t         energy1;
   Float_t         energy2;   
   Int_t           eventID1;
   Int_t           eventID2;
   Float_t         globalPosX1;
   Float_t         globalPosX2;
   Float_t         globalPosY1;
   Float_t         globalPosY2;      
   Float_t         globalPosZ1;
   Float_t         globalPosZ2;
   Int_t           layerID1;
   Int_t           layerID2;
   Int_t           moduleID1;
   Int_t           moduleID2;
   Float_t         rotationAngle;
   Int_t           rsectorID1;
   Int_t           rsectorID2;
   Int_t           runID;
   Float_t         sinogramS;
   Float_t         sinogramTheta;
   Int_t           sourceID1;
   Int_t           sourceID2;
   Float_t         sourcePosX1;
   Float_t         sourcePosX2;
   Float_t         sourcePosY1;
   Float_t         sourcePosY2;
   Float_t         sourcePosZ1;
   Float_t         sourcePosZ2;
   Int_t           submoduleID1;
   Int_t           submoduleID2;
   Double_t         time1;
   Double_t         time2;
   
//   
//Set branch addresses - TTree Coincicences
//  
   Coincidences->SetBranchAddress("axialPos",&axialPos);
   Coincidences->SetBranchAddress("comptVolName1",&comptVolName1);
   Coincidences->SetBranchAddress("comptVolName2",&comptVolName2);
   Coincidences->SetBranchAddress("comptonPhantom1",&comptonPhantom1);
   Coincidences->SetBranchAddress("comptonPhantom2",&comptonPhantom2);
   Coincidences->SetBranchAddress("comptonCrystal1",&comptonCrystal1);
   Coincidences->SetBranchAddress("comptonCrystal2",&comptonCrystal2);
   Coincidences->SetBranchAddress("crystalID1",&crystalID1);
   Coincidences->SetBranchAddress("crystalID2",&crystalID2);
  // Coincidences->SetBranchAddress("blockID1",&blockID1);
  // Coincidences->SetBranchAddress("blockID2",&blockID2);
   Coincidences->SetBranchAddress("energy1",&energy1);
   Coincidences->SetBranchAddress("energy2",&energy2);   
   Coincidences->SetBranchAddress("eventID1",&eventID1);
   Coincidences->SetBranchAddress("eventID2",&eventID2);
   Coincidences->SetBranchAddress("globalPosX1",&globalPosX1);
   Coincidences->SetBranchAddress("globalPosX2",&globalPosX2);
   Coincidences->SetBranchAddress("globalPosY1",&globalPosY1);
   Coincidences->SetBranchAddress("globalPosY2",&globalPosY2);      
   Coincidences->SetBranchAddress("globalPosZ1",&globalPosZ1);
   Coincidences->SetBranchAddress("globalPosZ2",&globalPosZ2);
   Coincidences->SetBranchAddress("layerID1",&layerID1);
   Coincidences->SetBranchAddress("layerID2",&layerID2);
   Coincidences->SetBranchAddress("moduleID1",&moduleID1);
   Coincidences->SetBranchAddress("moduleID2",&moduleID2);
   Coincidences->SetBranchAddress("rotationAngle",&rotationAngle);
   Coincidences->SetBranchAddress("rsectorID1",&rsectorID1);
   Coincidences->SetBranchAddress("rsectorID2",&rsectorID2);
   Coincidences->SetBranchAddress("runID",&runID);
   Coincidences->SetBranchAddress("sinogramS",&sinogramS);
   Coincidences->SetBranchAddress("sinogramTheta",&sinogramTheta);
   Coincidences->SetBranchAddress("sourceID1",&sourceID1);
   Coincidences->SetBranchAddress("sourceID2",&sourceID2);
   Coincidences->SetBranchAddress("sourcePosX1",&sourcePosX1);
   Coincidences->SetBranchAddress("sourcePosX2",&sourcePosX2);
   Coincidences->SetBranchAddress("sourcePosY1",&sourcePosY1);
   Coincidences->SetBranchAddress("sourcePosY2",&sourcePosY2);
   Coincidences->SetBranchAddress("sourcePosZ1",&sourcePosZ1);
   Coincidences->SetBranchAddress("sourcePosZ2",&sourcePosZ2);
   Coincidences->SetBranchAddress("submoduleID1",&submoduleID1);
   Coincidences->SetBranchAddress("submoduleID2",&submoduleID2);
   Coincidences->SetBranchAddress("time1",&time1);
   Coincidences->SetBranchAddress("time2",&time2);
   
   Int_t nentries = Coincidences->GetEntries();
	
	cout<<" nentries:   "<<  nentries <<endl;
   Int_t nbytes = 0;
    
//
//loop on the events in the TTree Coincidences
//

Float_t Nbr_Coinc_Prompt = 0. ;
Float_t Nbr_Coinc_Random = 0. ;
Float_t Nbr_Coinc_Scatter = 0. ;
Float_t Nbr_Coinc_Trues = 0. ;
Float_t Ntot = 10000000. ;

    for (Int_t i=0; i<nentries;i++) {
       nbytes += Coincidences->GetEntry(i);
       
       
       // Fill gamma1 histo without condition
       gamma1->Fill(energy1);
       
       // Fill the gamma2 histo with condition
       if (energy2 >= 0.4)gamma2->Fill(energy2);
       
       // Fill the 3D Histo without condition
       position->Fill(globalPosZ1,globalPosX1,globalPosY1);
       
       
       ///////////////////////////////////////////////////////////////////////////////////////////
       //      						                                        //	
       // E V A L U A T I O N   O F   :   P R O M P T S   ;   T R U E S   ;   R A N D O M   ;   //
       //                                                                                       //
       // S E N S I T I V I T Y                                                                 //                           
       //									                //
       ///////////////////////////////////////////////////////////////////////////////////////////
		
		Nbr_Coinc_Prompt++;
		
		if ( eventID1 != eventID2 ) Nbr_Coinc_Random++;
            
                if ( eventID1 == eventID2 && comptonPhantom1 == 0 && comptonPhantom2 == 0 ) Nbr_Coinc_Trues++;
			    
		}

Float_t Sensi = Nbr_Coinc_Prompt/Ntot*100.;


cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<"#   P R O M P T S     =   "<<Nbr_Coinc_Prompt <<"   Cps"<<endl;
cout<<"#   T R U E S         =   "<<Nbr_Coinc_Trues  <<"   Cps"<<endl;
cout<<"#   R A N D O M S     =   "<<Nbr_Coinc_Random <<"   Cps"<<endl;
cout<<" ______________________________________"<<endl;
cout<<"|                                      "<<endl;
cout<<"|  T O T A L   S E N S I T I V I T Y   :   "<<  Sensi <<"  %"<<endl;
cout<<"|______________________________________"<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl; 


//
// Plot the results
//

   gStyle->SetPalette(1);
   
   
   c1 = new TCanvas("Reco","Reco",200,10,500,600);
   c1->SetFillColor(0);
   c1->SetBorderMode(0);   
       
   gamma1->Draw();
   gamma1->SetFillColor(2);
   gamma2->Draw("same");  
   gamma2->SetFillColor(9);
   
   
   tex = new TLatex(0.255919,600,"GAMMA 1");
   tex->SetTextColor(2);
   tex->SetTextSize(0.05);
   tex->SetLineWidth(2);
   tex->Draw();
      tex2 = new TLatex(0.620151,300,"GAMMA 2");
   tex2->SetTextColor(9);
   tex2->SetTextSize(0.05);
   tex2->SetLineWidth(2);
   tex2->Draw();
     
   c1->Update(); 

//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
   c2 = new TCanvas("Reco_true","Reco_true",200,10,500,600);
   c2->SetFillColor(0);
   c2->SetGrid();
   c2->SetBorderMode(0); 

   position->Draw();
   
   c2->Update(); 
    
}
예제 #18
0
void draw_qa_sim(TString inFileName="sim.qa.root")
{
  gStyle->SetPalette(1);

  TFile* inFile = new TFile(inFileName.Data());

  TH1F* fhNofEvents = (TH1F*)inFile->Get("STSSimulationQA/hNofEvents");
  TH1F* fhNofStsStations = (TH1F*)inFile->Get("STSSimulationQA/hNofStsStations");

  Int_t nofStations = fhNofStsStations->GetBinContent(1);
  Int_t fShowStation = 4;
  Int_t fNEvents = fhNofEvents->GetBinContent(1);

  TH1F* fhMomAll  = (TH1F*)inFile->Get("STSSimulationQA/hMomAll");
  TH1F* fhMomRec  = (TH1F*)inFile->Get("STSSimulationQA/hMomRec");
  TH2F* fhYPtMapRec  = (TH2F*)inFile->Get("STSSimulationQA/hYPtMapRec");
  TH1F* fhStsPointsRec  = (TH1F*)inFile->Get("STSSimulationQA/hStsPointsRec");
  TH3F* fhStsPointsPosition  = (TH3F*)inFile->Get("STSSimulationQA/hStsPointsPosition");
  TH2F* fhStationPoints[10];
  for ( Int_t ist = 0 ; ist < nofStations ; ist++ ) 
    fhStationPoints[ist] = (TH2F*)inFile->Get(Form("STSSimulationQA/hStationPoints%i",ist+1));

  Double_t tracksPerEvent = (Double_t)(fhMomAll->GetEntries())/((Double_t)fNEvents);
  Double_t pointsPerEvent = (Double_t)(fhStsPointsPosition->GetEntries())/((Double_t)fNEvents);


  TCanvas* simCanvas = new TCanvas("StsSim","Sts simulation",10,10,600,900);
  TPad* simPad[10];
  simPad[0] = new TPad("titlePad",   "Title pad"                ,0.01,0.91,0.99,0.99);
  simPad[1] = new TPad("momentumPad","Momentum pad"             ,0.01,0.46,0.49,0.89);
  simPad[2] = new TPad("yptPad",     "y-pt pad"                 ,0.01,0.01,0.49,0.44);
  simPad[3] = new TPad("pointPad",   "Points per track pad"     ,0.51,0.61,0.99,0.89);
  simPad[4] = new TPad("stationPad", "Points on 1st station pad",0.51,0.31,0.99,0.59);
  simPad[5] = new TPad("printoutPad","Print information pad    ",0.51,0.01,0.99,0.29);
  simPad[1]->SetLogy();
  for ( Int_t ipad = 0 ; ipad < 6 ; ipad++ ) {
    simPad[ipad]->SetFillColor(0);
    simPad[ipad]->SetBorderMode(0);
    simPad[ipad]->Draw();
  }
  
  simPad[0]->cd();
  TLegend* brp = new TLegend(0.1,0.1,0.9,0.9,"STS simulation");
  brp->SetTextAlign(22);
  brp->SetTextSize(0.6);
  brp->SetTextColor(1);
  brp->SetBorderSize(0);
  brp->SetFillColor(0);
  brp->Draw();
  simPad[0]->Update();
  
  simPad[1]->cd();
  //  fhMomAll->Draw();
  fhMomRec->Draw();
  simPad[1]->Update();
  simPad[2]->cd();
  fhYPtMapRec->Draw("colz");
  simPad[2]->Update();
  simPad[3]->cd();
  fhStsPointsRec->Draw();
  simPad[3]->Update();
  
  simPad[4]->cd();
  fhStationPoints[0]->Draw();
  fhStationPoints[0]->Draw("colz");
  simPad[4]->Update();
  
  simPad[5]->cd();
  TPaveText* printoutPave = new TPaveText(0.1,0.1,0.9,0.9);
  printoutPave->SetTextAlign(22);
  printoutPave->SetTextSize(0.1);
  printoutPave->SetTextColor(1);
  printoutPave->SetBorderSize(0);
  printoutPave->SetFillColor(0);
  printoutPave->AddText(Form("%i events",fNEvents));
  printoutPave->AddText(Form("tracks/event = %3.2f",tracksPerEvent));
  printoutPave->AddText(Form("points/event = %3.2f",pointsPerEvent));
  simPad[5]->Clear();
  printoutPave->Draw();
  simPad[5]->Update();
}