CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripLorentzAngleGenerator.cc
Go to the documentation of this file.
3 #include <boost/cstdint.hpp>
8 #include "CLHEP/Random/RandGauss.h"
9 #include "CLHEP/Random/RandFlat.h"
10 
11 #include<cmath>
12 #include<algorithm>
13 #include<numeric>
14 
15 // Defined inside a nameless namespace so that it is local to this file
16 namespace {
17  double computeSigma(const double & value, const double & perCentError) {
18  return (perCentError/100)*value;
19  }
20 }
21 
24 {
25  edm::LogInfo("SiStripLorentzAngleGenerator") << "[SiStripLorentzAngleGenerator::SiStripLorentzAngleGenerator]";
26 }
27 
28 
30  edm::LogInfo("SiStripLorentzAngleGenerator") << "[SiStripLorentzAngleGenerator::~SiStripLorentzAngleGenerator]";
31 }
32 
33 void SiStripLorentzAngleGenerator::setHallMobility(const double & meanMin, const double & meanMax, const double & sigma, const bool uniform) {
34  if( uniform ) hallMobility_ = CLHEP::RandFlat::shoot(meanMin, meanMax);
35  else if( sigma>0 ) hallMobility_ = CLHEP::RandGauss::shoot(meanMin, sigma);
36  else hallMobility_ = meanMin;
37 }
38 
39 void SiStripLorentzAngleGenerator::setUniform(const std::vector<double> & estimatedValuesMin, const std::vector<double> & estimatedValuesMax, std::vector<bool> & uniform) {
40  if( estimatedValuesMax.size() != 0 ) {
41  std::vector<double>::const_iterator min = estimatedValuesMin.begin();
42  std:: vector<double>::const_iterator max = estimatedValuesMax.begin();
43  std::vector<bool>::iterator uniformIt = uniform.begin();
44  for( ; min != estimatedValuesMin.end(); ++min, ++max, ++uniformIt ) {
45  if( *min != *max ) *uniformIt = true;
46  }
47  }
48 }
49 
51 {
52  obj_ = new SiStripLorentzAngle();
53 
55 
56  std::vector<double> TIB_EstimatedValuesMin(_pset.getParameter<std::vector<double> >("TIB_EstimatedValuesMin"));
57  std::vector<double> TIB_EstimatedValuesMax(_pset.getParameter<std::vector<double> >("TIB_EstimatedValuesMax"));
58  std::vector<double> TOB_EstimatedValuesMin(_pset.getParameter<std::vector<double> >("TOB_EstimatedValuesMin"));
59  std::vector<double> TOB_EstimatedValuesMax(_pset.getParameter<std::vector<double> >("TOB_EstimatedValuesMax"));
60  std::vector<double> TIB_PerCent_Errs(_pset.getParameter<std::vector<double> >("TIB_PerCent_Errs"));
61  std::vector<double> TOB_PerCent_Errs(_pset.getParameter<std::vector<double> >("TOB_PerCent_Errs"));
62 
63  // If max values are passed they must be equal in number to the min values.
64  if( (TIB_EstimatedValuesMax.size() != 0 && (TIB_EstimatedValuesMin.size() != TIB_EstimatedValuesMax.size())) ||
65  (TOB_EstimatedValuesMax.size() != 0 && (TOB_EstimatedValuesMin.size() != TOB_EstimatedValuesMax.size())) ) {
66  std::cout << "ERROR: size of min and max values is different" << std::endl;
67  std::cout << "TIB_EstimatedValuesMin.size() = " << TIB_EstimatedValuesMin.size() << ", TIB_EstimatedValuesMax.size() " << TIB_EstimatedValuesMax.size() << std::endl;
68  std::cout << "TOB_EstimatedValuesMin.size() = " << TOB_EstimatedValuesMin.size() << ", TOB_EstimatedValuesMax.size() " << TOB_EstimatedValuesMax.size() << std::endl;
69  }
70  std::vector<bool> uniformTIB(TIB_EstimatedValuesMin.size(), false);
71  std::vector<bool> uniformTOB(TOB_EstimatedValuesMin.size(), false);
72 
73  setUniform(TIB_EstimatedValuesMin, TIB_EstimatedValuesMax, uniformTIB);
74  setUniform(TOB_EstimatedValuesMin, TOB_EstimatedValuesMax, uniformTOB);
75 
77 
78  // Compute standard deviations
79  std::vector<double> StdDevs_TIB(TIB_EstimatedValuesMin.size(), 0);
80  std::vector<double> StdDevs_TOB(TOB_EstimatedValuesMin.size(), 0);
81  transform(TIB_EstimatedValuesMin.begin(), TIB_EstimatedValuesMin.end(), TIB_PerCent_Errs.begin(), StdDevs_TIB.begin(), computeSigma);
82  transform(TOB_EstimatedValuesMin.begin(), TOB_EstimatedValuesMin.end(), TOB_PerCent_Errs.begin(), StdDevs_TOB.begin(), computeSigma);
83 
84  // Compute mean values to be used with TID and TEC
85  double TIBmeanValueMin = std::accumulate( TIB_EstimatedValuesMin.begin(), TIB_EstimatedValuesMin.end(), 0.)/double(TIB_EstimatedValuesMin.size());
86  double TIBmeanValueMax = std::accumulate( TIB_EstimatedValuesMax.begin(), TIB_EstimatedValuesMax.end(), 0.)/double(TIB_EstimatedValuesMax.size());
87  double TOBmeanValueMin = std::accumulate( TOB_EstimatedValuesMin.begin(), TOB_EstimatedValuesMin.end(), 0.)/double(TOB_EstimatedValuesMin.size());
88  double TOBmeanValueMax = std::accumulate( TOB_EstimatedValuesMax.begin(), TOB_EstimatedValuesMax.end(), 0.)/double(TOB_EstimatedValuesMax.size());
89  double TIBmeanPerCentError = std::accumulate( TIB_PerCent_Errs.begin(), TIB_PerCent_Errs.end(), 0.)/double(TIB_PerCent_Errs.size());
90  double TOBmeanPerCentError = std::accumulate( TOB_PerCent_Errs.begin(), TOB_PerCent_Errs.end(), 0.)/double(TOB_PerCent_Errs.size());
91  double TIBmeanStdDev = (TIBmeanPerCentError/100)*TIBmeanValueMin;
92  double TOBmeanStdDev = (TOBmeanPerCentError/100)*TOBmeanValueMin;
93 
94  const std::vector<uint32_t> DetIds = reader.getAllDetIds();
95  for(std::vector<uint32_t>::const_iterator detit=DetIds.begin(); detit!=DetIds.end(); detit++){
96 
97  hallMobility_ = 0;
98 
99  StripSubdetector subid(*detit);
100 
101  int layerId = 0;
102 
103  if(subid.subdetId() == int (StripSubdetector::TIB)) {
104  TIBDetId theTIBDetId(*detit);
105  layerId = theTIBDetId.layer() - 1;
106  setHallMobility( TIB_EstimatedValuesMin[layerId], TIB_EstimatedValuesMax[layerId], StdDevs_TIB[layerId], uniformTIB[layerId] );
107  }
108  else if(subid.subdetId() == int (StripSubdetector::TOB)) {
109  TOBDetId theTOBDetId(*detit);
110  layerId = theTOBDetId.layer() - 1;
111  setHallMobility( TOB_EstimatedValuesMin[layerId], TOB_EstimatedValuesMax[layerId], StdDevs_TOB[layerId], uniformTOB[layerId] );
112  }
113  else if(subid.subdetId() == int (StripSubdetector::TID)) {
114  // ATTENTION: as of now the uniform generation for TID is decided by the setting for layer 0 of TIB
115  setHallMobility( TIBmeanValueMin, TIBmeanValueMax, TIBmeanStdDev, uniformTIB[0] );
116  }
117  if(subid.subdetId() == int (StripSubdetector::TEC)){
118  TECDetId TECid = TECDetId(*detit);
119  if(TECid.ringNumber()<5){
120  // ATTENTION: as of now the uniform generation for TEC is decided by the setting for layer 0 of TIB
121  setHallMobility( TIBmeanValueMin, TIBmeanValueMax, TIBmeanStdDev, uniformTIB[0] );
122  }else{
123  // ATTENTION: as of now the uniform generation for TEC is decided by the setting for layer 0 of TOB
124  setHallMobility( TOBmeanValueMin, TOBmeanValueMax, TOBmeanStdDev, uniformTOB[0] );
125  }
126  }
127 
128  if ( ! obj_->putLorentzAngle(*detit, hallMobility_) ) {
129  edm::LogError("SiStripLorentzAngleGenerator")<<" detid already exists"<<std::endl;
130  }
131  }
132 }
T getParameter(std::string const &) const
SiStripLorentzAngleGenerator(const edm::ParameterSet &, const edm::ActivityRegistry &)
tuple SiStripLorentzAngle
Definition: redigi_cff.py:15
void setUniform(const std::vector< double > &TIB_EstimatedValuesMin, const std::vector< double > &TIB_EstimatedValuesMax, std::vector< bool > &uniformTIB)
Method used to determine whether to generate with a uniform distribution for each layer...
unsigned int layer() const
layer id
Definition: TOBDetId.h:39
#define min(a, b)
Definition: mlp_lapack.h:161
bool putLorentzAngle(const uint32_t &, float &)
const T & max(const T &a, const T &b)
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
unsigned int layer() const
layer id
Definition: TIBDetId.h:41
unsigned int ringNumber() const
Definition: TECDetId.h:98
tuple cout
Definition: gather_cfg.py:121
std::string fullPath() const
Definition: FileInPath.cc:171
void setHallMobility(const double &meanMin, const double &meanMax, const double &sigma, const bool uniform)