CMS 3D CMS Logo

TTStubAlgorithm_official.cc
Go to the documentation of this file.
1 
12 
14 template< >
16  int &aDisplacement,
17  int &anOffset,
18  float &anROffset,
19  float &anHardBend,
20  const TTStub< Ref_Phase2TrackerDigi_ > &aTTStub ) const
21 {
23  // These are already corrected for being at the center of each pixel
24  MeasurementPoint mp0 = aTTStub.getClusterRef(0)->findAverageLocalCoordinates();
25  MeasurementPoint mp1 = aTTStub.getClusterRef(1)->findAverageLocalCoordinates();
26 
28  bool isPS = (theTrackerGeom_->getDetectorType(aTTStub.getDetId())==TrackerGeometry::ModuleType::Ph2PSP);
29  // TODO temporary: should use a method from the topology
30  DetId stDetId( aTTStub.getDetId() );
31  const GeomDetUnit* det0 = theTrackerGeom_->idToDetUnit( stDetId+1 );
32  const GeomDetUnit* det1 = theTrackerGeom_->idToDetUnit( stDetId+2 );
33 
35  const PixelGeomDetUnit* pix0 = dynamic_cast< const PixelGeomDetUnit* >( det0 );
36  const PixelGeomDetUnit* pix1 = dynamic_cast< const PixelGeomDetUnit* >( det1 );
37  const PixelTopology* top0 = dynamic_cast< const PixelTopology* >( &(pix0->specificTopology()) );
38  const PixelTopology* top1 = dynamic_cast< const PixelTopology* >( &(pix1->specificTopology()) );
39  std::pair< float, float > pitch0 = top0->pitch();
40  std::pair< float, float > pitch1 = top1->pitch();
41 
43  int cols0 = top0->ncolumns();
44  int cols1 = top1->ncolumns();
45  int ratio = cols0/cols1;
46  int segment0 = floor( mp0.y() / ratio );
47 
48 // if ( ratio == 1 ) /// 2S Modules
49  if (!isPS)
50  {
51  if ( mPerformZMatching2S && ( segment0 != floor( mp1.y() ) ) )
52  return;
53  }
54  else
55  {
56  if ( mPerformZMatchingPS && ( segment0 != floor( mp1.y() ) ) )
57  return;
58  }
59 
61  double R0 = det0->position().perp();
62  double R1 = det1->position().perp();
63  double Z0 = det0->position().z();
64  double Z1 = det1->position().z();
65 
66  double DR = R1-R0;
67  double DZ = Z1-Z0;
68 
69  double alpha = atan2(DR,DZ);
70  double delta = sqrt(DR*DR+DZ*DZ)/(R0*sin(alpha)+Z0*cos(alpha));
71 
72  int window=0;
73 
78 
79 
90  double dispD = 2 * (mp1.x() - mp0.x()) * (pitch0.first / pitch1.first);
91  int dispI = ((dispD>0)-(dispD<0))*floor(std::abs(dispD));
92 
97  double offsetD = 2 * delta * ( mp0.x() - (top0->nrows()/2 - 0.5) ) * (pitch0.first / pitch1.first);
98  int offsetI = ((offsetD>0)-(offsetD<0))*floor(std::abs(offsetD));
99 
100  if (stDetId.subdetId()==StripSubdetector::TOB)
101  {
102  int layer = theTrackerTopo_->layer(stDetId);
103  int ladder = theTrackerTopo_->tobRod(stDetId);
104  int type = 2*theTrackerTopo_->tobSide(stDetId)-3; // -1 for tilted-, 1 for tilted+, 3 for flat
105  double corr=0;
106 
107  if (type<3) // Only for tilted modules
108  {
109  corr = (barrelNTilt.at(layer)+1)/2.;
110  ladder = corr-(corr-ladder)*type; // Corrected ring number, bet 0 and barrelNTilt.at(layer), in ascending |z|
111  window = 2*(tiltedCut.at(layer)).at(ladder);
112  }
113  else // Classis barrel window otherwise
114  {
115  window = 2*barrelCut.at( layer );
116  }
117 
118  }
119  else if (stDetId.subdetId()==StripSubdetector::TID)
120  {
121  window = 2*(ringCut.at( theTrackerTopo_->tidWheel(stDetId))).at(theTrackerTopo_->tidRing(stDetId));
122  }
123 
125  if ( std::abs(dispI - offsetI) <= window )
126  {
127  aConfirmation = true;
128  aDisplacement = dispI;
129  anOffset = offsetI;
130  anROffset = static_cast<float>(offsetD);
131  anHardBend = this->degradeBend(isPS, window, (aDisplacement - anOffset)); // In strips units
132  }
133 
134 }
135 
136 
137 //--- Does the actual work of degrading the bend. (based on I.Tomalin's code)
138 template< >
140 
141  // Number of bits used to encoded bend output by FE electronics.
142  const unsigned int bitsPS_ = 3;
143  const unsigned int bits2S_ = 4;
144 
145  // Number of degraded bend values should correspond to 3 bits (PS modules) or 4 bits (2S modules),
146  // so measuring everything in half-strip units, max integer "window" size that can be encoded without
147  // compression given by 2*window+1 <= pow(2,B), where B is number of bits.
148  // Hence no compression required if window cut is abs(b) <= 3 (PS) or 7 (2S). Must introduce one merge for
149  // each 1 unit increase in "window" beyond this.
150 
151  // Bend is measured with granularity of 0.5 strips.
152  // Convert it to integer measured in half-strip units for this calculation!
153 
154  float degradedB;
155  unsigned int numBends = 2*window + 1;
156  unsigned int numAllowed = (psModule) ? pow(2, bitsPS_) : pow(2, bits2S_);
157 
158  // Existance of bend = 0 means can only use an odd number of groups.
159  numAllowed -= 1; // NumAllowed can be only based on 3 or 4 bits encoded bends, so 7 or 15 possible values
160  if (numBends <= numAllowed)
161  {
162  // Can output uncompressed bend info. (So if window is lower or equal than 1.5 in PS, and 3.5 in 2S
163  degradedB = static_cast<double>(bend);
164  }
165  else // all other cases, need to compress
166  {
167  unsigned int inSmallGroup = numBends/numAllowed;
168  unsigned int numLargeGroups = numBends%numAllowed;
169  unsigned int inLargeGroup = inSmallGroup + 1;
170  unsigned int numSmallGroups = numAllowed - numLargeGroups;
171 
172  std::vector<unsigned int> groups;
173 
174  // At the end we have
175  //
176  // numBends=inSmallGroup*numSmallGroups+inLargeGroup*numLargeGroups
177  // and
178  // numAllowed= numSmallGroups+numLargeGroups;
179  //
180  // Then you alternate large-small-large-small....large. In the middle, you
181  // put either large or small, depending if group size is odd or not
182 
183 
184  for (unsigned int i = 0; i < numLargeGroups/2; i++) groups.push_back(inLargeGroup);
185  for (unsigned int i = 0; i < numSmallGroups/2; i++) groups.push_back(inSmallGroup);
186 
187  // Only one of numLargeGroups & numSmallGroups can be odd, since numAllowed is odd.
188  // And whichever one is odd is associated to a group with an odd number of elements since numBends is odd,
189  if (numLargeGroups%2 == 1 && inLargeGroup%2 == 1)
190  {
191  groups.push_back(inLargeGroup);
192  } else if (numSmallGroups%2 == 1 && inSmallGroup%2 == 1) {
193  groups.push_back(inSmallGroup);
194  } else {
195  throw cms::Exception("DegradeBend: logic error with odd numbers");
196  }
197 
198  for (unsigned int i = 0; i < numSmallGroups/2; i++) groups.push_back(inSmallGroup);
199  for (unsigned int i = 0; i < numLargeGroups/2; i++) groups.push_back(inLargeGroup);
200 
201  degradedB = 999;
202  int iUp = -static_cast<int>(window) - 1; // Start with the minimal possible bend -1
203  int iDown;
204 
205  for (unsigned int& inGroup: groups)
206  {
207  iUp += inGroup;
208  iDown = iUp - inGroup + 1;
209  if (bend <= iUp && bend >= iDown)
210  {
211  degradedB = 0.5*(iUp + iDown);
212  }
213  }
214  if (degradedB == 999) throw cms::Exception("DegradeStubResolution: error in the group creation, method has been called with wrong inputs");
215  }
216 
217  // This is degraded bend in full strip units (neglecting bend sign).
218  return static_cast<float>(degradedB)/2.;
219 
220 
221 }
222 
223 //--- Check for mistakes.
dbl * delta
Definition: mlp_gen.cc:36
void PatternHitCorrelation(bool &aConfirmation, int &aDisplacement, int &anOffset, float &anROffset, float &anHardBend, const TTStub< T > &aTTStub) const override
Matching operations.
type
Definition: HCALResponse.h:21
virtual int nrows() const =0
float alpha
Definition: AMPTWrapper.h:95
T y() const
Definition: PV2DBase.h:46
static const double Z0
T perp() const
Definition: PV3DBase.h:72
float degradeBend(bool psModule, int window, int bend) const
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
virtual std::pair< float, float > pitch() const =0
DetId getDetId() const
Detector element.
Definition: TTStub.h:40
const Surface::PositionType & position() const
The position (origin of the R.F.)
Definition: GeomDet.h:48
T sqrt(T t)
Definition: SSEVec.h:18
T z() const
Definition: PV3DBase.h:64
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
def window(xmin, xmax, ymin, ymax, x=0, y=0, width=100, height=100, xlogbase=None, ylogbase=None, minusInfinity=-1000, flipx=False, flipy=True)
Definition: svgfig.py:643
Class to store the L1 Track Trigger stubs.
Definition: TTStub.h:22
JetCorrectorParameters corr
Definition: classes.h:5
Definition: DetId.h:18
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
virtual int ncolumns() const =0
T x() const
Definition: PV2DBase.h:45
const edm::Ref< edmNew::DetSetVector< TTCluster< T > >, TTCluster< T > > & getClusterRef(unsigned int hitIdentifier) const
Clusters composing the Stub.
Definition: TTStub.h:116
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40