CMS 3D CMS Logo

AlCaHOCalibProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 // Dec 2015 : Added bool m_cosmic to choose cosmic or collision run through python file
3 
4 //integrate the code with some 8_0_X or 7_6_X recent IB and run the
5 // following tests: 4.22, 8.0, 25.0, 140.53. You can always activate them using
6 //runTheMatrix.py -l 4.22
7 
8 // 7th Nov 2015 : tmpHOCalib.ecal03 = iso05.sumPt; // iso03.emEt+muonenr.em;
9 // tmpHOCalib.pileup=lumiScale->begin()->pileup();
10 //
11 // April 2015 : Remove all digi part
12 // Also look for HO geometry in CMSSW in parallel with stanalone one.
13 // Official one has problem in reco geometry, particularly tiles at the edge of wheel
14 // Remove all histogrammes except occupancy one
15 // Remove Trigger bits
16 // But addition of these variables, ilumi (analyser), pileup (analyser), nprim
17 
18 // Feb09 2009
19 // Move the initialisation of SteppingHelixPropagator from ::beginJob() to ::produce()
20 //
21 // Oct3 2008
22 // Difference in tag V00-02-45 with previous code
23 
24 // 1. One new object on data format, which was realised in
25 // CRUZET data analysis.
26 //2. Remove all histogram and cout in the code
27 //3. An upgrade in code, which increases the acceptance of
28 // muon near the edge (this also realised in CRUZET data).
29 // Difference in wrt V00-02-45
30 // 1. initialisation tmpHOCalib.htime = -1000;
31 // 2. By mistake HLT was commented out
32 
33 // Package: AlCaHOCalibProducer
34 // Class: AlCaHOCalibProducer
35 //
68 //
69 // Original Author: Gobinda Majumder
70 // Created: Fri Jul 6 17:17:21 CEST 2007
71 //
72 //
73 
74 // system include files
75 #include <memory>
76 
77 // user include files
87 
106 
113 
116 
119 
122 
123 // Necessary includes for identify severity of flagged problems in HO rechits
124 //#include "RecoLocalCalo/HcalRecAlgos/interface/HcalCaloFlagLabels.h"
129 #include "CLHEP/Vector/LorentzVector.h"
130 #include "CLHEP/Units/GlobalPhysicalConstants.h"
131 #include "CLHEP/Units/GlobalSystemOfUnits.h"
132 
133 #include "TH2F.h"
134 
135 /* C++ Headers */
136 #include <string>
137 
138 #include <iostream>
139 #include <fstream>
140 //
141 // class decleration
142 //
143 
144 class AlCaHOCalibProducer : public edm::one::EDProducer<edm::one::SharedResources> {
145 public:
146  explicit AlCaHOCalibProducer(const edm::ParameterSet&);
147  ~AlCaHOCalibProducer() override = default;
148 
149  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
153 
154 private:
155  void produce(edm::Event&, const edm::EventSetup&) override;
156  void beginJob() override;
157  void endJob() override;
158 
159  void fillHOStore(const reco::TrackRef& ncosm,
160  HOCalibVariables& tmpHOCalib,
161  std::unique_ptr<HOCalibVariableCollection>& hostore,
162  int Noccu_old,
163  int indx,
166  const edm::Event& iEvent,
168  const MagneticField&);
169 
170  void findHOEtaPhi(int iphsect, int& ietaho, int& iphiho);
171  // virtual void endRun(edm::Run const &, edm::EventSetup const &) override;
172  // ----------member data ---------------------------
173 
174  float xhor0; //x-position in ring 0
175  float yhor0; //y-position in ring 0
176  float xhor1; //x-position in ring 1
177  float yhor1; //y-position in ring 1
178  int iring; //Ring number -2,-1,0,1,2
179 
180  float localxhor0; //local x-distance from edege in ring 0
181  float localyhor0; //local y-distance from edege in ring 0
182  float localxhor1; //local x-distance from edege in ring 1
183  float localyhor1; //local y-distance from edege in ring 1
184 
185  TH2F* ho_occupency[5];
187  bool m_cosmic;
188 
189  const int netabin = 16;
190  const int nphimx = 72;
191  const int netamx = 32;
192  const int ncidmx = 5;
193  const double rHOL0 = 382.0;
194  const double rHOL1 = 407.0;
195 
196  edm::InputTag muonTags_; // cosmicMuons (for cosmic run) or muons (for collision run)
197 
201  // edm::EDGetTokenT<LumiDetails> tok_lumi_;
204 
208 
213 
214  bool m_hbinfo;
216  int m_endTS;
217  double m_sigma;
218 
220  int Noccu;
221  int nRuns;
222 
223  // SteppingHelixPropagator* stepProp;
224  FreeTrajectoryState getFreeTrajectoryState(const reco::Track& tk, const MagneticField* field, int itag, bool dir);
225 
226  unsigned int Ntp; // # of HLT trigger paths (should be the same for all events!)
227  std::map<std::string, bool> fired;
228 
229  //hcal severity ES
232  int Nevents;
233 };
234 
235 //
236 // constants, enums and typedefs
237 //
238 
239 //
240 // static data member definitions
241 //
242 
243 //
244 // constructors and destructor
245 //
247  usesResource(TFileService::kSharedResource);
248  //register your products
249 
250  m_hbinfo = iConfig.getUntrackedParameter<bool>("hbinfo", false);
251  m_sigma = iConfig.getUntrackedParameter<double>("sigma", 0.05);
252  m_occupancy = iConfig.getUntrackedParameter<bool>("plotOccupancy", false);
253  m_cosmic = iConfig.getUntrackedParameter<bool>("CosmicData", false);
254 
255  // keep InputTag muonTags_ since it is used below. - cowden
256  muonTags_ = iConfig.getUntrackedParameter<edm::InputTag>("muons");
257  tok_muonsCosmic_ = consumes<reco::TrackCollection>(muonTags_);
258  tok_muons_ = consumes<edm::View<reco::Muon> >(muonTags_);
259  tok_vertex_ = consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vertexTags"));
260  // tok_lumi_ = consumes<LumiDetails ,edm::InLumi>(iConfig.getParameter<edm::InputTag>("lumiTags"));
261  tok_lumi_ = consumes<LumiScalersCollection>(iConfig.getParameter<edm::InputTag>("lumiTags"));
262  tok_metaData_ = consumes<OnlineLuminosityRecord>(iConfig.getParameter<edm::InputTag>("metadata"));
263  tok_ho_ = consumes<HORecHitCollection>(iConfig.getParameter<edm::InputTag>("hoInput"));
264  tok_hbhe_ = consumes<HBHERecHitCollection>(iConfig.getParameter<edm::InputTag>("hbheInput"));
265  tok_tower_ = consumes<CaloTowerCollection>(iConfig.getParameter<edm::InputTag>("towerInput"));
266 
267  tok_hcalChStatus_ = esConsumes<HcalChannelQuality, HcalChannelQualityRcd>(edm::ESInputTag("", "withTopo"));
268  tok_geom_ = esConsumes<CaloGeometry, CaloGeometryRecord>();
269  tok_hcalSevLvlComputer_ = esConsumes<HcalSeverityLevelComputer, HcalSeverityLevelComputerRcd>();
270  tok_magField_ = esConsumes<MagneticField, IdealMagneticFieldRecord>();
271 
272  produces<HOCalibVariableCollection>("HOCalibVariableCollection").setBranchAlias("HOCalibVariableCollection");
273 
274  if (m_occupancy) {
276 
277  char title[200];
278 
279  for (int ij = 0; ij < 5; ij++) {
280  sprintf(title, "ho_occupency (>%i #sigma)", ij + 2);
281  ho_occupency[ij] =
282  fs->make<TH2F>(title, title, netamx + 1, -netamx - 0.5, netamx / 2 + 0.5, nphimx, 0.5, nphimx + 0.5);
283  }
284  }
285 }
286 
287 //
288 // member functions
289 //
290 
293  desc.add<edm::InputTag>("hbheInput", edm::InputTag("hbhereco"));
294  desc.addUntracked<bool>("hotime", false);
295  desc.addUntracked<bool>("hbinfo", false);
296  desc.addUntracked<double>("sigma", 1.0);
297  desc.addUntracked<bool>("plotOccupancy", false);
298  desc.addUntracked<bool>("CosmicData", false);
299  desc.add<edm::InputTag>("hoInput", edm::InputTag("horeco"));
300  desc.add<edm::InputTag>("towerInput", edm::InputTag("towerMaker"));
301  desc.addUntracked<std::string>("RootFileName", "test.root");
302  desc.addUntracked<double>("m_scale", 4.0);
303  desc.addUntracked<bool>("debug", false);
304  desc.addUntracked<edm::InputTag>("muons", edm::InputTag("muons"));
305  desc.add<edm::InputTag>("vertexTags", edm::InputTag("offlinePrimaryVertices"));
306  desc.add<edm::InputTag>("lumiTags", edm::InputTag("scalersRawToDigi"));
307  desc.add<edm::InputTag>("metadata", edm::InputTag("onlineMetaDataDigis"));
308  descriptions.add("alcaHOCalibProducer", desc);
309 }
310 
311 // ------------ method called to produce the data ------------
313  int irun = iEvent.id().run();
314  // int ilumi = iEvent.luminosityBlock();
315 
316  Nevents++;
317 
318  if (Nevents % 5000 == 1)
319  edm::LogInfo("HOCalib") << "AlCaHOCalibProducer Processing event # " << Nevents << " " << Noccu << " " << irun
320  << " " << iEvent.id().event();
321 
323 
324  auto hostore = std::make_unique<HOCalibVariableCollection>();
325 
327  edm::Handle<edm::View<reco::Muon> > collisionmuon;
328 
329  bool muonOK(true);
330  HOCalibVariables tmpHOCalib;
331  tmpHOCalib.nprim = -1;
332  tmpHOCalib.pileup = -1.;
333 
334  if (m_cosmic) {
335  cosmicmuon = iEvent.getHandle(tok_muonsCosmic_);
336  muonOK = (cosmicmuon.isValid() && !cosmicmuon->empty());
337  } else {
338  collisionmuon = iEvent.getHandle(tok_muons_);
339  muonOK = (collisionmuon.isValid() && !collisionmuon->empty());
340 
341  if (iEvent.isRealData()) {
342  auto const& primaryVertices = iEvent.getHandle(tok_vertex_);
343  if (primaryVertices.isValid()) {
344  tmpHOCalib.nprim = primaryVertices->size();
345  }
346 
347  tmpHOCalib.pileup = 0.;
348 
349  auto const& lumiScale = iEvent.getHandle(tok_lumi_);
350  auto const& metaData = iEvent.getHandle(tok_metaData_);
351 
352  // by default use Run-3 access (onlineMetaDataDigis)
353  if (metaData.isValid()) {
354  tmpHOCalib.pileup = metaData->avgPileUp();
355  } else if (lumiScale.isValid() && !lumiScale->empty()) {
356  if (lumiScale->begin() != lumiScale->end()) {
357  tmpHOCalib.pileup = lumiScale->begin()->pileup();
358  }
359  } else {
360  edm::LogWarning("HOCalib") << "Neither LumiScalers nor OnlineMetadata collections found in the event";
361  }
362  }
363  }
364 
365  if (muonOK) {
366  int Noccu_old = Noccu;
368 
370 
371  MagneticField const& magField = iSetup.getData(tok_magField_);
372 
373  const CaloGeometry& geo = iSetup.getData(tok_geom_);
375 
376  if (m_cosmic) {
377  int indx(0);
378  for (reco::TrackCollection::const_iterator ncosm = cosmicmuon->begin(); ncosm != cosmicmuon->end();
379  ++ncosm, ++indx) {
380  if ((*ncosm).ndof() < 15)
381  continue;
382  if ((*ncosm).normalizedChi2() > 30.0)
383  continue;
384  reco::TrackRef tRef = reco::TrackRef(cosmicmuon, indx);
385  fillHOStore(tRef, tmpHOCalib, hostore, Noccu_old, indx, cosmicmuon, muon1, iEvent, gHO, magField);
386  }
387  } else {
388  for (muon1 = collisionmuon->begin(); muon1 < collisionmuon->end(); muon1++) {
389  if ((!muon1->isGlobalMuon()) || (!muon1->isTrackerMuon()))
390  continue;
391  reco::TrackRef ncosm = muon1->innerTrack();
392  fillHOStore(ncosm, tmpHOCalib, hostore, Noccu_old, 0, cosmicmuon, muon1, iEvent, gHO, magField);
393  }
394  }
395  }
396 
397  iEvent.put(std::move(hostore), "HOCalibVariableCollection");
398 }
399 
400 // ------------ method called once each job just before starting event loop ------------
402  Nevents = 0;
403  nRuns = 0;
404  Noccu = 0;
405 }
406 
407 // ------------ method called once each job just after ending the event loop ------------
409  if (m_occupancy) {
410  for (int ij = 0; ij < 5; ij++) {
411  ho_occupency[ij]->Scale(1. / std::max(1, Noccu));
412  }
413  }
414  edm::LogInfo("HOCalib") << " AlCaHOCalibProducer processed event " << Nevents;
415 }
416 
418  HOCalibVariables& tmpHOCalib,
419  std::unique_ptr<HOCalibVariableCollection>& hostore,
420  int Noccu_old,
421  int indx,
424  const edm::Event& iEvent,
425  const CaloSubdetectorGeometry* gHO,
426  const MagneticField& magField) {
427  // Get Hcal Severity Level Computer, so that the severity of each rechit flag/status may be determined
428 
429  int charge = ncosm->charge();
430 
431  double innerr = (*ncosm).innerPosition().Perp2();
432  double outerr = (*ncosm).outerPosition().Perp2();
433  int iiner = (innerr < outerr) ? 1 : 0;
434 
435  //---------------------------------------------------
436  // in_to_out Dir in_to_out Dir
437  // StandAlone ^ ^ Cosmic ^ |
438  // | | | v
439  //---------------------------------------------------Y=0
440  // StandAlone | | Cosmic ^ |
441  // v v | v
442  //----------------------------------------------------
443 
444  double posx, posy, posz;
445  double momx, momy, momz;
446 
447  if (iiner == 1) {
448  posx = (*ncosm).innerPosition().X();
449  posy = (*ncosm).innerPosition().Y();
450  posz = (*ncosm).innerPosition().Z();
451 
452  momx = (*ncosm).innerMomentum().X();
453  momy = (*ncosm).innerMomentum().Y();
454  momz = (*ncosm).innerMomentum().Z();
455 
456  } else {
457  posx = (*ncosm).outerPosition().X();
458  posy = (*ncosm).outerPosition().Y();
459  posz = (*ncosm).outerPosition().Z();
460 
461  momx = (*ncosm).outerMomentum().X();
462  momy = (*ncosm).outerMomentum().Y();
463  momz = (*ncosm).outerMomentum().Z();
464  }
465 
466  PositionType trkpos(posx, posy, posz);
467 
468  CLHEP::Hep3Vector tmpmuon3v(posx, posy, posz);
469  CLHEP::Hep3Vector tmpmuondir(momx, momy, momz);
470 
471  bool samedir = (tmpmuon3v.dot(tmpmuondir) > 0) ? true : false;
472  for (int ij = 0; ij < 3; ij++) {
473  tmpHOCalib.caloen[ij] = 0.0;
474  }
475  int inearbymuon = 0;
476  localxhor0 = localyhor0 = 20000; //GM for 22OCT07 data
477 
478  if (m_cosmic) {
479  int ind(0);
480  for (reco::TrackCollection::const_iterator ncosmcor = cosmicmuon->begin(); ncosmcor != cosmicmuon->end();
481  ++ncosmcor, ++ind) {
482  if (indx == ind)
483  continue;
484  CLHEP::Hep3Vector tmpmuon3vcor;
485  CLHEP::Hep3Vector tmpmom3v;
486  if (iiner == 1) {
487  tmpmuon3vcor = CLHEP::Hep3Vector(
488  (*ncosmcor).innerPosition().X(), (*ncosmcor).innerPosition().Y(), (*ncosmcor).innerPosition().Z());
489  tmpmom3v = CLHEP::Hep3Vector(
490  (*ncosmcor).innerMomentum().X(), (*ncosmcor).innerMomentum().Y(), (*ncosmcor).innerMomentum().Z());
491  } else {
492  tmpmuon3vcor = CLHEP::Hep3Vector(
493  (*ncosmcor).outerPosition().X(), (*ncosmcor).outerPosition().Y(), (*ncosmcor).outerPosition().Z());
494  tmpmom3v = CLHEP::Hep3Vector(
495  (*ncosmcor).outerMomentum().X(), (*ncosmcor).outerMomentum().Y(), (*ncosmcor).outerMomentum().Z());
496  }
497 
498  if (tmpmom3v.mag() < 0.2 || (*ncosmcor).ndof() < 5)
499  continue;
500 
501  double angle = tmpmuon3v.angle(tmpmuon3vcor);
502  if (angle < 7.5 * CLHEP::deg) {
503  inearbymuon = 1;
504  } // break;}
505 
506  // if (muonTagsi_.label() =="cosmicMuons") {
507  if (angle < 7.5 * CLHEP::deg) {
508  tmpHOCalib.caloen[0] += 1.;
509  }
510  if (angle < 15.0 * CLHEP::deg) {
511  tmpHOCalib.caloen[1] += 1.;
512  }
513  if (angle < 35.0 * CLHEP::deg) {
514  tmpHOCalib.caloen[2] += 1.;
515  }
516  }
517  } else {
518  // if (muonTags_.label() =="muons") {
519  auto const& calotower = iEvent.getHandle(tok_tower_);
520 
521  for (CaloTowerCollection::const_iterator calt = calotower->begin(); calt != calotower->end(); calt++) {
522  //CMSSW_2_1_x const math::XYZVector towermom = (*calt).momentum();
523  double ith = (*calt).momentum().theta();
524  double iph = (*calt).momentum().phi();
525 
526  CLHEP::Hep3Vector calo3v(sin(ith) * cos(iph), sin(ith) * sin(iph), cos(ith));
527 
528  double angle = tmpmuon3v.angle(calo3v);
529 
530  if (angle < 7.5 * CLHEP::deg) {
531  tmpHOCalib.caloen[0] += calt->emEnergy() + calt->hadEnergy();
532  }
533  if (angle < 15 * CLHEP::deg) {
534  tmpHOCalib.caloen[1] += calt->emEnergy() + calt->hadEnergy();
535  }
536  if (angle < 35 * CLHEP::deg) {
537  tmpHOCalib.caloen[2] += calt->emEnergy() + calt->hadEnergy();
538  }
539  }
540  }
541  if ((m_cosmic) || (tmpHOCalib.caloen[0] <= 10.0)) {
542  GlobalPoint glbpt(posx, posy, posz);
543 
544  double mom = sqrt(momx * momx + momy * momy + momz * momz);
545 
546  momx /= mom;
547  momy /= mom;
548  momz /= mom;
549 
550  DirectionType trkdir(momx, momy, momz);
551 
552  tmpHOCalib.trkdr = (*ncosm).d0();
553  tmpHOCalib.trkdz = (*ncosm).dz();
554  tmpHOCalib.nmuon = (m_cosmic) ? cosmicmuon->size() : 1;
555  tmpHOCalib.trkvx = glbpt.x();
556  tmpHOCalib.trkvy = glbpt.y();
557  tmpHOCalib.trkvz = glbpt.z();
558  tmpHOCalib.trkmm = mom * charge;
559  tmpHOCalib.trkth = trkdir.theta();
560  tmpHOCalib.trkph = trkdir.phi();
561  tmpHOCalib.isect2 = -2;
562  tmpHOCalib.isect = -2;
563  tmpHOCalib.hodx = -100;
564  tmpHOCalib.hody = -100;
565  tmpHOCalib.hoang = -2.0;
566  tmpHOCalib.momatho = -2;
567  tmpHOCalib.ndof = (inearbymuon == 0) ? (int)(*ncosm).ndof() : -(int)(*ncosm).ndof();
568  tmpHOCalib.chisq = (*ncosm).normalizedChi2(); // max(1.,tmpHOCalib.ndof);
569  if (!m_cosmic) {
570  reco::MuonEnergy muonenr = muon1->calEnergy();
571  reco::MuonIsolation iso03 = muon1->isolationR03();
572  reco::MuonIsolation iso05 = muon1->isolationR05();
573 
574  tmpHOCalib.tkpt03 = iso03.sumPt;
575  tmpHOCalib.ecal03 = iso05.sumPt; // iso03.emEt+muonenr.em;
576  tmpHOCalib.hcal03 = iso03.hadEt + muonenr.had;
577  }
578  tmpHOCalib.therr = 0.;
579  tmpHOCalib.pherr = 0.;
580  if (iiner == 1) {
581  reco::TrackBase::CovarianceMatrix innercov = (*ncosm).innerStateCovariance();
582  tmpHOCalib.therr = innercov(1, 1); //thetaError();
583  tmpHOCalib.pherr = innercov(2, 2); //phi0Error();
584  } else {
585  reco::TrackBase::CovarianceMatrix outercov = (*ncosm).outerStateCovariance();
586  tmpHOCalib.therr = outercov(1, 1); //thetaError();
587  tmpHOCalib.pherr = outercov(2, 2); //phi0Error();
588  }
589 
590  SteppingHelixPropagator myHelix(&magField, anyDirection);
591  myHelix.setMaterialMode(false);
592  myHelix.applyRadX0Correction(true);
593  double phiho = trkpos.phi();
594  if (phiho < 0)
595  phiho += CLHEP::twopi;
596 
597  int iphisect_dt = int(6 * (phiho + 10.0 * CLHEP::deg) / CLHEP::pi); //for u 18/12/06
598  if (iphisect_dt >= 12)
599  iphisect_dt = 0;
600 
601  int iphisect = -1;
602  bool ipath = false;
603  for (int kl = 0; kl <= 2; kl++) {
604  int iphisecttmp = (kl < 2) ? iphisect_dt + kl : iphisect_dt - 1;
605  if (iphisecttmp < 0)
606  iphisecttmp = 11;
607  if (iphisecttmp >= 12)
608  iphisecttmp = 0;
609 
610  double phipos = iphisecttmp * CLHEP::pi / 6.;
611  double phirot = phipos;
612 
613  GlobalVector xLocal(-sin(phirot), cos(phirot), 0.);
614  GlobalVector yLocal(0., 0., 1.);
615  GlobalVector zLocal = xLocal.cross(yLocal).unit();
616  // GlobalVector zLocal(cos(phirot), sin(phirot), 0.0);
617 
618  FreeTrajectoryState freetrajectorystate_ = getFreeTrajectoryState(*ncosm, &(magField), iiner, samedir);
619 
620  Surface::RotationType rot(xLocal, yLocal, zLocal);
621 
622  for (int ik = 1; ik >= 0; ik--) { //propagate track in two HO layers
623 
624  double radial = rHOL1;
625  if (ik == 0)
626  radial = rHOL0;
627 
628  Surface::PositionType pos(radial * cos(phipos), radial * sin(phipos), 0.);
630 
631  auto aPlane2 = new Plane(pos, rot);
632 
633  SteppingHelixStateInfo steppingHelixstateinfo_;
634  myHelix.propagate(SteppingHelixStateInfo(freetrajectorystate_), (*aPlane2), steppingHelixstateinfo_);
635 
636  if (steppingHelixstateinfo_.isValid()) {
637  GlobalPoint hotrkpos2xx(steppingHelixstateinfo_.position().x(),
638  steppingHelixstateinfo_.position().y(),
639  steppingHelixstateinfo_.position().z());
640 
641  if (ik == 1) {
642  HcalDetId ClosestCell = (HcalDetId)gHO->getClosestCell(hotrkpos2xx);
643  int ixeta = ClosestCell.ieta();
644  int ixphi = ClosestCell.iphi();
645  tmpHOCalib.isect2 = 100 * std::abs(ixeta + 50) + std::abs(ixphi);
646  }
647 
648  GlobalVector hotrkpos2(steppingHelixstateinfo_.position().x(),
649  steppingHelixstateinfo_.position().y(),
650  steppingHelixstateinfo_.position().z());
651  CLHEP::Hep3Vector hotrkdir2(steppingHelixstateinfo_.momentum().x(),
652  steppingHelixstateinfo_.momentum().y(),
653  steppingHelixstateinfo_.momentum().z());
654 
655  LocalVector lclvt0 = (*aPlane).toLocal(hotrkpos2);
656 
657  double xx = lclvt0.x();
658  double yy = lclvt0.y();
659 
660  if (ik == 1) {
661  if ((std::abs(yy) < 130 && xx > -64.7 && xx < 138.2) //Ring-0
662  || (std::abs(yy) > 130 && std::abs(yy) < 700 && xx > -76.3 && xx < 140.5)) { //Ring +-1,2
663  ipath = true; //Only look for tracks which as hits in layer 1
664  iphisect = iphisecttmp;
665  }
666  }
667 
668  if (iphisect != iphisecttmp)
669  continue; //Look for ring-0 only when ring1 is accepted for that sector
670 
671  switch (ik) {
672  case 0:
673  xhor0 = xx; //lclvt0.x();
674  yhor0 = yy; //lclvt0.y();
675  break;
676  case 1:
677  xhor1 = xx; //lclvt0.x();
678  yhor1 = yy; //lclvt0.y();
679  tmpHOCalib.momatho = hotrkdir2.mag();
680  tmpHOCalib.hoang = CLHEP::Hep3Vector(zLocal.x(), zLocal.y(), zLocal.z()).dot(hotrkdir2.unit());
681  break;
682  default:
683  break;
684  }
685  } else {
686  break;
687  }
688  }
689  if (ipath)
690  break;
691  }
692  if (ipath) { //If muon crossed HO laeyrs
693 
694  int ietaho = 50;
695  int iphiho = -1;
696 
697  for (int ij = 0; ij < 9; ij++) {
698  tmpHOCalib.hosig[ij] = -100.0;
699  }
700  for (int ij = 0; ij < 18; ij++) {
701  tmpHOCalib.hocorsig[ij] = -100.0;
702  }
703  for (int ij = 0; ij < 9; ij++) {
704  tmpHOCalib.hbhesig[ij] = -100.0;
705  }
706  tmpHOCalib.hocro = -100;
707  tmpHOCalib.htime = -1000;
708 
709  int isect = 0;
710 
711  findHOEtaPhi(iphisect, ietaho, iphiho);
712 
713  if (ietaho != 0 && iphiho != 0 && std::abs(iring) <= 2) { //Muon passed through a tower
714  isect = 100 * std::abs(ietaho + 50) + std::abs(iphiho);
715  if (std::abs(ietaho) >= netabin || iphiho < 0)
716  isect *= -1; //Not extrapolated to any tower
717  if (std::abs(ietaho) >= netabin)
718  isect -= 1000000; //not matched with eta
719  if (iphiho < 0)
720  isect -= 2000000; //not matched with phi
721  tmpHOCalib.isect = isect;
722 
723  tmpHOCalib.hodx = localxhor1;
724  tmpHOCalib.hody = localyhor1;
725 
726  if (iring == 0) {
727  tmpHOCalib.hocorsig[8] = localxhor0;
728  tmpHOCalib.hocorsig[9] = localyhor0;
729  }
730 
731  int etamn = -4;
732  int etamx = 4;
733  if (iring == 1) {
734  etamn = 5;
735  etamx = 10;
736  }
737  if (iring == 2) {
738  etamn = 11;
739  etamx = 16;
740  }
741  if (iring == -1) {
742  etamn = -10;
743  etamx = -5;
744  }
745  if (iring == -2) {
746  etamn = -16;
747  etamx = -11;
748  }
749 
750  int phimn = 1;
751  int phimx = 2;
752  if (iring == 0) {
753  phimx = 2 * int((iphiho + 1) / 2.);
754  phimn = phimx - 1;
755  } else {
756  phimn = 3 * int((iphiho + 1) / 3.) - 1;
757  phimx = phimn + 2;
758  }
759 
760  if (phimn < 1)
761  phimn += nphimx;
762  if (phimx > 72)
763  phimx -= nphimx;
764 
765  if (m_hbinfo) {
766  for (int ij = 0; ij < 9; ij++) {
767  tmpHOCalib.hbhesig[ij] = -100.0;
768  }
769 
770  auto const& hbheht = iEvent.getHandle(tok_hbhe_); // iEvent.getByType(hbheht);
771  if (!(*hbheht).empty()) {
772  if ((*hbheht).empty())
773  throw (int)(*hbheht).size();
774 
775  for (HBHERecHitCollection::const_iterator jk = (*hbheht).begin(); jk != (*hbheht).end(); jk++) {
776  HcalDetId id = (*jk).id();
777  int tmpeta = id.ieta();
778  int tmpphi = id.iphi();
779 
780  int deta = tmpeta - ietaho;
781  if (tmpeta < 0 && ietaho > 0)
782  deta += 1;
783  if (tmpeta > 0 && ietaho < 0)
784  deta -= 1;
785 
786  // if (tmpeta==-1 && ietaho== 1) deta = -1;
787  // if (tmpeta== 1 && ietaho==-1) deta = 1;
788 
789  int dphi = tmpphi - iphiho;
790  if (dphi > nphimx / 2) {
791  dphi -= nphimx;
792  }
793  if (dphi < -nphimx / 2) {
794  dphi += nphimx;
795  }
796 
797  // if (phimn >phimx) {
798  // if (dphi==71) dphi=-1;
799  // if (dphi==-71) dphi=1;
800  // }
801 
802  if (m_occupancy) {
803  float signal = (*jk).energy();
804  // int tmpeta1 = (tmpeta>0) ? tmpeta -1 : -tmpeta +14;
805  if (signal > -100 && Noccu == Noccu_old) {
806  for (int ij = 0; ij < 5; ij++) {
807  if (signal > (ij + 2) * m_sigma) {
808  ho_occupency[ij]->Fill(tmpeta, tmpphi);
809  }
810  }
811  }
812  }
813 
814  int ipass2 = (std::abs(deta) <= 1 && std::abs(dphi) <= 1) ? 1 : 0; //NEED correction in full CMS detector
815  if (ipass2 == 0)
816  continue;
817 
818  float signal = (*jk).energy();
819 
820  if (3 * (deta + 1) + dphi + 1 < 9)
821  tmpHOCalib.hbhesig[3 * (deta + 1) + dphi + 1] = signal;
822  }
823  }
824  } //m_hbinfo #endif
825 
826  auto const& hoht = iEvent.getHandle(tok_ho_);
827 
828  if (!(*hoht).empty()) {
829  for (HORecHitCollection::const_iterator jk = (*hoht).begin(); jk != (*hoht).end(); jk++) {
830  HcalDetId id = (*jk).id();
831  int tmpeta = id.ieta();
832  int tmpphi = id.iphi();
833 
834  int ipass1 = 0;
835  if (tmpeta >= etamn && tmpeta <= etamx) {
836  if (phimn < phimx) {
837  ipass1 = (tmpphi >= phimn && tmpphi <= phimx) ? 1 : 0;
838  } else {
839  ipass1 = (tmpphi == 71 || tmpphi == 72 || tmpphi == 1) ? 1 : 0;
840  }
841  }
842 
843  int deta = tmpeta - ietaho;
844  int dphi = tmpphi - iphiho;
845 
846  if (tmpeta < 0 && ietaho > 0)
847  deta += 1;
848  if (tmpeta > 0 && ietaho < 0)
849  deta -= 1;
850  // if (tmpeta==-1 && ietaho== 1) deta = -1;
851  // if (tmpeta== 1 && ietaho==-1) deta = 1;
852 
853  if (dphi > nphimx / 2) {
854  dphi -= nphimx;
855  }
856  if (dphi < -nphimx / 2) {
857  dphi += nphimx;
858  }
859  // if (phimn>phimx) {
860  // if (dphi==71) dphi=-1;
861  // if (dphi==-71) dphi=1;
862  // }
863 
864  float signal = (*jk).energy();
865 
866  int ipass2 = (std::abs(deta) <= 1 && std::abs(dphi) <= 1) ? 1 : 0;
867 
868  if (ipass1 == 0 && ipass2 == 0)
869  continue;
870 
871  if (ipass1 == 1) {
872  int tmpdph = tmpphi - phimn;
873  if (tmpdph < 0)
874  tmpdph = 2; //only case of iphi==1, where phimn=71
875 
876  int ilog = 2 * (tmpeta - etamn) + tmpdph;
877  if (iring != 0) {
878  if (iring > 0) {
879  ilog = 3 * (tmpeta - etamn) + tmpdph; //Again CMS correction
880  } else {
881  ilog = 3 * (etamx - tmpeta) + tmpdph; //Again CMS correction
882  }
883  }
884  if (ilog > -1 && ilog < 18) {
885  tmpHOCalib.hocorsig[ilog] = signal;
886  }
887  }
888 
889  if (ipass2 == 1) {
890  if (3 * (deta + 1) + dphi + 1 < 9) {
891  tmpHOCalib.hosig[3 * (deta + 1) + dphi + 1] = signal; //Again CMS azimuthal near phi 1&72
892  }
893  }
894 
895  if (deta == 0 && dphi == 0) {
896  tmpHOCalib.htime = (*jk).time();
897  tmpHOCalib.hoflag = (*jk).flags();
898 
899  // Get Channel Quality information for the given detID
900  unsigned theStatusValue = theHcalChStatus->getValues(id)->getValue();
901  // Now get severity of problems for the given detID, based on the rechit flag word and the channel quality status value
902  int hitSeverity = theHcalSevLvlComputer->getSeverityLevel(id, (*jk).flags(), theStatusValue);
903  tmpHOCalib.hoflag = hitSeverity;
904  int crphi = tmpphi + 6;
905  if (crphi > 72)
906  crphi -= 72;
907 
908  for (HORecHitCollection::const_iterator jcr = (*hoht).begin(); jcr != (*hoht).end(); jcr++) {
909  const HORecHit reccr = (const HORecHit)(*jcr);
910  HcalDetId idcr = reccr.id();
911  int etacr = idcr.ieta();
912  int phicr = idcr.iphi();
913  if (tmpeta == etacr && crphi == phicr) {
914  tmpHOCalib.hocro = reccr.energy();
915  }
916  }
917  }
918  }
919  }
920  }
921 
922  //GMA Npass++;
923  if (Noccu == Noccu_old)
924  Noccu++;
925  hostore->push_back(tmpHOCalib);
926  } // if (ipath)
927  } // Cut on calo energy
928 }
929 
930 void AlCaHOCalibProducer::findHOEtaPhi(int iphisect, int& ietaho, int& iphiho) {
931  //18/12/06 : use only position, not angle phi
932 
933  const double etalow[16] = {0.025,
934  35.195,
935  70.625,
936  106.595,
937  141.565,
938  180.765,
939  220.235,
940  261.385,
941  304.525,
942  349.975,
943  410.025,
944  452.085,
945  506.645,
946  565.025,
947  627.725,
948  660.25};
949  const double etahgh[16] = {35.145,
950  70.575,
951  106.545,
952  125.505,
953  180.715,
954  220.185,
955  261.335,
956  304.475,
957  349.925,
958  392.575,
959  452.035,
960  506.595,
961  564.975,
962  627.675,
963  661.075,
964  700.25};
965 
966  const double philow[6] = {-76.27, -35.11, 0.35, 35.81, 71.77, 108.93}; //Ring+/-1 & 2
967  const double phihgh[6] = {-35.81, -0.35, 35.11, 71.07, 108.23, 140.49};
968 
969  const double philow00[6] = {-60.27, -32.91, 0.35, 33.61, 67.37, 102.23}; //Ring0 L0
970  const double phihgh00[6] = {-33.61, -0.35, 32.91, 66.67, 101.53, 129.49};
971 
972  const double philow01[6] = {-64.67, -34.91, 0.35, 35.61, 71.37, 108.33}; //Ring0 L1
973  const double phihgh01[6] = {-35.61, -0.35, 34.91, 70.67, 107.63, 138.19};
974 
975  iring = -10;
976 
977  double tmpdy = std::abs(yhor1);
978  for (int ij = 0; ij < netabin; ij++) {
979  if (tmpdy > etalow[ij] && tmpdy < etahgh[ij]) {
980  ietaho = ij + 1;
981  float tmp1 = fabs(tmpdy - etalow[ij]);
982  float tmp2 = fabs(tmpdy - etahgh[ij]);
983 
984  localyhor1 = (tmp1 < tmp2) ? -tmp1 : tmp2;
985  if (yhor1 < 0)
986  localyhor1 *= -1.;
987 
988  if (ij < 4)
989  iring = 0;
990  if (ij >= 4 && ij < 10)
991  iring = 1;
992  if (ij >= 10 && ij < netabin)
993  iring = 2;
994  break;
995  }
996  }
997 
998  int tmpphi = 0;
999  int tmpphi0 = 0;
1000 
1001  if (ietaho > 4) { //Ring 1 and 2
1002  for (int ij = 0; ij < 6; ij++) {
1003  if (xhor1 > philow[ij] && xhor1 < phihgh[ij]) {
1004  tmpphi = ij + 1;
1005  float tmp1 = fabs(xhor1 - philow[ij]);
1006  float tmp2 = fabs(xhor1 - phihgh[ij]);
1007  localxhor1 = (tmp1 < tmp2) ? -tmp1 : tmp2;
1008  break;
1009  }
1010  }
1011  } else { //Ring 0
1012  for (int ij = 0; ij < 6; ij++) {
1013  if (xhor1 > philow01[ij] && xhor1 < phihgh01[ij]) {
1014  tmpphi = ij + 1;
1015  float tmp1 = fabs(xhor1 - philow01[ij]);
1016  float tmp2 = fabs(xhor1 - phihgh01[ij]);
1017  localxhor1 = (tmp1 < tmp2) ? -tmp1 : tmp2;
1018  break;
1019  }
1020  }
1021 
1022  for (int ij = 0; ij < 6; ij++) {
1023  if (xhor0 > philow00[ij] && xhor0 < phihgh00[ij]) {
1024  tmpphi0 = ij + 1;
1025  float tmp1 = fabs(xhor0 - philow00[ij]);
1026  float tmp2 = fabs(xhor0 - phihgh00[ij]);
1027  localxhor0 = (tmp1 < tmp2) ? -tmp1 : tmp2;
1028  if (tmpphi != tmpphi0)
1029  localxhor0 += 10000.;
1030  break;
1031  }
1032  }
1033 
1034  double tmpdy = std::abs(yhor0);
1035  for (int ij = 0; ij < 4; ij++) {
1036  if (tmpdy > etalow[ij] && tmpdy < etahgh[ij]) {
1037  float tmp1 = fabs(tmpdy - etalow[ij]);
1038  float tmp2 = fabs(tmpdy - etahgh[ij]);
1039  localyhor0 = (tmp1 < tmp2) ? -tmp1 : tmp2;
1040  if (yhor0 < 0)
1041  localyhor0 *= -1.;
1042  if (ij + 1 != ietaho)
1043  localyhor0 += 10000.;
1044  break;
1045  }
1046  }
1047  }
1048 
1049  if (tmpphi != 0) {
1050  iphiho = 6 * iphisect - 2 + tmpphi;
1051  if (iphiho <= 0)
1052  iphiho += nphimx;
1053  if (iphiho > nphimx)
1054  iphiho -= nphimx;
1055  }
1056 
1057  // isect2 = 15*iring+iphisect+1;
1058 
1059  if (yhor1 < 0) {
1060  if (std::abs(ietaho) > netabin) { //Initialised with 50
1061  ietaho += 1;
1062  } else {
1063  ietaho *= -1;
1064  }
1065  // isect2 *=-1;
1066  iring *= -1;
1067  }
1068 }
1069 
1071  const MagneticField* field,
1072  int iiner,
1073  bool dir) {
1074  if (iiner == 0) {
1075  GlobalPoint gpos(tk.outerX(), tk.outerY(), tk.outerZ());
1076  GlobalVector gmom(tk.outerPx(), tk.outerPy(), tk.outerPz());
1077  if (dir)
1078  gmom *= -1.;
1079  GlobalTrajectoryParameters par(gpos, gmom, tk.charge(), field);
1080  CurvilinearTrajectoryError err(tk.extra()->outerStateCovariance());
1081  return FreeTrajectoryState(par, err);
1082  } else {
1083  GlobalPoint gpos(tk.innerPosition().X(), tk.innerPosition().Y(), tk.innerPosition().Z());
1084  GlobalVector gmom(tk.innerMomentum().X(), tk.innerMomentum().Y(), tk.innerMomentum().Z());
1085  if (dir)
1086  gmom *= -1.;
1087  GlobalTrajectoryParameters par(gpos, -gmom, tk.charge(), field);
1088  CurvilinearTrajectoryError err(tk.extra()->innerStateCovariance());
1089  return FreeTrajectoryState(par, err);
1090  }
1091 }
1092 
1094 
1095 //define this as a plug-in
static const std::string kSharedResource
Definition: TFileService.h:76
float hadEt
hcal sum-Et
Definition: MuonIsolation.h:8
double outerY() const
y coordinate of the outermost hit position
Definition: Track.h:112
Basic3DVector< float > DirectionType
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EDGetTokenT< CaloTowerCollection > tok_tower_
FreeTrajectoryState getFreeTrajectoryState(const reco::Track &tk, const MagneticField *field, int itag, bool dir)
Vector3DBase< typename PreciseFloatType< T, U >::Type, FrameTag > cross(const Vector3DBase< U, FrameTag > &v) const
Definition: Vector3DBase.h:110
float sumPt
sum-pt of tracks
Definition: MuonIsolation.h:6
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
double outerX() const
x coordinate of the outermost hit position
Definition: Track.h:109
const HcalChannelQuality * theHcalChStatus
double outerPy() const
y coordinate of momentum vector at the outermost hit position
Definition: Track.h:103
T z() const
Definition: PV3DBase.h:61
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
ReturnType plane(const PositionType &pos, const RotationType &rot) const
Definition: PlaneBuilder.h:21
std::vector< CaloTower >::const_iterator const_iterator
void produce(edm::Event &, const edm::EventSetup &) override
const HcalSeverityLevelComputer * theHcalSevLvlComputer
std::map< std::string, bool > fired
ErrorD< N >::type type
Definition: Error.h:32
edm::EDGetTokenT< reco::TrackCollection > tok_muonsCosmic_
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > tok_geom_
double outerZ() const
z coordinate of the outermost hit position
Definition: Track.h:115
void findHOEtaPhi(int iphsect, int &ietaho, int &iphiho)
Definition: Plane.h:16
T dot(const Basic3DVector &v) const
Scalar product, or "dot" product, with a vector of same type.
Geom::Theta< T > theta() const
const Item * getValues(DetId fId, bool throwOnFail=true) const
constexpr float energy() const
Definition: CaloRecHit.h:29
GlobalPoint position() const
const Double_t pi
T getUntrackedParameter(std::string const &, T const &) const
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
int charge() const
track electric charge
Definition: TrackBase.h:596
int iEvent
Definition: GenABIO.cc:224
unsigned int hoflag
edm::ESGetToken< HcalChannelQuality, HcalChannelQualityRcd > tok_hcalChStatus_
~AlCaHOCalibProducer() override=default
void applyRadX0Correction(bool applyRadX0Correction)
void fillHOStore(const reco::TrackRef &ncosm, HOCalibVariables &tmpHOCalib, std::unique_ptr< HOCalibVariableCollection > &hostore, int Noccu_old, int indx, edm::Handle< reco::TrackCollection > cosmicmuon, edm::View< reco::Muon >::const_iterator muon1, const edm::Event &iEvent, const CaloSubdetectorGeometry *, const MagneticField &)
constexpr int ieta() const
get the cell ieta
Definition: HcalDetId.h:155
T sqrt(T t)
Definition: SSEVec.h:19
Basic3DVector< float > RotationType
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
edm::EDGetTokenT< OnlineLuminosityRecord > tok_metaData_
math::Error< 5 >::type CovarianceMatrix
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Basic3DVector< float > PositionType
uint32_t getValue() const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
double outerPz() const
z coordinate of momentum vector at the outermost hit position
Definition: Track.h:106
virtual DetId getClosestCell(const GlobalPoint &r) const
edm::EDGetTokenT< LumiScalersCollection > tok_lumi_
Log< level::Info, false > LogInfo
void propagate(const SteppingHelixStateInfo &ftsStart, const Surface &sDest, SteppingHelixStateInfo &out) const
Propagate to Plane given a starting point.
edm::EDGetTokenT< reco::VertexCollection > tok_vertex_
edm::EDGetTokenT< edm::View< reco::Muon > > tok_muons_
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::EDGetTokenT< HORecHitCollection > tok_ho_
bool isValid() const
Definition: HandleBase.h:70
GlobalVector momentum() const
edm::ESGetToken< HcalSeverityLevelComputer, HcalSeverityLevelComputerRcd > tok_hcalSevLvlComputer_
AlCaHOCalibProducer(const edm::ParameterSet &)
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
constexpr HcalDetId id() const
get the id
Definition: HORecHit.h:19
double outerPx() const
x coordinate of momentum vector at the outermost hit position
Definition: Track.h:100
int getSeverityLevel(const DetId &myid, const uint32_t &myflag, const uint32_t &mystatus) const
Geom::Phi< T > phi() const
const math::XYZVector & innerMomentum() const
momentum vector at the innermost hit position
Definition: Track.h:59
Log< level::Warning, false > LogWarning
edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > tok_magField_
const math::XYZPoint & innerPosition() const
position of the innermost hit
Definition: Track.h:56
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:34
constexpr int iphi() const
get the cell iphi
Definition: HcalDetId.h:157
void setMaterialMode(bool noMaterial)
Switch for material effects mode: no material effects if true.
def move(src, dest)
Definition: eostools.py:511
edm::EDGetTokenT< HBHERecHitCollection > tok_hbhe_
math::Error< dimension >::type CovarianceMatrix
5 parameter covariance matrix
Definition: TrackBase.h:74
const TrackExtraRef & extra() const
reference to "extra" object
Definition: Track.h:139
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11