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")),
70  digiLabel_(pset.getParameter<edm::InputTag>("digiLabel")) {
71 
73  rootFile_ = new TFile(rootFileName.c_str(), "RECREATE");
74  rootFile_->cd();
75 
76  if(subtractT0_)
77  tTrigSync_ = std::unique_ptr<DTTTrigBaseSync>{DTTTrigSyncFactory::get()->create(pset.getParameter<std::string>("tTrigMode"),
78  pset.getParameter<edm::ParameterSet>("tTrigModeConfig"))};
79 
80 }
81 
83  rootFile_->Close();
84 }
85 
87  // Get the t0 map from the DB
88  if(subtractT0_){
89  /*ESHandle<DTT0> t0;
90  setup.get<DTT0Rcd>().get(t0);
91  tZeroMap_ = &*t0;*/
92  tTrigSync_->setES(setup);
93  }
94  // Get the DT Geometry
95  setup.get<MuonGeometryRecord>().get(dtGeom_);
96 }
97 
99 
100  // Get the digis from the event
102  event.getByLabel(digiLabel_, digis);
103 
104  // Iterate through all digi collections ordered by LayerId
106  for (dtLayerIt = digis->begin();
107  dtLayerIt != digis->end();
108  ++dtLayerIt){
109  // Get the iterators over the digis associated with this LayerId
110  const DTDigiCollection::Range& digiRange = (*dtLayerIt).second;
111 
112  // Get the layerId
113  const DTLayerId layerId = (*dtLayerIt).first; //FIXME: check to be in the right sector
114 
115  // Loop over all digis in the given layer
116  for (DTDigiCollection::const_iterator digi = digiRange.first;
117  digi != digiRange.second;
118  ++digi) {
119  const DTWireId wireId( layerId, (*digi).wire() );
120 
121  double t0 = (*digi).countsTDC();
122 
123  //FIXME: Reject digis not coming from TP
124 
125  if(subtractT0_) {
126  const DTLayer* layer = nullptr; //fake
127  const GlobalPoint glPt; //fake
128  double offset = tTrigSync_->offset(layer, wireId, glPt);
129  t0 -= offset;
130  }
131 
132  if(nDigisPerWire_.find(wireId) == nDigisPerWire_.end()){
133  nDigisPerWire_[wireId] = 0;
134  sumWPerWire_[wireId] = 0.;
135  sumW2PerWire_[wireId] = 0.;
136  }
137 
138  ++nDigisPerWire_[wireId];
139  sumWPerWire_[wireId] += t0;
140  sumW2PerWire_[wireId] += t0*t0;
141  }
142 
143  }
144 }
145 
147  rootFile_->cd();
148  std::map<DTLayerId, TH1F*> meanHistoMap;
149  std::map<DTLayerId, TH1F*> sigmaHistoMap;
150  for(std::map<DTWireId, int>::const_iterator wireIdIt = nDigisPerWire_.begin();
151  wireIdIt != nDigisPerWire_.end(); ++wireIdIt){
152  DTWireId wireId((*wireIdIt).first);
153 
154  int nDigis = nDigisPerWire_[wireId];
155  double sumW = sumWPerWire_[wireId];
156  double sumW2 = sumW2PerWire_[wireId];
157 
158  double mean = sumW/nDigis;
159  double rms = sumW2/nDigis - mean*mean;
160  rms = sqrt(rms);
161 
162  DTLayerId layerId = wireId.layerId();
163  if(meanHistoMap.find(layerId) == meanHistoMap.end()) {
164  std::string histoName = getHistoName(layerId);
165  const int firstChannel = dtGeom_->layer(layerId)->specificTopology().firstChannel();
166  const int nWires = dtGeom_->layer(layerId)->specificTopology().channels();
167  TH1F* meanHistoTP = new TH1F((histoName + "_tpMean").c_str(),"mean from test pulses by channel",
168  nWires,firstChannel,(firstChannel + nWires));
169  TH1F* sigmaHistoTP = new TH1F((histoName + "_tpSigma").c_str(),"sigma from test pulses by channel",
170  nWires,firstChannel,(firstChannel + nWires));
171  meanHistoMap[layerId] = meanHistoTP;
172  sigmaHistoMap[layerId] = sigmaHistoTP;
173  }
174  // Fill the histograms
175  int nBin = meanHistoMap[layerId]->GetXaxis()->FindFixBin(wireId.wire());
176  meanHistoMap[layerId]->SetBinContent(nBin,mean);
177  sigmaHistoMap[layerId]->SetBinContent(nBin,rms);
178  }
179 
180  for(std::map<DTLayerId, TH1F*>::const_iterator key = meanHistoMap.begin();
181  key != meanHistoMap.end(); ++key){
182  meanHistoMap[(*key).first]->Write();
183  sigmaHistoMap[(*key).first]->Write();
184  }
185 
186 }
187 
189  std::string histoName;
190  std::stringstream theStream;
191  theStream << "Ch_" << lId.wheel() << "_" << lId.station() << "_" << lId.sector()
192  << "_SL" << lId.superlayer() << "_L" << lId.layer();
193  theStream >> histoName;
194  return histoName;
195 }
196 
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
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
std::map< DTWireId, int > nDigisPerWire_
Definition: DTTPAnalyzer.cc:42
int layer() const
Return the layer number.
Definition: DTLayerId.h:53
int firstChannel() const
Returns the wire number of the first wire.
Definition: DTTopology.h:78
TFile * rootFile_
Definition: DTTPAnalyzer.cc:36
std::string getHistoName(const DTLayerId &)
void endJob() override
const DTTopology & specificTopology() const
Definition: DTLayer.cc:42
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
T sqrt(T t)
Definition: SSEVec.h:18
~DTTPAnalyzer() override
Definition: DTTPAnalyzer.cc:82
std::unique_ptr< DTTTrigBaseSync > tTrigSync_
Definition: DTTPAnalyzer.cc:39
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: DTTPAnalyzer.cc:98
std::map< DTWireId, double > sumW2PerWire_
Definition: DTTPAnalyzer.cc:44
int wire() const
Return the wire number.
Definition: DTWireId.h:56
int superlayer() const
Return the superlayer number (deprecated method name)
int channels() const
Returns the number of wires in the layer.
Definition: DTTopology.h:75
std::vector< DigiType >::const_iterator const_iterator
void beginRun(const edm::Run &, const edm::EventSetup &) override
Definition: DTTPAnalyzer.cc:86
DTLayerId layerId() const
Return the corresponding LayerId.
Definition: DTWireId.h:62
HLT enums.
int sector() const
Definition: DTChamberId.h:61
T get() const
Definition: EventSetup.h:71
std::pair< const_iterator, const_iterator > Range
const DTLayer * layer(const DTLayerId &id) const
Return a layer given its id.
Definition: DTGeometry.cc:127
edm::ESHandle< DTGeometry > dtGeom_
Definition: DTTPAnalyzer.cc:38
int station() const
Return the station number.
Definition: DTChamberId.h:51
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:45
T get(const Candidate &c)
Definition: component.h:55
Definition: event.py:1
Definition: Run.h:45