CMS 3D CMS Logo

CastorDigiProducer.cc
Go to the documentation of this file.
21 
23  edm::ProducerBase &mixMod,
25  : theParameterMap(new CastorSimParameterMap(ps)),
26  theCastorShape(new CastorShape()),
27  theCastorIntegratedShape(new CaloShapeIntegrator(theCastorShape)),
28  theCastorResponse(new CaloHitResponse(theParameterMap, theCastorIntegratedShape)),
29  theAmplifier(nullptr),
30  theCoderFactory(nullptr),
31  theElectronicsSim(nullptr),
32  theHitCorrection(nullptr),
33  theCastorDigitizer(nullptr),
34  theCastorHits() {
35  theHitsProducerTag = ps.getParameter<edm::InputTag>("hitsProducer");
36  iC.consumes<std::vector<PCaloHit>>(theHitsProducerTag);
37 
39 
41 
42  bool doTimeSlew = ps.getParameter<bool>("doTimeSlew");
43  if (doTimeSlew) {
44  // no time slewing for HF
46  }
47 
48  bool doNoise = ps.getParameter<bool>("doNoise");
52 
54 
56  if (!rng.isAvailable()) {
57  throw cms::Exception("Configuration") << "CastorDigiProducer requires the RandomNumberGeneratorService\n"
58  "which is not present in the configuration file. You must add the "
59  "service\n"
60  "in the configuration file or remove the modules that require it.";
61  }
62 }
63 
65  delete theCastorDigitizer;
66  delete theParameterMap;
67  delete theCastorShape;
69  delete theCastorResponse;
70  delete theElectronicsSim;
71  delete theAmplifier;
72  delete theCoderFactory;
73  delete theHitCorrection;
74 }
75 
77  // get the appropriate gains, noises, & widths for this event
79  eventSetup.get<CastorDbRecord>().get(conditions);
80  theAmplifier->setDbService(conditions.product());
81  theCoderFactory->setDbService(conditions.product());
82  theParameterMap->setDbService(conditions.product());
83 
84  // Cache random number engine
86  randomEngine_ = &rng->getEngine(event.streamID());
87 
88  edm::LogInfo("CastorDigiProducer") << "checking the geometry...";
89 
90  // get the correct geometry
91  checkGeometry(eventSetup);
92 
93  theCastorHits.clear();
94 
96 }
97 
98 void CastorDigiProducer::accumulateCaloHits(std::vector<PCaloHit> const &hcalHits, int bunchCrossing) {
99  // fillFakeHits();
100 
101  if (theHitCorrection != nullptr) {
102  theHitCorrection->fillChargeSums(hcalHits);
103  }
104  theCastorDigitizer->add(hcalHits, bunchCrossing, randomEngine_);
105 }
106 
108  // Step A: Get and accumulate digitized hits
109  edm::Handle<std::vector<PCaloHit>> castorHandle;
110  e.getByLabel(theHitsProducerTag, castorHandle);
111 
112  accumulateCaloHits(*castorHandle.product(), 0);
113 }
114 
116  edm::EventSetup const &,
117  edm::StreamID const &streamID) {
118  // Step A: Get and accumulate digitized hits
119  edm::Handle<std::vector<PCaloHit>> castorHandle;
120  e.getByLabel(theHitsProducerTag, castorHandle);
121 
122  accumulateCaloHits(*castorHandle.product(), e.bunchCrossing());
123 }
124 
126  // Step B: Create empty output
127 
128  std::unique_ptr<CastorDigiCollection> castorResult(new CastorDigiCollection());
129 
130  // Step C: Invoke the algorithm, getting back outputs.
131  theCastorDigitizer->run(*castorResult, randomEngine_);
132 
133  edm::LogInfo("CastorDigiProducer") << "HCAL/Castor digis : " << castorResult->size();
134 
135  // Step D: Put outputs into event
136  e.put(std::move(castorResult));
137 
138  randomEngine_ = nullptr; // to prevent access outside event
139 }
140 
142  for (edm::PCaloHitContainer::const_iterator hitItr = hits.begin(); hitItr != hits.end(); ++hitItr) {
143  DetId detId = hitItr->id();
144  if (detId.det() == DetId::Calo && detId.subdetId() == HcalCastorDetId::SubdetectorId) {
145  theCastorHits.push_back(*hitItr);
146  } else {
147  edm::LogError("CastorDigiProducer") << "Bad Hit subdetector " << detId.subdetId();
148  }
149  }
150 }
151 
153  HcalCastorDetId castorDetId(HcalCastorDetId::Section(2), true, 1, 1);
154 
155  theCastorHits.emplace_back(castorDetId.rawId(), 50.0, 0.);
156 }
157 
159  // TODO find a way to avoid doing this every event
161  eventSetup.get<CaloGeometryRecord>().get(geometry);
162  theCastorResponse->setGeometry(&*geometry);
163 
164  const std::vector<DetId> &castorCells = geometry->getValidDetIds(DetId::Calo, HcalCastorDetId::SubdetectorId);
165 
166  // std::cout<<"CastorDigiProducer::CheckGeometry number of cells:
167  // "<<castorCells.size()<<std::endl;
168  theCastorDigitizer->setDetIds(castorCells);
169 }
void finalizeEvent(edm::Event &e, edm::EventSetup const &c) override
BranchAliasSetterT< ProductType > produces()
declare what type of product will make and with which optional label
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
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:125
void add(const std::vector< PCaloHit > &hits, int bunchCrossing, CLHEP::HepRandomEngine *engine)
void fillChargeSums(MixCollection< PCaloHit > &hits)
~CastorDigiProducer() override
CastorDigiProducer(const edm::ParameterSet &ps, edm::ProducerBase &mixMod, edm::ConsumesCollector &iC)
CaloTDigitizer< CastorDigitizerTraits > CastorDigitizer
#define nullptr
void checkGeometry(const edm::EventSetup &eventSetup)
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
void setDbService(const CastorDbService *service)
CastorSimParameterMap * theParameterMap
void sortHits(const edm::PCaloHitContainer &hits)
fills the vectors for each subdetector
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
CLHEP::HepRandomEngine * randomEngine_
CastorElectronicsSim * theElectronicsSim
CastorHitFilter theCastorHitFilter
void setHitFilter(const CaloVHitFilter *filter)
Creates electronics signals from hits.
void initializeHits()
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:41
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:480
void accumulateCaloHits(std::vector< PCaloHit > const &, int bunchCrossing)
void accumulate(edm::Event const &e, edm::EventSetup const &c) override
Definition: DetId.h:18
T const * product() const
Definition: Handle.h:74
CastorHitCorrection * theHitCorrection
void run(MixCollection< PCaloHit > &, DigiCollection &)
turns hits into digis
std::vector< DetId > getValidDetIds() const
Get the list of all valid detector ids.
ESHandle< TrackerGeometry > geometry
CastorDigitizer * theCastorDigitizer
void setHitCorrection(const CaloVHitCorrection *hitCorrection)
If you want to correct hits, for attenuation or delay, set this.
bool getByLabel(edm::InputTag const &tag, edm::Handle< T > &result) const
T get() const
Definition: EventSetup.h:71
StreamID streamID() const
Definition: Event.h:95
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::InputTag theHitsProducerTag
void setDbService(const CastorDbService *service)
T const * product() const
Definition: ESHandle.h:86
CaloVShape * theCastorIntegratedShape
def move(src, dest)
Definition: eostools.py:511
void setDetIds(const std::vector< DetId > &detIds)
Definition: event.py:1
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:39