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 {
52  // arrange the hits by layer
53  std::map<int, edm::PSimHitContainer> hitMap;
54  for(MixCollection<PSimHit>::MixItr hitItr = simHits.begin();
55  hitItr != simHits.end(); ++hitItr)
56  {
57  hitMap[hitItr->detUnitId()].push_back(*hitItr);
58  }
59 
60  // count how many layers on each chamber are hit
61  std::map<int, std::set<int> > layersInChamberHit;
62  for(std::map<int, edm::PSimHitContainer>::const_iterator hitMapItr = hitMap.begin();
63  hitMapItr != hitMap.end(); ++hitMapItr)
64  {
65  CSCDetId cscDetId(hitMapItr->first);
66  int chamberId = cscDetId.chamberId();
67  layersInChamberHit[chamberId].insert(cscDetId.layer());
68  }
69 
70  // add neutron background, if needed
71  if(theNeutronReader != 0)
72  {
73  theNeutronReader->addHits(hitMap);
74  }
75 
76  // now loop over layers and run the simulation for each one
77  for(std::map<int, edm::PSimHitContainer>::const_iterator hitMapItr = hitMap.begin();
78  hitMapItr != hitMap.end(); ++hitMapItr)
79  {
80  int chamberId = CSCDetId(hitMapItr->first).chamberId();
81  unsigned int nLayersInChamberHit = layersInChamberHit[chamberId].size();
82  if(nLayersInChamberHit < theLayersNeeded) continue;
83  // skip bad chambers
84  if ( !digitizeBadChambers_ && theConditions->isInBadChamber( CSCDetId(hitMapItr->first) ) ) continue;
85 
86  const CSCLayer * layer = findLayer(hitMapItr->first);
87  const edm::PSimHitContainer & layerSimHits = hitMapItr->second;
88 
89  std::vector<CSCDetectorHit> newWireHits, newStripHits;
90 
91  LogTrace("CSCDigitizer") << "CSCDigitizer: found " << layerSimHits.size() <<" hit(s) in layer"
92  << " E" << layer->id().endcap() << " S" << layer->id().station() << " R" << layer->id().ring()
93  << " C" << layer->id().chamber() << " L" << layer->id().layer();
94 
95  // turn the edm::PSimHits into WireHits, using the WireHitSim
96  {
97  newWireHits.swap(theWireHitSim->simulate(layer, layerSimHits));
98  }
99  if(!newWireHits.empty()) {
100  newStripHits.swap(theStripHitSim->simulate(layer, newWireHits));
101  }
102 
103  // turn the hits into wire digis, using the electronicsSim
104  {
105  theWireElectronicsSim->simulate(layer, newWireHits);
106  theWireElectronicsSim->fillDigis(wireDigis);
107  wireDigiSimLinks.insert( theWireElectronicsSim->digiSimLinks() );
108  }
109  {
110  theStripElectronicsSim->simulate(layer, newStripHits);
111  theStripElectronicsSim->fillDigis(stripDigis, comparators);
112  stripDigiSimLinks.insert( theStripElectronicsSim->digiSimLinks() );
113  }
114  }
115 
116  // fill in the layers were missing from this chamber
117  std::list<int> missingLayers = layersMissing(stripDigis);
118  for(std::list<int>::const_iterator missingLayerItr = missingLayers.begin();
119  missingLayerItr != missingLayers.end(); ++missingLayerItr)
120  {
121  const CSCLayer * layer = findLayer(*missingLayerItr);
122  theStripElectronicsSim->fillMissingLayer(layer, comparators, stripDigis);
123  }
124 }
125 
126 
127 std::list<int> CSCDigitizer::layersMissing(const CSCStripDigiCollection & stripDigis) const
128 {
129  std::list<int> result;
130 
131  std::map<int, std::list<int> > layersInChamberWithDigi;
132  for (CSCStripDigiCollection::DigiRangeIterator j=stripDigis.begin();
133  j!=stripDigis.end(); j++)
134  {
135  CSCDetId layerId((*j).first);
136  // make sure the vector of digis isn't empty
137  if((*j).second.first != (*j).second.second)
138  {
139  int chamberId = layerId.chamberId();
140  layersInChamberWithDigi[chamberId].push_back(layerId.layer());
141  }
142  }
143 
144  std::list<int> oneThruSix;
145  for(int i = 1; i <=6; ++i)
146  oneThruSix.push_back(i);
147 
148  for(std::map<int, std::list<int> >::iterator layersInChamberWithDigiItr = layersInChamberWithDigi.begin();
149  layersInChamberWithDigiItr != layersInChamberWithDigi.end(); ++ layersInChamberWithDigiItr)
150  {
151  std::list<int> & layersHit = layersInChamberWithDigiItr->second;
152  if (layersHit.size() < 6 && layersHit.size() >= theLayersNeeded)
153  {
154  layersHit.sort();
155  std::list<int> missingLayers(6);
156  std::list<int>::iterator lastLayerMissing =
157  set_difference(oneThruSix.begin(), oneThruSix.end(),
158  layersHit.begin(), layersHit.end(), missingLayers.begin());
159  int chamberId = layersInChamberWithDigiItr->first;
160  for(std::list<int>::iterator layerMissingItr = missingLayers.begin();
161  layerMissingItr != lastLayerMissing; ++layerMissingItr)
162  {
163  // got from layer 1-6 to layer ID
164  result.push_back(chamberId + *layerMissingItr);
165  }
166  }
167  }
168  return result;
169 }
170 
171 
174 }
175 
176 
178 {
179  theConditions = cond; // cache here
180  theStripElectronicsSim->setStripConditions(cond); // percolate downwards
181 }
182 
183 
185 {
187 }
188 
189 
190 void CSCDigitizer::setRandomEngine(CLHEP::HepRandomEngine& engine)
191 {
196 }
197 
198 
199 const CSCLayer * CSCDigitizer::findLayer(int detId) const {
200  assert(theCSCGeometry != 0);
201  const GeomDetUnit* detUnit = theCSCGeometry->idToDetUnit(CSCDetId(detId));
202  if(detUnit == 0)
203  {
204  throw cms::Exception("CSCDigiProducer") << "Invalid DetUnit: " << CSCDetId(detId)
205  << "\nPerhaps your signal or pileup dataset are not compatible with the current release?";
206  }
207  return dynamic_cast<const CSCLayer *>(detUnit);
208 }
209 
int chamber() const
Definition: CSCDetId.h:70
CSCDriftSim * theDriftSim
Definition: CSCDigitizer.h:75
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:83
HepPDT::ParticleDataTable ParticleDataTable
CSCDetId id() const
Definition: CSCLayer.h:42
void fillMissingLayer(const CSCLayer *layer, const CSCComparatorDigiCollection &comparators, CSCStripDigiCollection &digis)
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:63
std::list< int > layersMissing(const CSCStripDigiCollection &stripDigis) const
finds which layers, 1-6, aren&#39;t in the current list
void setRandomEngine(CLHEP::HepRandomEngine &engine)
void setRandomEngine(CLHEP::HepRandomEngine &engine)
dictionary map
Definition: Association.py:205
void setMagneticField(const MagneticField *field)
Definition: CSCDriftSim.h:43
int endcap() const
Definition: CSCDetId.h:95
iterator end()
bool digitizeBadChambers_
Definition: CSCDigitizer.h:84
const DigiSimLinks & digiSimLinks() const
CSCStripElectronicsSim * theStripElectronicsSim
Definition: CSCDigitizer.h:79
CSCDigitizer(const edm::ParameterSet &p)
configurable parameters
Definition: CSCDigitizer.cc:16
CSCNeutronReader * theNeutronReader
Definition: CSCDigitizer.h:80
virtual const GeomDetUnit * idToDetUnit(DetId) const
Return the pointer to the GeomDetUnit corresponding to a given DetId.
Definition: CSCGeometry.cc:93
const CSCGeometry * theCSCGeometry
Definition: CSCDigitizer.h:81
void doAction(MixCollection< PSimHit > &simHits, CSCWireDigiCollection &wireDigis, CSCStripDigiCollection &stripDigis, CSCComparatorDigiCollection &comparators, DigiSimLinks &wireDigiSimLinks, DigiSimLinks &stripDigiSimLinks)
Definition: CSCDigitizer.cc:45
tuple result
Definition: query.py:137
int j
Definition: DBlmapReader.cc:9
CSCDetId chamberId() const
Definition: CSCDetId.h:55
void setStripConditions(CSCStripConditions *cond)
#define LogTrace(id)
CSCWireHitSim * theWireHitSim
Definition: CSCDigitizer.h:76
int ring() const
Definition: CSCDetId.h:77
void setRandomEngine(CLHEP::HepRandomEngine &engine)
iterator begin()
tuple simHits
Definition: trackerHits.py:16
void setParticleDataTable(const ParticleDataTable *pdt)
std::vector< CSCDetectorHit > & simulate(const CSCLayer *layer, const edm::PSimHitContainer &simHits)
void simulate(const CSCLayer *layer, const std::vector< CSCDetectorHit > &inputHits)
void fillDigis(CSCStripDigiCollection &digis, CSCComparatorDigiCollection &comparators)
void fillDigis(CSCWireDigiCollection &digis)
void insert(detset const &s)
Insert the given DetSet.
Definition: DetSetVector.h:234
CSCWireElectronicsSim * theWireElectronicsSim
Definition: CSCDigitizer.h:78
void setRandomEngine(CLHEP::HepRandomEngine &engine)
int station() const
Definition: CSCDetId.h:88
std::vector< PSimHit > PSimHitContainer
virtual bool isInBadChamber(const CSCDetId &id) const
is supplied layer/chamber flagged as bad? (default impl. is no)
void setMagneticField(const MagneticField *field)
sets the magnetic field
void addHits(std::map< int, edm::PSimHitContainer > &hitMap)
void setParticleDataTable(const ParticleDataTable *pdt)
CSCStripHitSim * theStripHitSim
Definition: CSCDigitizer.h:77
CSCStripConditions * theConditions
Definition: CSCDigitizer.h:82