CMS 3D CMS Logo

RPDigiProducer.cc
Go to the documentation of this file.
1 // user include files
13 
18 
24 
25 //Random Number
28 
34 
35 // system include files
36 #include <memory>
37 #include <vector>
38 #include <map>
39 #include <string>
40 #include <iostream>
41 #include <cstdlib> // I need it for random numbers
42 
43 // user include files
44 
45 //
46 // class decleration
47 //
48 
49 namespace CLHEP {
50  class HepRandomEngine;
51 }
52 
54 public:
55  explicit RPDigiProducer(const edm::ParameterSet&);
56  ~RPDigiProducer() override;
57 
58  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
59 
60 private:
61  void beginRun(const edm::Run&, const edm::EventSetup&) override;
62  void produce(edm::Event&, const edm::EventSetup&) override;
63 
65 
66  // ----------member data ---------------------------
67  std::vector<std::string> RP_hit_containers_;
68  typedef std::map<unsigned int, std::vector<PSimHit>> simhit_map;
69  typedef simhit_map::iterator simhit_map_iterator;
70 
72  std::map<RPDetId, std::unique_ptr<RPDetDigitizer>> theAlgoMap;
73 
74  CLHEP::HepRandomEngine* rndEngine_ = nullptr;
76 
86 
88 };
89 
91  //now do what ever other initialization is needed
92  produces<edm::DetSetVector<TotemRPDigi>>();
93 
94  // register data to consume
95  tokenCrossingFrameTotemRP = consumes<CrossingFrame<PSimHit>>(edm::InputTag("mix", "g4SimHitsTotemHitsRP", ""));
96 
97  RP_hit_containers_ = conf.getParameter<std::vector<std::string>>("ROUList");
98  verbosity_ = conf.getParameter<int>("RPVerbosity");
99 
100  simulateDeadChannels = false;
101  if (conf.exists(
102  "simulateDeadChannels")) { //check if "simulateDeadChannels" variable is defined in configuration file
103  simulateDeadChannels = conf.getParameter<bool>("simulateDeadChannels");
104  }
105 }
106 
108  // do anything here that needs to be done at desctruction time
109  // (e.g. close files, deallocate resources etc.)
110 }
111 //
112 // member functions
113 //
114 
115 // ------------ method called to produce the data ------------
117  using namespace edm;
118 
119  // initialize random engine
120  if (!rndEngine_) {
122  if (!rng.isAvailable()) {
123  throw cms::Exception("Configuration")
124  << "This class requires the RandomNumberGeneratorService\n"
125  "which is not present in the configuration file. You must add the service\n"
126  "in the configuration file or remove the modules that require it.";
127  }
128  rndEngine_ = &(rng->getEngine(iEvent.streamID()));
129  }
130 
131  // Step A: Get Inputs
133  iEvent.getByLabel("mix", "g4SimHitsTotemHitsRP", cf);
134 
135  if (verbosity_) {
136  edm::LogInfo("RPDigiProducer") << "\n\n=================== Starting SimHit access"
137  << " ==================="
138  << "\n";
139 
140  MixCollection<PSimHit> col{cf.product(), std::pair(-0, 0)};
142  int count = 0;
143  for (cfi = col.begin(); cfi != col.end(); cfi++) {
144  edm::LogInfo("RPDigiProducer") << " Hit " << count << " has tof " << cfi->timeOfFlight() << " trackid "
145  << cfi->trackId() << " bunchcr " << cfi.bunch() << " trigger " << cfi.getTrigger()
146  << ", from EncodedEventId: " << cfi->eventId().bunchCrossing() << " "
147  << cfi->eventId().event() << " bcr from MixCol " << cfi.bunch() << "\n";
148  edm::LogInfo("RPDigiProducer") << " Hit: " << (*cfi) << "\n";
149  count++;
150  }
151  }
152 
153  MixCollection<PSimHit> allRPHits{cf.product(), std::pair(0, 0)};
154 
155  if (verbosity_)
156  edm::LogInfo("RPDigiProducer") << "Input MixCollection size = " << allRPHits.size() << "\n";
157 
158  //Loop on PSimHit
159  simhit_map simHitMap_;
160  simHitMap_.clear();
161 
163  for (isim = allRPHits.begin(); isim != allRPHits.end(); ++isim) {
164  simHitMap_[(*isim).detUnitId()].push_back((*isim));
165  }
166 
167  // Step B: LOOP on hits in event
168  std::vector<edm::DetSet<TotemRPDigi>> DigiVector;
169  DigiVector.reserve(400);
170  DigiVector.clear();
171 
172  for (simhit_map_iterator it = simHitMap_.begin(); it != simHitMap_.end(); ++it) {
173  edm::DetSet<TotemRPDigi> digi_collector(it->first);
174 
175  if (theAlgoMap.find(it->first) == theAlgoMap.end()) {
176  theAlgoMap[it->first] = std::make_unique<RPDetDigitizer>(conf_, *rndEngine_, it->first, iSetup);
177  }
178 
179  std::vector<int> input_links;
180  simromanpot::DigiPrimaryMapType output_digi_links;
181 
182  (theAlgoMap.find(it->first)->second)
183  ->run(simHitMap_[it->first], input_links, digi_collector.data, output_digi_links);
184 
185  if (!digi_collector.data.empty()) {
186  DigiVector.push_back(convertRPStripDetSet(digi_collector));
187  }
188  }
189 
190  // Step C: create empty output collection
191  std::unique_ptr<edm::DetSetVector<TotemRPDigi>> digi_output(new edm::DetSetVector<TotemRPDigi>(DigiVector));
192 
193  if (verbosity_) {
194  edm::LogInfo("RPDigiProducer") << "digi_output->size()=" << digi_output->size() << "\n";
195  }
196  // Step D: write output to file
197  iEvent.put(std::move(digi_output));
198 }
199 
200 // ------------ method called once each job just before starting event loop ------------
201 void RPDigiProducer::beginRun(const edm::Run& beginrun, const edm::EventSetup& es) {
202  // get analysis mask to mask channels
203  if (simulateDeadChannels) {
205  es.get<TotemReadoutRcd>().get(analysisMask);
206  deadChannelsManager = DeadChannelsManager(analysisMask); //set analysisMask in deadChannelsManager
207  }
208 }
209 
211  edm::DetSet<TotemRPDigi> rpdigi_detset(rpstrip_detset.detId());
212  rpdigi_detset.reserve(rpstrip_detset.size());
213 
214  for (std::vector<TotemRPDigi>::const_iterator stripIterator = rpstrip_detset.data.begin();
215  stripIterator < rpstrip_detset.data.end();
216  ++stripIterator) {
217  rpdigi_detset.push_back(TotemRPDigi(stripIterator->stripNumber()));
218  }
219 
220  return rpdigi_detset;
221 }
222 
224  //RPSiDetDigitizer
225  //all distances in [mm]
227  desc.add<bool>("RPLandauFluctuations", true);
228  desc.add<bool>("RPDisplacementOn", false);
229  desc.add<int>("RPVerbosity", 0);
230  desc.add<double>("RPVFATThreshold", 9000.0);
231  desc.add<double>("RPTopEdgePosition", 1.5);
232  desc.add<double>("RPActiveEdgeSmearing", 0.013);
233  desc.add<double>("RPEquivalentNoiseCharge300um", 1000.0);
234  desc.add<int>("RPVFATTriggerMode", 2);
235  desc.add<std::vector<double>>("RPInterStripSmearing",
236  {
237  0.011,
238  });
239  desc.add<double>("RPSharingSigmas", 5.0); //how many sigmas taken into account for the edges and inter strips
240  desc.add<double>("RPGeVPerElectron", 3.61e-09);
241  desc.add<double>("RPActiveEdgePosition", 0.034); //from the physical edge
242  desc.add<bool>("RPDeadStripSimulationOn", false);
243  desc.add<std::vector<std::string>>("ROUList",
244  {
245  "TotemHitsRP",
246  });
247  desc.add<bool>("RPNoNoise", false);
248  desc.add<bool>("RPDigiSimHitRelationsPresistence", false); //save links betweend digi, clusters and OSCAR/Geant4 hits
249  desc.add<std::string>("mixLabel", "mix");
250  desc.add<int>("RPChargeDivisionsPerThickness", 5);
251  desc.add<double>("RPDeltaProductionCut", 0.120425); //[MeV]
252  desc.add<double>("RPBottomEdgePosition", 1.5);
253  desc.add<double>("RPBottomEdgeSmearing", 0.011);
254  desc.add<double>("RPTopEdgeSmearing", 0.011);
255  desc.add<std::string>("InputCollection", "g4SimHitsTotemHitsRP");
256  desc.add<double>("RPInterStripCoupling",
257  1.0); //fraction of charge going to the strip, the missing part is taken by its neighbours
258  desc.add<double>("RPDeadStripProbability", 0.001);
259  desc.add<int>("RPChargeDivisionsPerStrip", 15);
260  descriptions.add("RPSiDetDigitizer", desc);
261 }
262 
ConfigurationDescriptions.h
edm::DetSetVector
Definition: DetSetVector.h:61
edm::RandomNumberGenerator::getEngine
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
simromanpot::DigiPrimaryMapType
std::vector< std::vector< std::pair< int, double > > > DigiPrimaryMapType
Definition: RPSimTypes.h:22
TotemReadoutRcd.h
RPDigiProducer::theAlgoMap
std::map< RPDetId, std::unique_ptr< RPDetDigitizer > > theAlgoMap
Definition: RPDigiProducer.cc:72
MessageLogger.h
edm::Handle::product
T const * product() const
Definition: Handle.h:70
EDProducer.h
ESHandle.h
edm::DetSet::size
size_type size() const
Definition: DetSet.h:61
edm::DetSet
Definition: DetSet.h:23
edm::Run
Definition: Run.h:45
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:89353
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
RPDigiProducer::RPDigiProducer
RPDigiProducer(const edm::ParameterSet &)
Definition: RPDigiProducer.cc:90
RPDigiProducer::simhit_map
std::map< unsigned int, std::vector< PSimHit > > simhit_map
Definition: RPDigiProducer.cc:68
TotemReadoutRcd
EventSetup record for TOTEM readout-related information.
Definition: TotemReadoutRcd.h:16
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
RPDigiProducer::conf_
edm::ParameterSet conf_
Definition: RPDigiProducer.cc:71
DeadChannelsManager
Definition: DeadChannelsManager.h:14
MakerMacros.h
MixCollection::MixItr::bunch
int bunch() const
Definition: MixCollection.h:91
PSimHit.h
edm::EventSetup::get
T get() const
Definition: EventSetup.h:80
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
MixCollection.h
MixCollection
Definition: MixCollection.h:11
TotemRPDigi
Definition: TotemRPDigi.h:15
Service.h
MixCollection::MixItr::getTrigger
bool getTrigger() const
Definition: MixCollection.h:98
RPDigiProducer::verbosity_
int verbosity_
Definition: RPDigiProducer.cc:75
edm::ESHandle< TotemAnalysisMask >
TotemAnalysisMask.h
submitPVResolutionJobs.count
count
Definition: submitPVResolutionJobs.py:352
RPDigiProducer::RP_hit_containers_
std::vector< std::string > RP_hit_containers_
Definition: RPDigiProducer.cc:67
ParameterSetDescription.h
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
CLHEP
Definition: CocoaGlobals.h:27
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
RPDigiProducer::~RPDigiProducer
~RPDigiProducer() override
Definition: RPDigiProducer.cc:107
edm::ParameterSet::exists
bool exists(std::string const &parameterName) const
checks if a parameter exists
Definition: ParameterSet.cc:681
RPDigiProducer::simulateDeadChannels
bool simulateDeadChannels
Definition: RPDigiProducer.cc:85
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
RPDigiProducer::simhit_map_iterator
simhit_map::iterator simhit_map_iterator
Definition: RPDigiProducer.cc:69
edm::Service
Definition: Service.h:30
iEvent
int iEvent
Definition: GenABIO.cc:224
RPDigiProducer
Definition: RPDigiProducer.cc:53
RPDigiProducer::rndEngine_
CLHEP::HepRandomEngine * rndEngine_
Definition: RPDigiProducer.cc:74
edm::EventSetup
Definition: EventSetup.h:57
edm::DetSet::detId
det_id_type detId() const
Definition: DetSet.h:74
DetSetVector.h
RPDigiProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: RPDigiProducer.cc:223
get
#define get
RPSimTypes.h
edm::DetSet::reserve
void reserve(size_t s)
Definition: DetSet.h:65
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
RPDigiProducer::deadChannelsManager
DeadChannelsManager deadChannelsManager
Definition: RPDigiProducer.cc:80
Frameworkfwd.h
Exception
Definition: hltDiff.cc:246
DeadChannelsManager.h
TotemRPDetId.h
edm::DetSet::data
collection_type data
Definition: DetSet.h:80
EventSetup.h
edm::EDProducer
Definition: EDProducer.h:35
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
Exception.h
RPDigiProducer::convertRPStripDetSet
edm::DetSet< TotemRPDigi > convertRPStripDetSet(const edm::DetSet< TotemRPDigi > &)
Definition: RPDigiProducer.cc:210
RPDetDigitizer.h
DetSet.h
RPDigiProducer::tokenCrossingFrameTotemRP
edm::EDGetTokenT< CrossingFrame< PSimHit > > tokenCrossingFrameTotemRP
Definition: RPDigiProducer.cc:87
ParameterSet.h
TotemRPDigi.h
edm::Event
Definition: Event.h:73
RPDigiProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: RPDigiProducer.cc:116
RPDigiProducer::beginRun
void beginRun(const edm::Run &, const edm::EventSetup &) override
Definition: RPDigiProducer.cc:201