CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DQM/SiPixelMonitorClient/src/SiPixelMuonHLT.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    SiPixelMuonHLT
00004 // Class:      SiPixelMuonHLT
00005 // 
00013 
00014 //
00015 // Original Author:  Dan Duggan
00016 //         Created:  
00017 // $Id: SiPixelMuonHLT.cc,v 1.8 2010/04/28 09:46:47 duggan Exp $
00018 //
00020 #include "DQM/SiPixelMonitorClient/interface/SiPixelMuonHLT.h"
00021 #include <string>
00022 #include <stdlib.h>
00023 
00024 SiPixelMuonHLT::SiPixelMuonHLT(const edm::ParameterSet& iConfig) :
00025   conf_(iConfig)
00026 {
00027 
00028   parameters_ = iConfig;
00029 
00030   verbose_ = parameters_.getUntrackedParameter < bool > ("verbose", false);
00031   monitorName_ = parameters_.getUntrackedParameter < std::string > ("monitorName", "HLT/HLTMonMuon");
00032   saveOUTput_  = parameters_.getUntrackedParameter < bool > ("saveOUTput", true);
00033 
00034   //tags
00035   clusterCollectionTag_ = parameters_.getUntrackedParameter < edm::InputTag > ("clusterCollectionTag", edm::InputTag ("hltSiPixelClusters"));
00036   rechitsCollectionTag_ = parameters_.getUntrackedParameter < edm::InputTag > ("rechitsCollectionTag", edm::InputTag ("hltSiPixelRecHits"));
00037   l3MuonCollectionTag_  = parameters_.getUntrackedParameter < edm::InputTag > ("l3MuonCollectionTag", edm::InputTag ("hltL3MuonCandidates"));
00039 
00040    theDMBE = edm::Service<DQMStore>().operator->();
00041    edm::LogInfo ("PixelHLTDQM") << "SiPixelMuonHLT::SiPixelMuonHLT: Got DQM BackEnd interface"<<std::endl;
00042    outputFile_ = parameters_.getUntrackedParameter < std::string > ("outputFile", "");
00043    if (outputFile_.size () != 0)
00044      edm::LogWarning ("HLTMuonDQMSource") << "Muon HLT Monitoring histograms will be saved to " << outputFile_ << std::endl;
00045    else
00046      outputFile_ = "PixelHLTDQM.root";
00048    if (theDMBE != NULL) theDMBE->setCurrentFolder (monitorName_); 
00049    SiPixelMuonHLT::Histo_init();
00050    
00051 }
00052 
00053 SiPixelMuonHLT::~SiPixelMuonHLT()
00054 {
00055    // do anything here that needs to be done at desctruction time
00056    // (e.g. close files, deallocate resources etc.)
00057   edm::LogInfo ("PixelHLTDQM") << "SiPixelMuonHLT::~SiPixelMuonHLT: Destructor"<<std::endl;
00058 
00059 }
00060 
00061 void SiPixelMuonHLT::beginJob(){
00062 
00063   edm::LogInfo ("PixelHLTDQM") << " SiPixelMuonHLT::beginJob - Initialisation ... " << std::endl;
00064   eventNo = 0;
00065 
00066 }
00067 
00068 
00069 void SiPixelMuonHLT::endJob(void){
00070   if(saveOUTput_){
00071     edm::LogInfo ("PixelHLTDQM") << " SiPixelMuonHLT::endJob - Saving Root File " << std::endl;
00072     theDMBE->save( outputFile_.c_str() );
00073   }
00074 }
00075 
00076 //------------------------------------------------------------------
00077 // Method called for every event
00078 //------------------------------------------------------------------
00079 void SiPixelMuonHLT::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00080 {
00081   eventNo++;
00082 
00083   edm::ESHandle < TrackerGeometry > TG;
00084   iSetup.get < TrackerDigiGeometryRecord > ().get (TG);
00085   const TrackerGeometry *theTrackerGeometry = TG.product ();
00086   const TrackerGeometry & theTracker (*theTrackerGeometry);
00087   edm::Handle < reco::RecoChargedCandidateCollection > l3mucands;
00088   reco::RecoChargedCandidateCollection::const_iterator cand;
00089   edm::Handle <edmNew::DetSetVector<SiPixelCluster> > clusters;
00090   edm::Handle <edmNew::DetSetVector<SiPixelRecHit> > rechits;
00091 
00092   bool GotClusters = true;
00093   bool GotRecHits  = true;
00094   bool GotL3Muons  = true;
00095   
00096   iEvent.getByLabel("hltSiPixelClusters", clusters);
00097   if(!clusters.isValid()){
00098     edm::LogInfo("PixelHLTDQM") << "No pix clusters, cannot run for event " << iEvent.eventAuxiliary ().event() <<" run: "<<iEvent.eventAuxiliary ().run()  << std::endl;
00099     GotClusters = false;
00100   }
00101   iEvent.getByLabel("hltSiPixelRecHits", rechits);
00102   if(!rechits.isValid()){
00103     edm::LogInfo("PixelHLTDQM") << "No pix rechits, cannot run for event " << iEvent.eventAuxiliary ().event() <<" run: "<<iEvent.eventAuxiliary ().run()  << std::endl;
00104     GotRecHits = false;
00105   }
00106   iEvent.getByLabel (l3MuonCollectionTag_, l3mucands);
00107   if(!l3mucands.isValid()){
00108     edm::LogInfo("PixelHLTDQM") << "No L3 Muons, cannot run for event " << iEvent.eventAuxiliary ().event() <<" run: "<<iEvent.eventAuxiliary ().run()  << std::endl;
00109     GotL3Muons = false;
00110   }
00111   
00112   if (GotClusters){
00113     if(!clusters.failedToGet ())
00114       {
00115         int NBarrel[4] = {0,0,0,0};
00116         int NEndcap[5] = {0,0,0,0,0};
00117         for (size_t i = 0; i < clusters->size(); ++i){ 
00118           const SiPixelCluster* clust = clusters->data(i);
00119           clust->charge();
00121           uint detID = clusters->id(i);
00122           const PixelGeomDetUnit *PixGeom = dynamic_cast < const PixelGeomDetUnit * >(theTracker.idToDet (detID));
00123           const PixelTopology *topol = dynamic_cast < const PixelTopology * >(&(PixGeom->specificTopology ()));
00124           // get the cluster position in local coordinates (cm)
00125           LocalPoint clustlp = topol->localPosition (MeasurementPoint(clust->x(),clust->y()));
00126           GlobalPoint clustgp = PixGeom->surface ().toGlobal (clustlp);
00127           if(PixGeom->geographicalId().subdetId() == 1){ //1 Defines a barrel hit
00128             int clustLay = PXBDetId(detID).layer();
00129             //Eta-Phi
00130             MEContainerAllBarrelEtaPhi[0]->Fill(clustgp.eta(),clustgp.phi());
00131             MEContainerAllBarrelZPhi[0]->Fill(clustgp.z(),clustgp.phi());
00132             MEContainerAllBarrelEtaPhi[clustLay]->Fill(clustgp.eta(),clustgp.phi());
00133             MEContainerAllBarrelZPhi[clustLay]->Fill(clustgp.z(),clustgp.phi());
00134             //Eta
00135             MEContainerAllBarrelEta[0]->Fill(clustgp.eta());
00136             MEContainerAllBarrelZ[0]->Fill(clustgp.z());
00137             MEContainerAllBarrelEta[clustLay]->Fill(clustgp.eta());
00138             MEContainerAllBarrelZ[clustLay]->Fill(clustgp.z());
00139             //Phi
00140             MEContainerAllBarrelPhi[0]->Fill(clustgp.phi());
00141             MEContainerAllBarrelPhi[clustLay]->Fill(clustgp.phi());
00142             ++NBarrel[0]; //N clusters all layers
00143             ++NBarrel[clustLay]; //N clusters all layers
00144           }
00146           if(PixGeom->geographicalId().subdetId() == 2){ //2 Defines a Endcap hit
00147             int clustDisk  = PXFDetId(detID).disk();
00148             if( PXFDetId(detID).side() == 2)
00149               clustDisk = clustDisk +2;//neg z disks have ID 3 and 4
00150             MEContainerAllEndcapXY[0]->Fill(clustgp.x(),clustgp.y());
00151             MEContainerAllEndcapXY[clustDisk]->Fill(clustgp.x(),clustgp.y());
00152             MEContainerAllEndcapPhi[0]->Fill(clustgp.phi());
00153             MEContainerAllEndcapPhi[clustDisk]->Fill(clustgp.phi());
00154             ++NEndcap[0];
00155             ++NEndcap[clustDisk];
00156           }
00157           
00158         }
00159         MEContainerAllBarrelN[0]->Fill(NBarrel[0]);
00160         for (int lay = 1; lay < 4; ++lay)
00161           MEContainerAllBarrelN[lay]->Fill(NBarrel[lay]);
00162         MEContainerAllEndcapN[0]->Fill(NEndcap[0]);
00163         for (int disk = 1; disk < 5; ++disk)
00164           MEContainerAllEndcapN[disk]->Fill(NEndcap[disk]); 
00165       }//if clust (!failedToGet)
00166   }
00167   bool doRecHits = false;
00168   
00169   if (GotRecHits && doRecHits){
00170     if(!rechits.failedToGet ())
00171       {
00172         for (size_t i = 0; i < rechits->size(); ++i){ 
00173           const SiPixelRecHit* myhit = rechits->data(i);
00174           uint detID = rechits->id(i);
00175           const PixelGeomDetUnit *PixGeom = dynamic_cast < const PixelGeomDetUnit * >(theTracker.idToDet (detID));
00176           //edm::LogInfo("PixelHLTDQM") << "" << PixGeom->geographicalId().subdetId() << std::endl;
00177           //const PixelTopology *topol = dynamic_cast < const PixelTopology * >(&(PixGeom->specificTopology ()));
00178           // get the hit position in local coordinates (cm)
00179           //LocalPoint hitlp = topol->localPosition (MeasurementPoint(myhit->x(),myhit->y()));
00180           if(PixGeom->geographicalId().subdetId() == 1 && myhit->hasPositionAndError()){
00181             GlobalPoint hitgp = PixGeom->surface ().toGlobal (myhit->localPosition());
00182             edm::LogInfo("PixelHLTDQM") << " (From SiPixelRecHit) Hit Eta: " << hitgp.eta()   << " Hit Phi: " << hitgp.phi()  << std::endl;
00183           }
00184         }      
00185       }
00186   }
00187   if(GotL3Muons){
00188     if(!l3mucands.failedToGet ())
00189       {
00190         int NBarrel[4] = {0,0,0,0};
00191         int NEndcap[5] = {0,0,0,0,0};
00192         for (cand = l3mucands->begin (); cand != l3mucands->end (); ++cand){
00193           reco::TrackRef l3tk = cand->get < reco::TrackRef > ();
00194           for (size_t hit = 0; hit < l3tk->recHitsSize (); hit++){
00195             if (l3tk->recHit (hit)->isValid () == true && l3tk->recHit (hit)->geographicalId ().det () == DetId::Tracker){
00196               int detID = l3tk->recHit(hit)->geographicalId().rawId();
00197               //if hit is in pixel detector say true
00198               bool IdMatch = typeid(*(l3tk->recHit(hit))) == typeid(SiPixelRecHit);
00199               if (IdMatch){
00200                 const SiPixelRecHit *pixhit = dynamic_cast < const SiPixelRecHit * >(l3tk->recHit(hit).get());
00201                 if((*pixhit).isValid() == true){
00202                   edm::Ref<edmNew::DetSetVector<SiPixelCluster>, SiPixelCluster> const& pixclust = (*pixhit).cluster();
00203                   if (!(*pixhit).cluster().isAvailable()) 
00204                     {continue;}
00205                   const PixelGeomDetUnit *PixGeom = dynamic_cast < const PixelGeomDetUnit * >(theTracker.idToDet (detID));
00206                   const PixelTopology *topol = dynamic_cast < const PixelTopology * >(&(PixGeom->specificTopology ()));
00207                   LocalPoint clustlp = topol->localPosition (MeasurementPoint(pixclust->x(),pixclust->y()));
00208                   GlobalPoint clustgp = PixGeom->surface ().toGlobal (clustlp);
00209                   if(l3tk->recHit(hit)->geographicalId().subdetId() == 1){ //1 Defines a barrel hit
00210                     //get the cluster position in local coordinates (cm)          
00211                     int clustLay = PXBDetId(detID).layer();
00212                     MEContainerOnTrackBarrelEtaPhi[0]->Fill(clustgp.eta(),clustgp.phi());
00213                     MEContainerOnTrackBarrelZPhi[0]->Fill(clustgp.z(),clustgp.phi());
00214                     MEContainerOnTrackBarrelEtaPhi[clustLay]->Fill(clustgp.eta(),clustgp.phi());
00215                     MEContainerOnTrackBarrelZPhi[clustLay]->Fill(clustgp.z(),clustgp.phi());
00216                     MEContainerOnTrackBarrelEta[0]->Fill(clustgp.eta());
00217                     MEContainerOnTrackBarrelZ[0]->Fill(clustgp.z());
00218                     MEContainerOnTrackBarrelEta[clustLay]->Fill(clustgp.eta());
00219                     MEContainerOnTrackBarrelZ[clustLay]->Fill(clustgp.z());
00220                     MEContainerOnTrackBarrelPhi[0]->Fill(clustgp.phi());
00221                     MEContainerOnTrackBarrelPhi[clustLay]->Fill(clustgp.phi());
00222                     ++NBarrel[0];
00223                     ++NBarrel[clustLay];
00224                   }//subdet ==1
00225                   if(l3tk->recHit(hit)->geographicalId().subdetId() == 2){ //2 Defines a Endcap hit
00226                     int clustDisk  = PXFDetId(detID).disk();
00227                     if( PXFDetId(detID).disk() == 2)
00228                       clustDisk = clustDisk +2;
00229                     MEContainerOnTrackEndcapXY[0]->Fill(clustgp.x(),clustgp.y());
00230                     MEContainerOnTrackEndcapXY[clustDisk]->Fill(clustgp.x(),clustgp.y());
00231                     MEContainerOnTrackEndcapPhi[0]->Fill(clustgp.phi());
00232                     MEContainerOnTrackEndcapPhi[clustDisk]->Fill(clustgp.phi());
00233                     ++NEndcap[0];
00234                     ++NEndcap[clustDisk];
00235                   }//subdet ==2
00236                 }//pixhit valid
00237               }//typeid match
00238             }//l3tk->recHit (hit)->isValid () == true
00239           }//loop over RecHits
00240         }//loop over l3mucands
00241         MEContainerOnTrackBarrelN[0]->Fill(NBarrel[0]);
00242         for (int lay = 1; lay < 4; ++lay)
00243           MEContainerOnTrackBarrelN[lay]->Fill(NBarrel[lay]);
00244         MEContainerOnTrackEndcapN[0]->Fill(NEndcap[0]);
00245         for (int disk = 1; disk < 5; ++disk)
00246           MEContainerOnTrackEndcapN[disk]->Fill(NEndcap[disk]);
00247         
00248       }//if l3mucands  
00249   }
00250 }
00251 
00252 void SiPixelMuonHLT::Histo_init()
00253 {
00254    monitorName_ = monitorName_+"/SiPixel";
00255    int NBinsEta = 100;
00256    int NBinsPhi = 80;
00257    float EtaMax = 3.0;
00258    float ZMax   = 28.0;
00259    int NBinsZ   = 112;
00260    float PhiMax = 3.142;
00261    int   NBinsN = 800;
00262    float NMax   = 800.;
00263    int   NBinsX = 100;
00264    int   NBinsY = 100;
00265    float XMax   = 20.;
00266    float YMax   = 20.;
00267    std::string histoname;
00268    std::string title;
00269 
00270    theDMBE->setCurrentFolder (monitorName_ + "/Barrel");   
00271    std::string layerLabel[4] = {"All_Layers", "Layer1", "Layer2", "Layer3"};
00272    for (unsigned int i = 0; i < 4; i++)
00273      {
00276        //Eta-Phi
00277        histoname = "EtaPhiAllBarrelMap_" + layerLabel[i];
00278        title     = "#eta-#phi Pixel Barrel Cluster Occupancy Map for " + layerLabel[i];
00279        MEContainerAllBarrelEtaPhi[i] = theDMBE->book2D (histoname, title, NBinsEta, -EtaMax, EtaMax, NBinsPhi, -PhiMax, PhiMax);
00280        //Z-Phi
00281        histoname = "ZPhiAllBarrelMap_" + layerLabel[i];
00282        title     = "Z-#phi Pixel Barrel Cluster Occupancy Map for " + layerLabel[i];
00283        MEContainerAllBarrelZPhi[i] = theDMBE->book2D (histoname, title, NBinsZ, -ZMax, ZMax, NBinsPhi, -PhiMax, PhiMax);
00284        //Eta
00285        histoname = "EtaAllBarrelMap_" + layerLabel[i];
00286        title     = "#eta Pixel Barrel Cluster Occupancy Map for " + layerLabel[i];
00287        MEContainerAllBarrelEta[i] = theDMBE->book1D (histoname, title, NBinsEta, -EtaMax, EtaMax);
00288        //Z
00289        histoname = "ZAllBarrelMap_" + layerLabel[i];
00290        title     = "Z Pixel Barrel Cluster Occupancy Map for " + layerLabel[i];
00291        MEContainerAllBarrelZ[i] = theDMBE->book1D (histoname, title, NBinsZ, -ZMax, ZMax);
00292        //Phi
00293        histoname = "PhiAllBarrelMap_" + layerLabel[i];
00294        title     = "#phi Pixel Barrel Cluster Occupancy Map for " + layerLabel[i];
00295        MEContainerAllBarrelPhi[i] = theDMBE->book1D (histoname, title, NBinsPhi, -PhiMax, PhiMax);
00296        //N clusters
00297        histoname = "NAllBarrelMap_" + layerLabel[i];
00298        title     = "#phi Pixel Barrel Cluster Occupancy Map for " + layerLabel[i];
00299        MEContainerAllBarrelN[i] = theDMBE->book1D (histoname, title, NBinsN, 0, NMax);
00302        //Eta-Phi
00303        histoname = "EtaPhiOnTrackBarrelMap_" + layerLabel[i];
00304        title = "#eta-#phi On Track Pixel Barrel Cluster Occupancy Map for " + layerLabel[i];
00305        MEContainerOnTrackBarrelEtaPhi[i] = theDMBE->book2D (histoname, title, NBinsEta, -EtaMax, EtaMax, NBinsPhi, -PhiMax, PhiMax);
00306        //Z-Phi
00307        histoname = "ZPhiOnTrackBarrelMap_" + layerLabel[i];
00308        title = "Z-#phi On Track Pixel Barrel Cluster Occupancy Map for " + layerLabel[i];
00309        MEContainerOnTrackBarrelZPhi[i] = theDMBE->book2D (histoname, title, NBinsZ, -ZMax, ZMax, NBinsPhi, -PhiMax, PhiMax);
00310        //Eta
00311        histoname = "EtaOnTrackBarrelMap_" + layerLabel[i];
00312        title     = "#eta On Track Pixel Barrel Cluster Occupancy Map for " + layerLabel[i];
00313        MEContainerOnTrackBarrelEta[i] = theDMBE->book1D (histoname, title, NBinsEta, -EtaMax, EtaMax);
00314        //Z
00315        histoname = "ZOnTrackBarrelMap_" + layerLabel[i];
00316        title     = "Z On Track Pixel Barrel Cluster Occupancy Map for " + layerLabel[i];
00317        MEContainerOnTrackBarrelZ[i] = theDMBE->book1D (histoname, title, NBinsZ, -ZMax, ZMax);
00318        //Phi
00319        histoname = "PhiOnTrackBarrelMap_" + layerLabel[i];
00320        title     = "#phi On Track Pixel Barrel Cluster Occupancy Map for " + layerLabel[i];
00321        MEContainerOnTrackBarrelPhi[i] = theDMBE->book1D (histoname, title, NBinsPhi, -PhiMax, PhiMax);
00322        //N clusters
00323        histoname = "NOnTrackBarrelMap_" + layerLabel[i];
00324        title     = "N_{Clusters} On Track Pixel Barrel Cluster Occupancy Map for " + layerLabel[i];
00325        MEContainerOnTrackBarrelN[i] = theDMBE->book1D (histoname, title, NBinsN, 0, NMax);
00326      }
00327 
00328    theDMBE->setCurrentFolder (monitorName_ + "/EndCap");
00329    std::string diskLabel[5] = {"All_Disks", "InnerPosZ", "OuterPosZ", "InnerNegZ", "OuterNegZ"};
00330    for (int i = 0;i < 5; ++i) 
00331      {
00334        //XY
00335        histoname = "XYAllEndcapMap_" + diskLabel[i];
00336        title     = "X-Y Pixel Endcap Cluster Occupancy Map for " + diskLabel[i];
00337        MEContainerAllEndcapXY[i] = theDMBE->book2D (histoname, title, NBinsX, -XMax, XMax, NBinsY, -YMax, YMax);
00338        //Phi
00339        histoname = "PhiAllEndcapMap_" + diskLabel[i];
00340        title     = "#phi Pixel Endcap Cluster Occupancy Map for " + diskLabel[i];
00341        MEContainerAllEndcapPhi[i] = theDMBE->book1D (histoname, title, NBinsPhi, -PhiMax, PhiMax);
00342        //N clusters
00343        histoname = "NAllEndcapMap_" + diskLabel[i];
00344        title     = "#phi Pixel Endcap Cluster Occupancy Map for " + diskLabel[i];
00345        MEContainerAllEndcapN[i] = theDMBE->book1D (histoname, title, NBinsN, 0, NMax);
00348        //XY
00349        histoname = "XYOnTrackEndcapMap_" + diskLabel[i];
00350        title     = "X-Y Pixel Endcap On Track Cluster Occupancy Map for " + diskLabel[i];
00351        MEContainerOnTrackEndcapXY[i] = theDMBE->book2D (histoname, title, NBinsX, -XMax, XMax, NBinsY, -YMax, YMax);
00352        //Phi
00353        histoname = "PhiOnTrackEndcapMap_" + diskLabel[i];
00354        title     = "#phi Pixel Endcap On Track Cluster Occupancy Map for " + diskLabel[i];
00355        MEContainerOnTrackEndcapPhi[i] = theDMBE->book1D (histoname, title, NBinsPhi, -PhiMax, PhiMax);
00356        //N clusters
00357        histoname = "NOnTrackEndcapMap_" + diskLabel[i];
00358        title     = "#phi Pixel Endcap On Track Cluster Occupancy Map for " + diskLabel[i];
00359        MEContainerOnTrackEndcapN[i] = theDMBE->book1D (histoname, title, NBinsN, 0, NMax);
00360    }
00361    return;
00362 }
00363 
00364 //define this as a plug-in
00365 DEFINE_FWK_MODULE(SiPixelMuonHLT);