CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/Calibration/Tools/src/EcalRingCalibrationTools.cc

Go to the documentation of this file.
00001 #include "Calibration/Tools/interface/EcalRingCalibrationTools.h"
00002 #include "DataFormats/DetId/interface/DetId.h"
00003 
00004 //Includes need to read from geometry
00005 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00006 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00007 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
00008 
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010 
00011 #include <iostream>
00012 
00013 
00014 //by default is not initialized, gets initialized at first call
00015 bool EcalRingCalibrationTools::isInitializedFromGeometry_ = false;
00016 const CaloGeometry* EcalRingCalibrationTools::caloGeometry_ = 0;
00017 short EcalRingCalibrationTools::endcapRingIndex_[EEDetId::IX_MAX][EEDetId::IY_MAX];
00018 
00019 
00020 short EcalRingCalibrationTools::getRingIndex(DetId id) 
00021 {
00022   if (id.det() != DetId::Ecal)
00023     return -1;
00024   
00025   if (id.subdetId() == EcalBarrel)
00026     {
00027       if(EBDetId(id).ieta()<0) 
00028         return EBDetId(id).ieta() + 85; 
00029       else 
00030         return EBDetId(id).ieta() + 84; 
00031       
00032     }
00033   if (id.subdetId() == EcalEndcap)
00034     {
00035       //needed only for the EE, it can be replaced at some point with something smarter
00036       if (!isInitializedFromGeometry_)
00037         initializeFromGeometry();
00038       EEDetId eid(id);
00039       short endcapRingIndex = endcapRingIndex_[eid.ix()-1][eid.iy()-1] + N_RING_BARREL;
00040       if (eid.zside() == 1) endcapRingIndex += N_RING_ENDCAP/2;
00041       return endcapRingIndex;
00042     }
00043   return -1;
00044 }
00045 
00046 short EcalRingCalibrationTools::getModuleIndex(DetId id) 
00047 {
00048 
00049   if (id.det() != DetId::Ecal)
00050     return -1;
00051   
00052   if (id.subdetId() == EcalBarrel)
00053     {
00054 
00055       
00056       short module = 4*( EBDetId(id).ism() -1 ) + EBDetId(id).im() -1; 
00057 
00058       //      std::cout<<"SM construction # : "<<EBDetId(id).ism() <<" SM installation # : "<<  installationSMNumber[ EBDetId(id).ism() -1 ]<< "Xtal is Module :"<<module<< std::endl;      
00059       return module;
00060       
00061     }
00062   if (id.subdetId() == EcalEndcap)
00063     {
00064       
00065       return -1; 
00066     }
00067 
00068   return -1;
00069 }
00070 
00071 std::vector<DetId> EcalRingCalibrationTools::getDetIdsInRing(short etaIndex) 
00072 {
00073 
00074 
00075   std::vector<DetId> ringIds;
00076   if (etaIndex < 0)
00077     return ringIds;
00078   
00079   if (etaIndex < N_RING_BARREL)
00080     {
00081 
00082       int k =0;
00083       if (etaIndex<85)
00084         k=-85 + etaIndex;
00085       else
00086         k= etaIndex - 84;
00087 
00088         for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) 
00089           
00090           if (EBDetId::validDetId(k,iphi))
00091             ringIds.push_back(EBDetId(k,iphi));
00092     }
00093 
00094   else if (etaIndex < N_RING_TOTAL)
00095     {
00096       //needed only for the EE, it can be replaced at some point maybe with something smarter
00097       if (!isInitializedFromGeometry_)
00098         initializeFromGeometry();
00099       
00100       int zside= (etaIndex < N_RING_BARREL + (N_RING_ENDCAP/2) ) ? -1 : 1;
00101       short eeEtaIndex = (etaIndex - N_RING_BARREL)%(N_RING_ENDCAP/2); 
00102 
00103       for (int ix=0;ix<EEDetId::IX_MAX;++ix)
00104         for (int iy=0;iy<EEDetId::IY_MAX;++iy)
00105           if (endcapRingIndex_[ix][iy] == eeEtaIndex)
00106             ringIds.push_back(EEDetId(ix+1,iy+1,zside));
00107       
00108     }
00109   
00110   return ringIds;
00111 } 
00112 
00113 std::vector<DetId> EcalRingCalibrationTools::getDetIdsInECAL() 
00114 {
00115   
00116   std::vector<DetId> ringIds;
00117   
00118   for(int ieta= - EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) 
00119     for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) 
00120       if (EBDetId::validDetId(ieta,iphi))
00121         ringIds.push_back(EBDetId(ieta,iphi));
00122   
00123   //needed only for the EE, it can be replaced at some point maybe with something smarter
00124   if (!isInitializedFromGeometry_)
00125     initializeFromGeometry();
00126   
00127   for (int ix=0;ix<EEDetId::IX_MAX;++ix)
00128     for (int iy=0;iy<EEDetId::IY_MAX;++iy)
00129       for(int zside = -1; zside<2; zside += 2)
00130         if ( EEDetId::validDetId(ix+1,iy+1,zside) )
00131           ringIds.push_back( EEDetId(ix+1,iy+1,zside) );
00132   
00133   
00134   //  std::cout<<" [EcalRingCalibrationTools::getDetIdsInECAL()] DetId.size() is "<<ringIds.size()<<std::endl;
00135   
00136   return ringIds;
00137 } 
00138 
00139 std::vector<DetId> EcalRingCalibrationTools::getDetIdsInModule(short moduleIndex) 
00140 {
00141 
00142   std::vector<DetId> ringIds;
00143   if (moduleIndex < 0)
00144     return ringIds;  
00145 
00146   short moduleBound[5] = {1, 26, 46, 66, 86};  
00147   if ( moduleIndex < EcalRingCalibrationTools::N_MODULES_BARREL)
00148     {
00150       short sm, moduleInSm, zsm;
00151 
00152       short minModuleiphi, maxModuleiphi, minModuleieta=360,maxModuleieta=0;
00153 
00154       //        if(moduleIndex%4 != 0 )
00155           sm = moduleIndex / 4 + 1;
00156           //    else
00157           //sm = moduleIndex/4;//i.e. module 8 belongs to sm=3, not sm=3
00158         
00159           //if(moduleIndex%4 != 0 )
00160           moduleInSm = moduleIndex%4;
00161           //else
00162           //moduleInSm = 4;//moduleInSm is [1,2,3,4]
00163 
00164         if(moduleIndex > 71)
00165           zsm = -1;
00166         else 
00167           zsm = 1;
00168         
00169         minModuleiphi = ( (sm - 1) %18 + 1 ) *20 - 19;
00170         maxModuleiphi = ( (sm - 1) %18 + 1 ) * 20;
00171         
00172         if(zsm == 1)
00173           {
00174             minModuleieta = moduleBound[ moduleInSm   ];
00175             maxModuleieta = moduleBound[ moduleInSm + 1 ] - 1;
00176           }
00177         else if(zsm == -1){
00178           minModuleieta = - moduleBound[ moduleInSm + 1 ] + 1;
00179           maxModuleieta = - moduleBound[ moduleInSm ];
00180         } 
00182 
00183 
00184         std::cout<<"Called moduleIndex "<<moduleIndex<<std::endl;
00185         std::cout<<"minModuleieta "<<minModuleieta<<" maxModuleieta "<<maxModuleieta<<" minModuleiphi "<<minModuleiphi<<" maxModuleiphi "<<maxModuleiphi<<std::endl;
00186 
00187         for(int ieta = minModuleieta; ieta <= maxModuleieta; ++ieta){ 
00188           for(int iphi = minModuleiphi; iphi<= maxModuleiphi; ++iphi){
00189             
00190             
00191               ringIds.push_back(EBDetId(ieta,iphi));
00192               
00193               //              std::cout<<"Putting Xtal with ieta: "<<ieta<<" iphi "<<iphi<<" of SM "<<sm<<" into Module "<<moduleIndex<<std::endl;
00194               
00195                     
00196         }//close loop on phi
00197         }//close loop on eta  
00198     }//close if ( moduleInstallationNumber < 144)
00199   
00200   return ringIds;
00201 } 
00202 
00203 void EcalRingCalibrationTools::initializeFromGeometry()
00204 {
00205 
00206   if (!caloGeometry_)
00207     {
00208       edm::LogError("EcalRingCalibrationTools") << "BIG ERROR::Initializing without geometry handle" ;
00209       return;
00210     }
00211 
00212   float m_cellPosEta[EEDetId::IX_MAX][EEDetId::IY_MAX];
00213   for (int ix=0; ix<EEDetId::IX_MAX; ++ix) 
00214     for (int iy=0; iy<EEDetId::IY_MAX; ++iy) 
00215       {
00216         m_cellPosEta[ix][iy] = -1.;
00217         endcapRingIndex_[ix][iy]=-9;
00218       }
00219   
00220   
00221   const CaloSubdetectorGeometry *endcapGeometry = caloGeometry_->getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
00222 
00223   if (!endcapGeometry)
00224     {
00225       edm::LogError("EcalRingCalibrationTools") << "BIG ERROR::Ecal Endcap geometry not found" ;
00226       return;
00227     }
00228 
00229   const std::vector<DetId>& m_endcapCells= caloGeometry_->getValidDetIds(DetId::Ecal, EcalEndcap);
00230 
00231   for (std::vector<DetId>::const_iterator endcapIt = m_endcapCells.begin();
00232        endcapIt!=m_endcapCells.end();
00233        ++endcapIt)
00234     {
00235       EEDetId ee(*endcapIt);
00236       if (ee.zside() == -1) continue; //Just using +side to fill absEta x,y map
00237       const CaloCellGeometry *cellGeometry = endcapGeometry->getGeometry(*endcapIt) ;
00238       int ics=ee.ix() - 1 ;
00239       int ips=ee.iy() - 1 ;
00240       m_cellPosEta[ics][ips] = fabs(cellGeometry->getPosition().eta());
00241 
00242       //std::cout<<"EE Xtal, |eta| is "<<fabs(cellGeometry->getPosition().eta())<<std::endl;
00243 
00244     }
00245   
00246   float eta_ring[N_RING_ENDCAP/2];
00247   for (int ring=0; ring<N_RING_ENDCAP/2; ++ring)
00248     eta_ring[ring]=m_cellPosEta[ring][50];
00249 
00250   double etaBoundary[N_RING_ENDCAP/2 + 1];
00251   etaBoundary[0]=1.47;
00252   etaBoundary[N_RING_ENDCAP/2]=4.0;
00253 
00254   for (int ring=1; ring<N_RING_ENDCAP/2; ++ring)
00255     etaBoundary[ring]=(eta_ring[ring]+eta_ring[ring-1])/2.;
00256   
00257   
00258   
00259   for (int ring=0; ring<N_RING_ENDCAP/2; ring++){
00260     // std::cout<<"***********************EE ring: "<<ring<<" eta "<<(etaBoundary[ring] + etaBoundary[ring+1])/2.<<std::endl;
00261     for (int ix=0; ix<EEDetId::IX_MAX; ix++)
00262       for (int iy=0; iy<EEDetId::IY_MAX; iy++)
00263         if (m_cellPosEta[ix][iy]>etaBoundary[ring] && m_cellPosEta[ix][iy]<etaBoundary[ring+1])
00264         {
00265           endcapRingIndex_[ix][iy]=ring;
00266           //std::cout<<"endcapRing_["<<ix+1<<"]["<<iy+1<<"] = "<<ring<<";"<<std::endl;  
00267         }
00268   }
00269 
00270   const std::vector<DetId>& m_barrelCells= caloGeometry_->getValidDetIds(DetId::Ecal, EcalBarrel);
00271 
00272   for (std::vector<DetId>::const_iterator barrelIt = m_barrelCells.begin();
00273        barrelIt!=m_barrelCells.end();
00274        ++barrelIt)
00275     {
00276       EBDetId eb(*barrelIt);
00277     }
00278 
00279 
00280   //EB
00281 
00282   isInitializedFromGeometry_ = true;
00283 
00284 }
00285 
00286