CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes | Friends

pftools::PFClusterCalibration Class Reference

#include <PFClusterCalibration.h>

List of all members.

Public Member Functions

void calibrate (Calibratable &c)
void calibrateTree (TTree *tree)
double getCalibratedEcalEnergy (const double &ecalE, const double &hcalE, const double &eta, const double &phi) const
double getCalibratedEnergy (const double &ecalE, const double &hcalE, const double &eta, const double &phi) const
void getCalibratedEnergyEmbedAInHcal (double &ecalE, double &hcalE, const double &eta, const double &phi) const
double getCalibratedHcalEnergy (const double &ecalE, const double &hcalE, const double &eta, const double &phi) const
void getCalibrationResultWrapper (const Calibratable &c, CalibrationResultWrapper &crw)
std::vector< std::string > * getKnownSectorNames ()
 PFClusterCalibration ()
void setAllowNegativeEnergy (const bool &allowIt)
void setBarrelBoundary (const double &eta)
void setCorrections (const double &lowEP0, const double &lowEP1, const double &globalP0, const double &globalP1)
void setDoCorrection (const int &doCorrection)
void setDoEtaCorrection (const int doEtaCorrection)
void setEcalHcalEnergyCuts (const double &ecalCut, const double &hcalCut)
void setEtaCorrectionParameters (std::vector< double > params)
void setEvolutionParameters (const std::string &sector, std::vector< double > params)
void setMaxEToCorrect (double maxE)
virtual ~PFClusterCalibration ()

Private Member Functions

void init ()

Private Attributes

int allowNegativeEnergy_
double barrelEndcapEtaDiv_
TF1 * correction_
double correctionLowLimit_
int doCorrection_
int doEtaCorrection_
double ecalOnlyDiv_
TF1 * etaCorrection_
double globalP0_
double globalP1_
double hcalOnlyDiv_
double lowEP0_
double lowEP1_
double maxEToCorrect_
std::vector< std::string > names_
std::map< std::string, TF1 > namesAndFunctions_

Friends

std::ostream & pftools::operator<< (std::ostream &s, const PFClusterCalibration &cc)

Detailed Description

Definition at line 40 of file PFClusterCalibration.h.


Constructor & Destructor Documentation

PFClusterCalibration::PFClusterCalibration ( )

Definition at line 104 of file PFClusterCalibration.cc.

References init().

                                           :
        barrelEndcapEtaDiv_(1.0), ecalOnlyDiv_(0.3), hcalOnlyDiv_(0.5),
                        doCorrection_(1), allowNegativeEnergy_(0), doEtaCorrection_(1),
                        maxEToCorrect_(-1.0), correctionLowLimit_(0.), globalP0_(0.0),
                        globalP1_(1.0), lowEP0_(0.0), lowEP1_(1.0) {
  //    std::cout << __PRETTY_FUNCTION__ << std::endl;
        init();
        //      std::cout
        //                      << "WARNING! PFClusterCalibration evolution functions have not yet been initialised - ensure this is done.\n";
        //      std::cout << "PFClusterCalibration construction complete."<< std::endl;

}
PFClusterCalibration::~PFClusterCalibration ( ) [virtual]

Definition at line 117 of file PFClusterCalibration.cc.

References correction_, and etaCorrection_.

                                            {
        delete correction_;
        delete etaCorrection_;
}

Member Function Documentation

void PFClusterCalibration::calibrate ( Calibratable c)
void PFClusterCalibration::calibrateTree ( TTree *  tree)

Definition at line 292 of file PFClusterCalibration.cc.

References calibrate(), gather_cfg::cout, and python::tagInventory::entries.

                                                     {
        std::cout << __PRETTY_FUNCTION__
                        << ": WARNING! This isn't working properly yet!\n";
        TBranch* calibBr = input->GetBranch("Calibratable");
        Calibratable* calib_ptr = new Calibratable();
        calibBr->SetAddress(&calib_ptr);

        //      TBranch* newBranch = input->Branch("NewCalibratable",
        //                      "pftools::Calibratable", &calib_ptr, 32000, 2);

        std::cout << "Looping over tree's "<< input->GetEntries()
                        << " entries...\n";
        for (unsigned entries(0); entries < 20000; entries++) {
                if (entries % 10000== 0)
                        std::cout << "\tProcessing entry "<< entries << "\n";
                input->GetEntry(entries);
                calibrate(*calib_ptr);
                input->Fill();
        }
        //input.Write("",TObject::kOverwrite);
}
double PFClusterCalibration::getCalibratedEcalEnergy ( const double &  ecalE,
const double &  hcalE,
const double &  eta,
const double &  phi 
) const

Definition at line 178 of file PFClusterCalibration.cc.

References barrelEndcapEtaDiv_, and namesAndFunctions_.

Referenced by pftools::CalibCompare::evaluateCalibrations(), pftools::Exercises3::evaluateCalibrator(), getCalibratedEnergy(), getCalibratedEnergyEmbedAInHcal(), and getCalibrationResultWrapper().

                                                                                 {
        const TF1* theFunction(0);

        if (fabs(eta) < barrelEndcapEtaDiv_) {
                //barrel
                theFunction = &(namesAndFunctions_.find("ecalHcalEcalBarrel")->second);
        } else {
                //endcap
                theFunction = &(namesAndFunctions_.find("ecalHcalEcalEndcap")->second);
        }

        assert(theFunction != 0);
        double totalE(ecalE + hcalE);
        double bCoeff = theFunction->Eval(totalE);
        return ecalE * bCoeff;
}
double PFClusterCalibration::getCalibratedEnergy ( const double &  ecalE,
const double &  hcalE,
const double &  eta,
const double &  phi 
) const
void PFClusterCalibration::getCalibratedEnergyEmbedAInHcal ( double &  ecalE,
double &  hcalE,
const double &  eta,
const double &  phi 
) const

Definition at line 239 of file PFClusterCalibration.cc.

References a, allowNegativeEnergy_, correction_, doCorrection_, doEtaCorrection_, etaCorrection_, getCalibratedEcalEnergy(), and getCalibratedHcalEnergy().

                                                                           {

        double ecalEOld(ecalE);
        double hcalEOld(hcalE);

        ecalE = getCalibratedEcalEnergy(ecalEOld, hcalEOld, eta, phi);
        hcalE = getCalibratedHcalEnergy(ecalEOld, hcalEOld, eta, phi);

        double preCorrection(ecalE + hcalE);
        if (doEtaCorrection_)
                preCorrection = preCorrection/etaCorrection_->Eval(eta);

        if (doCorrection_) {
                double corrE = correction_->Eval(preCorrection);
                //a term  = difference
                double a = corrE - preCorrection;
                hcalE += a;
        }
        if (hcalE < 0 && !allowNegativeEnergy_)
                hcalE = 0;

}
double PFClusterCalibration::getCalibratedHcalEnergy ( const double &  ecalE,
const double &  hcalE,
const double &  eta,
const double &  phi 
) const

Definition at line 196 of file PFClusterCalibration.cc.

References barrelEndcapEtaDiv_, and namesAndFunctions_.

Referenced by pftools::CalibCompare::evaluateCalibrations(), pftools::Exercises3::evaluateCalibrator(), getCalibratedEnergy(), getCalibratedEnergyEmbedAInHcal(), and getCalibrationResultWrapper().

                                                                                 {
        const TF1* theFunction(0);

        if (fabs(eta) < barrelEndcapEtaDiv_) {
                //barrel
                theFunction = &(namesAndFunctions_.find("ecalHcalHcalBarrel")->second);
        } else {
                //endcap
                theFunction = &(namesAndFunctions_.find("ecalHcalHcalEndcap")->second);
        }

        double totalE(ecalE + hcalE);
        assert(theFunction != 0);
        double cCoeff = theFunction->Eval(totalE);
        return hcalE * cCoeff;
}
void PFClusterCalibration::getCalibrationResultWrapper ( const Calibratable c,
CalibrationResultWrapper crw 
)
std::vector<std::string>* pftools::PFClusterCalibration::getKnownSectorNames ( ) [inline]

Definition at line 127 of file PFClusterCalibration.h.

References names_.

Referenced by pftools::CalibCompare::CalibCompare(), and pftools::Exercises3::Exercises3().

                                                    {
                return &names_;
        }
void PFClusterCalibration::init ( void  ) [private]

Definition at line 13 of file PFClusterCalibration.cc.

References correction_, correctionLowLimit_, etaCorrection_, globalP0_, globalP1_, lowEP0_, lowEP1_, mergeVDriftHistosByStation::name, names_, namesAndFunctions_, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by PFClusterCalibration().

                                {
  
  //std::cout << __PRETTY_FUNCTION__ << std::endl;
        correction_ = new TF1("correction",
                        "((x-[0])/[1])*(x>[4])+((x-[2])/[3])*(x<[4])");
        etaCorrection_
                        = new TF1( "etaCorrection",
                                        "(1-[0]*x-[1]*x*x)*(x<[2])+([3]+[4]*x)*(x>[2]&&x<[5])+(1-[6]*x-[7]*x*x)*(x>[5])");

        correction_->FixParameter(0, globalP0_);
        correction_->FixParameter(1, globalP1_);
        correction_->FixParameter(2, lowEP0_);
        correction_->FixParameter(3, lowEP1_);
        correction_->FixParameter(4, correctionLowLimit_);

        /* These are the types of calibration I know about:
         * ecalOnly_elementName
         * etc. Sorry, it's not very nice, but well, neither is ROOT... */

        std::string eheb("ecalHcalEcalBarrel");
        names_.push_back(eheb);
        std::string ehee("ecalHcalEcalEndcap");
        names_.push_back(ehee);
        std::string ehhb("ecalHcalHcalBarrel");
        names_.push_back(ehhb);
        std::string ehhe("ecalHcalHcalEndcap");
        names_.push_back(ehhe);

        /* char
         * funcString("([0]*[5]*x*([1]-[5]*x)/pow(([2]+[5]*x),3)+[3]*pow([5]*x, 0.1))*([5]*x<[8] && [5]*x>[7])+[4]*([5]*x>[8])+([6]*[5]*x)*([5]*x<[7])");
         */

        const char*
          funcString("([0]*[5]*x)*([5]*x<=[1])+([2]+[3]*exp([4]*[5]*x))*([5]*x>[1])");

        //Create functions for each sector
        for (std::vector<std::string>::const_iterator cit = names_.begin(); cit
                        != names_.end(); ++cit) {
                std::string name = *cit;
                TF1 func(name.c_str(), funcString);
                //some sensible defaults
                func.FixParameter(0, 1);
                func.FixParameter(1, 0);
                func.FixParameter(2, 1);
                func.FixParameter(3, 0);
                func.FixParameter(4, 0);
                func.FixParameter(5, 1);

                func.SetMinimum(0);
                //Store in map
                namesAndFunctions_[name] = func;

        }
}
void pftools::PFClusterCalibration::setAllowNegativeEnergy ( const bool &  allowIt) [inline]
void pftools::PFClusterCalibration::setBarrelBoundary ( const double &  eta) [inline]
void PFClusterCalibration::setCorrections ( const double &  lowEP0,
const double &  lowEP1,
const double &  globalP0,
const double &  globalP1 
)

Definition at line 157 of file PFClusterCalibration.cc.

References correction_, correctionLowLimit_, globalP0_, globalP1_, lowEP0_, and lowEP1_.

Referenced by pftools::CalibCompare::CalibCompare(), and pftools::Exercises3::Exercises3().

                                                                                      {
        //'a' term is -globalP0/globalP1
        globalP0_ = globalP0;
        globalP1_ = globalP1;
        //Specifically for low energies...
        lowEP0_ = lowEP0;
        lowEP1_ = lowEP1;
        //Intersection of two straight lines => matching at...
        correctionLowLimit_ = (lowEP0_ - globalP0_)/(globalP1_ - lowEP1_);

        correction_->FixParameter(0, globalP0_);
        correction_->FixParameter(1, globalP1_);
        correction_->FixParameter(2, lowEP0_);
        correction_->FixParameter(3, lowEP1_);
        correction_->FixParameter(4, correctionLowLimit_);

        //      std::cout << __PRETTY_FUNCTION__ << ": setting correctionLowLimit_ = "
        //              << correctionLowLimit_ << "\n";
}
void pftools::PFClusterCalibration::setDoCorrection ( const int &  doCorrection) [inline]

Definition at line 93 of file PFClusterCalibration.h.

References doCorrection_.

Referenced by pftools::CalibCompare::CalibCompare(), and pftools::Exercises3::Exercises3().

                                                      {
                doCorrection_ = doCorrection;
        }
void pftools::PFClusterCalibration::setDoEtaCorrection ( const int  doEtaCorrection) [inline]

Definition at line 97 of file PFClusterCalibration.h.

References doEtaCorrection_.

Referenced by pftools::CalibCompare::CalibCompare(), and pftools::Exercises3::Exercises3().

                                                           {
                doEtaCorrection_ = doEtaCorrection;
        }
void pftools::PFClusterCalibration::setEcalHcalEnergyCuts ( const double &  ecalCut,
const double &  hcalCut 
) [inline]

Definition at line 102 of file PFClusterCalibration.h.

References ecalOnlyDiv_, and hcalOnlyDiv_.

Referenced by pftools::CalibCompare::CalibCompare(), and pftools::Exercises3::Exercises3().

                                                                                 {
                //std::cout << __PRETTY_FUNCTION__ << "WARNING! These will be ignored.\n";
                ecalOnlyDiv_ = ecalCut;
                hcalOnlyDiv_ = hcalCut;
        }
void PFClusterCalibration::setEtaCorrectionParameters ( std::vector< double >  params)

Definition at line 122 of file PFClusterCalibration.cc.

References prof2calltree::count, gather_cfg::cout, and etaCorrection_.

Referenced by pftools::CalibCompare::CalibCompare(), and pftools::Exercises3::Exercises3().

                                                                              {
        if (params.size() != 6) {
                std::cout << __PRETTY_FUNCTION__ << ": params is of the wrong length."
                                << std::endl;
                return;
        }
        //      std::cout << "Fixing eta correction:\n\t";
        unsigned count(0);
        for (std::vector<double>::const_iterator dit = params.begin(); dit
                        != params.end(); ++dit) {
          //std::cout << *dit << "\t";
                etaCorrection_->FixParameter(count, *dit);
                ++count;
        }
        //      std::cout << std::endl;
        /*for(double eta(0); eta < 2.5; eta += 0.05) {
         std::cout << "Eta = " << eta << ",\tcorr = " << etaCorrection_->Eval(eta) << "\n"; 
         }*/
}
void PFClusterCalibration::setEvolutionParameters ( const std::string &  sector,
std::vector< double >  params 
)

Definition at line 142 of file PFClusterCalibration.cc.

References prof2calltree::count, and namesAndFunctions_.

Referenced by pftools::CalibCompare::CalibCompare(), and pftools::Exercises3::Exercises3().

                                          {
        TF1* func = &(namesAndFunctions_.find(sector)->second);
        unsigned count(0);
        //std::cout << "Fixing for "<< sector << "\n";
        for (std::vector<double>::const_iterator dit = params.begin(); dit
                        != params.end(); ++dit) {
                func->FixParameter(count, *dit);
                //std::cout << "\t"<< count << ": "<< *dit;
                ++count;
        }
        //      std::cout << std::endl;
        func->SetMinimum(0);
}
void pftools::PFClusterCalibration::setMaxEToCorrect ( double  maxE) [inline]

Friends And Related Function Documentation

std::ostream& pftools::operator<< ( std::ostream &  s,
const PFClusterCalibration cc 
) [friend]

Member Data Documentation

Definition at line 151 of file PFClusterCalibration.h.

Referenced by init(), pftools::operator<<(), and setCorrections().

Definition at line 143 of file PFClusterCalibration.h.

Referenced by pftools::operator<<(), and setEcalHcalEnergyCuts().

Definition at line 152 of file PFClusterCalibration.h.

Referenced by init(), pftools::operator<<(), and setCorrections().

Definition at line 153 of file PFClusterCalibration.h.

Referenced by init(), pftools::operator<<(), and setCorrections().

Definition at line 144 of file PFClusterCalibration.h.

Referenced by pftools::operator<<(), and setEcalHcalEnergyCuts().

Definition at line 154 of file PFClusterCalibration.h.

Referenced by init(), pftools::operator<<(), and setCorrections().

Definition at line 155 of file PFClusterCalibration.h.

Referenced by init(), pftools::operator<<(), and setCorrections().

Definition at line 149 of file PFClusterCalibration.h.

Referenced by getCalibratedEnergy(), and setMaxEToCorrect().

std::vector<std::string> pftools::PFClusterCalibration::names_ [private]

Definition at line 163 of file PFClusterCalibration.h.

Referenced by getKnownSectorNames(), and init().

std::map<std::string, TF1> pftools::PFClusterCalibration::namesAndFunctions_ [private]