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_stress \
0020    -input file:${DD4hep_DIR}/examples/AlignDet/compact/Telescope.xml
0021 
0022    Populate the conditions store by hand for a set of IOVs.
0023    Then compute the corresponding alignment entries....
0024 
0025 */
0026 // Framework include files
0027 #include "AlignmentExampleObjects.h"
0028 #include "DD4hep/Factories.h"
0029 #include "TStatistic.h"
0030 #include "TTimeStamp.h"
0031 #include "TRandom3.h"
0032 
0033 using namespace std;
0034 using namespace dd4hep;
0035 using namespace dd4hep::AlignmentExamples;
0036 
0037 /// Plugin function: Alignment program example
0038 /**
0039  *  Factory: DD4hep_AlignmentExample_stress
0040  *
0041  *  \author  M.Frank
0042  *  \version 1.0
0043  *  \date    01/12/2016
0044  */
0045 static int alignment_example (Detector& description, int argc, char** argv)  {
0046 
0047   string input;
0048   int    num_iov = 10, num_runs = 10;
0049   bool   arg_error = false;
0050   for(int i=0; i<argc && argv[i]; ++i)  {
0051     if ( 0 == ::strncmp("-input",argv[i],4) )
0052       input = argv[++i];
0053     else if ( 0 == ::strncmp("-iovs",argv[i],4) )
0054       num_iov = ::atol(argv[++i]);
0055     else if ( 0 == ::strncmp("-runs",argv[i],4) )
0056       num_runs = ::atol(argv[++i]);
0057     else
0058       arg_error = true;
0059   }
0060   if ( arg_error || input.empty() )   {
0061     /// Help printout describing the basic command line interface
0062     cout <<
0063       "Usage: -plugin <name> -arg [-arg]                                             \n"
0064       "     name:   factory name     DD4hep_AlignmentExample_stress                  \n"
0065       "     -input   <string>        Geometry file                                   \n"
0066       "     -iovs    <number>        Number of parallel IOV slots for processing.    \n"
0067       "     -runs    <number>        Number of collision loads to be performed.      \n"
0068       "\tArguments given: " << arguments(argc,argv) << endl << flush;
0069     ::exit(EINVAL);
0070   }
0071 
0072   // First we load the geometry
0073   description.fromXML(input);
0074 
0075   /******************** Initialize the conditions manager *****************/
0076   ConditionsManager manager = installManager(description);
0077   const IOVType*    iov_typ = manager.registerIOVType(0,"run").second;
0078   if ( 0 == iov_typ )
0079     except("ConditionsPrepare","++ Unknown IOV type supplied.");
0080 
0081   TStatistic cr_stat("Creation"), comp_stat("Computation"), access_stat("Access");
0082   size_t total_created = 0;
0083   /******************** Populate the conditions store *********************/
0084   // Have num_iov possible run-slices [11,20] .... [n*10+1,(n+1)*10]
0085   for(int i=0; i<num_iov; ++i)  {
0086     TTimeStamp start;
0087     IOV iov(iov_typ, IOV::Key(1+i*10,(i+1)*10));
0088     ConditionsPool* iov_pool = manager.registerIOV(*iov.iovType, iov.key());
0089     // Create conditions with all deltas. Use a generic creator
0090     total_created += Scanner().scan(AlignmentCreator(manager, *iov_pool),description.world());
0091     TTimeStamp stop;
0092     cr_stat.Fill(stop.AsDouble()-start.AsDouble());
0093   }
0094 
0095   /******************** Now as usual: create the slice ********************/
0096   shared_ptr<ConditionsContent> content(new ConditionsContent());
0097   shared_ptr<ConditionsSlice>   slice(new ConditionsSlice(manager,content));
0098   cond::fill_content(manager,*content,*iov_typ);
0099   
0100   /******************** Register alignments *******************************/
0101   // Note: We have to load one set of conditions in order to auto-populate
0102   //       because we need to see if a detector element actually has alignment
0103   //       conditions. For this we must access the conditions data.
0104   //       Unfortunate, but unavoidable.
0105   //
0106   IOV iov(iov_typ,15);
0107   manager.prepare(iov,*slice);
0108   slice->pool->flags |= cond::UserPool::PRINT_INSERT;
0109 
0110   // Collect all the delta conditions and make proper alignment conditions out of them
0111   map<DetElement, Delta>  deltas;
0112   Scanner(deltaCollector(*slice,deltas),description.world());
0113   printout(INFO,"Prepare","Got a total of %ld deltas for processing alignments.",deltas.size());
0114 
0115   ConditionsManager::Result total_cres;
0116   AlignmentsCalculator::Result total_ares;
0117   /******************** Compute  alignments *******************************/
0118   for(int i=0; i<num_iov; ++i)  {
0119     TTimeStamp start;
0120     IOV req_iov(iov_typ,1+i*10);
0121     shared_ptr<ConditionsSlice> sl(new ConditionsSlice(manager,content));
0122     ConditionsManager::Result cres = manager.prepare(req_iov,*sl);
0123     // Now compute the tranformation matrices
0124     AlignmentsCalculator calculator;
0125     AlignmentsCalculator::Result ares = calculator.compute(deltas,*sl);
0126     TTimeStamp stop;
0127     total_cres += cres;
0128     total_ares += ares;
0129     //sl->manage(alignments.data);
0130     comp_stat.Fill(stop.AsDouble()-start.AsDouble());
0131     printout(INFO,"ComputedDerived",
0132              "Setup %ld conditions (S:%ld,L:%ld,C:%ld,M:%ld) (D:%ld,A:%ld,M:%ld) for IOV:%-12s [%8.3f sec]",
0133              cres.total(), cres.selected, cres.loaded, cres.computed, cres.missing, 
0134              deltas.size(),ares.computed, ares.missing, req_iov.str().c_str(),
0135              stop.AsDouble()-start.AsDouble());
0136   }
0137 
0138   // ++++++++++++++++++++++++ Now access the conditions for every IOV....
0139   TRandom3 random;
0140   for(int i=0; i<num_runs; ++i)  {
0141     TTimeStamp start;
0142     unsigned int rndm = 1+random.Integer(num_iov*10);
0143     IOV req_iov(iov_typ,rndm);
0144     // Attach the proper set of conditions to the user pool
0145     ConditionsManager::Result res = manager.prepare(req_iov,*slice);
0146     TTimeStamp stop;
0147     total_cres += res;
0148     access_stat.Fill(stop.AsDouble()-start.AsDouble());
0149     printout(INFO,"Setup slice: ",
0150              "Total %ld conditions (S:%6ld,L:%6ld,C:%4ld,M:%ld) for random %4d of type %s. [%8.4f sec]",
0151              res.total(), res.selected, res.loaded, res.computed, res.missing, rndm,
0152              iov_typ->str().c_str(), stop.AsDouble()-start.AsDouble());
0153   }
0154   printout(INFO,"Statistics","+======= Summary: # of IOV: %3d  # of Runs: %3d ===========================", num_iov, num_runs);
0155   printout(INFO,"Statistics","+  %-12s:  %11.5g +- %11.4g  RMS = %11.5g  N = %lld",
0156            cr_stat.GetName(), cr_stat.GetMean(), cr_stat.GetMeanErr(), cr_stat.GetRMS(), cr_stat.GetN());
0157   printout(INFO,"Statistics","+  %-12s:  %11.5g +- %11.4g  RMS = %11.5g  N = %lld",
0158            comp_stat.GetName(), comp_stat.GetMean(), comp_stat.GetMeanErr(), comp_stat.GetRMS(), comp_stat.GetN());
0159   printout(INFO,"Statistics","+  %-12s:  %11.5g +- %11.4g  RMS = %11.5g  N = %lld",
0160            access_stat.GetName(), access_stat.GetMean(), access_stat.GetMeanErr(), access_stat.GetRMS(), access_stat.GetN());
0161   printout(INFO,"Statistics",
0162            "+  Summary: Total %ld conditions used (S:%ld,L:%ld,C:%ld,M:%ld) (A:%ld,M:%ld). Created:%ld",
0163            total_cres.total(), total_cres.selected, total_cres.loaded, total_cres.computed, total_cres.missing, 
0164            total_ares.computed, total_ares.missing, total_created);
0165 
0166   printout(INFO,"Statistics","+==========================================================================");
0167   // All done.
0168   return 1;
0169 }
0170 
0171 // first argument is the type from the xml file
0172 DECLARE_APPLY(DD4hep_AlignmentExample_stress,alignment_example)