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