CMS 3D CMS Logo

PPSPixelDigiProducer.cc
Go to the documentation of this file.
1 #ifndef SimPPS_PPSPixelDigiProducer_PPSPixelDigiProducer_h
2 #define SimPPS_PPSPixelDigiProducer_PPSPixelDigiProducer_h
3 
4 // -*- C++ -*-
5 //
6 // Package: PPSPixelDigiProducer
7 // Class: CTPPSPixelDigiProducer
8 //
16 //
17 // Original Author: F.Ferro
18 //
19 
20 // system include files
21 #include <memory>
22 #include <vector>
23 #include <map>
24 #include <string>
25 
26 // user include files
29 
33 
37 
38 // **** CTPPS
41 
44 
46 
47 // DB
54 
57 // user include files
62 #include <cstdlib> // I need it for random numbers
63 //needed for the geometry:
66 
68 
69 //Random Number
73 #include "CLHEP/Random/RandomEngine.h"
74 
75 namespace CLHEP {
76  class HepRandomEngine;
77 }
78 
80 public:
82  ~CTPPSPixelDigiProducer() override;
83  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
84 
85 private:
86  void produce(edm::Event&, const edm::EventSetup&) override;
87 
88  // ----------member data ---------------------------
89  std::vector<std::string> RPix_hit_containers_;
90  typedef std::map<unsigned int, std::vector<PSimHit>> simhit_map;
91  typedef simhit_map::iterator simhit_map_iterator;
92 
94 
95  std::map<uint32_t, std::unique_ptr<RPixDetDigitizer>> theAlgoMap; //DetId = uint32_t
96 
97  CLHEP::HepRandomEngine* rndEngine_ = nullptr;
99 
103 };
104 
106  : conf_(conf), gainCalibESToken_(esConsumes()), thePixelTopologyToken_(esConsumes()) {
107  produces<edm::DetSetVector<CTPPSPixelDigi>>();
108 
109  // register data to consume
110  tokenCrossingFramePPSPixel = consumes<CrossingFrame<PSimHit>>(edm::InputTag("mix", "g4SimHitsCTPPSPixelHits"));
111 
112  RPix_hit_containers_.clear();
113  RPix_hit_containers_ = conf.getParameter<std::vector<std::string>>("ROUList");
114  verbosity_ = conf.getParameter<int>("RPixVerbosity");
115 }
116 
118 
121  // all distances in [mm]
122  // RPDigiProducer
123  desc.add<std::vector<std::string>>("ROUList", {"CTPPSPixelHits"});
124  desc.add<int>("RPixVerbosity", 0);
125  desc.add<bool>("CTPPSPixelDigiSimHitRelationsPersistence",
126  false); // save links betweend digi, clusters and OSCAR/Geant4 hits
127 
128  // RPDetDigitizer
129  desc.add<double>("RPixEquivalentNoiseCharge", 1000.0);
130  desc.add<bool>("RPixNoNoise", false);
131 
132  // RPDisplacementGenerator
133  desc.add<double>("RPixGeVPerElectron", 3.61e-09);
134  desc.add<std::vector<double>>("RPixInterSmearing", {0.011});
135  desc.add<bool>("RPixLandauFluctuations", true);
136  desc.add<int>("RPixChargeDivisions", 20);
137  desc.add<double>("RPixDeltaProductionCut", 0.120425); // [MeV]
138 
139  // RPixChargeShare
140  desc.add<std::string>("ChargeMapFile2E", "SimPPS/PPSPixelDigiProducer/data/PixelChargeMap.txt");
141  desc.add<std::string>("ChargeMapFile2E_2X", "SimPPS/PPSPixelDigiProducer/data/PixelChargeMap_2X.txt");
142  desc.add<std::string>("ChargeMapFile2E_2Y", "SimPPS/PPSPixelDigiProducer/data/PixelChargeMap_2Y.txt");
143  desc.add<std::string>("ChargeMapFile2E_2X2Y", "SimPPS/PPSPixelDigiProducer/data/PixelChargeMap_2X2Y.txt");
144  desc.add<double>(
145  "RPixCoupling",
146  0.250); // fraction of the remaining charge going to the closer neighbour pixel. Value = 0.135, Value = 0.0 bypass the charge map and the charge sharing approach
147 
148  // RPixDummyROCSimulator
149  desc.add<double>("RPixDummyROCThreshold", 1900.0);
150  desc.add<double>("RPixDummyROCElectronPerADC", 135.0); // 210.0 to be verified
151  desc.add<int>("VCaltoElectronGain", 50); // same values as in RPixDetClusterizer
152  desc.add<int>("VCaltoElectronOffset", -411); //
153  desc.add<bool>("doSingleCalibration", false); //
154  desc.add<double>("RPixDeadPixelProbability", 0.001);
155  desc.add<bool>("RPixDeadPixelSimulationOn", true);
156 
157  desc.add<std::string>("mixLabel", "mix");
158  desc.add<std::string>("InputCollection", "g4SimHitsCTPPSPixelHits");
159  descriptions.add("RPixDetDigitizer", desc);
160 }
161 
162 // member functions
163 //
164 
165 // ------------ method called to produce the data ------------
167  if (!rndEngine_) {
169  if (!rng.isAvailable()) {
170  throw cms::Exception("Configuration")
171  << "This class requires the RandomNumberGeneratorService\n"
172  "which is not present in the configuration file. You must add the service\n"
173  "in the configuration file or remove the modules that require it.";
174  }
175  rndEngine_ = &(rng->getEngine(iEvent.streamID()));
176  }
177 
178  // get calibration DB
179  const auto& gainCalibration = iSetup.getData(gainCalibESToken_);
180  const auto& thePixelTopology = iSetup.getData(thePixelTopologyToken_);
181 
182  // Step A: Get Inputs
184 
185  iEvent.getByToken(tokenCrossingFramePPSPixel, cf);
186 
187  if (verbosity_) {
188  edm::LogInfo("PPS") << "PixelDigiProducer \n\n=================== Starting SimHit access"
189  << " ===================";
190 
191  MixCollection<PSimHit> col{cf.product(), std::pair(-0, 0)};
193  int count = 0;
194  for (cfi = col.begin(); cfi != col.end(); cfi++) {
195  edm::LogInfo("PPS") << "PixelDigiProducer"
196  << " Hit " << count << " has tof " << cfi->timeOfFlight() << " trackid " << cfi->trackId()
197  << " bunchcr " << cfi.bunch() << " trigger " << cfi.getTrigger()
198  << ", from EncodedEventId: " << cfi->eventId().bunchCrossing() << " "
199  << cfi->eventId().event() << " bcr from MixCol " << cfi.bunch();
200  edm::LogInfo("PPS") << " PixelDigiProducer Hit: " << (*cfi) << " " << cfi->exitPoint();
201  count++;
202  }
203  }
204 
205  MixCollection<PSimHit> allRPixHits{cf.product(), std::pair(0, 0)};
206 
207  if (verbosity_)
208  edm::LogInfo("PPS") << "PixelDigiProducer Input MixCollection size = " << allRPixHits.size();
209 
210  //Loop on PSimHit
211  simhit_map SimHitMap;
212  SimHitMap.clear();
213 
215  for (isim = allRPixHits.begin(); isim != allRPixHits.end(); ++isim) {
216  SimHitMap[(*isim).detUnitId()].push_back((*isim));
217  }
218 
219  // Step B: LOOP on hits in event
220  std::vector<edm::DetSet<CTPPSPixelDigi>> theDigiVector;
221  theDigiVector.reserve(400);
222  theDigiVector.clear();
223 
224  for (simhit_map_iterator it = SimHitMap.begin(); it != SimHitMap.end(); ++it) {
225  edm::DetSet<CTPPSPixelDigi> digi_collector(it->first);
226 
227  if (theAlgoMap.find(it->first) == theAlgoMap.end()) {
228  theAlgoMap[it->first] = std::make_unique<RPixDetDigitizer>(
229  conf_, *rndEngine_, it->first, thePixelTopology); //a digitizer for any detector
230  }
231 
232  std::vector<int> input_links;
233  std::vector<std::vector<std::pair<int, double>>> output_digi_links; // links to simhits
234 
235  theAlgoMap.at(it->first)->run(
236  SimHitMap[it->first], input_links, digi_collector.data, output_digi_links, &gainCalibration, &thePixelTopology);
237 
238  if (!digi_collector.data.empty()) {
239  theDigiVector.push_back(digi_collector);
240  }
241  }
242 
243  std::unique_ptr<edm::DetSetVector<CTPPSPixelDigi>> digi_output(new edm::DetSetVector<CTPPSPixelDigi>(theDigiVector));
244 
245  if (verbosity_) {
246  edm::LogInfo("PPS") << "PixelDigiProducer digi_output->size()=" << digi_output->size();
247  }
248 
249  iEvent.put(std::move(digi_output));
250 }
251 
253 
254 #endif
simhit_map::iterator simhit_map_iterator
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
T const * product() const
Definition: Handle.h:70
CTPPSPixelDigiProducer(const edm::ParameterSet &)
void produce(edm::Event &, const edm::EventSetup &) override
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
std::vector< std::string > RPix_hit_containers_
int iEvent
Definition: GenABIO.cc:224
edm::EDGetTokenT< CrossingFrame< PSimHit > > tokenCrossingFramePPSPixel
CLHEP::HepRandomEngine * rndEngine_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::map< unsigned int, std::vector< PSimHit > > simhit_map
Log< level::Info, false > LogInfo
bool getTrigger() const
Definition: MixCollection.h:97
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::ESGetToken< CTPPSPixelGainCalibrations, CTPPSPixelGainCalibrationsRcd > gainCalibESToken_
std::map< uint32_t, std::unique_ptr< RPixDetDigitizer > > theAlgoMap
collection_type data
Definition: DetSet.h:80
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
col
Definition: cuy.py:1009
bool isAvailable() const
Definition: Service.h:40
edm::ESGetToken< PPSPixelTopology, PPSPixelTopologyRcd > thePixelTopologyToken_
def move(src, dest)
Definition: eostools.py:511