45 digiLabel_( pset.getParameter<
InputTag>(
"digiLabel") ),
46 useTimeWindow_( pset.getParameter<bool>(
"useTimeWindow") ),
47 triggerWidth_( pset.getParameter<double>(
"triggerWidth") ),
48 timeWindowOffset_( pset.getParameter<int>(
"timeWindowOffset") ),
49 maximumNoiseRate_( pset.getParameter<double>(
"maximumNoiseRate") ),
50 useAbsoluteRate_( pset.getParameter<bool>(
"useAbsoluteRate") ),
51 readDB_(
true), defaultTtrig_(0),
52 dbLabel_( pset.getUntrackedParameter<string>(
"dbLabel",
"") ),
54 wireIdWithHisto_( std::vector<
DTWireId>() ),
65 if( pset.
exists(
"defaultTtrig") ){
70 if( pset.
exists(
"cellsWithHisto") ){
71 vector<string> cellsWithHisto = pset.
getParameter<vector<string> >(
"cellsWithHisto");
72 for(vector<string>::const_iterator cell = cellsWithHisto.begin(); cell != cellsWithHisto.end(); ++cell){
74 if( (*cell) !=
"" && (*cell) !=
"None"){
76 int wheel,
station,sector,sl,layer,wire;
78 linestr >> wheel >> station >> sector >> sl >> layer >> wire;
86 rootFile_ =
new TFile(rootFileName.c_str(),
"RECREATE");
91 LogVerbatim(
"Calibration") <<
"[DTNoiseCalibration]: Begin job";
95 TH1::SetDefaultSumw2(
true);
96 int numBin = (triggerWidth_*32/25)/50;
97 hTDCTriggerWidth_ =
new TH1F(
"TDC_Time_Distribution",
"TDC_Time_Distribution", numBin, 0, triggerWidth_*32/25);
106 if( readDB_ ) setup.
get<
DTTtrigRcd>().
get(dbLabel_,tTrigMap_);
125 event.getByLabel(digiLabel_, dtdigis);
132 time_t eventTime = time_t(event.
time().
value()>>32);
133 unsigned int lumiSection =
event.luminosityBlock();
137 for (dtLayerId_It=dtdigis->begin(); dtLayerId_It!=dtdigis->end(); ++dtLayerId_It){
139 float upperLimit = 0.;
142 float tTrig,tTrigRMS,kFactor;
145 if(status != 0)
throw cms::Exception(
"DTNoiseCalibration") <<
"Could not find tTrig entry in DB for" << slId << endl;
146 upperLimit = tTrig - timeWindowOffset_;
148 upperLimit = defaultTtrig_ - timeWindowOffset_;
152 double triggerWidth_s = 0.;
153 if(useTimeWindow_) triggerWidth_s = ( (upperLimit*25)/32 )/1e9;
154 else triggerWidth_s = double(triggerWidth_/1e9);
155 LogTrace(
"Calibration") << ((*dtLayerId_It).first).superlayerId() <<
" Trigger width (s): " << triggerWidth_s;
158 digiIt!=((*dtLayerId_It).second).
second; ++digiIt){
161 int tdcTime = (*digiIt).countsTDC();
162 if( !useTimeWindow_ ){
163 if( ( ((
float)tdcTime*25)/32 ) > triggerWidth_ ){
164 LogError(
"Calibration") <<
"Digi has a TDC time (ns) higher than the pre-defined TDC trigger width: " << ((float)tdcTime*25)/32;
169 hTDCTriggerWidth_->Fill(tdcTime);
171 if( useTimeWindow_ && tdcTime > upperLimit)
continue;
176 const DTLayerId dtLId = (*dtLayerId_It).first;
177 const DTTopology& dtTopo = dtGeom_->layer(dtLId)->specificTopology();
181 const int nWires = lastWire - firstWire + 1;
184 if( theHistoOccupancyMap_.find(dtLId) == theHistoOccupancyMap_.end() ){
185 string histoName =
"DigiOccupancy_" + getLayerName(dtLId);
187 TH1F* hOccupancyHisto =
new TH1F(histoName.c_str(), histoName.c_str(), nWires, firstWire, lastWire+1);
188 LogTrace(
"Calibration") <<
" Created occupancy Histo: " << hOccupancyHisto->GetName();
189 theHistoOccupancyMap_[dtLId] = hOccupancyHisto;
191 theHistoOccupancyMap_[dtLId]->Fill( (*digiIt).wire(), 1./triggerWidth_s );
195 if( chamberOccupancyVsLumiMap_.find(dtChId) == chamberOccupancyVsLumiMap_.end() ){
196 string histoName =
"OccupancyVsLumi_" + getChamberName(dtChId);
198 TH1F* hOccupancyVsLumiHisto =
new TH1F(histoName.c_str(), histoName.c_str(), lumiMax_, 0, lumiMax_);
199 LogTrace(
"Calibration") <<
" Created occupancy histo: " << hOccupancyVsLumiHisto->GetName();
200 chamberOccupancyVsLumiMap_[dtChId] = hOccupancyVsLumiHisto;
202 chamberOccupancyVsLumiMap_[dtChId]->Fill( lumiSection, 1./triggerWidth_s );
204 const DTWireId wireId(dtLId, (*digiIt).wire());
205 if(
find(wireIdWithHisto_.begin(),wireIdWithHisto_.end(),wireId) != wireIdWithHisto_.end() ){
206 if( theHistoOccupancyVsLumiMap_.find(wireId) == theHistoOccupancyVsLumiMap_.end() ){
207 string histoName =
"OccupancyVsLumi_" + getChannelName(wireId);
209 TH1F* hOccupancyVsLumiHisto =
new TH1F(histoName.c_str(), histoName.c_str(), lumiMax_, 0, lumiMax_);
210 LogTrace(
"Calibration") <<
" Created occupancy histo: " << hOccupancyVsLumiHisto->GetName();
211 theHistoOccupancyVsLumiMap_[wireId] = hOccupancyVsLumiHisto;
213 theHistoOccupancyVsLumiMap_[wireId]->Fill( lumiSection, 1./triggerWidth_s );
217 if( chamberOccupancyVsTimeMap_.find(dtChId) == chamberOccupancyVsTimeMap_.end() ){
218 string histoName =
"OccupancyVsTime_" + getChamberName(dtChId);
219 float secPerBin = 20.0;
220 unsigned int nBins = ( (
unsigned int)(runEndTime_ - runBeginTime_) )/secPerBin;
222 TH1F* hOccupancyVsTimeHisto =
new TH1F(histoName.c_str(), histoName.c_str(),
223 nBins, (
unsigned int)runBeginTime_,
224 (
unsigned int)runEndTime_);
225 for(
int k = 0;
k < hOccupancyVsTimeHisto->GetNbinsX(); ++
k){
227 unsigned int binLowEdge = hOccupancyVsTimeHisto->GetBinLowEdge(
k+1);
228 time_t timeValue = time_t(binLowEdge);
229 hOccupancyVsTimeHisto->GetXaxis()->SetBinLabel( (
k+1),ctime(&timeValue) );
232 size_t lastBin = hOccupancyVsTimeHisto->GetNbinsX();
233 unsigned int binUpperEdge = hOccupancyVsTimeHisto->GetBinLowEdge(lastBin) +
234 hOccupancyVsTimeHisto->GetBinWidth(lastBin);
235 time_t timeValue = time_t(binUpperEdge);
236 hOccupancyVsTimeHisto->GetXaxis()->SetBinLabel( (lastBin),ctime(&timeValue) );
238 LogTrace(
"Calibration") <<
" Created occupancy histo: " << hOccupancyVsTimeHisto->GetName();
239 chamberOccupancyVsTimeMap_[dtChId] = hOccupancyVsTimeHisto;
241 chamberOccupancyVsTimeMap_[dtChId]->Fill( (
unsigned int)eventTime, 1./triggerWidth_s );
332 LogVerbatim(
"Calibration") <<
"[DTNoiseCalibration] Total number of events analyzed: " << nevents_;
336 hTDCTriggerWidth_->Write();
338 double normalization = 1./double(nevents_);
340 for(map<DTWireId, TH1F*>::const_iterator wHisto = theHistoOccupancyVsLumiMap_.begin();
341 wHisto != theHistoOccupancyVsLumiMap_.end(); ++wHisto){
342 (*wHisto).second->Scale(normalization);
343 (*wHisto).second->Write();
346 for(map<DTChamberId, TH1F*>::const_iterator chHisto = chamberOccupancyVsLumiMap_.begin();
347 chHisto != chamberOccupancyVsLumiMap_.end(); ++chHisto){
348 (*chHisto).second->Scale(normalization);
349 (*chHisto).second->Write();
352 for(map<DTChamberId, TH1F*>::const_iterator chHisto = chamberOccupancyVsTimeMap_.begin();
353 chHisto != chamberOccupancyVsTimeMap_.end(); ++chHisto){
354 (*chHisto).second->Scale(normalization);
355 (*chHisto).second->Write();
360 for(map<DTLayerId, TH1F*>::const_iterator lHisto = theHistoOccupancyMap_.begin();
361 lHisto != theHistoOccupancyMap_.end();
383 if((*lHisto).second){
384 (*lHisto).second->Scale(normalization);
386 (*lHisto).second->Write();
387 const DTTopology& dtTopo = dtGeom_->layer((*lHisto).first)->specificTopology();
391 const int nWires = lastWire - firstWire + 1;
393 double averageRate = 0.;
394 for(
int bin = 1;
bin <= (*lHisto).second->GetNbinsX(); ++
bin)
395 averageRate += (*lHisto).second->GetBinContent(
bin);
397 if(nWires) averageRate /= nWires;
398 LogTrace(
"Calibration") <<
" Average rate = " << averageRate;
400 for(
int i_wire = firstWire; i_wire <= lastWire; ++i_wire){
402 int bin = i_wire - firstWire + 1;
403 double channelRate = (*lHisto).second->GetBinContent(bin);
404 double rateOffset = (useAbsoluteRate_) ? 0. : averageRate;
405 if( (channelRate - rateOffset) > maximumNoiseRate_ ){
406 DTWireId wireID((*lHisto).first, i_wire);
408 LogVerbatim(
"Calibration") <<
">>> Channel noisy: " << wireID;
413 LogVerbatim(
"Calibration") <<
"Writing noise map object to DB";
414 string record =
"DTStatusFlagRcd";
423 stringstream channelName;
424 channelName <<
"Wh" << wId.
wheel() <<
"_St" << wId.
station() <<
"_Sec" << wId.
sector()
427 return channelName.str();
434 stringstream Layer; Layer << lId.
layer();
435 stringstream superLayer; superLayer << dtSLId.
superlayer();
436 stringstream wheel; wheel << dtChId.
wheel();
438 stringstream sector; sector << dtChId.
sector();
442 +
"_St" + station.str()
443 +
"_Sec" + sector.str()
444 +
"_SL" + superLayer.str()
445 +
"_L" + Layer.str();
453 stringstream superLayer; superLayer << dtSLId.
superlayer();
454 stringstream wheel; wheel << dtChId.
wheel();
456 stringstream sector; sector << dtChId.
sector();
458 string superLayerName =
460 +
"_St" + station.str()
461 +
"_Sec" + sector.str()
462 +
"_SL" + superLayer.str();
464 return superLayerName;
469 stringstream wheel; wheel << dtChId.
wheel();
471 stringstream sector; sector << dtChId.
sector();
475 +
"_St" + station.str()
476 +
"_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.
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)
TimeValue_t value() const
std::vector< DigiType >::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="")
std::string getSuperLayerName(const DTSuperLayerId &) const
edm::Timestamp time() const