test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MeasurementTrackerImpl.cc
Go to the documentation of this file.
2 
5 
12 
14 
16 
22 
24 
29 
32 #include "TkStripMeasurementDet.h"
33 #include "TkPixelMeasurementDet.h"
34 #include "TkGluedMeasurementDet.h"
35 #include "TkStackMeasurementDet.h"
36 
39 
40 #include <iostream>
41 #include <typeinfo>
42 #include <map>
43 #include <algorithm>
44 
45 
46 //
47 
48 using namespace std;
49 
50 namespace {
51 
52  class StrictWeakOrdering{
53  public:
54  bool operator() ( uint32_t p,const uint32_t& i) const {return p < i;}
55  };
56 
57 
58  struct CmpTKD {
59  bool operator()(MeasurementDet const* rh, MeasurementDet const * lh) {
60  return rh->fastGeomDet().geographicalId().rawId() < lh->fastGeomDet().geographicalId().rawId();
61  }
62  bool operator()(MeasurementDet const & rh, MeasurementDet const & lh) {
64  }
65  };
66 
67  template<typename TKD>
68  void sortTKD( std::vector<TKD*> & det) {
69  std::sort(det.begin(),det.end(),CmpTKD());
70  }
71  template<typename TKD>
72  void sortTKD( std::vector<TKD> & det) {
73  std::sort(det.begin(),det.end(),CmpTKD());
74  }
75 
76 }
77 
78 
81  const StripClusterParameterEstimator* stripCPE,
82  const SiStripRecHitMatcher* hitMatcher,
83  const TrackerGeometry* trackerGeom,
84  const GeometricSearchTracker* geometricSearchTracker,
85  const SiStripQuality *stripQuality,
86  int stripQualityFlags,
87  int stripQualityDebugFlags,
88  const SiPixelQuality *pixelQuality,
89  const SiPixelFedCabling *pixelCabling,
90  int pixelQualityFlags,
91  int pixelQualityDebugFlags) :
92  MeasurementTracker(trackerGeom,geometricSearchTracker),
93  pset_(conf),
94  name_(conf.getParameter<std::string>("ComponentName")),
95  theStDetConditions(hitMatcher,stripCPE),
96  thePxDetConditions(pixelCPE)
97 {
98  this->initialize();
99  this->initializeStripStatus(stripQuality, stripQualityFlags, stripQualityDebugFlags);
100  this->initializePixelStatus(pixelQuality, pixelCabling, pixelQualityFlags, pixelQualityDebugFlags);
101 }
102 
104 {
105 }
106 
107 
109 {
110 
111  bool subIsPixel = false;
112 
113  //if the TkGeometry has the subDet vector filled, the theDetMap is filled, otherwise nothing should happen
114  if(theTrackerGeom->detsPXB().size()!=0) {
115  subIsPixel = GeomDetEnumerators::isTrackerPixel(theTrackerGeom->geomDetSubDetector(theTrackerGeom->detsPXB().front()->geographicalId().subdetId()));
116  addDets(theTrackerGeom->detsPXB(), subIsPixel);
117  }
118 
119  if(theTrackerGeom->detsPXF().size()!=0) {
120  subIsPixel = GeomDetEnumerators::isTrackerPixel(theTrackerGeom->geomDetSubDetector(theTrackerGeom->detsPXF().front()->geographicalId().subdetId()));
121  addDets(theTrackerGeom->detsPXF(), subIsPixel);
122  }
123 
124  if(theTrackerGeom->detsTIB().size()!=0) {
125  subIsPixel = GeomDetEnumerators::isTrackerPixel(theTrackerGeom->geomDetSubDetector(theTrackerGeom->detsTIB().front()->geographicalId().subdetId()));
126  addDets(theTrackerGeom->detsTIB(), subIsPixel);
127  }
128 
129  if(theTrackerGeom->detsTID().size()!=0) {
130  subIsPixel = GeomDetEnumerators::isTrackerPixel(theTrackerGeom->geomDetSubDetector(theTrackerGeom->detsTID().front()->geographicalId().subdetId()));
131  addDets(theTrackerGeom->detsTID(), subIsPixel);
132  }
133 
134  if(theTrackerGeom->detsTOB().size()!=0) {
135  subIsPixel = GeomDetEnumerators::isTrackerPixel(theTrackerGeom->geomDetSubDetector(theTrackerGeom->detsTOB().front()->geographicalId().subdetId()));
136  addDets(theTrackerGeom->detsTOB(), subIsPixel);
137  }
138 
139  if(theTrackerGeom->detsTEC().size()!=0) {
140  subIsPixel = GeomDetEnumerators::isTrackerPixel(theTrackerGeom->geomDetSubDetector(theTrackerGeom->detsTEC().front()->geographicalId().subdetId()));
141  addDets(theTrackerGeom->detsTEC(), subIsPixel);
142  }
143 
144  // fist all stripdets
145  sortTKD(theStripDets);
147  for (unsigned int i=0; i!=theStripDets.size(); ++i)
149 
150  // now the glued dets
151  sortTKD(theGluedDets);
152  for (unsigned int i=0; i!=theGluedDets.size(); ++i)
154 
155  // then the stack dets
156  sortTKD(theStackDets);
157  for (unsigned int i=0; i!=theStackDets.size(); ++i)
159 
160  // and then the pixels, at last
161  sortTKD(thePixelDets);
163  for (unsigned int i=0; i!=thePixelDets.size(); ++i)
165 
166  if(!checkDets())
167  throw MeasurementDetException("Number of dets in MeasurementTracker not consistent with TrackerGeometry!");
168 
169 }
170 
171 void MeasurementTrackerImpl::initStMeasurementConditionSet(std::vector<TkStripMeasurementDet> & stripDets)
172 {
173  // assume vector is full and ordered!
174  int size = stripDets.size();
175  theStDetConditions.init(size);
176  for (int i=0; i!=size; ++i) {
177  auto & mdet = stripDets[i];
178  mdet.setIndex(i);
179  //intialize the detId !
180  theStDetConditions.id_[i] = mdet.specificGeomDet().geographicalId().rawId();
182  //initalize the total number of strips
183  theStDetConditions.totalStrips_[i] = mdet.specificGeomDet().specificTopology().nstrips();
184  }
185 }
186 
187 void MeasurementTrackerImpl::initPxMeasurementConditionSet(std::vector<TkPixelMeasurementDet> & pixelDets)
188 {
189  // assume vector is full and ordered!
190  int size = pixelDets.size();
191  thePxDetConditions.init(size);
192 
193  for (int i=0; i!=size; ++i) {
194  auto & mdet = pixelDets[i];
195  mdet.setIndex(i);
196  thePxDetConditions.id_[i] = mdet.specificGeomDet().geographicalId().rawId();
197  }
198 }
199 
200 
201 
202 
204 
205  //in phase2, we can have composed subDetector made by Pixel or Strip
206  for (TrackerGeometry::DetContainer::const_iterator gd=dets.begin();
207  gd != dets.end(); gd++) {
208 
209  const GeomDetUnit* gdu = dynamic_cast<const GeomDetUnit*>(*gd);
210 
211  //Pixel or Strip GeomDetUnit
212  if (gdu->isLeaf()) {
213  if(subIsPixel) {
214  addPixelDet(*gd);
215  } else {
216  addStripDet(*gd);
217  }
218  } else {
219 
220  //Glued or Stack GeomDet
221  const GluedGeomDet* gluedDet = dynamic_cast<const GluedGeomDet*>(*gd);
222  const StackGeomDet* stackDet = dynamic_cast<const StackGeomDet*>(*gd);
223 
224  if ((gluedDet == 0 && stackDet == 0) || (gluedDet != 0 && stackDet != 0)) {
225  throw MeasurementDetException("MeasurementTracker ERROR: GeomDet neither DetUnit nor GluedDet nor StackDet");
226  }
227  if(gluedDet != 0)
228  addGluedDet(gluedDet);
229  else
230  addStackDet(stackDet);
231 
232  }
233  }
234 
235 }
236 
238  if(theTrackerGeom->dets().size() == theDetMap.size())
239  return true;
240  return false;
241 }
242 
244 {
245  try {
247  }
248  catch(MeasurementDetException& err){
249  edm::LogError("MeasurementDet") << "Oops, got a MeasurementDetException: " << err.what() ;
250  }
251 }
252 
254 {
255  try {
257  }
258  catch(MeasurementDetException& err){
259  edm::LogError("MeasurementDet") << "Oops, got a MeasurementDetException: " << err.what() ;
260  }
261 }
262 
264 {
266 }
267 
269 {
270  //since the Stack will be composed by PS or 2S,
271  //both cluster parameter estimators are needed? - right now just the thePixelCPE is used.
273 }
274 
276 {
277  const GluedGeomDet& gd = det.specificGeomDet();
278  const MeasurementDet* monoDet = findDet( gd.monoDet()->geographicalId());
279  const MeasurementDet* stereoDet = findDet( gd.stereoDet()->geographicalId());
280  if (monoDet == 0 || stereoDet == 0) {
281  edm::LogError("MeasurementDet") << "MeasurementTracker ERROR: GluedDet components not found as MeasurementDets ";
282  throw MeasurementDetException("MeasurementTracker ERROR: GluedDet components not found as MeasurementDets");
283  }
284  det.init(monoDet,stereoDet);
285  theDetMap[gd.geographicalId()] = &det;
286 }
287 
289 {
290  const StackGeomDet& gd = det.specificGeomDet();
291  const MeasurementDet* lowerDet = findDet( gd.lowerDet()->geographicalId());
292  const MeasurementDet* upperDet = findDet( gd.upperDet()->geographicalId());
293  if (lowerDet == 0 || upperDet == 0) {
294  edm::LogError("MeasurementDet") << "MeasurementTracker ERROR: StackDet components not found as MeasurementDets ";
295  throw MeasurementDetException("MeasurementTracker ERROR: StackDet components not found as MeasurementDets");
296  }
297  det.init(lowerDet,upperDet);
298  theDetMap[gd.geographicalId()] = &det;
299 }
300 
301 void MeasurementTrackerImpl::initializeStripStatus(const SiStripQuality *quality, int qualityFlags, int qualityDebugFlags) {
302  edm::ParameterSet cutPset = pset_.getParameter<edm::ParameterSet>("badStripCuts");
303  if (qualityFlags & BadStrips) {
304  typedef StMeasurementConditionSet::BadStripCuts BadStripCuts;
309  }
311 
312 
313  if ((quality != 0) && (qualityFlags != 0)) {
314  edm::LogInfo("MeasurementTracker") << "qualityFlags = " << qualityFlags;
315  unsigned int on = 0, tot = 0;
316  unsigned int foff = 0, ftot = 0, aoff = 0, atot = 0;
317  for (int i=0; i!= theStDetConditions.nDet(); i++) {
318  uint32_t detid = theStDetConditions.id(i);
319  if (qualityFlags & BadModules) {
320  bool isOn = quality->IsModuleUsable(detid);
322  tot++; on += (unsigned int) isOn;
323  if (qualityDebugFlags & BadModules) {
324  edm::LogInfo("MeasurementTracker")<< "MeasurementTrackerImpl::initializeStripStatus : detid " << detid << " is " << (isOn ? "on" : "off");
325  }
326  } else {
328  }
329  // first turn all APVs and fibers ON
331  if (qualityFlags & BadAPVFibers) {
332  short badApvs = quality->getBadApvs(detid);
333  short badFibers = quality->getBadFibers(detid);
334  for (int j = 0; j < 6; j++) {
335  atot++;
336  if (badApvs & (1 << j)) {
338  aoff++;
339  }
340  }
341  for (int j = 0; j < 3; j++) {
342  ftot++;
343  if (badFibers & (1 << j)) {
346  foff++;
347  }
348  }
349  }
350  auto & badStrips = theStDetConditions.getBadStripBlocks(i);
351  badStrips.clear();
352  if (qualityFlags & BadStrips) {
353  SiStripBadStrip::Range range = quality->getRange(detid);
354  for (SiStripBadStrip::ContainerIterator bit = range.first; bit != range.second; ++bit) {
355  badStrips.push_back(quality->decode(*bit));
356  }
357  }
358  }
359  if (qualityDebugFlags & BadModules) {
360  edm::LogInfo("MeasurementTracker StripModuleStatus") <<
361  " Total modules: " << tot << ", active " << on <<", inactive " << (tot - on);
362  }
363  if (qualityDebugFlags & BadAPVFibers) {
364  edm::LogInfo("MeasurementTracker StripAPVStatus") <<
365  " Total APVs: " << atot << ", active " << (atot-aoff) <<", inactive " << (aoff);
366  edm::LogInfo("MeasurementTracker StripFiberStatus") <<
367  " Total Fibers: " << ftot << ", active " << (ftot-foff) <<", inactive " << (foff);
368  }
369  } else {
370  for (int i=0; i!=theStDetConditions.nDet(); i++) {
371  theStDetConditions.setActive(i,true); // module ON
372  theStDetConditions.set128StripStatus(i,true); // all APVs and fibers ON
373  }
374  }
375 
376 }
377 
378 void MeasurementTrackerImpl::initializePixelStatus(const SiPixelQuality *quality, const SiPixelFedCabling *pixelCabling, int qualityFlags, int qualityDebugFlags) {
379  if ((quality != 0) && (qualityFlags != 0)) {
380  edm::LogInfo("MeasurementTracker") << "qualityFlags = " << qualityFlags;
381  unsigned int on = 0, tot = 0, badrocs = 0;
382  for (std::vector<TkPixelMeasurementDet>::iterator i=thePixelDets.begin();
383  i!=thePixelDets.end(); i++) {
384  uint32_t detid = ((*i).geomDet().geographicalId()).rawId();
385  if (qualityFlags & BadModules) {
386  bool isOn = quality->IsModuleUsable(detid);
387  (i)->setActive(isOn);
388  tot++; on += (unsigned int) isOn;
389  if (qualityDebugFlags & BadModules) {
390  edm::LogInfo("MeasurementTracker")<< "MeasurementTrackerImpl::initializePixelStatus : detid " << detid << " is " << (isOn ? "on" : "off");
391  }
392  } else {
393  (i)->setActive(true);
394  }
395  if ((qualityFlags & BadROCs) && (quality->getBadRocs(detid) != 0)) {
396  std::vector<LocalPoint> badROCs = quality->getBadRocPositions(detid, *theTrackerGeom, pixelCabling);
397  badrocs += badROCs.size();
398  (i)->setBadRocPositions(badROCs);
399  } else {
400  (i)->clearBadRocPositions();
401  }
402  }
403  if (qualityDebugFlags & BadModules) {
404  edm::LogInfo("MeasurementTracker PixelModuleStatus") <<
405  " Total modules: " << tot << ", active " << on <<", inactive " << (tot - on);
406  }
407  if (qualityDebugFlags & BadROCs) {
408  edm::LogInfo("MeasurementTracker PixelROCStatus") << " Total of bad ROCs: " << badrocs ;
409  }
410  } else {
411  for (std::vector<TkPixelMeasurementDet>::iterator i=thePixelDets.begin();
412  i!=thePixelDets.end(); i++) {
413  (i)->setActive(true); // module ON
414  }
415  }
416 }
417 
const GeomDetUnit * lowerDet() const
Definition: StackGeomDet.h:20
virtual char const * what() const
Definition: Exception.cc:141
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
const GeomDetEnumerators::SubDetector geomDetSubDetector(int subdet) const
short getBadFibers(const uint32_t &detid) const
void init(const MeasurementDet *monoDet, const MeasurementDet *stereoDet)
void addStripDet(const GeomDet *gd)
void addStackDet(const StackGeomDet *gd)
unsigned int id(int i) const
std::vector< TkStripMeasurementDet > theStripDets
const GeomDetUnit * monoDet() const
Definition: GluedGeomDet.h:20
const MeasurementDet * findDet(const DetId &id) const
const DetContainer & dets() const
Returm a vector of all GeomDet (including all GeomDetUnits)
std::vector< TkStackMeasurementDet > theStackDets
StMeasurementConditionSet theStDetConditions
std::vector< unsigned int >::const_iterator ContainerIterator
void initializeStripStatus(const SiStripQuality *stripQuality, int qualityFlags, int qualityDebugFlags)
const TrackerGeometry * theTrackerGeom
void initGluedDet(TkGluedMeasurementDet &det)
bool int lh
Definition: SIMDVec.h:21
void addPixelDet(const GeomDet *gd)
const GeomDet & fastGeomDet() const
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
void init(const MeasurementDet *lowerDet, const MeasurementDet *upperDet)
std::vector< unsigned char > subId_
unsigned int id(int i) const
const SiStripRecHitMatcher * matcher() const
const DetContainer & detsTEC() const
short getBadApvs(const uint32_t &detid) const
bool IsModuleUsable(const uint32_t &detid) const
std::vector< TkPixelMeasurementDet > thePixelDets
void initializePixelStatus(const SiPixelQuality *stripQuality, const SiPixelFedCabling *pixelCabling, int qualityFlags, int qualityDebugFlags)
const std::vector< LocalPoint > getBadRocPositions(const uint32_t &detid, const TrackerGeometry &theTracker, const SiPixelFedCabling *map) const
void setActive(int i, bool active)
Turn on/off the module for reconstruction, for the full run or lumi (using info from DB...
const GluedGeomDet & specificGeomDet() const
std::vector< BadStripBlock > & getBadStripBlocks(int i)
void addDets(const TrackingGeometry::DetContainer &dets, bool subIsPixel)
void initStMeasurementConditionSet(std::vector< TkStripMeasurementDet > &stripDets)
const DetContainer & detsPXB() const
int j
Definition: DBlmapReader.cc:9
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:79
const StripClusterParameterEstimator * stripCPE() const
virtual bool isLeaf() const
is a Unit
Definition: GeomDet.h:85
const edm::ParameterSet & pset_
bool IsModuleUsable(const uint32_t &detid) const
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
std::vector< int > totalStrips_
const DetContainer & detsTIB() const
MeasurementTrackerImpl(const edm::ParameterSet &conf, const PixelClusterParameterEstimator *pixelCPE, const StripClusterParameterEstimator *stripCPE, const SiStripRecHitMatcher *hitMatcher, const TrackerGeometry *trackerGeom, const GeometricSearchTracker *geometricSearchTracker, const SiStripQuality *stripQuality, int stripQualityFlags, int stripQualityDebugFlags, const SiPixelQuality *pixelQuality, const SiPixelFedCabling *pixelCabling, int pixelQualityFlags, int pixelQualityDebugFlags)
Detector identifier class for the strip tracker.
Definition: SiStripDetId.h:17
void setMaskBad128StripBlocks(bool maskThem)
std::vector< unsigned int > id_
void addGluedDet(const GluedGeomDet *gd)
std::vector< unsigned int > id_
std::vector< TkGluedMeasurementDet > theGluedDets
bool isTrackerPixel(const GeomDetEnumerators::SubDetector m)
short getBadRocs(const uint32_t &detid) const
PxMeasurementConditionSet thePxDetConditions
const Range getRange(const uint32_t detID) const
std::pair< ContainerIterator, ContainerIterator > Range
const GeomDetUnit * upperDet() const
Definition: StackGeomDet.h:21
const DetContainer & detsPXF() const
const DetContainer & detsTOB() const
const StackGeomDet & specificGeomDet() const
const PixelClusterParameterEstimator * pixelCPE() const
void initPxMeasurementConditionSet(std::vector< TkPixelMeasurementDet > &pixelDets)
void set128StripStatus(int i, bool good, int idx=-1)
std::vector< GeomDet const * > DetContainer
tuple size
Write out results.
void initStackDet(TkStackMeasurementDet &det)
const GeomDetUnit * stereoDet() const
Definition: GluedGeomDet.h:21
data decode(const unsigned int &value) const
const DetContainer & detsTID() const