Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
#include "CondFormats/SiPixelObjects/interface/PixelROC.h"

#include "DataFormats/TrackerCommon/interface/PixelBarrelName.h"
#include "DataFormats/TrackerCommon/interface/PixelEndcapName.h"
#include "DataFormats/DetId/interface/DetId.h"

#include <sstream>
#include <algorithm>
using namespace std;
using namespace sipixelobjects;

// Constructor with transformation frame initilization - NEVER CALLED
PixelROC::PixelROC(uint32_t du, int idDU, int idLk) : theDetUnit(du), theIdDU(idDU), theIdLk(idLk) {
  initFrameConversion();
}

// // for testing, uses topology fot det id, it works but I cannot pass topology here
// // not used
// void PixelROC::initFrameConversion(const TrackerTopology *tt, bool phase1) {
//   const bool TEST = false;
//   if(phase1) { // phase1
//     bool isBarrel = PixelModuleName::isBarrel(theDetUnit);
//     int side = 0;
//     if(isBarrel) {
//       // Barrel Z-index=1,8
//       if((tt->pxbModule(theDetUnit))<5) side=-1;
//       else side=1;
//       if(TEST) {
// 	// phase0 code
// 	PXBDetId det(theDetUnit);
// 	unsigned  int module = bpixSidePhase0(theDetUnit);
// 	if(!phase1 && (tt->pxbModule(theDetUnit) != module) )
// 	// phase1 code
// 	unsigned  int module1 = bpixSidePhase1(theDetUnit);
//       }
//     } else {
//       // Endcaps, use the panel to find the direction
//       if((tt->pxfPanel(theDetUnit))==1) side=-1; // panel 1
//       else side =1; // panel 2
//       if(TEST) {
// 	// code -phase0
// 	PXFDetId det(theDetUnit);
// 	unsigned int module = fpixSidePhase0(theDetUnit);
// 	// phase1 code
// 	unsigned int module1 = fpixSidePhase1(theDetUnit);
//       }
//     }
//     theFrameConverter = FrameConversion(isBarrel,side, theIdDU);
//   } else { // phase0
//     initFrameConversion();  // old code for phase0
//   }
// }

// works for phase 1, find det side from the local method
// Frame conversion compatible with CMSSW_9_0_X Monte Carlo samples
void PixelROC::initFrameConversionPhase1_CMSSW_9_0_X() {
  int side = 0;
  bool isBarrel = PixelModuleName::isBarrel(theDetUnit);
  if (isBarrel) {
    side = bpixSidePhase1(theDetUnit);  // find the side for phase1
  } else {
    side = fpixSidePhase1(theDetUnit);
  }

  theFrameConverter = FrameConversion(isBarrel, side, theIdDU);
}

// works for phase 1, find det side from the local method
void PixelROC::initFrameConversionPhase1() {
  int side = 0;
  int layer = 0;
  bool isBarrel = PixelModuleName::isBarrel(theDetUnit);
  if (isBarrel) {
    side = bpixSidePhase1(theDetUnit);  // find the side for phase1
    layer = bpixLayerPhase1(theDetUnit);
  } else {
    side = fpixSidePhase1(theDetUnit);
  }

  theFrameConverter = FrameConversion(isBarrel, side, layer, theIdDU);
}

// Works only for phase0, uses the fixed pixel id
void PixelROC::initFrameConversion() {
  if (PixelModuleName::isBarrel(theDetUnit)) {
    PixelBarrelName barrelName(theDetUnit);
    theFrameConverter = FrameConversion(barrelName, theIdDU);
  } else {
    PixelEndcapName endcapName(theDetUnit);
    theFrameConverter = FrameConversion(endcapName, theIdDU);
  }
}

// These are methods to find the module side.
// The are hardwired for phase0 and phase1
// Will not work for phase2 or when the detid coding changes.
int PixelROC::bpixSidePhase0(uint32_t rawId) const {
  int side = 1;
  /// two bits would be enough, but  we could use the number "0" as a wildcard
  //const unsigned int layerStartBit_=   16;
  //const unsigned int ladderStartBit_=   8;
  const unsigned int moduleStartBit_ = 2;
  /// two bits would be enough, but  we could use the number "0" as a wildcard
  //const unsigned int layerMask_=       0xF;
  //const unsigned int ladderMask_=      0xFF;
  const unsigned int moduleMask_ = 0x3F;

  /// layer id
  //unsigned int layer = (rawId>>layerStartBit_) & layerMask_;
  /// ladder  id
  //unsigned int ladder = (rawId>>ladderStartBit_) & ladderMask_;
  /// det id
  unsigned int module = (rawId >> moduleStartBit_) & moduleMask_;

  if (module < 5)
    side = -1;  // modules 1-4 are on -z
  return side;
}
int PixelROC::bpixSidePhase1(uint32_t rawId) const {
  int side = 1;

  /// two bits would be enough, but  we could use the number "0" as a wildcard
  //const unsigned int layerStartBit_=   20;
  //const unsigned int ladderStartBit_=  12;
  const unsigned int moduleStartBit_ = 2;
  /// two bits would be enough, but  we could use the number "0" as a wildcard
  //const unsigned int layerMask_=       0xF;
  //const unsigned int ladderMask_=      0xFF;
  const unsigned int moduleMask_ = 0x3FF;

  /// layer id
  //unsigned int layer = (rawId>>layerStartBit_) & layerMask_;
  /// ladder  id
  //unsigned int ladder = (rawId>>ladderStartBit_) & ladderMask_;
  /// det id
  unsigned int module = (rawId >> moduleStartBit_) & moduleMask_;

  if (module < 5)
    side = -1;  // modules 1-4 are on -z
  return side;
}
int PixelROC::bpixLayerPhase1(uint32_t rawId) {
  /// two bits would be enough, but  we could use the number "0" as a wildcard
  const unsigned int layerStartBit_ = 20;
  //const unsigned int ladderStartBit_=  12;
  //const unsigned int moduleStartBit_=   2;
  /// two bits would be enough, but  we could use the number "0" as a wildcard
  const unsigned int layerMask_ = 0xF;
  //const unsigned int ladderMask_=      0xFF;
  //const unsigned int moduleMask_=      0x3FF;

  /// layer id
  unsigned int layer = (rawId >> layerStartBit_) & layerMask_;
  /// ladder  id
  //unsigned int ladder = (rawId>>ladderStartBit_) & ladderMask_;
  /// det id
  //unsigned int module = (rawId>>moduleStartBit_)& moduleMask_;

  //if(module<5) side=-1; // modules 1-4 are on -z
  return layer;
}

int PixelROC::fpixSidePhase0(uint32_t rawId) const {
  int side = 1;

  /// two bits would be enough, but  we could use the number "0" as a wildcard
  //const unsigned int sideStartBit_=   23;
  //const unsigned int diskStartBit_=   16;
  //const unsigned int bladeStartBit_=  10;
  const unsigned int panelStartBit_ = 8;
  //const unsigned int moduleStartBit_= 2;
  /// two bits would be enough, but  we could use the number "0" as a wildcard

  //const unsigned int sideMask_=     0x3;
  //const unsigned int diskMask_=     0xF;
  //const unsigned int bladeMask_=    0x3F;
  const unsigned int panelMask_ = 0x3;
  //const unsigned int moduleMask_=   0x3F;

  /// positive or negative id
  //unsigned int sides = int((rawId>>sideStartBit_) & sideMask_);
  /// disk id
  //unsigned int disk = int((rawId>>diskStartBit_) & diskMask_);
  /// blade id
  //unsigned int blade = ((rawId>>bladeStartBit_) & bladeMask_);
  /// panel id
  unsigned int panel = ((rawId >> panelStartBit_) & panelMask_);
  /// det id
  //unsigned int module = ((rawId>>moduleStartBit_) & moduleMask_);

  if (panel == 1)
    side = -1;  // panel 1 faces -z (is this true for all disks?)
  return side;
}
int PixelROC::fpixSidePhase1(uint32_t rawId) const {
  int side = 1;

  /// two bits would be enough, but  we could use the number "0" as a wildcard
  //const unsigned int sideStartBit_=   23;
  //const unsigned int diskStartBit_=   18;
  //const unsigned int bladeStartBit_=  12;
  const unsigned int panelStartBit_ = 10;
  //const unsigned int moduleStartBit_= 2;
  /// two bits would be enough, but  we could use the number "0" as a wildcard

  //const unsigned int sideMask_=     0x3;
  //const unsigned int diskMask_=     0xF;
  //const unsigned int bladeMask_=    0x3F;
  const unsigned int panelMask_ = 0x3;
  //const unsigned int moduleMask_=   0xFF;

  /// positive or negative id
  //unsigned int sides = int((rawId>>sideStartBit_) & sideMask_);
  /// disk id
  //unsigned int disk = int((rawId>>diskStartBit_) & diskMask_);

  /// blade id
  //unsigned int blade = ((rawId>>bladeStartBit_) & bladeMask_);

  /// panel id 1 or 2
  unsigned int panel = ((rawId >> panelStartBit_) & panelMask_);

  /// det id
  //unsigned int module = ((rawId>>moduleStartBit_) & moduleMask_);

  if (panel == 1)
    side = -1;  // panel 1 faces -z (is this true for all disks?)
  return side;
}

string PixelROC::print(int depth) const {
  ostringstream out;
  bool barrel = PixelModuleName::isBarrel(theDetUnit);
  DetId detId(theDetUnit);
  if (depth-- >= 0) {
    out << "======== PixelROC ";
    //out <<" unit: ";
    //if (barrel) out << PixelBarrelName(detId).name();
    //else        out << PixelEndcapName(detId).name();
    if (barrel)
      out << " barrel ";
    else
      out << " endcap ";
    out << " (" << theDetUnit << ")"
        << " idInDU: " << theIdDU << " idInLk: "
        << theIdLk
        //        <<" frame: "<<theRowOffset<<","<<theRowSlopeSign<<","<<theColOffset<<","<<theColSlopeSign
        //        <<" frame: "<<*theFrameConverter
        << endl;
  }
  return out.str();
}