All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
VTXBgClusters.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 #include "VTXBgClusters.h"
3 #include "VXDGeometry.h"
4 #include "VXDClusterParameters.h"
5 
6 //#include <iostream>
7 
8 #include <EVENT/LCCollection.h>
9 //#include <IMPL/LCCollectionVec.h>
10 #include <EVENT/SimTrackerHit.h>
11 //#include <IMPL/TrackerHitImpl.h>
12 //#include <EVENT/MCParticle.h>
13 // #include "random.h"
14 // #include <CLHEP/Random/RandGauss.h>
15 //#include <gsl/gsl_randist.h>
16 
17 #include <gear/GEAR.h>
18 #include <marlin/Global.h>
19 #ifdef MARLIN_USE_AIDA
20 #include <marlin/AIDAProcessor.h>
21 #endif
22 
23 #include <cmath>
24 #include <math.h>
25 
26 using namespace lcio ;
27 using namespace marlin ;
28 using namespace std ;
29 
31 
32 
33 VTXBgClusters::VTXBgClusters() : Processor("VTXBgClusters") {
34 
35  // modify processor description
36  _description = "VTXBgClusters should create VTX TrackerHits from SimTrackerHits" ;
37 
38 
39  // register steering parameters: name, description, class-variable, default value
40 
41  registerProcessorParameter( "RemoveDrays" ,
42  "Remove D-rays ?",
44  int(0));
45 
46  registerProcessorParameter( "MomentumCutForDRays" ,
47  "Momentum Cut For D Rays (MeV)",
48  _momCut ,
49  float(10.0));
50 
51  registerProcessorParameter( "Debug",
52  "Debugging option",
53  _debug,
54  int(0));
55 
56  registerProcessorParameter( "Modif",
57  "sensor modification option",
58  _mod,
59  int(0));
60 
61  // Input collections
62  registerInputCollection( LCIO::SIMTRACKERHIT,
63  "VTXCollectionName" ,
64  "Name of the VTX SimTrackerHit collection" ,
65  _colNameVTX ,
66  std::string("VXDCollection") ) ;
67 
68  //fg: not needed...
69 // // Output collections
70 // registerOutputCollection( LCIO::TRACKERHIT,
71 // "VTXHitCollection" ,
72 // "Name of the vxd TrackerHit output collection" ,
73 // _outColNameVTX ,
74 // std::string("VTXTrackerHits") ) ;
75 
76 }
77 
78 
80 
81  // usually a good idea to
82  printParameters() ;
83 
84  _nRun = 0 ;
85  _nEvt = 0 ;
86 
87  _vxdGeo = new VXDGeometry( Global::GEAR ) ;
88 
89  //fg: not needed
90  //r = gsl_rng_alloc(gsl_rng_ranlxs2);
91 
92  //fg: these should become processor parameters at some point:
93  if (_mod==0){
94  _epi=1;
95  for(int i=0; i<6; i++) {
96  _pitch[i]=25;
97  _it[i]=200;
98  _it[0]=50;
99  _it[1]=50;
100  }
101  std::cout << "------------STANDARD mode for sensor--------------- " << std::endl;
102 
103  } else{
104  _epi=0.015/0.05;
105  for(int i=0; i<6; i++) {
106  _pitch[i]=33;
107  _pitch[0]=20;
108  _pitch[1]=20;
109  _it[i]=100;
110  _it[0]=25;
111  _it[1]=25;
112  }
113  std::cout << "------------MODIFIED mode for sensor--------------- " << std::endl;
114  }
115 }
116 
117 void VTXBgClusters::processRunHeader( LCRunHeader* /*run*/) {
118  _nRun++ ;
119 }
120 
121 void VTXBgClusters::processEvent( LCEvent * evt ) {
122 
123  LCCollection* STHcol = 0 ;
124  try{
125  STHcol = evt->getCollection( _colNameVTX ) ;
126  }
127  catch(DataNotAvailableException &e){
128  streamlog_out( DEBUG ) << "Collection " << _colNameVTX.c_str() << " is unavailable in event "
129  << _nEvt << std::endl;
130 
131  }
132 
133 
134  if( STHcol != 0 ){
135 
136  //fg: not needed LCCollectionVec* trkhitVec = new LCCollectionVec( LCIO::TRACKERHIT ) ;
137 
138  int nSimHits = STHcol->getNumberOfElements() ;
139 
140  for(int i=0; i< nSimHits; i++){
141 
142  SimTrackerHit* SimTHit = dynamic_cast<SimTrackerHit*>( STHcol->getElementAt( i ) ) ;
143 
144  bool accept = 1;
145 
146  float totMomentum = 0;
147  if (_removeDRays) { // check if hit originates from delta-electron
148  for (int i=0;i<3;++i)
149  totMomentum+=SimTHit->getMomentum()[i]*SimTHit->getMomentum()[i];
150  totMomentum = sqrt(totMomentum);
151  if (totMomentum < _momCut)
152  accept = 0;
153  }
154 
155  if (accept == 1) {
156 
157  /* the equation of the ellipse is
158  y'**2/sma**2 + z'**2/SMA**2
159  where y'-z' is the reference system which coincide with the axes of the ellipse
160  and with origin in the center of the ellipse.
161  z' coincide with is the direction of the particle.
162  */
163 
164  const int cellId = SimTHit->getCellID0() ;
165  //fg: cellId is 'layer + 1' - we need layerId
166  const int layerId = ( cellId & 0xff ) - 1 ;
167 
168  //calculate the two axis of the ellipse that approximate the cluster
169  double effpl = SimTHit->getPathLength()*_epi; //effective path length on the ladder surface
170 
171  double sma; //ellipse minor axis
172  if (_mod==0)
173  sma=3*_pitch[layerId];
174  else sma=4*_pitch[layerId];
175 
176  double SMA = ((int)(effpl*1000/_pitch[layerId] -1/4) +4)*_pitch[layerId]; //ellipse major axis - effpl in mm
177  sma*= (0.001 / 2.) ; //in mm and half axis
178  SMA*= (0.001 / 2.) ; //in mm and half axis
179 
180 
181  //calculate the ladder where the hit has taken place
182  gear::Vector3D pos(SimTHit->getPosition()[0],SimTHit->getPosition()[1],SimTHit->getPosition()[2]) ;
183  int ladderId = (_vxdGeo->getLadderID(pos,layerId)).second;
184 
185  streamlog_out( DEBUG ) << " eff. path length : " << effpl
186  << " SMA " << SMA
187  << " sma " << sma
188  << " layerId : " << layerId
189  << " ladderId : " << ladderId
190  << std::endl ;
191 
192 
193  //calculate the momentum of the hit in the ladder ref.syst.
194  gear::Vector3D mom(SimTHit->getMomentum()[0],SimTHit->getMomentum()[1],SimTHit->getMomentum()[2]);
195  gear::Vector3D laddermom = _vxdGeo->lab2LadderDir(mom,layerId,ladderId) ;
196  double modladdermom = sqrt(laddermom[1]*laddermom[1]+laddermom[2]*laddermom[2]);
197 
198  //calculate the direction of the SMA (which lays on the y-z plane)
199  gear::Vector3D dSMAladder(0,SMA*laddermom[1]/modladdermom,SMA*laddermom[2]/modladdermom);
200 
201  //calculate the direction of the sma (orthogonal to SMA on the y-z plane)
202  gear::Vector3D dsmaladder(0,sma*laddermom[2]/modladdermom,sma*laddermom[1]/modladdermom);
203 
204 // //calculate the direction of the SMA in the lab frame
205 // gear::Vector3D dSMA = _vxdGeo->ladder2LabDir(dSMAladder,layerId,ladderId);
206 // //calculate the direction of the sma in the lab frame
207 // gear::Vector3D dsma = _vxdGeo->ladder2LabDir(dsmaladder,layerId,ladderId);
208 // SimTHit->ext< ClusterParams >() = new VXDClusterParameters( dSMA , dsma , layerId, ladderId) ;
209 
210  // compute the hit position in ladder coordinates:
211  gear::Vector3D locPos = _vxdGeo->lab2LadderPos(pos,layerId,ladderId);
212 
213  SimTHit->ext< ClusterParams >() = new VXDClusterParameters(locPos,
214  dSMAladder, dsmaladder,
215  layerId,ladderId ) ;
216 
217  }
218 
219  }
220  }
221 
222  _nEvt ++ ;
223 }
224 
225 
226 
227 void VTXBgClusters::check( LCEvent * evt ) {
228 
229  // create some histograms with VXD hit densities and cluster sizes...
230 
231 #ifdef MARLIN_USE_AIDA
232  struct H1D{
233  enum {
234  hitsLayer1,
235  hitsLayer2,
236  hitsLayer3,
237  hitsLayer4,
238  hitsLayer5,
239  hitsLayer6,
240  size
241  } ;
242  };
243 
244  if( isFirstEvent() ) {
245 
246  _hist1DVec.resize( H1D::size ) ;
247 
248  float hitMax = 1000. ;
249  _hist1DVec[ H1D::hitsLayer1 ] = AIDAProcessor::histogramFactory(this)->createHistogram1D( "hitsLayer1",
250  "hits Layer 1",
251  100, 0. ,hitMax ) ;
252  _hist1DVec[ H1D::hitsLayer2 ] = AIDAProcessor::histogramFactory(this)->createHistogram1D( "hitsLayer2",
253  "hits Layer 2",
254  100, 0. , hitMax ) ;
255  _hist1DVec[ H1D::hitsLayer3 ] = AIDAProcessor::histogramFactory(this)->createHistogram1D( "hitsLayer3",
256  "hits Layer 3",
257  100, 0. , hitMax ) ;
258  _hist1DVec[ H1D::hitsLayer4 ] = AIDAProcessor::histogramFactory(this)->createHistogram1D( "hitsLayer4",
259  "hits Layer 4",
260  100, 0. ,hitMax ) ;
261  _hist1DVec[ H1D::hitsLayer5 ] = AIDAProcessor::histogramFactory(this)->createHistogram1D( "hitsLayer5",
262  "hits Layer 5",
263  100, 0. , hitMax ) ;
264  _hist1DVec[ H1D::hitsLayer6 ] = AIDAProcessor::histogramFactory(this)->createHistogram1D( "hitsLayer6",
265  "hits Layer 6",
266  100, 0. , hitMax ) ;
267 
268 
269  _hist2DVec.resize( H1D::size ) ;
270 
271  for(int i=0 ; i < H1D::size ; ++i ){
272 
273  std::stringstream name ;
274  name << "clusSizLayer" << i ;
275 
276  std::stringstream comment ;
277  comment << "cluster sizes in layer " << i ;
278 
279 
280  int nx = 200 ;
281  float xMin = 0. ;
282  float xMax = 4. ;
283 
284  int ny = 200 ;
285  float yMin = 0. ;
286  float yMax = 4. ;
287 
288 
289  _hist2DVec[i] = AIDAProcessor::histogramFactory(this)
290  ->createHistogram2D( name.str() ,
291  comment.str() ,
292  nx, xMin, xMax ,
293  ny, yMin, yMax ) ;
294 
295  }
296 
297 
298 
299  }
300 #endif
301 
302 
303 
304  LCCollection* vxdCol = 0 ;
305 
306 // int nhit = 0 ;
307  int nHitL1 = 0 ;
308  int nHitL2 = 0 ;
309  int nHitL3 = 0 ;
310  int nHitL4 = 0 ;
311  int nHitL5 = 0 ;
312  int nHitL6 = 0 ;
313 
314 
315  try {
316  vxdCol = evt->getCollection( _colNameVTX ) ;
317 
318  int nH = vxdCol->getNumberOfElements() ;
319 
320 
321  for(int i=0; i<nH ; ++i){
322 
323  SimTrackerHit* sth = dynamic_cast<SimTrackerHit*>( vxdCol->getElementAt(i) ) ;
324 
325  int layer = ( sth->getCellID0() & 0xff ) - 1 ;
326 
327  // --- cluster axes in lab frame
328  VXDClusterParameters* cluP = sth->ext< ClusterParams >() ;
329 
330 
331 
332  if( cluP != 0 ) { // physics hits have no cluster parameters
333 
334  // now get cluster axis vector:
335 
336  gear::Vector3D axisAlad = cluP->getClusterAxisA() ;
337  gear::Vector3D axisBlad = cluP->getClusterAxisB() ;
338 
339  // fg: fixme this is not the exact projection of the rectangle....
340  double za = std::abs( axisAlad.z() ) ;
341  double zb = std::abs( axisBlad.z() ) ;
342  double ya = std::abs( axisAlad.y() ) ;
343  double yb = std::abs( axisBlad.y() ) ;
344 
345  double zPro = ( za > zb ? za : zb ) ;
346  double yPro = ( ya > yb ? ya : yb ) ;
347 
348 #ifdef MARLIN_USE_AIDA
349  _hist2DVec[ layer ]->fill( zPro , yPro ) ;
350 #endif
351 
352 
353 
354  //====== uncomment for testing the isPointInClusterEllipse method ============================
355  /*
356  gear::Vector3D pos( sth->getPosition()[0] , sth->getPosition()[1] , sth->getPosition()[2] ) ;
357  gear::Vector3D ladPos = _vxdGeo->lab2LadderPos(pos , layer , cluP->getLadderId() ) ;
358 
359  if( ! cluP->isPointInClusterEllipse( ladPos ) )
360 
361  streamlog_out( ERROR ) << " point " << ladPos << " is not in ellipse "
362  << " a: " << axisAlad << " b: " << axisBlad
363  << " at " << cluP->getClusterPosition()
364  << std::endl ;
365 
366  if( cluP->isPointInClusterEllipse( ladPos + 1.01 * axisAlad ) )
367 
368  streamlog_out( ERROR ) << " point " << ladPos + 1.01 * axisAlad << " is in ellipse "
369  << " a: " << axisAlad << " b: " << axisBlad
370  << " at " << cluP->getClusterPosition()
371  << std::endl ;
372  */
373  //====== uncomment for testing the isPointInClusterEllipse method ============================
374 
375 
376  }
377 
378  switch (layer) {
379 
380  case 0 :
381  nHitL1++ ;
382  break ;
383  case 1 :
384  nHitL2++ ;
385  break ;
386  case 2 :
387  nHitL3++ ;
388  break ;
389  case 3 :
390  nHitL4++ ;
391  break ;
392  case 4 :
393  nHitL5++ ;
394  break ;
395  case 5 :
396  nHitL6++ ;
397  break ;
398  }
399 
400  }
401  } catch( DataNotAvailableException& e) {}
402 
403 #ifdef MARLIN_USE_AIDA
404  _hist1DVec[ H1D::hitsLayer1 ]->fill( nHitL1 ) ;
405  _hist1DVec[ H1D::hitsLayer2 ]->fill( nHitL2 ) ;
406  _hist1DVec[ H1D::hitsLayer3 ]->fill( nHitL3 ) ;
407  _hist1DVec[ H1D::hitsLayer4 ]->fill( nHitL4 ) ;
408  _hist1DVec[ H1D::hitsLayer5 ]->fill( nHitL5 ) ;
409  _hist1DVec[ H1D::hitsLayer6 ]->fill( nHitL6 ) ;
410 #endif
411 }
412 
413 
415 
416  streamlog_out( DEBUG4 ) << "VTXBgClusters::end() " << name()
417  << " processed " << _nEvt << " events in " << _nRun << " runs "
418  << std::endl ;
419 }
420 
VTXBgClusters aVTXBgClusters
virtual void check(LCEvent *evt)
CLHEP::Hep3Vector Vector3D
Allows to use VXDClusterParameters as runtime extension object.
======= VXDGeometry ========== Helper class for VXD geomtry transformations: from lab frame to ladd...
Definition: VXDGeometry.h:53
gear::Vector3D getClusterAxisA()
gear::Vector3D lab2LadderDir(gear::Vector3D labPos, int layerID, int ladderID)
Convert a direction in the lab frame to local ladder coordinates (x_ladder==0 is the middle of the se...
Definition: VXDGeometry.cc:162
virtual void processEvent(LCEvent *evt)
Called for every event - the working horse.
virtual void processRunHeader(LCRunHeader *run)
Called for every run.
virtual void end()
Called after data processing for clean up.
gear::Vector3D lab2LadderPos(gear::Vector3D labPos, int layerID, int ladderID)
Convert a position in the lab frame to local ladder coordinates (x_ladder==0 is the middle of the sen...
Definition: VXDGeometry.cc:141
static const float e
VXDGeometry * _vxdGeo
std::string _colNameVTX
Definition: VTXBgClusters.h:92
float _pitch[6]
std::pair< int, int > getLadderID(gear::Vector3D labPos, int layerID=-1)
Return the pair (layerID, ladderID) for the given position, (-1,-1) if not in sensitive volume (in th...
Definition: VXDGeometry.cc:181
gear::Vector3D getClusterAxisB()
virtual void init()
Called at the begin of the job before anything is read.