CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/Fireworks/SimData/plugins/FWSimTrackProxyBuilder.cc

Go to the documentation of this file.
00001 /*
00002  *  FWSimTrackProxyBuilder.cc
00003  *  FWorks
00004  *
00005  *  Created by Ianna Osborne on 9/9/10.
00006  *
00007  */
00008 
00009 #include "Fireworks/Core/interface/FWProxyBuilderBase.h"
00010 #include "Fireworks/Core/interface/Context.h"
00011 #include "Fireworks/Core/interface/FWEventItem.h"
00012 #include "SimDataFormats/Track/interface/SimTrack.h"
00013 #include "SimDataFormats/Track/interface/SimTrackContainer.h"
00014 #include "SimDataFormats/Vertex/interface/SimVertex.h"
00015 #include "SimDataFormats/Vertex/interface/SimVertexContainer.h"
00016 
00017 #include "FWCore/Common/interface/EventBase.h"
00018 
00019 #include "TEveTrack.h"
00020 #include "TParticle.h"
00021 #include "TDatabasePDG.h"
00022 
00023 class FWSimTrackProxyBuilder : public FWProxyBuilderBase
00024 {
00025 public:
00026    FWSimTrackProxyBuilder( void ) {} 
00027    virtual ~FWSimTrackProxyBuilder( void ) {}
00028 
00029    REGISTER_PROXYBUILDER_METHODS();
00030 
00031 private:
00032    // Disable default copy constructor
00033    FWSimTrackProxyBuilder( const FWSimTrackProxyBuilder& );
00034    // Disable default assignment operator
00035    const FWSimTrackProxyBuilder& operator=( const FWSimTrackProxyBuilder& );
00036 
00037    virtual void build( const FWEventItem* iItem, TEveElementList* product, const FWViewContext* );
00038 
00039    void getVertices( void );
00040    void addParticlesToPdgDataBase( void );
00041    std::vector<SimVertex> m_vertices;
00042 };
00043 
00044 void
00045 FWSimTrackProxyBuilder::getVertices( void )
00046 {
00047    edm::Handle<edm::SimVertexContainer> collection;
00048    const edm::EventBase *event = item()->getEvent();
00049    event->getByLabel( edm::InputTag( "g4SimHits" ), collection );
00050    
00051    if( collection.isValid())
00052    {
00053       for( std::vector<SimVertex>::const_iterator isimv = collection->begin(), isimvEnd = collection->end();
00054            isimv != isimvEnd; ++isimv )
00055       {
00056          m_vertices.push_back( *isimv );
00057       }
00058    }
00059 }
00060 
00061 void
00062 FWSimTrackProxyBuilder::addParticlesToPdgDataBase( void )
00063 {
00064    static Bool_t bAdded = kFALSE;
00065    // Check if already called
00066    if(bAdded)return;
00067    bAdded = true;
00068    
00069    TDatabasePDG *pdgDB = TDatabasePDG::Instance();
00070    const Int_t kspe=50000000;
00071    
00072    // PDG nuclear states are 10-digit numbers
00073    // 10LZZZAAAI e.g. deuteron is 
00074    // 1000010020
00075    const Int_t kion=1000000000;
00076    
00077    /*
00078     const Double_t kAu2Gev=0.9314943228;
00079     */
00080    
00081    const Double_t khSlash = 1.0545726663e-27;
00082    const Double_t kErg2Gev = 1/1.6021773349e-3;
00083    const Double_t khShGev = khSlash*kErg2Gev;
00084    const Double_t kYear2Sec = 3600*24*365.25;
00085    
00086    //
00087    // Bottom mesons
00088    // mass and life-time from PDG
00089    //
00090    pdgDB->AddParticle("Upsilon(3S)","Upsilon(3S)",10.3552,kTRUE,
00091                       0,1,"Bottonium",200553);
00092    
00093    // QCD diffractive states
00094    pdgDB->AddParticle("rho_diff0","rho_diff0",0,kTRUE,
00095                       0,0,"QCD diffr. state",9900110);
00096    pdgDB->AddParticle("pi_diffr+","pi_diffr+",0,kTRUE,
00097                       0,1,"QCD diffr. state",9900210);
00098    pdgDB->AddParticle("omega_di","omega_di",0,kTRUE,
00099                       0,0,"QCD diffr. state",9900220);
00100    pdgDB->AddParticle("phi_diff","phi_diff",0,kTRUE,
00101                       0,0,"QCD diffr. state",9900330);
00102    pdgDB->AddParticle("J/psi_di","J/psi_di",0,kTRUE,
00103                       0,0,"QCD diffr. state",9900440);
00104    pdgDB->AddParticle("n_diffr0","n_diffr0",0,kTRUE,
00105                       0,0,"QCD diffr. state",9902110);
00106    pdgDB->AddParticle("p_diffr+","p_diffr+",0,kTRUE,
00107                       0,1,"QCD diffr. state",9902210);
00108    
00109    // From Herwig
00110    pdgDB->AddParticle("PSID    ", " ", 3.7699, kFALSE, 0.0, 0, "meson",   30443);
00111    
00112    pdgDB->AddParticle("A_00    ", " ", 0.9960, kFALSE, 0.0, 0, "meson",  9000111); 
00113    pdgDB->AddParticle("A_0+    ", " ", 0.9960, kFALSE, 0.0,+3, "meson",  9000211);  
00114    pdgDB->AddParticle("A_0-    ", " ", 0.9960, kFALSE, 0.0,-3, "meson", -9000211);  
00115    
00116    pdgDB->AddParticle("F0P0    ", " ", 0.9960, kFALSE, 0.0, 0, "meson",  9010221); 
00117    
00118    pdgDB->AddParticle("KDL_2+  ", " ", 1.773,  kFALSE, 0.0,+3, "meson",   10325); 
00119    pdgDB->AddParticle("KDL_2-  ", " ", 1.773,  kFALSE, 0.0,-3, "meson",  -10325); 
00120    
00121    pdgDB->AddParticle("KDL_20  ", " ", 1.773,  kFALSE, 0.0, 0, "meson",   10315); 
00122    pdgDB->AddParticle("KDL_2BR0", " ", 1.773,  kFALSE, 0.0, 0, "meson",  -10315); 
00123    
00124    pdgDB->AddParticle("PI_2+   ", " ", 1.670,  kFALSE, 0.0,+3, "meson",   10215);
00125    pdgDB->AddParticle("PI_2-   ", " ", 1.670,  kFALSE, 0.0,-3, "meson",  -10215);
00126    pdgDB->AddParticle("PI_20   ", " ", 1.670,  kFALSE, 0.0, 0, "meson",   10115);
00127    
00128    
00129    pdgDB->AddParticle("KD*+    ", " ", 1.717,  kFALSE, 0.0,+3, "meson",   30323); 
00130    pdgDB->AddParticle("KD*-    ", " ", 1.717,  kFALSE, 0.0,-3, "meson",  -30323); 
00131    
00132    pdgDB->AddParticle("KD*0    ", " ", 1.717,  kFALSE, 0.0, 0, "meson",   30313); 
00133    pdgDB->AddParticle("KDBR*0  ", " ", 1.717,  kFALSE, 0.0, 0, "meson",  -30313); 
00134    
00135    pdgDB->AddParticle("RHOD+   ", " ", 1.700,  kFALSE, 0.0,+3, "meson",   30213); 
00136    pdgDB->AddParticle("RHOD-   ", " ", 1.700,  kFALSE, 0.0,-3, "meson",  -30213); 
00137    pdgDB->AddParticle("RHOD0   ", " ", 1.700,  kFALSE, 0.0, 0, "meson",   30113); 
00138    
00139    pdgDB->AddParticle("ETA_2(L)", " ", 1.632,  kFALSE, 0.0, 0, "meson",   10225); 
00140    pdgDB->AddParticle("ETA_2(H)", " ", 1.854,  kFALSE, 0.0, 0, "meson",   10335); 
00141    pdgDB->AddParticle("OMEGA(H)", " ", 1.649,  kFALSE, 0.0, 0, "meson",   30223);
00142    
00143    
00144    pdgDB->AddParticle("KDH_2+  ", " ", 1.816,  kFALSE, 0.0,+3, "meson",   20325);
00145    pdgDB->AddParticle("KDH_2-  ", " ", 1.816,  kFALSE, 0.0,-3, "meson",  -20325);
00146    
00147    pdgDB->AddParticle("KDH_20  ", " ", 1.816,  kFALSE, 0.0, 0, "meson",   20315);
00148    pdgDB->AddParticle("KDH_2BR0", " ", 1.816,  kFALSE, 0.0, 0, "meson",  -20315);
00149    
00150    
00151    pdgDB->AddParticle("KD_3+   ", " ", 1.773,  kFALSE, 0.0,+3, "meson",     327);
00152    pdgDB->AddParticle("KD_3-   ", " ", 1.773,  kFALSE, 0.0,-3, "meson",    -327);
00153    
00154    pdgDB->AddParticle("KD_30   ", " ", 1.773,  kFALSE, 0.0, 0, "meson",     317);
00155    pdgDB->AddParticle("KD_3BR0 ", " ", 1.773,  kFALSE, 0.0, 0, "meson",    -317);
00156    
00157    pdgDB->AddParticle("RHO_3+  ", " ", 1.691,  kFALSE, 0.0,+3, "meson",     217);
00158    pdgDB->AddParticle("RHO_3-  ", " ", 1.691,  kFALSE, 0.0,-3, "meson",    -217);
00159    pdgDB->AddParticle("RHO_30  ", " ", 1.691,  kFALSE, 0.0, 0, "meson",     117);
00160    pdgDB->AddParticle("OMEGA_3 ", " ", 1.667,  kFALSE, 0.0, 0, "meson",     227);
00161    pdgDB->AddParticle("PHI_3   ", " ", 1.854,  kFALSE, 0.0, 0, "meson",     337);
00162    
00163    pdgDB->AddParticle("CHI2P_B0", " ", 10.232, kFALSE, 0.0, 0, "meson", 110551);
00164    pdgDB->AddParticle("CHI2P_B1", " ", 10.255, kFALSE, 0.0, 0, "meson", 120553);
00165    pdgDB->AddParticle("CHI2P_B2", " ", 10.269, kFALSE, 0.0, 0, "meson", 100555);
00166    pdgDB->AddParticle("UPSLON4S", " ", 10.580, kFALSE, 0.0, 0, "meson", 300553);
00167    
00168    
00169    // IONS
00170    //
00171    // Done by default now from Pythia6 table
00172    // Needed for other generators
00173    // So check if already defined
00174    
00175    
00176    Int_t ionCode = kion+10020;
00177    if(!pdgDB->GetParticle(ionCode)){
00178       pdgDB->AddParticle("Deuteron","Deuteron", 1.875613, kTRUE,
00179                          0,3,"Ion",ionCode);
00180    }
00181    pdgDB->AddAntiParticle("AntiDeuteron", - ionCode);
00182    
00183    ionCode = kion+10030;
00184    if(!pdgDB->GetParticle(ionCode)){
00185       pdgDB->AddParticle("Triton","Triton", 2.80925, kFALSE,
00186                          khShGev/(12.33*kYear2Sec),3,"Ion",ionCode);
00187    }
00188    pdgDB->AddAntiParticle("AntiTriton", - ionCode);
00189    
00190    ionCode = kion+20030;
00191    if(!pdgDB->GetParticle(ionCode)){
00192       pdgDB->AddParticle("HE3","HE3", 2.80923,kFALSE,
00193                          0,6,"Ion",ionCode);
00194    }
00195    pdgDB->AddAntiParticle("AntiHE3", - ionCode);
00196    
00197    ionCode = kion+20040;
00198    if(!pdgDB->GetParticle(ionCode)){
00199       pdgDB->AddParticle("Alpha","Alpha", 3.727417, kTRUE,
00200                          khShGev/(12.33*kYear2Sec), 6, "Ion", ionCode);
00201    }
00202    pdgDB->AddAntiParticle("AntiAlpha", - ionCode);
00203    
00204    // Special particles
00205    // 
00206    pdgDB->AddParticle("Cherenkov","Cherenkov",0,kFALSE,
00207                       0,0,"Special",kspe+50);
00208    pdgDB->AddParticle("FeedbackPhoton","FeedbackPhoton",0,kFALSE,
00209                       0,0,"Special",kspe+51);
00210    pdgDB->AddParticle("Lambda1520","Lambda1520",1.5195,kFALSE,
00211                       0.0156,0,"Resonance",3124);
00212    pdgDB->AddAntiParticle("Lambda1520bar",-3124);   
00213 }
00214 
00215 void
00216 FWSimTrackProxyBuilder::build( const FWEventItem* iItem, TEveElementList* product, const FWViewContext* )
00217 {
00218    const edm::SimTrackContainer* collection = 0;
00219    iItem->get( collection );
00220 
00221    if( 0 == collection )
00222    {
00223       return;
00224    }
00225    addParticlesToPdgDataBase();
00226 
00227    TEveTrackPropagator* propagator = context().getTrackPropagator();
00228    getVertices();
00229    int i = 0;
00230    for( std::vector<SimTrack>::const_iterator it = collection->begin(), end = collection->end(); it != end; ++it )
00231    {
00232      const SimTrack& iData = (*it);
00233      double vx = 0.0;
00234      double vy = 0.0;
00235      double vz = 0.0;
00236      double vt = 0.0;
00237      if(! iData.noVertex() && ! m_vertices.empty())
00238      {
00239        int vInd = iData.vertIndex();
00240        vx = ( m_vertices.at( vInd )).position().x() * 0.01;
00241        vy = ( m_vertices.at( vInd )).position().y() * 0.01;
00242        vz = ( m_vertices.at( vInd )).position().z() * 0.01;
00243        vt = ( m_vertices.at( vInd )).position().t();
00244      }
00245    
00246      TParticle* particle = new TParticle;
00247      particle->SetPdgCode( iData.type());
00248      particle->SetMomentum( iData.momentum().px(), iData.momentum().py(), iData.momentum().pz(), iData.momentum().e());
00249      particle->SetProductionVertex( vx, vy, vz, vt );
00250   
00251      TEveTrack* track = new TEveTrack( particle, ++i, propagator );
00252      if( iData.charge() == 0 )
00253      {
00254        track->SetLineStyle( 7 );
00255      }
00256      track->AddPathMark( TEvePathMark( TEvePathMark::kReference, 
00257                                        TEveVector( iData.trackerSurfacePosition().x(), iData.trackerSurfacePosition().y(), iData.trackerSurfacePosition().z()),
00258                                        TEveVector( iData.trackerSurfaceMomentum().px(), iData.trackerSurfaceMomentum().py(), iData.trackerSurfaceMomentum().pz())));
00259      track->MakeTrack();
00260      setupAddElement( track, product );
00261    }
00262 }
00263 
00264 REGISTER_FWPROXYBUILDER( FWSimTrackProxyBuilder, edm::SimTrackContainer, "SimTracks", FWViewType::kAll3DBits | FWViewType::kAllRPZBits );