Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:57:50

0001 #include <cassert>
0002 #include <iostream>
0003 #include <iomanip>
0004 using namespace std;
0005 
0006 #include "CalibCalorimetry/EcalLaserAnalyzer/interface/ME.h"
0007 #include "CalibCalorimetry/EcalLaserAnalyzer/interface/MEChannel.h"
0008 #include "CalibCalorimetry/EcalLaserAnalyzer/interface/MEGeom.h"
0009 
0010 // ClassImp(MEChannel)
0011 
0012 MEChannel::MEChannel(int ix, int iy, int id_, MEChannel* mother) : _m(mother) {
0013   if (_m == nullptr) {
0014     _ig = 0;
0015   } else {
0016     _ig = _m->_ig + 1;
0017   }
0018   _id.resize(_ig + 1, -1);
0019   for (int ii = 0; ii < _ig; ii++) {
0020     _id[ii] = _m->_id[ii];
0021   }
0022   _id[_ig] = id_;
0023   _ix = ix;
0024   _iy = iy;
0025 }
0026 
0027 MEChannel::~MEChannel() {
0028   for (unsigned ii = 0; ii < _d.size(); ii++) {
0029     delete _d[ii];
0030   }
0031 }
0032 
0033 MEChannel* MEChannel::getDaughter(int ix, int iy, int id_) {
0034   for (unsigned ii = 0; ii < _d.size(); ii++) {
0035     if (_d[ii]->id() == id_) {
0036       return _d[ii];
0037     }
0038   }
0039   return addDaughter(ix, iy, id_);
0040 }
0041 
0042 MEChannel* MEChannel::addDaughter(int ix, int iy, int id_) {
0043   MEChannel* d = new MEChannel(ix, iy, id_, this);
0044   _d.push_back(d);
0045   return d;
0046 }
0047 
0048 int MEChannel::id() const { return _id[_ig]; }
0049 
0050 bool MEChannel::getListOfChannels(std::vector<MEChannel*>& vec) {
0051   if (n() == 0) {
0052     vec.push_back(this);
0053     return true;
0054   }
0055   for (unsigned ii = 0; ii < n(); ii++) {
0056     bool ok = _d[ii]->getListOfChannels(vec);
0057     assert(ok);
0058   }
0059   return true;
0060 }
0061 
0062 bool MEChannel::getListOfAncestors(std::vector<MEChannel*>& vec) {
0063   MEChannel* mother = this->m();
0064   if (mother != nullptr) {
0065     vec.push_back(mother);
0066     mother->getListOfAncestors(vec);
0067   }
0068   return true;
0069 }
0070 
0071 MEChannel* MEChannel::getAncestor(int g) {
0072   if (_ig == g)
0073     return this;
0074 
0075   MEChannel* mother = this->m();
0076   if (mother != nullptr) {
0077     if (mother->_ig == g)
0078       return mother;
0079     return mother->getAncestor(g);
0080   }
0081 
0082   return nullptr;
0083 }
0084 
0085 bool MEChannel::getListOfDescendants(std::vector<MEChannel*>& vec) {
0086   for (unsigned ii = 0; ii < n(); ii++) {
0087     vec.push_back(_d[ii]);
0088     _d[ii]->getListOfDescendants(vec);
0089   }
0090   return true;
0091 }
0092 
0093 bool MEChannel::getListOfDescendants(int ig, std::vector<MEChannel*>& vec) {
0094   for (unsigned ii = 0; ii < n(); ii++) {
0095     MEChannel* curLeaf = _d[ii];
0096     if (curLeaf->_ig == ig)
0097       vec.push_back(curLeaf);
0098     curLeaf->getListOfDescendants(ig, vec);
0099   }
0100   return true;
0101 }
0102 
0103 MEChannel* MEChannel::getDescendant(int ig, int id_) {
0104   std::vector<MEChannel*> vec;
0105   bool OK = getListOfDescendants(ig, vec);
0106   if (!OK)
0107     return nullptr;
0108   MEChannel* leaf(nullptr);
0109   for (unsigned int ii = 0; ii < vec.size(); ii++) {
0110     leaf = vec[ii];
0111     if (leaf->id() == id_)
0112       return leaf;
0113   }
0114   return leaf;
0115 }
0116 
0117 MEChannel* MEChannel::getFirstDescendant(int ig) {
0118   std::vector<MEChannel*> vec;
0119   bool OK = getListOfDescendants(ig, vec);
0120   if (!OK)
0121     return nullptr;
0122   return vec[0];
0123 }
0124 
0125 MEChannel* MEChannel::getChannel(int ig, int ix, int iy) {
0126   assert(ig >= 0);
0127   MEChannel* leaf = getChannel(ix, iy);
0128   if (leaf == nullptr)
0129     return nullptr;
0130   while (ig != leaf->_ig) {
0131     leaf = leaf->_m;
0132   }
0133   return leaf;
0134 }
0135 
0136 MEChannel* MEChannel::getChannel(int ix, int iy) {
0137   if (n() == 0) {
0138     if (ix == _ix && iy == _iy) {
0139       return this;
0140     } else
0141       return nullptr;
0142   }
0143   MEChannel* leaf(nullptr);
0144   for (unsigned ii = 0; ii < n(); ii++) {
0145     leaf = _d[ii]->getChannel(ix, iy);
0146     if (leaf != nullptr)
0147       break;
0148   }
0149   return leaf;
0150 }
0151 
0152 void MEChannel::print(ostream& o, bool recursif) const {
0153   o << ME::granularity[_ig] << " ";
0154   for (int ii = 0; ii <= _ig; ii++) {
0155     o << ME::granularity[ii] << "=" << _id[ii] << " ";
0156   }
0157   if (n() > 0) {
0158     o << "NDau=" << n() << " ";
0159   } else {
0160     o << "ix=" << _ix << " iy=" << _iy << " ";
0161   }
0162   o << std::endl;
0163   if (recursif) {
0164     for (unsigned jj = 0; jj < n(); jj++) {
0165       _d[jj]->print(o, true);
0166     }
0167   }
0168 }
0169 
0170 TString MEChannel::oneLine(int ig) {
0171   assert(ig >= ME::iEcalRegion);
0172   int reg_ = _id[ME::iEcalRegion];
0173   TString out;
0174   if (ig < ME::iLMRegion) {
0175     out += ME::region[reg_];
0176     if (ig == ME::iSector) {
0177       out += "/S=";
0178       out += _id[ME::iSector];
0179     }
0180     return out;
0181   }
0182   int lmr_ = _id[ME::iLMRegion];
0183   std::pair<int, int> p_ = ME::dccAndSide(lmr_);
0184   out += ME::granularity[ME::iLMRegion];
0185   out += "=";
0186   out += lmr_;
0187   int dcc_ = p_.first;
0188   int side_ = p_.second;
0189   out += "(DCC=";
0190   out += dcc_;
0191   out += ",";
0192   out += ME::smName(lmr_);
0193   out += "/";
0194   out += side_;
0195   out += ")";
0196   if (ig >= _ig)
0197     ig = _ig;
0198   if (ig >= ME::iLMModule) {
0199     int lmm_ = _id[ME::iLMModule];
0200     out += "/";
0201     out += ME::granularity[ME::iLMModule];
0202     out += "=";
0203     out += lmm_;
0204     if (ig >= ME::iSuperCrystal) {
0205       int sc_ = _id[ME::iSuperCrystal];
0206       out += "/";
0207       out += ME::granularity[ME::iSuperCrystal];
0208       out += "=";
0209       out += sc_;
0210       if (ig >= ME::iCrystal) {
0211         int c_ = _id[ME::iCrystal];
0212         out += "/";
0213         out += ME::granularity[ME::iCrystal];
0214         out += "=";
0215         out += c_;
0216         if (reg_ == ME::iEBM || reg_ == ME::iEBP) {
0217           out += "/ieta=";
0218           out += ix();
0219           out += "/iphi=";
0220           out += iy();
0221           MEEBGeom::XYCoord ixy_ = MEEBGeom::localCoord(ix(), iy());
0222           out += "(ix=";
0223           out += ixy_.first;
0224           out += "/iy=";
0225           out += ixy_.second;
0226           out += ")";
0227         } else {
0228           out += "/ix=";
0229           out += ix();
0230           out += "/iy=";
0231           out += iy();
0232         }
0233       }
0234     }
0235   }
0236   if (ig < ME::iCrystal) {
0237     std::vector<MEChannel*> _channels;
0238     getListOfChannels(_channels);
0239     int nchan = _channels.size();
0240     if (nchan > 1) {
0241       out += "(";
0242       out += nchan;
0243       out += "xTals)";
0244     }
0245   }
0246   return out;
0247 }
0248 
0249 TString MEChannel::oneWord(int ig) {
0250   assert(ig >= ME::iEcalRegion);
0251   int reg_ = _id[ME::iEcalRegion];
0252   TString out;
0253   if (ig < ME::iLMRegion) {
0254     out = "ECAL_";
0255     out += ME::region[reg_];
0256     if (ig == ME::iSector) {
0257       out += "_S";
0258       out += _id[ME::iSector];
0259     }
0260     return out;
0261   }
0262   int lmr_ = _id[ME::iLMRegion];
0263   out += ME::granularity[ME::iLMRegion];
0264   out += lmr_;
0265   if (ig >= _ig)
0266     ig = _ig;
0267   if (ig >= ME::iLMModule) {
0268     int lmm_ = _id[ME::iLMModule];
0269     out += "_";
0270     out += ME::granularity[ME::iLMModule];
0271     out += lmm_;
0272     if (ig >= ME::iSuperCrystal) {
0273       int sc_ = _id[ME::iSuperCrystal];
0274       out += "_";
0275       out += ME::granularity[ME::iSuperCrystal];
0276       out += sc_;
0277       if (ig >= ME::iCrystal) {
0278         int c_ = _id[ME::iCrystal];
0279         out += "_";
0280         out += ME::granularity[ME::iCrystal];
0281         out += c_;
0282         if (reg_ == ME::iEBM || reg_ == ME::iEBP) {
0283           MEEBGeom::XYCoord ixy_ = MEEBGeom::localCoord(ix(), iy());
0284           out += "_";
0285           out += ixy_.first;
0286           out += "_";
0287           out += ixy_.second;
0288         } else {
0289           out += "_";
0290           out += ix();
0291           out += "_";
0292           out += iy();
0293         }
0294       }
0295     }
0296   }
0297   return out;
0298 }