CMS 3D CMS Logo

Classes | Public Member Functions | Private Member Functions | Private Attributes

CaloTrkProcessing Class Reference

#include <CaloTrkProcessing.h>

Inheritance diagram for CaloTrkProcessing:
SensitiveCaloDetector Observer< const BeginOfEvent * > Observer< const G4Step * > SensitiveDetector

List of all members.

Classes

struct  Detector

Public Member Functions

 CaloTrkProcessing (G4String aSDname, const DDCompactView &cpv, SensitiveDetectorCatalog &clg, edm::ParameterSet const &p, const SimTrackManager *)
virtual void clearHits ()
virtual void EndOfEvent (G4HCofThisEvent *)
void fillHits (edm::PCaloHitContainer &, std::string)
virtual void Initialize (G4HCofThisEvent *)
virtual bool ProcessHits (G4Step *, G4TouchableHistory *)
virtual uint32_t setDetUnitId (G4Step *step)
virtual ~CaloTrkProcessing ()

Private Member Functions

void detectorLevel (const G4VTouchable *, int &, int *, G4String *) const
int detLevels (const G4VTouchable *) const
G4LogicalVolume * detLV (const G4VTouchable *, int) const
std::vector< std::string > getNames (G4String, const DDsvalues_type &)
std::vector< double > getNumbers (G4String, const DDsvalues_type &)
int isItCalo (const G4VTouchable *)
int isItInside (const G4VTouchable *, int, int)
void update (const G4Step *)
 This routine will be called when the appropriate signal arrives.
void update (const BeginOfEvent *evt)
 This routine will be called when the appropriate signal arrives.

Private Attributes

std::vector< Detectordetectors
double eMin
int lastTrackID
const SimTrackManagerm_trackManager
bool putHistory
bool testBeam

Detailed Description

Definition at line 22 of file CaloTrkProcessing.h.


Constructor & Destructor Documentation

CaloTrkProcessing::CaloTrkProcessing ( G4String  aSDname,
const DDCompactView cpv,
SensitiveDetectorCatalog clg,
edm::ParameterSet const &  p,
const SimTrackManager manager 
)

Definition at line 22 of file CaloTrkProcessing.cc.

References DDFilteredView::addFilter(), detectors, eMin, DDSpecificsFilter::equals, Exception, align_tpl::filter, DDFilteredView::firstChild(), CaloTrkProcessing::Detector::fromDetL, CaloTrkProcessing::Detector::fromDets, CaloTrkProcessing::Detector::fromLevels, SensitiveDetector::getNames(), getNumbers(), edm::ParameterSet::getParameter(), i, gen::k, CaloTrkProcessing::Detector::level, LogDebug, CaloTrkProcessing::Detector::lv, DDFilteredView::mergedSpecifics(), SensitiveDetector::name, CaloTrkProcessing::Detector::name, putHistory, DDSpecificsFilter::setCriteria(), testBeam, and relativeConstraints::value.

                                                                     : 
  SensitiveCaloDetector(name, cpv, clg, p), lastTrackID(-1),
  m_trackManager(manager) {  

  //Initialise the parameter set
  edm::ParameterSet m_p = p.getParameter<edm::ParameterSet>("CaloTrkProcessing");
  testBeam   = m_p.getParameter<bool>("TestBeam");
  eMin       = m_p.getParameter<double>("EminTrack")*MeV;
  putHistory = m_p.getParameter<bool>("PutHistory");

  edm::LogInfo("CaloSim") << "CaloTrkProcessing: Initailised with TestBeam = " 
                          << testBeam << " Emin = " << eMin << " MeV and"
                          << " History flag " << putHistory;

  //Get the names 
  G4String attribute = "ReadOutName"; 
  DDSpecificsFilter filter;
  DDValue           ddv(attribute,name,0);
  filter.setCriteria(ddv,DDSpecificsFilter::equals);
  DDFilteredView fv(cpv);
  fv.addFilter(filter);
  fv.firstChild();
  DDsvalues_type sv(fv.mergedSpecifics());

  G4String value                     = "Calorimeter";
  std::vector<std::string> caloNames = getNames (value, sv);
#ifdef DebugLog
  LogDebug("CaloSim") << "CaloTrkProcessing: Names for " << value << ":";
  for (unsigned int i=0; i<caloNames.size(); i++)
    LogDebug("CaloSim") << " (" << i << ") " << caloNames[i];
#endif

  value                                = "Levels";
  std::vector<double>      levels      = getNumbers (value, sv);
#ifdef DebugLog
  LogDebug("CaloSim") << "CaloTrkProcessing: Names for " << value << ":";
  for (unsigned int i=0; i<levels.size(); i++)
    LogDebug("CaloSim") << " (" << i << ") " << levels[i];
#endif

  value                                = "Neighbours";
  std::vector<double>      neighbours  = getNumbers (value, sv);
#ifdef DebugLog
  LogDebug("CaloSim") << "CaloTrkProcessing: Names for " << value << ":";
  for (unsigned int i=0; i<neighbours.size(); i++)
    LogDebug("CaloSim") << " (" << i << ") " << neighbours[i];
#endif

  value                                = "Inside";
  std::vector<std::string> insideNames = getNames (value, sv);
#ifdef DebugLog
  LogDebug("CaloSim") << "CaloTrkProcessing: Names for " << value << ":";
  for (unsigned int i=0; i<insideNames.size(); i++)
    LogDebug("CaloSim") << " (" << i << ") " << insideNames[i];
#endif

  value                                = "InsideLevel";
  std::vector<double>      insideLevel = getNumbers (value, sv);
#ifdef DebugLog
  LogDebug("CaloSim") << "CaloTrkProcessing: Names for " << value << ":";
  for (unsigned int i=0; i<insideLevel.size(); i++)
    LogDebug("CaloSim") << " (" << i << ") " << insideLevel[i];
#endif

  if (caloNames.size() < neighbours.size()) {
    edm::LogError("CaloSim") << "CaloTrkProcessing: # of Calorimeter bins " 
                             << caloNames.size() << " does not match with "
                             << neighbours.size() << " ==> illegal ";
    throw cms::Exception("Unknown", "CaloTrkProcessing")
      << "Calorimeter array size does not match with size of neighbours\n";
  }

  const G4LogicalVolumeStore * lvs = G4LogicalVolumeStore::GetInstance();
  std::vector<G4LogicalVolume *>::const_iterator lvcite;
  int istart = 0;
  for (unsigned int i=0; i<caloNames.size(); i++) {
    G4LogicalVolume* lv     = 0;
    G4String         name   = caloNames[i];
    int              number = static_cast<int>(neighbours[i]);
    for (lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++) {
      if ((*lvcite)->GetName() == name) {
        lv = (*lvcite);
        break;
      }
    }
    if (lv != 0) {
     CaloTrkProcessing::Detector detector;
     detector.name  = name;
     detector.lv    = lv;
     detector.level = static_cast<int>(levels[i]);
     if (istart+number > (int)(insideNames.size())) {
       edm::LogError("CaloSim") << "CaloTrkProcessing: # of InsideNames bins " 
                                << insideNames.size() <<" too few compaerd to "
                                << istart+number << " requested ==> illegal ";
       throw cms::Exception("Unknown", "CaloTrkProcessing")
         << "InsideNames array size does not match with list of neighbours\n";
     }
     std::vector<std::string>      inside;
     std::vector<G4LogicalVolume*> insideLV;
     std::vector<int>              insideLevels;
     for (int k = 0; k < number; k++) {
       lv   = 0;
       name = insideNames[istart+k];
       for (lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++) 
         if ((*lvcite)->GetName() == name) {
           lv = (*lvcite);
           break;
         }
       inside.push_back(name);
       insideLV.push_back(lv);
       insideLevels.push_back(static_cast<int>(insideLevel[istart+k]));
     }
     detector.fromDets   = inside;
     detector.fromDetL   = insideLV;
     detector.fromLevels = insideLevels;
     detectors.push_back(detector);
    }
    istart += number;
  }

  edm::LogInfo("CaloSim") << "CaloTrkProcessing: with " << detectors.size()
                          << " calorimetric volumes";
  for (unsigned int i=0; i<detectors.size(); i++) {
    edm::LogInfo("CaloSim") << "CaloTrkProcessing: Calorimeter volume " << i
                            << " " << detectors[i].name << " LV "
                            << detectors[i].lv << " at level "
                            << detectors[i].level << " with "
                            << detectors[i].fromDets.size() << " neighbours";
    for (unsigned int k=0; k<detectors[i].fromDets.size(); k++) 
      edm::LogInfo("CaloSim") << "                   Element " << k << " "
                              << detectors[i].fromDets[k] << " LV "
                              << detectors[i].fromDetL[k] << " at level "
                              << detectors[i].fromLevels[k];
  }
}
CaloTrkProcessing::~CaloTrkProcessing ( ) [virtual]

Definition at line 162 of file CaloTrkProcessing.cc.

                                      {
  edm::LogInfo("CaloSim") << "CaloTrkProcessing: Deleted";
}

Member Function Documentation

virtual void CaloTrkProcessing::clearHits ( ) [inline, virtual]

Implements SensitiveDetector.

Definition at line 33 of file CaloTrkProcessing.h.

{}
void CaloTrkProcessing::detectorLevel ( const G4VTouchable *  touch,
int &  level,
int *  copyno,
G4String *  name 
) const [private]

Definition at line 415 of file CaloTrkProcessing.cc.

References i, testEve_cfg::level, and susybsm::HSCParticleType::unknown.

Referenced by isItCalo(), and isItInside().

                                                                         {

  static const std::string unknown("Unknown");
  //Get name and copy numbers
  if (level > 0) {
    for (int ii = 0; ii < level; ii++) {
      int i      = level - ii - 1;
      G4VPhysicalVolume* pv = touch->GetVolume(i);
      if (pv != 0) 
        name[ii] = pv->GetName();
      else
        name[ii] = unknown;
      copyno[ii] = touch->GetReplicaNumber(i);
    }
  }
}
int CaloTrkProcessing::detLevels ( const G4VTouchable *  touch) const [private]

Definition at line 391 of file CaloTrkProcessing.cc.

Referenced by isItCalo(), and isItInside().

                                                                {

  //Return number of levels
  if (touch) 
    return ((touch->GetHistoryDepth())+1);
  else
    return 0;
}
G4LogicalVolume * CaloTrkProcessing::detLV ( const G4VTouchable *  touch,
int  currentlevel 
) const [private]

Definition at line 400 of file CaloTrkProcessing.cc.

References testEve_cfg::level.

Referenced by isItCalo(), and isItInside().

                                                                  {

  G4LogicalVolume* lv=0;
  if (touch) {
    int level = ((touch->GetHistoryDepth())+1);
    if (level > 0 && level >= currentlevel) {
      int ii = level - currentlevel; 
      lv     = touch->GetVolume(ii)->GetLogicalVolume();
      return lv;
    } 
  }
  return lv;
}
virtual void CaloTrkProcessing::EndOfEvent ( G4HCofThisEvent *  ) [inline, virtual]

Reimplemented from SensitiveDetector.

Definition at line 38 of file CaloTrkProcessing.h.

{}
void CaloTrkProcessing::fillHits ( edm::PCaloHitContainer ,
std::string   
) [inline, virtual]

Implements SensitiveCaloDetector.

Definition at line 39 of file CaloTrkProcessing.h.

{}
std::vector< std::string > CaloTrkProcessing::getNames ( G4String  str,
const DDsvalues_type sv 
) [private]

Definition at line 250 of file CaloTrkProcessing.cc.

References DDfetch(), Exception, LogDebug, DDValue::strings(), and relativeConstraints::value.

                                                                              {

#ifdef DebugLog
  LogDebug("CaloSim") << "CaloTrkProcessing::getNames called for " << str;
#endif
  DDValue value(str);
  if (DDfetch(&sv,value)) {
#ifdef DebugLog
    LogDebug("CaloSim") << value;
#endif
    const std::vector<std::string> & fvec = value.strings();
    int nval = fvec.size();
    if (nval < 1) {

        edm::LogError("CaloSim") << "CaloTrkProcessing: # of " << str 
                                 << " bins " << nval << " < 1 ==> illegal ";
        throw cms::Exception("Unknown", "CaloTrkProcessing")
          << "nval < 2 for array " << str << "\n";
    }
    
    return fvec;
  } else {
    edm::LogError("CaloSim") << "CaloTrkProcessing: cannot get array " << str ;
    throw cms::Exception("Unknown", "CaloTrkProcessing")
      << "cannot get array " << str << "\n";
  }
}
std::vector< double > CaloTrkProcessing::getNumbers ( G4String  str,
const DDsvalues_type sv 
) [private]

Definition at line 279 of file CaloTrkProcessing.cc.

References DDfetch(), DDValue::doubles(), Exception, LogDebug, and relativeConstraints::value.

Referenced by CaloTrkProcessing().

                                                                            {

#ifdef DebugLog
  LogDebug("CaloSim") << "CaloTrkProcessing::getNumbers called for " << str;
#endif
  DDValue value(str);
  if (DDfetch(&sv,value)) {
#ifdef DebugLog
    LogDebug("CaloSim") << value;
#endif
    const std::vector<double> & fvec = value.doubles();
    int nval = fvec.size();
    if (nval < 1) {
        edm::LogError("CaloSim") << "CaloTrkProcessing: # of " << str 
                                 << " bins " << nval << " < 1 ==> illegal ";
        throw cms::Exception("Unknown", "CaloTrkProcessing")
          << "nval < 2 for array " << str << "\n";
    }
    
    return fvec;
  } else {
    edm::LogError("CaloSim") << "CaloTrkProcessing: cannot get array " << str ;
    throw cms::Exception("Unknown", "CaloTrkProcessing")
      << "cannot get array " << str << "\n";
  }
}
virtual void CaloTrkProcessing::Initialize ( G4HCofThisEvent *  ) [inline, virtual]

Reimplemented from SensitiveDetector.

Definition at line 32 of file CaloTrkProcessing.h.

{}
int CaloTrkProcessing::isItCalo ( const G4VTouchable *  touch) [private]

Definition at line 307 of file CaloTrkProcessing.cc.

References detectorLevel(), detectors, detLevels(), detLV(), testEve_cfg::level, LogDebug, and convertSQLiteXML::ok.

Referenced by update().

                                                         {

  int lastLevel = -1;
  G4LogicalVolume* lv=0;
  for (unsigned int it=0; it < detectors.size(); it++) {
    if (lastLevel != detectors[it].level) {
      lastLevel = detectors[it].level;
      lv        = detLV(touch, lastLevel);
#ifdef DebugLog
      std::string  name1 = "Unknown";
      if (lv != 0) name1 = lv->GetName(); 
      LogDebug("CaloSim") << "CaloTrkProcessing: volume " << name1
                          << " at Level " << lastLevel;
      int levels = detLevels(touch);
      if (levels > 0) {
        G4String name2[20]; int copyno2[20];
        detectorLevel(touch, levels, copyno2, name2);
        for (int i2=0; i2<levels; i2++) 
          LogDebug("CaloSim") << " " << i2 << " " << name2[i2] << " " 
                              << copyno2[i2];
      }
#endif
    }
    bool ok = (lv   == detectors[it].lv);
    if (ok) return it;
  }
  return -1;
}
int CaloTrkProcessing::isItInside ( const G4VTouchable *  touch,
int  idcal,
int  idin 
) [private]

Definition at line 336 of file CaloTrkProcessing.cc.

References detectorLevel(), detectors, detLevels(), detLV(), LogDebug, and convertSQLiteXML::ok.

Referenced by update().

                                            {
  int lastLevel = -1;
  G4LogicalVolume* lv=0;
  int id1, id2;
  if (idcal < 0) {id1 = 0; id2 = static_cast<int>(detectors.size());}
  else           {id1 = idcal; id2 = id1+1;}
  for (int it1 = id1; it1 < id2; it1++) {
    if (idin < 0) {
      for (unsigned int it2 = 0; it2 < detectors[it1].fromDets.size(); it2++) {
        if (lastLevel != detectors[it1].fromLevels[it2]) {
          lastLevel = detectors[it1].fromLevels[it2];
          lv        = detLV(touch,lastLevel);
#ifdef DebugLog
          std::string  name1 = "Unknown";
          if (lv != 0) name1 = lv->GetName(); 
          LogDebug("CaloSim") << "CaloTrkProcessing: volume " << name1
                              << " at Level " << lastLevel;
          int levels = detLevels(touch);
          if (levels > 0) {
            G4String name2[20]; int copyno2[20];
            detectorLevel(touch, levels, copyno2, name2);
            for (int i2=0; i2<levels; i2++) 
              LogDebug("CaloSim") << " " << i2 << " " << name2[i2] << " " 
                                  << copyno2[i2];
          }
#endif
        }
        bool ok = (lv   == detectors[it1].fromDetL[it2]);
        if (ok) return it2;
      }
    } else {
      lastLevel = detectors[it1].fromLevels[idin];
      lv        = detLV(touch,lastLevel);
#ifdef DebugLog
      std::string  name1 = "Unknown";
      if (lv != 0) name1 = lv->GetName(); 
      LogDebug("CaloSim") << "CaloTrkProcessing: volume " << name1
                          << " at Level " << lastLevel;
      int levels = detLevels(touch);
      if (levels > 0) {
        G4String name2[20]; int copyno2[20];
        detectorLevel(touch, levels, copyno2, name2);
        for (int i2=0; i2<levels; i2++) 
          LogDebug("CaloSim") << " " << i2 << " " << name2[i2] << " " 
                              << copyno2[i2];
      }
#endif
      bool ok = (lv   == detectors[it1].fromDetL[idin]);
      if (ok) return idin;
    }
  }
  return -1;
}
virtual bool CaloTrkProcessing::ProcessHits ( G4Step *  ,
G4TouchableHistory *   
) [inline, virtual]

Implements SensitiveDetector.

Definition at line 34 of file CaloTrkProcessing.h.

                                                                         {
    return true;
  }
virtual uint32_t CaloTrkProcessing::setDetUnitId ( G4Step *  step) [inline, virtual]

Implements SensitiveDetector.

Definition at line 37 of file CaloTrkProcessing.h.

{return 0;}
void CaloTrkProcessing::update ( const BeginOfEvent ) [private, virtual]

This routine will be called when the appropriate signal arrives.

Implements Observer< const BeginOfEvent * >.

Definition at line 166 of file CaloTrkProcessing.cc.

References lastTrackID.

                                                       {
  lastTrackID = -1;
}
void CaloTrkProcessing::update ( const G4Step *  ) [private, virtual]

This routine will be called when the appropriate signal arrives.

Implements Observer< const G4Step * >.

Definition at line 170 of file CaloTrkProcessing.cc.

References TrackInformation::caloIDChecked(), eMin, Exception, TrackInformation::getIDCaloVolume(), TrackInformation::getIDLastVolume(), TrackInformation::getIDonCaloSurface(), isItCalo(), isItInside(), lastTrackID, LogDebug, putHistory, TrackInformation::putInHistory(), TrackInformation::setCaloIDChecked(), TrackInformation::setIDonCaloSurface(), and testBeam.

                                                   {
  
  // define if you are at the surface of CALO  
  
  G4Track* theTrack = aStep->GetTrack();   
  int      id       = theTrack->GetTrackID();

  TrackInformation* trkInfo = dynamic_cast<TrackInformation*>
    (theTrack->GetUserInformation());
  
  if (trkInfo == 0) {
    edm::LogError("CaloSim") << "CaloTrkProcessing: No trk info !!!! abort ";
    throw cms::Exception("Unknown", "CaloTrkProcessing")
      << "cannot get trkInfo for Track " << id << "\n";
  }
  
  if (testBeam) {
    if (trkInfo->getIDonCaloSurface() == 0) {
#ifdef DebugLog
      LogDebug("CaloSim") << "CaloTrkProcessing set IDonCaloSurface to " << id 
                          << " at step Number "
                          << theTrack->GetCurrentStepNumber();
#endif
      trkInfo->setIDonCaloSurface(id,0,0,
                                  theTrack->GetDefinition()->GetPDGEncoding(),
                                  theTrack->GetMomentum().mag());
      lastTrackID = id;
      if (theTrack->GetKineticEnergy()/MeV > eMin)
        trkInfo->putInHistory();
    } 
  } else {
    if (putHistory) {
      trkInfo->putInHistory();
      //      trkInfo->setAncestor();
    }
#ifdef DebugLog
    LogDebug("CaloSim") << "CaloTrkProcessing Entered for " << id 
                        << " at stepNumber "<< theTrack->GetCurrentStepNumber()
                        << " IDonCaloSur.. " << trkInfo->getIDonCaloSurface()
                        << " CaloCheck " << trkInfo->caloIDChecked();
#endif
    if (trkInfo->getIDonCaloSurface() != 0) {
      if (trkInfo->caloIDChecked() == false) {
        G4StepPoint*        postStepPoint = aStep->GetPostStepPoint();   
        const G4VTouchable* post_touch    = postStepPoint->GetTouchable();

        if (isItInside(post_touch, trkInfo->getIDCaloVolume(),
                       trkInfo->getIDLastVolume()) > 0) {
          trkInfo->setIDonCaloSurface(0, -1, -1, 0, 0);
        } else {
          trkInfo->setCaloIDChecked(true);
        }
      }
    } else {
      G4StepPoint*        postStepPoint = aStep->GetPostStepPoint();   
      const G4VTouchable* post_touch    = postStepPoint->GetTouchable();
      int                 ical          = isItCalo(post_touch);
      if (ical >= 0) {
        G4StepPoint*        preStepPoint = aStep->GetPreStepPoint(); 
        const G4VTouchable* pre_touch    = preStepPoint->GetTouchable();
        int                 inside       = isItInside(pre_touch, ical, -1);
        if (inside >= 0 ||  (theTrack->GetCurrentStepNumber()==1)) {
          trkInfo->setIDonCaloSurface(id,ical,inside,
                                      theTrack->GetDefinition()->GetPDGEncoding(),
                                      theTrack->GetMomentum().mag());
          trkInfo->setCaloIDChecked(true);
          lastTrackID = id;
          if (theTrack->GetKineticEnergy()/MeV > eMin) trkInfo->putInHistory();
#ifdef DebugLog
          LogDebug("CaloSim") <<"CaloTrkProcessing: set ID on Calo " << ical
                              << " surface (Inside " << inside << ") to " 
                              << id << " of a Track with Kinetic Energy " 
                              << theTrack->GetKineticEnergy()/MeV << " MeV";
#endif
        }
      }
    }
  }
}

Member Data Documentation

std::vector<Detector> CaloTrkProcessing::detectors [private]

Definition at line 70 of file CaloTrkProcessing.h.

Referenced by CaloTrkProcessing(), isItCalo(), and isItInside().

double CaloTrkProcessing::eMin [private]

Definition at line 68 of file CaloTrkProcessing.h.

Referenced by CaloTrkProcessing(), and update().

Definition at line 69 of file CaloTrkProcessing.h.

Referenced by update().

Definition at line 71 of file CaloTrkProcessing.h.

Definition at line 67 of file CaloTrkProcessing.h.

Referenced by CaloTrkProcessing(), and update().

Definition at line 67 of file CaloTrkProcessing.h.

Referenced by CaloTrkProcessing(), and update().