Exemple #1
0
int main() {

	//File PARITY
	std::fstream parity_file("..\\..\\data\\PARITY.txt");
	if (!parity_file)
		return 1;

	std::istream_iterator<long> eos;
	std::istream_iterator<long> iit(parity_file);

	const long rows = *iit++;
	const long cols = *iit++;

	std::vector<std::vector<long>> check(rows), bit(cols);

	std::cout << "Reading PARITY...\n";

	std::chrono::system_clock::time_point start = std::chrono::system_clock::now();

	//Initial bit_connections and check_connections
	while (iit != eos) {
		long left = *iit;
		++iit;
		check[left - 1].push_back(*iit);
		bit[*iit - 1].push_back(left);
		++iit;
	}
	std::chrono::system_clock::time_point end = std::chrono::system_clock::now();

	int sec = std::chrono::duration_cast<std::chrono::seconds>(end - start).count();
	int msec = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() - sec * 1000;
	std::cout << "Done reading in " << sec << " s " << msec << " ms\n";

	//File demodSignal
	std::fstream signal_file("..\\..\\data\\demodSignal.txt");
	if (!signal_file) { std::cout << "Error with opening demodSignal.txt\n" << std::endl; return 1; }

	std::istream_iterator<float> eos_d;
	std::istream_iterator<float> iit_d(signal_file);

	std::vector<float> demodSignal;

	std::cout << "Reading demodSignal...\n";

	start = std::chrono::system_clock::now();

	//Reading demodSignal file
	while (iit_d != eos_d) {
		demodSignal.push_back(*iit_d);
		++iit_d;
	}

	end = std::chrono::system_clock::now();

	sec = std::chrono::duration_cast<std::chrono::seconds>(end - start).count();
	msec = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() - sec * 1000;
	std::cout << "Done reading in " << sec << " s " << msec << " ms\n";

	//Initialization posylka_from_bit_to_check
	std::vector<std::vector<float>> posylka_from_bit_to_check(cols);
	std::vector<std::vector<long>>::iterator iter_p = bit.begin();
	int num_d = 0;//Íîìåð èíäåêñà ñèãíàëà

	std::cout << "Preparing posylka_from_bit_to_check...\n";

	start = std::chrono::system_clock::now();

	while (iter_p != bit.end()) {
		for (int i = 0; i < bit[num_d].size(); i++) {

			posylka_from_bit_to_check[num_d].push_back(demodSignal[num_d]);
		}
		num_d++;
		++iter_p;
	}

	end = std::chrono::system_clock::now();

	sec = std::chrono::duration_cast<std::chrono::seconds>(end - start).count();
	msec = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() - sec * 1000;
	std::cout << "Done preparing in " << sec << " s " << msec << " ms\n";

	//Initialization posylka_from_check_to_bit
	std::vector<std::vector<float>> posylka_from_check_to_bit(rows);

	const int MaxIteration = 50;

	//Íà÷àëàñü îòïðàâêà
	start = std::chrono::system_clock::now();

	for (int n_iter = 0; n_iter < MaxIteration; n_iter++) {
		std::cout << "\n" << n_iter + 1 << " iterations\n";
		std::vector<long>::iterator it_find;
		std::vector<long> d; // Çàïèñûâàåòñÿ èñïðàâëÿåìûé ñèãíàë
		std::vector<float> LQ;

		//std::cout << "Otpravka: \n";

		for (int nn = 0; nn < rows; nn++) {
			std::vector<long> input_indeces = check[nn];
			std::vector<long>::iterator it_ii = input_indeces.begin();
			std::vector<float> posylki;

			//Chto imenno prihodilo:
			while (it_ii != input_indeces.end()) {

				it_find = std::find(bit[*it_ii - 1].begin(), bit[*it_ii - 1].end(), nn + 1);
				int num_it_find = it_find - bit[*it_ii - 1].begin();
				float tmp = posylka_from_bit_to_check[*it_ii - 1][num_it_find];
				++it_ii;
				posylki.push_back(tmp);
			}

			posylka_from_check_to_bit[nn].clear(); // Ñòèðàåì äëÿ çàïîëíåíèÿ îáíîâëåííûìè çíà÷åíèÿìè

			//Formiruem otvet
			for (int kk = 0; kk < input_indeces.size(); kk++) {
				std::vector<float> posyl_minus_1(posylki);

				posyl_minus_1.erase(posyl_minus_1.begin() + kk);
				float gg = g_func(posyl_minus_1);
				posylka_from_check_to_bit[nn].push_back(gg);
			}
		}

		//std::cout << "Otvet:\n";

		//bit node update
		for (int nn = 0; nn < cols; nn++) {
			std::vector<long> input_indeces = bit[nn];
			std::vector<long>::iterator it_ii = input_indeces.begin();
			std::vector<float> posylki;

			//Chto imenno prihodilo:
			while (it_ii != input_indeces.end()) {
				
				it_find = std::find(check[*it_ii - 1].begin(), check[*it_ii - 1].end(), nn + 1);
				int num_it_find = it_find - check[*it_ii - 1].begin();
				float tmp = posylka_from_check_to_bit[*it_ii - 1][num_it_find];
				++it_ii;
				posylki.push_back(tmp);
			}

			posylka_from_bit_to_check[nn].clear();

			//Formiruem otvet
			for (int kk = 0; kk < input_indeces.size(); kk++) {
				std::vector<float> posyl_minus_1(posylki);
				
				posyl_minus_1.erase(posyl_minus_1.begin() + kk);
				float gg = demodSignal[nn] + sum(posyl_minus_1);
				posylka_from_bit_to_check[nn].push_back(gg);
			}

			LQ.push_back(demodSignal[nn] + sum(posylki));
			d.push_back((1 - Sign(LQ[nn])) / 2);
		}

		//Ñîçäàåì è çàïîëíÿåì ñèíäîðì
		std::vector<long> syndrome;
		for (int i = 0; i < rows; i++) {
			std::vector<long> indeces = check[i];
			std::vector<long>::iterator it_ind = indeces.begin();
			std::vector<long> tmp;

			while (it_ind != indeces.end()) {
				tmp.push_back(d[*it_ind - 1]);
				it_ind++;
			}

			syndrome.push_back(fmod(sum(tmp), 2));
		}

		std::cout << "\nErrors: " << sum(syndrome) << std::endl;
		if (sum(syndrome) == 0) { break; }
	}

	end = std::chrono::system_clock::now();

	sec = std::chrono::duration_cast<std::chrono::seconds>(end - start).count();
	msec = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() - sec * 1000;
	std::cout << "\nDone preparing in " << sec << " s " << msec << " ms\n";

	std::cout << "SYNDROME == 0" << std::endl;

	system("pause");

	return 0;
}
Exemple #2
0
void compareWeights(const char* fileName, const std::string plotTitle,
                    const std::string plotType, const std::string plot,
                    const std::string xlabel, const float xMin, const float xMax) {
    gStyle->SetOptStat(0);
    gROOT->ForceStyle();
 
    THStack* histStack = new THStack("histStack", plotTitle.c_str());
    TLegend* legend = new TLegend(.55 ,.55 ,.885 ,.875);
    legend->SetFillColor(kWhite);
     
    std::vector<std::string> weightNames = {"unit wgt = 0.000001"};
                                            //{"f_{T1} = 5e-12 ", "f_{T1} = 4e-12 ", 
                                            //"f_{T1} = 1.5e-12 ", "Standard Model"};
    std::vector<int> colors = {kRed-7, kAzure-3, kGreen-6, kBlack, kBlue-4};

    TFile signal_file(fileName);
    TCanvas* canvas = new TCanvas("canvas","Weight Comparison",150,10,990,660);
    canvas->cd();

    int numBins = 13;
    float rebinPoint = 0;
    double variableBins[numBins+1];
    for (int i = 0; i <= numBins; i++)
    {
        if (i < 10)
            rebinPoint += 75.;
        else if (i < 11)
            rebinPoint += 150.;
        else
            rebinPoint += 200;
        variableBins[i] = rebinPoint;
    }

    std::string bg_path = "/nfs_scratch/kdlong/wpz_zg_qcdbkgd/Events/run_01/";
    bg_path += fileName; 
    addBackground(histStack, bg_path, plotType, plot, legend, "WZ EWK + QCD",
                  variableBins, numBins);

    for (unsigned int i = 0; i < weightNames.size(); i++)
    {
        std::string path = weightNames[i] + "/" + plotType + "/" + plot;
        TH1F* hist = static_cast<TH1F*>(signal_file.GetObjectChecked(path.c_str(), 
                                                                     "TH1F"));
        //hist->SetFillColor(colors[i]);
        hist->SetLineColor(colors[i]);
        hist->SetLineWidth(2);
        TH1* histRebin = hist->Rebin(numBins, "histRebin", variableBins);
        histRebin->Sumw2();
        histStack->Add(histRebin, "hist E1");
        std::string legendName = "WZ EWK (" + weightNames[i] + ")";
        legend->AddEntry(hist, legendName.c_str(), "l");
    }
    
    histStack->Draw("nostack");
    histStack->GetXaxis()->SetTitle(xlabel.c_str());
    histStack->GetYaxis()->SetTitle("Events");
    //histStack->GetXaxis()->SetRangeUser(xMin, xMax); 
    //histStack->SetMaximum(125); 
    histStack->DrawClone("nostack");
    legend->DrawClone("same");
    canvas->Update();
    canvas->Print("WZTMassComp_zg_bg_cuts.pdf");
}