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