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 //
17 //
18 // Updated by: Lukas Wehrli
19 // for pixel offline DQM
21 // Framework
24 // DQM Framework
27 // Geometry
33 // DataFormats
41 //
42 #include <string>
43 #include <stdlib.h>
44 
45 using namespace std;
46 using namespace edm;
47 
49  conf_(iConfig),
50  src_( conf_.getParameter<edm::InputTag>( "src" ) ),
51  saveFile( conf_.getUntrackedParameter<bool>("saveFile",false) ),
52  isPIB( conf_.getUntrackedParameter<bool>("isPIB",false) ),
53  slowDown( conf_.getUntrackedParameter<bool>("slowDown",false) ),
54  modOn( conf_.getUntrackedParameter<bool>("modOn",true) ),
55  twoDimOn( conf_.getUntrackedParameter<bool>("twoDimOn",true) ),
56  reducedSet( conf_.getUntrackedParameter<bool>("reducedSet",false) ),
57  ladOn( conf_.getUntrackedParameter<bool>("ladOn",false) ),
58  layOn( conf_.getUntrackedParameter<bool>("layOn",false) ),
59  phiOn( conf_.getUntrackedParameter<bool>("phiOn",false) ),
60  ringOn( conf_.getUntrackedParameter<bool>("ringOn",false) ),
61  bladeOn( conf_.getUntrackedParameter<bool>("bladeOn",false) ),
62  diskOn( conf_.getUntrackedParameter<bool>("diskOn",false) ),
63  smileyOn(conf_.getUntrackedParameter<bool>("smileyOn",false) ),
64  bigEventSize( conf_.getUntrackedParameter<int>("bigEventSize",100) ),
65  isUpgrade( conf_.getUntrackedParameter<bool>("isUpgrade",false) ),
66  noOfLayers(0),
67  noOfDisks(0)
68 {
69  LogInfo ("PixelDQM") << "SiPixelClusterSource::SiPixelClusterSource: Got DQM BackEnd interface"<<endl;
70 
71  //set Token(-s)
72  srcToken_ = consumes<edmNew::DetSetVector<SiPixelCluster> >(conf_.getParameter<edm::InputTag>("src"));
73  firstRun = true;
74  topFolderName_ = conf_.getParameter<std::string>("TopFolderName");
75 }
76 
77 
79 {
80  // do anything here that needs to be done at desctruction time
81  // (e.g. close files, deallocate resources etc.)
82  LogInfo ("PixelDQM") << "SiPixelClusterSource::~SiPixelClusterSource: Destructor"<<endl;
83 
84  std::map<uint32_t,SiPixelClusterModule*>::iterator struct_iter;
85  for (struct_iter = thePixelStructure.begin() ; struct_iter != thePixelStructure.end() ; struct_iter++){
86  delete struct_iter->second;
87  struct_iter->second = 0;
88  }
89 }
90 
91 
92 
94  LogInfo ("PixelDQM") << " SiPixelClusterSource::beginJob - Initialisation ... " << std::endl;
95  LogInfo ("PixelDQM") << "Mod/Lad/Lay/Phi " << modOn << "/" << ladOn << "/"
96  << layOn << "/" << phiOn << std::endl;
97  LogInfo ("PixelDQM") << "Blade/Disk/Ring" << bladeOn << "/" << diskOn << "/"
98  << ringOn << std::endl;
99  LogInfo ("PixelDQM") << "2DIM IS " << twoDimOn << "\n";
100  LogInfo ("PixelDQM") << "Smiley (Cluster sizeY vs. Cluster eta) is " << smileyOn << "\n";
101 
102  if(firstRun){
103  eventNo = 0;
104  lumSec = 0;
105  nLumiSecs = 0;
106  nBigEvents = 0;
107  // Build map
108  buildStructure(iSetup);
109 
110  firstRun = false;
111  }
112 }
113 
115  bookMEs(iBooker, iSetup);
116  // Book occupancy maps in global coordinates for all clusters:
117  iBooker.setCurrentFolder(topFolderName_+"/Clusters/OffTrack");
118  //bpix
119  std::stringstream ss1, ss2;
120  for (int i = 1; i <= noOfLayers; i++)
121  {
122  ss1.str(std::string()); ss1 << "position_siPixelClusters_Layer_" << i;
123  ss2.str(std::string()); ss2 << "Clusters Layer" << i << ";Global Z (cm);Global #phi";
124  meClPosLayer.push_back(iBooker.book2D(ss1.str(),ss2.str(),200,-30.,30.,128,-3.2,3.2));
125  }
126  for (int i = 1; i <= noOfDisks; i++)
127  {
128  ss1.str(std::string()); ss1 << "position_siPixelClusters_pz_Disk_" << i;
129  ss2.str(std::string()); ss2 << "Clusters +Z Disk" << i << ";Global X (cm);Global Y (cm)";
130  meClPosDiskpz.push_back(iBooker.book2D(ss1.str(),ss2.str(),80,-20.,20.,80,-20.,20.));
131  ss1.str(std::string()); ss1 << "position_siPixelClusters_mz_Disk_" << i;
132  ss2.str(std::string()); ss2 << "Clusters -Z Disk" << i << ";Global X (cm);Global Y (cm)";
133  meClPosDiskmz.push_back(iBooker.book2D(ss1.str(),ss2.str(),80,-20.,20.,80,-20.,20.));
134  }
135 }
136 
137 //------------------------------------------------------------------
138 // Method called for every event
139 //------------------------------------------------------------------
141 {
142  eventNo++;
143 
144  if(meClPosLayer.at(0) && meClPosLayer.at(0)->getEntries()>150000){
145  for (int i = 0; i < noOfLayers; i++)
146  {
147  meClPosLayer.at(i)->Reset();
148  }
149  for (int i = 0; i < noOfDisks; i++)
150  {
151  meClPosDiskpz.at(i)->Reset();
152  meClPosDiskmz.at(i)->Reset();
153  }
154  }
155 
156  // get input data
158  iEvent.getByToken(srcToken_, input);
159 
161  iSetup.get<TrackerDigiGeometryRecord> ().get (pDD);
162  const TrackerGeometry* tracker = &(* pDD);
163 
164  int lumiSection = (int)iEvent.luminosityBlock();
165  int nEventFpixClusters = 0;
166 
167 
168  std::map<uint32_t,SiPixelClusterModule*>::iterator struct_iter;
169  for (struct_iter = thePixelStructure.begin() ; struct_iter != thePixelStructure.end() ; struct_iter++) {
170 
171  int numberOfFpixClusters = (*struct_iter).second->fill(*input, tracker,
172  meClPosLayer,
175  modOn, ladOn, layOn, phiOn,
176  bladeOn, diskOn, ringOn,
178  nEventFpixClusters = nEventFpixClusters + numberOfFpixClusters;
179 
180  }
181 
182  if(nEventFpixClusters>bigEventSize){
184  bigFpixClusterEventRate->Fill(lumiSection,1./23.);
185  }
186  }
187  //std::cout<<"nEventFpixClusters: "<<nEventFpixClusters<<" , nLumiSecs: "<<nLumiSecs<<" , nBigEvents: "<<nBigEvents<<std::endl;
188 
189  // slow down...
190  if(slowDown) usleep(10000);
191 
192 }
193 
194 //------------------------------------------------------------------
195 // Build data structure
196 //------------------------------------------------------------------
198 
199  LogInfo ("PixelDQM") <<" SiPixelClusterSource::buildStructure" ;
201  iSetup.get<TrackerDigiGeometryRecord>().get( pDD );
202 
203  edm::ESHandle<TrackerTopology> tTopoHandle;
204  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
205  const TrackerTopology *pTT = tTopoHandle.product();
206 
207  LogVerbatim ("PixelDQM") << " *** Geometry node for TrackerGeom is "<<&(*pDD)<<std::endl;
208  LogVerbatim ("PixelDQM") << " *** I have " << pDD->dets().size() <<" detectors"<<std::endl;
209  LogVerbatim ("PixelDQM") << " *** I have " << pDD->detTypes().size() <<" types"<<std::endl;
210 
211  for(TrackerGeometry::DetContainer::const_iterator it = pDD->dets().begin(); it != pDD->dets().end(); it++){
212 
213  if(dynamic_cast<PixelGeomDetUnit const *>((*it))!=0){
214 
215  DetId detId = (*it)->geographicalId();
216  const GeomDetUnit * geoUnit = pDD->idToDetUnit( detId );
217  const PixelGeomDetUnit * pixDet = dynamic_cast<const PixelGeomDetUnit*>(geoUnit);
218  int nrows = (pixDet->specificTopology()).nrows();
219  int ncols = (pixDet->specificTopology()).ncolumns();
220 
221 
222  if((detId.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel)) ||
223  (detId.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap))){
224  uint32_t id = detId();
225  SiPixelClusterModule* theModule = new SiPixelClusterModule(id, ncols, nrows);
226  if(detId.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel)) {
227  if(isPIB) continue;
228  LogDebug ("PixelDQM") << " ---> Adding Barrel Module " << detId.rawId() << endl;
229  int layer = PixelBarrelName(DetId(id),pTT,isUpgrade).layerName();
230  if (layer > noOfLayers) noOfLayers = layer;
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),pTT,isUpgrade).diskName();
236  if (disk>noOfDisks) noOfDisks=disk;
237  int blade = PixelEndcapName(DetId(id),pTT,isUpgrade).bladeName();
238  int panel = PixelEndcapName(DetId(id),pTT,isUpgrade).pannelName();
240  char sside[80]; sprintf(sside, "HalfCylinder_%i",side);
241  char sdisk[80]; sprintf(sdisk, "Disk_%i",disk);
242  char sblade[80]; sprintf(sblade, "Blade_%02i",blade);
243  char spanel[80]; sprintf(spanel, "Panel_%i",panel);
244  char smodule[80];sprintf(smodule,"Module_%i",module);
245  std::string side_str = sside;
246  std::string disk_str = sdisk;
247  bool mask = side_str.find("HalfCylinder_1")!=string::npos||
248  side_str.find("HalfCylinder_2")!=string::npos||
249  side_str.find("HalfCylinder_4")!=string::npos||
250  disk_str.find("Disk_2")!=string::npos;
251  // clutch to take all of FPIX, but no BPIX:
252  mask = false;
253  if(isPIB && mask) continue;
254  thePixelStructure.insert(pair<uint32_t,SiPixelClusterModule*> (id,theModule));
255  }
256  }
257  }
258  }
259  LogInfo ("PixelDQM") << " *** Pixel Structure Size " << thePixelStructure.size() << endl;
260 }
261 //------------------------------------------------------------------
262 // Book MEs
263 //------------------------------------------------------------------
265 
266  // Get DQM interface
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 = iBooker.book1D("bigFpixClusterEventRate",title,5000,0.,5000.);
270 
271 
272  std::map<uint32_t,SiPixelClusterModule*>::iterator struct_iter;
273 
274  SiPixelFolderOrganizer theSiPixelFolder(false);
275 
276  for(struct_iter = thePixelStructure.begin(); struct_iter != thePixelStructure.end(); struct_iter++){
277 
279  if(modOn){
280  if(theSiPixelFolder.setModuleFolder(iBooker,(*struct_iter).first,0,isUpgrade)){
281  (*struct_iter).second->book( conf_,iSetup,iBooker,0,twoDimOn,reducedSet,isUpgrade);
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(iBooker,(*struct_iter).first,1,isUpgrade)){
290  (*struct_iter).second->book( conf_,iSetup,iBooker,1,twoDimOn,reducedSet,isUpgrade);
291  } else {
292  LogDebug ("PixelDQM") << "PROBLEM WITH LADDER-FOLDER\n";
293  }
294  }
295  if(layOn){
296  if(theSiPixelFolder.setModuleFolder(iBooker,(*struct_iter).first,2,isUpgrade)){
297  (*struct_iter).second->book( conf_,iSetup,iBooker,2,twoDimOn,reducedSet,isUpgrade);
298  } else {
299  LogDebug ("PixelDQM") << "PROBLEM WITH LAYER-FOLDER\n";
300  }
301  }
302  if(phiOn){
303  if(theSiPixelFolder.setModuleFolder(iBooker,(*struct_iter).first,3,isUpgrade)){
304  (*struct_iter).second->book( conf_,iSetup,iBooker,3,twoDimOn,reducedSet,isUpgrade);
305  } else {
306  LogDebug ("PixelDQM") << "PROBLEM WITH PHI-FOLDER\n";
307  }
308  }
309  if(bladeOn){
310  if(theSiPixelFolder.setModuleFolder(iBooker,(*struct_iter).first,4,isUpgrade)){
311  (*struct_iter).second->book( conf_,iSetup,iBooker,4,twoDimOn,reducedSet,isUpgrade);
312  } else {
313  LogDebug ("PixelDQM") << "PROBLEM WITH BLADE-FOLDER\n";
314  }
315  }
316  if(diskOn){
317  if(theSiPixelFolder.setModuleFolder(iBooker,(*struct_iter).first,5,isUpgrade)){
318  (*struct_iter).second->book( conf_,iSetup,iBooker,5,twoDimOn,reducedSet,isUpgrade);
319  } else {
320  LogDebug ("PixelDQM") << "PROBLEM WITH DISK-FOLDER\n";
321  }
322  }
323  if(ringOn){
324  if(theSiPixelFolder.setModuleFolder(iBooker,(*struct_iter).first,6,isUpgrade)){
325  (*struct_iter).second->book( conf_,iSetup,iBooker,6,twoDimOn,reducedSet,isUpgrade);
326  } else {
327  LogDebug ("PixelDQM") << "PROBLEM WITH RING-FOLDER\n";
328  }
329  }
330  if(smileyOn){
331  if(theSiPixelFolder.setModuleFolder(iBooker,(*struct_iter).first,7,isUpgrade)){
332  (*struct_iter).second->book( conf_,iSetup,iBooker,7,twoDimOn,reducedSet,isUpgrade);
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
int i
Definition: DBlmapReader.cc:9
virtual void analyze(const edm::Event &, const edm::EventSetup &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
std::vector< MonitorElement * > meClPosDiskmz
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:63
edm::EDGetTokenT< edmNew::DetSetVector< SiPixelCluster > > srcToken_
SiPixelClusterSource(const edm::ParameterSet &conf)
static std::string const input
Definition: EdmProvDump.cc:43
void Fill(long long x)
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
int bladeName() const
blade id
int iEvent
Definition: GenABIO.cc:230
std::vector< MonitorElement * > meClPosDiskpz
bool setModuleFolder(const uint32_t &rawdetid=0, int type=0, bool isUpgrade=false)
Set folder name for a module or plaquette.
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
std::vector< MonitorElement * > meClPosLayer
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
edm::ParameterSet conf_
Definition: DetId.h:18
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:274
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:133
const T & get() const
Definition: EventSetup.h:56
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
int layerName() const
layer id
T const * product() const
Definition: ESHandle.h:86
virtual void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
virtual void dqmBeginRun(const edm::Run &, edm::EventSetup const &)
int pannelName() const
pannel id
virtual void bookMEs(DQMStore::IBooker &, const edm::EventSetup &iSetup)
int diskName() const
disk id
std::map< uint32_t, SiPixelClusterModule * > thePixelStructure
volatile std::atomic< bool > shutdown_flag false
HalfCylinder halfCylinder() const
Definition: vlib.h:208
MonitorElement * bigFpixClusterEventRate
Definition: Run.h:43