Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:49:08

0001 #include "Geometry/TrackerNumberingBuilder/plugins/CmsTrackerDetIdBuilder.h"
0002 #include "Geometry/TrackerNumberingBuilder/interface/GeometricDet.h"
0003 #include "FWCore/Utilities/interface/Exception.h"
0004 #include "DataFormats/DetId/interface/DetId.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 
0007 #include <iostream>
0008 #include <fstream>
0009 #include <sstream>
0010 #include <string>
0011 #include <bitset>
0012 
0013 CmsTrackerDetIdBuilder::CmsTrackerDetIdBuilder(const std::vector<int>& detidShifts) : m_detidshifts() {
0014   if (detidShifts.size() != nSubDet * maxLevels)
0015     edm::LogError("WrongConfiguration") << "Wrong configuration of TrackerGeometricDetESModule. Vector of "
0016                                         << detidShifts.size() << " elements provided";
0017   else {
0018     for (unsigned int i = 0; i < nSubDet * maxLevels; ++i) {
0019       m_detidshifts[i] = detidShifts[i];
0020     }
0021   }
0022 }
0023 
0024 void CmsTrackerDetIdBuilder::buildId(GeometricDet& tracker) {
0025   LogDebug("BuildingTrackerDetId") << "Starting to build Tracker DetIds";
0026 
0027   DetId t(DetId::Tracker, 0);
0028   tracker.setGeographicalID(t);
0029   iterate(tracker, 0, tracker.geographicalId().rawId());
0030 }
0031 
0032 void CmsTrackerDetIdBuilder::iterate(GeometricDet& in, int level, unsigned int ID) {
0033   std::bitset<32> binary_ID(ID);
0034 
0035   // SubDetector (useful to know fron now on, valid only after level 0, where SubDetector is assigned)
0036   uint32_t mask = (7 << 25);
0037   uint32_t iSubDet = ID & mask;
0038   iSubDet = iSubDet >> 25;
0039   //
0040 
0041   LogTrace("BuildingTrackerDetId") << std::string(2 * level, '-') << "+" << ID << " " << iSubDet << " " << level;
0042 
0043   switch (level) {
0044       // level 0: special case because it is used to assign the proper detid bits based on the endcap-like subdetector position: +z or -z
0045     case 0: {
0046       for (uint32_t i = 0; i < in.components().size(); i++) {
0047         GeometricDet* component = in.component(i);
0048         uint32_t iSubDet = component->geographicalId().rawId();
0049         uint32_t temp = ID;
0050         temp |= (iSubDet << 25);
0051         component->setGeographicalID(temp);
0052 
0053         if (iSubDet > 0 && iSubDet <= nSubDet && m_detidshifts[level * nSubDet + iSubDet - 1] >= 0) {
0054           if (m_detidshifts[level * nSubDet + iSubDet - 1] + 2 < 25)
0055             temp |= (0 << (m_detidshifts[level * nSubDet + iSubDet - 1] + 2));
0056           bool negside = component->translation().z() < 0.;
0057           if (std::abs(component->translation().z()) < 1.)
0058             negside = component->components().front()->translation().z() <
0059                       0.;  // needed for subdet like TID which are NOT translated
0060           LogTrace("BuildingTrackerDetId")
0061               << "Is negative endcap? " << negside << ", because z translation is " << component->translation().z()
0062               << " and component z translation is " << component->components().front()->translation().z();
0063           if (negside) {
0064             temp |= (1 << m_detidshifts[level * nSubDet + iSubDet - 1]);
0065           } else {
0066             temp |= (2 << m_detidshifts[level * nSubDet + iSubDet - 1]);
0067           }
0068         }
0069         component->setGeographicalID(DetId(temp));
0070 
0071         // next level
0072         iterate(*component, level + 1, (in.components())[i]->geographicalId().rawId());
0073       }
0074       break;
0075     }
0076       // level 1 to 5
0077     default: {
0078       for (uint32_t i = 0; i < in.components().size(); i++) {
0079         auto component = in.component(i);
0080         uint32_t temp = ID;
0081 
0082         if (level < maxLevels) {
0083           if (iSubDet > 0 && iSubDet <= nSubDet && m_detidshifts[level * nSubDet + iSubDet - 1] >= 0) {
0084             temp |= (component->geographicalId().rawId() << m_detidshifts[level * nSubDet + iSubDet - 1]);
0085           }
0086           component->setGeographicalID(temp);
0087           // next level
0088           iterate(*component, level + 1, (in.components())[i]->geographicalId().rawId());
0089         }
0090       }
0091 
0092       break;
0093     }
0094       // level switch ends
0095   }
0096 
0097   return;
0098 }