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.
37 
38 #include <vector>
39 
40 namespace CLHEP {
41  class HepRandomEngine;
42 }
43 
45 public:
47  ~CastorDigiProducer() override;
48 
49  void initializeEvent(edm::Event const &e, edm::EventSetup const &c) override;
50  void accumulate(edm::Event const &e, edm::EventSetup const &c) override;
51  void accumulate(PileUpEventPrincipal const &e, edm::EventSetup const &c, edm::StreamID const &) override;
52  void finalizeEvent(edm::Event &e, edm::EventSetup const &c) override;
53 
54 private:
55  void accumulateCaloHits(std::vector<PCaloHit> const &, int bunchCrossing);
56 
58  void sortHits(const edm::PCaloHitContainer &hits);
60  void fillFakeHits();
63  void checkGeometry(const edm::EventSetup &eventSetup);
64 
69 
72 
76 
78 
82 
84 
86 
88 
89  std::vector<PCaloHit> theCastorHits;
90 
91  CLHEP::HepRandomEngine *randomEngine_ = nullptr;
92 };
93 
95  edm::ProducesCollector producesCollector,
97  : theConditionsToken(iC.esConsumes()),
98  theGeometryToken(iC.esConsumes()),
99  theParameterMap(new CastorSimParameterMap(ps)),
100  theCastorShape(new CastorShape()),
101  theCastorIntegratedShape(new CaloShapeIntegrator(theCastorShape)),
102  theCastorResponse(new CaloHitResponse(theParameterMap, theCastorIntegratedShape)),
103  theAmplifier(nullptr),
104  theCoderFactory(nullptr),
105  theElectronicsSim(nullptr),
106  theHitCorrection(nullptr),
107  theCastorDigitizer(nullptr),
108  theCastorHits() {
109  theHitsProducerTag = ps.getParameter<edm::InputTag>("hitsProducer");
110  iC.consumes<std::vector<PCaloHit>>(theHitsProducerTag);
111 
112  producesCollector.produces<CastorDigiCollection>();
113 
115 
116  bool doTimeSlew = ps.getParameter<bool>("doTimeSlew");
117  if (doTimeSlew) {
118  // no time slewing for HF
120  }
121 
122  bool doNoise = ps.getParameter<bool>("doNoise");
126 
128 
130  if (!rng.isAvailable()) {
131  throw cms::Exception("Configuration") << "CastorDigiProducer requires the RandomNumberGeneratorService\n"
132  "which is not present in the configuration file. You must add the "
133  "service\n"
134  "in the configuration file or remove the modules that require it.";
135  }
136 }
137 
139  delete theCastorDigitizer;
140  delete theParameterMap;
141  delete theCastorShape;
143  delete theCastorResponse;
144  delete theElectronicsSim;
145  delete theAmplifier;
146  delete theCoderFactory;
147  delete theHitCorrection;
148 }
149 
151  // get the appropriate gains, noises, & widths for this event
153  theAmplifier->setDbService(conditions);
154  theCoderFactory->setDbService(conditions);
155  theParameterMap->setDbService(conditions);
156 
157  // Cache random number engine
159  randomEngine_ = &rng->getEngine(event.streamID());
160 
161  edm::LogInfo("CastorDigiProducer") << "checking the geometry...";
162 
163  // get the correct geometry
164  checkGeometry(eventSetup);
165 
166  theCastorHits.clear();
167 
169 }
170 
171 void CastorDigiProducer::accumulateCaloHits(std::vector<PCaloHit> const &hcalHits, int bunchCrossing) {
172  // fillFakeHits();
173 
174  if (theHitCorrection != nullptr) {
175  theHitCorrection->fillChargeSums(hcalHits);
176  }
177  theCastorDigitizer->add(hcalHits, bunchCrossing, randomEngine_);
178 }
179 
181  // Step A: Get and accumulate digitized hits
182  edm::Handle<std::vector<PCaloHit>> castorHandle;
183  e.getByLabel(theHitsProducerTag, castorHandle);
184 
185  accumulateCaloHits(*castorHandle.product(), 0);
186 }
187 
189  edm::EventSetup const &,
190  edm::StreamID const &streamID) {
191  // Step A: Get and accumulate digitized hits
192  edm::Handle<std::vector<PCaloHit>> castorHandle;
193  e.getByLabel(theHitsProducerTag, castorHandle);
194 
195  accumulateCaloHits(*castorHandle.product(), e.bunchCrossing());
196 }
197 
199  // Step B: Create empty output
200 
201  std::unique_ptr<CastorDigiCollection> castorResult(new CastorDigiCollection());
202 
203  // Step C: Invoke the algorithm, getting back outputs.
204  theCastorDigitizer->run(*castorResult, randomEngine_);
205 
206  edm::LogInfo("CastorDigiProducer") << "HCAL/Castor digis : " << castorResult->size();
207 
208  // Step D: Put outputs into event
209  e.put(std::move(castorResult));
210 
211  randomEngine_ = nullptr; // to prevent access outside event
212 }
213 
215  for (edm::PCaloHitContainer::const_iterator hitItr = hits.begin(); hitItr != hits.end(); ++hitItr) {
216  DetId detId = hitItr->id();
217  if (detId.det() == DetId::Calo && detId.subdetId() == HcalCastorDetId::SubdetectorId) {
218  theCastorHits.push_back(*hitItr);
219  } else {
220  edm::LogError("CastorDigiProducer") << "Bad Hit subdetector " << detId.subdetId();
221  }
222  }
223 }
224 
226  HcalCastorDetId castorDetId(HcalCastorDetId::Section(2), true, 1, 1);
227 
228  theCastorHits.emplace_back(castorDetId.rawId(), 50.0, 0.);
229 }
230 
232  if (theGeometryWatcher.check(eventSetup)) {
233  const CaloGeometry *geometry = &eventSetup.getData(theGeometryToken);
234  theCastorResponse->setGeometry(geometry);
235 
236  const std::vector<DetId> &castorCells = geometry->getValidDetIds(DetId::Calo, HcalCastorDetId::SubdetectorId);
237 
238  // std::cout<<"CastorDigiProducer::CheckGeometry number of cells:
239  // "<<castorCells.size()<<std::endl;
240  theCastorDigitizer->setDetIds(castorCells);
241  }
242 }
243 
246 
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:128
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