Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pixel template making code update #30563

Merged
merged 2 commits into from Jul 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 27 additions & 0 deletions CondTools/SiPixel/data/phaseI_mapping.csv
@@ -0,0 +1,27 @@
RULES,,,,
,,,,
BARREL,,,,
,,,,
TEMPLATE ID ,LAYER,LADDER,MODULE,
310,1,1-12,1-8,
311,2,1-28,1-8,
312,3,1-44,1-8,
313,4,1-64,1-8,
,,,,
ENDCAP,,,,
,,,,
TEMPLATE ID ,DISK,BLADE,SIDE,PANEL
315,1-3,23-56,1-2,1
314,1-3,1-22,1-2,1
314,1-3,1-22,1-2,2
315,1-3,23-56,1-2,2
,,,,
EXCEPTIONS,,,,
,,,,
BARREL,,,,
,,,,
TEMPLATE ID ,LAYER,LADDER,MODULE,
,,,,
ENDCAP,,,,
,,,,
TEMPLATE ID ,DISK,BLADE,SIDE,PANEL
7 changes: 7 additions & 0 deletions CondTools/SiPixel/test/BuildFile.xml
Expand Up @@ -12,3 +12,10 @@
<library file="*.cc" name="testCondToolsSiPixel">
<flags EDM_PLUGIN="1"/>
</library>
<environment>
<bin file="testPixelDBs.cpp">
<flags TEST_RUNNER_ARGS=" /bin/bash CondTools/SiPixel/test run_0T_BoR3.sh"/>
<use name="FWCore/Utilities"/>
</bin>
</environment>

499 changes: 126 additions & 373 deletions CondTools/SiPixel/test/SiPixel2DTemplateDBObjectUploader.cc

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion CondTools/SiPixel/test/SiPixel2DTemplateDBObjectUploader.h
Expand Up @@ -31,7 +31,11 @@ class SiPixel2DTemplateDBObjectUploader : public edm::EDAnalyzer {
float theVersion;
float theMagField;
std::vector<uint32_t> theDetIds;
std::vector<uint32_t> theTemplIds;
vstring theBarrelLocations;
vstring theEndcapLocations;
std::vector<uint32_t> theBarrelTemplateIds;
std::vector<uint32_t> theEndcapTemplateIds;
bool useVectorIndices;
};

#endif
333 changes: 250 additions & 83 deletions CondTools/SiPixel/test/SiPixel2DTemplateDBObjectUploader_cfg.py

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions CondTools/SiPixel/test/SiPixelGenErrorDBObjectReader.cc
Expand Up @@ -10,9 +10,6 @@
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "CondFormats/SiPixelTransient/interface/SiPixelGenError.h"
//#include "MagneticField/Engine/interface/MagneticField.h"
//#include "FWCore/ParameterSet/interface/FileInPath.h"

#include "CondTools/SiPixel/test/SiPixelGenErrorDBObjectReader.h"

using namespace std;
Expand Down
171 changes: 136 additions & 35 deletions CondTools/SiPixel/test/SiPixelGenErrorDBObjectUploader.cc
Expand Up @@ -6,18 +6,28 @@

#include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
#include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h"
#include "Geometry/CommonTopologies/interface/PixelGeomDetUnit.h"
#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"

#include "DataFormats/DetId/interface/DetId.h"
#include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
#include "DataFormats/SiPixelDetId/interface/PixelBarrelName.h"
#include "DataFormats/SiPixelDetId/interface/PixelEndcapName.h"

#include <fstream>
#include <stdio.h>
#include <iostream>

SiPixelGenErrorDBObjectUploader::SiPixelGenErrorDBObjectUploader(const edm::ParameterSet& iConfig)
: theGenErrorCalibrations(iConfig.getParameter<vstring>("siPixelGenErrorCalibrations")),
theGenErrorBaseString(iConfig.getParameter<std::string>("theGenErrorBaseString")),
theVersion(iConfig.getParameter<double>("Version")),
theMagField(iConfig.getParameter<double>("MagField")),
theDetIds(iConfig.getParameter<std::vector<uint32_t> >("detIds")),
theTemplIds(iConfig.getParameter<std::vector<uint32_t> >("generrorIds")) {}
theBarrelLocations(iConfig.getParameter<std::vector<std::string> >("barrelLocations")),
theEndcapLocations(iConfig.getParameter<std::vector<std::string> >("endcapLocations")),
theBarrelGenErrIds(iConfig.getParameter<std::vector<uint32_t> >("barrelGenErrIds")),
theEndcapGenErrIds(iConfig.getParameter<std::vector<uint32_t> >("endcapGenErrIds")),
useVectorIndices(iConfig.getUntrackedParameter<bool>("useVectorIndices", false)) {}

SiPixelGenErrorDBObjectUploader::~SiPixelGenErrorDBObjectUploader() {}

Expand All @@ -41,9 +51,7 @@ void SiPixelGenErrorDBObjectUploader::analyze(const edm::Event& iEvent, const ed
for (m = 0; m < obj->numOfTempl(); ++m) {
edm::FileInPath file(theGenErrorCalibrations[m].c_str());
tempfile = (file.fullPath()).c_str();

std::ifstream in_file(tempfile, std::ios::in);

if (in_file.is_open()) {
edm::LogInfo("GenError Info") << "Opened GenError File: " << file.fullPath().c_str();

Expand Down Expand Up @@ -88,47 +96,140 @@ void SiPixelGenErrorDBObjectUploader::analyze(const edm::Event& iEvent, const ed
}
}

//Get the event setup
edm::ESHandle<TrackerGeometry> pDD;
es.get<TrackerDigiGeometryRecord>().get(pDD);

for (unsigned int i = 0; i < theDetIds.size(); ++i) {
short s_detid = (short)theDetIds[i];
short templid = (short)theTemplIds[i];
// Use the TrackerTopology class for layer/disk etc. number
edm::ESHandle<TrackerTopology> tTopoHandle;
es.get<TrackerTopologyRcd>().get(tTopoHandle);
const TrackerTopology* tTopo = tTopoHandle.product();

// This tells if we are using Phase I geometry (may be needed for commented out Phase 1 variables)
//bool phase = pDD->isThere(GeomDetEnumerators::P1PXB) && pDD->isThere(GeomDetEnumerators::P1PXEC);

//Loop over the detector elements and put the GenError IDs in place
for (const auto& it : pDD->detUnits()) {
if (it != 0) {
// Here is the actual looping step over all DetIds:
DetId detid = it->geographicalId();
unsigned int layer = 0, ladder = 0, disk = 0, side = 0, blade = 0, panel = 0, module = 0;
// Some extra variables that can be used for Phase 1 - comment in if needed
// unsigned int shl=0, sec=0, half=0, flipped=0, ring=0;
short thisID = 10000;
unsigned int iter;

// Now we sort them into the Barrel and Endcap:
//Barrel Pixels first
if (detid.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel)) {
std::cout << "--- IN THE BARREL ---\n";

//Get the layer, ladder, and module corresponding to this DetID
layer = tTopo->pxbLayer(detid.rawId());
ladder = tTopo->pxbLadder(detid.rawId());
module = tTopo->pxbModule(detid.rawId());
/*
// Comment these in if needed
PixelBarrelName pbn(detid, tTopo, phase);
shl = pbn.shell();
sec = pbn.sectorName();
half = pbn.isHalfModule();
// This tells if we are on a flipped ladder (in the inner radius, closer to beam)
flipped = (phase ? layer==4 : layer%2) ? ladder%2==0 : ladder%2==1;
*/
if (useVectorIndices) {
--layer;
--ladder;
--module;
}

//Assign template IDs
//Loop over all the barrel locations
for (iter = 0; iter < theBarrelLocations.size(); ++iter) {
//get the string of this barrel location
std::string loc_string = theBarrelLocations[iter];
//find where the delimiters are
unsigned int first_delim_pos = loc_string.find("_");
unsigned int second_delim_pos = loc_string.find("_", first_delim_pos + 1);
//get the layer, ladder, and module as unsigned ints
unsigned int checklayer = (unsigned int)stoi(loc_string.substr(0, first_delim_pos));
unsigned int checkladder =
(unsigned int)stoi(loc_string.substr(first_delim_pos + 1, second_delim_pos - first_delim_pos - 1));
unsigned int checkmodule = (unsigned int)stoi(loc_string.substr(second_delim_pos + 1, 5));
//check them against the desired layer, ladder, and module
if (ladder == checkladder && layer == checklayer && module == checkmodule)
//if they match, set the template ID
thisID = (short)theBarrelGenErrIds[iter];
}

DetId theDetid(s_detid);
if (s_detid != 0 && s_detid != 1 && s_detid != 2) {
if (!(*obj).putGenErrorID(theDetid.rawId(), templid)) {
edm::LogInfo("GenError Info") << " Could not fill specified det unit: " << theDetid;
if (thisID == 10000 || (!(*obj).putGenErrorID(detid.rawId(), thisID)))
std::cout << " Could not fill barrel layer " << layer << ", module " << module << "\n";
// ----- debug:
std::cout << "This is a barrel element with: layer " << layer << ", ladder " << ladder << " and module "
<< module << ".\n"; //Uncomment to read out exact position of each element.
// -----
}
} else {
edm::LogInfo("DetUnit Info") << " There are " << pDD->detUnits().size() << " detectors";
}
for (const auto& it : pDD->detUnits()) {
if (dynamic_cast<PixelGeomDetUnit const*>(it) != 0) {
DetId detid = it->geographicalId();

if (detid.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel) &&
(detid.subdetId() == s_detid || s_detid == 0)) {
if (!(*obj).putGenErrorID(detid.rawId(), templid))
edm::LogInfo("GenError Info") << " Could not fill barrel det unit";
//Now endcaps
else if (detid.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap)) {
std::cout << "--- IN AN ENDCAP ---\n";

//Get the DetID's disk, blade, side, panel, and module
disk = tTopo->pxfDisk(detid.rawId()); //1,2,3
blade = tTopo->pxfBlade(detid.rawId()); //1-56 (Ring 1 is 1-22, Ring 2 is 23-56)
side = tTopo->pxfSide(detid.rawId()); //side=1 for -z, 2 for +z
panel = tTopo->pxfPanel(detid.rawId()); //panel=1,2
/*
// Comment these in if needed
PixelEndcapName pen(detid, tTopo, phase);
shl = pen.halfCylinder();
ring = pen.ringName(); //1,2 This is for Phase I
*/
if (useVectorIndices) {
--disk;
--blade;
--side;
--panel;
}
if (detid.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap) &&
(detid.subdetId() == s_detid || s_detid == 0)) {
if (!(*obj).putGenErrorID(detid.rawId(), templid))
edm::LogInfo("GenError Info") << " Could not fill endcap det unit";

//Assign IDs
//Loop over all the endcap locations
for (iter = 0; iter < theEndcapLocations.size(); ++iter) {
//get the string of this barrel location
std::string loc_string = theEndcapLocations[iter];
//find where the delimiters are
unsigned int first_delim_pos = loc_string.find("_");
unsigned int second_delim_pos = loc_string.find("_", first_delim_pos + 1);
unsigned int third_delim_pos = loc_string.find("_", second_delim_pos + 1);
//get the disk, blade, side, panel, and module as unsigned ints
unsigned int checkdisk = (unsigned int)stoi(loc_string.substr(0, first_delim_pos));
unsigned int checkblade =
(unsigned int)stoi(loc_string.substr(first_delim_pos + 1, second_delim_pos - first_delim_pos - 1));
unsigned int checkside =
(unsigned int)stoi(loc_string.substr(second_delim_pos + 1, third_delim_pos - second_delim_pos - 1));
unsigned int checkpanel = (unsigned int)stoi(loc_string.substr(third_delim_pos + 1, 5));
//check them against the desired disk, blade, side, panel, and module
if (disk == checkdisk && blade == checkblade && side == checkside && panel == checkpanel)
//if they match, set the template ID
thisID = (short)theEndcapGenErrIds[iter];
}
} else {
//edm::LogInfo("GenError Info")<< "Detid is Pixel but neither bpix nor fpix";

if (thisID == 10000 || (!(*obj).putGenErrorID(detid.rawId(), thisID)))
std::cout << " Could not fill endcap det unit" << side << ", disk " << disk << ", blade " << blade
<< ", panel " << panel << ".\n";
// ----- debug:
std::cout << "This is an endcap element with: side " << side << ", disk " << disk << ", blade " << blade
<< ", panel " << panel << ".\n"; //Uncomment to read out exact position of each element.
// -----
}

//Print out the assignment of this DetID
short mapnum;
std::cout << "checking map:\n";
mapnum = (*obj).getGenErrorID(detid.rawId());
std::cout << "The DetID: " << detid.rawId() << " is mapped to the template: " << mapnum << ".\n\n";
}
}

// Uncomment to output the contents of the db object at the end of the job
// std::cout << *obj << std::endl;
//std::map<unsigned int,short> templMap=(*obj).getGenErrorIDs();
//for(std::map<unsigned int,short>::const_iterator it=templMap.begin(); it!=templMap.end();++it)
//std::cout<< "Map:\n"<< "DetId: "<< it->first << " GenErrorID: "<< it->second <<"\n";

//--- Create a new IOV
edm::Service<cond::service::PoolDBOutputService> poolDbService;
if (!poolDbService.isAvailable()) // Die if not available
Expand Down
6 changes: 5 additions & 1 deletion CondTools/SiPixel/test/SiPixelGenErrorDBObjectUploader.h
Expand Up @@ -31,7 +31,11 @@ class SiPixelGenErrorDBObjectUploader : public edm::EDAnalyzer {
float theVersion;
float theMagField;
std::vector<uint32_t> theDetIds;
std::vector<uint32_t> theTemplIds;
vstring theBarrelLocations;
vstring theEndcapLocations;
std::vector<uint32_t> theBarrelGenErrIds;
std::vector<uint32_t> theEndcapGenErrIds;
bool useVectorIndices;
};

#endif