CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/CalibCalorimetry/EcalLaserAnalyzer/src/MEGeom.cc

Go to the documentation of this file.
00001 #include <cassert>
00002 #include <iostream>
00003 #include <stdlib.h>
00004 #include <string>
00005 using namespace std;
00006 
00007 #include "CalibCalorimetry/EcalLaserAnalyzer/interface/MEGeom.h"
00008 #include "CalibCalorimetry/EcalLaserAnalyzer/interface/ME.h"
00009 
00010 #include <TCanvas.h>
00011 #include <TGraph.h>
00012 #include <TFile.h>
00013 #include <TH2.h>
00014 
00015 //TString MEGeom::granularity[MEGeom::iSizeG] = { 
00016 //  "Ecal Region", "Ecal Sector", "Laser Monitoring Region", "Laser Monitoring Module", "Super-Crystal", "Crystal" 
00017 //};
00018 
00019 int MEGeom::_nbuf = 5;
00020 int MEGeom::_nbinx = 2*( MEGeom::_nbuf + 100 + 85 ) + 1;
00021 float MEGeom::_xmin = -( 0.5 + MEGeom::_nbuf + 100 + 85 );
00022 float MEGeom::_xmax =    0.5 + MEGeom::_nbuf + 100 + 85  ;
00023 int MEGeom::_nbiny = 2*( MEGeom::_nbuf + 180 );
00024 float MEGeom::_ymin = 180.5 - ( MEGeom::_nbuf + 180 );  
00025 float MEGeom::_ymax = 180.5 + ( MEGeom::_nbuf + 180 );
00026 TH2* MEGeom::_h = new TH2F( "globalEcal", "Global representation of ECAL",
00027                             MEGeom::_nbinx, MEGeom::_xmin, MEGeom::_xmax, 
00028                             MEGeom::_nbiny, MEGeom::_ymin, MEGeom::_ymax );
00029 
00030 //GHM ClassImp(MEGeom)
00031 
00032 
00033 TH2* 
00034 MEGeom::getHist( int ilmr, int unit )
00035 {
00036   int ireg;
00037   int ism;
00038   int idcc; 
00039   int side;
00040   ME::regionAndSector( ilmr, ireg, ism, idcc, side );
00041 
00042   std::cout << "LM region=" << ilmr << " reg/sm/dcc/side " << ireg << "/" << ism << "/" << idcc << "/" << side << std::endl;
00043 
00044   TString hname = "LMR="; hname += ilmr; hname += " ";
00045   if( ireg==ME::iEEM || ireg==ME::iEEP )
00046     {
00047       hname += MEEEGeom::smName( ism );
00048     }
00049   else if( ireg==ME::iEBM || ireg==ME::iEBP )
00050     {
00051       hname += MEEBGeom::smName( ism );
00052     }
00053   else
00054     abort();
00055 
00056   hname += " ";
00057   hname += "DCC="; hname += idcc; hname += "/" ; hname += side;
00058   
00059   //
00060   // to produce these root files, run the runGeom executable
00061   //
00062   TH2* h_(0);
00063   TFile* rootfile(0);
00064   TString hn_;
00065   if( ireg==ME::iEBM || ireg==ME::iEBP )
00066     {
00067       rootfile = TFile::Open("ebgeom.root");
00068       assert( rootfile!=0 );
00069       hn_="eb_loc";
00070       switch ( unit )
00071         {
00072         case ME::iSector:             break;
00073         case ME::iLMRegion:           hn_ += "_side";   break;
00074         case ME::iLMModule:           hn_ += "_lmmod";  break;
00075         case ME::iSuperCrystal:       hn_ += "_tt";     break;
00076         case ME::iCrystal:            hn_ += "_cr";     break;
00077         case ME::iElectronicChannel:  hn_ += "_elecr";  break;
00078         case ME::iHVChannel:          hn_ += "_hv";     break;
00079         case ME::iLVChannel:          hn_ += "_lv";     break;
00080         }
00081     }
00082   else
00083     {
00084       int isect=ism;
00085       if( ireg==ME::iEEM )
00086         {
00087           isect-=9;
00088           rootfile = TFile::Open("eegeom_1.root");
00089         }
00090       if( ireg==ME::iEEP ) rootfile = TFile::Open("eegeom_2.root");
00091       assert( rootfile!=0 );
00092       hn_="eem_S"; hn_+= isect; 
00093       switch (unit)
00094         {
00095         case ME::iSector:             break;
00096         case ME::iLMRegion:   break;
00097         case ME::iLMModule:   hn_ += "_lmmod";  break;
00098         case ME::iSuperCrystal:       hn_ += "_sc";     break;
00099         case ME::iCrystal:            hn_ += "_cr";     break;
00100         case ME::iElectronicChannel:  hn_ += "_cr";  break;
00101         case ME::iHVChannel:          break;
00102         case ME::iLVChannel:          break;
00103         }
00104     }
00105   h_ = (TH2*) rootfile->Get( hn_ );
00106   h_->SetTitle( hname );
00107   h_->GetXaxis()->SetTitle("ix");
00108   h_->GetXaxis()->CenterTitle();
00109   h_->GetYaxis()->SetTitle("iy");
00110   h_->GetYaxis()->CenterTitle();
00111   return h_;
00112 }
00113 
00114 TGraph* 
00115 MEGeom::getBoundary( int ilmr, int histtype )
00116 {
00117   // for local pictures, only sector or monitoring region
00118   if( histtype!=ME::iSector && histtype!=ME::iLMRegion ) 
00119     histtype = ME::iSector;
00120 
00121   int ireg;
00122   int ism;
00123   int idcc; 
00124   int side;
00125   ME::regionAndSector( ilmr, ireg, ism, idcc, side );
00126 
00127   //
00128   // to produce these root files, run the runGeom executable
00129   //
00130   TGraph* g_(0);
00131   TFile* rootfile(0);
00132   TString gn_;
00133   if( ireg==ME::iEBM || ireg==ME::iEBP )
00134     {
00135       rootfile = TFile::Open("ebgeom.root");
00136       assert( rootfile!=0 );
00137       switch (histtype)
00138         {
00139         case ME::iSector:             gn_ = "SuperModule"; break;
00140         case ME::iLMRegion:   gn_ = "Side_"; gn_+=side; break;
00141         }
00142     }
00143   else
00144     {
00145       int isect=ism;
00146       if( ireg==ME::iEEM ) 
00147         {
00148           isect-=9;
00149           rootfile = TFile::Open("eegeom_1.root");
00150         }
00151       if( ireg==ME::iEEP ) rootfile = TFile::Open("eegeom_2.root");
00152       assert( rootfile!=0 );
00153       int lmr_= ilmr;
00154       if( ireg==ME::iEEP ) lmr_-=72;
00155       else if( ireg==ME::iEEM ) lmr_-=82;
00156       switch (histtype)
00157         {
00158         case ME::iSector:             gn_ = "Sector_"; gn_+=isect; break;
00159         case ME::iLMRegion:   gn_ = "LMRegion_"; gn_+=lmr_; break;
00160         }
00161     }
00162   g_ = (TGraph*) rootfile->Get( gn_ );
00163   return g_;
00164 }
00165 
00166 void
00167 MEGeom::drawHist( int ilmr, int histtype, TCanvas* canv )
00168 {
00169 
00170   TH2* h = getHist( ilmr, histtype );
00171   assert( h!=0 );
00172   TString tname = h->GetTitle();
00173   switch( histtype )
00174     {
00175     case ME::iSector: break;
00176     case ME::iLMRegion: tname += " Monitoring Regions"; break;
00177     case ME::iLMModule: tname += " Monitoring Modules"; break;
00178     case ME::iSuperCrystal: tname += " Super Crystals"; break;
00179     case ME::iCrystal: tname += " Crystals"; break;
00180     case ME::iElectronicChannel: tname += " Electronic Channels"; break;
00181     case ME::iHVChannel: tname += " HV Channels"; break;
00182     case ME::iLVChannel: tname += " LV Channels"; break;
00183     }
00184   
00185   if( canv==0 )
00186     {
00187       TString cname = tname;
00188       cname.ReplaceAll(" ","_");
00189       canv = new TCanvas( cname, cname, 10, 10, 500, 500 );
00190     }
00191   canv->SetTitle( tname );
00192   canv->cd();
00193 
00194   h->Draw("COLZ");
00195 
00196   TGraph* gsect = getBoundary( ilmr, ME::iSector );
00197   assert( gsect!=0 );
00198   gsect->SetLineWidth( 1 );
00199   gsect->Draw("LSame");
00200   TGraph* gside = getBoundary( ilmr, ME::iLMRegion );
00201   assert( gside!=0 );
00202   gside->SetLineWidth( 2 );
00203   gside->Draw("LSame");
00204 }
00205 
00206 TH2*
00207 MEGeom::getGlobalHist( const char* name )
00208 {
00209   TH2* h = (TH2*)_h->Clone( name );
00210   h->Reset();
00211   return h;
00212 }
00213 
00214 void
00215 MEGeom::setBinGlobalHist( TH2* h, int ix, int iy, int iz, float val )
00216 {
00217   // make sure it's a global hist
00218   TAxis* ax = h->GetXaxis();
00219   TAxis* ay = h->GetYaxis();
00220   assert( ax->GetNbins()==_nbinx && ay->GetNbins()==_nbiny );
00221   assert( ax->GetXmax()==_xmax && ax->GetXmin()==_xmin );
00222   assert( ay->GetXmax()==_ymax && ay->GetXmin()==_ymin );
00223 
00224   int ibinx(0);
00225   int ibiny(0);
00226 
00227   if( iz==0 )
00228     {
00229       int ieta = ix;
00230       int iphi = iy;
00231       assert( abs(ieta)>=1 && abs(ieta)<=85 );
00232       assert( iphi>=1 && iphi<=360 );
00233       
00234       ibinx = ax->FindBin( ieta );
00235       ibiny = ay->FindBin( iphi );
00236     }
00237   else if( iz==-1 )
00238     {
00239       assert( ix>=1 && ix<=100 && iy>=1 && iy<=100 );
00240       ibinx = (_nbuf+100+1)-ix;
00241       ibiny = (_nbuf+180+50+1)-iy;
00242     }
00243   else if( iz==1  )
00244     {
00245       assert( ix>=1 && ix<=100 && iy>=1 && iy<=100 );
00246       ibinx = _nbinx+1-((_nbuf+100+1)-ix);
00247       ibiny = (_nbuf+180+50+1)-iy;
00248     }
00249   h->SetBinContent( ibinx, ibiny, val );
00250 }
00251 
00252 // fixme !!!
00253 void
00254 MEGeom::drawGlobalBoundaries( int lineColor )
00255 {
00256   TGraph* gr(0);
00257   for( int ism=1; ism<=36; ism++ )
00258     {
00259       gr = MEEBGeom::getGraphBoundary( MEEBGeom::iSuperModule, ism, true );
00260       gr->SetLineWidth( 2 );
00261       gr->SetLineColor( lineColor );
00262       gr->Draw("LSame");
00263     }
00264   for( int isec=1; isec<=9; isec++ )
00265     {
00266       gr = MEEEGeom::getGraphBoundary( MEEEGeom::iSector, isec );
00267       TGraph* grm = (TGraph*) gr->Clone();
00268       TGraph* grp = (TGraph*) gr->Clone();
00269       int n = gr->GetN();
00270       //      std::cout << std::endl;
00271       for( int ii=0; ii<n; ii++ )
00272         {
00273           double x_, y_;
00274           gr->GetPoint( ii, x_, y_ );
00275           //      std::cout << isec << " " << ii << " x=" << x_ << " y=" << y_ << std::endl;
00276 
00277           double xx_, yy_;
00278 
00279           xx_ = -85-x_;
00280           yy_ = 231-y_;
00281           //      std::cout << isec << " " << 0 << " x=" << xx_ << " y=" << yy_ << std::endl;
00282 
00283           grm->SetPoint( ii, xx_, yy_ );
00284 
00285           xx_ =  85+x_;
00286           yy_ =  231-y_;
00287           //      std::cout << isec << " " << 1 << " x=" << xx_ << " y=" << yy_ << std::endl;
00288           grp->SetPoint( ii, xx_, yy_ );
00289         }
00290       grm->SetLineColor( lineColor );
00291       grm->SetLineWidth( 2 );
00292       grm->Draw("LSame");
00293       grp->SetLineColor( lineColor );
00294       grp->SetLineWidth( 2 );
00295       grp->Draw("LSame");
00296     }
00297 }
00298