CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

pftools::CalibCompare Class Reference

#include <CalibCompare.h>

List of all members.

Public Member Functions

 CalibCompare (IO *options)
void calibrateCalibratables (TChain &sourceTree, const std::string &exercisefile)
void evaluateCalibrations (TTree &tree, pftools::Calibratable *calibrated, const std::vector< pftools::Calibratable > &calibVec)
void setTarget (CalibrationTarget t)
virtual ~CalibCompare ()

Private Member Functions

 CalibCompare (const CalibCompare &)
void operator= (const CalibCompare &)

Private Attributes

PFClusterCalibration clusterCalibration_
unsigned debug_
Erl_mlp erlCalibration_
double mlpOffset_
double mlpSlope_
IOoptions_
CalibrationTarget target_
bool withOffset_

Detailed Description

Definition at line 23 of file CalibCompare.h.


Constructor & Destructor Documentation

CalibCompare::CalibCompare ( IO options)

Definition at line 28 of file CalibCompare.cc.

References clusterCalibration_, gather_cfg::cout, debug_, erlCalibration_, pftools::PFClusterCalibration::getKnownSectorNames(), pftools::IO::GetOpt(), i, mlpOffset_, mlpSlope_, h::names, options_, pftools::PFClusterCalibration::setAllowNegativeEnergy(), pftools::PFClusterCalibration::setBarrelBoundary(), pftools::PFClusterCalibration::setCorrections(), pftools::PFClusterCalibration::setDoCorrection(), pftools::PFClusterCalibration::setDoEtaCorrection(), pftools::PFClusterCalibration::setEcalHcalEnergyCuts(), pftools::PFClusterCalibration::setEtaCorrectionParameters(), pftools::PFClusterCalibration::setEvolutionParameters(), pftools::PFClusterCalibration::setMaxEToCorrect(), pftools::Erl_mlp::setOffsetAndSlope(), and withOffset_.

                                      :
        withOffset_(false), target_(CLUSTER), options_(options), debug_(0),
                        mlpOffset_(0.0), mlpSlope_(1.0) {

        options_->GetOpt("exercises", "withOffset", withOffset_);
        options_->GetOpt("exercises", "debug", debug_);

        /* Initialise PFClusterCalibration appropriately. */
        double g0, g1, e0, e1;
        options_->GetOpt("correction", "globalP0", g0);
        options_->GetOpt("correction", "globalP1", g1);
        options_->GetOpt("correction", "lowEP0", e0);
        options_->GetOpt("correction", "lowEP1", e1);
        clusterCalibration_.setCorrections(e0, e1, g0, g1);

        double ecalECut, hcalECut;
        options_->GetOpt("evolution", "ecalECut", ecalECut);
        options_->GetOpt("evolution", "hcalECut", hcalECut);
        clusterCalibration_.setEcalHcalEnergyCuts(ecalECut, hcalECut);

        int allowNegative(0);
        options_->GetOpt("correction", "allowNegativeEnergy", allowNegative);
        clusterCalibration_.setAllowNegativeEnergy(allowNegative);

        int doCorrection(1);
        options_->GetOpt("correction", "doCorrection", doCorrection);
        clusterCalibration_.setDoCorrection(doCorrection);

        int doEtaCorrection(0);
        options_->GetOpt("correction", "doEtaCorrection", doEtaCorrection);
        clusterCalibration_.setDoEtaCorrection(doEtaCorrection);

        double barrelEta;
        options_->GetOpt("evolution", "barrelEndcapEtaDiv", barrelEta);
        clusterCalibration_.setBarrelBoundary(barrelEta);

        double maxEToCorrect(100.0);
        options_->GetOpt("correction", "maxEToCorrect", maxEToCorrect);
        clusterCalibration_.setMaxEToCorrect(maxEToCorrect);

        std::vector<std::string>* names = clusterCalibration_.getKnownSectorNames();
        for (std::vector<std::string>::iterator i = names->begin(); i
                        != names->end(); ++i) {
                std::string sector = *i;
                std::vector<double> params;
                options_->GetOpt("evolution", sector.c_str(), params);
                clusterCalibration_.setEvolutionParameters(sector, params);
        }

        std::vector<double> etaParams;
        options_->GetOpt("evolution", "etaCorrection", etaParams);
        clusterCalibration_.setEtaCorrectionParameters(etaParams);

        std::cout << clusterCalibration_ << "\n";

        options_->GetOpt("correction", "mlpOffset", mlpOffset_);
        options_->GetOpt("correction", "mlpSlope", mlpSlope_);

        erlCalibration_.setOffsetAndSlope(mlpOffset_, mlpSlope_);

        if (debug_ > 0)
                std::cout << __PRETTY_FUNCTION__ << ": finished.\n";

}
CalibCompare::~CalibCompare ( ) [virtual]

Definition at line 25 of file CalibCompare.cc.

                            {
}
pftools::CalibCompare::CalibCompare ( const CalibCompare ) [private]

Member Function Documentation

void CalibCompare::calibrateCalibratables ( TChain &  sourceTree,
const std::string &  exercisefile 
)

Definition at line 93 of file CalibCompare.cc.

References gather_cfg::cout, debug_, evaluateCalibrations(), pftools::TreeUtility::getCalibratablesFromRootFile(), and diffTreeTool::tree.

                                               {

        if (debug_ > 0) {
                std::cout << "Welcome to " << __PRETTY_FUNCTION__ << "\n";
                std::cout << "Opening TTree...\n";
        }

        TreeUtility tu;
        std::vector<Calibratable> calibVec;

        tu.getCalibratablesFromRootFile(sourceTree, calibVec);

        std::cout << "Moving on... " << std::endl;
        TFile* exercises = new TFile(exercisefile.c_str(), "recreate");
        TTree tree("CalibratedParticles", "");
        Calibratable* calibrated = new Calibratable();
        tree.Branch("Calibratable", "pftools::Calibratable", &calibrated, 32000, 2);

        evaluateCalibrations(tree, calibrated, calibVec);

        //save results
        std::cout << "Writing output tree...\n";
        tree.Write();
        //gaussianFits(*exercises, calibVec);
        exercises->Write();
        exercises->Close();
        std::cout << "Done." << std::endl;
        delete calibrated;

}
void CalibCompare::evaluateCalibrations ( TTree &  tree,
pftools::Calibratable calibrated,
const std::vector< pftools::Calibratable > &  calibVec 
)

Definition at line 125 of file CalibCompare.cc.

References pftools::CalibrationResultWrapper::b_, pftools::BAYESIAN, pftools::CalibrationResultWrapper::c_, calib, pftools::Calibratable::calibrations_, pftools::Calibratable::cluster_energyEcal_, pftools::Calibratable::cluster_energyHcal_, pftools::Calibratable::cluster_meanEcal_, pftools::Calibratable::cluster_meanHcal_, pftools::Calibratable::cluster_numEcal_, pftools::Calibratable::cluster_numHcal_, clusterCalibration_, pftools::CalibrationResultWrapper::compute(), prof2calltree::count, pftools::CalibrationResultWrapper::ecalEnergy_, pftools::Erl_mlp::ecalFraction(), erlCalibration_, pftools::CalibratableElement::eta_, pftools::Erl_mlp::evaluate(), pftools::PFClusterCalibration::getCalibratedEcalEnergy(), pftools::PFClusterCalibration::getCalibratedEnergy(), pftools::PFClusterCalibration::getCalibratedHcalEnergy(), pftools::CalibrationResultWrapper::hcalEnergy_, pftools::LINEAR, pftools::CalibrationResultWrapper::particleEnergy_, pftools::CalibratableElement::phi_, pftools::CalibrationResultWrapper::provenance_, pftools::Calibratable::recompute(), pftools::Calibratable::reset(), pftools::Calibratable::sim_energyEvent_, pftools::Calibratable::sim_etaEcal_, pftools::Calibratable::sim_phiEcal_, pftools::CalibrationResultWrapper::target_, target_, pftools::CalibrationResultWrapper::targetFuncContrib_, pftools::CalibrationResultWrapper::truthEnergy_, and pftools::UNCALIBRATED.

Referenced by calibrateCalibratables().

                                                         {

        unsigned count(0);
        for (std::vector<Calibratable>::const_iterator zit = calibVec.begin(); zit
                        != calibVec.end(); ++zit) {

                const Calibratable& calib = *zit;

                calibrated->reset();

                CalibrationResultWrapper crwPre;
                crwPre.ecalEnergy_ = calib.cluster_energyEcal_;
                crwPre.hcalEnergy_ = calib.cluster_energyHcal_;
                crwPre.particleEnergy_ = calib.cluster_energyEcal_
                                + calib.cluster_energyHcal_;
                crwPre.truthEnergy_ = calib.sim_energyEvent_;
                crwPre.provenance_ = UNCALIBRATED;
                crwPre.targetFuncContrib_ = 0;
                crwPre.target_ = target_;
                crwPre.compute();
                calibrated->calibrations_.push_back(crwPre);

                CalibrationResultWrapper crwErl;

                crwErl.particleEnergy_ = erlCalibration_.evaluate(crwPre.ecalEnergy_,
                                crwPre.hcalEnergy_, calib.cluster_numEcal_,
                                calib.cluster_numHcal_, fabs(calib.cluster_meanEcal_.eta_)
                                                / 2.0, crwPre.ecalEnergy_ / (crwPre.particleEnergy_),
                                (calib.cluster_meanEcal_.phi_ + 3.14) / 6.3);
                crwErl.ecalEnergy_ = crwErl.particleEnergy_
                                * erlCalibration_.ecalFraction(crwPre.ecalEnergy_,
                                                crwPre.hcalEnergy_, calib.cluster_numEcal_,
                                                calib.cluster_numHcal_, fabs(
                                                                calib.cluster_meanEcal_.eta_) / 2.0,
                                                crwPre.ecalEnergy_ / (crwPre.particleEnergy_),
                                                (calib.cluster_meanEcal_.phi_ + 3.14) / 6.3);

                crwErl.hcalEnergy_ = crwErl.particleEnergy_ - crwErl.ecalEnergy_;
                crwErl.b_ = crwErl.ecalEnergy_ / crwPre.ecalEnergy_;
                crwErl.c_ = crwErl.hcalEnergy_ / crwPre.hcalEnergy_;

                crwErl.truthEnergy_ = calib.sim_energyEvent_;
                crwErl.provenance_ = BAYESIAN;
                crwErl.target_ = target_;
                crwErl.compute();
                calibrated->calibrations_.push_back(crwErl);

                CalibrationResultWrapper crwCorr;

                crwCorr.ecalEnergy_ = clusterCalibration_.getCalibratedEcalEnergy(
                                crwPre.ecalEnergy_, crwPre.hcalEnergy_,
                                calib.cluster_meanEcal_.eta_, calib.cluster_meanEcal_.phi_);
                crwCorr.hcalEnergy_ = clusterCalibration_.getCalibratedHcalEnergy(
                                crwPre.ecalEnergy_, crwPre.hcalEnergy_,
                                calib.cluster_meanHcal_.eta_, calib.cluster_meanHcal_.phi_);
                crwCorr.particleEnergy_ = clusterCalibration_.getCalibratedEnergy(
                                crwPre.ecalEnergy_, crwPre.hcalEnergy_, calib.sim_etaEcal_,
                                calib.sim_phiEcal_);

                crwCorr.truthEnergy_ = calib.sim_energyEvent_;
                crwCorr.provenance_ = LINEAR;
                crwCorr.targetFuncContrib_ = 0;;
                crwCorr.target_ = target_;
                crwCorr.compute();
                calibrated->calibrations_.push_back(crwCorr);

                calibrated->recompute();

                tree.Fill();

                ++count;
        }

}
void pftools::CalibCompare::operator= ( const CalibCompare ) [private]
void pftools::CalibCompare::setTarget ( CalibrationTarget  t) [inline]

Definition at line 34 of file CalibCompare.h.

References matplotRender::t, and target_.

                                            {
                target_ = t;
        }

Member Data Documentation

Definition at line 54 of file CalibCompare.h.

Referenced by CalibCompare(), and evaluateCalibrations().

unsigned pftools::CalibCompare::debug_ [private]

Definition at line 50 of file CalibCompare.h.

Referenced by CalibCompare(), and calibrateCalibratables().

Definition at line 55 of file CalibCompare.h.

Referenced by CalibCompare(), and evaluateCalibrations().

Definition at line 52 of file CalibCompare.h.

Referenced by CalibCompare().

Definition at line 53 of file CalibCompare.h.

Referenced by CalibCompare().

Definition at line 49 of file CalibCompare.h.

Referenced by CalibCompare().

Definition at line 48 of file CalibCompare.h.

Referenced by evaluateCalibrations(), and setTarget().

Definition at line 47 of file CalibCompare.h.

Referenced by CalibCompare().