CMS 3D CMS Logo

TrackerGeomBuilderFromGeometricDet.cc
Go to the documentation of this file.
19 
20 #include <cfloat>
21 #include <cassert>
22 using std::vector;
23 using std::string;
24 
25 namespace {
26  void verifyDUinTG(TrackerGeometry const & tg) {
27  int off=0; int end=0;
28  for ( int i=1; i!=7; i++) {
29  auto det = GeomDetEnumerators::tkDetEnum[i];
30  off = tg.offsetDU(det);
31  end = tg.endsetDU(det); assert(end>=off); // allow empty subdetectors. Needed for upgrade
32  for (int j=off; j!=end; ++j) {
33  assert(tg.detUnits()[j]->geographicalId().subdetId()==i);
34  assert(GeomDetEnumerators::subDetGeom[tg.detUnits()[j]->subDetector()]==det);
35  assert(tg.detUnits()[j]->index()==j);
36  }
37  }
38  }
39 }
40 
43 {
44  int BIG_PIX_PER_ROC_X = ptp.vpars[2];
45  int BIG_PIX_PER_ROC_Y = ptp.vpars[3];
46 
47  thePixelDetTypeMap.clear();
48  theStripDetTypeMap.clear();
49 
51  std::vector<const GeometricDet*> comp;
52  gd->deepComponents(comp);
53 
54  if(tTopo) theTopo = tTopo;
55 
56  //define a vector which associate to the detid subdetector index -1 (from 0 to 5) the GeometridDet enumerator to be able to know which type of subdetector it is
57 
58  std::vector<GeometricDet::GDEnumType> gdsubdetmap(6,GeometricDet::unknown); // hardcoded "6" should not be a surprise...
60 
61  LogDebug("SubDetectorGeometricDetType") << "GeometriDet enumerator values of the subdetectors";
62  for(unsigned int i=0;i<subdetgd.size();++i) {
63  assert(subdetgd[i]->geographicalId().subdetId()>0 && subdetgd[i]->geographicalId().subdetId()<7);
64  gdsubdetmap[subdetgd[i]->geographicalId().subdetId()-1]= subdetgd[i]->type();
65  LogTrace("SubDetectorGeometricDetType") << "subdet " << i
66  << " type " << subdetgd[i]->type()
67  << " detid " << subdetgd[i]->geographicalId().rawId()
68  << " subdetid " << subdetgd[i]->geographicalId().subdetId();
69  }
70 
71  std::vector<const GeometricDet*> dets[6];
72  std::vector<const GeometricDet*> & pixB = dets[0]; pixB.reserve(comp.size());
73  std::vector<const GeometricDet*> & pixF = dets[1]; pixF.reserve(comp.size());
74  std::vector<const GeometricDet*> & tib = dets[2]; tib.reserve(comp.size());
75  std::vector<const GeometricDet*> & tid = dets[3]; tid.reserve(comp.size());
76  std::vector<const GeometricDet*> & tob = dets[4]; tob.reserve(comp.size());
77  std::vector<const GeometricDet*> & tec = dets[5]; tec.reserve(comp.size());
78 
79  for(auto & i : comp)
80  dets[i->geographicalID().subdetId()-1].emplace_back(i);
81 
82  //loop on all the six elements of dets and firstly check if they are from pixel-like detector and call buildPixel, then loop again and check if they are strip and call buildSilicon. "unknown" can be filled either way but the vector of GeometricDet must be empty !!
83  // this order is VERY IMPORTANT!!!!! For the moment I (AndreaV) understand that some pieces of code rely on pixel-like being before strip-like
84 
85  // now building the Pixel-like subdetectors
86  for(unsigned int i=0;i<6;++i) {
87  if(gdsubdetmap[i] == GeometricDet::PixelBarrel)
89  false,
90  BIG_PIX_PER_ROC_X,
91  BIG_PIX_PER_ROC_Y);
92  if(gdsubdetmap[i] == GeometricDet::PixelPhase1Barrel)
94  false,
95  BIG_PIX_PER_ROC_X,
96  BIG_PIX_PER_ROC_Y);
97  // Phase2 case
98  if(gdsubdetmap[i] == GeometricDet::PixelPhase2Barrel)
100  true,
101  BIG_PIX_PER_ROC_X,
102  BIG_PIX_PER_ROC_Y);
103  //
104  if(gdsubdetmap[i] == GeometricDet::PixelEndCap)
106  false,
107  BIG_PIX_PER_ROC_X,
108  BIG_PIX_PER_ROC_Y);
109  if(gdsubdetmap[i] == GeometricDet::PixelPhase1EndCap)
111  false,
112  BIG_PIX_PER_ROC_X,
113  BIG_PIX_PER_ROC_Y);
114  if(gdsubdetmap[i] == GeometricDet::PixelPhase2EndCap)
116  true,
117  BIG_PIX_PER_ROC_X,
118  BIG_PIX_PER_ROC_Y);
119  if(gdsubdetmap[i] == GeometricDet::OTPhase2Barrel)
121  true,
122  BIG_PIX_PER_ROC_X,
123  BIG_PIX_PER_ROC_Y);
124  if(gdsubdetmap[i] == GeometricDet::OTPhase2EndCap)
126  true,
127  BIG_PIX_PER_ROC_X,
128  BIG_PIX_PER_ROC_Y);
129  }
130  //now building Strips
131  for(unsigned int i=0;i<6;++i) {
132  if(gdsubdetmap[i] == GeometricDet::TIB) buildSilicon(dets[i],tracker,GeomDetEnumerators::SubDetector::TIB, "barrel");
133  if(gdsubdetmap[i] == GeometricDet::TID) buildSilicon(dets[i],tracker,GeomDetEnumerators::SubDetector::TID, "endcap");
134  if(gdsubdetmap[i] == GeometricDet::TOB) buildSilicon(dets[i],tracker,GeomDetEnumerators::SubDetector::TOB, "barrel");
135  if(gdsubdetmap[i] == GeometricDet::TEC) buildSilicon(dets[i],tracker,GeomDetEnumerators::SubDetector::TEC, "endcap");
136  }
137  // and finally the "empty" subdetectors (maybe it is not needed)
138  for(unsigned int i=0;i<6;++i) {
139  if(gdsubdetmap[i] == GeometricDet::unknown) {
140  if(!dets[i].empty()) throw cms::Exception("NotEmptyUnknownSubDet") << "Subdetector " << i+1 << " is unknown but it is not empty: " << dets[i].size();
141  buildSilicon(dets[i],tracker,GeomDetEnumerators::tkDetEnum[i+1], "barrel"); // "barrel" is used but it is irrelevant
142  }
143  }
144  buildGeomDet(tracker);//"GeomDet"
145 
146  verifyDUinTG(*tracker);
147 
148  return tracker;
149 }
150 
151 void TrackerGeomBuilderFromGeometricDet::buildPixel(std::vector<const GeometricDet*> const & gdv,
154  bool upgradeGeometry,
155  int BIG_PIX_PER_ROC_X, // in x direction, rows. BIG_PIX_PER_ROC_X = 0 for SLHC
156  int BIG_PIX_PER_ROC_Y) // in y direction, cols. BIG_PIX_PER_ROC_Y = 0 for SLHC
157 {
158  LogDebug("BuildingGeomDetUnits") << " Pixel type. Size of vector: " << gdv.size()
159  << " GeomDetType subdetector: " << det
160  << " logical subdetector: " << GeomDetEnumerators::subDetGeom[det]
161  << " big pix per ROC x: " << BIG_PIX_PER_ROC_X << " y: " << BIG_PIX_PER_ROC_Y
162  << " is upgrade: " << upgradeGeometry;
163 
165 
166  for(auto i : gdv){
167 
168  std::string const & detName = i->name().fullname();
169  if (thePixelDetTypeMap.find(detName) == thePixelDetTypeMap.end()) {
170  std::unique_ptr<const Bounds> bounds(i->bounds());
171 
172  PixelTopology* t =
173  PixelTopologyBuilder().build(&*bounds,
174  upgradeGeometry,
175  i->pixROCRows(),
176  i->pixROCCols(),
177  BIG_PIX_PER_ROC_X,
178  BIG_PIX_PER_ROC_Y,
179  i->pixROCx(), i->pixROCy());
180 
181  thePixelDetTypeMap[detName] = new PixelGeomDetType(t,detName,det);
182  tracker->addType(thePixelDetTypeMap[detName]);
183  }
184 
186  GeomDetUnit* temp = new PixelGeomDetUnit(&(*plane),thePixelDetTypeMap[detName],i->geographicalID());
187 
188  tracker->addDetUnit(temp);
189  tracker->addDetUnitId(i->geographicalID());
190  }
192 }
193 
194 void TrackerGeomBuilderFromGeometricDet::buildSilicon(std::vector<const GeometricDet*> const & gdv,
197  const std::string& part)
198 {
199  LogDebug("BuildingGeomDetUnits") << " Strip type. Size of vector: " << gdv.size()
200  << " GeomDetType subdetector: " << det
201  << " logical subdetector: " << GeomDetEnumerators::subDetGeom[det]
202  << " part " << part;
203 
205 
206  for(auto i : gdv){
207 
208  std::string const & detName = i->name().fullname();
209  if (theStripDetTypeMap.find(detName) == theStripDetTypeMap.end()) {
210  std::unique_ptr<const Bounds> bounds(i->bounds());
211  StripTopology* t =
212  StripTopologyBuilder().build(&*bounds,
213  i->siliconAPVNum(),
214  part);
215  theStripDetTypeMap[detName] = new StripGeomDetType( t,detName,det,
216  i->stereo());
217  tracker->addType(theStripDetTypeMap[detName]);
218  }
219 
220  double scale = (theTopo->partnerDetId(i->geographicalID())) ? 0.5 : 1.0 ;
221 
223  GeomDetUnit* temp = new StripGeomDetUnit(&(*plane), theStripDetTypeMap[detName],i->geographicalID());
224 
225  tracker->addDetUnit(temp);
226  tracker->addDetUnitId(i->geographicalID());
227  }
229 
230 }
231 
232 
234 
235  PlaneBuilderForGluedDet gluedplaneBuilder;
236  auto const & gdu = tracker->detUnits();
237  auto const & gduId = tracker->detUnitIds();
238 
239  for(u_int32_t i=0;i<gdu.size();i++){
240 
241  tracker->addDet(gdu[i]);
242  tracker->addDetId(gduId[i]);
243  string gduTypeName = gdu[i]->type().name();
244 
245  //this step is time consuming >> TO FIX with a MAP?
246  if( (gduTypeName.find("Ster")!=std::string::npos ||
247  gduTypeName.find("Lower")!=std::string::npos) &&
248  (theTopo->glued(gduId[i])!=0 || theTopo->stack(gduId[i])!=0 )) {
249 
250 
251  int partner_pos=-1;
252  for(u_int32_t jj=0;jj<gduId.size();jj++){
253  if(theTopo->partnerDetId(gduId[i]) == gduId[jj]) {
254  partner_pos=jj;
255  break;
256  }
257  }
258  if(partner_pos==-1){
259  throw cms::Exception("Configuration") <<"Module Type is Stereo or Lower but no partner detector found \n"
260  <<"There is a problem on Tracker geometry configuration\n";
261  }
262 
263  const GeomDetUnit* dus = gdu[i];
264  const GeomDetUnit* dum = gdu[partner_pos];
265  std::vector<const GeomDetUnit *> composed(2);
266  composed[0]=dum;
267  composed[1]=dus;
268  DetId composedDetId;
269  if(gduTypeName.find("Ster")!=std::string::npos){
270 
271  PlaneBuilderForGluedDet::ResultType plane = gluedplaneBuilder.plane(composed);
272  composedDetId = theTopo->glued(gduId[i]);
273  GluedGeomDet* gluedDet = new GluedGeomDet(&(*plane),dum,dus,composedDetId);
274  tracker->addDet((GeomDet*) gluedDet);
275  tracker->addDetId(composedDetId);
276 
277  } else if (gduTypeName.find("Lower")!=std::string::npos){
278 
279  //FIXME::ERICA: the plane builder is built in the middle...
280  PlaneBuilderForGluedDet::ResultType plane = gluedplaneBuilder.plane(composed);
281  composedDetId = theTopo->stack(gduId[i]);
282  StackGeomDet* stackDet = new StackGeomDet(&(*plane),dum,dus,composedDetId);
283  tracker->addDet((GeomDet*) stackDet);
284  tracker->addDetId(composedDetId);
285 
286  }
287 
288  }
289 
290  }
291 }
292 
295  double scale) const
296 {
297  PlaneBuilderFromGeometricDet planeBuilder;
298  PlaneBuilderFromGeometricDet::ResultType plane = planeBuilder.plane(gd);
299  //
300  // set medium properties (if defined)
301  //
302  plane->setMediumProperties(MediumProperties(gd->radLength()*scale,gd->xi()*scale));
303 
304  return plane;
305 }
#define LogDebug(id)
const DetIdContainer & detUnitIds() const override
Returm a vector of all GeomDetUnit DetIds.
std::vector< int > vpars
double radLength() const
Definition: GeometricDet.h:253
void addDet(GeomDet const *p)
void setEndsetDU(SubDetector sid)
PixelTopology * build(const Bounds *bounds, bool upgradeGeometry, int ROWS_PER_ROC, int COLS_PER_ROC, int BIG_PIX_PER_ROC_X, int BIG_PIX_PER_ROC_Y, int ROCS_X, int ROCS_Y)
TrackerGeometry * build(const GeometricDet *gd, const PTrackerParameters &ptp, const TrackerTopology *tTopo)
void buildPixel(std::vector< const GeometricDet * > const &, TrackerGeometry *, GeomDetType::SubDetector det, bool upgradeGeometry, int BIG_PIX_PER_ROC_X, int BIG_PIX_PER_ROC_Y)
ResultType plane(const std::vector< const GeomDetUnit * > &dets) const
DetId partnerDetId(const DetId &id) const
ConstGeometricDetContainer & components()
Definition: GeometricDet.h:176
void addDetId(DetId p)
void addDetUnit(GeomDetUnit const *p)
unsigned int endsetDU(SubDetector sid) const
void setOffsetDU(SubDetector sid)
std::map< std::string, const StripGeomDetType * > theStripDetTypeMap
void buildSilicon(std::vector< const GeometricDet * > const &, TrackerGeometry *, GeomDetType::SubDetector det, const std::string &part)
PlaneBuilderFromGeometricDet::ResultType buildPlaneWithMaterial(const GeometricDet *gd, double scaleFactor=1.) const
void addType(GeomDetType const *p)
unsigned int offsetDU(SubDetector sid) const
ResultType plane(const GeometricDet *gd) const
SubDetector subDetGeom[21]
#define end
Definition: vmac.h:37
std::map< std::string, const PixelGeomDetType * > thePixelDetTypeMap
SubDetector tkDetEnum[8]
#define LogTrace(id)
std::vector< GeometricDet const * > ConstGeometricDetContainer
Definition: GeometricDet.h:36
Definition: DetId.h:18
double xi() const
Definition: GeometricDet.h:257
uint32_t stack(const DetId &id) const
part
Definition: HCALResponse.h:20
void addDetUnitId(DetId p)
ConstGeometricDetContainer deepComponents() const
uint32_t glued(const DetId &id) const
const DetUnitContainer & detUnits() const override
Returm a vector of all GeomDetUnit.
StripTopology * build(const Bounds *, double, const std::string &)