CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/SimTransport/HectorProducer/src/Hector.cc

Go to the documentation of this file.
00001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00002 #include "FWCore/ParameterSet/interface/FileInPath.h"
00003 #include "FWCore/ServiceRegistry/interface/Service.h"
00004 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
00005 #include "IOMC/RandomEngine/src/TRandomAdaptor.h"
00006 
00007 #include "SimTransport/HectorProducer/interface/Hector.h"
00008 
00009 #include "SimGeneral/HepPDTRecord/interface/ParticleDataTable.h"
00010 #include "CLHEP/Units/GlobalSystemOfUnits.h"
00011 #include "CLHEP/Units/GlobalPhysicalConstants.h"
00012 #include "HepMC/SimpleVector.h"
00013 
00014 #include "H_Parameters.h"
00015 
00016 #include <math.h>
00017 
00018 Hector::Hector(const edm::ParameterSet & param, bool verbosity, bool FP420Transport,bool ZDCTransport) : 
00019   m_verbosity(verbosity), 
00020   m_FP420Transport(FP420Transport),
00021   m_ZDCTransport(ZDCTransport),
00022   rootEngine_(0)
00023 {
00024   
00025   // Create LHC beam line
00026   edm::ParameterSet hector_par = param.getParameter<edm::ParameterSet>("Hector");
00027   
00028   // User definitons
00029   lengthfp420    = hector_par.getParameter<double>("BeamLineLengthFP420" );
00030   m_rpp420_f     = (float) hector_par.getParameter<double>("RP420f");
00031   m_rpp420_b     = (float) hector_par.getParameter<double>("RP420b");
00032   lengthzdc      = hector_par.getParameter<double>("BeamLineLengthZDC" );
00033   lengthd1       = hector_par.getParameter<double>("BeamLineLengthD1" );
00034   beam1filename  = hector_par.getParameter<string>("Beam1");
00035   beam2filename  = hector_par.getParameter<string>("Beam2");  
00036   m_rppzdc       = (float) lengthzdc ;
00037   m_rppd1        = (float) lengthd1 ;
00038   m_smearAng     = hector_par.getParameter<bool>("smearAng");
00039   m_sigmaSTX     = hector_par.getParameter<double>("sigmaSTX" );
00040   m_sigmaSTY     = hector_par.getParameter<double>("sigmaSTY" );
00041   m_smearE       = hector_par.getParameter<bool>("smearEnergy");
00042   m_sig_e        = hector_par.getParameter<double>("sigmaEnergy");
00043   etacut         = hector_par.getParameter<double>("EtaCutForHector" );
00044   
00045   edm::Service<edm::RandomNumberGenerator> rng;
00046   if ( ! rng.isAvailable() ) {
00047     throw cms::Exception("Configuration")
00048       << "LHCTransport (Hector) requires the RandomNumberGeneratorService\n"
00049       "which is not present in the configuration file.  You must add the service\n"
00050       "in the configuration file or remove the modules that require it.";
00051   }
00052   if ( (rng->getEngine()).name() == "TRandom3" ) {
00053     rootEngine_ = ( (edm::TRandomAdaptor*) &(rng->getEngine()) )->getRootEngine();
00054     if ( m_verbosity ) LogDebug("HectorSetup") << "LHCTransport seed = " << rootEngine_->GetSeed();
00055   }
00056   else {
00057     edm::LogError("WrongRandomNumberGenerator") << "The TRandom3 engine must be used, Random Number Generator Service not correctly initialized!"; 
00058     rootEngine_ = new TRandom3();
00059   }
00060 
00061   theCorrespondenceMap.clear();
00062 
00063   if(m_verbosity) {
00064     edm::LogInfo("HectorSetup") << "===================================================================\n"  
00065                                 << " * * * * * * * * * * * * * * * * * * * * * * * * * * * *           \n"  
00066                                 << " *                                                         *       \n"  
00067                                 << " *                   --<--<--  A fast simulator --<--<--     *     \n"  
00068                                 << " *                 | --<--<--     of particle   --<--<--     *     \n"  
00069                                 << " *  ----HECTOR----<                                          *     \n"  
00070                                 << " *                 | -->-->-- transport through-->-->--      *     \n"   
00071                                 << " *                   -->-->-- generic beamlines -->-->--     *     \n"  
00072                                 << " *                                                           *     \n"   
00073                                 << " * JINST 2:P09005 (2007)                                     *     \n"  
00074                                 << " *      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *     \n"  
00075                                 << " *       https://www.fynu.ucl.ac.be/hector.html               *     \n"  
00076                                 << " *                                                           *     \n"  
00077                                 << " * Center for Cosmology, Particle Physics and Phenomenology  *     \n"  
00078                                 << " *              Universite catholique de Louvain             *     \n"  
00079                                 << " *                 Louvain-la-Neuve, Belgium                 *     \n"  
00080                                 << " *                                                         *       \n"  
00081                                 << " * * * * * * * * * * * * * * * * * * * * * * * * * * * *           \n"   
00082                                 << " Hector configuration: \n" 
00083                                 << " m_FP420Transport = " << m_FP420Transport << "\n" 
00084                                 << " m_ZDCTransport   = " << m_ZDCTransport << "\n" 
00085                                 << " lengthfp420      = " << lengthfp420 << "\n" 
00086                                 << " m_rpp420_f       = " << m_rpp420_f << "\n" 
00087                                 << " m_rpp420_b       = " << m_rpp420_b << "\n" 
00088                                 << " lengthzdc        = " << lengthzdc << "\n" 
00089                                 << " lengthd1         = " << lengthd1 << "\n" 
00090                                 << "===================================================================\n";
00091   }  
00092   edm::FileInPath b1(beam1filename.c_str());
00093   edm::FileInPath b2(beam2filename.c_str());
00094   
00095   // construct beam line for FP420:                                                                                           .
00096   if(m_FP420Transport && lengthfp420>0. ) {
00097     m_beamlineFP4201 = new H_BeamLine(  1, lengthfp420 + 0.1 ); // (direction, length)
00098     m_beamlineFP4202 = new H_BeamLine( -1, lengthfp420 + 0.1 ); //
00099     m_beamlineFP4201->fill( b1.fullPath(),  1, "IP5" );
00100     m_beamlineFP4202->fill( b2.fullPath(), -1, "IP5" );
00101     m_beamlineFP4201->offsetElements( 120, -0.097 );
00102     m_beamlineFP4202->offsetElements( 120, +0.097 );
00103     m_beamlineFP4201->calcMatrix();
00104     m_beamlineFP4202->calcMatrix();
00105   }  
00106   else{
00107     if ( m_verbosity ) LogDebug("HectorSetup") << "Hector: WARNING: lengthfp420=  " << lengthfp420;
00108   }
00109   
00110   
00111   if (m_ZDCTransport && lengthzdc>0. && lengthd1>0.) {
00112     // construct beam line for ZDC:                                                                                           .
00113     m_beamlineZDC1 = new H_BeamLine(  1, lengthzdc + 0.1 ); // (direction, length)
00114     m_beamlineZDC2 = new H_BeamLine( -1, lengthzdc + 0.1 ); //
00115     m_beamlineZDC1->fill( b1.fullPath(),  1, "IP5" );
00116     m_beamlineZDC2->fill( b2.fullPath(), -1, "IP5" );
00117     m_beamlineZDC1->offsetElements( 120, -0.097 );
00118     m_beamlineZDC2->offsetElements( 120, +0.097 );
00119     m_beamlineZDC1->calcMatrix();
00120     m_beamlineZDC2->calcMatrix();
00121     
00122     
00123     // construct beam line for D1:                                                                                           .
00124     m_beamlineD11 = new H_BeamLine(  1, lengthd1 + 0.1 ); // (direction, length)
00125     m_beamlineD12 = new H_BeamLine( -1, lengthd1 + 0.1 ); //
00126     m_beamlineD11->fill( b1.fullPath(),  1, "IP5" );
00127     m_beamlineD12->fill( b2.fullPath(), -1, "IP5" );
00128     m_beamlineD11->offsetElements( 120, -0.097 );
00129     m_beamlineD12->offsetElements( 120, +0.097 );
00130     m_beamlineD11->calcMatrix();
00131     m_beamlineD12->calcMatrix();
00132   }  
00133   else{
00134     if ( m_verbosity ) LogDebug("HectorSetup") << "Hector: WARNING: lengthzdc=  " << lengthzdc << "lengthd1=  " << lengthd1;
00135   }
00136   
00137 }
00138 
00139 Hector::~Hector(){
00140   
00141   for (std::map<unsigned int,H_BeamParticle*>::iterator it = m_beamPart.begin(); it != m_beamPart.end(); ++it ) {
00142     delete (*it).second;
00143   }
00144 
00145   delete m_beamlineFP4201;
00146   delete m_beamlineFP4202;
00147   delete m_beamlineZDC1;
00148   delete m_beamlineZDC2;
00149   delete m_beamlineD11;
00150   delete m_beamlineD12;
00151   
00152 }
00153 
00154 void Hector::clearApertureFlags(){
00155   m_isStoppedfp420.clear();
00156   m_isStoppedzdc.clear();
00157   m_isStoppedd1.clear();
00158 }
00159 
00160 void Hector::clear(){
00161   for ( std::map<unsigned int,H_BeamParticle*>::iterator it = m_beamPart.begin(); it != m_beamPart.end(); ++it ) {
00162     delete (*it).second;
00163   };
00164   m_beamPart.clear();
00165   m_direct.clear();
00166   m_eta.clear();
00167   m_pdg.clear();
00168   m_pz.clear();
00169   m_isCharged.clear();  
00170 }
00171 
00172 /*
00173   bool Hector::isCharged(const HepMC::GenParticle * p){
00174   const ParticleData * part = pdt->particle( p->pdg_id() );
00175   if (part){
00176   return part->charge()!=0;
00177   }else{
00178   // the new/improved particle table doesn't know anti-particles
00179   return  pdt->particle( -p->pdg_id() )!=0;
00180   }
00181   }
00182 */
00183 void Hector::add( const HepMC::GenEvent * evt ,const edm::EventSetup & iSetup) {
00184   
00185   H_BeamParticle * h_p;
00186   unsigned int line;
00187   
00188   for (HepMC::GenEvent::particle_const_iterator eventParticle =evt->particles_begin();
00189        eventParticle != evt->particles_end();
00190        ++eventParticle ) {
00191     if ( (*eventParticle)->status() == 1 ) {
00192       if ( abs( (*eventParticle)->momentum().eta())>etacut){
00193         line = (*eventParticle)->barcode();
00194         if ( m_beamPart.find(line) == m_beamPart.end() ) {
00195           double charge=1.;
00196           m_isCharged[line] = false;// neutrals
00197           HepMC::GenParticle * g = (*eventParticle);    
00198           iSetup.getData( pdt );
00199           const ParticleData * part = pdt->particle( g->pdg_id() );
00200           if (part){
00201             charge = part->charge();
00202           }
00203           if(charge !=0) m_isCharged[line] = true;//charged
00204           double mass = (*eventParticle)->generatedMass();
00205           
00206           h_p = new H_BeamParticle(mass,charge);
00207           
00208           double px,py,pz;
00209           px = (*eventParticle)->momentum().px();         
00210           py = (*eventParticle)->momentum().py();         
00211           pz = (*eventParticle)->momentum().pz();         
00212           
00213           h_p->set4Momentum( px, py, pz, (*eventParticle)->momentum().e() );
00214           
00215           // from mm to um        
00216           double XforPosition = (*eventParticle)->production_vertex()->position().x()/micrometer;//um
00217           double YforPosition = (*eventParticle)->production_vertex()->position().y()/micrometer;//um
00218           double ZforPosition = (*eventParticle)->production_vertex()->position().z()/meter;//m
00219           // crossing angle (beam tilt) is not known a priory; keep now 0.0 but, in principle, can be entered as parameters
00220           double TXforPosition=0.0, TYforPosition=0.0;//urad
00221           
00222           // Clears H_BeamParticle::positions and sets the initial one
00223           h_p->setPosition(XforPosition, YforPosition, TXforPosition, TYforPosition, ZforPosition );
00224           
00225           m_beamPart[line] = h_p;
00226           m_direct[line] = 0;
00227           m_direct[line] = ( pz > 0 ) ? 1 : -1;
00228           
00229           m_eta[line] = (*eventParticle)->momentum().eta();
00230           m_pdg[line] = (*eventParticle)->pdg_id();
00231           m_pz[line]  = (*eventParticle)->momentum().pz();
00232           
00233           if(m_verbosity) { 
00234             LogDebug("HectorEventProcessing") << "Hector:add: barcode = " << line 
00235                                               << " status = " << g->status() 
00236                                               << " PDG Id = " << g->pdg_id() 
00237                                               << " mass = " << mass 
00238                                               << " pz = " << pz 
00239                                               << " charge = " << charge 
00240                                               << " m_isCharged[line] = " << m_isCharged[line];
00241           } 
00242         }// if find line
00243       }// if eta > 8.2
00244     }// if status
00245   }// for loop
00246   
00247 }
00248 
00249 void Hector::filterFP420(){
00250   unsigned int line;
00251   H_BeamParticle * part;
00252   std::map< unsigned int, H_BeamParticle* >::iterator it;
00253   
00254   bool is_stop;
00255   int direction;
00256   
00257   float x1_420;
00258   float y1_420;
00259   
00260   if ( m_beamPart.size() && lengthfp420>0. ) {
00261     
00262     for (it = m_beamPart.begin(); it != m_beamPart.end(); ++it ) {
00263       line = (*it).first;
00264       part = (*it).second;
00265       
00266       if(m_verbosity) {
00267         LogDebug("HectorEventProcessing") << "Hector:filterFP420: barcode = " << line;
00268       }
00269       if ( (*m_isCharged.find( line )).second ) {
00270         direction = (*m_direct.find( line )).second;
00271         if (m_smearAng) {
00272           // the beam transverse direction is centered on (TXforPosition, TYforPosition) at IP
00273           if ( m_sigmaSTX>0. && m_sigmaSTY>0.) {
00274             part->smearAng(m_sigmaSTX,m_sigmaSTY,rootEngine_);
00275           }
00276           else {
00277             // for smearAng() in urad, default are (STX=30.23, STY=30.23)
00278             part->smearAng(STX,STY,rootEngine_); 
00279           }
00280         }
00281         if (m_smearE) {
00282           if ( m_sig_e ) {
00283             part->smearE(m_sig_e,rootEngine_);
00284           }
00285           else {
00286             part->smearE(SBE,rootEngine_);  // in GeV, default is SBE=0.79
00287           }
00288         }
00289         if ( direction == 1 && m_beamlineFP4201 != 0 ) {
00290           part->computePath( m_beamlineFP4201 );
00291           is_stop = part->stopped( m_beamlineFP4201 );
00292           if(m_verbosity) LogDebug("HectorEventProcessing") << "Hector:filterFP420: barcode = " << line << " positive is_stop=  "<< is_stop;
00293         }
00294         else if ( direction == -1 && m_beamlineFP4202 != 0 ){
00295           part->computePath( m_beamlineFP4202 );
00296           is_stop = part->stopped( m_beamlineFP4202 );
00297           if(m_verbosity) LogDebug("HectorEventProcessing") << "Hector:filterFP420: barcode = " << line << " negative is_stop=  "<< is_stop;
00298         }
00299         else {
00300           is_stop = true;
00301           if(m_verbosity) LogDebug("HectorEventProcessing") << "Hector:filterFP420: barcode = " << line << " 0        is_stop=  "<< is_stop;
00302         }
00303         
00304         //propagating
00305         m_isStoppedfp420[line] = is_stop;
00306         if(m_verbosity) LogDebug("HectorEventProcessing") << "Hector:filterFP420: barcode = " << line << " isStopped=" << (*m_isStoppedfp420.find(line)).second;
00307         
00308         if (!is_stop) {
00309           if ( direction == 1 ) part->propagate( m_rpp420_f );
00310           if ( direction == -1 ) part->propagate( m_rpp420_b );
00311           x1_420 = part->getX();
00312           y1_420 = part->getY();
00313           if(m_verbosity) LogDebug("HectorEventProcessing") << "Hector:filterFP420: barcode = " << line << " x=  "<< x1_420 <<" y= " << y1_420;
00314           
00315           m_xAtTrPoint[line]  = x1_420;
00316           m_yAtTrPoint[line]  = y1_420;
00317           m_TxAtTrPoint[line] = part->getTX();
00318           m_TyAtTrPoint[line] = part->getTY();
00319           m_eAtTrPoint[line]  = part->getE();
00320           
00321         }
00322       }// if isCharged
00323       else {
00324         m_isStoppedfp420[line] = true;// imply that neutral particles stopped to reach 420m
00325         if(m_verbosity) LogDebug("HectorEventProcessing") << "Hector:filterFP420: barcode = " << line << " isStopped=" << (*m_isStoppedfp420.find(line)).second;
00326       }
00327       
00328     } // for (it = m_beamPart.begin(); it != m_beamPart.end(); it++ ) 
00329   } // if ( m_beamPart.size() )
00330   
00331 }
00332 
00333 void Hector::filterZDC(){
00334   unsigned int line;
00335   H_BeamParticle * part;
00336   std::map< unsigned int, H_BeamParticle* >::iterator it;
00337   
00338   bool is_stop_zdc = false;
00339   int direction;
00340   
00341   if ( m_beamPart.size() && lengthzdc>0. ) {
00342     
00343     for (it = m_beamPart.begin(); it != m_beamPart.end(); ++it ) {
00344       line = (*it).first;
00345       part = (*it).second;
00346       if(m_verbosity) {
00347         LogDebug("HectorEventProcessing") << "Hector:filterZDC: barcode = " << line << " charge  = " << (*m_isCharged.find(line)).second;
00348         if (m_FP420Transport) LogDebug("HectorEventProcessing") << " isStoppedFP420 =" << (*m_isStoppedfp420.find(line)).second;
00349       }
00350       //      if ( ((*m_isStoppedfp420.find(line)).second) && ((*m_isCharged.find(line)).second) ) {
00351       if ( ((*m_isCharged.find(line)).second) ) {
00352         
00353         if(m_verbosity) LogDebug("HectorEventProcessing") << "Hector:filterZDC: barcode = " << line << " propagated ";
00354         
00355         direction = (*m_direct.find( line )).second;
00356         if(m_verbosity) LogDebug("HectorEventProcessing") << "Hector:filterZDC: barcode = " << line << " direction = " << direction;
00357         if (m_smearAng) {
00358           if ( m_sigmaSTX>0. && m_sigmaSTY>0.) {
00359             // the beam transverse direction is centered on (TXforPosition, TYforPosition) at IP
00360             part->smearAng(m_sigmaSTX,m_sigmaSTY,rootEngine_);
00361           } else {
00362             // for smearAng() in urad, default are (STX=30.23, STY=30.23)
00363             part->smearAng(STX,STY,rootEngine_); 
00364           }
00365         }
00366         if (m_smearE) {
00367           if ( m_sig_e ) {
00368             part->smearE(m_sig_e,rootEngine_);
00369           } else {
00370             part->smearE(SBE,rootEngine_);  // in GeV, default is SBE=0.79
00371           }
00372         }
00373         if ( direction == 1 && m_beamlineZDC1 != 0 ){
00374           part->computePath( m_beamlineZDC1 );
00375           is_stop_zdc = part->stopped( m_beamlineZDC1 );
00376           m_isStoppedzdc[line] = is_stop_zdc;
00377           if(m_verbosity) LogDebug("HectorEventProcessing") << "Hector:filterZDC: barcode " << line << " positive is_stop_zdc=  "<< is_stop_zdc;
00378         } else if ( direction == -1 && m_beamlineZDC2 != 0 ){
00379           part->computePath( m_beamlineZDC2 );
00380           is_stop_zdc = part->stopped( m_beamlineZDC2 );
00381           m_isStoppedzdc[line] = is_stop_zdc;
00382           if(m_verbosity) LogDebug("HectorEventProcessing") << "Hector:filterZDC: barcode " << line << " negative is_stop_zdc=  "<< is_stop_zdc;
00383         } else {
00384           m_isStoppedzdc[line] = true;
00385           if(m_verbosity) LogDebug("HectorEventProcessing") << "Hector:filterZDC: barcode " << line << " 0         is_stop_zdc=  "<< is_stop_zdc;
00386         }
00387       }
00388       // if stopfp420 charged particles
00389       /*
00390         else if ( ((*m_isCharged.find(line)).second) ){
00391         m_isStoppedzdc[line] = false;// not stopped in propagating to FP420 and therefore in  propagation to ZDC too.
00392         if(m_verbosity) LogDebug("HectorEventProcessing") << "Hector:filterZDC: barcode = " << line << " isStopped=" << (*m_isStoppedzdc.find(line)).second;
00393         } */
00394       else {
00395         m_isStoppedzdc[line] = true;// neutrals particles considered as stopped in propagating to ZDC
00396         if(m_verbosity) LogDebug("HectorEventProcessing") << "Hector:filterZDC: barcode = " << line << " isStopped=" << (*m_isStoppedzdc.find(line)).second;
00397       }
00398       
00399     } // for (it = m_beamPart.begin(); it != m_beamPart.end(); it++ ) 
00400   } // if ( m_beamPart.size() )
00401   
00402 }
00403 
00404 void Hector::filterD1(){
00405   unsigned int line;
00406   H_BeamParticle * part;
00407   std::map< unsigned int, H_BeamParticle* >::iterator it;
00408   
00409   bool is_stop_d1;
00410   int direction;
00411   
00412   float x1_d1;
00413   float y1_d1;
00414   
00415   if ( m_beamPart.size() && lengthd1>0.) {
00416     
00417     for (it = m_beamPart.begin(); it != m_beamPart.end(); ++it ) {
00418       line = (*it).first;
00419       part = (*it).second;
00420       if(m_verbosity) LogDebug("HectorEventProcessing") << "Hector:filterD1: barcode = " << line << " isStoppedZDC =" << (*m_isStoppedzdc.find(line)).second;
00421       if ( ((*m_isStoppedzdc.find(line)).second) || !((*m_isCharged.find( line )).second) ) {
00422         
00423         if(m_verbosity) LogDebug("HectorEventProcessing") << "Hector:filterD1: barcode = " << line << " propagated ";
00424         
00425         direction = (*m_direct.find( line )).second;
00426         if(m_verbosity) LogDebug("HectorEventProcessing") << "Hector:filterD1:direction=" << direction;
00427         if (m_smearAng) {
00428           if ( m_sigmaSTX>0. && m_sigmaSTY>0.) {
00429             // the beam transverse direction is centered on (TXforPosition, TYforPosition) at IP
00430             part->smearAng(m_sigmaSTX,m_sigmaSTY,rootEngine_);
00431           } else {
00432             // for smearAng() in urad, default are (STX=30.23, STY=30.23)
00433             part->smearAng(STX,STY,rootEngine_); 
00434           }
00435         }
00436         if (m_smearE) {
00437           if ( m_sig_e ) {
00438             part->smearE(m_sig_e,rootEngine_);
00439           } else {
00440             part->smearE(SBE,rootEngine_);  // in GeV, default is SBE=0.79
00441           }
00442         }
00443         if ( direction == 1 && m_beamlineD11 != 0 ) {
00444           part->computePath( m_beamlineD11 );
00445           is_stop_d1 = part->stopped( m_beamlineD11 );
00446           m_isStoppedd1[line] = is_stop_d1;
00447           if(m_verbosity) LogDebug("HectorEventProcessing") << "Hector:filterD1 barcode " << line << " positive is_stop_d1 =  "<< is_stop_d1;
00448         } else  if ( direction == -1 && m_beamlineD12 != 0 ){
00449           part->computePath( m_beamlineD12 );
00450           is_stop_d1 = part->stopped( m_beamlineD12 );
00451           m_isStoppedd1[line] = is_stop_d1;
00452           if(m_verbosity) LogDebug("HectorEventProcessing") << "Hector:filterD1 barcode " << line << " negative is_stop_d1 =  "<< is_stop_d1;
00453         } else {
00454           is_stop_d1 = true;
00455           m_isStoppedd1[line] = is_stop_d1;
00456           if(m_verbosity) LogDebug("HectorEventProcessing") << "Hector:filterD1 barcode " << line << " 0        is_stop_d1 =  "<< is_stop_d1;
00457         }
00458         //propagating
00459         if (!is_stop_d1 ) {
00460           part->propagate( lengthd1 );
00461           x1_d1 = part->getX();
00462           y1_d1 = part->getY();
00463           m_xAtTrPoint[line]  = x1_d1;
00464           m_yAtTrPoint[line]  = y1_d1;
00465           m_TxAtTrPoint[line] = part->getTX();
00466           m_TyAtTrPoint[line] = part->getTY();
00467           m_eAtTrPoint[line]  = part->getE();
00468         }
00469       }// if stopzdc
00470       else {
00471         m_isStoppedd1[line] = false;// not stopped in propagating to ZDC and therefore in  propagation to D1 too.
00472         if(m_verbosity) LogDebug("HectorEventProcessing") << "Hector:filterD1: barcode = " << line << " isStopped=" << (*m_isStoppedd1.find(line)).second;
00473       }
00474       
00475     } // for (it = m_beamPart.begin(); it != m_beamPart.end(); it++ ) 
00476   } // if ( m_beamPart.size() )
00477   
00478 }
00479 
00480 int  Hector::getDirect( unsigned int part_n ) const {
00481   std::map<unsigned int, int>::const_iterator it = m_direct.find( part_n );
00482   if ( it != m_direct.end() ){
00483     return (*it).second;
00484   }
00485   return 0;
00486 }
00487 
00488 void Hector::print() const {
00489   for (std::map<unsigned int,H_BeamParticle*>::const_iterator it = m_beamPart.begin(); it != m_beamPart.end(); ++it ) {
00490     (*it).second->printProperties();
00491   };
00492 }
00493 
00494 
00495 HepMC::GenEvent * Hector::addPartToHepMC( HepMC::GenEvent * evt ){
00496 
00497   theCorrespondenceMap.clear();
00498   
00499   unsigned int line;
00500 
00501   HepMC::GenParticle * gpart;
00502   long double tx,ty,theta,fi,energy,time = 0;
00503   std::map< unsigned int, H_BeamParticle* >::iterator it;
00504   
00505   
00506   for (it = m_beamPart.begin(); it != m_beamPart.end(); ++it ) {
00507     line = (*it).first;
00508     if(!m_FP420Transport) m_isStoppedfp420[line] = true;
00509     if(!m_ZDCTransport) {m_isStoppedzdc[line] = false;m_isStoppedd1[line] = true;}
00510     if(m_verbosity) {
00511       LogDebug("HectorEventProcessing") << "Hector:addPartToHepMC: barcode = " << line << "\n"
00512                                         << "Hector:addPartToHepMC: isStoppedfp420=" << (*m_isStoppedfp420.find(line)).second << "\n"
00513                                         << "Hector:addPartToHepMC: isStoppedzdc=" << (*m_isStoppedzdc.find(line)).second << "\n"
00514                                         << "Hector:addPartToHepMC: isStoppedd1=" << (*m_isStoppedd1.find(line)).second;
00515     }
00516     if (!((*m_isStoppedfp420.find(line)).second) || (!((*m_isStoppedd1.find(line)).second) && ((*m_isStoppedzdc.find(line)).second))){
00517 
00518       gpart = evt->barcode_to_particle( line );
00519       if ( gpart ) {
00520         tx     = (*m_TxAtTrPoint.find(line)).second / 1000000.;
00521         ty     = (*m_TyAtTrPoint.find(line)).second / 1000000.;
00522         theta  = sqrt((tx*tx) + (ty*ty));
00523         double ddd = 0.;
00524         if ( !((*m_isStoppedfp420.find(line)).second)) {
00525           if( (*m_direct.find( line )).second >0 ) {
00526             ddd = m_rpp420_f;
00527           }
00528           else if((*m_direct.find( line )).second <0 ) {
00529             ddd = m_rpp420_b;
00530             theta= pi-theta;
00531           }
00532         }
00533         else {
00534           ddd = lengthd1;
00535           if((*m_direct.find( line )).second <0 ) theta= pi-theta;
00536         }
00537         
00538         fi     = std::atan2(tx,ty); // tx, ty never == 0?
00539         energy = (*m_eAtTrPoint.find(line)).second;
00540         
00541         time = ( ddd*meter - gpart->production_vertex()->position().z()*mm ); // mm
00542 
00543         if(ddd != 0.) {
00544           if(m_verbosity) {
00545             LogDebug("HectorEventProcessing") <<"Hector:: x= "<< (*(m_xAtTrPoint.find(line))).second*0.001<< "\n"
00546                                               <<"Hector:: y= "<< (*(m_yAtTrPoint.find(line))).second*0.001<< "\n"
00547                                               <<"Hector:: z= "<< ddd * (*(m_direct.find( line ))).second*1000. << "\n"
00548                                               <<"Hector:: t= "<< time;
00549           }
00550           
00551           HepMC::GenVertex * vert = new HepMC::GenVertex( HepMC::FourVector( (*(m_xAtTrPoint.find(line))).second*0.001,
00552                                                                              (*(m_yAtTrPoint.find(line))).second*0.001,
00553                                                                              ddd * (*(m_direct.find( line ))).second*1000.,
00554                                                                              time + .001*time ) );
00555           
00556           gpart->set_status( 2 );
00557           vert->add_particle_in( gpart );
00558           vert->add_particle_out( new HepMC::GenParticle( HepMC::FourVector(energy*std::sin(theta)*std::sin(fi),
00559                                                                             energy*std::sin(theta)*std::cos(fi),
00560                                                                             energy*std::cos(theta),
00561                                                                             energy ),
00562                                                           gpart->pdg_id(), 1, gpart->flow() ) );
00563           evt->add_vertex( vert );
00564 
00565           int ingoing = (*vert->particles_in_const_begin())->barcode();
00566           int outgoing = (*vert->particles_out_const_begin())->barcode();
00567           LHCTransportLink theLink(ingoing,outgoing);
00568           if (m_verbosity) LogDebug("HectorEventProcessing") << "Hector:addPartToHepMC: LHCTransportLink " << theLink;
00569           theCorrespondenceMap.push_back(theLink);
00570 
00571           if(m_verbosity) LogDebug("HectorEventProcessing") << "Hector::TRANSPORTED pz= " << gpart->momentum().pz()  
00572                                                                  << " eta= "<< gpart->momentum().eta()  
00573                                                                  << " status= "<< gpart->status();
00574           
00575           
00576         }// ddd
00577       }// if gpart
00578     }// if !isStopped
00579     
00580     else {
00581       gpart = evt->barcode_to_particle( line );
00582       if ( gpart ) {
00583         //        HepMC::GenVertex * vert= new HepMC::GenVertex();
00584         gpart->set_status( 2 );
00585         //        vert->add_particle_in( gpart );
00586         //        vert->add_particle_out( gpart );
00587         //        evt->add_vertex( vert );
00588         if(m_verbosity) LogDebug("HectorEventProcessing") << "Hector::NON-transp. pz= " << gpart->momentum().pz()  
00589                                                                << " eta= "<< gpart->momentum().eta()  
00590                                                                << " status= "<< gpart->status();
00591       }
00592     }
00593 
00594   }//for 
00595   
00596   return evt;
00597 }