CMS 3D CMS Logo

EgammaIsoHcalDetIdCollectionProducer.cc
Go to the documentation of this file.
2 
5 
8 
10 {
11 
12  recHitsToken_ =
13  consumes<HBHERecHitCollection>(iConfig.getParameter< edm::InputTag > ("recHitsLabel"));
14  elesToken_ =
15  consumes<reco::GsfElectronCollection>(iConfig.getParameter< edm::InputTag >("elesLabel"));
16 
17  phosToken_ =
18  consumes<reco::PhotonCollection>(iConfig.getParameter< edm::InputTag >("phosLabel"));
19 
21  consumes<reco::SuperClusterCollection>(iConfig.getParameter< edm::InputTag >("superClustersLabel"));
22 
23  minSCEt_ = iConfig.getParameter<double>("minSCEt");
24  minEleEt_ = iConfig.getParameter<double>("minEleEt");
25  minPhoEt_ = iConfig.getParameter<double>("minPhoEt");
26 
27 
28  interestingDetIdCollection_ = iConfig.getParameter<std::string>("interestingDetIdCollection");
29 
30  maxDIEta_ = iConfig.getParameter<int>("maxDIEta");
31  maxDIPhi_ = iConfig.getParameter<int>("maxDIPhi");
32 
33  minEnergyHCAL_= iConfig.getParameter<double>("minEnergyHCAL");
34 
35  //register your products
36  produces< DetIdCollection > (interestingDetIdCollection_) ;
37 
38 
39 }
40 
41 
43 {
44  iSetup.get<CaloGeometryRecord>().get(towerMap_);
45  // std::cout <<" got geom "<<towerMap_.isValid()<<" "<<&(*towerMap_)<<std::endl;
46 }
47 
48 // ------------ method called to produce the data ------------
49 void
51  const edm::EventSetup& iSetup)
52 {
53 
54  // take BasicClusters
56  iEvent.getByToken(superClustersToken_, superClusters);
57 
59  iEvent.getByToken(elesToken_,eles);
60 
62  iEvent.getByToken(phosToken_,phos);
63 
65  iEvent.getByToken(recHitsToken_,recHits);
66 
67  //Create empty output collections
68  std::vector<DetId> indexToStore;
69  indexToStore.reserve(100);
70 
71  if(eles.isValid() && recHits.isValid()){
72  for(auto& ele : *eles){
73 
74  float scEt = ele.superCluster()->energy()*std::sin(ele.superCluster()->position().theta());
75  if(scEt > minEleEt_ || ele.et()> minEleEt_) addDetIds(*ele.superCluster(),*recHits,indexToStore);
76  }
77  }
78  if(phos.isValid() && recHits.isValid()){
79  for(auto& pho : *phos){
80  float scEt = pho.superCluster()->energy()*std::sin(pho.superCluster()->position().theta());
81  if(scEt > minPhoEt_ || pho.et()> minPhoEt_) addDetIds(*pho.superCluster(),*recHits,indexToStore);
82  }
83  }
84  if(superClusters.isValid() && recHits.isValid()){
85  for(auto& sc : *superClusters){
86  float scEt = sc.energy()*std::sin(sc.position().theta());
87  if(scEt > minSCEt_) addDetIds(sc,*recHits,indexToStore);
88  }
89  }
90 
91  //unify the vector
92  std::sort(indexToStore.begin(),indexToStore.end());
93  std::unique(indexToStore.begin(),indexToStore.end());
94 
95  auto detIdCollection = std::make_unique<DetIdCollection>(indexToStore);
96 
97  iEvent.put(std::move(detIdCollection), interestingDetIdCollection_ );
98 
99 }
100 
101 //some nasty hardcoded badness
102 int calDIEta(int iEta1,int iEta2)
103 {
104 
105  int dEta = iEta1-iEta2;
106  if(iEta1*iEta2<0) {//-ve to +ve transistion and no crystal at zero
107  if(dEta<0) dEta++;
108  else dEta--;
109  }
110  return dEta;
111 }
112 
113 //some nasty hardcoded badness
114 int calDIPhi(int iPhi1,int iPhi2)
115 {
116 
117  int dPhi = iPhi1-iPhi2;
118 
119  if(dPhi>72/2) dPhi-=72;
120  else if(dPhi<-72/2) dPhi+=72;
121 
122  return dPhi;
123 
124 }
125 
126 
127 void
128 EgammaIsoHcalDetIdCollectionProducer::addDetIds(const reco::SuperCluster& superClus,const HBHERecHitCollection& recHits,std::vector<DetId>& detIdsToStore)
129 {
130  DetId seedId = superClus.seed()->seed();
131  if(seedId.det() != DetId::Ecal && seedId.det() != DetId::Forward) {
132  edm::LogError("EgammaIsoHcalDetIdCollectionProducerError") << "Somehow the supercluster has a seed which is not ECAL, something is badly wrong";
133  }
134  //so we are using CaloTowers to get the iEta/iPhi of the HCAL rec hit behind the seed cluster, this might go funny on tower 28 but shouldnt matter there
135 
136  if( seedId.det() == DetId::Forward ) return;
137 
139  int seedHcalIEta = towerId.ieta();
140  int seedHcalIPhi = towerId.iphi();
141 
142  for(auto& recHit : recHits){
143  int dIEtaAbs = std::abs(calDIEta(seedHcalIEta,recHit.id().ieta()));
144  int dIPhiAbs = std::abs(calDIPhi(seedHcalIPhi,recHit.id().iphi()));
145 
146  if(dIEtaAbs<=maxDIEta_ && dIPhiAbs<=maxDIPhi_ && recHit.energy()>minEnergyHCAL_) detIdsToStore.push_back(recHit.id().rawId());
147  }
148 
149 }
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
virtual void produce(edm::Event &, const edm::EventSetup &) override
producer
int calDIPhi(int iPhi1, int iPhi2)
edm::EDGetTokenT< reco::SuperClusterCollection > superClustersToken_
int iEvent
Definition: GenABIO.cc:230
CaloTowerDetId towerOf(const DetId &id) const
Get the tower id for this det id (or null if not known)
def unique(seq, keepstr=True)
Definition: tier0.py:24
edm::EDGetTokenT< HBHERecHitCollection > recHitsToken_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
float energy() const
Energy. Note this is taken from the first SimTrack only.
Definition: SimCluster.h:111
bool isValid() const
Definition: HandleBase.h:74
unsigned towerId(DetId const &)
float theta() const
Momentum polar angle. Note this is taken from the first SimTrack only.
Definition: SimCluster.h:166
Definition: DetId.h:18
const T & get() const
Definition: EventSetup.h:56
edm::EDGetTokenT< reco::GsfElectronCollection > elesToken_
EgammaIsoHcalDetIdCollectionProducer(const edm::ParameterSet &)
ctor
edm::ESHandle< CaloTowerConstituentsMap > towerMap_
edm::EDGetTokenT< reco::PhotonCollection > phosToken_
void addDetIds(const reco::SuperCluster &superClus, const HBHERecHitCollection &recHits, std::vector< DetId > &detIdsToStore)
const CaloClusterPtr & seed() const
seed BasicCluster
Definition: SuperCluster.h:66
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
virtual void beginRun(edm::Run const &, const edm::EventSetup &) override final
int calDIEta(int iEta1, int iEta2)
def move(src, dest)
Definition: eostools.py:510
Definition: Run.h:42