CMS 3D CMS Logo

CTPPSGeometryESModule.cc
Go to the documentation of this file.
1 /****************************************************************************
2 *
3 * Authors:
4 * Jan Kaspar (jan.kaspar@gmail.com)
5 * Dominik Mierzejewski <dmierzej@cern.ch>
6 *
7 ****************************************************************************/
8 
14 
21 
23 
28 
30 //#include "CondFormats/AlignmentRecord/interface/CTPPSRPAlignmentCorrectionsDataRcd.h"
31 
33 
37 
41 
42 #include <regex>
43 
53 {
54  public:
56  ~CTPPSGeometryESModule() override {}
57 
58  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
59 
60  private:
61  std::unique_ptr<DetGeomDesc> produceIdealGD( const IdealGeometryRecord& );
62 
63  template<typename ALIGNMENT_REC> struct GDTokens {
66  alignmentToken_{iCC.consumesFrom<CTPPSRPAlignmentCorrectionsData, ALIGNMENT_REC>(edm::ESInputTag())}
67  {}
70  };
71 
72  std::unique_ptr<DetGeomDesc> produceRealGD( const VeryForwardRealGeometryRecord& );
73  std::unique_ptr<CTPPSGeometry> produceRealTG( const VeryForwardRealGeometryRecord& );
74 
75  std::unique_ptr<DetGeomDesc> produceMisalignedGD( const VeryForwardMisalignedGeometryRecord& );
76  std::unique_ptr<CTPPSGeometry> produceMisalignedTG( const VeryForwardMisalignedGeometryRecord& );
77 
78  template<typename REC>
79  std::unique_ptr<DetGeomDesc> produceGD( IdealGeometryRecord const&, const std::optional<REC>&, GDTokens<REC> const&, const char* name);
80 
81 
83  static void buildDetGeomDesc( DDFilteredView* fv, DetGeomDesc* gd );
84 
85  const unsigned int verbosity_;
87 
90 
93 
94 };
95 
96 
97 //----------------------------------------------------------------------------------------------------
98 //----------------------------------------------------------------------------------------------------
99 
101  verbosity_( iConfig.getUntrackedParameter<unsigned int>( "verbosity") ),
103  .consumes<DDCompactView>(edm::ESInputTag(""/*optional module label */,
104  iConfig.getParameter<std::string>( "compactViewTag" ) )) },
109 {
110 }
111 
112 void
115  desc.addUntracked<unsigned int>("verbosity", 1);
116  desc.add<std::string>("compactViewTag", std::string());
117  descriptions.add("DoodadESSource", desc);
118 }
119 
120 
121 //----------------------------------------------------------------------------------------------------
122 
123 void
125  const CTPPSRPAlignmentCorrectionsData* alignments,
126  DetGeomDesc*& newGD )
127 {
128  newGD = new DetGeomDesc( idealGD );
129  std::deque<const DetGeomDesc*> buffer;
130  std::deque<DetGeomDesc*> bufferNew;
131  buffer.emplace_back( &idealGD );
132  bufferNew.emplace_back( newGD );
133 
134  while ( !buffer.empty() ) {
135  const DetGeomDesc* sD = buffer.front();
136  DetGeomDesc* pD = bufferNew.front();
137  buffer.pop_front();
138  bufferNew.pop_front();
139 
140  const std::string name = pD->name();
141 
142  // Is it sensor? If yes, apply full sensor alignments
143  if ( name == DDD_TOTEM_RP_SENSOR_NAME
145  || name == DDD_CTPPS_UFSD_SEGMENT_NAME
147  || std::regex_match( name, std::regex( DDD_TOTEM_TIMING_SENSOR_TMPL ) )) {
148  unsigned int plId = pD->geographicalID();
149 
150  if ( alignments ) {
151  const auto& ac = alignments->getFullSensorCorrection( plId );
152  pD->applyAlignment( ac );
153  }
154  }
155 
156  // Is it RP box? If yes, apply RP alignments
157  if ( name == DDD_TOTEM_RP_RP_NAME
158  || name == DDD_CTPPS_DIAMONDS_RP_NAME
159  || name == DDD_CTPPS_PIXELS_RP_NAME
160  || name == DDD_TOTEM_TIMING_RP_NAME ) {
161  unsigned int rpId = pD->geographicalID();
162 
163  if ( alignments ) {
164  const auto& ac = alignments->getRPCorrection( rpId );
165  pD->applyAlignment( ac );
166  }
167  }
168 
169  // create and add children
170  for ( unsigned int i = 0; i < sD->components().size(); i++ ) {
171  const DetGeomDesc* sDC = sD->components()[i];
172  buffer.emplace_back( sDC );
173 
174  // create new node with the same information as in sDC and add it as a child of pD
175  DetGeomDesc* cD = new DetGeomDesc( *sDC );
176  pD->addComponent( cD );
177 
178  bufferNew.emplace_back( cD );
179  }
180  }
181 }
182 
183 //----------------------------------------------------------------------------------------------------
184 
185 void
187 {
188  // try to dive into next level
189  if ( !fv->firstChild() ) return;
190 
191  // loop over siblings in the level
192  do {
193  // create new DetGeomDesc node and add it to the parent's (gd) list
194  DetGeomDesc* newGD = new DetGeomDesc( fv );
195 
196  const std::string name = fv->logicalPart().name().name();
197 
198  // strip sensors
199  if ( name == DDD_TOTEM_RP_SENSOR_NAME ) {
200  const std::vector<int>& copy_num = fv->copyNumbers();
201  // check size of copy numubers array
202  if ( copy_num.size() < 3 )
203  throw cms::Exception("DDDTotemRPContruction") << "size of copyNumbers for strip sensor is "
204  << copy_num.size() << ". It must be >= 3.";
205 
206  // extract information
207  const unsigned int decRPId = copy_num[copy_num.size() - 3];
208  const unsigned int arm = decRPId / 100;
209  const unsigned int station = ( decRPId % 100 ) / 10;
210  const unsigned int rp = decRPId % 10;
211  const unsigned int detector = copy_num[copy_num.size() - 1];
212  newGD->setGeographicalID( TotemRPDetId( arm, station, rp, detector ) );
213  }
214 
215  // strip and pixels RPs
216  else if ( name == DDD_TOTEM_RP_RP_NAME || name == DDD_CTPPS_PIXELS_RP_NAME ) {
217  unsigned int decRPId = fv->copyno();
218 
219  // check if it is a pixel RP
220  if ( decRPId >= 10000 ){
221  decRPId = decRPId % 10000;
222  const unsigned int armIdx = ( decRPId / 100 ) % 10;
223  const unsigned int stIdx = ( decRPId / 10 ) % 10;
224  const unsigned int rpIdx = decRPId % 10;
225  newGD->setGeographicalID( CTPPSPixelDetId( armIdx, stIdx, rpIdx ) );
226  }
227  else {
228  const unsigned int armIdx = ( decRPId / 100 ) % 10;
229  const unsigned int stIdx = ( decRPId / 10 ) % 10;
230  const unsigned int rpIdx = decRPId % 10;
231  newGD->setGeographicalID( TotemRPDetId( armIdx, stIdx, rpIdx ) );
232  }
233  }
234 
235  else if ( std::regex_match( name, std::regex( DDD_TOTEM_TIMING_SENSOR_TMPL ) ) ) {
236  const std::vector<int>& copy_num = fv->copyNumbers();
237  // check size of copy numbers array
238  if ( copy_num.size() < 4 )
239  throw cms::Exception("DDDTotemRPContruction") << "size of copyNumbers for TOTEM timing sensor is "
240  << copy_num.size() << ". It must be >= 4.";
241 
242  const unsigned int decRPId = copy_num[copy_num.size()-4];
243  const unsigned int arm = decRPId / 100, station = ( decRPId % 100 )/10, rp = decRPId % 10;
244  const unsigned int plane = copy_num[copy_num.size()-2], channel = copy_num[copy_num.size()-1];
245  newGD->setGeographicalID( TotemTimingDetId( arm, station, rp, plane, channel ) );
246  }
247 
248  else if ( name == DDD_TOTEM_TIMING_RP_NAME ) {
249  const unsigned int arm = fv->copyno() / 100, station = ( fv->copyno() % 100 )/10, rp = fv->copyno() % 10;
250  newGD->setGeographicalID( TotemTimingDetId( arm, station, rp ) );
251  }
252 
253  // pixel sensors
254  else if ( name == DDD_CTPPS_PIXELS_SENSOR_NAME ) {
255  const std::vector<int>& copy_num = fv->copyNumbers();
256  // check size of copy numubers array
257  if ( copy_num.size() < 4 )
258  throw cms::Exception("DDDTotemRPContruction") << "size of copyNumbers for pixel sensor is "
259  << copy_num.size() << ". It must be >= 4.";
260 
261  // extract information
262  const unsigned int decRPId = copy_num[copy_num.size() - 4] % 10000;
263  const unsigned int arm = decRPId / 100;
264  const unsigned int station = ( decRPId % 100 ) / 10;
265  const unsigned int rp = decRPId % 10;
266  const unsigned int detector = copy_num[copy_num.size() - 2] - 1;
267  newGD->setGeographicalID( CTPPSPixelDetId( arm, station, rp, detector ) );
268  }
269 
270  // diamond/UFSD sensors
271  else if ( name == DDD_CTPPS_DIAMONDS_SEGMENT_NAME || name == DDD_CTPPS_UFSD_SEGMENT_NAME ) {
272  const std::vector<int>& copy_num = fv->copyNumbers();
273 
274  const unsigned int id = copy_num[copy_num.size()-1];
275  const unsigned int arm = copy_num[1]-1;
276  const unsigned int station = 1;
277  const unsigned int rp = 6;
278  const unsigned int plane = ( id / 100 );
279  const unsigned int channel = id % 100;
280 
281  newGD->setGeographicalID( CTPPSDiamondDetId( arm, station, rp, plane, channel ) );
282  }
283 
284  // diamond/UFSD RPs
285  else if ( name == DDD_CTPPS_DIAMONDS_RP_NAME ) {
286  const std::vector<int>& copy_num = fv->copyNumbers();
287 
288  // check size of copy numubers array
289  if ( copy_num.size() < 2 )
290  throw cms::Exception("DDDTotemRPContruction") << "size of copyNumbers for diamond RP is "
291  << copy_num.size() << ". It must be >= 2.";
292 
293  const unsigned int arm = copy_num[1] - 1;
294  const unsigned int station = 1;
295  const unsigned int rp = 6;
296 
297  newGD->setGeographicalID( CTPPSDiamondDetId( arm, station, rp ) );
298  }
299 
300  // add component
301  gd->addComponent( newGD );
302 
303  // recursion
304  buildDetGeomDesc( fv, newGD );
305  } while ( fv->nextSibling() );
306 
307  // go a level up
308  fv->parent();
309 }
310 
311 //----------------------------------------------------------------------------------------------------
312 
313 std::unique_ptr<DetGeomDesc>
315 {
316  // get the DDCompactView from EventSetup
317  auto const& cpv = iRecord.get( compactViewToken_);
318 
319  // create DDFilteredView and apply the filter
321  DDFilteredView fv( cpv, filter );
322 
323  // conversion to DetGeomDesc structure
324  auto root = std::make_unique<DetGeomDesc>( &fv );
325  buildDetGeomDesc( &fv, root.get() );
326 
327  // construct the tree of DetGeomDesc
328  return root;
329 }
330 
331 //----------------------------------------------------------------------------------------------------
332 
333 template<typename REC>
334 std::unique_ptr<DetGeomDesc>
336  std::optional<REC> const& iAlignRec,
337  GDTokens<REC> const& iTokens,
338  const char* name) {
339  // get the input GeometricalDet
340  auto const& idealGD = iIdealRec.get( iTokens.idealGDToken_ );
341 
342  // load alignments
344  if(iAlignRec) {
345  alignments = iAlignRec->getHandle(iTokens.alignmentToken_);
346  }
347 
348  if ( alignments.isValid() ) {
349  if ( verbosity_ )
350  edm::LogVerbatim(name)
351  << ">> "<<name<<" > Real geometry: "
352  << alignments->getRPMap().size() << " RP and "
353  << alignments->getSensorMap().size() << " sensor alignments applied.";
354  }
355  else {
356  if ( verbosity_ )
357  edm::LogVerbatim(name)
358  << ">> "<<name<< " > Real geometry: No alignments applied.";
359  }
360 
361  DetGeomDesc* newGD = nullptr;
362  applyAlignments( idealGD, alignments.product(), newGD );
363  return std::unique_ptr<DetGeomDesc>( newGD );
364 }
365 
366 std::unique_ptr<DetGeomDesc>
368 {
370  "CTPPSGeometryESModule::produceRealGD");
371 }
372 
373 //----------------------------------------------------------------------------------------------------
374 
375 std::unique_ptr<DetGeomDesc>
377 {
379  "CTPPSGeometryESModule::produceMisalignedGD");
380 }
381 
382 //----------------------------------------------------------------------------------------------------
383 
384 std::unique_ptr<CTPPSGeometry>
386 {
387  auto const& gD = iRecord.get( dgdRealToken_ );
388 
389  return std::make_unique<CTPPSGeometry>( &gD );
390 }
391 
392 //----------------------------------------------------------------------------------------------------
393 
394 std::unique_ptr<CTPPSGeometry>
396 {
397  auto const& gD = iRecord.get( dgdMisToken_ );
398 
399  return std::make_unique<CTPPSGeometry>( &gD );
400 }
401 
Detector ID class for TOTEM Si strip detectors.
Definition: TotemRPDetId.h:30
T getParameter(std::string const &) const
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:124
bool parent()
set the current node to the parent node ...
GDTokens(edm::ESConsumesCollector &&iCC)
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the filtered-view.
const std::string DDD_CTPPS_PIXELS_RP_NAME
Definition: CTPPSDDDNames.h:22
CTPPSRPAlignmentCorrectionData & getRPCorrection(unsigned int id)
returns the correction value from the RP map
const N & name() const
Definition: DDBase.h:74
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
DetId geographicalID() const
Definition: DetGeomDesc.h:54
nav_type copyNumbers() const
return the stack of copy numbers
bool nextSibling()
set the current node to the next sibling ...
void applyAlignment(const CTPPSRPAlignmentCorrectionData &)
alignment
Definition: DetGeomDesc.cc:94
std::unique_ptr< CTPPSGeometry > produceRealTG(const VeryForwardRealGeometryRecord &)
Builds ideal, real and misaligned geometries.
const std::string DDD_TOTEM_TIMING_RP_NAME
Definition: CTPPSDDDNames.h:24
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:80
Event setup record containing the real (actual) geometry information.
const std::string DDD_CTPPS_DIAMONDS_SEGMENT_NAME
Definition: CTPPSDDDNames.h:16
int copyno() const
Copy number associated with the current node.
const edm::ESGetToken< DetGeomDesc, IdealGeometryRecord > idealGDToken_
static void applyAlignments(const DetGeomDesc &, const CTPPSRPAlignmentCorrectionsData *, DetGeomDesc *&)
ProductT const & get(ESGetToken< ProductT, DepRecordT > const &iToken) const
const edm::ESGetToken< CTPPSRPAlignmentCorrectionsData, ALIGNMENT_REC > alignmentToken_
std::unique_ptr< CTPPSGeometry > produceMisalignedTG(const VeryForwardMisalignedGeometryRecord &)
void setGeographicalID(DetId id)
ID stuff.
Definition: DetGeomDesc.h:53
std::unique_ptr< DetGeomDesc > produceGD(IdealGeometryRecord const &, const std::optional< REC > &, GDTokens< REC > const &, const char *name)
Geometrical description of a sensor.
Definition: DetGeomDesc.h:35
const GDTokens< RPMisalignedAlignmentRecord > gdMisTokens_
const mapType & getRPMap() const
returns the map of RP alignment corrections
Container components() const
access to the tree structure
Definition: DetGeomDesc.cc:62
const std::string DDD_TOTEM_TIMING_SENSOR_TMPL
Definition: CTPPSDDDNames.h:18
ParameterDescriptionBase * add(U const &iLabel, T const &value)
std::unique_ptr< DetGeomDesc > produceRealGD(const VeryForwardRealGeometryRecord &)
CTPPSRPAlignmentCorrectionData getFullSensorCorrection(unsigned int id, bool useRPErrors=false) const
A DDFilter that always returns true.
Definition: DDFilter.h:27
const mapType & getSensorMap() const
returns the map of sensor alignment corrections
const edm::ESGetToken< DetGeomDesc, VeryForwardMisalignedGeometryRecord > dgdMisToken_
const std::string & name() const
Definition: DetGeomDesc.h:67
const edm::ESGetToken< DDCompactView, IdealGeometryRecord > compactViewToken_
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const std::string DDD_TOTEM_RP_RP_NAME
DDD names of RP volumes.
Definition: CTPPSDDDNames.h:21
const std::string DDD_CTPPS_DIAMONDS_RP_NAME
Definition: CTPPSDDDNames.h:23
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::unique_ptr< DetGeomDesc > produceMisalignedGD(const VeryForwardMisalignedGeometryRecord &)
Container for CTPPS RP alignment corrections. The corrections are stored on two levels - RP and senso...
CTPPSGeometryESModule(const edm::ParameterSet &)
const edm::ESGetToken< DetGeomDesc, VeryForwardRealGeometryRecord > dgdRealToken_
Event setup record containing the misaligned geometry information. It is used for alignment studies o...
static void buildDetGeomDesc(DDFilteredView *fv, DetGeomDesc *gd)
bool firstChild()
set the current node to the first child ...
Detector ID class for CTPPS Timing Diamond detectors. Bits [19:31] : Assigend in CTPPSDetId Calss Bit...
std::unique_ptr< DetGeomDesc > produceIdealGD(const IdealGeometryRecord &)
const std::string DDD_TOTEM_RP_SENSOR_NAME
DDD names of sensors.
Definition: CTPPSDDDNames.h:14
const GDTokens< RPRealAlignmentRecord > gdRealTokens_
bool isValid() const
Definition: ESHandle.h:44
const unsigned int verbosity_
const std::string DDD_CTPPS_PIXELS_SENSOR_NAME
Definition: CTPPSDDDNames.h:15
T const * product() const
Definition: ESHandle.h:86
void addComponent(DetGeomDesc *)
components (children) management
Definition: DetGeomDesc.cc:69
const std::string & name() const
Returns the name.
Definition: DDName.cc:53
const std::string DDD_CTPPS_UFSD_SEGMENT_NAME
Definition: CTPPSDDDNames.h:17
Detector ID class for CTPPS Totem Timing detectors. Bits [19:31] : Assigend in CTPPSDetId Calss Bits ...