CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/DPGAnalysis/SiStripTools/plugins/DetIdSelectorTest.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    SiStripTools
00004 // Class:      DetIdSelectorTest
00005 // 
00013 //
00014 // Original Author:  Andrea Venturi
00015 //         Created:  Tue Jul 19 11:56:00 CEST 2009
00016 //
00017 //
00018 
00019 
00020 // system include files
00021 #include <memory>
00022 
00023 // user include files
00024 #include <vector>
00025 #include <string>
00026 
00027 #include "FWCore/Framework/interface/Frameworkfwd.h"
00028 #include "FWCore/Framework/interface/EDAnalyzer.h"
00029 
00030 #include "FWCore/Framework/interface/Event.h"
00031 #include "FWCore/Framework/interface/MakerMacros.h"
00032 
00033 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00034 
00035 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00036 
00037 #include "FWCore/ServiceRegistry/interface/Service.h"
00038 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00039 
00040 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00041 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h"
00042 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00043 
00044 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
00045 #include "CalibTracker/SiPixelESProducers/interface/SiPixelDetInfoFileReader.h"
00046 #include "CommonTools/UtilAlgos/interface/DetIdSelector.h"
00047 #include "FWCore/ParameterSet/interface/FileInPath.h"
00048 
00049 //******** Single include for the TkMap *************
00050 #include "DQM/SiStripCommon/interface/TkHistoMap.h" 
00051 #include "CommonTools/TrackerMap/interface/TrackerMap.h"
00052 //***************************************************
00053 
00054 //
00055 // class decleration
00056 //
00057 
00058 class DetIdSelectorTest : public edm::EDAnalyzer {
00059 public:
00060   explicit DetIdSelectorTest(const edm::ParameterSet&);
00061   ~DetIdSelectorTest();
00062 
00063 
00064 private:
00065   virtual void beginJob() ;
00066   virtual void beginRun(const edm::Run&, const edm::EventSetup&) ;
00067   virtual void endRun(const edm::Run&, const edm::EventSetup&) ;
00068   virtual void analyze(const edm::Event&, const edm::EventSetup&);
00069   virtual void endJob() ;
00070 
00071       // ----------member data ---------------------------
00072 
00073 
00074   std::vector<DetIdSelector> detidsels_;
00075   TkHistoMap *tkhisto_;
00076   TrackerMap tkmap_;
00077 
00078   
00079 };
00080 
00081 //
00082 // constants, enums and typedefs
00083 //
00084 
00085 //
00086 // static data member definitions
00087 //
00088 
00089 //
00090 // constructors and destructor
00091 //
00092 DetIdSelectorTest::DetIdSelectorTest(const edm::ParameterSet& iConfig):
00093   detidsels_(), tkhisto_(new TkHistoMap("SelectorTest","SelectorTest",-1)),tkmap_()
00094 {
00095    //now do what ever initialization is needed
00096 
00097   std::vector<edm::ParameterSet> selconfigs = iConfig.getParameter<std::vector<edm::ParameterSet> >("selections");
00098 
00099   for(std::vector<edm::ParameterSet>::const_iterator selconfig=selconfigs.begin();selconfig!=selconfigs.end();++selconfig) {
00100     DetIdSelector selection(*selconfig);
00101     detidsels_.push_back(selection);
00102   }
00103 
00104   tkmap_.setPalette(1);
00105   tkmap_.addPixel(true);
00106 
00107 }
00108 
00109 
00110 DetIdSelectorTest::~DetIdSelectorTest()
00111 {
00112  
00113    // do anything here that needs to be done at desctruction time
00114    // (e.g. close files, deallocate resources etc.)
00115 
00116 }
00117 
00118 
00119 //
00120 // member functions
00121 //
00122 
00123 // ------------ method called to for each event  ------------
00124 void
00125 DetIdSelectorTest::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00126 {
00127    using namespace edm;
00128    
00129    {
00130      SiStripDetInfoFileReader * reader=edm::Service<SiStripDetInfoFileReader>().operator->();
00131      
00132      //   SiStripDetInfoFileReader reader(edm::FileInPath("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat"));
00133      //   SiStripDetInfoFileReader reader;
00134      
00135      const std::vector<uint32_t>& detids = reader->getAllDetIds();
00136      
00137      for(std::vector<uint32_t>::const_iterator detid=detids.begin();detid!=detids.end();++detid) {
00138        
00139        LogDebug("DetID") << *detid;
00140        int index=0;
00141        for(std::vector<DetIdSelector>::const_iterator detidsel=detidsels_.begin();detidsel!=detidsels_.end();++detidsel) {
00142          if(detidsel->isSelected(*detid)) {
00143            LogDebug("selected") << "Selected by selection " << index;
00144            unsigned int det = *detid;
00145            tkhisto_->add(det,index);
00146            tkmap_.fill_current_val(det,index);
00147          }
00148          ++index;
00149        }
00150        
00151      }
00152    }
00153 
00154    {
00155      edm::FileInPath fp("CalibTracker/SiPixelESProducers/data/PixelSkimmedGeometry.txt");
00156      
00157      SiPixelDetInfoFileReader pxlreader(fp.fullPath());
00158      const std::vector<uint32_t>& detids = pxlreader.getAllDetIds();
00159      
00160      for(std::vector<uint32_t>::const_iterator detid=detids.begin();detid!=detids.end();++detid) {
00161        
00162        LogDebug("DetID") << *detid;
00163        int index=0;
00164        for(std::vector<DetIdSelector>::const_iterator detidsel=detidsels_.begin();detidsel!=detidsels_.end();++detidsel) {
00165          if(detidsel->isSelected(*detid)) {
00166            LogDebug("selected") << "Selected by selection " << index;
00167            unsigned int det = *detid;
00168            //      tkhisto_->add(det,index);
00169            tkmap_.fill_current_val(det,index);
00170          }
00171          ++index;
00172        }
00173        
00174      }
00175    }
00176     
00177  
00178    /*
00179      edm::ESHandle<TrackerGeometry> pDD;
00180      iSetup.get<TrackerDigiGeometryRecord>().get( pDD );
00181      
00182      for (TrackerGeometry::DetContainer::const_iterator it = pDD->dets().begin(); it != pDD->dets().end(); it++){
00183      
00184      if(dynamic_cast<PixelGeomDetUnit*>((*it))!=0){
00185      DetId detId = (*it)->geographicalId();
00186      LogDebug("DetID") << detId.rawId();
00187      int index=0;
00188      for(std::vector<DetIdSelector>::const_iterator detidsel=detidsels_.begin();detidsel!=detidsels_.end();++detidsel) {
00189      if(detidsel->isSelected(detId)) {
00190      LogDebug("selected") << " Selected by selection " << index;
00191      //  tkhisto_->add(det,index);
00192      tkmap_.fill_current_val(detId.rawId(),index);
00193      }
00194      ++index;
00195      }
00196      
00197      }
00198      
00199      }
00200    */   
00201 }
00202 
00203 void 
00204 DetIdSelectorTest::beginRun(const edm::Run& iRun, const edm::EventSetup&)
00205 {}
00206 
00207 void 
00208 DetIdSelectorTest::endRun(const edm::Run& iRun, const edm::EventSetup&)
00209 {
00210 }
00211 
00212 
00213 // ------------ method called once each job just before starting event loop  ------------
00214 void 
00215 DetIdSelectorTest::beginJob()
00216 {
00217 
00218 }
00219 
00220 // ------------ method called once each job just after ending the event loop  ------------
00221 void 
00222 DetIdSelectorTest::endJob() {
00223 
00224 
00225   //  tkhisto_->dumpInTkMap(&tkmap);
00226   std::string mapname = "SelectorTest.png";
00227   tkmap_.save(true,0,0,mapname);
00228 
00229   std::string rootmapname = "TKMap_Selectortest.root";
00230   tkhisto_->save(rootmapname);
00231 }
00232 
00233 
00234 //define this as a plug-in
00235 DEFINE_FWK_MODULE(DetIdSelectorTest);