CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTTTrigWriter.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * $Date: 2010/08/02 16:11:35 $
5  * $Revision: 1.5 $
6  * \author S. Bolognesi
7  */
8 
12 
13 
14 
22 
26 
27 /* C++ Headers */
28 #include <vector>
29 #include <iostream>
30 #include <fstream>
31 #include <string>
32 #include <sstream>
33 #include "TFile.h"
34 #include "TH1.h"
35 
36 using namespace std;
37 using namespace edm;
38 
39 
40 // Constructor
42  // get selected debug option
43  debug = pset.getUntrackedParameter<bool>("debug",false);
44 
45  // Open the root file which contains the histos
46  theRootInputFile = pset.getUntrackedParameter<string>("rootFileName");
47  theFile = new TFile(theRootInputFile.c_str(), "READ");
48  theFile->cd();
49  theFitter = new DTTimeBoxFitter();
50  if(debug)
51  theFitter->setVerbosity(1);
52 
53  double sigmaFit = pset.getUntrackedParameter<double>("sigmaTTrigFit",10.);
54  theFitter->setFitSigma(sigmaFit);
55 
56  // the kfactor to be uploaded in the ttrig DB
57  kFactor = pset.getUntrackedParameter<double>("kFactor",-0.7);
58 
59  // Create the object to be written to DB
60  tTrig = new DTTtrig();
61 
62  if(debug)
63  cout << "[DTTTrigWriter]Constructor called!" << endl;
64 }
65 
66 
67 
68 // Destructor
70  if(debug)
71  cout << "[DTTTrigWriter]Destructor called!" << endl;
72  theFile->Close();
73  delete theFitter;
74 }
75 
76 
77 
78 // Do the job
79 void DTTTrigWriter::analyze(const Event & event, const EventSetup& eventSetup) {
80  if(debug)
81  cout << "[DTTTrigWriter]Analyzer called!" << endl;
82 
83  // Get the DT Geometry
84  ESHandle<DTGeometry> dtGeom;
85  eventSetup.get<MuonGeometryRecord>().get(dtGeom);
86 
87  // Get all the sls from the setup
88  const vector<DTSuperLayer*> superLayers = dtGeom->superLayers();
89 
90  // Loop over all SLs
91  for(vector<DTSuperLayer*>::const_iterator sl = superLayers.begin();
92  sl != superLayers.end(); sl++) {
93 
94  // Get the histo from file
95  DTSuperLayerId slId = (*sl)->id();
96  TH1F* histo = (TH1F*)theFile->Get((getTBoxName(slId)).c_str());
97  if(histo) { // Check that the histo exists
98  // Compute mean and sigma of the rising edge
99  pair<double, double> meanAndSigma = theFitter->fitTimeBox(histo);
100 
101  // Write them in DB object
102  tTrig->set(slId,
103  meanAndSigma.first,
104  meanAndSigma.second,
105  kFactor,
107  if(debug) {
108  cout << " SL: " << slId
109  << " mean = " << meanAndSigma.first
110  << " sigma = " << meanAndSigma.second << endl;
111  }
112  }
113  }
114 }
115 
116 
117 
118 // Write objects to DB
120  if(debug)
121  cout << "[DTTTrigWriter]Writing ttrig object to DB!" << endl;
122 
123  // FIXME: to be read from cfg?
124  string tTrigRecord = "DTTtrigRcd";
125 
126  // Write the object to DB
127  DTCalibDBUtils::writeToDB(tTrigRecord, tTrig);
128 
129 }
130 
131 
132 
133 // Compute the name of the time box histo
134 string DTTTrigWriter::getTBoxName(const DTSuperLayerId& slId) const {
135  string histoName;
136  stringstream theStream;
137  theStream << "Ch_" << slId.wheel() << "_" << slId.station() << "_" << slId.sector()
138  << "_SL" << slId.superlayer() << "_hTimeBox";
139  theStream >> histoName;
140  return histoName;
141 }
T getUntrackedParameter(std::string const &, T const &) const
void analyze(const edm::Event &event, const edm::EventSetup &eventSetup)
Compute the ttrig by fiting the TB rising edge.
void endJob()
Write ttrig in the DB.
DTTTrigWriter(const edm::ParameterSet &pset)
Constructor.
std::string getTBoxName(const DTSuperLayerId &slId) const
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
int superlayer() const
Return the superlayer number (deprecated method name)
const T & get() const
Definition: EventSetup.h:55
int sector() const
Definition: DTChamberId.h:63
tuple cout
Definition: gather_cfg.py:121
int station() const
Return the station number.
Definition: DTChamberId.h:53
#define debug
Definition: MEtoEDMFormat.h:34
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:47
static void writeToDB(std::string record, T *payload)
virtual ~DTTTrigWriter()
Destructor.