CMS 3D CMS Logo

MaterialAccountingGroup.h

Go to the documentation of this file.
00001 #ifndef MaterialAccountingGroup_h
00002 #define MaterialAccountingGroup_h
00003 
00004 #include <string>
00005 #include <stdexcept>
00006 #include <utility>
00007 
00008 #include "Geometry/CommonDetUnit/interface/GeomDetEnumerators.h"
00009 #include "TrackingTools/DetLayers/interface/DetLayer.h"
00010 
00011 #include "SimDataFormats/ValidationFormats/interface/MaterialAccountingStep.h"
00012 #include "SimDataFormats/ValidationFormats/interface/MaterialAccountingDetector.h"
00013 
00014 class TH1;
00015 class TH1F;
00016 class TProfile;
00017 class TFile;
00018 
00019 class MaterialAccountingGroup {
00020 private:
00021 
00022   // quick implementation of a bounding cilinder
00023   class BoundingBox {
00024   public:
00025 
00026     BoundingBox(double min_r, double max_r, double min_z, double max_z) :
00027       r_min(min_r),
00028       r_max(max_r),
00029       z_min(min_z),
00030       z_max(max_z)
00031     { }
00032 
00033     BoundingBox() :
00034       r_min(0.),
00035       r_max(0.),
00036       z_min(0.),
00037       z_max(0.)
00038     { }
00039 
00040     void grow(double r, double z) {
00041       if (r < r_min) r_min = r;
00042       if (r > r_max) r_max = r;
00043       if (z < z_min) z_min = z;
00044       if (z > z_max) z_max = z;
00045     }
00046 
00047     void grow(double skin) {
00048       r_min -= skin;    // yes, we allow r_min to go negative
00049       r_max += skin;
00050       z_min -= skin;
00051       z_max += skin;
00052     }
00053 
00054     bool inside(double r, double z) const {
00055       return (r >= r_min and r <= r_max and z >= z_min and z <= z_max);
00056     }
00057 
00058     std::pair<double, double> range_r() const {
00059       return std::make_pair(r_min, r_max);
00060     }
00061 
00062     std::pair<double, double> range_z() const {
00063       return std::make_pair(z_min, z_max);
00064     }
00065 
00066   private:
00067     double r_min;
00068     double r_max;
00069     double z_min;
00070     double z_max;
00071   };
00072   
00073 public:
00075   MaterialAccountingGroup( const std::string & name, const DDCompactView & geometry );
00076     
00078   ~MaterialAccountingGroup( void );
00079 
00080 private:
00082   MaterialAccountingGroup(const MaterialAccountingGroup & layer);
00083 
00085   MaterialAccountingGroup& operator=( const MaterialAccountingGroup & layer);
00086 
00087 public:
00089   bool addDetector( const MaterialAccountingDetector& detector );
00090  
00092   void endOfTrack( void );
00093   
00095   bool inside( const MaterialAccountingDetector& detector ) const;
00096 
00098   MaterialAccountingStep average(void) const 
00099   {
00100     return m_tracks ? m_accounting / m_tracks : MaterialAccountingStep();
00101   }
00102 
00104   double averageLength(void) const 
00105   {
00106     return m_tracks ? m_accounting.length() / m_tracks : 0.;
00107   }
00108   
00110   double averageRadiationLengths(void) const 
00111   {
00112     return m_tracks ? m_accounting.radiationLengths() / m_tracks : 0.;
00113   }
00114   
00116   double averageEnergyLoss(void) const 
00117   {
00118     return m_tracks ? m_accounting.energyLoss() / m_tracks : 0.;
00119   }
00120  
00122   double sigmaLength(void) const 
00123   {
00124     return m_tracks ? std::sqrt(m_errors.length() / m_tracks - averageLength()*averageLength()) : 0.;
00125   }
00126   
00128   double sigmaRadiationLengths(void) const 
00129   {
00130     return m_tracks ? std::sqrt(m_errors.radiationLengths() / m_tracks - averageRadiationLengths()*averageRadiationLengths()) : 0.;
00131   }
00132   
00134   double sigmaEnergyLoss(void) const 
00135   {
00136     return m_tracks ? std::sqrt(m_errors.energyLoss() / m_tracks - averageEnergyLoss()*averageEnergyLoss()) : 0.;
00137   }
00138  
00140   unsigned int tracks(void) const 
00141   {
00142     return m_tracks;
00143   }
00144  
00146   const std::string & name(void) const
00147   {
00148     return m_name;
00149   }
00150 
00152   std::string info(void) const;
00153 
00155   void savePlots(void);
00156  
00157 private:
00158   void savePlot(TH1F * plot, const std::string & name);
00159   void savePlot(TProfile * plot, float average, const std::string & name);
00160  
00161   std::string                   m_name;
00162   std::vector<GlobalPoint>      m_elements;
00163   BoundingBox                   m_boundingbox;
00164   MaterialAccountingStep        m_accounting;
00165   MaterialAccountingStep        m_errors;
00166   unsigned int                  m_tracks;
00167   bool                          m_counted;
00168   MaterialAccountingStep        m_buffer;
00169   
00170   // plots of material effects distribution
00171   TH1F * m_dedx_spectrum;
00172   TH1F * m_radlen_spectrum;
00173   // plots of material effects vs. η / Z / R
00174   TProfile * m_dedx_vs_eta;
00175   TProfile * m_dedx_vs_z;
00176   TProfile * m_dedx_vs_r;
00177   TProfile * m_radlen_vs_eta;
00178   TProfile * m_radlen_vs_z;
00179   TProfile * m_radlen_vs_r;
00180 
00181   // file to store plots into
00182   mutable TFile * m_file;
00183 
00184   // 100um should be small enough that no elements from different layers/groups are so close
00185   static double s_tolerance;
00186 };
00187 
00188 #endif // MaterialAccountingGroup_h

Generated on Tue Jun 9 17:47:55 2009 for CMSSW by  doxygen 1.5.4