CMS 3D CMS Logo

DTChamberEfficiency.cc

Go to the documentation of this file.
00001 /******* \class DTEffAnalyzer *******
00002  *
00003  * Description:
00004  *  
00005  *  detailed description
00006  *
00007  * \author : Mario Pelliccioni, pellicci@cern.ch
00008  * $date   : 20/11/2008 16:50:57 CET $
00009  *
00010  * Modification:
00011  *
00012  *********************************/
00013 
00014 #include "DTChamberEfficiency.h"
00015 
00016 #include "FWCore/Framework/interface/Event.h"
00017 #include "FWCore/Framework/interface/EventSetup.h"
00018 #include "FWCore/ServiceRegistry/interface/Service.h"
00019 
00020 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00021 
00022 #include "DataFormats/DTRecHit/interface/DTRecSegment4D.h"
00023 #include "DataFormats/MuonDetId/interface/MuonSubdetId.h"
00024 
00025 #include "DQMServices/Core/interface/DQMStore.h"
00026 #include "DQMServices/Core/interface/MonitorElement.h"
00027 
00028 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00029 
00030 #include "RecoMuon/Navigation/interface/DirectMuonNavigation.h"
00031 
00032 #include "TrackingTools/Records/interface/TransientTrackRecord.h"
00033 
00034 #include "TrackPropagation/SteppingHelixPropagator/interface/SteppingHelixPropagator.h"
00035 
00036 #include <iostream>
00037 #include <cmath>
00038 
00039 using namespace std;
00040 using namespace edm;
00041 
00042 DTChamberEfficiency::DTChamberEfficiency(const ParameterSet& pSet)
00043 {
00044 
00045   // Get the debug parameter for verbose output
00046   debug = pSet.getUntrackedParameter<bool>("debug","false");
00047 
00048   if(debug) LogVerbatim("DTDQM|DTMonitorModule|DTChamberEfficiency")
00049               << "DTChamberEfficiency: constructor called";
00050 
00051   // Get the DQM needed services
00052   theDbe = Service<DQMStore>().operator->();
00053   theDbe->setCurrentFolder("DT/05-ChamberEff/Task");
00054 
00055   // service parameters
00056   ParameterSet serviceParameters = pSet.getParameter<ParameterSet>("ServiceParameters");
00057   theService = new MuonServiceProxy(serviceParameters);
00058 
00059   theTracksLabel = pSet.getParameter<InputTag>("TrackCollection");
00060 
00061   theMaxChi2 = static_cast<unsigned int>(pSet.getParameter<double>("theMaxChi2"));
00062   theNSigma = pSet.getParameter<double>("theNSigma");
00063   theMinNrec = static_cast<int>(pSet.getParameter<double>("theMinNrec"));
00064 
00065   labelRPCRecHits = pSet.getParameter<InputTag>("theRPCRecHits");
00066 
00067   thedt4DSegments = pSet.getParameter<InputTag>("dt4DSegments");
00068   thecscSegments = pSet.getParameter<InputTag>("cscSegments");
00069 
00070   theMeasurementExtractor = new MuonDetLayerMeasurements(thedt4DSegments,thecscSegments,
00071                                                          labelRPCRecHits,true,false,false); 
00072 
00073   theNavigationType = pSet.getParameter<string>("NavigationType");
00074 
00075   theEstimator = new Chi2MeasurementEstimator(theMaxChi2,theNSigma); 
00076 }
00077 
00078 
00079 DTChamberEfficiency::~DTChamberEfficiency()
00080 {
00081   if(debug) LogVerbatim("DTDQM|DTMonitorModule|DTChamberEfficiency")
00082               << "DTChamberEfficiency: destructor called";
00083 }
00084 
00085 void DTChamberEfficiency::beginJob(const EventSetup& eventSetup) {
00086 
00087   if(debug) LogVerbatim("DTDQM|DTMonitorModule|DTChamberEfficiency")
00088               << "DTChamberEfficiency: beginOfJob";
00089 
00090   bookHistos();
00091 
00092   return;
00093 }
00094 
00095 void DTChamberEfficiency::beginRun(const Run& run, const EventSetup& setup)
00096 {
00097   // Get the DT Geometry
00098   setup.get<MuonGeometryRecord>().get(dtGeom);
00099 
00100   setup.get<IdealMagneticFieldRecord>().get(magfield);
00101   setup.get<GlobalTrackingGeometryRecord>().get(theTrackingGeometry);
00102 
00103   return;
00104 }
00105 
00106 void DTChamberEfficiency::endJob()
00107 {
00108   if(debug) LogVerbatim("DTDQM|DTMonitorModule|DTChamberEfficiency")
00109               << "DTChamberEfficiency: endOfJob";
00110 
00111   return;
00112 }
00113 
00114 // Book a set of histograms for a given Layer
00115 void DTChamberEfficiency::bookHistos()
00116 {
00117   if(debug) LogVerbatim("DTDQM|DTMonitorModule|DTChamberEfficiency")
00118               << "DTChamberEfficiency: booking histos";
00119 
00120   // Create the monitor elements
00121   theDbe->setCurrentFolder("DT/05-ChamberEff/Task");
00122 
00123   for(int wheel=-2;wheel<=2;wheel++){
00124 
00125     vector<MonitorElement *> histos;
00126 
00127     stringstream wheel_str; wheel_str << wheel; 
00128 
00129     histos.push_back(theDbe->book2D("hCountSectVsChamb_All_W"+ wheel_str.str(),
00130                                     "Countings for wheel " + wheel_str.str(),14,1.,15.,4,1.,5.));
00131 
00132     histos.push_back(theDbe->book2D("hCountSectVsChamb_Qual_W"+ wheel_str.str(),
00133                                     "Countings for wheel " + wheel_str.str(),14,1.,15.,4,1.,5.));
00134 
00135 
00136     histos.push_back(theDbe->book2D("hExtrapSectVsChamb_W"+ wheel_str.str(),
00137                                     "Extrapolations for wheel " + wheel_str.str(),14,1.,15.,4,1.,5.));
00138 
00139     histosPerW.push_back(histos);
00140   }
00141 
00142   return;
00143 }
00144 
00145 void DTChamberEfficiency::analyze(const Event & event,
00146                             const EventSetup& eventSetup)
00147 {
00148 
00149   if (debug) LogVerbatim("DTDQM|DTMonitorModule|DTChamberEfficiency") <<
00150                "--- [DTChamberEfficiency] Event analysed #Run: " <<
00151                event.id().run() << " #Event: " << event.id().event() << endl;
00152 
00153   theService->update(eventSetup);
00154   theMeasurementExtractor->setEvent(event); 
00155 
00156   //Read tracks from event
00157   Handle<reco::TrackCollection> tracks;
00158   event.getByLabel(theTracksLabel, tracks);
00159   
00160   if(tracks.isValid()) { // check the validity of the collection
00161 
00162     //loop over the muons
00163     for(reco::TrackCollection::const_iterator track = tracks->begin(); track!=tracks->end(); ++track) {
00164 
00165       reco::TransientTrack trans_track(*track,magfield.product(),theTrackingGeometry);
00166       const int recHitsize = (int)trans_track.recHitsSize();
00167       if(recHitsize < theMinNrec) continue;
00168 
00169       // Get the layer on which the seed relies
00170       DetId id = trans_track.recHit(recHitsize-1)->geographicalId();
00171       const DetLayer *initialLayer = theService->detLayerGeometry()->idToLayer(id);
00172 
00173       TrajectoryStateOnSurface init_fs = trans_track.innermostMeasurementState();
00174       FreeTrajectoryState *init_fs_free = trans_track.innermostMeasurementState().freeState();
00175 
00176       //get the list of compatible layers
00177       vector<const DetLayer*> layer_list = compatibleLayers(initialLayer,*init_fs_free,alongMomentum);
00178 
00179       //loop over the list of compatible layers
00180       for(int i=0;i< (int)layer_list.size();i++){
00181 
00182         //propagate the track to the i-th layer
00183         TrajectoryStateOnSurface tsos = propagator()->propagate(init_fs,layer_list.at(i)->surface()); 
00184         if(!tsos.isValid()) continue;
00185 
00186         //determine the chambers kinematically compatible with the track on the i-th layer
00187         vector<DetWithState> dss = layer_list.at(i)->compatibleDets(tsos, *propagator(), *theEstimator);
00188 
00189         for(vector<DetWithState>::const_iterator detWithStateItr = dss.begin();
00190             detWithStateItr != dss.end(); ++detWithStateItr){
00191 
00192           const DetId idDetLay = detWithStateItr->first->geographicalId(); 
00193 
00194           if(!chamberSelection(idDetLay,trans_track)) continue;
00195 
00196           DTChamberId DTid = (DTChamberId) idDetLay;
00197 
00198           MeasurementContainer detMeasurements_initial = theMeasurementExtractor->measurements(layer_list.at(i),
00199                                                                                                detWithStateItr->first,
00200                                                                                                detWithStateItr->second,
00201                                                                                                *theEstimator, event);
00202 
00203           //we want to be more picky about the quality of the segments:
00204           //exclude the segments with less than 12 hits
00205           MeasurementContainer detMeasurements = segQualityCut(detMeasurements_initial);
00206 
00207           vector<MonitorElement *> histos =  histosPerW[DTid.wheel()+2];  
00208 
00209           if (detMeasurements_initial.size() != 0) histos[0]->Fill(DTid.sector(),DTid.station(),1.);
00210           if (detMeasurements.size() != 0) histos[1]->Fill(DTid.sector(),DTid.station(),1.);
00211           histos[2]->Fill(DTid.sector(),DTid.station(),1.);
00212         }
00213 
00214       }
00215     }
00216   } else {
00217     LogInfo("DTDQM|DTMonitorModule|DTChamberEfficiency") << "[DTChamberEfficiency] Collection: " << theTracksLabel
00218                                                          << " is not valid!" << endl;
00219   }
00220   return;
00221 }
00222 
00223 bool DTChamberEfficiency::chamberSelection(const DetId& idDetLay, reco::TransientTrack& trans_track) const
00224 {
00225   //check that we have a muon and that is a DT detector
00226   if(!(idDetLay.det() == DetId::Muon && idDetLay.subdetId() == MuonSubdetId::DT)) return false;
00227 
00228   if(trans_track.recHitsSize() == 2)
00229     if(trans_track.recHit(0)->geographicalId() == idDetLay ||
00230        trans_track.recHit(1)->geographicalId() == idDetLay) return false;
00231 
00232   return true;
00233 }
00234 
00235 //riempi una per ogni segmento e una per segmento sopra 12 hit
00236 
00237 MeasurementContainer DTChamberEfficiency::segQualityCut(const MeasurementContainer seg_list) const
00238 {
00239 
00240   MeasurementContainer result;
00241 
00242   for(MeasurementContainer::const_iterator mescont_Itr = seg_list.begin();
00243       mescont_Itr != seg_list.end(); ++mescont_Itr){
00244 
00245     //get the rechits of the segment
00246     TransientTrackingRecHit::ConstRecHitContainer recHit_list = mescont_Itr->recHit()->transientHits();
00247 
00248     //loop over the rechits and get the number of hits
00249     int nhit_seg(0);
00250     for(TransientTrackingRecHit::ConstRecHitContainer::const_iterator recList_Itr = recHit_list.begin();
00251         recList_Itr != recHit_list.end(); ++recList_Itr){
00252 
00253       nhit_seg += (int)(*recList_Itr)->transientHits().size();
00254     }
00255 
00256     DTChamberId tmpId = (DTChamberId)mescont_Itr->recHit()->hit()->geographicalId();
00257 
00258     if(tmpId.station() < 4 && nhit_seg >= 12) result.push_back(*mescont_Itr);
00259     if(tmpId.station() == 4 && nhit_seg >= 8) result.push_back(*mescont_Itr);
00260   }
00261 
00262   return result;
00263 }
00264 
00265 vector<const DetLayer*> DTChamberEfficiency::compatibleLayers(const DetLayer *initialLayer,
00266                                 const FreeTrajectoryState& fts, PropagationDirection propDir)
00267 {
00268 
00269 vector<const DetLayer*> detLayers;
00270 
00271 if(theNavigationType == "Standard"){
00272    // ask for compatible layers
00273    detLayers = initialLayer->compatibleLayers(fts,propDir);
00274     // I have to fit by hand the first layer until the seedTSOS is defined on the first rechit layer
00275    // In fact the first layer is not returned by initialLayer->compatibleLayers.
00276    detLayers.insert(detLayers.begin(),initialLayer);
00277    }
00278  else if (theNavigationType == "Direct"){
00279 
00280    DirectMuonNavigation navigation(&*theService->detLayerGeometry());
00281    detLayers = navigation.compatibleLayers(fts,propDir);
00282      }
00283  else
00284    LogError("Muon|RecoMuon|StandAloneMuonFilter") << "No Properly Navigation Selected!!"<<endl;
00285 
00286  return detLayers;
00287 } 
00288 
00289 inline ESHandle<Propagator> DTChamberEfficiency::propagator() const {
00290   return theService->propagator("SteppingHelixPropagatorAny");
00291 }

Generated on Tue Jun 9 17:32:38 2009 for CMSSW by  doxygen 1.5.4