CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SiStripQualityHotStripIdentifier.cc
Go to the documentation of this file.
2 
4 
11 #include <fstream>
12 #include <iostream>
13 #include <memory>
14 #include <sstream>
15 
16 //Insert here the include to the algos
19 
22  dataLabel_(iConfig.getUntrackedParameter<std::string>("dataLabel", "")),
23  conf_(iConfig),
24  fp_(iConfig.getUntrackedParameter<edm::FileInPath>("file",
25  edm::FileInPath(SiStripDetInfoFileReader::kDefaultFile))),
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  tTopoToken_(esConsumes<edm::Transition::BeginRun>()),
30  stripQualityToken_(esConsumes<edm::Transition::BeginRun>()) {
32  MinClusterWidth_ = pset.getUntrackedParameter<uint32_t>("minWidth", 1);
33  MaxClusterWidth_ = pset.getUntrackedParameter<uint32_t>("maxWidth", 1000);
34 
35  bookHistos();
36 }
37 
39 
40 std::unique_ptr<SiStripBadStrip> SiStripQualityHotStripIdentifier::getNewObject() {
41  auto obj = std::make_unique<SiStripBadStrip>();
42 
44  std::string AlgoName = parameters.getParameter<std::string>("AlgoName");
45  if (AlgoName == "SiStripHotStripAlgorithmFromClusterOccupancy") {
46  edm::LogInfo("SiStripQualityHotStripIdentifier")
47  << " [SiStripQualityHotStripIdentifier::getNewObject] call to SiStripHotStripAlgorithmFromClusterOccupancy"
48  << std::endl;
49 
51  theIdentifier.setProbabilityThreshold(parameters.getUntrackedParameter<double>("ProbabilityThreshold", 1.E-7));
52  theIdentifier.setMinNumEntries(parameters.getUntrackedParameter<uint32_t>("MinNumEntries", 100));
53  theIdentifier.setMinNumEntriesPerStrip(parameters.getUntrackedParameter<uint32_t>("MinNumEntriesPerStrip", 5));
54 
55  const auto detInfo =
57  SiStripQuality* qobj = new SiStripQuality(detInfo);
59 
60  edm::LogInfo("SiStripQualityHotStripIdentifier")
61  << " [SiStripQualityHotStripIdentifier::getNewObject] copy SiStripObject in SiStripBadStrip" << std::endl;
62 
63  std::stringstream ss;
64 
65  SiStripBadStrip::RegistryIterator rIter = qobj->getRegistryVectorBegin();
66  SiStripBadStrip::RegistryIterator rIterEnd = qobj->getRegistryVectorEnd();
67  for (; rIter != rIterEnd; ++rIter) {
68  SiStripBadStrip::Range range(qobj->getDataVectorBegin() + rIter->ibegin,
69  qobj->getDataVectorBegin() + rIter->iend);
70  if (!obj->put(rIter->detid, range))
71  edm::LogError("SiStripQualityHotStripIdentifier")
72  << "[SiStripQualityHotStripIdentifier::getNewObject] detid already exists" << std::endl;
73  }
74  edm::LogInfo("SiStripQualityHotStripIdentifier")
75  << " [SiStripQualityHotStripIdentifier::getNewObject] " << ss.str() << std::endl;
76 
77  } else {
78  edm::LogError("SiStripQualityHotStripIdentifier")
79  << " [SiStripQualityHotStripIdentifier::getNewObject] call for a unknow HotStrip identification algoritm"
80  << std::endl;
81 
82  std::vector<uint32_t> a;
83  SiStripBadStrip::Range range(a.begin(), a.end());
84  if (!obj->put(0xFFFFFFFF, range))
85  edm::LogError("SiStripQualityHotStripIdentifier")
86  << "[SiStripQualityHotStripIdentifier::getNewObject] detid already exists" << std::endl;
87  }
88 
89  return obj;
90 }
91 
93  tTopo = &iSetup.getData(tTopoToken_);
94 
95  resetHistos();
96 
97  if (stripQualityWatcher_.check(iSetup)) {
99  }
100 }
101 
103  //Clear map
104  ClusterPositionHistoMap.clear();
105 }
106 
108  edm::LogInfo("SiStripQualityHotStripIdentifier") << " [SiStripQualityHotStripIdentifier::resetHistos] " << std::endl;
109  for (const auto& it : ClusterPositionHistoMap) {
110  it.second->Reset();
111  }
112 }
113 
115  edm::LogInfo("SiStripQualityHotStripIdentifier") << " [SiStripQualityHotStripIdentifier::bookHistos] " << std::endl;
116  char hname[1024];
117  for (const auto& it : SiStripDetInfoFileReader::read(fp_.fullPath()).getAllData()) {
118  sprintf(hname, "h_%d", it.first);
119  auto ref = ClusterPositionHistoMap.find(it.first);
120  if (ref == ClusterPositionHistoMap.end()) {
121  ClusterPositionHistoMap[it.first] =
122  std::make_shared<TH1F>(hname, hname, it.second.nApvs * 128, -0.5, it.second.nApvs * 128 - 0.5);
123  } else
124  edm::LogError("SiStripQualityHotStripIdentifier")
125  << " [SiStripQualityHotStripIdentifier::bookHistos] DetId " << it.first
126  << " already found in map. Ignoring new data" << std::endl;
127  }
128 }
129 
131  auto ref = ClusterPositionHistoMap.find(detid);
132  if (ref != ClusterPositionHistoMap.end())
133  ref->second->Fill(value);
134  else
135  edm::LogError("SiStripQualityHotStripIdentifier")
136  << " [SiStripQualityHotStripIdentifier::fillHisto] Histogram not found in the list for DetId " << detid
137  << " Ignoring data value " << value << std::endl;
138 }
139 
142  e.getByLabel(Cluster_src_, dsv_SiStripCluster);
143 
146  e.getByLabel(Track_src_, trackCollection);
147  if (!trackCollection.isValid()) {
148  edm::LogError("SiStripQualityHotStripIdentifier")
149  << " [SiStripQualityHotStripIdentifier::algoAnalyze] missing trackCollection with label " << Track_src_
150  << std::endl;
151  }
152  }
153 
154  std::set<const void*> vPSiStripCluster;
155  //Perform track study
157  int i = 0;
158  for (const auto& track : *(trackCollection.product())) {
159  LogTrace("SiStripQualityHotStripIdentifier")
160  << "Track number " << i + 1 << "\n\tmomentum: " << track.momentum() << "\n\tPT: " << track.pt()
161  << "\n\tvertex: " << track.vertex() << "\n\timpact parameter: " << track.d0()
162  << "\n\tcharge: " << track.charge() << "\n\tnormalizedChi2: " << track.normalizedChi2() << "\n\tFrom EXTRA : "
163  << "\n\t\touter PT " << track.outerPt() << std::endl;
164 
165  //Loop on rechits
166  for (auto const& recHit : track.recHits()) {
167  if (!recHit->isValid()) {
168  LogTrace("SiStripQualityHotStripIdentifier") << "\t\t Invalid Hit " << std::endl;
169  continue;
170  }
171 
172  const SiStripRecHit2D* singleHit = dynamic_cast<const SiStripRecHit2D*>(recHit);
173  const SiStripMatchedRecHit2D* matchedHit = dynamic_cast<const SiStripMatchedRecHit2D*>(recHit);
174  const ProjectedSiStripRecHit2D* projectedHit = dynamic_cast<const ProjectedSiStripRecHit2D*>(recHit);
175 
176  if (matchedHit) {
177  vPSiStripCluster.insert((void*)&(matchedHit->monoCluster()));
178  vPSiStripCluster.insert((void*)&(matchedHit->stereoCluster()));
179  } else if (projectedHit) {
180  vPSiStripCluster.insert((void*)&*(projectedHit->originalHit().cluster()));
181  } else if (singleHit) {
182  vPSiStripCluster.insert((void*)&*(singleHit->cluster()));
183  } else {
184  LogTrace("SiStripQualityHotStripIdentifier") << "NULL hit" << std::endl;
185  }
186  }
187  }
188  }
189 
190  std::stringstream ss;
191  //Loop on Det Clusters
192  for (const auto& dSet : *dsv_SiStripCluster) {
193  for (const auto& clus : dSet.data) {
194  if (MinClusterWidth_ <= clus.amplitudes().size() && clus.amplitudes().size() <= MaxClusterWidth_) {
195  if (std::find(vPSiStripCluster.begin(), vPSiStripCluster.end(), (void*)&clus) == vPSiStripCluster.end()) {
196  if (edm::isDebugEnabled())
197  ss << " adding cluster to histo for detid " << dSet.id << " with barycenter " << clus.barycenter()
198  << std::endl;
199  fillHisto(dSet.id, clus.barycenter());
200  }
201  }
202  }
203  }
204  LogTrace("SiStripQualityHotStripIdentifier") << ss.str();
205 }
bool isDebugEnabled()
T getUntrackedParameter(std::string const &, T const &) const
void fillHisto(uint32_t detid, float value)
SiStripCluster const & monoCluster() const
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
std::unique_ptr< SiStripBadStrip > getNewObject() override
#define LogTrace(id)
void algoBeginRun(const edm::Run &, const edm::EventSetup &) override
const uint16_t range(const Frame &aFrame)
bool getData(T &iHolder) const
Definition: EventSetup.h:128
SiStripQualityHotStripIdentifier(const edm::ParameterSet &)
edm::ESWatcher< SiStripQualityRcd > stripQualityWatcher_
void algoAnalyze(const edm::Event &, const edm::EventSetup &) override
void extractBadStrips(SiStripQuality *, HistoMap &, const SiStripQuality *)
Transition
Definition: Transition.h:12
ClusterRef cluster() const
SiStripDetInfo read(std::string filePath)
bool isValid() const
Definition: HandleBase.h:70
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:500
SiStripRecHit2D originalHit() const
Log< level::Info, false > LogInfo
tuple trackCollection
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken_
T const * product() const
Definition: Handle.h:70
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::ESGetToken< SiStripQuality, SiStripQualityRcd > stripQualityToken_
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
SiStripCluster const & stereoCluster() const
double a
Definition: hdecay.h:119
std::pair< ContainerIterator, ContainerIterator > Range
std::string fullPath() const
Definition: FileInPath.cc:161
static constexpr char const *const kDefaultFile
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
tTopoToken_
Definition: Run.h:45