75 #include "TObjArray.h"
76 #include "TClonesArray.h"
77 #include "TRefArray.h"
78 #include "TLorentzVector.h"
102 virtual void endJob()
override ;
183 tok_track_ = consumes<reco::IsolatedPixelTrackCandidateCollection>(iConfig.
getParameter<
edm::InputTag>(
"HcalIsolTrackInput"));
185 associationConeSize_=iConfig.
getParameter<
double>(
"associationConeSize");
190 calibrationConeSize_=iConfig.
getParameter<
double>(
"calibrationConeSize");
192 nIterations = iConfig.
getParameter<
int>(
"noOfIterations");
193 eventWeight = iConfig.
getParameter<
double>(
"eventWeight");
194 energyMinIso = iConfig.
getParameter<
double>(
"energyMinIso");
195 energyMaxIso = iConfig.
getParameter<
double>(
"energyMaxIso");
196 energyECALmip = iConfig.
getParameter<
double>(
"energyECALmip");
198 MinNTrackHitsBarrel = iConfig.
getParameter<
int>(
"MinNTrackHitsBarrel");
199 MinNTECHitsEndcap = iConfig.
getParameter<
int>(
"MinNTECHitsEndcap");
200 hottestHitDistance = iConfig.
getParameter<
double>(
"hottestHitDistance");
202 EcalConeOuter = iConfig.
getParameter<
double>(
"EcalConeOuter");
206 parameters_.loadParameters( parameters, iC );
207 trackAssociator_.useDefaultPropagator();
222 vector<float> rawEnergyVec;
226 vector<HcalDetId> detidvec;
259 parameters_.useEcal =
true;
260 parameters_.useHcal =
true;
261 parameters_.useCalo =
false;
262 parameters_.useMuon =
false;
263 parameters_.dREcal = 0.5;
264 parameters_.dRHcal = 0.6;
266 if (isoPixelTracks->size()==0)
return;
268 for (reco::TrackCollection::const_iterator trit=isoProdTracks->begin(); trit!=isoProdTracks->end(); trit++)
270 reco::IsolatedPixelTrackCandidateCollection::const_iterator isoMatched=isoPixelTracks->begin();
274 for (reco::IsolatedPixelTrackCandidateCollection::const_iterator it = isoPixelTracks->begin(); it!=isoPixelTracks->end(); it++)
277 if (
abs((trit->pt() - it->pt())/it->pt()) < 0.005 &&
abs(trit->eta() - it->eta()) < 0.01)
284 if (!matched)
continue;
286 if (trit->hitPattern().numberOfValidHits()<MinNTrackHitsBarrel)
continue;
287 if (fabs(trit->eta())>1.47&&trit->hitPattern().numberOfValidStripTECHits()<MinNTECHitsEndcap)
continue;
290 calEnergy =
sqrt(trit->px()*trit->px()+trit->py()*trit->py()+trit->pz()*trit->pz()+0.14*0.14);
295 double corrHCAL = 1.;
299 rvert =
sqrt(trit->vx()*trit->vx()+trit->vy()*trit->vy()+trit->vz()*trit->vz());
302 TrackDetMatchInfo info = trackAssociator_.associate(iEvent, iSetup,trackAssociator_.getFreeTrajectoryState(iSetup, *trit),parameters_);
305 xTrkHcal=info.trkGlobPosAtHcal.x();
306 yTrkHcal=info.trkGlobPosAtHcal.y();
307 zTrkHcal=info.trkGlobPosAtHcal.z();
309 xTrkEcal=info.trkGlobPosAtEcal.x();
310 yTrkEcal=info.trkGlobPosAtEcal.y();
311 zTrkEcal=info.trkGlobPosAtEcal.z();
313 if (xTrkEcal==0 && yTrkEcal==0&& zTrkEcal==0) {
cout<<
"zero point at Ecal"<<endl;
continue;}
314 if (xTrkHcal==0 && yTrkHcal==0&& zTrkHcal==0) {
cout<<
"zero point at Hcal"<<endl;
continue;}
318 PxTrkHcal = trackMomAtHcal.
x();
319 PyTrkHcal = trackMomAtHcal.
y();
320 PzTrkHcal = trackMomAtHcal.
z();
326 GlobalPoint gPointEcal(xTrkEcal,yTrkEcal,zTrkEcal);
327 GlobalPoint gPointHcal(xTrkHcal,yTrkHcal,zTrkHcal);
338 const HcalDetId tempId = gHcal->getClosestCell(gPointHcal);
339 ietatrue = tempId.
ieta();
340 iphitrue = tempId.
iphi();
344 std::vector<DetId> usedHits;
359 bool hitIsUsed=
false;
360 DetId hitId=hhit->id();
361 for (uint32_t
i=0;
i<usedHits.size();
i++)
363 if (usedHits[
i]==hitId) hitIsUsed=
true;
365 if (hitIsUsed)
continue;
366 usedHits.push_back(hitId);
375 int iphihitm = (hhit->id()).iphi();
376 int ietahitm = (hhit->id()).ieta();
377 int depthhit = (hhit->id()).depth();
378 double enehit = hhit->energy() * recal;
380 if (depthhit!=1)
continue;
387 if(distAtHcal < associationConeSize_)
391 int iphihitm2 = (hhit2->id()).iphi();
392 int ietahitm2 = (hhit2->id()).ieta();
393 int depthhit2 = (hhit2->id()).depth();
394 double enehit2 = hhit2->energy() * recal;
396 if ( iphihitm==iphihitm2 && ietahitm==ietahitm2 && depthhit!=depthhit2){
398 enehit = enehit+enehit2;
405 MaxHit.
ietahitm = (hhit->id()).ieta();
406 MaxHit.
iphihitm = (hhit->id()).iphi();
407 MaxHit.
depthhit = (hhit->id()).depth();
408 MaxHit.
dr = distAtHcal;
410 MaxHit.
posMax = geo->getPosition(hhit->detid());
417 Bool_t passCuts = kFALSE;
418 if(calEnergy > energyMinIso && calEnergy < energyMaxIso && emEnergy < energyECALmip &&
420 MaxHit.
dr < hottestHitDistance && emRingEnergy<8.){ passCuts = kTRUE; }
423 if(AxB_==
"5x5" || AxB_==
"3x3" || AxB_==
"7x7"|| AxB_==
"Cone")
434 bool hitIsUsed=
false;
435 DetId hitId=hhit->id();
436 for (uint32_t
i=0;
i<usedHits.size();
i++)
438 if (usedHits[
i]==hitId) hitIsUsed=
true;
445 usedHits.push_back(hitId);
449 if(MaxHit.
ietahitm*(hhit->id()).ieta()>0)
451 DIETA = MaxHit.
ietahitm - (hhit->id()).ieta();
453 if(MaxHit.
ietahitm*(hhit->id()).ieta()<0)
455 DIETA = MaxHit.
ietahitm - (hhit->id()).ieta();
456 DIETA = DIETA>0 ? DIETA-1 : DIETA+1;
459 int DIPHI =
abs(MaxHit.
iphihitm - (hhit->id()).iphi());
460 DIPHI = DIPHI>36 ? 72-DIPHI : DIPHI;
464 if(AxB_==
"3x3") numbercell = 1;
465 if(AxB_==
"5x5") numbercell = 2;
466 if(AxB_==
"7x7") numbercell = 3;
467 if(AxB_==
"Cone") numbercell = 1000;
469 if(
abs(DIETA)<=numbercell && (
abs(DIPHI)<=numbercell || (
abs(MaxHit.
ietahitm)>=20 &&
abs(DIPHI)<=numbercell+1)) ) {
476 const GlobalPoint pos2 = geo->getPosition(hhit->detid());
480 if(AxB_==
"5x5" || AxB_==
"3x3" || AxB_==
"7x7") {
482 rawEnergyVec.push_back(hhit->energy() * recal * corrHCAL);
483 detidvec.push_back(hhit->id());
484 detiphi.push_back((hhit->id()).iphi());
485 detieta.push_back((hhit->id()).ieta());
486 i3i5.push_back(iii3i5);
493 rawEnergyVec.push_back(hhit->energy() * recal * corrHCAL);
494 detidvec.push_back(hhit->id());
495 detiphi.push_back((hhit->id()).iphi());
496 detieta.push_back((hhit->id()).ieta());
497 i3i5.push_back(iii3i5);
506 if(AxB_!=
"3x3" && AxB_!=
"5x5" && AxB_!=
"7x7" && AxB_!=
"Cone")
LogWarning(
" AxB ")<<
" Not supported: "<< AxB_;
510 input_to_L3 << rawEnergyVec.size() <<
" " << calEnergy;
513 for (
unsigned int i=0;
i<rawEnergyVec.size();
i++)
515 input_to_L3 <<
" " << rawEnergyVec.at(
i) <<
" " << detidvec.at(
i).rawId() ;
520 eventNumber = iEvent.
id().
event();
525 numberOfCells=rawEnergyVec.size();
528 for (
unsigned int ia=0; ia<numberOfCells; ++ia) {
529 cellEnergy = rawEnergyVec.at(ia);
530 cell = detidvec.at(ia).rawId();
532 new((*cells)[ia])
TCell(cell, cellEnergy);
543 rawEnergyVec.clear();
562 bool hitIsUsed=
false;
563 DetId hitId=hoItr->id();
564 for (uint32_t
i=0;
i<usedHits.size();
i++)
566 if (usedHits[
i]==hitId) hitIsUsed=
true;
568 if (hitIsUsed)
continue;
570 usedHits.push_back(hitId);
589 if (!allowMissingInputs_)
throw e;
603 input_to_L3.open(
"input_to_l3.txt");
605 rootFile =
new TFile(
"rootFile.root",
"RECREATE");
606 tree =
new TTree(
"hcalCalibTree",
"Tree for IsoTrack Calibration");
607 cells =
new TClonesArray(
"TCell", 10000);
611 tagJetP4 =
new TLorentzVector();
612 probeJetP4 =
new TLorentzVector();
614 tree->Branch(
"cells", &cells, 64000, 0);
615 tree->Branch(
"targetE", &targetE,
"targetE/F");
616 tree->Branch(
"emEnergy", &emEnergy,
"emEnergy/F");
618 tree->Branch(
"PxTrkHcal", &PxTrkHcal,
"PxTrkHcal/F");
619 tree->Branch(
"PyTrkHcal", &PyTrkHcal,
"PyTrkHcal/F");
620 tree->Branch(
"PzTrkHcal", &PzTrkHcal,
"PzTrkHcal/F");
623 tree->Branch(
"xTrkHcal", &xTrkHcal,
"xTrkHcal/F");
624 tree->Branch(
"yTrkHcal", &yTrkHcal,
"yTrkHcal/F");
625 tree->Branch(
"zTrkHcal", &zTrkHcal,
"zTrkHcal/F");
627 tree->Branch(
"iEtaHit", &iEtaHit,
"iEtaHit/I");
628 tree->Branch(
"iPhiHit", &iPhiHit,
"iPhiHit/i");
629 tree->Branch(
"eventNumber", &eventNumber,
"eventNumber/i");
632 tree->Branch(
"tagJetP4",
"TLorentzVector", &tagJetP4);
633 tree->Branch(
"probeJetP4",
"TLorentzVector", &probeJetP4);
634 tree->Branch(
"etVetoJet", &etVetoJet,
"etVetoJet/F");
635 tree->Branch(
"tagJetEmFrac", &tagJetEmFrac,
"tagJetEmFrac/F");
636 tree->Branch(
"probeJetEmFrac", &probeJetEmFrac,
"probeJetEmFrac/F");
649 if (cells)
delete cells;
653 if (tagJetP4)
delete tagJetP4;
654 if (probeJetP4)
delete probeJetP4;
T getParameter(std::string const &) const
EventNumber_t event() const
T getUntrackedParameter(std::string const &, T const &) const
edm::EDGetTokenT< EcalRecHitCollection > tok_ecal_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
HcalIsoTrkAnalyzer(const edm::ParameterSet &)
double ecalEnergyInCone(const GlobalPoint center, double radius, const EcalRecHitCollection ecalCol, const CaloGeometry *geo)
#define DEFINE_FWK_MODULE(type)
double getDistInPlaneTrackDir(const GlobalPoint caloPoint, const GlobalVector caloVector, const GlobalPoint rechitPoint)
std::vector< HBHERecHit >::const_iterator const_iterator
TrackDetectorAssociator trackAssociator_
double calibrationConeSize_
std::ofstream input_to_L3
edm::EDGetTokenT< HBHERecHitCollection > tok_hbhe_
TLorentzVector * probeJetP4
edm::EDGetTokenT< reco::IsolatedPixelTrackCandidateCollection > tok_track_
int ieta() const
get the cell ieta
Abs< T >::type abs(const T &t)
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
TLorentzVector * tagJetP4
double hottestHitDistance
const_iterator end() const
TrackAssociatorParameters parameters_
int iphi() const
get the cell iphi
T const * product() const
edm::EDGetTokenT< HORecHitCollection > tok_ho_
virtual void endJob() override
std::string m_inputTrackLabel
virtual void beginJob() override
edm::EDGetTokenT< reco::TrackCollection > tok_track1_
const_iterator begin() const