CMS 3D CMS Logo

SiStripQualityHotStripIdentifierRoot.cc
Go to the documentation of this file.
2 
4 
11 
12 #include <iostream>
13 #include <fstream>
14 #include <sstream>
15 
16 #include "TH1F.h"
17 
18 //Insert here the include to the algos
22 
23 
25  m_cacheID_(0),
26  dataLabel_(iConfig.getUntrackedParameter<std::string>("dataLabel","")),
27  UseInputDB_(iConfig.getUntrackedParameter<bool>("UseInputDB",false)),
28  conf_(iConfig),
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 {
38  dqmStore_->setVerbose(iConfig.getUntrackedParameter<uint32_t>("verbosity",0));
39 
40  if(!filename.empty()){
41  edm::LogInfo("SiStripQualityHotStripIdentifierRoot") << " before opening file " << filename.c_str();
42  dqmStore_->open(filename, false);
43  edm::LogInfo("SiStripQualityHotStripIdentifierRoot") << " after opening file ";
44  }
45 }
46 
47 
49 }
50 
51 std::unique_ptr<SiStripBadStrip> SiStripQualityHotStripIdentifierRoot::getNewObject(){
52 
53  edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<"SiStripQualityHotStripIdentifierRoot::getNewObject called"<<std::endl;
54 
55  auto obj = std::make_unique<SiStripBadStrip>();
56 
58  std::string AlgoName = parameters.getParameter<std::string>("AlgoName");
59 
60  bookHistos();
61 
63  {
64  edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] Total number of events is " << TotNumberOfEvents << " which is bigger than "<<calibrationthreshold<<". Calibration is preparing to be launched." <<std::endl;
65  if (MeanNumberOfCluster > 0.01)
66  {
67  edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<"Mean Number of Cluster is "<<MeanNumberOfCluster<<". Calibration is launched." <<std::endl;
68 
69  if (AlgoName=="SiStripHotStripAlgorithmFromClusterOccupancy")
70  {
71 
72  edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] call to SiStripHotStripAlgorithmFromClusterOccupancy"<<std::endl;
73 
75  theIdentifier->setProbabilityThreshold(parameters.getUntrackedParameter<double>("ProbabilityThreshold",1.E-7));
76  theIdentifier->setMinNumEntries(parameters.getUntrackedParameter<uint32_t>("MinNumEntries",100));
77  theIdentifier->setMinNumEntriesPerStrip(parameters.getUntrackedParameter<uint32_t>("MinNumEntriesPerStrip",5));
78  theIdentifier->setOccupancyThreshold(parameters.getUntrackedParameter<double>("OccupancyThreshold",1.E-5));
80  theIdentifier->setOutputFileName(conf_.getUntrackedParameter<std::string>("OccupancyRootFile","Occupancy.root"),conf_.getUntrackedParameter<bool>("WriteOccupancyRootFile",false));
82 
83  SiStripQuality* qobj = new SiStripQuality();
84  theIdentifier->extractBadStrips(qobj,ClusterPositionHistoMap,SiStripQuality_);//here I insert SiStripQuality as input and get qobj as output
85 
86  //----------
87 
88  edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] copy SiStripObject in SiStripBadStrip"<<std::endl;
89 
90  std::stringstream ss;
91 
94  for(;rIter!=rIterEnd;++rIter){
95  SiStripBadStrip::Range range(qobj->getDataVectorBegin()+rIter->ibegin,qobj->getDataVectorBegin()+rIter->iend);
96  if ( ! obj->put(rIter->detid,range) )
97  edm::LogError("SiStripQualityHotStripIdentifierRoot")<<"[SiStripQualityHotStripIdentifierRoot::getNewObject] detid already exists"<<std::endl;
98  }
99  edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] " << ss.str() << std::endl;
100  }
101  else if (AlgoName=="SiStripBadAPVAlgorithmFromClusterOccupancy")
102  {
103 
104  edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] call to SiStripBadAPVAlgorithmFromClusterOccupancy"<<std::endl;
105 
107  theIdentifier2->setLowOccupancyThreshold(parameters.getUntrackedParameter<double>("LowOccupancyThreshold",5));
108  theIdentifier2->setHighOccupancyThreshold(parameters.getUntrackedParameter<double>("HighOccupancyThreshold",10));
109  theIdentifier2->setAbsoluteLowThreshold(parameters.getUntrackedParameter<double>("AbsoluteLowThreshold",0));
110  theIdentifier2->setNumberIterations(parameters.getUntrackedParameter<uint32_t>("NumberIterations",2));
111  theIdentifier2->setAbsoluteOccupancyThreshold(parameters.getUntrackedParameter<double>("OccupancyThreshold",1.E-5));
114  theIdentifier2->setOutputFileName(conf_.getUntrackedParameter<std::string>("OccupancyRootFile","Occupancy.root"),conf_.getUntrackedParameter<bool>("WriteOccupancyRootFile",false));
116 
117  SiStripQuality* qobj = new SiStripQuality();
119 
120  //----------
121 
122  edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] copy SiStripObject in SiStripBadStrip"<<std::endl;
123 
124  std::stringstream ss;
125 
128  for(;rIter!=rIterEnd;++rIter){
129  SiStripBadStrip::Range range(qobj->getDataVectorBegin()+rIter->ibegin,qobj->getDataVectorBegin()+rIter->iend);
130  if ( ! obj->put(rIter->detid,range) )
131  edm::LogError("SiStripQualityHotStripIdentifierRoot")<<"[SiStripQualityHotStripIdentifierRoot::getNewObject] detid already exists"<<std::endl;
132  }
133  edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] " << ss.str() << std::endl;
134 
135 
136  }
137  else if (AlgoName=="SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy")
138  {
139 
140  edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] call to SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy"<<std::endl;
141 
143  theIdentifier3->setProbabilityThreshold(parameters.getUntrackedParameter<double>("ProbabilityThreshold",1.E-7));
144  theIdentifier3->setMinNumEntries(parameters.getUntrackedParameter<uint32_t>("MinNumEntries",100));
145  theIdentifier3->setMinNumEntriesPerStrip(parameters.getUntrackedParameter<uint32_t>("MinNumEntriesPerStrip",5));
147  theIdentifier3->setOutputFileName(conf_.getUntrackedParameter<std::string>("OccupancyRootFile","Occupancy.root"),conf_.getUntrackedParameter<bool>("WriteOccupancyRootFile",false),conf_.getUntrackedParameter<std::string>("DQMHistoOutputFile","DQMHistos.root"),conf_.getUntrackedParameter<bool>("WriteDQMHistoOutputFile",false));
149  theIdentifier3->setLowOccupancyThreshold(parameters.getUntrackedParameter<double>("LowOccupancyThreshold",5));
150  theIdentifier3->setHighOccupancyThreshold(parameters.getUntrackedParameter<double>("HighOccupancyThreshold",10));
151  theIdentifier3->setAbsoluteLowThreshold(parameters.getUntrackedParameter<double>("AbsoluteLowThreshold",0));
152  theIdentifier3->setNumberIterations(parameters.getUntrackedParameter<uint32_t>("NumberIterations",2));
153  theIdentifier3->setAbsoluteOccupancyThreshold(parameters.getUntrackedParameter<double>("OccupancyThreshold",1.E-5));
155 
156  SiStripQuality* qobj = new SiStripQuality();
157  theIdentifier3->extractBadAPVSandStrips(qobj,ClusterPositionHistoMap,SiStripQuality_);//here I insert SiStripQuality as input and get qobj as output
158 
159  //----------
160 
161  edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] copy SiStripObject in SiStripBadStrip"<<std::endl;
162 
163  std::stringstream ss;
164 
167  for(;rIter!=rIterEnd;++rIter){
168  SiStripBadStrip::Range range(qobj->getDataVectorBegin()+rIter->ibegin,qobj->getDataVectorBegin()+rIter->iend);
169  if ( ! obj->put(rIter->detid,range) )
170  edm::LogError("SiStripQualityHotStripIdentifierRoot")<<"[SiStripQualityHotStripIdentifierRoot::getNewObject] detid already exists"<<std::endl;
171  }
172  edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] " << ss.str() << std::endl;
173  }
174  else
175  {
176  edm::LogError("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] call for a unknow HotStrip identification algoritm"<<std::endl;
177 
178  std::vector<uint32_t> a;
179  SiStripBadStrip::Range range(a.begin(),a.end());
180  if ( ! obj->put(0xFFFFFFFF,range) )
181  edm::LogError("SiStripQualityHotStripIdentifierRoot")<<"[SiStripQualityHotStripIdentifierRoot::getNewObject] detid already exists"<<std::endl;
182  }
183  }
184 
185  else
186  {
187  edm::LogWarning("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] :: Empty Events :: " <<"Mean Number of Cluster is " << MeanNumberOfCluster << " Calibration NOT launched" << std::endl;
188  setDoStore(false); // Don't put anything in the sqlite-file!
189  }
190  }
191  else
192  {
193  edm::LogWarning("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] :: Not Enough Events :: " <<"Total number of events is " << TotNumberOfEvents << " Calibration NOT launched" << std::endl;
194  setDoStore(false); // Don't put anything in the sqlite-file!
195  }
196 
197  return obj;
198 }
199 
201  //Retrieve tracker topology from geometry
202  edm::ESHandle<TrackerTopology> tTopoHandle;
203  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
204  tTopo = tTopoHandle.product();
205 
207  tracker_=&(* theTrackerGeom);
208 
209  if(UseInputDB_){
210  unsigned long long cacheID = iSetup.get<SiStripQualityRcd>().cacheIdentifier();
211 
212  if (m_cacheID_ == cacheID)
213  return;
214 
215  m_cacheID_ = cacheID;
216 
218  }
219 }
220 
222  //Clear map
223  ClusterPositionHistoMap.clear();
224 }
225 
226 
228  edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::bookHistos] " << dirpath << std::endl;
229  std::vector<MonitorElement*> MEs = dqmStore_->getAllContents(dirpath);
230  //"DQMData/Run 50908/SiStrip/MechanicalView");
231  // "/DQMData/Run 50908/SiStrip/Run summary/MechanicalView/TID/side_2/wheel_3/ring_2/mono_modules/module_402676874");
232  edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::bookHistos] vector size " << MEs.size()<< std::endl;
233 
234  std::vector<MonitorElement*>::const_iterator iter=MEs.begin();
235  std::vector<MonitorElement*>::const_iterator iterEnd=MEs.end();
236 
238  bool gotNentries=true;
239  if( parameters.getUntrackedParameter<uint32_t>("NumberOfEvents",0)==0 && parameters.getUntrackedParameter<double>("OccupancyThreshold",0)!=0)
240  gotNentries=false;
241  edm::LogInfo("SiStripQualityHotStripIdentifierRoot")<< "[SiStripQualityHotStripIdentifierRoot::bookHistos] gotNentries flag " << gotNentries
242  << " number of " << parameters.getUntrackedParameter<uint32_t>("NumberOfEvents",0)
243  << " occup " << parameters.getUntrackedParameter<double>("OccupancyThreshold",0)
244  << " OccupancyHisto" << parameters.getUntrackedParameter<std::string>("OccupancyHisto") << std::endl;
245 
246  // Check Number of Events
247  for (; iter!=iterEnd;++iter) {
248  std::string me_name = (*iter)->getName();
249 
250  if (!gotNentries && strstr(me_name.c_str(),"TotalNumberOfCluster__T")!=nullptr && strstr(me_name.c_str(),"Profile")==nullptr ){
251 
252  TotNumberOfEvents = ((TH1F*)(*iter)->getTH1F())->GetEntries();
253  MeanNumberOfCluster = ((TH1F*)(*iter)->getTH1F())->GetMean();
254  edm::LogInfo("SiStripQualityHotStripIdentifierRoot")<< "Total Number of Events: " << TotNumberOfEvents << std::endl;
255 
256  gotNentries=true;
257  edm::LogInfo("SiStripQualityHotStripIdentifierRoot")<< "[SiStripQualityHotStripIdentifierRoot::bookHistos] gotNentries flag " << gotNentries << std::endl;
258  break;
259  }
260  }
261  if (!gotNentries) {
262  edm::LogWarning("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::bookHistos] :: Histogram with to check # of evemnts missing" <<std::endl;
263  }
264  for (; iter!=iterEnd;++iter) {
265  std::string me_name = (*iter)->getName();
266 
267  if (strstr(me_name.c_str(),(parameters.getUntrackedParameter<std::string>("OccupancyHisto")).c_str())==nullptr)
268  continue;
269 
270  unsigned int detid=0;
271  char title[128];
272  sprintf(title,"%s",me_name.c_str());
273  char *ptr=strtok(title,"__");
274  int c=0;
275  while (ptr!=nullptr){
276  if (c==2){
277  detid=atol(ptr);
278  break;
279  }
280  ptr=strtok(nullptr,"_");
281  c++;
282  }
283  LogDebug("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::bookHistos] detid " << detid<< std::endl;
284 
285  ClusterPositionHistoMap[detid]=boost::shared_ptr<TH1F>(new TH1F(*(*iter)->getTH1F()));
286 
287  }
288 
289 }
290 
#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)
Registry::const_iterator RegistryIterator
#define nullptr
RegistryIterator getRegistryVectorEnd() const
SiStripHotStripAlgorithmFromClusterOccupancy * theIdentifier
void algoBeginRun(const edm::Run &, const edm::EventSetup &) override
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:2861
void setVerbose(unsigned level)
Definition: DQMStore.cc:525
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:121
std::pair< ContainerIterator, ContainerIterator > Range
T get() const
Definition: EventSetup.h:68
void extractBadAPVs(SiStripQuality *, HistoMap &, edm::ESHandle< SiStripQuality > &)
SiStripBadAPVAlgorithmFromClusterOccupancy * theIdentifier2
void extractBadAPVSandStrips(SiStripQuality *, HistoMap &, edm::ESHandle< SiStripQuality > &)
T const * product() const
Definition: ESHandle.h:84
std::vector< MonitorElement * > getAllContents(std::string const &path, uint32_t runNumber=0, uint32_t lumi=0) const
Definition: DQMStore.cc:1755
std::unique_ptr< SiStripBadStrip > getNewObject() override
Definition: Run.h:44