25 #include <unordered_map> 68 using ScalerMap = std::unordered_map<unsigned int, std::unordered_map<int, double> >;
118 auto tracker = std::unique_ptr<TrackerGeometry> {
122 std::sort(dets.begin(), dets.end(),
123 [](
const auto&
a,
const auto&
b) {
124 return a->geographicalId().rawId() <
b->geographicalId().rawId();});
130 if (dets.size() != alignments->m_align.size()) {
132 <<
"Size mismatch between alignments (size=" << alignments->m_align.size()
133 <<
") and ideal geometry (size=" << dets.size() <<
")";
138 auto outlierCounter{0};
139 auto ideal = dets.cbegin();
140 const auto& ideal_end = dets.cend();
141 auto misaligned = alignments->
m_align.cbegin();
142 for (; ideal != ideal_end; ++ideal, ++misaligned) {
143 if ((*ideal)->geographicalId().rawId() != misaligned->rawId()) {
145 <<
"Order differs between Dets in alignments ideal geometry.";
149 const auto&
subDetId = (*ideal)->geographicalId().subdetId();
150 auto side =
topology->side((*ideal)->geographicalId());
157 side =
topology->tibSide((*ideal)->geographicalId());
160 side =
topology->tobSide((*ideal)->geographicalId());
173 auto x_diff = misaligned->translation().x() - (*ideal)->position().x();
174 auto y_diff = misaligned->translation().y() - (*ideal)->position().y();
175 auto z_diff = misaligned->translation().z() - (*ideal)->position().z();
177 auto xx_diff = misaligned->rotation().xx() - (*ideal)->rotation().xx();
178 auto xy_diff = misaligned->rotation().xy() - (*ideal)->rotation().xy();
179 auto xz_diff = misaligned->rotation().xz() - (*ideal)->rotation().xz();
180 auto yx_diff = misaligned->rotation().yx() - (*ideal)->rotation().yx();
181 auto yy_diff = misaligned->rotation().yy() - (*ideal)->rotation().yy();
182 auto yz_diff = misaligned->rotation().yz() - (*ideal)->rotation().yz();
183 auto zx_diff = misaligned->rotation().zx() - (*ideal)->rotation().zx();
184 auto zy_diff = misaligned->rotation().zy() - (*ideal)->rotation().zy();
185 auto zz_diff = misaligned->rotation().zz() - (*ideal)->rotation().zz();
188 (x_diff*x_diff + y_diff*y_diff + z_diff*z_diff)
192 << outlierCounter <<
") Outlier found in subdetector " <<
subDetId 193 <<
": delta x: " << x_diff
194 <<
", delta y: " << y_diff
195 <<
", delta z: " << z_diff
196 <<
", delta xx: " << xx_diff
197 <<
", delta xy: " << xy_diff
198 <<
", delta xz: " << xz_diff
199 <<
", delta yx: " << yx_diff
200 <<
", delta yx: " << yy_diff
201 <<
", delta yy: " << yz_diff
202 <<
", delta zz: " << zx_diff
203 <<
", delta zy: " << zy_diff
204 <<
", delta zz: " << zz_diff
231 misaligned->
rawId()};
232 rescaledAlignments.m_align.emplace_back(
std::move(rescaledTransform));
238 throw cms::Exception(
"NotAvailable") <<
"PoolDBOutputService not available";
241 <<
"Writing rescaled tracker-alignment record.";
243 poolDb->
writeOne(&rescaledAlignments,
since,
"TrackerAlignmentRcd");
259 for (
const auto&
pset: psets) {
261 const auto& factor =
pset.getUntrackedParameter<
double>(
"factor");
263 std::vector<int> sides;
264 if (
name.find(
"-") != std::string::npos) sides.push_back(1);
265 if (
name.find(
"+") != std::string::npos) sides.push_back(2);
271 if (
name.find(
"Tracker") != std::string::npos) {
273 for (
const auto& side: sides) subDetMap[
subDetId][side] *= factor;
275 if (sides.size() == 1) {
280 }
else if (
name.find(
"PXB") != std::string::npos) {
284 }
else if (
name.find(
"PXF") != std::string::npos) {
286 }
else if (
name.find(
"TIB") != std::string::npos) {
288 }
else if (
name.find(
"TOB") != std::string::npos) {
290 }
else if (
name.find(
"TID") != std::string::npos) {
292 }
else if (
name.find(
"TEC") != std::string::npos) {
296 <<
"@SUB=MCMisalignmentScaler::decodeSubDetectors\n" 297 <<
"Unknown tracker subdetector: " <<
name 298 <<
"\nSupported options: Tracker, PXB, PXF, TIB, TOB, TID, TEC " 299 <<
"(possibly decorated with '+' or '-')";
303 std::stringstream logInfo;
304 logInfo <<
"MC misalignment scale factors:\n";
305 for (
const auto& subdet: subDetMap) {
306 logInfo <<
" Subdet " << subdet.first <<
"\n";
307 for (
const auto& side: subdet.second) {
308 logInfo <<
" side " << side.first <<
": " << side.second <<
"\n";
323 desc.
setComment(
"Creates rescaled MC misalignment scenario. " 324 "PoolDBOutputService must be set up for 'TrackerAlignmentRcd'.");
326 descScaler.
setComment(
"ParameterSet specifying the tracker part to be scaled " 327 "by a given factor.");
330 desc.
addVPSet(
"scalers", descScaler, std::vector<edm::ParameterSet>(1));
331 desc.
addUntracked<
bool>(
"pullBadModulesToIdeal",
false);
332 desc.
addUntracked<
double>(
"outlierPullToIdealCut", -1.0);
333 descriptions.
add(
"mcMisalignmentScaler", desc);
const TimeTypeSpecs timeTypeSpecs[]
T getParameter(std::string const &) const
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
CaloTopology const * topology(0)
#define DEFINE_FWK_MODULE(type)
std::vector< ParameterSet > VParameterSet
TrackerGeometry * build(const GeometricDet *gd, const PTrackerParameters &ptp, const TrackerTopology *tTopo)
std::vector< AlignTransform > m_align
const double outlierPullToIdealCut_
void setComment(std::string const &value)
MCMisalignmentScaler(const edm::ParameterSet &)
unsigned int subDetId[21]
std::unordered_map< unsigned int, std::unordered_map< int, double > > ScalerMap
~MCMisalignmentScaler() override=default
ScalerMap decodeSubDetectors(const edm::VParameterSet &)
Abs< T >::type abs(const T &t)
bool IsModuleBad(const uint32_t &detid) const
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
void analyze(const edm::Event &, const edm::EventSetup &) override
bool IsModuleBad(const uint32_t &detid) const
void add(std::string const &label, ParameterSetDescription const &psetDescription)
const bool pullBadModulesToIdeal_
static void fillDescriptions(edm::ConfigurationDescriptions &)
T const * product() const