CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiPixelClusterSource.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiPixelMonitorCluster
4 // Class: SiPixelClusterSource
5 //
13 //
14 // Original Author: Vincenzo Chiochia & Andrew York
15 // Created:
16 // $Id: SiPixelClusterSource.cc,v 1.28 2010/06/11 00:49:53 merkelp Exp $
17 //
18 //
19 // Updated by: Lukas Wehrli
20 // for pixel offline DQM
22 // Framework
25 // DQM Framework
28 // Geometry
33 // DataFormats
38 //
39 #include <string>
40 #include <stdlib.h>
41 
42 using namespace std;
43 using namespace edm;
44 
46  conf_(iConfig),
47  src_( conf_.getParameter<edm::InputTag>( "src" ) ),
48  saveFile( conf_.getUntrackedParameter<bool>("saveFile",false) ),
49  isPIB( conf_.getUntrackedParameter<bool>("isPIB",false) ),
50  slowDown( conf_.getUntrackedParameter<bool>("slowDown",false) ),
51  modOn( conf_.getUntrackedParameter<bool>("modOn",true) ),
52  twoDimOn( conf_.getUntrackedParameter<bool>("twoDimOn",true) ),
53  reducedSet( conf_.getUntrackedParameter<bool>("reducedSet",false) ),
54  ladOn( conf_.getUntrackedParameter<bool>("ladOn",false) ),
55  layOn( conf_.getUntrackedParameter<bool>("layOn",false) ),
56  phiOn( conf_.getUntrackedParameter<bool>("phiOn",false) ),
57  ringOn( conf_.getUntrackedParameter<bool>("ringOn",false) ),
58  bladeOn( conf_.getUntrackedParameter<bool>("bladeOn",false) ),
59  diskOn( conf_.getUntrackedParameter<bool>("diskOn",false) ),
60  smileyOn(conf_.getUntrackedParameter<bool>("smileyOn",false) ),
61  bigEventSize( conf_.getUntrackedParameter<int>("bigEventSize",100) )
62 {
64  LogInfo ("PixelDQM") << "SiPixelClusterSource::SiPixelClusterSource: Got DQM BackEnd interface"<<endl;
65 }
66 
67 
69 {
70  // do anything here that needs to be done at desctruction time
71  // (e.g. close files, deallocate resources etc.)
72  LogInfo ("PixelDQM") << "SiPixelClusterSource::~SiPixelClusterSource: Destructor"<<endl;
73 
74  std::map<uint32_t,SiPixelClusterModule*>::iterator struct_iter;
75  for (struct_iter = thePixelStructure.begin() ; struct_iter != thePixelStructure.end() ; struct_iter++){
76  delete struct_iter->second;
77  struct_iter->second = 0;
78  }
79 }
80 
81 
83  firstRun = true;
84 }
85 
87 
88  LogInfo ("PixelDQM") << " SiPixelClusterSource::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  LogInfo ("PixelDQM") << "Smiley (Cluster sizeY vs. Cluster eta) is " << smileyOn << "\n";
95 
96  if(firstRun){
97  eventNo = 0;
98  lumSec = 0;
99  nLumiSecs = 0;
100  nBigEvents = 0;
101  // Build map
102  buildStructure(iSetup);
103  // Book Monitoring Elements
104  bookMEs();
105  // Book occupancy maps in global coordinates for all clusters:
106  theDMBE->setCurrentFolder("Pixel/Clusters/OffTrack");
107  //bpix
108  meClPosLayer1 = theDMBE->book2D("position_siPixelClusters_Layer_1","Clusters Layer1;Global Z (cm);Global #phi",200,-30.,30.,128,-3.2,3.2);
109  meClPosLayer2 = theDMBE->book2D("position_siPixelClusters_Layer_2","Clusters Layer2;Global Z (cm);Global #phi",200,-30.,30.,128,-3.2,3.2);
110  meClPosLayer3 = theDMBE->book2D("position_siPixelClusters_Layer_3","Clusters Layer3;Global Z (cm);Global #phi",200,-30.,30.,128,-3.2,3.2);
111  //fpix
112  meClPosDisk1pz = theDMBE->book2D("position_siPixelClusters_pz_Disk_1","Clusters +Z Disk1;Global X (cm);Global Y (cm)",80,-20.,20.,80,-20.,20.);
113  meClPosDisk2pz = theDMBE->book2D("position_siPixelClusters_pz_Disk_2","Clusters +Z Disk2;Global X (cm);Global Y (cm)",80,-20.,20.,80,-20.,20.);
114  meClPosDisk1mz = theDMBE->book2D("position_siPixelClusters_mz_Disk_1","Clusters -Z Disk1;Global X (cm);Global Y (cm)",80,-20.,20.,80,-20.,20.);
115  meClPosDisk2mz = theDMBE->book2D("position_siPixelClusters_mz_Disk_2","Clusters -Z Disk2;Global X (cm);Global Y (cm)",80,-20.,20.,80,-20.,20.);
116 
117  firstRun = false;
118  }
119 }
120 
121 
123  if(saveFile){
124  LogInfo ("PixelDQM") << " SiPixelClusterSource::endJob - Saving Root File " << std::endl;
125  std::string outputFile = conf_.getParameter<std::string>("outputFile");
126  theDMBE->save( outputFile.c_str() );
127  }
128 }
129 
130 //------------------------------------------------------------------
131 // Method called for every event
132 //------------------------------------------------------------------
134 {
135  eventNo++;
136 
137  if(modOn){
138  MonitorElement* meReset = theDMBE->get("Pixel/Clusters/OffTrack/position_siPixelClusters_Layer_1");
139  MonitorElement* meReset1 = theDMBE->get("Pixel/Clusters/OffTrack/position_siPixelClusters_Layer_2");
140  MonitorElement* meReset2 = theDMBE->get("Pixel/Clusters/OffTrack/position_siPixelClusters_Layer_3");
141  MonitorElement* meReset3 = theDMBE->get("Pixel/Clusters/OffTrack/position_siPixelClusters_mz_Disk_1");
142  MonitorElement* meReset4 = theDMBE->get("Pixel/Clusters/OffTrack/position_siPixelClusters_mz_Disk_2");
143  MonitorElement* meReset5 = theDMBE->get("Pixel/Clusters/OffTrack/position_siPixelClusters_pz_Disk_1");
144  MonitorElement* meReset6 = theDMBE->get("Pixel/Clusters/OffTrack/position_siPixelClusters_pz_Disk_2");
145  if(meReset && meReset->getEntries()>150000){
146  meReset->Reset();
147  meReset1->Reset();
148  meReset2->Reset();
149  meReset3->Reset();
150  meReset4->Reset();
151  meReset5->Reset();
152  meReset6->Reset();
153  }
154  }
155 
156  // get input data
158  iEvent.getByLabel( src_, input );
159 
161  iSetup.get<TrackerDigiGeometryRecord> ().get (pDD);
162  const TrackerGeometry* tracker = &(* pDD);
163 // const PixelGeomDetUnit* theGeomDet = dynamic_cast<const PixelGeomDetUnit*> ( tracker->idToDet(detId) );
164 
165  //float iOrbitSec = iEvent.orbitNumber()/11223.;
166  //int bx = iEvent.bunchCrossing();
167  //long long tbx = (long long)iEvent.orbitNumber() * 3564 + bx;
168  int lumiSection = (int)iEvent.luminosityBlock();
169  int nEventFpixClusters = 0;
170 
171 
172  std::map<uint32_t,SiPixelClusterModule*>::iterator struct_iter;
173  for (struct_iter = thePixelStructure.begin() ; struct_iter != thePixelStructure.end() ; struct_iter++) {
174 
175  int numberOfFpixClusters = (*struct_iter).second->fill(*input, tracker, modOn,
176  ladOn, layOn, phiOn,
177  bladeOn, diskOn, ringOn,
179  nEventFpixClusters = nEventFpixClusters + numberOfFpixClusters;
180 
181  }
182 
183 // if(lumiSection>lumSec){ lumSec = lumiSection; nLumiSecs++; }
184 // if(nEventFpixClusters>bigEventSize) nBigEvents++;
185 // if(nLumiSecs%5==0){
186 
187  if(nEventFpixClusters>bigEventSize){
188  MonitorElement* me = theDMBE->get("Pixel/bigFpixClusterEventRate");
189  if(me){
190  me->Fill(lumiSection,1./23.);
191  }
192  }
193  //std::cout<<"nEventFpixClusters: "<<nEventFpixClusters<<" , nLumiSecs: "<<nLumiSecs<<" , nBigEvents: "<<nBigEvents<<std::endl;
194 
195  // slow down...
196  if(slowDown) usleep(10000);
197 
198 }
199 
200 //------------------------------------------------------------------
201 // Build data structure
202 //------------------------------------------------------------------
204 
205  LogInfo ("PixelDQM") <<" SiPixelClusterSource::buildStructure" ;
207  iSetup.get<TrackerDigiGeometryRecord>().get( pDD );
208 
209  LogVerbatim ("PixelDQM") << " *** Geometry node for TrackerGeom is "<<&(*pDD)<<std::endl;
210  LogVerbatim ("PixelDQM") << " *** I have " << pDD->dets().size() <<" detectors"<<std::endl;
211  LogVerbatim ("PixelDQM") << " *** I have " << pDD->detTypes().size() <<" types"<<std::endl;
212 
213  for(TrackerGeometry::DetContainer::const_iterator it = pDD->dets().begin(); it != pDD->dets().end(); it++){
214 
215  if(dynamic_cast<PixelGeomDetUnit*>((*it))!=0){
216 
217  DetId detId = (*it)->geographicalId();
218  const GeomDetUnit * geoUnit = pDD->idToDetUnit( detId );
219  const PixelGeomDetUnit * pixDet = dynamic_cast<const PixelGeomDetUnit*>(geoUnit);
220  int nrows = (pixDet->specificTopology()).nrows();
221  int ncols = (pixDet->specificTopology()).ncolumns();
222 
223 
224  if((detId.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel)) ||
225  (detId.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap))){
226  uint32_t id = detId();
227  SiPixelClusterModule* theModule = new SiPixelClusterModule(id, ncols, nrows);
228  if(detId.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel)) {
229  if(isPIB) continue;
230  LogDebug ("PixelDQM") << " ---> Adding Barrel Module " << detId.rawId() << endl;
231  thePixelStructure.insert(pair<uint32_t,SiPixelClusterModule*> (id,theModule));
232  }else if(detId.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap)) {
233  LogDebug ("PixelDQM") << " ---> Adding Endcap Module " << detId.rawId() << endl;
235  int disk = PixelEndcapName(DetId(id)).diskName();
236  int blade = PixelEndcapName(DetId(id)).bladeName();
237  int panel = PixelEndcapName(DetId(id)).pannelName();
239  char sside[80]; sprintf(sside, "HalfCylinder_%i",side);
240  char sdisk[80]; sprintf(sdisk, "Disk_%i",disk);
241  char sblade[80]; sprintf(sblade, "Blade_%02i",blade);
242  char spanel[80]; sprintf(spanel, "Panel_%i",panel);
243  char smodule[80];sprintf(smodule,"Module_%i",module);
244  std::string side_str = sside;
245  std::string disk_str = sdisk;
246  bool mask = side_str.find("HalfCylinder_1")!=string::npos||
247  side_str.find("HalfCylinder_2")!=string::npos||
248  side_str.find("HalfCylinder_4")!=string::npos||
249  disk_str.find("Disk_2")!=string::npos;
250  // clutch to take all of FPIX, but no BPIX:
251  mask = false;
252  if(isPIB && mask) continue;
253  thePixelStructure.insert(pair<uint32_t,SiPixelClusterModule*> (id,theModule));
254  }
255  }
256  }
257  }
258  LogInfo ("PixelDQM") << " *** Pixel Structure Size " << thePixelStructure.size() << endl;
259 }
260 //------------------------------------------------------------------
261 // Book MEs
262 //------------------------------------------------------------------
264 
265  // Get DQM interface
267  theDMBE->setCurrentFolder("Pixel");
268  char title[256]; snprintf(title, 256, "Rate of events with >%i FPIX clusters;LumiSection;Rate of large FPIX events per LS [Hz]",bigEventSize);
269  bigFpixClusterEventRate = theDMBE->book1D("bigFpixClusterEventRate",title,5000,0.,5000.);
270 
271 
272  std::map<uint32_t,SiPixelClusterModule*>::iterator struct_iter;
273 
274  SiPixelFolderOrganizer theSiPixelFolder;
275 
276  for(struct_iter = thePixelStructure.begin(); struct_iter != thePixelStructure.end(); struct_iter++){
277 
279  if(modOn){
280  if(theSiPixelFolder.setModuleFolder((*struct_iter).first)){
281  (*struct_iter).second->book( conf_,0,twoDimOn,reducedSet);
282  } else {
283 
284  if(!isPIB) throw cms::Exception("LogicError")
285  << "[SiPixelClusterSource::bookMEs] Creation of DQM folder failed";
286  }
287  }
288  if(ladOn){
289  if(theSiPixelFolder.setModuleFolder((*struct_iter).first,1)){
290  (*struct_iter).second->book( conf_,1,twoDimOn,reducedSet);
291  } else {
292  LogDebug ("PixelDQM") << "PROBLEM WITH LADDER-FOLDER\n";
293  }
294  }
295  if(layOn){
296  if(theSiPixelFolder.setModuleFolder((*struct_iter).first,2)){
297  (*struct_iter).second->book( conf_,2,twoDimOn,reducedSet);
298  } else {
299  LogDebug ("PixelDQM") << "PROBLEM WITH LAYER-FOLDER\n";
300  }
301  }
302  if(phiOn){
303  if(theSiPixelFolder.setModuleFolder((*struct_iter).first,3)){
304  (*struct_iter).second->book( conf_,3,twoDimOn,reducedSet);
305  } else {
306  LogDebug ("PixelDQM") << "PROBLEM WITH PHI-FOLDER\n";
307  }
308  }
309  if(bladeOn){
310  if(theSiPixelFolder.setModuleFolder((*struct_iter).first,4)){
311  (*struct_iter).second->book( conf_,4,twoDimOn,reducedSet);
312  } else {
313  LogDebug ("PixelDQM") << "PROBLEM WITH BLADE-FOLDER\n";
314  }
315  }
316  if(diskOn){
317  if(theSiPixelFolder.setModuleFolder((*struct_iter).first,5)){
318  (*struct_iter).second->book( conf_,5,twoDimOn,reducedSet);
319  } else {
320  LogDebug ("PixelDQM") << "PROBLEM WITH DISK-FOLDER\n";
321  }
322  }
323  if(ringOn){
324  if(theSiPixelFolder.setModuleFolder((*struct_iter).first,6)){
325  (*struct_iter).second->book( conf_,6,twoDimOn,reducedSet);
326  } else {
327  LogDebug ("PixelDQM") << "PROBLEM WITH RING-FOLDER\n";
328  }
329  }
330  if(smileyOn){
331  if(theSiPixelFolder.setModuleFolder((*struct_iter).first,7)){
332  (*struct_iter).second->book( conf_,7,twoDimOn,reducedSet);
333  } else {
334  LogDebug ("PixelDQM") << "PROBLEM WITH BARREL-FOLDER\n";
335  }
336  }
337 
338  }
339 
340 }
341 
342 //define this as a plug-in
#define LogDebug(id)
int plaquetteName() const
plaquetteId (in pannel)
virtual void buildStructure(edm::EventSetup const &)
T getParameter(std::string const &) const
MonitorElement * meClPosDisk2pz
virtual void analyze(const edm::Event &, const edm::EventSetup &)
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:514
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE")
Definition: DQMStore.cc:1898
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:59
double getEntries(void) const
get # of entries
SiPixelClusterSource(const edm::ParameterSet &conf)
void Fill(long long x)
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
MonitorElement * meClPosLayer3
int bladeName() const
blade id
int iEvent
Definition: GenABIO.cc:243
virtual void beginRun(const edm::Run &, edm::EventSetup const &)
MonitorElement * meClPosLayer1
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1265
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
tuple input
Definition: collect_tpl.py:10
edm::ParameterSet conf_
Definition: DetId.h:20
const T & get() const
Definition: EventSetup.h:55
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
int pannelName() const
pannel id
MonitorElement * meClPosDisk2mz
int diskName() const
disk id
std::map< uint32_t, SiPixelClusterModule * > thePixelStructure
MonitorElement * meClPosLayer2
HalfCylinder halfCylinder() const
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:642
void Reset(void)
reset ME (ie. contents, errors, etc)
Definition: vlib.h:209
MonitorElement * bigFpixClusterEventRate
MonitorElement * meClPosDisk1mz
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:232
MonitorElement * meClPosDisk1pz
Definition: Run.h:32
bool setModuleFolder(const uint32_t &rawdetid=0, int type=0)
Set folder name for a module or plaquette.