CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/Calibration/Tools/interface/ZIterativeAlgorithmWithFit.h

Go to the documentation of this file.
00001 #ifndef ZITERATIVEALGORITHMWITHFIT_H
00002 #define ZITERATIVEALGORITHMWITHFIT_H
00003 
00004 /* ******************************************
00005  * ZIterativeAlgorithmWithFit.h 
00006  *
00007  * Paolo Meridiani 06/03/2003
00008  ********************************************/
00009 
00010 #include <TROOT.h>
00011 #include <TClonesArray.h>
00012 #include <vector>
00013 #include <string>
00014 #include <TH1.h>
00015 
00016 #include "Calibration/Tools/interface/CalibElectron.h"
00017 
00018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00021 
00025 #define nMaxIterations 50
00026 #define nMaxChannels 250
00027 
00028 
00029 
00030 class ZIterativeAlgorithmWithFit 
00031 {
00032  public:
00033   struct ZIterativeAlgorithmWithFitPlots {
00034     TH1* weightedRescaleFactor[nMaxIterations][nMaxChannels];
00035     TH1* unweightedRescaleFactor[nMaxIterations][nMaxChannels];
00036     TH1* weight[nMaxIterations][nMaxChannels];
00037   };
00038 
00040   ZIterativeAlgorithmWithFit();
00041   
00043   ZIterativeAlgorithmWithFit(const edm::ParameterSet&  ps);
00044   //, unsigned int events);
00045   
00047   ZIterativeAlgorithmWithFit & operator=(const ZIterativeAlgorithmWithFit &r){
00048     return *this;
00049   }
00050   
00052   virtual ~ZIterativeAlgorithmWithFit();
00053   
00054   bool resetIteration();
00055   
00056   bool iterate();
00057 
00058   bool addEvent(calib::CalibElectron*, calib::CalibElectron*, float);
00059 
00060   const ZIterativeAlgorithmWithFitPlots* getHistos() const { return thePlots_; }
00061 
00062   int getNumberOfIterations() const { return numberOfIterations_; }
00063   
00064   int getNumberOfChannels() const { return channels_; }
00065   
00066   const std::vector<float>& getOptimizedCoefficients() const { return optimizedCoefficients_; }
00067 
00068   const std::vector<float>& getOptimizedCoefficientsError() const { return optimizedCoefficientsError_; }
00069 
00070   const std::vector<float>& getOptimizedChiSquare() const { return optimizedChiSquare_; }
00071 
00072   const std::vector<int>& getOptimizedIterations() const { return optimizedIterations_; }
00073 
00074   const std::vector<float>& getWeightSum() const { return weight_sum_; }
00075 
00076   const std::vector<float>& getEpsilonSum() const { return calib_fac_; }
00077 
00078   //Helper Methods
00079 
00080   static inline float invMassCalc(float Energy1, float Eta1, float Phi1, float Energy2, float Eta2, float Phi2) {
00081     return (sqrt(2 * Energy1 * Energy2 * (1 - cosTheta12(Eta1, Phi1, Eta2, Phi2))));
00082   }
00083 
00084   static inline float cosTheta12(float Eta1, float Phi1, float Eta2, float Phi2) {
00085     return ((cos(Phi1 - Phi2) + sinh(Eta1) * sinh(Eta2)) / (cosh(Eta1) * cosh(Eta2)));
00086   }
00087 
00088   /*
00089   static TF1* gausfit(TH1F * histoou,double* par,double* errpar) {
00090     return gausfit(histoou,par,errpar,1.,2.);
00091   }
00092   */
00093 
00094   static void gausfit(TH1F * histoou,double* par,double* errpar,float nsigmalow, float nsigmaup, double* mychi2, int* iterations); 
00095 
00096  private:
00097 
00098   void addWeightsCorrections(unsigned int event_id);
00099 
00100   void getStatWeights(const std::string& file);
00101 
00102   float getEventWeight(unsigned int event_id);
00103 
00104   void recalculateWeightsEnergies();
00105 
00106   void recalculateMasses();
00107 
00108   void recalculateWeightsEnergies(calib::CalibElectron* electron); 
00109 
00110   void getWeight(unsigned int evid,std::pair<calib::CalibElectron*,calib::CalibElectron*>, float);
00111 
00112   void getWeight(unsigned int evid,calib::CalibElectron* ele,float);
00113 
00114   void bookHistograms();
00115 
00116   ZIterativeAlgorithmWithFitPlots* thePlots_;
00117 
00118   int nCrystalCut_;
00119 
00120   unsigned int channels_;
00121   unsigned int totalEvents_;
00122   unsigned int numberOfIterations_;
00123 
00124   unsigned int currentEvent_;
00125   unsigned int currentIteration_;
00126 
00127   std::vector< std::pair<calib::CalibElectron*,calib::CalibElectron*> > electrons_;
00128 
00129   std::vector<float> optimizedCoefficients_;
00130   std::vector<float> optimizedCoefficientsError_;
00131   std::vector<float> calib_fac_;
00132   std::vector<float> weight_sum_;
00133   std::vector<float> massReco_;
00134   std::vector<float> optimizedChiSquare_;
00135   std::vector<int> optimizedIterations_;
00136 
00137   std::string massMethod;
00138 
00139   bool UseStatWeights_;
00140   std::string WeightFileName_;
00141  
00142   std::vector<float> StatWeights_;
00143   std::vector<float> Event_Weight_;
00144 
00145   TString calibType_;
00146   
00147   static const double M_Z_;
00148 };
00149 
00150 #endif // ZIterativeAlgorithmWithFit_H
00151 
00152