 |
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)
64 declareInterface<IInDetAlignDBTool>(
this);
82 return StatusCode::FAILURE;
119 ATH_MSG_FATAL(
"Pixel and SCT Managers have different alignfolder type registered --> Check ");
120 return StatusCode::FAILURE;
128 return StatusCode::FAILURE;
133 return StatusCode::FAILURE;
146 int TransfLevel_low = 0;
150 std::string man_name;
154 if (element!=
nullptr) {
158 std::string
level[3];
159 for (
int i=TransfLevel_low;
i<3;++
i) {
162 std::vector<std::string>::const_iterator ix=
171 ATH_MSG_ERROR(
"Si detector element type " << idet <<
" has no detset conversion" );
178 ATH_MSG_INFO(
"Geometry initialisation sees " << ndet[0] <<
179 " pixel and " << ndet[1] <<
" SCT modules giving " <<
m_alignobjs.size()
180 <<
" alignment keys" );
185 " pixel and " << ndet[1] <<
" SCT modules giving " <<
m_alignobjs.size()
186 <<
" alignment keys" );
193 ATH_MSG_DEBUG(
"Assuming new COOL alignment DB model based on AlignableTransformContainer");
196 ATH_MSG_DEBUG(
"Assuming old (Lisbon) alignment DB model based on separate AlignableTransforms");
203 coral::AttributeListSpecification*
spec =
new coral::AttributeListSpecification();
204 spec->extend(
"stave",
"int");
205 spec->extend(
"eta",
"int");
206 spec->extend(
"mag",
"float");
207 spec->extend(
"base",
"float");
208 spec->extend(
"free",
"float");
210 const int ibl_stave_max = 14;
212 for (
int this_stave=0; this_stave<ibl_stave_max; this_stave++){
216 atrlist[
"stave" ].data<
int>()=this_stave;
217 atrlist[
"eta" ].data<
int>()=0;
218 atrlist[
"mag" ].data<
float>()=0;
219 atrlist[
"base" ].data<
float>()=0;
220 atrlist[
"free" ].data<
float>()=0;
224 return StatusCode::SUCCESS;
230 return StatusCode::SUCCESS;
238 ATH_MSG_FATAL(
"Cannot create new database when geometry is faked");
249 ATH_MSG_ERROR(
"createDB: AlignableTransformContainer already exists");
253 ATH_MSG_DEBUG(
"Setup database structures in AlignableTransformContainer");
257 ATH_MSG_DEBUG(
"Setup separate AlignableTransform for each layer");
262 else ATH_MSG_DEBUG(
"Treat both sides of SCT module as single entity" );
287 ATH_MSG_ERROR(
"Could not record AlignableTransformContainer");
292 std::vector<std::string> level2;
299 if (element!=
nullptr) {
311 std::vector<std::string>::const_iterator ix =
find(level2.begin(),level2.end(),
key);
312 if (ix==level2.end()) {
313 level2.push_back(
key);
341 globshift.setIdentity();
363 ATH_MSG_DEBUG(
"Dumping size of created AlignableTransform objects");
369 int&
layer,
int& ring,
int& sector,
int&
side)
const {
396 const int level)
const {
410 std::ostringstream
result;
428 int layer,
const int level,
const int sector)
const {
432 std::ostringstream
result;
434 result <<
"/Indet/AlignL";
461 const int level,
const int sector)
const {
464 std::ostringstream
result;
478 const int layer,
const int ring,
const int sector,
479 const float rphidisp,
const float rdisp,
const float zdisp,
480 const int syst,
const int level,
const int skip)
const {
485 SmartIF<IRndmGenSvc> randsvc{Gaudi::svcLocator()->service(
"RndmGenSvc")};
486 if(!randsvc.isValid())
ATH_MSG_ERROR(
"Cannot find RndmGenSvc" );
488 Rndm::Numbers
gauss(randsvc,Rndm::Gauss(0.,1.));
494 float rpd=0,rd=0,zd=0;
496 rpd=rphidisp*
gauss();
501 std::vector<Identifier> lvl12id;
504 for (
int idet=1;idet<3;++idet) {
506 if (element!=
nullptr) {
508 int mdet,mbec,mlayer,mring,msector,mside;
511 if ((dettype==-1 || mdet==dettype) && (
bec==-1 || std::abs(2*mbec)==
bec) &&
512 (
layer==-1 || mlayer==
layer) && (ring==-1 || mring==ring) &&
513 (sector== -1 || msector==sector) && mside==0) {
520 if (dettype!=2 || mside!=1) {
521 if (syst==2 || syst==4 || (syst==6 && mring==-6)) {
522 rpd=rphidisp*
gauss();
526 mlayer <<
" " << mring <<
" z " << zd );
535 if (syst<=2 || syst==6) {
538 float dx=modcent.x();
539 float dy=modcent.y();
557 }
else if (
level==2) {
567 std::vector<Identifier>::const_iterator ix=
568 find(lvl12id.begin(),lvl12id.end(),ident2);
569 if (ix==lvl12id.end()) {
570 lvl12id.push_back(ident2);
582 std::vector<Identifier>::const_iterator ix=
583 find(lvl12id.begin(),lvl12id.end(),ident2);
584 if (ix==lvl12id.end()) {
585 lvl12id.push_back(ident2);
596 <<
"," << mlayer <<
"," << mring <<
"," << msector <<
" to xyz" <<
597 xd <<
"," << yd <<
"," << zd );
601 ATH_MSG_ERROR(
"Cannot find AlignableTransform for key" <<
key <<
" in AlignableTransform container");
608 <<
bec <<
"," <<
layer <<
" [" << rphidisp <<
"," << rdisp
609 <<
"," << zdisp <<
"]"
610 <<
" type " << syst );
615 std::ofstream*
outfile=
nullptr;
616 SmartIF<INTupleSvc> ntsvc{Gaudi::svcLocator()->service(
"NTupleSvc")};
617 if(!ntsvc.isValid())
ATH_MSG_ERROR(
"Cannot find NTupleSvc" );
618 const std::string
path=
file+
"/9002";
619 NTuplePtr
nt(ntsvc.get(),
path);
622 ATH_MSG_DEBUG(
"writeFile: Write AlignableTransforms on ntuple 9002, path: " <<
file );
628 nt=ntsvc->book(
file,ntid,CLID_ColumnWiseTuple,
"AlignDB");
649 "Error booking ntuple 9002 contents" );
656 for (std::vector<std::string>::const_iterator iobj=
m_alignobjs.begin();
661 if (!ntuple) *
outfile << *iobj << std::endl;
663 cit!=
pat->end();++cit) {
700 std::string r3=iobj->substr(iobj->size()-3,3);
702 if (r3==
"SCT" || r3==
"PIX")
nt_level=2;
713 if (StatusCode::SUCCESS!=
nt->write())
ATH_MSG_ERROR(
"Problem filling ntuple 9002" );
716 " " << ring <<
" " <<
side <<
" " <<
dx <<
" " <<
dy <<
" "
719 << *iobj <<
" when writing output file");
724 << *iobj <<
" when writing output file");
732 ATH_MSG_DEBUG(
"Written " << nobj <<
" AlignableTransform objects" <<
" with " << ntrans <<
" transforms to text file" );
738 std::ofstream*
outfile=
nullptr;
742 *
outfile <<
"/Indet/IBLDist" << std::endl;
745 if (StatusCode::SUCCESS==
detStore()->
retrieve(atrlistcol,
"/Indet/IBLDist")) {
750 *
outfile << citr->first <<
" " << atrlist[
"stave"].data<
int>()
751 <<
" " << atrlist[
"eta"].data<int>()
752 <<
" " << atrlist[
"mag"].data<
float>()
753 <<
" " << atrlist[
"base"].data<float>() << std::endl;
758 msg(
MSG::INFO) <<
"Cannot find IBLDist Container - cannot write IBLDist DB in text file " <<
endmsg;
770 std::ofstream*
outfile=
nullptr;
775 std::vector<std::string> folder_list = {
"/Indet/AlignL1/ID",
"/Indet/AlignL2/PIX",
"/Indet/AlignL2/SCT"};
787 *
outfile << atrlist[
"subsystem"].data<
int>()
788 <<
" " << atrlist[
"det"].data<int>()
789 <<
" " << atrlist[
"bec"].data<
int>()
790 <<
" " << atrlist[
"layer"].data<int>()
791 <<
" " << atrlist[
"ring"].data<
int>()
792 <<
" " << atrlist[
"sector"].data<int>()
793 <<
" " << atrlist[
"side"].data<
int>()
794 <<
" " << atrlist[
"Tx"].data<float>()
795 <<
" " << atrlist[
"Ty"].data<
float>()
796 <<
" " << atrlist[
"Tz"].data<float>()
797 <<
" " << atrlist[
"Rx"].data<
float>()
798 <<
" " << atrlist[
"Ry"].data<float>()
799 <<
" " << atrlist[
"Rz"].data<
float>() << std::endl;
804 msg(
MSG::INFO) <<
"Cannot find " << *
it <<
" Container - cannot write DB in text file " <<
endmsg;
811 ATH_MSG_DEBUG(
"writeFile: No dynamic Run2 DB structure is present --> skipping writing file " <<
file );
820 ATH_MSG_DEBUG(
"readTextFile - set alignment constants from text file: " <<
file );
832 std::string channelName;
837 std::getline(
infile, tmpline);
841 if ((tmpline.substr(0,2) ==
"//") || (tmpline.substr(0,1) ==
"#"))
continue;
843 std::istringstream instring(tmpline);
848 if (tmpstr.empty())
continue;
850 if (tmpstr[0] ==
'/') {
852 channelName = tmpstr;
853 ATH_MSG_DEBUG(
"Read in AlignableTransform data, key " << channelName );
857 ATH_MSG_ERROR(
"Cannot find AlignableTransform object for key"
858 << channelName <<
" when reading text file");
871 std::istringstream datastream(tmpline);
878 if (datastream.fail()) {
889 }
else if (dettype==2) {
895 if (!
ident.is_valid()) {
898 phiModule <<
"," << etaModule <<
"," <<
side <<
"] key " << channelName <<
899 " shift [" <<
dx <<
"," <<
dy <<
"," << dz <<
"]" );
906 Amg::Transform3D newtrans = newtranslation * Amg::RotationMatrix3D::Identity();
918 while ((itr->identify()!=
ident) && (itr!=pat2->
mend())) ++itr;
919 if (itr!=pat2->
mend()) {
928 " shift [" <<
dx <<
"," <<
dy <<
"," << dz <<
"]" );
936 ATH_MSG_DEBUG(
"Read " << nobj <<
" objects from file with " << ntrans <<
" transforms" );
941 ATH_MSG_DEBUG(
"readNtuple - set alignment constants from ntuple path: " <<
file );
942 SmartIF<INTupleSvc> ntsvc{Gaudi::svcLocator()->service(
"NTupleSvc")};
943 if(!ntsvc.isValid())
ATH_MSG_ERROR(
"Cannot find NTupleSvc" );
944 const std::string
path=
file+
"/9002";
945 NTuplePtr
nt(ntsvc.get(),
path);
963 "Error booking ntuple 9002 contents" );
965 while (
nt->read().isSuccess()) {
977 Amg::Transform3D newtrans = newtranslation * Amg::RotationMatrix3D::Identity();
985 ATH_MSG_DEBUG(
"Read " << ntrans <<
" transforms from ntuple");
1011 if (pat2!=
nullptr) {
1016 ATH_MSG_ERROR(
"setTrans: cannot retrieve AlignableTransform for key" <<
key );
1028 Amg::Transform3D newtrans = newtranslation * Amg::RotationMatrix3D::Identity();
1055 if (pat2!=
nullptr) {
1064 "tweakTrans: cannot retrieve AlignableTransform for key" <<
key );
1076 Amg::Transform3D newtrans = newtranslation * Amg::RotationMatrix3D::Identity();
1124 ATH_MSG_ERROR(
"getTransL123(): Module not found in PIX or SCT!" );
1130 ATH_MSG_FATAL(
"Code needs to corrected otherwise you will get nonsensical results-- IndetAlignDBTool:2060");
1133 result = trfL1 * trfL2 * trfL3 ;
1141 const int level)
const {
1160 return StatusCode::FAILURE;
1192 ATH_MSG_DEBUG(
"starting to register typeKey for IBLDist" );
1195 typekeys_IBLDist[0] = pair;
1198 if (StatusCode::SUCCESS!=
m_par_condstream->streamObjects(typekeys_IBLDist)) {
1200 return StatusCode::FAILURE;
1212 return StatusCode::SUCCESS;
1216 const unsigned int run1,
const unsigned int event1,
1217 const unsigned int run2,
const unsigned int event2)
const {
1224 SmartIF<IIOVRegistrationSvc> regsvc{Gaudi::svcLocator()->service(
"IOVRegistrationSvc")};
1225 if (!regsvc.isValid()) {
1232 if (StatusCode::SUCCESS==regsvc->registerIOV(
1241 for (std::vector<std::string>::const_iterator iobj=
m_alignobjs.begin();
1243 if (StatusCode::SUCCESS==regsvc->registerIOV(
"AlignableTransform",
1245 ATH_MSG_DEBUG(
"Stored AlignableTransform object " << *iobj );
1248 ATH_MSG_ERROR(
"Failed (registerIOV) to store object " << *iobj );
1252 ATH_MSG_DEBUG(
" Written " << nobj <<
" AlignableTransform objects to conditions database" );
1259 for (std::vector<std::string>::const_iterator iobj=
m_alignobjs.begin();
1266 cit!=
pat->end();++cit) {
1277 "," << ring <<
"," << sector <<
"," <<
side <<
"] Trans:(" <<
1278 shift.x() <<
"," << shift.y() <<
"," << shift.z() <<
") Rot:{"
1286 ATH_MSG_DEBUG(
"Object contains " << nobj <<
" transforms" );
1288 ATH_MSG_ERROR(
"AlignableTransform " << *iobj <<
" not found" );
1304 dva!=patc->
end();++dva) {
1305 if ((*dva)->tag()==
key) {
1327 dva!=patc->
end();++dva) {
1328 if ((*dva)->tag()==
key) {
1341 const int nbsct,
const int necsct) {
1353 if (nbpix!=0 || necpix!=0) {
1360 for (
int i=0;
i<necpix;++
i) {
1365 for (
int i=0;
i<nbpix;++
i) {
1370 for (
int i=0;
i<necpix;++
i) {
1375 if (nbsct!=0 || necsct!=0) {
1381 for (
int i=0;
i<necsct;++
i) {
1386 for (
int i=0;
i<nbsct;++
i) {
1391 for (
int i=0;
i<necsct;++
i) {
1411 double siny = trans(0,2);
1419 if ((trans(1,2) == 0) && (trans(2,2) == 0)) {
1423 alpha = atan2(trans(1,1),trans(2,1));
1425 alpha = atan2(-trans(1,2),trans(2,2));
1426 gamma = atan2(-trans(0,1),trans(0,0));
1439 if (StatusCode::SUCCESS==
detStore()->
retrieve(atrlistcol1,
"/Indet/IBLDist")) {
1442 if (atrlistcol2!=
nullptr){
1448 if(atrlist2[
"stave"].data<int>()!=stave)
continue;
1450 msg(
MSG::DEBUG) <<
"IBLDist DB -- channel before update: " << citr->first
1451 <<
" ,stave: " << atrlist2[
"stave"].data<
int>()
1452 <<
" ,mag: " << atrlist2[
"mag"].data<float>()
1453 <<
" ,base: " << atrlist2[
"base"].data<
float>() <<
endmsg;
1455 atrlist2[
"mag"].data<
float>() += bowx;
1457 msg(
MSG::DEBUG) <<
"IBLDist DB -- channel after update: " << citr->first
1458 <<
" ,stave: " << atrlist2[
"stave"].data<
int>()
1459 <<
" ,mag: " << atrlist2[
"mag"].data<float>()
1460 <<
" ,base: " << atrlist2[
"base"].data<
float>() <<
endmsg;
1466 ATH_MSG_ERROR(
"tweakIBLDist: cast fails for stave " << stave );
1471 ATH_MSG_ERROR(
"tweakIBLDist: cannot retrieve CondAttrListCollection for key /Indet/IBLDist" );
1490 const unsigned int DBident=
det*10000+2*
bec*1000+
layer*100+ring*10+sector;
1497 if (atrlistcol2!=
nullptr){
1503 if(citr->first!=DBident)
continue;
1505 msg(
MSG::DEBUG) <<
"Tweak Old global DB -- channel: " << citr->first
1506 <<
" ,det: " << atrlist2[
"det"].data<
int>()
1507 <<
" ,bec: " << atrlist2[
"bec"].data<int>()
1508 <<
" ,layer: " << atrlist2[
"layer"].data<
int>()
1509 <<
" ,ring: " << atrlist2[
"ring"].data<int>()
1510 <<
" ,sector: " << atrlist2[
"sector"].data<
int>()
1511 <<
" ,Tx: " << atrlist2[
"Tx"].data<float>()
1512 <<
" ,Ty: " << atrlist2[
"Ty"].data<
float>()
1513 <<
" ,Tz: " << atrlist2[
"Tz"].data<float>()
1514 <<
" ,Rx: " << atrlist2[
"Rx"].data<
float>()
1515 <<
" ,Ry: " << atrlist2[
"Ry"].data<float>()
1516 <<
" ,Rz: " << atrlist2[
"Rz"].data<
float>() <<
endmsg;
1520 Amg::Translation3D oldtranslation(atrlist2[
"Tx"].data<float>(),atrlist2[
"Ty"].data<float>(),atrlist2[
"Tz"].data<float>());
1521 Amg::Transform3D oldtrans = oldtranslation * Amg::RotationMatrix3D::Identity();
1534 atrlist2[
"Tx"].data<
float>() = shift.x();
1535 atrlist2[
"Ty"].data<
float>() = shift.y();
1536 atrlist2[
"Tz"].data<
float>() = shift.z();
1542 msg(
MSG::DEBUG) <<
"Tweak New global DB -- channel: " << citr->first
1543 <<
" ,det: " << atrlist2[
"det"].data<
int>()
1544 <<
" ,bec: " << atrlist2[
"bec"].data<int>()
1545 <<
" ,layer: " << atrlist2[
"layer"].data<
int>()
1546 <<
" ,ring: " << atrlist2[
"ring"].data<int>()
1547 <<
" ,sector: " << atrlist2[
"sector"].data<
int>()
1548 <<
" ,Tx: " << atrlist2[
"Tx"].data<float>()
1549 <<
" ,Ty: " << atrlist2[
"Ty"].data<
float>()
1550 <<
" ,Tz: " << atrlist2[
"Tz"].data<float>()
1551 <<
" ,Rx: " << atrlist2[
"Rx"].data<
float>()
1552 <<
" ,Ry: " << atrlist2[
"Ry"].data<float>()
1553 <<
" ,Rz: " << atrlist2[
"Rz"].data<
float>() <<
endmsg;
1559 ATH_MSG_ERROR(
"tweakGlobalFolder: cast fails for DBident " << DBident );
1564 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)
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 const 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
virtual const 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, 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.