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 #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<StripDigiSimLink> >().setBranchAlias ( alias + "siStripDigiSimLink");
70  trackerContainers.clear();
71  trackerContainers = conf.getParameter<std::vector<std::string> >("ROUList");
72  geometryType = conf.getParameter<std::string>("GeometryType");
73  useConfFromDB = conf.getParameter<bool>("TrackerConfigurationFromDB");
75  if ( ! rng.isAvailable()) {
76  throw cms::Exception("Configuration")
77  << "DigiSimLinkProducer requires the RandomNumberGeneratorService\n"
78  "which is not present in the configuration file. You must add the service\n"
79  "in the configuration file or remove the modules that require it.";
80  }
81 
82  rndEngine = &(rng->getEngine());
83  zeroSuppression = conf_.getParameter<bool>("ZeroSuppression");
85 
86 }
87 
88 // Virtual destructor needed.
90  delete theDigiAlgo;
91 }
92 
93 // Functions that gets called by framework every event
95 {
96  // Step A: Get Inputs
98  iSetup.getData( pdt );
99 
100  if(useConfFromDB){
102  iSetup.get<SiStripDetCablingRcd>().get( detCabling );
103  detCabling->addConnected(theDetIdList);
104  }
105 
107  std::vector<const CrossingFrame<PSimHit> *> cf_simhitvec;
108  for(uint32_t i = 0; i< trackerContainers.size();i++){
109  iEvent.getByLabel("mix",trackerContainers[i],cf_simhit);
110  cf_simhitvec.push_back(cf_simhit.product());
111  }
112 
113  std::auto_ptr<MixCollection<PSimHit> > allTrackerHits(new MixCollection<PSimHit>(cf_simhitvec));
114 
115  //Loop on PSimHit
116  SimHitMap.clear();
117 
118  //inside SimHitSelectorFromDb add the counter information from the original allhits collection
119  std::vector<std::pair<const PSimHit*,int> > trackerHits(SimHitSelectorFromDB_.getSimHit(allTrackerHits,theDetIdList));
120  std::vector<std::pair<const PSimHit*,int> >::iterator isim;
121  for (isim=trackerHits.begin() ; isim!= trackerHits.end();isim++) {
122  //make a pair = <*isim, counter> and save also position in the vector for DigiSimLink
123  SimHitMap[((*isim).first)->detUnitId()].push_back(*isim);
124  }
125 
127  iSetup.get<TrackerDigiGeometryRecord>().get(geometryType,pDD);
128 
130  iSetup.get<IdealMagneticFieldRecord>().get(pSetup);
131 
132  //get gain noise pedestal lorentzAngle from ES handle
133  edm::ESHandle<SiStripLorentzAngle> lorentzAngleHandle;
134  edm::ESHandle<SiStripGain> gainHandle;
135  edm::ESHandle<SiStripNoises> noiseHandle;
136  edm::ESHandle<SiStripThreshold> thresholdHandle;
137  edm::ESHandle<SiStripPedestals> pedestalHandle;
138  edm::ESHandle<SiStripBadStrip> deadChannelHandle;
139  std::string LAname = conf_.getParameter<std::string>("LorentzAngle");
140  iSetup.get<SiStripLorentzAngleSimRcd>().get(LAname,lorentzAngleHandle);
141  std::string gainLabel = conf_.getParameter<std::string>("Gain");
142  iSetup.get<SiStripGainSimRcd>().get(gainLabel,gainHandle);
143  iSetup.get<SiStripNoisesRcd>().get(noiseHandle);
144  iSetup.get<SiStripThresholdRcd>().get(thresholdHandle);
145  iSetup.get<SiStripPedestalsRcd>().get(pedestalHandle);
146  iSetup.get<SiStripBadChannelRcd>().get(deadChannelHandle);
147 
148  //Retrieve tracker topology from geometry
150  iSetup.get<IdealGeometryRecord>().get(tTopoHand);
151  const TrackerTopology *tTopo=tTopoHand.product();
152 
154 
155  // Step B: LOOP on StripGeomDetUnit
156  theDigiVector.reserve(10000);
157  theDigiVector.clear();
158  theDigiLinkVector.reserve(10000);
159  theDigiLinkVector.clear();
160 
161  for(TrackingGeometry::DetUnitContainer::const_iterator iu = pDD->detUnits().begin(); iu != pDD->detUnits().end(); iu ++){
162  if(useConfFromDB){
163  //apply the cable map _before_ digitization: consider only the detis that are connected
164  if(theDetIdList.find((*iu)->geographicalId().rawId())==theDetIdList.end())
165  continue;
166  }
167  GlobalVector bfield=pSetup->inTesla((*iu)->surface().position());
168  StripGeomDetUnit* sgd = dynamic_cast<StripGeomDetUnit*>((*iu));
169  if (sgd != 0){
170  edm::DetSet<SiStripDigi> collectorZS((*iu)->geographicalId().rawId());
171  edm::DetSet<SiStripRawDigi> collectorRaw((*iu)->geographicalId().rawId());
172  edm::DetSet<StripDigiSimLink> linkcollector((*iu)->geographicalId().rawId());
173  float langle = (lorentzAngleHandle.isValid()) ? lorentzAngleHandle->getLorentzAngle((*iu)->geographicalId().rawId()) : 0.;
174  theDigiAlgo->run(collectorZS,collectorRaw,SimHitMap[(*iu)->geographicalId().rawId()],sgd,bfield,langle,
175  gainHandle,thresholdHandle,noiseHandle,pedestalHandle, deadChannelHandle, tTopo);
176  if(zeroSuppression){
177  if(collectorZS.data.size()>0){
178  theDigiVector.push_back(collectorZS);
179  if(SimHitMap[(*iu)->geographicalId().rawId()].size()>0){
180  linkcollector.data = theDigiAlgo->make_link();
181  if(linkcollector.data.size()>0)
182  theDigiLinkVector.push_back(linkcollector);
183  }
184  }
185  }else{
186  if(collectorRaw.data.size()>0){
187  theRawDigiVector.push_back(collectorRaw);
188  if(SimHitMap[(*iu)->geographicalId().rawId()].size()>0){
189  linkcollector.data = theDigiAlgo->make_link();
190  if(linkcollector.data.size()>0)
191  theDigiLinkVector.push_back(linkcollector);
192  }
193  }
194  }
195  }
196  }
197 
198  // Step C: create output collection
199  std::auto_ptr<edm::DetSetVector<StripDigiSimLink> > outputlink(new edm::DetSetVector<StripDigiSimLink>(theDigiLinkVector));
200  // Step D: write output to file
201  iEvent.put(outputlink);
202 }
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:67
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:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
std::map< uint32_t, std::vector< int > > theDetIdList
DigiSimLinkAlgorithm * theDigiAlgo
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
tuple conf
Definition: dbtoconf.py:185
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 > &, const TrackerTopology *tTopo)
DigiSimLinkProducer(const edm::ParameterSet &conf)
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
T const * product() const
Definition: Handle.h:74
SimHitSelectorFromDB SimHitSelectorFromDB_
CLHEP::HepRandomEngine * rndEngine
std::vector< edm::DetSet< SiStripDigi > > theDigiVector
std::vector< edm::DetSet< SiStripRawDigi > > theRawDigiVector
bool isValid() const
Definition: ESHandle.h:37