CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/CalibMuon/DTCalibration/plugins/DTTPDeadWriter.cc

Go to the documentation of this file.
00001 /*
00002  *  See header file for a description of this class.
00003  *
00004  *  $Date: 2012/05/11 17:17:17 $
00005  *  $Revision: 1.4 $
00006  *  \author S. Bolognesi
00007  */
00008 
00009 #include "CalibMuon/DTCalibration/plugins/DTTPDeadWriter.h"
00010 #include "CalibMuon/DTCalibration/interface/DTCalibDBUtils.h"
00011 
00012 #include "FWCore/Framework/interface/EventSetup.h"
00013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00014 #include "FWCore/Framework/interface/Event.h"
00015 #include "DataFormats/MuonDetId/interface/DTWireId.h"
00016 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00017 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00018 
00019 #include "CondFormats/DTObjects/interface/DTT0.h"
00020 #include "CondFormats/DataRecord/interface/DTT0Rcd.h"
00021 #include "CondFormats/DataRecord/interface/DTDeadFlagRcd.h"
00022 #include "CondFormats/DTObjects/interface/DTDeadFlag.h"
00023 
00024 /* C++ Headers */
00025 #include <vector> 
00026 #include <set>
00027 #include <iostream>
00028 #include <fstream>
00029 #include <string>
00030 #include <sstream>
00031 #include "TFile.h"
00032 #include "TH1.h"
00033 
00034 using namespace std;
00035 using namespace edm;
00036 
00037 
00038 // Constructor
00039 DTTPDeadWriter::DTTPDeadWriter(const ParameterSet& pset) {
00040   // get selected debug option
00041   debug = pset.getUntrackedParameter<bool>("debug", false); 
00042 
00043   // Create the object to be written to DB
00044   tpDeadList = new DTDeadFlag();
00045 
00046   if(debug)
00047     cout << "[DTTPDeadWriter]Constructor called!" << endl;
00048 }
00049 
00050 // Destructor
00051 DTTPDeadWriter::~DTTPDeadWriter(){
00052   if(debug)
00053     cout << "[DTTPDeadWriter]Destructor called!" << endl;
00054 }
00055 
00056 void DTTPDeadWriter::beginRun(const edm::Run&, const EventSetup& setup) {
00057    // Get the t0 map  
00058    ESHandle<DTT0> t0;
00059    setup.get<DTT0Rcd>().get(t0);
00060    tZeroMap = &*t0;
00061 
00062    // Get the muon Geometry  
00063    setup.get<MuonGeometryRecord>().get(muonGeom);
00064 }
00065 
00066 // Do the job
00067 void DTTPDeadWriter::analyze(const Event & event, const EventSetup& eventSetup) {
00068   set<DTLayerId> analyzedLayers;
00069 
00070   //Loop on tzero map
00071   for(DTT0::const_iterator tzero = tZeroMap->begin();
00072       tzero != tZeroMap->end(); tzero++){
00073 
00074     //Consider what layers have been already considered
00075 // @@@ NEW DTT0 FORMAT
00076 //    DTLayerId layerId = (DTWireId((*tzero).first.wheelId,
00077 //                                (*tzero).first.stationId,
00078 //                                (*tzero).first.sectorId,
00079 //                                (*tzero).first.slId,
00080 //                                (*tzero).first.layerId,
00081 //                                (*tzero).first.cellId)).layerId();
00082     int channelId = tzero->channelId;
00083     if ( channelId == 0 ) continue;
00084     DTLayerId layerId = (DTWireId(channelId)).layerId();
00085 // @@@ NEW DTT0 END
00086     if(analyzedLayers.find(layerId)==analyzedLayers.end()){
00087       analyzedLayers.insert(layerId);
00088 
00089       //Take the layer topology
00090       const DTTopology& dtTopo = muonGeom->layer(layerId)->specificTopology();
00091       const int firstWire = dtTopo.firstChannel();
00092       //const int lastWire = dtTopo.lastChannel();
00093       const int nWires = muonGeom->layer(layerId)->specificTopology().channels();
00094 
00095       //Loop on wires
00096       for(int wire=firstWire; wire<=nWires; wire++){
00097         DTWireId wireId(layerId,wire);
00098         float t0 = 0;
00099         float t0rms = 0;
00100         tZeroMap->get(wireId,
00101                       t0,
00102                       t0rms,
00103                       DTTimeUnits::ns);
00104 
00105         //If no t0 stored then is a tp dead channel
00106         if(!t0){
00107           tpDeadList->setCellDead_TP(wireId, true);
00108           cout<<"Wire id "<<wireId<<" is TP dead"<<endl;          
00109         }
00110       }
00111     }
00112   }
00113 }
00114 
00115 // Write objects to DB
00116 void DTTPDeadWriter::endJob() {
00117   if(debug) 
00118         cout << "[DTTPDeadWriter]Writing ttrig object to DB!" << endl;
00119 
00120   // FIXME: to be read from cfg?
00121   string deadRecord = "DTDeadFlagRcd";
00122   
00123   // Write the object to DB
00124   DTCalibDBUtils::writeToDB(deadRecord, tpDeadList);
00125 
00126 }  
00127