CMS 3D CMS Logo

SiStripGainCosmicCalculator.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 // Package: SiStripChannelGain
3 // Class: SiStripGainCosmicCalculator
4 // Original Author: G. Bruno, D. Kcira
5 // Created: Mon May 20 10:04:31 CET 2007
18 #include "CLHEP/Random/RandFlat.h"
19 #include "CLHEP/Random/RandGauss.h"
34 //#include "DQM/SiStripCommon/interface/SiStripGenerateKey.h"
35 
36 //---------------------------------------------------------------------------------------------------------
38  edm::LogInfo("SiStripGainCosmicCalculator::SiStripGainCosmicCalculator");
40  edm::LogInfo("SiStripApvGainCalculator::SiStripApvGainCalculator")<<"ExpectedChargeDeposition="<<ExpectedChargeDeposition;
41 
42  TrackProducer = iConfig.getParameter<std::string>("TrackProducer");
43  TrackLabel = iConfig.getParameter<std::string>("TrackLabel");
44 
45  detModulesToBeExcluded.clear(); detModulesToBeExcluded = iConfig.getParameter< std::vector<unsigned> >("detModulesToBeExcluded");
46  MinNrEntries = iConfig.getUntrackedParameter<unsigned>("minNrEntries", 20);
47  MaxChi2OverNDF = iConfig.getUntrackedParameter<double>("maxChi2OverNDF", 5.);
48 
49  outputHistogramsInRootFile = iConfig.getParameter<bool>("OutputHistogramsInRootFile");
50  outputFileName = iConfig.getParameter<std::string>("OutputFileName");
51 
52  edm::LogInfo("SiStripApvGainCalculator")<<"Clusters from "<<detModulesToBeExcluded.size()<<" modules will be ignored in the calibration:";
53  edm::LogInfo("SiStripApvGainCalculator")<<"The calibration for these DetIds will be set to a default value";
54  for( std::vector<uint32_t>::const_iterator imod = detModulesToBeExcluded.begin(); imod != detModulesToBeExcluded.end(); imod++){
55  edm::LogInfo("SiStripApvGainCalculator")<<"exclude detid = "<< *imod;
56  }
57 
58  printdebug_ = iConfig.getUntrackedParameter<bool>("printDebug", false);
59  tTopo = nullptr;
60 }
61 
62 
64  edm::LogInfo("SiStripGainCosmicCalculator::~SiStripGainCosmicCalculator");
65 }
66 
68 }
69 
71 {
72  //Retrieve tracker topology from geometry
74  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
75  tTopo = tTopoHandle.product();
76 
77  edm::ESHandle<SiStripDetCabling> siStripDetCablingH;
78  iSetup.get<SiStripDetCablingRcd>().get(siStripDetCablingH);
79  siStripDetCabling = siStripDetCablingH.product();
80 
82  iSetup.get<TrackerDigiGeometryRecord>().get( tkGeomH );
83  tkGeom = tkGeomH.product();
84 
85  std::cout<<"SiStripGainCosmicCalculator::algoBeginJob called"<<std::endl;
87  HlistAPVPairs = new TObjArray(); HlistOtherHistos = new TObjArray();
88  //
89  HlistOtherHistos->Add(new TH1F( Form("APVPairCorrections"), Form("APVPairCorrections"), 50,-1.,4.));
90  HlistOtherHistos->Add(new TH1F(Form("APVPairCorrectionsTIB1mono"),Form("APVPairCorrectionsTIB1mono"),50,-1.,4.));
91  HlistOtherHistos->Add(new TH1F(Form("APVPairCorrectionsTIB1stereo"),Form("APVPairCorrectionsTIB1stereo"),50,-1.,4.));
92  HlistOtherHistos->Add(new TH1F(Form("APVPairCorrectionsTIB2"),Form("APVPairCorrectionsTIB2"),50,-1.,4.));
93  HlistOtherHistos->Add(new TH1F(Form("APVPairCorrectionsTOB1"),Form("APVPairCorrectionsTOB1"),50,-1.,4.));
94  HlistOtherHistos->Add(new TH1F(Form("APVPairCorrectionsTOB2"),Form("APVPairCorrectionsTOB2"),50,-1.,4.));
95  HlistOtherHistos->Add(new TH1F(Form("LocalAngle"),Form("LocalAngle"),70,-0.1,3.4));
96  HlistOtherHistos->Add(new TH1F(Form("LocalAngleAbsoluteCosine"),Form("LocalAngleAbsoluteCosine"),48,-0.1,1.1));
97  HlistOtherHistos->Add(new TH1F(Form("LocalPosition_cm"),Form("LocalPosition_cm"),100,-5.,5.));
98  HlistOtherHistos->Add(new TH1F(Form("LocalPosition_normalized"),Form("LocalPosition_normalized"),100,-1.1,1.1));
99  TH1F* local_histo = new TH1F(Form("SiStripRecHitType"),Form("SiStripRecHitType"),2,0.5,2.5); HlistOtherHistos->Add(local_histo);
100  local_histo->GetXaxis()->SetBinLabel(1,"simple"); local_histo->GetXaxis()->SetBinLabel(2,"matched");
101 
102  // get cabling and find out list of active detectors
104  std::vector<uint32_t> activeDets; activeDets.clear();
105  SelectedDetIds.clear();
106  siStripDetCabling->addActiveDetectorsRawIds(activeDets);
107 // SelectedDetIds = activeDets; // all active detector modules
108  // use SiStripSubStructure for selecting certain regions
109  SiStripSubStructure::getTIBDetectors(activeDets, SelectedDetIds, tTopo, 0, 0, 0, 0); // this adds rawDetIds to SelectedDetIds
110  SiStripSubStructure::getTOBDetectors(activeDets, SelectedDetIds, tTopo, 0, 0, 0); // this adds rawDetIds to SelectedDetIds
111  // get tracker geometry and find nr. of apv pairs for each active detector
113  for(TrackerGeometry::DetContainer::const_iterator it = tkGeom->dets().begin(); it != tkGeom->dets().end(); it++){ // loop over detector modules
114  if( dynamic_cast<const StripGeomDetUnit*>((*it))!=nullptr){
115  uint32_t detid= ((*it)->geographicalId()).rawId();
116  // get thickness for all detector modules, not just for active, this is strange
117  double module_thickness = (*it)->surface().bounds().thickness(); // get thickness of detector from GeomDet (DetContainer == vector<GeomDet*>)
118  thickness_map.insert(std::make_pair(detid,module_thickness));
119  //
120  bool is_active_detector = false;
121  for(std::vector<uint32_t>::iterator iactive = SelectedDetIds.begin(); iactive != SelectedDetIds.end(); iactive++){
122  if( *iactive == detid ){
123  is_active_detector = true;
124  break; // leave for loop if found matching detid
125  }
126  }
127  //
128  bool exclude_this_detid = false;
129  for( std::vector<uint32_t>::const_iterator imod = detModulesToBeExcluded.begin(); imod != detModulesToBeExcluded.end(); imod++ ){
130  if(*imod == detid) exclude_this_detid = true; // found in exclusion list
131  break;
132  }
133  //
134  if(is_active_detector && (!exclude_this_detid)){ // check whether is active detector and that should not be excluded
135  const StripTopology& p = dynamic_cast<const StripGeomDetUnit*>((*it))->specificTopology();
136  unsigned short NAPVPairs = p.nstrips()/256;
137  if( NAPVPairs<2 || NAPVPairs>3 ) {
138  edm::LogError("SiStripGainCosmicCalculator")<<"Problem with Number of strips in detector: "<<p.nstrips()<<" Exiting program";
139  exit(1);
140  }
141  for(int iapp = 0; iapp<NAPVPairs; iapp++){
142  TString hid = Form("ChargeAPVPair_%i_%i",detid,iapp);
143  HlistAPVPairs->Add(new TH1F(hid,hid,45,0.,1350.)); // multiply by 3 to take into account division by width
144  }
145  }
146  }
147  }
148 }
149 
150 //---------------------------------------------------------------------------------------------------------
152  using namespace edm;
154 
155  //TO BE RESTORED
156  // anglefinder_->init(event,iSetup);
157 
158 
159  // get seeds
160 // edm::Handle<TrajectorySeedCollection> seedcoll;
161 // event.getByType(seedcoll);
162  // get tracks
164  const reco::TrackCollection *tracks=trackCollection.product();
165 
166 // // get magnetic field
167 // edm::ESHandle<MagneticField> esmagfield;
168 // es.get<IdealMagneticFieldRecord>().get(esmagfield);
169 // magfield=&(*esmagfield);
170  // loop over tracks
171  for(reco::TrackCollection::const_iterator itr = tracks->begin(); itr != tracks->end(); itr++){ // looping over tracks
172 
173  //TO BE RESTORED
174  // std::vector<std::pair<const TrackingRecHit *,float> >hitangle =anglefinder_->findtrackangle((*(*seedcoll).begin()),*itr);
175  std::vector<std::pair<const TrackingRecHit *,float> >hitangle;// =anglefinder_->findtrackangle((*(*seedcoll).begin()),*itr);
176 
177  for(std::vector<std::pair<const TrackingRecHit *,float> >::const_iterator hitangle_iter=hitangle.begin();hitangle_iter!=hitangle.end();hitangle_iter++){
178  const TrackingRecHit * trechit = hitangle_iter->first;
179  float local_angle=hitangle_iter->second;
180  LocalPoint local_position= trechit->localPosition();
181  const SiStripRecHit2D* sistripsimplehit=dynamic_cast<const SiStripRecHit2D*>(trechit);
182  const SiStripMatchedRecHit2D* sistripmatchedhit=dynamic_cast<const SiStripMatchedRecHit2D*>(trechit);
183 // std::cout<<" hit/matched "<<std::ios::hex<<sistripsimplehit<<" "<<sistripmatchedhit<<std::endl;
184  ((TH1F*) HlistOtherHistos->FindObject("LocalAngle"))->Fill(local_angle);
185  ((TH1F*) HlistOtherHistos->FindObject("LocalAngleAbsoluteCosine"))->Fill(fabs(cos(local_angle)));
186  if(sistripsimplehit){
187  ((TH1F*) HlistOtherHistos->FindObject("SiStripRecHitType"))->Fill(1.);
188  const SiStripRecHit2D::ClusterRef & cluster=sistripsimplehit->cluster();
189  const auto & ampls = cluster->amplitudes();
190  uint32_t thedetid = 0; // is zero since long time cluster->geographicalId();
191  double module_width = moduleWidth(thedetid);
192  ((TH1F*) HlistOtherHistos->FindObject("LocalPosition_cm"))->Fill(local_position.x());
193  ((TH1F*) HlistOtherHistos->FindObject("LocalPosition_normalized"))->Fill(local_position.x()/module_width);
194  double module_thickness = moduleThickness(thedetid);
195  int ifirststrip= cluster->firstStrip();
196  int theapvpairid = int(float(ifirststrip)/256.);
197  TH1F* histopointer = (TH1F*) HlistAPVPairs->FindObject(Form("ChargeAPVPair_%i_%i",thedetid,theapvpairid));
198  if( histopointer ){
199  short cCharge = 0;
200  for(unsigned int iampl = 0; iampl<ampls.size(); iampl++){
201  cCharge += ampls[iampl];
202  }
203  double cluster_charge_over_path = ((double)cCharge) * fabs(cos(local_angle)) / ( 10. * module_thickness);
204  histopointer->Fill(cluster_charge_over_path);
205  }
206  }else{
207  if(sistripmatchedhit) ((TH1F*) HlistOtherHistos->FindObject("SiStripRecHitType"))->Fill(2.);
208  }
209  }
210  }
211 }
212 
213 
214 //---------------------------------------------------------------------------------------------------------
215 std::pair<double,double> SiStripGainCosmicCalculator::getPeakOfLandau( TH1F * inputHisto){ // automated fitting with finding of the appropriate nr. of ADCs
216  // set some default dummy value and return if no entries
217  double adcs = -0.5; double error = 0.; double nr_of_entries = inputHisto->GetEntries();
218  if(nr_of_entries < MinNrEntries){
219  return std::make_pair(adcs,error);
220  }
221 //
222 // // fit with initial setting of parameter values
223 // double rms_of_histogram = inputHisto->GetRMS();
224 // TF1 *landaufit = new TF1("landaufit","landau",0.,450.);
225 // landaufit->SetParameters(nr_of_entries,mean_of_histogram,rms_of_histogram);
226 // inputHisto->Fit("landaufit","0Q+");
227 // delete landaufit;
228 //
229  // perform fit with standard landau
230  // make our own copy to avoid problems with threads
231  std::unique_ptr<TF1> fitfunction( new TF1("landaufit","landau") );
232  inputHisto->Fit(fitfunction.get(),"0Q");
233  adcs = fitfunction->GetParameter("MPV");
234  error = fitfunction->GetParError(1); // MPV is parameter 1 (0=constant, 1=MPV, 2=Sigma)
235  double chi2 = fitfunction->GetChisquare();
236  double ndf = fitfunction->GetNDF();
237  double chi2overndf = chi2 / ndf;
238  // in case things went wrong, try to refit in smaller range
239  if(adcs< 2. || (error/adcs)>1.8 ){
240  inputHisto->Fit(fitfunction.get(),"0Q",nullptr,0.,400.);
241  std::cout<<"refitting landau for histogram "<<inputHisto->GetTitle()<<std::endl;
242  std::cout<<"initial error/adcs ="<<error<<" / "<<adcs<<std::endl;
243  std::cout<<"new error/adcs ="<<fitfunction->GetParError(1)<<" / "<<fitfunction->GetParameter("MPV")<<std::endl;
244  adcs = fitfunction->GetParameter("MPV");
245  error = fitfunction->GetParError(1); // MPV is parameter 1 (0=constant, 1=MPV, 2=Sigma)
246  chi2 = fitfunction->GetChisquare();
247  ndf = fitfunction->GetNDF();
248  chi2overndf = chi2 / ndf;
249  }
250  // if still wrong, give up
251  if(adcs<2. || chi2overndf>MaxChi2OverNDF){
252  adcs = -0.5; error = 0.;
253  }
254  return std::make_pair(adcs,error);
255 }
256 
257 //---------------------------------------------------------------------------------------------------------
258 double SiStripGainCosmicCalculator::moduleWidth(const uint32_t detid) // get width of the module detid
259 { //dk: copied from A. Giammanco and hacked, module_width values : 10.49 12.03 6.144 7.14 9.3696
260  double module_width=0.;
261  const GeomDetUnit* it = tkGeom->idToDetUnit(DetId(detid));
262  if (dynamic_cast<const StripGeomDetUnit*>(it)==nullptr && dynamic_cast<const PixelGeomDetUnit*>(it)==nullptr) {
263  std::cout << "this detID doesn't seem to belong to the Tracker" << std::endl;
264  }else{
265  module_width = it->surface().bounds().width();
266  }
267  return module_width;
268 }
269 
270 //---------------------------------------------------------------------------------------------------------
271 double SiStripGainCosmicCalculator::moduleThickness(const uint32_t detid) // get thickness of the module detid
272 { //dk: copied from A. Giammanco and hacked
273  double module_thickness=0.;
274  const GeomDetUnit* it = tkGeom->idToDetUnit(DetId(detid));
275  if (dynamic_cast<const StripGeomDetUnit*>(it)==nullptr && dynamic_cast<const PixelGeomDetUnit*>(it)==nullptr) {
276  std::cout << "this detID doesn't seem to belong to the Tracker" << std::endl;
277  }else{
278  module_thickness = it->surface().bounds().thickness();
279  }
280  return module_thickness;
281 }
282 
283 //---------------------------------------------------------------------------------------------------------
284 std::unique_ptr<SiStripApvGain> SiStripGainCosmicCalculator::getNewObject() {
285  std::cout<<"SiStripGainCosmicCalculator::getNewObject called"<<std::endl;
286 
287  std::cout<<"total_nr_of_events="<<total_nr_of_events<<std::endl;
288  // book some more histograms
289  TH1F *ChargeOfEachAPVPair = new TH1F("ChargeOfEachAPVPair","ChargeOfEachAPVPair",1,0,1); ChargeOfEachAPVPair->SetCanExtend(TH1::kAllAxes);
290  TH1F *EntriesApvPairs = new TH1F("EntriesApvPairs","EntriesApvPairs",1,0,1); EntriesApvPairs->SetCanExtend(TH1::kAllAxes);
291  TH1F * NrOfEntries = new TH1F("NrOfEntries","NrOfEntries",351,-0.5,350.5);// NrOfEntries->SetCanExtend(TH1::kAllAxes);
292  TH1F * ModuleThickness = new TH1F("ModuleThickness","ModuleThickness",2,0.5,2.5); HlistOtherHistos->Add(ModuleThickness);
293  ModuleThickness->GetXaxis()->SetBinLabel(1,"320mu"); ModuleThickness->GetXaxis()->SetBinLabel(2,"500mu"); ModuleThickness->SetYTitle("Nr APVPairs");
294  TH1F * ModuleWidth = new TH1F("ModuleWidth","ModuleWidth",5,0.5,5.5); HlistOtherHistos->Add(ModuleWidth);
295  ModuleWidth->GetXaxis()->SetBinLabel(1,"6.144cm"); ModuleWidth->GetXaxis()->SetBinLabel(2,"7.14cm");
296  ModuleWidth->GetXaxis()->SetBinLabel(3,"9.3696cm"); ModuleWidth->GetXaxis()->SetBinLabel(4,"10.49cm");
297  ModuleWidth->GetXaxis()->SetBinLabel(5,"12.03cm");
298  ModuleWidth->SetYTitle("Nr APVPairs");
299  // loop over single histograms and extract peak value of charge
300  HlistAPVPairs->Sort(); // sort alfabetically
301  TIter hiterator(HlistAPVPairs);
302  double MeanCharge = 0.;
303  double NrOfApvPairs = 0.;
304  TH1F *MyHisto = (TH1F*)hiterator();
305  while( MyHisto ){
306  TString histo_title = MyHisto->GetTitle();
307  if(histo_title.Contains("ChargeAPVPair_")){
308  std::pair<double,double> two_values = getPeakOfLandau(MyHisto);
309  double local_nrofadcs = two_values.first;
310  double local_sigma = two_values.second;
311  ChargeOfEachAPVPair->Fill(histo_title, local_nrofadcs);
312  int ichbin = ChargeOfEachAPVPair->GetXaxis()->FindBin(histo_title.Data());
313  ChargeOfEachAPVPair->SetBinError(ichbin,local_sigma);
314  EntriesApvPairs->Fill(histo_title, MyHisto->GetEntries());
315  NrOfEntries->Fill(MyHisto->GetEntries());
316  if(local_nrofadcs > 0){ // if nr of adcs is negative, the fitting routine could not extract meaningfull numbers
317  MeanCharge += local_nrofadcs;
318  NrOfApvPairs += 1.; // count nr of apv pairs since do not know whether nr of bins of histogram is the same
319  }
320  }
321  MyHisto = (TH1F*)hiterator();
322  }
323  ChargeOfEachAPVPair->LabelsDeflate("X"); EntriesApvPairs->LabelsDeflate("X"); // trim nr. of bins to match active labels
324  HlistOtherHistos->Add(ChargeOfEachAPVPair);
325  HlistOtherHistos->Add(EntriesApvPairs);
326  HlistOtherHistos->Add(NrOfEntries);
327  MeanCharge = MeanCharge / NrOfApvPairs;
328  // calculate correction
329  TH1F* CorrectionOfEachAPVPair = (TH1F*) ChargeOfEachAPVPair->Clone("CorrectionOfEachAPVPair");
330  TH1F *ChargeOfEachAPVPairControlView = new TH1F("ChargeOfEachAPVPairControlView","ChargeOfEachAPVPairControlView",1,0,1); ChargeOfEachAPVPairControlView->SetCanExtend(TH1::kAllAxes);
331 TH1F *CorrectionOfEachAPVPairControlView = new TH1F("CorrectionOfEachAPVPairControlView","CorrectionOfEachAPVPairControlView",1,0,1); CorrectionOfEachAPVPairControlView->SetCanExtend(TH1::kAllAxes);
332  std::ofstream APVPairTextOutput("apvpair_corrections.txt");
333  APVPairTextOutput<<"# MeanCharge = "<<MeanCharge<<std::endl;
334  APVPairTextOutput<<"# Nr. of APVPairs = "<<NrOfApvPairs<<std::endl;
335  for(int ibin=1; ibin <= ChargeOfEachAPVPair->GetNbinsX(); ibin++){
336  TString local_bin_label = ChargeOfEachAPVPair->GetXaxis()->GetBinLabel(ibin);
337  double local_charge_over_path = ChargeOfEachAPVPair->GetBinContent(ibin);
338  if(local_bin_label.Contains("ChargeAPVPair_") && local_charge_over_path > 0.0000001){ // calculate correction only for meaningful numbers
339  uint32_t extracted_detid; std::istringstream read_label((local_bin_label(14,9)).Data()); read_label >> extracted_detid;
340  unsigned short extracted_apvpairid; std::istringstream read_apvpair((local_bin_label(24,1)).Data()); read_apvpair >> extracted_apvpairid;
341  double local_error_of_charge = ChargeOfEachAPVPair->GetBinError(ibin);
342  double local_correction = -0.5;
343  double local_error_correction = 0.;
344  local_correction = MeanCharge / local_charge_over_path; // later use ExpectedChargeDeposition instead of MeanCharge
345  local_error_correction = local_correction * local_error_of_charge / local_charge_over_path;
346  if(local_error_correction>1.8){ // understand why error too large sometimes
347  std::cout<<"too large error "<<local_error_correction<<" for histogram "<<local_bin_label<<std::endl;
348  }
349  double nr_of_entries = EntriesApvPairs->GetBinContent(ibin);
350  APVPairTextOutput<<local_bin_label<<" "<<local_correction<<" "<<local_charge_over_path<<" "<<nr_of_entries<<std::endl;
351  CorrectionOfEachAPVPair->SetBinContent(ibin, local_correction);
352  CorrectionOfEachAPVPair->SetBinError(ibin, local_error_correction);
353  ((TH1F*) HlistOtherHistos->FindObject("APVPairCorrections"))->Fill(local_correction);
354  DetId thedetId = DetId(extracted_detid);
355  unsigned int generalized_layer = 0;
356  // calculate generalized_layer: 31,32 = TIB1, 33 = TIB2, 33 = TIB3, 51 = TOB1, 52 = TOB2, 60 = TEC
357  if(thedetId.subdetId()==StripSubdetector::TIB){
358 
359  generalized_layer = 10*thedetId.subdetId() + tTopo->tibLayer(thedetId.rawId()) + tTopo->tibStereo(thedetId.rawId());
360  if(tTopo->tibLayer(thedetId.rawId())==2){
361  generalized_layer++;
362  if (tTopo->tibGlued(thedetId.rawId())) edm::LogError("ClusterMTCCFilter")<<"WRONGGGG"<<std::endl;
363  }
364  }else{
365  generalized_layer = 10*thedetId.subdetId();
366  if(thedetId.subdetId()==StripSubdetector::TOB){
367 
368  generalized_layer += tTopo->tobLayer(thedetId.rawId());
369  }
370  }
371  if(generalized_layer==31){
372  ((TH1F*) HlistOtherHistos->FindObject("APVPairCorrectionsTIB1mono"))->Fill(local_correction);
373  }
374  if(generalized_layer==32){
375  ((TH1F*) HlistOtherHistos->FindObject("APVPairCorrectionsTIB1stereo"))->Fill(local_correction);
376  }
377  if(generalized_layer==33){
378  ((TH1F*) HlistOtherHistos->FindObject("APVPairCorrectionsTIB2"))->Fill(local_correction);
379  }
380  if(generalized_layer==51){
381  ((TH1F*) HlistOtherHistos->FindObject("APVPairCorrectionsTOB1"))->Fill(local_correction);
382  }
383  if(generalized_layer==52){
384  ((TH1F*) HlistOtherHistos->FindObject("APVPairCorrectionsTOB2"))->Fill(local_correction);
385  }
386  // control view
387  const FedChannelConnection& fedchannelconnection = siStripDetCabling->getConnection( extracted_detid, extracted_apvpairid );
388  std::ostringstream local_key;
389  // in S. Mersi's analysis the APVPair id seems to be used instead of the lldChannel, hence use the same here
390  local_key<<"fecCrate"<<fedchannelconnection.fecCrate()<<"_fecSlot"<<fedchannelconnection.fecSlot()<<"_fecRing"<<fedchannelconnection.fecRing()<<"_ccuAddr"<<fedchannelconnection.ccuAddr()<<"_ccuChan"<<fedchannelconnection.ccuChan()<<"_apvPair"<<extracted_apvpairid;
391  TString control_key = local_key.str();
392  ChargeOfEachAPVPairControlView->Fill(control_key,local_charge_over_path);
393  int ibin1 = ChargeOfEachAPVPairControlView->GetXaxis()->FindBin(control_key);
394  ChargeOfEachAPVPairControlView->SetBinError(ibin1,local_error_of_charge);
395  CorrectionOfEachAPVPairControlView->Fill(control_key, local_correction);
396  int ibin2 = CorrectionOfEachAPVPairControlView->GetXaxis()->FindBin(control_key);
397  CorrectionOfEachAPVPairControlView->SetBinError(ibin2, local_error_correction);
398  // thickness of each module
399  double module_thickness = moduleThickness(extracted_detid);
400  if( fabs(module_thickness - 0.032)<0.001 ) ModuleThickness->Fill(1);
401  if( fabs(module_thickness - 0.05)<0.001 ) ModuleThickness->Fill(2);
402  // width of each module
403  double module_width = moduleWidth(extracted_detid);
404  if(fabs(module_width-6.144)<0.01) ModuleWidth->Fill(1);
405  if(fabs(module_width-7.14)<0.01) ModuleWidth->Fill(2);
406  if(fabs(module_width-9.3696)<0.01) ModuleWidth->Fill(3);
407  if(fabs(module_width-10.49)<0.01) ModuleWidth->Fill(4);
408  if(fabs(module_width-12.03)<0.01) ModuleWidth->Fill(5);
409  }
410  }
411  HlistOtherHistos->Add(CorrectionOfEachAPVPair);
412  ChargeOfEachAPVPairControlView->LabelsDeflate("X");
413  CorrectionOfEachAPVPairControlView->LabelsDeflate("X");
414  HlistOtherHistos->Add(ChargeOfEachAPVPairControlView);
415  HlistOtherHistos->Add(CorrectionOfEachAPVPairControlView);
416  // output histograms to file
417 
418 
420  TFile *outputfile = new TFile(outputFileName,"RECREATE");
421  HlistAPVPairs->Write();
422  HlistOtherHistos->Write();
423  outputfile->Close();
424  }
425 
426  auto obj = std::make_unique<SiStripApvGain>();
427 
428 // for(std::map<uint32_t,OptoScanAnalysis*>::const_iterator it = analyses.begin(); it != analyses.end(); it++){
429 // //Generate Gain for det detid
430 // std::vector<float> theSiStripVector;
431 // for(unsigned short j=0; j<it->second; j++){
432 // float gain;
433 
434 // // if(sigmaGain_/meanGain_ < 0.00001) gain = meanGain_;
435 // // else{
436 // gain = CLHEP::RandGauss::shoot(meanGain_, sigmaGain_);
437 // if(gain<=minimumPosValue_) gain=minimumPosValue_;
438 // // }
439 
440 // if (printdebug_)
441 // edm::LogInfo("SiStripGainCalculator") << "detid " << it->first << " \t"
442 // << " apv " << j << " \t"
443 // << gain << " \t"
444 // << std::endl;
445 // theSiStripVector.push_back(gain);
446 // }
447 // SiStripApvGain::Range range(theSiStripVector.begin(),theSiStripVector.end());
448 // if ( ! obj->put(it->first,range) )
449 // edm::LogError("SiStripGainCalculator")<<"[SiStripGainCalculator::beginJob] detid already exists"<<std::endl;
450 // }
451 
452  return obj;
453 }
454 
const uint16_t & fecSlot() const
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::vector< uint32_t > SelectedDetIds
const uint16_t & fecCrate() const
const FedChannelConnection & getConnection(uint32_t det_id, unsigned short apv_pair) const
void getTIBDetectors(const std::vector< uint32_t > &inputDetRawIds, std::vector< uint32_t > &tibDetRawIds, const TrackerTopology *trackerTopology, uint32_t layer=0, uint32_t bkw_frw=0, uint32_t int_ext=0, uint32_t string=0)
void addActiveDetectorsRawIds(std::vector< uint32_t > &) const
unsigned int tibLayer(const DetId &id) const
double moduleThickness(const uint32_t detid)
void algoBeginJob(const edm::EventSetup &) override
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:15
const Bounds & bounds() const
Definition: Surface.h:120
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
std::pair< double, double > getPeakOfLandau(TH1F *inputHisto)
virtual float width() const =0
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
int iEvent
Definition: GenABIO.cc:224
const uint16_t & fecRing() const
Class containning control, module, detector and connection information, at the level of a FED channel...
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
const uint16_t & ccuChan() const
SiStripGainCosmicCalculator(const edm::ParameterSet &)
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
std::map< uint32_t, double > thickness_map
ClusterRef cluster() const
SiStripDetCabling const * siStripDetCabling
virtual LocalPoint localPosition() const =0
const uint16_t & ccuAddr() const
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:480
std::unique_ptr< SiStripApvGain > getNewObject() override
Definition: DetId.h:18
uint32_t tibGlued(const DetId &id) const
T const * product() const
Definition: Handle.h:74
virtual float thickness() const =0
virtual int nstrips() const =0
std::vector< uint32_t > detModulesToBeExcluded
HLT enums.
T get() const
Definition: EventSetup.h:71
void getTOBDetectors(const std::vector< uint32_t > &inputDetRawIds, std::vector< uint32_t > &tobDetRawIds, const TrackerTopology *trackerTopology, uint32_t layer=0, uint32_t bkw_frw=0, uint32_t rod=0)
uint32_t tibStereo(const DetId &id) const
double moduleWidth(const uint32_t detid)
T x() const
Definition: PV3DBase.h:62
T const * product() const
Definition: ESHandle.h:86
void algoAnalyze(const edm::Event &, const edm::EventSetup &) override
unsigned int tobLayer(const DetId &id) const