CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_4/src/GeneratorInterface/AlpgenInterface/src/AlpgenHeader.cc

Go to the documentation of this file.
00001 #include <algorithm>
00002 #include <iostream>
00003 #include <sstream>
00004 #include <fstream>
00005 #include <string>
00006 #include <memory>
00007 #include <map>
00008 
00009 #include <boost/algorithm/string/classification.hpp>
00010 #include <boost/algorithm/string/split.hpp>
00011 #include <boost/algorithm/string/trim.hpp>
00012 
00013 #include "FWCore/Utilities/interface/Exception.h"
00014 
00015 #include "GeneratorInterface/AlpgenInterface/interface/AlpgenHeader.h"
00016 
00017 namespace {
00018   struct AlpgenParTokens {
00019     unsigned int                index;
00020     std::vector<double>         values;
00021     std::vector<std::string>    comments;
00022 
00023     bool parse(const std::string &line, bool withIndex);
00024   };
00025 }
00026 
00027 bool AlpgenParTokens::parse(const std::string &line, bool withIndex)
00028 {
00029   std::string::size_type pos = line.find('!');
00030   if (pos == std::string::npos)
00031     return false;
00032 
00033   std::string tmp = boost::trim_copy(line.substr(0, pos));
00034   boost::split(comments, tmp, boost::algorithm::is_space(),
00035                boost::token_compress_on);
00036   if (comments.empty())
00037     return false;
00038 
00039   unsigned int i = 0, n = comments.size();
00040   if (withIndex) {
00041     std::istringstream ss(comments[i++]);
00042     ss >> index;
00043     if (ss.bad() ||
00044         ss.peek() != std::istringstream::traits_type::eof())
00045       return false;
00046   }
00047 
00048   values.clear();
00049   while(i < n) {
00050     std::istringstream ss(comments[i++]);
00051     double value;
00052     ss >> value;
00053     if (ss.bad() ||
00054         ss.peek() != std::istringstream::traits_type::eof())
00055       return false;
00056 
00057     values.push_back(value);
00058   }
00059 
00060   tmp = boost::trim_copy(line.substr(pos + 1));
00061   boost::split(comments, tmp, boost::algorithm::is_space(),
00062                boost::token_compress_on);
00063 
00064   return true;
00065 }
00066 
00067 bool AlpgenHeader::parse(const std::vector<std::string>::const_iterator &begin,
00068                          const std::vector<std::string>::const_iterator &end)
00069 {
00070   std::vector<std::string>::const_iterator line = begin;
00071   
00072   // Mimicking Alpgen - read the _unw.par file until you find the "****".
00073   while(line != end)
00074     if ((line++)->find("****") != std::string::npos)
00075       break;
00076   
00077   AlpgenParTokens tokens;
00078   
00079   // hard process code
00080   if (line == end || !tokens.parse(*line++, true) ||
00081       !tokens.values.empty())
00082     return false;
00083   ihrd = tokens.index;
00084 
00085   // mc,mb,mt,mw,mz,mh
00086   if (line == end || !tokens.parse(*line++, false) ||
00087       tokens.values.size() < 6)
00088     return false;
00089 
00090   std::copy(tokens.values.begin(), tokens.values.begin() + 6, masses);
00091 
00092   // key - value pairs
00093   params.clear();
00094   while(line != end && line->find("****") == std::string::npos) {
00095     if (!tokens.parse(*line++, true) ||
00096         tokens.values.size() != 1)
00097       return false;
00098     params[(Parameter)tokens.index] = tokens.values[0];
00099   }
00100   if (line == end)
00101     return false;
00102   else
00103     line++;
00104 
00105   // cross-section
00106   if (line == end || !tokens.parse(*line++, false) ||
00107       tokens.values.size() != 2)
00108     return false;
00109 
00110   xsec = tokens.values[0];
00111   xsecErr = tokens.values[1];
00112 
00113   // unweighted events, luminosity
00114   if (line == end || !tokens.parse(*line++, true) ||
00115       tokens.values.size() != 1)
00116     return false;
00117 
00118   nEvents = tokens.index;
00119   lumi = tokens.values[0];
00120 
00121   return true;
00122 }
00123 
00124 // create human-readable representation for all Alpgen parameter indices
00125 
00126 #define DEFINE_ALPGEN_PARAMETER(x) { AlpgenHeader::x, #x }
00127 
00128 namespace {
00129   struct AlpgenParameterName {
00130     AlpgenHeader::Parameter     index;
00131     const char*                 name;
00132 
00133     inline bool operator == (AlpgenHeader::Parameter index) const
00134     { return this->index == index; }
00135   } 
00136   
00137   static const alpgenParameterNames[] = {
00138     DEFINE_ALPGEN_PARAMETER(ih2),
00139     DEFINE_ALPGEN_PARAMETER(ebeam),
00140     DEFINE_ALPGEN_PARAMETER(ndns),
00141     DEFINE_ALPGEN_PARAMETER(iqopt),
00142     DEFINE_ALPGEN_PARAMETER(qfac),
00143     DEFINE_ALPGEN_PARAMETER(ickkw),
00144     DEFINE_ALPGEN_PARAMETER(ktfac),
00145     DEFINE_ALPGEN_PARAMETER(njets),
00146     DEFINE_ALPGEN_PARAMETER(ihvy),
00147     DEFINE_ALPGEN_PARAMETER(ihvy2),
00148     DEFINE_ALPGEN_PARAMETER(nw),
00149     DEFINE_ALPGEN_PARAMETER(nz),
00150     DEFINE_ALPGEN_PARAMETER(nh),
00151     DEFINE_ALPGEN_PARAMETER(nph),
00152     DEFINE_ALPGEN_PARAMETER(ptjmin),
00153     DEFINE_ALPGEN_PARAMETER(ptbmin),
00154     DEFINE_ALPGEN_PARAMETER(ptcmin),
00155     DEFINE_ALPGEN_PARAMETER(ptlmin),
00156     DEFINE_ALPGEN_PARAMETER(metmin),
00157     DEFINE_ALPGEN_PARAMETER(ptphmin),
00158     DEFINE_ALPGEN_PARAMETER(etajmax),
00159     DEFINE_ALPGEN_PARAMETER(etabmax),
00160     DEFINE_ALPGEN_PARAMETER(etacmax),
00161     DEFINE_ALPGEN_PARAMETER(etalmax),
00162     DEFINE_ALPGEN_PARAMETER(etaphmax),
00163     DEFINE_ALPGEN_PARAMETER(drjmin),
00164     DEFINE_ALPGEN_PARAMETER(drbmin),
00165     DEFINE_ALPGEN_PARAMETER(drcmin),
00166     DEFINE_ALPGEN_PARAMETER(drlmin),
00167     DEFINE_ALPGEN_PARAMETER(drphjmin),
00168     DEFINE_ALPGEN_PARAMETER(drphlmin),
00169     DEFINE_ALPGEN_PARAMETER(drphmin),
00170     DEFINE_ALPGEN_PARAMETER(mllmin),
00171     DEFINE_ALPGEN_PARAMETER(mllmax),
00172     DEFINE_ALPGEN_PARAMETER(iseed1),
00173     DEFINE_ALPGEN_PARAMETER(iseed2),
00174     DEFINE_ALPGEN_PARAMETER(itopprc),
00175     DEFINE_ALPGEN_PARAMETER(cluopt),
00176     DEFINE_ALPGEN_PARAMETER(iseed3),
00177     DEFINE_ALPGEN_PARAMETER(iseed4)
00178   };
00179 } // anonymous namespace
00180 
00181 std::string AlpgenHeader::parameterName(Parameter index)
00182 {
00183   static const unsigned int size = sizeof alpgenParameterNames /
00184     sizeof alpgenParameterNames[0];
00185 
00186   const AlpgenParameterName *pos =
00187     std::find(alpgenParameterNames,
00188               alpgenParameterNames + size, index);
00189 
00190   if (pos != alpgenParameterNames + size)
00191     return pos->name;
00192 
00193   std::ostringstream ss;
00194   ss << "unknown " << (int)index;
00195   return ss.str();
00196 }