CMS 3D CMS Logo

AlignmentTwoBoyDecayTrackSelector.cc
Go to the documentation of this file.
1 //Framework
3 
7 
8 //DataFormats
12 
13 //STL
14 #include <cmath>
15 //ROOT
16 #include "TLorentzVector.h"
17 
19 //TODO put those namespaces into functions?
20 using namespace std;
21 using namespace edm;
22 // constructor ----------------------------------------------------------------
23 
25 {
26  LogDebug("Alignment") << "> applying two body decay Trackfilter ...";
27  theMassrangeSwitch = cfg.getParameter<bool>( "applyMassrangeFilter" );
28  if (theMassrangeSwitch){
29  theMinMass = cfg.getParameter<double>( "minXMass" );
30  theMaxMass = cfg.getParameter<double>( "maxXMass" );
31  theDaughterMass = cfg.getParameter<double>( "daughterMass" );
32  theCandNumber = cfg.getParameter<unsigned int>( "numberOfCandidates" );//Number of candidates to keep
33  secThrBool = cfg.getParameter<bool> ( "applySecThreshold" );
34  thesecThr = cfg.getParameter<double>( "secondThreshold" );
35  LogDebug("Alignment") << "> Massrange min,max : " << theMinMass << "," << theMaxMass
36  << "\n> Mass of daughter Particle : " << theDaughterMass;
37 
38  }else{
39  theMinMass = 0;
40  theMaxMass = 0;
41  theDaughterMass = 0;
42  }
43  theChargeSwitch = cfg.getParameter<bool>( "applyChargeFilter" );
44  if(theChargeSwitch){
45  theCharge = cfg.getParameter<int>( "charge" );
46  theUnsignedSwitch = cfg.getParameter<bool>( "useUnsignedCharge" );
47  if(theUnsignedSwitch)
49  LogDebug("Alignment") << "> Desired Charge, unsigned: "<<theCharge<<" , "<<theUnsignedSwitch;
50  }else{
51  theCharge =0;
52  theUnsignedSwitch = true;
53  }
54  theMissingETSwitch = cfg.getParameter<bool>( "applyMissingETFilter" );
55  if(theMissingETSwitch){
56  edm::InputTag theMissingETSource = cfg.getParameter<InputTag>( "missingETSource" );
57  theMissingETToken = iC.consumes<reco::CaloMETCollection>(theMissingETSource);
58  LogDebug("Alignment") << "> missing Et Source: "<< theMissingETSource;
59  }
60  theAcoplanarityFilterSwitch = cfg.getParameter<bool>( "applyAcoplanarityFilter" );
61  if(theAcoplanarityFilterSwitch){
62  theAcoplanarDistance = cfg.getParameter<double>( "acoplanarDistance" );
63  LogDebug("Alignment") << "> Acoplanar Distance: "<<theAcoplanarDistance;
64  }
65 
66 }
67 
68 // destructor -----------------------------------------------------------------
69 
71 {}
72 
73 
76 {
77  return theMassrangeSwitch || theChargeSwitch || theAcoplanarityFilterSwitch;
78 }
79 
80 // do selection ---------------------------------------------------------------
81 
84 {
86 
87  if (theMassrangeSwitch) {
88  if (theMissingETSwitch)
89  result = checkMETMass(result,iEvent);
90  else
91  result = checkMass(result);
92  }
93 
94  LogDebug("Alignment") << "> TwoBodyDecay tracks all,kept: " << tracks.size() << "," << result.size();
95  return result;
96 }
97 
98 template<class T>
99 struct higherTwoBodyDecayPt : public std::binary_function<T,T,bool>
100 {
101  bool operator()( const T& a, const T& b )
102  {
103  return a.first > b.first ;
104  }
105 };
106 
110 {
111  Tracks result;
112 
113  LogDebug("Alignment") <<"> cands size : "<< cands.size();
114 
115  if (cands.size()<2) return result;
116 
117  TLorentzVector track0;
118  TLorentzVector track1;
119  TLorentzVector mother;
120  typedef pair<const reco::Track*,const reco::Track*> constTrackPair;
121  typedef pair<double,constTrackPair> candCollectionItem;
122  vector<candCollectionItem> candCollection;
123 
124  for (unsigned int iCand = 0; iCand < cands.size(); iCand++) {
125 
126  track0.SetXYZT(cands.at(iCand)->px(),
127  cands.at(iCand)->py(),
128  cands.at(iCand)->pz(),
129  sqrt( cands.at(iCand)->p()*cands.at(iCand)->p() + theDaughterMass*theDaughterMass ));
130 
131  for (unsigned int jCand = iCand+1; jCand < cands.size(); jCand++) {
132 
133  track1.SetXYZT(cands.at(jCand)->px(),
134  cands.at(jCand)->py(),
135  cands.at(jCand)->pz(),
136  sqrt( cands.at(jCand)->p()*cands.at(jCand)->p() + theDaughterMass*theDaughterMass ));
137  if (secThrBool==true && track1.Pt() < thesecThr && track0.Pt()< thesecThr) continue;
138  mother = track0 + track1;
139 
140  const reco::Track *trk1 = cands.at(iCand);
141  const reco::Track *trk2 = cands.at(jCand);
142 
143  bool correctCharge = true;
144  if (theChargeSwitch) correctCharge = this->checkCharge(trk1, trk2);
145 
146  bool acoplanarTracks = true;
147  if (theAcoplanarityFilterSwitch) acoplanarTracks = this->checkAcoplanarity(trk1, trk2);
148 
149  if (mother.M() > theMinMass &&
150  mother.M() < theMaxMass &&
151  correctCharge &&
152  acoplanarTracks) {
153  candCollection.push_back(candCollectionItem(mother.Pt(),
154  constTrackPair(trk1, trk2)));
155  }
156  }
157  }
158 
159  if (candCollection.empty()) return result;
160 
161  sort(candCollection.begin(), candCollection.end(),
163 
164  std::map<const reco::Track*,unsigned int> uniqueTrackIndex;
165  std::map<const reco::Track*,unsigned int>::iterator it;
166  for (unsigned int i=0;
167  i<candCollection.size() && i<theCandNumber;
168  i++) {
169  constTrackPair & trackPair = candCollection[i].second;
170 
171  it = uniqueTrackIndex.find(trackPair.first);
172  if (it==uniqueTrackIndex.end()) {
173  result.push_back(trackPair.first);
174  uniqueTrackIndex[trackPair.first] = i;
175  }
176 
177  it = uniqueTrackIndex.find(trackPair.second);
178  if (it==uniqueTrackIndex.end()) {
179  result.push_back(trackPair.second);
180  uniqueTrackIndex[trackPair.second] = i;
181  }
182  }
183 
184  return result;
185 }
186 
190 {
191  Tracks result;
192 
193  LogDebug("Alignment") <<"> cands size : "<< cands.size();
194 
195  if (cands.empty()) return result;
196 
197  TLorentzVector track;
198  TLorentzVector met4;
199  TLorentzVector mother;
200 
202  iEvent.getByToken(theMissingETToken ,missingET);
203  if (!missingET.isValid()) {
204  LogError("Alignment")<< "@SUB=AlignmentTwoBodyDecayTrackSelector::checkMETMass"
205  << "> could not optain missingET Collection!";
206  return result;
207  }
208 
209  typedef pair<double,const reco::Track*> candCollectionItem;
210  vector<candCollectionItem> candCollection;
211 
212  for (reco::CaloMETCollection::const_iterator itMET = missingET->begin();
213  itMET != missingET->end();
214  ++itMET) {
215 
216  met4.SetXYZT((*itMET).px(),
217  (*itMET).py(),
218  (*itMET).pz(),
219  (*itMET).p());
220 
221  for (unsigned int iCand = 0; iCand < cands.size(); iCand++) {
222 
223  track.SetXYZT(cands.at(iCand)->px(),
224  cands.at(iCand)->py(),
225  cands.at(iCand)->pz(),
226  sqrt( cands.at(iCand)->p()*cands.at(iCand)->p() + theDaughterMass*theDaughterMass ));
227 
228  mother = track + met4;
229 
230  const reco::Track *trk = cands.at(iCand);
231  const reco::CaloMET *met = &(*itMET);
232 
233  bool correctCharge = true;
234  if (theChargeSwitch) correctCharge = this->checkCharge(trk);
235 
236  bool acoplanarTracks = true;
237  if (theAcoplanarityFilterSwitch) acoplanarTracks = this->checkMETAcoplanarity(trk, met);
238 
239  if (mother.M() > theMinMass &&
240  mother.M() < theMaxMass &&
241  correctCharge &&
242  acoplanarTracks) {
243  candCollection.push_back(candCollectionItem(mother.Pt(), trk));
244  }
245  }
246  }
247 
248  if (candCollection.empty()) return result;
249 
250  sort(candCollection.begin(), candCollection.end(),
252 
253  std::map<const reco::Track*,unsigned int> uniqueTrackIndex;
254  std::map<const reco::Track*,unsigned int>::iterator it;
255  for (unsigned int i=0;
256  i<candCollection.size() && i<theCandNumber;
257  i++) {
258  it = uniqueTrackIndex.find(candCollection[i].second);
259  if (it==uniqueTrackIndex.end()) {
260  result.push_back(candCollection[i].second);
261  uniqueTrackIndex[candCollection[i].second] = i;
262  }
263  }
264 
265  return result;
266 }
267 
269 bool
271 {
272  int sumCharge = trk1->charge();
273  if (trk2) sumCharge += trk2->charge();
274  if (theUnsignedSwitch) sumCharge = std::abs(sumCharge);
275  if (sumCharge == theCharge) return true;
276  return false;
277 }
278 
280 bool
282 {
283  if (fabs(deltaPhi(trk1->phi(),trk2->phi()-M_PI)) < theAcoplanarDistance) return true;
284  return false;
285 }
286 
288 bool
290 {
291  if (fabs(deltaPhi(trk1->phi(),met->phi()-M_PI)) < theAcoplanarDistance) return true;
292  return false;
293 }
294 
295 //===================HELPERS===================
296 
299 {
300  int count = 0;
301  LogDebug("Alignment") << ">......................................";
302  for(Tracks::const_iterator it = col.begin();it < col.end();++it,++count){
303  LogDebug("Alignment")
304  <<"> Track No. "<< count <<": p = ("<<(*it)->px()<<","<<(*it)->py()<<","<<(*it)->pz()<<")\n"
305  <<"> pT = "<<(*it)->pt()<<" eta = "<<(*it)->eta()<<" charge = "<<(*it)->charge();
306  }
307  LogDebug("Alignment") << ">......................................";
308 }
309 
310 
#define LogDebug(id)
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
AlignmentTwoBodyDecayTrackSelector(const edm::ParameterSet &cfg, edm::ConsumesCollector &iC)
constructor
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:645
bool checkMETAcoplanarity(const reco::Track *trk, const reco::CaloMET *met) const
checks if [cands] contains a acoplanar track w.r.t missing ET (returns empty set if not) ...
bool checkAcoplanarity(const reco::Track *trk1, const reco::Track *trk2) const
checks if the [cands] are acoplanar (returns empty set if not)
U second(std::pair< T, U > const &p)
int iEvent
Definition: GenABIO.cc:230
T sqrt(T t)
Definition: SSEVec.h:18
bool checkCharge(const reco::Track *trk1, const reco::Track *trk2=0) const
checks if the mother has charge = [theCharge]
bool useThisFilter()
returns if any of the Filters is used.
void printTracks(const Tracks &col) const
print Information on Track-Collection
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Tracks select(const Tracks &tracks, const edm::Event &iEvent, const edm::EventSetup &iSetup)
select tracks
bool isValid() const
Definition: HandleBase.h:74
#define M_PI
bool operator()(const T &a, const T &b)
std::vector< reco::CaloMET > CaloMETCollection
collection of CaloMET objects
met
===> hadronic RAZOR
double b
Definition: hdecay.h:120
HLT enums.
double a
Definition: hdecay.h:121
col
Definition: cuy.py:1009
int charge() const
track electric charge
Definition: TrackBase.h:567
long double T
double phi() const final
momentum azimuthal angle
Tracks checkMETMass(const Tracks &cands, const edm::Event &iEvent) const
checks if the mass of the mother is in the mass region adding missing E_T
Tracks checkMass(const Tracks &cands) const
checks if the mass of the mother is in the mass region