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")) {
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
90  setup.get<MuonGeometryRecord>().get(dtGeom_);
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 
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
edm::InputTag digiLabel_
Definition: DTTPAnalyzer.cc:34
DTTPAnalyzer(const edm::ParameterSet &)
Definition: DTTPAnalyzer.cc:68
std::map< DTWireId, double > sumWPerWire_
Definition: DTTPAnalyzer.cc:43
std::map< DTWireId, int > nDigisPerWire_
Definition: DTTPAnalyzer.cc:42
int layer() const
Return the layer number.
Definition: DTLayerId.h:42
int firstChannel() const
Returns the wire number of the first wire.
Definition: DTTopology.h:79
TFile * rootFile_
Definition: DTTPAnalyzer.cc:36
std::string getHistoName(const DTLayerId &)
void endJob() override
const DTTopology & specificTopology() const
Definition: DTLayer.cc:37
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
T sqrt(T t)
Definition: SSEVec.h:19
~DTTPAnalyzer() override
Definition: DTTPAnalyzer.cc:79
std::unique_ptr< DTTTrigBaseSync > tTrigSync_
Definition: DTTPAnalyzer.cc:39
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: DTTPAnalyzer.cc:93
std::map< DTWireId, double > sumW2PerWire_
Definition: DTTPAnalyzer.cc:44
int wire() const
Return the wire number.
Definition: DTWireId.h:42
int superlayer() const
Return the superlayer number (deprecated method name)
int channels() const
Returns the number of wires in the layer.
Definition: DTTopology.h:76
std::pair< const_iterator, const_iterator > Range
std::vector< DigiType >::const_iterator const_iterator
void beginRun(const edm::Run &, const edm::EventSetup &) override
Definition: DTTPAnalyzer.cc:81
DTLayerId layerId() const
Return the corresponding LayerId.
Definition: DTWireId.h:45
HLT enums.
int sector() const
Definition: DTChamberId.h:49
T get() const
Definition: EventSetup.h:73
const DTLayer * layer(const DTLayerId &id) const
Return a layer given its id.
Definition: DTGeometry.cc:96
edm::ESHandle< DTGeometry > dtGeom_
Definition: DTTPAnalyzer.cc:38
int station() const
Return the station number.
Definition: DTChamberId.h:42
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:39
Definition: event.py:1
Definition: Run.h:45