|
ATLAS Offline Software
|
Go to the documentation of this file.
9 #include "CoralBase/AttributeListSpecification.h"
10 #include "CoralBase/Attribute.h"
19 #include "GaudiKernel/NTuple.h"
20 #include "GaudiKernel/INTupleSvc.h"
21 #include "GaudiKernel/SmartDataPtr.h"
23 #include "GaudiKernel/RndmGenerators.h"
24 #include "GaudiKernel/IRndmGenSvc.h"
61 const std::string&
name,
const IInterface*
parent)
67 m_attrListCollection(nullptr),
69 m_par_scttwoside(false),
71 m_par_condstream(
"AthenaOutputStreamTool/AthenaOutputStreamTool", this),
72 m_par_dbroot(
"/Indet/Align" ),
73 m_par_dbkey(
"/Indet/Align" ),
74 m_par_oldTextFile(false),
76 m_forceUserDBConfig(false)
78 declareInterface<IInDetAlignDBTool>(
this);
104 return StatusCode::FAILURE;
139 ATH_MSG_FATAL(
"Pixel and SCT Managers have different alignfolder type registered --> Check ");
140 return StatusCode::FAILURE;
148 return StatusCode::FAILURE;
153 return StatusCode::FAILURE;
166 int TransfLevel_low = 0;
170 std::string man_name;
174 if (element!=
nullptr) {
178 std::string
level[3];
179 for (
int i=TransfLevel_low;
i<3;++
i) {
182 std::vector<std::string>::const_iterator ix=
191 ATH_MSG_ERROR(
"Si detector element type " << idet <<
" has no detset conversion" );
198 ATH_MSG_INFO(
"Geometry initialisation sees " << ndet[0] <<
199 " pixel and " << ndet[1] <<
" SCT modules giving " <<
m_alignobjs.size()
200 <<
" alignment keys" );
205 " pixel and " << ndet[1] <<
" SCT modules giving " <<
m_alignobjs.size()
206 <<
" alignment keys" );
213 ATH_MSG_DEBUG(
"Assuming new COOL alignment DB model based on AlignableTransformContainer");
216 ATH_MSG_DEBUG(
"Assuming old (Lisbon) alignment DB model based on separate AlignableTransforms");
223 coral::AttributeListSpecification*
spec =
new coral::AttributeListSpecification();
224 spec->extend(
"stave",
"int");
225 spec->extend(
"eta",
"int");
226 spec->extend(
"mag",
"float");
227 spec->extend(
"base",
"float");
228 spec->extend(
"free",
"float");
230 const int ibl_stave_max = 14;
232 for (
int this_stave=0; this_stave<ibl_stave_max; this_stave++){
236 atrlist[
"stave" ].data<
int>()=this_stave;
237 atrlist[
"eta" ].data<
int>()=0;
238 atrlist[
"mag" ].data<
float>()=0;
239 atrlist[
"base" ].data<
float>()=0;
240 atrlist[
"free" ].data<
float>()=0;
244 return StatusCode::SUCCESS;
250 return StatusCode::SUCCESS;
259 ATH_MSG_FATAL(
"Cannot create new database when geometry is faked");
270 ATH_MSG_ERROR(
"createDB: AlignableTransformContainer already exists");
274 ATH_MSG_DEBUG(
"Setup database structures in AlignableTransformContainer");
278 ATH_MSG_DEBUG(
"Setup separate AlignableTransform for each layer");
283 else ATH_MSG_DEBUG(
"Treat both sides of SCT module as single entity" );
308 ATH_MSG_ERROR(
"Could not record AlignableTransformContainer");
313 std::vector<std::string> level2;
320 if (element!=
nullptr) {
332 std::vector<std::string>::const_iterator ix =
find(level2.begin(),level2.end(),
key);
333 if (ix==level2.end()) {
334 level2.push_back(
key);
362 globshift.setIdentity();
384 ATH_MSG_DEBUG(
"Dumping size of created AlignableTransform objects");
390 int&
layer,
int& ring,
int& sector,
int&
side)
const {
417 const int level)
const {
431 std::ostringstream
result;
449 int layer,
const int level,
const int sector)
const {
452 std::ostringstream
result;
454 result <<
"/Indet/AlignL";
480 const int level,
const int sector)
const {
483 std::ostringstream
result;
497 const int layer,
const int ring,
const int sector,
498 const float rphidisp,
const float rdisp,
const float zdisp,
499 const int syst,
const int level,
const int skip)
const {
504 SmartIF<IRndmGenSvc> randsvc{Gaudi::svcLocator()->service(
"RndmGenSvc")};
505 if(!randsvc.isValid())
ATH_MSG_ERROR(
"Cannot find RndmGenSvc" );
507 Rndm::Numbers
gauss(randsvc,Rndm::Gauss(0.,1.));
513 float rpd=0,rd=0,zd=0;
515 rpd=rphidisp*
gauss();
520 std::vector<Identifier> lvl12id;
523 for (
int idet=1;idet<3;++idet) {
525 if (element!=
nullptr) {
527 int mdet,mbec,mlayer,mring,msector,mside;
530 if ((dettype==-1 || mdet==dettype) && (
bec==-1 || std::abs(2*mbec)==
bec) &&
531 (
layer==-1 || mlayer==
layer) && (ring==-1 || mring==ring) &&
532 (sector== -1 || msector==sector) && mside==0) {
539 if (dettype!=2 || mside!=1) {
540 if (syst==2 || syst==4 || (syst==6 && mring==-6)) {
541 rpd=rphidisp*
gauss();
545 mlayer <<
" " << mring <<
" z " << zd );
554 if (syst<=2 || syst==6) {
557 float dx=modcent.x();
558 float dy=modcent.y();
576 }
else if (
level==2) {
586 std::vector<Identifier>::const_iterator ix=
587 find(lvl12id.begin(),lvl12id.end(),ident2);
588 if (ix==lvl12id.end()) {
589 lvl12id.push_back(ident2);
601 std::vector<Identifier>::const_iterator ix=
602 find(lvl12id.begin(),lvl12id.end(),ident2);
603 if (ix==lvl12id.end()) {
604 lvl12id.push_back(ident2);
615 <<
"," << mlayer <<
"," << mring <<
"," << msector <<
" to xyz" <<
616 xd <<
"," << yd <<
"," << zd );
626 ATH_MSG_DEBUG(
"Added displacement to " << nmod <<
" modules " << dettype <<
","
627 <<
bec <<
"," <<
layer <<
" [" << rphidisp <<
"," << rdisp
628 <<
"," << zdisp <<
"]"
629 <<
" type " << syst );
634 std::ofstream*
outfile=
nullptr;
635 SmartIF<INTupleSvc> ntsvc{Gaudi::svcLocator()->service(
"NTupleSvc")};
636 if(!ntsvc.isValid())
ATH_MSG_ERROR(
"Cannot find NTupleSvc" );
637 const std::string
path=
file+
"/9002";
638 NTuplePtr
nt(ntsvc.get(),
path);
641 ATH_MSG_DEBUG(
"writeFile: Write AlignableTransforms on ntuple 9002, path: " <<
file );
647 nt=ntsvc->book(
file,ntid,CLID_ColumnWiseTuple,
"AlignDB");
668 "Error booking ntuple 9002 contents" );
675 for (std::vector<std::string>::const_iterator iobj=
m_alignobjs.begin();
680 if (!ntuple) *
outfile << *iobj << std::endl;
682 cit!=
pat->end();++cit) {
718 std::string r3=iobj->substr(iobj->size()-3,3);
720 if (r3==
"SCT" || r3==
"PIX")
nt_level=2;
731 if (StatusCode::SUCCESS!=
nt->write())
ATH_MSG_ERROR(
"Problem filling ntuple 9002" );
734 " " << ring <<
" " <<
side <<
" " <<
dx <<
" " <<
dy <<
" "
748 ATH_MSG_DEBUG(
"Written " << nobj <<
" AlignableTransform objects" <<
" with " << ntrans <<
" transforms to text file" );
754 std::ofstream*
outfile=
nullptr;
758 *
outfile <<
"/Indet/IBLDist" << std::endl;
761 if (StatusCode::SUCCESS==
detStore()->
retrieve(atrlistcol,
"/Indet/IBLDist")) {
766 *
outfile << citr->first <<
" " << atrlist[
"stave"].data<
int>()
767 <<
" " << atrlist[
"eta"].data<int>()
768 <<
" " << atrlist[
"mag"].data<
float>()
769 <<
" " << atrlist[
"base"].data<float>() << std::endl;
774 msg(MSG::INFO) <<
"Cannot find IBLDist Container - cannot write IBLDist DB in text file " <<
endmsg;
786 std::ofstream*
outfile=
nullptr;
791 std::vector<std::string> folder_list = {
"/Indet/AlignL1/ID",
"/Indet/AlignL2/PIX",
"/Indet/AlignL2/SCT"};
803 *
outfile << atrlist[
"subsystem"].data<
int>()
804 <<
" " << atrlist[
"det"].data<int>()
805 <<
" " << atrlist[
"bec"].data<
int>()
806 <<
" " << atrlist[
"layer"].data<int>()
807 <<
" " << atrlist[
"ring"].data<
int>()
808 <<
" " << atrlist[
"sector"].data<int>()
809 <<
" " << atrlist[
"side"].data<
int>()
810 <<
" " << atrlist[
"Tx"].data<float>()
811 <<
" " << atrlist[
"Ty"].data<
float>()
812 <<
" " << atrlist[
"Tz"].data<float>()
813 <<
" " << atrlist[
"Rx"].data<
float>()
814 <<
" " << atrlist[
"Ry"].data<float>()
815 <<
" " << atrlist[
"Rz"].data<
float>() << std::endl;
820 msg(MSG::INFO) <<
"Cannot find " << *
it <<
" Container - cannot write DB in text file " <<
endmsg;
827 ATH_MSG_DEBUG(
"writeFile: No dynamic Run2 DB structure is present --> skipping writing file " <<
file );
836 ATH_MSG_DEBUG(
"readTextFile - set alignment constants from text file: " <<
file );
848 std::string channelName;
853 std::getline(
infile, tmpline);
857 if ((tmpline.substr(0,2) ==
"//") || (tmpline.substr(0,1) ==
"#"))
continue;
859 std::istringstream instring(tmpline);
864 if (tmpstr.empty())
continue;
866 if (tmpstr[0] ==
'/') {
868 channelName = tmpstr;
869 ATH_MSG_DEBUG(
"Read in AlignableTransform data, key " << channelName );
873 ATH_MSG_ERROR(
"Cannot find AlignableTransform object for key"
887 std::istringstream datastream(tmpline);
894 if (datastream.fail()) {
905 }
else if (dettype==2) {
911 if (!
ident.is_valid()) {
914 phiModule <<
"," << etaModule <<
"," <<
side <<
"] key " << channelName <<
915 " shift [" <<
dx <<
"," <<
dy <<
"," << dz <<
"]" );
922 Amg::Transform3D newtrans = newtranslation * Amg::RotationMatrix3D::Identity();
934 while ((itr->identify()!=
ident) && (itr!=pat2->
mend())) ++itr;
935 if (itr!=pat2->
mend()) {
944 " shift [" <<
dx <<
"," <<
dy <<
"," << dz <<
"]" );
952 ATH_MSG_DEBUG(
"Read " << nobj <<
" objects from file with " << ntrans <<
" transforms" );
957 ATH_MSG_DEBUG(
"readNtuple - set alignment constants from ntuple path: " <<
file );
958 SmartIF<INTupleSvc> ntsvc{Gaudi::svcLocator()->service(
"NTupleSvc")};
959 if(!ntsvc.isValid())
ATH_MSG_ERROR(
"Cannot find NTupleSvc" );
960 const std::string
path=
file+
"/9002";
961 NTuplePtr
nt(ntsvc.get(),
path);
979 "Error booking ntuple 9002 contents" );
981 while (
nt->read().isSuccess()) {
993 Amg::Transform3D newtrans = newtranslation * Amg::RotationMatrix3D::Identity();
1001 ATH_MSG_DEBUG(
"Read " << ntrans <<
" transforms from ntuple");
1027 if (pat2!=
nullptr) {
1032 ATH_MSG_ERROR(
"setTrans: cannot retrieve AlignableTransform for key" <<
key );
1044 Amg::Transform3D newtrans = newtranslation * Amg::RotationMatrix3D::Identity();
1071 if (pat2!=
nullptr) {
1080 "tweakTrans: cannot retrieve AlignableTransform for key" <<
key );
1092 Amg::Transform3D newtrans = newtranslation * Amg::RotationMatrix3D::Identity();
1140 ATH_MSG_ERROR(
"getTransL123(): Module not found in PIX or SCT!" );
1146 ATH_MSG_FATAL(
"Code needs to corrected otherwise you will get nonsensical results-- IndetAlignDBTool:2060");
1149 result = trfL1 * trfL2 * trfL3 ;
1157 const int level)
const {
1176 return StatusCode::FAILURE;
1208 ATH_MSG_DEBUG(
"starting to register typeKey for IBLDist" );
1211 typekeys_IBLDist[0] = pair;
1214 if (StatusCode::SUCCESS!=
m_par_condstream->streamObjects(typekeys_IBLDist)) {
1216 return StatusCode::FAILURE;
1228 return StatusCode::SUCCESS;
1232 const unsigned int run1,
const unsigned int event1,
1233 const unsigned int run2,
const unsigned int event2)
const {
1240 SmartIF<IIOVRegistrationSvc> regsvc{Gaudi::svcLocator()->service(
"IOVRegistrationSvc")};
1241 if (!regsvc.isValid()) {
1248 if (StatusCode::SUCCESS==regsvc->registerIOV(
1257 for (std::vector<std::string>::const_iterator iobj=
m_alignobjs.begin();
1259 if (StatusCode::SUCCESS==regsvc->registerIOV(
"AlignableTransform",
1261 ATH_MSG_DEBUG(
"Stored AlignableTransform object " << *iobj );
1264 ATH_MSG_ERROR(
"Failed (registerIOV) to store object " << *iobj );
1268 ATH_MSG_DEBUG(
" Written " << nobj <<
" AlignableTransform objects to conditions database" );
1275 for (std::vector<std::string>::const_iterator iobj=
m_alignobjs.begin();
1282 cit!=
pat->end();++cit) {
1293 "," << ring <<
"," << sector <<
"," <<
side <<
"] Trans:(" <<
1294 shift.x() <<
"," << shift.y() <<
"," << shift.z() <<
") Rot:{"
1295 << alpha <<
"," <<
beta <<
"," <<
gamma <<
"}");
1302 ATH_MSG_DEBUG(
"Object contains " << nobj <<
" transforms" );
1304 ATH_MSG_ERROR(
"AlignableTransform " << *iobj <<
" not found" );
1320 dva!=patc->
end();++dva) {
1321 if ((*dva)->tag()==
key) {
1343 dva!=patc->
end();++dva) {
1344 if ((*dva)->tag()==
key) {
1357 const int nbsct,
const int necsct) {
1369 if (nbpix!=0 || necpix!=0) {
1376 for (
int i=0;
i<necpix;++
i) {
1381 for (
int i=0;
i<nbpix;++
i) {
1386 for (
int i=0;
i<necpix;++
i) {
1391 if (nbsct!=0 || necsct!=0) {
1397 for (
int i=0;
i<necsct;++
i) {
1402 for (
int i=0;
i<nbsct;++
i) {
1407 for (
int i=0;
i<necsct;++
i) {
1425 double& alpha,
double&
beta,
double &
gamma)
const
1427 double siny = trans(0,2);
1435 if ((trans(1,2) == 0) && (trans(2,2) == 0)) {
1439 alpha = atan2(trans(1,1),trans(2,1));
1441 alpha = atan2(-trans(1,2),trans(2,2));
1442 gamma = atan2(-trans(0,1),trans(0,0));
1443 if (alpha == 0) alpha = 0;
1455 if (StatusCode::SUCCESS==
detStore()->
retrieve(atrlistcol1,
"/Indet/IBLDist")) {
1458 if (atrlistcol2!=
nullptr){
1464 if(atrlist2[
"stave"].data<int>()!=stave)
continue;
1466 msg(
MSG::DEBUG) <<
"IBLDist DB -- channel before update: " << citr->first
1467 <<
" ,stave: " << atrlist2[
"stave"].data<
int>()
1468 <<
" ,mag: " << atrlist2[
"mag"].data<float>()
1469 <<
" ,base: " << atrlist2[
"base"].data<
float>() <<
endmsg;
1471 atrlist2[
"mag"].data<
float>() += bowx;
1473 msg(
MSG::DEBUG) <<
"IBLDist DB -- channel after update: " << citr->first
1474 <<
" ,stave: " << atrlist2[
"stave"].data<
int>()
1475 <<
" ,mag: " << atrlist2[
"mag"].data<float>()
1476 <<
" ,base: " << atrlist2[
"base"].data<
float>() <<
endmsg;
1482 ATH_MSG_ERROR(
"tweakIBLDist: cast fails for stave " << stave );
1487 ATH_MSG_ERROR(
"tweakIBLDist: cannot retrieve CondAttrListCollection for key /Indet/IBLDist" );
1506 const unsigned int DBident=
det*10000+2*
bec*1000+
layer*100+ring*10+sector;
1513 if (atrlistcol2!=
nullptr){
1519 if(citr->first!=DBident)
continue;
1521 msg(
MSG::DEBUG) <<
"Tweak Old global DB -- channel: " << citr->first
1522 <<
" ,det: " << atrlist2[
"det"].data<
int>()
1523 <<
" ,bec: " << atrlist2[
"bec"].data<int>()
1524 <<
" ,layer: " << atrlist2[
"layer"].data<
int>()
1525 <<
" ,ring: " << atrlist2[
"ring"].data<int>()
1526 <<
" ,sector: " << atrlist2[
"sector"].data<
int>()
1527 <<
" ,Tx: " << atrlist2[
"Tx"].data<float>()
1528 <<
" ,Ty: " << atrlist2[
"Ty"].data<
float>()
1529 <<
" ,Tz: " << atrlist2[
"Tz"].data<float>()
1530 <<
" ,Rx: " << atrlist2[
"Rx"].data<
float>()
1531 <<
" ,Ry: " << atrlist2[
"Ry"].data<float>()
1532 <<
" ,Rz: " << atrlist2[
"Rz"].data<
float>() <<
endmsg;
1536 Amg::Translation3D oldtranslation(atrlist2[
"Tx"].data<float>(),atrlist2[
"Ty"].data<float>(),atrlist2[
"Tz"].data<float>());
1537 Amg::Transform3D oldtrans = oldtranslation * Amg::RotationMatrix3D::Identity();
1550 atrlist2[
"Tx"].data<
float>() = shift.x();
1551 atrlist2[
"Ty"].data<
float>() = shift.y();
1552 atrlist2[
"Tz"].data<
float>() = shift.z();
1553 atrlist2[
"Rx"].data<
float>() = alpha/
CLHEP::mrad ;
1558 msg(
MSG::DEBUG) <<
"Tweak New global DB -- channel: " << citr->first
1559 <<
" ,det: " << atrlist2[
"det"].data<
int>()
1560 <<
" ,bec: " << atrlist2[
"bec"].data<int>()
1561 <<
" ,layer: " << atrlist2[
"layer"].data<
int>()
1562 <<
" ,ring: " << atrlist2[
"ring"].data<int>()
1563 <<
" ,sector: " << atrlist2[
"sector"].data<
int>()
1564 <<
" ,Tx: " << atrlist2[
"Tx"].data<float>()
1565 <<
" ,Ty: " << atrlist2[
"Ty"].data<
float>()
1566 <<
" ,Tz: " << atrlist2[
"Tz"].data<float>()
1567 <<
" ,Rx: " << atrlist2[
"Rx"].data<
float>()
1568 <<
" ,Ry: " << atrlist2[
"Ry"].data<float>()
1569 <<
" ,Rz: " << atrlist2[
"Rz"].data<
float>() <<
endmsg;
1575 ATH_MSG_ERROR(
"tweakGlobalFolder: cast fails for DBident " << DBident );
1580 ATH_MSG_ERROR(
"tweakGlobalFolder: cannot retrieve CondAttrListCollection for key " <<
key );
def retrieve(aClass, aKey=None)
JetConstituentVector::iterator iterator
This is an Identifier helper class for the Pixel subdetector. This class is a factory for creating co...
bool is_pixel(Identifier id) const
const_iterator end() const
Const iterator class for DataVector/DataList.
This is an Identifier helper class for the SCT subdetector. This class is a factory for creating comp...
path
python interpreter configuration --------------------------------------—
Scalar phi() const
phi method
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
std::string find(const std::string &s)
return a remapped string
bool is_sct(Identifier id) const
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
A CondMultChanCollection is a template class which can hold a collection of T* objects which are inte...
Scalar theta() const
theta method
bool msgLvl(const MSG::Level lvl) const
const_iterator begin() const
Access to Chan/AttributeList pairs via iterators.
This is an interface to a tool used to register conditions objects in the Interval of Validity (IOV) ...
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
int phi_module(const Identifier &id) const
#define ATH_MSG_VERBOSE(x)
This class is a collection of AttributeLists where each one is associated with a channel number....
virtual SiDetectorElement * getDetectorElement(const Identifier &id) const override
access to individual elements via Identifier
Identifier wafer_id(int barrel_ec, int layer_disk, int phi_module, int eta_module) const
For a single crystal.
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
virtual const SiDetectorElementCollection * getDetectorElementCollection() const override
access to whole collectiom
virtual const SiDetectorElementCollection * getDetectorElementCollection() const override
access to whole collection via Iterators
(Non-const) Iterator class for DataVector/DataList.
::StatusCode StatusCode
StatusCode definition for legacy code.
Eigen::Affine3d Transform3D
void add(ChanNum chanNum)
Adding in channel numbers.
int layer_disk(const Identifier &id) const
int eta_module(const Identifier &id) const
int layer_disk(const Identifier &id) const
value_type push_back(value_type pElem)
Add an element to the end of the collection.
Eigen::Matrix< double, 3, 1 > Vector3D
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
std::string show_to_string(Identifier id, const IdContext *context=0, char sep='.') const
or provide the printout in string form
#define ATH_MSG_WARNING(x)
ChanAttrListMap::const_iterator const_iterator
Amg::Transform3D CLHEPTransformToEigen(const HepGeom::Transform3D &CLHEPtransf)
Converts a CLHEP-based HepGeom::Transform3D into an Eigen Amg::Transform3D.
Eigen::Matrix< double, 3, 3 > RotationMatrix3D
int eta_module(const Identifier &id) const
Eigen::Translation< double, 3 > Translation3D
HepGeom::Transform3D EigenTransformToCLHEP(const Amg::Transform3D &eigenTransf)
Converts an Eigen-based Amg::Transform3D into a CLHEP-based HepGeom::Transform3D.
AlignFolderType m_alignfoldertype
int side(const Identifier &id) const
Eigen::AngleAxisd AngleAxis3D
Identifier wafer_id(int barrel_ec, int layer_disk, int phi_module, int eta_module, int side) const
For a single side of module.
int phi_module(const Identifier &id) const
bool add(ChanNum chanNum, const AttributeList &attributeList)
Adding in chan/attrList pairs.
size_type size() const noexcept
Returns the number of elements in the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
virtual SiDetectorElement * getDetectorElement(const Identifier &id) const override
access to individual elements : via Identifier