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];
170  for (const auto& it : SiStripDetInfoFileReader::read(fp_.fullPath()).getAllData()) {
171  sprintf(hname, "h_%d", it.first);
172  auto ref = ClusterPositionHistoMap.find(it.first);
173  if (ref == ClusterPositionHistoMap.end()) {
174  ClusterPositionHistoMap[it.first] =
175  std::make_shared<TH1F>(hname, hname, it.second.nApvs * 128, -0.5, it.second.nApvs * 128 - 0.5);
176  } else
177  edm::LogError("SiStripQualityHotStripIdentifier")
178  << " [SiStripQualityHotStripIdentifier::bookHistos] DetId " << it.first
179  << " already found in map. Ignoring new data" << std::endl;
180  }
181 }
182 
184  auto ref = ClusterPositionHistoMap.find(detid);
185  if (ref != ClusterPositionHistoMap.end())
186  ref->second->Fill(value);
187  else
188  edm::LogError("SiStripQualityHotStripIdentifier")
189  << " [SiStripQualityHotStripIdentifier::fillHisto] Histogram not found in the list for DetId " << detid
190  << " Ignoring data value " << value << std::endl;
191 }
192 
195  e.getByLabel(Cluster_src_, dsv_SiStripCluster);
196 
199  e.getByLabel(Track_src_, trackCollection);
200  if (!trackCollection.isValid()) {
201  edm::LogError("SiStripQualityHotStripIdentifier")
202  << " [SiStripQualityHotStripIdentifier::algoAnalyze] missing trackCollection with label " << Track_src_
203  << std::endl;
204  }
205  }
206 
207  std::set<const void*> vPSiStripCluster;
208  //Perform track study
210  int i = 0;
211  for (const auto& track : *(trackCollection.product())) {
212  LogTrace("SiStripQualityHotStripIdentifier")
213  << "Track number " << i + 1 << "\n\tmomentum: " << track.momentum() << "\n\tPT: " << track.pt()
214  << "\n\tvertex: " << track.vertex() << "\n\timpact parameter: " << track.d0()
215  << "\n\tcharge: " << track.charge() << "\n\tnormalizedChi2: " << track.normalizedChi2() << "\n\tFrom EXTRA : "
216  << "\n\t\touter PT " << track.outerPt() << std::endl;
217 
218  //Loop on rechits
219  for (auto const& recHit : track.recHits()) {
220  if (!recHit->isValid()) {
221  LogTrace("SiStripQualityHotStripIdentifier") << "\t\t Invalid Hit " << std::endl;
222  continue;
223  }
224 
225  const SiStripRecHit2D* singleHit = dynamic_cast<const SiStripRecHit2D*>(recHit);
226  const SiStripMatchedRecHit2D* matchedHit = dynamic_cast<const SiStripMatchedRecHit2D*>(recHit);
227  const ProjectedSiStripRecHit2D* projectedHit = dynamic_cast<const ProjectedSiStripRecHit2D*>(recHit);
228 
229  if (matchedHit) {
230  vPSiStripCluster.insert((void*)&(matchedHit->monoCluster()));
231  vPSiStripCluster.insert((void*)&(matchedHit->stereoCluster()));
232  } else if (projectedHit) {
233  vPSiStripCluster.insert((void*)&*(projectedHit->originalHit().cluster()));
234  } else if (singleHit) {
235  vPSiStripCluster.insert((void*)&*(singleHit->cluster()));
236  } else {
237  LogTrace("SiStripQualityHotStripIdentifier") << "NULL hit" << std::endl;
238  }
239  }
240  }
241  }
242 
243  std::stringstream ss;
244  //Loop on Det Clusters
245  for (const auto& dSet : *dsv_SiStripCluster) {
246  for (const auto& clus : dSet.data) {
247  if (MinClusterWidth_ <= clus.amplitudes().size() && clus.amplitudes().size() <= MaxClusterWidth_) {
248  if (std::find(vPSiStripCluster.begin(), vPSiStripCluster.end(), (void*)&clus) == vPSiStripCluster.end()) {
249  if (edm::isDebugEnabled())
250  ss << " adding cluster to histo for detid " << dSet.id << " with barycenter " << clus.barycenter()
251  << std::endl;
252  fillHisto(dSet.id, clus.barycenter());
253  }
254  }
255  }
256  }
257  LogTrace("SiStripQualityHotStripIdentifier") << ss.str();
258 }
259 
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
~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