CMS 3D CMS Logo

CalibrationTask.cc
Go to the documentation of this file.
10 
11 #include <arpa/inet.h>
12 #include <sys/unistd.h>
13 #include <sys/socket.h>
14 #include <netdb.h>
15 #include <cstdio>
16 #include <fstream>
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_(64),
29  lastCalChan_(1000),
30  lastCalSel_(1000),
31  lastLatency_(1000),
32  extrainfo_(),
33  run_(run)
34 {
35 
37  else if(runType_ == sistrip::CALIBRATION_DECO) nBins_ = 80;
38 
39  LogDebug("Commissioning") << "[CalibrationTask::CalibrationTask] Constructing object...";
40  // load the pedestals
41  edm::ESHandle<SiStripPedestals> pedestalsHandle;
42  setup.get<SiStripPedestalsRcd>().get(pedestalsHandle);
43  SiStripPedestals::Range detPedRange = pedestalsHandle->getRange(conn.detId());
44  int start = conn.apvPairNumber()*256;
45  int stop = start + 256;
46  int value = 0;
47  ped.reserve(256);
48  for(int strip = start; strip < stop; ++strip) {
49  value = int(pedestalsHandle->getPed(strip,detPedRange));
50  if(value>895) value -= 1024;
51  ped.push_back(value);
52  }
53 }
54 
55 // -----------------------------------------------------------------------------
56 //
58  LogDebug("Commissioning") << "[CalibrationTask::CalibrationTask] Destructing object...";
59 }
60 
61 // -----------------------------------------------------------------------------
62 //
64  LogDebug("Commissioning") << "[CalibrationTask::book]";
65 
66  // book 16 histograms, one for each strip in a calibration group --> APV1
67  if(calib1_.find(extrainfo_) == calib1_.end()){
69  calib1_[extrainfo_].resize(16);
70  for(int i = 0; i < 16; ++i) {
71  std::string postfix = extrainfo_+"_istrip_"+std::to_string(i);
73  runType_,
75  fedKey(),
76  sistrip::APV,
77  connection().i2cAddr(0),
78  postfix).title();
79 
80  if(runType_ == sistrip::CALIBRATION) // each latency point is 25ns, each calSel is 25/8 --> 64 points = 8 calsel + 8 latency
81  calib1_[extrainfo_][i].histo( dqm()->book1D( title, title, nBins_, 0, 200));
82  else if(runType_ == sistrip::CALIBRATION_DECO) // each latency point is 25ns, each calSel is 25/8 --> 80 points = 8 calsel + 10 latency
83  calib1_[extrainfo_][i].histo( dqm()->book1D( title, title, nBins_, 0, 250));
84  calib1_[extrainfo_][i].isProfile_ = false;
85  calib1_[extrainfo_][i].vNumOfEntries_.resize(nBins_,0);
86  }
87  }
88 
89  // book 16 histograms, one for each strip in a calibration group --> APV2
90  if(calib2_.find(extrainfo_) == calib2_.end()){
91 
93  calib2_[extrainfo_].resize(16);
94  for(int i = 0; i < 16; ++i) {
95  std::string postfix = extrainfo_+"_istrip_"+std::to_string(i);
97  runType_,
99  fedKey(),
100  sistrip::APV,
101  connection().i2cAddr(1),
102  postfix).title();
103 
104  if(runType_ == sistrip::CALIBRATION) // each latency point is 25ns, each calSel is 25/8 --> 64 points = 8 calsel + 8 latency
105  calib2_[extrainfo_][i].histo( dqm()->book1D( title, title, nBins_, 0, 200));
106  else if(runType_ == sistrip::CALIBRATION_DECO) // each latency point is 25ns, each calSel is 25/8 --> 80 points = 8 calsel + 10 latency
107  calib2_[extrainfo_][i].histo( dqm()->book1D( title, title, nBins_, 0, 250));
108 
109  calib2_[extrainfo_][i].isProfile_ = false;
110  calib2_[extrainfo_][i].vNumOfEntries_.resize(nBins_,0);
111  }
112  }
113 }
114 
115 // -----------------------------------------------------------------------------
116 //
118  const edm::DetSet<SiStripRawDigi>& digis ) {
119 
120  LogDebug("Commissioning") << "[CalibrationTask::fill]";
121 
122  if(lastCalChan_ != summary.calChan()){ // change in the calChan value
123  lastCalChan_ = summary.calChan();
124  lastLatency_ = summary.latency();
125  lastCalSel_ = summary.calSel();
126  extrainfo_ = "calChan_"+std::to_string(lastCalChan_);
127  book(); // book histograms and load the right one
128  }
129  else{
130  lastCalChan_ = summary.calChan();
131  lastLatency_ = summary.latency();
132  lastCalSel_ = summary.calSel();
133  extrainfo_ = "calChan_"+std::to_string(lastCalChan_);
134  }
135 
136  // Check if CalChan changed. In that case, save, reset histo, change title, and continue
137  int isub = lastCalChan_<4 ? lastCalChan_+4 : lastCalChan_-4;
138  int bin = 0;
139 
140  if(runType_ == sistrip::CALIBRATION) bin = (100-summary.latency())*8+(7-summary.calSel());
141  else if(runType_ == sistrip::CALIBRATION_DECO) bin = (102-summary.latency())*8+(7-summary.calSel());
142 
143  // Fill the histograms data-ped -(data-ped)_isub
144  // the second term corresponds to the common mode substraction, looking at a strip far away.
145  for (int k=0;k<16;++k) {
146  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]));
147  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]));
148  }
149  update(); //TODO: temporary: find a better solution later
150 }
151 
152 // -----------------------------------------------------------------------------
153 //
155 
156  LogDebug("Commissioning") << "[CalibrationTask::update]"; // huge output
157 
158  for(auto element : calib1_){ // all pulse for different calChan
159  for(auto vecelement : element.second) // all strips in a calCan
160  updateHistoSet(vecelement);
161  }
162 
163  for(auto element : calib2_){ // all pulse for different calChan
164  for(auto vecelement : element.second) // all strips in a calCan
165  updateHistoSet(vecelement);
166  }
167 
168 }
169 
171  directory_ = dir;
172 }
#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:565
std::vector< uint16_t > ped
void book() override
DQMStore *const dqm() const
collection_type data
Definition: DetSet.h:78
~CalibrationTask() override
T get() const
Definition: EventSetup.h:68
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