CMS 3D CMS Logo

SiStripGainFromData.cc
Go to the documentation of this file.
1 // Original Author: Loic QUERTENMONT
2 // Created: Wed Feb 6 08:55:18 CET 2008
3 
4 #include <memory>
5 
12 
18 
25 
27 
30 
43 
46 
49 
51 
54 
55 #include "TFile.h"
56 #include "TObjString.h"
57 #include "TString.h"
58 #include "TH1F.h"
59 #include "TH2F.h"
60 #include "TProfile.h"
61 #include "TF1.h"
62 #include "TROOT.h"
63 
64 #include <unordered_map>
65 #include <memory>
66 
67 using namespace edm;
68 using namespace reco;
69 using namespace std;
70 
71 struct stAPVGain {
72  unsigned int Index;
73  int DetId;
74  int APVId;
75  int SubDet;
76  float Eta;
77  float R;
78  float Phi;
79  float Thickness;
80  double MPV;
81  double Gain;
82  double PreviousGain;
83  char Side;
84 };
85 
86 class SiStripGainFromData : public ConditionDBWriter<SiStripApvGain> {
87 public:
90  explicit SiStripGainFromData(const edm::ParameterSet&);
91  ~SiStripGainFromData() override;
92 
93 private:
94  void algoBeginJob(const edm::EventSetup&) override;
95  void algoEndJob() override;
96  void algoBeginRun(const edm::Run&, const edm::EventSetup&) override;
97  // virtual void algoBeginRun(const edm::Event& iEvent, const edm::EventSetup& iSetup);
98  void algoAnalyze(const edm::Event&, const edm::EventSetup&) override;
99 
100  std::unique_ptr<SiStripApvGain> getNewObject() override;
102 
103  double ComputeChargeOverPath(const SiStripCluster* Cluster,
104  TrajectoryStateOnSurface trajState,
105  const edm::EventSetup* iSetup,
106  const Track* track,
107  double trajChi2OverN);
108  bool IsFarFromBorder(TrajectoryStateOnSurface trajState, const uint32_t detid, const edm::EventSetup* iSetup);
109 
110  void getPeakOfLandau(TH1* InputHisto, double* FitResults, double LowRange = 0, double HighRange = 5400);
111 
114 
116  unsigned int MinNrEntries;
117  double MaxMPVError;
121  double MinTrackEta;
122  double MaxTrackEta;
123  unsigned int MaxNrStrips;
124  unsigned int MinTrackHits;
131 
137 
138  vector<string> VInputFiles;
139 
141 
144 
148  TH1F* HTrackHits;
149 
156 
163 
170 
177 
178  TH1F* Charge_TIB;
179  TH1F* Charge_TID;
180  TH1F* Charge_TIDP;
181  TH1F* Charge_TIDM;
182  TH1F* Charge_TOB;
183  TH1F* Charge_TEC;
184  TH1F* Charge_TEC1;
185  TH1F* Charge_TEC2;
186  TH1F* Charge_TECP;
187  TH1F* Charge_TECM;
188 
189  TH2F* MPV_Vs_Phi;
190  TH2F* MPV_Vs_Eta;
191  TH2F* MPV_Vs_R;
192 
193  // TH2F* PD_Vs_Eta;
194  // TH2F* PD_Vs_R;
195 
196  TH1F* APV_DetId;
197  TH1F* APV_Id;
198  TH1F* APV_Eta;
199  TH1F* APV_R;
200  TH1F* APV_SubDet;
202  TH2F* APV_Charge;
205  TH1F* APV_MPV;
206  TH1F* APV_Gain;
210 
211  TH1F* MPVs;
212  TH1F* MPVs320;
213  TH1F* MPVs500;
214 
215  // TH2F* MPV_vs_10RplusEta;
216 
219  // TH2F* Charge_Vs_PathLength_CS1;
220  // TH2F* Charge_Vs_PathLength_CS2;
221  // TH2F* Charge_Vs_PathLength_CS3;
222  // TH2F* Charge_Vs_PathLength_CS4;
223  // TH2F* Charge_Vs_PathLength_CS5;
224 
225  // TH1F* MPV_Vs_PathLength_CS1;
226  // TH1F* MPV_Vs_PathLength_CS2;
227  // TH1F* MPV_Vs_PathLength_CS3;
228  // TH1F* MPV_Vs_PathLength_CS4;
229  // TH1F* MPV_Vs_PathLength_CS5;
230 
231  // TH1F* FWHM_Vs_PathLength_CS1;
232  // TH1F* FWHM_Vs_PathLength_CS2;
233  // TH1F* FWHM_Vs_PathLength_CS3;
234  // TH1F* FWHM_Vs_PathLength_CS4;
235  // TH1F* FWHM_Vs_PathLength_CS5;
236 
240 
244 
248 
252 
256 
258  TH1F* MPV_Vs_Beta;
260 
265 
267 
270 
271  TH1F* JobInfo;
272 
273  TH1F* HFirstStrip;
274 
275  unsigned int NEvent;
276  unsigned int SRun;
277  unsigned int SEvent;
279  unsigned int ERun;
280  unsigned int EEvent;
282 
283 private:
284  class isEqual {
285  public:
286  template <class T>
287  bool operator()(const T& PseudoDetId1, const T& PseudoDetId2) {
288  return PseudoDetId1 == PseudoDetId2;
289  }
290  };
291 
292  std::vector<stAPVGain*> APVsCollOrdered;
293  std::unordered_map<unsigned int, stAPVGain*> APVsColl;
294 
298 };
299 
301  : ConditionDBWriter<SiStripApvGain>(iConfig) {
302  AlgoMode = iConfig.getParameter<std::string>("AlgoMode");
303 
304  OutputGains = iConfig.getParameter<std::string>("OutputGains");
305  OutputHistos = iConfig.getParameter<std::string>("OutputHistos");
306 
307  TrajToTrackProducer = iConfig.getParameter<std::string>("TrajToTrackProducer");
308  TrajToTrackLabel = iConfig.getParameter<std::string>("TrajToTrackLabel");
309 
310  CheckLocalAngle = iConfig.getUntrackedParameter<bool>("checkLocalAngle", false);
311  MinNrEntries = iConfig.getUntrackedParameter<unsigned>("minNrEntries", 20);
312  MaxMPVError = iConfig.getUntrackedParameter<double>("maxMPVError", 500.0);
313  MaxChi2OverNDF = iConfig.getUntrackedParameter<double>("maxChi2OverNDF", 5.0);
314  MinTrackMomentum = iConfig.getUntrackedParameter<double>("minTrackMomentum", 3.0);
315  MaxTrackMomentum = iConfig.getUntrackedParameter<double>("maxTrackMomentum", 99999.0);
316  MinTrackEta = iConfig.getUntrackedParameter<double>("minTrackEta", -5.0);
317  MaxTrackEta = iConfig.getUntrackedParameter<double>("maxTrackEta", 5.0);
318  MaxNrStrips = iConfig.getUntrackedParameter<unsigned>("maxNrStrips", 2);
319  MinTrackHits = iConfig.getUntrackedParameter<unsigned>("MinTrackHits", 8);
320  MaxTrackChiOverNdf = iConfig.getUntrackedParameter<double>("MaxTrackChiOverNdf", 3);
321  AllowSaturation = iConfig.getUntrackedParameter<bool>("AllowSaturation", false);
322  FirstSetOfConstants = iConfig.getUntrackedParameter<bool>("FirstSetOfConstants", true);
323  Validation = iConfig.getUntrackedParameter<bool>("Validation", false);
324  CheckIfFileExist = iConfig.getUntrackedParameter<bool>("CheckIfFileExist", false);
325 
326  CalibrationLevel = iConfig.getUntrackedParameter<int>("CalibrationLevel", 0);
327 
328  if (strcmp(AlgoMode.c_str(), "WriteOnDB") == 0)
329  VInputFiles = iConfig.getParameter<vector<string> >("VInputFiles");
330 
332 
333  tTopoToken_ = esConsumes<edm::Transition::BeginRun>();
334  tkGeomToken_ = esConsumes<edm::Transition::BeginRun>();
335  gainToken_ = esConsumes<edm::Transition::BeginRun>();
336 
337  //if( OutputHistos!="" )
338  // dqmStore_->open(OutputHistos.c_str(), true);
339 }
340 
342 
344  const TrackerTopology* const tTopo = &iSetup.getData(tTopoToken_);
345 
346  iSetup_ = &iSetup;
347 
348  // TH1::AddDirectory(kTRUE);
349 
350  tmp = dqmStore_->book1D("JobInfo", "JobInfo", 20, 0, 20);
351  JobInfo = tmp->getTH1F();
352 
353  tmp = dqmStore_->book1D("APV_DetId", "APV_DetId", 72785, 0, 72784);
354  APV_DetId = tmp->getTH1F();
355  tmp = dqmStore_->book1D("APV_Id", "APV_Id", 72785, 0, 72784);
356  APV_Id = tmp->getTH1F();
357  tmp = dqmStore_->book1D("APV_Eta", "APV_Eta", 72785, 0, 72784);
358  APV_Eta = tmp->getTH1F();
359  tmp = dqmStore_->book1D("APV_R", "APV_R", 72785, 0, 72784);
360  APV_R = tmp->getTH1F();
361  tmp = dqmStore_->book1D("APV_SubDet", "APV_SubDet", 72785, 0, 72784);
362  APV_SubDet = tmp->getTH1F();
363  tmp = dqmStore_->book2D("APV_Momentum", "APV_Momentum", 72785, 0, 72784, 50, 0, 200);
364  APV_Momentum = tmp->getTH2F();
365  tmp = dqmStore_->book2D("APV_Charge", "APV_Charge", 72785, 0, 72784, 1000, 0, 2000);
366  APV_Charge = tmp->getTH2F();
367  tmp = dqmStore_->book2D("APV_PathLength", "APV_PathLength", 72785, 0, 72784, 100, 0.2, 1.4);
369  tmp = dqmStore_->book1D("APV_PathLengthM", "APV_PathLengthM", 72785, 0, 72784);
371  tmp = dqmStore_->book1D("APV_MPV", "APV_MPV", 72785, 0, 72784);
372  APV_MPV = tmp->getTH1F();
373  tmp = dqmStore_->book1D("APV_Gain", "APV_Gain", 72785, 0, 72784);
374  APV_Gain = tmp->getTH1F();
375  tmp = dqmStore_->book1D("APV_PrevGain", "APV_PrevGain", 72785, 0, 72784);
376  APV_PrevGain = tmp->getTH1F();
377  tmp = dqmStore_->book1D("APV_CumulGain", "APV_CumulGain", 72785, 0, 72784);
379  tmp = dqmStore_->book1D("APV_Thickness", "APV_Thicknes", 72785, 0, 72784);
381 
382  tmp = dqmStore_->book2D("Tracks_P_Vs_Eta", "Tracks_P_Vs_Eta", 30, 0, 3, 50, 0, 200);
384  tmp = dqmStore_->book2D("Tracks_Pt_Vs_Eta", "Tracks_Pt_Vs_Eta", 30, 0, 3, 50, 0, 200);
386 
387  tmp = dqmStore_->book2D("Charge_Vs_PathTIB", "Charge_Vs_PathTIB", 100, 0.2, 1.4, 500, 0, 2000);
389  tmp = dqmStore_->book2D("Charge_Vs_PathTID", "Charge_Vs_PathTID", 100, 0.2, 1.4, 500, 0, 2000);
391  tmp = dqmStore_->book2D("Charge_Vs_PathTOB", "Charge_Vs_PathTOB", 100, 0.2, 1.4, 500, 0, 2000);
393  tmp = dqmStore_->book2D("Charge_Vs_PathTEC", "Charge_Vs_PathTEC", 100, 0.2, 1.4, 500, 0, 2000);
395  tmp = dqmStore_->book2D("Charge_Vs_PathTEC1", "Charge_Vs_PathTEC1", 100, 0.2, 1.4, 500, 0, 2000);
397  tmp = dqmStore_->book2D("Charge_Vs_PathTEC2", "Charge_Vs_PathTEC2", 100, 0.2, 1.4, 500, 0, 2000);
399 
400  tmp = dqmStore_->book1D("Charge_TIB", "Charge_TIB", 1000, 0, 2000);
401  Charge_TIB = tmp->getTH1F();
402  tmp = dqmStore_->book1D("Charge_TID", "Charge_TID", 1000, 0, 2000);
403  Charge_TID = tmp->getTH1F();
404  tmp = dqmStore_->book1D("Charge_TID+", "Charge_TID+", 1000, 0, 2000);
405  Charge_TIDP = tmp->getTH1F();
406  tmp = dqmStore_->book1D("Charge_TID-", "Charge_TID-", 1000, 0, 2000);
407  Charge_TIDM = tmp->getTH1F();
408  tmp = dqmStore_->book1D("Charge_TOB", "Charge_TOB", 1000, 0, 2000);
409  Charge_TOB = tmp->getTH1F();
410  tmp = dqmStore_->book1D("Charge_TEC", "Charge_TEC", 1000, 0, 2000);
411  Charge_TEC = tmp->getTH1F();
412  tmp = dqmStore_->book1D("Charge_TEC1", "Charge_TEC1", 1000, 0, 2000);
413  Charge_TEC1 = tmp->getTH1F();
414  tmp = dqmStore_->book1D("Charge_TEC2", "Charge_TEC2", 1000, 0, 2000);
415  Charge_TEC2 = tmp->getTH1F();
416  tmp = dqmStore_->book1D("Charge_TEC+", "Charge_TEC+", 1000, 0, 2000);
417  Charge_TECP = tmp->getTH1F();
418  tmp = dqmStore_->book1D("Charge_TEC-", "Charge_TEC-", 1000, 0, 2000);
419  Charge_TECM = tmp->getTH1F();
420 
421  /*
422  tmp = dqmStore_->book2D ("Charge_Vs_PathLength_CS1", "Charge_Vs_PathLength_CS1" , 250,0.2,1.4, 500,0,2000); Charge_Vs_PathLength_CS1 = tmp->getTH2F();
423  tmp = dqmStore_->book2D ("Charge_Vs_PathLength_CS2", "Charge_Vs_PathLength_CS2" , 250,0.2,1.4, 500,0,2000); Charge_Vs_PathLength_CS2 = tmp->getTH2F();
424  tmp = dqmStore_->book2D ("Charge_Vs_PathLength_CS3", "Charge_Vs_PathLength_CS3" , 250,0.2,1.4, 500,0,2000); Charge_Vs_PathLength_CS3 = tmp->getTH2F();
425  tmp = dqmStore_->book2D ("Charge_Vs_PathLength_CS4", "Charge_Vs_PathLength_CS4" , 250,0.2,1.4, 500,0,2000); Charge_Vs_PathLength_CS4 = tmp->getTH2F();
426  tmp = dqmStore_->book2D ("Charge_Vs_PathLength_CS5", "Charge_Vs_PathLength_CS5" , 250,0.2,1.4, 500,0,2000); Charge_Vs_PathLength_CS5 = tmp->getTH2F();
427 */
428  tmp = dqmStore_->book2D("Charge_Vs_PathLength", "Charge_Vs_PathLength", 100, 0.2, 1.4, 500, 0, 2000);
430  tmp = dqmStore_->book2D("Charge_Vs_PathLength320", "Charge_Vs_PathLength", 100, 0.2, 1.4, 500, 0, 2000);
432  tmp = dqmStore_->book2D("Charge_Vs_PathLength500", "Charge_Vs_PathLength", 100, 0.2, 1.4, 500, 0, 2000);
434 
435  tmp = dqmStore_->book2D("Charge_Vs_TransversAngle", "Charge_Vs_TransversAngle", 220, -20, 200, 500, 0, 2000);
437  tmp = dqmStore_->book2D("Charge_Vs_Alpha", "Charge_Vs_Alpha", 220, -20, 200, 500, 0, 2000);
439  tmp = dqmStore_->book2D("Charge_Vs_Beta", "Charge_Vs_Beta", 220, -20, 200, 500, 0, 2000);
441 
442  tmp = dqmStore_->book2D("NStrips_Vs_TransversAngle", "NStrips_Vs_TransversAngle", 220, -20, 200, 10, 0, 10);
444  tmp = dqmStore_->book2D("NStrips_Vs_Alpha", "NStrips_Vs_Alpha", 220, -20, 200, 10, 0, 10);
446  tmp = dqmStore_->book2D("NStrips_Vs_Beta", "NStrips_Vs_Beta", 220, -20, 200, 10, 0, 10);
448  tmp = dqmStore_->book1D("NHighStripInCluster", "NHighStripInCluster", 15, 0, 14);
450  tmp = dqmStore_->book1D("NSatStripInCluster", "NSatStripInCluster", 50, 0, 50);
452 
453  tmp = dqmStore_->book1D("TrackChi2OverNDF", "TrackChi2OverNDF", 500, 0, 10);
455  tmp = dqmStore_->book1D("TrackHits", "TrackHits", 40, 0, 40);
456  HTrackHits = tmp->getTH1F();
457 
458  tmp = dqmStore_->book1D("FirstStrip", "FirstStrip", 800, 0, 800);
459  HFirstStrip = tmp->getTH1F();
460 
461  if (strcmp(AlgoMode.c_str(), "MultiJob") != 0) {
462  tmp = dqmStore_->book2D("MPV_Vs_EtaTIB", "MPV_Vs_EtaTIB", 50, -3.0, 3.0, 300, 0, 600);
464  tmp = dqmStore_->book2D("MPV_Vs_EtaTID", "MPV_Vs_EtaTID", 50, -3.0, 3.0, 300, 0, 600);
466  tmp = dqmStore_->book2D("MPV_Vs_EtaTOB", "MPV_Vs_EtaTOB", 50, -3.0, 3.0, 300, 0, 600);
468  tmp = dqmStore_->book2D("MPV_Vs_EtaTEC", "MPV_Vs_EtaTEC", 50, -3.0, 3.0, 300, 0, 600);
470  tmp = dqmStore_->book2D("MPV_Vs_EtaTEC1", "MPV_Vs_EtaTEC1", 50, -3.0, 3.0, 300, 0, 600);
472  tmp = dqmStore_->book2D("MPV_Vs_EtaTEC2", "MPV_Vs_EtaTEC2", 50, -3.0, 3.0, 300, 0, 600);
474 
475  tmp = dqmStore_->book2D("MPV_Vs_PhiTIB", "MPV_Vs_PhiTIB", 50, -3.2, 3.2, 300, 0, 600);
477  tmp = dqmStore_->book2D("MPV_Vs_PhiTID", "MPV_Vs_PhiTID", 50, -3.2, 3.2, 300, 0, 600);
479  tmp = dqmStore_->book2D("MPV_Vs_PhiTOB", "MPV_Vs_PhiTOB", 50, -3.2, 3.2, 300, 0, 600);
481  tmp = dqmStore_->book2D("MPV_Vs_PhiTEC", "MPV_Vs_PhiTEC", 50, -3.2, 3.2, 300, 0, 600);
483  tmp = dqmStore_->book2D("MPV_Vs_PhiTEC1", "MPV_Vs_PhiTEC1", 50, -3.2, 3.2, 300, 0, 600);
485  tmp = dqmStore_->book2D("MPV_Vs_PhiTEC2", "MPV_Vs_PhiTEC2", 50, -3.2, 3.2, 300, 0, 600);
487 
488  tmp = dqmStore_->book1D("MPV_Vs_PathTIB", "MPV_Vs_PathTIB", 100, 0.2, 1.4);
490  tmp = dqmStore_->book1D("MPV_Vs_PathTID", "MPV_Vs_PathTID", 100, 0.2, 1.4);
492  tmp = dqmStore_->book1D("MPV_Vs_PathTOB", "MPV_Vs_PathTOB", 100, 0.2, 1.4);
494  tmp = dqmStore_->book1D("MPV_Vs_PathTEC", "MPV_Vs_PathTEC", 100, 0.2, 1.4);
496  tmp = dqmStore_->book1D("MPV_Vs_PathTEC1", "MPV_Vs_PathTEC1", 100, 0.2, 1.4);
498  tmp = dqmStore_->book1D("MPV_Vs_PathTEC2", "MPV_Vs_PathTEC2", 100, 0.2, 1.4);
500 
501  tmp = dqmStore_->book2D("MPV_Vs_Phi", "MPV_Vs_Phi", 50, -3.2, 3.2, 300, 0, 600);
502  MPV_Vs_Phi = tmp->getTH2F();
503  tmp = dqmStore_->book2D("MPV_Vs_Eta", "MPV_Vs_Eta", 50, -3.0, 3.0, 300, 0, 600);
504  MPV_Vs_Eta = tmp->getTH2F();
505  tmp = dqmStore_->book2D("MPV_Vs_R", "MPV_Vs_R", 150, 0.0, 150.0, 300, 0, 600);
506  MPV_Vs_R = tmp->getTH2F();
507  /*
508  tmp = dqmStore_->book1D ("MPV_Vs_PathLength_CS1" , "MPV_Vs_PathLength_CS1" , 250, 0.2, 1.4); MPV_Vs_PathLength_CS1 = tmp->getTH1F();
509  tmp = dqmStore_->book1D ("MPV_Vs_PathLength_CS2" , "MPV_Vs_PathLength_CS2" , 250, 0.2, 1.4); MPV_Vs_PathLength_CS2 = tmp->getTH1F();
510  tmp = dqmStore_->book1D ("MPV_Vs_PathLength_CS3" , "MPV_Vs_PathLength_CS3" , 250, 0.2, 1.4); MPV_Vs_PathLength_CS3 = tmp->getTH1F();
511  tmp = dqmStore_->book1D ("MPV_Vs_PathLength_CS4" , "MPV_Vs_PathLength_CS4" , 250, 0.2, 1.4); MPV_Vs_PathLength_CS4 = tmp->getTH1F();
512  tmp = dqmStore_->book1D ("MPV_Vs_PathLength_CS5" , "MPV_Vs_PathLength_CS5" , 250, 0.2, 1.4); MPV_Vs_PathLength_CS5 = tmp->getTH1F();
513 
514  tmp = dqmStore_->book1D ("FWHM_Vs_PathLength_CS1" , "FWHM_Vs_PathLength_CS1", 250, 0.2, 1.4); FWHM_Vs_PathLength_CS1 = tmp->getTH1F();
515  tmp = dqmStore_->book1D ("FWHM_Vs_PathLength_CS2" , "FWHM_Vs_PathLength_CS2", 250, 0.2, 1.4); FWHM_Vs_PathLength_CS2 = tmp->getTH1F();
516  tmp = dqmStore_->book1D ("FWHM_Vs_PathLength_CS3" , "FWHM_Vs_PathLength_CS3", 250, 0.2, 1.4); FWHM_Vs_PathLength_CS3 = tmp->getTH1F();
517  tmp = dqmStore_->book1D ("FWHM_Vs_PathLength_CS4" , "FWHM_Vs_PathLength_CS4", 250, 0.2, 1.4); FWHM_Vs_PathLength_CS4 = tmp->getTH1F();
518  tmp = dqmStore_->book1D ("FWHM_Vs_PathLength_CS5" , "FWHM_Vs_PathLength_CS5", 250, 0.2, 1.4); FWHM_Vs_PathLength_CS5 = tmp->getTH1F();
519 */
520  tmp = dqmStore_->book1D("MPV_Vs_PathLength", "MPV_Vs_PathLength", 100, 0.2, 1.4);
522  tmp = dqmStore_->book1D("MPV_Vs_PathLength320", "MPV_Vs_PathLength", 100, 0.2, 1.4);
524  tmp = dqmStore_->book1D("MPV_Vs_PathLength500", "MPV_Vs_PathLength", 100, 0.2, 1.4);
526 
527  tmp = dqmStore_->book1D("FWHM_Vs_PathLength", "FWHM_Vs_PathLength", 100, 0.2, 1.4);
529  tmp = dqmStore_->book1D("FWHM_Vs_PathLength320", "FWHM_Vs_PathLength", 100, 0.2, 1.4);
531  tmp = dqmStore_->book1D("FWHM_Vs_PathLength500", "FWHM_Vs_PathLength", 100, 0.2, 1.4);
533 
534  tmp = dqmStore_->book1D("MPV_Vs_TransversAngle", "MPV_Vs_TransversAngle", 220, -20, 200);
536  tmp = dqmStore_->book1D("MPV_Vs_Alpha", "MPV_Vs_Alpha", 220, -20, 200);
537  MPV_Vs_Alpha = tmp->getTH1F();
538  tmp = dqmStore_->book1D("MPV_Vs_Beta", "MPV_Vs_Beta", 220, -20, 200);
539  MPV_Vs_Beta = tmp->getTH1F();
540 
541  tmp = dqmStore_->book2D("Error_Vs_MPV", "Error_Vs_MPV", 600, 0, 600, 100, 0, 50);
542  Error_Vs_MPV = tmp->getTH2F();
543  tmp = dqmStore_->book2D("Error_Vs_Entries", "Error_Vs_Entries", 500, 0, 10000, 100, 0, 50);
545  tmp = dqmStore_->book2D("Error_Vs_Eta", "Error_Vs_Eta", 50, -3.0, 3.0, 100, 0, 50);
546  Error_Vs_Eta = tmp->getTH2F();
547  tmp = dqmStore_->book2D("Error_Vs_Phi", "Error_Vs_Phi", 50, -3.2, 3.2, 100, 0, 50);
548  Error_Vs_Phi = tmp->getTH2F();
549 
550  tmp = dqmStore_->book2D("NoMPV_Vs_EtaPhi", "NoMPV_Vs_EtaPhi", 50, -3.0, 3.0, 50, -3.2, 3.2);
552 
553  tmp = dqmStore_->book1D("NumberOfEntriesByAPV", "NumberOfEntriesByAPV", 1000, 0, 10000);
555  tmp = dqmStore_->book1D("Chi2OverNDF", "Chi2OverNDF", 500, 0, 25);
556  HChi2OverNDF = tmp->getTH1F();
557 
558  tmp = dqmStore_->book1D("MPVs", "MPVs", 600, 0, 600);
559  MPVs = tmp->getTH1F();
560  tmp = dqmStore_->book1D("MPVs320", "MPVs320", 600, 0, 600);
561  MPVs320 = tmp->getTH1F();
562  tmp = dqmStore_->book1D("MPVs500", "MPVs500", 600, 0, 600);
563  MPVs500 = tmp->getTH1F();
564 
565  // MPV_vs_10RplusEta tmp = dqmStore_->book2D ("MPV_vs_10RplusEta","MPV_vs_10RplusEta", 48000,0,2400, 800,100,500);
566  }
567 
568  gROOT->cd();
569 
570  auto const& Det = iSetup.getData(tkGeomToken_).dets();
571 
572  // if(strcmp(AlgoMode.c_str(),"MultiJob")!=0 && !FirstSetOfConstants){
573  if (!iSetup.getHandle(gainToken_)) {
574  printf("\n#####################\n\nERROR --> gainHandle is not valid\n\n#####################\n\n");
575  exit(0);
576  }
577  // }
578 
579  unsigned int Id = 0;
580  for (unsigned int i = 0; i < Det.size(); i++) {
581  DetId Detid = Det[i]->geographicalId();
582  int SubDet = Detid.subdetId();
583 
586  auto DetUnit = dynamic_cast<StripGeomDetUnit const*>(Det[i]);
587  if (!DetUnit)
588  continue;
589 
590  const StripTopology& Topo = DetUnit->specificTopology();
591  unsigned int NAPV = Topo.nstrips() / 128;
592 
593  double Phi = DetUnit->position().basicVector().phi();
594  double Eta = DetUnit->position().basicVector().eta();
595  double R = DetUnit->position().basicVector().transverse();
596  double Thick = DetUnit->surface().bounds().thickness();
597 
598  for (unsigned int j = 0; j < NAPV; j++) {
599  stAPVGain* APV = new stAPVGain;
600  APV->Index = Id;
601  APV->DetId = Detid.rawId();
602  APV->APVId = j;
603  APV->SubDet = SubDet;
604  APV->MPV = -1;
605  APV->Gain = -1;
606  APV->PreviousGain = 1;
607  APV->Eta = Eta;
608  APV->Phi = Phi;
609  APV->R = R;
610  APV->Thickness = Thick;
611  APV->Side = 0;
612 
613  if (SubDet == StripSubdetector::TID) {
614  APV->Side = tTopo->tecSide(Detid);
615  } else if (SubDet == StripSubdetector::TEC) {
616  APV->Side = tTopo->tecSide(Detid);
617  }
618 
619  APVsCollOrdered.push_back(APV);
620  APVsColl[(APV->DetId << 3) | APV->APVId] = APV;
621  Id++;
622 
623  APV_DetId->Fill(Id, APV->DetId);
624  APV_Id->Fill(Id, APV->APVId);
625  APV_Eta->Fill(Id, APV->Eta);
626  APV_R->Fill(Id, APV->R);
627  APV_SubDet->Fill(Id, APV->SubDet);
628  APV_Thickness->Fill(Id, APV->Thickness);
629  }
630  }
631  }
632 
633  NEvent = 0;
634  SRun = 0;
635  SEvent = 0;
636  STimestamp = 0;
637  ERun = 0;
638  EEvent = 0;
639  ETimestamp = 0;
640 }
641 
643  unsigned int I = 0;
644 
645  if (strcmp(AlgoMode.c_str(), "WriteOnDB") == 0 || strcmp(AlgoMode.c_str(), "Merge") == 0) {
646  TH1::AddDirectory(kTRUE);
647 
648  TFile* file = nullptr;
649  for (unsigned int f = 0; f < VInputFiles.size(); f++) {
650  printf("Loading New Input File : %s\n", VInputFiles[f].c_str());
651  if (CheckIfFileExist) {
652  FILE* doesFileExist = fopen(VInputFiles[f].c_str(), "r");
653  if (!doesFileExist) {
654  printf("File %s doesn't exist\n", VInputFiles[f].c_str());
655  continue;
656  } else {
657  fclose(doesFileExist);
658  }
659  }
660  file = new TFile(VInputFiles[f].c_str());
661  if (!file || file->IsZombie()) {
662  printf("### Bug With File %s\n### File will be skipped \n", VInputFiles[f].c_str());
663  continue;
664  }
665  APV_Charge->Add((TH1*)file->FindObjectAny("APV_Charge"), 1);
666  APV_Momentum->Add((TH1*)file->FindObjectAny("APV_Momentum"), 1);
667  APV_PathLength->Add((TH1*)file->FindObjectAny("APV_PathLength"), 1);
668 
669  Tracks_P_Vs_Eta->Add((TH1*)file->FindObjectAny("Tracks_P_Vs_Eta"), 1);
670  Tracks_Pt_Vs_Eta->Add((TH1*)file->FindObjectAny("Tracks_Pt_Vs_Eta"), 1);
671 
672  Charge_Vs_PathTIB->Add((TH1*)file->FindObjectAny("Charge_Vs_PathTIB"), 1);
673  Charge_Vs_PathTID->Add((TH1*)file->FindObjectAny("Charge_Vs_PathTID"), 1);
674  Charge_Vs_PathTOB->Add((TH1*)file->FindObjectAny("Charge_Vs_PathTOB"), 1);
675  Charge_Vs_PathTEC->Add((TH1*)file->FindObjectAny("Charge_Vs_PathTEC"), 1);
676  Charge_Vs_PathTEC1->Add((TH1*)file->FindObjectAny("Charge_Vs_PathTEC1"), 1);
677  Charge_Vs_PathTEC2->Add((TH1*)file->FindObjectAny("Charge_Vs_PathTEC2"), 1);
678 
679  HTrackChi2OverNDF->Add((TH1*)file->FindObjectAny("TrackChi2OverNDF"), 1);
680  HTrackHits->Add((TH1*)file->FindObjectAny("TrackHits"), 1);
681 
682  NHighStripInCluster->Add((TH1*)file->FindObjectAny("NHighStripInCluster"), 1);
683  NSatStripInCluster->Add((TH1*)file->FindObjectAny("NSatStripInCluster"), 1);
684  Charge_Vs_PathLength->Add((TH1*)file->FindObjectAny("Charge_Vs_PathLength"), 1);
685  Charge_Vs_PathLength320->Add((TH1*)file->FindObjectAny("Charge_Vs_PathLength320"), 1);
686  Charge_Vs_PathLength500->Add((TH1*)file->FindObjectAny("Charge_Vs_PathLength500"), 1);
687  Charge_Vs_TransversAngle->Add((TH1*)file->FindObjectAny("Charge_Vs_TransversAngle"), 1);
688  NStrips_Vs_TransversAngle->Add((TH1*)file->FindObjectAny("NStrips_Vs_TransversAngle"), 1);
689  Charge_Vs_Alpha->Add((TH1*)file->FindObjectAny("Charge_Vs_Alpha"), 1);
690  NStrips_Vs_Alpha->Add((TH1*)file->FindObjectAny("NStrips_Vs_Alpha"), 1);
691  HFirstStrip->Add((TH1*)file->FindObjectAny("FirstStrip"), 1);
692 
693  TH1F* JobInfo_tmp = (TH1F*)file->FindObjectAny("JobInfo");
694  NEvent += (unsigned int)JobInfo_tmp->GetBinContent(JobInfo_tmp->GetXaxis()->FindBin(1));
695  unsigned int tmp_SRun = (unsigned int)JobInfo_tmp->GetBinContent(JobInfo_tmp->GetXaxis()->FindBin(3));
696  unsigned int tmp_SEvent = (unsigned int)JobInfo_tmp->GetBinContent(JobInfo_tmp->GetXaxis()->FindBin(4));
697  unsigned int tmp_ERun = (unsigned int)JobInfo_tmp->GetBinContent(JobInfo_tmp->GetXaxis()->FindBin(6));
698  unsigned int tmp_EEvent = (unsigned int)JobInfo_tmp->GetBinContent(JobInfo_tmp->GetXaxis()->FindBin(7));
699 
700  if (SRun == 0)
701  SRun = tmp_SRun;
702 
703  if (tmp_SRun < SRun) {
704  SRun = tmp_SRun;
705  SEvent = tmp_SEvent;
706  } else if (tmp_SRun == SRun && tmp_SEvent < SEvent) {
707  SEvent = tmp_SEvent;
708  }
709 
710  if (tmp_ERun > ERun) {
711  ERun = tmp_ERun;
712  EEvent = tmp_EEvent;
713  } else if (tmp_ERun == ERun && tmp_EEvent > EEvent) {
714  EEvent = tmp_EEvent;
715  }
716 
717  printf("Deleting Current Input File\n");
718  file->Close();
719  delete file;
720  }
721  }
722 
723  JobInfo->Fill(1, NEvent);
724  JobInfo->Fill(3, SRun);
725  JobInfo->Fill(4, SEvent);
726  JobInfo->Fill(6, ERun);
727  JobInfo->Fill(7, EEvent);
728 
729  if (strcmp(AlgoMode.c_str(), "MultiJob") != 0) {
730  TH1D* Proj = nullptr;
731  double FitResults[5];
732  I = 0;
733  for (auto it = APVsColl.begin(); it != APVsColl.end(); it++) {
734  if (I % 3650 == 0)
735  printf("Fitting Histograms \t %6.2f%%\n", (100.0 * I) / APVsColl.size());
736  I++;
737  stAPVGain* APV = it->second;
738 
739  int bin = APV_Charge->GetXaxis()->FindBin(APV->Index);
740  Proj = APV_Charge->ProjectionY(" ", bin, bin, "e");
741  Proj = (TH1D*)Proj->Clone();
742  if (Proj == nullptr)
743  continue;
744 
745  // ADD PROJECTTIONS COMMING FROM THE SECOND APV IN THE PAIR
746  if (CalibrationLevel == 1) {
747  int SecondAPVId = APV->APVId;
748  if (SecondAPVId % 2 == 0) {
749  SecondAPVId = SecondAPVId + 1;
750  } else {
751  SecondAPVId = SecondAPVId - 1;
752  }
753  stAPVGain* APV2 = APVsColl[(APV->DetId << 3) | SecondAPVId];
754 
755  int bin2 = APV_Charge->GetXaxis()->FindBin(APV2->Index);
756  TH1D* Proj2 = APV_Charge->ProjectionY(" ", bin2, bin2, "e");
757  if (Proj2 != nullptr) {
758  Proj->Add(Proj2, 1);
759  }
760  } else if (CalibrationLevel > 1) {
761  // printf("%8i %i--> %4.0f + %4.0f\n",APV->DetId, APV->APVId, 0.0, Proj->GetEntries());
762  for (auto it2 = APVsColl.begin(); it2 != APVsColl.end(); it2++) {
763  stAPVGain* APV2 = it2->second;
764 
765  if (APV2->DetId != APV->DetId)
766  continue;
767  if (APV2->APVId == APV->APVId)
768  continue;
769 
770  int bin2 = APV_Charge->GetXaxis()->FindBin(APV2->Index);
771  TH1D* Proj2 = APV_Charge->ProjectionY(" ", bin2, bin2, "e");
772  if (Proj2 != nullptr) {
773  // printf("%8i %i--> %4.0f + %4.0f\n",APV2->DetId, APV2->APVId, Proj->GetEntries(), Proj2->GetEntries());
774  Proj->Add(Proj2, 1);
775  }
776  }
777  // printf("%8i %i--> %4.0f Full\n",APV->DetId, APV->APVId, Proj->GetEntries());
778  }
779 
780  //std::cout << "Proj->GetEntries(): " << Proj->GetEntries() << ", Proj->GetMean(): " << Proj->GetMean() << std::endl;
781 
782  getPeakOfLandau(Proj, FitResults);
783  APV->MPV = FitResults[0];
784  // printf("MPV = %f - %f\n",FitResults[0], FitResults[1]);
785  if (FitResults[0] != -0.5 && FitResults[1] < MaxMPVError) {
786  APV_MPV->Fill(APV->Index, APV->MPV);
787  MPVs->Fill(APV->MPV);
788  if (APV->Thickness < 0.04)
789  MPVs320->Fill(APV->MPV);
790  if (APV->Thickness > 0.04)
791  MPVs500->Fill(APV->MPV);
792 
793  MPV_Vs_R->Fill(APV->R, APV->MPV);
794  MPV_Vs_Eta->Fill(APV->Eta, APV->MPV);
795  if (APV->SubDet == StripSubdetector::TIB)
796  MPV_Vs_EtaTIB->Fill(APV->Eta, APV->MPV);
797  if (APV->SubDet == StripSubdetector::TID)
798  MPV_Vs_EtaTID->Fill(APV->Eta, APV->MPV);
799  if (APV->SubDet == StripSubdetector::TOB)
800  MPV_Vs_EtaTOB->Fill(APV->Eta, APV->MPV);
801  if (APV->SubDet == StripSubdetector::TEC) {
802  MPV_Vs_EtaTEC->Fill(APV->Eta, APV->MPV);
803  if (APV->Thickness < 0.04)
804  MPV_Vs_EtaTEC1->Fill(APV->Eta, APV->MPV);
805  if (APV->Thickness > 0.04)
806  MPV_Vs_EtaTEC2->Fill(APV->Eta, APV->MPV);
807  }
808  MPV_Vs_Phi->Fill(APV->Phi, APV->MPV);
809  if (APV->SubDet == StripSubdetector::TIB)
810  MPV_Vs_PhiTIB->Fill(APV->Phi, APV->MPV);
811  if (APV->SubDet == StripSubdetector::TID)
812  MPV_Vs_PhiTID->Fill(APV->Phi, APV->MPV);
813  if (APV->SubDet == StripSubdetector::TOB)
814  MPV_Vs_PhiTOB->Fill(APV->Phi, APV->MPV);
815  if (APV->SubDet == StripSubdetector::TEC) {
816  MPV_Vs_PhiTEC->Fill(APV->Phi, APV->MPV);
817  if (APV->Thickness < 0.04)
818  MPV_Vs_PhiTEC1->Fill(APV->Phi, APV->MPV);
819  if (APV->Thickness > 0.04)
820  MPV_Vs_PhiTEC2->Fill(APV->Phi, APV->MPV);
821  }
822 
823  if (APV->SubDet == StripSubdetector::TIB)
824  Charge_TIB->Add(Proj, 1);
825  if (APV->SubDet == StripSubdetector::TID) {
826  Charge_TID->Add(Proj, 1);
827  if (APV->Side == 1)
828  Charge_TIDM->Add(Proj, 1);
829  if (APV->Side == 2)
830  Charge_TIDP->Add(Proj, 1);
831  }
832  if (APV->SubDet == StripSubdetector::TOB)
833  Charge_TOB->Add(Proj, 1);
834  if (APV->SubDet == StripSubdetector::TEC) {
835  Charge_TEC->Add(Proj, 1);
836  if (APV->Thickness < 0.04)
837  Charge_TEC1->Add(Proj, 1);
838  if (APV->Thickness > 0.04)
839  Charge_TEC2->Add(Proj, 1);
840  if (APV->Side == 1)
841  Charge_TECM->Add(Proj, 1);
842  if (APV->Side == 2)
843  Charge_TECP->Add(Proj, 1);
844  }
845  }
846 
847  if (APV->SubDet == StripSubdetector::TIB)
848  Charge_TIB->Add(Proj, 1);
849  if (APV->SubDet == StripSubdetector::TID) {
850  Charge_TID->Add(Proj, 1);
851  if (APV->Side == 1)
852  Charge_TIDM->Add(Proj, 1);
853  if (APV->Side == 2)
854  Charge_TIDP->Add(Proj, 1);
855  }
856  if (APV->SubDet == StripSubdetector::TOB)
857  Charge_TOB->Add(Proj, 1);
858  if (APV->SubDet == StripSubdetector::TEC) {
859  Charge_TEC->Add(Proj, 1);
860  if (APV->Thickness < 0.04)
861  Charge_TEC1->Add(Proj, 1);
862  if (APV->Thickness > 0.04)
863  Charge_TEC2->Add(Proj, 1);
864  if (APV->Side == 1)
865  Charge_TECM->Add(Proj, 1);
866  if (APV->Side == 2)
867  Charge_TECP->Add(Proj, 1);
868  }
869 
870  if (FitResults[0] != -0.5) {
871  HChi2OverNDF->Fill(FitResults[4]);
872  Error_Vs_MPV->Fill(FitResults[0], FitResults[1]);
873  Error_Vs_Entries->Fill(Proj->GetEntries(), FitResults[1]);
874  Error_Vs_Eta->Fill(APV->Eta, FitResults[1]);
875  Error_Vs_Phi->Fill(APV->Phi, FitResults[1]);
876  }
877  NumberOfEntriesByAPV->Fill(Proj->GetEntries());
878  delete Proj;
879 
880  Proj = APV_PathLength->ProjectionY(" ", bin, bin, "e");
881  if (Proj == nullptr)
882  continue;
883 
884  APV_PathLengthM->SetBinContent(APV->Index, Proj->GetMean(1));
885  APV_PathLengthM->SetBinError(APV->Index, Proj->GetMeanError(1));
886  // delete Proj;
887  }
888 
889  unsigned int GOOD = 0;
890  unsigned int BAD = 0;
891  double MPVmean = 300.; //MPVs->GetMean();
892  for (auto it = APVsColl.begin(); it != APVsColl.end(); it++) {
893  stAPVGain* APV = it->second;
894  if (APV->MPV > 0) {
895  APV->Gain = APV->MPV / MPVmean; // APV->MPV;
896  GOOD++;
897  } else {
898  NoMPV_Vs_EtaPhi->Fill(APV->Eta, APV->Phi);
899  APV->Gain = 1;
900  BAD++;
901  }
902  if (APV->Gain <= 0)
903  APV->Gain = 1;
904  APV_Gain->Fill(APV->Index, APV->Gain);
905 
906  if (!FirstSetOfConstants)
907  APV->Gain *= APV->PreviousGain;
908  APV_CumulGain->Fill(APV->Index, APV->Gain);
909  }
910 
911  for (int j = 0; j < Charge_Vs_PathLength->GetXaxis()->GetNbins(); j++) {
912  Proj = Charge_Vs_PathLength->ProjectionY(" ", j, j, "e");
913  getPeakOfLandau(Proj, FitResults);
914  if (FitResults[0] == -0.5)
915  continue;
916  MPV_Vs_PathLength->SetBinContent(j, FitResults[0] / Charge_Vs_PathLength->GetXaxis()->GetBinCenter(j));
917  MPV_Vs_PathLength->SetBinError(j, FitResults[1] / Charge_Vs_PathLength->GetXaxis()->GetBinCenter(j));
918  FWHM_Vs_PathLength->SetBinContent(
919  j, FitResults[2] / (FitResults[0] / Charge_Vs_PathLength->GetXaxis()->GetBinCenter(j)));
920  FWHM_Vs_PathLength->SetBinError(
921  j, FitResults[3] / (FitResults[0] / Charge_Vs_PathLength->GetXaxis()->GetBinCenter(j)));
922  delete Proj;
923  }
924 
925  for (int j = 0; j < Charge_Vs_PathLength320->GetXaxis()->GetNbins(); j++) {
926  Proj = Charge_Vs_PathLength320->ProjectionY(" ", j, j, "e");
927  getPeakOfLandau(Proj, FitResults);
928  if (FitResults[0] == -0.5)
929  continue;
930  MPV_Vs_PathLength320->SetBinContent(j, FitResults[0] / Charge_Vs_PathLength320->GetXaxis()->GetBinCenter(j));
931  MPV_Vs_PathLength320->SetBinError(j, FitResults[1] / Charge_Vs_PathLength320->GetXaxis()->GetBinCenter(j));
932  FWHM_Vs_PathLength320->SetBinContent(
933  j, FitResults[2] / (FitResults[0] / Charge_Vs_PathLength320->GetXaxis()->GetBinCenter(j)));
934  FWHM_Vs_PathLength320->SetBinError(
935  j, FitResults[3] / (FitResults[0] / Charge_Vs_PathLength320->GetXaxis()->GetBinCenter(j)));
936  delete Proj;
937  }
938 
939  for (int j = 0; j < Charge_Vs_PathLength500->GetXaxis()->GetNbins(); j++) {
940  Proj = Charge_Vs_PathLength500->ProjectionY(" ", j, j, "e");
941  getPeakOfLandau(Proj, FitResults);
942  if (FitResults[0] == -0.5)
943  continue;
944  MPV_Vs_PathLength500->SetBinContent(j, FitResults[0] / Charge_Vs_PathLength500->GetXaxis()->GetBinCenter(j));
945  MPV_Vs_PathLength500->SetBinError(j, FitResults[1] / Charge_Vs_PathLength500->GetXaxis()->GetBinCenter(j));
946  FWHM_Vs_PathLength500->SetBinContent(
947  j, FitResults[2] / (FitResults[0] / Charge_Vs_PathLength500->GetXaxis()->GetBinCenter(j)));
948  FWHM_Vs_PathLength500->SetBinError(
949  j, FitResults[3] / (FitResults[0] / Charge_Vs_PathLength500->GetXaxis()->GetBinCenter(j)));
950  delete Proj;
951  }
952  /*
953  for(int j=0;j<Charge_Vs_PathLength_CS1->GetXaxis()->GetNbins();j++){
954  Proj = Charge_Vs_PathLength_CS1->ProjectionY(" ",j,j,"e");
955  getPeakOfLandau(Proj,FitResults); if(FitResults[0] ==-0.5)continue;
956  MPV_Vs_PathLength_CS1->SetBinContent (j, FitResults[0]/Charge_Vs_PathLength_CS1->GetXaxis()->GetBinCenter(j));
957  MPV_Vs_PathLength_CS1->SetBinError (j, FitResults[1]/Charge_Vs_PathLength_CS1->GetXaxis()->GetBinCenter(j));
958  FWHM_Vs_PathLength_CS1->SetBinContent(j, FitResults[2]/(FitResults[0]/Charge_Vs_PathLength_CS1->GetXaxis()->GetBinCenter(j) ));
959  FWHM_Vs_PathLength_CS1->SetBinError (j, FitResults[3]/(FitResults[0]/Charge_Vs_PathLength_CS1->GetXaxis()->GetBinCenter(j) ));
960  delete Proj;
961  }
962 
963  for(int j=0;j<Charge_Vs_PathLength_CS2->GetXaxis()->GetNbins();j++){
964  Proj = Charge_Vs_PathLength_CS2->ProjectionY(" ",j,j,"e");
965  getPeakOfLandau(Proj,FitResults); if(FitResults[0] ==-0.5)continue;
966  MPV_Vs_PathLength_CS2->SetBinContent (j, FitResults[0]/Charge_Vs_PathLength_CS2->GetXaxis()->GetBinCenter(j));
967  MPV_Vs_PathLength_CS2->SetBinError (j, FitResults[1]/Charge_Vs_PathLength_CS2->GetXaxis()->GetBinCenter(j));
968  FWHM_Vs_PathLength_CS2->SetBinContent(j, FitResults[2]/(FitResults[0]/Charge_Vs_PathLength_CS2->GetXaxis()->GetBinCenter(j) ));
969  FWHM_Vs_PathLength_CS2->SetBinError (j, FitResults[3]/(FitResults[0]/Charge_Vs_PathLength_CS2->GetXaxis()->GetBinCenter(j) ));
970  delete Proj;
971  }
972 
973  for(int j=0;j<Charge_Vs_PathLength_CS3->GetXaxis()->GetNbins();j++){
974  Proj = Charge_Vs_PathLength_CS3->ProjectionY(" ",j,j,"e");
975  getPeakOfLandau(Proj,FitResults); if(FitResults[0] ==-0.5)continue;
976  MPV_Vs_PathLength_CS3->SetBinContent (j, FitResults[0]/Charge_Vs_PathLength_CS3->GetXaxis()->GetBinCenter(j));
977  MPV_Vs_PathLength_CS3->SetBinError (j, FitResults[1]/Charge_Vs_PathLength_CS3->GetXaxis()->GetBinCenter(j));
978  FWHM_Vs_PathLength_CS3->SetBinContent(j, FitResults[2]/(FitResults[0]/Charge_Vs_PathLength_CS3->GetXaxis()->GetBinCenter(j) ));
979  FWHM_Vs_PathLength_CS3->SetBinError (j, FitResults[3]/(FitResults[0]/Charge_Vs_PathLength_CS3->GetXaxis()->GetBinCenter(j) ));
980  delete Proj;
981  }
982 
983  for(int j=0;j<Charge_Vs_PathLength_CS4->GetXaxis()->GetNbins();j++){
984  Proj = Charge_Vs_PathLength_CS4->ProjectionY(" ",j,j,"e");
985  getPeakOfLandau(Proj,FitResults); if(FitResults[0] ==-0.5)continue;
986  MPV_Vs_PathLength_CS4->SetBinContent (j, FitResults[0]/Charge_Vs_PathLength_CS4->GetXaxis()->GetBinCenter(j));
987  MPV_Vs_PathLength_CS4->SetBinError (j, FitResults[1]/Charge_Vs_PathLength_CS4->GetXaxis()->GetBinCenter(j));
988  FWHM_Vs_PathLength_CS4->SetBinContent(j, FitResults[2]/(FitResults[0]/Charge_Vs_PathLength_CS4->GetXaxis()->GetBinCenter(j) ));
989  FWHM_Vs_PathLength_CS4->SetBinError (j, FitResults[3]/(FitResults[0]/Charge_Vs_PathLength_CS4->GetXaxis()->GetBinCenter(j) ));
990  delete Proj;
991  }
992 
993  for(int j=0;j<Charge_Vs_PathLength_CS5->GetXaxis()->GetNbins();j++){
994  Proj = Charge_Vs_PathLength_CS5->ProjectionY(" ",j,j,"e");
995  getPeakOfLandau(Proj,FitResults); if(FitResults[0] ==-0.5)continue;
996  MPV_Vs_PathLength_CS5->SetBinContent (j, FitResults[0]/Charge_Vs_PathLength_CS5->GetXaxis()->GetBinCenter(j));
997  MPV_Vs_PathLength_CS5->SetBinError (j, FitResults[1]/Charge_Vs_PathLength_CS5->GetXaxis()->GetBinCenter(j));
998  FWHM_Vs_PathLength_CS5->SetBinContent(j, FitResults[2]/(FitResults[0]/Charge_Vs_PathLength_CS5->GetXaxis()->GetBinCenter(j) ));
999  FWHM_Vs_PathLength_CS5->SetBinError (j, FitResults[3]/(FitResults[0]/Charge_Vs_PathLength_CS5->GetXaxis()->GetBinCenter(j) ));
1000  delete Proj;
1001  }
1002 */
1003 
1004  for (int j = 0; j < Charge_Vs_PathTIB->GetXaxis()->GetNbins(); j++) {
1005  Proj = Charge_Vs_PathTIB->ProjectionY(" ", j, j, "e");
1006  getPeakOfLandau(Proj, FitResults);
1007  if (FitResults[0] == -0.5)
1008  continue;
1009  MPV_Vs_PathTIB->SetBinContent(j, FitResults[0] / Charge_Vs_PathTIB->GetXaxis()->GetBinCenter(j));
1010  MPV_Vs_PathTIB->SetBinError(j, FitResults[1] / Charge_Vs_PathTIB->GetXaxis()->GetBinCenter(j));
1011  delete Proj;
1012  }
1013 
1014  for (int j = 0; j < Charge_Vs_PathTID->GetXaxis()->GetNbins(); j++) {
1015  Proj = Charge_Vs_PathTID->ProjectionY(" ", j, j, "e");
1016  getPeakOfLandau(Proj, FitResults);
1017  if (FitResults[0] == -0.5)
1018  continue;
1019  MPV_Vs_PathTID->SetBinContent(j, FitResults[0] / Charge_Vs_PathTID->GetXaxis()->GetBinCenter(j));
1020  MPV_Vs_PathTID->SetBinError(j, FitResults[1] / Charge_Vs_PathTID->GetXaxis()->GetBinCenter(j));
1021  delete Proj;
1022  }
1023 
1024  for (int j = 0; j < Charge_Vs_PathTOB->GetXaxis()->GetNbins(); j++) {
1025  Proj = Charge_Vs_PathTOB->ProjectionY(" ", j, j, "e");
1026  getPeakOfLandau(Proj, FitResults);
1027  if (FitResults[0] == -0.5)
1028  continue;
1029  MPV_Vs_PathTOB->SetBinContent(j, FitResults[0] / Charge_Vs_PathTOB->GetXaxis()->GetBinCenter(j));
1030  MPV_Vs_PathTOB->SetBinError(j, FitResults[1] / Charge_Vs_PathTOB->GetXaxis()->GetBinCenter(j));
1031  delete Proj;
1032  }
1033 
1034  for (int j = 0; j < Charge_Vs_PathTEC->GetXaxis()->GetNbins(); j++) {
1035  Proj = Charge_Vs_PathTEC->ProjectionY(" ", j, j, "e");
1036  getPeakOfLandau(Proj, FitResults);
1037  if (FitResults[0] == -0.5)
1038  continue;
1039  MPV_Vs_PathTEC->SetBinContent(j, FitResults[0] / Charge_Vs_PathTEC->GetXaxis()->GetBinCenter(j));
1040  MPV_Vs_PathTEC->SetBinError(j, FitResults[1] / Charge_Vs_PathTEC->GetXaxis()->GetBinCenter(j));
1041  delete Proj;
1042  }
1043 
1044  for (int j = 0; j < Charge_Vs_PathTEC1->GetXaxis()->GetNbins(); j++) {
1045  Proj = Charge_Vs_PathTEC1->ProjectionY(" ", j, j, "e");
1046  getPeakOfLandau(Proj, FitResults);
1047  if (FitResults[0] == -0.5)
1048  continue;
1049  MPV_Vs_PathTEC1->SetBinContent(j, FitResults[0] / Charge_Vs_PathTEC1->GetXaxis()->GetBinCenter(j));
1050  MPV_Vs_PathTEC1->SetBinError(j, FitResults[1] / Charge_Vs_PathTEC1->GetXaxis()->GetBinCenter(j));
1051  delete Proj;
1052  }
1053 
1054  for (int j = 0; j < Charge_Vs_PathTEC2->GetXaxis()->GetNbins(); j++) {
1055  Proj = Charge_Vs_PathTEC2->ProjectionY(" ", j, j, "e");
1056  getPeakOfLandau(Proj, FitResults);
1057  if (FitResults[0] == -0.5)
1058  continue;
1059  MPV_Vs_PathTEC2->SetBinContent(j, FitResults[0] / Charge_Vs_PathTEC2->GetXaxis()->GetBinCenter(j));
1060  MPV_Vs_PathTEC2->SetBinError(j, FitResults[1] / Charge_Vs_PathTEC2->GetXaxis()->GetBinCenter(j));
1061  delete Proj;
1062  }
1063 
1064  for (int j = 1; j < Charge_Vs_TransversAngle->GetXaxis()->GetNbins(); j++) {
1065  Proj = Charge_Vs_TransversAngle->ProjectionY(" ", j, j, "e");
1066  getPeakOfLandau(Proj, FitResults);
1067  if (FitResults[0] == -0.5)
1068  continue;
1069  MPV_Vs_TransversAngle->SetBinContent(j, FitResults[0]);
1070  MPV_Vs_TransversAngle->SetBinError(j, FitResults[1]);
1071  delete Proj;
1072  }
1073 
1074  for (int j = 1; j < Charge_Vs_Alpha->GetXaxis()->GetNbins(); j++) {
1075  Proj = Charge_Vs_Alpha->ProjectionY(" ", j, j, "e");
1076  getPeakOfLandau(Proj, FitResults);
1077  if (FitResults[0] == -0.5)
1078  continue;
1079  MPV_Vs_Alpha->SetBinContent(j, FitResults[0]);
1080  MPV_Vs_Alpha->SetBinError(j, FitResults[1]);
1081  delete Proj;
1082  }
1083 
1084  for (int j = 1; j < Charge_Vs_Beta->GetXaxis()->GetNbins(); j++) {
1085  Proj = Charge_Vs_Beta->ProjectionY(" ", j, j, "e");
1086  getPeakOfLandau(Proj, FitResults);
1087  if (FitResults[0] == -0.5)
1088  continue;
1089  MPV_Vs_Beta->SetBinContent(j, FitResults[0]);
1090  MPV_Vs_Beta->SetBinError(j, FitResults[1]);
1091  delete Proj;
1092  }
1093 
1094  FILE* Gains = fopen(OutputGains.c_str(), "w");
1095  fprintf(Gains, "NEvents = %i\n", NEvent);
1096  fprintf(Gains, "Number of APVs = %lu\n", static_cast<unsigned long>(APVsColl.size()));
1097  fprintf(Gains, "GoodFits = %i BadFits = %i ratio = %f\n", GOOD, BAD, (100.0 * GOOD) / (GOOD + BAD));
1098  for (std::vector<stAPVGain*>::iterator it = APVsCollOrdered.begin(); it != APVsCollOrdered.end(); it++) {
1099  stAPVGain* APV = *it;
1100  fprintf(Gains,
1101  "%i | %i | PreviousGain = %7.5f NewGain = %7.5f\n",
1102  APV->DetId,
1103  APV->APVId,
1104  APV->PreviousGain,
1105  APV->Gain);
1106  }
1107 
1108  std::vector<int> DetIdOfBuggedAPV;
1109  fprintf(Gains, "----------------------------------------------------------------------\n");
1110  for (std::vector<stAPVGain*>::iterator it = APVsCollOrdered.begin(); it != APVsCollOrdered.end(); it++) {
1111  stAPVGain* APV = *it;
1112  if (APV->MPV > 0 && APV->MPV < 200) {
1113  bool tmpBug = false;
1114  for (unsigned int b = 0; b < DetIdOfBuggedAPV.size() && !tmpBug; b++) {
1115  if (DetIdOfBuggedAPV[b] == APV->DetId)
1116  tmpBug = true;
1117  }
1118  if (!tmpBug) {
1119  fprintf(Gains, "%i,\n", APV->DetId);
1120  DetIdOfBuggedAPV.push_back(APV->DetId);
1121  }
1122  }
1123  }
1124 
1125  fclose(Gains);
1126 
1127  // delete [] FitResults;
1128  // delete Proj;
1129  }
1130 
1131  dqmStore_->cd();
1133 }
1134 
1136  if ((strcmp(AlgoMode.c_str(), "MultiJob") != 0 && !FirstSetOfConstants) || Validation) {
1137  const auto gainHandle = iSetup.getHandle(gainToken_);
1138  if (!gainHandle.isValid()) {
1139  printf("\n#####################\n\nERROR --> gainHandle is not valid\n\n#####################\n\n");
1140  exit(0);
1141  }
1142 
1143  for (std::vector<stAPVGain*>::iterator it = APVsCollOrdered.begin(); it != APVsCollOrdered.end(); it++) {
1144  stAPVGain* APV = *it;
1145 
1146  if (gainHandle.isValid()) {
1147  SiStripApvGain::Range detGainRange = gainHandle->getRange(APV->DetId);
1148  APV->PreviousGain = *(detGainRange.first + APV->APVId);
1149  // APV_PrevGain->Fill(APV->Index,APV->PreviousGain);
1150  APV_PrevGain->SetBinContent(APV_PrevGain->GetXaxis()->FindBin(APV->Index), APV->PreviousGain);
1151  if (APV->PreviousGain < 0)
1152  APV->PreviousGain = 1;
1153  } else {
1154  printf("GAIN HANDLE IS NOT VALID\n");
1155  }
1156  }
1157  }
1158 }
1159 
1161  if (strcmp(AlgoMode.c_str(), "WriteOnDB") == 0)
1162  return;
1163 
1164  if (NEvent == 0) {
1165  SRun = iEvent.id().run();
1166  SEvent = iEvent.id().event();
1167  STimestamp = iEvent.time().value();
1168  }
1169  ERun = iEvent.id().run();
1170  EEvent = iEvent.id().event();
1171  ETimestamp = iEvent.time().value();
1172  NEvent++;
1173 
1174  iEvent_ = &iEvent;
1175 
1176  Handle<TrajTrackAssociationCollection> trajTrackAssociationHandle;
1177  iEvent.getByLabel(TrajToTrackProducer, TrajToTrackLabel, trajTrackAssociationHandle);
1178  const TrajTrackAssociationCollection TrajToTrackMap = *trajTrackAssociationHandle.product();
1179 
1180  for (TrajTrackAssociationCollection::const_iterator it = TrajToTrackMap.begin(); it != TrajToTrackMap.end(); ++it) {
1181  const Track track = *it->val;
1182  const Trajectory traj = *it->key;
1183 
1184  if (track.p() < MinTrackMomentum || track.p() > MaxTrackMomentum || track.eta() < MinTrackEta ||
1185  track.eta() > MaxTrackEta)
1186  continue;
1187 
1188  Tracks_Pt_Vs_Eta->Fill(fabs(track.eta()), track.pt());
1189  Tracks_P_Vs_Eta->Fill(fabs(track.eta()), track.p());
1190 
1191  //BEGIN TO COMPUTE NDOF FOR TRACKS NO IMPLEMENTED BEFORE 200pre3
1192  int ndof = 0;
1193  const Trajectory::RecHitContainer transRecHits = traj.recHits();
1194 
1195  for (Trajectory::RecHitContainer::const_iterator rechit = transRecHits.begin(); rechit != transRecHits.end();
1196  ++rechit)
1197  if ((*rechit)->isValid())
1198  ndof += (*rechit)->dimension();
1199  ndof -= 5;
1200  //END TO COMPUTE NDOF FOR TRACKS NO IMPLEMENTED BEFORE 200pre3
1201 
1202  HTrackChi2OverNDF->Fill(traj.chiSquared() / ndof);
1203  if (traj.chiSquared() / ndof > MaxTrackChiOverNdf)
1204  continue;
1205 
1206  vector<TrajectoryMeasurement> measurements = traj.measurements();
1207  HTrackHits->Fill(traj.foundHits());
1208  if (traj.foundHits() < (int)MinTrackHits)
1209  continue;
1210  /*
1211  //BEGIN TO COMPUTE #MATCHEDRECHIT IN THE TRACK
1212  int NMatchedHit = 0;
1213  for(vector<TrajectoryMeasurement>::const_iterator measurement_it = measurements.begin(); measurement_it!=measurements.end(); measurement_it++){
1214  TrajectoryStateOnSurface trajState = measurement_it->updatedState();
1215  if( !trajState.isValid() ) continue;
1216  const TrackingRecHit* hit = (*measurement_it->recHit()).hit();
1217  const SiStripMatchedRecHit2D* sistripmatchedhit = dynamic_cast<const SiStripMatchedRecHit2D*>(hit);
1218  if(sistripmatchedhit)NMatchedHit++;
1219 // NMatchedHit++;
1220 
1221  }
1222  //END TO COMPUTE #MATCHEDRECHIT IN THE TRACK
1223 
1224  if(NMatchedHit<2){
1225  printf("NOT ENOUGH MATCHED RECHITS : %i\n",NMatchedHit);
1226  continue;
1227  }
1228 */
1229 
1230  for (vector<TrajectoryMeasurement>::const_iterator measurement_it = measurements.begin();
1231  measurement_it != measurements.end();
1232  measurement_it++) {
1233  TrajectoryStateOnSurface trajState = measurement_it->updatedState();
1234  if (!trajState.isValid())
1235  continue;
1236 
1237  const TrackingRecHit* hit = (*measurement_it->recHit()).hit();
1238  const SiStripRecHit1D* sistripsimple1dhit = dynamic_cast<const SiStripRecHit1D*>(hit);
1239  const SiStripRecHit2D* sistripsimplehit = dynamic_cast<const SiStripRecHit2D*>(hit);
1240  const SiStripMatchedRecHit2D* sistripmatchedhit = dynamic_cast<const SiStripMatchedRecHit2D*>(hit);
1241 
1242  if (sistripsimplehit) {
1244  (sistripsimplehit->cluster()).get(), trajState, &iSetup, &track, traj.chiSquared() / ndof);
1245  } else if (sistripmatchedhit) {
1246  ComputeChargeOverPath(&sistripmatchedhit->monoCluster(), trajState, &iSetup, &track, traj.chiSquared() / ndof);
1248  &sistripmatchedhit->stereoCluster(), trajState, &iSetup, &track, traj.chiSquared() / ndof);
1249  } else if (sistripsimple1dhit) {
1251  (sistripsimple1dhit->cluster()).get(), trajState, &iSetup, &track, traj.chiSquared() / ndof);
1252  } else {
1253  }
1254  }
1255  }
1256 }
1257 
1259  TrajectoryStateOnSurface trajState,
1260  const edm::EventSetup* iSetup,
1261  const Track* track,
1262  double trajChi2OverN) {
1263  LocalVector trackDirection = trajState.localDirection();
1264  double cosine = trackDirection.z() / trackDirection.mag();
1265  auto const& Ampls = Cluster->amplitudes();
1266  uint32_t DetId = 0; // is 0 since long time Cluster->geographicalId();
1267  int FirstStrip = Cluster->firstStrip();
1268  int APVId = FirstStrip / 128;
1269  stAPVGain* APV = APVsColl[(DetId << 3) | APVId];
1270  int Saturation = 0;
1271  bool Overlaping = false;
1272  int Charge = 0;
1273  unsigned int NHighStrip = 0;
1274 
1275  if (!IsFarFromBorder(trajState, DetId, iSetup))
1276  return -1;
1277 
1278  if (FirstStrip == 0)
1279  Overlaping = true;
1280  if (FirstStrip == 128)
1281  Overlaping = true;
1282  if (FirstStrip == 256)
1283  Overlaping = true;
1284  if (FirstStrip == 384)
1285  Overlaping = true;
1286  if (FirstStrip == 512)
1287  Overlaping = true;
1288  if (FirstStrip == 640)
1289  Overlaping = true;
1290 
1291  if (FirstStrip <= 127 && FirstStrip + Ampls.size() > 127)
1292  Overlaping = true;
1293  if (FirstStrip <= 255 && FirstStrip + Ampls.size() > 255)
1294  Overlaping = true;
1295  if (FirstStrip <= 383 && FirstStrip + Ampls.size() > 383)
1296  Overlaping = true;
1297  if (FirstStrip <= 511 && FirstStrip + Ampls.size() > 511)
1298  Overlaping = true;
1299  if (FirstStrip <= 639 && FirstStrip + Ampls.size() > 639)
1300  Overlaping = true;
1301 
1302  if (FirstStrip + Ampls.size() == 127)
1303  Overlaping = true;
1304  if (FirstStrip + Ampls.size() == 255)
1305  Overlaping = true;
1306  if (FirstStrip + Ampls.size() == 383)
1307  Overlaping = true;
1308  if (FirstStrip + Ampls.size() == 511)
1309  Overlaping = true;
1310  if (FirstStrip + Ampls.size() == 639)
1311  Overlaping = true;
1312  if (FirstStrip + Ampls.size() == 767)
1313  Overlaping = true;
1314  if (Overlaping)
1315  return -1;
1316 
1317  /*
1318  if(FirstStrip==0 )Overlaping=true;
1319  if(FirstStrip<=255 && FirstStrip+Ampls.size()>255)Overlaping=true;
1320  if(FirstStrip<=511 && FirstStrip+Ampls.size()>511)Overlaping=true;
1321  if(FirstStrip+Ampls.size()==511 )Overlaping=true;
1322  if(FirstStrip+Ampls.size()==767 )Overlaping=true;
1323  if(Overlaping)return -1;
1324 */
1325 
1326  for (unsigned int a = 0; a < Ampls.size(); a++) {
1327  Charge += Ampls[a];
1328  if (Ampls[a] >= 254)
1329  Saturation++;
1330  if (Ampls[a] >= 20)
1331  NHighStrip++;
1332  }
1333  double path = (10.0 * APV->Thickness) / fabs(cosine);
1334  double ClusterChargeOverPath = (double)Charge / path;
1335 
1336  NSatStripInCluster->Fill(Saturation);
1337 
1338  if (Ampls.size() > MaxNrStrips)
1339  return -1;
1340  if (Saturation > 0 && !AllowSaturation)
1341  return -1;
1343  if (APV->Thickness < 0.04)
1345  if (APV->Thickness > 0.04)
1347  if (APV->SubDet == StripSubdetector::TIB)
1348  Charge_Vs_PathTIB->Fill(path, Charge);
1349  if (APV->SubDet == StripSubdetector::TID)
1350  Charge_Vs_PathTID->Fill(path, Charge);
1351  if (APV->SubDet == StripSubdetector::TOB)
1352  Charge_Vs_PathTOB->Fill(path, Charge);
1353  if (APV->SubDet == StripSubdetector::TEC) {
1354  Charge_Vs_PathTEC->Fill(path, Charge);
1355  if (APV->Thickness < 0.04)
1356  Charge_Vs_PathTEC1->Fill(path, Charge);
1357  if (APV->Thickness > 0.04)
1358  Charge_Vs_PathTEC2->Fill(path, Charge);
1359  }
1360 
1361  double trans = atan2(trackDirection.y(), trackDirection.x()) * (180 / 3.14159265);
1362  double alpha =
1363  acos(trackDirection.x() / sqrt(pow(trackDirection.x(), 2) + pow(trackDirection.z(), 2))) * (180 / 3.14159265);
1364  double beta =
1365  acos(trackDirection.y() / sqrt(pow(trackDirection.x(), 2) + pow(trackDirection.z(), 2))) * (180 / 3.14159265);
1366 
1367  if (path > 0.4 && path < 0.45) {
1368  Charge_Vs_TransversAngle->Fill(trans, Charge / path);
1369  Charge_Vs_Alpha->Fill(alpha, Charge / path);
1370  Charge_Vs_Beta->Fill(beta, Charge / path);
1371  }
1372 
1373  NStrips_Vs_TransversAngle->Fill(trans, Ampls.size());
1374  NStrips_Vs_Alpha->Fill(alpha, Ampls.size());
1375  NStrips_Vs_Beta->Fill(beta, Ampls.size());
1376 
1377  NHighStripInCluster->Fill(NHighStrip);
1378  // if(NHighStrip==1) Charge_Vs_PathLength_CS1->Fill(path, Charge );
1379  // if(NHighStrip==2) Charge_Vs_PathLength_CS2->Fill(path, Charge );
1380  // if(NHighStrip==3) Charge_Vs_PathLength_CS3->Fill(path, Charge );
1381  // if(NHighStrip==4) Charge_Vs_PathLength_CS4->Fill(path, Charge );
1382  // if(NHighStrip==5) Charge_Vs_PathLength_CS5->Fill(path, Charge );
1383 
1384  HFirstStrip->Fill(FirstStrip);
1385 
1386  if (Validation) {
1387  ClusterChargeOverPath = ClusterChargeOverPath / APV->PreviousGain;
1388  }
1389 
1390  APV_Charge->Fill(APV->Index, ClusterChargeOverPath);
1391  APV_Momentum->Fill(APV->Index, trajState.globalMomentum().mag());
1392  APV_PathLength->Fill(APV->Index, path);
1393 
1394  return ClusterChargeOverPath;
1395 }
1396 
1398  const uint32_t detid,
1399  const edm::EventSetup* iSetup) {
1400  const auto& tkGeom = iSetup->getData(tkGeomToken_);
1401 
1402  LocalPoint HitLocalPos = trajState.localPosition();
1403  LocalError HitLocalError = trajState.localError().positionError();
1404 
1405  const GeomDetUnit* it = tkGeom.idToDetUnit(DetId(detid));
1406  if (dynamic_cast<const StripGeomDetUnit*>(it) == nullptr && dynamic_cast<const PixelGeomDetUnit*>(it) == nullptr) {
1407  std::cout << "this detID doesn't seem to belong to the Tracker" << std::endl;
1408  return false;
1409  }
1410 
1411  const BoundPlane plane = it->surface();
1412  const TrapezoidalPlaneBounds* trapezoidalBounds(dynamic_cast<const TrapezoidalPlaneBounds*>(&(plane.bounds())));
1413  const RectangularPlaneBounds* rectangularBounds(dynamic_cast<const RectangularPlaneBounds*>(&(plane.bounds())));
1414 
1415  double DistFromBorder = 1.0;
1416  //double HalfWidth = it->surface().bounds().width() /2.0;
1417  double HalfLength;
1418 
1419  if (trapezoidalBounds) {
1420  std::array<const float, 4> const& parameters = (*trapezoidalBounds).parameters();
1421  HalfLength = parameters[3];
1422  //double t = (HalfLength + HitLocalPos.y()) / (2*HalfLength) ;
1423  //HalfWidth = parameters[0] + (parameters[1]-parameters[0]) * t;
1424  } else if (rectangularBounds) {
1425  //HalfWidth = it->surface().bounds().width() /2.0;
1426  HalfLength = it->surface().bounds().length() / 2.0;
1427  } else {
1428  return false;
1429  }
1430 
1431  // if (fabs(HitLocalPos.x())+HitLocalError.xx() >= (HalfWidth - DistFromBorder) ) return false;//Don't think is really necessary
1432  if (fabs(HitLocalPos.y()) + HitLocalError.yy() >= (HalfLength - DistFromBorder))
1433  return false;
1434 
1435  return true;
1436 }
1437 
1438 void SiStripGainFromData::getPeakOfLandau(TH1* InputHisto, double* FitResults, double LowRange, double HighRange) {
1439  double adcs = -0.5;
1440  double adcs_err = 0.;
1441  double width = -0.5;
1442  double width_err = 0;
1443  double chi2overndf = -0.5;
1444 
1445  double nr_of_entries = InputHisto->GetEntries();
1446 
1447  if ((unsigned int)nr_of_entries < MinNrEntries) {
1448  FitResults[0] = adcs;
1449  FitResults[1] = adcs_err;
1450  FitResults[2] = width;
1451  FitResults[3] = width_err;
1452  FitResults[4] = chi2overndf;
1453  return;
1454  }
1455 
1456  // perform fit with standard landau
1457  TF1* MyLandau = new TF1("MyLandau", "landau", LowRange, HighRange);
1458  MyLandau->SetParameter("MPV", 300);
1459 
1460  InputHisto->Fit(MyLandau, "QR WW");
1461 
1462  // MPV is parameter 1 (0=constant, 1=MPV, 2=Sigma)
1463  adcs = MyLandau->GetParameter("MPV");
1464  adcs_err = MyLandau->GetParError(1);
1465  width = MyLandau->GetParameter(2);
1466  width_err = MyLandau->GetParError(2);
1467  chi2overndf = MyLandau->GetChisquare() / MyLandau->GetNDF();
1468 
1469  // if still wrong, give up
1470  if (adcs < 2. || chi2overndf > MaxChi2OverNDF) {
1471  adcs = -0.5;
1472  adcs_err = 0.;
1473  width = -0.5;
1474  width_err = 0;
1475  chi2overndf = -0.5;
1476  }
1477 
1478  FitResults[0] = adcs;
1479  FitResults[1] = adcs_err;
1480  FitResults[2] = width;
1481  FitResults[3] = width_err;
1482  FitResults[4] = chi2overndf;
1483 
1484  delete MyLandau;
1485 }
1486 
1487 std::unique_ptr<SiStripApvGain> SiStripGainFromData::getNewObject() {
1488  cout << "START getNewObject\n";
1489 
1490  // if( !(strcmp(AlgoMode.c_str(),"WriteOnDB")==0 || strcmp(AlgoMode.c_str(),"SingleJob")==0) )return NULL;
1491  if (!(strcmp(AlgoMode.c_str(), "WriteOnDB") == 0 || strcmp(AlgoMode.c_str(), "SingleJob") == 0))
1492  return std::make_unique<SiStripApvGain>();
1493 
1494  auto obj = std::make_unique<SiStripApvGain>();
1495  std::vector<float>* theSiStripVector = nullptr;
1496  int PreviousDetId = -1;
1497  for (unsigned int a = 0; a < APVsCollOrdered.size(); a++) {
1499  if (APV == nullptr) {
1500  printf("Bug\n");
1501  continue;
1502  }
1503  if (APV->DetId != PreviousDetId) {
1504  if (theSiStripVector != nullptr) {
1505  SiStripApvGain::Range range(theSiStripVector->begin(), theSiStripVector->end());
1506  if (!obj->put(PreviousDetId, range))
1507  printf("Bug to put detId = %i\n", PreviousDetId);
1508  }
1509 
1510  theSiStripVector = new std::vector<float>;
1511  PreviousDetId = APV->DetId;
1512  }
1513  printf("%i | %i | PreviousGain = %7.5f NewGain = %7.5f\n", APV->DetId, APV->APVId, APV->PreviousGain, APV->Gain);
1514  if (theSiStripVector != nullptr) {
1515  theSiStripVector->push_back(APV->Gain);
1516  }
1517  // theSiStripVector->push_back(APV->Gain);
1518  }
1519 
1520  if (theSiStripVector != nullptr) {
1521  SiStripApvGain::Range range(theSiStripVector->begin(), theSiStripVector->end());
1522  if (!obj->put(PreviousDetId, range))
1523  printf("Bug to put detId = %i\n", PreviousDetId);
1524  }
1525 
1526  cout << "END getNewObject\n";
1527  return obj;
1528 }
1529 
edm::ESGetToken< SiStripGain, SiStripGainRcd > gainToken_
static constexpr auto TEC
virtual int nstrips() const =0
float alpha
Definition: AMPTWrapper.h:105
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void algoEndJob() override
uint16_t firstStrip() const
virtual float length() const =0
SiStripGainFromData(const edm::ParameterSet &)
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tkGeomToken_
const LocalTrajectoryError & localError() const
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken_
T z() const
Definition: PV3DBase.h:61
std::vector< stAPVGain * > APVsCollOrdered
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
unsigned int APVId
Definition: APVGainStruct.h:13
bool IsFarFromBorder(TrajectoryStateOnSurface trajState, const uint32_t detid, const edm::EventSetup *iSetup)
T const * product() const
Definition: Handle.h:70
dqm::legacy::MonitorElement MonitorElement
void algoBeginRun(const edm::Run &, const edm::EventSetup &) override
float chiSquared() const
Definition: Trajectory.h:241
bool operator()(const T &PseudoDetId1, const T &PseudoDetId2)
unsigned int DetId
Definition: APVGainStruct.h:12
LocalError positionError() const
int foundHits() const
Definition: Trajectory.h:206
const edm::EventSetup * iSetup_
ClusterRef cluster() const
dqm::legacy::DQMStore DQMStore
DataContainer const & measurements() const
Definition: Trajectory.h:178
const_iterator end() const
last iterator over the map (read only)
T getUntrackedParameter(std::string const &, T const &) const
virtual TH2F * getTH2F() const
float yy() const
Definition: LocalError.h:24
vector< string > VInputFiles
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
int iEvent
Definition: GenABIO.cc:224
std::unordered_map< unsigned int, stAPVGain * > APVsColl
SiStripCluster const & monoCluster() const
unsigned int tecSide(const DetId &id) const
SiStripCluster const & amplitudes() const
unsigned int Index
Definition: APVGainStruct.h:10
T sqrt(T t)
Definition: SSEVec.h:19
ConstRecHitContainer recHits() const
Definition: Trajectory.h:186
LocalVector localDirection() const
T mag() const
Definition: PV3DBase.h:64
std::pair< ContainerIterator, ContainerIterator > Range
const std::complex< double > I
Definition: I.h:8
double f[11][100]
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
bool getData(T &iHolder) const
Definition: EventSetup.h:122
double const GOOD
Definition: Constants.h:13
static constexpr auto TOB
void algoBeginJob(const edm::EventSetup &) override
unsigned long long TimeValue_t
Definition: Timestamp.h:28
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:151
Definition: DetId.h:17
double const BAD
Definition: Constants.h:15
ConstRecHitContainer RecHitContainer
Definition: Trajectory.h:42
static constexpr auto TIB
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
double ComputeChargeOverPath(const SiStripCluster *Cluster, TrajectoryStateOnSurface trajState, const edm::EventSetup *iSetup, const Track *track, double trajChi2OverN)
void algoAnalyze(const edm::Event &, const edm::EventSetup &) override
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
virtual TH1F * getTH1F() const
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:212
std::unique_ptr< SiStripApvGain > getNewObject() override
double b
Definition: hdecay.h:118
GlobalVector globalMomentum() const
SiStripCluster const & stereoCluster() const
void getPeakOfLandau(TH1 *InputHisto, double *FitResults, double LowRange=0, double HighRange=5400)
DQM_DEPRECATED void save(std::string const &filename, std::string const &path="")
Definition: DQMStore.cc:784
const_iterator begin() const
first iterator over the map (read only)
fixed size matrix
HLT enums.
double a
Definition: hdecay.h:119
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
long double T
ClusterRef cluster() const
static constexpr auto TID
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
const edm::Event * iEvent_
Definition: Run.h:45
def exit(msg="")
const Bounds & bounds() const
Definition: Surface.h:87