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 
16 
17 // Ecal
21 
23 
28 
30 
31 using namespace std;
32 
33 /*****************************************************************************/
34 struct sortByPabs
35 {
36  bool operator() (const PSimHit& a, const PSimHit& b) const
37  {
38  return (a.pabs() > b.pabs());
39  }
40 };
41 
42 /*****************************************************************************/
43 struct sortByTof
44 {
45  bool operator() (const PSimHit& a, const PSimHit& b) const
46  {
47  return (a.tof() < b.tof());
48  }
49 };
50 
51 /*****************************************************************************/
53  (const edm::EventSetup& es, ofstream& file_) : file(file_)
54 {
55  // Get tracker geometry
56  edm::ESHandle<TrackerGeometry> trackerHandle;
57  es.get<TrackerDigiGeometryRecord>().get(trackerHandle);
58  theTracker = trackerHandle.product();
59 
60  // Get calorimetry
62  es.get<CaloGeometryRecord>().get(calo);
63  theCaloGeometry = (const CaloGeometry*)calo.product();
64 }
65 
66 /*****************************************************************************/
68 {
69 }
70 
71 /*****************************************************************************/
73 {
74  //Retrieve tracker topology from geometry
76  es.get<IdealGeometryRecord>().get(tTopoHandle);
77  const TrackerTopology* const tTopo = tTopoHandle.product();
78 
79  // Tracker
81  ev.getByLabel("mix", simTrackHandle);
82  const TrackingParticleCollection* simTracks = simTrackHandle.product();
83 
84  // Ecal
86  ev.getByLabel("g4SimHits", "EcalHitsEB", simHitsBarrel);
87 
88 // edm::Handle<edm::PCaloHitContainer> simHitsPreshower;
89 // ev.getByLabel("g4SimHits", "EcalHitsES", simHitsPreshower);
90 
92  ev.getByLabel("g4SimHits", "EcalHitsEE", simHitsEndcap);
93 
94 // FIXME
95 /*
96  {
97  edm::Handle<edm::SimTrackContainer> simTracks;
98  ev.getByType<edm::SimTrackContainer>(simTracks);
99  std::cerr << " SSSSS " << simTracks.product()->size() << std::endl;
100 
101  for(edm::SimTrackContainer::const_iterator t = simTracks.product()->begin();
102  t!= simTracks.product()->end(); t++)
103  {
104  std::cerr << " simTrack " << t - simTracks.product()->begin()
105  << " " << t->type()
106  << " " << t->charge()
107  << " " << t->vertIndex()
108  << " " << t->genpartIndex()
109  << " " << t->momentum().x()
110  << " " << t->momentum().y()
111  << " " << t->momentum().z()
112  << std::endl;
113  }
114 
115  }
116 */
117 
119 
120  // Utilities
121  PlotUtils plotUtils;
122 
123  file << ", If[st, {RGBColor[0.5,0.5,0.5]";
124 
125  for(TrackingParticleCollection::const_iterator simTrack = simTracks->begin();
126  simTrack!= simTracks->end();
127  simTrack++)
128  {
129  std::vector<PSimHit> simHits;
130 
131 #warning "This file has been modified just to get it to compile without any regard as to whether it still functions as intended"
132 #ifdef REMOVED_JUST_TO_GET_IT_TO_COMPILE__THIS_CODE_NEEDS_TO_BE_CHECKED
133  simHits = simTrack->trackPSimHit();
134 #endif
135 
136  // reorder with help of momentum
137  sort(simHits.begin(), simHits.end(), sortByPabs());
138 
139  for(std::vector<PSimHit>::const_iterator simHit = simHits.begin();
140  simHit!= simHits.end(); simHit++)
141  {
142  DetId id = DetId(simHit->detUnitId());
143 
144  if(theTracker->idToDetUnit(id) != 0)
145  {
146  GlobalPoint p1 =
147  theTracker->idToDetUnit(id)->toGlobal(simHit->localPosition());
148  GlobalVector v1 =
149  theTracker->idToDetUnit(id)->toGlobal(simHit->localDirection());
150 
151  // simHit
152  file << ", Point[{" << p1.x() << "," << p1.y() << ",(" << p1.z() << "-zs)*mz}]"
153  << std::endl;
154  file << ", Text[StyleForm[\"s\", URL->\"SimHit | Ekin="
155  << simTrack->energy() - simTrack->mass()
156  << " GeV | parent: source="
157  << simTrack->parentVertex()->nSourceTracks()
158  << " daughter=" << simTrack->parentVertex()->nDaughterTracks()
159  << HitInfo::getInfo(*simHit, tTopo) << "\"], {"
160  << p1.x() << "," << p1.y() << ",(" << p1.z() << "-zs)*mz}, {1,1}]"
161  << std::endl;
162 
163  // det
164  double x = theTracker->idToDet(id)->surface().bounds().width() /2;
165  double y = theTracker->idToDet(id)->surface().bounds().length()/2;
166  double z = 0.;
167 
168  GlobalPoint p00 = theTracker->idToDet(id)->toGlobal(LocalPoint(-x,-y,z));
169  GlobalPoint p01 = theTracker->idToDet(id)->toGlobal(LocalPoint(-x, y,z));
170  GlobalPoint p10 = theTracker->idToDet(id)->toGlobal(LocalPoint( x,-y,z));
171  GlobalPoint p11 = theTracker->idToDet(id)->toGlobal(LocalPoint( x, y,z));
172 
173  if(theTracker->idToDet(id)->subDetector() ==
175  theTracker->idToDet(id)->subDetector() ==
177  file << ", If[sd, {RGBColor[0.6,0.6,0.6], ";
178  else
179  file << ", If[sd, {RGBColor[0.8,0.8,0.8], ";
180 
181  file <<"Line[{{"<< p00.x()<<","<<p00.y()<<",("<<p00.z()<<"-zs)*mz}, "
182  <<"{"<< p01.x()<<","<<p01.y()<<",("<<p01.z()<<"-zs)*mz}, "
183  <<"{"<< p11.x()<<","<<p11.y()<<",("<<p11.z()<<"-zs)*mz}, "
184  <<"{"<< p10.x()<<","<<p10.y()<<",("<<p10.z()<<"-zs)*mz}, "
185  <<"{"<< p00.x()<<","<<p00.y()<<",("<<p00.z()<<"-zs)*mz}}]}]"
186  << std::endl;
187 
188  if(simHit == simHits.begin()) // vertex to first point
189  {
190  GlobalPoint p0(simTrack->vertex().x(),
191  simTrack->vertex().y(),
192  simTrack->vertex().z());
193  plotUtils.printHelix(p0,p1,v1, file, simTrack->charge());
194  }
195 
196  if(simHit+1 != simHits.end()) // if not last
197  {
198  DetId id = DetId((simHit+1)->detUnitId());
199  GlobalPoint p2 =
200  theTracker->idToDetUnit(id)->toGlobal((simHit+1)->localPosition());
201  GlobalVector v2 =
202  theTracker->idToDetUnit(id)->toGlobal((simHit+1)->localDirection());
203 
204  plotUtils.printHelix(p1,p2,v2, file, simTrack->charge());
205  }
206 
207  // Continue to Ecal
208  if(simHit+1 == simHits.end()) // if last
209  {
210  DetId id = DetId(simHit->detUnitId());
211  GlobalPoint p =
212  theTracker->idToDetUnit(id)->toGlobal(simHit->localPosition());
213 
214  // EB
215  geom = theCaloGeometry->getSubdetectorGeometry(DetId::Ecal,EcalBarrel);
216 
217  for(edm::PCaloHitContainer::const_iterator
218  simHit = simHitsBarrel->begin();
219  simHit!= simHitsBarrel->end(); simHit++)
220  if(simHit->geantTrackId() == static_cast<int>(simTrack->g4Track_begin()->trackId()) && //the sign of trackId tells whether there was a match
221  simHit->energy() > 0.060)
222  {
223  EBDetId detId(simHit->id());
224  const CaloCellGeometry* cell = geom->getGeometry(detId);
225 
226  if(cell != 0)
227  file << ", Line[{{" << p.x()
228  << "," << p.y()
229  << ",(" << p.z() <<"-zs)*mz}"
230  << ", {" << cell->getPosition().x() << ","
231  << cell->getPosition().y() << ",("
232  << cell->getPosition().z() << "-zs)*mz}}]" << std::endl;
233  }
234 
235  // ES
236 
237  // EE
238  geom = theCaloGeometry->getSubdetectorGeometry(DetId::Ecal,EcalEndcap);
239 
240  for(edm::PCaloHitContainer::const_iterator
241  simHit = simHitsEndcap->begin();
242  simHit!= simHitsEndcap->end(); simHit++)
243  if(simHit->geantTrackId() == static_cast<int>(simTrack->g4Track_begin()->trackId()) && //the sign of trackId tells whether there was a match
244  simHit->energy() > 0.060)
245  {
246  EEDetId detId(simHit->id());
247  const CaloCellGeometry* cell = geom->getGeometry(detId);
248 
249  if(cell != 0)
250  file << ", Line[{{" << p.x()
251  << "," << p.y()
252  << ",(" << p.z() << "-zs)*mz}"
253  << ", {" << cell->getPosition().x() << ","
254  << cell->getPosition().y() << ",("
255  << cell->getPosition().z() << "-zs)*mz}}]" << std::endl;
256  }
257  }
258  }
259  }
260  }
261 
262  file << "}]";
263 }
264 
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
void printSimTracks(const edm::Event &ev, const edm::EventSetup &es)
std::vector< TrackingParticle > TrackingParticleCollection
T y() const
Definition: PV3DBase.h:63
float float float 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:64
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:361
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
static std::string getInfo(const DetId &id, const TrackerTopology *tTopo)
Definition: HitInfo.cc:25
T x() const
Definition: PV3DBase.h:62