43 digiLabel_( pset.getParameter<
InputTag>(
"digiLabel") ),
44 useTimeWindow_( pset.getParameter<bool>(
"useTimeWindow") ),
45 triggerWidth_( pset.getParameter<double>(
"triggerWidth") ),
46 timeWindowOffset_( pset.getParameter<int>(
"timeWindowOffset") ),
47 maximumNoiseRate_( pset.getParameter<double>(
"maximumNoiseRate") ),
48 useAbsoluteRate_( pset.getParameter<bool>(
"useAbsoluteRate") ),
49 readDB_(
true), defaultTtrig_(0),
50 dbLabel_( pset.getUntrackedParameter<
string>(
"dbLabel",
"") ),
52 wireIdWithHisto_( std::vector<
DTWireId>() ),
63 if( pset.
exists(
"defaultTtrig") ){
68 if( pset.
exists(
"cellsWithHisto") ){
69 vector<string> cellsWithHisto = pset.
getParameter<vector<string> >(
"cellsWithHisto");
70 for(vector<string>::const_iterator cell = cellsWithHisto.begin(); cell != cellsWithHisto.end(); ++cell){
72 if( (*cell) !=
"" && (*cell) !=
"None"){
74 int wheel,
station,sector,sl,layer,wire;
76 linestr >> wheel >> station >> sector >> sl >> layer >> wire;
84 rootFile_ =
new TFile(rootFileName.c_str(),
"RECREATE");
89 LogVerbatim(
"Calibration") <<
"[DTNoiseCalibration]: Begin job";
93 TH1::SetDefaultSumw2(
true);
94 int numBin = (triggerWidth_*32/25)/50;
95 hTDCTriggerWidth_ =
new TH1F(
"TDC_Time_Distribution",
"TDC_Time_Distribution", numBin, 0, triggerWidth_*32/25);
104 if( readDB_ ) setup.
get<
DTTtrigRcd>().
get(dbLabel_,tTrigMap_);
123 event.getByLabel(digiLabel_, dtdigis);
130 time_t eventTime = time_t(event.
time().
value()>>32);
131 unsigned int lumiSection =
event.luminosityBlock();
135 for (dtLayerId_It=dtdigis->begin(); dtLayerId_It!=dtdigis->end(); ++dtLayerId_It){
137 float upperLimit = 0.;
140 float tTrig,tTrigRMS,kFactor;
143 if(status != 0)
throw cms::Exception(
"DTNoiseCalibration") <<
"Could not find tTrig entry in DB for" << slId << endl;
144 upperLimit = tTrig - timeWindowOffset_;
146 upperLimit = defaultTtrig_ - timeWindowOffset_;
150 double triggerWidth_s = 0.;
151 if(useTimeWindow_) triggerWidth_s = ( (upperLimit*25)/32 )/1e9;
152 else triggerWidth_s = double(triggerWidth_/1e9);
153 LogTrace(
"Calibration") << ((*dtLayerId_It).first).superlayerId() <<
" Trigger width (s): " << triggerWidth_s;
156 digiIt!=((*dtLayerId_It).second).
second; ++digiIt){
159 int tdcTime = (*digiIt).countsTDC();
160 if( !useTimeWindow_ ){
161 if( ( ((
float)tdcTime*25)/32 ) > triggerWidth_ ){
162 LogError(
"Calibration") <<
"Digi has a TDC time (ns) higher than the pre-defined TDC trigger width: " << ((float)tdcTime*25)/32;
167 hTDCTriggerWidth_->Fill(tdcTime);
169 if( useTimeWindow_ && tdcTime > upperLimit)
continue;
174 const DTLayerId dtLId = (*dtLayerId_It).first;
175 const DTTopology& dtTopo = dtGeom_->layer(dtLId)->specificTopology();
179 const int nWires = lastWire - firstWire + 1;
182 if( theHistoOccupancyMap_.find(dtLId) == theHistoOccupancyMap_.end() ){
183 string histoName =
"DigiOccupancy_" + getLayerName(dtLId);
185 TH1F* hOccupancyHisto =
new TH1F(histoName.c_str(), histoName.c_str(), nWires, firstWire, lastWire+1);
186 LogTrace(
"Calibration") <<
" Created occupancy Histo: " << hOccupancyHisto->GetName();
187 theHistoOccupancyMap_[dtLId] = hOccupancyHisto;
189 theHistoOccupancyMap_[dtLId]->Fill( (*digiIt).wire(), 1./triggerWidth_s );
193 if( chamberOccupancyVsLumiMap_.find(dtChId) == chamberOccupancyVsLumiMap_.end() ){
194 string histoName =
"OccupancyVsLumi_" + getChamberName(dtChId);
196 TH1F* hOccupancyVsLumiHisto =
new TH1F(histoName.c_str(), histoName.c_str(), lumiMax_, 0, lumiMax_);
197 LogTrace(
"Calibration") <<
" Created occupancy histo: " << hOccupancyVsLumiHisto->GetName();
198 chamberOccupancyVsLumiMap_[dtChId] = hOccupancyVsLumiHisto;
200 chamberOccupancyVsLumiMap_[dtChId]->Fill( lumiSection, 1./triggerWidth_s );
202 const DTWireId wireId(dtLId, (*digiIt).wire());
203 if(
find(wireIdWithHisto_.begin(),wireIdWithHisto_.end(),wireId) != wireIdWithHisto_.end() ){
204 if( theHistoOccupancyVsLumiMap_.find(wireId) == theHistoOccupancyVsLumiMap_.end() ){
205 string histoName =
"OccupancyVsLumi_" + getChannelName(wireId);
207 TH1F* hOccupancyVsLumiHisto =
new TH1F(histoName.c_str(), histoName.c_str(), lumiMax_, 0, lumiMax_);
208 LogTrace(
"Calibration") <<
" Created occupancy histo: " << hOccupancyVsLumiHisto->GetName();
209 theHistoOccupancyVsLumiMap_[wireId] = hOccupancyVsLumiHisto;
211 theHistoOccupancyVsLumiMap_[wireId]->Fill( lumiSection, 1./triggerWidth_s );
215 if( chamberOccupancyVsTimeMap_.find(dtChId) == chamberOccupancyVsTimeMap_.end() ){
216 string histoName =
"OccupancyVsTime_" + getChamberName(dtChId);
217 float secPerBin = 20.0;
218 unsigned int nBins = ( (
unsigned int)(runEndTime_ - runBeginTime_) )/secPerBin;
220 TH1F* hOccupancyVsTimeHisto =
new TH1F(histoName.c_str(), histoName.c_str(),
221 nBins, (
unsigned int)runBeginTime_,
222 (
unsigned int)runEndTime_);
223 for(
int k = 0;
k < hOccupancyVsTimeHisto->GetNbinsX(); ++
k){
225 unsigned int binLowEdge = hOccupancyVsTimeHisto->GetBinLowEdge(
k+1);
226 time_t timeValue = time_t(binLowEdge);
227 hOccupancyVsTimeHisto->GetXaxis()->SetBinLabel( (
k+1),ctime(&timeValue) );
230 size_t lastBin = hOccupancyVsTimeHisto->GetNbinsX();
231 unsigned int binUpperEdge = hOccupancyVsTimeHisto->GetBinLowEdge(lastBin) +
232 hOccupancyVsTimeHisto->GetBinWidth(lastBin);
233 time_t timeValue = time_t(binUpperEdge);
234 hOccupancyVsTimeHisto->GetXaxis()->SetBinLabel( (lastBin),ctime(&timeValue) );
236 LogTrace(
"Calibration") <<
" Created occupancy histo: " << hOccupancyVsTimeHisto->GetName();
237 chamberOccupancyVsTimeMap_[dtChId] = hOccupancyVsTimeHisto;
239 chamberOccupancyVsTimeMap_[dtChId]->Fill( (
unsigned int)eventTime, 1./triggerWidth_s );
330 LogVerbatim(
"Calibration") <<
"[DTNoiseCalibration] Total number of events analyzed: " << nevents_;
334 hTDCTriggerWidth_->Write();
336 double normalization = 1./double(nevents_);
338 for(map<DTWireId, TH1F*>::const_iterator wHisto = theHistoOccupancyVsLumiMap_.begin();
339 wHisto != theHistoOccupancyVsLumiMap_.end(); ++wHisto){
340 (*wHisto).second->Scale(normalization);
341 (*wHisto).second->Write();
344 for(map<DTChamberId, TH1F*>::const_iterator chHisto = chamberOccupancyVsLumiMap_.begin();
345 chHisto != chamberOccupancyVsLumiMap_.end(); ++chHisto){
346 (*chHisto).second->Scale(normalization);
347 (*chHisto).second->Write();
350 for(map<DTChamberId, TH1F*>::const_iterator chHisto = chamberOccupancyVsTimeMap_.begin();
351 chHisto != chamberOccupancyVsTimeMap_.end(); ++chHisto){
352 (*chHisto).second->Scale(normalization);
353 (*chHisto).second->Write();
358 for(map<DTLayerId, TH1F*>::const_iterator lHisto = theHistoOccupancyMap_.begin();
359 lHisto != theHistoOccupancyMap_.end();
381 if((*lHisto).second){
382 (*lHisto).second->Scale(normalization);
384 (*lHisto).second->Write();
385 const DTTopology& dtTopo = dtGeom_->layer((*lHisto).first)->specificTopology();
389 const int nWires = lastWire - firstWire + 1;
391 double averageRate = 0.;
392 for(
int bin = 1;
bin <= (*lHisto).second->GetNbinsX(); ++
bin)
393 averageRate += (*lHisto).second->GetBinContent(
bin);
395 if(nWires) averageRate /= nWires;
396 LogTrace(
"Calibration") <<
" Average rate = " << averageRate;
398 for(
int i_wire = firstWire; i_wire <= lastWire; ++i_wire){
400 int bin = i_wire - firstWire + 1;
401 double channelRate = (*lHisto).second->GetBinContent(bin);
402 double rateOffset = (useAbsoluteRate_) ? 0. : averageRate;
403 if( (channelRate - rateOffset) > maximumNoiseRate_ ){
404 DTWireId wireID((*lHisto).first, i_wire);
406 LogVerbatim(
"Calibration") <<
">>> Channel noisy: " << wireID;
411 LogVerbatim(
"Calibration") <<
"Writing noise map object to DB";
412 string record =
"DTStatusFlagRcd";
421 stringstream channelName;
422 channelName <<
"Wh" << wId.
wheel() <<
"_St" << wId.
station() <<
"_Sec" << wId.
sector()
425 return channelName.str();
433 stringstream superLayer; superLayer << dtSLId.
superlayer();
434 stringstream wheel; wheel << dtChId.
wheel();
436 stringstream sector; sector << dtChId.
sector();
440 +
"_St" + station.str()
441 +
"_Sec" + sector.str()
442 +
"_SL" + superLayer.str()
443 +
"_L" + Layer.str();
451 stringstream superLayer; superLayer << dtSLId.
superlayer();
452 stringstream wheel; wheel << dtChId.
wheel();
454 stringstream sector; sector << dtChId.
sector();
456 string superLayerName =
458 +
"_St" + station.str()
459 +
"_Sec" + sector.str()
460 +
"_SL" + superLayer.str();
462 return superLayerName;
467 stringstream wheel; wheel << dtChId.
wheel();
469 stringstream sector; sector << dtChId.
sector();
473 +
"_St" + station.str()
474 +
"_Sec" + sector.str();
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
Timestamp const & endTime() const
DTChamberId chamberId() const
Return the corresponding ChamberId.
std::vector< DTWireId > wireIdWithHisto_
bool exists(std::string const ¶meterName) const
checks if a parameter exists
std::string getChannelName(const DTWireId &) const
int layer() const
Return the layer number.
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
std::string getChamberName(const DTChamberId &) const
int firstChannel() const
Returns the wire number of the first wire.
std::string getLayerName(const DTLayerId &) const
DTNoiseCalibration(const edm::ParameterSet &ps)
Constructor.
SeedingLayerSetsHits::SeedingLayer Layer
U second(std::pair< T, U > const &p)
int lastChannel() const
Returns the wire number of the last wire.
int setCellNoise(int wheelId, int stationId, int sectorId, int slId, int layerId, int cellId, bool flag)
void beginRun(const edm::Run &run, const edm::EventSetup &setup)
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
virtual ~DTNoiseCalibration()
Destructor.
void analyze(const edm::Event &e, const edm::EventSetup &c)
int wire() const
Return the wire number.
int superlayer() const
Return the superlayer number (deprecated method name)
std::vector< DTDigi >::const_iterator const_iterator
Timestamp const & beginTime() const
int station() const
Return the station number.
int wheel() const
Return the wheel number.
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
TimeValue_t value() const
std::string getSuperLayerName(const DTSuperLayerId &) const
edm::Timestamp time() const