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