CMS 3D CMS Logo

Classes | Public Member Functions | Private Member Functions | Private Attributes

DTNoiseCalibration Class Reference

#include <DTNoiseCalibration.h>

Inheritance diagram for DTNoiseCalibration:
edm::EDAnalyzer

List of all members.

Classes

class  DTNoiseCalibration

Public Member Functions

void analyze (const edm::Event &e, const edm::EventSetup &c)
void beginJob ()
void beginRun (const edm::Run &run, const edm::EventSetup &setup)
 DTNoiseCalibration (const edm::ParameterSet &ps)
 Constructor.
void endJob ()
virtual ~DTNoiseCalibration ()
 Destructor.

Private Member Functions

std::string getChannelName (const DTWireId &wId) const
std::string getLayerName (const DTLayerId &lId) const
std::string getSuperLayerName (const DTSuperLayerId &dtSLId) const

Private Attributes

std::string dbLabel_
int defaultTtrig_
edm::InputTag digiLabel_
edm::ESHandle< DTGeometrydtGeom_
TH1F * hTDCTriggerWidth_
unsigned int lumiMax_
double maximumNoiseRate_
int nevents_
bool readDB_
TFile * rootFile_
std::map< DTLayerId, TH1F * > theHistoOccupancyMap_
std::map< DTWireId, TH1F * > theHistoOccupancyVsLumiMap_
int timeWindowOffset_
int triggerWidth_
edm::ESHandle< DTTtrigtTrigMap_
bool useAbsoluteRate_
bool useTimeWindow_
std::vector< DTWireIdwireIdWithHisto_

Detailed Description

Definition at line 30 of file DTNoiseCalibration.h.


Constructor & Destructor Documentation

Constructor.

Definition at line 42 of file DTNoiseCalibration.cc.

References dtT0WireCalibration_cfg::cellsWithHisto, defaultTtrig_, edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), readDB_, rootFile_, dtT0WireCalibration_cfg::rootFileName, relativeConstraints::station, and wireIdWithHisto_.

                                                                 :
  digiLabel_( pset.getParameter<InputTag>("digiLabel") ),
  useTimeWindow_( pset.getParameter<bool>("useTimeWindow") ),
  triggerWidth_( pset.getParameter<int>("triggerWidth") ),
  timeWindowOffset_( pset.getParameter<int>("timeWindowOffset") ),
  maximumNoiseRate_( pset.getParameter<double>("maximumNoiseRate") ),
  useAbsoluteRate_( pset.getParameter<bool>("useAbsoluteRate") ), 
  readDB_(true), defaultTtrig_(0), 
  dbLabel_( pset.getUntrackedParameter<string>("dbLabel", "") ),
  //fastAnalysis_( pset.getParameter<bool>("fastAnalysis", true) ),
  wireIdWithHisto_( std::vector<DTWireId>() ),
  lumiMax_(5000)
  {

  // Get the debug parameter for verbose output
  //debug = ps.getUntrackedParameter<bool>("debug");
  /*// The analysis type
  // The wheel & sector interested for the time-dependent analysis
  wh = ps.getUntrackedParameter<int>("wheel", 0);
  sect = ps.getUntrackedParameter<int>("sector", 6);*/

  if( pset.exists("defaultTtrig") ){
     readDB_ = false;
     defaultTtrig_ = pset.getParameter<int>("defaultTtrig");
  }

  if( pset.exists("cellsWithHisto") ){
     vector<string> cellsWithHisto = pset.getParameter<vector<string> >("cellsWithHisto");
     for(vector<string>::const_iterator cell = cellsWithHisto.begin(); cell != cellsWithHisto.end(); ++cell){
        //FIXME: Use regex to check whether format is right
        if( (*cell) != "" && (*cell) != "None"){
           stringstream linestr;
           int wheel,station,sector,sl,layer,wire;
           linestr << (*cell);
           linestr >> wheel >> station >> sector >> sl >> layer >> wire;
           wireIdWithHisto_.push_back(DTWireId(wheel,station,sector,sl,layer,wire));
        }
     }
  }

  // The root file which will contain the histos
  string rootFileName = pset.getUntrackedParameter<string>("rootFileName","noise.root");
  rootFile_ = new TFile(rootFileName.c_str(), "RECREATE");
  rootFile_->cd();
}
DTNoiseCalibration::~DTNoiseCalibration ( ) [virtual]

Destructor.

Definition at line 348 of file DTNoiseCalibration.cc.

References rootFile_.

                                       {
  rootFile_->Close();
}

Member Function Documentation

void DTNoiseCalibration::analyze ( const edm::Event e,
const edm::EventSetup c 
) [virtual]

Implements edm::EDAnalyzer.

Definition at line 116 of file DTNoiseCalibration.cc.

References DTTimeUnits::counts, defaultTtrig_, digiLabel_, dtGeom_, Exception, spr::find(), DTTopology::firstChannel(), getChannelName(), getLayerName(), hTDCTriggerWidth_, DTTopology::lastChannel(), LogTrace, lumiMax_, nevents_, readDB_, rootFile_, ntuplemaker::status, theHistoOccupancyMap_, theHistoOccupancyVsLumiMap_, timeWindowOffset_, triggerWidth_, tTrigMap_, useTimeWindow_, and wireIdWithHisto_.

                                                                                 {
  ++nevents_;
  
  // Get the digis from the event
  Handle<DTDigiCollection> dtdigis;
  event.getByLabel(digiLabel_, dtdigis);

  /*TH1F *hOccupancyHisto;
  TH2F *hEvtPerWireH;
  string Histo2Name;*/

  // Loop over digis
  DTDigiCollection::DigiRangeIterator dtLayerId_It;
  for (dtLayerId_It=dtdigis->begin(); dtLayerId_It!=dtdigis->end(); ++dtLayerId_It){
     // Define time window
     float upperLimit = 0.;
     if( readDB_ ){
        float tTrig,tTrigRMS,kFactor;
        DTSuperLayerId slId = ((*dtLayerId_It).first).superlayerId();
        int status = tTrigMap_->get( slId, tTrig, tTrigRMS, kFactor, DTTimeUnits::counts );
        if(status != 0) throw cms::Exception("DTNoiseCalibration") << "Could not find tTrig entry in DB for" << slId << endl;
        upperLimit = tTrig - timeWindowOffset_;
     } else {
        upperLimit = defaultTtrig_ - timeWindowOffset_;
     }

     for (DTDigiCollection::const_iterator digiIt = ((*dtLayerId_It).second).first;
         digiIt!=((*dtLayerId_It).second).second; ++digiIt){

        //Check the TDC trigger width
        int tdcTime = (*digiIt).countsTDC();
        if( !useTimeWindow_ ){
           if( ( ((float)tdcTime*25)/32 ) > triggerWidth_ )
              LogError("Calibration") << "Digi has a TDC time (ns) higher than the pre-defined TDC trigger width: " << ((float)tdcTime*25)/32;
        }       

        hTDCTriggerWidth_->Fill(tdcTime);

        if( useTimeWindow_ && tdcTime > upperLimit) continue;

        /*LogTrace("Calibration") << "TDC time (ns): " << ((float)tdcTime*25)/32
                                <<" --- trigger width (ns): " << ((float)upperLimit*25)/32;*/

        const DTLayerId dtLId = (*dtLayerId_It).first;
        const DTTopology& dtTopo = dtGeom_->layer(dtLId)->specificTopology();
        const int firstWire = dtTopo.firstChannel();
        const int lastWire = dtTopo.lastChannel();
        //const int nWires = dtTopo.channels();
        const int nWires = lastWire - firstWire + 1;

        // Book the occupancy histos
        if( theHistoOccupancyMap_.find(dtLId) == theHistoOccupancyMap_.end() ){
           string histoName = "DigiOccupancy_" + getLayerName(dtLId);
           rootFile_->cd();
           TH1F* hOccupancyHisto = new TH1F(histoName.c_str(), histoName.c_str(), nWires, firstWire, lastWire+1);
           LogTrace("Calibration") << "  Created occupancy Histo: " << hOccupancyHisto->GetName();
           theHistoOccupancyMap_[dtLId] = hOccupancyHisto;
        }
        theHistoOccupancyMap_[dtLId]->Fill((*digiIt).wire());

        const DTWireId wireId(dtLId, (*digiIt).wire());
        if( find(wireIdWithHisto_.begin(),wireIdWithHisto_.end(),wireId) != wireIdWithHisto_.end() ){
           if( theHistoOccupancyVsLumiMap_.find(wireId) == theHistoOccupancyVsLumiMap_.end() ){
              string histoName = "OccupancyVsLumi_" + getChannelName(wireId);
              rootFile_->cd();
              TH1F* hOccupancyVsLumiHisto = new TH1F(histoName.c_str(), histoName.c_str(), lumiMax_, 0, lumiMax_);
              LogTrace("Calibration") << "  Created occupancy histo: " << hOccupancyVsLumiHisto->GetName();
              theHistoOccupancyVsLumiMap_[wireId] = hOccupancyVsLumiHisto;
           }

           unsigned int lumiSection = event.luminosityBlock();
           theHistoOccupancyVsLumiMap_[wireId]->Fill(lumiSection);
        }

        /*// Book the digi event plot every 1000 events if the analysis is not "fast" and if is the correct sector
        if(!fastAnalysis &&
           dtLId.superlayerId().chamberId().wheel()==wh &&
           dtLId.superlayerId().chamberId().sector()==sect) {
          if(theHistoEvtPerWireMap.find(dtLId) == theHistoEvtPerWireMap.end() ||
             (theHistoEvtPerWireMap.find(dtLId) != theHistoEvtPerWireMap.end() &&
              skippedPlot[dtLId] != counter)){ 
            skippedPlot[dtLId] = counter;
            stringstream toAppend; toAppend << counter;
            Histo2Name = "DigiPerWirePerEvent_" + getLayerName(dtLId) + "_" + toAppend.str();
            theFile->cd();
            hEvtPerWireH = new TH2F(Histo2Name.c_str(), Histo2Name.c_str(), 1000,0.5,1000.5,nWires, firstWire, lastWire+1);
            if(hEvtPerWireH){
              if(debug)
                cout << "  New Histo with the number of digi per evt per wire: " << hEvtPerWireH->GetName() << endl;
              theHistoEvtPerWireMap[dtLId]=hEvtPerWireH;
            }
          }
        }*/
     }
  }
    
  /*//Fill the plot of the number of digi per event per wire
  std::map<int,int > DigiPerWirePerEvent;
  // LOOP OVER ALL THE CHAMBERS
  vector<DTChamber*>::const_iterator ch_it = dtGeom->chambers().begin();
  vector<DTChamber*>::const_iterator ch_end = dtGeom->chambers().end();
  for (; ch_it != ch_end; ++ch_it) {
    DTChamberId ch = (*ch_it)->id();
    vector<const DTSuperLayer*>::const_iterator sl_it = (*ch_it)->superLayers().begin(); 
    vector<const DTSuperLayer*>::const_iterator sl_end = (*ch_it)->superLayers().end();
    // Loop over the SLs
    for(; sl_it != sl_end; ++sl_it) {
      DTSuperLayerId sl = (*sl_it)->id();
      vector<const DTLayer*>::const_iterator l_it = (*sl_it)->layers().begin(); 
      vector<const DTLayer*>::const_iterator l_end = (*sl_it)->layers().end();
      // Loop over the Ls
      for(; l_it != l_end; ++l_it) {
        DTLayerId layerId = (*l_it)->id();
        
        // Get the number of wires
        const DTTopology& dtTopo = dtGeom->layer(layerId)->specificTopology();
        const int firstWire = dtTopo.firstChannel();
        const int lastWire = dtTopo.lastChannel();
          
        if (theHistoEvtPerWireMap.find(layerId) != theHistoEvtPerWireMap.end() &&
            skippedPlot[layerId] == counter) {
          
          for (int wire=firstWire; wire<=lastWire; wire++) {
            DigiPerWirePerEvent[wire]= 0;
          }     
          // loop over all the digis of the event
          DTDigiCollection::Range layerDigi= dtdigis->get(layerId);
          for (DTDigiCollection::const_iterator digi = layerDigi.first;
               digi!=layerDigi.second;
               ++digi){
            if((cosmicRun && (*digi).countsTDC()<upperLimit) || (!cosmicRun))
              DigiPerWirePerEvent[(*digi).wire()]+=1;
          }
          // fill the digi event histo
          for (int wire=firstWire; wire<=lastWire; wire++) {
            theFile->cd();
            int histoEvents = nevents - (counter*1000);
            theHistoEvtPerWireMap[layerId]->Fill(histoEvents,wire,DigiPerWirePerEvent[wire]);
          }
        }
      } //Loop Ls
    } //Loop SLs
  } //Loop chambers
  
  
  if(nevents % 1000 == 0) {
    counter++;
    // save the digis event plot on file
    for(map<DTLayerId,  TH2F* >::const_iterator lHisto = theHistoEvtPerWireMap.begin();
        lHisto != theHistoEvtPerWireMap.end();
        lHisto++) {
      theFile->cd();
      if((*lHisto).second)
        (*lHisto).second->Write();
    }
    theHistoEvtPerWireMap.clear();
  }*/
  
}
void DTNoiseCalibration::beginJob ( void  ) [virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 88 of file DTNoiseCalibration.cc.

References hTDCTriggerWidth_, nevents_, and triggerWidth_.

                                  {
  LogVerbatim("Calibration") << "[DTNoiseCalibration]: Begin job";
  
  nevents_ = 0;
  
  TH1::SetDefaultSumw2(true);
  int numBin = (triggerWidth_*32/25)/50;
  hTDCTriggerWidth_ = new TH1F("TDC_Time_Distribution", "TDC_Time_Distribution", numBin, 0, triggerWidth_*32/25);
}
void DTNoiseCalibration::beginRun ( const edm::Run run,
const edm::EventSetup setup 
) [virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 98 of file DTNoiseCalibration.cc.

References dbLabel_, dtGeom_, edm::EventSetup::get(), readDB_, and tTrigMap_.

                                                                                {

  // Get the DT Geometry
  setup.get<MuonGeometryRecord>().get(dtGeom_);

  // tTrig 
  if( readDB_ ) setup.get<DTTtrigRcd>().get(dbLabel_,tTrigMap_);

  /*
  nevents = 0;
  counter = 0;

  // TDC time distribution
  int numBin = (triggerWidth_*(32/25))/50;
  hTDCTriggerWidth = new TH1F("TDC_Time_Distribution", "TDC_Time_Distribution", numBin, 0, triggerWidth_*(32/25));*/

}
void DTNoiseCalibration::endJob ( void  ) [virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 276 of file DTNoiseCalibration.cc.

References newFWLiteAna::bin, DTTimeUnits::counts, defaultTtrig_, dtGeom_, Exception, DTTopology::firstChannel(), hTDCTriggerWidth_, DTTopology::lastChannel(), LogTrace, maximumNoiseRate_, nevents_, readDB_, record, rootFile_, DTStatusFlag::setCellNoise(), ntuplemaker::status, crabStatusFromReport::statusMap, theHistoOccupancyMap_, theHistoOccupancyVsLumiMap_, timeWindowOffset_, triggerWidth_, tTrigMap_, useAbsoluteRate_, and useTimeWindow_.

                               {

  //LogVerbatim("Calibration") << "[DTNoiseCalibration] endjob called!";
  LogVerbatim("Calibration") << "[DTNoiseCalibration] Total number of events analyzed: " << nevents_;

  // Save the TDC digi plot
  rootFile_->cd();
  hTDCTriggerWidth_->Write();

  for(map<DTWireId, TH1F*>::const_iterator wHisto = theHistoOccupancyVsLumiMap_.begin();
      wHisto != theHistoOccupancyVsLumiMap_.end(); ++wHisto) (*wHisto).second->Write();
  
  // Save on file the occupancy histos and write the list of noisy cells
  DTStatusFlag *statusMap = new DTStatusFlag();
  for(map<DTLayerId, TH1F*>::const_iterator lHisto = theHistoOccupancyMap_.begin();
      lHisto != theHistoOccupancyMap_.end();
      ++lHisto){
     double triggerWidth_s = 0.;
     if( useTimeWindow_ ){
        double triggerWidth_ns = 0.;
        if( readDB_ ){
           float tTrig, tTrigRMS, kFactor;
           DTSuperLayerId slId = ((*lHisto).first).superlayerId();
           int status = tTrigMap_->get( slId, tTrig, tTrigRMS, kFactor, DTTimeUnits::counts );
           if(status != 0) throw cms::Exception("DTNoiseCalibration") << "Could not find tTrig entry in DB for" << slId << endl;
           triggerWidth_ns = tTrig - timeWindowOffset_;
        } else{
           triggerWidth_ns = defaultTtrig_ - timeWindowOffset_;
        }
        triggerWidth_ns = (triggerWidth_ns*25)/32;
        triggerWidth_s = triggerWidth_ns/1e9;
     } else{
        triggerWidth_s = double(triggerWidth_/1e9);
     }
     LogTrace("Calibration") << (*lHisto).second->GetName() << " trigger width (s): " << triggerWidth_s;

     double normalization = 1./(nevents_*triggerWidth_s);
     if((*lHisto).second){
        (*lHisto).second->Scale(normalization);
        rootFile_->cd();
        (*lHisto).second->Write();
        const DTTopology& dtTopo = dtGeom_->layer((*lHisto).first)->specificTopology();
        const int firstWire = dtTopo.firstChannel();
        const int lastWire = dtTopo.lastChannel();
        //const int nWires = dtTopo.channels();
        const int nWires = lastWire - firstWire + 1;
        // Find average in layer
        double averageRate = 0.;  
        for(int bin = 1; bin <= (*lHisto).second->GetNbinsX(); ++bin)
           averageRate += (*lHisto).second->GetBinContent(bin);

        if(nWires) averageRate /= nWires;  
        LogTrace("Calibration") << "  Average rate = " << averageRate;

        for(int i_wire = firstWire; i_wire <= lastWire; ++i_wire){
           // From definition of "noisy cell"
           int bin = i_wire - firstWire + 1;
           double channelRate = (*lHisto).second->GetBinContent(bin);
           double rateOffset = (useAbsoluteRate_) ? 0. : averageRate;
           if( (channelRate - rateOffset) > maximumNoiseRate_ ){
              DTWireId wireID((*lHisto).first, i_wire);
              statusMap->setCellNoise(wireID,1);
              LogVerbatim("Calibration") << ">>> Channel noisy: " << wireID;
           }
        }
     }
  }
  LogVerbatim("Calibration") << "Writing noise map object to DB";
  string record = "DTStatusFlagRcd";
  DTCalibDBUtils::writeToDB<DTStatusFlag>(record, statusMap);
}
string DTNoiseCalibration::getChannelName ( const DTWireId wId) const [private]

Definition at line 352 of file DTNoiseCalibration.cc.

References DTLayerId::layer(), DTChamberId::sector(), DTChamberId::station(), DTSuperLayerId::superlayer(), DTChamberId::wheel(), and DTWireId::wire().

Referenced by analyze().

                                                                  {
  stringstream channelName;
  channelName << "Wh" << wId.wheel() << "_St" << wId.station() << "_Sec" << wId.sector()
              << "_SL" << wId.superlayer() << "_L" << wId.layer() << "_W"<< wId.wire();

  return channelName.str();
}
string DTNoiseCalibration::getLayerName ( const DTLayerId lId) const [private]

Definition at line 360 of file DTNoiseCalibration.cc.

References DTSuperLayerId::chamberId(), DTLayerId::layer(), DTChamberId::sector(), relativeConstraints::station, DTChamberId::station(), DTSuperLayerId::superlayer(), DTLayerId::superlayerId(), and DTChamberId::wheel().

Referenced by analyze().

                                                                 {

  const  DTSuperLayerId dtSLId = lId.superlayerId();
  const  DTChamberId dtChId = dtSLId.chamberId(); 
  stringstream Layer; Layer << lId.layer();
  stringstream superLayer; superLayer << dtSLId.superlayer();
  stringstream wheel; wheel << dtChId.wheel();  
  stringstream station; station << dtChId.station();    
  stringstream sector; sector << dtChId.sector();
  
  string LayerName = 
    "W" + wheel.str()
    + "_St" + station.str() 
    + "_Sec" + sector.str() 
    + "_SL" + superLayer.str()
    + "_L" + Layer.str();
  
  return LayerName;
}
string DTNoiseCalibration::getSuperLayerName ( const DTSuperLayerId dtSLId) const [private]

Definition at line 380 of file DTNoiseCalibration.cc.

References DTSuperLayerId::chamberId(), DTChamberId::sector(), relativeConstraints::station, DTChamberId::station(), DTSuperLayerId::superlayer(), and DTChamberId::wheel().

                                                                              {

  const  DTChamberId dtChId = dtSLId.chamberId(); 
  stringstream superLayer; superLayer << dtSLId.superlayer();
  stringstream wheel; wheel << dtChId.wheel();  
  stringstream station; station << dtChId.station();    
  stringstream sector; sector << dtChId.sector();
  
  string SuperLayerName = 
    "W" + wheel.str()
    + "_St" + station.str() 
    + "_Sec" + sector.str() 
    + "_SL" + superLayer.str();
  
  return SuperLayerName;
}

Member Data Documentation

std::string DTNoiseCalibration::dbLabel_ [private]

Definition at line 63 of file DTNoiseCalibration.h.

Referenced by beginRun().

Definition at line 62 of file DTNoiseCalibration.h.

Referenced by analyze(), DTNoiseCalibration(), and endJob().

Definition at line 50 of file DTNoiseCalibration.h.

Referenced by analyze().

Definition at line 72 of file DTNoiseCalibration.h.

Referenced by analyze(), beginRun(), and endJob().

Definition at line 78 of file DTNoiseCalibration.h.

Referenced by analyze(), beginJob(), and endJob().

unsigned int DTNoiseCalibration::lumiMax_ [private]

Definition at line 66 of file DTNoiseCalibration.h.

Referenced by analyze().

Definition at line 54 of file DTNoiseCalibration.h.

Referenced by endJob().

Definition at line 68 of file DTNoiseCalibration.h.

Referenced by analyze(), beginJob(), and endJob().

Definition at line 61 of file DTNoiseCalibration.h.

Referenced by analyze(), beginRun(), DTNoiseCalibration(), and endJob().

Definition at line 76 of file DTNoiseCalibration.h.

Referenced by analyze(), DTNoiseCalibration(), endJob(), and ~DTNoiseCalibration().

Definition at line 80 of file DTNoiseCalibration.h.

Referenced by analyze(), and endJob().

Definition at line 82 of file DTNoiseCalibration.h.

Referenced by analyze(), and endJob().

Definition at line 53 of file DTNoiseCalibration.h.

Referenced by analyze(), and endJob().

Definition at line 52 of file DTNoiseCalibration.h.

Referenced by analyze(), beginJob(), and endJob().

Definition at line 74 of file DTNoiseCalibration.h.

Referenced by analyze(), beginRun(), and endJob().

Definition at line 55 of file DTNoiseCalibration.h.

Referenced by endJob().

Definition at line 51 of file DTNoiseCalibration.h.

Referenced by analyze(), and endJob().

Definition at line 65 of file DTNoiseCalibration.h.

Referenced by analyze(), and DTNoiseCalibration().