CMS 3D CMS Logo

SiPixelVCalReader.cc
Go to the documentation of this file.
1 // system includes
2 #include <cstdio>
3 #include <iomanip> // std::setw
4 #include <iostream>
5 #include <sys/time.h>
6 
7 // user includes
29 
30 // ROOT includes
31 #include "TFile.h"
32 #include "TH2F.h"
33 #include "TROOT.h"
34 #include "TTree.h"
35 
36 class SiPixelVCalReader : public edm::one::EDAnalyzer<edm::one::SharedResources> {
37 public:
38  explicit SiPixelVCalReader(const edm::ParameterSet&);
39  ~SiPixelVCalReader() override;
40  void analyze(const edm::Event&, const edm::EventSetup&) override;
41 
42 private:
43  // es tokens
48 
49  const bool printdebug_;
50  const bool useSimRcd_;
51 
52  TH1F* slopeBPix_;
53  TH1F* slopeFPix_;
54  TH1F* offsetBPix_;
55  TH1F* offsetFPix_;
56 };
57 
58 using namespace cms;
59 
61  : siPixelVCalSimToken_(esConsumes()),
62  siPixelVCalToken_(esConsumes()),
63  tkGeomToken_(esConsumes()),
64  tkTopoToken_(esConsumes()),
65  printdebug_(iConfig.getUntrackedParameter<bool>("printDebug", false)),
66  useSimRcd_(iConfig.getParameter<bool>("useSimRcd")) {
67  usesResource(TFileService::kSharedResource);
68 }
69 
71 
73  const SiPixelVCal* siPixelVCal;
74 
75  // Get record & file service
76  if (useSimRcd_) {
77  siPixelVCal = &iSetup.getData(siPixelVCalSimToken_);
78  } else {
79  siPixelVCal = &iSetup.getData(siPixelVCalToken_);
80  }
81  edm::LogInfo("SiPixelVCalReader") << "[SiPixelVCalReader::analyze] End Reading SiPixelVCal" << std::endl;
83 
84  // Retrieve tracker topology from geometry
85  const TrackerTopology* const tTopo = &iSetup.getData(tkTopoToken_);
86 
87  // Retrieve old style tracker geometry from geometry
88  const TrackerGeometry* pDD = &iSetup.getData(tkGeomToken_);
89  edm::LogPrint("SiPixelVCalReader") << " There are " << pDD->detUnits().size() << " modules" << std::endl;
90 
91  // Phase
92  bool phase1 = true;
93 
94  // Prepare tree
95  TTree* tree = new TTree("tree", "tree");
96  uint32_t detid, subdet, layer, ladder, side, disk, ring;
97  double slope, offset;
98  tree->Branch("detid", &detid, "detid/I");
99  tree->Branch("subdet", &subdet, "subdet/I");
100  tree->Branch("layer", &layer, "layer/I");
101  tree->Branch("ladder", &ladder, "ladder/I");
102  tree->Branch("side", &side, "side/I");
103  tree->Branch("disk", &disk, "disk/I");
104  tree->Branch("ring", &ring, "ring/I");
105  tree->Branch("slope", &slope, "slope/D");
106  tree->Branch("offset", &offset, "offset/D");
107 
108  // Prepare histograms
109  slopeBPix_ = fs->make<TH1F>("VCalSlopeBarrelPixel", "VCalSlopeBarrelPixel", 150, 0, 100);
110  slopeFPix_ = fs->make<TH1F>("VCalSlopeForwardPixel", "VCalSlopeForwardPixel", 150, 0, 100);
111  offsetBPix_ = fs->make<TH1F>("VCalOffsetBarrelPixel", "VCalOffsetBarrelPixel", 200, -900, 100);
112  offsetFPix_ = fs->make<TH1F>("VCalOffsetForwardPixel", "VCalOffsetForwardPixel", 200, -900, 100);
113  std::map<unsigned int, SiPixelVCal::VCal> vcal = siPixelVCal->getSlopeAndOffset();
114  std::map<unsigned int, SiPixelVCal::VCal>::const_iterator it;
115 
116  // Fill histograms
117  edm::LogPrint("SiPixelVCalReader") << std::setw(12) << "detid" << std::setw(8) << "subdet" << std::setw(8) << "layer"
118  << std::setw(8) << "disk" << std::setw(14) << "VCal slope" << std::setw(8)
119  << "offset" << std::endl;
120  for (it = vcal.begin(); it != vcal.end(); it++) {
121  detid = it->first;
122  slope = it->second.slope;
123  offset = it->second.offset;
124  const DetId detIdObj(detid);
125  PixelEndcapName fpix(detid, tTopo, phase1);
126  subdet = detIdObj.subdetId();
127  layer = tTopo->pxbLayer(detIdObj); // 1, 2, 3, 4
128  ladder = tTopo->pxbLadder(detIdObj); // 1-12/28/44/64
129  side = tTopo->pxfSide(detIdObj); // 1, 2
130  disk = tTopo->pxfDisk(detIdObj); // 1, 2, 3
131  ring = fpix.ringName(); // 1 (lower), 2 (upper)
132  edm::LogPrint("SiPixelVCalReader") << std::setw(12) << detid << std::setw(8) << subdet << std::setw(8) << layer
133  << std::setw(8) << disk << std::setw(14) << slope << std::setw(8) << offset
134  << std::endl;
135  // edm::LogPrint("SiPixelVCalReader") << "detid " << detid << ", subdet " << subdet << ", layer " <<
136  // layer << ", disk " << disk
137  // << ", VCal slope " << slope << ", offset " << offset <<
138  // std::endl;
139  // edm::LogInfo("SiPixelVCalReader") << "detid " << detid << ", subdet " <<
140  // subdet << ", layer " << layer
141  // << ", VCal slope " << slope << ", offset
142  // " << offset;
143  if (subdet == static_cast<int>(PixelSubdetector::PixelBarrel)) {
144  slopeBPix_->Fill(slope);
145  offsetBPix_->Fill(offset);
146  } else if (subdet == static_cast<int>(PixelSubdetector::PixelEndcap)) {
147  slopeFPix_->Fill(slope);
148  offsetFPix_->Fill(offset);
149  }
150  tree->Fill();
151  }
152 }
static const std::string kSharedResource
Definition: TFileService.h:76
const edm::ESGetToken< SiPixelVCal, SiPixelVCalRcd > siPixelVCalToken_
void analyze(const edm::Event &, const edm::EventSetup &) override
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
unsigned int pxbLayer(const DetId &id) const
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tkGeomToken_
int ringName() const
ring Id
~SiPixelVCalReader() override
static const double slope[3]
const DetContainer & detUnits() const override
Returm a vector of all GeomDet.
unsigned int pxbLadder(const DetId &id) const
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tkTopoToken_
const edm::ESGetToken< SiPixelVCal, SiPixelVCalSimRcd > siPixelVCalSimToken_
unsigned int pxfDisk(const DetId &id) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
Log< level::Warning, true > LogPrint
Namespace of DDCMS conversion namespace.
Log< level::Info, false > LogInfo
Definition: DetId.h:17
unsigned int pxfSide(const DetId &id) const
const std::map< unsigned int, VCal > & getSlopeAndOffset() const
Definition: SiPixelVCal.h:23
Definition: tree.py:1
SiPixelVCalReader(const edm::ParameterSet &)