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");
205 parameters_.loadParameters( parameters );
206 trackAssociator_.useDefaultPropagator();
221 vector<float> rawEnergyVec;
225 vector<HcalDetId> detidvec;
258 parameters_.useEcal =
true;
259 parameters_.useHcal =
true;
260 parameters_.useCalo =
false;
261 parameters_.useMuon =
false;
262 parameters_.dREcal = 0.5;
263 parameters_.dRHcal = 0.6;
265 if (isoPixelTracks->size()==0)
return;
267 for (reco::TrackCollection::const_iterator trit=isoProdTracks->begin(); trit!=isoProdTracks->end(); trit++)
269 reco::IsolatedPixelTrackCandidateCollection::const_iterator isoMatched=isoPixelTracks->begin();
273 for (reco::IsolatedPixelTrackCandidateCollection::const_iterator it = isoPixelTracks->begin(); it!=isoPixelTracks->end(); it++)
276 if (
abs((trit->pt() - it->pt())/it->pt()) < 0.005 &&
abs(trit->eta() - it->eta()) < 0.01)
283 if (!matched)
continue;
285 if (trit->hitPattern().numberOfValidHits()<MinNTrackHitsBarrel)
continue;
286 if (fabs(trit->eta())>1.47&&trit->hitPattern().numberOfValidStripTECHits()<MinNTECHitsEndcap)
continue;
289 calEnergy =
sqrt(trit->px()*trit->px()+trit->py()*trit->py()+trit->pz()*trit->pz()+0.14*0.14);
294 double corrHCAL = 1.;
298 rvert =
sqrt(trit->vx()*trit->vx()+trit->vy()*trit->vy()+trit->vz()*trit->vz());
301 TrackDetMatchInfo info = trackAssociator_.associate(iEvent, iSetup,trackAssociator_.getFreeTrajectoryState(iSetup, *trit),parameters_);
304 xTrkHcal=info.trkGlobPosAtHcal.x();
305 yTrkHcal=info.trkGlobPosAtHcal.y();
306 zTrkHcal=info.trkGlobPosAtHcal.z();
308 xTrkEcal=info.trkGlobPosAtEcal.x();
309 yTrkEcal=info.trkGlobPosAtEcal.y();
310 zTrkEcal=info.trkGlobPosAtEcal.z();
312 if (xTrkEcal==0 && yTrkEcal==0&& zTrkEcal==0) {
cout<<
"zero point at Ecal"<<endl;
continue;}
313 if (xTrkHcal==0 && yTrkHcal==0&& zTrkHcal==0) {
cout<<
"zero point at Hcal"<<endl;
continue;}
317 PxTrkHcal = trackMomAtHcal.
x();
318 PyTrkHcal = trackMomAtHcal.
y();
319 PzTrkHcal = trackMomAtHcal.
z();
325 GlobalPoint gPointEcal(xTrkEcal,yTrkEcal,zTrkEcal);
326 GlobalPoint gPointHcal(xTrkHcal,yTrkHcal,zTrkHcal);
337 const HcalDetId tempId = gHcal->getClosestCell(gPointHcal);
338 ietatrue = tempId.
ieta();
339 iphitrue = tempId.
iphi();
343 std::vector<DetId> usedHits;
358 bool hitIsUsed=
false;
359 DetId hitId=hhit->id();
360 for (uint32_t
i=0;
i<usedHits.size();
i++)
362 if (usedHits[
i]==hitId) hitIsUsed=
true;
364 if (hitIsUsed)
continue;
365 usedHits.push_back(hitId);
374 int iphihitm = (hhit->id()).iphi();
375 int ietahitm = (hhit->id()).ieta();
376 int depthhit = (hhit->id()).depth();
377 double enehit = hhit->energy() * recal;
379 if (depthhit!=1)
continue;
386 if(distAtHcal < associationConeSize_)
390 int iphihitm2 = (hhit2->id()).iphi();
391 int ietahitm2 = (hhit2->id()).ieta();
392 int depthhit2 = (hhit2->id()).depth();
393 double enehit2 = hhit2->energy() * recal;
395 if ( iphihitm==iphihitm2 && ietahitm==ietahitm2 && depthhit!=depthhit2){
397 enehit = enehit+enehit2;
404 MaxHit.
ietahitm = (hhit->id()).ieta();
405 MaxHit.
iphihitm = (hhit->id()).iphi();
406 MaxHit.
depthhit = (hhit->id()).depth();
407 MaxHit.
dr = distAtHcal;
409 MaxHit.
posMax = geo->getPosition(hhit->detid());
416 Bool_t passCuts = kFALSE;
417 if(calEnergy > energyMinIso && calEnergy < energyMaxIso && emEnergy < energyECALmip &&
419 MaxHit.
dr < hottestHitDistance && emRingEnergy<8.){ passCuts = kTRUE; }
422 if(AxB_==
"5x5" || AxB_==
"3x3" || AxB_==
"7x7"|| AxB_==
"Cone")
433 bool hitIsUsed=
false;
434 DetId hitId=hhit->id();
435 for (uint32_t
i=0;
i<usedHits.size();
i++)
437 if (usedHits[
i]==hitId) hitIsUsed=
true;
444 usedHits.push_back(hitId);
448 if(MaxHit.
ietahitm*(hhit->id()).ieta()>0)
450 DIETA = MaxHit.
ietahitm - (hhit->id()).ieta();
452 if(MaxHit.
ietahitm*(hhit->id()).ieta()<0)
454 DIETA = MaxHit.
ietahitm - (hhit->id()).ieta();
455 DIETA = DIETA>0 ? DIETA-1 : DIETA+1;
458 int DIPHI =
abs(MaxHit.
iphihitm - (hhit->id()).iphi());
459 DIPHI = DIPHI>36 ? 72-DIPHI : DIPHI;
463 if(AxB_==
"3x3") numbercell = 1;
464 if(AxB_==
"5x5") numbercell = 2;
465 if(AxB_==
"7x7") numbercell = 3;
466 if(AxB_==
"Cone") numbercell = 1000;
468 if(
abs(DIETA)<=numbercell && (
abs(DIPHI)<=numbercell || (
abs(MaxHit.
ietahitm)>=20 &&
abs(DIPHI)<=numbercell+1)) ) {
475 const GlobalPoint pos2 = geo->getPosition(hhit->detid());
479 if(AxB_==
"5x5" || AxB_==
"3x3" || AxB_==
"7x7") {
481 rawEnergyVec.push_back(hhit->energy() * recal * corrHCAL);
482 detidvec.push_back(hhit->id());
483 detiphi.push_back((hhit->id()).iphi());
484 detieta.push_back((hhit->id()).ieta());
485 i3i5.push_back(iii3i5);
492 rawEnergyVec.push_back(hhit->energy() * recal * corrHCAL);
493 detidvec.push_back(hhit->id());
494 detiphi.push_back((hhit->id()).iphi());
495 detieta.push_back((hhit->id()).ieta());
496 i3i5.push_back(iii3i5);
505 if(AxB_!=
"3x3" && AxB_!=
"5x5" && AxB_!=
"7x7" && AxB_!=
"Cone")
LogWarning(
" AxB ")<<
" Not supported: "<< AxB_;
509 input_to_L3 << rawEnergyVec.size() <<
" " << calEnergy;
512 for (
unsigned int i=0;
i<rawEnergyVec.size();
i++)
514 input_to_L3 <<
" " << rawEnergyVec.at(
i) <<
" " << detidvec.at(
i).rawId() ;
519 eventNumber = iEvent.
id().
event();
524 numberOfCells=rawEnergyVec.size();
527 for (
unsigned int ia=0; ia<numberOfCells; ++ia) {
528 cellEnergy = rawEnergyVec.at(ia);
529 cell = detidvec.at(ia).rawId();
531 new((*cells)[ia])
TCell(cell, cellEnergy);
542 rawEnergyVec.clear();
561 bool hitIsUsed=
false;
562 DetId hitId=hoItr->id();
563 for (uint32_t
i=0;
i<usedHits.size();
i++)
565 if (usedHits[
i]==hitId) hitIsUsed=
true;
567 if (hitIsUsed)
continue;
569 usedHits.push_back(hitId);
588 if (!allowMissingInputs_)
throw e;
602 input_to_L3.open(
"input_to_l3.txt");
604 rootFile =
new TFile(
"rootFile.root",
"RECREATE");
605 tree =
new TTree(
"hcalCalibTree",
"Tree for IsoTrack Calibration");
606 cells =
new TClonesArray(
"TCell", 10000);
610 tagJetP4 =
new TLorentzVector();
611 probeJetP4 =
new TLorentzVector();
613 tree->Branch(
"cells", &cells, 64000, 0);
614 tree->Branch(
"targetE", &targetE,
"targetE/F");
615 tree->Branch(
"emEnergy", &emEnergy,
"emEnergy/F");
617 tree->Branch(
"PxTrkHcal", &PxTrkHcal,
"PxTrkHcal/F");
618 tree->Branch(
"PyTrkHcal", &PyTrkHcal,
"PyTrkHcal/F");
619 tree->Branch(
"PzTrkHcal", &PzTrkHcal,
"PzTrkHcal/F");
622 tree->Branch(
"xTrkHcal", &xTrkHcal,
"xTrkHcal/F");
623 tree->Branch(
"yTrkHcal", &yTrkHcal,
"yTrkHcal/F");
624 tree->Branch(
"zTrkHcal", &zTrkHcal,
"zTrkHcal/F");
626 tree->Branch(
"iEtaHit", &iEtaHit,
"iEtaHit/I");
627 tree->Branch(
"iPhiHit", &iPhiHit,
"iPhiHit/i");
628 tree->Branch(
"eventNumber", &eventNumber,
"eventNumber/i");
631 tree->Branch(
"tagJetP4",
"TLorentzVector", &tagJetP4);
632 tree->Branch(
"probeJetP4",
"TLorentzVector", &probeJetP4);
633 tree->Branch(
"etVetoJet", &etVetoJet,
"etVetoJet/F");
634 tree->Branch(
"tagJetEmFrac", &tagJetEmFrac,
"tagJetEmFrac/F");
635 tree->Branch(
"probeJetEmFrac", &probeJetEmFrac,
"probeJetEmFrac/F");
648 if (cells)
delete cells;
652 if (tagJetP4)
delete tagJetP4;
653 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)
double getDistInPlaneTrackDir(const GlobalPoint caloPoint, const GlobalVector caloVector, const GlobalPoint rechitPoint)
std::vector< HBHERecHit >::const_iterator const_iterator
TrackDetectorAssociator trackAssociator_
DEFINE_FWK_MODULE(HiMixingModule)
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
edm::EDGetTokenT< HORecHitCollection > tok_ho_
T const * product() const
virtual void endJob() override
std::string m_inputTrackLabel
virtual void beginJob() override
edm::EDGetTokenT< reco::TrackCollection > tok_track1_
const_iterator begin() const