CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HBHETimeProfileStatusBitSetter.cc
Go to the documentation of this file.
4 
5 #include <algorithm> // for "max"
6 #include <math.h>
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 
51 
52 
53 
54 
55 
56 
57 void HBHETimeProfileStatusBitSetter::hbheSetTimeFlagsFromDigi(HBHERecHitCollection * hbhe, const std::vector<HBHEDataFrame>& udigi, const std::vector<int>& RecHitIndex)
58 {
59 
60  bool Bits[4]={false, false, false, false};
61  std::vector<HBHEDataFrame> digi = const_cast<std::vector<HBHEDataFrame>&>(udigi);
62  std::sort(digi.begin(), digi.end(), compare_digi_energy()); // sort digis according to energies
63  std::vector<double> PulseShape; // store fC values for each time slice
64  int DigiSize=0;
65  // int LeadingEta=0;
66  int LeadingPhi=0;
67  bool FoundLeadingChannel=false;
68  for(std::vector<HBHEDataFrame>::const_iterator itDigi = digi.begin(); itDigi!=digi.end(); itDigi++)
69  {
70  if(!FoundLeadingChannel)
71  {
72  // LeadingEta = itDigi->id().ieta();
73  LeadingPhi = itDigi->id().iphi();
74  DigiSize=(*itDigi).size();
75  PulseShape.clear();
76  PulseShape.resize(DigiSize,0);
77  FoundLeadingChannel=true;
78  }
79  if(abs(LeadingPhi - itDigi->id().iphi())<2)
80  for(int i=0; i!=DigiSize; i++)
81  PulseShape[i]+=itDigi->sample(i).nominal_fC();
82 
83  }
84 
85 
86 
87  if(RecHitIndex.size()>0)
88  {
89  double FracInLeader=-1;
90  //double Slope=0; // not currently used
91  double R1=-1;
92  double R2=-1;
93  double OuterEnergy=-1;
94  double TotalEnergy=0;
95  int PeakPosition=0;
96 
97  for(int i=0; i!=DigiSize; i++)
98  {
99  if(PulseShape[i]>PulseShape[PeakPosition])
100  PeakPosition=i;
101  TotalEnergy+=PulseShape[i];
102  }
103 
104 
105  if(PeakPosition < (DigiSize-2))
106  {
107  R1 = PulseShape[PeakPosition+1]/PulseShape[PeakPosition];
108  R2 = PulseShape[PeakPosition+2]/PulseShape[PeakPosition+1];
109  }
110 
111  FracInLeader = PulseShape[PeakPosition]/TotalEnergy;
112 
113  if((PeakPosition > 0) && (PeakPosition < (DigiSize-2)))
114  {
115  OuterEnergy = 1. -((PulseShape[PeakPosition - 1] +
116  PulseShape[PeakPosition] +
117  PulseShape[PeakPosition + 1] +
118  PulseShape[PeakPosition + 2] )
119  / TotalEnergy);
120 
121  }
122 
123  /* TH1D * HistForFit = new TH1D("HistForFit","HistForFit",DigiSize,0,DigiSize);
124  for(int i=0; i!=DigiSize; i++)
125  {
126  HistForFit->Fill(i,PulseShape[i]);
127  HistForFit->Fit("expo","WWQ","",PeakPosition, DigiSize-1);
128  TF1 * Fit = HistForFit->GetFunction("expo");
129  Slope = Fit->GetParameter("Slope");
130  }
131  delete HistForFit;
132  */
133  if (R1!=-1 && R2!=-1)
134  Bits[0] = (R1Min_ > R1) || (R1Max_ < R1) || (R2Min_ > R2) || (R2Max_ < R2);
135  if (FracInLeader!=-1)
136  Bits[1] = (FracInLeader < FracLeaderMin_) || (FracInLeader > FracLeaderMax_);
137  if (OuterEnergy!=-1)
138  Bits[2] = (OuterEnergy < OuterMin_) || (OuterEnergy > OuterMax_);
139  // Bits[3] = (SlopeMin_ > Slope) || (SlopeMax_ < Slope);
140  Bits[3] = false;
141 
142  } // if (RecHitIndex.size()>0)
143  else
144  {
145 
146  Bits[0]=false;
147  Bits[1]=false;
148  Bits[2]=false;
149  Bits[3]=true;
150 
151  } // (RecHitIndex.size()==0; no need to set Bit3 true?)
152 
153  for(unsigned int i=0; i!=RecHitIndex.size(); i++)
154  {
155 
156  // Write calculated bit values starting from position FirstBit
157  (*hbhe)[RecHitIndex.at(i)].setFlagField(Bits[0],HcalCaloFlagLabels::HSCP_R1R2);
158  (*hbhe)[RecHitIndex.at(i)].setFlagField(Bits[1],HcalCaloFlagLabels::HSCP_FracLeader);
159  (*hbhe)[RecHitIndex.at(i)].setFlagField(Bits[2],HcalCaloFlagLabels::HSCP_OuterEnergy);
160  (*hbhe)[RecHitIndex.at(i)].setFlagField(Bits[3],HcalCaloFlagLabels::HSCP_ExpFit);
161 
162  }
163 
164 
165 
166 }
167 
int i
Definition: DBlmapReader.cc:9
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void hbheSetTimeFlagsFromDigi(HBHERecHitCollection *, const std::vector< HBHEDataFrame > &, const std::vector< int > &)