CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes
PlotSimTracks Class Reference

#include <PlotSimTracks.h>

Public Member Functions

 PlotSimTracks (const edm::EventSetup &es, std::ofstream &file_)
 
void printSimTracks (const edm::Event &ev)
 
 ~PlotSimTracks ()
 

Private Attributes

std::ofstream & file
 
const CaloGeometrytheCaloGeometry
 
const TrackerGeometrytheTracker
 

Detailed Description

Definition at line 12 of file PlotSimTracks.h.

Constructor & Destructor Documentation

PlotSimTracks::PlotSimTracks ( const edm::EventSetup es,
std::ofstream &  file_ 
)
explicit

Definition at line 59 of file PlotSimTracks.cc.

References edm::EventSetup::get(), and edm::ESHandle< class >::product().

59  : file(file_)
60 {
61  // Get tracker geometry
62  edm::ESHandle<TrackerGeometry> trackerHandle;
63  es.get<TrackerDigiGeometryRecord>().get(trackerHandle);
64  theTracker = trackerHandle.product();
65 
66  // Get calorimetry
68  es.get<CaloGeometryRecord>().get(calo);
69  theCaloGeometry = (const CaloGeometry*)calo.product();
70 }
std::ofstream & file
Definition: PlotSimTracks.h:20
const TrackerGeometry * theTracker
Definition: PlotSimTracks.h:21
const CaloGeometry * theCaloGeometry
Definition: PlotSimTracks.h:22
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
PlotSimTracks::~PlotSimTracks ( )

Definition at line 73 of file PlotSimTracks.cc.

74 {
75 }

Member Function Documentation

void PlotSimTracks::printSimTracks ( const edm::Event ev)

Definition at line 78 of file PlotSimTracks.cc.

References DetId::Ecal, EcalBarrel, EcalEndcap, mergeVDriftHistosByStation::file, relativeConstraints::geom, edm::Event::getByLabel(), CaloSubdetectorGeometry::getGeometry(), HitInfo::getInfo(), AlCaHLTBitMon_ParallelJobs::p, p1, p2, GeomDetEnumerators::PixelBarrel, GeomDetEnumerators::PixelEndcap, PlotUtils::printHelix(), edm::Handle< T >::product(), trackerHits::simHits, python.multivaluedict::sort(), PV3DBase< T, PVType, FrameType >::x(), vdt::x, detailsBasic3DVector::y, PV3DBase< T, PVType, FrameType >::y(), detailsBasic3DVector::z, and PV3DBase< T, PVType, FrameType >::z().

79 {
80  // Tracker
82  ev.getByLabel("mergedtruth", simTrackHandle);
83  const TrackingParticleCollection* simTracks = simTrackHandle.product();
84 
85  // Ecal
87  ev.getByLabel("g4SimHits", "EcalHitsEB", simHitsBarrel);
88 
89 // edm::Handle<edm::PCaloHitContainer> simHitsPreshower;
90 // ev.getByLabel("g4SimHits", "EcalHitsES", simHitsPreshower);
91 
93  ev.getByLabel("g4SimHits", "EcalHitsEE", simHitsEndcap);
94 
95 // FIXME
96 /*
97  {
98  edm::Handle<edm::SimTrackContainer> simTracks;
99  ev.getByType<edm::SimTrackContainer>(simTracks);
100  std::cerr << " SSSSS " << simTracks.product()->size() << std::endl;
101 
102  for(edm::SimTrackContainer::const_iterator t = simTracks.product()->begin();
103  t!= simTracks.product()->end(); t++)
104  {
105  std::cerr << " simTrack " << t - simTracks.product()->begin()
106  << " " << t->type()
107  << " " << t->charge()
108  << " " << t->vertIndex()
109  << " " << t->genpartIndex()
110  << " " << t->momentum().x()
111  << " " << t->momentum().y()
112  << " " << t->momentum().z()
113  << std::endl;
114  }
115 
116  }
117 */
118 
120 
121  // Utilities
122  PlotUtils plotUtils;
123 
124  file << ", If[st, {RGBColor[0.5,0.5,0.5]";
125 
126  for(TrackingParticleCollection::const_iterator simTrack = simTracks->begin();
127  simTrack!= simTracks->end();
128  simTrack++)
129  {
130  std::vector<PSimHit> simHits;
131 
132  simHits = simTrack->trackPSimHit();
133 
134  // reorder with help of momentum
135  sort(simHits.begin(), simHits.end(), sortByPabs());
136 
137  for(std::vector<PSimHit>::const_iterator simHit = simHits.begin();
138  simHit!= simHits.end(); simHit++)
139  {
140  DetId id = DetId(simHit->detUnitId());
141 
142  if(theTracker->idToDetUnit(id) != 0)
143  {
144  GlobalPoint p1 =
145  theTracker->idToDetUnit(id)->toGlobal(simHit->localPosition());
146  GlobalVector v1 =
147  theTracker->idToDetUnit(id)->toGlobal(simHit->localDirection());
148 
149  // simHit
150  file << ", Point[{" << p1.x() << "," << p1.y() << ",(" << p1.z() << "-zs)*mz}]"
151  << std::endl;
152  file << ", Text[StyleForm[\"s\", URL->\"SimHit | Ekin="
153  << simTrack->energy() - simTrack->mass()
154  << " GeV | parent: source="
155  << simTrack->parentVertex()->nSourceTracks()
156  << " daughter=" << simTrack->parentVertex()->nDaughterTracks()
157  << HitInfo::getInfo(*simHit) << "\"], {"
158  << p1.x() << "," << p1.y() << ",(" << p1.z() << "-zs)*mz}, {1,1}]"
159  << std::endl;
160 
161  // det
162  double x = theTracker->idToDet(id)->surface().bounds().width() /2;
163  double y = theTracker->idToDet(id)->surface().bounds().length()/2;
164  double z = 0.;
165 
166  GlobalPoint p00 = theTracker->idToDet(id)->toGlobal(LocalPoint(-x,-y,z));
167  GlobalPoint p01 = theTracker->idToDet(id)->toGlobal(LocalPoint(-x, y,z));
168  GlobalPoint p10 = theTracker->idToDet(id)->toGlobal(LocalPoint( x,-y,z));
169  GlobalPoint p11 = theTracker->idToDet(id)->toGlobal(LocalPoint( x, y,z));
170 
171  if(theTracker->idToDet(id)->subDetector() ==
173  theTracker->idToDet(id)->subDetector() ==
175  file << ", If[sd, {RGBColor[0.6,0.6,0.6], ";
176  else
177  file << ", If[sd, {RGBColor[0.8,0.8,0.8], ";
178 
179  file <<"Line[{{"<< p00.x()<<","<<p00.y()<<",("<<p00.z()<<"-zs)*mz}, "
180  <<"{"<< p01.x()<<","<<p01.y()<<",("<<p01.z()<<"-zs)*mz}, "
181  <<"{"<< p11.x()<<","<<p11.y()<<",("<<p11.z()<<"-zs)*mz}, "
182  <<"{"<< p10.x()<<","<<p10.y()<<",("<<p10.z()<<"-zs)*mz}, "
183  <<"{"<< p00.x()<<","<<p00.y()<<",("<<p00.z()<<"-zs)*mz}}]}]"
184  << std::endl;
185 
186  if(simHit == simHits.begin()) // vertex to first point
187  {
188  GlobalPoint p0(simTrack->vertex().x(),
189  simTrack->vertex().y(),
190  simTrack->vertex().z());
191  plotUtils.printHelix(p0,p1,v1, file, simTrack->charge());
192  }
193 
194  if(simHit+1 != simHits.end()) // if not last
195  {
196  DetId id = DetId((simHit+1)->detUnitId());
197  GlobalPoint p2 =
198  theTracker->idToDetUnit(id)->toGlobal((simHit+1)->localPosition());
199  GlobalVector v2 =
200  theTracker->idToDetUnit(id)->toGlobal((simHit+1)->localDirection());
201 
202  plotUtils.printHelix(p1,p2,v2, file, simTrack->charge());
203  }
204 
205  // Continue to Ecal
206  if(simHit+1 == simHits.end()) // if last
207  {
208  DetId id = DetId(simHit->detUnitId());
209  GlobalPoint p =
210  theTracker->idToDetUnit(id)->toGlobal(simHit->localPosition());
211 
212  // EB
214 
215  for(edm::PCaloHitContainer::const_iterator
216  simHit = simHitsBarrel->begin();
217  simHit!= simHitsBarrel->end(); simHit++)
218  if(simHit->geantTrackId() == static_cast<int>(simTrack->g4Track_begin()->trackId()) && //the sign of trackId tells whether there was a match
219  simHit->energy() > 0.060)
220  {
221  EBDetId detId(simHit->id());
222  const CaloCellGeometry* cell = geom->getGeometry(detId);
223 
224  if(cell != 0)
225  file << ", Line[{{" << p.x()
226  << "," << p.y()
227  << ",(" << p.z() <<"-zs)*mz}"
228  << ", {" << cell->getPosition().x() << ","
229  << cell->getPosition().y() << ",("
230  << cell->getPosition().z() << "-zs)*mz}}]" << std::endl;
231  }
232 
233  // ES
234 
235  // EE
237 
238  for(edm::PCaloHitContainer::const_iterator
239  simHit = simHitsEndcap->begin();
240  simHit!= simHitsEndcap->end(); simHit++)
241  if(simHit->geantTrackId() == static_cast<int>(simTrack->g4Track_begin()->trackId()) && //the sign of trackId tells whether there was a match
242  simHit->energy() > 0.060)
243  {
244  EEDetId detId(simHit->id());
245  const CaloCellGeometry* cell = geom->getGeometry(detId);
246 
247  if(cell != 0)
248  file << ", Line[{{" << p.x()
249  << "," << p.y()
250  << ",(" << p.z() << "-zs)*mz}"
251  << ", {" << cell->getPosition().x() << ","
252  << cell->getPosition().y() << ",("
253  << cell->getPosition().z() << "-zs)*mz}}]" << std::endl;
254  }
255  }
256  }
257  }
258  }
259 
260  file << "}]";
261 }
static std::string getInfo(const DetId &id)
Definition: HitInfo.cc:24
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:43
void printHelix(const GlobalPoint &p1, const GlobalPoint &p2, const GlobalVector &n2, std::ofstream &outFile, int charge)
Definition: PlotUtils.cc:7
virtual float length() const =0
std::vector< TrackingParticle > TrackingParticleCollection
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:47
T y() const
Definition: PV3DBase.h:62
virtual SubDetector subDetector() const =0
Which subdetector.
std::ofstream & file
Definition: PlotSimTracks.h:20
double double double z
virtual const CaloCellGeometry * getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
T z() const
Definition: PV3DBase.h:63
const TrackerGeometry * theTracker
Definition: PlotSimTracks.h:21
const CaloGeometry * theCaloGeometry
Definition: PlotSimTracks.h:22
double p2[4]
Definition: TauolaWrapper.h:90
virtual const GeomDet * idToDet(DetId) const
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
Definition: DetId.h:20
const Bounds & bounds() const
Definition: BoundSurface.h:89
tuple simHits
Definition: trackerHits.py:16
T const * product() const
Definition: Handle.h:74
virtual const GeomDetUnit * idToDetUnit(DetId) const
Return the pointer to the GeomDetUnit corresponding to a given DetId.
double p1[4]
Definition: TauolaWrapper.h:89
const BoundPlane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:35
Local3DPoint LocalPoint
Definition: LocalPoint.h:11
x
Definition: VDTMath.h:216
T x() const
Definition: PV3DBase.h:61
virtual float width() const =0

Member Data Documentation

std::ofstream& PlotSimTracks::file
private

Definition at line 20 of file PlotSimTracks.h.

const CaloGeometry* PlotSimTracks::theCaloGeometry
private

Definition at line 22 of file PlotSimTracks.h.

const TrackerGeometry* PlotSimTracks::theTracker
private

Definition at line 21 of file PlotSimTracks.h.