CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SelectReplacementCandidates.cc
Go to the documentation of this file.
3 
5 {
6  using namespace edm;
7  using namespace std;
8  produces< vector<uint32_t> >();
9  produces< vector<uint32_t> >("assocHitsWithHCAL");
10  produces< std::vector<reco::Muon> >();
11 
12  targetParticleMass_=iConfig.getUntrackedParameter<double>("targetParticlesMass",1.77690);
13  targetParticlePdgID_=iConfig.getUntrackedParameter<int>("targetParticlesPdgID",15);
14 
15  muonInputTag_ = iConfig.getParameter<edm::InputTag>("muonInputTag");
16  edm::ParameterSet parameters = iConfig.getParameter<edm::ParameterSet>("TrackAssociatorParameters");
18 
20 }
21 
23 {
24 
25 }
26 
28 {
29  using namespace std;
30  using namespace edm;
31  reco::Muon muon1, muon2;
32 
33  // determine the muons to be used
34  // these can be reconstructed muons or muons from a HepMC::Event
35  if (determineMuonsToUse(iEvent, iSetup, &muon1, &muon2)!=0)
36  return;
37 
38  vector<uint32_t> hits ;
39  getRawIDsAdvanced(iEvent, iSetup, &hits, &muon1, false);
40  getRawIDsAdvanced(iEvent, iSetup, &hits, &muon2, false);
41  std::auto_ptr< vector<uint32_t> > selectedHitsAutoPtr(new vector<uint32_t>(hits) );
42  iEvent.put( selectedHitsAutoPtr );
43 
44  vector<uint32_t> assoc_hits_withHCAL;
45  getRawIDsAdvanced(iEvent, iSetup, &assoc_hits_withHCAL, &muon1, true);
46  getRawIDsAdvanced(iEvent, iSetup, &assoc_hits_withHCAL, &muon2, true);
47  std::cout << "found in total " << assoc_hits_withHCAL.size() << " cells with associated hits with hcal\n";
48  std::auto_ptr< vector<uint32_t> > selectedAssocHitsWithHCALAutoPtr(new vector<uint32_t>(assoc_hits_withHCAL) );
49  iEvent.put( selectedAssocHitsWithHCALAutoPtr, "assocHitsWithHCAL");
50 
51  std::vector<reco::Muon> muons;
52  transformMuMu2TauTau(&muon1, &muon2);
53  muons.push_back(muon1);
54  muons.push_back(muon2);
55  std::auto_ptr< std::vector<reco::Muon> > selectedMuonsPtr(new std::vector<reco::Muon>(muons) );
56  iEvent.put( selectedMuonsPtr );
57 
58 }
59 
61 {
62 
63 }
64 
66 {
67 
68 }
69 
70 
72 {
73  using namespace edm;
74  using namespace reco;
75  using namespace std;
76 
78  if (!iEvent.getByLabel("dimuonsGlobal", zCandidate_handle))
79  {
80  std::cout << "Could not find product: " << "dimuonsGlobal" << "\n";
81  std::vector< edm::Handle< edm::RefToBaseVector<reco::Candidate> > > allHandles;
82  iEvent.getManyByType(allHandles);
83  std::vector< edm::Handle< edm::RefToBaseVector<reco::Candidate> > >::iterator it;
84  for (it = allHandles.begin(); it != allHandles.end(); it++)
85  {
86  std::cout << "available product: " << (*it).provenance()->moduleLabel() << ", " << (*it).provenance()->productInstanceName() << ", " << (*it).provenance()->processName();
87  }
88 
89  std::cout << "Objekt nicht gefunden: dimuonsGloal\n";
90  return -1;
91  }
92 // std::cout << zCandidate_handle->size() << " Kandidaten gefunden!\n";
93 
94  unsigned int nMuons = zCandidate_handle->size();
95  if (nMuons==0)
96  return -1;
97 
98  for (edm::RefToBaseVector<reco::Candidate>::const_iterator z = zCandidate_handle->begin(); z!=zCandidate_handle->end(); ++z)
99  {
100  reco::Particle::LorentzVector muon1p4 = z->get()->daughter(0)->p4();
101  reco::Particle::LorentzVector muon2p4 = z->get()->daughter(1)->p4();
102 
103  edm::Handle<edm::View<reco::Muon> > trackCollection;
104  iEvent.getByLabel(muonInputTag_, trackCollection);
105  const edm::View<reco::Muon>& muons = * trackCollection;
106 
107  bool found1=false, found2=false;
108  for (unsigned int i=0;i<muons.size() && !(found1 && found2);i++)
109  {
110  if (deltaR(muon1p4,muons[i].p4())<0.1)
111  {
112  *muon1 = muons[i];
113  found1=true;
114  }
115  if (deltaR(muon2p4,muons[i].p4())<0.1)
116  {
117  *muon2 = muons[i];
118  found2=true;
119  }
120  }
121 
122  break;
123  }
124  return 0;
125 }
126 
127 
129 {
130  using namespace edm;
131  using namespace reco;
132  using namespace std;
133 
134  Handle<MuonCollection> muonHandle;
135  if (!iEvent.getByLabel(muonInputTag_,muonHandle))
136  ProductNotFound<reco::MuonCollection>(iEvent, muonInputTag_);
137 
138  edm::Handle<edm::View<reco::Muon> > trackCollection;
139  iEvent.getByLabel(muonInputTag_, trackCollection);
140  const edm::View<reco::Muon>& muons = * trackCollection;
141 
142  unsigned int nMuons = muons.size();
143  if (nMuons<2)
144  return -1;
145 
146  *muon1 = muons[0];
147  *muon2 = muons[1];
148  std::cout << muons[0].p4() << "\n";
149  std::cout << muons[1].p4() << "\n";
150 
151  return 0;
152 }
153 
154 void SelectReplacementCandidates::getRawIDsAdvanced(const edm::Event& iEvent, const edm::EventSetup& iConfig, std::vector<uint32_t> * L, reco::Muon * muon, bool includeHCAL)
155 {
156  using namespace edm;
157  using namespace reco;
158  using namespace std;
159 
160  if (muon->bestTrackRef().isNonnull())
161  {
162  TrackDetMatchInfo info = trackAssociator_.associate(iEvent, iConfig, *(muon->bestTrackRef().get()), parameters_);
163  if (includeHCAL)
164  {
165  for(std::vector<const EcalRecHit*>::const_iterator hit = info.ecalRecHits.begin(); hit != info.ecalRecHits.end(); ++hit)
166  L->push_back((*hit)->detid().rawId());
167 
168  for(std::vector<const HBHERecHit*>::const_iterator hit = info.hcalRecHits.begin(); hit != info.hcalRecHits.end(); ++hit)
169  L->push_back((*hit)->detid().rawId());
170  }
171  int recs = (muon->bestTrackRef().get())->recHitsSize();
172  for (int i=0; i<recs; i++)
173  L->push_back(((muon->bestTrackRef().get())->recHit(i).get())->geographicalId().rawId());
174  }
175  else
176  std::cout << "ERROR: Muon has no bestTrackRef!!\n";
177 
178  std::cout << " with " << L->size() << " muon hits found\n";
179 // return L;
180 }
181 
182 
183 template < typename T > void SelectReplacementCandidates::ProductNotFound(const edm::Event& iEvent, edm::InputTag inputTag)
184 {
185  std::cout << "--- TauHitSelector ------------------------------------\n";
186  std::cout << "Could not find product with:\n"<< inputTag << "\n";
187  std::vector< edm::Handle< T > > allHandles;
188  iEvent.getManyByType(allHandles);
189  typename std::vector< edm::Handle< T > >::iterator it;
190  for (it = allHandles.begin(); it != allHandles.end(); it++)
191  {
192  std::cout << "module label: " << (*it).provenance()->moduleLabel() << "\n";
193  std::cout << "productInstanceName: " << (*it).provenance()->productInstanceName() << "\n";
194  std::cout << "processName: " << (*it).provenance()->processName() << "\n\n";
195  }
196  std::cout << "-------------------------------------------------------\n";
197  return;
198 }
199 
200 
203 {
204  using namespace edm;
205  using namespace reco;
206  using namespace std;
207 
208  reco::Particle::LorentzVector muon1_momentum = muon1->p4();
209  reco::Particle::LorentzVector muon2_momentum = muon2->p4();
210  reco::Particle::LorentzVector z_momentum = muon1_momentum + muon2_momentum;
211 
212  ROOT::Math::Boost booster(z_momentum.BoostToCM());
213  ROOT::Math::Boost invbooster(booster.Inverse());
214 
215  reco::Particle::LorentzVector Zb = booster(z_momentum);
216 
217  reco::Particle::LorentzVector muon1b = booster(muon1_momentum);
218  reco::Particle::LorentzVector muon2b = booster(muon2_momentum);
219 
220  double tau_mass2 = targetParticleMass_*targetParticleMass_;
221 
222  double muonxb_mom2 = muon1b.x()*muon1b.x() + muon1b.y()*muon1b.y() + muon1b.z() * muon1b.z();
223  double tauxb_mom2 = 0.25 * Zb.t() * Zb.t() - tau_mass2;
224 
225  float scaling1 = sqrt(tauxb_mom2 / muonxb_mom2);
226  float scaling2 = scaling1;
227 
228  float tauEnergy= Zb.t() / 2.;
229 
230  if (tauEnergy*tauEnergy<tau_mass2)
231  return;
232 
233  reco::Particle::LorentzVector tau1b_mom = reco::Particle::LorentzVector(scaling1*muon1b.x(),scaling1*muon1b.y(),scaling1*muon1b.z(),tauEnergy);
234  reco::Particle::LorentzVector tau2b_mom = reco::Particle::LorentzVector(scaling2*muon2b.x(),scaling2*muon2b.y(),scaling2*muon2b.z(),tauEnergy);
235 
236  // some checks
237  // the following test guarantees a deviation
238  // of less than 0.1% for phi and theta for the
239  // original muons and the placed taus
240  // (in the centre-of-mass system of the z boson)
241  assert((muon1b.phi()-tau1b_mom.phi())/muon1b.phi()<0.001);
242  assert((muon2b.phi()-tau2b_mom.phi())/muon2b.phi()<0.001);
243  assert((muon1b.theta()-tau1b_mom.theta())/muon1b.theta()<0.001);
244  assert((muon2b.theta()-tau2b_mom.theta())/muon2b.theta()<0.001);
245 
246  reco::Particle::LorentzVector tau1_mom = (invbooster(tau1b_mom));
247  reco::Particle::LorentzVector tau2_mom = (invbooster(tau2b_mom));
248 
249  // some additional checks
250  // the following tests guarantee a deviation of less
251  // than 0.1% for the following values of the original
252  // muons and the placed taus
253  // invariant mass
254  // transverse momentum
255  assert(((muon1_momentum+muon1_momentum).mass()-(tau1_mom+tau2_mom).mass())/(muon1_momentum+muon1_momentum).mass()<0.001);
256  assert(((muon1_momentum+muon2_momentum).pt()-(tau1_mom+tau2_mom).pt())/(muon1_momentum+muon1_momentum).pt()<0.001);
257 
258  muon1->setP4(tau1_mom);
259  muon2->setP4(tau2_mom);
260 
261  muon1->setPdgId(targetParticlePdgID_*muon1->pdgId()/abs(muon1->pdgId()));
262  muon2->setPdgId(targetParticlePdgID_*muon2->pdgId()/abs(muon2->pdgId()));
263 
264  muon1->setStatus(1);
265  muon2->setStatus(1);
266 
267  return;
268 }
269 
271 
273 
void getManyByType(std::vector< Handle< PROD > > &results) const
Definition: Event.h:408
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
virtual int pdgId() const
PDG identifier.
dictionary parameters
Definition: Parameters.py:2
TrackDetectorAssociator trackAssociator_
virtual void setStatus(int status)
set status word
void ProductNotFound(const edm::Event &iEvent, edm::InputTag inputTag)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< const EcalRecHit * > ecalRecHits
hits in the cone
void useDefaultPropagator()
use the default propagator
#define abs(x)
Definition: mlp_lapack.h:159
virtual void setP4(const LorentzVector &p4)
set 4-momentum
double double double z
SelectReplacementCandidates(const edm::ParameterSet &iSetup)
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
T sqrt(T t)
Definition: SSEVec.h:46
double p4[4]
Definition: TauolaWrapper.h:92
std::vector< const HBHERecHit * > hcalRecHits
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
int determineMuonsToUse(const edm::Event &iEvent, const edm::EventSetup &iConfig, reco::Muon *muon1, reco::Muon *muon2)
size_type size() const
void getRawIDsAdvanced(const edm::Event &iEvent, const edm::EventSetup &iConfig, std::vector< uint32_t > *L, reco::Muon *muon, bool includeHCAL)
void transformMuMu2TauTau(reco::Muon *muon1, reco::Muon *muon2)
transform muon into tau
tuple muons
Definition: patZpeak.py:38
tuple mass
Definition: scaleCards.py:27
virtual void setPdgId(int pdgId)
TrackDetMatchInfo associate(const edm::Event &, const edm::EventSetup &, const FreeTrajectoryState &, const AssociatorParameters &)
tuple cout
Definition: gather_cfg.py:121
TrackAssociatorParameters parameters_
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iConfig)
bool isNonnull() const
Checks for non-null.
Definition: RefToBase.h:279
virtual const LorentzVector & p4() const
four-momentum Lorentz vector
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:25
value_type const * get() const
Definition: RefToBase.h:212
int determineMuonsToUse_old(const edm::Event &iEvent, const edm::EventSetup &iConfig, reco::Muon *muon1, reco::Muon *muon2)
virtual TrackBaseRef bestTrackRef() const
best track RefToBase
Definition: Muon.h:63
void loadParameters(const edm::ParameterSet &)