CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
OccupancyPlots.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: OccupancyPlots
4 // Class: OccupancyPlots
5 //
13 //
14 // Original Author: Andrea Venturi
15 // Created: Mon Oct 27 17:37:53 CET 2008
16 // $Id: OccupancyPlots.cc,v 1.3 2013/02/27 19:49:47 wmtan Exp $
17 //
18 //
19 
20 
21 // system include files
22 #include <memory>
23 
24 // user include files
25 
26 #include <vector>
27 #include <map>
28 #include <limits>
29 
30 #include "TProfile.h"
31 
41 
47 
52 
61 
62 //
63 // class decleration
64 //
65 
67  public:
68  explicit OccupancyPlots(const edm::ParameterSet&);
70 
71 
72 private:
73  virtual void beginJob() override ;
74  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
75  virtual void beginRun(const edm::Run&, const edm::EventSetup&) override;
76  virtual void endRun(const edm::Run&, const edm::EventSetup&) override;
77  virtual void endJob() override ;
78 
79  // ----------member data ---------------------------
80 
81  std::vector<edm::InputTag> m_multiplicityMaps;
82  std::vector<edm::InputTag> m_occupancyMaps;
84 
86  std::map<unsigned int,DetIdSelector> m_wantedsubdets;
87 
88  TProfile** m_avemultiplicity;
89  TProfile** m_aveoccupancy;
90 
93 
94  TProfile** m_averadius;
95  TProfile** m_avez;
96  TProfile** m_zavedr;
97  TProfile** m_zavedz;
98  TProfile** m_zavedrphi;
99  TProfile** m_yavedr;
100  TProfile** m_yavedz;
101  TProfile** m_yavedrphi;
102  TProfile** m_xavedr;
103  TProfile** m_xavedz;
104  TProfile** m_xavedrphi;
105 
106 
107 };
108 
109 //
110 // constants, enums and typedefs
111 //
112 
113 //
114 // static data member definitions
115 //
116 
117 //
118 // constructors and destructor
119 //
121  m_multiplicityMaps(iConfig.getParameter<std::vector<edm::InputTag> >("multiplicityMaps")),
122  m_occupancyMaps(iConfig.getParameter<std::vector<edm::InputTag> >("occupancyMaps")),
123  m_fp(iConfig.getUntrackedParameter<edm::FileInPath>("file",edm::FileInPath("CalibTracker/SiPixelESProducers/data/PixelSkimmedGeometry.txt"))),
124  m_rhm(), m_wantedsubdets()
125 {
126  //now do what ever initialization is needed
127 
128  m_avemultiplicity = m_rhm.makeTProfile("avemult","Average Multiplicty",6000,0.5,6000.5);
129  m_aveoccupancy = m_rhm.makeTProfile("aveoccu","Average Occupancy",6000,0.5,6000.5);
130 
131  m_nchannels_ideal = m_rhm.makeTH1F("nchannels_ideal","Number of channels (ideal)",6000,0.5,6000.5);
132  m_nchannels_real = m_rhm.makeTH1F("nchannels_real","Number of channels (real)",6000,0.5,6000.5);
133 
134  m_averadius = m_rhm.makeTProfile("averadius","Average Module Radius",6000,0.5,6000.5);
135  m_avez = m_rhm.makeTProfile("avez","Average Module z coordinate",6000,0.5,6000.5);
136 
137  m_zavedr = m_rhm.makeTProfile("zavedr","Average z unit vector dr",6000,0.5,6000.5);
138  m_zavedz = m_rhm.makeTProfile("zavedz","Average z unit vector dz",6000,0.5,6000.5);
139  m_zavedrphi = m_rhm.makeTProfile("zavedrphi","Average z unit vector drphi",6000,0.5,6000.5);
140  m_xavedr = m_rhm.makeTProfile("xavedr","Average x unit vector dr",6000,0.5,6000.5);
141  m_xavedz = m_rhm.makeTProfile("xavedz","Average x unit vctor dz",6000,0.5,6000.5);
142  m_xavedrphi = m_rhm.makeTProfile("xavedrphi","Average Module x unit vector drphi",6000,0.5,6000.5);
143  m_yavedr = m_rhm.makeTProfile("yavedr","Average y unit vector dr",6000,0.5,6000.5);
144  m_yavedz = m_rhm.makeTProfile("yavedz","Average y unit vector dz",6000,0.5,6000.5);
145  m_yavedrphi = m_rhm.makeTProfile("yavedrphi","Average y unit vector drphi",6000,0.5,6000.5);
146 
147  std::vector<edm::ParameterSet> wantedsubdets_ps = iConfig.getParameter<std::vector<edm::ParameterSet> >("wantedSubDets");
148 
149  for(std::vector<edm::ParameterSet>::const_iterator wsdps = wantedsubdets_ps.begin();wsdps!=wantedsubdets_ps.end();++wsdps) {
150 
151  unsigned int detsel = wsdps->getParameter<unsigned int>("detSelection");
152  std::vector<std::string> selstr = wsdps->getUntrackedParameter<std::vector<std::string> >("selection");
153  m_wantedsubdets[detsel]=DetIdSelector(selstr);
154 
155  }
156 
157 
158 }
159 
160 
162 {
163 
164  // do anything here that needs to be done at desctruction time
165  // (e.g. close files, deallocate resources etc.)
166 
167 }
168 
169 
170 //
171 // member functions
172 //
173 
174 // ------------ method called to for each event ------------
175 void
177 {
178  using namespace edm;
179 
180 
181  for(std::vector<edm::InputTag>::const_iterator map = m_multiplicityMaps.begin();map!=m_multiplicityMaps.end();++map) {
182 
184  iEvent.getByLabel(*map,mults);
185 
186  for(std::map<unsigned int,int>::const_iterator mult=mults->begin();mult!=mults->end();mult++) {
187  if(m_avemultiplicity && *m_avemultiplicity) (*m_avemultiplicity)->Fill(mult->first,mult->second);
188  }
189  }
190 
191 
192 
193  for(std::vector<edm::InputTag>::const_iterator map = m_occupancyMaps.begin();map!=m_occupancyMaps.end();++map) {
194 
196  iEvent.getByLabel(*map,occus);
197 
198  for(std::map<unsigned int,int>::const_iterator occu=occus->begin();occu!=occus->end();occu++) {
199  if(m_aveoccupancy && *m_aveoccupancy) (*m_aveoccupancy)->Fill(occu->first,occu->second);
200  }
201  }
202 
203 }
204 
205 
206 // ------------ method called once each job just before starting event loop ------------
207 void
209 {
210 
211 }
212 
213 void
214 OccupancyPlots::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
215 
216  m_rhm.beginRun(iRun);
217 
218 }
219 
220 void
221 OccupancyPlots::endRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
222 
223 
224  // edm::ESHandle<GlobalTrackingGeometry> trkgeo;
225  // iSetup.get<GlobalTrackingGeometryRecord>().get("",trkgeo);
227  iSetup.get<TrackerDigiGeometryRecord>().get("",trkgeo);
228 
229  const Local2DPoint center(0.,0.);
230  const Local3DPoint locz(0.,0.,1.);
231  const Local3DPoint locx(1.,0.,0.);
232  const Local3DPoint locy(0.,1.,0.);
233  const GlobalPoint origin(0.,0.,0.);
234 
235  TrackingGeometry::DetIdContainer detunits = trkgeo->detUnitIds();
236 
237  for(TrackingGeometry::DetIdContainer::const_iterator det = detunits.begin(); det!=detunits.end(); ++det) {
238 
239  if(det->det()!=DetId::Tracker) continue;
240 
241  edm::LogInfo("DetIdFromGeometry") << det->rawId();
242 
243  GlobalPoint position = trkgeo->idToDet(*det)->toGlobal(center);
244  GlobalPoint zpos = trkgeo->idToDet(*det)->toGlobal(locz);
245  GlobalPoint xpos = trkgeo->idToDet(*det)->toGlobal(locx);
246  GlobalPoint ypos = trkgeo->idToDet(*det)->toGlobal(locy);
247  GlobalVector posvect = position - origin;
248  GlobalVector dz = zpos - position;
249  GlobalVector dx = xpos - position;
250  GlobalVector dy = ypos - position;
251 
252  double dzdr = posvect.perp()>0 ? (dz.x()*posvect.x()+dz.y()*posvect.y())/posvect.perp() : 0. ;
253  double dxdr = posvect.perp()>0 ? (dx.x()*posvect.x()+dx.y()*posvect.y())/posvect.perp() : 0. ;
254  double dydr = posvect.perp()>0 ? (dy.x()*posvect.x()+dy.y()*posvect.y())/posvect.perp() : 0. ;
255 
256  double dzdrphi = posvect.perp()>0 ? (dz.y()*posvect.x()-dz.x()*posvect.y())/posvect.perp() : 0. ;
257  double dxdrphi = posvect.perp()>0 ? (dx.y()*posvect.x()-dx.x()*posvect.y())/posvect.perp() : 0. ;
258  double dydrphi = posvect.perp()>0 ? (dy.y()*posvect.x()-dy.x()*posvect.y())/posvect.perp() : 0. ;
259 
260  for(std::map<unsigned int,DetIdSelector>::const_iterator sel=m_wantedsubdets.begin();sel!=m_wantedsubdets.end();++sel) {
261 
262  if(sel->second.isSelected(*det)) {
263  edm::LogInfo("SelectedDetId") << sel->first;
264  // average positions
265  if(m_averadius && *m_averadius) (*m_averadius)->Fill(sel->first,position.perp());
266  if(m_avez && *m_avez) (*m_avez)->Fill(sel->first,position.z());
267  if(m_zavedr && *m_zavedr) (*m_zavedr)->Fill(sel->first,dzdr);
268  if(m_zavedz && *m_zavedz) (*m_zavedz)->Fill(sel->first,dz.z());
269  if(m_zavedrphi && *m_zavedrphi) (*m_zavedrphi)->Fill(sel->first,dzdrphi);
270  if(m_xavedr && *m_xavedr) (*m_xavedr)->Fill(sel->first,dxdr);
271  if(m_xavedz && *m_xavedz) (*m_xavedz)->Fill(sel->first,dx.z());
272  if(m_xavedrphi && *m_xavedrphi) (*m_xavedrphi)->Fill(sel->first,dxdrphi);
273  if(m_yavedr && *m_yavedr) (*m_yavedr)->Fill(sel->first,dydr);
274  if(m_yavedz && *m_yavedz) (*m_yavedz)->Fill(sel->first,dy.z());
275  if(m_yavedrphi && *m_yavedrphi) (*m_yavedrphi)->Fill(sel->first,dydrphi);
276  }
277  }
278  }
279 
280 
282  iSetup.get<SiStripQualityRcd>().get("",quality);
283 
284 
286 
287  const std::vector<uint32_t>& detids = reader->getAllDetIds();
288 
289  for(std::vector<uint32_t>::const_iterator detid=detids.begin();detid!=detids.end();++detid) {
290 
291  int nchannideal = reader->getNumberOfApvsAndStripLength(*detid).first*128;
292  // int nchannreal = reader->getNumberOfApvsAndStripLength(*detid).first*128;
293  int nchannreal = 0;
294  for(int strip = 0; strip < nchannideal; ++strip) {
295  if(!quality->IsStripBad(*detid,strip)) ++nchannreal;
296  }
297 
298 
299  for(std::map<unsigned int,DetIdSelector>::const_iterator sel=m_wantedsubdets.begin();sel!=m_wantedsubdets.end();++sel) {
300 
301  if(sel->second.isSelected(*detid)) {
302  if(m_nchannels_ideal && *m_nchannels_ideal) (*m_nchannels_ideal)->Fill(sel->first,nchannideal);
303  if(m_nchannels_real && *m_nchannels_real) (*m_nchannels_real)->Fill(sel->first,nchannreal);
304  }
305  }
306 
307  }
308 
309 
311  iSetup.get<SiPixelQualityRcd>().get("",pxlquality);
312 
313 
315 
316  const std::vector<uint32_t>& pxldetids = pxlreader.getAllDetIds();
317 
318  for(std::vector<uint32_t>::const_iterator detid=pxldetids.begin();detid!=pxldetids.end();++detid) {
319 
320  int nchannideal = pxlreader.getDetUnitDimensions(*detid).first*pxlreader.getDetUnitDimensions(*detid).second;
321  int nchannreal = 0;
322  if(!pxlquality->IsModuleBad(*detid)) {
323  nchannreal = pxlreader.getDetUnitDimensions(*detid).first*pxlreader.getDetUnitDimensions(*detid).second;
324  }
325  /*
326  int nchannreal = 0;
327  for(int strip = 0; strip < nchannideal; ++strip) {
328  if(!quality->IsStripBad(*detid,strip)) ++nchannreal;
329  }
330  */
331 
332  for(std::map<unsigned int,DetIdSelector>::const_iterator sel=m_wantedsubdets.begin();sel!=m_wantedsubdets.end();++sel) {
333 
334  if(sel->second.isSelected(*detid)) {
335  if(m_nchannels_ideal && *m_nchannels_ideal) (*m_nchannels_ideal)->Fill(sel->first,nchannideal);
336  if(m_nchannels_real && *m_nchannels_real) (*m_nchannels_real)->Fill(sel->first,nchannreal);
337  }
338  }
339 
340  }
341 
342 }
343 // ------------ method called once each job just after ending the event loop ------------
344 void
346 }
347 //define this as a plug-in
OccupancyPlots(const edm::ParameterSet &)
T getParameter(std::string const &) const
TProfile ** m_zavedrphi
TProfile ** m_xavedz
T perp() const
Definition: PV3DBase.h:72
const std::vector< uint32_t > & getAllDetIds() const
TH1F ** m_nchannels_ideal
const std::pair< unsigned short, double > getNumberOfApvsAndStripLength(uint32_t detId) const
virtual void beginRun(const edm::Run &, const edm::EventSetup &) override
std::vector< edm::InputTag > m_multiplicityMaps
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
T y() const
Definition: PV3DBase.h:63
TProfile ** m_zavedr
virtual void beginJob() override
RunHistogramManager m_rhm
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
TH1F ** m_nchannels_real
std::map< unsigned int, DetIdSelector > m_wantedsubdets
TH1F ** makeTH1F(const char *name, const char *title, const unsigned int nbinx, const double xmin, const double xmax)
int iEvent
Definition: GenABIO.cc:243
const std::vector< uint32_t > & getAllDetIds() const
TProfile ** m_aveoccupancy
TProfile ** m_averadius
T z() const
Definition: PV3DBase.h:64
TProfile ** m_avez
TProfile ** makeTProfile(const char *name, const char *title, const unsigned int nbinx, const double xmin, const double xmax)
std::vector< edm::InputTag > m_occupancyMaps
TProfile ** m_xavedr
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
TProfile ** m_yavedr
TProfile ** m_yavedz
TProfile ** m_avemultiplicity
TProfile ** m_zavedz
const T & get() const
Definition: EventSetup.h:55
void beginRun(const edm::Run &iRun)
TProfile ** m_yavedrphi
edm::FileInPath m_fp
std::string fullPath() const
Definition: FileInPath.cc:171
T x() const
Definition: PV3DBase.h:62
virtual void endJob() override
virtual void endRun(const edm::Run &, const edm::EventSetup &) override
Definition: Run.h:41
TProfile ** m_xavedrphi
std::vector< DetId > DetIdContainer
virtual void analyze(const edm::Event &, const edm::EventSetup &) override