コード例 #1
0
int main(int argc, char **argv)
{
	if (argc < 4) {
		std::cerr << "Syntax: " << argv[0] << " <input> "
		          << "<output> <var1> [<var2>...]" << std::endl;
		return 1;
	}

	ROOT::Cintex::Cintex::Enable();

	std::vector<std::string> names;
	for(int i = 3; i < argc; i++)
		names.push_back(argv[i]);

	try {
		std::auto_ptr<Calibration::VarProcessor> proc(
					getCalibration(argv[1], names));

		BitSet inputVars(names.size());
		for(std::size_t i = 0; i < names.size(); i++)
			inputVars[i] = true;
		proc->inputVars = Calibration::convert(inputVars);

		Calibration::MVAComputer mva;
		std::copy(names.begin(), names.end(),
		          std::back_inserter(mva.inputSet));
		mva.addProcessor(proc.get());
		mva.output = names.size();

		MVAComputer::writeCalibration(argv[2], &mva);
	} catch(cms::Exception e) {
		std::cerr << e.what() << std::endl;
	}

	return 0;
}
コード例 #2
0
ファイル: mvaExtractPDFs.cpp プロジェクト: aashaqshah/cmssw-1
int main(int argc, char **argv)
{
	using Calibration::HistogramF;
	using Calibration::VarProcessor;

	ROOT::Cintex::Cintex::Enable();

	if (argc != 3) {
		std::cerr << "Syntax: " << argv[0] << " <MVA File> "
		          << "<output ROOT file>" << std::endl;
		return 1;
	}

	Calibration::MVAComputer *calib =
		MVAComputer::readCalibration(argv[1]);
	if (!calib)
		return 1;

	std::map<std::string, HistogramF*> histos;

	std::vector<VarProcessor*> procs = calib->getProcessors();
	for(unsigned int z = 0; z < procs.size(); ++z) {
		VarProcessor *proc = procs[z];
		if (!proc)
			continue;

		std::ostringstream ss3;
		ss3 << (z + 1);

		Calibration::ProcLikelihood *lkh =
			dynamic_cast<Calibration::ProcLikelihood*>(proc);
		Calibration::ProcNormalize *norm =
			dynamic_cast<Calibration::ProcNormalize*>(proc);

		if (lkh) {
			for(unsigned int i = 0; i < lkh->pdfs.size(); i++) {
				std::ostringstream ss2;
				ss2 << (i + 1);
				histos["proc" + ss3.str() + "_sig" + ss2.str()] = &lkh->pdfs[i].signal;
				histos["proc" + ss3.str() + "_bkg" + ss2.str()] = &lkh->pdfs[i].background;
			}
		} else if (norm) {
			for(unsigned int i = 0; i < norm->distr.size(); i++) {
				std::ostringstream ss2;
				ss2 << (i + 1);
				histos["proc" + ss3.str() + "_norm" + ss2.str()] = &norm->distr[i];
			}
		}
	}

	TFile *f = TFile::Open(argv[2], "RECREATE");
	if (!f)
		return 2;

	for(std::map<std::string, HistogramF*>::const_iterator iter = histos.begin();
	    iter != histos.end(); ++iter) {
		std::string name = iter->first;
		HistogramF *histo = iter->second;

		unsigned int size = histo->values().size() - 2;
		std::vector<double> values(
				histo->values().begin() + 1,
				histo->values().end() - 1);
		Spline spline;
		spline.set(values.size(), &values.front());

		double min = histo->range().min;
		double max = histo->range().max;

		TH1F *h = new TH1F((name + "_histo").c_str(), (name + "_histo").c_str(),
		                   size, min - 0.5 * (max - min) / size,
		                   max + 0.5 * (max - min) / size);
		TH1F *s = new TH1F((name + "_spline").c_str(), (name + "_spline").c_str(),
		                   size * precision, min, max);

		for(unsigned int i = 0; i < size; i++) {
			h->SetBinContent(i + 1, histo->values()[i + 1]);
			for(int j = 0; j < precision; j++) {
				unsigned int k = i * precision + j;
				double x = (k + 0.5) / (size * precision);
				double v = spline.eval(x);
				s->SetBinContent(k, v);
			}
		}
	}

	f->Write();
	delete f;

	return 0;
}
コード例 #3
0
ファイル: mvaExtractor.cpp プロジェクト: tj710/TTEmulator
int main(int argc, char **argv)
{
    if (argc != 3) {
        std::cerr << "Syntax: " << argv[0] << " <input.mva> "
                  "<output.xml>\n";
        return 1;
    }


    try {
        Calibration::MVAComputer *calib =
            MVAComputer::readCalibration(argv[1]);
        if (!calib) {
            std::cerr << "MVA calibration could not be read."
                      << std::endl;
            return 1;
        }

        std::ofstream out(argv[2]);
        if (!out.good()) {
            std::cerr << "XML description file could not be "
                      "opened for writing."
                      << std::endl;
            return 1;
        }

        out << "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>" << std::endl;
        out << "<MVATrainer>" << std::endl;
        out << "\t<!-- Warning: Auto-generated file from MVA calibration extractor. -->" << std::endl;
        out << "\t<!--          This trainer configuration is incomplete! -->" << std::endl;
        out << "\t<general>" << std::endl;
        out << "\t\t<option name=\"trainfiles\">train_%1$s%2$s.%3$s</option>" << std::endl;
        out << "\t</general>" << std::endl;

        std::vector< std::pair<std::string, std::string> > vars;

        out << "\t<input id=\"input\">" << std::endl;
        for(std::vector<Calibration::Variable>::const_iterator iter =
                    calib->inputSet.begin();
                iter != calib->inputSet.end(); ++iter) {

            out << "\t\t<var name=\"" << escape(iter->name)
                << "\" multiple=\"true\" optional=\"true\"/>"
                << std::endl;
            vars.push_back(std::make_pair("input", iter->name));
        }
        out << "\t</input>" << std::endl;

        unsigned int procId = 0;
        std::string proc = "input";
        std::vector<Calibration::VarProcessor*> procs =
            calib->getProcessors();
        for(std::vector<Calibration::VarProcessor*>::const_iterator
                iter = procs.begin(); iter != procs.end(); ++iter) {
            std::string name = (*iter)->getInstanceName();

            PhysicsTools::BitSet in =
                PhysicsTools::Calibration::convert(
                    (*iter)->inputVars);

            int j = 0;
            for(unsigned int i = vars.size(); i < in.size(); i++) {
                std::string var = mkNumber("var", ++j);
                out << "\t\t\t<var name=\"" << var
                    << "\"/>" << std::endl;

                vars.push_back(std::make_pair(proc, var));
            }

            if (iter != procs.begin()) {
                out << "\t\t</output>" << std::endl;
                out << "\t</processor>" << std::endl;
            }

            proc = mkNumber("proc", ++procId);
            out << "\t<processor id=\"" << proc
                << "\" name=\"" << name << "\">" << std::endl;
            out << "\t\t<input>" << std::endl;

            for(unsigned int i = 0; i < in.size(); i++) {
                if (in[i])
                    out << "\t\t\t<var source=\""
                        << escape(vars.at(i).first)
                        << "\" name=\""
                        << escape(vars.at(i).second)
                        << "\"/>" << std::endl;
            }

            out << "\t\t</input>" << std::endl;
            out << "\t\t<config>" << std::endl;
            out << "\t\t\t<!-- FILL ME -->" << std::endl;
            out << "\t\t</config>" << std::endl;
            out << "\t\t<output>" << std::endl;
        }

        int j = 0;
        for(unsigned int i = vars.size(); i <= calib->output; i++) {
            std::string var = mkNumber("var", ++j);

            out << "\t\t\t<var name=\"" << var
                << "\"/>" << std::endl;

            vars.push_back(std::make_pair(proc, var));
        }

        if (!procs.empty()) {
            out << "\t\t</output>" << std::endl;
            out << "\t</processor>" << std::endl;
        }

        out << "\t<output>" << std::endl;
        out << "\t\t<var source=\""
            << escape(vars.at(calib->output).first)
            << "\" name=\""
            << escape(vars.at(calib->output).second)
            << "\"/>" << std::endl;
        out << "\t</output>" << std::endl;

        out << "</MVATrainer>" << std::endl;
    } catch(cms::Exception e) {
        std::cerr << e.what() << std::endl;
    }

    return 0;
}