CMS 3D CMS Logo

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