CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SiPixelRecHitSource.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiPixelMonitorRecHits
4 // Class: SiPixelRecHitSource
5 //
14 //
15 // Original Author: Vincenzo Chiochia
16 // Created:
17 //
18 //
19 // Adapted by: Keith Rose
20 // For use in SiPixelMonitorClient for RecHits
21 // Updated by: Lukas Wehrli
22 // for pixel offline DQM
23 
25 // Framework
29 // DQM Framework
32 // Geometry
34 // DataFormats
41 
42 //
43 #include <cstdlib>
44 #include <iostream>
45 #include <string>
46 using namespace std;
47 using namespace edm;
48 
50  : conf_(iConfig),
51  src_(consumes<SiPixelRecHitCollection>(conf_.getParameter<edm::InputTag>("src"))),
52  trackerTopoTokenBeginRun_(esConsumes<TrackerTopology, TrackerTopologyRcd, edm::Transition::BeginRun>()),
53  trackerGeomTokenBeginRun_(esConsumes<TrackerGeometry, TrackerDigiGeometryRecord, edm::Transition::BeginRun>()),
54  saveFile(conf_.getUntrackedParameter<bool>("saveFile", false)),
55  isPIB(conf_.getUntrackedParameter<bool>("isPIB", false)),
56  slowDown(conf_.getUntrackedParameter<bool>("slowDown", false)),
57  modOn(conf_.getUntrackedParameter<bool>("modOn", true)),
58  twoDimOn(conf_.getUntrackedParameter<bool>("twoDimOn", true)),
59  reducedSet(conf_.getUntrackedParameter<bool>("reducedSet", false)),
60  ladOn(conf_.getUntrackedParameter<bool>("ladOn", false)),
61  layOn(conf_.getUntrackedParameter<bool>("layOn", false)),
62  phiOn(conf_.getUntrackedParameter<bool>("phiOn", false)),
63  ringOn(conf_.getUntrackedParameter<bool>("ringOn", false)),
64  bladeOn(conf_.getUntrackedParameter<bool>("bladeOn", false)),
65  diskOn(conf_.getUntrackedParameter<bool>("diskOn", false)),
66  isUpgrade(conf_.getUntrackedParameter<bool>("isUpgrade", false)) {
67  firstRun = true;
68  LogInfo("PixelDQM") << "SiPixelRecHitSource::SiPixelRecHitSource: Got DQM BackEnd interface" << endl;
69  topFolderName_ = conf_.getParameter<std::string>("TopFolderName");
70 }
71 
73  // do anything here that needs to be done at desctruction time
74  // (e.g. close files, deallocate resources etc.)
75  LogInfo("PixelDQM") << "SiPixelRecHitSource::~SiPixelRecHitSource: Destructor" << endl;
76  std::map<uint32_t, SiPixelRecHitModule *>::iterator struct_iter;
77  for (struct_iter = thePixelStructure.begin(); struct_iter != thePixelStructure.end(); struct_iter++) {
78  delete struct_iter->second;
79  struct_iter->second = nullptr;
80  }
81 }
82 
84  LogInfo("PixelDQM") << " SiPixelRecHitSource::beginJob - Initialisation ... " << std::endl;
85  LogInfo("PixelDQM") << "Mod/Lad/Lay/Phi " << modOn << "/" << ladOn << "/" << layOn << "/" << phiOn << std::endl;
86  LogInfo("PixelDQM") << "Blade/Disk/Ring" << bladeOn << "/" << diskOn << "/" << ringOn << std::endl;
87  LogInfo("PixelDQM") << "2DIM IS " << twoDimOn << "\n";
88 
89  if (firstRun) {
90  eventNo = 0;
91  // Build map
92  buildStructure(iSetup);
93  // Book Monitoring Elements
94  firstRun = false;
95  }
96 }
97 
99  bookMEs(iBooker, iSetup);
100 }
101 
102 //------------------------------------------------------------------
103 // Method called for every event
104 //------------------------------------------------------------------
106  eventNo++;
107  // cout << eventNo << endl;
108  // get input data
110  iEvent.getByToken(src_, recHitColl);
111 
112  std::map<uint32_t, SiPixelRecHitModule *>::iterator struct_iter;
113  for (struct_iter = thePixelStructure.begin(); struct_iter != thePixelStructure.end(); struct_iter++) {
114  uint32_t TheID = (*struct_iter).first;
115 
116  SiPixelRecHitCollection::const_iterator match = recHitColl->find(TheID);
117 
118  // if( pixelrechitRangeIteratorBegin == pixelrechitRangeIteratorEnd) {cout
119  // << "oops" << endl;}
120  float rechit_x = 0;
121  float rechit_y = 0;
122  int rechit_count = 0;
123 
124  if (match != recHitColl->end()) {
125  SiPixelRecHitCollection::DetSet pixelrechitRange = *match;
126  SiPixelRecHitCollection::DetSet::const_iterator pixelrechitRangeIteratorBegin = pixelrechitRange.begin();
127  SiPixelRecHitCollection::DetSet::const_iterator pixelrechitRangeIteratorEnd = pixelrechitRange.end();
128  SiPixelRecHitCollection::DetSet::const_iterator pixeliter = pixelrechitRangeIteratorBegin;
129 
130  for (; pixeliter != pixelrechitRangeIteratorEnd; pixeliter++) {
131  rechit_count++;
132  // cout << TheID << endl;
133  SiPixelRecHit::ClusterRef const &clust = pixeliter->cluster();
134  int sizeX = (*clust).sizeX();
135  // cout << sizeX << endl;
136  int sizeY = (*clust).sizeY();
137  // cout << sizeY << endl;
138  LocalPoint lp = pixeliter->localPosition();
139  rechit_x = lp.x();
140  rechit_y = lp.y();
141 
142  LocalError lerr = pixeliter->localPositionError();
143  float lerr_x = sqrt(lerr.xx());
144  float lerr_y = sqrt(lerr.yy());
145  // std::cout << "errors " << lerr_x << " " << lerr_y << std::endl;
146  (*struct_iter)
147  .second->fill(rechit_x,
148  rechit_y,
149  sizeX,
150  sizeY,
151  lerr_x,
152  lerr_y,
153  modOn,
154  ladOn,
155  layOn,
156  phiOn,
157  bladeOn,
158  diskOn,
159  ringOn,
160  twoDimOn,
161  reducedSet);
162  }
163  }
164  if (rechit_count > 0)
165  (*struct_iter).second->nfill(rechit_count, modOn, ladOn, layOn, phiOn, bladeOn, diskOn, ringOn);
166  }
167 
168  // slow down...
169  if (slowDown)
170  usleep(10000);
171 }
172 
173 //------------------------------------------------------------------
174 // Build data structure
175 //------------------------------------------------------------------
177  LogInfo("PixelDQM") << " SiPixelRecHitSource::buildStructure";
178 
180 
182  const TrackerTopology *pTT = tTopoHandle.product();
183 
184  LogVerbatim("PixelDQM") << " *** Geometry node for TrackerGeom is " << &(*pDD) << std::endl;
185  LogVerbatim("PixelDQM") << " *** I have " << pDD->dets().size() << " detectors" << std::endl;
186  LogVerbatim("PixelDQM") << " *** I have " << pDD->detTypes().size() << " types" << std::endl;
187 
188  for (TrackerGeometry::DetContainer::const_iterator it = pDD->dets().begin(); it != pDD->dets().end(); it++) {
189  if (dynamic_cast<PixelGeomDetUnit const *>((*it)) != nullptr) {
190  DetId detId = (*it)->geographicalId();
191 
192  if ((detId.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel)) ||
193  (detId.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap))) {
194  uint32_t id = detId();
195 
196  if (detId.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel)) {
197  if (isPIB)
198  continue;
199  LogDebug("PixelDQM") << " ---> Adding Barrel Module " << detId.rawId() << endl;
200  SiPixelRecHitModule *theModule = new SiPixelRecHitModule(id);
201  thePixelStructure.insert(pair<uint32_t, SiPixelRecHitModule *>(id, theModule));
202 
203  } else if ((detId.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap))) {
204  LogDebug("PixelDQM") << " ---> Adding Endcap Module " << detId.rawId() << endl;
205 
207  int disk = PixelEndcapName(DetId(id), pTT, isUpgrade).diskName();
208  int blade = PixelEndcapName(DetId(id), pTT, isUpgrade).bladeName();
209  int panel = PixelEndcapName(DetId(id), pTT, isUpgrade).pannelName();
211 
212  char sside[80];
213  sprintf(sside, "HalfCylinder_%i", side);
214  char sdisk[80];
215  sprintf(sdisk, "Disk_%i", disk);
216  char sblade[80];
217  sprintf(sblade, "Blade_%02i", blade);
218  char spanel[80];
219  sprintf(spanel, "Panel_%i", panel);
220  char smodule[80];
221  sprintf(smodule, "Module_%i", module);
222  std::string side_str = sside;
223  std::string disk_str = sdisk;
224  bool mask = side_str.find("HalfCylinder_1") != string::npos ||
225  side_str.find("HalfCylinder_2") != string::npos ||
226  side_str.find("HalfCylinder_4") != string::npos || disk_str.find("Disk_2") != string::npos;
227  if (isPIB && mask)
228  continue;
229 
230  SiPixelRecHitModule *theModule = new SiPixelRecHitModule(id);
231  thePixelStructure.insert(pair<uint32_t, SiPixelRecHitModule *>(id, theModule));
232  }
233  }
234  }
235  } // FOR_LOOP
236 
237  LogInfo("PixelDQM") << " *** Pixel Structure Size " << thePixelStructure.size() << endl;
238 }
239 //------------------------------------------------------------------
240 // Book MEs
241 //------------------------------------------------------------------
243  std::map<uint32_t, SiPixelRecHitModule *>::iterator struct_iter;
244 
245  SiPixelFolderOrganizer theSiPixelFolder(false);
246 
248  const TrackerTopology *pTT = tTopoHandle.product();
249 
250  for (struct_iter = thePixelStructure.begin(); struct_iter != thePixelStructure.end(); struct_iter++) {
252  if (modOn) {
253  if (theSiPixelFolder.setModuleFolder(iBooker, (*struct_iter).first, 0, isUpgrade)) {
254  (*struct_iter).second->book(conf_, iBooker, pTT, 0, twoDimOn, reducedSet, isUpgrade);
255  } else {
256  if (!isPIB)
257  throw cms::Exception("LogicError") << "[SiPixelDigiSource::bookMEs] Creation of DQM folder failed";
258  }
259  }
260  if (ladOn) {
261  if (theSiPixelFolder.setModuleFolder(iBooker, (*struct_iter).first, 1, isUpgrade)) {
262  (*struct_iter).second->book(conf_, iBooker, pTT, 1, twoDimOn, reducedSet, isUpgrade);
263  } else {
264  LogDebug("PixelDQM") << "PROBLEM WITH LADDER-FOLDER\n";
265  }
266  }
267  if (layOn) {
268  if (theSiPixelFolder.setModuleFolder(iBooker, (*struct_iter).first, 2, isUpgrade)) {
269  (*struct_iter).second->book(conf_, iBooker, pTT, 2, twoDimOn, reducedSet, isUpgrade);
270  } else {
271  LogDebug("PixelDQM") << "PROBLEM WITH LAYER-FOLDER\n";
272  }
273  }
274  if (phiOn) {
275  if (theSiPixelFolder.setModuleFolder(iBooker, (*struct_iter).first, 3, isUpgrade)) {
276  (*struct_iter).second->book(conf_, iBooker, pTT, 3, twoDimOn, reducedSet, isUpgrade);
277  } else {
278  LogDebug("PixelDQM") << "PROBLEM WITH PHI-FOLDER\n";
279  }
280  }
281  if (bladeOn) {
282  if (theSiPixelFolder.setModuleFolder(iBooker, (*struct_iter).first, 4, isUpgrade)) {
283  (*struct_iter).second->book(conf_, iBooker, pTT, 4, twoDimOn, reducedSet, isUpgrade);
284  } else {
285  LogDebug("PixelDQM") << "PROBLEM WITH BLADE-FOLDER\n";
286  }
287  }
288  if (diskOn) {
289  if (theSiPixelFolder.setModuleFolder(iBooker, (*struct_iter).first, 5, isUpgrade)) {
290  (*struct_iter).second->book(conf_, iBooker, pTT, 5, twoDimOn, reducedSet, isUpgrade);
291  } else {
292  LogDebug("PixelDQM") << "PROBLEM WITH DISK-FOLDER\n";
293  }
294  }
295  if (ringOn) {
296  if (theSiPixelFolder.setModuleFolder(iBooker, (*struct_iter).first, 6, isUpgrade)) {
297  (*struct_iter).second->book(conf_, iBooker, pTT, 6, twoDimOn, reducedSet, isUpgrade);
298  } else {
299  LogDebug("PixelDQM") << "PROBLEM WITH RING-FOLDER\n";
300  }
301  }
302  }
303 }
304 
305 // define this as a plug-in
int plaquetteName() const
plaquetteId (in pannel)
Log< level::Info, true > LogVerbatim
float xx() const
Definition: LocalError.h:22
std::map< uint32_t, SiPixelRecHitModule * > thePixelStructure
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
SiPixelRecHitSource(const edm::ParameterSet &conf)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
T y() const
Definition: PV3DBase.h:60
virtual void bookMEs(DQMStore::IBooker &, const edm::EventSetup &iSetup)
edm::ParameterSet conf_
virtual void buildStructure(edm::EventSetup const &)
void dqmBeginRun(const edm::Run &, edm::EventSetup const &) override
int bladeName() const
blade id
std::map< uint32_t, int > rechit_count
int iEvent
Definition: GenABIO.cc:224
float yy() const
Definition: LocalError.h:24
void bookHistograms(DQMStore::IBooker &, edm::Run const &, const edm::EventSetup &) override
T sqrt(T t)
Definition: SSEVec.h:19
bool setModuleFolder(const uint32_t &rawdetid=0, int type=0, bool isUpgrade=false)
Set folder name for a module or plaquette.
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
Transition
Definition: Transition.h:12
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > trackerGeomTokenBeginRun_
Log< level::Info, false > LogInfo
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
Definition: DetId.h:17
T const * product() const
Definition: ESHandle.h:86
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void analyze(const edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< SiPixelRecHitCollection > src_
iterator end()
Definition: DetSetNew.h:56
int pannelName() const
pannel id
int diskName() const
disk id
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:157
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > trackerTopoTokenBeginRun_
HalfCylinder halfCylinder() const
T x() const
Definition: PV3DBase.h:59
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
Definition: Run.h:45
tuple module
Definition: callgraph.py:69
#define LogDebug(id)
iterator begin()
Definition: DetSetNew.h:54