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  *  \author S. Bolognesi
0005  */
0006 
0007 #include "CalibMuon/DTCalibration/plugins/DTTPDeadWriter.h"
0008 #include "CalibMuon/DTCalibration/interface/DTCalibDBUtils.h"
0009 
0010 #include "FWCore/Framework/interface/EventSetup.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012 #include "FWCore/Framework/interface/Event.h"
0013 #include "DataFormats/MuonDetId/interface/DTWireId.h"
0014 #include "Geometry/DTGeometry/interface/DTGeometry.h"
0015 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0016 
0017 #include "CondFormats/DTObjects/interface/DTT0.h"
0018 #include "CondFormats/DataRecord/interface/DTT0Rcd.h"
0019 #include "CondFormats/DataRecord/interface/DTDeadFlagRcd.h"
0020 #include "CondFormats/DTObjects/interface/DTDeadFlag.h"
0021 
0022 /* C++ Headers */
0023 #include <vector>
0024 #include <set>
0025 #include <iostream>
0026 #include <fstream>
0027 #include <string>
0028 #include <sstream>
0029 #include "TFile.h"
0030 #include "TH1.h"
0031 
0032 using namespace std;
0033 using namespace edm;
0034 
0035 // Constructor
0036 DTTPDeadWriter::DTTPDeadWriter(const ParameterSet& pset) : dtGeomToken_(esConsumes<edm::Transition::BeginRun>()) {
0037   // get selected debug option
0038   debug = pset.getUntrackedParameter<bool>("debug", false);
0039   t0Token_ = esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", pset.getParameter<string>("debug")));
0040 
0041   // Create the object to be written to DB
0042   tpDeadList = new DTDeadFlag();
0043 
0044   if (debug)
0045     cout << "[DTTPDeadWriter]Constructor called!" << endl;
0046 }
0047 
0048 // Destructor
0049 DTTPDeadWriter::~DTTPDeadWriter() {
0050   if (debug)
0051     cout << "[DTTPDeadWriter]Destructor called!" << endl;
0052 }
0053 
0054 void DTTPDeadWriter::beginRun(const edm::Run&, const EventSetup& setup) {
0055   // Get the t0 map
0056   tZeroMap = &setup.getData(t0Token_);
0057 
0058   // Get the muon Geometry
0059   muonGeom = setup.getHandle(dtGeomToken_);
0060 }
0061 
0062 // Do the job
0063 void DTTPDeadWriter::analyze(const Event& event, const EventSetup& eventSetup) {
0064   set<DTLayerId> analyzedLayers;
0065 
0066   //Loop on tzero map
0067   for (DTT0::const_iterator tzero = tZeroMap->begin(); tzero != tZeroMap->end(); ++tzero) {
0068     //Consider what layers have been already considered
0069     // @@@ NEW DTT0 FORMAT
0070     //    DTLayerId layerId = (DTWireId((*tzero).first.wheelId,
0071     //                (*tzero).first.stationId,
0072     //                (*tzero).first.sectorId,
0073     //                (*tzero).first.slId,
0074     //                (*tzero).first.layerId,
0075     //                (*tzero).first.cellId)).layerId();
0076     int channelId = tzero->channelId;
0077     if (channelId == 0)
0078       continue;
0079     DTLayerId layerId = (DTWireId(channelId)).layerId();
0080     // @@@ NEW DTT0 END
0081     if (analyzedLayers.find(layerId) == analyzedLayers.end()) {
0082       analyzedLayers.insert(layerId);
0083 
0084       //Take the layer topology
0085       const DTTopology& dtTopo = muonGeom->layer(layerId)->specificTopology();
0086       const int firstWire = dtTopo.firstChannel();
0087       //const int lastWire = dtTopo.lastChannel();
0088       const int nWires = muonGeom->layer(layerId)->specificTopology().channels();
0089 
0090       //Loop on wires
0091       for (int wire = firstWire; wire <= nWires; wire++) {
0092         DTWireId wireId(layerId, wire);
0093         float t0 = 0;
0094         float t0rms = 0;
0095         tZeroMap->get(wireId, t0, t0rms, DTTimeUnits::ns);
0096 
0097         //If no t0 stored then is a tp dead channel
0098         if (!t0) {
0099           tpDeadList->setCellDead_TP(wireId, true);
0100           cout << "Wire id " << wireId << " is TP dead" << endl;
0101         }
0102       }
0103     }
0104   }
0105 }
0106 
0107 // Write objects to DB
0108 void DTTPDeadWriter::endJob() {
0109   if (debug)
0110     cout << "[DTTPDeadWriter]Writing ttrig object to DB!" << endl;
0111 
0112   // FIXME: to be read from cfg?
0113   string deadRecord = "DTDeadFlagRcd";
0114 
0115   // Write the object to DB
0116   DTCalibDBUtils::writeToDB(deadRecord, tpDeadList);
0117 }