CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AlCaDiJetsProducer.cc
Go to the documentation of this file.
6 
7 using namespace edm;
8 using namespace std;
9 using namespace reco;
10 
11 namespace cms
12 {
13 
14 AlCaDiJetsProducer::AlCaDiJetsProducer(const edm::ParameterSet& iConfig)
15 {
16  tok_jets_ = consumes<CaloJetCollection>(iConfig.getParameter<edm::InputTag>("jetsInput"));
17  ecalLabels_=iConfig.getParameter<std::vector<edm::InputTag> >("ecalInputs");
18  tok_hbhe_ = consumes<HBHERecHitCollection>(iConfig.getParameter<edm::InputTag>("hbheInput"));
19  tok_ho_ = consumes<HORecHitCollection>(iConfig.getParameter<edm::InputTag>("hoInput"));
20  tok_hf_ = consumes<HFRecHitCollection>(iConfig.getParameter<edm::InputTag>("hfInput"));
21  allowMissingInputs_ = true;
22 
23  // fill ecal tokens from input labels
24  const unsigned nLabels = ecalLabels_.size();
25  for ( unsigned i=0; i != nLabels; i++ )
26  toks_ecal_.push_back(consumes<EcalRecHitCollection>(ecalLabels_[i]));
27 
28 //register your products
29  produces<CaloJetCollection>("DiJetsBackToBackCollection");
30  produces<EcalRecHitCollection>("DiJetsEcalRecHitCollection");
31  produces<HBHERecHitCollection>("DiJetsHBHERecHitCollection");
32  produces<HORecHitCollection>("DiJetsHORecHitCollection");
33  produces<HFRecHitCollection>("DiJetsHFRecHitCollection");
34 
35 }
37 {
38 }
39 
40 AlCaDiJetsProducer::~AlCaDiJetsProducer()
41 {
42 
43 
44 }
45 
46 
47 // ------------ method called to produce the data ------------
48 void
49 AlCaDiJetsProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
50 {
51 
52  double pi = 4.*atan(1.);
53 
54  std::auto_ptr<CaloJetCollection> result (new CaloJetCollection); //Corrected jets
55  std::auto_ptr<EcalRecHitCollection> miniDiJetsEcalRecHitCollection(new EcalRecHitCollection);
56  std::auto_ptr<HBHERecHitCollection> miniDiJetsHBHERecHitCollection(new HBHERecHitCollection);
57  std::auto_ptr<HORecHitCollection> miniDiJetsHORecHitCollection(new HORecHitCollection);
58  std::auto_ptr<HFRecHitCollection> miniDiJetsHFRecHitCollection(new HFRecHitCollection);
59 
61  iSetup.get<CaloGeometryRecord>().get(pG);
62  const CaloGeometry* geo = pG.product();
63 
64  // Jets Collections
65 
66  vector<CaloJet> jetv;
67 
68  CaloJet fJet1, fJet2, fJet3;
70  iEvent.getByToken(tok_jets_, jets);
71  int iflag_select = 0;
72  if(jets->size()>1){
73  fJet1 = (*jets)[0];
74  fJet2 = (*jets)[1];
75  double dphi = fabs(fJet1.phi() - fJet2.phi());
76  if(dphi > pi){dphi = 2*pi - dphi;}
77  double degreedphi = dphi*180./pi;
78  if(fabs(degreedphi-180)<30.){iflag_select = 1;}
79  }
80  if(iflag_select == 1){
81  result->push_back(fJet1);
82  result->push_back(fJet2);
83  jetv.push_back(fJet1);
84  jetv.push_back(fJet2);
85  if(jets->size()>2){
86  fJet3 = (*jets)[2];
87  result->push_back(fJet3);
88  jetv.push_back(fJet3);
89  }
90  } else {
91  iEvent.put( result, "DiJetsBackToBackCollection");
92  iEvent.put( miniDiJetsEcalRecHitCollection,"DiJetsEcalRecHitCollection");
93  iEvent.put( miniDiJetsHBHERecHitCollection, "DiJetsHBHERecHitCollection");
94  iEvent.put( miniDiJetsHORecHitCollection, "DiJetsHORecHitCollection");
95  iEvent.put( miniDiJetsHFRecHitCollection, "DiJetsHFRecHitCollection");
96  return;
97  }
98 
99  // Ecal Collections
100 
101  std::vector<edm::EDGetTokenT<EcalRecHitCollection> >::const_iterator i;
102  for (i=toks_ecal_.begin(); i!=toks_ecal_.end(); i++) {
104  iEvent.getByToken(*i,ec);
105  for(EcalRecHitCollection::const_iterator ecItr = (*ec).begin();
106  ecItr != (*ec).end(); ++ecItr)
107  {
108 // EcalBarrel = 1, EcalEndcap = 2
109  GlobalPoint pos = geo->getPosition(ecItr->detid());
110  double phihit = pos.phi();
111  double etahit = pos.eta();
112  int iflag_select = 0;
113  for(unsigned int i=0; i<jetv.size(); i++){
114  double deta = fabs(etahit - jetv[i].eta());
115  double dphi = fabs(phihit - jetv[i].phi());
116  if(dphi > pi) dphi = 2*pi - dphi;
117  double dr = sqrt(deta*deta+dphi*dphi);
118  if(dr < 1.4){iflag_select = 1;}
119  }
120  if(iflag_select==1){miniDiJetsEcalRecHitCollection->push_back(*ecItr);}
121  }
122 
123  }
124 
125  // HB & HE Collections
126 
128  iEvent.getByToken(tok_hbhe_,hbhe);
129  for(HBHERecHitCollection::const_iterator hbheItr=hbhe->begin();
130  hbheItr!=hbhe->end(); hbheItr++)
131  {
132  GlobalPoint pos = geo->getPosition(hbheItr->detid());
133  double phihit = pos.phi();
134  double etahit = pos.eta();
135  int iflag_select = 0;
136  for(unsigned int i=0; i<jetv.size(); i++){
137  double deta = fabs(etahit - jetv[i].eta());
138  double dphi = fabs(phihit - jetv[i].phi());
139  if(dphi > pi) dphi = 2*pi - dphi;
140  double dr = sqrt(deta*deta+dphi*dphi);
141  if(dr < 1.4){iflag_select = 1;}
142  }
143  if(iflag_select==1){miniDiJetsHBHERecHitCollection->push_back(*hbheItr);}
144  }
145 
146 
147 // HO Collections
148 
149 
151  iEvent.getByToken(tok_ho_,ho);
152  for(HORecHitCollection::const_iterator hoItr=ho->begin();
153  hoItr!=ho->end(); hoItr++)
154  {
155  GlobalPoint pos = geo->getPosition(hoItr->detid());
156  double phihit = pos.phi();
157  double etahit = pos.eta();
158  int iflag_select = 0;
159  for(unsigned int i=0; i<jetv.size(); i++){
160  double deta = fabs(etahit - jetv[i].eta());
161  double dphi = fabs(phihit - jetv[i].phi());
162  if(dphi > pi) dphi = 2*pi - dphi;
163  double dr = sqrt(deta*deta+dphi*dphi);
164  if(dr < 1.4){iflag_select = 1;}
165  }
166  if(iflag_select==1){miniDiJetsHORecHitCollection->push_back(*hoItr);}
167  }
168 
169  // HF Collection
170 
171 
173  iEvent.getByToken(tok_hf_,hf);
174  for(HFRecHitCollection::const_iterator hfItr=hf->begin();
175  hfItr!=hf->end(); hfItr++)
176  {
177  GlobalPoint pos = geo->getPosition(hfItr->detid());
178  double phihit = pos.phi();
179  double etahit = pos.eta();
180  int iflag_select = 0;
181  for(unsigned int i=0; i<jetv.size(); i++){
182  double deta = fabs(etahit - jetv[i].eta());
183  double dphi = fabs(phihit - jetv[i].phi());
184  if(dphi > pi) dphi = 2*pi - dphi;
185  double dr = sqrt(deta*deta+dphi*dphi);
186  if(dr < 1.4){iflag_select = 1;}
187  }
188  if(iflag_select==1){miniDiJetsHFRecHitCollection->push_back(*hfItr);}
189  }
190 
191 
192  //Put selected information in the event
193 
194  iEvent.put( result, "DiJetsBackToBackCollection");
195  iEvent.put( miniDiJetsEcalRecHitCollection,"DiJetsEcalRecHitCollection");
196  iEvent.put( miniDiJetsHBHERecHitCollection, "DiJetsHBHERecHitCollection");
197  iEvent.put( miniDiJetsHORecHitCollection, "DiJetsHORecHitCollection");
198  iEvent.put( miniDiJetsHFRecHitCollection, "DiJetsHFRecHitCollection");
199 }
200 }
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
Jets made from CaloTowers.
Definition: CaloJet.h:29
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
std::vector< EcalRecHit >::const_iterator const_iterator
T eta() const
void beginJob()
Definition: Breakpoints.cc:15
const Double_t pi
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
T sqrt(T t)
Definition: SSEVec.h:48
vector< PseudoJet > jets
tuple result
Definition: query.py:137
const GlobalPoint & getPosition(const DetId &id) const
Get the position of a given detector id.
Definition: CaloGeometry.cc:68
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:86
T eta() const
Definition: PV3DBase.h:76
virtual double phi() const
momentum azimuthal angle
std::vector< CaloJet > CaloJetCollection
collection of CaloJet objects
Definition: DDAxes.h:10