CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/DQM/TrackingMonitor/src/dEdxAnalyzer.cc

Go to the documentation of this file.
00001 /*
00002  *  See header file for a description of this class.
00003  *
00004  *  $Date: 2012/10/16 10:07:42 $
00005  *  $Revision: 1.3 $
00006  *  \author Loic Quertenmont 
00007  */
00008 #include "DQM/TrackingMonitor/interface/dEdxAnalyzer.h"
00009 
00010 #include "DataFormats/TrackReco/interface/DeDxData.h"
00011 #include "DataFormats/TrackReco/interface/Track.h"
00012 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00013 
00014 #include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h"
00015 #include "TrackingTools/Records/interface/TransientTrackRecord.h"
00016 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
00017 #include "MagneticField/Engine/interface/MagneticField.h"
00018 
00019 #include "CommonTools/TriggerUtils/interface/GenericTriggerEventFlag.h"
00020 
00021 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00022 #include "FWCore/Utilities/interface/InputTag.h"
00023 #include "DQMServices/Core/interface/DQMStore.h"
00024 
00025 #include <string>
00026 #include "TMath.h"
00027 
00028 dEdxAnalyzer::dEdxAnalyzer(const edm::ParameterSet& iConfig) 
00029   : dqmStore_( edm::Service<DQMStore>().operator->() )
00030   , fullconf_( iConfig )
00031   , conf_    (fullconf_.getParameter<edm::ParameterSet>("dEdxParameters") )
00032   , doAllPlots_  ( conf_.getParameter<bool>("doAllPlots") )
00033   , doDeDxPlots_ ( conf_.getParameter<bool>("doDeDxPlots") )    
00034   , genTriggerEventFlag_( new GenericTriggerEventFlag(conf_) )
00035 {
00036 }
00037 
00038 dEdxAnalyzer::~dEdxAnalyzer() 
00039 { 
00040 
00041   if (genTriggerEventFlag_)      delete genTriggerEventFlag_;
00042 }
00043 
00044 // ------------ method called once each job just after ending the event loop  ------------
00045 void 
00046 dEdxAnalyzer::endJob() 
00047 {
00048     bool outputMEsInRootFile   = conf_.getParameter<bool>("OutputMEsInRootFile");
00049     std::string outputFileName = conf_.getParameter<std::string>("OutputFileName");
00050     if(outputMEsInRootFile)
00051     {
00052         dqmStore_->showDirStructure();
00053         dqmStore_->save(outputFileName);
00054     }
00055 }
00056 
00057 // -- BeginRun
00058 //---------------------------------------------------------------------------------//
00059 void dEdxAnalyzer::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup)
00060 {
00061  
00062   // Initialize the GenericTriggerEventFlag
00063   if ( genTriggerEventFlag_->on() ) genTriggerEventFlag_->initRun( iRun, iSetup );
00064 }
00065 
00066 
00067 void dEdxAnalyzer::beginJob()
00068 {
00069     // parameters from the configuration
00070     AlgoNames                  = conf_.getParameter<std::vector<std::string> >("deDxProducers");
00071     TrackName                  = conf_.getParameter<std::string>("TracksForDeDx");
00072     std::string MEFolderName   = conf_.getParameter<std::string>("FolderName"); 
00073 
00074     // get binning from the configuration
00075     TrackHitMin  = conf_.getParameter<double>("TrackHitMin");
00076     HIPdEdxMin   = conf_.getParameter<double>("HIPdEdxMin");
00077 
00078     dEdxK      = conf_.getParameter<double>("dEdxK");
00079     dEdxC      = conf_.getParameter<double>("dEdxC");
00080 
00081 
00082     int    dEdxNHitBin     = conf_.getParameter<int>(   "dEdxNHitBin");
00083     double dEdxNHitMin     = conf_.getParameter<double>("dEdxNHitMin");
00084     double dEdxNHitMax     = conf_.getParameter<double>("dEdxNHitMax");
00085 
00086     int    dEdxBin      = conf_.getParameter<int>(   "dEdxBin");
00087     double dEdxMin      = conf_.getParameter<double>("dEdxMin");
00088     double dEdxMax      = conf_.getParameter<double>("dEdxMax");
00089 
00090     int    dEdxHIPmassBin  = conf_.getParameter<int>(   "dEdxHIPmassBin");
00091     double dEdxHIPmassMin  = conf_.getParameter<double>("dEdxHIPmassMin"); 
00092     double dEdxHIPmassMax  = conf_.getParameter<double>("dEdxHIPmassMax");
00093 
00094     int    dEdxMIPmassBin  = conf_.getParameter<int>(   "dEdxMIPmassBin");
00095     double dEdxMIPmassMin  = conf_.getParameter<double>("dEdxMIPmassMin"); 
00096     double dEdxMIPmassMax  = conf_.getParameter<double>("dEdxMIPmassMax");
00097 
00098     dqmStore_->setCurrentFolder(MEFolderName);
00099 
00100     // book the Hit Property histograms
00101     // ---------------------------------------------------------------------------------//
00102 
00103     if ( doDeDxPlots_ || doAllPlots_ ){
00104       for(unsigned int i=0;i<AlgoNames.size();i++){
00105          dqmStore_->setCurrentFolder(MEFolderName+"/"+ AlgoNames[i]);
00106          dEdxMEsVector.push_back(dEdxMEs() );
00107 
00108          histname = "MIP_dEdxPerTrack_"; 
00109          dEdxMEsVector[i].ME_MipDeDx = dqmStore_->book1D(histname, histname, dEdxBin, dEdxMin, dEdxMax);
00110          dEdxMEsVector[i].ME_MipDeDx->setAxisTitle("dEdx of each MIP Track (MeV/cm)");
00111          dEdxMEsVector[i].ME_MipDeDx->setAxisTitle("Number of Tracks", 2);
00112 
00113          histname =  "MIP_NumberOfdEdxHitsPerTrack_";
00114          dEdxMEsVector[i].ME_MipDeDxNHits = dqmStore_->book1D(histname, histname, dEdxNHitBin, dEdxNHitMin, dEdxNHitMax);
00115          dEdxMEsVector[i].ME_MipDeDxNHits->setAxisTitle("Number of dEdxHits of each MIP Track");
00116          dEdxMEsVector[i].ME_MipDeDxNHits->setAxisTitle("Number of Tracks", 2);
00117 
00118          histname =  "MIP_FractionOfSaturateddEdxHitsPerTrack_"; 
00119          dEdxMEsVector[i].ME_MipDeDxNSatHits = dqmStore_->book1D(histname, histname,2*dEdxNHitBin, 0, 1);
00120          dEdxMEsVector[i].ME_MipDeDxNSatHits->setAxisTitle("Fraction of Saturated dEdxHits of each MIP Track");
00121          dEdxMEsVector[i].ME_MipDeDxNSatHits->setAxisTitle("Number of Tracks", 2);
00122 
00123          histname =  "MIP_MassPerTrack_";
00124          dEdxMEsVector[i].ME_MipDeDxMass = dqmStore_->book1D(histname, histname, dEdxMIPmassBin, dEdxMIPmassMin, dEdxMIPmassMax);
00125          dEdxMEsVector[i].ME_MipDeDxMass->setAxisTitle("dEdx Mass of each MIP Track (GeV/c^{2})");
00126          dEdxMEsVector[i].ME_MipDeDxMass->setAxisTitle("Number of Tracks", 2);
00127 
00128          histname =  "HIP_MassPerTrack_";
00129          dEdxMEsVector[i].ME_HipDeDxMass = dqmStore_->book1D(histname, histname, dEdxHIPmassBin, dEdxHIPmassMin, dEdxHIPmassMax);
00130          dEdxMEsVector[i].ME_HipDeDxMass->setAxisTitle("dEdx Mass of each HIP Track (GeV/c^{2})");
00131          dEdxMEsVector[i].ME_HipDeDxMass->setAxisTitle("Number of Tracks", 2);
00132 
00133        }
00134     }
00135 }
00136 
00137 
00138 double dEdxAnalyzer::mass(double P, double I){
00139    if(I-dEdxC<0)return -1;
00140    return sqrt((I-dEdxC)/dEdxK)*P;
00141 }
00142 
00143 // -- Analyse
00144 // ---------------------------------------------------------------------------------//
00145 void dEdxAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00146 {
00147 
00148   // Filter out events if Trigger Filtering is requested
00149   if (genTriggerEventFlag_->on()&& ! genTriggerEventFlag_->accept( iEvent, iSetup) ) return;
00150 
00151 
00152    if ( doDeDxPlots_ || doAllPlots_ ){
00153       edm::Handle<reco::TrackCollection> trackCollectionHandle;
00154       iEvent.getByLabel(TrackName,trackCollectionHandle);
00155       if(!trackCollectionHandle.isValid())return;
00156 
00157 
00158       for(unsigned int i=0;i<AlgoNames.size();i++){
00159          edm::Handle<reco::DeDxDataValueMap> dEdxObjectHandle;
00160          iEvent.getByLabel(AlgoNames[i],dEdxObjectHandle);
00161          if(!dEdxObjectHandle.isValid())continue;
00162          const edm::ValueMap<reco::DeDxData> dEdxColl = *dEdxObjectHandle.product();
00163  
00164               
00165          for(unsigned int t=0; t<trackCollectionHandle->size(); t++){
00166             reco::TrackRef track = reco::TrackRef( trackCollectionHandle, t );
00167 
00168 
00169             if(track->quality(reco::TrackBase::highPurity) ) {
00170               //MIPs  
00171               if( track->pt() >= 5.0 && track->numberOfValidHits()>TrackHitMin){
00172                  dEdxMEsVector[i].ME_MipDeDx        ->Fill(dEdxColl[track].dEdx());
00173                  dEdxMEsVector[i].ME_MipDeDxNHits   ->Fill(dEdxColl[track].numberOfMeasurements());
00174                  if (dEdxColl[track].numberOfMeasurements()!=0)
00175                    dEdxMEsVector[i].ME_MipDeDxNSatHits->Fill((1.0*dEdxColl[track].numberOfSaturatedMeasurements())/dEdxColl[track].numberOfMeasurements());
00176                  dEdxMEsVector[i].ME_MipDeDxMass    ->Fill(mass(track->p(), dEdxColl[track].dEdx()));
00177 
00178               //HighlyIonizing particles
00179               }else if(track->pt()<2 && dEdxColl[track].dEdx()>HIPdEdxMin){
00180                  dEdxMEsVector[i].ME_HipDeDxMass    ->Fill(mass(track->p(), dEdxColl[track].dEdx()));
00181               }
00182             }
00183          }
00184       }
00185    }
00186 }
00187 
00188  
00189 
00190 void 
00191 dEdxAnalyzer::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
00192 {
00193 }
00194 
00195 // ------------ method called when ending the processing of a luminosity block  ------------
00196 void 
00197 dEdxAnalyzer::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
00198 {
00199 }
00200 
00201 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
00202 void
00203 dEdxAnalyzer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
00204   //The following says we do not know what parameters are allowed so do no validation
00205   // Please change this to state exactly what you do use, even if it is no parameters
00206   edm::ParameterSetDescription desc;
00207   desc.setUnknown();
00208   descriptions.addDefault(desc);
00209 }
00210 
00211 DEFINE_FWK_MODULE(dEdxAnalyzer);