CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
22 class DTTPAnalyzer : public edm::EDAnalyzer {
23 public:
25  virtual ~DTTPAnalyzer();
26 
27  //void beginJob();
28  void beginRun( const edm::Run& , const edm::EventSetup& );
29  void analyze( const edm::Event& , const edm::EventSetup& );
30  void endJob();
31 
32 private:
33  std::string getHistoName( const DTLayerId& );
34 
37 
38  TFile* rootFile_;
39  //const DTT0* tZeroMap_;
42 
43  // Map of the t0 and sigma histos by layer
44  std::map<DTWireId, int> nDigisPerWire_;
45  std::map<DTWireId, double> sumWPerWire_;
46  std::map<DTWireId, double> sumW2PerWire_;
47  //std::map<DTLayerId, TH1F*> meanHistoMap_;
48  //std::map<DTLayerId, TH1F*> sigmaHistoMap_;
49 };
50 
54 
57 
61 
64 
66 
67 #include "TH1F.h"
68 #include "TFile.h"
69 
71  subtractT0_(pset.getParameter<bool>("subtractT0")),
72  digiLabel_(pset.getParameter<edm::InputTag>("digiLabel")),
73  tTrigSync_(0) {
74 
75  std::string rootFileName = pset.getUntrackedParameter<std::string>("rootFileName");
76  rootFile_ = new TFile(rootFileName.c_str(), "RECREATE");
77  rootFile_->cd();
78 
79  if(subtractT0_)
80  tTrigSync_ = DTTTrigSyncFactory::get()->create(pset.getParameter<std::string>("tTrigMode"),
81  pset.getParameter<edm::ParameterSet>("tTrigModeConfig"));
82 
83 }
84 
86  rootFile_->Close();
87 }
88 
90  // Get the t0 map from the DB
91  if(subtractT0_){
92  /*ESHandle<DTT0> t0;
93  setup.get<DTT0Rcd>().get(t0);
94  tZeroMap_ = &*t0;*/
95  tTrigSync_->setES(setup);
96  }
97  // Get the DT Geometry
98  setup.get<MuonGeometryRecord>().get(dtGeom_);
99 }
100 
102 
103  // Get the digis from the event
105  event.getByLabel(digiLabel_, digis);
106 
107  // Iterate through all digi collections ordered by LayerId
109  for (dtLayerIt = digis->begin();
110  dtLayerIt != digis->end();
111  ++dtLayerIt){
112  // Get the iterators over the digis associated with this LayerId
113  const DTDigiCollection::Range& digiRange = (*dtLayerIt).second;
114 
115  // Get the layerId
116  const DTLayerId layerId = (*dtLayerIt).first; //FIXME: check to be in the right sector
117 
118  // Loop over all digis in the given layer
119  for (DTDigiCollection::const_iterator digi = digiRange.first;
120  digi != digiRange.second;
121  digi++) {
122  const DTWireId wireId( layerId, (*digi).wire() );
123 
124  double t0 = (*digi).countsTDC();
125 
126  //FIXME: Reject digis not coming from TP
127 
128  if(subtractT0_) {
129  const DTLayer* layer = 0; //fake
130  const GlobalPoint glPt; //fake
131  double offset = tTrigSync_->offset(layer, wireId, glPt);
132  t0 -= offset;
133  }
134 
135  if(nDigisPerWire_.find(wireId) == nDigisPerWire_.end()){
136  nDigisPerWire_[wireId] = 0;
137  sumWPerWire_[wireId] = 0.;
138  sumW2PerWire_[wireId] = 0.;
139  }
140 
141  ++nDigisPerWire_[wireId];
142  sumWPerWire_[wireId] += t0;
143  sumW2PerWire_[wireId] += t0*t0;
144  }
145 
146  }
147 }
148 
150  rootFile_->cd();
151  std::map<DTLayerId, TH1F*> meanHistoMap;
152  std::map<DTLayerId, TH1F*> sigmaHistoMap;
153  for(std::map<DTWireId, int>::const_iterator wireIdIt = nDigisPerWire_.begin();
154  wireIdIt != nDigisPerWire_.end(); ++wireIdIt){
155  DTWireId wireId((*wireIdIt).first);
156 
157  int nDigis = nDigisPerWire_[wireId];
158  double sumW = sumWPerWire_[wireId];
159  double sumW2 = sumW2PerWire_[wireId];
160 
161  double mean = sumW/nDigis;
162  double rms = sumW2/nDigis - mean*mean;
163  rms = sqrt(rms);
164 
165  DTLayerId layerId = wireId.layerId();
166  if(meanHistoMap.find(layerId) == meanHistoMap.end()) {
167  std::string histoName = getHistoName(layerId);
168  const int firstChannel = dtGeom_->layer(layerId)->specificTopology().firstChannel();
169  const int nWires = dtGeom_->layer(layerId)->specificTopology().channels();
170  TH1F* meanHistoTP = new TH1F((histoName + "_tpMean").c_str(),"mean from test pulses by channel",
171  nWires,firstChannel,(firstChannel + nWires));
172  TH1F* sigmaHistoTP = new TH1F((histoName + "_tpSigma").c_str(),"sigma from test pulses by channel",
173  nWires,firstChannel,(firstChannel + nWires));
174  meanHistoMap[layerId] = meanHistoTP;
175  sigmaHistoMap[layerId] = sigmaHistoTP;
176  }
177  // Fill the histograms
178  int nBin = meanHistoMap[layerId]->GetXaxis()->FindFixBin(wireId.wire());
179  meanHistoMap[layerId]->SetBinContent(nBin,mean);
180  sigmaHistoMap[layerId]->SetBinContent(nBin,rms);
181  }
182 
183  for(std::map<DTLayerId, TH1F*>::const_iterator key = meanHistoMap.begin();
184  key != meanHistoMap.end(); ++key){
185  meanHistoMap[(*key).first]->Write();
186  sigmaHistoMap[(*key).first]->Write();
187  }
188 
189 }
190 
191 std::string DTTPAnalyzer::getHistoName(const DTLayerId& lId) {
192  std::string histoName;
193  std::stringstream theStream;
194  theStream << "Ch_" << lId.wheel() << "_" << lId.station() << "_" << lId.sector()
195  << "_SL" << lId.superlayer() << "_L" << lId.layer();
196  theStream >> histoName;
197  return histoName;
198 }
199 
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
edm::InputTag digiLabel_
Definition: DTTPAnalyzer.cc:36
DTTPAnalyzer(const edm::ParameterSet &)
Definition: DTTPAnalyzer.cc:70
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::map< DTWireId, double > sumWPerWire_
Definition: DTTPAnalyzer.cc:45
double offset(const DTLayer *layer, const DTWireId &wireId, const GlobalPoint &globalPos)
std::map< DTWireId, int > nDigisPerWire_
Definition: DTTPAnalyzer.cc:44
int layer() const
Return the layer number.
Definition: DTLayerId.h:55
DTTTrigBaseSync * tTrigSync_
Definition: DTTPAnalyzer.cc:41
TFile * rootFile_
Definition: DTTPAnalyzer.cc:38
std::string getHistoName(const DTLayerId &)
virtual void setES(const edm::EventSetup &setup)=0
Pass the Event Setup to the synchronization module at each event.
T sqrt(T t)
Definition: SSEVec.h:46
virtual ~DTTPAnalyzer()
Definition: DTTPAnalyzer.cc:85
unsigned int offset(bool)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
std::map< DTWireId, double > sumW2PerWire_
Definition: DTTPAnalyzer.cc:46
void analyze(const edm::Event &, const edm::EventSetup &)
int wire() const
Return the wire number.
Definition: DTWireId.h:58
int superlayer() const
Return the superlayer number (deprecated method name)
void beginRun(const edm::Run &, const edm::EventSetup &)
Definition: DTTPAnalyzer.cc:89
const T & get() const
Definition: EventSetup.h:55
std::vector< DigiType >::const_iterator const_iterator
DTLayerId layerId() const
Return the corresponding LayerId.
Definition: DTWireId.h:64
list key
Definition: combine.py:13
int sector() const
Definition: DTChamberId.h:63
std::pair< const_iterator, const_iterator > Range
edm::ESHandle< DTGeometry > dtGeom_
Definition: DTTPAnalyzer.cc:40
int station() const
Return the station number.
Definition: DTChamberId.h:53
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:47
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
T get(const Candidate &c)
Definition: component.h:56
Definition: Run.h:33