Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-03-24 23:46:11

0001 #ifndef SiStripDetSummary_h
0002 #define SiStripDetSummary_h
0003 
0004 #include "DataFormats/DetId/interface/DetId.h"
0005 class TrackerTopology;
0006 
0007 #include <sstream>
0008 #include <map>
0009 #include <cmath>
0010 #include <iomanip>
0011 #include <iostream>
0012 
0013 /**
0014  * @class SiStripDetSummary
0015  * @author M. De Mattia
0016  * @date 26/3/2009
0017  * Class to compute and print summary information.
0018  *
0019  * If values are passed together with DetIds (method add( detId, value)), it computes the mean value and
0020  * rms of a given quantity and is able to print a summary divided by layer/disk for each subdetector. <br>
0021  * If instead only DetIds are passed (method add( detId )), it prints the count divided by layer/disk for
0022  * each subdetector. <br>
0023  * <br>
0024  * Note: consider the possibility to move this class inside SiStripBaseObject as a protected member class.
0025  *
0026  */
0027 
0028 class SiStripDetSummary {
0029 public:
0030   explicit SiStripDetSummary(const TrackerTopology* tTopo) : computeMean_(true), trackerTopo_(tTopo) {
0031     // Initialize valueMap_ with zeros
0032     // WARNING: this initialization is strongly connected with how the map is filled in the add method
0033     // TIB: layers = 4, stereo = the first 2
0034     // TOB: layers = 6, stereo = the first 2
0035     // TEC: wheels = 9, stereo = 9
0036     // TID: wheels = 3, stereo = 3
0037     unsigned int layers[] = {4, 6, 9, 3};
0038     unsigned int stereo[] = {2, 2, 9, 3};
0039     Values initValues;
0040     for (unsigned int subDet = 0; subDet < 4; ++subDet) {
0041       // Layers start from 1
0042       for (unsigned int layer = 1; layer <= layers[subDet]; ++layer) {
0043         valueMap_[1000 * (subDet + 1) + layer * 10] = initValues;
0044         if (layer <= stereo[subDet])
0045           valueMap_[1000 * (subDet + 1) + layer * 10 + 1] = initValues;
0046       }
0047     }
0048   }
0049 
0050   /// Used to compute the mean value of the value variable divided by subdetector, layer and mono/stereo
0051   void add(DetId detid, float value);
0052   /// Used to compute the number of entries divided by subdetector, layer and mono/stereo
0053   inline void add(DetId detid) {
0054     computeMean_ = false;
0055     add(detid, 0);
0056   }
0057 
0058   /**
0059    * Method used to write the output. By default mean == true and it writes the mean value. If mean == false
0060    * it will write the count.
0061    */
0062   void print(std::stringstream& ss, const bool mean = true) const;
0063 
0064   inline void clear() { valueMap_.clear(); }
0065 
0066   struct Values {
0067     Values() : mean(0.), rms(0.), count(0) {}
0068     double mean;
0069     double rms;
0070     unsigned int count;
0071   };
0072   std::map<unsigned int, Values> getCounts() { return valueMap_; }
0073 
0074 protected:
0075   // Maps to store the value and the counts
0076   std::map<unsigned int, Values> valueMap_;
0077   bool computeMean_;
0078 
0079 private:
0080   const TrackerTopology* trackerTopo_;
0081 };
0082 
0083 #endif