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 {
68  LogInfo ("PixelDQM") << "SiPixelRecHitSource::SiPixelRecHitSource: Got DQM BackEnd interface"<<endl;
69 }
70 
71 
73 {
74  // do anything here that needs to be done at desctruction time
75  // (e.g. close files, deallocate resources etc.)
76  LogInfo ("PixelDQM") << "SiPixelRecHitSource::~SiPixelRecHitSource: Destructor"<<endl;
77  std::map<uint32_t,SiPixelRecHitModule*>::iterator struct_iter;
78  for (struct_iter = thePixelStructure.begin() ; struct_iter != thePixelStructure.end() ; struct_iter++){
79  delete struct_iter->second;
80  struct_iter->second = 0;
81  }
82 }
83 
84 
86  firstRun = true;
87 }
88 
89 
91 
92  LogInfo ("PixelDQM") << " SiPixelRecHitSource::beginJob - Initialisation ... " << std::endl;
93  LogInfo ("PixelDQM") << "Mod/Lad/Lay/Phi " << modOn << "/" << ladOn << "/"
94  << layOn << "/" << phiOn << std::endl;
95  LogInfo ("PixelDQM") << "Blade/Disk/Ring" << bladeOn << "/" << diskOn << "/"
96  << ringOn << std::endl;
97  LogInfo ("PixelDQM") << "2DIM IS " << twoDimOn << "\n";
98 
99  if(firstRun){
100  eventNo = 0;
101  // Build map
102  buildStructure(iSetup);
103  // Book Monitoring Elements
104  bookMEs();
105  firstRun = false;
106  }
107 }
108 
109 
111 
112 
113  if(saveFile){
114  LogInfo ("PixelDQM") << " SiPixelRecHitSource::endJob - Saving Root File " << std::endl;
116  theDMBE->save( outputFile );
117  }
118 
119 }
120 
121 //------------------------------------------------------------------
122 // Method called for every event
123 //------------------------------------------------------------------
125 {
126  eventNo++;
127  //cout << eventNo << endl;
128  // get input data
130  iEvent.getByToken( src_, recHitColl );
131 
132  std::map<uint32_t,SiPixelRecHitModule*>::iterator struct_iter;
133  for (struct_iter = thePixelStructure.begin() ; struct_iter != thePixelStructure.end() ; struct_iter++) {
134  uint32_t TheID = (*struct_iter).first;
135 
136  SiPixelRecHitCollection::const_iterator match = recHitColl->find(TheID);
137 
138  // if( pixelrechitRangeIteratorBegin == pixelrechitRangeIteratorEnd) {cout << "oops" << endl;}
139  float rechit_x = 0;
140  float rechit_y = 0;
141  int rechit_count = 0;
142 
143  if (match != recHitColl->end()) {
144  SiPixelRecHitCollection::DetSet pixelrechitRange = *match;
145  SiPixelRecHitCollection::DetSet::const_iterator pixelrechitRangeIteratorBegin = pixelrechitRange.begin();
146  SiPixelRecHitCollection::DetSet::const_iterator pixelrechitRangeIteratorEnd = pixelrechitRange.end();
147  SiPixelRecHitCollection::DetSet::const_iterator pixeliter = pixelrechitRangeIteratorBegin;
148 
149  for ( ; pixeliter != pixelrechitRangeIteratorEnd; pixeliter++)
150  {
151 
152 
153  rechit_count++;
154  //cout << TheID << endl;
155  SiPixelRecHit::ClusterRef const& clust = pixeliter->cluster();
156  int sizeX = (*clust).sizeX();
157  //cout << sizeX << endl;
158  int sizeY = (*clust).sizeY();
159  //cout << sizeY << endl;
160  LocalPoint lp = pixeliter->localPosition();
161  rechit_x = lp.x();
162  rechit_y = lp.y();
163 
164  LocalError lerr = pixeliter->localPositionError();
165  float lerr_x = sqrt(lerr.xx());
166  float lerr_y = sqrt(lerr.yy());
167  //std::cout << "errors " << lerr_x << " " << lerr_y << std::endl;
168  //cout << "hh" << endl;
169  (*struct_iter).second->fill(rechit_x, rechit_y, sizeX, sizeY, lerr_x, lerr_y,
172  //cout << "ii" << endl;
173 
174  }
175  }
176  if(rechit_count > 0) (*struct_iter).second->nfill(rechit_count, modOn, ladOn, layOn, phiOn, bladeOn, diskOn, ringOn);
177 
178  }
179 
180  // slow down...
181  if(slowDown) usleep(10000);
182 
183 }
184 
185 //------------------------------------------------------------------
186 // Build data structure
187 //------------------------------------------------------------------
189 
190  LogInfo ("PixelDQM") <<" SiPixelRecHitSource::buildStructure" ;
192  iSetup.get<TrackerDigiGeometryRecord>().get( pDD );
193 
194  LogVerbatim ("PixelDQM") << " *** Geometry node for TrackerGeom is "<<&(*pDD)<<std::endl;
195  LogVerbatim ("PixelDQM") << " *** I have " << pDD->dets().size() <<" detectors"<<std::endl;
196  LogVerbatim ("PixelDQM") << " *** I have " << pDD->detTypes().size() <<" types"<<std::endl;
197 
198  for(TrackerGeometry::DetContainer::const_iterator it = pDD->dets().begin(); it != pDD->dets().end(); it++){
199 
200  if(dynamic_cast<PixelGeomDetUnit const *>((*it))!=0){
201 
202  DetId detId = (*it)->geographicalId();
203  // const GeomDetUnit * geoUnit = pDD->idToDetUnit( detId );
204  //const PixelGeomDetUnit * pixDet = dynamic_cast<const PixelGeomDetUnit*>(geoUnit);
205 
206 
207 
208  // SiPixelRecHitModule *theModule = new SiPixelRecHitModule(id, rechit_x, rechit_y, x_res, y_res, x_pull, y_pull);
209 
210 
211  if((detId.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel)) ||
212  (detId.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap))){
213  uint32_t id = detId();
214  SiPixelRecHitModule* theModule = new SiPixelRecHitModule(id);
215  if(detId.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel)) {
216  if(isPIB) continue;
217  LogDebug ("PixelDQM") << " ---> Adding Barrel Module " << detId.rawId() << endl;
218  thePixelStructure.insert(pair<uint32_t,SiPixelRecHitModule*> (id,theModule));
219 
220  } else if( (detId.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap)) && (!isUpgrade)) {
221  LogDebug ("PixelDQM") << " ---> Adding Endcap Module " << detId.rawId() << endl;
223  int disk = PixelEndcapName(DetId(id)).diskName();
224  int blade = PixelEndcapName(DetId(id)).bladeName();
225  int panel = PixelEndcapName(DetId(id)).pannelName();
227 
228  char sside[80]; sprintf(sside, "HalfCylinder_%i",side);
229  char sdisk[80]; sprintf(sdisk, "Disk_%i",disk);
230  char sblade[80]; sprintf(sblade, "Blade_%02i",blade);
231  char spanel[80]; sprintf(spanel, "Panel_%i",panel);
232  char smodule[80];sprintf(smodule,"Module_%i",module);
233  std::string side_str = sside;
234  std::string disk_str = sdisk;
235  bool mask = side_str.find("HalfCylinder_1")!=string::npos||
236  side_str.find("HalfCylinder_2")!=string::npos||
237  side_str.find("HalfCylinder_4")!=string::npos||
238  disk_str.find("Disk_2")!=string::npos;
239  if(isPIB && mask) continue;
240 
241  thePixelStructure.insert(pair<uint32_t,SiPixelRecHitModule*> (id,theModule));
242  } else if( (detId.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap)) && (isUpgrade)) {
243  LogDebug ("PixelDQM") << " ---> Adding Endcap Module " << detId.rawId() << endl;
245  int disk = PixelEndcapNameUpgrade(DetId(id)).diskName();
246  int blade = PixelEndcapNameUpgrade(DetId(id)).bladeName();
247  int panel = PixelEndcapNameUpgrade(DetId(id)).pannelName();
249 
250  char sside[80]; sprintf(sside, "HalfCylinder_%i",side);
251  char sdisk[80]; sprintf(sdisk, "Disk_%i",disk);
252  char sblade[80]; sprintf(sblade, "Blade_%02i",blade);
253  char spanel[80]; sprintf(spanel, "Panel_%i",panel);
254  char smodule[80];sprintf(smodule,"Module_%i",module);
255  std::string side_str = sside;
256  std::string disk_str = sdisk;
257  bool mask = side_str.find("HalfCylinder_1")!=string::npos||
258  side_str.find("HalfCylinder_2")!=string::npos||
259  side_str.find("HalfCylinder_4")!=string::npos||
260  disk_str.find("Disk_2")!=string::npos;
261  if(isPIB && mask) continue;
262 
263  thePixelStructure.insert(pair<uint32_t,SiPixelRecHitModule*> (id,theModule));
264  }//endif(isUpgrade)
265  }
266  }
267  }
268 
269  LogInfo ("PixelDQM") << " *** Pixel Structure Size " << thePixelStructure.size() << endl;
270 }
271 //------------------------------------------------------------------
272 // Book MEs
273 //------------------------------------------------------------------
275 
276  std::map<uint32_t,SiPixelRecHitModule*>::iterator struct_iter;
277 
278  SiPixelFolderOrganizer theSiPixelFolder;
279 
280  for(struct_iter = thePixelStructure.begin(); struct_iter != thePixelStructure.end(); struct_iter++){
281 
283  if(modOn){
284  if(theSiPixelFolder.setModuleFolder((*struct_iter).first,0,isUpgrade)){
285  (*struct_iter).second->book( conf_,0,twoDimOn, reducedSet, isUpgrade);
286  } else {
287  if(!isPIB) throw cms::Exception("LogicError")
288  << "[SiPixelDigiSource::bookMEs] Creation of DQM folder failed";
289  }
290  }
291  if(ladOn){
292  if(theSiPixelFolder.setModuleFolder((*struct_iter).first,1,isUpgrade)){
293  (*struct_iter).second->book( conf_,1,twoDimOn, reducedSet, isUpgrade);
294  } else {
295  LogDebug ("PixelDQM") << "PROBLEM WITH LADDER-FOLDER\n";
296  }
297  }
298  if(layOn){
299  if(theSiPixelFolder.setModuleFolder((*struct_iter).first,2,isUpgrade)){
300  (*struct_iter).second->book( conf_,2,twoDimOn, reducedSet, isUpgrade);
301  } else {
302  LogDebug ("PixelDQM") << "PROBLEM WITH LAYER-FOLDER\n";
303  }
304  }
305  if(phiOn){
306  if(theSiPixelFolder.setModuleFolder((*struct_iter).first,3,isUpgrade)){
307  (*struct_iter).second->book( conf_,3,twoDimOn, reducedSet, isUpgrade);
308  } else {
309  LogDebug ("PixelDQM") << "PROBLEM WITH PHI-FOLDER\n";
310  }
311  }
312  if(bladeOn){
313  if(theSiPixelFolder.setModuleFolder((*struct_iter).first,4,isUpgrade)){
314  (*struct_iter).second->book( conf_,4,twoDimOn, reducedSet, isUpgrade);
315  } else {
316  LogDebug ("PixelDQM") << "PROBLEM WITH BLADE-FOLDER\n";
317  }
318  }
319  if(diskOn){
320  if(theSiPixelFolder.setModuleFolder((*struct_iter).first,5,isUpgrade)){
321  (*struct_iter).second->book( conf_,5,twoDimOn, reducedSet, isUpgrade);
322  } else {
323  LogDebug ("PixelDQM") << "PROBLEM WITH DISK-FOLDER\n";
324  }
325  }
326  if(ringOn){
327  if(theSiPixelFolder.setModuleFolder((*struct_iter).first,6,isUpgrade)){
328  (*struct_iter).second->book( conf_,6,twoDimOn, reducedSet, isUpgrade);
329  } else {
330  LogDebug ("PixelDQM") << "PROBLEM WITH RING-FOLDER\n";
331  }
332  }
333 
334  }
335 
336 }
337 
338 //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:434
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 beginRun(const edm::Run &, edm::EventSetup const &)
edm::ParameterSet conf_
virtual void buildStructure(edm::EventSetup const &)
int plaquetteName() const
plaquetteId (in pannel)
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
float yy() const
Definition: LocalError.h:26
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.
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", const uint32_t run=0, SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE")
Definition: DQMStore.cc:2424
int bladeName() const
blade id
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
int diskName() const
disk id
Definition: DetId.h:18
const T & get() const
Definition: EventSetup.h:55
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:6
volatile std::atomic< bool > shutdown_flag false
HalfCylinder halfCylinder() const
HalfCylinder halfCylinder() const
int pannelName() const
pannel id
T x() const
Definition: PV3DBase.h:62
Definition: vlib.h:208
Definition: Run.h:41
iterator begin()
Definition: DetSetNew.h:67