CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch2/src/DQM/SiPixelMonitorRecHit/src/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.26 2010/04/10 08:12:27 elmer 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   reducedSet( conf_.getUntrackedParameter<bool>("reducedSet",false) ),
00059   ladOn( conf_.getUntrackedParameter<bool>("ladOn",false) ), 
00060   layOn( conf_.getUntrackedParameter<bool>("layOn",false) ), 
00061   phiOn( conf_.getUntrackedParameter<bool>("phiOn",false) ), 
00062   ringOn( conf_.getUntrackedParameter<bool>("ringOn",false) ), 
00063   bladeOn( conf_.getUntrackedParameter<bool>("bladeOn",false) ), 
00064   diskOn( conf_.getUntrackedParameter<bool>("diskOn",false) )
00065 {
00066    theDMBE = edm::Service<DQMStore>().operator->();
00067    LogInfo ("PixelDQM") << "SiPixelRecHitSource::SiPixelRecHitSource: Got DQM BackEnd interface"<<endl;
00068 }
00069 
00070 
00071 SiPixelRecHitSource::~SiPixelRecHitSource()
00072 {
00073    // do anything here that needs to be done at desctruction time
00074   // (e.g. close files, deallocate resources etc.)
00075   LogInfo ("PixelDQM") << "SiPixelRecHitSource::~SiPixelRecHitSource: Destructor"<<endl;
00076   std::map<uint32_t,SiPixelRecHitModule*>::iterator struct_iter;
00077   for (struct_iter = thePixelStructure.begin() ; struct_iter != thePixelStructure.end() ; struct_iter++){
00078     delete struct_iter->second;
00079     struct_iter->second = 0;
00080   }
00081 }
00082 
00083 
00084 void SiPixelRecHitSource::beginJob(){
00085   firstRun = true;
00086 }
00087 
00088 
00089 void SiPixelRecHitSource::beginRun(const edm::Run& r, const edm::EventSetup& iSetup){
00090 
00091   LogInfo ("PixelDQM") << " SiPixelRecHitSource::beginJob - Initialisation ... " << std::endl;
00092   LogInfo ("PixelDQM") << "Mod/Lad/Lay/Phi " << modOn << "/" << ladOn << "/" 
00093             << layOn << "/" << phiOn << std::endl;
00094   LogInfo ("PixelDQM") << "Blade/Disk/Ring" << bladeOn << "/" << diskOn << "/" 
00095             << ringOn << std::endl;
00096   LogInfo ("PixelDQM") << "2DIM IS " << twoDimOn << "\n";
00097   
00098   if(firstRun){
00099     eventNo = 0;
00100     // Build map
00101     buildStructure(iSetup);
00102     // Book Monitoring Elements
00103     bookMEs();
00104     firstRun = false;
00105   }
00106 }
00107 
00108 
00109 void SiPixelRecHitSource::endJob(void){
00110 
00111 
00112   if(saveFile){
00113     LogInfo ("PixelDQM") << " SiPixelRecHitSource::endJob - Saving Root File " << std::endl;
00114     std::string outputFile = conf_.getParameter<std::string>("outputFile");
00115     theDMBE->save( outputFile );
00116   }
00117 
00118 }
00119 
00120 //------------------------------------------------------------------
00121 // Method called for every event
00122 //------------------------------------------------------------------
00123 void SiPixelRecHitSource::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00124 {
00125   eventNo++;
00126   //cout << eventNo << endl;
00127   // get input data
00128   edm::Handle<SiPixelRecHitCollection>  recHitColl;
00129   iEvent.getByLabel( src_, recHitColl );
00130 
00131   std::map<uint32_t,SiPixelRecHitModule*>::iterator struct_iter;
00132   for (struct_iter = thePixelStructure.begin() ; struct_iter != thePixelStructure.end() ; struct_iter++) {
00133     uint32_t TheID = (*struct_iter).first;
00134 
00135     SiPixelRecHitCollection::const_iterator match = recHitColl->find(TheID);
00136     
00137       // if( pixelrechitRangeIteratorBegin == pixelrechitRangeIteratorEnd) {cout << "oops" << endl;}
00138       float rechit_x = 0;
00139       float rechit_y = 0;
00140       int rechit_count = 0;
00141 
00142       if (match != recHitColl->end()) {
00143         SiPixelRecHitCollection::DetSet pixelrechitRange = *match;
00144         SiPixelRecHitCollection::DetSet::const_iterator pixelrechitRangeIteratorBegin = pixelrechitRange.begin();
00145         SiPixelRecHitCollection::DetSet::const_iterator pixelrechitRangeIteratorEnd = pixelrechitRange.end();
00146         SiPixelRecHitCollection::DetSet::const_iterator pixeliter = pixelrechitRangeIteratorBegin;
00147 
00148        for ( ; pixeliter != pixelrechitRangeIteratorEnd; pixeliter++) 
00149          {
00150           
00151 
00152           rechit_count++;
00153           //cout << TheID << endl;
00154           SiPixelRecHit::ClusterRef const& clust = pixeliter->cluster();
00155           int sizeX = (*clust).sizeX();
00156           //cout << sizeX << endl;
00157           int sizeY = (*clust).sizeY();
00158           //cout << sizeY << endl;
00159           LocalPoint lp = pixeliter->localPosition();
00160           rechit_x = lp.x();
00161           rechit_y = lp.y();
00162           
00163           LocalError lerr = pixeliter->localPositionError();
00164           float lerr_x = sqrt(lerr.xx());
00165           float lerr_y = sqrt(lerr.yy());
00166           //std::cout << "errors " << lerr_x << " " << lerr_y << std::endl;
00167           //cout << "hh" << endl;
00168           (*struct_iter).second->fill(rechit_x, rechit_y, sizeX, sizeY, lerr_x, lerr_y, 
00169                                       modOn, ladOn, layOn, phiOn, bladeOn, diskOn, ringOn, 
00170                                       twoDimOn, reducedSet);
00171           //cout << "ii" << endl;
00172         
00173         }
00174       }
00175       if(rechit_count > 0) (*struct_iter).second->nfill(rechit_count, modOn, ladOn, layOn, phiOn, bladeOn, diskOn, ringOn);
00176     
00177   }
00178 
00179   // slow down...
00180   if(slowDown) usleep(10000);
00181   
00182 }
00183 
00184 //------------------------------------------------------------------
00185 // Build data structure
00186 //------------------------------------------------------------------
00187 void SiPixelRecHitSource::buildStructure(const edm::EventSetup& iSetup){
00188 
00189   LogInfo ("PixelDQM") <<" SiPixelRecHitSource::buildStructure" ;
00190   edm::ESHandle<TrackerGeometry> pDD;
00191   iSetup.get<TrackerDigiGeometryRecord>().get( pDD );
00192 
00193   LogVerbatim ("PixelDQM") << " *** Geometry node for TrackerGeom is  "<<&(*pDD)<<std::endl;
00194   LogVerbatim ("PixelDQM") << " *** I have " << pDD->dets().size() <<" detectors"<<std::endl;
00195   LogVerbatim ("PixelDQM") << " *** I have " << pDD->detTypes().size() <<" types"<<std::endl;
00196   
00197   for(TrackerGeometry::DetContainer::const_iterator it = pDD->dets().begin(); it != pDD->dets().end(); it++){
00198     
00199     if(dynamic_cast<PixelGeomDetUnit*>((*it))!=0){
00200 
00201       DetId detId = (*it)->geographicalId();
00202       // const GeomDetUnit      * geoUnit = pDD->idToDetUnit( detId );
00203       //const PixelGeomDetUnit * pixDet  = dynamic_cast<const PixelGeomDetUnit*>(geoUnit);
00204 
00205           
00206           
00207               // SiPixelRecHitModule *theModule = new SiPixelRecHitModule(id, rechit_x, rechit_y, x_res, y_res, x_pull, y_pull);
00208         
00209         
00210             if((detId.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel)) ||
00211                (detId.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap))){ 
00212               uint32_t id = detId();
00213               SiPixelRecHitModule* theModule = new SiPixelRecHitModule(id);
00214               if(detId.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel)) {
00215                 if(isPIB) continue;
00216                 LogDebug ("PixelDQM") << " ---> Adding Barrel Module " <<  detId.rawId() << endl;
00217                 thePixelStructure.insert(pair<uint32_t,SiPixelRecHitModule*> (id,theModule));
00218                 
00219               } else if(detId.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap)) {
00220                 LogDebug ("PixelDQM") << " ---> Adding Endcap Module " <<  detId.rawId() << endl;
00221                 PixelEndcapName::HalfCylinder side = PixelEndcapName(DetId(id)).halfCylinder();
00222                 int disk   = PixelEndcapName(DetId(id)).diskName();
00223                 int blade  = PixelEndcapName(DetId(id)).bladeName();
00224                 int panel  = PixelEndcapName(DetId(id)).pannelName();
00225                 int module = PixelEndcapName(DetId(id)).plaquetteName();
00226 
00227                 char sside[80];  sprintf(sside,  "HalfCylinder_%i",side);
00228                 char sdisk[80];  sprintf(sdisk,  "Disk_%i",disk);
00229                 char sblade[80]; sprintf(sblade, "Blade_%02i",blade);
00230                 char spanel[80]; sprintf(spanel, "Panel_%i",panel);
00231                 char smodule[80];sprintf(smodule,"Module_%i",module);
00232                 std::string side_str = sside;
00233                 std::string disk_str = sdisk;
00234                 bool mask = side_str.find("HalfCylinder_1")!=string::npos||
00235                             side_str.find("HalfCylinder_2")!=string::npos||
00236                             side_str.find("HalfCylinder_4")!=string::npos||
00237                             disk_str.find("Disk_2")!=string::npos;
00238                 if(isPIB && mask) continue;
00239         
00240                 thePixelStructure.insert(pair<uint32_t,SiPixelRecHitModule*> (id,theModule));
00241               }
00242             }
00243         }           
00244   }
00245 
00246   LogInfo ("PixelDQM") << " *** Pixel Structure Size " << thePixelStructure.size() << endl;
00247 }
00248 //------------------------------------------------------------------
00249 // Book MEs
00250 //------------------------------------------------------------------
00251 void SiPixelRecHitSource::bookMEs(){
00252   
00253   std::map<uint32_t,SiPixelRecHitModule*>::iterator struct_iter;
00254     
00255   SiPixelFolderOrganizer theSiPixelFolder;
00256   
00257   for(struct_iter = thePixelStructure.begin(); struct_iter != thePixelStructure.end(); struct_iter++){
00258     
00260     if(modOn){
00261       if(theSiPixelFolder.setModuleFolder((*struct_iter).first)){
00262         (*struct_iter).second->book( conf_,0,twoDimOn, reducedSet);
00263       } else {
00264         if(!isPIB) throw cms::Exception("LogicError")
00265           << "[SiPixelDigiSource::bookMEs] Creation of DQM folder failed";
00266       }
00267     }
00268     if(ladOn){
00269       if(theSiPixelFolder.setModuleFolder((*struct_iter).first,1)){
00270         (*struct_iter).second->book( conf_,1,twoDimOn, reducedSet);
00271         } else {
00272         LogDebug ("PixelDQM") << "PROBLEM WITH LADDER-FOLDER\n";
00273       }
00274     }
00275     if(layOn){
00276       if(theSiPixelFolder.setModuleFolder((*struct_iter).first,2)){
00277         (*struct_iter).second->book( conf_,2,twoDimOn, reducedSet);
00278         } else {
00279         LogDebug ("PixelDQM") << "PROBLEM WITH LAYER-FOLDER\n";
00280       }
00281     }
00282     if(phiOn){
00283       if(theSiPixelFolder.setModuleFolder((*struct_iter).first,3)){
00284         (*struct_iter).second->book( conf_,3,twoDimOn, reducedSet);
00285         } else {
00286         LogDebug ("PixelDQM") << "PROBLEM WITH PHI-FOLDER\n";
00287       }
00288     }
00289     if(bladeOn){
00290       if(theSiPixelFolder.setModuleFolder((*struct_iter).first,4)){
00291         (*struct_iter).second->book( conf_,4,twoDimOn, reducedSet);
00292         } else {
00293         LogDebug ("PixelDQM") << "PROBLEM WITH BLADE-FOLDER\n";
00294       }
00295     }
00296     if(diskOn){
00297       if(theSiPixelFolder.setModuleFolder((*struct_iter).first,5)){
00298         (*struct_iter).second->book( conf_,5,twoDimOn, reducedSet);
00299         } else {
00300         LogDebug ("PixelDQM") << "PROBLEM WITH DISK-FOLDER\n";
00301       }
00302     }
00303     if(ringOn){
00304       if(theSiPixelFolder.setModuleFolder((*struct_iter).first,6)){
00305         (*struct_iter).second->book( conf_,6,twoDimOn, reducedSet);
00306         } else {
00307         LogDebug ("PixelDQM") << "PROBLEM WITH RING-FOLDER\n";
00308       }
00309     }
00310 
00311   }
00312 
00313 }
00314 
00315 //define this as a plug-in
00316 DEFINE_FWK_MODULE(SiPixelRecHitSource);