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;
523 for (
const auto& decision : finalDecisions) {
524 if (decision.first.find(
l1TrigName_) != std::string::npos) {
531 <<
" from a list of " << finalDecisions.size() <<
" decisions";
540 for (
unsigned int iHLT = 0; iHLT <
triggerResults->size(); iHLT++) {
563 std::array<int, 3> ntksave{{0, 0, 0}};
592 if (!triggerEventHandle.
isValid()) {
599 std::vector<std::string>
modules;
602 for (
unsigned int iHLT = 0; iHLT <
triggerResults->size(); iHLT++) {
607 std::vector<math::XYZTLorentzVector> vecL2;
611 for (
unsigned int ifilter = 0; ifilter <
triggerEvent.sizeFilters(); ++ifilter) {
612 std::vector<int>
Keys;
615 for (
unsigned int imodule = 0; imodule < moduleLabels.size(); imodule++) {
616 if (
label.find(moduleLabels[imodule]) != std::string::npos) {
620 for (
unsigned int ifiltrKey = 0; ifiltrKey <
triggerEvent.filterKeys(ifilter).size(); ++ifiltrKey) {
633 <<
"key " << ifiltrKey <<
" : pt " << TO.
pt() <<
" eta " << TO.
eta() <<
" phi " << TO.
phi()
634 <<
" mass " << TO.
mass() <<
" Id " << TO.
id();
639 <<
"sizes " << vecL1.size() <<
":" << vecL2.size() <<
":" << vecL3.size();
647 for (
unsigned int i = 0;
i < vecL2.size();
i++) {
648 double dr =
dR(vecL1[0], vecL2[
i]);
654 mindRvec1 = vecL2[
i];
658 edm::LogVerbatim(
"HcalIsoTrack") <<
"L2 object closest to L1 " << mindRvec1 <<
" at Dr " << mindR1;
661 if (!vecL1.empty()) {
668 if (!vecL3.empty()) {
713 tree =
fs->
make<TTree>(
"CalibTree",
"CalibTree");
715 tree->Branch(
"t_Run", &
t_Run,
"t_Run/I");
730 tree->Branch(
"t_p", &
t_p,
"t_p/D");
731 tree->Branch(
"t_pt", &
t_pt,
"t_pt/D");
732 tree->Branch(
"t_phi", &
t_phi,
"t_phi/D");
754 t_DetIds =
new std::vector<unsigned int>();
755 t_DetIds1 =
new std::vector<unsigned int>();
756 t_DetIds3 =
new std::vector<unsigned int>();
761 tree->Branch(
"t_DetIds",
"std::vector<unsigned int>", &
t_DetIds);
764 tree->Branch(
"t_DetIds1",
"std::vector<unsigned int>", &
t_DetIds1);
765 tree->Branch(
"t_DetIds3",
"std::vector<unsigned int>", &
t_DetIds3);
769 tree2 =
fs->
make<TTree>(
"EventInfo",
"Event Information");
799 <<
" init flag " <<
flag <<
" change flag " << changed_;
806 for (
unsigned itrig = 0; itrig <
trigNames_.size(); itrig++) {
808 if (triggerindx >=
n) {
810 <<
"the current menu";
828 std::vector<std::string>
trig = {
"HLT_PFJet40",
838 desc.add<std::vector<std::string> >(
"triggers",
trig);
845 desc.add<
double>(
"minTrackPt", 1.0);
846 desc.add<
double>(
"maxDxyPV", 0.02);
847 desc.add<
double>(
"maxDzPV", 0.02);
848 desc.add<
double>(
"maxChi2", 5.0);
849 desc.add<
double>(
"maxDpOverP", 0.1);
850 desc.add<
int>(
"minOuterHit", 4);
851 desc.add<
int>(
"minLayerCrossed", 8);
852 desc.add<
int>(
"maxInMiss", 0);
853 desc.add<
int>(
"maxOutMiss", 0);
855 desc.add<
double>(
"minimumTrackP", 10.0);
856 desc.add<
double>(
"coneRadius", 34.98);
858 desc.add<
double>(
"coneRadiusMIP", 14.0);
859 desc.add<
double>(
"coneRadiusMIP2", 18.0);
860 desc.add<
double>(
"coneRadiusMIP3", 20.0);
861 desc.add<
double>(
"coneRadiusMIP4", 22.0);
862 desc.add<
double>(
"coneRadiusMIP5", 24.0);
863 desc.add<
double>(
"maximumEcalEnergy", 2.0);
865 desc.add<
double>(
"maxTrackP", 8.0);
866 desc.add<
double>(
"slopeTrackP", 0.05090504066);
867 desc.add<
double>(
"isolationEnergyTight", 2.0);
868 desc.add<
double>(
"isolationEnergyLoose", 10.0);
870 desc.add<
double>(
"EBHitEnergyThreshold", 0.08);
871 desc.add<
double>(
"EEHitEnergyThreshold0", 0.30);
872 desc.add<
double>(
"EEHitEnergyThreshold1", 0.00);
873 desc.add<
double>(
"EEHitEnergyThreshold2", 0.00);
874 desc.add<
double>(
"EEHitEnergyThreshold3", 0.00);
875 desc.add<
double>(
"EEHitEnergyThresholdLow", 0.30);
876 desc.add<
double>(
"EEHitEnergyThresholdHigh", 0.30);
878 desc.add<
double>(
"momentumLow", 40.0);
879 desc.add<
double>(
"momentumHigh", 60.0);
880 desc.add<
int>(
"prescaleLow", 1);
881 desc.add<
int>(
"prescaleHigh", 1);
899 desc.addUntracked<
int>(
"useRaw", 0);
900 desc.addUntracked<
bool>(
"ignoreTriggers",
false);
901 desc.addUntracked<
bool>(
"useL1Trigger",
false);
902 desc.addUntracked<
double>(
"hcalScale", 1.0);
903 desc.addUntracked<
int>(
"dataType", 0);
904 desc.addUntracked<
bool>(
"unCorrect",
false);
905 desc.addUntracked<
bool>(
"collapseDepth",
false);
907 desc.addUntracked<
int>(
"outMode", 11);
908 std::vector<int>
dummy;
909 desc.addUntracked<std::vector<int> >(
"oldID",
dummy);
910 desc.addUntracked<std::vector<int> >(
"newDepth",
dummy);
911 desc.addUntracked<
bool>(
"hep17",
false);
912 descriptions.
add(
"HcalIsoTrkAnalyzer",
desc);
916 std::vector<math::XYZTLorentzVector>& vecL3,
918 std::vector<spr::propagatedTrackDirection>& trkCaloDirections,
919 std::vector<spr::propagatedTrackID>& trkCaloDets,
932 int nSave(0),
nLoose(0), nTight(0);
934 std::vector<spr::propagatedTrackDirection>::const_iterator trkDetItr;
935 unsigned int nTracks(0), nselTracks(0);
936 t_nTrk = trkCaloDirections.size();
938 for (trkDetItr = trkCaloDirections.begin(),
nTracks = 0; trkDetItr != trkCaloDirections.end();
940 const reco::Track* pTrack = &(*(trkDetItr->trkItr));
944 << pTrack->
eta() <<
"|" << pTrack->
phi() <<
"|" << pTrack->
p();
947 for (
unsigned int k = 0;
k < vecL3.size(); ++
k) {
948 double dr =
dR(vecL3[
k], v4);
953 t_mindR1 = (!vecL1.empty()) ?
dR(vecL1[0], v4) : 999;
958 if (trkDetItr->okHCAL) {
962 if (
t_p > 40.0 &&
t_p <= 60.0)
969 oneCutParameters.
maxDzPV = 100;
972 bool qltyFlag =
spr::goodTrack(pTrack, leadPV, oneCutParameters,
false);
975 oneCutParameters.
maxDzPV = 100;
987 edm::LogVerbatim(
"HcalIsoTrack") <<
"qltyFlag|okECAL|okHCAL : " << qltyFlag <<
"|" << trkDetItr->okECAL <<
"|"
988 << trkDetItr->okHCAL <<
" eIsolation " << eIsolation;
990 t_qltyFlag = (qltyFlag && trkDetItr->okECAL && trkDetItr->okHCAL);
996 std::vector<DetId> eIds;
997 std::vector<double> eHit;
1000 endcapRecHitsHandle,
1001 trkDetItr->pointHCAL,
1002 trkDetItr->pointECAL,
1004 trkDetItr->directionECAL,
1008 for (
unsigned int k = 0;
k < eIds.size(); ++
k) {
1018 std::vector<DetId> eIds2;
1019 std::vector<double> eHit2;
1021 barrelRecHitsHandle,
1022 endcapRecHitsHandle,
1023 trkDetItr->pointHCAL,
1024 trkDetItr->pointECAL,
1026 trkDetItr->directionECAL,
1030 for (
unsigned int k = 0;
k < eIds2.size(); ++
k) {
1040 std::vector<DetId> eIds3;
1041 std::vector<double> eHit3;
1043 barrelRecHitsHandle,
1044 endcapRecHitsHandle,
1045 trkDetItr->pointHCAL,
1046 trkDetItr->pointECAL,
1048 trkDetItr->directionECAL,
1052 for (
unsigned int k = 0;
k < eIds3.size(); ++
k) {
1062 std::vector<DetId> eIds4;
1063 std::vector<double> eHit4;
1065 barrelRecHitsHandle,
1066 endcapRecHitsHandle,
1067 trkDetItr->pointHCAL,
1068 trkDetItr->pointECAL,
1070 trkDetItr->directionECAL,
1074 for (
unsigned int k = 0;
k < eIds4.size(); ++
k) {
1084 std::vector<DetId> eIds5;
1085 std::vector<double> eHit5;
1087 barrelRecHitsHandle,
1088 endcapRecHitsHandle,
1089 trkDetItr->pointHCAL,
1090 trkDetItr->pointECAL,
1092 trkDetItr->directionECAL,
1096 for (
unsigned int k = 0;
k < eIds5.size(); ++
k) {
1107 const DetId cellE(trkDetItr->detIdECAL);
1109 barrelRecHitsHandle,
1110 endcapRecHitsHandle,
1122 barrelRecHitsHandle,
1123 endcapRecHitsHandle,
1134 if (e11x11P.second && e15x15P.second) {
1135 t_eAnnular = (e15x15P.first - e11x11P.first);
1137 t_eAnnular = -(e15x15P.first - e11x11P.first);
1140 const DetId cellH(trkDetItr->detIdHCAL);
1142 theHBHETopology, cellH,
hbhe, 2, 2,
false,
true, -100.0, -100.0, -100.0, -100.0, -100.0, 100.0);
1144 theHBHETopology, cellH,
hbhe, 3, 3,
false,
true, -100.0, -100.0, -100.0, -100.0, -100.0, 100.0);
1148 <<
" Annular E (Ecal) " << e11x11P.first <<
":" << e15x15P.first <<
":"
1159 int nRecHits(-999), nRecHits1(-999), nRecHits3(-999);
1160 std::vector<DetId> ids, ids1, ids3;
1161 std::vector<double> edet0, edet1, edet3;
1164 trkDetItr->pointHCAL,
1165 trkDetItr->pointECAL,
1167 trkDetItr->directionHCAL,
1173 for (
unsigned k = 0;
k < ids.size(); ++
k)
1181 trkDetItr->pointHCAL,
1182 trkDetItr->pointECAL,
1184 trkDetItr->directionHCAL,
1190 for (
unsigned k = 0;
k < ids1.size(); ++
k)
1198 trkDetItr->pointHCAL,
1199 trkDetItr->pointECAL,
1201 trkDetItr->directionHCAL,
1207 for (
unsigned k = 0;
k < ids3.size(); ++
k)
1218 << pTrack->
eta() <<
"|" <<
t_phi <<
"|" <<
t_p <<
" Generator Level p "
1223 for (
unsigned int ll = 0; ll <
t_DetIds->size(); ll++) {
1227 for (
unsigned int ll = 0; ll <
t_DetIds1->size(); ll++) {
1231 for (
unsigned int ll = 0; ll <
t_DetIds3->size(); ll++) {
1281 std::array<int, 3>
i3{{nSave,
nLoose, nTight}};
1293 double mindR(999.9);
1298 pmom =
p.momentum().R();
1306 std::vector<double> sumPFNallSMDQH2;
1312 for (
const auto& pf_it : (*
tower)) {
1317 hadder += pf_it.hadEt();
1319 sumPFNallSMDQH2.emplace_back(hadder);
1324 std::sort(sumPFNallSMDQH2.begin(), sumPFNallSMDQH2.end());
1325 if (sumPFNallSMDQH2.size() % 2)
1326 evt_smdq = sumPFNallSMDQH2[(sumPFNallSMDQH2.size() - 1) / 2];
1328 evt_smdq = (sumPFNallSMDQH2[sumPFNallSMDQH2.size() / 2] + sumPFNallSMDQH2[(sumPFNallSMDQH2.size() - 2) / 2]) / 2.;
1354 for (
unsigned int k = 0;
k <
oldID_.size(); ++
k) {
1364 const std::vector<DetId>& ids,
1365 std::vector<double>& edet,
1367 std::vector<unsigned int>* detIds,
1368 std::vector<double>* hitEnergies) {
1371 for (
unsigned int k = 0;
k < ids.size(); ++
k) {
1378 for (
const auto& en : edet)
1382 edm::LogWarning(
"HcalIsoTrack") <<
"Check inconsistent energies: " << indx <<
" " << eHcal <<
":" << ehcal
1383 <<
" from " << ids.size() <<
" cells";
1387 std::map<HcalDetId, double> hitMap;
1388 for (
unsigned int k = 0;
k < ids.size(); ++
k) {
1390 auto itr = hitMap.find(
id);
1391 if (itr == hitMap.end()) {
1392 hitMap[
id] = edet[
k];
1394 (itr->second) += edet[
k];
1397 detIds->reserve(hitMap.size());
1398 hitEnergies->reserve(hitMap.size());
1399 for (
const auto&
hit : hitMap) {
1400 detIds->emplace_back(
hit.first.rawId());
1401 hitEnergies->emplace_back(
hit.second);
1404 detIds->reserve(ids.size());
1405 hitEnergies->reserve(ids.size());
1406 for (
unsigned int k = 0;
k < ids.size(); ++
k) {
1407 detIds->emplace_back(ids[
k].rawId());
1408 hitEnergies->emplace_back(edet[
k]);
1412 edm::LogVerbatim(
"HcalIsoTrack") <<
"Input to storeEnergy with " << ids.size() <<
" cells";
1413 for (
unsigned int k = 0;
k < ids.size(); ++
k)
1415 edm::LogVerbatim(
"HcalIsoTrack") <<
"Output of storeEnergy with " << detIds->size() <<
" cells and Etot " << eHcal;
1416 for (
unsigned int k = 0;
k < detIds->size(); ++
k)
1423 for (reco::MuonCollection::const_iterator recMuon = muonh->begin(); recMuon != muonh->end(); ++recMuon) {
1424 if (recMuon->innerTrack().isNonnull()) {
1426 bool mediumMuon = (((recMuon->isPFMuon()) && (recMuon->isGlobalMuon() || recMuon->isTrackerMuon())) &&
1427 (recMuon->innerTrack()->validFraction() > 0.49));
1429 double chiGlobal = ((recMuon->globalTrack().isNonnull()) ? recMuon->globalTrack()->normalizedChi2() : 999);
1430 bool goodGlob = (recMuon->isGlobalMuon() && chiGlobal < 3 &&
1431 recMuon->combinedQuality().chi2LocalPosition < 12 && recMuon->combinedQuality().trkKink < 20);