78 void endJob()
override ;
118 float genPt[500], genPhi[500], genEta[500];
119 float isoPt[500], isoPhi[500], isoEta[500];
120 float pixPt[500], pixPhi[500], pixEta[500];
185 float numVH,
numVS, numValidTrkHits, numValidTrkStrips;
217 tok_track_ = consumes<reco::IsolatedPixelTrackCandidateCollection>(iConfig.
getParameter<
edm::InputTag>(
"HcalIsolTrackInput"));
220 associationConeSize_=iConfig.
getParameter<
double>(
"associationConeSize");
227 calibrationConeSize_=iConfig.
getParameter<
double>(
"calibrationConeSize");
229 MinNTrackHitsBarrel = iConfig.
getParameter<
int>(
"MinNTrackHitsBarrel");
230 MinNTECHitsEndcap = iConfig.
getParameter<
int>(
"MinNTECHitsEndcap");
231 energyECALmip = iConfig.
getParameter<
double>(
"energyECALmip");
232 energyMinIso = iConfig.
getParameter<
double>(
"energyMinIso");
233 energyMaxIso = iConfig.
getParameter<
double>(
"energyMaxIso");
238 parameters_.loadParameters( parameters, iC );
239 trackAssociator_.useDefaultPropagator();
265 respRecalib = recalibCorrs.
product();
267 LogInfo(
"CalibConstants")<<
" Loaded: OK ";
270 LogWarning(
"CalibConstants")<<
" Not Found!! ";
274 iEvent.
getByToken(tok_genTrack_, generalTracks);
302 parameters_.useEcal =
true;
303 parameters_.useHcal =
true;
304 parameters_.useCalo =
false;
305 parameters_.useMuon =
false;
311 if (isoPixelTracks->empty())
return;
314 for (reco::TrackCollection::const_iterator trit=isoProdTracks->begin(); trit!=isoProdTracks->end(); trit++)
317 reco::IsolatedPixelTrackCandidateCollection::const_iterator isoMatched=isoPixelTracks->begin();
322 for (reco::IsolatedPixelTrackCandidateCollection::const_iterator it = isoPixelTracks->begin(); it!=isoPixelTracks->end(); it++)
326 if (
abs((trit->pt() - it->pt())/it->pt()) < 0.005 &&
abs(trit->eta() - it->eta()) < 0.01)
335 if (!matched)
continue;
336 if(isoMatched->maxPtPxl() > maxPNear)
continue;
338 ptNear = isoMatched->maxPtPxl();
343 if (trit->hitPattern().numberOfValidHits()<MinNTrackHitsBarrel)
continue;
344 if (fabs(trit->eta())>1.47&&trit->hitPattern().numberOfValidStripTECHits()<MinNTECHitsEndcap)
continue;
349 numVH = trit->hitPattern().numberOfValidHits();
350 numVS = trit->hitPattern().numberOfValidStripTECHits();
354 trackE =
sqrt(trit->px()*trit->px()+trit->py()*trit->py()+trit->pz()*trit->pz()+0.14*0.14);
359 emEnergy = isoMatched->energyIn();
364 TrackDetMatchInfo info = trackAssociator_.associate(iEvent, iSetup,trackAssociator_.getFreeTrajectoryState(iSetup, *trit), parameters_);
380 if (xTrkEcal==0 && yTrkEcal==0&& zTrkEcal==0) {
cout<<
"zero point at Ecal"<<endl;
continue;}
381 if (xTrkHcal==0 && yTrkHcal==0&& zTrkHcal==0) {
cout<<
"zero point at Hcal"<<endl;
continue;}
391 GlobalPoint gPointEcal(xTrkEcal,yTrkEcal,zTrkEcal);
392 GlobalPoint gPointHcal(xTrkHcal,yTrkHcal,zTrkHcal);
397 ietatrue = tempId.
ieta();
398 iphitrue = tempId.
iphi();
406 std::vector<DetId> usedHits;
423 bool hitIsUsed=
false;
424 for (uint32_t
i=0;
i<usedHits.size();
i++)
426 if (usedHits[
i]==hhit->id()) hitIsUsed=
true;
428 if (hitIsUsed)
continue;
429 usedHits.push_back(hhit->id());
440 int iphihitm = (hhit->id()).iphi();
441 int ietahitm = (hhit->id()).ieta();
442 int depthhit = (hhit->id()).
depth();
443 float enehit = hhit->energy() * recal;
445 if (depthhit!=1)
continue;
458 if(distAtHcal < associationConeSize_)
463 int iphihitm2 = (hhit2->id()).iphi();
464 int ietahitm2 = (hhit2->id()).ieta();
465 int depthhit2 = (hhit2->id()).
depth();
466 float enehit2 = hhit2->energy() * recal;
468 if (iphihitm==iphihitm2 && ietahitm==ietahitm2 && depthhit!=depthhit2) enehit = enehit+enehit2;
480 MaxHit.
ietahitm = (hhit->id()).ieta();
481 MaxHit.
iphihitm = (hhit->id()).iphi();
482 MaxHit.
dr = distAtHcal;
499 Bool_t passCuts = kFALSE;
500 if(trackE > energyMinIso && trackE < energyMaxIso && emEnergy < energyECALmip && MaxHit.hitenergy > 0. &&
abs(MaxHit.
ietahitm)<29) passCuts = kTRUE;
524 bool hitIsUsed=
false;
525 for (uint32_t
i=0;
i<usedHits.size();
i++)
527 if (usedHits[
i]==hhit->id()) hitIsUsed=
true;
529 if (hitIsUsed)
continue;
530 usedHits.push_back(hhit->id());
533 if(MaxHit.
ietahitm*(hhit->id()).ieta()>0)
535 DIETA = MaxHit.
ietahitm - (hhit->id()).ieta();
537 if(MaxHit.
ietahitm*(hhit->id()).ieta()<0)
539 DIETA = MaxHit.
ietahitm - (hhit->id()).ieta();
540 DIETA = DIETA>0 ? DIETA-1 : DIETA+1;
543 int DIPHI =
abs(MaxHit.
iphihitm - (hhit->id()).iphi());
544 DIPHI = DIPHI>36 ? 72-DIPHI : DIPHI;
556 if(
abs(DIETA)<=numbercell && (
abs(DIPHI)<=numbercell || (
abs(MaxHit.
ietahitm)>=20 &&
abs(DIPHI)<=numbercell+1)) )
558 const GlobalPoint pos2 = geo->getPosition(hhit->detid());
560 if(passCuts && hhit->energy()>0)
566 factor = respRecalib -> getValues(hhit->id())->
getValue();
572 if (hhit->id().ieta() == MaxHit.
ietahitm && hhit->id().iphi() == MaxHit.
iphihitm) CentHitFactor=factor;
574 if (hhit->id().ieta() == MaxHit.
ietahitm && hhit->id().iphi() == MaxHit.
iphihitm) iTime = hhit->time();
576 if(AxB_!=
"3x3" && AxB_!=
"5x5" && AxB_!=
"Cone")
LogWarning(
" AxB ")<<
" Not supported: "<< AxB_;
582 e5x5Before += hhit->energy();
583 e5x5After += hhit->energy()*factor;
590 e3x3Before += hhit->energy();
591 e3x3After += hhit->energy()*factor;
600 if (
abs(MaxHit.
ietahitm)==21 &&
abs((hhit->id()).ieta())<=20 &&
abs(DIPHI)>3)
continue;
602 HTime[numHits]= hhit->time();
605 eClustBefore += hhit->energy();
606 eClustAfter += hhit->energy()*factor;
608 if ((hhit->id().depth() == 1) && (
abs(hhit->id().ieta()) > 17) && (
abs(hhit->id().ieta()) < 29))
610 eBeforeDepth1 += hhit->energy();
611 eAfterDepth1 += hhit->energy()*factor;
613 else if((hhit->id().depth() == 2) && (
abs(hhit->id().ieta()) > 17) && (
abs(hhit->id().ieta()) < 29))
615 eBeforeDepth2 += hhit->energy();
616 eAfterDepth2 += hhit->energy()*factor;
627 if (
abs(MaxHit.
ietahitm)==21 &&
abs((hhit->id()).ieta())<=20 &&
abs(DIPHI)>2)
continue;
629 HTime[numHits]= hhit->time();
632 eClustBefore += hhit->energy();
633 eClustAfter += hhit->energy() * factor;
635 if ((hhit->id().depth() == 1) && (
abs(hhit->id().ieta()) > 17) && (
abs(hhit->id().ieta()) < 29))
637 eBeforeDepth1 += hhit->energy();
638 eAfterDepth1 += hhit->energy() * factor;
640 else if((hhit->id().depth() == 2) && (
abs(hhit->id().ieta()) > 17) && (
abs(hhit->id().ieta()) < 29))
642 eBeforeDepth2 += hhit->energy();
643 eAfterDepth2 += hhit->energy() * factor;
652 HTime[numHits]= hhit->time();
655 eClustBefore += hhit->energy();
656 eClustAfter += hhit->energy() * factor;
658 if ((hhit->id().depth() == 1) && (
abs(hhit->id().ieta()) > 17) && (
abs(hhit->id().ieta()) < 29))
660 eBeforeDepth1 += hhit->energy();
661 eAfterDepth1 += hhit->energy() * factor;
663 else if((hhit->id().depth() == 2) && (
abs(hhit->id().ieta()) > 17) && (
abs(hhit->id().ieta()) < 29))
665 eBeforeDepth2 += hhit->energy();
666 eAfterDepth2 += hhit->energy() * factor;
684 diphi_M_P = diphi_M_P>36 ? 72-diphi_M_P : diphi_M_P;
690 eventNumber = iEvent.
id().
event();
694 eCentHitAfter = MaxHit.
hitenergy*CentHitFactor;
696 numValidTrkHits = numVH;
697 numValidTrkStrips = numVS;
710 iDr =
sqrt(diphi_M_P*diphi_M_P+dieta_M_P*dieta_M_P);
724 int n = generalTracks->size();
727 if(takeGenTracks_ && iEvent.
id().
event()%10==1)
729 gen = generalTracks->size();
730 iso = isoProdTracks->size();
731 pix = isoPixelTracks->size();
745 Int_t gencount=0, isocount=0, pixcount=0;
746 for (reco::TrackCollection::const_iterator gentr=generalTracks->begin(); gentr!=generalTracks->end(); gentr++)
748 genPt[gencount] = gentr->pt();
749 genPhi[gencount] = gentr->phi();
750 genEta[gencount] = gentr->eta();
754 for (reco::TrackCollection::const_iterator isotr=isoProdTracks->begin(); isotr!=isoProdTracks->end(); isotr++)
756 isoPt[isocount] = isotr->pt();
757 isoPhi[isocount] = isotr->phi();
758 isoEta[isocount] = isotr->eta();
762 for (reco::IsolatedPixelTrackCandidateCollection::const_iterator pixtr=isoPixelTracks->begin(); pixtr!=isoPixelTracks->end(); pixtr++)
764 pixPt[pixcount] = pixtr->pt();
765 pixPhi[pixcount] = pixtr->phi();
766 pixEta[pixcount] = pixtr->eta();
799 nTracks = fs->make<TH1F>(
"nTracks",
"general;number of general tracks",11,-0.5,10.5);
802 tTree = fs->make<TTree>(
"tTree",
"Tree for gen info");
804 fTree = fs->make<TTree>(
"fTree",
"Tree for IsoTrack Calibration");
806 fTree->Branch(
"eventNumber", &eventNumber,
"eventNumber/I");
807 fTree->Branch(
"runNumber", &
runNumber,
"runNumber/I");
809 fTree->Branch(
"eClustBefore", &eClustBefore,
"eClustBefore/F");
810 fTree->Branch(
"eClustAfter", &eClustAfter,
"eClustAfter/F");
811 fTree->Branch(
"eTrack", &eTrack,
"eTrack/F");
812 fTree->Branch(
"etaTrack", &etaTrack,
"etaTrack/F");
813 fTree->Branch(
"phiTrack", &phiTrack,
"phiTrack/F");
815 fTree->Branch(
"numHits", &numHits,
"numHits/I");
816 fTree->Branch(
"eECAL", &eECAL,
"eECAL/F");
817 fTree->Branch(
"PtNearBy", &PtNearBy,
"PtNearBy/F");
818 fTree->Branch(
"numValidTrkHits", &numValidTrkHits,
"numValidTrkHits/F");
819 fTree->Branch(
"numValidTrkStrips", &numValidTrkStrips,
"numValidTrkStrips/F");
821 fTree->Branch(
"eBeforeDepth1", &eBeforeDepth1,
"eBeforeDepth1/F");
822 fTree->Branch(
"eBeforeDepth2", &eBeforeDepth2,
"eBeforeDepth2/F");
823 fTree->Branch(
"eAfterDepth1", &eAfterDepth1,
"eAfterDepth1/F");
824 fTree->Branch(
"eAfterDepth2", &eAfterDepth2,
"eAfterDepth2/F");
826 fTree->Branch(
"e3x3Before", &e3x3Before,
"e3x3Before/F");
827 fTree->Branch(
"e3x3After", &e3x3After,
"e3x3After/F");
828 fTree->Branch(
"e5x5Before", &e5x5Before,
"e5x5Before/F");
829 fTree->Branch(
"e5x5After", &e5x5After,
"e5x5After/F");
831 fTree->Branch(
"eCentHitAfter", &eCentHitAfter,
"eCentHitAfter/F");
832 fTree->Branch(
"eCentHitBefore", &eCentHitBefore,
"eCentHitBefore/F");
833 fTree->Branch(
"iEta", &iEta,
"iEta/I");
834 fTree->Branch(
"iPhi", &iPhi,
"iPhi/I");
837 fTree->Branch(
"iEtaTr", &iEtaTr,
"iEtaTr/I");
838 fTree->Branch(
"iPhiTr", &iPhiTr,
"iPhiTr/I");
839 fTree->Branch(
"dietatr", &dietatr,
"dietatr/I");
840 fTree->Branch(
"diphitr", &diphitr,
"diphitr/I");
841 fTree->Branch(
"iDr", &iDr,
"iDr/F");
842 fTree->Branch(
"delR", &delR,
"delR/F");
844 fTree->Branch(
"iTime", &iTime,
"iTime/F");
845 fTree->Branch(
"HTime", HTime,
"HTime[numHits]/F");
847 fTree->Branch(
"xTrkEcal", &xTrkEcal,
"xTrkEcal/F");
848 fTree->Branch(
"yTrkEcal", &yTrkEcal,
"yTrkEcal/F");
849 fTree->Branch(
"zTrkEcal", &zTrkEcal,
"zTrkEcal/F");
850 fTree->Branch(
"xTrkHcal", &xTrkHcal,
"xTrkHcal/F");
851 fTree->Branch(
"yTrkHcal", &yTrkHcal,
"yTrkHcal/F");
852 fTree->Branch(
"zTrkHcal", &zTrkHcal,
"zTrkHcal/F");
855 tTree->Branch(
"gen", &
gen,
"gen/I");
856 tTree->Branch(
"iso", &iso,
"iso/I");
857 tTree->Branch(
"pix", &pix,
"pix/I");
858 tTree->Branch(
"genPt",
genPt,
"genPt[gen]/F");
859 tTree->Branch(
"genPhi", genPhi,
"genPhi[gen]/F");
860 tTree->Branch(
"genEta", genEta,
"genEta[gen]/F");
862 tTree->Branch(
"isoPt", isoPt,
"isoPt[iso]/F");
863 tTree->Branch(
"isoPhi", isoPhi,
"isoPhi[iso]/F");
864 tTree->Branch(
"isoEta", isoEta,
"isoEta[iso]/F");
866 tTree->Branch(
"pixPt", pixPt,
"pixPt[pix]/F");
867 tTree->Branch(
"pixPhi", pixPhi,
"pixPhi[pix]/F");
868 tTree->Branch(
"pixEta", pixEta,
"pixEta[pix]/F");
edm::EDGetTokenT< reco::TrackCollection > tok_genTrack_
T getParameter(std::string const &) const
EventNumber_t event() const
T getUntrackedParameter(std::string const &, T const &) const
const unsigned int nTracks(const reco::Vertex &sv)
~ValidIsoTrkCalib() override
virtual example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
void analyze(const edm::Event &, const edm::EventSetup &) override
#define DEFINE_FWK_MODULE(type)
std::vector< HBHERecHit >::const_iterator const_iterator
TrackAssociatorParameters parameters_
math::XYZPoint trkGlobPosAtHcal
edm::EDGetTokenT< reco::IsolatedPixelTrackCandidateCollection > tok_track_
double calibrationConeSize_
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
int ieta() const
get the cell ieta
Abs< T >::type abs(const T &t)
TrackDetectorAssociator trackAssociator_
edm::EDGetTokenT< HBHERecHitCollection > tok_hbhe_
const HcalRespCorrs * respRecalib
def gen(fragment, howMuch)
Production test section ####.
ValidIsoTrkCalib(const edm::ParameterSet &)
std::vector< edm::InputTag > genecalLabel_
const_iterator end() const
int iphi() const
get the cell iphi
T const * product() const
edm::Service< TFileService > fs
edm::EDGetTokenT< HORecHitCollection > tok_ho_
math::XYZPoint trkGlobPosAtEcal
Track position at different parts of the calorimeter.
const JetExtendedData & getValue(const Container &, const reco::JetBaseRef &)
get value for the association. Throw exception if no association found
double getDistInPlaneSimple(const GlobalPoint caloPoint, const GlobalPoint rechitPoint)
double associationConeSize_
edm::EDGetTokenT< reco::TrackCollection > tok_track1_
T const * product() const
DetId getClosestCell(const GlobalPoint &r) const override
const_iterator begin() const