Ejemplo n.º 1
0
CalibTree::CalibTree(TTree *tree) : fChain(0) {
  // if parameter tree is not specified (or zero), connect the file
  // used to generate this class and read the Tree.
  if (tree == 0) {
    TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject("output.root");
    if (!f || !f->IsOpen()) {
      f = new TFile("output.root");
    }
    TDirectory * dir = (TDirectory*)f->Get("output.root:/isopf");
    dir->GetObject("CalibTree",tree);
  }
  Init(tree);
}
Ejemplo n.º 2
0
NeroTree::NeroTree(TTree *tree) : fChain(0) 
{
// if parameter tree is not specified (or zero), connect the file
// used to generate this class and read the Tree.
   if (tree == 0) {
      TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject("root://eoscms.cern.ch//store/user/yiiyama/nero/DYJetsToLL_M-50_TuneCUETP8M1_13TeV-amcatnloFXFX-pythia8+RunIISpring15DR74-Asympt25ns_MCRUN2_74_V9-v3+AODSIM/nero_0000.root");
      if (!f || !f->IsOpen()) {
         f = new TFile("root://eoscms.cern.ch//store/user/yiiyama/nero/DYJetsToLL_M-50_TuneCUETP8M1_13TeV-amcatnloFXFX-pythia8+RunIISpring15DR74-Asympt25ns_MCRUN2_74_V9-v3+AODSIM/nero_0000.root");
      }
      TDirectory * dir = (TDirectory*)f->Get("root://eoscms.cern.ch//store/user/yiiyama/nero/DYJetsToLL_M-50_TuneCUETP8M1_13TeV-amcatnloFXFX-pythia8+RunIISpring15DR74-Asympt25ns_MCRUN2_74_V9-v3+AODSIM/nero_0000.root:/nero");
      dir->GetObject("events",tree);

   }
   Init(tree);
}
Ejemplo n.º 3
0
void HHbbbbMikeBase(int wMs,int wM, string st,string st2,string option=""){	
	//1=signal ,0=QCD ,2=data-----------------------------------------------------------
	int nameRoot=1;
	if(st2.find("QCD")!= std::string::npos)nameRoot=0;
	if(st2.find("data")!= std::string::npos)nameRoot=2;
	//---------------------Thea correction
	TFile *f3;
	f3=TFile::Open("puppiCorr.root");
	TF1 * puppisd_corrGEN,* puppisd_corrRECO_cen,* puppisd_corrRECO_for;
	puppisd_corrGEN=(TF1 *) f3->FindObjectAny("puppiJECcorr_gen");
	puppisd_corrRECO_cen=(TF1 *) f3->FindObjectAny("puppiJECcorr_reco_0eta1v3");
	puppisd_corrRECO_for=(TF1 *) f3->FindObjectAny("puppiJECcorr_reco_1v3eta2v5");
	TF1* tf1[3];
	tf1[0]=puppisd_corrGEN;
	tf1[1]=puppisd_corrRECO_cen;
	tf1[2]=puppisd_corrRECO_for;
	//option-----------------------------------------------------------
	int JESOption=0;
	if(option.find("JESUp")!= std::string::npos)JESOption=1;
	if(option.find("JESDown")!= std::string::npos)JESOption=2;
	if(option.find("BtagUp")!= std::string::npos)JESOption=3;
	if(option.find("BtagDown")!= std::string::npos)JESOption=4;
	if(option.find("tau21Up")!= std::string::npos)JESOption=5;
	if(option.find("tau21Down")!= std::string::npos)JESOption=6;
	cout<<"JESOption = "<<JESOption<<endl;
	bool printHighPtSubjet=0;
	bool isFast=1;
	//tuple tree and cutflow variables------------------------------------------------------------------------------------
	TFile *f;
	TTree *tree;
	int nPass[20]={0},total=0,dataPassingcsc=0;
	double nPassB[6]={0};
	double fixScaleNum[2]={0};
	//using for Btag Eff -----------------------------------------------------------------------------
	string btagsystematicsType="central";
	if(JESOption==3)btagsystematicsType="up";
	else if(JESOption==4)btagsystematicsType="down";
	BTagCalibration calib("CSVv2L", "subjet_CSVv2_ichep.csv");
	BTagCalibrationReader LF(BTagEntry::OP_LOOSE,"central", {"up", "down"});  
	BTagCalibrationReader HFC(BTagEntry::OP_LOOSE, "central", {"up", "down"});      // other sys types
	BTagCalibrationReader HF(BTagEntry::OP_LOOSE,"central",{"up", "down"});      // other sys types
	LF.load(calib, BTagEntry::FLAV_UDSG,    // btag flavour
            "incl");               // measurement type
	HFC.load(calib, BTagEntry::FLAV_C,    // btag flavour
            "lt");               // measurement type
	HF.load(calib, BTagEntry::FLAV_B,    // btag flavour
            "lt");               // measurement type
	
	TFile *f1;
	if(nameRoot==2)f1=TFile::Open("btagEffSource/data.root");
	else if (nameRoot!=2 && (JESOption==0||JESOption==3||JESOption==4||JESOption==5||JESOption==6))f1=TFile::Open(Form("btagEffSource/%s.root",st2.data()));
	else if (nameRoot!=2 && JESOption==1)f1=TFile::Open(Form("btagEffSource/%s_JESUp.root",st2.data()));
	else if (nameRoot!=2 && JESOption==2)f1=TFile::Open(Form("btagEffSource/%s_JESDown.root",st2.data()));
	TH1D* th1[6];
	string btaggingEff[6]={"effD_b","effN_b","effD_c","effN_c","effD_l","effN_l"};
	for(int i=0;i<6;i++){
		th1[i]=(TH1D*)f1->FindObjectAny(Form("%s_1d",btaggingEff[i].data()));
		if(i==1||i==3||i==5)th1[i]->Divide(th1[i-1]);
	}
	//check for zero btagging SF----------------------------------------------------------------------------------------
	TH2D* th3[6];
	th3[0]=new TH2D("zeroSF_b","zeroSF_b",200,0,2000,60,-3,3);
	th3[1]=new TH2D("zeroSF_c","zeroSF_c",200,0,2000,60,-3,3);
	th3[2]=new TH2D("zeroSF_l","zeroSF_l",200,0,2000,60,-3,3);
	th3[3]=new TH2D("SF_vs_Pt_b","SF_vs_Pt_b",120,0,1200,40,0.8,1.2);
	th3[4]=new TH2D("SF_vs_Pt_c","SF_vs_Pt_c",120,0,1200,40,0.8,1.2);
	th3[5]=new TH2D("SF_vs_Pt_l","SF_vs_Pt_l",120,0,1200,40,0.8,1.2);
	for(int i=0;i<6;i++)th3[i]->Sumw2();
	//check for high btagging SF----------------------------------------------------------------------------------------
	TH1D* th4[14];
	string SF_jet_sub[8]={"SF_jet0_sub0_pass","SF_jet0_sub1_pass","SF_jet1_sub0_pass","SF_jet1_sub1_pass","SF_jet0_sub0_fail","SF_jet0_sub1_fail","SF_jet1_sub0_fail","SF_jet1_sub1_fail"};
	for(int i=0;i<8;i++)th4[i]=new TH1D(Form("%s",SF_jet_sub[i].data()),Form("%s",SF_jet_sub[i].data()),40,0.8,1.2);
	string weightName[6]={"weight","weight_0b","weight_1b","weight_2b","weight_2b_ll","weight_2b_onel"};
	for(int i=0;i<6;i++)th4[i+8]=new TH1D(Form("%s",weightName[i].data()),Form("%s",weightName[i].data()),40,0,2);
	for(int i=0;i<14;i++)th4[i]->Sumw2();
	//saving variables----------------------------------------------------------------------------------------
	TH1D * th5[300],* th6[300];
	for(int i=0;i<2;i++){
		for(int j=0;j<2;j++){
			for(int k=0;k<5;k++){
				th5[(i*2+j)*5+k]=new TH1D(Form("Pt_j%d_sj%d_%db",i,j,k),Form("Pt_j%d_sj%d_%db",i,j,k),200,0,2000);
				th5[(i*2+j)*5+k+20]=new TH1D(Form("Eta_j%d_sj%d_%db",i,j,k),Form("Eta_j%d_sj%d_%db",i,j,k),60,-3,3);
				th5[(i*2+j)*5+k+85]=new TH1D(Form("subCSV_j%d_sj%d_%db",i,j,k),Form("subCSV_j%d_sj%d_%db",i,j,k),20,0,1);
				th5[(i*2+j)*5+k+194]=new TH1D(Form("subCSVCut_j%d_sj%d_%db",i,j,k),Form("subCSVCut_j%d_sj%d_%db",i,j,k),20,0,1);
			}
		}
		for(int k=0;k<5;k++){
			th5[i*5+k+40]=new TH1D(Form("deltaR_j%d_%db",i,k),Form("deltaR_j%d_%db",i,k),20,0,1);
			th5[i*5+k+50]=new TH1D(Form("Pt_j%d_%db",i,k),Form("Pt_j%d_%db",i,k),200,0,2000);
			th5[i*5+k+60]=new TH1D(Form("Eta_j%d_%db",i,k),Form("Eta_j%d_%db",i,k),60,-3,3);
			th5[i*5+k+70]=new TH1D(Form("prMassL2L3_j%d_%db",i,k),Form("prMassL2L3_j%d_%db",i,k),15,90,150);
			th5[i*5+k+105]=new TH1D(Form("tau21_j%d_%db",i,k),Form("tau21_j%d_%db",i,k),25,0,1);
			th5[i*5+k+120]=new TH1D(Form("PuppiSDMassL2L3_j%d_%db",i,k),Form("PuppiSDMassL2L3_j%d_%db",i,k),15,90,150);
			th5[i*5+k+130]=new TH1D(Form("puppiTau21_j%d_%db",i,k),Form("puppiTau21_j%d_%db",i,k),25,0,1);
			th5[i*5+k+140]=new TH1D(Form("prMass_j%d_%db",i,k),Form("prMass_j%d_%db",i,k),15,90,150);
			th5[i*5+k+150]=new TH1D(Form("PuppiSDMass_j%d_%db",i,k),Form("PuppiSDMass_j%d_%db",i,k),15,90,150);
			th5[i*5+k+170]=new TH1D(Form("doubleSV_j%d_%db",i,k),Form("doubleSV_j%d_%db",i,k),40,-1,1);
			th5[i*5+k+184]=new TH1D(Form("FatSV_j%d_%db",i,k),Form("FatSV_j%d_%db",i,k),20,0,1);
			th5[i*5+k+250]=new TH1D(Form("PuppiSDMassThea_j%d_%db",i,k),Form("PuppiSDMassThea_j%d_%db",i,k),15,90,150);
		}
	}
	for(int k=0;k<5;k++){
		th5[k+80]=new TH1D(Form("totalMass_%db",k),Form("totalMass_%db",k),200,1000,5000);
		th5[k+115]=new TH1D(Form("deltaEta_%db",k),Form("deltaEta_%db",k),40,0,2);
		th5[k+160]=new TH1D(Form("logPt_%db",k),Form("logPt_%db",k),70,0,7);
		th5[k+165]=new TH1D(Form("totalMassRed_%db",k),Form("totalMassRed_%db",k),200,1000,5000);
	}
	th5[180]= new TH1D("h_nvtx","h_nvtx",60,0,60);
	th5[181]= new TH1D("h_ntrue","h_ntrue",60,0,60);
	th5[182]= new TH1D("h_nvtx_cut","h_nvtx_cut",60,0,60);
	th5[183]= new TH1D("h_ntrue_cut","h_ntrue_cut",60,0,60);
	
	string prMass_no[4]={"prMass","prMassL2L3","PuppiSDMass","PuppiSDMassL2L3"};
	string tau21_no[2]={"tau21","puppiTau21"};
	for (int i=0;i<4;i++){
		th5[214+i*2]=new TH1D(Form("%s_j0_noPr_noTau21",prMass_no[i].data()),Form("%s_j0_noPr_noTau21",prMass_no[i].data()),200,0,200);
		th5[215+i*2]=new TH1D(Form("%s_j1_noPr_noTau21",prMass_no[i].data()),Form("%s_j1_noPr_noTau21",prMass_no[i].data()),200,0,200);
		th5[222+i*2]=new TH1D(Form("%s_j0_noPr",prMass_no[i].data()),Form("%s_j0_noPr",prMass_no[i].data()),200,0,200);
		th5[223+i*2]=new TH1D(Form("%s_j1_noPr",prMass_no[i].data()),Form("%s_j1_noPr",prMass_no[i].data()),200,0,200);
		th5[230+i*2]=new TH1D(Form("%s_j0_noTau21",prMass_no[i].data()),Form("%s_j0_noTau21",prMass_no[i].data()),15,90,150);
		th5[231+i*2]=new TH1D(Form("%s_j1_noTau21",prMass_no[i].data()),Form("%s_j1_noTau21",prMass_no[i].data()),15,90,150);
	}
	for (int i=0;i<2;i++){
		th5[238+i*2]=new TH1D(Form("%s_j0_noPr_noTau21",tau21_no[i].data()),Form("%s_j0_noPr_noTau21",tau21_no[i].data()),25,0,1);
		th5[239+i*2]=new TH1D(Form("%s_j1_noPr_noTau21",tau21_no[i].data()),Form("%s_j1_noPr_noTau21",tau21_no[i].data()),25,0,1);
		th5[242+i*2]=new TH1D(Form("%s_j0_noPr",tau21_no[i].data()),Form("%s_j0_noPr",tau21_no[i].data()),25,0,1);
		th5[243+i*2]=new TH1D(Form("%s_j1_noPr",tau21_no[i].data()),Form("%s_j1_noPr",tau21_no[i].data()),25,0,1);
		th5[246+i*2]=new TH1D(Form("%s_j0_noTau21",tau21_no[i].data()),Form("%s_j0_noTau21",tau21_no[i].data()),25,0,1);
		th5[247+i*2]=new TH1D(Form("%s_j1_noTau21",tau21_no[i].data()),Form("%s_j1_noTau21",tau21_no[i].data()),25,0,1);
	}
	string flavor[4]={"bb","b","cc","udscg"};
	for (int i=0;i<4;i++){
		th5[260+i]=new TH1D(Form("Pt_j0_0b_%s",flavor[i].data()),Form("Pt_j0_0b_%s",flavor[i].data()),200,0,2000);
		th5[264+i]=new TH1D(Form("Pt_j0_1b_%s",flavor[i].data()),Form("Pt_j0_1b_%s",flavor[i].data()),200,0,2000);
		th5[268+i]=new TH1D(Form("Pt_j0_2b_%s",flavor[i].data()),Form("Pt_j0_2b_%s",flavor[i].data()),200,0,2000);
		th5[272+i]=new TH1D(Form("Pt_j0_DSV_%s",flavor[i].data()),Form("Pt_j0_DSV_%s",flavor[i].data()),200,0,2000);
	}
	
	for(int i=0;i<276;i++){
		th6[i]=(TH1D* )th5[i]->Clone(Form("%ss",th5[i]->GetTitle()));
		th5[i]->Sumw2();
		th6[i]->Sumw2();
	}
	//pileup uncertainty----------------------------------------------------------------------------------------
	TH1D* th7[14];
	th7[0]=new TH1D("totalMass","totalMass",200,1000,5000);
	th7[1]=new TH1D("totalMass_pileup_up","totalMass_pileup_up",200,1000,5000);
	th7[2]=new TH1D("totalMass_pileup_down","totalMass_pileup_down",200,1000,5000);
	th7[3]=new TH1D("pileupEff","pileupEff",15,0.5,15.5);
	double totalPileup[3]={0},passPileup[3]={0};
	standalone_LumiReWeighting LumiWeights_central(0),LumiWeights_up(1),LumiWeights_down(-1);
	//PDF uncertainty
	th7[4]=new TH1D("PDFEff","PDFEff",101,0.5,101.5);
	double passPDF[101]={0},totalPDF[101]={0};
	//QCD uncertainty
	for(int i=5;i<14;i++)th7[i]=new TH1D(Form("uns_QCD_%d",i-5),Form("uns_QCD_%d",i-5),200,1000,5000);
	
	
	
	//NCUtuple loop----------------------------------------------------------------------------------------
	for (int w=wMs;w<wM;w++){
		if(w%20==0)cout<<w<<endl;
		//Get ntuple----------------------------------------------------------------------------------------
		if (nameRoot!=1)f = TFile::Open(Form("%s%d.root",st.data(),w));
		else f = TFile::Open(st.data());
		if (!f || !f->IsOpen())continue;
		TDirectory * dir;
		if (nameRoot!=1)dir = (TDirectory*)f->Get(Form("%s%d.root:/tree",st.data(),w));
		else dir = (TDirectory*)f->Get(Form("%s:/tree",st.data()));
		dir->GetObject("treeMaker",tree);
		TreeReader data(tree);
		total+=data.GetEntriesFast();
		
		
		
		for(Long64_t jEntry=0; jEntry<data.GetEntriesFast() ;jEntry++){//event loop----------------------------------------------------------------------------------------
			data.GetEntry(jEntry);
			
			
			Int_t nVtx        = data.GetInt("nVtx");
			Float_t ntrue= data.GetFloat("pu_nTrueInt");
			//Float_t*  pdfscaleSysWeights= data.GetPtrFloat("pdfscaleSysWeights");
			th5[180]->Fill(nVtx);
			th5[181]->Fill(ntrue);
			double PU_weight[3]={1,1,1};
			
			if(nameRoot!=2){
				if(ntrue<51){
					PU_weight[0] = LumiWeights_central.weight(ntrue);
					PU_weight[1]= LumiWeights_up.weight(ntrue);
					PU_weight[2] = LumiWeights_down.weight(ntrue);
				}
				else {
					PU_weight[0] = LumiWeights_central.weight(50);
					PU_weight[1] = LumiWeights_up.weight(50);
					PU_weight[2]= LumiWeights_down.weight(50);
				}
			}
			
			th6[180]->Fill(nVtx,PU_weight[0]);
			th6[181]->Fill(ntrue,PU_weight[0]);
			fixScaleNum[0]+=PU_weight[0];
			for(int i=0;i<3;i++)totalPileup[i]+=PU_weight[i];
			for(int i=0;i<101;i++)totalPDF[i]+=PU_weight[0];
			
			
			
			//1.trigger
			std::string* trigName = data.GetPtrString("hlt_trigName");
		 	vector<bool> &trigResult = *((vector<bool>*) data.GetPtr("hlt_trigResult"));
			bool passTrigger=false;
			for(int it=0; it< data.GetPtrStringSize(); it++){
				std::string thisTrig= trigName[it];
				bool results = trigResult[it];
				if( ((thisTrig.find("HLT_PFHT800")!= std::string::npos
						) && results==1)){
					passTrigger=true;
					break;
				}
			}
			if(!passTrigger && nameRoot==2)continue;nPass[1]++;
			
			Float_t HT= data.GetFloat("HT");
			if(nameRoot!=2 && HT<800)continue;
			
			
			int nFATJet         = data.GetInt("FATnJet");
			TClonesArray* fatjetP4 = (TClonesArray*) data.GetPtrTObject("FATjetP4");
			float*  FATjetCorrUncUp = data.GetPtrFloat("FATjetCorrUncUp"); 
			float*  FATjetCorrUncDown = data.GetPtrFloat("FATjetCorrUncDown"); 
			vector<bool>    &FATjetPassIDTight = *((vector<bool>*) data.GetPtr("FATjetPassIDTight"));
			//2.nJets
			if(nFATJet<2)continue;nPass[2]++;
			TLorentzVector* thisJet ,* thatJet;
			if (JESOption==1){
				TLorentzVector test0= (*((TLorentzVector*)fatjetP4->At(0)))*(1+FATjetCorrUncUp[0] );
				TLorentzVector test1= (*((TLorentzVector*)fatjetP4->At(1)))*(1+FATjetCorrUncUp[1] );
				thisJet= &test0;
				thatJet= &test1;
			}
			else if (JESOption==2){
				TLorentzVector test0= (*((TLorentzVector*)fatjetP4->At(0)))*(1-FATjetCorrUncDown[0] );
				TLorentzVector test1= (*((TLorentzVector*)fatjetP4->At(1)))*(1-FATjetCorrUncDown[1] );
				thisJet= &test0;
				thatJet= &test1;
			}
			else{
				thisJet= (TLorentzVector*)fatjetP4->At(0);
				thatJet = (TLorentzVector*)fatjetP4->At(1);
			}
			//3. Pt 
			if(thisJet->Pt()<200||thatJet->Pt()<200)continue;
			nPass[3]++;
			//4tightId-----------------------------------------
			if(FATjetPassIDTight[0]==0||FATjetPassIDTight[1]==0)continue;
			nPass[4]++;
			//5. Eta-----------------------------------------
			if(fabs(thisJet->Eta())>2.4||fabs(thatJet->Eta())>2.4)continue;
			nPass[5]++;
			//6. DEta-----------------------------------------
			float dEta = fabs(thisJet->Eta()-thatJet->Eta());
			if(dEta>1.3)continue;
			nPass[6]++;
			//7. Mjj-----------------------------------------
			float mjj = (*thisJet+*thatJet).M();
			float mjjRed = (*thisJet+*thatJet).M()+250-thisJet->M()-thatJet->M();
			//if(mjjRed<1000)continue;
			nPass[7]++;
			//8. fatjetPRmassL2L3Corr-----------------------------------------
			Float_t*  fatjetPRmassL2L3Corr = data.GetPtrFloat("FATjetPRmassL2L3Corr");
			
			
			vector<float>   *subjetSDCSV =  data.GetPtrVectorFloat("FATsubjetSDCSV");
			vector<Int_t>   *FATsubjetSDHadronFlavor =  data.GetPtrVectorInt("FATsubjetSDHadronFlavor");
			int nbtag=0,nbtag2=0;
			float MaxBJetPt = 670., MaxLJetPt = 1000.;
			double sf[2][2],eta[2],pt[2],dr[2],subjetPt[2][2],subjetEta[2][2],eff[2][2],btaggingscaleFactor=1;
			pt[0]=thisJet->Pt();
			pt[1]=thatJet->Pt();
			
			
			
			double scaleFactor=PU_weight[0]*btaggingscaleFactor;
			Float_t*  fatjetTau1 = data.GetPtrFloat("FATjetTau1");
			Float_t*  fatjetTau2 = data.GetPtrFloat("FATjetTau2");
			Float_t*  FATjetPuppiTau1 = data.GetPtrFloat("FATjetPuppiTau1");
			Float_t*  FATjetPuppiTau2 = data.GetPtrFloat("FATjetPuppiTau2");
			double tau21[2];
			tau21[0]=(fatjetTau2[0]/fatjetTau1[0]),tau21[1]=(fatjetTau2[1]/fatjetTau1[1]);
			double puppiTau21[2];
			puppiTau21[0]=(FATjetPuppiTau2[0]/FATjetPuppiTau1[0]),puppiTau21[1]=(FATjetPuppiTau2[1]/FATjetPuppiTau1[1]);
			
			
			
			
			if(fatjetPRmassL2L3Corr[0]<50||fatjetPRmassL2L3Corr[0]>300)continue;
			if(fatjetPRmassL2L3Corr[1]<50||fatjetPRmassL2L3Corr[1]>300)continue;
			nPass[8]++;
			
			
			//9.-----------------------------------------
			if(tau21[0]>0.6 || tau21[1]>0.6) continue;
			nPass[9]++;
			
			
			Int_t* FATjetHadronFlavor        = data.GetPtrInt("FATjetHadronFlavor");
			
			if(subjetSDCSV[0][0]<0.605 && subjetSDCSV[0][1]<0.605){
				if(FATjetHadronFlavor[0]==5 && FATsubjetSDHadronFlavor[0][0]==5 && FATsubjetSDHadronFlavor[0][1]==5)th5[260]->Fill(thisJet->Pt());
				else if(FATjetHadronFlavor[0]==5 && (FATsubjetSDHadronFlavor[0][0]==5 || FATsubjetSDHadronFlavor[0][1]==5))th5[261]->Fill(thisJet->Pt());
				else if(FATjetHadronFlavor[0]==4 && FATsubjetSDHadronFlavor[0][0]==4 && FATsubjetSDHadronFlavor[0][1]==4)th5[262]->Fill(thisJet->Pt());
				else th5[263]->Fill(thisJet->Pt());
			}
			else if (subjetSDCSV[0][0]>0.605 && subjetSDCSV[0][1]>0.605){
				if(FATjetHadronFlavor[0]==5 && FATsubjetSDHadronFlavor[0][0]==5 && FATsubjetSDHadronFlavor[0][1]==5)th5[268]->Fill(thisJet->Pt());
				else if(FATjetHadronFlavor[0]==5 && (FATsubjetSDHadronFlavor[0][0]==5 || FATsubjetSDHadronFlavor[0][1]==5))th5[269]->Fill(thisJet->Pt());
				else if (FATjetHadronFlavor[0]==4 && FATsubjetSDHadronFlavor[0][0]==4 && FATsubjetSDHadronFlavor[0][1]==4)th5[270]->Fill(thisJet->Pt());
				else th5[271]->Fill(thisJet->Pt());
			}
			else {
				if(FATjetHadronFlavor[0]==5 && FATsubjetSDHadronFlavor[0][0]==5 && FATsubjetSDHadronFlavor[0][1]==5)th5[264]->Fill(thisJet->Pt());
				else if(FATjetHadronFlavor[0]==5 && (FATsubjetSDHadronFlavor[0][0]==5 || FATsubjetSDHadronFlavor[0][1]==5))th5[265]->Fill(thisJet->Pt());
				else if (FATjetHadronFlavor[0]==4 && FATsubjetSDHadronFlavor[0][0]==4 && FATsubjetSDHadronFlavor[0][1]==4)th5[266]->Fill(thisJet->Pt());
				else th5[267]->Fill(thisJet->Pt());
			}
			
			
			
			
			
			
			 fixScaleNum[1]+=PU_weight[0];
			
			
			Float_t*  ADDjet_DoubleSV = data.GetPtrFloat("ADDjet_DoubleSV");
			Float_t  FATjet_DoubleSV[2]={0};
			
			Int_t ADDnJet        = data.GetInt("ADDnJet");
			bool matchThis=0,matchThat=0;
			TClonesArray* ADDjetP4 = (TClonesArray*) data.GetPtrTObject("ADDjetP4");
			for(int i=0;i<ADDnJet;i++){
				TLorentzVector* thisAddJet ;
				thisAddJet= (TLorentzVector*)ADDjetP4->At(i);
				if(!matchThis && thisAddJet->DeltaR(*thisJet)<0.8){
					matchThis=1;
					FATjet_DoubleSV[0]=ADDjet_DoubleSV[i];
					continue;
				}
				if(!matchThat && thisAddJet->DeltaR(*thatJet)<0.8){
					matchThat=1;
					FATjet_DoubleSV[1]=ADDjet_DoubleSV[i];
				}
				if(matchThis&& matchThat){
					//cout<<"match"<<FATjet_DoubleSV[0]<<","<<FATjet_DoubleSV[0]<<endl;
					break;
				}
				
			}
			
			if(FATjet_DoubleSV[0]>-0.8){
				if(FATjetHadronFlavor[0]==5 && FATsubjetSDHadronFlavor[0][0]==5 && FATsubjetSDHadronFlavor[0][1]==5)th5[272]->Fill(thisJet->Pt());
				else if(FATjetHadronFlavor[0]==5 && (FATsubjetSDHadronFlavor[0][0]==5 || FATsubjetSDHadronFlavor[0][1]==5))th5[273]->Fill(thisJet->Pt());
				else if (FATjetHadronFlavor[0]==4 && FATsubjetSDHadronFlavor[0][0]==4 && FATsubjetSDHadronFlavor[0][1]==4)th5[274]->Fill(thisJet->Pt());
				else th5[275]->Fill(thisJet->Pt());
			}
			
			

		}//end event loop----------------------------------------------------------------------------------------
	}	//end ntuple loop----------------------------------------------------------------------------------------
	cout<<"entries="<<total<<endl;	
	for(int i=0;i<6;i++)cout<<"nPassB["<<i<<"]="<<nPassB[i]<<endl;
	for(int i=0;i<16;i++)cout<<"nPass["<<i<<"]="<<nPass[i]<<endl;
	
	for(int i=0;i<3;i++)th7[3]->SetBinContent(i+1,passPileup[i]/totalPileup[i]);
	for(int i=0;i<101;i++)th7[4]->SetBinContent(i+1,passPDF[i]/totalPDF[i]);
	
	TH1D * th2o=new TH1D("Nbtagjet","Nbtagjet",5,-0.5,4.5);
	for (int i=0;i<5;i++){
		if(nameRoot==2 && i>2)continue;
		th2o->SetBinContent(i+1,nPass[i+10]);
	}
	TH1D * th2ob=new TH1D("NbtagjetB","NbtagjetB",5,-0.5,4.5);
	for (int i=0;i<5;i++){
		if(nameRoot==2 && i>2)continue;
		th2ob->SetBinContent(i+1,nPassB[i]);
	}
	
	TH1D * fixScale=new TH1D("fixScale","fixScale",2,-0.5,1.5);
	fixScale->SetBinContent(1,fixScaleNum[0]);
	fixScale->SetBinContent(2,fixScaleNum[1]);
	TH1D * cutflow=new TH1D("cutflow","cutflow",16,0.5,16.5);
	cutflow->SetBinContent(1,total);
	if(nameRoot==2)for(int ii=1;ii<14;ii++)cutflow->SetBinContent(ii+1,nPass[ii-1]);
	else for(int ii=1;ii<16;ii++)cutflow->SetBinContent(ii+1,nPass[ii-1]);
	
	TFile* outFile = new TFile(Form("root_file_mike/%s.root",st2.data()),"recreate");
	th2o->Write();
	th2ob->Write();
	fixScale->Write();
	cutflow->Write();
	for(int i=0;i<6;i++)th3[i]->Write();
	for(int i=0;i<14;i++)th4[i]->Write();
	for(int i=0;i<276;i++){
		th5[i]->Write();
		th6[i]->Write();
	}
	for(int i=0;i<14;i++)th7[i]->Write();
	outFile->Close();
}
Ejemplo n.º 4
0
    long init(TFile* f,  string jetcoll) {
        TDirectory* dir = (TDirectory*)f->Get("event");
        dir->GetObject("t",tevent);
        dir = (TDirectory*)f->Get("hlt");
        dir->GetObject("t",thlt);
        dir = (TDirectory*)f->Get("vertex");
        dir->GetObject("t",tvtx);
        dir = (TDirectory*)f->Get(jetcoll.c_str());
        dir->GetObject("t",tjet);
        dir = (TDirectory*)f->Get("met_chs");
        dir->GetObject("t",tmet);

        assert(tevent);
        assert(thlt);
        assert(tvtx);
        assert(tjet);
        assert(tmet);

        // Set branch addresses.
        tevent->SetBranchAddress("nMEPartonsFiltered",&nMEPartonsFiltered);
        tevent->SetBranchAddress("bunch_spacings",&bunch_spacings);
        tevent->SetBranchAddress("bxns",&bxns);
        tevent->SetBranchAddress("evt",&evt);
        tevent->SetBranchAddress("alphaQCD",&alphaQCD);
        tevent->SetBranchAddress("nMEPartons",&nMEPartons);
        tevent->SetBranchAddress("run",&run);
        tevent->SetBranchAddress("alphaQED",&alphaQED);
        tevent->SetBranchAddress("rhos",&rhos);
        tevent->SetBranchAddress("lumi",&lumi);
        tevent->SetBranchAddress("pu_sumpt_lowpt",&pu_sumpt_lowpt);
        tevent->SetBranchAddress("npus",&npus);
        tevent->SetBranchAddress("npv",&npv);
        tevent->SetBranchAddress("rho",&rho);
        tevent->SetBranchAddress("pthat",&pthat);
        tevent->SetBranchAddress("qScale",&qScale);
        tevent->SetBranchAddress("tnpus",&tnpus);
        tevent->SetBranchAddress("weight",&weight);
        tevent->SetBranchAddress("pu_ntrks_lowpt",&pu_ntrks_lowpt);
        tevent->SetBranchAddress("pu_sumpt_highpt",&pu_sumpt_highpt);
        tevent->SetBranchAddress("pu_zpositions",&pu_zpositions);
        tevent->SetBranchAddress("pu_ntrks_highpt",&pu_ntrks_highpt);
        tevent->SetBranchAddress("pdf_x",&pdf_x);
        tevent->SetBranchAddress("pdf_id",&pdf_id);


        thlt->SetBranchAddress("objects_paths_islast",&objects_paths_islast);
        thlt->SetBranchAddress("objects_paths",&objects_paths);
        thlt->SetBranchAddress("objects_paths_isl3",&objects_paths_isl3);
        thlt->SetBranchAddress("objects_phi",&objects_phi);
        thlt->SetBranchAddress("objects_e",&objects_e);
        thlt->SetBranchAddress("objects_eta",&objects_eta);
        thlt->SetBranchAddress("objects_pt",&objects_pt);
        thlt->SetBranchAddress("prescales",&prescales);
        thlt->SetBranchAddress("paths",&paths);

        tjet->SetBranchAddress("allGenJet_patJetmatched",&allGenJet_patJetmatched);
        tjet->SetBranchAddress("allGenJet_phi",&allGenJet_phi);
        tjet->SetBranchAddress("neutralEmEnergyFraction",&neutralEmEnergyFraction);
        tjet->SetBranchAddress("hoEnergyFraction",&hoEnergyFraction);
        tjet->SetBranchAddress("HFEMEnergyFraction",&HFEMEnergyFraction);
        tjet->SetBranchAddress("chargedMuEnergyFraction",&chargedMuEnergyFraction);
        tjet->SetBranchAddress("chargedHadronEnergyFraction",&chargedHadronEnergyFraction);
        tjet->SetBranchAddress("dZ",&dZ);
        tjet->SetBranchAddress("nTot",&nTot);
        tjet->SetBranchAddress("PUJetId_cutBasedId",&PUJetId_cutBasedId);
        tjet->SetBranchAddress("betaStar",&betaStar);
        tjet->SetBranchAddress("jec_factors",&jec_factors);
        tjet->SetBranchAddress("betaClassic",&betaClassic);
        tjet->SetBranchAddress("jec_toraw",&jec_toraw);
        tjet->SetBranchAddress("hadronFlavor",&hadronFlavor);
        tjet->SetBranchAddress("chargedMultiplicity",&chargedMultiplicity);
        tjet->SetBranchAddress("gen_y",&gen_y);
        tjet->SetBranchAddress("y",&y);
        tjet->SetBranchAddress("fRing1",&fRing1);
        tjet->SetBranchAddress("partonFlavor",&partonFlavor);
        tjet->SetBranchAddress("fRing3",&fRing3);
        tjet->SetBranchAddress("allGenJet_pt",&allGenJet_pt);
        tjet->SetBranchAddress("has_gen_particle",&has_gen_particle);
        tjet->SetBranchAddress("refpdgid",&refpdgid);
        tjet->SetBranchAddress("gen_charge",&gen_charge);
        tjet->SetBranchAddress("fRing2",&fRing2);
        tjet->SetBranchAddress("DRweighted",&DRweighted);
        tjet->SetBranchAddress("photonEnergyFraction",&photonEnergyFraction);
        tjet->SetBranchAddress("refarea",&refarea);
        tjet->SetBranchAddress("jtarea",&jtarea);
        tjet->SetBranchAddress("p4",&p4);
        tjet->SetBranchAddress("refdrjt",&refdrjt);
        tjet->SetBranchAddress("neutralHadronEnergyFraction",&neutralHadronEnergyFraction);
        tjet->SetBranchAddress("fRing4",&fRing4);
        tjet->SetBranchAddress("axisMinor",&axisMinor);
        tjet->SetBranchAddress("fRing5",&fRing5);
        tjet->SetBranchAddress("electronEnergyFraction",&electronEnergyFraction);
        tjet->SetBranchAddress("fRing6",&fRing6);
        tjet->SetBranchAddress("axisMajor",&axisMajor);
        tjet->SetBranchAddress("betaStarClassic",&betaStarClassic);
        tjet->SetBranchAddress("fRing7",&fRing7);
        tjet->SetBranchAddress("nCh",&nCh);
        tjet->SetBranchAddress("fRing0",&fRing0);
        tjet->SetBranchAddress("nNeutrals",&nNeutrals);
        tjet->SetBranchAddress("allGenJet_m",&allGenJet_m);
        tjet->SetBranchAddress("allGenJet_eta",&allGenJet_eta);
        tjet->SetBranchAddress("HFHadronEnergyFraction",&HFHadronEnergyFraction);
        tjet->SetBranchAddress("gen_p4",&gen_p4);
        tjet->SetBranchAddress("ptD",&ptD);
        tjet->SetBranchAddress("PUJetId_fullDiscriminant",&PUJetId_fullDiscriminant);
        tjet->SetBranchAddress("PUJetId_fullId",&PUJetId_fullId);
        tjet->SetBranchAddress("chargedEmEnergyFraction",&chargedEmEnergyFraction);
        tjet->SetBranchAddress("jetRchg",&jetRchg);
        tjet->SetBranchAddress("charge",&charge);
        tjet->SetBranchAddress("QGTagger_qgLikelihood",&QGTagger_qgLikelihood);
        tjet->SetBranchAddress("dRMatch",&dRMatch);
        tjet->SetBranchAddress("muonEnergyFraction",&muonEnergyFraction);
        tjet->SetBranchAddress("fRing8",&fRing8);
        tjet->SetBranchAddress("pull",&pull);
        tjet->SetBranchAddress("beta",&beta);
        tjet->SetBranchAddress("jetRneutral",&jetRneutral);
        tjet->SetBranchAddress("jetR",&jetR);
        tjet->SetBranchAddress("Ttheta",&Ttheta);
        tjet->SetBranchAddress("pfTrackCountingHighEffBJetTags",&pfTrackCountingHighEffBJetTags);
        tjet->SetBranchAddress("pfTrackCountingHighPurBJetTags",&pfTrackCountingHighPurBJetTags);
        tjet->SetBranchAddress("pfJetProbabilityBJetTags",&pfJetProbabilityBJetTags);
        tjet->SetBranchAddress("pfJetBProbabilityBJetTags",&pfJetBProbabilityBJetTags);
        tjet->SetBranchAddress("pfSimpleSecondaryVertexHighEffBJetTags",&pfSimpleSecondaryVertexHighEffBJetTags);
        tjet->SetBranchAddress("pfSimpleSecondaryVertexHighPurBJetTags",&pfSimpleSecondaryVertexHighPurBJetTags);
        tjet->SetBranchAddress("pfCombinedSecondaryVertexV2BJetTags",&pfCombinedSecondaryVertexV2BJetTags);
        tjet->SetBranchAddress("pfCombinedInclusiveSecondaryVertexV2BJetTags",&pfCombinedInclusiveSecondaryVertexV2BJetTags);


        tvtx->SetBranchAddress("covariance",&covariance);
        tvtx->SetBranchAddress("position",&position);
        tvtx->SetBranchAddress("isValid",&isValid);
        tvtx->SetBranchAddress("isFake",&isFake);
        tvtx->SetBranchAddress("ndof",&ndof);
        tvtx->SetBranchAddress("normalizedChi2",&normalizedChi2);

        tmet->SetBranchAddress("caloMET_pt",&met_caloMET_pt);
        tmet->SetBranchAddress("gen_significance",&met_gen_significance);
        tmet->SetBranchAddress("gen_sumEt",&met_gen_sumEt);
        tmet->SetBranchAddress("uncorrectedSumEt",&met_uncorrectedSumEt);
        tmet->SetBranchAddress("gen_y",&met_gen_y);
        tmet->SetBranchAddress("uncorrectedPhi",&met_uncorrectedPhi);
        tmet->SetBranchAddress("y",&met_y);
        tmet->SetBranchAddress("sumEt",&met_sumEt);
        tmet->SetBranchAddress("significance",&met_significance);
        tmet->SetBranchAddress("charge",&met_charge);
        tmet->SetBranchAddress("caloMET_sumEt",&met_caloMET_sumEt);
        tmet->SetBranchAddress("has_gen_particle",&met_has_gen_particle);
        tmet->SetBranchAddress("gen_p4",&met_gen_p4);
        tmet->SetBranchAddress("p4",&met_p4);
        tmet->SetBranchAddress("gen_charge",&met_gen_charge);
        tmet->SetBranchAddress("caloMET_phi",&met_caloMET_phi);
        tmet->SetBranchAddress("uncorrectedPt",&met_uncorrectedPt);

        int entries = tevent->GetEntries();
        assert(thlt->GetEntries()==entries);
        assert(tjet->GetEntries()==entries);
        assert(tvtx->GetEntries()==entries);
        assert(tmet->GetEntries()==entries);
        return entries;
    }
void HH4bCategoryBase_80(int wMs,int wM, string st,string st2,string option=""){	

	//1=signal ,0=QCD ,2=data
	int nameRoot=1;
	if(st2.find("QCD")!= std::string::npos)nameRoot=0;
	if(st2.find("data")!= std::string::npos)nameRoot=2;
	cout<<"nameRoot = "<<nameRoot<<endl;
	
	//option-----------------------------------------------------------
	
	int JESOption=0;
	if(option.find("JESUp")!= std::string::npos)JESOption=1;
	if(option.find("JESDown")!= std::string::npos)JESOption=2;
	cout<<"JESOption = "<<JESOption<<endl;
	
	
	//using for Btag Eff -----------------------------------------------------------------------------
	string btagsystematicsType="central";
	if(JESOption==3)btagsystematicsType="up";
	else if(JESOption==4)btagsystematicsType="down";
	BTagCalibration calib("CSVv2L", "subjet_CSVv2_ichep.csv");
	BTagCalibrationReader LF(BTagEntry::OP_LOOSE,"central", {"up", "down"});  
	BTagCalibrationReader HFC(BTagEntry::OP_LOOSE, "central", {"up", "down"});      // other sys types
	BTagCalibrationReader HF(BTagEntry::OP_LOOSE,"central",{"up", "down"});      // other sys types
	LF.load(calib, BTagEntry::FLAV_UDSG,    // btag flavour
            "incl");               // measurement type
	HFC.load(calib, BTagEntry::FLAV_C,    // btag flavour
            "lt");               // measurement type
	HF.load(calib, BTagEntry::FLAV_B,    // btag flavour
            "lt");               // measurement type
	
	TFile *f1;
	if(nameRoot==2)f1=TFile::Open("btagEffSource/data.root");
	else if (nameRoot!=2 && (JESOption==0||JESOption==3||JESOption==4||JESOption==5||JESOption==6))f1=TFile::Open(Form("btagEffSource/%s.root",st2.data()));
	else if (nameRoot!=2 && JESOption==1)f1=TFile::Open(Form("btagEffSource/%s_JESUp.root",st2.data()));
	else if (nameRoot!=2 && JESOption==2)f1=TFile::Open(Form("btagEffSource/%s_JESDown.root",st2.data()));
	TH1D* th1[6];
	string btaggingEff[6]={"effD_b","effN_b","effD_c","effN_c","effD_l","effN_l"};
	for(int i=0;i<6;i++){
		th1[i]=(TH1D*)f1->FindObjectAny(Form("%s_1d",btaggingEff[i].data()));
		if(i==1||i==3||i==5)th1[i]->Divide(th1[i-1]);
	}
	
	standalone_LumiReWeighting LumiWeights_central(0),LumiWeights_up(1),LumiWeights_down(-1);
	
	TFile *f;
	TTree *tree;
	int nPass[20]={0};
	int total=0;
	double fixScaleNum[2]={0};
	double xBinsForHeavyFlavor[5]={30,140,180,240,3000};
	double xBinsForLightFlavor[11]={20,100,200,300,400,500,600,700,800,900,3000};
	
	TH1D* th5[3];
	th5[0]=new TH1D("cat0","cat0",4000,1000,5000);
	th5[1]=new TH1D("cat1","cat1",4000,1000,5000);
	th5[2]=new TH1D("cat2","cat2",4000,1000,5000);

	for(int i=0;i<3;i++){
		th5[i]->Sumw2();
	}
	
	//---------------------------------
	
	for (int w=wMs;w<wM;w++){
		if(w%20==0)cout<<w<<endl;
		
		if (nameRoot!=1)f = TFile::Open(Form("%s%d.root",st.data(),w));
		else f = TFile::Open(st.data());
		if (!f || !f->IsOpen())continue;
		
		TDirectory * dir;
		if (nameRoot!=1)dir = (TDirectory*)f->Get(Form("%s%d.root:/tree",st.data(),w));
		else dir = (TDirectory*)f->Get(Form("%s:/tree",st.data()));
		
		dir->GetObject("treeMaker",tree);
		TreeReader data(tree);
		total+=data.GetEntriesFast();
		for(Long64_t jEntry=0; jEntry<data.GetEntriesFast() ;jEntry++){
			data.GetEntry(jEntry);
			
			
			double PU_weight[3]={1,1,1};
			Float_t ntrue= data.GetFloat("pu_nTrueInt");
			if(nameRoot!=2){
				if(ntrue<51){
					PU_weight[0] = LumiWeights_central.weight(ntrue);
					PU_weight[1]= LumiWeights_up.weight(ntrue);
					PU_weight[2] = LumiWeights_down.weight(ntrue);
				}
				else {
					PU_weight[0] = LumiWeights_central.weight(50);
					PU_weight[1] = LumiWeights_up.weight(50);
					PU_weight[2]= LumiWeights_down.weight(50);
				}
			}
			fixScaleNum[0]+=PU_weight[0];
			
			Int_t nVtx        = data.GetInt("nVtx");
			//0. has a good vertex
			if(nVtx<1)continue;
			nPass[0]++;
			
			//1.trigger
			std::string* trigName = data.GetPtrString("hlt_trigName");
		 	vector<bool> &trigResult = *((vector<bool>*) data.GetPtr("hlt_trigResult"));
			bool passTrigger=false;
			for(int it=0; it< data.GetPtrStringSize();it++){
				std::string thisTrig= trigName[it];
				bool results = trigResult[it];
				if( ((thisTrig.find("HLT_PFHT800")!= std::string::npos||
						thisTrig.find("HLT_PFHT650_WideJetMJJ900DEtaJJ1p5_v")!= std::string::npos||
						thisTrig.find("HLT_PFHT650_WideJetMJJ950DEtaJJ1p5_v")!= std::string::npos||
						thisTrig.find("HLT_AK8PFJet360_TrimMass30_v")!= std::string::npos||
						thisTrig.find("HLT_AK8PFHT700_TrimR0p1PT0p03Mass50_v")!= std::string::npos
						) && results==1)){
					passTrigger=true;
					break;
				}
			}
			if(!passTrigger && nameRoot==2)continue;
			nPass[1]++;

			const int nFATJet=data.GetInt("FATnJet");
			//2.nJets
			if(nFATJet<2)continue;nPass[2]++;
			TClonesArray* fatjetP4 = (TClonesArray*) data.GetPtrTObject("FATjetP4");
			float*  FATjetCorrUncUp = data.GetPtrFloat("FATjetCorrUncUp"); 
			float*  FATjetCorrUncDown = data.GetPtrFloat("FATjetCorrUncDown"); 
			TLorentzVector* thisJet ,* thatJet;
			if(JESOption==0){
				thisJet=(TLorentzVector*)fatjetP4->At(0);
				thatJet=(TLorentzVector*)fatjetP4->At(1);
			}
			else if (JESOption==1){
				TLorentzVector thisJetScaleUp= (*((TLorentzVector*)fatjetP4->At(0)))*(1+FATjetCorrUncUp[0]);
				TLorentzVector thatJetScaleUp= (*((TLorentzVector*)fatjetP4->At(1)))*(1+FATjetCorrUncUp[1]);
				thisJet= &thisJetScaleUp;
				thatJet= &thatJetScaleUp;
			}
			else if (JESOption==2){
				TLorentzVector thisJetScaleDown= (*((TLorentzVector*)fatjetP4->At(0)))*(1-FATjetCorrUncDown[0]);
				TLorentzVector thatJetScaleDown= (*((TLorentzVector*)fatjetP4->At(1)))*(1-FATjetCorrUncDown[1]);
				thisJet= &thisJetScaleDown;
				thatJet= &thatJetScaleDown;
			}
			
			//3. Pt 
			if(thisJet->Pt()<200)continue;
			if(thatJet->Pt()<200)continue;
			nPass[3]++;
			//4tightId-----------------------------------------
			vector<bool>    &FATjetPassIDTight = *((vector<bool>*) data.GetPtr("FATjetPassIDTight"));
			if(FATjetPassIDTight[0]==0)continue;
			if(FATjetPassIDTight[1]==0)continue;
			Float_t*  FATjetCEmEF = data.GetPtrFloat("FATjetCEmEF");
			Float_t*  FATjetMuEF = data.GetPtrFloat("FATjetMuEF");
			if(FATjetMuEF[0]>0.8)continue;
			if(FATjetCEmEF[0]>0.9)continue;
			if(FATjetMuEF[1]>0.8)continue;
			if(FATjetCEmEF[1]>0.9)continue;
			nPass[4]++;
			//5. Eta-----------------------------------------
			if(fabs(thisJet->Eta())>2.4)continue;
			if(fabs(thatJet->Eta())>2.4)continue;
			nPass[5]++;
			//6. DEta-----------------------------------------
			float dEta = fabs(thisJet->Eta()-thatJet->Eta());
			if(dEta>1.3)continue;
			nPass[6]++;
			//7. Mjj-----------------------------------------
			float mjjRed = (*thisJet+*thatJet).M()+250-thisJet->M()-thatJet->M();
			if(mjjRed<1000)continue;
			nPass[7]++;
			//8. fatjetPRmassL2L3Corr-----------------------------------------
			Float_t*  fatjetPRmassL2L3Corr = data.GetPtrFloat("FATjetPRmassL2L3Corr");
			if(fatjetPRmassL2L3Corr[0]<105||fatjetPRmassL2L3Corr[0]>135)continue;
			if(fatjetPRmassL2L3Corr[1]<105||fatjetPRmassL2L3Corr[1]>135)continue;
			nPass[8]++;
			//9.-----------------------------------------
			Float_t*  fatjetTau1 = data.GetPtrFloat("FATjetTau1");
			Float_t*  fatjetTau2 = data.GetPtrFloat("FATjetTau2");
			double tau21_1=(fatjetTau2[0]/fatjetTau1[0]),tau21_2=(fatjetTau2[1]/fatjetTau1[1]);
			//10.btag
			vector<float>   *subjetSDCSV =  data.GetPtrVectorFloat("FATsubjetSDCSV");
			int nbtag=0;
			if(subjetSDCSV[0][0]>0.46)nbtag++;
			if(subjetSDCSV[0][1]>0.46)nbtag++;
			if(subjetSDCSV[1][0]>0.46)nbtag++;
			if(subjetSDCSV[1][1]>0.46)nbtag++;
			
			vector<float>   *subjetSDPx  =  data.GetPtrVectorFloat("FATsubjetSDPx");
			vector<float>   *subjetSDPy  =  data.GetPtrVectorFloat("FATsubjetSDPy");
			vector<float>   *subjetSDPz  =  data.GetPtrVectorFloat("FATsubjetSDPz");
			vector<float>   *subjetSDE   =  data.GetPtrVectorFloat("FATsubjetSDE");
			vector<Int_t>   *FATsubjetSDHadronFlavor =  data.GetPtrVectorInt("FATsubjetSDHadronFlavor");
			
			double sf[2][2],subjetPt[2][2],subjetEta[2][2],eff[2][2],btaggingscaleFactor=1;
			TLorentzVector* subjetP4[2][2];
			for(int i=0;i<2;i++){
				for(int j=0;j<2;j++){
					sf[i][j]=1;
					subjetP4[i][j]=new TLorentzVector(0,0,0,0);
					subjetP4[i][j]->SetPxPyPzE(subjetSDPx[i][j],subjetSDPy[i][j],subjetSDPz[i][j],subjetSDE[i][j]);
					subjetPt[i][j]=subjetP4[i][j]->Pt();
					subjetEta[i][j]=subjetP4[i][j]->Eta();
				}
			}
			for(int i=0;i<2;i++){
				for(int j=0;j<2;j++){
					
					//get btagging eff------------------------------------------------------------
					int getPtBin=1;
					if(subjetPt[i][j]<140)getPtBin=1;
					else if (140<=subjetPt[i][j] && subjetPt[i][j]<180)getPtBin=2;
					else if (180<=subjetPt[i][j] && subjetPt[i][j]<240)getPtBin=3;
					else getPtBin=4;
					if(FATsubjetSDHadronFlavor[i][j]==5)eff[i][j]=th1[1]->GetBinContent(getPtBin);
					else if(FATsubjetSDHadronFlavor[i][j]==4)eff[i][j]=th1[3]->GetBinContent(getPtBin);
					else {
						int temp=0;
						if(subjetPt[i][j]>=900)temp=10;
						else temp=ceil(subjetPt[i][j]/100);
						
						bool checkBinContentIfZero=0;
						while(checkBinContentIfZero==0){
							if(th1[4]->GetBinContent(temp)==0){
								temp--;
							}
							else checkBinContentIfZero=1;
						}
						eff[i][j]=th1[5]->GetBinContent(temp);
					}
					//Get SF from csv------------------------------------------------------------
					if(FATsubjetSDHadronFlavor[i][j]==5){
						sf[i][j]=HF.eval_auto_bounds("central",BTagEntry::FLAV_B, subjetEta[i][j],subjetPt[i][j]); 
					}
					else if(FATsubjetSDHadronFlavor[i][j]==4){
						sf[i][j]=HFC.eval_auto_bounds("central",BTagEntry::FLAV_C, subjetEta[i][j],subjetPt[i][j]); 
					}
					else {
						sf[i][j]=LF.eval_auto_bounds("central",BTagEntry::FLAV_UDSG, subjetEta[i][j],subjetPt[i][j]); 
					}
					//get tot. btagging SF
					if(subjetSDCSV[i][j]>=0.46)btaggingscaleFactor*=sf[i][j];
					else btaggingscaleFactor*=((1-eff[i][j]*sf[i][j])/(1-eff[i][j]));
					
				}
			}
			
			//if(tau21_1>0.75 || tau21_2>0.75) continue;
			
			//if(nbtag==3 && ((tau21_1>0.6 && tau21_2<0.6)||(tau21_1<0.6 && tau21_2>0.6)))th1[2]->Fill(mjjRed);
			
			if(tau21_1>0.6 || tau21_2>0.6) continue;
			if(nbtag==4)th5[0]->Fill(mjjRed,btaggingscaleFactor*PU_weight[0]);
			if(nbtag==3)th5[1]->Fill(mjjRed,btaggingscaleFactor*PU_weight[0]);
			if(nbtag==2)th5[2]->Fill(mjjRed,btaggingscaleFactor*PU_weight[0]);
			nPass[9]++;
			
			 fixScaleNum[1]+=PU_weight[0];
			
			
			
		}
	}	
	cout<<"entries="<<total<<endl;	
	for(int i=0;i<9;i++)cout<<"nPass["<<i<<"]="<<nPass[i]<<endl;
	
	
	TH1D * fixScale=new TH1D("fixScale","fixScale",2,-0.5,1.5);
	fixScale->SetBinContent(1,fixScaleNum[0]);
	fixScale->SetBinContent(2,fixScaleNum[1]);
	
	TFile* outFile ;
	if(JESOption==0)outFile= new TFile(Form("category/%s.root",st2.data()),"recreate");
	else if(JESOption==1)outFile= new TFile(Form("category/%s_JESUp.root",st2.data()),"recreate");
	else if(JESOption==2)outFile= new TFile(Form("category/%s_JESDown.root",st2.data()),"recreate");
	fixScale->Write();
	for(int i=0;i<3;i++){
		th5[i]->Write();
	}
	outFile->Close();
}
void HH4bBtagEffBase_80_v2(int wMs,int wM, string st,string st2,string option=""){	
	//1=signal ,0=QCD ,2=data-----------------------------------------------------------
	int nameRoot=1;
	if((st2.find("QCD")!= std::string::npos)||
	(st2.find("bGen")!= std::string::npos)||
	(st2.find("bEnriched")!= std::string::npos))nameRoot=0;
	if(st2.find("data")!= std::string::npos)nameRoot=2;
	//Thea correction---------------------
	TFile *f3;
	f3=TFile::Open("puppiCorr.root");
	TF1* tf1[3];
	tf1[0]=(TF1 *) f3->FindObjectAny("puppiJECcorr_gen");
	tf1[1]=(TF1 *) f3->FindObjectAny("puppiJECcorr_reco_0eta1v3");
	tf1[2]=(TF1 *) f3->FindObjectAny("puppiJECcorr_reco_1v3eta2v5");
	//option-----------------------------------------------------------
	int JESOption=0;
	if(option.find("JESUp")!= std::string::npos)JESOption=1;
	if(option.find("JESDown")!= std::string::npos)JESOption=2;
	if(option.find("BtagUp")!= std::string::npos)JESOption=3;
	if(option.find("BtagDown")!= std::string::npos)JESOption=4;
	if(option.find("tau21Up")!= std::string::npos)JESOption=5;
	if(option.find("tau21Down")!= std::string::npos)JESOption=6;
	cout<<"JESOption = "<<JESOption<<endl;
	bool printHighPtSubjet=0;
	bool isFast=1;
	//tuple tree and cutflow variables------------------------------------------------------------------------------------
	TFile *f;
	TTree *tree;
	double nPass[30]={0},total=0;
	double fixScaleNum[2]={0};
	//using for Btag Eff -----------------------------------------------------------------------------
	string btagsystematicsType="central";
	if(JESOption==3)btagsystematicsType="up";
	else if(JESOption==4)btagsystematicsType="down";
	BTagCalibration calib("CSVv2L", "subjet_CSVv2_ichep.csv");
	BTagCalibrationReader LF(BTagEntry::OP_LOOSE,"central", {"up", "down"});  
	BTagCalibrationReader HFC(BTagEntry::OP_LOOSE, "central", {"up", "down"});      // other sys types
	BTagCalibrationReader HF(BTagEntry::OP_LOOSE,"central",{"up", "down"});      // other sys types
	LF.load(calib, BTagEntry::FLAV_UDSG,    // btag flavour
            "incl");               // measurement type
	HFC.load(calib, BTagEntry::FLAV_C,    // btag flavour
            "lt");               // measurement type
	HF.load(calib, BTagEntry::FLAV_B,    // btag flavour
            "lt");               // measurement type
	TFile *f1;
	if(nameRoot==2)f1=TFile::Open("btagEffSource/data.root");
	else if (nameRoot!=2 && (JESOption==0||JESOption==3||JESOption==4||JESOption==5||JESOption==6))f1=TFile::Open(Form("btagEffSource/%s.root",st2.data()));
	else if (nameRoot!=2 && JESOption==1)f1=TFile::Open(Form("btagEffSource/%s_JESUp.root",st2.data()));
	else if (nameRoot!=2 && JESOption==2)f1=TFile::Open(Form("btagEffSource/%s_JESDown.root",st2.data()));
	TH1D* th1[6];
	string btaggingEff[6]={"effD_b","effN_b","effD_c","effN_c","effD_l","effN_l"};
	for(int i=0;i<6;i++){
		th1[i]=(TH1D*)f1->FindObjectAny(Form("%s_1d",btaggingEff[i].data()));
		if(i==1||i==3||i==5)th1[i]->Divide(th1[i-1]);
	}
	//saving variables----------------------------------------------------------------------------------------
	TH1D * th5[300],* th_flavor[4][300];
	for(int i=0;i<2;i++){
		for(int j=0;j<2;j++){
			for(int k=0;k<5;k++){
				th5[(i*2+j)*5+k]=new TH1D(Form("Pt_j%d_sj%d_%db",i,j,k),Form("Pt_j%d_sj%d_%db",i,j,k),200,0,2000);
				th5[(i*2+j)*5+k+20]=new TH1D(Form("Eta_j%d_sj%d_%db",i,j,k),Form("Eta_j%d_sj%d_%db",i,j,k),60,-3,3);
				th5[(i*2+j)*5+k+85]=new TH1D(Form("subCSV_j%d_sj%d_%db",i,j,k),Form("subCSV_j%d_sj%d_%db",i,j,k),20,0,1);
				th5[(i*2+j)*5+k+194]=new TH1D(Form("subCSVCut_j%d_sj%d_%db",i,j,k),Form("subCSVCut_j%d_sj%d_%db",i,j,k),20,0,1);
			}
		}
		for(int k=0;k<5;k++){
			th5[i*5+k+40]=new TH1D(Form("deltaR_j%d_%db",i,k),Form("deltaR_j%d_%db",i,k),20,0,1);
			th5[i*5+k+50]=new TH1D(Form("Pt_j%d_%db",i,k),Form("Pt_j%d_%db",i,k),200,0,2000);
			th5[i*5+k+60]=new TH1D(Form("Eta_j%d_%db",i,k),Form("Eta_j%d_%db",i,k),60,-3,3);
			th5[i*5+k+70]=new TH1D(Form("prMassL2L3_j%d_%db",i,k),Form("prMassL2L3_j%d_%db",i,k),15,90,150);
			th5[i*5+k+105]=new TH1D(Form("tau21_j%d_%db",i,k),Form("tau21_j%d_%db",i,k),25,0,1);
			th5[i*5+k+120]=new TH1D(Form("PuppiSDMassL2L3_j%d_%db",i,k),Form("PuppiSDMassL2L3_j%d_%db",i,k),15,90,150);
			th5[i*5+k+130]=new TH1D(Form("puppiTau21_j%d_%db",i,k),Form("puppiTau21_j%d_%db",i,k),25,0,1);
			th5[i*5+k+140]=new TH1D(Form("prMass_j%d_%db",i,k),Form("prMass_j%d_%db",i,k),15,90,150);
			th5[i*5+k+150]=new TH1D(Form("PuppiSDMass_j%d_%db",i,k),Form("PuppiSDMass_j%d_%db",i,k),15,90,150);
			th5[i*5+k+170]=new TH1D(Form("doubleSV_j%d_%db",i,k),Form("doubleSV_j%d_%db",i,k),40,-1,1);
			th5[i*5+k+184]=new TH1D(Form("FatSV_j%d_%db",i,k),Form("FatSV_j%d_%db",i,k),20,0,1);
			th5[i*5+k+250]=new TH1D(Form("PuppiSDMassThea_j%d_%db",i,k),Form("PuppiSDMassThea_j%d_%db",i,k),15,90,150);
		}
	}
	for(int k=0;k<5;k++){
		th5[k+80]=new TH1D(Form("totalMass_%db",k),Form("totalMass_%db",k),200,1000,5000);
		th5[k+115]=new TH1D(Form("deltaEta_%db",k),Form("deltaEta_%db",k),40,0,2);
		th5[k+160]=new TH1D(Form("logPt_%db",k),Form("logPt_%db",k),70,0,7);
		th5[k+165]=new TH1D(Form("totalMassRed_%db",k),Form("totalMassRed_%db",k),200,1000,5000);
	}
	th5[180]= new TH1D("h_nvtx","h_nvtx",60,0,60);
	th5[181]= new TH1D("h_ntrue","h_ntrue",60,0,60);
	th5[182]= new TH1D("h_nvtx_cut","h_nvtx_cut",60,0,60);
	th5[183]= new TH1D("h_ntrue_cut","h_ntrue_cut",60,0,60);
	
	string prMass_no[4]={"prMass","prMassL2L3","PuppiSDMass","PuppiSDMassL2L3"};
	string tau21_no[2]={"tau21","puppiTau21"};
	for (int i=0;i<4;i++){
		th5[214+i*2]=new TH1D(Form("%s_j0_noPr_noTau21",prMass_no[i].data()),Form("%s_j0_noPr_noTau21",prMass_no[i].data()),200,0,200);
		th5[215+i*2]=new TH1D(Form("%s_j1_noPr_noTau21",prMass_no[i].data()),Form("%s_j1_noPr_noTau21",prMass_no[i].data()),200,0,200);
		th5[222+i*2]=new TH1D(Form("%s_j0_noPr",prMass_no[i].data()),Form("%s_j0_noPr",prMass_no[i].data()),200,0,200);
		th5[223+i*2]=new TH1D(Form("%s_j1_noPr",prMass_no[i].data()),Form("%s_j1_noPr",prMass_no[i].data()),200,0,200);
		th5[230+i*2]=new TH1D(Form("%s_j0_noTau21",prMass_no[i].data()),Form("%s_j0_noTau21",prMass_no[i].data()),15,90,150);
		th5[231+i*2]=new TH1D(Form("%s_j1_noTau21",prMass_no[i].data()),Form("%s_j1_noTau21",prMass_no[i].data()),15,90,150);
	}
	for (int i=0;i<2;i++){
		th5[238+i*2]=new TH1D(Form("%s_j0_noPr_noTau21",tau21_no[i].data()),Form("%s_j0_noPr_noTau21",tau21_no[i].data()),25,0,1);
		th5[239+i*2]=new TH1D(Form("%s_j1_noPr_noTau21",tau21_no[i].data()),Form("%s_j1_noPr_noTau21",tau21_no[i].data()),25,0,1);
		th5[242+i*2]=new TH1D(Form("%s_j0_noPr",tau21_no[i].data()),Form("%s_j0_noPr",tau21_no[i].data()),25,0,1);
		th5[243+i*2]=new TH1D(Form("%s_j1_noPr",tau21_no[i].data()),Form("%s_j1_noPr",tau21_no[i].data()),25,0,1);
		th5[246+i*2]=new TH1D(Form("%s_j0_noTau21",tau21_no[i].data()),Form("%s_j0_noTau21",tau21_no[i].data()),25,0,1);
		th5[247+i*2]=new TH1D(Form("%s_j1_noTau21",tau21_no[i].data()),Form("%s_j1_noTau21",tau21_no[i].data()),25,0,1);
	}
	for(int i=0;i<260;i++){
		th5[i]->Sumw2();
		th_flavor[0][i]=(TH1D* )th5[i]->Clone(Form("%s_bb",th5[i]->GetTitle()));
		th_flavor[1][i]=(TH1D* )th5[i]->Clone(Form("%s_b",th5[i]->GetTitle()));
		th_flavor[2][i]=(TH1D* )th5[i]->Clone(Form("%s_cc",th5[i]->GetTitle()));
		th_flavor[3][i]=(TH1D* )th5[i]->Clone(Form("%s_udcsg",th5[i]->GetTitle()));
		//th_flavor[0][i]->Sumw2();
		//th_flavor[1][i]->Sumw2();
		//th_flavor[2][i]->Sumw2();
		//th_flavor[3][i]->Sumw2();
	}
	
	//pileup uncertainty----------------------------------------------------------------------------------------
	TH1D* th7[14];
	th7[0]=new TH1D("totalMass","totalMass",200,1000,5000);
	th7[1]=new TH1D("totalMass_pileup_up","totalMass_pileup_up",200,1000,5000);
	th7[2]=new TH1D("totalMass_pileup_down","totalMass_pileup_down",200,1000,5000);
	th7[3]=new TH1D("pileupEff","pileupEff",15,0.5,15.5);
	double totalPileup[3]={0},passPileup[3]={0};
	standalone_LumiReWeighting LumiWeights_central(0),LumiWeights_up(1),LumiWeights_down(-1);
	//PDF uncertainty
	th7[4]=new TH1D("PDFEff","PDFEff",101,0.5,101.5);
	double passPDF[101]={0},totalPDF[101]={0};
	//QCD uncertainty
	for(int i=5;i<14;i++)th7[i]=new TH1D(Form("uns_QCD_%d",i-5),Form("uns_QCD_%d",i-5),200,1000,5000);
	
	
	
	//NCUtuple loop----------------------------------------------------------------------------------------
	for (int w=wMs;w<wM;w++){
		if(w%20==0)cout<<w<<endl;
		//Get ntuple----------------------------------------------------------------------------------------
		if (nameRoot!=1)f = TFile::Open(Form("%s%d.root",st.data(),w));
		else f = TFile::Open(st.data());
		if (!f || !f->IsOpen())continue;
		TDirectory * dir;
		if (nameRoot!=1)dir = (TDirectory*)f->Get(Form("%s%d.root:/tree",st.data(),w));
		else dir = (TDirectory*)f->Get(Form("%s:/tree",st.data()));
		dir->GetObject("treeMaker",tree);
		TreeReader data(tree);
		total+=data.GetEntriesFast();
		
		//TFile* fileFast=TFile::Open(Form("fast/%s/%d.root",st2.data(),w));
		//TTree* treeFast=(TTree* )fileFast->Get("hh4bFast");
		//TreeReader dataFast(treeFast);
		//if(isFast)dataFast=TreeReader(treeFast);
		
		for(Long64_t jEntry=0; jEntry<data.GetEntriesFast() ;jEntry++){//event loop----------------------------------------------------------------------------------------
			data.GetEntry(jEntry);
			//if(isFast)dataFast.GetEntry(jEntry);
			
			Int_t nVtx        = data.GetInt("nVtx");
			Float_t ntrue= data.GetFloat("pu_nTrueInt");
			//Float_t*  pdfscaleSysWeights= data.GetPtrFloat("pdfscaleSysWeights");
			
			double PU_weight[3]={1,1,1};
			
			if(nameRoot!=2){
				if(ntrue<51){
					PU_weight[0] = LumiWeights_central.weight(ntrue);
					PU_weight[1]= LumiWeights_up.weight(ntrue);
					PU_weight[2] = LumiWeights_down.weight(ntrue);
				}
				else {
					PU_weight[0] = LumiWeights_central.weight(50);
					PU_weight[1] = LumiWeights_up.weight(50);
					PU_weight[2]= LumiWeights_down.weight(50);
				}
			}
			fixScaleNum[0]+=PU_weight[0];
			for(int i=0;i<3;i++)totalPileup[i]+=PU_weight[i];
			for(int i=0;i<101;i++)totalPDF[i]+=PU_weight[0];
			
			//Int_t nPassFast;  
			//if(isFast)nPassFast= dataFast.GetInt("nPassB");
			//cout<<nPassFast<<endl;
			//if(isFast &&nPassFast<8)continue;
			//0. has a good vertex
			if(nVtx<1)continue;nPass[0]+=PU_weight[0];
			//1.trigger
			std::string* trigName = data.GetPtrString("hlt_trigName");
		 	vector<bool> &trigResult = *((vector<bool>*) data.GetPtr("hlt_trigResult"));
			bool passTrigger=false;
			for(int it=0; it< data.GetPtrStringSize(); it++){
				std::string thisTrig= trigName[it];
				bool results = trigResult[it];
				if( ((thisTrig.find("HLT_PFHT800")!= std::string::npos||
						//thisTrig.find("HLT_PFHT650")!= std::string::npos||
						thisTrig.find("HLT_PFHT650_WideJetMJJ900DEtaJJ1p5_v")!= std::string::npos||
						thisTrig.find("HLT_PFHT650_WideJetMJJ950DEtaJJ1p5_v")!= std::string::npos||
						thisTrig.find("HLT_AK8PFJet360_TrimMass30_v")!= std::string::npos||
						thisTrig.find("HLT_AK8PFHT700_TrimR0p1PT0p03Mass50_v")!= std::string::npos
						) && results==1)){
					passTrigger=true;
					break;
				}
			}
			if(!passTrigger && nameRoot==2)continue;nPass[1]+=PU_weight[0];
			
			int nFATJet         = data.GetInt("FATnJet");
			TClonesArray* fatjetP4 = (TClonesArray*) data.GetPtrTObject("FATjetP4");
			float*  FATjetCorrUncUp = data.GetPtrFloat("FATjetCorrUncUp"); 
			float*  FATjetCorrUncDown = data.GetPtrFloat("FATjetCorrUncDown"); 
			vector<bool>    &FATjetPassIDTight = *((vector<bool>*) data.GetPtr("FATjetPassIDTight"));
			//2.nJets
			if(nFATJet<2)continue;nPass[2]+=PU_weight[0];
			TLorentzVector* thisJet ,* thatJet;
			if (JESOption==1){
				TLorentzVector test0= (*((TLorentzVector*)fatjetP4->At(0)))*(1+FATjetCorrUncUp[0] );
				TLorentzVector test1= (*((TLorentzVector*)fatjetP4->At(1)))*(1+FATjetCorrUncUp[1] );
				thisJet= &test0;
				thatJet= &test1;
			}
			else if (JESOption==2){
				TLorentzVector test0= (*((TLorentzVector*)fatjetP4->At(0)))*(1-FATjetCorrUncDown[0] );
				TLorentzVector test1= (*((TLorentzVector*)fatjetP4->At(1)))*(1-FATjetCorrUncDown[1] );
				thisJet= &test0;
				thatJet= &test1;
			}
			else{
				thisJet= (TLorentzVector*)fatjetP4->At(0);
				thatJet = (TLorentzVector*)fatjetP4->At(1);
			}
			//3. Pt 
			if(thisJet->Pt()<200||thatJet->Pt()<200)continue;
			nPass[3]+=PU_weight[0];
			//4tightId-----------------------------------------
			if(FATjetPassIDTight[0]==0||FATjetPassIDTight[1]==0)continue;
			Float_t*  FATjetCEmEF = data.GetPtrFloat("FATjetCEmEF");
			Float_t*  FATjetMuEF = data.GetPtrFloat("FATjetMuEF");
			if(FATjetMuEF[0]>0.8||FATjetMuEF[1]>0.8)continue;
			if(FATjetCEmEF[0]>0.9||FATjetCEmEF[1]>0.9)continue;
			nPass[4]+=PU_weight[0];
			//5. Eta-----------------------------------------
			if(fabs(thisJet->Eta())>2.4||fabs(thatJet->Eta())>2.4)continue;
			nPass[5]+=PU_weight[0];
			
			int event_flavor=-1;
			Int_t* FATjetHadronFlavor        = data.GetPtrInt("FATjetHadronFlavor");
			vector<Int_t>   *FATsubjetSDHadronFlavor =  data.GetPtrVectorInt("FATsubjetSDHadronFlavor");
			if(FATjetHadronFlavor[0]==5 && FATsubjetSDHadronFlavor[0][0]==5 && FATsubjetSDHadronFlavor[0][1]==5)event_flavor=0;
				else if(FATjetHadronFlavor[1]==5 && FATsubjetSDHadronFlavor[1][0]==5 && FATsubjetSDHadronFlavor[1][1]==5)event_flavor=0;
				else if(FATjetHadronFlavor[0]==5 && (FATsubjetSDHadronFlavor[0][0]==5 || FATsubjetSDHadronFlavor[0][1]==5))event_flavor=1;
				else if(FATjetHadronFlavor[1]==5 && (FATsubjetSDHadronFlavor[1][0]==5 || FATsubjetSDHadronFlavor[1][1]==5))event_flavor=1;
				else if(FATjetHadronFlavor[0]==4 && FATsubjetSDHadronFlavor[0][0]==4 && FATsubjetSDHadronFlavor[0][1]==4)event_flavor=2;
				else if(FATjetHadronFlavor[1]==4 && FATsubjetSDHadronFlavor[1][0]==4 && FATsubjetSDHadronFlavor[1][1]==4)event_flavor=2;
				else event_flavor=3;
			
			th5[180]->Fill(nVtx,PU_weight[0]);
			th5[181]->Fill(ntrue,PU_weight[0]);
			
			th_flavor[event_flavor][180]->Fill(nVtx,PU_weight[0]);
			th_flavor[event_flavor][181]->Fill(ntrue,PU_weight[0]);
			//6. DEta-----------------------------------------
			float dEta = fabs(thisJet->Eta()-thatJet->Eta());
			if(dEta>1.3)continue;
			nPass[6]+=PU_weight[0];
			//7. Mjj-----------------------------------------
			float mjj = (*thisJet+*thatJet).M();
			float mjjRed = (*thisJet+*thatJet).M()+250-thisJet->M()-thatJet->M();
			if(mjjRed<1000)continue;
			nPass[7]+=PU_weight[0];
			//8. fatjetPRmassL2L3Corr-----------------------------------------
			Float_t*  fatjetPRmassL2L3Corr = data.GetPtrFloat("FATjetPRmassL2L3Corr");
			Float_t*  FATjetPuppiSDmassL2L3Corr = data.GetPtrFloat("FATjetPuppiSDmassL2L3Corr");
			Float_t*  FATjetPRmass = data.GetPtrFloat("FATjetPRmass");
			Float_t*  FATjetPuppiSDmass = data.GetPtrFloat("FATjetPuppiSDmass");
			
			
			
			vector<float>   *subjetSDCSV =  data.GetPtrVectorFloat("FATsubjetSDCSV");
			vector<float>   *subjetSDPx  =  data.GetPtrVectorFloat("FATsubjetSDPx", nFATJet);
			vector<float>   *subjetSDPy  =  data.GetPtrVectorFloat("FATsubjetSDPy", nFATJet);
			vector<float>   *subjetSDPz  =  data.GetPtrVectorFloat("FATsubjetSDPz", nFATJet);
			vector<float>   *subjetSDE   =  data.GetPtrVectorFloat("FATsubjetSDE", nFATJet);
			
			int nbtag=0,nbtag2=0;
			float MaxBJetPt = 670., MaxLJetPt = 1000.;
			double sf[2][2],eta[2],pt[2],dr[2],subjetPt[2][2],subjetEta[2][2],eff[2][2],btaggingscaleFactor=1;
			pt[0]=thisJet->Pt();
			pt[1]=thatJet->Pt();
			TLorentzVector* subjetP4[2][2];
			for(int i=0;i<2;i++){
				for(int j=0;j<2;j++){
					sf[i][j]=1;
					subjetP4[i][j]=new TLorentzVector(0,0,0,0);
					subjetP4[i][j]->SetPxPyPzE(subjetSDPx[i][j],subjetSDPy[i][j],subjetSDPz[i][j],subjetSDE[i][j]);
					subjetPt[i][j]=subjetP4[i][j]->Pt();
					subjetEta[i][j]=subjetP4[i][j]->Eta();
				}
				dr[i]=subjetP4[i][0]->DeltaR(*subjetP4[i][1]);
			}
			for(int i=0;i<2;i++){
				for(int j=0;j<2;j++){
					//get btagging eff------------------------------------------------------------
					int getPtBin=1;
					if(subjetPt[i][j]<140)getPtBin=1;
					else if (140<=subjetPt[i][j] && subjetPt[i][j]<180)getPtBin=2;
					else if (180<=subjetPt[i][j] && subjetPt[i][j]<240)getPtBin=3;
					else getPtBin=4;
					//if(FATsubjetSDHadronFlavor[i][j]==5)eff[i][j]=th1[1]->GetBinContent(getPtBin,ceil(subjetEta[i][j]/0.2)+15);
					//else if(FATsubjetSDHadronFlavor[i][j]==4)eff[i][j]=th1[3]->GetBinContent(getPtBin,ceil(subjetEta[i][j]/0.2)+15);
					//else eff[i][j]=th1[5]->GetBinContent(getPtBin,ceil(subjetEta[i][j]/0.2)+15);
					if(FATsubjetSDHadronFlavor[i][j]==5)eff[i][j]=th1[1]->GetBinContent(getPtBin);
					else if(FATsubjetSDHadronFlavor[i][j]==4)eff[i][j]=th1[3]->GetBinContent(getPtBin);
					else {
						int temp=0;
						if(subjetPt[i][j]>=900)temp=10;
						else temp=ceil(subjetPt[i][j]/100);
						
						bool checkBinContentIfZero=0;
						while(checkBinContentIfZero==0){
							if(th1[4]->GetBinContent(temp)==0){
								temp--;
							}
							else checkBinContentIfZero=1;
						}
						eff[i][j]=th1[5]->GetBinContent(temp);
					}
					
					//Get SF from csv------------------------------------------------------------
					if(FATsubjetSDHadronFlavor[i][j]==5){
						sf[i][j]=HF.eval_auto_bounds("central",BTagEntry::FLAV_B, subjetEta[i][j],subjetPt[i][j]); 
						//sf[i][j]=HF.eval(BTagEntry::FLAV_B,subjetEta[i][j],subjetPt[i][j]); 
					
					}
					else if(FATsubjetSDHadronFlavor[i][j]==4){
						sf[i][j]=HFC.eval_auto_bounds("central",BTagEntry::FLAV_C, subjetEta[i][j],subjetPt[i][j]); 
						//sf[i][j]=HF.eval(BTagEntry::FLAV_C,subjetEta[i][j],subjetPt[i][j]); 
				
					}
					else {
						sf[i][j]=LF.eval_auto_bounds("central",BTagEntry::FLAV_UDSG, subjetEta[i][j],subjetPt[i][j]); 
						//sf[i][j]=LF.eval(BTagEntry::FLAV_UDSG,subjetEta[i][j],subjetPt[i][j]); 
						
					}
					//conut nbtag---------------------------------------------------------
					if(subjetSDCSV[i][j]>0.46)nbtag++;
					//get tot. btagging SF
					if(subjetSDCSV[i][j]>=0.46)btaggingscaleFactor*=sf[i][j];
					else btaggingscaleFactor*=((1-eff[i][j]*sf[i][j])/(1-eff[i][j]));
					
				}
			}
			
			
			
			if(nameRoot==2)btaggingscaleFactor=1;
			double scaleFactor=PU_weight[0]*btaggingscaleFactor;
			
			
			
			Float_t*  fatjetTau1 = data.GetPtrFloat("FATjetTau1");
			Float_t*  fatjetTau2 = data.GetPtrFloat("FATjetTau2");
			Float_t*  FATjetPuppiTau1 = data.GetPtrFloat("FATjetPuppiTau1");
			Float_t*  FATjetPuppiTau2 = data.GetPtrFloat("FATjetPuppiTau2");
			double tau21[2];
			tau21[0]=(fatjetTau2[0]/fatjetTau1[0]),tau21[1]=(fatjetTau2[1]/fatjetTau1[1]);
			double puppiTau21[2];
			puppiTau21[0]=(FATjetPuppiTau2[0]/FATjetPuppiTau1[0]),puppiTau21[1]=(FATjetPuppiTau2[1]/FATjetPuppiTau1[1]);
			
			for (int i=0;i<2;i++){
				th5[214+i]->Fill(FATjetPRmass[i],scaleFactor);
				th5[216+i]->Fill(fatjetPRmassL2L3Corr[i],scaleFactor);
				th5[218+i]->Fill(FATjetPuppiSDmass[i],scaleFactor);
				th5[220+i]->Fill(FATjetPuppiSDmassL2L3Corr[i],scaleFactor);
				th5[238+i]->Fill(tau21[i],scaleFactor);
				th5[240+i]->Fill(puppiTau21[i],scaleFactor);
				
				th_flavor[event_flavor][214+i]->Fill(FATjetPRmass[i],scaleFactor);
				th_flavor[event_flavor][216+i]->Fill(fatjetPRmassL2L3Corr[i],scaleFactor);
				th_flavor[event_flavor][218+i]->Fill(FATjetPuppiSDmass[i],scaleFactor);
				th_flavor[event_flavor][220+i]->Fill(FATjetPuppiSDmassL2L3Corr[i],scaleFactor);
				th_flavor[event_flavor][238+i]->Fill(tau21[i],scaleFactor);
				th_flavor[event_flavor][240+i]->Fill(puppiTau21[i],scaleFactor);
			}
			
			if(!(tau21[0]>0.6 || tau21[1]>0.6)){
				for (int i=0;i<2;i++){
					
					th5[222+i]->Fill(FATjetPRmass[i],scaleFactor);
					th5[224+i]->Fill(fatjetPRmassL2L3Corr[i],scaleFactor);
					th5[226+i]->Fill(FATjetPuppiSDmass[i],scaleFactor);
					th5[228+i]->Fill(FATjetPuppiSDmassL2L3Corr[i],scaleFactor);
					th5[242+i]->Fill(tau21[i],scaleFactor);
					th5[244+i]->Fill(puppiTau21[i],scaleFactor);
					
					th_flavor[event_flavor][222+i]->Fill(FATjetPRmass[i],scaleFactor);
					th_flavor[event_flavor][224+i]->Fill(fatjetPRmassL2L3Corr[i],scaleFactor);
					th_flavor[event_flavor][226+i]->Fill(FATjetPuppiSDmass[i],scaleFactor);
					th_flavor[event_flavor][228+i]->Fill(FATjetPuppiSDmassL2L3Corr[i],scaleFactor);
					th_flavor[event_flavor][242+i]->Fill(tau21[i],scaleFactor);
					th_flavor[event_flavor][244+i]->Fill(puppiTau21[i],scaleFactor);
				}
			}
			
			
			if(fatjetPRmassL2L3Corr[0]<105||fatjetPRmassL2L3Corr[0]>135)continue;
			if(fatjetPRmassL2L3Corr[1]<105||fatjetPRmassL2L3Corr[1]>135)continue;
			nPass[8]+=PU_weight[0];
			for (int i=0;i<2;i++){
				
				th5[230+i]->Fill(FATjetPRmass[i],scaleFactor);
				th5[232+i]->Fill(fatjetPRmassL2L3Corr[i],scaleFactor);
				th5[234+i]->Fill(FATjetPuppiSDmass[i],scaleFactor);
				th5[236+i]->Fill(FATjetPuppiSDmassL2L3Corr[i],scaleFactor);
				th5[246+i]->Fill(tau21[i],scaleFactor);
				th5[248+i]->Fill(puppiTau21[i],scaleFactor);
				
				th_flavor[event_flavor][230+i]->Fill(FATjetPRmass[i],scaleFactor);
				th_flavor[event_flavor][232+i]->Fill(fatjetPRmassL2L3Corr[i],scaleFactor);
				th_flavor[event_flavor][234+i]->Fill(FATjetPuppiSDmass[i],scaleFactor);
				th_flavor[event_flavor][236+i]->Fill(FATjetPuppiSDmassL2L3Corr[i],scaleFactor);
				th_flavor[event_flavor][246+i]->Fill(tau21[i],scaleFactor);
				th_flavor[event_flavor][248+i]->Fill(puppiTau21[i],scaleFactor);
			}
			
			//9.-----------------------------------------
			if(tau21[0]>0.6 || tau21[1]>0.6) continue;
			nPass[9]+=PU_weight[0];
			double tau21_SF=1.031*0.881;
			if(JESOption==5)tau21_SF=(1.031+0.126)*(0.881+0.49);
			if(JESOption==6)tau21_SF=(1.031-0.126)*(0.881-0.49);
			if(tau21[0]<0.6 && tau21[1]<0.6 ){
				tau21_SF=1.031*1.031;
				if(JESOption==5)tau21_SF=(1.031+0.126)*(1.031+0.126);
				if(JESOption==6)tau21_SF=(1.031-0.126)*(1.031-0.126);
			}
			
			
			
			
			
			//10.btag
			
			
			//uncertainty -------------------------------------
			//double scaleFactor=btaggingscaleFactor*PU_weight[0]*tau21_SF;
			
			for(int i=0;i<3;i++){
				passPileup[i]+=btaggingscaleFactor*PU_weight[i]*tau21_SF;
				th7[i]->Fill(mjj,btaggingscaleFactor*PU_weight[i]*tau21_SF);
			}
			 for(int i=0;i<101;i++)passPDF[i]+=btaggingscaleFactor*PU_weight[0]*tau21_SF;
			 for(int i=5;i<14;i++)th7[i]->Fill(mjj,btaggingscaleFactor*PU_weight[0]*tau21_SF);
			 fixScaleNum[1]+=PU_weight[0];
			//--------------------------------------
			Float_t  FATjetPuppiSDmassThea[2] ={0};
			FATjetPuppiSDmassThea[0]=FATjetPuppiSDmass[0]*getPUPPIweight(thisJet->Pt(),thisJet->Eta(),tf1);
			FATjetPuppiSDmassThea[1]=FATjetPuppiSDmass[1]*getPUPPIweight(thatJet->Pt(),thatJet->Eta(),tf1);
			eta[0]=thisJet->Eta();
			eta[1]=thatJet->Eta();
			Float_t*  ADDjet_DoubleSV = data.GetPtrFloat("ADDjet_DoubleSV");
			Float_t  FATjet_DoubleSV[2]={0};
			
			Int_t ADDnJet        = data.GetInt("ADDnJet");
			bool matchThis=0,matchThat=0;
			TClonesArray* ADDjetP4 = (TClonesArray*) data.GetPtrTObject("ADDjetP4");
			for(int i=0;i<ADDnJet;i++){
				TLorentzVector* thisAddJet ;
				thisAddJet= (TLorentzVector*)ADDjetP4->At(i);
				if(!matchThis && thisAddJet->DeltaR(*thisJet)<0.8){
					matchThis=1;
					FATjet_DoubleSV[0]=ADDjet_DoubleSV[i];
					continue;
				}
				if(!matchThat && thisAddJet->DeltaR(*thatJet)<0.8){
					matchThat=1;
					FATjet_DoubleSV[1]=ADDjet_DoubleSV[i];
				}
				if(matchThis&& matchThat)break;
			}
			
			
			
			
			Float_t*  FATjetCISVV2 = data.GetPtrFloat("FATjetCISVV2");
			for(int i=0;i<2;i++){
				for(int j=0;j<2;j++){
					
					th5[(i*2+j)*5+nbtag]->Fill(subjetPt[i][j],scaleFactor);
					th5[(i*2+j)*5+nbtag+20]->Fill(subjetEta[i][j],scaleFactor);
					th5[(i*2+j)*5+nbtag+85]->Fill(subjetSDCSV[i][j],scaleFactor);
					if(subjetPt[i][j]>30 && fabs(subjetEta[i][j])<2.4)th5[(i*2+j)*5+nbtag+194]->Fill(subjetSDCSV[i][j],scaleFactor);
					
					th_flavor[event_flavor][(i*2+j)*5+nbtag]->Fill(subjetPt[i][j],scaleFactor);
					th_flavor[event_flavor][(i*2+j)*5+nbtag+20]->Fill(subjetEta[i][j],scaleFactor);
					th_flavor[event_flavor][(i*2+j)*5+nbtag+85]->Fill(subjetSDCSV[i][j],scaleFactor);
					if(subjetPt[i][j]>30 && fabs(subjetEta[i][j])<2.4)th_flavor[event_flavor][(i*2+j)*5+nbtag+194]->Fill(subjetSDCSV[i][j],scaleFactor);
					
				}
				th5[i*5+nbtag+40]->Fill(dr[i],scaleFactor);
				th5[i*5+nbtag+50]->Fill(pt[i],scaleFactor);
				th5[i*5+nbtag+60]->Fill(eta[i],scaleFactor);
				th5[i*5+nbtag+70]->Fill(fatjetPRmassL2L3Corr[i],scaleFactor);
				th5[i*5+nbtag+105]->Fill(tau21[i],scaleFactor);
				th5[i*5+nbtag+120]->Fill(FATjetPuppiSDmassL2L3Corr[i],scaleFactor);
				th5[i*5+nbtag+130]->Fill(puppiTau21[i],scaleFactor);
				th5[i*5+nbtag+140]->Fill(FATjetPRmass[i],scaleFactor);
				th5[i*5+nbtag+150]->Fill(FATjetPuppiSDmass[i],scaleFactor);
				th5[i*5+nbtag+170]->Fill(FATjet_DoubleSV[i],PU_weight[0]);
				th5[i*5+nbtag+184]->Fill(FATjetCISVV2[i],scaleFactor);
				th5[i*5+nbtag+250]->Fill(FATjetPuppiSDmassThea[i],scaleFactor);
				
				th_flavor[event_flavor][i*5+nbtag+40]->Fill(dr[i],scaleFactor);
				th_flavor[event_flavor][i*5+nbtag+50]->Fill(pt[i],scaleFactor);
				th_flavor[event_flavor][i*5+nbtag+60]->Fill(eta[i],scaleFactor);
				th_flavor[event_flavor][i*5+nbtag+70]->Fill(fatjetPRmassL2L3Corr[i],scaleFactor);
				th_flavor[event_flavor][i*5+nbtag+105]->Fill(tau21[i],scaleFactor);
				th_flavor[event_flavor][i*5+nbtag+120]->Fill(FATjetPuppiSDmassL2L3Corr[i],scaleFactor);
				th_flavor[event_flavor][i*5+nbtag+130]->Fill(puppiTau21[i],scaleFactor);
				th_flavor[event_flavor][i*5+nbtag+140]->Fill(FATjetPRmass[i],scaleFactor);
				th_flavor[event_flavor][i*5+nbtag+150]->Fill(FATjetPuppiSDmass[i],scaleFactor);
				th_flavor[event_flavor][i*5+nbtag+170]->Fill(FATjet_DoubleSV[i],PU_weight[0]);
				th_flavor[event_flavor][i*5+nbtag+184]->Fill(FATjetCISVV2[i],scaleFactor);
				th_flavor[event_flavor][i*5+nbtag+250]->Fill(FATjetPuppiSDmassThea[i],scaleFactor);
				
			}
			th5[nbtag+80]->Fill(mjj,scaleFactor);
			th5[nbtag+115]->Fill(dEta,scaleFactor);
			th5[nbtag+165]->Fill(mjjRed,scaleFactor);
			
			th_flavor[event_flavor][nbtag+80]->Fill(mjj,scaleFactor);
			th_flavor[event_flavor][nbtag+115]->Fill(dEta,scaleFactor);
			th_flavor[event_flavor][nbtag+165]->Fill(mjjRed,scaleFactor);
			
			nPass[nbtag+10]+=PU_weight[0]*btaggingscaleFactor;
				
			
			
			int nDoubleSV=0;
			if(FATjet_DoubleSV[0]>0.6)nDoubleSV++;
			if(FATjet_DoubleSV[1]>0.6)nDoubleSV++;
			
			if(nDoubleSV==0)nPass[15]+=PU_weight[0];
			else if(nDoubleSV==2)nPass[17]+=PU_weight[0];
			else {
				nPass[16]+=PU_weight[0];
				if((FATjet_DoubleSV[0]>0.6 && subjetSDCSV[1][0]<0.46 && subjetSDCSV[1][1]<0.46) ||
				     (FATjet_DoubleSV[1]>0.6 && subjetSDCSV[0][0]<0.46 && subjetSDCSV[0][1]<0.46))nPass[18]+=PU_weight[0];
				else if((FATjet_DoubleSV[0]>0.6 && subjetSDCSV[1][0]>0.46 && subjetSDCSV[1][1]>0.46) ||
				               (FATjet_DoubleSV[1]>0.6 && subjetSDCSV[0][0]>0.46 && subjetSDCSV[0][1]>0.46))nPass[20]+=PU_weight[0];
				else nPass[19]+=PU_weight[0];
			}
			
			
			th5[182]->Fill(nVtx,scaleFactor);
			th5[183]->Fill(ntrue,scaleFactor);
			th_flavor[event_flavor][182]->Fill(nVtx,scaleFactor);
			th_flavor[event_flavor][183]->Fill(ntrue,scaleFactor);

		}//end event loop----------------------------------------------------------------------------------------
	}	//end ntuple loop----------------------------------------------------------------------------------------
	cout<<"entries="<<total<<endl;	
	for(int i=0;i<22;i++)cout<<"nPass["<<i<<"]="<<nPass[i]<<endl;
	
	for(int i=0;i<3;i++)th7[3]->SetBinContent(i+1,passPileup[i]/totalPileup[i]);
	for(int i=0;i<101;i++)th7[4]->SetBinContent(i+1,passPDF[i]/totalPDF[i]);
	
	TH1D * th2o=new TH1D("Nbtagjet","Nbtagjet",5,-0.5,4.5);
	for (int i=0;i<5;i++){
		if(nameRoot==2 && i>2)continue;
		th2o->SetBinContent(i+1,nPass[i+10]);
	}
	
	TH1D * fixScale=new TH1D("fixScale","fixScale",2,-0.5,1.5);
	fixScale->SetBinContent(1,fixScaleNum[0]);
	fixScale->SetBinContent(2,fixScaleNum[1]);
	TH1D * cutflow=new TH1D("cutflow","cutflow",21,0.5,21.5);
	cutflow->SetBinContent(1,fixScaleNum[0]);
	if(nameRoot!=2)for(int ii=1;ii<22;ii++)cutflow->SetBinContent(ii+1,nPass[ii-1]);
	else for(int ii=1;ii<16;ii++)cutflow->SetBinContent(ii+1,nPass[ii-1]);
	
	TFile* outFile ;
	if(JESOption==0)outFile= new TFile(Form("sf2/%s.root",st2.data()),"recreate");
	else if(JESOption==1)outFile= new TFile(Form("sf2/%s_JESUp.root",st2.data()),"recreate");
	else if(JESOption==2)outFile= new TFile(Form("sf2/%s_JESDown.root",st2.data()),"recreate");
	else if(JESOption==3)outFile= new TFile(Form("sf2/%s_BtagUp.root",st2.data()),"recreate");
	else if(JESOption==4)outFile= new TFile(Form("sf2/%s_BtagDown.root",st2.data()),"recreate");
	else if(JESOption==5)outFile= new TFile(Form("sf2/%s_tau21Up.root",st2.data()),"recreate");
	else if(JESOption==6)outFile= new TFile(Form("sf2/%s_tau21Down.root",st2.data()),"recreate");
	th2o->Write();
	fixScale->Write();
	cutflow->Write();
	
	for(int i=0;i<260;i++){
		th5[i]->Write();
		th_flavor[0][i]->Write();
		th_flavor[1][i]->Write();
		th_flavor[2][i]->Write();
		th_flavor[3][i]->Write();
	}
	
	for(int i=0;i<14;i++)th7[i]->Write();
	outFile->Close();
}
Ejemplo n.º 7
0
void Analyze7p2_Lin(bool force_recompile=true)
{
    FNameManager fnm("fnameconfig.dat");
    TString results_dir = fnm.GetResultsDir(true);
    TString target_id  = TString::Format("%s_%.1f_%s",target.Data(), eg, pol.Data());
    TString combined_hist_run = (results_dir + "/");
    combined_hist_run += (fnm.GetHistFileBase(false) + target_id.Data() + ".root");

    TString int_file = (fnm.GetResultsDir() + "/IntOutput/" + target_id.Data());
    TString int_subbed_file = (fnm.GetResultsDir() + "/IntOutput/" + target_id.Data() + "_bgsubbed");
    TString int_sanormed_file = (fnm.GetResultsDir() + "/IntOutput/" + target_id.Data() + "_sanormed");
    TString int_subbed_sanormed_file = (fnm.GetResultsDir() + "/IntOutput/" + target_id.Data() + "_bgsubbed_sanormed");

    TString angle_file = "angle_data/angles";
    TString sa_corr_file = "angle_data/sa_corrections";
    TString correction_id = TString::Format("%s_%.1f_%s", target.Data(), eg, pol.Data());
    TString circ_corr_file = TString::Format("corrections%s.root",correction_id.Data());

    TString angdist_dir = (results_dir + "/ang_dists");
    TString angdist_text_file = (angdist_dir + "/angdists_" + target_id + ".dat");
    TString angdist_subbed_text_file = (angdist_dir + "/angdists_" + target_id + "_bgsubbed.dat");

    TString angdist_sanormed_text_file = (angdist_dir + "/angdists_" + target_id + "_sanormed" + ".dat");
    TString angdist_subbed_sanormed_text_file = (angdist_dir + "/angdists_" + target_id + "_sanormed_bgsubbed.dat");

    TString angdist_root_file = (angdist_dir + "/angdists_" + target_id + ".root");
    TString angdist_subbed_root_file = (angdist_dir + "/angdists_" + target_id + "_bgsubbed.root");
    TString angdist_sanormed_root_file = (angdist_dir + "/angdists_" + target_id + "_sanormed" + ".root");
    TString angdist_subbed_sanormed_root_file = (angdist_dir + "/angdists_" + target_id + "_sanormed_bgsubbed.root");


    TString overnight_hist_run = (results_dir + "/" + fnm.GetHistFileBase(false).data() + bgnd_id + "_0.0_--.root");


    if (force_recompile==true)
    {
        gROOT->ProcessLine(".L analysis_soft/Scripts/GenerateTGraphInputFiles.cpp++");
        gROOT->ProcessLine(".L analysis_soft/Scripts/CreatePlotOverlay.C++");
        gROOT->ProcessLine(".L analysis_soft/Scripts/CleanupCombinedCanvasesDirectory.cpp++");
        gROOT->ProcessLine(".L analysis_soft/Scripts/CreateOverlayCanvases.cpp++");
        gROOT->ProcessLine(".L analysis_soft/Scripts/GenerateRatioAndAsymmetry.cpp++");
        gROOT->ProcessLine(".L GenerateSubtractionUncertainties.cpp++");
        gROOT->ProcessLine(".L NormalizeByLiveTimeFractionForRuns.cpp++");
        gROOT->ProcessLine(".L NormalizeAllHists.C++");
        gROOT->ProcessLine(".L ShiftHistsFromFile.cpp++");
        gROOT->ProcessLine(".L SubtractBgnd.cpp++");
        gROOT->ProcessLine(".L UnnormalizeAllHists.C++");
        gROOT->ProcessLine(".L NormalizeAlphaCountsByReference.cpp++");
        gROOT->ProcessLine(".L CalibrateHIsts.cpp++");
        gROOT->ProcessLine(".L CreateSysCorrRatios.cpp++");
        gROOT->ProcessLine(".L CreateRatioFromAlphaInts.cpp++");

    }
    else
    {
        gROOT->ProcessLine(".L analysis_soft/Scripts/GenerateTGraphInputFiles.cpp+");
        gROOT->ProcessLine(".L analysis_soft/Scripts/CreatePlotOverlay.C+");
        gROOT->ProcessLine(".L analysis_soft/Scripts/CleanupCombinedCanvasesDirectory.cpp+");
        gROOT->ProcessLine(".L analysis_soft/Scripts/CreateOverlayCanvases.cpp+");
        gROOT->ProcessLine(".L analysis_soft/Scripts/GenerateRatioAndAsymmetry.cpp+");
        gROOT->ProcessLine(".L GenerateSubtractionUncertainties.cpp+");
        gROOT->ProcessLine(".L NormalizeByLiveTimeFractionForRuns.cpp+");
        gROOT->ProcessLine(".L NormalizeAllHists.C+");
        gROOT->ProcessLine(".L ShiftHistsFromFile.cpp+");
        gROOT->ProcessLine(".L SubtractBgnd.cpp+");
        gROOT->ProcessLine(".L UnnormalizeAllHists.C+");
        gROOT->ProcessLine(".L NormalizeAlphaCountsByReference.cpp+");
        gROOT->ProcessLine(".L CalibrateHIsts.cpp+");
        gROOT->ProcessLine(".L CreateSysCorrRatios.cpp+");
        gROOT->ProcessLine(".L CreateRatioFromAlphaInts.cpp+");
    }
    cout << "BEGIN ANALYSIS" << endl;
    cout << "begin processing runs" << endl;

    TString message = TString::Format("Form LTF corrected histograms");
    if (OkToContinue(message))
    {
        FormAlphaLTFCorrection(target.Data(), eg, pol.Data(), 678);
    }


    message = TString::Format("combine %s, Eg=%.1f, %s", target.Data(), eg, pol.Data());
    if (OkToContinue(message))
    {
        CombineAllRunsForTargetWithEnergyAndPol(target.Data(),eg,pol.Data(),true);
        f = new TFile(combined_hist_run,"UPDATE");
        CleanupCombinedCanvasesDirectory(f);
        f->Close();
        f = TFile::Open(combined_hist_run,"UPDATE");
        CreateOverlayCanvases(f);
        f->Close();
    }

    message = TString::Format("calibrate %s, Eg=%.1f, %s", target.Data(), eg, pol.Data());
    if (OkToContinue(message))
    {
        f = new TFile(combined_hist_run.Data(),"UPDATE");
        TDirectory* dir = f->GetDirectory("adc");
        if (dir==0)
        {
            std::cout << "\tfailed to find adc folder in " << f->GetName() << std::endl;
        }
        else
        {
            std::cout << "\tCalibrating adc with " << calib_file
                    << std::endl;
            CalibrateHists(dir, calib_file.Data());
        }
        f->Close();
        dir = 0;

        f = new TFile(combined_hist_run.Data(),"UPDATE");
        dir = f->GetDirectory("ltf_corr_adc");
        if (dir==0)
        {
            std::cout << "\tfailed to find ltf_corr_adc folder in " << f->GetName() << std::endl;
        }
        else
        {
            std::cout << "\tCalibrating ltf_corr_adc with " << calib_file
                    << std::endl;
            CalibrateHists(dir, calib_file.Data());
        }

        dir = 0;

        dir = f->GetDirectory("ltf_corr_adc_gt_thresh");
        if (dir==0)
        {
            std::cout << "\tfailed to find ltf_corr_adc_gt_thresh folder in " << f->GetName() << std::endl;
        }
        else
        {
            std::cout << "\tCalibrating ltf_corr_adc_gt_thresh with " << calib_file
                    << std::endl;
            CalibrateHists(dir, calib_file.Data());
        }

        f->Close();
    }
//    TFile *f, *fcorr;
//    message = TString::Format("normalize %s, Eg=%.1f, %s data by 10HzClock",
//                              target.Data(), eg, pol.Data());
//    if (OkToContinue(message))
//    {
//        f = new TFile(combined_hist_run.Data(),"UPDATE");
//
//        std::cout << "\tNormalizing hists in ltf_corr_adc directory" << std::endl;
//        TDirectory *dir = f->GetDirectory("ltf_corr_adc_cut_tofcut");
//        if (dir==0)  std::cout << "cannot find ltf_corr_adc histograms" << std::endl;
//        else         NormalizeAllHists(dir,1/16042.0);
//
//        std::cout << "\tNormalizing hists in ltf_corr_adc_gt_thresh directory" << std::endl;
//        dir = f->GetDirectory("ltf_corr_adc_gt_thresh_tofcut");
//        if (dir==0)  std::cout << "cannot find ltf_corr_adc_gt_thresh histograms" << std::endl;
//        else         NormalizeAllHists(dir,1/16042.0);
//
//        f->Close();
//    }

    cout << "\n\nBegin processing runs overnight background runs\n" << endl;
     cout << "Do you want to skip the overnight bgnd subtraction? (y/n) " << endl;
     Char_t myans;
     cin >> myans;
     if (myans=='n')
     {
         message = TString::Format("Form LTF corrected histograms");
         if (OkToContinue(message))
         {
             FormAlphaLTFCorrection(bgnd_id.Data(), 0, "--", 678);
         }

         message = TString::Format("combine runs and set errors on %s", bgnd_id.Data());
         if (OkToContinue(message))
         {
             CombineAllRunsForTargetWithEnergyAndPol(bgnd_id.Data(),0,"--");
         }

         message = TString::Format("normalize %s by Veto10HzClock", bgnd_id.Data());
         if (OkToContinue(message))
         {
             f = new TFile(overnight_hist_run.Data(),"UPDATE");

             std::cout << "\tNormalizing hists in ltf_corr_adc directory" << std::endl;
             TDirectory *dir = f->GetDirectory("ltf_corr_adc");
             if (dir==0) std::cout << "Cannot find ltf_corr_adc folder" << std::endl;
             else        NormalizeAllHists(dir,normalization);

             std::cout << "\tNormalizing hists in ltf_corr_adc_gt_thresh directory" << std::endl;
             dir = f->GetDirectory("ltf_corr_adc_gt_thresh");
             if (dir==0) std::cout << "Cannot find ltf_corr_adc_gt_thresh folder" << std::endl;
             else        NormalizeAllHists(dir,normalization);

             std::cout << "\tNormalizing hists in ltf_corr_adc_gt_thresh_tofcut directory" << std::endl;
             dir = f->GetDirectory("ltf_corr_adc_gt_thresh_tofcut");
             if (dir==0) std::cout << "Cannot find ltf_corr_adc_gt_thresh_tofcut folder" << std::endl;
             else        NormalizeAllHists(dir,normalization);
             f->Close();
         }

         message = TString::Format("calibrate %s", bgnd_id.Data());
         if (OkToContinue(message))
         {
             f = new TFile(overnight_hist_run,"UPDATE");
             TDirectory* dir = f->GetDirectory("adc");
             if (dir==0)
             {
                 std::cout << "\tfailed to find adc folder in " << f->GetName() << std::endl;
             }
             else
             {
                 std::cout << "\tCalibrating adc with " << bgnd_calib_file
                         << std::endl;
                 CalibrateHists(dir, bgnd_calib_file.Data());
             }

             f = new TFile(overnight_hist_run,"UPDATE");
             dir = f->GetDirectory("normed_ltf_corr_adc");
             if (dir==0)
             {
                 std::cout << "\tfailed to find normed_ltf_corr_adc folder in " << f->GetName() << std::endl;
             }
             else
             {
                 std::cout << "\tCalibrating normed_ltf_corr_adc with " << bgnd_calib_file
                         << std::endl;
                 CalibrateHists(dir, bgnd_calib_file.Data());
             }

             dir = f->GetDirectory("normed_ltf_corr_adc_gt_thresh");
             if (dir==0)
             {
                 std::cout << "\tfailed to find normed_ltf_corr_adc_gt_thresh folder in " << f->GetName() << std::endl;
             }
             else
             {
                 std::cout << "\tCalibrating normed_ltf_corr_adc_gt_thresh with " << bgnd_calib_file
                         << std::endl;
                 CalibrateHists(dir, bgnd_calib_file.Data());
             }

//             dir = f->GetDirectory("normed_ltf_corr_adc_gt_thresh_sanormed");
//             if (dir==0)
//             {
//                 std::cout << "\tfailed to find normed_ltf_corr_adc_gt_thresh_sanormed folder in " << f->GetName() << std::endl;
//             }
//             else
//             {
//                 std::cout << "\tCalibrating normed_ltf_corr_adc_gt_thresh_sanormed with " << bgnd_calib_file
//                         << std::endl;
//                 CalibrateHists(dir, bgnd_calib_file.Data());
//             }

             f->Close();
         }

         message = TString::Format("align %s, Eg=%.1f, %s hists to %s",
                                   target.Data(), eg, pol.Data(), bgnd_id.Data());
         if (OkToContinue(message))
         {
             f = new TFile(combined_hist_run.Data(),"UPDATE");

             std::cout << "\tShifting ltf_corr_adc hists" << std::endl;
             TDirectory *dir = f->GetDirectory("ltf_corr_adc");
             if (dir==0)  std::cout << "cannot find ltf_corr_adc directory" << std::endl;
             else         ShiftHistsFromFile(dir, shift_data.Data());

             std::cout << "\tShifting ltf_corr_adc_gt_thresh hists" << std::endl;
             dir = f->GetDirectory("ltf_corr_adc_gt_thresh");
             if (dir==0)  std::cout << "cannot find ltf_corr_adc_gt_thresh directory" << std::endl;
             else         ShiftHistsFromFile(dir, shift_data.Data());

             std::cout << "\tShifting ltf_corr_adc_gt_thresh_tofcut hists" << std::endl;
             dir = f->GetDirectory("ltf_corr_adc_gt_thresh_tofcut");
             if (dir==0)  std::cout << "cannot find ltf_corr_adc_gt_thresh_tofcut directory" << std::endl;
             else         ShiftHistsFromFile(dir, shift_data.Data());
             f->Close();
         }

         cout << "Subtraction..." << endl;
         message = TString::Format("subtract %s from %s, Eg=%.1f, %s data",
                                   bgnd_id.Data(), target.Data(), eg, pol.Data());
         if (OkToContinue(message))
         {
             f = new TFile(combined_hist_run.Data(),"UPDATE");

             std::cout << "\tSubtracting shifted_ltf_corr_adc hists" << std::endl;
             TDirectory *dir = f->GetDirectory("shifted_ltf_corr_adc");
             if (dir==0)
             {
                 std::cout << "cannot find shifted shifted_ltf_corr_adc histograms" << std::endl;
             }
             else
             {
                 fbg = new TFile(overnight_hist_run.Data(),"UPDATE");
                 TDirectory *dirbg = fbg->GetDirectory("normed_ltf_corr_adc");
                 if (dirbg==0)   std::cout << "cannot find normed histograms in " << fbg->GetName() << std::endl;
                 else     	      SubtractBgndRuns(dirbg,dir);
                 fbg->Close();
             }

             std::cout << "\tSubtracting shifted_ltf_corr_adc_gt_thresh hists" << std::endl;
             dir = f->GetDirectory("shifted_ltf_corr_adc_gt_thresh");
             if (dir==0)
             {
                 std::cout << "cannot find shifted_ltf_corr_adc_gt_thresh histograms" << std::endl;
             }
             else
             {
                 fbg = new TFile(overnight_hist_run.Data(),"UPDATE");
                 TDirectory *dirbg = fbg->GetDirectory("normed_ltf_corr_adc_gt_thresh");
                 if (dirbg==0) std::cout << "cannot find normed histograms in " << fbg->GetName() << std::endl;
                 else          SubtractBgndRuns(dirbg,dir);
                 fbg->Close();
             }

             std::cout << "\tSubtracting shifted_ltf_corr_adc_gt_thresh_tofcut hists" << std::endl;
             dir = f->GetDirectory("shifted_ltf_corr_adc_gt_thresh_tofcut");
             if (dir==0)
             {
                 std::cout << "cannot find shifted_ltf_corr_adc_gt_thresh_tofcut histograms" << std::endl;
             }
             else
             {
                 fbg = new TFile(overnight_hist_run.Data(),"UPDATE");
                 TDirectory *dirbg = fbg->GetDirectory("normed_ltf_corr_adc_gt_thresh_tofcut");
                 if (dirbg==0) std::cout << "cannot find normed histograms in " << fbg->GetName() << std::endl;
                 else          SubtractBgndRuns(dirbg,dir);
                 fbg->Close();
             }


             f->Close();
         }

//         message = TString::Format("unnormalize run bgsubbed %s", pol.Data());
//          if (OkToContinue(message))
//          {
//              f = new TFile(combined_hist_run.Data(),"UPDATE");
//
//              std::cout << "\tUnnormalizing adc hists" << std::endl;
//              TDirectory* dir = f->GetDirectory("bgsubbed_shifted_ltf_corr_adc");
//              if (dir==0)  std::cout << "Cannot find folder containing hists" << std::endl;
//              else         UnnormalizeAllHists(dir,16042.0);
//
//              std::cout << "\tUnnormalizing adc_gt_thresh hists" << std::endl;
//              dir = f->GetDirectory("bgsubbed_shifted_ltf_corr_adc_gt_thresh");
//              if (dir==0)  std::cout << "Cannot find folder containing hists" << std::endl;
//              else         UnnormalizeAllHists(dir,16042.0);
//
//              f->Close();
//          }
     }

     if (OkToContinue("compute systematic unc. from overnight bgnd histograms"))
     {
         TString uncorr_dir = "ltf_corr_adc_gt_thresh";
         TString corr_dir = "bgsubbed_shifted_ltf_corr_adc_gt_thresh";
         f = new TFile(combined_hist_run.Data(),"update");
         TDirectory* du = f->GetDirectory(uncorr_dir.Data());
         TDirectory* ds = f->GetDirectory(corr_dir.Data());

         if (du==0)      std::cout << "Cannot find " << uncorr_dir << std::endl;
         else if (ds==0) std::cout << "Cannot find " << corr_dir << std::endl;
         else
         {
             TGraph* gr = GenerateSubtractionUncertainties(du, ds);
             f->cd();
             gr->Write("", TObject::kOverwrite);
         }

         f->Close();
     }

//     if (OkToContinue("Form alpha normalized spectra"))
//     {
//         f = new TFile(combined_hist_run.Data(),"update");
//
//         TString uncorr_dir = "ltf_corr_adc_gt_thresh";
//         TString corr_dir = "bgsubbed_shifted_ltf_corr_adc_gt_thresh";
//         TDirectory* du = f->GetDirectory(uncorr_dir.Data());
//
//
//         if (du==0)      std::cout << "Cannot find " << uncorr_dir << std::endl;
//         else
//         {
//            CreateAlphaNormedHists(du, "g4_sa_corr_232Th.dat");
//         }
//
//         TDirectory* dc = f->GetDirectory(corr_dir);
//
//         if (dc==0)      std::cout << "Cannot find " << corr_dir << std::endl;
//         else
//         {
//            CreateAlphaNormedHists(dc, "g4_sa_corr_232Th.dat");
//         }
//
//         f->Close();
//     }

    if (OkToContinue("integrate all \"adc_gt_thresh_tofcut\" histograms"))
    {
        PAnalysis::IntegrateSiStrips(combined_hist_run,
                                     TString("ltf_corr_adc_gt_thresh"),
                                     TString(""));

        PAnalysis::IntegrateSiStrips(combined_hist_run,
                                     "normed_bgsubbed_ltf_corr_adc_gt_thresh",
                                     "",
                                     int_subbed_file,
                                     "bgsubbed_shifted_ltf_corr_adc_gt_thresh");

//        PAnalysis::IntegrateSiStrips(combined_hist_run,
//                                     "ltf_corr_adc_gt_thresh",
//                                     "_sanormed",
//                                     int_sanormed_file,
//                                     "ltf_corr_adc_gt_thresh_sanormed");
//
//        PAnalysis::IntegrateSiStrips(combined_hist_run,
//                                     "ltf_corr_normed_bgsubbed_ltf_corr_adc_gt_thresh",
//                                     "_sanormed",
//                                     int_subbed_sanormed_file,
//                                     "bgsubbed_shifted_ltf_corr_adc_gt_thresh_sanormed");
//
    }

    if (OkToContinue("generate angular distribution"))
    {
        GenerateTGraphInputFiles(int_file.Data(),
                                 angle_file.Data(),
                                 angdist_text_file.Data());

        GenerateTGraphInputFiles(int_subbed_file.Data(),
                                 angle_file.Data(),
                                 angdist_subbed_text_file.Data());

//        GenerateTGraphInputFiles(int_sanormed_file.Data(),
//                                 angle_file.Data(),
//                                 angdist_sanormed_text_file.Data());
//
//        GenerateTGraphInputFiles(int_subbed_sanormed_file.Data(),
//                                 angle_file.Data(),
//                                 angdist_subbed_sanormed_text_file.Data());
//
    }

    if (OkToContinue("generate ratio and asymmetry plots"))
    {
        f = new TFile(angdist_root_file.Data(),"UPDATE");
        GenerateRatioAndAsymmetry(f);
        f->Close();

        f = new TFile(angdist_subbed_root_file.Data(),"UPDATE");
        GenerateRatioAndAsymmetry(f);
        f->Close();

//        f = new TFile(angdist_sanormed_root_file.Data(),"UPDATE");
//        GenerateRatioAndAsymmetry(f);
//        f->Close();
//
//        f = new TFile(angdist_subbed_sanormed_root_file.Data(),"UPDATE");
//        GenerateRatioAndAsymmetry(f);
//        f->Close();
//
    }

    if (OkToContinue("create overlaid angular distributions"))
    {
        gROOT->SetBatch(true);
        f = new TFile(angdist_root_file.Data(),"UPDATE");
        CreatePlotOverlay(f, Form("%s E_{#gamma}=%.1f MeV %s Yields", target.Data(), eg, pol.Data()));
        f->Close();

        f = new TFile(angdist_subbed_root_file.Data(),"UPDATE");
        CreatePlotOverlay(f, Form("%s E_{#gamma}=%.1f MeV %s Yields (subbed)", target.Data(), eg, pol.Data()));
        f->Close();

//        f = new TFile(angdist_sanormed_root_file.Data(),"UPDATE");
//        CreatePlotOverlay(f, Form("%s E_{#gamma}=%.1f MeV %s Yields SA Normed", target.Data(), eg, pol.Data()));
//        f->Close();
//
//        f = new TFile(angdist_subbed_sanormed_root_file.Data(),"UPDATE");
//        CreatePlotOverlay(f, Form("%s E_{#gamma}=%.1f MeV %s Yields SA Normed (subbed)", target.Data(), eg, pol.Data()));
//        f->Close();
//
        gROOT->SetBatch(false);
    }

//    if (OkToContinue("generate 2D angular dist"))
//    {
//        GenerateTGraph2D(angdist_corr_text_file.Data(), angdist_root_file.Data());
//        f = new TFile(angdist_root_file.Data(),"UPDATE");
////        GenerateTH2D(f);
//        f->Close();
//
//        GenerateTGraph2D(angdist_corr_text_file.Data(), angdist_root_file.Data());
//        f = new TFile(angdist_root_file.Data(),"UPDATE");
////        GenerateTH2D(f);
//        f->Close();
//
//
//    }

    if (OkToContinue("form alpha_ratio graph"))
    {
        f = new TFile(combined_hist_run.Data(),"UPDATE");

        StripDb sdb(angle_file.Data());
        TH1* halpha_ints;
        f->GetObject("alpha_ints",halpha_ints);
        TGraphErrors* gr_alpha_ratio = CreateRatioFromStripHist(halpha_ints,sdb);
		gr_alpha_ratio->Sort();
        gr_alpha_ratio->Write("alpha_ratio", TObject::kOverwrite);
        f->Close();
    }



    if (OkToContinue("incorporate systematic uncertainty into the ratio"))
    {
        f = new TFile(combined_hist_run.Data(),"UPDATE");
//        if (gr_==0)
//        {
//            std::cout << "Failed to find the ratio graph" << std::endl;
//        }
//        else
//        {
            TFile* fsim = new TFile("alpha_source_r3_r5_x1_y0_z0_80M_analyzed.root");
            // the next will look for the alpha_ratio graphs in specified directories
            CreateSysCorrRatios(f, fsim, angdist_subbed_root_file.Data());
            fsim->Close();
  //      }
        f->Close();

        f = new TFile(angdist_subbed_root_file.Data(),"UPDATE");
        TDirectory* d = f->GetDirectory("uncorrected");
        TGraphErrors* gr_ = 0;
        d->GetObject("ratio",gr_);
        if (gr_==0)
        {
            std::cout << "Failed to find the ratio graph" << std::endl;
        }
        else
        {
            TGraphErrors* grsys = 0;
            f->GetObject("systematic_alpha_diffs",grsys);
            if (grsys!=0)
            {
                CreateCorrectedRatios(gr_, grsys, f);
            }
            else
            {
                std::cout << "Couldn't find systematic_alpha_diffs graph" << std::endl;
            }
            fsim->Close();
        }

        f->Close();

    }

    cout << "ANALYSIS COMPLETE" << endl;
}
void HHbbbbBtagEffBase_76(int wMs,int wM, string st,string st2,string option=""){	
	//0=signal ,1=QCD ,2=data-----------------------------------------------------------
	int nameRoot=1;
	if(st2.find("QCD")!= std::string::npos)nameRoot=0;
	if(st2.find("data")!= std::string::npos)nameRoot=2;
	//option-----------------------------------------------------------
	int JESOption=0;
	if(option.find("JESUp")!= std::string::npos)JESOption=1;
	if(option.find("JESDown")!= std::string::npos)JESOption=2;
	if(option.find("BtagUp")!= std::string::npos)JESOption=3;
	if(option.find("BtagDown")!= std::string::npos)JESOption=4;
	if(option.find("tau21Up")!= std::string::npos)JESOption=5;
	if(option.find("tau21Down")!= std::string::npos)JESOption=6;
	cout<<"JESOption = "<<JESOption<<endl;
	//tuple tree and cutflow variables------------------------------------------------------------------------------------
	TFile *f;
	TTree *tree;
	int nPass[20]={0},total=0,dataPassingcsc=0;
	double nPassB[6]={0};
	//using for Btag Eff -----------------------------------------------------------------------------
	string btagsystematicsType="central";
	if(JESOption==3)btagsystematicsType="up";
	else if(JESOption==4)btagsystematicsType="down";
	BTagCalibration calib("CSVv2L", "../CSVv2_76.csv");
	BTagCalibrationReader LF(&calib,               // calibration instance
                             BTagEntry::OP_LOOSE,  // operating point
                             "incl",               // measurement type
                             btagsystematicsType);           // systematics type
	BTagCalibrationReader HF(&calib, BTagEntry::OP_LOOSE,  "mujets",btagsystematicsType);        
	TFile *f1;
	if(nameRoot==2)f1=TFile::Open("../btagEffSource/data.root");
	else if (nameRoot!=2 && (JESOption==0||JESOption==3||JESOption==4||JESOption==5||JESOption==6))f1=TFile::Open(Form("../btagEffSource/%s.root",st2.data()));
	else if (nameRoot!=2 && JESOption==1)f1=TFile::Open(Form("../btagEffSource/%s_JESUp.root",st2.data()));
	else if (nameRoot!=2 && JESOption==2)f1=TFile::Open(Form("../btagEffSource/%s_JESDown.root",st2.data()));
	TH2D* th1[6];
	string btaggingEff[6]={"effD_b","effN_b","effD_c","effN_c","effD_l","effN_l"};
	for(int i=0;i<6;i++){
		th1[i]=(TH2D*)f1->FindObjectAny(Form("%s",btaggingEff[i].data()));
		if(i==1||i==3||i==5)th1[i]->Divide(th1[i-1]);
	}
	//check for zero btagging SF----------------------------------------------------------------------------------------
	TH2D* th3[6];
	th3[0]=new TH2D("zeroSF_b","zeroSF_b",200,0,2000,60,-3,3);
	th3[1]=new TH2D("zeroSF_c","zeroSF_c",200,0,2000,60,-3,3);
	th3[2]=new TH2D("zeroSF_l","zeroSF_l",200,0,2000,60,-3,3);
	th3[3]=new TH2D("SF_vs_Pt_b","SF_vs_Pt_b",120,0,1200,40,0.8,1.2);
	th3[4]=new TH2D("SF_vs_Pt_c","SF_vs_Pt_c",120,0,1200,40,0.8,1.2);
	th3[5]=new TH2D("SF_vs_Pt_l","SF_vs_Pt_l",120,0,1200,40,0.8,1.2);
	for(int i=0;i<6;i++)th3[i]->Sumw2();
	//check for high btagging SF----------------------------------------------------------------------------------------
	TH1D* th4[14];
	string SF_jet_sub[8]={"SF_jet0_sub0_pass","SF_jet0_sub1_pass","SF_jet1_sub0_pass","SF_jet1_sub1_pass","SF_jet0_sub0_fail","SF_jet0_sub1_fail","SF_jet1_sub0_fail","SF_jet1_sub1_fail"};
	for(int i=0;i<8;i++)th4[i]=new TH1D(Form("%s",SF_jet_sub[i].data()),Form("%s",SF_jet_sub[i].data()),40,0.8,1.2);
	string weightName[6]={"weight","weight_0b","weight_1b","weight_2b","weight_2b_ll","weight_2b_onel"};
	for(int i=0;i<6;i++)th4[i+8]=new TH1D(Form("%s",weightName[i].data()),Form("%s",weightName[i].data()),40,0,2);
	for(int i=0;i<14;i++)th4[i]->Sumw2();
	//saving variables----------------------------------------------------------------------------------------
	TH1D * th5[200],* th6[200];
	for(int i=0;i<2;i++){
		for(int j=0;j<2;j++){
			for(int k=0;k<5;k++){
				th5[(i*2+j)*5+k]=new TH1D(Form("Pt_j%d_sj%d_%db",i,j,k),Form("Pt_j%d_sj%d_%db",i,j,k),200,0,2000);
				th5[(i*2+j)*5+k+20]=new TH1D(Form("Eta_j%d_sj%d_%db",i,j,k),Form("Eta_j%d_sj%d_%db",i,j,k),60,-3,3);
				th5[(i*2+j)*5+k+85]=new TH1D(Form("subCSV_j%d_sj%d_%db",i,j,k),Form("subCSV_j%d_sj%d_%db",i,j,k),20,0,1);
			}
		}
		for(int k=0;k<5;k++){
			th5[i*5+k+40]=new TH1D(Form("deltaR_j%d_%db",i,k),Form("deltaR_j%d_%db",i,k),20,0,1);
			th5[i*5+k+50]=new TH1D(Form("Pt_j%d_%db",i,k),Form("Pt_j%d_%db",i,k),200,0,2000);
			th5[i*5+k+60]=new TH1D(Form("Eta_j%d_%db",i,k),Form("Eta_j%d_%db",i,k),60,-3,3);
			th5[i*5+k+70]=new TH1D(Form("prMassL2L3_j%d_%db",i,k),Form("prMassL2L3_j%d_%db",i,k),15,90,150);
			th5[i*5+k+105]=new TH1D(Form("tau21_j%d_%db",i,k),Form("tau21_j%d_%db",i,k),25,0,1);
			th5[i*5+k+120]=new TH1D(Form("PuppiSDmassL2L3_j%d_%db",i,k),Form("PuppiSDmassL2L3_j%d_%db",i,k),15,90,150);
			th5[i*5+k+130]=new TH1D(Form("puppiTau21_j%d_%db",i,k),Form("puppiTau21_j%d_%db",i,k),25,0,1);
			th5[i*5+k+140]=new TH1D(Form("prMass_j%d_%db",i,k),Form("prMass_j%d_%db",i,k),15,90,150);
			th5[i*5+k+150]=new TH1D(Form("PuppiSDmass_j%d_%db",i,k),Form("PuppiSDmass_j%d_%db",i,k),15,90,150);
		}
	}
	for(int k=0;k<5;k++){
		th5[k+80]=new TH1D(Form("totalMass_%db",k),Form("totalMass_%db",k),200,1000,5000);
		th5[k+115]=new TH1D(Form("deltaEta_%db",k),Form("deltaEta_%db",k),40,0,2);
		th5[k+160]=new TH1D(Form("logPt_%db",k),Form("logPt_%db",k),70,0,7);
	}
	for(int i=0;i<165;i++){
		th6[i]=(TH1D* )th5[i]->Clone(Form("%ss",th5[i]->GetTitle()));
		th5[i]->Sumw2();
		th6[i]->Sumw2();
	}
	//pileup uncertainty----------------------------------------------------------------------------------------
	TH1D* th7[14];
	th7[0]=new TH1D("totalMass","totalMass",200,1000,5000);
	th7[1]=new TH1D("totalMass_pileup_up","totalMass_pileup_up",200,1000,5000);
	th7[2]=new TH1D("totalMass_pileup_down","totalMass_pileup_down",200,1000,5000);
	th7[3]=new TH1D("pileupEff","pileupEff",15,0.5,15.5);
	double totalPileup[3]={0},passPileup[3]={0};
	standalone_LumiReWeighting LumiWeights_central(0),LumiWeights_up(1),LumiWeights_down(-1);
	//PDF uncertainty
	th7[4]=new TH1D("PDFEff","PDFEff",101,0.5,101.5);
	double passPDF[101]={0},totalPDF[101]={0};
	//QCD uncertainty
	for(int i=5;i<14;i++)th7[i]=new TH1D(Form("uns_QCD_%d",i-5),Form("uns_QCD_%d",i-5),200,1000,5000);
	
	//NCUtuple loop----------------------------------------------------------------------------------------
	for (int w=wMs;w<wM;w++){
		if(w%20==0)cout<<w<<endl;
		//Get ntuple----------------------------------------------------------------------------------------
		if (nameRoot!=1)f = TFile::Open(Form("%s%d.root",st.data(),w));
		else f = TFile::Open(st.data());
		if (!f || !f->IsOpen())continue;
		TDirectory * dir;
		if (nameRoot!=1)dir = (TDirectory*)f->Get(Form("%s%d.root:/tree",st.data(),w));
		else dir = (TDirectory*)f->Get(Form("%s:/tree",st.data()));
		dir->GetObject("treeMaker",tree);
		TreeReader data(tree);
		total+=data.GetEntriesFast();
		for(Long64_t jEntry=0; jEntry<data.GetEntriesFast() ;jEntry++){//event loop----------------------------------------------------------------------------------------
			data.GetEntry(jEntry);
			
			Int_t nVtx        = data.GetInt("nVtx");
			Float_t ntrue= data.GetFloat("pu_nTrueInt");
			//Float_t*  pdfscaleSysWeights= data.GetPtrFloat("pdfscaleSysWeights");
			
			double PU_weight[3]={1,1,1};
			
			if(nameRoot!=2){
				if(ntrue<51){
					PU_weight[0] = LumiWeights_central.weight(ntrue);
					PU_weight[1]= LumiWeights_up.weight(ntrue);
					PU_weight[2] = LumiWeights_down.weight(ntrue);
				}
				else {
					PU_weight[0] = LumiWeights_central.weight(50);
					PU_weight[1] = LumiWeights_up.weight(50);
					PU_weight[2]= LumiWeights_down.weight(50);
				}
			}
			
			for(int i=0;i<3;i++)totalPileup[i]+=PU_weight[i];
			
			for(int i=0;i<101;i++)totalPDF[i]+=PU_weight[0];
			//0. has a good vertex
			if(nVtx<1)continue;nPass[0]++;
			//1.trigger
			std::string* trigName = data.GetPtrString("hlt_trigName");
		 	vector<bool> &trigResult = *((vector<bool>*) data.GetPtr("hlt_trigResult"));
			bool passTrigger=false;
			for(int it=0; it< data.GetPtrStringSize(); it++){
				std::string thisTrig= trigName[it];
				bool results = trigResult[it];
				if( ((thisTrig.find("HLT_PFHT800")!= std::string::npos||
						thisTrig.find("HLT_PFHT650")!= std::string::npos||
						thisTrig.find("HLT_PFHT650_WideJetMJJ900DEtaJJ1p5_v")!= std::string::npos||
						thisTrig.find("HLT_PFHT650_WideJetMJJ950DEtaJJ1p5_v")!= std::string::npos||
						thisTrig.find("HLT_AK8PFJet360_TrimMass30_v")!= std::string::npos||
						thisTrig.find("HLT_AK8PFHT700_TrimR0p1PT0p03Mass50_v")!= std::string::npos
						) && results==1)){
					passTrigger=true;
					break;
				}
			}
			if(!passTrigger && nameRoot==2)continue;nPass[1]++;
			
			int nFATJet         = data.GetInt("FATnJet");
			TClonesArray* fatjetP4 = (TClonesArray*) data.GetPtrTObject("FATjetP4");
			float*  FATjetCorrUncUp = data.GetPtrFloat("FATjetCorrUncUp"); 
			float*  FATjetCorrUncDown = data.GetPtrFloat("FATjetCorrUncDown"); 
			vector<bool>    &FATjetPassIDTight = *((vector<bool>*) data.GetPtr("FATjetPassIDTight"));
			//2.nJets
			if(nFATJet<2)continue;nPass[2]++;
			TLorentzVector* thisJet ,* thatJet;
			if (JESOption==1){
				TLorentzVector test0= (*((TLorentzVector*)fatjetP4->At(0)))*(1+FATjetCorrUncUp[0] );
				TLorentzVector test1= (*((TLorentzVector*)fatjetP4->At(1)))*(1+FATjetCorrUncUp[1] );
				thisJet= &test0;
				thatJet= &test1;
			}
			else if (JESOption==2){
				TLorentzVector test0= (*((TLorentzVector*)fatjetP4->At(0)))*(1-FATjetCorrUncDown[0] );
				TLorentzVector test1= (*((TLorentzVector*)fatjetP4->At(1)))*(1-FATjetCorrUncDown[1] );
				thisJet= &test0;
				thatJet= &test1;
			}
			else{
				thisJet= (TLorentzVector*)fatjetP4->At(0);
				thatJet = (TLorentzVector*)fatjetP4->At(1);
			}
			//3. Pt 
			if(thisJet->Pt()<300||thatJet->Pt()<300)continue;
			nPass[3]++;
			//4tightId-----------------------------------------
			if(FATjetPassIDTight[0]==0||FATjetPassIDTight[1]==0)continue;
			Float_t*  FATjetCEmEF = data.GetPtrFloat("FATjetCEmEF");
			Float_t*  FATjetMuEF = data.GetPtrFloat("FATjetMuEF");
			if(FATjetMuEF[0]>0.8||FATjetMuEF[1]>0.8)continue;
			if(FATjetCEmEF[0]>0.9||FATjetCEmEF[1]>0.9)continue;
			nPass[4]++;
			//5. Eta-----------------------------------------
			if(fabs(thisJet->Eta())>2.4||fabs(thatJet->Eta())>2.4)continue;
			nPass[5]++;
			//6. DEta-----------------------------------------
			float dEta = fabs(thisJet->Eta()-thatJet->Eta());
			if(dEta>1.3)continue;
			nPass[6]++;
			//7. Mjj-----------------------------------------
			float mjj = (*thisJet+*thatJet).M();
			if(mjj<1000)continue;
			nPass[7]++;
			//8. fatjetPRmassL2L3Corr-----------------------------------------
			Float_t*  fatjetPRmassL2L3Corr = data.GetPtrFloat("FATjetPRmassL2L3Corr");
			Float_t*  FATjetPuppiSDmassL2L3Corr = data.GetPtrFloat("FATjetPuppiSDmassL2L3Corr");
			Float_t*  FATjetPRmass = data.GetPtrFloat("FATjetPRmass");
			Float_t*  FATjetPuppiSDmass = data.GetPtrFloat("FATjetPuppiSDmass");
			if(fatjetPRmassL2L3Corr[0]<105||fatjetPRmassL2L3Corr[0]>135)continue;
			if(fatjetPRmassL2L3Corr[1]<105||fatjetPRmassL2L3Corr[1]>135)continue;
			nPass[8]++;
			//9.-----------------------------------------
			Float_t*  fatjetTau1 = data.GetPtrFloat("FATjetTau1");
			Float_t*  fatjetTau2 = data.GetPtrFloat("FATjetTau2");
			Float_t*  FATjetPuppiTau1 = data.GetPtrFloat("FATjetPuppiTau1");
			Float_t*  FATjetPuppiTau2 = data.GetPtrFloat("FATjetPuppiTau2");
			double tau21[2];
			tau21[0]=(fatjetTau2[0]/fatjetTau1[0]),tau21[1]=(fatjetTau2[1]/fatjetTau1[1]);
			double puppiTau21[2];
			puppiTau21[0]=(FATjetPuppiTau2[0]/FATjetPuppiTau1[0]),puppiTau21[1]=(FATjetPuppiTau2[1]/FATjetPuppiTau1[1]);
			if(tau21[0]>0.75||tau21[1]>0.75)continue;
			if(tau21[0]>0.6 &&tau21[1]>0.6) continue;
			nPass[9]++;
			bool isHPHP=0;
			double tau21_SF=1.031*0.881;
			if(JESOption==5)tau21_SF=(1.031+0.126)*(0.881+0.49);
			if(JESOption==6)tau21_SF=(1.031-0.126)*(0.881-0.49);
			if(tau21[0]<0.6 && tau21[1]<0.6 ){
				isHPHP=1;
				tau21_SF=1.031*1.031;
				if(JESOption==5)tau21_SF=(1.031+0.126)*(1.031+0.126);
				if(JESOption==6)tau21_SF=(1.031-0.126)*(1.031-0.126);
			}
			
			
			
			//8.btag
			vector<float>   *subjetSDCSV =  data.GetPtrVectorFloat("FATsubjetSDCSV");
			vector<float>   *subjetSDPx  =  data.GetPtrVectorFloat("FATsubjetSDPx", nFATJet);
			vector<float>   *subjetSDPy  =  data.GetPtrVectorFloat("FATsubjetSDPy", nFATJet);
			vector<float>   *subjetSDPz  =  data.GetPtrVectorFloat("FATsubjetSDPz", nFATJet);
			vector<float>   *subjetSDE   =  data.GetPtrVectorFloat("FATsubjetSDE", nFATJet);
			vector<Int_t>   *FATsubjetSDHadronFlavor =  data.GetPtrVectorInt("FATsubjetSDHadronFlavor");
			int nbtag=0,nbtag2=0;
			float MaxBJetPt = 670., MaxLJetPt = 1000.;
			double sf[2][2],eta[2],pt[2],dr[2],subjetPt[2][2],subjetEta[2][2],eff[2][2],btaggingscaleFactor=1;
			TLorentzVector* subjetP4[2][2];
			for(int i=0;i<2;i++)for(int j=0;j<2;j++)sf[i][j]=1;
			for(int i=0;i<2;i++){
				for(int j=0;j<2;j++){
					subjetP4[i][j]=new TLorentzVector(0,0,0,0);
					subjetP4[i][j]->SetPxPyPzE(subjetSDPx[i][j],subjetSDPy[i][j],subjetSDPz[i][j],subjetSDE[i][j]);
					subjetPt[i][j]=subjetP4[i][j]->Pt();
					subjetEta[i][j]=subjetP4[i][j]->Eta();
					//get btagging eff------------------------------------------------------------
					if(FATsubjetSDHadronFlavor[i][j]==5)eff[i][j]=th1[1]->GetBinContent(ceil(subjetPt[i][j]/10),ceil(subjetEta[i][j]/0.1)+30);
					else if(FATsubjetSDHadronFlavor[i][j]==4)eff[i][j]=th1[3]->GetBinContent(ceil(subjetPt[i][j]/10),ceil(subjetEta[i][j]/0.1)+30);
					else eff[i][j]=th1[5]->GetBinContent(ceil(subjetPt[i][j]/10),ceil(subjetEta[i][j]/0.1)+30);
					//check maxPt-------------------------------------------------------------
					if(FATsubjetSDHadronFlavor[i][j]!=0 && subjetPt[i][j]>MaxBJetPt )subjetPt[i][j]=MaxBJetPt-0.1;
					if(FATsubjetSDHadronFlavor[i][j]==0 && subjetPt[i][j]>MaxLJetPt )subjetPt[i][j]=MaxLJetPt-0.1;
					//Get SF from csv------------------------------------------------------------
					if(FATsubjetSDHadronFlavor[i][j]==5){
						sf[i][j]=HF.eval(BTagEntry::FLAV_B,subjetEta[i][j],subjetPt[i][j]); 
						th3[3]->Fill(subjetPt[i][j],sf[i][j]);
					}
					else if(FATsubjetSDHadronFlavor[i][j]==4){
						sf[i][j]=HF.eval(BTagEntry::FLAV_C,subjetEta[i][j],subjetPt[i][j]); 
						th3[4]->Fill(subjetPt[i][j],sf[i][j]);
					}
					else {
						sf[i][j]=LF.eval(BTagEntry::FLAV_UDSG,subjetEta[i][j],subjetPt[i][j]); 
						th3[5]->Fill(subjetPt[i][j],sf[i][j]);
					}
					//check zero ------------------------------------------------------------
					if(sf[i][j]==0 && FATsubjetSDHadronFlavor[i][j]==5 ) th3[0]->Fill(subjetPt[i][j],subjetEta[i][j]);
					if(sf[i][j]==0 && FATsubjetSDHadronFlavor[i][j]==4 ) th3[1]->Fill(subjetPt[i][j],subjetEta[i][j]);
					if(sf[i][j]==0 && FATsubjetSDHadronFlavor[i][j]!=5 && FATsubjetSDHadronFlavor[i][j]!=4 ) th3[2]->Fill(subjetPt[i][j],subjetEta[i][j]);
					//conut nbtag---------------------------------------------------------
					if(subjetSDCSV[i][j]>0.46)nbtag++;
					//get tot. btagging SF
					if(subjetSDCSV[i][j]>=0.46)btaggingscaleFactor*=sf[i][j];
					else btaggingscaleFactor*=((1-eff[i][j]*sf[i][j])/(1-eff[i][j]));
					//##############check light jet SF##########
					if(subjetSDCSV[i][j]>0.46 &&FATsubjetSDHadronFlavor[i][j]==0)nbtag2++;
					if(subjetSDCSV[i][j]>0.46)th4[i*2+j]->Fill(sf[i][j]);
					else th4[i*2+j+4]->Fill(sf[i][j]);
					subjetPt[i][j]=subjetP4[i][j]->Pt();
				}
				dr[i]=subjetP4[i][0]->DeltaR(*subjetP4[i][1]);
			}
			th4[8]->Fill(btaggingscaleFactor);
			if(nbtag2==2 && nbtag==2)th4[12]->Fill(btaggingscaleFactor);
			if(nbtag2==1 && nbtag==2)th4[13]->Fill(btaggingscaleFactor);
			
			//uncertainty -------------------------------------
			double scaleFactor=btaggingscaleFactor*PU_weight[0]*tau21_SF;
			for(int i=0;i<3;i++){
				passPileup[i]+=btaggingscaleFactor*PU_weight[i]*tau21_SF;
				th7[i]->Fill(mjj,btaggingscaleFactor*PU_weight[i]*tau21_SF);
			}
			 for(int i=0;i<101;i++)passPDF[i]+=btaggingscaleFactor*PU_weight[0]*tau21_SF;
			 for(int i=5;i<14;i++)th7[i]->Fill(mjj,btaggingscaleFactor*PU_weight[0]*tau21_SF);
			//--------------------------------------
			pt[0]=thisJet->Pt();
			pt[1]=thatJet->Pt();
			eta[0]=thisJet->Eta();
			eta[1]=thatJet->Eta();
			for(int i=0;i<2;i++){
				for(int j=0;j<2;j++){
					for(int k=0;k<5;k++){
						if(nbtag!=k)continue;
						th5[(i*2+j)*5+k]->Fill(subjetPt[i][j]);
						th5[(i*2+j)*5+k+20]->Fill(subjetEta[i][j]);
						th5[(i*2+j)*5+k+85]->Fill(subjetSDCSV[i][j]);
						th6[(i*2+j)*5+k]->Fill(subjetPt[i][j],scaleFactor);
						th6[(i*2+j)*5+k+20]->Fill(subjetEta[i][j],scaleFactor);
						th6[(i*2+j)*5+k]->Fill(subjetSDCSV[i][j],scaleFactor);
					}
				}
				for(int k=0;k<5;k++){
					if(nbtag!=k)continue;
					th5[i*5+k+40]->Fill(dr[i]);
					th5[i*5+k+50]->Fill(pt[i]);
					th5[i*5+k+60]->Fill(eta[i]);
					th5[i*5+k+70]->Fill(fatjetPRmassL2L3Corr[i]);
					th5[i*5+k+105]->Fill(tau21[i]);
					th6[i*5+k+40]->Fill(dr[i],scaleFactor);
					th6[i*5+k+50]->Fill(pt[i],scaleFactor);
					th6[i*5+k+60]->Fill(eta[i],scaleFactor);
					th6[i*5+k+70]->Fill(fatjetPRmassL2L3Corr[i],scaleFactor);
					th6[i*5+k+105]->Fill(tau21[i],scaleFactor);
					th5[i*5+k+120]->Fill(FATjetPuppiSDmassL2L3Corr[i]);
					th6[i*5+k+120]->Fill(FATjetPuppiSDmassL2L3Corr[i],scaleFactor);
					th5[i*5+k+130]->Fill(puppiTau21[i]);
					th6[i*5+k+130]->Fill(puppiTau21[i],scaleFactor);
					th5[i*5+k+140]->Fill(FATjetPRmass[i]);
					th6[i*5+k+140]->Fill(FATjetPRmass[i],scaleFactor);
					th5[i*5+k+150]->Fill(FATjetPuppiSDmass[i]);
					th6[i*5+k+150]->Fill(FATjetPuppiSDmass[i],scaleFactor);
				}
			}
			for(int k=0;k<5;k++){
				if(nbtag!=k)continue;
				th5[k+80]->Fill(mjj);
				th6[k+80]->Fill(mjj,scaleFactor);
				th5[k+115]->Fill(dEta);
				th6[k+115]->Fill(dEta,scaleFactor);
				th5[k+160]->Fill(log10(pt[0]));
				th6[k+160]->Fill(log10(pt[0]),scaleFactor);
				th5[k+160]->Fill(log10(pt[1]));
				th6[k+160]->Fill(log10(pt[1]),scaleFactor);
				nPassB[k]+=scaleFactor;
				nPass[k+10]++;
				if(k<3)th4[9+k]->Fill(btaggingscaleFactor);
			}
			if(nbtag==3){
				if(isHPHP)nPassB[5]+=scaleFactor;
				if(isHPHP)nPass[15]++;
			}

		}//end event loop----------------------------------------------------------------------------------------
	}	//end ntuple loop----------------------------------------------------------------------------------------
	cout<<"entries="<<total<<endl;	
	for(int i=0;i<6;i++)cout<<"nPassB["<<i<<"]="<<nPassB[i]<<endl;
	for(int i=0;i<16;i++)cout<<"nPass["<<i<<"]="<<nPass[i]<<endl;
	
	for(int i=0;i<3;i++)th7[3]->SetBinContent(i+1,passPileup[i]/totalPileup[i]);
	for(int i=0;i<101;i++)th7[4]->SetBinContent(i+1,passPDF[i]/totalPDF[i]);
	
	TH1D * th2o=new TH1D("Nbtagjet","Nbtagjet",6,-0.5,5.5);
	for (int i=0;i<6;i++){
		if(nameRoot==2 && i>2)continue;
		th2o->SetBinContent(i+1,nPass[i+10]);
	}
	TH1D * th2ob=new TH1D("NbtagjetB","NbtagjetB",6,-0.5,5.5);
	for (int i=0;i<6;i++){
		if(nameRoot==2 && i>2)continue;
		th2ob->SetBinContent(i+1,nPassB[i]);
	}
	TH1D * cutflow=new TH1D("cutflow","cutflow",17,0.5,17.5);
	cutflow->SetBinContent(1,total);
	if(nameRoot==2)for(int ii=1;ii<14;ii++)cutflow->SetBinContent(ii+1,nPass[ii-1]);
	else for(int ii=1;ii<17;ii++)cutflow->SetBinContent(ii+1,nPass[ii-1]);
	
	TFile* outFile ;
	if(JESOption==0)outFile= new TFile(Form("../sf/%s.root",st2.data()),"recreate");
	else if(JESOption==1)outFile= new TFile(Form("sf/%s_JESUp.root",st2.data()),"recreate");
	else if(JESOption==2)outFile= new TFile(Form("sf/%s_JESDown.root",st2.data()),"recreate");
	else if(JESOption==3)outFile= new TFile(Form("sf/%s_BtagUp.root",st2.data()),"recreate");
	else if(JESOption==4)outFile= new TFile(Form("sf/%s_BtagDown.root",st2.data()),"recreate");
	else if(JESOption==5)outFile= new TFile(Form("sf/%s_tau21Up.root",st2.data()),"recreate");
	else if(JESOption==6)outFile= new TFile(Form("sf/%s_tau21Down.root",st2.data()),"recreate");
	th2o->Write();
	th2ob->Write();
	cutflow->Write();
	for(int i=0;i<6;i++)th3[i]->Write();
	for(int i=0;i<14;i++)th4[i]->Write();
	for(int i=0;i<165;i++){
		th5[i]->Write();
		th6[i]->Write();
	}
	for(int i=0;i<14;i++)th7[i]->Write();
	outFile->Close();
}
Ejemplo n.º 9
0
void TMVAReaderPracticeDT0818() {
	
  bool isTT=0;
    
	string  masspoint[13]={"600","800","1000","1200","1400","1600","1800","2000","2500","3000","3500","4000","4500"};

	//for (int massP=0;massP<13;massP++){
	 for (int massP=0;massP<1;massP++){
		
		//Sig
	   //  TString endfix =Form("treeV4DT/signal-%s.root",masspoint[massP].data());for(int w=1;w<2;w++){f = TFile::Open(Form("/data2/syu/13TeV/ZprimeZhbb/ZprimeToZhToZlephbb_narrow_M-%s_13TeV-madgraph.root",masspoint[massP].data()));if (!f || !f->IsOpen())continue;TDirectory * dir = (TDirectory*)f->Get(Form("/data2/syu/13TeV/ZprimeZhbb/ZprimeToZhToZlephbb_narrow_M-%s_13TeV-madgraph.root:/tree",masspoint[massP].data()));dir->GetObject("treeMaker",tree);


	  //DY100-200
  
	   //for(int w=1;w<90;w++){ f = TFile::Open(Form("/data7/khurana/NCUGlobalTuples/SPRING15/DYJetsHTBins25nsSamples/DYJetsToLL_M-50_HT-100to200_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/crab_DYJetsToLL_M-50_HT-100to200_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_0803/150812_162742/0000/NCUGlobalTuples_%d.root",w));if (!f || !f->IsOpen())continue;TDirectory * dir = (TDirectory*)f->Get(Form("/data7/khurana/NCUGlobalTuples/SPRING15/DYJetsHTBins25nsSamples/DYJetsToLL_M-50_HT-100to200_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/crab_DYJetsToLL_M-50_HT-100to200_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_0803/150812_162742/0000/NCUGlobalTuples_%d.root:/tree",w));   dir->GetObject("treeMaker",tree);TString endfix =Form("treeV4DT/DYHT100-%d.root",w);

    //DY200-400
 
	 
	   //  for(int w=1;w<45;w++){f = TFile::Open(Form("/data7/khurana/NCUGlobalTuples/SPRING15/DYJetsHTBins25nsSamples/DYJetsToLL_M-50_HT-200to400_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/crab_DYJetsToLL_M-50_HT-200to400_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_0803/150812_162821/0000/NCUGlobalTuples_%d.root",w));if (!f || !f->IsOpen())continue;TDirectory * dir = (TDirectory*)f->Get(Form("/data7/khurana/NCUGlobalTuples/SPRING15/DYJetsHTBins25nsSamples/DYJetsToLL_M-50_HT-200to400_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/crab_DYJetsToLL_M-50_HT-200to400_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_0803/150812_162821/0000/NCUGlobalTuples_%d.root:/tree",w));   dir->GetObject("treeMaker",tree);TString endfix =Form("treeV4DT/DYHT200-%d.root",w);


    //DY400-600

	   //  for(int w=1;w<45;w++){f = TFile::Open(Form("/data7/khurana/NCUGlobalTuples/SPRING15/DYJetsHTBins25nsSamples/DYJetsToLL_M-50_HT-400to600_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/crab_DYJetsToLL_M-50_HT-400to600_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_0803/150812_162858/0000/NCUGlobalTuples_%d.root",w));if (!f || !f->IsOpen())continue;TDirectory * dir = (TDirectory*)f->Get(Form("/data7/khurana/NCUGlobalTuples/SPRING15/DYJetsHTBins25nsSamples/DYJetsToLL_M-50_HT-400to600_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/crab_DYJetsToLL_M-50_HT-400to600_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_0803/150812_162858/0000/NCUGlobalTuples_%d.root:/tree",w));   dir->GetObject("treeMaker",tree);TString endfix =Form("treeV4DT/DYHT400-%d.root",w);


    //DY600-inf
   
	   //  for(int w=1;w<48;w++){f = TFile::Open(Form("/data7/khurana/NCUGlobalTuples/SPRING15/DYJetsHTBins25nsSamples/DYJetsToLL_M-50_HT-600toInf_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/crab_DYJetsToLL_M-50_HT-600toInf_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_0803/150812_162937/0000/NCUGlobalTuples_%d.root",w));if (!f || !f->IsOpen())continue;TDirectory * dir = (TDirectory*)f->Get(Form("/data7/khurana/NCUGlobalTuples/SPRING15/DYJetsHTBins25nsSamples/DYJetsToLL_M-50_HT-600toInf_TuneCUETP8M1_13TeV-madgraphMLM-pythia8/crab_DYJetsToLL_M-50_HT-600toInf_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_0803/150812_162937/0000/NCUGlobalTuples_%d.root:/tree",w));   dir->GetObject("treeMaker",tree);TString endfix =Form("treeV4DT/DYHT600-%d.root",w);


//tt
	     isTT=1; for (int w=1;w<174;w++){f = TFile::Open(Form("/data7/khurana/NCUGlobalTuples/SPRING15/crab_TT_TuneCUETP8M1_13TeV-powheg-pythia8_0803/150803_175618/0000/NCUGlobalTuples_%d.root",w));  if (!f || !f->IsOpen())continue;TDirectory * dir = (TDirectory*)f->Get(Form("/data7/khurana/NCUGlobalTuples/SPRING15/crab_TT_TuneCUETP8M1_13TeV-powheg-pythia8_0803/150803_175618/0000/NCUGlobalTuples_%d.root:/tree",w));    dir->GetObject("treeMaker",tree);TString endfix =Form("treeV4DT/TT-%d.root",w);


      // TFile *fw;
      // TTree* treeP;
      // if(w==1){fw = new TFile("tree/DY.root","recreate");
      // 	 treeP=new TTree("treeP","treeP");
      // 	}
      // else {fw = new TFile("tree/DY.root","update");
      // 	treeP =(TTree*)fw->FindObjectAny("treeP");}
		   
       TFile *fw=new TFile(endfix.Data(),"recreate");
       
      float fatPt;
      float fatCSV;
      float sub1Pt;
      
      float sub1CSV;
      float sub2Pt;
     
      float sub2CSV;
      float delta_R;
      float tau21;
      float tau1;
      float tau2;
      
      cout<<massP<<","<<w<<endl;
      TreeReader data(tree);
      //data.Print();
      Long64_t nentries = data.GetEntriesFast();

      TMVA::Reader *reader = new TMVA::Reader( "!Color:!Silent" );
      reader->AddVariable( "fatPt", &fatPt );
      reader->AddVariable( "fatCSV", &fatCSV );
      reader->AddVariable( "sub1Pt", &sub1Pt );
      reader->AddVariable( "sub1CSV", &sub1CSV );
      reader->AddVariable( "sub2Pt", &sub2Pt );
      reader->AddVariable( "sub2CSV", &sub2CSV );
      reader->AddVariable( "delta_R", &delta_R );
      reader->AddVariable( "tau21", &tau21 );
      reader->AddVariable( "tau1", &tau1 );
      reader->AddVariable( "tau2", &tau2 );

      reader->BookMVA("BDT method","weights/DT.xml"); 
      TH1F *th1 =new TH1F("BDT","BDT",100,-0.8,0.8);
		  
		  for (Long64_t jentry=0; jentry<nentries;jentry++) {
		    data.GetEntry(jentry);
		    Int_t FATnJet=data.GetInt("FATnJet");
		    if(FATnJet==0)continue;

		    TClonesArray* eleP4 = (TClonesArray*) data.GetPtrTObject("eleP4");
		    TClonesArray* muP4 = (TClonesArray*) data.GetPtrTObject("muP4");
		    vector<bool> eleIsPassVeto=  *((vector<bool>*) data.GetPtr("eleIsPassVeto"));
		    vector<bool> isLooseMuon=  *((vector<bool>*) data.GetPtr("isLooseMuon"));
		    Int_t nMu=data.GetInt("nMu");
		    Int_t nEle=data.GetInt("nEle");
		    vector<int> mus,eles;
		    for(int i=0;i<nEle;i++){
		      TLorentzVector* thisEle =(TLorentzVector*)eleP4->At(i) ;
		      if(thisEle->Pt()<10 ||fabs(thisEle->Eta())>2.5 || eleIsPassVeto[i]==0 )continue;
		      eles.push_back(i);
		    }
		    
		     for(int i=0;i<nMu;i++){
		       TLorentzVector* thisMu =(TLorentzVector*)muP4->At(i) ;
		       if(thisMu->Pt()<10 ||fabs(thisMu->Eta())>2.4 || isLooseMuon[i]==0 )continue;
		       mus.push_back(i);
		     }
		      
		    
		    TClonesArray* FATjetP4 = (TClonesArray*) data.GetPtrTObject("FATjetP4");
		    Float_t*  FATjetSDmass = data.GetPtrFloat("FATjetSDmass");
		    Float_t*  FATjetCISVV2 = data.GetPtrFloat("FATjetCISVV2");


		    //if(>1 )continue;    
		    
		    int FATi=0;
		    bool isFAT=0;
		    TLorentzVector* FATjetP4_1;
		    //cout<<FATnJet<<endl;
		    for (FATi=0;FATi<FATnJet;FATi++){
		      //cout<<"FATi="<<FATi<<endl;
		      if(FATjetCISVV2[FATi]<0 ||FATjetCISVV2[FATi]>1 )continue;
		      FATjetP4_1 = (TLorentzVector*)FATjetP4->At(FATi);
		      bool isOverlap=0;
		      for(int i=0;i<mus.size();i++){
			TLorentzVector* thisMu =(TLorentzVector*)muP4->At(mus[i]) ;
			if(FATjetP4_1->DeltaR(*thisMu)<0.8){
			  isOverlap=1;
			  break;
			}
		      }
		      if(!isOverlap){
			for(int i=0;i<eles.size();i++){
			  TLorentzVector* thisEle =(TLorentzVector*)eleP4->At(eles[i]) ;
			  if(FATjetP4_1->DeltaR(*thisEle)<0.8){
			    isOverlap=1;
			    break;
			  }
			}
			
		      }
		      if(isOverlap)continue;
		      
		      isFAT=1;
		    break;
		    }
		    if(!isFAT)continue;
		    
		    if(FATjetP4_1->Pt()<200)continue;
		    
		    Int_t* FATnSubSDJet=data.GetPtrInt("FATnSubSDJet");
		    
		    if(FATnSubSDJet[FATi]<2)continue;
		    
		    int nsub=FATnSubSDJet[FATi];
		    if(nsub!=2)cout<<"nsub="<<nsub<<endl;if(nsub!=2)cout<<"nsub="<<nsub<<endl;
		    //
		    
		    float* FATjetTau1=data.GetPtrFloat("FATjetTau1");
		    float* FATjetTau2=data.GetPtrFloat("FATjetTau2");
		    vector<float>   *FATsubjetSDCSV =  data.GetPtrVectorFloat("FATsubjetSDCSV");
		    vector<float>   *FATsubjetSDPx =  data.GetPtrVectorFloat("FATsubjetSDPx");
		    vector<float>   *FATsubjetSDPy =  data.GetPtrVectorFloat("FATsubjetSDPy");
		    vector<float>   *FATsubjetSDPz =  data.GetPtrVectorFloat("FATsubjetSDPz");
		    vector<float>   *FATsubjetSDCE =  data.GetPtrVectorFloat("FATsubjetSDCE");
		    
		 	

		    int subi=0,subj=0;
		    bool isSubi=0,isSubj=0;
		    
	         
		    for(int subij=0;subij<FATnSubSDJet[FATi];subij++){
		      if(FATsubjetSDCSV[FATi][subij]>1 ||FATsubjetSDCSV[FATi][subij]<0 )continue;
		      if(!isSubi && !isSubj){
			subi=subij;isSubi=1;continue;
		      }
		      if(isSubi && !isSubj){
			subj=subij;isSubj=1;break;
		      }
		    }
		    //
		    if (!isSubi || !isSubj)continue;
		    
		    TLorentzVector  FATsubjet_1,FATsubjet_2;
		    
		    
		    FATsubjet_1.SetPxPyPzE(FATsubjetSDPx[FATi][subi],FATsubjetSDPy[FATi][subi],FATsubjetSDPz[FATi][subi],FATsubjetSDCE[FATi][subi]);
	            FATsubjet_2.SetPxPyPzE(FATsubjetSDPx[FATi][subj],FATsubjetSDPy[FATi][subj],FATsubjetSDPz[FATi][subj],FATsubjetSDCE[FATi][subj]);
	           
		    
		    fatPt=FATjetP4_1->Pt();//BfatPt->Fill();
		    fatCSV=FATjetCISVV2[FATi];//BfatCSV->Fill();
		    sub1Pt=FATsubjet_1.Pt();//Bsub1Pt->Fill();
		    //sub1Eta=FATsubjet_1.Eta();//Bsub1Eta->Fill();
		    sub1CSV=FATsubjetSDCSV[FATi][subi];//Bsub1CSV->Fill();
		    sub2Pt=FATsubjet_2.Pt();//Bsub2Pt->Fill();
		    //sub2Eta=FATsubjet_2.Eta();//Bsub2Eta->Fill();
		    sub2CSV=FATsubjetSDCSV[FATi][subj];//Bsub2CSV->Fill();
		    delta_R=FATsubjet_1.DeltaR(FATsubjet_2);//BdeltaR->Fill();
		    tau21=FATjetTau2[FATi]/FATjetTau1[FATi];
		    tau1=FATjetTau1[FATi];
		    tau2=FATjetTau2[FATi];
		    
		    
		    th1 ->Fill( reader->EvaluateMVA("BDT method"));
		   
		  }
		  th1->Write();
		  
		  fw->Close();
		  
		}	
		
		
    }	    
    
}
Ejemplo n.º 10
0
void HHbbbbAnalyzerBase(int wM, string st,string st2,double Xsec=1,int SignalBkgNum=0){
	
	//for (int massP=0;massP<1;massP++){
		
		
		
	    
		
		int nPass[10]={0};
		int total=0;
		TH1D* th[30];
		
			th[0]=new TH1D("deltaEta","deltaEta",30,0,3);
			th[1]=new TH1D("Mjj","Mjj",2000,400,4000);
			th[2]=new TH1D("SDMass1","SDMass1",200,0,200);
			th[3]=new TH1D("SDMass2","SDMass2",200,0,200);
			th[4]=new TH1D("PRMass1","PRMass1",200,0,200);
			th[5]=new TH1D("PRMass2","PRMass2",200,0,200);
			th[6]=new TH1D("deltaR1","deltaR1",20,0,1);
			th[7]=new TH1D("deltaR2","deltaR2",20,0,1);
			th[8]=new TH1D("CSV1","CSV1",20,0,1);
			th[9]=new TH1D("CSV2","CSV2",20,0,1);
			th[10]=new TH1D("CSVSum","CSVSum",20,0,2);
			th[11]=new TH1D("CSVMax","CSVMax",20,0,1);
			th[12]=new TH1D("CSVMin","CSVMin",20,0,1);
			th[13]=new TH1D("tau21_1","tau21_1",20,0,1);
			th[14]=new TH1D("tau21_2","tau21_2",20,0,1);
			th[15]=new TH1D("jetPt1","jetPt1",1500,0,1500);
			th[16]=new TH1D("jetPt2","jetPt2",1500,0,1500);
			th[17]=new TH1D("PRMassC1","PRMassC1",600,0,600);
			th[18]=new TH1D("PRMassC2","PRMassC2",600,0,600);
			
			th[19]=new TH1D("FATjetPRmassL2L3Corr","FATjetPRmassL2L3Corr",600,0,600);
			th[20]=new TH1D("FATjetPRmassL2L3Corr_2","FATjetPRmassL2L3Corr_2",600,0,600);
			th[21]=new TH1D("FATjetPRmassL2L3CorrC","FATjetPRmassL2L3CorrC",600,0,600);
			th[22]=new TH1D("FATjetPRmassL2L3CorrC_2","FATjetPRmassL2L3CorrC_2",600,0,600);
			
			th[23]=new TH1D("MjjC","MjjC",2000,400,4000);
			th[24]=new TH1D("Mbb1","Mbb1",600,0,600);
			th[25]=new TH1D("Mbb2","Mbb2",600,0,600);
			th[26]=new TH1D("MbbC1","MbbC1",600,0,600);
			th[27]=new TH1D("MbbC2","MbbC2",600,0,600);
			
			TH1D* cs1=new TH1D("case1","case1",2000,400,6000);
			TH1D* cs2=new TH1D("case2","case2",2000,400,6000);
			TH1D* cs3=new TH1D("case3","case3",2000,400,6000);
			TH1D* cs4=new TH1D("case4","case4",2000,400,6000);
			TH1D* cs5=new TH1D("case5","case5",2000,400,6000);
			TH1D* csS=new TH1D("caseS","caseS",2000,400,6000);
		
			TH2F* th2f=new TH2F("2d","2d",600,0,600,600,0,600);
		for (int w=1;w<wM;w++){
			//cout<<Form("%s%d.root",st.data(),w)<<endl;
		//if(SignalBkgNum==1)f = TFile::Open(Form("%s",st.data()));
		//else 
			TFile *f;
			f = TFile::Open(Form("%s%d.root",st.data(),w));
		if (!f || !f->IsOpen())continue;
		TDirectory * dir;
		//if(SignalBkgNum==1)dir = (TDirectory*)f->Get(Form("%s:/tree",st.data()));
		//else 
			dir = (TDirectory*)f->Get(Form("%s%d.root:/tree",st.data(),w));
		
		cout<<w<<endl;
		
		TTree *tree;
		dir->GetObject("treeMaker",tree);
		
		TreeReader data(tree);
		
		total+=data.GetEntriesFast();
		
		
		
			
			

		
		for(Long64_t jEntry=0; jEntry<data.GetEntriesFast() ;jEntry++){
			data.GetEntry(jEntry);
			
			Int_t nJet         = data.GetInt("FATnJet");
			TClonesArray* FATjetP4 = (TClonesArray*) data.GetPtrTObject("FATjetP4");
			float*   FATjetPRmass= data.GetPtrFloat("FATjetPRmass");  
			float*   FATjetSDmass= data.GetPtrFloat("FATjetSDmass");
			float*  FATjetCISVV2 = data.GetPtrFloat("FATjetCISVV2"); 
			float* FATjetTau1=data.GetPtrFloat("FATjetTau1");
		    float* FATjetTau2=data.GetPtrFloat("FATjetTau2");
			Int_t* FATnSubSDJet=data.GetPtrInt("FATnSubSDJet");
			vector<float>   *FATsubjetSDCSV = data.GetPtrVectorFloat("FATsubjetSDCSV");
		    vector<float>   *FATsubjetSDPx =  data.GetPtrVectorFloat("FATsubjetSDPx");
		    vector<float>   *FATsubjetSDPy =  data.GetPtrVectorFloat("FATsubjetSDPy");
		    vector<float>   *FATsubjetSDPz =  data.GetPtrVectorFloat("FATsubjetSDPz");
			Float_t*  jetPRmassL2L3Corr = data.GetPtrFloat("FATjetPRmassL2L3Corr");
			
			string fixName ="";if(SignalBkgNum==1)fixName="";
			
		    vector<float>   *FATsubjetSDE =  data.GetPtrVectorFloat(Form("FATsubjetSD%sE",fixName.data()));
			
			if(nJet<1)continue;
			
			vector<int> FatjetPreSelection;
			for(int i=0;i<nJet;i++){
				TLorentzVector* thisHiggs = (TLorentzVector*)FATjetP4->At(i);
				if(thisHiggs->Pt()<200)continue;
				if(fabs(thisHiggs->Eta())>2.4)continue;
				FatjetPreSelection.push_back(i);
			}
			if(FatjetPreSelection.size()<2)continue;
			
			//TH1D* th1=new TH1D("","",,0,);
			
			TLorentzVector* thisHiggs = (TLorentzVector*)FATjetP4->At(FatjetPreSelection[0]);
			TLorentzVector* thatHiggs = (TLorentzVector*)FATjetP4->At(FatjetPreSelection[1]);
			TLorentzVector mjj=*thisHiggs+*thatHiggs;
			csS->Fill(mjj.M()+250-thisHiggs->M()-thatHiggs->M());
			th[24]->Fill(thisHiggs->M());
			th[25]->Fill(thatHiggs->M());
			
			th[0]->Fill(fabs(thisHiggs->Eta()-thatHiggs->Eta()));
			th[1]->Fill(mjj.M());
			th[2]->Fill(FATjetSDmass[FatjetPreSelection[0]]);
			th[3]->Fill(FATjetSDmass[FatjetPreSelection[1]]);
			th[4]->Fill(FATjetPRmass[FatjetPreSelection[0]]);
			th[5]->Fill(FATjetPRmass[FatjetPreSelection[1]]);
			
			TLorentzVector  FATsubjet_1,FATsubjet_2,FATsubjet_3,FATsubjet_4;;
			FATsubjet_1.SetPxPyPzE(FATsubjetSDPx[FatjetPreSelection[0]][0],FATsubjetSDPy[FatjetPreSelection[0]][0],FATsubjetSDPz[FatjetPreSelection[0]][0],FATsubjetSDE[FatjetPreSelection[0]][0]);
			FATsubjet_2.SetPxPyPzE(FATsubjetSDPx[FatjetPreSelection[0]][1],FATsubjetSDPy[FatjetPreSelection[0]][1],FATsubjetSDPz[FatjetPreSelection[0]][1],FATsubjetSDE[FatjetPreSelection[0]][1]);
			FATsubjet_3.SetPxPyPzE(FATsubjetSDPx[FatjetPreSelection[1]][0],FATsubjetSDPy[FatjetPreSelection[1]][0],FATsubjetSDPz[FatjetPreSelection[1]][0],FATsubjetSDE[FatjetPreSelection[1]][0]);
			FATsubjet_4.SetPxPyPzE(FATsubjetSDPx[FatjetPreSelection[1]][1],FATsubjetSDPy[FatjetPreSelection[1]][1],FATsubjetSDPz[FatjetPreSelection[1]][1],FATsubjetSDE[FatjetPreSelection[1]][1]);
				
				
			th[6]->Fill(FATsubjet_1.DeltaR(FATsubjet_2));
			th[7]->Fill(FATsubjet_3.DeltaR(FATsubjet_4));
			
			
			th[8]->Fill(FATjetCISVV2[FatjetPreSelection[0]]);
			th[9]->Fill(FATjetCISVV2[FatjetPreSelection[1]]);
			
			th[10]->Fill(FATjetCISVV2[FatjetPreSelection[0]]+FATjetCISVV2[FatjetPreSelection[1]]);
			double temp=FATjetCISVV2[FatjetPreSelection[0]]>FATjetCISVV2[FatjetPreSelection[1]]?FATjetCISVV2[FatjetPreSelection[0]]:FATjetCISVV2[FatjetPreSelection[1]];
			th[11]->Fill(temp);
			temp=FATjetCISVV2[FatjetPreSelection[0]]<FATjetCISVV2[FatjetPreSelection[1]]?FATjetCISVV2[FatjetPreSelection[0]]:FATjetCISVV2[FatjetPreSelection[1]];
			th[12]->Fill(temp);
			
			
			
			th[13]->Fill(FATjetTau2[FatjetPreSelection[0]]/FATjetTau1[FatjetPreSelection[0]]);
			th[14]->Fill(FATjetTau2[FatjetPreSelection[1]]/FATjetTau1[FatjetPreSelection[1]]);
			
			th[15]->Fill(thisHiggs->Pt());
			//cout<<thisHiggs->Pt()<<endl;
			th[16]->Fill(thatHiggs->Pt());
			

			vector<int> FatjetPreSelection1i,FatjetPreSelection1j;
			for(unsigned int i=0;i<FatjetPreSelection.size();i++){
				TLorentzVector* thisHiggs = (TLorentzVector*)FATjetP4->At(FatjetPreSelection[i]);
				for(unsigned int j=i+1;j<FatjetPreSelection.size();j++){
					TLorentzVector* thatHiggs = (TLorentzVector*)FATjetP4->At(FatjetPreSelection[j]);
				    if(fabs(thisHiggs->Eta()-thatHiggs->Eta())<1.3){
						FatjetPreSelection1i.push_back(FatjetPreSelection[i]);
						FatjetPreSelection1j.push_back(FatjetPreSelection[j]);
					}
				}
				//if(isDeltaEta13)break;
			}
			if(FatjetPreSelection1i.size()<1)continue;
	
			nPass[0]++;
			
			vector<int> FatjetPreSelection2i,FatjetPreSelection2j;
			for(unsigned int i=0;i<FatjetPreSelection1i.size();i++){
				TLorentzVector* thisHiggs = (TLorentzVector*)FATjetP4->At(FatjetPreSelection1i[i]);
				TLorentzVector* thatHiggs = (TLorentzVector*)FATjetP4->At(FatjetPreSelection1j[i]);
				TLorentzVector mjj=*thisHiggs+*thatHiggs;
				//cout<<mjj.M()<<endl;
				if(mjj.M()>1000){
					//cout<<"y"<<endl;
					FatjetPreSelection2i.push_back(FatjetPreSelection1i[i]);
				    FatjetPreSelection2j.push_back(FatjetPreSelection1j[i]);
					
				}
				
				
			}
			if(FatjetPreSelection2i.size()<1)continue;
			nPass[1]++;
			
			vector<int> FatjetPreSelection3i,FatjetPreSelection3j;
			for(unsigned int i=0;i<FatjetPreSelection2i.size();i++){
				
				th[19]->Fill(jetPRmassL2L3Corr[FatjetPreSelection2i[i]]);
				th[20]->Fill(jetPRmassL2L3Corr[FatjetPreSelection2j[i]]);
				th2f->Fill(jetPRmassL2L3Corr[FatjetPreSelection2i[i]],jetPRmassL2L3Corr[FatjetPreSelection2j[i]]);
				
				if(jetPRmassL2L3Corr[FatjetPreSelection2i[i]]>135||jetPRmassL2L3Corr[FatjetPreSelection2i[i]]<105)continue;
				if(jetPRmassL2L3Corr[FatjetPreSelection2j[i]]>135||jetPRmassL2L3Corr[FatjetPreSelection2j[i]]<105)continue;
				//if(FATjetPRmass[FatjetPreSelection2j[i]]>130||FATjetPRmass[FatjetPreSelection2j[i]]<95)continue;
				//if(FATjetPRmass[FatjetPreSelection2i[i]]>150||FATjetPRmass[FatjetPreSelection2i[i]]<90)continue;
				//if(FATjetPRmass[FatjetPreSelection2j[i]]>150||FATjetPRmass[FatjetPreSelection2j[i]]<90)continue;
				
				
				
				FatjetPreSelection3i.push_back(FatjetPreSelection2i[i]);
				FatjetPreSelection3j.push_back(FatjetPreSelection2j[i]);
			}
			if(FatjetPreSelection3i.size()<1)continue;
			nPass[2]++;
			
			vector<int> FatjetPreSelection4i,FatjetPreSelection4j;
			for(unsigned int i=0;i<FatjetPreSelection3i.size();i++){
				if(FATnSubSDJet[FatjetPreSelection3i[i]]<2||FATnSubSDJet[FatjetPreSelection3j[i]]<2)continue;
				TLorentzVector  FATsubjet_1,FATsubjet_2;
				bool thisHiggsBTagTight=0,thisHiggsBTagLoose=0;
				FATsubjet_1.SetPxPyPzE(FATsubjetSDPx[FatjetPreSelection3i[i]][0],FATsubjetSDPy[FatjetPreSelection3i[i]][0],FATsubjetSDPz[FatjetPreSelection3i[i]][0],FATsubjetSDE[FatjetPreSelection3i[i]][0]);
				FATsubjet_2.SetPxPyPzE(FATsubjetSDPx[FatjetPreSelection3i[i]][1],FATsubjetSDPy[FatjetPreSelection3i[i]][1],FATsubjetSDPz[FatjetPreSelection3i[i]][1],FATsubjetSDE[FatjetPreSelection3i[i]][1]);
				if(FATsubjet_1.DeltaR(FATsubjet_2)<0.3 && FATjetCISVV2[FatjetPreSelection3i[i]]<0.244)continue;
				if(FATsubjet_1.DeltaR(FATsubjet_2)>0.3 && (FATsubjetSDCSV[FatjetPreSelection3i[i]][0]>0.244 || FATsubjetSDCSV[FatjetPreSelection3i[i]][1]>0.244))thisHiggsBTagLoose=1;
				if(FATsubjet_1.DeltaR(FATsubjet_2)>0.3 && (FATsubjetSDCSV[FatjetPreSelection3i[i]][0]>0.244 && FATsubjetSDCSV[FatjetPreSelection3i[i]][1]>0.244))thisHiggsBTagTight=1;
				if(FATsubjet_1.DeltaR(FATsubjet_2)<0.3){
					thisHiggsBTagTight=1;
					thisHiggsBTagLoose=1;
				}
				FATsubjet_1.SetPxPyPzE(FATsubjetSDPx[FatjetPreSelection3j[i]][0],FATsubjetSDPy[FatjetPreSelection3j[i]][0],FATsubjetSDPz[FatjetPreSelection3j[i]][0],FATsubjetSDE[FatjetPreSelection3j[i]][0]);
				FATsubjet_2.SetPxPyPzE(FATsubjetSDPx[FatjetPreSelection3j[i]][1],FATsubjetSDPy[FatjetPreSelection3j[i]][1],FATsubjetSDPz[FatjetPreSelection3j[i]][1],FATsubjetSDE[FatjetPreSelection3j[i]][1]);
				TLorentzVector  FATsubjet_3,FATsubjet_4;
				bool thatHiggsBTagTight=0,thatHiggsBTagLoose=0;
				if(FATsubjet_3.DeltaR(FATsubjet_4)<0.3 && FATjetCISVV2[FatjetPreSelection3j[i]]<0.244)continue;
				if(FATsubjet_3.DeltaR(FATsubjet_4)>0.3 && (FATsubjetSDCSV[FatjetPreSelection3j[i]][0]>0.244 || FATsubjetSDCSV[FatjetPreSelection3j[i]][1]>0.244))thatHiggsBTagLoose=1;
				if(FATsubjet_3.DeltaR(FATsubjet_4)>0.3 && (FATsubjetSDCSV[FatjetPreSelection3j[i]][0]>0.244 && FATsubjetSDCSV[FatjetPreSelection3j[i]][1]>0.244))thatHiggsBTagTight=1;
				if(FATsubjet_3.DeltaR(FATsubjet_4)<0.3){
					thatHiggsBTagTight=1;
					thatHiggsBTagLoose=1;
				}
				//if(FATsubjet_3.DeltaR(FATsubjet_4)>0.3)cout<<"Y"<<endl;
				if(thisHiggsBTagLoose==0 || thatHiggsBTagLoose==0 ){
					//cout<<thisHiggsBTagLoose<<","<<thatHiggsBTagLoose<<endl;
					//if(FATsubjet_3.DeltaR(FATsubjet_4)>0.3)cout<<FATsubjetSDCSV[FatjetPreSelection3j[i]][0]<<","<<FATsubjetSDCSV[FatjetPreSelection3j[i]][1]<<endl;
					continue;
					
				}
				if(thisHiggsBTagTight==0 && thatHiggsBTagTight==0) continue;
				FatjetPreSelection4i.push_back(FatjetPreSelection3i[i]);
				FatjetPreSelection4j.push_back(FatjetPreSelection3j[i]);
				
				
			}
			//if(numHiggsBTagLoose<2||numHiggsBTagTight<1)continue;
            if(FatjetPreSelection4i.size()<1)continue;
			nPass[3]++;
			
			//int numHiggsHP=0,numHiggsLP=0;
			
			bool isPassingTau=0;
			for(unsigned int i=0;i<FatjetPreSelection4i.size();i++){
				bool thisHiggsHP=0,thisHiggsLP=0;
				if(FATjetTau2[FatjetPreSelection4i[i]]/FATjetTau1[FatjetPreSelection4i[i]]<0.5)thisHiggsHP=1;
				if(FATjetTau2[FatjetPreSelection4i[i]]/FATjetTau1[FatjetPreSelection4i[i]]<0.75 && FATjetTau2[FatjetPreSelection4i[i]]/FATjetTau1[FatjetPreSelection4i[i]]>0.5)thisHiggsLP=1;
				if(thisHiggsHP)thisHiggsLP=1;
				bool thatHiggsHP=0,thatHiggsLP=0;
			
				
				if(FATjetTau2[FatjetPreSelection4j[i]]/FATjetTau1[FatjetPreSelection4j[i]]<0.5)thatHiggsHP=1;
				if(FATjetTau2[FatjetPreSelection4j[i]]/FATjetTau1[FatjetPreSelection4j[i]]<0.75 && FATjetTau2[FatjetPreSelection4j[i]]/FATjetTau1[FatjetPreSelection4j[i]]>0.5)thatHiggsLP=1;
				if(thatHiggsHP)thatHiggsLP=1;
				
				if(thisHiggsLP==0 || thatHiggsLP==0 )continue;
				if(thisHiggsHP==0 && thatHiggsHP==0) continue;
				
				isPassingTau=1;
			}
			if(isPassingTau==0)continue;
			
  
			nPass[4]++;
			
			TLorentzVector* thisHiggsCs = (TLorentzVector*)FATjetP4->At(FatjetPreSelection4i[0]);
			TLorentzVector* thatHiggsCs = (TLorentzVector*)FATjetP4->At(FatjetPreSelection4j[0]);
			TLorentzVector mjjCs=*thisHiggsCs+*thatHiggsCs;
			cs1->Fill(mjjCs.M());
			
			
			thatHiggsCs ->SetPxPyPzE(thatHiggsCs->Px()*125/jetPRmassL2L3Corr[FatjetPreSelection4j[0]],thatHiggsCs->Py()*125/jetPRmassL2L3Corr[FatjetPreSelection4j[0]],thatHiggsCs->Pz()*125/jetPRmassL2L3Corr[FatjetPreSelection4j[0]],thatHiggsCs->E()*125/jetPRmassL2L3Corr[FatjetPreSelection4j[0]]);
			
			mjjCs=*thisHiggsCs+*thatHiggsCs;
			cs2->Fill(mjjCs.M());
			
			thisHiggsCs ->SetPxPyPzE(thisHiggsCs->Px()*125/jetPRmassL2L3Corr[FatjetPreSelection4i[0]],thisHiggsCs->Py()*125/jetPRmassL2L3Corr[FatjetPreSelection4i[0]],thisHiggsCs->Pz()*125/jetPRmassL2L3Corr[FatjetPreSelection4i[0]],thisHiggsCs->E()*125/jetPRmassL2L3Corr[FatjetPreSelection4i[0]]);
			
			mjjCs=*thisHiggsCs+*thatHiggsCs;
			cs3->Fill(mjjCs.M());
			
			thisHiggsCs = (TLorentzVector*)FATjetP4->At(FatjetPreSelection4i[0]);
			thatHiggsCs = (TLorentzVector*)FATjetP4->At(FatjetPreSelection4j[0]);
			double scaleThis = 125/thisHiggsCs->M();
			double scaleThat = 125/thatHiggsCs->M();
			
			thisHiggsCs ->SetPxPyPzE(thisHiggsCs->Px()*scaleThis,thisHiggsCs->Py()*scaleThis,thisHiggsCs->Pz()*scaleThis,thisHiggsCs->E()*scaleThis);
			thatHiggsCs ->SetPxPyPzE(thatHiggsCs->Px()*scaleThat,thatHiggsCs->Py()*scaleThat,thatHiggsCs->Pz()*scaleThat,thatHiggsCs->E()*scaleThat);
		
			mjjCs=*thisHiggsCs+*thatHiggsCs;
			cs4->Fill(mjjCs.M());
			
			thisHiggsCs = (TLorentzVector*)FATjetP4->At(FatjetPreSelection4i[0]);
			thatHiggsCs = (TLorentzVector*)FATjetP4->At(FatjetPreSelection4j[0]);
			mjjCs=*thisHiggsCs+*thatHiggsCs;
			
			cs5->Fill(mjjCs.M()+250-thisHiggsCs->M()-thatHiggsCs->M());
			
			th[21]->Fill(jetPRmassL2L3Corr[FatjetPreSelection4i[0]]);
			th[22]->Fill(jetPRmassL2L3Corr[FatjetPreSelection4j[0]]);
			
			th[17]->Fill(FATjetPRmass[FatjetPreSelection4i[0]]);
			th[18]->Fill(FATjetPRmass[FatjetPreSelection4j[0]]);
			
			th[26]->Fill(thisHiggsCs->M());
			th[27]->Fill(thatHiggsCs->M());
			th[23]->Fill(mjjCs.M());
		}
		
		
		
		
		}
		
		
	for(int i=0 ;i< 28;i++)th[i]->Scale(1000*Xsec/total);
	
	th2f->Scale(1000*Xsec/total);
	cs1->Scale(1000*Xsec/total);
	cs2->Scale(1000*Xsec/total);
	cs3->Scale(1000*Xsec/total);
	cs4->Scale(1000*Xsec/total);
	cs5->Scale(1000*Xsec/total);
	csS->Scale(1000*Xsec/total);
		
	TFile* outFile = new TFile(Form("root_files/%s.root",st2.data()),"recreate");   
	
	for(int i=0 ;i< 28;i++)th[i]->Write();
	
	cs1->Write();
	cs2->Write();
	cs3->Write();
	cs4->Write();
	cs5->Write();
	csS->Write();

	th2f->Write();
	//cout<<th2f->GetCorrelationFactor();
	outFile->Close();
	
	for(int i=0 ;i<28;i++)th[i]->Clear();
	
	cs1->Clear();
	cs2->Clear();
	cs3->Clear();
	cs4->Clear();
	cs5->Clear();
	csS->Clear();
	th2f->Clear();
	
	//dir->Close();
	//delete f;
}
Ejemplo n.º 11
0
int InputForLimits(){
  TH1::SetDefaultSumw2(true);
  if(pcp)cout<<"going to set inputs"<<endl;

  Int_t NBR = 3;
  Float_t BR[] = { 1., 0.75, 0.5};

  TFile* bkgFile = new TFile( "../../BkgPrediction/BkgPrediction.root", "READ"); 
  TTree* bkgTree;
  bkgFile->GetObject( "ElAndMu", bkgTree);
  
  Float_t bkg = 0.;
  Float_t bkgTotUnc = 0.;

  Float_t obs = 0.;

  bkgTree->SetBranchAddress( "srData", &obs);
  bkgTree->SetBranchAddress( "srAllBkgCorr", &bkg);
  bkgTree->SetBranchAddress( "TotUnc", &bkgTotUnc);

  TFile* sigFile = new TFile( "../../SignalSystematics/SignalSys.root", "READ"); 

  std::vector<std::vector<TString> > sysColl;
  std::vector<TString> sys;
  sys.push_back(TString("JES_Up"));
  sys.push_back(TString("JES_Down"));
  sysColl.push_back(sys);

  sys.clear();
  sys.push_back(TString("BTagReweight_UpBC"));
  sys.push_back(TString("BTagReweight_DownBC"));
  sysColl.push_back(sys);

  sys.clear();
  sys.push_back(TString("BTagReweight_UpLight"));
  sys.push_back(TString("BTagReweight_DownLight"));
  sysColl.push_back(sys);

  std::vector<TString> decayMode;
  decayMode.push_back(TString("tt"));
  decayMode.push_back(TString("tb"));
  decayMode.push_back(TString("bb"));
		      
  Systematics* systematics[3];
  TString dirname;
  TString histoname;

  TDirectory* srDir;
  TDirectory* histoDir;

  TFile* outFile = new TFile( "InputForLimits.root", "RECREATE");
  TDirectory* outBRDir;
  TDirectory* outSRDir;

  TH1F* datah = new TH1F( "data", "data", 1, 0., 1.);
  TH1F* bkgh = new TH1F( "bkg", "bkg", 1, 0., 1.);

  TH2F* sigh;
  TH2F* sig_toth;
  TH2F* effh;
  
  TH2F* sigLh;
  TH2F* effLh;

  TH2F* sigRh;
  TH2F* effRh;
  
  TH2F* jesh;
  TH2F* btagBCh;
  TH2F* btagLighth;
  TH2F* btagh;
  
  TH2F* sysh;

  TH2F* unch;

  TH2F* jesPercenth;
  TH2F* btagBCPercenth;
  TH2F* btagLightPercenth;
  TH2F* btagPercenth;
  
  TH2F* sysPercenth;

  TH2F* uncPercenth;

  Float_t sig = 0.;
  Float_t stat = 0.;

  Float_t jes = 0.;
  Float_t bc = 0.;
  Float_t light = 0.;
  
  Float_t unc = 0.;

  int N = bkgTree->GetEntries();

  for ( int ibr = 0; ibr < NBR; ibr++){
    dirname = ""; dirname += BR[ibr];
    outFile->mkdir(dirname);
    outBRDir = outFile->GetDirectory(dirname);

    for ( int iSR = 0; iSR < 9; iSR++){
      bkgTree->GetEntry(iSR);      
      datah->SetBinContent( 1, obs);
      bkgh->SetBinContent( 1, bkg);
      bkgh->SetBinError( 1, bkgTotUnc);

      dirname = ""; dirname += iSR;
      outBRDir->mkdir(dirname);
      outSRDir = outBRDir->GetDirectory(dirname);
      
      dirname = ""; dirname += iSR; dirname += ".root";      
      srDir = sigFile->GetDirectory( dirname);
      for ( int isys = 0; isys < (int) sysColl.size(); isys++){
	systematics[isys] = new Systematics();
	systematics[isys]->BR = BR[ibr];

	histoDir = srDir->GetDirectory( "NoSystematic");
	for ( int idecay = 0; idecay < (int) decayMode.size(); idecay++){
	  histoDir->GetObject( decayMode.at(idecay), systematics[isys]->h[idecay]);
	  histoDir->GetObject( decayMode.at(idecay) + "l", systematics[isys]->Lh);
	  histoDir->GetObject( decayMode.at(idecay) + "r", systematics[isys]->Rh);
	}
	histoDir->GetObject( decayMode.at(0) + "l", systematics[isys]->Lh);
	histoDir->GetObject( decayMode.at(0) + "r", systematics[isys]->Rh);
	histoDir->GetObject( "sig_tot", systematics[isys]->sig_toth);

	for ( int ishift = 0; ishift < 2; ishift++){
	  histoDir = srDir->GetDirectory(sysColl.at(isys).at(ishift));
	  for ( int idecay = 0; idecay < (int) decayMode.size(); idecay++){
	    histoDir->GetObject( decayMode.at(idecay), systematics[isys]->shifth[ishift][idecay]);
	  }
	}
	systematics[isys]->Calc();
      }
      sig_toth = new TH2F( *systematics[0]->sig_toth);
      sig_toth->SetName("sig_tot");
      sig_toth->SetTitle("sig_tot");    

      sigh = new TH2F( *systematics[0]->sigh);
      sigh->SetName("sig");
      sigh->SetTitle("sig");

      effh = new TH2F( *systematics[0]->effh);
      effh->SetName("eff");
      effh->SetTitle("eff");

      sigLh = new TH2F( *systematics[0]->sigRh);
      sigLh->SetName("sigL");
      sigLh->SetTitle("sigL");

      effLh = new TH2F( *systematics[0]->effLh);
      effLh->SetName("effL");
      effLh->SetTitle("effL");

      sigRh = new TH2F( *systematics[0]->sigRh);
      sigRh->SetName("sigR");
      sigRh->SetTitle("sigR");

      effRh = new TH2F( *systematics[0]->effRh);
      effRh->SetName("effR");
      effRh->SetTitle("effR");

      jesh = new TH2F( *systematics[0]->sysh);
      jesh->SetName("jes");
      jesh->SetTitle("jes");

      btagBCh = new TH2F( *systematics[1]->sysh);
      btagBCh->SetName("btagBC");
      btagBCh->SetTitle("btagBC");
      
      btagLighth = new TH2F( *systematics[2]->sysh);
      btagLighth->SetName("btagLight");
      btagLighth->SetTitle("btagLight");
      
      btagh = new TH2F( *btagBCh);
      btagh->Reset();
      btagh->SetName("btag");
      btagh->SetTitle("btag");
 
      sysh = new TH2F( *jesh);
      sysh->Reset();
      sysh->SetName("sys");
      sysh->SetTitle("sys");

      unch = new TH2F( *jesh);
      unch->Reset();
      unch->SetName("unc");
      unch->SetTitle("unc");


      jesPercenth = new TH2F( *systematics[0]->sysh);
      jesPercenth->SetName("jesPercent");
      jesPercenth->SetTitle("jesPercent");
      jesPercenth->Divide( sigh);
      jesPercenth->Scale( 100.);      

      btagBCPercenth = new TH2F( *systematics[1]->sysh);
      btagBCPercenth->SetName("btagBCPercent");
      btagBCPercenth->SetTitle("btagBCPercent");
      btagBCPercenth->Divide( sigh);
      btagBCPercenth->Scale( 100.);   

      btagLightPercenth = new TH2F( *systematics[2]->sysh);
      btagLightPercenth->SetName("btagLightPercent");
      btagLightPercenth->SetTitle("btagLightPercent");
      btagLightPercenth->Divide( sigh);
      btagLightPercenth->Scale( 100.);   

      btagPercenth = new TH2F( *btagBCh);
      btagPercenth->Reset();
      btagPercenth->SetName("btagPercent");
      btagPercenth->SetTitle("btagPercent");
 
      sysPercenth = new TH2F( *jesh);
      sysPercenth->Reset();
      sysPercenth->SetName("sysPercent");
      sysPercenth->SetTitle("sysPercent");

      uncPercenth = new TH2F( *jesh);
      uncPercenth->Reset();
      uncPercenth->SetName("uncPercent");
      uncPercenth->SetTitle("uncPercent");

      for (int ibin = 0; ibin < sigh->GetSize(); ibin++){	
	sig = sigh->GetBinContent( ibin);
	stat = sigh->GetBinError( ibin);

	jes = jesh->GetBinContent(ibin);
	bc = btagBCh->GetBinContent(ibin);
	light = btagLighth->GetBinContent(ibin);
    
	unc = sqrt( bc * bc + light * light);
	btagh->SetBinContent( ibin, unc);
	btagPercenth->SetBinContent( ibin, unc / sig * 100.);
	
	unc = sqrt( jes * jes + bc * bc + light * light +
		    sig * sig * (0.044 * 0.044 + // Lumi
				 0.03  * 0.03  + // Trigger
				 0.05  * 0.05    // Lep Id
				 )
		    );       
	sysh->SetBinContent( ibin, unc);
	sysPercenth->SetBinContent( ibin, unc / sig * 100.);
	
	unc = sqrt( jes * jes + bc * bc + light * light + stat * stat +  
		    sig * sig * (0.044 * 0.044 + // Lumi
				 0.03  * 0.03  + // Trigger
				 0.05  * 0.05    // Lep Id
				 )
		    );	
	unch->SetBinContent( ibin, unc);
	uncPercenth->SetBinContent( ibin, unc / sig * 100.);
      }
      outSRDir->cd();

      datah->Write();
      bkgh->Write();

      sig_toth->Write();
      sigh->Write();
      effh->Write();
      
      sigLh->Write();
      effLh->Write();

      sigRh->Write();
      effRh->Write();

      jesh->Write();
      btagBCh->Write(); 
      btagLighth->Write();
      btagh->Write();
      
      sysh->Write();
      unch->Write();

      jesPercenth->Write();
      btagBCPercenth->Write(); 
      btagLightPercenth->Write();
      btagPercenth->Write();
      
      sysPercenth->Write();
      uncPercenth->Write();
    }
  }

  delete systematics[0];
  delete systematics[1];
  delete systematics[2];

  outFile->Close();
  sigFile->Close();
  bkgFile->Close();

  return 0;
}
Ejemplo n.º 12
0
void PhotonIsolation()

{
  const float chargeHadronIsoCut_LWP_EB = 1.3;
  const float chargeHadronIsoCut_MWP_EB = 0.44;
  const float chargeHadronIsoCut_TWP_EB = 0.2;

  const float chargeHadronIsoCut_LWP_EE = 1.36;
  const float chargeHadronIsoCut_MWP_EE = 0.82;
  const float chargeHadronIsoCut_TWP_EE = 0.27;

  const float HoverECut_LWP_EB = 0.06;
  const float HoverECut_MWP_EB = 0.04;
  const float HoverECut_TWP_EB = 0.027;

  const float HoverECut_LWP_EE = 0.027;
  const float HoverECut_MWP_EE = 0.021;
  const float HoverECut_TWP_EE = 0.020;

  const float SigIEtaIEtaCut_LWP_EB = 0.01031;
  const float SigIEtaIEtaCut_MWP_EB = 0.01023;
  const float SigIEtaIEtaCut_TWP_EB = 0.00994;

  const float SigIEtaIEtaCut_LWP_EE = 0.0269;
  const float SigIEtaIEtaCut_MWP_EE = 0.0259;
  const float SigIEtaIEtaCut_TWP_EE = 0.0258;

  const float beamSpotZ = 0.282329;
  const float beamSpotSigmaZ = 43.131299;
  const float NPU = 140.0;

  const int n_density = 5;

  float IsoEff_NoTiming[n_density] = {0.0};// for n_density pu density bins, ranging from 0 to 2.0, bin width 0.1
  float Err_IsoEff_NoTiming[n_density] = {0.0};// for n_density pu density bins, ranging from 0 to 2.0, bin width 0.1
  float IsoEff_Timing50_TrkVtx[n_density] = {0.0}; 
  float IsoEff_Timing80_TrkVtx[n_density] = {0.0}; 
  float Err_IsoEff_Timing80_TrkVtx[n_density] = {0.0}; 
  float IsoEff_Timing120_TrkVtx[n_density] = {0.0}; 

  float IsoEff_Timing50_TrkPho[n_density] = {0.0}; 
  float IsoEff_Timing80_TrkPho[n_density] = {0.0}; 
  float IsoEff_Timing120_TrkPho[n_density] = {0.0}; 
  float Err_IsoEff_Timing120_TrkPho[n_density] = {0.0}; 


  int N_Pho_Total_NoBin = 0;
  int N_Pho_Total_NoBin200 = 0;
  int N_Pho_Total[n_density] = {0};
  int N_Pho_Total200[n_density] = {0};
  int N_Pho_PassIso_NoTiming[n_density] = {0}; 
  int N_Pho_PassIso_Timing50_TrkVtx[n_density] = {0}; 
  int N_Pho_PassIso_Timing80_TrkVtx[n_density] = {0}; 
  int N_Pho_PassIso_Timing120_TrkVtx[n_density] = {0}; 
 
  int N_Pho_PassIso_Timing50_TrkPho[n_density] = {0}; 
  int N_Pho_PassIso_Timing80_TrkPho[n_density] = {0}; 
  int N_Pho_PassIso_Timing120_TrkPho[n_density] = {0}; 
 

  TTree * tree = 0;
  TFile *f  =new TFile("/afs/cern.ch/work/z/zhicaiz/public/release/CMSSW_8_1_0_pre15/src/SUSYBSMAnalysis/RazorTuplizer/python/razorNtuple_PU140_Timing_Iso.root");
  TDirectory * dir = (TDirectory*)f->Get("/afs/cern.ch/work/z/zhicaiz/public/release/CMSSW_8_1_0_pre15/src/SUSYBSMAnalysis/RazorTuplizer/python/razorNtuple_PU140_Timing_Iso.root:/ntuples");
  dir->GetObject("RazorEvents",tree);
  //cout<<tree->GetEntries()<<endl;  
  int NEntries = tree->GetEntries();

  TTree * tree200 = 0;
  TFile *f200  =new TFile("/afs/cern.ch/work/z/zhicaiz/public/release/CMSSW_8_1_0_pre15/src/SUSYBSMAnalysis/RazorTuplizer/python/razorNtuple_PU200_Timing_Iso.root");
  TDirectory * dir200 = (TDirectory*)f200->Get("/afs/cern.ch/work/z/zhicaiz/public/release/CMSSW_8_1_0_pre15/src/SUSYBSMAnalysis/RazorTuplizer/python/razorNtuple_PU200_Timing_Iso.root:/ntuples");
  dir200->GetObject("RazorEvents",tree200);
  //cout<<tree->GetEntries()<<endl;  
  int NEntries200 = tree200->GetEntries();


  Int_t           nPhotons;

  Float_t         pvZ;
  Float_t         phoSigmaIetaIeta[700];
  Float_t         pho_superClusterEta[700];
  Float_t         pho_superClusterEnergy[700];
  Float_t         pho_HoverE[700];
  Bool_t          pho_passEleVeto[700];
  
  Float_t         pho_sumChargedHadronPt_NewPV_NoTiming[700];
  Float_t         pho_sumChargedHadronPt_NewPV_Timing50_TrkVtx[700];
  Float_t         pho_sumChargedHadronPt_NewPV_Timing80_TrkVtx[700];
  Float_t         pho_sumChargedHadronPt_NewPV_Timing120_TrkVtx[700];
 
  Float_t         pho_sumChargedHadronPt_NewPV_Timing50_TrkPho[700];
  Float_t         pho_sumChargedHadronPt_NewPV_Timing80_TrkPho[700];
  Float_t         pho_sumChargedHadronPt_NewPV_Timing120_TrkPho[700];
  
  tree->SetBranchAddress("nPhotons", &nPhotons);
  tree->SetBranchAddress("pvZ_New", &pvZ);
  tree->SetBranchAddress("phoSigmaIetaIeta", phoSigmaIetaIeta);
  tree->SetBranchAddress("pho_superClusterEta", pho_superClusterEta);
  tree->SetBranchAddress("pho_superClusterEnergy", pho_superClusterEnergy);
  tree->SetBranchAddress("pho_HoverE", pho_HoverE);
  tree->SetBranchAddress("pho_passEleVeto", pho_passEleVeto);
  
  tree->SetBranchAddress("pho_sumChargedHadronPt_NewPV_NoTiming", pho_sumChargedHadronPt_NewPV_NoTiming);
  tree->SetBranchAddress("pho_sumChargedHadronPt_NewPV_Timing50_TrkVtx", pho_sumChargedHadronPt_NewPV_Timing50_TrkVtx);
  tree->SetBranchAddress("pho_sumChargedHadronPt_NewPV_Timing80_TrkVtx", pho_sumChargedHadronPt_NewPV_Timing80_TrkVtx);
  tree->SetBranchAddress("pho_sumChargedHadronPt_NewPV_Timing120_TrkVtx", pho_sumChargedHadronPt_NewPV_Timing120_TrkVtx);

  tree->SetBranchAddress("pho_sumChargedHadronPt_NewPV_Timing50_TrkPho", pho_sumChargedHadronPt_NewPV_Timing50_TrkPho);
  tree->SetBranchAddress("pho_sumChargedHadronPt_NewPV_Timing80_TrkPho", pho_sumChargedHadronPt_NewPV_Timing80_TrkPho);
  tree->SetBranchAddress("pho_sumChargedHadronPt_NewPV_Timing120_TrkPho", pho_sumChargedHadronPt_NewPV_Timing120_TrkPho);

  tree200->SetBranchAddress("nPhotons", &nPhotons);
  tree200->SetBranchAddress("pvZ_New", &pvZ);
  tree200->SetBranchAddress("phoSigmaIetaIeta", phoSigmaIetaIeta);
  tree200->SetBranchAddress("pho_superClusterEta", pho_superClusterEta);
  tree200->SetBranchAddress("pho_superClusterEnergy", pho_superClusterEnergy);
  tree200->SetBranchAddress("pho_HoverE", pho_HoverE);
  tree200->SetBranchAddress("pho_passEleVeto", pho_passEleVeto);
  
  tree200->SetBranchAddress("pho_sumChargedHadronPt_NewPV_NoTiming", pho_sumChargedHadronPt_NewPV_NoTiming);
  tree200->SetBranchAddress("pho_sumChargedHadronPt_NewPV_Timing50_TrkVtx", pho_sumChargedHadronPt_NewPV_Timing50_TrkVtx);
  tree200->SetBranchAddress("pho_sumChargedHadronPt_NewPV_Timing80_TrkVtx", pho_sumChargedHadronPt_NewPV_Timing80_TrkVtx);
  tree200->SetBranchAddress("pho_sumChargedHadronPt_NewPV_Timing120_TrkVtx", pho_sumChargedHadronPt_NewPV_Timing120_TrkVtx);

  tree200->SetBranchAddress("pho_sumChargedHadronPt_NewPV_Timing50_TrkPho", pho_sumChargedHadronPt_NewPV_Timing50_TrkPho);
  tree200->SetBranchAddress("pho_sumChargedHadronPt_NewPV_Timing80_TrkPho", pho_sumChargedHadronPt_NewPV_Timing80_TrkPho);
  tree200->SetBranchAddress("pho_sumChargedHadronPt_NewPV_Timing120_TrkPho", pho_sumChargedHadronPt_NewPV_Timing120_TrkPho);


  TH1F * h_pho_sumChargedHadronPt_NewPV_NoTiming = new TH1F("h_pho_sumChargedHadronPt_NewPV_NoTiming","h_pho_sumChargedHadronPt_NewPV_NoTiming", 100,0,5);
  TH1F * h_pho_sumChargedHadronPt_NewPV_Timing50_TrkVtx = new TH1F("h_pho_sumChargedHadronPt_NewPV_Timing50_TrkVtx","h_pho_sumChargedHadronPt_NewPV_Timing50_TrkVtx", 100,0,5);
  TH1F * h_pho_sumChargedHadronPt_NewPV_Timing80_TrkVtx = new TH1F("h_pho_sumChargedHadronPt_NewPV_Timing80_TrkVtx","h_pho_sumChargedHadronPt_NewPV_Timing80_TrkVtx", 100,0,5);
  TH1F * h_pho_sumChargedHadronPt_NewPV_Timing120_TrkVtx = new TH1F("h_pho_sumChargedHadronPt_NewPV_Timing120_TrkVtx","h_pho_sumChargedHadronPt_NewPV_Timing120_TrkVtx", 100,0,5);

  TH1F * h_pho_sumChargedHadronPt_NewPV_Timing50_TrkPho = new TH1F("h_pho_sumChargedHadronPt_NewPV_Timing50_TrkPho","h_pho_sumChargedHadronPt_NewPV_Timing50_TrkPho", 100,0,5);
  TH1F * h_pho_sumChargedHadronPt_NewPV_Timing80_TrkPho = new TH1F("h_pho_sumChargedHadronPt_NewPV_Timing80_TrkPho","h_pho_sumChargedHadronPt_NewPV_Timing80_TrkPho", 100,0,5);
  TH1F * h_pho_sumChargedHadronPt_NewPV_Timing120_TrkPho = new TH1F("h_pho_sumChargedHadronPt_NewPV_Timing120_TrkPho","h_pho_sumChargedHadronPt_NewPV_Timing120_TrkPho", 100,0,5);


  for(int i=0;i<NEntries;i++)
 { 
	tree->GetEntry(i);
	for(int j=0;j<nPhotons;j++)
	{
        bool passCut = false;
	if(abs(pho_superClusterEta[j])<1.47 && phoSigmaIetaIeta[j]<SigIEtaIEtaCut_LWP_EB && pho_HoverE[j]<HoverECut_LWP_EB && pho_superClusterEnergy[j]/cosh(pho_superClusterEta[j])> 40.0 && pho_passEleVeto[j]==1) passCut = true;
	else if(abs(pho_superClusterEta[j])<2.5 && phoSigmaIetaIeta[j]<SigIEtaIEtaCut_LWP_EE && pho_HoverE[j]<HoverECut_LWP_EE && pho_superClusterEnergy[j]/cosh(pho_superClusterEta[j])> 40.0 && pho_passEleVeto[j]==1) passCut = true;
	if(!passCut) continue;

        N_Pho_Total_NoBin ++;		

	float pu_density =  140*TMath::Gaus(pvZ*10.0,beamSpotZ,beamSpotSigmaZ,1);
	//cout<<"event "<<i<<"  photon "<<j<<" pu_density "<<pu_density<<endl;	
	int pu_density_bin = int(pu_density*n_density/2.0);
 	if(pu_density_bin >= n_density) continue;

  	N_Pho_Total[pu_density_bin] ++;

        //if(pho_sumChargedHadronPt_NewPV_NoTiming[j]>-1.0) h_pho_sumChargedHadronPt_NewPV_NoTiming->Fill(pho_sumChargedHadronPt_NewPV_NoTiming[j]);	
        //if(pho_sumChargedHadronPt_NewPV_Timing50_TrkVtx[j]>-1.0) h_pho_sumChargedHadronPt_NewPV_Timing50_TrkVtx->Fill(pho_sumChargedHadronPt_NewPV_Timing50_TrkVtx[j]);	
        //if(pho_sumChargedHadronPt_NewPV_Timing80_TrkVtx[j]>-1.0) h_pho_sumChargedHadronPt_NewPV_Timing80_TrkVtx->Fill(pho_sumChargedHadronPt_NewPV_Timing80_TrkVtx[j]);	
        //if(pho_sumChargedHadronPt_NewPV_Timing120_TrkVtx[j]>-1.0) h_pho_sumChargedHadronPt_NewPV_Timing120_TrkVtx->Fill(pho_sumChargedHadronPt_NewPV_Timing120_TrkVtx[j]);	
	
 	if(pho_sumChargedHadronPt_NewPV_Timing50_TrkPho[j]>-1.0) h_pho_sumChargedHadronPt_NewPV_Timing50_TrkPho->Fill(pho_sumChargedHadronPt_NewPV_Timing50_TrkPho[j]);	
        if(pho_sumChargedHadronPt_NewPV_Timing80_TrkPho[j]>-1.0) h_pho_sumChargedHadronPt_NewPV_Timing80_TrkPho->Fill(pho_sumChargedHadronPt_NewPV_Timing80_TrkPho[j]);	
        if(pho_sumChargedHadronPt_NewPV_Timing120_TrkPho[j]>-1.0) h_pho_sumChargedHadronPt_NewPV_Timing120_TrkPho->Fill(pho_sumChargedHadronPt_NewPV_Timing120_TrkPho[j]);	
	

	if(abs(pho_superClusterEta[j])<1.47)
	{
	//if( pho_sumChargedHadronPt_NewPV_NoTiming[j] < chargeHadronIsoCut_LWP_EB) N_Pho_PassIso_NoTiming[pu_density_bin]++;
	//if( pho_sumChargedHadronPt_NewPV_Timing50_TrkVtx[j] < chargeHadronIsoCut_LWP_EB) N_Pho_PassIso_Timing50_TrkVtx[pu_density_bin]++;
	//if( pho_sumChargedHadronPt_NewPV_Timing80_TrkVtx[j] < chargeHadronIsoCut_LWP_EB) N_Pho_PassIso_Timing80_TrkVtx[pu_density_bin]++;
	//if( pho_sumChargedHadronPt_NewPV_Timing120_TrkVtx[j] < chargeHadronIsoCut_LWP_EB) N_Pho_PassIso_Timing120_TrkVtx[pu_density_bin]++;

	if( pho_sumChargedHadronPt_NewPV_Timing50_TrkPho[j] < chargeHadronIsoCut_LWP_EB) N_Pho_PassIso_Timing50_TrkPho[pu_density_bin]++;
	if( pho_sumChargedHadronPt_NewPV_Timing80_TrkPho[j] < chargeHadronIsoCut_LWP_EB) N_Pho_PassIso_Timing80_TrkPho[pu_density_bin]++;
	if( pho_sumChargedHadronPt_NewPV_Timing120_TrkPho[j] < chargeHadronIsoCut_LWP_EB) N_Pho_PassIso_Timing120_TrkPho[pu_density_bin]++;

	}
	else if(abs(pho_superClusterEta[j])<2.5)
	{
	//if( pho_sumChargedHadronPt_NewPV_NoTiming[j] < chargeHadronIsoCut_LWP_EE) N_Pho_PassIso_NoTiming[pu_density_bin]++;
	//if( pho_sumChargedHadronPt_NewPV_Timing50_TrkVtx[j] < chargeHadronIsoCut_LWP_EE) N_Pho_PassIso_Timing50_TrkVtx[pu_density_bin]++;
	//if( pho_sumChargedHadronPt_NewPV_Timing80_TrkVtx[j] < chargeHadronIsoCut_LWP_EE) N_Pho_PassIso_Timing80_TrkVtx[pu_density_bin]++;
	//if( pho_sumChargedHadronPt_NewPV_Timing120_TrkVtx[j] < chargeHadronIsoCut_LWP_EE) N_Pho_PassIso_Timing120_TrkVtx[pu_density_bin]++;

	if( pho_sumChargedHadronPt_NewPV_Timing50_TrkPho[j] < chargeHadronIsoCut_LWP_EE) N_Pho_PassIso_Timing50_TrkPho[pu_density_bin]++;
	if( pho_sumChargedHadronPt_NewPV_Timing80_TrkPho[j] < chargeHadronIsoCut_LWP_EE) N_Pho_PassIso_Timing80_TrkPho[pu_density_bin]++;
	if( pho_sumChargedHadronPt_NewPV_Timing120_TrkPho[j] < chargeHadronIsoCut_LWP_EE) N_Pho_PassIso_Timing120_TrkPho[pu_density_bin]++;
	}
	}
 }

//  cout<<"Total photons in sample that pass cuts: "<<N_Pho_Total_NoBin<<endl;

  for(int i=0;i<NEntries200;i++)
 { 
	tree200->GetEntry(i);
	for(int j=0;j<nPhotons;j++)
	{
        bool passCut = false;
	if(abs(pho_superClusterEta[j])<1.47 && phoSigmaIetaIeta[j]<SigIEtaIEtaCut_LWP_EB && pho_HoverE[j]<HoverECut_LWP_EB && pho_superClusterEnergy[j]/cosh(pho_superClusterEta[j])> 40.0 && pho_passEleVeto[j]==1) passCut = true;
	else if(abs(pho_superClusterEta[j])<2.5 && phoSigmaIetaIeta[j]<SigIEtaIEtaCut_LWP_EE && pho_HoverE[j]<HoverECut_LWP_EE && pho_superClusterEnergy[j]/cosh(pho_superClusterEta[j])> 40.0 && pho_passEleVeto[j]==1) passCut = true;
	if(!passCut) continue;

        N_Pho_Total_NoBin200 ++;		

	float pu_density =  200*TMath::Gaus(pvZ*10.0,beamSpotZ,beamSpotSigmaZ,1);
	//cout<<"event "<<i<<"  photon "<<j<<" pu_density "<<pu_density<<endl;	
	int pu_density_bin = int(pu_density*n_density/2.0);
 	if(pu_density_bin >= n_density) continue;

  	N_Pho_Total200[pu_density_bin] ++;

        if(pho_sumChargedHadronPt_NewPV_NoTiming[j]>-1.0) h_pho_sumChargedHadronPt_NewPV_NoTiming->Fill(pho_sumChargedHadronPt_NewPV_NoTiming[j]);	
        if(pho_sumChargedHadronPt_NewPV_Timing50_TrkVtx[j]>-1.0) h_pho_sumChargedHadronPt_NewPV_Timing50_TrkVtx->Fill(pho_sumChargedHadronPt_NewPV_Timing50_TrkVtx[j]);	
        if(pho_sumChargedHadronPt_NewPV_Timing80_TrkVtx[j]>-1.0) h_pho_sumChargedHadronPt_NewPV_Timing80_TrkVtx->Fill(pho_sumChargedHadronPt_NewPV_Timing80_TrkVtx[j]);	
        if(pho_sumChargedHadronPt_NewPV_Timing120_TrkVtx[j]>-1.0) h_pho_sumChargedHadronPt_NewPV_Timing120_TrkVtx->Fill(pho_sumChargedHadronPt_NewPV_Timing120_TrkVtx[j]);	
	

	if(abs(pho_superClusterEta[j])<1.47)
	{
	if( pho_sumChargedHadronPt_NewPV_NoTiming[j] < chargeHadronIsoCut_LWP_EB) N_Pho_PassIso_NoTiming[pu_density_bin]++;
	if( pho_sumChargedHadronPt_NewPV_Timing50_TrkVtx[j] < chargeHadronIsoCut_LWP_EB) N_Pho_PassIso_Timing50_TrkVtx[pu_density_bin]++;
	if( pho_sumChargedHadronPt_NewPV_Timing80_TrkVtx[j] < chargeHadronIsoCut_LWP_EB) N_Pho_PassIso_Timing80_TrkVtx[pu_density_bin]++;
	if( pho_sumChargedHadronPt_NewPV_Timing120_TrkVtx[j] < chargeHadronIsoCut_LWP_EB) N_Pho_PassIso_Timing120_TrkVtx[pu_density_bin]++;

	}
	else if(abs(pho_superClusterEta[j])<2.5)
	{
	if( pho_sumChargedHadronPt_NewPV_NoTiming[j] < chargeHadronIsoCut_LWP_EE) N_Pho_PassIso_NoTiming[pu_density_bin]++;
	if( pho_sumChargedHadronPt_NewPV_Timing50_TrkVtx[j] < chargeHadronIsoCut_LWP_EE) N_Pho_PassIso_Timing50_TrkVtx[pu_density_bin]++;
	if( pho_sumChargedHadronPt_NewPV_Timing80_TrkVtx[j] < chargeHadronIsoCut_LWP_EE) N_Pho_PassIso_Timing80_TrkVtx[pu_density_bin]++;
	if( pho_sumChargedHadronPt_NewPV_Timing120_TrkVtx[j] < chargeHadronIsoCut_LWP_EE) N_Pho_PassIso_Timing120_TrkVtx[pu_density_bin]++;

	}
	}
 }

 
  float pu_density[n_density];
  float ex[n_density] = {0.0};

  cout<<"Total number of photons (PU200): "<<N_Pho_Total_NoBin200<<endl;

  for(int i=0;i<n_density;i++)
  {
//	ex[i] = 0.5*2.0/n_density;
	pu_density[i] = 2.0*(i+0.5)/n_density;
	cout<<"bin: "<<i<<"  #pho = "<<N_Pho_Total200[i]<<"   #pho_passIso(NoTiming) = "<<N_Pho_PassIso_NoTiming[i]<<endl;
	if(N_Pho_Total[i]>0)
	{
//	IsoEff_NoTiming[i] =100.0* (N_Pho_PassIso_NoTiming[i]*1.0)/(N_Pho_Total[i]);
//	IsoEff_Timing50_TrkVtx[i] = 100.0* (N_Pho_PassIso_Timing50_TrkVtx[i]*1.0)/(N_Pho_Total[i]);
//	IsoEff_Timing80_TrkVtx[i] = 100.0* (N_Pho_PassIso_Timing80_TrkVtx[i]*1.0)/(N_Pho_Total[i]);
//	IsoEff_Timing120_TrkVtx[i] = 100.0* (N_Pho_PassIso_Timing120_TrkVtx[i]*1.0)/(N_Pho_Total[i]);

	IsoEff_Timing50_TrkPho[i] = 100.0* (N_Pho_PassIso_Timing50_TrkPho[i]*1.0)/(N_Pho_Total[i]);
	IsoEff_Timing80_TrkPho[i] = 100.0* (N_Pho_PassIso_Timing80_TrkPho[i]*1.0)/(N_Pho_Total[i]);
	IsoEff_Timing120_TrkPho[i] = 100.0* (N_Pho_PassIso_Timing120_TrkPho[i]*1.0)/(N_Pho_Total[i]);
	Err_IsoEff_Timing120_TrkPho[i] = IsoEff_Timing120_TrkPho[i]* sqrt(1.0/N_Pho_PassIso_Timing120_TrkPho[i] + 1.0/N_Pho_Total[i]);
	}
	if(N_Pho_Total200[i]>0)
	{
	IsoEff_NoTiming[i] =100.0* (N_Pho_PassIso_NoTiming[i]*1.0)/(N_Pho_Total200[i]);
	Err_IsoEff_NoTiming[i] = IsoEff_NoTiming[i]* sqrt(1.0/N_Pho_PassIso_NoTiming[i] + 1.0/N_Pho_Total200[i]);
	IsoEff_Timing50_TrkVtx[i] = 100.0* (N_Pho_PassIso_Timing50_TrkVtx[i]*1.0)/(N_Pho_Total200[i]);
	IsoEff_Timing80_TrkVtx[i] = 100.0* (N_Pho_PassIso_Timing80_TrkVtx[i]*1.0)/(N_Pho_Total200[i]);
	Err_IsoEff_Timing80_TrkVtx[i] = IsoEff_Timing80_TrkVtx[i]* sqrt(1.0/N_Pho_PassIso_Timing80_TrkVtx[i] + 1.0/N_Pho_Total200[i]);
	IsoEff_Timing120_TrkVtx[i] = 100.0* (N_Pho_PassIso_Timing120_TrkVtx[i]*1.0)/(N_Pho_Total200[i]);
	}

  }


  float MaxY = 0.0;
  float MinY = 999.9;

  TGraphErrors *gr_NoTiming = new TGraphErrors(n_density, pu_density, IsoEff_NoTiming,ex,Err_IsoEff_NoTiming);
  TGraphErrors *gr_Timing80_TrkVtx = new TGraphErrors(n_density, pu_density, IsoEff_Timing80_TrkVtx,ex, Err_IsoEff_Timing80_TrkVtx);
  TGraphErrors *gr_Timing120_TrkPho = new TGraphErrors(n_density, pu_density, IsoEff_Timing120_TrkPho,ex, Err_IsoEff_Timing120_TrkPho);

  TGraph *gr_Timing80_TrkPho = new TGraph(n_density, pu_density, IsoEff_Timing80_TrkPho);
  TGraph *gr_Timing120_TrkVtx = new TGraph(n_density, pu_density, IsoEff_Timing120_TrkVtx);


  gStyle->SetOptStat(0);


  TCanvas *cv = 0;
  TLegend *legend = 0;
  TLegend *legend_h = 0;
  bool firstdrawn = false;
  TLatex *tex = 0;
  TLine *line = 0;


  cv = new TCanvas("cv","cv", 800,800);
  cv->SetLeftMargin(0.15);
  cv->SetBottomMargin(0.12);

  legend_h = new TLegend(0.20,0.75,0.60,0.88, NULL,"brNDC");
  legend_h->SetTextSize(0.03);
  legend_h->SetBorderSize(0);
  legend_h->SetLineColor(1);
  legend_h->SetLineStyle(1);
  legend_h->SetLineWidth(1);
  legend_h->SetFillColor(0);
  legend_h->SetFillStyle(1001);

  legend_h->AddEntry(h_pho_sumChargedHadronPt_NewPV_NoTiming, "No Timing cut (PU200)");
  legend_h->AddEntry(h_pho_sumChargedHadronPt_NewPV_Timing80_TrkVtx, "Track-Vertex Timing 80ps cut (PU200)");
  //legend_h->AddEntry(h_pho_sumChargedHadronPt_NewPV_Timing120_TrkVtx, "Track-Vertex Timing 120ps cut (PU200)");
  //legend_h->AddEntry(h_pho_sumChargedHadronPt_NewPV_Timing80_TrkPho, "Track-Photon Timing 80ps cut (PU140)");
  legend_h->AddEntry(h_pho_sumChargedHadronPt_NewPV_Timing120_TrkPho, "Track-Photon Timing 120ps cut (PU140)");

 
  h_pho_sumChargedHadronPt_NewPV_NoTiming->Draw();
  h_pho_sumChargedHadronPt_NewPV_Timing80_TrkVtx->Draw("same");
 // h_pho_sumChargedHadronPt_NewPV_Timing120_TrkVtx->Draw("same");
 // h_pho_sumChargedHadronPt_NewPV_Timing80_TrkPho->Draw("same");
  h_pho_sumChargedHadronPt_NewPV_Timing120_TrkPho->Draw("same");
  legend_h->Draw();

  h_pho_sumChargedHadronPt_NewPV_NoTiming->SetLineColor(2);
  h_pho_sumChargedHadronPt_NewPV_Timing80_TrkVtx->SetLineColor(4);
  h_pho_sumChargedHadronPt_NewPV_Timing120_TrkPho->SetLineColor(3);

  h_pho_sumChargedHadronPt_NewPV_NoTiming->SetTitle("");
  h_pho_sumChargedHadronPt_NewPV_NoTiming->GetXaxis()->SetTitle("sum charged hadron Pt / GeV");
  h_pho_sumChargedHadronPt_NewPV_NoTiming->GetXaxis()->SetTitleSize(0.045);
  h_pho_sumChargedHadronPt_NewPV_NoTiming->GetXaxis()->SetTitleOffset(1.1);
  h_pho_sumChargedHadronPt_NewPV_NoTiming->GetYaxis()->SetTitle("Events");
  h_pho_sumChargedHadronPt_NewPV_NoTiming->GetYaxis()->SetTitleOffset(1.2);
  h_pho_sumChargedHadronPt_NewPV_NoTiming->GetYaxis()->SetTitleSize(0.045);
  h_pho_sumChargedHadronPt_NewPV_NoTiming->GetYaxis()->SetRangeUser(0,200);


  cv->SaveAs("~/www/sharebox/tomyself/Timing/h_chargedHadronPt.pdf");
  cv->SaveAs("~/www/sharebox/tomyself/Timing/h_chargedHadronPt.png");
  cv->SaveAs("~/www/sharebox/tomyself/Timing/h_chargedHadronPt.C");

  legend = new TLegend(0.20,0.75,0.60,0.88, NULL,"brNDC");
  legend->SetTextSize(0.03);
  legend->SetBorderSize(0);
  legend->SetLineColor(1);
  legend->SetLineStyle(1);
  legend->SetLineWidth(1);
  legend->SetFillColor(0);
  legend->SetFillStyle(1001);

  legend->AddEntry(gr_NoTiming, "No Timing cut (PU200)");
  legend->AddEntry(gr_Timing80_TrkVtx, "Track-Vertex Timing 80ps cut (PU200)");
  //legend->AddEntry(gr_Timing120_TrkVtx, "Track-Vertex Timing 120ps cut (PU200)");
  //legend->AddEntry(gr_Timing80_TrkPho, "Track-Photon Timing 80ps cut (PU140)");
  legend->AddEntry(gr_Timing120_TrkPho, "Track-Photon Timing 120ps cut (PU140)");


  gr_NoTiming->Draw("AP");
  gr_Timing80_TrkVtx->Draw("P");
  //gr_Timing120_TrkVtx->Draw("P");

  //gr_Timing80_TrkPho->Draw("P");
  gr_Timing120_TrkPho->Draw("P");
 
  legend->Draw();

  gr_NoTiming->SetFillStyle(0);
  gr_NoTiming->SetLineColor(kRed);
  gr_NoTiming->SetLineWidth(2);
  gr_NoTiming->SetMarkerColor(kRed);
  gr_NoTiming->SetMarkerStyle(20);
  gr_NoTiming->SetMarkerSize(2);

  gr_Timing80_TrkVtx->SetFillStyle(0);
  gr_Timing80_TrkVtx->SetLineColor(kBlue);
  gr_Timing80_TrkVtx->SetLineWidth(2);
  gr_Timing80_TrkVtx->SetMarkerColor(kBlue);
  gr_Timing80_TrkVtx->SetMarkerStyle(22);
  gr_Timing80_TrkVtx->SetMarkerSize(2);


  gr_Timing120_TrkPho->SetFillStyle(0);
  gr_Timing120_TrkPho->SetLineColor(kGreen);
  gr_Timing120_TrkPho->SetLineWidth(2);
  gr_Timing120_TrkPho->SetMarkerColor(kGreen);
  gr_Timing120_TrkPho->SetMarkerStyle(21);
  gr_Timing120_TrkPho->SetMarkerSize(2);


 
  gr_NoTiming->SetTitle("");
  gr_NoTiming->GetXaxis()->SetTitle("Linear Pileup Density (events / mm)");
  gr_NoTiming->GetXaxis()->SetTitleSize(0.045);
  gr_NoTiming->GetXaxis()->SetTitleOffset(1.1);
  gr_NoTiming->GetYaxis()->SetTitle("Photon Charged Isolation Eff (%)");
  gr_NoTiming->GetYaxis()->SetTitleOffset(1.2);
  gr_NoTiming->GetYaxis()->SetTitleSize(0.045);
  gr_NoTiming->GetYaxis()->SetRangeUser(60,105);
  gr_NoTiming->GetXaxis()->SetRangeUser(0,2.0);

  cv->SaveAs("~/www/sharebox/tomyself/Timing/PhotonIsolationEff.pdf");
  cv->SaveAs("~/www/sharebox/tomyself/Timing/PhotonIsolationEff.C");
  cv->SaveAs("~/www/sharebox/tomyself/Timing/PhotonIsolationEff.png");

}
Ejemplo n.º 13
0
void subJetParctice0805() {
	
  float  DRR[7]={0.1,0.15,0.2,0.25,0.3,0.35,0.4};
  TGraphAsymmErrors* TGrDR[7][13];
  TGraphAsymmErrors* TGrPt[7][13];
  for (int DR=0;DR<7;DR++){
    c1 = new TCanvas("c1","",1360,768);
	string  masspoint[13]={"600","800","1000","1200","1400","1600","1800","2000","2500","3000","3500","4000","4500"};
	string  crabInf[13]={"150729_212416","150729_212459","150729_211555","150729_211640","150729_211727","150729_211727","150729_211855","150729_211940","150729_212023","150729_212110","150729_212159","150729_212245","150729_212331"};
    for (int massP=0;massP<13;massP++){
		TString endfix =Form("signal-%s",masspoint[massP].data());
		TH1F* th1=new TH1F("deltaR","deltaR",40,0,1);
		TH1F* th2=new TH1F("deltaRCut","deltaRCut",40,0,1);
		TH1F* th3,*th4;
		if(massP<5){
			double bins[7]={200,250,300,350,500,1000,2000};
			th3=new TH1F("Pt","Pt",6,bins);
		    th4=new TH1F("PtCut","PtCut",6,bins);
			
		}
		else{
			double bins[10]={200,300,400,500,700,1000,1300,1500,2000,2500};
			th3=new TH1F("Pt","Pt",9,bins);
		    th4=new TH1F("PtCut","PtCut",9,bins);
		}
		
		TH1F* th5=new TH1F("SDMass","SDMass",14,0,210);
		TH1F* th6=new TH1F("SDMassCut","SDMassCut",14,0,210);
		th2->SetLineColor(2);
	
		for(int w=1;w<2;w++){
		  f = TFile::Open(Form("/data2/syu/13TeV/ZprimeZhbb/ZprimeToZhToZlephbb_narrow_M-%s_13TeV-madgraph.root",masspoint[massP].data()));
		  if (!f || !f->IsOpen())continue;
		  TDirectory * dir = (TDirectory*)f->Get(Form("/data2/syu/13TeV/ZprimeZhbb/ZprimeToZhToZlephbb_narrow_M-%s_13TeV-madgraph.root:/tree",masspoint[massP].data()));
		  dir->GetObject("treeMaker",tree);

			

			cout<<w<<endl;
			TreeReader data(tree);
			data.Print();
			Long64_t nentries = data.GetEntriesFast();
			
			
			
			for (Long64_t jentry=0; jentry<nentries;jentry++) {
				data.GetEntry(jentry);
				TClonesArray* FATjetP4 = (TClonesArray*) data.GetPtrTObject("FATjetP4");
				Float_t*  FATjetSDmass = data.GetPtrFloat("FATjetSDmass");
				Float_t*  FATjetCISVV2 = data.GetPtrFloat("FATjetCISVV2");
				Int_t* FATnSubSDJet=data.GetPtrInt("FATnSubSDJet");
				Int_t FATnJet=data.GetInt("FATnJet");
				
				
				if(FATnJet==0)continue;
				TLorentzVector* FATjetP4_1 = (TLorentzVector*)FATjetP4->At(0);
				
				if(FATjetP4_1->Pt()<200)continue;
				//if(FATjetSDmass[0]<100||FATjetSDmass[0]>150)continue;
				if(FATnSubSDJet[0]<2)continue;
				
				TLorentzVector  FATsubjet_1,FATsubjet_2;
				
				vector<float>   *FATsubjetSDPx =  data.GetPtrVectorFloat("FATsubjetSDPx", FATnSubSDJet[0]);
				vector<float>   *FATsubjetSDPy =  data.GetPtrVectorFloat("FATsubjetSDPy", FATnSubSDJet[0]);
				vector<float>   *FATsubjetSDPz =  data.GetPtrVectorFloat("FATsubjetSDPz", FATnSubSDJet[0]);
				vector<float>   *FATsubjetSDCE =  data.GetPtrVectorFloat("FATsubjetSDCE", FATnSubSDJet[0]);
				vector<float>   *FATsubjetSDCSV =  data.GetPtrVectorFloat("FATsubjetSDCSV", FATnSubSDJet[0]);
				
				FATsubjet_1.SetPxPyPzE(FATsubjetSDPx[0][0],FATsubjetSDPy[0][0],FATsubjetSDPz[0][0],FATsubjetSDCSV[0][0]);
	            FATsubjet_2.SetPxPyPzE(FATsubjetSDPx[0][1],FATsubjetSDPy[0][1],FATsubjetSDPz[0][1],FATsubjetSDCSV[0][1]);
	            
				th1->Fill(FATsubjet_1.DeltaR(FATsubjet_2));
				th3->Fill(FATjetP4_1->Pt());
				th5->Fill(FATjetSDmass[0]);
				if(FATsubjet_1.DeltaR(FATsubjet_2)>DRR[DR] &&(FATsubjetSDCSV[0][0]<0.432|| FATsubjetSDCSV[0][1]<0.432))continue;
				if(FATsubjet_1.DeltaR(FATsubjet_2)<DRR[DR] && FATjetCISVV2[0]<0.432)continue;
				th2->Fill(FATsubjet_1.DeltaR(FATsubjet_2));
				th4->Fill(FATjetP4_1->Pt());
				th6->Fill(FATjetSDmass[0]);
			}
			
			
		}	
		
		th1->SetTitle(Form("deltaR,mass %s Gev",masspoint[massP].data()));
		th1->Draw();
		th2->Draw("same");
		//TH1F* th5=(TH1F*)th4->Clone("eff");
		//th5->Divide(th3);
		if(massP==0)c1->Print(Form("pdf/0807_deltaR_%0.2f.pdf(",DRR[DR]));
		else if (massP==12)c1->Print(Form("pdf/0807_deltaR_%0.2f.pdf)",DRR[DR]));
		else c1->Print(Form("pdf/0807_deltaR_%0.2f.pdf",DRR[DR]));
		//th5->SetXTitle("Pt");
		//th5->SetTitle("efficiency");

	       
		TGraphAsymmErrors* g = new TGraphAsymmErrors(th2,th1);
		g->SetTitle(Form("deltaR eff %s",masspoint[massP].data()));
		g->Draw("AP");
		TGrDR[DR][massP]=new TGraphAsymmErrors(th2,th1);
		//TGrDR[DR][massP]->SetTitle(Form("deltaR eff %s",masspoint[massP].data()));
		if(massP==0)c1->Print(Form("pdf/0807_deltaR_eff_%0.2f.pdf(",DRR[DR]));
		//else if (massP==12)c1->Print(Form("pdf/0807_deltaR_eff_%0.2f.pdf)",DRR[DR]));
		else c1->Print(Form("pdf/0807_deltaR_eff_%0.2f.pdf",DRR[DR]));

		th3->Draw();
		th4->SetLineColor(2);
		th4->Draw("same");
		if(massP==0)c1->Print(Form("pdf/0807_Pt_%0.2f.pdf(",DRR[DR]));
		else if (massP==12)c1->Print(Form("pdf/0807_Pt_%0.2f.pdf)",DRR[DR]));
		else c1->Print(Form("pdf/0807_Pt_%0.2f.pdf",DRR[DR]));

		g = new TGraphAsymmErrors(th4,th3);
		g->SetTitle(Form("Pt eff %s",masspoint[massP].data()));
		g->Draw("AP");
		TGrPt[DR][massP]= new TGraphAsymmErrors(th4,th3);
		if(massP==0)c1->Print(Form("pdf/0807_Pt_eff_%0.2f.pdf(",DRR[DR]));
		//else if (massP==12)c1->Print(Form("pdf/0807_Pt_eff_%0.2f.pdf)",DRR[DR]));
		else c1->Print(Form("pdf/0807_Pt_eff_%0.2f.pdf",DRR[DR]));

		


		th5->Draw();
		th6->SetLineColor(2);
		th6->Draw("same");
		if(massP==0)c1->Print(Form("pdf/0807_SDMass_%0.2f.pdf(",DRR[DR]));
		else if (massP==12)c1->Print(Form("pdf/0807_SDMass_%0.2f.pdf)",DRR[DR]));
		else c1->Print(Form("pdf/0807_SDMass_%0.2f.pdf",DRR[DR]));

		
		g = new TGraphAsymmErrors(th6,th5);
		g->SetTitle(Form("SDMass eff %s",masspoint[massP].data()));
		g->Draw("AP");
		if(massP==0)c1->Print(Form("pdf/0807_SDMass_eff_%0.2f.pdf(",DRR[DR]));
		else if (massP==12)c1->Print(Form("pdf/0807_SDMass_eff_%0.2f.pdf)",DRR[DR]));
		else c1->Print(Form("pdf/0807_SDMass_eff_%0.2f.pdf",DRR[DR]));

		
    }	    
    double x1NDC = 0.6522;
    double y1NDC = 0.7835;
    double x2NDC = 0.9122;
    double y2NDC = 0.9860;
    
    TLegend* leg ;
    leg=new TLegend(x1NDC,y1NDC,x2NDC,y2NDC);
    setLeg(leg);
  
    
    TGrDR[DR][0]->SetLineColor(1);
    TGrDR[DR][2]->SetLineColor(2);
    TGrDR[DR][4]->SetLineColor(3);
    TGrDR[DR][0]->SetMarkerStyle(20);
    TGrDR[DR][2]->SetMarkerStyle(21);
    TGrDR[DR][4]->SetMarkerStyle(22);
    TGrDR[DR][0]->Draw("AP");
    TGrDR[DR][2]->Draw("P,same");
    TGrDR[DR][4]->Draw("P,same");
    leg->AddEntry(TGrDR[DR][0],"600");
    leg->AddEntry(TGrDR[DR][2],"1000");
    leg->AddEntry(TGrDR[DR][4],"1400");
    leg->Draw("same");
    c1->Print(Form("pdf/0807_deltaR_eff_%0.2f.pdf",DRR[DR]));


    TGrDR[DR][5]->SetLineColor(1);
    TGrDR[DR][7]->SetLineColor(2);
    TGrDR[DR][9]->SetLineColor(3);
    TGrDR[DR][12]->SetLineColor(4);
    TGrDR[DR][5]->SetMarkerStyle(20);
    TGrDR[DR][7]->SetMarkerStyle(21);
    TGrDR[DR][9]->SetMarkerStyle(22);
    TGrDR[DR][12]->SetMarkerStyle(23);
    TGrDR[DR][5]->Draw("P,same");
    TGrDR[DR][7]->Draw("P,same");
    TGrDR[DR][9]->Draw("P,same");
    TGrDR[DR][12]->Draw("P,same");
    leg->Clear();
    leg->AddEntry(TGrDR[DR][5],"1600");
    leg->AddEntry(TGrDR[DR][7],"2000");
    leg->AddEntry(TGrDR[DR][9],"3000");
    leg->AddEntry(TGrDR[DR][12],"4500");
    leg->Draw("same");
    c1->Print(Form("pdf/0807_deltaR_eff_%0.2f.pdf)",DRR[DR]));

    TGrPt[DR][0]->SetLineColor(1);
    TGrPt[DR][2]->SetLineColor(2);
    TGrPt[DR][4]->SetLineColor(3);
    TGrPt[DR][0]->SetMarkerStyle(20);
    TGrPt[DR][2]->SetMarkerStyle(21);
    TGrPt[DR][4]->SetMarkerStyle(22);
    TGrPt[DR][0]->Draw("AP");
    TGrPt[DR][2]->Draw("P,same");
    TGrPt[DR][4]->Draw("P,same");
    leg->Clear();
    leg->AddEntry(TGrPt[DR][0],"600");
    leg->AddEntry(TGrPt[DR][2],"1000");
    leg->AddEntry(TGrPt[DR][4],"1400");
    leg->Draw("same");
    c1->Print(Form("pdf/0807_Pt_eff_%0.2f.pdf",DRR[DR]));

    TGrPt[DR][5]->SetLineColor(1);
    TGrPt[DR][7]->SetLineColor(2);
    TGrPt[DR][9]->SetLineColor(3);
    TGrPt[DR][12]->SetLineColor(4);
    TGrPt[DR][5]->SetMarkerStyle(20);
    TGrPt[DR][7]->SetMarkerStyle(21);
    TGrPt[DR][9]->SetMarkerStyle(22);
    TGrPt[DR][12]->SetMarkerStyle(23);
    TGrPt[DR][5]->Draw("AP");
    TGrPt[DR][7]->Draw("P,same");
    TGrPt[DR][9]->Draw("P,same");
    TGrPt[DR][12]->Draw("P,same");
    leg->Clear();
    leg->AddEntry(TGrPt[DR][5],"1600");
    leg->AddEntry(TGrPt[DR][7],"2000");
    leg->AddEntry(TGrPt[DR][9],"3000");
    leg->AddEntry(TGrPt[DR][12],"4500");
    leg->Draw("same");
    c1->Print(Form("pdf/0807_Pt_eff_%0.2f.pdf)",DRR[DR]));



  }
  double x1NDC = 0.6522;
  double y1NDC = 0.7835;
  double x2NDC = 0.9122;
  double y2NDC = 0.9860;
  
  TLegend* leg ;
  leg=new TLegend(x1NDC,y1NDC,x2NDC,y2NDC);
  setLeg(leg);
  
  for (int massP=0;massP<13;massP++){
    TGrDR[0][massP]->SetLineColor(1);
    TGrDR[1][massP]->SetLineColor(2);
    TGrDR[2][massP]->SetLineColor(3);
    TGrDR[4][massP]->SetLineColor(4);
    TGrDR[0][massP]->SetMarkerStyle(20);
    TGrDR[1][massP]->SetMarkerStyle(21);
    TGrDR[2][massP]->SetMarkerStyle(22);
    TGrDR[4][massP]->SetMarkerStyle(23);
    TGrDR[0][massP]->Draw("AP");
    TGrDR[1][massP]->Draw("P,same");
    TGrDR[2][massP]->Draw("P,same");
    TGrDR[4][massP]->Draw("P,same");
    leg->Clear();
    leg->AddEntry(TGrDR[0][massP],"0.1");
    leg->AddEntry(TGrDR[1][massP],"0.15");
    leg->AddEntry(TGrDR[2][massP],"0.2");
    leg->AddEntry(TGrDR[4][massP],"0.3");
    leg->Draw("same");

    if(massP ==0 )c1->Print("pdf/0807_deltaR_same.pdf(");
    else c1->Print("pdf/0807_deltaR_same.pdf");

    TGrDR[3][massP]->SetLineColor(1);
    TGrDR[4][massP]->SetLineColor(2);
    TGrDR[5][massP]->SetLineColor(3);
    TGrDR[6][massP]->SetLineColor(4);
    TGrDR[3][massP]->SetMarkerStyle(20);
    TGrDR[4][massP]->SetMarkerStyle(21);
    TGrDR[5][massP]->SetMarkerStyle(22);
    TGrDR[6][massP]->SetMarkerStyle(23);
    TGrDR[3][massP]->Draw("AP");
    TGrDR[4][massP]->Draw("P,same");
    TGrDR[5][massP]->Draw("P,same");
    TGrDR[6][massP]->Draw("P,same");
    leg->Clear();
    leg->AddEntry(TGrDR[3][massP],"0.25");
    leg->AddEntry(TGrDR[4][massP],"0.3");
    leg->AddEntry(TGrDR[5][massP],"0.35");
    leg->AddEntry(TGrDR[6][massP],"0.4");
    leg->Draw("same");
    if(massP ==12 )c1->Print("pdf/0807_deltaR_same.pdf)");
    else c1->Print("pdf/0807_deltaR_same.pdf");
  }
}
void HHbbbbBtagAdditionThinJet(int wMs,int wM, string st,string st2,double Xsec,int nameRoot=0){	
	TFile *f;
	TTree *tree;
	int nPass[20]={0};int total=0;
	int dataPassingcsc=0;
	
	TH1D* th1[4];
	
	th1[0]=new TH1D("addThinJet_3b","addThinJet_3b",10,-0.5,9.5);
	th1[1]=new TH1D("addThinJet_4b","addThinJet_4b",10,-0.5,9.5);
	
	th1[2]=new TH1D("addThinJet_3b_withoutDr","addThinJet_3b_withoutDr",10,-0.5,9.5);
	th1[3]=new TH1D("addThinJet_4b_withoutDr","addThinJet_4b_withoutDr",10,-0.5,9.5);
	
	std::vector<TString> eventlist;                                                                                                                                            
	if(nameRoot==2){
		std::vector<TString> eventlist;                                                                                                                                            
		std::ifstream fin("somfilename.txt");
		eventlist.clear();
		std::string line;
		if (fin.is_open())  {
			while (fin.good())  {
				getline(fin,line);
				eventlist.push_back(line);
		}
		fin.close();
		}
	}
		
	for (int w=wMs;w<wM;w++){
		
		if (nameRoot!=1)f = TFile::Open(Form("%s%d.root",st.data(),w));
		else f = TFile::Open(st.data());
		if (!f || !f->IsOpen())continue;
		
		TDirectory * dir;
		
		if (nameRoot!=1)dir = (TDirectory*)f->Get(Form("%s%d.root:/tree",st.data(),w));
		else dir = (TDirectory*)f->Get(Form("%s:/tree",st.data()));
		
		if(w%20==0)cout<<w<<endl;
		
		dir->GetObject("treeMaker",tree);
		TreeReader data(tree);
		total+=data.GetEntriesFast();
		for(Long64_t jEntry=0; jEntry<data.GetEntriesFast() ;jEntry++){
			data.GetEntry(jEntry);
			
			
			//Int_t event        = data.GetInt("eventId");
			//0. has a good vertex
			Int_t nVtx        = data.GetInt("nVtx");
			if(nVtx<1)continue;
			nPass[0]++;
	
			std::string* trigName = data.GetPtrString("hlt_trigName");
		 	vector<bool> &trigResult = *((vector<bool>*) data.GetPtr("hlt_trigResult"));
		 	const Int_t nsize = data.GetPtrStringSize();

			bool passTrigger=false;
			for(int it=0; it< nsize; it++){
				std::string thisTrig= trigName[it];
				bool results = trigResult[it];
				//cout<<it<<"="<<thisTrig<<endl;
				// std::cout << thisTrig << " : " << results << std::endl;
				if( ((thisTrig.find("HLT_PFHT800")!= std::string::npos||
						thisTrig.find("HLT_PFHT650_WideJetMJJ900DEtaJJ1p5_v")!= std::string::npos||
						thisTrig.find("HLT_PFHT650_WideJetMJJ950DEtaJJ1p5_v")!= std::string::npos||
						thisTrig.find("HLT_AK8PFJet360_TrimMass30_v")!= std::string::npos||
						thisTrig.find("HLT_AK8PFHT700_TrimR0p1PT0p03Mass50_v")!= std::string::npos
						) && results==1)){
					passTrigger=true;
					break;
				}
			}
			if(!passTrigger && (nameRoot!=0))continue;
			nPass[1]++;
		
			int nFATJet         = data.GetInt("FATnJet");
			const int nJets=nFATJet;
			TClonesArray* fatjetP4 = (TClonesArray*) data.GetPtrTObject("FATjetP4");
			Float_t*  fatjetTau1 = data.GetPtrFloat("FATjetTau1");
			Float_t*  fatjetTau2 = data.GetPtrFloat("FATjetTau2");
			//Float_t*  fatjetTau4 = data.GetPtrFloat("FATjetTau4");
			Float_t*  fatjetCISVV2 = data.GetPtrFloat("FATjetCISVV2");
			Float_t*  fatjetPRmass = data.GetPtrFloat("FATjetPRmass");
			Float_t*  fatjetPRmassL2L3Corr = data.GetPtrFloat("FATjetPRmassL2L3Corr");
			Float_t*  fatjetSDmass = data.GetPtrFloat("FATjetSDmass");
			Int_t*   nSubSoftDropJet = data.GetPtrInt("FATnSubSDJet");
			vector<float>   *subjetSDCSV =  data.GetPtrVectorFloat("FATsubjetSDCSV");
			//  vector<float>   *subjetSDCSV =  data.GetPtrVectorFloat("FATsubjetSDCSV", nFATJet);
			vector<float>   *subjetSDPx  =  data.GetPtrVectorFloat("FATsubjetSDPx", nFATJet);
			vector<float>   *subjetSDPy  =  data.GetPtrVectorFloat("FATsubjetSDPy", nFATJet);
			vector<float>   *subjetSDPz  =  data.GetPtrVectorFloat("FATsubjetSDPz", nFATJet);
			vector<float>   *subjetSDE   =  data.GetPtrVectorFloat("FATsubjetSDE", nFATJet);
			vector<Int_t>   *FATsubjetSDHadronFlavor =  data.GetPtrVectorInt("FATsubjetSDHadronFlavor");
			//vector<bool>    &passFatJetLooseID = *((vector<bool>*) data.GetPtr("FATjetPassIDLoose"));
			vector<bool>    &FATjetPassIDTight = *((vector<bool>*) data.GetPtr("FATjetPassIDTight"));
			if(nJets<2)continue;
			//-----------------------------------------
			TLorentzVector* thisJet = (TLorentzVector*)fatjetP4->At(0);
			TLorentzVector* thatJet = (TLorentzVector*)fatjetP4->At(1);
			//2. Pt and tightId-----------------------------------------
			if(thisJet->Pt()<200)continue;
			if(thatJet->Pt()<200)continue;
			if(FATjetPassIDTight[0]==0)continue;
			if(FATjetPassIDTight[1]==0)continue;
			nPass[2]++;
			//3. Eta-----------------------------------------
			if(fabs(thisJet->Eta())>2.4)continue;
			if(fabs(thatJet->Eta())>2.4)continue;
			nPass[3]++;
			//4. DEta-----------------------------------------
			float dEta = fabs(thisJet->Eta()-thatJet->Eta());
			if(dEta>1.3)continue;
			nPass[4]++;
			//5. Mjj-----------------------------------------
			float mjj = (*thisJet+*thatJet).M();
			if(mjj<1000)continue;
			nPass[5]++;
			//6. fatjetPRmassL2L3Corr-----------------------------------------
			if(fatjetPRmassL2L3Corr[0]<105||fatjetPRmassL2L3Corr[0]>135)continue;
			if(fatjetPRmassL2L3Corr[1]<105||fatjetPRmassL2L3Corr[1]>135)continue;
			nPass[6]++;
			//7.-----------------------------------------
			double tau21_1=(fatjetTau2[0]/fatjetTau1[0]),
		           tau21_2=(fatjetTau2[1]/fatjetTau1[1]);
			if(tau21_1>0.75||tau21_2>0.75)continue;
			if(tau21_1>0.6 &&tau21_2>0.6) continue;
			nPass[7]++;
			
			bool isHPHP=0;
			if(tau21_1<0.6 && tau21_2<0.6 )isHPHP=1;
			
			if(nameRoot==2){
				//data:csc2015
				TString thisEvent;                                                   
				Int_t  runId = data.GetInt("runId");
				Int_t  lumiSection = data.GetInt("lumiSection");
				Int_t  eventId = data.GetInt("eventId");
				thisEvent.Form("%d:%d:%d",runId,lumiSection,eventId);                                                                                                                 
				if ( std::find(eventlist.begin(), eventlist.end(), thisEvent) != eventlist.end()){
					std::cout<<" match found to skip event "<<std::endl;
					continue;
				}                                                                              
				dataPassingcsc++;
			}
			
			
			//8.btag
			int nbtag=0;
			if(subjetSDCSV[0][0]>0.605)nbtag++;
			if(subjetSDCSV[0][1]>0.605)nbtag++;
			if(subjetSDCSV[1][0]>0.605)nbtag++;
			if(subjetSDCSV[1][1]>0.605)nbtag++;
		
			int THINnJet         = data.GetInt("THINnJet");
			TClonesArray* THINgenjetP4 = (TClonesArray*) data.GetPtrTObject("THINgenjetP4");
			vector<bool>    &THINjetPassIDTight = *((vector<bool>*) data.GetPtr("THINjetPassIDTight"));
			int AddTHINnJet=0;
			int AddTHINnJet2=0;
			for(int i=0;i<THINnJet;i++){
				if(THINjetPassIDTight[i]==0)continue;
				TLorentzVector* thisThinJet = (TLorentzVector*)THINgenjetP4->At(i);
				AddTHINnJet2++;
				if(thisThinJet->DeltaR(*thisJet)<1)continue;
				if(thisThinJet->DeltaR(*thatJet)<1)continue;
				if(thisThinJet->Pt()<30)continue;
				if(fabs(thisThinJet->Eta())<3)continue;
				AddTHINnJet++;
				//cout<<w<<",etr="<<jEntry<<","<<i<<","<<"1="<<thisThinJet->DeltaR(*thisJet)<<",2="<<thisThinJet->DeltaR(*thatJet)<<endl;
			}
			
			if(nbtag==3)th1[0]->Fill(AddTHINnJet);
			if(nbtag==4)th1[1]->Fill(AddTHINnJet);
			
			if(nbtag==3)th1[2]->Fill(AddTHINnJet2);
			if(nbtag==4)th1[3]->Fill(AddTHINnJet2);
		}
	}	
	cout<<"entries="<<total<<endl;	
	if(nameRoot==2)cout<<"dataPassingcsc="<<dataPassingcsc<<endl;
	for(int i=0;i<14;i++)cout<<"nPass["<<i<<"]="<<nPass[i]<<endl;
	
	TFile* outFile = new TFile(Form("root_files_addThinJet/%s_3.root",st2.data()),"recreate");
	if(nameRoot==0){
		for(int i=0;i<4;i++){
			th1[i]->Sumw2();
			th1[i]->Scale(2245.87*Xsec/total);
		}
	}
	for (int i=0;i<4;i++)th1[i]->Write();
	outFile->Close();
	
}
Ejemplo n.º 15
0
void AK8CorrBase(int wMs,int wM, string st,string st2,string option=""){	

	//1=signal ,0=QCD ,2=data
	int nameRoot=1;
	if((st2.find("QCD")!= std::string::npos)||
	(st2.find("bGen")!= std::string::npos)||
	(st2.find("bEnriched")!= std::string::npos))nameRoot=0;
	if(st2.find("data")!= std::string::npos)nameRoot=2;
	
	bool fixGen=0;
	if(st2.find("B1000")!= std::string::npos)fixGen=1;
	cout<<"nameRoot = "<<nameRoot<<endl;
	
	//option-----------------------------------------------------------
	
	int JESOption=0;
	if(option.find("JESUp")!= std::string::npos)JESOption=1;
	if(option.find("JESDown")!= std::string::npos)JESOption=2;
	cout<<"JESOption = "<<JESOption<<endl;
	
	
	TFile *f;
	TTree *tree;
	int nPass[20]={0};
	int total=0;
	
	TH1D* th1;
	th1=new TH1D("mass","mass",150,0,150);
	
	TH1D* th3;
	th3=new TH1D("mass","mass",1500,200,3200);
	
	double ptBins[14]={200,300,400,500,600,700,800,900,1000,1250,1500,1750,2000,2500};
	
	TH1D* th2[6][14];
	
	for(int i=0;i<14;i++){
		th2[0][i]=(TH1D*)th1->Clone(Form("genBarelMass%.0f",ptBins[i]));
		th2[1][i]=(TH1D*)th1->Clone(Form("genEndcapMass%.0f",ptBins[i]));
		th2[2][i]=(TH1D*)th1->Clone(Form("recoBarelMass%.0f",ptBins[i]));
		th2[3][i]=(TH1D*)th1->Clone(Form("recoEndcapMass%.0f",ptBins[i]));
		th2[4][i]=(TH1D*)th3->Clone(Form("ptBarel%.0f",ptBins[i]));
		th2[5][i]=(TH1D*)th3->Clone(Form("ptEndcap%.0f",ptBins[i]));
	}

	for(int i=0;i<14;i++){
		th2[0][i]->Sumw2();
		th2[1][i]->Sumw2();
		th2[2][i]->Sumw2();
		th2[3][i]->Sumw2();
		th2[4][i]->Sumw2();
		th2[5][i]->Sumw2();
	}
	
	//---------------------------------
	
	for (int w=wMs;w<wM;w++){
		if(w%20==0)cout<<w<<endl;
		
		if (nameRoot!=1)f = TFile::Open(Form("%s%d.root",st.data(),w));
		else f = TFile::Open(st.data());
		if (!f || !f->IsOpen())continue;
		
		TDirectory * dir;
		if (nameRoot!=1)dir = (TDirectory*)f->Get(Form("%s%d.root:/tree",st.data(),w));
		else dir = (TDirectory*)f->Get(Form("%s:/tree",st.data()));
		
		dir->GetObject("treeMaker",tree);
		TreeReader data(tree);
		total+=data.GetEntriesFast();
		for(Long64_t jEntry=0; jEntry<data.GetEntriesFast() ;jEntry++){
			if(jEntry%2)continue;
			data.GetEntry(jEntry);
			
			
			
			Int_t nGenPar        = data.GetInt("nGenPar");
			Int_t* genParId      = data.GetPtrInt("genParId");
			Int_t* genParSt      = data.GetPtrInt("genParSt");
			Int_t* genMomParId   = data.GetPtrInt("genMomParId");
			Int_t* genDa1      = data.GetPtrInt("genDa1");
			Int_t* genDa2      = data.GetPtrInt("genDa2");

			int genHIndex[2]={-1,-1};
			int genbIndex[2][2]={{-1,-1},
						{-1,-1}};		       

			for(int ig=0; ig < nGenPar; ig++){

				if(genParId[ig]!=25)continue;

				if(genHIndex[0]<0)
				{
				genHIndex[0]=ig;
				genbIndex[0][0]=genDa1[ig];
				genbIndex[0][1]=genDa2[ig];
				}

				else if(genHIndex[1]<0)
				{
				genHIndex[1]=ig;
				genbIndex[1][0]=genDa1[ig];
				genbIndex[1][1]=genDa2[ig];
				}

			}    

			if(genHIndex[0]<0 || genHIndex[1]<0)continue;
			if(genbIndex[0][0]<0 || genbIndex[0][1]<0)continue;
			if(genbIndex[1][0]<0 || genbIndex[1][1]<0)continue;

			nPass[0]++;

			if(genHIndex[0]==genHIndex[1])continue;
			nPass[1]++;

			TLorentzVector genH_l4[2];
			TLorentzVector genb_l4[2][2];
			TClonesArray* genParP4 = (TClonesArray*) data.GetPtrTObject("genParP4");
			
			

			for(int ih=0; ih<2; ih++)
			{
				genH_l4[ih] = *((TLorentzVector*)genParP4->At(genHIndex[ih]));
				for(int ib=0; ib<2; ib++)
				{
				genb_l4[ih][ib] = *((TLorentzVector*)genParP4->At(genbIndex[ih][ib]));
				}
				}


			
			
			TClonesArray* AK8PuppijetP4 = (TClonesArray*) data.GetPtrTObject("AK8PuppijetP4");

			// check matching first    
			bool findAK8Match=false;
			const float dRMax=0.4;
			const float dRbMax=0.8;
			int matchedHAK8JetIndex[2]={-1,-1};
		      int AK8nJet=data.GetInt("AK8PuppinJet");
			if(AK8nJet<2)continue;
			bool matchb=1;
			for(int ij=0; ij<AK8nJet; ij++)
			{
				TLorentzVector* thisJet = (TLorentzVector*)AK8PuppijetP4->At(ij);

				for(int jj=0; jj<AK8nJet; jj++)
				{

				if(ij==jj)continue;
				TLorentzVector* thatJet = (TLorentzVector*)AK8PuppijetP4->At(jj);
	    
				if(thisJet->DeltaR(genH_l4[0])<dRMax && 
					(!matchb || (matchb && 
						thisJet->DeltaR(genb_l4[0][0])<dRbMax && 
						thisJet->DeltaR(genb_l4[0][1])<dRbMax)) &&
					thatJet->DeltaR(genH_l4[1])<dRMax &&
					(!matchb || (matchb &&
						thatJet->DeltaR(genb_l4[1][0])<dRbMax &&
						thatJet->DeltaR(genb_l4[1][1])<dRbMax)))
					{
					
					if(ij<jj){
					matchedHAK8JetIndex[0]=ij;
					matchedHAK8JetIndex[1]=jj;
					}
					else
					{
					matchedHAK8JetIndex[0]=jj;
					matchedHAK8JetIndex[1]=ij;
					}
					findAK8Match=true;
					break;
					}

				if(findAK8Match)break;
	
				}	

				if(findAK8Match)break;

				}
	
			if(!findAK8Match)continue;
			
			
				
			
			
			Float_t*  AK8PuppijetGenSDmass;
			if(fixGen)AK8PuppijetGenSDmass= data.GetPtrFloat("AK8PuppijetSDmass");
			else 	AK8PuppijetGenSDmass= data.GetPtrFloat("AK8PuppijetGenSDmass");
			Float_t*  AK8PuppijetSDmass = data.GetPtrFloat("AK8PuppijetSDmass");
			int* AK8PuppinSubSDJet=data.GetPtrInt("AK8PuppinSubSDJet");
			
		
			for(int i=0; i<2;i++){
		
				
				int AK8jet=matchedHAK8JetIndex[i];
				
				TLorentzVector* thisAK8Jet = (TLorentzVector*)AK8PuppijetP4->At(AK8jet);
				
				if(thisAK8Jet->Pt()<200)continue;
				if(fabs(thisAK8Jet->Eta())>2.4)continue;
				if(AK8PuppinSubSDJet[AK8jet]!=2)continue;
				
				th1->Fill(AK8PuppijetGenSDmass[AK8jet]);
				
				for(int j=0;j<13;j++){
					if(thisAK8Jet->Pt()>ptBins[j] && thisAK8Jet->Pt()<ptBins[j+1]){
						
						if(fabs(thisAK8Jet->Eta())<1.3){
							th2[0][j]->Fill(AK8PuppijetGenSDmass[AK8jet]);
							th2[2][j]->Fill(AK8PuppijetSDmass[AK8jet]);
							th2[4][j]->Fill(thisAK8Jet->Pt());
						}
						else{
							th2[1][j]->Fill(AK8PuppijetGenSDmass[AK8jet]);
							th2[3][j]->Fill(AK8PuppijetSDmass[AK8jet]);
							th2[5][j]->Fill(thisAK8Jet->Pt());
						}
							
					}
				}
				
				if(thisAK8Jet->Pt()>ptBins[13]){
					if(fabs(thisAK8Jet->Eta())<1.3){
							th2[0][13]->Fill(AK8PuppijetGenSDmass[AK8jet]);
							th2[2][13]->Fill(AK8PuppijetSDmass[AK8jet]);
							th2[4][13]->Fill(thisAK8Jet->Pt());
						}
						else{
							th2[1][13]->Fill(AK8PuppijetGenSDmass[AK8jet]);
							th2[3][13]->Fill(AK8PuppijetSDmass[AK8jet]);
							th2[5][13]->Fill(thisAK8Jet->Pt());
						}
				}
				
			}
			
		}
	}	
	cout<<"entries="<<total<<endl;	
	
	
	TFile* outFile ;
	outFile= new TFile(Form("corr2/%s.root",st2.data()),"recreate");
	th1->Write();
	for(int i=0;i<14;i++){
		th2[0][i]->Write();
		th2[1][i]->Write();
		th2[2][i]->Write();
		th2[3][i]->Write();
		th2[4][i]->Write();
		th2[5][i]->Write();
	}
	outFile->Close();
}
void TMVARegressionApplication( int wMs,int wM, string st,string st2,string option="",TString myMethodList = "" ) 
{
   //---------------------------------------------------------------
   // This loads the library
   TMVA::Tools::Instance();

   // Default MVA methods to be trained + tested
   std::map<std::string,int> Use;

   // --- Mutidimensional likelihood and Nearest-Neighbour methods
   Use["PDERS"]           = 0;
   Use["PDEFoam"]         = 0; 
   Use["KNN"]             = 0;
   // 
   // --- Linear Discriminant Analysis
   Use["LD"]		        = 0;
   // 
   // --- Function Discriminant analysis
   Use["FDA_GA"]          = 0;
   Use["FDA_MC"]          = 0;
   Use["FDA_MT"]          = 0;
   Use["FDA_GAMT"]        = 0;
   // 
   // --- Neural Network
   Use["MLP"]             = 0; 
   // 
   // --- Support Vector Machine 
   Use["SVM"]             = 0;
   // 
   // --- Boosted Decision Trees
   Use["BDT"]             = 0;
   Use["BDTG"]            = 1;
   // ---------------------------------------------------------------

   std::cout << std::endl;
   std::cout << "==> Start TMVARegressionApplication" << std::endl;

   // Select methods (don't look at this code - not of interest)
   if (myMethodList != "") {
      for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) it->second = 0;

      std::vector<TString> mlist = gTools().SplitString( myMethodList, ',' );
      for (UInt_t i=0; i<mlist.size(); i++) {
         std::string regMethod(mlist[i]);

         if (Use.find(regMethod) == Use.end()) {
            std::cout << "Method \"" << regMethod << "\" not known in TMVA under this name. Choose among the following:" << std::endl;
            for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) std::cout << it->first << " ";
            std::cout << std::endl;
            return;
         }
         Use[regMethod] = 1;
      }
   }

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

   // --- Create the Reader object

   TMVA::Reader *reader = new TMVA::Reader( "!Color:!Silent" );    

   // Create a set of variables and declare them to the reader
   // - the variable names MUST corresponds in name and type to those given in the weight file(s) used
   //Float_t var1, var2;
   //reader->AddVariable( "var1", &var1 );
   //reader->AddVariable( "var2", &var2 );
   Float_t pt_AK8MatchedToHbb,eta_AK8MatchedToHbb,nsv_AK8MatchedToHbb,sv0mass_AK8MatchedToHbb,sv1mass_AK8MatchedToHbb,
   nch_AK8MatchedToHbb,nmu_AK8MatchedToHbb,nel_AK8MatchedToHbb,muenfr_AK8MatchedToHbb,emenfr_AK8MatchedToHbb;
   reader->AddVariable( "pt_AK8MatchedToHbb", &pt_AK8MatchedToHbb );
   reader->AddVariable( "eta_AK8MatchedToHbb", &eta_AK8MatchedToHbb );
   reader->AddVariable( "nsv_AK8MatchedToHbb", &nsv_AK8MatchedToHbb );
   reader->AddVariable( "sv0mass_AK8MatchedToHbb", &sv0mass_AK8MatchedToHbb );
   reader->AddVariable( "sv1mass_AK8MatchedToHbb", &sv1mass_AK8MatchedToHbb );
   reader->AddVariable( "nch_AK8MatchedToHbb", &nch_AK8MatchedToHbb );
   reader->AddVariable( "nmu_AK8MatchedToHbb", &nmu_AK8MatchedToHbb );
   reader->AddVariable( "nel_AK8MatchedToHbb", &nel_AK8MatchedToHbb );
   reader->AddVariable( "muenfr_AK8MatchedToHbb", &muenfr_AK8MatchedToHbb );
   reader->AddVariable( "emenfr_AK8MatchedToHbb", &emenfr_AK8MatchedToHbb );

   
   // Spectator variables declared in the training have to be added to the reader, too
   Float_t spec1,spec2;
    reader->AddSpectator( "spec1:=n_pv",  &spec1 );
   reader->AddSpectator( "spec2:=msoftdrop_AK8MatchedToHbb",  &spec2 );

   // --- Book the MVA methods

   TString dir    = "weights/";
   TString prefix = "TMVARegression";

   // Book method(s)
   for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) {
      if (it->second) {
         TString methodName = it->first + " method";
         TString weightfile = dir + prefix + "_" + TString(it->first) + ".weights.xml";
         reader->BookMVA( methodName, weightfile ); 
      }
   }
   
     TH1* hists[100];
   Int_t nhists = -1;
      for (std::map<std::string,int>::iterator it = Use.begin(); it != Use.end(); it++) {
         TH1* h = new TH1F( it->first.c_str(), TString(it->first) + " method", 100, -100, 600 );
         if (it->second) hists[++nhists] = h;
      }
      nhists++;
   
  //1=signal ,0=QCD ,2=data
	int nameRoot=1;
	if((st2.find("QCD")!= std::string::npos)||
	(st2.find("bGen")!= std::string::npos)||
	(st2.find("bEnriched")!= std::string::npos))nameRoot=0;
	if(st2.find("data")!= std::string::npos)nameRoot=2;
	cout<<"nameRoot = "<<nameRoot<<endl;
	
	//option-----------------------------------------------------------
	
	int JESOption=0;
	
   
   // Prepare input tree (this must be replaced by your data source)
   // in this example, there is a toy tree with signal and one with background events
   // we'll later on use only the "signal" events for the test in this example.
   //   
   TFile *f;
	TTree *tree;
	int nPass[20]={0};
	int total=0;
	double fixScaleNum[2]={0};
	
	TH1D* th1=new TH1D("a","a",150,50,200);	
	
	string massName[nMass]={"Thea","HCorr","Reg"};
	string catName[nCat]={"PP","PF","FP","FF"};
	string tau21Name[2]={"withTau21","woTau21"};
	
	string catNameShort[nCat]={"P","F"};
	string looseTight[2]={"loose","tight"};
	TF1 *fa[nMass][2][2][2];
	
	for(int i=0;i<nMass;i++){
		for(int j=0;j<2;j++){
			for(int k=0;k<2;k++){
				for(int w=0;w<2;w++){
					fa[i][j][k][w] = new TF1("fa","[0]+[1]*x+[2]*x*x+[3]*pow(x,3)",-3,3);
					ifstream myfile (Form("PFRatio/%s_%s_%s_%s.txt",looseTight[w].data(),massName[i].data(),catNameShort[j].data(),tau21Name[k].data()));
					double para[4];
					for(int m=0;m<4;m++){
						myfile>>para[m];
					}
					fa[i][j][k][w]->SetParameters(para[0],para[1],para[2],para[3]);
				}
			}
		}
	}
	
	/*
	TH1D* th2[nMass][nCat][2];
	TH1D* th3[nMass][nCat][2];
	for(int i=0;i<nMass;i++){
		for(int j=0;j<nCat;j++){
			for(int k=0;k<2;k++){
				th2[i][j][k]=(TH1D*)th1->Clone(Form("loose_%s_%s_%s",massName[i].data(),catName[j].data(),tau21Name[k].data()));
				th3[i][j][k]=(TH1D*)th1->Clone(Form("tight_%s_%s_%s",massName[i].data(),catName[j].data(),tau21Name[k].data()));
				
				th2[i][j][k]->Sumw2();
				th3[i][j][k]->Sumw2();
			}
		}
	}
	*/
	TH1D* th2d[14];
	
	th2d[0]=new TH1D("0a","0a",4000,1000,5000);	
	th2d[1]=new TH1D("0c","0c",4000,1000,5000);
	th2d[2]=new TH1D("1a","1a",4000,1000,5000);	
	th2d[3]=new TH1D("1c","1c",4000,1000,5000);	
	th2d[4]=new TH1D("2a","2a",4000,1000,5000);	
	th2d[5]=new TH1D("2b","2b",4000,1000,5000);	
	th2d[6]=new TH1D("2d","2d",4000,1000,5000);	
	
	
	th2d[7]=new TH1D("0aL","0aL",4000,1000,5000);		
	th2d[8]=new TH1D("0cL","0cL",4000,1000,5000);		
	th2d[9]=new TH1D("1aL","1aL",4000,1000,5000);		
	th2d[10]=new TH1D("1cL","1cL",4000,1000,5000);		
	th2d[11]=new TH1D("2aL","2aL",4000,1000,5000);	
	th2d[12]=new TH1D("2bL","2bL",4000,1000,5000);	
	th2d[13]=new TH1D("2dL","2dL",4000,1000,5000);	
		
	
		
	
	//int nWidth=5,nBmin=11;
	 int width [nWidth]={25,30,35,40};
	 int bmin[nBmin]={100,105,110,115};
	 
	
	 TH1D* th3d[14][nWidth][nBmin][2];
	 TH1D* th3f[14][nWidth][nBmin][2];
	 TH1D* th3v[14][nWidth][nBmin][2];
	 
	 for(int i=0;i<nWidth;i++){
		 for(int j=0;j<nBmin;j++){
			 for(int k=0;k<2;k++){
				  for(int l=0;l<14;l++){
					  th3d[l][i][j][k]=(TH1D*) th2d[l]->Clone(Form("%s_%d_%d_%s",th2d[l]->GetTitle(),bmin[j],width[i]+bmin[j],tau21Name[k].data()));
					  th3f[l][i][j][k]=(TH1D*) th2d[l]->Clone(Form("fill_%s_%d_%d_%s",th2d[l]->GetTitle(),bmin[j],width[i]+bmin[j],tau21Name[k].data()));
					  th3v[l][i][j][k]=(TH1D*) th2d[l]->Clone(Form("valid_%s_%d_%d_%s",th2d[l]->GetTitle(),bmin[j],width[i]+bmin[j],tau21Name[k].data()));
					   
					  th3d[l][i][j][k]->Sumw2();
					  th3f[l][i][j][k]->Sumw2();
					  th3v[l][i][j][k]->Sumw2();
				  }
			 }
		 }
	 }
   
   for (int w=wMs;w<wM;w++){
		if(w%20==0)cout<<w<<endl;
		
		if (nameRoot!=1)f = TFile::Open(Form("%s%d.root",st.data(),w));
		else f = TFile::Open(st.data());
		if (!f || !f->IsOpen())continue;
		
		TDirectory * dir;
		if (nameRoot!=1)dir = (TDirectory*)f->Get(Form("%s%d.root:/tree",st.data(),w));
		else dir = (TDirectory*)f->Get(Form("%s:/tree",st.data()));
		
		dir->GetObject("treeMaker",tree);
		
		//tree=(TTree*)f->Get("treeMaker");
		TreeReader data(tree);
		total+=data.GetEntriesFast();
		for(Long64_t jEntry=0; jEntry<data.GetEntriesFast() ;jEntry++){
			data.GetEntry(jEntry);
			
			
			
			Int_t nVtx        = data.GetInt("nVtx");
			//0. has a good vertex
			if(nVtx<1)continue;
			nPass[0]++;
			
			//1.trigger
			std::string* trigName = data.GetPtrString("hlt_trigName");
		 	vector<bool> &trigResult = *((vector<bool>*) data.GetPtr("hlt_trigResult"));
			bool passTrigger=false;
			for(int it=0; it< data.GetPtrStringSize();it++){
				std::string thisTrig= trigName[it];
				bool results = trigResult[it];
				if( ((thisTrig.find("HLT_PFHT800")!= std::string::npos||
					thisTrig.find("HLT_AK8DiPFJet300_200_TrimMass30_BTagCSV_p20")!= std::string::npos
						) && results==1)){
					passTrigger=true;
					break;
				}
			}
			if(!passTrigger && nameRoot==2)continue;
			nPass[1]++;

			const int nAK8Jet=data.GetInt("AK8PuppinJet");
			//2.nJets
			if(nAK8Jet<2)continue;nPass[2]++;
			int* AK8PuppinSubSDJet=data.GetPtrInt("AK8PuppinSubSDJet");
			if(AK8PuppinSubSDJet[0]!=2||AK8PuppinSubSDJet[1]!=2)continue;
			TClonesArray* AK8PuppijetP4 = (TClonesArray*) data.GetPtrTObject("AK8PuppijetP4");
			float*  AK8PuppijetCorrUncUp = data.GetPtrFloat("AK8PuppijetCorrUncUp"); 
			float*  AK8PuppijetCorrUncDown = data.GetPtrFloat("AK8PuppijetCorrUncDown"); 
			TLorentzVector* thisJet ,* thatJet;
			
			
			thisJet=(TLorentzVector*)AK8PuppijetP4->At(0);
			thatJet=(TLorentzVector*)AK8PuppijetP4->At(1);
			
			//3. Pt 
			if(thisJet->Pt()>99998 ||thatJet->Pt()>99998 )continue;
			if(thisJet->Pt()<300)continue;
			if(thatJet->Pt()<300)continue;
			nPass[3]++;
			//4tightId-----------------------------------------
			vector<bool>    &AK8PuppijetPassIDTight = *((vector<bool>*) data.GetPtr("AK8PuppijetPassIDTight"));
			if(AK8PuppijetPassIDTight[0]==0)continue;
			if(AK8PuppijetPassIDTight[1]==0)continue;
			Float_t*  AK8PuppijetCEmEF = data.GetPtrFloat("AK8PuppijetCEmEF");
			Float_t*  AK8PuppijetMuoEF = data.GetPtrFloat("AK8PuppijetMuoEF");
			if(AK8PuppijetMuoEF[0]>0.8)continue;
			if(AK8PuppijetCEmEF[0]>0.9)continue;
			if(AK8PuppijetMuoEF[1]>0.8)continue;
			if(AK8PuppijetCEmEF[1]>0.9)continue;
			nPass[4]++;
			//5. Eta-----------------------------------------
			if(fabs(thisJet->Eta())>2.4)continue;
			if(fabs(thatJet->Eta())>2.4)continue;
			nPass[5]++;
			//6. DEta-----------------------------------------
			float dEta = fabs(thisJet->Eta()-thatJet->Eta());
			if(dEta>1.3)continue;
			nPass[6]++;
			//7. Mjj-----------------------------------------
			//float mjjRed = (*thisJet+*thatJet).M()+250-thisJet->M()-thatJet->M();
			//if(mjjRed<1000)continue;
			nPass[7]++;
			//8. fatjetPRmassL2L3Corr-----------------------------------------
			nPass[8]++;
			//9.-----------------------------------------
		
			
    
			Float_t*  AK8Puppijet_DoubleSV = data.GetPtrFloat("AK8Puppijet_DoubleSV");
			
			
			int looseStat=-1;
			int tightStat=-1;
			
			if(AK8Puppijet_DoubleSV[0]>0.3 && AK8Puppijet_DoubleSV[1]>0.3)looseStat=0;
			else if(AK8Puppijet_DoubleSV[0]>0.3 && AK8Puppijet_DoubleSV[1]<0.3)looseStat=1;
			else if(AK8Puppijet_DoubleSV[0]<0.3 && AK8Puppijet_DoubleSV[1]>0.3)looseStat=2;
			else looseStat=3;
			
			if(AK8Puppijet_DoubleSV[0]>0.8 && AK8Puppijet_DoubleSV[1]>0.8)tightStat=0;
			else if(AK8Puppijet_DoubleSV[0]>0.8 && AK8Puppijet_DoubleSV[1]<0.8)tightStat=1;
			else if(AK8Puppijet_DoubleSV[0]<0.3 && AK8Puppijet_DoubleSV[1]>0.8)tightStat=2;
			else if(AK8Puppijet_DoubleSV[0]<0.3 && AK8Puppijet_DoubleSV[1]<0.8)tightStat=3;
			else tightStat=-1;
			
			
			double varTemp[2];
			
			Float_t*  AK8PuppijetSDmass = data.GetPtrFloat("AK8PuppijetSDmass");
			
			if(AK8PuppijetSDmass[0]<50||AK8PuppijetSDmass[1]<50)continue;
			
			Int_t* AK8Puppijet_nSV=data.GetPtrInt("AK8Puppijet_nSV");
			vector<float>   *AK8Puppijet_SVMass  =  data.GetPtrVectorFloat("AK8Puppijet_SVMass");
			int nEle= data.GetInt("nEle");
			int nMu=data.GetInt("nMu");
			Float_t*  AK8PuppijetEleEF = data.GetPtrFloat("AK8PuppijetEleEF");
			//Float_t*  AK8PuppijetMuoEF = data.GetPtrFloat("AK8PuppijetMuoEF");
			Int_t* AK8PuppijetCMulti=data.GetPtrInt("AK8PuppijetCMulti");
			Int_t* AK8PuppijetEleMulti=data.GetPtrInt("AK8PuppijetEleMulti");
			Int_t* AK8PuppijetMuoMulti=data.GetPtrInt("AK8PuppijetMuoMulti");
			
			for(int i=0; i<2;i++){
		
				TLorentzVector* thisAK8Jet ;
				
				if(i==1)thisAK8Jet=thatJet;
				else thisAK8Jet=thisJet;
				
				
				pt_AK8MatchedToHbb=thisAK8Jet->Pt();
				eta_AK8MatchedToHbb=thisAK8Jet->Eta();
				nsv_AK8MatchedToHbb=AK8Puppijet_nSV[i];
				sv0mass_AK8MatchedToHbb=AK8Puppijet_SVMass[i][0];
				sv1mass_AK8MatchedToHbb=AK8Puppijet_SVMass[i][1];
				nmu_AK8MatchedToHbb=AK8PuppijetMuoMulti[i];
				nel_AK8MatchedToHbb=AK8PuppijetEleMulti[i];
				muenfr_AK8MatchedToHbb=AK8PuppijetMuoEF[i];
				nch_AK8MatchedToHbb=AK8PuppijetCMulti[i];
				emenfr_AK8MatchedToHbb=AK8PuppijetEleEF[i];
				spec1=nVtx;
				spec2=AK8PuppijetSDmass[i];
				Float_t val ;
				for (Int_t ih=0; ih<nhists; ih++) {
				TString title = hists[ih]->GetTitle();
				val= (reader->EvaluateRegression( title ))[0];
				}
				varTemp[i]=val;
			}
			
			double PUPPIweight[2]={0};
			PUPPIweight[0]=getPUPPIweight(thisJet->Pt(),thisJet->Eta());
			PUPPIweight[1]=getPUPPIweight(thatJet->Pt(),thatJet->Eta());
			
			double PUPPIweightThea[2]={0};
			PUPPIweightThea[0]=getPUPPIweight_o(thisJet->Pt(),thisJet->Eta());
			PUPPIweightThea[1]=getPUPPIweight_o(thatJet->Pt(),thatJet->Eta());
	
			double Mjja= ((*thisJet)+(*thatJet)).M()+250
									-((*thisJet)).M()-((*thatJet)).M();
									
			TLorentzVector  thisJetReg, thatJetReg;
			thisJetReg=(*thisJet)*varTemp[0];
			thatJetReg=(*thatJet)*varTemp[1];
			
			double Mjjb= (thisJetReg+thatJetReg).M()+250
									-(thisJetReg).M()-(thatJetReg).M();
			
			double PUPPIweightOnRegressed[2]={0};			
			PUPPIweightOnRegressed[0]=getPUPPIweightOnRegressed(thisJetReg.Pt(),thisJetReg.Eta());
			PUPPIweightOnRegressed[1]=getPUPPIweightOnRegressed(thatJetReg.Pt(),thatJetReg.Eta());
			
			vector<float>   *subjetSDPx  =  data.GetPtrVectorFloat("AK8PuppisubjetSDPx");
			vector<float>   *subjetSDPy  =  data.GetPtrVectorFloat("AK8PuppisubjetSDPy");
			vector<float>   *subjetSDPz  =  data.GetPtrVectorFloat("AK8PuppisubjetSDPz");
			vector<float>   *subjetSDE   =  data.GetPtrVectorFloat("AK8PuppisubjetSDE");
			vector<float>   *AK8PuppisubjetSDRawFactor =  data.GetPtrVectorFloat("AK8PuppisubjetSDRawFactor");
			
			TLorentzVector thisSDJet, thatSDJet;
			TLorentzVector* subjetP4[2][2];
			for(int i=0;i<2;i++){
				for(int j=0;j<2;j++){
					subjetP4[i][j]=new TLorentzVector(0,0,0,0);
					subjetP4[i][j]->SetPxPyPzE(subjetSDPx[i][j],subjetSDPy[i][j],subjetSDPz[i][j],subjetSDE[i][j]);
				//	subjetP4[i][j]*=AK8PuppisubjetSDRawFactor[i][j];
				}
			}
			thisSDJet=(*subjetP4[0][0])*AK8PuppisubjetSDRawFactor[0][0]+(*subjetP4[0][1])*AK8PuppisubjetSDRawFactor[0][1];
			thatSDJet=(*subjetP4[1][0])*AK8PuppisubjetSDRawFactor[1][0]+(*subjetP4[1][1])*AK8PuppisubjetSDRawFactor[1][1];
			//thatSDJet=(*subjetP4[1][0])+(*subjetP4[1][1]);
			TLorentzVector thisSDJetReg, thatSDJetReg;			
			thisSDJetReg=	thisSDJet*varTemp[0]*PUPPIweightOnRegressed[0];			
			thatSDJetReg=	thatSDJet*varTemp[1]*PUPPIweightOnRegressed[1];			
			
			
			//double Mjjc= ((thisSDJet)+(thatSDJet)).M()+250
			//						-((thisSDJet)).M()-((thatSDJet)).M();
			
			
			double Mjjd= ((thisSDJet)+(thatSDJet)).M()+250
									-((thisSDJet)).M()-((thatSDJet)).M();
			
			
			Float_t*  AK8PuppijetTau1 = data.GetPtrFloat("AK8PuppijetTau1");
			Float_t*  AK8PuppijetTau2 = data.GetPtrFloat("AK8PuppijetTau2");
			double puppiTau21[2];
			puppiTau21[0]=(AK8PuppijetTau2[0]/AK8PuppijetTau1[0]),puppiTau21[1]=(AK8PuppijetTau2[1]/AK8PuppijetTau1[1]);
			
			double mass_j0,mass_j1,MjjLoop;
			int massCat;
			for(int k=0;k<7;k++){
				
				if(k==0||k==2||k==4){
					if(thisJet->Pt()<300)continue;
					if(thatJet->Pt()<300)continue;
				}
				else if (k==1){
					if((thisSDJet*PUPPIweightThea[0]).Pt()<300)continue;
					if((thatSDJet*PUPPIweightThea[1]).Pt()<300)continue;
				}
				else if (k==3){
					if((thisSDJet*PUPPIweight[0]).Pt()<300)continue;
					if((thatSDJet*PUPPIweight[1]).Pt()<300)continue;
				}
				else if (k==5){
					if(thisJetReg.Pt()<300)continue;
					if(thatJetReg.Pt()<300)continue;
				}
				else{
					if(thisSDJetReg.Pt()<300)continue;
					if(thatSDJetReg.Pt()<300)continue;
				}
				
				
				if(k==0||k==1){
					mass_j0=AK8PuppijetSDmass[0]*PUPPIweightThea[0];
					mass_j1=AK8PuppijetSDmass[1]*PUPPIweightThea[1];
					massCat=0;
				}
				else if (k==2||k==3){
					mass_j0=AK8PuppijetSDmass[0]*PUPPIweight[0];
					mass_j1=AK8PuppijetSDmass[1]*PUPPIweight[1];
					massCat=1;
				}
				
				else{
					mass_j0=AK8PuppijetSDmass[0]*varTemp[0]*PUPPIweightOnRegressed[0];
					mass_j1=AK8PuppijetSDmass[1]*varTemp[1]*PUPPIweightOnRegressed[1];
					massCat=2;
				} 
				
				
				
				if(k==0||k==2||k==4)MjjLoop=Mjja;
				else if (k==1)MjjLoop=((thisSDJet)*PUPPIweightThea[0]+(thatSDJet)*PUPPIweightThea[1]).M()+250-((thisSDJet)*PUPPIweightThea[0]).M()-((thatSDJet)*PUPPIweightThea[1]).M();
				else if (k==3)MjjLoop=((thisSDJet)*PUPPIweight[0]+(thatSDJet)*PUPPIweight[1]).M()+250-((thisSDJet)*PUPPIweight[0]).M()-((thatSDJet)*PUPPIweight[1]).M();
				else if (k==5)MjjLoop=Mjjb;
				else MjjLoop=Mjjd;
				
				
				//cout<<mass_j0<<","<<mass_j1<<",k="<<k<<endl;
				for(int i=0;i<nWidth;i++){
					for(int j=0;j<nBmin;j++){
						if(mass_j0<bmin[j] ||mass_j0>width[i]+bmin[j]
						||mass_j1<bmin[j] ||mass_j1>width[i]+bmin[j] )continue;
						
						for(int m=0;m<2;m++){
							if(m==0 && (puppiTau21[0]>0.6 || puppiTau21[1]>0.6))continue;
							double tightPFRatio=0,loosePFRatio=0;
							tightPFRatio=fa[massCat][0][m][1]->Eval(mass_j0);
							loosePFRatio=fa[massCat][0][m][0]->Eval(mass_j0);
							if(tightStat==0){
								th3d[k][i][j][m]->Fill(MjjLoop);
							}
							else if (tightStat==1){
								th3f[k][i][j][m]->Fill(MjjLoop);
							}
							else if(tightStat==3){
								tightPFRatio=fa[massCat][1][m][1]->Eval(mass_j0);
								th3v[k][i][j][m]->Fill(MjjLoop,tightPFRatio);
							}
							
							if(looseStat==0 && tightStat!=0){
								th3d[k+7][i][j][m]->Fill(MjjLoop);
							}
							else if (looseStat==1){
								th3f[k+7][i][j][m]->Fill(MjjLoop);
							}
							else if(looseStat==3){
								loosePFRatio=fa[massCat][1][m][0]->Eval(mass_j0);
								th3v[k+7][i][j][m]->Fill(MjjLoop,loosePFRatio);
							}
						}
						
					}
				}
			}
			
			
			
		}
	}	
	
	for(int i=0;i<10;i++)cout<<"npass["<<i<<"]="<<nPass[i]<<endl;
   

	TFile* outFile;//= new TFile(Form("PFRatio/%s.root",st2.data()),"recreate");
	outFile= new TFile(Form("MjjVC/%s.root",st2.data()),"recreate");
	for(int i=0;i<nWidth;i++){
		 for(int j=0;j<nBmin;j++){
			 for(int k=0;k<2;k++){
				  for(int l=0;l<14;l++){
					  th3d[l][i][j][k]->Write();
					  th3f[l][i][j][k]->Write();
					  th3v[l][i][j][k]->Write();
					  
				  }
			 }
		 }
	 }
	outFile->Close();
	
	for(int i=0;i<nWidth;i++){
		 for(int j=0;j<nBmin;j++){
			 for(int k=0;k<2;k++){
				  for(int l=0;l<14;l++){
					  delete th3d[l][i][j][k];
					  delete th3f[l][i][j][k];
					  delete th3v[l][i][j][k];
					  
				  }
			 }
		 }
	 }
  
   delete reader;
    
   
}
Ejemplo n.º 17
0
void optimization0803(){

  

  TH1F * th1 =new TH1F("HMass","HMass",600,0,600); 
  TH1F * th2 =new TH1F("Pt of good","Pt of good",2000,0,2000); 
  TH1F * th3 =new TH1F("Pt of bad","P of bad",2000,0,2000);
  TH1F * thr =new TH1F("Dr of good","deltaR of good",50,0,3);
  TH1F * thr2 =new TH1F("Dr of bad","deltaR of bad",50,0,3);

  //DY bkg
  // TString endfix ="DYBkg";
  // double scaleF=0;
  // double xsecF=2008.4;
  // for(int w=1;w<363;w++){
  //   f = TFile::Open(Form("/data7/khurana/NCUGlobalTuples/SPRING15/DYJetsToLL_M-50_TuneCUETP8M1_13TeV-amcatnloFXFX-pythia8/crab_DYJetsToLL_M-50_TuneCUETP8M1_13TeV-amcatnloFXFX-pythia8_ForEIKO/150729_202330/0000/NCUGlobalTuples_%d.root",w));
  //   if (!f || !f->IsOpen())continue;
  //   TDirectory * dir = (TDirectory*)f->Get(Form("/data7/khurana/NCUGlobalTuples/SPRING15/DYJetsToLL_M-50_TuneCUETP8M1_13TeV-amcatnloFXFX-pythia8/crab_DYJetsToLL_M-50_TuneCUETP8M1_13TeV-amcatnloFXFX-pythia8_ForEIKO/150729_202330/0000/NCUGlobalTuples_%d.root:/tree",w));
  //   dir->GetObject("treeMaker",tree);


  //BulkGravitonZlepZqq  noCleaning_BulkGravToZZToZlepZhad_narrow_M-1000_13TeV-madgraph.root
   string  masspoint[13]={"600","800","1000","1200","1400","1600","1800","2000","2500","3000","3500","4000","4500"};
   double xsecFB[13]={0.046310769831789535,0.010953371285280107,0.0033153186581553304,0.0011796819730577413,0.0004688386674106958,0.00025472097,0.00007503744,0.00004542880185027153,8.614571731526816e-6,1.9201182127764607e-6,4.25018556e-7,9.40119436e-8,2.08241719e-8};
  double xsecFB2[13]={0.184219,0.142802,0.125936,0.117445,0.112554,0.109472,0.101401,0.10594,0.103732,0.102549,0.101841,0.101384,0.100927};
     for (int massP=0;massP<13;massP++){
       TString endfix =Form("BulkGravitonZlepZqq-%s",masspoint[massP].data());
       double scaleF=0;
       double xsecF=xsecFB[massP]*xsecFB2[massP]*0.047063412;
      for(int w=1;w<2;w++){
  	 f = TFile::Open(Form("/data2/syu/13TeV/BulkGravitonZlepZqq/noCleaning_BulkGravToZZToZlepZhad_narrow_M-%s_13TeV-madgraph.root",masspoint[massP].data()));
  	 if (!f || !f->IsOpen())continue;
  	 TDirectory * dir = (TDirectory*)f->Get(Form("/data2/syu/13TeV/BulkGravitonZlepZqq/noCleaning_BulkGravToZZToZlepZhad_narrow_M-%s_13TeV-madgraph.root:/tree",masspoint[massP].data()));
   	 dir->GetObject("treeMaker",tree);


  //Signal

   // string  masspoint[13]={"600","800","1000","1200","1400","1600","1800","2000","2500","3000","3500","4000","4500"};
   // string  crabInf[13]={"150729_212416","150729_212459","150729_211555","150729_211640","150729_211727","150729_211727","150729_211855","150729_211940","150729_212023","150729_212110","150729_212159","150729_212245","150729_212331"};
   // for (int massP=0;massP<13;massP++){
   // TString endfix =Form("signal-%s",,masspoint[massP].data());
   // for(int w=1;w<3;w++){
   //   f = TFile::Open(Form("/data7/khurana/NCUGlobalTuples/SPRING15/ZPrimeSignal/ZprimeToZhToZlephbb_narrow_M-%s_13TeV-madgraph/crab_ZprimeToZhToZlephbb_narrow_M-%s_13TeV-madgraph/%s/0000/NCUGlobalTuples_%d.root",masspoint[massP].data(),masspoint[massP].data(),crabInf[massP].data(),w));
   // if (!f || !f->IsOpen())continue;
   // TDirectory * dir = (TDirectory*)f->Get(Form("/data7/khurana/NCUGlobalTuples/SPRING15/ZPrimeSignal/ZprimeToZhToZlephbb_narrow_M-%s_13TeV-madgraph/crab_ZprimeToZhToZlephbb_narrow_M-%s_13TeV-madgraph/%s/0000/NCUGlobalTuples_%d.root:/tree",masspoint[massP].data(),masspoint[massP].data(),crabInf[massP].data(),w));
   // dir->GetObject("treeMaker",tree);

  cout<<w<<endl;

  TreeReader data(tree);
  //data.Print();
  Long64_t nLepton[3]={0};
  Long64_t nTotal=0;
  Long64_t nPass[20]={0};
  ofstream fout;
  fout.open("ele_Eiko.txt");

  //Event loop
  for(Long64_t jEntry=0; jEntry<data.GetEntriesFast() ;jEntry++){

    if (jEntry % 50000 == 0)
      fprintf(stderr, "Processing event %lli of %lli\n", jEntry + 1, data.GetEntriesFast());

    data.GetEntry(jEntry);
    nTotal ++;
    
    Int_t nGenPar        = data.GetInt("nGenPar");
    Int_t* genParId      = data.GetPtrInt("genParId");
    Int_t* genParSt      = data.GetPtrInt("genParSt");
    Int_t* genMomParId   = data.GetPtrInt("genMomParId");
    Int_t* genDa1      = data.GetPtrInt("genDa1");
    Int_t* genDa2      = data.GetPtrInt("genDa2");
    TClonesArray* genParP4 = (TClonesArray*) data.GetPtrTObject("genParP4");

    bool hasElectron=false;

    for(int ig=0; ig < nGenPar; ig++){

        int pid = abs(genParId[ig]);
        if(pid!=11)continue;
        int momId = abs(genMomParId[ig]);
        if(
            momId!=23 &&
            momId!=9000001 &&
            momId!=pid)
        continue;
        hasElectron=true;
        if(hasElectron)break;

    }

    if(!hasElectron)continue;
    nPass[0]++;

    // bool hasHadron=false;

    // for(int ig=0; ig < nGenPar; ig++){

    //     int pid = abs(genParId[ig]);
    //     //if(pid!=11)continue;
    //     int momId = abs(genMomParId[ig]);
    //     if(
    //         momId!=25 &&
    //         momId!=9000001 &&
    //         momId!=pid)
    //     continue;
    //     hasHadron=true;
    //     if(hasHadron)break;


    // }
    


    // if(!hasHadron)continue;
    // nPass[1]++;
  
    TLorentzVector* thisB ,* thatB;
    bool isThisB=0,isThatB=0;
    vector<int> thisBArray;

    for(int ig=0; ig < nGenPar; ig++){
      if(isThisB && isThatB)continue;
        int pid = abs(genParId[ig]);
        int momId = abs(genMomParId[ig]);
        if(
            momId!=25 &&
            momId!=9000001 &&
            momId!=pid)
        continue;
	if (pid==5)thisBArray.push_back(ig);
        if (pid==5 && !isThisB){
	  thisB= (TLorentzVector*)genParP4->At(ig);
	  isThisB=1;
	  continue;
	}
	if(pid==5 && isThisB && !isThatB){
	  thatB= (TLorentzVector*)genParP4->At(ig);
          isThatB=1;
	}
	

    }
    //if (thisBArray.size()!=2)cout<<"thisBArray.size()="<<thisBArray.size()<<" , entry="<<jEntry<<endl;

     
    std::string* trigName = data.GetPtrString("hlt_trigName");
    vector<bool> &trigResult = *((vector<bool>*) data.GetPtr("hlt_trigResult"));
    const Int_t nsize = data.GetPtrStringSize();

    bool passTrigger=false;
    for(int it=0; it< nsize; it++)
      {
 	std::string thisTrig= trigName[it];
 	bool results = trigResult[it];

	// std::cout << thisTrig << " : " << results << std::endl;
	
 	if( (thisTrig.find("HLT_Ele105")!= std::string::npos && results==1)
	    ||
	    (thisTrig.find("HLT_Mu45")!= std::string::npos && results==1)
	    )
 	  {
 	    passTrigger=true;
 	    break;
 	  }


      }


    if(!passTrigger)continue;
    nPass[2]++;

    

    Int_t nVtx        = data.GetInt("nVtx");
    if(nVtx<1)continue;
    nPass[3]++;

    Int_t nEle         = data.GetInt("nEle");
    Int_t run          = data.GetInt("runId");
    Int_t lumi         = data.GetInt("lumiSection");
    Int_t event        = data.GetInt("eventId");
    vector<bool> &passHEEPID = *((vector<bool>*) data.GetPtr("eleIsPassHEEPNoIso"));
    TClonesArray* eleP4 = (TClonesArray*) data.GetPtrTObject("eleP4");
    Float_t* eleSCEta         = data.GetPtrFloat("eleScEta");
    Float_t* eleMiniIso       = data.GetPtrFloat("eleMiniIso");
    Int_t*   eleCharge        = data.GetPtrInt("eleCharge");

    bool findEPair=false;
    TLorentzVector l4_Z(0,0,0,0);
    std::vector<int> myElectrons;

    // select_electrons(data, myElectrons);

    // select good electrons

    for(int ie=0; ie< nEle; ie++)
      {

    	TLorentzVector* thisEle = (TLorentzVector*)eleP4->At(ie);

    	if(fabs(thisEle->Eta())>2.5)continue;

    	if(! (fabs(eleSCEta[ie])<1.442 || fabs(eleSCEta[ie])>1.566))continue;
    	
    	if(thisEle->Pt() < 115)continue;

    	if(!passHEEPID[ie])continue;
    	
    	if(eleMiniIso[ie]>0.1)continue;

    	myElectrons.push_back(ie);
      }

    TLorentzVector * checkThisEle, * checkThatEle;

    for(unsigned int i=0; i< myElectrons.size(); i++)
      {
	int ie = myElectrons[i];
	TLorentzVector* thisEle = (TLorentzVector*)eleP4->At(ie);

	for(unsigned int j=0; j< i; j++)
	  {
	    int je= myElectrons[j];

	    if(eleCharge[ie]*eleCharge[je]>0)continue;

	    TLorentzVector* thatEle = (TLorentzVector*)eleP4->At(je);

	    Float_t mll  = (*thisEle+*thatEle).M();
	    Float_t ptll = (*thisEle+*thatEle).Pt();
	    

	    if(mll<70 || mll>110)continue;
	    if(ptll<200)continue;

	    if(!findEPair){
	      l4_Z=(*thisEle+*thatEle);
	      checkThisEle = thisEle;
              checkThatEle = thatEle;
	    }
	    findEPair=true;
	  }	
      }

    if(!findEPair)
      continue;
    nPass[4]++;

    //cout<<"a"<<jEntry<<endl;

    Int_t nJet         = data.GetInt("FATnJet");
    TClonesArray* jetP4 = (TClonesArray*) data.GetPtrTObject("FATjetP4");
    Float_t*  jetSDmass = data.GetPtrFloat("FATjetSDmass");

    TLorentzVector l4_leadingJet(0,0,0,0);
    bool findAJet=false;
    bool goodJet=0;



    for(int ij=0; ij<nJet; ij++)
      {
	
	TLorentzVector* thisJet = (TLorentzVector*)jetP4->At(ij);

	//if(jetSDmass[ij]<50 || jetSDmass[ij]>110)continue;
        if (thisJet->DeltaR(*checkThisEle)<0.8)continue;
        if (thisJet->DeltaR(*checkThatEle)<0.8)continue;
        if (thisJet->Pt()<20 || thisJet->Eta()>2.4)continue;
        bool checkMyEle=0;
        for (unsigned int k=0;k<myElectrons.size();k++){
          TLorentzVector* thisEle = (TLorentzVector*)eleP4->At(myElectrons[k]);
	  if (thisJet->DeltaR(*thisEle)<0.8)checkMyEle=1;
	}
	if (checkMyEle)continue;
        if (jetSDmass[ij]<20||jetSDmass[ij]>220)continue;
	if(!findAJet){
	  l4_leadingJet = *thisJet;
          th1->Fill(jetSDmass[ij]);
          if(jetSDmass[ij]<20){
	    th3->Fill(thisJet->Pt());
	    //thr2->Fill(thisB->DeltaR(*thatB));
	  }
	  else {
	    //thr->Fill(thisB->DeltaR(*thatB));
	    th2->Fill(thisJet->Pt());
	  }
	  //if (thisJet->DeltaR(*thisB)<0.8)goodJet=1;
          //else if (thisJet->DeltaR(*thatB)<0.8)goodJet=1;
	}
	//cout<<"b"<<endl;
	findAJet=true;
      }
    
    
    if(!findAJet)
      continue;
    nPass[5]++;
    //if(!goodJet)l4_leadingJet.Print();



    Float_t MGrav = (l4_leadingJet + l4_Z).M();
    if(MGrav<400)continue;
    nPass[6]++;

    fout << run << " " << lumi << " " << event << endl;
    

  } // end of loop over entries

  fout.close();
  std::cout << "nTotal    = " << nTotal << std::endl;
  for(int i=0; i<3; i++)
    std::cout << "nLepton[" << i << "]    = " << nLepton[i] << std::endl;
  for(int i=0;i<20;i++)
    if(nPass[i]>0)
      std::cout << "nPass[" << i << "]= " << nPass[i] << std::endl;
  //th1->Draw();
  scaleF+=nPass[0];

  }
  TFile* outFile = new TFile(Form("root_files/%s.root",endfix.Data()),"recreate");       
  
  th1->Sumw2();
  th1->Scale(5000*xsecF/scaleF);
  th1->Write();
  th2->Write();
  th3->Write();
  thr->Write();
  thr2->Write();
  outFile->Close();

  int width [nWidth]={30,35,50,45,50};
  int bmin[nBmin]={91,93,95,97,99,101,103,105,107,109};
  double eff[nWidth][nBmin];
  for(int i=0;i<nWidth;i++){
    for(int j=0;j<nBmin;j++){
      //eff[i][j]=getEff(th1,bmin[j],bmin[j]+width[i]);
      //cout<<"range={"<<bmin[j]<<","<<bmin[j]+width[i]<<"} and efficiency="<<eff[i][j]<<endl;
    }
  }

  
  }

    }//sig mass point