CMS 3D CMS Logo

CTPPSGeometryESModule.cc
Go to the documentation of this file.
1 /****************************************************************************
2 * Based on CTPPSGeometryESModule.cc by:
3 * Jan Kaspar (jan.kaspar@gmail.com)
4 * Dominik Mierzejewski <dmierzej@cern.ch>
5 *
6 * Rewritten + Moved out common functionailities to DetGeomDesc(Builder) by Gabrielle Hugo.
7 * Migrated to DD4hep by Wagner Carvalho and Gabrielle Hugo.
8 *
9 ****************************************************************************/
10 
17 
21 
27 
32 
33 #include <regex>
34 
44 using RotationMatrix = ROOT::Math::Rotation3D;
45 using Translation = ROOT::Math::DisplacementVector3D<ROOT::Math::Cartesian3D<double>>;
46 
48 public:
50  ~CTPPSGeometryESModule() override {}
51 
52  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
53 
54 private:
55  std::unique_ptr<DetGeomDesc> produceIdealGD(const IdealGeometryRecord&);
56  std::vector<int> fillCopyNos(TGeoIterator& it);
57 
58  template <typename ALIGNMENT_REC>
59  struct GDTokens {
60  explicit GDTokens(edm::ESConsumesCollector&& iCC)
62  alignmentToken_{iCC.consumesFrom<CTPPSRPAlignmentCorrectionsData, ALIGNMENT_REC>(edm::ESInputTag())} {}
65  };
66 
67  std::unique_ptr<DetGeomDesc> produceRealGD(const VeryForwardRealGeometryRecord&);
68  std::unique_ptr<CTPPSGeometry> produceRealTG(const VeryForwardRealGeometryRecord&);
69 
70  std::unique_ptr<DetGeomDesc> produceMisalignedGD(const VeryForwardMisalignedGeometryRecord&);
71  std::unique_ptr<CTPPSGeometry> produceMisalignedTG(const VeryForwardMisalignedGeometryRecord&);
72 
73  template <typename REC>
74  std::unique_ptr<DetGeomDesc> produceGD(IdealGeometryRecord const&,
75  const std::optional<REC>&,
76  GDTokens<REC> const&,
77  const char* name);
78 
79  static std::unique_ptr<DetGeomDesc> applyAlignments(const DetGeomDesc&, const CTPPSRPAlignmentCorrectionsData*);
80 
81  const unsigned int verbosity_;
82 
85  const bool fromDD4hep_;
86 
89 
92 };
93 
95  : verbosity_(iConfig.getUntrackedParameter<unsigned int>("verbosity")),
96  fromDD4hep_(iConfig.getUntrackedParameter<bool>("fromDD4hep", false)),
98  gdMisTokens_{setWhatProduced(this, &CTPPSGeometryESModule::produceMisalignedGD)},
99  dgdRealToken_{
100  setWhatProduced(this, &CTPPSGeometryESModule::produceRealTG).consumes<DetGeomDesc>(edm::ESInputTag())},
101  dgdMisToken_{
102  setWhatProduced(this, &CTPPSGeometryESModule::produceMisalignedTG).consumes<DetGeomDesc>(edm::ESInputTag())} {
103  auto c = setWhatProduced(this, &CTPPSGeometryESModule::produceIdealGD);
104 
105  if (!fromDD4hep_) {
106  ddToken_ = c.consumes<DDCompactView>(edm::ESInputTag("", iConfig.getParameter<std::string>("compactViewTag")));
107  } else {
108  dd4hepToken_ =
109  c.consumes<cms::DDCompactView>(edm::ESInputTag("", iConfig.getParameter<std::string>("compactViewTag")));
110  }
111 }
112 
115  desc.addUntracked<unsigned int>("verbosity", 1);
116  desc.add<std::string>("compactViewTag", std::string());
117  desc.addUntracked<bool>("fromDD4hep", false);
118  descriptions.add("CTPPSGeometryESModule", desc);
119 }
120 
121 //----------------------------------------------------------------------------------------------------
122 /*
123  * Apply alignments by doing a BFS on idealGD tree.
124  */
125 std::unique_ptr<DetGeomDesc> CTPPSGeometryESModule::applyAlignments(const DetGeomDesc& idealDetRoot,
126  const CTPPSRPAlignmentCorrectionsData* alignments) {
127  std::deque<const DetGeomDesc*> bufferIdealGeo;
128  bufferIdealGeo.emplace_back(&idealDetRoot);
129 
130  std::deque<DetGeomDesc*> bufferAlignedGeo;
131  DetGeomDesc* alignedDetRoot = new DetGeomDesc(idealDetRoot, DetGeomDesc::cmWithoutChildren);
132  bufferAlignedGeo.emplace_back(alignedDetRoot);
133 
134  while (!bufferIdealGeo.empty()) {
135  const DetGeomDesc* idealDet = bufferIdealGeo.front();
136  DetGeomDesc* alignedDet = bufferAlignedGeo.front();
137  bufferIdealGeo.pop_front();
138  bufferAlignedGeo.pop_front();
139 
140  const std::string name = alignedDet->name();
141 
142  // Is it sensor? If yes, apply full sensor alignments
145  name == DDD_CTPPS_PIXELS_SENSOR_NAME_2x2 || std::regex_match(name, std::regex(DDD_TOTEM_TIMING_SENSOR_TMPL))) {
146  unsigned int plId = alignedDet->geographicalID();
147 
148  if (alignments) {
149  const auto& ac = alignments->getFullSensorCorrection(plId);
150  alignedDet->applyAlignment(ac);
151  }
152  }
153 
154  // Is it RP box? If yes, apply RP alignments
157  unsigned int rpId = alignedDet->geographicalID();
158 
159  if (alignments) {
160  const auto& ac = alignments->getRPCorrection(rpId);
161  alignedDet->applyAlignment(ac);
162  }
163  }
164 
165  // create and add children
166  const auto& idealDetChildren = idealDet->components();
167  for (unsigned int i = 0; i < idealDetChildren.size(); i++) {
168  const DetGeomDesc* idealDetChild = idealDetChildren[i];
169  bufferIdealGeo.emplace_back(idealDetChild);
170 
171  // create new node with the same information as in idealDetChild and add it as a child of alignedDet
172  DetGeomDesc* alignedDetChild = new DetGeomDesc(*idealDetChild, DetGeomDesc::cmWithoutChildren);
173  alignedDet->addComponent(alignedDetChild);
174 
175  bufferAlignedGeo.emplace_back(alignedDetChild);
176  }
177  }
178  return std::unique_ptr<DetGeomDesc>(alignedDetRoot);
179 }
180 
181 std::unique_ptr<DetGeomDesc> CTPPSGeometryESModule::produceIdealGD(const IdealGeometryRecord& iRecord) {
182  if (!fromDD4hep_) {
183  // Get the DDCompactView from EventSetup
184  auto const& myCompactView = iRecord.get(ddToken_);
185 
186  // Build geo from compact view.
188  }
189 
190  else {
191  // Get the DDCompactView from EventSetup
192  auto const& myCompactView = iRecord.get(dd4hepToken_);
193 
194  // Build geo from compact view.
196  }
197 }
198 
199 template <typename REC>
200 std::unique_ptr<DetGeomDesc> CTPPSGeometryESModule::produceGD(IdealGeometryRecord const& iIdealRec,
201  std::optional<REC> const& iAlignRec,
202  GDTokens<REC> const& iTokens,
203  const char* name) {
204  // get the input GeometricalDet
205  auto const& idealGD = iIdealRec.get(iTokens.idealGDToken_);
206 
207  // load alignments
208  CTPPSRPAlignmentCorrectionsData const* alignments = nullptr;
209  if (iAlignRec) {
210  auto alignmentsHandle = iAlignRec->getHandle(iTokens.alignmentToken_);
211  if (alignmentsHandle.isValid()) {
212  alignments = alignmentsHandle.product();
213  }
214  }
215 
216  if (verbosity_) {
217  if (alignments) {
218  edm::LogVerbatim(name) << ">> " << name << " > Real geometry: " << alignments->getRPMap().size() << " RP and "
219  << alignments->getSensorMap().size() << " sensor alignments applied.";
220  } else {
221  edm::LogVerbatim(name) << ">> " << name << " > Real geometry: No alignment applied.";
222  }
223  }
224 
225  return applyAlignments(idealGD, alignments);
226 }
227 
228 std::unique_ptr<DetGeomDesc> CTPPSGeometryESModule::produceRealGD(const VeryForwardRealGeometryRecord& iRecord) {
229  return produceGD(iRecord.getRecord<IdealGeometryRecord>(),
232  "CTPPSGeometryESModule::produceRealGD");
233 }
234 
235 //----------------------------------------------------------------------------------------------------
236 
237 std::unique_ptr<DetGeomDesc> CTPPSGeometryESModule::produceMisalignedGD(
238  const VeryForwardMisalignedGeometryRecord& iRecord) {
239  return produceGD(iRecord.getRecord<IdealGeometryRecord>(),
241  gdMisTokens_,
242  "CTPPSGeometryESModule::produceMisalignedGD");
243 }
244 
245 //----------------------------------------------------------------------------------------------------
246 
247 std::unique_ptr<CTPPSGeometry> CTPPSGeometryESModule::produceRealTG(const VeryForwardRealGeometryRecord& iRecord) {
248  auto const& gD = iRecord.get(dgdRealToken_);
249 
250  return std::make_unique<CTPPSGeometry>(&gD, verbosity_);
251 }
252 
253 //----------------------------------------------------------------------------------------------------
254 
255 std::unique_ptr<CTPPSGeometry> CTPPSGeometryESModule::produceMisalignedTG(
256  const VeryForwardMisalignedGeometryRecord& iRecord) {
257  auto const& gD = iRecord.get(dgdMisToken_);
258 
259  return std::make_unique<CTPPSGeometry>(&gD, verbosity_);
260 }
261 
edm::eventsetup::DependentRecordImplementation::getRecord
const DepRecordT getRecord() const
Definition: DependentRecordImplementation.h:50
CTPPSGeometryESModule::GDTokens::idealGDToken_
const edm::ESGetToken< DetGeomDesc, IdealGeometryRecord > idealGDToken_
Definition: CTPPSGeometryESModule.cc:62
CTPPSGeometryESModule::CTPPSGeometryESModule
CTPPSGeometryESModule(const edm::ParameterSet &)
Definition: CTPPSGeometryESModule.cc:93
VeryForwardRealGeometryRecord
Event setup record containing the real (actual) geometry information.
Definition: VeryForwardRealGeometryRecord.h:22
DetGeomDesc::applyAlignment
void applyAlignment(const CTPPSRPAlignmentCorrectionData &)
Definition: DetGeomDesc.cc:81
electrons_cff.bool
bool
Definition: electrons_cff.py:393
mps_fire.i
i
Definition: mps_fire.py:428
DDD_CTPPS_UFSD_SEGMENT_NAME
const std::string DDD_CTPPS_UFSD_SEGMENT_NAME
Definition: CTPPSDDDNames.h:18
edm::ESInputTag
Definition: ESInputTag.h:87
MessageLogger.h
DDD_CTPPS_PIXELS_SENSOR_NAME
const std::string DDD_CTPPS_PIXELS_SENSOR_NAME
Definition: CTPPSDDDNames.h:14
funct::false
false
Definition: Factorize.h:29
CTPPSRPAlignmentCorrectionsData::getRPMap
const mapType & getRPMap() const
returns the map of RP alignment corrections
Definition: CTPPSRPAlignmentCorrectionsData.h:46
CTPPSGeometryESModule::GDTokens::GDTokens
GDTokens(edm::ESConsumesCollector &&iCC)
Definition: CTPPSGeometryESModule.cc:59
DetGeomDesc::addComponent
void addComponent(DetGeomDesc *)
Definition: DetGeomDesc.cc:79
edm::ESConsumesCollector
Definition: ESConsumesCollector.h:61
ESHandle.h
CTPPSRPAlignmentCorrectionsData::getSensorMap
const mapType & getSensorMap() const
returns the map of sensor alignment corrections
Definition: CTPPSRPAlignmentCorrectionsData.h:49
edm::ESProducer::setWhatProduced
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:163
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
ESProducer.h
DDD_CTPPS_PIXELS_RP_NAME
const std::string DDD_CTPPS_PIXELS_RP_NAME
Definition: CTPPSDDDNames.h:23
CTPPSGeometryESModule::produceGD
std::unique_ptr< DetGeomDesc > produceGD(IdealGeometryRecord const &, const std::optional< REC > &, GDTokens< REC > const &, const char *name)
Definition: CTPPSGeometryESModule.cc:199
DDD_TOTEM_TIMING_RP_NAME
const std::string DDD_TOTEM_TIMING_RP_NAME
Definition: CTPPSDDDNames.h:26
CTPPSGeometryESModule::gdMisTokens_
const GDTokens< RPMisalignedAlignmentRecord > gdMisTokens_
Definition: CTPPSGeometryESModule.cc:87
year_2016_postTS2_cff.rpId
rpId
Definition: year_2016_postTS2_cff.py:23
RotationMatrix
ROOT::Math::Rotation3D RotationMatrix
Definition: PGeometricDetBuilder.cc:21
RPMisalignedAlignmentRecord
Definition: RPMisalignedAlignmentRecord.h:6
DDCompactView.h
VeryForwardMisalignedGeometryRecord.h
CTPPSGeometryESModule::produceRealGD
std::unique_ptr< DetGeomDesc > produceRealGD(const VeryForwardRealGeometryRecord &)
Definition: CTPPSGeometryESModule.cc:227
DDD_CTPPS_DIAMONDS_SEGMENT_NAME
const std::string DDD_CTPPS_DIAMONDS_SEGMENT_NAME
Definition: CTPPSDDDNames.h:17
CTPPSGeometryESModule::applyAlignments
static std::unique_ptr< DetGeomDesc > applyAlignments(const DetGeomDesc &, const CTPPSRPAlignmentCorrectionsData *)
Definition: CTPPSGeometryESModule.cc:124
RPMisalignedAlignmentRecord.h
CTPPSRPAlignmentCorrectionsData::getRPCorrection
CTPPSRPAlignmentCorrectionData & getRPCorrection(unsigned int id)
returns the correction value from the RP map
Definition: CTPPSRPAlignmentCorrectionsData.cc:17
CTPPSGeometryESModule
Definition: CTPPSGeometryESModule.cc:46
CTPPSGeometry.h
CTPPSGeometryESModule::ddToken_
edm::ESGetToken< DDCompactView, IdealGeometryRecord > ddToken_
Definition: CTPPSGeometryESModule.cc:82
RPRealAlignmentRecord
Definition: RPRealAlignmentRecord.h:6
DetGeomDesc::geographicalID
DetId geographicalID() const
Definition: DetGeomDesc.h:94
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
CTPPSGeometryESModule::dgdMisToken_
const edm::ESGetToken< DetGeomDesc, VeryForwardMisalignedGeometryRecord > dgdMisToken_
Definition: CTPPSGeometryESModule.cc:90
CTPPSGeometryESModule::GDTokens::alignmentToken_
const edm::ESGetToken< CTPPSRPAlignmentCorrectionsData, ALIGNMENT_REC > alignmentToken_
Definition: CTPPSGeometryESModule.cc:63
DDCompactView
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
CTPPSGeometryESModule::produceRealTG
std::unique_ptr< CTPPSGeometry > produceRealTG(const VeryForwardRealGeometryRecord &)
Definition: CTPPSGeometryESModule.cc:246
RPRealAlignmentRecord.h
DDD_CTPPS_PIXELS_SENSOR_NAME_2x2
const std::string DDD_CTPPS_PIXELS_SENSOR_NAME_2x2
Definition: CTPPSDDDNames.h:15
CTPPSGeometryESModule::fillCopyNos
std::vector< int > fillCopyNos(TGeoIterator &it)
DDCompactView.h
edm::eventsetup::DependentRecordImplementation::get
ProductT const & get(ESGetToken< ProductT, DepRecordT > const &iToken) const
Definition: DependentRecordImplementation.h:103
CTPPSGeometryESModule::gdRealTokens_
const GDTokens< RPRealAlignmentRecord > gdRealTokens_
Definition: CTPPSGeometryESModule.cc:86
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
CTPPSGeometryESModule::~CTPPSGeometryESModule
~CTPPSGeometryESModule() override
Definition: CTPPSGeometryESModule.cc:49
CTPPSGeometryESModule::produceIdealGD
std::unique_ptr< DetGeomDesc > produceIdealGD(const IdealGeometryRecord &)
Definition: CTPPSGeometryESModule.cc:180
CTPPSGeometryESModule::verbosity_
const unsigned int verbosity_
Definition: CTPPSGeometryESModule.cc:80
DetGeomDesc::cmWithoutChildren
Definition: DetGeomDesc.h:62
edm::ParameterSet
Definition: ParameterSet.h:47
DetGeomDesc::components
const Container & components() const
Definition: DetGeomDesc.h:97
DetGeomDesc.h
DDD_CTPPS_DIAMONDS_RP_NAME
const std::string DDD_CTPPS_DIAMONDS_RP_NAME
Definition: CTPPSDDDNames.h:25
CTPPSGeometryESModule::GDTokens
Definition: CTPPSGeometryESModule.cc:58
DetGeomDesc::name
const std::string & name() const
Definition: DetGeomDesc.h:66
CTPPSGeometryESModule::produceMisalignedGD
std::unique_ptr< DetGeomDesc > produceMisalignedGD(const VeryForwardMisalignedGeometryRecord &)
Definition: CTPPSGeometryESModule.cc:236
DetGeomDescBuilder.h
createfilelist.int
int
Definition: createfilelist.py:10
DDD_TOTEM_TIMING_SENSOR_TMPL
const std::string DDD_TOTEM_TIMING_SENSOR_TMPL
Definition: CTPPSDDDNames.h:19
DetGeomDesc
Definition: DetGeomDesc.h:49
DDD_TOTEM_RP_RP_NAME
const std::string DDD_TOTEM_RP_RP_NAME
DDD names of RP volumes.
Definition: CTPPSDDDNames.h:22
Translation
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > Translation
Definition: PGeometricDetBuilder.cc:20
IdealGeometryRecord.h
CTPPSDDDNames.h
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
VeryForwardRealGeometryRecord.h
edm::ESGetToken< DetGeomDesc, IdealGeometryRecord >
CTPPSGeometryESModule::fromDD4hep_
const bool fromDD4hep_
Definition: CTPPSGeometryESModule.cc:84
VeryForwardMisalignedGeometryRecord
Event setup record containing the misaligned geometry information. It is used for alignment studies o...
Definition: VeryForwardMisalignedGeometryRecord.h:23
detgeomdescbuilder::buildDetGeomDescFromCompactView
std::unique_ptr< DetGeomDesc > buildDetGeomDescFromCompactView(const DDCompactView &myCompactView)
Definition: DetGeomDescBuilder.cc:9
ModuleFactory.h
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
CTPPSGeometryESModule::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: CTPPSGeometryESModule.cc:112
edm::eventsetup::DependentRecordImplementation::tryToGetRecord
std::optional< DepRecordT > tryToGetRecord() const
Definition: DependentRecordImplementation.h:68
DEFINE_FWK_EVENTSETUP_MODULE
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
CTPPSGeometryESModule::dgdRealToken_
const edm::ESGetToken< DetGeomDesc, VeryForwardRealGeometryRecord > dgdRealToken_
Definition: CTPPSGeometryESModule.cc:89
cms::DDCompactView
Definition: DDCompactView.h:31
DDD_TOTEM_RP_SENSOR_NAME
const std::string DDD_TOTEM_RP_SENSOR_NAME
DDD names of sensors.
Definition: CTPPSDDDNames.h:13
CTPPSRPAlignmentCorrectionsData
Container for CTPPS RP alignment corrections. The corrections are stored on two levels - RP and senso...
Definition: CTPPSRPAlignmentCorrectionsData.h:24
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
EventSetup.h
CTPPSRPAlignmentCorrectionsData.h
edm::ESProducer
Definition: ESProducer.h:104
CTPPSRPAlignmentCorrectionsData::getFullSensorCorrection
CTPPSRPAlignmentCorrectionData getFullSensorCorrection(unsigned int id, bool useRPErrors=false) const
Definition: CTPPSRPAlignmentCorrectionsData.cc:47
ParameterSet.h
IdealGeometryRecord
Definition: IdealGeometryRecord.h:25
CTPPSGeometryESModule::produceMisalignedTG
std::unique_ptr< CTPPSGeometry > produceMisalignedTG(const VeryForwardMisalignedGeometryRecord &)
Definition: CTPPSGeometryESModule.cc:254
CTPPSGeometryESModule::dd4hepToken_
edm::ESGetToken< cms::DDCompactView, IdealGeometryRecord > dd4hepToken_
Definition: CTPPSGeometryESModule.cc:83