CMS 3D CMS Logo

SiStripQualityHotStripIdentifierRoot.cc
Go to the documentation of this file.
2 
4 
11 
12 #include <fstream>
13 #include <iostream>
14 #include <memory>
15 #include <sstream>
16 
17 #include "TH1F.h"
18 
19 //Insert here the include to the algos
24 
27  UseInputDB_(iConfig.getUntrackedParameter<bool>("UseInputDB", false)),
28  conf_(iConfig),
29  tracker_(nullptr),
30  tTopo(nullptr),
31  filename(iConfig.getUntrackedParameter<std::string>("rootFilename", "CondDB_TKCC_20X_v3_hlt_50822.root")),
32  dirpath(iConfig.getUntrackedParameter<std::string>("rootDirPath", "")),
33  TotNumberOfEvents(0),
34  MeanNumberOfCluster(0),
35  calibrationthreshold(iConfig.getUntrackedParameter<uint32_t>("CalibrationThreshold", 10000)),
36  tTopoToken_(esConsumes<edm::Transition::BeginRun>()),
37  tkGeomToken_(esConsumes<edm::Transition::BeginRun>()),
38  stripQualityToken_(UseInputDB_
39  ? decltype(stripQualityToken_)(esConsumes<edm::Transition::BeginRun>(
40  edm::ESInputTag{"", iConfig.getUntrackedParameter<std::string>("dataLabel", "")}))
41  : decltype(stripQualityToken_){}) {
42  dqmStore_ = edm::Service<DQMStore>().operator->();
43 
44  if (!filename.empty()) {
45  edm::LogInfo("SiStripQualityHotStripIdentifierRoot") << " before opening file " << filename.c_str();
46  dqmStore_->open(filename, false);
47  edm::LogInfo("SiStripQualityHotStripIdentifierRoot") << " after opening file ";
48  }
49 }
50 
52 
53 std::unique_ptr<SiStripBadStrip> SiStripQualityHotStripIdentifierRoot::getNewObject() {
54  edm::LogInfo("SiStripQualityHotStripIdentifierRoot")
55  << "SiStripQualityHotStripIdentifierRoot::getNewObject called" << std::endl;
56 
57  auto obj = std::make_unique<SiStripBadStrip>();
58 
60  std::string AlgoName = parameters.getParameter<std::string>("AlgoName");
61 
62  bookHistos();
63 
65  edm::LogInfo("SiStripQualityHotStripIdentifierRoot")
66  << " [SiStripQualityHotStripIdentifierRoot::getNewObject] Total number of events is " << TotNumberOfEvents
67  << " which is bigger than " << calibrationthreshold << ". Calibration is preparing to be launched."
68  << std::endl;
69  if (MeanNumberOfCluster > 0.01) {
70  edm::LogInfo("SiStripQualityHotStripIdentifierRoot")
71  << "Mean Number of Cluster is " << MeanNumberOfCluster << ". Calibration is launched." << std::endl;
72 
73  if (AlgoName == "SiStripHotStripAlgorithmFromClusterOccupancy") {
74  edm::LogInfo("SiStripQualityHotStripIdentifierRoot") << " [SiStripQualityHotStripIdentifierRoot::getNewObject] "
75  "call to SiStripHotStripAlgorithmFromClusterOccupancy"
76  << std::endl;
77 
79  theIdentifier->setProbabilityThreshold(parameters.getUntrackedParameter<double>("ProbabilityThreshold", 1.E-7));
80  theIdentifier->setMinNumEntries(parameters.getUntrackedParameter<uint32_t>("MinNumEntries", 100));
81  theIdentifier->setMinNumEntriesPerStrip(parameters.getUntrackedParameter<uint32_t>("MinNumEntriesPerStrip", 5));
82  theIdentifier->setOccupancyThreshold(parameters.getUntrackedParameter<double>("OccupancyThreshold", 1.E-5));
85  conf_.getUntrackedParameter<std::string>("OccupancyRootFile", "Occupancy.root"),
86  conf_.getUntrackedParameter<bool>("WriteOccupancyRootFile", false));
88 
89  const auto detInfo =
91  SiStripQuality* qobj = new SiStripQuality(detInfo);
93  qobj,
95  SiStripQuality_); //here I insert SiStripQuality as input and get qobj as output
96 
97  //----------
98 
99  edm::LogInfo("SiStripQualityHotStripIdentifierRoot")
100  << " [SiStripQualityHotStripIdentifierRoot::getNewObject] copy SiStripObject in SiStripBadStrip"
101  << std::endl;
102 
103  std::stringstream ss;
104 
105  SiStripBadStrip::RegistryIterator rIter = qobj->getRegistryVectorBegin();
106  SiStripBadStrip::RegistryIterator rIterEnd = qobj->getRegistryVectorEnd();
107  for (; rIter != rIterEnd; ++rIter) {
108  SiStripBadStrip::Range range(qobj->getDataVectorBegin() + rIter->ibegin,
109  qobj->getDataVectorBegin() + rIter->iend);
110  if (!obj->put(rIter->detid, range))
111  edm::LogError("SiStripQualityHotStripIdentifierRoot")
112  << "[SiStripQualityHotStripIdentifierRoot::getNewObject] detid already exists" << std::endl;
113  }
114  edm::LogInfo("SiStripQualityHotStripIdentifierRoot")
115  << " [SiStripQualityHotStripIdentifierRoot::getNewObject] " << ss.str() << std::endl;
116  } else if (AlgoName == "SiStripBadAPVAlgorithmFromClusterOccupancy") {
117  edm::LogInfo("SiStripQualityHotStripIdentifierRoot") << " [SiStripQualityHotStripIdentifierRoot::getNewObject] "
118  "call to SiStripBadAPVAlgorithmFromClusterOccupancy"
119  << std::endl;
120 
122  theIdentifier2->setLowOccupancyThreshold(parameters.getUntrackedParameter<double>("LowOccupancyThreshold", 5));
124  parameters.getUntrackedParameter<double>("HighOccupancyThreshold", 10));
125  theIdentifier2->setAbsoluteLowThreshold(parameters.getUntrackedParameter<double>("AbsoluteLowThreshold", 0));
126  theIdentifier2->setNumberIterations(parameters.getUntrackedParameter<uint32_t>("NumberIterations", 2));
128  parameters.getUntrackedParameter<double>("OccupancyThreshold", 1.E-5));
132  conf_.getUntrackedParameter<std::string>("OccupancyRootFile", "Occupancy.root"),
133  conf_.getUntrackedParameter<bool>("WriteOccupancyRootFile", false));
135 
136  const auto detInfo =
138  SiStripQuality* qobj = new SiStripQuality(detInfo);
140 
141  //----------
142 
143  edm::LogInfo("SiStripQualityHotStripIdentifierRoot")
144  << " [SiStripQualityHotStripIdentifierRoot::getNewObject] copy SiStripObject in SiStripBadStrip"
145  << std::endl;
146 
147  std::stringstream ss;
148 
149  SiStripBadStrip::RegistryIterator rIter = qobj->getRegistryVectorBegin();
150  SiStripBadStrip::RegistryIterator rIterEnd = qobj->getRegistryVectorEnd();
151  for (; rIter != rIterEnd; ++rIter) {
152  SiStripBadStrip::Range range(qobj->getDataVectorBegin() + rIter->ibegin,
153  qobj->getDataVectorBegin() + rIter->iend);
154  if (!obj->put(rIter->detid, range))
155  edm::LogError("SiStripQualityHotStripIdentifierRoot")
156  << "[SiStripQualityHotStripIdentifierRoot::getNewObject] detid already exists" << std::endl;
157  }
158  edm::LogInfo("SiStripQualityHotStripIdentifierRoot")
159  << " [SiStripQualityHotStripIdentifierRoot::getNewObject] " << ss.str() << std::endl;
160 
161  } else if (AlgoName == "SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy") {
162  edm::LogInfo("SiStripQualityHotStripIdentifierRoot")
163  << " [SiStripQualityHotStripIdentifierRoot::getNewObject] call to "
164  "SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy"
165  << std::endl;
166 
169  parameters.getUntrackedParameter<double>("ProbabilityThreshold", 1.E-7));
170  theIdentifier3->setMinNumEntries(parameters.getUntrackedParameter<uint32_t>("MinNumEntries", 100));
172  parameters.getUntrackedParameter<uint32_t>("MinNumEntriesPerStrip", 5));
175  conf_.getUntrackedParameter<std::string>("OccupancyRootFile", "Occupancy.root"),
176  conf_.getUntrackedParameter<bool>("WriteOccupancyRootFile", false),
177  conf_.getUntrackedParameter<std::string>("DQMHistoOutputFile", "DQMHistos.root"),
178  conf_.getUntrackedParameter<bool>("WriteDQMHistoOutputFile", false));
180  theIdentifier3->setLowOccupancyThreshold(parameters.getUntrackedParameter<double>("LowOccupancyThreshold", 5));
182  parameters.getUntrackedParameter<double>("HighOccupancyThreshold", 10));
183  theIdentifier3->setAbsoluteLowThreshold(parameters.getUntrackedParameter<double>("AbsoluteLowThreshold", 0));
184  theIdentifier3->setNumberIterations(parameters.getUntrackedParameter<uint32_t>("NumberIterations", 2));
186  parameters.getUntrackedParameter<double>("OccupancyThreshold", 1.E-5));
188 
189  const auto detInfo =
191  SiStripQuality* qobj = new SiStripQuality(detInfo);
193  qobj,
195  SiStripQuality_); //here I insert SiStripQuality as input and get qobj as output
196 
197  //----------
198 
199  edm::LogInfo("SiStripQualityHotStripIdentifierRoot")
200  << " [SiStripQualityHotStripIdentifierRoot::getNewObject] copy SiStripObject in SiStripBadStrip"
201  << std::endl;
202 
203  std::stringstream ss;
204 
205  SiStripBadStrip::RegistryIterator rIter = qobj->getRegistryVectorBegin();
206  SiStripBadStrip::RegistryIterator rIterEnd = qobj->getRegistryVectorEnd();
207  for (; rIter != rIterEnd; ++rIter) {
208  SiStripBadStrip::Range range(qobj->getDataVectorBegin() + rIter->ibegin,
209  qobj->getDataVectorBegin() + rIter->iend);
210  if (!obj->put(rIter->detid, range))
211  edm::LogError("SiStripQualityHotStripIdentifierRoot")
212  << "[SiStripQualityHotStripIdentifierRoot::getNewObject] detid already exists" << std::endl;
213  }
214  edm::LogInfo("SiStripQualityHotStripIdentifierRoot")
215  << " [SiStripQualityHotStripIdentifierRoot::getNewObject] " << ss.str() << std::endl;
216  } else {
217  edm::LogError("SiStripQualityHotStripIdentifierRoot") << " [SiStripQualityHotStripIdentifierRoot::getNewObject]"
218  " call for a unknow HotStrip identification algoritm"
219  << std::endl;
220 
221  std::vector<uint32_t> a;
222  SiStripBadStrip::Range range(a.begin(), a.end());
223  if (!obj->put(0xFFFFFFFF, range))
224  edm::LogError("SiStripQualityHotStripIdentifierRoot")
225  << "[SiStripQualityHotStripIdentifierRoot::getNewObject] detid already exists" << std::endl;
226  }
227  }
228 
229  else {
230  edm::LogWarning("SiStripQualityHotStripIdentifierRoot")
231  << " [SiStripQualityHotStripIdentifierRoot::getNewObject] :: Empty Events :: "
232  << "Mean Number of Cluster is " << MeanNumberOfCluster << " Calibration NOT launched" << std::endl;
233  setDoStore(false); // Don't put anything in the sqlite-file!
234  }
235  } else {
236  edm::LogWarning("SiStripQualityHotStripIdentifierRoot")
237  << " [SiStripQualityHotStripIdentifierRoot::getNewObject] :: Not Enough Events :: "
238  << "Total number of events is " << TotNumberOfEvents << " Calibration NOT launched" << std::endl;
239  setDoStore(false); // Don't put anything in the sqlite-file!
240  }
241 
242  return obj;
243 }
244 
246  tTopo = &iSetup.getData(tTopoToken_);
247  tracker_ = &iSetup.getData(tkGeomToken_);
248  if (UseInputDB_ && stripQualityWatcher_.check(iSetup)) {
250  }
251 }
252 
254  //Clear map
255  ClusterPositionHistoMap.clear();
256 }
257 
259  edm::LogInfo("SiStripQualityHotStripIdentifierRoot")
260  << " [SiStripQualityHotStripIdentifierRoot::bookHistos] " << dirpath << std::endl;
261  std::vector<MonitorElement*> MEs = dqmStore_->getAllContents(dirpath);
262  //"DQMData/Run 50908/SiStrip/MechanicalView");
263  // "/DQMData/Run 50908/SiStrip/Run summary/MechanicalView/TID/side_2/wheel_3/ring_2/mono_modules/module_402676874");
264  edm::LogInfo("SiStripQualityHotStripIdentifierRoot")
265  << " [SiStripQualityHotStripIdentifierRoot::bookHistos] vector size " << MEs.size() << std::endl;
266 
267  std::vector<MonitorElement*>::const_iterator iter = MEs.begin();
268  std::vector<MonitorElement*>::const_iterator iterEnd = MEs.end();
269 
271  bool gotNentries = true;
272  if (parameters.getUntrackedParameter<uint32_t>("NumberOfEvents", 0) == 0 &&
273  parameters.getUntrackedParameter<double>("OccupancyThreshold", 0) != 0)
274  gotNentries = false;
275  edm::LogInfo("SiStripQualityHotStripIdentifierRoot")
276  << "[SiStripQualityHotStripIdentifierRoot::bookHistos] gotNentries flag " << gotNentries << " number of "
277  << parameters.getUntrackedParameter<uint32_t>("NumberOfEvents", 0) << " occup "
278  << parameters.getUntrackedParameter<double>("OccupancyThreshold", 0) << " OccupancyHisto"
279  << parameters.getUntrackedParameter<std::string>("OccupancyHisto") << std::endl;
280 
281  // Check Number of Events
282  for (; iter != iterEnd; ++iter) {
283  std::string me_name = (*iter)->getName();
284 
285  if (!gotNentries && strstr(me_name.c_str(), "TotalNumberOfCluster__T") != nullptr &&
286  strstr(me_name.c_str(), "Profile") == nullptr) {
287  TotNumberOfEvents = ((TH1F*)(*iter)->getTH1F())->GetEntries();
288  MeanNumberOfCluster = ((TH1F*)(*iter)->getTH1F())->GetMean();
289  edm::LogInfo("SiStripQualityHotStripIdentifierRoot")
290  << "Total Number of Events: " << TotNumberOfEvents << std::endl;
291 
292  gotNentries = true;
293  edm::LogInfo("SiStripQualityHotStripIdentifierRoot")
294  << "[SiStripQualityHotStripIdentifierRoot::bookHistos] gotNentries flag " << gotNentries << std::endl;
295  break;
296  }
297  }
298  if (!gotNentries) {
299  edm::LogWarning("SiStripQualityHotStripIdentifierRoot")
300  << " [SiStripQualityHotStripIdentifierRoot::bookHistos] :: Histogram with to check # of events missing"
301  << std::endl;
302  }
303  for (; iter != iterEnd; ++iter) {
304  std::string me_name = (*iter)->getName();
305 
306  if (strstr(me_name.c_str(), (parameters.getUntrackedParameter<std::string>("OccupancyHisto")).c_str()) == nullptr)
307  continue;
308 
309  unsigned int detid = 0;
310  char title[128];
311  sprintf(title, "%s", me_name.c_str());
312  char* saveptr;
313  char* ptr = strtok_r(title, "__", &saveptr);
314  int c = 0;
315  while (ptr != nullptr) {
316  if (c == 2) {
317  detid = atol(ptr);
318  break;
319  }
320  ptr = strtok_r(nullptr, "_", &saveptr);
321  c++;
322  }
323  LogDebug("SiStripQualityHotStripIdentifierRoot")
324  << " [SiStripQualityHotStripIdentifierRoot::bookHistos] detid " << detid << std::endl;
325 
326  ClusterPositionHistoMap[detid] = std::make_shared<TH1F>(*(*iter)->getTH1F());
327  }
328 }
void setOutputFileName(std::string OutputFileName, bool WriteOutputFile)
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 tracker_[]
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy * theIdentifier3
void setOutputFileName(std::string OutputFileName, bool WriteOutputFile, std::string DQMOutfileName, bool WriteDQMHistograms)
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken_
void extractBadAPVSandStrips(SiStripQuality *, HistoMap &, const SiStripQuality *)
Registry::const_iterator RegistryIterator
Log< level::Error, false > LogError
T getUntrackedParameter(std::string const &, T const &) const
SiStripHotStripAlgorithmFromClusterOccupancy * theIdentifier
edm::ESGetToken< SiStripQuality, SiStripQualityRcd > stripQualityToken_
void extractBadAPVs(SiStripQuality *, HistoMap &, const SiStripQuality *)
virtual std::vector< dqm::harvesting::MonitorElement * > getAllContents(std::string const &path) const
Definition: DQMStore.cc:641
void extractBadStrips(SiStripQuality *, HistoMap &, const SiStripQuality *)
Transition
Definition: Transition.h:12
void algoBeginRun(const edm::Run &, const edm::EventSetup &) override
SiStripDetInfo read(std::string filePath)
Log< level::Info, false > LogInfo
void setOutputFileName(std::string OutputFileName, bool WriteOutputFile)
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
void setDoStore(const bool doStore)
When set to false the payload will not be written to the db.
HLT enums.
double a
Definition: hdecay.h:121
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tkGeomToken_
edm::ESWatcher< SiStripQualityRcd > stripQualityWatcher_
std::pair< ContainerIterator, ContainerIterator > Range
SiStripBadAPVAlgorithmFromClusterOccupancy * theIdentifier2
static constexpr char const *const kDefaultFile
Log< level::Warning, false > LogWarning
std::unique_ptr< SiStripBadStrip > getNewObject() override
Definition: Run.h:45
#define LogDebug(id)