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    geoPluginRun -volmgr -destroy -plugin DD4hep_AlignmentExample_nominal \
0020    -input file:${DD4hep_DIR}/examples/AlignDet/compact/Telescope.xml
0021 
0022    Access the DetElement nominal conditions using the AlignmentNominalMap.
0023    Any use of DDCond is inhibited.
0024 
0025    1) We use the generic printer, which during the detector element scan accesses the
0026       conditions map.
0027    2) We use a delta scanner to extract the nominal deltas from the DetElement's 
0028       nominal alignments
0029    3) We use a ConditionsTreeMap to perform the alignments re-computation.
0030 */
0031 // Framework include files
0032 #include "AlignmentExampleObjects.h"
0033 #include "DD4hep/AlignmentsNominalMap.h"
0034 #include "DD4hep/Factories.h"
0035 
0036 using namespace std;
0037 using namespace dd4hep;
0038 using namespace dd4hep::AlignmentExamples;
0039 
0040 /// Plugin function: Alignment program example
0041 /**
0042  *  Factory: DD4hep_AlignmentExample_nominal
0043  *
0044  *  \author  M.Frank
0045  *  \version 1.0
0046  *  \date    01/12/2016
0047  */
0048 static int alignment_example (Detector& description, int argc, char** argv)  {
0049   class Collector  {
0050   public:
0051     map<DetElement, Delta>& deltas;
0052     ConditionsMap&          mapping;
0053     Collector(map<DetElement, Delta>& del, ConditionsMap& cond_map)
0054       : deltas(del), mapping(cond_map) {}
0055     // Here we test the ConditionsMap interface of the AlignmentsNominalMap
0056     int operator()(DetElement de, int )  const    {
0057       Alignment a = mapping.get(de, align::Keys::alignmentKey);
0058       deltas.insert(make_pair(de,a.delta()));
0059       return 1;
0060     }
0061   };
0062   string input;
0063   bool   arg_error = false;
0064   for(int i=0; i<argc && argv[i]; ++i)  {
0065     if ( 0 == ::strncmp("-input",argv[i],4) )
0066       input = argv[++i];
0067     else
0068       arg_error = true;
0069   }
0070   if ( arg_error || input.empty() )   {
0071     /// Help printout describing the basic command line interface
0072     cout <<
0073       "Usage: -plugin <name> -arg [-arg]                                             \n"
0074       "     name:   factory name     DD4hep_AlignmentExample1                        \n"
0075       "     -input   <string>        Geometry file                                   \n"
0076       "\tArguments given: " << arguments(argc,argv) << endl << flush;
0077     ::exit(EINVAL);
0078   }
0079 
0080   // First we load the geometry
0081   description.fromXML(input);
0082 
0083 
0084   // ++++++++++++++++++++++++ Try scam with the fake AlignmentsNominalMap
0085   AlignmentsNominalMap nominal(description.world());
0086   
0087   // Collect all the delta conditions and make proper alignment conditions out of them
0088   map<DetElement, Delta> deltas;
0089   // Show that the access interface works:
0090   int num_delta = Scanner().scan(Collector(deltas,nominal),description.world());
0091   /// Show that utilities can work with this one:
0092   int num_printed = Scanner().scan(AlignmentsPrinter(&nominal),description.world());
0093   printout(ALWAYS,"Prepare","Got a total of %ld Deltas (Nominals: %d , Printed: %d)",
0094            deltas.size(), num_delta, num_printed);
0095 
0096   // ++++++++++++++++++++++++ Now compute the alignments for a generic slice
0097   ConditionsTreeMap slice;
0098   // Now compute the tranformation matrices
0099   AlignmentsCalculator calculator;
0100   AlignmentsCalculator::Result ares = calculator.compute(deltas,slice);  
0101   printout(ALWAYS,"Compute","Total %ld conditions inserted. Alignments:(C:%ld,M:%ld)",
0102            slice.data.size(), ares.computed, ares.missing);
0103   if ( ares.missing > 0 ) {
0104     printout(ERROR,"Compute","Failed tro compute %ld alignments.",ares.missing);
0105   }
0106   printout(ALWAYS,"Summary","Printed %d, scanned %d and computed a total of %ld alignments (C:%ld,M:%ld).",
0107            num_printed, num_delta, slice.data.size(), ares.computed, ares.missing);
0108   // All done.
0109   return 1;
0110 }
0111 
0112 // first argument is the type from the xml file
0113 DECLARE_APPLY(DD4hep_AlignmentExample_nominal,alignment_example)