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::beginRun( const edm::Run&, const edm::EventSetup& setup) {
00040 updateCabling( setup );
00041 }
00042
00043 void SiStripRawToClustersRoI::produce(edm::Event& event, const edm::EventSetup& setup) {
00044
00045 updateCabling( setup );
00046
00047 edm::Handle< LazyGetter > lazygetter;
00048 event.getByLabel(siStripLazyGetter_,lazygetter);
00049
00051
00052 if (global_) {
00053 std::auto_ptr<RefGetter> globalrefgetter(new RefGetter(lazygetter,allregions_));
00054
00055
00056 event.put(globalrefgetter);
00057 return;
00058 }
00059
00060 std::auto_ptr<RefGetter> refgetter(new RefGetter(allregions_.size()));
00061 refgetter->reserve(10000);
00062
00064
00065 if (random_) {random(*refgetter,lazygetter);}
00066
00068
00069 if (electrons_) {
00070 edm::Handle<reco::SuperClusterCollection> barrelcollection;
00071 edm::Handle<reco::SuperClusterCollection> endcapcollection;
00072 event.getByLabel(electronBarrelL2_,barrelcollection);
00073 event.getByLabel(electronEndcapL2_,endcapcollection);
00074 if (barrelcollection.isValid()) {
00075 electrons(*barrelcollection,*refgetter,lazygetter);
00076 }
00077 if (endcapcollection.isValid()) {
00078 electrons(*endcapcollection,*refgetter,lazygetter);
00079 }
00080 }
00081
00083
00084 if (muons_) {
00085 edm::Handle<reco::TrackCollection> collection;
00086 event.getByLabel(muonL2_,collection);
00087 if (collection.isValid()) {
00088 muons(*collection,*refgetter,lazygetter);
00089 }
00090 }
00091
00093
00094 if (taujets_) {
00095 edm::Handle<reco::CaloJetCollection> collection;
00096 event.getByLabel(taujetL2_,collection);
00097 if (collection.isValid()) {
00098 taujets(*collection,*refgetter,lazygetter);
00099 }
00100 }
00101
00103
00104 if (bjets_) {
00105 edm::Handle<reco::CaloJetCollection> collection;
00106 event.getByLabel(bjetL2_,collection);
00107 if (collection.isValid()) {
00108 bjets(*collection,*refgetter,lazygetter);
00109 }
00110 }
00111
00112 event.put(refgetter);
00113 }
00114
00115
00117 void SiStripRawToClustersRoI::updateCabling( const edm::EventSetup& setup ) {
00118 uint32_t cache_id = setup.get<SiStripRegionCablingRcd>().cacheIdentifier();
00119 if ( cacheId_ != cache_id ) {
00120 edm::ESHandle<SiStripRegionCabling> c;
00121 setup.get<SiStripRegionCablingRcd>().get( c );
00122 cabling_ = c.product();
00123 cacheId_ = cache_id;
00124 allregions_.clear();
00125 allregions_.reserve( cabling_->getRegionCabling().size() );
00126 for (uint32_t iregion=0;iregion<cabling_->getRegionCabling().size();iregion++) {
00127 for (uint32_t isubdet=0;isubdet<cabling_->getRegionCabling()[iregion].size();isubdet++) {
00128 for (uint32_t ilayer=0;ilayer<cabling_->getRegionCabling()[iregion][isubdet].size();ilayer++) {
00129 uint32_t index = SiStripRegionCabling::elementIndex(iregion,static_cast<SubDet>(isubdet),ilayer);
00130 allregions_.push_back(index);
00131 }
00132 }
00133 }
00134 }
00135 }
00136
00137 bool SiStripRawToClustersRoI::physicalLayer(SubDet& subdet, uint32_t& layer) const {
00138 int signedlayer = static_cast<int>(SiStripRegionCabling::physicalLayer(subdet,layer));
00139 return (nlayers_ == -1 || signedlayer < nlayers_) ? true : false;
00140 }
00141
00142 void SiStripRawToClustersRoI::random(RefGetter& refgetter, edm::Handle<LazyGetter>& lazygetter) const {
00143
00144 uint32_t total = cabling_->getRegionCabling().size();
00145 uint32_t required = static_cast<uint32_t>(CLHEP::RandFlat::shoot()*(total+1));
00146 for (uint32_t iregion = 0; iregion < required; iregion++) {
00147 for (uint32_t isubdet = 0; isubdet < SiStripRegionCabling::ALLSUBDETS; isubdet++) {
00148 SubDet subdet = static_cast<SubDet>(isubdet);
00149 for (uint32_t ilayer = 0; ilayer < SiStripRegionCabling::ALLLAYERS; ilayer++) {
00150 if (!physicalLayer(subdet,ilayer)) break;
00151 cabling_->updateSiStripRefGetter<SiStripCluster>(refgetter,lazygetter,SiStripRegionCabling::elementIndex(iregion,subdet,ilayer));
00152 }
00153 }
00154 }
00155 }
00156
00157 void SiStripRawToClustersRoI::electrons(const reco::SuperClusterCollection& collection, RefGetter& refgetter, edm::Handle<LazyGetter>& lazygetter) const {
00158
00159 reco::SuperClusterCollection::const_iterator icollection = collection.begin();
00160 for (; icollection!=collection.end(); icollection++) {
00161 Position position(icollection->eta(),icollection->phi());
00162 for (uint32_t isubdet = 0; isubdet < SiStripRegionCabling::ALLSUBDETS; isubdet++) {
00163 SubDet subdet = static_cast<SubDet>(isubdet);
00164 for (uint32_t ilayer = 0; ilayer < SiStripRegionCabling::ALLLAYERS; ilayer++) {
00165 if (!physicalLayer(subdet,ilayer)) break;
00166 cabling_->updateSiStripRefGetter<SiStripCluster>(refgetter,lazygetter,position,electrondeta_,electrondphi_,subdet,ilayer);
00167 }
00168 }
00169 }
00170 }
00171
00172 void SiStripRawToClustersRoI::muons(const reco::TrackCollection& collection, RefGetter& refgetter, edm::Handle<LazyGetter>& lazygetter) const {
00173
00174 reco::TrackCollection::const_iterator icollection = collection.begin();
00175 for (; icollection!=collection.end(); icollection++) {
00176 Position position(icollection->outerPosition().eta(),icollection->outerPosition().phi());
00177 for (uint32_t isubdet = 0; isubdet < SiStripRegionCabling::ALLSUBDETS; isubdet++) {
00178 SubDet subdet = static_cast<SubDet>(isubdet);
00179 for (uint32_t ilayer = 0; ilayer < SiStripRegionCabling::ALLLAYERS; ilayer++) {
00180 if (!physicalLayer(subdet,ilayer)) break;
00181 cabling_->updateSiStripRefGetter<SiStripCluster>(refgetter,lazygetter,position,muondeta_,muondphi_,subdet,ilayer);
00182 }
00183 }
00184 }
00185 }
00186
00187 void SiStripRawToClustersRoI::taujets(const reco::CaloJetCollection& collection, RefGetter& refgetter, edm::Handle<LazyGetter>& lazygetter) const {
00188
00189 reco::CaloJetCollection::const_iterator icollection = collection.begin();
00190 for (; icollection!=collection.end(); icollection++) {
00191 Position position(icollection->eta(),icollection->phi());
00192 for (uint32_t isubdet = 0; isubdet < SiStripRegionCabling::ALLSUBDETS; isubdet++) {
00193 SubDet subdet = static_cast<SubDet>(isubdet);
00194 for (uint32_t ilayer = 0; ilayer < SiStripRegionCabling::ALLLAYERS; ilayer++) {
00195 if (!physicalLayer(subdet,ilayer)) break;
00196 cabling_->updateSiStripRefGetter<SiStripCluster>(refgetter,lazygetter,position,taujetdeta_,taujetdphi_,subdet,ilayer);
00197 }
00198 }
00199 }
00200 }
00201
00202 void SiStripRawToClustersRoI::bjets(const reco::CaloJetCollection& collection, RefGetter& refgetter, edm::Handle<LazyGetter>& lazygetter) const {
00203
00204 reco::CaloJetCollection::const_iterator icollection = collection.begin();
00205 for (; icollection!=collection.end(); icollection++) {
00206 Position position(icollection->eta(),icollection->phi());
00207 for (uint32_t isubdet = 0; isubdet < SiStripRegionCabling::ALLSUBDETS; isubdet++) {
00208 SubDet subdet = static_cast<SubDet>(isubdet);
00209 for (uint32_t ilayer = 0; ilayer < SiStripRegionCabling::ALLLAYERS; ilayer++) {
00210 if (!physicalLayer(subdet,ilayer)) break;
00211 cabling_->updateSiStripRefGetter<SiStripCluster>(refgetter,lazygetter,position,bjetdeta_,bjetdphi_,subdet,ilayer);
00212 }
00213 }
00214 }
00215 }
00216