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