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 
55 // user include files
60 #include <cstdlib> // I need it for random numbers
61 //needed for the geometry:
64 
66 
67 //Random Number
71 #include "CLHEP/Random/RandomEngine.h"
72 
73 namespace CLHEP {
74  class HepRandomEngine;
75 }
76 
78 public:
80  ~CTPPSPixelDigiProducer() override;
81  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
82 
83 private:
84  void produce(edm::Event&, const edm::EventSetup&) override;
85 
86  // ----------member data ---------------------------
87  std::vector<std::string> RPix_hit_containers_;
88  typedef std::map<unsigned int, std::vector<PSimHit>> simhit_map;
89  typedef simhit_map::iterator simhit_map_iterator;
90 
92 
93  std::map<uint32_t, std::unique_ptr<RPixDetDigitizer>> theAlgoMap; //DetId = uint32_t
94 
95  CLHEP::HepRandomEngine* rndEngine_ = nullptr;
97 
99 
101 };
102 
104  produces<edm::DetSetVector<CTPPSPixelDigi>>();
105 
106  // register data to consume
107  tokenCrossingFramePPSPixel = consumes<CrossingFrame<PSimHit>>(edm::InputTag("mix", "g4SimHitsCTPPSPixelHits"));
108 
109  RPix_hit_containers_.clear();
110  RPix_hit_containers_ = conf.getParameter<std::vector<std::string>>("ROUList");
111  verbosity_ = conf.getParameter<int>("RPixVerbosity");
112 }
113 
115 
118  // all distances in [mm]
119  // RPDigiProducer
120  desc.add<std::vector<std::string>>("ROUList", {"CTPPSPixelHits"});
121  desc.add<int>("RPixVerbosity", 0);
122  desc.add<bool>("CTPPSPixelDigiSimHitRelationsPersistence",
123  false); // save links betweend digi, clusters and OSCAR/Geant4 hits
124 
125  // RPDetDigitizer
126  desc.add<double>("RPixEquivalentNoiseCharge", 1000.0);
127  desc.add<bool>("RPixNoNoise", false);
128 
129  // RPDisplacementGenerator
130  desc.add<double>("RPixGeVPerElectron", 3.61e-09);
131  desc.add<std::vector<double>>("RPixInterSmearing", {0.011});
132  desc.add<bool>("RPixLandauFluctuations", true);
133  desc.add<int>("RPixChargeDivisions", 20);
134  desc.add<double>("RPixDeltaProductionCut", 0.120425); // [MeV]
135 
136  // RPixChargeShare
137  desc.add<std::string>("ChargeMapFile2E", "SimPPS/PPSPixelDigiProducer/data/PixelChargeMap.txt");
138  desc.add<std::string>("ChargeMapFile2E_2X", "SimPPS/PPSPixelDigiProducer/data/PixelChargeMap_2X.txt");
139  desc.add<std::string>("ChargeMapFile2E_2Y", "SimPPS/PPSPixelDigiProducer/data/PixelChargeMap_2Y.txt");
140  desc.add<std::string>("ChargeMapFile2E_2X2Y", "SimPPS/PPSPixelDigiProducer/data/PixelChargeMap_2X2Y.txt");
141  desc.add<double>(
142  "RPixCoupling",
143  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
144 
145  // RPixDummyROCSimulator
146  desc.add<double>("RPixDummyROCThreshold", 1900.0);
147  desc.add<double>("RPixDummyROCElectronPerADC", 135.0); // 210.0 to be verified
148  desc.add<int>("VCaltoElectronGain", 50); // same values as in RPixDetClusterizer
149  desc.add<int>("VCaltoElectronOffset", -411); //
150  desc.add<bool>("doSingleCalibration", false); //
151  desc.add<double>("RPixDeadPixelProbability", 0.001);
152  desc.add<bool>("RPixDeadPixelSimulationOn", true);
153 
154  // CTPPSPixelSimTopology
155  desc.add<double>("RPixActiveEdgeSmearing", 0.020);
156  desc.add<double>("RPixActiveEdgePosition", 0.150);
157 
158  desc.add<std::string>("mixLabel", "mix");
159  desc.add<std::string>("InputCollection", "g4SimHitsCTPPSPixelHits");
160  descriptions.add("RPixDetDigitizer", desc);
161 }
162 
163 //
164 // member functions
165 //
166 
167 // ------------ method called to produce the data ------------
169  using namespace edm;
170  if (!rndEngine_) {
172  if (!rng.isAvailable()) {
173  throw cms::Exception("Configuration")
174  << "This class requires the RandomNumberGeneratorService\n"
175  "which is not present in the configuration file. You must add the service\n"
176  "in the configuration file or remove the modules that require it.";
177  }
178  rndEngine_ = &(rng->getEngine(iEvent.streamID()));
179  }
180 
181  // get calibration DB
183 
184  // Step A: Get Inputs
186 
187  iEvent.getByToken(tokenCrossingFramePPSPixel, cf);
188 
189  if (verbosity_) {
190  edm::LogInfo("PPSPixelDigiProducer") << "\n\n=================== Starting SimHit access"
191  << " ===================";
192 
193  MixCollection<PSimHit> col{cf.product(), std::pair(-0, 0)};
194  edm::LogInfo("PPSPixelDigiProducer") << col;
196  int count = 0;
197  for (cfi = col.begin(); cfi != col.end(); cfi++) {
198  edm::LogInfo("PPSPixelDigiProducer")
199  << " Hit " << count << " has tof " << cfi->timeOfFlight() << " trackid " << cfi->trackId() << " bunchcr "
200  << cfi.bunch() << " trigger " << cfi.getTrigger()
201  << ", from EncodedEventId: " << cfi->eventId().bunchCrossing() << " " << cfi->eventId().event()
202  << " bcr from MixCol " << cfi.bunch();
203  edm::LogInfo("PPSPixelDigiProducer") << " Hit: " << (*cfi) << " " << cfi->exitPoint();
204  count++;
205  }
206  }
207 
208  MixCollection<PSimHit> allRPixHits{cf.product(), std::pair(0, 0)};
209 
210  if (verbosity_)
211  edm::LogInfo("PPSPixelDigiProducer") << "Input MixCollection size = " << allRPixHits.size();
212 
213  //Loop on PSimHit
214  simhit_map SimHitMap;
215  SimHitMap.clear();
216 
218  for (isim = allRPixHits.begin(); isim != allRPixHits.end(); ++isim) {
219  SimHitMap[(*isim).detUnitId()].push_back((*isim));
220  }
221 
222  // Step B: LOOP on hits in event
223  std::vector<edm::DetSet<CTPPSPixelDigi>> theDigiVector;
224  theDigiVector.reserve(400);
225  theDigiVector.clear();
226 
227  for (simhit_map_iterator it = SimHitMap.begin(); it != SimHitMap.end(); ++it) {
228  edm::DetSet<CTPPSPixelDigi> digi_collector(it->first);
229 
230  if (theAlgoMap.find(it->first) == theAlgoMap.end()) {
231  theAlgoMap[it->first] =
232  std::make_unique<RPixDetDigitizer>(conf_, *rndEngine_, it->first, iSetup); //a digitizer for eny detector
233  }
234 
235  std::vector<int> input_links;
236  std::vector<std::vector<std::pair<int, double>>> output_digi_links; // links to simhits
237 
238  (theAlgoMap.find(it->first)->second)
239  ->run(
240  SimHitMap[it->first], input_links, digi_collector.data, output_digi_links, theGainCalibrationDB.getCalibs());
241 
242  if (!digi_collector.data.empty()) {
243  theDigiVector.push_back(digi_collector);
244  }
245  }
246 
247  std::unique_ptr<edm::DetSetVector<CTPPSPixelDigi>> digi_output(new edm::DetSetVector<CTPPSPixelDigi>(theDigiVector));
248 
249  if (verbosity_) {
250  edm::LogInfo("PPSPixelDigiProducer") << "digi_output->size()=" << digi_output->size();
251  }
252 
253  iEvent.put(std::move(digi_output));
254 }
255 
257 
258 #endif
ConfigurationDescriptions.h
CTPPSPixelDigiProducer::tokenCrossingFramePPSPixel
edm::EDGetTokenT< CrossingFrame< PSimHit > > tokenCrossingFramePPSPixel
Definition: PPSPixelDigiProducer.cc:100
edm::DetSetVector
Definition: DetSetVector.h:61
edm::RandomNumberGenerator::getEngine
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
CTPPSPixelAnalysisMaskRcd.h
CTPPSPixelDAQMappingRcd.h
edm::Handle::product
T const * product() const
Definition: Handle.h:70
ESHandle.h
edm::DetSet
Definition: DetSet.h:23
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
RandomNumberGenerator.h
CrossingFrame.h
cuy.col
col
Definition: cuy.py:1010
PSimHitContainer.h
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89287
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
EDProducer.h
RPixDetDigitizer.h
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
edm::Handle
Definition: AssociativeIterator.h:50
edm::Service::isAvailable
bool isAvailable() const
Definition: Service.h:40
MixCollection::MixItr
Definition: MixCollection.h:62
CTPPSPixelGainCalibrationDBService
Definition: CTPPSPixelGainCalibrationDBService.h:23
CTPPSPixelGainCalibrations.h
CTPPSPixelGainCalibrationDBService::getCalibs
const CTPPSPixelGainCalibrations * getCalibs() const
Definition: CTPPSPixelGainCalibrationDBService.h:28
MakerMacros.h
MixCollection::MixItr::bunch
int bunch() const
Definition: MixCollection.h:91
PSimHit.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
CTPPSPixelDigiProducer::CTPPSPixelDigiProducer
CTPPSPixelDigiProducer(const edm::ParameterSet &)
Definition: PPSPixelDigiProducer.cc:103
MixCollection.h
MixCollection
Definition: MixCollection.h:11
Service.h
CTPPSPixelDigiProducer::verbosity_
int verbosity_
Definition: PPSPixelDigiProducer.cc:96
MixCollection::MixItr::getTrigger
bool getTrigger() const
Definition: MixCollection.h:98
CTPPSPixelGainCalibrationDBService::getDB
virtual void getDB(const edm::Event &e, const edm::EventSetup &c)
Definition: CTPPSPixelGainCalibrationDBService.cc:25
submitPVResolutionJobs.count
count
Definition: submitPVResolutionJobs.py:352
ParameterSetDescription.h
CTPPSPixelDigiProducer::theAlgoMap
std::map< uint32_t, std::unique_ptr< RPixDetDigitizer > > theAlgoMap
Definition: PPSPixelDigiProducer.cc:93
CTPPSPixelDigiProducer::simhit_map
std::map< unsigned int, std::vector< PSimHit > > simhit_map
Definition: PPSPixelDigiProducer.cc:88
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
CLHEP
Definition: CocoaGlobals.h:27
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
CTPPSPixelAnalysisMask.h
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
CTPPSPixelDigiProducer
Definition: PPSPixelDigiProducer.cc:77
edm::Service
Definition: Service.h:30
iEvent
int iEvent
Definition: GenABIO.cc:224
CTPPSPixelDigiProducer::simhit_map_iterator
simhit_map::iterator simhit_map_iterator
Definition: PPSPixelDigiProducer.cc:89
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:57
DetSetVector.h
CTPPSPixelDigiProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: PPSPixelDigiProducer.cc:116
CTPPSPixelDigiProducer::rndEngine_
CLHEP::HepRandomEngine * rndEngine_
Definition: PPSPixelDigiProducer.cc:95
CTPPSPixelDigi.h
CTPPSPixelDigiProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: PPSPixelDigiProducer.cc:168
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
writedatasetfile.run
run
Definition: writedatasetfile.py:27
CTPPSPixelDAQMapping.h
Frameworkfwd.h
Exception
Definition: hltDiff.cc:246
CTPPSPixelDigiProducer::~CTPPSPixelDigiProducer
~CTPPSPixelDigiProducer() override
Definition: PPSPixelDigiProducer.cc:114
CTPPSPixelDigiProducer::theGainCalibrationDB
CTPPSPixelGainCalibrationDBService theGainCalibrationDB
Definition: PPSPixelDigiProducer.cc:98
edm::DetSet::data
collection_type data
Definition: DetSet.h:80
EventSetup.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
Exception.h
CTPPSPixelDigiProducer::conf_
edm::ParameterSet conf_
Definition: PPSPixelDigiProducer.cc:91
DetSet.h
ParameterSet.h
CTPPSPixelGainCalibrationDBService.h
edm::Event
Definition: Event.h:73
CTPPSPixelDigiCollection.h
CTPPSPixelDigiProducer::RPix_hit_containers_
std::vector< std::string > RPix_hit_containers_
Definition: PPSPixelDigiProducer.cc:87