CMS 3D CMS Logo

DeDxCalibrationDbCreator.cc
Go to the documentation of this file.
1 // system include files
2 #include <iostream>
3 #include <fstream>
4 #include <vector>
5 
6 // user include files
13 
14 class DeDxCalibrationDbCreator : public edm::one::EDAnalyzer<edm::one::SharedResources> {
15 public:
16  typedef std::pair<uint32_t, unsigned char> ChipId;
17  enum AllDetector { PXB = 0, PXF = 1, TIB = 2, TID = 3, TOB = 4, TECThin = 5, TECThick = 6, nDets };
18 
21 
22 private:
23  void beginJob() override;
24  void analyze(const edm::Event&, const edm::EventSetup&) override{};
25 
26  void readStripProps(std::vector<double>&, std::vector<double>&, std::vector<double>&);
27  void readGainCorrection(std::map<ChipId, float>&);
28 
30 };
31 
33  : propFile_(iConfig.getParameter<std::string>("propFile")),
34  gainFile_(iConfig.getParameter<std::string>("gainFile")) {}
35 
37  std::map<ChipId, float> gain;
38  std::vector<double> thr, alpha, sigma;
39  readStripProps(thr, alpha, sigma);
41  DeDxCalibration TD(thr, alpha, sigma, gain);
42 
44  if (pool.isAvailable())
45  pool->writeOneIOV(TD, pool->beginOfTime(), "DeDxCalibrationRcd");
46 }
47 
48 /*****************************************************************************/
49 void DeDxCalibrationDbCreator::readStripProps(std::vector<double>& thr,
50  std::vector<double>& alpha,
51  std::vector<double>& sigma) {
52  std::cout << " reading strip properties from " << propFile_;
53  std::ifstream file(edm::FileInPath(propFile_).fullPath());
54 
55  int det;
56  for (det = PXB; det <= PXF; det++) {
57  thr.emplace_back(0.);
58  alpha.emplace_back(0.);
59  sigma.emplace_back(0.);
60  }
61 
62  while (!file.eof()) {
63  std::string detName;
64  float f;
65 
66  file >> detName;
67  file >> f;
68  thr.emplace_back(f);
69  file >> f;
70  alpha.emplace_back(f);
71  file >> f;
72  sigma.emplace_back(f);
73 
74  det++;
75  }
76 
77  file.close();
78  std::cout << " [done]" << std::endl;
79 }
80 
81 /*****************************************************************************/
82 void DeDxCalibrationDbCreator::readGainCorrection(std::map<ChipId, float>& gain) {
83  std::cout << " reading gain from " << gainFile_;
84  std::ifstream fileGain(edm::FileInPath(gainFile_).fullPath());
85 
86  int i = 0;
87  while (!fileGain.eof()) {
88  uint32_t det;
89  int chip;
90 
91  int d;
92  float g, f;
93  std::string s;
94 
95  fileGain >> std::hex >> det;
96  fileGain >> std::dec >> chip;
97 
98  ChipId detId(det, (unsigned char)chip);
99 
100  fileGain >> std::dec >> d;
101  fileGain >> g;
102  fileGain >> f;
103  fileGain >> s;
104 
105  if (!fileGain.eof()) {
106  if (g > 0.5 && g < 2.0)
107  gain[detId] = g;
108  else
109  gain[detId] = -1.;
110  }
111 
112  if (i++ % 5000 == 0)
113  std::cout << ".";
114  }
115 
116  fileGain.close();
117  std::cout << " [done]" << std::endl;
118 }
119 
120 //define this as a plug-in
std::pair< uint32_t, unsigned char > ChipId
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 g
Definition: Activities.doc:4
double f[11][100]
DeDxCalibrationDbCreator(const edm::ParameterSet &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
d
Definition: ztail.py:151
void readGainCorrection(std::map< ChipId, float > &)
void analyze(const edm::Event &, const edm::EventSetup &) override
void readStripProps(std::vector< double > &, std::vector< double > &, std::vector< double > &)