CMS 3D CMS Logo

List of all members | Public Member Functions | Protected Member Functions | Private Attributes
SubsystemNeutronWriter Class Referenceabstract

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

#include <SubsystemNeutronWriter.h>

Inheritance diagram for SubsystemNeutronWriter:
edm::stream::EDProducer<> edm::stream::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper CSCNeutronWriter DTNeutronWriter RPCNeutronWriter

Public Member Functions

virtual bool accept (const edm::PSimHitContainer &cluster) const =0
 decides whether this cluster is good enough to be included More...
 
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 More...
 
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 More...
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
- Public Member Functions inherited from edm::stream::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducerBase ()
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, std::unordered_multimap< std::string, edm::ProductResolverIndex > const &iIndicies, std::string const &moduleLabel)
 
virtual ~ProducerBase () noexcept(false)
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Protected Member Functions

void adjust (PSimHit &h, float timeOffset, float smearing)
 helper to add time offsets and local det ID More...
 
void updateCount (int chamberType)
 updates the counter More...
 
void writeCluster (int chamberType, const edm::PSimHitContainer &cluster)
 
virtual void writeHits (int chamberType, edm::PSimHitContainer &chamberHits, CLHEP::HepRandomEngine *)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Private Attributes

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

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 
- Public Types inherited from edm::stream::EDProducerBase
typedef EDProducerAdaptorBase ModuleType
 
- Public Types inherited from edm::ProducerBase
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::stream::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Detailed Description

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

Definition at line 28 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, useLocalDetId_, useRandFlat, and cscNeutronWriter_cfi::writer.

27 : theHitWriter(0),
28  useRandFlat(false),
29  theInputTag(pset.getParameter<edm::InputTag>("input")),
30  theNeutronTimeCut(pset.getParameter<double>("neutronTimeCut")),
31  theTimeWindow(pset.getParameter<double>("timeWindow")),
32  theT0(pset.getParameter<double>("t0")),
33  theNEvents(0),
34  initialized(false),
35  useLocalDetId_(true)
36 {
37  string writer = pset.getParameter<string>("writer");
38  string output = pset.getParameter<string>("output");
39  if(writer == "ASCII")
40  {
41  theHitWriter = new AsciiNeutronWriter(output);
42  }
43  else if (writer == "ROOT")
44  {
45  theHitWriter = new RootNeutronWriter(output);
46  }
47  else if (writer == "EDM")
48  {
49  produces<edm::PSimHitContainer>();
51  // write out the real DetId, not the local one
52  useLocalDetId_ = false;
53  // smear the times
55  if ( ! rng.isAvailable()) {
56  throw cms::Exception("Configuration")
57  << "SubsystemNeutronWriter requires the RandomNumberGeneratorService\n"
58  "which is not present in the configuration file. You must add the service\n"
59  "in the configuration file or remove the modules that require it.";
60  }
61  useRandFlat = true;
62  }
63  else
64  {
65  throw cms::Exception("NeutronWriter") << "Bad writer: "
66  << writer;
67  }
68 }
bool isAvailable() const
Definition: Service.h:46
SubsystemNeutronWriter::~SubsystemNeutronWriter ( )
virtual

destructor prints statistics on number of events written

Definition at line 70 of file SubsystemNeutronWriter.cc.

References printStats(), and theHitWriter.

71 {
72  printStats();
73  delete theHitWriter;
74 }

Member Function Documentation

virtual bool SubsystemNeutronWriter::accept ( const edm::PSimHitContainer cluster) const
pure virtual
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().

177  {
178  unsigned int detId = useLocalDetId_ ? localDetId(h.detUnitId()) : h.detUnitId();
179  float htime = h.timeOfFlight() + timeOffset + smearing;
180  // prevent float precision loss
181  if (h.timeOfFlight() > 1.E+6) {
182  htime = smearing;
183  }
184  h = PSimHit( h.entryPoint(), h.exitPoint(), h.pabs(), htime,
185  h.energyLoss(), h.particleType(),
186  detId, h.trackId(),
187  h.momentumAtEntry().theta(),
188  h.momentumAtEntry().phi() );
189 }
LocalVector momentumAtEntry() const
The momentum of the track that produced the hit, at entry point.
Definition: PSimHit.h:47
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
Geom::Theta< T > theta() const
Definition: PV3DBase.h:75
Local3DPoint exitPoint() const
Exit point in the local Det frame.
Definition: PSimHit.h:38
float timeOfFlight() const
Definition: PSimHit.h:69
float pabs() const
fast and more accurate access to momentumAtEntry().mag()
Definition: PSimHit.h:63
float energyLoss() const
The energy deposit in the PSimHit, in ???.
Definition: PSimHit.h:75
int particleType() const
Definition: PSimHit.h:85
unsigned int trackId() const
Definition: PSimHit.h:102
Local3DPoint entryPoint() const
Entry point in the local Det frame.
Definition: PSimHit.h:35
virtual int localDetId(int globalDetId) const =0
unsigned int detUnitId() const
Definition: PSimHit.h:93
virtual int SubsystemNeutronWriter::chamberId ( int  globalDetId) const
pure virtual

Implemented in CSCNeutronWriter, RPCNeutronWriter, and DTNeutronWriter.

Referenced by produce().

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

Implemented in CSCNeutronWriter, RPCNeutronWriter, and DTNeutronWriter.

Referenced by produce(), and writeHits().

void SubsystemNeutronWriter::initialize ( int  chamberType)

good practice to do once for each chamber type

Definition at line 117 of file SubsystemNeutronWriter.cc.

References NeutronWriter::initialize(), and theHitWriter.

Referenced by CSCNeutronWriter::CSCNeutronWriter().

118 {
119  // should instantiate one of every chamber type, just so
120  // ROOT knows what file to associate them with
122 }
virtual void initialize(int detType)
Definition: NeutronWriter.h:19
virtual int chamberType(int globalDetId) const =0
virtual int SubsystemNeutronWriter::localDetId ( int  globalDetId) const
pure virtual

Implemented in CSCNeutronWriter, RPCNeutronWriter, and DTNeutronWriter.

Referenced by adjust().

void SubsystemNeutronWriter::printStats ( )

Definition at line 76 of file SubsystemNeutronWriter.cc.

References theCountPerChamberType, and theNEvents.

Referenced by ~SubsystemNeutronWriter().

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

Implements edm::stream::EDProducerBase.

Definition at line 85 of file SubsystemNeutronWriter.cc.

References NeutronWriter::beginEvent(), chamberId(), chamberType(), NeutronWriter::endEvent(), edm::Event::getByLabel(), edm::RandomNumberGenerator::getEngine(), hfClusterShapes_cfi::hits, edm::Event::streamID(), theHitWriter, theInputTag, theNEvents, useRandFlat, and writeHits().

86 {
87  CLHEP::HepRandomEngine* engine = nullptr;
88  if(useRandFlat) {
90  engine = &rng->getEngine(e.streamID());
91  }
93  ++theNEvents;
95  e.getByLabel(theInputTag, hits);
96 
97  // sort hits by chamber
98  map<int, edm::PSimHitContainer> hitsByChamber;
99  for(edm::PSimHitContainer::const_iterator hitItr = hits->begin();
100  hitItr != hits->end(); ++hitItr)
101  {
102  int chamberIndex = chamberId(hitItr->detUnitId());
103  hitsByChamber[chamberIndex].push_back(*hitItr);
104  }
105 
106  // now write out each chamber's contents
107  for(map<int, edm::PSimHitContainer>::iterator hitsByChamberItr = hitsByChamber.begin();
108  hitsByChamberItr != hitsByChamber.end(); ++hitsByChamberItr)
109  {
110  int chambertype = chamberType(hitsByChamberItr->first);
111  writeHits(chambertype, hitsByChamberItr->second, engine);
112  }
114 }
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
virtual void beginEvent(edm::Event &e, const edm::EventSetup &es)
Definition: NeutronWriter.h:20
virtual void endEvent()
Definition: NeutronWriter.h:21
virtual void writeHits(int chamberType, edm::PSimHitContainer &chamberHits, CLHEP::HepRandomEngine *)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:413
virtual int chamberId(int globalDetId) const =0
StreamID streamID() const
Definition: Event.h:81
virtual int chamberType(int globalDetId) const =0
void SubsystemNeutronWriter::updateCount ( int  chamberType)
protected

updates the counter

Definition at line 192 of file SubsystemNeutronWriter.cc.

References mps_splice::entry, and theCountPerChamberType.

Referenced by writeCluster().

192  {
193  map<int,int>::iterator entry = theCountPerChamberType.find(chamberType);
194  if(entry == theCountPerChamberType.end()) {
195  theCountPerChamberType.insert( pair<int,int>(chamberType, 1) );
196  } else {
197  ++(entry->second);
198  }
199 }
std::map< int, int > theCountPerChamberType
virtual int chamberType(int globalDetId) const =0
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().

168 {
169  if(accept(cluster))
170  {
173  }
174 }
virtual bool accept(const edm::PSimHitContainer &cluster) const =0
decides whether this cluster is good enough to be included
virtual void writeCluster(int detType, const edm::PSimHitContainer &simHits)=0
writes out a list of SimHits.
void updateCount(int chamberType)
updates the counter
virtual int chamberType(int globalDetId) const =0
void SubsystemNeutronWriter::writeHits ( int  chamberType,
edm::PSimHitContainer chamberHits,
CLHEP::HepRandomEngine *  engine 
)
protectedvirtual

Definition at line 125 of file SubsystemNeutronWriter.cc.

References adjust(), chamberType(), PSimHit::detUnitId(), mps_fire::i, LogDebug, PSimHit::pabs(), PSimHit::particleType(), theNeutronTimeCut, theT0, theTimeWindow, PSimHit::tof(), useRandFlat, and writeCluster().

Referenced by produce().

127 {
128 
129  sort(chamberHits.begin(), chamberHits.end(), SortByTime());
130  edm::PSimHitContainer cluster;
131  float startTime = -1000.;
132  float smearing = 0.;
133  for(size_t i = 0; i < chamberHits.size(); ++i) {
134  PSimHit hit = chamberHits[i];
135  float tof = hit.tof();
136  LogDebug("SubsystemNeutronWriter") << "found hit from part type " << hit.particleType()
137  << " at tof " << tof << " p " << hit.pabs()
138  << " on det " << hit.detUnitId()
139  << " chamber type " << chamberType;
140  if(tof > theNeutronTimeCut) {
141  if(tof > (startTime + theTimeWindow) ) { // 1st in cluster
142  startTime = tof;
143  // set the time to be [t0, t0+25] at start of event
144  smearing = theT0;
145  if(useRandFlat) {
146  smearing += CLHEP::RandFlat::shoot(engine, 25.);
147  }
148  if(!cluster.empty()) {
149  LogDebug("SubsystemNeutronWriter") << "filling old cluster";
150  writeCluster(chamberType, cluster);
151  cluster.clear();
152  }
153  LogDebug("SubsystemNeutronWriter") << "starting neutron cluster at time " << startTime
154  << " on detType " << chamberType;
155  }
156  adjust(hit, -1.*startTime, smearing);
157  cluster.push_back( hit );
158  }
159  }
160  // get any leftover cluster
161  if(!cluster.empty()) {
162  writeCluster(chamberType, cluster);
163  }
164 }
#define LogDebug(id)
float tof() const
deprecated name for timeOfFlight()
Definition: PSimHit.h:72
void adjust(PSimHit &h, float timeOffset, float smearing)
helper to add time offsets and local det ID
float pabs() const
fast and more accurate access to momentumAtEntry().mag()
Definition: PSimHit.h:63
void writeCluster(int chamberType, const edm::PSimHitContainer &cluster)
int particleType() const
Definition: PSimHit.h:85
std::vector< PSimHit > PSimHitContainer
virtual int chamberType(int globalDetId) const =0
unsigned int detUnitId() const
Definition: PSimHit.h:93

Member Data Documentation

bool SubsystemNeutronWriter::initialized
private

Definition at line 73 of file SubsystemNeutronWriter.h.

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

Definition at line 76 of file SubsystemNeutronWriter.h.

Referenced by printStats(), and updateCount().

NeutronWriter* SubsystemNeutronWriter::theHitWriter
private
edm::InputTag SubsystemNeutronWriter::theInputTag
private

Definition at line 68 of file SubsystemNeutronWriter.h.

Referenced by produce().

double SubsystemNeutronWriter::theNeutronTimeCut
private

Definition at line 69 of file SubsystemNeutronWriter.h.

Referenced by writeHits().

int SubsystemNeutronWriter::theNEvents
private

Definition at line 72 of file SubsystemNeutronWriter.h.

Referenced by printStats(), and produce().

double SubsystemNeutronWriter::theT0
private

Definition at line 71 of file SubsystemNeutronWriter.h.

Referenced by writeHits().

double SubsystemNeutronWriter::theTimeWindow
private

Definition at line 70 of file SubsystemNeutronWriter.h.

Referenced by writeHits().

bool SubsystemNeutronWriter::useLocalDetId_
private

Definition at line 75 of file SubsystemNeutronWriter.h.

Referenced by adjust(), and SubsystemNeutronWriter().

bool SubsystemNeutronWriter::useRandFlat
private

Definition at line 67 of file SubsystemNeutronWriter.h.

Referenced by produce(), SubsystemNeutronWriter(), and writeHits().