5 #include <marlin/Global.h>
6 #include <marlin/AIDAProcessor.h>
7 #include <AIDA/ITupleFactory.h>
8 #include <AIDA/ITuple.h>
10 #include <DDSegmentation/BitField64.h>
11 #include <DDRec/CellIDPositionConverter.h>
12 #include <DD4hep/DetectorSelector.h>
16 using namespace lcio ;
17 using namespace marlin ;
25 _tupleHit = AIDAProcessor::tupleFactory( proc )->create(
"SimDigitalGeom",
27 "int chtlayout,module,tower,stave,layer,I,J, float x,y,z, normalx,normaly,normalz, Ix,Iy,Iz,Jx,Jy,Jz");
28 streamlog_out(DEBUG) <<
"Tuple for Hit has been initialized to " << _tupleHit << std::endl;
29 streamlog_out(DEBUG)<<
"it has " << _tupleHit->columns() <<
" columns" <<std::endl;
31 _tupleStep = AIDAProcessor::tupleFactory( proc )->create(
"SimDigitalStep",
32 "SimDigital_DebugStep",
33 "int chtlayout,hitcellid,nstep, float hitx,hity,hitz,stepx,stepy,stepz,deltaI,deltaJ,deltaLayer,time");
34 streamlog_out(DEBUG) <<
"Tuple for Step has been initialized to " << _tupleStep << std::endl;
35 streamlog_out(DEBUG) <<
"it has " << _tupleStep->columns() <<
" columns" <<std::endl;
40 : _decoder(inputCol) , _encoder(inputCol->getParameters().getStringVal(LCIO::CellIDEncoding),outputCol) ,
41 _normal() , _Iaxis() , _Jaxis()
43 outputCol->parameters().setValue(LCIO::CellIDEncoding,inputCol->getParameters().getStringVal(LCIO::CellIDEncoding)) ;
51 streamlog_out( DEBUG ) <<
"we will use lcgeo!" << std::endl ;
58 streamlog_out( DEBUG ) <<
"we will use proto!" << std::endl ;
85 std::map< unsigned int , std::vector<StepAndCharge> > stepMap ;
87 if ( hit->getNMCContributions() == 0 )
90 float currentTime = hit->getTimeCont(0) ;
92 unsigned int currentNum = 0 ;
94 for (
int imcp = 0 ; imcp < hit->getNMCContributions() ; imcp++)
97 const float* pos = hit->getStepPosition(imcp) ;
100 stepPos.set(pos[0],pos[1],pos[2]) ;
106 if ( std::abs( stepPos.z() ) < std::numeric_limits<float>::epsilon() )
108 vec.push_back(
StepAndCharge( stepPos , hit->getLengthCont(imcp) , hit->getTimeCont(imcp)) ) ;
113 if ( hit->getTimeCont(imcp) >= currentTime && (stepID == id) )
114 stepMap[ currentNum ].push_back(
StepAndCharge( stepPos , hit->getLengthCont(imcp) , hit->getTimeCont(imcp)) ) ;
118 stepMap[ currentNum ].push_back(
StepAndCharge( stepPos , hit->getLengthCont(imcp) , hit->getTimeCont(imcp)) ) ;
122 currentTime = hit->getTimeCont(imcp) ;
123 id.PDGStep = hit->getPDGCont(imcp) ;
124 id.PDGParent = hit->getParticleCont(imcp)->getPDG() ;
127 streamlog_out(WARNING) <<
"DIGITISATION : STEP POSITION IS (0,0,0)" << std::endl;
132 for (
auto& it : stepMap )
136 for (
const auto& it : stepMap )
137 for (
const auto& step : it.second )
138 vec.push_back( step ) ;
141 streamlog_out(MESSAGE) <<
"no Steps in hit" << std::endl ;
146 if ( vec.size() < 2 )
149 float time = std::numeric_limits<float>::max() ;
150 float totalLength = 0 ;
151 LCVector3D pos(0,0,0) ;
153 for (
const auto& step : vec )
155 totalLength += step.stepLength ;
156 pos += step.step * step.stepLength ;
157 time = std::min( time , step.time ) ;
161 totalLength =
static_cast<float>( (vec.front().step - vec.back().step).mag() + 0.5f*(vec.front().stepLength + vec.back().stepLength) ) ;
184 catch (lcio::Exception &)
192 catch(lcio::Exception &)
201 if(abs(
_Iy)<1 && abs(
_Iy)!=0.0)
202 streamlog_out(DEBUG) <<
"_Iy, _Jz:"<<
_Iy <<
" "<<
_Jz<< std::endl;
208 dd4hep::Detector& ild = dd4hep::Detector::getInstance() ;
209 dd4hep::rec::CellIDPositionConverter idposConv( ild ) ;
213 dd4hep::long64 id0 = hit->getCellID0() ;
214 dd4hep::long64 id1 = hit->getCellID1() ;
216 idDecoder.setValue( id0 , id1 ) ;
218 dd4hep::long64
id = idDecoder.getValue() ;
219 dd4hep::Position pos_0 = idposConv.position(
id ) ;
222 const float* hitPos = hit->getPosition();
224 streamlog_out( DEBUG ) <<
"hit pos: " << hitPos[0] <<
" " << hitPos[1] <<
" " << hitPos[2] << std::endl;
225 streamlog_out( DEBUG ) <<
"cell pos: " << pos_0.X() <<
" " << pos_0.Y() <<
" " << pos_0.Z() << std::endl;
227 streamlog_out( DEBUG ) <<
"layer: " << idDecoder[_encodingStrings[_encodingType][0]]
228 <<
", stave: " << idDecoder[_encodingStrings[_encodingType][1]]
229 <<
", module: " << idDecoder[_encodingStrings[_encodingType][2]]
230 <<
", tower: " << idDecoder[_encodingStrings[_encodingType][3]]
231 <<
", x: " << idDecoder[_encodingStrings[_encodingType][4]]
232 <<
", y: " << idDecoder[_encodingStrings[_encodingType][5]] << std::endl;
235 double const epsilon = 1.e-3;
238 dd4hep::Position pos_i_plus_1;
239 dd4hep::Position dir_i;
244 idDecoder[ xEncoding ] = idDecoder[ xEncoding ] + 1 ;
245 pos_i_plus_1 = idposConv.position( idDecoder.getValue() ) ;
247 dir_i = pos_i_plus_1 - pos_0 ;
249 if(dir_i.R() < epsilon)
251 idDecoder[ xEncoding ] = idDecoder[ xEncoding ] - 2 ;
252 pos_i_plus_1 = idposConv.position( idDecoder.getValue() ) ;
253 dir_i = - ( pos_i_plus_1 - pos_0 ) ;
257 idDecoder.setValue( id0 , id1 ) ;
260 dd4hep::Position pos_j_plus_1;
261 dd4hep::Position dir_j;
263 idDecoder[ yEncoding ] = idDecoder[ yEncoding ] + 1 ;
264 pos_j_plus_1 = idposConv.position( idDecoder.getValue() ) ;
266 dir_j = pos_j_plus_1 - pos_0 ;
268 if(dir_j.R() < epsilon)
270 idDecoder[ yEncoding ] = idDecoder[ yEncoding ] - 2 ;
271 pos_j_plus_1 = idposConv.position( idDecoder.getValue() ) ;
272 dir_j = - ( pos_j_plus_1 - pos_0 ) ;
275 dd4hep::Position dir_layer = dir_i.Cross( dir_j ) ;
277 dir_layer = - dir_layer.Unit();
281 dir_i = dir_i.Unit();
282 dir_j = dir_j.Unit();
284 _normal.set(dir_layer.X(), dir_layer.Y(), dir_layer.Z()) ;
285 _Iaxis.set(dir_i.X(), dir_i.Y(), dir_i.Z()) ;
286 _Jaxis.set(dir_j.X(), dir_j.Y(), dir_j.Z()) ;
304 std::vector<StepAndCharge> stepsInIJZcoord ;
311 return stepsInIJZcoord ;
340 for (
int i=0; i<3; i++)
354 int nsteps = hit->getNMCContributions() ;
356 for (
int imcp = 0 ; imcp<nsteps ; imcp++)
361 const float* steppos = hit->getStepPosition(imcp) ;
362 for (
int i=0; i<3; i++)
376 if (imcp < (
int)stepsInIJZcoord.size() )
381 if (imcp < (
int)stepsInIJZcoord.size() )
396 int RealIy =
_Iy + delta_I ;
397 int RealJz =
_Jz + delta_J ;
402 std::unique_ptr<CalorimeterHitImpl> hit(
new CalorimeterHitImpl ) ;
411 hit->setPosition(posB) ;
420 int RealIy =
_Iy + delta_I ;
421 int RealJz =
_Jz + delta_J ;
423 if ( RealIy < 0 || RealJz < 0 )
424 return std::unique_ptr<CalorimeterHitImpl>(
nullptr) ;
429 std::unique_ptr<CalorimeterHitImpl> hit(
new CalorimeterHitImpl ) ;
430 _encoder.setCellID( hit.get() ) ;
438 hit->setPosition(posB) ;
447 dd4hep::Detector & ild = dd4hep::Detector::getInstance() ;
451 const std::vector< dd4hep::DetElement>& det = dd4hep::DetectorSelector(ild).detectors(
452 (dd4hep::DetType::CALORIMETER | dd4hep::DetType::HADRONIC | dd4hep::DetType::BARREL),
453 (dd4hep::DetType::AUXILIARY | dd4hep::DetType::FORWARD) ) ;
455 _caloData = det.at(0).extension<dd4hep::rec::LayeredCalorimeterData>();
461 const std::vector< dd4hep::DetElement>& det = dd4hep::DetectorSelector(ild).detectors(
462 (dd4hep::DetType::CALORIMETER | dd4hep::DetType::HADRONIC | dd4hep::DetType::AUXILIARY),
463 dd4hep::DetType::FORWARD) ;
465 _caloData = det.at(0).extension<dd4hep::rec::LayeredCalorimeterData>();
472 const std::vector< dd4hep::DetElement>& det = dd4hep::DetectorSelector(ild).detectors(
473 (dd4hep::DetType::CALORIMETER | dd4hep::DetType::HADRONIC | dd4hep::DetType::ENDCAP),
474 (dd4hep::DetType::AUXILIARY | dd4hep::DetType::FORWARD) ) ;
476 _caloData = det.at(0).extension<dd4hep::rec::LayeredCalorimeterData>();
489 float cellSize = 0.f ;
490 const double CM2MM = 10.0 ;
497 const std::vector<dd4hep::rec::LayeredCalorimeterStruct::Layer>& hcalBarrelLayers =
_caloData->layers ;
498 cellSize = hcalBarrelLayers[
_trueLayer].cellSize0 * CM2MM ;
501 if ( cellSize < std::numeric_limits<float>::epsilon() )
502 streamlog_out( WARNING ) <<
"Cell Size is 0" << std::endl ;
static void bookTuples(const marlin::Processor *proc)
virtual void processGeometry(SimCalorimeterHit *hit)
void fillDebugTupleGeometryStep(SimCalorimeterHit *hit, const std::vector< StepAndCharge > &stepsInIJZcoord)
virtual void processGeometry(SimCalorimeterHit *hit)
dd4hep::long64 _cellIDvalue
std::vector< std::string > _encodingString
SimDigitalGeomCellId(LCCollection *inputCol, LCCollectionVec *outputCol)
const float * _hitPosition
CellIDDecoder< SimCalorimeterHit > _decoder
std::vector< StepAndCharge > decode(SimCalorimeterHit *hit, bool link)
virtual float getCellSize()
static AIDA::ITuple * _tupleStep
void createStepAndChargeVec(SimCalorimeterHit *hit, std::vector< StepAndCharge > &vec, bool link)
virtual std::unique_ptr< CalorimeterHitImpl > encode(int delta_I, int delta_J)
virtual float getCellSize()
virtual ~SimDigitalGeomCellIdLCGEO()
virtual void processGeometry(SimCalorimeterHit *hit)=0
static AIDA::ITuple * _tupleHit
SimDigitalGeomCellIdLCGEO(LCCollection *inputCol, LCCollectionVec *outputCol)
virtual void setLayerLayout(CHT::Layout layout)
CellIDEncoder< CalorimeterHitImpl > _encoder
std::string _cellIDEncodingString
virtual std::unique_ptr< CalorimeterHitImpl > encode(int delta_I, int delta_J)
void fillDebugTupleGeometryHit()
std::vector< LCCollection * > LCCollectionVec
dd4hep::rec::LayeredCalorimeterData * _caloData
std::vector< std::string > _encodingString
virtual ~SimDigitalGeomCellId()
virtual ~SimDigitalGeomCellIdPROTO()
CHT::Layout _currentHCALCollectionCaloLayout
SimDigitalGeomCellIdPROTO(LCCollection *inputCol, LCCollectionVec *outputCol)
virtual void setLayerLayout(CHT::Layout layout)
void linkSteps(std::vector< StepAndCharge > &vec)