コード例 #1
0
ファイル: plotCmp.C プロジェクト: andjuo/DYee
void plotCmp(int eff) {
  TFile fin1("out1_EE_Jan.root","read");
  TH1D *hEff1=(TH1D*)fin1.Get("eff_postFSRcorr");
  TH1D *hAcc1=(TH1D*)fin1.Get("acc_postFSRcorr");
  hEff1->SetDirectory(0);
  hAcc1->SetDirectory(0);
  fin1.Close();
  TH1D* hAS=(eff) ? hEff1 : hAcc1;

  TString path="../root_files_reg/constants/DY_j22_19712pb/";
  TString fname2= path+ TString((!eff) ? "acceptance_1D.root" : "efficiency_1D.root");
  TString fieldName=(eff) ? "hEfficiency" : "hAcceptance";
  TString correctionName=(eff) ? "efficiency" : "acceptance";

  TFile fin2(fname2,"read");
  TH2D *h2Our=(TH2D*)fin2.Get(fieldName);
  h2Our->SetName("h2Our");
  h2Our->SetDirectory(0);
  fin2.Close();

  TH1D *hOurRaw=createProfileX(h2Our,1,fieldName + TString("Raw"));
  TH1D *hOur=removeLastBin(hOurRaw,fieldName);
  TString label1="regressed en. (20-500,500-800,800+)";
  TH1D *h2=NULL, *h3=NULL;
  TString label2,label3;

  if (0) {
    TString fname3="../root_files_reg/constants/DY_j22_19712pb_20inf/efficiency_1D.root";
    if (!eff) fname3.ReplaceAll("efficiency","acceptance");
    TFile fin3(fname3,"read");
    TH2D* h2tmp=(TH2D*)fin3.Get(fieldName);
    TH1D* h1tmp=createProfileX(h2tmp,1,"h1tmp");
    label2="regressed en. (20-inf)";
    h2=removeLastBin(h1tmp,fieldName+TString("regEn20inf"));
    delete h1tmp;
    delete h2tmp;
    fin3.Close();
  }

  if (0) {
    TString fname4="../root_files/constants/DY_j22_19789pb/efficiency_1D.root";
    if (!eff) fname4.ReplaceAll("efficiency","acceptance");
    TFile fin4(fname4,"read");
    TH2D* h2tmp=(TH2D*)fin4.Get(fieldName);
    TH1D* h1tmp=createProfileX(h2tmp,1,"h1tmp");
    h3=removeLastBin(h1tmp,fieldName+TString("summer2012"));
    label3="old n-tuples (20-500,500-800,800+)";
    delete h1tmp;
    delete h2tmp;
    fin4.Close();
  }

  if (0 && !eff) {
    TString fname3="../root_files_reg/constants/DY_j22_19712pb/acceptance_1D-PU.root";
    //if (!eff) fname4.ReplaceAll("efficiency","acceptance");
    TFile fin3(fname3,"read");
    TH2D* h2tmp=(TH2D*)fin3.Get(fieldName);
    printHisto(h2tmp);
    TH1D* h1tmp=createProfileX(h2tmp,1,"h1tmp");
    h2=removeLastBin(h1tmp,fieldName+TString("_wPU"));
    label3="regressed (20-500,500-800,800+); wPU";
    delete h1tmp;
    delete h2tmp;
    fin3.Close();
  }

  if (0 && !eff) {
    //TString fname4="../root_files_reg/constants/DY_j22_19712pb/acceptance_1D-PU.root";
    TString fname4="../root_files_reg/constants/DY_j22_19712pb_NoReweight/acceptance_1D___NoReweight.root";
    //if (!eff) fname4.ReplaceAll("efficiency","acceptance");
    TFile fin4(fname4,"read");
    TH2D* h2tmp=(TH2D*)fin4.Get(fieldName);
    printHisto(h2tmp);
    TH1D* h1tmp=createProfileX(h2tmp,1,"h1tmp");
    h3=removeLastBin(h1tmp,fieldName+TString("_noFEWZ"));
    label3="regressed (20-500,500-800,800+); noFEWZ";
    delete h1tmp;
    delete h2tmp;
    fin4.Close();
  }

  std::cout << "Alexey: "; printHisto(hAS);
  //std::cout << "OurRaw: "; printHisto(hOurRaw);
  std::cout << "Our   : "; printHisto(hOur);

  ComparisonPlot_t cp(ComparisonPlot_t::_ratioPlain,"cp","","#it{M}_{ee}",correctionName,"ratio");
  cp.SetLogx();
  cp.AddHist1D(hAS,"Alexey","LP",kBlack,1,0);
  cp.AddHist1D(hOur,label1,"LP",kBlue,1,0);
  if (h2) cp.AddHist1D(h2,label2,"LP",kGreen+1,1,0);
  if (h3) cp.AddHist1D(h3,label3,"LP",kRed+1,1,0);
  
  TCanvas *cx= new TCanvas("cx","cx",700,850);
  cp.Prepare2Pads(cx);
  cp.Draw(cx);
  cp.TransLegend(0,-0.6);
  if (1 || h2 || h3) {
    cp.TransLegend(-0.15,0.);
    cp.WidenLegend(0.15,0.);
  }
  cx->Update();
}
コード例 #2
0
ファイル: belief_diff.cpp プロジェクト: ekoontz/graphlab
int main(int argc, char** argv) {
  std::cout << "This program computes the difference between two belief files."
            << std::endl;

  if(argc != 3) {
    std::cout << "Usage example: " << std::endl
              << " %> " << argv[0] << " bp_beliefs.csv gibbs_beliefs.csv "
              << std::endl;
  }


  std::ifstream fin1(argv[1]);
  if(!fin1.good()) {
    std::cout << "Unable to open: " << argv[1] << std::endl;
    exit(EXIT_FAILURE);
  }
  std::ifstream fin2(argv[2]);
  if(!fin2.good()) {
    std::cout << "Unable to open: " << argv[2] << std::endl;
    exit(EXIT_FAILURE);
  }

  double L1_L1_error    = 0;
  double L1_L_inf_error  = 0;
  double L_inf_L1_error    = 0;
  size_t disagree = 0;
  size_t vertices = 0;
  while(fin1.good() && fin2.good()) {
    // Read the line for both files
    std::string line1;
    std::getline(fin1, line1);
    std::string line2;
    std::getline(fin2, line2);
    line1 = trim(line1);
    line2 = trim(line2);
    if(line1.size() == 0 || line2.size() == 0) continue;


    // Trim the varialble name
    size_t index1 = line1.find_first_of('/');
    assert(index1 != std::string::npos);
    size_t index2 = line2.find_first_of('/');
    assert(index2 != std::string::npos);

    std::string var1 = trim(line1.substr(0, index1));
    std::string var2 = trim(line1.substr(0, index2));
    assert(var1 == var2);

    line1 = line1.substr(index1);
    line2 = line2.substr(index2);
    

    //  compute the rest of the string
    std::stringstream strm1(line1), strm2(line2);
    
    size_t index = 0;
    double sum = 0, max = 0;
    size_t mapInd1 = 0;
    double mapVal1 = -1;
    size_t mapInd2 = 0;
    double mapVal2 = -1;

    while(strm1.good() && strm2.good()) {
      
      double value1=-1, value2=-1;      
      strm1 >> value1;
      strm2 >> value2;
      strm1.ignore(1); strm2.ignore(1);
      
      assert(value1 >= 0 && value1 <= 1);
      assert(value2 >= 0 && value2 <= 1);
      // Compute the map for each line
      if(value1 > mapVal1) {
        mapVal1 = value1;
        mapInd1 = index;
      }
      if(value2 > mapVal2) {
        mapVal2 = value2;
        mapInd2 = index;
      }
      // Compute the difference in the probabilities 
      double diff = std::abs(value1 - value2);
      sum += diff;
      max = std::max(max, diff);
      // Increment index
      ++index;
    }

    // Assert both lines end at the same state
    assert(!strm1.good() && !strm2.good());

    // update the global counters
    double l1_error = sum / index;
    L1_L1_error += l1_error;
    L1_L_inf_error += max;
    L_inf_L1_error = std::max(L_inf_L1_error, l1_error);
    disagree += (mapInd1 != mapInd2? 1 : 0);
    ++vertices;
  } // end of while loop
  assert(!fin1.good() && !fin2.good());
  fin1.close(); fin2.close();

  std::cout << "Read " << vertices << " beliefs."
            << std::endl
            << "L1 L1 error:       " << L1_L1_error / vertices << std::endl
            << "L1 Linf error:     " << L1_L_inf_error / vertices << std::endl
            << "Linf L1 error:     " << L_inf_L1_error << std::endl
            << "%Map Disagree:      " << double(disagree) / vertices << std::endl;  
  return EXIT_SUCCESS;
}
コード例 #3
0
//LEGO‚RGB‚Lab
void  LegoRGB_to_Lab(Model& m)
{
	string line;
	istringstream ssline;
	CColor temp;
	string temps;
	vector<string> iro;
	vector<CColor> tempLegoColor;
	int BackColorNum(0);
	int i(0);
	//LEGO
	string filename("lego_color_rgb.txt");
	//string filename("lego_color_rgb_tree.txt");
	//string filename("lego_color_rgb_palette.txt");
	ifstream fin(directory[0] + filename);
	if (!fin){
		cout << filename << " lego_color_rgb.txt was not found!!!  " << endl;
		exit(-1);
	}

	//###########################
	//###########################
	while (!fin.eof()){
		getline(fin, line);									
		if (line.size() == 0 || line[0] == '\n') continue;	
		//Block_colorNum++;	
		ssline.str(line);									
		ssline >> temp.r >> temp.g >> temp.b >> temps;		
		temp.r = temp.r / 255.0;							
		temp.g = temp.g / 255.0;
		temp.b = temp.b / 255.0;
		iro.push_back(temps);
		tempLegoColor.push_back(temp);						
		ssline.clear();			//ssline
	}

	//###########################
	//
	//###########################
	for (i = 0; i < iro.size(); i++)
		cout << i << ":" << iro[i] << endl;


	for (;;){
		cout << "         " << endl;
		cout << "0-" << iro.size() - 1 << ":choose one of that color, Other: not " << endl;
		//cin >> BackColorNum;
		BackColorNum = 2;

		if (-1 < BackColorNum && BackColorNum < iro.size())
		{
			cout << iro[BackColorNum] << " was chosen." << endl;
			m.BackColor = tempLegoColor[BackColorNum];
			cout << "RGB to Hue: " << RGBtoHue(m.BackColor.r, m.BackColor.g, m.BackColor.b) << endl;

			for (i = 0; i < iro.size(); i++){
				if (i == BackColorNum)
					continue;
				m.LegoColor.push_back(tempLegoColor[i]);
			}
			break;
		}
		else
			break;
	}
	for (i = 0; i < iro.size(); i++) {
		cout << "iro[" << i << "] m.LegoColor[" << i << "] r." << m.LegoColor[i].r<<" g." << m.LegoColor[i].g<<" b." << m.LegoColor[i].b << endl;
	}

	//#################################
	//                                     
	//#################################

	string filename1("BrickTable.txt");
	ifstream fin1(directory[0] + filename1);
	if (!fin1){
		cout << filename1 << " could not find!!" << endl;
		exit(-1);
	}

	unsigned designID;
	getline(fin1, line);								//1s–ځiDesign IDj
	ssline.str(line);
	for (i = 0; i < 7; i++){
		ssline >> designID;
		table.DesignID.push_back(designID);
	}
	ssline.clear();			//ssline‚Ì‘S—v‘f‚ðíœ

	table.itemNos.resize(7);
	unsigned colorID;
	unsigned itemnos;
	int k(0);
	while (!fin1.eof()){
		getline(fin1, line);									

		if (line.size() == 0 || line[0] == '\n') continue;		
		if (k != BackColorNum){
			ssline.str(line);									
			ssline >> colorID;				
			table.ColorID.push_back(colorID);

			//cout << "colorID " << colorID << "-k" << k << " -table.ColorID " << table.ColorID[k] << endl;

			for (i = 0; i < 7; i++){
				ssline >> itemnos;
				table.itemNos[i].push_back(itemnos);
			//	cout << "itemnos " << itemnos << " table.itemNos[" << i << "]\n";
			}
		}
		k++;
		ssline.clear();			//ssline‚Ì‘S—v‘f‚ðíœ
	}
コード例 #4
0
ファイル: result_lessbin.C プロジェクト: ChenXu8774/pp_SA
void result_lessbin( int check = 1)
{

	TString infile="422070_hist.root";
//	TString infile="diMuon_his.lst.root";
	gStyle->SetOptFit();
	
	TFile *file = TFile::Open(infile);
	if (check == 0)
	{
		TH2F *_sig_s_uu = (TH2F*)file->Get("_sah_pT_os_lsb_n_PP");
		TH2F *_sig_s_ud = (TH2F*)file->Get("_sah_pT_os_lsb_n_PM");
		TH2F *_sig_s_du = (TH2F*)file->Get("_sah_pT_os_lsb_n_MP");
		TH2F *_sig_s_dd = (TH2F*)file->Get("_sah_pT_os_lsb_n_MM");
	
		ofstream fout("sig_n_countsbin.txt");

		for (int i = 0; i<16; i++)
		{
			fout<<//"event "<<setw(3)<<i<<" : " 
			_sig_s_uu->GetBinContent(1,i+1)+
			_sig_s_ud->GetBinContent(1,i+1)<<"      "<<
			_sig_s_du->GetBinContent(1,i+1)+
			_sig_s_dd->GetBinContent(1,i+1)
//			<<" uu "<<_sig_s_uu->GetBinContent(1,i+1)
//			<<" ud "<<_sig_s_ud->GetBinContent(1,i+1)
//			<<" du "<<_sig_s_du->GetBinContent(1,i+1)
//			<<" dd "<<_sig_s_dd->GetBinContent(1,i+1)
			<<endl;
		}
	}

	if (check == 1)
	{
		TH2 *_sig_n_al_blue = (TH2F*)file->Get("_sah_pT_os_sig_n_A_L_Blue");
		TH2 *_sig_s_al_blue = (TH2F*)file->Get("_sah_pT_os_sig_s_A_L_Blue");
		TH2 *_sig_n_al_yellow = (TH2F*)file->Get("_sah_pT_os_sig_n_A_L_Yellow");
                TH2 *_sig_s_al_yellow = (TH2F*)file->Get("_sah_pT_os_sig_s_A_L_Yellow");

		TH2 *_lsb_n_al_blue = (TH2F*)file->Get("_sah_pT_os_lsb_n_A_L_Blue");
                TH2 *_lsb_s_al_blue = (TH2F*)file->Get("_sah_pT_os_lsb_s_A_L_Blue");
                TH2 *_lsb_n_al_yellow = (TH2F*)file->Get("_sah_pT_os_lsb_n_A_L_Yellow");
                TH2 *_lsb_s_al_yellow = (TH2F*)file->Get("_sah_pT_os_lsb_s_A_L_Yellow");

		ofstream fout("al.txt");
		for (int i = 0; i<16; i++)
			fout<<"bin "<<setw(3)<<i<<" : "
			<<setw(15)<<_sig_n_al_blue->GetBinContent(1,i+1)
			<<setw(15)<<_sig_s_al_blue->GetBinContent(1,i+1)
		//	<<setw(15)<<_sig_n_al_yellow->GetBinContent(1,i+1)
                   //     <<setw(15)<<_sig_s_al_yellow->GetBinContent(1,i+1)

			<<setw(15)<<_lsb_n_al_blue->GetBinContent(1,i+1)
                        <<setw(15)<<_lsb_s_al_blue->GetBinContent(1,i+1)
               //         <<setw(15)<<_lsb_n_al_yellow->GetBinContent(1,i+1)
                 //       <<setw(15)<<_lsb_s_al_yellow->GetBinContent(1,i+1)
			

			<<endl;
	}
	
	if (check == 2)
	{
		int fill;
		double polb, poly;	
		double p1,p2, total;
		ifstream fin1("fill_pol.txt");
		ofstream fout("fill_lumi.txt");
		while (fin1>>fill>>polb>>poly)
		{
			char *n1 = Form("RelLumi_FILL_0%d_SUM",fill);
//			char *n2 = Form("RelLumi_FILL_0%d_SUM",fill);
//			char *n3 = Form("RelLumi_FILL_0%d_Pol_Ylue",fill);
			TH1D *_Rel_SUM = (TH1D*)file->Get(n1);
//			TH1D *_Rel_Pol_B=(TH1D*)file->Get(n2);
//			TH1D *_Rel_Pol_Y=(TH1D*)file->Get(n3);
// 			p1 = _Rel_Pol_B->GetBinContent(1)/_Rel_SUM->GetBinContent(1);
			total +=_Rel_SUM->GetBinContent(1);
			fout <<" fill " << fill<< "       "<<"Lumi:   "<< _Rel_SUM->GetBinContent(1) <<endl;
		}
		cout<<"total lumi: " <<total<<endl;
	}