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_.

83  :
85  pullBadModulesToIdeal_{iConfig.getUntrackedParameter<bool>("pullBadModulesToIdeal")},
86  outlierPullToIdealCut_{iConfig.getUntrackedParameter<double>("outlierPullToIdealCut")}
87 {
88 }
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 98 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, JetEnergyShift_cfi::scaleFactor, scalers_, ntuplemaker::since, jetUpdater_cfi::sort, GeomDetEnumerators::subDetId, StripSubdetector::TIB, cond::timeTypeSpecs, StripSubdetector::TOB, ecaldqm::topology(), trackingTruthProducer_cfi::tracker, and cond::service::PoolDBOutputService::writeOne().

99 {
100  if (!firstEvent_) return;
101  firstEvent_ = false;
102 
103  // get handle on bad modules
104  edm::ESHandle<SiPixelQuality> pixelModules;
105  iSetup.get<SiPixelQualityRcd>().get(pixelModules);
106  edm::ESHandle<SiStripQuality> stripModules;
107  iSetup.get<SiStripQualityRcd>().get(stripModules);
108 
109  // get the tracker geometry
110  edm::ESHandle<GeometricDet> geometricDet;
111  iSetup.get<IdealGeometryRecord>().get(geometricDet);
113  iSetup.get<PTrackerParametersRcd>().get(ptp);
114  edm::ESHandle<TrackerTopology> tTopoHandle;
115  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
116  const auto* const topology = tTopoHandle.product();
117  TrackerGeomBuilderFromGeometricDet trackerBuilder;
118  auto tracker = std::unique_ptr<TrackerGeometry> {
119  trackerBuilder.build(&(*geometricDet), *ptp, topology)};
120 
121  auto dets = tracker->dets();
122  std::sort(dets.begin(), dets.end(),
123  [](const auto& a, const auto& b) {
124  return a->geographicalId().rawId() < b->geographicalId().rawId();});
125 
126  // get the input alignment
127  edm::ESHandle<Alignments> alignments;
128  iSetup.get<TrackerAlignmentRcd>().get(alignments);
129 
130  if (dets.size() != alignments->m_align.size()) {
131  throw cms::Exception("GeometryMismatch")
132  << "Size mismatch between alignments (size=" << alignments->m_align.size()
133  << ") and ideal geometry (size=" << dets.size() << ")";
134  }
135 
136  Alignments rescaledAlignments{};
137  {
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()) {
144  throw cms::Exception("GeometryMismatch")
145  << "Order differs between Dets in alignments ideal geometry.";
146  }
147 
148  // determine scale factor
149  const auto& subDetId = (*ideal)->geographicalId().subdetId();
150  auto side = topology->side((*ideal)->geographicalId());
151  if (side == 0) {
152  switch(subDetId) {
154  side = 1; // both sides are treated identical -> pick one of them
155  break;
157  side = topology->tibSide((*ideal)->geographicalId());
158  break;
160  side = topology->tobSide((*ideal)->geographicalId());
161  break;
162  default: break;
163  }
164  }
165  auto scaleFactor = scalers_.find(subDetId)->second.find(side)->second;
166 
168  (pixelModules->IsModuleBad(misaligned->rawId()) ||
169  stripModules->IsModuleBad(misaligned->rawId()))) {
170  scaleFactor = 0.0;
171  }
172 
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();
176 
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();
186 
187  if (outlierPullToIdealCut_ > 0.0 &&
188  (x_diff*x_diff + y_diff*y_diff + z_diff*z_diff)
190  ++outlierCounter;
191  edm::LogInfo("Alignment")
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
205  << "\n";
206  scaleFactor = 0.0;
207  }
208 
209  const AlignTransform::Translation rescaledTranslation{
210  (*ideal)->position().x() + scaleFactor*x_diff,
211  (*ideal)->position().y() + scaleFactor*y_diff,
212  (*ideal)->position().z() + scaleFactor*z_diff
213  };
214 
215  const AlignTransform::Rotation rescaledRotation{
216  CLHEP::HepRep3x3{
217  (*ideal)->rotation().xx() + scaleFactor*xx_diff,
218  (*ideal)->rotation().xy() + scaleFactor*xy_diff,
219  (*ideal)->rotation().xz() + scaleFactor*xz_diff,
220  (*ideal)->rotation().yx() + scaleFactor*yx_diff,
221  (*ideal)->rotation().yy() + scaleFactor*yy_diff,
222  (*ideal)->rotation().yz() + scaleFactor*yz_diff,
223  (*ideal)->rotation().zx() + scaleFactor*zx_diff,
224  (*ideal)->rotation().zy() + scaleFactor*zy_diff,
225  (*ideal)->rotation().zz() + scaleFactor*zz_diff
226  }
227  };
228 
229  const AlignTransform rescaledTransform{rescaledTranslation,
230  rescaledRotation,
231  misaligned->rawId()};
232  rescaledAlignments.m_align.emplace_back(std::move(rescaledTransform));
233  }
234  }
235 
237  if (!poolDb.isAvailable()) {
238  throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
239  }
240  edm::LogInfo("Alignment")
241  << "Writing rescaled tracker-alignment record.";
243  poolDb->writeOne(&rescaledAlignments, since, "TrackerAlignmentRcd");
244 
245 }
const TimeTypeSpecs timeTypeSpecs[]
Definition: Time.cc:22
CaloTopology const * topology(0)
Time_t beginValue
Definition: Time.h:45
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)
bool IsModuleBad(const uint32_t &detid) const
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121
T get() const
Definition: EventSetup.h:71
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 249 of file MCMisalignmentScaler.cc.

References funct::abs(), Exception, dataset::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().

250 {
251  // initialize scaler map
252  ScalerMap subDetMap;
253  for (unsigned int subDetId = 1; subDetId <= 6; ++subDetId) {
254  subDetMap[subDetId][1] = 1.0;
255  subDetMap[subDetId][2] = 1.0;
256  }
257 
258  // apply scale factors from configuration
259  for (const auto& pset: psets) {
260  const auto& name = pset.getUntrackedParameter<std::string>("subDetector");
261  const auto& factor = pset.getUntrackedParameter<double>("factor");
262 
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);
266  if (sides.empty()) { // -> use both sides
267  sides.push_back(1);
268  sides.push_back(2);
269  }
270 
271  if (name.find("Tracker") != std::string::npos) {
272  for (unsigned int subDetId = 1; subDetId <= 6; ++subDetId) {
273  for (const auto& side: sides) subDetMap[subDetId][side] *= factor;
274  }
275  if (sides.size() == 1) {
276  // if only one side to be scaled
277  // -> scale also the other side for PXB (subdetid = 1)
278  subDetMap[PixelSubdetector::PixelBarrel][std::abs(sides[0] - 2) + 1] *= factor;
279  }
280  } else if (name.find("PXB") != std::string::npos) {
281  // ignore sides for PXB
282  subDetMap[PixelSubdetector::PixelBarrel][1] *= factor;
283  subDetMap[PixelSubdetector::PixelBarrel][2] *= factor;
284  } else if (name.find("PXF") != std::string::npos) {
285  for (const auto& side: sides) subDetMap[PixelSubdetector::PixelEndcap][side] *= factor;
286  } else if (name.find("TIB") != std::string::npos) {
287  for (const auto& side: sides) subDetMap[StripSubdetector::TIB][side] *= factor;
288  } else if (name.find("TOB") != std::string::npos) {
289  for (const auto& side: sides) subDetMap[StripSubdetector::TOB][side] *= factor;
290  } else if (name.find("TID") != std::string::npos) {
291  for (const auto& side: sides) subDetMap[StripSubdetector::TID][side] *= factor;
292  } else if (name.find("TEC") != std::string::npos) {
293  for (const auto& side: sides) subDetMap[StripSubdetector::TEC][side] *= factor;
294  } else {
295  throw cms::Exception("BadConfig")
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 '-')";
300  }
301  }
302 
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";
309  }
310  logInfo << "\n";
311  }
312  edm::LogInfo("Alignment") << logInfo.str();
313 
314  return subDetMap;
315 }
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
void MCMisalignmentScaler::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 320 of file MCMisalignmentScaler.cc.

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

321 {
323  desc.setComment("Creates rescaled MC misalignment scenario. "
324  "PoolDBOutputService must be set up for 'TrackerAlignmentRcd'.");
325  edm::ParameterSetDescription descScaler;
326  descScaler.setComment("ParameterSet specifying the tracker part to be scaled "
327  "by a given factor.");
328  descScaler.addUntracked<std::string>("subDetector", "Tracker");
329  descScaler.addUntracked<double>("factor", 1.0);
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);
334 }
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().