CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

MaterialBudgetAction Class Reference

#include <MaterialBudgetAction.h>

Inheritance diagram for MaterialBudgetAction:
SimProducer Observer< const BeginOfRun * > Observer< const BeginOfTrack * > Observer< const G4Step * > Observer< const EndOfTrack * > Observer< const EndOfEvent * > SimWatcher

List of all members.

Public Member Functions

 MaterialBudgetAction (const edm::ParameterSet &)
void produce (edm::Event &, const edm::EventSetup &)
virtual ~MaterialBudgetAction ()

Private Member Functions

bool CheckTouchableInSelectedVolumes (const G4VTouchable *touch)
void endRun ()
std::string getPartName (G4StepPoint *aStepPoint)
std::string getSubDetectorName (G4StepPoint *aStepPoint)
void initRun ()
 MaterialBudgetAction (const MaterialBudgetAction &)
const MaterialBudgetActionoperator= (const MaterialBudgetAction &)
void processEvent (unsigned int nEv)
void save (const G4Step *aStep)
bool StopAfterProcess (const G4Step *aStep)
void update (const BeginOfRun *)
 This routine will be called when the appropriate signal arrives.
void update (const EndOfTrack *)
 This routine will be called when the appropriate signal arrives.
void update (const G4Step *)
 This routine will be called when the appropriate signal arrives.
void update (const EndOfEvent *)
 This routine will be called when the appropriate signal arrives.
void update (const BeginOfTrack *)
 This routine will be called when the appropriate signal arrives.

Private Attributes

double Ekin
bool firstParticle
bool saveToHistos
bool saveToTree
bool saveToTxt
bool storeDecay
MaterialBudgetDatatheData
std::string theHistoList
TestHistoMgrtheHistoMgr
MaterialBudgetFormattheHistos
G4String theProcessToStop
MaterialBudgetTreetheTree
MaterialBudgetTxttheTxt
std::vector< G4String > theVolumeList

Detailed Description

Definition at line 29 of file MaterialBudgetAction.h.


Constructor & Destructor Documentation

MaterialBudgetAction::MaterialBudgetAction ( const edm::ParameterSet iPSet)

Definition at line 31 of file MaterialBudgetAction.cc.

References gather_cfg::cout, Ekin, firstParticle, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), saveToHistos, saveToTree, saveToTxt, MaterialBudgetData::SetAllStepsToTree(), storeDecay, AlCaHLTBitMon_QueryRunRegistry::string, theData, theHistoList, theHistoMgr, theHistos, theProcessToStop, theTree, theTxt, and theVolumeList.

                                                                       :
  theHistoMgr(0)
{
  theData = new MaterialBudgetData;
  
  edm::ParameterSet m_Anal = iPSet.getParameter<edm::ParameterSet>("MaterialBudgetAction");
  
  //---- Accumulate material budget only inside selected volumes
  std::string theHistoList = m_Anal.getParameter<std::string>("HistogramList");
  std::vector<std::string> volList = m_Anal.getParameter< std::vector<std::string> >("SelectedVolumes");
  std::vector<std::string>::const_iterator ite;
  std::cout << "TestGeometry: List of the selected volumes: " << std::endl;
  for( ite = volList.begin(); ite != volList.end(); ite++ ){
    if( (*ite) != "None" ) {
      theVolumeList.push_back( *ite );
      std::cout << (*ite) << std::endl;
    }
  }
  // log
  if(theHistoList == "Tracker" ) {
    std::cout << "TestGeometry: MaterialBudgetAction running in Tracker Mode" << std::endl;
  } 
  else if(theHistoList == "ECAL" ) {
    std::cout << "TestGeometry: MaterialBudgetAction running in Ecal Mode" << std::endl;
  } 
  else {
    std::cout << "TestGeometry: MaterialBudgetAction running in General Mode" << std::endl;
  }
  //
    
  //---- Stop track when a process occurs
  theProcessToStop = m_Anal.getParameter<std::string>("StopAfterProcess");
  std::cout << "TestGeometry: stop at process " << theProcessToStop << std::endl;

  //---- Save histos to ROOT file 
  std::string saveToHistosFile = m_Anal.getParameter<std::string>("HistosFile");
  if( saveToHistosFile != "None" ) {
    saveToHistos = true;
    std::cout << "TestGeometry: saving histograms to " << saveToHistosFile << std::endl;
    theHistoMgr = new TestHistoMgr();

    // rr
    if(theHistoList == "Tracker" ) {
      theHistos = new MaterialBudgetTrackerHistos( theData, theHistoMgr, saveToHistosFile );
    } 
    else if (theHistoList == "ECAL") {
      theHistos = new MaterialBudgetEcalHistos( theData, theHistoMgr, saveToHistosFile );
    }
    else {
      theHistos = new MaterialBudgetHistos( theData, theHistoMgr, saveToHistosFile );
    }
      // rr
  } else {
    saveToHistos = false;
  }
  
  //---- Save material budget info to TEXT file
  std::string saveToTxtFile = m_Anal.getParameter<std::string>("TextFile");
  if( saveToTxtFile != "None" ) {
    saveToTxt = true;
    std::cout << "TestGeometry: saving text info to " << saveToTxtFile << std::endl;
    theTxt = new MaterialBudgetTxt( theData, saveToTxtFile );
  } else {
    saveToTxt = false;
  }
  
  //---- Compute all the steps even if not stored on file
  bool allSteps = m_Anal.getParameter<bool>("AllStepsToTree");  
  std::cout << "TestGeometry: all steps are computed " << allSteps << std::endl;
  if( allSteps ) theData->SetAllStepsToTree();
  
  //---- Save tree to ROOT file
  std::string saveToTreeFile = m_Anal.getParameter<std::string>("TreeFile");
  //  std::string saveToTreeFile = ""; 
  if( saveToTreeFile != "None" ) {
    saveToTree = true;
    theTree = new MaterialBudgetTree( theData, saveToTreeFile );
  } else {
    saveToTree = false;
  }
  std::cout << "TestGeometry: saving ROOT TREE to " << saveToTreeFile << std::endl;
  
  //---- Track the first decay products of the main particle
  // if their kinetic energy is greater than  Ekin
  storeDecay = m_Anal.getUntrackedParameter<bool>("storeDecay",false);  
  Ekin       = m_Anal.getUntrackedParameter<double>("EminDecayProd",1000.0); // MeV
  std::cout << "TestGeometry: decay products steps are stored " << storeDecay;
  if(storeDecay) std::cout << " if their kinetic energy is greater than " << Ekin << " MeV";
  std::cout << std::endl;
  firstParticle = false;
  }
MaterialBudgetAction::~MaterialBudgetAction ( ) [virtual]

Definition at line 125 of file MaterialBudgetAction.cc.

References saveToHistos, saveToTree, saveToTxt, theData, theHistoMgr, theHistos, theTree, and theTxt.

{
  if (saveToTxt) delete theTxt;
  if (saveToTree) delete theTree;
  if (saveToHistos) delete theHistos;
  if (theHistoMgr) delete theHistoMgr;
  delete theData;
}
MaterialBudgetAction::MaterialBudgetAction ( const MaterialBudgetAction ) [private]

Member Function Documentation

bool MaterialBudgetAction::CheckTouchableInSelectedVolumes ( const G4VTouchable *  touch) [private]

Definition at line 337 of file MaterialBudgetAction.cc.

References theVolumeList.

Referenced by update().

{
  std::vector<G4String>::const_iterator ite;
  size_t volh = touch->GetHistoryDepth();
  for( ite = theVolumeList.begin(); ite != theVolumeList.end(); ite++ ){
    //-  std::cout << " CheckTouchableInSelectedVolumes vol " << *ite << std::endl;
    for( int ii = volh; ii >= 0; ii-- ){
      //-  std::cout << ii << " CheckTouchableInSelectedVolumes parent  " << touch->GetVolume(ii)->GetName() << std::endl;
      if( touch->GetVolume(ii)->GetName() == *ite ) return true;
    }
  }

  return false;

}
void MaterialBudgetAction::endRun ( void  ) [private]

Definition at line 331 of file MaterialBudgetAction.cc.

{
}
std::string MaterialBudgetAction::getPartName ( G4StepPoint *  aStepPoint) [private]

Definition at line 294 of file MaterialBudgetAction.cc.

{
  G4TouchableHistory* theTouchable
    = (G4TouchableHistory*)(aStepPoint->GetTouchable());
  G4int num_levels = theTouchable->GetHistoryDepth();
  //  theTouchable->MoveUpHistory(num_levels-3);
  
  if( theTouchable->GetVolume() ) {
    return theTouchable->GetVolume(num_levels-3)->GetName();
  } else { 
    return "OutOfWorld";
  }
}
std::string MaterialBudgetAction::getSubDetectorName ( G4StepPoint *  aStepPoint) [private]

Definition at line 279 of file MaterialBudgetAction.cc.

{
  G4TouchableHistory* theTouchable
    = (G4TouchableHistory*)(aStepPoint->GetTouchable());
  G4int num_levels = theTouchable->GetHistoryDepth();
  
  if( theTouchable->GetVolume() ) {
    return theTouchable->GetVolume(num_levels-1)->GetName();
  } else { 
    return "OutOfWorld";
  }
}
void MaterialBudgetAction::initRun ( ) [private]
const MaterialBudgetAction& MaterialBudgetAction::operator= ( const MaterialBudgetAction ) [private]
void MaterialBudgetAction::processEvent ( unsigned int  nEv) [private]
void MaterialBudgetAction::produce ( edm::Event e,
const edm::EventSetup  
) [virtual]

Implements SimProducer.

Definition at line 136 of file MaterialBudgetAction.cc.

{
}
void MaterialBudgetAction::save ( const G4Step *  aStep) [private]
bool MaterialBudgetAction::StopAfterProcess ( const G4Step *  aStep) [private]

Definition at line 355 of file MaterialBudgetAction.cc.

References gather_cfg::cout, NULL, and theProcessToStop.

Referenced by update().

{
  if( theProcessToStop == "" ) return false;

  if(aStep->GetPostStepPoint()->GetProcessDefinedStep() == NULL) return false;
  if( aStep->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName() == theProcessToStop ) {
    std::cout << " MaterialBudgetAction::StopAfterProcess " << aStep->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName() << std::endl;
    return true;
  } else {
    return false;
  }
}
void MaterialBudgetAction::update ( const BeginOfRun ) [private, virtual]

This routine will be called when the appropriate signal arrives.

Implements Observer< const BeginOfRun * >.

Definition at line 142 of file MaterialBudgetAction.cc.

References dtNoiseDBValidation_cfg::cerr, findQualityFiles::jj, AlCaHLTBitMon_QueryRunRegistry::string, theProcessToStop, and theVolumeList.

{
  //----- Check that selected volumes are indeed part of the geometry
  const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
  std::vector<G4LogicalVolume*>::const_iterator lvcite;
  std::vector<G4String>::const_iterator volcite;

  for( volcite = theVolumeList.begin(); volcite != theVolumeList.end(); volcite++ ){
  //-  std::cout << " MaterialBudgetAction checking volume " << *volcite << std::endl;
    bool volFound = false;
    for( lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++ ) {
      if( (*lvcite)->GetName() == *volcite )  {
        volFound = true;
        break;
      }
    }
    if( !volFound ) {
      std::cerr << " @@@@@@@ WARNING at MaterialBudgetAction: selected volume not found in geometry " << *volcite << std::endl;
    }
  }


  //----- Check process selected is one of the available ones
  bool procFound = false;
  if( theProcessToStop == "None" ) { 
    procFound = true;
  } else {
    G4ParticleTable * partTable = G4ParticleTable::GetParticleTable();
    int siz = partTable->size();
    for (int ii= 0; ii < siz; ii++) {
      G4ParticleDefinition * particle = partTable->GetParticle(ii);
      std::string particleName = particle->GetParticleName();
      
      //--- All processes of this particle 
      G4ProcessManager * pmanager = particle->GetProcessManager();
      G4ProcessVector * pvect = pmanager->GetProcessList();
      int sizproc = pvect->size();
      for (int jj = 0; jj < sizproc; jj++) {
        if( (*pvect)[jj]->GetProcessName() == theProcessToStop ) {
          procFound = true;
          break;
        }
      }
    }
  }

  if( !procFound ) {
      std::cerr << " @@@@@@@ WARNING at MaterialBudgetAction: selected process to stop tracking not found " << theProcessToStop << std::endl;
    }

}
void MaterialBudgetAction::update ( const EndOfTrack ) [private, virtual]

This routine will be called when the appropriate signal arrives.

Implements Observer< const EndOfTrack * >.

Definition at line 311 of file MaterialBudgetAction.cc.

References MaterialBudgetData::dataEndTrack(), and theData.

{
  //  std::cout << " EndOfTrack " << saveToHistos << std::endl;
  const G4Track * aTrack = (*trk)(); // recover G4 pointer if wanted
  //  if( aTrack->GetParentID() != 0 ) return;
  
  //---------- end of track (OutOfWorld)
  //-  std::cout << " Data End Track " << std::endl;
  theData->dataEndTrack( aTrack );
}
void MaterialBudgetAction::update ( const G4Step *  ) [private, virtual]

This routine will be called when the appropriate signal arrives.

Implements Observer< const G4Step * >.

Definition at line 251 of file MaterialBudgetAction.cc.

References CheckTouchableInSelectedVolumes(), MaterialBudgetData::dataPerStep(), MaterialBudgetTxt::fillPerStep(), MaterialBudgetFormat::fillPerStep(), MaterialBudgetTree::fillPerStep(), saveToHistos, saveToTree, saveToTxt, StopAfterProcess(), theData, theHistos, theTree, theTxt, and theVolumeList.

{

  //----- Check it is inside one of the volumes selected
  if( theVolumeList.size() != 0 ) {
    if( !CheckTouchableInSelectedVolumes( aStep->GetTrack()->GetTouchable() ) ) return;
  } 

  //---------- each step
  theData->dataPerStep( aStep );
  //-  std::cout << " aStep->GetPostStepPoint()->GetTouchable() " << aStep->GetPostStepPoint()->GetTouchable()->GetVolume() << " " << aStep->GetPreStepPoint()->GetTouchable()->GetVolume() << std::endl;
  if (saveToTree) theTree->fillPerStep();
  if (saveToHistos) theHistos->fillPerStep();
  if (saveToTxt) theTxt->fillPerStep();


  //----- Stop tracking after selected process
  if( StopAfterProcess( aStep ) ) {
    G4Track* track = aStep->GetTrack();
    track->SetTrackStatus( fStopAndKill );
  }

  return;

}
void MaterialBudgetAction::update ( const EndOfEvent ) [private, virtual]

This routine will be called when the appropriate signal arrives.

Implements Observer< const EndOfEvent * >.

Definition at line 322 of file MaterialBudgetAction.cc.

References MaterialBudgetTxt::fillEndTrack(), MaterialBudgetTree::fillEndTrack(), MaterialBudgetFormat::fillEndTrack(), saveToHistos, saveToTree, saveToTxt, theHistos, theTree, and theTxt.

{
  //-  std::cout << " Data End Event " << std::endl;
  if (saveToTree) theTree->fillEndTrack();
  if (saveToHistos) theHistos->fillEndTrack();
  if (saveToTxt) theTxt->fillEndTrack();  
}
void MaterialBudgetAction::update ( const BeginOfTrack ) [private, virtual]

This routine will be called when the appropriate signal arrives.

Implements Observer< const BeginOfTrack * >.

Definition at line 196 of file MaterialBudgetAction.cc.

References gather_cfg::cout, MaterialBudgetData::dataStartTrack(), Ekin, MaterialBudgetFormat::fillStartTrack(), MaterialBudgetTxt::fillStartTrack(), MaterialBudgetTree::fillStartTrack(), firstParticle, saveToHistos, saveToTree, saveToTxt, storeDecay, theData, theHistos, theTree, and theTxt.

{
  const G4Track * aTrack = (*trk)(); // recover G4 pointer if wanted
  
  // that was a temporary action while we're sorting out
  // about # of secondaries (produced if CutsPerRegion=true)
  //
  std::cout << "Track ID " << aTrack->GetTrackID() << " Track parent ID " << aTrack->GetParentID() 
            << " PDG Id. = " << aTrack->GetDefinition()->GetPDGEncoding()
            << " Ekin = " << aTrack->GetKineticEnergy() << " MeV" << std::endl;
  if( aTrack->GetCreatorProcess() ) std::cout << " produced through " << aTrack->GetCreatorProcess()->GetProcessType() << std::endl;
  
  if(aTrack->GetTrackID() == 1) {
    firstParticle = true;
  } else {
    firstParticle = false;
  }
  
  if( storeDecay ) { // if record of the decay is requested
    if( aTrack->GetCreatorProcess() ) {
      if (
          aTrack->GetParentID() == 1
          &&
          //      aTrack->GetCreatorProcess()->GetProcessType() == 6
          //      &&
          aTrack->GetKineticEnergy() > Ekin
          ) {
        // continue
      } else {
        G4Track * aTracknc = const_cast<G4Track*>(aTrack);
        aTracknc->SetTrackStatus(fStopAndKill);
        return;
      }
    } // particles produced from a decay (type=6) of the main particle (ID=1) with Kinetic Energy [MeV] > Ekin
  } else { // kill all the other particles (take only the main one until it disappears) if decay not stored
    if( aTrack->GetParentID() != 0) {
      G4Track * aTracknc = const_cast<G4Track*>(aTrack);
      aTracknc->SetTrackStatus(fStopAndKill);
      return;  
    }
  }
  
  
  if(firstParticle) {
    //--------- start of track
    //-    std::cout << " Data Start Track " << std::endl;
    theData->dataStartTrack( aTrack );
    if (saveToTree) theTree->fillStartTrack();
    if (saveToHistos) theHistos->fillStartTrack();
    if (saveToTxt) theTxt->fillStartTrack();
  }
}

Member Data Documentation

double MaterialBudgetAction::Ekin [private]

Definition at line 72 of file MaterialBudgetAction.h.

Referenced by MaterialBudgetAction(), and update().

Definition at line 73 of file MaterialBudgetAction.h.

Referenced by MaterialBudgetAction(), and update().

Definition at line 70 of file MaterialBudgetAction.h.

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

Definition at line 70 of file MaterialBudgetAction.h.

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

Definition at line 70 of file MaterialBudgetAction.h.

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

Definition at line 71 of file MaterialBudgetAction.h.

Referenced by MaterialBudgetAction(), and update().

Definition at line 65 of file MaterialBudgetAction.h.

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

std::string MaterialBudgetAction::theHistoList [private]

Definition at line 77 of file MaterialBudgetAction.h.

Referenced by MaterialBudgetAction().

Definition at line 69 of file MaterialBudgetAction.h.

Referenced by MaterialBudgetAction(), and ~MaterialBudgetAction().

Definition at line 67 of file MaterialBudgetAction.h.

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

Definition at line 76 of file MaterialBudgetAction.h.

Referenced by MaterialBudgetAction(), StopAfterProcess(), and update().

Definition at line 66 of file MaterialBudgetAction.h.

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

Definition at line 68 of file MaterialBudgetAction.h.

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

std::vector<G4String> MaterialBudgetAction::theVolumeList [private]