All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
VTXNoiseHits.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 #include "VTXNoiseHits.h"
3 
4 #include <iostream>
5 
6 #include <EVENT/LCCollection.h>
7 #include <IMPL/LCCollectionVec.h>
8 
9 #include <IMPL/TrackerHitImpl.h>
10 
11 // #include <CLHEP/Random/RandGauss.h>
12 #include <gsl/gsl_randist.h>
13 
14 #include <cmath>
15 #include <math.h>
16 
17 using namespace lcio ;
18 using namespace marlin ;
19 using namespace std ;
20 
22 
23 
24 VTXNoiseHits::VTXNoiseHits() : Processor("VTXNoiseHits") {
25 
26  // modify processor description
27  _description = "VTXNoiseHits should create VTX TrackerHits from SimTrackerHits" ;
28 
29 
30  // register steering parameters: name, description, class-variable, default value
31 
32  FloatVec densityDefault(5) ;
33  for(int i=0 ;i<5; i++ )
34  densityDefault[i] = 0.0 ;
35 
36 
37  registerProcessorParameter( "HitDensityPerLayer_VTX" ,
38  "hit densities (hits/cm^2) per VXD layer" ,
39  _densities ,
40  densityDefault ) ;
41 
42 
43  // Input collection
44  registerInputCollection( LCIO::TRACKERHIT,
45  "VTXCollectionName" ,
46  "Name of the VTX TrackerHit collection" ,
47  _colNameVTX ,
48  std::string("VTXTrackerHits") ) ;
49 
50 
51  registerProcessorParameter( "PointResolutionRPhi_VTX" ,
52  "R-Phi Resolution in VTX" ,
54  float(0.0027)) ;
55 
56 
57  registerProcessorParameter( "PointResolutionZ_VTX" ,
58  "Z Resolution in VTX" ,
60  float(0.0027));
61 
62 }
63 
64 
66 
67  // usually a good idea to
68  printParameters() ;
69 
70  _nRun = 0 ;
71  _nEvt = 0 ;
72 
73  // initialize gsl random generator
74  // ranlux algorithm of Lüscher, which produces 'luxury random numbers'
75  r = gsl_rng_alloc(gsl_rng_ranlxs2) ;
76 
77  //FIXME: do we want a seed from a processor parameter ?
78 }
79 
80 
81 void VTXNoiseHits::processRunHeader( LCRunHeader* /*run*/) {
82  _nRun++ ;
83 }
84 
85 void VTXNoiseHits::processEvent( LCEvent * evt ) {
86 
87  LCCollection* col = 0 ;
88 
89  try{
90 
91  col = evt->getCollection( _colNameVTX ) ;
92 
93  }
94  catch(DataNotAvailableException &e){
95 
96 
97  streamlog_out( WARNING ) << " VTX collection " << _colNameVTX
98  << " not found - do nothing ! " << std::endl ;
99 
100 
101  return ;
102 
103  }
104 
105  //get VXD geometry info
106  const gear::VXDParameters& gearVXD = Global::GEAR->getVXDParameters() ;
107  const gear::VXDLayerLayout& layerVXD = gearVXD.getVXDLayerLayout();
108 
109  //gear::Vector3D hitvec(pos[0],pos[1],pos[2]);
110 
111  if( (unsigned) layerVXD.getNLayers() != _densities.size() ){
112 
113 
114  streamlog_out( ERROR ) << " *************************************************** " << std::endl
115  << " wrong number of hit densities: " << _densities.size()
116  << " for " << layerVXD.getNLayers() << " VXD layers "
117  << " - do nothing ! " << std::endl
118  << " *************************************************** " << std::endl ;
119 
120  return ;
121 
122  }
123 
124 // double gap = gearVXD.getShellGap () ;
125 
126  for( int i=0 ; i < layerVXD.getNLayers() ; i++ ) {
127 
128  double phi0 = layerVXD.getPhi0 (i) ;
129  double dist = layerVXD.getSensitiveDistance (i) ;
130 
131  double thick = layerVXD.getSensitiveThickness (i) ;
132  double offs = layerVXD.getSensitiveOffset (i) ;
133  double width = layerVXD.getSensitiveWidth (i) ;
134 
135  // -----fg: gear length is half length really !!!!!
136  double len = 2 * layerVXD.getSensitiveLength (i) ;
137 
138 
139  int nLad = layerVXD.getNLadders(i) ;
140 
141  for( int j=0 ; j < nLad ; j++ ) {
142 
143  double phi = phi0 + j * ( 2 * M_PI ) / nLad ;
144 
145  // point in middle of sensitive ladder at z=-len/2
146  gear::Vector3D p0( dist + thick / 2. , phi , - len / 2. , gear::Vector3D::cylindrical ) ;
147 
148  // direction vector along ladder in rphi (negative)
149  gear::Vector3D v0( - (width / 2. - offs ) , phi + M_PI / 2. , 0. , gear::Vector3D::cylindrical ) ;
150 
151  // point p1: 'lower left corner of sensitive surface' (seen from outside)
152  gear::Vector3D p1 = p0 + v0 ;
153 
154  // v1: direction along rphi
155  gear::Vector3D v1( width , phi + M_PI / 2. , 0. , gear::Vector3D::cylindrical ) ;
156 
157  // v2: direction along ladder (z-axis)
158  gear::Vector3D v2( 0. , 0. , len ) ;
159 
160 
161  double area = len * width / 100. ; // mm^2 to cm^2
162 
163 
164  int nHit = gsl_ran_poisson( r, _densities[ i ] * area ) ;
165 
166  streamlog_out( DEBUG ) << " layer: " << i << " - ladder: " << j
167  << " density: " << _densities[ i ]
168  << " area: " << area
169  << " #hits: " << nHit
170  << std::endl ;
171 
172 
173 
174 
175  for( int k=0 ; k< nHit ; k++){
176 
177  double l1 = gsl_rng_uniform( r ) ;
178  double l2 = gsl_rng_uniform( r ) ;
179 
180  gear::Vector3D ph = p1 + l1 * v1 + l2 * v2 ;
181 
182  if( ! gearVXD.isPointInSensitive( ph ) ){
183 
184  streamlog_out( WARNING ) << " created hit outside sensitve volume " << ph << std::endl ;
185  }
186 
187  TrackerHitImpl *hit = new TrackerHitImpl() ;
188 
189  double pos[3] = { ph[0] , ph[1] , ph[2] } ;
190 
191  hit->setPosition( pos ) ;
192 
193  hit->setEDep( 0. ) ; // FIXME: which dedx should be used for noise hits
194 
195  hit->setType( 101 + i ) ; // encoding used in VTXDigi: 100 + layernum + 1
196 
197  //fg: FIXME: this is not quite the proper error matrix for a ladder
198  // and it is also not in cartesian coordiantes
199  // however this is what is done in VTXDigiProcessor as well. ..
200  float covMat[TRKHITNCOVMATRIX]={ 0., 0., _pointResoRPhiVTX * _pointResoRPhiVTX,
201  0., 0., _pointResoZVTX * _pointResoZVTX } ;
202  hit->setCovMatrix(covMat);
203 
204 // const LCObjectVec& simHits = hit->getRawHits() ;
205 // streamlog_out( DEBUG ) << " hit->getRawHits() " << simHits.size() << std::endl ;
206 // for( LCObjectVec::const_iterator objIt = simHits.begin() ;
207 // objIt != simHits.end() ; ++objIt ){
208 // }
209 
210  col->addElement( hit ) ;
211 
212  }
213  }
214  }
215 
216  _nEvt ++ ;
217 }
218 
219 
220 
221  void VTXNoiseHits::check( LCEvent * /*evt*/ ) {
222  // nothing to check here - could be used to fill checkplots in reconstruction processor
223 }
224 
225 
227 
228  std::cout << "VTXNoiseHits::end() " << name()
229  << " processed " << _nEvt << " events in " << _nRun << " runs "
230  << std::endl ;
231 }
232 
233 
float _pointResoZVTX
Definition: VTXNoiseHits.h:81
VTXNoiseHits aVTXNoiseHits
Definition: VTXNoiseHits.cc:21
std::string _colNameVTX
Definition: VTXNoiseHits.h:78
CLHEP::Hep3Vector Vector3D
static const float k
virtual void init()
Called at the begin of the job before anything is read.
Definition: VTXNoiseHits.cc:65
static const float e
FloatVec _densities
Definition: VTXNoiseHits.h:79
virtual void processRunHeader(LCRunHeader *run)
Called for every run.
Definition: VTXNoiseHits.cc:81
float _pointResoRPhiVTX
Definition: VTXNoiseHits.h:80
virtual void processEvent(LCEvent *evt)
Called for every event - the working horse.
Definition: VTXNoiseHits.cc:85
virtual void check(LCEvent *evt)
virtual void end()
Called after data processing for clean up.
gsl_rng * r
Definition: VTXNoiseHits.h:86