CMS 3D CMS Logo

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