CMS 3D CMS Logo

SiStripDB2Tree.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: CondTools/SiStrip
4 // Class: SiStripDB2Tree
5 //
11 //
12 // Original Author: Mauro Verzetti
13 // Modified by: Marco Musich
14 //
15 
16 // system include files
17 #include <map>
18 #include <memory>
19 #include <string>
20 #include <unordered_map>
21 #include <vector>
22 
23 // user include files
50 
52 #define LOGERROR(x) edm::LogError(x)
53 #define LOGINFO(x) edm::LogInfo(x)
54 #define LOGDEBUG(x) LogDebug(x)
55 
56 // ROOT includes
57 #include "TNamed.h"
58 #include "TObjString.h"
59 #include "TText.h"
60 #include "TTree.h"
61 
62 //**********************************************//
63 // Auxilliary class
64 //**********************************************//
65 class RecordInfo : public TNamed {
66 public:
67  RecordInfo(const char* record, const char* tag) : TNamed(record, tag) {}
68 
69  void printInfo() const { LOGINFO("RecordInfo") << GetName() << " " << GetTitle(); }
70 
71  const char* getRecord() { return this->GetName(); }
72  const char* getIOVSince() { return this->GetTitle(); }
73 };
74 
75 class SiStripDB2Tree : public edm::one::EDAnalyzer<edm::one::SharedResources, edm::one::WatchRuns> {
76 public:
77  explicit SiStripDB2Tree(const edm::ParameterSet&);
78  ~SiStripDB2Tree() override = default;
79 
80  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
81 
82 private:
83  void beginRun(edm::Run const&, edm::EventSetup const&) override;
84  void endRun(edm::Run const&, edm::EventSetup const&) override{};
85  void analyze(const edm::Event&, const edm::EventSetup&) override;
86  void setTopoInfo(uint32_t detId, const TrackerTopology* tTopo);
87  template <class Rcd>
88  std::pair<const char*, std::string> getRecordInfo(const edm::EventSetup& iSetup) const;
89 
90  // ----------member data ---------------------------
91 
92  // ES tokens
101 
102  const bool isMC_;
103 
104  TTree* tree_;
106 
107  //branches
112  TText* text_;
113 
114  // detInfo
116 };
117 
118 //
119 // constructors and destructor
120 //
122  : pedToken_(esConsumes()),
123  noiseToken_(esConsumes()),
124  g1Token_(esConsumes()),
125  g2Token_(esConsumes()),
126  qualToken_(esConsumes(edm::ESInputTag("", iConfig.getParameter<std::string>("StripQualityLabel")))),
127  gsimToken_(esConsumes()),
128  latToken_(esConsumes()),
129  topoToken_(esConsumes()),
130  isMC_(iConfig.getUntrackedParameter<bool>("isMC", false)),
131  detId_(0),
132  ring_(0),
133  istrip_(0),
134  det_type_(0),
135  layer_(0),
136  side_(0),
137  subdetId_(0),
138  noise_(0),
139  gsim_(0),
140  g1_(0),
141  g2_(0),
142  lenght_(0),
143  isTIB_(false),
144  isTOB_(false),
145  isTEC_(false),
146  isTID_(false) {
147  usesResource(TFileService::kSharedResource);
148 
150  //now do what ever initialization is needed
151  text_ = fs->make<TText>(0., 0., "");
152  text_->SetName("RunMode");
153  tree_ = fs->make<TTree>("StripDBTree", "Tree with DB SiStrip info");
154 
155  tree_->Branch("detId", &detId_, "detId/i");
156  tree_->Branch("detType", &det_type_, "detType/i");
157  tree_->Branch("noise", &noise_, "noise/F");
158  tree_->Branch("pedestal", &pedestal_, "pedestal/F");
159  tree_->Branch("istrip", &istrip_, "istrip/i");
160  tree_->Branch("gsim", &gsim_, "gsim/F");
161  tree_->Branch("g1", &g1_, "g1/F");
162  tree_->Branch("g2", &g2_, "g2/F");
163  tree_->Branch("layer", &layer_, "layer/I");
164  tree_->Branch("side", &side_, "side/I");
165  tree_->Branch("subdetId", &subdetId_, "subdetId/I");
166  tree_->Branch("ring", &ring_, "ring/i");
167  tree_->Branch("length", &lenght_, "length/F");
168  tree_->Branch("isBad", &isBad_, "isBad/O");
169  tree_->Branch("isTIB", &isTIB_, "isTIB/O");
170  tree_->Branch("isTOB", &isTOB_, "isTOB/O");
171  tree_->Branch("isTEC", &isTEC_, "isTEC/O");
172  tree_->Branch("isTID", &isTID_, "isTID/O");
173 
175 }
176 
177 //
178 // member functions
179 //
180 
181 void SiStripDB2Tree::setTopoInfo(uint32_t detId, const TrackerTopology* tTopo) {
183  switch (subdetId_) {
184  case SiStripSubdetector::TIB: //TIB
185  isTIB_ = true;
186  isTOB_ = false;
187  isTEC_ = false;
188  isTID_ = false;
189  layer_ = tTopo->tibLayer(detId);
190  side_ = 0;
191  ring_ = 0;
192  break;
193  case SiStripSubdetector::TID: //TID
194  isTIB_ = false;
195  isTOB_ = false;
196  isTEC_ = false;
197  isTID_ = true;
198  side_ = tTopo->tidSide(detId);
199  layer_ = tTopo->tidWheel(detId);
200  ring_ = 0;
201  break;
202  case SiStripSubdetector::TOB: //TOB
203  isTIB_ = false;
204  isTOB_ = true;
205  isTEC_ = false;
206  isTID_ = false;
207  layer_ = tTopo->tobLayer(detId);
208  side_ = 0;
209  ring_ = 0;
210  break;
211  case SiStripSubdetector::TEC: //TEC
212  isTIB_ = false;
213  isTOB_ = false;
214  isTEC_ = true;
215  isTID_ = false;
216  side_ = tTopo->tecSide(detId);
217  layer_ = tTopo->tecWheel(detId);
218  ring_ = 0;
219  break;
220  }
221  return;
222 }
223 
224 // ------------ auxilliary method for record info ------------
225 template <class Rcd>
226 std::pair<const char*, std::string> SiStripDB2Tree::getRecordInfo(const edm::EventSetup& iSetup) const {
227  const Rcd& record = iSetup.get<Rcd>();
228  const edm::ValidityInterval& validity = record.validityInterval();
229  const edm::IOVSyncValue first = validity.first();
230  const edm::IOVSyncValue last = validity.last();
232  LOGINFO("SiStripDB2Tree") << "@SUB=SiStripDB2Tree::getRecordInfo"
233  << "\nTrying to apply " << record.key().name() << " with multiple IOVs in tag.\n"
234  << "Validity range is " << first.eventID().run() << " - " << last.eventID().run() << "\n";
235  } else {
236  LOGINFO("SiStripDB2Tree") << "@SUB=SiStripDB2Tree::getRecordInfo"
237  << "\nTrying to apply " << record.key().name() << "Validity range is "
238  << first.eventID().run() << " - " << last.eventID().run() << "\n";
239  }
240 
241  tree_->GetUserInfo()->Add(new RecordInfo(record.key().name(), std::to_string(first.eventID().run()).c_str()));
242 
243  return std::make_pair(record.key().name(), std::to_string(first.eventID().run()));
244 }
245 
246 // ------------ method called for each run ------------
247 void SiStripDB2Tree::beginRun(const edm::Run& iRun, edm::EventSetup const& iSetup) {
248  char c_run[30];
249  sprintf(c_run, "%i", iRun.run());
250  tree_->GetUserInfo()->Add(new TObjString(c_run));
251 
252  auto pedHook = this->getRecordInfo<SiStripPedestalsRcd>(iSetup);
253  auto noiseHook = this->getRecordInfo<SiStripNoisesRcd>(iSetup);
254  auto g1Hook = this->getRecordInfo<SiStripApvGainRcd>(iSetup);
255  auto g2Hook = this->getRecordInfo<SiStripApvGain2Rcd>(iSetup);
256  auto qualityHook = this->getRecordInfo<SiStripQualityRcd>(iSetup);
257  if (isMC_) {
258  auto g1SimHook = this->getRecordInfo<SiStripApvGainSimRcd>(iSetup);
259  }
260 }
261 
262 // ------------ method called for each event ------------
264  // fill header information
266 
267  const edm::ParameterSet& globalTagPSet =
269 
270  processGT_ = globalTagPSet.getParameter<std::string>("globaltag");
271 
272  RecordInfo* GTheader = new RecordInfo("GlobalTag", processGT_.c_str());
273  tree_->GetUserInfo()->Add(GTheader);
274  GTheader->printInfo();
275 
276  // handles
277  const SiStripPedestals* pedestalObj = &iSetup.getData(pedToken_);
278  const SiStripNoises* noiseObj = &iSetup.getData(noiseToken_);
279  const SiStripApvGain* g1Obj = &iSetup.getData(g1Token_);
280  const SiStripApvGain* g2Obj = &iSetup.getData(g2Token_);
281  const SiStripQuality* siStripQualityObj = &iSetup.getData(qualToken_);
282  const SiStripApvGain* gsimObj = nullptr;
283  if (isMC_) {
284  gsimObj = &iSetup.getData(gsimToken_);
285  } else {
286  LOGINFO("SiStripDB2Tree") << "We have determined this Data";
287  }
288 
289  bool first = true;
290  const SiStripLatency* latencyObj = &iSetup.getData(latToken_);
291 
292  std::vector<uint32_t> activeDetIds;
293  noiseObj->getDetIds(activeDetIds);
294 
295  const TrackerTopology* tTopo_ = &iSetup.getData(topoToken_);
296 
297  for (uint32_t detid : activeDetIds) {
298  setTopoInfo(detid, tTopo_);
299 
300  SiStripNoises::Range noiseRange = noiseObj->getRange(detid);
301  SiStripApvGain::Range gsimRange;
302  if (isMC_ && gsimObj != nullptr) {
303  gsimObj->getRange(detid);
304  }
305  SiStripApvGain::Range g1Range = g1Obj->getRange(detid);
306  SiStripApvGain::Range g2Range = g2Obj->getRange(detid);
307  SiStripPedestals::Range pedestalsRange = pedestalObj->getRange(detid);
308 
309  unsigned int nStrip = detInfo_.getNumberOfApvsAndStripLength(detid).first * sistrip::STRIPS_PER_APV;
311  detId_ = detid;
312  det_type_ = static_cast<unsigned int>(SiStripDetId(detid).moduleGeometry());
313  for (istrip_ = 0; istrip_ < nStrip; ++istrip_) {
314  if (first) {
315  first = false;
316  std::string run_op = ((latencyObj->latency(detid, 1) & READMODEMASK) == READMODEMASK) ? "PEAK" : "DECO";
317  text_->SetText(0., 0., run_op.c_str());
318  LOGINFO("SiStripDB2Tree") << "SiStripOperationModeRcd "
319  << ". . . " << run_op;
320  }
321  gsim_ = isMC_ ? gsimObj->getStripGain(istrip_, gsimRange) : 1.;
322  g1_ = g1Obj->getStripGain(istrip_, g1Range) ? g1Obj->getStripGain(istrip_, g1Range) : 1.;
323  g2_ = g2Obj->getStripGain(istrip_, g2Range) ? g2Obj->getStripGain(istrip_, g2Range) : 1.;
324  noise_ = noiseObj->getNoise(istrip_, noiseRange);
325  pedestal_ = pedestalObj->getPed(istrip_, pedestalsRange);
326  isBad_ = siStripQualityObj->IsStripBad(siStripQualityObj->getRange(detid), istrip_);
327  tree_->Fill();
328  }
329  }
330 }
331 
332 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
335 
336  desc.setComment("Creates TTree with SiStrip Database tag content.");
337  desc.add<std::string>("StripQualityLabel", "MergedBadComponent");
338  desc.addUntracked<bool>("isMC", false);
339 
340  descriptions.add("SiStripDB2Tree", desc);
341 }
342 
343 //define this as a plug-in
static const std::string kSharedResource
Definition: TFileService.h:76
static const char noise_[]
void setTopoInfo(uint32_t detId, const TrackerTopology *tTopo)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
static const char layer_[]
unsigned int tobLayer(const DetId &id) const
const Range getRange(const uint32_t &detID) const
std::pair< const char *, std::string > getRecordInfo(const edm::EventSetup &iSetup) const
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
const edm::ESGetToken< SiStripQuality, SiStripQualityRcd > qualToken_
unsigned int tidSide(const DetId &id) const
SiStripModuleGeometry moduleGeometry() const
Definition: SiStripDetId.h:109
const edm::ESGetToken< SiStripApvGain, SiStripApvGainSimRcd > gsimToken_
unsigned int tidWheel(const DetId &id) const
unsigned int tecWheel(const DetId &id) const
ParameterSet const & getParameterSet(std::string const &) const
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:82
void printInfo() const
const edm::ESGetToken< SiStripLatency, SiStripLatencyRcd > latToken_
const edm::ESGetToken< SiStripNoises, SiStripNoisesRcd > noiseToken_
std::pair< ContainerIterator, ContainerIterator > Range
const bool isMC_
const Range getRange(const uint32_t detID) const
~SiStripDB2Tree() override=default
static std::string to_string(const XMLCh *ch)
float getPed(const uint16_t &strip, const Range &range) const
void beginRun(edm::Run const &, edm::EventSetup const &) override
const char * getIOVSince()
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > topoToken_
static float getNoise(uint16_t strip, const Range &range)
Definition: SiStripNoises.h:72
int iEvent
Definition: GenABIO.cc:224
RunNumber_t run() const
Definition: RunBase.h:40
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
static const IOVSyncValue & beginOfTime()
Definition: IOVSyncValue.cc:88
unsigned int tecSide(const DetId &id) const
static const char ring_[]
const edm::ESGetToken< SiStripApvGain, SiStripApvGain2Rcd > g2Token_
RecordInfo(const char *record, const char *tag)
std::pair< ContainerIterator, ContainerIterator > Range
T get() const
Definition: EventSetup.h:79
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
void endRun(edm::Run const &, edm::EventSetup const &) override
SiStripDetInfo read(std::string filePath)
void analyze(const edm::Event &, const edm::EventSetup &) override
ParameterSet const & getProcessParameterSetContainingModule(ModuleDescription const &moduleDescription)
Detector identifier class for the strip tracker.
Definition: SiStripDetId.h:18
Definition: DetId.h:17
SiStripDB2Tree(const edm::ParameterSet &)
const std::pair< unsigned short, double > getNumberOfApvsAndStripLength(uint32_t detId) const
bool IsStripBad(uint32_t detid, short strip) const
const char * getRecord()
Constants and enumerated types for FED/FEC systems.
const edm::ESGetToken< SiStripPedestals, SiStripPedestalsRcd > pedToken_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
SiStripDetInfo detInfo_
const Range getRange(const uint32_t detID) const
ModuleDescription const & moduleDescription() const
const Range getRange(const uint32_t detID) const
#define LOGINFO(x)
HLT enums.
static float getStripGain(uint16_t strip, const Range &range)
static const uint16_t STRIPS_PER_APV
uint16_t latency(const uint32_t detId, const uint16_t apv) const
std::string processGT_
std::string dump(unsigned int indent=0) const
static constexpr char const *const kDefaultFile
unsigned int tibLayer(const DetId &id) const
std::pair< ContainerIterator, ContainerIterator > Range
Definition: SiStripNoises.h:47
void getDetIds(std::vector< uint32_t > &DetIds_) const
Definition: Run.h:45
#define READMODEMASK
#define LogDebug(id)
const edm::ESGetToken< SiStripApvGain, SiStripApvGainRcd > g1Token_