00001 #include "EventFilter/SiStripRawToDigi/plugins/SiStripRawToClustersRoI.h"
00002 #include "CalibTracker/Records/interface/SiStripRegionCablingRcd.h"
00003 #include "CLHEP/Random/RandFlat.h"
00004
00005 using namespace std;
00006 using namespace sistrip;
00007
00008 SiStripRawToClustersRoI::SiStripRawToClustersRoI(const edm::ParameterSet& conf) :
00009 cabling_(0),
00010 cacheId_(0),
00011 allregions_(),
00012 nlayers_(conf.getUntrackedParameter<int>("Layers",-1)),
00013 global_(conf.getUntrackedParameter<bool>("Global",true)),
00014 random_(conf.getUntrackedParameter<bool>("Random",false)),
00015 electrons_(conf.getUntrackedParameter<bool>("Electrons",false)),
00016 muons_(conf.getUntrackedParameter<bool>("Muons",false)),
00017 taujets_(conf.getUntrackedParameter<bool>("TauJets",false)),
00018 bjets_(conf.getUntrackedParameter<bool>("BJets",false)),
00019 siStripLazyGetter_(conf.getParameter<edm::InputTag>("SiStripLazyGetter")),
00020 electronBarrelL2_(conf.getParameter<edm::InputTag>("ElectronBarrelL2")),
00021 electronEndcapL2_(conf.getParameter<edm::InputTag>("ElectronEndcapL2")),
00022 muonL2_(conf.getParameter<edm::InputTag>("MuonL2")),
00023 taujetL2_(conf.getParameter<edm::InputTag>("TauJetL2")),
00024 bjetL2_(conf.getParameter<edm::InputTag>("BJetL2")),
00025 electrondeta_(conf.getUntrackedParameter<double>("ElectronEtaWindow",0.2)),
00026 electrondphi_(conf.getUntrackedParameter<double>("ElectronPhiWindow",0.2)),
00027 muondeta_(conf.getUntrackedParameter<double>("MuonEtaWindow",0.2)),
00028 muondphi_(conf.getUntrackedParameter<double>("MuonPhiWindow",0.2)),
00029 taujetdeta_(conf.getUntrackedParameter<double>("TauJetEtaWindow",0.2)),
00030 taujetdphi_(conf.getUntrackedParameter<double>("TauJetPhiWindow",0.2)),
00031 bjetdeta_(conf.getUntrackedParameter<double>("BJetEtaWindow",0.2)),
00032 bjetdphi_(conf.getUntrackedParameter<double>("BJetPhiWindow",0.2))
00033 {
00034 produces< RefGetter >();
00035 }
00036
00037 SiStripRawToClustersRoI::~SiStripRawToClustersRoI() {}
00038
00039 void SiStripRawToClustersRoI::beginJob(const edm::EventSetup& setup) {
00040
00041
00042 }
00043
00044 void SiStripRawToClustersRoI::beginRun( edm::Run&, const edm::EventSetup& setup) {
00045 updateCabling( setup );
00046 }
00047
00048 void SiStripRawToClustersRoI::produce(edm::Event& event, const edm::EventSetup& setup) {
00049
00050 updateCabling( setup );
00051
00052 edm::Handle< LazyGetter > lazygetter;
00053 event.getByLabel(siStripLazyGetter_,lazygetter);
00054
00056
00057 if (global_) {
00058 std::auto_ptr<RefGetter> globalrefgetter(new RefGetter(lazygetter,allregions_));
00059
00060
00061 event.put(globalrefgetter);
00062 return;
00063 }
00064
00065 std::auto_ptr<RefGetter> refgetter(new RefGetter(allregions_.size()));
00066 refgetter->reserve(10000);
00067
00069
00070 if (random_) {random(*refgetter,lazygetter);}
00071
00073
00074 if (electrons_) {
00075 try {
00076 edm::Handle<reco::SuperClusterCollection> barrelcollection;
00077 edm::Handle<reco::SuperClusterCollection> endcapcollection;
00078 event.getByLabel(electronBarrelL2_,barrelcollection);
00079 event.getByLabel(electronEndcapL2_,endcapcollection);
00080 electrons(*barrelcollection,*refgetter,lazygetter);
00081 electrons(*endcapcollection,*refgetter,lazygetter);
00082 } catch(...) {}
00083 }
00084
00086
00087 if (muons_) {
00088 try {
00089 edm::Handle<reco::TrackCollection> collection;
00090 event.getByLabel(muonL2_,collection);
00091 muons(*collection,*refgetter,lazygetter);
00092 } catch(...) {}
00093 }
00094
00096
00097 if (taujets_) {
00098 try {
00099 edm::Handle<reco::CaloJetCollection> collection;
00100 event.getByLabel(taujetL2_,collection);
00101 taujets(*collection,*refgetter,lazygetter);
00102 } catch(...) {}
00103 }
00104
00106
00107 if (bjets_) {
00108 try {
00109 edm::Handle<reco::CaloJetCollection> collection;
00110 event.getByLabel(bjetL2_,collection);
00111 bjets(*collection,*refgetter,lazygetter);
00112 } catch(...) {}
00113 }
00114
00115 event.put(refgetter);
00116 }
00117
00118
00120 void SiStripRawToClustersRoI::updateCabling( const edm::EventSetup& setup ) {
00121 uint32_t cache_id = setup.get<SiStripRegionCablingRcd>().cacheIdentifier();
00122 if ( cacheId_ != cache_id ) {
00123 edm::ESHandle<SiStripRegionCabling> c;
00124 setup.get<SiStripRegionCablingRcd>().get( c );
00125 cabling_ = c.product();
00126 cacheId_ = cache_id;
00127 allregions_.clear();
00128 allregions_.reserve( cabling_->getRegionCabling().size() );
00129 for (uint32_t iregion=0;iregion<cabling_->getRegionCabling().size();iregion++) {
00130 for (uint32_t isubdet=0;isubdet<cabling_->getRegionCabling()[iregion].size();isubdet++) {
00131 for (uint32_t ilayer=0;ilayer<cabling_->getRegionCabling()[iregion][isubdet].size();ilayer++) {
00132 uint32_t index = SiStripRegionCabling::elementIndex(iregion,static_cast<SubDet>(isubdet),ilayer);
00133 allregions_.push_back(index);
00134 }
00135 }
00136 }
00137 }
00138 }
00139
00140 bool SiStripRawToClustersRoI::physicalLayer(SubDet& subdet, uint32_t& layer) const {
00141 int signedlayer = static_cast<int>(SiStripRegionCabling::physicalLayer(subdet,layer));
00142 return (nlayers_ == -1 || signedlayer < nlayers_) ? true : false;
00143 }
00144
00145 void SiStripRawToClustersRoI::random(RefGetter& refgetter, edm::Handle<LazyGetter>& lazygetter) const {
00146
00147 uint32_t total = cabling_->getRegionCabling().size();
00148 uint32_t required = static_cast<uint32_t>(RandFlat::shoot()*(total+1));
00149 for (uint32_t iregion = 0; iregion < required; iregion++) {
00150 for (uint32_t isubdet = 0; isubdet < SiStripRegionCabling::ALLSUBDETS; isubdet++) {
00151 SubDet subdet = static_cast<SubDet>(isubdet);
00152 for (uint32_t ilayer = 0; ilayer < SiStripRegionCabling::ALLLAYERS; ilayer++) {
00153 if (!physicalLayer(subdet,ilayer)) break;
00154 cabling_->updateSiStripRefGetter<SiStripCluster>(refgetter,lazygetter,SiStripRegionCabling::elementIndex(iregion,subdet,ilayer));
00155 }
00156 }
00157 }
00158 }
00159
00160 void SiStripRawToClustersRoI::electrons(const reco::SuperClusterCollection& collection, RefGetter& refgetter, edm::Handle<LazyGetter>& lazygetter) const {
00161
00162 reco::SuperClusterCollection::const_iterator icollection = collection.begin();
00163 for (; icollection!=collection.end(); icollection++) {
00164 Position position(icollection->eta(),icollection->phi());
00165 for (uint32_t isubdet = 0; isubdet < SiStripRegionCabling::ALLSUBDETS; isubdet++) {
00166 SubDet subdet = static_cast<SubDet>(isubdet);
00167 for (uint32_t ilayer = 0; ilayer < SiStripRegionCabling::ALLLAYERS; ilayer++) {
00168 if (!physicalLayer(subdet,ilayer)) break;
00169 cabling_->updateSiStripRefGetter<SiStripCluster>(refgetter,lazygetter,position,electrondeta_,electrondphi_,subdet,ilayer);
00170 }
00171 }
00172 }
00173 }
00174
00175 void SiStripRawToClustersRoI::muons(const reco::TrackCollection& collection, RefGetter& refgetter, edm::Handle<LazyGetter>& lazygetter) const {
00176
00177 reco::TrackCollection::const_iterator icollection = collection.begin();
00178 for (; icollection!=collection.end(); icollection++) {
00179 Position position(icollection->outerPosition().eta(),icollection->outerPosition().phi());
00180 for (uint32_t isubdet = 0; isubdet < SiStripRegionCabling::ALLSUBDETS; isubdet++) {
00181 SubDet subdet = static_cast<SubDet>(isubdet);
00182 for (uint32_t ilayer = 0; ilayer < SiStripRegionCabling::ALLLAYERS; ilayer++) {
00183 if (!physicalLayer(subdet,ilayer)) break;
00184 cabling_->updateSiStripRefGetter<SiStripCluster>(refgetter,lazygetter,position,muondeta_,muondphi_,subdet,ilayer);
00185 }
00186 }
00187 }
00188 }
00189
00190 void SiStripRawToClustersRoI::taujets(const reco::CaloJetCollection& collection, RefGetter& refgetter, edm::Handle<LazyGetter>& lazygetter) const {
00191
00192 reco::CaloJetCollection::const_iterator icollection = collection.begin();
00193 for (; icollection!=collection.end(); icollection++) {
00194 Position position(icollection->eta(),icollection->phi());
00195 for (uint32_t isubdet = 0; isubdet < SiStripRegionCabling::ALLSUBDETS; isubdet++) {
00196 SubDet subdet = static_cast<SubDet>(isubdet);
00197 for (uint32_t ilayer = 0; ilayer < SiStripRegionCabling::ALLLAYERS; ilayer++) {
00198 if (!physicalLayer(subdet,ilayer)) break;
00199 cabling_->updateSiStripRefGetter<SiStripCluster>(refgetter,lazygetter,position,taujetdeta_,taujetdphi_,subdet,ilayer);
00200 }
00201 }
00202 }
00203 }
00204
00205 void SiStripRawToClustersRoI::bjets(const reco::CaloJetCollection& collection, RefGetter& refgetter, edm::Handle<LazyGetter>& lazygetter) const {
00206
00207 reco::CaloJetCollection::const_iterator icollection = collection.begin();
00208 for (; icollection!=collection.end(); icollection++) {
00209 Position position(icollection->eta(),icollection->phi());
00210 for (uint32_t isubdet = 0; isubdet < SiStripRegionCabling::ALLSUBDETS; isubdet++) {
00211 SubDet subdet = static_cast<SubDet>(isubdet);
00212 for (uint32_t ilayer = 0; ilayer < SiStripRegionCabling::ALLLAYERS; ilayer++) {
00213 if (!physicalLayer(subdet,ilayer)) break;
00214 cabling_->updateSiStripRefGetter<SiStripCluster>(refgetter,lazygetter,position,bjetdeta_,bjetdphi_,subdet,ilayer);
00215 }
00216 }
00217 }
00218 }
00219