26 #include "GaudiKernel/IToolSvc.h"
32 #include "G4Version.hh"
42 using CLHEP::Hep3Vector;
71 if (
first->position().mag2() <
second->position().mag2())
return true;
73 }
else if (
type ==
R) {
74 if (
first->position().perp2() <
second->position().perp2())
return true;
76 }
else if (
type ==
Z) {
77 if (
first->position().z() <
second->position().z())
return true;
90 std::vector< std::string >::const_iterator nameiter;
99 if (library ==
nullptr) {
100 ATH_MSG_WARNING (
"Library structure file " << (*nameiter) <<
" doesn't describe a valid library" );
104 std::stringstream location;
111 ATH_MSG_VERBOSE (
"Library named " << (*nameiter)+
".root" <<
"is stored at the location " << location.str() );
116 ATH_MSG_ERROR (
"No valid library structure files found. Further execution is pointless." );
117 return StatusCode::FAILURE;
122 return StatusCode::SUCCESS;
132 return StatusCode::FAILURE;
137 double fraction = eventStepsES->
invalid_energy/theParticle->momentum().e();
139 ATH_MSG_WARNING (
"Shower deposited too much energy outside the calorimeter region (" << (
int)(fraction*100) <<
"%), ignoring" );
141 return StatusCode::SUCCESS;
148 if (eventStepsES->
size()>500) {
155 for (ShowerLib::StepInfoList::const_iterator
iter = eventSteps->begin();
iter != eventSteps->end();++
iter) {
156 etot += (*iter)->dep();
159 std::stringstream location;
161 location << eventStepsES->
detector <<
"/" << theParticle->pdg_id();
171 return StatusCode::SUCCESS;
174 Hep3Vector origin(theParticle->production_vertex()->position().x(),
175 theParticle->production_vertex()->position().y(),
176 theParticle->production_vertex()->position().z());
180 Hep3Vector DirectionShower(theParticle->momentum().px(),
181 theParticle->momentum().py(),
182 theParticle->momentum().pz());
183 DirectionShower /= DirectionShower.mag();
184 Hep3Vector OrthoShower = DirectionShower.orthogonal();
185 OrthoShower /= OrthoShower.mag();
186 Hep3Vector CrossShower = DirectionShower.cross(OrthoShower);
187 CrossShower /= CrossShower.mag();
191 Hep3Vector HitDir = (*i)->position() - origin;
193 (*i)->setX(HitDir*OrthoShower);
194 (*i)->setY(HitDir*CrossShower);
195 (*i)->setZ(HitDir*DirectionShower);
202 ATH_MSG_VERBOSE (
"Size after clusterization: " << eventSteps->size() );
204 if (eventSteps->size() > 10) {
209 double maxZ = 0, maxR = 0;
216 ShowerLib::StepInfoList::const_iterator
iter = eventSteps->begin();
217 for (;(
iter != eventSteps->end()) && (edep < containmentEnergy);++
iter) {
218 edep += (*iter)->dep();
219 maxR = (*iter)->position().r();
225 iter = eventSteps->begin();
226 for (;(
iter != eventSteps->end()) && (edep < containmentEnergy);++
iter) {
227 edep += (*iter)->dep();
228 maxZ = (*iter)->position().z();
244 if ((*
m_libraries.find(location.str())).second->storeShower(theParticle, shower)) {
247 ATH_MSG_WARNING (
"Wasn't able to store shower (" << location.str() <<
")" );
253 return StatusCode::SUCCESS;
264 return !mcEvent->
at(0)->particles().empty() ? mcEvent->
at(0)->particles().back() :
nullptr;
266 return ( * (* mcEvent->
begin())->particles_end());
275 if (
evtStore()->
retrieve(eventStepsES,
"EventSteps").isFailure())
return nullptr;
288 rez->push_back(
copy);
298 const double dsame = 1.;
310 if ( (i1)->diff2(*i2) < dsame) {
325 typedef std::multimap<double,Dist> distMap;
332 for (ShowerLib::StepInfoList::reverse_iterator i_h2(stepinfo->rbegin()); (*i_h2) != (*i_h1); ++i_h2) {
333 distances.insert(distMap::value_type((*i_h1)->diff2(**i_h2),
Dist(*i_h1, *i_h2)));
339 int cursize = stepinfo->size();
342 while (cursize > 1) {
344 while ( !( (*iter).second.h1->valid() && (*iter).second.h2->valid() ) ) {
345 distances.erase(
iter++);
348 if ((*iter).first > rmin )
break;
353 if ((*i_h1)->valid()){
354 distances.insert(distMap::value_type((*i_h1)->diff2(*mergedHit),
Dist(*i_h1, mergedHit)));
358 stepinfo->push_back(mergedHit);
368 i = stepinfo->erase(
i);
379 for (ShowerLib::StepInfoList::const_iterator
i(stepinfo->begin());
i != stepinfo->end(); ++
i) {
387 for (iterCut = stepinfo->begin(); (iterCut != stepinfo->end()) && (((*iterCut)->position().mag2() <
m_maxDistance) || (rsum < minEnergy));++iterCut) {
388 rsum += (*iterCut)->dep();
391 if (iterCut == stepinfo->end()) {
395 stepinfo->erase(iterCut,stepinfo->end());
401 const double inv_rsum = 1. / rsum;
402 for (iterCut = stepinfo->begin(); iterCut != stepinfo->end(); ++iterCut){
403 (*iterCut)->setE((*iterCut)->dep() * etot*inv_rsum);
410 char* atlasProject =
getenv(
"AtlasProject");
411 char* atlasVersion =
getenv(
"AtlasVersion");
412 std::string atlasReleaseTag = (atlasProject? std::string(atlasProject)+std::string(
"-") : std::string(
"Unknown-"));
414 atlasReleaseTag += std::string(atlasVersion);
417 atlasReleaseTag += std::string(
"Unknown");
423 (*itr).second->release(atlasReleaseTag);
427 (*itr).second->geometry(geoModelSvc->atlasVersion());
433 std::string g4Version = G4Version;
434 size_t pos = g4Version.find(
"$Name: ");
435 if (
pos != std::string::npos) {
436 g4Version.erase(
pos, 7);
438 pos = g4Version.find(
" $");
439 if (
pos != std::string::npos) {
440 g4Version.erase(
pos, 2);
442 (*itr).second->geantVersion(g4Version);
455 ATH_MSG_DEBUG (
"Writing shower library to file " << (*itr).first );
457 TFile libr((*itr).first.c_str(),
"RECREATE");
459 if (!(*itr).second->writeToROOT(&libr)) {
460 ATH_MSG_ERROR (
"Wasn't able to write " << (*itr).first <<
". Probably empty lib." );
466 ATH_MSG_DEBUG (
"********Statistics for GenShowerLib********" );
471 ATH_MSG_DEBUG (
"*******************************************" );
472 std::stringstream
ss((*itr).second->statistics());
477 ATH_MSG_DEBUG (
"*******************************************" );
482 return StatusCode::SUCCESS;
487 double&
weights,
double& xavfra,
double& yavfra,
double& ravfra)
490 double xav(0.), yav(0.), xav2(0.), yav2(0.);
493 escal += (*i)->dep();
494 xav += (*i)->x()*(*i)->dep();
495 yav += (*i)->y()*(*i)->dep();
496 xav2 += (*i)->x()*(*i)->x()*(*i)->dep();
497 yav2 += (*i)->y()*(*i)->y()*(*i)->dep();
501 const double inv_escal = 1. / escal;
502 xavfra = xav*inv_escal;
503 yavfra = yav*inv_escal;
505 ravfra = std::sqrt(std::abs((xav2*inv_escal-xavfra*xavfra) +
506 (yav2*inv_escal-yavfra*yavfra)));