00001
00002
00003
00004
00005 #include <memory>
00006
00007 #include "SimTracker/SiStripDigitizer/interface/SiStripDigitizer.h"
00008
00009 #include "DataFormats/Common/interface/DetSetVector.h"
00010 #include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
00011 #include "DataFormats/SiStripDigi/interface/SiStripRawDigi.h"
00012 #include "SimDataFormats/TrackerDigiSimLink/interface/StripDigiSimLink.h"
00013
00014
00015 #include "FWCore/Framework/interface/Frameworkfwd.h"
00016 #include "FWCore/Framework/interface/EDProducer.h"
00017
00018 #include "FWCore/Framework/interface/Event.h"
00019 #include "FWCore/Framework/interface/MakerMacros.h"
00020
00021 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00022 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
00023 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
00024 #include "SimDataFormats/CrossingFrame/interface/CrossingFrame.h"
00025 #include "SimDataFormats/CrossingFrame/interface/MixCollection.h"
00026
00027
00028 #include "FWCore/Framework/interface/EventSetup.h"
00029 #include "FWCore/Framework/interface/ESHandle.h"
00030 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00031 #include "Geometry/CommonDetUnit/interface/GeomDetType.h"
00032 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00033 #include "Geometry/TrackerNumberingBuilder/interface/GeometricDet.h"
00034 #include "Geometry/CommonTopologies/interface/StripTopology.h"
00035 #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetType.h"
00036 #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
00037
00038 #include "MagneticField/Engine/interface/MagneticField.h"
00039 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00040
00041 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00042 #include "SimGeneral/HepPDTRecord/interface/ParticleDataTable.h"
00043
00044
00045 #include "CondFormats/DataRecord/interface/SiStripLorentzAngleRcd.h"
00046 #include "CalibTracker/Records/interface/SiStripGainRcd.h"
00047 #include "CondFormats/DataRecord/interface/SiStripNoisesRcd.h"
00048 #include "CondFormats/DataRecord/interface/SiStripPedestalsRcd.h"
00049 #include "CondFormats/DataRecord/interface/SiStripThresholdRcd.h"
00050 #include "CondFormats/SiStripObjects/interface/SiStripLorentzAngle.h"
00051 #include "CondFormats/SiStripObjects/interface/SiStripNoises.h"
00052 #include "CondFormats/SiStripObjects/interface/SiStripPedestals.h"
00053 #include "CondFormats/SiStripObjects/interface/SiStripThreshold.h"
00054 #include "CalibFormats/SiStripObjects/interface/SiStripGain.h"
00055 #include "CalibTracker/Records/interface/SiStripDetCablingRcd.h"
00056 #include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
00057
00058
00059 #include "FWCore/ServiceRegistry/interface/Service.h"
00060 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
00061 #include "FWCore/Utilities/interface/Exception.h"
00062 #include "CLHEP/Random/RandomEngine.h"
00063
00064 SiStripDigitizer::SiStripDigitizer(const edm::ParameterSet& conf) :
00065 conf_(conf)
00066 {
00067 alias = conf.getParameter<std::string>("@module_label");
00068 edm::ParameterSet ParamSet=conf_.getParameter<edm::ParameterSet>("DigiModeList");
00069
00070 produces<edm::DetSetVector<SiStripDigi> >(ParamSet.getParameter<std::string>("ZSDigi")).setBranchAlias( ParamSet.getParameter<std::string>("ZSDigi") );
00071 produces<edm::DetSetVector<StripDigiSimLink> >().setBranchAlias ( alias + "siStripDigiSimLink");
00072 produces<edm::DetSetVector<SiStripRawDigi> >(ParamSet.getParameter<std::string>("SCDigi")).setBranchAlias( alias + ParamSet.getParameter<std::string>("SCDigi") );
00073 produces<edm::DetSetVector<SiStripRawDigi> >(ParamSet.getParameter<std::string>("VRDigi")).setBranchAlias( alias + ParamSet.getParameter<std::string>("VRDigi") );
00074 produces<edm::DetSetVector<SiStripRawDigi> >(ParamSet.getParameter<std::string>("PRDigi")).setBranchAlias( alias + ParamSet.getParameter<std::string>("PRDigi") );
00075 trackerContainers.clear();
00076 trackerContainers = conf.getParameter<std::vector<std::string> >("ROUList");
00077 geometryType = conf.getParameter<std::string>("GeometryType");
00078 useConfFromDB = conf.getParameter<bool>("TrackerConfigurationFromDB");
00079 edm::Service<edm::RandomNumberGenerator> rng;
00080 if ( ! rng.isAvailable()) {
00081 throw cms::Exception("Configuration")
00082 << "SiStripDigitizer requires the RandomNumberGeneratorService\n"
00083 "which is not present in the configuration file. You must add the service\n"
00084 "in the configuration file or remove the modules that require it.";
00085 }
00086
00087 rndEngine = &(rng->getEngine());
00088 zeroSuppression = conf_.getParameter<bool>("ZeroSuppression");
00089 theDigiAlgo = new SiStripDigitizerAlgorithm(conf_,(*rndEngine));
00090
00091 }
00092
00093
00094 SiStripDigitizer::~SiStripDigitizer() {
00095 delete theDigiAlgo;
00096 }
00097
00098
00099 void SiStripDigitizer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00100 {
00101
00102
00103 edm::ESHandle < ParticleDataTable > pdt;
00104 iSetup.getData( pdt );
00105
00106 if(useConfFromDB){
00107 edm::ESHandle<SiStripDetCabling> detCabling;
00108 iSetup.get<SiStripDetCablingRcd>().get( detCabling );
00109 detCabling->addConnected(theDetIdList);
00110 }
00111
00112 edm::Handle<CrossingFrame<PSimHit> > cf_simhit;
00113 std::vector<const CrossingFrame<PSimHit> *> cf_simhitvec;
00114 for(uint32_t i = 0; i< trackerContainers.size();i++){
00115 iEvent.getByLabel("mix",trackerContainers[i],cf_simhit);
00116 cf_simhitvec.push_back(cf_simhit.product());
00117 }
00118
00119 std::auto_ptr<MixCollection<PSimHit> > allTrackerHits(new MixCollection<PSimHit>(cf_simhitvec));
00120
00121
00122 SimHitMap.clear();
00123
00124
00125 std::vector<std::pair<PSimHit,int> > trackerHits = SimHitSelectorFromDB_.getSimHit(allTrackerHits,theDetIdList);
00126
00127 std::vector<std::pair<PSimHit,int> >::iterator isim;
00128 for (isim=trackerHits.begin() ; isim!= trackerHits.end();isim++) {
00129
00130 SimHitMap[((*isim).first).detUnitId()].push_back(*isim);
00131
00132 }
00133
00134 edm::ESHandle<TrackerGeometry> pDD;
00135
00136 iSetup.get<TrackerDigiGeometryRecord>().get(geometryType,pDD);
00137
00138 edm::ESHandle<MagneticField> pSetup;
00139 iSetup.get<IdealMagneticFieldRecord>().get(pSetup);
00140
00141
00142 edm::ESHandle<SiStripLorentzAngle> lorentzAngleHandle;
00143 edm::ESHandle<SiStripGain> gainHandle;
00144 edm::ESHandle<SiStripNoises> noiseHandle;
00145 edm::ESHandle<SiStripThreshold> thresholdHandle;
00146 edm::ESHandle<SiStripPedestals> pedestalHandle;
00147 std::string LAname = conf_.getParameter<std::string>("LorentzAngle");
00148 iSetup.get<SiStripLorentzAngleRcd>().get(LAname,lorentzAngleHandle);
00149 std::string gainLabel = conf_.getParameter<std::string>("Gain");
00150 iSetup.get<SiStripGainRcd>().get(gainLabel,gainHandle);
00151 iSetup.get<SiStripNoisesRcd>().get(noiseHandle);
00152 iSetup.get<SiStripThresholdRcd>().get(thresholdHandle);
00153 iSetup.get<SiStripPedestalsRcd>().get(pedestalHandle);
00154
00155
00156 theDigiAlgo->setParticleDataTable(&*pdt);
00157
00158
00159 theDigiVector.reserve(10000);
00160 theDigiVector.clear();
00161
00162 theDigiLinkVector.reserve(10000);
00163 theDigiLinkVector.clear();
00164
00165 for(TrackingGeometry::DetUnitContainer::const_iterator iu = pDD->detUnits().begin(); iu != pDD->detUnits().end(); iu ++){
00166
00167 if(useConfFromDB){
00168
00169 if(theDetIdList.find((*iu)->geographicalId().rawId())==theDetIdList.end())
00170 continue;
00171 }
00172
00173 GlobalVector bfield=pSetup->inTesla((*iu)->surface().position());
00174
00175 StripGeomDetUnit* sgd = dynamic_cast<StripGeomDetUnit*>((*iu));
00176 if (sgd != 0){
00177 edm::DetSet<SiStripDigi> collectorZS((*iu)->geographicalId().rawId());
00178 edm::DetSet<SiStripRawDigi> collectorRaw((*iu)->geographicalId().rawId());
00179 edm::DetSet<StripDigiSimLink> linkcollector((*iu)->geographicalId().rawId());
00180
00181 float langle=0.;
00182 if(lorentzAngleHandle.isValid())langle=lorentzAngleHandle->getLorentzAngle((*iu)->geographicalId().rawId());
00183 theDigiAlgo->run(collectorZS,collectorRaw,SimHitMap[(*iu)->geographicalId().rawId()],sgd,bfield,langle,
00184 gainHandle,thresholdHandle,noiseHandle,pedestalHandle);
00185
00186 if(zeroSuppression){
00187 if(collectorZS.data.size()>0){
00188 theDigiVector.push_back(collectorZS);
00189 if(SimHitMap[(*iu)->geographicalId().rawId()].size()>0){
00190 linkcollector.data = theDigiAlgo->make_link();
00191 if(linkcollector.data.size()>0)
00192 theDigiLinkVector.push_back(linkcollector);
00193 }
00194 }
00195 }else{
00196 if(collectorRaw.data.size()>0){
00197 theRawDigiVector.push_back(collectorRaw);
00198 if(SimHitMap[(*iu)->geographicalId().rawId()].size()>0){
00199 linkcollector.data = theDigiAlgo->make_link();
00200 if(linkcollector.data.size()>0)
00201 theDigiLinkVector.push_back(linkcollector);
00202 }
00203 }
00204 }
00205 }
00206 }
00207
00208 if(zeroSuppression){
00209
00210 std::auto_ptr<edm::DetSetVector<SiStripRawDigi> > output_virginraw(new edm::DetSetVector<SiStripRawDigi>());
00211 std::auto_ptr<edm::DetSetVector<SiStripRawDigi> > output_scopemode(new edm::DetSetVector<SiStripRawDigi>());
00212 std::auto_ptr<edm::DetSetVector<SiStripRawDigi> > output_processedraw(new edm::DetSetVector<SiStripRawDigi>());
00213 std::auto_ptr<edm::DetSetVector<SiStripDigi> > output(new edm::DetSetVector<SiStripDigi>(theDigiVector) );
00214 std::auto_ptr<edm::DetSetVector<StripDigiSimLink> > outputlink(new edm::DetSetVector<StripDigiSimLink>(theDigiLinkVector) );
00215
00216
00217 edm::ParameterSet ParamSet=conf_.getParameter<edm::ParameterSet>("DigiModeList");
00218
00219 iEvent.put(output,ParamSet.getParameter<std::string>("ZSDigi"));
00220 iEvent.put(outputlink);
00221 iEvent.put(output_scopemode, ParamSet.getParameter<std::string>("SCDigi"));
00222 iEvent.put(output_virginraw, ParamSet.getParameter<std::string>("VRDigi"));
00223 iEvent.put(output_processedraw,ParamSet.getParameter<std::string>("PRDigi"));
00224 }else{
00225
00226 std::auto_ptr<edm::DetSetVector<SiStripRawDigi> > output_virginraw(new edm::DetSetVector<SiStripRawDigi>(theRawDigiVector));
00227 std::auto_ptr<edm::DetSetVector<SiStripRawDigi> > output_scopemode(new edm::DetSetVector<SiStripRawDigi>());
00228 std::auto_ptr<edm::DetSetVector<SiStripRawDigi> > output_processedraw(new edm::DetSetVector<SiStripRawDigi>());
00229 std::auto_ptr<edm::DetSetVector<SiStripDigi> > output(new edm::DetSetVector<SiStripDigi>() );
00230 std::auto_ptr<edm::DetSetVector<StripDigiSimLink> > outputlink(new edm::DetSetVector<StripDigiSimLink>(theDigiLinkVector) );
00231
00232
00233 edm::ParameterSet ParamSet=conf_.getParameter<edm::ParameterSet>("DigiModeList");
00234
00235 iEvent.put(output,ParamSet.getParameter<std::string>("ZSDigi"));
00236 iEvent.put(outputlink);
00237 iEvent.put(output_scopemode, ParamSet.getParameter<std::string>("SCDigi"));
00238 iEvent.put(output_virginraw, ParamSet.getParameter<std::string>("VRDigi"));
00239 iEvent.put(output_processedraw,ParamSet.getParameter<std::string>("PRDigi"));
00240 }
00241 }