CMS 3D CMS Logo

Public Member Functions | Private Attributes

CastorPSMonitor Class Reference

#include <CastorPSMonitor.h>

Inheritance diagram for CastorPSMonitor:
CastorBaseMonitor

List of all members.

Public Member Functions

 CastorPSMonitor ()
void processEvent (const CastorDigiCollection &castorDigis, const CastorDbService &conditions, std::vector< HcalGenericDetId > listEMap, int iBunch, float PedSigmaInChannel[14][16])
void reset ()
void setup (const edm::ParameterSet &ps, DQMStore *dbe)
 ~CastorPSMonitor ()

Private Attributes

std::vector< NewBunchBunches_
struct {
   MonitorElement *   meDigi_pulseBX
castorDigiHists
MonitorElementChannelSummaryMap
MonitorElementDigiOccupancyMap
bool doPerChannel_
double firstRegionThreshold_
bool firstTime_
double fraction
TH2F * h_reportSummaryMap
int ievt_
MonitorElementmeEvt_
double numberSigma_
int numOK
bool offline_
MonitorElementoverallStatus
std::map< int, MonitorElement * > PSsector
MonitorElementreportSummary
MonitorElementreportSummaryMap
int saturatedMap [14][16]
double saturatedThreshold_
MonitorElementSaturationSummaryMap
double secondRegionThreshold_
double status
double statusRS
double statusSaturated
double sumDigiForEachChannel [14][16]
double thirdRegionThreshold_

Detailed Description

Definition at line 14 of file CastorPSMonitor.h.


Constructor & Destructor Documentation

CastorPSMonitor::CastorPSMonitor ( )
CastorPSMonitor::~CastorPSMonitor ( )

Definition at line 63 of file CastorPSMonitor.cc.

                                 {
}

Member Function Documentation

void CastorPSMonitor::processEvent ( const CastorDigiCollection castorDigis,
const CastorDbService conditions,
std::vector< HcalGenericDetId listEMap,
int  iBunch,
float  PedSigmaInChannel[14][16] 
)

Definition at line 155 of file CastorPSMonitor.cc.

References HcalQIESample::adc(), edm::SortedCollection< T, SORT >::begin(), Bunches_, HcalQIESample::capid(), castorDigiHists, ChannelSummaryMap, CastorQIECoder::charge(), gather_cfg::cout, CastorBaseMonitor::cpu_timer, edm::CPUTimer::cpuTime(), NewBunch::detid, DigiOccupancyMap, edm::SortedCollection< T, SORT >::end(), MonitorElement::Fill(), firstRegionThreshold_, firstTime_, fraction, CastorBaseMonitor::fVerbosity, CastorDbService::getCastorCalibrations(), CastorDbService::getCastorCoder(), CastorDbService::getCastorShape(), MonitorElement::getTH2F(), i, CastorDataFrame::id(), ievt_, j, gen::k, CastorBaseMonitor::m_dbe, meEvt_, module(), numberSigma_, numOK, overallStatus, CastorCalibrations::pedestal(), CastorDataFrame::presamples(), PSsector, DetId::rawId(), reportSummary, reportSummaryMap, edm::CPUTimer::reset(), CastorDataFrame::sample(), saturatedMap, saturatedThreshold_, SaturationSummaryMap, secondRegionThreshold_, CastorBaseMonitor::showTiming, edm::SortedCollection< T, SORT >::size(), CastorDataFrame::size(), edm::CPUTimer::start(), status, statusRS, statusSaturated, edm::CPUTimer::stop(), sumDigiForEachChannel, thirdRegionThreshold_, NewBunch::tsAdc, NewBunch::tsCapId, NewBunch::tsfC, and NewBunch::usedflag.

Referenced by CastorMonitorModule::analyze().

 {
  
     
  if(fVerbosity>0) std::cout << "==>CastorPSMonitor::processEvent !!!" << std::endl;
 
  if(!m_dbe) { 
    if(fVerbosity>0) std::cout <<"CastorPSMonitor::processEvent => DQMStore not instantiated !!!"<<std::endl;  
    return; 
  }
 
  meEvt_->Fill(ievt_); 

  ievt_++;

  status = -99; statusRS = -99; statusSaturated=-99;

  const CastorQIEShape* shape = conditions.getCastorShape();
     
  if(firstTime_)     
    {
      //===> show the array of sigmas
      for (int i=0; i<14; i++){
        for (int k=0; k<16; k++){
        if(fVerbosity>0)  std::cout<< "module:"<<i+1<< " sector:"<<k+1<< " Sigma=" <<   PedSigmaInChannel[i][k] << std::endl;   
        }
      }
      for (std::vector<HcalGenericDetId>::const_iterator it = listEMap.begin(); it != listEMap.end(); it++)
        {     
          HcalGenericDetId mygenid(it->rawId());
          if(mygenid.isHcalCastorDetId())
            {
              NewBunch myBunch;
              HcalCastorDetId chanid(mygenid.rawId());
              myBunch.detid = chanid;
              myBunch.usedflag = false;
              std::string type;
              type = "CASTOR";
              for(int i = 0; i != 20; i++)
                {
                  myBunch.tsCapId[i] = 0;
                  myBunch.tsAdc[i] = 0;
                  myBunch.tsfC[i] = 0.0;
                }
              Bunches_.push_back(myBunch);
            }
        }

      firstTime_ = false;
    }
  
  
      if(castorDigis.size()>0) {
        int firstTS = 0; 
        int lastTS  = 9;   
        std::vector<NewBunch>::iterator bunch_it;
        int numBunches = 0;
        bool firstDigi = true;
        bool saturated = false;
        
        for(CastorDigiCollection::const_iterator j = castorDigis.begin(); j != castorDigis.end(); j++)
          {
            
            const CastorDataFrame digi = (const CastorDataFrame)(*j);
            if ( lastTS+1 > digi.size() ) lastTS = digi.size()-1;
            for(bunch_it = Bunches_.begin(); bunch_it != Bunches_.end(); bunch_it++)
              if(bunch_it->detid.rawId() == digi.id().rawId()) break;
            bunch_it->usedflag = true;
            
            numBunches++;
            //
            //---- Skip noisy channels present in 2009 beam data:
            // if ( (bunch_it->detid.sector() == 16 && bunch_it->detid.module() == 6)  ||
            //   (bunch_it->detid.sector() ==  3 && bunch_it->detid.module() == 8)  ||
            //   (bunch_it->detid.sector() ==  8 && bunch_it->detid.module() == 8) ) continue;
            //

            if ( lastTS+1 > digi.size() ) lastTS = digi.size()-1;
            
            const CastorCalibrations& calibrations=conditions.getCastorCalibrations(digi.id().rawId());

            double sumDigi=0.;  double sumDigiADC=0.; int bxTS=-9999; saturated = false;

            for(int ts = firstTS; ts != lastTS+1; ts++)
              {
                 if (firstDigi) {
                    bxTS = (iBunch+ts-1-digi.presamples());
                    if ( bxTS < 0 ) bxTS += 3563;
                    bxTS = ( bxTS % 3563 ) + 1;
                    if(fVerbosity>0) std::cout << "!!! " << bxTS << " " << iBunch <<" "<< ts << " " << digi.presamples() << std::endl;
                  }
                
                  const CastorQIECoder* coder = conditions.getCastorCoder(digi.id().rawId());
                  bunch_it->tsCapId[ts] = digi.sample(ts).capid();
                  bunch_it->tsAdc[ts] = digi.sample(ts).adc();
                
                  double charge_fC = coder->charge(*shape, digi.sample(ts).adc(), digi.sample(ts).capid());
                
                  bunch_it->tsfC[ts] = charge_fC - calibrations.pedestal(digi.sample(ts).capid());
                  castorDigiHists.meDigi_pulseBX->Fill(static_cast<double>(bxTS),(bunch_it->tsfC[ts])/224.);

                  // PK: do not normalize histograms
                  //  PSsector[bunch_it->detid.sector()-1]->Fill(10*(bunch_it->detid.module()-1)+ts, bunch_it->tsfC[ts]/double(ievt_)); 
                  PSsector[bunch_it->detid.sector()-1]->Fill(10*(bunch_it->detid.module()-1)+ts, bunch_it->tsfC[ts]);
 
                  sumDigi +=  bunch_it->tsfC[ts]; //std::cout<< " signal(fC) in TS:"<<ts << " =" << bunch_it->tsfC[ts] << std::endl;       
                  sumDigiADC +=   bunch_it->tsAdc[ts]; //std::cout<< " signal(ADC) in TS:"<<ts << " =" << bunch_it->tsAdc[ts] << std::endl; 

                  if(bunch_it->tsAdc[ts]>126.95) {
                    saturated = true;
                  if(fVerbosity>0) 
                  std::cout<< "WARNING: ==> Module:" << bunch_it->detid.module() << " Sector:" << bunch_it->detid.sector() << " SATURATED !!! in TS:"<< ts <<std::endl;   
                 }

              } //-- end of the loop for time slices
          
            sumDigiForEachChannel[bunch_it->detid.module()-1][bunch_it->detid.sector()-1] += sumDigi;

            if(saturated) saturatedMap[bunch_it->detid.module()-1][bunch_it->detid.sector()-1] += 1;

            DigiOccupancyMap->Fill(bunch_it->detid.module()-1,bunch_it->detid.sector()-1, double(sumDigi/10)); //std::cout<< "=====> sumDigi=" << sumDigi << std::endl;

            
            if(fVerbosity>0){
             std::cout<< "==> Module:" << bunch_it->detid.module() << " Sector:" << bunch_it->detid.sector() << std::endl; 
             std::cout<< "==> Total charge in fC:" << sumDigi << std::endl;  
             std::cout<< "==> Total charge in ADC:" << sumDigiADC << std::endl;  
            }
         
           firstDigi = false;  
    } //-- end of the loop over digis 







        // if( ievt_ == 25 || ievt_ % 500 == 0 ) {  // no event selection - get all events

    numOK = 0;

     for (int sector=0; sector<16; sector++){
       for (int module=0; module<14; module++){
  
     firstRegionThreshold_ = (-1)*(numberSigma_*PedSigmaInChannel[module][sector]);
     secondRegionThreshold_ = numberSigma_*PedSigmaInChannel[module][sector] ;
    

 if(double(sumDigiForEachChannel[module][sector]/(10*ievt_)) < firstRegionThreshold_ )  
   { status = -1.; statusRS=0.; }
              
 if(double(sumDigiForEachChannel[module][sector]/(10*ievt_)) > firstRegionThreshold_ && double(sumDigiForEachChannel[module][sector]/(10*ievt_)) < secondRegionThreshold_ ) 
   { status = 0.25; statusRS=0.95; }
  
 if(double(sumDigiForEachChannel[module][sector]/(10*ievt_)) > secondRegionThreshold_ && double(sumDigiForEachChannel[module][sector]/(10*ievt_))< thirdRegionThreshold_ ) 
   { status = 1.; statusRS=1.0; }

 //---- leave it out for the time being
 // if(double(sumDigiForEachChannel[module][sector]/(10*ievt_)) > thirdRegionThreshold_ ) 
 // { status = -0.25; statusRS=0.88 ; }
   
 //-- define the fraction of saturated events for a particular channel
 double fractionSaturated =  double(saturatedMap[module][sector])/double(ievt_) ;
 if(fVerbosity>0) std::cout<< "==> module: " << module << " sector: " << sector << " ==> N_saturation:" << saturatedMap[module][sector] << " events:"<< ievt_ << " fraction:" << fractionSaturated << std::endl;

 if( fractionSaturated > saturatedThreshold_ ) 
   { status = -0.25; statusRS=0.88 ; statusSaturated=-1.0; }

 if( saturatedMap[module][sector] > 0 && fractionSaturated <  saturatedThreshold_  ) 
   { statusSaturated= 0; }

 if( saturatedMap[module][sector] == 0 ) 
   { statusSaturated= 1; }

   ChannelSummaryMap->getTH2F()->SetBinContent(module+1,sector+1,status);

   reportSummaryMap->getTH2F()->SetBinContent(module+1,sector+1,statusRS);

   SaturationSummaryMap->getTH2F()->SetBinContent(module+1,sector+1,double(statusSaturated));

   if ( statusRS > 0.9) numOK++;

       } //-- end of the loop over the modules
     } //-- end of the loop over the sectors

    fraction=double(numOK)/224;
    overallStatus->Fill(fraction); reportSummary->Fill(fraction); 

    //  } //-- end of if for the number of events // update ( PK ):   


      for (int sector=16; sector<20; sector++){
        for (int module=0; module<14; module++){
      ChannelSummaryMap->getTH2F()->SetBinContent(module+1,sector+1,99);
        }
    }
      for (int sector=16; sector<20; sector++){
        for (int module=0; module<14; module++){
          SaturationSummaryMap->getTH2F()->SetBinContent(module+1,sector+1, 99);
        }
    }





 } //-- end of the if castDigi
       
  else { if(fVerbosity>0) std::cout<<"CastorPSMonitor::processEvent NO Castor Digis !!!"<<std::endl; }

      
   if (showTiming) { 
      cpu_timer.stop(); std::cout << " TIMER::CastorPS -> " << cpu_timer.cpuTime() << std::endl; 
      cpu_timer.reset(); cpu_timer.start();  
    }
 
  
  return;
}
void CastorPSMonitor::reset ( void  )

Definition at line 66 of file CastorPSMonitor.cc.

Referenced by CastorMonitorModule::reset().

                           {
}
void CastorPSMonitor::setup ( const edm::ParameterSet ps,
DQMStore dbe 
) [virtual]

Reimplemented from CastorBaseMonitor.

Definition at line 73 of file CastorPSMonitor.cc.

References CastorBaseMonitor::baseFolder_, DQMStore::book1D(), DQMStore::book2D(), DQMStore::bookFloat(), DQMStore::bookInt(), castorDigiHists, ChannelSummaryMap, gather_cfg::cout, DigiOccupancyMap, MonitorElement::Fill(), firstRegionThreshold_, firstTime_, fraction, CastorBaseMonitor::fVerbosity, MonitorElement::getTH2F(), edm::ParameterSet::getUntrackedParameter(), h_reportSummaryMap, i, ievt_, CastorBaseMonitor::m_dbe, meEvt_, mergeVDriftHistosByStation::name, NULL, numberSigma_, numOK, offline_, overallStatus, PSsector, reportSummary, reportSummaryMap, CastorBaseMonitor::rootFolder_, saturatedMap, saturatedThreshold_, SaturationSummaryMap, secondRegionThreshold_, DQMStore::setCurrentFolder(), sumDigiForEachChannel, and thirdRegionThreshold_.

Referenced by CastorMonitorModule::CastorMonitorModule().

                                                                   {
  
  CastorBaseMonitor::setup(ps,dbe);
  baseFolder_ = rootFolder_+"CastorPSMonitor";

  numberSigma_ = ps.getUntrackedParameter<double>("numberSigma", 1.5);
  thirdRegionThreshold_ = ps.getUntrackedParameter<double>("thirdRegionThreshold", 300);
  saturatedThreshold_   = ps.getUntrackedParameter<double>("saturatedThreshold", 0.05); //-- fraction of events in which chargeTS > 127 ADC
  offline_              = ps.getUntrackedParameter<bool>("OfflineMode", false); 

  if(fVerbosity>0) std::cout << "CastorPSMonitor::setup (start)" << std::endl;
    
  ievt_=0;  firstTime_ = true;
  firstRegionThreshold_=0.;
  secondRegionThreshold_=0.;
  numOK = 0; 
  fraction=0.; 

  for (int row=0; row<14; row++){
    for (int col=0; col<16; col++){
        sumDigiForEachChannel[row][col] = 0;
        saturatedMap [row][col] = 0;
    }
  }

  if ( m_dbe !=NULL ) {    
    m_dbe->setCurrentFolder(baseFolder_);
    
    meEvt_ = m_dbe->bookInt("PS Event Number"); 
    castorDigiHists.meDigi_pulseBX = m_dbe->book1D("CASTOR average pulse in bunch crossings","CASTOR average pulse in bunch crossings", 3600,  -0.5, 3600);
    TH1F* h_meDigi_pulseBX = castorDigiHists.meDigi_pulseBX->getTH1F();
    h_meDigi_pulseBX->GetXaxis()->SetTitle("orbit");

    //---- Pulse Shape per sector
    char name[1024];
    for(int i=0; i<16; i++){
    sprintf(name,"Castor Pulse Shape for sector=%d (in all 14 modules)",i+1);      
    PSsector[i] =  m_dbe->book1D(name,name,140,-0.5,139.5);
    }

    DigiOccupancyMap = m_dbe->book2D("CASTOR Digi Occupancy Map","CASTOR Digi Occupancy Map",14,0.0,14.0,16,0.0,16.0);
    ChannelSummaryMap = m_dbe->book2D("CASTOR Digi ChannelSummaryMap","CASTOR Digi ChannelSummaryMap",14,0.0,14.0,20,0.0,20.0); // put 20 instead of 16 to get some space for the legend

    SaturationSummaryMap = m_dbe->book2D("CASTOR Digi SaturationSummaryMap","CASTOR Digi SaturationSummaryMap",14,0.0,14.0,20,0.0,20.0); // put 20 instead of 16 to get some space for the legend



    m_dbe->setCurrentFolder(rootFolder_+"EventInfo");
    reportSummary    = m_dbe->bookFloat("reportSummary");
    reportSummaryMap = m_dbe->book2D("reportSummaryMap","CASTOR reportSummaryMap",14,0.0,14.0,16,0.0,16.0);
    if(offline_){
      h_reportSummaryMap =reportSummaryMap->getTH2F();
      h_reportSummaryMap->SetOption("textcolz");
      h_reportSummaryMap->GetXaxis()->SetTitle("module");
      h_reportSummaryMap->GetYaxis()->SetTitle("sector");
    }
    m_dbe->setCurrentFolder(rootFolder_+"EventInfo/reportSummaryContents");
    overallStatus = m_dbe->bookFloat("fraction of good channels");
    overallStatus->Fill(fraction); reportSummary->Fill(fraction); 
  } 

  else{
    if(fVerbosity>0) std::cout << "CastorPSMonitor::setup - NO DQMStore service" << std::endl; 
  }

  if(fVerbosity>0) std::cout << "CastorPSMonitor::setup (end)" << std::endl;

  return;
}

Member Data Documentation

std::vector<NewBunch> CastorPSMonitor::Bunches_ [private]

Definition at line 60 of file CastorPSMonitor.h.

Referenced by processEvent().

struct { ... } CastorPSMonitor::castorDigiHists [private]

Referenced by processEvent(), and setup().

Definition at line 41 of file CastorPSMonitor.h.

Referenced by processEvent(), and setup().

Definition at line 37 of file CastorPSMonitor.h.

Referenced by processEvent(), and setup().

Definition at line 25 of file CastorPSMonitor.h.

Referenced by CastorPSMonitor().

Definition at line 54 of file CastorPSMonitor.h.

Referenced by CastorPSMonitor(), processEvent(), and setup().

Definition at line 44 of file CastorPSMonitor.h.

Referenced by processEvent(), and setup().

double CastorPSMonitor::fraction [private]

Definition at line 51 of file CastorPSMonitor.h.

Referenced by processEvent(), and setup().

Definition at line 52 of file CastorPSMonitor.h.

Referenced by setup().

int CastorPSMonitor::ievt_ [private]

Definition at line 27 of file CastorPSMonitor.h.

Referenced by CastorPSMonitor(), processEvent(), and setup().

Definition at line 31 of file CastorPSMonitor.h.

Definition at line 34 of file CastorPSMonitor.h.

Referenced by processEvent(), and setup().

Definition at line 46 of file CastorPSMonitor.h.

Referenced by processEvent(), and setup().

int CastorPSMonitor::numOK [private]

Definition at line 47 of file CastorPSMonitor.h.

Referenced by processEvent(), and setup().

bool CastorPSMonitor::offline_ [private]

Definition at line 45 of file CastorPSMonitor.h.

Referenced by setup().

Definition at line 40 of file CastorPSMonitor.h.

Referenced by processEvent(), and setup().

std::map<int,MonitorElement*> CastorPSMonitor::PSsector [private]

Definition at line 35 of file CastorPSMonitor.h.

Referenced by processEvent(), and setup().

Definition at line 38 of file CastorPSMonitor.h.

Referenced by processEvent(), and setup().

Definition at line 39 of file CastorPSMonitor.h.

Referenced by processEvent(), and setup().

int CastorPSMonitor::saturatedMap[14][16] [private]

Definition at line 59 of file CastorPSMonitor.h.

Referenced by processEvent(), and setup().

Definition at line 57 of file CastorPSMonitor.h.

Referenced by processEvent(), and setup().

Definition at line 42 of file CastorPSMonitor.h.

Referenced by processEvent(), and setup().

Definition at line 55 of file CastorPSMonitor.h.

Referenced by CastorPSMonitor(), processEvent(), and setup().

double CastorPSMonitor::status [private]

Definition at line 48 of file CastorPSMonitor.h.

Referenced by CastorPSMonitor(), and processEvent().

double CastorPSMonitor::statusRS [private]

Definition at line 49 of file CastorPSMonitor.h.

Referenced by CastorPSMonitor(), and processEvent().

Definition at line 50 of file CastorPSMonitor.h.

Referenced by CastorPSMonitor(), and processEvent().

double CastorPSMonitor::sumDigiForEachChannel[14][16] [private]

Definition at line 58 of file CastorPSMonitor.h.

Referenced by processEvent(), and setup().

Definition at line 56 of file CastorPSMonitor.h.

Referenced by processEvent(), and setup().