CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Protected Member Functions | Private Attributes
DTFineDelayCorr Class Reference

#include <DTFineDelayCorr.h>

Inheritance diagram for DTFineDelayCorr:
DTLocalTriggerBaseTest edm::EDAnalyzer

Public Member Functions

 DTFineDelayCorr (const edm::ParameterSet &ps)
 Constructor. More...
 
virtual ~DTFineDelayCorr ()
 Destructor. More...
 
- Public Member Functions inherited from DTLocalTriggerBaseTest
 DTLocalTriggerBaseTest ()
 Constructor. More...
 
virtual ~DTLocalTriggerBaseTest ()
 Destructor. More...
 
- Public Member Functions inherited from edm::EDAnalyzer
 EDAnalyzer ()
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 

Protected Member Functions

void beginJob ()
 Begin Job. More...
 
void beginRun (const edm::Run &run, const edm::EventSetup &evSU)
 Begin Run. More...
 
void endJob ()
 End Job. More...
 
void runClientDiagnostic ()
 DQM Client Diagnostic. More...
 
void writeConsts (const std::string &outputFileName) const
 
- Protected Member Functions inherited from DTLocalTriggerBaseTest
void analyze (const edm::Event &e, const edm::EventSetup &c)
 Analyze. More...
 
void beginJob ()
 BeginJob. More...
 
void beginLuminosityBlock (edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &context)
 Perform begin lumiblock operations. More...
 
void beginRun (edm::Run const &run, edm::EventSetup const &context)
 BeginRun. More...
 
void bookCmsHistos (std::string hTag, std::string folder="", bool isGlb=false)
 Book the new MEs (CMS summary) More...
 
void bookSectorHistos (int wheel, int sector, std::string hTag, std::string folder="")
 Book the new MEs (for each sector) More...
 
void bookWheelHistos (int wheel, std::string hTag, std::string folder="")
 Book the new MEs (for each wheel) More...
 
std::string category ()
 Get message logger name. More...
 
void endJob ()
 EndJob. More...
 
void endLuminosityBlock (edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &context)
 Perform client diagnostic in online. More...
 
void endRun (edm::Run const &run, edm::EventSetup const &context)
 Perform client diagnostic in offline. More...
 
std::string fullName (std::string htype)
 Create fullname from histo partial name. More...
 
template<class T >
TgetHisto (MonitorElement *me)
 Convert ME to Histogram fo type T. More...
 
std::string getMEName (std::string histoTag, std::string subfolder, const DTChamberId &chambid)
 Get the ME name (by chamber) More...
 
std::string getMEName (std::string histoTag, std::string subfolder, int wh)
 Get the ME name (by wheel) More...
 
std::pair< float, float > phiRange (const DTChamberId &id)
 Calculate phi range for histograms. More...
 
void setConfig (const edm::ParameterSet &ps, std::string name)
 Set configuration variables. More...
 
std::string & topFolder (bool isDCC)
 Get top folder name. More...
 
- Protected Member Functions inherited from edm::EDAnalyzer
CurrentProcessingContext const * currentContext () const
 

Private Attributes

std::map< DTChamberId,
std::vector< float > > 
delayMap
 
edm::ESHandle< DTConfigManagerdtConfig
 
bool gaussMean
 
int minEntries
 
int nEvents
 
std::map< DTChamberId,
std::pair< int, float > > 
oldDelayMap
 
std::string oldDelaysInputFile
 
std::string outputFileName
 
bool readOldFromDb
 
std::string t0MeanHistoTag
 
std::string trSource
 
edm::ESHandle< DTTPGParametersworstPhaseMap
 
bool writeDB
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
typedef WorkerT< EDAnalyzerWorkerType
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
- Protected Attributes inherited from DTLocalTriggerBaseTest
std::string baseFolderDCC
 
std::string baseFolderDDU
 
std::map< std::string,
MonitorElement * > 
cmsME
 
DQMStoredbe
 
std::string hwSource
 
std::vector< std::string > hwSources
 
edm::ESHandle< DTGeometrymuonGeom
 
int nevents
 
unsigned int nLumiSegs
 
edm::ParameterSet parameters
 
int prescaleFactor
 
int run
 
bool runOnline
 
std::map< int, std::map
< std::string, MonitorElement * > > 
secME
 
std::string sourceFolder
 
std::string testName
 
std::string trigSource
 
std::vector< std::string > trigSources
 
std::map< int, std::map
< std::string, MonitorElement * > > 
whME
 

Detailed Description

Definition at line 28 of file DTFineDelayCorr.h.

Constructor & Destructor Documentation

DTFineDelayCorr::DTFineDelayCorr ( const edm::ParameterSet ps)

Constructor.

Definition at line 45 of file DTFineDelayCorr.cc.

45  {
46 
47  setConfig(ps,"DTFineDelayCorr"); // sets parameter values and name used in log file
48  baseFolderDCC = "DT/90-LocalTriggerSynch/";
49  baseFolderDDU = "DT/90-LocalTriggerSynch/";
50 
51 }
void setConfig(const edm::ParameterSet &ps, std::string name)
Set configuration variables.
DTFineDelayCorr::~DTFineDelayCorr ( )
virtual

Destructor.

Definition at line 54 of file DTFineDelayCorr.cc.

54  {
55 
56 }

Member Function Documentation

void DTFineDelayCorr::beginJob ( void  )
protectedvirtual

Begin Job.

Reimplemented from edm::EDAnalyzer.

Definition at line 59 of file DTFineDelayCorr.cc.

References dumpDBToFile_GT_ttrig_cfg::outputFileName, and Parameters::parameters.

59  {
60 
61  // Tag for Hardware Source (DDU or DCC)
62  hwSource = parameters.getParameter<string>("hwSource");
63  // Tag for the t0Mean Histograms
64  t0MeanHistoTag = parameters.getParameter<string>("t0MeanHistoTag");
65  // Read old delays from file or from Db
66  readOldFromDb = parameters.getParameter<bool>("readOldFromDb");
67  // Input file name for old delays
68  oldDelaysInputFile = parameters.getParameter<string>("oldDelaysInputFile"),
69  // Write new delays to file or to Db
70  writeDB = parameters.getParameter<bool>("writeDB");
71  // Output File Name
72  outputFileName = parameters.getParameter<string>("outputFile");
73  // Choose to use Hist Mean or Gaussian Fit Mean
74  gaussMean = parameters.getParameter<bool>("gaussMean");
75  // Require Minimum Number Of Entries in the t0Mean Histogram
76  minEntries = parameters.getUntrackedParameter<int>("minEntries",5);
77 
78 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::string outputFileName
std::string t0MeanHistoTag
std::string oldDelaysInputFile
void DTFineDelayCorr::beginRun ( const edm::Run run,
const edm::EventSetup evSU 
)
protectedvirtual

Begin Run.

Reimplemented from edm::EDAnalyzer.

Definition at line 80 of file DTFineDelayCorr.cc.

References DTLocalTriggerBaseTest::beginRun(), and edm::EventSetup::get().

80  {
81 
83  evSU.get< DTConfigManagerRcd >().get(dtConfig);
84  evSU.get< DTTPGParametersRcd >().get(worstPhaseMap);
85 
86 }
edm::ESHandle< DTConfigManager > dtConfig
void beginRun(edm::Run const &run, edm::EventSetup const &context)
BeginRun.
const T & get() const
Definition: EventSetup.h:55
edm::ESHandle< DTTPGParameters > worstPhaseMap
void DTFineDelayCorr::endJob ( void  )
protectedvirtual

End Job.

Reimplemented from edm::EDAnalyzer.

Definition at line 187 of file DTFineDelayCorr.cc.

References filterCSVwithJSON::copy, DTLocalTriggerBaseTest::endJob(), python.multivaluedict::map(), GetRecoTauVFromDQM_MC_cff::outFile, and dumpDBToFile_GT_ttrig_cfg::outputFileName.

187  {
188 
190 
191  if (writeDB) {
192  // to be added if needed
193  }
194  else { // write txt file
195  // ** Open output file **
196  ofstream outFile(outputFileName.c_str());
197  for(map< DTChamberId, vector<float> >::const_iterator iter = delayMap.begin();
198  iter != delayMap.end() ; iter++) {
199  // writing
200  ostream_iterator<float> oit(outFile, " ");
201  copy((*iter).second.begin(), (*iter).second.end(), oit);
202  outFile << endl;
203  }
204  outFile.close();
205  }
206 }
std::string outputFileName
std::map< DTChamberId, std::vector< float > > delayMap
void DTFineDelayCorr::runClientDiagnostic ( )
protectedvirtual

DQM Client Diagnostic.

Implements DTLocalTriggerBaseTest.

Definition at line 88 of file DTFineDelayCorr.cc.

References python.rootplot.argparse::category, gather_cfg::cout, DTChamberId, DTLayerId, DTTopology::firstChannel(), DTConfigPedestals::getOffset(), DTLayer::id(), geometryCSVtoXML::line, timingPdfMaker::mean, DTTimeUnits::ns, DetId::rawId(), DTChamberId::sector(), DTLayer::specificTopology(), DTChamberId::station(), relativeConstraints::station, and DTChamberId::wheel().

88  {
89  int coarseDelay = -999;
90  float oldFineDelay = -999;
91  if(!readOldFromDb) { // read old delays from txt file
92  // ** Open and read old delays input file **
93  ifstream oldDelaysFile(oldDelaysInputFile.c_str());
94  string line;
95 
96  while (getline(oldDelaysFile, line)) {
97  if( line == "" || line[0] == '#' ) continue;
98  stringstream linestr;
99  int wheelKey,sectorKey, stationKey;
100  linestr << line;
101 
102  linestr >> wheelKey
103  >> sectorKey
104  >> stationKey
105  >> coarseDelay
106  >> oldFineDelay;
107 
108  pair<int,float> oldDelays = make_pair(coarseDelay,oldFineDelay);
109  DTChamberId oldDelayKey = DTChamberId(wheelKey,stationKey,sectorKey);
110  oldDelayMap.insert(make_pair(oldDelayKey,oldDelays));
111  }
112  }
113 
114  // ** Loop over the chambers **
115  vector<DTChamber*>::const_iterator chambIt = muonGeom->chambers().begin();
116  vector<DTChamber*>::const_iterator chambEnd = muonGeom->chambers().end();
117  for (; chambIt!=chambEnd; ++chambIt) {
118  DTChamberId chId = (*chambIt)->id();
119  uint32_t indexCh = chId.rawId();
120  int wheel = chId.wheel();
121  int sector = chId.sector();
122  int station = chId.station();
123 
124  // ** Compute corrected values and write them to file or database **
125  vector<float> newDelays;
126 
127  // ** Retrieve Delays Loaded in MiniCrates **
128  if(readOldFromDb) { // read from db
129  DTConfigPedestals *pedestals = dtConfig->getDTConfigPedestals();
130  const DTLayer *layer = muonGeom->layer(DTLayerId(chId,1,1));
131  float delay = pedestals->getOffset(DTWireId(layer->id(),layer->specificTopology().firstChannel()));
132  coarseDelay = int(delay/25.);
133  oldFineDelay = delay - coarseDelay * 25.;
134  }
135  else { // read from map created from txt file
136  coarseDelay = oldDelayMap[chId].first;
137  oldFineDelay = oldDelayMap[chId].second;
138  }
139 
140  // ** Retrieve t0Mean histograms **
141  TH1F *t0H = getHisto<TH1F>(dbe->get(getMEName(t0MeanHistoTag,"", chId)));
142  float newFineDelay = -999; // initialize to dummy number
143  cout <<"MG: " << getMEName(t0MeanHistoTag,"", chId) << " entries: " << t0H->GetEntries() << endl;
144  if (t0H->GetEntries() > minEntries) {
145  Double_t mean;
146  // ** Find Mean Value of the distribution **
147  if(gaussMean) {
148  TF1 *funct = t0H->GetFunction("gaus");
149  mean = funct->GetParameter(1);
150  }
151  else {
152  mean = t0H->GetMean();
153  }
154 
155  // ** Retrieve Worst Phase values **
156  int wpCoarseDelay;
157  float wpFineDelay;
158  worstPhaseMap->get(chId, wpCoarseDelay, wpFineDelay, DTTimeUnits::ns);
159 // cout << "wpFineDelay, oldFineDelay, mean: " << wpFineDelay << " "
160 // << oldFineDelay << " " << mean << endl;
161  float bpFineDelay = (wpFineDelay < 12.5)? (wpFineDelay + 12.5) : (wpFineDelay - 12.5); // Best Phase: half BX far from the worst phase
162  // ** Calculate correction **
163  float diffFineDelays = oldFineDelay + (mean - bpFineDelay); // positive mean shift implies positive delay correction
164  int bxDiff = (int) (diffFineDelays / 25);
165  coarseDelay += bxDiff;
166  newFineDelay = fmodf(diffFineDelays, 25);
167 // cout << "diffFineDelays, newFineDelay, bxDiff, coarseDelay: " << diffFineDelays
168 // << " "<< newFineDelay << " " << bxDiff << " " << coarseDelay << endl;
169  }
170  else {
171  LogProblem(category()) << "[" << testName << "Test]: Not enough entries in hist for Chamber "
172  << indexCh << endl;
173  }
174 
175  newDelays.push_back(wheel);
176  newDelays.push_back(sector);
177  newDelays.push_back(station);
178  newDelays.push_back(coarseDelay);
179  newDelays.push_back(newFineDelay);
180  pair< DTChamberId, vector<float> > chDelays;
181  chDelays.first = chId;
182  chDelays.second = newDelays;
183  delayMap.insert(chDelays);
184  }
185 }
edm::ESHandle< DTConfigManager > dtConfig
DTLayerId id() const
Return the DetId of this SL.
Definition: DTLayer.cc:48
std::map< DTChamberId, std::pair< int, float > > oldDelayMap
edm::ESHandle< DTGeometry > muonGeom
int firstChannel() const
Returns the wire number of the first wire.
Definition: DTTopology.h:80
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
const DTTopology & specificTopology() const
Definition: DTLayer.cc:44
float getOffset(const DTWireId &wire)
Get wire by wire delay.
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1468
std::string category()
Get message logger name.
std::map< DTChamberId, std::vector< float > > delayMap
std::string t0MeanHistoTag
std::string getMEName(std::string histoTag, std::string subfolder, const DTChamberId &chambid)
Get the ME name (by chamber)
edm::ESHandle< DTTPGParameters > worstPhaseMap
int sector() const
Definition: DTChamberId.h:63
std::string oldDelaysInputFile
tuple cout
Definition: gather_cfg.py:121
int station() const
Return the station number.
Definition: DTChamberId.h:53
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:47
void DTFineDelayCorr::writeConsts ( const std::string &  outputFileName) const
protected

Member Data Documentation

std::map< DTChamberId, std::vector<float> > DTFineDelayCorr::delayMap
private

Definition at line 72 of file DTFineDelayCorr.h.

edm::ESHandle< DTConfigManager > DTFineDelayCorr::dtConfig
private

Definition at line 65 of file DTFineDelayCorr.h.

bool DTFineDelayCorr::gaussMean
private

Definition at line 62 of file DTFineDelayCorr.h.

int DTFineDelayCorr::minEntries
private

Definition at line 63 of file DTFineDelayCorr.h.

int DTFineDelayCorr::nEvents
private

Definition at line 64 of file DTFineDelayCorr.h.

std::map< DTChamberId, std::pair<int,float> > DTFineDelayCorr::oldDelayMap
private

Definition at line 69 of file DTFineDelayCorr.h.

std::string DTFineDelayCorr::oldDelaysInputFile
private

Definition at line 58 of file DTFineDelayCorr.h.

std::string DTFineDelayCorr::outputFileName
private

Definition at line 57 of file DTFineDelayCorr.h.

bool DTFineDelayCorr::readOldFromDb
private

Definition at line 60 of file DTFineDelayCorr.h.

std::string DTFineDelayCorr::t0MeanHistoTag
private

Definition at line 56 of file DTFineDelayCorr.h.

std::string DTFineDelayCorr::trSource
private

Definition at line 59 of file DTFineDelayCorr.h.

edm::ESHandle< DTTPGParameters > DTFineDelayCorr::worstPhaseMap
private

Definition at line 66 of file DTFineDelayCorr.h.

bool DTFineDelayCorr::writeDB
private

Definition at line 61 of file DTFineDelayCorr.h.