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 
31 
35 
39 
40 #include <regex>
41 
51 {
52  public:
54  ~CTPPSGeometryESModule() override {}
55 
56  std::unique_ptr<DetGeomDesc> produceIdealGD( const IdealGeometryRecord& );
57 
58  std::unique_ptr<DetGeomDesc> produceRealGD( const VeryForwardRealGeometryRecord& );
59  std::unique_ptr<CTPPSGeometry> produceRealTG( const VeryForwardRealGeometryRecord& );
60 
61  std::unique_ptr<DetGeomDesc> produceMisalignedGD( const VeryForwardMisalignedGeometryRecord& );
62  std::unique_ptr<CTPPSGeometry> produceMisalignedTG( const VeryForwardMisalignedGeometryRecord& );
63 
64  protected:
66  static void buildDetGeomDesc( DDFilteredView* fv, DetGeomDesc* gd );
67 
68  unsigned int verbosity_;
70 };
71 
72 
73 //----------------------------------------------------------------------------------------------------
74 //----------------------------------------------------------------------------------------------------
75 
77  verbosity_( iConfig.getUntrackedParameter<unsigned int>( "verbosity", 1 ) ),
78  compactViewTag_( iConfig.getParameter<std::string>( "compactViewTag" ) )
79 {
81 
84 
87 }
88 
89 //----------------------------------------------------------------------------------------------------
90 
91 void
94  DetGeomDesc*& newGD )
95 {
96  newGD = new DetGeomDesc( *(idealGD.product()) );
97  std::deque<const DetGeomDesc*> buffer;
98  std::deque<DetGeomDesc*> bufferNew;
99  buffer.emplace_back( idealGD.product() );
100  bufferNew.emplace_back( newGD );
101 
102  while ( !buffer.empty() ) {
103  const DetGeomDesc* sD = buffer.front();
104  DetGeomDesc* pD = bufferNew.front();
105  buffer.pop_front();
106  bufferNew.pop_front();
107 
108  const std::string name = pD->name().name();
109 
110  // Is it sensor? If yes, apply full sensor alignments
111  if ( name == DDD_TOTEM_RP_SENSOR_NAME
113  || name == DDD_CTPPS_UFSD_SEGMENT_NAME
114  || name == DDD_CTPPS_PIXELS_SENSOR_NAME ) {
115  unsigned int plId = pD->geographicalID();
116 
117  if ( alignments.isValid() ) {
118  const RPAlignmentCorrectionData& ac = alignments->getFullSensorCorrection( plId );
119  pD->ApplyAlignment( ac );
120  }
121  }
122 
123  // Is it RP box? If yes, apply RP alignments
124  if ( name == DDD_TOTEM_RP_RP_NAME
125  || name == DDD_CTPPS_DIAMONDS_RP_NAME
126  || name == DDD_CTPPS_PIXELS_RP_NAME ) {
127  unsigned int rpId = pD->geographicalID();
128 
129  if ( alignments.isValid() ) {
130  const RPAlignmentCorrectionData& ac = alignments->getRPCorrection( rpId );
131  pD->ApplyAlignment( ac );
132  }
133  }
134 
135  // create and add children
136  for ( unsigned int i = 0; i < sD->components().size(); i++ ) {
137  const DetGeomDesc* sDC = sD->components()[i];
138  buffer.emplace_back( sDC );
139 
140  // create new node with the same information as in sDC and add it as a child of pD
141  DetGeomDesc* cD = new DetGeomDesc( *sDC );
142  pD->addComponent( cD );
143 
144  bufferNew.emplace_back( cD );
145  }
146  }
147 }
148 
149 //----------------------------------------------------------------------------------------------------
150 
151 void
153 {
154  // try to dive into next level
155  if ( !fv->firstChild() ) return;
156 
157  // loop over siblings in the level
158  do {
159  // create new DetGeomDesc node and add it to the parent's (gd) list
160  DetGeomDesc* newGD = new DetGeomDesc( fv );
161 
162  const std::string name = fv->logicalPart().name().name();
163 
164  // strip sensors
165  if ( name == DDD_TOTEM_RP_SENSOR_NAME ) {
166  const std::vector<int>& copy_num = fv->copyNumbers();
167  // check size of copy numubers array
168  if ( copy_num.size() < 3 )
169  throw cms::Exception("DDDTotemRPContruction") << "size of copyNumbers for strip sensor is "
170  << copy_num.size() << ". It must be >= 3.";
171 
172  // extract information
173  const unsigned int decRPId = copy_num[copy_num.size() - 3];
174  const unsigned int arm = decRPId / 100;
175  const unsigned int station = ( decRPId % 100 ) / 10;
176  const unsigned int rp = decRPId % 10;
177  const unsigned int detector = copy_num[copy_num.size() - 1];
178  newGD->setGeographicalID( TotemRPDetId( arm, station, rp, detector ) );
179  }
180 
181  // strip and pixels RPs
182  else if ( name == DDD_TOTEM_RP_RP_NAME || name == DDD_CTPPS_PIXELS_RP_NAME ) {
183  unsigned int decRPId = fv->copyno();
184 
185  // check if it is a pixel RP
186  if ( decRPId >= 10000 ){
187  decRPId = decRPId % 10000;
188  const unsigned int armIdx = ( decRPId / 100 ) % 10;
189  const unsigned int stIdx = ( decRPId / 10 ) % 10;
190  const unsigned int rpIdx = decRPId % 10;
191  newGD->setGeographicalID( CTPPSPixelDetId( armIdx, stIdx, rpIdx ) );
192  }
193  else {
194  const unsigned int armIdx = ( decRPId / 100 ) % 10;
195  const unsigned int stIdx = ( decRPId / 10 ) % 10;
196  const unsigned int rpIdx = decRPId % 10;
197  newGD->setGeographicalID( TotemRPDetId( armIdx, stIdx, rpIdx ) );
198  }
199  }
200 
201  else if ( std::regex_match( name, std::regex( DDD_TOTEM_TIMING_SENSOR_TMPL ) ) ) {
202  const std::vector<int>& copy_num = fv->copyNumbers();
203  // check size of copy numbers array
204  if ( copy_num.size() < 4 )
205  throw cms::Exception("DDDTotemRPContruction") << "size of copyNumbers for TOTEM timing sensor is "
206  << copy_num.size() << ". It must be >= 4.";
207 
208  const unsigned int decRPId = copy_num[copy_num.size()-4];
209  const unsigned int arm = decRPId / 100, station = ( decRPId % 100 )/10, rp = decRPId % 10;
210  const unsigned int plane = copy_num[copy_num.size()-2], channel = copy_num[copy_num.size()-1];
211  newGD->setGeographicalID( TotemTimingDetId( arm, station, rp, plane, channel ) );
212  }
213 
214  else if ( name == DDD_TOTEM_TIMING_RP_NAME ) {
215  const unsigned int arm = fv->copyno() / 100, station = ( fv->copyno() % 100 )/10, rp = fv->copyno() % 10;
216  newGD->setGeographicalID( TotemTimingDetId( arm, station, rp ) );
217  }
218 
219  // pixel sensors
220  else if ( name == DDD_CTPPS_PIXELS_SENSOR_NAME ) {
221  const std::vector<int>& copy_num = fv->copyNumbers();
222  // check size of copy numubers array
223  if ( copy_num.size() < 4 )
224  throw cms::Exception("DDDTotemRPContruction") << "size of copyNumbers for pixel sensor is "
225  << copy_num.size() << ". It must be >= 4.";
226 
227  // extract information
228  const unsigned int decRPId = copy_num[copy_num.size() - 4] % 10000;
229  const unsigned int arm = decRPId / 100;
230  const unsigned int station = ( decRPId % 100 ) / 10;
231  const unsigned int rp = decRPId % 10;
232  const unsigned int detector = copy_num[copy_num.size() - 2] - 1;
233  newGD->setGeographicalID( CTPPSPixelDetId( arm, station, rp, detector ) );
234  }
235 
236  // diamond/UFSD sensors
237  else if ( name == DDD_CTPPS_DIAMONDS_SEGMENT_NAME || name == DDD_CTPPS_UFSD_SEGMENT_NAME ) {
238  const std::vector<int>& copy_num = fv->copyNumbers();
239 
240  const unsigned int id = copy_num[copy_num.size()-1];
241  const unsigned int arm = copy_num[1]-1;
242  const unsigned int station = 1;
243  const unsigned int rp = 6;
244  const unsigned int plane = ( id / 100 );
245  const unsigned int channel = id % 100;
246 
247  newGD->setGeographicalID( CTPPSDiamondDetId( arm, station, rp, plane, channel ) );
248  }
249 
250  // diamond/UFSD RPs
251  else if ( name == DDD_CTPPS_DIAMONDS_RP_NAME ) {
252  const std::vector<int>& copy_num = fv->copyNumbers();
253 
254  // check size of copy numubers array
255  if ( copy_num.size() < 2 )
256  throw cms::Exception("DDDTotemRPContruction") << "size of copyNumbers for diamond RP is "
257  << copy_num.size() << ". It must be >= 2.";
258 
259  const unsigned int arm = copy_num[1] - 1;
260  const unsigned int station = 1;
261  const unsigned int rp = 6;
262 
263  newGD->setGeographicalID( CTPPSDiamondDetId( arm, station, rp ) );
264  }
265 
266  // add component
267  gd->addComponent( newGD );
268 
269  // recursion
270  buildDetGeomDesc( fv, newGD );
271  } while ( fv->nextSibling() );
272 
273  // go a level up
274  fv->parent();
275 }
276 
277 //----------------------------------------------------------------------------------------------------
278 
279 std::unique_ptr<DetGeomDesc>
281 {
282  // get the DDCompactView from EventSetup
284  iRecord.get( compactViewTag_, cpv );
285 
286  // create DDFilteredView and apply the filter
288  DDFilteredView fv( *( cpv.product() ), filter );
289 
290  // conversion to DetGeomDesc structure
291  DetGeomDesc* root = new DetGeomDesc( &fv );
292  buildDetGeomDesc( &fv, root );
293 
294  // construct the tree of DetGeomDesc
295  return std::unique_ptr<DetGeomDesc>( const_cast<DetGeomDesc*>( root ) );
296 }
297 
298 //----------------------------------------------------------------------------------------------------
299 
300 std::unique_ptr<DetGeomDesc>
302 {
303  // get the input GeometricalDet
305  iRecord.getRecord<IdealGeometryRecord>().get( idealGD );
306 
307  // load alignments
309  try { iRecord.getRecord<RPRealAlignmentRecord>().get( alignments ); }
310  catch ( cms::Exception& ) {}
311 
312  if ( alignments.isValid() ) {
313  if ( verbosity_ )
314  edm::LogVerbatim("CTPPSGeometryESModule::produceRealGD")
315  << ">> CTPPSGeometryESModule::produceRealGD > Real geometry: "
316  << alignments->getRPMap().size() << " RP and "
317  << alignments->getSensorMap().size() << " sensor alignments applied.";
318  }
319  else {
320  if ( verbosity_ )
321  edm::LogVerbatim("CTPPSGeometryESModule::produceRealGD")
322  << ">> CTPPSGeometryESModule::produceRealGD > Real geometry: No alignments applied.";
323  }
324 
325  DetGeomDesc* newGD = nullptr;
326  applyAlignments( idealGD, alignments, newGD );
327  return std::unique_ptr<DetGeomDesc>( newGD );
328 }
329 
330 //----------------------------------------------------------------------------------------------------
331 
332 std::unique_ptr<DetGeomDesc>
334 {
335  // get the input GeometricalDet
337  iRecord.getRecord<IdealGeometryRecord>().get( idealGD );
338 
339  // load alignments
341  try { iRecord.getRecord<RPMisalignedAlignmentRecord>().get( alignments ); }
342  catch ( cms::Exception& ) {}
343 
344  if ( alignments.isValid() ) {
345  if ( verbosity_ )
346  edm::LogVerbatim("CTPPSGeometryESModule::produceMisalignedGD")
347  << ">> CTPPSGeometryESModule::produceMisalignedGD > Misaligned geometry: "
348  << alignments->getRPMap().size() << " RP and "
349  << alignments->getSensorMap().size() << " sensor alignments applied.";
350  } else {
351  if ( verbosity_ )
352  edm::LogVerbatim("CTPPSGeometryESModule::produceMisalignedGD")
353  << ">> CTPPSGeometryESModule::produceMisalignedGD > Misaligned geometry: No alignments applied.";
354  }
355 
356  DetGeomDesc* newGD = nullptr;
357  applyAlignments( idealGD, alignments, newGD );
358  return std::unique_ptr<DetGeomDesc>( newGD );
359 }
360 
361 //----------------------------------------------------------------------------------------------------
362 
363 std::unique_ptr<CTPPSGeometry>
365 {
367  iRecord.get( gD );
368 
369  return std::make_unique<CTPPSGeometry>( gD.product() );
370 }
371 
372 //----------------------------------------------------------------------------------------------------
373 
374 std::unique_ptr<CTPPSGeometry>
376 {
378  iRecord.get( gD );
379 
380  return std::make_unique<CTPPSGeometry>( gD.product() );
381 }
382 
Detector ID class for TOTEM Si strip detectors.
Definition: TotemRPDetId.h:30
bool parent()
set the current node to the parent node ...
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
const N & name() const
Definition: DDBase.h:78
nav_type copyNumbers() const
return the stack of copy numbers
bool nextSibling()
set the current node to the next sibling ...
static void applyAlignments(const edm::ESHandle< DetGeomDesc > &, const edm::ESHandle< RPAlignmentCorrectionsData > &, DetGeomDesc *&)
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
const mapType & getRPMap() const
returns the map of RP alignment corrections
Event setup record containing the real (actual) geometry information.
void setWhatProduced(T *iThis, const es::Label &iLabel=es::Label())
Definition: ESProducer.h:115
const std::string DDD_CTPPS_DIAMONDS_SEGMENT_NAME
Definition: CTPPSDDDNames.h:16
int copyno() const
Copy number associated with the current node.
RPAlignmentCorrectionData & getRPCorrection(unsigned int id)
returns the correction value from the RP map
void ApplyAlignment(const RPAlignmentCorrectionData &)
alignment
Definition: DetGeomDesc.cc:185
std::unique_ptr< CTPPSGeometry > produceMisalignedTG(const VeryForwardMisalignedGeometryRecord &)
void setGeographicalID(DetId id)
ID stuff.
Definition: DetGeomDesc.h:60
virtual ConstContainer components() const
access to the tree structure
Definition: DetGeomDesc.cc:123
RPAlignmentCorrectionData getFullSensorCorrection(unsigned int id, bool useRPErrors=false) const
void get(HolderT &iHolder) const
Geometrical description of a sensor.
Definition: DetGeomDesc.h:37
Alignment correction for an element of the CT-PPS detector. Within the geometry description, every sensor (more generally every element) is given its translation and rotation. These two quantities shall be understood in local-to-global coordinate transform. That is, if r_l is a point in local coordinate system and x_g in global, then it holds.
DDName name() const
Definition: DetGeomDesc.h:87
const std::string DDD_TOTEM_TIMING_SENSOR_TMPL
Definition: CTPPSDDDNames.h:18
std::unique_ptr< DetGeomDesc > produceRealGD(const VeryForwardRealGeometryRecord &)
A DDFilter that always returns true.
Definition: DDFilter.h:27
const std::string DDD_TOTEM_RP_RP_NAME
DDD names of RP volumes.
Definition: CTPPSDDDNames.h:21
virtual DetId geographicalID() const
Definition: DetGeomDesc.h:61
const mapType & getSensorMap() const
returns the map of sensor alignment corrections
const std::string DDD_CTPPS_DIAMONDS_RP_NAME
Definition: CTPPSDDDNames.h:23
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
std::unique_ptr< DetGeomDesc > produceMisalignedGD(const VeryForwardMisalignedGeometryRecord &)
CTPPSGeometryESModule(const edm::ParameterSet &)
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
bool isValid() const
Definition: ESHandle.h:47
const std::string DDD_CTPPS_PIXELS_SENSOR_NAME
Definition: CTPPSDDDNames.h:15
T const * product() const
Definition: ESHandle.h:86
void addComponent(DetGeomDesc *)
Definition: DetGeomDesc.cc:160
const std::string & name() const
Returns the name.
Definition: DDName.cc:88
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 ...