CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/src/CalibCalorimetry/EcalLaserAnalyzer/src/MEChannel.cc

Go to the documentation of this file.
00001 #include <cassert>
00002 #include <iostream>
00003 #include <iomanip>
00004 using namespace std;
00005 
00006 #include "CalibCalorimetry/EcalLaserAnalyzer/interface/ME.h"
00007 #include "CalibCalorimetry/EcalLaserAnalyzer/interface/MEChannel.h"
00008 #include "CalibCalorimetry/EcalLaserAnalyzer/interface/MEGeom.h"
00009 
00010 // ClassImp(MEChannel)
00011 
00012 MEChannel::MEChannel( int ix, int iy, int id_, MEChannel* mother )
00013   : _m(mother)
00014 {
00015   if( _m==0 ) 
00016     {
00017       _ig=0;      
00018     }
00019   else 
00020     {
00021       _ig = _m->_ig+1;
00022     }
00023   _id.resize( _ig+1, -1 );
00024   for( int ii=0; ii<_ig; ii++ )
00025     {
00026       _id[ii] = _m->_id[ii];
00027     }
00028   _id[_ig] = id_;
00029   _ix = ix;
00030   _iy = iy;
00031 }
00032 
00033 MEChannel::~MEChannel() 
00034 {
00035   for( unsigned ii=0; ii<_d.size(); ii++ )
00036     {
00037       delete _d[ii];
00038     }
00039 }
00040 
00041 MEChannel* 
00042 MEChannel::getDaughter( int ix, int iy, int id_ )
00043 {
00044   for( unsigned ii=0; ii<_d.size(); ii++ )
00045     {
00046       if( _d[ii]->id()==id_ ) 
00047         {
00048           return _d[ii];
00049         }
00050     }  
00051   return addDaughter( ix, iy, id_ );
00052 }
00053 
00054 MEChannel*
00055 MEChannel::addDaughter( int ix, int iy, int id_ )
00056 {
00057   MEChannel* d = new MEChannel( ix, iy, id_, this );
00058   _d.push_back( d );
00059   return d;
00060 }
00061 
00062 int
00063 MEChannel::id() const
00064 {
00065   return _id[_ig];
00066 }
00067 
00068 bool
00069 MEChannel::getListOfChannels( std::vector< MEChannel* >& vec )
00070 {
00071   if( n()==0 ) 
00072     {
00073       vec.push_back( this );
00074       return true;
00075     }
00076   for( unsigned ii=0; ii<n(); ii++ )
00077     {
00078       bool ok = _d[ii]->getListOfChannels( vec ); 
00079       assert( ok );
00080     }
00081   return true;
00082 }
00083 
00084 bool
00085 MEChannel::getListOfAncestors( std::vector< MEChannel* >& vec )
00086 {
00087   MEChannel* mother = this->m();
00088   if( mother!=0 )
00089     {
00090       vec.push_back( mother );
00091       mother->getListOfAncestors( vec );
00092     }
00093   return true;
00094 }
00095 
00096 MEChannel* 
00097 MEChannel::getAncestor( int g )
00098 {
00099   if( _ig==g ) return this;
00100   
00101   MEChannel* mother = this->m();
00102   if( mother!=0 )
00103     {
00104       if( mother->_ig==g ) return mother;
00105       return mother->getAncestor( g );
00106     }
00107 
00108   return 0;
00109 }
00110 
00111 bool
00112 MEChannel::getListOfDescendants( std::vector< MEChannel* >& vec )
00113 {
00114   for( unsigned ii=0; ii<n(); ii++ )
00115     {
00116       vec.push_back(_d[ii]);
00117       _d[ii]->getListOfDescendants( vec ); 
00118     }
00119   return true;
00120 }
00121 
00122 bool
00123 MEChannel::getListOfDescendants( int ig, std::vector< MEChannel* >& vec )
00124 {
00125   for( unsigned ii=0; ii<n(); ii++ )
00126     {
00127       MEChannel* curLeaf = _d[ii];
00128       if( curLeaf->_ig==ig ) vec.push_back(curLeaf);
00129       curLeaf->getListOfDescendants( ig, vec ); 
00130     }
00131   return true;
00132 }
00133 
00134 MEChannel*
00135 MEChannel::getDescendant( int ig, int id_ )
00136 {
00137   std::vector< MEChannel* > vec;
00138   bool OK = getListOfDescendants( ig, vec );
00139   if( !OK ) return 0;
00140   MEChannel* leaf(0);
00141   for( unsigned int ii=0; ii<vec.size(); ii++ )
00142     {
00143       leaf = vec[ii];
00144       if( leaf->id()==id_ ) return leaf;
00145     }
00146   return leaf;
00147 }
00148 
00149 MEChannel*
00150 MEChannel::getFirstDescendant( int ig )
00151 {
00152   std::vector< MEChannel* > vec;
00153   bool OK = getListOfDescendants( ig, vec );
00154   if( !OK ) return 0;
00155   return vec[0];
00156 }
00157 
00158 MEChannel* 
00159 MEChannel::getChannel( int ig, int ix, int iy )
00160 {
00161   assert( ig>=0 );
00162   MEChannel* leaf = getChannel( ix, iy );
00163   if( leaf==0 ) return 0;
00164   while( ig!=leaf->_ig )
00165     {
00166       leaf = leaf->_m;
00167     }
00168   return leaf;
00169 }
00170 
00171 MEChannel*
00172 MEChannel::getChannel( int ix, int iy )
00173 {
00174   if( n()==0 )
00175     {
00176       if( ix==_ix && iy==_iy )
00177         {
00178           return this;
00179         }
00180       else
00181         return 0;
00182     }
00183   MEChannel* leaf(0);
00184   for( unsigned ii=0; ii<n(); ii++ )
00185     {
00186       leaf =  _d[ii]->getChannel( ix, iy ); 
00187       if( leaf!=0 ) break;
00188     }
00189   return leaf;
00190 }
00191 
00192 void
00193 MEChannel::print( ostream& o, bool recursif ) const
00194 {
00195   o << ME::granularity[_ig] << " ";
00196   for( int ii=0; ii<=_ig; ii++ )
00197     { 
00198       o << ME::granularity[ii] << "=" << _id[ii] << " ";
00199     }
00200   if( n()>0 )
00201     {
00202       o << "NDau=" << n() << " " ;
00203     }
00204   else
00205     {
00206       o << "ix=" << _ix << " iy=" << _iy << " " ;
00207     }
00208   o << std::endl;
00209   if( recursif )
00210     {
00211       for( unsigned jj=0; jj<n(); jj++ )
00212         {
00213           _d[jj]->print( o, true );
00214         }
00215     }
00216 }
00217 
00218 TString
00219 MEChannel::oneLine( int ig )
00220 {
00221   assert( ig>=ME::iEcalRegion );
00222   int reg_ = _id[ME::iEcalRegion];
00223   TString out;
00224   if( ig<ME::iLMRegion )
00225     {
00226       out += ME::region[reg_];
00227       if( ig==ME::iSector ) out+="/S="; out+=_id[ME::iSector];
00228       return out;
00229     }
00230   int lmr_ = _id[ME::iLMRegion];
00231   std::pair<int,int> p_ = ME::dccAndSide( lmr_ );
00232   out+= ME::granularity[ME::iLMRegion]; 
00233   out+="=";out += lmr_;
00234   int dcc_=p_.first; 
00235   int side_=p_.second; 
00236   out+="(DCC="; out+=dcc_; out+=","; 
00237   out+= ME::smName(lmr_);
00238   out+="/"; out+=side_; out+=")";
00239   if( ig>=_ig ) ig=_ig;
00240   if( ig>=ME::iLMModule )
00241     {
00242       int lmm_=_id[ME::iLMModule]; 
00243       out+="/"; 
00244       out+=ME::granularity[ME::iLMModule];
00245       out+="=";
00246       out+=lmm_;
00247       if( ig>=ME::iSuperCrystal )
00248         {
00249           int sc_=_id[ME::iSuperCrystal];
00250           out+="/"; 
00251           out+=ME::granularity[ME::iSuperCrystal];
00252           out+="=";
00253           out+=sc_;
00254           if( ig>=ME::iCrystal )
00255             {
00256               int c_=_id[ME::iCrystal];
00257               out+="/"; 
00258               out+=ME::granularity[ME::iCrystal];
00259               out+="=";
00260               out+=c_;
00261               if( reg_==ME::iEBM || reg_==ME::iEBP )
00262                 {
00263                   out += "/ieta="; out+=ix();
00264                   out += "/iphi="; out+=iy();
00265                   MEEBGeom::XYCoord ixy_ = 
00266                     MEEBGeom::localCoord( ix(), iy() );
00267                   out += "(ix="; out+=ixy_.first;
00268                   out += "/iy="; out+=ixy_.second;
00269                   out += ")";
00270                 }
00271               else
00272                 {
00273                   out += "/ix="; out+=ix();
00274                   out += "/iy="; out+=iy();
00275                 }
00276             }
00277         }
00278     }
00279   if( ig<ME::iCrystal )
00280     {
00281       std::vector< MEChannel* > _channels;
00282       getListOfChannels( _channels );
00283       int nchan = _channels.size();
00284       if( nchan>1 )
00285         {
00286           out += "(";
00287           out += nchan;
00288           out += "xTals)";
00289         }
00290     }
00291   return out;
00292 }
00293 
00294 TString
00295 MEChannel::oneWord( int ig )
00296 {
00297   assert( ig>=ME::iEcalRegion );
00298   int reg_ = _id[ME::iEcalRegion];
00299   TString out;
00300   if( ig<ME::iLMRegion )
00301     {
00302       out = "ECAL_"; 
00303       out += ME::region[reg_];
00304       if( ig==ME::iSector ) out+="_S"; out+=_id[ME::iSector];
00305       return out;
00306     }
00307   int lmr_ = _id[ME::iLMRegion];
00308   out+= ME::granularity[ME::iLMRegion]; 
00309   out+=lmr_;
00310   if( ig>=_ig ) ig=_ig;
00311   if( ig>=ME::iLMModule )
00312     {
00313       int lmm_=_id[ME::iLMModule]; 
00314       out+="_"; 
00315       out+=ME::granularity[ME::iLMModule];
00316       out+=lmm_;
00317       if( ig>=ME::iSuperCrystal )
00318         {
00319           int sc_=_id[ME::iSuperCrystal];
00320           out+="_"; 
00321           out+=ME::granularity[ME::iSuperCrystal];
00322           out+=sc_;
00323           if( ig>=ME::iCrystal )
00324             {
00325               int c_=_id[ME::iCrystal];
00326               out+="_"; 
00327               out+=ME::granularity[ME::iCrystal];
00328               out+=c_;
00329               if( reg_==ME::iEBM || reg_==ME::iEBP )
00330                 {
00331                   MEEBGeom::XYCoord ixy_ = 
00332                     MEEBGeom::localCoord( ix(), iy() );
00333                   out += "_"; out+=ixy_.first;
00334                   out += "_"; out+=ixy_.second;
00335                 }
00336               else
00337                 {
00338                   out += "_"; out+=ix();
00339                   out += "_"; out+=iy();
00340                 }
00341             }
00342         }
00343     }
00344   return out;
00345 }
00346