CMS 3D CMS Logo

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