CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DigiSimLinkProducer.cc
Go to the documentation of this file.
1 // File: DigiSimLinkAlgorithm.cc
2 // Description: Class for digitization.
3 
4 // system include files
5 #include <memory>
6 
7 #include "DigiSimLinkProducer.h"
8 
13 
14 // user include files
17 
20 
26 
27 //needed for the geometry:
37 //needed for the magnetic field:
40 
43 
44 //Data Base infromations
55 
56 
57 //Random Number
61 
62 namespace CLHEP{
63  class HepRandomEngine;
64 }
65 
67  conf_(conf)
68 {
69  alias = conf.getParameter<std::string>("@module_label");
70  edm::ParameterSet ParamSet=conf_.getParameter<edm::ParameterSet>("DigiModeList");
71 
72  produces<edm::DetSetVector<StripDigiSimLink> >().setBranchAlias ( alias + "siStripDigiSimLink");
73  trackerContainers.clear();
74  trackerContainers = conf.getParameter<std::vector<std::string> >("ROUList");
75  geometryType = conf.getParameter<std::string>("GeometryType");
76  useConfFromDB = conf.getParameter<bool>("TrackerConfigurationFromDB");
78  if ( ! rng.isAvailable()) {
79  throw cms::Exception("Configuration")
80  << "DigiSimLinkProducer requires the RandomNumberGeneratorService\n"
81  "which is not present in the configuration file. You must add the service\n"
82  "in the configuration file or remove the modules that require it.";
83  }
84 
85  zeroSuppression = conf_.getParameter<bool>("ZeroSuppression");
87 
88 }
89 
90 // Virtual destructor needed.
92  delete theDigiAlgo;
93 }
94 
95 // Functions that gets called by framework every event
97 {
99  CLHEP::HepRandomEngine* engine = &rng->getEngine(iEvent.streamID());
100 
101  // Step A: Get Inputs
103  iSetup.getData( pdt );
104 
105  if(useConfFromDB){
107  iSetup.get<SiStripDetCablingRcd>().get( detCabling );
108  detCabling->addConnected(theDetIdList);
109  }
110 
112  std::vector<const CrossingFrame<PSimHit> *> cf_simhitvec;
113  for(uint32_t i = 0; i< trackerContainers.size();i++){
114  iEvent.getByLabel("mix",trackerContainers[i],cf_simhit);
115  cf_simhitvec.push_back(cf_simhit.product());
116  }
117 
118  std::auto_ptr<MixCollection<PSimHit> > allTrackerHits(new MixCollection<PSimHit>(cf_simhitvec));
119 
120  //Loop on PSimHit
121  SimHitMap.clear();
122 
123  //inside SimHitSelectorFromDb add the counter information from the original allhits collection
124  std::vector<std::pair<const PSimHit*,int> > trackerHits(SimHitSelectorFromDB_.getSimHit(allTrackerHits,theDetIdList));
125  std::vector<std::pair<const PSimHit*,int> >::iterator isim;
126  for (isim=trackerHits.begin() ; isim!= trackerHits.end();isim++) {
127  //make a pair = <*isim, counter> and save also position in the vector for DigiSimLink
128  SimHitMap[((*isim).first)->detUnitId()].push_back(*isim);
129  }
130 
132  iSetup.get<TrackerDigiGeometryRecord>().get(geometryType,pDD);
133 
135  iSetup.get<IdealMagneticFieldRecord>().get(pSetup);
136 
137  //get gain noise pedestal lorentzAngle from ES handle
138  edm::ESHandle<SiStripLorentzAngle> lorentzAngleHandle;
139  edm::ESHandle<SiStripGain> gainHandle;
140  edm::ESHandle<SiStripNoises> noiseHandle;
141  edm::ESHandle<SiStripThreshold> thresholdHandle;
142  edm::ESHandle<SiStripPedestals> pedestalHandle;
143  edm::ESHandle<SiStripBadStrip> deadChannelHandle;
144  std::string LAname = conf_.getParameter<std::string>("LorentzAngle");
145  iSetup.get<SiStripLorentzAngleSimRcd>().get(LAname,lorentzAngleHandle);
146  std::string gainLabel = conf_.getParameter<std::string>("Gain");
147  iSetup.get<SiStripGainSimRcd>().get(gainLabel,gainHandle);
148  iSetup.get<SiStripNoisesRcd>().get(noiseHandle);
149  iSetup.get<SiStripThresholdRcd>().get(thresholdHandle);
150  iSetup.get<SiStripPedestalsRcd>().get(pedestalHandle);
151  iSetup.get<SiStripBadChannelRcd>().get(deadChannelHandle);
152 
153  //Retrieve tracker topology from geometry
155  iSetup.get<IdealGeometryRecord>().get(tTopoHand);
156  const TrackerTopology *tTopo=tTopoHand.product();
157 
159 
160  // Step B: LOOP on StripGeomDetUnit
161  theDigiVector.reserve(10000);
162  theDigiVector.clear();
163  theDigiLinkVector.reserve(10000);
164  theDigiLinkVector.clear();
165 
166  for(TrackingGeometry::DetUnitContainer::const_iterator iu = pDD->detUnits().begin(); iu != pDD->detUnits().end(); iu ++){
167  if(useConfFromDB){
168  //apply the cable map _before_ digitization: consider only the detis that are connected
169  if(theDetIdList.find((*iu)->geographicalId().rawId())==theDetIdList.end())
170  continue;
171  }
172  GlobalVector bfield=pSetup->inTesla((*iu)->surface().position());
173  auto sgd = dynamic_cast<StripGeomDetUnit const*>((*iu));
174  if (sgd != 0){
175  edm::DetSet<SiStripDigi> collectorZS((*iu)->geographicalId().rawId());
176  edm::DetSet<SiStripRawDigi> collectorRaw((*iu)->geographicalId().rawId());
177  edm::DetSet<StripDigiSimLink> linkcollector((*iu)->geographicalId().rawId());
178  float langle = (lorentzAngleHandle.isValid()) ? lorentzAngleHandle->getLorentzAngle((*iu)->geographicalId().rawId()) : 0.;
179  theDigiAlgo->run(collectorZS,collectorRaw,SimHitMap[(*iu)->geographicalId().rawId()],sgd,bfield,langle,
180  gainHandle,thresholdHandle,noiseHandle,pedestalHandle, deadChannelHandle, tTopo, engine);
181  if(zeroSuppression){
182  if(collectorZS.data.size()>0){
183  theDigiVector.push_back(collectorZS);
184  if(SimHitMap[(*iu)->geographicalId().rawId()].size()>0){
185  linkcollector.data = theDigiAlgo->make_link();
186  if(linkcollector.data.size()>0)
187  theDigiLinkVector.push_back(linkcollector);
188  }
189  }
190  }else{
191  if(collectorRaw.data.size()>0){
192  theRawDigiVector.push_back(collectorRaw);
193  if(SimHitMap[(*iu)->geographicalId().rawId()].size()>0){
194  linkcollector.data = theDigiAlgo->make_link();
195  if(linkcollector.data.size()>0)
196  theDigiLinkVector.push_back(linkcollector);
197  }
198  }
199  }
200  }
201  }
202 
203  // Step C: create output collection
204  std::auto_ptr<edm::DetSetVector<StripDigiSimLink> > outputlink(new edm::DetSetVector<StripDigiSimLink>(theDigiLinkVector));
205  // Step D: write output to file
206  iEvent.put(outputlink);
207 }
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
std::vector< edm::DetSet< StripDigiSimLink > > theDigiLinkVector
virtual void produce(edm::Event &e, const edm::EventSetup &c)
std::vector< StripDigiSimLink > make_link()
edm::ParameterSet conf_
void setParticleDataTable(const ParticleDataTable *pardt)
void getData(T &iHolder) const
Definition: EventSetup.h:78
std::vector< std::pair< const PSimHit *, int > > getSimHit(std::auto_ptr< MixCollection< PSimHit > > &, std::map< uint32_t, std::vector< int > > &)
int iEvent
Definition: GenABIO.cc:230
void run(edm::DetSet< SiStripDigi > &, edm::DetSet< SiStripRawDigi > &, const std::vector< std::pair< const PSimHit *, int > > &, StripGeomDetUnit const *, GlobalVector, float, edm::ESHandle< SiStripGain > &, edm::ESHandle< SiStripThreshold > &, edm::ESHandle< SiStripNoises > &, edm::ESHandle< SiStripPedestals > &, edm::ESHandle< SiStripBadStrip > &, const TrackerTopology *tTopo, CLHEP::HepRandomEngine *)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
std::map< uint32_t, std::vector< int > > theDetIdList
DigiSimLinkAlgorithm * theDigiAlgo
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:402
tuple conf
Definition: dbtoconf.py:185
DigiSimLinkProducer(const edm::ParameterSet &conf)
T const * product() const
Definition: Handle.h:81
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:86
string const
Definition: compareJSON.py:14
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &) const =0
Use this engine in event methods.
SimHitSelectorFromDB SimHitSelectorFromDB_
std::vector< edm::DetSet< SiStripDigi > > theDigiVector
StreamID streamID() const
Definition: Event.h:72
std::vector< edm::DetSet< SiStripRawDigi > > theRawDigiVector
bool isValid() const
Definition: ESHandle.h:47