コード例 #1
0
ファイル: Asymmetry.C プロジェクト: A2-Collaboration/acqu
// 
// GetHistFile
//
// Sets pointers to the scaler and random-subtracted asymmetry 3D histograms
// for a certain input file (full/empty and perp/para).  Results are NOT
// dead-time corrected.
//
void GetHistFile( TFile* file, Bool_t cthflag = kFALSE)
{
	Double_t pa;
	TString prompt, random, scalers;

	TH3D* hP;
	TH3D* hR;

	pa = 0.0833;

	if ( cthflag == kFALSE ) {
//		prompt = "PhiCMCut2P_v_ThetaCMCut2P_v_TChanCut2P";
//		random = "PhiCMCut2R_v_ThetaCMCut2R_v_TChanCut2R";
		prompt = "PhiCMCut1P_v_ThetaCMCut1P_v_TChanCut1P";
		random = "PhiCMCut1R_v_ThetaCMCut1R_v_TChanCut1R";
	}
	else {
		prompt = "PhiCMCut1P_v_CosThetaCMCut1P_v_TChanCut1P";
		random = "PhiCMCut1R_v_CosThetaCMCut1R_v_TChanCut1R";
	}
	scalers = "SumScalers152to503";

	hP = (TH3D*) file->Get( prompt);
	hR = (TH3D*) file->Get( random);
	hsc = (TH1D*) file->Get( scalers);

	hS = (TH3D*) hP->Clone( "sub");
	hS->Sumw2();
	hS->Add( hR, -pa);
}
コード例 #2
0
ファイル: FillHists.cpp プロジェクト: aogaki/GridBI
void THisHandler::FillHists()
{
   fTree->SetBranchStatus("*", 0);

   TVector3 position;
   fTree->SetBranchStatus("x", 1);
   fTree->SetBranchStatus("y", 1);
   fTree->SetBranchStatus("z", 1);
   fTree->SetBranchAddress("x", &position[0]);
   fTree->SetBranchAddress("y", &position[1]);
   fTree->SetBranchAddress("z", &position[2]);
   
   Char_t volumeName[256]; // Array size is enough?
   fTree->SetBranchStatus("VolumeName", 1);
   fTree->SetBranchAddress("VolumeName", volumeName);

   Double_t ene;
   fTree->SetBranchStatus("DepositEnergy", 1);
   fTree->SetBranchAddress("DepositEnergy", &ene);

   const Int_t kEntries = fTree->GetEntries();
   for(Int_t iEntry = 0; iEntry < kEntries; iEntry++){
      //if(iEntry%100000 == 0) cout << iEntry <<" / "<< kEntries << endl;
      fTree->GetEntry(iEntry);
      if(!(ene > 0.)) continue;
      
      fHisAll->Fill(position.X(), position.Y(), position.Z(), ene);

      if(TString(volumeName) == "Sealing")
         fHisSealing->Fill(position.X(), position.Y(), position.Z(), ene);
      else if(TString(volumeName) == "Window")
         fHisWindow->Fill(position.X(), position.Y(), position.Z(), ene);
      else if(TString(volumeName) == "Foil")
         fHisFoil->Fill(position.X(), position.Y(), position.Z(), ene);
      else if(TString(volumeName) == "Holder")
         fHisHolder->Fill(position.X(), position.Y(), position.Z(), ene);
      else if(TString(volumeName) == "Cassette")
         fHisCassette->Fill(position.X(), position.Y(), position.Z(), ene);
      else if(TString(volumeName) == "Air")
         fHisAir->Fill(position.X(), position.Y(), position.Z(), ene);
      else if(TString(volumeName) == "Plate" ||
              TString(volumeName) == "Well" ||
              TString(volumeName) == "Outer")
         fHisPlate->Fill(position.X(), position.Y(), position.Z(), ene);
      else if(TString(volumeName) == "Film")
         fHisFilm->Fill(position.X(), position.Y(), position.Z(), ene);
      else if(TString(volumeName) == "Stuff")
         fHisWell->Fill(position.X(), position.Y(), position.Z(), ene);

      else if(TString(volumeName) == "Cell"){
         Int_t wellID = XYtoIndex(position.X(), position.Y());
         fHisEachCell20[wellID]->Fill(position.X(), position.Y(), ene);
         fHisEachCell50[wellID]->Fill(position.X(), position.Y(), ene);
      }

   }

}
コード例 #3
0
TH3D *plotCor(TTree *tSig,TString var,TString weight, TString etcut, TString htcut,TString njetcut, TString ph, TString bin)
{
  TCut etcut20=weight+" * ("+etcut+htcut+" && "+njetcut+")";

  TCut conv1=weight+" * ("+etcut+htcut+" &&"+njetcut+" && mHits<=1)";
  TCut conv2=weight+" * ("+etcut+htcut+" && "+njetcut+"&& mHits<=1 && mHits<2)";
  TCut conv3=weight+" * ("+etcut+htcut+" && "+njetcut+"&& mHits<=1 && mHits<2 && (dcot>0.02 || dcot<-0.02 || dist>0.02 || dist<-0.02))";
  
  tSig->Draw(var+">>hsqrti"+bin,conv1);
  TH3D *hsqrt = (TH3D*)gDirectory->Get("hsqrti");
  hsqrt->SetName(ph+var+htcut+"hsqrti");

  return hsqrt;
}
コード例 #4
0
ファイル: HistoXML.cpp プロジェクト: atlas-org/gaudi
// ============================================================================
StatusCode Gaudi::Utils::Histos::fromXml
( TH3D& result , const std::string& input )
{
  //
  result.Reset() ;                                 // RESET old histogram
  //
  _Xml<TH3D> _xml ;
  std::auto_ptr<TH3D> histo = _xml ( input ) ;
  if ( 0 == histo.get() ) { return StatusCode::FAILURE ; }        // RETURN
  //
  result.Reset() ;
  histo->Copy ( result ) ;
  //
  return StatusCode::SUCCESS ;
}
コード例 #5
0
ファイル: MCCTRapDep.C プロジェクト: cmironov/UserCode
void DoEffCor3D(TFile* a, int b, double c, double d, double e, double *f){
  char tmp[512];
  if(b == 0) sprintf(tmp,"eff_default");
  if(b == 1) sprintf(tmp,"eff_cowboy");
  if(b == 2) sprintf(tmp,"eff_sailor");
  TH3D *hEff = (TH3D*)a->Get(tmp);
  int sbin = 0;
  sbin = hEff->FindBin(c, d, e);
  f[0] = hEff->GetBinContent(sbin);
  f[1] = hEff->GetBinError(sbin);
  if(f[0] == 0) {
    cout<<"b : "<<b<<", c : "<<c<<", d : "<<d<<", e : "<<e<<endl;
    cout<<"sbin : "<<sbin<<", eff : "<<f[0]<<", err : "<<f[1]<<endl;
  }
  //return f;
}
コード例 #6
0
TH3D *plotConv(TTree *tSig,TString var,TString weight, TString etcut, TString htcut,TString njetcut, TString ph, TString bin)
{
  TCut etcut20=weight+" * ("+etcut+htcut+" && "+njetcut+")";

  TCut conv1=weight+" * ("+etcut+htcut+" &&"+njetcut+" && hitFP==0)";
  TCut conv2=weight+" * ("+etcut+htcut+" && "+njetcut+"&& (hitFP==0 && mHits>=2))";
  TCut conv3=weight+" * ("+etcut+htcut+" && "+njetcut+"&& (hitFP==0 && mHits>=2 && !(dcot>0.02 || dcot<-0.02 || dist>0.02 || dist<-0.02)) )";
  TCut conv4=weight+" * ("+etcut+htcut+" && "+njetcut+"&& ( !(dcot>0.02 || dcot<-0.02 || dist>0.02 || dist<-0.02)) )";

  
  tSig->Draw(var+">>hsqrtic"+bin,conv4);
  TH3D *hsqrt = (TH3D*)gDirectory->Get("hsqrtic");
  hsqrt->SetName(ph+var+htcut+"hsqrtic");

  return hsqrt;
}
コード例 #7
0
int main ()
{
  TFile* testFile = new TFile("test.root", "RECREATE");
  
  TH3D* test = new TH3D("test","test", 50,-50,50, 50,-50,50, 50,-50,50);
  
  for (int i = -10; i <= 10; i++)
    {
      for (int j = -2; j <= 2; j++)
	{
	  for (int k = -2; k <= 2; k++)
	    {
	      test->Fill (i, j, k, 5);
	    }
	}
    }
  
  testFile->Write();

  return 0;
}
コード例 #8
0
TH3D* readHist3D(TString nameHist,TString nameFile, int rebin)
{
 TFile* file = new TFile(nameFile);

 TH3D* hist = (TH3D*)file->Get(nameHist);
 hist->GetSumw2();
 // hist->SetLineWidth(2);
 // if(rebin>0) hist->RebinX(rebin); hist->RebinY(rebin);
 hist->GetXaxis()->SetTitleSize(.055);
 hist->GetYaxis()->SetTitleSize(.055);
 hist->GetXaxis()->SetLabelSize(.05);
 hist->GetYaxis()->SetLabelSize(.05);
 hist->SetStats(kFALSE);
 return hist;
}
コード例 #9
0
void projectPbPbMBMC()
{
  gStyle->SetTextSize(0.05);
  gStyle->SetTextFont(42);
  gStyle->SetPadRightMargin(0.043);
  gStyle->SetPadLeftMargin(0.18);
  gStyle->SetPadTopMargin(0.1);
  gStyle->SetPadBottomMargin(0.145);
  gStyle->SetTitleX(.0f);
  gStyle->SetOptFit(1111);
  gStyle->SetOptStat(0);
  gStyle->SetOptTitle(0);

  TFile* infMCP = new TFile("/data/HeavyFlavourRun2/MC2015/Dntuple/PbPb/ntD_EvtBase_20160513_DfinderMC_PbPb_20160502_dPt1tkPt0p5_D0_prompt_Dpt2Dy1p1tkPt0p7tkEta2Decay2p9Dalpha0p14Skim_pthatweight.root");
  TFile* infMCNP = new TFile("/data/HeavyFlavourRun2/MC2015/Dntuple/PbPb/ntD_EvtBase_20160513_DfinderMC_PbPb_20160502_dPt1tkPt0p5_D0_nonprompt_Dpt2Dy1p1tkPt0p7tkEta2Decay2p9Dalpha0p14Skim_pthatweight.root");
  
  TTree* tMCP = (TTree*)infMCP->Get("ntDkpi");
  TTree* tMCNP = (TTree*)infMCNP->Get("ntDkpi");
  TTree* tMCPHI = (TTree*)infMCP->Get("ntHi");
  TTree* tMCNPHI = (TTree*)infMCNP->Get("ntHi");
  TTree* tMCPSkim = (TTree*)infMCP->Get("ntSkim");
  TTree* tMCNPSkim = (TTree*)infMCNP->Get("ntSkim");
  tMCP->AddFriend(tMCPHI);
  tMCNP->AddFriend(tMCNPHI);
  tMCP->AddFriend(tMCPSkim);
  tMCNP->AddFriend(tMCNPSkim);
  
  TFile* outf = new TFile("bFeedDownPbPbMBMC.hist.root","recreate");
  
  TCut cutPbPbMB = "pclusterCompatibilityFilter&&pprimaryVertexFilter&&phfCoincFilter3&&Dy>-1.&&Dy<1.&&Dtrk1highPurity&&Dtrk2highPurity&&Dtrk1Pt>1.0&&Dtrk2Pt>1.0&&Dtrk1PtErr/Dtrk1Pt<0.3&&Dtrk2PtErr/Dtrk2Pt<0.3&&abs(Dtrk1Eta)<1.5&&abs(Dtrk2Eta)<1.5&&((DlxyBS/DlxyBSErr)>1.5&&Dalpha<0.12&&((Dpt>1&&Dpt<2&&(DsvpvDistance/DsvpvDisErr)>6.0&&Dchi2cl>0.25)||(Dpt>2&&Dpt<4&&(DsvpvDistance/DsvpvDisErr)>5.86&&Dchi2cl>0.224)||(Dpt>4&&Dpt<5&&(DsvpvDistance/DsvpvDisErr)>5.46&&Dchi2cl>0.196)||(Dpt>5&&Dpt<6&&(DsvpvDistance/DsvpvDisErr)>4.86&&Dchi2cl>0.170)||(Dpt>6&&Dpt<8&&(DsvpvDistance/DsvpvDisErr)>4.54&&Dchi2cl>0.125)||(Dpt>8&&Dpt<10&&(DsvpvDistance/DsvpvDisErr)>4.42&&Dchi2cl>0.091)||(Dpt>10&&Dpt<15&&(DsvpvDistance/DsvpvDisErr)>4.06&&Dchi2cl>0.069)||(Dpt>15&&Dpt<20&&(DsvpvDistance/DsvpvDisErr)>3.71&&Dchi2cl>0.056)||(Dpt>20&&Dpt<25&&(DsvpvDistance/DsvpvDisErr)>3.25&&Dchi2cl>0.054)||(Dpt>25&&(DsvpvDistance/DsvpvDisErr)>2.97&&Dchi2cl>0.050)))";

  TCut cutmc = "(Dgen==23333||Dgen==23344)";
  TCut cutmcSignal = "Dgen==23333";
  TCut cutmcSwapped = "Dgen==23344";
  TCut cutpt = "Dpt<20";
  TCut cutSignal = "abs(Dmass-1.8649)<0.025";
  TCut cutSideband = "abs(Dmass-1.8649)>0.075&&abs(Dmass-1.8649)<0.1";
  TCut cutPrompt = "DgenBAncestorpt<=0";
  TCut cutNonPrompt ="DgenBAncestorpt>0";
  TCut weightfunctionreco = "pthatweight";

  const int nBinX = 14;
  Float_t binsX[nBinX+1] = {2.,3.,4.,5.,6.,8.,10.,12.5,15.0,20.,25.,30.,40.,60.,100};

  const int nBinY = 20;
  Float_t binsY[nBinY+1];
  float firstBinYWidth = 0.001;
  float binYWidthRatio = 1.27;
  binsY[0]=0;
  for(int i=1; i<=nBinY; i++)
    binsY[i] = binsY[i-1]+firstBinYWidth*pow(binYWidthRatio,i-1);
  cout<<"last y bin: "<<binsY[nBinY]<<endl;

  const int nBinZ = 20;
  Float_t binsZ[nBinZ+1];
  float firstBinZ = 3.5;
  float binWidthZ = 5;
  for(int i=0; i<=nBinZ; i++)
    binsZ[i] = firstBinZ+binWidthZ*i;
  
  const int nBinM = 60;
  Float_t binsM[nBinM];
  float minMassBin = 1.7;
  float massBinWidth = 0.005;
  for(int i=0; i<=nBinM; i++)
    binsM[i] = minMassBin + massBinWidth*i;

  TH3D* hMCPSignal = new TH3D("hMCPSignal",";p_{T} (GeV/c);D0 DCA (cm);flight distance significance",nBinX,binsX,nBinY,binsY,nBinZ,binsZ);
  TH3D* hMCNPSignal = new TH3D("hMCNPSignal",";p_{T} (GeV/c);D0 DCA (cm);flight distance significance",nBinX,binsX,nBinY,binsY,nBinZ,binsZ);
  TH3D* hPtMD0DcaMCPSignal = new TH3D("hPtMD0DcaMCPSignal",";p_{T} (GeV/c);m (GeV/c^{2});D^{0} DCA (cm)",nBinX,binsX,nBinM,binsM,nBinY,binsY);
  TH3D* hPtMD0DcaMCPSwapped = new TH3D("hPtMD0DcaMCPSwapped",";p_{T} (GeV/c);m (GeV/c^{2});D^{0} DCA (cm)",nBinX,binsX,nBinM,binsM,nBinY,binsY);
  
  hMCPSignal->Sumw2();
  hMCNPSignal->Sumw2();
  hPtMD0DcaMCPSignal->Sumw2();
  hPtMD0DcaMCPSwapped->Sumw2();
  
  tMCP->Draw("DsvpvDistance/DsvpvDisErr:DsvpvDistance*sin(Dalpha):Dpt>>hMCPSignal",weightfunctionreco*(cutpt&&cutPbPbMB&&cutSignal&&cutmc&&cutPrompt));
  tMCNP->Draw("DsvpvDistance/DsvpvDisErr:DsvpvDistance*sin(Dalpha):Dpt>>hMCNPSignal",weightfunctionreco*(cutpt&&cutPbPbMB&&cutSignal&&cutmc&&cutNonPrompt));
  tMCP->Draw("DsvpvDistance*sin(Dalpha):Dmass:Dpt>>hPtMD0DcaMCPSignal",weightfunctionreco*(cutpt&&cutPbPbMB&&cutmcSignal&&cutPrompt));
  tMCP->Draw("DsvpvDistance*sin(Dalpha):Dmass:Dpt>>hPtMD0DcaMCPSwapped",weightfunctionreco*(cutpt&&cutPbPbMB&&cutmcSwapped&&cutPrompt));
  
  outf->Write();
}
コード例 #10
0
ファイル: MomentumResSmear.C プロジェクト: KongTu/V0sRatio
void MomentumResSmear(){

	TFile* file1 = new TFile("/Users/kongkong/2014Research/ROOT_file/newEPOSsample/EPOS_TH3D_Nov21_vtx_2014.root");
	TFile* file2 = new TFile("/Users/kongkong/2014Research/ROOT_file/newEPOSsample/EPOS_TH3D_Nov21_vtx_pTsmear_2014.root");

	TH3D* genKS = (TH3D*)file1->Get("ana/genKS_underlying");
	TH3D* genLA = (TH3D*)file1->Get("ana/genLA_underlying");

	TH3D* genKS_smear = (TH3D*)file2->Get("ana/genKS_underlying");
	TH3D* genLA_smear = (TH3D*)file2->Get("ana/genLA_underlying");

	//cout << "number of entries: " << genKS->GetEntries() << endl;
	//cout << "number of entries: " << genKS_smear->GetEntries() << endl;


	TH1D* genks_mass[5][28];
	TH1D* genla_mass[5][20];

	TH1D* genks_smear_mass[5][28];
	TH1D* genla_smear_mass[5][28];



	double ks_pTbinsBound[29] = {0,1,2,3,4,5,6,7,8,9,10,12,14,16,18,20,22,24,26,28,30,34,38,42,46,50,56,66,90};
    double ks_ptbins[29] = {0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.2,1.4,1.6,1.8,2.0,2.2,2.4,2.6,2.8,3.0,3.4,3.8,4.2,4.6,5.0,5.6,6.6,9.0};
    double ks_binwidth[28] = {0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.4,0.4,0.4,0.4,0.4,0.6,1.0,2.4};
    double ks_ptbincenter[28] = {0.05,0.15,0.25,0.35,0.45,0.55,0.65,0.75,0.85,0.95,1.1,1.3,1.5,1.7,1.9,2.1,2.3,2.5,2.7,2.9,3.2,3.6,4.0,4.4,4.8,5.3,6.1,7.8};

    double la_pTbinsBound[21] = {6,8,10,12,14,16,18,20,22,24,26,28,30,34,38,42,46,50,56,66,90};
    double la_ptbins[21] = {0.6,0.8,1.0,1.2,1.4,1.6,1.8,2.0,2.2,2.4,2.6,2.8,3.0,3.4,3.8,4.2,4.6,5.0,5.6,6.6,9.0};
    double la_ptbincenter[20] = {0.7,0.9,1.1,1.3,1.5,1.7,1.9,2.1,2.3,2.5,2.7,2.9,3.2,3.6,4.0,4.4,4.8,5.3,6.1,7.8};
    double la_binwidth[20] = {0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.4,0.4,0.4,0.4,0.4,0.6,1.0,2.4};

    double rpybins[6] = {6,16,26,35,44,55};
    double rpybinwidth[5] = {1.0,0.97,0.9,0.93,1.0};

	stringstream ksName;
	stringstream laName;

	for(int rpy = 0; rpy < 5; rpy++){

		for(int pt = 0; pt < 28; pt++){

			ksName.str("");
			ksName << "genks_mass";
			ksName << "_";
			ksName << rpy+1;
			ksName << "_";
			ksName << pt+1;

			genks_mass[rpy][pt] = genKS->ProjectionZ(ksName.str().c_str(),rpybins[rpy]+1,rpybins[rpy+1],ks_pTbinsBound[pt]+1,ks_pTbinsBound[pt+1]);

			ksName.str("");
			ksName << "genks_smear_mass";
			ksName << "_";
			ksName << rpy+1;
			ksName << "_";
			ksName << pt+1;

			genks_smear_mass[rpy][pt] = genKS_smear->ProjectionZ(ksName.str().c_str(),rpybins[rpy]+1,rpybins[rpy+1],ks_pTbinsBound[pt]+1,ks_pTbinsBound[pt+1]);
		}

		for(pt = 0; pt < 20; pt++){

			laName.str("");
			laName << "genla_mass";
			laName << "_";
			laName << rpy+1;
			laName << "_";
			laName << pt+1;

			genla_mass[rpy][pt] = genLA->ProjectionZ(laName.str().c_str(),rpybins[rpy]+1,rpybins[rpy+1],la_pTbinsBound[pt]+1,la_pTbinsBound[pt+1]);

			laName.str("");
			laName << "genla_smear_mass";
			laName << "_";
			laName << rpy+1;
			laName << "_";
			laName << pt+1;

			genla_smear_mass[rpy][pt] = genLA_smear->ProjectionZ(laName.str().c_str(),rpybins[rpy]+1,rpybins[rpy+1],la_pTbinsBound[pt]+1,la_pTbinsBound[pt+1]);


		}
	}

   	int genksYield[5][28];
   	int genlaYield[5][20];

  	int genksSmearYield[5][28];
  	int genlaSmearYield[5][20];

   	for(rpy = 0; rpy < 5; rpy++){

   		for( pt = 0; pt < 28; pt++){

   			genksYield[rpy][pt] = genks_mass[rpy][pt]->GetEntries();
   			genksSmearYield[rpy][pt] = genks_smear_mass[rpy][pt]->GetEntries();
   		}
	   	
	   	for (pt = 0; pt < 20; pt++){

	   		genlaYield[rpy][pt] = genla_mass[rpy][pt]->GetEntries();
	   		genlaSmearYield[rpy][pt] = genla_smear_mass[rpy][pt]->GetEntries();

	   	}
	}
	   		
	

/*
GEN spectra distribution;
 */

	TH1D* ksSpectra_gen[5];
	TH1D* laSpectra_gen[5];

	TH1D* ksSpectra_gen_smear[5];
	TH1D* laSpectra_gen_smear[5];

	for(rpy = 0; rpy < 5; rpy++){

		ksName.str("");
		laName.str("");

		ksName << "ksSpectra_epos_gen_";
		ksName << rpy+1;

		laName << "laSpectra_epos_gen_";
		laName << rpy+1;

		ksSpectra_gen[rpy] = new TH1D(ksName.str().c_str(),ksName.str().c_str(),28,ks_ptbins);
		laSpectra_gen[rpy] = new TH1D(laName.str().c_str(),laName.str().c_str(),20,la_ptbins);

		ksName.str("");
		laName.str("");

		ksName << "ksSpectra_epos_gen_smear_";
		ksName << rpy+1;

		laName << "laSpectra_epos_gen_smear_";
		laName << rpy+1;

		ksSpectra_gen_smear[rpy] = new TH1D(ksName.str().c_str(),ksName.str().c_str(),28,ks_ptbins);
		laSpectra_gen_smear[rpy] = new TH1D(laName.str().c_str(),laName.str().c_str(),20,la_ptbins);

		for(pt = 0; pt < 28; pt++){

			ksSpectra_gen[rpy]->SetBinContent(pt+1, genksYield[rpy][pt]/(2*3.1415926*ks_binwidth[pt]*ks_ptbincenter[pt]*rpybinwidth[rpy] ));
				ksSpectra_gen[rpy]->SetBinError(pt+1, sqrt( genksYield[rpy][pt] )/(2*3.1415926*ks_binwidth[pt]*ks_ptbincenter[pt]*rpybinwidth[rpy] ));

			ksSpectra_gen_smear[rpy]->SetBinContent(pt+1, genksSmearYield[rpy][pt]/(2*3.1415926*ks_binwidth[pt]*ks_ptbincenter[pt]*rpybinwidth[rpy] ));
				ksSpectra_gen_smear[rpy]->SetBinError(pt+1, sqrt( genksSmearYield[rpy][pt] )/(2*3.1415926*ks_binwidth[pt]*ks_ptbincenter[pt]*rpybinwidth[rpy] ));

		}

		for(pt = 0; pt < 20; pt++){

			laSpectra_gen[rpy]->SetBinContent(pt+1, genlaYield[rpy][pt]/(2*3.1415926*la_binwidth[pt]*la_ptbincenter[pt]*rpybinwidth[rpy] ));
				laSpectra_gen[rpy]->SetBinError(pt+1, sqrt( genlaYield[rpy][pt] )/(2*3.1415926*la_binwidth[pt]*la_ptbincenter[pt]*rpybinwidth[rpy]));

			laSpectra_gen_smear[rpy]->SetBinContent(pt+1, genlaSmearYield[rpy][pt]/(2*3.1415926*la_binwidth[pt]*la_ptbincenter[pt]*rpybinwidth[rpy] ));
				laSpectra_gen_smear[rpy]->SetBinError(pt+1, sqrt( genlaSmearYield[rpy][pt] )/(2*3.1415926*la_binwidth[pt]*la_ptbincenter[pt]*rpybinwidth[rpy] ));

		}
	}

	TLine* l1 = new TLine(0,1,9.0,1.0);
	l1->SetLineWidth(2);
	l1->SetLineColor(kRed);
	l1->SetLineStyle(2);

	TLatex* ratio[5];
    ratio[0] = new TLatex(1.65,1.06,"-2.87 < y < -1.8");
    ratio[1] = new TLatex(1.65,1.06,"-1.8 < y < -0.9");
    ratio[2] = new TLatex(1.65,1.06,"-0.9 < y < 0");
    ratio[3] = new TLatex(1.65,1.06,"0 < y < 0.93");
    ratio[4] = new TLatex(1.65,1.06,"0.93 < y < 1.93");

	TCanvas* c1 = new TCanvas();
	c1->Divide(3,2,0,0);
	for(rpy = 0; rpy < 5; rpy++){

		c1->cd(rpy+1);
		laSpectra_gen[rpy]->Divide( laSpectra_gen_smear[rpy] );
		laSpectra_gen[rpy]->SetMarkerStyle(20);
		laSpectra_gen[rpy]->SetLineColor(kBlack);
		laSpectra_gen[rpy]->GetYaxis()->SetRangeUser(0.9,1.1);
		laSpectra_gen[rpy]->SetTitle("#Lambda/#bar{#Lambda}");
		laSpectra_gen[rpy]->SetYTitle("noSmear/Smear");
		laSpectra_gen[rpy]->SetXTitle("pT(GeV/c)");
		laSpectra_gen[rpy]->SetStats(kFALSE);

		laSpectra_gen[rpy]->Draw("P");
		l1->Draw("same");
		ratio[rpy]->Draw("same");


	}


}
コード例 #11
0
ファイル: correlate.C プロジェクト: CmsHI/HiForestAnalysis
void correlate(
    const char* infname = "/data_CMS/cms/yilmaz/HiForest_HYDJET_Track8_Jet21_STARTHI53_LV1_merged_forest_0.root",
    const char* outname = "histograms_01.root",
    bool MC = 1,
    bool PbPb = 1,
    double jetEtaMax = 1.6,
    int centIndex = 0, int etaBin = 0, int leadJetPtBin = 0, int trackPtBin = 0
) {

    cout<<"Begin"<<endl;

    bool mini = 1;

    int Nevents = 1000;

    bool usePF = 1;
    int R = 3;

    double etaCOM = -0.465;

    bool doFlow = 0;
    bool doInclusiveJets = 1;
    bool doTracks = 1;
    bool doGenParticles = 1;

    bool fillTracks = 0;

    if(mini) {
        fillTracks = 0;
        doTracks = 0;
    }

    double pi = TMath::Pi();

    double trkMin = 0.5;

    double leadPtMin = 120;
    double subleadPtMin = 50;
    double dphiMin = 2.*pi/3.;

    int frame = 1; // Dijet frame for z

    int analysisId = 0;

    double ptSubLeadMin = 30;
    double ptLeadMin = 120;

    double etLeadMin[10] = {100, 100,120,150,180,200  };
    double etLeadMax[10] = {1000,120,150,180,200,1000 };

    double tkMin[10] = {4.,  4.,5.,7.,10., 20.};
    double tkMax[10] = {100.,5.,7.,10.,20.,1000.};

    TF1* gaus = new TF1("gaus","gaus",-5,5);
    gaus->SetParameter(0,1);
    gaus->SetParameter(1,0);
    gaus->SetParameter(2,1);

    TRandom* engin = new TRandom();

    //  double fitMin[10] = {100,80,60,50,100};
    //  double fitMax[10] = {250,200,150,100,250};

    double fitMin[10] = {100,90,80,70,100};
    double fitMax[10] = {300,300,300,300,300};

    TH1::SetDefaultSumw2();
    TH2::SetDefaultSumw2();
    cout<<"x"<<endl;

    string name[10] = {"c0to10","c10to20","c20to30","c30to50","c50to100","c0to30","c30to100","c0to100"};
    cout<<"x"<<endl;

    TFile* outf = new TFile(outname,"recreate");

    TNtuple *nt;
    nt = new TNtuple("nt","nt","x");

    TH3D* hAxisLead = new TH3D("hAxisLead","",500,0,500,160,-1.6,1.6,200,-pi,pi);
    TH3D* hAxisSubLead = new TH3D("hAxisSubLead","",500,0,500,160,-1.6,1.6,200,-pi,pi);

    TH3D* hCorrLead = new TH3D("hCorrLead","",500,0,500,160,-1.6,1.6,200,-pi,pi);
    TH3D* hCorrSubLead = new TH3D("hCorrSubLead","",500,0,500,160,-1.6,1.6,200,-pi,pi);

    TH3D* hGenParticleLead = new TH3D("hGenParticleLead","",500,0,500,160,-1.6,1.6,200,-pi,pi);
    TH3D* hGenParticleSubLead = new TH3D("hGenParticleSubLead","",500,0,500,160,-1.6,1.6,200,-pi,pi);

    TH1D* hPtLead = new TH1D("hPtLead","",500,0,500);
    TH1D* hPtSubLead = new TH1D("hPtSubLead","",500,0,500);

    bool pp = 0;

    double ajMin[10] = {0,    0.11, 0.22, 0.33, 0. , 0, 0};
    double ajMax[10] = {0.11, 0.22, 0.33, 1.,   1. , 0 ,0};

    int nEta = 4;
    double etaMin[10] = {0,  0,    0.5,  1.};
    double etaMax[10] = {5., 0.5,  1.,   2.};

    outf->cd();

    int NxsiBin = 20;
    int NptBin = 100;
    double zBins[21];
    double ptBins[101];

    cout<<"BINS : "<<endl;
    for(int i = 0; i < NxsiBin+1; ++i) {
        double xsi = -1+(10./NxsiBin)*(NxsiBin-i-1);
        cout<<"xsi : "<<xsi<<endl;
        zBins[i] = exp(-xsi);
    }

    for(int i = 0; i < NptBin+1; ++i) {
        ptBins[i] = i*1000./NptBin;
    }

    HiForest * t;
    if(PbPb) {
        t = new HiForest(infname,"",cPbPb,MC);
    } else {
        t = new HiForest(infname,"",cPPb,MC);
    }

    t->hasPhotonTree *= 0;
    t->hasMetTree *= 0;
    t->hasPFTree *= 0;
    t->hasPFTree *= 0;


    t->hasAk2JetTree *= 0;
    t->hasAk3JetTree *= 1;
    t->hasAk4JetTree *= 0;
    t->hasAk5JetTree *= 1;

    t->hasAkPu2JetTree *= 0;
    t->hasAkPu3JetTree *= 1;
    t->hasAkPu4JetTree *= 0;
    t->hasAkPu5JetTree *= 1;

    t->hasAk2CaloJetTree *= 0;
    t->hasAk3CaloJetTree *= 1;
    t->hasAk4CaloJetTree *= 0;
    t->hasAk5CaloJetTree *= 1;

    t->hasAkPu2CaloJetTree *= 0;
    t->hasAkPu3CaloJetTree *= 1;
    t->hasAkPu4CaloJetTree *= 0;
    t->hasAkPu5CaloJetTree *= 1;

    t->hasTrackTree *= 1;
    t->hasPixTrackTree *= 0;
    t->hasTowerTree *= 0;
    t->hasHbheTree *= 0;
    t->hasEbTree *= 0;
    t->hasGenpTree *= 0;
    t->hasGenParticleTree *= MC;

    t->InitTree();

    cout<<"a"<<endl;


    if(Nevents > 0) {
        t->nEntries = Nevents;
    } else {
        Nevents = t->nEntries;
    }

    outf->cd();

    vector<JetIndex> vecs;
    vecs.reserve(maxEntry);

    float z1[4], z2[4],
          z1a[4], z2a[4],
          z1b[4], z2b[4],
          z1c[4], z2c[4];

    float tdt1[4], tdt2[4], tdt1a[4], tdt2a[4], tdt1b[4], tdt2b[4], tdt1c[4], tdt2c[4];

    Jets *jets0 = 0, * jets1 = 0, *jets2 = 0;
    TTree  *jetTree0 = 0, * jetTree1 = 0, *jetTree2 = 0;

    if(usePF) {
        if(R == 3) {
            jets1 = &(t->akPu3PF);
            jetTree1 = t->akPu3PFJetTree;
        }
        if(R == 5) {
            jets1 = &(t->akPu5PF);
            jetTree1 = t->akPu5PFJetTree;
        }
    } else {
        if(R == 3) {
            jets1 = &(t->akPu3Calo);
            jetTree1 = t->akPu3CaloJetTree;
        }
        if(R == 5) {
            jets1 = &(t->akPu5Calo);
            jetTree1 = t->akPu5CaloJetTree;
        }
    }

    cout<<"a"<<endl;

    for(int iev = 0; iev < Nevents; ++iev) {
        if(iev%1000==0) {
            cout<<"Processing entry : "<<iev<<endl;
        }
        t->GetEntry(iev);

        if(!MC && !PbPb && !(t->skim.pPAcollisionEventSelectionPA && t->skim.pHBHENoiseFilter)) continue;
        if(!MC && PbPb && !(t->skim.pcollisionEventSelection && t->skim.pHBHENoiseFilter)) continue;

        // add other selection

        int noise = -1;

        if(!MC && noise >= 2) continue;

        cout<<"passed event selection"<<endl;

        float pthat = jets1->pthat;

        double pt1 = -9, pt2 = -9, pt3 = -9, aj = -9,
               eta1 = -9,eta2 = -9,phi1 = -9,phi2 = -9,
               dphi  = -9, adphi  = -9,
               eta3 = -9, phi3 = -9, dr = -9,
               ch1 = 0,ch2 = 0, ch1alt = 0, ch2alt = 0,

               refpt1 = 0, refpt2 = 0, refpt3 = 0,
               genpt1 = 0, genpt2 = 0, genpt3 = 0,

               pu1=-9,pu2=-9, pu3 = -9,
               puc1=-9,puc2=-9, puc3 = -9,

               raw1=-9,raw2=-9, raw3 = -9,

               drm1=-9,drm2=-9, drm3=-9,
               psi1=-9, psi2=-9, psi=-9, psiP=-9, psiM=-9, psiPS=-9, psiMS=-9, psiS=-9,
               psiTri = -9, psiTriP = -9, psiTriM = -9, psiTriS = -9, psiTriPS = -9, psiTriMS = -9;

        float etsum=0,etx=0,ety=0,v2=0,
              etp=0,etxp=0,etyp=0,v2p=0,
              etm=0,etxm=0,etym=0,v2m=0,
              v2pm=0,v2mp=0,v2pp=0,v2mm=0,etx1=0,ety1=0,
              v2s,v2ps,v2ms;

        int dijetType = -9,njt10=0,njt20=0,njt30=0,njt40=0,njt50=0,njt100=0;
        int ngen10 = 0, ngen20=0, ngen30 = 0, ngen50 = 0;

        float trkMax1 = -9,trkMax2=-9,trkMax3=-9,
              trkSum1=-9,trkSum2=-9,trkSum3=-9,
              had1=-9,had2=-9,had3=-9,
              matchPt1=-9,matchPt2=-9,matchPt3=-9;

        int nSide = -9;

        int iPlane = 21; //21 HF, 0 tracks

        double flowEtaMin = 3;

        double hfp = t->evt.hiHFplusEta4;
        double hfm = t->evt.hiHFminusEta4;
        double zdc = t->evt.hiZDCplus;
        double vz = t->track.zVtx[t->track.maxVtx];

        double ntrk = t->evt.hiNtracks;
        double npix = t->evt.hiNpix;

        int nside = 0;
        int nps = 0;
        int npb = 0;
        int npscom = 0;
        int npbcom = 0;
        double hfs = 0, hfb = 0;
        int nls = 0, nlb = 0, nlscom = 0, nlbcom = 0;

        psi = t->evt.hiEvtPlanes[iPlane];
        psiM = t->evt.hiEvtPlanes[iPlane+2];
        psiP = t->evt.hiEvtPlanes[iPlane+1];

        v2 = 0;

        vecs.clear();

        for(int j = 0; j < jets1->nref; ++j) {
            if(jets1->rawpt[j] < 15) continue;

            if( fabs(jets1->jteta[j]) > jetEtaMax ) continue;

            JetIndex entry;
            entry.pt = jets1->jtpt[j];
            entry.index = j;
            vecs.push_back(entry);

            if(jets1->jtpt[j]>10) njt10++;
            if(jets1->jtpt[j]>20) njt20++;
            if(jets1->jtpt[j]>30) njt30++;
            if(jets1->jtpt[j]>40) njt40++;
            if(jets1->jtpt[j]>50) njt50++;
            if(jets1->jtpt[j]>100) njt100++;
        }

        sort(vecs.begin(),vecs.end(),comparePt);

        int jtLead = -1, jtSubLead = -1, jtThird = -1;

        if(vecs.size() > 0) jtLead = vecs[0].index;
        if(vecs.size() > 1) jtSubLead = vecs[1].index;
        if(vecs.size() > 2) jtThird = vecs[2].index;

        cout<<"Got some jets "<<vecs.size()<<endl;
        if(vecs.size() > 0) cout<<"pt1 : "<<jets1->jtpt[jtLead]<<endl;
        if(vecs.size() > 1) cout<<"pt2 : "<<jets1->jtpt[jtSubLead]<<endl;

        if(!MC && (vecs.size() < 1 || jets1->jtpt[jtLead] < leadPtMin)) continue;
        if(vecs.size() < 2 || jets1->jtpt[jtSubLead] < subleadPtMin) continue;
        if(fabs(deltaPhi(phi1,phi2)) < dphiMin) continue;

        cout<<"Got dijets"<<endl;

        int evt = t->hlt.Event;
        int run = t->hlt.Run;

        if(jtLead > -1) {
            pt1 = jets1->jtpt[jtLead];
            eta1 = jets1->jteta[jtLead];
            phi1 = jets1->jtphi[jtLead];
            raw1 = jets1->rawpt[jtLead];
            trkMax1 = jets1->trackMax[jtLead];
            trkSum1 = jets1->trackSum[jtLead];
            matchPt1 = jets1->matchedPt[jtLead];

            if(MC) refpt1 = jets1->refpt[jtLead];
        }

        if(jtSubLead > -1) {
            pt2 = jets1->jtpt[jtSubLead];
            eta2 = jets1->jteta[jtSubLead];
            phi2 = jets1->jtphi[jtSubLead];
            raw2 = jets1->rawpt[jtSubLead];
            trkMax2 = jets1->trackMax[jtSubLead];
            trkSum2 = jets1->trackSum[jtSubLead];
            matchPt2 = jets1->matchedPt[jtSubLead];

            if(MC) refpt2 = jets1->refpt[jtSubLead];

            aj = (pt1-pt2)/(pt1+pt2);
            dphi = deltaPhi(phi1,phi2);
            adphi = fabs(dphi);

            dr= deltaR(eta2,phi2,eta1,phi1);
            //       correlateTracks(t->track,eta2,phi2,trkMin,ch2,trk2,ntrk2);
        }

        if(jtThird > -1) {
            pt3 = jets1->jtpt[jtThird];
            eta3 = jets1->jteta[jtThird];
            phi3 = jets1->jtphi[jtThird];
            raw3 = jets1->rawpt[jtThird];
            trkMax3 = jets1->trackMax[jtThird];
            trkSum3 = jets1->trackSum[jtThird];
            matchPt3 = jets1->matchedPt[jtThird];

            if(MC) refpt3 = jets1->refpt[jtThird];

        }

        if(MC) {
            vecs.clear();
            for(int j = 0; j < jets1->ngen; ++j) {
                JetIndex entry;
                if(fabs(jets1->geneta[j]) > 2) continue;
                entry.pt = jets1->genpt[j];
                entry.index = j;
                vecs.push_back(entry);

                if(jets1->genpt[j] > 10)ngen10++;
                if(jets1->genpt[j] > 20)ngen20++;
                if(jets1->genpt[j] > 30)ngen30++;
                if(jets1->genpt[j] > 50)ngen50++;

            }

            sort(vecs.begin(),vecs.end(),comparePt);

            int ig1 = -1, ig2 = -1, ig3 = -1;
            if(vecs.size() > 0) {
                ig1 = jets1->genmatchindex[vecs[0].index];
                genpt1 = jets1->genpt[vecs[0].index];
            }
            if(vecs.size() > 1) {
                ig2 = jets1->genmatchindex[vecs[1].index];
                genpt2 = jets1->genpt[vecs[1].index];
            }
            if(vecs.size() > 2) {
                ig3 = jets1->genmatchindex[vecs[2].index];
                genpt3 = jets1->genpt[vecs[2].index];
            }

        }

        double dijetEta = (eta1+eta2)/2;

        cout<<"Filling jets"<<endl;

        double weight = 1;
        hPtLead->Fill(pt1,weight);
        hPtSubLead->Fill(pt2,weight);

        hAxisLead->Fill(pt1,eta1,phi1,weight);
        hAxisSubLead->Fill(pt2,eta2,phi2,weight);

        if(doGenParticles) {

            for(int i = 0; i < t->genparticle.mult; ++i) {
                if(t->genparticle.chg[i] == 0 || t->genparticle.sta[i] != 1) continue;
                double peta = t->genparticle.eta[i];
                double pphi = t->genparticle.phi[i];
                hGenParticleLead->Fill(pt1,deltaEta(peta,eta1),deltaPhi(pphi,phi1),weight);
                hGenParticleSubLead->Fill(pt2,deltaEta(peta,eta2),deltaPhi(pphi,phi2),weight);
            }
        }

        if(doTracks) {

            for(int i = 0; i < t->track.nTrk; ++i) {
                if(!t->selectTrack(i)) continue;
                if(t->track.trkPt[i] < trkMin) continue;
                double peta = t->track.trkEta[i];
                double pphi = t->track.trkPhi[i];
                hCorrLead->Fill(pt1,deltaEta(peta,eta1),deltaPhi(pphi,phi1),weight);
                hCorrSubLead->Fill(pt2,deltaEta(peta,eta2),deltaPhi(pphi,phi2),weight);

            }
        }

    }

    outf->Write();

    cout<<"Congrats!!!"<<endl;


}
コード例 #12
0
ファイル: pileup.C プロジェクト: CmsHI/CVS_CmsHi
void pileup()
{
//  TH3D* h = (TH3D*)GetHist("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/outputs_312/HIData_Minbias_2760GeV/merged/HIData_Minbias_2760GeV_PPRereco_INCLMULT_nmin-1_nmax-1_etatrg-2.4-2.4_etaass-2.4-2.4_centmin-1_centmax-1.root","multmaxvssecvszvtxsep");
  TH3D* h = (TH3D*)GetHist("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/outputs_312/HydjetReco_Minbias_2760GeV/merged/HydjetReco_Minbias_2760GeV_PeripheralNew_INCLMULT_nmin-1_nmax-1_etatrg-2.4-2.4_etaass-2.4-2.4_centmin-1_centmax-1.root","multmaxvssecvszvtxsep");
//  TH3D* h = (TH3D*)GetHist("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/outputs_312/PAData_Minbias_5TeV/merged/PAData_Minbias_5TeV_HM_PromptReco_INCLMULTAllPURej3Vtx_nmin-1_nmax-1_etatrg-2.4-2.4_etaass-2.4-2.4_centmin-1_centmax-1.root","multmaxvssecvszvtxsep");

  TF1* func[40];
  TGraph* xx_yy[40];
  double par0_arr[40];
  double par1_arr[40];
  double par2_arr[40];
  double dz_arr[40];
//  double binwidth=0.2;
  double binedges[16]={0.0,0.2,0.3,0.4,0.5,0.6,0.8,1.0,1.4,1.8,2.4,3.0,4.2,5.0,7.0,10.0};

  TCanvas* c16 = new TCanvas("c16","c16",800,600);
  c16->Divide(4,4);

  for(int i=0;i<15;i++)
  {
//    h->GetZaxis()->SetRange(h->GetZaxis()->FindBin(binwidth*i),h->GetZaxis()->FindBin(binwidth*i+binwidth));
    h->GetZaxis()->SetRange(h->GetZaxis()->FindBin(binedges[i]),h->GetZaxis()->FindBin(binedges[i+1]));
    h->GetYaxis()->SetRange(h->GetYaxis()->FindBin(2),h->GetYaxis()->FindBin(50));
    TH2D* h2D = (TH2D*)h->Project3DProfile(Form("yx%d",i));
    h2D->Rebin2D(10,1);
    TProfile* hprof_x = (TProfile*)h2D->ProfileX("hprof_x",-1,-1,"s");
    double xx[500];
    double yy[500];
    for(int ibin=1;ibin<=hprof_x->GetNbinsX();ibin++)
    {
      yy[ibin-1] = hprof_x->GetBinContent(ibin)+2*hprof_x->GetBinError(ibin);
      xx[ibin-1] = hprof_x->GetBinCenter(ibin);
    }
  
// Hydjet
//    TF1* func = new TF1("func","[0]+[1]*(x-[2])*(x-[2])",0,500);
//    func->SetParameters(20,-0.1,150);
  func[i] = new TF1(Form("func_%d",i),"[0]*x**[1]",0,500);
  func[i]->SetParameters(1,0.5);
  func[i]->SetParLimits(0,0,10000);
  func[i]->SetParLimits(1,0,10000);
  if(i==0) func[i]->FixParameter(0,8); //pPb
//  else if(i>11) func[i]->FixParameter(0,20); //pPb
  else func[i]->FixParameter(0,2.); //pPb

//  func->FixParameter(0,5); //PbPb

//    TF1* func = new TF1("func","[0]+[1]*x",40,500);
//    double par1 = (hprof_x->GetBinContent(6)+hprof_x->GetBinError(6)-hprof_x->GetBinContent(1)-hprof_x->GetBinError(1))/(hprof_x->GetBinCenter(6)-hprof_x->GetBinCenter(1));
//    double par0 = hprof_x->GetBinContent(6)+hprof_x->GetBinError(6)-par1*hprof_x->GetBinCenter(6);
//    func->SetParameters(par0,par1);

    xx_yy[i] = new TGraph(hprof_x->GetNbinsX(),xx,yy);
    xx_yy[i]->Fit(Form("func_%d",i),"NO","",0,300);

    c16->cd(i+1);
    xx_yy[i]->Draw("AP"); 
    func[i]->SetLineColor(kRed);
    func[i]->Draw("Lsame");   

    par2_arr[i] = func[i]->GetParameter(2);    
    par1_arr[i] = func[i]->GetParameter(1);
    par0_arr[i] = func[i]->GetParameter(0);
    dz_arr[i] = (binedges[i]+binedges[i+1])/2;
  }

  TGraph* gr_par0 = new TGraph(15,dz_arr,par0_arr);
  TGraph* gr_par1 = new TGraph(15,dz_arr,par1_arr);
  TGraph* gr_par2 = new TGraph(15,dz_arr,par2_arr);

  TCanvas* cc = new TCanvas("cc","",950,400);  
  cc->Divide(3,1);
  cc->cd(1);
  gr_par0->Draw("AP");
  TF1* func_par0 = new TF1("func_par0","[2]*exp(-x**2/[0])*x**[3]+[1]",0.0,10.0);
  func_par0->SetParameters(0.2,0,5,-1);
  func_par0->FixParameter(2,0);
  gr_par0->Fit("func_par0","NO","",0.3,4.0);
  func_par0->Draw("Lsame");
  cc->cd(2);
  gr_par1->Draw("AP");
//  TF1* func_par1 = new TF1("func_par1","[2]*exp(-x**2/[0])*x**[3]+[1]",0.,10.0);
//  func_par1->SetParameters(0.2,0,-0.0005,0);
//  TF1* func_par1 = new TF1("func_par1","[2]*exp(-x/[0])*x**[3]+[1]",0.,10.0);
  TF1* func_par1 = new TF1("func_par1","[1]*exp(-x**[2]/[0])*x**[3]",0.,10.0);
  func_par1->SetParameters(0.1,0.6,2,1);
//  func_par1->FixParameter(2,1);
//  func_par1->FixParameter(3,1);

  gr_par1->Fit("func_par1","NO","",0.3,4.0);
  func_par1->Draw("Lsame");
  cc->cd(3);
  gr_par2->Draw("AP"); 
  TF1* func_par2 = new TF1("func_par2","[2]*exp(-x**2/[0])*x**[3]+[1]",0.,10.0);
  func_par2->SetParameters(1.2,170,120,1);
  gr_par2->Fit("func_par2","NO","",0.2,2.0);
  func_par2->Draw("Lsame");

cout<<Form("par0=%.2f*exp(-x**2/%.2f)*(x**%.2f)+%.2f",func_par0->GetParameter(2),func_par0->GetParameter(0),func_par0->GetParameter(3),func_par0->GetParameter(1))<<endl;
cout<<Form("par1=%.6f*exp(-x/%.6f)*(x**%.6f)+%.2f",func_par1->GetParameter(2),func_par1->GetParameter(0),func_par1->GetParameter(3),func_par1->GetParameter(1))<<endl;
cout<<Form("par2=%.2f*exp(-x**2/%.2f)*(x**%.2f)+%.2f",func_par2->GetParameter(2),func_par2->GetParameter(0),func_par2->GetParameter(3),func_par2->GetParameter(1))<<endl;

//  TF2* func2D = new TF2("func2D","[2]*exp(-x**2/[0])*x**[3]+[1]+([6]*exp(-x**2/[7])*x**[3]+[5])*y",0,1.0,0,500);
//  TF2* func2D = new TF2("func2D","[2]*exp(-x**2/[0])*x**[3]+[1]+([6]*exp(-x/[4])*x**[7]+[5])*(y-[10]*exp(-x**2/[8])*x**[11]-[9])*(y-[10]*exp(-x**2/[8])*x**[11]-[9])",0,5.0,0,500);
//  TF2* func2D = new TF2("func2D","([2]*exp(-x**2/[0])*x**[3]+[1])*y**[4]",0,10.0,0,500);
  TF2* func2D = new TF2("func2D","[0]*y**([2]*exp(-x**[3]/[1])*x**[4])",0,10.0,0,500);
  func2D->SetParameter(0,func_par0->GetParameter(1));
  func2D->SetParameter(1,func_par1->GetParameter(0));
  func2D->SetParameter(2,func_par1->GetParameter(1));
  func2D->SetParameter(3,func_par1->GetParameter(2));
  func2D->SetParameter(4,func_par1->GetParameter(3));
/*
  func2D->SetParameter(0,func_par0->GetParameter(0));
  func2D->SetParameter(1,func_par0->GetParameter(1));
  func2D->SetParameter(2,func_par0->GetParameter(2));
  func2D->SetParameter(3,func_par0->GetParameter(3));
  func2D->SetParameter(4,func_par1->GetParameter(0));
  func2D->SetParameter(5,func_par1->GetParameter(1));
  func2D->SetParameter(6,func_par1->GetParameter(2));
  func2D->SetParameter(7,func_par1->GetParameter(3));
  func2D->SetParameter(8,func_par2->GetParameter(0));
  func2D->SetParameter(9,func_par2->GetParameter(1));
  func2D->SetParameter(10,func_par2->GetParameter(2));
  func2D->SetParameter(11,func_par2->GetParameter(3));
*/
/*
cout<<Form("%.6f, %.6f, %.6f, %.6f,",func_par0->GetParameter(0),func_par0->GetParameter(1),func_par0->GetParameter(2),func_par0->GetParameter(3))<<endl;
cout<<Form("%.6f, %.6f, %.6f, %.6f,",func_par1->GetParameter(0),func_par1->GetParameter(1),func_par1->GetParameter(2),func_par1->GetParameter(3))<<endl;
cout<<Form("%.6f, %.6f, %.6f, %.6f,",func_par2->GetParameter(0),func_par2->GetParameter(1),func_par2->GetParameter(2),func_par2->GetParameter(3))<<endl;
*/
cout<<Form("%.6f, %.6f, %.6f, %.6f, %.6f,",func2D->GetParameter(0),func2D->GetParameter(1),func2D->GetParameter(2),func2D->GetParameter(3),func2D->GetParameter(4))<<endl;
cout<<Form("%.6f, %.6f",func[0]->GetParameter(0),func[0]->GetParameter(1))<<endl;

  TH2D* h_pileup = new TH2D("distfunc",";d (cm);N_{trk}^{primary};N_{trk}^{secondary}",500,0,50.0,50,0,500);

  for(int i=1;i<=h_pileup->GetNbinsX();i++) 
    for(int j=1;j<=h_pileup->GetNbinsY();j++)
    {

//      if(h_pileup->GetYaxis()->GetBinCenter(j)<func2D->Eval(h_pileup->GetXaxis()->GetBinCenter(i),h_pileup->GetYaxis()->GetBinCenter(j))) h_pileup->SetBinContent(i,j,h_pileup->GetYaxis()->GetBinCenter(j));
//      else if(h_pileup->GetXaxis()->GetBinCenter(i)<0.2) h_pileup->SetBinContent(i,j,func2D->Eval(0.2,h_pileup->GetYaxis()->GetBinCenter(j)));
//      else h_pileup->SetBinContent(i,j,func2D->Eval(h_pileup->GetXaxis()->GetBinCenter(i),h_pileup->GetYaxis()->GetBinCenter(j)));
      if(h_pileup->GetXaxis()->GetBinCenter(i)<0.2) h_pileup->SetBinContent(i,j,func[0]->Eval(h_pileup->GetYaxis()->GetBinCenter(j)));
      else h_pileup->SetBinContent(i,j,func2D->Eval(h_pileup->GetXaxis()->GetBinCenter(i),h_pileup->GetYaxis()->GetBinCenter(j)));
    }

/*
  for(int i=1;i<=h_pileup->GetNbinsX();i++) 
    for(int j=1;j<=h_pileup->GetNbinsY();j++)
    {
      for(int k=0;k<15;k++) 
      {
        if(h_pileup->GetXaxis()->GetBinCenter(i)>binedges[k] && h_pileup->GetXaxis()->GetBinCenter(i)<binedges[k+1]) h_pileup->SetBinContent(i,j,func[k]->Eval(h_pileup->GetYaxis()->GetBinCenter(j)));
      }
    }
*/

  TCanvas* c2D = new TCanvas("c2D","",550,500);
  c2D->SetPhi(-60);
  c2D->SetTheta(50);
  h_pileup->SetAxisRange(0,3.0,"X");
  h_pileup->GetXaxis()->CenterTitle();
  h_pileup->GetYaxis()->CenterTitle();
  h_pileup->GetZaxis()->CenterTitle();
  h_pileup->Draw("surf1"); 
  SaveCanvas(c2D,"pPb/corr","pileup_distfunc_hydjet");
return;
  TFile* fout = new TFile("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/efficiency/pileup_distfunc_pPb_1sigma_mode1.root","recreate");
  h_pileup->Write();
  fout->Close();
}
コード例 #13
0
ファイル: pileup.C プロジェクト: CmsHI/CVS_CmsHi
void pileup1(double dzmin, double dzmax)
{
  TH1D* hdz = (TH1D*)GetHist("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/outputs_312/PAData_Minbias_5TeV/merged/PAData_Minbias_5TeV_MBNEW_INCLMULT_nmin-1_nmax-1_etatrg-2.4-2.4_etaass-2.4-2.4_centmin-1_centmax-1.root","xyzvtxsepmin");
  TH3D* h1 = (TH3D*)GetHist("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/outputs_312/PAData_Minbias_5TeV/merged/PAData_Minbias_5TeV_MBNEW_INCLMULT_nmin-1_nmax-1_etatrg-2.4-2.4_etaass-2.4-2.4_centmin-1_centmax-1.root","multmaxvssecvszvtxsep"); 
  TH2D* h21 = (TH2D*)GetHist("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/outputs_312/PAData_Minbias_5TeV/merged/PAData_Minbias_5TeV_MBNEW_INCLMULT_nmin-1_nmax-1_etatrg-2.4-2.4_etaass-2.4-2.4_centmin-1_centmax-1.root","multmaxvssec");
  TH2D* hNvtxVsMult = (TH2D*)GetHist("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/outputs_312/PAData_Minbias_5TeV/merged/PAData_Minbias_5TeV_MBNEW_INCLMULT_nmin-1_nmax-1_etatrg-2.4-2.4_etaass-2.4-2.4_centmin-1_centmax-1.root","nvtxvsnmult");

  TH1D* htrk_max1 = h1->ProjectionX();
  h1->GetZaxis()->SetRange(h1->GetZaxis()->FindBin(dzmin),h1->GetZaxis()->FindBin(dzmax));
  h1->GetYaxis()->SetRange(h1->GetYaxis()->FindBin(2),h1->GetYaxis()->FindBin(50));
  TH2D* h2D1 = (TH2D*)h1->Project3DProfile("yx100");
  h2D1->Rebin2D(5,1);
  TProfile* hprof1_x = (TProfile*)h2D1->ProfileX("hprof1_x",-1,-1,"s");
  TH1D* h1D1 = (TH1D*)h2D1->ProjectionY("h1D1",13,15,"e");
/*
  TH1D* hdz = (TH1D*)GetHist("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/outputs_312/HIData_Minbias_2760GeV/merged/HIData_Minbias_2760GeV_PPRereco_INCLMULT_nmin-1_nmax-1_etatrg-2.4-2.4_etaass-2.4-2.4_centmin-1_centmax-1.root","xyzvtxsepmin");
  TH3D* h = (TH3D*)GetHist("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/outputs_312/HIData_Minbias_2760GeV/merged/HIData_Minbias_2760GeV_PPRereco_INCLMULT_nmin-1_nmax-1_etatrg-2.4-2.4_etaass-2.4-2.4_centmin-1_centmax-1.root","multmaxvssecvszvtxsep");
  TH2D* h2 = (TH2D*)GetHist("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/outputs_312/HIData_Minbias_2760GeV/merged/HIData_Minbias_2760GeV_PPRereco_INCLMULT_nmin-1_nmax-1_etatrg-2.4-2.4_etaass-2.4-2.4_centmin-1_centmax-1.root","multmaxvssec");
  TH2D* hNvtxVsMult = (TH2D*)GetHist("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/outputs_312/HIData_Minbias_2760GeV/merged/HIData_Minbias_2760GeV_PPRereco_INCLMULT_nmin-1_nmax-1_etatrg-2.4-2.4_etaass-2.4-2.4_centmin-1_centmax-1.root","nvtxvsnmult");
*/

  TH1D* hdz = (TH1D*)GetHist("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/outputs_312/HydjetReco_Minbias_2760GeV/merged/HydjetReco_Minbias_2760GeV_PeripheralNew_INCLMULT_nmin-1_nmax-1_etatrg-2.4-2.4_etaass-2.4-2.4_centmin-1_centmax-1.root","xyzvtxsepmin");
  TH3D* h = (TH3D*)GetHist("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/outputs_312/HydjetReco_Minbias_2760GeV/merged/HydjetReco_Minbias_2760GeV_PeripheralNew_INCLMULT_nmin-1_nmax-1_etatrg-2.4-2.4_etaass-2.4-2.4_centmin-1_centmax-1.root","multmaxvssecvszvtxsep");
  TH2D* h2 = (TH2D*)GetHist("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/outputs_312/HydjetReco_Minbias_2760GeV/merged/HydjetReco_Minbias_2760GeV_PeripheralNew_INCLMULT_nmin-1_nmax-1_etatrg-2.4-2.4_etaass-2.4-2.4_centmin-1_centmax-1.root","multmaxvssec");
  TH2D* hNvtxVsMult = (TH2D*)GetHist("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/outputs_312/HydjetReco_Minbias_2760GeV/merged/HydjetReco_Minbias_2760GeV_PeripheralNew_INCLMULT_nmin-1_nmax-1_etatrg-2.4-2.4_etaass-2.4-2.4_centmin-1_centmax-1.root","nvtxvsnmult");

/*
  TH1D* hdz = (TH1D*)GetHist("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/outputs_312/HijingReco_Minbias_2760GeV/merged/HijingReco_Minbias_2760GeV_53x_INCLMULT_nmin-1_nmax-1_etatrg-2.4-2.4_etaass-2.4-2.4_centmin-1_centmax-1.root","xyzvtxsepmin");
  TH3D* h = (TH3D*)GetHist("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/outputs_312/HijingReco_Minbias_2760GeV/merged/HijingReco_Minbias_2760GeV_53x_INCLMULT_nmin-1_nmax-1_etatrg-2.4-2.4_etaass-2.4-2.4_centmin-1_centmax-1.root","multmaxvssecvszvtxsep");
  TH2D* hNvtxVsMult = (TH2D*)GetHist("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/outputs_312/HijingReco_Minbias_2760GeV/merged/HijingReco_Minbias_2760GeV_53x_INCLMULT_nmin-1_nmax-1_etatrg-2.4-2.4_etaass-2.4-2.4_centmin-1_centmax-1.root","nvtxvsnmult");
*/
/*
  TH1D* hdz = (TH1D*)GetHist("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/outputs_312/PAData_Minbias_5TeV/merged/PAData_Minbias_5TeV_MBNEW_INCLMULT_nmin-1_nmax-1_etatrg-2.4-2.4_etaass-2.4-2.4_centmin-1_centmax-1.root","xyzvtxsepmin");
  TH3D* h = (TH3D*)GetHist("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/outputs_312/PAData_Minbias_5TeV/merged/PAData_Minbias_5TeV_MBNEW_INCLMULT_nmin-1_nmax-1_etatrg-2.4-2.4_etaass-2.4-2.4_centmin-1_centmax-1.root","multmaxvssecvszvtxsep"); 
  TH2D* h2 = (TH2D*)GetHist("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/outputs_312/PAData_Minbias_5TeV/merged/PAData_Minbias_5TeV_MBNEW_INCLMULT_nmin-1_nmax-1_etatrg-2.4-2.4_etaass-2.4-2.4_centmin-1_centmax-1.root","multmaxvssec");
  TH2D* hNvtxVsMult = (TH2D*)GetHist("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/outputs_312/PAData_Minbias_5TeV/merged/PAData_Minbias_5TeV_MBNEW_INCLMULT_nmin-1_nmax-1_etatrg-2.4-2.4_etaass-2.4-2.4_centmin-1_centmax-1.root","nvtxvsnmult");
*/
/*
  TH1D* hdz = (TH1D*)GetHist("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/outputs_312/PAData_Minbias_5TeV/merged/PAData_Minbias_5TeV_HM_PromptSkim_INCLMULT220_nmin-1_nmax-1_etatrg-2.4-2.4_etaass-2.4-2.4_centmin-1_centmax-1.root","xyzvtxsepmin");
  TH3D* h = (TH3D*)GetHist("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/outputs_312/PAData_Minbias_5TeV/merged/PAData_Minbias_5TeV_HM_PromptSkim_INCLMULT220_nmin-1_nmax-1_etatrg-2.4-2.4_etaass-2.4-2.4_centmin-1_centmax-1.root","multmaxvssecvszvtxsep"); 
  TH2D* h2 = (TH2D*)GetHist("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/outputs_312/PAData_Minbias_5TeV/merged/PAData_Minbias_5TeV_HM_PromptSkim_INCLMULT220_nmin-1_nmax-1_etatrg-2.4-2.4_etaass-2.4-2.4_centmin-1_centmax-1.root","multmaxvssec"); 
  TH2D* hNvtxVsMult = (TH2D*)GetHist("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/outputs_312/PAData_Minbias_5TeV/merged/PAData_Minbias_5TeV_HM_PromptSkim_INCLMULT220_nmin-1_nmax-1_etatrg-2.4-2.4_etaass-2.4-2.4_centmin-1_centmax-1.root","nvtxvsnmult");
*/
/*
  TH1D* hdz = (TH1D*)GetHist("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/outputs_312/PAData_Minbias_5TeV/merged/PAData_Minbias_5TeV_HM_PromptRecoNew_INCLMULT220PURej2sigmaMode1_nmin-1_nmax-1_etatrg-2.4-2.4_etaass-2.4-2.4_centmin-1_centmax-1.root","xyzvtxsepmin");
  TH3D* h = (TH3D*)GetHist("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/outputs_312/PAData_Minbias_5TeV/merged/PAData_Minbias_5TeV_HM_PromptRecoNew_INCLMULT220PURej2sigmaMode1_nmin-1_nmax-1_etatrg-2.4-2.4_etaass-2.4-2.4_centmin-1_centmax-1.root","multmaxvssecvszvtxsep"); 
  TH2D* h2 = (TH2D*)GetHist("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/outputs_312/PAData_Minbias_5TeV/merged/PAData_Minbias_5TeV_HM_PromptRecoNew_INCLMULT220PURej2sigmaMode1_nmin-1_nmax-1_etatrg-2.4-2.4_etaass-2.4-2.4_centmin-1_centmax-1.root","multmaxvssec"); 
  TH2D* hNvtxVsMult = (TH2D*)GetHist("/net/hisrv0001/home/davidlw/scratch1/DiHadronCorrelations/outputs_312/PAData_Minbias_5TeV/merged/PAData_Minbias_5TeV_HM_PromptRecoNew_INCLMULT220PURej2sigmaMode1_nmin-1_nmax-1_etatrg-2.4-2.4_etaass-2.4-2.4_centmin-1_centmax-1.root","nvtxvsnmult");
*/
  TH1D* htrk_max = h->ProjectionX();
  h->GetZaxis()->SetRange(h->GetZaxis()->FindBin(dzmin),h->GetZaxis()->FindBin(dzmax));
  h->GetYaxis()->SetRange(h->GetYaxis()->FindBin(2),h->GetYaxis()->FindBin(241));
//  h->Rebin3D(10,1);
  TH2D* h2D = (TH2D*)h->Project3DProfile("yx");
  h2D->Rebin2D(5,1);
  TProfile* hprof_x = (TProfile*)h2D->ProfileX("hprof_x",-1,-1,"s");
//  TH1D* h1D = (TH1D*)h2D->ProjectionY("h1D",h2D->GetXaxis()->FindBin(200),h2D->GetXaxis()->FindBin(220),"e");
  TH1D* h1D = (TH1D*)h2->ProjectionY("h1D",h2->GetXaxis()->FindBin(200),h2->GetXaxis()->FindBin(220),"e");
   
  double xx[1000];
  double yy[1000];
  for(int i=1;i<=hprof_x->GetNbinsX();i++)
  {
    yy[i-1] = hprof_x->GetBinContent(i)+2*hprof_x->GetBinError(i);
    xx[i-1] = hprof_x->GetBinCenter(i);
  }

  TGraph* xx_yy = new TGraph(hprof_x->GetNbinsX(),xx,yy);

  int ibin = hprof_x->GetXaxis()->FindBin(200);
/*
  TF1* func = new TF1("func","[0]+[1]*x",0,500);
  double par1 = (hprof_x->GetBinContent(ibin)+hprof_x->GetBinError(ibin)-hprof_x->GetBinContent(1)-hprof_x->GetBinError(1))/(hprof_x->GetBinCenter(ibin)-hprof_x->GetBinCenter(1));
  double par0 = hprof_x->GetBinContent(ibin)+hprof_x->GetBinError(ibin)-par1*hprof_x->GetBinCenter(ibin);
  func->SetParameters(par0,par1);
*/
//  TF1* func = new TF1("func","[0]+[1]*(x-[2])*(x-[2])",0,500);
//  func->SetParameters(30,-0.1,150);
  TF1* func = new TF1("func","[0]*x**[1]",0,500);
  func->SetParameters(0.1,0.5);
  func->SetParLimits(0,0,10000);
  func->SetParLimits(1,0,10000);
//  func->FixParameter(0,5); small dz
  func->FixParameter(0,2);
  xx_yy->Fit("func","NO","",10,400);

  TCanvas* cc6 = new TCanvas("cc6","cc6",550,500);
  TH2D* htmp = new TH2D("htmp",";N_{trk}^{primary};N_{trk}^{secondary}",500,0,500,50,0,50);
  htmp->Draw("");
  xx_yy->Draw("Psame");
  func->SetLineColor(2);
  func->Draw("Lsame");
  TLatex* latex = new TLatex();
  latex->SetNDC();
  latex->SetTextSize(latex->GetTextSize()*0.75);
  latex->DrawLatex(0.23,0.87,"PbPb HYDJET, 1<|dz|<2 cm");
//  SaveCanvas(cc6,"pPb/corr","NpriVsNsecProfile_2Sigma_hydjet_dz1020_ForAN");

  TCanvas* cc4 = new TCanvas("cc4","cc4",550,500);
  cc4->SetLogz();
  hNvtxVsMult->Rebin2D(10,1);
//  hNvtxVsMult->Scale(1.0/hNvtxVsMult->GetBinContent(0,0));
  hNvtxVsMult->SetAxisRange(1,5.9,"Y");
  hNvtxVsMult->SetAxisRange(0,280,"X");
  hNvtxVsMult->SetTitle(";N_{trk}^{offline};# of vertices");
  TProfile* hNvtxVsMult_prof = (TProfile*)hNvtxVsMult->ProfileX("hNvtxVsMult_prof",-1,-1,"s");
  hNvtxVsMult->Draw("colz");
//  hNvtxVsMult_prof->Draw("PEsame");
//  SaveCanvas(cc4,"pPb/corr","NvtxVsMult_PbPb2011_ForAN");

  TCanvas* cc5 = new TCanvas("cc5","cc5",550,500);
  TH1D* hNvtxVsMult_1D = hNvtxVsMult->ProjectionY("hNvtxVsMult_1D",23,23,"e");
  hNvtxVsMult_1D->Draw("PE");

//  TCanvas* cc3 = new TCanvas("cc3","cc3",550,500);
//  htrk_max->SetAxisRange(-1.5,1.5,"X");
//  htrk_max->Draw("PE");

  TCanvas* cc1 = new TCanvas("cc1","cc1",550,500);
  hdz->SetAxisRange(-1.5,1.5,"X");
  hdz->Draw("PE");
//  SaveCanvas(cc1,"pPb/corr","dz_pPbPURej3");

  TCanvas* c = new TCanvas("c","",580,500);
  c->SetLogz();
  c->SetRightMargin(0.14);

  h2D->SetTitle(";N_{trk}^{primary};N_{trk}^{secondary}");
  h2D->GetXaxis()->CenterTitle();
  h2D->GetYaxis()->CenterTitle();
  h2D->Draw("colz");
/*
  h2->SetAxisRange(2,241,"Y");
  h2->SetTitle(";N_{trk}^{primary};N_{trk}^{secondary}");
  h2->GetXaxis()->CenterTitle();
  h2->GetYaxis()->CenterTitle();
  h2->Draw("colz");
*/
  //hprof_x->Draw("PESAME");
//  func->Draw("Lsame");
  TLatex* latex = new TLatex();
  latex->SetNDC();
  latex->SetTextSize(latex->GetTextSize()*0.75);
//  latex->DrawLatex(0.23,0.87,"PbPb data 2011");
//  latex->DrawLatex(0.23,0.87,"PbPb HYDJET, 1<|dz|<2 cm");
  latex->DrawLatex(0.23,0.87,"HLT_PAPixelTracks_Multiplicity220");
  latex->DrawLatex(0.23,0.8,"1<|dz|<2 cm, pileup rejected");
//  latex->DrawLatex(0.23,0.87,"pPb pilot");
//  SaveCanvas(c,"pPb/corr","NpriVsNsec_NoPURej_pPbTrigger220_ForAN");
//  SaveCanvas(c,"pPb/corr","NpriVsNsec_NoPURej_PbPb2011_ForAN");
//  SaveCanvas(c,"pPb/corr","NpriVsNsec_NoPURej_hydjet_ForAN_dz1020");
//  SaveCanvas(c,"pPb/corr","NpriVsNsec_PURej_pPbTrigger220_dz1020_ForAN");

  TCanvas* cc = new TCanvas("cc","",550,500);
  cc->SetLogy();
  h1D->SetTitle("");
  h1D->SetXTitle("N_{trk}^{secondary}");
  h1D->GetXaxis()->CenterTitle();
  h1D->Scale(1.0/h1D->Integral());
  htrk_max1->Scale(1.0/htrk_max1->Integral());
  htrk_max1->SetMarkerStyle(24);
  h1D->SetAxisRange(0,50,"X");
  h1D->Draw("PE");
  htrk_max1->Draw("PESAME");
  TLine* l_2sigma = new TLine(h1D->GetMean()+h1D->GetRMS()*2,0,h1D->GetMean()+h1D->GetRMS()*2,0.04);
  l_2sigma->SetLineWidth(3);
  l_2sigma->SetLineColor(2);
  l_2sigma->Draw("Lsame");
  TLatex* latex = new TLatex();
  latex->SetTextColor(2);
  latex->SetTextSize(latex->GetTextSize()*0.75);
  latex->DrawLatex(h1D->GetMean()+h1D->GetRMS()*2*0.7,0.053,"Mean+2#timesRMS");

  TLine* l_1sigma = new TLine(h1D->GetMean()+h1D->GetRMS()*1,0,h1D->GetMean()+h1D->GetRMS()*1,0.1);
  l_1sigma->SetLineWidth(3);
  l_1sigma->SetLineStyle(9);
  l_1sigma->SetLineColor(4);
  l_1sigma->Draw("Lsame");
  TLatex* latex = new TLatex();
  latex->SetTextColor(4);
  latex->SetTextSize(latex->GetTextSize()*0.75);
  latex->DrawLatex(h1D->GetMean()+h1D->GetRMS()*0.4,0.123,"Mean+1#timesRMS");

  TLatex* latex = new TLatex();
  latex->SetTextColor(1);
  latex->SetNDC();
  latex->SetTextSize(latex->GetTextSize()*0.75);
  latex->DrawLatex(0.65,0.85,"200<N_{trk}^{primary}<220");
  SaveCanvas(cc,"pPb/corr","NsecDist_PUestimate");

  TLegend* legend = new TLegend(0.4,0.58,0.9,0.68);
  legend->SetFillColor(0);
  legend->SetFillStyle(0);
  legend->AddEntry(h1D,"N_{trk}^{secondary} from PbPb Hydjet","P");
  legend->AddEntry(htrk_max1,"N_{trk}^{primary} from pPb pilot","P");
  legend->Draw();

  TH1D* hhh = new TH1D("hhh",";N_{trk}^{primary};Residual pileup (%)",25,0,500);
  for(int i=1;i<=hhh->GetNbinsX();i++)
  {
    TH1D* h1Dtmp = (TH1D*)h2->ProjectionY("h1Dtmp",h2->GetXaxis()->FindBin((i-1)*20),h2->GetXaxis()->FindBin(i*20),"e");
    double frac = htrk_max1->Integral(1,htrk_max1->FindBin(h1Dtmp->GetMean()+h1Dtmp->GetRMS()*2))*3.0;
    hhh->SetBinContent(i,frac);
  }
  TCanvas* cc4 = new TCanvas("cc4","",550,500);
  hhh->GetXaxis()->CenterTitle();
  hhh->GetYaxis()->CenterTitle();
  hhh->GetYaxis()->SetTitleOffset(hhh->GetYaxis()->GetTitleOffset()*1.3);
  hhh->Draw("hist");
  TLatex* latex = new TLatex();
  latex->SetTextColor(1);
  latex->SetNDC();
  latex->SetTextSize(latex->GetTextSize()*0.75);
  latex->DrawLatex(0.25,0.85,"Mean+2#timesRMS cut");
  SaveCanvas(cc4,"pPb/corr","ResidualPUvsNtrkpri");
}
コード例 #14
0
void GetYield()
{
	Int_t xmin, xmax, ymin, ymax, zmin, zmax;
	Double_t count;
	Char_t name[64];


	TH3D *h = (TH3D*)full.Get( "THits_TGG_ThetaCM_P");
	xmin = h->GetXaxis()->FindBin( 0);
	xmax = h->GetXaxis()->FindBin( 180);
	ymin = h->GetYaxis()->FindBin( 0);
	ymax = h->GetYaxis()->FindBin( 180);
	zmin = h->GetZaxis()->FindBin( 0);
	zmax = h->GetZaxis()->FindBin( 352);
	count = h->Integral(xmin, xmax, ymin, ymax, zmin, zmax);
	cout << count << endl;

	count = 0;
	TH3D *h1 = (TH3D*)full.Get( "THits_TGG_Phi_1perp_P");
	xmin = h1->GetXaxis()->FindBin( -180);
	xmax = h1->GetXaxis()->FindBin( 180);
	ymin = h1->GetYaxis()->FindBin( 0);
	ymax = h1->GetYaxis()->FindBin( 180);
	zmin = h1->GetZaxis()->FindBin( 0);
	zmax = h1->GetZaxis()->FindBin( 352);
	count += h1->Integral(xmin, xmax, ymin, ymax, zmin, zmax);
	cout << count << endl;
	TH3D *h2 = (TH3D*)full.Get( "THits_TGG_Phi_2perp_P");
	count += h2->Integral(xmin, xmax, ymin, ymax, zmin, zmax);
	cout << count << endl;
	TH3D *h3 = (TH3D*)full.Get( "THits_TGG_Phi_3perp_P");
	count += h3->Integral(xmin, xmax, ymin, ymax, zmin, zmax);
	cout << count << endl;
	TH3D *h4 = (TH3D*)full.Get( "THits_TGG_Phi_4perp_P");
	count += h4->Integral(xmin, xmax, ymin, ymax, zmin, zmax);
	cout << count << endl;
	TH3D *h5 = (TH3D*)full.Get( "THits_TGG_Phi_5perp_P");
	count += h5->Integral(xmin, xmax, ymin, ymax, zmin, zmax);
	cout << count << endl;
	TH3D *h6 = (TH3D*)full.Get( "THits_TGG_Phi_6perp_P");
	count += h6->Integral(xmin, xmax, ymin, ymax, zmin, zmax);
	cout << count << endl;
	TH3D *h7 = (TH3D*)full.Get( "THits_TGG_Phi_7perp_P");
	count += h7->Integral(xmin, xmax, ymin, ymax, zmin, zmax);
	cout << count << endl;
	TH3D *h8 = (TH3D*)full.Get( "THits_TGG_Phi_8perp_P");
	count += h8->Integral(xmin, xmax, ymin, ymax, zmin, zmax);
	cout << count << endl;
	TH3D *h9 = (TH3D*)full.Get( "THits_TGG_Phi_9perp_P");
	count += h9->Integral(xmin, xmax, ymin, ymax, zmin, zmax);
	cout << count << endl;

	TH3D *h1 = (TH3D*)full.Get( "THits_TGG_Phi_1para_P");
	count += h1->Integral(xmin, xmax, ymin, ymax, zmin, zmax);
	cout << count << endl;
	TH3D *h2 = (TH3D*)full.Get( "THits_TGG_Phi_2para_P");
	count += h2->Integral(xmin, xmax, ymin, ymax, zmin, zmax);
	cout << count << endl;
	TH3D *h3 = (TH3D*)full.Get( "THits_TGG_Phi_3para_P");
	count += h3->Integral(xmin, xmax, ymin, ymax, zmin, zmax);
	cout << count << endl;
	TH3D *h4 = (TH3D*)full.Get( "THits_TGG_Phi_4para_P");
	count += h4->Integral(xmin, xmax, ymin, ymax, zmin, zmax);
	cout << count << endl;
	TH3D *h5 = (TH3D*)full.Get( "THits_TGG_Phi_5para_P");
	count += h5->Integral(xmin, xmax, ymin, ymax, zmin, zmax);
	cout << count << endl;
	TH3D *h6 = (TH3D*)full.Get( "THits_TGG_Phi_6para_P");
	count += h6->Integral(xmin, xmax, ymin, ymax, zmin, zmax);
	cout << count << endl;
	TH3D *h7 = (TH3D*)full.Get( "THits_TGG_Phi_7para_P");
	count += h7->Integral(xmin, xmax, ymin, ymax, zmin, zmax);
	cout << count << endl;
	TH3D *h8 = (TH3D*)full.Get( "THits_TGG_Phi_8para_P");
	count += h8->Integral(xmin, xmax, ymin, ymax, zmin, zmax);
	cout << count << endl;
	TH3D *h9 = (TH3D*)full.Get( "THits_TGG_Phi_9para_P");
	count += h9->Integral(xmin, xmax, ymin, ymax, zmin, zmax);
	cout << count << endl;

}
コード例 #15
0
ファイル: stopBabyLooper.C プロジェクト: haweber/StopAnalysis
//
// Functions
//
int looper( sampleInfo::ID sampleID, std::vector<analyzer*> analyzers, int nEvents, bool readFast ) {


  //
  // Intro
  //
  cout << "====================================================" << endl;
  cout << endl;
  cout << "  WELCOME TO STOP BABY ANALYZER! " << endl;
  cout << endl;
  cout << "====================================================" << endl;
  cout << endl;


  //
  // Benchmark
  //
  TBenchmark *bmark = new TBenchmark();
  bmark->Start("benchmark");
  

  //
  // Input SampleInfo
  //
  sampleInfo::sampleUtil sample( sampleID );

  bool sampleIsTTbar = false;
  if( sample.id == sampleInfo::k_ttbar_powheg_pythia8 ||
      sample.id == sampleInfo::k_ttbar_powheg_pythia8_ext4 ||
      sample.id == sampleInfo::k_ttbar_singleLeptFromT_madgraph_pythia8 ||
      sample.id == sampleInfo::k_ttbar_singleLeptFromT_madgraph_pythia8_ext1 ||
      sample.id == sampleInfo::k_ttbar_singleLeptFromTbar_madgraph_pythia8 ||
      sample.id == sampleInfo::k_ttbar_singleLeptFromTbar_madgraph_pythia8_ext1 ||
      sample.id == sampleInfo::k_ttbar_diLept_madgraph_pythia8 ||
      sample.id == sampleInfo::k_ttbar_diLept_madgraph_pythia8_ext1 ) {
    sampleIsTTbar = true;
  }
  
  //
  // Input chain
  //
  TChain *chain = new TChain("t");
  
  cout << "    Processing the following: " << endl;  
  for(int iFile=0; iFile<(int)sample.inputBabies.size(); iFile++) {
    
    // input directory
    string input = sample.baby_i_o.first;
      
    // input file
    input += sample.inputBabies[iFile];
      
    chain->Add( input.c_str() );
    cout << "      " << input << endl; 
  }
  cout << endl;
  
  
  //
  // Output File
  //

  // output dir
  string f_output_name = "";
  f_output_name += sample.baby_i_o.second;

  // output name
  f_output_name += sample.label;
  f_output_name += ".root";

  // output file
  TFile *f_output = new TFile( f_output_name.c_str(), "recreate" );

  // print output location
  cout << "    Output Written to: " << endl;
  cout << "      " << f_output_name << endl;
  cout << endl;


  //
  // JSON File Tools
  //
  const char* json_file = "../StopCORE/inputs/json_files/Cert_271036-284044_13TeV_23Sep2016ReReco_Collisions16_JSON.txt"; // 35.876fb final 2016 run
  if( sample.isData ) set_goodrun_file_json(json_file);
  

  //
  // Event Weight Utilities
  //
  cout << "    Loading eventWeight Utilities..." << endl << endl;
  wgtInfo.setUp( sample.id, useBTagSFs_fromFiles_, useLepSFs_fromFiles_, add2ndLepToMet_ );  
  wgtInfo.apply_cr2lTrigger_sf  = (apply_cr2lTrigger_sf_ && add2ndLepToMet_);
  wgtInfo.apply_bTag_sf         = apply_bTag_sf_;
  wgtInfo.apply_lep_sf          = apply_lep_sf_;
  wgtInfo.apply_vetoLep_sf      = apply_vetoLep_sf_;
  wgtInfo.apply_tau_sf          = apply_tau_sf_;
  wgtInfo.apply_lepFS_sf        = apply_lepFS_sf_;
  wgtInfo.apply_topPt_sf        = apply_topPt_sf_;
  wgtInfo.apply_metRes_sf       = apply_metRes_sf_;
  wgtInfo.apply_metTTbar_sf     = apply_metTTbar_sf_;
  wgtInfo.apply_ttbarSysPt_sf   = apply_ttbarSysPt_sf_;
  wgtInfo.apply_ISR_sf          = apply_ISR_sf_;
  wgtInfo.apply_pu_sf           = apply_pu_sf_;
  wgtInfo.apply_sample_sf       = apply_sample_sf_;


  //
  // Declare genClassification list
  //
  cout << "    Loading genClassyList: ";
  std::vector< genClassyInfo::Util > genClassyList;
  if( sample.isData ) {
    genClassyList.push_back(genClassyInfo::Util(genClassyInfo::k_incl));
  }
  else{
    for(int iGenClassy=0; iGenClassy<genClassyInfo::k_nGenClassy; iGenClassy++) {
      genClassyList.push_back( genClassyInfo::Util(genClassyInfo::ID(iGenClassy)) );
    }
  }
  const int nGenClassy=(int)genClassyList.size();
  cout << nGenClassy << " genClassifications" << endl << endl;

  
  //
  // Declare Systematics
  //
  cout << "    Loading systematicList: ";
  std::vector< sysInfo::Util > systematicList;
  if( sample.isData || analyzeFast_ ) {
    systematicList.push_back(sysInfo::Util(sysInfo::k_nominal));
  }
  else{
    for(int iSys=0; iSys<sysInfo::k_nSys; iSys++) {
      systematicList.push_back( sysInfo::Util(sysInfo::ID(iSys)) );
    }
  }  
  const int nSystematics = (int)systematicList.size();
  cout << nSystematics << " systematics" << endl << endl;


	// Count number of analyzers in the list
	const int nAnalyzers = analyzers.size();



  ////////////////////////
  //                    //
  // Declare Histograms //
  //                    //
  ////////////////////////
  //
  //
  //  For Using DownStream Scripts, please adhere to the conventions:
  //
  //
  //    histogram_name = "your_name_here"+"__"+regionList[i]+"__genClassy_"+genClassyObject.label+"__systematic_"+sysInfoObject.label;
  //
  //
  //  Where regionList is the list of "SR", "CR0b", "CR0b_tightBTagHighMlb" or "CR2l"
  //
  //    And systematicList[0] is the nominal selection
  //
  //    And if there is andditional selection involved in this histogram, please refer to it in "you name here"
  //

  cout << "    Preparing histograms" << endl << endl;


	//
	// Declare yield histograms
	//
  f_output->cd(); // All yield histos will belong to the output file
	for( analyzer* thisAnalyzer : analyzers ) {

		TH1D* h_template = thisAnalyzer->GetYieldTemplate();
		TH3D* h_template_signal = thisAnalyzer->GetYieldTemplateSignal();

		for( int iClassy=0; iClassy<nGenClassy; iClassy++ ) {
			for( int iSys=0; iSys<nSystematics; iSys++ ) {

				int histIndex = iClassy*nSystematics + iSys;

				// Gen and Systematic String
				TString reg_gen_sys_name = "__";
				reg_gen_sys_name += thisAnalyzer->GetLabel();
				reg_gen_sys_name += "__genClassy_";
				reg_gen_sys_name += genClassyList[iClassy].label;
				reg_gen_sys_name += "__systematic_";
				reg_gen_sys_name += systematicList[iSys].label;

				TH1* h_tmp = 0;

				TString yieldname = "h_yields";
				yieldname += reg_gen_sys_name;
				if( sample.isSignalScan ) h_tmp = (TH3D*)h_template_signal->Clone( yieldname );
				else                      h_tmp = (TH1D*)h_template->Clone( yieldname );
				thisAnalyzer->SetYieldHistogram( histIndex, h_tmp );

			} // End loop over systematics
		} // End loop over genClassys
	} // End loop over analyzers

  
  
  

  //
  // Declare non-yield histograms
  //

  int nMassPts = 1;
  if( sample.isSignalScan ) nMassPts = (int)sample.massPtList.size();

  const int nHistosVars = nAnalyzers*nGenClassy*nMassPts;

  // nJets
  TH1D *h_nJets[nHistosVars];
  
  // nBTags
  TH1D *h_nBTags[nHistosVars];
  
  // lep1 pT
  TH1D *h_lep1Pt_incl[nHistosVars];
  
  // lep2 pT
  TH1D *h_lep2Pt_incl[nHistosVars];
  
  // jet pT
  TH1D *h_jetPt_incl[nHistosVars];
  
  // jet1 pT
  TH1D *h_jet1Pt_incl[nHistosVars];
  
  // jet2 pT
  TH1D *h_jet2Pt_incl[nHistosVars];
  
  // DeepCSV jet1 pT
  TH1D *h_deepcsvJet1Pt_incl[nHistosVars];
  
  // DeepCSV jet2 pT
  TH1D *h_deepcsvJet2Pt_incl[nHistosVars];
  
  // met
  TH1D *h_met_incl[nHistosVars];
  TH1D *h_met_lt4j[nHistosVars];
  TH1D *h_met_ge4j[nHistosVars];

  // lep1lep2bbMetPt
  TH1D *h_lep1lep2bbMetPt_incl[nHistosVars];
  TH1D *h_lep1lep2bbMetPt_lt4j[nHistosVars];
  TH1D *h_lep1lep2bbMetPt_ge4j[nHistosVars];

  // mt
  TH1D *h_mt_incl[nHistosVars];
  
  // modTopness
  TH1D *h_modTopness_incl[nHistosVars];
  TH1D *h_modTopness_lt4j[nHistosVars];
  TH1D *h_modTopness_ge4j[nHistosVars];

  // mlb
  TH1D *h_mlb_incl[nHistosVars];
  TH1D *h_mlb_lt4j[nHistosVars];
  TH1D *h_mlb_ge4j[nHistosVars];

  // mlb
  TH1D *h_mlb_lt0modTopness[nHistosVars];
  TH1D *h_mlb_ge0modTopness[nHistosVars];
  TH1D *h_mlb_ge10modTopness[nHistosVars];
  
  // mlb, met sideband CR
  TH1D *h_mlb_150to250met_incl[nHistosVars];
  TH1D *h_mlb_150to250met_lt4j[nHistosVars];
  TH1D *h_mlb_150to250met_ge4j[nHistosVars];

  // ml2b
  TH1D *h_mlb_lep2_incl[nHistosVars];
  TH1D *h_mlb_lep2_lt4j[nHistosVars];
  TH1D *h_mlb_lep2_ge4j[nHistosVars];
  
  // ml2b
  TH1D *h_mlb_lep2_150to250met_incl[nHistosVars];
  TH1D *h_mlb_lep2_150to250met_lt4j[nHistosVars];
  TH1D *h_mlb_lep2_150to250met_ge4j[nHistosVars];

  // Gen ttbar system pT
  TH1D *h_gen_ttbarPt_incl[nHistosVars];
  TH1D *h_gen_ttbarPt_lt4j[nHistosVars];
  TH1D *h_gen_ttbarPt_ge4j[nHistosVars];

  // Gen 2nd lepton ID
  TH1D *h_gen_lep2_id_incl[nHistosVars];
  TH1D *h_gen_lep2_id_lt4j[nHistosVars];
  TH1D *h_gen_lep2_id_ge4j[nHistosVars];

  f_output->cd(); // All non-yield histos will belong to the output file
  
  for(int iReg=0; iReg<nAnalyzers; iReg++) {
    for(int iGen=0; iGen<nGenClassy; iGen++) {
      for(int iMassPt=0; iMassPt<nMassPts; iMassPt++) {

				// Histo Index
				int iHisto = iReg*nGenClassy*nMassPts + iGen*nMassPts + iMassPt;

				int mStop = 0;
				int mLSP  = 0;
				if(sample.isSignalScan) {
					mStop = sample.massPtList[iMassPt].first;
					mLSP  = sample.massPtList[iMassPt].second;
				}

				TString hName = "";
	
				TString reg_gen_sys_name = "__";
				reg_gen_sys_name += analyzers.at(iReg)->GetLabel();
				reg_gen_sys_name += "__genClassy_";
				reg_gen_sys_name += genClassyList[iGen].label;
				reg_gen_sys_name += "__systematic_";
				reg_gen_sys_name += systematicList[0].label;
				if( sample.isSignalScan ) {
					reg_gen_sys_name += "__mStop_";
					reg_gen_sys_name += mStop;
					reg_gen_sys_name += "__mLSP_";
					reg_gen_sys_name += mLSP;
				}

      
				//
				// Njets
				//
				hName = "h_nJets" + reg_gen_sys_name;
				h_nJets[iHisto] = new TH1D( hName, "Number of Selected Jets;nJets", 11, -0.5, 10.5);

				//
				// nBTags
				//
				hName = "h_nBTags" + reg_gen_sys_name;
				h_nBTags[iHisto] = new TH1D( hName, "Number of b-Tagged Jets;nBTags", 5, -0.5, 4.5);


				//
				// lep1Pt
				//

				// Incl Selection
				hName = "h_lep1Pt__inclSelection" + reg_gen_sys_name;
				h_lep1Pt_incl[iHisto] = new TH1D( hName, "Lepton p_{T};p_{T} [GeV]", 20.0, 0.0, 200.0 );
      
	

				//
				// lep2Pt
				//

				// Incl Selection
				hName = "h_lep2Pt__inclSelection" + reg_gen_sys_name;
				h_lep2Pt_incl[iHisto] = new TH1D( hName, "Trailing Lepton p_{T};p_{T} [GeV]", 20.0, 0.0, 200.0 );
      
				//
				// jetPt
				//

				// Incl Selection
				hName = "h_jetPt__inclSelection" + reg_gen_sys_name;
				h_jetPt_incl[iHisto] = new TH1D( hName, "Jet p_{T};p_{T} [GeV]", 24, 0.0, 600.0 );
	
				//
				// jet1Pt
				//

				// Incl Selection
				hName = "h_jet1Pt__inclSelection" + reg_gen_sys_name;
				h_jet1Pt_incl[iHisto] = new TH1D( hName, "Leading Jet p_{T};p_{T} [GeV]", 24, 0.0, 600.0 );
	
	

				//
				// jet2Pt
				//

				// Incl Selection
				hName = "h_jet2Pt__inclSelection" + reg_gen_sys_name;
				h_jet2Pt_incl[iHisto] = new TH1D( hName, "2nd Leading Jet p_{T};p_{T} [GeV]", 24, 0.0, 600.0 );
      
	
				//
				// DeepCSVJet1Pt
				//

				// Incl Selection
				hName = "h_deepcsvJet1Pt__inclSelection" + reg_gen_sys_name;
				h_deepcsvJet1Pt_incl[iHisto] = new TH1D( hName, "Leading DeepCSV Jet p_{T};p_{T} [GeV]", 24, 0.0, 600.0 );
      
	

				//
				// DeepCSVJet2Pt
				//

				// Incl Selection
				hName = "h_deepcsvJet2Pt__inclSelection" + reg_gen_sys_name;
				h_deepcsvJet2Pt_incl[iHisto] = new TH1D( hName, "2nd Leading DeepCSV Jet p_{T};p_{T} [GeV]", 24, 0.0, 600.0 );
      
	

				//
				// met
				//

				// Incl Selection
				hName = "h_met__inclSelection" + reg_gen_sys_name;
				h_met_incl[iHisto] = new TH1D( hName, "MET;MET [GeV]", 32, 0.0, 800.0 );
      
				// <4j Selection
				hName = "h_met__lt4jSelection" + reg_gen_sys_name;
				h_met_lt4j[iHisto] = new TH1D( hName, "MET;MET [GeV]", 32, 0.0, 800.0 );

				// >=4j Selection
				hName = "h_met__ge4jSelection" + reg_gen_sys_name;
				h_met_ge4j[iHisto] = new TH1D( hName, "MET;MET [GeV]", 32, 0.0, 800.0 );


	

				//
				// lep1lep2bbMetPt
				//

				// Incl Selection
				hName = "h_lep1lep2bbMetPt__inclSelection" + reg_gen_sys_name;
				h_lep1lep2bbMetPt_incl[iHisto] = new TH1D( hName, "lep1(lep2)bbMet system p_{T};p_{T} [GeV]", 24, 0.0, 600.0 );
	
				// <4j Selection
				hName = "h_lep1lep2bbMetPt__lt4jSelection" + reg_gen_sys_name;
				h_lep1lep2bbMetPt_lt4j[iHisto] = new TH1D( hName, "lep1(lep2)bbMet system p_{T};p_{T} [GeV]", 24, 0.0, 600.0 );

				// >=4j Selection
				hName = "h_lep1lep2bbMetPt__ge4jSelection" + reg_gen_sys_name;
				h_lep1lep2bbMetPt_ge4j[iHisto] = new TH1D( hName, "lep1(lep2)bbMet system p_{T};p_{T} [GeV]", 24, 0.0, 600.0 );


				//
				// mt
				//

				// Incl Selection
				hName = "h_mt__inclSelection" + reg_gen_sys_name;
				h_mt_incl[iHisto] = new TH1D( hName, "M_{T};M_{T} [GeV]", 24, 0.0, 600.0 );
      
	
				//
				// modTopness
				//

				// Incl Selection
				hName = "h_modTopness__inclSelection" + reg_gen_sys_name;
				h_modTopness_incl[iHisto] = new TH1D( hName, "Modified Topness;Modified Topness", 20, -20.0, 20.0 );
      
				// <4j Selection
				hName = "h_modTopness__lt4jSelection" + reg_gen_sys_name;
				h_modTopness_lt4j[iHisto] = new TH1D( hName, "Modified Topness;Modified Topness", 20, -20.0, 20.0 );

				// >=4j Selection
				hName = "h_modTopness__ge4jSelection" + reg_gen_sys_name;
				h_modTopness_ge4j[iHisto] = new TH1D( hName, "Modified Topness;Modified Topness", 20, -20.0, 20.0 );

      
				//
				// mlb
				//

				// Incl Selection
				hName = "h_mlb__inclSelection" + reg_gen_sys_name;
				h_mlb_incl[iHisto] = new TH1D( hName, "M_{lb};M_{lb} [GeV]", 24, 0.0, 600.0 );
      
				// <4j Selection
				hName = "h_mlb__lt4jSelection" + reg_gen_sys_name;
				h_mlb_lt4j[iHisto] = new TH1D( hName, "M_{lb};M_{lb} [GeV]", 24, 0.0, 600.0 );

				// >=4j Selection
				hName = "h_mlb__ge4jSelection" + reg_gen_sys_name;
				h_mlb_ge4j[iHisto] = new TH1D( hName, "M_{lb};M_{lb} [GeV]", 24, 0.0, 600.0 );

      

				//
				// mlb, inclusive nJets, modTopness bins
				//

				// <0 modTopness Selection
				hName = "h_mlb__lt0modTopnessSelection" + reg_gen_sys_name;
				h_mlb_lt0modTopness[iHisto] = new TH1D( hName, "M_{lb};M_{lb} [GeV]", 24, 0.0, 600.0 );

				// >=0 modTopness Selection
				hName = "h_mlb__ge0modTopnessSelection" + reg_gen_sys_name;
				h_mlb_ge0modTopness[iHisto] = new TH1D( hName, "M_{lb};M_{lb} [GeV]", 24, 0.0, 600.0 );
      
				// >=10 modTopness Selection
				hName = "h_mlb__ge10modTopnessSelection" + reg_gen_sys_name;
				h_mlb_ge10modTopness[iHisto] = new TH1D( hName, "M_{lb};M_{lb} [GeV]", 24, 0.0, 600.0 );


				//
				// mlb, met sideband CR
				//

				// Incl Selection
				hName = "h_mlb_150to250met__inclSelection" + reg_gen_sys_name;
				h_mlb_150to250met_incl[iHisto] = new TH1D( hName, "M_{lb};M_{lb} [GeV]", 24, 0.0, 600.0 );
      
				// <4j Selection
				hName = "h_mlb_150to250met__lt4jSelection" + reg_gen_sys_name;
				h_mlb_150to250met_lt4j[iHisto] = new TH1D( hName, "M_{lb};M_{lb} [GeV]", 24, 0.0, 600.0 );

				// >=4j Selection
				hName = "h_mlb_150to250met__ge4jSelection" + reg_gen_sys_name;
				h_mlb_150to250met_ge4j[iHisto] = new TH1D( hName, "M_{lb};M_{lb} [GeV]", 24, 0.0, 600.0 );


				//
				// mlb_lep2
				//

				// Incl Selection
				hName = "h_mlb_lep2__inclSelection" + reg_gen_sys_name;
				h_mlb_lep2_incl[iHisto] = new TH1D( hName, "M_{l2b};M_{l2b} [GeV]", 24, 0.0, 600.0 );
      
				// <4j Selection
				hName = "h_mlb_lep2__lt4jSelection" + reg_gen_sys_name;
				h_mlb_lep2_lt4j[iHisto] = new TH1D( hName, "M_{l2b};M_{l2b} [GeV]", 24, 0.0, 600.0 );

				// >=4j Selection
				hName = "h_mlb_lep2__ge4jSelection" + reg_gen_sys_name;
				h_mlb_lep2_ge4j[iHisto] = new TH1D( hName, "M_{l2b};M_{l2b} [GeV]", 24, 0.0, 600.0 );



				//
				// mlb_lep2, met CR sideband
				//

				// Incl Selection
				hName = "h_mlb_lep2_150to250met__inclSelection" + reg_gen_sys_name;
				h_mlb_lep2_150to250met_incl[iHisto] = new TH1D( hName, "M_{l2b};M_{l2b} [GeV]", 24, 0.0, 600.0 );
      
				// <4j Selection
				hName = "h_mlb_lep2_150to250met__lt4jSelection" + reg_gen_sys_name;
				h_mlb_lep2_150to250met_lt4j[iHisto] = new TH1D( hName, "M_{l2b};M_{l2b} [GeV]", 24, 0.0, 600.0 );

				// >=4j Selection
				hName = "h_mlb_lep2_150to250met__ge4jSelection" + reg_gen_sys_name;
				h_mlb_lep2_150to250met_ge4j[iHisto] = new TH1D( hName, "M_{l2b};M_{l2b} [GeV]", 24, 0.0, 600.0 );



	

				//
				// Gen ttbar pT
				//
				if( !sample.isData ) {
    
					// Incl Selection
					hName = "h_gen_ttbarPt__inclSelection" + reg_gen_sys_name;
					h_gen_ttbarPt_incl[iHisto] = new TH1D( hName, "Gen t#bar{t} system p_{T};p_{T} [GeV]", 24, 0.0, 600.0 );
	
					// <4j Selection
					hName = "h_gen_ttbarPt__lt4jSelection" + reg_gen_sys_name;
					h_gen_ttbarPt_lt4j[iHisto] = new TH1D( hName, "Gen t#bar{t} system p_{T};p_{T} [GeV]", 24, 0.0, 600.0 );

					// >=4j Selection
					hName = "h_gen_ttbarPt__ge4jSelection" + reg_gen_sys_name;
					h_gen_ttbarPt_ge4j[iHisto] = new TH1D( hName, "Gen t#bar{t} system p_{T};p_{T} [GeV]", 24, 0.0, 600.0 );



					//
					// Gen Lep2 ID
					//
      
					// Incl Selection
					hName = "h_gen_lep2_id__inclSelection" + reg_gen_sys_name;
					h_gen_lep2_id_incl[iHisto] = new TH1D( hName, "Gen 2nd Lepton ID;ID", 7, 1.0, 8.0 );
					h_gen_lep2_id_incl[iHisto]->GetXaxis()->SetBinLabel(1, "ele");
					h_gen_lep2_id_incl[iHisto]->GetXaxis()->SetBinLabel(2, "mu");
					h_gen_lep2_id_incl[iHisto]->GetXaxis()->SetBinLabel(3, "lep tau, ele");
					h_gen_lep2_id_incl[iHisto]->GetXaxis()->SetBinLabel(4, "lep tau, mu");
					h_gen_lep2_id_incl[iHisto]->GetXaxis()->SetBinLabel(5, "had tau, 1 prong");
					h_gen_lep2_id_incl[iHisto]->GetXaxis()->SetBinLabel(6, "had tau, 3 prong");
					h_gen_lep2_id_incl[iHisto]->GetXaxis()->SetBinLabel(7, "\"other\" tau");
	
					// <4j Selection
					hName = "h_gen_lep2_id__lt4jSelection" + reg_gen_sys_name;
					h_gen_lep2_id_lt4j[iHisto] = new TH1D( hName, "Gen 2nd Lepton ID;ID", 7, 1.0, 8.0 );
					h_gen_lep2_id_lt4j[iHisto]->GetXaxis()->SetBinLabel(1, "ele");
					h_gen_lep2_id_lt4j[iHisto]->GetXaxis()->SetBinLabel(2, "mu");
					h_gen_lep2_id_lt4j[iHisto]->GetXaxis()->SetBinLabel(3, "lep tau, ele");
					h_gen_lep2_id_lt4j[iHisto]->GetXaxis()->SetBinLabel(4, "lep tau, mu");
					h_gen_lep2_id_lt4j[iHisto]->GetXaxis()->SetBinLabel(5, "had tau, 1 prong");
					h_gen_lep2_id_lt4j[iHisto]->GetXaxis()->SetBinLabel(6, "had tau, 3 prong");
					h_gen_lep2_id_lt4j[iHisto]->GetXaxis()->SetBinLabel(7, "\"other\" tau");

					// >=4j Selection
					hName = "h_gen_lep2_id__ge4jSelection" + reg_gen_sys_name;
					h_gen_lep2_id_ge4j[iHisto] = new TH1D( hName, "Gen 2nd Lepton ID;ID", 7, 1.0, 8.0 );
					h_gen_lep2_id_ge4j[iHisto]->GetXaxis()->SetBinLabel(1, "ele");
					h_gen_lep2_id_ge4j[iHisto]->GetXaxis()->SetBinLabel(2, "mu");
					h_gen_lep2_id_ge4j[iHisto]->GetXaxis()->SetBinLabel(3, "lep tau, ele");
					h_gen_lep2_id_ge4j[iHisto]->GetXaxis()->SetBinLabel(4, "lep tau, mu");
					h_gen_lep2_id_ge4j[iHisto]->GetXaxis()->SetBinLabel(5, "had tau, 1 prong");
					h_gen_lep2_id_ge4j[iHisto]->GetXaxis()->SetBinLabel(6, "had tau, 3 prong");
					h_gen_lep2_id_ge4j[iHisto]->GetXaxis()->SetBinLabel(7, "\"other\" tau");

	
				} // end if sample is ttbar
      

      } // end loop over mass pts (1 pt only if not signal scan)
    } // end loop over genClassifications for histogram arrays
  } // end loop over analyzers/regions for histogram arrays


	// Set up cutflow histograms
	TH1D* h_cutflow[nAnalyzers];
	for( int iAna=0; iAna<nAnalyzers; iAna++ ) {

		analyzer* thisAnalyzer = analyzers.at(iAna);
		std::string histName  = "h_cutflow_";
		std::string histTitle = "Cutflow histogram ";
		histName  += thisAnalyzer->GetLabel();
		histTitle += thisAnalyzer->GetLabel();

		h_cutflow[iAna] = selectionInfo::get_cutflowHistoTemplate( thisAnalyzer->GetSelections(), histName, histTitle );
	}


  //////////////////////
  //                  //
  // Loop Over Events //
  //                  //
  //////////////////////
    
  // Event Counters
  cout << "    Loading files to loop over" << endl << endl;
  unsigned int nEventsTotal = 0;
  unsigned int nEventsChain = chain->GetEntries();
  if( nEvents >= 0 ) nEventsChain = nEvents;
  
  // Grab list of files
  TObjArray *listOfFiles = chain->GetListOfFiles();
  TIter fileIter(listOfFiles);
  TFile *currentFile = 0;
  while ( (currentFile = (TFile*)fileIter.Next()) ) {
    
    
    //////////////////////
    //                  //
    // Get File Content //
    //                  //
    //////////////////////
    
    // Open File and Get Tree
    TFile *file = new TFile( currentFile->GetTitle(), "read" );
    TTree *tree = (TTree*)file->Get("t");
    if(readFast) TTreeCache::SetLearnEntries(10);
    if(readFast) tree->SetCacheSize(128*1024*1024);
    babyAnalyzer.Init(tree);
    
    // Get weight histogram from baby
    wgtInfo.getWeightHistogramFromBaby( file );
    
    // Loop over Events in current file
    if( nEventsTotal >= nEventsChain ) continue;
    unsigned int nEventsTree = tree->GetEntriesFast();
    for( unsigned int event = 0; event < nEventsTree; ++event) {

      
      ///////////////////////
      //                   //
      // Get Event Content //
      //                   //
      ///////////////////////
   
      // Read Tree
      if( nEventsTotal >= nEventsChain ) continue;
      if(readFast) tree->LoadTree(event);
      babyAnalyzer.GetEntry(event);
      ++nEventsTotal;

      // Progress
      stop_1l_babyAnalyzer::progress( nEventsTotal, nEventsChain );

      
      /////////////////////
      //                 //
      // Check Selection //
      //                 //
      /////////////////////


      // Check JSON
      if( sample.isData && applyjson ) {
	if( !goodrun(run(),ls()) ) continue;
      }
	
      // Check duplicate event
      if( sample.isData ) {
	duplicate_removal::DorkyEventIdentifier id(run(), evt(), ls());
	if( is_duplicate(id) ) continue;
      }

      // Check WNJets genPt
      if( sample.id == sampleInfo::k_W1JetsToLNu_madgraph_pythia8 ||
					sample.id == sampleInfo::k_W2JetsToLNu_madgraph_pythia8 ||
					sample.id == sampleInfo::k_W3JetsToLNu_madgraph_pythia8 ||
					sample.id == sampleInfo::k_W4JetsToLNu_madgraph_pythia8    ) {
				if( nupt()>200.0 ) continue;
      }

			// Pre-calculate all the event weights
      wgtInfo.getEventWeights();



      /////////////////////////////
      //                         //
      // Compute Event Variables //
      //                         //
      /////////////////////////////

      // Find the gen pT of the ttbar system
      double ttbarPt = -99.9;
      LorentzVector genTTbar_LV;
      int nFoundGenTop=0;
      if( sampleIsTTbar ) {
	
				for(int iGen=0; iGen<(int)genqs_p4().size(); iGen++) {
					if( abs(genqs_id().at(iGen))==6 && genqs_isLastCopy().at(iGen) ) {
						genTTbar_LV += genqs_p4().at(iGen);
						nFoundGenTop++;
					} // end if last copy of top
				} // end loop over gen quarks

				if( nFoundGenTop == 2 ) ttbarPt = genTTbar_LV.Pt();

      } // end if sample is ttbar

      
      // Find the gen ID of the 2nd lepton
      double matched_lep_dr = 0.1;

      int gen2ndLep__idx = -1;
      int gen2ndLep__id = -99;
      int gen2ndLep__tauDecay = -1;
      int fill_bin_genLep2ID = -1;
      if( !sample.isData && is2lep() ) {
	
				// match leading lepton first
				int genLep_matchedTo_selLep__idx = -1;
				for(int iGen=0; iGen<(int)genleps_p4().size(); iGen++) {
					if( abs(genleps_id().at(iGen)) != abs(lep1_pdgid()) ) continue;
					if( !genleps_isLastCopy().at(iGen) ) continue;
					if( !genleps_fromHardProcessFinalState().at(iGen) &&
							!genleps_fromHardProcessDecayed().at(iGen)       ) continue;
					if( ROOT::Math::VectorUtil::DeltaR(genleps_p4().at(iGen), lep1_p4()) < matched_lep_dr ) {
						genLep_matchedTo_selLep__idx = iGen;
						break;
					}
				}

				// If matched selected lepton, find lost gen lepton
				if( genLep_matchedTo_selLep__idx>0 ) {

					for(int iGen=0; iGen<(int)genleps_p4().size(); iGen++) {
						if( iGen == genLep_matchedTo_selLep__idx ) continue;
						if( !genleps_isLastCopy().at(iGen) ) continue;
						if( !genleps_fromHardProcessFinalState().at(iGen) &&
								!genleps_fromHardProcessDecayed().at(iGen)       ) continue;
						gen2ndLep__idx = iGen;
						gen2ndLep__id = genleps_id().at(iGen);
						gen2ndLep__tauDecay = genleps_gentaudecay().at(iGen);
					}

					// If found second lep
					if( gen2ndLep__idx>=0 ) {
	      
						if( abs(gen2ndLep__id)==11 ) fill_bin_genLep2ID = 1;  // "ele";
						if( abs(gen2ndLep__id)==13 ) fill_bin_genLep2ID = 2;  // "mu";
						if( abs(gen2ndLep__id)==15 ) {
							if( gen2ndLep__tauDecay==1 ) fill_bin_genLep2ID = 3;  // "lep tau, ele";
							if( gen2ndLep__tauDecay==2 ) fill_bin_genLep2ID = 4;  // "lep tau, mu";
							if( gen2ndLep__tauDecay==3 ) fill_bin_genLep2ID = 5;  // "had tau, 1 prong";
							if( gen2ndLep__tauDecay==4 ) fill_bin_genLep2ID = 6;  // "had tau, 3 prong";
							if( gen2ndLep__tauDecay==5 ) fill_bin_genLep2ID = 7;  // "\"other\" tau";
						} // end if 2nd lep is tau


					} // end if found 2nd gen lep
				} // end if found first gen lep, matched to selected lepton
      } // end if 2lep event and not data

      // Calculate p4 of (lep1 lep2 b b) system
      LorentzVector lep1lep2bb_TLV(0.0,0.0,0.0,0.0);

      LorentzVector lep1lep2bbMet_TLV(0.0,0.0,0.0,0.0);
      double lep1lep2bbMet_pt = -99.9;

      lep1lep2bb_TLV += lep1_p4();
      if(nvetoleps()>1) lep1lep2bb_TLV += lep2_p4();
      
      int jet1_idx = -1;
      double max_deepcsv = -99.9;
      for(int iJet=0; iJet<(int)ak4pfjets_p4().size(); iJet++) {
				if( ak4pfjets_deepCSV().at(iJet) > max_deepcsv ) {
					jet1_idx = iJet;
					max_deepcsv  = ak4pfjets_deepCSV().at(iJet);
				}
      }
      if(jet1_idx>=0) lep1lep2bb_TLV += ak4pfjets_p4().at(jet1_idx);
      
      int jet2_idx = -1;
      max_deepcsv = -99.9;
      for(int iJet=0; iJet<(int)ak4pfjets_p4().size(); iJet++) {
				if( iJet==jet1_idx ) continue;
				if( ak4pfjets_deepCSV().at(iJet) > max_deepcsv ) {
					jet2_idx = iJet;
					max_deepcsv = ak4pfjets_deepCSV().at(iJet);
				}
      }
      if(jet2_idx>=0) lep1lep2bb_TLV += ak4pfjets_p4().at(jet2_idx);
      
      // Calculate p4 of (lep1 lep2 b b MET) system
      lep1lep2bbMet_TLV = lep1lep2bb_TLV;
      LorentzVector met_TLV( pfmet()*cos(pfmet_phi()), pfmet()*sin(pfmet_phi()), 0.0, pfmet() );
      lep1lep2bbMet_TLV += met_TLV;
    
      lep1lep2bbMet_pt = lep1lep2bbMet_TLV.Pt();

      // Calculate mlb using lep2 instead of lep1
      LorentzVector lep2b_TLV(0.0,0.0,0.0,0.0);
      double minDr = 99.9;
      int minBJetIdx = -99;
      if(nvetoleps()>1) {
				lep2b_TLV += lep2_p4();
				for(int iJet=0; iJet<(int)ak4pfjets_p4().size(); iJet++) {
					if(!ak4pfjets_passMEDbtag().at(iJet)) continue;
					if(ROOT::Math::VectorUtil::DeltaR(ak4pfjets_p4().at(iJet),lep2_p4())<minDr) {
						minDr = ROOT::Math::VectorUtil::DeltaR(ak4pfjets_p4().at(iJet),lep2_p4());
						minBJetIdx = iJet;
					}
				} // end loop over jets
				if(minBJetIdx>=0) lep2b_TLV += ak4pfjets_p4().at(minBJetIdx);
      } // end if nvetoleps>1

      int mStop = mass_stop();
      int mLSP  = mass_lsp();



			/////////////////////////////////////////////////////////////
			//                                                         //
			// Loop over all analyzers, genClassy's, systematics, etc. //
			//                                                         //
			/////////////////////////////////////////////////////////////

			// Loop over all analyzers
			for( int iAna=0; iAna<nAnalyzers; iAna++ ) {
				analyzer* thisAnalyzer = analyzers.at(iAna);


				// Make an array of which genClassy's this event passes
				bool passedGenClassies[genClassyInfo::k_nGenClassy];
				for( genClassyInfo::Util thisGenClassy : thisAnalyzer->GetGenClassifications() ) {
					passedGenClassies[thisGenClassy.id] = thisGenClassy.eval_GenClassy();

					// Manually correct the ZZto2L2Nu sample
					if( sample.id==sampleInfo::k_ZZTo2L2Nu_powheg_pythia8 ) {
						if( thisGenClassy.id == genClassyInfo::k_ge2lep ||
								thisGenClassy.id == genClassyInfo::k_incl ) passedGenClassies[thisGenClassy.id] = true;
						else passedGenClassies[thisGenClassy.id] = false;
					}
				}

				// Check if this event passes selections with JES set to nominal
				//  (saves us having to evaluate this for every systematic)
				thisAnalyzer->SetJesType( 0 );
				bool pass_JESnominal = thisAnalyzer->PassSelections();

				// Fill cutflow histogram
				std::vector<bool> cutflow_results = selectionInfo::get_selectionResults( thisAnalyzer->GetSelections() );
				for( uint i=0; i<cutflow_results.size(); i++ ) {
					if( !cutflow_results.at(i) ) break;
					h_cutflow[iAna]->Fill( i+1 );
				}


				// Loop over all systematics in the analyzer
				for( sysInfo::Util thisSystematic : thisAnalyzer->GetSystematics() ) {

					// Check if this event passes selections, and also set the appropriate JES type for future use
					if( thisSystematic.id == sysInfo::k_JESUp ) {
						thisAnalyzer->SetJesType( 1 );
						if( !thisAnalyzer->PassSelections() ) continue;
					}
					else if( thisSystematic.id == sysInfo::k_JESDown ) {
						thisAnalyzer->SetJesType( -1 );
						if( !thisAnalyzer->PassSelections() ) continue;
					}
					else {
						thisAnalyzer->SetJesType( 0 );
						if( !pass_JESnominal ) continue;
					}

					// If we've passed selections, then get the event weight and the categories passed
					double weight = thisAnalyzer->GetEventWeight( thisSystematic.id );
					std::vector<int> categories_passed = thisAnalyzer->GetCategoriesPassed();

					// Loop over all the gen classifications that we passed
					for( genClassyInfo::Util thisGenClassy : thisAnalyzer->GetGenClassifications() ) {
						int iGen = thisGenClassy.id;
						if( !passedGenClassies[iGen] ) continue;

						// Get the index for the histogram corresponding to this genClassy and systematic
						int histIndex = iGen*nSystematics + thisSystematic.id;

						// Fill yield histograms
						for( int category : categories_passed ) {
							if( sample.isSignalScan ) {
								TH3D* yieldHisto = (TH3D*)thisAnalyzer->GetYieldHistogram( histIndex );
								yieldHisto->Fill( mStop, mLSP, category, weight );
							}
							else thisAnalyzer->GetYieldHistogram( histIndex )->Fill( category, weight );
						}

						/////////////////////////////////////
						//                                 //
						// Fill other non-yield histograms //
						//                                 //
						/////////////////////////////////////

						if( thisSystematic.id == sysInfo::k_nominal ) {

							for(int iMassPt=0; iMassPt<nMassPts; iMassPt++) {

								if( sample.isSignalScan && mStop!=sample.massPtList[iMassPt].first && mLSP!=sample.massPtList[iMassPt].second ) continue;
								//if(!isnormal(wgt_nominal)) cout << "NaN/inf weight: nEntries=" << wgtInfo.nEvents << ", lepSF=" << wgtInfo.sf_lep << ", vetoLep="<< wgtInfo.sf_vetoLep << ", btagSF=" << wgtInfo.sf_bTag << endl;
								// Histo Index
								int iHisto = iAna*nGenClassy*nMassPts + iGen*nMassPts + iMassPt;

								// Vars
								double nGoodJets = ngoodjets();

								bool add2ndLepToMet = thisAnalyzer->GetAdd2ndLep();

								double mt =         add2ndLepToMet ? mt_met_lep_rl() : mt_met_lep();
								double modTopness = add2ndLepToMet ? topnessMod_rl() : topnessMod();
								double met =        add2ndLepToMet ? pfmet_rl() : pfmet();

								double mlb = Mlb_closestb();
								if( TString(thisAnalyzer->GetLabel()).Contains("CR0b") ) mlb = ( lep1_p4() + ak4pfjets_leadbtag_p4() ).M();

								// Met Sideband CR area, met>=150

								if( met>=150 && met<250 ) {
									// mlb, met sideband CR
									h_mlb_150to250met_incl[iHisto]->Fill( mlb, weight );
									if( nGoodJets<4 )  h_mlb_150to250met_lt4j[iHisto]->Fill( mlb, weight );
									if( nGoodJets>=4 ) h_mlb_150to250met_ge4j[iHisto]->Fill( mlb, weight );
	      
									// mlb_lep2, met sideband CR
									if(nvetoleps()>1 && minBJetIdx>=0) {
										h_mlb_lep2_150to250met_incl[iHisto]->Fill( lep2b_TLV.M(), weight );
										if( nGoodJets<4 )  h_mlb_lep2_150to250met_lt4j[iHisto]->Fill( lep2b_TLV.M(), weight );
										if( nGoodJets>=4 ) h_mlb_lep2_150to250met_ge4j[iHisto]->Fill( lep2b_TLV.M(), weight );
									}

								} // end if 150<met<250

								// Signal Region Area, met>=250
								if( met<250.0 ) continue;
	    
								// nJets
								h_nJets[iHisto]->Fill( nGoodJets, weight );

								// nBTags
								h_nBTags[iHisto]->Fill( ngoodbtags(), weight );
	    
								// lep1 pT
								h_lep1Pt_incl[iHisto]->Fill( lep1_p4().Pt(), weight );

								// lep2 pT
								if( nvetoleps()>1 ) h_lep2Pt_incl[iHisto]->Fill( lep2_p4().Pt(), weight );

								// jet pT
								for(int iJet=0; iJet<(int)ak4pfjets_p4().size(); iJet++) h_jetPt_incl[iHisto]->Fill( ak4pfjets_p4().at(iJet).Pt(), weight );

								// jet1 pT
								h_jet1Pt_incl[iHisto]->Fill( ak4pfjets_p4().at(0).Pt(), weight );

								// jet2 pT
								h_jet2Pt_incl[iHisto]->Fill( ak4pfjets_p4().at(1).Pt(), weight );

								// DeepCSV jet1 pT
								if(jet1_idx>=0) h_deepcsvJet1Pt_incl[iHisto]->Fill( ak4pfjets_p4().at(jet1_idx).Pt(), weight );

								// DeepCSV jet2 pT
								if(jet2_idx>=0) h_deepcsvJet2Pt_incl[iHisto]->Fill( ak4pfjets_p4().at(jet2_idx).Pt(), weight );

								// met
								h_met_incl[iHisto]->Fill( met, weight );
								if( nGoodJets<4  ) h_met_lt4j[iHisto]->Fill( met, weight );
								if( nGoodJets>=4 ) h_met_ge4j[iHisto]->Fill( met, weight );

								// lep1lep2bbMetPt
								h_lep1lep2bbMetPt_incl[iHisto]->Fill( lep1lep2bbMet_pt, weight );
								if( nGoodJets<4  ) h_lep1lep2bbMetPt_lt4j[iHisto]->Fill( lep1lep2bbMet_pt, weight );
								if( nGoodJets>=4 ) h_lep1lep2bbMetPt_ge4j[iHisto]->Fill( lep1lep2bbMet_pt, weight );

								// mt
								h_mt_incl[iHisto]->Fill( mt, weight );

								// modTopness
								h_modTopness_incl[iHisto]->Fill( modTopness, weight );
								if( nGoodJets<4  ) h_modTopness_lt4j[iHisto]->Fill( modTopness, weight );
								if( nGoodJets>=4 ) h_modTopness_ge4j[iHisto]->Fill( modTopness, weight );

								// mlb
								h_mlb_incl[iHisto]->Fill( mlb, weight );
								if( nGoodJets<4 )  h_mlb_lt4j[iHisto]->Fill( mlb, weight );
								if( nGoodJets>=4 ) h_mlb_ge4j[iHisto]->Fill( mlb, weight );

								// mlb, modTopness bins
								if(modTopness<0.0)   h_mlb_lt0modTopness[iHisto]->Fill( mlb, weight );
								if(modTopness>=0.0)  h_mlb_ge0modTopness[iHisto]->Fill( mlb, weight );
								if(modTopness>=10.0) h_mlb_ge10modTopness[iHisto]->Fill( mlb, weight );

								// mlb_lep2
								if(nvetoleps()>1 && minBJetIdx>=0) {
									h_mlb_lep2_incl[iHisto]->Fill( lep2b_TLV.M(), weight );
									if( nGoodJets<4 )  h_mlb_lep2_lt4j[iHisto]->Fill( lep2b_TLV.M(), weight );
									if( nGoodJets>=4 ) h_mlb_lep2_ge4j[iHisto]->Fill( lep2b_TLV.M(), weight );
								}

								// Gen TTBar System
								if( sampleIsTTbar ) {
									h_gen_ttbarPt_incl[iHisto]->Fill( ttbarPt, weight );
									if( nGoodJets<4 )  h_gen_ttbarPt_lt4j[iHisto]->Fill( ttbarPt, weight );
									if( nGoodJets>=4 ) h_gen_ttbarPt_ge4j[iHisto]->Fill( ttbarPt, weight );
								}

								// Gen 2nd Lep ID
								if( !sample.isData && is2lep() && gen2ndLep__idx>=0 ) {
									h_gen_lep2_id_incl[iHisto]->Fill( fill_bin_genLep2ID, weight );
									if( ngoodjets()<4 )  h_gen_lep2_id_lt4j[iHisto]->Fill( fill_bin_genLep2ID, weight );
									if( ngoodjets()>=4 ) h_gen_lep2_id_ge4j[iHisto]->Fill( fill_bin_genLep2ID, weight );
								}

							} // end loop over mass points (1 if not signal scan)

						} // End filling of non-yield histograms

					} // End loop over genClassy's

				} // End loop over systematics

			} // End loop over analyzers

		} // End loop over events in tree


    //
    // Clean Up
    //
    delete tree;
    file->Close();
    delete file;

  } // end loop over file list


  //
  // Output Sanitation
  //
  if ( nEventsChain != nEventsTotal ) {
	  cout << Form( "ERROR: number of events from files (%d) is not equal to total number of events (%d)", nEventsChain, nEventsTotal ) << endl;
  }


  //
  // Print Selection Cutflow
  //
  cout << "====================================================" << endl;
  cout << endl;
  for(int iAna=0; iAna<nAnalyzers; iAna++) {
	  cout << "    " << analyzers.at(iAna)->GetLabel() << " Cutflow: " << endl;
	  for(int iCut=1; iCut<=(int)h_cutflow[iAna]->GetNbinsX(); iCut++) {
		  cout << "      nEvents pass " << h_cutflow[iAna]->GetXaxis()->GetBinLabel(iCut) << " = " << h_cutflow[iAna]->GetBinContent(iCut) << endl;
	  }
	  cout << endl;
	  cout << endl;
  }
  cout << "====================================================" << endl;


  //
  // Clean stopCORE objects
  //
  wgtInfo.cleanUp(); 


  //
  // Close Output File
  //
  f_output->Write();
  f_output->Close();


  //
  // Clean input chain
  // 
  chain->~TChain();
  if( sample.isData ) duplicate_removal::clear_list();

  //
  // Benchmark Reporting
  //
  bmark->Stop("benchmark");
  cout << endl;
  cout << nEventsTotal << " Events Processed" << endl;
  cout << "------------------------------" << endl;
  cout << "CPU  Time:	" << Form( "%.01f", bmark->GetCpuTime("benchmark")  ) << endl;
  cout << "Real Time:	" << Form( "%.01f", bmark->GetRealTime("benchmark") ) << endl;
  cout << endl;
  delete bmark;

  cout << "====================================================" << endl;
    
  //fclose(f_evtList);

  //
  // Return!
  //
  return 0;

} // End of function "looper"
コード例 #16
0
ファイル: fakerate.C プロジェクト: radziej/findsusyb3
void tight_loose_ratioplot()
{
  DEBUG("tight_loose_ratioplot() start");
  MakeCanvas(1,1);

  DEBUG("reading histograms");
  // "plot" histograms, i.e. read into memory
  cd(1);
  top();
  plot3("TightMuons");
  cd(2);
  top();
  plot3("LooseMuons");
  cd(1);

  TLegend * leg = new TLegend(0.53, 0.52, 0.77, 0.84);
  setopt(leg);
  Bool_t first = kTRUE;

  // get summed histograms
  vector<Int_t> entries;
  TH3D * hTightSum = 0;
  TH3D * hLooseSum = 0;
  for (Int_t i = 0; i < gMaxProcess; i++) {
    Int_t process = gOrder[0][i];
    // not existing
    TH3D * hTight3 = gHisto3[0][process];
    TH3D * hLoose3 = gHisto3[1][process];
    if (hTight3 == 0 || hLoose3 == 0) {
      ERROR("could not get histogram # " << i << " from memory");
      continue;
    }
    // if joined, it was already considered in previous iteration
    if (gProcess[process].join)
      continue;
    if (strncmp(gProcess[process].fname, "qcd", 3) &&
	strncmp(gProcess[process].fname, "dyll", 4) &&
	strncmp(gProcess[process].fname, "ttjets", 6) &&
	strncmp(gProcess[process].fname, "wjetstolnu", 10) &&
	strncmp(gProcess[process].fname, "data", 3))
      continue;
    DEBUG("Creating histos for process " << gProcess[process].fname);
    hTightSum = new TH3D(*hTight3);
    hLooseSum = new TH3D(*hLoose3);
    // check if histograms are joined -> we need to add statistics
    for (Int_t j = i+1; j < gMaxProcess; j++) {
      Int_t proc = gOrder[0][j];
      if (gOrder[1][j] != proc) {
	ERROR("wrong order - need to restart!");
	return;
      }
      // only add joined histograms
      if (!gProcess[proc].join)
	break;
      // not existing
      if (gHisto3[0][proc] == 0 || gHisto3[1][proc] == 0)
	continue;
      DEBUG("Adding histos for process " << gProcess[proc].fname);
      hTightSum->Add(gHisto3[0][proc], 1.);
      hLooseSum->Add(gHisto3[1][proc], 1.);
    }
    DEBUG("Getting ratio");
    TH1D * histo = get_1d_ratio(hTightSum, hLooseSum);
    if (histo == 0) {
      ERROR("Division failed");
      return;
    }
    check_1d_ratio_histogram(histo);
    setopt(histo);
    histo->SetLineColor(gProcess[process].lcolor);
    histo->SetLineStyle(gProcess[process].lstyle);
    DEBUG("Adding to legend");
    if (process != gMaxProcess-1) {
      leg->AddEntry(histo, gProcess[process].tname, "l");
    }
    else {
      leg->AddEntry(histo, gProcess[process].tname);
    }
    DEBUG("Draw");
    if (first) {
      histo->SetMaximum(1.);
      histo->SetMinimum(-0.1);
      histo->SetXTitle("p_{T}(#mu) [GeV]");
      histo->SetYTitle("T/L ratio");
      histo->Draw("ehisto");
      first = kFALSE;
    }
    else {
      if (process == gMaxProcess-1) {
	histo->SetMarkerStyle(gProcess[gMaxProcess-1].marker);
	histo->Draw("epsame");
      }
      else {
	histo->Draw("ehistosame");
      }
    }
  }
  // add subtracted data histogram
  TH1D * hdata_subtracted = get_subtracted_tight_loose_ratio(false, false);
  if (hdata_subtracted == 0)
    return;
  Double_t linemax = hdata_subtracted->GetXaxis()->GetXmax();
  Double_t linemin = hdata_subtracted->GetXaxis()->GetXmin();
  TLine * l = new TLine(linemin, 0, linemax, 0);
  l->SetLineStyle(kDotted);
  l->SetLineColor(kBlack);
  l->SetLineWidth(2);
  l->Draw();
  hdata_subtracted->SetMarkerColor(kBlue);
  hdata_subtracted->SetMarkerStyle(8);
  hdata_subtracted->Draw("epsame");
  leg->AddEntry(hdata_subtracted, "data subtr.", "ep");
  leg->Draw();
  gPad->Print("tlratio.pdf");
}
コード例 #17
0
ファイル: analyze3D.C プロジェクト: noferini/lessonmaterials
void analyze(Int_t step){

  // TOF propagation factors (TOF efficiencies)
  fEfficiencyPiTOF = new TF1("fEfficiencyPiTOF","(x > 0.3)*0.7",0,10);
  fEfficiencyKaTOF = new TF1("fEfficiencyKaTOF","(x > 0.3)*(x-0.3)*(x<1) + (x>1)*0.7",0,10);
  fEfficiencyPrTOF = new TF1("fEfficiencyPrTOF","(x > 0.3)*(x-0.3)*(x<1) + (x>1)*0.7",0,10);

  // teoretical separation (perfect if equal to the one simualted in sim.C)
  fseparation = new TF1("f","[0]+[1]/x",0,100);
  fseparation->SetParameter(0,0.);
  fseparation->SetParameter(1,7.);
 
  fseparationPiKa = new TF1("fPiKa","[0]+[1]/TMath::Power(x,2.5)",0,100);
  fseparationPiKa->SetParameter(0,2.34);
  fseparationPiKa->SetParameter(1,10);

  fseparationKaPr = new TF1("fKaPr","[0]+[1]/TMath::Power(x,2.5)",0,100);
  fseparationKaPr->SetParameter(0,1);
  fseparationKaPr->SetParameter(1,56);

  // x=p, y=pt/p (normalized at the number of sigma assuming 80 ps resolution)
  fTOFpi = new TF2("fTOFpi","3.7/y*(sqrt(x*x+0.0193210)/x-1)*37.47405725",0.3,10,0.5,1);
  fTOFka = new TF2("fTOFka","3.7/y*(sqrt(x*x+0.243049)/x-1)*37.47405725",0.3,10,0.5,1);
  fTOFpr = new TF2("fTOFpr","3.7/y*(sqrt(x*x+0.879844)/x-1)*37.47405725",0.3,10,0.5,1);


  // x=p, already normalized in number of sigma (sigma assumed 3.5=7% of the MIP)
  fTPCpi = new TF1("fTPCpi",BetheBlochAleph,0,10,6);
  fTPCpi->SetParameter(0,fKp1);
  fTPCpi->SetParameter(1,fKp2);
  fTPCpi->SetParameter(2,fKp3);
  fTPCpi->SetParameter(3,fKp4);
  fTPCpi->SetParameter(4,fKp5);
  fTPCpi->SetParameter(5,0.139);
  fTPCka = new TF1("fTPCka",BetheBlochAleph,0,10,6);
  fTPCka->SetParameter(0,fKp1);
  fTPCka->SetParameter(1,fKp2);
  fTPCka->SetParameter(2,fKp3);
  fTPCka->SetParameter(3,fKp4);
  fTPCka->SetParameter(4,fKp5);
  fTPCka->SetParameter(5,0.493);
  fTPCpr = new TF1("fTPCpr",BetheBlochAleph,0,10,6);
  fTPCpr->SetParameter(0,fKp1);
  fTPCpr->SetParameter(1,fKp2);
  fTPCpr->SetParameter(2,fKp3);
  fTPCpr->SetParameter(3,fKp4);
  fTPCpr->SetParameter(4,fKp5);
  fTPCpr->SetParameter(5,0.938);

  Float_t width = 1.0;
  addshift =0;

  invwidth = 1./width;

  Float_t widthTOF = 1.0;
  addshiftTOF =0;

  invwidthTOF = 1./widthTOF;

  TH1D *priorsPt[6];
  TH1D *newpriorsPt[6];
  TH1D *truePt[6];
  TH1D *allPtPos = new TH1D("allPtP","All positive;p_{T} (GeV/#it{c});N",100,0,10);
  TH1D *allPtNeg = new TH1D("allPtN","All negative;p_{T} (GeV/#it{c});N",100,0,10);

  TH3D *priorsKs[3][3];
  TH3D *newpriorsKs[3][3];
  TH3D *truePidKs[3][3];
  TH3D *trueKs;

  TH2D *priorsPhi[3][3];
  TH2D *newpriorsPhi[3][3];
  TH2D *truePidPhi[3][3];
  TH2D *truePhi;

  TH3D *priorsLc[3][3][3];
  TH3D *newpriorsLc[3][3][3];
  TH3D *truePidLc[3][3][3];
  TH3D *trueLc,*mypidLc;

  TH3D *priorsLcbar[3][3][3];
  TH3D *newpriorsLcbar[3][3][3];
  TH3D *truePidLcbar[3][3][3];
  TH3D *trueLcbar,*mypidLcbar;

  Int_t nbinPtFrKa = 8;
  Int_t nbinPtFrPi = 8;
  Int_t nbinY = 1;
  Int_t nbinpol=nbinPtFrKa*nbinPtFrPi*nbinY;
  Double_t normbin = 1./nbinpol;
  Int_t nbinmlc = 100;
  Int_t nbinptlc = 10;

  const char *spec[3] = {"Pi","Ka","Pr"};

  if(step==0){
    priorsPt[0] = new TH1D("oldpriorsPtPiP","Pion (+) priors;p_{T} (GeV/#it{c});N",100,0,10);
    for(Int_t i=1;i<=100;i++)
      priorsPt[0]->SetBinContent(i,1);
    priorsPt[1] = new TH1D("oldpriorsPtKaP","Kaon (+) priors;p_{T} (GeV/#it{c});N",100,0,10);
    priorsPt[2] = new TH1D("oldpriorsPtPrP","Proton (+) priors;p_{T} (GeV/#it{c});N",100,0,10);
    priorsPt[3] = new TH1D("oldpriorsPtPiM","Pion (-) priors;p_{T} (GeV/#it{c});N",100,0,10);
    priorsPt[4] = new TH1D("oldpriorsPtKaM","Kaon (-) priors;p_{T} (GeV/#it{c});N",100,0,10);
    priorsPt[5] = new TH1D("oldpriorsPtPrM","Proton (-) priors;p_{T} (GeV/#it{c});N",100,0,10);
    priorsPt[1]->Add(priorsPt[0]);
    priorsPt[2]->Add(priorsPt[0]);
    priorsPt[3]->Add(priorsPt[0]);
    priorsPt[4]->Add(priorsPt[0]);
    priorsPt[5]->Add(priorsPt[0]);

    // Ks and phi priors
    for(Int_t i=0; i< 3;i++){
      for(Int_t j=0; j< 3;j++){
	priorsKs[i][j] =  new TH3D(Form("oldpriorsKs%s%s",spec[i],spec[j]),Form("K^{0*} priors for %s-%s;m_{#piK} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j]),200,0.4,1.4,40,0,10,nbinpol,-1.001,1.001);
	priorsPhi[i][j] =  new TH2D(Form("oldpriorsPhi%s%s",spec[i],spec[j]),Form("#phi priors for %s-%s;m_{KK} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j]),100,0.98,1.05,40,0,10);


	if(i==0 && j==0){
	  for(Int_t ibx=1;ibx<=200;ibx++)
	    for(Int_t iby=1;iby<=40;iby++){
	      for(Int_t ibz=1;ibz <= nbinpol;ibz++)
		priorsKs[i][j]->SetBinContent(ibx,iby,ibz,1);
	      priorsPhi[i][j]->SetBinContent(ibx,iby,1);
	    }
	}
	else{
	  priorsKs[i][j]->Add(priorsKs[0][0]);
	  priorsPhi[i][j]->Add(priorsPhi[0][0]);
	}

	for(Int_t k=0; k< 3;k++){
	  priorsLc[i][j][k] =  new TH3D(Form("oldpriorsLc%s%s%s",spec[i],spec[j],spec[k]),Form("#Lambda_{c}^{+} priors for %s-%s-%s;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j],spec[k]),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.);
	  priorsLcbar[i][j][k] =  new TH3D(Form("oldpriorsLcbar%s%s%s",spec[i],spec[j],spec[k]),Form("#overline{#Lambda}_{c}^{-} priors for %s-%s-%s;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j],spec[k]),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.);
	  if(i==0 && j==0 && k==0){
	    for(Int_t ibx=1;ibx<=nbinmlc;ibx++)
	      for(Int_t iby=1;iby<=nbinptlc;iby++){
		for(Int_t ibz=1;ibz <= nbinpol;ibz++){
		  priorsLc[i][j][k]->SetBinContent(ibx,iby,ibz,1);
		  priorsLcbar[i][j][k]->SetBinContent(ibx,iby,ibz,1);
		}
	      }
	  }
	  else{
	    priorsLc[i][j][k]->Add(priorsLc[0][0][0]);
	    priorsLcbar[i][j][k]->Add(priorsLc[0][0][0]);
	  }
	}
      }
    }
  }
  else{
    TFile *fin = new TFile(Form("step%i.root",step));
    priorsPt[0] = (TH1D *) fin->Get("priorsPtPiP"); 
    priorsPt[0]->SetName("oldpriorsPtPiP");
    priorsPt[1] = (TH1D *) fin->Get("priorsPtKaP"); 
    priorsPt[1]->SetName("oldpriorsPtPiP");
    priorsPt[2] = (TH1D *) fin->Get("priorsPtPrP"); 
    priorsPt[2]->SetName("oldpriorsPtPiP");
    priorsPt[3] = (TH1D *) fin->Get("priorsPtPiM"); 
    priorsPt[3]->SetName("oldpriorsPtPiM");
    priorsPt[4] = (TH1D *) fin->Get("priorsPtKaM"); 
    priorsPt[4]->SetName("oldpriorsPtKaM");
    priorsPt[5] = (TH1D *) fin->Get("priorsPtPrM"); 
    priorsPt[5]->SetName("oldpriorsPtPrM");

    // Ks and phi priors
    for(Int_t i=0; i< 3;i++){
      for(Int_t j=0; j< 3;j++){
	priorsKs[i][j] =  (TH3D *) fin->Get(Form("priorsKs%s%s",spec[i],spec[j]));
	priorsKs[i][j]->SetName(Form("oldpriorsKs%s%s",spec[i],spec[j]));
	priorsPhi[i][j] =  (TH2D *) fin->Get(Form("priorsPhi%s%s",spec[i],spec[j]));
	priorsPhi[i][j]->SetName(Form("oldpriorsPhi%s%s",spec[i],spec[j]));
	for(Int_t k=0; k< 3;k++){
	  priorsLc[i][j][k] =  (TH3D *) fin->Get(Form("priorsLc%s%s%s",spec[i],spec[j],spec[k]));
	  priorsLc[i][j][k]->SetName(Form("oldpriorsLc%s%s%s",spec[i],spec[j],spec[k]));
	  priorsLcbar[i][j][k] =  (TH3D *) fin->Get(Form("priorsLcbar%s%s%s",spec[i],spec[j],spec[k]));
	  priorsLcbar[i][j][k]->SetName(Form("oldpriorsLcbar%s%s%s",spec[i],spec[j],spec[k]));
	}
      }
    }
  }
  
  newpriorsPt[0] = new TH1D("priorsPtPiP","Pion (+) priors;p_{T} (GeV/#it{c});N",100,0,10);
  newpriorsPt[1] = new TH1D("priorsPtKaP","Kaon (+) priors;p_{T} (GeV/#it{c});N",100,0,10);
  newpriorsPt[2] = new TH1D("priorsPtPrP","Proton (+) priors;p_{T} (GeV/#it{c});N",100,0,10);
  newpriorsPt[3] = new TH1D("priorsPtPiM","Pion (-) priors;p_{T} (GeV/#it{c});N",100,0,10);
  newpriorsPt[4] = new TH1D("priorsPtKaM","Kaon (-) priors;p_{T} (GeV/#it{c});N",100,0,10);
  newpriorsPt[5] = new TH1D("priorsPtPrM","Proton (-) priors;p_{T} (GeV/#it{c});N",100,0,10);

  // Ks and phi priors distributions
  for(Int_t i=0; i< 3;i++){
    for(Int_t j=0; j< 3;j++){
      newpriorsKs[i][j] =  new TH3D(Form("priorsKs%s%s",spec[i],spec[j]),Form("K^{0*} priors for %s-%s;m_{#piK} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j]),200,0.4,1.4,40,0,10,nbinpol,-1.001,1.001);
      newpriorsPhi[i][j] =  new TH2D(Form("priorsPhi%s%s",spec[i],spec[j]),Form("#phi priors for %s-%s;m_{KK} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j]),100,0.98,1.05,40,0,10);
      for(Int_t k=0; k< 3;k++){
	newpriorsLc[i][j][k] =  new TH3D(Form("priorsLc%s%s%s",spec[i],spec[j],spec[k]),Form("#Lambda_{c}^{+} priors for %s-%s-%s;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j],spec[k]),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.);
	newpriorsLcbar[i][j][k] =  new TH3D(Form("priorsLcbar%s%s%s",spec[i],spec[j],spec[k]),Form("#overline{#Lambda}_{c}^{-} priors for %s-%s-%s;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j],spec[k]),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.);
      }
    }
  }
  
  truePt[0]  = new TH1D("truePtPiP","Pion (+) truth;p_{T} (GeV/#it{c});N",100,0,10);
  truePt[1]  = new TH1D("truePtKaP","Kaon (+) truth;p_{T} (GeV/#it{c});N",100,0,10);
  truePt[2]  = new TH1D("truePtPrP","Proton (+) truth;p_{T} (GeV/#it{c});N",100,0,10);
  truePt[3]  = new TH1D("truePtPiM","Pion (-) truth;p_{T} (GeV/#it{c});N",100,0,10);
  truePt[4]  = new TH1D("truePtKaM","Kaon (-) truth;p_{T} (GeV/#it{c});N",100,0,10);
  truePt[5]  = new TH1D("truePtPrM","Proton (-) truth;p_{T} (GeV/#it{c});N",100,0,10);

  // Ks and phi truePid distributions
  for(Int_t i=0; i< 3;i++){
    for(Int_t j=0; j< 3;j++){
      truePidKs[i][j] =  new TH3D(Form("truePidKs%s%s",spec[i],spec[j]),Form("K^{0*} truePid for %s-%s;m_{#piK} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j]),200,0.4,1.4,40,0,10,nbinpol,-1.001,1.001);
      truePidPhi[i][j] =  new TH2D(Form("truePidPhi%s%s",spec[i],spec[j]),Form("#phi truePid for %s-%s;m_{KK} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j]),100,0.98,1.05,40,0,10);

      for(Int_t k=0; k< 3;k++){
	truePidLc[i][j][k] =  new TH3D(Form("truePidLc%s%s%s",spec[i],spec[j],spec[k]),Form("#Lambda_{c}^{+} truePid for %s-%s-%s;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j],spec[k]),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.);
	truePidLcbar[i][j][k] =  new TH3D(Form("truePidLcbar%s%s%s",spec[i],spec[j],spec[k]),Form("#overline{#Lambda}_{c}^{-} truePid for %s-%s-%s;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j],spec[k]),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.);
      }

    }
  }

  trueKs =  new TH3D(Form("trueKs"),Form("K^{0*} true;m_{#piK} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N"),200,0.4,1.4,40,0,10,nbinpol,-1.001,1.001);
  truePhi =  new TH2D(Form("truePhi"),Form("#phi true;m_{KK} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N"),100,0.98,1.05,40,0,10);

  trueLc =  new TH3D(Form("trueLc"),Form("#Lambda_{c}^{+} true;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N"),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.);
  trueLcbar =  new TH3D(Form("trueLcbar"),Form("#overline{#Lambda}_{c}^{-} true;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N"),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1);

  mypidLc =  new TH3D(Form("mypidLc"),Form("#Lambda_{c}^{+} true;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N"),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.);
  mypidLcbar =  new TH3D(Form("mypidLcbar"),Form("#Lambda_{c}^{+} true;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N"),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.);

  // define particle types (particle type array)
  particle::AddParticleType("pi+",0.139,1); // 0
  particle::AddParticleType("pi-",0.139,-1); // 1
  particle::AddParticleType("K+",0.493,1); // 2 
  particle::AddParticleType("K-",0.493,-1); // 3
  particle::AddParticleType("p+",0.938,1); // 4 
  particle::AddParticleType("p-",0.938,-1); // 5
  particle::AddParticleType("K0*",0.896,0,5.05e-02); // 6
  particle::AddParticleType("K0bar*",0.896,0,5.05e-02); // 7
  particle::AddParticleType("Phi",1.02,0,0.00426); // 8
  particle::AddParticleType("Delta++",1.232,2,0.118); // 9 
  particle::AddParticleType("Delta--",1.232,-2,0.118);  // 10
  particle::AddParticleType("Lambdac+",2.28646,1,0.008); // 11
  particle::AddParticleType("Lambdacbar-",2.28646,-1,0.008); // 12
  particle::AddParticleType("Lambda1520",1.5195,-1,0.0000156); // 12

  particle d1("pi+");
  particle d2("K+");
  particle d3("p+");
  particle d4("pi-");
  particle d5("K-");
  particle d6("p-");

  particle prong1;
  particle prong2;
  particle prong3;

  particle polarKs("K0*");
  particle polarLc("Lambdac+");

  Int_t charge[] = {1,-1,1,-1,1,-1,0,0,0,2,-2,1,-1};

  particle ppos[20000];
  particle pneg[20000];

  Float_t weightsPos[20000][3];
  Float_t weightsNeg[20000][3];
  Int_t passMyPIDPos[20000][3];
  Int_t passMyPIDNeg[20000][3];

  Int_t npos=0;
  Int_t nneg=0;

  Float_t signal,signalTOF,signalTPC,pt,pz,phi,ptComb,ptComb3prong,invmass;
  Float_t ptd,pzd,phid;

  Float_t priors[3],prob[3];
  Float_t priors2[3][3],prob2[3][3];
  Float_t priors3[3][3][3],prob3[3][3][3];
      
  Int_t iev=-1,id,mother;
  Int_t cev;
  
  TFile *fout = new TFile(Form("step%i.root",step+1),"RECREATE");
  // TTree *treeKs = new TTree("treeKs","treeKs");
  // Float_t ptPair,massPair,ptD1,ptD2,weightD1[3],weightD2[3],weightFill;
  // Int_t isTrue,isTruePid;
  // treeKs->Branch("ptPair",&ptPair,"ptPair/F");
  // treeKs->Branch("massPair",&massPair,"massPair/F");
  // treeKs->Branch("ptPi",&ptD1,"ptPi/F");
  // treeKs->Branch("ptKa",&ptD2,"ptKa/F");
  // treeKs->Branch("weightPi",weightD1,"wightPi[3]/F");
  // treeKs->Branch("weightKa",weightD2,"wightKa[3]/F");
  // treeKs->Branch("weightFill",&weightFill,"wightFill/F");
  // treeKs->Branch("isTruePid",&isTruePid,"isTruePid/I");
  // treeKs->Branch("isTrue",&isTrue,"isTrue/I");
  TH1F *hcentr = new TH1F("hcentr","",100,0,100);

  FILE *flist = fopen("lista","r");
  char namefile[100];
  Float_t weight1[3],weight2[3],weight3[3];
  Float_t ptPi,ptKa,ptPr;

  TH1F *htemp;

  while(fscanf(flist,"%s",namefile)==1){
    TFile *fin = new TFile(namefile);
    printf("file = %s\n",namefile);
    TList *l = (TList *) fin->Get("TOFpid");
    htemp = (TH1F *) l->At(0);
    if(!hcentr) hcentr = new TH1F(*htemp);
    else hcentr->Add(htemp);
    TTree *t = (TTree *) l->At(1);
    Int_t n = t->GetEntries();
    
    for(Int_t i=0;i < n;i++){
      t->GetEvent(i);

      ptPi = t->GetLeaf("ptPi")->GetValue();
      ptKa = t->GetLeaf("ptPi")->GetValue();
      ptPr = t->GetLeaf("ptPi")->GetValue();
      pt = t->GetLeaf("pt")->GetValue();
      invmass = t->GetLeaf("mass")->GetValue();
      weight1[0] = t->GetLeaf("weightPi")->GetValue(0);
      weight1[1] = t->GetLeaf("weightPi")->GetValue(1);
      weight1[2] = t->GetLeaf("weightPi")->GetValue(2);
      weight2[0] = t->GetLeaf("weightKa")->GetValue(0);
      weight2[1] = t->GetLeaf("weightKa")->GetValue(1);
      weight2[2] = t->GetLeaf("weightKa")->GetValue(2);
      weight3[0] = t->GetLeaf("weightPr")->GetValue(0);
      weight3[1] = t->GetLeaf("weightPr")->GetValue(1);
      weight3[2] = t->GetLeaf("weightPr")->GetValue(2);

      Float_t pt1 = Int_t(ptPi/(ptPi+ptKa+ptPr)*nbinPtFrPi);
      Float_t pt2 = Int_t(ptKa/(ptPi+ptKa+ptPr)*nbinPtFrKa);
      Float_t polar = 0;//TMath::Abs(polarLc.GetY());//ptComb3prong/ptot;//(pt2*nbinpol + pt1)*invpollc;
      polar = ((pt1*nbinPtFrKa + pt2 + polar)*nbinY)*normbin;

      Int_t ibinx = priorsLc[0][0][0]->GetXaxis()->FindBin(invmass);
      Int_t ibiny = priorsLc[0][0][0]->GetYaxis()->FindBin(pt);
      Int_t ibinz = priorsLc[0][0][0]->GetZaxis()->FindBin(polar);
      
      for(Int_t ipr=0;ipr<3;ipr++)
	for(Int_t jpr=0;jpr<3;jpr++)
	  for(Int_t kpr=0;kpr<3;kpr++)
	    priors3[ipr][jpr][kpr] = priorsLc[ipr][jpr][kpr]->GetBinContent(ibinx,ibiny,ibinz);
      
      GetProb3(weight1,weight2,weight3,priors3,prob3);

      for(Int_t ipr=0;ipr<3;ipr++)
	for(Int_t jpr=0;jpr<3;jpr++)
	  for(Int_t kpr=0;kpr<3;kpr++){
	    newpriorsLc[ipr][jpr][kpr]->Fill(invmass,pt,polar,prob3[ipr][jpr][kpr]);
	  }
    }
    t->Delete();
    fin->Close();

  }



  printf("Write output\n");
  fout->cd();
  hcentr->Write();
  //if(step==0) treeKs->Write();
  for(Int_t i=0;i<6;i++){
    newpriorsPt[i]->Write();
    truePt[i]->Write();
  }
  for(Int_t i=0;i<3;i++){
    for(Int_t j=0;j<3;j++){
      priorsPhi[i][j]->Write();
      newpriorsKs[i][j]->Write();
      newpriorsPhi[i][j]->Write();
      truePidKs[i][j]->Write();
      truePidPhi[i][j]->Write();
      for(Int_t k=0;k<3;k++){
       	newpriorsLc[i][j][k]->Write();
	truePidLc[i][j][k]->Write();
	newpriorsLcbar[i][j][k]->Write();
	truePidLcbar[i][j][k]->Write();
      }
    }
  }
  trueKs->Write();
  truePhi->Write();
  trueLc->Write();
  trueLcbar->Write();
  mypidLc->Write();
  mypidLcbar->Write();
  fout->Close();
}
コード例 #18
0
void AngularAcceptance(string filename)
{
  bool imposesymmetry = true;
  // Input
  TFile* file = TFile::Open(filename.c_str());
  TTree* tree = (TTree*)file->Get("DecayTree");
  int n = tree->GetEntries();
  double x[3],d;
  tree->SetBranchAddress("Phi_angle", &x[0]);
  tree->SetBranchAddress("cos_theta1",&x[1]);
  tree->SetBranchAddress("cos_theta2",&x[2]);
  // Configure and make the 3D histogram
  int nbinsx = 10;
  double xlow = imposesymmetry ? 0 : -TMath::Pi();
  double xup  = +TMath::Pi();
  double xrange = xup - xlow;
  int nbinsy = 10;
  double ylow = imposesymmetry ? 0 : -1;
  double yup  = +1;
  double yrange = yup - ylow;
  int nbinsz = 20;
  double zlow = imposesymmetry ? 0 : -1;
  double zup  = +1;
  double zrange = zup - zlow;
  // For TH3::Interpolate() to work properly, the points have to be within the centres of the edge bins
  TH3D* hist = new TH3D("hist","",nbinsx,xlow-(xrange/(nbinsx)),xup+(xrange/(nbinsx))  // Phi range
                                 ,nbinsy,ylow-(yrange/(nbinsy)),yup+(yrange/(nbinsy))  // cos_theta1 range
                                 ,nbinsz,zlow-(zrange/(nbinsz)),zup+(zrange/(nbinsz)));// cos_theta2 range
  // Fill the histogram
  cout << "Filling a 3D histogram with " << n << " events." << endl;
  for(int i = 0; i < n; i++)
  {
    tree->GetEntry(i);
    imposesymmetry ?
      hist->Fill(TMath::Abs(x[0]),TMath::Abs(x[1]),TMath::Abs(x[2]))
      :
      hist->Fill(x[0],x[1],x[2]);
  }
  // Output
  TFile* outfile = TFile::Open("AngAcc.root", "RECREATE");
  TMultiDimFit* fit = new TMultiDimFit(3, TMultiDimFit::kLegendre,"KV");
  // Configuration
  int maxpowers[3] = {2,2,6};
  fit->SetMaxPowers(maxpowers);
  fit->SetMaxFunctions(100000);
  fit->SetMaxStudy(1000000);
  fit->SetMaxTerms(30);
  fit->SetPowerLimit(1);
  fit->SetMinAngle(10);
  fit->SetMaxAngle(10);
  fit->SetMinRelativeError(.01);
  // Event loop
  for(int i = 0; i < n; i++)
  {
    tree->GetEntry(i);
    d = imposesymmetry ?
      hist->Interpolate(TMath::Abs(x[0]),TMath::Abs(x[1]),TMath::Abs(x[2]))
      :
      hist->Interpolate(x[0],x[1],x[2]);
    (i < n/2) ?
      fit->AddRow(x,d) // Training sample
      :
      fit->AddTestRow(x,d); // Test sample
  }
  // Print starting parameters
  fit->Print("p");
  // Print out the statistics
  fit->Print("s");
  // Book histograms
  fit->MakeHistograms();
  // Find the parameterization
  fit->FindParameterization();
  // Print coefficents
  fit->Print("rc");
  // Do the fit
  fit->Fit("M");
  // Print result
  fit->Print("fc");
  // Write code to file
  fit->MakeMethod("AutoAngAcc");
  hist->Write();
  outfile->Write();
  outfile->Close();
}
コード例 #19
0
ファイル: generator.cpp プロジェクト: bonventre/sxmc
std::pair<std::vector<float>, std::vector<int> >   sample_pdf(TH1* hist, long int nsamples, long int maxsamples)
{
  std::vector<float> events;
  std::vector<int> weights;


  double histint = hist->Integral();
  int totalbins = hist->GetNbinsX()*hist->GetNbinsY()*hist->GetNbinsZ();
  double maxperbin = maxsamples/(1.0*totalbins);

  std::vector<int> histweights(totalbins);
  bool weighted = false;
  if (nsamples > maxsamples){
    weighted = true;
    std::cout << "Creating weighted dataset wherever bincount > " << maxperbin<< std::endl;
    for (int i=0;i<hist->GetNbinsX();i++){
      for (int j=0;j<hist->GetNbinsY();j++){
        for (int k=0;k<hist->GetNbinsZ();k++){
          double height = hist->GetBinContent(i+1,j+1,k+1);
          if (nsamples*(height/histint) > maxperbin){
            int weight = ((nsamples*(height/histint)) / maxperbin) + 1;
            hist->SetBinContent(i+1,j+1,k+1,height/weight);
            std::cout << "Weighting bin " << i << " " << j << " " << k << " (" << k + j*hist->GetNbinsZ() + i*hist->GetNbinsY()*hist->GetNbinsZ() << ") " << ", binheight: " << height << " (" << height*histint << "), Weight: " << weight << ", now " << hist->GetBinContent(i+1,j+1,k+1) << std::endl;
            histweights[k + j*hist->GetNbinsZ() + i*hist->GetNbinsY()*hist->GetNbinsZ()] = weight;
          }else{
            histweights[k + j*hist->GetNbinsZ() + i*hist->GetNbinsY()*hist->GetNbinsZ()] = 1.0;
            //        std::cout << "Not weighting bin " << i << ", binheight: " << height << " (" << height*histint << ")" << std::endl;
          }
        }
      }
    }
  }else{
    std::cout << nsamples << " < " << maxsamples << std::endl;

  }

  int allocatesize = nsamples;
  if (weighted){
    double totalweight = 0;
    for (int i=0;i<hist->GetNbinsX();i++)
      for (int j=0;j<hist->GetNbinsY();j++)
        for (int k=0;k<hist->GetNbinsZ();k++)
          totalweight += hist->GetBinContent(i+1,j+1,k+1)*histweights[k + j*hist->GetNbinsZ() + i*hist->GetNbinsY()*hist->GetNbinsZ()];
    std::cout << "NSAMPLES: " << nsamples << ", TOTALWEIGHT: " << totalweight << std::endl;
    allocatesize = (int) (nsamples * (1.5*hist->Integral()/histint));
  }
  std::cout << "ALLOCATESIZE: " << allocatesize << std::endl;

  if (hist->IsA() == TH1D::Class()) {
    events.reserve(allocatesize);
    weights.reserve(allocatesize);
    TH1D* ht = dynamic_cast<TH1D*>(hist);

    double obs;
    long int j;
    for (j=0; j<nsamples; j++) {
      obs = ht->GetRandom();

      events.push_back(obs);

      if (weighted){
        int ibin = (hist->GetXaxis()->FindBin(obs)-1);
        weights.push_back(histweights[ibin]);
        j += histweights[ibin]-1;
      }else{
        weights.push_back(1);
      }
    }
    if (j > nsamples)
      weights.back() -= j-nsamples;
  }
  else if (hist->IsA() == TH2D::Class()) {
    events.reserve(allocatesize*2);
    weights.reserve(allocatesize);
    TH2D* ht = dynamic_cast<TH2D*>(hist);

    double obs0;
    double obs1;
    long int j;
    for (j=0; j<nsamples; j++) {
      ht->GetRandom2(obs0, obs1);

      events.push_back(obs0);
      events.push_back(obs1);

      if (weighted){
        int ibin = (hist->GetYaxis()->FindBin(obs1)-1) + (hist->GetXaxis()->FindBin(obs0)-1)*hist->GetNbinsY();
        weights.push_back(histweights[ibin]);
        j += histweights[ibin]-1;
      }else{
        weights.push_back(1);
      }
    }
    if (j > nsamples)
      weights.back() -= j-nsamples;
  }
  else if (hist->IsA() == TH3D::Class()) {
    events.reserve(allocatesize*3);
    weights.reserve(allocatesize);
    TH3D* ht = dynamic_cast<TH3D*>(hist);

    double obs0;
    double obs1;
    double obs2;
    long int j;
    for (j=0; j<nsamples; j++) {
      ht->GetRandom3(obs0, obs1, obs2);

      events.push_back(obs0);
      events.push_back(obs1);
      events.push_back(obs2);

      if (weighted){
        int ibin = (hist->GetZaxis()->FindBin(obs2)-1) + 
          (hist->GetYaxis()->FindBin(obs1)-1)*hist->GetNbinsZ() +
          (hist->GetXaxis()->FindBin(obs0)-1)*hist->GetNbinsZ()*hist->GetNbinsY();
        weights.push_back(histweights[ibin]);
        j += histweights[ibin]-1;
      }else{
        weights.push_back(1);
      }
    }
    if (j > nsamples)
      weights.back() -= j-nsamples;
  }
  else {
    std::cerr << "make_fake_dataset: Unknown histogram class: "
      << hist->ClassName() << std::endl;
    assert(false);
  }

  std::cout << "Made " << weights.size() << ", weighted to " << nsamples << std::endl;
  return std::make_pair(events,weights);
}
コード例 #20
0
int study3Dtrig(){//main


  TFile *file = TFile::Open("HLTEffParkedABCD_v1.root");

  TH3D *h[3];
  h[0] = (TH3D*)gDirectory->Get("h3DHLT_Dijet40_A");
  h[1] = (TH3D*)gDirectory->Get("h3DHLT_Dijet35_BC");
  h[2] = (TH3D*)gDirectory->Get("h3DHLT_Dijet30_D");

  std::string period[3] = {"A","BC","D"};
  std::string var[3] = {"pTj2","MET","Mjj"};

  const unsigned nC = 3*3; 
  TCanvas *myc[nC];
  for (unsigned iC(0); iC<nC;++iC){
    std::ostringstream lname,lLabel;
    lname << "myc" << iC;
    lLabel << var[iC%3] << "_run" << period[iC/3];
    myc[iC] = new TCanvas(lname.str().c_str(),lLabel.str().c_str(),1);
  }

  for (unsigned iP(0); iP<3;++iP){//periods
    if (!h[iP]) {
      std::cout << " Error, histo for period " << period[iP] << " not found. Continue..." << std::endl;
      continue;
    }
    TH3D *htmp = h[iP];
    TGraphErrors *gr1D[3][10][10];
 
    for (unsigned iV(0); iV<3; ++iV){//var

      unsigned idx = 3*iP+iV;

      std::ostringstream lLabel,lLabelBase;
      lLabelBase << var[iV] << "_run" << period[iP];
      int n1,n2;
      if (iV==0) { 
	n1 = htmp->GetNbinsY();
	n2 = htmp->GetNbinsZ(); 
      } else if (iV==1) {
	n1 = htmp->GetNbinsX();
	n2 = htmp->GetNbinsZ(); 
      } else {
	n1 = htmp->GetNbinsX();
	n2 = htmp->GetNbinsY(); 
      }

      TLegend *leg1 = new TLegend(0.85,0.2,1.,0.6);
      leg1->SetFillColor(10);
      TLegend *leg2 = new TLegend(0.85,0.6,1.,1.);
      leg2->SetFillColor(10);

      std::cout << lLabelBase.str() << ": " << n1 << "x" << n2 << " bins." << std::endl;
      double maxY = 0;
      for (unsigned iX(1); iX<htmp->GetNbinsX()+1; ++iX){
	for (unsigned iY(1); iY<htmp->GetNbinsY()+1; ++iY){
	  for (unsigned iZ(1); iZ<htmp->GetNbinsZ()+1; ++iZ){
	    unsigned i1,i2,i0;
	    double lval,lval1,lval2;
	    double lvalerr = 0;
	    std::string var1,var2;
	    if (iV==0) { 
	      i1 = iY-1; i2 = iZ-1; i0 = iX-1;
	      lval = htmp->GetXaxis()->GetBinCenter(iX);
	      lval1 = htmp->GetYaxis()->GetBinCenter(iY);
	      lval2 = htmp->GetZaxis()->GetBinCenter(iZ);
	      var1 = var[1]; var2 = var[2];
	    } else if (iV==1){
	      i1 = iX-1; i2 = iZ-1; i0 = iY-1;
	      lval = htmp->GetYaxis()->GetBinCenter(iY);
	      lval1 = htmp->GetXaxis()->GetBinCenter(iX);
	      lval2 = htmp->GetZaxis()->GetBinCenter(iZ);
	      var1 = var[0]; var2 = var[2];
	    } else {
	      i1 = iX-1; i2 = iY-1; i0 = iZ-1;
	      lval = htmp->GetZaxis()->GetBinCenter(iZ);
	      lval1 = htmp->GetXaxis()->GetBinCenter(iX);
	      lval2 = htmp->GetYaxis()->GetBinCenter(iY);
	      var1 = var[0]; var2 = var[1];
	    }

	    if (i0 == 0){
	      lLabel.str("");
	      lLabel << lLabelBase.str() << "_" << i1 << "_" << i2;
	      gr1D[iV][i1][i2] = new TGraphErrors();
	      gr1D[iV][i1][i2]->SetName(lLabel.str().c_str());
	      gr1D[iV][i1][i2]->SetMarkerStyle(20+i1);
	      gr1D[iV][i1][i2]->SetMarkerColor(1+i2);
	      gr1D[iV][i1][i2]->SetLineColor(1+i2);
	      if (i2==0){
		lLabel.str("");
		lLabel << var1 << "=" << lval1;
		leg1->AddEntry(gr1D[iV][i1][i2],lLabel.str().c_str(),"P");
	      }
	      if (i1==0){
		lLabel.str("");
		lLabel << var2 << "=" << lval2;
		leg2->AddEntry(gr1D[iV][i1][i2],lLabel.str().c_str(),"P");
	      }
	    }
	    if (htmp->GetBinContent(iX,iY,iZ)>maxY) maxY = htmp->GetBinContent(iX,iY,iZ);
	    gr1D[iV][i1][i2]->SetPoint(i0,lval,htmp->GetBinContent(iX,iY,iZ));
	    gr1D[iV][i1][i2]->SetPointError(i0,lvalerr,htmp->GetBinError(iX,iY,iZ));
	  }
	}
      }


      myc[idx]->cd();
      for (unsigned i1(0); i1<n1; ++i1){
	for (unsigned i2(0); i2<n2; ++i2){
	  gr1D[iV][i1][i2]->SetMaximum(maxY);
	  gr1D[iV][i1][i2]->GetXaxis()->SetTitle(var[iV].c_str());
	  gr1D[iV][i1][i2]->GetYaxis()->SetTitle("#varepsilon_{trig}");
	  if (i1==0 && i2 == 0) gr1D[iV][i1][i2]->Draw("APL");
	  else gr1D[iV][i1][i2]->Draw("PL");
	}
      }
      leg1->Draw("same");
      leg2->Draw("same");
      myc[idx]->Update();
      TString lname;
      lname = "PLOTS/"+lLabelBase.str();
      myc[idx]->Print(lname+".pdf");
      myc[idx]->Print(lname+".png");


    }//var
  }//period




  return 0;
}//main
コード例 #21
0
void EcalShape::Loop()
{
//   In a ROOT session, you can do:
//      Root > .L EcalShape.C
//      Root > EcalShape t
//      Root > t.GetEntry(12); // Fill t data members with entry number 12
//      Root > t.Show();       // Show values of entry 12
//      Root > t.Show(16);     // Read and show values of entry 16
//      Root > t.Loop();       // Loop on all entries
//

//     This is the loop skeleton where:
//    jentry is the global entry number in the chain
//    ientry is the entry number in the current Tree
//  Note that the argument to GetEntry must be:
//    jentry for TChain::GetEntry
//    ientry for TTree::GetEntry and TBranch::GetEntry
//
//       To read only selected branches, Insert statements like:
// METHOD1:
//    fChain->SetBranchStatus("*",0);  // disable all branches
//    fChain->SetBranchStatus("branchname",1);  // activate branchname
// METHOD2: replace line
//    fChain->GetEntry(jentry);       //read all branches
//by  b_branchname->GetEntry(ientry); //read only this branch
   if (fChain == 0) return;

   Long64_t nentries = fChain->GetEntriesFast();

   TH3D * timing = new TH3D("timing", "Timing TP data", 72, 1, 73, 56, -28, 28, 10, 0.5, 10.5) ;
   timing->GetYaxis()->SetTitle("eta index") ;
   timing->GetXaxis()->SetTitle("phi index") ;
   TH2D * timing2D = new TH2D("timing2D", "Timing TP data", 72, 1, 73, 56, -28, 28) ;
   timing2D->GetYaxis()->SetTitle("eta index") ;
   timing2D->GetXaxis()->SetTitle("phi index") ;
   TH1D * timing1D = new TH1D("timing1D", "Timing TP data", 10, 0.5, 10.5) ;
  
   bool display(true) ;

   Long64_t nbytes = 0, nb = 0;
   for (Long64_t jentry=0; jentry<nentries;jentry++) {
      Long64_t ientry = LoadTree(jentry);
      if (ientry < 0) break;
      nb = fChain->GetEntry(jentry);   nbytes += nb;

      if (display) {
	stringstream ss ;
	ss<<"ieta="<<ieta<<", iphi="<<iphi<<", evt="<<evtNb ;
	pulse = new TH1F("pulse", ss.str().c_str(), 10, 0, 10) ;
	int max = 0 ;
	int min = 999999999 ;
	for (int i=0 ; i<10 ; i ++) {
	  pulse->Fill(i, samp[i]) ;
	  if (samp[i]<min) min = samp[i] ;
	  if (samp[i]>max) max = samp[i] ;
	}
	pulse->Draw() ;
	int pause ;
	c1->Update() ;
	cin >> pause ;
	if (pause==0) break ;
      }
      delete pulse ;

      int max = 0 ;
      float time = 0 ;
      for (int i=0 ; i<10 ; i ++) {
	if (samp[i]>max) {
	  max = samp[i] ;
	  time = i+1 ;
	}
      }
      timing->Fill(iphi, ieta, time) ;
      timing1D->Fill(time) ;
   }


   for (int binx=1 ; binx<=72 ; binx++)    
     for (int biny=1 ; biny<=56 ; biny++) {
       double t = 0. ;
       int nbTime(0) ;
       for (int binz=1; binz<=10 ; binz++) {   
	 int content = timing->GetBinContent(binx, biny, binz) ;
	 if (content>0) {
	   cout<<binx<<" "<<biny<<" "<<binz<<" "<<content<<endl; 
	   t += content*binz ;
	   nbTime += content ;
	 }
       }
       if (nbTime>0) {
	 t /= nbTime ;
	 cout<<t<<endl ;
	 timing2D->SetBinContent(binx, biny, t) ;
       }
     }
}
コード例 #22
0
int ScanChain( TChain* chain, bool fast = true, int nEvents = -1, string skimFilePrefix = "test") {

  //load PUweights
  TFile *fPU = new TFile("puWeights.root","READ");
  TH1D *puWeight     = (TH1D*)fPU->Get("puWeight");
  TH1D *puWeightUp   = (TH1D*)fPU->Get("puWeightUp");
  TH1D *puWeightDown = (TH1D*)fPU->Get("puWeightDown");

  TFile *fxsec = new TFile("xsec_stop_13TeV.root","READ");
  TH1D *hxsec     = (TH1D*)fxsec->Get("stop");

  TFile *f_el_SF       = new TFile("lepsf/kinematicBinSFele.root", "read");
  TFile *f_mu_SF_id    = new TFile("lepsf/TnP_MuonID_NUM_MediumID_DENOM_generalTracks_VAR_map_pt_eta.root", "read");
  TFile *f_mu_SF_iso   = new TFile("lepsf/TnP_MuonID_NUM_MiniIsoTight_DENOM_LooseID_VAR_map_pt_eta.root");
  TFile *f_mu_SF_veto_id  = new TFile("lepsf/TnP_MuonID_NUM_LooseID_DENOM_generalTracks_VAR_map_pt_eta.root", "read");
  TFile *f_mu_SF_veto_iso = new TFile("lepsf/TnP_MuonID_NUM_MiniIsoTight_DENOM_LooseID_VAR_map_pt_eta.root");
  //TFile *f_mu_SF_veto_iso = new TFile("lepsf/TnP_MuonID_NUM_MiniIsoLoose_DENOM_LooseID_VAR_map_pt_eta.root");
  //TFile *f_vetoLep_eff = new TFile("lepsf/lepeff__ttbar_powheg_pythia8_25ns.root", "read");
  TFile *f_vetoLep_eff = new TFile("lepsf/lepeff__ttbar_powheg_pythia8_25ns__SRcuts.root", "read");  
  TH2D *h_el_SF_id_temp      = (TH2D*)f_el_SF->Get("CutBasedMedium");
  TH2D *h_el_SF_iso_temp     = (TH2D*)f_el_SF->Get("MiniIso0p1_vs_AbsEta");
  TH2D *h_el_SF_veto_id_temp  = (TH2D*)f_el_SF->Get("CutBasedVeto");
  TH2D *h_el_SF_veto_iso_temp = (TH2D*)f_el_SF->Get("MiniIso0p4_vs_AbsEta");
  TH2D *h_mu_SF_id_temp      = (TH2D*)f_mu_SF_id->Get("pt_abseta_PLOT_pair_probeMultiplicity_bin0_&_tag_combRelIsoPF04dBeta_bin0_&_tag_pt_bin0_&_tag_IsoMu20_pass");
  TH2D *h_mu_SF_iso_temp     = (TH2D*)f_mu_SF_iso->Get("pt_abseta_PLOT_pair_probeMultiplicity_bin0_&_tag_combRelIsoPF04dBeta_bin0_&_tag_pt_bin0_&_PF_pass_&_tag_IsoMu20_pass");
  TH2D *h_mu_SF_veto_id_temp  = (TH2D*)f_mu_SF_veto_id->Get("pt_abseta_PLOT_pair_probeMultiplicity_bin0_&_tag_combRelIsoPF04dBeta_bin0_&_tag_pt_bin0_&_tag_IsoMu20_pass");
  TH2D *h_mu_SF_veto_iso_temp = (TH2D*)f_mu_SF_veto_iso->Get("pt_abseta_PLOT_pair_probeMultiplicity_bin0_&_tag_combRelIsoPF04dBeta_bin0_&_tag_pt_bin0_&_PF_pass_&_tag_IsoMu20_pass");
  //TH2D *h_el_vetoLepEff_temp = (TH2D*)f_vetoLep_eff->Get("h2_lepEff_vetoSel_Eff_el");
  //TH2D *h_mu_vetoLepEff_temp = (TH2D*)f_vetoLep_eff->Get("h2_lepEff_vetoSel_Eff_mu");
  TH2D *h_el_vetoLepEff_temp = (TH2D*)f_vetoLep_eff->Get("h2_lepEff_vetoSel_rebin_Eff_el");
  TH2D *h_mu_vetoLepEff_temp = (TH2D*)f_vetoLep_eff->Get("h2_lepEff_vetoSel_rebin_Eff_mu");
  TH2D *h_el_SF_id  = (TH2D*)h_el_SF_id_temp->Clone("h_el_SF_id");
  TH2D *h_el_SF_iso = (TH2D*)h_el_SF_iso_temp->Clone("h_el_SF_iso");
  TH2D *h_mu_SF_id  = (TH2D*)h_mu_SF_id_temp->Clone("h_mu_SF_id");
  TH2D *h_mu_SF_iso = (TH2D*)h_mu_SF_iso_temp->Clone("h_mu_SF_iso");
  TH2D *h_el_SF_veto_id  = (TH2D*)h_el_SF_veto_id_temp->Clone("h_el_SF_veto_id");
  TH2D *h_el_SF_veto_iso = (TH2D*)h_el_SF_veto_iso_temp->Clone("h_el_SF_veto_iso");
  TH2D *h_mu_SF_veto_id  = (TH2D*)h_mu_SF_veto_id_temp->Clone("h_mu_SF_veto_id");
  TH2D *h_mu_SF_veto_iso = (TH2D*)h_mu_SF_veto_iso_temp->Clone("h_mu_SF_veto_iso");
  //This is are the important ones
  TH2D *h_el_vetoLepEff = (TH2D*)h_el_vetoLepEff_temp->Clone("h_el_vetoLepEff");
  TH2D *h_mu_vetoLepEff = (TH2D*)h_mu_vetoLepEff_temp->Clone("h_mu_vetoLepEff");
  TH2D *h_el_SF = (TH2D*)h_el_SF_id->Clone("h_el_SF");
  h_el_SF->Multiply(h_el_SF_iso);
  TH2D *h_el_SF_veto = (TH2D*)h_el_SF_veto_id->Clone("h_el_SF_veto");
  TH2D *h_mu_SF = (TH2D*)h_mu_SF_id->Clone("h_mu_SF");
  h_mu_SF->Multiply(h_mu_SF_iso);
  TH2D *h_mu_SF_veto = (TH2D*)h_mu_SF_veto_id->Clone("h_mu_SF_veto");
  h_mu_SF_veto->Multiply(h_mu_SF_veto_iso);
  TFile *f_el_FS_ID       = new TFile("lepsf/sf_el_mediumCB.root", "read");
  TFile *f_el_FS_Iso      = new TFile("lepsf/sf_el_mini01.root", "read");
  TFile *f_mu_FS_ID       = new TFile("lepsf/sf_mu_mediumID.root", "read");
  TFile *f_mu_FS_Iso      = new TFile("lepsf/sf_mu_mini02.root", "read");
  TH2D *h_el_FS_ID_temp  = (TH2D*)f_el_FS_ID ->Get("histo2D");
  //TH2D *h_el_FS_ID       = (TH2D*)h_el_FS_ID_temp ->Clone("h_el_FS_ID");
  TH2D *h_el_FS          = (TH2D*)h_el_FS_ID_temp ->Clone("h_el_FS");
  TH2D *h_el_FS_Iso_temp = (TH2D*)f_el_FS_Iso->Get("histo2D");
  //TH2D *h_el_FS_Iso      = (TH2D*)h_el_FS_Iso_temp->Clone("h_el_FS_Iso");
  h_el_FS->Multiply(h_el_FS_Iso_temp);
  TH2D *h_mu_FS_ID_temp  = (TH2D*)f_mu_FS_ID ->Get("histo2D");
  //TH2D *h_mu_FS_ID       = (TH2D*)h_mu_FS_ID_temp ->Clone("h_mu_FS_ID");
  TH2D *h_mu_FS          = (TH2D*)h_mu_FS_ID_temp ->Clone("h_mu_FS");
  TH2D *h_mu_FS_Iso_temp = (TH2D*)f_mu_FS_Iso->Get("histo2D");
  //TH2D *h_mu_FS_Iso      = (TH2D*)h_mu_FS_Iso_temp->Clone("h_mu_FS_ID");
  h_mu_FS->Multiply(h_mu_FS_Iso_temp);

  
  // Benchmark
  TBenchmark *bmark = new TBenchmark();
  bmark->Start("benchmark");

  // Example Histograms
  TDirectory *rootdir = gDirectory->GetDirectory("Rint:");


  map<string, TH3D*> histos;//use D histos as weights can vary a lot among the signal
  vector<string> histonames; histonames.clear();
  //  vector<int> hbins; hbins.clear();
  //  vector<float> hlow; hlow.clear();
  //  vector<float> hup; hup.clear();

  //lumi, trigger, stats done
  histonames.push_back("SRyield");
  histonames.push_back("SR_Bup_HF");//done
  histonames.push_back("SR_Bdown_HF");
  histonames.push_back("SR_Bup_LF");//done
  histonames.push_back("SR_Bdown_LF");
  histonames.push_back("SR_JESup");
  histonames.push_back("SR_JESdown");
  histonames.push_back("SR_muRFup");
  histonames.push_back("SR_muRFdown");
  //histonames.push_back("SR_PDFup");
  //histonames.push_back("SR_PDFdown");
  histonames.push_back("SR_ISRup");//done preliminary
  histonames.push_back("SR_ISRdown");
  histonames.push_back("SR_PUup");//done preliminary
  histonames.push_back("SR_PUdown");
  histonames.push_back("SR_LepEffup");//done - I guess we need no renormalization - no fastsim in, no vetoSF
  histonames.push_back("SR_LepEffdown");
  histonames.push_back("SR_LepEffFSup");//done - I guess we need no renormalization - no fastsim in, no vetoSF
  histonames.push_back("SR_LepEffFSdown");
  histonames.push_back("SR_Xsecup");//done
  histonames.push_back("SR_Xsecdown");
  histonames.push_back("CR1l_sigcontamination");//scaled to signalreg yield
  histonames.push_back("CR2l_sigcontamination");//scaled to signalreg yield
  /*
  histonames.push_back("eventsum");
  histonames.push_back("rawweightsum");
  histonames.push_back("totweightsum");
  histonames.push_back("ISRsum");
  histonames.push_back("BSFsum");
  histonames.push_back("PUweightsum");
  histonames.push_back("xsecsum");
  histonames.push_back("nevtsum");
  histonames.push_back("lepsum");
  histonames.push_back("lepSFsum");
  */
  for(unsigned int i = 0; i<histonames.size(); ++i){
    string mapname = histonames[i];
    if(histos.count(mapname) == 0 ) histos[mapname] = new TH3D(mapname.c_str(), "", 37,99,1024, 19,-1,474, 13, -0.5,12.5);
    //mStop 100-1000, mLSP 0-450, SR 1-12, 9200 bins, SR 0 is non-SR - in case it it needed!!
      histos[mapname]->Sumw2(); histos[mapname]->SetDirectory(rootdir);
    }

  
  
  // Loop over events to Analyze
  unsigned int nEventsTotal = 0;
  unsigned int nEventsChain = chain->GetEntries();
  if( nEvents >= 0 ) nEventsChain = nEvents;
  TObjArray *listOfFiles = chain->GetListOfFiles();
  TIter fileIter(listOfFiles);
  TFile *currentFile = 0;

  //get the reweighting histograms
  TIter fileIterFirst(listOfFiles);
  TFile *currentFileFirst = 0;
  TH3D* counterhistSig;
  TH2F* histNEvts;
  bool thisisfirst = true;
  // File Loop for adding correct histograms
  while ( (currentFileFirst = (TFile*)fileIterFirst.Next()) ) {
    TFile *file = new TFile( currentFileFirst->GetTitle() );
    file->cd();
    if(thisisfirst){
      counterhistSig = (TH3D*)file->Get("h_counterSMS");
      counterhistSig->SetDirectory(0); 
      histNEvts = (TH2F*)file->Get("histNEvts");
      histNEvts->SetDirectory(0);
      thisisfirst = false;
    } else {
      TH3D *tempcounterhistSig = (TH3D*)file->Get("h_counterSMS");
      tempcounterhistSig->SetDirectory(0); 
      TH2F *temphistNEvts = (TH2F*)file->Get("histNEvts");
      temphistNEvts->SetDirectory(0);
      counterhistSig->Add(tempcounterhistSig);
      histNEvts->Add(temphistNEvts);
      tempcounterhistSig->Delete();
      temphistNEvts->Delete();
    }
    file->Close();
    delete file;
  }

  // File Loop
  while ( (currentFile = (TFile*)fileIter.Next()) ) {

    // Get File Content
    TFile *file = new TFile( currentFile->GetTitle() );
    TTree *tree = (TTree*)file->Get("t");
    if(fast) TTreeCache::SetLearnEntries(10);
    if(fast) tree->SetCacheSize(128*1024*1024);
    cms3.Init(tree);
    
    // Loop over Events in current file
    if( nEventsTotal >= nEventsChain ) continue;
    unsigned int nEventsTree = tree->GetEntriesFast();
    for( unsigned int event = 0; event < nEventsTree; ++event) {
 
      // Get Event Content
      if( nEventsTotal >= nEventsChain ) continue;
      if(fast) tree->LoadTree(event);
      cms3.GetEntry(event);
      ++nEventsTotal;
    
      // Progress
      CMS3::progress( nEventsTotal, nEventsChain );

      // Analysis Code

      float mStop = mass_stop();
      float mLSP = mass_lsp();
      float mCharg = mass_chargino();
      //float xVal = mass_lsp();
      int Nevts = histNEvts->GetBinContent(histNEvts->FindBin(mStop,mLSP));
      double nevts = double(Nevts);
      //float weight = cms3.scale1fb()*2.11;
      double PUweight     = puWeight    ->GetBinContent(puWeight    ->FindBin(pu_ntrue() ) );
      double PUweightUp   = puWeightUp  ->GetBinContent(puWeightUp  ->FindBin(pu_ntrue() ) );
      double PUweightDown = puWeightDown->GetBinContent(puWeightDown->FindBin(pu_ntrue() ) );
      PUweightUp = 1; PUweightDown = PUweight; PUweight = 1; //now PU syst is applying vs not applying
     double ISRnorm = counterhistSig->GetBinContent(counterhistSig->FindBin(mStop,mLSP,19));
      double ISRnormup = counterhistSig->GetBinContent(counterhistSig->FindBin(mStop,mLSP,20));
      double ISRnormdown = counterhistSig->GetBinContent(counterhistSig->FindBin(mStop,mLSP,21));
      double ISRweight = weight_ISR();
      double BSFnorm = counterhistSig->GetBinContent(counterhistSig->FindBin(mStop,mLSP,14));
      double BSFnormHup = counterhistSig->GetBinContent(counterhistSig->FindBin(mStop,mLSP,15));
      double BSFnormLup = counterhistSig->GetBinContent(counterhistSig->FindBin(mStop,mLSP,16));
      double BSFnormHdown = counterhistSig->GetBinContent(counterhistSig->FindBin(mStop,mLSP,17));
      double BSFnormLdown = counterhistSig->GetBinContent(counterhistSig->FindBin(mStop,mLSP,18));
      double BSFweight = weight_btagsf();
      double muRFnorm = counterhistSig->GetBinContent(counterhistSig->FindBin(mStop,mLSP,1));
      double muRFnormup = counterhistSig->GetBinContent(counterhistSig->FindBin(mStop,mLSP,5));
      double muRFnormdown = counterhistSig->GetBinContent(counterhistSig->FindBin(mStop,mLSP,9));
      if(ISRnorm>0) ISRweight*=nevts/ISRnorm;
      if(ISRnorm<=0||ISRnormup<=0||ISRnormdown<=0){ ISRnormdown=1.; ISRnormup=1.; ISRnorm=1.;}
      if(ISRweight!=weight_ISR()) cout << "ISRw " << ISRweight << " wISR " << weight_ISR() << " nevts " << nevts << " ISRn " << ISRnorm << endl;
      if(BSFnorm>0) BSFweight *=nevts/BSFnorm;
      if(BSFnorm<=0||BSFnormHup<=0||BSFnormLup<=0||BSFnormHdown<=0||BSFnormLdown<=0){
	BSFnorm=1; BSFnormHup=1; BSFnormLup=1; BSFnormHdown=1; BSFnormLdown=1;
      }
      if(muRFnorm<=0||muRFnormup<=0||muRFnormdown<=0){ muRFnormdown=1; muRFnormup=1; muRFnorm=1; }
      //lepSF is done below
      double xsection = hxsec->GetBinContent(hxsec->FindBin(mStop));
      double xsectionerr = hxsec->GetBinError(hxsec->FindBin(mStop));
      //double rawweight = xsec()*2260./nevts;
      //double weight = xsec()*2260./nevts*PUweight*ISRweight*BSFweight;//xsec given in pb
      double rawweight = xsection*2260./nevts;
      double weight = xsection*2260./nevts*PUweight*ISRweight*BSFweight;//xsec given in pb
      //did put ISRweight which should be ==1
      if(ISRweight!=1) cout << "ISRw " << ISRweight << endl;
      if(event==0) cout << "weight " << weight << " nEvents " << nEventsTree << " filename " << currentFile->GetTitle() << endl;

      int NSLeps = 0;
      int NAddVetoLeps = 0;
      if(lep1_is_mu()){
	if(lep1_pt()>20&&fabs(lep1_eta())<2.4) {++NSLeps;}
      } else if (lep1_is_el()){
	if(lep1_pt()>20&&fabs(lep1_eta())<1.4442) {++NSLeps; }
      } if(lep2_is_mu()){
	if(lep2_pt()>20&&fabs(lep2_eta())<2.4) {++NSLeps;}
      } else if (lep2_is_el()){
	if(lep2_pt()>20&&fabs(lep2_eta())<1.4442) {++NSLeps; }
      }
      if(lep2_is_mu()){
	if(lep2_pt()>10&&fabs(lep2_eta())<2.4) {++NAddVetoLeps;}
      } else if (lep2_is_el()){
	if(lep2_pt()>10&&fabs(lep2_eta())<2.4) {++NAddVetoLeps; }
      }
      if(NSLeps<1) continue;//temp
      float lepSF_pt_cutoff = 100.0;
      float lepSF_pt_min    = 10.0;
      double lepSF    = 1.0;
      double lepSF_Up = 1.0;
      double lepSF_Dn = 1.0;
      float lepSF_FS_pt_cutoff = 200.0;
      double lepSF_FS    = 1.0;
      double lepSF_FS_Up = 1.0;
      double lepSF_FS_Dn = 1.0;	
      if(lep1_is_el()){
	int binX = h_el_SF->GetXaxis()->FindBin( std::min(lepSF_pt_cutoff, (float)lep1_p4().Pt()) );
	int binY = h_el_SF->GetYaxis()->FindBin( fabs(lep1_p4().Eta()) );
	lepSF    = h_el_SF->GetBinContent( binX, binY );
	lepSF_Up = lepSF + h_el_SF->GetBinError( binX, binY );
	lepSF_Dn = lepSF - h_el_SF->GetBinError( binX, binY );
	int bin = h_el_FS->FindBin(  std::min(lepSF_FS_pt_cutoff, (float)lep1_p4().Pt()), fabs(lep1_p4().Eta()) );
	lepSF_FS = h_el_FS->GetBinContent(bin);
	lepSF_FS_Up = lepSF_FS + h_el_FS->GetBinError(bin);
	lepSF_FS_Dn = lepSF_FS + h_el_FS->GetBinError(bin);
      }
      if(lep1_is_mu()){
	int binX = h_mu_SF->GetXaxis()->FindBin( std::min(lepSF_pt_cutoff, (float)lep1_p4().Pt()) );
	int binY = h_mu_SF->GetYaxis()->FindBin( fabs(lep1_p4().Eta()) );
	lepSF    = h_mu_SF->GetBinContent( binX, binY );
	lepSF_Up = lepSF + h_mu_SF->GetBinError( binX, binY );
	lepSF_Dn = lepSF - h_mu_SF->GetBinError( binX, binY );
	int bin = h_mu_FS->FindBin(  std::min(lepSF_FS_pt_cutoff, (float)lep1_p4().Pt()), fabs(lep1_p4().Eta()) );
	lepSF_FS = h_mu_FS->GetBinContent(bin);
	lepSF_FS_Up = lepSF_FS + h_mu_FS->GetBinError(bin);
	lepSF_FS_Dn = lepSF_FS + h_mu_FS->GetBinError(bin);
      }
      weight *= (lepSF*lepSF_FS);

      
      if(nvtxs()<0)               continue;
      if(ngoodleps()<1)           continue;//accomodate 2l-CR
      if(nvetoleps()<1)           continue;//accomodate 2l-CR
    //if(!PassTrackVeto_v3())     continue;//accomodate 2l-CR
    //if(!PassTauVeto())          continue;//accomodate 2l-CR
      if(ngoodjets()<2)           continue;
      if(ngoodbtags()<0)          continue;//accomodate 1l-CR
      if(pfmet()<250)             continue;
      if(mt_met_lep()<150)        continue;
      if(mindphi_met_j1_j2()<0.8) continue;


      int SR = -1;
      int compressedSR = -1;
      if(ngoodleps()==1&&nvetoleps()==1&&PassTrackVeto_v3()&&PassTauVeto()&&ngoodbtags()>=1){//basis for SR 1l, >=1b
	if(ngoodjets()>=4){
	  if(MT2W()<=200){
	    if(pfmet()>325) SR = 2;
	    else SR = 1;
	  } else { //high MT2W
	    if(pfmet()>450) SR = 5;
	    else if(pfmet()>350) SR = 4;
	    else SR = 3;
	  }
	} else if(ngoodjets()==3 && MT2W()>200 && pfmet()>350) {
	  SR = 6;
	} else if(MT2W()>200&&topnessMod()>(-3)) { //2 or 3 jets
	  if(ngoodbtags()==1){
	    if(pfmet()>400) SR = 8;
	    else SR = 7;
	  } else {//ge2 jets
	    if(pfmet()>400) SR = 10;
	    else SR = 9;
	  }
	}
	//compressed region (jets are sorted by pt
	if(ngoodjets()>=5&&ak4pfjets_passMEDbtag()[0]==false&&ak4pfjets_pt()[0]>200.){
	  if(MT2W()<=200) compressedSR = 11;
	  else compressedSR = 12;
	}
      }

      //CR-1l
      int CR1l = -1;
      if(ngoodleps()==1&&nvetoleps()==1&&PassTrackVeto_v3()&&PassTauVeto()&&ngoodbtags()==0&&ngoodjets()>=3&&MT2W()>200){
	if(ngoodjets()==3){
	  CR1l = 1;
	} else {
	  CR1l = 2;
	}
      }
      //CR1l  1 --> SR  6
      //CR1l  2 --> SR  3-5
      float CR1l_1_6 = 0.37*0.18;
      float CR1l_2_3 = 0.55*0.15;
      float CR1l_2_4 = 0.25*0.29;
      float CR1l_2_5 = 0.20*0.40;

      //CR2l = -1;
      int lepind = -1;
      if(ngoodleps()>=2&&NSLeps==2) lepind = 5;
      else if(ngoodleps()==2&&NSLeps==2) lepind = 4;//exactly two leptons,CR4
      else if(ngoodleps()==1&&NSLeps==1&&NAddVetoLeps>=1) lepind = 3;//one lepton, but more than 1 add. loose,1l,>2l
      //else if(ngoodleps()==1&&NSLeps==1&&nvetoleps()==2) lepind = 2;//one lepton + 1 add. loose,CR5
      else if(ngoodleps()==1&&NSLeps==1&&nvetoleps()==0&&(!PassTrackVeto_v3()||!PassTauVeto())) lepind = 1;//exactly one lepton, but do not pass track/tau veto - i.e. one additional track or tau, CR6
      int CR2l = -1;
      if((lepind==4||lepind==3||lepind==1)&&ngoodjets()>=3&&ngoodbtags()>=1){
	if(MT2W()<=200) CR2l = 1;
	else CR2l = 2;
      }
      float CR2l_1_1 = 0.61*0.48;
      float CR2l_1_2 = 0.61*0.19;
      float CR2l_2_3 = 0.44*0.39;
      float CR2l_2_4 = 0.44*0.11;
      float CR2l_2_5 = 0.44*0.07;
      float CR2l_2_6 = 0.44*0.11;

      if(SR==(-1)&&CR1l==(-1)&&CR2l==(-1)&&compressedSR==(-1)) continue;
      //implement some sanity checks
      if(CR1l!=(-1)&&CR2l!=(-1)) cout << "WTF CR1l " << CR1l << " CR2l " << CR2l << endl;
      if(SR!=(-1)&&CR1l!=(-1)) cout << "WTF SR " << SR << " CR1l " << CR1l << endl;
      if(SR!=(-1)&&CR2l!=(-1)) cout << "WTF SR " << SR << " CR2l " << CR2l << endl;

      //ISR reweighting, get stop pair using last copy:
      double ISRup = weight_ISRup()/weight_ISR()*ISRnorm/ISRnormup;
      double ISRdown = weight_ISRdown()/weight_ISR()*ISRnorm/ISRnormdown;
      //double XSup = (xsec()+xsec_uncert())/xsec();
      //double XSdown = (xsec()-xsec_uncert())/xsec();
      double XSup = (xsection+xsectionerr)/xsection;
      double XSdown = (xsection-xsectionerr)/xsection;
      double PUup = PUweightUp/PUweight;
      double PUdown = PUweightDown/PUweight;
      double lEffup = lepSF_Up/lepSF;
      double lEffdown = lepSF_Dn/lepSF;
      double lEffFSup = lepSF_FS_Up/lepSF_FS;
      double lEffFSdown = lepSF_FS_Dn/lepSF_FS;
      double BSFHup = weight_btagsf_heavy_UP()/weight_btagsf()*BSFnorm/BSFnormHup;
      double BSFLup = weight_btagsf_light_UP()/weight_btagsf()*BSFnorm/BSFnormHup;
      double BSFHdown = weight_btagsf_heavy_DN()/weight_btagsf()*BSFnorm/BSFnormHup;
      double BSFLdown = weight_btagsf_light_DN()/weight_btagsf()*BSFnorm/BSFnormHup;
      double muRFup = genweights().at(4)/genweights().at(0)*muRFnorm/muRFnormup;
      double muRFdown = genweights().at(8)/genweights().at(0)*muRFnorm/muRFnormdown;
      //cout << genweights().at(0) << " " << genweights().at(4) << " " << genweights().at(8) << " " << mStop << " " << mLSP << endl;

      if(CR1l>0){
	if(ngoodleps()!=1) cout << __LINE__ << " " << ngoodleps() << endl;
	if(NSLeps!=1) cout << __LINE__ << " " << NSLeps << endl;
	if(nvetoleps()!=1) cout << __LINE__ << " " << nvetoleps() << endl;
	if(ngoodbtags()>=1) cout << __LINE__ << " " << ngoodbtags() << endl;
	//signal contamination in 0b control region, do correlations later during datacard making
	if(CR1l==1){
	  histos["CR1l_sigcontamination"]->Fill(mStop,mLSP,6,weight*CR1l_1_6);
	} else if(CR1l==2){
	  histos["CR1l_sigcontamination"]->Fill(mStop,mLSP,3,weight*CR1l_2_3);
	  histos["CR1l_sigcontamination"]->Fill(mStop,mLSP,4,weight*CR1l_2_4);
	  histos["CR1l_sigcontamination"]->Fill(mStop,mLSP,5,weight*CR1l_2_5);
	}
      } else if(CR2l>0){
	if(nvetoleps()<=1||(nvetoleps()==1&&(!PassTrackVeto_v3()||!PassTauVeto()))) cout << __LINE__ << " " << nvetoleps() << " " << PassTrackVeto_v3() << " " << PassTauVeto() << endl;
	if(ngoodbtags()<1) cout << __LINE__ << " " << ngoodbtags() << endl;
	//signal contamination in 2l control region, do correlations later during datacard making
	if(CR2l==1){
	  histos["CR2l_sigcontamination"]->Fill(mStop,mLSP,1,weight*CR2l_1_1);
	  histos["CR2l_sigcontamination"]->Fill(mStop,mLSP,2,weight*CR2l_1_2);
	} else if(CR2l==2){
	  histos["CR2l_sigcontamination"]->Fill(mStop,mLSP,3,weight*CR2l_2_3);
	  histos["CR2l_sigcontamination"]->Fill(mStop,mLSP,4,weight*CR2l_2_4);
	  histos["CR2l_sigcontamination"]->Fill(mStop,mLSP,5,weight*CR2l_2_5);
	  histos["CR2l_sigcontamination"]->Fill(mStop,mLSP,6,weight*CR2l_2_6);

	}
      } else if(SR>0){
	if(ngoodleps()!=1) cout << __LINE__ << " " << ngoodleps() << endl;
	if(NSLeps!=1) cout << __LINE__ << " " << NSLeps << endl;
	if(nvetoleps()!=1) cout << __LINE__ << " " << nvetoleps() << endl;
	if(!PassTrackVeto_v3())  cout << __LINE__ << endl;
	if(!PassTauVeto())  cout << __LINE__ << endl;
	if(SR<=6&&ngoodjets()<3) cout << __LINE__ << " " << ngoodjets() << endl;
	if(ngoodbtags()<1) cout << __LINE__ << " " << ngoodbtags() << endl;
	/*
	histos["eventsum"]->Fill(mStop,mLSP,SR,1.);
	histos["rawweightsum"]->Fill(mStop,mLSP,SR,rawweight);
	histos["totweightsum"]->Fill(mStop,mLSP,SR,weight);
	histos["ISRsum"]->Fill(mStop,mLSP,SR,ISRweight);
	histos["BSFsum"]->Fill(mStop,mLSP,SR,BSFweight);
	histos["PUweightsum"]->Fill(mStop,mLSP,SR,PUweight);
	histos["xsecsum"]->Fill(mStop,mLSP,SR,xsection);
	histos["nevtsum"]->Fill(mStop,mLSP,SR,nevts);
	histos["lepsum"]->Fill(mStop,mLSP,SR,lepSF);
	histos["lepSFsum"]->Fill(mStop,mLSP,SR,lepSF_FS);
	*/
	//finally - do signal regions!
	histos["SRyield"]->Fill(mStop,mLSP,SR,weight);
	histos["SR_ISRup"]->Fill(mStop,mLSP,SR,weight*ISRup);
	histos["SR_ISRdown"]->Fill(mStop,mLSP,SR,weight*ISRdown);
	histos["SR_Xsecup"]->Fill(mStop,mLSP,SR,weight*XSup);
	histos["SR_Xsecdown"]->Fill(mStop,mLSP,SR,weight*XSdown);
	histos["SR_PUup"]->Fill(mStop,mLSP,SR,weight*PUup);
	histos["SR_PUdown"]->Fill(mStop,mLSP,SR,weight*PUdown);
	histos["SR_Bup_HF"]->Fill(mStop,mLSP,SR,weight*BSFHup);
	histos["SR_Bup_LF"]->Fill(mStop,mLSP,SR,weight*BSFLup);
	histos["SR_Bdown_HF"]->Fill(mStop,mLSP,SR,weight*BSFHdown);
	histos["SR_Bdown_LF"]->Fill(mStop,mLSP,SR,weight*BSFLdown);
	histos["SR_LepEffup"]->Fill(mStop,mLSP,SR,weight*lEffup);
	histos["SR_LepEffdown"]->Fill(mStop,mLSP,SR,weight*lEffdown);
	histos["SR_LepEffFSup"]->Fill(mStop,mLSP,SR,weight*lEffFSup);
	histos["SR_LepEffFSdown"]->Fill(mStop,mLSP,SR,weight*lEffFSdown);
	histos["SR_muRFup"]->Fill(mStop,mLSP,SR,weight*muRFup);
	histos["SR_muRFdown"]->Fill(mStop,mLSP,SR,weight*muRFdown);
      }
      if(compressedSR>0){
	if(compressedSR<=6) cout << __LINE__ << " " << compressedSR << endl;
	//compressedSR is defined to not overlap with SR - can use same histogram!
	histos["SRyield"]->Fill(mStop,mLSP,compressedSR,weight);
	histos["SR_ISRup"]->Fill(mStop,mLSP,compressedSR,weight*ISRup);
	histos["SR_ISRdown"]->Fill(mStop,mLSP,compressedSR,weight*ISRdown);
	histos["SR_Xsecup"]->Fill(mStop,mLSP,compressedSR,weight*XSup);
	histos["SR_Xsecdown"]->Fill(mStop,mLSP,compressedSR,weight*XSdown);
	histos["SR_PUup"]->Fill(mStop,mLSP,compressedSR,weight*PUup);
	histos["SR_PUdown"]->Fill(mStop,mLSP,compressedSR,weight*PUdown);
	histos["SR_Bup_HF"]->Fill(mStop,mLSP,compressedSR,weight*BSFHup);
	histos["SR_Bup_LF"]->Fill(mStop,mLSP,compressedSR,weight*BSFLup);
	histos["SR_Bdown_HF"]->Fill(mStop,mLSP,compressedSR,weight*BSFHdown);
	histos["SR_Bdown_LF"]->Fill(mStop,mLSP,compressedSR,weight*BSFLdown);
	histos["SR_LepEffup"]->Fill(mStop,mLSP,compressedSR,weight*lEffup);
	histos["SR_LepEffdown"]->Fill(mStop,mLSP,compressedSR,weight*lEffdown);
	histos["SR_LepEffFSup"]->Fill(mStop,mLSP,compressedSR,weight*lEffFSup);
	histos["SR_LepEffFSdown"]->Fill(mStop,mLSP,compressedSR,weight*lEffFSdown);
	histos["SR_muRFup"]->Fill(mStop,mLSP,compressedSR,weight*muRFup);
	histos["SR_muRFdown"]->Fill(mStop,mLSP,compressedSR,weight*muRFdown);
      }

    }//event loop
  
    // Clean Up
    delete tree;
    file->Close();
    delete file;
  }//file loop
  if ( nEventsChain != nEventsTotal ) {
    cout << Form( "ERROR: number of events from files (%d) is not equal to total number of events (%d)", nEventsChain, nEventsTotal ) << endl;
  }
  
  // Example Histograms
  // samplehisto->Draw();

  /*
  for(map<string,TH3D*>::iterator h=histos.begin(); h!=histos.end();++h){
    //add overflow
    //h->second->SetBinContent(h->second->GetNbinsX(), h->second->GetBinContent(h->second->GetNbinsX() )+ h->second->GetBinContent(h->second->GetNbinsX()+1) );
    //h->second->SetBinError(h->second->GetNbinsX(), sqrt(pow(h->second->GetBinError(h->second->GetNbinsX() ),2)+pow(h->second->GetBinError(h->second->GetNbinsX()+1),2) ) );
    //add underfloe
    //h->second->SetBinContent(1, h->second->GetBinContent(1)+ h->second->GetBinContent(0) );
    //h->second->SetBinError(1, sqrt(pow(h->second->GetBinError(1),2)+pow(h->second->GetBinError(0),2) ) );
  }
  */
  string filename = "rootfiles/signalyields/Histos_"+skimFilePrefix+".root";
  TFile *f = new TFile(filename.c_str(),"RECREATE");
  f->cd();
  for(map<string,TH3D*>::iterator h=    histos.begin(); h!=    histos.end();++h) h->second->Write();
  f->Close();
  cout << "Saved histos in " << f->GetName() << endl;

  f_el_SF->Close();
  f_mu_SF_id->Close();
  f_mu_SF_iso->Close();
  f_mu_SF_veto_id->Close();
  f_mu_SF_veto_iso->Close();
  f_vetoLep_eff->Close();
  f_el_FS_ID->Close();
  f_el_FS_Iso->Close();
  f_mu_FS_ID->Close();
  f_mu_FS_Iso->Close();
  // return
  bmark->Stop("benchmark");
  cout << endl;
  cout << nEventsTotal << " Events Processed" << endl;
  cout << "------------------------------" << endl;
  cout << "CPU  Time:	" << Form( "%.01f", bmark->GetCpuTime("benchmark")  ) << endl;
  cout << "Real Time:	" << Form( "%.01f", bmark->GetRealTime("benchmark") ) << endl;
  cout << endl;
  delete bmark;
  delete fPU;//delete PU file
  delete f_el_SF;
  delete f_mu_SF_id;
  delete f_mu_SF_iso;
  delete f_mu_SF_veto_id;
  delete f_mu_SF_veto_iso;
  delete f_vetoLep_eff;
  delete f_el_FS_ID;
  delete f_el_FS_Iso;
  delete f_mu_FS_ID;
  delete f_mu_FS_Iso;
  return 0;
}
コード例 #23
0
ファイル: bToDRawYield.C プロジェクト: Jelov/BtoD
void bToDRawYield()
{
	gStyle->SetTextSize(0.05);
	gStyle->SetTextFont(42);
	gStyle->SetPadRightMargin(0.04);
	gStyle->SetPadLeftMargin(0.14);
	gStyle->SetPadTopMargin(0.1);
	gStyle->SetPadBottomMargin(0.14);
	gStyle->SetTitleX(.0f);
	gStyle->SetOptFit(1111);
	gStyle->SetOptStat(0);
	gStyle->SetOptTitle(0);

	TCanvas* c4 = new TCanvas("c4","",800,600);
	c4->Divide(2,2);

	TCanvas* c2 = new TCanvas("c2","",400,600);
	c2->Divide(1,2);

	TCanvas* c1 = new TCanvas();

	TCanvas* c15 = new TCanvas("c15","",810,1000);
	c15->Divide(3,5);

	TFile* fPbPb = new TFile("bFeedDownPbPb.hist.root");
	TFile* fPbPbMB = new TFile("bFeedDownPbPbMB.hist.root");
	TFile* fPbPbMC = new TFile("bFeedDownPbPbMC.hist.root");
	TFile* fPbPbMBMC = new TFile("bFeedDownPbPbMBMC.hist.root");

	TH3D* hDataPbPb = (TH3D*)fPbPb->Get("hData");
	TH3D* hSidebandPbPb = (TH3D*)fPbPb->Get("hSideband");
	TH3D* hDataPbPbMB = (TH3D*)fPbPbMB->Get("hData");
	TH3D* hSidebandPbPbMB = (TH3D*)fPbPbMB->Get("hSideband");
	TH3D* hPtMD0DcaPbPb = (TH3D*)fPbPb->Get("hPtMD0Dca");
	TH3D* hPtMD0DcaPbPbMB = (TH3D*)fPbPbMB->Get("hPtMD0Dca");

	TH3D* hMCPSignalPbPb = (TH3D*)fPbPbMC->Get("hMCPSignal");
	TH3D* hMCNPSignalPbPb = (TH3D*)fPbPbMC->Get("hMCNPSignal");
	TH3D* hMCPSignalPbPbMB = (TH3D*)fPbPbMBMC->Get("hMCPSignal");
	TH3D* hMCNPSignalPbPbMB = (TH3D*)fPbPbMBMC->Get("hMCNPSignal");
	TH3D* hPtMD0DcaMCPSignalPbPb = (TH3D*)fPbPbMC->Get("hPtMD0DcaMCPSignal");
	TH3D* hPtMD0DcaMCPSwappedPbPb = (TH3D*)fPbPbMC->Get("hPtMD0DcaMCPSwapped");
	TH3D* hPtMD0DcaMCPSignalPbPbMB =(TH3D*)fPbPbMBMC->Get("hPtMD0DcaMCPSignal");
	TH3D* hPtMD0DcaMCPSwappedPbPbMB = (TH3D*)fPbPbMBMC->Get("hPtMD0DcaMCPSwapped");

	TH3D* hData = (TH3D*)hDataPbPb->Clone("hData");
	hData->Sumw2();
	hData->Add(hDataPbPbMB);

	TH3D* hSideband = (TH3D*)hSidebandPbPb->Clone("hSideband");
	hSideband->Sumw2();
	hSideband->Add(hSidebandPbPbMB);

	TH3D* hPtMD0Dca = (TH3D*)hPtMD0DcaPbPb->Clone("hPtMD0Dca");
	hPtMD0Dca->Sumw2();
	hPtMD0Dca->Add(hPtMD0DcaPbPbMB);

	TH3D* hMCPSignal = (TH3D*)hMCPSignalPbPb->Clone("hMCPSignal");
	hMCPSignal->Sumw2();
	hMCPSignal->Add(hMCPSignalPbPbMB);

	TH3D* hMCNPSignal = (TH3D*)hMCNPSignalPbPb->Clone("hMCNPSignal");
	hMCNPSignal->Sumw2();
	hMCNPSignal->Add(hMCNPSignalPbPbMB);

	TH3D* hPtMD0DcaMCPSignal = (TH3D*)hPtMD0DcaMCPSignalPbPb->Clone("hPtMD0DcaMCPSignal");
	hPtMD0DcaMCPSignal->Sumw2();
	hPtMD0DcaMCPSignal->Add(hPtMD0DcaMCPSignalPbPbMB);

	TH3D* hPtMD0DcaMCPSwapped =(TH3D*)hPtMD0DcaMCPSwappedPbPb->Clone("hPtMD0DcaMCPSwapped");
	hPtMD0DcaMCPSwapped->Sumw2();
	hPtMD0DcaMCPSwapped->Add(hPtMD0DcaMCPSwappedPbPbMB);

	TLatex* texCms = new TLatex(0.18,0.93, "#scale[1.25]{CMS} Preliminary");
	texCms->SetNDC();
	texCms->SetTextAlign(12);
	texCms->SetTextSize(0.06);
	texCms->SetTextFont(42);

	TLatex* texCol = new TLatex(0.96,0.93, "PbPb #sqrt{s_{NN}} = 5.02 TeV");
	texCol->SetNDC();
	texCol->SetTextAlign(32);
	texCol->SetTextSize(0.06);
	texCol->SetTextFont(42);

	const int nPtBins = 14;
	float ptBins[nPtBins+1] = {2.,3.,4.,5.,6.,8.,10.,12.5,15.0,20.,25.,30.,40.,60.,100};

	float pts[nPtBins];
	float ptErrors[nPtBins];
	float promptFraction[nPtBins];
	float totalYield[nPtBins];
	float totalYieldInvMassFit[nPtBins];
	float totalYieldInvMassFitError[nPtBins];
	float bToDYield[nPtBins];
	float bToDYieldError[nPtBins];
	float bToDYieldErrorDataOnly[nPtBins];
	float promptDYield[nPtBins];
	float promptDYieldError[nPtBins];
	float promptDYieldErrorDataOnly[nPtBins];

	const int nBinY = 14;
	Float_t binsY[nBinY+1];
	float firstBinYWidth = 0.001;
	float binYWidthRatio = 1.27;
	binsY[0]=0;
	for(int i=1; i<=nBinY; i++)
		binsY[i] = binsY[i-1]+firstBinYWidth*pow(binYWidthRatio,i-1);
	cout<<"last y bin: "<<binsY[nBinY]<<endl;

	//  for(int i=1; i<=nPtBins; i++)
	for(int i =7; i<=7; i++)
	{
		pts[i-1] = 0.5*(ptBins[i-1]+ptBins[i]);
		ptErrors[i-1] = 0.5*(ptBins[i]-ptBins[i-1]);
		float ptLow = ptBins[i-1];
		float ptHigh = ptBins[i];
		cout<<endl<<"======================================="<<endl;
		cout<<"pT range: "<<ptLow<<" "<<ptHigh<<endl;

		TLatex* texPtY = new TLatex(0.32,0.82,Form("%.1f < p_{T} < %.1f GeV/c      |y| < 1.0",ptLow,ptHigh));
		texPtY->SetNDC();
		texPtY->SetTextFont(42);
		texPtY->SetTextSize(0.06);
		texPtY->SetLineWidth(2);

		TLatex* texPt = new TLatex(0.18,0.82,Form("%.1f < p_{T} < %.1f GeV/c",ptLow,ptHigh));
		texPt->SetNDC();
		texPt->SetTextFont(42);
		texPt->SetTextSize(0.06);
		texPt->SetLineWidth(2);

		TLatex* texY = new TLatex(0.18,0.74,Form("|y| < 1.0"));
		texY->SetNDC();
		texY->SetTextFont(42);
		texY->SetTextSize(0.06);
		texY->SetLineWidth(2);

		c2->cd(1);

		hPtMD0Dca->GetZaxis()->SetRange(1,100);
		hPtMD0Dca->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001);
		hPtMD0DcaMCPSignal->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001);
		hPtMD0DcaMCPSwapped->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001);
		TH1D* hMData = (TH1D*)hPtMD0Dca->Project3D("y")->Clone(Form("hM_%1.1f_%1.1f", ptLow, ptHigh));
		TH1D* hMMCSignal = (TH1D*)hPtMD0DcaMCPSignal->Project3D("y");
		TH1D* hMMCSwapped = (TH1D*)hPtMD0DcaMCPSwapped->Project3D("y");

		setColorTitleLabel(hMData);
		setColorTitleLabel(hMMCSignal);
		setColorTitleLabel(hMMCSwapped);

		TF1* fMass = fitMass(hMData, hMMCSignal, hMMCSwapped);

		texCms->Draw();
		texCol->Draw();
		texPt->Draw();
		texY->Draw();

		TF1* fSignalAndSwapped = new TF1("fSignalAndSwapped","[0]*([3]*([5]*Gaus(x,[1],[2]*(1+[7]))/(sqrt(2*3.1415927)*[2]*(1+[7]))+(1-[5])*Gaus(x,[1],[6]*(1+[7]))/(sqrt(2*3.1415927)*[6]*(1+[7])))+(1-[3])*Gaus(x,[1],[4]*(1+[7]))/(sqrt(2*3.1415927)*[4]*(1+[7])))", 1.7, 2.0);      
		fSignalAndSwapped->SetParameter(0,fMass->GetParameter(0));
		fSignalAndSwapped->SetParameter(1,fMass->GetParameter(1));
		fSignalAndSwapped->SetParameter(2,fMass->GetParameter(2));
		fSignalAndSwapped->SetParameter(3,fMass->GetParameter(7));
		fSignalAndSwapped->SetParameter(4,fMass->GetParameter(8));
		fSignalAndSwapped->SetParameter(5,fMass->GetParameter(9));
		fSignalAndSwapped->SetParameter(6,fMass->GetParameter(10));
		fSignalAndSwapped->SetParameter(7,fMass->GetParameter(11));

		TF1* background = new TF1("fBackground","[0]+[1]*x+[2]*x*x+[3]*x*x*x");
		background->SetParameter(0,fMass->GetParameter(3));
		background->SetParameter(1,fMass->GetParameter(4));
		background->SetParameter(2,fMass->GetParameter(5));
		background->SetParameter(3,fMass->GetParameter(6));

		cout<<"MC signal width: "<<fMass->GetParameter(2)<<"   "<<fMass->GetParameter(10)<<endl;
		cout<<"MC swapped width: "<<fMass->GetParameter(8)<<endl;

		float massD = 1.8649;
		float massSignal1 = massD-0.025;
		float massSignal2 = massD+0.025;
		float massSideBand1 = massD-0.1;
		float massSideBand2 = massD-0.075;
		float massSideBand3 = massD+0.075;
		float massSideBand4 = massD+0.1;

		float scaleSideBandBackground = background->Integral(massSignal1, massSignal2)/(background->Integral(massSideBand1, massSideBand2)+background->Integral(massSideBand3, massSideBand4));
		cout<<"scaleSideBandBackground: "<<scaleSideBandBackground<<endl;
		totalYieldInvMassFit[i-1] = fMass->GetParameter(0)*fMass->GetParameter(7)/hMData->GetBinWidth(1);
		totalYieldInvMassFitError[i-1] = fMass->GetParError(0)*fMass->GetParameter(7)/hMData->GetBinWidth(1);
		cout<<"totalYieldInvMassFit: "<<totalYieldInvMassFit[i-1]<<" +- "<<totalYieldInvMassFitError[i-1]<<endl;
		float scaleSideBandMethodSignal = fSignalAndSwapped->GetParameter(0)*fSignalAndSwapped->GetParameter(3) / (fSignalAndSwapped->Integral(massSignal1, massSignal2)-fSignalAndSwapped->Integral(massSideBand1, massSideBand2)-fSignalAndSwapped->Integral(massSideBand3, massSideBand4));
		cout<<"scaleSideBandMethodSignal: "<<scaleSideBandMethodSignal<<endl;

		TLatex* texScale = new TLatex(0.18,0.66,Form("side band bg scale: %1.3f", scaleSideBandBackground));
		texScale->SetNDC();
		texScale->SetTextFont(42);
		texScale->SetTextSize(0.06);
		texScale->SetLineWidth(2);
		texScale->Draw();

		TLine* lineSignal1 = new TLine(massSignal1, 0, massSignal1, hMData->GetMaximum()*0.5);
		TLine* lineSignal2 = new TLine(massSignal2, 0, massSignal2, hMData->GetMaximum()*0.5);
		TLine* lineSideBand1 = new TLine(massSideBand1, 0, massSideBand1, hMData->GetMaximum()*0.5);
		TLine* lineSideBand2 = new TLine(massSideBand2, 0, massSideBand2, hMData->GetMaximum()*0.5);
		TLine* lineSideBand3 = new TLine(massSideBand3, 0, massSideBand3, hMData->GetMaximum()*0.5);
		TLine* lineSideBand4 = new TLine(massSideBand4, 0, massSideBand4, hMData->GetMaximum()*0.5);
		lineSignal1->Draw();
		lineSignal2->Draw();
		lineSideBand1->Draw();
		lineSideBand2->Draw();
		lineSideBand3->Draw();
		lineSideBand4->Draw();

		c2->cd(2);
		gPad->SetLogy();

		hData->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001);
		hSideband->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001);
		hMCPSignal->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001);
		hMCNPSignal->GetXaxis()->SetRangeUser(ptLow+0.001,ptHigh-0.001);

		TH1D* hD0DcaData0 = (TH1D*)hData->Project3D("y")->Clone("hD0DcaData0");
		TH1D* hD0DcaSideband = (TH1D*)hSideband->Project3D("y")->Clone("hD0DcaSideband");
		TH1D* hD0DcaMCPSignal0 = (TH1D*)hMCPSignal->Project3D("y")->Clone("hD0DcaMCPSignal0");
		TH1D* hD0DcaMCNPSignal0 = (TH1D*)hMCNPSignal->Project3D("y")->Clone("hD0DcaMCNPSignal0");

		float integralRawYieldMCP = hD0DcaMCPSignal0->Integral();
		float integralRawYieldMCNP = hD0DcaMCNPSignal0->Integral();
		cout<<"integralRawYieldMCP: "<<integralRawYieldMCP<<endl;
		cout<<"integralRawYieldMCNP: "<<integralRawYieldMCNP<<endl;

		hD0DcaMCPSignal = hD0DcaMCPSignal0;
		hD0DcaMCNPSignal = hD0DcaMCNPSignal0;

		divideBinWidth(hD0DcaData0);
		divideBinWidth(hD0DcaSideband);
		setColorTitleLabel(hD0DcaData0, 1);
		hD0DcaData0->GetXaxis()->SetRangeUser(0,0.07);
		hD0DcaData0->GetYaxis()->SetTitle("counts per cm");

		TH1D* hD0DcaSideband0 = (TH1D*)hD0DcaSideband->Clone("hD0DcaSideband0");
		hD0DcaSideband->Scale(scaleSideBandBackground);

		TH1D* hD0DcaDataSubSideBand = (TH1D*)hD0DcaData0->Clone("hD0DcaDataSubSideBand");
		hD0DcaDataSubSideBand->Add(hD0DcaSideband,-1);
		hD0DcaDataSubSideBand->Scale(scaleSideBandMethodSignal);

		hD0DcaData0->SetMarkerSize(0.6);
		hD0DcaData0->Draw();
		hD0DcaSideband->Draw("hsame");
		hD0DcaSideband0->SetLineStyle(2);
		hD0DcaSideband0->Draw("hsame");

		TLegend* leg1 = new TLegend(0.44,0.6,0.90,0.76,NULL,"brNDC");
		leg1->SetBorderSize(0);
		leg1->SetTextSize(0.06);
		leg1->SetTextFont(42);
		leg1->SetFillStyle(0);
		leg1->AddEntry(hD0DcaData0,"D^{0} candidate","pl");
		leg1->AddEntry(hD0DcaSideband,"side band","l");
		leg1->AddEntry(hD0DcaSideband0,"side band unscaled","l");
		leg1->Draw("same");

		texCms->Draw();
		texCol->Draw();
		texPtY->Draw();

		c2->SaveAs(Form("plots/PbPb_%.0f_%.0f_sideBand.pdf",ptLow,ptHigh));

		c2->cd(1);
		hMMCSignal->Draw();
		texCms->Draw();
		texCol->Draw();
		texPt->Draw();
		texY->Draw();

		c2->cd(2);
		gPad->SetLogy(0);
		hMMCSwapped->Draw();
		texCms->Draw();
		texCol->Draw();
		texPt->Draw();
		texY->Draw();

		c2->SaveAs(Form("plots/PbPb_%.0f_%.0f_McInvMassFit.pdf",ptLow,ptHigh));

		c15->cd(1);

		fitMass(hMData, hMMCSignal, hMMCSwapped);

		texPt->Draw();
		texY->Draw();

		TH1D* hD0DcaDataFit = new TH1D("hD0DcaDataFit", ";D^{0} DCA (cm);dN / d(D^{0} DCA) (cm^{-1})", nBinY, binsY);

		for(int j=1; j<=14; j++)
		{
			c15->cd(j+1);
			hPtMD0Dca->GetZaxis()->SetRange(j,j);
			float D0DcaLow = hPtMD0Dca->GetZaxis()->GetBinLowEdge(j);
			float D0DcaHigh = hPtMD0Dca->GetZaxis()->GetBinUpEdge(j);
			TH1D* hMData_D0Dca = (TH1D*)hPtMD0Dca->Project3D("y")->Clone(Form("hM_pt_%1.1f_%1.1f_D0Dca_%1.4f_%1.4f", ptLow, ptHigh, D0DcaLow, D0DcaHigh));
			setColorTitleLabel(hMData_D0Dca);
			fMass = fitMass(hMData_D0Dca, hMMCSignal, hMMCSwapped);

			float yield = fMass->GetParameter(0)*fMass->GetParameter(7)/hMData_D0Dca->GetBinWidth(1);
			float yieldError = fMass->GetParError(0)*fMass->GetParameter(7)/hMData_D0Dca->GetBinWidth(1);

			hD0DcaDataFit->SetBinContent(j, yield);
			hD0DcaDataFit->SetBinError(j, yieldError);

			TLatex* texD0Dca = new TLatex(0.18,0.82,Form("D^{0} DCA: %1.4f - %1.4f",D0DcaLow,D0DcaHigh));
			texD0Dca->SetNDC();
			texD0Dca->SetTextFont(42);
			texD0Dca->SetTextSize(0.06);
			texD0Dca->SetLineWidth(2);
			texD0Dca->Draw();

			TLatex* texYield = new TLatex(0.18,0.74,Form("D^{0} yield: %1.0f #pm %1.0f",yield,yieldError));
			texYield->SetNDC();
			texYield->SetTextFont(42);
			texYield->SetTextSize(0.06);
			texYield->SetLineWidth(2);
			texYield->Draw();
		}

		c15->SaveAs(Form("plots/PbPb_%.0f_%.0f_invMassFit.pdf",ptLow,ptHigh));

		divideBinWidth(hD0DcaDataFit);

		c4->cd(1);
		gPad->SetLogy();

		normalize(hD0DcaMCPSignal);
		setColorTitleLabel(hD0DcaMCPSignal, 2);
		hD0DcaMCPSignal->GetXaxis()->SetRangeUser(0,0.07);

		normalize(hD0DcaMCNPSignal);
		setColorTitleLabel(hD0DcaMCNPSignal, 4);
		hD0DcaMCNPSignal->GetXaxis()->SetRangeUser(0,0.07);
		hD0DcaMCNPSignal->GetYaxis()->SetTitle("dN / d(D^{0} DCA) (cm^{-1})");
		hD0DcaMCNPSignal->GetXaxis()->SetTitle("D^{0} DCA (cm)");
		hD0DcaMCNPSignal->SetMaximum(hD0DcaMCPSignal->GetMaximum()*3.);

		hD0DcaMCNPSignal->Draw("");
		hD0DcaMCPSignal->Draw("same");

		TLegend* leg2 = new TLegend(0.54,0.72,0.90,0.88,NULL,"brNDC");
		leg2->SetBorderSize(0);
		leg2->SetTextSize(0.06);
		leg2->SetTextFont(42);
		leg2->SetFillStyle(0);
		leg2->AddEntry(hD0DcaMCPSignal,"MC Prompt D^{0}","pl");
		leg2->AddEntry(hD0DcaMCNPSignal,"MC Non-prompt D^{0}","pl");
		leg2->Draw("same");

		c4->cd(2);
		gPad->SetLogy();

		TH1D* hD0DcaData = hD0DcaDataFit;
		if(pts[i-1]>20) hD0DcaData = hD0DcaDataSubSideBand;

		setColorTitleLabel(hD0DcaData, 1);

		double integralTotalYield = hD0DcaData->Integral(1,hD0DcaData->GetXaxis()->GetNbins(),"width");
		cout<<"integralTotalYield: "<<integralTotalYield<<endl;

		TF1* fMix = new TF1("fMix",&funMix, 0., 0.5, 2);
		fMix->SetParameters(0.5*integralTotalYield,0.5*integralTotalYield);
		fMix->SetParLimits(0,0,2*integralTotalYield);
		fMix->SetParLimits(1,0,2*integralTotalYield);

		fMix->SetLineColor(2);
		fMix->SetFillColor(kRed-9);
		fMix->SetFillStyle(1001);

		float fitRangeL = 0;
		float fitRangeH = 0.08;

		hD0DcaData->GetXaxis()->SetRangeUser(0,0.07);
		hD0DcaData->Draw();
		int fitStatus = 1;
		TFitResultPtr fitResult;
		double fitPrecision = 1.e-6;
		while(fitStatus)
		{
			TFitter::SetPrecision(fitPrecision);
			fMix->SetParameters(0.5*integralTotalYield,0.5*integralTotalYield);
			fMix->SetParError(0,0.1*integralTotalYield);
			fMix->SetParError(1,0.1*integralTotalYield);
			fitResult = hD0DcaData->Fit("fMix","E SNQ0", "", fitRangeL, fitRangeH);
			fitStatus = fitResult->Status();
			cout<<"fit precision: "<<TFitter::GetPrecision()<<"   status: "<<fitStatus<<endl;
			if(fitStatus)
				fitPrecision *= 10;
		}
		cout<<"============== do main fit ============"<<endl;
		fMix->SetParameters(integralTotalYield,0.9);
		fMix->SetParError(0,0.1*integralTotalYield);
		fMix->SetParError(1,0.1);
		fMix->SetNpx(10000);
		fitResult = hD0DcaData->Fit("fMix","E S0", "", fitRangeL, fitRangeH);
		hD0DcaData->GetFunction("fMix")->Draw("flsame");
		fitStatus = fitResult->Status();
		cout<<"fit precision: "<<TFitter::GetPrecision()<<"   status: "<<fitStatus<<endl;

		TF1* fNP = new TF1("fNP",&funNonPrompt, 0., 0.5, 2);
		fNP->SetParameters(fMix->GetParameter(0),fMix->GetParameter(1));
		fNP->SetRange(fitRangeL,fitRangeH);
		fNP->SetLineColor(4);
		fNP->SetFillStyle(1001);
		fNP->SetFillColor(kBlue-9);
		fNP->SetNpx(10000);
		fNP->Draw("same");  

		hD0DcaData->Draw("same");

		promptDYield[i-1] = fMix->GetParameter(0);
		promptDYieldErrorDataOnly[i-1] = fMix->GetParError(0);
		bToDYield[i-1] = fMix->GetParameter(1);
		bToDYieldErrorDataOnly[i-1] = fMix->GetParError(1);
		totalYield[i-1] = promptDYield[i-1]+bToDYield[i-1];
		promptFraction[i-1] = promptDYield[i-1]/totalYield[i-1];

		cout<<"chi2 / NDF: "<<fitResult->Chi2()<<" / "<<fitResult->Ndf()<<endl;

		texCms->Draw();
		texCol->Draw();
		texPtY->Draw();

		TLatex* texPrompt = new TLatex(0.4,0.73,Form("Prompt D^{0} yield : %.0f #pm %.0f",fMix->GetParameter(0),fMix->GetParError(0)));
		texPrompt->SetNDC();
		texPrompt->SetTextFont(42);
		texPrompt->SetTextSize(0.06);
		texPrompt->SetLineWidth(2);
		texPrompt->Draw();

		TLatex* texNonPrompt = new TLatex(0.4,0.65,Form("B to D^{0} yield : %.0f #pm %.0f",fMix->GetParameter(1),fMix->GetParError(1)));
		texNonPrompt->SetNDC();
		texNonPrompt->SetTextFont(42);
		texNonPrompt->SetTextSize(0.06);
		texNonPrompt->SetLineWidth(2);
		texNonPrompt->Draw();

		TLegend* leg4 = new TLegend(0.56,0.38,0.90,0.62);
		leg4->SetBorderSize(0);
		leg4->SetTextSize(0.06);
		leg4->SetTextFont(42);
		leg4->SetFillStyle(0);
		leg4->AddEntry(hD0DcaData,"Data","pl");
		leg4->AddEntry(fMix,"Prompt D^{0}","f");
		leg4->AddEntry(fNP,"B to D^{0}","f");
		leg4->Draw("same");

		//smear MC smaple with the error, to simulate the MC statistic error effect.
		c4->cd(3);

		hD0DcaMCPSignal = (TH1D*)hD0DcaMCPSignal0->Clone("hMCPSignal");
		hD0DcaMCNPSignal = (TH1D*)hD0DcaMCNPSignal0->Clone("hMCNPSignal");

		TH1D* hNPYield = new TH1D("hNPYield", ";hNPYield", 100, 0., 1.1*(fMix->GetParameter(0)+fMix->GetParameter(1)));
		TH1D* hPYield = new TH1D("hPYield", ";hPYield", 100, 0., 1.1*(fMix->GetParameter(0)+fMix->GetParameter(1)));
		setColorTitleLabel(hNPYield, 1);
		setColorTitleLabel(hPYield, 1);

		int nSmear = 1000;

		for(int j=0; j<nSmear; j++)
		{
			RandomSmear(hD0DcaMCPSignal0, hD0DcaMCPSignal);
			RandomSmear(hD0DcaMCNPSignal0, hD0DcaMCNPSignal);
			fMix->SetParameters(0.5*integralTotalYield,0.5*integralTotalYield);
			fMix->SetParError(0,0.1*integralTotalYield);
			fMix->SetParError(1,0.1*integralTotalYield);

			hD0DcaData->Fit("fMix","E QN0");

			hPYield->Fill(fMix->GetParameter(0));
			hNPYield->Fill(fMix->GetParameter(1));
		}

		hPYield->GetXaxis()->SetTitle("prompt D^{0} yield");
		hPYield->GetYaxis()->SetTitle("counts");
		hPYield->GetYaxis()->SetRangeUser(0.5, 1.4*hPYield->GetMaximum());
		hPYield->SetMarkerStyle(20);
		hPYield->SetStats(0);
		hPYield->Draw("e");
		hPYield->Fit("gaus");

		TLatex* texGaussMeanSigmaP = new TLatex(0.27,0.83,Form("#mu: %.0f              #sigma: %.0f",hPYield->GetFunction("gaus")->GetParameter(1),hPYield->GetFunction("gaus")->GetParameter(2)));
		texGaussMeanSigmaP->SetNDC();
		texGaussMeanSigmaP->SetTextFont(42);
		texGaussMeanSigmaP->SetTextSize(0.06);
		texGaussMeanSigmaP->SetLineWidth(2);
		texGaussMeanSigmaP->Draw();

		float promptYieldErrorMc = hPYield->GetFunction("gaus")->GetParameter(2);
		promptDYieldError[i-1] = sqrt(pow(promptDYieldErrorDataOnly[i-1],2)+pow(promptYieldErrorMc,2));

		c4->cd(4);

		hNPYield->GetXaxis()->SetTitle("B to D^{0} yield");
		hNPYield->GetYaxis()->SetTitle("counts");
		hNPYield->GetYaxis()->SetRangeUser(0.5, 1.4*hNPYield->GetMaximum());
		hNPYield->SetMarkerStyle(20);
		hNPYield->SetStats(0);
		hNPYield->Draw("e");
		hNPYield->Fit("gaus");

		TLatex* texGaussMeanSigmaNP = new TLatex(0.27,0.83,Form("#mu: %.0f              #sigma: %.0f",hNPYield->GetFunction("gaus")->GetParameter(1),hNPYield->GetFunction("gaus")->GetParameter(2)));
		texGaussMeanSigmaNP->SetNDC();
		texGaussMeanSigmaNP->SetTextFont(42);
		texGaussMeanSigmaNP->SetTextSize(0.06);
		texGaussMeanSigmaNP->SetLineWidth(2);
		texGaussMeanSigmaNP->Draw();

		float bToDYieldErrorMc = hNPYield->GetFunction("gaus")->GetParameter(2);
		bToDYieldError[i-1] = sqrt(pow(bToDYieldErrorDataOnly[i-1],2)+pow(bToDYieldErrorMc,2));

		cout<<"prompt D yield: "<<promptDYield[i-1]<<" +- "<<promptDYieldError[i-1]<<" (+- "<<promptDYieldErrorDataOnly[i-1]<<" +- "<<promptYieldErrorMc<<" )"<<endl;
		cout<<"B to D yield: "<<bToDYield[i-1]<<" +- "<<bToDYieldError[i-1]<<" (+- "<<bToDYieldErrorDataOnly[i-1]<<" +- "<<bToDYieldErrorMc<<" )"<<endl;
		cout<<"total yield: "<<totalYield[i-1]<<endl;
		cout<<"prompt fraction: "<<promptFraction[i-1]<<endl;

		float promptMCScale = promptDYield[i-1]/integralRawYieldMCP;
		float nonPromptMCScale = bToDYield[i-1]/integralRawYieldMCNP;

		cout<<"promptMCScale: "<<promptMCScale<<endl;
		cout<<"nonPromptMCScale: "<<nonPromptMCScale<<endl;

		//restore original unsmeared histograms before saving plots
		delete hD0DcaMCPSignal;
		delete hD0DcaMCNPSignal;
		hD0DcaMCPSignal = hD0DcaMCPSignal0;
		hD0DcaMCNPSignal = hD0DcaMCNPSignal0;
		hD0DcaData->Fit("fMix","E QN0");

		c4->SaveAs(Form("plots/PbPb_%.0f_%.0f_fit.pdf",ptLow,ptHigh));

		c1->cd();

		TH1D* hD0DcaDataOverFit = (TH1D*)hD0DcaData->Clone("hD0DcaDataOverFit");
		hD0DcaDataOverFit->Divide(fMix);
		hD0DcaDataOverFit->GetYaxis()->SetTitle("data / fit");
		hD0DcaDataOverFit->GetYaxis()->SetRangeUser(0,5);
		hD0DcaDataOverFit->GetXaxis()->SetRangeUser(0,0.07);
		setColorTitleLabel(hD0DcaDataOverFit, 1);
		hD0DcaDataOverFit->Draw("e");

		TF1* fLine1 = new TF1("fLine1", "1", 0,1);
		fLine1->Draw("same");
		hD0DcaDataOverFit->Draw("esame");

		c1->SaveAs(Form("plots/dataOverFit_%.0f_%.0f_fit.pdf",ptLow,ptHigh));

		delete hD0DcaMCPSignal;
		delete hD0DcaMCNPSignal;

	} // end for i ptbins
	c1->cd();

	TH1D* hStupidJie = new TH1D("hStupidJie", "", 100, 0, 100);
	hStupidJie->GetYaxis()->SetRangeUser(0,1);
	hStupidJie->GetXaxis()->SetTitle("p_{T} (GeV/c)");
	hStupidJie->GetYaxis()->SetTitle("prompt fraction");
	hStupidJie->SetStats(0);
	hStupidJie->Draw();
	TGraph* grFraction = new TGraph(nPtBins, pts, promptFraction);
	grFraction->SetName("grPromptFraction");
	grFraction->SetMarkerStyle(20);
	grFraction->Draw("psame");

	c1->SaveAs("promptFraction.pdf");

	c1->SetLogy();

	TH1D* hBtoDRawYield = new TH1D("hBtoDRawYield", ";p_{T} (GeV/c);dN/dp_{T} ((GeV/c)^{-1})", nPtBins, ptBins);
	for(int i=1; i<=nPtBins; i++)
	{
		if(bToDYield[i-1] <= 0) continue;
		hBtoDRawYield->SetBinContent(i, bToDYield[i-1]);
		hBtoDRawYield->SetBinError(i, bToDYieldError[i-1]);
	}
	divideBinWidth(hBtoDRawYield);
	setColorTitleLabel(hBtoDRawYield, 1);
	c1->SetBottomMargin(0.14);
	hBtoDRawYield->Draw("p");
	c1->SaveAs("BtoD.pdf");

	TH1D* hPromptDRawYield = new TH1D("hPromptDRawYield", ";p_{T} (GeV/c);dN/dp_{T} ((GeV/c)^{-1})", nPtBins, ptBins);
	for(int i=1; i<=nPtBins; i++)
	{
		if(promptDYield[i-1] <= 0) continue;
		hPromptDRawYield->SetBinContent(i, promptDYield[i-1]);
		hPromptDRawYield->SetBinError(i, promptDYieldError[i-1]);
	}
	divideBinWidth(hPromptDRawYield);
	setColorTitleLabel(hPromptDRawYield, 1);
	c1->SetBottomMargin(0.14);
	hPromptDRawYield->Draw("p");
	c1->SaveAs("promptD.pdf");

	TH1D* hTotalDYieldInvMassFit = new TH1D("hTotalDYieldInvMassFit", ";p_{T} (GeV/c);dN/dp_{T} ((GeV/c)^{-1})", nPtBins, ptBins);
	for(int i=1; i<=nPtBins; i++)
	{
		if(totalYieldInvMassFit[i-1] <= 0) continue;
		hTotalDYieldInvMassFit->SetBinContent(i, totalYieldInvMassFit[i-1]);
		hTotalDYieldInvMassFit->SetBinError(i, totalYieldInvMassFitError[i-1]);
	}
	divideBinWidth(hTotalDYieldInvMassFit);
	setColorTitleLabel(hTotalDYieldInvMassFit, 1);
	hTotalDYieldInvMassFit->Draw("p");
	c1->SaveAs("totalDInvMassFit.pdf");

	TFile* fOut = new TFile("bFeedDownResult.root", "recreate");
	fOut->WriteTObject(grFraction);
	fOut->WriteTObject(hBtoDRawYield);
	fOut->WriteTObject(hPromptDRawYield);
	fOut->WriteTObject(hTotalDYieldInvMassFit);
	fOut->Write();
	fOut->Close();
}
コード例 #24
0
ファイル: DrawLc3D.C プロジェクト: noferini/lessonmaterials
void DrawLc3D(Int_t step=1,Float_t ptmin=0,Float_t ptmax=10){
  Double_t nev = 13E6;
  Double_t nsig = 1.5E5;
  Double_t nback = 1.5;

  TFile *fcur = TFile::Open(Form("step%i.root",step));
  TFile *fpre = TFile::Open(Form("step%i.root",step-1));

  if(! fpre) fpre = fcur;

  const char *comb = "PiKaPr";

  Int_t rebin=1;

  TH3D *hcurT = (TH3D *) fcur->Get(Form("truePidLc%s",comb));
  TH3D *hcurP = (TH3D *) fcur->Get(Form("priorsLc%s",comb));
  TH3D *htrueLc = (TH3D *) fcur->Get(Form("trueLc"));
  TH3D *hmypidLc = (TH3D *) fcur->Get(Form("mypidLc"));

  TH3D *hpreT = (TH3D *) fpre->Get(Form("truePidLc%s",comb));
  TH3D *hpreP = (TH3D *) fpre->Get(Form("priorsLc%s",comb));

  TH3D *hPion = (TH3D *) fcur->Get("priorsLcPiPiPi");
//   hPion->Add((TH2D *) fcur->Get("priorsKsPiKa"));
//   hPion->Add((TH2D *) fcur->Get("priorsKsPiPr"));
//   hPion->Add((TH2D *) fcur->Get("priorsKsKaKa"));
//   hPion->Add((TH2D *) fcur->Get("priorsKsKaPr"));
//   hPion->Add((TH2D *) fcur->Get("priorsKsKaPi"));
//   hPion->Add((TH2D *) fcur->Get("priorsKsPrKa"));
//   hPion->Add((TH2D *) fcur->Get("priorsKsPrPr"));
//   hPion->Add((TH2D *) fcur->Get("priorsKsPrPi"));

  hcurT->RebinX(rebin);
  hcurP->RebinX(rebin);
  hpreT->RebinX(rebin);
  hpreP->RebinX(rebin);
  hPion->RebinX(rebin);
  htrueLc->RebinX(rebin);
  if(hmypidLc) hmypidLc->RebinX(rebin);

  TH1D *hprior = hcurP->ProjectionX("meas",hcurP->GetYaxis()->FindBin(ptmin+0.001),hcurP->GetYaxis()->FindBin(ptmax-0.001),0,-1);

  TH1D *htrue = hcurT->ProjectionX("true",hcurT->GetYaxis()->FindBin(ptmin+0.001),hcurT->GetYaxis()->FindBin(ptmax-0.001),0,-1);

  TH1D *hreal = htrueLc->ProjectionX("real",hcurT->GetYaxis()->FindBin(ptmin+0.001),hcurT->GetYaxis()->FindBin(ptmax-0.001),0,-1);

  TH1D *hmypid = NULL;
  if(hmypidLc) hmypid = hmypidLc->ProjectionX("mypid",hcurT->GetYaxis()->FindBin(ptmin+0.001),hcurT->GetYaxis()->FindBin(ptmax-0.001),0,-1);

  TH1D *hpriorOld = hpreP->ProjectionX("measOld",hpreP->GetYaxis()->FindBin(ptmin+0.001),hpreP->GetYaxis()->FindBin(ptmax-0.001),0,-1);

  TH1D *hnorm = hPion->ProjectionX("norm",hPion->GetYaxis()->FindBin(ptmin+0.001),hPion->GetYaxis()->FindBin(ptmax-0.001),0,-1);



  for(Int_t i=1;i <= hprior->GetNbinsX();i++){
    Float_t err = TMath::Abs(hprior->GetBinContent(i)-hpriorOld->GetBinContent(i));

    if(hnorm->GetBinContent(i) > hprior->GetBinContent(i)){
      err *= hnorm->GetBinContent(i);
      err /= hprior->GetBinContent(i);
    }

    err = sqrt(err*err + hprior->GetBinContent(i));

    if(err < 1) err = 1;

    if(htrue->GetBinError(i)<1)htrue->SetBinError(i,1);

    hprior->SetBinError(i,err);
    


  }

  TF1 *bw = new TF1("bw","gaus(0) + pol1(3)",2.23,2.35);
  TF1 *bwsig = new TF1("bw","gaus(0)",0.8,1);

  bw->SetLineColor(2);
  bw->SetParameter(0,100);
  bw->FixParameter(1,2.28646);
  bw->FixParameter(2,0.008);
  bw->SetParameter(3,0);
  bw->SetParameter(4,0);
  bw->SetParameter(5,0);

  TCanvas *c = new TCanvas();
  c->Divide(1,2);
  c->cd(1);
  hprior->Draw("ERR3");
  hprior->SetMinimum(0);
  htrue->Draw("SAME");
  htrue->SetLineColor(2);
  htrue->Fit(bw,"EI","",2.15,2.42);

  for(Int_t i=0;i < 3;i++) bwsig->SetParameter(i,bw->GetParameter(i));
  
  Float_t truesig = bwsig->Integral(2.28646-3*0.008,2.28646+3*0.008) / htrue->GetBinWidth(1);
  Float_t backgrd = bw->Integral(2.28646-3*0.008,2.28646+3*0.008) / htrue->GetBinWidth(1);
  backgrd -= truesig;

  hprior->Draw("SAME");
  hprior->Fit(bw,"EI","",2.15,2.42);

  Float_t fiterror = 0;
  if(bw->GetParameter(0)) fiterror = TMath::Abs(bw->GetParError(0)/bw->GetParameter(0));

  hreal->Draw("SAME");

  for(Int_t i=0;i < 3;i++) bwsig->SetParameter(i,bw->GetParameter(i));
  
  Float_t meassig = bwsig->Integral(2.28646-3*0.008,2.28646+3*0.008) / htrue->GetBinWidth(1);
					       
						
//   hpriorOld->SetLineColor(4);
//   hpriorOld->Draw("SAME");

//   for(Int_t i=1;i<= htrue->GetNbinsX();i++)
//     htrue->SetBinError(i,0);
  c->cd(2);
  bw->SetParameter(0,100);
  bw->SetParameter(3,0);
  bw->SetParameter(4,0);
  bw->SetParameter(5,0);

  TH1D *hr=new TH1D(*hprior);
  hr->GetYaxis()->SetTitle("(meas - true)/true");
  hr->Add(htrue,-1);
  hr->Divide(htrue);
  hr->Draw();
  hr->GetYaxis()->UnZoom();
  //  hr->Fit(bw,"","",0.8,1.);

  for(Int_t i=0;i < 3;i++) bwsig->SetParameter(i,bw->GetParameter(i));

  Float_t deltasig = bwsig->Integral(2.28646-3*0.008,2.28646+3*0.008) / hr->GetBinWidth(1);

  printf("signal = %f(true) %f(meas) -- delta  = %f (%f) --> Relative Error = %f(stat=%f, fit=%f)%c\n",truesig,meassig,meassig-truesig,deltasig,(meassig-truesig)/truesig*100,100./sqrt(TMath::Abs(truesig)),fiterror*100,'%');

  Float_t signal = hreal->Integral(1,hreal->GetNbinsX())*nev/nsig;
  Float_t signalback = signal + backgrd*nev/nback;
  Float_t signalmeas = meassig*nev/nsig;

  printf("significance = %f (yield=%f)\n",signal/sqrt(signalback),signal);
  printf("S/B = %f (back=%f)\n",signal/signalback,signalback);
  printf("significance measured = %f\n",signal/sqrt(signalback));

  printf("reco Lambdac = %i\n",hreal->Integral(1,hreal->GetNbinsX()));

  if(!hmypidLc) return;

  new TCanvas();
  hmypid->Draw();
  hmypid->Fit(bw,"EI","",2.15,2.42);
  for(Int_t i=0;i < 3;i++) bwsig->SetParameter(i,bw->GetParameter(i));

  Float_t mypidsig = bwsig->Integral(2.28646-3*0.008,2.28646+3*0.008) / hmypid->GetBinWidth(1);
  backgrd = bw->Integral(2.28646-3*0.008,2.28646+3*0.008) / hmypid->GetBinWidth(1);
  backgrd -= mypidsig;
  signal = mypidsig*nev/nsig;
  signalback = signal + backgrd*nev/nback;

  printf("my pid signal = %f\n",mypidsig);
  printf("my pid significance = %f\n",signal/sqrt(signalback));
}
コード例 #25
0
nu_pardecpoint_dists(){

    TFile *f1 = new TFile("numuCCAnalysis_output.root","READ");
    TTree *tf1 = (TTree*)f1->Get("default");
    
    double offset1_x = 0.18;
    double offset1_y = 0.45;
    double leg_x = 0.2;
    double leg_y = 0.35;
    
    double offset2_x = 0.6;
    double offset2_y = 0.45;
    
    //*************************************************************************************************//
    //**************************          dist for xyz          ***************************************//
    
    //dist x
    TH1D * h1 = new TH1D("h1","",35,-1.5,1.50);
    tf1->Draw("NuParentDecPoint[0]/100>>h1","");
    h1->GetXaxis()->SetTitle("ND280 Coord. x (m)");
    h1->GetYaxis()->SetTitle(Form("Entries/(%.2g m)",h1->GetBinWidth(1)));
    h1->SetLineWidth(3);
    h1->SetLineColor(2);
    h1->GetYaxis()->SetTitleOffset(1.4);
    
    Double_t yh1 = 1.05*h1->GetBinContent(h1->GetMaximumBin());
    h1->GetYaxis()->SetRangeUser(0,yh1);
    TLine *lineh1 = new TLine(h1->GetMean(),0,h1->GetMean(),yh1);
    lineh1->SetLineColor(1);
    lineh1->SetLineWidth(3);
    
    //TLegend * legh1 = TLegend(0.6,0.6,0.)
    
    TH1D * h2 = new TH1D("h2","",25, -7.35, 1.00);
    tf1->Draw("NuParentDecPoint[1]/100>>h2","");
    h2->GetXaxis()->SetTitle("ND280 Coord. y (m)");
    h2->GetYaxis()->SetTitle(Form("Entries/(%.2g m)",h2->GetBinWidth(1)));
    h2->SetLineWidth(3);
    h2->SetLineColor(2);
    h2->GetYaxis()->SetTitleOffset(1.4);
    
    Double_t yh2 = 1.05*h2->GetBinContent(h2->GetMaximumBin());
    h2->GetYaxis()->SetRangeUser(0,yh2);
    TLine *lineh2 = new TLine(h2->GetMean(),0,h2->GetMean(),yh2);
    lineh2->SetLineColor(1);
    lineh2->SetLineWidth(3);
    
    TH1D * h3 = new TH1D("h3","",30, -7.00, 110.00);
    tf1->Draw("NuParentDecPoint[2]/100>>h3","");
    h3->GetXaxis()->SetTitle("ND280 Coord. z (m)");
    h3->GetYaxis()->SetTitle(Form("Entries/(%.2g m)",h3->GetBinWidth(1)));
    h3->SetLineWidth(3);
    h3->SetLineColor(2);
    h3->GetYaxis()->SetTitleOffset(1.4);
    
    Double_t yh3 = 1.05*h3->GetBinContent(h3->GetMaximumBin());
    h3->GetYaxis()->SetRangeUser(0,yh3);
    TLine *lineh3 = new TLine(h3->GetMean(),0,h3->GetMean(),yh3);
    lineh3->SetLineColor(1);
    lineh3->SetLineWidth(3);
    
    TCanvas * c3 = new TCanvas("c3","",1450,550);
    c3->Divide(3);
    c3->cd(1);
    h1->Draw();
    lineh1->Draw();
    c3->cd(2);
    h2->Draw();
    lineh2->Draw();
    c3->cd(3);
    h3->Draw();
    lineh3->Draw();
    c3->Print("nu_parent_decay_point_xyz_dist.eps");
    
    TCanvas * c4 = new TCanvas("c4","",1450,550);
    
    TH3D * decpoint = new TH3D("decpoint","",35, -1.5, 1.5, 25, -7.35, 1.00, 30, -7.00, 110.00);
    tf1->Draw("NuParentDecPoint[2]/100:NuParentDecPoint[1]/100:NuParentDecPoint[0]/100>>decpoint","");
    //decpoint->SetTitle("");
    TCanvas * c4 = new TCanvas("c4","", 450, 450);
    decpoint->Draw("LEGO");
    c4->Print("3D_nu_parent_decay_point_xyz_dist.eps");
    
}
コード例 #26
0
ファイル: FillHists.cpp プロジェクト: aogaki/GridBI
void THisHandler::DefineHists()
{
   const Double_t areaL = 200.;
   const Double_t areaW = 140.;
   
   const Double_t plateL = 125.;
   const Double_t plateW = 82.4;
   //Double_t binW = 0.02;

   fHisAll = new TH3D("HisAll", "Deposited Energy",
                      Int_t(areaL), -areaL / 2., areaL / 2.,
                      Int_t(areaW), -areaW / 2., areaW / 2.,
                      450, -10., 35.);
   fHisAll->SetXTitle("[mm]");
   fHisAll->SetYTitle("[mm]");
   fHisAll->SetZTitle("[mm]");

   fHisSealing = new TH3D("HisSealing", "Deposited Energy at Sealing",
                          Int_t(areaL), -areaL / 2., areaL / 2.,
                          Int_t(areaW), -areaW / 2., areaW / 2.,
                          60, -6., 0.);
   fHisSealing->SetXTitle("[mm]");
   fHisSealing->SetYTitle("[mm]");
   fHisSealing->SetZTitle("[mm]");

   fHisWindow = new TH3D("HisWindow", "Deposited Energy at Window",
                         Int_t(areaL), -areaL / 2., areaL / 2.,
                         Int_t(areaW), -areaW / 2., areaW / 2.,
                         20, -1., 1.);
   fHisWindow->SetXTitle("[mm]");
   fHisWindow->SetYTitle("[mm]");
   fHisWindow->SetZTitle("[mm]");

   fHisFoil = new TH3D("HisFoil", "Deposited Energy at Foil",
                       Int_t(areaL), -areaL / 2., areaL / 2.,
                       Int_t(areaW), -areaW / 2., areaW / 2.,
                       15, 0., 1.5);
   fHisFoil->SetXTitle("[mm]");
   fHisFoil->SetYTitle("[mm]");
   fHisFoil->SetZTitle("[mm]");

   fHisHolder = new TH3D("HisHolder", "Deposited Energy at Holder",
                         Int_t(areaL), -areaL / 2., areaL / 2.,
                         Int_t(areaW), -areaW / 2., areaW / 2.,
                         30, 0., 3.);
   fHisHolder->SetXTitle("[mm]");
   fHisHolder->SetYTitle("[mm]");
   fHisHolder->SetZTitle("[mm]");

   fHisCassette = new TH3D("HisCassette", "Deposited Energy at Cassette",
                           Int_t(areaL), -areaL / 2., areaL / 2.,
                           Int_t(areaW), -areaW / 2., areaW / 2.,
                           300, 0., 30.);
   fHisCassette->SetXTitle("[mm]");
   fHisCassette->SetYTitle("[mm]");
   fHisCassette->SetZTitle("[mm]");

   fHisAir = new TH3D("HisAir", "Deposited Energy at Air",
                      Int_t(areaL), -areaL / 2., areaL / 2.,
                      Int_t(areaW), -areaW / 2., areaW / 2.,
                      300, 0., 30.);
   fHisAir->SetXTitle("[mm]");
   fHisAir->SetYTitle("[mm]");
   fHisAir->SetZTitle("[mm]");

   fHisPlate = new TH3D("HisPlate", "Deposited Energy at Plate",
                        Int_t(areaL), -areaL / 2., areaL / 2.,
                        Int_t(areaW), -areaW / 2., areaW / 2.,
                        300, 0., 30.);
   fHisPlate->SetXTitle("[mm]");
   fHisPlate->SetYTitle("[mm]");
   fHisPlate->SetZTitle("[mm]");

   fHisFilm = new TH3D("HisFilm", "Deposited Energy at Film",
                       Int_t(areaL), -areaL / 2., areaL / 2.,
                       Int_t(areaW), -areaW / 2., areaW / 2.,
                       300, 0., 30.);
   fHisFilm->SetXTitle("[mm]");
   fHisFilm->SetYTitle("[mm]");
   fHisFilm->SetZTitle("[mm]");

   fHisWell = new TH3D("HisWell", "Deposited Energy at Well",
                       Int_t(areaL), -areaL / 2., areaL / 2.,
                       Int_t(areaW), -areaW / 2., areaW / 2.,
                       300, 0., 30.);
   fHisWell->SetXTitle("[mm]");
   fHisWell->SetYTitle("[mm]");
   fHisWell->SetZTitle("[mm]");


   const Double_t wellPitch = 9.;
   const Double_t bin20W = 0.02;
   UInt_t hisIt = 0;
   for(Double_t y = -36.; y < 32.; y += 9.){
      for(Double_t x = -54.; x < 50.; x += 9.){
         TString name = "His20" + XYtoWell(x, y);
         TString title = "Deposited Energy at " + XYtoWell(x, y);
         fHisEachCell20[hisIt++] = new TH2D(name, title,
                                            Int_t(wellPitch / bin20W), x, x + wellPitch,
                                            Int_t(wellPitch / bin20W), y, y + wellPitch);
      }
   }
   
   const Double_t bin50W = 0.05;
   hisIt = 0;
   for(Double_t y = -36.; y < 32.; y += 9.){
      for(Double_t x = -54.; x < 50.; x += 9.){
         TString name = "His50" + XYtoWell(x, y);
         TString title = "Deposited Energy at " + XYtoWell(x, y);
         fHisEachCell50[hisIt++] = new TH2D(name, title,
                                            Int_t(wellPitch / bin50W), x, x + wellPitch,
                                            Int_t(wellPitch / bin50W), y, y + wellPitch);
      }
   }
      
}
コード例 #27
0
ファイル: hijingEPOSspectra.C プロジェクト: KongTu/V0sRatio
void hijingEPOSspectra(){

//HIJING:
	//TFile* file = new TFile("/Users/kongkong/2014Research/ROOT_file/newHIJINGsample/HIJING_18M_TH3D_Nov5_rpyDependent_vtxReweight_2014.root");
//EPOS:
	TFile* file = new TFile("/Users/kongkong/2014Research/ROOT_file/newEPOSsample/EPOS_TH3D_Nov6_rpyDependent_vertexReweight_2014.root");

	TH3D* ksHist;
	TH3D* laHist;
	TH3D* xiHist;

	TH3D* genksHist;
	TH3D* genlaHist;

	ksHist = (TH3D*)file->Get("ana/InvMass_ks_underlying");
	laHist = (TH3D*)file->Get("ana/InvMass_la_underlying");
	genksHist = (TH3D*)file->Get("ana/genKS_underlying");
	genlaHist = (TH3D*)file->Get("ana/genLA_underlying");
	xiHist = (TH3D*)file->Get("ana/XiDaughter");

	TH1D* ks_mass[5][28];
	TH1D* la_mass[5][20];
	TH1D* genks_mass[5][28];
	TH1D* genla_mass[5][20];
	TH1D* xiHist_mass[5][20];

    double ks_pTbinsBound[29] = {0,1,2,3,4,5,6,7,8,9,10,12,14,16,18,20,22,24,26,28,30,34,38,42,46,50,56,66,90};
    double ks_ptbins[29] = {0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.2,1.4,1.6,1.8,2.0,2.2,2.4,2.6,2.8,3.0,3.4,3.8,4.2,4.6,5.0,5.6,6.6,9.0};
    double ks_binwidth[28] = {0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.4,0.4,0.4,0.4,0.4,0.6,1.0,2.4};
    double ks_ptbincenter[28] = {0.05,0.15,0.25,0.35,0.45,0.55,0.65,0.75,0.85,0.95,1.1,1.3,1.5,1.7,1.9,2.1,2.3,2.5,2.7,2.9,3.2,3.6,4.0,4.4,4.8,5.3,6.1,7.8};

    double la_pTbinsBound[21] = {6,8,10,12,14,16,18,20,22,24,26,28,30,34,38,42,46,50,56,66,90};
    double la_ptbins[21] = {0.6,0.8,1.0,1.2,1.4,1.6,1.8,2.0,2.2,2.4,2.6,2.8,3.0,3.4,3.8,4.2,4.6,5.0,5.6,6.6,9.0};
    double la_ptbincenter[20] = {0.7,0.9,1.1,1.3,1.5,1.7,1.9,2.1,2.3,2.5,2.7,2.9,3.2,3.6,4.0,4.4,4.8,5.3,6.1,7.8};
    double la_binwidth[20] = {0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.4,0.4,0.4,0.4,0.4,0.6,1.0,2.4};

    double rpybins[6] = {6,16,26,35,44,55};
    double rpybinwidth[5] = {1.0,0.97,0.9,0.93,1.0};

    stringstream ksHistName;
    stringstream laHistName;
    stringstream xiHistName;

    for ( int rpy = 0; rpy < 5; rpy++){

    	for (int pt = 0; pt < 28; pt++){

    		ksHistName.str("");

    		ksHistName << "ks_";
	        ksHistName << rpy+1;
	        ksHistName << "_";
	        ksHistName << pt;

	        ks_mass[rpy][pt] = ksHist->ProjectionZ( ksHistName.str().c_str(),rpybins[rpy]+1,rpybins[rpy+1],ks_pTbinsBound[pt]+1,ks_pTbinsBound[pt+1] );

	        ksHistName.str("");

         	ksHistName << "genks_";
	        ksHistName << rpy+1;
	        ksHistName << "_";
	        ksHistName << pt;

	        genks_mass[rpy][pt] = genksHist->ProjectionZ( ksHistName.str().c_str(),rpybins[rpy]+1,rpybins[rpy+1],ks_pTbinsBound[pt]+1,ks_pTbinsBound[pt+1] );

    	}

	    for (pt = 0; pt < 20; pt++){

	        laHistName.str("");
	        xiHistName.str("");

	        laHistName << "la_";
	        laHistName << rpy+1;
	        laHistName << "_";
	        laHistName << pt;

	        xiHistName << "xiDau_";
	        xiHistName << rpy+1;
	        xiHistName << "_";
	        xiHistName << pt;

	        la_mass[rpy][pt] = laHist->ProjectionZ( laHistName.str().c_str(),rpybins[rpy]+1,rpybins[rpy+1],la_pTbinsBound[pt]+1,la_pTbinsBound[pt+1] );
	        xiHist_mass[rpy][pt] = xiHist->ProjectionZ( xiHistName.str().c_str(),rpybins[rpy]+1,rpybins[rpy+1],la_pTbinsBound[pt]+1,la_pTbinsBound[pt+1] );

	  
	        laHistName.str("");

	        laHistName << "genla_";
          	laHistName << rpy+1;
	        laHistName << "_";
	        laHistName << pt;

	        genla_mass[rpy][pt] = genlaHist->ProjectionZ( laHistName.str().c_str(),rpybins[rpy]+1,rpybins[rpy+1],la_pTbinsBound[pt]+1,la_pTbinsBound[pt+1] );
	   	
	   	}
   }

   	int genksYield[5][28];
   	int genlaYield[5][20];

   	for ( rpy = 0; rpy < 5; rpy++){


   		for( pt = 0; pt < 28; pt++){

   			genksYield[rpy][pt] = genks_mass[rpy][pt]->GetEntries();
   		}
	   	
	   	for (int i = 0; i < 20; i++){

	   		genlaYield[rpy][i] = genla_mass[rpy][i]->GetEntries();

	   	}
   	}	

   	double ksYield[5][28];
   	double laYield[5][20];

   	for ( rpy = 0; rpy < 5; rpy++){

   		for (pt = 0; pt < 28; pt++){

   			ksYield[rpy][pt] = ks_YieldCal( ks_mass[rpy][pt] );

   		}

	   	for ( i = 0; i < 20; i++){
	
			la_mass[rpy][i]->Add( xiHist_mass[rpy][i],-1 );
	   			laYield[rpy][i] = la_YieldCal( la_mass[rpy][i] );
	   	}
   	}

/*
Filling into spectrum
 */

	TH1D* ksSpectra_reco[5];
	TH1D* laSpectra_reco[5];

	TH1D* ksSpectra_gen[5];
	TH1D* laSpectra_gen[5];

	stringstream ksName;
	stringstream laName;

	for(rpy = 0; rpy < 5; rpy++){

		ksName.str("");
		laName.str("");

		ksName << "ksSpectra_epos_reco_";
		ksName << rpy+1;

		laName << "laSpectra_epos_reco_";
		laName << rpy+1;

		ksSpectra_reco[rpy] = new TH1D(ksName.str().c_str(),ksName.str().c_str(),28,ks_ptbins);
		laSpectra_reco[rpy] = new TH1D(laName.str().c_str(),laName.str().c_str(),20,la_ptbins);

		for(pt = 0; pt < 28; pt++){

			ksSpectra_reco[rpy]->SetBinContent(pt+1, ksYield[rpy][pt]/(2*3.1415926*ks_binwidth[pt]*ks_ptbincenter[pt]*rpybinwidth[rpy] ));
				ksSpectra_reco[rpy]->SetBinError(pt+1, sqrt( ksYield[rpy][pt] )/(2*3.1415926*ks_binwidth[pt]*ks_ptbincenter[pt]*rpybinwidth[rpy] ));

		}

		for(pt = 0; pt < 20; pt++){

			laSpectra_reco[rpy]->SetBinContent(pt+1, laYield[rpy][pt]/(2*3.1415926*la_binwidth[pt]*la_ptbincenter[pt]*rpybinwidth[rpy] ));
				laSpectra_reco[rpy]->SetBinError(pt+1, sqrt( laYield[rpy][pt] )/(2*3.1415926*la_binwidth[pt]*la_ptbincenter[pt]*rpybinwidth[rpy] ));

		}

		ksName.str("");
		laName.str("");

		ksName << "ksSpectra_epos_gen_";
		ksName << rpy+1;

		laName << "laSpectra_epos_gen_";
		laName << rpy+1;

		ksSpectra_gen[rpy] = new TH1D(ksName.str().c_str(),ksName.str().c_str(),28,ks_ptbins);
		laSpectra_gen[rpy] = new TH1D(laName.str().c_str(),laName.str().c_str(),20,la_ptbins);

		for(pt = 0; pt < 28; pt++){

			ksSpectra_gen[rpy]->SetBinContent(pt+1, genksYield[rpy][pt]/(2*3.1415926*ks_binwidth[pt]*ks_ptbincenter[pt]*rpybinwidth[rpy] ));
				ksSpectra_gen[rpy]->SetBinError(pt+1, sqrt( genksYield[rpy][pt] )/(2*3.1415926*ks_binwidth[pt]*ks_ptbincenter[pt]*rpybinwidth[rpy] ));

		}

		for(pt = 0; pt < 20; pt++){

			laSpectra_gen[rpy]->SetBinContent(pt+1, genlaYield[rpy][pt]/(2*3.1415926*la_binwidth[pt]*la_ptbincenter[pt]*rpybinwidth[rpy] ));
				laSpectra_gen[rpy]->SetBinError(pt+1, sqrt( genlaYield[rpy][pt] )/(2*3.1415926*la_binwidth[pt]*la_ptbincenter[pt]*rpybinwidth[rpy] ));

		}
	}
	

   	TFile f1("EPOSspectra_5rpyBins.root","new");
 
   	for ( rpy = 0; rpy < 5; rpy++){

   		ksSpectra_reco[rpy]->Write();
   		laSpectra_reco[rpy]->Write();
   	}

   	for ( rpy = 0; rpy < 5; rpy++){

   		ksSpectra_gen[rpy]->Write();
   		laSpectra_gen[rpy]->Write();
   	}






}
コード例 #28
0
void bkgndSubtraction  (char* inHistoName, char* outHistName,char* backgroundHisto, int extent, float modifier, TFile* inFile, TFile* outFile, TFile* backgroundFile)
{
  TH3D* in = (TH3D*) inFile->Get(inHistoName); // loads the input histo

  TH3D* bkgnd = (TH3D*) backgroundFile->Get(backgroundHisto); // loads the background histo

  // information to clone the axis to the out histogram
  int nBinsX = in->GetNbinsX();
  int nBinsY = in->GetNbinsY();
  int nBinsZ = in->GetNbinsZ();

  float xAxisMin = in->GetXaxis()->GetXmin();
  float xAxisMax = in->GetXaxis()->GetXmax();

  float yAxisMin = in->GetYaxis()->GetXmin();
  float yAxisMax = in->GetYaxis()->GetXmax();

  float zAxisMin = in->GetZaxis()->GetXmin();
  float zAxisMax = in->GetZaxis()->GetXmax();

  //******************** create output histograms

  char outHistNameN [25];
  char outHistNameP [25];

  strcpy (outHistNameN, outHistName);
  strcpy (outHistNameP, outHistName);

  strcat (outHistNameN, "N");
  strcat (outHistNameP, "P");

  TH3D* out  = new TH3D(outHistName,  outHistName,  nBinsX,xAxisMin,xAxisMax, nBinsY,yAxisMin,yAxisMax, nBinsZ,zAxisMin,zAxisMax); // total output
  TH3D* outN = new TH3D(outHistNameN, outHistNameN, nBinsX,xAxisMin,xAxisMax, nBinsY,yAxisMin,yAxisMax, nBinsZ,zAxisMin,zAxisMax); // where source < background
  TH3D* outP = new TH3D(outHistNameP, outHistNameP, nBinsX,xAxisMin,xAxisMax, nBinsY,yAxisMin,yAxisMax, nBinsZ,zAxisMin,zAxisMax); // where source > background

  // calculations for tests

  double nEntriesS = in->GetEntries();    //number of source entries
  double nEntriesB = bkgnd->GetEntries();  // number of background entries

  double vol = std::pow ( (float)(2*extent + 1), 3) ; // volume of the test region

  double volTotal = (nBinsX * nBinsY * nBinsZ);

  double threshold = modifier * std::sqrt ((nEntriesB+nEntriesS)/volTotal);  // <modifier> number of std deviations on the density of the test region 

  double scalingConst = nEntriesS / nEntriesB; // used to account for different numbers of muons

  //******************** run the test on all points

  for (int i = 0; i <= nBinsX; i++)
    {
      for (int j = 0; j<= nBinsY; j++)
	{
	  for (int k = 0; k <= nBinsZ; k++)
	    {

	      double sourceVal = 0;
	      double bkgndVal  = 0;

	      for (int x = -extent; x <= extent; x++)
		{
		  for (int y = -extent; y <= extent; y++)
		    {
		      for (int z = -extent; z <= extent; z++)
			{
			  sourceVal += in->GetBinContent ((i+x),(j+y),(k+z));
			  bkgndVal  += bkgnd->GetBinContent ((i+x),(j+y),(k+z));
			} 
		    }		  
		}
	      sourceVal = sourceVal /(vol*scalingConst);  // density to be tested
	      bkgndVal  = (bkgndVal*scalingConst)  /vol;  // expected density

	      if( std::fabs (sourceVal - bkgndVal) > threshold )// if there is a significant difference in densities 
		{
		  out->SetBinContent (i,j,k,1);
		  
		  if (sourceVal > bkgndVal)
		    {
		     outP->SetBinContent (i,j,k,1);
		    }
		  else if (sourceVal < bkgndVal)
		    {
		      outN->SetBinContent (i,j,k,1);
		    }		    
		}

	    }
	}
      if (!(i%10)) std::cout<<i<< " of " << nBinsX <<std::endl;
    }
  outFile->Add(out);
  outFile->Add(outP);
  outFile->Add(outN);

  std::cout<<(threshold)<<" threshold "<<std::endl;
}
コード例 #29
0
void eposClosureTestRapidity(){

	gStyle->SetErrorX(0);

	TFile* file = new TFile("~/2014Research/ROOT_file/V0reco_pPb_rpyDependent_3Dhisto/EPOS_TH3D_Oct3_rpyDependent_5M_2014.root");
	//TFile* file = new TFile("~/Desktop/EPOS_TH3D_Sep16_5M_v1_ptDist_2014.root");

	TH3D* ksHist;
	TH3D* laHist;
	TH3D* genksHist;
	TH3D* genlaHist;
	TH3D* xiHist;

	ksHist = (TH3D*)file->Get("ana/InvMass_ks_underlying");
	laHist = (TH3D*)file->Get("ana/InvMass_la_underlying");
	genksHist = (TH3D*)file->Get("ana/genKS_underlying");
	genlaHist = (TH3D*)file->Get("ana/genLA_underlying");
	xiHist = (TH3D*)file->Get("ana/XiDaughter");

	TH1D* ks_mass[5][20];
	TH1D* la_mass[5][20];
	TH1D* xiHist_mass[5][20];
	
	TH1D* genks_mass[20];
	TH1D* genla_mass[20];

    double pTbinsBound[19] = {10,12,14,16,18,20,22,24,26,28,30,34,38,42,46,50,56,66,90};
    double pTbinsBound_1[16] = {0,2,4,6,8,10,12,14,16,18,20,26,32,42,60,90};
    double ptbins[] = {1.0,1.2,1.4,1.6,1.8,2.0,2.2,2.4,2.6,2.8,3.0,3.4,3.8,4.2,4.6,5.0,5.6,6.6,9.0};
    double ptbins_1[] = {0,0.2,0.4,0.6,0.8,1.0,1.2,1.4,1.6,1.8,2.0,2.6,3.2,4.2,6.0,9.0};
    double binwidth[18] = {0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.4,0.4,0.4,0.4,0.4,0.6,1.0,1.4};
    double binwidth_1[15] = {0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.6,0.6,1.0,1.8,3.0};

    double rpybins[6] = {6,16,26,35,44,55};

    stringstream ksHistName;
    stringstream laHistName;
    stringstream xiHistName;


    for ( int rpy = 0; rpy < 5; rpy++){

	    for (int pt = 0; pt < 18; pt++){

	        ksHistName.str("");
	        laHistName.str("");
	        xiHistName.str("");

	        ksHistName << "ks_";
	        ksHistName << rpy+1;
	        ksHistName << "_";
	        ksHistName << pt;

	        laHistName << "la_";
	        laHistName << rpy+1;
	        laHistName << "_";
	        laHistName << pt;

	        xiHistName << "xiDau_";
	        xiHistName << rpy+1;
	        xiHistName << "_";
	        xiHistName << pt;

	        ks_mass[rpy][pt] = ksHist->ProjectionZ( ksHistName.str().c_str(),rpybins[rpy]+1,rpybins[rpy+1],pTbinsBound[pt]+1,pTbinsBound[pt+1] );
	        la_mass[rpy][pt] = laHist->ProjectionZ( laHistName.str().c_str(),rpybins[rpy]+1,rpybins[rpy+1],pTbinsBound[pt]+1,pTbinsBound[pt+1] );
	        xiHist_mass[rpy][pt] = xiHist->ProjectionZ( xiHistName.str().c_str(),rpybins[rpy]+1,rpybins[rpy+1],pTbinsBound[pt]+1,pTbinsBound[pt+1] );

	        ksHistName.str("");
	        laHistName.str("");

	        ksHistName << "genks_";
	        ksHistName << pt;

	        laHistName << "genla_";
	        laHistName << pt;

	        genks_mass[pt] = genksHist->ProjectionZ( ksHistName.str().c_str(),1,70,pTbinsBound[pt]+1,pTbinsBound[pt+1] );
	        genla_mass[pt] = genlaHist->ProjectionZ( laHistName.str().c_str(),1,70,pTbinsBound[pt]+1,pTbinsBound[pt+1] );
	   	
	   	}
   }

	double genksYield[20];
	double genlaYield[20];

	TH1D* genksSpectra = new TH1D("genksSpectra","genK0short pT spectra",18,ptbins);
	TH1D* genlaSpectra = new TH1D("genlaSpectra","genLambda pT spectra",18,ptbins);


	for(pt = 0; pt < 18; pt++){

		genksYield[pt] = genks_mass[pt]->GetEntries();
			//genksSpectra->SetBinContent( pt+1, genksYield[eta][pt]/(4.8*binwidth_1[pt]) );

		genlaYield[pt] = genla_mass[pt]->GetEntries();
			//genlaSpectra->SetBinContent( pt+1, genlaYield[pt]/(4.8*binwidth_1[pt]) );

	}
	

	double ksYield[5][20];
	double laYield[5][20];


/**
 * Getting efficiency from the table:
 */
    /*
    TFile* t1 = new TFile("/Users/kongkong/2014Research/Code/Jet'study/gitV0sRatio/hijingEfficiencyRapidityTable/effKongNew2DTable_18M_Oct2_rapidity_v1_18pTbins.root");
    //TFile* t1 = new TFile("~/Desktop/Efficiency2D_V0_10M.root");
    
    TH2D* hnew1 = (TH2D*)t1->Get("ks_eff");
    TH2D* hnew2 = (TH2D*)t1->Get("la_eff");

    double ks_eff[5][20];
    double la_eff[5][20];

    double ks_eff_err[5][20];
    double la_eff_err[5][20];

    for (int i = 0; i < 5; i++){

        for (int r = 0; r < 18; r++){

            ks_eff[i][r] = hnew1->GetBinContent(i+1,r+1);
            	
            	ks_eff_err[i][r] = hnew1->GetBinError(i+1,r+1);
            
            la_eff[i][r] = hnew2->GetBinContent(i+1,r+1);
            	
            	la_eff_err[i][r] = hnew2->GetBinError(i+1,r+1);

        }
    }*/

        //TFile* t1 = new TFile("~/2014Research/Code/Jet'study/gitV0sRatio/eff_2Dtable.root");
    TFile* t1 = new TFile("~/2014Research/Code/Jet'study/gitV0sRatio/hijingEfficiencyRapidityTable/effKongNew2DTable_18M_Oct2_rapidity_v1_18pTbins.root");
    
    TH2D* hnew1 = (TH2D*)t1->Get("ks_eff");
    TH2D* hnew2 = (TH2D*)t1->Get("la_eff");

    TH1D* ks_eff_hist[5];
    TH1D* la_eff_hist[5];

    double ks_eff[5][20];
    double la_eff[5][20];

    double ks_eff_err[5][20];
    double la_eff_err[5][20];

    stringstream ksEffName;
    stringstream laEffName;

    for(rpy = 0; rpy < 5; rpy++){

        ksEffName.str("");
        laEffName.str("");

        ksEffName << "kshist_";
        ksEffName << rpy+1;

        laEffName << "lahist_";
        laEffName << rpy+1;

        ks_eff_hist[rpy] = hnew1->ProjectionY(ksEffName.str().c_str(), rpy+1,rpy+1 );
            ks_eff_hist[rpy]->Smooth(10);
        la_eff_hist[rpy] = hnew2->ProjectionY(laEffName.str().c_str(), rpy+1,rpy+1 );
            la_eff_hist[rpy]->Smooth(10);

    }

/*
smoothing the efficiency:
 */

    for(rpy = 0; rpy < 5; rpy++){

        for(pt = 0; pt < 18; pt++){

            ks_eff[rpy][pt] = ks_eff_hist[rpy]->GetBinContent( pt+1 );

                ks_eff_err[rpy][pt] = ks_eff_hist[rpy]->GetBinError( pt+1 );

            la_eff[rpy][pt] = la_eff_hist[rpy]->GetBinContent( pt+1 );

                la_eff_err[rpy][pt] = la_eff_hist[rpy]->GetBinError( pt+1 );  
        }
    }

    double ks_pTYield[20];
	double la_pTYield[20];

	double ks_pTYield_err[20];
	double la_pTYield_err[20];

	double temp_ks_err[5];
	double num_ks_err[20];
	double temp_la_err[5];
	double num_la_err[20];

	double temp = 0;


    for (pt = 0; pt < 18; pt++){

    	ks_pTYield[pt] = 0;
    	la_pTYield[pt] = 0;

    	for (rpy = 0; rpy < 5; rpy++){

    		ksYield[rpy][pt] = ks_YieldCal( ks_mass[rpy][pt] );

    		double ksYield_err = sqrt( ksYield[rpy][pt] );
    		temp_ks_err[rpy] = errorCal_num(ksYield[rpy][pt], ksYield_err, ks_eff[rpy][pt], ks_eff_err[rpy][pt]);
    		
    				ksYield[rpy][pt] = ksYield[rpy][pt]/ks_eff[rpy][pt];

    			ks_pTYield[pt] = ksYield[rpy][pt] + ks_pTYield[pt];


    		la_mass[rpy][pt]->Add( xiHist_mass[rpy][pt], -1);
    		laYield[rpy][pt] = la_YieldCal( la_mass[rpy][pt] );

    		double laYield_err = sqrt( laYield[rpy][pt] );
    		temp_la_err[rpy] = errorCal_num(laYield[rpy][pt], laYield_err, la_eff[rpy][pt], la_eff_err[rpy][pt]);
    		
    				laYield[rpy][pt] = laYield[rpy][pt]/la_eff[rpy][pt];

    			la_pTYield[pt] = laYield[rpy][pt] + la_pTYield[pt];

    	}

    	num_ks_err[pt] = errorCal_sum(temp_ks_err[0], temp_ks_err[1], temp_ks_err[2], temp_ks_err[3], temp_ks_err[4], temp_ks_err[5]);
    	num_la_err[pt] = errorCal_sum(temp_la_err[0], temp_la_err[1], temp_la_err[2], temp_la_err[3], temp_la_err[4], temp_la_err[5]);
    }


	TH1D* ks_close = new TH1D("ks_close","ks_close",18,ptbins);
	TH1D* la_close = new TH1D("la_close","la_close",18,ptbins);

	for (pt = 0; pt < 18; pt++){

		ks_close->SetBinContent(pt+1, ks_pTYield[pt]/genksYield[pt] );

			double error_genks = sqrt( genksYield[pt] );
			double error_ks = errorCal_num( ks_pTYield[pt], num_ks_err[pt], genksYield[pt], error_genks );
		ks_close->SetBinError(pt+1, error_ks);

		la_close->SetBinContent(pt+1, la_pTYield[pt]/genlaYield[pt] );

			double error_genla = sqrt( genlaYield[pt] );
			double error_la = errorCal_num( la_pTYield[pt], num_la_err[pt], genlaYield[pt], error_genla );
		la_close->SetBinError(pt+1, error_la);

	}
	

	/*
	TLatex* etarange[6];

	etarange[0] = new TLatex(2,1.3,"-2.4 < #eta < -1.6");
	etarange[1] = new TLatex(2,1.3,"-1.6 < #eta < -0.8");
	etarange[2] = new TLatex(2,1.3,"-0.8 < #eta < 0");
	etarange[3] = new TLatex(2,1.3,"0 < #eta < 0.8");
	etarange[4] = new TLatex(2,1.3,"0.8 < #eta < 1.6");
	etarange[5] = new TLatex(2,1.3,"1.6 < #eta < 2.4");

	TCanvas* wq1 = new TCanvas();
    gStyle->SetOptTitle(0);
    gStyle->SetPadBorderMode(0);
    gStyle->SetTitleX(0.15);

    wq1->Divide(2,3,0,0);

    for (eta = 0; eta < 6; eta++){

    	wq1->cd(eta+1);
    	gPad->SetTicks();

    	ks_close[eta]->SetStats(kFALSE);
        ks_close[eta]->GetXaxis()->SetTitleOffset(1.0);
        ks_close[eta]->GetYaxis()->SetTitleOffset(1.0);
        ks_close[eta]->GetXaxis()->SetTitleSize(0.05);
        ks_close[eta]->GetYaxis()->SetTitleSize(0.05);
        ks_close[eta]->GetXaxis()->SetLabelSize(0.06);
        ks_close[eta]->GetYaxis()->SetLabelSize(0.06);

        ks_close[eta]->SetYTitle("K^{0}_{s} RECO/GEN");
        ks_close[eta]->SetXTitle("P^{}_{T,V0}(GeV/c)");
        ks_close[eta]->SetMarkerStyle(2);
        ks_close[eta]->SetMarkerSize(1.2);
        ks_close[eta]->SetMarkerColor(kBlue);
        ks_close[eta]->GetYaxis()->SetRangeUser(0.8,1.4);    

        ks_close[eta]->Draw("P");
        etarange[eta]->Draw("same");

    }

    TCanvas* wq2 = new TCanvas();
    gStyle->SetOptTitle(0);
    gStyle->SetPadBorderMode(0);
    gStyle->SetTitleX(0.15);

    wq2->Divide(2,3,0,0);

    for (eta = 0; eta < 6; eta++){

    	wq2->cd(eta+1);
    	gPad->SetTicks();

    	la_close[eta]->SetStats(kFALSE);
        la_close[eta]->GetXaxis()->SetTitleOffset(1.0);
        la_close[eta]->GetYaxis()->SetTitleOffset(1.0);
        la_close[eta]->GetXaxis()->SetTitleSize(0.05);
        la_close[eta]->GetYaxis()->SetTitleSize(0.05);
        la_close[eta]->GetXaxis()->SetLabelSize(0.06);
        la_close[eta]->GetYaxis()->SetLabelSize(0.06);

        la_close[eta]->SetYTitle("#Lambda/#bar{#Lambda} RECO/GEN");
        la_close[eta]->SetXTitle("P^{}_{T,V0}(GeV/c)");
        la_close[eta]->SetMarkerStyle(2);
        la_close[eta]->SetMarkerSize(1.2);
        la_close[eta]->SetMarkerColor(kBlue);
        la_close[eta]->GetYaxis()->SetRangeUser(0.7,1.4);    

        la_close[eta]->Draw("P");
        etarange[eta]->Draw("same");

    }*/
   	cout << "EPOS genLa 1st:  " << genlaYield[3] << endl;
    cout << "EPOS recola 1st: " << la_pTYield[3] << endl;

    cout << "EPOS genLa 2nd:  " << genlaYield[4] << endl;
    cout << "EPOS recola 2nd: " << la_pTYield[4] << endl;

    cout << "EPOS genLa 3rd:  " << genlaYield[5] << endl;
    cout << "EPOS recola 3rd: " << la_pTYield[5] << endl;

	TFile f1("eposClosureTestResult_wErr_withXiRemovel_v2_smooth10_rpy_18pTBins.root","new");

	ks_close->Write();
	la_close->Write();

	
	



}
コード例 #30
0
ファイル: Pi0Hist.C プロジェクト: collicott/old-working-acqu
void M2gHist( UInt_t chan)
{
	UInt_t cbin;
	Double_t factor;
	TString name;

	TFile* file;

	cbin = chan+1;

	// Target FULL
	// Prompt
	TH2D *hP = (TH3D*)full.Get( "THR_M2gTaggP_v_TChanM2gP");
	hP->GetXaxis()->SetRange( cbin, cbin);
	TH1D *hPf_y = hP->ProjectionY( "M2gP");

	// Random
	TH3D *hR = (TH3D*)full.Get( "THR_M2gTaggR_v_TChanM2gR");
	hR->GetXaxis()->SetRange( cbin, cbin);
	TH1D *hRf_y = hR->ProjectionY( "M2gR");
	hRf_y->Scale( 0.5);

	// Subtracted
	hSf = (TH1D*) hPf_y->Clone( "FullSubt");
	hSf->Sumw2();
	hSf->Add( hRf_y, -1.0);

	// Target EMPTY
	// Prompt
	TH2D *hP = (TH3D*)empty.Get( "THR_M2gTaggP_v_TChanM2gP");
	hP->GetXaxis()->SetRange( cbin, cbin);
	TH1D *hPf_y = hP->ProjectionY( "M2gP");

	// Random
	TH3D *hR = (TH3D*)empty.Get( "THR_M2gTaggR_v_TChanM2gR");
	hR->GetXaxis()->SetRange( cbin, cbin);
	TH1D *hRe_y = hR->ProjectionY( "M2gR");
	hRe_y->Scale( 0.5);

	// Subtracted
	hSe = (TH1D*) hPe_y->Clone( "EmptySubt");
	hSe->Sumw2();
	hSe->Add( hRe_y, -1.0);

	// COMPLETELY SUBTRACTED

	// Dead-time correction
	file = full;
	f_dead_f = DeadTimeSF( file);
	file = empty;
	f_dead_e = DeadTimeSF( file);

	// Scale full to empty
	factor = HistSF( hesc, hfsc, cbin, cbin)*f_dead_f/f_dead_e;

	hSf->Scale( factor);
	hS = (TH1D*) hSf->Clone( "Subtracted");
	hS->Add( hSe, -1.0);

	fhist = (TH1D*) hSf->Clone( "Full");
	ehist = (TH1D*) hSe->Clone( "Empty");
	shist = (TH1D*) hS->Clone( "Subt");
}