26 using namespace DD4hep;
27 using namespace DD4hep::Alignments;
30 if ( !cache.insert(alignment) ) {
35 void AlignmentSelector::operator()(Entries::value_type
e)
const {
36 TGeoPhysicalNode* pn = 0;
37 nodes.insert(make_pair(e->path,make_pair(pn,e)));
40 void AlignmentSelector::operator()(
const Cache::value_type& entry)
const {
41 TGeoPhysicalNode* pn = entry.second;
42 for(Entries::const_iterator j=entries.begin(); j != entries.end(); ++j) {
43 Entries::value_type e = (*j);
44 if ( e->needsReset() || e->hasMatrix() ) {
45 const char* p = pn->GetName();
46 bool reset_children = e->resetChildren();
47 if ( reset_children && ::strstr(p,e->path.c_str()) == p ) {
48 nodes.insert(make_pair(p,make_pair(pn,e)));
51 else if ( e->path == p ) {
52 nodes.insert(make_pair(p,make_pair(pn,e)));
60 printout(
ALWAYS,
"GlobalAlignmentCache",
"++++++++++++++++++++++++ Summary ++++++++++++++++++++++++");
64 TGeoPhysicalNode* p = n.second.first;
65 Entry* e = n.second.second;
66 printout(
ALWAYS,
"GlobalAlignmentCache",
"Need to reset entry:%s - %s [needsReset:%s, hasMatrix:%s]",
71 delete n.second.second;
76 TGeoPhysicalNode* p = n.second.first;
78 if ( p->IsAligned() ) {
79 for (Int_t i=0, nLvl=p->GetLevel(); i<=nLvl; i++) {
80 TGeoNode* node = p->GetNode(i);
81 TGeoMatrix*
mm = node->GetMatrix();
82 np += string(
"/")+node->GetName();
83 if ( !mm->IsIdentity() && i > 0 ) {
86 printout(
ALWAYS,
"AlignmentActor<reset>",
"Correct path:%s leaf:%s",p->GetName(),np.c_str());
87 TGeoHMatrix* glob = p->GetMatrix(i-1);
89 *mm = *(a->GetOriginalMatrix());
92 TGeoHMatrix* hm =
dynamic_cast<TGeoHMatrix*
>(
mm);
93 TGeoMatrix* org = p->GetOriginalMatrix();
94 hm->SetTranslation(org->GetTranslation());
95 hm->SetRotation(org->GetRotationMatrix());
105 Entry& e = *n.second.second;
110 printout(
WARNING,
"AlignmentActor",
"++++ SKIP Alignment %s DE:%s Valid:%s Matrix:%s",
115 if ( GlobalDetectorAlignment::debug() ) {
116 printout(
INFO,
"AlignmentActor",
"++++ %s DE:%s Matrix:%s",
127 if ( delta.
checkFlag(Delta::HAVE_ROTATION|Delta::HAVE_PIVOT|Delta::HAVE_TRANSLATION) )
129 else if ( delta.
checkFlag(Delta::HAVE_ROTATION|Delta::HAVE_TRANSLATION) )
131 else if ( delta.
checkFlag(Delta::HAVE_ROTATION|Delta::HAVE_PIVOT) )
133 else if ( delta.
checkFlag(Delta::HAVE_ROTATION) )
135 else if ( delta.
checkFlag(Delta::HAVE_TRANSLATION) )
139 align = no_vol ? ad.align(trafo,ovl_val,e.
overlap) : ad.align(e.
path,trafo,ovl_val,e.
overlap);
141 align = no_vol ? ad.align(trafo,ovl_val) : ad.align(e.
path,trafo,ovl_val);
143 align = no_vol ? ad.align(trafo) : ad.align(e.
path,trafo);
149 except(
"AlignmentActor",
"Failed to apply alignment for "+e.
path);
153 void alignment_reset_dbg(
const string& path,
const GlobalAlignment& a) {
154 TGeoPhysicalNode* n = a.
ptr();
155 cout <<
" +++++++++++++++++++++++++++++++ " << path << endl;
156 cout <<
" +++++ Misaligned physical node: " << endl;
159 if ( n->IsAligned() ) {
160 for (Int_t i=0; i<=n->GetLevel(); i++) {
161 TGeoMatrix* mm = n->GetNode(i)->GetMatrix();
163 np += n->GetNode(i)->GetName();
164 if ( mm->IsIdentity() )
continue;
165 if ( i == 0 )
continue;
167 TGeoHMatrix* glob = n->GetMatrix(i-1);
168 NodeMap::const_iterator j=original_matrices.find(np);
169 if ( j != original_matrices.end() && i!=n->GetLevel() ) {
170 cout <<
" +++++ Patch Level: " << i << np << endl;
171 *mm = *((*j).second);
174 if ( i==n->GetLevel() ) {
175 cout <<
" +++++ Level: " << i << np <<
" --- Original matrix: " << endl;
176 n->GetOriginalMatrix()->Print();
177 cout <<
" +++++ Level: " << i << np <<
" --- Local matrix: " << endl;
179 TGeoHMatrix* hm =
dynamic_cast<TGeoHMatrix*
>(
mm);
180 hm->SetTranslation(n->GetOriginalMatrix()->GetTranslation());
181 hm->SetRotation(n->GetOriginalMatrix()->GetRotationMatrix());
182 cout <<
" +++++ Level: " << i << np <<
" --- New local matrix" << endl;
186 cout <<
" +++++ Level: " << i << np <<
" --- Keep matrix " << endl;
190 cout <<
" +++++ Level: " << i << np <<
" --- Global matrix: " << endl;
193 cout <<
" +++++ Level: " << i << np <<
" --- New global matrix: " << endl;
197 cout <<
"\n\n\n +++++ physical node (full): " << np << endl;
199 cout <<
" +++++ physical node (global): " << np << endl;
200 n->GetMatrix()->Print();
Act on selected alignment entries.
bool overlapDefined() const
Check if the overlap flag checking is enabled.
bool isValid() const
Check the validity of the object held by the handle.
bool checkFlag(unsigned int mask) const
Check a given flag.
Main handle class to hold a TGeo alignment object of type TGeoPhysicalNode.
GlobalDetectorAlignment. DetElement Handle supporting alignment operations.
const char * yes_no(bool value)
Helper function to print booleans in format YES/NO.
DetElement detector
Reference to the detector element.
Delta delta
Delta transformation to be applied.
double overlap
Parameter for overlap checking.
int except(const std::string &src, const std::string &fmt,...)
Calls the display action with ERROR and throws an std::runtime_error exception.
T * ptr() const
Access to the held object.
bool hasMatrix() const
Check if this alignment entry has a non unitary transformation matrix.
bool needsReset() const
Check flag if the node location should be reset.
Class describing an condition to re-adjust an alignment.
std::string path
Path to the misaligned volume.
bool checkOverlap() const
Check if the overlap flag checking is enabled.
Handle class describing a detector element.
ROOT::Math::Translation3D Translation3D
int printout(PrintLevel severity, const char *src, const char *fmt,...)
Calls the display action with a given severity level.
ROOT::Math::Transform3D Transform3D
bool overlapValue() const
Check if the overalp value is present.
const std::string & placementPath() const
Access to the full path to the placed object.