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