34 #include "TDecompSVD.h"
35 #include "TDecompQRH.h"
71 TString option = GetOption();
75 if (APPLY_PHI_SYM_COR_FLAG && !ReadPhiSymCor()) {
76 cout <<
"\nERROR: Failed to read the phi symmetry corrections." << endl;
77 cout <<
"Check if the filename is correct. If the corrections are not needed, set the corresponding flag to \"false\"\n" << endl;
79 cout <<
"\nThe program will be terminated\n" << endl;
90 histoFile =
new TFile(HISTO_FILENAME.Data(),
"RECREATE");
93 h1_trkP =
new TH1F(
"h1_trkP",
"Track momenta; p_{trk} (GeV); Number of tracks", 100, 0, 200);
94 h1_allTrkP =
new TH1F(
"h1_allTrkP",
"Track momenta - all tracks; p_{trk} (GeV); Number of tracks", 100, 0, 200);
96 h1_selTrkP_iEta10 =
new TH1F(
"h1_selTrkP_iEta10",
"Track momenta - tracks with |iEta|<10; p_{trk} (GeV); Number of tracks", 100, 0, 200);
100 if (CALIB_TYPE==
"ISO_TRACK")
101 h1_rawSumE =
new TH1F(
"h1_rawSumE",
"Cluster Energy; E_{cl} (GeV); Number of tracks", 100, 0, 200);
103 h1_rawSumE =
new TH1F(
"h1_rawSumE",
"Cluster Energy; E_{cl} (GeV); Number of tracks", 1000, 0, 2000);
107 h1_rawResp =
new TH1F(
"h1_rawResp",
"Uncorrected response: |iEta|<24; E_{had}/p; Number of tracks", 300, 0, 3);
108 h1_corResp =
new TH1F(
"h1_corResp",
"Corrected response: |iEta|<24; E_{had}/p; Number of tracks", 300, 0, 3);
110 h1_rawRespBarrel =
new TH1F(
"h1_rawRespBarrel",
"Uncorrected response: |iEta|<15; E_{had}/p; Number of tracks", 300, 0, 3);
111 h1_corRespBarrel =
new TH1F(
"h1_corRespBarrel",
"Corrected response: |iEta|<15; E_{had}/p; Number of tracks", 300, 0, 3);
113 h1_rawRespEndcap =
new TH1F(
"h1_rawRespEndcap",
"Uncorrected response: 17<|iEta|<24; E_{had}/p; Number of tracks", 300, 0, 3);
114 h1_corRespEndcap =
new TH1F(
"h1_corRespEndcap",
"Corrected response: 17<|iEta|<24; E_{had}/p; Number of tracks", 300, 0, 3);
118 h2_dHitRefBarrel =
new TH2F(
"h2_dHitRefBarrel",
"{#Delta}i{#phi} vs {#Delta}i{#eta} of hit and most energetic tower(|i{#eta}|<16);{#Delta}i{#eta}; {#Delta}i{#phi}", 10, -5, 5, 10, -5, 5);
119 h2_dHitRefEndcap =
new TH2F(
"h2_dHitRefEndcap",
"{#Delta}i{#phi} vs {#Delta}i{#eta} of hit and most energetic tower (16<|i{#eta}|<25) ;{#Delta}i{#eta}; {#Delta}i{#phi}", 10, -5, 5, 10, -5, 5);
123 TString histoName =
"isoTrack_";
125 for (Int_t
i=0;
i<48; ++
i) {
127 if (
i<24) iEta =
i-24;
129 TString hn = histoName + iEta;
149 set<UInt_t> uniqueIds;
152 Bool_t acceptEvent = kTRUE;
161 if (targetE < MIN_TARGET_E || targetE > MAX_TARGET_E)
return kFALSE;;
165 vector<TCell> selectCells;
168 if (cells->GetSize()==0)
return kFALSE;
170 if (CALIB_TYPE==
"DI_JET" && probeJetEmFrac > 0.999)
return kTRUE;
173 for (Int_t
i=0;
i<cells->GetSize(); ++
i) {
182 cout <<
"Unknown or wrong hcal subdetector: " <<
HcalDetId(thisCell->
id()).subdet() << endl;
188 if (APPLY_PHI_SYM_COR_FLAG) thisCell->
SetE(phiSymCor[thisCell->
id()] * thisCell->
e());
190 if (thisCell->
e() > MIN_CELL_E) selectCells.push_back(*thisCell);
194 if (selectCells.size()==0) {
195 cout <<
"NO CELLS ABOVE THRESHOLD FOUND FOR TARGET!!!" << endl;
205 pair<Int_t, UInt_t> refPos;
207 Int_t dEtaHitRef = 999;
208 Int_t dPhiHitRef = 999;
210 if (CALIB_TYPE==
"ISO_TRACK") {
217 dEtaHitRef = iEtaMaxE - iEtaHit;
218 dPhiHitRef = iPhiMaxE - iPhiHit;
220 if (dPhiHitRef < -36) dPhiHitRef += 72;
221 if (dPhiHitRef > 36) dPhiHitRef -= 72;
223 if (iEtaHit*iEtaMaxE < 0) {
224 if (dEtaHitRef<0) dEtaHitRef += 1;
225 if (dEtaHitRef>0) dEtaHitRef -= 1;
236 if (!USE_CONE_CLUSTERING) {
237 if (
abs(iEtaMaxE)<16 && HB_CLUSTER_SIZE==3)
filterCells3x3(selectCells, iEtaMaxE, iPhiMaxE);
238 if (
abs(iEtaMaxE)>15 && HE_CLUSTER_SIZE==3)
filterCells3x3(selectCells, iEtaMaxE, iPhiMaxE);
240 if (
abs(iEtaMaxE)<16 && HB_CLUSTER_SIZE==5)
filterCells5x5(selectCells, iEtaMaxE, iPhiMaxE);
241 if (
abs(iEtaMaxE)>15 && HE_CLUSTER_SIZE==5)
filterCells5x5(selectCells, iEtaMaxE, iPhiMaxE);
245 const GlobalPoint hitPositionHcal(xTrkHcal, yTrkHcal, zTrkHcal);
251 refPos.first = iEtaMaxE;
252 refPos.second = iPhiMaxE;
255 else if (CALIB_TYPE==
"DI_JET") {
257 if (etVetoJet>MAX_ET_THIRD_JET) acceptEvent = kFALSE;
259 Float_t jetsDPhi = probeJetP4->DeltaPhi(*tagJetP4);
260 if (fabs(jetsDPhi * 180.0/
M_PI) < MIN_DPHI_DIJETS) acceptEvent = kFALSE;
262 if (probeJetEmFrac>MAX_PROBEJET_EMFRAC) acceptEvent = kFALSE;
263 if (fabs(probeJetP4->Eta())<MIN_PROBEJET_ABSETA) acceptEvent = kFALSE;
264 if (fabs(tagJetP4->Eta())>MAX_TAGJET_ABSETA) acceptEvent = kFALSE;
265 if (fabs(tagJetP4->Et())< MIN_TAGJET_ET) acceptEvent = kFALSE;
281 refPos.first = iEtaMaxE;
282 refPos.second = iPhiMaxE;
284 if (
abs(iEtaMaxE)>40) acceptEvent = kFALSE;
294 vector<Float_t> energies;
297 for (vector<TCell>::iterator i_it = selectCells.begin(); i_it!=selectCells.end(); ++i_it) {
301 if (uniqueIds.insert(i_it->id()).
second) {
302 energies.push_back(i_it->e());
303 ids.push_back(i_it->id());
308 if (CALIB_TYPE==
"ISO_TRACK") {
309 if (accumulate(energies.begin(), energies.end(), 0.0) / targetE < MIN_EOVERP) acceptEvent=kFALSE;
310 if (accumulate(energies.begin(), energies.end(), 0.0) / targetE > MAX_EOVERP) acceptEvent=kFALSE;
312 if (emEnergy > MAX_TRK_EME) acceptEvent=kFALSE;
314 if (
abs(dEtaHitRef)>1 ||
abs(dPhiHitRef)>1) acceptEvent=kFALSE;
323 h1_rawSumE->Fill(accumulate(energies.begin(), energies.end(), 0.0));
328 cellEnergies.push_back(energies);
329 cellIds.push_back(ids);
330 targetEnergies.push_back(targetE);
331 refIEtaIPhi.push_back(refPos);
333 if (
abs(refPos.first)<=10)
354 cout <<
"\n\nFinished reading the events.\n";
355 cout <<
"Number of input objects: " << cellIds.size() << endl;
356 cout <<
"Performing minimization: depending on selected method can take some time...\n\n";
358 for (vector<pair<Int_t, UInt_t> >::iterator it_rp=refIEtaIPhi.begin(); it_rp!=refIEtaIPhi.end(); ++it_rp ) {
359 Float_t
weight = (
abs(it_rp->first)<21)? 1.0/72.0 : 1.0/36.0;
363 if (CALIB_METHOD==
"MATRIX_INV_OF_ETA_AVE") {
364 GetCoefFromMtrxInvOfAve();
366 else if (CALIB_METHOD==
"L3" || CALIB_METHOD==
"L3_AND_MTRX_INV") {
369 int numIterations = 10;
371 solution = thisL3Algo->
iterate(cellEnergies, cellIds, targetEnergies, numIterations);
377 if (!SUM_DEPTHS && SUM_SMALL_DEPTHS) {
378 vector<UInt_t> idForSummedCells;
380 for (map<UInt_t, Float_t>::iterator m_it = solution.begin(); m_it != solution.end(); ++m_it) {
384 idForSummedCells.push_back(
HcalDetId(m_it->first));
387 for (vector<UInt_t>::iterator v_it=idForSummedCells.begin(); v_it!=idForSummedCells.end(); ++v_it) {
389 solution[addCoefId] = solution[*v_it];
395 if (CALIB_METHOD==
"L3_AND_MTRX_INV") {
396 GetCoefFromMtrxInvOfAve();
400 for (map<UInt_t, Float_t>::iterator it_s=solution.begin(); it_s!=solution.end(); ++it_s) {
402 if (
abs(iEtaSol)<CALIB_ABS_IETA_MIN ||
abs(iEtaSol)> CALIB_ABS_IETA_MAX) it_s->second = 1.0;
403 else it_s->second *= iEtaCoefMap[iEtaSol];
420 for (
unsigned int i=0;
i<cellEnergies.size(); ++
i) {
422 for (
unsigned int j=0;
j<(cellEnergies[
i]).
size(); ++
j) {
424 rawResp += (cellEnergies[
i])[j];
426 if (CALIB_METHOD==
"L3_AND_MTRX_INV") {
427 corResp += (solution[cellIds[
i][
j]] * cellEnergies[
i][
j]);
429 else if (CALIB_METHOD==
"L3") {
430 corResp += (solution[cellIds[
i][
j]] * (cellEnergies[
i][
j]));
432 else if (CALIB_METHOD==
"MATRIX_INV_OF_ETA_AVE") {
433 corResp += (iEtaCoefMap[iEta]* cellEnergies[
i][
j]);
436 if (maxIEta <
abs(iEta) ) maxIEta =
abs(iEta);
437 if (minIEta >
abs(iEta) ) minIEta =
abs(iEta);
440 rawResp /= targetEnergies[
i];
441 corResp /= targetEnergies[
i];
447 if (CALIB_TYPE==
"ISO_TRACK") {
448 Int_t ind = refIEtaIPhi[
i].first;
449 (ind<0) ? (ind +=24) : (ind +=23);
450 if (ind>=0 && ind<48) {
463 else if (maxIEta<25 && minIEta>16) {
501 for (Int_t
i=0;
i<48; ++
i) {
512 cout <<
"\n Finished calibration.\n " << endl;
525 map<Int_t, Float_t> aveTargetE;
526 map<Int_t, Int_t> nEntries;
529 map<Int_t, map<Int_t, Float_t> > aveHitE;
531 for (
unsigned int i=0;
i<cellEnergies.size(); ++
i) {
532 Int_t iEtaRef = refIEtaIPhi[
i].first;
533 aveTargetE[iEtaRef] += targetEnergies[
i];
537 if (CALIB_METHOD==
"L3_AND_MTRX_INV") {
538 for (
unsigned int j=0;
j<(cellEnergies[
i]).
size(); ++
j) {
539 aveHitE[iEtaRef][
HcalDetId(cellIds[
i][
j]).
ieta()] += (solution[cellIds[
i][
j]] * cellEnergies[
i][
j]);
542 else if (CALIB_METHOD==
"MATRIX_INV_OF_ETA_AVE") {
543 for (
unsigned int j=0;
j<(cellEnergies[
i]).
size(); ++
j) {
553 for (map<Int_t, Float_t>::iterator m_it = aveTargetE.begin(); m_it!=aveTargetE.end(); ++m_it){
554 Int_t iEta = m_it->first;
555 norm = (nEntries[iEta] > 0)? 1.0/(nEntries[iEta]) : 1.0;
556 aveTargetE[iEta] *= norm;
558 map<Int_t, Float_t>::iterator n_it = (aveHitE[iEta]).
begin();
561 for (; n_it!=(aveHitE[iEta]).
end(); ++n_it) {
562 (n_it->second) *= norm;
563 sumRawE += (n_it->second);
568 Int_t ONE_SIDE_IETA_RANGE = CALIB_ABS_IETA_MAX - CALIB_ABS_IETA_MIN +1;
572 vector<Int_t> iEtaList;
574 for (Int_t
i=-CALIB_ABS_IETA_MAX;
i<=CALIB_ABS_IETA_MAX; ++
i) {
575 if (
abs(
i)<CALIB_ABS_IETA_MIN)
continue;
576 iEtaList.push_back(
i);
579 TMatrixD
A(2*ONE_SIDE_IETA_RANGE, 2*ONE_SIDE_IETA_RANGE);
580 TMatrixD
b(2*ONE_SIDE_IETA_RANGE, 1);
581 TMatrixD
x(2*ONE_SIDE_IETA_RANGE, 1);
583 for (Int_t
i=0;
i<2*ONE_SIDE_IETA_RANGE; ++
i) {
584 for (Int_t
j=0;
j<2*ONE_SIDE_IETA_RANGE; ++
j) {
589 for (
UInt_t i=0;
i<iEtaList.size(); ++
i) {
590 b(
i, 0) = aveTargetE[iEtaList[
i]];
592 map<Int_t, Float_t>::iterator n_it = aveHitE[iEtaList[
i]].begin();
593 for (; n_it!=aveHitE[iEtaList[
i]].end(); ++n_it){
595 if (fabs(n_it->first)>CALIB_ABS_IETA_MAX || fabs(n_it->first)<CALIB_ABS_IETA_MIN)
continue;
596 Int_t
j = Int_t(
find(iEtaList.begin(),iEtaList.end(), n_it->first) - iEtaList.begin());
597 A(
i, j) = n_it->second;
605 Bool_t hasSolution = qrh.MultiSolve(coef);
607 if (hasSolution && (CALIB_METHOD==
"L3_AND_MTRX_INV" || CALIB_METHOD==
"MATRIX_INV_OF_ETA_AVE")) {
608 for (
UInt_t i=0;
i<iEtaList.size(); ++
i) {
609 iEtaCoefMap[iEtaList[
i]] = coef(
i, 0);
617 ifstream phiSymFile(PHI_SYM_COR_FILENAME.Data());
620 cout <<
"\nERROR: Can not find file with phi symmetry constants \"" << PHI_SYM_COR_FILENAME.Data() <<
"\"" << endl;
637 while (getline(phiSymFile, line)) {
639 if(!line.size() || line[0]==
'#')
continue;
641 std::istringstream linestream(line);
642 linestream >> iEta >> iPhi >> depth >> sdName >> value >> hex >> detId;
649 cout <<
"\nInvalid detector name in phi symmetry constants file: " << sdName.Data() << endl;
650 cout <<
"Check file and rerun!\n" << endl;
657 cout <<
"\nInconsistent info in phi symmetry file: subdet, iEta, iPhi, depth do not match rawId!\n" << endl;
661 cout <<
"\nInvalid DetId from: iEta=" << iEta <<
" iPhi=" << iPhi <<
" depth=" << depth
662 <<
" subdet=" << sdName.Data() <<
" detId=" << detId << endl << endl;
677 TString sdName[8] = {
"EMPTY",
"HB",
"HE",
"HO",
"HF",
"TRITWR",
"UNDEF",
"OTHER"};
679 FILE *constFile = fopen(OUTPUT_COR_COEF_FILENAME.Data(),
"w+");
682 fprintf(constFile,
"%1s%16s%16s%16s%16s%9s%11s\n",
683 "#",
"eta",
"phi",
"depth",
"det",
"value",
"DetId");
687 for(Int_t
sd=1;
sd<=4;
sd++) {
689 for(Int_t
e=1;
e<=50;
e++) {
692 for(Int_t side=0; side<2; side++) {
693 eta = (side==0)? -
e :
e;
697 for(Int_t d=1; d<5; d++) {
701 Float_t corrFactor = 1.0;
710 Int_t subdetInd =
sd;
716 if (CALIB_METHOD==
"L3" || CALIB_METHOD==
"L3_AND_MTRX_INV") {
734 else if (CALIB_METHOD==
"MATRIX_INV_OF_ETA_AVE") {
735 corrFactor = iEtaCoefMap[
eta];
738 else if (CALIB_METHOD==
"ISO_TRK_PHI_SYM") {
745 fprintf(constFile,
"%17i%16i%16i%16s%9.5f%11X\n",
746 eta,
phi, d, sdName[
sd].
Data(), corrFactor,
id.rawId());
void filterCellsInCone(std::vector< TCell > &selectCells, const GlobalPoint hitPositionHcal, Float_t maxConeDist, const CaloGeometry *theCaloGeometry)
TH1F * h1_corRespIEta[48]
virtual Bool_t Process(Long64_t entry)
HcalSubdetector subdet() const
get the subdetector
void GetCoefFromMtrxInvOfAve()
TH1F * h1_numEventsTwrIEta
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
static bool validDetId(HcalSubdetector subdet, int tower_ieta, int tower_iphi, int depth)
virtual void Begin(TTree *tree)
U second(std::pair< T, U > const &p)
int depth() const
get the tower depth
std::pair< std::string, MonitorElement * > entry
int ieta() const
get the cell ieta
void filterCells3x3(std::vector< TCell > &selectCells, Int_t iEta, UInt_t iPhi)
int ietaAbs() const
get the absolute value of the cell ieta
int iphi() const
get the cell iphi
void filterCells5x5(std::vector< TCell > &selectCells, Int_t iEta, UInt_t iPhi)
IDmap iterate(const std::vector< std::vector< float > > &eventMatrix, const std::vector< std::vector< IDdet > > &idMatrix, const std::vector< float > &energyVector, const int &nIter, const bool &normalizeFlag=false)
void getIEtaIPhiForHighestE(std::vector< TCell > &selectCells, Int_t &iEta, UInt_t &iPhi)
tuple size
Write out results.