Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-17 01:40:51

0001 // system includes
0002 #include <cstdio>
0003 #include <iomanip>  // std::setw
0004 #include <iostream>
0005 #include <sys/time.h>
0006 
0007 // user includes
0008 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0009 #include "CondFormats/DataRecord/interface/SiPixelVCalRcd.h"
0010 #include "CondFormats/DataRecord/interface/SiPixelVCalSimRcd.h"
0011 #include "CondFormats/SiPixelObjects/interface/SiPixelVCal.h"
0012 #include "DataFormats/DetId/interface/DetId.h"
0013 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
0014 #include "DataFormats/TrackerCommon/interface/PixelBarrelName.h"
0015 #include "DataFormats/TrackerCommon/interface/PixelEndcapName.h"
0016 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0017 #include "FWCore/Framework/interface/Event.h"
0018 #include "FWCore/Framework/interface/EventSetup.h"
0019 #include "FWCore/Framework/interface/Frameworkfwd.h"
0020 #include "FWCore/Framework/interface/MakerMacros.h"
0021 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0022 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0023 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0024 #include "FWCore/ServiceRegistry/interface/Service.h"
0025 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0026 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0027 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0028 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0029 
0030 // ROOT includes
0031 #include "TFile.h"
0032 #include "TH2F.h"
0033 #include "TROOT.h"
0034 #include "TTree.h"
0035 
0036 class SiPixelVCalReader : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0037 public:
0038   explicit SiPixelVCalReader(const edm::ParameterSet&);
0039   ~SiPixelVCalReader() override;
0040   void analyze(const edm::Event&, const edm::EventSetup&) override;
0041 
0042 private:
0043   // es tokens
0044   const edm::ESGetToken<SiPixelVCal, SiPixelVCalSimRcd> siPixelVCalSimToken_;
0045   const edm::ESGetToken<SiPixelVCal, SiPixelVCalRcd> siPixelVCalToken_;
0046   const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> tkGeomToken_;
0047   const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tkTopoToken_;
0048 
0049   const bool printdebug_;
0050   const bool useSimRcd_;
0051 
0052   TH1F* slopeBPix_;
0053   TH1F* slopeFPix_;
0054   TH1F* offsetBPix_;
0055   TH1F* offsetFPix_;
0056 };
0057 
0058 using namespace cms;
0059 
0060 SiPixelVCalReader::SiPixelVCalReader(const edm::ParameterSet& iConfig)
0061     : siPixelVCalSimToken_(esConsumes()),
0062       siPixelVCalToken_(esConsumes()),
0063       tkGeomToken_(esConsumes()),
0064       tkTopoToken_(esConsumes()),
0065       printdebug_(iConfig.getUntrackedParameter<bool>("printDebug", false)),
0066       useSimRcd_(iConfig.getParameter<bool>("useSimRcd")) {
0067   usesResource(TFileService::kSharedResource);
0068 }
0069 
0070 SiPixelVCalReader::~SiPixelVCalReader() = default;
0071 
0072 void SiPixelVCalReader::analyze(const edm::Event& e, const edm::EventSetup& iSetup) {
0073   const SiPixelVCal* siPixelVCal;
0074 
0075   // Get record & file service
0076   if (useSimRcd_) {
0077     siPixelVCal = &iSetup.getData(siPixelVCalSimToken_);
0078   } else {
0079     siPixelVCal = &iSetup.getData(siPixelVCalToken_);
0080   }
0081   edm::LogInfo("SiPixelVCalReader") << "[SiPixelVCalReader::analyze] End Reading SiPixelVCal" << std::endl;
0082   edm::Service<TFileService> fs;
0083 
0084   // Retrieve tracker topology from geometry
0085   const TrackerTopology* const tTopo = &iSetup.getData(tkTopoToken_);
0086 
0087   // Retrieve old style tracker geometry from geometry
0088   const TrackerGeometry* pDD = &iSetup.getData(tkGeomToken_);
0089   edm::LogPrint("SiPixelVCalReader") << " There are " << pDD->detUnits().size() << " modules" << std::endl;
0090 
0091   // Phase
0092   bool phase1 = true;
0093 
0094   // Prepare tree
0095   TTree* tree = new TTree("tree", "tree");
0096   uint32_t detid, subdet, layer, ladder, side, disk, ring;
0097   double slope, offset;
0098   tree->Branch("detid", &detid, "detid/I");
0099   tree->Branch("subdet", &subdet, "subdet/I");
0100   tree->Branch("layer", &layer, "layer/I");
0101   tree->Branch("ladder", &ladder, "ladder/I");
0102   tree->Branch("side", &side, "side/I");
0103   tree->Branch("disk", &disk, "disk/I");
0104   tree->Branch("ring", &ring, "ring/I");
0105   tree->Branch("slope", &slope, "slope/D");
0106   tree->Branch("offset", &offset, "offset/D");
0107 
0108   // Prepare histograms
0109   slopeBPix_ = fs->make<TH1F>("VCalSlopeBarrelPixel", "VCalSlopeBarrelPixel", 150, 0, 100);
0110   slopeFPix_ = fs->make<TH1F>("VCalSlopeForwardPixel", "VCalSlopeForwardPixel", 150, 0, 100);
0111   offsetBPix_ = fs->make<TH1F>("VCalOffsetBarrelPixel", "VCalOffsetBarrelPixel", 200, -900, 100);
0112   offsetFPix_ = fs->make<TH1F>("VCalOffsetForwardPixel", "VCalOffsetForwardPixel", 200, -900, 100);
0113   std::map<unsigned int, SiPixelVCal::VCal> vcal = siPixelVCal->getSlopeAndOffset();
0114   std::map<unsigned int, SiPixelVCal::VCal>::const_iterator it;
0115 
0116   // Fill histograms
0117   edm::LogPrint("SiPixelVCalReader") << std::setw(12) << "detid" << std::setw(8) << "subdet" << std::setw(8) << "layer"
0118                                      << std::setw(8) << "disk" << std::setw(14) << "VCal slope" << std::setw(8)
0119                                      << "offset" << std::endl;
0120   for (it = vcal.begin(); it != vcal.end(); it++) {
0121     detid = it->first;
0122     slope = it->second.slope;
0123     offset = it->second.offset;
0124     const DetId detIdObj(detid);
0125     PixelEndcapName fpix(detid, tTopo, phase1);
0126     subdet = detIdObj.subdetId();
0127     layer = tTopo->pxbLayer(detIdObj);    // 1, 2, 3, 4
0128     ladder = tTopo->pxbLadder(detIdObj);  // 1-12/28/44/64
0129     side = tTopo->pxfSide(detIdObj);      // 1, 2
0130     disk = tTopo->pxfDisk(detIdObj);      // 1, 2, 3
0131     ring = fpix.ringName();               // 1 (lower), 2 (upper)
0132     edm::LogPrint("SiPixelVCalReader") << std::setw(12) << detid << std::setw(8) << subdet << std::setw(8) << layer
0133                                        << std::setw(8) << disk << std::setw(14) << slope << std::setw(8) << offset
0134                                        << std::endl;
0135     // edm::LogPrint("SiPixelVCalReader") << "detid " << detid << ", subdet " << subdet << ", layer " <<
0136     // layer << ", disk " << disk
0137     //          << ", VCal slope " << slope << ", offset " << offset <<
0138     //          std::endl;
0139     // edm::LogInfo("SiPixelVCalReader") << "detid " << detid << ", subdet " <<
0140     // subdet << ", layer " << layer
0141     //                                  << ", VCal slope " << slope << ", offset
0142     //                                  " << offset;
0143     if (subdet == static_cast<int>(PixelSubdetector::PixelBarrel)) {
0144       slopeBPix_->Fill(slope);
0145       offsetBPix_->Fill(offset);
0146     } else if (subdet == static_cast<int>(PixelSubdetector::PixelEndcap)) {
0147       slopeFPix_->Fill(slope);
0148       offsetFPix_->Fill(offset);
0149     }
0150     tree->Fill();
0151   }
0152 }
0153 DEFINE_FWK_MODULE(SiPixelVCalReader);