CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

CheckSecondary Class Reference

#include <CheckSecondary.h>

Inheritance diagram for CheckSecondary:
SimWatcher Observer< const BeginOfEvent * > Observer< const BeginOfTrack * > Observer< const EndOfEvent * > Observer< const G4Step * >

List of all members.

Public Member Functions

 CheckSecondary (const edm::ParameterSet &p)
virtual ~CheckSecondary ()

Private Member Functions

TTree * bookTree (std::string)
 CheckSecondary (const CheckSecondary &)
void endTree ()
const CheckSecondaryoperator= (const CheckSecondary &)
void update (const BeginOfEvent *evt)
 This routine will be called when the appropriate signal arrives.
void update (const G4Step *step)
 This routine will be called when the appropriate signal arrives.
void update (const EndOfEvent *evt)
 This routine will be called when the appropriate signal arrives.
void update (const BeginOfTrack *trk)
 This routine will be called when the appropriate signal arrives.

Private Attributes

std::vector< double > * deltae
TFile * file
std::vector< double > * mass
int nHad
std::vector< int > * nsec
std::vector< int > * procids
std::vector< std::string > * procs
std::vector< double > * px
std::vector< double > * py
std::vector< double > * pz
bool saveToTree
bool storeIt
TreatSecondarytreatSecondary
TTree * tree
G4ProcessTypeEnumeratortypeEnumerator

Detailed Description

Definition at line 24 of file CheckSecondary.h.


Constructor & Destructor Documentation

CheckSecondary::CheckSecondary ( const edm::ParameterSet p)

Definition at line 23 of file CheckSecondary.cc.

References bookTree(), deltae, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), mass, nsec, procids, procs, px, py, pz, saveToTree, AlCaHLTBitMon_QueryRunRegistry::string, treatSecondary, tree, and typeEnumerator.

                                                      : treatSecondary(0),
                                                            typeEnumerator(0),
                                                            nsec(0),procids(0),
                                                            px(0),py(0),pz(0),
                                                            mass(0),deltae(0),
                                                            procs(0),file(0),
                                                            tree(0) {

  edm::ParameterSet m_p = p.getParameter<edm::ParameterSet>("CheckSecondary");
  std::string saveFile = m_p.getUntrackedParameter<std::string>("SaveInFile", "None");
  treatSecondary = new TreatSecondary(m_p);
  typeEnumerator = new G4ProcessTypeEnumerator();

  nsec               = new std::vector<int>();
  px                 = new std::vector<double>();
  py                 = new std::vector<double>();
  pz                 = new std::vector<double>();
  mass               = new std::vector<double>();
  deltae             = new std::vector<double>();
  procids            = new std::vector<int>();
  procs              = new std::vector<std::string>();

  if (saveFile != "None") {
    saveToTree = true;
    tree = bookTree (saveFile);
    edm::LogInfo("CheckSecondary") << "Instantiate CheckSecondary with first"
                                   << " hadronic interaction information"
                                   << " to be saved in file " << saveFile;
  } else {
    saveToTree = false;
    edm::LogInfo("CheckSecondary") << "Instantiate CheckSecondary with first"
                                   << " hadronic interaction information"
                                   << " not saved";
  }
} 
CheckSecondary::~CheckSecondary ( ) [virtual]

Definition at line 59 of file CheckSecondary.cc.

References deltae, endTree(), mass, nsec, procids, procs, px, py, pz, saveToTree, treatSecondary, and typeEnumerator.

                                {
  if (saveToTree)     endTree();
  if (nsec)           delete nsec;
  if (px)             delete px;
  if (py)             delete py;
  if (pz)             delete pz;
  if (mass)           delete mass;
  if (deltae)         delete deltae;
  if (procs)          delete procs;
  if (procids)        delete procids;
  if (typeEnumerator) delete typeEnumerator;
  if (treatSecondary) delete treatSecondary;
}
CheckSecondary::CheckSecondary ( const CheckSecondary ) [private]

Member Function Documentation

TTree * CheckSecondary::bookTree ( std::string  fileName) [private]

Definition at line 73 of file CheckSecondary.cc.

References deltae, file, mass, nsec, procids, procs, px, py, and pz.

Referenced by CheckSecondary().

                                                  {

  file = new TFile (fileName.c_str(), "RECREATE");
  file->cd();

  TTree * t1 = new TTree("T1", "Secondary Particle Information");
  t1->Branch("SecondaryPx",       "std::vector<double>",      &px);
  t1->Branch("SecondaryPy",       "std::vector<double>",      &py);
  t1->Branch("SecondaryPz",       "std::vector<double>",      &pz);
  t1->Branch("SecondaryMass",     "std::vector<double>",      &mass);
  t1->Branch("NumberSecondaries", "std::vector<int>",         &nsec);
  t1->Branch("DeltaEinInteract",  "std::vector<double>",      &deltae);
  t1->Branch("ProcessID",         "std::vector<int>",         &procids);
  t1->Branch("ProcessNames",      "std::vector<std::string>", &procs);
  return t1;
}
void CheckSecondary::endTree ( ) [private]

Definition at line 90 of file CheckSecondary.cc.

References file, and tree.

Referenced by ~CheckSecondary().

                             {

  edm::LogInfo("CheckSecondary") << "Save the Secondary Tree " 
                                 << tree->GetName() << " (" << tree
                                 << ") in file " << file->GetName() << " ("
                                 << file << ")";
  file->cd();
  tree->Write();
  file->Close();
  delete file;
}
const CheckSecondary& CheckSecondary::operator= ( const CheckSecondary ) [private]
void CheckSecondary::update ( const BeginOfTrack ) [private, virtual]

This routine will be called when the appropriate signal arrives.

Implements Observer< const BeginOfTrack * >.

Definition at line 118 of file CheckSecondary.cc.

References TreatSecondary::initTrack(), LogDebug, nHad, storeIt, and treatSecondary.

                                                    {

  const G4Track * thTk = (*trk)();
  treatSecondary->initTrack(thTk);
  if (thTk->GetParentID() <= 0) storeIt = true;
  else                          storeIt = false;
  nHad  = 0;
  LogDebug("CheckSecondary") << "CheckSecondary:: Track " << thTk->GetTrackID()
                             << " Parent " << thTk->GetParentID() << " Flag "
                             << storeIt;
}
void CheckSecondary::update ( const BeginOfEvent ) [private, virtual]

This routine will be called when the appropriate signal arrives.

Implements Observer< const BeginOfEvent * >.

Definition at line 102 of file CheckSecondary.cc.

References LogDebug.

                                                    {

  int iev = (*evt)()->GetEventID();
  LogDebug("CheckSecondary") << "CheckSecondary::=====> Begin of event = " 
                             << iev;

  (*nsec).clear();
  (*procs).clear();
  (*procids).clear();
  (*deltae).clear();
  (*px).clear();
  (*py).clear();
  (*pz).clear();
  (*mass).clear();
}
void CheckSecondary::update ( const EndOfEvent ) [private, virtual]

This routine will be called when the appropriate signal arrives.

Implements Observer< const EndOfEvent * >.

Definition at line 170 of file CheckSecondary.cc.

References i, LogDebug, G4ProcessTypeEnumerator::processG4Name(), procids, saveToTree, tree, and typeEnumerator.

                                                  {

  LogDebug("CheckSecondary") << "CheckSecondary::EndofEvent =====> Event " 
                             << (*evt)()->GetEventID() << " with "
                             << (*nsec).size() << " hadronic collisions with"
                             << " secondaries produced in each step";
  for (unsigned int i= 0; i < (*nsec).size(); i++) 
    LogDebug("CheckSecondary") << " " << (*nsec)[i] << " from " << (*procs)[i]
                               << " ID " << (*procids)[i] << " (" 
                               << typeEnumerator->processG4Name((*procids)[i])
                               << ") deltaE = " << (*deltae)[i] << " MeV";
  LogDebug("CheckSecondary") << "And " << (*mass).size() << " secondaries "
                             << "produced in the first interactions";
  for (unsigned int i= 0; i < (*mass).size(); i++) 
    LogDebug("CheckSecondary") << "Secondary " << i << " (" << (*px)[i] << ", "
                               << (*py)[i] << ", " << (*pz)[i] << ", " 
                               << (*mass)[i] << ")";

  if (saveToTree) tree->Fill();
}
void CheckSecondary::update ( const G4Step *  ) [private, virtual]

This routine will be called when the appropriate signal arrives.

Implements Observer< const G4Step * >.

Definition at line 130 of file CheckSecondary.cc.

References DeDxDiscriminatorTools::charge(), i, LogDebug, m, mag(), mergeVDriftHistosByStation::name, nHad, storeIt, AlCaHLTBitMon_QueryRunRegistry::string, TreatSecondary::tracks(), testEve_cfg::tracks, and treatSecondary.

                                                {

  std::string      name;
  int              procID;
  bool             hadrInt;
  double           deltaE;
  std::vector<int> charge;
  std::vector<math::XYZTLorentzVector> tracks = treatSecondary->tracks(aStep,
                                                                       name,
                                                                       procID,
                                                                       hadrInt,
                                                                       deltaE,
                                                                       charge);
  if (storeIt && hadrInt) {
    double pInit = (aStep->GetPreStepPoint()->GetMomentum()).mag();
    double pEnd  = (aStep->GetPostStepPoint()->GetMomentum()).mag();
    nHad++;
    int  sec = (int)(tracks.size());
    LogDebug("CheckSecondary") << "CheckSecondary:: Hadronic Interaction "
                               << nHad << " of type " << name << " ID "
                               << procID << " with " << sec << " secondaries "
                               << " and Momentum (MeV/c) at start " << pInit
                               << " and at end " << pEnd;
    (*nsec).push_back(sec);
    (*procs).push_back(name);
    (*procids).push_back(procID);
    (*deltae).push_back(deltaE);
    if (nHad == 1) {
      for (int i=0; i<sec; i++) {
        double m = tracks[i].M();
        if (charge[i]<0) m = -m;
        (*px).push_back(tracks[i].Px());
        (*py).push_back(tracks[i].Py());
        (*pz).push_back(tracks[i].Pz());
        (*mass).push_back(m);
      }
    }
  }
}

Member Data Documentation

std::vector<double> * CheckSecondary::deltae [private]

Definition at line 52 of file CheckSecondary.h.

Referenced by bookTree(), CheckSecondary(), and ~CheckSecondary().

TFile* CheckSecondary::file [private]

Definition at line 54 of file CheckSecondary.h.

Referenced by bookTree(), and endTree().

std::vector<double> * CheckSecondary::mass [private]

Definition at line 52 of file CheckSecondary.h.

Referenced by bookTree(), CheckSecondary(), and ~CheckSecondary().

int CheckSecondary::nHad [private]

Definition at line 50 of file CheckSecondary.h.

Referenced by update().

std::vector<int>* CheckSecondary::nsec [private]

Definition at line 51 of file CheckSecondary.h.

Referenced by bookTree(), CheckSecondary(), and ~CheckSecondary().

std::vector<int> * CheckSecondary::procids [private]

Definition at line 51 of file CheckSecondary.h.

Referenced by bookTree(), CheckSecondary(), update(), and ~CheckSecondary().

std::vector<std::string>* CheckSecondary::procs [private]

Definition at line 53 of file CheckSecondary.h.

Referenced by bookTree(), CheckSecondary(), and ~CheckSecondary().

std::vector<double>* CheckSecondary::px [private]

Definition at line 52 of file CheckSecondary.h.

Referenced by bookTree(), CheckSecondary(), and ~CheckSecondary().

std::vector<double> * CheckSecondary::py [private]

Definition at line 52 of file CheckSecondary.h.

Referenced by bookTree(), CheckSecondary(), and ~CheckSecondary().

std::vector<double> * CheckSecondary::pz [private]

Definition at line 52 of file CheckSecondary.h.

Referenced by bookTree(), CheckSecondary(), and ~CheckSecondary().

Definition at line 49 of file CheckSecondary.h.

Referenced by CheckSecondary(), update(), and ~CheckSecondary().

bool CheckSecondary::storeIt [private]

Definition at line 49 of file CheckSecondary.h.

Referenced by update().

Definition at line 47 of file CheckSecondary.h.

Referenced by CheckSecondary(), update(), and ~CheckSecondary().

TTree* CheckSecondary::tree [private]

Definition at line 55 of file CheckSecondary.h.

Referenced by CheckSecondary(), endTree(), and update().

Definition at line 48 of file CheckSecondary.h.

Referenced by CheckSecondary(), update(), and ~CheckSecondary().