CMS 3D CMS Logo

SiStripQualityHotStripIdentifier.cc
Go to the documentation of this file.
2 
4 
12 #include <iostream>
13 #include <fstream>
14 #include <sstream>
15 
16 //Insert here the include to the algos
18 
21  m_cacheID_(0),
22  dataLabel_(iConfig.getUntrackedParameter<std::string>("dataLabel", "")),
23  conf_(iConfig),
24  fp_(iConfig.getUntrackedParameter<edm::FileInPath>(
25  "file", edm::FileInPath("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat"))),
26  Cluster_src_(iConfig.getParameter<edm::InputTag>("Cluster_src")),
27  Track_src_(iConfig.getUntrackedParameter<edm::InputTag>("Track_src")),
28  tracksCollection_in_EventTree(iConfig.getUntrackedParameter<bool>("RemoveTrackClusters", false)),
29  tTopo(nullptr) {
31 
33  MinClusterWidth_ = pset.getUntrackedParameter<uint32_t>("minWidth", 1);
34  MaxClusterWidth_ = pset.getUntrackedParameter<uint32_t>("maxWidth", 1000);
35 
36  bookHistos();
37 }
38 
40 
41 std::unique_ptr<SiStripBadStrip> SiStripQualityHotStripIdentifier::getNewObject() {
42  auto obj = std::make_unique<SiStripBadStrip>();
43 
45  std::string AlgoName = parameters.getParameter<std::string>("AlgoName");
46  if (AlgoName == "SiStripHotStripAlgorithmFromClusterOccupancy") {
47  edm::LogInfo("SiStripQualityHotStripIdentifier")
48  << " [SiStripQualityHotStripIdentifier::getNewObject] call to SiStripHotStripAlgorithmFromClusterOccupancy"
49  << std::endl;
50 
52  theIdentifier.setProbabilityThreshold(parameters.getUntrackedParameter<double>("ProbabilityThreshold", 1.E-7));
53  theIdentifier.setMinNumEntries(parameters.getUntrackedParameter<uint32_t>("MinNumEntries", 100));
54  theIdentifier.setMinNumEntriesPerStrip(parameters.getUntrackedParameter<uint32_t>("MinNumEntriesPerStrip", 5));
55 
56  SiStripQuality* qobj = new SiStripQuality();
58 
59  edm::LogInfo("SiStripQualityHotStripIdentifier")
60  << " [SiStripQualityHotStripIdentifier::getNewObject] copy SiStripObject in SiStripBadStrip" << std::endl;
61 
62  std::stringstream ss;
63 
66  for (; rIter != rIterEnd; ++rIter) {
67  SiStripBadStrip::Range range(qobj->getDataVectorBegin() + rIter->ibegin,
68  qobj->getDataVectorBegin() + rIter->iend);
69  if (!obj->put(rIter->detid, range))
70  edm::LogError("SiStripQualityHotStripIdentifier")
71  << "[SiStripQualityHotStripIdentifier::getNewObject] detid already exists" << std::endl;
72  }
73  edm::LogInfo("SiStripQualityHotStripIdentifier")
74  << " [SiStripQualityHotStripIdentifier::getNewObject] " << ss.str() << std::endl;
75 
76  } else {
77  edm::LogError("SiStripQualityHotStripIdentifier")
78  << " [SiStripQualityHotStripIdentifier::getNewObject] call for a unknow HotStrip identification algoritm"
79  << std::endl;
80 
81  std::vector<uint32_t> a;
82  SiStripBadStrip::Range range(a.begin(), a.end());
83  if (!obj->put(0xFFFFFFFF, range))
84  edm::LogError("SiStripQualityHotStripIdentifier")
85  << "[SiStripQualityHotStripIdentifier::getNewObject] detid already exists" << std::endl;
86  }
87 
88  return obj;
89 }
90 
92  //Retrieve tracker topology from geometry
94  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
95  tTopo = tTopoHandle.product();
96 
97  resetHistos();
98  unsigned long long cacheID = iSetup.get<SiStripQualityRcd>().cacheIdentifier();
99 
100  if (m_cacheID_ == cacheID)
101  return;
102 
103  m_cacheID_ = cacheID;
104 
106 }
107 
109  //Clear map
110  ClusterPositionHistoMap.clear();
111 }
112 
114  edm::LogInfo("SiStripQualityHotStripIdentifier") << " [SiStripQualityHotStripIdentifier::resetHistos] " << std::endl;
115  SiStrip::QualityHistosMap::iterator it = ClusterPositionHistoMap.begin();
116  SiStrip::QualityHistosMap::iterator iEnd = ClusterPositionHistoMap.end();
117  for (; it != iEnd; ++it) {
118  it->second->Reset();
119  }
120 }
121 
123  edm::LogInfo("SiStripQualityHotStripIdentifier") << " [SiStripQualityHotStripIdentifier::bookHistos] " << std::endl;
124  char hname[1024];
125  std::map<uint32_t, SiStripDetInfoFileReader::DetInfo>::const_iterator it = reader->getAllData().begin();
126  std::map<uint32_t, SiStripDetInfoFileReader::DetInfo>::const_iterator iEnd = reader->getAllData().end();
127  for (; it != iEnd; ++it) {
128  sprintf(hname, "h_%d", it->first);
129  SiStrip::QualityHistosMap::iterator ref = ClusterPositionHistoMap.find(it->first);
130  if (ref == ClusterPositionHistoMap.end()) {
131  ClusterPositionHistoMap[it->first] =
132  boost::shared_ptr<TH1F>(new TH1F(hname, hname, it->second.nApvs * 128, -0.5, it->second.nApvs * 128 - 0.5));
133  } else
134  edm::LogError("SiStripQualityHotStripIdentifier")
135  << " [SiStripQualityHotStripIdentifier::bookHistos] DetId " << it->first
136  << " already found in map. Ignoring new data" << std::endl;
137  }
138 }
139 
141  SiStrip::QualityHistosMap::iterator ref = ClusterPositionHistoMap.find(detid);
142  if (ref != ClusterPositionHistoMap.end())
143  ref->second->Fill(value);
144  else
145  edm::LogError("SiStripQualityHotStripIdentifier")
146  << " [SiStripQualityHotStripIdentifier::fillHisto] Histogram not found in the list for DetId " << detid
147  << " Ignoring data value " << value << std::endl;
148 }
149 
152  e.getByLabel(Cluster_src_, dsv_SiStripCluster);
153 
156  e.getByLabel(Track_src_, trackCollection);
157  if (!trackCollection.isValid()) {
158  edm::LogError("SiStripQualityHotStripIdentifier")
159  << " [SiStripQualityHotStripIdentifier::algoAnalyze] missing trackCollection with label " << Track_src_
160  << std::endl;
161  }
162  }
163 
164  std::set<const void*> vPSiStripCluster;
165  //Perform track study
167  const reco::TrackCollection tC = *(trackCollection.product());
168  int i = 0;
169  for (reco::TrackCollection::const_iterator track = tC.begin(); track != tC.end(); track++) {
170  LogTrace("SiStripQualityHotStripIdentifier")
171  << "Track number " << i + 1 << "\n\tmomentum: " << track->momentum() << "\n\tPT: " << track->pt()
172  << "\n\tvertex: " << track->vertex() << "\n\timpact parameter: " << track->d0()
173  << "\n\tcharge: " << track->charge() << "\n\tnormalizedChi2: " << track->normalizedChi2()
174  << "\n\tFrom EXTRA : "
175  << "\n\t\touter PT " << track->outerPt() << std::endl;
176 
177  //Loop on rechits
178  for (auto const& recHit : track->recHits()) {
179  if (!recHit->isValid()) {
180  LogTrace("SiStripQualityHotStripIdentifier") << "\t\t Invalid Hit " << std::endl;
181  continue;
182  }
183 
184  const SiStripRecHit2D* singleHit = dynamic_cast<const SiStripRecHit2D*>(recHit);
185  const SiStripMatchedRecHit2D* matchedHit = dynamic_cast<const SiStripMatchedRecHit2D*>(recHit);
186  const ProjectedSiStripRecHit2D* projectedHit = dynamic_cast<const ProjectedSiStripRecHit2D*>(recHit);
187 
188  if (matchedHit) {
189  vPSiStripCluster.insert((void*)&(matchedHit->monoCluster()));
190  vPSiStripCluster.insert((void*)&(matchedHit->stereoCluster()));
191  } else if (projectedHit) {
192  vPSiStripCluster.insert((void*)&*(projectedHit->originalHit().cluster()));
193  } else if (singleHit) {
194  vPSiStripCluster.insert((void*)&*(singleHit->cluster()));
195  } else {
196  LogTrace("SiStripQualityHotStripIdentifier") << "NULL hit" << std::endl;
197  }
198  }
199  }
200  }
201 
202  std::stringstream ss;
203  //Loop on Det Clusters
204  edm::DetSetVector<SiStripCluster>::const_iterator DSViter = dsv_SiStripCluster->begin();
205  for (; DSViter != dsv_SiStripCluster->end(); DSViter++) {
207  edm::DetSet<SiStripCluster>::const_iterator ClusIterEnd = DSViter->data.end();
208  for (; ClusIter != ClusIterEnd; ++ClusIter) {
209  if (MinClusterWidth_ <= ClusIter->amplitudes().size() && ClusIter->amplitudes().size() <= MaxClusterWidth_) {
210  if (std::find(vPSiStripCluster.begin(), vPSiStripCluster.end(), (void*)&*ClusIter) == vPSiStripCluster.end()) {
211  if (edm::isDebugEnabled())
212  ss << " adding cluster to histo for detid " << DSViter->id << " with barycenter " << ClusIter->barycenter()
213  << std::endl;
214  fillHisto(DSViter->id, ClusIter->barycenter());
215  }
216  }
217  }
218  }
219  LogTrace("SiStripQualityHotStripIdentifier") << ss.str();
220 }
size
Write out results.
T getParameter(std::string const &) const
bool isDebugEnabled()
T getUntrackedParameter(std::string const &, T const &) const
void fillHisto(uint32_t detid, float value)
void extractBadStrips(SiStripQuality *, HistoMap &, edm::ESHandle< SiStripQuality > &)
SiStripCluster const & monoCluster() const
#define nullptr
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:15
Registry::const_iterator RegistryIterator
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
std::unique_ptr< SiStripBadStrip > getNewObject() override
void algoBeginRun(const edm::Run &, const edm::EventSetup &) override
size_type size() const
Definition: DetSet.h:63
SiStripQualityHotStripIdentifier(const edm::ParameterSet &)
edmNew::DetSet< SiStripCluster >::const_iterator ClusIter
const std::map< uint32_t, DetInfo > & getAllData() const
RegistryIterator getRegistryVectorEnd() const
void algoAnalyze(const edm::Event &, const edm::EventSetup &) override
ClusterRef cluster() const
edm::ESHandle< SiStripQuality > SiStripQuality_
Definition: value.py:1
bool isValid() const
Definition: HandleBase.h:74
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:480
iterator end()
Return the off-the-end iterator.
Definition: DetSetVector.h:361
#define LogTrace(id)
ContainerIterator getDataVectorBegin() const
SiStripRecHit2D originalHit() const
T const * product() const
Definition: Handle.h:74
RegistryIterator getRegistryVectorBegin() const
SiStripCluster const & stereoCluster() const
HLT enums.
double a
Definition: hdecay.h:121
std::pair< ContainerIterator, ContainerIterator > Range
T get() const
Definition: EventSetup.h:71
std::string fullPath() const
Definition: FileInPath.cc:163
iterator begin()
Return an iterator to the first DetSet.
Definition: DetSetVector.h:346
collection_type::const_iterator const_iterator
Definition: DetSet.h:33
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:104
T const * product() const
Definition: ESHandle.h:86
Definition: Run.h:45