CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RPDigiProducer.cc
Go to the documentation of this file.
1 // user include files
12 
17 
23 
24 //Random Number
27 
33 
34 // system include files
35 #include <memory>
36 #include <vector>
37 #include <map>
38 #include <string>
39 #include <iostream>
40 #include <cstdlib> // I need it for random numbers
41 
42 // user include files
43 
44 //
45 // class decleration
46 //
47 
48 namespace CLHEP {
49  class HepRandomEngine;
50 }
51 
53 public:
54  explicit RPDigiProducer(const edm::ParameterSet&);
55  ~RPDigiProducer() override = default;
56 
57  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
58 
59 private:
60  void beginRun(const edm::Run&, const edm::EventSetup&) override;
61  void produce(edm::Event&, const edm::EventSetup&) override;
62 
64 
65  // ----------member data ---------------------------
66  std::vector<std::string> RP_hit_containers_;
67  typedef std::map<unsigned int, std::vector<PSimHit>> simhit_map;
68  typedef simhit_map::iterator simhit_map_iterator;
69 
71  std::map<RPDetId, std::unique_ptr<RPDetDigitizer>> theAlgoMap;
72 
73  CLHEP::HepRandomEngine* rndEngine_ = nullptr;
75 
85 
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  if (simulateDeadChannels) {
107  }
108 }
109 
110 //
111 // member functions
112 //
113 
114 // ------------ method called to produce the data ------------
116  using namespace edm;
117 
118  // initialize random engine
119  if (!rndEngine_) {
121  if (!rng.isAvailable()) {
122  throw cms::Exception("Configuration")
123  << "This class requires the RandomNumberGeneratorService\n"
124  "which is not present in the configuration file. You must add the service\n"
125  "in the configuration file or remove the modules that require it.";
126  }
127  rndEngine_ = &(rng->getEngine(iEvent.streamID()));
128  }
129 
130  // Step A: Get Inputs
132  iEvent.getByLabel("mix", "g4SimHitsTotemHitsRP", cf);
133 
134  if (verbosity_) {
135  edm::LogInfo("RPDigiProducer") << "\n\n=================== Starting SimHit access"
136  << " ==================="
137  << "\n";
138 
139  MixCollection<PSimHit> col{cf.product(), std::pair(-0, 0)};
141  int count = 0;
142  for (cfi = col.begin(); cfi != col.end(); cfi++) {
143  edm::LogInfo("RPDigiProducer") << " Hit " << count << " has tof " << cfi->timeOfFlight() << " trackid "
144  << cfi->trackId() << " bunchcr " << cfi.bunch() << " trigger " << cfi.getTrigger()
145  << ", from EncodedEventId: " << cfi->eventId().bunchCrossing() << " "
146  << cfi->eventId().event() << " bcr from MixCol " << cfi.bunch() << "\n";
147  edm::LogInfo("RPDigiProducer") << " Hit: " << (*cfi) << "\n";
148  count++;
149  }
150  }
151 
152  MixCollection<PSimHit> allRPHits{cf.product(), std::pair(0, 0)};
153 
154  if (verbosity_)
155  edm::LogInfo("RPDigiProducer") << "Input MixCollection size = " << allRPHits.size() << "\n";
156 
157  //Loop on PSimHit
158  simhit_map simHitMap_;
159  simHitMap_.clear();
160 
162  for (isim = allRPHits.begin(); isim != allRPHits.end(); ++isim) {
163  simHitMap_[(*isim).detUnitId()].push_back((*isim));
164  }
165 
166  // Step B: LOOP on hits in event
167  std::vector<edm::DetSet<TotemRPDigi>> DigiVector;
168  DigiVector.reserve(400);
169  DigiVector.clear();
170 
171  for (simhit_map_iterator it = simHitMap_.begin(); it != simHitMap_.end(); ++it) {
172  edm::DetSet<TotemRPDigi> digi_collector(it->first);
173 
174  if (theAlgoMap.find(it->first) == theAlgoMap.end()) {
175  theAlgoMap[it->first] = std::make_unique<RPDetDigitizer>(conf_, *rndEngine_, it->first, iSetup);
176  }
177 
178  std::vector<int> input_links;
179  simromanpot::DigiPrimaryMapType output_digi_links;
180 
181  (theAlgoMap.find(it->first)->second)
182  ->run(simHitMap_[it->first], input_links, digi_collector.data, output_digi_links);
183 
184  if (!digi_collector.data.empty()) {
185  DigiVector.push_back(convertRPStripDetSet(digi_collector));
186  }
187  }
188 
189  // Step C: create empty output collection
190  std::unique_ptr<edm::DetSetVector<TotemRPDigi>> digi_output(new edm::DetSetVector<TotemRPDigi>(DigiVector));
191 
192  if (verbosity_) {
193  edm::LogInfo("RPDigiProducer") << "digi_output->size()=" << digi_output->size() << "\n";
194  }
195  // Step D: write output to file
196  iEvent.put(std::move(digi_output));
197 }
198 
199 // ------------ method called once each job just before starting event loop ------------
200 void RPDigiProducer::beginRun(const edm::Run& beginrun, const edm::EventSetup& es) {
201  // get analysis mask to mask channels
202  if (simulateDeadChannels) {
203  //set analysisMask in deadChannelsManager
205  }
206 }
207 
209  edm::DetSet<TotemRPDigi> rpdigi_detset(rpstrip_detset.detId());
210  rpdigi_detset.reserve(rpstrip_detset.size());
211 
212  for (std::vector<TotemRPDigi>::const_iterator stripIterator = rpstrip_detset.data.begin();
213  stripIterator < rpstrip_detset.data.end();
214  ++stripIterator) {
215  rpdigi_detset.push_back(TotemRPDigi(stripIterator->stripNumber()));
216  }
217 
218  return rpdigi_detset;
219 }
220 
222  //RPSiDetDigitizer
223  //all distances in [mm]
225  desc.add<bool>("RPLandauFluctuations", true);
226  desc.add<bool>("RPDisplacementOn", false);
227  desc.add<int>("RPVerbosity", 0);
228  desc.add<double>("RPVFATThreshold", 9000.0);
229  desc.add<double>("RPTopEdgePosition", 1.5);
230  desc.add<double>("RPActiveEdgeSmearing", 0.013);
231  desc.add<double>("RPEquivalentNoiseCharge300um", 1000.0);
232  desc.add<int>("RPVFATTriggerMode", 2);
233  desc.add<std::vector<double>>("RPInterStripSmearing",
234  {
235  0.011,
236  });
237  desc.add<double>("RPSharingSigmas", 5.0); //how many sigmas taken into account for the edges and inter strips
238  desc.add<double>("RPGeVPerElectron", 3.61e-09);
239  desc.add<double>("RPActiveEdgePosition", 0.034); //from the physical edge
240  desc.add<bool>("RPDeadStripSimulationOn", false);
241  desc.add<std::vector<std::string>>("ROUList",
242  {
243  "TotemHitsRP",
244  });
245  desc.add<bool>("RPNoNoise", false);
246  desc.add<bool>("RPDigiSimHitRelationsPresistence", false); //save links betweend digi, clusters and OSCAR/Geant4 hits
247  desc.add<std::string>("mixLabel", "mix");
248  desc.add<int>("RPChargeDivisionsPerThickness", 5);
249  desc.add<double>("RPDeltaProductionCut", 0.120425); //[MeV]
250  desc.add<double>("RPBottomEdgePosition", 1.5);
251  desc.add<double>("RPBottomEdgeSmearing", 0.011);
252  desc.add<double>("RPTopEdgeSmearing", 0.011);
253  desc.add<std::string>("InputCollection", "g4SimHitsTotemHitsRP");
254  desc.add<double>("RPInterStripCoupling",
255  1.0); //fraction of charge going to the strip, the missing part is taken by its neighbours
256  desc.add<double>("RPDeadStripProbability", 0.001);
257  desc.add<int>("RPChargeDivisionsPerStrip", 15);
258  descriptions.add("RPSiDetDigitizer", desc);
259 }
260 
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
std::map< unsigned int, std::vector< PSimHit > > simhit_map
det_id_type detId() const
Definition: DetSet.h:74
edm::DetSet< TotemRPDigi > convertRPStripDetSet(const edm::DetSet< TotemRPDigi > &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
simhit_map::iterator simhit_map_iterator
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::vector< std::vector< std::pair< int, double > > > DigiPrimaryMapType
Definition: RPSimTypes.h:22
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
bool getTrigger() const
Definition: MixCollection.h:97
size_type size() const
Definition: DetSet.h:61
bool getData(T &iHolder) const
Definition: EventSetup.h:128
edm::ESGetToken< TotemAnalysisMask, TotemReadoutRcd > tokenAnalysisMask
void reserve(size_t s)
Definition: DetSet.h:65
int iEvent
Definition: GenABIO.cc:224
edm::ParameterSet conf_
std::map< RPDetId, std::unique_ptr< RPDetDigitizer > > theAlgoMap
~RPDigiProducer() override=default
def move
Definition: eostools.py:511
bool isAvailable() const
Definition: Service.h:40
RPDigiProducer(const edm::ParameterSet &)
edm::EDGetTokenT< CrossingFrame< PSimHit > > tokenCrossingFrameTotemRP
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:500
std::vector< std::string > RP_hit_containers_
Log< level::Info, false > LogInfo
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void add(std::string const &label, ParameterSetDescription const &psetDescription)
collection_type data
Definition: DetSet.h:80
void produce(edm::Event &, const edm::EventSetup &) override
DeadChannelsManager deadChannelsManager
StreamID streamID() const
Definition: Event.h:98
int col
Definition: cuy.py:1009
Definition: Run.h:45
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void beginRun(const edm::Run &, const edm::EventSetup &) override
CLHEP::HepRandomEngine * rndEngine_