CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch2/src/Geometry/CaloTopology/src/EcalTrigTowerConstituentsMap.cc

Go to the documentation of this file.
00001 #include "Geometry/CaloTopology/interface/EcalTrigTowerConstituentsMap.h"
00002 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00003 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00004 
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006 
00007 #include "FWCore/Utilities/interface/Exception.h"
00008 
00009 EcalTrigTowerConstituentsMap::EcalTrigTowerConstituentsMap() 
00010 {
00011 }
00012 
00013 EcalTrigTowerDetId EcalTrigTowerConstituentsMap::towerOf(const DetId& id) const {
00014   if (id.det() == DetId::Ecal && id.subdetId() == EcalBarrel)
00015     {
00016       //--------------------
00017       // Ecal Barrel
00018       //--------------------
00019       EBDetId myId(id);
00020       return myId.tower();
00021     }
00022   else if (id.det() == DetId::Ecal && id.subdetId() == EcalEndcap)
00023     {
00024       //--------------------
00025       // Ecal Endcap
00026       //--------------------
00027       EEDetId originalId(id);
00028       // DetId wrappedId=wrapEEDetId(id);
00029       DetId wrappedId(originalId);
00030       EcalTowerMap::const_iterator i=m_items.find(wrappedId);
00031       if (i!=m_items.end()) 
00032         {
00033           int etaTower=i->tower.ietaAbs();
00034           int phiTower=i->tower.iphi();
00035           //trigger tower <-> crystal maping read 
00036           //..........from file and done only for 1 quadrant
00037           //move from quadrant 1 to the actual one:
00038           // phiTower = changeTowerQuadrant(phiTower, 1, originalId.iquadrant());
00039           // std::cout << originalId.zside() <<  " " << etaTower << " " << phiTower << std::endl;
00040           return EcalTrigTowerDetId(originalId.zside(),EcalEndcap,etaTower,phiTower);
00041         }
00042     }
00043   return EcalTrigTowerDetId(0);
00044 }
00045 
00046 DetId EcalTrigTowerConstituentsMap::wrapEEDetId(const DetId& eeid) const
00047 {
00048   if (! (eeid.det() == DetId::Ecal && eeid.subdetId() == EcalEndcap) )
00049     return EEDetId(0);
00050   
00051   EEDetId myId(eeid);
00052   switch((myId.iquadrant()-1)%4)
00053     {
00054     case 0:
00055       return DetId(EEDetId(myId.ix(),myId.iy(),1,EEDetId::XYMODE));
00056       break;
00057     case 1:
00058       return DetId(EEDetId(101-myId.ix(),myId.iy(),1,EEDetId::XYMODE));
00059       break;
00060     case 2:
00061       return DetId(EEDetId(101-myId.ix(),101-myId.iy(),1,EEDetId::XYMODE));   
00062       break;
00063     case 3:
00064       return DetId(EEDetId(myId.ix(),101-myId.iy(),1,EEDetId::XYMODE));   
00065       break;
00066     default:
00067       /*should never be reached*/
00068       edm::LogError("EcalTrigTowerConstituentsMapError") << "This should never be reached. Profound error!";    
00069     }
00070   return EEDetId(0);
00071 }
00072 
00073 
00074 DetId EcalTrigTowerConstituentsMap::wrapEcalTrigTowerDetId(const DetId& id) const
00075 {
00076   EcalTrigTowerDetId etid(id);
00077 
00078   if (! (etid.det() == DetId::Ecal && etid.subdetId() == EcalTriggerTower && etid.subDet() == EcalEndcap) )
00079     return EcalTrigTowerDetId(0);
00080   
00081   switch((etid.iquadrant()-1)%4)
00082     {
00083     case 0:
00084       return DetId(EcalTrigTowerDetId(1,EcalEndcap,etid.ietaAbs(),etid.iphi()));
00085       break;
00086     case 1:
00087       return DetId(EcalTrigTowerDetId(1,EcalEndcap,etid.ietaAbs(),EcalTrigTowerDetId::kEETowersInPhiPerQuadrant * 2 - etid.iphi() + 1));
00088       break;
00089     case 2:
00090       return DetId(EcalTrigTowerDetId(1,EcalEndcap,etid.ietaAbs(),etid.iphi() - EcalTrigTowerDetId::kEETowersInPhiPerQuadrant * 2 ));
00091       break;
00092     case 3:
00093       return DetId(EcalTrigTowerDetId(1,EcalEndcap,etid.ietaAbs(),EcalTrigTowerDetId::kEETowersInPhiPerQuadrant * 4 - etid.iphi() + 1));
00094       break;
00095     default:
00096       /*should never be reached*/
00097       edm::LogError("EcalTrigTowerConstituentsMapError") << "This should never be reached. Profound error!";    
00098     }
00099   return EcalTrigTowerDetId(0);
00100 }
00101 
00102 DetId EcalTrigTowerConstituentsMap::changeEEDetIdQuadrantAndZ(const DetId& fromid, const int& toQuadrant,const int& tozside) const
00103 {
00104   if (! (fromid.det() == DetId::Ecal && fromid.subdetId() == EcalEndcap) )
00105     return EEDetId(0);
00106   
00107   EEDetId myId(fromid);
00108   int dQuadrant = toQuadrant-myId.iquadrant(); 
00109   switch(dQuadrant%4){
00110   case 0:
00111     return DetId(EEDetId(myId.ix(),myId.iy(),tozside,EEDetId::XYMODE));
00112     break;
00113   case 1:
00114     /* adjacent tower: they are symetric*/
00115     return DetId(EEDetId(101-myId.ix(),myId.iy(),tozside,EEDetId::XYMODE));
00116     break;
00117   case 2:
00118     /* opposite quadrant: they are identical*/
00119     return DetId(EEDetId(101-myId.ix(),101-myId.iy(),tozside,EEDetId::XYMODE));   
00120     break;
00121   case 3:
00122     /* adjacent tower: they are symetric*/
00123     return DetId(EEDetId(myId.ix(),101-myId.iy(),tozside,EEDetId::XYMODE));   
00124     break;
00125   default:
00126     /*should never be reached*/
00127     edm::LogError("EcalTrigTowerConstituentsMapError") << "This should never be reached. Profound error!";    
00128   }
00129   return EEDetId(0);
00130 }
00131 
00132 int EcalTrigTowerConstituentsMap::changeTowerQuadrant(int phiTower, int fromQuadrant, int toQuadrant) const{
00133   int newPhiTower = phiTower;
00134   int dQuadrant = toQuadrant-fromQuadrant; 
00135   
00136   switch(dQuadrant%4){
00137   case 0:
00138     newPhiTower = phiTower;
00139     break;
00140   case 1:
00141     /* adjacent tower: they are symetric*/
00142     newPhiTower = EcalTrigTowerDetId::kEETowersInPhiPerQuadrant * 2 - phiTower + 1;
00143     break;
00144   case 2:
00145     /* opposite quadrant: they are identical*/
00146     newPhiTower = phiTower + EcalTrigTowerDetId::kEETowersInPhiPerQuadrant * 2;
00147     break;
00148   case 3:
00149     /* adjacent tower: they are symetric*/
00150     newPhiTower = EcalTrigTowerDetId::kEETowersInPhiPerQuadrant * 4 - phiTower + 1;
00151     break;
00152   default:
00153     /*should never be reached*/
00154     edm::LogError("EcalTrigTowerConstituentsMapError") << "This should never be reached. Profound error!";    
00155   }
00156   return newPhiTower;
00157 }
00158 
00159 void EcalTrigTowerConstituentsMap::assign(const DetId& cell, const EcalTrigTowerDetId& tower) {
00160   if (m_items.find(cell)!=m_items.end()) {
00161     throw cms::Exception("EcalTrigTowers") << "Cell with id " << std::hex << cell.rawId() << std::dec << " is already mapped to a EcalTrigTower " << m_items.find(cell)->tower << std::endl;
00162   }
00163   
00164   m_items.insert(MapItem(cell,tower));
00165 }
00166 
00167 std::vector<DetId> EcalTrigTowerConstituentsMap::constituentsOf(const EcalTrigTowerDetId& id) const {
00168   std::vector<DetId> items;
00169   
00170   if ( id.det() == DetId::Ecal && id.subdetId() == EcalTriggerTower && id.subDet() == EcalBarrel ) 
00171     {
00172       //--------------------
00173       // Ecal Barrel
00174       //--------------------
00175       // trigger towers are 5x5 crystals in the barrel
00176       int etaxtalMin=(id.ietaAbs()-1)*5+1;
00177       int phixtalMin=((id.iphi()-1)*5+11)%360;
00178       if(phixtalMin<=0)phixtalMin+=360;
00179       int etaxtalMax=id.ietaAbs()*5;
00180       int phixtalMax=((id.iphi())*5+10)%360;
00181       if(phixtalMax<=0) phixtalMax+=360;
00182       for(int e=etaxtalMin;e<=etaxtalMax;e++) 
00183         for(int p=phixtalMin;p<=phixtalMax;p++) 
00184           items.push_back(DetId(EBDetId(id.zside()*e,p,EBDetId::ETAPHIMODE)));
00185     }
00186   else if (id.det() == DetId::Ecal && id.subdetId() == EcalTriggerTower && id.subDet() == EcalEndcap) 
00187     {
00188       //--------------------
00189       // Ecal Endcap
00190       //--------------------
00191       //DetId myId=wrapEcalTrigTowerDetId(id);  
00192       EcalTowerMap_by_towerDetId::const_iterator lb,ub;
00193       //boost::tuples::tie(lb,ub)=get<1>(m_items).equal_range(myId);
00194       boost::tuples::tie(lb,ub)=boost::get<1>(m_items).equal_range(id);
00195       while (lb!=ub)
00196         {
00197           //EEDetId mappedId((*lb).cell);
00198           //items.push_back(changeEEDetIdQuadrantAndZ(mappedId,id.iquadrant(),id.zside()));
00199           items.push_back((*lb).cell);
00200           ++lb;
00201         }
00202     }
00203   
00204   return items;
00205 }
00206