CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes
MCMisalignmentScaler Class Reference

#include <Alignment/TrackerAlignment/plugins/MCMisalignmentScaler.cc>

Inheritance diagram for MCMisalignmentScaler:
edm::one::EDAnalyzer<> edm::one::EDAnalyzerBase edm::EDConsumerBase

Public Member Functions

 MCMisalignmentScaler (const edm::ParameterSet &)
 
 ~MCMisalignmentScaler () override=default
 
- Public Member Functions inherited from edm::one::EDAnalyzer<>
 EDAnalyzer ()=default
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
- Public Member Functions inherited from edm::one::EDAnalyzerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzerBase ()
 
ModuleDescription const & moduleDescription () const
 
bool wantsStreamLuminosityBlocks () const
 
bool wantsStreamRuns () const
 
 ~EDAnalyzerBase () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &)
 
- Static Public Member Functions inherited from edm::one::EDAnalyzerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Private Types

using ScalerMap = std::unordered_map< unsigned int, std::unordered_map< int, double > >
 

Private Member Functions

void analyze (const edm::Event &, const edm::EventSetup &) override
 
ScalerMap decodeSubDetectors (const edm::VParameterSet &)
 

Private Attributes

bool firstEvent_ {true}
 
const double outlierPullToIdealCut_
 
const bool pullBadModulesToIdeal_
 
const ScalerMap scalers_
 

Additional Inherited Members

- Public Types inherited from edm::one::EDAnalyzerBase
typedef EDAnalyzerBase ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Description: Plugin to rescale misalignment wrt. ideal geometry

Implementation:

The plugin takes the ideal geometry and the alignment object and rescales the position difference by the scaling factor provided by the user.

Definition at line 60 of file MCMisalignmentScaler.cc.

Member Typedef Documentation

using MCMisalignmentScaler::ScalerMap = std::unordered_map<unsigned int, std::unordered_map<int, double> >
private

Definition at line 68 of file MCMisalignmentScaler.cc.

Constructor & Destructor Documentation

MCMisalignmentScaler::MCMisalignmentScaler ( const edm::ParameterSet iConfig)
explicit

Definition at line 83 of file MCMisalignmentScaler.cc.

References decodeSubDetectors(), edm::ParameterSet::getParameter(), outlierPullToIdealCut_, and pullBadModulesToIdeal_.

85  pullBadModulesToIdeal_{iConfig.getUntrackedParameter<bool>("pullBadModulesToIdeal")},
86  outlierPullToIdealCut_{iConfig.getUntrackedParameter<double>("outlierPullToIdealCut")} {}
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::vector< ParameterSet > VParameterSet
Definition: ParameterSet.h:33
const double outlierPullToIdealCut_
ScalerMap decodeSubDetectors(const edm::VParameterSet &)
MCMisalignmentScaler::~MCMisalignmentScaler ( )
overridedefault

Member Function Documentation

void MCMisalignmentScaler::analyze ( const edm::Event ,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 93 of file MCMisalignmentScaler.cc.

References a, b, cond::TimeTypeSpecs::beginValue, TrackerGeomBuilderFromGeometricDet::build(), Exception, firstEvent_, edm::EventSetup::get(), edm::Service< T >::isAvailable(), SiStripQuality::IsModuleBad(), SiPixelQuality::IsModuleBad(), Alignments::m_align, eostools::move(), outlierPullToIdealCut_, PixelSubdetector::PixelBarrel, edm::ESHandle< T >::product(), pullBadModulesToIdeal_, AlignTransform::rawId(), cond::runnumber, multiplicitycorr_cfi::scaleFactor, scalers_, writeEcalDQMStatus::since, GeomDetEnumerators::subDetId, StripSubdetector::TIB, cond::timeTypeSpecs, StripSubdetector::TOB, ecaldqm::topology(), PbPb_ZMuSkimMuonDPG_cff::tracker, and cond::service::PoolDBOutputService::writeOne().

93  {
94  if (!firstEvent_)
95  return;
96  firstEvent_ = false;
97 
98  // get handle on bad modules
99  edm::ESHandle<SiPixelQuality> pixelModules;
100  iSetup.get<SiPixelQualityRcd>().get(pixelModules);
101  edm::ESHandle<SiStripQuality> stripModules;
102  iSetup.get<SiStripQualityRcd>().get(stripModules);
103 
104  // get the tracker geometry
105  edm::ESHandle<GeometricDet> geometricDet;
106  iSetup.get<IdealGeometryRecord>().get(geometricDet);
108  iSetup.get<PTrackerParametersRcd>().get(ptp);
109  edm::ESHandle<TrackerTopology> tTopoHandle;
110  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
111  const auto* const topology = tTopoHandle.product();
112  TrackerGeomBuilderFromGeometricDet trackerBuilder;
113  auto tracker = std::unique_ptr<TrackerGeometry>{trackerBuilder.build(&(*geometricDet), *ptp, topology)};
114 
115  auto dets = tracker->dets();
116  std::sort(dets.begin(), dets.end(), [](const auto& a, const auto& b) {
117  return a->geographicalId().rawId() < b->geographicalId().rawId();
118  });
119 
120  // get the input alignment
121  edm::ESHandle<Alignments> alignments;
122  iSetup.get<TrackerAlignmentRcd>().get(alignments);
123 
124  if (dets.size() != alignments->m_align.size()) {
125  throw cms::Exception("GeometryMismatch") << "Size mismatch between alignments (size=" << alignments->m_align.size()
126  << ") and ideal geometry (size=" << dets.size() << ")";
127  }
128 
129  Alignments rescaledAlignments{};
130  {
131  auto outlierCounter{0};
132  auto ideal = dets.cbegin();
133  const auto& ideal_end = dets.cend();
134  auto misaligned = alignments->m_align.cbegin();
135  for (; ideal != ideal_end; ++ideal, ++misaligned) {
136  if ((*ideal)->geographicalId().rawId() != misaligned->rawId()) {
137  throw cms::Exception("GeometryMismatch") << "Order differs between Dets in alignments ideal geometry.";
138  }
139 
140  // determine scale factor
141  const auto& subDetId = (*ideal)->geographicalId().subdetId();
142  auto side = topology->side((*ideal)->geographicalId());
143  if (side == 0) {
144  switch (subDetId) {
146  side = 1; // both sides are treated identical -> pick one of them
147  break;
149  side = topology->tibSide((*ideal)->geographicalId());
150  break;
152  side = topology->tobSide((*ideal)->geographicalId());
153  break;
154  default:
155  break;
156  }
157  }
158  auto scaleFactor = scalers_.find(subDetId)->second.find(side)->second;
159 
161  (pixelModules->IsModuleBad(misaligned->rawId()) || stripModules->IsModuleBad(misaligned->rawId()))) {
162  scaleFactor = 0.0;
163  }
164 
165  auto x_diff = misaligned->translation().x() - (*ideal)->position().x();
166  auto y_diff = misaligned->translation().y() - (*ideal)->position().y();
167  auto z_diff = misaligned->translation().z() - (*ideal)->position().z();
168 
169  auto xx_diff = misaligned->rotation().xx() - (*ideal)->rotation().xx();
170  auto xy_diff = misaligned->rotation().xy() - (*ideal)->rotation().xy();
171  auto xz_diff = misaligned->rotation().xz() - (*ideal)->rotation().xz();
172  auto yx_diff = misaligned->rotation().yx() - (*ideal)->rotation().yx();
173  auto yy_diff = misaligned->rotation().yy() - (*ideal)->rotation().yy();
174  auto yz_diff = misaligned->rotation().yz() - (*ideal)->rotation().yz();
175  auto zx_diff = misaligned->rotation().zx() - (*ideal)->rotation().zx();
176  auto zy_diff = misaligned->rotation().zy() - (*ideal)->rotation().zy();
177  auto zz_diff = misaligned->rotation().zz() - (*ideal)->rotation().zz();
178 
179  if (outlierPullToIdealCut_ > 0.0 &&
180  (x_diff * x_diff + y_diff * y_diff + z_diff * z_diff) > outlierPullToIdealCut_ * outlierPullToIdealCut_) {
181  ++outlierCounter;
182  edm::LogInfo("Alignment") << outlierCounter << ") Outlier found in subdetector " << subDetId
183  << ": delta x: " << x_diff << ", delta y: " << y_diff << ", delta z: " << z_diff
184  << ", delta xx: " << xx_diff << ", delta xy: " << xy_diff
185  << ", delta xz: " << xz_diff << ", delta yx: " << yx_diff
186  << ", delta yx: " << yy_diff << ", delta yy: " << yz_diff
187  << ", delta zz: " << zx_diff << ", delta zy: " << zy_diff
188  << ", delta zz: " << zz_diff << "\n";
189  scaleFactor = 0.0;
190  }
191 
192  const AlignTransform::Translation rescaledTranslation{(*ideal)->position().x() + scaleFactor * x_diff,
193  (*ideal)->position().y() + scaleFactor * y_diff,
194  (*ideal)->position().z() + scaleFactor * z_diff};
195 
196  const AlignTransform::Rotation rescaledRotation{
197  CLHEP::HepRep3x3{(*ideal)->rotation().xx() + scaleFactor * xx_diff,
198  (*ideal)->rotation().xy() + scaleFactor * xy_diff,
199  (*ideal)->rotation().xz() + scaleFactor * xz_diff,
200  (*ideal)->rotation().yx() + scaleFactor * yx_diff,
201  (*ideal)->rotation().yy() + scaleFactor * yy_diff,
202  (*ideal)->rotation().yz() + scaleFactor * yz_diff,
203  (*ideal)->rotation().zx() + scaleFactor * zx_diff,
204  (*ideal)->rotation().zy() + scaleFactor * zy_diff,
205  (*ideal)->rotation().zz() + scaleFactor * zz_diff}};
206 
207  const AlignTransform rescaledTransform{rescaledTranslation, rescaledRotation, misaligned->rawId()};
208  rescaledAlignments.m_align.emplace_back(std::move(rescaledTransform));
209  }
210  }
211 
213  if (!poolDb.isAvailable()) {
214  throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
215  }
216  edm::LogInfo("Alignment") << "Writing rescaled tracker-alignment record.";
218  poolDb->writeOne(&rescaledAlignments, since, "TrackerAlignmentRcd");
219 }
const TimeTypeSpecs timeTypeSpecs[]
Definition: Time.cc:16
CaloTopology const * topology(0)
Time_t beginValue
Definition: Time.h:41
CLHEP::Hep3Vector Translation
TrackerGeometry * build(const GeometricDet *gd, const PTrackerParameters &ptp, const TrackerTopology *tTopo)
std::vector< AlignTransform > m_align
Definition: Alignments.h:19
const double outlierPullToIdealCut_
unsigned int subDetId[21]
bool isAvailable() const
Definition: Service.h:40
bool IsModuleBad(const uint32_t &detid) const
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
static constexpr auto TOB
bool IsModuleBad(const uint32_t &detid) const
static constexpr auto TIB
double b
Definition: hdecay.h:118
double a
Definition: hdecay.h:119
T get() const
Definition: EventSetup.h:73
align::ID rawId() const
Do not expose Euler angles since we may change its type later.
T const * product() const
Definition: ESHandle.h:86
def move(src, dest)
Definition: eostools.py:511
CLHEP::HepRotation Rotation
MCMisalignmentScaler::ScalerMap MCMisalignmentScaler::decodeSubDetectors ( const edm::VParameterSet psets)
private

Definition at line 221 of file MCMisalignmentScaler.cc.

References funct::abs(), Exception, DQMScaleToClient_cfi::factor, Skims_PA_cff::name, PixelSubdetector::PixelBarrel, PixelSubdetector::PixelEndcap, muonDTDigis_cfi::pset, AlCaHLTBitMon_QueryRunRegistry::string, GeomDetEnumerators::subDetId, StripSubdetector::TEC, StripSubdetector::TIB, StripSubdetector::TID, and StripSubdetector::TOB.

Referenced by MCMisalignmentScaler().

221  {
222  // initialize scaler map
223  ScalerMap subDetMap;
224  for (unsigned int subDetId = 1; subDetId <= 6; ++subDetId) {
225  subDetMap[subDetId][1] = 1.0;
226  subDetMap[subDetId][2] = 1.0;
227  }
228 
229  // apply scale factors from configuration
230  for (const auto& pset : psets) {
231  const auto& name = pset.getUntrackedParameter<std::string>("subDetector");
232  const auto& factor = pset.getUntrackedParameter<double>("factor");
233 
234  std::vector<int> sides;
235  if (name.find("-") != std::string::npos)
236  sides.push_back(1);
237  if (name.find("+") != std::string::npos)
238  sides.push_back(2);
239  if (sides.empty()) { // -> use both sides
240  sides.push_back(1);
241  sides.push_back(2);
242  }
243 
244  if (name.find("Tracker") != std::string::npos) {
245  for (unsigned int subDetId = 1; subDetId <= 6; ++subDetId) {
246  for (const auto& side : sides)
247  subDetMap[subDetId][side] *= factor;
248  }
249  if (sides.size() == 1) {
250  // if only one side to be scaled
251  // -> scale also the other side for PXB (subdetid = 1)
252  subDetMap[PixelSubdetector::PixelBarrel][std::abs(sides[0] - 2) + 1] *= factor;
253  }
254  } else if (name.find("PXB") != std::string::npos) {
255  // ignore sides for PXB
256  subDetMap[PixelSubdetector::PixelBarrel][1] *= factor;
257  subDetMap[PixelSubdetector::PixelBarrel][2] *= factor;
258  } else if (name.find("PXF") != std::string::npos) {
259  for (const auto& side : sides)
260  subDetMap[PixelSubdetector::PixelEndcap][side] *= factor;
261  } else if (name.find("TIB") != std::string::npos) {
262  for (const auto& side : sides)
263  subDetMap[StripSubdetector::TIB][side] *= factor;
264  } else if (name.find("TOB") != std::string::npos) {
265  for (const auto& side : sides)
266  subDetMap[StripSubdetector::TOB][side] *= factor;
267  } else if (name.find("TID") != std::string::npos) {
268  for (const auto& side : sides)
269  subDetMap[StripSubdetector::TID][side] *= factor;
270  } else if (name.find("TEC") != std::string::npos) {
271  for (const auto& side : sides)
272  subDetMap[StripSubdetector::TEC][side] *= factor;
273  } else {
274  throw cms::Exception("BadConfig") << "@SUB=MCMisalignmentScaler::decodeSubDetectors\n"
275  << "Unknown tracker subdetector: " << name
276  << "\nSupported options: Tracker, PXB, PXF, TIB, TOB, TID, TEC "
277  << "(possibly decorated with '+' or '-')";
278  }
279  }
280 
281  std::stringstream logInfo;
282  logInfo << "MC misalignment scale factors:\n";
283  for (const auto& subdet : subDetMap) {
284  logInfo << " Subdet " << subdet.first << "\n";
285  for (const auto& side : subdet.second) {
286  logInfo << " side " << side.first << ": " << side.second << "\n";
287  }
288  logInfo << "\n";
289  }
290  edm::LogInfo("Alignment") << logInfo.str();
291 
292  return subDetMap;
293 }
static constexpr auto TEC
unsigned int subDetId[21]
std::unordered_map< unsigned int, std::unordered_map< int, double > > ScalerMap
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static constexpr auto TOB
static constexpr auto TIB
static constexpr auto TID
void MCMisalignmentScaler::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 296 of file MCMisalignmentScaler.cc.

References edm::ConfigurationDescriptions::add(), edm::ParameterSetDescription::addUntracked(), edm::ParameterSetDescription::addVPSet(), DEFINE_FWK_MODULE, edm::ParameterSetDescription::setComment(), and AlCaHLTBitMon_QueryRunRegistry::string.

296  {
298  desc.setComment(
299  "Creates rescaled MC misalignment scenario. "
300  "PoolDBOutputService must be set up for 'TrackerAlignmentRcd'.");
301  edm::ParameterSetDescription descScaler;
302  descScaler.setComment(
303  "ParameterSet specifying the tracker part to be scaled "
304  "by a given factor.");
305  descScaler.addUntracked<std::string>("subDetector", "Tracker");
306  descScaler.addUntracked<double>("factor", 1.0);
307  desc.addVPSet("scalers", descScaler, std::vector<edm::ParameterSet>(1));
308  desc.addUntracked<bool>("pullBadModulesToIdeal", false);
309  desc.addUntracked<double>("outlierPullToIdealCut", -1.0);
310  descriptions.add("mcMisalignmentScaler", desc);
311 }
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
void setComment(std::string const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)

Member Data Documentation

bool MCMisalignmentScaler::firstEvent_ {true}
private

Definition at line 77 of file MCMisalignmentScaler.cc.

Referenced by analyze().

const double MCMisalignmentScaler::outlierPullToIdealCut_
private

Definition at line 76 of file MCMisalignmentScaler.cc.

Referenced by analyze(), and MCMisalignmentScaler().

const bool MCMisalignmentScaler::pullBadModulesToIdeal_
private

Definition at line 75 of file MCMisalignmentScaler.cc.

Referenced by analyze(), and MCMisalignmentScaler().

const ScalerMap MCMisalignmentScaler::scalers_
private

Definition at line 74 of file MCMisalignmentScaler.cc.

Referenced by analyze().