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