CMS 3D CMS Logo

DTTPAnalyzer.cc
Go to the documentation of this file.
1 
11 
12 #include <string>
13 #include <map>
14 
15 //class DTT0;
16 class DTLayerId;
17 class DTWireId;
18 class DTGeometry;
19 class DTTTrigBaseSync;
20 class TFile;
21 
23 public:
25  ~DTTPAnalyzer() override;
26 
27  void analyze(const edm::Event&, const edm::EventSetup&) override;
28  void endJob() override;
29 
30 private:
32 
35 
36  TFile* rootFile_;
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 };
46 
50 
53 
56 
59 
61 
62 #include "TH1F.h"
63 #include "TFile.h"
64 
66  : subtractT0_(pset.getParameter<bool>("subtractT0")),
67  digiLabel_(pset.getParameter<edm::InputTag>("digiLabel")),
68  dtGeomToken_(esConsumes()) {
69  std::string rootFileName = pset.getUntrackedParameter<std::string>("rootFileName");
70  rootFile_ = new TFile(rootFileName.c_str(), "RECREATE");
71  rootFile_->cd();
72 
73  if (subtractT0_)
74  tTrigSync_ = DTTTrigSyncFactory::get()->create(pset.getParameter<std::string>("tTrigMode"),
75  pset.getParameter<edm::ParameterSet>("tTrigModeConfig"),
77 }
78 
80 
82  // Get the digis from the event
84  event.getByLabel(digiLabel_, digis);
85 
86  if (subtractT0_) {
87  tTrigSync_->setES(setup);
88  }
89  // Get the DT Geometry
90  dtGeom_ = setup.getHandle(dtGeomToken_);
91 
92  // Iterate through all digi collections ordered by LayerId
94  for (dtLayerIt = digis->begin(); dtLayerIt != digis->end(); ++dtLayerIt) {
95  // Get the iterators over the digis associated with this LayerId
96  const DTDigiCollection::Range& digiRange = (*dtLayerIt).second;
97 
98  // Get the layerId
99  const DTLayerId layerId = (*dtLayerIt).first; //FIXME: check to be in the right sector
100 
101  // Loop over all digis in the given layer
102  for (DTDigiCollection::const_iterator digi = digiRange.first; digi != digiRange.second; ++digi) {
103  const DTWireId wireId(layerId, (*digi).wire());
104 
105  double t0 = (*digi).countsTDC();
106 
107  //FIXME: Reject digis not coming from TP
108 
109  if (subtractT0_) {
110  const DTLayer* layer = nullptr; //fake
111  const GlobalPoint glPt; //fake
112  double offset = tTrigSync_->offset(layer, wireId, glPt);
113  t0 -= offset;
114  }
115 
116  if (nDigisPerWire_.find(wireId) == nDigisPerWire_.end()) {
117  nDigisPerWire_[wireId] = 0;
118  sumWPerWire_[wireId] = 0.;
119  sumW2PerWire_[wireId] = 0.;
120  }
121 
122  ++nDigisPerWire_[wireId];
123  sumWPerWire_[wireId] += t0;
124  sumW2PerWire_[wireId] += t0 * t0;
125  }
126  }
127 }
128 
130  rootFile_->cd();
131  std::map<DTLayerId, TH1F*> meanHistoMap;
132  std::map<DTLayerId, TH1F*> sigmaHistoMap;
133  for (std::map<DTWireId, int>::const_iterator wireIdIt = nDigisPerWire_.begin(); wireIdIt != nDigisPerWire_.end();
134  ++wireIdIt) {
135  DTWireId wireId((*wireIdIt).first);
136 
137  int nDigis = nDigisPerWire_[wireId];
138  double sumW = sumWPerWire_[wireId];
139  double sumW2 = sumW2PerWire_[wireId];
140 
141  double mean = sumW / nDigis;
142  double rms = sumW2 / nDigis - mean * mean;
143  rms = sqrt(rms);
144 
145  DTLayerId layerId = wireId.layerId();
146  if (meanHistoMap.find(layerId) == meanHistoMap.end()) {
148  const int firstChannel = dtGeom_->layer(layerId)->specificTopology().firstChannel();
149  const int nWires = dtGeom_->layer(layerId)->specificTopology().channels();
150  TH1F* meanHistoTP = new TH1F((histoName + "_tpMean").c_str(),
151  "mean from test pulses by channel",
152  nWires,
153  firstChannel,
154  (firstChannel + nWires));
155  TH1F* sigmaHistoTP = new TH1F((histoName + "_tpSigma").c_str(),
156  "sigma from test pulses by channel",
157  nWires,
158  firstChannel,
159  (firstChannel + nWires));
160  meanHistoMap[layerId] = meanHistoTP;
161  sigmaHistoMap[layerId] = sigmaHistoTP;
162  }
163  // Fill the histograms
164  int nBin = meanHistoMap[layerId]->GetXaxis()->FindFixBin(wireId.wire());
165  meanHistoMap[layerId]->SetBinContent(nBin, mean);
166  sigmaHistoMap[layerId]->SetBinContent(nBin, rms);
167  }
168 
169  for (std::map<DTLayerId, TH1F*>::const_iterator key = meanHistoMap.begin(); key != meanHistoMap.end(); ++key) {
170  meanHistoMap[(*key).first]->Write();
171  sigmaHistoMap[(*key).first]->Write();
172  }
173 }
174 
177  std::stringstream theStream;
178  theStream << "Ch_" << lId.wheel() << "_" << lId.station() << "_" << lId.sector() << "_SL" << lId.superlayer() << "_L"
179  << lId.layer();
180  theStream >> histoName;
181  return histoName;
182 }
183 
int station() const
Return the station number.
Definition: DTChamberId.h:42
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::InputTag digiLabel_
Definition: DTTPAnalyzer.cc:34
int wire() const
Return the wire number.
Definition: DTWireId.h:42
const edm::ESGetToken< DTGeometry, MuonGeometryRecord > dtGeomToken_
Definition: DTTPAnalyzer.cc:38
DTTPAnalyzer(const edm::ParameterSet &)
Definition: DTTPAnalyzer.cc:65
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::map< DTWireId, double > sumWPerWire_
Definition: DTTPAnalyzer.cc:43
std::map< DTWireId, int > nDigisPerWire_
Definition: DTTPAnalyzer.cc:42
constexpr std::array< uint8_t, layerIndexSize > layer
TFile * rootFile_
Definition: DTTPAnalyzer.cc:36
std::string getHistoName(const DTLayerId &)
int firstChannel() const
Returns the wire number of the first wire.
Definition: DTTopology.h:79
void endJob() override
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
T sqrt(T t)
Definition: SSEVec.h:19
~DTTPAnalyzer() override
Definition: DTTPAnalyzer.cc:79
std::unique_ptr< DTTTrigBaseSync > tTrigSync_
Definition: DTTPAnalyzer.cc:39
const DTTopology & specificTopology() const
Definition: DTLayer.cc:37
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: DTTPAnalyzer.cc:81
std::map< DTWireId, double > sumW2PerWire_
Definition: DTTPAnalyzer.cc:44
int superlayer() const
Return the superlayer number (deprecated method name)
std::pair< const_iterator, const_iterator > Range
std::vector< DigiType >::const_iterator const_iterator
int layer() const
Return the layer number.
Definition: DTLayerId.h:42
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:39
HLT enums.
int sector() const
Definition: DTChamberId.h:49
edm::ESHandle< DTGeometry > dtGeom_
Definition: DTTPAnalyzer.cc:37
#define get
DTLayerId layerId() const
Return the corresponding LayerId.
Definition: DTWireId.h:45
int channels() const
Returns the number of wires in the layer.
Definition: DTTopology.h:76
Definition: event.py:1
const DTLayer * layer(const DTLayerId &id) const
Return a layer given its id.
Definition: DTGeometry.cc:96