22#define DataFormats_BTLDetId_BTLDetId_h
33
44#include " DataFormats/ForwardDetId/interface/MTDDetId.h"
5- #include < iostream>
65#include < ostream>
76#include < array>
8- #include < bitset>
97
108/* *
119 @class BTLDetId
1614 bit 9-8 : crystal type (1 - 3)
1715 bit 7-6 : readout unit sequential number within a type ( 1 - 2 )
1816 bit 5-0 : crystal sequential number within a module ( 0 - 15 )
19-
20- // Geometry v3 new DetID (all type 1 modules)
21- bit 15: kBTLNewFormat (0 - old BTLDetID, 1 - new BTLDetID)
22- bit 12-10: Readout unit number ( 1 - 6 )
23- bit 9-6 : Detector Module ( 1 - 12 )
24- bit 5 : Sensor Module inside DM ( 0 - 1 )
25- bit 4-0 : Crystal number in a SM ( 1 - 16 )
2617*/
2718
2819class BTLDetId : public MTDDetId {
2920public:
30- // old BTLDetID RU and module number scheme
31- static constexpr uint32_t kBTLoldModuleOffset = 10 ;
32- static constexpr uint32_t kBTLoldModuleMask = 0x3F ;
33- static constexpr uint32_t kBTLoldModTypeOffset = 8 ;
34- static constexpr uint32_t kBTLoldModTypeMask = 0x3 ;
35- static constexpr uint32_t kBTLoldRUOffset = 6 ;
36- static constexpr uint32_t kBTLoldRUMask = 0x3 ;
37-
38- // New BTLDetID
39- static constexpr uint32_t kBTLRodOffset = 16 ;
40- static constexpr uint32_t kBTLRodMask = 0x3F ;
41- static constexpr uint32_t kBTLRUOffset = 10 ;
42- static constexpr uint32_t kBTLRUMask = 0x7 ;
43- static constexpr uint32_t kBTLdetectorModOffset = 6 ;
44- static constexpr uint32_t kBTLdetectorModMask = 0xF ;
45- static constexpr uint32_t kBTLsensorModOffset = 5 ;
46- static constexpr uint32_t kBTLsensorModMask = 0x1 ;
21+ static constexpr uint32_t kBTLmoduleOffset = 10 ;
22+ static constexpr uint32_t kBTLmoduleMask = 0x3F ;
23+ static constexpr uint32_t kBTLmodTypeOffset = 8 ;
24+ static constexpr uint32_t kBTLmodTypeMask = 0x3 ;
25+ static constexpr uint32_t kBTLRUOffset = 6 ;
26+ static constexpr uint32_t kBTLRUMask = 0x3 ;
4727 static constexpr uint32_t kBTLCrystalOffset = 0 ;
48- static constexpr uint32_t kBTLCrystalMask = 0x1F ;
28+ static constexpr uint32_t kBTLCrystalMask = 0x3F ;
4929
5030 // / range constants, need two sets for the time being (one for tiles and one for bars)
5131 static constexpr uint32_t HALF_ROD = 36 ;
5232 static constexpr uint32_t kModulesPerRODBarPhiFlat = 48 ;
5333 static constexpr uint32_t kModulePerTypeBarPhiFlat = 48 / 3 ;
5434 static constexpr uint32_t kRUPerTypeV2 = 2 ;
55- static constexpr uint32_t kRUPerRod = 6 ;
5635 static constexpr uint32_t kModulesPerRUV2 = 24 ;
57- static constexpr uint32_t kDModulesPerRU = 12 ;
58- static constexpr uint32_t kSModulesPerDM = 2 ;
59- static constexpr uint32_t kDModulesInRUCol = 3 ;
60- static constexpr uint32_t kDModulesInRURow = 4 ;
61- static constexpr uint32_t kSModulesInDM = 2 ;
6236 static constexpr uint32_t kCrystalsPerModuleV2 = 16 ;
6337 static constexpr uint32_t kModulesPerTrkV2 = 3 ;
6438 static constexpr uint32_t kCrystalTypes = 3 ;
6539
66- // conversion
67- static constexpr uint32_t kBTLoldFieldMask = 0x3FFFFF ;
68- static constexpr uint32_t kBTLNewFormat = 1 << 15 ;
69-
70- //
71-
7240 // Number of crystals in BTL according to TDR design, valid also for barphiflat scenario:
7341 // 16 crystals x 24 modules x 2 readout units/type x 3 types x 36 rods/side x 2 sides
7442 //
@@ -82,120 +50,67 @@ class BTLDetId : public MTDDetId {
8250 /* * Construct a null id */
8351 BTLDetId () : MTDDetId (DetId::Forward, ForwardSubdetector::FastTime) {
8452 id_ |= (MTDType::BTL & kMTDsubdMask ) << kMTDsubdOffset ;
85- id_ |= kBTLNewFormat ;
8653 }
8754
8855 /* * Construct from a raw value */
89- BTLDetId (const uint32_t & raw_id) : MTDDetId (raw_id) {
90- uint32_t tmpId = raw_id;
91- if ((tmpId & kBTLNewFormat ) == 0 ) {
92- tmpId = newForm (tmpId);
93- }
94- id_ = MTDDetId (tmpId).rawId ();
95- }
56+ BTLDetId (const uint32_t & raw_id) : MTDDetId (raw_id) { ; }
9657
9758 /* * Construct from generic DetId */
98- BTLDetId (const DetId& det_id) : MTDDetId (det_id.rawId ()) {
99- uint32_t tmpId = det_id.rawId ();
100- if ((tmpId & kBTLNewFormat ) == 0 ) {
101- tmpId = newForm (tmpId);
102- }
103- id_ = MTDDetId (tmpId).rawId ();
104- }
59+ BTLDetId (const DetId& det_id) : MTDDetId (det_id.rawId ()) { ; }
10560
106- /* * Construct from complete geometry information, v2, v3 **/
107- /* * Geometry v1 is obsolete and not supported **/
108- BTLDetId (uint32_t zside, uint32_t rod, uint32_t runit, uint32_t dmodule, uint32_t smodule, uint32_t crystal)
61+ /* * Construct from complete geometry information, v1 **/
62+ BTLDetId (uint32_t zside, uint32_t rod, uint32_t module, uint32_t modtyp, uint32_t crystal)
10963 : MTDDetId (DetId::Forward, ForwardSubdetector::FastTime) {
110- // RU, DM, SM & Xtal numbers start from 0
11164 id_ |= (MTDType::BTL & kMTDsubdMask ) << kMTDsubdOffset | (zside & kZsideMask ) << kZsideOffset |
112- (rod & kRodRingMask ) << kRodRingOffset | (runit & kBTLRUMask ) << kBTLRUOffset |
113- (dmodule & kBTLdetectorModMask ) << kBTLdetectorModOffset |
114- (smodule & kBTLsensorModMask ) << kBTLsensorModOffset |
115- (crystal & kBTLCrystalMask ) << kBTLCrystalOffset ;
116- id_ |= kBTLNewFormat ;
65+ (rod & kRodRingMask ) << kRodRingOffset | (module & kBTLmoduleMask ) << kBTLmoduleOffset |
66+ (modtyp & kBTLmodTypeMask ) << kBTLmodTypeOffset | ((crystal - 1 ) & kBTLCrystalMask ) << kBTLCrystalOffset ;
11767 }
11868
119- // ---------- Common methods ----------
120-
121- /* * Returns BTL crystal number. */
122- inline int crystal () const { return ((id_ >> kBTLCrystalOffset ) & kBTLCrystalMask );}
123-
124- /* * Returns BTL crystal number in construction database. */
125- inline int crystalConsDB () const {
126- if (crystal () == kCrystalsPerModuleV2 ) return -1 ;
127- if (smodule () == 0 ) return kCrystalsPerModuleV2 -1 - crystal () ;
128- else return crystal ();
69+ /* * Construct from complete geometry information, v2 **/
70+ BTLDetId (uint32_t zside, uint32_t rod, uint32_t runit, uint32_t module, uint32_t modtyp, uint32_t crystal)
71+ : MTDDetId (DetId::Forward, ForwardSubdetector::FastTime) {
72+ id_ |= (MTDType::BTL & kMTDsubdMask ) << kMTDsubdOffset | (zside & kZsideMask ) << kZsideOffset |
73+ (rod & kRodRingMask ) << kRodRingOffset | (module & kBTLmoduleMask ) << kBTLmoduleOffset |
74+ (modtyp & kBTLmodTypeMask ) << kBTLmodTypeOffset | (runit & kBTLRUMask ) << kBTLRUOffset |
75+ ((crystal - 1 ) & kBTLCrystalMask ) << kBTLCrystalOffset ;
12976 }
13077
131- /* * Returns BTL detector module number. */
132- inline int dmodule () const { return ((id_ >> kBTLdetectorModOffset ) & kBTLdetectorModMask ); }
78+ // ---------- Common methods ----------
13379
134- /* * Returns BTL sensor module number. */
135- inline int smodule () const { return (( id_ >> kBTLsensorModOffset ) & kBTLsensorModMask ) ; }
80+ /* * Returns BTL module number. */
81+ inline int module () const { return (id_ >> kBTLmoduleOffset ) & kBTLmoduleMask ; }
13682
137- /* * Returns BTL module number [1-24] (OLD BTL NUMBERING). */
138- inline int module () const {
139- int mod = ((dmodule () % kDModulesInRURow ) * (kSModulesInDM * kDModulesInRUCol ) + int (dmodule () / kDModulesInRURow ) + kDModulesInRUCol * smodule ()) + 1 ;
140- return mod;
141- }
83+ /* * Returns BTL crystal type number. */
84+ inline int modType () const { return (id_ >> kBTLmodTypeOffset ) & kBTLmodTypeMask ; }
14285
143- /* * Returns BTL crystal type number [1-3] (OLD BTL NUMBERING). */
144- inline int modType () const {
145- int gRU = runit ();
146- return int (gRU / kRUPerTypeV2 + 1 );
147- }
86+ /* * Returns BTL crystal number. */
87+ inline int crystal () const { return ((id_ >> kBTLCrystalOffset ) & kBTLCrystalMask ) + 1 ; }
14888
149- /* * Returns BTL readout unit number per type [1-2], from Global RU number [1-6] . */
150- inline int runitByType () const { return (runit () % kRUPerTypeV2 ) ; }
89+ /* * Returns BTL readout unit number per type. */
90+ inline int runit () const { return (id_ >> kBTLRUOffset ) & kBTLRUMask ; }
15191
15292 /* * Returns BTL global readout unit number. */
153- inline int runit () const { return ((id_ >> kBTLRUOffset ) & kBTLRUMask ); }
93+ inline int globalRunit () const {
94+ if (runit () == 0 ) {
95+ // pre-V2: build a RU identifier from available information
96+ return (module () - 1 ) / kModulePerTypeBarPhiFlat / kRUPerTypeV2 + 1 ;
97+ } else if (runit () > 0 && modType () > 0 ) {
98+ // V2/V3: build global RU identifier from RU per type and type
99+ return (modType () - 1 ) * kRUPerTypeV2 + runit ();
100+ }
101+ return 0 ;
102+ }
154103
155104 /* * return the row in GeomDet language **/
156105 inline int row (unsigned nrows = kCrystalsPerModuleV2 ) const {
157- return crystal () % nrows; // anything else for now
106+ return ( crystal () - 1 ) % nrows; // anything else for now
158107 }
159108
160109 /* * return the column in GeomDetLanguage **/
161- inline int column (unsigned nrows = kCrystalsPerModuleV2 ) const { return crystal () / nrows; }
110+ inline int column (unsigned nrows = kCrystalsPerModuleV2 ) const { return ( crystal () - 1 ) / nrows; }
162111
163112 /* * create a Geographical DetId for Tracking **/
164113 BTLDetId geographicalId (CrysLayout lay) const ;
165-
166- /* * conversion from old to new BTLDetID**/
167- uint32_t newForm (const uint32_t & rawid) {
168- uint32_t fixedP = rawid & (0xFFFFFFFF - kBTLoldFieldMask ); // unchanged part of id
169-
170- // convert old tray number into new tray nymber
171- uint32_t oldTray = (rawid >> kBTLRodOffset ) & kBTLRodMask ;
172- uint32_t newTray = oldTray - 1 ;
173-
174- // convert old module number into detector module + sensor module numbers
175- uint32_t oldModule = (rawid >> kBTLoldModuleOffset ) & kBTLoldModuleMask ;
176- uint32_t detModule = int ((oldModule - 1 ) % (kDModulesInRUCol )) * kDModulesInRURow +
177- int ((oldModule - 1 ) / (kDModulesInRUCol * kSModulesInDM ));
178- uint32_t senModule = int ((oldModule - 1 ) / kDModulesInRUCol ) % kSModulesInDM ;
179-
180- // change detector module number if on the negative side
181- int zside = int (mtdSide ());
182- if (zside < 1 ) detModule = detModule - 2 * kDModulesInRURow * (int (detModule/kDModulesInRURow ) - 1 );
183-
184- // convert old RU and type number into new RU number
185- uint32_t oldRU = (rawid >> kBTLoldRUOffset ) & kBTLoldRUMask ;
186- uint32_t oldType = (rawid >> kBTLoldModTypeOffset ) & kBTLoldModTypeMask ;
187- uint32_t newRU = ((oldType - 1 ) * kRUPerTypeV2 ) + (oldRU-1 );
188-
189- // get crystal number
190- uint32_t crystal = (rawid & kBTLCrystalMask ) >> kBTLCrystalOffset ;
191-
192- // return new BTLDetID for v3 geom
193- return (fixedP | (newTray & kBTLRodMask ) << kBTLRodOffset | (newRU & kBTLRUMask ) << kBTLRUOffset |
194- (detModule & kBTLdetectorModMask ) << kBTLdetectorModOffset |
195- (senModule & kBTLsensorModMask ) << kBTLsensorModOffset |
196- ((crystal & kBTLCrystalMask ) << kBTLCrystalOffset )) |
197- kBTLNewFormat ;
198- }
199114};
200115
201116std::ostream& operator<<(std::ostream&, const BTLDetId&);
0 commit comments