CMS 3D CMS Logo

Public Member Functions | Protected Member Functions | Private Attributes

SubsystemNeutronWriter Class Reference

doesn't have to be a producer. Can act as an analyzer, too. More...

#include <SubsystemNeutronWriter.h>

Inheritance diagram for SubsystemNeutronWriter:
edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper CSCNeutronWriter DTNeutronWriter RPCNeutronWriter

List of all members.

Public Member Functions

virtual bool accept (const edm::PSimHitContainer &cluster) const =0
 decides whether this cluster is good enough to be included
virtual int chamberId (int globalDetId) const =0
virtual int chamberType (int globalDetId) const =0
void initialize (int chamberType)
 good practice to do once for each chamber type
virtual int localDetId (int globalDetId) const =0
void printStats ()
virtual void produce (edm::Event &e, edm::EventSetup const &c)
 SubsystemNeutronWriter (edm::ParameterSet const &pset)
virtual ~SubsystemNeutronWriter ()
 destructor prints statistics on number of events written

Protected Member Functions

void adjust (PSimHit &h, float timeOffset, float smearing)
 helper to add time offsets and local det ID
void updateCount (int chamberType)
 updates the counter
void writeCluster (int chamberType, const edm::PSimHitContainer &cluster)
virtual void writeHits (int chamberType, edm::PSimHitContainer &chamberHits)

Private Attributes

bool initialized
std::map< int, int > theCountPerChamberType
NeutronWritertheHitWriter
edm::InputTag theInputTag
double theNeutronTimeCut
int theNEvents
CLHEP::RandFlat * theRandFlat
double theT0
double theTimeWindow
bool useLocalDetId_

Detailed Description

doesn't have to be a producer. Can act as an analyzer, too.

Definition at line 26 of file SubsystemNeutronWriter.h.


Constructor & Destructor Documentation

SubsystemNeutronWriter::SubsystemNeutronWriter ( edm::ParameterSet const &  pset) [explicit]

Definition at line 26 of file SubsystemNeutronWriter.cc.

References Exception, edm::ParameterSet::getParameter(), edm::Service< T >::isAvailable(), convertSQLitetoXML_cfg::output, theHitWriter, theRandFlat, and useLocalDetId_.

: theHitWriter(0),
  theRandFlat(0),
  theInputTag(pset.getParameter<edm::InputTag>("input")),
  theNeutronTimeCut(pset.getParameter<double>("neutronTimeCut")),
  theTimeWindow(pset.getParameter<double>("timeWindow")),
  theT0(pset.getParameter<double>("t0")),
  theNEvents(0),
  initialized(false),
  useLocalDetId_(true)
{
  string writer = pset.getParameter<string>("writer");
  string output = pset.getParameter<string>("output");
  if(writer == "ASCII")
  {
    theHitWriter = new AsciiNeutronWriter(output);
  }
  else if (writer == "ROOT")
  {
    theHitWriter = new RootNeutronWriter(output);
  }
  else if (writer == "EDM")
  {
    produces<edm::PSimHitContainer>();
    theHitWriter = new EDMNeutronWriter();
    // write out the real DetId, not the local one
    useLocalDetId_ = false;
    // smear the times
    edm::Service<edm::RandomNumberGenerator> rng;
    if ( ! rng.isAvailable()) {
     throw cms::Exception("Configuration")
       << "SubsystemNeutronWriter requires the RandomNumberGeneratorService\n"
          "which is not present in the configuration file.  You must add the service\n"
          "in the configuration file or remove the modules that require it.";
    }
    CLHEP::HepRandomEngine& engine = rng->getEngine();
    theRandFlat = new CLHEP::RandFlat(engine);
  }
  else 
  {
    throw cms::Exception("NeutronWriter") << "Bad writer: "
      << writer;
  } 
}
SubsystemNeutronWriter::~SubsystemNeutronWriter ( ) [virtual]

destructor prints statistics on number of events written

Definition at line 72 of file SubsystemNeutronWriter.cc.

References printStats(), theHitWriter, and theRandFlat.

{
  printStats();
  delete theHitWriter;
  delete theRandFlat;
}

Member Function Documentation

virtual bool SubsystemNeutronWriter::accept ( const edm::PSimHitContainer cluster) const [pure virtual]

decides whether this cluster is good enough to be included

Implemented in CSCNeutronWriter, DTNeutronWriter, and RPCNeutronWriter.

Referenced by writeCluster().

void SubsystemNeutronWriter::adjust ( PSimHit h,
float  timeOffset,
float  smearing 
) [protected]

helper to add time offsets and local det ID

Definition at line 177 of file SubsystemNeutronWriter.cc.

References PSimHit::detUnitId(), PSimHit::energyLoss(), PSimHit::entryPoint(), PSimHit::exitPoint(), localDetId(), PSimHit::momentumAtEntry(), PSimHit::pabs(), PSimHit::particleType(), PV3DBase< T, PVType, FrameType >::phi(), PV3DBase< T, PVType, FrameType >::theta(), PSimHit::timeOfFlight(), PSimHit::trackId(), and useLocalDetId_.

Referenced by writeHits().

                                                                                 {
  unsigned int detId = useLocalDetId_ ? localDetId(h.detUnitId()) : h.detUnitId();
  float htime = h.timeOfFlight() + timeOffset + smearing;
  // prevent float precision loss
  if (h.timeOfFlight() > 1.E+6) {
    htime = smearing;
  }
  h = PSimHit( h.entryPoint(), h.exitPoint(), h.pabs(), htime,
               h.energyLoss(), h.particleType(), 
               detId, h.trackId(),
               h.momentumAtEntry().theta(),
               h.momentumAtEntry().phi() );
}
virtual int SubsystemNeutronWriter::chamberId ( int  globalDetId) const [pure virtual]

Implemented in CSCNeutronWriter, DTNeutronWriter, and RPCNeutronWriter.

Referenced by produce().

virtual int SubsystemNeutronWriter::chamberType ( int  globalDetId) const [pure virtual]

Implemented in CSCNeutronWriter, DTNeutronWriter, and RPCNeutronWriter.

Referenced by produce(), and writeHits().

void SubsystemNeutronWriter::initialize ( int  chamberType)

good practice to do once for each chamber type

Definition at line 118 of file SubsystemNeutronWriter.cc.

References NeutronWriter::initialize(), and theHitWriter.

Referenced by CSCNeutronWriter::CSCNeutronWriter().

{
  // should instantiate one of every chamber type, just so
  // ROOT knows what file to associate them with
  theHitWriter->initialize(chamberType);
}
virtual int SubsystemNeutronWriter::localDetId ( int  globalDetId) const [pure virtual]

Implemented in CSCNeutronWriter, DTNeutronWriter, and RPCNeutronWriter.

Referenced by adjust().

void SubsystemNeutronWriter::printStats ( )

Definition at line 81 of file SubsystemNeutronWriter.cc.

References theCountPerChamberType, and theNEvents.

Referenced by ~SubsystemNeutronWriter().

                                        {
  edm::LogInfo("SubsystemNeutronWriter") << "SubsystemNeutronWriter Statistics:\n";
  for(map<int,int>::iterator mapItr = theCountPerChamberType.begin();
      mapItr != theCountPerChamberType.end();  ++mapItr) {
     edm::LogInfo("SubsystemNeutronWriter") << "   theEventOccupancy[" << mapItr->first << "] = "
         << mapItr->second << " / " << theNEvents << " / NCT \n";
  }
}
void SubsystemNeutronWriter::produce ( edm::Event e,
edm::EventSetup const &  c 
) [virtual]

Implements edm::EDProducer.

Definition at line 91 of file SubsystemNeutronWriter.cc.

References NeutronWriter::beginEvent(), chamberId(), chamberType(), NeutronWriter::endEvent(), edm::Event::getByLabel(), theHitWriter, theInputTag, theNEvents, and writeHits().

{
  theHitWriter->beginEvent(e,c);
  ++theNEvents;
  edm::Handle<edm::PSimHitContainer> hits;
  e.getByLabel(theInputTag, hits);

  // sort hits by chamber
  map<int, edm::PSimHitContainer> hitsByChamber;
  for(edm::PSimHitContainer::const_iterator hitItr = hits->begin();
      hitItr != hits->end(); ++hitItr)
  {
    int chamberIndex = chamberId(hitItr->detUnitId());
    hitsByChamber[chamberIndex].push_back(*hitItr);
  }

  // now write out each chamber's contents
  for(map<int, edm::PSimHitContainer>::iterator hitsByChamberItr = hitsByChamber.begin();
      hitsByChamberItr != hitsByChamber.end(); ++hitsByChamberItr)
  {
    int chambertype = chamberType(hitsByChamberItr->first);
    writeHits(chambertype, hitsByChamberItr->second);
  }
  theHitWriter->endEvent();
}
void SubsystemNeutronWriter::updateCount ( int  chamberType) [protected]

updates the counter

Definition at line 192 of file SubsystemNeutronWriter.cc.

References theCountPerChamberType.

Referenced by writeCluster().

                                                        {
  map<int,int>::iterator entry = theCountPerChamberType.find(chamberType);
  if(entry == theCountPerChamberType.end()) {
    theCountPerChamberType.insert( pair<int,int>(chamberType, 1) );
  } else {
    ++(entry->second);
  }
}
void SubsystemNeutronWriter::writeCluster ( int  chamberType,
const edm::PSimHitContainer cluster 
) [protected]

Definition at line 167 of file SubsystemNeutronWriter.cc.

References accept(), theHitWriter, updateCount(), and NeutronWriter::writeCluster().

Referenced by writeHits().

void SubsystemNeutronWriter::writeHits ( int  chamberType,
edm::PSimHitContainer chamberHits 
) [protected, virtual]

Definition at line 126 of file SubsystemNeutronWriter.cc.

References adjust(), chamberType(), PSimHit::detUnitId(), i, LogDebug, PSimHit::pabs(), PSimHit::particleType(), python::multivaluedict::sort(), theNeutronTimeCut, theRandFlat, theT0, theTimeWindow, PSimHit::tof(), and writeCluster().

Referenced by produce().

{

  sort(chamberHits.begin(), chamberHits.end(), SortByTime());
  edm::PSimHitContainer cluster;
  float startTime = -1000.;
  float smearing = 0.;
  for(size_t i = 0; i < chamberHits.size(); ++i) {
    PSimHit hit = chamberHits[i];
    float tof = hit.tof();
    LogDebug("SubsystemNeutronWriter") << "found hit from part type " << hit.particleType()
                   << " at tof " << tof << " p " << hit.pabs() 
                   << " on det " << hit.detUnitId() 
                   << " chamber type " << chamberType;
    if(tof > theNeutronTimeCut) {
      if(tof > (startTime + theTimeWindow) ) { // 1st in cluster
        startTime = tof;
        // set the time to be [t0, t0+25] at start of event
        smearing = theT0;
        if(theRandFlat) {
          smearing += theRandFlat->fire(25.);
        }
        if(!cluster.empty()) {
          LogDebug("SubsystemNeutronWriter") << "filling old cluster";
          writeCluster(chamberType, cluster);
          cluster.clear();
        }
        LogDebug("SubsystemNeutronWriter") << "starting neutron cluster at time " << startTime 
          << " on detType " << chamberType;
      }
      adjust(hit, -1.*startTime, smearing);
      cluster.push_back( hit );
    }
  }
  // get any leftover cluster
  if(!cluster.empty()) {
    writeCluster(chamberType, cluster);
  }
}

Member Data Documentation

Definition at line 72 of file SubsystemNeutronWriter.h.

std::map<int, int> SubsystemNeutronWriter::theCountPerChamberType [private]

Definition at line 75 of file SubsystemNeutronWriter.h.

Referenced by printStats(), and updateCount().

Definition at line 67 of file SubsystemNeutronWriter.h.

Referenced by produce().

Definition at line 68 of file SubsystemNeutronWriter.h.

Referenced by writeHits().

Definition at line 71 of file SubsystemNeutronWriter.h.

Referenced by printStats(), and produce().

CLHEP::RandFlat* SubsystemNeutronWriter::theRandFlat [private]

Definition at line 70 of file SubsystemNeutronWriter.h.

Referenced by writeHits().

Definition at line 69 of file SubsystemNeutronWriter.h.

Referenced by writeHits().

Definition at line 74 of file SubsystemNeutronWriter.h.

Referenced by adjust(), and SubsystemNeutronWriter().