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
23 
26  m_cacheID_(0),
27  dataLabel_(iConfig.getUntrackedParameter<std::string>("dataLabel", "")),
28  UseInputDB_(iConfig.getUntrackedParameter<bool>("UseInputDB", false)),
29  conf_(iConfig),
31  tTopo(nullptr),
32  filename(iConfig.getUntrackedParameter<std::string>("rootFilename", "CondDB_TKCC_20X_v3_hlt_50822.root")),
33  dirpath(iConfig.getUntrackedParameter<std::string>("rootDirPath", "")),
34  TotNumberOfEvents(0),
35  MeanNumberOfCluster(0),
36  calibrationthreshold(iConfig.getUntrackedParameter<uint32_t>("CalibrationThreshold", 10000)) {
38 
39  if (!filename.empty()) {
40  edm::LogInfo("SiStripQualityHotStripIdentifierRoot") << " before opening file " << filename.c_str();
41  dqmStore_->open(filename, false);
42  edm::LogInfo("SiStripQualityHotStripIdentifierRoot") << " after opening file ";
43  }
44 }
45 
47 
48 std::unique_ptr<SiStripBadStrip> SiStripQualityHotStripIdentifierRoot::getNewObject() {
49  edm::LogInfo("SiStripQualityHotStripIdentifierRoot")
50  << "SiStripQualityHotStripIdentifierRoot::getNewObject called" << std::endl;
51 
52  auto obj = std::make_unique<SiStripBadStrip>();
53 
55  std::string AlgoName = parameters.getParameter<std::string>("AlgoName");
56 
57  bookHistos();
58 
60  edm::LogInfo("SiStripQualityHotStripIdentifierRoot")
61  << " [SiStripQualityHotStripIdentifierRoot::getNewObject] Total number of events is " << TotNumberOfEvents
62  << " which is bigger than " << calibrationthreshold << ". Calibration is preparing to be launched."
63  << std::endl;
64  if (MeanNumberOfCluster > 0.01) {
65  edm::LogInfo("SiStripQualityHotStripIdentifierRoot")
66  << "Mean Number of Cluster is " << MeanNumberOfCluster << ". Calibration is launched." << std::endl;
67 
68  if (AlgoName == "SiStripHotStripAlgorithmFromClusterOccupancy") {
69  edm::LogInfo("SiStripQualityHotStripIdentifierRoot") << " [SiStripQualityHotStripIdentifierRoot::getNewObject] "
70  "call to SiStripHotStripAlgorithmFromClusterOccupancy"
71  << std::endl;
72 
74  theIdentifier->setProbabilityThreshold(parameters.getUntrackedParameter<double>("ProbabilityThreshold", 1.E-7));
75  theIdentifier->setMinNumEntries(parameters.getUntrackedParameter<uint32_t>("MinNumEntries", 100));
76  theIdentifier->setMinNumEntriesPerStrip(parameters.getUntrackedParameter<uint32_t>("MinNumEntriesPerStrip", 5));
77  theIdentifier->setOccupancyThreshold(parameters.getUntrackedParameter<double>("OccupancyThreshold", 1.E-5));
80  conf_.getUntrackedParameter<std::string>("OccupancyRootFile", "Occupancy.root"),
81  conf_.getUntrackedParameter<bool>("WriteOccupancyRootFile", false));
83 
84  SiStripQuality* qobj = new SiStripQuality();
86  qobj,
88  SiStripQuality_); //here I insert SiStripQuality as input and get qobj as output
89 
90  //----------
91 
92  edm::LogInfo("SiStripQualityHotStripIdentifierRoot")
93  << " [SiStripQualityHotStripIdentifierRoot::getNewObject] copy SiStripObject in SiStripBadStrip"
94  << std::endl;
95 
96  std::stringstream ss;
97 
100  for (; rIter != rIterEnd; ++rIter) {
101  SiStripBadStrip::Range range(qobj->getDataVectorBegin() + rIter->ibegin,
102  qobj->getDataVectorBegin() + rIter->iend);
103  if (!obj->put(rIter->detid, range))
104  edm::LogError("SiStripQualityHotStripIdentifierRoot")
105  << "[SiStripQualityHotStripIdentifierRoot::getNewObject] detid already exists" << std::endl;
106  }
107  edm::LogInfo("SiStripQualityHotStripIdentifierRoot")
108  << " [SiStripQualityHotStripIdentifierRoot::getNewObject] " << ss.str() << std::endl;
109  } else if (AlgoName == "SiStripBadAPVAlgorithmFromClusterOccupancy") {
110  edm::LogInfo("SiStripQualityHotStripIdentifierRoot") << " [SiStripQualityHotStripIdentifierRoot::getNewObject] "
111  "call to SiStripBadAPVAlgorithmFromClusterOccupancy"
112  << std::endl;
113 
115  theIdentifier2->setLowOccupancyThreshold(parameters.getUntrackedParameter<double>("LowOccupancyThreshold", 5));
117  parameters.getUntrackedParameter<double>("HighOccupancyThreshold", 10));
118  theIdentifier2->setAbsoluteLowThreshold(parameters.getUntrackedParameter<double>("AbsoluteLowThreshold", 0));
119  theIdentifier2->setNumberIterations(parameters.getUntrackedParameter<uint32_t>("NumberIterations", 2));
121  parameters.getUntrackedParameter<double>("OccupancyThreshold", 1.E-5));
125  conf_.getUntrackedParameter<std::string>("OccupancyRootFile", "Occupancy.root"),
126  conf_.getUntrackedParameter<bool>("WriteOccupancyRootFile", false));
128 
129  SiStripQuality* qobj = new SiStripQuality();
131 
132  //----------
133 
134  edm::LogInfo("SiStripQualityHotStripIdentifierRoot")
135  << " [SiStripQualityHotStripIdentifierRoot::getNewObject] copy SiStripObject in SiStripBadStrip"
136  << std::endl;
137 
138  std::stringstream ss;
139 
142  for (; rIter != rIterEnd; ++rIter) {
143  SiStripBadStrip::Range range(qobj->getDataVectorBegin() + rIter->ibegin,
144  qobj->getDataVectorBegin() + rIter->iend);
145  if (!obj->put(rIter->detid, range))
146  edm::LogError("SiStripQualityHotStripIdentifierRoot")
147  << "[SiStripQualityHotStripIdentifierRoot::getNewObject] detid already exists" << std::endl;
148  }
149  edm::LogInfo("SiStripQualityHotStripIdentifierRoot")
150  << " [SiStripQualityHotStripIdentifierRoot::getNewObject] " << ss.str() << std::endl;
151 
152  } else if (AlgoName == "SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy") {
153  edm::LogInfo("SiStripQualityHotStripIdentifierRoot")
154  << " [SiStripQualityHotStripIdentifierRoot::getNewObject] call to "
155  "SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy"
156  << std::endl;
157 
160  parameters.getUntrackedParameter<double>("ProbabilityThreshold", 1.E-7));
161  theIdentifier3->setMinNumEntries(parameters.getUntrackedParameter<uint32_t>("MinNumEntries", 100));
163  parameters.getUntrackedParameter<uint32_t>("MinNumEntriesPerStrip", 5));
166  conf_.getUntrackedParameter<std::string>("OccupancyRootFile", "Occupancy.root"),
167  conf_.getUntrackedParameter<bool>("WriteOccupancyRootFile", false),
168  conf_.getUntrackedParameter<std::string>("DQMHistoOutputFile", "DQMHistos.root"),
169  conf_.getUntrackedParameter<bool>("WriteDQMHistoOutputFile", false));
171  theIdentifier3->setLowOccupancyThreshold(parameters.getUntrackedParameter<double>("LowOccupancyThreshold", 5));
173  parameters.getUntrackedParameter<double>("HighOccupancyThreshold", 10));
174  theIdentifier3->setAbsoluteLowThreshold(parameters.getUntrackedParameter<double>("AbsoluteLowThreshold", 0));
175  theIdentifier3->setNumberIterations(parameters.getUntrackedParameter<uint32_t>("NumberIterations", 2));
177  parameters.getUntrackedParameter<double>("OccupancyThreshold", 1.E-5));
179 
180  SiStripQuality* qobj = new SiStripQuality();
182  qobj,
184  SiStripQuality_); //here I insert SiStripQuality as input and get qobj as output
185 
186  //----------
187 
188  edm::LogInfo("SiStripQualityHotStripIdentifierRoot")
189  << " [SiStripQualityHotStripIdentifierRoot::getNewObject] copy SiStripObject in SiStripBadStrip"
190  << std::endl;
191 
192  std::stringstream ss;
193 
196  for (; rIter != rIterEnd; ++rIter) {
197  SiStripBadStrip::Range range(qobj->getDataVectorBegin() + rIter->ibegin,
198  qobj->getDataVectorBegin() + rIter->iend);
199  if (!obj->put(rIter->detid, range))
200  edm::LogError("SiStripQualityHotStripIdentifierRoot")
201  << "[SiStripQualityHotStripIdentifierRoot::getNewObject] detid already exists" << std::endl;
202  }
203  edm::LogInfo("SiStripQualityHotStripIdentifierRoot")
204  << " [SiStripQualityHotStripIdentifierRoot::getNewObject] " << ss.str() << std::endl;
205  } else {
206  edm::LogError("SiStripQualityHotStripIdentifierRoot") << " [SiStripQualityHotStripIdentifierRoot::getNewObject]"
207  " call for a unknow HotStrip identification algoritm"
208  << std::endl;
209 
210  std::vector<uint32_t> a;
211  SiStripBadStrip::Range range(a.begin(), a.end());
212  if (!obj->put(0xFFFFFFFF, range))
213  edm::LogError("SiStripQualityHotStripIdentifierRoot")
214  << "[SiStripQualityHotStripIdentifierRoot::getNewObject] detid already exists" << std::endl;
215  }
216  }
217 
218  else {
219  edm::LogWarning("SiStripQualityHotStripIdentifierRoot")
220  << " [SiStripQualityHotStripIdentifierRoot::getNewObject] :: Empty Events :: "
221  << "Mean Number of Cluster is " << MeanNumberOfCluster << " Calibration NOT launched" << std::endl;
222  setDoStore(false); // Don't put anything in the sqlite-file!
223  }
224  } else {
225  edm::LogWarning("SiStripQualityHotStripIdentifierRoot")
226  << " [SiStripQualityHotStripIdentifierRoot::getNewObject] :: Not Enough Events :: "
227  << "Total number of events is " << TotNumberOfEvents << " Calibration NOT launched" << std::endl;
228  setDoStore(false); // Don't put anything in the sqlite-file!
229  }
230 
231  return obj;
232 }
233 
235  //Retrieve tracker topology from geometry
236  edm::ESHandle<TrackerTopology> tTopoHandle;
237  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
238  tTopo = tTopoHandle.product();
239 
241  tracker_ = &(*theTrackerGeom);
242 
243  if (UseInputDB_) {
244  unsigned long long cacheID = iSetup.get<SiStripQualityRcd>().cacheIdentifier();
245 
246  if (m_cacheID_ == cacheID)
247  return;
248 
249  m_cacheID_ = cacheID;
250 
252  }
253 }
254 
256  //Clear map
257  ClusterPositionHistoMap.clear();
258 }
259 
261  edm::LogInfo("SiStripQualityHotStripIdentifierRoot")
262  << " [SiStripQualityHotStripIdentifierRoot::bookHistos] " << dirpath << std::endl;
263  std::vector<MonitorElement*> MEs = dqmStore_->getAllContents(dirpath);
264  //"DQMData/Run 50908/SiStrip/MechanicalView");
265  // "/DQMData/Run 50908/SiStrip/Run summary/MechanicalView/TID/side_2/wheel_3/ring_2/mono_modules/module_402676874");
266  edm::LogInfo("SiStripQualityHotStripIdentifierRoot")
267  << " [SiStripQualityHotStripIdentifierRoot::bookHistos] vector size " << MEs.size() << std::endl;
268 
269  std::vector<MonitorElement*>::const_iterator iter = MEs.begin();
270  std::vector<MonitorElement*>::const_iterator iterEnd = MEs.end();
271 
273  bool gotNentries = true;
274  if (parameters.getUntrackedParameter<uint32_t>("NumberOfEvents", 0) == 0 &&
275  parameters.getUntrackedParameter<double>("OccupancyThreshold", 0) != 0)
276  gotNentries = false;
277  edm::LogInfo("SiStripQualityHotStripIdentifierRoot")
278  << "[SiStripQualityHotStripIdentifierRoot::bookHistos] gotNentries flag " << gotNentries << " number of "
279  << parameters.getUntrackedParameter<uint32_t>("NumberOfEvents", 0) << " occup "
280  << parameters.getUntrackedParameter<double>("OccupancyThreshold", 0) << " OccupancyHisto"
281  << parameters.getUntrackedParameter<std::string>("OccupancyHisto") << std::endl;
282 
283  // Check Number of Events
284  for (; iter != iterEnd; ++iter) {
285  std::string me_name = (*iter)->getName();
286 
287  if (!gotNentries && strstr(me_name.c_str(), "TotalNumberOfCluster__T") != nullptr &&
288  strstr(me_name.c_str(), "Profile") == nullptr) {
289  TotNumberOfEvents = ((TH1F*)(*iter)->getTH1F())->GetEntries();
290  MeanNumberOfCluster = ((TH1F*)(*iter)->getTH1F())->GetMean();
291  edm::LogInfo("SiStripQualityHotStripIdentifierRoot")
292  << "Total Number of Events: " << TotNumberOfEvents << std::endl;
293 
294  gotNentries = true;
295  edm::LogInfo("SiStripQualityHotStripIdentifierRoot")
296  << "[SiStripQualityHotStripIdentifierRoot::bookHistos] gotNentries flag " << gotNentries << std::endl;
297  break;
298  }
299  }
300  if (!gotNentries) {
301  edm::LogWarning("SiStripQualityHotStripIdentifierRoot")
302  << " [SiStripQualityHotStripIdentifierRoot::bookHistos] :: Histogram with to check # of evemnts missing"
303  << std::endl;
304  }
305  for (; iter != iterEnd; ++iter) {
306  std::string me_name = (*iter)->getName();
307 
308  if (strstr(me_name.c_str(), (parameters.getUntrackedParameter<std::string>("OccupancyHisto")).c_str()) == nullptr)
309  continue;
310 
311  unsigned int detid = 0;
312  char title[128];
313  sprintf(title, "%s", me_name.c_str());
314  char* saveptr;
315  char* ptr = strtok_r(title, "__", &saveptr);
316  int c = 0;
317  while (ptr != nullptr) {
318  if (c == 2) {
319  detid = atol(ptr);
320  break;
321  }
322  ptr = strtok_r(nullptr, "_", &saveptr);
323  c++;
324  }
325  LogDebug("SiStripQualityHotStripIdentifierRoot")
326  << " [SiStripQualityHotStripIdentifierRoot::bookHistos] detid " << detid << std::endl;
327 
328  ClusterPositionHistoMap[detid] = std::make_shared<TH1F>(*(*iter)->getTH1F());
329  }
330 }
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
void setOutputFileName(std::string OutputFileName, bool WriteOutputFile)
static const char tracker_[]
void extractBadStrips(SiStripQuality *, HistoMap &, edm::ESHandle< SiStripQuality > &)
SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy * theIdentifier3
void setOutputFileName(std::string OutputFileName, bool WriteOutputFile, std::string DQMOutfileName, bool WriteDQMHistograms)
#define nullptr
Registry::const_iterator RegistryIterator
RegistryIterator getRegistryVectorEnd() const
SiStripHotStripAlgorithmFromClusterOccupancy * theIdentifier
void algoBeginRun(const edm::Run &, const edm::EventSetup &) override
std::vector< MonitorElement * > getAllContents(std::string const &path, uint32_t runNumber=0, uint32_t lumi=0) const
Definition: DQMStore.cc:1616
ContainerIterator getDataVectorBegin() const
void setOutputFileName(std::string OutputFileName, bool WriteOutputFile)
RegistryIterator getRegistryVectorBegin() const
void setDoStore(const bool doStore)
When set to false the payload will not be written to the db.
double a
Definition: hdecay.h:119
std::pair< ContainerIterator, ContainerIterator > Range
T get() const
Definition: EventSetup.h:73
void extractBadAPVs(SiStripQuality *, HistoMap &, edm::ESHandle< SiStripQuality > &)
SiStripBadAPVAlgorithmFromClusterOccupancy * theIdentifier2
bool open(std::string const &filename, bool overwrite=false, std::string const &path="", std::string const &prepend="", OpenRunDirs stripdirs=KeepRunDirs, bool fileMustExist=true)
Definition: DQMStore.cc:2626
void extractBadAPVSandStrips(SiStripQuality *, HistoMap &, edm::ESHandle< SiStripQuality > &)
T const * product() const
Definition: ESHandle.h:86
std::unique_ptr< SiStripBadStrip > getNewObject() override
Definition: Run.h:45