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