CMS 3D CMS Logo

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