test
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, p)),
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  edm::LogVerbatim("CSCDigitizer") << "[CSCDigitizer] found " << layerSimHits.size() << " hit(s) in layer"
116  << layer->id();
117  // << " E" << layer->id().endcap() << " S" << layer->id().station() << " R" << layer->id().ring()
118  // << " C" << layer->id().chamber() << " L" << layer->id().layer();
119 
120  // turn the edm::PSimHits into WireHits, using the WireHitSim
121  {
122  newWireHits.swap(theWireHitSim->simulate(layer, layerSimHits, engine));
123  }
124  if(!newWireHits.empty()) {
125  newStripHits.swap(theStripHitSim->simulate(layer, newWireHits));
126  }
127 
128  // turn the hits into wire digis, using the electronicsSim
129  if (nLayersInChamberHitForWireDigis >= theLayersNeeded) {
130  theWireElectronicsSim->simulate(layer, newWireHits, engine);
131  theWireElectronicsSim->fillDigis(wireDigis, engine);
132  wireDigiSimLinks.insert( theWireElectronicsSim->digiSimLinks() );
133  }
134  if (nLayersInChamberHitForStripDigis >= theLayersNeeded) {
135  theStripElectronicsSim->simulate(layer, newStripHits, engine);
136  theStripElectronicsSim->fillDigis(stripDigis, comparators, engine);
137  stripDigiSimLinks.insert( theStripElectronicsSim->digiSimLinks() );
138  }
139  }
140 
141  // fill in the layers were missing from this chamber
142  std::list<int> missingLayers = layersMissing(stripDigis);
143  for(std::list<int>::const_iterator missingLayerItr = missingLayers.begin();
144  missingLayerItr != missingLayers.end(); ++missingLayerItr)
145  {
146  const CSCLayer * layer = findLayer(*missingLayerItr);
147  theStripElectronicsSim->fillMissingLayer(layer, comparators, stripDigis, engine);
148  }
149 }
150 
151 
152 std::list<int> CSCDigitizer::layersMissing(const CSCStripDigiCollection & stripDigis) const
153 {
154  std::list<int> result;
155 
156  std::map<int, std::list<int> > layersInChamberWithDigi;
157  for (CSCStripDigiCollection::DigiRangeIterator j=stripDigis.begin();
158  j!=stripDigis.end(); j++)
159  {
160  CSCDetId layerId((*j).first);
161  // make sure the vector of digis isn't empty
162  if((*j).second.first != (*j).second.second)
163  {
164  int chamberId = layerId.chamberId();
165  layersInChamberWithDigi[chamberId].push_back(layerId.layer());
166  }
167  }
168 
169  std::list<int> oneThruSix;
170  for(int i = 1; i <=6; ++i)
171  oneThruSix.push_back(i);
172 
173  for(std::map<int, std::list<int> >::iterator layersInChamberWithDigiItr = layersInChamberWithDigi.begin();
174  layersInChamberWithDigiItr != layersInChamberWithDigi.end(); ++ layersInChamberWithDigiItr)
175  {
176  std::list<int> & layersHit = layersInChamberWithDigiItr->second;
177  if (layersHit.size() < 6 && layersHit.size() >= theLayersNeeded)
178  {
179  layersHit.sort();
180  std::list<int> missingLayers(6);
181  std::list<int>::iterator lastLayerMissing =
182  set_difference(oneThruSix.begin(), oneThruSix.end(),
183  layersHit.begin(), layersHit.end(), missingLayers.begin());
184  int chamberId = layersInChamberWithDigiItr->first;
185  for(std::list<int>::iterator layerMissingItr = missingLayers.begin();
186  layerMissingItr != lastLayerMissing; ++layerMissingItr)
187  {
188  // got from layer 1-6 to layer ID
189  result.push_back(chamberId + *layerMissingItr);
190  }
191  }
192  }
193  return result;
194 }
195 
196 
199 }
200 
201 
203 {
204  theConditions = cond; // cache here
205  theStripElectronicsSim->setStripConditions(cond); // percolate downwards
206 }
207 
208 
210 {
212 }
213 
214 
215 const CSCLayer * CSCDigitizer::findLayer(int detId) const {
216  assert(theCSCGeometry != 0);
217  const GeomDetUnit* detUnit = theCSCGeometry->idToDetUnit(CSCDetId(detId));
218  if(detUnit == 0)
219  {
220  throw cms::Exception("CSCDigiProducer") << "Invalid DetUnit: " << CSCDetId(detId)
221  << "\nPerhaps your signal or pileup dataset are not compatible with the current release?";
222  }
223  return dynamic_cast<const CSCLayer *>(detUnit);
224 }
225 
int chamber() const
Definition: CSCDetId.h:68
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:61
std::list< int > layersMissing(const CSCStripDigiCollection &stripDigis) const
finds which layers, 1-6, aren&#39;t in the current list
tuple result
Definition: mps_fire.py:83
void setMagneticField(const MagneticField *field)
Definition: CSCDriftSim.h:46
int endcap() const
Definition: CSCDetId.h:93
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 *)
int j
Definition: DBlmapReader.cc:9
CSCDetId chamberId() const
Definition: CSCDetId.h:53
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:75
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:235
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:86
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