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<> 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 ()
 
void produce (edm::Event &e, edm::EventSetup const &c) override
 
 SubsystemNeutronWriter (edm::ParameterSet const &pset)
 
 ~SubsystemNeutronWriter () override
 destructor prints statistics on number of events written More...
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 

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 *)
 

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
 

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::SubsystemNeutronWriter ( edm::ParameterSet const &  pset)
explicit

Definition at line 24 of file SubsystemNeutronWriter.cc.

25  : theHitWriter(nullptr),
26  useRandFlat(false),
27  theInputTag(pset.getParameter<edm::InputTag>("input")),
28  theNeutronTimeCut(pset.getParameter<double>("neutronTimeCut")),
29  theTimeWindow(pset.getParameter<double>("timeWindow")),
30  theT0(pset.getParameter<double>("t0")),
31  theNEvents(0),
32  initialized(false),
33  useLocalDetId_(true) {
34  string writer = pset.getParameter<string>("writer");
35  string output = pset.getParameter<string>("output");
36  if (writer == "ASCII") {
38  } else if (writer == "ROOT") {
40  } else if (writer == "EDM") {
41  produces<edm::PSimHitContainer>();
43  // write out the real DetId, not the local one
44  useLocalDetId_ = false;
45  // smear the times
47  if (!rng.isAvailable()) {
48  throw cms::Exception("Configuration")
49  << "SubsystemNeutronWriter requires the RandomNumberGeneratorService\n"
50  "which is not present in the configuration file. You must add the service\n"
51  "in the configuration file or remove the modules that require it.";
52  }
53  useRandFlat = true;
54  } else {
55  throw cms::Exception("NeutronWriter") << "Bad writer: " << writer;
56  }
57 }

References Exception, edm::Service< T >::isAvailable(), convertSQLitetoXML_cfg::output, muonDTDigis_cfi::pset, theHitWriter, useLocalDetId_, useRandFlat, and cscNeutronWriter_cfi::writer.

◆ ~SubsystemNeutronWriter()

SubsystemNeutronWriter::~SubsystemNeutronWriter ( )
override

destructor prints statistics on number of events written

Definition at line 59 of file SubsystemNeutronWriter.cc.

59  {
60  printStats();
61  delete theHitWriter;
62 }

References printStats(), and theHitWriter.

Member Function Documentation

◆ accept()

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

decides whether this cluster is good enough to be included

Implemented in CSCNeutronWriter, RPCNeutronWriter, and DTNeutronWriter.

Referenced by esMonitoring.FDJsonServer::handle_accept(), and writeCluster().

◆ adjust()

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

helper to add time offsets and local det ID

Definition at line 153 of file SubsystemNeutronWriter.cc.

153  {
154  unsigned int detId = useLocalDetId_ ? localDetId(h.detUnitId()) : h.detUnitId();
155  float htime = h.timeOfFlight() + timeOffset + smearing;
156  // prevent float precision loss
157  if (h.timeOfFlight() > 1.E+6) {
158  htime = smearing;
159  }
160  h = PSimHit(h.entryPoint(),
161  h.exitPoint(),
162  h.pabs(),
163  htime,
164  h.energyLoss(),
165  h.particleType(),
166  detId,
167  h.trackId(),
168  h.momentumAtEntry().theta(),
169  h.momentumAtEntry().phi());
170 }

References localDetId(), CalibratedDigis_cfi::timeOffset, and useLocalDetId_.

Referenced by writeHits().

◆ chamberId()

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

Implemented in CSCNeutronWriter, RPCNeutronWriter, and DTNeutronWriter.

Referenced by produce().

◆ chamberType()

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

◆ initialize()

void SubsystemNeutronWriter::initialize ( int  chamberType)

good practice to do once for each chamber type

Definition at line 101 of file SubsystemNeutronWriter.cc.

101  {
102  // should instantiate one of every chamber type, just so
103  // ROOT knows what file to associate them with
105 }

References chamberType(), NeutronWriter::initialize(), and theHitWriter.

Referenced by CSCNeutronWriter::CSCNeutronWriter().

◆ localDetId()

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

Implemented in CSCNeutronWriter, RPCNeutronWriter, and DTNeutronWriter.

Referenced by adjust().

◆ printStats()

void SubsystemNeutronWriter::printStats ( )

Definition at line 64 of file SubsystemNeutronWriter.cc.

64  {
65  edm::LogInfo("SubsystemNeutronWriter") << "SubsystemNeutronWriter Statistics:\n";
66  for (map<int, int>::iterator mapItr = theCountPerChamberType.begin(); mapItr != theCountPerChamberType.end();
67  ++mapItr) {
68  edm::LogInfo("SubsystemNeutronWriter")
69  << " theEventOccupancy[" << mapItr->first << "] = " << mapItr->second << " / " << theNEvents << " / NCT \n";
70  }
71 }

References theCountPerChamberType, and theNEvents.

Referenced by ~SubsystemNeutronWriter().

◆ produce()

void SubsystemNeutronWriter::produce ( edm::Event e,
edm::EventSetup const &  c 
)
override

Definition at line 73 of file SubsystemNeutronWriter.cc.

73  {
74  CLHEP::HepRandomEngine* engine = nullptr;
75  if (useRandFlat) {
77  engine = &rng->getEngine(e.streamID());
78  }
80  ++theNEvents;
82  e.getByLabel(theInputTag, hits);
83 
84  // sort hits by chamber
85  map<int, edm::PSimHitContainer> hitsByChamber;
86  for (edm::PSimHitContainer::const_iterator hitItr = hits->begin(); hitItr != hits->end(); ++hitItr) {
87  int chamberIndex = chamberId(hitItr->detUnitId());
88  hitsByChamber[chamberIndex].push_back(*hitItr);
89  }
90 
91  // now write out each chamber's contents
92  for (map<int, edm::PSimHitContainer>::iterator hitsByChamberItr = hitsByChamber.begin();
93  hitsByChamberItr != hitsByChamber.end();
94  ++hitsByChamberItr) {
95  int chambertype = chamberType(hitsByChamberItr->first);
96  writeHits(chambertype, hitsByChamberItr->second, engine);
97  }
99 }

References NeutronWriter::beginEvent(), HltBtagPostValidation_cff::c, chamberId(), chamberType(), MillePedeFileConverter_cfg::e, NeutronWriter::endEvent(), edm::RandomNumberGenerator::getEngine(), hfClusterShapes_cfi::hits, theHitWriter, theInputTag, theNEvents, useRandFlat, and writeHits().

◆ updateCount()

void SubsystemNeutronWriter::updateCount ( int  chamberType)
protected

updates the counter

Definition at line 172 of file SubsystemNeutronWriter.cc.

172  {
173  map<int, int>::iterator entry = theCountPerChamberType.find(chamberType);
174  if (entry == theCountPerChamberType.end()) {
175  theCountPerChamberType.insert(pair<int, int>(chamberType, 1));
176  } else {
177  ++(entry->second);
178  }
179 }

References chamberType(), mps_splice::entry, and theCountPerChamberType.

Referenced by writeCluster().

◆ writeCluster()

void SubsystemNeutronWriter::writeCluster ( int  chamberType,
const edm::PSimHitContainer cluster 
)
protected

Definition at line 146 of file SubsystemNeutronWriter.cc.

146  {
147  if (accept(cluster)) {
150  }
151 }

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

Referenced by writeHits().

◆ writeHits()

void SubsystemNeutronWriter::writeHits ( int  chamberType,
edm::PSimHitContainer chamberHits,
CLHEP::HepRandomEngine *  engine 
)
protectedvirtual

Definition at line 107 of file SubsystemNeutronWriter.cc.

109  {
110  sort(chamberHits.begin(), chamberHits.end(), SortByTime());
111  edm::PSimHitContainer cluster;
112  float startTime = -1000.;
113  float smearing = 0.;
114  for (size_t i = 0; i < chamberHits.size(); ++i) {
115  PSimHit hit = chamberHits[i];
116  float tof = hit.tof();
117  LogDebug("SubsystemNeutronWriter") << "found hit from part type " << hit.particleType() << " at tof " << tof
118  << " p " << hit.pabs() << " on det " << hit.detUnitId() << " chamber type "
119  << chamberType;
120  if (tof > theNeutronTimeCut) {
121  if (tof > (startTime + theTimeWindow)) { // 1st in cluster
122  startTime = tof;
123  // set the time to be [t0, t0+25] at start of event
124  smearing = theT0;
125  if (useRandFlat) {
126  smearing += CLHEP::RandFlat::shoot(engine, 25.);
127  }
128  if (!cluster.empty()) {
129  LogDebug("SubsystemNeutronWriter") << "filling old cluster";
130  writeCluster(chamberType, cluster);
131  cluster.clear();
132  }
133  LogDebug("SubsystemNeutronWriter")
134  << "starting neutron cluster at time " << startTime << " on detType " << chamberType;
135  }
136  adjust(hit, -1. * startTime, smearing);
137  cluster.push_back(hit);
138  }
139  }
140  // get any leftover cluster
141  if (!cluster.empty()) {
142  writeCluster(chamberType, cluster);
143  }
144 }

References adjust(), chamberType(), mps_fire::i, LogDebug, theNeutronTimeCut, theT0, theTimeWindow, useRandFlat, and writeCluster().

Referenced by produce().

Member Data Documentation

◆ initialized

bool SubsystemNeutronWriter::initialized
private

Definition at line 70 of file SubsystemNeutronWriter.h.

◆ theCountPerChamberType

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

Definition at line 73 of file SubsystemNeutronWriter.h.

Referenced by printStats(), and updateCount().

◆ theHitWriter

NeutronWriter* SubsystemNeutronWriter::theHitWriter
private

◆ theInputTag

edm::InputTag SubsystemNeutronWriter::theInputTag
private

Definition at line 65 of file SubsystemNeutronWriter.h.

Referenced by produce().

◆ theNeutronTimeCut

double SubsystemNeutronWriter::theNeutronTimeCut
private

Definition at line 66 of file SubsystemNeutronWriter.h.

Referenced by writeHits().

◆ theNEvents

int SubsystemNeutronWriter::theNEvents
private

Definition at line 69 of file SubsystemNeutronWriter.h.

Referenced by printStats(), and produce().

◆ theT0

double SubsystemNeutronWriter::theT0
private

Definition at line 68 of file SubsystemNeutronWriter.h.

Referenced by writeHits().

◆ theTimeWindow

double SubsystemNeutronWriter::theTimeWindow
private

Definition at line 67 of file SubsystemNeutronWriter.h.

Referenced by writeHits().

◆ useLocalDetId_

bool SubsystemNeutronWriter::useLocalDetId_
private

Definition at line 72 of file SubsystemNeutronWriter.h.

Referenced by adjust(), and SubsystemNeutronWriter().

◆ useRandFlat

bool SubsystemNeutronWriter::useRandFlat
private

Definition at line 64 of file SubsystemNeutronWriter.h.

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

edm::RandomNumberGenerator::getEngine
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
mps_fire.i
i
Definition: mps_fire.py:428
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
NeutronWriter::initialize
virtual void initialize(int detType)
Definition: NeutronWriter.h:19
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:72
SubsystemNeutronWriter::theTimeWindow
double theTimeWindow
Definition: SubsystemNeutronWriter.h:67
mps_splice.entry
entry
Definition: mps_splice.py:68
SubsystemNeutronWriter::useLocalDetId_
bool useLocalDetId_
Definition: SubsystemNeutronWriter.h:72
NeutronWriter::writeCluster
virtual void writeCluster(int detType, const edm::PSimHitContainer &simHits)=0
writes out a list of SimHits.
cscNeutronWriter_cfi.writer
writer
Definition: cscNeutronWriter_cfi.py:6
AsciiNeutronWriter
Definition: AsciiNeutronWriter.h:11
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
SubsystemNeutronWriter::localDetId
virtual int localDetId(int globalDetId) const =0
edm::Handle< edm::PSimHitContainer >
NeutronWriter::beginEvent
virtual void beginEvent(edm::Event &e, const edm::EventSetup &es)
Definition: NeutronWriter.h:20
edm::Service::isAvailable
bool isAvailable() const
Definition: Service.h:40
SubsystemNeutronWriter::writeCluster
void writeCluster(int chamberType, const edm::PSimHitContainer &cluster)
Definition: SubsystemNeutronWriter.cc:146
SubsystemNeutronWriter::initialized
bool initialized
Definition: SubsystemNeutronWriter.h:70
SubsystemNeutronWriter::chamberId
virtual int chamberId(int globalDetId) const =0
h
NeutronWriter::endEvent
virtual void endEvent()
Definition: NeutronWriter.h:21
SubsystemNeutronWriter::accept
virtual bool accept(const edm::PSimHitContainer &cluster) const =0
decides whether this cluster is good enough to be included
SubsystemNeutronWriter::chamberType
virtual int chamberType(int globalDetId) const =0
SubsystemNeutronWriter::theNeutronTimeCut
double theNeutronTimeCut
Definition: SubsystemNeutronWriter.h:66
SubsystemNeutronWriter::updateCount
void updateCount(int chamberType)
updates the counter
Definition: SubsystemNeutronWriter.cc:172
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
SubsystemNeutronWriter::theT0
double theT0
Definition: SubsystemNeutronWriter.h:68
SubsystemNeutronWriter::writeHits
virtual void writeHits(int chamberType, edm::PSimHitContainer &chamberHits, CLHEP::HepRandomEngine *)
Definition: SubsystemNeutronWriter.cc:107
edm::Service< edm::RandomNumberGenerator >
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
RootNeutronWriter
Definition: RootNeutronWriter.h:13
SubsystemNeutronWriter::theCountPerChamberType
std::map< int, int > theCountPerChamberType
Definition: SubsystemNeutronWriter.h:73
CalibratedDigis_cfi.timeOffset
timeOffset
Definition: CalibratedDigis_cfi.py:23
SubsystemNeutronWriter::theInputTag
edm::InputTag theInputTag
Definition: SubsystemNeutronWriter.h:65
Exception
Definition: hltDiff.cc:246
SortByTime
Definition: SubsystemNeutronWriter.cc:19
SubsystemNeutronWriter::theHitWriter
NeutronWriter * theHitWriter
Definition: SubsystemNeutronWriter.h:63
edm::PSimHitContainer
std::vector< PSimHit > PSimHitContainer
Definition: PSimHitContainer.h:11
PSimHit
Definition: PSimHit.h:15
SubsystemNeutronWriter::adjust
void adjust(PSimHit &h, float timeOffset, float smearing)
helper to add time offsets and local det ID
Definition: SubsystemNeutronWriter.cc:153
SubsystemNeutronWriter::theNEvents
int theNEvents
Definition: SubsystemNeutronWriter.h:69
edm::InputTag
Definition: InputTag.h:15
hit
Definition: SiStripHitEffFromCalibTree.cc:88
EDMNeutronWriter
Definition: EDMNeutronWriter.h:9
SubsystemNeutronWriter::printStats
void printStats()
Definition: SubsystemNeutronWriter.cc:64
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
SubsystemNeutronWriter::useRandFlat
bool useRandFlat
Definition: SubsystemNeutronWriter.h:64