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
32 // DataFormats
40 //
41 #include <string>
42 #include <stdlib.h>
43 
44 using namespace std;
45 using namespace edm;
46 
48  conf_(iConfig),
49  src_( conf_.getParameter<edm::InputTag>( "src" ) ),
50  saveFile( conf_.getUntrackedParameter<bool>("saveFile",false) ),
51  isPIB( conf_.getUntrackedParameter<bool>("isPIB",false) ),
52  slowDown( conf_.getUntrackedParameter<bool>("slowDown",false) ),
53  modOn( conf_.getUntrackedParameter<bool>("modOn",true) ),
54  twoDimOn( conf_.getUntrackedParameter<bool>("twoDimOn",true) ),
55  reducedSet( conf_.getUntrackedParameter<bool>("reducedSet",false) ),
56  ladOn( conf_.getUntrackedParameter<bool>("ladOn",false) ),
57  layOn( conf_.getUntrackedParameter<bool>("layOn",false) ),
58  phiOn( conf_.getUntrackedParameter<bool>("phiOn",false) ),
59  ringOn( conf_.getUntrackedParameter<bool>("ringOn",false) ),
60  bladeOn( conf_.getUntrackedParameter<bool>("bladeOn",false) ),
61  diskOn( conf_.getUntrackedParameter<bool>("diskOn",false) ),
62  smileyOn(conf_.getUntrackedParameter<bool>("smileyOn",false) ),
63  bigEventSize( conf_.getUntrackedParameter<int>("bigEventSize",100) ),
64  isUpgrade( conf_.getUntrackedParameter<bool>("isUpgrade",false) ),
65  noOfLayers(0),
66  noOfDisks(0)
67 {
68  LogInfo ("PixelDQM") << "SiPixelClusterSource::SiPixelClusterSource: Got DQM BackEnd interface"<<endl;
69 
70  //set Token(-s)
71  srcToken_ = consumes<edmNew::DetSetVector<SiPixelCluster> >(conf_.getParameter<edm::InputTag>("src"));
72  firstRun = true;
73  topFolderName_ = conf_.getParameter<std::string>("TopFolderName");
74 }
75 
76 
78 {
79  // do anything here that needs to be done at desctruction time
80  // (e.g. close files, deallocate resources etc.)
81  LogInfo ("PixelDQM") << "SiPixelClusterSource::~SiPixelClusterSource: Destructor"<<endl;
82 
83  std::map<uint32_t,SiPixelClusterModule*>::iterator struct_iter;
84  for (struct_iter = thePixelStructure.begin() ; struct_iter != thePixelStructure.end() ; struct_iter++){
85  delete struct_iter->second;
86  struct_iter->second = 0;
87  }
88 }
89 
90 
91 
93  LogInfo ("PixelDQM") << " SiPixelClusterSource::beginJob - Initialisation ... " << std::endl;
94  LogInfo ("PixelDQM") << "Mod/Lad/Lay/Phi " << modOn << "/" << ladOn << "/"
95  << layOn << "/" << phiOn << std::endl;
96  LogInfo ("PixelDQM") << "Blade/Disk/Ring" << bladeOn << "/" << diskOn << "/"
97  << ringOn << std::endl;
98  LogInfo ("PixelDQM") << "2DIM IS " << twoDimOn << "\n";
99  LogInfo ("PixelDQM") << "Smiley (Cluster sizeY vs. Cluster eta) is " << smileyOn << "\n";
100 
101  if(firstRun){
102  eventNo = 0;
103  lumSec = 0;
104  nLumiSecs = 0;
105  nBigEvents = 0;
106  // Build map
107  buildStructure(iSetup);
108 
109  firstRun = false;
110  }
111 }
112 
114  bookMEs(iBooker, iSetup);
115  // Book occupancy maps in global coordinates for all clusters:
116  iBooker.setCurrentFolder(topFolderName_+"/Clusters/OffTrack");
117  //bpix
118  std::stringstream ss1, ss2;
119  for (int i = 1; i <= noOfLayers; i++)
120  {
121  ss1.str(std::string()); ss1 << "position_siPixelClusters_Layer_" << i;
122  ss2.str(std::string()); ss2 << "Clusters Layer" << i << ";Global Z (cm);Global #phi";
123  meClPosLayer.push_back(iBooker.book2D(ss1.str(),ss2.str(),200,-30.,30.,128,-3.2,3.2));
124  }
125  for (int i = 1; i <= noOfDisks; i++)
126  {
127  ss1.str(std::string()); ss1 << "position_siPixelClusters_pz_Disk_" << i;
128  ss2.str(std::string()); ss2 << "Clusters +Z Disk" << i << ";Global X (cm);Global Y (cm)";
129  meClPosDiskpz.push_back(iBooker.book2D(ss1.str(),ss2.str(),80,-20.,20.,80,-20.,20.));
130  ss1.str(std::string()); ss1 << "position_siPixelClusters_mz_Disk_" << i;
131  ss2.str(std::string()); ss2 << "Clusters -Z Disk" << i << ";Global X (cm);Global Y (cm)";
132  meClPosDiskmz.push_back(iBooker.book2D(ss1.str(),ss2.str(),80,-20.,20.,80,-20.,20.));
133  }
134 }
135 
136 //------------------------------------------------------------------
137 // Method called for every event
138 //------------------------------------------------------------------
140 {
141  eventNo++;
142 
143  if(meClPosLayer.at(0) && meClPosLayer.at(0)->getEntries()>150000){
144  for (int i = 0; i < noOfLayers; i++)
145  {
146  meClPosLayer.at(i)->Reset();
147  }
148  for (int i = 0; i < noOfDisks; i++)
149  {
150  meClPosDiskpz.at(i)->Reset();
151  meClPosDiskmz.at(i)->Reset();
152  }
153  }
154 
155  // get input data
157  iEvent.getByToken(srcToken_, input);
158 
160  iSetup.get<TrackerDigiGeometryRecord> ().get (pDD);
161  const TrackerGeometry* tracker = &(* pDD);
162 
163  int lumiSection = (int)iEvent.luminosityBlock();
164  int nEventFpixClusters = 0;
165 
166 
167  std::map<uint32_t,SiPixelClusterModule*>::iterator struct_iter;
168  for (struct_iter = thePixelStructure.begin() ; struct_iter != thePixelStructure.end() ; struct_iter++) {
169 
170  int numberOfFpixClusters = (*struct_iter).second->fill(*input, tracker,
171  meClPosLayer,
174  modOn, ladOn, layOn, phiOn,
175  bladeOn, diskOn, ringOn,
177  nEventFpixClusters = nEventFpixClusters + numberOfFpixClusters;
178 
179  }
180 
181  if(nEventFpixClusters>bigEventSize){
183  bigFpixClusterEventRate->Fill(lumiSection,1./23.);
184  }
185  }
186  //std::cout<<"nEventFpixClusters: "<<nEventFpixClusters<<" , nLumiSecs: "<<nLumiSecs<<" , nBigEvents: "<<nBigEvents<<std::endl;
187 
188  // slow down...
189  if(slowDown) usleep(10000);
190 
191 }
192 
193 //------------------------------------------------------------------
194 // Build data structure
195 //------------------------------------------------------------------
197 
198  LogInfo ("PixelDQM") <<" SiPixelClusterSource::buildStructure" ;
200  iSetup.get<TrackerDigiGeometryRecord>().get( pDD );
201 
202  edm::ESHandle<TrackerTopology> tTopoHandle;
203  iSetup.get<IdealGeometryRecord>().get(tTopoHandle);
204  const TrackerTopology *pTT = tTopoHandle.product();
205 
206  LogVerbatim ("PixelDQM") << " *** Geometry node for TrackerGeom is "<<&(*pDD)<<std::endl;
207  LogVerbatim ("PixelDQM") << " *** I have " << pDD->dets().size() <<" detectors"<<std::endl;
208  LogVerbatim ("PixelDQM") << " *** I have " << pDD->detTypes().size() <<" types"<<std::endl;
209 
210  for(TrackerGeometry::DetContainer::const_iterator it = pDD->dets().begin(); it != pDD->dets().end(); it++){
211 
212  if(dynamic_cast<PixelGeomDetUnit const *>((*it))!=0){
213 
214  DetId detId = (*it)->geographicalId();
215  const GeomDetUnit * geoUnit = pDD->idToDetUnit( detId );
216  const PixelGeomDetUnit * pixDet = dynamic_cast<const PixelGeomDetUnit*>(geoUnit);
217  int nrows = (pixDet->specificTopology()).nrows();
218  int ncols = (pixDet->specificTopology()).ncolumns();
219 
220 
221  if((detId.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel)) ||
222  (detId.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap))){
223  uint32_t id = detId();
224  SiPixelClusterModule* theModule = new SiPixelClusterModule(id, ncols, nrows);
225  if(detId.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel)) {
226  if(isPIB) continue;
227  LogDebug ("PixelDQM") << " ---> Adding Barrel Module " << detId.rawId() << endl;
228  int layer = PixelBarrelName(DetId(id),pTT,isUpgrade).layerName();
229  if (layer > noOfLayers) noOfLayers = layer;
230  thePixelStructure.insert(pair<uint32_t,SiPixelClusterModule*> (id,theModule));
231  }else if ( detId.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap ) ) {
232  LogDebug ("PixelDQM") << " ---> Adding Endcap Module " << detId.rawId() << endl;
234  int disk = PixelEndcapName(DetId(id),pTT,isUpgrade).diskName();
235  if (disk>noOfDisks) noOfDisks=disk;
236  int blade = PixelEndcapName(DetId(id),pTT,isUpgrade).bladeName();
237  int panel = PixelEndcapName(DetId(id),pTT,isUpgrade).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  char title[256]; snprintf(title, 256, "Rate of events with >%i FPIX clusters;LumiSection;Rate of large FPIX events per LS [Hz]",bigEventSize);
268  bigFpixClusterEventRate = iBooker.book1D("bigFpixClusterEventRate",title,5000,0.,5000.);
269 
270 
271  std::map<uint32_t,SiPixelClusterModule*>::iterator struct_iter;
272 
273  SiPixelFolderOrganizer theSiPixelFolder(false);
274 
275  for(struct_iter = thePixelStructure.begin(); struct_iter != thePixelStructure.end(); struct_iter++){
276 
278  if(modOn){
279  if(theSiPixelFolder.setModuleFolder(iBooker,(*struct_iter).first,0,isUpgrade)){
280  (*struct_iter).second->book( conf_,iSetup,iBooker,0,twoDimOn,reducedSet,isUpgrade);
281  } else {
282 
283  if(!isPIB) throw cms::Exception("LogicError")
284  << "[SiPixelClusterSource::bookMEs] Creation of DQM folder failed";
285  }
286  }
287  if(ladOn){
288  if(theSiPixelFolder.setModuleFolder(iBooker,(*struct_iter).first,1,isUpgrade)){
289  (*struct_iter).second->book( conf_,iSetup,iBooker,1,twoDimOn,reducedSet,isUpgrade);
290  } else {
291  LogDebug ("PixelDQM") << "PROBLEM WITH LADDER-FOLDER\n";
292  }
293  }
294  if(layOn){
295  if(theSiPixelFolder.setModuleFolder(iBooker,(*struct_iter).first,2,isUpgrade)){
296  (*struct_iter).second->book( conf_,iSetup,iBooker,2,twoDimOn,reducedSet,isUpgrade);
297  } else {
298  LogDebug ("PixelDQM") << "PROBLEM WITH LAYER-FOLDER\n";
299  }
300  }
301  if(phiOn){
302  if(theSiPixelFolder.setModuleFolder(iBooker,(*struct_iter).first,3,isUpgrade)){
303  (*struct_iter).second->book( conf_,iSetup,iBooker,3,twoDimOn,reducedSet,isUpgrade);
304  } else {
305  LogDebug ("PixelDQM") << "PROBLEM WITH PHI-FOLDER\n";
306  }
307  }
308  if(bladeOn){
309  if(theSiPixelFolder.setModuleFolder(iBooker,(*struct_iter).first,4,isUpgrade)){
310  (*struct_iter).second->book( conf_,iSetup,iBooker,4,twoDimOn,reducedSet,isUpgrade);
311  } else {
312  LogDebug ("PixelDQM") << "PROBLEM WITH BLADE-FOLDER\n";
313  }
314  }
315  if(diskOn){
316  if(theSiPixelFolder.setModuleFolder(iBooker,(*struct_iter).first,5,isUpgrade)){
317  (*struct_iter).second->book( conf_,iSetup,iBooker,5,twoDimOn,reducedSet,isUpgrade);
318  } else {
319  LogDebug ("PixelDQM") << "PROBLEM WITH DISK-FOLDER\n";
320  }
321  }
322  if(ringOn){
323  if(theSiPixelFolder.setModuleFolder(iBooker,(*struct_iter).first,6,isUpgrade)){
324  (*struct_iter).second->book( conf_,iSetup,iBooker,6,twoDimOn,reducedSet,isUpgrade);
325  } else {
326  LogDebug ("PixelDQM") << "PROBLEM WITH RING-FOLDER\n";
327  }
328  }
329  if(smileyOn){
330  if(theSiPixelFolder.setModuleFolder(iBooker,(*struct_iter).first,7,isUpgrade)){
331  (*struct_iter).second->book( conf_,iSetup,iBooker,7,twoDimOn,reducedSet,isUpgrade);
332  } else {
333  LogDebug ("PixelDQM") << "PROBLEM WITH BARREL-FOLDER\n";
334  }
335  }
336 
337  }
338 
339 }
340 
341 //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:449
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:55
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:41