Photos.cxx

00001 #include <stdarg.h>
00002 #include <iostream>
00003 #include <vector>
00004 
00005 #include "PhotosRandom.h"
00006 #include "PhotosEvent.h"
00007 #include "Photos.h"
00008 #include "Log.h"
00009 using std::vector;
00010 using std::cout;
00011 using std::endl;
00012 using std::ios_base;
00013 
00014 namespace Photospp
00015 {
00016 
00017 Photos Photos::_instance;
00018 
00019 vector<vector<int>* >    *Photos::supBremList    = 0;
00020 vector<vector<int>* >    *Photos::forceBremList  = 0;
00021 vector<pair<int,double>* > *Photos::forceMassList = 0;
00022 vector<int>              *Photos::ignoreStatusCodeList = 0;
00023 bool Photos::isSuppressed=false;
00024 bool Photos::massFrom4Vector=true;
00025 double Photos::momentum_conservation_threshold   = 0.1;
00026 bool Photos::meCorrectionWtForZ=false;
00027 bool Photos::meCorrectionWtForW=false;
00028 bool Photos::meCorrectionWtForScalar=false;
00029 bool Photos::isCreateHistoryEntries=false;
00030 int  Photos::historyEntriesStatus = 3;
00031 double (*Photos::randomDouble)() = PhotosRandom::randomReal;
00032 
00033 Photos::Photos()
00034 {
00035         setAlphaQED           (0.00729735039);
00036         setInfraredCutOff     (0.01);
00037         setInterference       (true);
00038         setDoubleBrem         (true);
00039         setQuatroBrem         (false);
00040         setTopProcessRadiation(true);
00041         setCorrectionWtForW   (true);
00042 
00043         // setExponentiation(true) moved to initialize() due to communication
00044         // problems with Fortran under MacOS.
00045         phokey_.iexp = 1;
00046 }
00047 
00048 void Photos::initialize()
00049 {
00050 // Should return if already initialized?
00051 
00052 /*******************************************************************************
00053   All the following parameter setters can be called after PHOINI.
00054   Initialization of kinematic correction against rounding errors.
00055   The set values will be used later if called with zero.
00056   Default parameter is 1 (no correction) optionally 2, 3, 4
00057   In case of exponentiation new version 5 is needed in most cases.
00058   Definition given here will be thus overwritten in such a case
00059   below in routine PHOCIN
00060 *******************************************************************************/
00061         if(!phokey_.iexp) initializeKinematicCorrections(1);
00062         else              setExponentiation(true);
00063 
00064         int buf=1;
00065         iphqrk_(&buf); // Blocks emission from quarks if buf=1 (default); enables if buf=2
00066                        // Physical treatment will be 3, option 2 is not realistic and for tests only
00067         buf=2;
00068         iphekl_(&buf); // Blocks emission in  pi0 to gamma e+ e- if parameter is >1 (enables otherwise)
00069 
00070 // Initialize status counter for warning messages
00071         for(int i=0;i<10;i++) phosta_.status[i]=0;
00072 // elementary security level, should remain 1 but we may want to have a method to change.
00073         phosta_.ifstop=1; 
00074 
00075         pholun_.phlun=6; // Logical output unit for printing error messages
00076 
00077 // Define pi and 2*pi
00078         phpico_.pi   =3.14159265358979324;
00079         phpico_.twopi=6.28318530717958648;
00080 
00081 // Further initialization done automatically
00082 // see places with - VARIANT A - VARIANT B - all over to switch between options
00083 
00084 //----------- SLOWER VARIANT A, but stable ------------------
00085 //--- it is limiting choice for small XPHCUT in fixed orer
00086 //--- modes of operation
00087 
00088 // Best choice is if FINT=2**N where N+1 is maximal number
00089 // of charged daughters
00090 // see report on overweihted events
00091         if(phokey_.interf) maxWtInterference(2.0);
00092         else               maxWtInterference(1.0);
00093 
00094 /*
00095 ----------- FASTER VARIANT B  ------------------
00096 -- it is good for tests of fixed order and small XPHCUT
00097 -- but is less promising for more complex cases of interference
00098 -- sometimes fails because of that
00099 
00100         if(phokey_.interf) maxWtInterference(1.8);
00101         else               maxWtInterference(0.0);
00102 ------------END VARIANTS A B -----------------------
00103 */
00104 
00105 
00106 //------------------------------------------------------------------------------
00107 // Print PHOTOS header
00108 //------------------------------------------------------------------------------
00109         int                coutPrec = cout.precision(6);
00110         ios_base::fmtflags flags    = cout.setf(ios_base::floatfield);
00111         cout<<endl;
00112         cout<<"********************************************************************************"<<endl<<endl;
00113 
00114         cout<<"                            ========================="<<endl;
00115         cout<<"                              PHOTOS, Version:  "<<VER_MAJOR<<"."<<VER_MINOR<<endl;
00116         cout<<"                              Released at:  "<<DAT_DAY<<"/"<<DAT_MONTH<<"/"<<DAT_YEAR<<endl;
00117         cout<<"                            ========================="<<endl<<endl;
00118 
00119         cout<<"                     Photos QED corrections in Particle Decays"<<endl<<endl;
00120 
00121         cout<<"           Monte Carlo Program - by E. Barberio, B. van Eijk and Z. Was"<<endl;
00122         cout<<"           From version 2.09   - by P. Golonka and Z. Was"<<endl;
00123         cout<<"           From version 3.00   - by N. Davidson, T. Przedzinski and Z. Was"<<endl;
00124 
00125         cout<<"********************************************************************************"<<endl<<endl;
00126 
00127         cout<<"                  Internal (default) input parameters: "<<endl<<endl;
00128         cout<<"                    INTERF= "<<phokey_.interf<<" ISEC= " <<phokey_.isec <<" ITRE= "<<phokey_.itre
00129                              <<" IEXP= "  <<phokey_.iexp  <<" IFTOP= "<<phokey_.iftop<<" IFW= " <<phokey_.ifw <<endl;
00130         cout<<"                    ALPHA_QED= "<<phocop_.alpha<<" XPHCUT= "<<phocop_.xphcut<<endl<<endl;
00131 
00132         if(phokey_.interf) cout<<"                    Option with interference is active"<<endl;
00133         if(phokey_.isec)   cout<<"                    Option with double photons is active"<<endl;
00134         if(phokey_.itre)   cout<<"                    Option with triple/quatric photons is active"<<endl;
00135         if(phokey_.iexp)   cout<<"                    Option with exponentiation is active EPSEXP="<<phokey_.expeps<<endl;
00136         if(phokey_.iftop)  cout<<"                    Emision in t tbar production is active"<<endl;
00137         if(phokey_.ifw)    cout<<"                    Correction wt in decay of W is active"<<endl;
00138         if(meCorrectionWtForZ)    cout<<"                    ME in decay of Z is active"<<endl;
00139         if(meCorrectionWtForW)    cout<<"                    ME in decay of W is active"<<endl;
00140         cout<<endl<<"          WARNING:  /HEPEVT/ is not anymore used."<<endl<<endl;
00141 /*
00142         cout<<endl<<"            WARNING (1): /HEPEVT/ is not anymore the standard common block"<<endl<<endl;
00143 
00144         cout<<"            PHOTOS expects /HEPEVT/ to have REAL*8 variables. To change to"<<endl;
00145         cout<<"            REAL*4 modify its declaration in subr. PHOTOS_GET PHOTOS_SET:"<<endl;
00146         cout<<"                 REAL*8  d_h_phep,  d_h_vhep"<<endl;
00147         cout<<"            WARNING (2): check dims. of /hepevt/ /phoqed/ /ph_hepevt/."<<endl;
00148         cout<<"            HERE:                     d_h_nmxhep=10000 and  NMXHEP=10000"<<endl<<endl;
00149 */
00150         cout<<"********************************************************************************"<<endl;
00151         // Revert output stream flags and precision
00152         cout.precision(coutPrec);
00153         cout.flags    (flags);
00154 
00155         // Add reggeon, pomeron and its diffractive states to the list
00156         // of decays where bremsstrahlung is suppressed
00157         Photos::suppressBremForDecay(0,110);
00158         Photos::suppressBremForDecay(0,990);
00159         Photos::suppressBremForDecay(0,9902110);
00160         Photos::suppressBremForDecay(0,9902210);
00161         Photos::suppressBremForDecay(0,9900110);
00162         Photos::suppressBremForDecay(0,9900210);
00163         Photos::suppressBremForDecay(0,9900220);
00164         Photos::suppressBremForDecay(0,9900330);
00165         Photos::suppressBremForDecay(0,9900440);
00166 
00167 // Initialize Marsaglia and Zaman random number generator
00168         PhotosRandom::initialize();
00169 }
00170 void Photos::iniInfo()
00171 {
00172 // prints infomation like Photos::initialize; may be called after reinitializations.
00173 
00174 /*******************************************************************************
00175   Once  parameter setters are called after PHOINI one may want to know and write
00176   into output info including all reinitializations.
00177 *******************************************************************************/
00178 
00179 
00180 //------------------------------------------------------------------------------
00181 // Print PHOTOS header again
00182 //------------------------------------------------------------------------------
00183         int                coutPrec = cout.precision(6);
00184         ios_base::fmtflags flags    = cout.setf(ios_base::floatfield);
00185         cout<<endl;
00186         cout<<"********************************************************************************"<<endl<<endl;
00187         cout<<"                            ========================================="<<endl;
00188         cout<<"                            PHOTOS, information routine"<<endl;
00189         cout<<"                            Input parameters after reinitialization: "<<endl<<endl;
00190         cout<<"                            ========================================="<<endl<<endl;
00191         cout<<"********************************************************************************"<<endl<<endl;
00192         cout<<"                    INTERF= "<<phokey_.interf<<" ISEC= " <<phokey_.isec <<" ITRE= "<<phokey_.itre
00193                              <<" IEXP= "  <<phokey_.iexp  <<" IFTOP= "<<phokey_.iftop<<" IFW= " <<phokey_.ifw <<endl;
00194         cout<<"                    ALPHA_QED= "<<phocop_.alpha<<" XPHCUT= "<<phocop_.xphcut<<endl<<endl;
00195 
00196         if(phokey_.interf) cout<<"                    Option with interference is active"<<endl;
00197         if(phokey_.isec)   cout<<"                    Option with double photons is active"<<endl;
00198         if(phokey_.itre)   cout<<"                    Option with triple/quatric photons is active"<<endl;
00199         if(phokey_.iexp)   cout<<"                    Option with exponentiation is active EPSEXP="<<phokey_.expeps<<endl;
00200         if(phokey_.iftop)  cout<<"                    Emision in t tbar production is active"<<endl;
00201         if(phokey_.ifw)    cout<<"                    Correction wt in decay of W is active"<<endl;
00202         if(meCorrectionWtForZ)    cout<<"                    ME in decay of Z is active"<<endl;
00203         if(meCorrectionWtForW)    cout<<"                    ME in decay of W is active"<<endl;
00204         if(meCorrectionWtForScalar)    cout<<"                    ME in decay of Scalar is active"<<endl;
00205 
00206         cout<<endl<<"          WARNING:  /HEPEVT/ is not anymore used."<<endl<<endl;
00207         // Revert output stream flags and precision
00208         cout.precision(coutPrec);
00209         cout.flags    (flags);
00210 }
00211 
00212 void Photos::processParticle(PhotosParticle *p)
00213 {
00214         PhotosBranch b(p);
00215         if(!b.getSuppressionStatus()) b.process();
00216 }
00217 
00218 void Photos::processBranch(PhotosParticle *p)
00219 {
00220         vector<PhotosParticle *> particles = p->getDecayTree();
00221         vector<PhotosBranch *>   branches = PhotosBranch::createBranches(particles);
00222         for(int i=0;i<(int)branches.size();i++) branches.at(i)->process();
00223 }
00224 
00225 void Photos::suppressBremForDecay(int count, int motherID, ... )
00226 {
00227         va_list arg;
00228         va_start(arg, motherID);
00229         vector<int> *v = new vector<int>();
00230         v->push_back(motherID);
00231         for(int i = 0;i<count;i++)
00232         {
00233                 v->push_back(va_arg(arg,int));
00234         }
00235         va_end(arg);
00236         v->push_back(0);
00237         if(!supBremList) supBremList = new vector< vector<int>* >();
00238         supBremList->push_back(v);
00239 }
00240 
00241 void Photos::suppressBremForBranch(int count, int motherID, ... )
00242 {
00243         va_list arg;
00244         va_start(arg, motherID);
00245         vector<int> *v = new vector<int>();
00246         v->push_back(motherID);
00247         for(int i = 0;i<count;i++)
00248         {
00249                 v->push_back(va_arg(arg,int));
00250         }
00251         va_end(arg);
00252         v->push_back(1);
00253         if(!supBremList) supBremList = new vector< vector<int>* >();
00254         supBremList->push_back(v);
00255 }
00256 
00257 void Photos::forceBremForDecay(int count, int motherID, ... )
00258 {
00259         va_list arg;
00260         va_start(arg, motherID);
00261         vector<int> *v = new vector<int>();
00262         v->push_back(motherID);
00263         for(int i = 0;i<count;i++)
00264         {
00265                 v->push_back(va_arg(arg,int));
00266         }
00267         va_end(arg);
00268         v->push_back(0);
00269         if(!forceBremList) forceBremList = new vector< vector<int>* >();
00270         forceBremList->push_back(v);
00271 }
00272 
00273 void Photos::forceBremForBranch(int count, int motherID, ... )
00274 {
00275         va_list arg;
00276         va_start(arg, motherID);
00277         vector<int> *v = new vector<int>();
00278         v->push_back(motherID);
00279         for(int i = 0;i<count;i++)
00280         {
00281                 v->push_back(va_arg(arg,int));
00282         }
00283         va_end(arg);
00284         v->push_back(1);
00285         if(!forceBremList) forceBremList = new vector< vector<int>* >();
00286         forceBremList->push_back(v);
00287 }
00288 
00289 void Photos::createHistoryEntries(bool flag, int status)
00290 {
00291   if(status<3)
00292   {
00293     Log::Warning()<<"Photos::createHistoryEntries: status must be >=3"<<endl;
00294     return;
00295   }
00296 
00297   isCreateHistoryEntries = flag;
00298   historyEntriesStatus   = status;
00299   ignoreParticlesOfStatus(status);
00300 }
00301 
00302 void Photos::ignoreParticlesOfStatus(int status)
00303 {
00304   if(status<3)
00305   {
00306     Log::Warning()<<"Photos::ignoreParticlesOfStatus: status must be >=3"<<endl;
00307     return;
00308   }
00309   
00310   if(!ignoreStatusCodeList) ignoreStatusCodeList = new vector<int>();
00311 
00312   // Do not add duplicate entries to the list
00313   for(unsigned int i=0;i<ignoreStatusCodeList->size();i++)
00314     if( status==ignoreStatusCodeList->at(i) ) return;
00315   
00316   ignoreStatusCodeList->push_back(status);
00317 }
00318 
00319 void Photos::deIgnoreParticlesOfStatus(int status)
00320 {
00321   if(!ignoreStatusCodeList) return;
00322 
00323   for(unsigned int i=0;i<ignoreStatusCodeList->size();i++)
00324   {
00325     if( status==ignoreStatusCodeList->at(i) )
00326     {
00327       ignoreStatusCodeList->erase(ignoreStatusCodeList->begin()+i);
00328       return;
00329     }
00330   }
00331 }
00332 
00333 bool Photos::isStatusCodeIgnored(int status)
00334 {
00335   if(!ignoreStatusCodeList) return false;
00336 
00337   for(unsigned int i=0;i<ignoreStatusCodeList->size();i++)
00338     if( status==ignoreStatusCodeList->at(i) ) return true;
00339 
00340   return false;
00341 }
00342 
00343 void Photos::setRandomGenerator( double (*gen)() )
00344 {
00345   if(gen==NULL) randomDouble = PhotosRandom::randomReal;
00346   else          randomDouble = gen;
00347 }
00348 
00349 void Photos::setExponentiation(bool expo)
00350 {
00351         phokey_.iexp = (int) expo;
00352         if(expo)
00353         {
00354                 setDoubleBrem(false);
00355                 setQuatroBrem(false);
00356                 setInfraredCutOff(0.0000001);
00357                 initializeKinematicCorrections(5);
00358                 phokey_.expeps=0.0001;
00359         }
00360 }
00361 
00362 void Photos::setMeCorrectionWtForW(bool corr)
00363 {
00364         meCorrectionWtForW=corr;
00365 }
00366 
00367 void Photos::setMeCorrectionWtForZ(bool corr)
00368 {
00369         meCorrectionWtForZ=corr;
00370 }
00371 void Photos::setMeCorrectionWtForScalar(bool corr)
00372 {
00373         meCorrectionWtForScalar=corr;
00374 }
00375 
00376 void Photos::setStopAtCriticalError(bool stop)
00377 {
00378         phosta_.ifstop=(int)stop;
00379         if(!stop)
00380         {
00381                 Log::Info()<<"PHOTOS production mode. Elementary test of data flow from event record disabled. "<<endl
00382                            <<"Prior checks of the complete configuration "<<endl
00383                            <<"(for the particular set of input parameters) must have been done! "<<endl;
00384         }
00385 }
00386 
00387 
00388 void Photos::forceMassFromEventRecord(int pdgid)
00389 {
00390   if(!forceMassList) forceMassList = new vector<pair<int,double>* >();
00391   forceMassList->push_back( new pair<int,double>(pdgid, -1.0) );
00392 }
00393 
00394 void Photos::forceMass(int pdgid, double mass)
00395 {
00396   if(mass<0.0)
00397   {
00398     Log::Warning()<<"Photos::forceMass: Mass must be > 0.0"<<endl;
00399     return;
00400   }
00401   
00402   if(!forceMassList) forceMassList = new vector<pair<int,double>* >();
00403   forceMassList->push_back( new pair<int,double>(pdgid, mass) );
00404 }
00405 
00406 } // namespace Photospp
Generated on Sun Oct 20 20:23:56 2013 for C++InterfacetoPHOTOS by  doxygen 1.6.3