CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EgammaIsoHcalDetIdCollectionProducer.cc
Go to the documentation of this file.
2 
5 
6 
7 
8 
11 
12 
14 {
15 
16  recHitsToken_ =
17  consumes<HBHERecHitCollection>(iConfig.getParameter< edm::InputTag > ("recHitsLabel"));
18  elesToken_ =
19  consumes<reco::GsfElectronCollection>(iConfig.getParameter< edm::InputTag >("elesLabel"));
20 
21  phosToken_ =
22  consumes<reco::PhotonCollection>(iConfig.getParameter< edm::InputTag >("phosLabel"));
23 
25  consumes<reco::SuperClusterCollection>(iConfig.getParameter< edm::InputTag >("superClustersLabel"));
26 
27  minSCEt_ = iConfig.getParameter<double>("minSCEt");
28  minEleEt_ = iConfig.getParameter<double>("minEleEt");
29  minPhoEt_ = iConfig.getParameter<double>("minPhoEt");
30 
31 
32  interestingDetIdCollection_ = iConfig.getParameter<std::string>("interestingDetIdCollection");
33 
34  maxDIEta_ = iConfig.getParameter<int>("maxDIEta");
35  maxDIPhi_ = iConfig.getParameter<int>("maxDIPhi");
36 
37  minEnergyHCAL_= iConfig.getParameter<double>("minEnergyHCAL");
38 
39  //register your products
40  produces< DetIdCollection > (interestingDetIdCollection_) ;
41 
42 
43 }
44 
45 
47 {
48  iSetup.get<IdealGeometryRecord>().get(towerMap_);
49  // std::cout <<" got geom "<<towerMap_.isValid()<<" "<<&(*towerMap_)<<std::endl;
50 }
51 
52 // ------------ method called to produce the data ------------
53 void
55  const edm::EventSetup& iSetup)
56 {
57 
58  // take BasicClusters
60  iEvent.getByToken(superClustersToken_, superClusters);
61 
63  iEvent.getByToken(elesToken_,eles);
64 
66  iEvent.getByToken(phosToken_,phos);
67 
69  iEvent.getByToken(recHitsToken_,recHits);
70 
71  //Create empty output collections
72  std::vector<DetId> indexToStore;
73  indexToStore.reserve(100);
74 
75  if(eles.isValid() && recHits.isValid()){
76  for(auto& ele : *eles){
77 
78  float scEt = ele.superCluster()->energy()*std::sin(ele.superCluster()->position().theta());
79  if(scEt > minEleEt_ || ele.et()> minEleEt_) addDetIds(*ele.superCluster(),*recHits,indexToStore);
80  }
81  }
82  if(phos.isValid() && recHits.isValid()){
83  for(auto& pho : *phos){
84  float scEt = pho.superCluster()->energy()*std::sin(pho.superCluster()->position().theta());
85  if(scEt > minPhoEt_ || pho.et()> minPhoEt_) addDetIds(*pho.superCluster(),*recHits,indexToStore);
86  }
87  }
88  if(superClusters.isValid() && recHits.isValid()){
89  for(auto& sc : *superClusters){
90  float scEt = sc.energy()*std::sin(sc.position().theta());
91  if(scEt > minSCEt_) addDetIds(sc,*recHits,indexToStore);
92  }
93  }
94 
95  //unify the vector
96  std::sort(indexToStore.begin(),indexToStore.end());
97  std::unique(indexToStore.begin(),indexToStore.end());
98 
99  std::auto_ptr< DetIdCollection > detIdCollection (new DetIdCollection(indexToStore) ) ;
100 
101  iEvent.put( detIdCollection, interestingDetIdCollection_ );
102 
103 }
104 
105 //some nasty hardcoded badness
106 int calDIEta(int iEta1,int iEta2)
107 {
108 
109  int dEta = iEta1-iEta2;
110  if(iEta1*iEta2<0) {//-ve to +ve transistion and no crystal at zero
111  if(dEta<0) dEta++;
112  else dEta--;
113  }
114  return dEta;
115 }
116 
117 //some nasty hardcoded badness
118 int calDIPhi(int iPhi1,int iPhi2)
119 {
120 
121  int dPhi = iPhi1-iPhi2;
122 
123  if(dPhi>72/2) dPhi-=72;
124  else if(dPhi<-72/2) dPhi+=72;
125 
126  return dPhi;
127 
128 }
129 
130 
131 void
132 EgammaIsoHcalDetIdCollectionProducer::addDetIds(const reco::SuperCluster& superClus,const HBHERecHitCollection& recHits,std::vector<DetId>& detIdsToStore)
133 {
134  DetId seedId = superClus.seed()->seed();
135  if(seedId.det() != DetId::Ecal) {
136  edm::LogError("EgammaIsoHcalDetIdCollectionProducerError") << "Somehow the supercluster has a seed which is not ECAL, something is badly wrong";
137  }
138  //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
139 
140  CaloTowerDetId towerId(towerMap_->towerOf(seedId));
141  int seedHcalIEta = towerId.ieta();
142  int seedHcalIPhi = towerId.iphi();
143 
144  for(auto& recHit : recHits){
145  int dIEtaAbs = std::abs(calDIEta(seedHcalIEta,recHit.id().ieta()));
146  int dIPhiAbs = std::abs(calDIPhi(seedHcalIPhi,recHit.id().iphi()));
147 
148  if(dIEtaAbs<=maxDIEta_ && dIPhiAbs<=maxDIPhi_ && recHit.energy()>minEnergyHCAL_) detIdsToStore.push_back(recHit.id().rawId());
149  }
150 
151 }
T getParameter(std::string const &) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
int calDIPhi(int iPhi1, int iPhi2)
virtual void beginRun(edm::Run const &, const edm::EventSetup &) overridefinal
edm::EDGetTokenT< reco::SuperClusterCollection > superClustersToken_
int iEvent
Definition: GenABIO.cc:230
double dPhi(double phi1, double phi2)
Definition: JetUtil.h:30
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
edm::EDGetTokenT< HBHERecHitCollection > recHitsToken_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool isValid() const
Definition: HandleBase.h:75
unsigned towerId(DetId const &)
Definition: DetId.h:18
const T & get() const
Definition: EventSetup.h:55
virtual void produce(edm::Event &, const edm::EventSetup &)
producer
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
edm::EDCollection< DetId > DetIdCollection
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
int calDIEta(int iEta1, int iEta2)
Definition: Run.h:41