13 #include "TDirectory.h"
15 #include "TLorentzVector.h"
16 #include "TInterpreter.h"
104 std::array<int, 3>
fillTree(std::vector<math::XYZTLorentzVector>& vecL1,
105 std::vector<math::XYZTLorentzVector>& vecL3,
107 std::vector<spr::propagatedTrackDirection>& trkCaloDirections,
108 std::vector<spr::propagatedTrackID>& trkCaloDets,
128 const std::vector<DetId>& ids,
129 std::vector<double>& edet,
131 std::vector<unsigned int>* detIds,
132 std::vector<double>* hitEnergies);
214 theTrackQuality_(iConfig.getParameter<
std::
string>(
"trackQuality")),
215 processName_(iConfig.getParameter<
std::
string>(
"processName")),
216 l1Filter_(iConfig.getParameter<
std::
string>(
"l1Filter")),
217 l2Filter_(iConfig.getParameter<
std::
string>(
"l2Filter")),
218 l3Filter_(iConfig.getParameter<
std::
string>(
"l3Filter")),
219 a_coneR_(iConfig.getParameter<double>(
"coneRadius")),
220 a_mipR_(iConfig.getParameter<double>(
"coneRadiusMIP")),
221 a_mipR2_(iConfig.getParameter<double>(
"coneRadiusMIP2")),
222 a_mipR3_(iConfig.getParameter<double>(
"coneRadiusMIP3")),
223 a_mipR4_(iConfig.getParameter<double>(
"coneRadiusMIP4")),
224 a_mipR5_(iConfig.getParameter<double>(
"coneRadiusMIP5")),
225 pTrackMin_(iConfig.getParameter<double>(
"minimumTrackP")),
226 eEcalMax_(iConfig.getParameter<double>(
"maximumEcalEnergy")),
227 maxRestrictionP_(iConfig.getParameter<double>(
"maxTrackP")),
228 slopeRestrictionP_(iConfig.getParameter<double>(
"slopeTrackP")),
229 hcalScale_(iConfig.getUntrackedParameter<double>(
"hHcalScale", 1.0)),
230 eIsolate1_(iConfig.getParameter<double>(
"isolationEnergyTight")),
231 eIsolate2_(iConfig.getParameter<double>(
"isolationEnergyLoose")),
232 pTrackLow_(iConfig.getParameter<double>(
"momentumLow")),
233 pTrackHigh_(iConfig.getParameter<double>(
"momentumHigh")),
234 prescaleLow_(iConfig.getParameter<
int>(
"prescaleLow")),
235 prescaleHigh_(iConfig.getParameter<
int>(
"prescaleHigh")),
236 useRaw_(iConfig.getUntrackedParameter<
int>(
"useRaw", 0)),
237 dataType_(iConfig.getUntrackedParameter<
int>(
"dataType", 0)),
238 mode_(iConfig.getUntrackedParameter<
int>(
"outMode", 11)),
239 ignoreTrigger_(iConfig.getUntrackedParameter<
bool>(
"ignoreTriggers",
false)),
240 useL1Trigger_(iConfig.getUntrackedParameter<
bool>(
"useL1Trigger",
false)),
241 unCorrect_(iConfig.getUntrackedParameter<
bool>(
"unCorrect",
false)),
242 collapseDepth_(iConfig.getUntrackedParameter<
bool>(
"collapseDepth",
false)),
243 hitEthrEB_(iConfig.getParameter<double>(
"EBHitEnergyThreshold")),
244 hitEthrEE0_(iConfig.getParameter<double>(
"EEHitEnergyThreshold0")),
245 hitEthrEE1_(iConfig.getParameter<double>(
"EEHitEnergyThreshold1")),
246 hitEthrEE2_(iConfig.getParameter<double>(
"EEHitEnergyThreshold2")),
247 hitEthrEE3_(iConfig.getParameter<double>(
"EEHitEnergyThreshold3")),
248 hitEthrEELo_(iConfig.getParameter<double>(
"EEHitEnergyThresholdLow")),
249 hitEthrEEHi_(iConfig.getParameter<double>(
"EEHitEnergyThresholdHigh")),
250 triggerEvent_(iConfig.getParameter<
edm::
InputTag>(
"labelTriggerEvent")),
251 theTriggerResultsLabel_(iConfig.getParameter<
edm::
InputTag>(
"labelTriggerResult")),
252 labelGenTrack_(iConfig.getParameter<
std::
string>(
"labelTrack")),
253 labelRecVtx_(iConfig.getParameter<
std::
string>(
"labelVertex")),
254 labelEB_(iConfig.getParameter<
std::
string>(
"labelEBRecHit")),
255 labelEE_(iConfig.getParameter<
std::
string>(
"labelEERecHit")),
256 labelHBHE_(iConfig.getParameter<
std::
string>(
"labelHBHERecHit")),
257 labelTower_(iConfig.getParameter<
std::
string>(
"labelCaloTower")),
258 l1TrigName_(iConfig.getUntrackedParameter<
std::
string>(
"l1TrigName",
"L1_SingleJet60")),
259 oldID_(iConfig.getUntrackedParameter<
std::
vector<
int> >(
"oldID")),
260 newDepth_(iConfig.getUntrackedParameter<
std::
vector<
int> >(
"newDepth")),
261 hep17_(iConfig.getUntrackedParameter<
bool>(
"hep17")),
269 const double isolationRadius(28.9), innerR(10.0), outerR(30.0);
297 for (
unsigned int k = 0;
k <
oldID_.size(); ++
k) {
307 tok_bs_ = consumes<reco::BeamSpot>(labelBS);
312 tok_alg_ = consumes<BXVector<GlobalAlgBlk> >(algTag);
313 tok_Muon_ = consumes<reco::MuonCollection>(labelMuon);
315 if (modnam.empty()) {
338 tok_ddrec_ = esConsumes<HcalDDDRecConstants, HcalRecNumberingRecord, edm::Transition::BeginRun>();
339 tok_bFieldH_ = esConsumes<MagneticField, IdealMagneticFieldRecord>();
341 tok_sevlv_ = esConsumes<EcalSeverityLevelAlgo, EcalSeverityLevelAlgoRcd>();
342 tok_geom_ = esConsumes<CaloGeometry, CaloGeometryRecord>();
344 tok_htopo_ = esConsumes<HcalTopology, HcalRecNumberingRecord>();
345 tok_resp_ = esConsumes<HcalRespCorrs, HcalRespCorrsRcd>();
348 <<
"Parameters read from config file \n"
372 for (
unsigned int k = 0;
k <
oldID_.size(); ++
k)
376 for (
int i = 0;
i < 10;
i++)
378 for (
int i = 0;
i < 8; ++
i)
386 unsigned int k1(0), k2(0);
403 <<
" Luminosity " <<
iEvent.luminosityBlock() <<
" Bunch " <<
iEvent.bunchCrossing();
416 respCorrs->
setTopo(theHBHETopology);
426 if (!trkCollection.
isValid()) {
449 if (recVtxs.
isValid() && !(recVtxs->empty())) {
451 for (
unsigned int k = 0;
k < recVtxs->size(); ++
k) {
452 if (!((*recVtxs)[
k].isFake()) && ((*recVtxs)[
k].ndof() > 4)) {
472 if (!barrelRecHitsHandle.
isValid()) {
478 if (!endcapRecHitsHandle.
isValid()) {
484 if (!
hbhe.isValid()) {
492 std::vector<spr::propagatedTrackDirection> trkCaloDirections;
494 std::vector<spr::propagatedTrackID> trkCaloDets;
496 std::vector<math::XYZTLorentzVector> vecL1, vecL3;
521 for (
const auto& decision : finalDecisions) {
522 if (decision.first.find(
l1TrigName_) != std::string::npos) {
529 <<
" from a list of " << finalDecisions.size() <<
" decisions";
539 for (
unsigned int iHLT = 0; iHLT <
triggerResults->size(); iHLT++) {
560 std::array<int, 3> ntksave{{0, 0, 0}};
589 if (!triggerEventHandle.
isValid()) {
596 std::vector<std::string>
modules;
599 for (
unsigned int iHLT = 0; iHLT <
triggerResults->size(); iHLT++) {
604 std::vector<math::XYZTLorentzVector> vecL2;
608 for (
unsigned int ifilter = 0; ifilter <
triggerEvent.sizeFilters(); ++ifilter) {
609 std::vector<int>
Keys;
612 for (
unsigned int imodule = 0; imodule < moduleLabels.size(); imodule++) {
613 if (
label.find(moduleLabels[imodule]) != std::string::npos) {
617 for (
unsigned int ifiltrKey = 0; ifiltrKey <
triggerEvent.filterKeys(ifilter).size(); ++ifiltrKey) {
630 <<
"key " << ifiltrKey <<
" : pt " << TO.
pt() <<
" eta " << TO.
eta() <<
" phi " << TO.
phi()
631 <<
" mass " << TO.
mass() <<
" Id " << TO.
id();
636 <<
"sizes " << vecL1.size() <<
":" << vecL2.size() <<
":" << vecL3.size();
644 for (
unsigned int i = 0;
i < vecL2.size();
i++) {
645 double dr =
dR(vecL1[0], vecL2[
i]);
651 mindRvec1 = vecL2[
i];
655 edm::LogVerbatim(
"HcalIsoTrack") <<
"L2 object closest to L1 " << mindRvec1 <<
" at Dr " << mindR1;
658 if (!vecL1.empty()) {
665 if (!vecL3.empty()) {
710 tree =
fs->
make<TTree>(
"CalibTree",
"CalibTree");
712 tree->Branch(
"t_Run", &
t_Run,
"t_Run/I");
727 tree->Branch(
"t_p", &
t_p,
"t_p/D");
728 tree->Branch(
"t_pt", &
t_pt,
"t_pt/D");
729 tree->Branch(
"t_phi", &
t_phi,
"t_phi/D");
751 t_DetIds =
new std::vector<unsigned int>();
752 t_DetIds1 =
new std::vector<unsigned int>();
753 t_DetIds3 =
new std::vector<unsigned int>();
758 tree->Branch(
"t_DetIds",
"std::vector<unsigned int>", &
t_DetIds);
761 tree->Branch(
"t_DetIds1",
"std::vector<unsigned int>", &
t_DetIds1);
762 tree->Branch(
"t_DetIds3",
"std::vector<unsigned int>", &
t_DetIds3);
766 tree2 =
fs->
make<TTree>(
"EventInfo",
"Event Information");
796 <<
" init flag " <<
flag <<
" change flag " << changed_;
803 for (
unsigned itrig = 0; itrig <
trigNames_.size(); itrig++) {
805 if (triggerindx >=
n) {
807 <<
"the current menu";
825 std::vector<std::string>
trig = {
"HLT_PFJet40",
835 desc.add<std::vector<std::string> >(
"triggers",
trig);
842 desc.add<
double>(
"minTrackPt", 1.0);
843 desc.add<
double>(
"maxDxyPV", 0.02);
844 desc.add<
double>(
"maxDzPV", 0.02);
845 desc.add<
double>(
"maxChi2", 5.0);
846 desc.add<
double>(
"maxDpOverP", 0.1);
847 desc.add<
int>(
"minOuterHit", 4);
848 desc.add<
int>(
"minLayerCrossed", 8);
849 desc.add<
int>(
"maxInMiss", 0);
850 desc.add<
int>(
"maxOutMiss", 0);
852 desc.add<
double>(
"minimumTrackP", 10.0);
853 desc.add<
double>(
"coneRadius", 34.98);
855 desc.add<
double>(
"coneRadiusMIP", 14.0);
856 desc.add<
double>(
"coneRadiusMIP2", 18.0);
857 desc.add<
double>(
"coneRadiusMIP3", 20.0);
858 desc.add<
double>(
"coneRadiusMIP4", 22.0);
859 desc.add<
double>(
"coneRadiusMIP5", 24.0);
860 desc.add<
double>(
"maximumEcalEnergy", 2.0);
862 desc.add<
double>(
"maxTrackP", 8.0);
863 desc.add<
double>(
"slopeTrackP", 0.05090504066);
864 desc.add<
double>(
"isolationEnergyTight", 2.0);
865 desc.add<
double>(
"isolationEnergyLoose", 10.0);
867 desc.add<
double>(
"EBHitEnergyThreshold", 0.08);
868 desc.add<
double>(
"EEHitEnergyThreshold0", 0.30);
869 desc.add<
double>(
"EEHitEnergyThreshold1", 0.00);
870 desc.add<
double>(
"EEHitEnergyThreshold2", 0.00);
871 desc.add<
double>(
"EEHitEnergyThreshold3", 0.00);
872 desc.add<
double>(
"EEHitEnergyThresholdLow", 0.30);
873 desc.add<
double>(
"EEHitEnergyThresholdHigh", 0.30);
875 desc.add<
double>(
"momentumLow", 40.0);
876 desc.add<
double>(
"momentumHigh", 60.0);
877 desc.add<
int>(
"prescaleLow", 1);
878 desc.add<
int>(
"prescaleHigh", 1);
896 desc.addUntracked<
int>(
"useRaw", 0);
897 desc.addUntracked<
bool>(
"ignoreTriggers",
false);
898 desc.addUntracked<
bool>(
"useL1Trigger",
false);
899 desc.addUntracked<
double>(
"hcalScale", 1.0);
900 desc.addUntracked<
int>(
"dataType", 0);
901 desc.addUntracked<
bool>(
"unCorrect",
false);
902 desc.addUntracked<
bool>(
"collapseDepth",
false);
904 desc.addUntracked<
int>(
"outMode", 11);
905 std::vector<int>
dummy;
906 desc.addUntracked<std::vector<int> >(
"oldID",
dummy);
907 desc.addUntracked<std::vector<int> >(
"newDepth",
dummy);
908 desc.addUntracked<
bool>(
"hep17",
false);
909 descriptions.
add(
"HcalIsoTrkAnalyzer",
desc);
913 std::vector<math::XYZTLorentzVector>& vecL3,
915 std::vector<spr::propagatedTrackDirection>& trkCaloDirections,
916 std::vector<spr::propagatedTrackID>& trkCaloDets,
929 int nSave(0),
nLoose(0), nTight(0);
931 std::vector<spr::propagatedTrackDirection>::const_iterator trkDetItr;
932 unsigned int nTracks(0), nselTracks(0);
933 t_nTrk = trkCaloDirections.size();
935 for (trkDetItr = trkCaloDirections.begin(),
nTracks = 0; trkDetItr != trkCaloDirections.end();
937 const reco::Track* pTrack = &(*(trkDetItr->trkItr));
941 << pTrack->
eta() <<
"|" << pTrack->
phi() <<
"|" << pTrack->
p();
944 for (
unsigned int k = 0;
k < vecL3.size(); ++
k) {
945 double dr =
dR(vecL3[
k], v4);
950 t_mindR1 = (!vecL1.empty()) ?
dR(vecL1[0], v4) : 999;
955 if (trkDetItr->okHCAL) {
959 if (
t_p > 40.0 &&
t_p <= 60.0)
966 oneCutParameters.
maxDzPV = 100;
969 bool qltyFlag =
spr::goodTrack(pTrack, leadPV, oneCutParameters,
false);
972 oneCutParameters.
maxDzPV = 100;
984 edm::LogVerbatim(
"HcalIsoTrack") <<
"qltyFlag|okECAL|okHCAL : " << qltyFlag <<
"|" << trkDetItr->okECAL <<
"|"
985 << trkDetItr->okHCAL <<
" eIsolation " << eIsolation;
987 t_qltyFlag = (qltyFlag && trkDetItr->okECAL && trkDetItr->okHCAL);
993 std::vector<DetId> eIds;
994 std::vector<double> eHit;
998 trkDetItr->pointHCAL,
999 trkDetItr->pointECAL,
1001 trkDetItr->directionECAL,
1005 for (
unsigned int k = 0;
k < eIds.size(); ++
k) {
1015 std::vector<DetId> eIds2;
1016 std::vector<double> eHit2;
1018 barrelRecHitsHandle,
1019 endcapRecHitsHandle,
1020 trkDetItr->pointHCAL,
1021 trkDetItr->pointECAL,
1023 trkDetItr->directionECAL,
1027 for (
unsigned int k = 0;
k < eIds2.size(); ++
k) {
1037 std::vector<DetId> eIds3;
1038 std::vector<double> eHit3;
1040 barrelRecHitsHandle,
1041 endcapRecHitsHandle,
1042 trkDetItr->pointHCAL,
1043 trkDetItr->pointECAL,
1045 trkDetItr->directionECAL,
1049 for (
unsigned int k = 0;
k < eIds3.size(); ++
k) {
1059 std::vector<DetId> eIds4;
1060 std::vector<double> eHit4;
1062 barrelRecHitsHandle,
1063 endcapRecHitsHandle,
1064 trkDetItr->pointHCAL,
1065 trkDetItr->pointECAL,
1067 trkDetItr->directionECAL,
1071 for (
unsigned int k = 0;
k < eIds4.size(); ++
k) {
1081 std::vector<DetId> eIds5;
1082 std::vector<double> eHit5;
1084 barrelRecHitsHandle,
1085 endcapRecHitsHandle,
1086 trkDetItr->pointHCAL,
1087 trkDetItr->pointECAL,
1089 trkDetItr->directionECAL,
1093 for (
unsigned int k = 0;
k < eIds5.size(); ++
k) {
1104 const DetId cellE(trkDetItr->detIdECAL);
1106 barrelRecHitsHandle,
1107 endcapRecHitsHandle,
1119 barrelRecHitsHandle,
1120 endcapRecHitsHandle,
1131 if (e11x11P.second && e15x15P.second) {
1132 t_eAnnular = (e15x15P.first - e11x11P.first);
1134 t_eAnnular = -(e15x15P.first - e11x11P.first);
1137 const DetId cellH(trkDetItr->detIdHCAL);
1139 theHBHETopology, cellH,
hbhe, 2, 2,
false,
true, -100.0, -100.0, -100.0, -100.0, -100.0, 100.0);
1141 theHBHETopology, cellH,
hbhe, 3, 3,
false,
true, -100.0, -100.0, -100.0, -100.0, -100.0, 100.0);
1145 <<
" Annular E (Ecal) " << e11x11P.first <<
":" << e15x15P.first <<
":"
1156 int nRecHits(-999), nRecHits1(-999), nRecHits3(-999);
1157 std::vector<DetId> ids, ids1, ids3;
1158 std::vector<double> edet0, edet1, edet3;
1161 trkDetItr->pointHCAL,
1162 trkDetItr->pointECAL,
1164 trkDetItr->directionHCAL,
1170 for (
unsigned k = 0;
k < ids.size(); ++
k)
1178 trkDetItr->pointHCAL,
1179 trkDetItr->pointECAL,
1181 trkDetItr->directionHCAL,
1187 for (
unsigned k = 0;
k < ids1.size(); ++
k)
1195 trkDetItr->pointHCAL,
1196 trkDetItr->pointECAL,
1198 trkDetItr->directionHCAL,
1204 for (
unsigned k = 0;
k < ids3.size(); ++
k)
1215 << pTrack->
eta() <<
"|" <<
t_phi <<
"|" <<
t_p <<
" Generator Level p "
1220 for (
unsigned int ll = 0; ll <
t_DetIds->size(); ll++) {
1224 for (
unsigned int ll = 0; ll <
t_DetIds1->size(); ll++) {
1228 for (
unsigned int ll = 0; ll <
t_DetIds3->size(); ll++) {
1278 std::array<int, 3>
i3{{nSave,
nLoose, nTight}};
1290 double mindR(999.9);
1295 pmom =
p.momentum().R();
1303 std::vector<double> sumPFNallSMDQH2;
1309 for (
const auto& pf_it : (*
tower)) {
1314 hadder += pf_it.hadEt();
1316 sumPFNallSMDQH2.emplace_back(hadder);
1321 std::sort(sumPFNallSMDQH2.begin(), sumPFNallSMDQH2.end());
1322 if (sumPFNallSMDQH2.size() % 2)
1323 evt_smdq = sumPFNallSMDQH2[(sumPFNallSMDQH2.size() - 1) / 2];
1325 evt_smdq = (sumPFNallSMDQH2[sumPFNallSMDQH2.size() / 2] + sumPFNallSMDQH2[(sumPFNallSMDQH2.size() - 2) / 2]) / 2.;
1351 for (
unsigned int k = 0;
k <
oldID_.size(); ++
k) {
1361 const std::vector<DetId>& ids,
1362 std::vector<double>& edet,
1364 std::vector<unsigned int>* detIds,
1365 std::vector<double>* hitEnergies) {
1368 for (
unsigned int k = 0;
k < ids.size(); ++
k) {
1375 for (
const auto& en : edet)
1379 edm::LogWarning(
"HcalIsoTrack") <<
"Check inconsistent energies: " << indx <<
" " << eHcal <<
":" << ehcal
1380 <<
" from " << ids.size() <<
" cells";
1384 std::map<HcalDetId, double> hitMap;
1385 for (
unsigned int k = 0;
k < ids.size(); ++
k) {
1387 auto itr = hitMap.find(
id);
1388 if (itr == hitMap.end()) {
1389 hitMap[
id] = edet[
k];
1391 (itr->second) += edet[
k];
1394 detIds->reserve(hitMap.size());
1395 hitEnergies->reserve(hitMap.size());
1396 for (
const auto&
hit : hitMap) {
1397 detIds->emplace_back(
hit.first.rawId());
1398 hitEnergies->emplace_back(
hit.second);
1401 detIds->reserve(ids.size());
1402 hitEnergies->reserve(ids.size());
1403 for (
unsigned int k = 0;
k < ids.size(); ++
k) {
1404 detIds->emplace_back(ids[
k].rawId());
1405 hitEnergies->emplace_back(edet[
k]);
1409 edm::LogVerbatim(
"HcalIsoTrack") <<
"Input to storeEnergy with " << ids.size() <<
" cells";
1410 for (
unsigned int k = 0;
k < ids.size(); ++
k)
1412 edm::LogVerbatim(
"HcalIsoTrack") <<
"Output of storeEnergy with " << detIds->size() <<
" cells and Etot " << eHcal;
1413 for (
unsigned int k = 0;
k < detIds->size(); ++
k)
1420 for (reco::MuonCollection::const_iterator recMuon = muonh->begin(); recMuon != muonh->end(); ++recMuon) {
1421 if (recMuon->innerTrack().isNonnull()) {
1423 bool mediumMuon = (((recMuon->isPFMuon()) && (recMuon->isGlobalMuon() || recMuon->isTrackerMuon())) &&
1424 (recMuon->innerTrack()->validFraction() > 0.49));
1426 double chiGlobal = ((recMuon->globalTrack().isNonnull()) ? recMuon->globalTrack()->normalizedChi2() : 999);
1427 bool goodGlob = (recMuon->isGlobalMuon() && chiGlobal < 3 &&
1428 recMuon->combinedQuality().chi2LocalPosition < 12 && recMuon->combinedQuality().trkKink < 20);