00001
00002
00003
00078
00079
00080
00081 #ifndef TELECTRONLIKELIHOODTOOL_H
00082 #define TELECTRONLIKELIHOODTOOL_H
00083
00084 #include <fstream>
00085 #include <iostream>
00086
00087 #include "PATCore/TCalculatorToolBase.h"
00088 #include "PATCore/TSelectorToolBase.h"
00089 #include "AsgTools/AsgMessaging.h"
00090
00091 #include <string>
00092 #include <vector>
00093 class TFile;
00094 class TH1F;
00095 namespace Root { class TAccept; }
00096 namespace Root { class TResult; }
00097 namespace{
00098 const unsigned int IP_BINS=1;
00099 }
00100 namespace LikeEnum {
00101
00102 struct LHAcceptVars_t{
00103 double likelihood;
00104 double eta;
00105 double eT;
00106 int nSiHitsPlusDeadSensors;
00107 int nPixHitsPlusDeadSensors;
00108 bool passBLayerRequirement;
00109 int convBit;
00110 double d0;
00111 double deltaEta;
00112 double deltaphires;
00113 double wstot;
00114 double EoverP;
00115 double ip;
00116 };
00117
00118 struct LHCalcVars_t{
00119 double eta;
00120 double eT;
00121 double f3;
00122 double rHad;
00123 double rHad1;
00124 double Reta;
00125 double w2;
00126 double f1;
00127 double eratio;
00128 double deltaEta;
00129 double d0;
00130 double d0sigma;
00131 double rphi;
00132 double deltaPoverP;
00133 double deltaphires;
00134 double TRT_PID;
00135 double ip;
00136 };
00137 }
00138
00139 namespace Root {
00140 class TElectronLikelihoodTool : public TCalculatorToolBase, public TSelectorToolBase, public asg::AsgMessaging
00141 {
00142
00143 public:
00145
00146 TElectronLikelihoodTool(const char* name = "TElectronLikelihoodTool");
00147
00149 ~TElectronLikelihoodTool();
00150
00151 private:
00152 class SafeTH1{
00153 public :
00154 SafeTH1(TH1F* hist);
00155 ~SafeTH1();
00156 int GetNbinsX();
00157 int FindBin(double);
00158 double GetBinContent(int);
00159 double GetBinLowEdge(int);
00160 double Integral();
00161
00162 private:
00163 std::vector<float> m_binContent;
00164 double m_firstBinLowEdge;
00165 double m_lastBinLowEdge;
00166 double m_binWidth;
00167 double m_integral;
00168 };
00169
00170
00171 public:
00173 int initialize();
00174
00176 int finalize() {return 1;}
00177
00179 const Root::TAccept& accept(LikeEnum::LHAcceptVars_t& vars_struct) const;
00180 const Root::TAccept& accept( double likelihood,
00181 double eta, double eT,
00182 int nSiHitsPlusDeadSensors, int nPixHitsPlusDeadSensors,
00183 bool passBLayerRequirement,
00184 int convBit, double d0, double deltaEta, double deltaphires,
00185 double wstot, double EoverP, double ip ) const;
00186 const Root::TResult& calculate(LikeEnum::LHCalcVars_t& vars_struct) const ;
00187 const Root::TResult& calculate( double eta, double eT,double f3, double rHad, double rHad1,
00188 double Reta, double w2, double f1, double eratio,
00189 double deltaEta, double d0, double d0sigma, double rphi,
00190 double deltaPoverP ,double deltaphires, double TRT_PID,
00191 double ip) const;
00192
00193
00195 inline void setPDFFileName ( const std::string& val ) { PdfFileName = val; }
00196
00198 inline void setVariableNames ( const std::string& val ) {
00199 VariableNames = val;
00200 m_variableBitMask = GetLikelihoodBitmask(val);
00201 }
00202
00204 int LoadVarHistograms(std::string vstr, unsigned int varIndex);
00205
00207 inline void setBinning ( const std::string& val ) { m_ipBinning = val; }
00208
00210 inline void setResultPrefix ( const std::string& val ) { m_resultPrefix = val; }
00211
00213 inline void setResultName ( const std::string& val ) { m_resultName = val; }
00214
00215 unsigned int getBitmask(void) const { return m_variableBitMask;}
00216 inline void setBitmask(unsigned int val) { m_variableBitMask = val; };
00217
00218
00219 private:
00220
00221
00222
00223
00225 double EvaluateLikelihood(std::vector<double> varVector,double et,double eta,double ip=0) const;
00226
00228 double EvaluateLikelihood(std::vector<float> varVector,double et,double eta,double ip=0) const;
00229
00230
00231
00232
00233
00235 unsigned int GetLikelihoodBitmask(std::string vars) const;
00236
00237 double InterpolateCuts(const std::vector<double>& cuts,const std::vector<double>& cuts_4gev,double et,double eta) const;
00238 double InterpolatePdfs(unsigned int s_or_b,unsigned int ipbin,double et,double eta,int bin,unsigned int var) const;
00239
00240 public:
00242 std::vector<int> CutBL;
00244 std::vector<int> CutPi;
00246 std::vector<int> CutSi;
00248 std::vector<double> CutA0;
00250 std::vector<double> CutDeltaEta;
00251
00252 std::vector<double> CutDeltaPhiRes;
00254 bool doCutConversion;
00256 bool doRemoveF3AtHighEt;
00258 bool doRemoveTRTPIDAtHighEt;
00260 bool doSmoothBinInterpolation;
00262 bool useHighETLHBinning;
00264 bool useOneExtraHighETLHBin;
00266 double HighETBinThreshold;
00267
00268 std::vector<double> CutWstotAtHighET;
00269
00270 std::vector<double> CutEoverPAtHighET;
00272 bool doPileupTransform;
00274 bool doCentralityTransform;
00276 std::vector<double> CutLikelihood;
00278 std::vector<double> CutLikelihoodPileupCorrection;
00280 std::vector<double> CutLikelihood4GeV;
00282 std::vector<double> CutLikelihoodPileupCorrection4GeV;
00284 std::vector<double> DiscHardCutForPileupTransform;
00286 std::vector<double> DiscHardCutSlopeForPileupTransform;
00288 std::vector<double> DiscHardCutQuadForPileupTransform;
00290 std::vector<double> DiscLooseForPileupTransform;
00292 std::vector<double> DiscHardCutForPileupTransform4GeV;
00294 std::vector<double> DiscHardCutSlopeForPileupTransform4GeV;
00296 std::vector<double> DiscHardCutQuadForPileupTransform4GeV;
00298 std::vector<double> DiscLooseForPileupTransform4GeV;
00300 double DiscMaxForPileupTransform;
00302 double PileupMaxForPileupTransform;
00304 std::string VariableNames;
00306 std::string PdfFileName;
00307
00308
00309
00310 private:
00312 double TransformLikelihoodOutput(double ps,double pb, double ip, double et, double eta) const;
00313
00315 unsigned int getLikelihoodEtaBin(double eta) const ;
00316
00318 unsigned int getLikelihoodEtHistBin(double eT)const ;
00319
00321 unsigned int getLikelihoodEtDiscBin(double eT) const;
00322
00323
00324
00325 private:
00326
00328 unsigned int m_variableBitMask;
00329
00331 std::string m_ipBinning;
00332
00334 TFile* m_pdfFile;
00335
00337 std::string m_resultPrefix;
00338
00340 std::string m_resultName;
00341
00343 int m_cutPosition_kinematic;
00344
00346 int m_cutPosition_NSilicon;
00347
00349 int m_cutPosition_NPixel;
00350
00352 int m_cutPosition_NBlayer;
00353
00355 int m_cutPosition_conversion;
00356
00358 int m_cutPosition_LH;
00359
00361 int m_cutPositionTrackA0;
00362
00364 int m_cutPositionTrackMatchEta;
00365
00366
00367 int m_cutPositionTrackMatchPhiRes;
00368
00369
00370 int m_cutPositionWstotAtHighET;
00371
00372
00373 int m_cutPositionEoverPAtHighET;
00374
00376 int m_resultPosition_LH;
00377
00378 static const double fIpBounds[IP_BINS+1];
00379 static const unsigned int fnEtBinsHist = 8;
00380 static const unsigned int fnDiscEtBins = 33;
00381 static const unsigned int fnEtBinsHistOrig = 7;
00382 static const unsigned int fnDiscEtBinsOrig = 9;
00383 static const unsigned int fnDiscEtBinsOneExtra = 10;
00384 static const unsigned int fnEtaBins = 10;
00385 static const unsigned int fnVariables = 13;
00386 TElectronLikelihoodTool::SafeTH1* fPDFbins [2][IP_BINS][fnEtBinsHist][fnEtaBins][fnVariables];
00387 static const std::string fVariables [fnVariables];
00388
00389 unsigned int getIpBin(double ip) const;
00390 void getBinName(char* buffer, int etbin,int etabin, int ipbin, std::string iptype) const;
00391 };
00392
00393 }
00394
00395
00396 #endif