76 #include "TObjArray.h"
77 #include "TClonesArray.h"
78 #include "TRefArray.h"
79 #include "TLorentzVector.h"
103 virtual void endJob() ;
182 associationConeSize_=iConfig.
getParameter<
double>(
"associationConeSize");
184 outputFileName_=iConfig.
getParameter<std::string>(
"outputFileName");
187 calibrationConeSize_=iConfig.
getParameter<
double>(
"calibrationConeSize");
189 nIterations = iConfig.
getParameter<
int>(
"noOfIterations");
190 eventWeight = iConfig.
getParameter<
double>(
"eventWeight");
191 energyMinIso = iConfig.
getParameter<
double>(
"energyMinIso");
192 energyMaxIso = iConfig.
getParameter<
double>(
"energyMaxIso");
193 energyECALmip = iConfig.
getParameter<
double>(
"energyECALmip");
195 MinNTrackHitsBarrel = iConfig.
getParameter<
int>(
"MinNTrackHitsBarrel");
196 MinNTECHitsEndcap = iConfig.
getParameter<
int>(
"MinNTECHitsEndcap");
197 hottestHitDistance = iConfig.
getParameter<
double>(
"hottestHitDistance");
199 EcalConeOuter = iConfig.
getParameter<
double>(
"EcalConeOuter");
202 parameters_.loadParameters( parameters );
203 trackAssociator_.useDefaultPropagator();
218 vector<float> rawEnergyVec;
222 vector<HcalDetId> detidvec;
226 iEvent.
getByLabel(trackLabel1_,isoProdTracks);
229 iEvent.
getByLabel(trackLabel_,isoPixelTracks);
255 parameters_.useEcal =
true;
256 parameters_.useHcal =
true;
257 parameters_.useCalo =
false;
258 parameters_.useMuon =
false;
259 parameters_.dREcal = 0.5;
260 parameters_.dRHcal = 0.6;
262 if (isoPixelTracks->size()==0)
return;
264 for (reco::TrackCollection::const_iterator trit=isoProdTracks->begin(); trit!=isoProdTracks->end(); trit++)
266 reco::IsolatedPixelTrackCandidateCollection::const_iterator isoMatched=isoPixelTracks->begin();
270 for (reco::IsolatedPixelTrackCandidateCollection::const_iterator it = isoPixelTracks->begin(); it!=isoPixelTracks->end(); it++)
273 if (
abs((trit->pt() - it->pt())/it->pt()) < 0.005 &&
abs(trit->eta() - it->eta()) < 0.01)
280 if (!matched)
continue;
282 if (trit->hitPattern().numberOfValidHits()<MinNTrackHitsBarrel)
continue;
283 if (fabs(trit->eta())>1.47&&trit->hitPattern().numberOfValidStripTECHits()<MinNTECHitsEndcap)
continue;
286 calEnergy =
sqrt(trit->px()*trit->px()+trit->py()*trit->py()+trit->pz()*trit->pz()+0.14*0.14);
291 double corrHCAL = 1.;
295 rvert =
sqrt(trit->vx()*trit->vx()+trit->vy()*trit->vy()+trit->vz()*trit->vz());
298 TrackDetMatchInfo info = trackAssociator_.associate(iEvent, iSetup,trackAssociator_.getFreeTrajectoryState(iSetup, *trit),parameters_);
301 xTrkHcal=info.trkGlobPosAtHcal.x();
302 yTrkHcal=info.trkGlobPosAtHcal.y();
303 zTrkHcal=info.trkGlobPosAtHcal.z();
305 xTrkEcal=info.trkGlobPosAtEcal.x();
306 yTrkEcal=info.trkGlobPosAtEcal.y();
307 zTrkEcal=info.trkGlobPosAtEcal.z();
309 if (xTrkEcal==0 && yTrkEcal==0&& zTrkEcal==0) {
cout<<
"zero point at Ecal"<<endl;
continue;}
310 if (xTrkHcal==0 && yTrkHcal==0&& zTrkHcal==0) {
cout<<
"zero point at Hcal"<<endl;
continue;}
314 PxTrkHcal = trackMomAtHcal.
x();
315 PyTrkHcal = trackMomAtHcal.
y();
316 PzTrkHcal = trackMomAtHcal.
z();
322 GlobalPoint gPointEcal(xTrkEcal,yTrkEcal,zTrkEcal);
323 GlobalPoint gPointHcal(xTrkHcal,yTrkHcal,zTrkHcal);
334 const HcalDetId tempId = gHcal->getClosestCell(gPointHcal);
335 ietatrue = tempId.
ieta();
336 iphitrue = tempId.
iphi();
340 std::vector<int> usedHits;
355 bool hitIsUsed=
false;
356 int hitHashedIndex=hhit->id().hashed_index();
357 for (uint32_t
i=0;
i<usedHits.size();
i++)
359 if (usedHits[
i]==hitHashedIndex) hitIsUsed=
true;
361 if (hitIsUsed)
continue;
362 usedHits.push_back(hitHashedIndex);
371 int iphihitm = (hhit->id()).iphi();
372 int ietahitm = (hhit->id()).ieta();
373 int depthhit = (hhit->id()).depth();
374 double enehit = hhit->energy() * recal;
376 if (depthhit!=1)
continue;
383 if(distAtHcal < associationConeSize_)
387 int iphihitm2 = (hhit2->id()).iphi();
388 int ietahitm2 = (hhit2->id()).ieta();
389 int depthhit2 = (hhit2->id()).depth();
390 double enehit2 = hhit2->energy() * recal;
392 if ( iphihitm==iphihitm2 && ietahitm==ietahitm2 && depthhit!=depthhit2){
394 enehit = enehit+enehit2;
401 MaxHit.
ietahitm = (hhit->id()).ieta();
402 MaxHit.
iphihitm = (hhit->id()).iphi();
403 MaxHit.
depthhit = (hhit->id()).depth();
404 MaxHit.
dr = distAtHcal;
406 MaxHit.
posMax = geo->getPosition(hhit->detid());
413 Bool_t passCuts = kFALSE;
414 if(calEnergy > energyMinIso && calEnergy < energyMaxIso && emEnergy < energyECALmip &&
416 MaxHit.
dr < hottestHitDistance && emRingEnergy<8.){ passCuts = kTRUE; }
419 if(AxB_==
"5x5" || AxB_==
"3x3" || AxB_==
"7x7"|| AxB_==
"Cone")
430 bool hitIsUsed=
false;
431 int hitHashedIndex=hhit->id().hashed_index();
432 for (uint32_t
i=0;
i<usedHits.size();
i++)
434 if (usedHits[
i]==hitHashedIndex) hitIsUsed=
true;
441 usedHits.push_back(hitHashedIndex);
445 if(MaxHit.
ietahitm*(hhit->id()).ieta()>0)
447 DIETA = MaxHit.
ietahitm - (hhit->id()).ieta();
449 if(MaxHit.
ietahitm*(hhit->id()).ieta()<0)
451 DIETA = MaxHit.
ietahitm - (hhit->id()).ieta();
452 DIETA = DIETA>0 ? DIETA-1 : DIETA+1;
455 int DIPHI =
abs(MaxHit.
iphihitm - (hhit->id()).iphi());
456 DIPHI = DIPHI>36 ? 72-DIPHI : DIPHI;
460 if(AxB_==
"3x3") numbercell = 1;
461 if(AxB_==
"5x5") numbercell = 2;
462 if(AxB_==
"7x7") numbercell = 3;
463 if(AxB_==
"Cone") numbercell = 1000;
465 if(
abs(DIETA)<=numbercell && (
abs(DIPHI)<=numbercell || (
abs(MaxHit.
ietahitm)>=20 &&
abs(DIPHI)<=numbercell+1)) ) {
472 const GlobalPoint pos2 = geo->getPosition(hhit->detid());
476 if(AxB_==
"5x5" || AxB_==
"3x3" || AxB_==
"7x7") {
478 rawEnergyVec.push_back(hhit->energy() * recal * corrHCAL);
479 detidvec.push_back(hhit->id());
480 detiphi.push_back((hhit->id()).iphi());
481 detieta.push_back((hhit->id()).ieta());
482 i3i5.push_back(iii3i5);
489 rawEnergyVec.push_back(hhit->energy() * recal * corrHCAL);
490 detidvec.push_back(hhit->id());
491 detiphi.push_back((hhit->id()).iphi());
492 detieta.push_back((hhit->id()).ieta());
493 i3i5.push_back(iii3i5);
502 if(AxB_!=
"3x3" && AxB_!=
"5x5" && AxB_!=
"7x7" && AxB_!=
"Cone")
LogWarning(
" AxB ")<<
" Not supported: "<< AxB_;
506 input_to_L3 << rawEnergyVec.size() <<
" " << calEnergy;
509 for (
unsigned int i=0;
i<rawEnergyVec.size();
i++)
511 input_to_L3 <<
" " << rawEnergyVec.at(
i) <<
" " << detidvec.at(
i).rawId() ;
516 eventNumber = iEvent.
id().
event();
521 numberOfCells=rawEnergyVec.size();
524 for (
unsigned int ia=0; ia<numberOfCells; ++ia) {
525 cellEnergy = rawEnergyVec.at(ia);
526 cell = detidvec.at(ia).rawId();
528 new((*cells)[ia])
TCell(cell, cellEnergy);
539 rawEnergyVec.clear();
558 bool hitIsUsed=
false;
559 int hitHashedIndex=hoItr->id().hashed_index();
560 for (uint32_t
i=0;
i<usedHits.size();
i++)
562 if (usedHits[
i]==hitHashedIndex) hitIsUsed=
true;
564 if (hitIsUsed)
continue;
585 if (!allowMissingInputs_)
throw e;
599 input_to_L3.open(
"input_to_l3.txt");
601 rootFile =
new TFile(
"rootFile.root",
"RECREATE");
602 tree =
new TTree(
"hcalCalibTree",
"Tree for IsoTrack Calibration");
603 cells =
new TClonesArray(
"TCell", 10000);
607 tagJetP4 =
new TLorentzVector();
608 probeJetP4 =
new TLorentzVector();
610 tree->Branch(
"cells", &cells, 64000, 0);
611 tree->Branch(
"targetE", &targetE,
"targetE/F");
612 tree->Branch(
"emEnergy", &emEnergy,
"emEnergy/F");
614 tree->Branch(
"PxTrkHcal", &PxTrkHcal,
"PxTrkHcal/F");
615 tree->Branch(
"PyTrkHcal", &PyTrkHcal,
"PyTrkHcal/F");
616 tree->Branch(
"PzTrkHcal", &PzTrkHcal,
"PzTrkHcal/F");
619 tree->Branch(
"xTrkHcal", &xTrkHcal,
"xTrkHcal/F");
620 tree->Branch(
"yTrkHcal", &yTrkHcal,
"yTrkHcal/F");
621 tree->Branch(
"zTrkHcal", &zTrkHcal,
"zTrkHcal/F");
623 tree->Branch(
"iEtaHit", &iEtaHit,
"iEtaHit/I");
624 tree->Branch(
"iPhiHit", &iPhiHit,
"iPhiHit/i");
625 tree->Branch(
"eventNumber", &eventNumber,
"eventNumber/i");
628 tree->Branch(
"tagJetP4",
"TLorentzVector", &tagJetP4);
629 tree->Branch(
"probeJetP4",
"TLorentzVector", &probeJetP4);
630 tree->Branch(
"etVetoJet", &etVetoJet,
"etVetoJet/F");
631 tree->Branch(
"tagJetEmFrac", &tagJetEmFrac,
"tagJetEmFrac/F");
632 tree->Branch(
"probeJetEmFrac", &probeJetEmFrac,
"probeJetEmFrac/F");
645 if (cells)
delete cells;
649 if (tagJetP4)
delete tagJetP4;
650 if (probeJetP4)
delete probeJetP4;
T getParameter(std::string const &) const
EventNumber_t event() const
T getUntrackedParameter(std::string const &, T const &) 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< T >::const_iterator const_iterator
void push_back(T const &t)
TrackDetectorAssociator trackAssociator_
double calibrationConeSize_
TLorentzVector * probeJetP4
int ieta() const
get the cell ieta
virtual void analyze(const edm::Event &, const edm::EventSetup &)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
TLorentzVector * tagJetP4
double hottestHitDistance
const_iterator end() const
TrackAssociatorParameters parameters_
int iphi() const
get the cell iphi
T const * product() const
std::string m_inputTrackLabel
const_iterator begin() const