CMS 3D CMS Logo

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")) {
26  theNeutronReader = new CSCNeutronReader(p.getParameter<edm::ParameterSet>("neutrons"));
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 }
CSCWireElectronicsSim::fillDigis
void fillDigis(CSCWireDigiCollection &digis, CLHEP::HepRandomEngine *)
Definition: CSCWireElectronicsSim.cc:28
edm::DetSetVector
Definition: DetSetVector.h:61
electrons_cff.bool
bool
Definition: electrons_cff.py:393
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
CSCStripElectronicsSim.h
CSCStripElectronicsSim::setStripConditions
void setStripConditions(CSCStripConditions *cond)
Definition: CSCStripElectronicsSim.h:42
CSCDigitizer::theWireHitSim
CSCWireHitSim * theWireHitSim
Definition: CSCDigitizer.h:79
GeomDet
Definition: GeomDet.h:27
CSCDigitizer::setMagneticField
void setMagneticField(const MagneticField *field)
sets the magnetic field
Definition: CSCDigitizer.cc:176
CSCStripElectronicsSim
Definition: CSCStripElectronicsSim.h:28
relativeConstraints.cham
cham
Definition: relativeConstraints.py:69
CSCStripHitSim::simulate
std::vector< CSCDetectorHit > & simulate(const CSCLayer *layer, const std::vector< CSCDetectorHit > &wireHits)
Definition: CSCStripHitSim.cc:10
edm
HLT enums.
Definition: AlignableModifier.h:19
CSCDetId::ring
int ring() const
Definition: CSCDetId.h:68
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
CSCDigitizer::theConditions
CSCStripConditions * theConditions
Definition: CSCDigitizer.h:85
CSCStripDigiCollection
CSCDigitizer::digitizeBadChambers_
bool digitizeBadChambers_
Definition: CSCDigitizer.h:87
cms::cuda::assert
assert(be >=bs)
CSCDigitizer.h
FastTrackerRecHitCombiner_cfi.simHits
simHits
Definition: FastTrackerRecHitCombiner_cfi.py:5
CSCDriftSim::setMagneticField
void setMagneticField(const MagneticField *field)
Definition: CSCDriftSim.h:47
CSCNeutronReader.h
CSCDigitizer::theLayersNeeded
unsigned int theLayersNeeded
Definition: CSCDigitizer.h:86
CSCLayer
Definition: CSCLayer.h:24
CSCDigitizer::doAction
void doAction(MixCollection< PSimHit > &simHits, CSCWireDigiCollection &wireDigis, CSCStripDigiCollection &stripDigis, CSCComparatorDigiCollection &comparators, DigiSimLinks &wireDigiSimLinks, DigiSimLinks &stripDigiSimLinks, CLHEP::HepRandomEngine *)
Definition: CSCDigitizer.cc:39
CSCStripHitSim.h
CSCDigitizer::layersMissing
std::list< int > layersMissing(const CSCStripDigiCollection &stripDigis) const
finds which layers, 1-6, aren't in the current list
Definition: CSCDigitizer.cc:139
CSCWireHitSim::setParticleDataTable
void setParticleDataTable(const ParticleDataTable *pdt)
Definition: CSCWireHitSim.cc:77
MixCollection::MixItr
Definition: MixCollection.h:62
CSCWireElectronicsSim.h
CSCDigitizer::~CSCDigitizer
~CSCDigitizer()
Definition: CSCDigitizer.cc:30
CSCDigitizer::setStripConditions
void setStripConditions(CSCStripConditions *cond)
Definition: CSCDigitizer.cc:178
edm::DetSetVector::insert
void insert(detset const &s)
Insert the given DetSet.
Definition: DetSetVector.h:220
CSCNeutronReader::addHits
void addHits(std::map< int, edm::PSimHitContainer > &hitMap, CLHEP::HepRandomEngine *)
Definition: CSCNeutronReader.cc:6
CSCStripHitSim
Definition: CSCStripHitSim.h:21
PSimHit.h
hgcalPlots.stat
stat
Definition: hgcalPlots.py:1119
MixCollection
Definition: MixCollection.h:11
CSCLayer::id
CSCDetId id() const
Definition: CSCLayer.h:39
CSCDetId::layer
int layer() const
Definition: CSCDetId.h:56
CSCBaseElectronicsSim::digiSimLinks
const DigiSimLinks & digiSimLinks() const
Definition: CSCBaseElectronicsSim.h:46
CSCStripConditions
Definition: CSCStripConditions.h:13
CSCNeutronReader
Definition: CSCNeutronReader.h:10
CSCDigitizer::CSCDigitizer
CSCDigitizer(const CSCDigitizer &)=delete
CSCStripElectronicsSim::fillDigis
void fillDigis(CSCStripDigiCollection &digis, CSCComparatorDigiCollection &comparators, CLHEP::HepRandomEngine *)
Definition: CSCStripElectronicsSim.cc:286
CSCWireHitSim
Definition: CSCWireHitSim.h:27
CSCWireHitSim::simulate
std::vector< CSCDetectorHit > & simulate(const CSCLayer *layer, const edm::PSimHitContainer &simHits, CLHEP::HepRandomEngine *)
Definition: CSCWireHitSim.cc:15
cond
Definition: plugin.cc:23
CSCDriftSim.h
edm::ParameterSet
Definition: ParameterSet.h:47
ParameterSet
Definition: Functions.h:16
CSCDetId
Definition: CSCDetId.h:26
CSCDigitizer::findLayer
const CSCLayer * findLayer(int detId) const
finds the layer in the geometry associated with this det ID
Definition: CSCDigitizer.cc:185
CSCDigitizer::theCSCGeometry
const CSCGeometry * theCSCGeometry
Definition: CSCDigitizer.h:84
createfilelist.int
int
Definition: createfilelist.py:10
CSCStripConditions.h
CSCDetId::chamberId
CSCDetId chamberId() const
Definition: CSCDetId.h:47
CSCComparatorDigiCollection
CSCDetId::chamber
int chamber() const
Definition: CSCDetId.h:62
CSCDriftSim
Definition: CSCDriftSim.h:32
CSCWireHitSim.h
CSCDigitizer::theStripHitSim
CSCStripHitSim * theStripHitSim
Definition: CSCDigitizer.h:80
CSCWireDigiCollection
CSCLayer.h
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
CSCDetId::endcap
int endcap() const
Definition: CSCDetId.h:85
Exception
Definition: hltDiff.cc:246
CSCWireElectronicsSim
Definition: CSCWireElectronicsSim.h:20
CSCStripElectronicsSim::fillMissingLayer
void fillMissingLayer(const CSCLayer *layer, const CSCComparatorDigiCollection &comparators, CSCStripDigiCollection &digis, CLHEP::HepRandomEngine *)
Definition: CSCStripElectronicsSim.cc:398
relativeConstraints.ring
ring
Definition: relativeConstraints.py:68
CSCDetectorHit.h
CSCDigitizer::theDriftSim
CSCDriftSim * theDriftSim
Definition: CSCDigitizer.h:78
mps_fire.result
result
Definition: mps_fire.py:311
genParticles_cff.map
map
Definition: genParticles_cff.py:11
edm::PSimHitContainer
std::vector< PSimHit > PSimHitContainer
Definition: PSimHitContainer.h:11
CSCDetId::station
int station() const
Definition: CSCDetId.h:79
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
DigiContainerIterator
Definition: MuonDigiCollection.h:30
MagneticField
Definition: MagneticField.h:19
CSCGeometry::idToDetUnit
const GeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
Definition: CSCGeometry.cc:89
CSCDigitizer::setParticleDataTable
void setParticleDataTable(const ParticleDataTable *pdt)
Definition: CSCDigitizer.cc:183
CSCDigitizer::theNeutronReader
CSCNeutronReader * theNeutronReader
Definition: CSCDigitizer.h:83
ParticleDataTable
HepPDT::ParticleDataTable ParticleDataTable
Definition: ParticleDataTable.h:8
CSCDigitizer::theStripElectronicsSim
CSCStripElectronicsSim * theStripElectronicsSim
Definition: CSCDigitizer.h:82
CSCStripConditions::isInBadChamber
virtual bool isInBadChamber(const CSCDetId &id) const
is supplied layer/chamber flagged as bad? (default impl. is no)
Definition: CSCStripConditions.h:47
CSCBaseElectronicsSim::simulate
void simulate(const CSCLayer *layer, const std::vector< CSCDetectorHit > &inputHits, CLHEP::HepRandomEngine *)
Definition: CSCBaseElectronicsSim.cc:40
CSCDigitizer::theWireElectronicsSim
CSCWireElectronicsSim * theWireElectronicsSim
Definition: CSCDigitizer.h:81