CMS 3D CMS Logo

HBHETimeProfileStatusBitSetter.cc
Go to the documentation of this file.
4 
5 #include <algorithm> // for "max"
6 #include <cmath>
7 #include <TH1.h>
8 #include <TF1.h>
9 
10 
12 {
13  // use simple values in default constructor
14  R1Min_ = 0.1;
15  R1Max_ = 0.7;
16  R2Min_ = 0.2;
17  R2Max_ = 0.5;
18  FracLeaderMin_ = 0.4;
19  FracLeaderMax_ = 0.7;
20  SlopeMin_ = -1.5;
21  SlopeMax_ = -0.6;
22  OuterMin_ = 0.9;
23  OuterMax_ = 1.0;
25 }
26 
28  double R2Min, double R2Max,
29  double FracLeaderMin, double FracLeaderMax,
30  double SlopeMin, double SlopeMax,
31  double OuterMin, double OuterMax,
32  double EnergyThreshold)
33 {
34  R1Min_ = R1Min;
35  R1Max_ = R1Max;
36  R2Min_ = R2Min;
37  R2Max_ = R2Max;
38  FracLeaderMin_ = FracLeaderMin;
39  FracLeaderMax_ = FracLeaderMax;
40  SlopeMin_ = SlopeMin;
41  SlopeMax_ = SlopeMax;
42  OuterMin_ = OuterMin;
43  OuterMax_ = OuterMax;
45 }
46 
48 
49 
50 namespace {
51  bool compareDigiEnergy(const HBHEDataFrame& x, const HBHEDataFrame& y)
52  {
53  double totalX = 0;
54  double totalY = 0;
55  for(int i=0; i!=x.size(); totalX += x.sample(i++).nominal_fC());
56  for(int i=0; i!=y.size(); totalY += y.sample(i++).nominal_fC());
57 
58  return totalX > totalY;
59  }
60 }
61 
62 void HBHETimeProfileStatusBitSetter::hbheSetTimeFlagsFromDigi(HBHERecHitCollection * hbhe, const std::vector<HBHEDataFrame>& udigi, const std::vector<int>& RecHitIndex)
63 {
64 
65  bool Bits[4]={false, false, false, false};
66  std::vector<HBHEDataFrame> digi(udigi);
67  std::sort(digi.begin(), digi.end(), compareDigiEnergy); // sort digis according to energies
68  std::vector<double> PulseShape; // store fC values for each time slice
69  int DigiSize=0;
70  // int LeadingEta=0;
71  int LeadingPhi=0;
72  bool FoundLeadingChannel=false;
73  for(std::vector<HBHEDataFrame>::const_iterator itDigi = digi.begin(); itDigi!=digi.end(); itDigi++)
74  {
75  if(!FoundLeadingChannel)
76  {
77  // LeadingEta = itDigi->id().ieta();
78  LeadingPhi = itDigi->id().iphi();
79  DigiSize=(*itDigi).size();
80  PulseShape.clear();
81  PulseShape.resize(DigiSize,0);
82  FoundLeadingChannel=true;
83  }
84  if(abs(LeadingPhi - itDigi->id().iphi())<2)
85  for(int i=0; i!=DigiSize; i++)
86  PulseShape[i]+=itDigi->sample(i).nominal_fC();
87 
88  }
89 
90 
91 
92  if(!RecHitIndex.empty())
93  {
94  double FracInLeader=-1;
95  //double Slope=0; // not currently used
96  double R1=-1;
97  double R2=-1;
98  double OuterEnergy=-1;
99  double TotalEnergy=0;
100  int PeakPosition=0;
101 
102  for(int i=0; i!=DigiSize; i++)
103  {
104  if(PulseShape[i]>PulseShape[PeakPosition])
105  PeakPosition=i;
106  TotalEnergy+=PulseShape[i];
107  }
108 
109 
110  if(PeakPosition < (DigiSize-2))
111  {
112  R1 = PulseShape[PeakPosition+1]/PulseShape[PeakPosition];
113  R2 = PulseShape[PeakPosition+2]/PulseShape[PeakPosition+1];
114  }
115 
116  FracInLeader = PulseShape[PeakPosition]/TotalEnergy;
117 
118  if((PeakPosition > 0) && (PeakPosition < (DigiSize-2)))
119  {
120  OuterEnergy = 1. -((PulseShape[PeakPosition - 1] +
121  PulseShape[PeakPosition] +
122  PulseShape[PeakPosition + 1] +
123  PulseShape[PeakPosition + 2] )
124  / TotalEnergy);
125 
126  }
127 
128  /* TH1D * HistForFit = new TH1D("HistForFit","HistForFit",DigiSize,0,DigiSize);
129  for(int i=0; i!=DigiSize; i++)
130  {
131  HistForFit->Fill(i,PulseShape[i]);
132  HistForFit->Fit("expo","WWQ","",PeakPosition, DigiSize-1);
133  TF1 * Fit = HistForFit->GetFunction("expo");
134  Slope = Fit->GetParameter("Slope");
135  }
136  delete HistForFit;
137  */
138  if (R1!=-1 && R2!=-1)
139  Bits[0] = (R1Min_ > R1) || (R1Max_ < R1) || (R2Min_ > R2) || (R2Max_ < R2);
140  if (FracInLeader!=-1)
141  Bits[1] = (FracInLeader < FracLeaderMin_) || (FracInLeader > FracLeaderMax_);
142  if (OuterEnergy!=-1)
143  Bits[2] = (OuterEnergy < OuterMin_) || (OuterEnergy > OuterMax_);
144  // Bits[3] = (SlopeMin_ > Slope) || (SlopeMax_ < Slope);
145  Bits[3] = false;
146 
147  } // if (RecHitIndex.size()>0)
148  else
149  {
150 
151  Bits[0]=false;
152  Bits[1]=false;
153  Bits[2]=false;
154  Bits[3]=true;
155 
156  } // (RecHitIndex.size()==0; no need to set Bit3 true?)
157 
158  for(unsigned int i=0; i!=RecHitIndex.size(); i++)
159  {
160 
161  // Write calculated bit values starting from position FirstBit
162  (*hbhe)[RecHitIndex.at(i)].setFlagField(Bits[0],HcalCaloFlagLabels::HSCP_R1R2);
163  (*hbhe)[RecHitIndex.at(i)].setFlagField(Bits[1],HcalCaloFlagLabels::HSCP_FracLeader);
164  (*hbhe)[RecHitIndex.at(i)].setFlagField(Bits[2],HcalCaloFlagLabels::HSCP_OuterEnergy);
165  (*hbhe)[RecHitIndex.at(i)].setFlagField(Bits[3],HcalCaloFlagLabels::HSCP_ExpFit);
166 
167  }
168 
169 
170 
171 }
172 
int size() const
total number of samples in the digi
Definition: HBHEDataFrame.h:31
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void hbheSetTimeFlagsFromDigi(HBHERecHitCollection *, const std::vector< HBHEDataFrame > &, const std::vector< int > &)
constexpr double nominal_fC() const
get the nominal FC (no calibrations applied)
Definition: HcalQIESample.h:61
HcalQIESample const & sample(int i) const
access a sample
Definition: HBHEDataFrame.h:44