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 
64  edm::DetSet<TotemRPDigi> convertRPStripDetSet(const edm::DetSet<TotemRPDigi>&);
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 
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
std::map< unsigned int, std::vector< PSimHit > > simhit_map
det_id_type detId() const
Definition: DetSet.h:75
edm::DetSet< TotemRPDigi > convertRPStripDetSet(const edm::DetSet< TotemRPDigi > &)
EventSetup record for TOTEM readout-related information.
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:98
size_type size() const
Definition: DetSet.h:62
void reserve(size_t s)
Definition: DetSet.h:66
int iEvent
Definition: GenABIO.cc:224
edm::ParameterSet conf_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
~RPDigiProducer() override
std::map< RPDetId, std::unique_ptr< RPDetDigitizer > > theAlgoMap
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:488
std::vector< std::string > RP_hit_containers_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
T const * product() const
Definition: Handle.h:69
void add(std::string const &label, ParameterSetDescription const &psetDescription)
collection_type data
Definition: DetSet.h:81
void produce(edm::Event &, const edm::EventSetup &) override
HLT enums.
DeadChannelsManager deadChannelsManager
T get() const
Definition: EventSetup.h:73
StreamID streamID() const
Definition: Event.h:96
col
Definition: cuy.py:1010
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:45
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void beginRun(const edm::Run &, const edm::EventSetup &) override
CLHEP::HepRandomEngine * rndEngine_