Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:17:44

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 /* 
0014  Plugin invocation:
0015  ==================
0016  This plugin behaves like a main program.
0017  Invoke the plugin with something like this:
0018 
0019  A ideal detector may be worked on with:
0020  geoPluginRun -volmgr -destroy -plugin DD4hep_AlignmentExample_align_telescope  \
0021               -input file:${DD4hep_DIR}/examples/AlignDet/compact/Telescope.xml \
0022               -setup file:${DD4hep_DIR}/examples/Conditions/data/manager.xml    \
0023               -end_plugin -print INFO
0024 
0025  To work an already loaded alignments use:
0026 
0027  geoPluginRun -volmgr -destroy -plugin DD4hep_AlignmentExample_align_telescope  \
0028               -input file:${DD4hep_DIR}/examples/AlignDet/compact/Telescope.xml \
0029               -setup file:${DD4hep_DIR}/examples/Conditions/data/repository.xml \
0030               -end_plugin -print INFO
0031 
0032 */
0033 // Framework include files
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 /// Plugin function: Alignment program example
0060 /**
0061  *  Factory: DD4hep_AlignmentExample_align_telescope
0062  *
0063  *  \author  M.Frank
0064  *  \version 1.0
0065  *  \date    01/12/2016
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     /// Help printout describing the basic command line interface
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   // First we load the geometry
0094   description.fromXML(input);
0095   ConditionsManager manager = installManager(description);
0096   const void* setup_args[]  = {setup.c_str(), 0}; // Better zero-terminate
0097 
0098   description.apply("DD4hep_ConditionsXMLRepositoryParser",1,(char**)setup_args);
0099   // Now the deltas are stored in the conditions manager in the proper IOV pools
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);      // IOV goes from run 1000 ... 2000
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   // Collect all the delta conditions and make proper alignment conditions out of them
0111   map<DetElement, Delta> deltas;
0112   const auto coll = deltaCollector(*slice,deltas);
0113   auto proc = detectorProcessor(coll);
0114   //auto proc = detectorProcessor(deltaCollector(*slice,deltas));
0115   proc.process(description.world(),0,true);
0116   printout(INFO,"Prepare","Got a total of %ld deltas for processing alignments.",deltas.size());
0117   
0118   // ++++++++++++++++++++++++ Compute the tranformation matrices
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  {  // These are only valid if alignments got pre-loaded!
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   /// Let's change something:
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   /// Commit transaction and push deltas to the alignment conditions
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 // first argument is the type from the xml file
0184 DECLARE_APPLY(DD4hep_AlignmentExample_align_telescope,AlignmentExample_align_telescope)