CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CSCDigitizer.cc
Go to the documentation of this file.
13 #include <iostream>
14 
16  : theDriftSim(new CSCDriftSim()),
17  theWireHitSim(new CSCWireHitSim(theDriftSim, p)),
18  theStripHitSim(new CSCStripHitSim()),
19  theWireElectronicsSim(new CSCWireElectronicsSim(p.getParameter<edm::ParameterSet>("wires"))),
20  theStripElectronicsSim(new CSCStripElectronicsSim(p.getParameter<edm::ParameterSet>("strips"))),
21  theNeutronReader(nullptr),
22  theCSCGeometry(nullptr),
23  theLayersNeeded(p.getParameter<unsigned int>("layersNeeded")),
24  digitizeBadChambers_(p.getParameter<bool>("digitizeBadChambers")) {
25  if (p.getParameter<bool>("doNeutrons")) {
27  }
28 }
29 
31  delete theNeutronReader;
33  delete theWireElectronicsSim;
34  delete theStripHitSim;
35  delete theWireHitSim;
36  delete theDriftSim;
37 }
38 
40  CSCWireDigiCollection &wireDigis,
41  CSCStripDigiCollection &stripDigis,
42  CSCComparatorDigiCollection &comparators,
43  DigiSimLinks &wireDigiSimLinks,
44  DigiSimLinks &stripDigiSimLinks,
45  CLHEP::HepRandomEngine *engine) {
46  // arrange the hits by layer
47  std::map<int, edm::PSimHitContainer> hitMap;
48  for (MixCollection<PSimHit>::MixItr hitItr = simHits.begin(); hitItr != simHits.end(); ++hitItr) {
49  hitMap[hitItr->detUnitId()].push_back(*hitItr);
50  }
51 
52  // count how many layers on each chamber are hit
53  std::map<int, std::set<int>> layersInChamberHit;
54  for (std::map<int, edm::PSimHitContainer>::const_iterator hitMapItr = hitMap.begin(); hitMapItr != hitMap.end();
55  ++hitMapItr) {
56  CSCDetId cscDetId(hitMapItr->first);
57  int chamberId = cscDetId.chamberId();
58  layersInChamberHit[chamberId].insert(cscDetId.layer());
59  }
60 
61  // add neutron background, if needed
62  if (theNeutronReader != nullptr) {
63  theNeutronReader->addHits(hitMap, engine);
64  }
65 
66  // now loop over layers and run the simulation for each one
67  for (std::map<int, edm::PSimHitContainer>::const_iterator hitMapItr = hitMap.begin(); hitMapItr != hitMap.end();
68  ++hitMapItr) {
69  CSCDetId detId = CSCDetId(hitMapItr->first);
70  int chamberId = detId.chamberId();
71  int endc = detId.endcap();
72  int stat = detId.station();
73  int ring = detId.ring();
74  int cham = detId.chamber();
75 
76  unsigned int nLayersInChamberHitForWireDigis = 0;
77  if (stat == 1 && ring == 1) { // ME1b
78  std::set<int> layersInME1a = layersInChamberHit[CSCDetId(endc, stat, 4, cham, 0)];
79  std::set<int> layersInME11 = layersInChamberHit[chamberId];
80  layersInME11.insert(layersInME1a.begin(), layersInME1a.end());
81  nLayersInChamberHitForWireDigis = layersInME11.size();
82  } else if (stat == 1 && ring == 4) { // ME1a
83  std::set<int> layersInME1b = layersInChamberHit[CSCDetId(endc, stat, 1, cham, 0)];
84  std::set<int> layersInME11 = layersInChamberHit[chamberId];
85  layersInME11.insert(layersInME1b.begin(), layersInME1b.end());
86  nLayersInChamberHitForWireDigis = layersInME11.size();
87  } else
88  nLayersInChamberHitForWireDigis = layersInChamberHit[chamberId].size();
89 
90  unsigned int nLayersInChamberHitForStripDigis = layersInChamberHit[chamberId].size();
91 
92  if (nLayersInChamberHitForWireDigis < theLayersNeeded && nLayersInChamberHitForStripDigis < theLayersNeeded)
93  continue;
94  // skip bad chambers
95  if (!digitizeBadChambers_ && theConditions->isInBadChamber(CSCDetId(hitMapItr->first)))
96  continue;
97 
98  const CSCLayer *layer = findLayer(hitMapItr->first);
99  const edm::PSimHitContainer &layerSimHits = hitMapItr->second;
100 
101  std::vector<CSCDetectorHit> newWireHits, newStripHits;
102 
103  // LogTrace("CSCDigitizer") << "CSCDigitizer: found " <<
104  // layerSimHits.size() <<" hit(s) in layer"
105  edm::LogVerbatim("CSCDigitizer") << "[CSCDigitizer] found " << layerSimHits.size() << " hit(s) in layer"
106  << layer->id();
107  // << " E" << layer->id().endcap() << " S" << layer->id().station() <<
108  // " R" << layer->id().ring()
109  // << " C" << layer->id().chamber() << " L" << layer->id().layer();
110 
111  // turn the edm::PSimHits into WireHits, using the WireHitSim
112  { newWireHits.swap(theWireHitSim->simulate(layer, layerSimHits, engine)); }
113  if (!newWireHits.empty()) {
114  newStripHits.swap(theStripHitSim->simulate(layer, newWireHits));
115  }
116 
117  // turn the hits into wire digis, using the electronicsSim
118  if (nLayersInChamberHitForWireDigis >= theLayersNeeded) {
119  theWireElectronicsSim->simulate(layer, newWireHits, engine);
120  theWireElectronicsSim->fillDigis(wireDigis, engine);
121  wireDigiSimLinks.insert(theWireElectronicsSim->digiSimLinks());
122  }
123  if (nLayersInChamberHitForStripDigis >= theLayersNeeded) {
124  theStripElectronicsSim->simulate(layer, newStripHits, engine);
125  theStripElectronicsSim->fillDigis(stripDigis, comparators, engine);
126  stripDigiSimLinks.insert(theStripElectronicsSim->digiSimLinks());
127  }
128  }
129 
130  // fill in the layers were missing from this chamber
131  std::list<int> missingLayers = layersMissing(stripDigis);
132  for (std::list<int>::const_iterator missingLayerItr = missingLayers.begin(); missingLayerItr != missingLayers.end();
133  ++missingLayerItr) {
134  const CSCLayer *layer = findLayer(*missingLayerItr);
135  theStripElectronicsSim->fillMissingLayer(layer, comparators, stripDigis, engine);
136  }
137 }
138 
139 std::list<int> CSCDigitizer::layersMissing(const CSCStripDigiCollection &stripDigis) const {
140  std::list<int> result;
141 
142  std::map<int, std::list<int>> layersInChamberWithDigi;
143  for (CSCStripDigiCollection::DigiRangeIterator j = stripDigis.begin(); j != stripDigis.end(); j++) {
144  CSCDetId layerId((*j).first);
145  // make sure the vector of digis isn't empty
146  if ((*j).second.first != (*j).second.second) {
147  int chamberId = layerId.chamberId();
148  layersInChamberWithDigi[chamberId].push_back(layerId.layer());
149  }
150  }
151 
152  std::list<int> oneThruSix;
153  for (int i = 1; i <= 6; ++i)
154  oneThruSix.push_back(i);
155 
156  for (std::map<int, std::list<int>>::iterator layersInChamberWithDigiItr = layersInChamberWithDigi.begin();
157  layersInChamberWithDigiItr != layersInChamberWithDigi.end();
158  ++layersInChamberWithDigiItr) {
159  std::list<int> &layersHit = layersInChamberWithDigiItr->second;
160  if (layersHit.size() < 6 && layersHit.size() >= theLayersNeeded) {
161  layersHit.sort();
162  std::list<int> missingLayers(6);
163  std::list<int>::iterator lastLayerMissing = set_difference(
164  oneThruSix.begin(), oneThruSix.end(), layersHit.begin(), layersHit.end(), missingLayers.begin());
165  int chamberId = layersInChamberWithDigiItr->first;
166  for (std::list<int>::iterator layerMissingItr = missingLayers.begin(); layerMissingItr != lastLayerMissing;
167  ++layerMissingItr) {
168  // got from layer 1-6 to layer ID
169  result.push_back(chamberId + *layerMissingItr);
170  }
171  }
172  }
173  return result;
174 }
175 
177 
179  theConditions = cond; // cache here
180  theStripElectronicsSim->setStripConditions(cond); // percolate downwards
181 }
182 
184 
185 const CSCLayer *CSCDigitizer::findLayer(int detId) const {
186  assert(theCSCGeometry != nullptr);
187  const GeomDetUnit *detUnit = theCSCGeometry->idToDetUnit(CSCDetId(detId));
188  if (detUnit == nullptr) {
189  throw cms::Exception("CSCDigiProducer") << "Invalid DetUnit: " << CSCDetId(detId)
190  << "\nPerhaps your signal or pileup dataset are not compatible with "
191  "the current release?";
192  }
193  return dynamic_cast<const CSCLayer *>(detUnit);
194 }
int chamber() const
Definition: CSCDetId.h:62
CSCDriftSim * theDriftSim
Definition: CSCDigitizer.h:78
Log< level::Info, true > LogVerbatim
std::vector< CSCDetectorHit > & simulate(const CSCLayer *layer, const std::vector< CSCDetectorHit > &wireHits)
unsigned int theLayersNeeded
Definition: CSCDigitizer.h:86
HepPDT::ParticleDataTable ParticleDataTable
CSCDetId id() const
Definition: CSCLayer.h:39
std::vector< CSCDetectorHit > & simulate(const CSCLayer *layer, const edm::PSimHitContainer &simHits, CLHEP::HepRandomEngine *)
const CSCLayer * findLayer(int detId) const
finds the layer in the geometry associated with this det ID
void setStripConditions(CSCStripConditions *cond)
assert(be >=bs)
int layer() const
Definition: CSCDetId.h:56
std::list< int > layersMissing(const CSCStripDigiCollection &stripDigis) const
finds which layers, 1-6, aren&#39;t in the current list
CSCDigitizer(const CSCDigitizer &)=delete
constexpr std::array< uint8_t, layerIndexSize > layer
tuple result
Definition: mps_fire.py:311
void setMagneticField(const MagneticField *field)
Definition: CSCDriftSim.h:47
int endcap() const
Definition: CSCDetId.h:85
bool digitizeBadChambers_
Definition: CSCDigitizer.h:87
const DigiSimLinks & digiSimLinks() const
CSCStripElectronicsSim * theStripElectronicsSim
Definition: CSCDigitizer.h:82
CSCNeutronReader * theNeutronReader
Definition: CSCDigitizer.h:83
const CSCGeometry * theCSCGeometry
Definition: CSCDigitizer.h:84
void fillDigis(CSCWireDigiCollection &digis, CLHEP::HepRandomEngine *)
iterator end() const
CSCDetId chamberId() const
Definition: CSCDetId.h:47
void fillMissingLayer(const CSCLayer *layer, const CSCComparatorDigiCollection &comparators, CSCStripDigiCollection &digis, CLHEP::HepRandomEngine *)
void setStripConditions(CSCStripConditions *cond)
CSCWireHitSim * theWireHitSim
Definition: CSCDigitizer.h:79
int ring() const
Definition: CSCDetId.h:68
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
tuple simHits
Definition: trackerHits.py:16
void setParticleDataTable(const ParticleDataTable *pdt)
void doAction(MixCollection< PSimHit > &simHits, CSCWireDigiCollection &wireDigis, CSCStripDigiCollection &stripDigis, CSCComparatorDigiCollection &comparators, DigiSimLinks &wireDigiSimLinks, DigiSimLinks &stripDigiSimLinks, CLHEP::HepRandomEngine *)
Definition: CSCDigitizer.cc:39
void insert(detset const &s)
Insert the given DetSet.
Definition: DetSetVector.h:220
CSCWireElectronicsSim * theWireElectronicsSim
Definition: CSCDigitizer.h:81
void fillDigis(CSCStripDigiCollection &digis, CSCComparatorDigiCollection &comparators, CLHEP::HepRandomEngine *)
void addHits(std::map< int, edm::PSimHitContainer > &hitMap, CLHEP::HepRandomEngine *)
int station() const
Definition: CSCDetId.h:79
std::vector< PSimHit > PSimHitContainer
virtual bool isInBadChamber(const CSCDetId &id) const
is supplied layer/chamber flagged as bad? (default impl. is no)
iterator begin() const
void simulate(const CSCLayer *layer, const std::vector< CSCDetectorHit > &inputHits, CLHEP::HepRandomEngine *)
void setMagneticField(const MagneticField *field)
sets the magnetic field
void setParticleDataTable(const ParticleDataTable *pdt)
std::vector< std::string > set_difference(std::vector< std::string > const &v1, std::vector< std::string > const &v2)
CSCStripHitSim * theStripHitSim
Definition: CSCDigitizer.h:80
const GeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
Definition: CSCGeometry.cc:89
CSCStripConditions * theConditions
Definition: CSCDigitizer.h:85