示例#1
0
int loop(TString infile="/store/group/phys_heavyions/velicanu/forest/Run2015E/ExpressPhysics/Merged/HiForestExpress_baobab.root",
	 TString outfile="/data/wangj/Data2015/Bntuple/ntB_20151130_HiForestExpress_baobab.root", Bool_t REAL=true, Bool_t isPbPb=false, Int_t startEntries=0, Bool_t skim=false, Bool_t gskim=true, Bool_t checkMatching=false)
{
  void fillTree(TVector3* bP, TVector3* bVtx, TLorentzVector* b4P, Int_t j, Int_t typesize, Double_t track_mass1, Double_t track_mass2, Bool_t REAL);
  bool signalGen(Int_t Btype, Int_t j);

  cout<<endl;
  if(REAL) cout<<"--- Processing - REAL DATA"<<endl;
  else cout<<"--- Processing - MC"<<endl;

  TString ifname;
  if(iseos) ifname = Form("root://eoscms.cern.ch//eos/cms%s",infile.Data());
  else ifname = infile;
  TFile* f = TFile::Open(ifname);
  TTree* root = (TTree*)f->Get("Bfinder/root");
  TTree* hltroot = (TTree*)f->Get("hltanalysis/HltTree");
  TTree* hiroot  = (TTree*)f->Get("hiEvtAnalyzer/HiTree");
  TFile* outf = new TFile(outfile,"recreate");
  setBBranch(root);
  setHltBranch(hltroot);
  if(isPbPb) setHiTreeBranch(hiroot);

  int ifchannel[7];
  ifchannel[0] = 1; //jpsi+Kp
  ifchannel[1] = 1; //jpsi+pi
  ifchannel[2] = 1; //jpsi+Ks(pi+,pi-)
  ifchannel[3] = 1; //jpsi+K*(K+,pi-)
  ifchannel[4] = 1; //jpsi+K*(K-,pi+)
  ifchannel[5] = 1; //jpsi+phi(K+,K-)
  ifchannel[6] = 1; //jpsi+pi pi <= psi', X(3872), Bs->J/psi f0
  
  cout<<"--- Building trees"<<endl;
  TTree* nt0 = new TTree("ntKp","");     buildBranch(nt0);
  TTree* nt1 = new TTree("ntpi","");     buildBranch(nt1);
  TTree* nt2 = new TTree("ntKs","");     buildBranch(nt2);
  TTree* nt3 = new TTree("ntKstar","");  buildBranch(nt3);
  TTree* nt5 = new TTree("ntphi","");    buildBranch(nt5);
  TTree* nt6 = new TTree("ntmix","");    buildBranch(nt6);
  TTree* ntGen = new TTree("ntGen","");  buildGenBranch(ntGen);
  TTree* ntHlt = hltroot->CloneTree(0);
  TTree* ntHi = hiroot->CloneTree(0);
  cout<<"--- Building trees finished"<<endl;

  Long64_t nentries = root->GetEntries();
  TVector3* bP = new TVector3;
  TVector3* bVtx = new TVector3;
  TLorentzVector* b4P = new TLorentzVector;
  TLorentzVector* b4Pout = new TLorentzVector;
  TLorentzVector* bGen = new TLorentzVector;
  cout<<"--- Check the number of events for two trees"<<endl;
  cout<<root->GetEntries()<<" "<<hltroot->GetEntries();
  if(isPbPb) cout<<" "<<hiroot->GetEntries();
  cout<<endl;
  cout<<"--- Processing events"<<endl;
  //nentries=1000;
  for(Int_t i=startEntries;i<nentries;i++)
    {
      root->GetEntry(i);
      hltroot->GetEntry(i);
      if(isPbPb) hiroot->GetEntry(i);
      if(i%100000==0) cout<<setw(8)<<i<<" / "<<nentries<<endl;
      if(checkMatching)
	{
	  if((Int_t)Bf_HLT_Event!=EvtInfo_EvtNo||Bf_HLT_Run!=EvtInfo_RunNo||Bf_HLT_LumiBlock!=EvtInfo_LumiNo || (isPbPb&&(Bf_HiTree_Evt!=EvtInfo_EvtNo||Bf_HiTree_Run!=EvtInfo_RunNo||Bf_HiTree_Lumi!=EvtInfo_LumiNo)))
	    {
	      cout<<"Error: not matched "<<i<<" | ";
	      cout<<"EvtNo("<<Bf_HLT_Event<<","<<EvtInfo_EvtNo<<") RunNo("<<Bf_HLT_Run<<","<<EvtInfo_RunNo<<") LumiNo("<<Bf_HLT_LumiBlock<<","<<EvtInfo_LumiNo<<") | EvtNo("<<Bf_HiTree_Evt<<","<<EvtInfo_EvtNo<<") RunNo("<<Bf_HiTree_Run<<","<<EvtInfo_RunNo<<") LumiNo("<<Bf_HiTree_Lumi<<","<<EvtInfo_LumiNo<<")"<<endl;
	      continue;
	    }
	}
      Int_t Btypesize[7]={0,0,0,0,0,0,0};
      Int_t ptflag=-1,ptMatchedflag=-1,probflag=-1,probMatchedflag=-1,tktkflag=-1,tktkMatchedflag=-1;
      Double_t pttem=0,ptMatchedtem=0,probtem=0,probMatchedtem=0,tktktem=0,tktkMatchedtem=0;
      for(Int_t t=0;t<7;t++)
	{
	  Int_t tidx = t-1;
	  if(t!=4)
	    {
	      tidx = t;
	      Bsize = 0;
	      ptflag = -1;
	      pttem = 0;
	      ptMatchedflag = -1;
	      ptMatchedtem = 0;
	      probflag = -1;
	      probtem = 0;
	      probMatchedflag = -1;
	      probMatchedtem = 0;
	      tktkflag = -1;
	      tktktem = 1000000.;
	      tktkMatchedflag = -1;
	      tktkMatchedtem = 1000000.;
	    }
	  if(ifchannel[t]==1)
	    {
	      for(int j=0;j<BInfo_size;j++)
		{
		  if(BInfo_type[j]==(t+1))
		    {
		      fillTree(bP,bVtx,b4P,j,Btypesize[tidx],tk1mass[t],tk2mass[t],REAL);
		      if(BInfo_pt[j]>pttem)
			{
			  ptflag = Btypesize[tidx];
			  pttem = BInfo_pt[j];
			}
		      if(TMath::Prob(BInfo_vtxchi2[j],BInfo_vtxdof[j])>probtem)
			{
			  probflag = Btypesize[tidx];
			  probtem = TMath::Prob(BInfo_vtxchi2[j],BInfo_vtxdof[j]);
			}
		      if(BInfo_type[j]>2&&BInfo_type[j]<7)
			{
			  if(TMath::Abs(BInfo_tktk_mass[j]-midmass[t])<tktktem)
			    {
			      tktkflag = Btypesize[tidx];
			      tktktem = TMath::Abs(BInfo_tktk_mass[j]-midmass[t]);
			    }
			}
		      if((!REAL&&(Bgen[Btypesize[tidx]]==23333||Bgen[Btypesize[tidx]]==41000))||REAL)//////////////////////////////
			{
			  if(BInfo_pt[j]>ptMatchedtem)
			    {
			      ptMatchedflag = Btypesize[tidx];
			      ptMatchedtem = BInfo_pt[j];
			    }
			  if(TMath::Prob(BInfo_vtxchi2[j],BInfo_vtxdof[j])>probMatchedtem)
			    {
			      probMatchedflag = Btypesize[tidx];
			      probMatchedtem = TMath::Prob(BInfo_vtxchi2[j],BInfo_vtxdof[j]);
			    }
			  if(BInfo_type[j]>2&&BInfo_type[j]<7)
			    {
			      if(TMath::Abs(BInfo_tktk_mass[j]-midmass[t])<tktkMatchedtem)
				{
				  tktkMatchedflag = Btypesize[tidx];
				  tktkMatchedtem = TMath::Abs(BInfo_tktk_mass[j]-midmass[t]);
				}
			    }
			}
		      Btypesize[tidx]++;
		    }
		}
	      if(t!=3)
		{
		  if(ptflag>=0) Bmaxpt[ptflag] = true;
		  if(probflag>=0) Bmaxprob[probflag] = true;
		  if(tktkflag>=0) Bbesttktkmass[tktkflag] = true;
		  if(ptMatchedflag>=0) BmaxptMatched[ptMatchedflag] = true;
		  if(probMatchedflag>=0) BmaxprobMatched[probMatchedflag] = true;
		  if(tktkMatchedflag>=0) BbesttktkmassMatched[tktkMatchedflag] = true;
		}
	      if(t==0)      nt0->Fill();
	      else if(t==1) nt1->Fill();
	      else if(t==2) nt2->Fill();
	      else if(t==4) nt3->Fill();
	      else if(t==5) nt5->Fill();
	      else if(t==6) nt6->Fill();
	    }
	}

      ntHlt->Fill();
      if(isPbPb) ntHi->Fill();

      if(!REAL)
	{
	  Int_t gt=0,sigtype=0;
	  Int_t gsize=0;
	  Gsize = 0;
	  for(int j=0;j<GenInfo_size;j++)
	    {
	      if((TMath::Abs(GenInfo_pdgId[j])!=BPLUS_PDGID&&TMath::Abs(GenInfo_pdgId[j])!=BZERO_PDGID&&TMath::Abs(GenInfo_pdgId[j])!=BSUBS_PDGID) && gskim) continue;
	      Gsize = gsize+1;
	      Gpt[gsize] = GenInfo_pt[j];
	      Geta[gsize] = GenInfo_eta[j];
	      Gphi[gsize] = GenInfo_phi[j];
	      GpdgId[gsize] = GenInfo_pdgId[j];
	      bGen->SetPtEtaPhiM(GenInfo_pt[j],GenInfo_eta[j],GenInfo_phi[j],GenInfo_mass[j]);
	      Gy[gsize] = bGen->Rapidity();
	      sigtype=0;
	      for(gt=1;gt<8;gt++)
		{
		  if(signalGen(gt,j))
		    {
		      sigtype=gt;
		      break;
		    }
		}
	      GisSignal[gsize] = sigtype;
	      Gmu1pt[gsize] = -1;
	      Gmu1eta[gsize] = -20;
	      Gmu1phi[gsize] = -20;
	      Gmu1p[gsize] = -1;
	      Gmu2pt[gsize] = -1;
	      Gmu2eta[gsize] = -20;
	      Gmu2phi[gsize] = -20;
	      Gmu2p[gsize] = -1;
	      Gtk1pt[gsize] = -1;
	      Gtk1eta[gsize] = -20;
	      Gtk1phi[gsize] = -20;
	      Gtk2pt[gsize] = -1;
	      Gtk2eta[gsize] = -20;
	      Gtk2phi[gsize] = -20;
	      if(sigtype!=0)
		{
		  Gmu1pt[gsize] = GenInfo_pt[GenInfo_da1[GenInfo_da1[j]]];
		  Gmu1eta[gsize] = GenInfo_eta[GenInfo_da1[GenInfo_da1[j]]];
		  Gmu1phi[gsize] = GenInfo_phi[GenInfo_da1[GenInfo_da1[j]]];
		  Gmu1p[gsize] = Gmu1pt[gsize]*cosh(Gmu1eta[gsize]);
		  Gmu2pt[gsize] = GenInfo_pt[GenInfo_da2[GenInfo_da1[j]]];
		  Gmu2eta[gsize] = GenInfo_eta[GenInfo_da2[GenInfo_da1[j]]];
		  Gmu2phi[gsize] = GenInfo_phi[GenInfo_da2[GenInfo_da1[j]]];
		  Gmu2p[gsize] = Gmu2pt[gsize]*cosh(Gmu2eta[gsize]);
		  if(sigtype==1||sigtype==2)
		    {
		      Gtk1pt[gsize] = GenInfo_pt[GenInfo_da2[j]];
		      Gtk1eta[gsize] = GenInfo_eta[GenInfo_da2[j]];
		      Gtk1phi[gsize] = GenInfo_phi[GenInfo_da2[j]];
		    }
		  else
		    {
		      Gtk1pt[gsize] = GenInfo_pt[GenInfo_da1[GenInfo_da2[j]]];
		      Gtk1eta[gsize] = GenInfo_eta[GenInfo_da1[GenInfo_da2[j]]];
		      Gtk1phi[gsize] = GenInfo_phi[GenInfo_da1[GenInfo_da2[j]]];
		      Gtk2pt[gsize] = GenInfo_pt[GenInfo_da2[GenInfo_da2[j]]];
		      Gtk2eta[gsize] = GenInfo_eta[GenInfo_da2[GenInfo_da2[j]]];
		      Gtk2phi[gsize] = GenInfo_phi[GenInfo_da2[GenInfo_da2[j]]];
		    }
		}
	      gsize++;
	    }
	  ntGen->Fill();
	}
    }

  outf->Write();
  outf->Close();
  return 1;
}
示例#2
0
//////////////////Taking in/out file name as input
void loop(string infile, string outfile, bool REAL=0){
//void loop(bool REAL=0){

const   char* infname;
const   char* outfname;
/////////////////

   if(REAL)
     {
      cout<<"--- REAL DATA ---"<<endl;
      infname = "/net/hidsk0001/d00/scratch/yjlee/bmeson/merged_pPbData_20131114.root";
      outfname = "nt_data.root";
     }
   else
     {
      cout<<"--- MC ---"<<endl;
	  //infname = "/mnt/hadoop/cms/store/user/wangj/HI_Btuple/20140218_PAMuon_HIRun2013_PromptReco_v1/Bfinder_all_100_1_Jrd.root";
      //outfname = "nt_mc.root";

//////////////////
	  infname = infile.c_str();
	  outfname = outfile.c_str();
/////////////////

     }

   //File type
   TFile *f = new TFile(infname);
   TTree *root = (TTree*)f->Get("demo/root");

   //Chain type
   //TChain* root = new TChain("demo/root");
   //root->Add("/mnt/hadoop/cms/store/user/twang/HI_Btuple/20131202_PPMuon_Run2013A-PromptReco-v1_RECO/Bfinder_all_*");

   setBranch(root);
   TFile *outf = new TFile(outfname,"recreate");

   int ifchannel[7];
   ifchannel[0] = 1; //jpsi+Kp
   ifchannel[1] = 1; //jpsi+pi
   ifchannel[2] = 1; //jpsi+Ks(pi+,pi-)
   ifchannel[3] = 1; //jpsi+K*(K+,pi-)
   ifchannel[4] = 1; //jpsi+K*(K-,pi+)
   ifchannel[5] = 1; //jpsi+phi
   ifchannel[6] = 1; //jpsi+pi pi <= psi', X(3872), Bs->J/psi f0
   bNtuple* b0 = new bNtuple;
   bNtuple* b1 = new bNtuple;
   bNtuple* b2 = new bNtuple;
   bNtuple* b3 = new bNtuple;
   bNtuple* b4 = new bNtuple;
   bNtuple* b5 = new bNtuple;
   bNtuple* b6 = new bNtuple;
      
   TTree* nt0 = new TTree("ntKp","");
   b0->buildBranch(nt0);
   TTree* nt1 = new TTree("ntpi","");
   b1->buildBranch(nt1);
   TTree* nt2 = new TTree("ntKs","");
   b2->buildBranch(nt2);
   TTree* nt3 = new TTree("ntKstar1","");
   b3->buildBranch(nt3);
   TTree* nt4 = new TTree("ntKstar2","");
   b4->buildBranch(nt4);
   TTree* nt5 = new TTree("ntphi","");
   b5->buildBranch(nt5);
   TTree* nt6 = new TTree("ntmix","");
   b6->buildBranch(nt6);

   TNtuple* ntGen = new TNtuple("ntGen","","y:eta:phi:pt:pdgId");

   Long64_t nentries = root->GetEntries();
   Long64_t nbytes = 0;
   TVector3* bP = new TVector3;
   TVector3* bVtx = new TVector3;
   TLorentzVector bGen;
   int type;

   for (Long64_t i=0; i<100;i++) {
//   for (Long64_t i=0; i<nentries;i++) {
      nbytes += root->GetEntry(i);
      if (i%10000==0) cout <<i<<" / "<<nentries<<endl;
      for (int j=0;j<BInfo_size;j++) {
	if(BInfo_type[j]>7) continue;
	if (ifchannel[BInfo_type[j]-1]!=1) continue;
	if(BInfo_type[j]==1)
	  {
	    fillTree(b0,bP,bVtx,j);
	    nt0->Fill();
	  }
	if(BInfo_type[j]==2)
	  {
	    fillTree(b1,bP,bVtx,j);
	    nt1->Fill();
	  }
	if(BInfo_type[j]==3)
	  {
	    fillTree(b2,bP,bVtx,j);
	    nt2->Fill();
	  }
	if(BInfo_type[j]==4)
	  {
	    fillTree(b3,bP,bVtx,j);
	    nt3->Fill();
	  }
	if(BInfo_type[j]==5)
	  {
	    fillTree(b4,bP,bVtx,j);
	    nt4->Fill();
	  }
	if(BInfo_type[j]==6)
	  {
	    fillTree(b5,bP,bVtx,j);
	    nt5->Fill();
	  }
	if(BInfo_type[j]==7)
	  {
	    fillTree(b6,bP,bVtx,j);
	    nt6->Fill();
	  }
      }

      for (int j=0;j<GenInfo_size;j++)
	{
	  for(type=1;type<8;type++)
	    {
	      if(signalGen(type,j))
		{
		  bGen.SetPtEtaPhiM(GenInfo_pt[j],GenInfo_eta[j],GenInfo_phi[j],GenInfo_mass[j]);
		  ntGen->Fill(bGen.Rapidity(),bGen.Eta(),bGen.Phi(),bGen.Pt(),GenInfo_pdgId[j]);
		  break;
		}
	    }
	}
   }

  outf->Write();
  outf->Close();
}
示例#3
0
void loopNonpromptBzero(string infile="/mnt/hadoop/cms/store/user/jwang/Bfinder_BoostedMC_20140418_Hijing_PPb502_MinimumBias_HIJINGemb_inclBtoPsiMuMu_5TeV.root", string outfile="../../output/myoutputBzero.root", bool REAL=0){
//////////////////////////////////////////////////////////Phi
//   This file has been automatically generated 
//     (Thu Nov 21 13:34:42 2013 by ROOT version5.27/06b)
//   from TTree root/root
//   found on file: merged_pPbData_20131114.root
//////////////////////////////////////////////////////////

  const char* infname;
  const char* outfname;

  if(REAL) cout<<"--- REAL DATA ---"<<endl;
  else cout<<"--- MC ---"<<endl;


  infname = infile.c_str();
  outfname = outfile.c_str();

  //File type
  TFile *f = new TFile(infname);
  TTree *root = (TTree*)f->Get("demo/root");
  TTree *hlt = (TTree*)f->Get("hltanalysis/HltTree");
  if (root->GetEntries()!=hlt->GetEntries()) {
     cout <<"Inconsistent number of entries!!!"<<endl;
     cout <<"HLT tree: "<<hlt->GetEntries()<<endl;
     cout <<"Bfinder tree: "<<root->GetEntries()<<endl;
  }
  
  //Chain type
  //TChain* root = new TChain("demo/root");
  //root->Add("/mnt/hadoop/cms/store/user/wangj/HI_Btuple/20140213_PAMuon_HIRun2013_PromptReco_v1/Bfinder_all_100_1_dXJ.root");
  //root->Add("/mnt/hadoop/cms/store/user/wangj/HI_Btuple/20140213_PAMuon_HIRun2013_PromptReco_v1/Bfinder_all_101_1_kuy.root");
  //root->Add("/mnt/hadoop/cms/store/user/wangj/HI_Btuple/20140213_PAMuon_HIRun2013_PromptReco_v1/Bfinder_all_10_1_ZkX.root");
  //root->Add("/mnt/hadoop/cms/store/user/wangj/HI_Btuple/20140213_PAMuon_HIRun2013_PromptReco_v1/Bfinder_all_102_1_NyI.root");
  
  TFile *outf = new TFile(outfname,"recreate");

  setBranch(root);
  setHltBranch(hlt);
    
  int ifchannel[7];
  ifchannel[0] = 1; //jpsi+Kp
  ifchannel[1] = 1; //jpsi+pi
  ifchannel[2] = 1; //jpsi+Ks(pi+,pi-)
  ifchannel[3] = 1; //jpsi+K*(K+,pi-)
  ifchannel[4] = 1; //jpsi+K*(K-,pi+)
  ifchannel[5] = 1; //jpsi+phi
  ifchannel[6] = 1; //jpsi+pi pi <= psi', X(3872), Bs->J/psi f0
  
  TTree* nt0 = new TTree("ntKp","");
  buildBranch(nt0);
  TTree* nt1 = new TTree("ntpi","");
  buildBranch(nt1);
  TTree* nt2 = new TTree("ntKs","");
  buildBranch(nt2);
  TTree* nt3 = new TTree("ntKstar","");
  buildBranch(nt3);
  TTree* nt5 = new TTree("ntphi","");
  buildBranch(nt5);
  TTree* nt6 = new TTree("ntmix","");
  buildBranch(nt6);  
  TTree* ntGen = new TTree("ntGen","");
  buildGenBranch(ntGen);

  cout<<"--- Tree building finished ---"<<endl;
  
  Long64_t nentries = root->GetEntries();
  nentries = 100000;
  Long64_t nbytes = 0;  
  TVector3* bP = new TVector3;
  TVector3* bVtx = new TVector3;
  TLorentzVector* b4P = new TLorentzVector;
  TLorentzVector* b4Pout = new TLorentzVector;
  TLorentzVector bGen;
  int type,flag;
  int flagEvt=0;  
  int offsetHltTree=0;

  int testevent=0,testcand=0;
  
  for (Long64_t i=0; i<nentries;i++) {
    nbytes += root->GetEntry(i);
    flagEvt=0;
    while (flagEvt==0)
    {
       hlt->GetEntry(i+offsetHltTree);
       //cout <<offsetHltTree<<" "<<Bfr_HLT_Event<<" "<<EvtInfo_EvtNo<<endl;
       if (Bfr_HLT_Event==EvtInfo_EvtNo && Bfr_HLT_Run==EvtInfo_RunNo) flagEvt=1; else offsetHltTree++;
    } 

    if (i%10000==0) cout <<i<<" / "<<nentries<<"   offset HLT:"<<offsetHltTree<<endl;

    int type1size=0,type2size=0,type3size=0,type4size=0,type5size=0,type6size=0,type7size=0;
    float best,best2,temy;
    int bestindex,best2index;

    size=0;
    best=-1;
    bestindex=-1;
    best2=10000.;
    best2index=-1;
    for (int j=0;j<BInfo_size;j++) 
      {
	if(BInfo_type[j]>7) continue;
	if (ifchannel[BInfo_type[j]-1]!=1) continue;
	//skim{{{
	b4Pout->SetXYZM(BInfo_px[j],BInfo_py[j],BInfo_pz[j],BInfo_mass[j]);
	temy = b4Pout->Rapidity();
	if(REAL)
	  {
	    if(!(((EvtInfo_RunNo>=210498&&EvtInfo_RunNo<=211256&&abs(temy+0.465)<1.93)||(EvtInfo_RunNo>=211313&&EvtInfo_RunNo<=211631&&abs(temy-0.465)<1.93)))) continue;
	  }
	else
	  {
	    if(abs(temy+0.465)>=1.93) continue;
	  }
	if(BInfo_mass[j]<5 || BInfo_mass[j]>6) continue;
	if(BInfo_pt[j]<10.) continue;
	//}}}
	if(BInfo_type[j]==1)
	  {
	    //if(TrackInfo_pt[BInfo_rftk1_index[j]]<0.9) continue;
	    fillTree(bP,bVtx,b4P,j,type1size,KAON_MASS,0,REAL);
	    if(chi2cl[type1size]>best)
	      {
		best = chi2cl[type1size];
		bestindex = type1size;
	      }
	    type1size++;
	  }
      }
    if(size>0)
    {
      bestchi2 = bestindex;
      isbestchi2[bestindex] = 1;
    }
    nt0->Fill();

    size=0;
    best=-1;
    bestindex=-1;
    best2=10000.;
    best2index=-1;
    for (int j=0;j<BInfo_size;j++) 
      {
	if(BInfo_type[j]>7) continue;
	if (ifchannel[BInfo_type[j]-1]!=1) continue;
	//skim{{{
	b4Pout->SetXYZM(BInfo_px[j],BInfo_py[j],BInfo_pz[j],BInfo_mass[j]);
	temy = b4Pout->Rapidity();
	if(REAL)
	  {
	    if(!(((EvtInfo_RunNo>=210498&&EvtInfo_RunNo<=211256&&abs(temy+0.465)<1.93)||(EvtInfo_RunNo>=211313&&EvtInfo_RunNo<=211631&&abs(temy-0.465)<1.93)))) continue;
	  }
	else
	  {
	    if(abs(temy+0.465)>=1.93) continue;
	  }
	if(BInfo_mass[j]<5 || BInfo_mass[j]>6) continue;
	if(BInfo_pt[j]<10.) continue;
	//}}}
	if(BInfo_type[j]==2)
	  {
	    fillTree(bP,bVtx,b4P,j,type2size,PION_MASS,0,REAL);
	    if(chi2cl[type2size]>best)
	      {
		best = chi2cl[type2size];
		bestindex = type2size;
	      }
	    type2size++;
	  }
      }
    if(size>0)
      {
	bestchi2 = bestindex;
	isbestchi2[bestindex] = 1;
      }
    nt1->Fill();
    
    size=0;
    best=-1;
    bestindex=-1;
    best2=10000.;
    best2index=-1;
    for (int j=0;j<BInfo_size;j++) 
      {
	if(BInfo_type[j]>7) continue;
	if (ifchannel[BInfo_type[j]-1]!=1) continue;
	//skim{{{
	b4Pout->SetXYZM(BInfo_px[j],BInfo_py[j],BInfo_pz[j],BInfo_mass[j]);
	temy = b4Pout->Rapidity();
	if(REAL)
	  {
	    if(!(((EvtInfo_RunNo>=210498&&EvtInfo_RunNo<=211256&&abs(temy+0.465)<1.93)||(EvtInfo_RunNo>=211313&&EvtInfo_RunNo<=211631&&abs(temy-0.465)<1.93)))) continue;
	  }
	else
	  {
	    if(abs(temy+0.465)>=1.93) continue;
	  }
	if(BInfo_mass[j]<5 || BInfo_mass[j]>6) continue;
	if(BInfo_pt[j]<10.) continue;
	//}}}
	if(BInfo_type[j]==3)
	  {
	    fillTree(bP,bVtx,b4P,j,type3size,PION_MASS,PION_MASS,REAL);
	    if(chi2cl[type3size]>best)
	      {
		best = chi2cl[type3size];
		bestindex = type3size;
	      }
	    if(abs(tktkmass[type3size]-KSHORT_MASS)<best2)
	      {
		best2 = abs(tktkmass[type3size]-KSHORT_MASS);
		best2index = type3size;
	      }
	    type3size++;
	  }
      }
    if(size>0)
      {
	bestchi2 = bestindex;
	isbestchi2[bestindex] = 1;
	besttktkmass = best2index;
	isbesttktkmass[best2index] = 1;
      }
    nt2->Fill();
    
    size=0;
    best=-1;
    bestindex=-1;
    best2=10000.;
    best2index=-1;
    for (int j=0;j<BInfo_size;j++) 
      {
	if(BInfo_type[j]>7) continue;
	if (ifchannel[BInfo_type[j]-1]!=1) continue;
	//skim{{{
	b4Pout->SetXYZM(BInfo_px[j],BInfo_py[j],BInfo_pz[j],BInfo_mass[j]);
	temy = b4Pout->Rapidity();
	if(REAL)
	  {
	    if(!(((EvtInfo_RunNo>=210498&&EvtInfo_RunNo<=211256&&abs(temy+0.465)<1.93)||(EvtInfo_RunNo>=211313&&EvtInfo_RunNo<=211631&&abs(temy-0.465)<1.93)))) continue;
	  }
	else
	  {
	    if(abs(temy+0.465)>=1.93) continue;
	  }
	if(BInfo_mass[j]<5 || BInfo_mass[j]>6) continue;
	if(BInfo_pt[j]<10.) continue;
	//}}}
	if(BInfo_type[j]==4 || BInfo_type[j]==5)
	  {
	    fillTree(bP,bVtx,b4P,j,type4size,KAON_MASS,PION_MASS,REAL);
	    if(chi2cl[type4size]>best)
	      {
		best = chi2cl[type4size];
		bestindex = type4size;
	      }
	    if(abs(tktkmass[type4size]-KSTAR_MASS)<best2)
	      {
		best2 = abs(tktkmass[type4size]-KSTAR_MASS);
		best2index = type4size;
	      }
	    type4size++;
	  }
      }
    if(size>0)
      {
	bestchi2 = bestindex;
	isbestchi2[bestindex] = 1;
	besttktkmass = best2index;
	isbesttktkmass[best2index] = 1;
      }
    nt3->Fill();
    
    size=0;
    best=-1;
    bestindex=-1;
    best2=10000.;
    best2index=-1;
    for (int j=0;j<BInfo_size;j++) 
      {
	if(BInfo_type[j]>7) continue;
	if (ifchannel[BInfo_type[j]-1]!=1) continue;
	//skim{{{
	b4Pout->SetXYZM(BInfo_px[j],BInfo_py[j],BInfo_pz[j],BInfo_mass[j]);
	temy = b4Pout->Rapidity();
	if(REAL)
	  {
	    if(!(((EvtInfo_RunNo>=210498&&EvtInfo_RunNo<=211256&&abs(temy+0.465)<1.93)||(EvtInfo_RunNo>=211313&&EvtInfo_RunNo<=211631&&abs(temy-0.465)<1.93)))) continue;
	  }
	else
	  {
	    if(abs(temy+0.465)>=1.93) continue;
	  }
	if(BInfo_mass[j]<5 || BInfo_mass[j]>6) continue;
	if(BInfo_pt[j]<10.) continue;
	//}}}
	if(BInfo_type[j]==6)
	  {
	    //if(TrackInfo_pt[BInfo_rftk1_index[j]]<0.7) continue;
	    //if(TrackInfo_pt[BInfo_rftk2_index[j]]<0.7) continue;
	    fillTree(bP,bVtx,b4P,j,type6size,KAON_MASS,KAON_MASS,REAL);
	    if(chi2cl[type6size]>best)
	      {
		best = chi2cl[type6size];
		bestindex = type6size;
	      }
	    if(abs(tktkmass[type6size]-PHI_MASS)<best2)
	      {
		best2 = abs(tktkmass[type6size]-PHI_MASS);
		best2index = type6size;
	      }
	    type6size++;
	  }
      }
    if(size>0)
      {
	bestchi2 = bestindex;
	isbestchi2[bestindex] = 1;
	besttktkmass = best2index;
	isbesttktkmass[best2index] = 1;
      }
    nt5->Fill();
    
    size=0;
    best=-1;
    bestindex=-1;
    best2=10000.;
    best2index=-1;
    for (int j=0;j<BInfo_size;j++) 
      {
	if(BInfo_type[j]>7) continue;
	if (ifchannel[BInfo_type[j]-1]!=1) continue;
	//skim{{{
	b4Pout->SetXYZM(BInfo_px[j],BInfo_py[j],BInfo_pz[j],BInfo_mass[j]);
	temy = b4Pout->Rapidity();
	if(REAL)
	  {
	    if(!(((EvtInfo_RunNo>=210498&&EvtInfo_RunNo<=211256&&abs(temy+0.465)<1.93)||(EvtInfo_RunNo>=211313&&EvtInfo_RunNo<=211631&&abs(temy-0.465)<1.93)))) continue;
	  }
	else
	  {
	    if(abs(temy+0.465)>=1.93) continue;
	  }
	if(BInfo_mass[j]<5 || BInfo_mass[j]>6) continue;
	if(BInfo_pt[j]<10.) continue;
	//}}}
	if(BInfo_type[j]==7)
	  {
	    fillTree(bP,bVtx,b4P,j,type7size,PION_MASS,PION_MASS,REAL);
	    if(chi2cl[type7size]>best)
	      {
		best = chi2cl[type7size];
		bestindex = type7size;
	      }
	    type7size++;
	  }
      }
    if(size>0)
      {
	bestchi2 = bestindex;
	isbestchi2[bestindex] = 1;
      }
    nt6->Fill();
    
    if(!REAL)
      {
	Gensize = 0;
	for (int j=0;j<GenInfo_size;j++)
	  {
	    bGen.SetPtEtaPhiM(GenInfo_pt[j],GenInfo_eta[j],GenInfo_phi[j],GenInfo_mass[j]);
	    flag=0;
	    for(type=1;type<8;type++)
	      {
		if (signalGen(type,j)) {
                  flag=type;
		  break;
                }
	      }
	    Genmu1pt[j] = -1;
	    Genmu1eta[j] = -20;
	    Genmu1phi[j] = -20;
	    Genmu1p[j] = -1;
	    Genmu2pt[j] = -1;
	    Genmu2eta[j] = -20;
	    Genmu2phi[j] = -20;
	    Genmu2p[j] = -1;
	    Gentk1pt[j] = -1;
	    Gentk1eta[j] = -20;
	    Gentk1phi[j] = -20;
	    Gentk2pt[j] = -1;
	    Gentk2eta[j] = -20;
	    Gentk2phi[j] = -20;

            if(flag!=0)
              {
                Genmu1pt[j] = GenInfo_pt[GenInfo_da1[GenInfo_da1[j]]];
                Genmu1eta[j] = GenInfo_eta[GenInfo_da1[GenInfo_da1[j]]];
                Genmu1phi[j] = GenInfo_phi[GenInfo_da1[GenInfo_da1[j]]];
                Genmu1p[j] = Genmu1pt[j]*cosh(Genmu1eta[j]);
                Genmu2pt[j] = GenInfo_pt[GenInfo_da2[GenInfo_da1[j]]];
                Genmu2eta[j] = GenInfo_eta[GenInfo_da2[GenInfo_da1[j]]];
		Genmu2phi[j] = GenInfo_phi[GenInfo_da2[GenInfo_da1[j]]];
                Genmu2p[j] = Genmu2pt[j]*cosh(Genmu2eta[j]);
		if(flag==1||flag==2)
		  {
		    Gentk1pt[j] = GenInfo_pt[GenInfo_da2[j]];
		    Gentk1eta[j] = GenInfo_eta[GenInfo_da2[j]];
		    Gentk1phi[j] = GenInfo_phi[GenInfo_da2[j]];
		  }
		else
		  {
		    Gentk1pt[j] = GenInfo_pt[GenInfo_da1[GenInfo_da2[j]]];
		    Gentk1eta[j] = GenInfo_eta[GenInfo_da1[GenInfo_da2[j]]];
		    Gentk1phi[j] = GenInfo_phi[GenInfo_da1[GenInfo_da2[j]]];
		    Gentk2pt[j] = GenInfo_pt[GenInfo_da2[GenInfo_da2[j]]];
		    Gentk2eta[j] = GenInfo_eta[GenInfo_da2[GenInfo_da2[j]]];
		    Gentk2phi[j] = GenInfo_phi[GenInfo_da2[GenInfo_da2[j]]];
		  }
              }
	    Gensize = GenInfo_size;
	    Geny[j] = bGen.Rapidity();
	    Geneta[j] = bGen.Eta();
	    Genphi[j] = bGen.Phi();
	    Genpt[j] = bGen.Pt();
	    GenpdgId[j] = GenInfo_pdgId[j];
	    GenisSignal[j] = flag;
	  }
	ntGen->Fill();
      }
  }

  outf->Write();
  outf->Close();
}