コード例 #1
0
ファイル: Globals.cpp プロジェクト: gottardo7/pixie_scan
void Globals::SanityCheck() {
    Messenger m;
    std::stringstream ss;

    if (!(revision_ == "A" || revision_ == "D" || revision_ == "F")) {
        ss << "Globals: unknown revision version named "
           << revision_;
        throw GeneralException(ss.str());
    }

    if (clockInSeconds_ <= 0) {
        ss << "Globals: illegal value of clockInSeconds "
            << clockInSeconds_;
        throw GeneralException(ss.str());
    }

    if (adcClockInSeconds_ <= 0) {
        ss << "Globals: illegal value of adcClockInSeconds "
            << adcClockInSeconds_;
        throw GeneralException(ss.str());
    }

    if (filterClockInSeconds_ <= 0) {
        ss << "Globals: illegal value of filterClockInSeconds "
            << filterClockInSeconds_;
        throw GeneralException(ss.str());
    }

    if (eventInSeconds_ <= 0) {
        ss << "Globals: illegal value of eventInSeconds "
            << eventInSeconds_;
        throw GeneralException(ss.str());
    }

    if (hasReject_) {
        ss << "Total number of rejection regions: " << reject_.size();
        m.detail(ss.str());
    } else {
        ss << "Not using rejection regions";
        m.detail(ss.str());
    }

    ss.str("");
    if (energyContraction_ <= 0) {
        ss << "Globals: Surely you don't want to use Energy contraction = "
            << energyContraction_ << ". I'd better stop the program.";
        throw GeneralException(ss.str());
    } else {
        ss << "Energy contraction: " << energyContraction_;
        m.detail(ss.str());
    }

    m.done();
}
コード例 #2
0
ファイル: TreeCorrelator.cpp プロジェクト: akeeler/pixie_scan
void TreeCorrelator::createPlace(std::map<std::string, std::string>& params,
                                 bool verbose) {
    bool replace = false;
    if (params["replace"] != "")
        replace = strings::to_bool(params["replace"]);

    vector<string> names = split_names(params["name"]);
    for (vector<string>::iterator it = names.begin();
         it != names.end();
         ++it) {

        if (params["type"] != "") {
            if (replace) {
                if (places_.count((*it)) != 1) {
                    stringstream ss;
                    ss << "TreeCorrelator: cannot replace Place " << (*it)
                       << ", it doesn't exist";
                    throw TreeCorrelatorException(ss.str());
                }
                delete places_[(*it)];
                if (verbose) {
                    Messenger m;
                    stringstream ss;
                    ss << "Replacing place " << (*it);
                    m.detail(ss.str(), 1);
                }
            } else {
                if (places_.count((*it)) == 1) {
                    stringstream ss;
                    ss << "TreeCorrelator: place" << (*it) << " already exists";
                    throw TreeCorrelatorException(ss.str());
                }
                if (verbose) {
                    Messenger m;
                    stringstream ss;
                    ss << "Creating place " << (*it);
                    m.detail(ss.str(), 1);
                }
            }
            Place* current = builder.create(params, verbose);
            places_[(*it)] = current;
            if (strings::to_bool(params["init"]))
                current->activate(0.0);
        }

        if (params["parent"] != "root") {
            bool coincidence = strings::to_bool(params["coincidence"]);
            addChild(params["parent"], (*it), coincidence, verbose);
        }

    }
}
コード例 #3
0
ファイル: Notebook.cpp プロジェクト: spaulaus/paass
Notebook::Notebook() {
    pugi::xml_node note = XmlInterface::get()->GetDocument()->child("Configuration").child("Notebook");

    file_name_ = std::string(note.attribute("file").as_string());
    mode_ = std::string(note.attribute("mode").as_string("a"));

    Messenger m;
    m.detail("Notebook: " + file_name_ + " mode: " + mode_);

    std::ofstream note_file;

    if (mode_ == "r") {
        note_file.open(file_name_.c_str(), std::ios::out);
    } else if (mode_ == "a") {
        note_file.open(file_name_.c_str(), std::ios::out | std::ios::app);
    } else {
        std::stringstream ss;
        ss << "Notebook: unknown mode";
        ss << " : " << mode_;
        throw IOException(ss.str());
    }

    if (!note_file.good()) {
        std::stringstream ss;
        ss << "Notebook: error opening output file";
        ss << " : " << file_name_;
        throw IOException(ss.str());
    }
    note_file << "# Starting notebook on : " << currentDateTime() << std::endl;
    note_file.close();
}
コード例 #4
0
ファイル: RawEvent.cpp プロジェクト: spaulaus/paass
DetectorSummary *RawEvent::GetSummary(const std::string &s, bool construct) {
    map<string, DetectorSummary>::iterator it = sumMap.find(s);
    static set <string> nullSummaries;

    Messenger m;
    stringstream ss;
    if (it == sumMap.end()) {
        if (construct) {
            // construct the summary
            ss << "Constructing detector summary for type " << s;
            m.detail(ss.str());
            sumMap.insert(make_pair(s, DetectorSummary(s, eventList)));
            it = sumMap.find(s);
        } else {
            if (nullSummaries.count(s) == 0) {
                ss << "Returning NULL detector summary for type " << s;
                m.detail(ss.str());
                nullSummaries.insert(s);
            }
            return NULL;
        }
    }
    return &(it->second);
}
コード例 #5
0
ファイル: TreeCorrelator.cpp プロジェクト: akeeler/pixie_scan
void TreeCorrelator::addChild(std::string parent, std::string child,
                             bool coin, bool verbose) {
    if (places_.count(parent) == 1 && places_.count(child) == 1) {
        place(parent)->addChild(place(child), coin);
        if (verbose) {
            Messenger m;
            stringstream ss;
            ss << "Setting " << child
                 << " as a child of " << parent;
            m.detail(ss.str(), 1);
        }
    } else {
        stringstream ss;
        ss << "TreeCorrelator: could not set " << child
           << " as a child of " << parent << endl;
        throw TreeCorrelatorException(ss.str());
    }
}
コード例 #6
0
GeProcessor::GeProcessor(double gammaThreshold, double lowRatio,
                         double highRatio, double subEventWindow,
                         double gammaBetaLimit, double gammaGammaLimit):
                         EventProcessor(OFFSET, RANGE, "ge"),
                         leafToClover() {
    associatedTypes.insert("ge"); // associate with germanium detectors

    gammaThreshold_ = gammaThreshold;
    lowRatio_ = lowRatio;
    highRatio_ = highRatio;
    subEventWindow_ = subEventWindow;
    gammaBetaLimit_ = gammaBetaLimit;
    gammaGammaLimit_ = gammaGammaLimit;

    // previously used:
    // in seconds/bin
    // 1e-6, 10e-6, 100e-6, 1e-3, 10e-3, 100e-3
    timeResolution.push_back(5e-3);
    timeResolution.push_back(10e-3);
    if (timeResolution.size() > MAX_TIMEX) {
        stringstream ss;
        ss << "Number of requested time resolution spectra is greater then"
            << " MAX_TIMEX = " << MAX_TIMEX << "."
            << " See GeProcessor.hpp for details.";
        throw GeneralException(ss.str());
    }

#ifdef GGATES
    Messenger m;
    m.detail("Loading Gamma-gamma gates", 1);

    pugi::xml_document doc;
    pugi::xml_parse_result result = doc.load_file("Config.xml");
    if (!result) {
        stringstream ss;
        ss << "DetectorDriver: error parsing file Config.xml";
        ss << " : " << result.description();
        throw IOException(ss.str());
    }

    pugi::xml_node gamma_gates = doc.child("Configuration").child("GammaGates");
    for (pugi::xml_node gate = gamma_gates.child("Gate"); gate;
         gate = gate.next_sibling("Gate")) {
        vector<LineGate> vg;
        bool completeGate = true;
        for (pugi::xml_node line = gate.child("Line"); line;
             line = line.next_sibling("Line")) {
            double min = line.attribute("min").as_double();
            double max = line.attribute("max").as_double();
            LineGate lg = LineGate(min, max);
            if (lg.Check()) {
                vg.push_back(LineGate(min, max));
            } else {
                completeGate = false;
                continue;
            }
        }
        if (vg.size() != 2 && completeGate) {
            throw GeneralException("Gamma-gamma gate size different than 2 is \
not implemented");
        } else {
コード例 #7
0
ファイル: DetectorDriver.cpp プロジェクト: akeeler/pixie_scan
void DetectorDriver::ReadWalkXml() {
    pugi::xml_document doc;

    pugi::xml_parse_result result = doc.load_file("Config.xml");
    if (!result) {
        stringstream ss;
        ss << "DetectorDriver: error parsing file Config.xml";
        ss << " : " << result.description();
        throw GeneralException(ss.str());
    }

    Messenger m;
    m.start("Loading Walk Corrections");

    pugi::xml_node map = doc.child("Configuration").child("Map");
    /** See comment in the similiar place at ReadCalXml() */
    bool verbose = map.attribute("verbose_walk").as_bool();
    for (pugi::xml_node module = map.child("Module"); module;
         module = module.next_sibling("Module")) {
        int module_number = module.attribute("number").as_int(-1);
        for (pugi::xml_node channel = module.child("Channel"); channel;
             channel = channel.next_sibling("Channel")) {
            int ch_number = channel.attribute("number").as_int(-1);
            Identifier chanID = DetectorLibrary::get()->at(module_number,
                                                           ch_number);
            bool corrected = false;
            for (pugi::xml_node walkcorr = channel.child("WalkCorrection");
                walkcorr; walkcorr = walkcorr.next_sibling("WalkCorrection")) {
                string model = walkcorr.attribute("model").as_string("None");
                double min = walkcorr.attribute("min").as_double(0);
                double max =
                  walkcorr.attribute("max").as_double(
                                              numeric_limits<double>::max());

                stringstream pars(walkcorr.text().as_string());
                vector<double> parameters;
                while (true) {
                    double p;
                    pars >> p;
                    if (pars)
                        parameters.push_back(p);
                    else
                        break;
                }
                if (verbose) {
                    stringstream ss;
                    ss << "Module " << module_number
                       << ", channel " << ch_number << ": ";
                    ss << " model: " << model;
                    for (vector<double>::iterator it = parameters.begin();
                         it != parameters.end(); ++it)
                        ss << " " << (*it);
                    m.detail(ss.str(), 1);
                }
                walk.AddChannel(chanID, model, min, max, parameters);
                corrected = true;
            }
            if (!corrected && verbose) {
                stringstream ss;
                ss << "Module " << module_number << ", channel "
                << ch_number << ": ";
                ss << " not corrected for walk";
                m.detail(ss.str(), 1);
            }
        }
    }
    m.done();
}
コード例 #8
0
ファイル: DetectorDriver.cpp プロジェクト: akeeler/pixie_scan
void DetectorDriver::ReadCalXml() {
    pugi::xml_document doc;

    pugi::xml_parse_result result = doc.load_file("Config.xml");
    if (!result) {
        stringstream ss;
        ss << "DetectorDriver: error parsing file Config.xml";
        ss << " : " << result.description();
        throw GeneralException(ss.str());
    }

    Messenger m;
    m.start("Loading Calibration");

    pugi::xml_node map = doc.child("Configuration").child("Map");

    /** Note that before this reading in of the xml file, it was already
     * processed for the purpose of creating the channels map.
     * Some sanity checks (module and channel number) were done there
     * so they are not repeated here/
     */
    bool verbose = map.attribute("verbose_calibration").as_bool();
    for (pugi::xml_node module = map.child("Module"); module;
         module = module.next_sibling("Module")) {
        int module_number = module.attribute("number").as_int(-1);
        for (pugi::xml_node channel = module.child("Channel"); channel;
             channel = channel.next_sibling("Channel")) {
            int ch_number = channel.attribute("number").as_int(-1);
            Identifier chanID = DetectorLibrary::get()->at(module_number,
                                                           ch_number);
            bool calibrated = false;
            for (pugi::xml_node cal = channel.child("Calibration");
                cal; cal = cal.next_sibling("Calibration")) {
                string model = cal.attribute("model").as_string("None");
                double min = cal.attribute("min").as_double(0);
                double max =
                  cal.attribute("max").as_double(numeric_limits<double>::max());

                stringstream pars(cal.text().as_string());
                vector<double> parameters;
                while (true) {
                    double p;
                    pars >> p;
                    if (pars)
                        parameters.push_back(p);
                    else
                        break;
                }
                if (verbose) {
                    stringstream ss;
                    ss << "Module " << module_number << ", channel "
                       << ch_number << ": ";
                    ss << " model-" << model;
                    for (vector<double>::iterator it = parameters.begin();
                         it != parameters.end(); ++it)
                        ss << " " << (*it);
                    m.detail(ss.str(), 1);
                }
                cali.AddChannel(chanID, model, min, max, parameters);
                calibrated = true;
            }
            if (!calibrated && verbose) {
                stringstream ss;
                ss << "Module " << module_number << ", channel "
                   << ch_number << ": ";
                ss << " non-calibrated";
                m.detail(ss.str(), 1);
            }
        }
    }
    m.done();
}
コード例 #9
0
ファイル: DetectorDriver.cpp プロジェクト: akeeler/pixie_scan
void DetectorDriver::LoadProcessors(Messenger& m) {
    pugi::xml_document doc;
    pugi::xml_parse_result result = doc.load_file("Config.xml");
    if (!result) {
        stringstream ss;
        ss << "DetectorDriver: error parsing file Config.xml";
        ss << " : " << result.description();
        throw IOException(ss.str());
    }

    DetectorLibrary::get();

    pugi::xml_node driver = doc.child("Configuration").child("DetectorDriver");
    for (pugi::xml_node processor = driver.child("Processor"); processor;
        processor = processor.next_sibling("Processor")) {
        string name = processor.attribute("name").value();

        m.detail("Loading " + name);
        if (name == "BetaScintProcessor") {
            double gamma_beta_limit =
                processor.attribute("gamma_beta_limit").as_double(200.e-9);
            if (gamma_beta_limit == 200.e-9)
                m.warning("Using default gamme_beta_limit = 200e-9", 1);
            double energy_contraction =
                processor.attribute("energy_contraction").as_double(1.0);
            if (energy_contraction == 1)
                m.warning("Using default energy contraction = 1", 1);
            vecProcess.push_back(new BetaScintProcessor(gamma_beta_limit,
                                                        energy_contraction));
        } else if (name == "GeProcessor") {
            double gamma_threshold =
                processor.attribute("gamma_threshold").as_double(1.0);
            if (gamma_threshold == 1.0)
                m.warning("Using default gamma_threshold = 1.0", 1);
            double low_ratio =
                processor.attribute("low_ratio").as_double(1.0);
            if (low_ratio == 1.0)
                m.warning("Using default low_ratio = 1.0", 1);
            double high_ratio =
                processor.attribute("high_ratio").as_double(3.0);
            if (high_ratio == 3.0)
                m.warning("Using default high_ratio = 3.0", 1);
            double sub_event =
                processor.attribute("sub_event").as_double(100.e-9);
            if (sub_event == 100.e-9)
                m.warning("Using default sub_event = 100e-9", 1);
            double gamma_beta_limit =
                processor.attribute("gamma_beta_limit").as_double(200.e-9);
            if (gamma_beta_limit == 200.e-9)
                m.warning("Using default gamme_beta_limit = 200e-9", 1);
            double gamma_gamma_limit =
                processor.attribute("gamma_gamma_limit").as_double(200.e-9);
            if (gamma_gamma_limit == 200.e-9)
                m.warning("Using default gamma_gamma_limit = 200e-9", 1);
            double cycle_gate1_min =
                processor.attribute("cycle_gate1_min").as_double(0.0);
            if (cycle_gate1_min == 0.0)
                m.warning("Using default cycle_gate1_min = 0.0", 1);
            double cycle_gate1_max =
                processor.attribute("cycle_gate1_max").as_double(0.0);
            if (cycle_gate1_max == 0.0)
                m.warning("Using default cycle_gate1_max = 0.0", 1);
            double cycle_gate2_min =
                processor.attribute("cycle_gate2_min").as_double(0.0);
            if (cycle_gate2_min == 0.0)
                m.warning("Using default cycle_gate2_min = 0.0", 1);
            double cycle_gate2_max =
                processor.attribute("cycle_gate2_max").as_double(0.0);
            if (cycle_gate2_max == 0.0)
                m.warning("Using default cycle_gate2_max = 0.0", 1);
            vecProcess.push_back(new GeProcessor(gamma_threshold, low_ratio,
                high_ratio, sub_event, gamma_beta_limit, gamma_gamma_limit,
                cycle_gate1_min, cycle_gate1_max, cycle_gate2_min,
                cycle_gate2_max));
        } else if (name == "GeCalibProcessor") {
            double gamma_threshold =
                processor.attribute("gamma_threshold").as_double(1);
            double low_ratio =
                processor.attribute("low_ratio").as_double(1);
            double high_ratio =
                processor.attribute("high_ratio").as_double(3);
            vecProcess.push_back(new GeCalibProcessor(gamma_threshold,
                low_ratio, high_ratio));
        } else if (name == "Hen3Processor") {
            vecProcess.push_back(new Hen3Processor());
        } else if (name == "IonChamberProcessor") {
            vecProcess.push_back(new IonChamberProcessor());
        } else if (name == "LiquidScintProcessor") {
            vecProcess.push_back(new LiquidScintProcessor());
        } else if (name == "LogicProcessor") {
            vecProcess.push_back(new LogicProcessor());
        } else if (name == "NeutronScintProcessor") {
            vecProcess.push_back(new NeutronScintProcessor());
        } else if (name == "PositionProcessor") {
            vecProcess.push_back(new PositionProcessor());
        } else if (name == "PulserProcessor") {
            vecProcess.push_back(new PulserProcessor());
        } else if (name == "SsdProcessor") {
            vecProcess.push_back(new SsdProcessor());
        } else if (name == "VandleProcessor") {
            double res = processor.attribute("res").as_double(2.0);
            double offset = processor.attribute("offset").as_double(200.0);
            unsigned int numStarts = processor.attribute("NumStarts").as_int(2);
            vector<string> types =
                strings::tokenize(processor.attribute("types").as_string(),",");
            vecProcess.push_back(new VandleProcessor(types, res,
                offset, numStarts));
        } else if (name == "TeenyVandleProcessor") {
                vecProcess.push_back(new TeenyVandleProcessor());
        } else if (name == "DoubleBetaProcessor") {
            vecProcess.push_back(new DoubleBetaProcessor());
        } else if (name == "PspmtProcessor") {
                vecProcess.push_back(new PspmtProcessor());
        } else if (name == "TemplateProcessor") {
            vecProcess.push_back(new TemplateProcessor());
        } else if (name == "TemplateExpProcessor") {
            vecProcess.push_back(new TemplateExpProcessor());
	}
#ifdef useroot
        else if (name == "RootProcessor") {
            vecProcess.push_back(new RootProcessor("tree.root", "tree"));
        }
#endif
        else {
            stringstream ss;
            ss << "DetectorDriver: unknown processor type" << name;
            throw GeneralException(ss.str());
        }
        stringstream ss;
        for (pugi::xml_attribute_iterator ait = processor.attributes_begin();
            ait != processor.attributes_end(); ++ait) {
            ss.str("");
            ss << ait->name();
            if (ss.str().compare("name") != 0) {
                ss << " = " << ait->value();
                m.detail(ss.str(), 1);
            }
        }
    }

    for (pugi::xml_node analyzer = driver.child("Analyzer"); analyzer;
        analyzer = analyzer.next_sibling("Analyzer")) {
        string name = analyzer.attribute("name").value();
        m.detail("Loading " + name);

	if(name == "TraceFilterAnalyzer") {
	    vecAnalyzer.push_back(new TraceFilterAnalyzer());
	}/* else if (name == "DoubleTraceAnalyzer") {
            double gain_match = analyzer.attribute("gain_match").as_double(1.0);
            if (gain_match == 1.0)
                m.warning("Using gain_match = 1.0", 1);
            int fast_rise = analyzer.attribute("fast_rise").as_int(10);
            if (fast_rise == 10)
                m.warning("Using fast_rise = 10", 1);
            int fast_gap = analyzer.attribute("fast_gap").as_int(10);
            if (fast_gap == 10)
                m.warning("Using fast_gap = 10", 1);
            int fast_threshold =
                analyzer.attribute("fast_threshold").as_int(50);
            if (fast_threshold == 50)
                m.warning("Using fast_threshold = 50", 1);
            int energy_rise = analyzer.attribute("energy_rise").as_int(50);
            if (energy_rise == 50)
                m.warning("Using energy_rise = 50", 1);
            int energy_gap = analyzer.attribute("energy_gap").as_int(50);
            if (energy_gap == 50)
                m.warning("Using energy_gap = 50", 1);
            int slow_rise = analyzer.attribute("slow_rise").as_int(20);
            if (slow_rise == 20)
                m.warning("Using slow_rise = 20", 1);
            int slow_gap = analyzer.attribute("slow_gap").as_int(20);
            if (slow_gap == 20)
                m.warning("Using slow_gap = 20", 1);
            int slow_threshold =
                analyzer.attribute("slow_threshold").as_int(10);
            if (slow_threshold == 10)
                m.warning("Using slow_threshold = 10", 1);
            else if (name == "DoubleTraceAnalyzer")
                vecAnalyzer.push_back(new DoubleTraceAnalyzer(gain_match,
                    fast_rise, fast_gap, fast_threshold, energy_rise,
                    energy_gap, slow_rise, slow_gap, slow_threshold));
		    }*/ else if (name == "TauAnalyzer") {
            vecAnalyzer.push_back(new TauAnalyzer());
        } else if (name == "TraceExtractor") {
            string type = analyzer.attribute("type").as_string();
            string subtype = analyzer.attribute("subtype").as_string();
            string tag = analyzer.attribute("tag").as_string();
            vecAnalyzer.push_back(new TraceExtractor(type, subtype,tag));
        } else if (name == "WaveformAnalyzer") {
            vecAnalyzer.push_back(new WaveformAnalyzer());
        } else if (name == "FittingAnalyzer") {
            vecAnalyzer.push_back(new FittingAnalyzer());
        } else if (name == "CfdAnalyzer") {
            vecAnalyzer.push_back(new CfdAnalyzer());
        } else {
            stringstream ss;
            ss << "DetectorDriver: unknown analyzer type" << name;
            throw GeneralException(ss.str());
        }

        for (pugi::xml_attribute_iterator ait = analyzer.attributes_begin();
             ait != analyzer.attributes_end(); ++ait) {
            stringstream ss;
            ss << ait->name();
            if (ss.str().compare("name") != 0) {
                ss << " = " << ait->value();
                m.detail(ss.str(), 1);
            }
        }
    }
}
コード例 #10
0
ファイル: Globals.cpp プロジェクト: gottardo7/pixie_scan
Globals::Globals() {
    clockInSeconds_ = -1;
    adcClockInSeconds_ = -1;
    filterClockInSeconds_ = -1;
    eventInSeconds_ = -1;
    energyContraction_ = 1.0;
    hasReject_ = false;
    revision_ = "None";
    numTraces_  = 16;

    try {
        pugi::xml_document doc;
        pugi::xml_parse_result result = doc.load_file("Config.xml");

        std::stringstream ss;
        if (!result) {
            ss << "Globals : error parsing file " << "Config.xml";
            ss << " : " << result.description();
            throw GeneralException(ss.str());
        }

        Messenger m;
        pugi::xml_node description =
            doc.child("Configuration").child("Description");
        std::string desc_text = description.text().get();
        m.detail("Experiment: " + desc_text);

        m.start("Loading global parameters");
        pugi::xml_node global = doc.child("Configuration").child("Global");
        for (pugi::xml_node_iterator it = global.begin();
                                    it != global.end(); ++it) {
            if (std::string(it->name()).compare("Revision") == 0) {
                revision_ = it->attribute("version").as_string();
                ss << "Revision: " << revision_;
                m.detail(ss.str());
                ss.str("");

                if (revision_ == "A") {
                    clockInSeconds_ = 10e-9;
                    adcClockInSeconds_ = 10e-9;
                    filterClockInSeconds_ = 10e-9;
                    maxWords_ = IO_BUFFER_LENGTH;
                } else if (revision_ == "D") {
                    clockInSeconds_ = 10e-9;
                    adcClockInSeconds_ = 10e-9;
                    filterClockInSeconds_ = 10e-9;
                    maxWords_ = EXTERNAL_FIFO_LENGTH;
                } else if (revision_ == "F" || revision_ == "DF") {
                    clockInSeconds_ = 8e-9;
                    adcClockInSeconds_ = 4e-9;
                    filterClockInSeconds_ = 8e-9;
                    maxWords_ = EXTERNAL_FIFO_LENGTH;
                } else {
                    throw GeneralException("Globals: unknown revision version "
                                           + revision_);
                }

            } else if (std::string(it->name()).compare("EventWidth") == 0) {

                std::string units = it->attribute("unit").as_string("None");
                double value = it->attribute("value").as_double(-1);

                if (units == "ns")
                    value *= 1e-9;
                else if (units == "us")
                    value *= 1e-6;
                else if (units == "ms")
                    value *= 1e-3;
                else if (units == "s")
                    value *= 1.0;
                else
                    throw GeneralException("Globals: unknown units " + units);

                eventInSeconds_ = value;
                eventWidth_ = (int)(eventInSeconds_ / clockInSeconds_);
                ss << "Event width: " << eventInSeconds_ * 1e6
                   << " us" << ", i.e. " << eventWidth_
                   << " pixie16 clock tics.";
                m.detail(ss.str());
                ss.str("");
            } else if (std::string(it->name()).compare("EnergyContraction") == 0) {
                energyContraction_ = it->attribute("value").as_double(1);
            } else if (std::string(it->name()).compare("Path") == 0) {
                configPath_ =  it->text().get();
                m.detail("Path to other configuration files: " + configPath_);
            } else if (std::string(it->name()).compare("NumOfTraces") == 0) {
                numTraces_ =  it->attribute("value").as_uint();
            } else
                WarnOfUnknownParameter(m, it);
        }

        unsigned int power2 = 1;
        unsigned int maxDammSize = 16384;
        while (power2 < numTraces_ && power2 < maxDammSize) {
            power2 *= 2;
        }
        ss << "Number of traces set to " << power2 << " ("
           << numTraces_ << ")";
        m.detail(ss.str());
        ss.str("");
        numTraces_ = power2;

        m.detail("Loading rejection regions");
        pugi::xml_node reject = doc.child("Configuration").child("Reject");
        for (pugi::xml_node time = reject.child("Time"); time;
            time = time.next_sibling("Time")) {
            int start = time.attribute("start").as_int(-1);
            int end = time.attribute("end").as_int(-1);

            std::stringstream ss;
            if (start < 0 || end < 0 || start > end) {
                ss << "Globals: incomplete or wrong rejection region "
                <<  "declaration: " << start << ", " << end;
                throw GeneralException(ss.str());
            }

            ss << "Rejection region: " << start << " to " << end << " s";
            m.detail(ss.str(), 1);
            std::pair<int, int> region(start, end);
            reject_.push_back(region);
        }

        if (reject_.size() > 0) {
            hasReject_ = true;
        }

        pugi::xml_node timing = doc.child("Configuration").child("Timing");

        for(pugi::xml_node_iterator it = timing.child("Physical").begin();
            it != timing.child("Physical").end(); ++it) {
            if(std::string(it->name()).compare("NeutronMass") == 0)
                neutronMass_ = it->attribute("value").as_double();
            else if(std::string(it->name()).compare("SpeedOfLight") == 0)
                speedOfLight_ = it->attribute("value").as_double();
            else if(std::string(it->name()).compare("SpeedOfLightSmall") == 0)
                speedOfLightSmall_ = it->attribute("value").as_double();
            else if(std::string(it->name()).compare("SpeedOfLightBig") == 0)
                speedOfLightBig_ = it->attribute("value").as_double();
            else if(std::string(it->name()).compare("SpeedOfLightMedium") == 0)
                speedOfLightMedium_ = it->attribute("value").as_double();
            else if(std::string(it->name()).compare("SmallLength") == 0)
                smallLength_ = it->attribute("value").as_double();
            else if(std::string(it->name()).compare("MediumLength") == 0)
                mediumLength_ = it->attribute("value").as_double();
            else if(std::string(it->name()).compare("BigLength") == 0)
                bigLength_ = it->attribute("value").as_double();
            else
                WarnOfUnknownParameter(m, it);
        }

        for(pugi::xml_node_iterator it = timing.child("Trace").begin();
            it != timing.child("Trace").end(); ++it) {
            if(std::string(it->name()).compare("WaveformRange") == 0) {
                waveformRange_.first =
                    it->child("Low").attribute("value").as_int(5);
                waveformRange_.second =
                    it->child("High").attribute("value").as_int(10);
            } else if(std::string(it->name()).compare("SiPmtWaveformRange") == 0) {
                siPmtWaveformRange_.first =
                    it->child("Low").attribute("value").as_int(5);
                siPmtWaveformRange_.second =
                    it->child("High").attribute("value").as_int(5);
            } else if(std::string(it->name()).compare("LaBr3WaveformRange") == 0) {
                labr3WaveformRange_.first =
                    it->child("Low").attribute("value").as_int(10);
                labr3WaveformRange_.second =
                    it->child("High").attribute("value").as_int(15);
            } else if(std::string(it->name()).compare("DiscriminationStart") == 0)
                discriminationStart_ = it->attribute("value").as_double();
            else if(std::string(it->name()).compare("TrapezoidalWalk") == 0)
                trapezoidalWalk_ = it->attribute("value").as_double();
            else if(std::string(it->name()).compare("TraceDelay") == 0)
                traceDelay_ = it->attribute("value").as_double();
            else if(std::string(it->name()).compare("TraceLength") == 0)
                traceLength_ = it->attribute("value").as_double();
            else if(std::string(it->name()).compare("QdcCompression") == 0)
                qdcCompression_ = it->attribute("value").as_double();
            else
                WarnOfUnknownParameter(m, it);
        }

        for(pugi::xml_node_iterator it = timing.child("Fitting").begin();
            it != timing.child("Fitting").end(); ++it) {
            if(std::string(it->name()).compare("SigmaBaselineThresh") == 0)
                sigmaBaselineThresh_ = it->attribute("value").as_double();
            else if(std::string(it->name()).compare("SiPmtSigmaBaselineThresh") == 0)
                siPmtSigmaBaselineThresh_ = it->attribute("value").as_double();
            else if (std::string(it->name()).compare("Vandle") == 0) {
                smallVandlePars_.first =
                    it->child("Small").child("Beta").attribute("value").as_double();
                smallVandlePars_.second =
                    it->child("Small").child("Gamma").attribute("value").as_double();
                mediumVandlePars_.first =
                    it->child("Medium").child("Beta").attribute("value").as_double();
                mediumVandlePars_.second =
                    it->child("Medium").child("Gamma").attribute("value").as_double();
                bigVandlePars_.first =
                    it->child("Big").child("Beta").attribute("value").as_double();
                bigVandlePars_.second =
                    it->child("Big").child("Gamma").attribute("value").as_double();
                tvandlePars_.first =
                    it->child("TeenyVandle").child("Beta").attribute("value").as_double();
                tvandlePars_.second =
                    it->child("TeenyVandle").child("Gamma").attribute("value").as_double();
            }else if (std::string(it->name()).compare("SingleBeta") == 0) {
                singleBetaPars_.first =
                    it->child("Beta").attribute("value").as_double();
                singleBetaPars_.second =
                    it->child("Gamma").attribute("value").as_double();
            }else if(std::string(it->name()).compare("DoubleBeta") == 0) {
                doubleBetaPars_.first = 0.0;
                doubleBetaPars_.second =
                    it->child("Gamma").attribute("value").as_double();
            }else if (std::string(it->name()).compare("Pulser") == 0) {
                pulserPars_.first =
                    it->child("Beta").attribute("value").as_double();
                pulserPars_.second =
                    it->child("Gamma").attribute("value").as_double();
            }else if (std::string(it->name()).compare("Liquid") == 0) {
                liquidScintPars_.first =
                    it->child("Beta").attribute("value").as_double();
                liquidScintPars_.second =
                    it->child("Gamma").attribute("value").as_double();
            }else if (std::string(it->name()).compare("LaBr3") == 0) {
                labr3_r6231_100Pars_.first =
                    it->child("r6231_100").child("Beta").attribute("value").as_double(0);
                labr3_r6231_100Pars_.second =
                    it->child("r6231_100").child("Gamma").attribute("value").as_double(0);
                labr3_r7724_100Pars_.first =
                    it->child("r7724_100").child("Beta").attribute("value").as_double(0);
                labr3_r7724_100Pars_.second =
                    it->child("r7724_100").child("Gamma").attribute("value").as_double(0);
            }else
                WarnOfUnknownParameter(m, it);
        }

        SanityCheck();
    } catch (std::exception &e) {
        std::cout << "Exception caught at Globals" << std::endl;
        std::cout << "\t" << e.what() << std::endl;
        exit(EXIT_FAILURE);
    }
}
コード例 #11
0
ファイル: PixieStd.cpp プロジェクト: kmiernik/pixie_scan
/**
 * At various points in the processing of data in ScanList(), HistoStats() is
 * called to increment some low level pixie16 informational and diagnostic
 * spectra.  The list of spectra filled includes runtime in second and
 * milliseconds, the deadtime, time between events, and time width of an event.
 * \param [in] id : the id of the channel
 * \param [in] diff : The difference between current clock and last one
 * \param [in] clock : The current clock
 * \param [in] event : The type of event we are dealing with
 */
void HistoStats(unsigned int id, double diff, double clock, HistoPoints event) {
    static const int specNoBins = SE;

    static double start, stop;
    static int count;
    static double firstTime = 0.;
    static double bufStart;

    double runTimeSecs   = (clock - firstTime) *
                           Globals::get()->clockInSeconds();
    int    rowNumSecs    = int(runTimeSecs / specNoBins);
    double remainNumSecs = runTimeSecs - rowNumSecs * specNoBins;

    double runTimeMsecs   = runTimeSecs * 1000;
    int    rowNumMsecs    = int(runTimeMsecs / specNoBins);
    double remainNumMsecs = runTimeMsecs - rowNumMsecs * specNoBins;

    static double bufEnd = 0, bufLength = 0;
    // static double deadTime = 0 // not used
    DetectorDriver* driver = DetectorDriver::get();
    Messenger messenger;
    stringstream ss;

    if (firstTime > clock) {
        ss << "Backwards clock jump detected: prior start " << firstTime
           << ", now " << clock;
        messenger.warning(ss.str());
        ss.str("");
        // detect a backwards clock jump which occurs when some of the
        //   last buffers of a previous run sneak into the beginning of the
        //   next run, elapsed time of last buffers is usually small but
        //   just in case make some room for it
        double elapsed = stop - firstTime;
        // make an artificial 10 second gap by
        //   resetting the first time accordingly
        firstTime = clock - 10 / Globals::get()->clockInSeconds() - elapsed;
        ss << elapsed * Globals::get()->clockInSeconds()
           << " prior seconds elapsed "
           << ", resetting first time to " << firstTime;
        messenger.detail(ss.str());
        ss.str("");
    }

    switch (event) {
        case BUFFER_START:
            bufStart = clock;
            if(firstTime == 0.) {
                firstTime = clock;
            } else if (bufLength != 0.){
                //plot time between buffers as a function
                //of time - dead time spectrum
                // deadTime += (clock - bufEnd)*pixie::clockInSeconds;
                // plot(DD_DEAD_TIME_CUMUL,remainNumSecs,rownum,int(deadTime/runTimeSecs));
                driver->plot(dammIds::raw::DD_BUFFER_START_TIME, remainNumSecs,
                             rowNumSecs, (clock-bufEnd)/bufLength*1000.);
            }
            break;
        case BUFFER_END:
            driver->plot(D_BUFFER_END_TIME, (stop - bufStart) *
                                      Globals::get()->clockInSeconds() * 1000);
            bufEnd = clock;
            bufLength = clock - bufStart;
        case EVENT_START:
            driver->plot(D_EVENT_LENGTH, stop - start);
            driver->plot(D_EVENT_GAP, diff);
            driver->plot(D_EVENT_MULTIPLICITY, count);

            start = stop = clock; // reset the counters
            count = 1;
            break;
        case EVENT_CONTINUE:
            count++;
            if(diff > 0.) {
                driver->plot(D_SUBEVENT_GAP, diff + 100);
            }
            stop = clock;
            break;
        default:
            ss << "Unexpected type " << event << " given to HistoStats";
            messenger.warning(ss.str());
            ss.str("");
    }

    //fill these spectra on all events, id plots and runtime.
    // Exclude event type 0/1 since it will also appear as an
    // event type 11
    if ( event != BUFFER_START && event != BUFFER_END ){
        driver->plot(DD_RUNTIME_SEC, remainNumSecs, rowNumSecs);
        driver->plot(DD_RUNTIME_MSEC, remainNumMsecs, rowNumMsecs);
        //fill scalar spectrum (per second)
        driver->plot(D_HIT_SPECTRUM, id);
        driver->plot(D_SCALAR + id, runTimeSecs);
    }
}
コード例 #12
0
ファイル: PixieStd.cpp プロジェクト: kmiernik/pixie_scan
extern "C" void hissub_(unsigned short *ibuf[],unsigned short *nhw)
#endif
{
    static float hz = sysconf(_SC_CLK_TCK); // get the number of clock ticks per second
    static clock_t clockBegin; // initialization time
    static struct tms tmsBegin;

    vector<ChanEvent*> eventList; // vector to hold the events

    /* Pointer to singleton DetectorLibrary class */
    DetectorLibrary* modChan = DetectorLibrary::get();
    /* Pointer to singleton DetectorDriver class */
    DetectorDriver* driver = DetectorDriver::get();
    /* Screen messenger */
    Messenger messenger;
    stringstream ss;

    // local version of ibuf pointer
    word_t *lbuf;

    int retval = 0; // return value from various functions

    unsigned long bufLen;

    /*
      Various event counters
    */
    unsigned long numEvents = 0;
    static int counter = 0; // the number of times this function is called
    static int evCount;     // the number of times data is passed to ScanList
    static unsigned int lastVsn; // the last vsn read from the data
    time_t theTime = 0;

    /*
      Assign the local variable lbuf to the variable ibuf which is passed into
      the routine.  The difference between the new and old pixie16 readouts is
      the type of the variable and source of the variable ibuf.

      In the new readout ibuf is from a C++ function and is of type unsigned int*
      In the old readout ibuf is from a Fortran function and is of type
      unsigned short*

      This results in two different assignment statements depending on
      the readout.
    */
#ifdef newreadout
    lbuf=(word_t *)ibuf[0];
#else
    lbuf=(word_t *)ibuf; //old readout
#endif

    /* Initialize the scan program before the first event */
    if (counter==0) {
        /* Retrieve the current time for use later to determine the total
        * running time of the analysis.
        */
        messenger.start("Initializing scan");

        string revision = Globals::get()->revision();
        // Initialize function pointer to point to
        // correct version of ReadBuffData
        if (revision == "D" || revision == "F")
            ReadBuffData = ReadBuffDataDF;
        else if (revision == "A")
            ReadBuffData = ReadBuffDataA;

        clockBegin = times(&tmsBegin);

        ss << "First buffer at " << clockBegin << " sys time";
        messenger.detail(ss.str());
        ss.str("");

        /* After completion the descriptions of all channels are in the modChan
        * vector, the DetectorDriver and rawevent have been initialized with the
        * detectors that will be used in this analysis.
        */
        modChan->PrintUsedDetectors(rawev);
        driver->Init(rawev);

        /* Make a last check to see that everything is in order for the driver
        * before processing data. SanityCheck function throws exception if
        * something went wrong.
        */
        try {
            driver->SanityCheck();
        } catch (GeneralException &e) {
            messenger.fail();
            cout << "Exception caught while checking DetectorDriver"
                 << " sanity in PixieStd" << endl;
            cout << "\t" << e.what() << endl;
            exit(EXIT_FAILURE);
        } catch (GeneralWarning &w) {
            cout << "Warning caught during checking DetectorDriver"
                 << " at PixieStd" << endl;
            cout << "\t" << w.what() << endl;
        }

        lastVsn=-1; // set last vsn to -1 so we expect vsn 0 first

        ss << "Init at " << times(&tmsBegin) << " sys time.";
        messenger.detail(ss.str());
        messenger.done();
    }
    counter++;

    unsigned int nWords=0;  // buffer counter, reset only for new buffer

    // true if the buffer being analyzed is split across a spill from pixie
    bool multSpill;

    do {
        word_t vsn = pixie::U_DELIMITER;
        //true if spill had all vsn's
        bool fullSpill = false;
        //assume all buffers are not split between spills
        multSpill = false;

        /* while the current location in the buffer has not gone beyond the end
         * of the buffer (ignoring the last three delimiters,
         * continue reading */
        while (nWords < (nhw[0]/2 - 6)) {
            /*
            Retrieve the record length and the vsn number
            */
            word_t lenRec = lbuf[nWords];
            vsn = lbuf[nWords+1];

            /* If the record length is -1 (after end of spill), increment the
            location in the buffer by two and start over with the while loop
            */
            if (lenRec == pixie::U_DELIMITER) {
                nWords += 2;  // increment two whole words and try again
                continue;
            }
            // Buffer with vsn 1000 was inserted with
            // the time for superheavy exp't
            if (vsn == pixie::clockVsn) {
                memcpy(&theTime, &lbuf[nWords+2], sizeof(time_t));
                nWords += lenRec;
            }

            /* If the record length is 6, this is an empty channel.
             * Skip this vsn and continue with the next
            */
            //! Revision specific, so move to ReadBuffData
            if (lenRec == 6) {
                nWords += lenRec+1; // one additional word for delimiter
                lastVsn=vsn;
                continue;
            }
            /* If both the current vsn inspected is within an
             * acceptable range, begin reading the buffer.
             */
            if ( vsn < modChan->GetPhysicalModules()  ) {
                if ( lastVsn != pixie::U_DELIMITER) {
                // the modules should be read out cyclically
                    if ( ((lastVsn+1) % modChan->GetPhysicalModules() ) !=
                           vsn ) {
#ifdef VERBOSE
                            ss << " MISSING BUFFER " << vsn << "/"
                            << modChan->GetPhysicalModules()
                            << " -- lastVsn = " << lastVsn << "  "
                            << ", length = " << lenRec;
                            messenger.warning(ss.str());
                            ss.str("");
#endif
                            RemoveList(eventList);
                            fullSpill=true;
                    }
                }
                /* Read the buffer.  After read, the vector eventList will
                   contain pointers to all channels that fired in this buffer
                */
                retval= (*ReadBuffData)(&lbuf[nWords], &bufLen, eventList);
                /* If the return value is less than the error code,
                   reading the buffer failed for some reason.
                   Print error message and reset variables if necessary
                 */
                if ( retval <= readbuff::ERROR ) {
                    ss << " READOUT PROBLEM " << retval
                       << " in event " << counter;
                    messenger.warning(ss.str());
                    ss.str("");
                    if ( retval == readbuff::ERROR ) {
                        ss << "  Remove list " << lastVsn
                           << " " << vsn;
                        RemoveList(eventList);
                        messenger.warning(ss.str());
                        ss.str("");
                    }
                    return;
                } else if ( retval == 0 ) {
                    // empty buffers are regular in Rev. D data
                    // cout << " EMPTY BUFFER" << endl;
                    nWords += lenRec + 1;
                    lastVsn = vsn;
                    continue;
                } else if ( retval > 0 ) {
                    /* increment the total number of events observed */
                    numEvents += retval;
                }
                /* Update the variables that are keeping track of what has been
                   analyzed and increment the location in the current buffer
                */
                    lastVsn = vsn;
                    nWords += lenRec+1; // one extra word for delimiter
            } else {
                // bail out if we have lost our place,
                //   (bad vsn) and process events
                if (vsn != 9999 && vsn != pixie::clockVsn) {
#ifdef VERBOSE
                    ss << "UNEXPECTED VSN " << vsn;
                    messenger.warning(ss.str());
                    ss.str("");
#endif
                }
                break;
            }
        } // while still have words
        if (nWords > nhw[0] / 2 - 6) {
            ss << "This actually happens!";
            messenger.run_message(ss.str());
            ss.str("");
        }

        /* If the vsn is 9999 this is the end of a spill, signal this buffer
           for processing and determine if the buffer is split between spills.
        */
            if ( vsn == 9999 || vsn == pixie::clockVsn ) {
                fullSpill = true;
                nWords += 3;//skip it
                if (lbuf[nWords+1] != pixie::U_DELIMITER) {
                    ss << "this actually happens!";
                    messenger.warning(ss.str());
                    ss.str("");
                    multSpill = true;
                }
                lastVsn=pixie::U_DELIMITER;
            }

            /* if there are events to process, continue */
            if( numEvents > 0 ) {
                if (fullSpill) { 	  // if full spill process events
                    // sort the vector of pointers eventlist according to time
                    double lastTimestamp = (*(eventList.rbegin()))->GetTime();

                    sort(eventList.begin(),eventList.end(),CompareTime);
                    driver->CorrelateClock(lastTimestamp, theTime);

                    /* once the vector of pointers eventlist is sorted
                     * based on time, begin the event processing in ScanList()
                    */
                    ScanList(eventList, rawev);

                    /* once the eventlist has been scanned, remove it
                     * from memory and reset the number of events to zero
                     * and update the event counter
                    */

                    evCount++;
                    /*
                    every once in a while (when evcount is a multiple of 1000)
                    print the time elapsed doing the analysis
                    */
                    if(evCount % 1000 == 0 || evCount == 1) {
                        tms tmsNow;
                        clock_t clockNow = times(&tmsNow);

                        stringstream ss;
                        if (theTime != 0) {
                            string timestamp = string(ctime(&theTime));
                            timestamp.erase(timestamp.find_last_not_of(" \t\n\r") + 1);
                            ss << "Data read up to poll status time "
                            << timestamp;
                            messenger.run_message(ss.str());
                            ss.str("");
                        }
                        ss << "buffer = " << evCount << ", user time = "
                           << (tmsNow.tms_utime - tmsBegin.tms_utime) / hz
                           << ", system time = "
                           << (tmsNow.tms_stime - tmsBegin.tms_stime) / hz
                           << ", real time = "
                           << (clockNow - clockBegin) / hz
                           << ", ts = " << lastTimestamp;
                        messenger.run_message(ss.str());
                    }
                    RemoveList(eventList);
                    numEvents = 0;
                } // end fullSpill
                else {
                    stringstream ss;
                    ss << "Spill split between buffers";
                    messenger.run_message(ss.str());
                    //! this tosses out all events read into the vector so far
                    return;
                }
            }  // end numEvents > 0
            else if (retval != readbuff::STATS) {
                stringstream ss;
                ss << "bad buffer, numEvents = " << numEvents;
                messenger.warning(ss.str());
                return;
            }
    } while (multSpill); // end while loop over multiple spills
    return;
}