File indexing completed on 2025-01-30 09:17:44
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 #include "AlignmentExampleObjects.h"
0035 #include "DDAlign/AlignmentsCalib.h"
0036 #include "DD4hep/Factories.h"
0037
0038 using namespace std;
0039 using namespace dd4hep;
0040 using namespace dd4hep::AlignmentExamples;
0041 using align::AlignmentsCalib;
0042
0043 static void print_world_trafo(AlignmentsCalib& calib, const std::string& path) {
0044 DetElement d(calib.detector(path));
0045 Alignment a = calib.slice.get(d,align::Keys::alignmentKey);
0046 if ( a.isValid() ) {
0047 const double* tr = a.worldTransformation().GetTranslation();
0048 printout(INFO,"Example","++ World transformation of: %-32s Tr:(%8.2g,%8.2g,%8.2g [cm])",
0049 path.c_str(), tr[0]/dd4hep::cm, tr[1]/dd4hep::cm, tr[2]/dd4hep::cm);
0050 a.worldTransformation().Print();
0051 return;
0052 }
0053 Condition c = calib.slice.get(d,align::Keys::deltaKey);
0054 printout(WARNING,"Example",
0055 "++ Detector element:%s No alignment conditions present. Delta:%s",
0056 path.c_str(), c.isValid() ? "Present" : "Not availible");
0057 }
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067 static int AlignmentExample_align_telescope (Detector& description, int argc, char** argv) {
0068 string input, setup;
0069 bool arg_error = false, dump = false;
0070
0071 for(int i=0; i<argc && argv[i]; ++i) {
0072 if ( 0 == ::strncmp("-input",argv[i],4) )
0073 input = argv[++i];
0074 else if ( 0 == ::strncmp("-setup",argv[i],5) )
0075 setup = argv[++i];
0076 else if ( 0 == ::strncmp("-dump",argv[i],5) )
0077 dump = true;
0078 else
0079 arg_error = true;
0080 }
0081 if ( arg_error || input.empty() || setup.empty() ) {
0082
0083 cout <<
0084 "Usage: -plugin <name> -arg [-arg] \n"
0085 " name: factory name DD4hep_AlignmentExample_align_telescope \n"
0086 " -input <string> Geometry file \n"
0087 " -setup <string> Alignment setups (Conditions, etc) \n"
0088 " -dump Dump conditions user pool before and afterwards.\n"
0089 "\tArguments given: " << arguments(argc,argv) << endl << flush;
0090 ::exit(EINVAL);
0091 }
0092
0093
0094 description.fromXML(input);
0095 ConditionsManager manager = installManager(description);
0096 const void* setup_args[] = {setup.c_str(), 0};
0097
0098 description.apply("DD4hep_ConditionsXMLRepositoryParser",1,(char**)setup_args);
0099
0100 const IOVType* iov_typ = manager.iovType("run");
0101 if ( 0 == iov_typ ) {
0102 except("ConditionsPrepare","++ Unknown IOV type supplied.");
0103 }
0104 IOV req_iov(iov_typ,1500);
0105 shared_ptr<ConditionsContent> content(new ConditionsContent());
0106 shared_ptr<ConditionsSlice> slice(new ConditionsSlice(manager,content));
0107 ConditionsManager::Result cres = manager.prepare(req_iov,*slice);
0108 cond::fill_content(manager,*content,*iov_typ);
0109
0110
0111 map<DetElement, Delta> deltas;
0112 const auto coll = deltaCollector(*slice,deltas);
0113 auto proc = detectorProcessor(coll);
0114
0115 proc.process(description.world(),0,true);
0116 printout(INFO,"Prepare","Got a total of %ld deltas for processing alignments.",deltas.size());
0117
0118
0119 AlignmentsCalculator alignCalc;
0120 AlignmentsCalculator::Result ares = alignCalc.compute(deltas,*slice);
0121 printout(INFO,"Example",
0122 "Setup %ld/%ld conditions (S:%ld,L:%ld,C:%ld,M:%ld) (A:%ld,M:%ld) for IOV:%-12s",
0123 slice->conditions().size(),
0124 cres.total(), cres.selected, cres.loaded, cres.computed, cres.missing,
0125 ares.computed, ares.missing, iov_typ->str().c_str());
0126
0127 printout(INFO,"Example","=========================================================");
0128 printout(INFO,"Example","==== Alignment transformation BEFORE manipulation =====");
0129 printout(INFO,"Example","=========================================================");
0130 if ( dump ) slice->pool->print("*");
0131
0132 AlignmentsCalib calib(description,*slice);
0133 try {
0134 print_world_trafo(calib,"/world/Telescope");
0135 print_world_trafo(calib,"/world/Telescope/module_1");
0136 print_world_trafo(calib,"/world/Telescope/module_1/sensor");
0137
0138 print_world_trafo(calib,"/world/Telescope/module_3");
0139 print_world_trafo(calib,"/world/Telescope/module_3/sensor");
0140
0141 print_world_trafo(calib,"/world/Telescope/module_5");
0142 print_world_trafo(calib,"/world/Telescope/module_5/sensor");
0143 print_world_trafo(calib,"/world/Telescope/module_8/sensor");
0144 }
0145 catch(const std::exception& e) {
0146 printout(ERROR,"Example","Exception: %s.", e.what());
0147 }
0148 catch(...) {
0149 printout(ERROR,"Example","UNKNOWN Exception....");
0150 }
0151
0152
0153 Delta delta(Position(333.0*dd4hep::cm,0,0));
0154 calib.set(calib.detector("/world/Telescope"),Delta(Position(55.0*dd4hep::cm,0,0)));
0155 calib.set(calib.detector("/world/Telescope/module_1"),delta);
0156 calib.set("/world/Telescope/module_3",delta);
0157
0158 calib.commit();
0159
0160 printout(INFO,"Example","=========================================================");
0161 printout(INFO,"Example","==== Alignment transformation AFTER manipulation =====");
0162 printout(INFO,"Example","=========================================================");
0163 if ( dump ) slice->pool->print("*");
0164
0165 print_world_trafo(calib,"/world/Telescope");
0166 print_world_trafo(calib,"/world/Telescope/module_1");
0167 print_world_trafo(calib,"/world/Telescope/module_1/sensor");
0168 print_world_trafo(calib,"/world/Telescope/module_2/sensor");
0169
0170 print_world_trafo(calib,"/world/Telescope/module_3");
0171 print_world_trafo(calib,"/world/Telescope/module_3/sensor");
0172 print_world_trafo(calib,"/world/Telescope/module_4/sensor");
0173
0174 print_world_trafo(calib,"/world/Telescope/module_5");
0175 print_world_trafo(calib,"/world/Telescope/module_5/sensor");
0176 print_world_trafo(calib,"/world/Telescope/module_6/sensor");
0177 print_world_trafo(calib,"/world/Telescope/module_7/sensor");
0178 print_world_trafo(calib,"/world/Telescope/module_8/sensor");
0179
0180 return 1;
0181 }
0182
0183
0184 DECLARE_APPLY(DD4hep_AlignmentExample_align_telescope,AlignmentExample_align_telescope)