CMS 3D CMS Logo

DisplayManager.cc

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <fstream>
00003 #include <stdlib.h>
00004 
00005 #include "RecoParticleFlow/PFRootEvent/interface/IO.h"
00006 
00007 #include "DataFormats/ParticleFlowReco/interface/PFBlock.h"
00008 #include "RecoParticleFlow/PFBlockAlgo/interface/PFGeometry.h"
00009 #include "DataFormats/ParticleFlowReco/interface/PFBlockElement.h"
00010 #include "DataFormats/ParticleFlowReco/interface/PFClusterFwd.h"
00011 
00012 #include "DataFormats/Math/interface/Point3D.h"
00013 
00014 
00015 #include "RecoParticleFlow/PFRootEvent/interface/DisplayManager.h"
00016 #include "RecoParticleFlow/PFRootEvent/interface/GPFRecHit.h"
00017 #include "RecoParticleFlow/PFRootEvent/interface/GPFCluster.h"
00018 #include "RecoParticleFlow/PFRootEvent/interface/GPFTrack.h"
00019 #include "RecoParticleFlow/PFRootEvent/interface/GPFSimParticle.h"
00020 #include "RecoParticleFlow/PFRootEvent/interface/GPFGenParticle.h"
00021 #include "RecoParticleFlow/PFRootEvent/interface/GPFBase.h"
00022 
00023 #include <TTree.h>
00024 #include <TVector3.h>
00025 #include <TH2F.h>
00026 #include <TEllipse.h>
00027 #include "TLine.h"
00028 #include "TLatex.h"
00029 #include "TList.h"
00030 #include "TColor.h"
00031 #include <TMath.h>
00032 #include <TApplication.h>
00033 
00034 using namespace std;
00035 
00036 //________________________________________________________________
00037 
00038 DisplayManager::DisplayManager(PFRootEventManager *em,
00039                                const char* optfile ) : 
00040   em_(em), 
00041   options_(0),
00042   maxERecHitEcal_(-1),
00043   maxERecHitHcal_(-1),
00044   isGraphicLoaded_(false),
00045   shiftId_(27) {
00046         
00047   readOptions( optfile );
00048         
00049   eventNumber_  = em_->eventNumber();
00050   //TODOLIST: re_initialize if new option file- better in em
00051   maxEvents_= em_->tree_->GetEntries();  
00052         
00053   createCanvas();
00054 }
00055 //________________________________________________________
00056 DisplayManager::~DisplayManager()
00057 {
00058   reset();
00059 } 
00060 
00061 //________________________________________________________
00062 void DisplayManager::readOptions( const char* optfile ) {
00063         
00064   try {
00065     delete options_;
00066     options_ = new IO(optfile);
00067   }
00068   catch( const string& err ) {
00069     cout<<err<<endl;
00070     return;
00071   }
00072         
00073   viewSizeEtaPhi_.clear();
00074   options_->GetOpt("display", "viewsize_etaphi", viewSizeEtaPhi_);
00075   if(viewSizeEtaPhi_.size() != 2) {
00076     cerr<<"PFRootEventManager::ReadOptions, bad display/viewsize_etaphi tag...using 700/350"
00077         <<endl;
00078     viewSizeEtaPhi_.clear();
00079     viewSizeEtaPhi_.push_back(700); 
00080     viewSizeEtaPhi_.push_back(350); 
00081   }
00082         
00083   viewSize_.clear();
00084   options_->GetOpt("display", "viewsize_xy", viewSize_);
00085   if(viewSize_.size() != 2) {
00086     cerr<<"PFRootEventManager::ReadOptions, bad display/viewsize_xy tag...using 700/350"
00087         <<endl;
00088     viewSize_.clear();
00089     viewSize_.push_back(600); 
00090     viewSize_.push_back(600); 
00091   } 
00092         
00093   clusterAttributes_.clear();
00094   options_->GetOpt("display", "cluster_attributes", clusterAttributes_);
00095   if(clusterAttributes_.size() != 4) {
00096     cerr<<"PFRootEventManager::::ReadOptions, bad display/cluster_attributes tag...using 20 10 2 5"
00097         <<endl;
00098     clusterAttributes_.clear();
00099     clusterAttributes_.push_back(2); //color
00100     clusterAttributes_.push_back(5);  // color if clusterPS
00101     clusterAttributes_.push_back(20); // marker style
00102     clusterAttributes_.push_back(10); //markersize *10
00103   }
00104   trackAttributes_.clear();
00105   options_->GetOpt("display", "track_attributes", trackAttributes_);
00106   if(trackAttributes_.size() != 4) {
00107     cerr<<"PFRootEventManager::::ReadOptions, bad display/track_attributes tag...using 103 1 8 8"
00108         <<endl;
00109     trackAttributes_.clear();
00110     trackAttributes_.push_back(103); //color Line and Marker
00111     trackAttributes_.push_back(1);  //line style
00112     trackAttributes_.push_back(8);   //Marker style
00113     trackAttributes_.push_back(8);   //Marker size *10
00114   }
00115         
00116         
00117   clusPattern_ = new TAttMarker(clusterAttributes_[0],clusterAttributes_[2],(double)clusterAttributes_[3]/10);
00118   clusPSPattern_ = new TAttMarker(clusterAttributes_[1],clusterAttributes_[2],(double)clusterAttributes_[3]/10);
00119   trackPatternL_ = new TAttLine(trackAttributes_[0],trackAttributes_[1],1);
00120   trackPatternM_ = new TAttMarker(trackAttributes_[0],trackAttributes_[2],(double)trackAttributes_[3]/10);
00121   
00122   genPartPattern_= new TAttMarker(kGreen-1,22,1.);
00123   
00124   simPartPatternPhoton_ = new TAttMarker(4,3,.8);
00125   simPartPatternElec_   = new TAttMarker(4,5,.8);
00126   simPartPatternMuon_   = new TAttMarker(4,2,.8);
00127   simPartPatternK_      = new TAttMarker(4,24,.8);
00128   simPartPatternPi_     = new TAttMarker(4,25,.8);
00129   simPartPatternProton_ = new TAttMarker(4,26,.8);
00130   simPartPatternNeutron_= new TAttMarker(4,27,.8);
00131   simPartPatternDefault_= new TAttMarker(4,30,.8);
00132         
00133   simPartPatternL_ = new TAttLine(4,2,1);
00134   simPartPatternM_.resize(8);
00135         
00136   setNewAttrToSimParticles();
00137         
00138   drawHits_= true;
00139   options_->GetOpt("display", "rechits",drawHits_);
00140         
00141   drawClus_ = true;
00142   options_->GetOpt("display", "clusters",drawClus_);
00143         
00144   drawClusterL_ = false;
00145   options_->GetOpt("display", "cluster_lines", drawClusterL_);
00146         
00147   drawTracks_ = true;
00148   options_->GetOpt("display", "rectracks", drawTracks_);
00149         
00150   drawParticles_ = true;
00151   options_->GetOpt("display", "particles", drawParticles_);
00152         
00153   particlePtMin_ = -1;
00154   options_->GetOpt("display", "particles_ptmin", particlePtMin_);
00155   
00156   
00157   drawGenParticles_=false;
00158   genParticlePtMin_ = 0;
00159   
00160   
00161   trackPtMin_ = -1;
00162   options_->GetOpt("display", "rectracks_ptmin", trackPtMin_);
00163         
00164   hitEnMin_ = -1;
00165   options_->GetOpt("display","rechits_enmin",hitEnMin_);
00166         
00167   clusEnMin_ = -1;
00168   options_->GetOpt("display","clusters_enmin",clusEnMin_);
00169         
00170         
00171   drawPFBlocks_  = false;
00172   options_->GetOpt("display","drawPFBlock",drawPFBlocks_);
00173   //redrawWithoutHits_=false;
00174         
00175   zoomFactor_ = 10;  
00176   options_->GetOpt("display", "zoom_factor", zoomFactor_);
00177         
00178 }
00179 
00180 //________________________________________________________
00181 void DisplayManager::createCanvas()
00182 {
00183         
00184   //TODOLIST: better TCanvas *displayView_[4]
00185   displayView_.resize(NViews);
00186   displayHist_.resize(NViews);
00187         
00188   // TODOLIST:Canvases size  
00189   // Add menu to mofify canvas size
00190   // Add menu of views to be drawn
00191         
00192         
00193   displayView_[XY] = new TCanvas("displayXY_", "XY view",viewSize_[0], viewSize_[1]);
00194   displayView_[RZ] = new TCanvas("displayRZ_", "RZ view",viewSize_[0], viewSize_[1]);
00195   displayView_[EPE] = new TCanvas("displayEPE_", "eta/phi view, ECAL",viewSize_[0], viewSize_[1]);
00196   displayView_[EPH] = new TCanvas("displayEPH_", "eta/phi view, HCAL",viewSize_[0], viewSize_[1]);
00197         
00198         
00199   for (int viewType=0;viewType<NViews;++viewType) {
00200     displayView_[viewType]->SetGrid(0, 0);
00201     displayView_[viewType]->SetLeftMargin(0.12);
00202     displayView_[viewType]->SetBottomMargin(0.12);
00203     displayView_[viewType]->ToggleToolBar();
00204   } 
00205     
00206   // Draw support histogram
00207   double zLow = -500.;
00208   double zUp  = +500.;
00209   double rLow = -300.;
00210   double rUp  = +300.;
00211   displayHist_[XY] = new TH2F("hdisplayHist_XY", "", 500, rLow, rUp, 
00212                               500, rLow, rUp);
00213   displayHist_[XY]->SetXTitle("X");
00214   displayHist_[XY]->SetYTitle("Y");
00215         
00216   displayHist_[RZ] = new TH2F("hdisplayHist_RZ", "",500, zLow, zUp, 
00217                               500, rLow, rUp); 
00218   displayHist_[RZ]->SetXTitle("Z");
00219   displayHist_[RZ]->SetYTitle("R");
00220         
00221   displayHist_[EPE] = new TH2F("hdisplayHist_EP", "", 500, -5, 5, 
00222                                500, -3.5, 3.5);
00223   displayHist_[EPE]->SetXTitle("#eta");
00224   displayHist_[EPE]->SetYTitle("#phi");
00225         
00226   displayHist_[EPH] = displayHist_[EPE];
00227         
00228   for (int viewType=0;viewType<NViews;++viewType){
00229     displayHist_[viewType]->SetStats(kFALSE);
00230   }  
00231         
00232   // Draw ECAL front face
00233   frontFaceECALXY_.SetX1(0);
00234   frontFaceECALXY_.SetY1(0);
00235   frontFaceECALXY_.SetR1(PFGeometry::innerRadius(PFGeometry::ECALBarrel));
00236   frontFaceECALXY_.SetR2(PFGeometry::innerRadius(PFGeometry::ECALBarrel));
00237   frontFaceECALXY_.SetFillStyle(0);
00238         
00239   // Draw HCAL front face
00240   frontFaceHCALXY_.SetX1(0);
00241   frontFaceHCALXY_.SetY1(0);
00242   frontFaceHCALXY_.SetR1(PFGeometry::innerRadius(PFGeometry::HCALBarrel));
00243   frontFaceHCALXY_.SetR2(PFGeometry::innerRadius(PFGeometry::HCALBarrel));
00244   frontFaceHCALXY_.SetFillStyle(0);
00245         
00246   // Draw ECAL side
00247   frontFaceECALRZ_.SetX1(-1.*PFGeometry::innerZ(PFGeometry::ECALEndcap));
00248   frontFaceECALRZ_.SetY1(-1.*PFGeometry::innerRadius(PFGeometry::ECALBarrel));
00249   frontFaceECALRZ_.SetX2(PFGeometry::innerZ(PFGeometry::ECALEndcap));
00250   frontFaceECALRZ_.SetY2(PFGeometry::innerRadius(PFGeometry::ECALBarrel));
00251   frontFaceECALRZ_.SetFillStyle(0);
00252         
00253 }
00254 //_________________________________________________________________________
00255 void DisplayManager::createGCluster(const reco::PFCluster& cluster, 
00256                                     int ident, 
00257                                     double phi0)
00258 {
00259 
00260   double eta = cluster.position().Eta();
00261   double phi = cluster.position().Phi();
00262   
00263   //   int type = cluster.type();
00264   //   if(algosToDisplay_.find(type) == algosToDisplay_.end() )
00265   //     return;
00266         
00267   //   TCutG* cutg = (TCutG*) gROOT->FindObject("CUTG");  
00268   //   if( cutg && !cutg->IsInside( eta, phi ) ) return;
00269         
00270         
00271   //int color = clusterAttributes_[2];
00272   //if ( cluster.layer()==PFLayer::PS1 || cluster.layer()==PFLayer::PS2 )
00273   //  color = clusterAttributes_[3];
00274     
00275   //int markerSize = clusterAttributes_[1];
00276   //int markerStyle = clusterAttributes_[0];
00277         
00278   int clusType=0;
00279         
00280   if ( cluster.layer()==PFLayer::PS1 || cluster.layer()==PFLayer::PS2 )
00281     clusType=1;  
00282 
00283   const math::XYZPoint& xyzPos = cluster.position();
00284 
00285   GPFCluster *gc;
00286         
00287   for (int viewType=0;viewType<4;viewType++){
00288                 
00289     switch(viewType) {
00290     case XY:
00291       {
00292         if (clusType==0) {
00293           gc = new  GPFCluster(this,
00294                                viewType,ident,
00295                                &cluster,
00296                                xyzPos.X(), xyzPos.Y(), clusPattern_);
00297         }
00298         else {
00299           gc = new  GPFCluster(this,
00300                                viewType,ident,
00301                                &cluster,
00302                                xyzPos.X(), xyzPos.Y(), clusPSPattern_);
00303         }                                     
00304         graphicMap_.insert(pair<int,GPFBase *> (ident, gc));
00305       }
00306       break;
00307     case RZ:
00308       {
00309         double sign = 1.;
00310         if (cos(phi0 - phi) < 0.)
00311           sign = -1.;
00312         if ( clusType==0) { 
00313           gc = new  GPFCluster(this,
00314                                viewType,ident,
00315                                &cluster,
00316                                xyzPos.z(),sign*xyzPos.Rho(),
00317                                clusPattern_);
00318         }
00319         else {
00320           gc = new  GPFCluster(this,
00321                                viewType,ident,
00322                                &cluster,
00323                                xyzPos.z(),sign*xyzPos.Rho(),
00324                                clusPattern_);
00325         }
00326                                          
00327         graphicMap_.insert(pair<int,GPFBase *>  (ident, gc));                    
00328 
00329       } 
00330       break;
00331     case EPE:
00332       {
00333         if( cluster.layer()<0 ) {
00334           if (clusType==0) {
00335             gc = new  GPFCluster(this,
00336                                  viewType,ident,
00337                                  &cluster,
00338                                  eta,phi,
00339                                  clusPattern_);
00340           }
00341           else {
00342             gc = new  GPFCluster(this,
00343                                  viewType,ident,
00344                                  &cluster,
00345                                  eta,phi,
00346                                  clusPSPattern_);
00347           }                              
00348                                          
00349           graphicMap_.insert(pair<int,GPFBase *>        (ident, gc));                    
00350         }
00351 
00352       } 
00353       break;
00354     case EPH:
00355       {
00356         if( cluster.layer()>0 ) {
00357           if (clusType==0) {
00358             gc = new  GPFCluster(this,
00359                                  viewType,ident,
00360                                  &cluster,
00361                                  eta,phi,clusPattern_);
00362           }
00363           else {
00364             gc = new  GPFCluster(this,
00365                                  viewType,ident,
00366                                  &cluster,
00367                                  eta,phi,clusPSPattern_);
00368           }
00369             
00370                                          
00371           graphicMap_.insert(pair<int,GPFBase *>        (ident, gc));          
00372         }
00373       } 
00374       break;
00375     default :break; 
00376     } 
00377   }      
00378 }
00379 //________________________________________________________________________________________
00380 void DisplayManager::createGPart( const reco::PFSimParticle &ptc,
00381                                   const std::vector<reco::PFTrajectoryPoint>& points, 
00382                                   int ident,double pt,double phi0, double sign, bool displayInitial,
00383                                   int markerIndex)
00384 {
00385   //bool inside = false; 
00386   //TCutG* cutg = (TCutG*) gROOT->FindObject("CUTG");
00387   bool debug_createGpart = false;
00388   //    bool debug_createGpart = true;
00389   for (int viewType=0;viewType<4;++viewType) {
00390     // reserving space. nb not all trajectory points are valid
00391     vector<double> xPos;
00392     xPos.reserve( points.size() );
00393     vector<double> yPos;
00394     yPos.reserve( points.size() );
00395                 
00396     for(unsigned i=0; i<points.size(); i++) {
00397 
00398       if( !points[i].isValid() ) continue;
00399         
00400       const math::XYZPoint& xyzPos = points[i].position();      
00401 
00402       double eta = xyzPos.Eta();
00403       double phi = xyzPos.Phi();
00404                         
00405       // always take momentum for the first point 
00406       // otherwise decay products from resonances will have wrong eta, phi
00407       //calculated from position (0,0,0) (MDN 11 June 2008)
00408       if( points[i].layer() == reco::PFTrajectoryPoint::ClosestApproach ) {
00409                                 
00410         //      if( !displayInitial && 
00411         //              points[i].layer() == reco::PFTrajectoryPoint::ClosestApproach ) {
00412         const math::XYZTLorentzVector& mom = points[i].momentum();
00413         eta = mom.Eta();
00414         phi = mom.Phi();
00415       }
00416                         
00417       //if( !cutg || cutg->IsInside( eta, phi ) ) 
00418       //  inside = true;
00419                         
00420       switch(viewType) {
00421       case XY:
00422         xPos.push_back(xyzPos.X());
00423         yPos.push_back(xyzPos.Y());
00424         break;
00425       case RZ:
00426         xPos.push_back(xyzPos.Z());
00427         yPos.push_back(sign*xyzPos.Rho());
00428         break;
00429       case EPE:
00430       case EPH:
00431         xPos.push_back( eta );
00432         yPos.push_back( phi );
00433         break;
00434       default:break;
00435       }
00436     }  
00437     if (viewType == EPE && debug_createGpart) {
00438       cout << " display PFsim eta/phi view ECAL" << endl;
00439       cout << " nb of points for display " << xPos.size() << endl;
00440       for(unsigned i=0; i<xPos.size(); i++) {
00441         cout << " point " << i << " x/y " << xPos[i] <<"/" << yPos[i]<< endl;
00442       }
00443     }
00444                 
00446     //if( !inside ) return;
00447     //int color = 4;
00448     GPFSimParticle *gc   = new GPFSimParticle(this,
00449                                               viewType, ident,
00450                                               &ptc,
00451                                               xPos.size(),&xPos[0],&yPos[0],
00452                                               pt,
00453                                               simPartPatternM_[markerIndex],
00454                                               simPartPatternL_,
00455                                               "pl");
00456                                               
00457     graphicMap_.insert(pair<int,GPFBase *>      (ident, gc));                                 
00458     //graphicMap_.insert(pair<int,GPFBase *> (ident,new GPFSimParticle(this,viewType,ident,&ptc,xPos.size(),&xPos[0],&yPos[0],pt,simPartPattern_[indexMarker], "pl")));
00459   }
00460 }
00461 //____________________________________________________________________
00462 void DisplayManager::createGRecHit(reco::PFRecHit& rh,int ident, double maxe, double phi0, int color)
00463 {
00464         
00465   double me = maxe;
00466   double thresh = 0;
00467   int layer = rh.layer();
00468         
00469         
00470   switch(layer) {
00471   case PFLayer::ECAL_BARREL:
00472     thresh = em_->clusterAlgoECAL_.threshBarrel();
00473     break;     
00474   case PFLayer::ECAL_ENDCAP:
00475     thresh = em_->clusterAlgoECAL_.threshEndcap();
00476     break;     
00477   case PFLayer::HCAL_BARREL1:
00478   case PFLayer::HCAL_BARREL2:
00479     thresh = em_->clusterAlgoHCAL_.threshBarrel();
00480     break;           
00481   case PFLayer::HCAL_ENDCAP:
00482     thresh = em_->clusterAlgoHCAL_.threshEndcap();
00483     break;           
00484   case PFLayer::HCAL_HF: 
00485     // how to handle a different threshold for HF?
00486     thresh = em_->clusterAlgoHCAL_.threshEndcap();
00487     break;           
00488   case PFLayer::PS1:
00489   case PFLayer::PS2:
00490     me = -1;
00491     thresh = em_->clusterAlgoPS_.threshBarrel();
00492     break;
00493   default:
00494     {
00495       cerr<<"DisplayManager::createGRecHit : manage other layers."
00496           <<" GRechit notcreated."<<endl;
00497       return;
00498     }
00499   }
00500   if( rh.energy() < thresh ) return;
00501         
00502   //loop on all views
00503   for(int viewType=0;viewType<4;++viewType) {
00504   
00505     bool isHCAL = (layer == PFLayer::HCAL_BARREL1 || 
00506                    layer == PFLayer::HCAL_BARREL2 || 
00507                    layer == PFLayer::HCAL_ENDCAP || 
00508                    layer == PFLayer::HCAL_HF);
00509     
00510     if(  viewType == EPH && 
00511          ! isHCAL) {
00512       continue;
00513     }
00514     // on EPE view, draw only HCAL and preshower
00515     if(  viewType == EPE && isHCAL ) {
00516       continue;
00517     }
00518     double rheta = rh.position().Eta();
00519     double rhphi = rh.position().Phi();
00520 
00521     double sign = 1.;
00522     if (cos(phi0 - rhphi) < 0.) sign = -1.;
00523                 
00524                 
00525     double etaSize[4];
00526     double phiSize[4];
00527     double x[5];
00528     double y[5];
00529     double z[5];
00530     double r[5];
00531     double eta[5];
00532     double phi[5];
00533     double xprop[5];
00534     double yprop[5];
00535     double etaprop[5];
00536     double phiprop[5];
00537                 
00538                 
00539     const std::vector< math::XYZPoint >& corners = rh.getCornersXYZ();
00540     assert(corners.size() == 4);
00541     double propfact = 0.95; // so that the cells don't overlap ? 
00542     double ampl=0;
00543     if(me>0) ampl = (log(rh.energy() + 1.)/log(me + 1.));
00544     for ( unsigned jc=0; jc<4; ++jc ) { 
00545 
00546       phiSize[jc] = rhphi-corners[jc].Phi();
00547       etaSize[jc] = rheta-corners[jc].Eta();
00548       if ( phiSize[jc] > 1. ) phiSize[jc] -= 2.*TMath::Pi();  
00549       if ( phiSize[jc] < -1. ) phiSize[jc]+= 2.*TMath::Pi();
00550 
00551       phiSize[jc] *= propfact;
00552       etaSize[jc] *= propfact;
00553                         
00554       math::XYZPoint cornerposxyz = corners[jc];
00555                         
00556       x[jc] = cornerposxyz.X();
00557       y[jc] = cornerposxyz.Y();
00558       z[jc] = cornerposxyz.Z();
00559       r[jc] = sign*cornerposxyz.Rho();
00560       eta[jc] = rheta - etaSize[jc];
00561       phi[jc] = rhphi - phiSize[jc];
00562                         
00563                         
00564       // cell area is prop to log(E)
00565       // not drawn for preshower. 
00566       // otherwise, drawn for eta/phi view, and for endcaps in xy view
00567       if( layer != PFLayer::PS1 && 
00568           layer != PFLayer::PS2 && 
00569           ( viewType == EPE || 
00570             viewType == EPH || 
00571             ( viewType == XY &&  
00572               ( layer == PFLayer::ECAL_ENDCAP || 
00573                 layer == PFLayer::HCAL_ENDCAP || 
00574                 layer == PFLayer::HCAL_HF
00575                 ) ) ) ) {
00576       
00577       
00578         math::XYZPoint centreXYZrot = rh.position();
00579 
00580         math::XYZPoint centertocorner(x[jc] - centreXYZrot.X(), 
00581                                       y[jc] - centreXYZrot.Y(),
00582                                       0 );
00583                                 
00584         math::XYZPoint centertocornerep(eta[jc] - centreXYZrot.Eta(), 
00585                                         phi[jc] - centreXYZrot.Phi(),
00586                                         0 );
00587                                 
00588                                 
00589         // centertocorner -= centreXYZrot;
00590         xprop[jc] = centreXYZrot.X() + centertocorner.X()*ampl;
00591         yprop[jc] = centreXYZrot.Y() + centertocorner.Y()*ampl;
00592                                 
00593         etaprop[jc] = centreXYZrot.Eta() + centertocornerep.X()*ampl;
00594         phiprop[jc] = centreXYZrot.Phi() + centertocornerep.Y()*ampl;
00595       }
00596     }//loop on jc 
00597                 
00598     if(layer == PFLayer::ECAL_BARREL  || 
00599        layer == PFLayer::HCAL_BARREL1 || 
00600        layer == PFLayer::HCAL_BARREL2 || viewType == RZ) {
00601                         
00602       // we are in the barrel. Determining which corners to shift 
00603       // away from the center to represent the cell energy
00604                         
00605       int i1 = -1;
00606       int i2 = -1;
00607                         
00608       if(fabs(phiSize[1]-phiSize[0]) > 0.0001) {
00609         if (viewType == XY) {
00610           i1 = 2;
00611           i2 = 3;
00612         } else if (viewType == RZ) {
00613           i1 = 1;
00614           i2 = 2;
00615         }
00616       } else {
00617         if (viewType == XY) {
00618           i1 = 1;
00619           i2 = 2;
00620         } else if (viewType == RZ) {
00621           i1 = 2;
00622           i2 = 3;
00623         }
00624       }
00625                         
00626       x[i1] *= 1+ampl/2.;
00627       x[i2] *= 1+ampl/2.;
00628       y[i1] *= 1+ampl/2.;
00629       y[i2] *= 1+ampl/2.;
00630       z[i1] *= 1+ampl/2.;
00631       z[i2] *= 1+ampl/2.;
00632       r[i1] *= 1+ampl/2.;
00633       r[i2] *= 1+ampl/2.;
00634     }
00635     x[4]=x[0];
00636     y[4]=y[0]; // closing the polycell
00637     z[4]=z[0];
00638     r[4]=r[0]; // closing the polycell
00639     eta[4]=eta[0];
00640     phi[4]=phi[0]; // closing the polycell
00641                 
00642     int npoints=5;
00643                 
00644     switch( viewType ) {
00645     case  XY:
00646       {
00647         if(layer == PFLayer::ECAL_BARREL || 
00648            layer == PFLayer::HCAL_BARREL1 || 
00649            layer == PFLayer::HCAL_BARREL2) {
00650           graphicMap_.insert(pair<int,GPFBase *> (ident,new GPFRecHit(this, viewType,ident,&rh,npoints,x,y,color,"f")));
00651                                         
00652         } else {
00653           graphicMap_.insert(pair<int,GPFBase *> (ident,new GPFRecHit(this, viewType,ident,&rh,npoints,x,y,color,"l")));
00654           if( ampl>0 ) { // not for preshower
00655             xprop[4]=xprop[0];
00656             yprop[4]=yprop[0]; // closing the polycell    
00657             graphicMap_.insert(pair<int,GPFBase *> (ident,new GPFRecHit(this, viewType,ident,&rh,npoints,xprop,yprop,color,"f")));
00658           }
00659         }
00660       } 
00661       break;
00662                                 
00663     case RZ:
00664       graphicMap_.insert(pair<int,GPFBase *> (ident,new GPFRecHit(this, viewType,ident,&rh,npoints,z,r,color,"f")));
00665       break;
00666                                 
00667     case EPE:
00668       {
00669         graphicMap_.insert(pair<int,GPFBase *> (ident,new GPFRecHit(this, viewType,ident,&rh,npoints,eta,phi,color,"l")));
00670                                 
00671         if( ampl>0 ) { // not for preshower
00672           etaprop[4]=etaprop[0];
00673           phiprop[4]=phiprop[0]; // closing the polycell    
00674           graphicMap_.insert(pair<int,GPFBase *> (ident,new GPFRecHit(this, viewType,ident,&rh,npoints,etaprop,phiprop,color,"f")));
00675         }
00676       }  
00677       break;
00678     case EPH:
00679       {      
00680         graphicMap_.insert(pair<int,GPFBase *> (ident,new GPFRecHit(this, viewType,ident,&rh,npoints,eta,phi,color,"l")));
00681                                 
00682         if( ampl>0 ) { // not for preshower
00683           etaprop[4]=etaprop[0];
00684           phiprop[4]=phiprop[0]; // closing the polycell    
00685           graphicMap_.insert(pair<int,GPFBase *> (ident,new GPFRecHit(this, viewType,ident,&rh,npoints,etaprop,phiprop,color,"f")));
00686         }
00687       } 
00688       break;
00689                                 
00690     default: break;
00691     }//switch end
00692                 
00693   } //loop on views
00694 }
00695 
00696 //_________________________________________________________________________________________
00697 void DisplayManager::createGTrack( reco::PFRecTrack &tr,
00698                                    const std::vector<reco::PFTrajectoryPoint>& points, 
00699                                    int ident,double pt,double phi0, double sign, bool displayInitial,
00700                                    int linestyle) 
00701 {
00702         
00703   //   bool inside = false; 
00704   //TCutG* cutg = (TCutG*) gROOT->FindObject("CUTG");
00705         
00706   for (int viewType=0;viewType<4;++viewType) {
00707     // reserving space. nb not all trajectory points are valid
00708     vector<double> xPos;
00709     xPos.reserve( points.size() );
00710     vector<double> yPos;
00711     yPos.reserve( points.size() );
00712                 
00713     for(unsigned i=0; i<points.size(); i++) {
00714       if( !points[i].isValid() ) continue;
00715       
00716       const math::XYZPoint& xyzPos = points[i].position();      
00717 
00718       double eta = xyzPos.Eta();
00719       double phi = xyzPos.Phi();
00720                         
00721       if( !displayInitial && 
00722           points[i].layer() == reco::PFTrajectoryPoint::ClosestApproach ) {
00723         const math::XYZTLorentzVector& mom = points[i].momentum();
00724         eta = mom.Eta();
00725         phi = mom.Phi();
00726       }
00727                         
00728       //if( !cutg || cutg->IsInside( eta, phi ) ) 
00729       //  inside = true;
00730                         
00731                         
00732       switch(viewType) {
00733       case XY:
00734         xPos.push_back(xyzPos.X());
00735         yPos.push_back(xyzPos.Y());
00736         break;
00737       case RZ:
00738         xPos.push_back(xyzPos.Z());
00739         yPos.push_back(sign*xyzPos.Rho());
00740         break;
00741       case EPE:
00742       case EPH:
00743         xPos.push_back( eta );
00744         yPos.push_back( phi );
00745         break;
00746       }
00747     }  
00749     //if( !inside ) return;
00750                 
00751     //fill map with graphic objects
00752                 
00753     GPFTrack *gt = new  GPFTrack(this,
00754                                  viewType,ident,
00755                                  &tr,
00756                                  xPos.size(),&xPos[0],&yPos[0],pt,
00757                                  trackPatternM_,trackPatternL_,"pl");
00758     graphicMap_.insert(pair<int,GPFBase *> (ident, gt));
00759   }   
00760 }
00761 //________________________________________________________
00762 void DisplayManager::display(int ientry)
00763 {
00764   if (ientry<0 || ientry>maxEvents_) {
00765     std::cerr<<"DisplayManager::no event matching criteria"<<std::endl;
00766     return;
00767   }  
00768   reset();
00769   em_->processEntry(ientry);  
00770   eventNumber_= em_->eventNumber();
00771   loadGraphicObjects();
00772   isGraphicLoaded_= true;
00773   displayAll();
00774 }
00775 //________________________________________________________________________________
00776 void DisplayManager::displayAll(bool noRedraw)
00777 {
00778   if (!isGraphicLoaded_) {
00779     std::cout<<" no Graphic Objects to draw"<<std::endl;
00780     return;
00781   }
00782   if (noRedraw) { 
00783     for (int viewType=0;viewType<NViews;++viewType) {
00784       displayView_[viewType]->cd();
00785       gPad->Clear();
00786     } 
00787     //TODOLIST: add test on view to draw 
00788     displayCanvas();
00789   }  
00790         
00791   std::multimap<int,GPFBase *>::iterator p;
00792         
00793   for (p=graphicMap_.begin();p!=graphicMap_.end();p++) {
00794     int ident=p->first;
00795     int type=ident >> shiftId_;
00796     int view = p->second->getView();
00797     switch (type) {
00798     case CLUSTERECALID: case CLUSTERHCALID: case  CLUSTERPSID: case CLUSTERIBID:
00799       {
00800         if (drawClus_)
00801           if (p->second->getEnergy() > clusEnMin_) {
00802             displayView_[view]->cd();
00803             p->second->draw();
00804           }        
00805       }
00806       break;
00807     case RECHITECALID: case  RECHITHCALID: case RECHITPSID:
00808       {
00809         if (!noRedraw) break; 
00810         if (drawHits_) 
00811           if(p->second->getEnergy() > hitEnMin_)  {
00812             displayView_[view]->cd();
00813             p->second->draw();
00814           }
00815         break;  
00816       }  
00817     case RECTRACKID:
00818       {
00819         if (drawTracks_) 
00820           if (p->second->getPt() > trackPtMin_) {
00821             displayView_[view]->cd();
00822             p->second->draw();
00823           }
00824       }
00825       break;
00826     case SIMPARTICLEID:
00827       {
00828         if (drawParticles_)
00829           if (p->second->getPt() > particlePtMin_) {
00830             displayView_[view]->cd();
00831             p->second->draw();
00832           }
00833       }
00834       break;
00835     case GENPARTICLEID:
00836       {  
00837         if (drawGenParticles_) 
00838           if (p->second->getPt() > genParticlePtMin_) 
00839             if (view == EPH || view ==EPE) {
00840               displayView_[view]->cd();
00841               p->second->draw();
00842             }  
00843       } 
00844       break;           
00845     default : std::cout<<"DisplayManager::displayAll()-- unknown object "<<std::endl;               
00846     }  //switch end
00847   }   //for end
00848   for (int i=0;i<NViews;i++) {
00849     displayView_[i]->cd();
00850     gPad->Modified();
00851     displayView_[i]->Update();
00852   }  
00853 }
00854 //___________________________________________________________________________________
00855 void DisplayManager::drawWithNewGraphicAttributes()
00856 {
00857   std::multimap<int,GPFBase *>::iterator p;
00858         
00859   for (p=graphicMap_.begin();p!=graphicMap_.end();p++) {
00860     int ident=p->first;
00861     int type=ident >> shiftId_;
00862     switch (type) {
00863     case CLUSTERECALID: case CLUSTERHCALID: case  CLUSTERPSID: case CLUSTERIBID:
00864       {
00865         p->second->setNewStyle();
00866         p->second->setNewSize();
00867         p->second->setColor();  
00868       }
00869       break;
00870     case RECTRACKID:
00871       {
00872         p->second->setColor();
00873         p->second->setNewStyle();
00874         p->second->setNewSize();
00875       }
00876       break;
00877     case SIMPARTICLEID:
00878       {
00879       }
00880       break;
00881     default : break;            
00882     }  //switch end
00883   }   //for end
00884   displayAll(false);
00885 }
00886 //___________________________________________________________________________________
00887 void DisplayManager::displayCanvas()
00888 {
00889   double zLow = -500.;
00890   double zUp  = +500.;
00891   double rUp  = +300.;
00892         
00893   //TODOLIST : test wether view on/off
00894   //if (!displayView_[viewType] || !gROOT->GetListOfCanvases()->FindObject(displayView_[viewType]) ) {
00895   //   assert(viewSize_.size() == 2);
00896         
00897   for (int viewType=0;viewType<NViews;++viewType) {
00898     displayView_[viewType]->cd();
00899     displayHist_[viewType]->Draw();
00900     switch(viewType) {
00901     case XY: 
00902       frontFaceECALXY_.Draw();
00903       frontFaceHCALXY_.Draw();
00904       break;
00905     case RZ:    
00906       {// Draw lines at different etas
00907         TLine l;
00908         l.SetLineColor(1);
00909         l.SetLineStyle(3);
00910         TLatex etaLeg;
00911         etaLeg.SetTextSize(0.02);
00912         float etaMin = -3.;
00913         float etaMax = +3.;
00914         float etaBin = 0.2;
00915         int nEtas = int((etaMax - etaMin)/0.2) + 1;
00916         for (int iEta = 0; iEta <= nEtas; iEta++) {
00917           float eta = etaMin + iEta*etaBin;
00918           float r = 0.9*rUp;
00919           TVector3 etaImpact;
00920           etaImpact.SetPtEtaPhi(r, eta, 0.);
00921           etaLeg.SetTextAlign(21);
00922           if (eta <= -1.39) {
00923             etaImpact.SetXYZ(0.,0.85*zLow*tan(etaImpact.Theta()),0.85*zLow);
00924             etaLeg.SetTextAlign(31);
00925           } else if (eta >= 1.39) {
00926             etaImpact.SetXYZ(0.,0.85*zUp*tan(etaImpact.Theta()),0.85*zUp);
00927             etaLeg.SetTextAlign(11);
00928           }
00929           l.DrawLine(0., 0., etaImpact.Z(), etaImpact.Perp());
00930           etaLeg.DrawLatex(etaImpact.Z(), etaImpact.Perp(), Form("%2.1f", eta));
00931         }
00932         frontFaceECALRZ_.Draw();
00933       } 
00934       break;
00935     default: break;
00936     } //end switch
00937   }
00938 }
00939 //________________________________________________________________________________
00940 void DisplayManager::displayNext()
00941 {
00942   int eventNumber_=em_->eventNumber();
00943   display(++eventNumber_);
00944 }
00945 //_________________________________________________________________________________
00946 void DisplayManager::displayNextInteresting(int ientry)
00947 {
00948   bool ok=false;
00949   while (!ok && ientry<em_->tree_->GetEntries() ) {
00950     ok = em_->processEntry(ientry);
00951     ientry++;
00952   }
00953   eventNumber_ = em_->eventNumber();
00954   if (ok) {
00955     reset();
00956     loadGraphicObjects();
00957     isGraphicLoaded_= true;
00958     displayAll();
00959   }
00960   else 
00961     std::cerr<<"DisplayManager::dislayNextInteresting : no event matching criteria"<<std::endl;
00962 }
00963 //_________________________________________________________________________________
00964 void DisplayManager::displayPrevious()
00965 {
00966   int eventNumber_=em_->eventNumber();
00967   display(--eventNumber_);
00968 }
00969 //______________________________________________________________________________
00970 void DisplayManager::rubOutGPFBlock()
00971 {
00972   int size = selectedGObj_.size();
00973   bool toInitial=true;
00974   int color=0;
00975   for (int i=0;i<size;i++) 
00976     drawGObject(selectedGObj_[i],color,toInitial);
00977 }
00978 //_______________________________________________________________________________
00979 void DisplayManager::displayPFBlock(int blockNb) 
00980 {
00981   rubOutGPFBlock();
00982   selectedGObj_.clear();
00983   if (!drawPFBlocks_) return;
00984   int color=1;
00985   multimap<int,pair <int,int > >::const_iterator p;
00986   p= blockIdentsMap_.find(blockNb);
00987   if (p !=blockIdentsMap_.end()) {
00988     do {
00989       int ident=(p->second).first;
00990       drawGObject(ident,color,false);
00991       p++;
00992     } while (p!=blockIdentsMap_.upper_bound(blockNb));
00993   }
00994   else 
00995     cout<<"DisplayManager::displayPFBlock :not found"<<endl;    
00996 }  
00997 //_______________________________________________________________________________
00998 void DisplayManager::drawGObject(int ident,int color,bool toInitial) 
00999 {
01000   typedef std::multimap<int,GPFBase *>::const_iterator iter;
01001   iter p;
01002   std::pair<iter, iter > result = graphicMap_.equal_range(ident);
01003   if(result.first == graphicMap_.end()) {
01004     return;
01005   }
01006   p=result.first;
01007   while (p != result.second) {
01008     int view=p->second->getView();
01009     displayView_[view]->cd();
01010     if (toInitial) p->second->setInitialColor();
01011     else p->second->setColor(color);
01012     p->second->draw();
01013     gPad->Modified();
01014     //      displayView_[view]->Update();
01015     if (!toInitial) selectedGObj_.push_back(ident);
01016     p++; 
01017   }
01018 }
01019 //______________________________________________________________________________
01020 void DisplayManager::enableDrawPFBlock(bool state)
01021 {
01022   drawPFBlocks_=state;
01023 }  
01024 //_______________________________________________________________________________
01025 void DisplayManager::findAndDraw(int ident) 
01026 {
01027         
01028   int type=ident >> shiftId_;
01029   int color=1;
01030   if (type>8) {
01031     std ::cout<<"DisplayManager::findAndDraw :object Type unknown"<<std::endl;
01032     return;
01033   }  
01034   if (drawPFBlocks_==0  || type<3 || type==8) {
01035     rubOutGPFBlock();
01036     selectedGObj_.clear();
01037     bool toInitial=false;
01038     drawGObject(ident,color,toInitial);
01039     if (type<3) {
01040       //redrawWithoutHits_=true;
01041       displayAll(false);
01042       //redrawWithoutHits_=false;
01043     }
01044   }     
01045   updateDisplay();
01046 }
01047 //___________________________________________________________________________________
01048 void DisplayManager::findBlock(int ident) 
01049 {
01050   int blockNb=-1;
01051   int elemNb=-1;
01052   multimap<int, pair <int,int > >::const_iterator p;
01053   for (p=blockIdentsMap_.begin();p!=blockIdentsMap_.end();p++) {
01054     int id=(p->second).first;
01055     if (id == ident) {
01056       blockNb=p->first;
01057       elemNb=(p->second).second;
01058       break;
01059     }   
01060   }
01061   if (blockNb > -1) {
01062     std::cout<<"this object is element "<<elemNb<<" of PFblock nb "<<blockNb<<std::endl;
01063     assert( blockNb < static_cast<int>(em_->blocks().size()) );
01064     const reco::PFBlock& block = em_->blocks()[blockNb];
01065     std::cout<<block<<std::endl;
01066     displayPFBlock(blockNb);
01067   }   
01068   updateDisplay();
01069 }  
01070 //_________________________________________________________________________
01071 
01072 void DisplayManager::updateDisplay() {
01073   for(unsigned i=0; i<displayView_.size(); i++) {
01074     TPad* p =  displayView_[i];
01075     assert( p );
01076     p->Modified();
01077     p->Update();
01078   }
01079 }
01080 
01081 
01082 //_________________________________________________________________________
01083 double DisplayManager::getMaxE(int layer) const
01084 {
01085         
01086   double maxe = -9999;
01087         
01088   // in which vector should we look for these rechits ?
01089         
01090   const reco::PFRecHitCollection* vec = 0;
01091   switch(layer) {
01092   case PFLayer::ECAL_ENDCAP:
01093   case PFLayer::ECAL_BARREL:
01094     vec = &(em_->rechitsECAL_);
01095     break;
01096   case PFLayer::HCAL_ENDCAP:
01097   case PFLayer::HCAL_BARREL1:
01098   case PFLayer::HCAL_BARREL2:
01099   case PFLayer::HCAL_HF:
01100     vec = &(em_->rechitsHCAL_);
01101     break;
01102   case PFLayer::PS1:
01103   case PFLayer::PS2:
01104     vec = &(em_->rechitsPS_);
01105     break;
01106   default:
01107     cerr<<"DisplayManager::getMaxE : manage other layers"<<endl;
01108     return maxe;
01109   }
01110         
01111   for( unsigned i=0; i<vec->size(); i++) {
01112     if( (*vec)[i].layer() != layer ) continue;
01113     if( (*vec)[i].energy() > maxe)
01114       maxe = (*vec)[i].energy();
01115   }
01116         
01117   return maxe;
01118 }
01119 //____________________________________________________________________________
01120 double DisplayManager::getMaxEEcal() {
01121         
01122   if( maxERecHitEcal_<0 ) {
01123     double maxeec = getMaxE( PFLayer::ECAL_ENDCAP );
01124     double maxeb =  getMaxE( PFLayer::ECAL_BARREL );
01125     maxERecHitEcal_ = maxeec > maxeb ? maxeec:maxeb; 
01126     // max of both barrel and endcap
01127   }
01128   return  maxERecHitEcal_;
01129 }
01130 //_______________________________________________________________________________
01131 double DisplayManager::getMaxEHcal() {
01132         
01133   if(maxERecHitHcal_ < 0) {
01134     double maxehf = getMaxE( PFLayer::HCAL_HF );
01135     double maxeec = getMaxE( PFLayer::HCAL_ENDCAP );
01136     double maxeb =  getMaxE( PFLayer::HCAL_BARREL1 );
01137     maxERecHitHcal_ =  maxeec>maxeb  ?  maxeec:maxeb;
01138     maxERecHitHcal_ = maxERecHitHcal_>maxehf ? maxERecHitHcal_:maxehf;
01139   }
01140   return maxERecHitHcal_;
01141 } 
01142 //________________________________________________________________________________________________
01143 void DisplayManager::loadGGenParticles()
01144 {
01145   
01146   const HepMC::GenEvent* myGenEvent = em_->MCTruth_.GetEvent();
01147   if(!myGenEvent) return;
01148   for ( HepMC::GenEvent::particle_const_iterator piter  = myGenEvent->particles_begin();
01149         piter != myGenEvent->particles_end(); 
01150         ++piter ) {
01151     HepMC::GenParticle* p = *piter;
01152 
01153     createGGenParticle(p);
01154   } 
01155 }
01156 //____________________________________________________________________________
01157 void DisplayManager::createGGenParticle(HepMC::GenParticle* p)
01158 {
01159   // these are the beam protons
01160   if ( !p->production_vertex() && p->pdg_id() == 2212 ) return;
01161     
01162   int partId = p->pdg_id();
01163 
01164   std::string name;
01165   std::string latexStringName;
01166 
01167   name = em_->getGenParticleName(partId,latexStringName);
01168   int barcode = p->barcode();
01169   int genPartId=(GENPARTICLEID<<shiftId_) | barcode;
01170     
01171     
01172 //   int vertexId1 = 0;
01173 //   vertexId1 = p->production_vertex()->barcode();
01174     
01175 //   math::XYZVector vertex1 (p->production_vertex()->position().x()/10.,
01176 //                            p->production_vertex()->position().y()/10.,
01177 //                            p->production_vertex()->position().z()/10.);
01178                              
01179   math::XYZTLorentzVector momentum1(p->momentum().px(),
01180                                     p->momentum().py(),
01181                                     p->momentum().pz(),
01182                                     p->momentum().e());
01183                                       
01184   double eta = momentum1.eta();
01185   if ( eta > +10. ) eta = +10.;
01186   if ( eta < -10. ) eta = -10.;
01187     
01188   double phi = momentum1.phi();
01189     
01190   double pt = momentum1.pt();
01191   double e = momentum1.e();
01192     
01193   //mother ?    
01194 
01195   // Colin: the following line gives a segmentation fault when there is 
01196   // no particles entering the production vertex.
01197     
01198   // const HepMC::GenParticle* mother = 
01199   //  *(p->production_vertex()->particles_in_const_begin());
01200     
01201   // protecting against this in the following way:
01202   const HepMC::GenParticle* mother = 0;
01203   if(p->production_vertex() && 
01204      p->production_vertex()->particles_in_size() ) {
01205     mother = 
01206       *(p->production_vertex()->particles_in_const_begin()); 
01207   }
01208 
01209   // Colin: no need to declare this pointer in this context.
01210   // the declaration can be more local.
01211   // GPFGenParticle *gp; 
01212 
01213   if ( mother ) {
01214     int barcodeMother = mother->barcode();
01215     math::XYZTLorentzVector momentumMother(mother->momentum().px(),
01216                                            mother->momentum().py(),
01217                                            mother->momentum().pz(),
01218                                            mother->momentum().e());
01219     double etaMother = momentumMother.eta();                                  
01220     if ( etaMother > +10. ) etaMother = +10.;
01221     if ( etaMother < -10. ) etaMother = -10.;
01222     double phiMother = momentumMother.phi();
01223     
01224        
01225     double x[2],y[2];
01226     x[0]=etaMother;x[1]=eta;
01227     y[0]=phiMother;y[1]=phi;
01228        
01229     for (int view = 2; view< NViews; view++) {
01230       GPFGenParticle* gp   = new GPFGenParticle(this,             
01231                                                 view, genPartId,
01232                                                 x, y,              //double *, double *
01233                                                 e,pt,barcode,barcodeMother,
01234                                                 genPartPattern_, 
01235                                                 name,latexStringName);
01236       graphicMap_.insert(pair<int,GPFBase *>    (genPartId, gp));
01237     }
01238   }
01239   else {     //no Mother    
01240     for (int view = 2; view< NViews; view++) {
01241       GPFGenParticle* gp   = new GPFGenParticle(this,
01242                                                 view, genPartId,
01243                                                 eta, phi,                  //double double
01244                                                 e,pt,barcode,
01245                                                 genPartPattern_,
01246                                                 name, latexStringName);
01247       graphicMap_.insert(pair<int,GPFBase *>    (genPartId, gp));
01248     }                                         
01249   }
01250 }
01251 //____________________________________________________________________________  
01252 void DisplayManager::loadGClusters()
01253 {
01254   double phi0=0;
01255         
01256   for(unsigned i=0; i<em_->clustersECAL_->size(); i++){
01257     //int clusId=(i<<shiftId_) | CLUSTERECALID;
01258     int clusId=(CLUSTERECALID<<shiftId_) | i;
01259     createGCluster( (*(em_->clustersECAL_))[i],clusId, phi0);
01260   }    
01261   for(unsigned i=0; i<em_->clustersHCAL_->size(); i++) {
01262     //int clusId=(i<<shiftId_) | CLUSTERHCALID;
01263     int clusId=(CLUSTERHCALID<<shiftId_) | i;
01264     createGCluster( (*(em_->clustersHCAL_))[i],clusId, phi0);
01265   }    
01266   for(unsigned i=0; i<em_->clustersPS_->size(); i++){ 
01267     //int clusId=(i<<shiftId_) | CLUSTERPSID;
01268     int clusId=(CLUSTERPSID<<shiftId_) | i;
01269     createGCluster( (*(em_->clustersPS_))[i],clusId,phi0);
01270   }
01271   for(unsigned i=0; i<em_->clustersIslandBarrel_.size(); i++) {
01272     PFLayer::Layer layer = PFLayer::ECAL_BARREL;
01273     //int clusId=(i<<shiftId_) | CLUSTERIBID;
01274     int clusId=(CLUSTERIBID<<shiftId_) | i;
01275                 
01276     reco::PFCluster cluster( layer, 
01277                              em_->clustersIslandBarrel_[i].energy(),
01278                              em_->clustersIslandBarrel_[i].x(),
01279                              em_->clustersIslandBarrel_[i].y(),
01280                              em_->clustersIslandBarrel_[i].z() ); 
01281     createGCluster( cluster,clusId, phi0);
01282   }  
01283 }
01284 //_____________________________________________________________________
01285 void DisplayManager::loadGPFBlocks()
01286 {
01287   int size = em_->pfBlocks_->size();
01288   for (int ibl=0;ibl<size;ibl++) {
01289     //int elemNb=((*(em_->pfBlocks_))[ibl].elements()).size();
01290     //std::cout<<"block "<<ibl<<":"<<elemNb<<" elements"<<std::flush<<std::endl;
01291     edm::OwnVector< reco::PFBlockElement >::const_iterator iter;
01292     for( iter =((*(em_->pfBlocks_))[ibl].elements()).begin();
01293          iter != ((*(em_->pfBlocks_))[ibl].elements()).end();iter++) {
01294 
01295       //COLIN
01296 //       std::cout<<"elem index "<<(*iter).index()<<"-type:"
01297 //            <<(*iter).type()<<std::flush<<std::endl;
01298       int ident=-1;  
01299        
01300       reco::PFBlockElement::Type type = (*iter).type();
01301       switch (type) {
01302       case reco::PFBlockElement::NONE :
01303         assert(0);
01304         break;
01305       case reco::PFBlockElement::TRACK:
01306         {
01307           reco::PFRecTrackRef trackref =(*iter).trackRefPF();  
01308           assert( !trackref.isNull() );
01309           // std::cout<<" - key "<<trackref.key()<<std::flush<<std::endl<<std::endl;
01310           ident=(RECTRACKID <<shiftId_) | trackref.key();
01311         }
01312       break;
01313       case reco::PFBlockElement::PS1:
01314         {
01315           reco::PFClusterRef clusref=(*iter).clusterRef();
01316           assert( !clusref.isNull() );
01317           //std::cout<<"- key "<<clusref.key()<<std::flush<<std::endl<<std::endl;
01318           ident=(CLUSTERPSID <<shiftId_) |clusref.key();
01319         }
01320       break;
01321       case reco::PFBlockElement::PS2:
01322         {
01323           reco::PFClusterRef clusref=(*iter).clusterRef();
01324           assert( !clusref.isNull() );
01325           //std::cout<<"key "<<clusref.key()<<std::flush<<std::endl<<std::endl;
01326           ident=(CLUSTERPSID <<shiftId_) |clusref.key();
01327         }
01328       break;
01329       case reco::PFBlockElement::ECAL:
01330         {
01331           reco::PFClusterRef clusref=(*iter).clusterRef();
01332           assert( !clusref.isNull() );
01333           //std::cout<<"key "<<clusref.key()<<std::flush<<std::endl<<std::endl;
01334           ident=(CLUSTERECALID <<shiftId_) |clusref.key();
01335         }
01336       break;
01337       case reco::PFBlockElement::HCAL:
01338         {
01339           reco::PFClusterRef clusref=(*iter).clusterRef();
01340           assert( !clusref.isNull() );
01341           //std::cout<<"key "<<clusref.key()<<std::flush<<std::endl<<std::endl;
01342           ident=(CLUSTERHCALID <<shiftId_) |clusref.key();
01343         }
01344       break;
01345       default: 
01346         std::cout<<"unknown PFBlock element of type "<<type<<std::endl;
01347         break; 
01348       } //end switch 
01349       pair <int, int> idElem;
01350       idElem.first=ident;
01351       idElem.second=(*iter).index();
01352       if (ident != -1) blockIdentsMap_.insert(pair<int,pair <int,int> > (ibl,idElem));            
01353     }   //end for elements
01354   }   //end for blocks
01355         
01356 }
01357 //__________________________________________________________________________________
01358 void DisplayManager::loadGraphicObjects()
01359 {
01360   loadGClusters();
01361   loadGRecHits();
01362   loadGRecTracks();
01363   loadGSimParticles();
01364   loadGPFBlocks();
01365   loadGGenParticles();
01366 }
01367 //________________________________________________________
01368 void DisplayManager::loadGRecHits()
01369 {
01370   double phi0=0;
01371         
01372   double maxee = getMaxEEcal();
01373   double maxeh = getMaxEHcal();
01374   double maxe = maxee>maxeh ? maxee : maxeh;
01375         
01376   int color = TColor::GetColor(210,210,210);
01377   int seedcolor = TColor::GetColor(145,145,145);
01378   int specialcolor = TColor::GetColor(255,140,0);
01379         
01380   for(unsigned i=0; i<em_->rechitsECAL_.size(); i++) { 
01381     int rhcolor = color;
01382     if( unsigned col = em_->clusterAlgoECAL_.color(i) ) {
01383       switch(col) {
01384       case PFClusterAlgo::SEED: rhcolor = seedcolor; break;
01385       case PFClusterAlgo::SPECIAL: rhcolor = specialcolor; break;
01386       default:
01387         cerr<<"DisplayManager::loadGRecHits: unknown color"<<endl;
01388       }
01389     }
01390     //int recHitId=(i<<shiftId_) | RECHITECALID;
01391     int recHitId=i;
01392     createGRecHit(em_->rechitsECAL_[i],recHitId, maxe, phi0, rhcolor);
01393   }
01394         
01395   for(unsigned i=0; i<em_->rechitsHCAL_.size(); i++) { 
01396     int rhcolor = color;
01397     if(unsigned col = em_->clusterAlgoHCAL_.color(i) ) {
01398       switch(col) {
01399       case PFClusterAlgo::SEED: rhcolor = seedcolor; break;
01400       case PFClusterAlgo::SPECIAL: rhcolor = specialcolor; break;
01401       default:
01402         cerr<<"DisplayManager::loadGRecHits: unknown color"<<endl;
01403       }
01404     }
01405     //int recHitId=(i<<shiftId_) | RECHITHCALID;
01406     int recHitId=(RECHITHCALID <<shiftId_) | i;
01407     createGRecHit(em_->rechitsHCAL_[i],recHitId, maxe, phi0, rhcolor);
01408   }
01409         
01410   for(unsigned i=0; i<em_->rechitsPS_.size(); i++) { 
01411     int rhcolor = color;
01412     if( unsigned col = em_->clusterAlgoPS_.color(i) ) {
01413       switch(col) {
01414       case PFClusterAlgo::SEED: rhcolor = seedcolor; break;
01415       case PFClusterAlgo::SPECIAL: rhcolor = specialcolor; break;
01416       default:
01417         cerr<<"DisplayManager::loadGRecHits: unknown color"<<endl;
01418       }
01419     }
01420     //int recHitId=(i<<shiftId_) | RECHITPSID;
01421     int recHitId=(RECHITPSID<<shiftId_) | i;
01422                 
01423     createGRecHit(em_->rechitsPS_[i],recHitId, maxe, phi0, rhcolor);
01424   }
01425 } 
01426 //________________________________________________________________________
01427 void DisplayManager::loadGRecTracks()
01428 {
01429   double phi0=0;
01430         
01431   int ind=-1;
01432   std::vector<reco::PFRecTrack>::iterator itRecTrack;
01433   for (itRecTrack = em_->recTracks_.begin(); itRecTrack != em_->recTracks_.end();itRecTrack++) {
01434     double sign = 1.;
01435     const reco::PFTrajectoryPoint& tpinitial 
01436       = itRecTrack->extrapolatedPoint(reco::PFTrajectoryPoint::ClosestApproach);
01437     double pt = tpinitial.momentum().Pt();
01438     //if( pt<em_->displayRecTracksPtMin_ ) continue;
01439                 
01440     const reco::PFTrajectoryPoint& tpatecal 
01441       = itRecTrack->trajectoryPoint(itRecTrack->nTrajectoryMeasurements() +
01442                                     reco::PFTrajectoryPoint::ECALEntrance );
01443                 
01444     if ( cos(phi0 - tpatecal.momentum().Phi()) < 0.)
01445       sign = -1.;
01446                 
01447     const std::vector<reco::PFTrajectoryPoint>& points = 
01448       itRecTrack->trajectoryPoints();
01449                 
01450     int    linestyle = itRecTrack->algoType();
01451     ind++;
01452     //int recTrackId=(ind<<shiftId_) | RECTRACKID;
01453     int recTrackId=(RECTRACKID <<shiftId_) | ind; 
01454                 
01455     createGTrack(*itRecTrack,points,recTrackId, pt, phi0, sign, false,linestyle);
01456   }
01457 }
01458 //___________________________________________________________________________
01459 void DisplayManager::loadGSimParticles()
01460 {
01461   double phi0=0;
01462   //    bool debug_loadGSim = true;
01463   unsigned simParticlesVSize = em_->trueParticles_.size();
01464         
01465   for(unsigned i=0; i<simParticlesVSize; i++) {
01466                 
01467     const reco::PFSimParticle& ptc = em_->trueParticles_[i];
01468                 
01469     const reco::PFTrajectoryPoint& tpinitial 
01470       = ptc.extrapolatedPoint( reco::PFTrajectoryPoint::ClosestApproach );
01471                 
01472     double pt = tpinitial.momentum().Pt();
01473     //if( pt<em_->getDisplayTrueParticlesPtMin()) continue;
01474                 
01475     double sign = 1.;
01476     const reco::PFTrajectoryPoint& tpFirst = ptc.trajectoryPoint(0);
01477     if ( tpFirst.position().X() < 0. )
01478       sign = -1.;
01479     //double sign2 = 1.;
01480     // if position vector is 0,0,0: X component is undefined  (MDN 11 June 2008)
01481     // const reco::PFTrajectoryPoint& tpFirst = ptc.trajectoryPoint(0);
01482     //  if ( tpFirst.positionXYZ().X() < 0. )
01483     //   sign2 = -1.;
01484                 
01485     const std::vector<reco::PFTrajectoryPoint>& points = 
01486       ptc.trajectoryPoints();
01487       
01488 
01489     int markerstyle;
01490     int indexMarker;
01491     switch( abs(ptc.pdgCode() ) ) {
01492     case 22:   markerstyle = 3 ; indexMarker=0; break; // photons
01493     case 11:   markerstyle = 5 ; indexMarker=1;  break; // electrons 
01494     case 13:   markerstyle = 2 ; indexMarker=2;  break; // muons 
01495     case 130:  
01496     case 321:  markerstyle = 24; indexMarker=3; break; // K
01497     case 211:  markerstyle = 25; indexMarker=4; break; // pi+/pi-
01498     case 2212: markerstyle = 26; indexMarker=5; break; // protons
01499     case 2112: markerstyle = 27; indexMarker=6; break; // neutrons  
01500     default:   markerstyle = 30; indexMarker=7; break; 
01501     }
01502 
01503     bool displayInitial=true;
01504     if( ptc.motherId() < 0 ) displayInitial=false;
01505     int partId=(SIMPARTICLEID << shiftId_) | i; 
01506     createGPart(ptc, points,partId, pt, phi0, sign, displayInitial,indexMarker);
01507     //cout << " sign " << sign << " sign2 " << sign2 << endl;
01508     //if ( sign*sign2 <0 ) cout << " ++++++Warning sign*sign2 <0 ++++++++++++++++++ " << endl;
01509                 
01510   }
01511 }
01512 //_____________________________________________________________________________
01513 void DisplayManager::lookForMaxRecHit(bool ecal)
01514 {
01515   // look for the rechit with max e in ecal or hcal
01516   double maxe = -999;
01517   reco::PFRecHit* maxrh = 0;
01518         
01519   reco::PFRecHitCollection* rechits = 0;
01520   if(ecal) rechits = &(em_->rechitsECAL_);
01521   else rechits = &(em_->rechitsHCAL_);
01522   assert(rechits);
01523         
01524   for(unsigned i=0; i<(*rechits).size(); i++) {
01525                 
01526     double energy = (*rechits)[i].energy();
01527                 
01528     if(energy > maxe ) {
01529       maxe = energy;
01530       maxrh = &((*rechits)[i]);
01531     }      
01532   }
01533         
01534   if(!maxrh) return;
01535         
01536   // center view on this rechit
01537         
01538         
01539   // get the cell size to set the eta and phi width 
01540   // of the display window from one of the cells
01541         
01542   double phisize = -1;
01543   double etasize = -1;
01544   maxrh->size(phisize, etasize);
01545         
01546   double etagate = zoomFactor_ * etasize;
01547   double phigate = zoomFactor_ * phisize;
01548   
01549   double eta =  maxrh->position().Eta();
01550   double phi =  maxrh->position().Phi();
01551   
01552   if(displayHist_[EPE]) {
01553     displayHist_[EPE]->GetXaxis()->SetRangeUser(eta-etagate, eta+etagate);
01554     displayHist_[EPE]->GetYaxis()->SetRangeUser(phi-phigate, phi+phigate);
01555     displayView_[EPE]->Modified();
01556     displayView_[EPE]->Update();
01557   }
01558         
01559   if(displayHist_[EPH]) {
01560     displayHist_[EPH]->GetXaxis()->SetRangeUser(eta-etagate, eta+etagate);
01561     displayHist_[EPH]->GetYaxis()->SetRangeUser(phi-phigate, phi+phigate);
01562     displayView_[EPH]->Modified();
01563     displayView_[EPH]->Update();
01564   }
01565 }
01566 //________________________________________________________________________________
01567 void DisplayManager::lookForGenParticle(unsigned barcode) {
01568         
01569   const HepMC::GenEvent* event = em_->MCTruth_.GetEvent();
01570   if(!event) {
01571     cerr<<"no GenEvent"<<endl;
01572     return;
01573   }
01574         
01575   const HepMC::GenParticle* particle = event->barcode_to_particle(barcode);
01576   if(!particle) {
01577     cerr<<"no particle with barcode "<<barcode<<endl;
01578     return;
01579   }
01580         
01581   math::XYZTLorentzVector momentum(particle->momentum().px(),
01582                                    particle->momentum().py(),
01583                                    particle->momentum().pz(),
01584                                    particle->momentum().e());
01585         
01586   double eta = momentum.Eta();
01587   double phi = momentum.phi();
01588         
01589   double phisize = 0.05;
01590   double etasize = 0.05;
01591         
01592   double etagate = zoomFactor_ * etasize;
01593   double phigate = zoomFactor_ * phisize;
01594         
01595   if(displayHist_[EPE]) {
01596     displayHist_[EPE]->GetXaxis()->SetRangeUser(eta-etagate, eta+etagate);
01597     displayHist_[EPE]->GetYaxis()->SetRangeUser(phi-phigate, phi+phigate);
01598     displayView_[EPE]->Modified();
01599     displayView_[EPE]->Update();
01600                 
01601   }
01602   if(displayHist_[EPH]) {
01603     displayHist_[EPH]->GetXaxis()->SetRangeUser(eta-etagate, eta+etagate);
01604     displayHist_[EPH]->GetYaxis()->SetRangeUser(phi-phigate, phi+phigate);
01605     displayView_[EPH]->Modified();
01606     displayView_[EPH]->Update();
01607   }
01608 }
01609 //_______________________________________________________________________
01610 void DisplayManager::printDisplay(const char* sdirectory ) const
01611 {
01612   string directory = sdirectory;
01613   if( directory.empty() ) {   
01614     directory = "Event_";
01615   }
01616   char num[10];
01617   sprintf(num,"%d", eventNumber_);
01618   directory += num;
01619         
01620   string mkdir = "mkdir "; mkdir += directory;
01621   int code = system( mkdir.c_str() );
01622         
01623   if( code ) {
01624     cerr<<"cannot create directory "<<directory<<endl;
01625     return;
01626   }
01627         
01628   cout<<"Event display printed in directory "<<directory<<endl;
01629         
01630   directory += "/";
01631         
01632   for(unsigned iView=0; iView<displayView_.size(); iView++) {
01633     if( !displayView_[iView] ) continue;
01634                 
01635     string name = directory;
01636     name += displayView_[iView]->GetName();
01637                 
01638     cout<<displayView_[iView]->GetName()<<endl;
01639                 
01640     string eps = name; eps += ".eps";
01641     displayView_[iView]->SaveAs( eps.c_str() );
01642                 
01643     string png = name; png += ".png";
01644     displayView_[iView]->SaveAs( png.c_str() );
01645   }
01646         
01647   string txt = directory;
01648   txt += "event.txt";
01649   ofstream out( txt.c_str() );
01650   if( !out ) 
01651     cerr<<"cannot open "<<txt<<endl;
01652   em_->print( out );
01653 }
01654 //_____________________________________________________________________________
01655 void DisplayManager::reset()
01656 {
01657   maxERecHitEcal_=-1;
01658   maxERecHitHcal_=-1;
01659   isGraphicLoaded_= false;
01660   
01661   std::multimap<int,GPFBase *>::iterator p;
01662   for (p=graphicMap_.begin();p!=graphicMap_.end();p++)
01663     delete p->second;
01664   graphicMap_.clear();
01665 
01666   blockIdentsMap_.clear(); 
01667   selectedGObj_.clear();
01668 
01669 }
01670 //_______________________________________________________________________________
01671 void DisplayManager::unZoom()
01672 {
01673   for( unsigned i=0; i<displayHist_.size(); i++) {
01674     // the corresponding view was not requested
01675     if( ! displayHist_[i] ) continue;
01676     displayHist_[i]->GetXaxis()->UnZoom();
01677     displayHist_[i]->GetYaxis()->UnZoom();
01678   }
01679   updateDisplay();
01680 }
01681 //_______________________________________________________________________________
01682 void DisplayManager::setNewAttrToSimParticles()
01683 {
01684   simPartPatternM_.clear();
01685   simPartPatternM_.push_back(simPartPatternPhoton_);
01686   simPartPatternM_.push_back(simPartPatternElec_);
01687   simPartPatternM_.push_back(simPartPatternMuon_);
01688   simPartPatternM_.push_back(simPartPatternK_);
01689   simPartPatternM_.push_back(simPartPatternPi_);
01690   simPartPatternM_.push_back(simPartPatternProton_);
01691   simPartPatternM_.push_back(simPartPatternNeutron_);
01692   simPartPatternM_.push_back(simPartPatternDefault_);
01693 } 
01694 
01695 //_______________________________________________________________________________
01696 void DisplayManager::printGenParticleInfo(std::string name,int barcode,int barcodeMother) 
01697 { 
01698   const HepMC::GenEvent* myGenEvent = em_->MCTruth_.GetEvent();
01699   HepMC::GenParticle *p = myGenEvent->barcode_to_particle(barcode);
01700   std::cout<<"genParticle "<<name<<" with barcode "<<barcode<<std::flush<<std::endl;
01701   p->print();
01702   if (barcodeMother) { 
01703     HepMC:: GenParticle *mother = myGenEvent->barcode_to_particle(barcodeMother);
01704     std::cout<<"mother particle with barcode "<<barcodeMother<<std::flush<<std::endl;
01705     mother->print();
01706   }    
01707 }

Generated on Tue Jun 9 17:44:46 2009 for CMSSW by  doxygen 1.5.4