CMS 3D CMS Logo

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

SiStripHotStripAlgorithmFromClusterOccupancy Class Reference

#include <CalibTracker/SiStripQuality/src/SiStripHotStripAlgorithmFromClusterOccupancy.cc>

List of all members.

Classes

struct  pHisto

Public Types

typedef SiStrip::QualityHistosMap HistoMap

Public Member Functions

void extractBadStrips (SiStripQuality *, HistoMap &, edm::ESHandle< SiStripQuality > &)
void setMinNumEntries (unsigned short m)
void setMinNumEntriesPerStrip (unsigned short m)
void setNumberOfEvents (double Nevents)
void setOccupancyThreshold (long double occupancy)
void setOutputFileName (std::string OutputFileName, bool WriteOutputFile)
void setProbabilityThreshold (long double prob)
void setTrackerGeometry (const TrackerGeometry *tkgeom)
 SiStripHotStripAlgorithmFromClusterOccupancy (const edm::ParameterSet &)
virtual ~SiStripHotStripAlgorithmFromClusterOccupancy ()

Private Member Functions

void evaluatePoissonian (std::vector< long double > &, long double &meanVal)
void iterativeSearch (pHisto &, std::vector< unsigned int > &, int)

Private Attributes

int apv_channel
int detrawid
int disc
TFile * f
float global_position_x
float global_position_y
float global_position_z
int hotstripsperapv [6]
int hotStripsPerAPV
int hotStripsPerModule
int hotstripspermodule
int isback
int isexternalstring
int ishot [768]
int isHot
int isstereo
int iszminusside
int layer_ring
double minNevents_
unsigned short MinNumEntries_
unsigned short MinNumEntriesPerStrip_
int module_position
double Nevents_
int number_strips
long double occupancy_
std::string OutFileName_
double poissonProb
double poissonprob [768]
SiStripQualitypQuality
long double prob_
int rodstringpetal
std::stringstream ss
int strip_number
int stripHits
int striphits [768]
double stripOccupancy
double stripoccupancy [768]
TTree * striptree
int subdetid
const TrackerGeometryTkGeom
bool UseInputDB_
bool WriteOutputFile_

Detailed Description

Description: <one line="" class="" summary>="">

Implementation: <Notes on="" implementation>="">

Definition at line 56 of file SiStripHotStripAlgorithmFromClusterOccupancy.h.


Member Typedef Documentation


Constructor & Destructor Documentation

SiStripHotStripAlgorithmFromClusterOccupancy::SiStripHotStripAlgorithmFromClusterOccupancy ( const edm::ParameterSet iConfig)

Definition at line 6 of file SiStripHotStripAlgorithmFromClusterOccupancy.cc.

References minNevents_, Nevents_, and occupancy_.

                                                                                                                        :
    prob_(1.E-7),
    MinNumEntries_(0),
    MinNumEntriesPerStrip_(0),
    Nevents_(0),
    occupancy_(0),
    OutFileName_("Occupancy.root"),
    UseInputDB_(iConfig.getUntrackedParameter<bool>("UseInputDB",false))
  {  
    minNevents_=Nevents_*occupancy_;
  }
SiStripHotStripAlgorithmFromClusterOccupancy::~SiStripHotStripAlgorithmFromClusterOccupancy ( ) [virtual]

Definition at line 19 of file SiStripHotStripAlgorithmFromClusterOccupancy.cc.

References LogTrace.

                                                                                           {
  LogTrace("SiStripHotStripAlgorithmFromClusterOccupancy")<<"[SiStripHotStripAlgorithmFromClusterOccupancy::~SiStripHotStripAlgorithmFromClusterOccupancy] "<<std::endl;
}

Member Function Documentation

void SiStripHotStripAlgorithmFromClusterOccupancy::evaluatePoissonian ( std::vector< long double > &  vPoissonProbs,
long double &  meanVal 
) [private]

Definition at line 278 of file SiStripHotStripAlgorithmFromClusterOccupancy.cc.

References i.

Referenced by iterativeSearch().

                                                                                                                                {
  for(size_t i=0;i<vPoissonProbs.size();++i){
    vPoissonProbs[i]= (i==0)?TMath::Poisson(i,meanVal):vPoissonProbs[i-1]+TMath::Poisson(i,meanVal);
  }
}
void SiStripHotStripAlgorithmFromClusterOccupancy::extractBadStrips ( SiStripQuality OutSiStripQuality,
HistoMap DM,
edm::ESHandle< SiStripQuality > &  InSiStripQuality 
)

Definition at line 23 of file SiStripHotStripAlgorithmFromClusterOccupancy.cc.

References SiStripHotStripAlgorithmFromClusterOccupancy::pHisto::_NEntries, SiStripHotStripAlgorithmFromClusterOccupancy::pHisto::_SubdetId, SiStripHotStripAlgorithmFromClusterOccupancy::pHisto::_th1f, apv_channel, SiStripQuality::clear(), SiStripQuality::compact(), gather_cfg::cout, cond::rpcobgas::detid, detrawid, disc, f, SiStripQuality::fillBadComponents(), global_position_x, global_position_y, global_position_z, hotstripsperapv, hotStripsPerAPV, hotStripsPerModule, hotstripspermodule, i, TrackerGeometry::idToDet(), isback, edm::isDebugEnabled(), isexternalstring, ishot, isHot, isstereo, iszminusside, iterativeSearch(), TIBDetId::layer(), TOBDetId::layer(), layer_ring, StripTopology::localPosition(), LogTrace, module_position, TIDDetId::moduleNumber(), TECDetId::moduleNumber(), TOBDetId::moduleNumber(), TIBDetId::moduleNumber(), number_strips, OutFileName_, TECDetId::petalNumber(), poissonProb, poissonprob, pQuality, SiStripBadStrip::put(), TIDDetId::ring(), TECDetId::ring(), TOBDetId::rodNumber(), rodstringpetal, StripGeomDetUnit::specificTopology(), ss, SiStripDetId::stereo(), TIBDetId::stringNumber(), strip(), strip_number, stripHits, striphits, stripOccupancy, stripoccupancy, striptree, DetId::subdetId(), subdetid, StripSubdetector::TEC, StripSubdetector::TIB, StripSubdetector::TID, TkGeom, StripSubdetector::TOB, UseInputDB_, TIDDetId::wheel(), TECDetId::wheel(), WriteOutputFile_, PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by SiStripQualityHotStripIdentifierRoot::getNewObject(), and SiStripQualityHotStripIdentifier::getNewObject().

                                                                                                                                                               {

  LogTrace("SiStripHotStripAlgorithmFromClusterOccupancy")<<"[SiStripHotStripAlgorithmFromClusterOccupancy::extractBadStrips] "<<std::endl;


  
  if (WriteOutputFile_==true){
  f = new TFile(OutFileName_.c_str(),"RECREATE");
  f->cd();

  striptree = new TTree("stripOccupancy","tree");

  striptree->Branch("DetRawId",             &detrawid,          "DetRawId/I");
  striptree->Branch("SubDetId",             &subdetid,          "SubDetId/I");
  striptree->Branch("Layer_Ring",           &layer_ring,        "Layer_Ring/I");
  striptree->Branch("Disc",                 &disc,              "Disc/I");
  striptree->Branch("IsBack",               &isback,            "IsBack/I");
  striptree->Branch("IsExternalString",     &isexternalstring,  "IsExternalString/I");
  striptree->Branch("IsZMinusSide",         &iszminusside,      "IsZMinusSide/I");
  striptree->Branch("RodStringPetal",       &rodstringpetal,    "RodStringPetal/I");
  striptree->Branch("IsStereo",             &isstereo,          "IsStereo/I");
  striptree->Branch("ModulePosition",       &module_position,   "ModulePosition/I");
  striptree->Branch("NumberOfStrips",       &number_strips,     "NumberOfStrips/I");
  striptree->Branch("StripNumber",          &strip_number,      "StripNumber/I");
  striptree->Branch("APVChannel",           &apv_channel,       "APVChannel/I");
  striptree->Branch("StripGlobalPositionX", &global_position_x, "StripGlobalPositionX/F");
  striptree->Branch("StripGlobalPositionY", &global_position_y, "StripGlobalPositionY/F");
  striptree->Branch("StripGlobalPositionZ", &global_position_z, "StripGlobalPositionZ/F");
  striptree->Branch("IsHot",                &isHot,             "IsHot/I");
  striptree->Branch("HotStripsPerAPV",      &hotStripsPerAPV,   "HotStripsPerAPV/I");
  striptree->Branch("HotStripsPerModule",   &hotStripsPerModule,"HotStripsPerModule/I");
  striptree->Branch("StripOccupancy",       &stripOccupancy,    "StripOccupancy/D");
  striptree->Branch("StripHits",            &stripHits,         "StripHits/I");
  striptree->Branch("PoissonProb",          &poissonProb,       "PoissonProb/D");
  }

  
  HistoMap::iterator it=DM.begin();
  HistoMap::iterator itEnd=DM.end();
  std::vector<unsigned int> badStripList;
  uint32_t detid;
  for (;it!=itEnd;++it){
    pHisto phisto;
    detid=it->first;

    DetId detectorId=DetId(detid);
    phisto._SubdetId=detectorId.subdetId();
    
    if (edm::isDebugEnabled())
      LogTrace("SiStripHotStrip") << "Analyzing detid " << detid<< std::endl;
    
    int numberAPVs = (int)(it->second.get())->GetNbinsX()/128;

    // Set the values for the tree:

    detrawid = detid;
    subdetid = detectorId.subdetId();
    number_strips = (int)(it->second.get())->GetNbinsX();
    if (SiStripDetId(detrawid).stereo() !=0 ) isstereo = 1; // It's a stereo module
    else                                      isstereo = 0; // It's an rphi module
    switch (detectorId.subdetId())
      {
      case StripSubdetector::TIB :
        layer_ring = TIBDetId(detrawid).layer();
        disc       = -1;
        isback     = -1;
        if (TIBDetId(detrawid).isExternalString()) isexternalstring = 1;
        else                                       isexternalstring = 0;
        if (TIBDetId(detrawid).isZMinusSide()) iszminusside = 1;
        else                                   iszminusside = 0;
        rodstringpetal  = TIBDetId(detrawid).stringNumber();
        module_position = TIBDetId(detrawid).moduleNumber();
        break;

      case StripSubdetector::TID :
        layer_ring = TIDDetId(detrawid).ring();
        disc       = TIDDetId(detrawid).wheel();
        if (TIDDetId(detrawid).isBackRing()) isback = 1;
        else                                 isback = 0;
        if (TIDDetId(detrawid).isZMinusSide()) iszminusside = 1;
        else                                   iszminusside = 0;
        isexternalstring = -1;
        rodstringpetal   = -1;
        module_position  = TIDDetId(detrawid).moduleNumber();
        break;

      case StripSubdetector::TOB :
        layer_ring = TOBDetId(detrawid).layer();
        disc       = -1;
        isback     = -1;
        if (TOBDetId(detrawid).isZMinusSide()) iszminusside = 1;
        else                                   iszminusside = 0;
        isexternalstring = -1;
        rodstringpetal   = TOBDetId(detrawid).rodNumber();
        module_position  = TOBDetId(detrawid).moduleNumber();
        break;

      case StripSubdetector::TEC :
        layer_ring = TECDetId(detrawid).ring();
        disc       = TECDetId(detrawid).wheel();
        if (TECDetId(detrawid).isBackPetal()) isback = 1;
        else                                  isback = 0;
        if (TECDetId(detrawid).isZMinusSide()) iszminusside = 1;
        else                                   iszminusside = 0;
        isexternalstring = -1;
        rodstringpetal   = TECDetId(detrawid).petalNumber();
        module_position  = TECDetId(detrawid).moduleNumber();
        break;

      default :
        std::cout << "### Detector does not belong to TIB, TID, TOB or TEC !? ###" << std::endl;
        std::cout << "### DetRawId: " << detrawid << " ###" << std::endl;
      }

    // End: Set the values for the tree.


    pQuality=OutSiStripQuality;
    badStripList.clear();

    for (int i=0; i<768; i++){
      ishot[i]               = 0;
      stripoccupancy[i]      = 0;
      striphits[i]           = 0;
      poissonprob[i]         = 0;
      hotstripsperapv[i/128] = 0;
        }

    hotstripspermodule = 0;

    for (int apv=0; apv<numberAPVs; apv++){
      if(UseInputDB_){
        if(InSiStripQuality->IsApvBad(detid,apv) ){
          if(edm::isDebugEnabled())
            LogTrace("SiStripHotStrip")<<"(Module and Apv number) "<<detid<<" , "<<apv<<" excluded by input ESetup."<<std::endl;
          continue;//if the apv is already flagged as bad, continue.
        }
        else{
          if(edm::isDebugEnabled())
            LogTrace("SiStripHotStrip")<<"(Module and Apv number) "<<detid<<" , "<<apv<<" good by input ESetup."<<std::endl;
        }
      }

      phisto._th1f = new TH1F("tmp","tmp",128,0.5,128.5);
      int NumberEntriesPerAPV=0;
      
      for (int strip=0; strip<128; strip++){
        phisto._th1f->SetBinContent(strip+1,(it->second.get())->GetBinContent((apv*128)+strip+1));
        NumberEntriesPerAPV += (int)(it->second.get())->GetBinContent((apv*128)+strip+1);
      }

      phisto._th1f->SetEntries(NumberEntriesPerAPV);
      phisto._NEntries=(int)phisto._th1f->GetEntries();

      LogTrace("SiStripHotStrip") << "Number of clusters in APV " << apv << ": " << NumberEntriesPerAPV << std::endl;

      iterativeSearch(phisto,badStripList,apv);

      delete phisto._th1f;
    }

    const StripGeomDetUnit*  theStripDet = dynamic_cast<const StripGeomDetUnit*>( (TkGeom->idToDet(detectorId)) );
    const StripTopology* theStripTopol   = dynamic_cast<const StripTopology*>( &(theStripDet->specificTopology()) );  

    for (int strip=0; strip<number_strips; strip++)
      {
        strip_number   = strip+1;
        apv_channel    = (strip%128)+1;
        isHot          = ishot[strip];
        stripOccupancy = stripoccupancy[strip];
        stripHits      = striphits[strip];
        poissonProb    = poissonprob[strip];

        hotStripsPerModule = hotstripspermodule;
        hotStripsPerAPV    = hotstripsperapv[strip/128];

        LocalPoint  pos_strip_local  = theStripTopol->localPosition(strip);
        GlobalPoint pos_strip_global = (TkGeom->idToDet(detectorId))->surface().toGlobal(pos_strip_local);

        global_position_x = pos_strip_global.x();
        global_position_y = pos_strip_global.y();
        global_position_z = pos_strip_global.z();

        if (WriteOutputFile_==true) striptree->Fill();
      }

    if (badStripList.begin()==badStripList.end())
      continue;

    OutSiStripQuality->compact(detid,badStripList);

    SiStripQuality::Range range(badStripList.begin(),badStripList.end());
    if ( ! OutSiStripQuality->put(detid,range) )
      edm::LogError("SiStripHotStrip")<<"[SiStripHotStripAlgorithmFromClusterOccupancy::extractBadStrips] detid already exists"<<std::endl;
  }
  OutSiStripQuality->fillBadComponents();

  if (WriteOutputFile_==true){
  f->cd();
  striptree->Write();
  f->Close();
  }

  LogTrace("SiStripHotStrip") << ss.str() << std::endl;
}
void SiStripHotStripAlgorithmFromClusterOccupancy::iterativeSearch ( pHisto histo,
std::vector< unsigned int > &  vect,
int  apv 
) [private]

Definition at line 230 of file SiStripHotStripAlgorithmFromClusterOccupancy.cc.

References SiStripHotStripAlgorithmFromClusterOccupancy::pHisto::_NEmptyBins, SiStripHotStripAlgorithmFromClusterOccupancy::pHisto::_NEntries, SiStripHotStripAlgorithmFromClusterOccupancy::pHisto::_th1f, diffTreeTool::diff, SiStripBadStrip::encode(), python::tagInventory::entries, evaluatePoissonian(), hotstripsperapv, hotstripspermodule, i, edm::isDebugEnabled(), ishot, LogTrace, minNevents_, MinNumEntries_, MinNumEntriesPerStrip_, Nevents_, poissonprob, pQuality, prob_, striphits, and stripoccupancy.

Referenced by extractBadStrips().

                                                                                                                      {
  if (!histo._NEntries || histo._NEntries <=MinNumEntries_ || histo._NEntries <= minNevents_)
    return;
  
  size_t startingSize=vect.size();
  long double diff=1.-prob_; 
  
  int Nbins     = histo._th1f->GetNbinsX();
  int ibinStart = 1; 
  int ibinStop  = Nbins+1; 
  int MaxEntry  = (int)histo._th1f->GetMaximum();

  std::vector<long double> vPoissonProbs(MaxEntry+1,0);
  long double meanVal=1.*histo._NEntries/(1.*Nbins-histo._NEmptyBins); 
  evaluatePoissonian(vPoissonProbs,meanVal);

  for (Int_t i=ibinStart; i<ibinStop; ++i){
    unsigned int entries= (unsigned int)histo._th1f->GetBinContent(i);

    if (ishot[(apv*128)+i-1]==0){
      stripoccupancy[(apv*128)+i-1] = entries/(double) Nevents_;
      striphits[(apv*128)+i-1]      = entries;
      poissonprob[(apv*128)+i-1]    = 1-vPoissonProbs[entries];
    }

    if (entries<=MinNumEntriesPerStrip_ || entries <= minNevents_)
      continue;

    if(diff<vPoissonProbs[entries]){
      ishot[(apv*128)+i-1] = 1;
      hotstripspermodule++;
      hotstripsperapv[apv]++;
      histo._th1f->SetBinContent(i,0.);
      histo._NEntries-=entries;
      histo._NEmptyBins++;
      if (edm::isDebugEnabled())
        LogTrace("SiStripHotStrip")<< " rejecting strip " << (apv*128)+i-1 << " value " << entries << " diff  " << diff << " prob " << vPoissonProbs[entries]<< std::endl;
      vect.push_back(pQuality->encode((apv*128)+i-1,1,0));
    }

  }
  if (edm::isDebugEnabled())
    LogTrace("SiStripHotStrip") << " [SiStripHotStripAlgorithmFromClusterOccupancy::iterativeSearch] Nbins="<< Nbins << " MaxEntry="<<MaxEntry << " meanVal=" << meanVal << " NEmptyBins="<<histo._NEmptyBins<< " NEntries=" << histo._NEntries << " thEntries " << histo._th1f->GetEntries()<< " startingSize " << startingSize << " vector.size " << vect.size() << std::endl;

  if (vect.size()!=startingSize)
    iterativeSearch(histo,vect,apv);
}
void SiStripHotStripAlgorithmFromClusterOccupancy::setMinNumEntries ( unsigned short  m) [inline]
void SiStripHotStripAlgorithmFromClusterOccupancy::setMinNumEntriesPerStrip ( unsigned short  m) [inline]
void SiStripHotStripAlgorithmFromClusterOccupancy::setNumberOfEvents ( double  Nevents)

Definition at line 284 of file SiStripHotStripAlgorithmFromClusterOccupancy.cc.

References edm::isDebugEnabled(), LogTrace, minNevents_, Nevents_, and occupancy_.

Referenced by SiStripQualityHotStripIdentifierRoot::getNewObject().

                                                                                  {
  Nevents_=Nevents;
  minNevents_=occupancy_*Nevents_; 
  if (edm::isDebugEnabled())                                                                                                                                                                          
    LogTrace("SiStripHotStrip")<<" [SiStripHotStripAlgorithmFromClusterOccupancy::setNumberOfEvents] minNumber of Events per strip used to consider a strip bad" << minNevents_ << " for occupancy " << occupancy_ << std::endl;
}
void SiStripHotStripAlgorithmFromClusterOccupancy::setOccupancyThreshold ( long double  occupancy) [inline]
void SiStripHotStripAlgorithmFromClusterOccupancy::setOutputFileName ( std::string  OutputFileName,
bool  WriteOutputFile 
) [inline]
void SiStripHotStripAlgorithmFromClusterOccupancy::setProbabilityThreshold ( long double  prob) [inline]
void SiStripHotStripAlgorithmFromClusterOccupancy::setTrackerGeometry ( const TrackerGeometry tkgeom) [inline]

Member Data Documentation

Definition at line 121 of file SiStripHotStripAlgorithmFromClusterOccupancy.h.

Referenced by extractBadStrips().

Definition at line 109 of file SiStripHotStripAlgorithmFromClusterOccupancy.h.

Referenced by extractBadStrips().

Definition at line 112 of file SiStripHotStripAlgorithmFromClusterOccupancy.h.

Referenced by extractBadStrips().

Definition at line 106 of file SiStripHotStripAlgorithmFromClusterOccupancy.h.

Referenced by extractBadStrips().

Definition at line 123 of file SiStripHotStripAlgorithmFromClusterOccupancy.h.

Referenced by extractBadStrips().

Definition at line 124 of file SiStripHotStripAlgorithmFromClusterOccupancy.h.

Referenced by extractBadStrips().

Definition at line 125 of file SiStripHotStripAlgorithmFromClusterOccupancy.h.

Referenced by extractBadStrips().

Definition at line 128 of file SiStripHotStripAlgorithmFromClusterOccupancy.h.

Referenced by extractBadStrips().

Definition at line 129 of file SiStripHotStripAlgorithmFromClusterOccupancy.h.

Referenced by extractBadStrips().

Definition at line 113 of file SiStripHotStripAlgorithmFromClusterOccupancy.h.

Referenced by extractBadStrips().

Definition at line 114 of file SiStripHotStripAlgorithmFromClusterOccupancy.h.

Referenced by extractBadStrips().

Definition at line 127 of file SiStripHotStripAlgorithmFromClusterOccupancy.h.

Referenced by extractBadStrips().

Definition at line 117 of file SiStripHotStripAlgorithmFromClusterOccupancy.h.

Referenced by extractBadStrips().

Definition at line 115 of file SiStripHotStripAlgorithmFromClusterOccupancy.h.

Referenced by extractBadStrips().

Definition at line 111 of file SiStripHotStripAlgorithmFromClusterOccupancy.h.

Referenced by extractBadStrips().

Definition at line 118 of file SiStripHotStripAlgorithmFromClusterOccupancy.h.

Referenced by extractBadStrips().

Definition at line 119 of file SiStripHotStripAlgorithmFromClusterOccupancy.h.

Referenced by extractBadStrips().

Definition at line 132 of file SiStripHotStripAlgorithmFromClusterOccupancy.h.

Referenced by extractBadStrips().

Definition at line 116 of file SiStripHotStripAlgorithmFromClusterOccupancy.h.

Referenced by extractBadStrips().

Definition at line 142 of file SiStripHotStripAlgorithmFromClusterOccupancy.h.

Referenced by extractBadStrips().

Definition at line 120 of file SiStripHotStripAlgorithmFromClusterOccupancy.h.

Referenced by extractBadStrips().

Definition at line 131 of file SiStripHotStripAlgorithmFromClusterOccupancy.h.

Referenced by extractBadStrips().

Definition at line 130 of file SiStripHotStripAlgorithmFromClusterOccupancy.h.

Referenced by extractBadStrips().

Definition at line 107 of file SiStripHotStripAlgorithmFromClusterOccupancy.h.

Referenced by extractBadStrips().

Definition at line 110 of file SiStripHotStripAlgorithmFromClusterOccupancy.h.

Referenced by extractBadStrips().

Definition at line 108 of file SiStripHotStripAlgorithmFromClusterOccupancy.h.

Referenced by extractBadStrips().