Go to the documentation of this file.00001 #include <iostream>
00002 #include <fstream>
00003 #include <algorithm>
00004 #include <numeric>
00005
00006 #include "TString.h"
00007 #include "Calibration/HcalCalibAlgos/interface/hcalCalibUtils.h"
00008
00009
00010 #include "Calibration/HcalCalibAlgos/interface/CommonUsefulStuff.h"
00011
00012 using namespace std;
00013
00014 void sumDepths(vector<TCell> &selectCells) {
00015
00016
00017
00018
00019
00020 if (selectCells.size()==0) return;
00021
00022 vector<TCell> selectCellsDepth1;
00023 vector<TCell> selectCellsHighDepth;
00024
00025
00026
00027
00028
00029
00030
00031
00032 for (vector<TCell>::iterator i_it = selectCells.begin(); i_it != selectCells.end(); ++i_it) {
00033 if (HcalDetId(i_it->id()).depth()==1) {
00034 selectCellsDepth1.push_back(*i_it);
00035 }
00036 else {
00037 selectCellsHighDepth.push_back(*i_it);
00038 }
00039 }
00040
00041
00042
00043
00044
00045 for (vector<TCell>::iterator i_it2 = selectCellsHighDepth.begin(); i_it2 != selectCellsHighDepth.end(); ++i_it2) {
00046
00047
00048
00049 if (HcalDetId(i_it2->id()).ietaAbs()<15 && HcalDetId(i_it2->id()).depth()>1) {
00050 cout << "ERROR!!! there are no HB cells with depth>1 for iEta<15!\n"
00051 << "Check the input data..." << endl;
00052 cout << "HCalDetId: " << HcalDetId(i_it2->id()) << endl;
00053 return;
00054 }
00055
00056
00057 bool foundDepthOne = false;
00058 for (vector<TCell>::iterator i_it = selectCellsDepth1.begin(); i_it != selectCellsDepth1.end(); ++i_it) {
00059 if (HcalDetId(i_it->id()).ieta()==HcalDetId(i_it2->id()).ieta() &&
00060 HcalDetId(i_it->id()).iphi()==HcalDetId(i_it2->id()).iphi())
00061 foundDepthOne = true;
00062 continue;
00063 }
00064 if (!foundDepthOne) {
00065
00066 UInt_t newId;
00067 if (abs(HcalDetId(i_it2->id()).ieta())==16)
00068 newId = HcalDetId(HcalBarrel, HcalDetId(i_it2->id()).ieta(), HcalDetId(i_it2->id()).iphi(), 1);
00069 else
00070 newId = HcalDetId(HcalDetId(i_it2->id()).subdet(), HcalDetId(i_it2->id()).ieta(), HcalDetId(i_it2->id()).iphi(), 1);
00071
00072 selectCellsDepth1.push_back(TCell(newId, 0.0));
00074 }
00075 }
00076
00077 for (vector<TCell>::iterator i_it = selectCellsDepth1.begin(); i_it != selectCellsDepth1.end(); ++i_it) {
00078 for (vector<TCell>::iterator i_it2 = selectCellsHighDepth.begin(); i_it2 != selectCellsHighDepth.end(); ++i_it2) {
00079 if (HcalDetId(i_it->id()).ieta()==HcalDetId(i_it2->id()).ieta() &&
00080 HcalDetId(i_it->id()).iphi()==HcalDetId(i_it2->id()).iphi()) {
00081 i_it->SetE(i_it->e()+i_it2->e());
00082 i_it2->SetE(0.0);
00083 }
00084 }
00085 }
00086
00087
00088 selectCells = selectCellsDepth1;
00089
00090 return;
00091 }
00092
00093
00094 void combinePhi(vector<TCell> &selectCells) {
00095
00096
00097
00098
00099 if (selectCells.size()==0) return;
00100
00101
00102
00103
00104 vector<TCell> combinedCells;
00105
00106 map<UInt_t, vector<Float_t> > etaSliceE;
00107
00108
00109 vector<TCell>::iterator i_it = selectCells.begin();
00110 for (; i_it != selectCells.end(); ++i_it) {
00111 DetId id = HcalDetId(i_it->id());
00112 UInt_t thisKey = HcalDetId(HcalDetId(id).subdet(), HcalDetId(id).ieta(), 1, HcalDetId(id).depth() );
00113 etaSliceE[thisKey].push_back(i_it->e());
00114 }
00115
00116 map<UInt_t, vector<Float_t> >::iterator m_it = etaSliceE.begin();
00117 for (; m_it != etaSliceE.end(); ++m_it) {
00118 combinedCells.push_back(TCell(m_it->first, accumulate(m_it->second.begin(), m_it->second.end(), 0.0) ) );
00119 }
00120
00121
00122 selectCells = combinedCells;
00123
00124 }
00125
00126
00127 void combinePhi(vector<TCell> &selectCells, vector<TCell> &combinedCells) {
00128
00129
00130
00131
00132 if (selectCells.size()==0) return;
00133
00134 map<UInt_t, vector<Float_t> > etaSliceE;
00135
00136
00137 vector<TCell>::iterator i_it = selectCells.begin();
00138 for (; i_it != selectCells.end(); ++i_it) {
00139 DetId id = HcalDetId(i_it->id());
00140 UInt_t thisKey = HcalDetId(HcalDetId(id).subdet(), HcalDetId(id).ieta(), 1, HcalDetId(id).depth() );
00141 etaSliceE[thisKey].push_back(i_it->e());
00142 }
00143
00144 map<UInt_t, vector<Float_t> >::iterator m_it = etaSliceE.begin();
00145 for (; m_it != etaSliceE.end(); ++m_it) {
00146 combinedCells.push_back(TCell(m_it->first, accumulate(m_it->second.begin(), m_it->second.end(), 0.0) ) );
00147 }
00148
00149 }
00150
00151
00152
00153 void getIEtaIPhiForHighestE(vector<TCell>& selectCells, Int_t& iEtaMostE, UInt_t& iPhiMostE) {
00154
00155
00156 vector<TCell> summedDepthsCells = selectCells;
00157
00158 sumDepths(summedDepthsCells);
00159 vector<TCell>::iterator highCell = summedDepthsCells.begin();
00160
00161
00162
00163 Float_t highE = -999;
00164
00165 for (vector<TCell>::iterator it=summedDepthsCells.begin(); it!=summedDepthsCells.end(); ++it) {
00166 if (highE < it->e()) {
00167 highCell = it;
00168 highE = it->e();
00169 }
00170 }
00171
00172 iEtaMostE = HcalDetId(highCell->id()).ieta();
00173 iPhiMostE = HcalDetId(highCell->id()).iphi();
00174
00175 return;
00176 }
00177
00178
00179
00180
00181
00182
00183
00184
00185 void filterCells3x3(vector<TCell>& selectCells, Int_t iEtaMaxE, UInt_t iPhiMaxE) {
00186
00187 vector<TCell> filteredCells;
00188
00189 Int_t dEta, dPhi;
00190
00191 for (vector<TCell>::iterator it=selectCells.begin(); it!=selectCells.end(); ++it) {
00192
00193 Bool_t passDEta = false;
00194 Bool_t passDPhi = false;
00195
00196 dEta = HcalDetId(it->id()).ieta() - iEtaMaxE;
00197 dPhi = HcalDetId(it->id()).iphi() - iPhiMaxE;
00198
00199 if (dPhi > 36) dPhi -= 72;
00200 if (dPhi < -36) dPhi += 72;
00201
00202 if (abs(dEta)<=1 || (iEtaMaxE * HcalDetId(it->id()).ieta() == -1)) passDEta = true;
00203
00204 if (abs(iEtaMaxE)<=20) {
00205
00206 if (abs(HcalDetId(it->id()).ieta())<=20) {
00207 if (abs(dPhi)<=1) passDPhi = true;
00208 }
00209 else {
00210
00211 if (iPhiMaxE%2==0){
00212 if (abs(dPhi)<=1) passDPhi = true;
00213 }
00214 else {
00215 if (dPhi== -2 || dPhi==0) passDPhi = true;
00216 }
00217 }
00218
00219 }
00220
00221 else {
00222 if (abs(HcalDetId(it->id()).ieta())<=20) {
00223 if (abs(dPhi)<=1 || dPhi==2) passDPhi = true;
00224 }
00225 else {
00226 if (abs(dPhi)<=2) passDPhi = true;
00227 }
00228 }
00229
00230 if (passDEta && passDPhi) filteredCells.push_back(*it);
00231 }
00232
00233 selectCells = filteredCells;
00234
00235 return;
00236 }
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246 void filterCells5x5(vector<TCell>& selectCells, Int_t iEtaMaxE, UInt_t iPhiMaxE) {
00247
00248 vector<TCell> filteredCells;
00249
00250 Int_t dEta, dPhi;
00251
00252 for (vector<TCell>::iterator it=selectCells.begin(); it!=selectCells.end(); ++it) {
00253
00254 dEta = HcalDetId(it->id()).ieta() - iEtaMaxE;
00255 dPhi = HcalDetId(it->id()).iphi() - iPhiMaxE;
00256
00257 if (dPhi > 36) dPhi -= 72;
00258 if (dPhi < -36) dPhi += 72;
00259
00260 bool passDPhi = (abs(dPhi)<3);
00261
00262 bool passDEta = (abs(dEta)<3 || (iEtaMaxE * HcalDetId(it->id()).ieta() == -2) );
00263
00264
00265 if (passDPhi && passDEta) filteredCells.push_back(*it);
00266
00267 }
00268
00269 selectCells = filteredCells;
00270
00271 return;
00272 }
00273
00274
00275
00276
00277
00278
00279
00280 void sumSmallDepths(vector<TCell> &selectCells) {
00281
00282 if (selectCells.size()==0) return;
00283
00284 vector<TCell> newCells;
00285 vector<TCell> manipulatedCells;
00286
00287 for (vector<TCell>::iterator i_it = selectCells.begin(); i_it != selectCells.end(); ++i_it) {
00288
00289 if ( (HcalDetId(i_it->id()).ietaAbs()==15 && HcalDetId(i_it->id()).depth()<=2) ||
00290 (HcalDetId(i_it->id()).ietaAbs()==16 && HcalDetId(i_it->id()).depth()<=2)) {
00291 manipulatedCells.push_back(*i_it);
00292 }
00293 else {
00294 newCells.push_back(*i_it);
00295 }
00296
00297 }
00298
00299
00300
00301
00302 if (manipulatedCells.size()<1) {
00303 newCells.clear();
00304 return;
00305 }
00306
00307
00308
00309
00310
00311 vector<UInt_t> dummyIds;
00312 vector<TCell> createdCells;
00313
00314 for (vector<TCell>::iterator i_it = manipulatedCells.begin(); i_it!=manipulatedCells.end(); ++i_it) {
00315 UInt_t dummyId = HcalDetId(HcalDetId(i_it->id()).subdet(), HcalDetId(i_it->id()).ieta(), HcalDetId(i_it->id()).iphi(), 1);
00316 if (find(dummyIds.begin(), dummyIds.end(), dummyId)==dummyIds.end()) {
00317 dummyIds.push_back(dummyId);
00318 createdCells.push_back(TCell(dummyId, 0.0));
00319 }
00320 }
00321
00322 for (vector<TCell>::iterator i_it = createdCells.begin(); i_it!=createdCells.end(); ++i_it) {
00323 for (vector<TCell>::iterator i_it2 = manipulatedCells.begin(); i_it2!=manipulatedCells.end(); ++i_it2) {
00324 if (HcalDetId(i_it->id()).ieta()==HcalDetId(i_it2->id()).ieta() &&
00325 HcalDetId(i_it->id()).iphi()==HcalDetId(i_it2->id()).iphi() &&
00326 HcalDetId(i_it2->id()).depth()<=2) {
00327 i_it->SetE(i_it->e()+i_it2->e());
00328 }
00329 }
00330 }
00331
00332 for (vector<TCell>::iterator i_it = createdCells.begin(); i_it!=createdCells.end(); ++i_it) {
00333 newCells.push_back(*i_it);
00334 }
00335
00336
00337
00338 selectCells = newCells;
00339
00340 return;
00341 }
00342
00343
00344 void filterCellsInCone(std::vector<TCell>& selectCells, const GlobalPoint hitPositionHcal,
00345 Float_t maxConeDist, const CaloGeometry* theCaloGeometry) {
00346
00347 vector<TCell> filteredCells;
00348
00349 for (vector<TCell>::iterator it=selectCells.begin(); it!=selectCells.end(); ++it) {
00350
00351 const GlobalPoint recHitPoint = theCaloGeometry->getPosition(it->id());
00352
00353 if (getDistInPlaneSimple(hitPositionHcal, recHitPoint)<= maxConeDist)
00354 filteredCells.push_back(*it);
00355 }
00356
00357 selectCells = filteredCells;
00358
00359 return;
00360 }
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406