CMS 3D CMS Logo

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