Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-08 08:16:01

0001 // -*- C++ -*-
0002 //
0003 // Package:    SiStripTools
0004 // Class:      DetIdSelectorTest
0005 //
0006 /**\class DetIdSelectorTest DetIdSelectorTest.cc DPGAnalysis/SiStripTools/plugins/DetIdSelectorTest.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Andrea Venturi
0015 //         Created:  Tue Jul 19 11:56:00 CEST 2009
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 // user include files
0023 #include <vector>
0024 #include <string>
0025 
0026 #include "FWCore/Framework/interface/Frameworkfwd.h"
0027 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0028 
0029 #include "FWCore/Framework/interface/Event.h"
0030 #include "FWCore/Framework/interface/MakerMacros.h"
0031 
0032 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0033 
0034 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0035 
0036 #include "FWCore/ServiceRegistry/interface/Service.h"
0037 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0038 
0039 #include "Geometry/TrackerNumberingBuilder/interface/utils.h"
0040 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0041 #include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h"
0042 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0043 
0044 #include "CalibTracker/SiPixelESProducers/interface/SiPixelDetInfoFileReader.h"
0045 #include "CommonTools/UtilAlgos/interface/DetIdSelector.h"
0046 #include "FWCore/ParameterSet/interface/FileInPath.h"
0047 
0048 //******** Single include for the TkMap *************
0049 #include "DQM/SiStripCommon/interface/TkHistoMap.h"
0050 #include "CommonTools/TrackerMap/interface/TrackerMap.h"
0051 //***************************************************
0052 
0053 //
0054 // class decleration
0055 //
0056 
0057 class DetIdSelectorTest : public edm::one::EDAnalyzer<> {
0058 public:
0059   explicit DetIdSelectorTest(const edm::ParameterSet&);
0060   ~DetIdSelectorTest() override;
0061 
0062 private:
0063   void beginJob() override;
0064   void analyze(const edm::Event&, const edm::EventSetup&) override;
0065   void endJob() override;
0066 
0067   // ----------member data ---------------------------
0068 
0069   std::vector<DetIdSelector> detidsels_;
0070   std::unique_ptr<TkHistoMap> tkhisto_;
0071   TrackerMap tkmap_;
0072 
0073   edm::ESGetToken<TkDetMap, TrackerTopologyRcd> tkDetMapToken_;
0074   edm::ESGetToken<GeometricDet, IdealGeometryRecord> geomDetToken_;
0075 };
0076 
0077 //
0078 // constants, enums and typedefs
0079 //
0080 
0081 //
0082 // static data member definitions
0083 //
0084 
0085 //
0086 // constructors and destructor
0087 //
0088 DetIdSelectorTest::DetIdSelectorTest(const edm::ParameterSet& iConfig)
0089     : detidsels_(), tkhisto_(nullptr), tkmap_(), tkDetMapToken_(esConsumes()), geomDetToken_(esConsumes()) {
0090   //now do what ever initialization is needed
0091 
0092   std::vector<edm::ParameterSet> selconfigs = iConfig.getParameter<std::vector<edm::ParameterSet> >("selections");
0093 
0094   for (std::vector<edm::ParameterSet>::const_iterator selconfig = selconfigs.begin(); selconfig != selconfigs.end();
0095        ++selconfig) {
0096     DetIdSelector selection(*selconfig);
0097     detidsels_.push_back(selection);
0098   }
0099 
0100   tkmap_.setPalette(1);
0101   tkmap_.addPixel(true);
0102 }
0103 
0104 DetIdSelectorTest::~DetIdSelectorTest() {
0105   // do anything here that needs to be done at desctruction time
0106   // (e.g. close files, deallocate resources etc.)
0107 }
0108 
0109 //
0110 // member functions
0111 //
0112 
0113 // ------------ method called to for each event  ------------
0114 void DetIdSelectorTest::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0115   using namespace edm;
0116 
0117   if (!tkhisto_) {
0118     tkhisto_ = std::make_unique<TkHistoMap>(&iSetup.getData(tkDetMapToken_), "SelectorTest", "SelectorTest", -1);
0119   }
0120 
0121   {
0122     const auto detids = TrackerGeometryUtils::getSiStripDetIds(iSetup.getData(geomDetToken_));
0123 
0124     for (std::vector<uint32_t>::const_iterator detid = detids.begin(); detid != detids.end(); ++detid) {
0125       LogDebug("DetID") << *detid;
0126       int index = 0;
0127       for (std::vector<DetIdSelector>::const_iterator detidsel = detidsels_.begin(); detidsel != detidsels_.end();
0128            ++detidsel) {
0129         if (detidsel->isSelected(*detid)) {
0130           LogDebug("selected") << "Selected by selection " << index;
0131           unsigned int det = *detid;
0132           tkhisto_->add(det, index);
0133           tkmap_.fill_current_val(det, index);
0134         }
0135         ++index;
0136       }
0137     }
0138   }
0139 
0140   {
0141     edm::FileInPath fp("CalibTracker/SiPixelESProducers/data/PixelSkimmedGeometry.txt");
0142 
0143     SiPixelDetInfoFileReader pxlreader(fp.fullPath());
0144     const std::vector<uint32_t>& detids = pxlreader.getAllDetIds();
0145 
0146     for (std::vector<uint32_t>::const_iterator detid = detids.begin(); detid != detids.end(); ++detid) {
0147       LogDebug("DetID") << *detid;
0148       int index = 0;
0149       for (std::vector<DetIdSelector>::const_iterator detidsel = detidsels_.begin(); detidsel != detidsels_.end();
0150            ++detidsel) {
0151         if (detidsel->isSelected(*detid)) {
0152           LogDebug("selected") << "Selected by selection " << index;
0153           unsigned int det = *detid;
0154           //       tkhisto_->add(det,index);
0155           tkmap_.fill_current_val(det, index);
0156         }
0157         ++index;
0158       }
0159     }
0160   }
0161 
0162   /*
0163      edm::ESHandle<TrackerGeometry> pDD;
0164      iSetup.get<TrackerDigiGeometryRecord>().get( pDD );
0165      
0166      for (TrackerGeometry::DetContainer::const_iterator it = pDD->dets().begin(); it != pDD->dets().end(); it++){
0167      
0168      if(dynamic_cast<PixelGeomDetUnit*>((*it))!=0){
0169      DetId detId = (*it)->geographicalId();
0170      LogDebug("DetID") << detId.rawId();
0171      int index=0;
0172      for(std::vector<DetIdSelector>::const_iterator detidsel=detidsels_.begin();detidsel!=detidsels_.end();++detidsel) {
0173      if(detidsel->isSelected(detId)) {
0174      LogDebug("selected") << " Selected by selection " << index;
0175      //  tkhisto_->add(det,index);
0176      tkmap_.fill_current_val(detId.rawId(),index);
0177      }
0178      ++index;
0179      }
0180      
0181      }
0182      
0183      }
0184    */
0185 }
0186 
0187 // ------------ method called once each job just before starting event loop  ------------
0188 void DetIdSelectorTest::beginJob() {}
0189 
0190 // ------------ method called once each job just after ending the event loop  ------------
0191 void DetIdSelectorTest::endJob() {
0192   //  tkhisto_->dumpInTkMap(&tkmap);
0193   std::string mapname = "SelectorTest.png";
0194   tkmap_.save(true, 0, 0, mapname, 5700, 2400);
0195 
0196   std::string rootmapname = "TKMap_Selectortest.root";
0197   tkhisto_->save(rootmapname);
0198 }
0199 
0200 //define this as a plug-in
0201 DEFINE_FWK_MODULE(DetIdSelectorTest);