File indexing completed on 2022-06-03 00:58:54
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <array>
0010 #include <memory>
0011 #include <fstream>
0012 #include <utility>
0013 #include <iostream>
0014 #include <vector>
0015 #include <map>
0016 #include <string>
0017
0018
0019 #include "CalibTracker/SiStripCommon/interface/TkDetMap.h"
0020 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0021 #include "DataFormats/Common/interface/DetSetVectorNew.h"
0022 #include "DataFormats/SiPixelDetId/interface/PXBDetId.h"
0023 #include "DataFormats/SiPixelDetId/interface/PXFDetId.h"
0024 #include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
0025 #include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
0026 #include "DataFormats/TrackReco/interface/Track.h"
0027 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0028 #include "DataFormats/TrackerCommon/interface/PixelBarrelName.h"
0029 #include "DataFormats/TrackerCommon/interface/PixelEndcapName.h"
0030 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0031 #include "FWCore/Framework/interface/ESHandle.h"
0032 #include "FWCore/Framework/interface/Event.h"
0033 #include "FWCore/Framework/interface/Frameworkfwd.h"
0034 #include "FWCore/Framework/interface/MakerMacros.h"
0035 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0036 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0037 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0038 #include "FWCore/ParameterSet/interface/EmptyGroupDescription.h"
0039 #include "FWCore/ParameterSet/interface/allowedValues.h"
0040 #include "FWCore/ServiceRegistry/interface/Service.h"
0041 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0042 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0043
0044
0045 #include "TGraph.h"
0046 #include "TObjString.h"
0047 #include "TObjArray.h"
0048 #include "TH2Poly.h"
0049 #include "TProfile2D.h"
0050 #include "TColor.h"
0051
0052 using namespace edm;
0053
0054 class TrackerRemapper : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0055 public:
0056 explicit TrackerRemapper(const edm::ParameterSet&);
0057 ~TrackerRemapper() override;
0058
0059 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0060
0061 enum PixelLayerEnum {
0062 INVALID = 0,
0063
0064 PXB_L1,
0065 PXB_L2,
0066 PXB_L3,
0067 PXB_L4,
0068
0069 PXF_R1,
0070 PXF_R2
0071 };
0072
0073 enum AnalyzeData {
0074 RECHITS = 1,
0075 DIGIS,
0076 CLUSTERS,
0077 };
0078
0079 enum OpMode { MODE_ANALYZE = 0, MODE_REMAP = 1 };
0080
0081 private:
0082 void beginJob() override;
0083 void analyze(const edm::Event&, const edm::EventSetup&) override;
0084 void endJob() override;
0085
0086 void readVertices(double& minx, double& maxx, double& miny, double& maxy);
0087
0088 void prepareStripNames();
0089 void preparePixelNames();
0090
0091 void bookBins();
0092
0093 template <class T>
0094 void analyzeGeneric(const edm::Event& iEvent, const edm::EDGetTokenT<T>& src);
0095 void analyzeRechits(const edm::Event& iEvent, const edm::EDGetTokenT<reco::TrackCollection>& src);
0096
0097 void fillStripRemap();
0098 void fillPixelRemap(const TrackerGeometry* theTrackerGeometry, const TrackerTopology* tt);
0099 void fillBarrelRemap(TFile* rootFileHandle, const TrackerGeometry* theTrackerGeometry, const TrackerTopology* tt);
0100 void fillEndcapRemap(TFile* rootFileHandle, const TrackerGeometry* theTrackerGeometry, const TrackerTopology* tt);
0101
0102 const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> geomToken_;
0103 const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> topoToken_;
0104 const edm::ESGetToken<TkDetMap, TrackerTopologyRcd> tkDetMapToken_;
0105
0106 edm::Service<TFileService> fs;
0107 const edm::ParameterSet& iConfig;
0108
0109 int m_opMode;
0110 int m_analyzeMode;
0111
0112 std::map<long, TGraph*> m_bins;
0113 std::vector<unsigned> m_detIdVector;
0114
0115 const TkDetMap* m_tkdetmap;
0116
0117 std::map<unsigned, std::string> m_stripHistnameMap;
0118 std::map<unsigned, std::string> m_pixelHistnameMap;
0119 std::map<unsigned, std::string> m_analyzeModeNameMap;
0120
0121 std::string m_stripRemapFile;
0122 std::string m_pixelRemapFile;
0123
0124 std::string m_stripBaseDir, m_stripDesiredHistogram;
0125 std::string m_pixelBaseDir, m_pixelDesiredHistogramBarrel, m_pixelDesiredHistogramDisk;
0126
0127 std::string runString;
0128
0129 TH2Poly* trackerMap{nullptr};
0130
0131 edm::EDGetTokenT<reco::TrackCollection> rechitSrcToken;
0132 edm::EDGetTokenT<edmNew::DetSetVector<SiStripDigi>> digiSrcToken;
0133 edm::EDGetTokenT<edmNew::DetSetVector<SiStripCluster>> clusterSrcToken;
0134 };
0135
0136 template <class T>
0137
0138 void TrackerRemapper::analyzeGeneric(const edm::Event& iEvent, const edm::EDGetTokenT<T>& src)
0139
0140 {
0141 edm::Handle<T> input;
0142 iEvent.getByToken(src, input);
0143
0144 if (!input.isValid()) {
0145 edm::LogError("TrackerRemapper") << "<GENERIC> not found... Aborting...\n";
0146 return;
0147 }
0148
0149 typename T::const_iterator it;
0150 for (it = input->begin(); it != input->end(); ++it) {
0151 auto id = DetId(it->detId());
0152 trackerMap->Fill(TString::Format("%ld", (long)id.rawId()), it->size());
0153 }
0154 }
0155
0156 template <>
0157
0158 void TrackerRemapper::analyzeGeneric(const edm::Event& iEvent, const edm::EDGetTokenT<reco::TrackCollection>& t)
0159
0160 {
0161 analyzeRechits(iEvent, t);
0162 }
0163
0164
0165 TrackerRemapper::TrackerRemapper(const edm::ParameterSet& iConfig)
0166 : geomToken_(esConsumes()),
0167 topoToken_(esConsumes()),
0168 tkDetMapToken_(esConsumes()),
0169 iConfig(iConfig),
0170 m_opMode(iConfig.getParameter<int>("opMode")),
0171 m_analyzeMode(iConfig.getParameter<int>("analyzeMode")) {
0172 usesResource("TFileService");
0173
0174 if (m_opMode == MODE_REMAP) {
0175 m_stripRemapFile = iConfig.getParameter<std::string>("stripRemapFile");
0176 m_stripDesiredHistogram = iConfig.getParameter<std::string>("stripHistogram");
0177 runString = iConfig.getParameter<std::string>("runString");
0178
0179 m_pixelRemapFile = std::string("DQM_V0001_PixelPhase1_R000305516.root");
0180
0181 m_stripBaseDir = std::string("DQMData/Run " + runString + "/SiStrip/Run summary/MechanicalView/");
0182 m_pixelBaseDir = std::string("DQMData/Run " + runString + "/PixelPhase1/Run summary/Phase1_MechanicalView/");
0183
0184 m_pixelDesiredHistogramBarrel = std::string("adc_per_SignedModule_per_SignedLadder");
0185 m_pixelDesiredHistogramDisk = std::string("adc_per_PXDisk_per_SignedBladePanel");
0186
0187 prepareStripNames();
0188 preparePixelNames();
0189 } else if (m_opMode == MODE_ANALYZE) {
0190 m_analyzeModeNameMap[RECHITS] = "# Rechits";
0191 m_analyzeModeNameMap[DIGIS] = "# Digis";
0192 m_analyzeModeNameMap[CLUSTERS] = "# Clusters";
0193
0194 switch (m_analyzeMode) {
0195 case RECHITS:
0196 rechitSrcToken = consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("src"));
0197 break;
0198 case DIGIS:
0199 digiSrcToken = consumes<edmNew::DetSetVector<SiStripDigi>>(iConfig.getParameter<edm::InputTag>("src"));
0200 break;
0201 case CLUSTERS:
0202 clusterSrcToken = consumes<edmNew::DetSetVector<SiStripCluster>>(iConfig.getParameter<edm::InputTag>("src"));
0203 break;
0204 default:
0205 edm::LogError("LogicError") << "Unrecognized analyze mode!" << std::endl;
0206 }
0207 } else {
0208 throw cms::Exception("TrackerRemapper") << "Unrecognized operations mode!" << std::endl;
0209 }
0210
0211
0212 }
0213
0214
0215 void TrackerRemapper::prepareStripNames()
0216
0217 {
0218 m_stripHistnameMap[TkLayerMap::TkLayerEnum::TIB_L1] =
0219 m_stripBaseDir + "TIB/layer_1/" + m_stripDesiredHistogram + "_TIB_L1;1";
0220 m_stripHistnameMap[TkLayerMap::TkLayerEnum::TIB_L2] =
0221 m_stripBaseDir + "TIB/layer_2/" + m_stripDesiredHistogram + "_TIB_L2;1";
0222 m_stripHistnameMap[TkLayerMap::TkLayerEnum::TIB_L3] =
0223 m_stripBaseDir + "TIB/layer_3/" + m_stripDesiredHistogram + "_TIB_L3;1";
0224 m_stripHistnameMap[TkLayerMap::TkLayerEnum::TIB_L4] =
0225 m_stripBaseDir + "TIB/layer_4/" + m_stripDesiredHistogram + "_TIB_L4;1";
0226
0227 m_stripHistnameMap[TkLayerMap::TkLayerEnum::TIDM_D1] =
0228 m_stripBaseDir + "TID/MINUS/wheel_1/" + m_stripDesiredHistogram + "_TIDM_D1;1";
0229 m_stripHistnameMap[TkLayerMap::TkLayerEnum::TIDM_D2] =
0230 m_stripBaseDir + "TID/MINUS/wheel_2/" + m_stripDesiredHistogram + "_TIDM_D2;1";
0231 m_stripHistnameMap[TkLayerMap::TkLayerEnum::TIDM_D3] =
0232 m_stripBaseDir + "TID/MINUS/wheel_3/" + m_stripDesiredHistogram + "_TIDM_D3;1";
0233 m_stripHistnameMap[TkLayerMap::TkLayerEnum::TIDP_D1] =
0234 m_stripBaseDir + "TID/PLUS/wheel_1/" + m_stripDesiredHistogram + "_TIDP_D1;1";
0235 m_stripHistnameMap[TkLayerMap::TkLayerEnum::TIDP_D2] =
0236 m_stripBaseDir + "TID/PLUS/wheel_2/" + m_stripDesiredHistogram + "_TIDP_D2;1";
0237 m_stripHistnameMap[TkLayerMap::TkLayerEnum::TIDP_D3] =
0238 m_stripBaseDir + "TID/PLUS/wheel_3/" + m_stripDesiredHistogram + "_TIDP_D3;1";
0239
0240 m_stripHistnameMap[TkLayerMap::TkLayerEnum::TOB_L1] =
0241 m_stripBaseDir + "TOB/layer_1/" + m_stripDesiredHistogram + "_TOB_L1;1";
0242 m_stripHistnameMap[TkLayerMap::TkLayerEnum::TOB_L2] =
0243 m_stripBaseDir + "TOB/layer_2/" + m_stripDesiredHistogram + "_TOB_L2;1";
0244 m_stripHistnameMap[TkLayerMap::TkLayerEnum::TOB_L3] =
0245 m_stripBaseDir + "TOB/layer_3/" + m_stripDesiredHistogram + "_TOB_L3;1";
0246 m_stripHistnameMap[TkLayerMap::TkLayerEnum::TOB_L4] =
0247 m_stripBaseDir + "TOB/layer_4/" + m_stripDesiredHistogram + "_TOB_L4;1";
0248 m_stripHistnameMap[TkLayerMap::TkLayerEnum::TOB_L5] =
0249 m_stripBaseDir + "TOB/layer_5/" + m_stripDesiredHistogram + "_TOB_L5;1";
0250 m_stripHistnameMap[TkLayerMap::TkLayerEnum::TOB_L6] =
0251 m_stripBaseDir + "TOB/layer_6/" + m_stripDesiredHistogram + "_TOB_L6;1";
0252
0253 m_stripHistnameMap[TkLayerMap::TkLayerEnum::TECM_W1] =
0254 m_stripBaseDir + "TEC/MINUS/wheel_1/" + m_stripDesiredHistogram + "_TECM_W1;1";
0255 m_stripHistnameMap[TkLayerMap::TkLayerEnum::TECM_W2] =
0256 m_stripBaseDir + "TEC/MINUS/wheel_2/" + m_stripDesiredHistogram + "_TECM_W2;1";
0257 m_stripHistnameMap[TkLayerMap::TkLayerEnum::TECM_W3] =
0258 m_stripBaseDir + "TEC/MINUS/wheel_3/" + m_stripDesiredHistogram + "_TECM_W3;1";
0259 m_stripHistnameMap[TkLayerMap::TkLayerEnum::TECM_W4] =
0260 m_stripBaseDir + "TEC/MINUS/wheel_4/" + m_stripDesiredHistogram + "_TECM_W4;1";
0261 m_stripHistnameMap[TkLayerMap::TkLayerEnum::TECM_W5] =
0262 m_stripBaseDir + "TEC/MINUS/wheel_5/" + m_stripDesiredHistogram + "_TECM_W5;1";
0263 m_stripHistnameMap[TkLayerMap::TkLayerEnum::TECM_W6] =
0264 m_stripBaseDir + "TEC/MINUS/wheel_6/" + m_stripDesiredHistogram + "_TECM_W6;1";
0265 m_stripHistnameMap[TkLayerMap::TkLayerEnum::TECM_W7] =
0266 m_stripBaseDir + "TEC/MINUS/wheel_7/" + m_stripDesiredHistogram + "_TECM_W7;1";
0267 m_stripHistnameMap[TkLayerMap::TkLayerEnum::TECM_W8] =
0268 m_stripBaseDir + "TEC/MINUS/wheel_8/" + m_stripDesiredHistogram + "_TECM_W8;1";
0269 m_stripHistnameMap[TkLayerMap::TkLayerEnum::TECM_W9] =
0270 m_stripBaseDir + "TEC/MINUS/wheel_9/" + m_stripDesiredHistogram + "_TECM_W9;1";
0271
0272 m_stripHistnameMap[TkLayerMap::TkLayerEnum::TECP_W1] =
0273 m_stripBaseDir + "TEC/PLUS/wheel_1/" + m_stripDesiredHistogram + "_TECP_W1;1";
0274 m_stripHistnameMap[TkLayerMap::TkLayerEnum::TECP_W2] =
0275 m_stripBaseDir + "TEC/PLUS/wheel_2/" + m_stripDesiredHistogram + "_TECP_W2;1";
0276 m_stripHistnameMap[TkLayerMap::TkLayerEnum::TECP_W3] =
0277 m_stripBaseDir + "TEC/PLUS/wheel_3/" + m_stripDesiredHistogram + "_TECP_W3;1";
0278 m_stripHistnameMap[TkLayerMap::TkLayerEnum::TECP_W4] =
0279 m_stripBaseDir + "TEC/PLUS/wheel_4/" + m_stripDesiredHistogram + "_TECP_W4;1";
0280 m_stripHistnameMap[TkLayerMap::TkLayerEnum::TECP_W5] =
0281 m_stripBaseDir + "TEC/PLUS/wheel_5/" + m_stripDesiredHistogram + "_TECP_W5;1";
0282 m_stripHistnameMap[TkLayerMap::TkLayerEnum::TECP_W6] =
0283 m_stripBaseDir + "TEC/PLUS/wheel_6/" + m_stripDesiredHistogram + "_TECP_W6;1";
0284 m_stripHistnameMap[TkLayerMap::TkLayerEnum::TECP_W7] =
0285 m_stripBaseDir + "TEC/PLUS/wheel_7/" + m_stripDesiredHistogram + "_TECP_W7;1";
0286 m_stripHistnameMap[TkLayerMap::TkLayerEnum::TECP_W8] =
0287 m_stripBaseDir + "TEC/PLUS/wheel_8/" + m_stripDesiredHistogram + "_TECP_W8;1";
0288 m_stripHistnameMap[TkLayerMap::TkLayerEnum::TECP_W9] =
0289 m_stripBaseDir + "TEC/PLUS/wheel_9/" + m_stripDesiredHistogram + "_TECP_W9;1";
0290 }
0291
0292
0293 void TrackerRemapper::preparePixelNames()
0294
0295 {
0296 m_pixelHistnameMap[PixelLayerEnum::PXB_L1] =
0297 m_pixelBaseDir + "PXBarrel/" + m_pixelDesiredHistogramBarrel + "_PXLayer_1;1";
0298 m_pixelHistnameMap[PixelLayerEnum::PXB_L2] =
0299 m_pixelBaseDir + "PXBarrel/" + m_pixelDesiredHistogramBarrel + "_PXLayer_2;1";
0300 m_pixelHistnameMap[PixelLayerEnum::PXB_L3] =
0301 m_pixelBaseDir + "PXBarrel/" + m_pixelDesiredHistogramBarrel + "_PXLayer_3;1";
0302 m_pixelHistnameMap[PixelLayerEnum::PXB_L4] =
0303 m_pixelBaseDir + "PXBarrel/" + m_pixelDesiredHistogramBarrel + "_PXLayer_4;1";
0304
0305 m_pixelHistnameMap[PixelLayerEnum::PXF_R1] =
0306 m_pixelBaseDir + "PXForward/" + m_pixelDesiredHistogramDisk + "_PXRing_1;1";
0307 m_pixelHistnameMap[PixelLayerEnum::PXF_R2] =
0308 m_pixelBaseDir + "PXForward/" + m_pixelDesiredHistogramDisk + "_PXRing_2;1";
0309 }
0310
0311 TrackerRemapper::~TrackerRemapper() {}
0312
0313
0314 void TrackerRemapper::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
0315
0316 {
0317
0318
0319 const TrackerGeometry* theTrackerGeometry = &iSetup.getData(geomToken_);
0320 const TrackerTopology* tt = &iSetup.getData(topoToken_);
0321 m_tkdetmap = &iSetup.getData(tkDetMapToken_);
0322
0323 if (!trackerMap)
0324 bookBins();
0325
0326 if (m_opMode == MODE_ANALYZE) {
0327 switch (m_analyzeMode) {
0328 case AnalyzeData::RECHITS:
0329 analyzeGeneric(iEvent, rechitSrcToken);
0330 break;
0331 case AnalyzeData::DIGIS:
0332 analyzeGeneric(iEvent, digiSrcToken);
0333 break;
0334 case AnalyzeData::CLUSTERS:
0335 analyzeGeneric(iEvent, clusterSrcToken);
0336 break;
0337 default:
0338 edm::LogError("LogicError") << "Unrecognized Analyze mode!" << std::endl;
0339 return;
0340 }
0341 } else if (m_opMode == MODE_REMAP) {
0342 fillStripRemap();
0343 fillPixelRemap(theTrackerGeometry, tt);
0344 }
0345 }
0346
0347
0348 void TrackerRemapper::analyzeRechits(const edm::Event& iEvent, const edm::EDGetTokenT<reco::TrackCollection>& src)
0349
0350 {
0351 edm::Handle<reco::TrackCollection> tracks;
0352 iEvent.getByToken(src, tracks);
0353 if (!tracks.isValid()) {
0354 LogInfo("Analyzer") << "reco::TrackCollection not found... Aborting...\n";
0355 return;
0356 }
0357
0358 for (auto const& track : *tracks) {
0359 auto recHitsBegin = track.recHitsBegin();
0360 for (unsigned i = 0; i < track.recHitsSize(); ++i) {
0361 auto recHit = *(recHitsBegin + i);
0362 if (!recHit->isValid())
0363 continue;
0364
0365 DetId id = recHit->geographicalId();
0366 unsigned subdetId = id.subdetId();
0367
0368
0369 if (subdetId == PixelSubdetector::PixelBarrel || subdetId == PixelSubdetector::PixelEndcap)
0370 continue;
0371
0372
0373 trackerMap->Fill(TString::Format("%ld", (long)id.rawId()), 1);
0374 }
0375 }
0376 }
0377
0378
0379 void TrackerRemapper::bookBins()
0380
0381 {
0382
0383 double minx = 0xFFFFFF, maxx = -0xFFFFFF, miny = 0xFFFFFF, maxy = -0xFFFFFFF;
0384 readVertices(minx, maxx, miny, maxy);
0385
0386 TObject* ghostObj = fs->make<TH2Poly>("ghost", "ghost", -1, 1, -1, 1);
0387
0388 TDirectory* topDir = fs->getBareDirectory();
0389 topDir->cd();
0390
0391 int margin = 50;
0392 std::string mapTitle;
0393 switch (m_opMode) {
0394 case MODE_ANALYZE:
0395 mapTitle = std::string(m_analyzeModeNameMap[m_analyzeMode] + " - " + runString);
0396 break;
0397 case MODE_REMAP:
0398 mapTitle = std::string(m_stripDesiredHistogram + " - " + runString);
0399 break;
0400 }
0401
0402 trackerMap = new TH2Poly("Tracker Map", mapTitle.c_str(), minx - margin, maxx + margin, miny - margin, maxy + margin);
0403 trackerMap->SetFloat();
0404 trackerMap->SetOption("COLZ");
0405 trackerMap->SetStats(false);
0406
0407 for (auto pair : m_bins) {
0408 trackerMap->AddBin(pair.second->Clone());
0409 }
0410
0411 topDir->Add(trackerMap);
0412
0413 ghostObj->Delete();
0414 }
0415
0416
0417 void TrackerRemapper::readVertices(double& minx, double& maxx, double& miny, double& maxy)
0418
0419 {
0420 std::ifstream in;
0421
0422
0423 in.open(edm::FileInPath("DQM/SiStripMonitorClient/data/Geometry/tracker_map_bare").fullPath().c_str());
0424
0425 unsigned count = 0;
0426
0427 if (!in.good()) {
0428 throw cms::Exception("TrackerRemapper") << "Error Reading File" << std::endl;
0429 }
0430 while (in.good()) {
0431 long detid = 0;
0432 double x[5], y[5];
0433
0434 std::string line;
0435 std::getline(in, line);
0436 ++count;
0437
0438 TString string(line);
0439 TObjArray* array = string.Tokenize(" ");
0440 int ix{0}, iy{0};
0441 bool isPixel{false};
0442 for (int i = 0; i < array->GetEntries(); ++i) {
0443 if (i == 0) {
0444 detid = static_cast<TObjString*>(array->At(i))->String().Atoll();
0445
0446
0447 DetId detId(detid);
0448 if (detId.subdetId() == PixelSubdetector::PixelBarrel || detId.subdetId() == PixelSubdetector::PixelEndcap) {
0449 isPixel = true;
0450 break;
0451 }
0452 } else {
0453 if (i % 2 == 0) {
0454 x[ix] = static_cast<TObjString*>(array->At(i))->String().Atof();
0455
0456 if (x[ix] < minx)
0457 minx = x[ix];
0458 if (x[ix] > maxx)
0459 maxx = x[ix];
0460
0461 ++ix;
0462 } else {
0463 y[iy] = static_cast<TObjString*>(array->At(i))->String().Atof();
0464
0465 if (y[iy] < miny)
0466 miny = y[iy];
0467 if (y[iy] > maxy)
0468 maxy = y[iy];
0469
0470 ++iy;
0471 }
0472 }
0473 }
0474
0475 if (isPixel)
0476 continue;
0477
0478 m_detIdVector.push_back(detid);
0479 m_bins[detid] = new TGraph(ix, x, y);
0480 m_bins[detid]->SetName(TString::Format("%ld", detid));
0481 m_bins[detid]->SetTitle(TString::Format("Module ID=%ld", detid));
0482 }
0483 }
0484
0485
0486 void TrackerRemapper::fillStripRemap()
0487
0488 {
0489 int nchX;
0490 int nchY;
0491 double lowX, highX;
0492 double lowY, highY;
0493
0494 TFile* rootFileHandle = new TFile(m_stripRemapFile.c_str());
0495
0496 for (int layer = TkLayerMap::TkLayerEnum::TIB_L1; layer <= TkLayerMap::TkLayerEnum::TECP_W9; ++layer) {
0497 m_tkdetmap->getComponents(layer, nchX, lowX, highX, nchY, lowY, highY);
0498
0499 const TProfile2D* histHandle = (TProfile2D*)rootFileHandle->Get(m_stripHistnameMap[layer].c_str());
0500
0501 if (!histHandle) {
0502 edm::LogError("TrackerRemapper") << "Could not find histogram:\n\t" << m_stripHistnameMap[layer] << std::endl;
0503 return;
0504 }
0505
0506 for (unsigned binx = 1; binx <= (unsigned)nchX; ++binx) {
0507 for (unsigned biny = 1; biny <= (unsigned)nchY; ++biny) {
0508 long rawid = m_tkdetmap->getDetFromBin(layer, binx, biny);
0509
0510 if (rawid)
0511 {
0512 double val = histHandle->GetBinContent(binx, biny);
0513
0514
0515
0516 trackerMap->Fill(TString::Format("%ld", rawid), val);
0517 }
0518 }
0519 }
0520 }
0521
0522 rootFileHandle->Close();
0523 }
0524
0525
0526 void TrackerRemapper::fillPixelRemap(const TrackerGeometry* theTrackerGeometry, const TrackerTopology* tt)
0527
0528 {
0529 TFile* rootFileHandle = new TFile(m_pixelRemapFile.c_str());
0530
0531 if (!rootFileHandle) {
0532 edm::LogError("TrackerRemapper") << "Could not find file:\n\t" << m_pixelRemapFile << std::endl;
0533 return;
0534 }
0535 fillBarrelRemap(rootFileHandle, theTrackerGeometry, tt);
0536 fillEndcapRemap(rootFileHandle, theTrackerGeometry, tt);
0537
0538 rootFileHandle->Close();
0539 }
0540
0541
0542 void TrackerRemapper::fillBarrelRemap(TFile* rootFileHandle,
0543 const TrackerGeometry* theTrackerGeometry,
0544 const TrackerTopology* tt)
0545
0546 {
0547 TrackingGeometry::DetContainer pxb = theTrackerGeometry->detsPXB();
0548
0549 for (auto& i : pxb) {
0550 const GeomDet* det = i;
0551
0552 PXBDetId id = det->geographicalId();
0553 long rawid = id.rawId();
0554
0555 int module = tt->pxbModule(id);
0556 int layer = tt->pxbLayer(id);
0557
0558 int signedOnlineModule = module - 4;
0559 if (signedOnlineModule <= 0)
0560 --signedOnlineModule;
0561
0562 PixelBarrelName pixelBarrelName = PixelBarrelName(id, tt, true);
0563 int onlineShell = pixelBarrelName.shell();
0564
0565 int signedOnlineLadder = ((onlineShell & 1) ? -pixelBarrelName.ladderName() : pixelBarrelName.ladderName());
0566
0567 const TProfile2D* histHandle = (TProfile2D*)rootFileHandle->Get(m_pixelHistnameMap[layer].c_str());
0568
0569 unsigned nx = histHandle->GetNbinsX();
0570 unsigned ny = histHandle->GetNbinsY();
0571
0572 unsigned binX = signedOnlineModule + ((nx + 1) >> 1);
0573 unsigned binY = (signedOnlineLadder) + ((ny + 1) >> 1);
0574
0575 double val = histHandle->GetBinContent(binX, binY);
0576
0577 trackerMap->Fill(TString::Format("%ld", rawid), val);
0578 }
0579 }
0580
0581
0582 void TrackerRemapper::fillEndcapRemap(TFile* rootFileHandle,
0583 const TrackerGeometry* theTrackerGeometry,
0584 const TrackerTopology* tt)
0585
0586 {
0587 TrackingGeometry::DetContainer pxf = theTrackerGeometry->detsPXF();
0588
0589 for (auto& i : pxf) {
0590 const GeomDet* det = i;
0591
0592 PXFDetId id = det->geographicalId();
0593
0594 int side = tt->side(id);
0595 int disk = tt->layer(id);
0596
0597 long rawid = id.rawId();
0598
0599 PixelEndcapName pixelEndcapName = PixelEndcapName(PXFDetId(rawid), tt, true);
0600
0601 unsigned layer = pixelEndcapName.ringName() - 1 + PixelLayerEnum::PXF_R1;
0602 const TProfile2D* histHandle = (TProfile2D*)rootFileHandle->Get(m_pixelHistnameMap[layer].c_str());
0603
0604
0605 unsigned nx = histHandle->GetNbinsX();
0606 unsigned ny = histHandle->GetNbinsY();
0607
0608 int onlineBlade = pixelEndcapName.bladeName();
0609 bool isInnerOnlineBlade = !(pixelEndcapName.halfCylinder() & 1);
0610
0611 int signedOnlineBlade = (isInnerOnlineBlade) ? onlineBlade : -onlineBlade;
0612 int signedDisk = (side == 2) ? disk : -disk;
0613 int pannel = pixelEndcapName.pannelName() - 1;
0614
0615 unsigned binX = signedDisk + ((nx + 1) >> 1);
0616 unsigned binY = (signedOnlineBlade * 2) + (ny >> 1);
0617
0618 double val = histHandle->GetBinContent(binX, binY + pannel);
0619
0620 trackerMap->Fill(TString::Format("%ld", rawid), val);
0621 }
0622 }
0623
0624 void TrackerRemapper::beginJob() {}
0625
0626 void TrackerRemapper::endJob() {}
0627
0628
0629 void TrackerRemapper::fillDescriptions(edm::ConfigurationDescriptions& descriptions)
0630
0631 {
0632 edm::ParameterSetDescription desc;
0633 desc.setComment(
0634 "Creates TH2Poly Strip Tracker maps by either analyzing the event or remapping exising DQM historams");
0635 desc.add<edm::InputTag>("src", edm::InputTag("generalTracks"));
0636 desc.ifValue(edm::ParameterDescription<int>("opMode", 0, true),
0637 0 >> edm::EmptyGroupDescription() or
0638 1 >> (edm::ParameterDescription<std::string>("stripRemapFile", "", true) and
0639 edm::ParameterDescription<std::string>("stripHistogram", "", true) and
0640 edm::ParameterDescription<std::string>("runString", "", true)))
0641 ->setComment("0 for Analyze, 1 for Remap");
0642
0643 desc.ifValue(edm::ParameterDescription<int>("analyzeMode", 1, true), edm::allowedValues<int>(1, 2, 3))
0644 ->setComment("1=Rechits, 2=Digis, 3=Clusters");
0645
0646
0647
0648
0649
0650
0651 descriptions.addWithDefaultLabel(desc);
0652 }
0653
0654
0655 DEFINE_FWK_MODULE(TrackerRemapper);