CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/DQM/SiStripMonitorTrack/src/SiStripMonitorMuonHLT.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    SiStripMonitorMuonHLT
00004 // Class:      SiStripMonitorMuonHLT
00005 // 
00013 //
00014 // Original Author:  Eric Chabert
00015 //         Created:  Wed Sep 23 17:26:42 CEST 2009
00016 // $Id: SiStripMonitorMuonHLT.cc,v 1.14 2012/01/17 10:31:50 innocent Exp $
00017 //
00018 
00019 #include "DQM/SiStripMonitorTrack/interface/SiStripMonitorMuonHLT.h"
00020 
00021 
00022 //
00023 // constructors and destructor
00024 //
00025 SiStripMonitorMuonHLT::SiStripMonitorMuonHLT (const edm::ParameterSet & iConfig)
00026 {
00027   //now do what ever initialization is needed
00028   parameters_ = iConfig;
00029   verbose_ = parameters_.getUntrackedParameter<bool>("verbose",false);
00030   normalize_ = parameters_.getUntrackedParameter<bool>("normalize",true);
00031   printNormalize_ = parameters_.getUntrackedParameter<bool>("printNormalize",false);
00032   monitorName_ = parameters_.getUntrackedParameter<std::string>("monitorName","HLT/HLTMonMuon");
00033   prescaleEvt_ = parameters_.getUntrackedParameter<int>("prescaleEvt",-1);
00034 
00035   //booleans
00036   runOnClusters_ = parameters_.getUntrackedParameter<bool>("runOnClusters",true);
00037   runOnMuonCandidates_ = parameters_.getUntrackedParameter<bool>("runOnMuonCandidates",true);
00038   runOnTracks_ = parameters_.getUntrackedParameter<bool>("runOnTracks",true);
00039 
00040   //tags
00041   clusterCollectionTag_ = parameters_.getUntrackedParameter < edm::InputTag > ("clusterCollectionTag",edm::InputTag("hltSiStripRawToClustersFacility"));
00042   l3collectionTag_ = parameters_.getUntrackedParameter < edm::InputTag > ("l3MuonTag",edm::InputTag("hltL3MuonCandidates"));
00043   TrackCollectionTag_ = parameters_.getUntrackedParameter < edm::InputTag > ("trackCollectionTag",edm::InputTag("hltL3TkTracksFromL2"));
00045 
00046   HistoNumber = 35;
00047 
00048   //services
00049   dbe_ = 0;
00050   if (!edm::Service < DQMStore > ().isAvailable ())
00051     {
00052       edm::LogError ("TkHistoMap") <<
00053         "\n------------------------------------------"
00054         "\nUnAvailable Service DQMStore: please insert in the configuration file an instance like" "\n\tprocess.load(\"DQMServices.Core.DQMStore_cfg\")" "\n------------------------------------------";
00055     }
00056   dbe_ = edm::Service < DQMStore > ().operator-> ();
00057   dbe_->setVerbose (0);
00058 
00059   tkdetmap_ = 0;
00060   if (!edm::Service < TkDetMap > ().isAvailable ())
00061     {
00062       edm::LogError ("TkHistoMap") <<
00063         "\n------------------------------------------"
00064         "\nUnAvailable Service TkHistoMap: please insert in the configuration file an instance like" "\n\tprocess.TkDetMap = cms.Service(\"TkDetMap\")" "\n------------------------------------------";
00065     }
00066   tkdetmap_ = edm::Service < TkDetMap > ().operator-> ();
00068 
00069   outputFile_ = parameters_.getUntrackedParameter < std::string > ("outputFile","");
00070   if (outputFile_.size () != 0) edm::LogWarning ("HLTMuonDQMSource") << "Muon HLT Monitoring histograms will be saved to " << outputFile_ << std::endl;
00071   else outputFile_ = "MuonHLTDQM.root";
00072 
00073   bool disable = parameters_.getUntrackedParameter < bool > ("disableROOToutput",false);
00074   if (disable) outputFile_ = "";
00075   if (dbe_ != NULL) dbe_->setCurrentFolder (monitorName_);
00076 
00077 }
00078 
00079 
00080 SiStripMonitorMuonHLT::~SiStripMonitorMuonHLT ()
00081 {
00082 
00083   // do anything here that needs to be done at desctruction time
00084   // (e.g. close files, deallocate resources etc.)
00085 
00086 }
00087 
00088 
00089 //
00090 // member functions
00091 //
00092 
00093 float SiStripMonitorMuonHLT::GetEtaWeight(std::string label, GlobalPoint clustgp){
00094         float etaWeight = 1.;
00095         for (unsigned int i = 0; i < m_BinEta[label].size() - 1; i++){                      
00096                 if (m_BinEta[label][i] < clustgp.eta() && clustgp.eta() < m_BinEta[label][i+1]){
00097                         if (m_ModNormEta[label][i] > 0.1) etaWeight = 1./m_ModNormEta[label][i];
00098                         else etaWeight = 1.;
00099                 }       
00100         }
00101         return etaWeight; 
00102 }
00103 
00104 float SiStripMonitorMuonHLT::GetPhiWeight(std::string label, GlobalPoint clustgp){
00105         float phiWeight = 1.;
00106         for (unsigned int i = 0; i < m_BinPhi[label].size() - 1; i++){                      
00107                 if (m_BinPhi[label][i] < clustgp.phi() && clustgp.phi() < m_BinPhi[label][i+1]){
00108                         if (m_ModNormPhi[label][i] > 0.1) phiWeight = 1./m_ModNormPhi[label][i];
00109                         else phiWeight = 1.;
00110                 }       
00111         }
00112         return phiWeight; 
00113 }
00114 
00115 // ------------ method called to for each event  ------------
00116 void
00117 SiStripMonitorMuonHLT::analyze (const edm::Event & iEvent, const edm::EventSetup & iSetup)
00118 {
00119 
00120 
00121 #ifdef THIS_IS_AN_EVENT_EXAMPLE
00122   Handle < ExampleData > pIn;
00123   iEvent.getByLabel ("example", pIn);
00124 #endif
00125 
00126 #ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE
00127   ESHandle < SetupData > pSetup;
00128   iSetup.get < SetupRecord > ().get (pSetup);
00129 #endif
00130 
00131   if (!dbe_)
00132     return;
00133   counterEvt_++;
00134   if (prescaleEvt_ > 0 && counterEvt_ % prescaleEvt_ != 0)
00135     return;
00136   LogDebug ("SiStripMonitorHLTMuon") << " processing conterEvt_: " << counterEvt_ << std::endl;
00137 
00138 
00139   edm::ESHandle < TrackerGeometry > TG;
00140   iSetup.get < TrackerDigiGeometryRecord > ().get (TG);
00141   const TrackerGeometry *theTrackerGeometry = TG.product ();
00142   const TrackerGeometry & theTracker (*theTrackerGeometry);
00143 
00144 
00146 
00147   //Access to L3MuonCand
00148   edm::Handle < reco::RecoChargedCandidateCollection > l3mucands;
00149   bool accessToL3Muons = true;
00150   iEvent.getByLabel (l3collectionTag_, l3mucands);
00151   reco::RecoChargedCandidateCollection::const_iterator cand;
00152 
00153   //Access to clusters
00154   edm::Handle < edm::LazyGetter < SiStripCluster > >clusters;
00155   bool accessToClusters = true;
00156   iEvent.getByLabel (clusterCollectionTag_, clusters);
00157   edm::LazyGetter < SiStripCluster >::record_iterator clust;
00158  
00159   //Access to Tracks
00160   edm::Handle<reco::TrackCollection > trackCollection;
00161   bool accessToTracks = true;
00162   iEvent.getByLabel (TrackCollectionTag_, trackCollection);
00163   reco::TrackCollection::const_iterator track;
00165 
00166 
00167   if (runOnClusters_ && accessToClusters && !clusters.failedToGet () && clusters.isValid())
00168     {
00169       for (clust = clusters->begin_record (); clust != clusters->end_record (); ++clust)
00170         {
00171           
00172           uint detID = clust->geographicalId ();
00173           std::stringstream ss;
00174           int layer = tkdetmap_->FindLayer (detID);
00175           std::string label = tkdetmap_->getLayerName (layer);
00176           const StripGeomDetUnit *theGeomDet = dynamic_cast < const StripGeomDetUnit * >(theTracker.idToDet (detID));
00177           const StripTopology *topol = dynamic_cast < const StripTopology * >(&(theGeomDet->specificTopology ()));
00178           // get the cluster position in local coordinates (cm) 
00179           LocalPoint clustlp = topol->localPosition (clust->barycenter ());
00180           GlobalPoint clustgp = theGeomDet->surface ().toGlobal (clustlp);
00181           
00182           //NORMALIZE HISTO IF ASKED
00183           float etaWeight = 1.;
00184           float phiWeight = 1.;
00185           if (normalize_){
00186                 etaWeight = GetEtaWeight(label, clustgp);
00187                 phiWeight = GetPhiWeight(label,clustgp);
00188           }        
00189           LayerMEMap[label.c_str ()].EtaDistribAllClustersMap->Fill (clustgp.eta (),etaWeight);
00190           LayerMEMap[label.c_str ()].PhiDistribAllClustersMap->Fill (clustgp.phi (),phiWeight);
00191           LayerMEMap[label.c_str ()].EtaPhiAllClustersMap->Fill (clustgp.eta (), clustgp.phi ());
00192           tkmapAllClusters->add(detID,1.);
00193         }
00194     }
00195 
00196   if (runOnMuonCandidates_ && accessToL3Muons && !l3mucands.failedToGet () && l3mucands.isValid())
00197     {
00198       for (cand = l3mucands->begin (); cand != l3mucands->end (); ++cand)
00199         {
00200           //TrackRef l3tk = cand->get < TrackRef > ();
00201           const reco::Track* l3tk = cand->get < reco::TrackRef > ().get();
00202           analyzeOnTrackClusters(l3tk, theTracker, true);       
00203         }                       //loop over l3mucands
00204     }                           //if l3seed
00205  
00206   if (runOnTracks_ && accessToTracks && !trackCollection.failedToGet() && trackCollection.isValid()){
00207         for (track = trackCollection->begin (); track != trackCollection->end() ; ++ track)
00208           {
00209             const reco::Track* tk =  &(*track);
00210             analyzeOnTrackClusters(tk, theTracker, false);      
00211           }
00212   }
00213 
00214 }
00215 
00216 void SiStripMonitorMuonHLT::analyzeOnTrackClusters( const reco::Track* l3tk, const TrackerGeometry & theTracker,  bool isL3MuTrack ){
00217 
00218           for (size_t hit = 0; hit < l3tk->recHitsSize (); hit++)
00219             {
00220               //if hit is valid and in tracker say true
00221               if (l3tk->recHit (hit)->isValid () == true && l3tk->recHit (hit)->geographicalId ().det () == DetId::Tracker)
00222                 {
00223                   uint detID = l3tk->recHit (hit)->geographicalId ()();
00224                   
00225                   const SiStripRecHit1D *hit1D = dynamic_cast < const SiStripRecHit1D * >(l3tk->recHit (hit).get ());
00226                   const SiStripRecHit2D *hit2D = dynamic_cast < const SiStripRecHit2D * >(l3tk->recHit (hit).get ());
00227                   const SiStripMatchedRecHit2D *hitMatched2D = dynamic_cast < const SiStripMatchedRecHit2D * >(l3tk->recHit (hit).get ());
00228                   const ProjectedSiStripRecHit2D *hitProj2D = dynamic_cast < const ProjectedSiStripRecHit2D * >(l3tk->recHit (hit).get ());
00229 
00230 
00231                   // if SiStripRecHit1D
00232                   if (hit1D != 0)
00233                     {
00234                       if (hit1D->cluster_regional ().isNonnull ())
00235                         {
00236                           if (hit1D->cluster_regional ().isAvailable ())
00237                             {
00238                               detID = hit1D->cluster_regional ()->geographicalId ();
00239                             }
00240                         }
00241                       int layer = tkdetmap_->FindLayer (detID);
00242                       std::string label = tkdetmap_->getLayerName (layer);
00243                       const StripGeomDetUnit *theGeomDet = dynamic_cast < const StripGeomDetUnit * >(theTracker.idToDet (detID));
00244                       if (theGeomDet != 0)
00245                         {
00246                           const StripTopology *topol = dynamic_cast < const StripTopology * >(&(theGeomDet->specificTopology ()));
00247                           if (topol != 0)
00248                             {
00249                               // get the cluster position in local coordinates (cm) 
00250                               LocalPoint clustlp = topol->localPosition (hit1D->cluster_regional ()->barycenter ());
00251                               GlobalPoint clustgp = theGeomDet->surface ().toGlobal (clustlp);
00252                               //NORMALIZE HISTO IF ASKED
00253                               float etaWeight = 1.;
00254                               float phiWeight = 1.;
00255                               if (normalize_){
00256                                 etaWeight = GetEtaWeight(label, clustgp);
00257                                 phiWeight = GetPhiWeight(label,clustgp);
00258                               }        
00259                               if(!isL3MuTrack){
00260                                 LayerMEMap[label.c_str ()].EtaDistribOnTrackClustersMap->Fill (clustgp.eta (),etaWeight);
00261                                 LayerMEMap[label.c_str ()].PhiDistribOnTrackClustersMap->Fill (clustgp.phi (),phiWeight);
00262                                 LayerMEMap[label.c_str ()].EtaPhiOnTrackClustersMap->Fill (clustgp.eta (), clustgp.phi ());  
00263                                 tkmapOnTrackClusters->add(detID,1.);
00264                               }
00265                               else{
00266                                 LayerMEMap[label.c_str ()].EtaDistribL3MuTrackClustersMap->Fill (clustgp.eta (),etaWeight);
00267                                 LayerMEMap[label.c_str ()].PhiDistribL3MuTrackClustersMap->Fill (clustgp.phi (),phiWeight);
00268                                 LayerMEMap[label.c_str ()].EtaPhiL3MuTrackClustersMap->Fill (clustgp.eta (), clustgp.phi ());  
00269                                 tkmapL3MuTrackClusters->add(detID,1.);
00270                               }
00271                             }
00272                         }
00273                     }
00274                   // if SiStripRecHit2D
00275                   if (hit2D != 0)
00276                     {
00277                       if (hit2D->cluster_regional ().isNonnull ())
00278                         {
00279                           if (hit2D->cluster_regional ().isAvailable ())
00280                             {
00281                               detID = hit2D->cluster_regional ()->geographicalId ();
00282                             }
00283                         }
00284                       int layer = tkdetmap_->FindLayer (detID);
00285                       std::string label = tkdetmap_->getLayerName (layer);
00286                       const StripGeomDetUnit *theGeomDet = dynamic_cast < const StripGeomDetUnit * >(theTracker.idToDet (detID));
00287                       if (theGeomDet != 0)
00288                         {
00289                           const StripTopology *topol = dynamic_cast < const StripTopology * >(&(theGeomDet->specificTopology ()));
00290                           if (topol != 0)
00291                             {
00292                               // get the cluster position in local coordinates (cm) 
00293                               LocalPoint clustlp = topol->localPosition (hit2D->cluster_regional ()->barycenter ());
00294                               GlobalPoint clustgp = theGeomDet->surface ().toGlobal (clustlp);
00295                               
00296                               //NORMALIZE HISTO IF ASKED
00297                               float etaWeight = 1.;
00298                               float phiWeight = 1.;
00299                               if (normalize_){
00300                                 etaWeight = GetEtaWeight(label, clustgp);
00301                                 phiWeight = GetPhiWeight(label,clustgp);
00302                               }
00303                               if(!isL3MuTrack){
00304                                 LayerMEMap[label.c_str ()].EtaDistribOnTrackClustersMap->Fill (clustgp.eta (),etaWeight);
00305                                 LayerMEMap[label.c_str ()].PhiDistribOnTrackClustersMap->Fill (clustgp.phi (),phiWeight);
00306                                 LayerMEMap[label.c_str ()].EtaPhiOnTrackClustersMap->Fill (clustgp.eta (), clustgp.phi ());  
00307                                 tkmapOnTrackClusters->add(detID,1.);
00308                               }
00309                               else{
00310                                 LayerMEMap[label.c_str ()].EtaDistribL3MuTrackClustersMap->Fill (clustgp.eta (),etaWeight);
00311                                 LayerMEMap[label.c_str ()].PhiDistribL3MuTrackClustersMap->Fill (clustgp.phi (),phiWeight);
00312                                 LayerMEMap[label.c_str ()].EtaPhiL3MuTrackClustersMap->Fill (clustgp.eta (), clustgp.phi ());  
00313                                 tkmapL3MuTrackClusters->add(detID,1.);
00314                               }
00315                             }
00316                         }
00317                     }
00318                   // if SiStripMatchedRecHit2D  
00319                   if (hitMatched2D != 0)
00320                     {
00321                       //hit mono
00322                       detID = hitMatched2D->monoCluster().geographicalId ();
00323                       int layer = tkdetmap_->FindLayer (detID);
00324                       std::string label = tkdetmap_->getLayerName (layer);
00325                       const StripGeomDetUnit *theGeomDet = dynamic_cast < const StripGeomDetUnit * >(theTracker.idToDet (detID));
00326                       if (theGeomDet != 0)
00327                         {
00328                           const StripTopology *topol = dynamic_cast < const StripTopology * >(&(theGeomDet->specificTopology ()));
00329                           if (topol != 0)
00330                             {
00331                               // get the cluster position in local coordinates (cm) 
00332                               LocalPoint clustlp = topol->localPosition (hitMatched2D->monoCluster().barycenter ());
00333                               GlobalPoint clustgp = theGeomDet->surface ().toGlobal (clustlp);
00334                               //NORMALIZE HISTO IF ASKED
00335                               float etaWeight = 1.;
00336                               float phiWeight = 1.;
00337                               if (normalize_){
00338                                 etaWeight = GetEtaWeight(label, clustgp);
00339                                 phiWeight = GetPhiWeight(label,clustgp);
00340                               }        
00341                               if(!isL3MuTrack){
00342                                 LayerMEMap[label.c_str ()].EtaDistribOnTrackClustersMap->Fill (clustgp.eta (),etaWeight);
00343                                 LayerMEMap[label.c_str ()].PhiDistribOnTrackClustersMap->Fill (clustgp.phi (),phiWeight);
00344                                 LayerMEMap[label.c_str ()].EtaPhiOnTrackClustersMap->Fill (clustgp.eta (), clustgp.phi ());  
00345                                 tkmapOnTrackClusters->add(detID,1.);
00346                               }
00347                               else{
00348                                 LayerMEMap[label.c_str ()].EtaDistribL3MuTrackClustersMap->Fill (clustgp.eta (),etaWeight);
00349                                 LayerMEMap[label.c_str ()].PhiDistribL3MuTrackClustersMap->Fill (clustgp.phi (),phiWeight);
00350                                 LayerMEMap[label.c_str ()].EtaPhiL3MuTrackClustersMap->Fill (clustgp.eta (), clustgp.phi ());  
00351                                 tkmapL3MuTrackClusters->add(detID,1.);
00352                               }
00353                             }
00354                         }
00355 
00356                       //hit stereo
00357                       detID = hitMatched2D->stereoCluster().geographicalId ();
00358                       layer = tkdetmap_->FindLayer (detID);
00359                       label = tkdetmap_->getLayerName (layer);
00360                       const StripGeomDetUnit *theGeomDet2 = dynamic_cast < const StripGeomDetUnit * >(theTracker.idToDet (detID));
00361                       if (theGeomDet2 != 0)
00362                         {
00363                           const StripTopology *topol = dynamic_cast < const StripTopology * >(&(theGeomDet2->specificTopology ()));
00364                           if (topol != 0)
00365                             {
00366                               // get the cluster position in local coordinates (cm) 
00367                               LocalPoint clustlp = topol->localPosition (hitMatched2D->stereoCluster().barycenter ());
00368                               GlobalPoint clustgp = theGeomDet2->surface ().toGlobal (clustlp);
00369                               //NORMALIZE HISTO IF ASKED
00370                               float etaWeight = 1.;
00371                               float phiWeight = 1.;
00372                               if (normalize_){
00373                                 etaWeight = GetEtaWeight(label, clustgp);
00374                                 phiWeight = GetPhiWeight(label,clustgp);
00375                               }        
00376                               if(!isL3MuTrack){
00377                                 LayerMEMap[label.c_str ()].EtaDistribOnTrackClustersMap->Fill (clustgp.eta (),etaWeight);
00378                                 LayerMEMap[label.c_str ()].PhiDistribOnTrackClustersMap->Fill (clustgp.phi (),phiWeight);
00379                                 LayerMEMap[label.c_str ()].EtaPhiOnTrackClustersMap->Fill (clustgp.eta (), clustgp.phi ());  
00380                                 tkmapOnTrackClusters->add(detID,1.);
00381                               }
00382                               else{
00383                                 LayerMEMap[label.c_str ()].EtaDistribL3MuTrackClustersMap->Fill (clustgp.eta (),etaWeight);
00384                                 LayerMEMap[label.c_str ()].PhiDistribL3MuTrackClustersMap->Fill (clustgp.phi (),phiWeight);
00385                                 LayerMEMap[label.c_str ()].EtaPhiL3MuTrackClustersMap->Fill (clustgp.eta (), clustgp.phi ());  
00386                                 tkmapL3MuTrackClusters->add(detID,1.);
00387                               }
00388                             }
00389                         }
00390 
00391                     }
00392 
00393                   //if ProjectedSiStripRecHit2D
00394                   if (hitProj2D != 0)
00395                     {
00396                       if (hitProj2D->originalHit ().cluster_regional ().isNonnull ())
00397                         {
00398                           if (hitProj2D->originalHit ().cluster_regional ().isAvailable ())
00399                             {
00400                               detID = hitProj2D->originalHit ().cluster_regional ()->geographicalId ();
00401                             }
00402                         }
00403                       int layer = tkdetmap_->FindLayer (detID);
00404                       std::string label = tkdetmap_->getLayerName (layer);
00405                       const StripGeomDetUnit *theGeomDet = dynamic_cast < const StripGeomDetUnit * >(theTracker.idToDet (detID));
00406                       if (theGeomDet != 0)
00407                         {
00408                           const StripTopology *topol = dynamic_cast < const StripTopology * >(&(theGeomDet->specificTopology ()));
00409                           if (topol != 0)
00410                             {
00411                               // get the cluster position in local coordinates (cm) 
00412                               LocalPoint clustlp = topol->localPosition (hitProj2D->originalHit ().cluster_regional ()->barycenter ());
00413                               GlobalPoint clustgp = theGeomDet->surface ().toGlobal (clustlp);
00414                               //NORMALIZE HISTO IF ASKED
00415                               float etaWeight = 1.;
00416                               float phiWeight = 1.;
00417                               if (normalize_){
00418                                 etaWeight = GetEtaWeight(label, clustgp);
00419                                 phiWeight = GetPhiWeight(label,clustgp);
00420                               }        
00421                               if(!isL3MuTrack){
00422                                 LayerMEMap[label.c_str ()].EtaDistribOnTrackClustersMap->Fill (clustgp.eta (),etaWeight);
00423                                 LayerMEMap[label.c_str ()].PhiDistribOnTrackClustersMap->Fill (clustgp.phi (),phiWeight);
00424                                 LayerMEMap[label.c_str ()].EtaPhiOnTrackClustersMap->Fill (clustgp.eta (), clustgp.phi ());  
00425                                 tkmapOnTrackClusters->add(detID,1.);
00426                               }
00427                               else{
00428                                 LayerMEMap[label.c_str ()].EtaDistribL3MuTrackClustersMap->Fill (clustgp.eta (),etaWeight);
00429                                 LayerMEMap[label.c_str ()].PhiDistribL3MuTrackClustersMap->Fill (clustgp.phi (),phiWeight);
00430                                 LayerMEMap[label.c_str ()].EtaPhiL3MuTrackClustersMap->Fill (clustgp.eta (), clustgp.phi ());  
00431                                 tkmapL3MuTrackClusters->add(detID,1.);
00432                               }
00433                             }
00434                         }
00435                     }
00436 
00437                 }
00438             }                   //loop over RecHits
00439 }
00440 
00441 void
00442 SiStripMonitorMuonHLT::createMEs (const edm::EventSetup & es)
00443 {
00444 
00445   // vector used 
00446   std::vector <float *> tgraphEta;
00447   std::vector <float *> tgraphPhi;
00448   std::vector <int> tgraphSize;
00449 
00450   std::vector <std::vector<float> > binningEta;
00451   std::vector <std::vector<float> > binningPhi;
00452 
00453   for (int p = 0; p < 34; p++){
00454     tgraphEta.push_back (new float[1000]);
00455     tgraphPhi.push_back (new float[1000]);    
00456   }
00457 
00458   // FOR COMPUTING BINNING
00459   std::map< std::string,std::vector<float> > m_BinEta_Prel ;
00460   std::map< std::string,std::vector<float> > m_PhiStripMod_Eta;
00461   std::map< std::string,std::vector<float> > m_PhiStripMod_Nb;
00462   
00463   //----------------
00464 
00465   //Get the tracker geometry
00466   edm::ESHandle < TrackerGeometry > TG;
00467   es.get < TrackerDigiGeometryRecord > ().get (TG);
00468   const TrackerGeometry *theTrackerGeometry = TG.product ();
00469   const TrackerGeometry & theTracker (*theTrackerGeometry);
00470 
00471   std::vector<DetId> Dets = theTracker.detUnitIds();  
00472 
00473 
00474   //CALL GEOMETRY METHOD
00475   GeometryFromTrackGeom(Dets,theTracker,m_PhiStripMod_Eta,m_PhiStripMod_Nb);
00476 
00477 
00482 
00483   std::string fullName, folder;
00484 
00485   //STRUCTURE OF DETECTORS
00486   int p =0;
00487 
00488   //Loop over layers
00489   for (int layer = 1; layer < HistoNumber; ++layer)
00490     {
00491       SiStripFolderOrganizer folderOrg;
00492       std::stringstream ss;
00493       SiStripDetId::SubDetector subDet;
00494       uint32_t subdetlayer, side;
00495       tkdetmap_->getSubDetLayerSide (layer, subDet, subdetlayer, side);
00496       folderOrg.getSubDetLayerFolderName (ss, subDet, subdetlayer, side);
00497       folder = ss.str ();
00498       dbe_->setCurrentFolder (monitorName_ + folder);
00499 
00500       LayerMEs layerMEs;
00501       layerMEs.EtaPhiAllClustersMap           = 0;
00502       layerMEs.EtaDistribAllClustersMap       = 0;  
00503       layerMEs.PhiDistribAllClustersMap       = 0;
00504       layerMEs.EtaPhiOnTrackClustersMap       = 0;
00505       layerMEs.EtaDistribOnTrackClustersMap   = 0;
00506       layerMEs.PhiDistribOnTrackClustersMap   = 0;  
00507       layerMEs.EtaPhiL3MuTrackClustersMap     = 0;
00508       layerMEs.EtaDistribL3MuTrackClustersMap = 0;
00509       layerMEs.PhiDistribL3MuTrackClustersMap = 0;
00510 
00511       std::string histoname;
00512       std::string title;
00513       std::string labelHisto = tkdetmap_->getLayerName (layer);
00514 
00515       std::string labelHisto_ID = labelHisto;
00516       labelHisto_ID.erase(3);
00517 
00518       //
00519       unsigned int sizePhi = 0;
00520       unsigned int sizeEta = 0;
00521       float * xbinsPhi = new float[100];
00522       float * xbinsEta = new float[100];
00523 
00524       //TEC && TID && TOB && TIB
00525       if (labelHisto_ID == "TEC" || labelHisto_ID == "TID" || labelHisto_ID == "TOB" || labelHisto_ID == "TIB"){
00526 
00527         // PHI BINNING
00528         //ADDING BORDERS
00529         m_BinPhi[labelHisto].push_back(-M_PI);
00530         m_BinPhi[labelHisto].push_back(M_PI);
00531 
00532         //SORTING
00533         sort(m_BinPhi[labelHisto].begin(),m_BinPhi[labelHisto].end());
00534         //CREATING XBIN VECTOR
00535         sizePhi = m_BinPhi[labelHisto].size();
00536 
00537         for (unsigned int i = 0; i < sizePhi; i++){
00538           xbinsPhi[i] = m_BinPhi[labelHisto][i];
00539         }
00540 
00541         //ETA BINNING
00542         std::vector <float > v_BinEta_Prel;
00543         // LOOPING ON RINGS
00544         for (unsigned int i = 0; i < 12; i++){
00545           // COMPUTE BARYCENTER IF NON NULL
00546           if (m_PhiStripMod_Nb[labelHisto][i] != 0 && fabs(m_PhiStripMod_Eta[labelHisto][i]) > 0.05){
00547             float EtaBarycenter = m_PhiStripMod_Eta[labelHisto][i]/m_PhiStripMod_Nb[labelHisto][i];
00548             v_BinEta_Prel.push_back(EtaBarycenter);
00549           }
00550         }
00551 
00552         //SORT THEM IN ETA
00553         sort(v_BinEta_Prel.begin(),v_BinEta_Prel.end());
00554 
00555         //RECOMPUTE THE BINS BY TAKING THE HALF OF THE DISTANCE
00556         for (unsigned int i = 0; i < v_BinEta_Prel.size(); i++){
00557           if (i == 0) m_BinEta[labelHisto].push_back(v_BinEta_Prel[i] - 0.15);
00558           if (i != 0) {
00559             float shift = v_BinEta_Prel[i] - v_BinEta_Prel[i-1];
00560             m_BinEta[labelHisto].push_back(v_BinEta_Prel[i] - shift/2.);
00561           }
00562           if (i == v_BinEta_Prel.size()-1) m_BinEta[labelHisto].push_back(v_BinEta_Prel[i] + 0.15);
00563         }
00564 
00565         sort(m_BinEta[labelHisto].begin(),m_BinEta[labelHisto].end());
00566 
00567         //CREATING XBIN VECTOR
00568         sizeEta = m_BinEta[labelHisto].size();
00569 
00570         for (unsigned int i = 0; i < sizeEta; i++){
00571           xbinsEta[i] = m_BinEta[labelHisto][i];
00572         }
00573 
00574       } // END SISTRIP DETECTORS
00575 
00576       // all clusters
00577       if(runOnClusters_){
00578         histoname = "EtaAllClustersDistrib_" + labelHisto;
00579         title = "#eta(All Clusters) in " + labelHisto;
00580         layerMEs.EtaDistribAllClustersMap = dbe_->book1D (histoname, title, sizeEta - 1, xbinsEta);
00581         histoname = "PhiAllClustersDistrib_" + labelHisto;
00582         title = "#phi(All Clusters) in " + labelHisto;
00583         layerMEs.PhiDistribAllClustersMap = dbe_->book1D (histoname, title, sizePhi - 1, xbinsPhi);
00584         histoname = "EtaPhiAllClustersMap_" + labelHisto;
00585         title = "#eta-#phi All Clusters map in " + labelHisto;
00586         layerMEs.EtaPhiAllClustersMap = dbe_->book2D (histoname, title, sizeEta - 1, xbinsEta, sizePhi - 1, xbinsPhi);
00587       }
00588       // on track clusters
00589       if(runOnTracks_){
00590         histoname = "EtaOnTrackClustersDistrib_" + labelHisto;
00591         title = "#eta(OnTrack Clusters) in " + labelHisto;
00592         layerMEs.EtaDistribOnTrackClustersMap = dbe_->book1D (histoname, title, sizeEta - 1, xbinsEta);
00593         histoname = "PhiOnTrackClustersDistrib_" + labelHisto;
00594         title = "#phi(OnTrack Clusters) in " + labelHisto;
00595         layerMEs.PhiDistribOnTrackClustersMap = dbe_->book1D (histoname, title, sizePhi - 1, xbinsPhi);
00596         histoname = "EtaPhiOnTrackClustersMap_" + labelHisto;
00597         title = "#eta-#phi OnTrack Clusters map in " + labelHisto;
00598         layerMEs.EtaPhiOnTrackClustersMap = dbe_->book2D (histoname, title, sizeEta - 1, xbinsEta, sizePhi - 1, xbinsPhi);
00599       }
00600       if(runOnMuonCandidates_){
00601         // L3 muon track clusters
00602         histoname = "EtaL3MuTrackClustersDistrib_" + labelHisto;
00603         title = "#eta(L3MuTrack Clusters) in " + labelHisto;
00604         layerMEs.EtaDistribL3MuTrackClustersMap = dbe_->book1D (histoname, title, sizeEta - 1, xbinsEta);
00605         histoname = "PhiL3MuTrackClustersDistrib_" + labelHisto;
00606         title = "#phi(L3MuTrack Clusters) in " + labelHisto;
00607         layerMEs.PhiDistribL3MuTrackClustersMap = dbe_->book1D (histoname, title, sizePhi - 1, xbinsPhi);
00608         histoname = "EtaPhiL3MuTrackClustersMap_" + labelHisto;
00609         title = "#eta-#phi L3MuTrack Clusters map in " + labelHisto;
00610         layerMEs.EtaPhiL3MuTrackClustersMap = dbe_->book2D (histoname, title, sizeEta - 1, xbinsEta, sizePhi - 1, xbinsPhi);
00611       }
00612       LayerMEMap[labelHisto] = layerMEs;
00613 
00614       //PUTTING ERRORS
00615       if(runOnClusters_){
00616         LayerMEMap[labelHisto].EtaDistribAllClustersMap->getTH1F()->Sumw2();
00617         LayerMEMap[labelHisto].PhiDistribAllClustersMap->getTH1F()->Sumw2();
00618         LayerMEMap[labelHisto].EtaPhiAllClustersMap->getTH2F()->Sumw2();
00619       }
00620       if(runOnTracks_){
00621         LayerMEMap[labelHisto].EtaDistribOnTrackClustersMap->getTH1F()->Sumw2();
00622         LayerMEMap[labelHisto].PhiDistribOnTrackClustersMap->getTH1F()->Sumw2();
00623         LayerMEMap[labelHisto].EtaPhiOnTrackClustersMap->getTH2F()->Sumw2();
00624       }
00625       if(runOnMuonCandidates_){
00626         LayerMEMap[labelHisto].EtaDistribL3MuTrackClustersMap->getTH1F()->Sumw2();
00627         LayerMEMap[labelHisto].PhiDistribL3MuTrackClustersMap->getTH1F()->Sumw2();
00628         LayerMEMap[labelHisto].EtaPhiL3MuTrackClustersMap->getTH2F()->Sumw2();
00629       }
00630       
00631       p++;
00632     }   //end of loop over layers
00633 
00634 
00635   //CALL THE NORMALIZATION METHOD
00636   Normalizer(Dets,theTracker);
00637 
00638 }                               //end of method
00639 
00640 
00641 void
00642 SiStripMonitorMuonHLT::GeometryFromTrackGeom (std::vector<DetId> Dets,const TrackerGeometry & theTracker,
00643                                               std::map< std::string,std::vector<float> > & m_PhiStripMod_Eta,std::map< std::string,std::vector<float> > & m_PhiStripMod_Nb){
00644 
00645 
00646   std::vector<std::string> v_LabelHisto;
00647 
00648   //Loop over DetIds
00649   //-----------------------------------------
00650   for(std::vector<DetId>::iterator detid_iterator =  Dets.begin(); detid_iterator!=Dets.end(); detid_iterator++){
00651     uint32_t detid = (*detid_iterator)();
00652 
00653     if ( (*detid_iterator).null() == true) break;
00654     if (detid == 0)  break;
00655 
00656     // Select the propers detectors - avoid pixels
00657     const GeomDetUnit * GeomDet = theTracker.idToDetUnit(detid);
00658     const GeomDet::SubDetector detector = GeomDet->subDetector();
00659 
00660     int mylayer;
00661     std::string mylabelHisto;
00662 
00663     // SELECT SISTRIP DETECTORS
00664     if (detector == GeomDetEnumerators::TEC
00665         || detector == GeomDetEnumerators::TID
00666         || detector == GeomDetEnumerators::TOB
00667         || detector == GeomDetEnumerators::TIB
00668         ){
00669 
00670       const StripGeomDetUnit *theGeomDet = dynamic_cast < const StripGeomDetUnit * >(theTracker.idToDet (detid));
00671       const StripTopology *topol = dynamic_cast < const StripTopology * >(&(theGeomDet->specificTopology ()));
00672 
00673       // Get the position of the 1st strip in local coordinates (cm) 
00674       LocalPoint clustlp = topol->localPosition (1.);
00675       GlobalPoint clustgp = theGeomDet->surface ().toGlobal (clustlp);
00676 
00677       // Get the eta, phi of modules
00678       mylayer = tkdetmap_->FindLayer (detid);
00679       mylabelHisto = tkdetmap_->getLayerName (mylayer);
00680 
00681       //      SiStripDetId stripdet = SiStripDetId(detid);
00682 
00683       // INITIALISATION OF m_PhiStripMod_Eta + BOOKING LAYERS
00684 
00685       //TEST IF NEW LAYER
00686       unsigned int count = 0;
00687       while (count < v_LabelHisto.size()){
00688         if (mylabelHisto == v_LabelHisto[count]) break;
00689         count++;
00690       }
00691       if (count == v_LabelHisto.size()){
00692 
00693         //FILL THE NEW LAYER
00694         v_LabelHisto.push_back(mylabelHisto);
00695 
00696         //INITIALIZE
00697 
00698         // LOOPING ON RINGS
00699         for (int i = 0; i < 12; i++){
00700           m_PhiStripMod_Eta[mylabelHisto].push_back(0.);
00701           m_PhiStripMod_Nb[mylabelHisto].push_back(0.);
00702         }
00703       }
00704 
00705       //TEC
00706       if (detector == GeomDetEnumerators::TEC ){
00707 
00708         TECDetId id = TECDetId(detid);
00709 
00710         //PHI BINNING
00711         //Select 7th ring
00712         if (id.ringNumber() == 7){
00713           //SELECT FP
00714           if (id.moduleNumber() == 1 && id.isFrontPetal() == true) m_BinPhi[mylabelHisto].push_back(clustgp.phi());
00715           //SELECT BP
00716           if (id.moduleNumber() == 1 && id.isBackPetal() == true) m_BinPhi[mylabelHisto].push_back(clustgp.phi());
00717         }
00718 
00719         //ETA BINNING
00720         //Select arbitrary petal
00721         if (id.petalNumber() == 1 ){
00722           m_PhiStripMod_Eta[mylabelHisto][id.ringNumber()-1] = m_PhiStripMod_Eta[mylabelHisto][id.ringNumber()-1] + clustgp.eta();
00723           m_PhiStripMod_Nb[mylabelHisto][id.ringNumber()-1]++;
00724         }
00725 
00726       } //END TEC
00727 
00728       //TID
00729       if (detector == GeomDetEnumerators::TID ){
00730 
00731         TIDDetId id = TIDDetId(detid);
00732 
00733         //PHI BINNING
00734         //Select 1st ring
00735         if (id.ringNumber() == 1){
00736           //SELECT MONO
00737           if (id.isFrontRing() == true && id.isStereo() == false) m_BinPhi[mylabelHisto].push_back(clustgp.phi());
00738           //SELECT STEREO
00739           if (id.isFrontRing() == true && id.isStereo() == true) m_BinPhi[mylabelHisto].push_back(clustgp.phi());
00740         }
00741 
00742         //ETA BINNING
00743         //Select arbitrary line in eta (phi fixed)
00744         if (id.moduleNumber() == 1){
00745           m_PhiStripMod_Eta[mylabelHisto][id.ringNumber()-1] = m_PhiStripMod_Eta[mylabelHisto][id.ringNumber()-1] + clustgp.eta();
00746           m_PhiStripMod_Nb[mylabelHisto][id.ringNumber()-1]++;
00747         }
00748 
00749       } //END TID
00750 
00751       //TOB
00752       if (detector == GeomDetEnumerators::TOB ){
00753 
00754         TOBDetId id = TOBDetId(detid);
00755         //PHI BINNING
00756         //Select arbitrary line in phi (eta fixed)
00757         if (id.moduleNumber() == 1 && id.isZMinusSide() == true){
00758           //SELECT MONO
00759           if (id.isStereo() == false) m_BinPhi[mylabelHisto].push_back(clustgp.phi());
00760         }
00761 
00762         //ETA BINNING
00763         //Select arbitrary rod
00764         if ( (id.rodNumber() == 2 && id.isStereo() == false)
00765              || (id.rodNumber() == 1 && id.isStereo() == true)
00766              ){
00767           if (id.isZMinusSide() == true){
00768             m_PhiStripMod_Eta[mylabelHisto][id.moduleNumber()-1] = m_PhiStripMod_Eta[mylabelHisto][id.moduleNumber()-1] + clustgp.eta();
00769             m_PhiStripMod_Nb[mylabelHisto][id.moduleNumber()-1]++;
00770           }
00771           if (id.isZMinusSide() == false){
00772             m_PhiStripMod_Eta[mylabelHisto][id.moduleNumber()+5] = m_PhiStripMod_Eta[mylabelHisto][id.moduleNumber()+5] + clustgp.eta();
00773             m_PhiStripMod_Nb[mylabelHisto][id.moduleNumber()+5]++;
00774           }
00775         }
00776 
00777       } //END TOB
00778 
00779       //TIB
00780       if (detector == GeomDetEnumerators::TIB ){
00781 
00782         TIBDetId id = TIBDetId(detid);
00783 
00784         //PHI BINNING
00785         //Select arbitrary line in phi (eta fixed)
00786         if (id.moduleNumber() == 1 && id.isZMinusSide() == true){
00787           //SELECT MONO
00788           if (id.isInternalString() == true && id.isStereo() == false) m_BinPhi[mylabelHisto].push_back(clustgp.phi());
00789         }
00790 
00791         //ETA BINNING
00792         //Select arbitrary string
00793         if ( (id.stringNumber() == 2 && id.isStereo() == false)
00794              || (id.stringNumber() == 1 && id.isStereo() == true)
00795              ){
00796           if (id.isZMinusSide() == true){
00797             if (id.isInternalString() == true){
00798               m_PhiStripMod_Eta[mylabelHisto][id.moduleNumber()-1] = m_PhiStripMod_Eta[mylabelHisto][id.moduleNumber()-1] + clustgp.eta();
00799               m_PhiStripMod_Nb[mylabelHisto][id.moduleNumber()-1]++;
00800             }
00801             if (id.isInternalString() == false){
00802               m_PhiStripMod_Eta[mylabelHisto][id.moduleNumber()+2] = m_PhiStripMod_Eta[mylabelHisto][id.moduleNumber()+2] + clustgp.eta();
00803               m_PhiStripMod_Nb[mylabelHisto][id.moduleNumber()+2]++;
00804             }
00805           }
00806           if (id.isZMinusSide() == false){
00807             if (id.isInternalString() == true){
00808               m_PhiStripMod_Eta[mylabelHisto][id.moduleNumber()+5] = m_PhiStripMod_Eta[mylabelHisto][id.moduleNumber()+5] + clustgp.eta();
00809               m_PhiStripMod_Nb[mylabelHisto][id.moduleNumber()+5]++;
00810             }
00811             if (id.isInternalString() == false){
00812               m_PhiStripMod_Eta[mylabelHisto][id.moduleNumber()+8] = m_PhiStripMod_Eta[mylabelHisto][id.moduleNumber()+8] + clustgp.eta();
00813               m_PhiStripMod_Nb[mylabelHisto][id.moduleNumber()+8]++;
00814             }
00815           }
00816         }
00817 
00818       } //END TIB
00819 
00820     } // END SISTRIP DETECTORS
00821   } // END DETID LOOP
00822 
00823 } //END OF METHOD
00824 
00825 
00826 
00827 void
00828 SiStripMonitorMuonHLT::Normalizer (std::vector<DetId> Dets,const TrackerGeometry & theTracker){
00829   
00830   
00831   std::vector<std::string> v_LabelHisto;
00832 
00833   //Loop over DetIds
00834   //-----------------------------------------
00835   for(std::vector<DetId>::iterator detid_iterator =  Dets.begin(); detid_iterator!=Dets.end(); detid_iterator++){
00836     uint32_t detid = (*detid_iterator)();
00837     
00838     if ( (*detid_iterator).null() == true) break;
00839     if (detid == 0)  break;  
00840     
00841     // Select the propers detectors - avoid pixels
00842     const GeomDetUnit * GeomDet = theTracker.idToDetUnit(detid);
00843     const GeomDet::SubDetector detector = GeomDet->subDetector();
00844 
00845     int mylayer;
00846     std::string mylabelHisto;
00847     
00848     // SELECT SISTRIP DETECTORS
00849     if (detector == GeomDetEnumerators::TEC 
00850         || detector == GeomDetEnumerators::TID
00851         || detector == GeomDetEnumerators::TOB
00852         || detector == GeomDetEnumerators::TIB
00853         ){
00854       
00855       const StripGeomDetUnit *theGeomDet = dynamic_cast < const StripGeomDetUnit * >(theTracker.idToDet (detid));
00856       //      const StripTopology *topol = dynamic_cast < const StripTopology * >(&(theGeomDet->specificTopology ()));
00857 
00858       // Get the eta, phi of modules
00859       mylayer = tkdetmap_->FindLayer (detid);
00860       mylabelHisto = tkdetmap_->getLayerName (mylayer);
00861 
00862       //      SiStripDetId stripdet = SiStripDetId(detid);
00863 
00864       // INITIALISATION OF m_ModNormEta + BOOKING LAYERS
00865 
00866       //TEST IF NEW LAYER
00867       unsigned int count = 0;
00868 
00869       while (count < v_LabelHisto.size()){
00870         if (mylabelHisto == v_LabelHisto[count]) break;
00871         count++;
00872       }
00873 
00874       if (count == v_LabelHisto.size()){
00875         //FILL THE NEW LAYER
00876         v_LabelHisto.push_back(mylabelHisto);
00877 
00878         //INITIALIZE    
00879         // LOOPING ON ETA VECTOR
00880         for (unsigned int i = 0; i < m_BinEta[mylabelHisto].size() -1; i++){
00881           m_ModNormEta[mylabelHisto].push_back(0.);
00882         }
00883 
00884         // LOOPING ON PHI VECTOR
00885         for (unsigned int i = 0; i < m_BinPhi[mylabelHisto].size() -1; i++){
00886           m_ModNormPhi[mylabelHisto].push_back(0.);
00887         }
00888       }
00889 
00890       // Get the position of the 1st strip in local coordinates (cm) 
00891       //      LocalPoint clustlp_1 = topol->localPosition (1.);
00892       //      GlobalPoint clustgp_1 = theGeomDet->surface ().toGlobal (clustlp_1);
00893 
00894       // Get the position of the center of the module
00895       LocalPoint clustlp(0.,0.);
00896       GlobalPoint clustgp = theGeomDet->surface ().toGlobal (clustlp);
00897 
00898       // Get the position of the last strip
00899       //      LocalPoint Border_clustlp = topol->localPosition (topol->nstrips());
00900       //      GlobalPoint Border_clustgp = theGeomDet->surface ().toGlobal (Border_clustlp);
00901 
00902       //GETTING SURFACE VALUE
00903       const BoundPlane& GeomDetSurface = GeomDet->surface();
00904       const Bounds& bound = GeomDetSurface.bounds();        
00905                                                     
00906       std::string labelHisto_ID = mylabelHisto;
00907       labelHisto_ID.erase(3);             
00908                              
00909       float length = 0.;
00910       float width = 0.; 
00911 
00912       std::vector <GlobalPoint> v_Edge_G;
00913                                     
00914       float ratio = 0.;
00915       float factor = 1.;
00916       
00917       //RECTANGULAR BOUNDS
00918       if (labelHisto_ID == "TOB" || labelHisto_ID == "TIB"){
00919         const RectangularPlaneBounds *rectangularBound = dynamic_cast < const RectangularPlaneBounds * >(& bound);                                                  
00920         length = rectangularBound->length();
00921         width = rectangularBound->width();                                                                                                                        
00922         ratio = width/length;
00923             
00924         //EDGES POINTS
00925         LocalPoint topleft(-width/2., length/2.);
00926         LocalPoint topright(width/2., length/2.);                                                                                                                   LocalPoint botleft(-width/2., -length/2.);
00927         LocalPoint botright(width/2., -length/2.);                                                                                                                                  
00928         v_Edge_G.push_back(theGeomDet->surface ().toGlobal (topleft));
00929         v_Edge_G.push_back(theGeomDet->surface ().toGlobal (topright));
00930         v_Edge_G.push_back(theGeomDet->surface ().toGlobal (botleft));                                                                                              v_Edge_G.push_back(theGeomDet->surface ().toGlobal (botright));
00931       }                                                                                                                                                            
00932       //TRAPEZOIDAL BOUNDS
00933       if (labelHisto_ID == "TEC" || labelHisto_ID == "TID"){    
00934         const TrapezoidalPlaneBounds *trapezoidalBound = dynamic_cast < const TrapezoidalPlaneBounds * >(& bound);
00935 
00936         length = trapezoidalBound->length();
00937         width = trapezoidalBound->widthAtHalfLength();
00938 
00939         ratio = width/length;
00940 
00941         //EDGES POINTS
00942         LocalPoint topleft(-width/2., length/2.);
00943         LocalPoint topright(width/2., length/2.);
00944         LocalPoint botleft(-width/2., -length/2.);
00945         LocalPoint botright(width/2., -length/2.);
00946 
00947         v_Edge_G.push_back(theGeomDet->surface ().toGlobal (topleft));
00948         v_Edge_G.push_back(theGeomDet->surface ().toGlobal (topright));
00949         v_Edge_G.push_back(theGeomDet->surface ().toGlobal (botleft));
00950         v_Edge_G.push_back(theGeomDet->surface ().toGlobal (botright));
00951       }
00952 
00953       //SORTING EDGES POINTS
00954       GlobalPoint top_left_G;
00955       GlobalPoint top_rightG;
00956       GlobalPoint bot_left_G;
00957       GlobalPoint bot_rightG;
00958 
00959       std::vector <bool> v_Fill;
00960       v_Fill.push_back(false);
00961       v_Fill.push_back(false);
00962       v_Fill.push_back(false);
00963       v_Fill.push_back(false);
00964 
00965       for (unsigned int i =0 ; i< v_Edge_G.size() ; i++){
00966         if (v_Edge_G[i].eta() < clustgp.eta()){
00967           if (v_Edge_G[i].phi() < clustgp.phi()) {
00968             bot_left_G = v_Edge_G[i];
00969             v_Fill[0] = true;
00970           }
00971           if (v_Edge_G[i].phi() > clustgp.phi()){
00972             top_left_G = v_Edge_G[i];
00973             v_Fill[1] = true;
00974           }
00975         }
00976         if (v_Edge_G[i].eta() > clustgp.eta()){
00977           if (v_Edge_G[i].phi() < clustgp.phi()){
00978             bot_rightG = v_Edge_G[i];
00979             v_Fill[2] = true;
00980           }
00981           if (v_Edge_G[i].phi() > clustgp.phi()){
00982             top_rightG = v_Edge_G[i];
00983             v_Fill[3] = true;
00984           }
00985         }
00986       }
00987 
00988       //USE EDGES FOR COMPUTING WIDTH AND LENGTH
00989 
00990       float G_length = 0.;
00991       float G_width = 0.;
00992 
00993       bool flag_border = false;
00994 
00995       if (v_Fill[0] == true
00996           && v_Fill[1] == true
00997           && v_Fill[2] == true
00998           && v_Fill[3] == true){
00999 
01000         //LENGTH BETWEEN TL AND TR
01001         G_length = sqrt( (top_left_G.x()-top_rightG.x())*(top_left_G.x()-top_rightG.x()) + (top_left_G.y()-top_rightG.y())*(top_left_G.y()-top_rightG.y()) + (top_left_G.z()-top_rightG.z())*(top_left_G.z()-top_rightG.z()) );
01002 
01003         //WIDTH BETWEEN BL AND TL
01004         G_width = sqrt( (bot_left_G.x()-top_left_G.x())*(bot_left_G.x()-top_left_G.x()) + (bot_left_G.y()-top_left_G.y())*(bot_left_G.y()-top_left_G.y()) + (bot_left_G.z()-top_left_G.z())*(bot_left_G.z()-top_left_G.z()) );
01005 
01006       }
01007       else {
01008 
01009         // MODULE IN THE PHI BORDER (-PI,PI)
01010         flag_border = true;
01011 
01012         //SORT THE EDGES POINTS 
01013         for (unsigned int i =0 ; i< v_Edge_G.size() ; i++){
01014 
01015           if (v_Edge_G[i].phi() > 0. ){
01016             if (v_Edge_G[i].eta() < clustgp.eta()){
01017               bot_left_G = v_Edge_G[i];
01018             }
01019             if (v_Edge_G[i].eta() > clustgp.eta()){
01020               bot_rightG = v_Edge_G[i];
01021             }
01022           }
01023           if (v_Edge_G[i].phi() < 0. ){
01024             if (v_Edge_G[i].eta() < clustgp.eta()){
01025               top_left_G = v_Edge_G[i];
01026             }
01027             if (v_Edge_G[i].eta() > clustgp.eta()){
01028               top_rightG = v_Edge_G[i];
01029             }
01030           }
01031         }
01032 
01033         // XYZ WIDTH AND LENGTH
01034         G_length = sqrt( (top_left_G.x()-top_rightG.x())*(top_left_G.x()-top_rightG.x()) + (top_left_G.y()-top_rightG.y())*(top_left_G.y()-top_rightG.y()) + (top_left_G.z()-top_rightG.z())*(top_left_G.z()-top_rightG.z()) );
01035         G_width = G_length*ratio;
01036       }
01037 
01038 
01039       //ETA PLOTS
01040       //unsigned int LastBinEta = m_BinEta[mylabelHisto].size() - 2;
01041       for (unsigned int i = 0; i < m_BinEta[mylabelHisto].size() - 1; i++){
01042         if (m_BinEta[mylabelHisto][i] <= clustgp.eta() && clustgp.eta() < m_BinEta[mylabelHisto][i+1]){
01043 
01044           // NO NEED TO DO CORRECTIONS FOR ETA
01045           m_ModNormEta[mylabelHisto][i] = m_ModNormEta[mylabelHisto][i] + factor*G_length*G_width;
01046 
01047         }
01048       } //END ETA
01049 
01050       //PHI PLOTS
01051       unsigned int LastBinPhi = m_BinPhi[mylabelHisto].size() - 2;
01052       for (unsigned int i = 0; i < m_BinPhi[mylabelHisto].size() - 1; i++){
01053         if (m_BinPhi[mylabelHisto][i] <= clustgp.phi() && clustgp.phi() < m_BinPhi[mylabelHisto][i+1]){
01054 
01055           // SCRIPT TO INTEGRATE THE SURFACE INTO PHI BIN
01056 
01057           float phiMin = std::min(bot_left_G.phi(),bot_rightG.phi());
01058           float phiMax = std::max(top_left_G.phi(),top_rightG.phi());
01059 
01060           bool offlimit_prev = false;
01061           bool offlimit_foll = false;
01062 
01063           if (phiMin < m_BinPhi[mylabelHisto][i]) offlimit_prev = true;
01064           if (i != LastBinPhi){
01065             if (phiMax > m_BinPhi[mylabelHisto][i+1]) offlimit_foll = true;
01066           }
01067 
01068           //LOOKING FOR THE INTERSECTION POINTS   
01069           float MidPoint_X_prev;
01070           float MidPoint_Y_prev;
01071           float MidPoint_Z_prev;
01072           float MidPoint_X_foll;
01073           float MidPoint_Y_foll;
01074           float MidPoint_Z_foll;
01075 
01076           // OFF LIMIT IN THE PREVIOUS BIN
01077           if (offlimit_prev){
01078 
01079             // BL TL
01080             float tStar1 = (m_BinPhi[mylabelHisto][i]-bot_left_G.phi())/(top_left_G.phi()-bot_left_G.phi());
01081 
01082             // BR TR
01083             float tStar2 = (m_BinPhi[mylabelHisto][i]-bot_rightG.phi())/(top_rightG.phi()-bot_rightG.phi());
01084 
01085             if (tStar1 < 0.) tStar1 = 0.;
01086             if (tStar2 < 0.) tStar2 = 0.;
01087 
01088             //FIND Z OF STAR POINT
01089             float xStar1 = bot_left_G.x() + (tStar1*1.)*(top_left_G.x()-bot_left_G.x());
01090             float xStar2 = bot_rightG.x() + (tStar2*1.)*(top_rightG.x()-bot_rightG.x());
01091 
01092             float yStar1 = bot_left_G.y() + (tStar1*1.)*(top_left_G.y()-bot_left_G.y());
01093             float yStar2 = bot_rightG.y() + (tStar2*1.)*(top_rightG.y()-bot_rightG.y());
01094 
01095             float zStar1 = bot_left_G.z() + (tStar1*1.)*(top_left_G.z()-bot_left_G.z());
01096             float zStar2 = bot_rightG.z() + (tStar2*1.)*(top_rightG.z()-bot_rightG.z());
01097 
01098             //MIDPOINT
01099             MidPoint_X_prev = (xStar1 + xStar2)/2.;
01100             MidPoint_Y_prev = (yStar1 + yStar2)/2.;
01101             MidPoint_Z_prev = (zStar1 + zStar2)/2.;
01102           }
01103 
01104           if (offlimit_prev == false){
01105             MidPoint_X_prev = (bot_left_G.x() + bot_rightG.x())/2.;
01106             MidPoint_Y_prev = (bot_left_G.y() + bot_rightG.y())/2.;
01107             MidPoint_Z_prev = (bot_left_G.z() + bot_rightG.z())/2.;
01108           }
01109 
01110           // OFF LIMIT IN THE FOLLOWING BIN
01111           if (offlimit_foll){
01112 
01113              // BL TL
01114             float tStar1 = (m_BinPhi[mylabelHisto][i+1]-bot_left_G.phi())/(top_left_G.phi()-bot_left_G.phi());
01115 
01116             // BR TR
01117             float tStar2 = (m_BinPhi[mylabelHisto][i+1]-bot_rightG.phi())/(top_rightG.phi()-bot_rightG.phi());
01118 
01119             if (tStar1 > 1.) tStar1 = 1.;
01120             if (tStar2 > 1.) tStar2 = 1.;
01121 
01122             //FIND Z OF STAR POINT                  
01123             float xStar1 = bot_left_G.x() + (tStar1*1.)*(top_left_G.x()-bot_left_G.x());
01124             float xStar2 = bot_rightG.x() + (tStar2*1.)*(top_rightG.x()-bot_rightG.x());
01125 
01126             float yStar1 = bot_left_G.y() + (tStar1*1.)*(top_left_G.y()-bot_left_G.y());
01127             float yStar2 = bot_rightG.y() + (tStar2*1.)*(top_rightG.y()-bot_rightG.y());
01128 
01129             float zStar1 = bot_left_G.z() + (tStar1*1.)*(top_left_G.z()-bot_left_G.z());
01130             float zStar2 = bot_rightG.z() + (tStar2*1.)*(top_rightG.z()-bot_rightG.z());
01131 
01132             //MIDPOINT
01133             MidPoint_X_foll = (xStar1 + xStar2)/2.;
01134             MidPoint_Y_foll = (yStar1 + yStar2)/2.;
01135             MidPoint_Z_foll = (zStar1 + zStar2)/2.;
01136           }
01137 
01138           if (offlimit_foll == false){
01139             MidPoint_X_foll = (top_left_G.x() + top_rightG.x())/2.;
01140             MidPoint_Y_foll = (top_left_G.y() + top_rightG.y())/2.;
01141             MidPoint_Z_foll = (top_left_G.z() + top_rightG.z())/2.;
01142           }
01143 
01144           //COMPUTE THE B AND T EDGES 
01145           float EdgePoint_X_B = (bot_left_G.x() + bot_rightG.x())/2.;
01146           float EdgePoint_Y_B = (bot_left_G.y() + bot_rightG.y())/2.;
01147           float EdgePoint_Z_B = (bot_left_G.z() + bot_rightG.z())/2.;
01148 
01149           float EdgePoint_X_T = (top_left_G.x() + top_rightG.x())/2.;
01150           float EdgePoint_Y_T = (top_left_G.y() + top_rightG.y())/2.;
01151           float EdgePoint_Z_T = (top_left_G.z() + top_rightG.z())/2.;
01152           // FILL INSIDE WIDTH
01153           float G_width_Ins = sqrt( (MidPoint_X_foll-MidPoint_X_prev)*(MidPoint_X_foll-MidPoint_X_prev) + (MidPoint_Y_foll-MidPoint_Y_prev)*(MidPoint_Y_foll-MidPoint_Y_prev) + (MidPoint_Z_foll-MidPoint_Z_prev)*(MidPoint_Z_foll-MidPoint_Z_prev) );
01154 
01155           //IF BORDER
01156           if (flag_border){
01157 
01158             // A) 3 POINT AND 1 POINT
01159             if (i != 0 && i != LastBinPhi){
01160               m_ModNormPhi[mylabelHisto][i] = m_ModNormPhi[mylabelHisto][i] + factor*G_length*G_width;
01161             }
01162 
01163             // B) MODULE SPLITTED IN TWO
01164             if (i == 0 || i == LastBinPhi){
01165               float PhiBalance = 0.;
01166               if (clustgp.phi() > 0.) PhiBalance = clustgp.phi() - M_PI ;
01167               if (clustgp.phi() < 0.) PhiBalance = clustgp.phi() + M_PI ;
01168 
01169               // Average Phi width of a phi bin
01170               float Phi_Width = m_BinPhi[mylabelHisto][3] - m_BinPhi[mylabelHisto][2];
01171 
01172               float weight_FirstBin = (1.+ (PhiBalance/(Phi_Width/2.)))/2. ;
01173               float weight_LastBin = fabs(1. - weight_FirstBin);
01174 
01175               m_ModNormPhi[mylabelHisto][0] = m_ModNormPhi[mylabelHisto][0] + weight_FirstBin*(factor*G_length*G_width);
01176               m_ModNormPhi[mylabelHisto][LastBinPhi] = m_ModNormPhi[mylabelHisto][LastBinPhi] + weight_LastBin*(factor*G_length*G_width);
01177             }
01178           }
01179 
01180           if (flag_border == false){
01181 
01182             // A) SURFACE TOTALY CONTAINED IN THE BIN
01183             if (offlimit_prev == false && offlimit_foll == false){
01184               m_ModNormPhi[mylabelHisto][i] = m_ModNormPhi[mylabelHisto][i] + factor*G_length*G_width;
01185             }
01186 
01187             // B) SURFACE CONTAINED IN 2 BINS
01188             if ((offlimit_prev == true && offlimit_foll == false)
01189                 ||(offlimit_prev == false && offlimit_foll == true) ){
01190               float G_width_Out = fabs(G_width - G_width_Ins);
01191 
01192               //FILL INSIDE CELL            
01193               m_ModNormPhi[mylabelHisto][i] = m_ModNormPhi[mylabelHisto][i] + factor*G_width_Ins*G_length;
01194 
01195               //FILL OFF LIMITS CELLS
01196               if (offlimit_prev && i != 0) m_ModNormPhi[mylabelHisto][i-1] = m_ModNormPhi[mylabelHisto][i-1] + factor*G_width_Out*G_length;
01197               if (offlimit_foll && i != LastBinPhi) m_ModNormPhi[mylabelHisto][i+1] = m_ModNormPhi[mylabelHisto][i+1] + factor*G_width_Out*G_length;
01198             }
01199 
01200             // C) SURFACE CONTAINED IN 3 BINS
01201             if (offlimit_prev == true && offlimit_foll == true){
01202 
01203               //COMPUTE OFF LIMITS LENGTHS
01204               float G_width_T =  sqrt( (MidPoint_X_foll-EdgePoint_X_T)*(MidPoint_X_foll-EdgePoint_X_T) + (MidPoint_Y_foll-EdgePoint_Y_T)*(MidPoint_Y_foll-EdgePoint_Y_T) + (MidPoint_Z_foll-EdgePoint_Z_T)*(MidPoint_Z_foll-EdgePoint_Z_T) );
01205               float G_width_B =  sqrt( (MidPoint_X_prev-EdgePoint_X_B)*(MidPoint_X_prev-EdgePoint_X_B) + (MidPoint_Y_prev-EdgePoint_Y_B)*(MidPoint_Y_prev-EdgePoint_Y_B) + (MidPoint_Z_prev-EdgePoint_Z_B)*(MidPoint_Z_prev-EdgePoint_Z_B) );
01206 
01207               //FOR SAFETY
01208               if (i != 0 && i != LastBinPhi){
01209                 //FILL INSIDE CELL          
01210                 m_ModNormPhi[mylabelHisto][i] = m_ModNormPhi[mylabelHisto][i] + factor*G_width_Ins*G_length;
01211 
01212                 //FILL OFF LIMITS CELLS
01213                 if (i != 0) m_ModNormPhi[mylabelHisto][i-1] = m_ModNormPhi[mylabelHisto][i-1] + factor*G_width_B*G_length;
01214                 if (i != LastBinPhi) m_ModNormPhi[mylabelHisto][i+1] = m_ModNormPhi[mylabelHisto][i+1] + factor*G_width_T*G_length;
01215               }
01216 
01217             }
01218           }
01219         }
01220       } // END PHI
01221 
01222     } // END SISTRIP DETECTORS
01223 
01224   } // END DETID LOOP
01225 
01226   //PRINT NORMALIZATION IF ASKED
01227   if (printNormalize_) {
01228     TFile output("MuonHLTDQMNormalization.root","recreate");
01229     output.cd();
01230     PrintNormalization(v_LabelHisto);
01231     output.Close();
01232   }
01233 
01234 } //END METHOD
01235 
01236 
01237 
01238 void
01239 SiStripMonitorMuonHLT::PrintNormalization (std::vector<std::string> v_LabelHisto)
01240 {
01241   std::vector <TH1F *> h_ModNorm_Eta;
01242   std::vector <TH1F *> h_ModNorm_Phi;
01243 
01244   for (unsigned int p = 0; p < v_LabelHisto.size(); p++){
01245    
01246     std::string titleHistoEta = v_LabelHisto[p] + "_eta" ;    
01247     std::string titleHistoPhi = v_LabelHisto[p] + "_phi" ;  
01248 
01249     std::string labelHisto = v_LabelHisto[p];
01250     
01251     float * xbinsPhi = new float[100];
01252     float * xbinsEta = new float[100];
01253 
01254     //CREATING XBIN VECTOR
01255     unsigned int sizePhi = m_BinPhi[labelHisto].size();
01256     for (unsigned int i = 0; i < sizePhi; i++){
01257       xbinsPhi[i] = m_BinPhi[labelHisto][i];
01258     }
01259     //CREATING XBIN VECTOR
01260     unsigned int sizeEta = m_BinEta[labelHisto].size();
01261     for (unsigned int i = 0; i < sizeEta; i++){
01262       xbinsEta[i] = m_BinEta[labelHisto][i];
01263     }
01264        
01265     h_ModNorm_Eta.push_back(new TH1F (titleHistoEta.c_str(),titleHistoEta.c_str(),sizeEta - 1,xbinsEta));
01266     h_ModNorm_Phi.push_back(new TH1F (titleHistoPhi.c_str(),titleHistoPhi.c_str(),sizePhi - 1,xbinsPhi));
01267     
01268     for (unsigned int i = 0; i < m_ModNormEta[labelHisto].size(); i++){
01269       (*h_ModNorm_Eta[p]).SetBinContent(i+1,m_ModNormEta[labelHisto][i]);
01270     }
01271     for (unsigned int i = 0; i < m_ModNormPhi[labelHisto].size(); i++){
01272       (*h_ModNorm_Phi[p]).SetBinContent(i+1,m_ModNormPhi[labelHisto][i]);
01273     }
01274 
01275     (*h_ModNorm_Eta[p]).Write();
01276     (*h_ModNorm_Phi[p]).Write();
01277   }
01278     
01279 } 
01280 
01281 
01282 // ------------ method called once each job just before starting event loop  ------------
01283 void
01284 SiStripMonitorMuonHLT::beginRun (const edm::Run& run, const edm::EventSetup & es)
01285 {
01286   if (dbe_)
01287     {
01288       if (monitorName_ != "")
01289         monitorName_ = monitorName_ + "/";
01290       edm::LogInfo ("HLTMuonDQMSource") << "===>DQM event prescale = " << prescaleEvt_ << " events " << std::endl;
01291       createMEs (es);
01292       //create TKHistoMap
01293       if(runOnClusters_)
01294         tkmapAllClusters = new TkHistoMap("HLT/HLTMonMuon/SiStrip" ,"TkHMap_AllClusters",0.0,0);
01295       if(runOnTracks_)
01296         tkmapOnTrackClusters = new TkHistoMap("HLT/HLTMonMuon/SiStrip" ,"TkHMap_OnTrackClusters",0.0,0);
01297       if(runOnMuonCandidates_)
01298         tkmapL3MuTrackClusters = new TkHistoMap("HLT/HLTMonMuon/SiStrip" ,"TkHMap_L3MuTrackClusters",0.0,0);
01299     }
01300 }
01301 
01302 // ------------ method called once each job just after ending the event loop  ------------
01303 void
01304 SiStripMonitorMuonHLT::endJob ()
01305 {
01306   edm::LogInfo ("SiStripMonitorHLTMuon") << "analyzed " << counterEvt_ << " events";
01307   return;
01308 }
01309 
01310 DEFINE_FWK_MODULE(SiStripMonitorMuonHLT);