CMS 3D CMS Logo

SiStripQualityHotStripIdentifier.cc
Go to the documentation of this file.
1 // system includes
2 #include <fstream>
3 #include <iostream>
4 #include <memory>
5 #include <sstream>
6 #include <vector>
7 
8 // user includes
29 
30 class TrackerTopology;
31 
32 class SiStripQualityHotStripIdentifier : public ConditionDBWriter<SiStripBadStrip> {
33 public:
35  ~SiStripQualityHotStripIdentifier() override = default;
36 
37 private:
38  //Will be called at the beginning of the job
39  void algoBeginJob(const edm::EventSetup&) override {}
40  //Will be called at the beginning of each run in the job
41  void algoBeginRun(const edm::Run&, const edm::EventSetup&) override;
42  //Will be called at the beginning of each luminosity block in the run
44  //Will be called at the end of the job
45  void algoEndJob() override;
46 
47  //Will be called at every event
48  void algoAnalyze(const edm::Event&, const edm::EventSetup&) override;
49 
50  std::unique_ptr<SiStripBadStrip> getNewObject() override;
51 
52  void bookHistos();
53  void resetHistos();
54  void fillHisto(uint32_t detid, float value);
55 
56 private:
58  const SiStripQuality* stripQuality_ = nullptr;
64  const TrackerTopology* tTopo = nullptr;
65 
67 
69 
73 };
74 
77  dataLabel_(iConfig.getUntrackedParameter<std::string>("dataLabel", "")),
78  conf_(iConfig),
79  fp_(iConfig.getUntrackedParameter<edm::FileInPath>("file",
81  Cluster_src_(iConfig.getParameter<edm::InputTag>("Cluster_src")),
82  Track_src_(iConfig.getUntrackedParameter<edm::InputTag>("Track_src")),
83  tracksCollection_in_EventTree(iConfig.getUntrackedParameter<bool>("RemoveTrackClusters", false)),
84  tTopoToken_(esConsumes<edm::Transition::BeginRun>()),
85  stripQualityToken_(esConsumes<edm::Transition::BeginRun>()) {
87  MinClusterWidth_ = pset.getUntrackedParameter<uint32_t>("minWidth", 1);
88  MaxClusterWidth_ = pset.getUntrackedParameter<uint32_t>("maxWidth", 1000);
89 
90  bookHistos();
91 }
92 
93 std::unique_ptr<SiStripBadStrip> SiStripQualityHotStripIdentifier::getNewObject() {
94  auto obj = std::make_unique<SiStripBadStrip>();
95 
97  std::string AlgoName = parameters.getParameter<std::string>("AlgoName");
98  if (AlgoName == "SiStripHotStripAlgorithmFromClusterOccupancy") {
99  edm::LogInfo("SiStripQualityHotStripIdentifier")
100  << " [SiStripQualityHotStripIdentifier::getNewObject] call to SiStripHotStripAlgorithmFromClusterOccupancy"
101  << std::endl;
102 
104  theIdentifier.setProbabilityThreshold(parameters.getUntrackedParameter<double>("ProbabilityThreshold", 1.E-7));
105  theIdentifier.setMinNumEntries(parameters.getUntrackedParameter<uint32_t>("MinNumEntries", 100));
106  theIdentifier.setMinNumEntriesPerStrip(parameters.getUntrackedParameter<uint32_t>("MinNumEntriesPerStrip", 5));
107 
108  const auto detInfo =
110  SiStripQuality* qobj = new SiStripQuality(detInfo);
112 
113  edm::LogInfo("SiStripQualityHotStripIdentifier")
114  << " [SiStripQualityHotStripIdentifier::getNewObject] copy SiStripObject in SiStripBadStrip" << std::endl;
115 
116  std::stringstream ss;
117 
118  SiStripBadStrip::RegistryIterator rIter = qobj->getRegistryVectorBegin();
119  SiStripBadStrip::RegistryIterator rIterEnd = qobj->getRegistryVectorEnd();
120  for (; rIter != rIterEnd; ++rIter) {
121  SiStripBadStrip::Range range(qobj->getDataVectorBegin() + rIter->ibegin,
122  qobj->getDataVectorBegin() + rIter->iend);
123  if (!obj->put(rIter->detid, range))
124  edm::LogError("SiStripQualityHotStripIdentifier")
125  << "[SiStripQualityHotStripIdentifier::getNewObject] detid already exists" << std::endl;
126  }
127  edm::LogInfo("SiStripQualityHotStripIdentifier")
128  << " [SiStripQualityHotStripIdentifier::getNewObject] " << ss.str() << std::endl;
129 
130  } else {
131  edm::LogError("SiStripQualityHotStripIdentifier")
132  << " [SiStripQualityHotStripIdentifier::getNewObject] call for a unknow HotStrip identification algoritm"
133  << std::endl;
134 
135  std::vector<uint32_t> a;
136  SiStripBadStrip::Range range(a.begin(), a.end());
137  if (!obj->put(0xFFFFFFFF, range))
138  edm::LogError("SiStripQualityHotStripIdentifier")
139  << "[SiStripQualityHotStripIdentifier::getNewObject] detid already exists" << std::endl;
140  }
141 
142  return obj;
143 }
144 
146  tTopo = &iSetup.getData(tTopoToken_);
147 
148  resetHistos();
149 
150  if (stripQualityWatcher_.check(iSetup)) {
152  }
153 }
154 
156  //Clear map
157  ClusterPositionHistoMap.clear();
158 }
159 
161  edm::LogInfo("SiStripQualityHotStripIdentifier") << " [SiStripQualityHotStripIdentifier::resetHistos] " << std::endl;
162  for (const auto& it : ClusterPositionHistoMap) {
163  it.second->Reset();
164  }
165 }
166 
168  edm::LogInfo("SiStripQualityHotStripIdentifier") << " [SiStripQualityHotStripIdentifier::bookHistos] " << std::endl;
169  char hname[1024];
171  for (const auto& it : info.getAllData()) {
172  sprintf(hname, "h_%d", it.first);
173  auto ref = ClusterPositionHistoMap.find(it.first);
174  if (ref == ClusterPositionHistoMap.end()) {
175  ClusterPositionHistoMap[it.first] =
176  std::make_shared<TH1F>(hname, hname, it.second.nApvs * 128, -0.5, it.second.nApvs * 128 - 0.5);
177  } else
178  edm::LogError("SiStripQualityHotStripIdentifier")
179  << " [SiStripQualityHotStripIdentifier::bookHistos] DetId " << it.first
180  << " already found in map. Ignoring new data" << std::endl;
181  }
182 }
183 
185  auto ref = ClusterPositionHistoMap.find(detid);
186  if (ref != ClusterPositionHistoMap.end())
187  ref->second->Fill(value);
188  else
189  edm::LogError("SiStripQualityHotStripIdentifier")
190  << " [SiStripQualityHotStripIdentifier::fillHisto] Histogram not found in the list for DetId " << detid
191  << " Ignoring data value " << value << std::endl;
192 }
193 
196  e.getByLabel(Cluster_src_, dsv_SiStripCluster);
197 
200  e.getByLabel(Track_src_, trackCollection);
201  if (!trackCollection.isValid()) {
202  edm::LogError("SiStripQualityHotStripIdentifier")
203  << " [SiStripQualityHotStripIdentifier::algoAnalyze] missing trackCollection with label " << Track_src_
204  << std::endl;
205  }
206  }
207 
208  std::set<const void*> vPSiStripCluster;
209  //Perform track study
211  int i = 0;
212  for (const auto& track : *(trackCollection.product())) {
213  LogTrace("SiStripQualityHotStripIdentifier")
214  << "Track number " << i + 1 << "\n\tmomentum: " << track.momentum() << "\n\tPT: " << track.pt()
215  << "\n\tvertex: " << track.vertex() << "\n\timpact parameter: " << track.d0()
216  << "\n\tcharge: " << track.charge() << "\n\tnormalizedChi2: " << track.normalizedChi2() << "\n\tFrom EXTRA : "
217  << "\n\t\touter PT " << track.outerPt() << std::endl;
218 
219  //Loop on rechits
220  for (auto const& recHit : track.recHits()) {
221  if (!recHit->isValid()) {
222  LogTrace("SiStripQualityHotStripIdentifier") << "\t\t Invalid Hit " << std::endl;
223  continue;
224  }
225 
226  const SiStripRecHit2D* singleHit = dynamic_cast<const SiStripRecHit2D*>(recHit);
227  const SiStripMatchedRecHit2D* matchedHit = dynamic_cast<const SiStripMatchedRecHit2D*>(recHit);
228  const ProjectedSiStripRecHit2D* projectedHit = dynamic_cast<const ProjectedSiStripRecHit2D*>(recHit);
229 
230  if (matchedHit) {
231  vPSiStripCluster.insert((void*)&(matchedHit->monoCluster()));
232  vPSiStripCluster.insert((void*)&(matchedHit->stereoCluster()));
233  } else if (projectedHit) {
234  vPSiStripCluster.insert((void*)&*(projectedHit->originalHit().cluster()));
235  } else if (singleHit) {
236  vPSiStripCluster.insert((void*)&*(singleHit->cluster()));
237  } else {
238  LogTrace("SiStripQualityHotStripIdentifier") << "NULL hit" << std::endl;
239  }
240  }
241  }
242  }
243 
244  std::stringstream ss;
245  //Loop on Det Clusters
246  for (const auto& dSet : *dsv_SiStripCluster) {
247  for (const auto& clus : dSet.data) {
248  if (MinClusterWidth_ <= clus.amplitudes().size() && clus.amplitudes().size() <= MaxClusterWidth_) {
249  if (std::find(vPSiStripCluster.begin(), vPSiStripCluster.end(), (void*)&clus) == vPSiStripCluster.end()) {
250  if (edm::isDebugEnabled())
251  ss << " adding cluster to histo for detid " << dSet.id << " with barycenter " << clus.barycenter()
252  << std::endl;
253  fillHisto(dSet.id, clus.barycenter());
254  }
255  }
256  }
257  }
258  LogTrace("SiStripQualityHotStripIdentifier") << ss.str();
259 }
260 
const edm::ESGetToken< SiStripQuality, SiStripQualityRcd > stripQualityToken_
bool isDebugEnabled()
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
static const TGPicture * info(bool iBackgroundIsBlack)
~SiStripQualityHotStripIdentifier() override=default
void fillHisto(uint32_t detid, float value)
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
std::string fullPath() const
Definition: FileInPath.cc:161
Registry::const_iterator RegistryIterator
Log< level::Error, false > LogError
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
ClusterRef cluster() const
std::unique_ptr< SiStripBadStrip > getNewObject() override
#define LogTrace(id)
void algoBeginRun(const edm::Run &, const edm::EventSetup &) override
T getUntrackedParameter(std::string const &, T const &) const
SiStripQualityHotStripIdentifier(const edm::ParameterSet &)
edm::ESWatcher< SiStripQualityRcd > stripQualityWatcher_
std::unordered_map< unsigned int, std::shared_ptr< TH1F > > QualityHistosMap
SiStripCluster const & monoCluster() const
void algoAnalyze(const edm::Event &, const edm::EventSetup &) override
void extractBadStrips(SiStripQuality *, HistoMap &, const SiStripQuality *)
void algoBeginJob(const edm::EventSetup &) override
Transition
Definition: Transition.h:12
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
SiStripDetInfo read(std::string filePath)
Definition: value.py:1
trackCollection
Definition: JetHT_cfg.py:51
Log< level::Info, false > LogInfo
SiStripCluster const & stereoCluster() const
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
HLT enums.
SiStripRecHit2D originalHit() const
double a
Definition: hdecay.h:121
std::pair< ContainerIterator, ContainerIterator > Range
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken_
static constexpr char const *const kDefaultFile
Definition: Run.h:45
void algoBeginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) override