CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DQM/SiPixelMonitorCluster/src/SiPixelClusterSource.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    SiPixelMonitorCluster
00004 // Class:      SiPixelClusterSource
00005 // 
00013 //
00014 // Original Author:  Vincenzo Chiochia & Andrew York
00015 //         Created:  
00016 // $Id: SiPixelClusterSource.cc,v 1.29 2010/11/19 13:39:23 eulisse Exp $
00017 //
00018 //
00019 // Updated by: Lukas Wehrli
00020 // for pixel offline DQM 
00021 #include "DQM/SiPixelMonitorCluster/interface/SiPixelClusterSource.h"
00022 // Framework
00023 #include "FWCore/ServiceRegistry/interface/Service.h"
00024 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00025 // DQM Framework
00026 #include "DQM/SiPixelCommon/interface/SiPixelFolderOrganizer.h"
00027 #include "DQMServices/Core/interface/DQMStore.h"
00028 // Geometry
00029 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00030 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00031 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h"
00032 #include "Geometry/CommonTopologies/interface/PixelTopology.h"
00033 // DataFormats
00034 #include "DataFormats/DetId/interface/DetId.h"
00035 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
00036 #include "DataFormats/SiPixelDetId/interface/PixelBarrelName.h"
00037 #include "DataFormats/SiPixelDetId/interface/PixelEndcapName.h"
00038 //
00039 #include <string>
00040 #include <stdlib.h>
00041 
00042 using namespace std;
00043 using namespace edm;
00044 
00045 SiPixelClusterSource::SiPixelClusterSource(const edm::ParameterSet& iConfig) :
00046   conf_(iConfig),
00047   src_( conf_.getParameter<edm::InputTag>( "src" ) ),
00048   saveFile( conf_.getUntrackedParameter<bool>("saveFile",false) ),
00049   isPIB( conf_.getUntrackedParameter<bool>("isPIB",false) ),
00050   slowDown( conf_.getUntrackedParameter<bool>("slowDown",false) ),
00051   modOn( conf_.getUntrackedParameter<bool>("modOn",true) ),
00052   twoDimOn( conf_.getUntrackedParameter<bool>("twoDimOn",true) ),
00053   reducedSet( conf_.getUntrackedParameter<bool>("reducedSet",false) ),
00054   ladOn( conf_.getUntrackedParameter<bool>("ladOn",false) ), 
00055   layOn( conf_.getUntrackedParameter<bool>("layOn",false) ), 
00056   phiOn( conf_.getUntrackedParameter<bool>("phiOn",false) ), 
00057   ringOn( conf_.getUntrackedParameter<bool>("ringOn",false) ), 
00058   bladeOn( conf_.getUntrackedParameter<bool>("bladeOn",false) ), 
00059   diskOn( conf_.getUntrackedParameter<bool>("diskOn",false) ),
00060   smileyOn(conf_.getUntrackedParameter<bool>("smileyOn",false) ),
00061   bigEventSize( conf_.getUntrackedParameter<int>("bigEventSize",100) )
00062 {
00063    theDMBE = edm::Service<DQMStore>().operator->();
00064    LogInfo ("PixelDQM") << "SiPixelClusterSource::SiPixelClusterSource: Got DQM BackEnd interface"<<endl;
00065 }
00066 
00067 
00068 SiPixelClusterSource::~SiPixelClusterSource()
00069 {
00070    // do anything here that needs to be done at desctruction time
00071    // (e.g. close files, deallocate resources etc.)
00072   LogInfo ("PixelDQM") << "SiPixelClusterSource::~SiPixelClusterSource: Destructor"<<endl;
00073 
00074   std::map<uint32_t,SiPixelClusterModule*>::iterator struct_iter;
00075   for (struct_iter = thePixelStructure.begin() ; struct_iter != thePixelStructure.end() ; struct_iter++){
00076     delete struct_iter->second;
00077     struct_iter->second = 0;
00078   }
00079 }
00080 
00081 
00082 void SiPixelClusterSource::beginJob(){
00083   firstRun = true;
00084 }
00085 
00086 void SiPixelClusterSource::beginRun(const edm::Run& r, const edm::EventSetup& iSetup){
00087 
00088   LogInfo ("PixelDQM") << " SiPixelClusterSource::beginJob - Initialisation ... " << std::endl;
00089   LogInfo ("PixelDQM") << "Mod/Lad/Lay/Phi " << modOn << "/" << ladOn << "/" 
00090             << layOn << "/" << phiOn << std::endl;
00091   LogInfo ("PixelDQM") << "Blade/Disk/Ring" << bladeOn << "/" << diskOn << "/" 
00092             << ringOn << std::endl;
00093   LogInfo ("PixelDQM") << "2DIM IS " << twoDimOn << "\n";
00094   LogInfo ("PixelDQM") << "Smiley (Cluster sizeY vs. Cluster eta) is " << smileyOn << "\n";
00095 
00096   if(firstRun){
00097     eventNo = 0;
00098     lumSec = 0;
00099     nLumiSecs = 0;
00100     nBigEvents = 0;
00101     // Build map
00102     buildStructure(iSetup);
00103     // Book Monitoring Elements
00104     bookMEs();
00105     // Book occupancy maps in global coordinates for all clusters:
00106     theDMBE->setCurrentFolder("Pixel/Clusters/OffTrack");
00107     //bpix
00108     meClPosLayer1 = theDMBE->book2D("position_siPixelClusters_Layer_1","Clusters Layer1;Global Z (cm);Global #phi",200,-30.,30.,128,-3.2,3.2);
00109     meClPosLayer2 = theDMBE->book2D("position_siPixelClusters_Layer_2","Clusters Layer2;Global Z (cm);Global #phi",200,-30.,30.,128,-3.2,3.2);
00110     meClPosLayer3 = theDMBE->book2D("position_siPixelClusters_Layer_3","Clusters Layer3;Global Z (cm);Global #phi",200,-30.,30.,128,-3.2,3.2);
00111     //fpix
00112     meClPosDisk1pz = theDMBE->book2D("position_siPixelClusters_pz_Disk_1","Clusters +Z Disk1;Global X (cm);Global Y (cm)",80,-20.,20.,80,-20.,20.);
00113     meClPosDisk2pz = theDMBE->book2D("position_siPixelClusters_pz_Disk_2","Clusters +Z Disk2;Global X (cm);Global Y (cm)",80,-20.,20.,80,-20.,20.);
00114     meClPosDisk1mz = theDMBE->book2D("position_siPixelClusters_mz_Disk_1","Clusters -Z Disk1;Global X (cm);Global Y (cm)",80,-20.,20.,80,-20.,20.);
00115     meClPosDisk2mz = theDMBE->book2D("position_siPixelClusters_mz_Disk_2","Clusters -Z Disk2;Global X (cm);Global Y (cm)",80,-20.,20.,80,-20.,20.);
00116     
00117     firstRun = false;
00118   }
00119 }
00120 
00121 
00122 void SiPixelClusterSource::endJob(void){
00123   if(saveFile){
00124     LogInfo ("PixelDQM") << " SiPixelClusterSource::endJob - Saving Root File " << std::endl;
00125     std::string outputFile = conf_.getParameter<std::string>("outputFile");
00126     theDMBE->save( outputFile.c_str() );
00127   }
00128 }
00129 
00130 //------------------------------------------------------------------
00131 // Method called for every event
00132 //------------------------------------------------------------------
00133 void SiPixelClusterSource::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00134 {
00135   eventNo++;
00136   
00137   if(modOn){
00138     MonitorElement* meReset = theDMBE->get("Pixel/Clusters/OffTrack/position_siPixelClusters_Layer_1");
00139     MonitorElement* meReset1 = theDMBE->get("Pixel/Clusters/OffTrack/position_siPixelClusters_Layer_2");
00140     MonitorElement* meReset2 = theDMBE->get("Pixel/Clusters/OffTrack/position_siPixelClusters_Layer_3");
00141     MonitorElement* meReset3 = theDMBE->get("Pixel/Clusters/OffTrack/position_siPixelClusters_mz_Disk_1");
00142     MonitorElement* meReset4 = theDMBE->get("Pixel/Clusters/OffTrack/position_siPixelClusters_mz_Disk_2");
00143     MonitorElement* meReset5 = theDMBE->get("Pixel/Clusters/OffTrack/position_siPixelClusters_pz_Disk_1");
00144     MonitorElement* meReset6 = theDMBE->get("Pixel/Clusters/OffTrack/position_siPixelClusters_pz_Disk_2");
00145     if(meReset && meReset->getEntries()>150000){
00146       meReset->Reset();
00147       meReset1->Reset();
00148       meReset2->Reset();
00149       meReset3->Reset();
00150       meReset4->Reset();
00151       meReset5->Reset();
00152       meReset6->Reset();
00153     }
00154   }
00155   
00156   // get input data
00157   edm::Handle< edmNew::DetSetVector<SiPixelCluster> >  input;
00158   iEvent.getByLabel( src_, input );
00159 
00160   edm::ESHandle<TrackerGeometry> pDD;
00161   iSetup.get<TrackerDigiGeometryRecord> ().get (pDD);
00162   const TrackerGeometry* tracker = &(* pDD);
00163 //  const PixelGeomDetUnit* theGeomDet = dynamic_cast<const PixelGeomDetUnit*> ( tracker->idToDet(detId) );
00164 
00165   //float iOrbitSec = iEvent.orbitNumber()/11223.;
00166   //int bx = iEvent.bunchCrossing();
00167   //long long tbx = (long long)iEvent.orbitNumber() * 3564 + bx;
00168   int lumiSection = (int)iEvent.luminosityBlock();
00169   int nEventFpixClusters = 0;
00170 
00171 
00172   std::map<uint32_t,SiPixelClusterModule*>::iterator struct_iter;
00173   for (struct_iter = thePixelStructure.begin() ; struct_iter != thePixelStructure.end() ; struct_iter++) {
00174     
00175     int numberOfFpixClusters = (*struct_iter).second->fill(*input, tracker,  modOn, 
00176                                                            ladOn, layOn, phiOn, 
00177                                                            bladeOn, diskOn, ringOn, 
00178                                                            twoDimOn, reducedSet, smileyOn);
00179     nEventFpixClusters = nEventFpixClusters + numberOfFpixClusters;    
00180     
00181   }
00182 
00183 //  if(lumiSection>lumSec){ lumSec = lumiSection; nLumiSecs++; }
00184 //  if(nEventFpixClusters>bigEventSize) nBigEvents++;
00185 //  if(nLumiSecs%5==0){
00186 
00187   if(nEventFpixClusters>bigEventSize){
00188     MonitorElement* me = theDMBE->get("Pixel/bigFpixClusterEventRate");
00189     if(me){ 
00190       me->Fill(lumiSection,1./23.);    
00191     }
00192   }
00193   //std::cout<<"nEventFpixClusters: "<<nEventFpixClusters<<" , nLumiSecs: "<<nLumiSecs<<" , nBigEvents: "<<nBigEvents<<std::endl;
00194   
00195   // slow down...
00196   if(slowDown) usleep(10000);
00197   
00198 }
00199 
00200 //------------------------------------------------------------------
00201 // Build data structure
00202 //------------------------------------------------------------------
00203 void SiPixelClusterSource::buildStructure(const edm::EventSetup& iSetup){
00204 
00205   LogInfo ("PixelDQM") <<" SiPixelClusterSource::buildStructure" ;
00206   edm::ESHandle<TrackerGeometry> pDD;
00207   iSetup.get<TrackerDigiGeometryRecord>().get( pDD );
00208 
00209   LogVerbatim ("PixelDQM") << " *** Geometry node for TrackerGeom is  "<<&(*pDD)<<std::endl;
00210   LogVerbatim ("PixelDQM") << " *** I have " << pDD->dets().size() <<" detectors"<<std::endl;
00211   LogVerbatim ("PixelDQM") << " *** I have " << pDD->detTypes().size() <<" types"<<std::endl;
00212   
00213   for(TrackerGeometry::DetContainer::const_iterator it = pDD->dets().begin(); it != pDD->dets().end(); it++){
00214     
00215     if(dynamic_cast<PixelGeomDetUnit*>((*it))!=0){
00216 
00217       DetId detId = (*it)->geographicalId();
00218       const GeomDetUnit      * geoUnit = pDD->idToDetUnit( detId );
00219       const PixelGeomDetUnit * pixDet  = dynamic_cast<const PixelGeomDetUnit*>(geoUnit);
00220       int nrows = (pixDet->specificTopology()).nrows();
00221       int ncols = (pixDet->specificTopology()).ncolumns();
00222 
00223       
00224       if((detId.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel)) ||
00225          (detId.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap))){ 
00226         uint32_t id = detId();
00227         SiPixelClusterModule* theModule = new SiPixelClusterModule(id, ncols, nrows);
00228         if(detId.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel)) {
00229           if(isPIB) continue;
00230           LogDebug ("PixelDQM") << " ---> Adding Barrel Module " <<  detId.rawId() << endl;
00231           thePixelStructure.insert(pair<uint32_t,SiPixelClusterModule*> (id,theModule));
00232         }else if(detId.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap)) {
00233           LogDebug ("PixelDQM") << " ---> Adding Endcap Module " <<  detId.rawId() << endl;
00234           PixelEndcapName::HalfCylinder side = PixelEndcapName(DetId(id)).halfCylinder();
00235           int disk   = PixelEndcapName(DetId(id)).diskName();
00236           int blade  = PixelEndcapName(DetId(id)).bladeName();
00237           int panel  = PixelEndcapName(DetId(id)).pannelName();
00238           int module = PixelEndcapName(DetId(id)).plaquetteName();
00239           char sside[80];  sprintf(sside,  "HalfCylinder_%i",side);
00240           char sdisk[80];  sprintf(sdisk,  "Disk_%i",disk);
00241           char sblade[80]; sprintf(sblade, "Blade_%02i",blade);
00242           char spanel[80]; sprintf(spanel, "Panel_%i",panel);
00243           char smodule[80];sprintf(smodule,"Module_%i",module);
00244           std::string side_str = sside;
00245           std::string disk_str = sdisk;
00246           bool mask = side_str.find("HalfCylinder_1")!=string::npos||
00247                       side_str.find("HalfCylinder_2")!=string::npos||
00248                       side_str.find("HalfCylinder_4")!=string::npos||
00249                       disk_str.find("Disk_2")!=string::npos;
00250           // clutch to take all of FPIX, but no BPIX:
00251           mask = false;
00252           if(isPIB && mask) continue;
00253           thePixelStructure.insert(pair<uint32_t,SiPixelClusterModule*> (id,theModule));
00254         }
00255       }
00256     }
00257   }
00258   LogInfo ("PixelDQM") << " *** Pixel Structure Size " << thePixelStructure.size() << endl;
00259 }
00260 //------------------------------------------------------------------
00261 // Book MEs
00262 //------------------------------------------------------------------
00263 void SiPixelClusterSource::bookMEs(){
00264   
00265   // Get DQM interface
00266   DQMStore* theDMBE = edm::Service<DQMStore>().operator->();
00267   theDMBE->setCurrentFolder("Pixel");
00268   char title[256]; snprintf(title, 256, "Rate of events with >%i FPIX clusters;LumiSection;Rate of large FPIX events per LS [Hz]",bigEventSize);
00269   bigFpixClusterEventRate = theDMBE->book1D("bigFpixClusterEventRate",title,5000,0.,5000.);
00270 
00271 
00272   std::map<uint32_t,SiPixelClusterModule*>::iterator struct_iter;
00273     
00274   SiPixelFolderOrganizer theSiPixelFolder;
00275   
00276   for(struct_iter = thePixelStructure.begin(); struct_iter != thePixelStructure.end(); struct_iter++){
00277     
00279     if(modOn){
00280       if(theSiPixelFolder.setModuleFolder((*struct_iter).first)){
00281         (*struct_iter).second->book( conf_,0,twoDimOn,reducedSet);
00282       } else {
00283         
00284         if(!isPIB) throw cms::Exception("LogicError")
00285           << "[SiPixelClusterSource::bookMEs] Creation of DQM folder failed";
00286       }
00287     }
00288     if(ladOn){
00289       if(theSiPixelFolder.setModuleFolder((*struct_iter).first,1)){
00290         (*struct_iter).second->book( conf_,1,twoDimOn,reducedSet);
00291         } else {
00292         LogDebug ("PixelDQM") << "PROBLEM WITH LADDER-FOLDER\n";
00293       }
00294     }
00295     if(layOn){
00296       if(theSiPixelFolder.setModuleFolder((*struct_iter).first,2)){
00297         (*struct_iter).second->book( conf_,2,twoDimOn,reducedSet);
00298         } else {
00299         LogDebug ("PixelDQM") << "PROBLEM WITH LAYER-FOLDER\n";
00300       }
00301     }
00302     if(phiOn){
00303       if(theSiPixelFolder.setModuleFolder((*struct_iter).first,3)){
00304         (*struct_iter).second->book( conf_,3,twoDimOn,reducedSet);
00305         } else {
00306         LogDebug ("PixelDQM") << "PROBLEM WITH PHI-FOLDER\n";
00307       }
00308     }
00309     if(bladeOn){
00310       if(theSiPixelFolder.setModuleFolder((*struct_iter).first,4)){
00311         (*struct_iter).second->book( conf_,4,twoDimOn,reducedSet);
00312         } else {
00313         LogDebug ("PixelDQM") << "PROBLEM WITH BLADE-FOLDER\n";
00314       }
00315     }
00316     if(diskOn){
00317       if(theSiPixelFolder.setModuleFolder((*struct_iter).first,5)){
00318         (*struct_iter).second->book( conf_,5,twoDimOn,reducedSet);
00319         } else {
00320         LogDebug ("PixelDQM") << "PROBLEM WITH DISK-FOLDER\n";
00321       }
00322     }
00323     if(ringOn){
00324       if(theSiPixelFolder.setModuleFolder((*struct_iter).first,6)){
00325         (*struct_iter).second->book( conf_,6,twoDimOn,reducedSet);
00326         } else {
00327         LogDebug ("PixelDQM") << "PROBLEM WITH RING-FOLDER\n";
00328       }
00329     }
00330     if(smileyOn){
00331       if(theSiPixelFolder.setModuleFolder((*struct_iter).first,7)){
00332         (*struct_iter).second->book( conf_,7,twoDimOn,reducedSet);
00333         } else {
00334         LogDebug ("PixelDQM") << "PROBLEM WITH BARREL-FOLDER\n";
00335       }
00336     }
00337 
00338   }
00339 
00340 }
00341 
00342 //define this as a plug-in
00343 DEFINE_FWK_MODULE(SiPixelClusterSource);