CMS 3D CMS Logo

HBHEDarkening.cc
Go to the documentation of this file.
2 
4 
5 #include <vector>
6 #include <string>
7 #include <map>
8 #include <algorithm>
9 #include <fstream>
10 #include <iostream>
11 #include <string>
12 #include <sstream>
13 #include <cmath>
14 #include <cassert>
15 
16 HBHEDarkening::HBHEDarkening(int ieta_shift, float drdA, float drdB, const std::map<int,std::vector<std::vector<float>>>& dosemaps, const std::vector<LumiYear>& years) :
17  ieta_shift_(ieta_shift), drdA_(drdA), drdB_(drdB), dosemaps_(dosemaps), years_(years)
18 {
19  //finish initializing years
20  std::sort(years_.begin(),years_.end());
21  //sum up int lumi
22  float sumlumi = 0.0;
23  for(auto& year : years_){
24  sumlumi += year.intlumi_;
25  year.sumlumi_ = sumlumi;
26  }
27 }
28 
29 std::vector<std::vector<float>> HBHEDarkening::readDoseMap(const std::string& fullpath) {
30  std::ifstream infile(fullpath.c_str());
31  if(!infile.is_open()){
32  throw cms::Exception("FileNotFound") << "Unable to open '" << fullpath << "'" << std::endl;
33  }
35  std::vector<std::vector<float>> result;
36  while(getline(infile,line)){
37  //space-separated
38  std::stringstream linestream(line);
39  std::vector<float> lineresult;
40  float doseval;
41  while(linestream >> doseval) lineresult.push_back(doseval);
42  result.push_back(lineresult);
43  }
44  return result;
45 }
46 
47 float HBHEDarkening::dose(int ieta, int lay, int energy) const {
48  //existence check
49  const auto dosemapIt = dosemaps_.find(energy);
50  if(dosemapIt == dosemaps_.end()) return 0.0;
51 
52  //bounds check
53  const auto& dosemap = dosemapIt->second;
54  if(ieta<0 or ieta>=int(dosemap.size())) return 0.0;
55 
56  //bounds check
57  const auto& doserow = dosemap[ieta];
58  if(lay<0 or lay>=int(doserow.size())) return 0.0;
59 
60  return doserow[lay];
61 }
62 
64  //compare based on sum lumi value
65  auto lb = std::lower_bound(years_.begin(),years_.end(),intlumi,LumiYearComp());
66  if(lb == years_.end() or lb->sumlumi_ < intlumi) {
67  throw cms::Exception("ValueError") << "HBHEDarkening: insufficient LHC run information provided to simulate " << intlumi << "/fb - check the python config" << std::endl;
68  }
69  return lb->year_;
70 }
71 
72 float HBHEDarkening::degradationYear(const LumiYear& year, float intlumi, int ieta, int lay) const {
73  float doseToUse = dose(ieta,lay,year.energy_);
74  if(doseToUse==0.0) return 1.0;
75 
76  //apply dose rate dependence model to the provided year
77  //get krad/hr from Mrad/fb-1 and fb-1/hr
78  float decayConst = drdA_*std::pow(1000*doseToUse*year.lumirate_,drdB_);
79 
80  //determine if this is a partial year
81  float intlumiToUse = year.intlumi_;
82  if(intlumi < year.sumlumi_) intlumiToUse = year.sumlumi_ - intlumi;
83 
84  //calculate degradation
85  return std::exp(-(intlumiToUse*doseToUse)/decayConst);
86 }
87 
88 float HBHEDarkening::degradation(float intlumi, int ieta, int lay) const {
89  ieta = abs(ieta);
90  //shift ieta tower index to act as array index
91  ieta -= ieta_shift_;
92  //shift layer index by 1 to act as array index
93  lay -= 1;
94 
95  //accumulate degradation over years
96  float response = 1.0;
97  std::string yearForLumi = getYearForLumi(intlumi);
98  assert(yearForLumi.size());
99 
100  for(const auto& year : years_){
101  response *= degradationYear(year,intlumi,ieta,lay);
102  if(year.year_==yearForLumi) break;
103  }
104 
105  return response;
106 }
HBHEDarkening(int ieta_shift, float drdA, float drdB, const std::map< int, std::vector< std::vector< float >>> &dosemaps, const std::vector< LumiYear > &years)
std::string getYearForLumi(float intlumi) const
std::map< int, std::vector< std::vector< float > > > dosemaps_
Definition: HBHEDarkening.h:64
static std::vector< std::vector< float > > readDoseMap(const std::string &fullpath)
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
float degradationYear(const LumiYear &year, float intlumi, int ieta, int lay) const
std::vector< LumiYear > years_
Definition: HBHEDarkening.h:65
float dose(int ieta, int lay, int energy) const
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
float degradation(float intlumi, int ieta, int lay) const