Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:14:56

0001 #ifndef LA_FILLER_FITTER_H
0002 #define LA_FILLER_FITTER_H
0003 
0004 #include <string>
0005 #include <vector>
0006 #include <map>
0007 #include "DataFormats/SiStripDetId/interface/SiStripDetId.h"
0008 #include "CalibTracker/SiStripCommon/interface/Book.h"
0009 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0010 #include <TTree.h>
0011 #include "SymmetryFit.h"
0012 class TProfile;
0013 
0014 class LA_Filler_Fitter {
0015 public:
0016   //ensemble constructor
0017   LA_Filler_Fitter(int methods, int M, int N, double low, double up, unsigned max, const TrackerTopology* tTopo)
0018       : ensembleSize_(M),
0019         ensembleBins_(N),
0020         ensembleLow_(low),
0021         ensembleUp_(up),
0022         byLayer_(true),
0023         byModule_(false),
0024         localYbin_(0),
0025         stripsPerBin_(0),
0026         maxEvents_(max),
0027         methods_(methods),
0028         tTopo_(tTopo) {}
0029 
0030   //measurement constructor
0031   LA_Filler_Fitter(int methods,
0032                    bool layer,
0033                    bool module,
0034                    float localybin,
0035                    unsigned stripbin,
0036                    unsigned max,
0037                    const TrackerTopology* tTopo)
0038       : ensembleSize_(0),
0039         ensembleBins_(0),
0040         ensembleLow_(0),
0041         ensembleUp_(0),
0042         byLayer_(layer),
0043         byModule_(module),
0044         localYbin_(localybin),
0045         stripsPerBin_(stripbin),
0046         maxEvents_(max),
0047         methods_(methods),
0048         tTopo_(tTopo) {}
0049 
0050   enum Method {
0051     WIDTH = 1 << 0,
0052     FIRST_METHOD = 1 << 0,
0053     PROB1 = 1 << 1,
0054     AVGV2 = 1 << 2,
0055     AVGV3 = 1 << 3,
0056     RMSV2 = 1 << 4,
0057     RMSV3 = 1 << 5,
0058     LAST_METHOD = 1 << 5
0059   };
0060 
0061   static std::string method(Method m, bool fit = true) {
0062     switch (m) {
0063       case WIDTH:
0064         return "_width_prof";
0065       case PROB1:
0066         return fit ? SymmetryFit::name(method(m, false)) : "_prob_w1";
0067       case AVGV2:
0068         return fit ? SymmetryFit::name(method(m, false)) : "_avg_var_w2";
0069       case AVGV3:
0070         return fit ? SymmetryFit::name(method(m, false)) : "_avg_var_w3";
0071       case RMSV2:
0072         return fit ? SymmetryFit::name(method(m, false)) : "_rms_var_w2";
0073       case RMSV3:
0074         return fit ? SymmetryFit::name(method(m, false)) : "_rms_var_w3";
0075       default:
0076         return "_UNKNOWN";
0077     }
0078   }
0079 
0080   struct Result {
0081     std::pair<float, float> reco, measured, calMeasured;
0082     float field, chi2;
0083     unsigned ndof, entries;
0084     Result() : reco(1000, 0), measured(1000, 0), calMeasured(1000, 0), field(0), chi2(0), ndof(0), entries(0) {}
0085   };
0086 
0087   struct EnsembleSummary {
0088     std::pair<float, float> meanMeasured, sigmaMeasured, meanUncertainty, pull;
0089     float truth;
0090     unsigned samples;
0091     EnsembleSummary()
0092         : meanMeasured(0, 0), sigmaMeasured(0, 0), meanUncertainty(0, 0), pull(0, 0), truth(0), samples(0) {}
0093   };
0094 
0095   //Located in src/LA_Filler.cc
0096   void fill(TTree*, Book&) const;
0097   void fill_one_cluster(
0098       Book&, const poly<std::string>&, const unsigned, const float, const float, const float, const float) const;
0099   poly<std::string> allAndOne(const unsigned width) const;
0100   poly<std::string> varWidth(const unsigned width) const;
0101   poly<std::string> granularity(const SiStripDetId, const float, const Long64_t, const float, const unsigned) const;
0102   static std::string subdetLabel(const SiStripDetId);
0103   static std::string moduleLabel(const SiStripDetId);
0104   std::string layerLabel(const SiStripDetId) const;
0105   static unsigned layer_index(bool TIB, bool stereo, unsigned layer) {
0106     return layer + (TIB ? 0 : 6) + (stereo ? 1 : 0) + ((layer > 2) ? 1 : (layer == 1) ? -1 : 0);
0107   }
0108 
0109   //Located in src/LA_Fitter.cc
0110   static void fit(Book& book) {
0111     make_and_fit_symmchi2(book);
0112     fit_width_profile(book);
0113   }
0114   static void make_and_fit_symmchi2(Book&);
0115   static void fit_width_profile(Book&);
0116   static TH1* rms_profile(const std::string, const TProfile* const);
0117   static TH1* subset_probability(const std::string name, const TH1* const, const TH1* const);
0118   static unsigned find_rebin(const TH1* const);
0119 
0120   //Located in src/LA_Results.cc
0121   void summarize_ensembles(Book&) const;
0122   static Result result(Method, const std::string name, const Book&);
0123   static std::map<std::string, Result> layer_results(const Book&, const Method);
0124   static std::map<uint32_t, Result> module_results(const Book&, const Method);
0125   static std::map<std::string, std::vector<Result> > ensemble_results(const Book&, const Method);
0126   static std::map<std::string, std::vector<EnsembleSummary> > ensemble_summary(const Book&);
0127   static std::pair<std::pair<float, float>, std::pair<float, float> > offset_slope(const std::vector<EnsembleSummary>&);
0128   static float pull(const std::vector<EnsembleSummary>&);
0129 
0130 private:
0131   const int ensembleSize_, ensembleBins_;
0132   const double ensembleLow_, ensembleUp_;
0133   const bool byLayer_, byModule_;
0134   const float localYbin_;
0135   const unsigned stripsPerBin_;
0136   const Long64_t maxEvents_;
0137   const int methods_;
0138   const TrackerTopology* tTopo_;
0139 };
0140 
0141 std::ostream& operator<<(std::ostream&, const LA_Filler_Fitter::Result&);
0142 std::ostream& operator<<(std::ostream&, const LA_Filler_Fitter::EnsembleSummary&);
0143 
0144 #endif