CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/SimTracker/SiStripDigitizer/plugins/SiStripDigitizer.cc

Go to the documentation of this file.
00001 // File: SiStripDigitizerAlgorithm.cc
00002 // Description:  Class for digitization.
00003 
00004 // system include files
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 // user include files
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 //needed for the geometry:
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 //needed for the magnetic field:
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 //Data Base infromations
00045 #include "CondFormats/DataRecord/interface/SiStripCondDataRecords.h"
00046 #include "CalibTracker/Records/interface/SiStripDependentRecords.h"
00047 #include "CondFormats/SiStripObjects/interface/SiStripLorentzAngle.h"
00048 #include "CondFormats/SiStripObjects/interface/SiStripNoises.h"
00049 #include "CondFormats/SiStripObjects/interface/SiStripPedestals.h"
00050 #include "CondFormats/SiStripObjects/interface/SiStripThreshold.h"
00051 #include "CondFormats/SiStripObjects/interface/SiStripBadStrip.h"
00052 #include "CalibFormats/SiStripObjects/interface/SiStripGain.h"
00053 #include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
00054 #include "CalibFormats/SiStripObjects/interface/SiStripQuality.h"
00055 
00056 
00057 //Random Number
00058 #include "FWCore/ServiceRegistry/interface/Service.h"
00059 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
00060 #include "FWCore/Utilities/interface/Exception.h"
00061 #include "CLHEP/Random/RandomEngine.h"
00062 
00063 SiStripDigitizer::SiStripDigitizer(const edm::ParameterSet& conf) : 
00064   conf_(conf)
00065 {
00066   alias = conf.getParameter<std::string>("@module_label");
00067   edm::ParameterSet ParamSet=conf_.getParameter<edm::ParameterSet>("DigiModeList");
00068   
00069   produces<edm::DetSetVector<SiStripDigi> >(ParamSet.getParameter<std::string>("ZSDigi")).setBranchAlias( ParamSet.getParameter<std::string>("ZSDigi") );
00070   produces<edm::DetSetVector<StripDigiSimLink> >().setBranchAlias ( alias + "siStripDigiSimLink");
00071   produces<edm::DetSetVector<SiStripRawDigi> >(ParamSet.getParameter<std::string>("SCDigi")).setBranchAlias( alias + ParamSet.getParameter<std::string>("SCDigi") );
00072   produces<edm::DetSetVector<SiStripRawDigi> >(ParamSet.getParameter<std::string>("VRDigi")).setBranchAlias( alias + ParamSet.getParameter<std::string>("VRDigi") );
00073   produces<edm::DetSetVector<SiStripRawDigi> >(ParamSet.getParameter<std::string>("PRDigi")).setBranchAlias( alias + ParamSet.getParameter<std::string>("PRDigi") );
00074   trackerContainers.clear();
00075   trackerContainers = conf.getParameter<std::vector<std::string> >("ROUList");
00076   geometryType = conf.getParameter<std::string>("GeometryType");
00077   useConfFromDB = conf.getParameter<bool>("TrackerConfigurationFromDB");
00078   edm::Service<edm::RandomNumberGenerator> rng;
00079   if ( ! rng.isAvailable()) {
00080     throw cms::Exception("Configuration")
00081       << "SiStripDigitizer requires the RandomNumberGeneratorService\n"
00082       "which is not present in the configuration file.  You must add the service\n"
00083       "in the configuration file or remove the modules that require it.";
00084   }
00085   
00086   rndEngine       = &(rng->getEngine());
00087   zeroSuppression = conf_.getParameter<bool>("ZeroSuppression");
00088   theDigiAlgo = new SiStripDigitizerAlgorithm(conf_,(*rndEngine));
00089 
00090 }
00091 
00092 // Virtual destructor needed.
00093 SiStripDigitizer::~SiStripDigitizer() { 
00094   delete theDigiAlgo;
00095 }  
00096 
00097 // Functions that gets called by framework every event
00098 void SiStripDigitizer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00099 {
00100   // Step A: Get Inputs
00101   edm::ESHandle < ParticleDataTable > pdt;
00102   iSetup.getData( pdt );
00103 
00104   if(useConfFromDB){
00105     edm::ESHandle<SiStripDetCabling> detCabling;
00106     iSetup.get<SiStripDetCablingRcd>().get( detCabling );
00107     detCabling->addConnected(theDetIdList);
00108   }
00109 
00110   edm::Handle<CrossingFrame<PSimHit> > cf_simhit;
00111   std::vector<const CrossingFrame<PSimHit> *> cf_simhitvec;
00112   for(uint32_t i = 0; i< trackerContainers.size();i++){
00113     iEvent.getByLabel("mix",trackerContainers[i],cf_simhit);
00114     cf_simhitvec.push_back(cf_simhit.product());
00115   }
00116 
00117   std::auto_ptr<MixCollection<PSimHit> > allTrackerHits(new MixCollection<PSimHit>(cf_simhitvec));
00118   
00119   //Loop on PSimHit
00120   SimHitMap.clear();
00121   
00122   //inside SimHitSelectorFromDb add the counter information from the original allhits collection 
00123   std::vector<std::pair<const PSimHit*,int> > trackerHits(SimHitSelectorFromDB_.getSimHit(allTrackerHits,theDetIdList));
00124   std::vector<std::pair<const PSimHit*,int> >::iterator isim;
00125   for (isim=trackerHits.begin() ; isim!= trackerHits.end();isim++) {
00126     //make a pair = <*isim, counter> and save also position in the vector for DigiSimLink
00127     SimHitMap[((*isim).first)->detUnitId()].push_back(*isim);
00128   }
00129   
00130   edm::ESHandle<TrackerGeometry> pDD;
00131   iSetup.get<TrackerDigiGeometryRecord>().get(geometryType,pDD);
00132   
00133   edm::ESHandle<MagneticField> pSetup;
00134   iSetup.get<IdealMagneticFieldRecord>().get(pSetup);
00135   
00136   //get gain noise pedestal lorentzAngle from ES handle
00137   edm::ESHandle<SiStripLorentzAngle> lorentzAngleHandle;
00138   edm::ESHandle<SiStripGain> gainHandle;
00139   edm::ESHandle<SiStripNoises> noiseHandle;
00140   edm::ESHandle<SiStripThreshold> thresholdHandle;
00141   edm::ESHandle<SiStripPedestals> pedestalHandle;
00142   edm::ESHandle<SiStripBadStrip> deadChannelHandle;
00143   std::string LAname = conf_.getParameter<std::string>("LorentzAngle");
00144   iSetup.get<SiStripLorentzAngleSimRcd>().get(LAname,lorentzAngleHandle);
00145   std::string gainLabel = conf_.getParameter<std::string>("Gain");
00146   iSetup.get<SiStripGainSimRcd>().get(gainLabel,gainHandle);
00147   iSetup.get<SiStripNoisesRcd>().get(noiseHandle);
00148   iSetup.get<SiStripThresholdRcd>().get(thresholdHandle);
00149   iSetup.get<SiStripPedestalsRcd>().get(pedestalHandle);
00150   iSetup.get<SiStripBadChannelRcd>().get(deadChannelHandle);
00151   
00152   theDigiAlgo->setParticleDataTable(&*pdt);
00153 
00154   // Step B: LOOP on StripGeomDetUnit
00155   theDigiVector.reserve(10000);
00156   theDigiVector.clear();
00157   theDigiLinkVector.reserve(10000);
00158   theDigiLinkVector.clear();
00159 
00160   for(TrackingGeometry::DetUnitContainer::const_iterator iu = pDD->detUnits().begin(); iu != pDD->detUnits().end(); iu ++){
00161     if(useConfFromDB){
00162       //apply the cable map _before_ digitization: consider only the detis that are connected 
00163       if(theDetIdList.find((*iu)->geographicalId().rawId())==theDetIdList.end())
00164         continue;
00165     }
00166     GlobalVector bfield=pSetup->inTesla((*iu)->surface().position());
00167     StripGeomDetUnit* sgd = dynamic_cast<StripGeomDetUnit*>((*iu));
00168     if (sgd != 0){
00169       edm::DetSet<SiStripDigi> collectorZS((*iu)->geographicalId().rawId());
00170       edm::DetSet<SiStripRawDigi> collectorRaw((*iu)->geographicalId().rawId());
00171       edm::DetSet<StripDigiSimLink> linkcollector((*iu)->geographicalId().rawId());
00172       float langle = (lorentzAngleHandle.isValid()) ? lorentzAngleHandle->getLorentzAngle((*iu)->geographicalId().rawId()) : 0.;
00173       theDigiAlgo->run(collectorZS,collectorRaw,SimHitMap[(*iu)->geographicalId().rawId()],sgd,bfield,langle,
00174                        gainHandle,thresholdHandle,noiseHandle,pedestalHandle, deadChannelHandle);
00175       if(zeroSuppression){
00176         if(collectorZS.data.size()>0){
00177           theDigiVector.push_back(collectorZS);
00178           if(SimHitMap[(*iu)->geographicalId().rawId()].size()>0){
00179             linkcollector.data = theDigiAlgo->make_link();
00180             if(linkcollector.data.size()>0)
00181               theDigiLinkVector.push_back(linkcollector);
00182           }
00183         }
00184       }else{
00185         if(collectorRaw.data.size()>0){
00186           theRawDigiVector.push_back(collectorRaw);
00187           if(SimHitMap[(*iu)->geographicalId().rawId()].size()>0){
00188             linkcollector.data = theDigiAlgo->make_link();
00189             if(linkcollector.data.size()>0)
00190               theDigiLinkVector.push_back(linkcollector);
00191           }
00192         }
00193       }
00194     }
00195   }
00196 
00197   if(zeroSuppression){
00198     // Step C: create output collection
00199     std::auto_ptr<edm::DetSetVector<SiStripRawDigi> > output_virginraw(new edm::DetSetVector<SiStripRawDigi>());
00200     std::auto_ptr<edm::DetSetVector<SiStripRawDigi> > output_scopemode(new edm::DetSetVector<SiStripRawDigi>());
00201     std::auto_ptr<edm::DetSetVector<SiStripRawDigi> > output_processedraw(new edm::DetSetVector<SiStripRawDigi>());
00202     std::auto_ptr<edm::DetSetVector<SiStripDigi> > output(new edm::DetSetVector<SiStripDigi>(theDigiVector) );
00203     std::auto_ptr<edm::DetSetVector<StripDigiSimLink> > outputlink(new edm::DetSetVector<StripDigiSimLink>(theDigiLinkVector) );
00204     // Step D: write output to file
00205     edm::ParameterSet ParamSet=conf_.getParameter<edm::ParameterSet>("DigiModeList");
00206     iEvent.put(output,ParamSet.getParameter<std::string>("ZSDigi"));
00207     iEvent.put(outputlink);
00208     iEvent.put(output_scopemode,   ParamSet.getParameter<std::string>("SCDigi"));
00209     iEvent.put(output_virginraw,   ParamSet.getParameter<std::string>("VRDigi"));
00210     iEvent.put(output_processedraw,ParamSet.getParameter<std::string>("PRDigi"));
00211   }else{
00212     // Step C: create output collection
00213     std::auto_ptr<edm::DetSetVector<SiStripRawDigi> > output_virginraw(new edm::DetSetVector<SiStripRawDigi>(theRawDigiVector));
00214     std::auto_ptr<edm::DetSetVector<SiStripRawDigi> > output_scopemode(new edm::DetSetVector<SiStripRawDigi>());
00215     std::auto_ptr<edm::DetSetVector<SiStripRawDigi> > output_processedraw(new edm::DetSetVector<SiStripRawDigi>());
00216     std::auto_ptr<edm::DetSetVector<SiStripDigi> > output(new edm::DetSetVector<SiStripDigi>() );
00217     std::auto_ptr<edm::DetSetVector<StripDigiSimLink> > outputlink(new edm::DetSetVector<StripDigiSimLink>(theDigiLinkVector) );
00218     // Step D: write output to file
00219     edm::ParameterSet ParamSet=conf_.getParameter<edm::ParameterSet>("DigiModeList");
00220     iEvent.put(output,ParamSet.getParameter<std::string>("ZSDigi"));
00221     iEvent.put(outputlink);
00222     iEvent.put(output_scopemode,   ParamSet.getParameter<std::string>("SCDigi"));
00223     iEvent.put(output_virginraw,   ParamSet.getParameter<std::string>("VRDigi"));
00224     iEvent.put(output_processedraw,ParamSet.getParameter<std::string>("PRDigi"));
00225   }
00226 }