CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/SimG4Core/CheckSecondary/src/StoreSecondary.cc

Go to the documentation of this file.
00001 #include "SimG4Core/CheckSecondary/interface/StoreSecondary.h"
00002 
00003 #include "FWCore/Framework/interface/Event.h"
00004 #include "FWCore/Framework/interface/EventSetup.h"
00005 
00006 #include "SimG4Core/Notification/interface/BeginOfEvent.h"
00007 #include "SimG4Core/Notification/interface/BeginOfTrack.h"
00008 
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010 
00011 #include "G4Step.hh"
00012 #include "G4Track.hh"
00013 #include "G4VProcess.hh"
00014 #include "G4HCofThisEvent.hh"
00015 #include "CLHEP/Units/GlobalSystemOfUnits.h"
00016 #include "CLHEP/Units/GlobalPhysicalConstants.h"
00017 
00018 #include <cmath>
00019 #include <iostream>
00020 #include <iomanip>
00021 
00022 StoreSecondary::StoreSecondary(const edm::ParameterSet &p) {
00023 
00024   edm::ParameterSet m_p = p.getParameter<edm::ParameterSet>("StoreSecondary");
00025   treatSecondary    = new TreatSecondary (m_p);
00026 
00027   produces<std::vector<math::XYZTLorentzVector> >("SecondaryMomenta");
00028   produces<std::vector<int> >("SecondaryParticles");
00029   //  produces<std::vector<std::string> >("SecondaryProcesses");
00030 
00031   edm::LogInfo("CheckSecondary") << "Instantiate StoreSecondary to store "
00032                                  << "secondaries after 1st hadronic inelastic"
00033                                  << " interaction";
00034 } 
00035    
00036 StoreSecondary::~StoreSecondary() {
00037   delete treatSecondary;
00038 }
00039 
00040 void StoreSecondary::produce(edm::Event& e, const edm::EventSetup&) {
00041 
00042   std::auto_ptr<std::vector<math::XYZTLorentzVector> > secMom(new std::vector<math::XYZTLorentzVector>);
00043   *secMom = secondaries;
00044   e.put(secMom, "SecondaryMomenta");
00045 
00046   std::auto_ptr<std::vector<int> > secNumber(new std::vector<int>);
00047   *secNumber = nsecs;
00048   e.put(secNumber, "SecondaryParticles");
00049 
00050   /*
00051   std::auto_ptr<std::vector<std::string> > secProc(new std::vector<std::string>);
00052   *secProc = procs;
00053   e.put(secProc, "SecondaryProcesses");
00054   */
00055 
00056   LogDebug("CheckSecondary") << "StoreSecondary:: Event " << e.id() << " with "
00057                              << nsecs.size() << " hadronic collisions with "
00058                              << "secondaries produced in each step";
00059   for (unsigned int i= 0; i < nsecs.size(); i++) 
00060     LogDebug("CheckSecondary") << " " << nsecs[i] << " from " << procs[i];
00061   LogDebug("CheckSecondary") << " and " << secondaries.size() << " secondaries"
00062                              << " produced in the first interactions:";
00063   for (unsigned int i= 0; i < secondaries.size(); i++) 
00064     LogDebug("CheckSecondary") << "Secondary " << i << " " << secondaries[i];
00065 }
00066 
00067 void StoreSecondary::update(const BeginOfEvent *) {
00068 
00069   nsecs.clear();
00070   procs.clear();
00071   secondaries.clear();
00072 }
00073 
00074 void StoreSecondary::update(const BeginOfTrack * trk) {
00075 
00076   const G4Track * thTk = (*trk)();
00077   treatSecondary->initTrack(thTk);
00078   if (nsecs.size() == 0 && thTk->GetParentID() <= 0) storeIt = true;
00079   else                                               storeIt = false;
00080   nHad  = 0;
00081 }
00082 
00083 void StoreSecondary::update(const G4Step * aStep) {
00084 
00085   std::string      name;
00086   int              procID;
00087   bool             hadrInt;
00088   double           deltaE;
00089   std::vector<int> charge;
00090   std::vector<math::XYZTLorentzVector> tracks = treatSecondary->tracks(aStep,
00091                                                                        name,
00092                                                                        procID,
00093                                                                        hadrInt,
00094                                                                        deltaE,
00095                                                                        charge);
00096   if (hadrInt) {
00097     nHad++;
00098     if (storeIt) {
00099       int sec = (int)(tracks.size());
00100       nsecs.push_back(sec);
00101       procs.push_back(name);
00102       if (nHad == 1) {
00103         for (int i=0; i<sec; i++) 
00104           secondaries.push_back(tracks[i]);
00105       }
00106     }
00107   }
00108 }