CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 // system include files
20 #include <memory>
21 
22 // user include files
31 
35 
44 
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 ---------------------------
80 
82  std::vector<TrackerTreeVariables> vTkTreeVar_;
84 };
85 
86 //
87 // constants, enums and typedefs
88 //
89 
90 //
91 // static data member definitions
92 //
93 
94 //
95 // constructors and destructor
96 //
98  : geomDetToken_(esConsumes()),
99  ptpToken_(esConsumes()),
100  ptitpToken_(esConsumes()),
101  topoToken_(esConsumes()),
102  createEntryForDoubleSidedModule_(config.getParameter<bool>("createEntryForDoubleSidedModule")),
103  config_(config) {
104  usesResource(TFileService::kSharedResource);
105 }
106 
107 //
108 // member functions
109 //
110 
111 // ------------ method called to for each event ------------
113  // now try to take directly the ideal geometry independent of used geometry in Global Tag
114  const GeometricDet* geometricDet = &iSetup.getData(geomDetToken_);
115  const PTrackerParameters& ptp = iSetup.getData(ptpToken_);
117  const TrackerTopology* tTopo = &iSetup.getData(topoToken_);
118 
119  TrackerGeomBuilderFromGeometricDet trackerBuilder;
120  const TrackerGeometry* tkGeom = trackerBuilder.build(geometricDet, ptitp, ptp, tTopo);
121  AlignableTracker alignableTracker{tkGeom, tTopo};
122  const auto& ns = alignableTracker.trackerNameSpace();
123 
124  edm::LogInfo("TrackerTreeGenerator") << "@SUB=TrackerTreeGenerator::analyze"
125  << "There are " << tkGeom->detIds().size() << " dets and "
126  << tkGeom->detUnitIds().size() << " detUnits in the Geometry Record";
127 
129  edm::LogInfo("TrackerTreeGenerator") << "@SUB=TrackerTreeGenerator::analyze"
130  << "Create entry for each module AND one entry for virtual "
131  << "double-sided module in addition";
132  } else {
133  edm::LogInfo("TrackerTreeGenerator") << "@SUB=TrackerTreeGenerator::analyze"
134  << "Create one entry for each physical module, do NOT create additional "
135  << "entry for virtual double-sided module";
136  }
137 
138  for (const auto& detId : tkGeom->detIds()) {
139  const GeomDet& geomDet = *tkGeom->idToDet(detId);
140  const Surface& surface = geomDet.surface();
141 
142  TrackerTreeVariables tkTreeVar;
143  const auto rawId = detId.rawId();
144  tkTreeVar.rawId = rawId;
145  tkTreeVar.subdetId = detId.subdetId();
146 
147  switch (tkTreeVar.subdetId) {
149  tkTreeVar.layer = tTopo->pxbLayer(detId);
150  tkTreeVar.half = ns.tpb().halfBarrelNumber(rawId);
151  tkTreeVar.rod = tTopo->pxbLadder(detId); // ... so, ladder is not per halfBarrel-Layer, but per barrel-layer!
152  tkTreeVar.module = tTopo->pxbModule(detId);
153  break;
155  tkTreeVar.layer = tTopo->pxfDisk(detId);
156  tkTreeVar.side = tTopo->pxfSide(detId);
157  tkTreeVar.half = ns.tpe().halfCylinderNumber(rawId);
158  tkTreeVar.blade = tTopo->pxfBlade(detId);
159  tkTreeVar.panel = tTopo->pxfPanel(detId);
160  tkTreeVar.module = tTopo->pxfModule(detId);
161  break;
163  tkTreeVar.layer = tTopo->tibLayer(detId);
164  tkTreeVar.side = tTopo->tibStringInfo(detId)[0];
165  tkTreeVar.half = ns.tib().halfShellNumber(rawId);
166  tkTreeVar.rod = tTopo->tibStringInfo(detId)[2];
167  tkTreeVar.outerInner = tTopo->tibStringInfo(detId)[1];
168  tkTreeVar.module = tTopo->tibModule(detId);
169  tkTreeVar.isDoubleSide = tTopo->tibIsDoubleSide(detId);
170  tkTreeVar.isRPhi = tTopo->tibIsRPhi(detId);
171  tkTreeVar.isStereo = tTopo->tibIsStereo(detId);
172  break;
174  tkTreeVar.layer = tTopo->tidWheel(detId);
175  tkTreeVar.side = tTopo->tidSide(detId);
176  tkTreeVar.ring = tTopo->tidRing(detId);
177  tkTreeVar.outerInner = tTopo->tidModuleInfo(detId)[0];
178  tkTreeVar.module = tTopo->tidModuleInfo(detId)[1];
179  tkTreeVar.isDoubleSide = tTopo->tidIsDoubleSide(detId);
180  tkTreeVar.isRPhi = tTopo->tidIsRPhi(detId);
181  tkTreeVar.isStereo = tTopo->tidIsStereo(detId);
182  break;
184  tkTreeVar.layer = tTopo->tobLayer(detId);
185  tkTreeVar.side = tTopo->tobRodInfo(detId)[0];
186  tkTreeVar.rod = tTopo->tobRodInfo(detId)[1];
187  tkTreeVar.module = tTopo->tobModule(detId);
188  tkTreeVar.isDoubleSide = tTopo->tobIsDoubleSide(detId);
189  tkTreeVar.isRPhi = tTopo->tobIsRPhi(detId);
190  tkTreeVar.isStereo = tTopo->tobIsStereo(detId);
191  break;
193  tkTreeVar.layer = tTopo->tecWheel(detId);
194  tkTreeVar.side = tTopo->tecSide(detId);
195  tkTreeVar.ring = tTopo->tecRing(detId);
196  tkTreeVar.petal = tTopo->tecPetalInfo(detId)[1];
197  tkTreeVar.outerInner = tTopo->tecPetalInfo(detId)[0];
198  tkTreeVar.module = tTopo->tecModule(detId);
199  tkTreeVar.isDoubleSide = tTopo->tecIsDoubleSide(detId);
200  tkTreeVar.isRPhi = tTopo->tecIsRPhi(detId);
201  tkTreeVar.isStereo = tTopo->tecIsStereo(detId);
202  break;
203  }
204 
205  LocalPoint lPModule(0., 0., 0.), lUDirection(1., 0., 0.), lVDirection(0., 1., 0.), lWDirection(0., 0., 1.);
206  GlobalPoint gPModule = surface.toGlobal(lPModule), gUDirection = surface.toGlobal(lUDirection),
207  gVDirection = surface.toGlobal(lVDirection), gWDirection = surface.toGlobal(lWDirection);
208  double dR(999.), dPhi(999.), dZ(999.);
209  switch (tkTreeVar.subdetId) {
213  dR = gWDirection.perp() - gPModule.perp();
214  dPhi = deltaPhi(gUDirection.barePhi(), gPModule.barePhi());
215  dZ = gVDirection.z() - gPModule.z();
216  tkTreeVar.uDirection = dPhi > 0. ? 1 : -1;
217  tkTreeVar.vDirection = dZ > 0. ? 1 : -1;
218  tkTreeVar.wDirection = dR > 0. ? 1 : -1;
219  break;
221  dR = gUDirection.perp() - gPModule.perp();
222  dPhi = deltaPhi(gVDirection.barePhi(), gPModule.barePhi());
223  dZ = gWDirection.z() - gPModule.z();
224  tkTreeVar.uDirection = dR > 0. ? 1 : -1;
225  tkTreeVar.vDirection = dPhi > 0. ? 1 : -1;
226  tkTreeVar.wDirection = dZ > 0. ? 1 : -1;
227  break;
230  dR = gVDirection.perp() - gPModule.perp();
231  dPhi = deltaPhi(gUDirection.barePhi(), gPModule.barePhi());
232  dZ = gWDirection.z() - gPModule.z();
233  tkTreeVar.uDirection = dPhi > 0. ? 1 : -1;
234  tkTreeVar.vDirection = dR > 0. ? 1 : -1;
235  tkTreeVar.wDirection = dZ > 0. ? 1 : -1;
236  break;
237  }
238  tkTreeVar.posR = gPModule.perp();
239  tkTreeVar.posPhi = gPModule.barePhi(); // = gPModule.barePhi().degrees();
240  tkTreeVar.posEta = gPModule.eta();
241  tkTreeVar.posX = gPModule.x();
242  tkTreeVar.posY = gPModule.y();
243  tkTreeVar.posZ = gPModule.z();
244 
245  if (auto stripGeomDetUnit = dynamic_cast<const StripGeomDetUnit*>(&geomDet)) { //is it a single physical module?
246  switch (tkTreeVar.subdetId) {
251  auto& topol = dynamic_cast<const StripTopology&>(stripGeomDetUnit->specificTopology());
252  tkTreeVar.nStrips = topol.nstrips();
253  break;
254  }
255  }
256 
258  // do so only for individual modules and not also one entry for the combined doubleSided Module
259  if (tkTreeVar.isDoubleSide)
260  continue;
261  }
262  vTkTreeVar_.push_back(tkTreeVar);
263  }
264 }
265 
266 // ------------ method called once each job just before starting event loop ------------
268 
269 // ------------ method called once each job just after ending the event loop ------------
271  UInt_t rawId(999), subdetId(999), layer(999), side(999), half(999), rod(999), ring(999), petal(999), blade(999),
272  panel(999), outerInner(999), module(999), nStrips(999);
273  Bool_t isDoubleSide(false), isRPhi(false), isStereo(false);
274  Int_t uDirection(999), vDirection(999), wDirection(999);
275  Float_t posR(999.F), posPhi(999.F), posEta(999.F), posX(999.F), posY(999.F), posZ(999.F);
276 
277  edm::Service<TFileService> fileService;
278  TFileDirectory treeDir = fileService->mkdir("TrackerTree");
279  auto trackerTree{treeDir.make<TTree>("TrackerTree", "IDs of all modules (ideal geometry)")};
280  trackerTree->Branch("RawId", &rawId, "RawId/i");
281  trackerTree->Branch("SubdetId", &subdetId, "SubdetId/i");
282  trackerTree->Branch("Layer", &layer, "Layer/i"); // Barrel: Layer, Forward: Disk
283  trackerTree->Branch("Side", &side, "Side/i"); // Rod/Ring in +z or -z
284  trackerTree->Branch("Half", &half, "Half/i"); // PXB: HalfBarrel, PXF: HalfCylinder, TIB: HalfShell
285  trackerTree->Branch("Rod", &rod, "Rod/i"); // Barrel (Ladder or String or Rod)
286  trackerTree->Branch("Ring", &ring, "Ring/i"); // Forward
287  trackerTree->Branch("Petal", &petal, "Petal/i"); // TEC
288  trackerTree->Branch("Blade", &blade, "Blade/i"); // PXF
289  trackerTree->Branch("Panel", &panel, "Panel/i"); // PXF
290  trackerTree->Branch("OuterInner", &outerInner, "OuterInner/i"); // front/back String,Ring,Petal
291  trackerTree->Branch("Module", &module, "Module/i"); // Module ID
292  trackerTree->Branch("NStrips", &nStrips, "NStrips/i");
293  trackerTree->Branch("IsDoubleSide", &isDoubleSide, "IsDoubleSide/O");
294  trackerTree->Branch("IsRPhi", &isRPhi, "IsRPhi/O");
295  trackerTree->Branch("IsStereo", &isStereo, "IsStereo/O");
296  trackerTree->Branch("UDirection", &uDirection, "UDirection/I");
297  trackerTree->Branch("VDirection", &vDirection, "VDirection/I");
298  trackerTree->Branch("WDirection", &wDirection, "WDirection/I");
299  trackerTree->Branch("PosR", &posR, "PosR/F");
300  trackerTree->Branch("PosPhi", &posPhi, "PosPhi/F");
301  trackerTree->Branch("PosEta", &posEta, "PosEta/F");
302  trackerTree->Branch("PosX", &posX, "PosX/F");
303  trackerTree->Branch("PosY", &posY, "PosY/F");
304  trackerTree->Branch("PosZ", &posZ, "PosZ/F");
305 
306  for (const auto& iTree : vTkTreeVar_) {
307  rawId = iTree.rawId;
308  subdetId = iTree.subdetId;
309  layer = iTree.layer;
310  side = iTree.side;
311  half = iTree.half;
312  rod = iTree.rod;
313  ring = iTree.ring;
314  petal = iTree.petal;
315  blade = iTree.blade;
316  panel = iTree.panel;
317  outerInner = iTree.outerInner;
318  module = iTree.module;
319  nStrips = iTree.nStrips;
320  isDoubleSide = iTree.isDoubleSide;
321  isRPhi = iTree.isRPhi;
322  isStereo = iTree.isStereo;
323  uDirection = iTree.uDirection;
324  vDirection = iTree.vDirection;
325  wDirection = iTree.wDirection;
326  posR = iTree.posR;
327  posPhi = iTree.posPhi;
328  posEta = iTree.posEta;
329  posX = iTree.posX;
330  posY = iTree.posY;
331  posZ = iTree.posZ;
332 
333  trackerTree->Fill();
334  }
335  edm::LogInfo("TrackerTreeGenerator") << "@SUB=TrackerTreeGenerator::endJob"
336  << "TrackerTree contains " << vTkTreeVar_.size() << " entries overall";
337 }
338 
339 //define this as a plug-in
static const std::string kSharedResource
Definition: TFileService.h:76
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:79
static constexpr auto TEC
bool tecIsDoubleSide(const DetId &id) const
bool tobIsDoubleSide(const DetId &id) const
const edm::ESGetToken< GeometricDet, IdealGeometryRecord > geomDetToken_
bool tibIsDoubleSide(const DetId &id) const
T perp() const
Definition: PV3DBase.h:69
unsigned int tibLayer(const DetId &id) const
unsigned int tidRing(const DetId &id) const
TrackerTreeGenerator(const edm::ParameterSet &)
~TrackerTreeGenerator() override=default
bool tobIsStereo(const DetId &id) const
std::vector< unsigned int > tidModuleInfo(const DetId &id) const
const DetIdContainer & detIds() const override
Returm a vector of all GeomDet DetIds (including those of GeomDetUnits)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
unsigned int pxfDisk(const DetId &id) const
TrackerGeometry * build(const GeometricDet *gd, const PTrackerAdditionalParametersPerDet *ptitp, const PTrackerParameters &ptp, const TrackerTopology *tTopo)
unsigned int tecRing(const DetId &id) const
ring id
unsigned int pxbLadder(const DetId &id) const
T y() const
Definition: PV3DBase.h:60
unsigned int tidWheel(const DetId &id) const
unsigned int pxbModule(const DetId &id) const
const edm::ESGetToken< PTrackerAdditionalParametersPerDet, PTrackerAdditionalParametersPerDetRcd > ptitpToken_
std::vector< unsigned int > tibStringInfo(const DetId &id) const
bool tobIsRPhi(const DetId &id) const
edm::ParameterSet config_
tuple nStrips
1.2 is to make the matching window safely the two nearest strips 0.35 is the size of an ME0 chamber i...
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
void analyze(const edm::Event &, const edm::EventSetup &) override
bool tidIsStereo(const DetId &id) const
constexpr std::array< uint8_t, layerIndexSize > layer
bool getData(T &iHolder) const
Definition: EventSetup.h:122
T barePhi() const
Definition: PV3DBase.h:65
bool tecIsStereo(const DetId &id) const
int iEvent
Definition: GenABIO.cc:224
std::vector< unsigned int > tecPetalInfo(const DetId &id) const
bool tibIsRPhi(const DetId &id) const
unsigned int tidSide(const DetId &id) const
std::vector< unsigned int > tobRodInfo(const DetId &id) const
const edm::ESGetToken< PTrackerParameters, PTrackerParametersRcd > ptpToken_
T z() const
Definition: PV3DBase.h:61
T * make(const Args &...args) const
make new ROOT object
static constexpr auto TOB
bool tecIsRPhi(const DetId &id) const
const TrackerGeomDet * idToDet(DetId) const override
unsigned int tibModule(const DetId &id) const
unsigned int pxfModule(const DetId &id) const
unsigned int pxbLayer(const DetId &id) const
unsigned int tecModule(const DetId &id) const
Log< level::Info, false > LogInfo
bool tidIsRPhi(const DetId &id) const
static constexpr auto TIB
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
Definition: TFileService.h:69
bool tibIsStereo(const DetId &id) const
bool tidIsDoubleSide(const DetId &id) const
unsigned int tobModule(const DetId &id) const
T eta() const
Definition: PV3DBase.h:73
tuple config
parse the configuration file
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > topoToken_
const bool createEntryForDoubleSidedModule_
std::vector< TrackerTreeVariables > vTkTreeVar_
unsigned int pxfSide(const DetId &id) const
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:163
T x() const
Definition: PV3DBase.h:59
unsigned int tecWheel(const DetId &id) const
static constexpr auto TID
const DetIdContainer & detUnitIds() const override
Returm a vector of all GeomDetUnit DetIds.
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
unsigned int pxfPanel(const DetId &id) const
unsigned int pxfBlade(const DetId &id) const
unsigned int tobLayer(const DetId &id) const
tuple module
Definition: callgraph.py:69
unsigned int tecSide(const DetId &id) const