File indexing completed on 2024-09-07 04:34:59
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075 #include <memory>
0076
0077
0078 #include "FWCore/Framework/interface/Frameworkfwd.h"
0079 #include "FWCore/Framework/interface/one/EDProducer.h"
0080 #include "FWCore/Framework/interface/Event.h"
0081 #include "FWCore/Framework/interface/EventSetup.h"
0082 #include "FWCore/Framework/interface/MakerMacros.h"
0083 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0084 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0085 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0086 #include "FWCore/Utilities/interface/InputTag.h"
0087
0088 #include "DataFormats/CaloTowers/interface/CaloTowerCollection.h"
0089 #include "DataFormats/HcalCalibObjects/interface/HOCalibVariables.h"
0090 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
0091 #include "DataFormats/HcalDetId/interface/HcalSubdetector.h"
0092 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
0093 #include "DataFormats/GeometrySurface/interface/PlaneBuilder.h"
0094 #include "DataFormats/Luminosity/interface/LumiDetails.h"
0095 #include "DataFormats/OnlineMetaData/interface/OnlineLuminosityRecord.h"
0096 #include "DataFormats/Math/interface/Error.h"
0097 #include "DataFormats/MuonReco/interface/Muon.h"
0098 #include "DataFormats/RecoCandidate/interface/IsoDeposit.h"
0099 #include "DataFormats/Scalers/interface/LumiScalers.h"
0100 #include "DataFormats/TrackReco/interface/Track.h"
0101 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0102 #include "DataFormats/TrajectorySeed/interface/PropagationDirection.h"
0103 #include "DataFormats/TrajectorySeed/interface/TrajectorySeedCollection.h"
0104 #include "DataFormats/VertexReco/interface/Vertex.h"
0105 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0106
0107 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
0108 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
0109 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0110 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0111 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0112 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0113
0114 #include "MagneticField/Engine/interface/MagneticField.h"
0115 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0116
0117 #include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h"
0118 #include "TrackPropagation/SteppingHelixPropagator/interface/SteppingHelixPropagator.h"
0119
0120 #include "FWCore/ServiceRegistry/interface/Service.h"
0121 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0122
0123
0124
0125 #include "RecoLocalCalo/HcalRecAlgos/interface/HcalSeverityLevelComputer.h"
0126 #include "RecoLocalCalo/HcalRecAlgos/interface/HcalSeverityLevelComputerRcd.h"
0127 #include "CondFormats/HcalObjects/interface/HcalChannelQuality.h"
0128 #include "CondFormats/DataRecord/interface/HcalChannelQualityRcd.h"
0129 #include <CLHEP/Vector/LorentzVector.h>
0130 #include <CLHEP/Units/GlobalPhysicalConstants.h>
0131 #include <CLHEP/Units/SystemOfUnits.h>
0132
0133 #include "TH2F.h"
0134
0135
0136 #include <string>
0137
0138 #include <iostream>
0139 #include <fstream>
0140
0141
0142
0143
0144 class AlCaHOCalibProducer : public edm::one::EDProducer<edm::one::SharedResources> {
0145 public:
0146 explicit AlCaHOCalibProducer(const edm::ParameterSet&);
0147 ~AlCaHOCalibProducer() override = default;
0148
0149 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0150 typedef Basic3DVector<float> PositionType;
0151 typedef Basic3DVector<float> DirectionType;
0152 typedef Basic3DVector<float> RotationType;
0153
0154 private:
0155 void produce(edm::Event&, const edm::EventSetup&) override;
0156 void beginJob() override;
0157 void endJob() override;
0158
0159 void fillHOStore(const reco::TrackRef& ncosm,
0160 HOCalibVariables& tmpHOCalib,
0161 std::unique_ptr<HOCalibVariableCollection>& hostore,
0162 int Noccu_old,
0163 int indx,
0164 edm::Handle<reco::TrackCollection> cosmicmuon,
0165 edm::View<reco::Muon>::const_iterator muon1,
0166 const edm::Event& iEvent,
0167 const CaloSubdetectorGeometry*,
0168 const MagneticField&);
0169
0170 void findHOEtaPhi(int iphsect, int& ietaho, int& iphiho);
0171
0172
0173
0174 float xhor0;
0175 float yhor0;
0176 float xhor1;
0177 float yhor1;
0178 int iring;
0179
0180 float localxhor0;
0181 float localyhor0;
0182 float localxhor1;
0183 float localyhor1;
0184
0185 TH2F* ho_occupency[5];
0186 bool m_occupancy;
0187 bool m_cosmic;
0188
0189 const int netabin = 16;
0190 const int nphimx = 72;
0191 const int netamx = 32;
0192 const int ncidmx = 5;
0193 const double rHOL0 = 382.0;
0194 const double rHOL1 = 407.0;
0195
0196 edm::InputTag muonTags_;
0197
0198 edm::EDGetTokenT<reco::TrackCollection> tok_muonsCosmic_;
0199 edm::EDGetTokenT<edm::View<reco::Muon> > tok_muons_;
0200 edm::EDGetTokenT<reco::VertexCollection> tok_vertex_;
0201
0202 edm::EDGetTokenT<LumiScalersCollection> tok_lumi_;
0203 edm::EDGetTokenT<OnlineLuminosityRecord> tok_metaData_;
0204
0205 edm::EDGetTokenT<HBHERecHitCollection> tok_hbhe_;
0206 edm::EDGetTokenT<HORecHitCollection> tok_ho_;
0207 edm::EDGetTokenT<CaloTowerCollection> tok_tower_;
0208
0209 edm::ESGetToken<HcalChannelQuality, HcalChannelQualityRcd> tok_hcalChStatus_;
0210 edm::ESGetToken<CaloGeometry, CaloGeometryRecord> tok_geom_;
0211 edm::ESGetToken<HcalSeverityLevelComputer, HcalSeverityLevelComputerRcd> tok_hcalSevLvlComputer_;
0212 edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> tok_magField_;
0213
0214 bool m_hbinfo;
0215 int m_startTS;
0216 int m_endTS;
0217 double m_sigma;
0218
0219 typedef math::Error<5>::type CovarianceMatrix;
0220 int Noccu;
0221 int nRuns;
0222
0223
0224 FreeTrajectoryState getFreeTrajectoryState(const reco::Track& tk, const MagneticField* field, int itag, bool dir);
0225
0226 unsigned int Ntp;
0227 std::map<std::string, bool> fired;
0228
0229
0230 const HcalChannelQuality* theHcalChStatus;
0231 const HcalSeverityLevelComputer* theHcalSevLvlComputer;
0232 int Nevents;
0233 };
0234
0235
0236
0237
0238
0239
0240
0241
0242
0243
0244
0245
0246 AlCaHOCalibProducer::AlCaHOCalibProducer(const edm::ParameterSet& iConfig) {
0247 usesResource(TFileService::kSharedResource);
0248
0249
0250 m_hbinfo = iConfig.getUntrackedParameter<bool>("hbinfo", false);
0251 m_sigma = iConfig.getUntrackedParameter<double>("sigma", 0.05);
0252 m_occupancy = iConfig.getUntrackedParameter<bool>("plotOccupancy", false);
0253 m_cosmic = iConfig.getUntrackedParameter<bool>("CosmicData", false);
0254
0255
0256 muonTags_ = iConfig.getUntrackedParameter<edm::InputTag>("muons");
0257 tok_muonsCosmic_ = consumes<reco::TrackCollection>(muonTags_);
0258 tok_muons_ = consumes<edm::View<reco::Muon> >(muonTags_);
0259 tok_vertex_ = consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vertexTags"));
0260
0261 tok_lumi_ = consumes<LumiScalersCollection>(iConfig.getParameter<edm::InputTag>("lumiTags"));
0262 tok_metaData_ = consumes<OnlineLuminosityRecord>(iConfig.getParameter<edm::InputTag>("metadata"));
0263 tok_ho_ = consumes<HORecHitCollection>(iConfig.getParameter<edm::InputTag>("hoInput"));
0264 tok_hbhe_ = consumes<HBHERecHitCollection>(iConfig.getParameter<edm::InputTag>("hbheInput"));
0265 tok_tower_ = consumes<CaloTowerCollection>(iConfig.getParameter<edm::InputTag>("towerInput"));
0266
0267 tok_hcalChStatus_ = esConsumes<HcalChannelQuality, HcalChannelQualityRcd>(edm::ESInputTag("", "withTopo"));
0268 tok_geom_ = esConsumes<CaloGeometry, CaloGeometryRecord>();
0269 tok_hcalSevLvlComputer_ = esConsumes<HcalSeverityLevelComputer, HcalSeverityLevelComputerRcd>();
0270 tok_magField_ = esConsumes<MagneticField, IdealMagneticFieldRecord>();
0271
0272 produces<HOCalibVariableCollection>("HOCalibVariableCollection").setBranchAlias("HOCalibVariableCollection");
0273
0274 if (m_occupancy) {
0275 edm::Service<TFileService> fs;
0276
0277 char title[200];
0278
0279 for (int ij = 0; ij < 5; ij++) {
0280 sprintf(title, "ho_occupency (>%i #sigma)", ij + 2);
0281 ho_occupency[ij] =
0282 fs->make<TH2F>(title, title, netamx + 1, -netamx - 0.5, netamx / 2 + 0.5, nphimx, 0.5, nphimx + 0.5);
0283 }
0284 }
0285 }
0286
0287
0288
0289
0290
0291 void AlCaHOCalibProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0292 edm::ParameterSetDescription desc;
0293 desc.add<edm::InputTag>("hbheInput", edm::InputTag("hbhereco"));
0294 desc.addUntracked<bool>("hotime", false);
0295 desc.addUntracked<bool>("hbinfo", false);
0296 desc.addUntracked<double>("sigma", 1.0);
0297 desc.addUntracked<bool>("plotOccupancy", false);
0298 desc.addUntracked<bool>("CosmicData", false);
0299 desc.add<edm::InputTag>("hoInput", edm::InputTag("horeco"));
0300 desc.add<edm::InputTag>("towerInput", edm::InputTag("towerMaker"));
0301 desc.addUntracked<std::string>("RootFileName", "test.root");
0302 desc.addUntracked<double>("m_scale", 4.0);
0303 desc.addUntracked<bool>("debug", false);
0304 desc.addUntracked<edm::InputTag>("muons", edm::InputTag("muons"));
0305 desc.add<edm::InputTag>("vertexTags", edm::InputTag("offlinePrimaryVertices"));
0306 desc.add<edm::InputTag>("lumiTags", edm::InputTag("scalersRawToDigi"));
0307 desc.add<edm::InputTag>("metadata", edm::InputTag("onlineMetaDataDigis"));
0308 descriptions.add("alcaHOCalibProducer", desc);
0309 }
0310
0311
0312 void AlCaHOCalibProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0313 int irun = iEvent.id().run();
0314
0315
0316 Nevents++;
0317
0318 if (Nevents % 5000 == 1)
0319 edm::LogInfo("HOCalib") << "AlCaHOCalibProducer Processing event # " << Nevents << " " << Noccu << " " << irun
0320 << " " << iEvent.id().event();
0321
0322 theHcalChStatus = &iSetup.getData(tok_hcalChStatus_);
0323
0324 auto hostore = std::make_unique<HOCalibVariableCollection>();
0325
0326 edm::Handle<reco::TrackCollection> cosmicmuon;
0327 edm::Handle<edm::View<reco::Muon> > collisionmuon;
0328
0329 bool muonOK(true);
0330 HOCalibVariables tmpHOCalib;
0331 tmpHOCalib.nprim = -1;
0332 tmpHOCalib.pileup = -1.;
0333
0334 if (m_cosmic) {
0335 cosmicmuon = iEvent.getHandle(tok_muonsCosmic_);
0336 muonOK = (cosmicmuon.isValid() && !cosmicmuon->empty());
0337 } else {
0338 collisionmuon = iEvent.getHandle(tok_muons_);
0339 muonOK = (collisionmuon.isValid() && !collisionmuon->empty());
0340
0341 if (iEvent.isRealData()) {
0342 auto const& primaryVertices = iEvent.getHandle(tok_vertex_);
0343 if (primaryVertices.isValid()) {
0344 tmpHOCalib.nprim = primaryVertices->size();
0345 }
0346
0347 tmpHOCalib.pileup = 0.;
0348
0349 auto const& lumiScale = iEvent.getHandle(tok_lumi_);
0350 auto const& metaData = iEvent.getHandle(tok_metaData_);
0351
0352
0353 if (metaData.isValid()) {
0354 tmpHOCalib.pileup = metaData->avgPileUp();
0355 } else if (lumiScale.isValid() && !lumiScale->empty()) {
0356 if (lumiScale->begin() != lumiScale->end()) {
0357 tmpHOCalib.pileup = lumiScale->begin()->pileup();
0358 }
0359 } else {
0360 edm::LogWarning("HOCalib") << "Neither LumiScalers nor OnlineMetadata collections found in the event";
0361 }
0362 }
0363 }
0364
0365 if (muonOK) {
0366 int Noccu_old = Noccu;
0367 edm::View<reco::Muon>::const_iterator muon1;
0368
0369 theHcalSevLvlComputer = &iSetup.getData(tok_hcalSevLvlComputer_);
0370
0371 MagneticField const& magField = iSetup.getData(tok_magField_);
0372
0373 const CaloGeometry& geo = iSetup.getData(tok_geom_);
0374 const CaloSubdetectorGeometry* gHO = geo.getSubdetectorGeometry(DetId::Hcal, HcalOuter);
0375
0376 if (m_cosmic) {
0377 int indx(0);
0378 for (reco::TrackCollection::const_iterator ncosm = cosmicmuon->begin(); ncosm != cosmicmuon->end();
0379 ++ncosm, ++indx) {
0380 if ((*ncosm).ndof() < 15)
0381 continue;
0382 if ((*ncosm).normalizedChi2() > 30.0)
0383 continue;
0384 reco::TrackRef tRef = reco::TrackRef(cosmicmuon, indx);
0385 fillHOStore(tRef, tmpHOCalib, hostore, Noccu_old, indx, cosmicmuon, muon1, iEvent, gHO, magField);
0386 }
0387 } else {
0388 for (muon1 = collisionmuon->begin(); muon1 < collisionmuon->end(); muon1++) {
0389 if ((!muon1->isGlobalMuon()) || (!muon1->isTrackerMuon()))
0390 continue;
0391 reco::TrackRef ncosm = muon1->innerTrack();
0392 fillHOStore(ncosm, tmpHOCalib, hostore, Noccu_old, 0, cosmicmuon, muon1, iEvent, gHO, magField);
0393 }
0394 }
0395 }
0396
0397 iEvent.put(std::move(hostore), "HOCalibVariableCollection");
0398 }
0399
0400
0401 void AlCaHOCalibProducer::beginJob() {
0402 Nevents = 0;
0403 nRuns = 0;
0404 Noccu = 0;
0405 }
0406
0407
0408 void AlCaHOCalibProducer::endJob() {
0409 if (m_occupancy) {
0410 for (int ij = 0; ij < 5; ij++) {
0411 ho_occupency[ij]->Scale(1. / std::max(1, Noccu));
0412 }
0413 }
0414 edm::LogInfo("HOCalib") << " AlCaHOCalibProducer processed event " << Nevents;
0415 }
0416
0417 void AlCaHOCalibProducer::fillHOStore(const reco::TrackRef& ncosm,
0418 HOCalibVariables& tmpHOCalib,
0419 std::unique_ptr<HOCalibVariableCollection>& hostore,
0420 int Noccu_old,
0421 int indx,
0422 edm::Handle<reco::TrackCollection> cosmicmuon,
0423 edm::View<reco::Muon>::const_iterator muon1,
0424 const edm::Event& iEvent,
0425 const CaloSubdetectorGeometry* gHO,
0426 const MagneticField& magField) {
0427
0428
0429 int charge = ncosm->charge();
0430
0431 double innerr = (*ncosm).innerPosition().Perp2();
0432 double outerr = (*ncosm).outerPosition().Perp2();
0433 int iiner = (innerr < outerr) ? 1 : 0;
0434
0435
0436
0437
0438
0439
0440
0441
0442
0443
0444 double posx, posy, posz;
0445 double momx, momy, momz;
0446
0447 if (iiner == 1) {
0448 posx = (*ncosm).innerPosition().X();
0449 posy = (*ncosm).innerPosition().Y();
0450 posz = (*ncosm).innerPosition().Z();
0451
0452 momx = (*ncosm).innerMomentum().X();
0453 momy = (*ncosm).innerMomentum().Y();
0454 momz = (*ncosm).innerMomentum().Z();
0455
0456 } else {
0457 posx = (*ncosm).outerPosition().X();
0458 posy = (*ncosm).outerPosition().Y();
0459 posz = (*ncosm).outerPosition().Z();
0460
0461 momx = (*ncosm).outerMomentum().X();
0462 momy = (*ncosm).outerMomentum().Y();
0463 momz = (*ncosm).outerMomentum().Z();
0464 }
0465
0466 PositionType trkpos(posx, posy, posz);
0467
0468 CLHEP::Hep3Vector tmpmuon3v(posx, posy, posz);
0469 CLHEP::Hep3Vector tmpmuondir(momx, momy, momz);
0470
0471 bool samedir = (tmpmuon3v.dot(tmpmuondir) > 0) ? true : false;
0472 for (int ij = 0; ij < 3; ij++) {
0473 tmpHOCalib.caloen[ij] = 0.0;
0474 }
0475 int inearbymuon = 0;
0476 localxhor0 = localyhor0 = 20000;
0477
0478 if (m_cosmic) {
0479 int ind(0);
0480 for (reco::TrackCollection::const_iterator ncosmcor = cosmicmuon->begin(); ncosmcor != cosmicmuon->end();
0481 ++ncosmcor, ++ind) {
0482 if (indx == ind)
0483 continue;
0484 CLHEP::Hep3Vector tmpmuon3vcor;
0485 CLHEP::Hep3Vector tmpmom3v;
0486 if (iiner == 1) {
0487 tmpmuon3vcor = CLHEP::Hep3Vector(
0488 (*ncosmcor).innerPosition().X(), (*ncosmcor).innerPosition().Y(), (*ncosmcor).innerPosition().Z());
0489 tmpmom3v = CLHEP::Hep3Vector(
0490 (*ncosmcor).innerMomentum().X(), (*ncosmcor).innerMomentum().Y(), (*ncosmcor).innerMomentum().Z());
0491 } else {
0492 tmpmuon3vcor = CLHEP::Hep3Vector(
0493 (*ncosmcor).outerPosition().X(), (*ncosmcor).outerPosition().Y(), (*ncosmcor).outerPosition().Z());
0494 tmpmom3v = CLHEP::Hep3Vector(
0495 (*ncosmcor).outerMomentum().X(), (*ncosmcor).outerMomentum().Y(), (*ncosmcor).outerMomentum().Z());
0496 }
0497
0498 if (tmpmom3v.mag() < 0.2 || (*ncosmcor).ndof() < 5)
0499 continue;
0500
0501 double angle = tmpmuon3v.angle(tmpmuon3vcor);
0502 if (angle < 7.5 * CLHEP::deg) {
0503 inearbymuon = 1;
0504 }
0505
0506
0507 if (angle < 7.5 * CLHEP::deg) {
0508 tmpHOCalib.caloen[0] += 1.;
0509 }
0510 if (angle < 15.0 * CLHEP::deg) {
0511 tmpHOCalib.caloen[1] += 1.;
0512 }
0513 if (angle < 35.0 * CLHEP::deg) {
0514 tmpHOCalib.caloen[2] += 1.;
0515 }
0516 }
0517 } else {
0518
0519 auto const& calotower = iEvent.getHandle(tok_tower_);
0520
0521 for (CaloTowerCollection::const_iterator calt = calotower->begin(); calt != calotower->end(); calt++) {
0522
0523 double ith = (*calt).momentum().theta();
0524 double iph = (*calt).momentum().phi();
0525
0526 CLHEP::Hep3Vector calo3v(sin(ith) * cos(iph), sin(ith) * sin(iph), cos(ith));
0527
0528 double angle = tmpmuon3v.angle(calo3v);
0529
0530 if (angle < 7.5 * CLHEP::deg) {
0531 tmpHOCalib.caloen[0] += calt->emEnergy() + calt->hadEnergy();
0532 }
0533 if (angle < 15 * CLHEP::deg) {
0534 tmpHOCalib.caloen[1] += calt->emEnergy() + calt->hadEnergy();
0535 }
0536 if (angle < 35 * CLHEP::deg) {
0537 tmpHOCalib.caloen[2] += calt->emEnergy() + calt->hadEnergy();
0538 }
0539 }
0540 }
0541 if ((m_cosmic) || (tmpHOCalib.caloen[0] <= 10.0)) {
0542 GlobalPoint glbpt(posx, posy, posz);
0543
0544 double mom = sqrt(momx * momx + momy * momy + momz * momz);
0545
0546 momx /= mom;
0547 momy /= mom;
0548 momz /= mom;
0549
0550 DirectionType trkdir(momx, momy, momz);
0551
0552 tmpHOCalib.trkdr = (*ncosm).d0();
0553 tmpHOCalib.trkdz = (*ncosm).dz();
0554 tmpHOCalib.nmuon = (m_cosmic) ? cosmicmuon->size() : 1;
0555 tmpHOCalib.trkvx = glbpt.x();
0556 tmpHOCalib.trkvy = glbpt.y();
0557 tmpHOCalib.trkvz = glbpt.z();
0558 tmpHOCalib.trkmm = mom * charge;
0559 tmpHOCalib.trkth = trkdir.theta();
0560 tmpHOCalib.trkph = trkdir.phi();
0561 tmpHOCalib.isect2 = -2;
0562 tmpHOCalib.isect = -2;
0563 tmpHOCalib.hodx = -100;
0564 tmpHOCalib.hody = -100;
0565 tmpHOCalib.hoang = -2.0;
0566 tmpHOCalib.momatho = -2;
0567 tmpHOCalib.ndof = (inearbymuon == 0) ? (int)(*ncosm).ndof() : -(int)(*ncosm).ndof();
0568 tmpHOCalib.chisq = (*ncosm).normalizedChi2();
0569 if (!m_cosmic) {
0570 reco::MuonEnergy muonenr = muon1->calEnergy();
0571 reco::MuonIsolation iso03 = muon1->isolationR03();
0572 reco::MuonIsolation iso05 = muon1->isolationR05();
0573
0574 tmpHOCalib.tkpt03 = iso03.sumPt;
0575 tmpHOCalib.ecal03 = iso05.sumPt;
0576 tmpHOCalib.hcal03 = iso03.hadEt + muonenr.had;
0577 }
0578 tmpHOCalib.therr = 0.;
0579 tmpHOCalib.pherr = 0.;
0580 if (iiner == 1) {
0581 reco::TrackBase::CovarianceMatrix innercov = (*ncosm).innerStateCovariance();
0582 tmpHOCalib.therr = innercov(1, 1);
0583 tmpHOCalib.pherr = innercov(2, 2);
0584 } else {
0585 reco::TrackBase::CovarianceMatrix outercov = (*ncosm).outerStateCovariance();
0586 tmpHOCalib.therr = outercov(1, 1);
0587 tmpHOCalib.pherr = outercov(2, 2);
0588 }
0589
0590 SteppingHelixPropagator myHelix(&magField, anyDirection);
0591 myHelix.setMaterialMode(false);
0592 myHelix.applyRadX0Correction(true);
0593 double phiho = trkpos.phi();
0594 if (phiho < 0)
0595 phiho += CLHEP::twopi;
0596
0597 int iphisect_dt = int(6 * (phiho + 10.0 * CLHEP::deg) / CLHEP::pi);
0598 if (iphisect_dt >= 12)
0599 iphisect_dt = 0;
0600
0601 int iphisect = -1;
0602 bool ipath = false;
0603 for (int kl = 0; kl <= 2; kl++) {
0604 int iphisecttmp = (kl < 2) ? iphisect_dt + kl : iphisect_dt - 1;
0605 if (iphisecttmp < 0)
0606 iphisecttmp = 11;
0607 if (iphisecttmp >= 12)
0608 iphisecttmp = 0;
0609
0610 double phipos = iphisecttmp * CLHEP::pi / 6.;
0611 double phirot = phipos;
0612
0613 GlobalVector xLocal(-sin(phirot), cos(phirot), 0.);
0614 GlobalVector yLocal(0., 0., 1.);
0615 GlobalVector zLocal = xLocal.cross(yLocal).unit();
0616
0617
0618 FreeTrajectoryState freetrajectorystate_ = getFreeTrajectoryState(*ncosm, &(magField), iiner, samedir);
0619
0620 Surface::RotationType rot(xLocal, yLocal, zLocal);
0621
0622 for (int ik = 1; ik >= 0; ik--) {
0623
0624 double radial = rHOL1;
0625 if (ik == 0)
0626 radial = rHOL0;
0627
0628 Surface::PositionType pos(radial * cos(phipos), radial * sin(phipos), 0.);
0629 PlaneBuilder::ReturnType aPlane = PlaneBuilder().plane(pos, rot);
0630
0631 auto aPlane2 = new Plane(pos, rot);
0632
0633 SteppingHelixStateInfo steppingHelixstateinfo_;
0634 myHelix.propagate(SteppingHelixStateInfo(freetrajectorystate_), (*aPlane2), steppingHelixstateinfo_);
0635
0636 if (steppingHelixstateinfo_.isValid()) {
0637 GlobalPoint hotrkpos2xx(steppingHelixstateinfo_.position().x(),
0638 steppingHelixstateinfo_.position().y(),
0639 steppingHelixstateinfo_.position().z());
0640
0641 if (ik == 1) {
0642 HcalDetId ClosestCell = (HcalDetId)gHO->getClosestCell(hotrkpos2xx);
0643 int ixeta = ClosestCell.ieta();
0644 int ixphi = ClosestCell.iphi();
0645 tmpHOCalib.isect2 = 100 * std::abs(ixeta + 50) + std::abs(ixphi);
0646 }
0647
0648 GlobalVector hotrkpos2(steppingHelixstateinfo_.position().x(),
0649 steppingHelixstateinfo_.position().y(),
0650 steppingHelixstateinfo_.position().z());
0651 CLHEP::Hep3Vector hotrkdir2(steppingHelixstateinfo_.momentum().x(),
0652 steppingHelixstateinfo_.momentum().y(),
0653 steppingHelixstateinfo_.momentum().z());
0654
0655 LocalVector lclvt0 = (*aPlane).toLocal(hotrkpos2);
0656
0657 double xx = lclvt0.x();
0658 double yy = lclvt0.y();
0659
0660 if (ik == 1) {
0661 if ((std::abs(yy) < 130 && xx > -64.7 && xx < 138.2)
0662 || (std::abs(yy) > 130 && std::abs(yy) < 700 && xx > -76.3 && xx < 140.5)) {
0663 ipath = true;
0664 iphisect = iphisecttmp;
0665 }
0666 }
0667
0668 if (iphisect != iphisecttmp)
0669 continue;
0670
0671 switch (ik) {
0672 case 0:
0673 xhor0 = xx;
0674 yhor0 = yy;
0675 break;
0676 case 1:
0677 xhor1 = xx;
0678 yhor1 = yy;
0679 tmpHOCalib.momatho = hotrkdir2.mag();
0680 tmpHOCalib.hoang = CLHEP::Hep3Vector(zLocal.x(), zLocal.y(), zLocal.z()).dot(hotrkdir2.unit());
0681 break;
0682 default:
0683 break;
0684 }
0685 } else {
0686 break;
0687 }
0688 }
0689 if (ipath)
0690 break;
0691 }
0692 if (ipath) {
0693
0694 int ietaho = 50;
0695 int iphiho = -1;
0696
0697 for (int ij = 0; ij < 9; ij++) {
0698 tmpHOCalib.hosig[ij] = -100.0;
0699 }
0700 for (int ij = 0; ij < 18; ij++) {
0701 tmpHOCalib.hocorsig[ij] = -100.0;
0702 }
0703 for (int ij = 0; ij < 9; ij++) {
0704 tmpHOCalib.hbhesig[ij] = -100.0;
0705 }
0706 tmpHOCalib.hocro = -100;
0707 tmpHOCalib.htime = -1000;
0708
0709 int isect = 0;
0710
0711 findHOEtaPhi(iphisect, ietaho, iphiho);
0712
0713 if (ietaho != 0 && iphiho != 0 && std::abs(iring) <= 2) {
0714 isect = 100 * std::abs(ietaho + 50) + std::abs(iphiho);
0715 if (std::abs(ietaho) >= netabin || iphiho < 0)
0716 isect *= -1;
0717 if (std::abs(ietaho) >= netabin)
0718 isect -= 1000000;
0719 if (iphiho < 0)
0720 isect -= 2000000;
0721 tmpHOCalib.isect = isect;
0722
0723 tmpHOCalib.hodx = localxhor1;
0724 tmpHOCalib.hody = localyhor1;
0725
0726 if (iring == 0) {
0727 tmpHOCalib.hocorsig[8] = localxhor0;
0728 tmpHOCalib.hocorsig[9] = localyhor0;
0729 }
0730
0731 int etamn = -4;
0732 int etamx = 4;
0733 if (iring == 1) {
0734 etamn = 5;
0735 etamx = 10;
0736 }
0737 if (iring == 2) {
0738 etamn = 11;
0739 etamx = 16;
0740 }
0741 if (iring == -1) {
0742 etamn = -10;
0743 etamx = -5;
0744 }
0745 if (iring == -2) {
0746 etamn = -16;
0747 etamx = -11;
0748 }
0749
0750 int phimn = 1;
0751 int phimx = 2;
0752 if (iring == 0) {
0753 phimx = 2 * int((iphiho + 1) / 2.);
0754 phimn = phimx - 1;
0755 } else {
0756 phimn = 3 * int((iphiho + 1) / 3.) - 1;
0757 phimx = phimn + 2;
0758 }
0759
0760 if (phimn < 1)
0761 phimn += nphimx;
0762 if (phimx > 72)
0763 phimx -= nphimx;
0764
0765 if (m_hbinfo) {
0766 for (int ij = 0; ij < 9; ij++) {
0767 tmpHOCalib.hbhesig[ij] = -100.0;
0768 }
0769
0770 auto const& hbheht = iEvent.getHandle(tok_hbhe_);
0771 if (!(*hbheht).empty()) {
0772 if ((*hbheht).empty())
0773 throw (int)(*hbheht).size();
0774
0775 for (HBHERecHitCollection::const_iterator jk = (*hbheht).begin(); jk != (*hbheht).end(); jk++) {
0776 HcalDetId id = (*jk).id();
0777 int tmpeta = id.ieta();
0778 int tmpphi = id.iphi();
0779
0780 int deta = tmpeta - ietaho;
0781 if (tmpeta < 0 && ietaho > 0)
0782 deta += 1;
0783 if (tmpeta > 0 && ietaho < 0)
0784 deta -= 1;
0785
0786
0787
0788
0789 int dphi = tmpphi - iphiho;
0790 if (dphi > nphimx / 2) {
0791 dphi -= nphimx;
0792 }
0793 if (dphi < -nphimx / 2) {
0794 dphi += nphimx;
0795 }
0796
0797
0798
0799
0800
0801
0802 if (m_occupancy) {
0803 float signal = (*jk).energy();
0804
0805 if (signal > -100 && Noccu == Noccu_old) {
0806 for (int ij = 0; ij < 5; ij++) {
0807 if (signal > (ij + 2) * m_sigma) {
0808 ho_occupency[ij]->Fill(tmpeta, tmpphi);
0809 }
0810 }
0811 }
0812 }
0813
0814 int ipass2 = (std::abs(deta) <= 1 && std::abs(dphi) <= 1) ? 1 : 0;
0815 if (ipass2 == 0)
0816 continue;
0817
0818 float signal = (*jk).energy();
0819
0820 if (3 * (deta + 1) + dphi + 1 < 9)
0821 tmpHOCalib.hbhesig[3 * (deta + 1) + dphi + 1] = signal;
0822 }
0823 }
0824 }
0825
0826 auto const& hoht = iEvent.getHandle(tok_ho_);
0827
0828 if (!(*hoht).empty()) {
0829 for (HORecHitCollection::const_iterator jk = (*hoht).begin(); jk != (*hoht).end(); jk++) {
0830 HcalDetId id = (*jk).id();
0831 int tmpeta = id.ieta();
0832 int tmpphi = id.iphi();
0833
0834 int ipass1 = 0;
0835 if (tmpeta >= etamn && tmpeta <= etamx) {
0836 if (phimn < phimx) {
0837 ipass1 = (tmpphi >= phimn && tmpphi <= phimx) ? 1 : 0;
0838 } else {
0839 ipass1 = (tmpphi == 71 || tmpphi == 72 || tmpphi == 1) ? 1 : 0;
0840 }
0841 }
0842
0843 int deta = tmpeta - ietaho;
0844 int dphi = tmpphi - iphiho;
0845
0846 if (tmpeta < 0 && ietaho > 0)
0847 deta += 1;
0848 if (tmpeta > 0 && ietaho < 0)
0849 deta -= 1;
0850
0851
0852
0853 if (dphi > nphimx / 2) {
0854 dphi -= nphimx;
0855 }
0856 if (dphi < -nphimx / 2) {
0857 dphi += nphimx;
0858 }
0859
0860
0861
0862
0863
0864 float signal = (*jk).energy();
0865
0866 int ipass2 = (std::abs(deta) <= 1 && std::abs(dphi) <= 1) ? 1 : 0;
0867
0868 if (ipass1 == 0 && ipass2 == 0)
0869 continue;
0870
0871 if (ipass1 == 1) {
0872 int tmpdph = tmpphi - phimn;
0873 if (tmpdph < 0)
0874 tmpdph = 2;
0875
0876 int ilog = 2 * (tmpeta - etamn) + tmpdph;
0877 if (iring != 0) {
0878 if (iring > 0) {
0879 ilog = 3 * (tmpeta - etamn) + tmpdph;
0880 } else {
0881 ilog = 3 * (etamx - tmpeta) + tmpdph;
0882 }
0883 }
0884 if (ilog > -1 && ilog < 18) {
0885 tmpHOCalib.hocorsig[ilog] = signal;
0886 }
0887 }
0888
0889 if (ipass2 == 1) {
0890 if (3 * (deta + 1) + dphi + 1 < 9) {
0891 tmpHOCalib.hosig[3 * (deta + 1) + dphi + 1] = signal;
0892 }
0893 }
0894
0895 if (deta == 0 && dphi == 0) {
0896 tmpHOCalib.htime = (*jk).time();
0897 tmpHOCalib.hoflag = (*jk).flags();
0898
0899
0900 unsigned theStatusValue = theHcalChStatus->getValues(id)->getValue();
0901
0902 int hitSeverity = theHcalSevLvlComputer->getSeverityLevel(id, (*jk).flags(), theStatusValue);
0903 tmpHOCalib.hoflag = hitSeverity;
0904 int crphi = tmpphi + 6;
0905 if (crphi > 72)
0906 crphi -= 72;
0907
0908 for (HORecHitCollection::const_iterator jcr = (*hoht).begin(); jcr != (*hoht).end(); jcr++) {
0909 const HORecHit reccr = (const HORecHit)(*jcr);
0910 HcalDetId idcr = reccr.id();
0911 int etacr = idcr.ieta();
0912 int phicr = idcr.iphi();
0913 if (tmpeta == etacr && crphi == phicr) {
0914 tmpHOCalib.hocro = reccr.energy();
0915 }
0916 }
0917 }
0918 }
0919 }
0920 }
0921
0922
0923 if (Noccu == Noccu_old)
0924 Noccu++;
0925 hostore->push_back(tmpHOCalib);
0926 }
0927 }
0928 }
0929
0930 void AlCaHOCalibProducer::findHOEtaPhi(int iphisect, int& ietaho, int& iphiho) {
0931
0932
0933 const double etalow[16] = {0.025,
0934 35.195,
0935 70.625,
0936 106.595,
0937 141.565,
0938 180.765,
0939 220.235,
0940 261.385,
0941 304.525,
0942 349.975,
0943 410.025,
0944 452.085,
0945 506.645,
0946 565.025,
0947 627.725,
0948 660.25};
0949 const double etahgh[16] = {35.145,
0950 70.575,
0951 106.545,
0952 125.505,
0953 180.715,
0954 220.185,
0955 261.335,
0956 304.475,
0957 349.925,
0958 392.575,
0959 452.035,
0960 506.595,
0961 564.975,
0962 627.675,
0963 661.075,
0964 700.25};
0965
0966 const double philow[6] = {-76.27, -35.11, 0.35, 35.81, 71.77, 108.93};
0967 const double phihgh[6] = {-35.81, -0.35, 35.11, 71.07, 108.23, 140.49};
0968
0969 const double philow00[6] = {-60.27, -32.91, 0.35, 33.61, 67.37, 102.23};
0970 const double phihgh00[6] = {-33.61, -0.35, 32.91, 66.67, 101.53, 129.49};
0971
0972 const double philow01[6] = {-64.67, -34.91, 0.35, 35.61, 71.37, 108.33};
0973 const double phihgh01[6] = {-35.61, -0.35, 34.91, 70.67, 107.63, 138.19};
0974
0975 iring = -10;
0976
0977 double tmpdy = std::abs(yhor1);
0978 for (int ij = 0; ij < netabin; ij++) {
0979 if (tmpdy > etalow[ij] && tmpdy < etahgh[ij]) {
0980 ietaho = ij + 1;
0981 float tmp1 = fabs(tmpdy - etalow[ij]);
0982 float tmp2 = fabs(tmpdy - etahgh[ij]);
0983
0984 localyhor1 = (tmp1 < tmp2) ? -tmp1 : tmp2;
0985 if (yhor1 < 0)
0986 localyhor1 *= -1.;
0987
0988 if (ij < 4)
0989 iring = 0;
0990 if (ij >= 4 && ij < 10)
0991 iring = 1;
0992 if (ij >= 10 && ij < netabin)
0993 iring = 2;
0994 break;
0995 }
0996 }
0997
0998 int tmpphi = 0;
0999 int tmpphi0 = 0;
1000
1001 if (ietaho > 4) {
1002 for (int ij = 0; ij < 6; ij++) {
1003 if (xhor1 > philow[ij] && xhor1 < phihgh[ij]) {
1004 tmpphi = ij + 1;
1005 float tmp1 = fabs(xhor1 - philow[ij]);
1006 float tmp2 = fabs(xhor1 - phihgh[ij]);
1007 localxhor1 = (tmp1 < tmp2) ? -tmp1 : tmp2;
1008 break;
1009 }
1010 }
1011 } else {
1012 for (int ij = 0; ij < 6; ij++) {
1013 if (xhor1 > philow01[ij] && xhor1 < phihgh01[ij]) {
1014 tmpphi = ij + 1;
1015 float tmp1 = fabs(xhor1 - philow01[ij]);
1016 float tmp2 = fabs(xhor1 - phihgh01[ij]);
1017 localxhor1 = (tmp1 < tmp2) ? -tmp1 : tmp2;
1018 break;
1019 }
1020 }
1021
1022 for (int ij = 0; ij < 6; ij++) {
1023 if (xhor0 > philow00[ij] && xhor0 < phihgh00[ij]) {
1024 tmpphi0 = ij + 1;
1025 float tmp1 = fabs(xhor0 - philow00[ij]);
1026 float tmp2 = fabs(xhor0 - phihgh00[ij]);
1027 localxhor0 = (tmp1 < tmp2) ? -tmp1 : tmp2;
1028 if (tmpphi != tmpphi0)
1029 localxhor0 += 10000.;
1030 break;
1031 }
1032 }
1033
1034 double tmpdy = std::abs(yhor0);
1035 for (int ij = 0; ij < 4; ij++) {
1036 if (tmpdy > etalow[ij] && tmpdy < etahgh[ij]) {
1037 float tmp1 = fabs(tmpdy - etalow[ij]);
1038 float tmp2 = fabs(tmpdy - etahgh[ij]);
1039 localyhor0 = (tmp1 < tmp2) ? -tmp1 : tmp2;
1040 if (yhor0 < 0)
1041 localyhor0 *= -1.;
1042 if (ij + 1 != ietaho)
1043 localyhor0 += 10000.;
1044 break;
1045 }
1046 }
1047 }
1048
1049 if (tmpphi != 0) {
1050 iphiho = 6 * iphisect - 2 + tmpphi;
1051 if (iphiho <= 0)
1052 iphiho += nphimx;
1053 if (iphiho > nphimx)
1054 iphiho -= nphimx;
1055 }
1056
1057
1058
1059 if (yhor1 < 0) {
1060 if (std::abs(ietaho) > netabin) {
1061 ietaho += 1;
1062 } else {
1063 ietaho *= -1;
1064 }
1065
1066 iring *= -1;
1067 }
1068 }
1069
1070 FreeTrajectoryState AlCaHOCalibProducer::getFreeTrajectoryState(const reco::Track& tk,
1071 const MagneticField* field,
1072 int iiner,
1073 bool dir) {
1074 if (iiner == 0) {
1075 GlobalPoint gpos(tk.outerX(), tk.outerY(), tk.outerZ());
1076 GlobalVector gmom(tk.outerPx(), tk.outerPy(), tk.outerPz());
1077 if (dir)
1078 gmom *= -1.;
1079 GlobalTrajectoryParameters par(gpos, gmom, tk.charge(), field);
1080 CurvilinearTrajectoryError err(tk.extra()->outerStateCovariance());
1081 return FreeTrajectoryState(par, err);
1082 } else {
1083 GlobalPoint gpos(tk.innerPosition().X(), tk.innerPosition().Y(), tk.innerPosition().Z());
1084 GlobalVector gmom(tk.innerMomentum().X(), tk.innerMomentum().Y(), tk.innerMomentum().Z());
1085 if (dir)
1086 gmom *= -1.;
1087 GlobalTrajectoryParameters par(gpos, -gmom, tk.charge(), field);
1088 CurvilinearTrajectoryError err(tk.extra()->innerStateCovariance());
1089 return FreeTrajectoryState(par, err);
1090 }
1091 }
1092
1093 #include "FWCore/Framework/interface/MakerMacros.h"
1094
1095
1096 DEFINE_FWK_MODULE(AlCaHOCalibProducer);