CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10/src/CalibTracker/SiStripLorentzAngle/interface/LA_Filler_Fitter.h

Go to the documentation of this file.
00001 #ifndef LA_FILLER_FITTER_H
00002 #define LA_FILLER_FITTER_H
00003 
00004 #include <string>
00005 #include <vector>
00006 #include <map>
00007 #include "DataFormats/SiStripDetId/interface/TOBDetId.h"
00008 #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00009 #include "CalibTracker/SiStripCommon/interface/Book.h"
00010 #include <TTree.h>
00011 #include "SymmetryFit.h"
00012 class TProfile;
00013 
00014 class LA_Filler_Fitter {
00015 
00016  public:
00017 
00018  //ensemble constructor
00019   LA_Filler_Fitter(int methods, int M, int N, double low, double up, unsigned max) :
00020     ensembleSize_(M),
00021     ensembleBins_(N),ensembleLow_(low),ensembleUp_(up),
00022     byLayer_(true),byModule_(false),
00023     localYbin_(0),
00024     stripsPerBin_(0),
00025     maxEvents_(max),
00026     methods_(methods) {};
00027     
00028   //measurement constructor
00029   LA_Filler_Fitter(int methods, bool layer, bool module, float localybin, unsigned stripbin, unsigned max) : 
00030     ensembleSize_(0),
00031     ensembleBins_(0),ensembleLow_(0),ensembleUp_(0),
00032     byLayer_(layer),byModule_(module),
00033     localYbin_(localybin),
00034     stripsPerBin_(stripbin),
00035     maxEvents_(max),
00036     methods_(methods) {};
00037   
00038   enum Method { WIDTH =1<<0, FIRST_METHOD=1<<0, 
00039                 PROB1 =1<<1,
00040                 AVGV2 =1<<2,  
00041                 AVGV3 =1<<3, 
00042                 RMSV2 =1<<4,
00043                 RMSV3 =1<<5, LAST_METHOD=1<<5};
00044 
00045   static std::string method(Method m,bool fit=true) { 
00046     switch(m) {
00047     case WIDTH: return      "_width_prof";
00048     case PROB1: return fit? SymmetryFit::name(method(m,0)): "_prob_w1"   ;  
00049     case AVGV2: return fit? SymmetryFit::name(method(m,0)): "_avg_var_w2";  
00050     case AVGV3: return fit? SymmetryFit::name(method(m,0)): "_avg_var_w3";  
00051     case RMSV2: return fit? SymmetryFit::name(method(m,0)): "_rms_var_w2";  
00052     case RMSV3: return fit? SymmetryFit::name(method(m,0)): "_rms_var_w3";  
00053     default: return "_UNKNOWN";
00054     }
00055   }
00056 
00057   struct Result { 
00058     std::pair<float,float> reco,measured,calMeasured;
00059     float field,chi2;
00060     unsigned ndof,entries; 
00061     Result() : reco(1000,0), measured(1000,0), calMeasured(1000,0),
00062                field(0), chi2(0), ndof(0), entries(0) {}
00063   };
00064   
00065   struct EnsembleSummary {
00066     std::pair<float,float> meanMeasured, sigmaMeasured, meanUncertainty, pull;
00067     float truth;
00068     unsigned samples;
00069     EnsembleSummary() : meanMeasured(0,0), sigmaMeasured(0,0), meanUncertainty(0,0), pull(0,0),
00070                         truth(0), samples(0) {}
00071   };
00072   
00073   //Located in src/LA_Filler.cc
00074   void fill(TTree*, Book&) const;
00075   void fill_one_cluster(Book&,
00076                         const poly<std::string>&,
00077                         const unsigned, const float, const float, const float, const float) const;
00078   poly<std::string> allAndOne(const unsigned width) const;
00079   poly<std::string> varWidth(const unsigned width) const;
00080   poly<std::string> granularity(const SiStripDetId, const float, const Long64_t, const float, const unsigned) const;
00081   static std::string subdetLabel(const SiStripDetId);
00082   static std::string moduleLabel(const SiStripDetId);
00083   static std::string layerLabel(const SiStripDetId);
00084   static unsigned layer_index(bool TIB, bool stereo, unsigned layer) { return  layer + (TIB?0:6) +(stereo?1:0) + ( (layer>2)?1:(layer==1)?-1:0 );}
00085 
00086   //Located in src/LA_Fitter.cc
00087   static void fit(Book& book) { make_and_fit_symmchi2(book); fit_width_profile(book); }
00088   static void make_and_fit_symmchi2(Book&);
00089   static void fit_width_profile(Book&);
00090   static TH1* rms_profile(const std::string, const TProfile* const);
00091   static TH1* subset_probability(const std::string name, const TH1* const , const TH1* const );
00092   static unsigned find_rebin(const TH1* const);
00093 
00094   //Located in src/LA_Results.cc
00095   void summarize_ensembles(Book&) const;
00096   static Result result(Method, const std::string name, const Book&);
00097   static std::map< std::string,                      Result  >    layer_results(const Book&, const Method);
00098   static std::map<    uint32_t,                      Result  >   module_results(const Book&, const Method);
00099   static std::map< std::string,          std::vector<Result> > ensemble_results(const Book&, const Method );
00100   static std::map< std::string, std::vector<EnsembleSummary> > ensemble_summary(const Book& );
00101   static std::pair<std::pair<float,float>, std::pair<float,float> > offset_slope(const std::vector<EnsembleSummary>&);
00102   static float pull(const std::vector<EnsembleSummary>&);
00103     
00104  private:
00105   
00106   const int ensembleSize_, ensembleBins_;
00107   const double ensembleLow_, ensembleUp_;
00108   const bool byLayer_, byModule_;
00109   const float localYbin_;
00110   const unsigned stripsPerBin_;
00111   const Long64_t maxEvents_;
00112   const int methods_;
00113 };
00114 
00115 std::ostream& operator<<(std::ostream&, const LA_Filler_Fitter::Result&);
00116 std::ostream& operator<<(std::ostream&, const LA_Filler_Fitter::EnsembleSummary&);
00117 
00118 #endif