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  calibrationthreshold(iConfig.getUntrackedParameter<uint32_t>("CalibrationThreshold",10000))
34 {
36 
38  dqmStore_->setVerbose(iConfig.getUntrackedParameter<uint32_t>("verbosity",0));
39 
40  if(filename!=""){
41  edm::LogInfo("SiStripQualityHotStripIdentifierRoot") << " before opening file " << filename.c_str();
42  dqmStore_->open(filename.c_str(), false);
43  edm::LogInfo("SiStripQualityHotStripIdentifierRoot") << " after opening file ";
44  }
45 }
46 
47 
49 }
50 
52 
53  edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<"SiStripQualityHotStripIdentifierRoot::getNewObject called"<<std::endl;
54 
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 << ". Calibration is launched." <<std::endl;
65 
66  if (AlgoName=="SiStripHotStripAlgorithmFromClusterOccupancy")
67  {
68 
69  edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] call to SiStripHotStripAlgorithmFromClusterOccupancy"<<std::endl;
70 
72  theIdentifier->setProbabilityThreshold(parameters.getUntrackedParameter<double>("ProbabilityThreshold",1.E-7));
73  theIdentifier->setMinNumEntries(parameters.getUntrackedParameter<uint32_t>("MinNumEntries",100));
74  theIdentifier->setMinNumEntriesPerStrip(parameters.getUntrackedParameter<uint32_t>("MinNumEntriesPerStrip",5));
75  theIdentifier->setOccupancyThreshold(parameters.getUntrackedParameter<double>("OccupancyThreshold",1.E-5));
77  theIdentifier->setOutputFileName(conf_.getUntrackedParameter<std::string>("OccupancyRootFile","Occupancy.root"),conf_.getUntrackedParameter<bool>("WriteOccupancyRootFile",false));
79 
80  SiStripQuality* qobj = new SiStripQuality();
81  theIdentifier->extractBadStrips(qobj,ClusterPositionHistoMap,SiStripQuality_);//here I insert SiStripQuality as input and get qobj as output
82 
83  //----------
84 
85  edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] copy SiStripObject in SiStripBadStrip"<<std::endl;
86 
87  std::stringstream ss;
88 
89  SiStripBadStrip::RegistryIterator rIter=qobj->getRegistryVectorBegin();
90  SiStripBadStrip::RegistryIterator rIterEnd=qobj->getRegistryVectorEnd();
91  for(;rIter!=rIterEnd;++rIter){
92  SiStripBadStrip::Range range(qobj->getDataVectorBegin()+rIter->ibegin,qobj->getDataVectorBegin()+rIter->iend);
93  if ( ! obj->put(rIter->detid,range) )
94  edm::LogError("SiStripQualityHotStripIdentifierRoot")<<"[SiStripQualityHotStripIdentifierRoot::getNewObject] detid already exists"<<std::endl;
95  }
96  edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] " << ss.str() << std::endl;
97  }
98  else if (AlgoName=="SiStripBadAPVAlgorithmFromClusterOccupancy")
99  {
100 
101  edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] call to SiStripBadAPVAlgorithmFromClusterOccupancy"<<std::endl;
102 
104  theIdentifier2->setLowOccupancyThreshold(parameters.getUntrackedParameter<double>("LowOccupancyThreshold",5));
105  theIdentifier2->setHighOccupancyThreshold(parameters.getUntrackedParameter<double>("HighOccupancyThreshold",10));
106  theIdentifier2->setAbsoluteLowThreshold(parameters.getUntrackedParameter<double>("AbsoluteLowThreshold",0));
107  theIdentifier2->setNumberIterations(parameters.getUntrackedParameter<uint32_t>("NumberIterations",2));
108  theIdentifier2->setAbsoluteOccupancyThreshold(parameters.getUntrackedParameter<double>("OccupancyThreshold",1.E-5));
111  theIdentifier2->setOutputFileName(conf_.getUntrackedParameter<std::string>("OccupancyRootFile","Occupancy.root"),conf_.getUntrackedParameter<bool>("WriteOccupancyRootFile",false));
113 
114  SiStripQuality* qobj = new SiStripQuality();
116 
117  //----------
118 
119  edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] copy SiStripObject in SiStripBadStrip"<<std::endl;
120 
121  std::stringstream ss;
122 
123  SiStripBadStrip::RegistryIterator rIter=qobj->getRegistryVectorBegin();
124  SiStripBadStrip::RegistryIterator rIterEnd=qobj->getRegistryVectorEnd();
125  for(;rIter!=rIterEnd;++rIter){
126  SiStripBadStrip::Range range(qobj->getDataVectorBegin()+rIter->ibegin,qobj->getDataVectorBegin()+rIter->iend);
127  if ( ! obj->put(rIter->detid,range) )
128  edm::LogError("SiStripQualityHotStripIdentifierRoot")<<"[SiStripQualityHotStripIdentifierRoot::getNewObject] detid already exists"<<std::endl;
129  }
130  edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] " << ss.str() << std::endl;
131 
132 
133  }
134  else if (AlgoName=="SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy")
135  {
136 
137  edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] call to SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy"<<std::endl;
138 
140  theIdentifier3->setProbabilityThreshold(parameters.getUntrackedParameter<double>("ProbabilityThreshold",1.E-7));
141  theIdentifier3->setMinNumEntries(parameters.getUntrackedParameter<uint32_t>("MinNumEntries",100));
142  theIdentifier3->setMinNumEntriesPerStrip(parameters.getUntrackedParameter<uint32_t>("MinNumEntriesPerStrip",5));
145  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));
147  theIdentifier3->setLowOccupancyThreshold(parameters.getUntrackedParameter<double>("LowOccupancyThreshold",5));
148  theIdentifier3->setHighOccupancyThreshold(parameters.getUntrackedParameter<double>("HighOccupancyThreshold",10));
149  theIdentifier3->setAbsoluteLowThreshold(parameters.getUntrackedParameter<double>("AbsoluteLowThreshold",0));
150  theIdentifier3->setNumberIterations(parameters.getUntrackedParameter<uint32_t>("NumberIterations",2));
151  theIdentifier3->setAbsoluteOccupancyThreshold(parameters.getUntrackedParameter<double>("OccupancyThreshold",1.E-5));
152 
153  SiStripQuality* qobj = new SiStripQuality();
154  theIdentifier3->extractBadAPVSandStrips(qobj,ClusterPositionHistoMap,SiStripQuality_);//here I insert SiStripQuality as input and get qobj as output
155 
156  //----------
157 
158  edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] copy SiStripObject in SiStripBadStrip"<<std::endl;
159 
160  std::stringstream ss;
161 
162  SiStripBadStrip::RegistryIterator rIter=qobj->getRegistryVectorBegin();
163  SiStripBadStrip::RegistryIterator rIterEnd=qobj->getRegistryVectorEnd();
164  for(;rIter!=rIterEnd;++rIter){
165  SiStripBadStrip::Range range(qobj->getDataVectorBegin()+rIter->ibegin,qobj->getDataVectorBegin()+rIter->iend);
166  if ( ! obj->put(rIter->detid,range) )
167  edm::LogError("SiStripQualityHotStripIdentifierRoot")<<"[SiStripQualityHotStripIdentifierRoot::getNewObject] detid already exists"<<std::endl;
168  }
169  edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] " << ss.str() << std::endl;
170  }
171  else
172  {
173  edm::LogError("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::getNewObject] call for a unknow HotStrip identification algoritm"<<std::endl;
174 
175  std::vector<uint32_t> a;
176  SiStripBadStrip::Range range(a.begin(),a.end());
177  if ( ! obj->put(0xFFFFFFFF,range) )
178  edm::LogError("SiStripQualityHotStripIdentifierRoot")<<"[SiStripQualityHotStripIdentifierRoot::getNewObject] detid already exists"<<std::endl;
179  }
180  }
181  else
182  {
183  edm::LogWarning("NotEnoughEvents") <<"Total number of events is " << TotNumberOfEvents << ", which is below the threshold (" << calibrationthreshold << "). Calibration will NOT be launched.";
184  setDoStore(false); // Don't put anything in the sqlite-file!
185  }
186 
187  return obj;
188 }
189 
191  //Retrieve tracker topology from geometry
192  edm::ESHandle<TrackerTopology> tTopoHandle;
193  iSetup.get<IdealGeometryRecord>().get(tTopoHandle);
194  tTopo = tTopoHandle.product();
195 
197  _tracker=&(* theTrackerGeom);
198 
199  if(UseInputDB_){
200  unsigned long long cacheID = iSetup.get<SiStripQualityRcd>().cacheIdentifier();
201 
202  if (m_cacheID_ == cacheID)
203  return;
204 
205  m_cacheID_ = cacheID;
206 
208  }
209 }
210 
212  //Clear map
213  ClusterPositionHistoMap.clear();
214 }
215 
216 
218  edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::bookHistos] " << dirpath << std::endl;
219  std::vector<MonitorElement*> MEs = dqmStore_->getAllContents(dirpath);
220  //"DQMData/Run 50908/SiStrip/MechanicalView");
221  // "/DQMData/Run 50908/SiStrip/Run summary/MechanicalView/TID/side_2/wheel_3/ring_2/mono_modules/module_402676874");
222  edm::LogInfo("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::bookHistos] vector size " << MEs.size()<< std::endl;
223 
224  std::vector<MonitorElement*>::const_iterator iter=MEs.begin();
225  std::vector<MonitorElement*>::const_iterator iterEnd=MEs.end();
226 
228  bool gotNentries=true;
229  if( parameters.getUntrackedParameter<uint32_t>("NumberOfEvents",0)==0 && parameters.getUntrackedParameter<double>("OccupancyThreshold",0)!=0)
230  gotNentries=false;
231  edm::LogInfo("SiStripQualityHotStripIdentifierRoot")<< "[SiStripQualityHotStripIdentifierRoot::bookHistos] gotNentries flag " << gotNentries
232  << " number of " << parameters.getUntrackedParameter<uint32_t>("NumberOfEvents",0)
233  << " occup " << parameters.getUntrackedParameter<double>("OccupancyThreshold",0)
234  << " OccupancyHisto" << parameters.getUntrackedParameter<std::string>("OccupancyHisto") << std::endl;
235 
236  for (; iter!=iterEnd;++iter) {
237  std::string me_name = (*iter)->getName();
238 
239  if (!gotNentries && strstr(me_name.c_str(),"TotalNumberOfCluster__T")!=NULL && strstr(me_name.c_str(),"Profile")==NULL ){
240 
241  TotNumberOfEvents = ((TH1F*)(*iter)->getTH1F())->GetEntries();
242  edm::LogInfo("SiStripQualityHotStripIdentifierRoot")<< "Total Number of Events: " << TotNumberOfEvents << std::endl;
243 
244  gotNentries=true;
245  edm::LogInfo("SiStripQualityHotStripIdentifierRoot")<< "[SiStripQualityHotStripIdentifierRoot::bookHistos] gotNentries flag " << gotNentries << std::endl;
246  }
247 
248  if (strstr(me_name.c_str(),(parameters.getUntrackedParameter<std::string>("OccupancyHisto")).c_str())==NULL)
249  continue;
250 
251  unsigned int detid=0;
252  char title[128];
253  sprintf(title,"%s",me_name.c_str());
254  char *ptr=strtok(title,"__");
255  int c=0;
256  while (ptr!=NULL){
257  if (c==2){
258  detid=atol(ptr);
259  break;
260  }
261  ptr=strtok(NULL,"_");
262  c++;
263  }
264  LogDebug("SiStripQualityHotStripIdentifierRoot") <<" [SiStripQualityHotStripIdentifierRoot::bookHistos] detid " << detid<< std::endl;
265 
266  ClusterPositionHistoMap[detid]=boost::shared_ptr<TH1F>(new TH1F(*(*iter)->getTH1F()));
267 
268  }
269  if(!gotNentries) edm::LogWarning("MissingNumberOfEvents") <<"Missing histogram to get the number of events";
270 
271 }
272 
#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 nullptr
#define NULL
Definition: scimark2.h:8
Registry::const_iterator RegistryIterator
std::vector< MonitorElement * > getAllContents(const std::string &path, uint32_t runNumber=0, uint32_t lumi=0) const
Definition: DQMStore.cc:1909
SiStripHotStripAlgorithmFromClusterOccupancy * theIdentifier
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
void setOutputFileName(std::string OutputFileName, bool WriteOutputFile)
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:41