CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/DQM/PhysicsObjectsMonitoring/src/PhysicsObjectsMonitor.cc

Go to the documentation of this file.
00001 
00010 #include "DQM/PhysicsObjectsMonitoring/interface/PhysicsObjectsMonitor.h"
00011 
00012 // Collaborating Class Header
00013 #include "FWCore/Framework/interface/MakerMacros.h"
00014 #include "FWCore/Framework/interface/Event.h"
00015 #include "FWCore/Framework/interface/ESHandle.h"
00016 
00017 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00018 
00019 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
00020 #include "DataFormats/TrackReco/interface/Track.h"
00021 #include "RecoMuon/TrackingTools/interface/MuonPatternRecoDumper.h"
00022 
00023 // Not needed for data monitoring! #include "SimDataFormats/Track/interface/SimTrackContainer.h"
00024 #include "DataFormats/MuonDetId/interface/MuonSubdetId.h"
00025 
00026 #include <FWCore/MessageLogger/interface/MessageLogger.h>
00027 #include "DQMServices/Core/interface/DQMStore.h"
00028 #include "DQMServices/Core/interface/MonitorElement.h"
00029 
00030 
00031 using namespace std;
00032 using namespace edm;
00033 
00035 PhysicsObjectsMonitor::PhysicsObjectsMonitor(const ParameterSet& pset){
00036   theSTAMuonLabel = pset.getUntrackedParameter<string>("StandAloneTrackCollectionLabel");
00037   theSeedCollectionLabel = pset.getUntrackedParameter<string>("MuonSeedCollectionLabel");
00038 
00039   theRootFileName = pset.getUntrackedParameter<string>("rootFileName");
00040   saveRootFile = pset.getUntrackedParameter<bool>("produceRootFile");
00041 
00042   theDataType = pset.getUntrackedParameter<string>("DataType");
00043   
00044   if(theDataType != "RealData" && theDataType != "SimData")
00045   edm::LogInfo ("PhysicsObjectsMonitor") <<  "Error in Data Type!!"<<endl;
00046 
00047   numberOfSimTracks=0;
00048   numberOfRecTracks=0;
00049 
00051   dbe = edm::Service<DQMStore>().operator->();
00052   
00053 
00054 
00055 
00056 }
00057 
00059 PhysicsObjectsMonitor::~PhysicsObjectsMonitor(){
00060 }
00061 
00062 void PhysicsObjectsMonitor::beginJob(){
00063 
00064   dbe->setCurrentFolder("PhysicsObjects/MuonReconstruction");           
00065 
00066 
00067   hPres = dbe->book1D("pTRes","pT Resolution",100,-2,2);
00068   h1_Pres =dbe->book1D("invPTRes","1/pT Resolution",100,-2,2);
00069 
00070   charge= dbe->book1D("charge","track charge",5,-2.5,2.5);
00071   ptot = dbe->book1D("ptot","track momentum",50,0,50);
00072   pt = dbe->book1D("pt","track pT",100,0,50);
00073   px = dbe->book1D("px ","track px",100,-50,50);
00074   py = dbe->book1D("py","track py",100,-50,50);
00075   pz = dbe->book1D("pz","track pz",100,-50,50);
00076   Nmuon = dbe->book1D("Nmuon","Number of muon tracks",11,-.5,10.5);
00077   Nrechits = dbe->book1D("Nrechits","Number of RecHits/Segments on track",21,-.5,21.5);
00078   NDThits = dbe->book1D("NDThits","Number of DT Hits/Segments on track",31,-.5,31.5);
00079   NCSChits = dbe->book1D("NCSChits","Number of CSC Hits/Segments on track",31,-.5,31.5);
00080   NRPChits = dbe->book1D("NRPChits","Number of RPC hits on track",11,-.5,11.5);
00081 
00082   DTvsCSC = dbe->book2D("DTvsCSC","Number of DT vs CSC hits on track",29,-.5,28.5,29,-.5,28.5);
00083   TH2F * root_ob = DTvsCSC->getTH2F();
00084   root_ob->SetXTitle("Number of DT hits");
00085   root_ob->SetYTitle("Number of CSC hits");
00086 
00087 }
00088 
00089 void PhysicsObjectsMonitor::endJob(){
00090   
00091  if(theDataType == "SimData"){
00092    //     edm::LogInfo ("PhysicsObjectsMonitor") << "Number of Sim tracks: " << numberOfSimTracks;
00093     edm::LogInfo ("PhysicsObjectsMonitor") << "Sorry! Running this package on simulation is no longer supported! ";
00094   }
00095 
00096   edm::LogInfo ("PhysicsObjectsMonitor") << "Number of Reco tracks: " << numberOfRecTracks ;
00097 
00098   if(saveRootFile) dbe->save(theRootFileName); 
00099   dbe->setCurrentFolder("PhysicsObjects/MuonReconstruction");
00100   dbe->removeContents();
00101 
00102 
00103 }
00104 
00105 
00106 void PhysicsObjectsMonitor::analyze(const Event & event, const EventSetup& eventSetup){
00107   
00108   edm::LogInfo ("PhysicsObjectsMonitor") << "Run: " << event.id().run() << " Event: " << event.id().event();
00109   MuonPatternRecoDumper debug;
00110   
00111   // Get the RecTrack collection from the event
00112   Handle<reco::TrackCollection> staTracks;
00113   event.getByLabel(theSTAMuonLabel, staTracks);
00114 
00115   ESHandle<MagneticField> theMGField;
00116   eventSetup.get<IdealMagneticFieldRecord>().get(theMGField);
00117 
00118   
00119   double recPt=0.;
00120   double simPt=0.;
00121 
00122   // Get the SimTrack collection from the event
00123   //  if(theDataType == "SimData"){
00124   //  Handle<SimTrackContainer> simTracks;
00125   //  event.getByLabel("g4SimHits",simTracks);
00126     
00127   //  numberOfRecTracks += staTracks->size();
00128 
00129   //    SimTrackContainer::const_iterator simTrack;
00130 
00131   //    edm::LogInfo ("PhysicsObjectsMonitor") <<"Simulated tracks: ";
00132   //  for (simTrack = simTracks->begin(); simTrack != simTracks->end(); ++simTrack){
00133   //    if (abs((*simTrack).type()) == 13) {
00134   //      edm::LogInfo ("PhysicsObjectsMonitor") <<     "Sim pT: "<<(*simTrack).momentum().perp()<<endl;
00135   //    simPt=(*simTrack).momentum().perp();
00136   //    edm::LogInfo ("PhysicsObjectsMonitor") <<"Sim Eta: "<<(*simTrack).momentum().eta()<<endl;
00137   //    numberOfSimTracks++;
00138   //   }    
00139   //  }
00140   //  edm::LogInfo ("PhysicsObjectsMonitor") << "\n";
00141   //}
00142   
00143   reco::TrackCollection::const_iterator staTrack;
00144   
00145   edm::LogInfo ("PhysicsObjectsMonitor") << "Reconstructed tracks: " << staTracks->size() << endl;
00146   Nmuon->Fill(staTracks->size());
00147   for (staTrack = staTracks->begin(); staTrack != staTracks->end(); ++staTrack){
00148     reco::TransientTrack track(*staTrack,&*theMGField); 
00149     
00150     int nrechits=0;
00151     int nDThits=0;
00152     int nCSChits=0;
00153     int nRPChits=0;
00154 
00155     for (trackingRecHit_iterator it = track.recHitsBegin ();  it != track.recHitsEnd (); it++) {
00156       if ((*it)->isValid ()) {      
00157         edm::LogInfo ("PhysicsObjectsMonitor") << "Analyzer:  Aha this looks like a Rechit!" << std::endl;
00158         if((*it)->geographicalId().subdetId() == MuonSubdetId::DT) {
00159           nDThits++;
00160         } else if((*it)->geographicalId().subdetId() == MuonSubdetId::CSC) {
00161           nCSChits++;
00162         } else if((*it)->geographicalId().subdetId() == MuonSubdetId::RPC) {
00163           nRPChits++;
00164         } else {
00165          edm::LogInfo ("PhysicsObjectsMonitor") <<  "This is an UNKNOWN hit !! " << std::endl;
00166         }
00167         nrechits++;
00168       }
00169     }
00170                 
00171     Nrechits->Fill(nrechits);
00172     NDThits->Fill(nDThits);
00173     NCSChits->Fill(nCSChits);
00174     DTvsCSC->Fill(nDThits,nCSChits);
00175     NRPChits->Fill(nRPChits);
00176 
00177     debug.dumpFTS(track.impactPointTSCP().theState());
00178     
00179     recPt = track.impactPointTSCP().momentum().perp();    
00180     edm::LogInfo ("PhysicsObjectsMonitor") << " p: "<<track.impactPointTSCP().momentum().mag()<< " pT: "<<recPt<<endl;
00181     pt->Fill(recPt);
00182     ptot->Fill(track.impactPointTSCP().momentum().mag());
00183     charge->Fill(track.impactPointTSCP().charge());
00184     px->Fill(track.impactPointTSCP().momentum().x());
00185     py->Fill(track.impactPointTSCP().momentum().y());
00186     pz->Fill(track.impactPointTSCP().momentum().z());
00187   }
00188   edm::LogInfo ("PhysicsObjectsMonitor") <<"---"<<endl;
00189   if(recPt && theDataType == "SimData"){
00190     hPres->Fill( (recPt-simPt)/simPt);
00191     h1_Pres->Fill( ( 1/recPt - 1/simPt)/ (1/simPt));
00192 
00193   }  
00194 }
00195 
00196 DEFINE_FWK_MODULE(PhysicsObjectsMonitor);