CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CastorDigiProducer.cc
Go to the documentation of this file.
36 
37 #include <vector>
38 
39 namespace CLHEP {
40  class HepRandomEngine;
41 }
42 
44 public:
46  ~CastorDigiProducer() override;
47 
48  void initializeEvent(edm::Event const &e, edm::EventSetup const &c) override;
49  void accumulate(edm::Event const &e, edm::EventSetup const &c) override;
50  void accumulate(PileUpEventPrincipal const &e, edm::EventSetup const &c, edm::StreamID const &) override;
51  void finalizeEvent(edm::Event &e, edm::EventSetup const &c) override;
52 
53 private:
54  void accumulateCaloHits(std::vector<PCaloHit> const &, int bunchCrossing);
55 
57  void sortHits(const edm::PCaloHitContainer &hits);
59  void fillFakeHits();
62  void checkGeometry(const edm::EventSetup &eventSetup);
63 
68 
71 
75 
77 
81 
83 
85 
87 
88  std::vector<PCaloHit> theCastorHits;
89 
90  CLHEP::HepRandomEngine *randomEngine_ = nullptr;
91 };
92 
94  edm::ProducesCollector producesCollector,
96  : theConditionsToken(iC.esConsumes()),
97  theGeometryToken(iC.esConsumes()),
98  theParameterMap(new CastorSimParameterMap(ps)),
99  theCastorShape(new CastorShape()),
100  theCastorIntegratedShape(new CaloShapeIntegrator(theCastorShape)),
101  theCastorResponse(new CaloHitResponse(theParameterMap, theCastorIntegratedShape)),
102  theAmplifier(nullptr),
103  theCoderFactory(nullptr),
104  theElectronicsSim(nullptr),
105  theHitCorrection(nullptr),
106  theCastorDigitizer(nullptr),
107  theCastorHits() {
108  theHitsProducerTag = ps.getParameter<edm::InputTag>("hitsProducer");
109  iC.consumes<std::vector<PCaloHit>>(theHitsProducerTag);
110 
111  producesCollector.produces<CastorDigiCollection>();
112 
114 
115  bool doTimeSlew = ps.getParameter<bool>("doTimeSlew");
116  if (doTimeSlew) {
117  // no time slewing for HF
119  }
120 
121  bool doNoise = ps.getParameter<bool>("doNoise");
125 
127 
129  if (!rng.isAvailable()) {
130  throw cms::Exception("Configuration") << "CastorDigiProducer requires the RandomNumberGeneratorService\n"
131  "which is not present in the configuration file. You must add the "
132  "service\n"
133  "in the configuration file or remove the modules that require it.";
134  }
135 }
136 
138  delete theCastorDigitizer;
139  delete theParameterMap;
140  delete theCastorShape;
142  delete theCastorResponse;
143  delete theElectronicsSim;
144  delete theAmplifier;
145  delete theCoderFactory;
146  delete theHitCorrection;
147 }
148 
150  // get the appropriate gains, noises, & widths for this event
152  theAmplifier->setDbService(conditions);
153  theCoderFactory->setDbService(conditions);
154  theParameterMap->setDbService(conditions);
155 
156  // Cache random number engine
158  randomEngine_ = &rng->getEngine(event.streamID());
159 
160  edm::LogInfo("CastorDigiProducer") << "checking the geometry...";
161 
162  // get the correct geometry
163  checkGeometry(eventSetup);
164 
165  theCastorHits.clear();
166 
168 }
169 
170 void CastorDigiProducer::accumulateCaloHits(std::vector<PCaloHit> const &hcalHits, int bunchCrossing) {
171  // fillFakeHits();
172 
173  if (theHitCorrection != nullptr) {
174  theHitCorrection->fillChargeSums(hcalHits);
175  }
176  theCastorDigitizer->add(hcalHits, bunchCrossing, randomEngine_);
177 }
178 
180  // Step A: Get and accumulate digitized hits
181  edm::Handle<std::vector<PCaloHit>> castorHandle;
182  e.getByLabel(theHitsProducerTag, castorHandle);
183 
184  accumulateCaloHits(*castorHandle.product(), 0);
185 }
186 
188  edm::EventSetup const &,
189  edm::StreamID const &streamID) {
190  // Step A: Get and accumulate digitized hits
191  edm::Handle<std::vector<PCaloHit>> castorHandle;
192  e.getByLabel(theHitsProducerTag, castorHandle);
193 
194  accumulateCaloHits(*castorHandle.product(), e.bunchCrossing());
195 }
196 
198  // Step B: Create empty output
199 
200  std::unique_ptr<CastorDigiCollection> castorResult(new CastorDigiCollection());
201 
202  // Step C: Invoke the algorithm, getting back outputs.
203  theCastorDigitizer->run(*castorResult, randomEngine_);
204 
205  edm::LogInfo("CastorDigiProducer") << "HCAL/Castor digis : " << castorResult->size();
206 
207  // Step D: Put outputs into event
208  e.put(std::move(castorResult));
209 
210  randomEngine_ = nullptr; // to prevent access outside event
211 }
212 
214  for (edm::PCaloHitContainer::const_iterator hitItr = hits.begin(); hitItr != hits.end(); ++hitItr) {
215  DetId detId = hitItr->id();
216  if (detId.det() == DetId::Calo && detId.subdetId() == HcalCastorDetId::SubdetectorId) {
217  theCastorHits.push_back(*hitItr);
218  } else {
219  edm::LogError("CastorDigiProducer") << "Bad Hit subdetector " << detId.subdetId();
220  }
221  }
222 }
223 
225  HcalCastorDetId castorDetId(HcalCastorDetId::Section(2), true, 1, 1);
226 
227  theCastorHits.emplace_back(castorDetId.rawId(), 50.0, 0.);
228 }
229 
231  if (theGeometryWatcher.check(eventSetup)) {
232  const CaloGeometry *geometry = &eventSetup.getData(theGeometryToken);
233  theCastorResponse->setGeometry(geometry);
234 
235  const std::vector<DetId> &castorCells = geometry->getValidDetIds(DetId::Calo, HcalCastorDetId::SubdetectorId);
236 
237  // std::cout<<"CastorDigiProducer::CheckGeometry number of cells:
238  // "<<castorCells.size()<<std::endl;
239  theCastorDigitizer->setDetIds(castorCells);
240  }
241 }
242 
245 
void finalizeEvent(edm::Event &e, edm::EventSetup const &c) override
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
void setGeometry(const CaloGeometry *geometry)
geometry needed for time-of-flight
void initializeEvent(edm::Event const &e, edm::EventSetup const &c) override
CastorAmplifier * theAmplifier
CaloVShape * theCastorShape
std::vector< PCaloHit > PCaloHitContainer
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
const edm::EventSetup & c
void add(const std::vector< PCaloHit > &hits, int bunchCrossing, CLHEP::HepRandomEngine *engine)
ProductRegistryHelper::BranchAliasSetterT< ProductType > produces()
void fillChargeSums(MixCollection< PCaloHit > &hits)
CaloTDigitizer< CastorDigitizerTraits > CastorDigitizer
void checkGeometry(const edm::EventSetup &eventSetup)
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
void setDbService(const CastorDbService *service)
CastorSimParameterMap * theParameterMap
Electronic response of the preamp.
Definition: CaloVShape.h:11
void sortHits(const edm::PCaloHitContainer &hits)
fills the vectors for each subdetector
Log< level::Error, false > LogError
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
CLHEP::HepRandomEngine * randomEngine_
CastorElectronicsSim * theElectronicsSim
bool getData(T &iHolder) const
Definition: EventSetup.h:122
CastorHitFilter theCastorHitFilter
void setHitFilter(const CaloVHitFilter *filter)
Creates electronics signals from hits.
void initializeHits()
def move
Definition: eostools.py:511
CaloHitResponse * theCastorResponse
bool isAvailable() const
Definition: Service.h:40
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
std::vector< PCaloHit > theCastorHits
void fillFakeHits()
some hits in each subdetector, just for testing purposes
static const int SubdetectorId
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:500
void accumulateCaloHits(std::vector< PCaloHit > const &, int bunchCrossing)
void accumulate(edm::Event const &e, edm::EventSetup const &c) override
Log< level::Info, false > LogInfo
CastorDigiProducer(const edm::ParameterSet &ps, edm::ProducesCollector, edm::ConsumesCollector &iC)
Definition: DetId.h:17
T const * product() const
Definition: Handle.h:70
CastorHitCorrection * theHitCorrection
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void run(MixCollection< PCaloHit > &, DigiCollection &)
turns hits into digis
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
std::vector< DetId > getValidDetIds() const
Get the list of all valid detector ids.
Definition: CaloGeometry.cc:75
const edm::ESGetToken< CastorDbService, CastorDbRecord > theConditionsToken
CastorDigitizer * theCastorDigitizer
#define DEFINE_DIGI_ACCUMULATOR(type)
void setHitCorrection(const CaloVHitCorrection *hitCorrection)
If you want to correct hits, for attenuation or delay, set this.
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > theGeometryToken
bool getByLabel(edm::InputTag const &tag, edm::Handle< T > &result) const
StreamID streamID() const
Definition: Event.h:98
CastorCoderFactory * theCoderFactory
shaper for Castor
Definition: CastorShape.h:15
edm::SortedCollection< CastorDataFrame > CastorDigiCollection
void setDbService(const CastorDbService *service)
the Producer will probably update this every event
edm::ESWatcher< CaloGeometryRecord > theGeometryWatcher
edm::InputTag theHitsProducerTag
void setDbService(const CastorDbService *service)
CaloVShape * theCastorIntegratedShape
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
void setDetIds(const std::vector< DetId > &detIds)
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46