CMS 3D CMS Logo

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