8 #include <DD4hep/Detector.h>
9 #include <DD4hep/DetType.h>
11 #include "DD4hep/DD4hepUnits.h"
20 const std::string _collectionName,
const std::string _detectorName,
double _sensThickCheatVal) :
21 ThicknessSensitive( _sensThickCheatVal>0. ? &
LayerResolverBase::SensitiveThicknessCheat : NULL ),
22 sensThickCheatVal(_sensThickCheatVal),
23 detTypeFlag(_detTypeFlag),
24 collectionName(_collectionName),
25 detectorName(_detectorName),
42 return collection->getParameters().getStringVal( lcio::LCIO::CellIDEncoding );
62 streamlog_out(DEBUG5) <<
"LayerResolver::SetCollection: Looking for collection "
67 catch(EVENT::DataNotAvailableException &dataex) {
69 <<
" not found in event #" << evt->getEventNumber() <<
".\n";
76 streamlog_out(DEBUG5) <<
"Found collection of type \'" <<
collection->getTypeName()
77 <<
"\' with encoding \'"
78 <<
collection->getParameters().getStringVal( lcio::LCIO::CellIDEncoding ) <<
"\'\n";
91 const std::string _collectionName,
92 const std::string _detectorName,
93 double _sensThickCheatVal) :
94 LayerResolverBase(_detTypeFlag, _collectionName, _detectorName, _sensThickCheatVal),
103 return layering->layers.at(nLayer).thicknessSensitive;
113 FloatVec sensThickCheatVals) :
117 const std::vector< dd4hep::DetElement > &detElements = theDetector.detectors(
"tracker",
true);
119 if(_collectionNames.size() != detElements.size()) {
120 streamlog_out(ERROR) <<
"There are " << detElements.size() <<
" tracker detector elements in "
121 "the geometry and " << _collectionNames.size() <<
" tracker hit collection names have been "
122 "set in the parameters.\n";
126 streamlog_out(MESSAGE) <<
"Tracker has " << detElements.size() <<
" elements:\n";
128 for(
unsigned i=0; i<detElements.size(); i++) {
130 streamlog_out(MESSAGE) <<
"Detector element #" << i <<
" of type \'" << detElements.at(i).type();
131 streamlog_out(MESSAGE) <<
"\', named \'" << detElements.at(i).name() <<
"\'\n";
132 streamlog_out(MESSAGE) <<
" ... expects collection name " << _collectionNames[i] <<
"\n";
133 streamlog_out(MESSAGE) <<
" ... has type flags " << detElements.at(i).typeFlag() <<
"\n";
135 int tf = detElements.at(i).typeFlag();
140 streamlog_out(DEBUG) <<
"Trying ZPlanarData.\n";
141 dd4hep::rec::ZPlanarData*
layering = detElements.at(i).extension<dd4hep::rec::ZPlanarData>() ;
142 sr =
new PlaneResolver(tf, layering, _collectionNames[i], detElements.at(i).name(), sensThickCheatVals.at(i));
144 catch ( std::exception &
e) {
145 streamlog_out(DEBUG) <<
"Caught exception " << e.what() << std::endl;
147 streamlog_out(DEBUG) <<
"Trying ZDiskPetalsData.\n";
148 dd4hep::rec::ZDiskPetalsData *layering = detElements.at(i).extension<dd4hep::rec::ZDiskPetalsData>() ;
149 sr =
new PetalResolver(tf, layering, _collectionNames[i], detElements.at(i).name(), sensThickCheatVals.at(i));
151 catch ( std::exception &e1) {
152 streamlog_out(DEBUG) <<
"Caught exception " << e1.what() << std::endl;
157 streamlog_out(ERROR) <<
"Could not find a semiconductor layering extension in the detector element! Aborting.";
161 streamlog_out(MESSAGE) <<
"Detector element has " << sr->GetNumberOfLayers() <<
" layers with thicknesses: ";
163 for(
unsigned iLayer = 0; iLayer < sr->GetNumberOfLayers(); iLayer++) {
165 double sensThick = sr->SensitiveThickness(iLayer)/
dd4hep::mm;
166 streamlog_out(MESSAGE) << sensThick <<
" mm, ";
168 if(sensThick < 1.e-6 && sensThickCheatVals.at(i) < 0.) {
169 streamlog_out(ERROR) <<
"Detector element #" << i <<
", named \'" << detElements.at(i).name()
170 <<
"\' has sensitive thickness " << sensThick <<
" mm in layer " << iLayer
171 <<
" and cheat value has not been set.\n";
175 streamlog_out(MESSAGE) <<
"\n";
178 ResolverMapIter it = layerResolvers.find(detElements.at(i).id());
179 if (it == layerResolvers.end()) {
180 layerResolvers[detElements.at(i).id()] = sr;
183 streamlog_out(ERROR) <<
"Detector element \'" << detElements.at(i).name()
184 <<
"\' has ID = " << detElements.at(i).id()
185 <<
" which is already taken by the detector element \'"
186 << it->second->GetDetectorName() <<
"\'! Aborting.\n";
191 if(sensThickCheatVals.at(i) > 0.) {
192 streamlog_out(MESSAGE) <<
" ... Replacing this detector sensitive thicknesses with value "
193 << sensThickCheatVals.at(i)/
dd4hep::mm <<
" mm.\n";
205 collit.second->SetCollection(evt);
215 streamlog_out(DEBUG5) <<
"LayerFinder::SensitiveThickness() for hit ID = " << thit->getCellID0() <<
".\n";
223 streamlog_out(WARNING) <<
"Hit is located in the system with ID " << systemID
224 <<
" which is not handled by the processor.\n";
228 streamlog_out(DEBUG5) <<
"Hit is located in subdetector \'" << resolver->second->GetDetectorName()
229 <<
"\' with system ID " << systemID <<
"\n";
231 double t = resolver->second->SensitiveThickness(thit);
233 streamlog_out(DEBUG5) <<
" ... Thickness is " << t/
dd4hep::mm <<
" mm.\n";
241 streamlog_out(DEBUG5) <<
"LayerFinder handles the following detectors:\n";
244 if (dit.second->GetDetTypeFlag() & dd4hep::DetType::BARREL) dettype =
"BARREL";
245 else if (dit.second->GetDetTypeFlag() & dd4hep::DetType::ENDCAP) dettype =
"ENDCAP";
246 streamlog_out(DEBUG5) <<
"Detector \'" << dit.second->GetDetectorName() <<
"\' of type \'" << dettype;
247 streamlog_out(DEBUG5) <<
"\' associated with collection name \'" << dit.second->GetCollectionName() <<
"\'.\n";
248 streamlog_out(DEBUG5) <<
"Currently looking at collection of type \'" << dit.second->GetCollectionType();
249 streamlog_out(DEBUG5) <<
"\' with encoding \'" << dit.second->GetCollectionEncoding() <<
"\'\n";
258 for(
int i=0; i<cit.second->GetNumberOfHits(); i++) {
260 if( thit == cit.second->GetHit(i) ) {
262 streamlog_out(DEBUG5) <<
" ... Found matching hit " << cit.second->GetHit(i)->getCellID0()
263 <<
" with energy " << cit.second->GetHit(i)->getEDep()
264 <<
" in collection " << cit.second->GetCollectionName() <<
".\n";
266 return cit.second->DecodeSystem(thit);
std::string GetCollectionEncoding() const
int SetCollection(EVENT::LCEvent *)
double SensitiveThicknessRead(int nLayer) const
LayerResolver< dd4hep::rec::ZPlanarData > PlaneResolver
std::string GetCollectionType() const
virtual ~LayerResolverBase()
int FindSystem(lcio::TrackerHitPlane *thit) const
lcio::TrackerHitPlane * GetHit(int i) const
ResolverMap::iterator ResolverMapIter
int GetNumberOfHits() const
int ReadCollections(EVENT::LCEvent *)
LayerResolverFn ThicknessSensitive
LayerResolverBase()=delete
double(LayerResolverBase::* LayerResolverFn)(int) const
LayerResolver< dd4hep::rec::ZDiskPetalsData > PetalResolver
void ReportHandledDetectors()
ResolverMap layerResolvers
EVENT::LCCollection * collection
std::string collectionName
double SensitiveThickness(lcio::TrackerHitPlane *)
lcio::CellIDDecoder< lcio::TrackerHitPlane > * decoder
std::vector< std::string > StringVec