9 #include <marlin/AIDAProcessor.h>
13 #include <marlin/Global.h>
14 #include <gear/GEAR.h>
15 #include <gear/VXDParameters.h>
16 #include <gear/VXDLayerLayout.h>
21 #include <EVENT/LCCollection.h>
22 #include <IMPL/LCCollectionVec.h>
23 #include <IMPL/SimTrackerHitImpl.h>
26 #include <gsl/gsl_randist.h>
33 using namespace lcio ;
34 using namespace marlin ;
43 _description =
"VTXNoiseClusters adds SimTrackerHits with salt'n pepper noise clusters" ;
48 FloatVec densityDefault(6) ;
49 for(
int i=0 ;i<6; i++ )
50 densityDefault[i] = 0.0 ;
53 registerProcessorParameter(
"HitDensityPerLayer_VTX" ,
54 "hit densities (hits/cm^2) per VXD layer" ,
61 rootDefault[0] =
"sap2VXD05_1.root" ;
62 rootDefault[1] =
"hst1" ;
63 rootDefault[2] =
"hst2" ;
64 rootDefault[3] =
"hst3" ;
65 rootDefault[4] =
"hst4" ;
66 rootDefault[5] =
"hst5" ;
67 rootDefault[6] =
"hst6" ;
69 registerProcessorParameter(
"RootHistograms" ,
70 "root file name and histogram names (one per layer)" ,
76 registerInputCollection( LCIO::SIMTRACKERHIT,
78 "Name of the VTX SimTrackerHit collection" ,
80 std::string(
"VXDCollection") ) ;
83 registerProcessorParameter(
"RandomSeed" ,
84 "random seed - default 42" ,
103 _rng = gsl_rng_alloc(gsl_rng_ranlxs2) ;
110 const gear::VXDParameters& gearVXD = Global::GEAR->getVXDParameters() ;
111 const gear::VXDLayerLayout& layerVXD = gearVXD.getVXDLayerLayout();
113 if( (
unsigned) layerVXD.getNLayers() !=
_rootNames.size() - 1 ){
115 streamlog_out( ERROR ) <<
" *************************************************** " << std::endl
116 <<
" wrong number of histograms: " <<
_rootNames.size()
117 <<
" for " << layerVXD.getNLayers() <<
" VXD layers "
118 <<
" - do nothing ! " << std::endl
119 <<
" *************************************************** " << std::endl ;
126 _hfile =
new TFile( filename.c_str() );
128 if( !
_hfile->IsOpen() ) {
130 std::string mess(
" can't open root file :") ;
133 throw Exception( mess ) ;
136 streamlog_out(DEBUG4) <<
"Read histograms from file : " << filename << endl;
141 _hist.resize( layerVXD.getNLayers() ) ;
143 for(
int i=0;i<layerVXD.getNLayers(); ++i ){
146 streamlog_out(DEBUG4) <<
" " <<
_rootNames[i+1].c_str() <<
": .... " ;
151 std::string mess(
" can't read histogram :") ;
153 throw Exception( mess ) ;
155 streamlog_out(DEBUG4) <<
" OK at :" <<
_hist[i] << std::endl ;
157 streamlog_out(DEBUG) <<
" 2D histo - bins (x,y): "
158 <<
_hist[i]->GetNbinsX() <<
", "
159 <<
_hist[i]->GetXaxis()->GetBinLowEdge(1) <<
", "
160 <<
_hist[i]->GetXaxis()->GetBinLowEdge(
_hist[i]->GetNbinsX() )
161 +
_hist[i]->GetXaxis()->GetBinWidth(
_hist[i]->GetNbinsX() ) <<
" , "
162 <<
_hist[i]->GetNbinsY() <<
", "
163 <<
_hist[i]->GetYaxis()->GetBinLowEdge(1) <<
", "
164 <<
_hist[i]->GetYaxis()->GetBinLowEdge(
_hist[i]->GetNbinsY() )
165 +
_hist[i]->GetYaxis()->GetBinWidth(
_hist[i]->GetNbinsY() )
182 LCCollection* col = 0 ;
189 catch(DataNotAvailableException &
e){
192 streamlog_out( WARNING ) <<
" VTX collection " <<
_colNameVTX
193 <<
" not found - do nothing ! " << std::endl ;
224 const gear::VXDParameters& gearVXD = Global::GEAR->getVXDParameters() ;
225 const gear::VXDLayerLayout& layerVXD = gearVXD.getVXDLayerLayout();
228 if( (
unsigned) layerVXD.getNLayers() !=
_densities.size() ){
231 streamlog_out( ERROR ) <<
" *************************************************** " << std::endl
232 <<
" wrong number of hit densities: " <<
_densities.size()
233 <<
" for " << layerVXD.getNLayers() <<
" VXD layers "
234 <<
" - do nothing ! " << std::endl
235 <<
" *************************************************** " << std::endl ;
241 double hgap = gearVXD.getShellGap() / 2. ;
243 for(
int i=0 ; i < layerVXD.getNLayers() ; i++ ) {
245 double width = layerVXD.getSensitiveWidth (i) ;
246 double len = layerVXD.getSensitiveLength (i) ;
249 double area = 2 * len * width / 100. ;
251 int nLad = layerVXD.getNLadders(i) ;
253 for(
int j=0 ; j < nLad ; j++ ) {
257 streamlog_out( DEBUG ) <<
" layer: " << i <<
" - ladder: " << j
260 <<
" #hits: " << nHit
263 for(
int k=0 ;
k< nHit ;
k++){
265 double l1 = gsl_rng_uniform(
_rng ) ;
266 double l2 = gsl_rng_uniform(
_rng ) ;
270 double k1 = 0.5 - l1 ;
273 double k2 = ( (
k % 2) ? -1. : 1. ) * l2 ;
280 if( ! gearVXD.isPointInSensitive( lab ) ){
281 streamlog_out( WARNING ) <<
" created hit outside sensitve volume " << lab << std::endl ;
284 SimTrackerHitImpl *hit =
new SimTrackerHitImpl() ;
286 double pos[3] = { lab[0] , lab[1] , lab[2] } ;
288 hit->setPosition( pos ) ;
293 hit->setCellID0( i + 1 ) ;
297 double cluZ, cluRPhi ;
300 _hist[i]->GetRandom2( cluZ, cluRPhi ) ;
317 col->addElement( hit ) ;
332 #ifdef MARLIN_USE_AIDA
345 if( isFirstEvent() ) {
347 _hist1DVec.resize( H1D::size ) ;
349 float hitMax = 100000. ;
350 _hist1DVec[ H1D::hitsLayer1 ] = AIDAProcessor::histogramFactory(
this)->createHistogram1D(
"hitsLayer1",
353 _hist1DVec[ H1D::hitsLayer2 ] = AIDAProcessor::histogramFactory(
this)->createHistogram1D(
"hitsLayer2",
356 _hist1DVec[ H1D::hitsLayer3 ] = AIDAProcessor::histogramFactory(
this)->createHistogram1D(
"hitsLayer3",
359 _hist1DVec[ H1D::hitsLayer4 ] = AIDAProcessor::histogramFactory(
this)->createHistogram1D(
"hitsLayer4",
362 _hist1DVec[ H1D::hitsLayer5 ] = AIDAProcessor::histogramFactory(
this)->createHistogram1D(
"hitsLayer5",
365 _hist1DVec[ H1D::hitsLayer6 ] = AIDAProcessor::histogramFactory(
this)->createHistogram1D(
"hitsLayer6",
370 _hist2DVec.resize( H1D::size ) ;
372 for(
int i=0 ; i < H1D::size ; ++i ){
374 std::stringstream
name(
"clusSizLayer") ;
377 std::stringstream comment(
"cluster sizes in layer ") ;
381 int nx =
_hist[i]->GetNbinsX() ;
382 float xMin =
_hist[i]->GetXaxis()->GetBinLowEdge(1) ;
383 float xMax =
_hist[i]->GetXaxis()->GetBinLowEdge(
_hist[i]->GetNbinsX() )
384 +
_hist[i]->GetXaxis()->GetBinWidth(
_hist[i]->GetNbinsX() ) ;
386 int ny =
_hist[i]->GetNbinsY() ;
387 float yMin =
_hist[i]->GetYaxis()->GetBinLowEdge(1) ;
388 float yMax =
_hist[i]->GetYaxis()->GetBinLowEdge(
_hist[i]->GetNbinsY() )
389 +
_hist[i]->GetYaxis()->GetBinWidth(
_hist[i]->GetNbinsY() ) ;
392 _hist2DVec[i] = AIDAProcessor::histogramFactory(
this)
393 ->createHistogram2D( name.str() ,
407 LCCollection* vxdCol = 0 ;
421 int nH = vxdCol->getNumberOfElements() ;
424 for(
int i=0; i<nH ; ++i){
426 SimTrackerHit* sth =
dynamic_cast<SimTrackerHit*
>( vxdCol->getElementAt(i) ) ;
428 int layer = ( sth->getCellID0() & 0xff ) ;
443 double cluA = axisAlab.r() ;
444 double cluB = axisBlab.r() ;
449 #ifdef MARLIN_USE_AIDA
450 _hist2DVec[ layer-1 ]->fill( cluB *2. , cluA * 2. ) ;
477 }
catch( DataNotAvailableException&
e) {}
479 #ifdef MARLIN_USE_AIDA
480 _hist1DVec[ H1D::hitsLayer1 ]->fill( nHitL1 ) ;
481 _hist1DVec[ H1D::hitsLayer2 ]->fill( nHitL2 ) ;
482 _hist1DVec[ H1D::hitsLayer3 ]->fill( nHitL3 ) ;
483 _hist1DVec[ H1D::hitsLayer4 ]->fill( nHitL4 ) ;
484 _hist1DVec[ H1D::hitsLayer5 ]->fill( nHitL5 ) ;
485 _hist1DVec[ H1D::hitsLayer6 ]->fill( nHitL6 ) ;
493 std::cout <<
"VTXNoiseClusters::end() " <<
name()
494 <<
" processed " <<
_nEvt <<
" events in " <<
_nRun <<
" runs "
void modifyEvent(LCEvent *evt)
Called for every event - the working horse.
virtual void check(LCEvent *evt)
virtual void processEvent(LCEvent *evt)
VTXNoiseClusters aVTXNoiseClusters
gear::Vector3D ladder2LabPos(gear::Vector3D ladderPos, int layerID, int ladderID)
Convert a position in local ladder coordinates (x_ladder==0 is the middle of the sensitive) to the la...
CLHEP::Hep3Vector Vector3D
Allows to use VXDClusterParameters as runtime extension object.
======= VXDGeometry ========== Helper class for VXD geomtry transformations: from lab frame to ladd...
gear::Vector3D getClusterAxisA()
std::vector< TH2F * > _hist
virtual void end()
Called after data processing for clean up.
gear::Vector3D getClusterAxisB()
virtual void init()
Called at the begin of the job before anything is read.
virtual const std::string & name() const
virtual void processRunHeader(LCRunHeader *run)
Called for every run.
std::vector< std::string > StringVec