Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-27 09:18:07

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 /*
0027  * =============================================================================
0028  *
0029  *       Filename:  CexmcASTEval.cc
0030  *
0031  *    Description:  abstract syntax tree for custom filter eval
0032  *
0033  *        Version:  1.0
0034  *        Created:  17.07.2010 15:46:01
0035  *       Revision:  none
0036  *       Compiler:  gcc
0037  *
0038  *         Author:  Alexey Radkov (), 
0039  *        Company:  PNPI
0040  *
0041  * =============================================================================
0042  */
0043 
0044 #ifdef CEXMC_USE_CUSTOM_FILTER
0045 
0046 #include <numeric>
0047 #include <boost/variant/get.hpp>
0048 #include <G4SystemOfUnits.hh>
0049 #include "CexmcASTEval.hh"
0050 
0051 
0052 namespace
0053 {
0054     const std::string  CexmcCFVarEvent( "event" );
0055     const std::string  CexmcCFVarOpCosThetaSCM( "op_cosTh_SCM" );
0056     const std::string  CexmcCFVarEDT( "edt" );
0057     const std::string  CexmcCFVarTPT( "tpt" );
0058     const std::string  CexmcCFVarMon( "mon" );
0059     const std::string  CexmcCFVarMonED( "monED" );
0060     const std::string  CexmcCFVarVclED( "vclED" );
0061     const std::string  CexmcCFVarVcrED( "vcrED" );
0062     const std::string  CexmcCFVarClED( "clED" );
0063     const std::string  CexmcCFVarCrED( "crED" );
0064     const std::string  CexmcCFVarClEDCol( "clEDcol" );
0065     const std::string  CexmcCFVarCrEDCol( "crEDcol" );
0066     const std::string  CexmcCFVarBpMonPosL( "bp_mon_posl" );
0067     const std::string  CexmcCFVarBpMonPosW( "bp_mon_posw" );
0068     const std::string  CexmcCFVarBpMonDirL( "bp_mon_dirl" );
0069     const std::string  CexmcCFVarBpMonDirW( "bp_mon_dirw" );
0070     const std::string  CexmcCFVarBpMonMom( "bp_mon_mom" );
0071     const std::string  CexmcCFVarBpMonTid( "bp_mon_tid" );
0072     const std::string  CexmcCFVarBpTgtPosL( "bp_tgt_posl" );
0073     const std::string  CexmcCFVarBpTgtPosW( "bp_tgt_posw" );
0074     const std::string  CexmcCFVarBpTgtDirL( "bp_tgt_dirl" );
0075     const std::string  CexmcCFVarBpTgtDirW( "bp_tgt_dirw" );
0076     const std::string  CexmcCFVarBpTgtMom( "bp_tgt_mom" );
0077     const std::string  CexmcCFVarBpTgtTid( "bp_tgt_tid" );
0078     const std::string  CexmcCFVarOpTgtPosL( "op_tgt_posl" );
0079     const std::string  CexmcCFVarOpTgtPosW( "op_tgt_posw" );
0080     const std::string  CexmcCFVarOpTgtDirL( "op_tgt_dirl" );
0081     const std::string  CexmcCFVarOpTgtDirW( "op_tgt_dirw" );
0082     const std::string  CexmcCFVarOpTgtMom( "op_tgt_mom" );
0083     const std::string  CexmcCFVarOpTgtTid( "op_tgt_tid" );
0084     const std::string  CexmcCFVarNpTgtPosL( "np_tgt_posl" );
0085     const std::string  CexmcCFVarNpTgtPosW( "np_tgt_posw" );
0086     const std::string  CexmcCFVarNpTgtDirL( "np_tgt_dirl" );
0087     const std::string  CexmcCFVarNpTgtDirW( "np_tgt_dirw" );
0088     const std::string  CexmcCFVarNpTgtMom( "np_tgt_mom" );
0089     const std::string  CexmcCFVarNpTgtTid( "np_tgt_tid" );
0090     const std::string  CexmcCFVarOpdp1TgtPosL( "opdp1_tgt_posl" );
0091     const std::string  CexmcCFVarOpdp1TgtPosW( "opdp1_tgt_posw" );
0092     const std::string  CexmcCFVarOpdp1TgtDirL( "opdp1_tgt_dirl" );
0093     const std::string  CexmcCFVarOpdp1TgtDirW( "opdp1_tgt_dirw" );
0094     const std::string  CexmcCFVarOpdp1TgtMom( "opdp1_tgt_mom" );
0095     const std::string  CexmcCFVarOpdp1TgtTid( "opdp1_tgt_tid" );
0096     const std::string  CexmcCFVarOpdp2TgtPosL( "opdp2_tgt_posl" );
0097     const std::string  CexmcCFVarOpdp2TgtPosW( "opdp2_tgt_posw" );
0098     const std::string  CexmcCFVarOpdp2TgtDirL( "opdp2_tgt_dirl" );
0099     const std::string  CexmcCFVarOpdp2TgtDirW( "opdp2_tgt_dirw" );
0100     const std::string  CexmcCFVarOpdp2TgtMom( "opdp2_tgt_mom" );
0101     const std::string  CexmcCFVarOpdp2TgtTid( "opdp2_tgt_tid" );
0102     const std::string  CexmcCFVarOpdpVclPosL( "opdp_vcl_posl" );
0103     const std::string  CexmcCFVarOpdpVclPosW( "opdp_vcl_posw" );
0104     const std::string  CexmcCFVarOpdpVclDirL( "opdp_vcl_dirl" );
0105     const std::string  CexmcCFVarOpdpVclDirW( "opdp_vcl_dirw" );
0106     const std::string  CexmcCFVarOpdpVclMom( "opdp_vcl_mom" );
0107     const std::string  CexmcCFVarOpdpVclTid( "opdp_vcl_tid" );
0108     const std::string  CexmcCFVarOpdpVcrPosL( "opdp_vcr_posl" );
0109     const std::string  CexmcCFVarOpdpVcrPosW( "opdp_vcr_posw" );
0110     const std::string  CexmcCFVarOpdpVcrDirL( "opdp_vcr_dirl" );
0111     const std::string  CexmcCFVarOpdpVcrDirW( "opdp_vcr_dirw" );
0112     const std::string  CexmcCFVarOpdpVcrMom( "opdp_vcr_mom" );
0113     const std::string  CexmcCFVarOpdpVcrTid( "opdp_vcr_tid" );
0114     const std::string  CexmcCFVarOpdpClPosL( "opdp_cl_posl" );
0115     const std::string  CexmcCFVarOpdpClPosW( "opdp_cl_posw" );
0116     const std::string  CexmcCFVarOpdpClDirL( "opdp_cl_dirl" );
0117     const std::string  CexmcCFVarOpdpClDirW( "opdp_cl_dirw" );
0118     const std::string  CexmcCFVarOpdpClMom( "opdp_cl_mom" );
0119     const std::string  CexmcCFVarOpdpClTid( "opdp_cl_tid" );
0120     const std::string  CexmcCFVarOpdpCrPosL( "opdp_cr_posl" );
0121     const std::string  CexmcCFVarOpdpCrPosW( "opdp_cr_posw" );
0122     const std::string  CexmcCFVarOpdpCrDirL( "opdp_cr_dirl" );
0123     const std::string  CexmcCFVarOpdpCrDirW( "opdp_cr_dirw" );
0124     const std::string  CexmcCFVarOpdpCrMom( "opdp_cr_mom" );
0125     const std::string  CexmcCFVarOpdpCrTid( "opdp_cr_tid" );
0126     const std::string  CexmcCFVarIpSCM( "ipSCM" );
0127     const std::string  CexmcCFVarIpLAB( "ipLAB" );
0128     const std::string  CexmcCFVarNpSCM( "npSCM" );
0129     const std::string  CexmcCFVarNpLAB( "npLAB" );
0130     const std::string  CexmcCFVarOpSCM( "opSCM" );
0131     const std::string  CexmcCFVarOpLAB( "opLAB" );
0132     const std::string  CexmcCFVarNopSCM( "nopSCM" );
0133     const std::string  CexmcCFVarNopLAB( "nopLAB" );
0134     const std::string  CexmcCFVarIpId( "ipId" );
0135     const std::string  CexmcCFVarNpId( "npId" );
0136     const std::string  CexmcCFVarOpId( "opId" );
0137     const std::string  CexmcCFVarNopId( "nopId" );
0138     const std::string  CexmcCFVarConst_eV( "eV" );
0139     const std::string  CexmcCFVarConst_keV( "keV" );
0140     const std::string  CexmcCFVarConst_MeV( "MeV" );
0141     const std::string  CexmcCFVarConst_GeV( "GeV" );
0142     const std::string  CexmcCFVarConst_mm( "mm" );
0143     const std::string  CexmcCFVarConst_cm( "cm" );
0144     const std::string  CexmcCFVarConst_m( "m" );
0145 }
0146 
0147 
0148 const G4double  CexmcASTEval::constants[] = { eV, keV, MeV, GeV, mm, cm, m };
0149 
0150 
0151 CexmcASTEval::CexmcASTEval( const CexmcEventFastSObject *  evFastSObject_,
0152                             const CexmcEventSObject *  evSObject_ ) :
0153     evFastSObject( evFastSObject_ ), evSObject( evSObject_ )
0154 {
0155 }
0156 
0157 
0158 CexmcAST::BasicEval::ScalarValueType  CexmcASTEval::GetFunScalarValue(
0159                                         const CexmcAST::Subtree &  ast ) const
0160 {
0161     const CexmcAST::Function &  fun( boost::get< CexmcAST::Function >(
0162                                                                 ast.type ) );
0163 
0164     if ( fun == "Sum" )
0165     {
0166         CexmcEnergyDepositCalorimeterCollection  edCol;
0167         GetEDCollectionValue( ast.children[ 0 ], edCol );
0168 
0169         G4double  result( 0. );
0170 
0171         for ( CexmcEnergyDepositCalorimeterCollection::iterator
0172                                     k( edCol.begin() ); k != edCol.end(); ++k )
0173         {
0174             result += std::accumulate( k->begin(), k->end(), G4double( 0. ) );
0175         }
0176 
0177         return result;
0178     }
0179 
0180     bool             evalResult( false );
0181     ScalarValueType  result( GetBasicFunScalarValue( ast, evalResult ) );
0182 
0183     if ( evalResult )
0184         return result;
0185 
0186     throw CexmcException( CexmcCFUnexpectedFunction );
0187 
0188     return 0;
0189 }
0190 
0191 
0192 CexmcAST::BasicEval::ScalarValueType  CexmcASTEval::GetVarScalarValue(
0193                                         const CexmcAST::Variable &  var ) const
0194 {
0195     if ( evFastSObject == NULL || evSObject == NULL )
0196         throw CexmcException( CexmcCFUninitialized );
0197 
0198     /* Variables with initialized address */
0199 
0200     /* bound to CexmcAST::Variable:addr */
0201 
0202     const double * const *  addr( boost::get< const double * >( &var.addr ) );
0203 
0204     if ( addr )
0205     {
0206         if ( *addr )
0207             return **addr;
0208     }
0209     else
0210     {
0211         const int * const &  addr_( boost::get< const int * >( var.addr ) );
0212 
0213         if ( addr_ )
0214             return *addr_;
0215     }
0216 
0217     /* found in varAddrMap */
0218 
0219     VarAddrMap::const_iterator  found( varAddrMap.find( var.name ) );
0220 
0221     if ( found != varAddrMap.end() )
0222     {
0223         const CexmcEnergyDepositCalorimeterCollection * const *  addr_(
0224                 boost::get< const CexmcEnergyDepositCalorimeterCollection * >(
0225                                                             &found->second ) );
0226         if ( addr_ )
0227         {
0228             if ( *addr_ )
0229             {
0230                 if ( ( *addr_ )->size() == 0 )
0231                     throw CexmcException( CexmcCFUninitializedVector );
0232                 if ( var.index1 == 0 || var.index2 == 0 )
0233                     throw CexmcException( CexmcCFUnexpectedVectorIndex );
0234                 return ( *addr_ )->at( var.index1 - 1 ).at( var.index2 - 1 );
0235             }
0236         }
0237         else
0238         {
0239             const bool * const &  addr__( boost::get< const bool * >(
0240                                                             found->second ) );
0241             if ( addr__ )
0242                 return int( *addr__ );
0243         }
0244     }
0245 
0246     /* Variables without address */
0247 
0248     if ( var.name == CexmcCFVarTPT )
0249     {
0250         return int( evSObject->targetTPOutputParticle.trackId !=
0251                     CexmcInvalidTrackId );
0252     } 
0253 
0254     throw CexmcException( CexmcCFUnexpectedVariable );
0255 
0256     return 0;
0257 }
0258 
0259 
0260 void  CexmcASTEval::GetEDCollectionValue( const CexmcAST::Node &  node,
0261                         CexmcEnergyDepositCalorimeterCollection &  edCol ) const
0262 {
0263     if ( evSObject == NULL )
0264         throw CexmcException( CexmcCFUninitialized );
0265 
0266     const CexmcAST::Subtree *  ast( boost::get< CexmcAST::Subtree >( &node ) );
0267 
0268     if ( ast )
0269     {
0270         const CexmcAST::Function &  fun( boost::get< CexmcAST::Function >(
0271                                                                 ast->type ) );
0272 
0273         if ( fun == "Inner" )
0274         {
0275             GetEDCollectionValue( ast->children[ 0 ], edCol );
0276             edCol.pop_back();
0277             edCol.erase( edCol.begin() );
0278             for ( CexmcEnergyDepositCalorimeterCollection::iterator
0279                             k( edCol.begin() ); k != edCol.end(); ++k )
0280             {
0281                 k->pop_back();
0282                 k->erase( k->begin() );
0283             }
0284             return;
0285         }
0286         if ( fun == "Outer" )
0287         {
0288             GetEDCollectionValue( ast->children[ 0 ], edCol );
0289             if ( edCol.size() < 3 )
0290                 return;
0291             for ( CexmcEnergyDepositCalorimeterCollection::iterator
0292                             k( edCol.begin() + 1 ); k != edCol.end() - 1; ++k )
0293             {
0294                 if ( k->size() < 3 )
0295                     continue;
0296                 k->erase( k->begin() + 1, k->end() - 1 );
0297             }
0298             return;
0299         }
0300     }
0301     else
0302     {
0303         const CexmcAST::Leaf &      leaf( boost::get< CexmcAST::Leaf >(
0304                                                                     node ) );
0305         const CexmcAST::Variable &  var( boost::get< CexmcAST::Variable >(
0306                                                                     leaf ) );
0307 
0308         if ( var.index1 != 0 || var.index2 != 0 )
0309             throw CexmcException( CexmcCFUnexpectedVariableUsage );
0310 
0311         VarAddrMap::const_iterator  found( varAddrMap.find( var.name ) );
0312 
0313         if ( found == varAddrMap.end() )
0314             throw CexmcException( CexmcCFUnexpectedVariable );
0315 
0316         const CexmcEnergyDepositCalorimeterCollection * const *  addr(
0317                 boost::get< const CexmcEnergyDepositCalorimeterCollection * >(
0318                                                             &found->second ) );
0319         if ( ! addr )
0320         {
0321             throw CexmcException( CexmcCFUnexpectedVariableUsage );
0322         }
0323         else
0324         {
0325             if ( *addr )
0326                 edCol = **addr;
0327             return;
0328         }
0329     }
0330 }
0331 
0332 
0333 void  CexmcASTEval::BindAddresses( CexmcAST::Subtree &  ast )
0334 {
0335     if ( evFastSObject == NULL || evSObject == NULL )
0336         return;
0337 
0338     for ( std::vector< CexmcAST::Node >::iterator  k( ast.children.begin() );
0339                                                   k != ast.children.end(); ++k )
0340     {
0341         CexmcAST::Subtree *  subtree( boost::get< CexmcAST::Subtree >( &*k ) );
0342 
0343         if ( subtree )
0344         {
0345             BindAddresses( *subtree );
0346         }
0347         else
0348         {
0349             CexmcAST::Leaf &      leaf( boost::get< CexmcAST::Leaf >( *k ) );
0350             CexmcAST::Variable *  var( boost::get< CexmcAST::Variable >(
0351                                                                     &leaf ) );
0352             if ( ! var )
0353                 continue;
0354 
0355             const int * const *   intVarAddr(
0356                                     boost::get< const int * >( &var->addr ) );
0357             if ( intVarAddr )
0358             {
0359                 if ( *intVarAddr )
0360                     continue;
0361             }
0362             else
0363             {
0364                 const double * const &  doubleVarAddr(
0365                                     boost::get< const double * >( var->addr ) );
0366                 if ( doubleVarAddr )
0367                     continue;
0368             }
0369 
0370             VarAddrMap::const_iterator  found( varAddrMap.find( var->name ) );
0371 
0372             if ( found != varAddrMap.end() )
0373                 continue;
0374 
0375             do
0376             {
0377                 if ( var->name == CexmcCFVarEvent )
0378                 {
0379                     var->addr = &evFastSObject->eventId;
0380                     break;
0381                 }
0382                 if ( var->name == CexmcCFVarOpCosThetaSCM )
0383                 {
0384                     var->addr = &evFastSObject->opCosThetaSCM;
0385                     break;
0386                 }
0387                 if ( var->name == CexmcCFVarEDT )
0388                 {
0389                     varAddrMap.insert( VarAddrMapData( var->name,
0390                                    &evFastSObject->edDigitizerHasTriggered ) );
0391                     break;
0392                 } 
0393                 if ( var->name == CexmcCFVarMon )
0394                 {
0395                     varAddrMap.insert( VarAddrMapData( var->name,
0396                            &evFastSObject->edDigitizerMonitorHasTriggered ) );
0397                     break;
0398                 }
0399                 if ( var->name == CexmcCFVarMonED )
0400                 {
0401                     var->addr = &evSObject->monitorED;
0402                     break;
0403                 }
0404                 if ( var->name == CexmcCFVarVclED )
0405                 {
0406                     var->addr = &evSObject->vetoCounterEDLeft;
0407                     break;
0408                 }
0409                 if ( var->name == CexmcCFVarVcrED )
0410                 {
0411                     var->addr = &evSObject->vetoCounterEDRight;
0412                     break;
0413                 }
0414                 if ( var->name == CexmcCFVarClED )
0415                 {
0416                     var->addr = &evSObject->calorimeterEDLeft;
0417                     break;
0418                 }
0419                 if ( var->name == CexmcCFVarCrED )
0420                 {
0421                     var->addr = &evSObject->calorimeterEDRight;
0422                     break;
0423                 }
0424                 if ( var->name == CexmcCFVarClEDCol )
0425                 {
0426                     varAddrMap.insert( VarAddrMapData( var->name,
0427                                 &evSObject->calorimeterEDLeftCollection ) );
0428                     break;
0429                 }
0430                 if ( var->name == CexmcCFVarCrEDCol )
0431                 {
0432                     varAddrMap.insert( VarAddrMapData( var->name,
0433                                 &evSObject->calorimeterEDRightCollection ) );
0434                     break;
0435                 }
0436                 if ( var->name == CexmcCFVarBpMonPosL )
0437                 {
0438                     var->addr = GetThreeVectorElementAddrByIndex(
0439                             evSObject->monitorTP.positionLocal, var->index1 );
0440                     break;
0441                 }
0442                 if ( var->name == CexmcCFVarBpMonPosW )
0443                 {
0444                     var->addr = GetThreeVectorElementAddrByIndex(
0445                             evSObject->monitorTP.positionWorld, var->index1 );
0446                     break;
0447                 }
0448                 if ( var->name == CexmcCFVarBpMonDirL )
0449                 {
0450                     var->addr = GetThreeVectorElementAddrByIndex(
0451                             evSObject->monitorTP.directionLocal, var->index1 );
0452                     break;
0453                 }
0454                 if ( var->name == CexmcCFVarBpMonDirW )
0455                 {
0456                     var->addr = GetThreeVectorElementAddrByIndex(
0457                             evSObject->monitorTP.directionWorld, var->index1 );
0458                     break;
0459                 }
0460                 if ( var->name == CexmcCFVarBpMonMom )
0461                 {
0462                     var->addr = &evSObject->monitorTP.momentumAmp;
0463                     break;
0464                 }
0465                 if ( var->name == CexmcCFVarBpMonTid )
0466                 {
0467                     var->addr = &evSObject->monitorTP.trackId;
0468                     break;
0469                 }
0470                 if ( var->name == CexmcCFVarBpTgtPosL )
0471                 {
0472                     var->addr = GetThreeVectorElementAddrByIndex(
0473                             evSObject->targetTPBeamParticle.positionLocal,
0474                             var->index1 );
0475                     break;
0476                 }
0477                 if ( var->name == CexmcCFVarBpTgtPosW )
0478                 {
0479                     var->addr = GetThreeVectorElementAddrByIndex(
0480                             evSObject->targetTPBeamParticle.positionWorld,
0481                             var->index1 );
0482                     break;
0483                 }
0484                 if ( var->name == CexmcCFVarBpTgtDirL )
0485                 {
0486                     var->addr = GetThreeVectorElementAddrByIndex(
0487                             evSObject->targetTPBeamParticle.directionLocal,
0488                             var->index1 );
0489                     break;
0490                 }
0491                 if ( var->name == CexmcCFVarBpTgtDirW )
0492                 {
0493                     var->addr = GetThreeVectorElementAddrByIndex(
0494                             evSObject->targetTPBeamParticle.directionWorld,
0495                             var->index1 );
0496                     break;
0497                 }
0498                 if ( var->name == CexmcCFVarBpTgtMom )
0499                 {
0500                     var->addr = &evSObject->targetTPBeamParticle.momentumAmp;
0501                     break;
0502                 }
0503                 if ( var->name == CexmcCFVarBpTgtTid )
0504                 {
0505                     var->addr = &evSObject->targetTPBeamParticle.trackId;
0506                     break;
0507                 }
0508                 if ( var->name == CexmcCFVarOpTgtPosL )
0509                 {
0510                     var->addr = GetThreeVectorElementAddrByIndex(
0511                             evSObject->targetTPOutputParticle.positionLocal,
0512                             var->index1 );
0513                     break;
0514                 }
0515                 if ( var->name == CexmcCFVarOpTgtPosW )
0516                 {
0517                     var->addr = GetThreeVectorElementAddrByIndex(
0518                             evSObject->targetTPOutputParticle.positionWorld,
0519                             var->index1 );
0520                     break;
0521                 }
0522                 if ( var->name == CexmcCFVarOpTgtDirL )
0523                 {
0524                     var->addr = GetThreeVectorElementAddrByIndex(
0525                             evSObject->targetTPOutputParticle.directionLocal,
0526                             var->index1 );
0527                     break;
0528                 }
0529                 if ( var->name == CexmcCFVarOpTgtDirW )
0530                 {
0531                     var->addr = GetThreeVectorElementAddrByIndex(
0532                             evSObject->targetTPOutputParticle.directionWorld,
0533                             var->index1 );
0534                     break;
0535                 }
0536                 if ( var->name == CexmcCFVarOpTgtMom )
0537                 {
0538                     var->addr = &evSObject->targetTPOutputParticle.momentumAmp;
0539                     break;
0540                 }
0541                 if ( var->name == CexmcCFVarOpTgtTid )
0542                 {
0543                     var->addr = &evSObject->targetTPOutputParticle.trackId;
0544                     break;
0545                 }
0546                 if ( var->name == CexmcCFVarNpTgtPosL )
0547                 {
0548                     var->addr = GetThreeVectorElementAddrByIndex(
0549                             evSObject->targetTPNucleusParticle.positionLocal,
0550                             var->index1 );
0551                     break;
0552                 }
0553                 if ( var->name == CexmcCFVarNpTgtPosW )
0554                 {
0555                     var->addr = GetThreeVectorElementAddrByIndex(
0556                             evSObject->targetTPNucleusParticle.positionWorld,
0557                             var->index1 );
0558                     break;
0559                 }
0560                 if ( var->name == CexmcCFVarNpTgtDirL )
0561                 {
0562                     var->addr = GetThreeVectorElementAddrByIndex(
0563                             evSObject->targetTPNucleusParticle.directionLocal,
0564                             var->index1 );
0565                     break;
0566                 }
0567                 if ( var->name == CexmcCFVarNpTgtDirW )
0568                 {
0569                     var->addr = GetThreeVectorElementAddrByIndex(
0570                             evSObject->targetTPNucleusParticle.directionWorld,
0571                             var->index1 );
0572                     break;
0573                 }
0574                 if ( var->name == CexmcCFVarNpTgtMom )
0575                 {
0576                     var->addr = &evSObject->targetTPNucleusParticle.momentumAmp;
0577                     break;
0578                 }
0579                 if ( var->name == CexmcCFVarNpTgtTid )
0580                 {
0581                     var->addr = &evSObject->targetTPNucleusParticle.trackId;
0582                     break;
0583                 }
0584                 if ( var->name == CexmcCFVarOpdp1TgtPosL )
0585                 {
0586                     var->addr = GetThreeVectorElementAddrByIndex(
0587                         evSObject->targetTPOutputParticleDecayProductParticle1.
0588                                                                 positionLocal,
0589                         var->index1 );
0590                     break;
0591                 }
0592                 if ( var->name == CexmcCFVarOpdp1TgtPosW )
0593                 {
0594                     var->addr = GetThreeVectorElementAddrByIndex(
0595                         evSObject->targetTPOutputParticleDecayProductParticle1.
0596                                                                 positionWorld,
0597                         var->index1 );
0598                     break;
0599                 }
0600                 if ( var->name == CexmcCFVarOpdp1TgtDirL )
0601                 {
0602                     var->addr = GetThreeVectorElementAddrByIndex(
0603                         evSObject->targetTPOutputParticleDecayProductParticle1.
0604                                                                 directionLocal,
0605                         var->index1 );
0606                     break;
0607                 }
0608                 if ( var->name == CexmcCFVarOpdp1TgtDirW )
0609                 {
0610                     var->addr = GetThreeVectorElementAddrByIndex(
0611                         evSObject->targetTPOutputParticleDecayProductParticle1.
0612                                                                 directionWorld,
0613                         var->index1 );
0614                     break;
0615                 }
0616                 if ( var->name == CexmcCFVarOpdp1TgtMom )
0617                 {
0618                     var->addr = &evSObject->
0619                         targetTPOutputParticleDecayProductParticle1.momentumAmp;
0620                     break;
0621                 }
0622                 if ( var->name == CexmcCFVarOpdp1TgtTid )
0623                 {
0624                     var->addr = &evSObject->
0625                         targetTPOutputParticleDecayProductParticle1.trackId;
0626                     break;
0627                 }
0628                 if ( var->name == CexmcCFVarOpdp2TgtPosL )
0629                 {
0630                     var->addr = GetThreeVectorElementAddrByIndex(
0631                         evSObject->targetTPOutputParticleDecayProductParticle2.
0632                                                                 positionLocal,
0633                         var->index1 );
0634                     break;
0635                 }
0636                 if ( var->name == CexmcCFVarOpdp2TgtPosW )
0637                 {
0638                     var->addr = GetThreeVectorElementAddrByIndex(
0639                         evSObject->targetTPOutputParticleDecayProductParticle2.
0640                                                                 positionWorld,
0641                         var->index1 );
0642                     break;
0643                 }
0644                 if ( var->name == CexmcCFVarOpdp2TgtDirL )
0645                 {
0646                     var->addr = GetThreeVectorElementAddrByIndex(
0647                         evSObject->targetTPOutputParticleDecayProductParticle2.
0648                                                                 directionLocal,
0649                         var->index1 );
0650                     break;
0651                 }
0652                 if ( var->name == CexmcCFVarOpdp2TgtDirW )
0653                 {
0654                     var->addr = GetThreeVectorElementAddrByIndex(
0655                         evSObject->targetTPOutputParticleDecayProductParticle2.
0656                                                                 directionWorld,
0657                         var->index1 );
0658                     break;
0659                 }
0660                 if ( var->name == CexmcCFVarOpdp2TgtMom )
0661                 {
0662                     var->addr = &evSObject->
0663                         targetTPOutputParticleDecayProductParticle2.momentumAmp;
0664                     break;
0665                 }
0666                 if ( var->name == CexmcCFVarOpdp2TgtTid )
0667                 {
0668                     var->addr = &evSObject->
0669                         targetTPOutputParticleDecayProductParticle2.trackId;
0670                     break;
0671                 }
0672                 if ( var->name == CexmcCFVarOpdpVclPosL )
0673                 {
0674                     var->addr = GetThreeVectorElementAddrByIndex(
0675                             evSObject->vetoCounterTPLeft.positionLocal,
0676                             var->index1 );
0677                     break;
0678                 }
0679                 if ( var->name == CexmcCFVarOpdpVclPosW )
0680                 {
0681                     var->addr = GetThreeVectorElementAddrByIndex(
0682                             evSObject->vetoCounterTPLeft.positionWorld,
0683                             var->index1 );
0684                     break;
0685                 }
0686                 if ( var->name == CexmcCFVarOpdpVclDirL )
0687                 {
0688                     var->addr = GetThreeVectorElementAddrByIndex(
0689                             evSObject->vetoCounterTPLeft.directionLocal,
0690                             var->index1 );
0691                     break;
0692                 }
0693                 if ( var->name == CexmcCFVarOpdpVclDirW )
0694                 {
0695                     var->addr = GetThreeVectorElementAddrByIndex(
0696                             evSObject->vetoCounterTPLeft.directionWorld,
0697                             var->index1 );
0698                     break;
0699                 }
0700                 if ( var->name == CexmcCFVarOpdpVclMom )
0701                 {
0702                     var->addr = &evSObject->vetoCounterTPLeft.momentumAmp;
0703                     break;
0704                 }
0705                 if ( var->name == CexmcCFVarOpdpVclTid )
0706                 {
0707                     var->addr = &evSObject->vetoCounterTPLeft.trackId;
0708                     break;
0709                 }
0710                 if ( var->name == CexmcCFVarOpdpVcrPosL )
0711                 {
0712                     var->addr = GetThreeVectorElementAddrByIndex(
0713                             evSObject->vetoCounterTPRight.positionLocal,
0714                             var->index1 );
0715                     break;
0716                 }
0717                 if ( var->name == CexmcCFVarOpdpVcrPosW )
0718                 {
0719                     var->addr = GetThreeVectorElementAddrByIndex(
0720                             evSObject->vetoCounterTPRight.positionWorld,
0721                             var->index1 );
0722                     break;
0723                 }
0724                 if ( var->name == CexmcCFVarOpdpVcrDirL )
0725                 {
0726                     var->addr = GetThreeVectorElementAddrByIndex(
0727                             evSObject->vetoCounterTPRight.directionLocal,
0728                             var->index1 );
0729                     break;
0730                 }
0731                 if ( var->name == CexmcCFVarOpdpVcrDirW )
0732                 {
0733                     var->addr = GetThreeVectorElementAddrByIndex(
0734                             evSObject->vetoCounterTPRight.directionWorld,
0735                             var->index1 );
0736                     break;
0737                 }
0738                 if ( var->name == CexmcCFVarOpdpVcrMom )
0739                 {
0740                     var->addr = &evSObject->vetoCounterTPRight.momentumAmp;
0741                     break;
0742                 }
0743                 if ( var->name == CexmcCFVarOpdpVcrTid )
0744                 {
0745                     var->addr = &evSObject->vetoCounterTPRight.trackId;
0746                     break;
0747                 }
0748                 if ( var->name == CexmcCFVarOpdpClPosL )
0749                 {
0750                     var->addr = GetThreeVectorElementAddrByIndex(
0751                             evSObject->calorimeterTPLeft.positionLocal,
0752                             var->index1 );
0753                     break;
0754                 }
0755                 if ( var->name == CexmcCFVarOpdpClPosW )
0756                 {
0757                     var->addr = GetThreeVectorElementAddrByIndex(
0758                             evSObject->calorimeterTPLeft.positionWorld,
0759                             var->index1 );
0760                     break;
0761                 }
0762                 if ( var->name == CexmcCFVarOpdpClDirL )
0763                 {
0764                     var->addr = GetThreeVectorElementAddrByIndex(
0765                             evSObject->calorimeterTPLeft.directionLocal,
0766                             var->index1 );
0767                     break;
0768                 }
0769                 if ( var->name == CexmcCFVarOpdpClDirW )
0770                 {
0771                     var->addr = GetThreeVectorElementAddrByIndex(
0772                             evSObject->calorimeterTPLeft.directionWorld,
0773                             var->index1 );
0774                     break;
0775                 }
0776                 if ( var->name == CexmcCFVarOpdpClMom )
0777                 {
0778                     var->addr = &evSObject->calorimeterTPLeft.momentumAmp;
0779                     break;
0780                 }
0781                 if ( var->name == CexmcCFVarOpdpClTid )
0782                 {
0783                     var->addr = &evSObject->calorimeterTPLeft.trackId;
0784                     break;
0785                 }
0786                 if ( var->name == CexmcCFVarOpdpCrPosL )
0787                 {
0788                     var->addr = GetThreeVectorElementAddrByIndex(
0789                             evSObject->calorimeterTPRight.positionLocal,
0790                             var->index1 );
0791                     break;
0792                 }
0793                 if ( var->name == CexmcCFVarOpdpCrPosW )
0794                 {
0795                     var->addr = GetThreeVectorElementAddrByIndex(
0796                             evSObject->calorimeterTPRight.positionWorld,
0797                             var->index1 );
0798                     break;
0799                 }
0800                 if ( var->name == CexmcCFVarOpdpCrDirL )
0801                 {
0802                     var->addr = GetThreeVectorElementAddrByIndex(
0803                             evSObject->calorimeterTPRight.directionLocal,
0804                             var->index1 );
0805                     break;
0806                 }
0807                 if ( var->name == CexmcCFVarOpdpCrDirW )
0808                 {
0809                     var->addr = GetThreeVectorElementAddrByIndex(
0810                             evSObject->calorimeterTPRight.directionWorld,
0811                             var->index1 );
0812                     break;
0813                 }
0814                 if ( var->name == CexmcCFVarOpdpCrMom )
0815                 {
0816                     var->addr = &evSObject->calorimeterTPRight.momentumAmp;
0817                     break;
0818                 }
0819                 if ( var->name == CexmcCFVarOpdpCrTid )
0820                 {
0821                     var->addr = &evSObject->calorimeterTPRight.trackId;
0822                     break;
0823                 }
0824                 if ( var->name == CexmcCFVarIpSCM )
0825                 {
0826                     var->addr = GetLorentzVectorElementAddrByIndex(
0827                         evSObject->productionModelData.incidentParticleSCM,
0828                         var->index1 );
0829                     break;
0830                 }
0831                 if ( var->name == CexmcCFVarIpLAB )
0832                 {
0833                     var->addr = GetLorentzVectorElementAddrByIndex(
0834                         evSObject->productionModelData.incidentParticleLAB,
0835                         var->index1 );
0836                     break;
0837                 }
0838                 if ( var->name == CexmcCFVarNpSCM )
0839                 {
0840                     var->addr = GetLorentzVectorElementAddrByIndex(
0841                         evSObject->productionModelData.nucleusParticleSCM,
0842                         var->index1 );
0843                     break;
0844                 }
0845                 if ( var->name == CexmcCFVarNpLAB )
0846                 {
0847                     var->addr = GetLorentzVectorElementAddrByIndex(
0848                         evSObject->productionModelData.nucleusParticleLAB,
0849                         var->index1 );
0850                     break;
0851                 }
0852                 if ( var->name == CexmcCFVarOpSCM )
0853                 {
0854                     var->addr = GetLorentzVectorElementAddrByIndex(
0855                         evSObject->productionModelData.outputParticleSCM,
0856                         var->index1 );
0857                     break;
0858                 }
0859                 if ( var->name == CexmcCFVarOpLAB )
0860                 {
0861                     var->addr = GetLorentzVectorElementAddrByIndex(
0862                         evSObject->productionModelData.outputParticleLAB,
0863                         var->index1 );
0864                     break;
0865                 }
0866                 if ( var->name == CexmcCFVarNopSCM )
0867                 {
0868                     var->addr = GetLorentzVectorElementAddrByIndex(
0869                         evSObject->productionModelData.nucleusOutputParticleSCM,
0870                         var->index1 );
0871                     break;
0872                 }
0873                 if ( var->name == CexmcCFVarNopLAB )
0874                 {
0875                     var->addr = GetLorentzVectorElementAddrByIndex(
0876                         evSObject->productionModelData.nucleusOutputParticleLAB,
0877                         var->index1 );
0878                     break;
0879                 }
0880                 if ( var->name == CexmcCFVarIpId )
0881                 {
0882                     var->addr =
0883                         &evSObject->productionModelData.incidentParticle;
0884                     break;
0885                 }
0886                 if ( var->name == CexmcCFVarNpId )
0887                 {
0888                     var->addr = &evSObject->productionModelData.nucleusParticle;
0889                     break;
0890                 }
0891                 if ( var->name == CexmcCFVarOpId )
0892                 {
0893                     var->addr = &evSObject->productionModelData.outputParticle;
0894                     break;
0895                 }
0896                 if ( var->name == CexmcCFVarNopId )
0897                 {
0898                     var->addr =
0899                         &evSObject->productionModelData.nucleusOutputParticle;
0900                     break;
0901                 }
0902                 if ( var->name == CexmcCFVarConst_eV )
0903                 {
0904                     var->addr = &constants[ 0 ];
0905                     break;
0906                 }
0907                 if ( var->name == CexmcCFVarConst_keV )
0908                 {
0909                     var->addr = &constants[ 1 ];
0910                     break;
0911                 }
0912                 if ( var->name == CexmcCFVarConst_MeV )
0913                 {
0914                     var->addr = &constants[ 2 ];
0915                     break;
0916                 }
0917                 if ( var->name == CexmcCFVarConst_GeV )
0918                 {
0919                     var->addr = &constants[ 3 ];
0920                     break;
0921                 }
0922                 if ( var->name == CexmcCFVarConst_mm )
0923                 {
0924                     var->addr = &constants[ 4 ];
0925                     break;
0926                 }
0927                 if ( var->name == CexmcCFVarConst_cm )
0928                 {
0929                     var->addr = &constants[ 5 ];
0930                     break;
0931                 }
0932                 if ( var->name == CexmcCFVarConst_m )
0933                 {
0934                     var->addr = &constants[ 6 ];
0935                     break;
0936                 }
0937             } while ( false );
0938         }
0939     }
0940 }
0941 
0942 
0943 void  CexmcASTEval::ResetAddressBinding( CexmcAST::Subtree &  ast )
0944 {
0945     for ( std::vector< CexmcAST::Node >::iterator  k( ast.children.begin() );
0946                                                   k != ast.children.end(); ++k )
0947     {
0948         CexmcAST::Subtree *  subtree( boost::get< CexmcAST::Subtree >( &*k ) );
0949 
0950         if ( subtree )
0951         {
0952             ResetAddressBinding( *subtree );
0953         }
0954         else
0955         {
0956             CexmcAST::Leaf &      leaf( boost::get< CexmcAST::Leaf >( *k ) );
0957             CexmcAST::Variable *  var( boost::get< CexmcAST::Variable >(
0958                                                                     &leaf ) );
0959             if ( var )
0960                 var->addr = ( const int * ) NULL;
0961         }
0962     }
0963 }
0964 
0965 #endif
0966