CMS 3D CMS Logo

SiPixelRecHitSource.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    SiPixelMonitorRecHits
00004 // Class:      SiPixelRecHitSource
00005 // 
00014 //
00015 // Original Author:  Vincenzo Chiochia
00016 //         Created:  
00017 // $Id: SiPixelRecHitSource.cc,v 1.13 2008/10/13 19:04:33 krose Exp $
00018 //
00019 //
00020 // Adapted by:  Keith Rose
00021 //      For use in SiPixelMonitorClient for RecHits
00022 // Updated by: Lukas Wehrli
00023 // for pixel offline DQM 
00024 
00025 #include "DQM/SiPixelMonitorRecHit/interface/SiPixelRecHitSource.h"
00026 // Framework
00027 #include "FWCore/ServiceRegistry/interface/Service.h"
00028 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00029 // DQM Framework
00030 #include "DQM/SiPixelCommon/interface/SiPixelFolderOrganizer.h"
00031 #include "DQMServices/Core/interface/DQMStore.h"
00032 // Geometry
00033 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00034 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00035 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h"
00036 // DataFormats
00037 #include "DataFormats/DetId/interface/DetId.h"
00038 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
00039 #include "DataFormats/SiPixelDetId/interface/PixelBarrelName.h"
00040 #include "DataFormats/SiPixelDetId/interface/PixelEndcapName.h"
00041 
00042 
00043 //
00044 #include <string>
00045 #include <stdlib.h>
00046 #include <iostream>
00047 using namespace std;
00048 using namespace edm;
00049 
00050 SiPixelRecHitSource::SiPixelRecHitSource(const edm::ParameterSet& iConfig) :
00051   conf_(iConfig),
00052   src_( conf_.getParameter<edm::InputTag>( "src" ) ),
00053   saveFile( conf_.getUntrackedParameter<bool>("saveFile",false) ),
00054   isPIB( conf_.getUntrackedParameter<bool>("isPIB",false) ),
00055   slowDown( conf_.getUntrackedParameter<bool>("slowDown",false) ),
00056   modOn( conf_.getUntrackedParameter<bool>("modOn",true) ),
00057   twoDimOn( conf_.getUntrackedParameter<bool>("twoDimOn",true) ),
00058   ladOn( conf_.getUntrackedParameter<bool>("ladOn",false) ), 
00059   layOn( conf_.getUntrackedParameter<bool>("layOn",false) ), 
00060   phiOn( conf_.getUntrackedParameter<bool>("phiOn",false) ), 
00061   ringOn( conf_.getUntrackedParameter<bool>("ringOn",false) ), 
00062   bladeOn( conf_.getUntrackedParameter<bool>("bladeOn",false) ), 
00063   diskOn( conf_.getUntrackedParameter<bool>("diskOn",false) )
00064 {
00065    theDMBE = edm::Service<DQMStore>().operator->();
00066    LogInfo ("PixelDQM") << "SiPixelRecHitSource::SiPixelRecHitSource: Got DQM BackEnd interface"<<endl;
00067 }
00068 
00069 
00070 SiPixelRecHitSource::~SiPixelRecHitSource()
00071 {
00072    // do anything here that needs to be done at desctruction time
00073   // (e.g. close files, deallocate resources etc.)
00074   LogInfo ("PixelDQM") << "SiPixelRecHitSource::~SiPixelRecHitSource: Destructor"<<endl;
00075 }
00076 
00077 
00078 void SiPixelRecHitSource::beginJob(const edm::EventSetup& iSetup){
00079 
00080   LogInfo ("PixelDQM") << " SiPixelRecHitSource::beginJob - Initialisation ... " << std::endl;
00081   LogInfo ("PixelDQM") << "Mod/Lad/Lay/Phi " << modOn << "/" << ladOn << "/" 
00082             << layOn << "/" << phiOn << std::endl;
00083   LogInfo ("PixelDQM") << "Blade/Disk/Ring" << bladeOn << "/" << diskOn << "/" 
00084             << ringOn << std::endl;
00085   LogInfo ("PixelDQM") << "2DIM IS " << twoDimOn << "\n";
00086   eventNo = 0;
00087         
00088   // Build map
00089   buildStructure(iSetup);
00090         
00091   // Book Monitoring Elements
00092   bookMEs();
00093 
00094 }
00095 
00096 
00097 void SiPixelRecHitSource::endJob(void){
00098 
00099 
00100   if(saveFile){
00101     LogInfo ("PixelDQM") << " SiPixelRecHitSource::endJob - Saving Root File " << std::endl;
00102     std::string outputFile = conf_.getParameter<std::string>("outputFile");
00103     theDMBE->save( outputFile );
00104   }
00105 
00106 }
00107 
00108 //------------------------------------------------------------------
00109 // Method called for every event
00110 //------------------------------------------------------------------
00111 void SiPixelRecHitSource::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00112 {
00113   eventNo++;
00114   //cout << eventNo << endl;
00115   // get input data
00116   edm::Handle<SiPixelRecHitCollection>  recHitColl;
00117   iEvent.getByLabel( src_, recHitColl );
00118 
00119   std::map<uint32_t,SiPixelRecHitModule*>::iterator struct_iter;
00120   for (struct_iter = thePixelStructure.begin() ; struct_iter != thePixelStructure.end() ; struct_iter++) {
00121     uint32_t TheID = (*struct_iter).first;
00122         
00123     SiPixelRecHitCollection::range pixelrechitRange = (recHitColl.product())->get(TheID);
00124     SiPixelRecHitCollection::const_iterator pixelrechitRangeIteratorBegin = pixelrechitRange.first;
00125     
00126     SiPixelRecHitCollection::const_iterator pixelrechitRangeIteratorEnd = pixelrechitRange.second;
00127     SiPixelRecHitCollection::const_iterator pixeliter = pixelrechitRangeIteratorBegin;
00128 
00129       // if( pixelrechitRangeIteratorBegin == pixelrechitRangeIteratorEnd) {cout << "oops" << endl;}
00130       float rechit_x = 0;
00131       float rechit_y = 0;
00132       float rechit_count = 0;
00133   for ( ; pixeliter != pixelrechitRangeIteratorEnd; pixeliter++) 
00134         {
00135           
00136 
00137           rechit_count++;
00138           //cout << TheID << endl;
00139           SiPixelRecHit::ClusterRef const& clust = pixeliter->cluster();
00140           int sizeX = (*clust).sizeX();
00141           //cout << sizeX << endl;
00142           int sizeY = (*clust).sizeY();
00143           //cout << sizeY << endl;
00144           LocalPoint lp = pixeliter->localPosition();
00145           rechit_x = lp.x();
00146           rechit_y = lp.y();
00147           
00148           LocalError lerr = pixeliter->localPositionError();
00149           //  float lerr_x = sqrt(lerr.xx());
00150           //  float lerr_y = sqrt(lerr.yy());
00151           //cout << "hh" << endl;
00152           (*struct_iter).second->fill(rechit_x, rechit_y, sizeX, sizeY,modOn, ladOn, layOn, phiOn, bladeOn, diskOn, ringOn, twoDimOn);
00153           //cout << "ii" << endl;
00154         
00155         }
00156             (*struct_iter).second->nfill(rechit_count, modOn, ladOn, layOn, phiOn, bladeOn, diskOn, ringOn);
00157     
00158   }
00159 
00160   // slow down...
00161   if(slowDown) usleep(10000);
00162   
00163 }
00164 
00165 //------------------------------------------------------------------
00166 // Build data structure
00167 //------------------------------------------------------------------
00168 void SiPixelRecHitSource::buildStructure(const edm::EventSetup& iSetup){
00169 
00170   LogInfo ("PixelDQM") <<" SiPixelRecHitSource::buildStructure" ;
00171   edm::ESHandle<TrackerGeometry> pDD;
00172   iSetup.get<TrackerDigiGeometryRecord>().get( pDD );
00173 
00174   LogVerbatim ("PixelDQM") << " *** Geometry node for TrackerGeom is  "<<&(*pDD)<<std::endl;
00175   LogVerbatim ("PixelDQM") << " *** I have " << pDD->dets().size() <<" detectors"<<std::endl;
00176   LogVerbatim ("PixelDQM") << " *** I have " << pDD->detTypes().size() <<" types"<<std::endl;
00177   
00178   for(TrackerGeometry::DetContainer::const_iterator it = pDD->dets().begin(); it != pDD->dets().end(); it++){
00179     
00180     if(dynamic_cast<PixelGeomDetUnit*>((*it))!=0){
00181 
00182       DetId detId = (*it)->geographicalId();
00183       // const GeomDetUnit      * geoUnit = pDD->idToDetUnit( detId );
00184       //const PixelGeomDetUnit * pixDet  = dynamic_cast<const PixelGeomDetUnit*>(geoUnit);
00185 
00186           
00187           
00188               // SiPixelRecHitModule *theModule = new SiPixelRecHitModule(id, rechit_x, rechit_y, x_res, y_res, x_pull, y_pull);
00189         
00190         
00191               if(detId.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel)) {
00192                 if(isPIB) continue;
00193                 LogDebug ("PixelDQM") << " ---> Adding Barrel Module " <<  detId.rawId() << endl;
00194                 uint32_t id = detId();
00195                 SiPixelRecHitModule* theModule = new SiPixelRecHitModule(id);
00196                 thePixelStructure.insert(pair<uint32_t,SiPixelRecHitModule*> (id,theModule));
00197                 
00198               } else if(detId.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap)) {
00199                 LogDebug ("PixelDQM") << " ---> Adding Endcap Module " <<  detId.rawId() << endl;
00200                 uint32_t id = detId();
00201                 SiPixelRecHitModule* theModule = new SiPixelRecHitModule(id);
00202 
00203                 PixelEndcapName::HalfCylinder side = PixelEndcapName::PixelEndcapName(DetId::DetId(id)).halfCylinder();
00204                 int disk   = PixelEndcapName::PixelEndcapName(DetId::DetId(id)).diskName();
00205                 int blade  = PixelEndcapName::PixelEndcapName(DetId::DetId(id)).bladeName();
00206                 int panel  = PixelEndcapName::PixelEndcapName(DetId::DetId(id)).pannelName();
00207                 int module = PixelEndcapName::PixelEndcapName(DetId::DetId(id)).plaquetteName();
00208 
00209                 char sside[80];  sprintf(sside,  "HalfCylinder_%i",side);
00210                 char sdisk[80];  sprintf(sdisk,  "Disk_%i",disk);
00211                 char sblade[80]; sprintf(sblade, "Blade_%02i",blade);
00212                 char spanel[80]; sprintf(spanel, "Panel_%i",panel);
00213                 char smodule[80];sprintf(smodule,"Module_%i",module);
00214                 std::string side_str = sside;
00215                 std::string disk_str = sdisk;
00216                 bool mask = side_str.find("HalfCylinder_1")!=string::npos||
00217                             side_str.find("HalfCylinder_2")!=string::npos||
00218                             side_str.find("HalfCylinder_4")!=string::npos||
00219                             disk_str.find("Disk_2")!=string::npos;
00220                 if(isPIB && mask) continue;
00221         
00222                 thePixelStructure.insert(pair<uint32_t,SiPixelRecHitModule*> (id,theModule));
00223               }
00224       
00225         }           
00226   }
00227 
00228   LogInfo ("PixelDQM") << " *** Pixel Structure Size " << thePixelStructure.size() << endl;
00229 }
00230 //------------------------------------------------------------------
00231 // Book MEs
00232 //------------------------------------------------------------------
00233 void SiPixelRecHitSource::bookMEs(){
00234   
00235   std::map<uint32_t,SiPixelRecHitModule*>::iterator struct_iter;
00236   theDMBE->setVerbose(0);
00237     
00238   SiPixelFolderOrganizer theSiPixelFolder;
00239   
00240   for(struct_iter = thePixelStructure.begin(); struct_iter != thePixelStructure.end(); struct_iter++){
00241     
00243     if(modOn){
00244       if(theSiPixelFolder.setModuleFolder((*struct_iter).first)){
00245         (*struct_iter).second->book( conf_,0,twoDimOn);
00246       } else {
00247         if(!isPIB) throw cms::Exception("LogicError")
00248           << "[SiPixelDigiSource::bookMEs] Creation of DQM folder failed";
00249       }
00250     }
00251     if(ladOn){
00252       if(theSiPixelFolder.setModuleFolder((*struct_iter).first,1)){
00253         (*struct_iter).second->book( conf_,1,twoDimOn);
00254         } else {
00255         LogDebug ("PixelDQM") << "PROBLEM WITH LADDER-FOLDER\n";
00256       }
00257     }
00258     if(layOn){
00259       if(theSiPixelFolder.setModuleFolder((*struct_iter).first,2)){
00260         (*struct_iter).second->book( conf_,2,twoDimOn);
00261         } else {
00262         LogDebug ("PixelDQM") << "PROBLEM WITH LAYER-FOLDER\n";
00263       }
00264     }
00265     if(phiOn){
00266       if(theSiPixelFolder.setModuleFolder((*struct_iter).first,3)){
00267         (*struct_iter).second->book( conf_,3,twoDimOn);
00268         } else {
00269         LogDebug ("PixelDQM") << "PROBLEM WITH PHI-FOLDER\n";
00270       }
00271     }
00272     if(bladeOn){
00273       if(theSiPixelFolder.setModuleFolder((*struct_iter).first,4)){
00274         (*struct_iter).second->book( conf_,4,twoDimOn);
00275         } else {
00276         LogDebug ("PixelDQM") << "PROBLEM WITH BLADE-FOLDER\n";
00277       }
00278     }
00279     if(diskOn){
00280       if(theSiPixelFolder.setModuleFolder((*struct_iter).first,5)){
00281         (*struct_iter).second->book( conf_,5,twoDimOn);
00282         } else {
00283         LogDebug ("PixelDQM") << "PROBLEM WITH DISK-FOLDER\n";
00284       }
00285     }
00286     if(ringOn){
00287       if(theSiPixelFolder.setModuleFolder((*struct_iter).first,6)){
00288         (*struct_iter).second->book( conf_,6,twoDimOn);
00289         } else {
00290         LogDebug ("PixelDQM") << "PROBLEM WITH RING-FOLDER\n";
00291       }
00292     }
00293 
00294   }
00295 
00296 }
00297 
00298 //define this as a plug-in
00299 DEFINE_FWK_MODULE(SiPixelRecHitSource);

Generated on Tue Jun 9 17:33:25 2009 for CMSSW by  doxygen 1.5.4