From 557310e69750b6a6248f34bb1f7730a62ddba1e9 Mon Sep 17 00:00:00 2001 From: mmusich Date: Tue, 12 Jan 2021 16:26:47 +0100 Subject: [PATCH] modernize SiPixelPhase1Analyzer --- .../interface/SiPixelPhase1Analyzer.h | 359 ++-- DQM/SiPixelPhase1Analyzer/interface/mat4.h | 235 ++- .../plugins/SiPixelPhase1Analyzer.cc | 1527 ++++++++--------- 3 files changed, 1039 insertions(+), 1082 deletions(-) diff --git a/DQM/SiPixelPhase1Analyzer/interface/SiPixelPhase1Analyzer.h b/DQM/SiPixelPhase1Analyzer/interface/SiPixelPhase1Analyzer.h index f88256e0d7b95..9bb7c966b828f 100644 --- a/DQM/SiPixelPhase1Analyzer/interface/SiPixelPhase1Analyzer.h +++ b/DQM/SiPixelPhase1Analyzer/interface/SiPixelPhase1Analyzer.h @@ -1,177 +1,182 @@ -#ifndef SiPixelPhase1Analyzer__H_ -#define SiPixelPhase1Analyzer__H_ - -/**\class SiPixelPhase1Analyzer SiPixelPhase1Analyzer.cc EJTerm/SiPixelPhase1Analyzer/plugins/SiPixelPhase1Analyzer.cc - - Description: [one line class summary] - - Implementation: - [Notes on implementation] -*/ -// -// Original Author: Pawel Jurgielewicz -// Created: Tue, 21 Feb 2017 09:42:19 GMT -// -// - -// system include files -#include - -// #include -#include -#include - -#include - -#include -#include - - -// user include files -#include "DQM/SiPixelPhase1Analyzer/interface/mat4.h" - -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/one/EDAnalyzer.h" - -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/MakerMacros.h" - -#include "FWCore/ParameterSet/interface/ParameterSet.h" - -#include "FWCore/Framework/interface/ESHandle.h" - -#include "FWCore/MessageLogger/interface/MessageLogger.h" - -#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h" -#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" -#include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h" -#include "Geometry/CommonTopologies/interface/PixelTopology.h" - -#include "DataFormats/SiPixelDetId/interface/PXBDetId.h" -#include "DataFormats/SiPixelDetId/interface/PXFDetId.h" -#include "DataFormats/SiPixelDetId/interface/PixelEndcapName.h" -#include "DataFormats/SiPixelDetId/interface/PixelBarrelName.h" -#include "DataFormats/TrackerCommon/interface/TrackerTopology.h" -#include "DataFormats/TrackReco/interface/Track.h" -#include "DataFormats/TrackReco/interface/TrackFwd.h" -#include "DataFormats/GeometrySurface/interface/RectangularPlaneBounds.h" -#include "DataFormats/GeometrySurface/interface/TrapezoidalPlaneBounds.h" -#include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHitCollection.h" -#include "RecoTracker/TkDetLayers/src/DiskSectorBounds.h" - -#include "FWCore/ServiceRegistry/interface/Service.h" -#include "CommonTools/UtilAlgos/interface/TFileService.h" - -#include "TH2.h" -#include "TProfile2D.h" -#include "TH2Poly.h" -#include "TGraph.h" - -#define CODE_FORWARD(s, d, b) ((unsigned short)((b << 8) + (d << 4) + s)) - -// #define DEBUG_MODE - -// -// class declaration -// - -// If the analyzer does not use TFileService, please remove -// the template argument to the base class so the class inherits -// from edm::one::EDAnalyzer<> and also remove the line from -// constructor "usesResource("TFileService");" -// This will improve performance in multithreaded jobs. - -using namespace std; -using namespace edm; - -enum OperationMode {MODE_ANALYZE = 0, MODE_REMAP = 1}; - -class SiPixelPhase1Analyzer : public edm::one::EDAnalyzer { -public: - explicit SiPixelPhase1Analyzer(const edm::ParameterSet&); - ~SiPixelPhase1Analyzer(); - - static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); - -private: - virtual void beginJob() override; - virtual void analyze(const edm::Event&, const edm::EventSetup&) override; - virtual void endJob() override; - - void BookHistograms(); - - void BookBarrelHistograms(TDirectory* currentDir, const string& currentHistoName); - void BookForwardHistograms(TDirectory* currentDir, const string& currentHistoName); - - void BookBins(ESHandle < TrackerGeometry >& theTrackerGeometry, const TrackerTopology* tt); - void BookBarrelBins(ESHandle < TrackerGeometry >& theTrackerGeometry, const TrackerTopology* tt); - void BookForwardBins(ESHandle < TrackerGeometry >& theTrackerGeometry, const TrackerTopology* tt); - - void SaveDetectorVertices(const TrackerTopology* tt); - - void FillBins(edm::Handle *tracks, ESHandle < TrackerGeometry >& theTrackerGeometry, const TrackerTopology* tt); - - void FillBarrelBinsAnalyze(ESHandle < TrackerGeometry >& theTrackerGeometry, const TrackerTopology* tt, unsigned rawId, const GlobalPoint& globalPoint); - void FillForwardBinsAnalyze(ESHandle < TrackerGeometry >& theTrackerGeometry, const TrackerTopology* tt, unsigned rawId, const GlobalPoint& globalPoint); - - void FillBarrelBinsRemap(ESHandle < TrackerGeometry >& theTrackerGeometry, const TrackerTopology* tt); - void FillForwardBinsRemap(ESHandle < TrackerGeometry >& theTrackerGeometry, const TrackerTopology* tt); - - // ----------member data --------------------------- - OperationMode opMode; - - edm::EDGetTokenT tracksToken; - - string debugFileName; - std::ofstream debugFile; - - edm::Service < TFileService > fs; - - bool firstEvent; - - map bins, binsSummary; - - map< string, vector > th2PolyBarrel; - map< string, TH2Poly* > th2PolyBarrelSummary; - -#ifdef DEBUG_MODE - map< string, vector >th2PolyBarrelDebug; -#endif - - map< string, vector > pxfTh2PolyForward; - map< string, TH2Poly* > pxfTh2PolyForwardSummary; - -#ifdef DEBUG_MODE - map< string, vector > pxfTh2PolyForwardDebug; -#endif - - mat4 orthoProjectionMatrix; - - struct complementaryElements - { - mat4 mat[2]; - unsigned rawId[2]; - }; - // used to hold information about elements': ids & matrices which are of the same side, disk and barrel but different panel - // to build trapezoidal ring elements - map mapOfComplementaryElements; - - //Input root file handle; - TFile *rootFileHandle; - - // read input histograms - vector isBarrelSource; - vector analazedRootFileName; - vector pathToHistograms; - vector baseHistogramName; - - // temporal functionality - void SaveDetectorData(bool isBarrel, unsigned rawId, int shell_hc, int layer_disk, int ladder_blade) - { - static std::ofstream file("det.data", std::ofstream::out); - - file << isBarrel << "\t" << rawId << "\t" << shell_hc << "\t" << layer_disk << "\t" << ladder_blade << endl; - } -}; - -#endif \ No newline at end of file +#ifndef SiPixelPhase1Analyzer__H_ +#define SiPixelPhase1Analyzer__H_ + +/**\class SiPixelPhase1Analyzer SiPixelPhase1Analyzer.cc EJTerm/SiPixelPhase1Analyzer/plugins/SiPixelPhase1Analyzer.cc + + Description: [one line class summary] + + Implementation: + [Notes on implementation] +*/ +// +// Original Author: Pawel Jurgielewicz +// Created: Tue, 21 Feb 2017 09:42:19 GMT +// +// + +// system include files +#include + +// #include +#include +#include + +#include + +#include +#include + +// user include files +#include "DQM/SiPixelPhase1Analyzer/interface/mat4.h" + +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/one/EDAnalyzer.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" + +#include "FWCore/Framework/interface/ESHandle.h" + +#include "FWCore/MessageLogger/interface/MessageLogger.h" + +#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h" +#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" +#include "Geometry/CommonTopologies/interface/PixelGeomDetUnit.h" +#include "Geometry/CommonTopologies/interface/PixelTopology.h" + +#include "DataFormats/SiPixelDetId/interface/PXBDetId.h" +#include "DataFormats/SiPixelDetId/interface/PXFDetId.h" +#include "DataFormats/TrackerCommon/interface/PixelEndcapName.h" +#include "DataFormats/TrackerCommon/interface/PixelBarrelName.h" +#include "DataFormats/TrackerCommon/interface/TrackerTopology.h" +#include "DataFormats/TrackReco/interface/Track.h" +#include "DataFormats/TrackReco/interface/TrackFwd.h" +#include "DataFormats/GeometrySurface/interface/RectangularPlaneBounds.h" +#include "DataFormats/GeometrySurface/interface/TrapezoidalPlaneBounds.h" +#include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHitCollection.h" +#include "DataFormats/GeometrySurface/interface/DiskSectorBounds.h" + +#include "FWCore/ServiceRegistry/interface/Service.h" +#include "CommonTools/UtilAlgos/interface/TFileService.h" + +#include "TH2.h" +#include "TProfile2D.h" +#include "TH2Poly.h" +#include "TGraph.h" + +#define CODE_FORWARD(s, d, b) ((unsigned short)((b << 8) + (d << 4) + s)) + +// #define DEBUG_MODE + +// +// class declaration +// + +// If the analyzer does not use TFileService, please remove +// the template argument to the base class so the class inherits +// from edm::one::EDAnalyzer<> and also remove the line from +// constructor "usesResource("TFileService");" +// This will improve performance in multithreaded jobs. + +using namespace std; +using namespace edm; + +enum OperationMode { MODE_ANALYZE = 0, MODE_REMAP = 1 }; + +class SiPixelPhase1Analyzer : public edm::one::EDAnalyzer { +public: + explicit SiPixelPhase1Analyzer(const edm::ParameterSet&); + ~SiPixelPhase1Analyzer() override; + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + +private: + void beginJob() override; + void analyze(const edm::Event&, const edm::EventSetup&) override; + void endJob() override; + + void BookHistograms(); + + void BookBarrelHistograms(TDirectory* currentDir, const string& currentHistoName); + void BookForwardHistograms(TDirectory* currentDir, const string& currentHistoName); + + void BookBins(ESHandle& theTrackerGeometry, const TrackerTopology* tt); + void BookBarrelBins(ESHandle& theTrackerGeometry, const TrackerTopology* tt); + void BookForwardBins(ESHandle& theTrackerGeometry, const TrackerTopology* tt); + + void SaveDetectorVertices(const TrackerTopology* tt); + + void FillBins(edm::Handle* tracks, + ESHandle& theTrackerGeometry, + const TrackerTopology* tt); + + void FillBarrelBinsAnalyze(ESHandle& theTrackerGeometry, + const TrackerTopology* tt, + unsigned rawId, + const GlobalPoint& globalPoint); + void FillForwardBinsAnalyze(ESHandle& theTrackerGeometry, + const TrackerTopology* tt, + unsigned rawId, + const GlobalPoint& globalPoint); + + void FillBarrelBinsRemap(ESHandle& theTrackerGeometry, const TrackerTopology* tt); + void FillForwardBinsRemap(ESHandle& theTrackerGeometry, const TrackerTopology* tt); + + // ----------member data --------------------------- + OperationMode opMode; + + edm::EDGetTokenT tracksToken; + + string debugFileName; + std::ofstream debugFile; + + edm::Service fs; + + bool firstEvent; + + map bins, binsSummary; + + map > th2PolyBarrel; + map th2PolyBarrelSummary; + +#ifdef DEBUG_MODE + map > th2PolyBarrelDebug; +#endif + + map > pxfTh2PolyForward; + map pxfTh2PolyForwardSummary; + +#ifdef DEBUG_MODE + map > pxfTh2PolyForwardDebug; +#endif + + mat4 orthoProjectionMatrix; + + struct complementaryElements { + mat4 mat[2]; + unsigned rawId[2]; + }; + // used to hold information about elements': ids & matrices which are of the same side, disk and barrel but different panel + // to build trapezoidal ring elements + map mapOfComplementaryElements; + + //Input root file handle; + TFile* rootFileHandle; + + // read input histograms + vector isBarrelSource; + vector analazedRootFileName; + vector pathToHistograms; + vector baseHistogramName; + + // temporal functionality + void SaveDetectorData(bool isBarrel, unsigned rawId, int shell_hc, int layer_disk, int ladder_blade) { + static std::ofstream file("det.data", std::ofstream::out); + + file << isBarrel << "\t" << rawId << "\t" << shell_hc << "\t" << layer_disk << "\t" << ladder_blade << endl; + } +}; + +#endif diff --git a/DQM/SiPixelPhase1Analyzer/interface/mat4.h b/DQM/SiPixelPhase1Analyzer/interface/mat4.h index af596f54b0901..bc0b608d5051b 100644 --- a/DQM/SiPixelPhase1Analyzer/interface/mat4.h +++ b/DQM/SiPixelPhase1Analyzer/interface/mat4.h @@ -1,123 +1,114 @@ -#ifndef MAT4__H_ -#define MAT4__H_ - -// helper class for matrix operations -// - 4 rows -// - 3 columns -// in math operations behaves like 4x4 matrix with 4th row equal to: [0, 0, 0, 1] -// ! it's just the minimum implementation ! -class mat4 -{ - public: - - float data[12]; - - mat4() {} - - mat4(float r00, float r10, float r20, - float r01, float r11, float r21, - float r02, float r12, float r22, - float x, float y, float z) - { - data[0] = r00; - data[1] = r10; - data[2] = r20; - - data[3] = r01; - data[4] = r11; - data[5] = r21; - - data[6] = r02; - data[7] = r12; - data[8] = r22; - - data[9] = x; - data[10] = y; - data[11] = z; - } - - mat4(const mat4& mat) - { - for (unsigned i = 0; i < 12; ++i) data[i] = mat[i]; - } - - mat4& operator&(const mat4& mat) - { - if (this != &mat) - { - for (unsigned i = 0; i < 12; ++i) data[i] = mat[i]; - } - return *this; - } - - mat4 operator+(const mat4& mat) const - { - mat4 tmp; - for (unsigned i = 0; i < 12; ++i) tmp[i] = (*this)[i] + mat[i]; - - return tmp; - } - - mat4 operator*(float s) const - { - mat4 tmp; - for (unsigned i = 0; i < 12; ++i) tmp[i] = (*this)[i] * s; - - return tmp; - } - - float& operator[](unsigned i) - { - return data[i]; - } - - float operator[](unsigned i) const - { - return data[i]; - } - - void MulVec(const float* vecIn, float* vecOut) - { - for (unsigned i = 0; i < 3; ++i) - { - float temp = 0; - for (unsigned j = 0; j < 3; ++j) - { - temp += data[3 * j + i] * vecIn[j]; - } - vecOut[i] = temp + data[9 + i]; - } - } - void BuildOrthographicMatrix(float left, float right, - float top, float bottom, - float near, float far) - { - float rmli = 1.0f / (right - left); - float rpl = right + left; - - float tmbi = 1.0f / (top - bottom); - float tpb = top + bottom; - - float fmni = 1.0f / (far - near); - float fpn = far + near; - - data[0] = 2.0f * rmli; - data[1] = 0.0f; - data[2] = 0.0f; - - data[3] = 0.0f; - data[4] = 2.0f * tmbi; - data[5] = 0.0f; - - data[6] = 0.0f; - data[7] = 0.0f; - data[8] = -2.0f * fmni; - - data[9] = -rpl * rmli; - data[10] = -tpb * tmbi; - data[11] = -fpn * fmni; - } - -}; - +#ifndef MAT4__H_ +#define MAT4__H_ + +// helper class for matrix operations +// - 4 rows +// - 3 columns +// in math operations behaves like 4x4 matrix with 4th row equal to: [0, 0, 0, 1] +// ! it's just the minimum implementation ! +class mat4 { +public: + float data[12]; + + mat4() {} + + mat4(float r00, + float r10, + float r20, + float r01, + float r11, + float r21, + float r02, + float r12, + float r22, + float x, + float y, + float z) { + data[0] = r00; + data[1] = r10; + data[2] = r20; + + data[3] = r01; + data[4] = r11; + data[5] = r21; + + data[6] = r02; + data[7] = r12; + data[8] = r22; + + data[9] = x; + data[10] = y; + data[11] = z; + } + + mat4(const mat4& mat) { + for (unsigned i = 0; i < 12; ++i) + data[i] = mat[i]; + } + + mat4& operator&(const mat4& mat) { + if (this != &mat) { + for (unsigned i = 0; i < 12; ++i) + data[i] = mat[i]; + } + return *this; + } + + mat4 operator+(const mat4& mat) const { + mat4 tmp; + for (unsigned i = 0; i < 12; ++i) + tmp[i] = (*this)[i] + mat[i]; + + return tmp; + } + + mat4 operator*(float s) const { + mat4 tmp; + for (unsigned i = 0; i < 12; ++i) + tmp[i] = (*this)[i] * s; + + return tmp; + } + + float& operator[](unsigned i) { return data[i]; } + + float operator[](unsigned i) const { return data[i]; } + + void MulVec(const float* vecIn, float* vecOut) { + for (unsigned i = 0; i < 3; ++i) { + float temp = 0; + for (unsigned j = 0; j < 3; ++j) { + temp += data[3 * j + i] * vecIn[j]; + } + vecOut[i] = temp + data[9 + i]; + } + } + void BuildOrthographicMatrix(float left, float right, float top, float bottom, float near, float far) { + float rmli = 1.0f / (right - left); + float rpl = right + left; + + float tmbi = 1.0f / (top - bottom); + float tpb = top + bottom; + + float fmni = 1.0f / (far - near); + float fpn = far + near; + + data[0] = 2.0f * rmli; + data[1] = 0.0f; + data[2] = 0.0f; + + data[3] = 0.0f; + data[4] = 2.0f * tmbi; + data[5] = 0.0f; + + data[6] = 0.0f; + data[7] = 0.0f; + data[8] = -2.0f * fmni; + + data[9] = -rpl * rmli; + data[10] = -tpb * tmbi; + data[11] = -fpn * fmni; + } +}; + #endif \ No newline at end of file diff --git a/DQM/SiPixelPhase1Analyzer/plugins/SiPixelPhase1Analyzer.cc b/DQM/SiPixelPhase1Analyzer/plugins/SiPixelPhase1Analyzer.cc index 4ebce34804b69..5317f2282811f 100644 --- a/DQM/SiPixelPhase1Analyzer/plugins/SiPixelPhase1Analyzer.cc +++ b/DQM/SiPixelPhase1Analyzer/plugins/SiPixelPhase1Analyzer.cc @@ -2,868 +2,829 @@ // // Package: DQM/SiPixelPhase1Analyzer // Class: SiPixelPhase1Analyzer -// +// #include "DQM/SiPixelPhase1Analyzer/interface/SiPixelPhase1Analyzer.h" -SiPixelPhase1Analyzer::SiPixelPhase1Analyzer(const edm::ParameterSet& iConfig) : - opMode(static_cast(iConfig.getUntrackedParameter("opMode"))), - debugFileName(iConfig.getUntrackedParameter("debugFileName")), - firstEvent(true), - rootFileHandle(NULL), - isBarrelSource(iConfig.getUntrackedParameter>("isBarrelSource")), - analazedRootFileName(iConfig.getUntrackedParameter>("remapRootFileName")), - pathToHistograms(iConfig.getUntrackedParameter>("pathToHistograms")), - baseHistogramName(iConfig.getUntrackedParameter>("baseHistogramName")) -{ - +SiPixelPhase1Analyzer::SiPixelPhase1Analyzer(const edm::ParameterSet& iConfig) + : opMode(static_cast(iConfig.getUntrackedParameter("opMode"))), + debugFileName(iConfig.getUntrackedParameter("debugFileName")), + firstEvent(true), + rootFileHandle(nullptr), + isBarrelSource(iConfig.getUntrackedParameter>("isBarrelSource")), + analazedRootFileName(iConfig.getUntrackedParameter>("remapRootFileName")), + pathToHistograms(iConfig.getUntrackedParameter>("pathToHistograms")), + baseHistogramName(iConfig.getUntrackedParameter>("baseHistogramName")) { #ifdef DEBUG_MODE - debugFile = std::ofstream(debugFileName.c_str(),std::ofstream::out); + debugFile = std::ofstream(debugFileName.c_str(), std::ofstream::out); #endif - usesResource("TFileService"); - - orthoProjectionMatrix.BuildOrthographicMatrix(1.0f, -1.0f, 1.0f, -1.0f, -10.0f, 10.0f); - - switch (opMode) - { - case MODE_ANALYZE: - - tracksToken = consumes(iConfig.getParameter("src")); - - analazedRootFileName.clear(); - - pathToHistograms.clear(); - pathToHistograms.push_back("RecHits/"); - - baseHistogramName.clear(); - baseHistogramName.push_back("RecHits"); - - break; - case MODE_REMAP: - break; - default: - break; - } + usesResource("TFileService"); + + orthoProjectionMatrix.BuildOrthographicMatrix(1.0f, -1.0f, 1.0f, -1.0f, -10.0f, 10.0f); + + switch (opMode) { + case MODE_ANALYZE: + + tracksToken = consumes(iConfig.getParameter("src")); + + analazedRootFileName.clear(); + + pathToHistograms.clear(); + pathToHistograms.push_back("RecHits/"); + + baseHistogramName.clear(); + baseHistogramName.push_back("RecHits"); + + break; + case MODE_REMAP: + break; + default: + break; + } } -SiPixelPhase1Analyzer::~SiPixelPhase1Analyzer() -{ - for (auto& i: bins) - { - delete i.second; - } - - for (auto& i: binsSummary) - { - delete i.second; - } - +SiPixelPhase1Analyzer::~SiPixelPhase1Analyzer() { + for (auto& i : bins) { + delete i.second; + } + + for (auto& i : binsSummary) { + delete i.second; + } + #ifdef DEBUG_MODE - debugFile.close(); + debugFile.close(); #endif } // ------------ method called for each event ------------ -void SiPixelPhase1Analyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) -{ - ESHandle < TrackerGeometry > theTrackerGeometry; - iSetup.get < TrackerDigiGeometryRecord > ().get(theTrackerGeometry); - - edm::ESHandle trackerTopologyHandle; - iSetup.get().get(trackerTopologyHandle); - - const TrackerTopology* tt = trackerTopologyHandle.operator->(); - - if (firstEvent) - { -///////////////////////////////// - BookHistograms(); -///////////////////////////////// - BookBins(theTrackerGeometry, tt); -///////////////////////////////// - if (opMode == MODE_REMAP) - { - FillBins(NULL, theTrackerGeometry, tt); - } -///////////////////////////////// - firstEvent = false; - } - if (opMode == MODE_ANALYZE) - { - edm::Handle tracks; - iEvent.getByToken( tracksToken, tracks); - if (!tracks.isValid()) - { - LogInfo("Analyzer") << "reco::TrackCollection not found... Aborting...\n"; - return; - } - FillBins(&tracks, theTrackerGeometry, tt); - } - // debugFile << "SiPixelPhase1Analyzer::analyze() - Event " << iEvent.run() << "/" << iEvent.id().event() << endl; +void SiPixelPhase1Analyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { + ESHandle theTrackerGeometry; + iSetup.get().get(theTrackerGeometry); + + edm::ESHandle trackerTopologyHandle; + iSetup.get().get(trackerTopologyHandle); + + const TrackerTopology* tt = trackerTopologyHandle.operator->(); + + if (firstEvent) { + ///////////////////////////////// + BookHistograms(); + ///////////////////////////////// + BookBins(theTrackerGeometry, tt); + ///////////////////////////////// + if (opMode == MODE_REMAP) { + FillBins(nullptr, theTrackerGeometry, tt); + } + ///////////////////////////////// + firstEvent = false; + } + if (opMode == MODE_ANALYZE) { + edm::Handle tracks; + iEvent.getByToken(tracksToken, tracks); + if (!tracks.isValid()) { + LogInfo("Analyzer") << "reco::TrackCollection not found... Aborting...\n"; + return; + } + FillBins(&tracks, theTrackerGeometry, tt); + } + // debugFile << "SiPixelPhase1Analyzer::analyze() - Event " << iEvent.run() << "/" << iEvent.id().event() << endl; } -void SiPixelPhase1Analyzer::BookHistograms() -{ -// ghost object FileService (without it, it crashes and creation of directories would not be possible) - TObject* ghostObj = fs->make("ghost", "ghost", -1, 1, -1, 1); - - TDirectory *topDir = fs->getBareDirectory(); - topDir->cd(); - +void SiPixelPhase1Analyzer::BookHistograms() { + // ghost object FileService (without it, it crashes and creation of directories would not be possible) + TObject* ghostObj = fs->make("ghost", "ghost", -1, 1, -1, 1); + + TDirectory* topDir = fs->getBareDirectory(); + topDir->cd(); + #ifdef DEBUG_MODE - debugFile << "Full path: " << fs->fullPath() << endl << endl; + debugFile << "Full path: " << fs->fullPath() << endl << endl; #endif - string histName; - for (unsigned j = 0; j < baseHistogramName.size(); ++j) - { - string currentHistoName = baseHistogramName[j]; - - TDirectory* currentDir = topDir->mkdir(currentHistoName.c_str()); - currentDir->cd(); - - if (opMode == MODE_REMAP) - { - if (isBarrelSource[j]) - { - BookBarrelHistograms(currentDir, currentHistoName); - } - else - { - BookForwardHistograms(currentDir, currentHistoName); - } - } - else - { - BookBarrelHistograms(currentDir, currentHistoName); - BookForwardHistograms(currentDir, currentHistoName); - } - - topDir->cd(); - } - - ghostObj->Delete(); //not needed any more + string histName; + for (unsigned j = 0; j < baseHistogramName.size(); ++j) { + string currentHistoName = baseHistogramName[j]; + + TDirectory* currentDir = topDir->mkdir(currentHistoName.c_str()); + currentDir->cd(); + + if (opMode == MODE_REMAP) { + if (isBarrelSource[j]) { + BookBarrelHistograms(currentDir, currentHistoName); + } else { + BookForwardHistograms(currentDir, currentHistoName); + } + } else { + BookBarrelHistograms(currentDir, currentHistoName); + BookForwardHistograms(currentDir, currentHistoName); + } + + topDir->cd(); + } + + ghostObj->Delete(); //not needed any more } -void SiPixelPhase1Analyzer::BookBarrelHistograms(TDirectory* currentDir, const string& currentHistoName) -{ - string histName; - TH2Poly* th2p; - TH2* th2; - - for (unsigned i = 0; i < 4; ++i) - { - histName = "barrel_layer_"; - - th2p = new TH2Poly((histName + std::to_string(i + 1)).c_str(), "PXBMap", -15.0, 15.0, 0.0, 5.0); - - th2p->SetFloat(); - - th2p->GetXaxis()->SetTitle("z [cm]"); - th2p->GetYaxis()->SetTitle("ladder"); - +void SiPixelPhase1Analyzer::BookBarrelHistograms(TDirectory* currentDir, const string& currentHistoName) { + string histName; + TH2Poly* th2p; + TH2* th2; + + for (unsigned i = 0; i < 4; ++i) { + histName = "barrel_layer_"; + + th2p = new TH2Poly((histName + std::to_string(i + 1)).c_str(), "PXBMap", -15.0, 15.0, 0.0, 5.0); + + th2p->SetFloat(); + + th2p->GetXaxis()->SetTitle("z [cm]"); + th2p->GetYaxis()->SetTitle("ladder"); + #ifdef DEBUG_MODE - th2p->SetOption("COLZ 0 TEXT"); -#else - th2p->SetOption("COLZ L"); -#endif - - currentDir->Add(th2p); - th2PolyBarrel[currentHistoName].push_back(th2p); - + th2p->SetOption("COLZ 0 TEXT"); +#else + th2p->SetOption("COLZ L"); +#endif + + currentDir->Add(th2p); + th2PolyBarrel[currentHistoName].push_back(th2p); + #ifdef DEBUG_MODE - if (opMode == MODE_ANALYZE) - { - th2 = new TH2I((histName + std::to_string(i + 1) + "_DEBUG").c_str(), "position", 3000, -30.0f, 30.0f, 1000, -4.5f * (i + 1), 4.5f * (i + 1)); - - th2->GetXaxis()->SetTitle("z [cm]"); - th2->GetYaxis()->SetTitle("-x [?]"); - - th2->SetOption("COLZ 0 TEXT"); - - currentDir->Add(th2); - th2PolyBarrelDebug[currentHistoName].push_back(th2); - } + if (opMode == MODE_ANALYZE) { + th2 = new TH2I((histName + std::to_string(i + 1) + "_DEBUG").c_str(), + "position", + 3000, + -30.0f, + 30.0f, + 1000, + -4.5f * (i + 1), + 4.5f * (i + 1)); + + th2->GetXaxis()->SetTitle("z [cm]"); + th2->GetYaxis()->SetTitle("-x [?]"); + + th2->SetOption("COLZ 0 TEXT"); + + currentDir->Add(th2); + th2PolyBarrelDebug[currentHistoName].push_back(th2); + } #endif - } - - th2p = new TH2Poly("barrel_summary", "PXBMap", -5.0, 5.0, 0.0, 5.0); - th2p->SetFloat(); - - th2p->GetXaxis()->SetTitle(""); - th2p->GetYaxis()->SetTitle("~ladder"); - - th2p->SetOption("COLZ L"); - - currentDir->Add(th2p); - th2PolyBarrelSummary[currentHistoName] = th2p; + } + + th2p = new TH2Poly("barrel_summary", "PXBMap", -5.0, 5.0, 0.0, 5.0); + th2p->SetFloat(); + + th2p->GetXaxis()->SetTitle(""); + th2p->GetYaxis()->SetTitle("~ladder"); + + th2p->SetOption("COLZ L"); + + currentDir->Add(th2p); + th2PolyBarrelSummary[currentHistoName] = th2p; } -void SiPixelPhase1Analyzer::BookForwardHistograms(TDirectory* currentDir, const string& currentHistoName) -{ - string histName; - TH2Poly* th2p; - TH2* th2; - - for (unsigned side = 1; side <= 2; ++side) - { - for (unsigned disk = 1; disk <= 3; ++disk) - { - histName = "forward_disk_"; - - th2p = new TH2Poly((histName + std::to_string( (side == 1 ? -(int(disk)) : (int)disk) )).c_str(), "PXFMap", -15.0, 15.0, -15.0, 15.0); - - th2p->SetFloat(); - - th2p->GetXaxis()->SetTitle("x [cm]"); - th2p->GetYaxis()->SetTitle("y [cm]"); - +void SiPixelPhase1Analyzer::BookForwardHistograms(TDirectory* currentDir, const string& currentHistoName) { + string histName; + TH2Poly* th2p; + TH2* th2; + + for (unsigned side = 1; side <= 2; ++side) { + for (unsigned disk = 1; disk <= 3; ++disk) { + histName = "forward_disk_"; + + th2p = new TH2Poly((histName + std::to_string((side == 1 ? -(int(disk)) : (int)disk))).c_str(), + "PXFMap", + -15.0, + 15.0, + -15.0, + 15.0); + + th2p->SetFloat(); + + th2p->GetXaxis()->SetTitle("x [cm]"); + th2p->GetYaxis()->SetTitle("y [cm]"); + #ifdef DEBUG_MODE - th2p->SetOption("COLZ 0 TEXT"); -#else - th2p->SetOption("COLZ L"); -#endif - currentDir->Add(th2p); - pxfTh2PolyForward[currentHistoName].push_back(th2p); - + th2p->SetOption("COLZ 0 TEXT"); +#else + th2p->SetOption("COLZ L"); +#endif + currentDir->Add(th2p); + pxfTh2PolyForward[currentHistoName].push_back(th2p); + #ifdef DEBUG_MODE - if (opMode == MODE_ANALYZE) - { - th2 = new TH2I((histName + std::to_string( (side == 1 ? -(int(disk)) : (int)disk) ) + "_DEBUG").c_str(), "position", 1000, -15.0f, 15.0f, 1000, -15.0f, 15.0f); - - th2->GetXaxis()->SetTitle("x [cm]"); - th2->GetYaxis()->SetTitle("y [cm]"); - - th2->SetOption("COLZ 0 TEXT"); - - currentDir->Add(th2); - pxfTh2PolyForwardDebug[currentHistoName].push_back(th2); - } + if (opMode == MODE_ANALYZE) { + th2 = new TH2I((histName + std::to_string((side == 1 ? -(int(disk)) : (int)disk)) + "_DEBUG").c_str(), + "position", + 1000, + -15.0f, + 15.0f, + 1000, + -15.0f, + 15.0f); + + th2->GetXaxis()->SetTitle("x [cm]"); + th2->GetYaxis()->SetTitle("y [cm]"); + + th2->SetOption("COLZ 0 TEXT"); + + currentDir->Add(th2); + pxfTh2PolyForwardDebug[currentHistoName].push_back(th2); + } #endif - } - } - - th2p = new TH2Poly("forward_summary", "PXFMap", -40.0, 50.0, -20.0, 90.0); - th2p->SetFloat(); - - th2p->GetXaxis()->SetTitle(""); - th2p->GetYaxis()->SetTitle(""); - + } + } + + th2p = new TH2Poly("forward_summary", "PXFMap", -40.0, 50.0, -20.0, 90.0); + th2p->SetFloat(); + + th2p->GetXaxis()->SetTitle(""); + th2p->GetYaxis()->SetTitle(""); + #ifdef DEBUG_MODE - th2p->SetOption("COLZ 0 TEXT"); -#else - th2p->SetOption("COLZ L"); + th2p->SetOption("COLZ 0 TEXT"); +#else + th2p->SetOption("COLZ L"); #endif - - currentDir->Add(th2p); - pxfTh2PolyForwardSummary[currentHistoName] = th2p; + + currentDir->Add(th2p); + pxfTh2PolyForwardSummary[currentHistoName] = th2p; } -void SiPixelPhase1Analyzer::BookBins(ESHandle < TrackerGeometry >& theTrackerGeometry, const TrackerTopology* tt) -{ - BookBarrelBins(theTrackerGeometry, tt); - BookForwardBins(theTrackerGeometry, tt); - +void SiPixelPhase1Analyzer::BookBins(ESHandle& theTrackerGeometry, const TrackerTopology* tt) { + BookBarrelBins(theTrackerGeometry, tt); + BookForwardBins(theTrackerGeometry, tt); + #ifdef DEBUG_MODE - SaveDetectorVertices(tt); + SaveDetectorVertices(tt); #endif } -void SiPixelPhase1Analyzer::BookBarrelBins(ESHandle < TrackerGeometry >& theTrackerGeometry, const TrackerTopology* tt) -{ - TrackingGeometry::DetContainer pxb = theTrackerGeometry->detsPXB(); +void SiPixelPhase1Analyzer::BookBarrelBins(ESHandle& theTrackerGeometry, const TrackerTopology* tt) { + TrackingGeometry::DetContainer pxb = theTrackerGeometry->detsPXB(); #ifdef DEBUG_MODE - debugFile << "There are " << pxb.size() << " detector elements in the PXB." << endl; + debugFile << "There are " << pxb.size() << " detector elements in the PXB." << endl; #endif - for (auto &i: pxb) - { - const GeomDet *det = i; - - PXBDetId id = det->geographicalId(); - - Local2DPoint origin; - GlobalPoint p = det->surface().toGlobal(origin); - - int layer = tt->pxbLayer(id); - int ladder = tt->pxbLadder(id); - int module = tt->pxbModule(id); - + for (auto& i : pxb) { + const GeomDet* det = i; + + PXBDetId id = det->geographicalId(); + + Local2DPoint origin; + GlobalPoint p = det->surface().toGlobal(origin); + + int layer = tt->pxbLayer(id); + int ladder = tt->pxbLadder(id); + int module = tt->pxbModule(id); + #ifdef DEBUG_MODE - PixelBarrelName pixelBarrelName(id, tt, true); - SaveDetectorData(true, id.rawId(), pixelBarrelName.shell(), pixelBarrelName.layerName(), pixelBarrelName.ladderName()); + PixelBarrelName pixelBarrelName(id, tt, true); + SaveDetectorData( + true, id.rawId(), pixelBarrelName.shell(), pixelBarrelName.layerName(), pixelBarrelName.ladderName()); #endif - + #ifdef DEBUG_MODE - float r = sqrt(p.x() * p.x() + p.y() * p.y()); - - debugFile << "Layer: " << layer << "\tLadder: " << ladder << "\tModule: " << module << "\t(x, y, z, r2): (" << p.x() << ", " - << p.y() << ", " - << p.z() << ", " - << r << ")" << endl; + float r = sqrt(p.x() * p.x() + p.y() * p.y()); + + debugFile << "Layer: " << layer << "\tLadder: " << ladder << "\tModule: " << module << "\t(x, y, z, r2): (" << p.x() + << ", " << p.y() << ", " << p.z() << ", " << r << ")" << endl; #endif - - const Bounds& b = (det->surface().bounds()); - float bl = b.length(); - + + const Bounds& b = (det->surface().bounds()); + float bl = b.length(); + #ifdef DEBUG_MODE - float bw = b.width(); - float bt = b.thickness(); - - debugFile << "Length: " << bl << "\tWidth: " << bw << "\tThickness: " << bt << endl; -#endif - - float vertX[] = {p.z() - bl * 0.5f, p.z() + bl * 0.5f, p.z() + bl * 0.5f, p.z() - bl * 0.5f, p.z() - bl * 0.5f}; - float vertY[] = {(ladder - 1.0f), (ladder - 1.0f), (float)ladder, (float)ladder, (ladder - 1.0f)}; - - bins[id.rawId()] = new TGraph(5, vertX, vertY); - bins[id.rawId()]->SetName(TString::Format("%u",id.rawId())); - - // Summary plot - for (unsigned k = 0; k < 5; ++k) - { - vertX[k] += ((layer == 2 || layer == 3) ? 0.0f : -60.0f); - vertY[k] += ((layer > 2) ? 30.0f : 0.0f); - } - - binsSummary[id.rawId()] = new TGraph(5, vertX, vertY); - binsSummary[id.rawId()]->SetName(TString::Format("%u",id.rawId())); - - for (unsigned nameNum = 0; nameNum < baseHistogramName.size(); ++nameNum) - { - if (isBarrelSource[nameNum] || opMode == MODE_ANALYZE) - { - const string& strName = baseHistogramName[nameNum]; - th2PolyBarrel[strName][layer - 1]->AddBin(bins[id.rawId()]->Clone()); - th2PolyBarrelSummary[strName]->AddBin(binsSummary[id.rawId()]->Clone()); - } - } - } + float bw = b.width(); + float bt = b.thickness(); + + debugFile << "Length: " << bl << "\tWidth: " << bw << "\tThickness: " << bt << endl; +#endif + + float vertX[] = {p.z() - bl * 0.5f, p.z() + bl * 0.5f, p.z() + bl * 0.5f, p.z() - bl * 0.5f, p.z() - bl * 0.5f}; + float vertY[] = {(ladder - 1.0f), (ladder - 1.0f), (float)ladder, (float)ladder, (ladder - 1.0f)}; + + bins[id.rawId()] = new TGraph(5, vertX, vertY); + bins[id.rawId()]->SetName(TString::Format("%u", id.rawId())); + + // Summary plot + for (unsigned k = 0; k < 5; ++k) { + vertX[k] += ((layer == 2 || layer == 3) ? 0.0f : -60.0f); + vertY[k] += ((layer > 2) ? 30.0f : 0.0f); + } + + binsSummary[id.rawId()] = new TGraph(5, vertX, vertY); + binsSummary[id.rawId()]->SetName(TString::Format("%u", id.rawId())); + + for (unsigned nameNum = 0; nameNum < baseHistogramName.size(); ++nameNum) { + if (isBarrelSource[nameNum] || opMode == MODE_ANALYZE) { + const string& strName = baseHistogramName[nameNum]; + th2PolyBarrel[strName][layer - 1]->AddBin(bins[id.rawId()]->Clone()); + th2PolyBarrelSummary[strName]->AddBin(binsSummary[id.rawId()]->Clone()); + } + } + } } -void SiPixelPhase1Analyzer::BookForwardBins(ESHandle < TrackerGeometry >& theTrackerGeometry, const TrackerTopology* tt) -{ - TrackingGeometry::DetContainer pxf = theTrackerGeometry->detsPXF(); +void SiPixelPhase1Analyzer::BookForwardBins(ESHandle& theTrackerGeometry, const TrackerTopology* tt) { + TrackingGeometry::DetContainer pxf = theTrackerGeometry->detsPXF(); #ifdef DEBUG_MODE - debugFile << "There are " << pxf.size() << " detector elements in the PXF." << endl; -#endif - bool firstForwardElem = true; - - float elemWidth = 1.0f; - float elemLength = 1.0f; - - // FIRST PASS -> MAKE MAP OF CORRESPONDING ELEMENTS (BLADES ON BOTH PANELS) - for (auto &i: pxf) - { - const GeomDet *det = i; - - PXFDetId id = det->geographicalId(); - - Local2DPoint origin; - GlobalPoint p = det->surface().toGlobal(origin); - - int panel = tt->pxfPanel(id); - int side = tt->side(id);//tt->pxfSide(id); - int disk = tt->layer(id);//tt->pxfDisk(id); - int blade = tt->pxfBlade(id); - int module = tt->module(id);//tt->pxfModule(id); - + debugFile << "There are " << pxf.size() << " detector elements in the PXF." << endl; +#endif + bool firstForwardElem = true; + + float elemWidth = 1.0f; + float elemLength = 1.0f; + + // FIRST PASS -> MAKE MAP OF CORRESPONDING ELEMENTS (BLADES ON BOTH PANELS) + for (auto& i : pxf) { + const GeomDet* det = i; + + PXFDetId id = det->geographicalId(); + + Local2DPoint origin; + GlobalPoint p = det->surface().toGlobal(origin); + + int panel = tt->pxfPanel(id); + int side = tt->side(id); //tt->pxfSide(id); + int disk = tt->layer(id); //tt->pxfDisk(id); + int blade = tt->pxfBlade(id); + int module = tt->module(id); //tt->pxfModule(id); + #ifdef DEBUG_MODE - PixelEndcapName pixelEndcapName(id, tt, true); - SaveDetectorData(false, id.rawId(), pixelEndcapName.halfCylinder(), pixelEndcapName.diskName(), pixelEndcapName.bladeName()); + PixelEndcapName pixelEndcapName(id, tt, true); + SaveDetectorData( + false, id.rawId(), pixelEndcapName.halfCylinder(), pixelEndcapName.diskName(), pixelEndcapName.bladeName()); #endif - + #ifdef DEBUG_MODE - float r = sqrt(p.x() * p.x() + p.y() * p.y()); - - debugFile << "Panel: " << panel << "\tSide: " << side << "\tDisk: " << disk << "\tBlade: " << blade << "\tModule: " << module << "\t(x, y, z, r): (" << p.x() << ", " - << p.y() << ", " - << p.z() << ", " - << r << ")" << endl; -#endif - if (firstForwardElem) - { - const Bounds& b = det->surface().bounds(); //const RectangularPlaneBounds& b - - elemLength = b.length(); - elemWidth = b.width(); - - firstForwardElem = false; - } - - const auto& rot = det->rotation(); - - mat4 transMat(rot.xx(), rot.xy(), rot.xz(), - rot.yx(), rot.yy(), rot.yz(), - rot.zx(), rot.zy(), rot.zz(), - p.x(), p.y(), p.z()); - - mapOfComplementaryElements[CODE_FORWARD(side, disk, blade)].mat[panel - 1] = transMat; - mapOfComplementaryElements[CODE_FORWARD(side, disk, blade)].rawId[panel - 1] = id.rawId(); - } - - // SECOND PASS -> USE INFORMATION FROM MAP TO MAKE GEOMETRIC OBJECTS (BINS) - for (auto& i: mapOfComplementaryElements) - { - // decode side&disk from the map key - unsigned side = i.first & 0xF; - unsigned disk = (i.first & 0xF0) >> 4; - // unsigned blade = (i.first & 0xFF00) >> 8; - - unsigned mapIdx = disk + (side - 1) * 3 - 1; - - // normal vectors of elements point to the (almost) opposite direction, so correction is needed before interploation (probably not 100% correct but fast) - i.second.mat[1].data[0] = -i.second.mat[1].data[0]; - i.second.mat[1].data[1] = -i.second.mat[1].data[1]; - i.second.mat[1].data[2] = -i.second.mat[1].data[2]; - - i.second.mat[1].data[6] = -i.second.mat[1].data[6]; - i.second.mat[1].data[7] = -i.second.mat[1].data[7]; - i.second.mat[1].data[8] = -i.second.mat[1].data[8]; - - mat4 meanTransform = (i.second.mat[0] + i.second.mat[1]) * 0.5f; - // mat4 meanTransform = i.second.mat[0]; - - static float baseVertX[4] = {-elemWidth * 0.8f, -elemWidth * 0.5f, elemWidth * 0.8f, elemWidth * 0.5f}; - static float baseVertY[4] = { elemLength * 0.38f, -elemLength * 0.38f, elemLength * 0.38f, -elemLength * 0.38f}; - - static float vertXPanel[2][4], vertYPanel[2][4]; - float vertIn[3], vertOut[3]; - - /* + float r = sqrt(p.x() * p.x() + p.y() * p.y()); + + debugFile << "Panel: " << panel << "\tSide: " << side << "\tDisk: " << disk << "\tBlade: " << blade + << "\tModule: " << module << "\t(x, y, z, r): (" << p.x() << ", " << p.y() << ", " << p.z() << ", " << r + << ")" << endl; +#endif + if (firstForwardElem) { + const Bounds& b = det->surface().bounds(); //const RectangularPlaneBounds& b + + elemLength = b.length(); + elemWidth = b.width(); + + firstForwardElem = false; + } + + const auto& rot = det->rotation(); + + mat4 transMat( + rot.xx(), rot.xy(), rot.xz(), rot.yx(), rot.yy(), rot.yz(), rot.zx(), rot.zy(), rot.zz(), p.x(), p.y(), p.z()); + + mapOfComplementaryElements[CODE_FORWARD(side, disk, blade)].mat[panel - 1] = transMat; + mapOfComplementaryElements[CODE_FORWARD(side, disk, blade)].rawId[panel - 1] = id.rawId(); + } + + // SECOND PASS -> USE INFORMATION FROM MAP TO MAKE GEOMETRIC OBJECTS (BINS) + for (auto& i : mapOfComplementaryElements) { + // decode side&disk from the map key + unsigned side = i.first & 0xF; + unsigned disk = (i.first & 0xF0) >> 4; + // unsigned blade = (i.first & 0xFF00) >> 8; + + unsigned mapIdx = disk + (side - 1) * 3 - 1; + + // normal vectors of elements point to the (almost) opposite direction, so correction is needed before interploation (probably not 100% correct but fast) + i.second.mat[1].data[0] = -i.second.mat[1].data[0]; + i.second.mat[1].data[1] = -i.second.mat[1].data[1]; + i.second.mat[1].data[2] = -i.second.mat[1].data[2]; + + i.second.mat[1].data[6] = -i.second.mat[1].data[6]; + i.second.mat[1].data[7] = -i.second.mat[1].data[7]; + i.second.mat[1].data[8] = -i.second.mat[1].data[8]; + + mat4 meanTransform = (i.second.mat[0] + i.second.mat[1]) * 0.5f; + // mat4 meanTransform = i.second.mat[0]; + + static float baseVertX[4] = {-elemWidth * 0.8f, -elemWidth * 0.5f, elemWidth * 0.8f, elemWidth * 0.5f}; + static float baseVertY[4] = {elemLength * 0.38f, -elemLength * 0.38f, elemLength * 0.38f, -elemLength * 0.38f}; + + static float vertXPanel[2][4], vertYPanel[2][4]; + float vertIn[3], vertOut[3]; + + /* (1) __________________ (3) - \ / - \ / - \ / - \ / - (2)\__________/(4) - - - division line: (2) - (3) - - - panel 1: triangle of lower area (2, 3, 4) - - panel 2: triangle of bigger area (1, 2, 3) - */ - - // obtain transformed vertices - for (unsigned j = 0; j < 4; ++j) - { - vertIn[0] = baseVertX[j]; - vertIn[1] = baseVertY[j]; - vertIn[2] = 0.0f; - - meanTransform.MulVec(vertIn, vertOut); - std::swap(vertIn, vertOut); - orthoProjectionMatrix.MulVec(vertIn, vertOut); - - // vertical flip - vertOut[0] = -vertOut[0]; // so that inner elements have positive x-coordinate - - if (j > 0) - { - vertXPanel[0][j - 1] = vertOut[0]; vertYPanel[0][j - 1] = vertOut[1]; // for panel 2 - } - if (j < 3) - { - vertXPanel[1][j] = vertOut[0]; vertYPanel[1][j] = vertOut[1]; // for panel 1 - } - } - - for (unsigned j = 0; j < 2; ++j) - { - vertXPanel[j][3] = vertXPanel[j][0]; - vertYPanel[j][3] = vertYPanel[j][0]; - - bins[i.second.rawId[j]] = new TGraph(4, vertXPanel[j], vertYPanel[j]); - bins[i.second.rawId[j]]->SetName(TString::Format("%u",i.second.rawId[j])); - - // for (auto strName: baseHistogramName) - // { - // pxfTh2PolyForward[strName][mapIdx]->AddBin(bins[i.second.rawId[j]]->Clone()); - // } - - // Summary plot - for (unsigned k = 0; k < 4; ++k) - { - vertXPanel[j][k] += (float(side) - 1.5f) * 40.0f; - vertYPanel[j][k] += (disk - 1) * 35.0f; - } - - binsSummary[i.second.rawId[j]] = new TGraph(4, vertXPanel[j], vertYPanel[j]); - binsSummary[i.second.rawId[j]]->SetName(TString::Format("%u",i.second.rawId[j])); - - for (unsigned nameNum = 0; nameNum < baseHistogramName.size(); ++nameNum) - { - if (!isBarrelSource[nameNum] || opMode == MODE_ANALYZE) - { - const string& strName = baseHistogramName[nameNum]; - pxfTh2PolyForward[strName][mapIdx]->AddBin(bins[i.second.rawId[j]]->Clone()); - pxfTh2PolyForwardSummary[strName]->AddBin(binsSummary[i.second.rawId[j]]->Clone()); - } - } - } - } + \ / + \ / + \ / + \ / + (2)\_________/(4) + + - division line: (2) - (3) + + - panel 1: triangle of lower area (2, 3, 4) + - panel 2: triangle of bigger area (1, 2, 3) + */ + + // obtain transformed vertices + for (unsigned j = 0; j < 4; ++j) { + vertIn[0] = baseVertX[j]; + vertIn[1] = baseVertY[j]; + vertIn[2] = 0.0f; + + meanTransform.MulVec(vertIn, vertOut); + std::swap(vertIn, vertOut); + orthoProjectionMatrix.MulVec(vertIn, vertOut); + + // vertical flip + vertOut[0] = -vertOut[0]; // so that inner elements have positive x-coordinate + + if (j > 0) { + vertXPanel[0][j - 1] = vertOut[0]; + vertYPanel[0][j - 1] = vertOut[1]; // for panel 2 + } + if (j < 3) { + vertXPanel[1][j] = vertOut[0]; + vertYPanel[1][j] = vertOut[1]; // for panel 1 + } + } + + for (unsigned j = 0; j < 2; ++j) { + vertXPanel[j][3] = vertXPanel[j][0]; + vertYPanel[j][3] = vertYPanel[j][0]; + + bins[i.second.rawId[j]] = new TGraph(4, vertXPanel[j], vertYPanel[j]); + bins[i.second.rawId[j]]->SetName(TString::Format("%u", i.second.rawId[j])); + + // for (auto strName: baseHistogramName) + // { + // pxfTh2PolyForward[strName][mapIdx]->AddBin(bins[i.second.rawId[j]]->Clone()); + // } + + // Summary plot + for (unsigned k = 0; k < 4; ++k) { + vertXPanel[j][k] += (float(side) - 1.5f) * 40.0f; + vertYPanel[j][k] += (disk - 1) * 35.0f; + } + + binsSummary[i.second.rawId[j]] = new TGraph(4, vertXPanel[j], vertYPanel[j]); + binsSummary[i.second.rawId[j]]->SetName(TString::Format("%u", i.second.rawId[j])); + + for (unsigned nameNum = 0; nameNum < baseHistogramName.size(); ++nameNum) { + if (!isBarrelSource[nameNum] || opMode == MODE_ANALYZE) { + const string& strName = baseHistogramName[nameNum]; + pxfTh2PolyForward[strName][mapIdx]->AddBin(bins[i.second.rawId[j]]->Clone()); + pxfTh2PolyForwardSummary[strName]->AddBin(binsSummary[i.second.rawId[j]]->Clone()); + } + } + } + } } -void SiPixelPhase1Analyzer::SaveDetectorVertices(const TrackerTopology* tt) -{ - vector verticesFiles[2]; - for (unsigned i = 0; i < 4; ++i) - { - std::ofstream* f = new std::ofstream(("vertices_barrel_" + std::to_string(i + 1)).c_str(), std::ofstream::out); - - verticesFiles[0].push_back(f); - } - - for (unsigned side = 1; side <= 2; ++side) - { - for (unsigned disk = 1; disk <= 3; ++disk) - { - std::ofstream* f = new std::ofstream(("vertices_forward_" + std::to_string( (side == 1 ? -(int(disk)) : (int)disk) )).c_str(), std::ofstream::out); - - verticesFiles[1].push_back(f); - } - } - - for (auto& bin: bins) - { - unsigned rawId = bin.first; - DetId id(rawId); - unsigned subdetId = id.subdetId(); - - if (subdetId != PixelSubdetector::PixelBarrel && - subdetId != PixelSubdetector::PixelEndcap) continue; - - double* vertX = bin.second->GetX(); - double* vertY = bin.second->GetY(); - - if (subdetId == PixelSubdetector::PixelBarrel) - { - PXBDetId pxbId(rawId); - unsigned layer = tt->pxbLayer(pxbId); - string onlineName = PixelBarrelName(pxbId, tt, true).name(); - - *(verticesFiles[0][layer - 1]) << rawId << " " << onlineName << " \""; - for (unsigned i = 0; i < 4; ++i) - { - *(verticesFiles[0][layer - 1]) << vertX[i] << "," << vertY[i]; - if (i == 3) *(verticesFiles[0][layer - 1]) << "\"\n"; - else *(verticesFiles[0][layer - 1]) << " "; - } - } - else - { - PXFDetId pxfId(rawId); - unsigned side = tt->pxfSide(pxfId); - unsigned disk = tt->pxfDisk(pxfId); - string onlineName = PixelEndcapName(pxfId, tt, true).name(); - unsigned mapIdx = disk + (side - 1) * 3 - 1; - - *(verticesFiles[1][mapIdx]) << rawId << " " << onlineName << " \""; - for (unsigned i = 0; i < 3; ++i) - { - *(verticesFiles[1][mapIdx]) << vertX[i] << "," << vertY[i]; - - if (i == 2) *(verticesFiles[1][mapIdx]) << "\"\n"; - else *(verticesFiles[1][mapIdx]) << " "; - } - } - } - - for (unsigned i = 0; i < 2; ++i) - { - for (auto& j: verticesFiles[i]) - { - j->close(); - delete j; - } - } +void SiPixelPhase1Analyzer::SaveDetectorVertices(const TrackerTopology* tt) { + vector verticesFiles[2]; + for (unsigned i = 0; i < 4; ++i) { + std::ofstream* f = new std::ofstream(("vertices_barrel_" + std::to_string(i + 1)).c_str(), std::ofstream::out); + + verticesFiles[0].push_back(f); + } + + for (unsigned side = 1; side <= 2; ++side) { + for (unsigned disk = 1; disk <= 3; ++disk) { + std::ofstream* f = new std::ofstream( + ("vertices_forward_" + std::to_string((side == 1 ? -(int(disk)) : (int)disk))).c_str(), std::ofstream::out); + + verticesFiles[1].push_back(f); + } + } + + for (auto& bin : bins) { + unsigned rawId = bin.first; + DetId id(rawId); + unsigned subdetId = id.subdetId(); + + if (subdetId != PixelSubdetector::PixelBarrel && subdetId != PixelSubdetector::PixelEndcap) + continue; + + double* vertX = bin.second->GetX(); + double* vertY = bin.second->GetY(); + + if (subdetId == PixelSubdetector::PixelBarrel) { + PXBDetId pxbId(rawId); + unsigned layer = tt->pxbLayer(pxbId); + string onlineName = PixelBarrelName(pxbId, tt, true).name(); + + *(verticesFiles[0][layer - 1]) << rawId << " " << onlineName << " \""; + for (unsigned i = 0; i < 4; ++i) { + *(verticesFiles[0][layer - 1]) << vertX[i] << "," << vertY[i]; + if (i == 3) + *(verticesFiles[0][layer - 1]) << "\"\n"; + else + *(verticesFiles[0][layer - 1]) << " "; + } + } else { + PXFDetId pxfId(rawId); + unsigned side = tt->pxfSide(pxfId); + unsigned disk = tt->pxfDisk(pxfId); + string onlineName = PixelEndcapName(pxfId, tt, true).name(); + unsigned mapIdx = disk + (side - 1) * 3 - 1; + + *(verticesFiles[1][mapIdx]) << rawId << " " << onlineName << " \""; + for (unsigned i = 0; i < 3; ++i) { + *(verticesFiles[1][mapIdx]) << vertX[i] << "," << vertY[i]; + + if (i == 2) + *(verticesFiles[1][mapIdx]) << "\"\n"; + else + *(verticesFiles[1][mapIdx]) << " "; + } + } + } + + for (unsigned i = 0; i < 2; ++i) { + for (auto& j : verticesFiles[i]) { + j->close(); + delete j; + } + } } -void SiPixelPhase1Analyzer::FillBins(edm::Handle *tracks, ESHandle < TrackerGeometry >& theTrackerGeometry, const TrackerTopology* tt) -{ - switch (opMode) - { - case MODE_ANALYZE: - for (auto const & track: *(*tracks)) - { - auto recHitsBegin = track.recHitsBegin(); - for (unsigned i = 0; i < track.recHitsSize(); ++i) - { - auto recHit = *(recHitsBegin + i); - if (!recHit->isValid()) continue; - - DetId id = recHit->geographicalId(); - unsigned subdetId = id.subdetId(); - - if (subdetId != PixelSubdetector::PixelBarrel && - subdetId != PixelSubdetector::PixelEndcap) continue; - - const PixelGeomDetUnit* geomdetunit = dynamic_cast ( theTrackerGeometry->idToDet(id) ); // theTrackerGeometry ????? - const PixelTopology& topol = geomdetunit->specificTopology(); - - LocalPoint localPoint = recHit->localPosition(); - GlobalPoint globalPoint = geomdetunit->surface().toGlobal(localPoint); - - if (subdetId == PixelSubdetector::PixelBarrel) FillBarrelBinsAnalyze(theTrackerGeometry, tt, id.rawId(), globalPoint); - else FillForwardBinsAnalyze(theTrackerGeometry, tt, id.rawId(), globalPoint); - } - } - break; - case MODE_REMAP: - FillBarrelBinsRemap(theTrackerGeometry, tt); - FillForwardBinsRemap(theTrackerGeometry, tt); - break; - default: - break; - } +void SiPixelPhase1Analyzer::FillBins(edm::Handle* tracks, + ESHandle& theTrackerGeometry, + const TrackerTopology* tt) { + switch (opMode) { + case MODE_ANALYZE: + for (auto const& track : *(*tracks)) { + auto recHitsBegin = track.recHitsBegin(); + for (unsigned i = 0; i < track.recHitsSize(); ++i) { + auto recHit = *(recHitsBegin + i); + if (!recHit->isValid()) + continue; + + DetId id = recHit->geographicalId(); + unsigned subdetId = id.subdetId(); + + if (subdetId != PixelSubdetector::PixelBarrel && subdetId != PixelSubdetector::PixelEndcap) + continue; + + const PixelGeomDetUnit* geomdetunit = + dynamic_cast(theTrackerGeometry->idToDet(id)); // theTrackerGeometry ????? + const PixelTopology& topol = geomdetunit->specificTopology(); + + LocalPoint localPoint = recHit->localPosition(); + GlobalPoint globalPoint = geomdetunit->surface().toGlobal(localPoint); + + if (subdetId == PixelSubdetector::PixelBarrel) + FillBarrelBinsAnalyze(theTrackerGeometry, tt, id.rawId(), globalPoint); + else + FillForwardBinsAnalyze(theTrackerGeometry, tt, id.rawId(), globalPoint); + } + } + break; + case MODE_REMAP: + FillBarrelBinsRemap(theTrackerGeometry, tt); + FillForwardBinsRemap(theTrackerGeometry, tt); + break; + default: + break; + } } -void SiPixelPhase1Analyzer::FillBarrelBinsAnalyze(ESHandle < TrackerGeometry >& theTrackerGeometry, const TrackerTopology* tt, unsigned rawId, const GlobalPoint& globalPoint) -{ - for (unsigned nameNum = 0; nameNum < baseHistogramName.size(); ++nameNum) - { - string strName = baseHistogramName[nameNum]; - - PXBDetId id(rawId); - - int layer = tt->pxbLayer(id); - - th2PolyBarrel[strName][layer - 1]->Fill(TString::Format("%u",rawId), 1); - th2PolyBarrelSummary[strName]->Fill(TString::Format("%u",rawId), 1); -#ifdef DEBUG_MODE - th2PolyBarrelDebug[strName][layer - 1]->Fill((globalPoint.y() < 0 ? globalPoint.z() + 0.5f : globalPoint.z()), -globalPoint.x(), (globalPoint.y() < 0 ? -1 : 1)); +void SiPixelPhase1Analyzer::FillBarrelBinsAnalyze(ESHandle& theTrackerGeometry, + const TrackerTopology* tt, + unsigned rawId, + const GlobalPoint& globalPoint) { + for (unsigned nameNum = 0; nameNum < baseHistogramName.size(); ++nameNum) { + string strName = baseHistogramName[nameNum]; + + PXBDetId id(rawId); + + int layer = tt->pxbLayer(id); + + th2PolyBarrel[strName][layer - 1]->Fill(TString::Format("%u", rawId), 1); + th2PolyBarrelSummary[strName]->Fill(TString::Format("%u", rawId), 1); +#ifdef DEBUG_MODE + th2PolyBarrelDebug[strName][layer - 1]->Fill((globalPoint.y() < 0 ? globalPoint.z() + 0.5f : globalPoint.z()), + -globalPoint.x(), + (globalPoint.y() < 0 ? -1 : 1)); #endif - } + } } -void SiPixelPhase1Analyzer::FillForwardBinsAnalyze(ESHandle < TrackerGeometry >& theTrackerGeometry, const TrackerTopology* tt, unsigned rawId, const GlobalPoint& globalPoint) -{ - for (unsigned nameNum = 0; nameNum < baseHistogramName.size(); ++nameNum) - { - string strName = baseHistogramName[nameNum]; - - PXFDetId id(rawId); - - int side = tt->side(id);//tt->pxfSide(id); - int disk = tt->layer(id);//tt->pxfDisk(id); - // int blade = tt->pxfBlade(id); - unsigned mapIdx = disk + (side - 1) * 3 - 1; - - pxfTh2PolyForward[strName][mapIdx]->Fill(TString::Format("%u",rawId), 1); - pxfTh2PolyForwardSummary[strName]->Fill(TString::Format("%u",rawId), 1); - +void SiPixelPhase1Analyzer::FillForwardBinsAnalyze(ESHandle& theTrackerGeometry, + const TrackerTopology* tt, + unsigned rawId, + const GlobalPoint& globalPoint) { + for (unsigned nameNum = 0; nameNum < baseHistogramName.size(); ++nameNum) { + string strName = baseHistogramName[nameNum]; + + PXFDetId id(rawId); + + int side = tt->side(id); //tt->pxfSide(id); + int disk = tt->layer(id); //tt->pxfDisk(id); + // int blade = tt->pxfBlade(id); + unsigned mapIdx = disk + (side - 1) * 3 - 1; + + pxfTh2PolyForward[strName][mapIdx]->Fill(TString::Format("%u", rawId), 1); + pxfTh2PolyForwardSummary[strName]->Fill(TString::Format("%u", rawId), 1); + #ifdef DEBUG_MODE - pxfTh2PolyForwardDebug[strName][mapIdx]->Fill(globalPoint.x(), globalPoint.y(), 1); + pxfTh2PolyForwardDebug[strName][mapIdx]->Fill(globalPoint.x(), globalPoint.y(), 1); #endif - } + } } -void SiPixelPhase1Analyzer::FillBarrelBinsRemap(ESHandle < TrackerGeometry >& theTrackerGeometry, const TrackerTopology* tt) -{ - rootFileHandle = new TFile(analazedRootFileName[0].c_str()); - - if (!rootFileHandle) - { - LogInfo("Analyzer") << "Could not open file: " << analazedRootFileName[0] << "..." << endl; - return; - } - +void SiPixelPhase1Analyzer::FillBarrelBinsRemap(ESHandle& theTrackerGeometry, + const TrackerTopology* tt) { + rootFileHandle = new TFile(analazedRootFileName[0].c_str()); + + if (!rootFileHandle) { + LogInfo("Analyzer") << "Could not open file: " << analazedRootFileName[0] << "..." << endl; + return; + } + #ifdef DEBUG_MODE - rootFileHandle->ls(); - LogInfo("Analyzer") << "\n\n"; - rootFileHandle->pwd(); - LogInfo("Analyzer") << "\n\n"; + rootFileHandle->ls(); + LogInfo("Analyzer") << "\n\n"; + rootFileHandle->pwd(); + LogInfo("Analyzer") << "\n\n"; #endif - for (unsigned nameNum = 0; nameNum < baseHistogramName.size(); ++nameNum) - { - if (!isBarrelSource[nameNum]) continue; - - // if (pathToHistograms[nameNum][pathToHistograms.size() - 1] != '/') pathToHistograms[nameNum] += "/"; - string baseHistogramNameWithPath = pathToHistograms[nameNum] + baseHistogramName[nameNum] + "_"; - - const TProfile2D* handles[4]; - const TProfile2D* h; - - bool problemWithHandles = false; - - for (unsigned i = 0; i < 4; ++i) - { - string fullFileName = (baseHistogramNameWithPath + std::to_string(i + 1) + ";1 "); - handles[i] = (TProfile2D*)rootFileHandle->Get(fullFileName.c_str()); - if (!handles[i]) - { - problemWithHandles = true; - LogInfo("Analyzer") << "Histogram: " << fullFileName << " does not exist!\n"; - - break; - } - } - - if(!problemWithHandles) - { - LogInfo("Analyzer") << "\nInput histograms: " << baseHistogramNameWithPath << " opened successfully\n"; - - //Add original histograms to this file - - TDirectory* currDir = fs->getBareDirectory()->GetDirectory(baseHistogramName[nameNum].c_str()); - currDir->cd(); - - for (unsigned i = 0; i < 4; ++i) - { - currDir->Add(handles[i]->Clone()); - } - - TrackingGeometry::DetContainer pxb = theTrackerGeometry->detsPXB(); + for (unsigned nameNum = 0; nameNum < baseHistogramName.size(); ++nameNum) { + if (!isBarrelSource[nameNum]) + continue; + + // if (pathToHistograms[nameNum][pathToHistograms.size() - 1] != '/') pathToHistograms[nameNum] += "/"; + string baseHistogramNameWithPath = pathToHistograms[nameNum] + baseHistogramName[nameNum] + "_"; + + const TProfile2D* handles[4]; + const TProfile2D* h; + + bool problemWithHandles = false; + + for (unsigned i = 0; i < 4; ++i) { + string fullFileName = (baseHistogramNameWithPath + std::to_string(i + 1) + ";1 "); + handles[i] = (TProfile2D*)rootFileHandle->Get(fullFileName.c_str()); + if (!handles[i]) { + problemWithHandles = true; + LogInfo("Analyzer") << "Histogram: " << fullFileName << " does not exist!\n"; + + break; + } + } + + if (!problemWithHandles) { + LogInfo("Analyzer") << "\nInput histograms: " << baseHistogramNameWithPath << " opened successfully\n"; + + //Add original histograms to this file + + TDirectory* currDir = fs->getBareDirectory()->GetDirectory(baseHistogramName[nameNum].c_str()); + currDir->cd(); + + for (unsigned i = 0; i < 4; ++i) { + currDir->Add(handles[i]->Clone()); + } + + TrackingGeometry::DetContainer pxb = theTrackerGeometry->detsPXB(); #ifdef DEBUG_MODE - debugFile << "There are " << pxb.size() << " detector elements in the PXB." << endl; + debugFile << "There are " << pxb.size() << " detector elements in the PXB." << endl; #endif - for (auto &i: pxb) - { - const GeomDet *det = i; - - PXBDetId id = det->geographicalId(); - unsigned rawId = id.rawId(); - - int module = tt->pxbModule(id); - int ladder = tt->pxbLadder(id); - int layer = tt->pxbLayer(id); - - int signedOnlineModule = module - 4; - if (signedOnlineModule <= 0) --signedOnlineModule; - - PixelBarrelName pixelBarrelName = PixelBarrelName(id, tt, true); - int onlineShell = pixelBarrelName.shell(); - - int signedOnlineLadder = ((onlineShell & 1)?-pixelBarrelName.ladderName():pixelBarrelName.ladderName()); - - h = handles[layer - 1]; - - unsigned nx = h->GetNbinsX(); - unsigned ny = h->GetNbinsY(); - - unsigned binX = signedOnlineModule + ((nx + 1) >> 1); - unsigned binY = (signedOnlineLadder) + ((ny + 1) >> 1); - - string strName = baseHistogramName[nameNum]; - + for (auto& i : pxb) { + const GeomDet* det = i; + + PXBDetId id = det->geographicalId(); + unsigned rawId = id.rawId(); + + int module = tt->pxbModule(id); + int ladder = tt->pxbLadder(id); + int layer = tt->pxbLayer(id); + + int signedOnlineModule = module - 4; + if (signedOnlineModule <= 0) + --signedOnlineModule; + + PixelBarrelName pixelBarrelName = PixelBarrelName(id, tt, true); + int onlineShell = pixelBarrelName.shell(); + + int signedOnlineLadder = ((onlineShell & 1) ? -pixelBarrelName.ladderName() : pixelBarrelName.ladderName()); + + h = handles[layer - 1]; + + unsigned nx = h->GetNbinsX(); + unsigned ny = h->GetNbinsY(); + + unsigned binX = signedOnlineModule + ((nx + 1) >> 1); + unsigned binY = (signedOnlineLadder) + ((ny + 1) >> 1); + + string strName = baseHistogramName[nameNum]; + #ifdef DEBUG_MODE - th2PolyBarrel[strName][layer - 1]->Fill(TString::Format("%u",rawId), signedOnlineLadder); - th2PolyBarrelSummary[strName]->Fill(TString::Format("%u",rawId), signedOnlineLadder); -#else - double val = h->GetBinContent(binX, binY); - th2PolyBarrel[strName][layer - 1]->Fill(TString::Format("%u",rawId), val); - th2PolyBarrelSummary[strName]->Fill(TString::Format("%u",rawId), val); -#endif - } - } - } - - rootFileHandle->Close(); - delete rootFileHandle; + th2PolyBarrel[strName][layer - 1]->Fill(TString::Format("%u", rawId), signedOnlineLadder); + th2PolyBarrelSummary[strName]->Fill(TString::Format("%u", rawId), signedOnlineLadder); +#else + double val = h->GetBinContent(binX, binY); + th2PolyBarrel[strName][layer - 1]->Fill(TString::Format("%u", rawId), val); + th2PolyBarrelSummary[strName]->Fill(TString::Format("%u", rawId), val); +#endif + } + } + } + + rootFileHandle->Close(); + delete rootFileHandle; } -void SiPixelPhase1Analyzer::FillForwardBinsRemap(ESHandle < TrackerGeometry >& theTrackerGeometry, const TrackerTopology* tt) -{ - rootFileHandle = new TFile(analazedRootFileName[0].c_str()); - - if (!rootFileHandle) - { - return; - } - - TrackingGeometry::DetContainer pxf = theTrackerGeometry->detsPXF(); - +void SiPixelPhase1Analyzer::FillForwardBinsRemap(ESHandle& theTrackerGeometry, + const TrackerTopology* tt) { + rootFileHandle = new TFile(analazedRootFileName[0].c_str()); + + if (!rootFileHandle) { + return; + } + + TrackingGeometry::DetContainer pxf = theTrackerGeometry->detsPXF(); + #ifdef DEBUG_MODE - rootFileHandle->ls(); - LogInfo("Analyzer") << "\n\n"; - rootFileHandle->pwd(); - LogInfo("Analyzer") << "\n\n"; + rootFileHandle->ls(); + LogInfo("Analyzer") << "\n\n"; + rootFileHandle->pwd(); + LogInfo("Analyzer") << "\n\n"; #endif - - for (unsigned nameNum = 0; nameNum < baseHistogramName.size(); ++nameNum) - { - if (isBarrelSource[nameNum]) continue; - - string baseHistogramNameWithPath = pathToHistograms[nameNum] + baseHistogramName[nameNum] + "_"; - - const TProfile2D* h_1 = (TProfile2D*)rootFileHandle->Get((baseHistogramNameWithPath + "1;1 ").c_str()); - const TProfile2D* h_2 = (TProfile2D*)rootFileHandle->Get((baseHistogramNameWithPath + "2;1 ").c_str()); - const TProfile2D* h; - - if (h_2 && h_1) - { - LogInfo("Analyzer") << "\nInput histograms: " << baseHistogramNameWithPath << " opened successfully\n"; - - //Add original histograms to this file - TDirectory* currDir = fs->getBareDirectory()->GetDirectory(baseHistogramName[nameNum].c_str()); - currDir->cd(); - currDir->Add(h_1->Clone()); - currDir->Add(h_2->Clone()); - - for (auto &i: pxf) - { - const GeomDet *det = i; - - PXFDetId id = det->geographicalId(); - - int side = tt->side(id);//tt->pxfSide(id); - int disk = tt->layer(id);//tt->pxfDisk(id); - int blade = tt->pxfBlade(id); - unsigned mapIdx = disk + (side - 1) * 3 - 1; - - unsigned rawId = id.rawId(); - - PixelEndcapName pixelEndcapName = PixelEndcapName(PXFDetId(rawId), tt, true); - - if (pixelEndcapName.ringName() == 1) h = h_1; - else h = h_2; - - // ---- REMAP (Online -> Offline) - unsigned nx = h->GetNbinsX(); - unsigned ny = h->GetNbinsY(); - - int onlineBlade = pixelEndcapName.bladeName(); - bool isInnerOnlineBlade = !(pixelEndcapName.halfCylinder() & 1); // inner -> blade > 0 (?) - - int signedOnlineBlade = (isInnerOnlineBlade) ? onlineBlade : -onlineBlade; - int signedDisk = (side == 2) ? disk : -disk; - int pannel = pixelEndcapName.pannelName() - 1; - - unsigned binX = signedDisk + ((nx + 1) >> 1); - unsigned binY = (signedOnlineBlade * 2) + (ny >> 1); - - string strName = baseHistogramName[nameNum]; - -#ifdef DEBUG_MODE - pxfTh2PolyForward[strName][mapIdx]->Fill(TString::Format("%u",rawId), blade); - pxfTh2PolyForwardSummary[strName]->Fill(TString::Format("%u",rawId), blade); + + for (unsigned nameNum = 0; nameNum < baseHistogramName.size(); ++nameNum) { + if (isBarrelSource[nameNum]) + continue; + + string baseHistogramNameWithPath = pathToHistograms[nameNum] + baseHistogramName[nameNum] + "_"; + + const TProfile2D* h_1 = (TProfile2D*)rootFileHandle->Get((baseHistogramNameWithPath + "1;1 ").c_str()); + const TProfile2D* h_2 = (TProfile2D*)rootFileHandle->Get((baseHistogramNameWithPath + "2;1 ").c_str()); + const TProfile2D* h; + + if (h_2 && h_1) { + LogInfo("Analyzer") << "\nInput histograms: " << baseHistogramNameWithPath << " opened successfully\n"; + + //Add original histograms to this file + TDirectory* currDir = fs->getBareDirectory()->GetDirectory(baseHistogramName[nameNum].c_str()); + currDir->cd(); + currDir->Add(h_1->Clone()); + currDir->Add(h_2->Clone()); + + for (auto& i : pxf) { + const GeomDet* det = i; + + PXFDetId id = det->geographicalId(); + + int side = tt->side(id); //tt->pxfSide(id); + int disk = tt->layer(id); //tt->pxfDisk(id); + int blade = tt->pxfBlade(id); + unsigned mapIdx = disk + (side - 1) * 3 - 1; + + unsigned rawId = id.rawId(); + + PixelEndcapName pixelEndcapName = PixelEndcapName(PXFDetId(rawId), tt, true); + + if (pixelEndcapName.ringName() == 1) + h = h_1; + else + h = h_2; + + // ---- REMAP (Online -> Offline) + unsigned nx = h->GetNbinsX(); + unsigned ny = h->GetNbinsY(); + + int onlineBlade = pixelEndcapName.bladeName(); + bool isInnerOnlineBlade = !(pixelEndcapName.halfCylinder() & 1); // inner -> blade > 0 (?) + + int signedOnlineBlade = (isInnerOnlineBlade) ? onlineBlade : -onlineBlade; + int signedDisk = (side == 2) ? disk : -disk; + int pannel = pixelEndcapName.pannelName() - 1; + + unsigned binX = signedDisk + ((nx + 1) >> 1); + unsigned binY = (signedOnlineBlade * 2) + (ny >> 1); + + string strName = baseHistogramName[nameNum]; + +#ifdef DEBUG_MODE + pxfTh2PolyForward[strName][mapIdx]->Fill(TString::Format("%u", rawId), blade); + pxfTh2PolyForwardSummary[strName]->Fill(TString::Format("%u", rawId), blade); #else - double val = h->GetBinContent(binX, binY + pannel); - pxfTh2PolyForward[strName][mapIdx]->Fill(TString::Format("%u",rawId), val); - pxfTh2PolyForwardSummary[strName]->Fill(TString::Format("%u",rawId), val); -#endif - } - } - } - - rootFileHandle->Close(); - delete rootFileHandle; + double val = h->GetBinContent(binX, binY + pannel); + pxfTh2PolyForward[strName][mapIdx]->Fill(TString::Format("%u", rawId), val); + pxfTh2PolyForwardSummary[strName]->Fill(TString::Format("%u", rawId), val); +#endif + } + } + } + + rootFileHandle->Close(); + delete rootFileHandle; } // ------------ method called once each job just before starting event loop ------------ -void -SiPixelPhase1Analyzer::beginJob() -{ -} +void SiPixelPhase1Analyzer::beginJob() {} // ------------ method called once each job just after ending the event loop ------------ -void -SiPixelPhase1Analyzer::endJob() -{ -} +void SiPixelPhase1Analyzer::endJob() {} // ------------ method fills 'descriptions' with the allowed parameters for the module ------------ -void -SiPixelPhase1Analyzer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { +void SiPixelPhase1Analyzer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { //The following says we do not know what parameters are allowed so do no validation // Please change this to state exactly what you do use, even if it is no parameters edm::ParameterSetDescription desc;