CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackerTreeGenerator.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: TrackerTreeGenerator
4 // Class: TrackerTreeGenerator
5 //
13 //
14 // Original Author: Johannes Hauk
15 // Created: Fri Jan 16 14:09:52 CET 2009
16 // Modified by: Ajay Kumar (University of Delhi)
17 //
18 // $Id: TrackerTreeGenerator.cc,v 1.1 2011/09/01 11:18:08 hauk Exp $
19 //
20 //
21 
22 
23 // system include files
24 #include <memory>
25 
26 // user include files
35 
39 
53 
54 //#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
65 
67 
68 #include "TTree.h"
69 //
70 // class decleration
71 //
72 
74  public:
75  explicit TrackerTreeGenerator(const edm::ParameterSet&);
77 
78 
79  private:
80  virtual void beginJob() ;
81  virtual void analyze(const edm::Event&, const edm::EventSetup&);
82  virtual void endJob() ;
83 
84  // ----------member data ---------------------------
85 
87  std::vector<TrackerTreeVariables> vTkTreeVar_;
89 };
90 
91 //
92 // constants, enums and typedefs
93 //
94 
95 //
96 // static data member definitions
97 //
98 
99 //
100 // constructors and destructor
101 //
103 createEntryForDoubleSidedModule_(iConfig.getParameter<bool>("createEntryForDoubleSidedModule")),
104 theParameterSet( iConfig )
105 {
106 }
107 
108 
110 {
111 }
112 
113 
114 //
115 // member functions
116 //
117 
118 // ------------ method called to for each event ------------
119 void
121 {
122  //iSetup.get<TrackerDigiGeometryRecord>().get(tkGeom);
123  // now try to take directly the ideal geometry independent of used geometry in Global Tag
124  edm::ESHandle<GeometricDet> geometricDet;
125  iSetup.get<IdealGeometryRecord>().get(geometricDet);
126 
128  iSetup.get<PTrackerParametersRcd>().get(ptp);
129  TrackerGeomBuilderFromGeometricDet trackerBuilder;
130  TrackerGeometry* tkGeom = trackerBuilder.build(&(*geometricDet), *ptp);
131 
132  const TrackerGeometry *bareTkGeomPtr = &(*tkGeom);
133 
134  edm::LogInfo("TrackerTreeGenerator") //<< "@SUB=analyze"
135  << "There are " << bareTkGeomPtr->detIds().size()
136  << " dets and "<<bareTkGeomPtr->detUnitIds().size()
137  <<" detUnits in the Geometry Record";
138 
139  if(createEntryForDoubleSidedModule_)edm::LogInfo("TrackerTreeGenerator") << "Create entry for each module AND one entry for virtual "
140  << "double-sided module in addition";
141  else edm::LogInfo("TrackerTreeGenerator") << "Create one entry for each physical module, do NOT create additional entry for virtual "
142  << "double-sided module";
143 
144  const TrackingGeometry::DetIdContainer& detIdContainer = bareTkGeomPtr->detIds();
145 
146  std::vector<DetId>::const_iterator iDet;
147  for(iDet = detIdContainer.begin(); iDet != detIdContainer.end(); ++iDet){
148 
149  const DetId& detId = *iDet;
150  const GeomDet& geomDet = *tkGeom->idToDet(*(&detId));
151  const Surface& surface = (&geomDet)->surface();
152 
153  TrackerTreeVariables tkTreeVar;
154  uint32_t rawId = detId.rawId();
155  tkTreeVar.rawId = rawId;
156  tkTreeVar.subdetId = detId.subdetId();
157 
158  if(tkTreeVar.subdetId == PixelSubdetector::PixelBarrel){
159  PXBDetId pxbId(rawId);
160  unsigned int whichHalfBarrel(1), ladderAl(0); //DetId does not know about halfBarrels is PXB ...
161  if( (rawId>=302056964 && rawId<302059300) || (rawId>=302123268 && rawId<302127140) || (rawId>=302189572 && rawId<302194980) )whichHalfBarrel=2;
162  tkTreeVar.layer = pxbId.layer();
163  tkTreeVar.half = whichHalfBarrel;
164  tkTreeVar.rod = pxbId.ladder(); // ... so, ladder is not per halfBarrel-Layer, but per barrel-layer!
165  tkTreeVar.module = pxbId.module();
166  if(tkTreeVar.layer==1){
167  if(tkTreeVar.half==2)ladderAl = tkTreeVar.rod -5;
168  else if(tkTreeVar.rod>15)ladderAl = tkTreeVar.rod -10;
169  else ladderAl = tkTreeVar.rod;
170  }else if(tkTreeVar.layer==2){
171  if(tkTreeVar.half==2)ladderAl = tkTreeVar.rod -8;
172  else if(tkTreeVar.rod>24)ladderAl = tkTreeVar.rod -16;
173  else ladderAl = tkTreeVar.rod;
174  }else if(tkTreeVar.layer==3){
175  if(tkTreeVar.half==2)ladderAl = tkTreeVar.rod -11;
176  else if(tkTreeVar.rod>33)ladderAl = tkTreeVar.rod -22;
177  else ladderAl = tkTreeVar.rod;
178  }
179  tkTreeVar.rodAl = ladderAl;}
180  else if(tkTreeVar.subdetId == PixelSubdetector::PixelEndcap){
181  PXFDetId pxfId(rawId);
182  unsigned int whichHalfCylinder(1), bladeAl(0); //DetId does not kmow about halfCylinders in PXF
183  if( (rawId>=352394500 && rawId<352406032) || (rawId>=352460036 && rawId<352471568) || (rawId>=344005892 && rawId<344017424) || (rawId>=344071428 && rawId<344082960) )whichHalfCylinder=2;
184  tkTreeVar.layer = pxfId.disk();
185  tkTreeVar.side = pxfId.side();
186  tkTreeVar.half = whichHalfCylinder;
187  tkTreeVar.blade = pxfId.blade();
188  tkTreeVar.panel = pxfId.panel();
189  tkTreeVar.module = pxfId.module();
190  if(tkTreeVar.half==2)bladeAl = tkTreeVar.blade -6;
191  else if(tkTreeVar.blade>18)bladeAl = tkTreeVar.blade -12;
192  else bladeAl = tkTreeVar.blade;
193  tkTreeVar.bladeAl = bladeAl;}
194  else if(tkTreeVar.subdetId == StripSubdetector::TIB){
195  TIBDetId tibId(rawId);
196  unsigned int whichHalfShell(1), stringAl(0); //DetId does not kmow about halfShells in TIB
197  if( (rawId>=369120484 && rawId<369120688) || (rawId>=369121540 && rawId<369121776) || (rawId>=369136932 && rawId<369137200) || (rawId>=369137988 && rawId<369138288) ||
198  (rawId>=369153396 && rawId<369153744) || (rawId>=369154436 && rawId<369154800) || (rawId>=369169844 && rawId<369170256) || (rawId>=369170900 && rawId<369171344) ||
199  (rawId>=369124580 && rawId<369124784) || (rawId>=369125636 && rawId<369125872) || (rawId>=369141028 && rawId<369141296) || (rawId>=369142084 && rawId<369142384) ||
200  (rawId>=369157492 && rawId<369157840) || (rawId>=369158532 && rawId<369158896) || (rawId>=369173940 && rawId<369174352) || (rawId>=369174996 && rawId<369175440) ) whichHalfShell=2;
201  tkTreeVar.layer = tibId.layer();
202  tkTreeVar.side = tibId.string()[0];
203  tkTreeVar.half = whichHalfShell;
204  tkTreeVar.rod = tibId.string()[2];
205  tkTreeVar.outerInner = tibId.string()[1];
206  tkTreeVar.module = tibId.module();
207  tkTreeVar.isDoubleSide = tibId.isDoubleSide();
208  tkTreeVar.isRPhi = tibId.isRPhi();
209  if(tkTreeVar.half==2){
210  if(tkTreeVar.layer==1){
211  if(tkTreeVar.outerInner==1)stringAl = tkTreeVar.rod -13;
212  else if(tkTreeVar.outerInner==2)stringAl = tkTreeVar.rod -15;
213  }
214  if(tkTreeVar.layer==2){
215  if(tkTreeVar.outerInner==1)stringAl = tkTreeVar.rod -17;
216  else if(tkTreeVar.outerInner==2)stringAl = tkTreeVar.rod -19;
217  }
218  if(tkTreeVar.layer==3){
219  if(tkTreeVar.outerInner==1)stringAl = tkTreeVar.rod -22;
220  else if(tkTreeVar.outerInner==2)stringAl = tkTreeVar.rod -23;
221  }
222  if(tkTreeVar.layer==4){
223  if(tkTreeVar.outerInner==1)stringAl = tkTreeVar.rod -26;
224  else if(tkTreeVar.outerInner==2)stringAl = tkTreeVar.rod -28;
225  }
226  }
227  else stringAl = tkTreeVar.rod;
228  tkTreeVar.rodAl = stringAl;}
229  else if(tkTreeVar.subdetId == StripSubdetector::TID){
230  TIDDetId tidId(rawId);
231  tkTreeVar.layer = tidId.wheel();
232  tkTreeVar.side = tidId.side();
233  tkTreeVar.ring = tidId.ring();
234  tkTreeVar.outerInner = tidId.module()[0];
235  tkTreeVar.module = tidId.module()[1];
236  tkTreeVar.isDoubleSide = tidId.isDoubleSide();
237  tkTreeVar.isRPhi = tidId.isRPhi();}
238  else if(tkTreeVar.subdetId == StripSubdetector::TOB){
239  TOBDetId tobId(rawId);
240  tkTreeVar.layer = tobId.layer();
241  tkTreeVar.side = tobId.rod()[0];
242  tkTreeVar.rod = tobId.rod()[1];
243  tkTreeVar.module = tobId.module();
244  tkTreeVar.isDoubleSide = tobId.isDoubleSide();
245  tkTreeVar.isRPhi = tobId.isRPhi();}
246  else if(tkTreeVar.subdetId == StripSubdetector::TEC){
247  TECDetId tecId(rawId);
248  tkTreeVar.layer = tecId.wheel();
249  tkTreeVar.side = tecId.side();
250  tkTreeVar.ring = tecId.ring();
251  tkTreeVar.petal = tecId.petal()[1];
252  tkTreeVar.outerInner = tecId.petal()[0];
253  tkTreeVar.module = tecId.module();
254  tkTreeVar.isDoubleSide = tecId.isDoubleSide();
255  tkTreeVar.isRPhi = tecId.isRPhi();}
256 
257 
258  LocalPoint lPModule(0.,0.,0.), lUDirection(1.,0.,0.), lVDirection(0.,1.,0.), lWDirection(0.,0.,1.);
259  GlobalPoint gPModule = surface.toGlobal(lPModule),
260  gUDirection = surface.toGlobal(lUDirection),
261  gVDirection = surface.toGlobal(lVDirection),
262  gWDirection = surface.toGlobal(lWDirection);
263  double dR(999.), dPhi(999.), dZ(999.);
265  || tkTreeVar.subdetId==StripSubdetector::TOB){
266  dR = gWDirection.perp() - gPModule.perp();
267  dPhi = deltaPhi(gUDirection.phi(),gPModule.phi());
268  dZ = gVDirection.z() - gPModule.z();
269  tkTreeVar.uDirection = dPhi>0. ? 1 : -1;
270  tkTreeVar.vDirection = dZ>0. ? 1 : -1;
271  tkTreeVar.wDirection = dR>0. ? 1 : -1;
272  }else if(tkTreeVar.subdetId==PixelSubdetector::PixelEndcap){
273  dR = gUDirection.perp() - gPModule.perp();
274  dPhi = deltaPhi(gVDirection.phi(),gPModule.phi());
275  dZ = gWDirection.z() - gPModule.z();
276  tkTreeVar.uDirection = dR>0. ? 1 : -1;
277  tkTreeVar.vDirection = dPhi>0. ? 1 : -1;
278  tkTreeVar.wDirection = dZ>0. ? 1 : -1;
279  }else if(tkTreeVar.subdetId==StripSubdetector::TID || tkTreeVar.subdetId==StripSubdetector::TEC){
280  dR = gVDirection.perp() - gPModule.perp();
281  dPhi = deltaPhi(gUDirection.phi(),gPModule.phi());
282  dZ = gWDirection.z() - gPModule.z();
283  tkTreeVar.uDirection = dPhi>0. ? 1 : -1;
284  tkTreeVar.vDirection = dR>0. ? 1 : -1;
285  tkTreeVar.wDirection = dZ>0. ? 1 : -1;
286  }
287  tkTreeVar.posR = gPModule.perp();
288  tkTreeVar.posPhi = gPModule.phi(); // = gPModule.phi().degrees();
289  tkTreeVar.posEta = gPModule.eta();
290  tkTreeVar.posX = gPModule.x();
291  tkTreeVar.posY = gPModule.y();
292  tkTreeVar.posZ = gPModule.z();
293 
294 
295  if(dynamic_cast<const StripGeomDetUnit*>(&geomDet)){ //is it a single physical module?
296  const StripGeomDetUnit& StripgeomDetUnit = dynamic_cast<const StripGeomDetUnit&>(geomDet);
297  if(tkTreeVar.subdetId==StripSubdetector::TIB || tkTreeVar.subdetId==StripSubdetector::TOB ||
299  const StripTopology& topol = dynamic_cast<const StripTopology&>(StripgeomDetUnit.specificTopology());
300  tkTreeVar.nStrips = topol.nstrips();
301  }
302  }
303 
304 
305  if(!createEntryForDoubleSidedModule_){if(tkTreeVar.isDoubleSide==1)continue;} // do so only for individual modules and not also one entry for the combined doubleSided Module
306  vTkTreeVar_.push_back(tkTreeVar);
307  }
308 
309 }
310 
311 
312 // ------------ method called once each job just before starting event loop ------------
313 void
315 {
316 }
317 
318 
319 // ------------ method called once each job just after ending the event loop ------------
320 void
322  UInt_t rawId(999), subdetId(999), layer(999), side(999), half(999), rod(999), ring(999), petal(999),
323  blade(999), panel(999), outerInner(999), module(999), rodAl(999), bladeAl(999), nStrips(999);
324  Bool_t isDoubleSide(false), isRPhi(false);
325  Int_t uDirection(999), vDirection(999), wDirection(999);
326  Float_t posR(999.F), posPhi(999.F), posEta(999.F), posX(999.F), posY(999.F), posZ(999.F);
328  TFileDirectory treeDir = fileService->mkdir("TrackerTree");
329  TTree* trackerTree;
330  trackerTree = treeDir.make<TTree>("TrackerTree","IDs of all modules (ideal geometry)");
331  trackerTree->Branch("RawId", &rawId, "RawId/i");
332  trackerTree->Branch("SubdetId", &subdetId, "SubdetId/i");
333  trackerTree->Branch("Layer", &layer, "Layer/i"); // Barrel: Layer, Forward: Disk
334  trackerTree->Branch("Side", &side, "Side/i"); // Rod/Ring in +z or -z
335  trackerTree->Branch("Half", &half, "Half/i"); // PXB: HalfBarrel, PXF: HalfCylinder, TIB: HalfShell
336  trackerTree->Branch("Rod", &rod, "Rod/i"); // Barrel (Ladder or String or Rod)
337  trackerTree->Branch("Ring", &ring, "Ring/i"); // Forward
338  trackerTree->Branch("Petal", &petal, "Petal/i"); // TEC
339  trackerTree->Branch("Blade", &blade, "Blade/i"); // PXF
340  trackerTree->Branch("Panel", &panel, "Panel/i"); // PXF
341  trackerTree->Branch("OuterInner", &outerInner, "OuterInner/i"); // front/back String,Ring,Petal
342  trackerTree->Branch("Module", &module, "Module/i"); // Module ID
343  trackerTree->Branch("RodAl", &rodAl, "RodAl/i"); // Different for AlignmentHierarchy from TrackerHierarchy (TPB, TIB)
344  trackerTree->Branch("BladeAl", &bladeAl, "BladeAl/i"); // Different for AlignmentHierarchy from TrackerHierarchy (TPF)
345  trackerTree->Branch("NStrips", &nStrips, "NStrips/i");
346  trackerTree->Branch("IsDoubleSide", &isDoubleSide, "IsDoubleSide/O");
347  trackerTree->Branch("IsRPhi", &isRPhi, "IsRPhi/O");
348  trackerTree->Branch("UDirection", &uDirection, "UDirection/I");
349  trackerTree->Branch("VDirection", &vDirection, "VDirection/I");
350  trackerTree->Branch("WDirection", &wDirection, "WDirection/I");
351  trackerTree->Branch("PosR", &posR, "PosR/F");
352  trackerTree->Branch("PosPhi", &posPhi, "PosPhi/F");
353  trackerTree->Branch("PosEta", &posEta, "PosEta/F");
354  trackerTree->Branch("PosX", &posX, "PosX/F");
355  trackerTree->Branch("PosY", &posY, "PosY/F");
356  trackerTree->Branch("PosZ", &posZ, "PosZ/F");
357 
358  for(std::vector<TrackerTreeVariables>::const_iterator iTree = vTkTreeVar_.begin(); iTree != vTkTreeVar_.end(); ++iTree){
359  rawId = (*iTree).rawId;
360  subdetId = (*iTree).subdetId;
361  layer = (*iTree).layer;
362  side = (*iTree).side;
363  half = (*iTree).half;
364  rod = (*iTree).rod;
365  ring = (*iTree).ring;
366  petal = (*iTree).petal;
367  blade = (*iTree).blade;
368  panel = (*iTree).panel;
369  outerInner = (*iTree).outerInner;
370  module = (*iTree).module;
371  rodAl = (*iTree).rodAl;
372  bladeAl = (*iTree).bladeAl;
373  nStrips = (*iTree).nStrips;
374  isDoubleSide = (*iTree).isDoubleSide;
375  isRPhi = (*iTree).isRPhi;
376  uDirection = (*iTree).uDirection;
377  vDirection = (*iTree).vDirection;
378  wDirection = (*iTree).wDirection;
379  posR = (*iTree).posR;
380  posPhi = (*iTree).posPhi;
381  posEta = (*iTree).posEta;
382  posX = (*iTree).posX;
383  posY = (*iTree).posY;
384  posZ = (*iTree).posZ;
385 
386  trackerTree->Fill();
387  }
388  edm::LogInfo("TrackerTreeGenerator") << "TrackerTree contains "<< vTkTreeVar_.size() <<" entries overall";
389 }
390 
391 
392 //define this as a plug-in
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:114
virtual int nstrips() const =0
bool isDoubleSide() const
Definition: TECDetId.h:152
unsigned int panel() const
panel id
Definition: PXFDetId.h:52
T perp() const
Definition: PV3DBase.h:72
unsigned int layer() const
layer id
Definition: TOBDetId.h:39
TrackerTreeGenerator(const edm::ParameterSet &)
module()
Definition: vlib.cc:994
bool isDoubleSide() const
Definition: TIBDetId.h:140
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
edm::ParameterSet theParameterSet
T y() const
Definition: PV3DBase.h:63
unsigned int ladder() const
ladder id
Definition: PXBDetId.h:39
virtual const StripTopology & specificTopology() const
Returns a reference to the strip proxy topology.
std::vector< unsigned int > string() const
string id
Definition: TIBDetId.h:53
unsigned int module() const
det id
Definition: TECDetId.h:75
unsigned int layer() const
layer id
Definition: PXBDetId.h:35
unsigned int side() const
positive or negative id
Definition: TECDetId.h:47
std::vector< unsigned int > rod() const
rod id
Definition: TOBDetId.h:49
unsigned int blade() const
blade id
Definition: PXFDetId.h:48
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
virtual const DetIdContainer & detIds() const
Returm a vector of all GeomDet DetIds (including those of GeomDetUnits)
std::vector< unsigned int > petal() const
petal id
Definition: TECDetId.h:61
int iEvent
Definition: GenABIO.cc:230
double dPhi(double phi1, double phi2)
Definition: JetUtil.h:30
virtual void analyze(const edm::Event &, const edm::EventSetup &)
T z() const
Definition: PV3DBase.h:64
unsigned int ring() const
ring id
Definition: TIDDetId.h:55
unsigned int module() const
det id
Definition: PXBDetId.h:43
bool isRPhi()
Definition: TIDDetId.h:105
unsigned int module() const
det id
Definition: PXFDetId.h:56
std::vector< unsigned int > module() const
det id
Definition: TIDDetId.h:64
T * make(const Args &...args) const
make new ROOT object
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
unsigned int disk() const
disk id
Definition: PXFDetId.h:43
Definition: DetId.h:18
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
Definition: TFileService.h:69
unsigned int module() const
detector id
Definition: TIBDetId.h:61
edm::Service< TFileService > fileService
unsigned int side() const
positive or negative id
Definition: TIDDetId.h:45
const T & get() const
Definition: EventSetup.h:55
unsigned int wheel() const
wheel id
Definition: TECDetId.h:52
unsigned int layer() const
layer id
Definition: TIBDetId.h:41
T eta() const
Definition: PV3DBase.h:76
TrackerGeometry * build(const GeometricDet *gd, const PTrackerParameters &ptp)
const bool createEntryForDoubleSidedModule_
virtual const DetIdContainer & detUnitIds() const
Returm a vector of all GeomDetUnit DetIds.
unsigned int ring() const
ring id
Definition: TECDetId.h:71
std::vector< TrackerTreeVariables > vTkTreeVar_
bool isDoubleSide() const
Definition: TOBDetId.h:119
unsigned int side() const
positive or negative id
Definition: PXFDetId.h:38
unsigned int module() const
detector id
Definition: TOBDetId.h:58
bool isRPhi()
Definition: TOBDetId.h:85
bool isRPhi()
Definition: TIBDetId.h:103
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:281
T x() const
Definition: PV3DBase.h:62
Definition: vlib.h:208
bool isDoubleSide() const
Definition: TIDDetId.h:140
bool isRPhi()
Definition: TECDetId.h:114
unsigned int wheel() const
wheel id
Definition: TIDDetId.h:50
virtual const TrackerGeomDet * idToDet(DetId) const
std::vector< DetId > DetIdContainer