CMS 3D CMS Logo

SiPixelDynamicInefficiencyReader.cc
Go to the documentation of this file.
1 // system include files
2 #include <cstdio>
3 #include <iostream>
4 #include <sys/time.h>
5 
6 // user include files
26 
27 //
28 //
29 // class decleration
30 //
32 public:
35 
36  void analyze(const edm::Event&, const edm::EventSetup&) override;
37 
38 private:
42 
43  const bool printdebug_;
44  double thePixelEfficiency[20]; // Single pixel effciency
45  double thePixelColEfficiency[20]; // Column effciency
46  double thePixelChipEfficiency[20]; // ROC efficiency
47  std::vector<double> theLadderEfficiency_BPix[20]; // Ladder efficiency
48  std::vector<double> theModuleEfficiency_BPix[20]; // Module efficiency
49  std::vector<double> thePUEfficiency[20]; // Instlumi dependent efficiency
50  double theInnerEfficiency_FPix[20]; // Fpix inner module efficiency
51  double theOuterEfficiency_FPix[20]; // Fpix outer module efficiency
52 };
53 
54 using namespace cms;
55 
57  : tkGeomToken(esConsumes()),
58  tkTopoToken(esConsumes()),
59  dynIneffToken(esConsumes()),
60  printdebug_(iConfig.getUntrackedParameter<bool>("printDebug", false)) {
61  //Load factors from config file, copied from SimTracker/SiPixelDigitizer/plugins/SiPixelDigitizerAlgorithm.cc
62  int i = 0;
63  thePixelColEfficiency[i++] = iConfig.getParameter<double>("thePixelColEfficiency_BPix1");
64  thePixelColEfficiency[i++] = iConfig.getParameter<double>("thePixelColEfficiency_BPix2");
65  thePixelColEfficiency[i++] = iConfig.getParameter<double>("thePixelColEfficiency_BPix3");
66  i = 0;
67  thePixelEfficiency[i++] = iConfig.getParameter<double>("thePixelEfficiency_BPix1");
68  thePixelEfficiency[i++] = iConfig.getParameter<double>("thePixelEfficiency_BPix2");
69  thePixelEfficiency[i++] = iConfig.getParameter<double>("thePixelEfficiency_BPix3");
70  i = 0;
71  thePixelChipEfficiency[i++] = iConfig.getParameter<double>("thePixelChipEfficiency_BPix1");
72  thePixelChipEfficiency[i++] = iConfig.getParameter<double>("thePixelChipEfficiency_BPix2");
73  thePixelChipEfficiency[i++] = iConfig.getParameter<double>("thePixelChipEfficiency_BPix3");
74  i = 0;
75  theLadderEfficiency_BPix[i++] = iConfig.getParameter<std::vector<double> >("theLadderEfficiency_BPix1");
76  theLadderEfficiency_BPix[i++] = iConfig.getParameter<std::vector<double> >("theLadderEfficiency_BPix2");
77  theLadderEfficiency_BPix[i++] = iConfig.getParameter<std::vector<double> >("theLadderEfficiency_BPix3");
78  if ((theLadderEfficiency_BPix[0].size() != 20) || (theLadderEfficiency_BPix[1].size() != 32) ||
79  (theLadderEfficiency_BPix[2].size() != 44))
80  throw cms::Exception("Configuration") << "Wrong ladder number in efficiency config!";
81  //
82  i = 0;
83  theModuleEfficiency_BPix[i++] = iConfig.getParameter<std::vector<double> >("theModuleEfficiency_BPix1");
84  theModuleEfficiency_BPix[i++] = iConfig.getParameter<std::vector<double> >("theModuleEfficiency_BPix2");
85  theModuleEfficiency_BPix[i++] = iConfig.getParameter<std::vector<double> >("theModuleEfficiency_BPix3");
86  if ((theModuleEfficiency_BPix[0].size() != 4) || (theModuleEfficiency_BPix[1].size() != 4) ||
87  (theModuleEfficiency_BPix[2].size() != 4))
88  throw cms::Exception("Configuration") << "Wrong module number in efficiency config!";
89  //
90  i = 0;
91  thePUEfficiency[i++] = iConfig.getParameter<std::vector<double> >("thePUEfficiency_BPix1");
92  thePUEfficiency[i++] = iConfig.getParameter<std::vector<double> >("thePUEfficiency_BPix2");
93  thePUEfficiency[i++] = iConfig.getParameter<std::vector<double> >("thePUEfficiency_BPix3");
94  i = 3;
95  thePixelColEfficiency[i++] = iConfig.getParameter<double>("thePixelColEfficiency_FPix1");
96  thePixelColEfficiency[i++] = iConfig.getParameter<double>("thePixelColEfficiency_FPix2");
97  i = 3;
98  thePixelEfficiency[i++] = iConfig.getParameter<double>("thePixelEfficiency_FPix1");
99  thePixelEfficiency[i++] = iConfig.getParameter<double>("thePixelEfficiency_FPix2");
100  i = 3;
101  thePixelChipEfficiency[i++] = iConfig.getParameter<double>("thePixelChipEfficiency_FPix1");
102  thePixelChipEfficiency[i++] = iConfig.getParameter<double>("thePixelChipEfficiency_FPix2");
103  //FPix Dynamic Inefficiency
104  i = 3;
105  theInnerEfficiency_FPix[i++] = iConfig.getParameter<double>("theInnerEfficiency_FPix1");
106  theInnerEfficiency_FPix[i++] = iConfig.getParameter<double>("theInnerEfficiency_FPix2");
107  i = 3;
108  theOuterEfficiency_FPix[i++] = iConfig.getParameter<double>("theOuterEfficiency_FPix1");
109  theOuterEfficiency_FPix[i++] = iConfig.getParameter<double>("theOuterEfficiency_FPix2");
110  i = 3;
111  thePUEfficiency[i++] = iConfig.getParameter<std::vector<double> >("thePUEfficiency_FPix_Inner");
112  thePUEfficiency[i++] = iConfig.getParameter<std::vector<double> >("thePUEfficiency_FPix_Outer");
113 }
114 
116 
118  const SiPixelDynamicInefficiency* SiPixelDynamicInefficiency_ = &iSetup.getData(dynIneffToken);
119  edm::LogInfo("SiPixelDynamicInefficiencyReader")
120  << "[SiPixelDynamicInefficiencyReader::analyze] End Reading SiPixelDynamicInefficiency" << std::endl;
121 
122  std::map<unsigned int, double> map_pixelgeomfactor = SiPixelDynamicInefficiency_->getPixelGeomFactors();
123  std::map<unsigned int, double> map_colgeomfactor = SiPixelDynamicInefficiency_->getColGeomFactors();
124  std::map<unsigned int, double> map_chipgeomfactor = SiPixelDynamicInefficiency_->getChipGeomFactors();
125  std::map<unsigned int, std::vector<double> > map_pufactor = SiPixelDynamicInefficiency_->getPUFactors();
126  std::map<unsigned int, double>::const_iterator it_pixelgeom;
127  std::map<unsigned int, double>::const_iterator it_colgeom;
128  std::map<unsigned int, double>::const_iterator it_chipgeom;
129  std::map<unsigned int, std::vector<double> >::const_iterator it_pu;
130 
131  edm::LogPrint("SiPixelDynamicInefficiencyReader") << "Printing out DB content:" << std::endl;
132  for (it_pixelgeom = map_pixelgeomfactor.begin(); it_pixelgeom != map_pixelgeomfactor.end(); it_pixelgeom++) {
133  printf("pixelgeom detid %x\tfactor %f\n", it_pixelgeom->first, it_pixelgeom->second);
134  }
135  for (it_colgeom = map_colgeomfactor.begin(); it_colgeom != map_colgeomfactor.end(); it_colgeom++) {
136  printf("colgeom detid %x\tfactor %f\n", it_colgeom->first, it_colgeom->second);
137  }
138  for (it_chipgeom = map_chipgeomfactor.begin(); it_chipgeom != map_chipgeomfactor.end(); it_chipgeom++) {
139  printf("chipgeom detid %x\tfactor %f\n", it_chipgeom->first, it_chipgeom->second);
140  }
141  for (it_pu = map_pufactor.begin(); it_pu != map_pufactor.end(); it_pu++) {
142  printf("pu detid %x\t", it_pu->first);
143  edm::LogPrint("SiPixelDynamicInefficiencyReader") << " Size of vector " << it_pu->second.size() << " elements:";
144  if (it_pu->second.size() > 1) {
145  for (unsigned int i = 0; i < it_pu->second.size(); i++) {
146  edm::LogPrint("SiPixelDynamicInefficiencyReader") << " " << it_pu->second.at(i);
147  }
148  edm::LogPrint("SiPixelDynamicInefficiencyReader") << std::endl;
149  } else {
150  edm::LogPrint("SiPixelDynamicInefficiencyReader") << " " << it_pu->second.at(0) << std::endl;
151  }
152  }
153  std::vector<uint32_t> detIdmasks = SiPixelDynamicInefficiency_->getDetIdmasks();
154  for (unsigned int i = 0; i < detIdmasks.size(); i++)
155  printf("DetId Mask: %x\t\n", detIdmasks.at(i));
156  double theInstLumiScaleFactor = SiPixelDynamicInefficiency_->gettheInstLumiScaleFactor_();
157  edm::LogPrint("SiPixelDynamicInefficiencyReader") << "theInstLumiScaleFactor " << theInstLumiScaleFactor << std::endl;
158 
159  //Comparing DB factors to config factors
160  edm::LogPrint("SiPixelDynamicInefficiencyReader")
161  << "\nCalculating factors/module and comparing it to config file factors...\n"
162  << std::endl;
163 
164  const TrackerTopology* const tTopo = &iSetup.getData(tkTopoToken);
165  const TrackerGeometry* pDD = &iSetup.getData(tkGeomToken);
166  edm::LogInfo("SiPixelDynamicInefficiency (old)")
167  << " There are " << pDD->detUnits().size() << " detectors (old)" << std::endl;
168 
169  const size_t pu_det = map_pufactor.size();
170  double _pu_scale[pu_det];
171  double _pu_scale_conf[pu_det];
172  unsigned int match = 0, mismatch = 0, pu_match = 0, pu_mismatch = 0;
173 
174  for (const auto& it : pDD->detUnits()) {
175  if (dynamic_cast<PixelGeomDetUnit const*>(it) == nullptr)
176  continue;
177  const DetId detid = it->geographicalId();
178  double scale_db = 1;
179 
180  //Geom DB factor calculation
181  for (it_colgeom = map_colgeomfactor.begin(); it_colgeom != map_colgeomfactor.end(); ++it_colgeom) {
182  const DetId mapid = DetId(it_colgeom->first);
183  if (mapid.subdetId() != detid.subdetId())
184  continue;
185  size_t __i = 0;
186  for (; __i < detIdmasks.size(); __i++) {
187  DetId maskid = DetId(detIdmasks.at(__i));
188  if (maskid.subdetId() != mapid.subdetId())
189  continue;
190  if ((detid.rawId() & maskid.rawId()) != (mapid.rawId() & maskid.rawId()) &&
191  (mapid.rawId() & maskid.rawId()) != DetId(mapid.det(), mapid.subdetId()).rawId())
192  break;
193  }
194  if (__i != detIdmasks.size())
195  continue;
196  scale_db *= it_colgeom->second;
197  }
198 
199  //DB PU factor calculation
200  it_pu = map_pufactor.begin();
201  for (unsigned int pu_iterator = 0; pu_iterator < pu_det; it_pu++, pu_iterator++) {
202  const DetId mapid = DetId(it_pu->first);
203  if (mapid.subdetId() != detid.subdetId())
204  continue;
205  size_t __i = 0;
206  for (; __i < detIdmasks.size(); __i++) {
207  DetId maskid = DetId(detIdmasks.at(__i));
208  if (maskid.subdetId() != mapid.subdetId())
209  continue;
210  if ((detid.rawId() & maskid.rawId()) != (mapid.rawId() & maskid.rawId()) &&
211  (mapid.rawId() & maskid.rawId()) != DetId(mapid.det(), mapid.subdetId()).rawId())
212  break;
213  }
214  if (__i != detIdmasks.size())
215  continue;
216  double instlumi = 30 * theInstLumiScaleFactor;
217  double instlumi_pow = 1.;
218  _pu_scale[pu_iterator] = 0;
219  for (size_t j = 0; j < it_pu->second.size(); j++) {
220  _pu_scale[pu_iterator] += instlumi_pow * it_pu->second[j];
221  instlumi_pow *= instlumi;
222  }
223  }
224 
225  //Config PU factor calculation
226  for (size_t i = 0; i < pu_det; i++) {
227  double instlumi = 30 * theInstLumiScaleFactor;
228  double instlumi_pow = 1.;
229  _pu_scale_conf[i] = 0;
230  for (size_t j = 0; j < thePUEfficiency[i].size(); j++) {
231  _pu_scale_conf[i] += instlumi_pow * thePUEfficiency[i][j];
232  instlumi_pow *= instlumi;
233  }
234  }
235 
236  //Config geom factor calculation
237  double columnEfficiency = 1;
238  if (detid.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel)) {
239  int layerIndex = tTopo->pxbLayer(detid.rawId());
240  columnEfficiency = thePixelColEfficiency[layerIndex - 1];
241  int ladder = tTopo->pxbLadder(detid.rawId());
242  int module = tTopo->pxbModule(detid.rawId());
243  if (module <= 4)
244  module = 5 - module;
245  else
246  module -= 4;
247 
248  columnEfficiency *=
249  theLadderEfficiency_BPix[layerIndex - 1][ladder - 1] * theModuleEfficiency_BPix[layerIndex - 1][module - 1];
250  }
251 
252  if (detid.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap)) {
253  unsigned int diskIndex = tTopo->layer(detid) + 3; // Use diskIndex-1 later to stay consistent with BPix
254  unsigned int panelIndex = tTopo->pxfPanel(detid);
255  unsigned int moduleIndex = tTopo->pxfModule(detid);
256  columnEfficiency = thePixelColEfficiency[diskIndex - 1];
257  if ((panelIndex == 1 && (moduleIndex == 1 || moduleIndex == 2)) ||
258  (panelIndex == 2 && moduleIndex == 1)) { //inner modules
259  columnEfficiency *= theInnerEfficiency_FPix[diskIndex - 1];
260  } else { //outer modules
261  columnEfficiency *= theOuterEfficiency_FPix[diskIndex - 1];
262  }
263  }
264 
265  if (scale_db == columnEfficiency) {
266  //printf("Config match, detid %x\tfactor %f\n",detid.rawId(),columnEfficiency);
267  match++;
268  } else {
269  //printf("Config mismatch! detid %x\t db_geom_factor %f\tconf_geom_factor %f\n",detid.rawId(),scale_db,columnEfficiency);
270  mismatch++;
271  }
272  for (unsigned int i = 0; i < pu_det; i++) {
273  if (_pu_scale[i] != 0 && _pu_scale_conf[i] != 0 && _pu_scale[i] == _pu_scale_conf[i]) {
274  //printf("Config match! detid %x\t db_pu_scale %f\tconf_pu_scale %f\n",detid.rawId(),_pu_scale[i],_pu_scale_conf[i]);
275  pu_match++;
276  break;
277  }
278  if (_pu_scale[i] != 0 && _pu_scale_conf[i] != 0 && _pu_scale[i] != _pu_scale_conf[i]) {
279  //printf("Config mismatch! detid %x\t db_pu_scale %f\tconf_pu_scale %f\n",detid.rawId(),_pu_scale[i],_pu_scale_conf[i]);
280  pu_mismatch++;
281  continue;
282  }
283  }
284  }
285  edm::LogPrint("SiPixelDynamicInefficiencyReader")
286  << match << " geom factors and " << pu_match << " pu factors matched to config file factors!\n"
287  << std::endl;
288  if (mismatch != 0)
289  edm::LogPrint("SiPixelDynamicInefficiencyReader")
290  << "ERROR! " << mismatch
291  << " geom factors mismatched to config file factors! Please change config and/or DB content!" << std::endl;
292  if (pu_mismatch != 0)
293  edm::LogPrint("SiPixelDynamicInefficiencyReader")
294  << "ERROR! " << pu_mismatch
295  << " pu_factors mismatched to config file pu_factors! Please change config and/or DB content!" << std::endl;
296 }
size
Write out results.
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
unsigned int pxbLayer(const DetId &id) const
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tkGeomToken
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
const std::map< unsigned int, double > & getPixelGeomFactors() const
unsigned int pxfModule(const DetId &id) const
const std::map< unsigned int, double > & getColGeomFactors() const
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tkTopoToken
const DetContainer & detUnits() const override
Returm a vector of all GeomDet.
unsigned int pxbLadder(const DetId &id) const
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
unsigned int layer(const DetId &id) const
const std::map< unsigned int, std::vector< double > > & getPUFactors() const
const std::vector< uint32_t > getDetIdmasks() const
const std::map< unsigned int, double > & getChipGeomFactors() const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
const double gettheInstLumiScaleFactor_() const
void analyze(const edm::Event &, const edm::EventSetup &) override
Log< level::Warning, true > LogPrint
Namespace of DDCMS conversion namespace.
unsigned int pxfPanel(const DetId &id) const
Log< level::Info, false > LogInfo
Definition: DetId.h:17
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
const edm::ESGetToken< SiPixelDynamicInefficiency, SiPixelDynamicInefficiencyRcd > dynIneffToken
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
unsigned int pxbModule(const DetId &id) const
SiPixelDynamicInefficiencyReader(const edm::ParameterSet &)