00001 #include <memory>
00002 #include <math.h>
00003 #include "FWCore/Framework/interface/Frameworkfwd.h"
00004 #include "FWCore/Framework/interface/MakerMacros.h"
00005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00006 #include "Calibration/EcalCalibAlgos/interface/InvRingCalib.h"
00007 #include "DataFormats/Common/interface/Handle.h"
00008 #include "DataFormats/EgammaReco/interface/ClusterShape.h"
00009 #include "DataFormats/DetId/interface/DetId.h"
00010 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00011 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
00012 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00013 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00014 #include "CondFormats/DataRecord/interface/EcalIntercalibConstantsRcd.h"
00015 #include "Calibration/Tools/interface/calibXMLwriter.h"
00016 #include "CalibCalorimetry/CaloMiscalibTools/interface/CaloMiscalibTools.h"
00017 #include "TH2.h"
00018 #include "TFile.h"
00019
00020 #include "CalibCalorimetry/CaloMiscalibTools/interface/MiscalibReaderFromXMLEcalBarrel.h"
00021 #include "CalibCalorimetry/CaloMiscalibTools/interface/MiscalibReaderFromXMLEcalEndcap.h"
00022 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
00023 #include "DataFormats/EgammaReco/interface/BasicCluster.h"
00024 #include "DataFormats/EgammaReco/interface/ClusterShapeFwd.h"
00025 #include "DataFormats/EgammaReco/interface/ClusterShapeFwd.h"
00026 #include "DataFormats/EgammaReco/interface/ClusterShape.h"
00027
00028
00029
00030
00031
00032 InvRingCalib::InvRingCalib (const edm::ParameterSet& iConfig) :
00033 m_barrelAlCa (iConfig.getParameter<edm::InputTag>("barrelAlca")),
00034 m_endcapAlCa (iConfig.getParameter<edm::InputTag>("endcapAlca")) ,
00035 m_ElectronLabel (iConfig.getParameter<edm::InputTag>("ElectronLabel")),
00036 m_recoWindowSide (iConfig.getParameter<int>("recoWindowSide")),
00037 m_minEnergyPerCrystal (iConfig.getParameter<double>("minEnergyPerCrystal")) ,
00038 m_maxEnergyPerCrystal (iConfig.getParameter<double>("maxEnergyPerCrystal")) ,
00039 m_etaStart (iConfig.getParameter<int>("etaStart")),
00040 m_etaEnd (iConfig.getParameter<int>("etaEnd")),
00041 m_etaWidth (iConfig.getParameter<int>("etaWidth")),
00042 m_maxSelectedNumPerRing (iConfig.getParameter<int>("maxNumPerRing")),
00043 m_minCoeff (iConfig.getParameter<double>("minCoeff")),
00044 m_maxCoeff (iConfig.getParameter<double>("maxCoeff")),
00045 m_usingBlockSolver(iConfig.getParameter<int>("usingBlockSolver")),
00046 m_loops (iConfig.getParameter<int>("loops")),
00047 m_startRing (iConfig.getParameter<int>("startRing")),
00048 m_endRing (iConfig.getParameter<int>("endRing")),
00049 m_EBcoeffFile (iConfig.getParameter<std::string>("EBcoeffs")),
00050 m_EEcoeffFile (iConfig.getParameter<std::string>("EEcoeffs")),
00051 m_EEZone (iConfig.getParameter<int>("EEZone"))
00052 {
00053
00054 assert (m_etaStart >=-85 && m_etaStart <= 85);
00055 assert (m_etaEnd >= m_etaStart && m_etaEnd <= 86);
00056 assert (m_startRing>-1 && m_startRing<= 40);
00057 assert (m_endRing>=m_startRing && m_endRing<=40);
00058 assert (!((m_endRing - m_startRing)%m_etaWidth));
00059 assert ((m_etaEnd-m_etaStart)%m_etaWidth == 0);
00060 assert (( abs(m_EEZone)<=1));
00061 edm::LogInfo ("IML") << "[InvRingCalib][ctor] entering " ;
00062
00063
00064 for (int i = 0 ; i < EBRegionNum () ; ++i)
00065 m_IMACalibBlocks.push_back (IMACalibBlock (m_etaWidth));
00066
00067 int EEBlocks = 0 ;
00068 if (m_EEZone == 0) EEBlocks = 2 * EERegionNum () ;
00069 if (m_EEZone == 1 || m_EEZone == -1) EEBlocks = EERegionNum () ;
00070
00071 for (int i = 0; i < EEBlocks ; ++i)
00072 m_IMACalibBlocks.push_back (IMACalibBlock (m_etaWidth));
00073 edm::LogInfo ("IML") <<" [InvRingCalib][ctor] end of creator";
00074 }
00075
00076
00077
00079
00080
00081 InvRingCalib::~InvRingCalib ()
00082 {
00083 }
00084
00085
00086
00087
00088
00089
00091 void
00092 InvRingCalib::beginOfJob (const edm::EventSetup& iSetup)
00093 {
00094 edm::LogInfo ("IML") << "[InvRingCalib][beginOfJob]" ;
00095
00096 edm::ESHandle<CaloGeometry> geoHandle;
00097 iSetup.get<CaloGeometryRecord>().get(geoHandle);
00098 const CaloGeometry& geometry = *geoHandle;
00099 edm::LogInfo ("IML") <<"[InvRingCalib] Event Setup read";
00100
00101 m_barrelCells = geometry.getValidDetIds(DetId::Ecal, EcalBarrel);
00102 m_endcapCells = geometry.getValidDetIds(DetId::Ecal, EcalEndcap);
00103
00104 edm::LogInfo ("IML") <<"[InvRingCalib] Defining Barrel Regions";
00105 EBRegionDef();
00106
00107 edm::LogInfo ("IML") <<"[InvRingCalib] Defining endcap Rings";
00108 EERingDef(iSetup);
00109
00110 edm::LogInfo ("IML") <<"[InvRingCalib] Defining endcap Regions";
00111 EERegionDef();
00112 edm::LogInfo ("IML") <<"[InvRingCalib] Initializing the coeffs";
00113
00114 for (std::map<int,int>::const_iterator ring= m_xtalRing.begin();
00115 ring!=m_xtalRing.end();++ring)
00116 m_InterRings[ring->second]=1.;
00117
00118 TH2F EBRegion ("EBRegion","EBRegion",171,-85,86,360,1,361);
00119 TH2F EBRing ("EBRing","EBRing",171,-85,86,360,1,361);
00120 for (std::vector<DetId>::const_iterator it= m_barrelCells.begin();
00121 it!= m_barrelCells.end();
00122 ++it )
00123 {
00124 EBDetId eb (*it);
00125 EBRing.Fill(eb.ieta(),eb.iphi(),m_RinginRegion[it->rawId()]);
00126 EBRegion.Fill(eb.ieta(),eb.iphi(),m_xtalRegionId[it->rawId()]);
00127 }
00128
00129 TH2F EEPRegion ("EEPRegion", "EEPRegion",100,1,101,100,1,101);
00130 TH2F EEPRing ("EEPRing", "EEPRing",100,1,101,100,1,101);
00131 TH2F EEPRingReg ("EEPRingReg", "EEPRingReg",100,1,101,100,1,101);
00132 TH2F EEMRegion ("EEMRegion", "EEMRegion",100,1,101,100,1,101);
00133 TH2F EEMRing ("EEMRing", "EEMRing",100,1,101,100,1,101);
00134 TH2F EEMRingReg ("EEMRingReg", "EEMRingReg",100,1,101,100,1,101);
00135
00136 for (std::vector<DetId>::const_iterator it = m_endcapCells.begin();
00137 it!= m_endcapCells.end();
00138 ++it)
00139 {
00140 EEDetId ee (*it);
00141 if (ee.zside()>0)
00142 {
00143 EEPRegion.Fill(ee.ix(),ee.iy(),m_xtalRegionId[ee.rawId()]);
00144 EEPRing.Fill(ee.ix(),ee.iy(),m_xtalRing[ee.rawId()]);
00145 EEPRingReg.Fill(ee.ix(),ee.iy(),m_RinginRegion[ee.rawId()]);
00146 }
00147 if (ee.zside()<0)
00148 {
00149 EEMRegion.Fill(ee.ix(),ee.iy(),m_xtalRegionId[ee.rawId()]);
00150 EEMRing.Fill(ee.ix(),ee.iy(),m_xtalRing[ee.rawId()]);
00151 EEMRingReg.Fill(ee.ix(),ee.iy(),m_RinginRegion[ee.rawId()]);
00152 }
00153 }
00154
00155 TFile out ("EBZone.root", "recreate");
00156 EBRegion.Write();
00157 EBRing.Write();
00158 EEPRegion.Write();
00159 EEPRing.Write();
00160 EEPRingReg.Write();
00161 EEMRegion.Write();
00162 EEMRing.Write();
00163 EEMRingReg.Write();
00164 out.Close();
00165 edm::LogInfo ("IML") <<"[InvRingCalib] Start to acquire the coeffs";
00166 CaloMiscalibMapEcal EBmap;
00167 EBmap.prefillMap ();
00168 MiscalibReaderFromXMLEcalBarrel barrelreader (EBmap);
00169 if (!m_EBcoeffFile.empty()) barrelreader.parseXMLMiscalibFile (m_EBcoeffFile);
00170 EcalIntercalibConstants costants (EBmap.get());
00171 m_barrelMap = costants.getMap();
00172 CaloMiscalibMapEcal EEmap ;
00173 EEmap.prefillMap ();
00174 MiscalibReaderFromXMLEcalEndcap endcapreader (EEmap);
00175 if (!m_EEcoeffFile.empty()) endcapreader.parseXMLMiscalibFile (m_EEcoeffFile) ;
00176 EcalIntercalibConstants EEcostants (EEmap.get());
00177 m_endcapMap = EEcostants.getMap();
00178 }
00179
00180
00181
00182
00183
00185 void InvRingCalib::startingNewLoop (unsigned int ciclo)
00186 {
00187 edm::LogInfo ("IML") << "[InvMatrixCalibLooper][Start] entering loop " << ciclo;
00188 for (std::vector<IMACalibBlock>::iterator calibBlock = m_IMACalibBlocks.begin () ;
00189 calibBlock != m_IMACalibBlocks.end () ;
00190 ++calibBlock)
00191 {
00192
00193 calibBlock->reset () ;
00194 }
00195 for (std::map<int,int>::const_iterator ring=m_xtalRing.begin();
00196 ring!=m_xtalRing.end();
00197 ++ring)
00198 m_RingNumOfHits[ring->second]=0;
00199 return ;
00200 }
00201
00202
00203
00204
00205
00207 edm::EDLooper::Status
00208 InvRingCalib::duringLoop (const edm::Event& iEvent,
00209 const edm::EventSetup&)
00210 {
00211
00212 double pSubtract = 0.;
00213 double pTk = 0.;
00214 const EBRecHitCollection* barrelHitsCollection = 0;
00215 edm::Handle<EBRecHitCollection> barrelRecHitsHandle ;
00216 iEvent.getByLabel (m_barrelAlCa, barrelRecHitsHandle) ;
00217 barrelHitsCollection = barrelRecHitsHandle.product () ;
00218
00219
00220
00221
00222 const EERecHitCollection* endcapHitsCollection = 0;
00223 edm::Handle<EERecHitCollection> endcapRecHitsHandle ;
00224 iEvent.getByLabel (m_endcapAlCa, endcapRecHitsHandle) ;
00225 endcapHitsCollection = endcapRecHitsHandle.product () ;
00226
00227
00228
00229
00230 edm::Handle<reco::PixelMatchGsfElectronCollection> pElectrons;
00231 iEvent.getByLabel(m_ElectronLabel,pElectrons);
00232
00233
00234
00235
00236 for (eleIterator eleIt = pElectrons->begin();
00237 eleIt != pElectrons->end();
00238 ++eleIt )
00239 {
00240 pSubtract =0;
00241 pTk=0;
00242
00243 DetId Max = findMaxHit (eleIt->superCluster ()->getHitsByDetId (),
00244 barrelHitsCollection,
00245 endcapHitsCollection) ;
00246
00247
00248 if (Max.det()==0) continue;
00249
00250 if (m_xtalRegionId[Max.rawId()]==-1) continue;
00251 if (m_maxSelectedNumPerRing > 0 &&
00252 m_RingNumOfHits [m_xtalRing[Max.rawId ()]] > m_maxSelectedNumPerRing ) continue ;
00253 ++m_RingNumOfHits [m_xtalRing[Max.rawId()]];
00254
00255 std::map<int , double> xtlMap;
00256
00257 pTk = eleIt->trackMomentumAtVtx().R();
00258 if ( Max.subdetId() == EcalBarrel )
00259 {
00260 EBDetId EBmax = Max;
00261
00262 fillEBMap (EBmax, barrelHitsCollection, xtlMap,
00263 m_xtalRegionId[Max.rawId()], pSubtract ) ;
00264 }
00265 else
00266 {
00267 EEDetId EEmax = Max;
00268 fillEEMap (EEmax, endcapHitsCollection, xtlMap,
00269 m_xtalRegionId[Max.rawId()],pSubtract ) ;
00270
00271 pSubtract += eleIt->superCluster()->preshowerEnergy() ;
00272 }
00273
00274 m_IMACalibBlocks.at(m_xtalRegionId[Max.rawId()]).Fill (
00275 xtlMap.begin(), xtlMap.end(),pTk,pSubtract
00276 ) ;
00277 }
00278 return kContinue;
00279 }
00280
00281
00282
00283
00284
00285
00286 edm::EDLooper::Status
00287 InvRingCalib::endOfLoop (const edm::EventSetup& dumb,
00288 unsigned int iCounter)
00289 {
00290 edm::LogInfo ("IML") << "[InvMatrixCalibLooper][endOfLoop] Start to invert the matrixes" ;
00291
00292 for (std::vector<IMACalibBlock>::iterator calibBlock=m_IMACalibBlocks.begin();
00293 calibBlock!=m_IMACalibBlocks.end();
00294 ++calibBlock)
00295 calibBlock->solve(m_usingBlockSolver,m_minCoeff,m_maxCoeff);
00296
00297 edm::LogInfo("IML") << "[InvRingLooper][endOfLoop] Starting to write the coeffs";
00298 TH1F coeffDistr ("coeffdistr","coeffdistr",100 ,0.7,1.4);
00299 TH1F coeffMap ("coeffRingMap","coeffRingMap",249,-85,165);
00300 TH1F ringDistr ("ringDistr","ringDistr",249,-85,165);
00301
00302 for(std::map<int,int>::const_iterator it=m_xtalRing.begin();
00303 it!=m_xtalRing.end();
00304 ++it)
00305 ringDistr.Fill(it->second);
00306
00307 int ID;
00308 std::map<int,int> flag;
00309 for(std::map<int,int>::const_iterator it=m_xtalRing.begin();
00310 it!=m_xtalRing.end();
00311 ++it)
00312 flag[it->second]=0;
00313
00314 for (std::vector<DetId>::const_iterator it=m_barrelCells.begin();
00315 it!=m_barrelCells.end();
00316 ++it)
00317 {
00318 ID= it->rawId();
00319 if (m_xtalRegionId[ID]==-1) continue;
00320 if (flag[m_xtalRing[ID]]) continue;
00321 flag[m_xtalRing[ID]] =1;
00322 m_InterRings[m_xtalRing[ID]]= m_IMACalibBlocks.at(m_xtalRegionId[ID]).at(m_RinginRegion[ID]);
00323 coeffMap.Fill (m_xtalRing[ID],m_InterRings[m_xtalRing[ID]]);
00324 coeffDistr.Fill(m_InterRings[m_xtalRing[ID]]);
00325 }
00326
00327 for (std::vector<DetId>::const_iterator it=m_endcapCells.begin();
00328 it!=m_endcapCells.end();
00329 ++it)
00330 {
00331 ID= it->rawId();
00332 if (m_xtalRegionId[ID]==-1) continue;
00333 if (flag[m_xtalRing[ID]]) continue;
00334 flag[m_xtalRing[ID]]= 1;
00335 m_InterRings[m_xtalRing[ID]]= m_IMACalibBlocks.at(m_xtalRegionId[ID]).at(m_RinginRegion[ID]);
00336 coeffMap.Fill (m_xtalRing[ID],m_InterRings[m_xtalRing[ID]]);
00337 coeffDistr.Fill(m_InterRings[m_xtalRing[ID]]);
00338 }
00339
00340 char filename[80];
00341 sprintf(filename,"coeff%d.root",iCounter);
00342 TFile out(filename,"recreate");
00343 coeffDistr.Write();
00344 coeffMap.Write();
00345 ringDistr.Write();
00346 out.Close();
00347 if (iCounter < m_loops-1 ) return kContinue ;
00348 else return kStop;
00349 }
00350
00351
00352
00353
00354
00355
00356 void
00357 InvRingCalib::endOfJob ()
00358 {
00359
00360 edm::LogInfo ("IML") << "[InvMatrixCalibLooper][endOfJob] saving calib coeffs" ;
00361 calibXMLwriter barrelWriter(EcalBarrel);
00362 calibXMLwriter endcapWriter(EcalEndcap);
00363 for (std::vector<DetId>::const_iterator barrelIt =m_barrelCells.begin();
00364 barrelIt!=m_barrelCells.end();
00365 ++barrelIt) {
00366 EBDetId eb (*barrelIt);
00367 barrelWriter.writeLine(eb,m_InterRings[m_xtalRing[eb.rawId()]]*m_barrelMap[eb]);
00368 }
00369 for (std::vector<DetId>::const_iterator endcapIt = m_endcapCells.begin();
00370 endcapIt!=m_endcapCells.end();
00371 ++endcapIt) {
00372 EEDetId ee (*endcapIt);
00373 endcapWriter.writeLine(ee,m_InterRings[m_xtalRing[ee.rawId()]]*m_endcapMap[ee]);
00374 }
00375 }
00376
00377
00378
00379
00380
00381
00382
00383 void
00384 InvRingCalib::fillEBMap (EBDetId EBmax,
00385 const EcalRecHitCollection * barrelHitsCollection,
00386 std::map<int, double> & EBRegionMap,
00387 int EBNumberOfRegion, double & pSubtract)
00388 {
00389 int curr_eta;
00390 int curr_phi;
00391
00392 for (int ii = 0 ; ii< m_recoWindowSide ; ++ii)
00393 for (int ij =0 ; ij< m_recoWindowSide ; ++ij)
00394 {
00395 curr_eta=EBmax.ieta() + ii - (m_recoWindowSide/2);
00396 curr_phi=EBmax.iphi() + ij - (m_recoWindowSide/2);
00397
00398 if (abs(curr_eta)>85) continue;
00399
00400 if (curr_eta * EBmax.ieta() <= 0) {if (EBmax.ieta() > 0) curr_eta--; else curr_eta++; }
00401
00402 if (curr_phi < 1) curr_phi += 360;
00403 if (curr_phi >= 360) curr_phi -= 360;
00404
00405 if(EBDetId::validDetId(curr_eta,curr_phi))
00406 {
00407 EBDetId det = EBDetId(curr_eta,curr_phi,EBDetId::ETAPHIMODE);
00408 int ID= det.rawId();
00409
00410 EcalRecHitCollection::const_iterator curr_recHit = barrelHitsCollection->find(det) ;
00411 double dummy = 0;
00412 dummy = curr_recHit->energy () ;
00413
00414 if ( dummy < m_minEnergyPerCrystal) continue;
00415 if (dummy > m_maxEnergyPerCrystal)
00416 {edm::LogWarning("IML")<<"[InvRingCalib] recHit bigger than maxEnergy per Crystal\n"
00417 <<" EB xtal eta"<<det.ieta()<<" phi "<<det.iphi();
00418 continue;
00419 }
00420
00421 dummy *= m_barrelMap[det];
00422 dummy *= m_InterRings[m_xtalRing[ID]];
00423
00424 if (m_xtalRegionId[ID]==EBNumberOfRegion)
00425 EBRegionMap[m_RinginRegion[ID]]+= dummy;
00426
00427 else pSubtract +=dummy;
00428 }
00429 }
00430 }
00431
00432
00433
00434
00435
00437 void InvRingCalib::fillEEMap (EEDetId EEmax,
00438 const EcalRecHitCollection * endcapHitsCollection,
00439 std::map<int,double> & EExtlMap,
00440 int EENumberOfRegion, double & pSubtract )
00441 {
00442 int curr_x;
00443 int curr_y;
00444 for (int ii = 0 ; ii< m_recoWindowSide ; ++ii)
00445 for (int ij =0 ; ij< m_recoWindowSide ; ++ij)
00446 {
00447
00448 curr_x = EEmax.ix() - m_recoWindowSide/2 +ii;
00449 curr_y = EEmax.iy() - m_recoWindowSide /2 +ij;
00450 if(EEDetId::validDetId(curr_x,curr_y,EEmax.zside()))
00451 {
00452 EEDetId det = EEDetId(curr_x,curr_y,EEmax.zside(),EEDetId::XYMODE);
00453 int ID=det.rawId();
00454 EcalRecHitCollection::const_iterator curr_recHit = endcapHitsCollection->find(det) ;
00455 double dummy = curr_recHit->energy () ;
00456 if ( dummy < m_minEnergyPerCrystal ) continue;
00457 if ( dummy > m_maxEnergyPerCrystal ) {
00458 edm::LogWarning("IML")<<"[InvRingCalib] recHit bigger than maxEnergy per Crystal\n"
00459 <<"EE xtal "<<det.ix()<<" "<<det.iy()<<" Energy= "<< dummy;
00460 continue;
00461 }
00462 dummy *= m_endcapMap[det];
00463 dummy *= m_InterRings[m_xtalRing[ID]];
00464 if (m_xtalRegionId[ID]==EENumberOfRegion)
00465 EExtlMap[m_RinginRegion[ID]] += dummy;
00466 else pSubtract +=dummy;
00467 }
00468 }
00469 }
00470
00471
00472
00473
00474
00476 void InvRingCalib::EERingDef(const edm::EventSetup& iSetup)
00477 {
00478
00479 edm::ESHandle<CaloGeometry> geoHandle;
00480 iSetup.get<CaloGeometryRecord>().get(geoHandle);
00481
00482 const CaloGeometry& geometry = *geoHandle;
00483 const CaloSubdetectorGeometry *endcapGeometry = geometry.getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
00484
00485 for (std::vector<DetId>::const_iterator endcapIt = m_endcapCells.begin();
00486 endcapIt!=m_endcapCells.end();
00487 ++endcapIt) {
00488 const CaloCellGeometry *cellGeometry = endcapGeometry->getGeometry(*endcapIt);
00489 m_cellPos[endcapIt->rawId()] = cellGeometry->getPosition();
00490 m_cellPhi[endcapIt->rawId()] = cellGeometry->getPosition().phi();
00491 }
00492
00493 float eta_ring[39];
00494 for (int ring=0; ring<39; ring++)
00495 if (EEDetId::validDetId(ring,50,1)){
00496 EEDetId det = EEDetId (ring,50,1,EEDetId::XYMODE);
00497 eta_ring[ring]=m_cellPos[det.rawId()].eta();
00498 }
00499
00500 double etaBonduary[40];
00501 etaBonduary[0]=1.49;
00502 etaBonduary[39]=4.0;
00503 for (int ring=1; ring<39; ++ring)
00504 etaBonduary[ring]=(eta_ring[ring]+eta_ring[ring-1])/2.;
00505
00506 int CRing;
00507 for (int ring=0; ring<39; ring++)
00508 for (std::vector<DetId>::const_iterator endcapIt=m_endcapCells.begin();
00509 endcapIt!=m_endcapCells.end();++endcapIt){
00510 if (fabs(m_cellPos[endcapIt->rawId()].eta())>etaBonduary[ring] &&
00511 fabs(m_cellPos[endcapIt->rawId()].eta())<etaBonduary[ring+1])
00512 {
00513 EEDetId ee(*endcapIt);
00514 if (ee.zside()>0) CRing=ring + 86;
00515 else CRing = ring + 125;
00516 m_xtalRing[endcapIt->rawId()]=CRing;
00517 }
00518 }
00519 return;
00520 }
00521
00522
00523
00524
00525
00527 int InvRingCalib::EERegId( int id)
00528 {
00529 int reg;
00530 int ring;
00531 EEDetId ee (id);
00532
00533 if (m_xtalRing[id] == -1) return -1;
00534
00535 if (m_EEZone == 1 ){
00536 if (ee.zside()<0) return -1;
00537 ring = m_xtalRing[id]-86;
00538 if(ring >=m_endRing) return -1;
00539 if (ring<m_startRing) return -1;
00540 reg = (ring -m_startRing) / m_etaWidth;
00541 return reg;
00542 }
00543 if (m_EEZone == -1){
00544 if (ee.zside()>0) return -1;
00545 ring = m_xtalRing[id] -125;
00546 if(ring >=m_endRing) return -1;
00547 if (ring<m_startRing) return -1;
00548 reg = (ring -m_startRing) / m_etaWidth;
00549 return reg;
00550 }
00551 if (ee.zside()<0) ring=m_xtalRing[id]-86;
00552 else ring = m_xtalRing[id]-125;
00553 if(ring >=m_endRing) return -1;
00554 if (ring<m_startRing) return -1;
00555 reg = (ring -m_startRing) / m_etaWidth;
00556 return reg;
00557 }
00558
00561 void InvRingCalib::EERegionDef ()
00562 {
00563 int reg;
00564 for (std::vector<DetId>::const_iterator endcapIt=m_endcapCells.begin();
00565 endcapIt!=m_endcapCells.end();++endcapIt){
00566 EEDetId ee(*endcapIt);
00567 reg = EERegId(endcapIt->rawId());
00568
00569 if(reg==-1)
00570 m_xtalRegionId[endcapIt->rawId()]=reg;
00571
00572 else {
00573 if (ee.zside()>0)reg += EBRegionNum();
00574 else reg += EBRegionNum()+EERegionNum();
00575 m_xtalRegionId[endcapIt->rawId()]=reg;
00576 m_RinginRegion[endcapIt->rawId()]=(m_xtalRing[endcapIt->rawId()]-m_startRing)%m_etaWidth;
00577 }
00578 }
00579 }
00580
00581
00582
00583
00584
00586 inline int InvRingCalib::EERegionNum () const
00587 {
00588 return ((m_endRing - m_startRing)/m_etaWidth);
00589 }
00590
00591
00593 inline int InvRingCalib::EBRegionNum () const
00594 {
00595 return ((m_etaEnd - m_etaStart )/m_etaWidth);
00596 }
00598 int InvRingCalib::EBRegId(const int ieta) const
00599 {
00600 int reg;
00601 if (ieta<m_etaStart || ieta>=m_etaEnd) return -1;
00602 else reg = (ieta - m_etaStart)/m_etaWidth;
00603 return reg;
00604 }
00605
00606
00607
00608
00609
00610
00611 void InvRingCalib::EBRegionDef()
00612 {
00613 for (std::vector<DetId>::const_iterator it=m_barrelCells.begin();
00614 it!=m_barrelCells.end();++it)
00615 {
00616 EBDetId eb (it->rawId());
00617 m_xtalRing[eb.rawId()] = eb.ieta() ;
00618 m_xtalRegionId[eb.rawId()] = EBRegId (eb.ieta());
00619 if (m_xtalRegionId[eb.rawId()]==-1) continue;
00620 m_RinginRegion[eb.rawId()] = (eb.ieta() - m_etaStart)% m_etaWidth;
00621 }
00622 }
00623
00624
00625
00626
00627
00629 DetId InvRingCalib::findMaxHit (const std::vector<DetId> & v1,
00630 const EBRecHitCollection* EBhits,
00631 const EERecHitCollection* EEhits)
00632 {
00633 double currEnergy = 0.;
00634
00635 DetId maxHit;
00636
00637 for (std::vector<DetId>::const_iterator idsIt = v1.begin () ;
00638 idsIt != v1.end () ; ++idsIt)
00639 {
00640 if (idsIt->subdetId () == EcalBarrel)
00641 {
00642 EBRecHitCollection::const_iterator itrechit;
00643 itrechit = EBhits->find (*idsIt) ;
00644
00645 if (itrechit == EBhits->end () )
00646 {
00647 edm::LogWarning("IML") <<"max hit not found";
00648 continue;
00649 }
00650
00651
00652 if (itrechit->energy () > currEnergy)
00653 {
00654 currEnergy = itrechit->energy () ;
00655 maxHit= *idsIt ;
00656 }
00657 }
00658 else
00659 {
00660
00661 EERecHitCollection::const_iterator itrechit;
00662 itrechit = EEhits->find (*idsIt) ;
00663 if (itrechit == EEhits->end () )
00664 {
00665 edm::LogWarning("IML") <<"max hit not found";
00666 continue;
00667 }
00668 if (itrechit->energy () > currEnergy)
00669 {
00670 currEnergy=itrechit->energy ();
00671 maxHit= *idsIt;
00672 }
00673 }
00674 }
00675 return maxHit;
00676 }