Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-19 10:28:04

0001 /*
0002  *  See header file for a description of this class.
0003  *
0004  */
0005 
0006 #include "DTT0WireInChamberReferenceCorrection.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008 #include "FWCore/Framework/interface/EventSetup.h"
0009 #include "FWCore/Framework/interface/ESHandle.h"
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 
0012 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0013 #include "Geometry/DTGeometry/interface/DTGeometry.h"
0014 #include "Geometry/DTGeometry/interface/DTSuperLayer.h"
0015 
0016 #include "DataFormats/MuonDetId/interface/DTWireId.h"
0017 #include "CondFormats/DTObjects/interface/DTT0.h"
0018 #include "CondFormats/DataRecord/interface/DTT0Rcd.h"
0019 #include "FWCore/Framework/interface/ConsumesCollector.h"
0020 
0021 #include <string>
0022 #include <sstream>
0023 
0024 using namespace std;
0025 using namespace edm;
0026 
0027 namespace dtCalibration {
0028 
0029   DTT0WireInChamberReferenceCorrection::DTT0WireInChamberReferenceCorrection(const ParameterSet& pset,
0030                                                                              edm::ConsumesCollector cc)
0031       : calibChamber_(pset.getParameter<string>("calibChamber")),
0032         t0Token_(cc.esConsumes<edm::Transition::BeginRun>()),
0033         dtGeomToken_(cc.esConsumes<edm::Transition::BeginRun>()) {
0034     //DTChamberId chosenChamberId;
0035     if (!calibChamber_.empty() && calibChamber_ != "None" && calibChamber_ != "All") {
0036       stringstream linestr;
0037       int selWheel, selStation, selSector;
0038       linestr << calibChamber_;
0039       linestr >> selWheel >> selStation >> selSector;
0040       chosenChamberId_ = DTChamberId(selWheel, selStation, selSector);
0041       LogVerbatim("Calibration") << "[DTT0WireInChamberReferenceCorrection] Chosen chamber: " << chosenChamberId_
0042                                  << endl;
0043     }
0044     //FIXME: Check if chosen chamber is valid.
0045   }
0046 
0047   DTT0WireInChamberReferenceCorrection::~DTT0WireInChamberReferenceCorrection() {}
0048 
0049   void DTT0WireInChamberReferenceCorrection::setES(const EventSetup& setup) {
0050     // Get t0 record from DB
0051     ESHandle<DTT0> t0H = setup.getHandle(t0Token_);
0052     t0Map_ = &*t0H;
0053     LogVerbatim("Calibration") << "[DTT0WireInChamberReferenceCorrection] T0 version: " << t0H->version();
0054 
0055     // Get geometry from Event Setup
0056     dtGeom_ = setup.getHandle(dtGeomToken_);
0057   }
0058 
0059   DTT0Data DTT0WireInChamberReferenceCorrection::correction(const DTWireId& wireId) {
0060     // Compute for selected chamber (or All) correction using as reference chamber mean
0061 
0062     DTChamberId chamberId = wireId.layerId().superlayerId().chamberId();
0063 
0064     if (calibChamber_.empty() || calibChamber_ == "None")
0065       return defaultT0(wireId);
0066     if (calibChamber_ != "All" && chamberId != chosenChamberId_)
0067       return defaultT0(wireId);
0068 
0069     // Access DB
0070     float t0Mean, t0RMS;
0071     int status = t0Map_->get(wireId, t0Mean, t0RMS, DTTimeUnits::counts);
0072     if (status != 0)
0073       throw cms::Exception("[DTT0WireInChamberReferenceCorrection]")
0074           << "Could not find t0 entry in DB for" << wireId << endl;
0075 
0076     // Try to find t0 for reference wire in layer
0077     DTSuperLayerId slId = wireId.layerId().superlayerId();
0078     // Layers 1 and 2
0079     DTLayerId layerRef1(slId, 1);
0080     //DTLayerId layerRef2( slId,2 );
0081 
0082     const DTTopology& dtTopoLayerRef1 = dtGeom_->layer(layerRef1)->specificTopology();
0083     const int firstWireLayerRef1 = dtTopoLayerRef1.firstChannel();
0084     const int refWireLayerRef1 = firstWireLayerRef1;
0085     DTWireId wireIdRefLayerRef1(layerRef1, refWireLayerRef1);
0086 
0087     float t0MeanRef1, t0RMSRef1;
0088     int statusRef1 = t0Map_->get(wireIdRefLayerRef1, t0MeanRef1, t0RMSRef1, DTTimeUnits::counts);
0089 
0090     // Correct channels in a superlayer wrt t0 from first wire in first layer
0091     if (!statusRef1) {
0092       float t0MeanNew = t0Mean - t0MeanRef1;
0093       float t0RMSNew = t0RMS;
0094       return DTT0Data(t0MeanNew, t0RMSNew);
0095     } else {
0096       // If reference wire not active could choose adjacent wire instead
0097       //...
0098       throw cms::Exception("[DTT0WireInChamberReferenceCorrection]")
0099           << "Could not find t0 entry in DB for" << wireIdRefLayerRef1 << endl;
0100     }
0101   }
0102 
0103   DTT0Data DTT0WireInChamberReferenceCorrection::defaultT0(const DTWireId& wireId) {
0104     // Access default DB
0105     float t0Mean, t0RMS;
0106     int status = t0Map_->get(wireId, t0Mean, t0RMS, DTTimeUnits::counts);
0107     if (!status) {
0108       return DTT0Data(t0Mean, t0RMS);
0109     } else {
0110       //...
0111       throw cms::Exception("[DTT0WireInChamberReferenceCorrection]")
0112           << "Could not find t0 entry in DB for" << wireId << endl;
0113     }
0114   }
0115 
0116 }  // namespace dtCalibration