MarlinUtil  1.12.1
MarlinCED.h
1 #ifndef MarlinCED_h
2 #define MarlinCED_h 1
3 
4 #include <cmath>
5 
6 #include <vector>
7 #include <iostream>
8 #include <iomanip>
9 #include "marlin/Processor.h"
10 #include "marlin/Global.h"
11 
12 #include "ced_cli.h"
13 
14 #include <lcio.h>
15 #include <UTIL/LCTypedVector.h>
16 #include <UTIL/LCTOOLS.h>
17 #include <UTIL/Operators.h>
18 #include <EVENT/LCCollection.h>
19 #include <EVENT/MCParticle.h>
20 #include <EVENT/Track.h>
21 #include <EVENT/Cluster.h>
22 #include <EVENT/Vertex.h>
23 #include <EVENT/ReconstructedParticle.h>
24 #include <EVENT/SimTrackerHit.h>
25 #include <EVENT/SimCalorimeterHit.h>
26 #include <EVENT/TrackerHit.h>
27 #include <EVENT/CalorimeterHit.h>
28 
29 #include "IMPL/ClusterImpl.h"
30 
31 #include <MarlinDrawUtil.h>
32 #include <Trajectory.h>
33 
34 #include <ctime> //hauke
35 
36 
37 using namespace marlin ;
38 
39 struct CEDMapParticleObject{const LCObject *obj; void (*function)(const LCObject *);};
40 
41 typedef std::map<const int, CEDMapParticleObject> CEDPickingMap;
42 typedef std::map<std::string, void (*)(const LCObject *)> CEDFunctionMap;
43 
44 
45 template <class T>
46  void printDefault(const LCObject *raw){const T* obj = (T*) raw; std::cout << obj;}
47 
55  private:
58  static CEDPickingHandler *instance;
59 
63  static CEDPickingMap map;
64 
68  static CEDFunctionMap funcMap;
69  //static struct termios orig_termios;
70 
71  //CEDPickingHandler(); //is not allow to instance this
72  //CEDPickingHandler(const CEDPickingHandler& cc); //not allows to make copies
73  //~CEDPickingHandler();
74 
75 
76  public:
77  //class
80  static CEDPickingHandler& getInstance();
81 
85  template <class T>
86  static void defaultOutputFunction(const LCObject *obj){
87 
88  streamlog_out(MESSAGE) << " Picked object " << obj << " with id " << obj->id() << std::endl;
89  streamlog_out(MESSAGE) << *(T*)obj;
90 
91  }
92 
96  static int kbhit(void);
97  /*
98  static void set_conio_terminal_mode(void);
99  static void reset_terminal_mode(void);
100  static int getch(void);
101  */
102 
103 
113  void update(LCEvent *);
114 
117  void printID(int);
118 
123  void registerFunction(std::string, void (*)(const LCObject *));
124 };
125 //end hauke hoelbe
126 
127 
132 class MarlinCED {
133 
134  public:
135  static MarlinCED* instance() ;
136 
137  LCEvent* _currEvent;
138 
141  static void init( Processor* proc ) ;
142 
152  static void newEvent( Processor* proc , int modelID=0, LCEvent* evt=0 ) ;
153 
158  static void draw( Processor* proc , int waitForKeyboard=1 ) ;
159 
160  static void getParticleFromID(int, LCEvent*);
161 
162  static void printMCParticle(MCParticle* mcp, int daughterIndent=0, int motherIndent=0);
163  void printMCFamily(MCParticle* part, unsigned int daughterBranches, unsigned int motherBranches,
164  unsigned int daughterIndent=0, unsigned int motherIndent=0);
165  void printAndDrawMCFamily(MCParticle* part, LCEvent * evt, unsigned int daughterBranches, unsigned int motherBranches,
166  unsigned int daughterIndent=0, unsigned int motherIndent=0);
167 
168 
173  template <class In>
174  static void drawObjectsWithPosition(In first, In last, int marker, int size ,unsigned int color, unsigned int layer=0, const char * PickingMessage="") {
175  //std::cout<<"drawObjectsWithPosition register a map id"<< std::endl;
176  //int id;
177  while( first != last ) {
178 
179  //sprintf(pickingMessage, "Position: %f, %f", (*first)->getPosition()[1], (*first)->getPosition()[2]);
180 
181  //id = idMap::add(pickingMessage);
182 
183  int id = (*first)->id();
184  ced_hit_ID( (*first)->getPosition()[0],
185  (*first)->getPosition()[1],
186  (*first)->getPosition()[2],
187  //marker | ( layer << CED_LAYER_SHIFT ) , size , color, id ) ;
188  marker,layer, size , color, id ) ;
189 
190  ++first ;
191  }
192  }
193 
194 
195 //hauke hoelbe
196  template <class In>
197  static void drawObjectsWithPositionID(LCCollection* col,In first, In last, int marker, int size ,unsigned int color, unsigned int layer=0) {
198  int i=0;
199  while( first != last ) {
200  int id = (*first)->id();
201  std::cout << "test!!! " << std::endl;
202  //int id = getIDfromIndex(col,i);
203  ced_hit_ID( (*first)->getPosition()[0],
204  (*first)->getPosition()[1],
205  (*first)->getPosition()[2],
206  //marker | ( layer << CED_LAYER_SHIFT ) , size , color, id ) ;
207  marker, layer, size , color, id ) ;
208 
209  ++first ;
210  i++;
211  }
212  }
213 
214 
217  static void drawHelix(float b, float charge, float x, float y, float z,
218  float px, float py, float pz, int marker, int size,
219  unsigned int col,
220  float rmin=10.0, float rmax=3000.0, float zmax=4500.0, unsigned int id = 0);
221 
222 
225  static void drawTrajectory(const Trajectory* t, const int marker,
226  const int size, const unsigned int col,
227  const float rmin=10.0, const float rmax=3000.0,
228  const float zmax=4500.0, unsigned int id=0) ;
229 
232  static void drawSpike(float x0, float y0, float z0, float x1, float y1, float z1, unsigned int color, unsigned int layer, unsigned int id=0);
233 
235  static void drawGEARDetector() ;
236  static void drawDetectorFromGear( gear::GearMgr* gearMgr ) ;
237 
239  static void drawGEARTelescope() ;
240 
246  static void drawDetector(int modelID) {
247 
248 
249  // FIXME: for now have hard coded geometry ....
250  // here we would read some geometry description ....
251 
252  // from V.Morgunov / A.Raspereza: simple outlines of LDC, SID, GLD:
253 
254  static CED_GeoCylinder geoCylindersLDC[] = { // for TESLA Detector Geometry
255  // { 50.0, 6, 0.0, 5658.5, -5658.5, 0xff }, // beam tube
256  { 380.0, 24, 0.0, 2658.5, -2658.5, 0xff }, // inner TPC
257  { 1840.0, 8, 22.5, 2700.0, -2700.0, 0x7f7f1f }, // inner ECAL
258  { 2045.7, 8, 22.5, 2700.0, -2700.0, 0x7f7f1f }, // outer ECAL
259  { 2045.7, 8, 22.5, 101.00, 2820.0, 0x7f7f1f }, // endcap ECAL
260  { 2045.7, 8, 22.5, 101.00, -3022.0, 0x7f7f1f }, // endcap ECAL
261  { 3000.0, 16, 0.0, 2658.5, -2658.5, 0xcf00 }, // outer HCAL
262  { 3000.0, 8, 22.5, 702.25, 2826.0, 0xcf00 }, // endcap HCAL
263  { 3000.0, 8, 22.5, 702.25, -4230.5, 0xcf00 }, // endcap HCAL
264  // radius, poligon order, angle degree, 1/2 length, shift in z, color
265  };
266 
267  static CED_GeoCylinder geoCylindersSiD[] = { // for SiD Detector Geometry
268  // { 12.0, 100, 0.0, 5658.5, -5658.5, 0xff }, // beam tube
269  { 186.35, 20, 0.0, 271.0, -271.0, 0xff }, // 1st SiD layer
270  { 448.85, 20, 0.0, 621.0, -621.0, 0xff }, // 2nd SiD layer
271  { 711.35, 20, 0.0, 971.0, -971.0, 0xff }, // 3d SiD layer
272  { 973.85, 20, 0.0, 1321.0, -1321.0, 0xff }, // 4th SiD layer
273  { 1236.35, 20, 0.0, 1649.4, -1649.4, 0xff }, // 5th SiD layer
274  { 1270.00, 30, 0.0, 1682.5, -1682.5, 0x7f7f1f }, // inner ECAL
275  { 1385.00, 30, 0.0, 1682.5, -1682.5, 0x7f7f1f }, // outer ECAL
276  { 1385.00, 30, 0.0, 562.5, 1682.5, 0x7f7f1f }, // endcap ECAL
277  { 1385.00, 30, 0.0, 562.5, -2807.5, 0x7f7f1f }, // endcap ECAL
278  { 2500.00, 30, 0.0, 1795.0, -1795.0, 0xcf00 }, // outer HCAL
279  { 2500.00, 30, 0.0, 487.25 , 1795.0, 0xcf00 }, // endcap HCAL
280  { 2500.00, 30, 0.0, 487.25 ,-2770.0, 0xcf00 }, // endcap HCAL
281  };
282 
283 
284  static CED_GeoCylinder geoCylindersGLD[] = { // for Huge Detector Geometry
285  // { 50.0, 6, 0.0, 5658.5, -5658.5, 0xff }, // beam tube
286  { 400.0, 24, 0.0, 2600.0, -2600.0, 0xff }, // inner TPC
287  { 2100.0, 30, 22.5, 2700.0, -2700.0, 0x7f7f1f }, // inner CALO
288  { 3405.0, 30, 22.5, 2700.0, -2700.0, 0x7f7f1f }, // outer CAL0
289  { 3405.0, 30, 22.5, 737.5, 2700.0, 0x7f7f1f }, // endcap CAL0
290  { 3405.0, 30, 22.5, 737.5, -4175.0, 0x7f7f1f }, // endcap ECAL
291  // { 3000.0, 16, 0.0, 2658.5, -2658.5, 0xcf00 }, // outer HCAL
292  // { 3000.0, 8, 22.5, 702.25, 2826.0, 0xcf00 }, // endcap HCAL
293  // { 3000.0, 8, 22.5, 702.25, -4230.5, 0xcf00 }, // endcap HCAL
294  // radius, poligon order, angle degree, 1/2 length, shift in z, color
295  };
296 
297 
298  static CED_GeoCylinder geoCylindersCaliceTestBeam[] = { // Calice TestBeam Prototype (simple wire frame)
299  { float( 192.25*sqrt(2.0) ), 4, 45.0, 101.35, -2.0*101.35 , 0x7f7f1f }, // ECAL (Proto03)
300  { float( 450.00*sqrt(2.0) ), 4, 45.0, 572.87, 0.00 , 0xcf00 }, // HCAL (TBHcal04)
301  { float( 500.00*sqrt(2.0) ), 4, 45.0, 457.60, 2.0*572.87+250.0, 0xcf00 }, // TCatcher (TBCatcher04)
302  // radius (surrounding (out-circle!) the polygon), poligon order, angle degree, 1/2 length, shift in z, color
303  };
304 
305  if (modelID == 0) {
306  ced_geocylinders(sizeof(geoCylindersLDC)/sizeof(CED_GeoCylinder),geoCylindersLDC);
307  }
308  else if (modelID == 1) {
309  ced_geocylinders(sizeof(geoCylindersSiD)/sizeof(CED_GeoCylinder),geoCylindersSiD);
310  }
311  else if (modelID == 2) {
312  ced_geocylinders(sizeof(geoCylindersGLD)/sizeof(CED_GeoCylinder),geoCylindersGLD);
313  }
314  else if (modelID == 3) {
315  ced_geocylinders(sizeof(geoCylindersCaliceTestBeam)/sizeof(CED_GeoCylinder),geoCylindersCaliceTestBeam);
316  }
317 
318 
319  }
320 
326  static void drawMCParticle(MCParticle* MCP, bool drawSimHits, LCEvent* event, int marker, int size,
327  unsigned int color, unsigned int layer=0, double bField = 4.0,
328  double rmin = 0.0, double zmin = 0.0, double rmax = 3000.0, double zmax = 4500.0,
329  bool drawOnDifferentLayers = true);
330 
338  static void drawMCParticleTree(LCEvent* event, std::string colNameMC, double energyCut,
339  double bField = 4.0, double rIn = 0.0, double zIn = 0.0,
340  double rOut = 3000.0 , double zOut = 4500.0);
341 
344  static void drawSimTrackerHits(LCEvent* event, int marker, int size, unsigned int color, unsigned int layer=0);
345 
348  static void drawSimCalorimeterHits(LCEvent* event, int marker, int size, unsigned int color, unsigned int layer=0);
349 
352  static void drawSimHits(LCEvent* event, int marker, int size, unsigned int color, unsigned int layer=0);
353 
356  static void drawTrackerHits(LCEvent* event, int marker, int size, unsigned int color, unsigned int layer=0);
357 
360  static void drawCalorimeterHits(LCEvent* event, int marker, int size, unsigned int color, unsigned int layer=0);
361 
364  static void drawHits(LCEvent* event, int marker, int size, unsigned int color, unsigned int layer=0);
365 
368  static void drawTrack(Track* track, int marker, int size, unsigned int color, unsigned int layer=0);
369 
372  static void drawCluster(Cluster* cluster, int marker, int size, unsigned int color, unsigned int layer=0);
373 
376  static void drawClusterImpl(const ClusterImpl* cluster, int marker, int size, unsigned int color, unsigned int layer=0);
377 
380  static void drawRecoParticle(ReconstructedParticle* reco, int marker, int size, unsigned int color, unsigned int layer=0);
381 
382 
383 /*************************/
384  static int getIDfromIndex(LCCollection* col, int index);
385 //{
386 // _int_count++;
387 // std::cout<<"Registration" << "col.getTypeName(): " << col->getTypeName() << " id: " << index << " test i:" << _int_count << std::endl;
388 // return(1);
389 //}
390 
391  static void set_layer_description(const std::string& desc, int layerID);
392  static void add_layer_description(const std::string& desc, int layerID);
393  static void write_layer_description(void);
394 
395 private:
396  static int _int_count;
397  static std::vector<std::string> _descs;
398 
399 
400 protected:
401 
402  //hauke hoelbe: 08.02.2010
403  MarlinCED() : _first(0) , _last(0){ _currEvent=0; }
404 
405  static MarlinCED* _me ;
406 
407  Processor* _first ;
408  Processor* _last ;
409  // helper method to draw hit collections by type
410  static void drawHitCollectionsByType(LCEvent* event, const char* type, int marker, int size,
411  unsigned int color, unsigned int layer=0) {
412 
413  try {
414 
415  std::vector< std::string >::const_iterator iter;
416  const std::vector< std::string >* ColNames = event->getCollectionNames();
417 
418  for( iter = ColNames->begin() ; iter != ColNames->end() ; iter++) {
419 
420  LCCollection* col = event->getCollection( *iter ) ;
421 
422  if ( col->getTypeName() == type ) {
423 
424  if ( type == LCIO::SIMTRACKERHIT ) {
425 
426  LCTypedVector<SimTrackerHit> v(col);
427  drawObjectsWithPosition(v.begin(),v.end(),marker,size,color,layer);
428 
429  }
430 
431  if ( type == LCIO::SIMCALORIMETERHIT ) {
432 
433  LCTypedVector<SimCalorimeterHit> v(col);
434  drawObjectsWithPosition(v.begin(),v.end(),marker,size,color,layer);
435 
436  }
437 
438  if ( type == LCIO::TRACKERHIT ) {
439 
440  LCTypedVector<TrackerHit> v(col);
441  drawObjectsWithPosition(v.begin(),v.end(),marker,size,color,layer);
442 
443  }
444 
445  if ( type == LCIO::CALORIMETERHIT ) {
446 
447  LCTypedVector<CalorimeterHit> v(col);
448  drawObjectsWithPosition(v.begin(),v.end(),marker,size,color,layer);
449 
450  }
451  }
452  }
453  }
454  catch(DataNotAvailableException &e){}
455 
456  }
457 
458 
459  // FIXME: Not so elegant, refine! Use iterators, templates etc. See drawHitCollectionsByType(...).
460  // helper method to draw hit collections by MC Contribution
461  static void drawHitCollectionsByMCContribution(LCEvent* event, MCParticle* MCP, int marker, int size,
462  unsigned int color, unsigned int layer=0) {
463 
464  std::vector< std::string >::const_iterator iter;
465  const std::vector< std::string >* ColNames = event->getCollectionNames();
466 
467  for( iter = ColNames->begin() ; iter != ColNames->end() ; iter++) {
468 
469  LCCollection* col = event->getCollection( *iter ) ;
470 
471  if ( col->getTypeName() == LCIO::SIMTRACKERHIT ) {
472 
473  int n = col->getNumberOfElements();
474 
475  for (int i = 0; i < n; ++i) {
476 
477  SimTrackerHit* hit = dynamic_cast<SimTrackerHit*>(col->getElementAt(i));
478 
479  if (hit->getMCParticle() == MCP) {
480  double x = hit->getPosition()[0];
481  double y = hit->getPosition()[1];
482  double z = hit->getPosition()[2];
483  //ced_hit_ID(x,y,z,marker | ( layer << CED_LAYER_SHIFT ),size,color, MCP->id());
484  ced_hit_ID(x,y,z,marker, layer,size,color, MCP->id());
485 
486 
487  }
488  }
489  }
490 
491  if ( col->getTypeName() == LCIO::SIMCALORIMETERHIT ) {
492 
493  int n = col->getNumberOfElements();
494 
495  for (int i = 0; i < n; ++i) {
496 
497  SimCalorimeterHit* hit = dynamic_cast<SimCalorimeterHit*>(col->getElementAt(i));
498 
499  int nMC = hit->getNMCContributions();
500 
501  bool found = false;
502  for (int j = 0; j < nMC; ++j) {
503  if (hit->getParticleCont(j) == MCP) {
504  found = true;
505  break;
506  }
507  }
508 
509  if (found) {
510 
511  double x = hit->getPosition()[0];
512  double y = hit->getPosition()[1];
513  double z = hit->getPosition()[2];
514  //ced_hit_ID(x,y,z,marker | ( layer << CED_LAYER_SHIFT ),size,color, MCP->id());
515  ced_hit_ID(x,y,z,marker,layer,size,color, MCP->id());
516 
517 
518  }
519  }
520  }
521  }
522  }
523 
524 
525 
526 } ;
527 
528 
529 
533 extern "C"
534 void drawDetectorFromGearFile( const char* fname ) ;
535 
536 extern "C"
537 void draw_helix( float b, float charge, float x, float y, float z,
538  float px, float py, float pz,
539  int marker, int size, unsigned int col,
540  float rmin=10.0, float rmax=3000.0, float zmax=4500.0, unsigned int id = 0) ;
541 
542 
543 
544 
545 #endif
546 
547 
548 
549 
static void defaultOutputFunction(const LCObject *obj)
The default print method for all LCIO objects.
Definition: MarlinCED.h:86
Abstract trajectory interface describing a geometrical path in 3D space.
Definition: Trajectory.h:13
Bring the feature to print a LCIO-Objekt given by his ID.
Definition: MarlinCED.h:54
Singleton class to manage access to CED from several processors.
Definition: MarlinCED.h:132
Definition: MarlinCED.h:39
static void drawDetector(int modelID)
Draws the detector only.
Definition: MarlinCED.h:246
static void drawObjectsWithPosition(In first, In last, int marker, int size, unsigned int color, unsigned int layer=0, const char *PickingMessage="")
Draw all objects in iterator range [first,last) which have a method getPosition() with the given colo...
Definition: MarlinCED.h:174