Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:14:55

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 #ifndef DD4HEP_DDG4_PROPERTYTESTACTION_H
0014 #define DD4HEP_DDG4_PROPERTYTESTACTION_H
0015 
0016 /// Framework include files
0017 #include <DDG4/Geant4Action.h>
0018 #include <DD4hep/ComponentProperties.h>
0019 
0020 /// ROOT include files
0021 #include <Math/Point3D.h>
0022 #include <Math/Vector4D.h>
0023 #include <Math/Vector3D.h>
0024 
0025 /// C/C++ include files
0026 #include <map>
0027 #include <set>
0028 #include <list>
0029 #include <vector>
0030 
0031 /// Namespace example name of the user
0032 namespace DD4hepTests   {
0033 
0034   using namespace std;
0035 
0036   /// Class to measure the energy of escaping tracks
0037   /** Class to measure the energy of escaping tracks of a detector using Geant 4
0038    * Measure escaping energy....
0039    *
0040    *  \author  M.Frank
0041    *  \version 1.0
0042    *  \ingroup DD4HEP_SIMULATION
0043    */
0044   class PropertyTestAction : public dd4hep::sim::Geant4Action {
0045   public:
0046     using XYZPoint  = ROOT::Math::XYZPoint;
0047     using XYZVector = ROOT::Math::XYZVector;
0048     using PxPyPzE   = ROOT::Math::PxPyPzEVector;
0049     typedef unsigned long ulong;
0050 
0051     string                   prop_str;               // 'a'
0052     bool                     prop_bool;              // true
0053     int                      prop_int;               // 11
0054     long                     prop_long;              // 11
0055     unsigned long            prop_ulong;             // 11
0056     float                    prop_float;             // 1.11
0057     double                   prop_double;            // 1.11
0058     XYZPoint                 prop_XYZPoint;          // (1, 2, 3)
0059     XYZVector                prop_XYZVector;         // (1, 2, 3)
0060     PxPyPzE                  prop_PxPyPzEVector;     // (1, 2, 3, 4)
0061 
0062     map<string, string>      map_str_str;            // {'a':   'a',      'b': 'bb',        'c': 'ccc'}
0063     map<string, bool>        map_str_bool;           // {'a':   true,     'b':  false,      'c':  true}
0064     map<string, int>         map_str_int;            // {'a':   11,       'b':  200,        'c':  3000}
0065     map<string, long>        map_str_long;           // {'a':   11,       'b':  200,        'c':  3000}
0066     //map<string, ulong>       map_str_ulong;          // {'a':   11,       'b':  200,        'c':  3000}
0067     map<string, float>       map_str_float;          // {'a':   1.11,     'b': 22.22,       'c': 333.33}
0068     map<string, double>      map_str_double;         // {'a':   1.11,     'b': 22.22,       'c': 333.33}
0069 
0070     map<int, string>         map_int_str;            // { 10:   'a',        200:   'bb',        3000: '    ccc'}
0071     map<int, bool>           map_int_bool;           // { 10:   true,       200:  false,        3000:      true}
0072     map<int, int>            map_int_int;            // { 10:   11,         200:  200,          3000:      3000}
0073     map<int, long>           map_int_long;           // { 10:   11,         200:  200,          3000:      3000}
0074     //map<int, ulong>          map_int_ulong;          // { 10:   11,         200:  200,          3000:      3000}
0075     map<int, float>          map_int_float;          // { 10:   1.11,       200:   22.22,       3000:    333.33}
0076     map<int, double>         map_int_double;         // { 10:   1.11,       200:   22.22,       3000:    333.33}
0077 
0078     set<string>              set_str;                // {'a',                    'bb',              'ccc'}
0079     set<bool>                set_bool;               // {true,                   false,              true}
0080     set<int>                 set_int;                // {11,                     222,               3333}
0081     set<long>                set_long;               // {11,                     222,               3333}
0082     //set<ulong>               set_ulong;              // {11,                     222,               3333}
0083     set<float>               set_float;              // {1.11,                   22.22,             333.33}
0084     set<double>              set_double;             // {1.11,                   22.22,             333.33}
0085     set<XYZPoint>            set_XYZPoint;           // {(1, 2, 3),              (10,20,30),       (100,200,300)}
0086     set<XYZVector>           set_XYZVector;          // {(1, 2, 3),              (10,20,30),       (100,200,300)}
0087     set<PxPyPzE>             set_PxPyPzEVector;      // {(1, 2, 3,4),            (10,20,30,40),    (100,200,300,400)}
0088 
0089     vector<string>           vector_str;              // {'a',                    'bb',              'ccc'}
0090     vector<bool>             vector_bool;             // {true,                   false,              true}
0091     vector<int>              vector_int;              // {11,                     222,               3333}
0092     vector<long>             vector_long;             // {11,                     222,               3333}
0093     vector<ulong>            vector_ulong;            // {11,                     222,               3333}
0094     vector<float>            vector_float;            // {1.11,                   22.22,             333.33}
0095     vector<double>           vector_double;           // {1.11,                   22.22,             333.33}
0096     vector<XYZPoint>         vector_XYZPoint;         // {(1, 2, 3),              (10,20,30), (100,200,300)}
0097     vector<XYZVector>        vector_XYZVector;        // {(1, 2, 3),              (10,20,30), (100,200,300)}
0098     vector<PxPyPzE>          vector_PxPyPzEVector;    // {(1, 2, 3,4),            (10,20,30,40),    (100,200,300,400)}
0099 
0100     list<string>             list_str;                // {'a',                    'bb',              'ccc'}
0101     list<bool>               list_bool;               // {true,                   false,              true}
0102     list<int>                list_int;                // {11,                     222,               3333}
0103     list<long>               list_long;               // {11,                     222,               3333}
0104     list<ulong>              list_ulong;              // {11,                     222,               3333}
0105     list<float>              list_float;              // {1.11,                   22.22,             333.33}
0106     list<double>             list_double;             // {1.11,                   22.22,             333.33}
0107     list<XYZPoint>           list_XYZPoint;           // {(1, 2, 3),              (10,20,30), (100,200,300)}
0108     list<XYZVector>          list_XYZVector;          // {(1, 2, 3),              (10,20,30), (100,200,300)}
0109     list<PxPyPzE>            list_PxPyPzEVector;      // {(1, 2, 3,4),            (10,20,30,40),    (100,200,300,400)}
0110 
0111   public:
0112     /// Standard constructor
0113     PropertyTestAction(dd4hep::sim::Geant4Context* context, const std::string& nam);
0114     /// Default destructor
0115     virtual ~PropertyTestAction() = default;
0116     /// Dump properties to screen
0117     void dumpProperties()  const;
0118     /// Install command control messenger
0119     virtual void installCommandMessenger()  override;
0120   };
0121 }      // End namespace dd4hep
0122 #endif /* DD4HEP_DDG4_PROPERTYTESTACTION_H */
0123 
0124 //====================================================================
0125 //  AIDA Detector description implementation 
0126 //--------------------------------------------------------------------
0127 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0128 // All rights reserved.
0129 //
0130 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0131 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0132 //
0133 // Author     : M.Frank
0134 //
0135 //====================================================================
0136 
0137 // Framework include files
0138 #include <DDG4/Geant4UIMessenger.h>
0139 
0140 #include <iostream>
0141 #include <sstream>
0142 
0143 using namespace std;
0144 
0145 namespace {
0146   string str_rep(string in, const string& pat, const string& rep)   {
0147     size_t idx = string::npos;
0148     string res = in;
0149     while( (idx=res.find(pat)) != string::npos )
0150       res.replace(idx, pat.length(), rep);
0151     return res;
0152   }
0153   void _print(stringstream& log)   {
0154     auto res = str_rep(log.str(), "( ", "(");
0155     cout << res << endl;
0156   }
0157   /// Dump properties to screen
0158   template <typename T> int dump_item(const string& tag, const T& value)    {
0159     try  {
0160       stringstream log;
0161       log << "| " << setw(32) << left << tag << " " << setw(6) << left << value;
0162       _print(log);
0163     }
0164     catch(const exception& e)   {
0165       cout << "Test FAILED: " << tag << " Exception: " << e.what() << endl;
0166       return 1;
0167     }
0168     return 0;
0169   }
0170   template <typename T> int dump_cont(const string& tag, const T& value)    {
0171     try  {
0172       stringstream log;
0173       log << "| " << setw(32) << left << tag << " ";
0174       for(const auto& val : value)
0175         log << setw(6) << left << val << "  ";
0176       _print(log);
0177     }
0178     catch(const exception& e)   {
0179       cout << "Test FAILED: " << tag << " Exception: " << e.what() << endl;
0180       return 1;
0181     }
0182     return 0;
0183   }
0184   template <typename T> int dump_map(const string& tag, const T& value)    {
0185     try  {
0186       stringstream log;
0187       log << "| " << setw(32) << left << tag << " ";
0188       for(const auto& p : value)
0189         log << setw(6) << left << p.first << " = " << setw(10) << left << p.second << "  ";
0190       _print(log);
0191     }
0192     catch(const exception& e)   {
0193       cout << "Test FAILED: " << tag << " Exception: " << e.what() << endl;
0194       return 1;
0195     }
0196     return 0;
0197   }
0198 }
0199 
0200 /// Standard constructor
0201 DD4hepTests::PropertyTestAction::PropertyTestAction(dd4hep::sim::Geant4Context* ctxt, const string& nam)
0202   : dd4hep::sim::Geant4Action(ctxt, nam)
0203 {
0204   declareProperty("prop_str",   prop_str); 
0205   declareProperty("prop_bool",  prop_bool);
0206   declareProperty("prop_int",   prop_int);
0207   declareProperty("prop_long",  prop_long);
0208   declareProperty("prop_ulong",  prop_ulong);
0209   declareProperty("prop_float", prop_float);           
0210   declareProperty("prop_double", prop_double);          
0211   declareProperty("prop_XYZPoint", prop_XYZPoint);        
0212   declareProperty("prop_XYZVector", prop_XYZVector);         
0213   declareProperty("prop_PxPyPzEVector", prop_PxPyPzEVector);
0214 
0215   declareProperty("map_str_str", map_str_str);
0216   declareProperty("map_str_bool", map_str_bool);
0217   declareProperty("map_str_int", map_str_int);
0218   declareProperty("map_str_long", map_str_long);
0219   //declareProperty("map_str_ulong", map_str_ulong);
0220   declareProperty("map_str_float", map_str_float);
0221   declareProperty("map_str_double", map_str_double);
0222 
0223   declareProperty("map_int_str", map_int_str);
0224   declareProperty("map_int_bool", map_int_bool);
0225   declareProperty("map_int_int", map_int_int);
0226   declareProperty("map_int_long", map_int_long);
0227   //declareProperty("map_int_ulong", map_int_ulong);
0228   declareProperty("map_int_float", map_int_float);
0229   declareProperty("map_int_double", map_int_double);
0230 
0231   declareProperty("set_str", set_str);
0232   declareProperty("set_bool", set_bool);
0233   declareProperty("set_int", set_int);
0234   declareProperty("set_long", set_long);
0235   //declareProperty("set_ulong", set_ulong);
0236   declareProperty("set_float", set_float);
0237   declareProperty("set_double", set_double);
0238   declareProperty("set_XYZPoint", set_XYZPoint);
0239   declareProperty("set_XYZVector", set_XYZVector);
0240   declareProperty("set_PxPyPzEVector", set_PxPyPzEVector);
0241 
0242   declareProperty("vector_str", vector_str);
0243   declareProperty("vector_bool", vector_bool);
0244   declareProperty("vector_int", vector_int);
0245   declareProperty("vector_long", vector_long);
0246   declareProperty("vector_ulong", vector_ulong);
0247   declareProperty("vector_float", vector_float);
0248   declareProperty("vector_double", vector_double);
0249   declareProperty("vector_XYZPoint", vector_XYZPoint);
0250   declareProperty("vector_XYZVector", vector_XYZVector);
0251   declareProperty("vector_PxPyPzEVector", vector_PxPyPzEVector);
0252 
0253   declareProperty("list_str", list_str);
0254   declareProperty("list_bool", list_bool);
0255   declareProperty("list_int", list_int);
0256   declareProperty("list_long", list_long);
0257   declareProperty("list_ulong", list_ulong);
0258   declareProperty("list_float", list_float);
0259   declareProperty("list_double", list_double);
0260   declareProperty("list_XYZPoint", list_XYZPoint);
0261   declareProperty("list_XYZVector", list_XYZVector);
0262   declareProperty("list_PxPyPzEVector", list_PxPyPzEVector);
0263 }
0264 
0265 /// Install command control messenger
0266 void DD4hepTests::PropertyTestAction::installCommandMessenger()   {
0267   this->Geant4Action::installCommandMessenger();
0268   m_control->addCall("dumpProperties", "Execute property check",
0269                      dd4hep::Callback(this).make(&PropertyTestAction::dumpProperties),0);
0270 }
0271 
0272 /// Dump properties to screen
0273 void DD4hepTests::PropertyTestAction::dumpProperties()  const    {
0274   int result = 0;
0275   const char* line = "+----------------------------------------------------------------------------------------------------------";
0276   cout << line << endl;
0277   result += dump_item("prop_str", prop_str); 
0278   result += dump_item("prop_bool", prop_bool);
0279   result += dump_item("prop_int", prop_int);
0280   result += dump_item("prop_long", prop_long);
0281   result += dump_item("prop_ulong", prop_ulong);
0282   result += dump_item("prop_float", prop_float);           
0283   result += dump_item("prop_double", prop_double);          
0284   result += dump_item("prop_XYZPoint", prop_XYZPoint);        
0285   result += dump_item("prop_XYZVector", prop_XYZVector);         
0286   result += dump_item("prop_PxPyPzEVector", prop_PxPyPzEVector);
0287   cout << line << endl;
0288   result += dump_map("map_str_str", map_str_str);
0289   result += dump_map("map_str_bool", map_str_bool);
0290   result += dump_map("map_str_int", map_str_int);
0291   result += dump_map("map_str_long", map_str_long);
0292   //result += dump_map("map_str_ulong", map_str_ulong);
0293   result += dump_map("map_str_float", map_str_float);
0294   result += dump_map("map_str_double", map_str_double);
0295   cout << line << endl;
0296   result += dump_map("map_int_str", map_int_str);
0297   result += dump_map("map_int_bool", map_int_bool);
0298   result += dump_map("map_int_int", map_int_int);
0299   result += dump_map("map_int_long", map_int_long);
0300   //result += dump_map("map_int_ulong", map_int_ulong);
0301   result += dump_map("map_int_float", map_int_float);
0302   result += dump_map("map_int_double", map_int_double);
0303   cout << line << endl;
0304   result += dump_cont("set_str", set_str);
0305   result += dump_cont("set_bool", set_bool);
0306   result += dump_cont("set_int", set_int);
0307   result += dump_cont("set_long", set_long);
0308   //result += dump_cont("set_ulong", set_ulong);
0309   result += dump_cont("set_float", set_float);
0310   result += dump_cont("set_double", set_double);
0311   result += dump_cont("set_XYZPoint", set_XYZPoint);
0312   result += dump_cont("set_XYZVector", set_XYZVector);
0313   result += dump_cont("set_PxPyPzEVector", set_PxPyPzEVector);
0314   cout << line << endl;
0315   result += dump_cont("vector_str", vector_str);
0316   result += dump_cont("vector_bool", vector_bool);
0317   result += dump_cont("vector_int", vector_int);
0318   result += dump_cont("vector_long", vector_long);
0319   result += dump_cont("vector_ulong", vector_ulong);
0320   result += dump_cont("vector_float", vector_float);
0321   result += dump_cont("vector_double", vector_double);
0322   result += dump_cont("vector_XYZPoint", vector_XYZPoint);
0323   result += dump_cont("vector_XYZVector", vector_XYZVector);
0324   result += dump_cont("vector_PxPyPzEVector", vector_PxPyPzEVector);
0325   cout << line << endl;
0326   result += dump_cont("list_str", list_str);
0327   result += dump_cont("list_bool", list_bool);
0328   result += dump_cont("list_int", list_int);
0329   result += dump_cont("list_long", list_long);
0330   result += dump_cont("list_ulong", list_ulong);
0331   result += dump_cont("list_float", list_float);
0332   result += dump_cont("list_double", list_double);
0333   result += dump_cont("list_XYZPoint", list_XYZPoint);
0334   result += dump_cont("list_XYZVector", list_XYZVector);
0335   result += dump_cont("list_PxPyPzEVector", list_PxPyPzEVector);
0336   cout << line << endl;
0337 
0338   if ( 0 == result )
0339     cout << endl << "Test PASSED" << endl << endl;
0340   else
0341     cout << endl << "Test FAILED" << endl << "===> " << result << " Subtests FAILED" << endl;
0342   cout << line << endl;
0343 }
0344 
0345 #include "DDG4/Factories.h"
0346 DECLARE_GEANT4ACTION_NS(DD4hepTests,PropertyTestAction)