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] =
177  std::unique_ptr<RPDetDigitizer>(new RPDetDigitizer(conf_, *rndEngine_, it->first, iSetup));
178  }
179 
180  std::vector<int> input_links;
181  simromanpot::DigiPrimaryMapType output_digi_links;
182 
183  (theAlgoMap.find(it->first)->second)
184  ->run(simHitMap_[it->first], input_links, digi_collector.data, output_digi_links);
185 
186  if (!digi_collector.data.empty()) {
187  DigiVector.push_back(convertRPStripDetSet(digi_collector));
188  }
189  }
190 
191  // Step C: create empty output collection
192  std::unique_ptr<edm::DetSetVector<TotemRPDigi>> digi_output(new edm::DetSetVector<TotemRPDigi>(DigiVector));
193 
194  if (verbosity_) {
195  edm::LogInfo("RPDigiProducer") << "digi_output->size()=" << digi_output->size() << "\n";
196  }
197  // Step D: write output to file
198  iEvent.put(std::move(digi_output));
199 }
200 
201 // ------------ method called once each job just before starting event loop ------------
202 void RPDigiProducer::beginRun(const edm::Run& beginrun, const edm::EventSetup& es) {
203  // get analysis mask to mask channels
204  if (simulateDeadChannels) {
206  es.get<TotemReadoutRcd>().get(analysisMask);
207  deadChannelsManager = DeadChannelsManager(analysisMask); //set analysisMask in deadChannelsManager
208  }
209 }
210 
212  edm::DetSet<TotemRPDigi> rpdigi_detset(rpstrip_detset.detId());
213  rpdigi_detset.reserve(rpstrip_detset.size());
214 
215  for (std::vector<TotemRPDigi>::const_iterator stripIterator = rpstrip_detset.data.begin();
216  stripIterator < rpstrip_detset.data.end();
217  ++stripIterator) {
218  rpdigi_detset.push_back(TotemRPDigi(stripIterator->stripNumber()));
219  }
220 
221  return rpdigi_detset;
222 }
223 
225  //RPSiDetDigitizer
226  //all distances in [mm]
228  desc.add<bool>("RPLandauFluctuations", true);
229  desc.add<bool>("RPDisplacementOn", false);
230  desc.add<int>("RPVerbosity", 0);
231  desc.add<double>("RPVFATThreshold", 9000.0);
232  desc.add<double>("RPTopEdgePosition", 1.5);
233  desc.add<double>("RPActiveEdgeSmearing", 0.013);
234  desc.add<double>("RPEquivalentNoiseCharge300um", 1000.0);
235  desc.add<int>("RPVFATTriggerMode", 2);
236  desc.add<std::vector<double>>("RPInterStripSmearing",
237  {
238  0.011,
239  });
240  desc.add<double>("RPSharingSigmas", 5.0); //how many sigmas taken into account for the edges and inter strips
241  desc.add<double>("RPGeVPerElectron", 3.61e-09);
242  desc.add<double>("RPActiveEdgePosition", 0.034); //from the physical edge
243  desc.add<bool>("RPDeadStripSimulationOn", false);
244  desc.add<std::vector<std::string>>("ROUList",
245  {
246  "TotemHitsRP",
247  });
248  desc.add<bool>("RPNoNoise", false);
249  desc.add<bool>("RPDigiSimHitRelationsPresistence", false); //save links betweend digi, clusters and OSCAR/Geant4 hits
250  desc.add<std::string>("mixLabel", "mix");
251  desc.add<int>("RPChargeDivisionsPerThickness", 5);
252  desc.add<double>("RPDeltaProductionCut", 0.120425); //[MeV]
253  desc.add<double>("RPBottomEdgePosition", 1.5);
254  desc.add<double>("RPBottomEdgeSmearing", 0.011);
255  desc.add<double>("RPTopEdgeSmearing", 0.011);
256  desc.add<std::string>("InputCollection", "g4SimHitsTotemHitsRP");
257  desc.add<double>("RPInterStripCoupling",
258  1.0); //fraction of charge going to the strip, the missing part is taken by its neighbours
259  desc.add<double>("RPDeadStripProbability", 0.001);
260  desc.add<int>("RPChargeDivisionsPerStrip", 15);
261  descriptions.add("RPSiDetDigitizer", desc);
262 }
263 
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
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
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
edm::LogInfo
Definition: MessageLogger.h:254
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
RPDetDigitizer
Definition: RPDetDigitizer.h:24
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::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:73
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
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:674
RPDigiProducer::simulateDeadChannels
bool simulateDeadChannels
Definition: RPDigiProducer.cc:85
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
RPDigiProducer::simhit_map_iterator
simhit_map::iterator simhit_map_iterator
Definition: RPDigiProducer.cc:69
KineDebug3::count
void count()
Definition: KinematicConstrainedVertexUpdatorT.h:21
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:224
get
#define get
RPSimTypes.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
edm::DetSet::reserve
void reserve(size_t s)
Definition: DetSet.h:65
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:36
Exception.h
RPDigiProducer::convertRPStripDetSet
edm::DetSet< TotemRPDigi > convertRPStripDetSet(const edm::DetSet< TotemRPDigi > &)
Definition: RPDigiProducer.cc:211
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:202