CMS 3D CMS Logo

DiMuonValidation.cc
Go to the documentation of this file.
1 // system includes
2 #include <memory>
3 #include <cmath>
4 #include <fmt/printf.h>
5 
6 // user include files
22 
23 // ROOT includes
24 #include "TH1D.h"
25 #include "TH2D.h"
26 #include "TH3D.h"
27 
28 namespace DiMuonValid {
30 }
31 //
32 // class declaration
33 //
34 class DiMuonValidation : public edm::one::EDAnalyzer<edm::one::SharedResources> {
35 public:
37  : eBeam_(pset.getParameter<double>("eBeam")),
38  compressionSettings_(pset.getUntrackedParameter<int>("compressionSettings", -1)),
39  TkTag_(pset.getParameter<std::string>("TkTag")),
40  pair_mass_min_(pset.getParameter<double>("Pair_mass_min")),
41  pair_mass_max_(pset.getParameter<double>("Pair_mass_max")),
42  pair_mass_nbins_(pset.getParameter<int>("Pair_mass_nbins")),
43  pair_etaminpos_(pset.getParameter<double>("Pair_etaminpos")),
44  pair_etamaxpos_(pset.getParameter<double>("Pair_etamaxpos")),
45  pair_etaminneg_(pset.getParameter<double>("Pair_etaminneg")),
46  pair_etamaxneg_(pset.getParameter<double>("Pair_etamaxneg")),
47  variable_CosThetaCS_xmin_(pset.getParameter<double>("Variable_CosThetaCS_xmin")),
48  variable_CosThetaCS_xmax_(pset.getParameter<double>("Variable_CosThetaCS_xmax")),
49  variable_CosThetaCS_nbins_(pset.getParameter<int>("Variable_CosThetaCS_nbins")),
50  variable_DeltaEta_xmin_(pset.getParameter<double>("Variable_DeltaEta_xmin")),
51  variable_DeltaEta_xmax_(pset.getParameter<double>("Variable_DeltaEta_xmax")),
52  variable_DeltaEta_nbins_(pset.getParameter<int>("Variable_DeltaEta_nbins")),
53  variable_EtaMinus_xmin_(pset.getParameter<double>("Variable_EtaMinus_xmin")),
54  variable_EtaMinus_xmax_(pset.getParameter<double>("Variable_EtaMinus_xmax")),
55  variable_EtaMinus_nbins_(pset.getParameter<int>("Variable_EtaMinus_nbins")),
56  variable_EtaPlus_xmin_(pset.getParameter<double>("Variable_EtaPlus_xmin")),
57  variable_EtaPlus_xmax_(pset.getParameter<double>("Variable_EtaPlus_xmax")),
58  variable_EtaPlus_nbins_(pset.getParameter<int>("Variable_EtaPlus_nbins")),
59  variable_PhiCS_xmin_(pset.getParameter<double>("Variable_PhiCS_xmin")),
60  variable_PhiCS_xmax_(pset.getParameter<double>("Variable_PhiCS_xmax")),
61  variable_PhiCS_nbins_(pset.getParameter<int>("Variable_PhiCS_nbins")),
62  variable_PhiMinus_xmin_(pset.getParameter<double>("Variable_PhiMinus_xmin")),
63  variable_PhiMinus_xmax_(pset.getParameter<double>("Variable_PhiMinus_xmax")),
64  variable_PhiMinus_nbins_(pset.getParameter<int>("Variable_PhiMinus_nbins")),
65  variable_PhiPlus_xmin_(pset.getParameter<double>("Variable_PhiPlus_xmin")),
66  variable_PhiPlus_xmax_(pset.getParameter<double>("Variable_PhiPlus_xmax")),
67  variable_PhiPlus_nbins_(pset.getParameter<int>("Variable_PhiPlus_nbins")),
68  variable_PairPt_xmin_(pset.getParameter<double>("Variable_PairPt_xmin")),
69  variable_PairPt_xmax_(pset.getParameter<double>("Variable_PairPt_xmax")),
70  variable_PairPt_nbins_(pset.getParameter<int>("Variable_PairPt_nbins")) {
71  usesResource(TFileService::kSharedResource);
72  theTrackCollectionToken_ = consumes<reco::TrackCollection>(TkTag_);
73 
82 
91 
100  }
101 
102  ~DiMuonValidation() override = default;
103 
104  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
105  static constexpr int varNumber_ = 8;
106  static constexpr double mu_mass2_ = 0.105658 * 0.105658; //The invariant mass of muon 105.658MeV
107 
108 private:
109  void beginJob() override;
110  void analyze(const edm::Event&, const edm::EventSetup&) override;
111 
112  // ----------member data ---------------------------
113  float eBeam_;
116 
124 
128 
132 
136 
140 
144 
148 
152 
156 
158  TH2D* th2d_mass_variables_[varNumber_]; // actual histograms
160  "CosThetaCS", "DeltaEta", "EtaMinus", "EtaPlus", "PhiCS", "PhiMinus", "PhiPlus", "Pt"};
161 
162  int variables_bins_number_[varNumber_]; // = {20, 20, 12, 12, 20, 16, 16, 100};
163  double variables_min_[varNumber_]; // = {-1, -4.8, -2.4, -2.4, -M_PI / 2, -M_PI, -M_PI, 0};
164  double variables_max_[varNumber_]; // = {+1, +4.8, +2.4, +2.4, +M_PI / 2, +M_PI, +M_PI, 100};
165 };
166 
167 //
168 // member functions
169 //
170 
171 // ------------ method called for each event ------------
173  using namespace edm;
174 
176 
177  DiMuonValid::LV LV_mother(0., 0., 0., 0.);
178  //for (reco::TrackCollection::const_iterator track1 = tC.begin(); track1 != tC.end(); track1++) {
179  for (const auto& track1 : tC) {
180  DiMuonValid::LV LV_track1(track1.px(),
181  track1.py(),
182  track1.pz(),
183  sqrt((track1.p() * track1.p()) + mu_mass2_)); //old 106
184 
185  for (const auto& track2 : tC) {
186  if (&track1 == &track2) {
187  continue;
188  } // discard the same track
189 
190  if (track1.charge() == track2.charge()) {
191  continue;
192  } // only reconstruct opposite charge pair
193 
194  DiMuonValid::LV LV_track2(track2.px(), track2.py(), track2.pz(), sqrt((track2.p() * track2.p()) + mu_mass2_));
195 
196  LV_mother = LV_track1 + LV_track2;
197  double mother_mass = LV_mother.M();
198  double mother_pt = LV_mother.Pt();
199 
200  int charge1 = track1.charge();
201  double etaMu1 = track1.eta();
202  double phiMu1 = track1.phi();
203  double ptMu1 = track1.pt();
204 
205  int charge2 = track2.charge();
206  double etaMu2 = track2.eta();
207  double phiMu2 = track2.phi();
208  double ptMu2 = track2.pt();
209 
210  if (charge1 < 0) { // use Mu+ for charge1, Mu- for charge2
211  std::swap(charge1, charge2);
212  std::swap(etaMu1, etaMu2);
213  std::swap(phiMu1, phiMu2);
214  std::swap(ptMu1, ptMu2);
215  }
216  //eta cut
217  if (etaMu1 < pair_etaminpos_ || etaMu1 > pair_etamaxpos_ || etaMu2 < pair_etaminneg_ ||
218  etaMu2 > pair_etamaxneg_) {
219  continue;
220  }
221 
222  double delta_eta = etaMu1 - etaMu2;
223 
224  double muplus = 1.0 / sqrt(2.0) * (LV_track1.E() + LV_track1.Z());
225  double muminus = 1.0 / sqrt(2.0) * (LV_track1.E() - LV_track1.Z());
226  double mubarplus = 1.0 / sqrt(2.0) * (LV_track2.E() + LV_track2.Z());
227  double mubarminus = 1.0 / sqrt(2.0) * (LV_track2.E() - LV_track2.Z());
228  //double costheta = 2.0 / Q.mag() / sqrt(pow(Q.mag(), 2) + pow(Q.Pt(), 2)) * (muplus * mubarminus - muminus * mubarplus);
229  double costhetaCS = 2.0 / LV_mother.mag() / sqrt(pow(LV_mother.mag(), 2) + pow(LV_mother.Pt(), 2)) *
230  (muplus * mubarminus - muminus * mubarplus);
231 
232  DiMuonValid::LV Pbeam(0., 0., eBeam_, eBeam_);
233  auto R = Pbeam.Vect().Cross(LV_mother.Vect());
234  auto Runit = R.Unit();
235  auto Qt = LV_mother.Vect();
236  Qt.SetZ(0);
237  auto Qtunit = Qt.Unit();
238  DiMuonValid::LV D(LV_track1 - LV_track2);
239  auto Dt = D.Vect();
240  Dt.SetZ(0);
241  double tanphi =
242  sqrt(pow(LV_mother.mag(), 2) + pow(LV_mother.Pt(), 2)) / LV_mother.mag() * Dt.Dot(Runit) / Dt.Dot(Qtunit);
243  double phiCS = atan(tanphi);
244 
245  if (mother_mass > pair_mass_min_ && mother_mass < pair_mass_max_) {
246  th2d_mass_variables_[0]->Fill(mother_mass, costhetaCS, 1);
247  th2d_mass_variables_[1]->Fill(mother_mass, delta_eta, 1);
248  th2d_mass_variables_[2]->Fill(mother_mass, etaMu2, 1);
249  th2d_mass_variables_[3]->Fill(mother_mass, etaMu1, 1);
250  th2d_mass_variables_[4]->Fill(mother_mass, phiCS, 1);
251  th2d_mass_variables_[5]->Fill(mother_mass, phiMu2, 1);
252  th2d_mass_variables_[6]->Fill(mother_mass, phiMu1, 1);
253  th2d_mass_variables_[7]->Fill(mother_mass, mother_pt, 1);
254  }
255  }
256  }
257 }
258 
259 // ------------ method called once each job just before starting event loop ------------
262  if (compressionSettings_ > 0) {
263  fs->file().SetCompressionSettings(compressionSettings_);
264  }
265 
266  for (int i = 0; i < varNumber_; i++) {
267  std::string th2d_name = fmt::sprintf("th2d_mass_%s", variables_name_[i].c_str());
268  th2d_mass_variables_[i] = fs->make<TH2D>(th2d_name.c_str(),
269  th2d_name.c_str(),
274  variables_min_[i],
275  variables_max_[i]);
276  }
277 }
278 
279 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
282  desc.setComment("Validates alignment payloads by evaluating bias in Z->mm mass distributions");
283  desc.addUntracked<int>("compressionSettings", -1);
284 
285  desc.add<double>("eBeam", 3500.)->setComment("beam energy in GeV");
286  desc.add<std::string>("TkTag", "ALCARECOTkAlZMuMu");
287 
288  desc.add<double>("Pair_mass_min", 60);
289  desc.add<double>("Pair_mass_max", 120);
290  desc.add<int>("Pair_mass_nbins", 120);
291  desc.add<double>("Pair_etaminpos", 60);
292  desc.add<double>("Pair_etamaxpos", 60);
293  desc.add<double>("Pair_etaminneg", 60);
294  desc.add<double>("Pair_etamaxneg", 60);
295 
296  desc.add<double>("Variable_CosThetaCS_xmin", -1.);
297  desc.add<double>("Variable_CosThetaCS_xmax", 1.);
298  desc.add<int>("Variable_CosThetaCS_nbins", 20);
299 
300  desc.add<double>("Variable_DeltaEta_xmin", -4.8);
301  desc.add<double>("Variable_DeltaEta_xmax", 4.8);
302  desc.add<int>("Variable_DeltaEta_nbins", 20);
303 
304  desc.add<double>("Variable_EtaMinus_xmin", -2.4);
305  desc.add<double>("Variable_EtaMinus_xmax", 2.4);
306  desc.add<int>("Variable_EtaMinus_nbins", 12);
307 
308  desc.add<double>("Variable_EtaPlus_xmin", -2.4);
309  desc.add<double>("Variable_EtaPlus_xmax", 2.4);
310  desc.add<int>("Variable_EtaPlus_nbins", 12);
311 
312  desc.add<double>("Variable_PhiCS_xmin", -M_PI / 2);
313  desc.add<double>("Variable_PhiCS_xmax", M_PI / 2);
314  desc.add<int>("Variable_PhiCS_nbins", 20);
315 
316  desc.add<double>("Variable_PhiMinus_xmin", -M_PI);
317  desc.add<double>("Variable_PhiMinus_xmax", M_PI);
318  desc.add<int>("Variable_PhiMinus_nbins", 16);
319 
320  desc.add<double>("Variable_PhiPlus_xmin", -M_PI);
321  desc.add<double>("Variable_PhiPlus_xmax", M_PI);
322  desc.add<int>("Variable_PhiPlus_nbins", 16);
323 
324  desc.add<double>("Variable_PairPt_xmin", 0.);
325  desc.add<double>("Variable_PairPt_xmax", 100.);
326  desc.add<int>("Variable_PairPt_nbins", 100);
327 
328  descriptions.addWithDefaultLabel(desc);
329 }
330 
331 //define this as a plug-in
static const std::string kSharedResource
Definition: TFileService.h:76
int variables_bins_number_[varNumber_]
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
DiMuonValidation(const edm::ParameterSet &pset)
static constexpr double mu_mass2_
TH2D * th2d_mass_variables_[varNumber_]
double variable_CosThetaCS_xmax_
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
double variables_min_[varNumber_]
double variable_CosThetaCS_xmin_
int iEvent
Definition: GenABIO.cc:224
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
T sqrt(T t)
Definition: SSEVec.h:19
std::string variables_name_[varNumber_]
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
#define M_PI
void beginJob() override
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
DecomposeProduct< arg, typename Div::arg > D
Definition: Factorize.h:141
double variables_max_[varNumber_]
HLT enums.
void analyze(const edm::Event &, const edm::EventSetup &) override
static constexpr int varNumber_
reco::Particle::LorentzVector LV
edm::EDGetTokenT< reco::TrackCollection > theTrackCollectionToken_
~DiMuonValidation() override=default
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:21
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29