5 #include <EVENT/LCCollection.h>
6 #include <IMPL/LCCollectionVec.h>
7 #include <EVENT/SimTrackerHit.h>
8 #include <IMPL/TrackerHitImpl.h>
9 #include <EVENT/MCParticle.h>
12 #include <gsl/gsl_randist.h>
13 #include "marlin/ProcessorEventSeeder.h"
16 #include "CLHEP/Vector/TwoVector.h"
22 using namespace lcio ;
23 using namespace marlin ;
32 _description =
"VTXDigiProcessor should create VTX TrackerHits from SimTrackerHits" ;
37 registerProcessorParameter(
"SmearAlongLadders" ,
38 "Points smeared along the ladders" ,
42 registerProcessorParameter(
"PointResolutionRPhi_VTX" ,
43 "R-Phi Resolution in VTX" ,
47 registerProcessorParameter(
"PointResolutionZ_VTX" ,
48 "Z Resolution in VTX" ,
52 registerProcessorParameter(
"PointResolutionRPhi_SIT" ,
53 "R-Phi Resolution in SIT" ,
57 registerProcessorParameter(
"PointResolutionZ_SIT" ,
58 "Z Resolution in SIT" ,
62 registerProcessorParameter(
"PointResolutionRPhi_SET" ,
63 "R-Phi Resolution in SET" ,
67 registerProcessorParameter(
"PointResolutionZ_SET" ,
68 "Z Resolution in SET" ,
72 std::vector<int> activeSETLayers ;
73 activeSETLayers.push_back( 1 ) ;
75 registerProcessorParameter(
"ActiveSETLayers",
76 "only SET hits from active layers are digitized (mimic stereo layers)",
80 registerProcessorParameter(
"RemoveDrays" ,
85 registerProcessorParameter(
"MomentumCutForDRays" ,
86 "Momentum Cut For D Rays (MeV)",
90 registerProcessorParameter(
"Debug",
96 FloatVec effDefault(6) ;
97 for(
int i=0 ;i<6; i++ )
101 registerProcessorParameter(
"HitEfficiencyPerLayer_VTX" ,
102 "hit efficiencies per VXD layer (default: 1.0)" ,
108 registerInputCollection( LCIO::SIMTRACKERHIT,
109 "VTXCollectionName" ,
110 "Name of the VTX SimTrackerHit collection" ,
112 std::string(
"VXDCollection") ) ;
114 registerInputCollection( LCIO::SIMTRACKERHIT,
115 "SITCollectionName" ,
116 "Name of the SIT SimTrackerHit collection" ,
118 std::string(
"SITCollection") ) ;
120 registerInputCollection( LCIO::SIMTRACKERHIT,
121 "SETCollectionName" ,
122 "Name of the SET SimTrackerHit collection" ,
124 std::string(
"SETCollection") ) ;
127 registerOutputCollection( LCIO::TRACKERHIT,
129 "Name of the vxd TrackerHit output collection" ,
131 std::string(
"VTXTrackerHits") ) ;
133 registerOutputCollection( LCIO::TRACKERHIT,
135 "Name of the sit TrackerHit output collection" ,
137 std::string(
"SITTrackerHits") ) ;
139 registerOutputCollection( LCIO::TRACKERHIT,
141 "Name of the set TrackerHit output collection" ,
143 std::string(
"SETTrackerHits") ) ;
157 _rng = gsl_rng_alloc(gsl_rng_ranlxs2);
158 Global::EVENTSEEDER->registerProcessor(
this);
161 const gear::VXDParameters& gearVXD = Global::GEAR->getVXDParameters() ;
162 const gear::VXDLayerLayout& layerVXD = gearVXD.getVXDLayerLayout();
163 const unsigned int nLayer = layerVXD.getNLayers() ;
167 std::stringstream
s ;
168 s <<
" VTXDigiProcessor::init - wrong number of VXD efficiencies given : " <<
_vxdEff.size()
169 <<
" expected one for every " << nLayer <<
" layers " << std::endl ;
170 throw Exception( s.str() ) ;
183 gsl_rng_set(
_rng, Global::EVENTSEEDER->getSeed(
this) ) ;
184 streamlog_out( DEBUG ) <<
"seed set to " << Global::EVENTSEEDER->getSeed(
this) << std::endl;
186 for (
int iColl=0;iColl<3;++iColl) {
188 LCCollection* STHcol = 0 ;
197 catch(DataNotAvailableException &
e){
200 streamlog_out(DEBUG) <<
"Collection " <<
_colNameVTX.c_str() <<
" is unavailable in event " <<
_nEvt << std::endl;
202 streamlog_out(DEBUG) <<
"Collection " <<
_colNameSIT.c_str() <<
" is unavailable in event " <<
_nEvt << std::endl;
204 streamlog_out(DEBUG) <<
"Collection " <<
_colNameSET.c_str() <<
" is unavailable in event " <<
_nEvt << std::endl;
211 int nSimHits = STHcol->getNumberOfElements() ;
213 for(
int i=0; i< nSimHits; i++){
215 SimTrackerHit* SimTHit =
dynamic_cast<SimTrackerHit*
>( STHcol->getElementAt( i ) ) ;
221 int cellID = SimTHit->getCellID0() ;
229 float totMomentum = 0;
230 for (
int i=0;i<3;++i)
232 totMomentum+=SimTHit->getMomentum()[i]*SimTHit->getMomentum()[i];
234 totMomentum = sqrt(totMomentum);
238 streamlog_out( DEBUG ) <<
" removeDRays enabled: hit originates from delta-electron, hit dropped" << std::endl ;
244 const int celId = SimTHit->getCellID0() ;
247 pos = SimTHit->getPosition() ;
249 double smearedPos[3];
254 streamlog_out( DEBUG ) <<
" processing collection " <<
_colNameVTX
255 <<
" with " << nSimHits <<
" hits ... " << std::endl ;
258 int layer = SimTHit->getCellID0() - 1;
263 double urand = gsl_rng_uniform(
_rng ) ;
265 if( urand >
_vxdEff[ layer ] ){
266 streamlog_out( DEBUG ) <<
" dropping hit in layer " << layer << std::endl ;
273 const gear::VXDParameters& gearVXD = Global::GEAR->getVXDParameters() ;
274 const gear::VXDLayerLayout& layerVXD = gearVXD.getVXDLayerLayout();
279 streamlog_out(DEBUG) <<
"Position of hit before smearing = "<<pos[0]<<
" "<<pos[1]<<
" "<<pos[2]<<endl;
286 streamlog_out(DEBUG) <<
"start smearing along ladders for: " << layer << std::endl;
288 int layer = SimTHit->getCellID0() - 1;
291 double deltaPhi = ( 2 * M_PI ) / layerVXD.getNLadders(layer) ;
293 double PhiInLocal(0.0);
295 int ladderIndex = -1;
296 double ladderPhi=999;
298 for (
int ic=0; ic < layerVXD.getNLadders(layer); ++ic) {
300 ladderPhi =
correctPhiRange( layerVXD.getPhi0( layer ) + ic*deltaPhi ) ;
302 PhiInLocal = hitvec.phi() - ladderPhi;
303 double RXY = hitvec.rho();
306 if (RXY*cos(PhiInLocal) - layerVXD.getSensitiveDistance(layer) > -layerVXD.getSensitiveThickness(layer) &&
307 RXY*cos(PhiInLocal) - layerVXD.getSensitiveDistance(layer) < layerVXD.getSensitiveThickness(layer) )
314 double sensitive_width = layerVXD.getSensitiveWidth(layer);
315 double sensitive_offset = layerVXD.getSensitiveOffset(layer);
319 double u = (hitvec.rho() * sin(PhiInLocal) - sensitive_offset );
321 streamlog_out(DEBUG) <<
":"
322 <<
" Event: " <<
_nEvt
324 <<
" of " << nSimHits
325 <<
" layer: " << layer
326 <<
" ladderIndex: " << ladderIndex
327 <<
" half ladder width " << sensitive_width * 0.5
329 <<
" layer sensitive_offset " << sensitive_offset
330 <<
" layer phi0 " << layerVXD.getPhi0( layer )
331 <<
" phi: " << hitvec.phi()
332 <<
" PhiInLocal: " << PhiInLocal
333 <<
" ladderPhi: " << ladderPhi
334 <<
" ladder_incline: " << ladder_incline
337 if( u > sensitive_width * 0.5 || u < -sensitive_width * 0.5)
339 streamlog_out(DEBUG) <<
"hit not in sensitive: u: " << u <<
" half ladder width = " << sensitive_width * 0.5 << std::endl;
345 bool accept_hit =
false;
349 if(tries > 0) streamlog_out(DEBUG) <<
"retry smearing for " << layer <<
" " << ladderIndex <<
" : retries " << tries << std::endl;
356 if( (u+rPhiSmear) < sensitive_width * 0.5 && (u+rPhiSmear) > -sensitive_width * 0.5)
362 smearedPos[0] = hitvec.x() + rPhiSmear * cos(ladder_incline);
363 smearedPos[1] = hitvec.y() + rPhiSmear * sin(ladder_incline);
364 smearedPos[2] = hitvec.z() + zSmear;
370 if( accept_hit ==
false )
372 streamlog_out(DEBUG) <<
"hit could not be smeared within ladder after 100 tries: hit dropped" << std::endl;
380 streamlog_out(DEBUG) <<
"start simple smearing for: " << layer << std::endl;
381 CLHEP::Hep3Vector point(pos[0], pos[1], pos[2]);
389 point.setPhi( point.phi() + rphiSmear / point.perp() );
390 point.setZ( point.z() + zSmear );
392 smearedPos[0] = point.x();
393 smearedPos[1] = point.y();
394 smearedPos[2] = point.z();
413 double phi = atan2(pos[1],pos[0]);
414 double rad = sqrt(pos[1]*pos[1]+pos[0]*pos[0]);
415 double phi_new = phi + xSmear/rad;
416 smearedPos[0] = rad*cos(phi_new);
417 smearedPos[1] = rad*sin(phi_new);
418 smearedPos[2] = pos[2] + zSmear;
423 float dedxSmear = 0.0 ;
424 edep = SimTHit->getEDep() ;
426 edep = edep + dedxSmear ;
429 mcp = SimTHit->getMCParticle() ;
432 TrackerHitImpl* trkHit =
new TrackerHitImpl ;
435 trkHit->setPosition( smearedPos ) ;
437 trkHit->setEDep( edep ) ;
439 trkHit->setType(100+celId );
441 trkHit->setType(400+celId);
445 trkHit->setCovMatrix(covMat);
449 trkHit->rawHits().push_back( SimTHit ) ;
456 trkhitVec->addElement( trkHit ) ;
480 streamlog_out(MESSAGE) <<
" end() " << name()
481 <<
" processed " <<
_nEvt <<
" events in " <<
_nRun <<
" runs "
484 streamlog_out(DEBUG) <<
" VXD hits - efficiency : " << std::endl ;
485 for(
unsigned i=0 ; i<
_vxdCount.size(); ++i) {
487 streamlog_out(DEBUG) <<
" layer " << i <<
" kept "
499 while( (Phi < -1.0*M_PI) || (Phi > 1.0*M_PI) )
virtual void end()
Called after data processing for clean up.
virtual void check(LCEvent *evt)
CLHEP::Hep3Vector Vector3D
std::string _outColNameVTX
std::vector< std::pair< long, long > > _vxdCount
std::string _outColNameSET
std::string _outColNameSIT
VTXDigiProcessor aVTXDigiProcessor
double correctPhiRange(double Phi) const
std::vector< int > _activeSETLayers
virtual void processRunHeader(LCRunHeader *run)
Called for every run.
std::vector< LCCollection * > LCCollectionVec
virtual void processEvent(LCEvent *evt)
Called for every event - the working horse.
virtual void init()
Called at the begin of the job before anything is read.