CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PlotSimTracks.cc
Go to the documentation of this file.
4 
8 
12 
15 
19 
22 
23 // Ecal
27 
29 
34 
36 
37 using namespace std;
38 
39 /*****************************************************************************/
40 struct sortByPabs
41 {
42  bool operator() (const PSimHit& a, const PSimHit& b) const
43  {
44  return (a.pabs() > b.pabs());
45  }
46 };
47 
48 /*****************************************************************************/
49 struct sortByTof
50 {
51  bool operator() (const PSimHit& a, const PSimHit& b) const
52  {
53  return (a.tof() < b.tof());
54  }
55 };
56 
57 /*****************************************************************************/
59  (const edm::EventSetup& es, ofstream& file_) : 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 }
71 
72 /*****************************************************************************/
74 {
75 }
76 
77 /*****************************************************************************/
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
213  geom = theCaloGeometry->getSubdetectorGeometry(DetId::Ecal,EcalBarrel);
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
236  geom = theCaloGeometry->getSubdetectorGeometry(DetId::Ecal,EcalEndcap);
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 }
262 
static std::string getInfo(const DetId &id)
Definition: HitInfo.cc:24
void printHelix(const GlobalPoint &p1, const GlobalPoint &p2, const GlobalVector &n2, std::ofstream &outFile, int charge)
Definition: PlotUtils.cc:7
float tof() const
deprecated name for timeOfFlight()
Definition: PSimHit.h:72
std::vector< TrackingParticle > TrackingParticleCollection
T y() const
Definition: PV3DBase.h:62
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.
void printSimTracks(const edm::Event &ev)
T z() const
Definition: PV3DBase.h:63
float pabs() const
fast and more accurate access to momentumAtEntry().mag()
Definition: PSimHit.h:63
double p2[4]
Definition: TauolaWrapper.h:90
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
PlotSimTracks(const edm::EventSetup &es, std::ofstream &file_)
Definition: DetId.h:20
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
double b
Definition: hdecay.h:120
tuple simHits
Definition: trackerHits.py:16
T const * product() const
Definition: Handle.h:74
double p1[4]
Definition: TauolaWrapper.h:89
double a
Definition: hdecay.h:121
Local3DPoint LocalPoint
Definition: LocalPoint.h:11
Definition: DDAxes.h:10
T x() const
Definition: PV3DBase.h:61