CMS 3D CMS Logo

TrackerTreeGenerator.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: TrackerTreeGenerator
4 // Class: TrackerTreeGenerator
5 //
11 //
12 // Original Author: Johannes Hauk
13 // Created: Fri Jan 16 14:09:52 CET 2009
14 // Modified by: Gregor Mittag (DESY)
15 //
16 //
17 //
18 
19 
20 // system include files
21 #include <memory>
22 
23 // user include files
32 
36 
45 
56 
59 
60 #include "TTree.h"
61 //
62 // class decleration
63 //
64 
65 class TrackerTreeGenerator : public edm::one::EDAnalyzer<edm::one::SharedResources> {
66 public:
67  explicit TrackerTreeGenerator(const edm::ParameterSet&);
68  ~TrackerTreeGenerator() override = default;
69 
70 private:
71  void beginJob() override;
72  void analyze(const edm::Event&, const edm::EventSetup&) override;
73  void endJob() override;
74 
75  // ----------member data ---------------------------
76 
78  std::vector<TrackerTreeVariables> vTkTreeVar_;
80 };
81 
82 //
83 // constants, enums and typedefs
84 //
85 
86 //
87 // static data member definitions
88 //
89 
90 //
91 // constructors and destructor
92 //
94  createEntryForDoubleSidedModule_(config.getParameter<bool>("createEntryForDoubleSidedModule")),
95  config_(config)
96 {
97  usesResource(TFileService::kSharedResource);
98 }
99 
100 
101 //
102 // member functions
103 //
104 
105 // ------------ method called to for each event ------------
106 void
108 {
109  //iSetup.get<TrackerDigiGeometryRecord>().get(tkGeom);
110  // now try to take directly the ideal geometry independent of used geometry in Global Tag
111  edm::ESHandle<GeometricDet> geometricDet;
112  iSetup.get<IdealGeometryRecord>().get(geometricDet);
113 
114  //Retrieve tracker topology from geometry
115  edm::ESHandle<TrackerTopology> tTopoHandle;
116  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
117  const TrackerTopology* const tTopo = tTopoHandle.product();
118 
120  iSetup.get<PTrackerParametersRcd>().get(ptp);
121  TrackerGeomBuilderFromGeometricDet trackerBuilder;
122  const TrackerGeometry* tkGeom = trackerBuilder.build(&(*geometricDet), *ptp, tTopo);
123  AlignableTracker alignableTracker{tkGeom, tTopo};
124  const auto& ns = alignableTracker.trackerNameSpace();
125 
126  edm::LogInfo("TrackerTreeGenerator")
127  << "@SUB=TrackerTreeGenerator::analyze"
128  << "There are " << tkGeom->detIds().size()
129  << " dets and "<<tkGeom->detUnitIds().size()
130  <<" detUnits in the Geometry Record";
131 
133  edm::LogInfo("TrackerTreeGenerator")
134  << "@SUB=TrackerTreeGenerator::analyze"
135  << "Create entry for each module AND one entry for virtual "
136  << "double-sided module in addition";
137  } else {
138  edm::LogInfo("TrackerTreeGenerator")
139  << "@SUB=TrackerTreeGenerator::analyze"
140  << "Create one entry for each physical module, do NOT create additional "
141  << "entry for virtual double-sided module";
142  }
143 
144  for (const auto& detId: tkGeom->detIds()){
145 
146  const GeomDet& geomDet = *tkGeom->idToDet(detId);
147  const Surface& surface = geomDet.surface();
148 
149  TrackerTreeVariables tkTreeVar;
150  const auto rawId = detId.rawId();
151  tkTreeVar.rawId = rawId;
152  tkTreeVar.subdetId = detId.subdetId();
153 
154  switch (tkTreeVar.subdetId) {
156  tkTreeVar.layer = tTopo->pxbLayer(detId);
157  tkTreeVar.half = ns.tpb().halfBarrelNumber(rawId);
158  tkTreeVar.rod = tTopo->pxbLadder(detId); // ... so, ladder is not per halfBarrel-Layer, but per barrel-layer!
159  tkTreeVar.module = tTopo->pxbModule(detId);
160  break;
162  tkTreeVar.layer = tTopo->pxfDisk(detId);
163  tkTreeVar.side = tTopo->pxfSide(detId);
164  tkTreeVar.half = ns.tpe().halfCylinderNumber(rawId);
165  tkTreeVar.blade = tTopo->pxfBlade(detId);
166  tkTreeVar.panel = tTopo->pxfPanel(detId);
167  tkTreeVar.module = tTopo->pxfModule(detId);
168  break;
170  tkTreeVar.layer = tTopo->tibLayer(detId);
171  tkTreeVar.side = tTopo->tibStringInfo(detId)[0];
172  tkTreeVar.half = ns.tib().halfShellNumber(rawId);
173  tkTreeVar.rod = tTopo->tibStringInfo(detId)[2];
174  tkTreeVar.outerInner = tTopo->tibStringInfo(detId)[1];
175  tkTreeVar.module = tTopo->tibModule(detId);
176  tkTreeVar.isDoubleSide = tTopo->tibIsDoubleSide(detId);
177  tkTreeVar.isRPhi = tTopo->tibIsRPhi(detId);
178  tkTreeVar.isStereo = tTopo->tibIsStereo(detId);
179  break;
181  tkTreeVar.layer = tTopo->tidWheel(detId);
182  tkTreeVar.side = tTopo->tidSide(detId);
183  tkTreeVar.ring = tTopo->tidRing(detId);
184  tkTreeVar.outerInner = tTopo->tidModuleInfo(detId)[0];
185  tkTreeVar.module = tTopo->tidModuleInfo(detId)[1];
186  tkTreeVar.isDoubleSide = tTopo->tidIsDoubleSide(detId);
187  tkTreeVar.isRPhi = tTopo->tidIsRPhi(detId);
188  tkTreeVar.isStereo = tTopo->tidIsStereo(detId);
189  break;
191  tkTreeVar.layer = tTopo->tobLayer(detId);
192  tkTreeVar.side = tTopo->tobRodInfo(detId)[0];
193  tkTreeVar.rod = tTopo->tobRodInfo(detId)[1];
194  tkTreeVar.module = tTopo->tobModule(detId);
195  tkTreeVar.isDoubleSide = tTopo->tobIsDoubleSide(detId);
196  tkTreeVar.isRPhi = tTopo->tobIsRPhi(detId);
197  tkTreeVar.isStereo = tTopo->tobIsStereo(detId);
198  break;
200  tkTreeVar.layer = tTopo->tecWheel(detId);
201  tkTreeVar.side = tTopo->tecSide(detId);
202  tkTreeVar.ring = tTopo->tecRing(detId);
203  tkTreeVar.petal = tTopo->tecPetalInfo(detId)[1];
204  tkTreeVar.outerInner = tTopo->tecPetalInfo(detId)[0];
205  tkTreeVar.module = tTopo->tecModule(detId);
206  tkTreeVar.isDoubleSide = tTopo->tecIsDoubleSide(detId);
207  tkTreeVar.isRPhi = tTopo->tecIsRPhi(detId);
208  tkTreeVar.isStereo = tTopo->tecIsStereo(detId);
209  break;
210  }
211 
212 
213  LocalPoint lPModule(0.,0.,0.),
214  lUDirection(1.,0.,0.),
215  lVDirection(0.,1.,0.),
216  lWDirection(0.,0.,1.);
217  GlobalPoint gPModule = surface.toGlobal(lPModule),
218  gUDirection = surface.toGlobal(lUDirection),
219  gVDirection = surface.toGlobal(lVDirection),
220  gWDirection = surface.toGlobal(lWDirection);
221  double dR(999.), dPhi(999.), dZ(999.);
222  switch (tkTreeVar.subdetId) {
226  dR = gWDirection.perp() - gPModule.perp();
227  dPhi = deltaPhi(gUDirection.barePhi(),gPModule.barePhi());
228  dZ = gVDirection.z() - gPModule.z();
229  tkTreeVar.uDirection = dPhi>0. ? 1 : -1;
230  tkTreeVar.vDirection = dZ>0. ? 1 : -1;
231  tkTreeVar.wDirection = dR>0. ? 1 : -1;
232  break;
234  dR = gUDirection.perp() - gPModule.perp();
235  dPhi = deltaPhi(gVDirection.barePhi(),gPModule.barePhi());
236  dZ = gWDirection.z() - gPModule.z();
237  tkTreeVar.uDirection = dR>0. ? 1 : -1;
238  tkTreeVar.vDirection = dPhi>0. ? 1 : -1;
239  tkTreeVar.wDirection = dZ>0. ? 1 : -1;
240  break;
243  dR = gVDirection.perp() - gPModule.perp();
244  dPhi = deltaPhi(gUDirection.barePhi(),gPModule.barePhi());
245  dZ = gWDirection.z() - gPModule.z();
246  tkTreeVar.uDirection = dPhi>0. ? 1 : -1;
247  tkTreeVar.vDirection = dR>0. ? 1 : -1;
248  tkTreeVar.wDirection = dZ>0. ? 1 : -1;
249  break;
250  }
251  tkTreeVar.posR = gPModule.perp();
252  tkTreeVar.posPhi = gPModule.barePhi(); // = gPModule.barePhi().degrees();
253  tkTreeVar.posEta = gPModule.eta();
254  tkTreeVar.posX = gPModule.x();
255  tkTreeVar.posY = gPModule.y();
256  tkTreeVar.posZ = gPModule.z();
257 
258 
259  if(auto stripGeomDetUnit = dynamic_cast<const StripGeomDetUnit*>(&geomDet)){ //is it a single physical module?
260  switch (tkTreeVar.subdetId) {
265  auto& topol =
266  dynamic_cast<const StripTopology&>(stripGeomDetUnit->specificTopology());
267  tkTreeVar.nStrips = topol.nstrips();
268  break;
269  }
270  }
271 
272 
274  // do so only for individual modules and not also one entry for the combined doubleSided Module
275  if (tkTreeVar.isDoubleSide) continue;
276  }
277  vTkTreeVar_.push_back(tkTreeVar);
278  }
279 
280 }
281 
282 
283 // ------------ method called once each job just before starting event loop ------------
284 void
286 {
287 }
288 
289 
290 // ------------ method called once each job just after ending the event loop ------------
291 void
293  UInt_t rawId(999), subdetId(999), layer(999), side(999), half(999), rod(999),
294  ring(999), petal(999), blade(999), panel(999), outerInner(999),
295  module(999), nStrips(999);
296  Bool_t isDoubleSide(false), isRPhi(false), isStereo(false);
297  Int_t uDirection(999), vDirection(999), wDirection(999);
298  Float_t posR(999.F), posPhi(999.F), posEta(999.F),
299  posX(999.F), posY(999.F), posZ(999.F);
300 
302  TFileDirectory treeDir = fileService->mkdir("TrackerTree");
303  auto trackerTree{treeDir.make<TTree>("TrackerTree",
304  "IDs of all modules (ideal geometry)")};
305  trackerTree->Branch("RawId", &rawId, "RawId/i");
306  trackerTree->Branch("SubdetId", &subdetId, "SubdetId/i");
307  trackerTree->Branch("Layer", &layer, "Layer/i"); // Barrel: Layer, Forward: Disk
308  trackerTree->Branch("Side", &side, "Side/i"); // Rod/Ring in +z or -z
309  trackerTree->Branch("Half", &half, "Half/i"); // PXB: HalfBarrel, PXF: HalfCylinder, TIB: HalfShell
310  trackerTree->Branch("Rod", &rod, "Rod/i"); // Barrel (Ladder or String or Rod)
311  trackerTree->Branch("Ring", &ring, "Ring/i"); // Forward
312  trackerTree->Branch("Petal", &petal, "Petal/i"); // TEC
313  trackerTree->Branch("Blade", &blade, "Blade/i"); // PXF
314  trackerTree->Branch("Panel", &panel, "Panel/i"); // PXF
315  trackerTree->Branch("OuterInner", &outerInner, "OuterInner/i"); // front/back String,Ring,Petal
316  trackerTree->Branch("Module", &module, "Module/i"); // Module ID
317  trackerTree->Branch("NStrips", &nStrips, "NStrips/i");
318  trackerTree->Branch("IsDoubleSide", &isDoubleSide, "IsDoubleSide/O");
319  trackerTree->Branch("IsRPhi", &isRPhi, "IsRPhi/O");
320  trackerTree->Branch("IsStereo", &isStereo, "IsStereo/O");
321  trackerTree->Branch("UDirection", &uDirection, "UDirection/I");
322  trackerTree->Branch("VDirection", &vDirection, "VDirection/I");
323  trackerTree->Branch("WDirection", &wDirection, "WDirection/I");
324  trackerTree->Branch("PosR", &posR, "PosR/F");
325  trackerTree->Branch("PosPhi", &posPhi, "PosPhi/F");
326  trackerTree->Branch("PosEta", &posEta, "PosEta/F");
327  trackerTree->Branch("PosX", &posX, "PosX/F");
328  trackerTree->Branch("PosY", &posY, "PosY/F");
329  trackerTree->Branch("PosZ", &posZ, "PosZ/F");
330 
331  for(const auto& iTree: vTkTreeVar_){
332  rawId = iTree.rawId;
333  subdetId = iTree.subdetId;
334  layer = iTree.layer;
335  side = iTree.side;
336  half = iTree.half;
337  rod = iTree.rod;
338  ring = iTree.ring;
339  petal = iTree.petal;
340  blade = iTree.blade;
341  panel = iTree.panel;
342  outerInner = iTree.outerInner;
343  module = iTree.module;
344  nStrips = iTree.nStrips;
345  isDoubleSide = iTree.isDoubleSide;
346  isRPhi = iTree.isRPhi;
347  isStereo = iTree.isStereo;
348  uDirection = iTree.uDirection;
349  vDirection = iTree.vDirection;
350  wDirection = iTree.wDirection;
351  posR = iTree.posR;
352  posPhi = iTree.posPhi;
353  posEta = iTree.posEta;
354  posX = iTree.posX;
355  posY = iTree.posY;
356  posZ = iTree.posZ;
357 
358  trackerTree->Fill();
359  }
360  edm::LogInfo("TrackerTreeGenerator")
361  << "@SUB=TrackerTreeGenerator::endJob"
362  << "TrackerTree contains "<< vTkTreeVar_.size() <<" entries overall";
363 }
364 
365 
366 //define this as a plug-in
const DetIdContainer & detUnitIds() const override
Returm a vector of all GeomDetUnit DetIds.
static const std::string kSharedResource
Definition: TFileService.h:76
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:106
T perp() const
Definition: PV3DBase.h:72
TrackerTreeGenerator(const edm::ParameterSet &)
~TrackerTreeGenerator() override=default
module()
Definition: vlib.cc:994
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
T y() const
Definition: PV3DBase.h:63
TrackerGeometry * build(const GeometricDet *gd, const PTrackerParameters &ptp, const TrackerTopology *tTopo)
Definition: config.py:1
edm::ParameterSet config_
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
void analyze(const edm::Event &, const edm::EventSetup &) override
T barePhi() const
Definition: PV3DBase.h:68
int iEvent
Definition: GenABIO.cc:230
T z() const
Definition: PV3DBase.h:64
const DetIdContainer & detIds() const override
Returm a vector of all GeomDet DetIds (including those of GeomDetUnits)
T * make(const Args &...args) const
make new ROOT object
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
Definition: TFileService.h:69
edm::Service< TFileService > fileService
T eta() const
Definition: PV3DBase.h:76
T get() const
Definition: EventSetup.h:68
const bool createEntryForDoubleSidedModule_
const TrackerGeomDet * idToDet(DetId) const override
std::vector< TrackerTreeVariables > vTkTreeVar_
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:281
T x() const
Definition: PV3DBase.h:62
T const * product() const
Definition: ESHandle.h:84
Definition: vlib.h:208