CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
584  if (SubDet == StripSubdetector::TIB || SubDet == StripSubdetector::TID || SubDet == StripSubdetector::TOB ||
585  SubDet == StripSubdetector::TEC) {
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 = MPVs->GetMean();
892  MPVmean = 300;
893  for (auto it = APVsColl.begin(); it != APVsColl.end(); it++) {
894  stAPVGain* APV = it->second;
895  if (APV->MPV > 0) {
896  APV->Gain = APV->MPV / MPVmean; // APV->MPV;
897  GOOD++;
898  } else {
899  NoMPV_Vs_EtaPhi->Fill(APV->Eta, APV->Phi);
900  APV->Gain = 1;
901  BAD++;
902  }
903  if (APV->Gain <= 0)
904  APV->Gain = 1;
905  APV_Gain->Fill(APV->Index, APV->Gain);
906 
907  if (!FirstSetOfConstants)
908  APV->Gain *= APV->PreviousGain;
909  APV_CumulGain->Fill(APV->Index, APV->Gain);
910  }
911 
912  for (int j = 0; j < Charge_Vs_PathLength->GetXaxis()->GetNbins(); j++) {
913  Proj = Charge_Vs_PathLength->ProjectionY(" ", j, j, "e");
914  getPeakOfLandau(Proj, FitResults);
915  if (FitResults[0] == -0.5)
916  continue;
917  MPV_Vs_PathLength->SetBinContent(j, FitResults[0] / Charge_Vs_PathLength->GetXaxis()->GetBinCenter(j));
918  MPV_Vs_PathLength->SetBinError(j, FitResults[1] / Charge_Vs_PathLength->GetXaxis()->GetBinCenter(j));
919  FWHM_Vs_PathLength->SetBinContent(
920  j, FitResults[2] / (FitResults[0] / Charge_Vs_PathLength->GetXaxis()->GetBinCenter(j)));
921  FWHM_Vs_PathLength->SetBinError(
922  j, FitResults[3] / (FitResults[0] / Charge_Vs_PathLength->GetXaxis()->GetBinCenter(j)));
923  delete Proj;
924  }
925 
926  for (int j = 0; j < Charge_Vs_PathLength320->GetXaxis()->GetNbins(); j++) {
927  Proj = Charge_Vs_PathLength320->ProjectionY(" ", j, j, "e");
928  getPeakOfLandau(Proj, FitResults);
929  if (FitResults[0] == -0.5)
930  continue;
931  MPV_Vs_PathLength320->SetBinContent(j, FitResults[0] / Charge_Vs_PathLength320->GetXaxis()->GetBinCenter(j));
932  MPV_Vs_PathLength320->SetBinError(j, FitResults[1] / Charge_Vs_PathLength320->GetXaxis()->GetBinCenter(j));
933  FWHM_Vs_PathLength320->SetBinContent(
934  j, FitResults[2] / (FitResults[0] / Charge_Vs_PathLength320->GetXaxis()->GetBinCenter(j)));
935  FWHM_Vs_PathLength320->SetBinError(
936  j, FitResults[3] / (FitResults[0] / Charge_Vs_PathLength320->GetXaxis()->GetBinCenter(j)));
937  delete Proj;
938  }
939 
940  for (int j = 0; j < Charge_Vs_PathLength500->GetXaxis()->GetNbins(); j++) {
941  Proj = Charge_Vs_PathLength500->ProjectionY(" ", j, j, "e");
942  getPeakOfLandau(Proj, FitResults);
943  if (FitResults[0] == -0.5)
944  continue;
945  MPV_Vs_PathLength500->SetBinContent(j, FitResults[0] / Charge_Vs_PathLength500->GetXaxis()->GetBinCenter(j));
946  MPV_Vs_PathLength500->SetBinError(j, FitResults[1] / Charge_Vs_PathLength500->GetXaxis()->GetBinCenter(j));
947  FWHM_Vs_PathLength500->SetBinContent(
948  j, FitResults[2] / (FitResults[0] / Charge_Vs_PathLength500->GetXaxis()->GetBinCenter(j)));
949  FWHM_Vs_PathLength500->SetBinError(
950  j, FitResults[3] / (FitResults[0] / Charge_Vs_PathLength500->GetXaxis()->GetBinCenter(j)));
951  delete Proj;
952  }
953  /*
954  for(int j=0;j<Charge_Vs_PathLength_CS1->GetXaxis()->GetNbins();j++){
955  Proj = Charge_Vs_PathLength_CS1->ProjectionY(" ",j,j,"e");
956  getPeakOfLandau(Proj,FitResults); if(FitResults[0] ==-0.5)continue;
957  MPV_Vs_PathLength_CS1->SetBinContent (j, FitResults[0]/Charge_Vs_PathLength_CS1->GetXaxis()->GetBinCenter(j));
958  MPV_Vs_PathLength_CS1->SetBinError (j, FitResults[1]/Charge_Vs_PathLength_CS1->GetXaxis()->GetBinCenter(j));
959  FWHM_Vs_PathLength_CS1->SetBinContent(j, FitResults[2]/(FitResults[0]/Charge_Vs_PathLength_CS1->GetXaxis()->GetBinCenter(j) ));
960  FWHM_Vs_PathLength_CS1->SetBinError (j, FitResults[3]/(FitResults[0]/Charge_Vs_PathLength_CS1->GetXaxis()->GetBinCenter(j) ));
961  delete Proj;
962  }
963 
964  for(int j=0;j<Charge_Vs_PathLength_CS2->GetXaxis()->GetNbins();j++){
965  Proj = Charge_Vs_PathLength_CS2->ProjectionY(" ",j,j,"e");
966  getPeakOfLandau(Proj,FitResults); if(FitResults[0] ==-0.5)continue;
967  MPV_Vs_PathLength_CS2->SetBinContent (j, FitResults[0]/Charge_Vs_PathLength_CS2->GetXaxis()->GetBinCenter(j));
968  MPV_Vs_PathLength_CS2->SetBinError (j, FitResults[1]/Charge_Vs_PathLength_CS2->GetXaxis()->GetBinCenter(j));
969  FWHM_Vs_PathLength_CS2->SetBinContent(j, FitResults[2]/(FitResults[0]/Charge_Vs_PathLength_CS2->GetXaxis()->GetBinCenter(j) ));
970  FWHM_Vs_PathLength_CS2->SetBinError (j, FitResults[3]/(FitResults[0]/Charge_Vs_PathLength_CS2->GetXaxis()->GetBinCenter(j) ));
971  delete Proj;
972  }
973 
974  for(int j=0;j<Charge_Vs_PathLength_CS3->GetXaxis()->GetNbins();j++){
975  Proj = Charge_Vs_PathLength_CS3->ProjectionY(" ",j,j,"e");
976  getPeakOfLandau(Proj,FitResults); if(FitResults[0] ==-0.5)continue;
977  MPV_Vs_PathLength_CS3->SetBinContent (j, FitResults[0]/Charge_Vs_PathLength_CS3->GetXaxis()->GetBinCenter(j));
978  MPV_Vs_PathLength_CS3->SetBinError (j, FitResults[1]/Charge_Vs_PathLength_CS3->GetXaxis()->GetBinCenter(j));
979  FWHM_Vs_PathLength_CS3->SetBinContent(j, FitResults[2]/(FitResults[0]/Charge_Vs_PathLength_CS3->GetXaxis()->GetBinCenter(j) ));
980  FWHM_Vs_PathLength_CS3->SetBinError (j, FitResults[3]/(FitResults[0]/Charge_Vs_PathLength_CS3->GetXaxis()->GetBinCenter(j) ));
981  delete Proj;
982  }
983 
984  for(int j=0;j<Charge_Vs_PathLength_CS4->GetXaxis()->GetNbins();j++){
985  Proj = Charge_Vs_PathLength_CS4->ProjectionY(" ",j,j,"e");
986  getPeakOfLandau(Proj,FitResults); if(FitResults[0] ==-0.5)continue;
987  MPV_Vs_PathLength_CS4->SetBinContent (j, FitResults[0]/Charge_Vs_PathLength_CS4->GetXaxis()->GetBinCenter(j));
988  MPV_Vs_PathLength_CS4->SetBinError (j, FitResults[1]/Charge_Vs_PathLength_CS4->GetXaxis()->GetBinCenter(j));
989  FWHM_Vs_PathLength_CS4->SetBinContent(j, FitResults[2]/(FitResults[0]/Charge_Vs_PathLength_CS4->GetXaxis()->GetBinCenter(j) ));
990  FWHM_Vs_PathLength_CS4->SetBinError (j, FitResults[3]/(FitResults[0]/Charge_Vs_PathLength_CS4->GetXaxis()->GetBinCenter(j) ));
991  delete Proj;
992  }
993 
994  for(int j=0;j<Charge_Vs_PathLength_CS5->GetXaxis()->GetNbins();j++){
995  Proj = Charge_Vs_PathLength_CS5->ProjectionY(" ",j,j,"e");
996  getPeakOfLandau(Proj,FitResults); if(FitResults[0] ==-0.5)continue;
997  MPV_Vs_PathLength_CS5->SetBinContent (j, FitResults[0]/Charge_Vs_PathLength_CS5->GetXaxis()->GetBinCenter(j));
998  MPV_Vs_PathLength_CS5->SetBinError (j, FitResults[1]/Charge_Vs_PathLength_CS5->GetXaxis()->GetBinCenter(j));
999  FWHM_Vs_PathLength_CS5->SetBinContent(j, FitResults[2]/(FitResults[0]/Charge_Vs_PathLength_CS5->GetXaxis()->GetBinCenter(j) ));
1000  FWHM_Vs_PathLength_CS5->SetBinError (j, FitResults[3]/(FitResults[0]/Charge_Vs_PathLength_CS5->GetXaxis()->GetBinCenter(j) ));
1001  delete Proj;
1002  }
1003 */
1004 
1005  for (int j = 0; j < Charge_Vs_PathTIB->GetXaxis()->GetNbins(); j++) {
1006  Proj = Charge_Vs_PathTIB->ProjectionY(" ", j, j, "e");
1007  getPeakOfLandau(Proj, FitResults);
1008  if (FitResults[0] == -0.5)
1009  continue;
1010  MPV_Vs_PathTIB->SetBinContent(j, FitResults[0] / Charge_Vs_PathTIB->GetXaxis()->GetBinCenter(j));
1011  MPV_Vs_PathTIB->SetBinError(j, FitResults[1] / Charge_Vs_PathTIB->GetXaxis()->GetBinCenter(j));
1012  delete Proj;
1013  }
1014 
1015  for (int j = 0; j < Charge_Vs_PathTID->GetXaxis()->GetNbins(); j++) {
1016  Proj = Charge_Vs_PathTID->ProjectionY(" ", j, j, "e");
1017  getPeakOfLandau(Proj, FitResults);
1018  if (FitResults[0] == -0.5)
1019  continue;
1020  MPV_Vs_PathTID->SetBinContent(j, FitResults[0] / Charge_Vs_PathTID->GetXaxis()->GetBinCenter(j));
1021  MPV_Vs_PathTID->SetBinError(j, FitResults[1] / Charge_Vs_PathTID->GetXaxis()->GetBinCenter(j));
1022  delete Proj;
1023  }
1024 
1025  for (int j = 0; j < Charge_Vs_PathTOB->GetXaxis()->GetNbins(); j++) {
1026  Proj = Charge_Vs_PathTOB->ProjectionY(" ", j, j, "e");
1027  getPeakOfLandau(Proj, FitResults);
1028  if (FitResults[0] == -0.5)
1029  continue;
1030  MPV_Vs_PathTOB->SetBinContent(j, FitResults[0] / Charge_Vs_PathTOB->GetXaxis()->GetBinCenter(j));
1031  MPV_Vs_PathTOB->SetBinError(j, FitResults[1] / Charge_Vs_PathTOB->GetXaxis()->GetBinCenter(j));
1032  delete Proj;
1033  }
1034 
1035  for (int j = 0; j < Charge_Vs_PathTEC->GetXaxis()->GetNbins(); j++) {
1036  Proj = Charge_Vs_PathTEC->ProjectionY(" ", j, j, "e");
1037  getPeakOfLandau(Proj, FitResults);
1038  if (FitResults[0] == -0.5)
1039  continue;
1040  MPV_Vs_PathTEC->SetBinContent(j, FitResults[0] / Charge_Vs_PathTEC->GetXaxis()->GetBinCenter(j));
1041  MPV_Vs_PathTEC->SetBinError(j, FitResults[1] / Charge_Vs_PathTEC->GetXaxis()->GetBinCenter(j));
1042  delete Proj;
1043  }
1044 
1045  for (int j = 0; j < Charge_Vs_PathTEC1->GetXaxis()->GetNbins(); j++) {
1046  Proj = Charge_Vs_PathTEC1->ProjectionY(" ", j, j, "e");
1047  getPeakOfLandau(Proj, FitResults);
1048  if (FitResults[0] == -0.5)
1049  continue;
1050  MPV_Vs_PathTEC1->SetBinContent(j, FitResults[0] / Charge_Vs_PathTEC1->GetXaxis()->GetBinCenter(j));
1051  MPV_Vs_PathTEC1->SetBinError(j, FitResults[1] / Charge_Vs_PathTEC1->GetXaxis()->GetBinCenter(j));
1052  delete Proj;
1053  }
1054 
1055  for (int j = 0; j < Charge_Vs_PathTEC2->GetXaxis()->GetNbins(); j++) {
1056  Proj = Charge_Vs_PathTEC2->ProjectionY(" ", j, j, "e");
1057  getPeakOfLandau(Proj, FitResults);
1058  if (FitResults[0] == -0.5)
1059  continue;
1060  MPV_Vs_PathTEC2->SetBinContent(j, FitResults[0] / Charge_Vs_PathTEC2->GetXaxis()->GetBinCenter(j));
1061  MPV_Vs_PathTEC2->SetBinError(j, FitResults[1] / Charge_Vs_PathTEC2->GetXaxis()->GetBinCenter(j));
1062  delete Proj;
1063  }
1064 
1065  for (int j = 1; j < Charge_Vs_TransversAngle->GetXaxis()->GetNbins(); j++) {
1066  Proj = Charge_Vs_TransversAngle->ProjectionY(" ", j, j, "e");
1067  getPeakOfLandau(Proj, FitResults);
1068  if (FitResults[0] == -0.5)
1069  continue;
1070  MPV_Vs_TransversAngle->SetBinContent(j, FitResults[0]);
1071  MPV_Vs_TransversAngle->SetBinError(j, FitResults[1]);
1072  delete Proj;
1073  }
1074 
1075  for (int j = 1; j < Charge_Vs_Alpha->GetXaxis()->GetNbins(); j++) {
1076  Proj = Charge_Vs_Alpha->ProjectionY(" ", j, j, "e");
1077  getPeakOfLandau(Proj, FitResults);
1078  if (FitResults[0] == -0.5)
1079  continue;
1080  MPV_Vs_Alpha->SetBinContent(j, FitResults[0]);
1081  MPV_Vs_Alpha->SetBinError(j, FitResults[1]);
1082  delete Proj;
1083  }
1084 
1085  for (int j = 1; j < Charge_Vs_Beta->GetXaxis()->GetNbins(); j++) {
1086  Proj = Charge_Vs_Beta->ProjectionY(" ", j, j, "e");
1087  getPeakOfLandau(Proj, FitResults);
1088  if (FitResults[0] == -0.5)
1089  continue;
1090  MPV_Vs_Beta->SetBinContent(j, FitResults[0]);
1091  MPV_Vs_Beta->SetBinError(j, FitResults[1]);
1092  delete Proj;
1093  }
1094 
1095  FILE* Gains = fopen(OutputGains.c_str(), "w");
1096  fprintf(Gains, "NEvents = %i\n", NEvent);
1097  fprintf(Gains, "Number of APVs = %lu\n", static_cast<unsigned long>(APVsColl.size()));
1098  fprintf(Gains, "GoodFits = %i BadFits = %i ratio = %f\n", GOOD, BAD, (100.0 * GOOD) / (GOOD + BAD));
1099  for (std::vector<stAPVGain*>::iterator it = APVsCollOrdered.begin(); it != APVsCollOrdered.end(); it++) {
1100  stAPVGain* APV = *it;
1101  fprintf(Gains,
1102  "%i | %i | PreviousGain = %7.5f NewGain = %7.5f\n",
1103  APV->DetId,
1104  APV->APVId,
1105  APV->PreviousGain,
1106  APV->Gain);
1107  }
1108 
1109  std::vector<int> DetIdOfBuggedAPV;
1110  fprintf(Gains, "----------------------------------------------------------------------\n");
1111  for (std::vector<stAPVGain*>::iterator it = APVsCollOrdered.begin(); it != APVsCollOrdered.end(); it++) {
1112  stAPVGain* APV = *it;
1113  if (APV->MPV > 0 && APV->MPV < 200) {
1114  bool tmpBug = false;
1115  for (unsigned int b = 0; b < DetIdOfBuggedAPV.size() && !tmpBug; b++) {
1116  if (DetIdOfBuggedAPV[b] == APV->DetId)
1117  tmpBug = true;
1118  }
1119  if (!tmpBug) {
1120  fprintf(Gains, "%i,\n", APV->DetId);
1121  DetIdOfBuggedAPV.push_back(APV->DetId);
1122  }
1123  }
1124  }
1125 
1126  fclose(Gains);
1127 
1128  // delete [] FitResults;
1129  // delete Proj;
1130  }
1131 
1132  dqmStore_->cd();
1134 }
1135 
1137  if ((strcmp(AlgoMode.c_str(), "MultiJob") != 0 && !FirstSetOfConstants) || Validation) {
1138  const auto gainHandle = iSetup.getHandle(gainToken_);
1139  if (!gainHandle.isValid()) {
1140  printf("\n#####################\n\nERROR --> gainHandle is not valid\n\n#####################\n\n");
1141  exit(0);
1142  }
1143 
1144  for (std::vector<stAPVGain*>::iterator it = APVsCollOrdered.begin(); it != APVsCollOrdered.end(); it++) {
1145  stAPVGain* APV = *it;
1146 
1147  if (gainHandle.isValid()) {
1148  SiStripApvGain::Range detGainRange = gainHandle->getRange(APV->DetId);
1149  APV->PreviousGain = *(detGainRange.first + APV->APVId);
1150  // APV_PrevGain->Fill(APV->Index,APV->PreviousGain);
1151  APV_PrevGain->SetBinContent(APV_PrevGain->GetXaxis()->FindBin(APV->Index), APV->PreviousGain);
1152  if (APV->PreviousGain < 0)
1153  APV->PreviousGain = 1;
1154  } else {
1155  printf("GAIN HANDLE IS NOT VALID\n");
1156  }
1157  }
1158  }
1159 }
1160 
1162  if (strcmp(AlgoMode.c_str(), "WriteOnDB") == 0)
1163  return;
1164 
1165  if (NEvent == 0) {
1166  SRun = iEvent.id().run();
1167  SEvent = iEvent.id().event();
1168  STimestamp = iEvent.time().value();
1169  }
1170  ERun = iEvent.id().run();
1171  EEvent = iEvent.id().event();
1172  ETimestamp = iEvent.time().value();
1173  NEvent++;
1174 
1175  iEvent_ = &iEvent;
1176 
1177  Handle<TrajTrackAssociationCollection> trajTrackAssociationHandle;
1178  iEvent.getByLabel(TrajToTrackProducer, TrajToTrackLabel, trajTrackAssociationHandle);
1179  const TrajTrackAssociationCollection TrajToTrackMap = *trajTrackAssociationHandle.product();
1180 
1181  for (TrajTrackAssociationCollection::const_iterator it = TrajToTrackMap.begin(); it != TrajToTrackMap.end(); ++it) {
1182  const Track track = *it->val;
1183  const Trajectory traj = *it->key;
1184 
1185  if (track.p() < MinTrackMomentum || track.p() > MaxTrackMomentum || track.eta() < MinTrackEta ||
1186  track.eta() > MaxTrackEta)
1187  continue;
1188 
1189  Tracks_Pt_Vs_Eta->Fill(fabs(track.eta()), track.pt());
1190  Tracks_P_Vs_Eta->Fill(fabs(track.eta()), track.p());
1191 
1192  //BEGIN TO COMPUTE NDOF FOR TRACKS NO IMPLEMENTED BEFORE 200pre3
1193  int ndof = 0;
1194  const Trajectory::RecHitContainer transRecHits = traj.recHits();
1195 
1196  for (Trajectory::RecHitContainer::const_iterator rechit = transRecHits.begin(); rechit != transRecHits.end();
1197  ++rechit)
1198  if ((*rechit)->isValid())
1199  ndof += (*rechit)->dimension();
1200  ndof -= 5;
1201  //END TO COMPUTE NDOF FOR TRACKS NO IMPLEMENTED BEFORE 200pre3
1202 
1203  HTrackChi2OverNDF->Fill(traj.chiSquared() / ndof);
1204  if (traj.chiSquared() / ndof > MaxTrackChiOverNdf)
1205  continue;
1206 
1207  vector<TrajectoryMeasurement> measurements = traj.measurements();
1208  HTrackHits->Fill(traj.foundHits());
1209  if (traj.foundHits() < (int)MinTrackHits)
1210  continue;
1211  /*
1212  //BEGIN TO COMPUTE #MATCHEDRECHIT IN THE TRACK
1213  int NMatchedHit = 0;
1214  for(vector<TrajectoryMeasurement>::const_iterator measurement_it = measurements.begin(); measurement_it!=measurements.end(); measurement_it++){
1215  TrajectoryStateOnSurface trajState = measurement_it->updatedState();
1216  if( !trajState.isValid() ) continue;
1217  const TrackingRecHit* hit = (*measurement_it->recHit()).hit();
1218  const SiStripMatchedRecHit2D* sistripmatchedhit = dynamic_cast<const SiStripMatchedRecHit2D*>(hit);
1219  if(sistripmatchedhit)NMatchedHit++;
1220 // NMatchedHit++;
1221 
1222  }
1223  //END TO COMPUTE #MATCHEDRECHIT IN THE TRACK
1224 
1225  if(NMatchedHit<2){
1226  printf("NOT ENOUGH MATCHED RECHITS : %i\n",NMatchedHit);
1227  continue;
1228  }
1229 */
1230 
1231  for (vector<TrajectoryMeasurement>::const_iterator measurement_it = measurements.begin();
1232  measurement_it != measurements.end();
1233  measurement_it++) {
1234  TrajectoryStateOnSurface trajState = measurement_it->updatedState();
1235  if (!trajState.isValid())
1236  continue;
1237 
1238  const TrackingRecHit* hit = (*measurement_it->recHit()).hit();
1239  const SiStripRecHit1D* sistripsimple1dhit = dynamic_cast<const SiStripRecHit1D*>(hit);
1240  const SiStripRecHit2D* sistripsimplehit = dynamic_cast<const SiStripRecHit2D*>(hit);
1241  const SiStripMatchedRecHit2D* sistripmatchedhit = dynamic_cast<const SiStripMatchedRecHit2D*>(hit);
1242 
1243  if (sistripsimplehit) {
1245  (sistripsimplehit->cluster()).get(), trajState, &iSetup, &track, traj.chiSquared() / ndof);
1246  } else if (sistripmatchedhit) {
1247  ComputeChargeOverPath(&sistripmatchedhit->monoCluster(), trajState, &iSetup, &track, traj.chiSquared() / ndof);
1249  &sistripmatchedhit->stereoCluster(), trajState, &iSetup, &track, traj.chiSquared() / ndof);
1250  } else if (sistripsimple1dhit) {
1252  (sistripsimple1dhit->cluster()).get(), trajState, &iSetup, &track, traj.chiSquared() / ndof);
1253  } else {
1254  }
1255  }
1256  }
1257 }
1258 
1260  TrajectoryStateOnSurface trajState,
1261  const edm::EventSetup* iSetup,
1262  const Track* track,
1263  double trajChi2OverN) {
1264  LocalVector trackDirection = trajState.localDirection();
1265  double cosine = trackDirection.z() / trackDirection.mag();
1266  auto const& Ampls = Cluster->amplitudes();
1267  uint32_t DetId = 0; // is 0 since long time Cluster->geographicalId();
1268  int FirstStrip = Cluster->firstStrip();
1269  int APVId = FirstStrip / 128;
1270  stAPVGain* APV = APVsColl[(DetId << 3) | APVId];
1271  int Saturation = 0;
1272  bool Overlaping = false;
1273  int Charge = 0;
1274  unsigned int NHighStrip = 0;
1275 
1276  if (!IsFarFromBorder(trajState, DetId, iSetup))
1277  return -1;
1278 
1279  if (FirstStrip == 0)
1280  Overlaping = true;
1281  if (FirstStrip == 128)
1282  Overlaping = true;
1283  if (FirstStrip == 256)
1284  Overlaping = true;
1285  if (FirstStrip == 384)
1286  Overlaping = true;
1287  if (FirstStrip == 512)
1288  Overlaping = true;
1289  if (FirstStrip == 640)
1290  Overlaping = true;
1291 
1292  if (FirstStrip <= 127 && FirstStrip + Ampls.size() > 127)
1293  Overlaping = true;
1294  if (FirstStrip <= 255 && FirstStrip + Ampls.size() > 255)
1295  Overlaping = true;
1296  if (FirstStrip <= 383 && FirstStrip + Ampls.size() > 383)
1297  Overlaping = true;
1298  if (FirstStrip <= 511 && FirstStrip + Ampls.size() > 511)
1299  Overlaping = true;
1300  if (FirstStrip <= 639 && FirstStrip + Ampls.size() > 639)
1301  Overlaping = true;
1302 
1303  if (FirstStrip + Ampls.size() == 127)
1304  Overlaping = true;
1305  if (FirstStrip + Ampls.size() == 255)
1306  Overlaping = true;
1307  if (FirstStrip + Ampls.size() == 383)
1308  Overlaping = true;
1309  if (FirstStrip + Ampls.size() == 511)
1310  Overlaping = true;
1311  if (FirstStrip + Ampls.size() == 639)
1312  Overlaping = true;
1313  if (FirstStrip + Ampls.size() == 767)
1314  Overlaping = true;
1315  if (Overlaping)
1316  return -1;
1317 
1318  /*
1319  if(FirstStrip==0 )Overlaping=true;
1320  if(FirstStrip<=255 && FirstStrip+Ampls.size()>255)Overlaping=true;
1321  if(FirstStrip<=511 && FirstStrip+Ampls.size()>511)Overlaping=true;
1322  if(FirstStrip+Ampls.size()==511 )Overlaping=true;
1323  if(FirstStrip+Ampls.size()==767 )Overlaping=true;
1324  if(Overlaping)return -1;
1325 */
1326 
1327  for (unsigned int a = 0; a < Ampls.size(); a++) {
1328  Charge += Ampls[a];
1329  if (Ampls[a] >= 254)
1330  Saturation++;
1331  if (Ampls[a] >= 20)
1332  NHighStrip++;
1333  }
1334  double path = (10.0 * APV->Thickness) / fabs(cosine);
1335  double ClusterChargeOverPath = (double)Charge / path;
1336 
1337  NSatStripInCluster->Fill(Saturation);
1338 
1339  if (Ampls.size() > MaxNrStrips)
1340  return -1;
1341  if (Saturation > 0 && !AllowSaturation)
1342  return -1;
1343  Charge_Vs_PathLength->Fill(path, Charge);
1344  if (APV->Thickness < 0.04)
1345  Charge_Vs_PathLength320->Fill(path, Charge);
1346  if (APV->Thickness > 0.04)
1347  Charge_Vs_PathLength500->Fill(path, Charge);
1348  if (APV->SubDet == StripSubdetector::TIB)
1349  Charge_Vs_PathTIB->Fill(path, Charge);
1350  if (APV->SubDet == StripSubdetector::TID)
1351  Charge_Vs_PathTID->Fill(path, Charge);
1352  if (APV->SubDet == StripSubdetector::TOB)
1353  Charge_Vs_PathTOB->Fill(path, Charge);
1354  if (APV->SubDet == StripSubdetector::TEC) {
1355  Charge_Vs_PathTEC->Fill(path, Charge);
1356  if (APV->Thickness < 0.04)
1357  Charge_Vs_PathTEC1->Fill(path, Charge);
1358  if (APV->Thickness > 0.04)
1359  Charge_Vs_PathTEC2->Fill(path, Charge);
1360  }
1361 
1362  double trans = atan2(trackDirection.y(), trackDirection.x()) * (180 / 3.14159265);
1363  double alpha =
1364  acos(trackDirection.x() / sqrt(pow(trackDirection.x(), 2) + pow(trackDirection.z(), 2))) * (180 / 3.14159265);
1365  double beta =
1366  acos(trackDirection.y() / sqrt(pow(trackDirection.x(), 2) + pow(trackDirection.z(), 2))) * (180 / 3.14159265);
1367 
1368  if (path > 0.4 && path < 0.45) {
1369  Charge_Vs_TransversAngle->Fill(trans, Charge / path);
1370  Charge_Vs_Alpha->Fill(alpha, Charge / path);
1371  Charge_Vs_Beta->Fill(beta, Charge / path);
1372  }
1373 
1374  NStrips_Vs_TransversAngle->Fill(trans, Ampls.size());
1375  NStrips_Vs_Alpha->Fill(alpha, Ampls.size());
1376  NStrips_Vs_Beta->Fill(beta, Ampls.size());
1377 
1378  NHighStripInCluster->Fill(NHighStrip);
1379  // if(NHighStrip==1) Charge_Vs_PathLength_CS1->Fill(path, Charge );
1380  // if(NHighStrip==2) Charge_Vs_PathLength_CS2->Fill(path, Charge );
1381  // if(NHighStrip==3) Charge_Vs_PathLength_CS3->Fill(path, Charge );
1382  // if(NHighStrip==4) Charge_Vs_PathLength_CS4->Fill(path, Charge );
1383  // if(NHighStrip==5) Charge_Vs_PathLength_CS5->Fill(path, Charge );
1384 
1385  HFirstStrip->Fill(FirstStrip);
1386 
1387  if (Validation) {
1388  ClusterChargeOverPath = ClusterChargeOverPath / APV->PreviousGain;
1389  }
1390 
1391  APV_Charge->Fill(APV->Index, ClusterChargeOverPath);
1392  APV_Momentum->Fill(APV->Index, trajState.globalMomentum().mag());
1393  APV_PathLength->Fill(APV->Index, path);
1394 
1395  return ClusterChargeOverPath;
1396 }
1397 
1399  const uint32_t detid,
1400  const edm::EventSetup* iSetup) {
1401  const auto& tkGeom = iSetup->getData(tkGeomToken_);
1402 
1403  LocalPoint HitLocalPos = trajState.localPosition();
1404  LocalError HitLocalError = trajState.localError().positionError();
1405 
1406  const GeomDetUnit* it = tkGeom.idToDetUnit(DetId(detid));
1407  if (dynamic_cast<const StripGeomDetUnit*>(it) == nullptr && dynamic_cast<const PixelGeomDetUnit*>(it) == nullptr) {
1408  std::cout << "this detID doesn't seem to belong to the Tracker" << std::endl;
1409  return false;
1410  }
1411 
1412  const BoundPlane plane = it->surface();
1413  const TrapezoidalPlaneBounds* trapezoidalBounds(dynamic_cast<const TrapezoidalPlaneBounds*>(&(plane.bounds())));
1414  const RectangularPlaneBounds* rectangularBounds(dynamic_cast<const RectangularPlaneBounds*>(&(plane.bounds())));
1415 
1416  double DistFromBorder = 1.0;
1417  //double HalfWidth = it->surface().bounds().width() /2.0;
1418  double HalfLength = it->surface().bounds().length() / 2.0;
1419 
1420  if (trapezoidalBounds) {
1421  std::array<const float, 4> const& parameters = (*trapezoidalBounds).parameters();
1422  HalfLength = parameters[3];
1423  //double t = (HalfLength + HitLocalPos.y()) / (2*HalfLength) ;
1424  //HalfWidth = parameters[0] + (parameters[1]-parameters[0]) * t;
1425  } else if (rectangularBounds) {
1426  //HalfWidth = it->surface().bounds().width() /2.0;
1427  HalfLength = it->surface().bounds().length() / 2.0;
1428  } else {
1429  return false;
1430  }
1431 
1432  // if (fabs(HitLocalPos.x())+HitLocalError.xx() >= (HalfWidth - DistFromBorder) ) return false;//Don't think is really necessary
1433  if (fabs(HitLocalPos.y()) + HitLocalError.yy() >= (HalfLength - DistFromBorder))
1434  return false;
1435 
1436  return true;
1437 }
1438 
1439 void SiStripGainFromData::getPeakOfLandau(TH1* InputHisto, double* FitResults, double LowRange, double HighRange) {
1440  double adcs = -0.5;
1441  double adcs_err = 0.;
1442  double width = -0.5;
1443  double width_err = 0;
1444  double chi2overndf = -0.5;
1445 
1446  double nr_of_entries = InputHisto->GetEntries();
1447 
1448  if ((unsigned int)nr_of_entries < MinNrEntries) {
1449  FitResults[0] = adcs;
1450  FitResults[1] = adcs_err;
1451  FitResults[2] = width;
1452  FitResults[3] = width_err;
1453  FitResults[4] = chi2overndf;
1454  return;
1455  }
1456 
1457  // perform fit with standard landau
1458  TF1* MyLandau = new TF1("MyLandau", "landau", LowRange, HighRange);
1459  MyLandau->SetParameter("MPV", 300);
1460 
1461  InputHisto->Fit(MyLandau, "QR WW");
1462 
1463  // MPV is parameter 1 (0=constant, 1=MPV, 2=Sigma)
1464  adcs = MyLandau->GetParameter("MPV");
1465  adcs_err = MyLandau->GetParError(1);
1466  width = MyLandau->GetParameter(2);
1467  width_err = MyLandau->GetParError(2);
1468  chi2overndf = MyLandau->GetChisquare() / MyLandau->GetNDF();
1469 
1470  // if still wrong, give up
1471  if (adcs < 2. || chi2overndf > MaxChi2OverNDF) {
1472  adcs = -0.5;
1473  adcs_err = 0.;
1474  width = -0.5;
1475  width_err = 0;
1476  chi2overndf = -0.5;
1477  }
1478 
1479  FitResults[0] = adcs;
1480  FitResults[1] = adcs_err;
1481  FitResults[2] = width;
1482  FitResults[3] = width_err;
1483  FitResults[4] = chi2overndf;
1484 
1485  delete MyLandau;
1486 }
1487 
1488 std::unique_ptr<SiStripApvGain> SiStripGainFromData::getNewObject() {
1489  cout << "START getNewObject\n";
1490 
1491  // if( !(strcmp(AlgoMode.c_str(),"WriteOnDB")==0 || strcmp(AlgoMode.c_str(),"SingleJob")==0) )return NULL;
1492  if (!(strcmp(AlgoMode.c_str(), "WriteOnDB") == 0 || strcmp(AlgoMode.c_str(), "SingleJob") == 0))
1493  return std::make_unique<SiStripApvGain>();
1494 
1495  auto obj = std::make_unique<SiStripApvGain>();
1496  std::vector<float>* theSiStripVector = nullptr;
1497  int PreviousDetId = -1;
1498  for (unsigned int a = 0; a < APVsCollOrdered.size(); a++) {
1500  if (APV == nullptr) {
1501  printf("Bug\n");
1502  continue;
1503  }
1504  if (APV->DetId != PreviousDetId) {
1505  if (theSiStripVector != nullptr) {
1506  SiStripApvGain::Range range(theSiStripVector->begin(), theSiStripVector->end());
1507  if (!obj->put(PreviousDetId, range))
1508  printf("Bug to put detId = %i\n", PreviousDetId);
1509  }
1510 
1511  theSiStripVector = new std::vector<float>;
1512  PreviousDetId = APV->DetId;
1513  }
1514  printf("%i | %i | PreviousGain = %7.5f NewGain = %7.5f\n", APV->DetId, APV->APVId, APV->PreviousGain, APV->Gain);
1515  theSiStripVector->push_back(APV->Gain);
1516  // theSiStripVector->push_back(APV->Gain);
1517  }
1518 
1519  if (theSiStripVector != nullptr) {
1520  SiStripApvGain::Range range(theSiStripVector->begin(), theSiStripVector->end());
1521  if (!obj->put(PreviousDetId, range))
1522  printf("Bug to put detId = %i\n", PreviousDetId);
1523  }
1524 
1525  cout << "END getNewObject\n";
1526  return obj;
1527 }
1528 
edm::ESGetToken< SiStripGain, SiStripGainRcd > gainToken_
RunNumber_t run() const
Definition: EventID.h:38
ClusterRef cluster() const
double p() const
momentum vector magnitude
Definition: TrackBase.h:631
bool IsFarFromBorder(const TrajectoryStateOnSurface &trajState, const GeomDetUnit *it)
Definition: DeDxTools.cc:426
EventNumber_t event() const
Definition: EventID.h:40
static constexpr auto TEC
virtual int nstrips() const =0
int foundHits() const
Definition: Trajectory.h:206
T getUntrackedParameter(std::string const &, T const &) const
float alpha
Definition: AMPTWrapper.h:105
virtual TH2F * getTH2F() const
void algoEndJob() override
virtual float length() const =0
SiStripGainFromData(const edm::ParameterSet &)
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tkGeomToken_
tuple SubDet
Definition: ntupleEnum.py:14
const_iterator end() const
last iterator over the map (read only)
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken_
std::vector< stAPVGain * > APVsCollOrdered
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
SiStripCluster const & monoCluster() const
LocalVector localDirection() const
unsigned int APVId
Definition: APVGainStruct.h:11
virtual TH1F * getTH1F() const
float Thickness
Definition: APVGainStruct.h:19
SiStripCluster const & amplitudes() const
bool IsFarFromBorder(TrajectoryStateOnSurface trajState, const uint32_t detid, const edm::EventSetup *iSetup)
dqm::legacy::MonitorElement MonitorElement
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
T y() const
Definition: PV3DBase.h:60
void algoBeginRun(const edm::Run &, const edm::EventSetup &) override
ConstRecHitContainer recHits() const
Definition: Trajectory.h:186
const Bounds & bounds() const
Definition: Surface.h:87
uint16_t firstStrip() const
bool operator()(const T &PseudoDetId1, const T &PseudoDetId2)
unsigned int DetId
Definition: APVGainStruct.h:10
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
const edm::EventSetup * iSetup_
LocalError positionError() const
dqm::legacy::DQMStore DQMStore
const uint16_t range(const Frame &aFrame)
bool getData(T &iHolder) const
Definition: EventSetup.h:128
DataContainer const & measurements() const
Definition: Trajectory.h:178
vector< string > VInputFiles
int iEvent
Definition: GenABIO.cc:224
double Gain
Definition: APVGainStruct.h:26
T mag() const
Definition: PV3DBase.h:64
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:652
std::unordered_map< unsigned int, stAPVGain * > APVsColl
double PreviousGain
Definition: APVGainStruct.h:28
float yy() const
Definition: LocalError.h:24
unsigned int Index
Definition: APVGainStruct.h:8
T sqrt(T t)
Definition: SSEVec.h:19
double pt() const
track transverse momentum
Definition: TrackBase.h:637
printf("params %d %f %f %f\n", minT, eps, errmax, chi2max)
T z() const
Definition: PV3DBase.h:61
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
std::pair< ContainerIterator, ContainerIterator > Range
const std::complex< double > I
Definition: I.h:8
ClusterRef cluster() const
double const GOOD
Definition: Constants.h:13
const LocalTrajectoryError & localError() const
static constexpr auto TOB
void algoBeginJob(const edm::EventSetup &) override
unsigned long long TimeValue_t
Definition: Timestamp.h:28
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:500
Definition: DetId.h:17
double const BAD
Definition: Constants.h:15
ConstRecHitContainer RecHitContainer
Definition: Trajectory.h:42
static constexpr auto TIB
T const * product() const
Definition: Handle.h:70
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
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:177
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::unique_ptr< SiStripApvGain > getNewObject() override
double b
Definition: hdecay.h:118
float chiSquared() const
Definition: Trajectory.h:241
void getPeakOfLandau(TH1 *InputHisto, double *FitResults, double LowRange=0, double HighRange=5400)
SiStripCluster const & stereoCluster() const
edm::EventID id() const
Definition: EventBase.h:59
DQM_DEPRECATED void save(std::string const &filename, std::string const &path="")
Definition: DQMStore.cc:784
GlobalVector globalMomentum() const
double a
Definition: hdecay.h:119
tuple cout
Definition: gather_cfg.py:144
const_iterator begin() const
first iterator over the map (read only)
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:157
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
T x() const
Definition: PV3DBase.h:59
unsigned int SubDet
Definition: APVGainStruct.h:12
static constexpr auto TID
TimeValue_t value() const
Definition: Timestamp.h:45
edm::Timestamp time() const
Definition: EventBase.h:60
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
const edm::Event * iEvent_
Definition: Run.h:45
unsigned int tecSide(const DetId &id) const