コード例 #1
0
ファイル: main.cpp プロジェクト: HillBamboo/MOOCs
/******************************************************************************************
 * 起泡排序测试程序
 ******************************************************************************************/
void main ( int argc, char* argv[] ) {
   int n = 0; //array length
   if ( 1 < argc ) n = atoi ( argv[1] ); if ( n < 0 ) n = 0; //make sure length is non-negative
   int* A = ( int* ) malloc ( n * sizeof ( int ) ); //allocate an array of size n
   unsigned int seed = ( unsigned int ) time ( NULL ); //A same seed is used here for comparison between different algorithms
   printf ( "\n== Bubblesort algorithm #0 ========\n" );
   randomArray ( A, n, seed ); //create a randomized array using the same seed
   printf ( "-->  " ); print ( A, n );
   bubblesort ( A, n ); //sort the array using algorithm#0
   printf ( "==>  " ); print ( A, n );
   printf ( "\n== Bubblesort algorithm #1A ========\n" );
   randomArray ( A, n, seed ); //create a randomized array using the same seed
   printf ( "==>  " ); print ( A, n );
   bubblesort1A ( A, n ); //sort the array using algorithm#1A
   printf ( "==>  " ); print ( A, n );
   printf ( "\n== Bubblesort algorithm #1B ========\n" );
   randomArray ( A, n, seed ); //create a randomized array using the same seed
   printf ( "==>  " ); print ( A, n );
   bubblesort1B ( A, n ); //sort the array using algorithm#1B
   printf ( "==>  " ); print ( A, n );
   printf ( "\n== Bubblesort algorithm #2 ========\n" );
   randomArray ( A, n, seed ); //create a randomized array using the same seed
   printf ( "==>  " ); print ( A, n );
   bubblesort2 ( A, n ); //sort the array using algorithm#2
   printf ( "==>  " ); print ( A, n );
   free ( A ); //release the array
}
コード例 #2
0
void* sort8k_entry2( void *data )
{
    sortarg_t * my_arg;
    void *ptr;

    my_arg = (sortarg_t *)data;
    //unsigned int tid = (unsigned int)hthread_self();
    //unsigned int thread_number = ( unsigned int ) data;

    while ( 1 ) {
        // get pointer to next chunk of data
        ptr = (void*)mailbox_read( &my_arg->mb_start );
        // sort it
        bubblesort2( ( unsigned int * ) ptr, N );
        // return
        mailbox_write( &my_arg->mb_done, (void*)23 ); // return any value
    }
    return NULL;
}
コード例 #3
0
ファイル: CreateTree.C プロジェクト: chernyavskaya/Hbb
void CreateTree::Loop()
{
   if (fChain == 0) return;

   Long64_t nentries = fChain->GetEntriesFast();

   Long64_t nbytes = 0, nb = 0;

	TFile file("spring15_vbf_powheg_new_blike_125_08.root","recreate");
	TTree *tree0 = new TTree("Jet_tree_b","Jet_tree_b");
	TreeJets TreeJet;
	tree0->Branch("Jet_pt",&TreeJet.pt,"Jet_pt/F");
	tree0->Branch("Jet_eta",&TreeJet.eta,"Jet_eta/F");
	tree0->Branch("Jet_btagCSV",&TreeJet.btagCSV,"Jet_btagCSV/F");
	tree0->Branch("Jet_pt_idx",&TreeJet.pt_idx,"Jet_pt_idx/I");
	tree0->Branch("Jet_eta_idx",&TreeJet.eta_idx,"Jet_eta_idx/I");
	tree0->Branch("Jet_btagCSV_idx",&TreeJet.btagCSV_idx,"Jet_btagCSV_idx/I");
	tree0->Branch("Jet_btag_idx",&TreeJet.btag_idx,"Jet_btag_idx/I");
	tree0->Branch("Jet_chMult",&TreeJet.ch_mult,"Jet_chMult/I");
	tree0->Branch("Jet_ptd",&TreeJet.ptd,"Jet_ptd/F");
	tree0->Branch("Jet_leadTrackPt",&TreeJet.leadTrPt,"Jet_leadTrPt");
	tree0->Branch("Jet_axis2",&TreeJet.axis2, "Jet_axis2");
	tree0->Branch("Jet_b_matched",&TreeJet.b_matched,"Jet_b_matched/I");
	tree0->Branch("Jet_q_matched",&TreeJet.q_matched,"Jet_q_matched/I");
	tree0->Branch("Jet_n_matched",&TreeJet.n_matched,"Jet_n_matched/I");

	Float_t bb_efficiency_find=0.;
	Float_t bb_efficiency=0.;
	Float_t qq_efficiency_find=0.;
	Float_t qq_efficiency=0.;
	Float_t presel =0.;


   for (Long64_t jentry=0; jentry<nentries;jentry++) {
	   Long64_t ientry = LoadTree(jentry);
	   if (ientry < 0) break;
	   nb = fChain->GetEntry(jentry);   nbytes += nb;
	   JetList jetList_CSV, jetList_pt, jetList_eta; 
		Float_t jet_isMatched2 = 0;
		Float_t jet_isMatchedQ = 0;
	   

		if (genWeight<0) continue;



		if (!((Jet_pt[0]>92.)&&(Jet_pt[1]>76.)&&(Jet_pt[2]>64.)&&(Jet_pt[3]>30.))) continue;

		int loopJet_min = 6;
		if (nJet<6) loopJet_min=nJet;


		Double_t btag_max = 0.4;
		int btag_max1_number = -1;
		int btag_max2_number = -1;
		for (int i=0;i<loopJet_min;i++){
			if ((Jet_btagCSV[i]>btag_max)&&(Jet_id[i]>0)){
				btag_max=Jet_btagCSV[i];
				btag_max1_number=i;
			}
		}
		btag_max = 0.4;
		for (int i=0;i<loopJet_min;i++){
			if ((Jet_btagCSV[i]>btag_max)&&(i!=btag_max1_number)&&(Jet_id[i]>0)) {
				btag_max=Jet_btagCSV[i];
				btag_max2_number=i;
			} 
		}
		if (!((btag_max1_number>=0)&&(btag_max2_number>=0))) continue;
		TLorentzVector Bjet1;
		Bjet1.SetPtEtaPhiM(Jet_pt[btag_max1_number],Jet_eta[btag_max1_number],Jet_phi[btag_max1_number],Jet_mass[btag_max1_number]);
		
		TLorentzVector Bjet2;
		Bjet2.SetPtEtaPhiM(Jet_pt[btag_max2_number],Jet_eta[btag_max2_number],Jet_phi[btag_max2_number],Jet_mass[btag_max2_number]);


		Double_t pt_max = 20.;
		int pt_max1_number = -1;
		int pt_max2_number = -1;
		for (int i=0;i<loopJet_min;i++){
			if ((Jet_pt[i]>pt_max)&&(i!=btag_max1_number)&&(i!=btag_max2_number)&&(Jet_id[i]>0)) {
				pt_max=Jet_pt[i];
				pt_max1_number=i;	
			}
		}
		pt_max = 20.;
		for (int i=0;i<loopJet_min;i++){
			if ((Jet_pt[i]>pt_max)&&(i!=btag_max1_number)&&(i!=btag_max2_number)&&(i!=pt_max1_number)&&(Jet_id[i]>0)) {
				pt_max=Jet_pt[i];
				pt_max2_number=i;	
			}
		}
		
		if (!((pt_max1_number>=0)&&(pt_max2_number>=0))) continue;
			
		TLorentzVector Qjet1;
		Qjet1.SetPtEtaPhiM(Jet_pt[pt_max1_number],Jet_eta[pt_max1_number],Jet_phi[pt_max1_number],Jet_mass[pt_max1_number]);
	
		TLorentzVector Qjet2;
		Qjet2.SetPtEtaPhiM(Jet_pt[pt_max2_number],Jet_eta[pt_max2_number],Jet_phi[pt_max2_number],Jet_mass[pt_max2_number]);


		TLorentzVector qq;
		qq = Qjet1+Qjet2;
		Double_t Mqq = qq.M();
		Double_t bbDeltaPhi = TMath::Abs(Bjet1.DeltaPhi(Bjet2));
		Double_t qqDeltaEta = TMath::Abs(Qjet1.Eta()-Qjet2.Eta());
		if (!((Mqq>200)&&(qqDeltaEta>1.2)&&(bbDeltaPhi<2.4))) continue;

		if (HLT_BIT_HLT_QuadPFJet_DoubleBTagCSV_VBF_Mqq200_v!=1) continue;

		int loopJet_max = 7;
		if (nJet<7) loopJet_max = nJet; 

		for(int i=0; i<loopJet_max; i++){
		   if(Jet_pt[i]<20 || Jet_id[i] <0) continue;
			if (Jet_btagCSV[i]==-10) Jet_btagCSV[i]=0; 
			if (Jet_btagCSV[i]>1) Jet_btagCSV[i]=1.;
		   jetList_CSV[Jet_btagCSV[i]]=i;
		   jetList_pt[Jet_pt[i]]=i;
         jetList_eta[TMath::Abs(Jet_eta[i])]=i;
	   }


	Float_t bb_found = 0.;
	Float_t qq_found = 0.;


		Float_t eta_sort[30];
		Float_t btag_sort[30];
		for (int i=0;i<loopJet_max;i++){
			if ((Jet_pt[i]>20)&&(Jet_id[i]>0)) {
				TreeJet.eta = TMath::Abs(Jet_eta[i]);
				eta_sort[i] = TMath::Abs(Jet_eta[i]);
		   	TreeJet.btagCSV=Jet_btagCSV[i];
				btag_sort[i] = Jet_btagCSV[i];
			}
		}

		bubblesort(eta_sort,loopJet_max);
		bubblesort2(btag_sort,loopJet_max);
/*
		for (int i=0;i<loopJet_max;i++){
			cout<<btag_sort[i]<<"  "<<i<<endl;
		}*/
		int btag_0_num = 0;
	   for(int i=0; i<loopJet_max; i++){
		   if(Jet_pt[i]<20 || Jet_id[i] <0) continue;
			TreeJet.b_matched=0;
			TreeJet.q_matched=0;
			TreeJet.n_matched=0;
		   TLorentzVector hJ0;
		   TreeJet.pt=Jet_pt[i];
		   TreeJet.eta=TMath::Abs(Jet_eta[i]); 
		   TreeJet.btagCSV=Jet_btagCSV[i];
			TreeJet.ptd=Jet_ptd[i];
			TreeJet.ch_mult=Jet_chMult[i];
			TreeJet.axis2=Jet_axis2[i];
			TreeJet.leadTrPt=Jet_leadTrackPt[i];
			TreeJet.pt_idx = i;
			TreeJet.eta_idx = find(eta_sort,TreeJet.eta,loopJet_max);
			TreeJet.btagCSV_idx = find(btag_sort,TreeJet.btagCSV,loopJet_max);
			if ((TreeJet.btagCSV==0)&&(btag_0_num==0)) {
				btag_0_num =  find(btag_sort,TreeJet.btagCSV,loopJet_max);
				TreeJet.btagCSV_idx = btag_0_num;
			} else 
			if ((TreeJet.btagCSV==0)&&(btag_0_num!=0)) {
				btag_0_num++;
				TreeJet.btagCSV_idx = btag_0_num;
			}
			TreeJet.btag_idx = Jet_btagIdx[i];
			

		   hJ0.SetPtEtaPhiM(Jet_pt[i],Jet_eta[i],Jet_phi[i],Jet_mass[i]);	
		
		   for(int j =0; j<2; j++){
			   if(TMath::Abs(GenBQuarkFromH_pdgId[j])==5){
            	TLorentzVector hQQ;
               hQQ.SetPtEtaPhiM(GenBQuarkFromH_pt[j],GenBQuarkFromH_eta[j],GenBQuarkFromH_phi[j],GenBQuarkFromH_mass[j]);
              	if(hQQ.DeltaR(hJ0)<0.8){ TreeJet.b_matched =1; bb_found++;  }
            } 
		   }
		   for(int j =0; j<2; j++){
				TLorentzVector hQ;
				hQ.SetPtEtaPhiM(GenHiggsSisters_pt[j],GenHiggsSisters_eta[j],GenHiggsSisters_phi[j],GenHiggsSisters_mass[j]);
				if(hQ.DeltaR(hJ0)<0.8) {TreeJet.q_matched = 1; qq_found++;}
		   }



			if ((TreeJet.b_matched==0)&&(TreeJet.q_matched==0)) TreeJet.n_matched=1;
		 	tree0->Fill();
	   }
		
	int cont1=0; TLorentzVector hJ00, hJ11;	
	for (JetList::reverse_iterator iJet=jetList_CSV.rbegin(); iJet!=jetList_CSV.rend(); ++iJet)
	{

		int i = iJet->second;
		if(cont1==0) hJ00.SetPtEtaPhiM(Jet_pt[i],Jet_eta[i],Jet_phi[i],Jet_mass[i]);
		if(cont1==1) hJ11.SetPtEtaPhiM(Jet_pt[i],Jet_eta[i],Jet_phi[i],Jet_mass[i]);

		if (cont1>1) continue;
		cont1++;

	}
	for(int j =0; j<2; j++){
		if(TMath::Abs(GenBQuarkFromH_pdgId[j])==5)
		{
			TLorentzVector hQ;
			hQ.SetPtEtaPhiM(GenBQuarkFromH_pt[j],GenBQuarkFromH_eta[j],GenBQuarkFromH_phi[j],GenBQuarkFromH_mass[j]);
			if(hQ.DeltaR(hJ00)<0.8 || hQ.DeltaR(hJ11)<0.8) jet_isMatched2++;
		}
	}

	TLorentzVector hQ00, hQ11;
	hQ00.SetPtEtaPhiM(Jet_pt[pt_max1_number],Jet_eta[pt_max1_number],Jet_phi[pt_max1_number],Jet_mass[pt_max1_number]);
	hQ11.SetPtEtaPhiM(Jet_pt[pt_max2_number],Jet_eta[pt_max2_number],Jet_phi[pt_max2_number],Jet_mass[pt_max2_number]);
	for(int j =0; j<2; j++){
		TLorentzVector hQ;
		hQ.SetPtEtaPhiM(GenHiggsSisters_pt[j],GenHiggsSisters_eta[j],GenHiggsSisters_phi[j],GenHiggsSisters_mass[j]);
		if((hQ.DeltaR(hQ00)<0.8)||(hQ.DeltaR(hQ11)<0.8))  jet_isMatchedQ++;
	}




		if (jet_isMatched2==2) bb_efficiency+=TMath::Sign(1.,genWeight);
		if (jet_isMatchedQ==2) qq_efficiency+=TMath::Sign(1.,genWeight);
		if (bb_found>=2) bb_efficiency_find+=TMath::Sign(1.,genWeight);
		if (qq_found>=2) qq_efficiency_find+=TMath::Sign(1.,genWeight);
		presel+=TMath::Sign(1.,genWeight);
	}  

	ofstream out("spring15_powheg_125_08.txt"); 
	out<<"bb efficiency to find b-jets = "<<bb_efficiency_find/presel<<endl;
	out<<"bb efficiency to match b-jets = "<<bb_efficiency/presel<<endl;
	out<<"qq efficiency to find q-jets = "<<qq_efficiency_find/presel<<endl;
	out<<"qq efficiency to match q-jets = "<<qq_efficiency/presel<<endl;
	cout<<"bb efficiency to find b-jets = "<<bb_efficiency_find/presel<<endl;
	cout<<"bb efficiency to match b-jets = "<<bb_efficiency/presel<<endl;
	cout<<"qq efficiency to find q-jets = "<<qq_efficiency_find/presel<<endl;
	cout<<"qq efficiency to match q-jets = "<<qq_efficiency/presel<<endl;
	file.Write();
	file.Close();

}