CMS 3D CMS Logo

CalibrationTask.cc
Go to the documentation of this file.
10 
11 #include <arpa/inet.h>
12 #include <cstdio>
13 #include <fstream>
14 #include <netdb.h>
15 #include <sys/socket.h>
16 #include <sys/unistd.h>
17 
18 // -----------------------------------------------------------------------------
19 //
21  const FedChannelConnection& conn,
22  const sistrip::RunType& rtype,
23  const char* filename,
24  uint32_t run,
25  const edm::EventSetup& setup) :
26  CommissioningTask( dqm, conn, "CalibrationTask" ),
27  runType_(rtype),
28  nBins_(0),
29  lastCalChan_(1000),
30  lastCalSel_(1000),
31  lastLatency_(1000),
32  extrainfo_(),
33  run_(run)
34 {
35 
36  // each latency point is 25ns, each calSel is 25/8 --> 64 points = 8 calsel + 8 latency --> as set in the DAQ configuration
38  // each latency point is 25ns, each calSel is 25/8 --> 80 points = 8 calsel + 10 latency --> as set in the DAQ configuration
39  else if(runType_ == sistrip::CALIBRATION_DECO) nBins_ = 80;
40 
41  LogDebug("Commissioning") << "[CalibrationTask::CalibrationTask] Constructing object...";
42 
43  // load the pedestals
44  edm::ESHandle<SiStripPedestals> pedestalsHandle;
45  setup.get<SiStripPedestalsRcd>().get(pedestalsHandle);
46  SiStripPedestals::Range detPedRange = pedestalsHandle->getRange(conn.detId());
47  int start = conn.apvPairNumber()*256;
48  int stop = start + 256;
49  int value = 0;
50  ped.reserve(256);
51  for(int strip = start; strip < stop; ++strip) {
52  value = int(pedestalsHandle->getPed(strip,detPedRange));
53  if(value>895) value -= 1024;
54  ped.push_back(value);
55  }
56 }
57 
58 // -----------------------------------------------------------------------------
59 //
61  LogDebug("Commissioning") << "[CalibrationTask::CalibrationTask] Destructing object...";
62 }
63 
64 // -----------------------------------------------------------------------------
65 //
67 
68  LogDebug("Commissioning") << "[CalibrationTask::book]";
69 
70  // book 16 histograms, one for each strip in a calibration group --> APV1 --> 16 = dimension of one calChan
71  if(calib1_.find(extrainfo_) == calib1_.end()){
73  calib1_[extrainfo_].resize(16);
74  for(int i = 0; i < 16; ++i) {
75  std::string postfix = extrainfo_+"_istrip_"+std::to_string(i);
77  runType_,
79  fedKey(),
80  sistrip::APV,
81  connection().i2cAddr(0),
82  postfix).title();
83 
85  calib1_[extrainfo_][i].histo( dqm()->book1D( title, title, nBins_, 0, 200));
87  calib1_[extrainfo_][i].histo( dqm()->book1D( title, title, nBins_, 0, 250));
88  calib1_[extrainfo_][i].isProfile_ = false;
89  calib1_[extrainfo_][i].vNumOfEntries_.resize(nBins_,0);
90  }
91  }
92 
93  // book 16 histograms, one for each strip in a calibration group --> APV2 --> 16 = dimension of one calChan
94  if(calib2_.find(extrainfo_) == calib2_.end()){
95 
97  calib2_[extrainfo_].resize(16);
98  for(int i = 0; i < 16; ++i) {
99  std::string postfix = extrainfo_+"_istrip_"+std::to_string(i);
101  runType_,
103  fedKey(),
104  sistrip::APV,
105  connection().i2cAddr(1),
106  postfix).title();
107 
109  calib2_[extrainfo_][i].histo( dqm()->book1D( title, title, nBins_, 0, 200));
111  calib2_[extrainfo_][i].histo( dqm()->book1D( title, title, nBins_, 0, 250));
112 
113  calib2_[extrainfo_][i].isProfile_ = false;
114  calib2_[extrainfo_][i].vNumOfEntries_.resize(nBins_,0);
115  }
116  }
117 }
118 
119 // -----------------------------------------------------------------------------
120 //
122  const edm::DetSet<SiStripRawDigi>& digis ) {
123 
124  LogDebug("Commissioning") << "[CalibrationTask::fill]";
125 
126  if(lastCalChan_ != summary.calChan()){ // change in the calChan value
127  lastCalChan_ = summary.calChan();
128  lastLatency_ = summary.latency();
129  lastCalSel_ = summary.calSel();
130  extrainfo_ = "calChan_"+std::to_string(lastCalChan_);
131  book(); // book histograms and load the right one
132  }
133  else{
134  lastCalChan_ = summary.calChan();
135  lastLatency_ = summary.latency();
136  lastCalSel_ = summary.calSel();
137  extrainfo_ = "calChan_"+std::to_string(lastCalChan_);
138  }
139 
140  // Check if CalChan changed. In that case, save, reset histo, change title, and continue
141  int isub = lastCalChan_<4 ? lastCalChan_+4 : lastCalChan_-4;
142  int bin = 0;
143 
144  if(runType_ == sistrip::CALIBRATION) bin = (100-summary.latency())*8+(7-summary.calSel());
145  else if(runType_ == sistrip::CALIBRATION_DECO) bin = (102-summary.latency())*8+(7-summary.calSel());
146 
147  // Fill the histograms data-ped -(data-ped)_isub, the second term corresponds to the common mode substraction, looking at a strip far away.
148  for (int k=0;k<16;++k) {
149  updateHistoSet(calib1_[extrainfo_][k],bin,digis.data[lastCalChan_+k*8].adc()-ped[lastCalChan_+k*8]-(digis.data[isub+k*8].adc()-ped[isub+k*8]));
150  updateHistoSet(calib2_[extrainfo_][k],bin,digis.data[128+lastCalChan_+k*8].adc()-ped[128+lastCalChan_+k*8]-(digis.data[128+isub+k*8].adc()-ped[128+isub+k*8]));
151  }
152  update(); //TODO: temporary: find a better solution later
153 }
154 
155 // -----------------------------------------------------------------------------
156 //
158 
159  LogDebug("Commissioning") << "[CalibrationTask::update]"; // huge output
160 
161  for(auto element : calib1_){ // all pulse for different calChan
162  for(auto vecelement : element.second) // all strips in a calCan
163  updateHistoSet(vecelement);
164  }
165 
166  for(auto element : calib2_){ // all pulse for different calChan
167  for(auto vecelement : element.second) // all strips in a calCan
168  updateHistoSet(vecelement);
169  }
170 
171 }
172 
174  directory_ = dir;
175 }
#define LogDebug(id)
Definition: start.py:1
void update() override
uint16_t lastCalSel_
Utility class that holds histogram title.
const std::string & title() const
std::map< std::string, std::vector< HistoSet > > calib1_
const uint32_t & latency() const
uint16_t apvPairNumber() const
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
std::string extrainfo_
std::string directory_
std::pair< ContainerIterator, ContainerIterator > Range
CalibrationTask(DQMStore *, const FedChannelConnection &, const sistrip::RunType &, const char *filename, uint32_t run, const edm::EventSetup &setup)
uint16_t lastLatency_
float getPed(const uint16_t &strip, const Range &range) const
void updateHistoSet(HistoSet &, const uint32_t &bin, const float &value)
const uint32_t & detId() const
Class containning control, module, detector and connection information, at the level of a FED channel...
uint16_t lastCalChan_
sistrip::RunType runType_
Definition: value.py:1
void setCurrentFolder(const std::string &)
int k[5][pyjets_maxn]
bin
set the eta bin as selection string.
const uint32_t & calSel() const
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:571
std::vector< uint16_t > ped
void book() override
DQMStore *const dqm() const
collection_type data
Definition: DetSet.h:80
~CalibrationTask() override
T get() const
Definition: EventSetup.h:71
const uint32_t & calChan() const
const uint32_t & fedKey() const
std::map< std::string, std::vector< HistoSet > > calib2_
const Range getRange(const uint32_t &detID) const
const FedChannelConnection & connection() const
dbl *** dir
Definition: mlp_gen.cc:35
void fill(const SiStripEventSummary &, const edm::DetSet< SiStripRawDigi > &) override