CMS 3D CMS Logo

DTTPAnalyzer.cc
Go to the documentation of this file.
1 
9 
10 #include <string>
11 #include <map>
12 
13 //class DTT0;
14 class DTLayerId;
15 class DTWireId;
16 class DTGeometry;
17 class DTTTrigBaseSync;
18 class TFile;
19 
20 class DTTPAnalyzer : public edm::EDAnalyzer {
21 public:
23  ~DTTPAnalyzer() override;
24 
25  //void beginJob();
26  void beginRun(const edm::Run&, const edm::EventSetup&) override;
27  void analyze(const edm::Event&, const edm::EventSetup&) override;
28  void endJob() override;
29 
30 private:
32 
35 
36  TFile* rootFile_;
37  //const DTT0* tZeroMap_;
39  std::unique_ptr<DTTTrigBaseSync> tTrigSync_;
40 
41  // Map of the t0 and sigma histos by layer
42  std::map<DTWireId, int> nDigisPerWire_;
43  std::map<DTWireId, double> sumWPerWire_;
44  std::map<DTWireId, double> sumW2PerWire_;
45  //std::map<DTLayerId, TH1F*> meanHistoMap_;
46  //std::map<DTLayerId, TH1F*> sigmaHistoMap_;
47 };
48 
52 
55 
59 
62 
64 
65 #include "TH1F.h"
66 #include "TFile.h"
67 
69  : subtractT0_(pset.getParameter<bool>("subtractT0")), digiLabel_(pset.getParameter<edm::InputTag>("digiLabel")) {
70  std::string rootFileName = pset.getUntrackedParameter<std::string>("rootFileName");
71  rootFile_ = new TFile(rootFileName.c_str(), "RECREATE");
72  rootFile_->cd();
73 
74  if (subtractT0_)
75  tTrigSync_ = DTTTrigSyncFactory::get()->create(pset.getParameter<std::string>("tTrigMode"),
76  pset.getParameter<edm::ParameterSet>("tTrigModeConfig"));
77 }
78 
80 
82  // Get the t0 map from the DB
83  if (subtractT0_) {
84  /*ESHandle<DTT0> t0;
85  setup.get<DTT0Rcd>().get(t0);
86  tZeroMap_ = &*t0;*/
87  tTrigSync_->setES(setup);
88  }
89  // Get the DT Geometry
91 }
92 
94  // Get the digis from the event
96  event.getByLabel(digiLabel_, digis);
97 
98  // Iterate through all digi collections ordered by LayerId
100  for (dtLayerIt = digis->begin(); dtLayerIt != digis->end(); ++dtLayerIt) {
101  // Get the iterators over the digis associated with this LayerId
102  const DTDigiCollection::Range& digiRange = (*dtLayerIt).second;
103 
104  // Get the layerId
105  const DTLayerId layerId = (*dtLayerIt).first; //FIXME: check to be in the right sector
106 
107  // Loop over all digis in the given layer
108  for (DTDigiCollection::const_iterator digi = digiRange.first; digi != digiRange.second; ++digi) {
109  const DTWireId wireId(layerId, (*digi).wire());
110 
111  double t0 = (*digi).countsTDC();
112 
113  //FIXME: Reject digis not coming from TP
114 
115  if (subtractT0_) {
116  const DTLayer* layer = nullptr; //fake
117  const GlobalPoint glPt; //fake
118  double offset = tTrigSync_->offset(layer, wireId, glPt);
119  t0 -= offset;
120  }
121 
122  if (nDigisPerWire_.find(wireId) == nDigisPerWire_.end()) {
123  nDigisPerWire_[wireId] = 0;
124  sumWPerWire_[wireId] = 0.;
125  sumW2PerWire_[wireId] = 0.;
126  }
127 
128  ++nDigisPerWire_[wireId];
129  sumWPerWire_[wireId] += t0;
130  sumW2PerWire_[wireId] += t0 * t0;
131  }
132  }
133 }
134 
136  rootFile_->cd();
137  std::map<DTLayerId, TH1F*> meanHistoMap;
138  std::map<DTLayerId, TH1F*> sigmaHistoMap;
139  for (std::map<DTWireId, int>::const_iterator wireIdIt = nDigisPerWire_.begin(); wireIdIt != nDigisPerWire_.end();
140  ++wireIdIt) {
141  DTWireId wireId((*wireIdIt).first);
142 
143  int nDigis = nDigisPerWire_[wireId];
144  double sumW = sumWPerWire_[wireId];
145  double sumW2 = sumW2PerWire_[wireId];
146 
147  double mean = sumW / nDigis;
148  double rms = sumW2 / nDigis - mean * mean;
149  rms = sqrt(rms);
150 
151  DTLayerId layerId = wireId.layerId();
152  if (meanHistoMap.find(layerId) == meanHistoMap.end()) {
154  const int firstChannel = dtGeom_->layer(layerId)->specificTopology().firstChannel();
155  const int nWires = dtGeom_->layer(layerId)->specificTopology().channels();
156  TH1F* meanHistoTP = new TH1F((histoName + "_tpMean").c_str(),
157  "mean from test pulses by channel",
158  nWires,
159  firstChannel,
160  (firstChannel + nWires));
161  TH1F* sigmaHistoTP = new TH1F((histoName + "_tpSigma").c_str(),
162  "sigma from test pulses by channel",
163  nWires,
164  firstChannel,
165  (firstChannel + nWires));
166  meanHistoMap[layerId] = meanHistoTP;
167  sigmaHistoMap[layerId] = sigmaHistoTP;
168  }
169  // Fill the histograms
170  int nBin = meanHistoMap[layerId]->GetXaxis()->FindFixBin(wireId.wire());
171  meanHistoMap[layerId]->SetBinContent(nBin, mean);
172  sigmaHistoMap[layerId]->SetBinContent(nBin, rms);
173  }
174 
175  for (std::map<DTLayerId, TH1F*>::const_iterator key = meanHistoMap.begin(); key != meanHistoMap.end(); ++key) {
176  meanHistoMap[(*key).first]->Write();
177  sigmaHistoMap[(*key).first]->Write();
178  }
179 }
180 
183  std::stringstream theStream;
184  theStream << "Ch_" << lId.wheel() << "_" << lId.station() << "_" << lId.sector() << "_SL" << lId.superlayer() << "_L"
185  << lId.layer();
186  theStream >> histoName;
187  return histoName;
188 }
189 
DTGeometry
Definition: DTGeometry.h:28
DTWireId::wire
int wire() const
Return the wire number.
Definition: DTWireId.h:42
DTTPAnalyzer::beginRun
void beginRun(const edm::Run &, const edm::EventSetup &) override
Definition: DTTPAnalyzer.cc:81
DTTPAnalyzer::tTrigSync_
std::unique_ptr< DTTTrigBaseSync > tTrigSync_
Definition: DTTPAnalyzer.cc:39
electrons_cff.bool
bool
Definition: electrons_cff.py:366
SiStripPI::mean
Definition: SiStripPayloadInspectorHelper.h:169
ESHandle.h
edm::Run
Definition: Run.h:45
DTTTrigBaseSync
Definition: DTTTrigBaseSync.h:19
edm
HLT enums.
Definition: AlignableModifier.h:19
DTTPAnalyzer::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: DTTPAnalyzer.cc:93
DTT0.h
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89281
DTTPAnalyzer::getHistoName
std::string getHistoName(const DTLayerId &)
Definition: DTTPAnalyzer.cc:181
DTTopology::channels
int channels() const
Returns the number of wires in the layer.
Definition: DTTopology.h:76
EDAnalyzer.h
DTSuperLayerId::superlayer
int superlayer() const
Return the superlayer number (deprecated method name)
Definition: DTSuperLayerId.h:42
SiStripPI::rms
Definition: SiStripPayloadInspectorHelper.h:169
edm::Handle< DTDigiCollection >
MuonNumberingRecord.h
PFElectronDQMAnalyzer_cfi.nBin
nBin
Definition: PFElectronDQMAnalyzer_cfi.py:25
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
MuonDigiCollection::const_iterator
std::vector< DigiType >::const_iterator const_iterator
Definition: MuonDigiCollection.h:94
DTTPAnalyzer::~DTTPAnalyzer
~DTTPAnalyzer() override
Definition: DTTPAnalyzer.cc:79
edm::EDAnalyzer
Definition: EDAnalyzer.h:28
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
DTTopology::firstChannel
int firstChannel() const
Returns the wire number of the first wire.
Definition: DTTopology.h:79
DTWireId
Definition: DTWireId.h:12
FrontierCondition_GT_autoExpress_cfi.t0
t0
Definition: FrontierCondition_GT_autoExpress_cfi.py:149
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
edm::ESHandle< DTGeometry >
Point3DBase< float, GlobalTag >
DTLayerId
Definition: DTLayerId.h:12
DTTPAnalyzer::subtractT0_
bool subtractT0_
Definition: DTTPAnalyzer.cc:33
phase1PixelTopology::layer
constexpr std::array< uint8_t, layerIndexSize > layer
Definition: phase1PixelTopology.h:99
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
DTGeometry.h
edm::ParameterSet
Definition: ParameterSet.h:47
DTGeometry::layer
const DTLayer * layer(const DTLayerId &id) const
Return a layer given its id.
Definition: DTGeometry.cc:96
Event.h
DTTPAnalyzer::digiLabel_
edm::InputTag digiLabel_
Definition: DTTPAnalyzer.cc:34
DTTPAnalyzer::endJob
void endJob() override
Definition: DTTPAnalyzer.cc:135
DTTPAnalyzer
Definition: DTTPAnalyzer.cc:20
DTTTrigBaseSync.h
edm::EventSetup
Definition: EventSetup.h:58
get
#define get
DTLayer
Definition: DTLayer.h:25
DTTPAnalyzer::sumWPerWire_
std::map< DTWireId, double > sumWPerWire_
Definition: DTTPAnalyzer.cc:43
InputTag.h
DTChamberId::sector
int sector() const
Definition: DTChamberId.h:49
writedatasetfile.run
run
Definition: writedatasetfile.py:27
DTTPAnalyzer::nDigisPerWire_
std::map< DTWireId, int > nDigisPerWire_
Definition: DTTPAnalyzer.cc:42
DTTPAnalyzer::rootFile_
TFile * rootFile_
Definition: DTTPAnalyzer.cc:36
DTTTrigSyncFactory.h
HltBtagPostValidation_cff.histoName
histoName
Definition: HltBtagPostValidation_cff.py:17
MuonDigiCollection::Range
std::pair< const_iterator, const_iterator > Range
Definition: MuonDigiCollection.h:95
CSCSkim_cfi.rootFileName
rootFileName
Definition: CSCSkim_cfi.py:9
DTLayer::specificTopology
const DTTopology & specificTopology() const
Definition: DTLayer.cc:37
DTWireId::layerId
DTLayerId layerId() const
Return the corresponding LayerId.
Definition: DTWireId.h:45
DTTPAnalyzer::sumW2PerWire_
std::map< DTWireId, double > sumW2PerWire_
Definition: DTTPAnalyzer.cc:44
DTTPAnalyzer::DTTPAnalyzer
DTTPAnalyzer(const edm::ParameterSet &)
Definition: DTTPAnalyzer.cc:68
DTDigiCollection.h
ParameterSet.h
MuonGeometryRecord.h
event
Definition: event.py:1
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:82
DigiContainerIterator
Definition: MuonDigiCollection.h:30
edm::Event
Definition: Event.h:73
DTLayerId::layer
int layer() const
Return the layer number.
Definition: DTLayerId.h:42
crabWrapper.key
key
Definition: crabWrapper.py:19
MuonGeometryRecord
Definition: MuonGeometryRecord.h:34
GlobalPoint.h
DTChamberId::wheel
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:39
edm::InputTag
Definition: InputTag.h:15
DTChamberId::station
int station() const
Return the station number.
Definition: DTChamberId.h:42
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
DTTPAnalyzer::dtGeom_
edm::ESHandle< DTGeometry > dtGeom_
Definition: DTTPAnalyzer.cc:38