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 
27 
30 
34 
38 
48 {
49  public:
51  ~CTPPSGeometryESModule() override {}
52 
53  std::unique_ptr<DetGeomDesc> produceIdealGD( const IdealGeometryRecord& );
54 
55  std::unique_ptr<DetGeomDesc> produceRealGD( const VeryForwardRealGeometryRecord& );
56  std::unique_ptr<CTPPSGeometry> produceRealTG( const VeryForwardRealGeometryRecord& );
57 
58  std::unique_ptr<DetGeomDesc> produceMisalignedGD( const VeryForwardMisalignedGeometryRecord& );
59  std::unique_ptr<CTPPSGeometry> produceMisalignedTG( const VeryForwardMisalignedGeometryRecord& );
60 
61  protected:
63  static void buildDetGeomDesc( DDFilteredView* fv, DetGeomDesc* gd );
64 
65  unsigned int verbosity_;
67 };
68 
69 
70 //----------------------------------------------------------------------------------------------------
71 //----------------------------------------------------------------------------------------------------
72 
74  verbosity_( iConfig.getUntrackedParameter<unsigned int>( "verbosity", 1 ) ),
75  compactViewTag_( iConfig.getParameter<std::string>( "compactViewTag" ) )
76 {
78 
81 
84 }
85 
86 //----------------------------------------------------------------------------------------------------
87 
88 void
91  DetGeomDesc*& newGD )
92 {
93  newGD = new DetGeomDesc( *(idealGD.product()) );
94  std::deque<const DetGeomDesc*> buffer;
95  std::deque<DetGeomDesc*> bufferNew;
96  buffer.emplace_back( idealGD.product() );
97  bufferNew.emplace_back( newGD );
98 
99  while ( !buffer.empty() ) {
100  const DetGeomDesc* sD = buffer.front();
101  DetGeomDesc* pD = bufferNew.front();
102  buffer.pop_front();
103  bufferNew.pop_front();
104 
105  const std::string name = pD->name().name();
106 
107  // Is it sensor? If yes, apply full sensor alignments
108  if ( name == DDD_TOTEM_RP_SENSOR_NAME
110  || name == DDD_CTPPS_UFSD_SEGMENT_NAME
111  || name == DDD_CTPPS_PIXELS_SENSOR_NAME ) {
112  unsigned int plId = pD->geographicalID();
113 
114  if ( alignments.isValid() ) {
115  const RPAlignmentCorrectionData& ac = alignments->getFullSensorCorrection( plId );
116  pD->ApplyAlignment( ac );
117  }
118  }
119 
120  // Is it RP box? If yes, apply RP alignments
121  if ( name == DDD_TOTEM_RP_RP_NAME
122  || name == DDD_CTPPS_DIAMONDS_RP_NAME
123  || name == DDD_CTPPS_PIXELS_RP_NAME ) {
124  unsigned int rpId = pD->geographicalID();
125 
126  if ( alignments.isValid() ) {
127  const RPAlignmentCorrectionData& ac = alignments->getRPCorrection( rpId );
128  pD->ApplyAlignment( ac );
129  }
130  }
131 
132  // create and add children
133  for ( unsigned int i = 0; i < sD->components().size(); i++ ) {
134  const DetGeomDesc* sDC = sD->components()[i];
135  buffer.emplace_back( sDC );
136 
137  // create new node with the same information as in sDC and add it as a child of pD
138  DetGeomDesc* cD = new DetGeomDesc( *sDC );
139  pD->addComponent( cD );
140 
141  bufferNew.emplace_back( cD );
142  }
143  }
144 }
145 
146 //----------------------------------------------------------------------------------------------------
147 
148 void
150 {
151  // try to dive into next level
152  if ( !fv->firstChild() ) return;
153 
154  // loop over siblings in the level
155  do {
156  // create new DetGeomDesc node and add it to the parent's (gd) list
157  DetGeomDesc* newGD = new DetGeomDesc( fv );
158 
159  const std::string name = fv->logicalPart().name().name();
160 
161  // strip sensors
162  if ( name == DDD_TOTEM_RP_SENSOR_NAME ) {
163  const std::vector<int>& copy_num = fv->copyNumbers();
164  // check size of copy numubers array
165  if ( copy_num.size() < 3 )
166  throw cms::Exception("DDDTotemRPContruction") << "size of copyNumbers for strip sensor is "
167  << copy_num.size() << ". It must be >= 3.";
168 
169  // extract information
170  const unsigned int decRPId = copy_num[copy_num.size() - 3];
171  const unsigned int arm = decRPId / 100;
172  const unsigned int station = ( decRPId % 100 ) / 10;
173  const unsigned int rp = decRPId % 10;
174  const unsigned int detector = copy_num[copy_num.size() - 1];
175  newGD->setGeographicalID( TotemRPDetId( arm, station, rp, detector ) );
176  }
177 
178  // strip and pixels RPs
179  else if ( name == DDD_TOTEM_RP_RP_NAME || name == DDD_CTPPS_PIXELS_RP_NAME) {
180  uint32_t decRPId = uint32_t(fv->copyno());
181 
182  // check if it is a pixel RP
183  if ( decRPId >= 10000 ){
184  decRPId = decRPId % 10000;
185  const unsigned int armIdx = ( decRPId / 100 ) % 10;
186  const unsigned int stIdx = ( decRPId / 10 ) % 10;
187  const unsigned int rpIdx = decRPId % 10;
188  newGD->setGeographicalID( CTPPSPixelDetId( armIdx, stIdx, rpIdx ) );
189  }else{
190  const unsigned int armIdx = ( decRPId / 100 ) % 10;
191  const unsigned int stIdx = ( decRPId / 10 ) % 10;
192  const unsigned int rpIdx = decRPId % 10;
193  newGD->setGeographicalID( TotemRPDetId( armIdx, stIdx, rpIdx ) );
194  }
195  }
196 
197  // pixel sensors
198  else if ( name == DDD_CTPPS_PIXELS_SENSOR_NAME ) {
199  const std::vector<int>& copy_num = fv->copyNumbers();
200  // check size of copy numubers array
201  if ( copy_num.size() < 4 )
202  throw cms::Exception("DDDTotemRPContruction") << "size of copyNumbers for pixel sensor is "
203  << copy_num.size() << ". It must be >= 4.";
204 
205  // extract information
206  const unsigned int decRPId = copy_num[copy_num.size() - 4] % 10000;
207  const unsigned int arm = decRPId / 100;
208  const unsigned int station = ( decRPId % 100 ) / 10;
209  const unsigned int rp = decRPId % 10;
210  const unsigned int detector = copy_num[copy_num.size() - 2] - 1;
211  newGD->setGeographicalID( CTPPSPixelDetId( arm, station, rp, detector ) );
212  }
213 
214  // diamond/UFSD sensors
215  else if ( name == DDD_CTPPS_DIAMONDS_SEGMENT_NAME || name == DDD_CTPPS_UFSD_SEGMENT_NAME ) {
216  const std::vector<int>& copy_num = fv->copyNumbers();
217 
218  const unsigned int id = copy_num[copy_num.size()-1];
219  const unsigned int arm = copy_num[1]-1;
220  const unsigned int station = 1;
221  const unsigned int rp = 6;
222  const unsigned int plane = ( id / 100 );
223  const unsigned int channel = id % 100;
224 
225  newGD->setGeographicalID( CTPPSDiamondDetId( arm, station, rp, plane, channel ) );
226  }
227 
228  // diamond/UFSD RPs
229  else if ( name == DDD_CTPPS_DIAMONDS_RP_NAME ) {
230  const std::vector<int>& copy_num = fv->copyNumbers();
231 
232  // check size of copy numubers array
233  if ( copy_num.size() < 2 )
234  throw cms::Exception("DDDTotemRPContruction") << "size of copyNumbers for diamond RP is "
235  << copy_num.size() << ". It must be >= 2.";
236 
237  const unsigned int arm = copy_num[1] - 1;
238  const unsigned int station = 1;
239  const unsigned int rp = 6;
240 
241  newGD->setGeographicalID( CTPPSDiamondDetId( arm, station, rp ) );
242  }
243 
244  // add component
245  gd->addComponent( newGD );
246 
247  // recursion
248  buildDetGeomDesc( fv, newGD );
249  } while ( fv->nextSibling() );
250 
251  // go a level up
252  fv->parent();
253 }
254 
255 //----------------------------------------------------------------------------------------------------
256 
257 std::unique_ptr<DetGeomDesc>
259 {
260  // get the DDCompactView from EventSetup
262  iRecord.get( compactViewTag_, cpv );
263 
264  // create DDFilteredView and apply the filter
266  DDFilteredView fv( *( cpv.product() ), filter );
267 
268  // conversion to DetGeomDesc structure
269  DetGeomDesc* root = new DetGeomDesc( &fv );
270  buildDetGeomDesc( &fv, root );
271 
272  // construct the tree of DetGeomDesc
273  return std::unique_ptr<DetGeomDesc>( const_cast<DetGeomDesc*>( root ) );
274 }
275 
276 //----------------------------------------------------------------------------------------------------
277 
278 std::unique_ptr<DetGeomDesc>
280 {
281  // get the input GeometricalDet
283  iRecord.getRecord<IdealGeometryRecord>().get( idealGD );
284 
285  // load alignments
287  try { iRecord.getRecord<RPRealAlignmentRecord>().get( alignments ); }
288  catch ( cms::Exception& ) {}
289 
290  if ( alignments.isValid() ) {
291  if ( verbosity_ )
292  edm::LogVerbatim("CTPPSGeometryESModule::produceRealGD")
293  << ">> CTPPSGeometryESModule::produceRealGD > Real geometry: "
294  << alignments->getRPMap().size() << " RP and "
295  << alignments->getSensorMap().size() << " sensor alignments applied.";
296  }
297  else {
298  if ( verbosity_ )
299  edm::LogVerbatim("CTPPSGeometryESModule::produceRealGD")
300  << ">> CTPPSGeometryESModule::produceRealGD > Real geometry: No alignments applied.";
301  }
302 
303  DetGeomDesc* newGD = nullptr;
304  applyAlignments( idealGD, alignments, newGD );
305  return std::unique_ptr<DetGeomDesc>( newGD );
306 }
307 
308 //----------------------------------------------------------------------------------------------------
309 
310 std::unique_ptr<DetGeomDesc>
312 {
313  // get the input GeometricalDet
315  iRecord.getRecord<IdealGeometryRecord>().get( idealGD );
316 
317  // load alignments
319  try { iRecord.getRecord<RPMisalignedAlignmentRecord>().get( alignments ); }
320  catch ( cms::Exception& ) {}
321 
322  if ( alignments.isValid() ) {
323  if ( verbosity_ )
324  edm::LogVerbatim("CTPPSGeometryESModule::produceMisalignedGD")
325  << ">> CTPPSGeometryESModule::produceMisalignedGD > Misaligned geometry: "
326  << alignments->getRPMap().size() << " RP and "
327  << alignments->getSensorMap().size() << " sensor alignments applied.";
328  } else {
329  if ( verbosity_ )
330  edm::LogVerbatim("CTPPSGeometryESModule::produceMisalignedGD")
331  << ">> CTPPSGeometryESModule::produceMisalignedGD > Misaligned geometry: No alignments applied.";
332  }
333 
334  DetGeomDesc* newGD = nullptr;
335  applyAlignments( idealGD, alignments, newGD );
336  return std::unique_ptr<DetGeomDesc>( newGD );
337 }
338 
339 //----------------------------------------------------------------------------------------------------
340 
341 std::unique_ptr<CTPPSGeometry>
343 {
345  iRecord.get( gD );
346 
347  return std::make_unique<CTPPSGeometry>( gD.product() );
348 }
349 
350 //----------------------------------------------------------------------------------------------------
351 
352 std::unique_ptr<CTPPSGeometry>
354 {
356  iRecord.get( gD );
357 
358  return std::make_unique<CTPPSGeometry>( gD.product() );
359 }
360 
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 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
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:90
const std::string DDD_CTPPS_UFSD_SEGMENT_NAME
Definition: CTPPSDDDNames.h:17