LCOV - code coverage report
Current view: top level - TEvtGen/EvtGen/EvtGenBase - EvtMultiChannelParser.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 117 0.0 %
Date: 2016-06-14 17:26:59 Functions: 0 6 0.0 %

          Line data    Source code
       1             : //-----------------------------------------------------------------------
       2             : // File and Version Information: 
       3             : //      $Id: EvtMultiChannelParser.cpp,v 1.4 2009-03-16 15:46:01 robbep Exp $
       4             : // 
       5             : // Environment:
       6             : //      This software is part of the EvtGen package developed jointly
       7             : //      for the BaBar and CLEO collaborations. If you use all or part
       8             : //      of it, please give an appropriate acknowledgement.
       9             : //
      10             : // Copyright Information:
      11             : //      Copyright (C) 1998 Caltech, UCSB
      12             : //
      13             : // Module creator:
      14             : //      Alexei Dvoretskii, Caltech, 2001-2002.
      15             : //-----------------------------------------------------------------------
      16             : #include "EvtGenBase/EvtPatches.hh"
      17             : 
      18             : #include <assert.h>
      19             : #include <stdlib.h>
      20             : #include <stdio.h>
      21             : #include <math.h>
      22             : #include <string>
      23             : #include <vector>
      24             : #include "EvtGenBase/EvtParser.hh"
      25             : #include "EvtGenBase/EvtMultiChannelParser.hh"
      26             : #include "EvtGenBase/EvtDecayMode.hh"
      27             : #include "EvtGenBase/EvtPDL.hh"
      28             : 
      29             : using std::string;
      30             : using std::vector;
      31             : 
      32             : EvtDecayMode EvtMultiChannelParser::getDecayMode(const char* file)
      33             : {
      34             :   // Open file, read tokens
      35             : 
      36           0 :   EvtParser parser;
      37           0 :   parser.read(file);
      38             : 
      39             :   // Seek Decay
      40             : 
      41             :   int i = 0;
      42           0 :   int N = parser.getNToken();
      43           0 :   while(i<N) {
      44             :     
      45           0 :     std::string tok = parser.getToken(i++);
      46           0 :     if(tok == std::string("Decay")) break;
      47           0 :   }
      48             :   
      49             :   // Get mother
      50             : 
      51           0 :   string mother = string(parser.getToken(i++).c_str());
      52           0 :   std::string bf = parser.getToken(i++);
      53             : 
      54           0 :   vector<string> dauV;
      55             :   // Get daughters
      56             :     
      57           0 :   while(1) {
      58             : 
      59           0 :     std::string d = parser.getToken(i++);
      60             : 
      61           0 :     if(EvtPDL::getStdHep(EvtPDL::getId(d.c_str())) == 0) break;
      62             :     
      63           0 :     dauV.push_back(string(d.c_str()));
      64           0 :   }
      65             :   
      66           0 :   EvtDecayMode mode(mother,dauV);
      67           0 :   printf("Decay File defines mode %s\n",mode.mode().c_str());
      68             : 
      69             :   return mode;
      70           0 : }
      71             : 
      72             : 
      73             : 
      74             : void EvtMultiChannelParser::parse(const char* file, const char* model)
      75             : {
      76             :   // Open file, read tokens
      77             : 
      78           0 :   EvtParser parser;
      79           0 :   parser.read(file);
      80             : 
      81             : 
      82             :   // Get parameters (tokens between the model name and ;)
      83             : 
      84             :   int i = 0;
      85           0 :   int N = parser.getNToken();
      86             : 
      87             :   // Seek the model name
      88             : 
      89           0 :   while(i<N) {
      90             :    
      91           0 :     std::string tok = parser.getToken(i++);
      92           0 :     if(tok == std::string(model)) break;
      93           0 :   }
      94           0 :   if(i == N) {
      95             : 
      96           0 :     printf("No model %s found in decay file %s",model,file);
      97           0 :     exit(0);
      98             :   }  
      99             : 
     100             :   
     101             :   // Add all tokens up to a semicolon to vector 
     102             : 
     103           0 :   std::vector<std::string> v;
     104           0 :   while(i<N) {
     105             : 
     106           0 :     std::string tok = parser.getToken(i++);
     107           0 :     if(tok == std::string(";")) break;
     108           0 :     else v.push_back(tok);
     109           0 :   }
     110             :   
     111           0 :   if(i == N) {
     112             : 
     113           0 :     printf("No terminating ; found in decay file %s",file);
     114           0 :     assert(0);
     115             :   }
     116             : 
     117           0 :   parse(v);
     118           0 : }
     119             : 
     120             : 
     121             : void EvtMultiChannelParser::parse(const std::vector<std::string>& v)
     122             : {
     123             :   // place holder for strtod
     124             :   char** tc = 0;
     125             : 
     126             : 
     127             :   // Get PDF maximum or number of points to 
     128             :   // use in the scan.
     129             : 
     130           0 :   if(v[0] == std::string("MAXPDF")) {
     131             :     
     132           0 :     _pdfMax = strtod(v[1].c_str(),tc);
     133           0 :     if(_pdfMax <= 0) { printf("Bad pdfMax=%f\n",_pdfMax); assert(0); }
     134             :   }
     135             :   else 
     136           0 :     if(v[0] == std::string("SCANPDF")) {
     137             : 
     138           0 :       _nScan = atoi(v[1].c_str());
     139             :     }
     140             :     else {
     141             : 
     142           0 :       printf("Error parsing decay file\n");
     143           0 :       assert(0);
     144             :     }
     145             : 
     146             : 
     147             :   // Now parse the rest of file for amplitude specifications.
     148             : 
     149             :   bool conjugate = false;
     150           0 :   size_t i = 2;
     151           0 :   assert(isKeyword(v[2]));
     152             :   
     153           0 :   while(i  < v.size()) {
     154             :   
     155             :     size_t i0 = i;
     156             :   
     157             :     // Switch to conjugate amplitudes after keyword
     158           0 :     if(v[i] == std::string("CONJUGATE")) {
     159             :       
     160           0 :       assert(conjugate == false);
     161             :       conjugate = true;
     162           0 :       i++;
     163           0 :       _dm =  strtod(v[i++].c_str(),tc);
     164           0 :       _mixAmpli = strtod(v[i++].c_str(),tc);
     165           0 :       _mixPhase = strtod(v[i++].c_str(),tc);
     166           0 :     }
     167             : 
     168           0 :     if (i >= v.size()) break;
     169           0 :     std::vector<std::string> params;
     170           0 :     EvtComplex c;
     171           0 :     int format;
     172             : 
     173           0 :     if(!conjugate && v[i] == std::string("AMPLITUDE")) {
     174             : 
     175           0 :       while(!isKeyword(v[++i])) params.push_back(v[i]);
     176           0 :       _amp.push_back(params);
     177             :       
     178           0 :       parseComplexCoef(i,v,c,format);
     179           0 :       _ampCoef.push_back(c);
     180           0 :       _coefFormat.push_back(format);
     181           0 :       continue;
     182             :     }
     183             :     else 
     184           0 :       if(conjugate && v[i] == std::string("AMPLITUDE")) {
     185             : 
     186           0 :         while(!isKeyword(v[++i])) params.push_back(v[i]);
     187           0 :         _ampConj.push_back(params);
     188           0 :         parseComplexCoef(i,v,c,format);
     189           0 :         _ampConjCoef.push_back(c);
     190           0 :         _coefConjFormat.push_back(format);
     191           0 :         continue;
     192             :       }
     193             :       else {
     194             :         
     195           0 :         printf("Expect keyword, found parameter %s\n",v[i].c_str());
     196           0 :         assert(0);
     197             :       }
     198             :     
     199             : 
     200             :     assert(i > i0); _unused( i0 );
     201           0 :   }
     202             : 
     203           0 :   printf("PARSING SUCCESSFUL\n");
     204           0 :   printf("%d amplitude terms\n",(int)_amp.size());
     205           0 :   printf("%d conj amplitude terms\n",(int)_ampConj.size());
     206           0 : }
     207             : 
     208             : 
     209             : 
     210             : void EvtMultiChannelParser::parseComplexCoef(size_t& i, const std::vector<std::string>& v,
     211             :                                              EvtComplex& c, int& format) 
     212             : {
     213             :   // place holder for strtod
     214             :   char** tc = 0;
     215             : 
     216           0 :   std::string coefString = v[i++];
     217           0 :   assert(coefString == std::string("COEFFICIENT"));
     218             : 
     219           0 :   if(v[i] == std::string("POLAR_DEG")) {
     220             : 
     221           0 :       double mag = strtod(v[i+1].c_str(),tc);
     222           0 :       double phaseRad = strtod(v[i+2].c_str(),tc)*EvtConst::pi/180.0;
     223           0 :       i += 3;
     224           0 :       c = EvtComplex(mag*cos(phaseRad),mag*sin(phaseRad));  
     225           0 :       format = POLAR_DEG;
     226           0 :   }
     227           0 :   else if(v[i] == std::string("POLAR_RAD")) {
     228             :     
     229           0 :     double mag = strtod(v[i+1].c_str(),tc);
     230           0 :     double phaseRad = strtod(v[i+2].c_str(),tc);
     231           0 :     i += 3;
     232           0 :     c = EvtComplex(mag*cos(phaseRad),mag*sin(phaseRad));  
     233           0 :     format = POLAR_RAD;    
     234           0 :   }
     235           0 :   else if(v[i] == std::string("CARTESIAN")) {
     236             : 
     237           0 :     double re = strtod(v[i+1].c_str(),tc);
     238           0 :     double im = strtod(v[i+2].c_str(),tc);
     239           0 :     i += 3;
     240           0 :     c = EvtComplex(re,im);  
     241           0 :     format = CARTESIAN;
     242             :   }
     243             :   else {
     244             :     
     245           0 :     printf("Invalid format %s for complex coefficient\n",v[i].c_str());
     246           0 :     exit(0);
     247             :   }
     248           0 : }
     249             : 
     250             : 
     251             : double EvtMultiChannelParser::parseRealCoef(int& i, const std::vector<std::string>& v)
     252             : {
     253             :   // place holder for strtod
     254             :   char** tc = 0;
     255             :   double value = 0;
     256             : 
     257           0 :   if(v[i] == std::string("COEFFICIENT")) {
     258             : 
     259           0 :     value = strtod(v[i+1].c_str(),tc);
     260             :   }
     261           0 :   else assert(0);
     262             : 
     263           0 :   i += 2;
     264             : 
     265           0 :   assert(value > 0.);
     266           0 :   return value;
     267             : }
     268             : 
     269             : 
     270             : bool EvtMultiChannelParser::isKeyword(const std::string& s)
     271             : {
     272           0 :   if(s == std::string("AMPLITUDE")) return true;
     273           0 :   if(s == std::string("CONJUGATE")) return true;
     274           0 :   if(s == std::string("COEFFICIENT")) return true;
     275           0 :   return false;
     276           0 : }
     277             : 
     278             : 
     279             : 

Generated by: LCOV version 1.11