CMS 3D CMS Logo

SiStripApvGainReader.cc
Go to the documentation of this file.
5 
7 
8 #include <iostream>
9 #include <cstdio>
10 #include <sys/time.h>
11 
12 using namespace cms;
13 
15  : printdebug_(iConfig.getUntrackedParameter<bool>("printDebug", true)),
16  formatedOutput_(iConfig.getUntrackedParameter<std::string>("outputFile", "")),
17  gainType_(iConfig.getUntrackedParameter<uint32_t>("gainType", 1)),
18  tree_(nullptr) {
19  if (fs_.isAvailable()) {
20  tree_ = fs_->make<TTree>("Gains", "Gains");
21 
22  tree_->Branch("Index", &id_, "Index/I");
23  tree_->Branch("DetId", &detId_, "DetId/I");
24  tree_->Branch("APVId", &apvId_, "APVId/I");
25  tree_->Branch("Gain", &gain_, "Gain/D");
26  }
27 }
28 
30 
32  edm::ESHandle<SiStripGain> SiStripApvGain_;
33  iSetup.get<SiStripGainRcd>().get(SiStripApvGain_);
34  edm::LogInfo("SiStripApvGainReader") << "[SiStripApvGainReader::analyze] End Reading SiStripApvGain" << std::endl;
35  std::vector<uint32_t> detid;
36  SiStripApvGain_->getDetIds(detid);
37  edm::LogInfo("Number of detids ") << detid.size() << std::endl;
38 
39  FILE* pFile = nullptr;
40  if (!formatedOutput_.empty())
41  pFile = fopen(formatedOutput_.c_str(), "w");
42  for (size_t id = 0; id < detid.size(); id++) {
43  SiStripApvGain::Range range = SiStripApvGain_->getRange(detid[id], gainType_);
44  if (printdebug_) {
45  int apv = 0;
46  for (int it = 0; it < range.second - range.first; it++) {
47  edm::LogInfo("SiStripApvGainReader") << "detid " << detid[id] << " \t " << apv++ << " \t "
48  << SiStripApvGain_->getApvGain(it, range) << std::endl;
49  id_++;
50 
51  if (tree_) {
52  detId_ = detid[id];
53  apvId_ = apv;
54  gain_ = SiStripApvGain_->getApvGain(it, range);
55  tree_->Fill();
56  }
57  }
58  }
59 
60  if (pFile) {
61  fprintf(pFile, "%i ", detid[id]);
62  for (int it = 0; it < range.second - range.first; it++) {
63  fprintf(pFile, "%f ", SiStripApvGain_->getApvGain(it, range));
64  }
65  fprintf(pFile, "\n");
66  }
67  }
68 
69  if (pFile)
70  fclose(pFile);
71 }
#define nullptr
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
static float getApvGain(const uint16_t &apv, const SiStripApvGain::Range &range)
Definition: SiStripGain.h:76
bool isAvailable() const
Definition: Service.h:40
std::pair< ContainerIterator, ContainerIterator > Range
void getDetIds(std::vector< uint32_t > &DetIds_) const
ATTENTION: we assume the detIds are the same as those from the first gain.
Definition: SiStripGain.cc:102
Namespace of DDCMS conversion namespace.
edm::Service< TFileService > fs_
void analyze(const edm::Event &, const edm::EventSetup &) override
T get() const
Definition: EventSetup.h:73
SiStripApvGainReader(const edm::ParameterSet &)
const SiStripApvGain::Range getRange(uint32_t detID) const
Definition: SiStripGain.h:71