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