CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripHotStripAlgorithmFromClusterOccupancy.cc
Go to the documentation of this file.
4 
5 
6 
7 
9  prob_(1.E-7),
10  MinNumEntries_(0),
11  MinNumEntriesPerStrip_(0),
12  Nevents_(0),
13  occupancy_(0),
14  OutFileName_("Occupancy.root"),
15  tTopo(theTopo),
16  UseInputDB_(iConfig.getUntrackedParameter<bool>("UseInputDB",false))
17  {
19  }
20 
21 
23  LogTrace("SiStripHotStripAlgorithmFromClusterOccupancy")<<"[SiStripHotStripAlgorithmFromClusterOccupancy::~SiStripHotStripAlgorithmFromClusterOccupancy] "<<std::endl;
24 }
25 
27 
28  LogTrace("SiStripHotStripAlgorithmFromClusterOccupancy")<<"[SiStripHotStripAlgorithmFromClusterOccupancy::extractBadStrips] "<<std::endl;
29 
30 
31 
32  if (WriteOutputFile_==true){
33  f = new TFile(OutFileName_.c_str(),"RECREATE");
34  f->cd();
35 
36  striptree = new TTree("stripOccupancy","tree");
37 
38  striptree->Branch("DetRawId", &detrawid, "DetRawId/I");
39  striptree->Branch("SubDetId", &subdetid, "SubDetId/I");
40  striptree->Branch("Layer_Ring", &layer_ring, "Layer_Ring/I");
41  striptree->Branch("Disc", &disc, "Disc/I");
42  striptree->Branch("IsBack", &isback, "IsBack/I");
43  striptree->Branch("IsExternalString", &isexternalstring, "IsExternalString/I");
44  striptree->Branch("IsZMinusSide", &iszminusside, "IsZMinusSide/I");
45  striptree->Branch("RodStringPetal", &rodstringpetal, "RodStringPetal/I");
46  striptree->Branch("IsStereo", &isstereo, "IsStereo/I");
47  striptree->Branch("ModulePosition", &module_position, "ModulePosition/I");
48  striptree->Branch("NumberOfStrips", &number_strips, "NumberOfStrips/I");
49  striptree->Branch("StripNumber", &strip_number, "StripNumber/I");
50  striptree->Branch("APVChannel", &apv_channel, "APVChannel/I");
51  striptree->Branch("StripGlobalPositionX", &global_position_x, "StripGlobalPositionX/F");
52  striptree->Branch("StripGlobalPositionY", &global_position_y, "StripGlobalPositionY/F");
53  striptree->Branch("StripGlobalPositionZ", &global_position_z, "StripGlobalPositionZ/F");
54  striptree->Branch("IsHot", &isHot, "IsHot/I");
55  striptree->Branch("HotStripsPerAPV", &hotStripsPerAPV, "HotStripsPerAPV/I");
56  striptree->Branch("HotStripsPerModule", &hotStripsPerModule,"HotStripsPerModule/I");
57  striptree->Branch("StripOccupancy", &stripOccupancy, "StripOccupancy/D");
58  striptree->Branch("StripHits", &stripHits, "StripHits/I");
59  striptree->Branch("PoissonProb", &poissonProb, "PoissonProb/D");
60  }
61 
62 
63  HistoMap::iterator it=DM.begin();
64  HistoMap::iterator itEnd=DM.end();
65  std::vector<unsigned int> badStripList;
66  uint32_t detid;
67  for (;it!=itEnd;++it){
68  pHisto phisto;
69  detid=it->first;
70 
71  DetId detectorId=DetId(detid);
72  phisto._SubdetId=detectorId.subdetId();
73 
74  if (edm::isDebugEnabled())
75  LogTrace("SiStripHotStrip") << "Analyzing detid " << detid<< std::endl;
76 
77  int numberAPVs = (int)(it->second.get())->GetNbinsX()/128;
78 
79  // Set the values for the tree:
80 
81  detrawid = detid;
82  subdetid = detectorId.subdetId();
83  number_strips = (int)(it->second.get())->GetNbinsX();
84  switch (detectorId.subdetId())
85  {
88  disc = -1;
90  isback = -1;
92  else isexternalstring = 0;
94  else iszminusside = 0;
97  break;
98 
103  if (tTopo->tidIsBackRing(detrawid)) isback = 1;
104  else isback = 0;
106  else iszminusside = 0;
107  isexternalstring = -1;
108  rodstringpetal = -1;
110  break;
111 
112  case StripSubdetector::TOB :
114  disc = -1;
116  isback = -1;
118  else iszminusside = 0;
119  isexternalstring = -1;
122  break;
123 
124  case StripSubdetector::TEC :
128  if (tTopo->tecIsBackPetal(detrawid)) isback = 1;
129  else isback = 0;
131  else iszminusside = 0;
132  isexternalstring = -1;
135  break;
136 
137  default :
138  std::cout << "### Detector does not belong to TIB, TID, TOB or TEC !? ###" << std::endl;
139  std::cout << "### DetRawId: " << detrawid << " ###" << std::endl;
140  }
141 
142  // End: Set the values for the tree.
143 
144 
145  pQuality=OutSiStripQuality;
146  badStripList.clear();
147 
148  for (int i=0; i<768; i++){
149  ishot[i] = 0;
150  stripoccupancy[i] = 0;
151  striphits[i] = 0;
152  poissonprob[i] = 0;
153  hotstripsperapv[i/128] = 0;
154  }
155 
156  hotstripspermodule = 0;
157 
158  for (int apv=0; apv<numberAPVs; apv++){
159  if(UseInputDB_){
160  if(InSiStripQuality->IsApvBad(detid,apv) ){
161  if(edm::isDebugEnabled())
162  LogTrace("SiStripHotStrip")<<"(Module and Apv number) "<<detid<<" , "<<apv<<" excluded by input ESetup."<<std::endl;
163  continue;//if the apv is already flagged as bad, continue.
164  }
165  else{
166  if(edm::isDebugEnabled())
167  LogTrace("SiStripHotStrip")<<"(Module and Apv number) "<<detid<<" , "<<apv<<" good by input ESetup."<<std::endl;
168  }
169  }
170 
171  phisto._th1f = new TH1F("tmp","tmp",128,0.5,128.5);
172  int NumberEntriesPerAPV=0;
173 
174  for (int strip=0; strip<128; strip++){
175  phisto._th1f->SetBinContent(strip+1,(it->second.get())->GetBinContent((apv*128)+strip+1));
176  NumberEntriesPerAPV += (int)(it->second.get())->GetBinContent((apv*128)+strip+1);
177  }
178 
179  phisto._th1f->SetEntries(NumberEntriesPerAPV);
180  phisto._NEntries=(int)phisto._th1f->GetEntries();
181  phisto._NEmptyBins=0;
182 
183  LogTrace("SiStripHotStrip") << "Number of clusters in APV " << apv << ": " << NumberEntriesPerAPV << std::endl;
184 
185  iterativeSearch(phisto,badStripList,apv);
186 
187  delete phisto._th1f;
188  }
189 
190  const StripGeomDetUnit* theStripDet = dynamic_cast<const StripGeomDetUnit*>( (TkGeom->idToDet(detectorId)) );
191  const StripTopology* theStripTopol = dynamic_cast<const StripTopology*>( &(theStripDet->specificTopology()) );
192 
193  for (int strip=0; strip<number_strips; strip++)
194  {
195  strip_number = strip+1;
196  apv_channel = (strip%128)+1;
197  isHot = ishot[strip];
199  stripHits = striphits[strip];
200  poissonProb = poissonprob[strip];
201 
203  hotStripsPerAPV = hotstripsperapv[strip/128];
204 
205  LocalPoint pos_strip_local = theStripTopol->localPosition(strip);
206  GlobalPoint pos_strip_global = (TkGeom->idToDet(detectorId))->surface().toGlobal(pos_strip_local);
207 
208  global_position_x = pos_strip_global.x();
209  global_position_y = pos_strip_global.y();
210  global_position_z = pos_strip_global.z();
211 
212  if (WriteOutputFile_==true) striptree->Fill();
213  }
214 
215  if (badStripList.begin()==badStripList.end())
216  continue;
217 
218  OutSiStripQuality->compact(detid,badStripList);
219 
220  SiStripQuality::Range range(badStripList.begin(),badStripList.end());
221  if ( ! OutSiStripQuality->put(detid,range) )
222  edm::LogError("SiStripHotStrip")<<"[SiStripHotStripAlgorithmFromClusterOccupancy::extractBadStrips] detid already exists"<<std::endl;
223  }
224  OutSiStripQuality->fillBadComponents();
225 
226  if (WriteOutputFile_==true){
227  f->cd();
228  striptree->Write();
229  f->Close();
230  }
231 
232  LogTrace("SiStripHotStrip") << ss.str() << std::endl;
233 }
234 
235 
236 void SiStripHotStripAlgorithmFromClusterOccupancy::iterativeSearch(pHisto& histo,std::vector<unsigned int>& vect, int apv){
237  if (!histo._NEntries || histo._NEntries <=MinNumEntries_ || histo._NEntries <= minNevents_)
238  return;
239 
240  size_t startingSize=vect.size();
241  long double diff=1.-prob_;
242 
243  size_t Nbins = histo._th1f->GetNbinsX();
244  size_t ibinStart = 1;
245  size_t ibinStop = Nbins+1;
246  int MaxEntry = (int)histo._th1f->GetMaximum();
247 
248  std::vector<long double> vPoissonProbs(MaxEntry+1,0);
249  long double meanVal=1.*histo._NEntries/(1.*Nbins-histo._NEmptyBins);
250  evaluatePoissonian(vPoissonProbs,meanVal);
251 
252  for (size_t i=ibinStart; i<ibinStop; ++i){
253  unsigned int entries= (unsigned int)histo._th1f->GetBinContent(i);
254 
255  if (ishot[(apv*128)+i-1]==0){
256  stripoccupancy[(apv*128)+i-1] = entries/(double) Nevents_;
257  striphits[(apv*128)+i-1] = entries;
258  poissonprob[(apv*128)+i-1] = 1-vPoissonProbs[entries];
259  }
260 
261  if (entries<=MinNumEntriesPerStrip_ || entries <= minNevents_)
262  continue;
263 
264  if(diff<vPoissonProbs[entries]){
265  ishot[(apv*128)+i-1] = 1;
267  hotstripsperapv[apv]++;
268  histo._th1f->SetBinContent(i,0.);
269  histo._NEntries-=entries;
270  histo._NEmptyBins++;
271  if (edm::isDebugEnabled())
272  LogTrace("SiStripHotStrip")<< " rejecting strip " << (apv*128)+i-1 << " value " << entries << " diff " << diff << " prob " << vPoissonProbs[entries]<< std::endl;
273  vect.push_back(pQuality->encode((apv*128)+i-1,1,0));
274  }
275 
276  }
277  if (edm::isDebugEnabled())
278  LogTrace("SiStripHotStrip") << " [SiStripHotStripAlgorithmFromClusterOccupancy::iterativeSearch] Nbins="<< Nbins << " MaxEntry="<<MaxEntry << " meanVal=" << meanVal << " NEmptyBins="<<histo._NEmptyBins<< " NEntries=" << histo._NEntries << " thEntries " << histo._th1f->GetEntries()<< " startingSize " << startingSize << " vector.size " << vect.size() << std::endl;
279 
280  if (vect.size()!=startingSize)
281  iterativeSearch(histo,vect,apv);
282 }
283 
284 void SiStripHotStripAlgorithmFromClusterOccupancy::evaluatePoissonian(std::vector<long double>& vPoissonProbs, long double& meanVal){
285  for(size_t i=0;i<vPoissonProbs.size();++i){
286  vPoissonProbs[i]= (i==0)?TMath::Poisson(i,meanVal):vPoissonProbs[i-1]+TMath::Poisson(i,meanVal);
287  }
288 }
289 
291  Nevents_=Nevents;
293  if (edm::isDebugEnabled())
294  LogTrace("SiStripHotStrip")<<" [SiStripHotStripAlgorithmFromClusterOccupancy::setNumberOfEvents] minNumber of Events per strip used to consider a strip bad" << minNevents_ << " for occupancy " << occupancy_ << std::endl;
295 }
bool isDebugEnabled()
int i
Definition: DBlmapReader.cc:9
SiStripHotStripAlgorithmFromClusterOccupancy(const edm::ParameterSet &, const TrackerTopology *)
void extractBadStrips(SiStripQuality *, HistoMap &, edm::ESHandle< SiStripQuality > &)
unsigned int tibLayer(const DetId &id) const
unsigned int tibString(const DetId &id) const
unsigned int tidRing(const DetId &id) const
bool tobIsStereo(const DetId &id) const
unsigned int tecRing(const DetId &id) const
ring id
T y() const
Definition: PV3DBase.h:63
void evaluatePoissonian(std::vector< long double > &, long double &meanVal)
unsigned int tidWheel(const DetId &id) const
virtual const StripTopology & specificTopology() const
Returns a reference to the strip proxy topology.
bool tecIsZMinusSide(const DetId &id) const
bool tidIsStereo(const DetId &id) const
bool tidIsZMinusSide(const DetId &id) const
static const char occupancy_[]
bool tecIsStereo(const DetId &id) const
bool tibIsExternalString(const DetId &id) const
bool tibIsZMinusSide(const DetId &id) const
unsigned int tidModule(const DetId &id) const
bool tidIsBackRing(const DetId &id) const
T z() const
Definition: PV3DBase.h:64
void compact(unsigned int &, std::vector< unsigned int > &)
bool tobIsZMinusSide(const DetId &id) const
void fillBadComponents()
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
#define LogTrace(id)
unsigned int tibModule(const DetId &id) const
unsigned int tecModule(const DetId &id) const
bool tecIsBackPetal(const DetId &id) const
Definition: DetId.h:18
void iterativeSearch(pHisto &, std::vector< unsigned int > &, int)
bool tibIsStereo(const DetId &id) const
unsigned int tobModule(const DetId &id) const
std::pair< ContainerIterator, ContainerIterator > Range
virtual LocalPoint localPosition(float strip) const =0
unsigned int tecPetalNumber(const DetId &id) const
tuple cout
Definition: gather_cfg.py:121
volatile std::atomic< bool > shutdown_flag false
unsigned int tobRod(const DetId &id) const
bool put(const uint32_t &detID, const InputVector &vect)
T x() const
Definition: PV3DBase.h:62
unsigned int tecWheel(const DetId &id) const
unsigned int encode(const unsigned short &first, const unsigned short &NconsecutiveBadStrips, const unsigned short &flag=0)
unsigned int tobLayer(const DetId &id) const
virtual const TrackerGeomDet * idToDet(DetId) const