CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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::EDProducer 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::EDProducer
 EDProducer ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducer ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (const std::string &iProcessName, std::vector< const char * > &oModuleLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

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::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
- 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::EDProducer
typedef EDProducer ModuleType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Static Public Member Functions inherited from edm::EDProducer
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 27 of file SubsystemNeutronWriter.cc.

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

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

destructor prints statistics on number of events written

Definition at line 72 of file SubsystemNeutronWriter.cc.

References printStats(), and theHitWriter.

73 {
74  printStats();
75  delete theHitWriter;
76 }

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 182 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().

182  {
183  unsigned int detId = useLocalDetId_ ? localDetId(h.detUnitId()) : h.detUnitId();
184  float htime = h.timeOfFlight() + timeOffset + smearing;
185  // prevent float precision loss
186  if (h.timeOfFlight() > 1.E+6) {
187  htime = smearing;
188  }
189  h = PSimHit( h.entryPoint(), h.exitPoint(), h.pabs(), htime,
190  h.energyLoss(), h.particleType(),
191  detId, h.trackId(),
192  h.momentumAtEntry().theta(),
193  h.momentumAtEntry().phi() );
194 }
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
virtual int localDetId(int globalDetId) const =0
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
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 122 of file SubsystemNeutronWriter.cc.

References NeutronWriter::initialize(), and theHitWriter.

Referenced by CSCNeutronWriter::CSCNeutronWriter().

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

Implemented in CSCNeutronWriter, RPCNeutronWriter, and DTNeutronWriter.

Referenced by adjust().

void SubsystemNeutronWriter::printStats ( )

Definition at line 80 of file SubsystemNeutronWriter.cc.

References theCountPerChamberType, and theNEvents.

Referenced by ~SubsystemNeutronWriter().

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

Implements edm::EDProducer.

Definition at line 90 of file SubsystemNeutronWriter.cc.

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

91 {
92  CLHEP::HepRandomEngine* engine = nullptr;
93  if(useRandFlat) {
95  engine = &rng->getEngine(e.streamID());
96  }
98  ++theNEvents;
100  e.getByLabel(theInputTag, hits);
101 
102  // sort hits by chamber
103  map<int, edm::PSimHitContainer> hitsByChamber;
104  for(edm::PSimHitContainer::const_iterator hitItr = hits->begin();
105  hitItr != hits->end(); ++hitItr)
106  {
107  int chamberIndex = chamberId(hitItr->detUnitId());
108  hitsByChamber[chamberIndex].push_back(*hitItr);
109  }
110 
111  // now write out each chamber's contents
112  for(map<int, edm::PSimHitContainer>::iterator hitsByChamberItr = hitsByChamber.begin();
113  hitsByChamberItr != hitsByChamber.end(); ++hitsByChamberItr)
114  {
115  int chambertype = chamberType(hitsByChamberItr->first);
116  writeHits(chambertype, hitsByChamberItr->second, engine);
117  }
119 }
virtual int chamberType(int globalDetId) const =0
virtual void beginEvent(edm::Event &e, const edm::EventSetup &es)
Definition: NeutronWriter.h:20
virtual int chamberId(int globalDetId) const =0
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:405
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &) const =0
Use this engine in event methods.
StreamID streamID() const
Definition: Event.h:72
void SubsystemNeutronWriter::updateCount ( int  chamberType)
protected

updates the counter

Definition at line 197 of file SubsystemNeutronWriter.cc.

References theCountPerChamberType.

Referenced by writeCluster().

197  {
198  map<int,int>::iterator entry = theCountPerChamberType.find(chamberType);
199  if(entry == theCountPerChamberType.end()) {
200  theCountPerChamberType.insert( pair<int,int>(chamberType, 1) );
201  } else {
202  ++(entry->second);
203  }
204 }
virtual int chamberType(int globalDetId) const =0
std::map< int, int > theCountPerChamberType
void SubsystemNeutronWriter::writeCluster ( int  chamberType,
const edm::PSimHitContainer cluster 
)
protected

Definition at line 172 of file SubsystemNeutronWriter.cc.

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

Referenced by writeHits().

173 {
174  if(accept(cluster))
175  {
178  }
179 }
virtual int chamberType(int globalDetId) const =0
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
void SubsystemNeutronWriter::writeHits ( int  chamberType,
edm::PSimHitContainer chamberHits,
CLHEP::HepRandomEngine *  engine 
)
protectedvirtual

Definition at line 130 of file SubsystemNeutronWriter.cc.

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

Referenced by produce().

132 {
133 
134  sort(chamberHits.begin(), chamberHits.end(), SortByTime());
135  edm::PSimHitContainer cluster;
136  float startTime = -1000.;
137  float smearing = 0.;
138  for(size_t i = 0; i < chamberHits.size(); ++i) {
139  PSimHit hit = chamberHits[i];
140  float tof = hit.tof();
141  LogDebug("SubsystemNeutronWriter") << "found hit from part type " << hit.particleType()
142  << " at tof " << tof << " p " << hit.pabs()
143  << " on det " << hit.detUnitId()
144  << " chamber type " << chamberType;
145  if(tof > theNeutronTimeCut) {
146  if(tof > (startTime + theTimeWindow) ) { // 1st in cluster
147  startTime = tof;
148  // set the time to be [t0, t0+25] at start of event
149  smearing = theT0;
150  if(useRandFlat) {
151  smearing += CLHEP::RandFlat::shoot(engine, 25.);
152  }
153  if(!cluster.empty()) {
154  LogDebug("SubsystemNeutronWriter") << "filling old cluster";
155  writeCluster(chamberType, cluster);
156  cluster.clear();
157  }
158  LogDebug("SubsystemNeutronWriter") << "starting neutron cluster at time " << startTime
159  << " on detType " << chamberType;
160  }
161  adjust(hit, -1.*startTime, smearing);
162  cluster.push_back( hit );
163  }
164  }
165  // get any leftover cluster
166  if(!cluster.empty()) {
167  writeCluster(chamberType, cluster);
168  }
169 }
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
float tof() const
deprecated name for timeOfFlight()
Definition: PSimHit.h:72
virtual int chamberType(int globalDetId) const =0
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
unsigned int detUnitId() const
Definition: PSimHit.h:93

Member Data Documentation

bool SubsystemNeutronWriter::initialized
private

Definition at line 74 of file SubsystemNeutronWriter.h.

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

Definition at line 77 of file SubsystemNeutronWriter.h.

Referenced by printStats(), and updateCount().

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

Definition at line 69 of file SubsystemNeutronWriter.h.

Referenced by produce().

double SubsystemNeutronWriter::theNeutronTimeCut
private

Definition at line 70 of file SubsystemNeutronWriter.h.

Referenced by writeHits().

int SubsystemNeutronWriter::theNEvents
private

Definition at line 73 of file SubsystemNeutronWriter.h.

Referenced by printStats(), and produce().

double SubsystemNeutronWriter::theT0
private

Definition at line 72 of file SubsystemNeutronWriter.h.

Referenced by writeHits().

double SubsystemNeutronWriter::theTimeWindow
private

Definition at line 71 of file SubsystemNeutronWriter.h.

Referenced by writeHits().

bool SubsystemNeutronWriter::useLocalDetId_
private

Definition at line 76 of file SubsystemNeutronWriter.h.

Referenced by adjust(), and SubsystemNeutronWriter().

bool SubsystemNeutronWriter::useRandFlat
private

Definition at line 68 of file SubsystemNeutronWriter.h.

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