CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/DQM/DTMonitorModule/src/DTRunConditionVar.cc

Go to the documentation of this file.
00001 /******* \class DTRunConditionVar *******
00002  *
00003  * Description:
00004  *  
00005  *  detailed description
00006  *
00007  * \author : Paolo Bellan, Antonio Branca
00008  * $date   : 23/09/2011 15:42:04 CET $
00009  * $Revision: 1.4 $
00010  *
00011  * Modification:
00012  *
00013  *********************************/
00014 
00015 #include "DTRunConditionVar.h"
00016 
00017 #include "FWCore/Framework/interface/Event.h"
00018 #include "FWCore/Framework/interface/EventSetup.h"
00019 #include "FWCore/ServiceRegistry/interface/Service.h"
00020 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00021 
00022 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00023 
00024 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00025 
00026 #include "DataFormats/DTRecHit/interface/DTRecSegment4D.h"
00027 #include "DataFormats/MuonDetId/interface/MuonSubdetId.h"
00028 #include "CondFormats/DataRecord/interface/DTMtimeRcd.h"
00029 
00030 #include "DQMServices/Core/interface/DQMStore.h"
00031 #include "DQMServices/Core/interface/MonitorElement.h"
00032 
00033 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00034 
00035 #include "RecoMuon/Navigation/interface/DirectMuonNavigation.h"
00036 
00037 #include "DataFormats/DetId/interface/DetId.h"
00038 #include "TrackingTools/DetLayers/interface/DetLayer.h"
00039 #include "DataFormats/Common/interface/RefToBase.h" 
00040 
00041 #include <TMath.h>
00042 #include <cmath>
00043 
00044 using namespace std;
00045 using namespace edm;
00046 
00047 DTRunConditionVar::DTRunConditionVar(const ParameterSet& pSet):
00048   // Get the debug parameter for verbose output
00049   debug(pSet.getUntrackedParameter<bool>("debug",false)),
00050   nMinHitsPhi(pSet.getUntrackedParameter<int>("nMinHitsPhi")),
00051   maxAnglePhiSegm(pSet.getUntrackedParameter<double>("maxAnglePhiSegm")),
00052   thedt4DSegments_(pSet.getParameter<InputTag>("recoSegments"))
00053 {
00054   //  LogVerbatim("DTDQM|DTRunConditionVar|DTRunConditionVar")
00055   //    << "DTRunConditionVar: constructor called";
00056 
00057   // Get the DQM needed services
00058   theDbe = Service<DQMStore>().operator->();
00059 
00060 }
00061 
00062 DTRunConditionVar::~DTRunConditionVar()
00063 {
00064   LogTrace("DTDQM|DTMonitorModule|DTRunConditionVar")
00065     << "DTRunConditionVar: destructor called";
00066 
00067   // free memory
00068 }
00069 
00070 
00071 
00072 void DTRunConditionVar::beginJob() {
00073 
00074   LogTrace("DTDQM|DTMonitorModule|DTRunConditionVar")
00075     << "DTRunConditionVar: beginOfJob";
00076 
00077   for(int wheel=-2;wheel<=2;wheel++){
00078     for(int sec=1; sec<=14; sec++) {
00079       for(int stat=1; stat<=4; stat++) {
00080 
00081         bookChamberHistos(DTChamberId(wheel,stat,sec),"VDrift_FromSegm",100,0.0043,0.0065);
00082         bookChamberHistos(DTChamberId(wheel,stat,sec),"T0_FromSegm",100,-25.,25.);
00083 
00084       }
00085     }
00086   }
00087 
00088 
00089   return;
00090 }
00091 
00092 
00093 
00094 
00095 
00096 void DTRunConditionVar::beginRun(const Run& run, const EventSetup& setup)
00097 {
00098   // Get the DT Geometry
00099   setup.get<MuonGeometryRecord>().get(dtGeom);
00100 
00101   return;
00102 }
00103 
00104 
00105 
00106 
00107 void DTRunConditionVar::endJob()
00108 {
00109   LogTrace("DTDQM|DTMonitorModule|DTRunConditionVar")
00110     << "DTRunConditionVar: endOfJob";
00111 
00112   return;
00113 }
00114 
00115 
00116 
00117 void DTRunConditionVar::analyze(const Event & event,
00118     const EventSetup& eventSetup)
00119 {
00120 
00121   LogTrace("DTDQM|DTMonitorModule|DTRunConditionVar") <<
00122     "--- [DTRunConditionVar] Event analysed #Run: " <<
00123     event.id().run() << " #Event: " << event.id().event() << endl;
00124 
00125   // Get the DT Geometry
00126   ESHandle<DTGeometry> dtGeom;
00127   eventSetup.get<MuonGeometryRecord>().get(dtGeom);
00128 
00129   // Get the map of vdrift from the setup
00130   eventSetup.get<DTMtimeRcd>().get(mTime);
00131   mTimeMap_ = &*mTime;
00132 
00133   // Get the segment collection from the event
00134   Handle<DTRecSegment4DCollection> all4DSegments;
00135   event.getByLabel(thedt4DSegments_, all4DSegments); 
00136 
00137   // Loop over the segments
00138   for(DTRecSegment4DCollection::const_iterator segment  = all4DSegments->begin();
00139       segment != all4DSegments->end(); ++segment){
00140 
00141     // Get the chamber from the setup
00142     DTChamberId DTid = (DTChamberId) segment->chamberId();
00143     uint32_t indexCh = DTid.rawId();
00144 
00145     // Fill v-drift values
00146     if( (*segment).hasPhi() ) {
00147 
00148       int nHitsPhi = (*segment).phiSegment()->degreesOfFreedom()+2;
00149       double xdir = (*segment).phiSegment()->localDirection().x();      
00150       double zdir = (*segment).phiSegment()->localDirection().z();      
00151 
00152       double anglePhiSegm = fabs(atan(xdir/zdir))*180./TMath::Pi();
00153 
00154       if( nHitsPhi >= nMinHitsPhi && anglePhiSegm <= maxAnglePhiSegm ) {
00155 
00156         double segmentVDrift = segment->phiSegment()->vDrift();
00157 
00158 
00159         DTSuperLayerId indexSLPhi1(DTid,1);
00160         DTSuperLayerId indexSLPhi2(DTid,3);
00161 
00162         float vDriftPhi1(0.), vDriftPhi2(0.); 
00163         float ResPhi1(0.), ResPhi2(0.);
00164         int status1 = mTimeMap_->get(indexSLPhi1,vDriftPhi1,ResPhi1,DTVelocityUnits::cm_per_ns); 
00165         int status2 = mTimeMap_->get(indexSLPhi2,vDriftPhi2,ResPhi2,DTVelocityUnits::cm_per_ns); 
00166 
00167         if(status1 != 0 || status2 != 0) {
00168           DTSuperLayerId sl = (status1 != 0) ? indexSLPhi1 : indexSLPhi2; 
00169           throw cms::Exception("DTRunConditionVarClient") << "Could not find vDrift entry in DB for"
00170             << sl << endl;
00171         }
00172 
00173         float vDriftMed = (vDriftPhi1 + vDriftPhi2) / 2.;
00174 
00175         segmentVDrift = vDriftMed*(1. - segmentVDrift);
00176 
00177         double segmentT0 = segment->phiSegment()->t0();
00178 
00179         if( segment->phiSegment()->ist0Valid() ) (chamberHistos[indexCh])["T0_FromSegm"]->Fill(segmentT0);
00180         if( segmentVDrift != vDriftMed ) (chamberHistos[indexCh])["VDrift_FromSegm"]->Fill(segmentVDrift);
00181 
00182       }
00183     }
00184 
00185     //    if( (*segment).hasZed() ){
00186     //      double segmentVDrift = segment->zSegment()->vDrift();
00187     //      double segmentT0 = segment->zSegment()->t0();
00188     //
00189     //
00190     //      if(segmentT0 != -999 ) ht0[sector-1]->Fill(segmentT0);      
00191     //      if( segmentVDrift > 0.00 ) hvd[sector-1]->Fill(segmentVDrift);
00192     //
00193     //    }
00194   } //end loop on segment
00195 
00196 } //end analyze
00197 
00198 
00199 
00200 
00201 void DTRunConditionVar::bookChamberHistos(const DTChamberId& dtCh, string histoType, int nbins, float min, float max) {
00202 
00203   int wh = dtCh.wheel();                
00204   int sc = dtCh.sector();       
00205   int st = dtCh.station();
00206   stringstream wheel; wheel << wh;      
00207   stringstream station; station << st;  
00208   stringstream sector; sector << sc;    
00209 
00210   string bookingFolder = "DT/02-Segments/Wheel" + wheel.str() + "/Sector" + sector.str() + "/Station" + station.str();
00211   string histoTag      = "_W" + wheel.str() + "_Sec" + sector.str() + "_St" + station.str();
00212 
00213   theDbe->setCurrentFolder(bookingFolder);
00214 
00215   LogTrace ("DTDQM|DTMonitorModule|DTRunConditionVar") 
00216     << "[DTRunConditionVar]: booking histos in " << bookingFolder << endl;
00217 
00218   string histoName = histoType  +  histoTag;
00219   string histoLabel = histoType;
00220 
00221   (chamberHistos[dtCh.rawId()])[histoType] = 
00222     theDbe->book1D(histoName,histoLabel,nbins,min,max);
00223 
00224 }