CMS 3D CMS Logo

SiStripGainsPCLWorker.cc
Go to the documentation of this file.
4 
5 #include <iostream>
6 #include <sstream>
7 
8 //********************************************************************************//
10  MinTrackMomentum = iConfig.getUntrackedParameter<double>("minTrackMomentum", 3.0);
11  MaxTrackMomentum = iConfig.getUntrackedParameter<double>("maxTrackMomentum", 99999.0);
12  MinTrackEta = iConfig.getUntrackedParameter<double>("minTrackEta", -5.0);
13  MaxTrackEta = iConfig.getUntrackedParameter<double>("maxTrackEta", 5.0);
14  MaxNrStrips = iConfig.getUntrackedParameter<unsigned>("maxNrStrips", 2);
15  MinTrackHits = iConfig.getUntrackedParameter<unsigned>("MinTrackHits", 8);
16  MaxTrackChiOverNdf = iConfig.getUntrackedParameter<double>("MaxTrackChiOverNdf", 3);
17  MaxTrackingIteration = iConfig.getUntrackedParameter<int>("MaxTrackingIteration", 7);
18  AllowSaturation = iConfig.getUntrackedParameter<bool>("AllowSaturation", false);
19  FirstSetOfConstants = iConfig.getUntrackedParameter<bool>("FirstSetOfConstants", true);
20  Validation = iConfig.getUntrackedParameter<bool>("Validation", false);
21  OldGainRemoving = iConfig.getUntrackedParameter<bool>("OldGainRemoving", false);
22  useCalibration = iConfig.getUntrackedParameter<bool>("UseCalibration", false);
23  doChargeMonitorPerPlane = iConfig.getUntrackedParameter<bool>("doChargeMonitorPerPlane", false);
24  m_DQMdir = iConfig.getUntrackedParameter<std::string>("DQMdir", "AlCaReco/SiStripGains");
25  m_calibrationMode = iConfig.getUntrackedParameter<std::string>("calibrationMode", "StdBunch");
26  VChargeHisto = iConfig.getUntrackedParameter<std::vector<std::string>>("ChargeHisto");
27 
28  // fill in the mapping between the histogram indices and the (id,side,plane) tuple
29  std::vector<std::pair<std::string, std::string>> hnames =
30  APVGain::monHnames(VChargeHisto, doChargeMonitorPerPlane, "");
31  for (unsigned int i = 0; i < hnames.size(); i++) {
32  int id = APVGain::subdetectorId((hnames[i]).first);
33  int side = APVGain::subdetectorSide((hnames[i]).first);
34  int plane = APVGain::subdetectorPlane((hnames[i]).first);
35  std::string s = hnames[i].first;
36 
37  auto loc = APVloc(id, side, plane, s);
38  theTopologyMap.insert(std::make_pair(i, loc));
39  }
40 
41  //Set the monitoring element tag and store
42  dqm_tag_.reserve(7);
43  dqm_tag_.clear();
44  dqm_tag_.push_back("StdBunch"); // statistic collection from Standard Collision Bunch @ 3.8 T
45  dqm_tag_.push_back("StdBunch0T"); // statistic collection from Standard Collision Bunch @ 0 T
46  dqm_tag_.push_back("AagBunch"); // statistic collection from First Collision After Abort Gap @ 3.8 T
47  dqm_tag_.push_back("AagBunch0T"); // statistic collection from First Collision After Abort Gap @ 0 T
48  dqm_tag_.push_back("IsoMuon"); // statistic collection from Isolated Muon @ 3.8 T
49  dqm_tag_.push_back("IsoMuon0T"); // statistic collection from Isolated Muon @ 0 T
50  dqm_tag_.push_back("Harvest"); // statistic collection: Harvest
51 
52  // configure token for gathering the ntuple variables
53  edm::ParameterSet swhallowgain_pset = iConfig.getUntrackedParameter<edm::ParameterSet>("gain");
54 
55  std::string label = swhallowgain_pset.getUntrackedParameter<std::string>("label");
56  CalibPrefix_ = swhallowgain_pset.getUntrackedParameter<std::string>("prefix");
57  CalibSuffix_ = swhallowgain_pset.getUntrackedParameter<std::string>("suffix");
58 
59  trackindex_token_ = consumes<std::vector<int>>(edm::InputTag(label, CalibPrefix_ + "trackindex" + CalibSuffix_));
60  rawid_token_ = consumes<std::vector<unsigned int>>(edm::InputTag(label, CalibPrefix_ + "rawid" + CalibSuffix_));
61  localdirx_token_ = consumes<std::vector<double>>(edm::InputTag(label, CalibPrefix_ + "localdirx" + CalibSuffix_));
62  localdiry_token_ = consumes<std::vector<double>>(edm::InputTag(label, CalibPrefix_ + "localdiry" + CalibSuffix_));
63  localdirz_token_ = consumes<std::vector<double>>(edm::InputTag(label, CalibPrefix_ + "localdirz" + CalibSuffix_));
65  consumes<std::vector<unsigned short>>(edm::InputTag(label, CalibPrefix_ + "firststrip" + CalibSuffix_));
66  nstrips_token_ = consumes<std::vector<unsigned short>>(edm::InputTag(label, CalibPrefix_ + "nstrips" + CalibSuffix_));
67  saturation_token_ = consumes<std::vector<bool>>(edm::InputTag(label, CalibPrefix_ + "saturation" + CalibSuffix_));
68  overlapping_token_ = consumes<std::vector<bool>>(edm::InputTag(label, CalibPrefix_ + "overlapping" + CalibSuffix_));
69  farfromedge_token_ = consumes<std::vector<bool>>(edm::InputTag(label, CalibPrefix_ + "farfromedge" + CalibSuffix_));
70  charge_token_ = consumes<std::vector<unsigned int>>(edm::InputTag(label, CalibPrefix_ + "charge" + CalibSuffix_));
71  path_token_ = consumes<std::vector<double>>(edm::InputTag(label, CalibPrefix_ + "path" + CalibSuffix_));
72 #ifdef ExtendedCALIBTree
74  consumes<std::vector<double>>(edm::InputTag(label, CalibPrefix_ + "chargeoverpath" + CalibSuffix_));
75 #endif
77  consumes<std::vector<unsigned char>>(edm::InputTag(label, CalibPrefix_ + "amplitude" + CalibSuffix_));
78  gainused_token_ = consumes<std::vector<double>>(edm::InputTag(label, CalibPrefix_ + "gainused" + CalibSuffix_));
80  consumes<std::vector<double>>(edm::InputTag(label, CalibPrefix_ + "gainusedTick" + CalibSuffix_));
81 
82  edm::ParameterSet evtinfo_pset = iConfig.getUntrackedParameter<edm::ParameterSet>("evtinfo");
83  label = evtinfo_pset.getUntrackedParameter<std::string>("label");
84  EventPrefix_ = evtinfo_pset.getUntrackedParameter<std::string>("prefix");
85  EventSuffix_ = evtinfo_pset.getUntrackedParameter<std::string>("suffix");
86  TrigTech_token_ = consumes<std::vector<bool>>(edm::InputTag(label, EventPrefix_ + "TrigTech" + EventSuffix_));
87 
88  edm::ParameterSet track_pset = iConfig.getUntrackedParameter<edm::ParameterSet>("tracks");
89  label = track_pset.getUntrackedParameter<std::string>("label");
90  TrackPrefix_ = track_pset.getUntrackedParameter<std::string>("prefix");
91  TrackSuffix_ = track_pset.getUntrackedParameter<std::string>("suffix");
92 
93  trackchi2ndof_token_ = consumes<std::vector<double>>(edm::InputTag(label, TrackPrefix_ + "chi2ndof" + TrackSuffix_));
94  trackp_token_ = consumes<std::vector<float>>(edm::InputTag(label, TrackPrefix_ + "momentum" + TrackSuffix_));
95  trackpt_token_ = consumes<std::vector<float>>(edm::InputTag(label, TrackPrefix_ + "pt" + TrackSuffix_));
96  tracketa_token_ = consumes<std::vector<double>>(edm::InputTag(label, TrackPrefix_ + "eta" + TrackSuffix_));
97  trackphi_token_ = consumes<std::vector<double>>(edm::InputTag(label, TrackPrefix_ + "phi" + TrackSuffix_));
99  consumes<std::vector<unsigned int>>(edm::InputTag(label, TrackPrefix_ + "hitsvalid" + TrackSuffix_));
100  trackalgo_token_ = consumes<std::vector<int>>(edm::InputTag(label, TrackPrefix_ + "algo" + TrackSuffix_));
101 }
102 
103 //********************************************************************************//
105  edm::EventSetup const& iSetup,
107  using namespace edm;
108  static constexpr float defaultGainTick = 690. / 640.;
109 
110  // fills the APV collections at each begin run
112  iSetup.get<TrackerDigiGeometryRecord>().get(tkGeom_);
113  const TrackerGeometry* bareTkGeomPtr = &(*tkGeom_);
114  checkBookAPVColls(bareTkGeomPtr, histograms);
115 
116  edm::ESHandle<SiStripGain> gainHandle;
117  iSetup.get<SiStripGainRcd>().get(gainHandle);
118  if (!gainHandle.isValid()) {
119  edm::LogError("SiStripGainPCLWorker") << "gainHandle is not valid\n";
120  exit(0);
121  }
122 
123  edm::ESHandle<SiStripQuality> SiStripQuality_;
124  iSetup.get<SiStripQualityRcd>().get(SiStripQuality_);
125 
126  for (unsigned int a = 0; a < histograms.APVsCollOrdered.size(); a++) {
127  std::shared_ptr<stAPVGain> APV = histograms.APVsCollOrdered[a];
128 
129  if (APV->SubDet == PixelSubdetector::PixelBarrel || APV->SubDet == PixelSubdetector::PixelEndcap)
130  continue;
131 
132  APV->isMasked = SiStripQuality_->IsApvBad(APV->DetId, APV->APVId);
133 
134  if (gainHandle->getNumberOfTags() != 2) {
135  edm::LogError("SiStripGainPCLWorker") << "NUMBER OF GAIN TAG IS EXPECTED TO BE 2\n";
136  fflush(stdout);
137  exit(0);
138  };
139  float newPreviousGain = gainHandle->getApvGain(APV->APVId, gainHandle->getRange(APV->DetId, 1), 1);
140  if (APV->PreviousGain != 1 and newPreviousGain != APV->PreviousGain)
141  edm::LogWarning("SiStripGainPCLWorker") << "WARNING: ParticleGain in the global tag changed\n";
142  APV->PreviousGain = newPreviousGain;
143 
144  float newPreviousGainTick =
145  APV->isMasked ? defaultGainTick : gainHandle->getApvGain(APV->APVId, gainHandle->getRange(APV->DetId, 0), 0);
146  if (APV->PreviousGainTick != 1 and newPreviousGainTick != APV->PreviousGainTick) {
147  edm::LogWarning("SiStripGainPCLWorker")
148  << "WARNING: TickMarkGain in the global tag changed\n"
149  << std::endl
150  << " APV->SubDet: " << APV->SubDet << " APV->APVId:" << APV->APVId << std::endl
151  << " APV->PreviousGainTick: " << APV->PreviousGainTick << " newPreviousGainTick: " << newPreviousGainTick
152  << std::endl;
153  }
154  APV->PreviousGainTick = newPreviousGainTick;
155  }
156 }
157 
158 //********************************************************************************//
159 // ------------ method called for each event ------------
161  edm::EventSetup const& iSetup,
162  APVGain::APVGainHistograms const& histograms) const {
163  using namespace edm;
164 
165  unsigned int eventnumber = iEvent.id().event();
166  unsigned int runnumber = iEvent.id().run();
167 
168  edm::LogInfo("SiStripGainsPCLWorker") << "Processing run " << runnumber << " and event " << eventnumber << std::endl;
169 
171  iSetup.get<TrackerTopologyRcd>().get(TopoHandle);
172  const TrackerTopology* topo = TopoHandle.product();
173 
174  // *****************************
175  // * Event data handles
176  // *****************************
177 
178  //Event data
179 
180  // Track data
182  iEvent.getByToken(trackchi2ndof_token_, handle01);
183  auto trackchi2ndof = handle01.product();
184 
186  iEvent.getByToken(trackp_token_, handle02);
187  auto trackp = handle02.product();
188 
190  iEvent.getByToken(tracketa_token_, handle03);
191  auto tracketa = handle03.product();
192 
194  iEvent.getByToken(trackhitsvalid_token_, handle04);
195  auto trackhitsvalid = handle04.product();
196 
198  iEvent.getByToken(trackalgo_token_, handle05);
199  auto trackalgo = handle05.product();
200 
201  // CalibTree data
203  iEvent.getByToken(trackindex_token_, handle06);
204  auto trackindex = handle06.product();
205 
207  iEvent.getByToken(rawid_token_, handle07);
208  auto rawid = handle07.product();
209 
211  iEvent.getByToken(firststrip_token_, handle08);
212  auto firststrip = handle08.product();
213 
215  iEvent.getByToken(nstrips_token_, handle09);
216  auto nstrips = handle09.product();
217 
219  iEvent.getByToken(saturation_token_, handle10);
220  auto saturation = handle10.product();
221 
223  iEvent.getByToken(overlapping_token_, handle11);
224  auto overlapping = handle11.product();
225 
227  iEvent.getByToken(farfromedge_token_, handle12);
228  auto farfromedge = handle12.product();
229 
231  iEvent.getByToken(charge_token_, handle13);
232  auto charge = handle13.product();
233 
235  iEvent.getByToken(path_token_, handle14);
236  auto path = handle14.product();
237 
238 #ifdef ExtendedCALIBTree
240  iEvent.getByToken(chargeoverpath_token_, handle15);
241  auto chargeoverpath = handle15.product();
242 #endif
243 
245  iEvent.getByToken(amplitude_token_, handle16);
246  auto amplitude = handle16.product();
247 
249  iEvent.getByToken(gainused_token_, handle17);
250  auto gainused = handle17.product();
251 
253  iEvent.getByToken(gainusedTick_token_, handle18);
254  auto gainusedTick = handle18.product();
255 
256  for (const auto& elem : theTopologyMap) {
257  LogDebug("SiStripGainsPCLWorker") << elem.first << " - " << elem.second.m_string << " "
258  << elem.second.m_subdetectorId << " " << elem.second.m_subdetectorSide << " "
259  << elem.second.m_subdetectorPlane << std::endl;
260  }
261 
262  LogDebug("SiStripGainsPCLWorker") << "for mode" << m_calibrationMode << std::endl;
263 
264  int elepos = statCollectionFromMode(m_calibrationMode.c_str());
265 
266  unsigned int FirstAmplitude = 0;
267  for (unsigned int i = 0; i < charge->size(); i++) {
268  FirstAmplitude += (*nstrips)[i];
269  int TI = (*trackindex)[i];
270 
271  if ((*tracketa)[TI] < MinTrackEta)
272  continue;
273  if ((*tracketa)[TI] > MaxTrackEta)
274  continue;
275  if ((*trackp)[TI] < MinTrackMomentum)
276  continue;
277  if ((*trackp)[TI] > MaxTrackMomentum)
278  continue;
279  if ((*trackhitsvalid)[TI] < MinTrackHits)
280  continue;
281  if ((*trackchi2ndof)[TI] > MaxTrackChiOverNdf)
282  continue;
283  if ((*trackalgo)[TI] > MaxTrackingIteration)
284  continue;
285 
286  std::shared_ptr<stAPVGain> APV = histograms.APVsColl.at(
287  ((*rawid)[i] << 4) |
288  ((*firststrip)[i] /
289  128)); //works for both strip and pixel thanks to firstStrip encoding for pixel in the calibTree
290 
291  if (APV->SubDet > 2 && (*farfromedge)[i] == false)
292  continue;
293  if (APV->SubDet > 2 && (*overlapping)[i] == true)
294  continue;
295  if (APV->SubDet > 2 && (*saturation)[i] && !AllowSaturation)
296  continue;
297  if (APV->SubDet > 2 && (*nstrips)[i] > MaxNrStrips)
298  continue;
299 
300  int Charge = 0;
301  if (APV->SubDet > 2 && (useCalibration || !FirstSetOfConstants)) {
302  bool Saturation = false;
303  for (unsigned int s = 0; s < (*nstrips)[i]; s++) {
304  int StripCharge = (*amplitude)[FirstAmplitude - (*nstrips)[i] + s];
306  StripCharge = (int)(StripCharge * (APV->PreviousGain / APV->CalibGain));
307  } else if (useCalibration) {
308  StripCharge = (int)(StripCharge / APV->CalibGain);
309  } else if (!FirstSetOfConstants) {
310  StripCharge = (int)(StripCharge * APV->PreviousGain);
311  }
312  if (StripCharge > 1024) {
313  StripCharge = 255;
314  Saturation = true;
315  } else if (StripCharge > 254) {
316  StripCharge = 254;
317  Saturation = true;
318  }
319  Charge += StripCharge;
320  }
321  if (Saturation && !AllowSaturation)
322  continue;
323  } else if (APV->SubDet > 2) {
324  Charge = (*charge)[i];
325  } else {
326  Charge = (*charge)[i] / 265.0; //expected scale factor between pixel and strip charge
327  }
328 
329  double ClusterChargeOverPath = ((double)Charge) / (*path)[i];
330  if (APV->SubDet > 2) {
331  if (Validation) {
332  ClusterChargeOverPath /= (*gainused)[i];
333  }
334  if (OldGainRemoving) {
335  ClusterChargeOverPath *= (*gainused)[i];
336  }
337  }
338 
339  // keep processing of pixel cluster charge until here
340  if (APV->SubDet <= 2)
341  continue;
342 
343  // real histogram for calibration
344  histograms.Charge_Vs_Index[elepos]->Fill(APV->Index, ClusterChargeOverPath);
345  LogDebug("SiStripGainsPCLWorker") << " for mode " << m_calibrationMode << "\n"
346  << " i " << i << " useCalibration " << useCalibration << " FirstSetOfConstants "
347  << FirstSetOfConstants << " APV->PreviousGain " << APV->PreviousGain
348  << " APV->CalibGain " << APV->CalibGain << " APV->DetId " << APV->DetId
349  << " APV->Index " << APV->Index << " Charge " << Charge << " Path " << (*path)[i]
350  << " ClusterChargeOverPath " << ClusterChargeOverPath << std::endl;
351 
352  // Fill monitoring histograms
353  int mCharge1 = 0;
354  int mCharge2 = 0;
355  int mCharge3 = 0;
356  int mCharge4 = 0;
357  if (APV->SubDet > 2) {
358  for (unsigned int s = 0; s < (*nstrips)[i]; s++) {
359  int StripCharge = (*amplitude)[FirstAmplitude - (*nstrips)[i] + s];
360  if (StripCharge > 1024)
361  StripCharge = 255;
362  else if (StripCharge > 254)
363  StripCharge = 254;
364  mCharge1 += StripCharge;
365  mCharge2 += StripCharge;
366  mCharge3 += StripCharge;
367  mCharge4 += StripCharge;
368  }
369  // Revome gains for monitoring
370  mCharge2 *= (*gainused)[i]; // remove G2
371  mCharge3 *= (*gainusedTick)[i]; // remove G1
372  mCharge4 *= ((*gainused)[i] * (*gainusedTick)[i]); // remove G1 and G2
373  }
374 
375  LogDebug("SiStripGainsPCLWorker") << " full charge " << mCharge1 << " remove G2 " << mCharge2 << " remove G1 "
376  << mCharge3 << " remove G1*G2 " << mCharge4 << std::endl;
377 
378  auto indices = APVGain::FetchIndices(theTopologyMap, (*rawid)[i], topo);
379 
380  for (auto m : indices)
381  histograms.Charge_1[elepos][m]->Fill(((double)mCharge1) / (*path)[i]);
382  for (auto m : indices)
383  histograms.Charge_2[elepos][m]->Fill(((double)mCharge2) / (*path)[i]);
384  for (auto m : indices)
385  histograms.Charge_3[elepos][m]->Fill(((double)mCharge3) / (*path)[i]);
386  for (auto m : indices)
387  histograms.Charge_4[elepos][m]->Fill(((double)mCharge4) / (*path)[i]);
388 
389  if (APV->SubDet == StripSubdetector::TIB) {
390  histograms.Charge_Vs_PathlengthTIB[elepos]->Fill((*path)[i], Charge); // TIB
391 
392  } else if (APV->SubDet == StripSubdetector::TOB) {
393  histograms.Charge_Vs_PathlengthTOB[elepos]->Fill((*path)[i], Charge); // TOB
394 
395  } else if (APV->SubDet == StripSubdetector::TID) {
396  if (APV->Eta < 0) {
397  histograms.Charge_Vs_PathlengthTIDM[elepos]->Fill((*path)[i], Charge);
398  } // TID minus
399  else if (APV->Eta > 0) {
400  histograms.Charge_Vs_PathlengthTIDP[elepos]->Fill((*path)[i], Charge);
401  } // TID plus
402 
403  } else if (APV->SubDet == StripSubdetector::TEC) {
404  if (APV->Eta < 0) {
405  if (APV->Thickness < 0.04) {
406  histograms.Charge_Vs_PathlengthTECM1[elepos]->Fill((*path)[i], Charge);
407  } // TEC minus, type 1
408  else if (APV->Thickness > 0.04) {
409  histograms.Charge_Vs_PathlengthTECM2[elepos]->Fill((*path)[i], Charge);
410  } // TEC minus, type 2
411  } else if (APV->Eta > 0) {
412  if (APV->Thickness < 0.04) {
413  histograms.Charge_Vs_PathlengthTECP1[elepos]->Fill((*path)[i], Charge);
414  } // TEC plus, type 1
415  else if (APV->Thickness > 0.04) {
416  histograms.Charge_Vs_PathlengthTECP2[elepos]->Fill((*path)[i], Charge);
417  } // TEC plus, type 2
418  }
419  }
420 
421  } // END OF ON-CLUSTER LOOP
422 
423  //LogDebug("SiStripGainsPCLWorker")<<" for mode"<< m_calibrationMode
424  // <<" entries in histogram:"<< histograms.Charge_Vs_Index[elepos].getEntries()
425  // <<std::endl;
426 }
427 
428 //********************************************************************************//
430 
431 //********************************************************************************//
432 // ------------ method called once each job just before starting event loop ------------
435  if (bareTkGeomPtr) { // pointer not yet set: called the first time => fill the APVColls
436  auto const& Det = bareTkGeomPtr->dets();
437 
438  edm::LogInfo("SiStripGainsPCLWorker") << " Resetting APV struct" << std::endl;
439 
440  unsigned int Index = 0;
441 
442  for (unsigned int i = 0; i < Det.size(); i++) {
443  DetId Detid = Det[i]->geographicalId();
444  int SubDet = Detid.subdetId();
445 
446  if (SubDet == StripSubdetector::TIB || SubDet == StripSubdetector::TID || SubDet == StripSubdetector::TOB ||
447  SubDet == StripSubdetector::TEC) {
448  auto DetUnit = dynamic_cast<const StripGeomDetUnit*>(Det[i]);
449  if (!DetUnit)
450  continue;
451 
452  const StripTopology& Topo = DetUnit->specificTopology();
453  unsigned int NAPV = Topo.nstrips() / 128;
454 
455  for (unsigned int j = 0; j < NAPV; j++) {
456  auto APV = std::make_shared<stAPVGain>();
457  APV->Index = Index;
458  APV->Bin = -1;
459  APV->DetId = Detid.rawId();
460  APV->APVId = j;
461  APV->SubDet = SubDet;
462  APV->FitMPV = -1;
463  APV->FitMPVErr = -1;
464  APV->FitWidth = -1;
465  APV->FitWidthErr = -1;
466  APV->FitChi2 = -1;
467  APV->FitNorm = -1;
468  APV->Gain = -1;
469  APV->PreviousGain = 1;
470  APV->PreviousGainTick = 1;
471  APV->x = DetUnit->position().basicVector().x();
472  APV->y = DetUnit->position().basicVector().y();
473  APV->z = DetUnit->position().basicVector().z();
474  APV->Eta = DetUnit->position().basicVector().eta();
475  APV->Phi = DetUnit->position().basicVector().phi();
476  APV->R = DetUnit->position().basicVector().transverse();
477  APV->Thickness = DetUnit->surface().bounds().thickness();
478  APV->NEntries = 0;
479  APV->isMasked = false;
480 
481  histograms.APVsCollOrdered.push_back(APV);
482  histograms.APVsColl[(APV->DetId << 4) | APV->APVId] = APV;
483  Index++;
484  histograms.NStripAPVs++;
485  } // loop on APVs
486  } // if is Strips
487  } // loop on dets
488 
489  for (unsigned int i = 0; i < Det.size();
490  i++) { //Make two loop such that the Pixel information is added at the end --> make transition simpler
491  DetId Detid = Det[i]->geographicalId();
492  int SubDet = Detid.subdetId();
494  auto DetUnit = dynamic_cast<const PixelGeomDetUnit*>(Det[i]);
495  if (!DetUnit)
496  continue;
497 
498  const PixelTopology& Topo = DetUnit->specificTopology();
499  unsigned int NROCRow = Topo.nrows() / (80.);
500  unsigned int NROCCol = Topo.ncolumns() / (52.);
501 
502  for (unsigned int j = 0; j < NROCRow; j++) {
503  for (unsigned int i = 0; i < NROCCol; i++) {
504  auto APV = std::make_shared<stAPVGain>();
505  APV->Index = Index;
506  APV->Bin = -1;
507  APV->DetId = Detid.rawId();
508  APV->APVId = (j << 3 | i);
509  APV->SubDet = SubDet;
510  APV->FitMPV = -1;
511  APV->FitMPVErr = -1;
512  APV->FitWidth = -1;
513  APV->FitWidthErr = -1;
514  APV->FitChi2 = -1;
515  APV->Gain = -1;
516  APV->PreviousGain = 1;
517  APV->PreviousGainTick = 1;
518  APV->x = DetUnit->position().basicVector().x();
519  APV->y = DetUnit->position().basicVector().y();
520  APV->z = DetUnit->position().basicVector().z();
521  APV->Eta = DetUnit->position().basicVector().eta();
522  APV->Phi = DetUnit->position().basicVector().phi();
523  APV->R = DetUnit->position().basicVector().transverse();
524  APV->Thickness = DetUnit->surface().bounds().thickness();
525  APV->isMasked = false; //SiPixelQuality_->IsModuleBad(Detid.rawId());
526  APV->NEntries = 0;
527 
528  histograms.APVsCollOrdered.push_back(APV);
529  histograms.APVsColl[(APV->DetId << 4) | APV->APVId] = APV;
530  Index++;
531  histograms.NPixelDets++;
532 
533  } // loop on ROC cols
534  } // loop on ROC rows
535  } // if Pixel
536  } // loop on Dets
537  } //if (!bareTkGeomPtr_) ...
538 }
539 
540 //********************************************************************************//
542 
543 //********************************************************************************//
546  desc.setUnknown();
547  descriptions.addDefault(desc);
548 }
549 
550 //********************************************************************************//
552  edm::Run const& run,
553  edm::EventSetup const& setup,
555  ibooker.cd();
556  std::string dqm_dir = m_DQMdir;
557  const char* tag = dqm_tag_[statCollectionFromMode(m_calibrationMode.c_str())].c_str();
558 
559  edm::LogInfo("SiStripGainsPCLWorker") << "Setting " << dqm_dir << " in DQM and booking histograms for tag " << tag
560  << std::endl;
561 
562  ibooker.setCurrentFolder(dqm_dir);
563 
564  std::string stag(tag);
565  if (!stag.empty() && stag[0] != '_')
566  stag.insert(0, 1, '_');
567 
568  std::string cvi = std::string("Charge_Vs_Index") + stag;
569  std::string cvpTIB = std::string("Charge_Vs_PathlengthTIB") + stag;
570  std::string cvpTOB = std::string("Charge_Vs_PathlengthTOB") + stag;
571  std::string cvpTIDP = std::string("Charge_Vs_PathlengthTIDP") + stag;
572  std::string cvpTIDM = std::string("Charge_Vs_PathlengthTIDM") + stag;
573  std::string cvpTECP1 = std::string("Charge_Vs_PathlengthTECP1") + stag;
574  std::string cvpTECP2 = std::string("Charge_Vs_PathlengthTECP2") + stag;
575  std::string cvpTECM1 = std::string("Charge_Vs_PathlengthTECM1") + stag;
576  std::string cvpTECM2 = std::string("Charge_Vs_PathlengthTECM2") + stag;
577 
578  int elepos = statCollectionFromMode(tag);
579 
580  histograms.Charge_Vs_Index.reserve(dqm_tag_.size());
581  histograms.Charge_Vs_PathlengthTIB.reserve(dqm_tag_.size());
582  histograms.Charge_Vs_PathlengthTOB.reserve(dqm_tag_.size());
583  histograms.Charge_Vs_PathlengthTIDP.reserve(dqm_tag_.size());
584  histograms.Charge_Vs_PathlengthTIDM.reserve(dqm_tag_.size());
585  histograms.Charge_Vs_PathlengthTECP1.reserve(dqm_tag_.size());
586  histograms.Charge_Vs_PathlengthTECP2.reserve(dqm_tag_.size());
587  histograms.Charge_Vs_PathlengthTECM1.reserve(dqm_tag_.size());
588  histograms.Charge_Vs_PathlengthTECM2.reserve(dqm_tag_.size());
589 
590  // The cluster charge is stored by exploiting a non uniform binning in order
591  // reduce the histogram memory size. The bin width is relaxed with a falling
592  // exponential function and the bin boundaries are stored in the binYarray.
593  // The binXarray is used to provide as many bins as the APVs.
594  //
595  // More details about this implementations are here:
596  // https://indico.cern.ch/event/649344/contributions/2672267/attachments/1498323/2332518/OptimizeChHisto.pdf
597 
598  std::vector<float> binXarray;
599  binXarray.reserve(histograms.NStripAPVs + 1);
600  for (unsigned int a = 0; a <= histograms.NStripAPVs; a++) {
601  binXarray.push_back((float)a);
602  }
603 
604  std::array<float, 688> binYarray;
605  double p0 = 5.445;
606  double p1 = 0.002113;
607  double p2 = 69.01576;
608  double y = 0.;
609  for (int b = 0; b < 687; b++) {
610  binYarray[b] = y;
611  if (y <= 902.)
612  y = y + 2.;
613  else
614  y = (p0 - log(exp(p0 - p1 * y) - p2 * p1)) / p1;
615  }
616  binYarray[687] = 4000.;
617 
618  histograms.Charge_1[elepos].clear();
619  histograms.Charge_2[elepos].clear();
620  histograms.Charge_3[elepos].clear();
621  histograms.Charge_4[elepos].clear();
622 
623  auto it = histograms.Charge_Vs_Index.begin();
624  histograms.Charge_Vs_Index.insert(
625  it + elepos,
626  ibooker.book2S(cvi.c_str(), cvi.c_str(), histograms.NStripAPVs, &binXarray[0], 687, binYarray.data()));
627 
628  it = histograms.Charge_Vs_PathlengthTIB.begin();
629  histograms.Charge_Vs_PathlengthTIB.insert(it + elepos,
630  ibooker.book2S(cvpTIB.c_str(), cvpTIB.c_str(), 20, 0.3, 1.3, 250, 0, 2000));
631 
632  it = histograms.Charge_Vs_PathlengthTOB.begin();
633  histograms.Charge_Vs_PathlengthTOB.insert(it + elepos,
634  ibooker.book2S(cvpTOB.c_str(), cvpTOB.c_str(), 20, 0.3, 1.3, 250, 0, 2000));
635 
636  it = histograms.Charge_Vs_PathlengthTIDP.begin();
637  histograms.Charge_Vs_PathlengthTIDP.insert(
638  it + elepos, ibooker.book2S(cvpTIDP.c_str(), cvpTIDP.c_str(), 20, 0.3, 1.3, 250, 0, 2000));
639 
640  it = histograms.Charge_Vs_PathlengthTIDM.begin();
641  histograms.Charge_Vs_PathlengthTIDM.insert(
642  it + elepos, ibooker.book2S(cvpTIDM.c_str(), cvpTIDM.c_str(), 20, 0.3, 1.3, 250, 0, 2000));
643 
644  it = histograms.Charge_Vs_PathlengthTECP1.begin();
645  histograms.Charge_Vs_PathlengthTECP1.insert(
646  it + elepos, ibooker.book2S(cvpTECP1.c_str(), cvpTECP1.c_str(), 20, 0.3, 1.3, 250, 0, 2000));
647 
648  it = histograms.Charge_Vs_PathlengthTECP2.begin();
649  histograms.Charge_Vs_PathlengthTECP2.insert(
650  it + elepos, ibooker.book2S(cvpTECP2.c_str(), cvpTECP2.c_str(), 20, 0.3, 1.3, 250, 0, 2000));
651 
652  it = histograms.Charge_Vs_PathlengthTECM1.begin();
653  histograms.Charge_Vs_PathlengthTECM1.insert(
654  it + elepos, ibooker.book2S(cvpTECM1.c_str(), cvpTECM1.c_str(), 20, 0.3, 1.3, 250, 0, 2000));
655 
656  it = histograms.Charge_Vs_PathlengthTECM2.begin();
657  histograms.Charge_Vs_PathlengthTECM2.insert(
658  it + elepos, ibooker.book2S(cvpTECM2.c_str(), cvpTECM2.c_str(), 20, 0.3, 1.3, 250, 0, 2000));
659 
660  std::vector<std::pair<std::string, std::string>> hnames =
662  for (unsigned int i = 0; i < hnames.size(); i++) {
663  std::string htag = (hnames[i]).first + stag;
664  histograms.Charge_1[elepos].push_back(ibooker.book1DD(htag.c_str(), (hnames[i]).second.c_str(), 100, 0., 1000.));
665  }
666 
668  for (unsigned int i = 0; i < hnames.size(); i++) {
669  std::string htag = (hnames[i]).first + stag;
670  histograms.Charge_2[elepos].push_back(ibooker.book1DD(htag.c_str(), (hnames[i]).second.c_str(), 100, 0., 1000.));
671  }
672 
674  for (unsigned int i = 0; i < hnames.size(); i++) {
675  std::string htag = (hnames[i]).first + stag;
676  histograms.Charge_3[elepos].push_back(ibooker.book1DD(htag.c_str(), (hnames[i]).second.c_str(), 100, 0., 1000.));
677  }
678 
680  for (unsigned int i = 0; i < hnames.size(); i++) {
681  std::string htag = (hnames[i]).first + stag;
682  histograms.Charge_4[elepos].push_back(ibooker.book1DD(htag.c_str(), (hnames[i]).second.c_str(), 100, 0., 1000.));
683  }
684 }
#define LogDebug(id)
RunNumber_t run() const
Definition: EventID.h:38
bool IsApvBad(const uint32_t &detid, const short &apvNb) const
edm::EDGetTokenT< std::vector< double > > gainused_token_
EventNumber_t event() const
Definition: EventID.h:40
static constexpr auto TEC
T getUntrackedParameter(std::string const &, T const &) const
virtual int nrows() const =0
std::array< std::vector< dqm::reco::MonitorElement * >, 7 > Charge_4
edm::EDGetTokenT< std::vector< double > > localdirz_token_
edm::EDGetTokenT< std::vector< bool > > saturation_token_
edm::EDGetTokenT< std::vector< double > > trackchi2ndof_token_
edm::EDGetTokenT< std::vector< double > > gainusedTick_token_
size_t getNumberOfTags() const
Definition: SiStripGain.h:95
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
std::vector< dqm::reco::MonitorElement * > Charge_Vs_Index
MonitorElement * book2S(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Definition: DQMStore.cc:284
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:418
edm::EDGetTokenT< std::vector< float > > trackp_token_
SiStripGainsPCLWorker(const edm::ParameterSet &)
MonitorElement * book1DD(TString const &name, TString const &title, int nchX, double lowX, double highX)
Definition: DQMStore.cc:257
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
std::vector< dqm::reco::MonitorElement * > Charge_Vs_PathlengthTOB
int subdetectorPlane(uint32_t, const TrackerTopology *)
std::vector< dqm::reco::MonitorElement * > Charge_Vs_PathlengthTIDP
edm::EDGetTokenT< std::vector< unsigned int > > trackhitsvalid_token_
std::vector< dqm::reco::MonitorElement * > Charge_Vs_PathlengthTIDM
edm::EDGetTokenT< std::vector< unsigned short > > firststrip_token_
edm::EDGetTokenT< std::vector< bool > > farfromedge_token_
edm::EDGetTokenT< std::vector< bool > > overlapping_token_
static float getApvGain(const uint16_t &apv, const SiStripApvGain::Range &range)
Definition: SiStripGain.h:76
std::vector< std::string > dqm_tag_
U second(std::pair< T, U > const &p)
edm::EDGetTokenT< std::vector< unsigned short > > nstrips_token_
edm::EDGetTokenT< std::vector< double > > tracketa_token_
char const * label
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
std::vector< dqm::reco::MonitorElement * > Charge_Vs_PathlengthTECP2
void dqmBeginRun(edm::Run const &, edm::EventSetup const &, APVGain::APVGainHistograms &) const override
int iEvent
Definition: GenABIO.cc:224
void addDefault(ParameterSetDescription const &psetDescription)
std::atomic< unsigned int > NPixelDets
std::array< std::vector< dqm::reco::MonitorElement * >, 7 > Charge_3
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
std::atomic< unsigned int > NStripAPVs
std::vector< unsigned int > FetchIndices(std::map< unsigned int, APVloc >, uint32_t, const TrackerTopology *topo=0)
std::map< unsigned int, APVloc > theTopologyMap
static constexpr auto TOB
edm::EDGetTokenT< std::vector< int > > trackindex_token_
double p2[4]
Definition: TauolaWrapper.h:90
edm::EDGetTokenT< std::vector< double > > localdirx_token_
edm::EDGetTokenT< std::vector< unsigned int > > charge_token_
def elem(elemtype, innerHTML='', html_class='', kwargs)
Definition: HTMLExport.py:19
edm::EDGetTokenT< std::vector< double > > trackphi_token_
Definition: DetId.h:17
static constexpr auto TIB
T const * product() const
Definition: Handle.h:69
edm::EDGetTokenT< std::vector< float > > trackpt_token_
virtual int nstrips() const =0
void checkBookAPVColls(const TrackerGeometry *bareTkGeomPtr, APVGain::APVGainHistograms &histograms) const
std::vector< std::shared_ptr< stAPVGain > > APVsCollOrdered
void dqmAnalyze(edm::Event const &, edm::EventSetup const &, APVGain::APVGainHistograms const &) const override
int subdetectorSide(uint32_t, const TrackerTopology *)
double b
Definition: hdecay.h:118
std::vector< std::string > VChargeHisto
std::unordered_map< unsigned int, std::shared_ptr< stAPVGain > > APVsColl
edm::EDGetTokenT< std::vector< double > > path_token_
edm::EventID id() const
Definition: EventBase.h:59
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &, APVGain::APVGainHistograms &) const override
HLT enums.
virtual int ncolumns() const =0
double p1[4]
Definition: TauolaWrapper.h:89
double a
Definition: hdecay.h:119
T get() const
Definition: EventSetup.h:73
std::array< std::vector< dqm::reco::MonitorElement * >, 7 > Charge_1
std::vector< dqm::reco::MonitorElement * > Charge_Vs_PathlengthTECM2
int statCollectionFromMode(const char *tag) const
edm::EDGetTokenT< std::vector< double > > chargeoverpath_token_
edm::EDGetTokenT< std::vector< int > > trackalgo_token_
std::array< std::vector< dqm::reco::MonitorElement * >, 7 > Charge_2
edm::EDGetTokenT< std::vector< double > > localdiry_token_
std::vector< dqm::reco::MonitorElement * > Charge_Vs_PathlengthTECM1
std::vector< std::pair< std::string, std::string > > monHnames(std::vector< std::string >, bool, const char *tag)
bool isValid() const
Definition: ESHandle.h:44
edm::EDGetTokenT< std::vector< unsigned char > > amplitude_token_
static constexpr auto TID
T const * product() const
Definition: ESHandle.h:86
std::vector< dqm::reco::MonitorElement * > Charge_Vs_PathlengthTIB
int subdetectorId(uint32_t)
std::vector< dqm::reco::MonitorElement * > Charge_Vs_PathlengthTECP1
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
#define constexpr
Definition: Run.h:45
edm::EDGetTokenT< std::vector< unsigned int > > rawid_token_
const SiStripApvGain::Range getRange(uint32_t detID) const
Definition: SiStripGain.h:71
def exit(msg="")
edm::EDGetTokenT< std::vector< bool > > TrigTech_token_