CMS 3D CMS Logo

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