CMS 3D CMS Logo

ZToLLEdmNtupleDumper.cc
Go to the documentation of this file.
1 /* \class ZToLLEdmNtupleDumper
2  *
3  * \author Luca Lista, INFN
4  *
5  */
15 //#include "DataFormats/Common/interface/AssociationVector.h"
20 
27 
29 
30 #include <vector>
31 
32 using namespace edm;
33 using namespace std;
34 using namespace reco;
35 using namespace isodeposit;
36 //using namespace pat;
37 
39 public:
42 
43 private:
44  void produce( edm::Event &, const edm::EventSetup & ) override;
45  std::vector<std::string> zName_;
46  std::vector<edm::EDGetTokenT<CandidateView> > zTokens_;
47  std::vector<edm::EDGetTokenT<GenParticleMatch> > zGenParticlesMatchTokens_ ;
50 
51  std::vector<double> ptThreshold_, etEcalThreshold_, etHcalThreshold_ ,dRVetoTrk_, dRTrk_, dREcal_ , dRHcal_, alpha_, beta_;
52  std::vector<double> relativeIsolation_;
53  std::vector<string> hltPath_;
54  int counter;
55 
56 
57 };
58 
59 template<typename T>
60  double isolation(const T * t, double ptThreshold, double etEcalThreshold, double etHcalThreshold , double dRVetoTrk, double dRTrk, double dREcal , double dRHcal, double alpha, double beta, bool relativeIsolation) {
61  // on 34X:
62 const pat::IsoDeposit * trkIso = t->isoDeposit(pat::TrackIso);
63 // const pat::IsoDeposit * trkIso = t->trackerIsoDeposit();
64  // on 34X
65 const pat::IsoDeposit * ecalIso = t->isoDeposit(pat::EcalIso);
66 // const pat::IsoDeposit * ecalIso = t->ecalIsoDeposit();
67 // on 34X
68 const pat::IsoDeposit * hcalIso = t->isoDeposit(pat::HcalIso);
69 // const pat::IsoDeposit * hcalIso = t->hcalIsoDeposit();
70 
71  Direction dir = Direction(t->eta(), t->phi());
72 
74  vetosTrk.push_back(new ConeVeto( dir, dRVetoTrk ));
75  vetosTrk.push_back(new ThresholdVeto( ptThreshold ));
76 
77  pat::IsoDeposit::AbsVetos vetosEcal;
78  vetosEcal.push_back(new ConeVeto( dir, 0.));
79  vetosEcal.push_back(new ThresholdVeto( etEcalThreshold ));
80 
81  pat::IsoDeposit::AbsVetos vetosHcal;
82  vetosHcal.push_back(new ConeVeto( dir, 0. ));
83  vetosHcal.push_back(new ThresholdVeto( etHcalThreshold ));
84 
85  double isovalueTrk = (trkIso->sumWithin(dRTrk,vetosTrk));
86  double isovalueEcal = (ecalIso->sumWithin(dREcal,vetosEcal));
87  double isovalueHcal = (hcalIso->sumWithin(dRHcal,vetosHcal));
88 
89 
90  double iso = alpha*( ((1+beta)/2*isovalueEcal) + ((1-beta)/2*isovalueHcal) ) + ((1-alpha)*isovalueTrk) ;
91  if(relativeIsolation) iso /= t->pt();
92  return iso;
93  }
94 
95 
96 double candIsolation( const reco::Candidate* c, double ptThreshold, double etEcalThreshold, double etHcalThreshold , double dRVetoTrk, double dRTrk, double dREcal , double dRHcal, double alpha, double beta, bool relativeIsolation) {
97  const pat::Muon * mu = dynamic_cast<const pat::Muon *>(c);
98  if(mu != nullptr) return isolation(mu, ptThreshold, etEcalThreshold, etHcalThreshold ,dRVetoTrk, dRTrk, dREcal , dRHcal, alpha, beta, relativeIsolation);
99  const pat::GenericParticle * trk = dynamic_cast<const pat::GenericParticle*>(c);
100  if(trk != nullptr) return isolation(trk, ptThreshold, etEcalThreshold, etHcalThreshold ,dRVetoTrk, dRTrk, dREcal , dRHcal, alpha, beta, relativeIsolation);
102  << "Candidate daughter #0 is neither pat::Muons nor pat::GenericParticle\n";
103  return -1;
104  }
105 
106 
107 
109  string alias;
110  vector<ParameterSet> psets = cfg.getParameter<vector<ParameterSet> > ( "zBlocks" );
111  for( std::vector<edm::ParameterSet>::const_iterator i = psets.begin(); i != psets.end(); ++ i ) {
112  string zName = i->getParameter<string>( "zName" );
113  edm::EDGetTokenT<CandidateView> zToken = consumes<CandidateView>( i->getParameter<InputTag>( "z" ) );
114  edm::EDGetTokenT<GenParticleMatch> zGenParticlesMatchToken = consumes<GenParticleMatch>( i->getParameter<InputTag>( "zGenParticlesMatch" ) );
115  beamSpotToken_ = consumes<BeamSpot>( i->getParameter<InputTag>( "beamSpot" ) );
116  primaryVerticesToken_= consumes<VertexCollection>( i->getParameter<InputTag>( "primaryVertices" ) ) ;
117  double ptThreshold = i->getParameter<double>("ptThreshold");
118  double etEcalThreshold = i->getParameter<double>("etEcalThreshold");
119  double etHcalThreshold= i->getParameter<double>("etHcalThreshold");
120  double dRVetoTrk=i->getParameter<double>("deltaRVetoTrk");
121  double dRTrk=i->getParameter<double>("deltaRTrk");
122  double dREcal=i->getParameter<double>("deltaREcal");
123  double dRHcal=i->getParameter<double>("deltaRHcal");
124  double alpha=i->getParameter<double>("alpha");
125  double beta=i->getParameter<double>("beta");
126  bool relativeIsolation = i->getParameter<bool>("relativeIsolation");
127  string hltPath = i ->getParameter<std::string >("hltPath");
128  zName_.push_back( zName );
129  zTokens_.push_back( zToken );
130  zGenParticlesMatchTokens_.push_back( zGenParticlesMatchToken );
131  ptThreshold_.push_back( ptThreshold );
132  etEcalThreshold_.push_back(etEcalThreshold);
133  etHcalThreshold_.push_back(etHcalThreshold);
134  dRVetoTrk_.push_back(dRVetoTrk);
135  dRTrk_.push_back(dRTrk);
136  dREcal_.push_back(dREcal);
137  dRHcal_.push_back(dRHcal);
138  alpha_.push_back(alpha);
139  beta_.push_back(beta);
140  relativeIsolation_.push_back(relativeIsolation);
141  hltPath_.push_back(hltPath);
142  produces<vector<edm::EventNumber_t> >( alias = zName + "EventNumber" ).setBranchAlias( alias );
143  produces<vector<unsigned int> >( alias = zName + "RunNumber" ).setBranchAlias( alias );
144  produces<vector<unsigned int> >( alias = zName + "LumiBlock" ).setBranchAlias( alias );
145  produces<vector<float> >( alias = zName + "Mass" ).setBranchAlias( alias );
146  produces<vector<float> >( alias = zName + "MassSa" ).setBranchAlias( alias );
147  produces<vector<float> >( alias = zName + "Pt" ).setBranchAlias( alias );
148  produces<vector<float> >( alias = zName + "Eta" ).setBranchAlias( alias );
149  produces<vector<float> >( alias = zName + "Phi" ).setBranchAlias( alias );
150  produces<vector<float> >( alias = zName + "Y" ).setBranchAlias( alias );
151  produces<vector<float> >( alias = zName + "Dau1Pt" ).setBranchAlias( alias );
152  produces<vector<float> >( alias = zName + "Dau2Pt" ).setBranchAlias( alias );
153  produces<vector<float> >( alias = zName + "Dau1SaPt" ).setBranchAlias( alias );
154  produces<vector<float> >( alias = zName + "Dau2SaPt" ).setBranchAlias( alias );
155  produces<vector<unsigned int> >( alias = zName + "Dau1HLTBit" ).setBranchAlias( alias );
156  produces<vector<unsigned int> >( alias = zName + "Dau2HLTBit" ).setBranchAlias( alias );
157  produces<vector<int> >( alias = zName + "Dau1Q" ).setBranchAlias( alias );
158  produces<vector<int> >( alias = zName + "Dau2Q" ).setBranchAlias( alias );
159  produces<vector<float> >( alias = zName + "Dau1Eta" ).setBranchAlias( alias );
160  produces<vector<float> >( alias = zName + "Dau2Eta" ).setBranchAlias( alias );
161  produces<vector<float> >( alias = zName + "Dau1SaEta" ).setBranchAlias( alias );
162  produces<vector<float> >( alias = zName + "Dau2SaEta" ).setBranchAlias( alias );
163  produces<vector<float> >( alias = zName + "Dau1Phi" ).setBranchAlias( alias );
164  produces<vector<float> >( alias = zName + "Dau2Phi" ).setBranchAlias( alias );
165  produces<vector<float> >( alias = zName + "Dau1SaPhi" ).setBranchAlias( alias );
166  produces<vector<float> >( alias = zName + "Dau2SaPhi" ).setBranchAlias( alias );
167  produces<vector<float> >( alias = zName + "Dau1Iso" ).setBranchAlias( alias );
168  produces<vector<float> >( alias = zName + "Dau2Iso" ).setBranchAlias( alias );
169  produces<vector<float> >( alias = zName + "Dau1TrkIso" ).setBranchAlias( alias );
170  produces<vector<float> >( alias = zName + "Dau2TrkIso" ).setBranchAlias( alias );
171  produces<vector<float> >( alias = zName + "Dau1EcalIso" ).setBranchAlias( alias );
172  produces<vector<float> >( alias = zName + "Dau2EcalIso" ).setBranchAlias( alias );
173  produces<vector<float> >( alias = zName + "Dau1HcalIso" ).setBranchAlias( alias );
174  produces<vector<float> >( alias = zName + "Dau2HcalIso" ).setBranchAlias( alias );
175  produces<vector<float> >( alias = zName + "Dau1MuEnergyEm" ).setBranchAlias( alias );
176  produces<vector<float> >( alias = zName + "Dau1MuEnergyHad" ).setBranchAlias( alias );
177  produces<vector<float> >( alias = zName + "Dau2MuEnergyEm" ).setBranchAlias( alias );
178  produces<vector<float> >( alias = zName + "Dau2MuEnergyHad" ).setBranchAlias( alias );
179 
180  produces<vector<float> >( alias = zName + "VtxNormChi2" ).setBranchAlias( alias );
181  produces<vector<unsigned int> >( alias = zName + "Dau1NofHit" ).setBranchAlias( alias );
182  produces<vector<unsigned int> >( alias = zName + "Dau2NofHit" ).setBranchAlias( alias );
183  produces<vector<unsigned int> >( alias = zName + "Dau1NofHitTk" ).setBranchAlias( alias );
184  produces<vector<unsigned int> >( alias = zName + "Dau1NofHitSta" ).setBranchAlias( alias );
185  produces<vector<unsigned int> >( alias = zName + "Dau2NofHitTk" ).setBranchAlias( alias );
186  produces<vector<unsigned int> >( alias = zName + "Dau2NofHitSta" ).setBranchAlias( alias );
187  produces<vector<unsigned int> >( alias = zName + "Dau1NofMuChambers" ).setBranchAlias( alias );
188  produces<vector<unsigned int> >( alias = zName + "Dau2NofMuChambers" ).setBranchAlias( alias );
189  produces<vector<unsigned int> >( alias = zName + "Dau1NofMuMatches" ).setBranchAlias( alias );
190  produces<vector<unsigned int> >( alias = zName + "Dau2NofMuMatches" ).setBranchAlias( alias );
191  produces<vector<float> >( alias = zName + "Dau1Chi2" ).setBranchAlias( alias );
192  produces<vector<float> >( alias = zName + "Dau2Chi2" ).setBranchAlias( alias );
193  produces<vector<float> >( alias = zName + "Dau1TrkChi2" ).setBranchAlias( alias );
194  produces<vector<float> >( alias = zName + "Dau2TrkChi2" ).setBranchAlias( alias );
195  produces<vector<float> >( alias = zName + "Dau1dxyFromBS" ).setBranchAlias( alias );
196  produces<vector<float> >( alias = zName + "Dau2dxyFromBS" ).setBranchAlias( alias );
197  produces<vector<float> >( alias = zName + "Dau1dzFromBS" ).setBranchAlias( alias );
198  produces<vector<float> >( alias = zName + "Dau2dzFromBS" ).setBranchAlias( alias );
199  produces<vector<float> >( alias = zName + "Dau1dxyFromPV" ).setBranchAlias( alias );
200  produces<vector<float> >( alias = zName + "Dau2dxyFromPV" ).setBranchAlias( alias );
201  produces<vector<float> >( alias = zName + "Dau1dzFromPV" ).setBranchAlias( alias );
202  produces<vector<float> >( alias = zName + "Dau2dzFromPV" ).setBranchAlias( alias );
203  produces<vector<float> >( alias = zName + "TrueMass" ).setBranchAlias( alias );
204  produces<vector<float> >( alias = zName + "TruePt" ).setBranchAlias( alias );
205  produces<vector<float> >( alias = zName + "TrueEta" ).setBranchAlias( alias );
206  produces<vector<float> >( alias = zName + "TruePhi" ).setBranchAlias( alias );
207  produces<vector<float> >( alias = zName + "TrueY" ).setBranchAlias( alias );
208  }
209 }
210 
211 
212 
214  Handle<reco::BeamSpot> beamSpotHandle;
215  if (!evt.getByToken(beamSpotToken_, beamSpotHandle)) {
216  std::cout << ">>> No beam spot found !!!"<<std::endl;
217  }
218  Handle<reco::VertexCollection> primaryVertices; // Collection of primary Vertices
219  if (!evt.getByToken(primaryVerticesToken_, primaryVertices)){
220  std::cout << ">>> No primary verteces found !!!"<<std::endl;
221  }
222 
223  unsigned int size = zTokens_.size();
224  for( unsigned int c = 0; c < size; ++ c ) {
225  Handle<CandidateView> zColl;
226  evt.getByToken( zTokens_[c], zColl );
227  bool isMCMatchTrue = false;
228  //if (zGenParticlesMatchTokens_[c] != "") isMCMatchTrue = true;
229  Handle<GenParticleMatch> zGenParticlesMatch;
230  if (evt.getByToken( zGenParticlesMatchTokens_[c], zGenParticlesMatch )) {
231  isMCMatchTrue=true;
232  }
233  unsigned int zSize = zColl->size();
234  unique_ptr<vector<edm::EventNumber_t> > event( new vector<edm::EventNumber_t> );
235  unique_ptr<vector<unsigned int> > run( new vector<unsigned int> );
236  unique_ptr<vector<unsigned int> > lumi( new vector<unsigned int > );
237  unique_ptr<vector<float> > zMass( new vector<float> );
238  unique_ptr<vector<float> > zMassSa( new vector<float> );
239  unique_ptr<vector<float> > zPt( new vector<float> );
240  unique_ptr<vector<float> > zEta( new vector<float> );
241  unique_ptr<vector<float> > zPhi( new vector<float> );
242  unique_ptr<vector<float> > zY( new vector<float> );
243  unique_ptr<vector<float> > zDau1Pt( new vector<float> );
244  unique_ptr<vector<float> > zDau2Pt( new vector<float> );
245  unique_ptr<vector<float> > zDau1SaPt( new vector<float> );
246  unique_ptr<vector<float> > zDau2SaPt( new vector<float> );
247  unique_ptr<vector<unsigned int> > zDau1HLTBit( new vector<unsigned int> );
248  unique_ptr<vector<unsigned int> > zDau2HLTBit( new vector<unsigned int> );
249  unique_ptr<vector<int> > zDau1Q( new vector<int> );
250  unique_ptr<vector<int> > zDau2Q( new vector<int> );
251  unique_ptr<vector<float> > zDau1Eta( new vector<float> );
252  unique_ptr<vector<float> > zDau2Eta( new vector<float> );
253  unique_ptr<vector<float> > zDau1SaEta( new vector<float> );
254  unique_ptr<vector<float> > zDau2SaEta( new vector<float> );
255  unique_ptr<vector<float> > zDau1Phi( new vector<float> );
256  unique_ptr<vector<float> > zDau2Phi( new vector<float> );
257  unique_ptr<vector<float> > zDau1SaPhi( new vector<float> );
258  unique_ptr<vector<float> > zDau2SaPhi( new vector<float> );
259  unique_ptr<vector<float> > zDau1Iso( new vector<float> );
260  unique_ptr<vector<float> > zDau2Iso( new vector<float> );
261  unique_ptr<vector<float> > zDau1TrkIso( new vector<float> );
262  unique_ptr<vector<float> > zDau2TrkIso( new vector<float> );
263  unique_ptr<vector<float> > zDau1EcalIso( new vector<float> );
264  unique_ptr<vector<float> > zDau2EcalIso( new vector<float> );
265  unique_ptr<vector<float> > zDau1HcalIso( new vector<float> );
266  unique_ptr<vector<float> > zDau2HcalIso( new vector<float> );
267  unique_ptr<vector<float> > zDau1MuEnergyEm( new vector<float> );
268  unique_ptr<vector<float> > zDau2MuEnergyEm( new vector<float> );
269  unique_ptr<vector<float> > zDau1MuEnergyHad( new vector<float> );
270  unique_ptr<vector<float> > zDau2MuEnergyHad( new vector<float> );
271  unique_ptr<vector<float> > vtxNormChi2( new vector<float> );
272  unique_ptr<vector<unsigned int> > zDau1NofHit( new vector<unsigned int> );
273  unique_ptr<vector<unsigned int> > zDau2NofHit( new vector<unsigned int> );
274  unique_ptr<vector<unsigned int> > zDau1NofHitTk( new vector<unsigned int> );
275  unique_ptr<vector<unsigned int> > zDau2NofHitTk( new vector<unsigned int> );
276  unique_ptr<vector<unsigned int> > zDau1NofHitSta( new vector<unsigned int> );
277  unique_ptr<vector<unsigned int> > zDau2NofHitSta( new vector<unsigned int> );
278  unique_ptr<vector<unsigned int> > zDau1NofMuChambers( new vector<unsigned int> );
279  unique_ptr<vector<unsigned int> > zDau2NofMuChambers( new vector<unsigned int> );
280  unique_ptr<vector<unsigned int> > zDau1NofMuMatches( new vector<unsigned int> );
281  unique_ptr<vector<unsigned int> > zDau2NofMuMatches( new vector<unsigned int> );
282  unique_ptr<vector<float> > zDau1Chi2( new vector<float> );
283  unique_ptr<vector<float> > zDau2Chi2( new vector<float> );
284  unique_ptr<vector<float> > zDau1TrkChi2( new vector<float> );
285  unique_ptr<vector<float> > zDau2TrkChi2( new vector<float> );
286  unique_ptr<vector<float> > zDau1dxyFromBS( new vector<float> );
287  unique_ptr<vector<float> > zDau2dxyFromBS( new vector<float> );
288  unique_ptr<vector<float> > zDau1dzFromBS( new vector<float> );
289  unique_ptr<vector<float> > zDau2dzFromBS( new vector<float> );
290  unique_ptr<vector<float> > zDau1dxyFromPV( new vector<float> );
291  unique_ptr<vector<float> > zDau2dxyFromPV( new vector<float> );
292  unique_ptr<vector<float> > zDau1dzFromPV( new vector<float> );
293  unique_ptr<vector<float> > zDau2dzFromPV( new vector<float> );
294  unique_ptr<vector<float> > trueZMass( new vector<float> );
295  unique_ptr<vector<float> > trueZPt( new vector<float> );
296  unique_ptr<vector<float> > trueZEta( new vector<float> );
297  unique_ptr<vector<float> > trueZPhi( new vector<float> );
298  unique_ptr<vector<float> > trueZY( new vector<float> );
299  event -> push_back(evt.id().event());
300  run -> push_back(evt.id().run());
301  lumi -> push_back(evt.luminosityBlock());
302  for( unsigned int i = 0; i < zSize; ++ i ) {
303  const Candidate & z = (*zColl)[ i ];
304  CandidateBaseRef zRef = zColl->refAt(i);
305  zMass->push_back( z.mass() );
306  zPt->push_back( z.pt() );
307  zEta->push_back( z.eta() );
308  zPhi->push_back( z.phi() );
309  zY->push_back( z.rapidity() );
310  vtxNormChi2->push_back(z.vertexNormalizedChi2() );
311  const Candidate * dau1 = z.daughter(0);
312  const Candidate * dau2 = z.daughter(1);
313  zDau1Pt->push_back( dau1->pt() );
314  zDau2Pt->push_back( dau2->pt() );
315  zDau1Q->push_back( dau1->charge() );
316  zDau2Q->push_back( dau2->charge() );
317  zDau1Eta->push_back( dau1->eta() );
318  zDau2Eta->push_back( dau2->eta() );
319  zDau1Phi->push_back( dau1->phi() );
320  zDau2Phi->push_back( dau2->phi() );
321  if(!(dau1->hasMasterClone()&&dau2->hasMasterClone()))
323  << "Candidate daughters have no master clone\n";
324  const CandidateBaseRef & mr1 = dau1->masterClone(), & mr2 = dau2->masterClone();
325 
326  const Candidate * m1 = &*mr1, * m2 = &*mr2;
327 
328  // isolation as defined by us into the analyzer
329  double iso1 = candIsolation(m1,ptThreshold_[c], etEcalThreshold_[c], etHcalThreshold_[c] ,dRVetoTrk_[c], dRTrk_[c], dREcal_[c] , dRHcal_[c], alpha_[c], beta_[c], relativeIsolation_[c]);
330  double iso2 = candIsolation(m2,ptThreshold_[c], etEcalThreshold_[c], etHcalThreshold_[c] ,dRVetoTrk_[c], dRTrk_[c], dREcal_[c] , dRHcal_[c], alpha_[c], beta_[c], relativeIsolation_[c] );
331  // tracker isolation : alpha =0
332  double trkIso1 = candIsolation(m1,ptThreshold_[c], etEcalThreshold_[c], etHcalThreshold_[c] ,dRVetoTrk_[c], dRTrk_[c], dREcal_[c] , dRHcal_[c], 0.0, beta_[c], relativeIsolation_[c]);
333  double trkIso2 = candIsolation(m2,ptThreshold_[c], etEcalThreshold_[c], etHcalThreshold_[c] ,dRVetoTrk_[c], dRTrk_[c], dREcal_[c] , dRHcal_[c], 0.0, beta_[c], relativeIsolation_[c] );
334  // ecal isolation : alpha =1, beta =1
335  double ecalIso1 = candIsolation(m1,ptThreshold_[c], etEcalThreshold_[c], etHcalThreshold_[c] ,dRVetoTrk_[c], dRTrk_[c], dREcal_[c] , dRHcal_[c], 1.0, 1.0, relativeIsolation_[c]);
336  double ecalIso2 = candIsolation(m2,ptThreshold_[c], etEcalThreshold_[c], etHcalThreshold_[c] ,dRVetoTrk_[c], dRTrk_[c], dREcal_[c] , dRHcal_[c], 1.0, 1.0, relativeIsolation_[c] );
337  // hcal isolation : alpha =1, beta =-1
338  double hcalIso1 = candIsolation(m1,ptThreshold_[c], etEcalThreshold_[c], etHcalThreshold_[c] ,dRVetoTrk_[c], dRTrk_[c], dREcal_[c] , dRHcal_[c], 1.0, -1.0, relativeIsolation_[c]);
339  double hcalIso2 = candIsolation(m2,ptThreshold_[c], etEcalThreshold_[c], etHcalThreshold_[c] ,dRVetoTrk_[c], dRTrk_[c], dREcal_[c] , dRHcal_[c], 1.0, -1.0, relativeIsolation_[c] );
340 
341  zDau1Iso->push_back( iso1 );
342  zDau2Iso->push_back( iso2 );
343  zDau1TrkIso->push_back( trkIso1 );
344  zDau2TrkIso->push_back( trkIso2 );
345  zDau1EcalIso->push_back( ecalIso1 );
346  zDau2EcalIso->push_back( ecalIso2 );
347  zDau1HcalIso->push_back( hcalIso1 );
348  zDau2HcalIso->push_back( hcalIso2 );
349  if (isMCMatchTrue){
350  GenParticleRef trueZRef = (*zGenParticlesMatch)[zRef];
351  //CandidateRef trueZRef = trueZIter->val;
352  if( trueZRef.isNonnull() ) {
353  const Candidate & z = * trueZRef;
354  trueZMass->push_back( z.mass() );
355  trueZPt->push_back( z.pt() );
356  trueZEta->push_back( z.eta() );
357  trueZPhi->push_back( z.phi() );
358  trueZY->push_back( z.rapidity() );
359  } else {
360  trueZMass->push_back( -100 );
361  trueZPt->push_back( -100 );
362  trueZEta->push_back( -100 );
363  trueZPhi->push_back( -100 );
364  trueZY->push_back( -100 );
365  }
366  }
367  // quality variables
368  const pat::Muon * mu1 = dynamic_cast<const pat::Muon*>(m1);
369  // protection for standalone and trackerMuon
370  if (mu1->isGlobalMuon() == true){
371  zDau1NofHit->push_back(mu1->numberOfValidHits());
372  zDau1NofHitTk->push_back(mu1->innerTrack()->numberOfValidHits());
373  zDau1NofHitSta->push_back(mu1->outerTrack()->numberOfValidHits());
374  zDau1Chi2->push_back(mu1->normChi2());
375  TrackRef mu1TrkRef = mu1->innerTrack();
376  zDau1TrkChi2->push_back( mu1TrkRef->normalizedChi2());
377  zDau1dxyFromBS->push_back(mu1TrkRef->dxy(beamSpotHandle->position()));
378  zDau1dzFromBS->push_back(mu1TrkRef->dz(beamSpotHandle->position()));
379  zDau1dxyFromPV->push_back(mu1TrkRef->dxy(primaryVertices->begin()->position() ));
380  zDau1dzFromPV->push_back(mu1TrkRef->dz(primaryVertices->begin()->position() ));
381  zDau1MuEnergyEm->push_back( mu1->calEnergy().em);
382  zDau1MuEnergyHad->push_back( mu1->calEnergy().had);
383 
384  } else if (mu1->isStandAloneMuon() == true) {
385  // the muon is a standalone
386  TrackRef mu1StaRef = mu1->outerTrack();
387  zDau1NofHit->push_back(mu1StaRef->numberOfValidHits());
388  zDau1NofHitTk->push_back(0);
389  zDau1NofHitSta->push_back(mu1StaRef->numberOfValidHits());
390  zDau1Chi2->push_back(mu1StaRef->normalizedChi2());
391  zDau1TrkChi2->push_back(0);
392  zDau1dxyFromBS->push_back(mu1StaRef->dxy(beamSpotHandle->position()));
393  zDau1dzFromBS->push_back(mu1StaRef->dz(beamSpotHandle->position()));
394  zDau1dxyFromPV->push_back(mu1StaRef->dxy(primaryVertices->begin()->position() ));
395  zDau1dzFromPV->push_back(mu1StaRef->dz(primaryVertices->begin()->position() ));
396  zDau1MuEnergyEm->push_back( -1);
397  zDau1MuEnergyHad->push_back( -1);
398  } else if (mu1->isTrackerMuon() == true) {
399  // the muon is a trackerMuon
400  TrackRef mu1TrkRef = mu1->innerTrack();
401  zDau1NofHit->push_back(mu1TrkRef->numberOfValidHits());
402  zDau1NofHitTk->push_back(mu1TrkRef->numberOfValidHits());
403  zDau1NofHitSta->push_back(0);
404  zDau1Chi2->push_back(mu1TrkRef->normalizedChi2());
405  zDau1TrkChi2->push_back(mu1TrkRef->normalizedChi2());
406  zDau1dxyFromBS->push_back(mu1TrkRef->dxy(beamSpotHandle->position()));
407  zDau1dzFromBS->push_back(mu1TrkRef->dz(beamSpotHandle->position()));
408  zDau1dxyFromPV->push_back(mu1TrkRef->dxy(primaryVertices->begin()->position() ));
409  zDau1dzFromPV->push_back(mu1TrkRef->dz(primaryVertices->begin()->position() ));
410  zDau1MuEnergyEm->push_back( mu1->calEnergy().em);
411  zDau1MuEnergyHad->push_back( mu1->calEnergy().had);
412  }
413  zDau1NofMuChambers->push_back(mu1->numberOfChambers());
414  zDau1NofMuMatches->push_back(mu1->numberOfMatches());
415 
416  // would we like to add another variables???
417  // HLT trigger bit
418  const pat::TriggerObjectStandAloneCollection mu1HLTMatches = mu1->triggerObjectMatchesByPath( hltPath_[c] );
419 
420  int dimTrig1 = mu1HLTMatches.size();
421  if(dimTrig1 !=0 ){
422  zDau1HLTBit->push_back(1);
423  } else {
424  zDau1HLTBit->push_back(0);
425  }
426  const pat::Muon * mu2 = dynamic_cast<const pat::Muon*>(m2);
427  if (mu2!=nullptr ) {
428  if (mu2->isGlobalMuon() == true) {
429  zDau2NofHit->push_back(mu2->numberOfValidHits());
430  zDau2NofHitTk->push_back(mu2->innerTrack()->numberOfValidHits());
431  zDau2NofHitSta->push_back(mu2->outerTrack()->numberOfValidHits());
432  zDau2Chi2->push_back(mu2->normChi2());
433  TrackRef mu2TrkRef = mu2->innerTrack();
434  zDau1TrkChi2->push_back( mu2TrkRef->normalizedChi2());
435  zDau2dxyFromBS->push_back(mu2TrkRef->dxy(beamSpotHandle->position()));
436  zDau2dzFromBS->push_back(mu2TrkRef->dz(beamSpotHandle->position()));
437  zDau2dxyFromPV->push_back(mu2TrkRef->dxy(primaryVertices->begin()->position() ));
438  zDau2dzFromPV->push_back(mu2TrkRef->dz(primaryVertices->begin()->position() ));
439  zDau2MuEnergyEm->push_back( mu2->calEnergy().em);
440  zDau2MuEnergyHad->push_back( mu2->calEnergy().had);
441  } else if (mu2->isStandAloneMuon() == true){
442  // its' a standalone
443  zDau2HLTBit->push_back(0);
444  TrackRef mu2StaRef = mu2->outerTrack();
445  zDau2NofHit->push_back(mu2StaRef->numberOfValidHits());
446  zDau2NofHitTk->push_back(0);
447  zDau2NofHitSta->push_back(mu2StaRef->numberOfValidHits());
448  zDau2Chi2->push_back(mu2StaRef->normalizedChi2());
449  zDau2TrkChi2->push_back(0);
450  zDau2dxyFromBS->push_back(mu2StaRef->dxy(beamSpotHandle->position()));
451  zDau2dzFromBS->push_back(mu2StaRef->dz(beamSpotHandle->position()));
452  zDau2dxyFromPV->push_back(mu2StaRef->dxy(primaryVertices->begin()->position() ));
453  zDau2dzFromPV->push_back(mu2StaRef->dz(primaryVertices->begin()->position() ));
454  zDau1MuEnergyEm->push_back( -1);
455  zDau1MuEnergyHad->push_back( -1);
456  } else if (mu2->isTrackerMuon() == true) {
457  // the muon is a trackerMuon
458  TrackRef mu2TrkRef = mu2->innerTrack();
459  zDau2NofHit->push_back(mu2TrkRef->numberOfValidHits());
460  zDau2NofHitSta->push_back(0);
461  zDau2NofHitTk->push_back(mu2TrkRef->numberOfValidHits());
462  zDau2Chi2->push_back(mu2TrkRef->normalizedChi2());
463  zDau2TrkChi2->push_back(mu2TrkRef->normalizedChi2());
464  zDau2dxyFromBS->push_back(mu2TrkRef->dxy(beamSpotHandle->position()));
465  zDau2dzFromBS->push_back(mu2TrkRef->dz(beamSpotHandle->position()));
466  zDau2dxyFromPV->push_back(mu2TrkRef->dxy(primaryVertices->begin()->position() ));
467  zDau2dzFromPV->push_back(mu2TrkRef->dz(primaryVertices->begin()->position() ));
468  zDau2MuEnergyEm->push_back( mu2->calEnergy().em);
469  zDau2MuEnergyHad->push_back( mu2->calEnergy().had);
470  }
471 
472  // HLT trigger bit
473  const pat::TriggerObjectStandAloneCollection mu2HLTMatches = mu2->triggerObjectMatchesByPath( hltPath_[c] );
474  int dimTrig2 = mu2HLTMatches.size();
475  if(dimTrig2 !=0 ){
476  zDau2HLTBit->push_back(1);
477  }
478  else {
479  zDau2HLTBit->push_back(0);
480  }
482  if ( mu1->isGlobalMuon() && mu2->isGlobalMuon() ) {
483  TrackRef stAloneTrack1;
484  TrackRef stAloneTrack2;
485  Vector momentum;
487  double mu_mass;
488  stAloneTrack1 = dau1->get<TrackRef,reco::StandAloneMuonTag>();
489  stAloneTrack2 = dau2->get<TrackRef,reco::StandAloneMuonTag>();
490  zDau1SaEta->push_back(stAloneTrack1->eta());
491  zDau2SaEta->push_back(stAloneTrack2->eta());
492  zDau1SaPhi->push_back(stAloneTrack1->phi());
493  zDau2SaPhi->push_back(stAloneTrack2->phi());
494  if(counter % 2 == 0) {
495  momentum = stAloneTrack1->momentum();
496  p4_1 = dau2->polarP4();
497  mu_mass = dau1->mass();
499  zDau1SaPt->push_back(stAloneTrack1 ->pt());
500  zDau2SaPt->push_back(- stAloneTrack2->pt());
501  }else{
502  momentum = stAloneTrack2->momentum();
503  p4_1= dau1->polarP4();
504  mu_mass = dau2->mass();
506  zDau1SaPt->push_back( - stAloneTrack1->pt());
507  zDau2SaPt->push_back( stAloneTrack2->pt());
508  }
509 
510  Candidate::PolarLorentzVector p4_2(momentum.rho(), momentum.eta(),momentum.phi(), mu_mass);
511  double mass = (p4_1+p4_2).mass();
512  zMassSa->push_back(mass);
513  ++counter;
514  }
515 
516 
517  zDau2NofMuChambers->push_back(mu2->numberOfChambers());
518  zDau2NofMuMatches->push_back(mu2->numberOfMatches());
519  } else{
520  // for ZMuTk case...
521  // it's a track......
522  const pat::GenericParticle * trk2 = dynamic_cast<const pat::GenericParticle*>(m2);
523  TrackRef mu2TrkRef = trk2->track();
524  zDau2NofHit->push_back(mu2TrkRef->numberOfValidHits());
525  zDau2NofHitTk->push_back( mu2TrkRef->numberOfValidHits());
526  zDau2NofHitSta->push_back( 0);
527  zDau2NofMuChambers->push_back(0);
528  zDau2NofMuMatches->push_back(0);
529  zDau2Chi2->push_back(mu2TrkRef->normalizedChi2());
530  zDau2dxyFromBS->push_back(mu2TrkRef->dxy(beamSpotHandle->position()));
531  zDau2dzFromBS->push_back(mu2TrkRef->dz(beamSpotHandle->position()));
532  zDau2dxyFromPV->push_back(mu2TrkRef->dxy(primaryVertices->begin()->position() ));
533  zDau2dzFromPV->push_back(mu2TrkRef->dz(primaryVertices->begin()->position() ));
534  zDau1MuEnergyEm->push_back( -1);
535  zDau1MuEnergyHad->push_back( -1);
536  }
537  }
538  const string & zName = zName_[c];
539  evt.put(std::move(event),zName + "EventNumber" );
540  evt.put(std::move(run), zName + "RunNumber" );
541  evt.put(std::move(lumi),zName + "LumiBlock" );
542  evt.put(std::move(zMass), zName + "Mass" );
543  evt.put(std::move(zMassSa), zName + "MassSa" );
544  evt.put(std::move(zPt), zName + "Pt" );
545  evt.put(std::move(zEta), zName + "Eta" );
546  evt.put(std::move(zPhi), zName + "Phi" );
547  evt.put(std::move(zY), zName + "Y" );
548  evt.put(std::move(zDau1Pt), zName + "Dau1Pt" );
549  evt.put(std::move(zDau2Pt), zName + "Dau2Pt" );
550  evt.put(std::move(zDau1SaPt), zName + "Dau1SaPt" );
551  evt.put(std::move(zDau2SaPt), zName + "Dau2SaPt" );
552  evt.put(std::move(zDau1HLTBit), zName + "Dau1HLTBit" );
553  evt.put(std::move(zDau2HLTBit), zName + "Dau2HLTBit" );
554  evt.put(std::move(zDau1Q), zName + "Dau1Q" );
555  evt.put(std::move(zDau2Q), zName + "Dau2Q" );
556  evt.put(std::move(zDau1Eta), zName + "Dau1Eta" );
557  evt.put(std::move(zDau2Eta), zName + "Dau2Eta" );
558  evt.put(std::move(zDau1SaEta), zName + "Dau1SaEta" );
559  evt.put(std::move(zDau2SaEta), zName + "Dau2SaEta" );
560  evt.put(std::move(zDau1Phi), zName + "Dau1Phi" );
561  evt.put(std::move(zDau2Phi), zName + "Dau2Phi" );
562  evt.put(std::move(zDau1SaPhi), zName + "Dau1SaPhi" );
563  evt.put(std::move(zDau2SaPhi), zName + "Dau2SaPhi" );
564  evt.put(std::move(zDau1Iso), zName + "Dau1Iso" );
565  evt.put(std::move(zDau2Iso), zName + "Dau2Iso" );
566  evt.put(std::move(zDau1TrkIso), zName + "Dau1TrkIso" );
567  evt.put(std::move(zDau2TrkIso), zName + "Dau2TrkIso" );
568  evt.put(std::move(zDau1EcalIso), zName + "Dau1EcalIso" );
569  evt.put(std::move(zDau2EcalIso), zName + "Dau2EcalIso" );
570  evt.put(std::move(zDau1HcalIso), zName + "Dau1HcalIso" );
571  evt.put(std::move(zDau2HcalIso), zName + "Dau2HcalIso" );
572  evt.put(std::move(zDau1MuEnergyEm), zName + "Dau1MuEnergyEm" );
573  evt.put(std::move(zDau2MuEnergyEm), zName + "Dau2MuEnergyEm" );
574  evt.put(std::move(zDau1MuEnergyHad), zName + "Dau1MuEnergyHad" );
575  evt.put(std::move(zDau2MuEnergyHad), zName + "Dau2MuEnergyHad" );
576  evt.put(std::move(vtxNormChi2), zName + "VtxNormChi2" );
577  evt.put(std::move(zDau1NofHit), zName + "Dau1NofHit" );
578  evt.put(std::move(zDau2NofHit), zName + "Dau2NofHit" );
579  evt.put(std::move(zDau1NofHitTk), zName + "Dau1NofHitTk" );
580  evt.put(std::move(zDau2NofHitTk), zName + "Dau2NofHitTk" );
581  evt.put(std::move(zDau1NofHitSta), zName + "Dau1NofHitSta" );
582  evt.put(std::move(zDau2NofHitSta), zName + "Dau2NofHitSta" );
583  evt.put(std::move(zDau1NofMuChambers), zName + "Dau1NofMuChambers" );
584  evt.put(std::move(zDau1NofMuMatches), zName + "Dau1NofMuMatches" );
585  evt.put(std::move(zDau2NofMuChambers), zName + "Dau2NofMuChambers" );
586  evt.put(std::move(zDau2NofMuMatches), zName + "Dau2NofMuMatches" );
587  evt.put(std::move(zDau1Chi2), zName + "Dau1Chi2" );
588  evt.put(std::move(zDau2Chi2), zName + "Dau2Chi2" );
589  evt.put(std::move(zDau1TrkChi2), zName + "Dau1TrkChi2" );
590  evt.put(std::move(zDau2TrkChi2), zName + "Dau2TrkChi2" );
591  evt.put(std::move(zDau1dxyFromBS), zName + "Dau1dxyFromBS" );
592  evt.put(std::move(zDau2dxyFromBS), zName + "Dau2dxyFromBS" );
593  evt.put(std::move(zDau1dxyFromPV), zName + "Dau1dxyFromPV" );
594  evt.put(std::move(zDau2dxyFromPV), zName + "Dau2dxyFromPV" );
595  evt.put(std::move(zDau1dzFromBS), zName + "Dau1dzFromBS" );
596  evt.put(std::move(zDau2dzFromBS), zName + "Dau2dzFromBS" );
597  evt.put(std::move(zDau1dzFromPV), zName + "Dau1dzFromPV" );
598  evt.put(std::move(zDau2dzFromPV), zName + "Dau2dzFromPV" );
599  evt.put(std::move(trueZMass), zName + "TrueMass" );
600  evt.put(std::move(trueZPt), zName + "TruePt" );
601  evt.put(std::move(trueZEta), zName + "TrueEta" );
602  evt.put(std::move(trueZPhi), zName + "TruePhi" );
603  evt.put(std::move(trueZY), zName + "TrueY" );
604 }
605 }
606 
608 
610 
RunNumber_t run() const
Definition: EventID.h:39
size
Write out results.
std::vector< std::string > zName_
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
float alpha
Definition: AMPTWrapper.h:95
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:251
bool isStandAloneMuon() const override
Definition: Muon.h:293
edm::EDGetTokenT< VertexCollection > primaryVerticesToken_
virtual const PolarLorentzVector & polarP4() const =0
four-momentum Lorentz vector
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
edm::EDGetTokenT< BeamSpot > beamSpotToken_
std::vector< double > ptThreshold_
virtual const Candidate * daughter(size_type i) const =0
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
void produce(edm::Event &, const edm::EventSetup &) override
stand alone muon component tag
Definition: RecoCandidate.h:78
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:61
size_type size() const
std::vector< TriggerObjectStandAlone > TriggerObjectStandAloneCollection
Collection of TriggerObjectStandAlone.
double sumWithin(double coneSize, const AbsVetos &vetos=AbsVetos(), bool skipDepositVeto=false) const
Definition: IsoDeposit.cc:138
bool isTrackerMuon() const override
Definition: Muon.h:292
RefToBase< value_type > refAt(size_type i) const
std::vector< edm::EDGetTokenT< GenParticleMatch > > zGenParticlesMatchTokens_
Analysis-level Generic Particle class (e.g. for hadron or muon not fully reconstructed) ...
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
reco::TrackRef innerTrack() const override
reference to Track reconstructed in the tracker only (reimplemented from reco::Muon) ...
Definition: Muon.h:72
reco::TrackRef outerTrack() const override
reference to Track reconstructed in the muon detector only (reimplemented from reco::Muon) ...
Definition: Muon.h:76
bool isGlobalMuon() const override
Definition: Muon.h:291
ZToLLEdmNtupleDumper(const edm::ParameterSet &)
virtual double vertexNormalizedChi2() const =0
chi-squared divided by n.d.o.f.
const int mu
Definition: Constants.h:22
const TriggerObjectStandAloneCollection triggerObjectMatchesByPath(const std::string &namePath, const bool pathLastFilterAccepted=false, const bool pathL3FilterAccepted=true) const
Definition: PATObject.h:612
double candIsolation(const reco::Candidate *c, double ptThreshold, double etEcalThreshold, double etHcalThreshold, double dRVetoTrk, double dRTrk, double dREcal, double dRHcal, double alpha, double beta, bool relativeIsolation)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
MuonEnergy calEnergy() const
get energy deposition information
Definition: Muon.h:111
std::vector< string > hltPath_
std::vector< double > relativeIsolation_
virtual const CandidateBaseRef & masterClone() const =0
virtual double eta() const =0
momentum pseudorapidity
primaryVertices
Definition: jets_cff.py:24
virtual double pt() const =0
transverse momentum
reco::TrackRef track() const override
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
int numberOfChambers() const
Definition: Muon.h:244
virtual double mass() const =0
mass
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:21
int numberOfMatches(ArbitrationType type=SegmentAndTrackArbitration) const
get number of chambers with matched segments
virtual double rapidity() const =0
rapidity
virtual int charge() const =0
electric charge
edm::EventID id() const
Definition: EventBase.h:59
fixed size matrix
HLT enums.
double isolation(const T *t, double ptThreshold, double etEcalThreshold, double etHcalThreshold, double dRVetoTrk, double dRTrk, double dREcal, double dRHcal, double alpha, double beta, bool relativeIsolation)
static std::atomic< unsigned int > counter
T get() const
get a component
Definition: Candidate.h:217
std::vector< edm::EDGetTokenT< CandidateView > > zTokens_
const Point & position() const
position
Definition: BeamSpot.h:62
dbl *** dir
Definition: mlp_gen.cc:35
unsigned int numberOfValidHits() const
numberOfValidHits returns the number of valid hits on the global track.
isodeposit::AbsVetos AbsVetos
Definition: IsoDeposit.h:51
long double T
double normChi2() const
Norm chi2 gives the normalized chi2 of the global track.
virtual double phi() const =0
momentum azimuthal angle
Analysis-level muon class.
Definition: Muon.h:51
def move(src, dest)
Definition: eostools.py:511
virtual bool hasMasterClone() const =0
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: Candidate.h:39