00001
00002
00003 #ifndef EGAMMA_LAYER_RECALIB_TOOL
00004 #define EGAMMA_LAYER_RECALIB_TOOL
00005
00016
00018
00019 #include <string>
00020 #include <vector>
00021 #include <memory>
00022
00023 #include "AsgTools/AsgTool.h"
00024 #include "AsgTools/AsgMessaging.h"
00025 #include "xAODEgamma/Egamma.h"
00026 #include "xAODCaloEvent/CaloCluster.h"
00027 #include "xAODEventInfo/EventInfo.h"
00028 #include "PATInterfaces/CorrectionCode.h"
00029
00030 #include <TH1.h>
00031 #include <TH2.h>
00032 #include <TFormula.h>
00033
00034 #include "egammaLayerRecalibTool/corr_HV_EMBPS.h"
00035 #include "xAODEgamma/Egamma.h"
00036 #include "xAODCaloEvent/CaloCluster.h"
00037
00038
00039 struct StdCalibrationInputs
00040 {
00041 unsigned int RunNumber;
00042 double eta;
00043 double phi;
00044 double E0raw;
00045 double E1raw;
00046 double E2raw;
00047 double E3raw;
00048 };
00049
00050
00051
00052 struct GetAmountBase
00053 {
00054 virtual float operator()(const StdCalibrationInputs & input) const = 0;
00055 virtual ~GetAmountBase() { };
00056 virtual GetAmountBase* clone() const = 0;
00057 };
00058
00059
00060
00061 struct GetAmountHVPSGuillaume : public GetAmountBase
00062 {
00063 virtual float operator()(const StdCalibrationInputs & input) const;
00064 private:
00065 virtual GetAmountHVPSGuillaume* clone() const { return 0; };
00066 corr_HV_EMBPS m_tool;
00067 };
00068
00069
00070 struct GetAmountFormula : public GetAmountBase
00071 {
00072 GetAmountFormula(const TFormula & formula) : m_formula(formula) { };
00073 virtual GetAmountFormula* clone() const { return new GetAmountFormula(*this); };
00074 virtual float operator()(const StdCalibrationInputs & input) const;
00075 protected:
00076 TFormula m_formula;
00077 };
00078
00079
00080 struct GetAmountHisto1D : public GetAmountBase
00081 {
00082 GetAmountHisto1D(const TH1& histo) : m_histo(static_cast<TH1*>(histo.Clone())) { m_histo->SetDirectory(0); };
00083 GetAmountHisto1D(const GetAmountHisto1D & oth) : m_histo(static_cast<TH1*>(oth.m_histo->Clone())) { m_histo->SetDirectory(0); };
00084 GetAmountHisto1D& operator= (const GetAmountHisto1D & oth){
00085 if (this != &oth)
00086 {
00087 m_histo.reset(static_cast<TH1*>(oth.m_histo->Clone()));
00088 m_histo->SetDirectory(0);
00089 }
00090 return *this;
00091 }
00092 virtual GetAmountHisto1D* clone() const { return new GetAmountHisto1D(*this); };
00093 virtual float operator()(const StdCalibrationInputs & input) const;
00094 protected:
00095 std::unique_ptr<TH1> m_histo;
00096 };
00097
00098
00099 struct GetAmountHisto1DUp : public GetAmountHisto1D
00100 {
00101 GetAmountHisto1DUp(const TH1& histo) : GetAmountHisto1D(histo) { };
00102 virtual GetAmountHisto1D* clone() const { return new GetAmountHisto1DUp(*this); };
00103 virtual float operator()(const StdCalibrationInputs & input) const;
00104 };
00105
00106
00107 struct GetAmountHisto1DDown : public GetAmountHisto1D
00108 {
00109 GetAmountHisto1DDown(const TH1& histo) : GetAmountHisto1D(histo) { };
00110 virtual GetAmountHisto1D* clone() const { return new GetAmountHisto1DDown(*this); };
00111 virtual float operator()(const StdCalibrationInputs & input) const;
00112 };
00113
00114
00115 struct GetAmountHisto1DErrorUp : public GetAmountHisto1D
00116 {
00117 GetAmountHisto1DErrorUp(const TH1& histo) : GetAmountHisto1D(histo) { };
00118 virtual GetAmountHisto1D* clone() const { return new GetAmountHisto1DErrorUp(*this); };
00119 virtual float operator()(const StdCalibrationInputs & input) const;
00120 };
00121
00122
00123 struct GetAmountHisto1DErrorDown : public GetAmountHisto1D
00124 {
00125 GetAmountHisto1DErrorDown(const TH1& histo) : GetAmountHisto1D(histo) { };
00126 virtual GetAmountHisto1D* clone() const { return new GetAmountHisto1DErrorDown(*this); };
00127 virtual float operator()(const StdCalibrationInputs & input) const;
00128 };
00129
00130
00131 struct GetAmountHisto2D : public GetAmountBase
00132 {
00133 GetAmountHisto2D(const TH2F& histo) : m_histo(histo) { m_histo.SetDirectory(0); };
00134 virtual GetAmountHisto2D* clone() const { return new GetAmountHisto2D(*this); };
00135 virtual float operator()(const StdCalibrationInputs & input) const;
00136 protected:
00137 TH2F m_histo;
00138 };
00139
00140
00141 struct GetAmountFixed : public GetAmountBase
00142 {
00143 public:
00144 GetAmountFixed(float amount) : m_amount(amount) { }
00145 virtual GetAmountFixed* clone() const { return new GetAmountFixed(*this); };
00146 virtual float operator()(const StdCalibrationInputs & input) const;
00147 private:
00148 float m_amount;
00149 };
00150
00151
00152 class GetAmountDecoratorBase : public GetAmountBase
00153 {
00154 public:
00155 GetAmountDecoratorBase(GetAmountBase* getter) : m_getter(getter) { };
00156 virtual ~GetAmountDecoratorBase() { delete m_getter; }
00157 virtual float operator()(const StdCalibrationInputs & input) const {
00158 return (*m_getter)(input);
00159 }
00160 private:
00161 GetAmountBase* m_getter;
00162 };
00163
00164
00165 struct InputModifier
00166 {
00167 enum NullPoint {ZEROBASED, ONEBASED, ZEROBASED_ALPHA, ONEBASED_ALPHA, SHIFT};
00168
00169 InputModifier(NullPoint base) : m_base(base) { };
00170 CP::CorrectionCode operator()(StdCalibrationInputs&, float amount) const;
00171 virtual InputModifier* clone() const = 0;
00172 virtual ~InputModifier() { };
00173 private:
00174 InputModifier() { };
00175
00176 virtual void scale_inputs(StdCalibrationInputs&, float amount) const=0;
00177 NullPoint m_base;
00178 };
00179
00180
00181 struct ScaleE0 : public InputModifier
00182 {
00183 ScaleE0(NullPoint base) : InputModifier(base) { };
00184 ScaleE0* clone() const { return new ScaleE0(*this); };
00185 private:
00186 virtual void scale_inputs(StdCalibrationInputs&, float amount) const;
00187 };
00188
00189
00190 struct ScaleE1 : public InputModifier
00191 {
00192 ScaleE1(NullPoint base) : InputModifier(base) { };
00193 ScaleE1* clone() const { return new ScaleE1(*this); };
00194 private:
00195 virtual void scale_inputs(StdCalibrationInputs&, float amount) const;
00196 };
00197
00198
00199 struct ScaleE2 : public InputModifier
00200 {
00201 ScaleE2(NullPoint base) : InputModifier(base) { };
00202 ScaleE2* clone() const { return new ScaleE2(*this); };
00203 private:
00204 virtual void scale_inputs(StdCalibrationInputs&, float amount) const;
00205 };
00206
00207
00208 struct ScaleE3 : public InputModifier
00209 {
00210 ScaleE3(NullPoint base) : InputModifier(base) { };
00211 ScaleE3* clone() const { return new ScaleE3(*this); };
00212 private:
00213 virtual void scale_inputs(StdCalibrationInputs&, float amount) const;
00214 };
00215
00216
00217 struct ScaleE1overE2 : public InputModifier
00218 {
00219 ScaleE1overE2(NullPoint base) : InputModifier(base) { };
00220 ScaleE1overE2* clone() const { return new ScaleE1overE2(*this); };
00221 private:
00222 virtual void scale_inputs(StdCalibrationInputs&, float amount) const;
00223 };
00224
00225
00226 struct ScaleEaccordion : public InputModifier
00227 {
00228 ScaleEaccordion(NullPoint base) : InputModifier(base) { };
00229 ScaleEaccordion* clone() const { return new ScaleEaccordion(*this); };
00230 private:
00231 virtual void scale_inputs(StdCalibrationInputs&, float amount) const;
00232 };
00233
00234
00235 struct ScaleEcalorimeter : public InputModifier
00236 {
00237 ScaleEcalorimeter(NullPoint base) : InputModifier(base) { };
00238 ScaleEcalorimeter* clone() const { return new ScaleEcalorimeter(*this); };
00239 private:
00240 virtual void scale_inputs(StdCalibrationInputs&, float amount) const;
00241 };
00242
00243
00244 class egammaLayerRecalibTool : public asg::AsgMessaging
00245 {
00246 public:
00247 typedef std::vector<std::pair<InputModifier*, GetAmountBase*> > ModifiersList;
00254 egammaLayerRecalibTool(const std::string& name, const std::string& tune);
00255 egammaLayerRecalibTool(const std::string& tune);
00256 ~egammaLayerRecalibTool() { clear_corrections(); }
00257
00258 CP::CorrectionCode applyCorrection(xAOD::Egamma &, const xAOD::EventInfo& event_info) const;
00259
00263 static std::pair<std::string, egammaLayerRecalibTool*> create(const std::string& type,
00264 const std::string& args);
00265
00269 CP::CorrectionCode scale_inputs(StdCalibrationInputs & inputs) const;
00273 void add_scale(InputModifier * modifier, GetAmountBase * amount);
00278 void add_scale(const std::string& scale);
00282 void clear_corrections();
00283 private:
00284 std::string m_tune;
00285 const std::string resolve_path(std::string filename) const;
00286 const std::string& resolve_alias(const std::string& tune) const;
00287 ModifiersList m_modifiers;
00288 };
00289
00290 #endif // EGAMMA_LAYER_RECALIB_TOOL