CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/SimG4Core/Physics/src/DDG4ProductionCuts.cc

Go to the documentation of this file.
00001 #include "SimG4Core/Physics/interface/DDG4ProductionCuts.h"
00002 #include "SimG4Core/Notification/interface/SimG4Exception.h"
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 
00005 #include "G4ProductionCuts.hh"
00006 #include "G4RegionStore.hh"
00007 
00008 #include <algorithm>
00009 
00010 DDG4ProductionCuts::DDG4ProductionCuts(const G4LogicalVolumeToDDLogicalPartMap& map, int verb) : map_(map), m_Verbosity(verb) {
00011     m_KeywordRegion =  "CMSCutsRegion";
00012     initialize();
00013 }
00014 
00015 DDG4ProductionCuts::~DDG4ProductionCuts(){
00016 }
00017 
00023 bool dd_is_greater(const std::pair<G4LogicalVolume*, DDLogicalPart> & p1,
00024                    const std::pair<G4LogicalVolume*, DDLogicalPart> & p2) {
00025   bool result = false;
00026   if (p1.second.name().ns() > p2.second.name().ns()) {
00027     result = true;
00028   }
00029   if (p1.second.name().ns() == p2.second.name().ns()) {
00030     if (p1.second.name().name() > p2.second.name().name()) {
00031       result = true;
00032     }
00033     if (p1.second.name().name() == p2.second.name().name()) {
00034       if (p1.first->GetName() > p2.first->GetName()) {
00035         result = true;
00036       }
00037     }
00038   }
00039   return result;
00040 }                  
00041 
00042 void DDG4ProductionCuts::update() {
00043   //
00044   // Loop over all DDLP and provide the cuts for each region
00045   //
00046   for (G4LogicalVolumeToDDLogicalPartMap::Vector::iterator tit = vec_.begin();
00047        tit != vec_.end(); tit++){
00048     setProdCuts((*tit).second,(*tit).first);
00049   }
00050 }
00051 
00052 
00053 void DDG4ProductionCuts::initialize() {
00054 
00055   vec_ = map_.all(m_KeywordRegion);
00056   // sort all root volumes - to get the same sequence at every run of the application.
00057   // (otherwise, the sequence will depend on the pointer (memory address) of the 
00058   // involved objects, because 'new' does no guarantee that you allways get a
00059   // higher (or lower) address when allocating an object of the same type ...
00060   sort(vec_.begin(),vec_.end(),&dd_is_greater);
00061   if ( m_Verbosity > 0 ) {
00062     LogDebug("Physics") <<" DDG4ProductionCuts (New) : starting\n"
00063                         <<" DDG4ProductionCuts : Got "<<vec_.size()
00064                         <<" region roots.\n"
00065                         <<" DDG4ProductionCuts : List of all roots:";
00066     for ( size_t jj=0; jj<vec_.size(); ++jj)
00067       LogDebug("Physics") << "   DDG4ProductionCuts : root=" 
00068                           << vec_[jj].second.name();
00069   }
00070 
00071   // Now generate all the regions
00072   for (G4LogicalVolumeToDDLogicalPartMap::Vector::iterator tit = vec_.begin();
00073        tit != vec_.end(); tit++) {
00074 
00075     std::string  regionName;
00076     unsigned int num= map_.toString(m_KeywordRegion,(*tit).second,regionName);
00077   
00078     if (num != 1)
00079       throw SimG4Exception("DDG4ProductionCuts: Problem with Region tags.");
00080 
00081     G4Region * region = getRegion(regionName);
00082     region->AddRootLogicalVolume((*tit).first);
00083   
00084     if ( m_Verbosity > 0 )
00085       LogDebug("Physics") << " MakeRegions: added " <<((*tit).first)->GetName()
00086                           << " to region " << region->GetName();
00087   }
00088 }
00089 
00090 
00091 void DDG4ProductionCuts::setProdCuts(const DDLogicalPart lpart, 
00092                                      G4LogicalVolume* lvol ) {  
00093   
00094   if ( m_Verbosity > 0 ) 
00095     LogDebug("Physics") <<" DDG4ProductionCuts: inside setProdCuts";
00096   
00097   G4Region * region = 0;
00098   
00099   std::string  regionName;
00100   unsigned int num= map_.toString(m_KeywordRegion,lpart,regionName);
00101   
00102   if (num != 1) 
00103     throw SimG4Exception("DDG4ProductionCuts: Problem with Region tags.");
00104   
00105   if ( m_Verbosity > 0 ) LogDebug("Physics") << "Using region " << regionName;
00106 
00107   region = getRegion(regionName);
00108 
00109   //
00110   // search for production cuts
00111   // you must have three of them: e+ e- gamma
00112   //
00113   double gammacut;
00114   double electroncut;
00115   double positroncut;
00116   int temp =  map_.toDouble("ProdCutsForGamma",lpart,gammacut);
00117   if (temp != 1){
00118     throw SimG4Exception("DDG4ProductionCuts: Problem with Region tags: no/more than one ProdCutsForGamma.");
00119   }
00120   temp =  map_.toDouble("ProdCutsForElectrons",lpart,electroncut);
00121   if (temp != 1){
00122     throw SimG4Exception("DDG4ProductionCuts: Problem with Region tags: no/more than one ProdCutsForElectrons.");
00123   }
00124   temp =  map_.toDouble("ProdCutsForPositrons",lpart,positroncut);
00125   if (temp != 1) {
00126     throw SimG4Exception("DDG4ProductionCuts: Problem with Region tags: no/more than one ProdCutsForPositrons.");
00127   }
00128   //
00129   // For the moment I assume all of the three are set
00130   //
00131   G4ProductionCuts * prodCuts = getProductionCuts(region);
00132   prodCuts->SetProductionCut( gammacut, idxG4GammaCut );
00133   prodCuts->SetProductionCut( electroncut, idxG4ElectronCut );
00134   prodCuts->SetProductionCut( positroncut, idxG4PositronCut );
00135   // For recoil use the same cut as for e-
00136   prodCuts->SetProductionCut( electroncut, idxG4ProtonCut );
00137   if ( m_Verbosity > 0 ) {
00138     LogDebug("Physics") << "DDG4ProductionCuts : Setting cuts for " 
00139                         << regionName << "\n    Electrons: " << electroncut
00140                         << "\n    Positrons: " << positroncut
00141                         << "\n    Gamma    : " << gammacut;
00142   }
00143 }
00144 
00145 G4Region * DDG4ProductionCuts::getRegion(const std::string & regName) {
00146   G4Region * reg =  G4RegionStore::GetInstance()->FindOrCreateRegion (regName);
00147   return reg;
00148 }
00149 
00150  G4ProductionCuts * DDG4ProductionCuts::getProductionCuts( G4Region* reg ) {
00151 
00152   G4ProductionCuts * prodCuts = reg->GetProductionCuts();
00153   if( !prodCuts ) {
00154     prodCuts = new G4ProductionCuts();
00155     reg->SetProductionCuts(prodCuts);
00156   }
00157   return prodCuts;
00158 }
00159