11 for (
int id = 0;
id < 9; ++id) {
20 for (
int id = 0;
id < 9; ++id) {
45 TTree *
t =
new TTree(
"t",
"dummy MLP tree");
48 t->Branch(
"z1", &(ctx.
tmp[0]),
"z1/D");
49 t->Branch(
"z2", &(ctx.
tmp[1]),
"z2/D");
50 t->Branch(
"z3", &(ctx.
tmp[2]),
"z3/D");
51 t->Branch(
"z4", &(ctx.
tmp[3]),
"z4/D");
52 t->Branch(
"z5", &(ctx.
tmp[4]),
"z5/D");
53 t->Branch(
"z6", &(ctx.
tmp[5]),
"z6/D");
54 t->Branch(
"z7", &(ctx.
tmp[6]),
"z7/D");
55 t->Branch(
"z8", &(ctx.
tmp[7]),
"z8/D");
56 t->Branch(
"zf", &(ctx.
tmp[8]),
"zf/D");
60 new TMultiLayerPerceptron(
"@z1,@z2,@z3,@z4,@z5,@z6,@z7,@z8:10:5:zf", t);
61 ctx.
mlp->LoadWeights(path.c_str());
66 std::string p =
"RecoLocalCalo/EcalDeadChannelRecoveryAlgos/data/NNWeights/";
81 std::string p =
"RecoLocalCalo/EcalDeadChannelRecoveryAlgos/data/NNWeights/";
100 double NewEnergy = 0.0;
102 double NewEnergy_RelMC = 0.0;
103 double NewEnergy_RelDC = 0.0;
105 double MNxN_RelMC[9] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } ;
106 double MNxN_RelDC[9] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } ;
110 double sum8_RelMC = makeNxNMatrice_RelMC(
id, hit_collection, MNxN_RelMC,AcceptFlag);
111 double sum8_RelDC = makeNxNMatrice_RelDC(
id, hit_collection, MNxN_RelDC,AcceptFlag);
115 if (sum8_RelDC > Sum8Cut && sum8_RelMC > Sum8Cut) {
116 NewEnergy_RelMC = estimateEnergy(MNxN_RelMC);
117 NewEnergy_RelDC = estimateEnergy(MNxN_RelDC);
122 double SumMNxN_RelMC = MNxN_RelMC[LU] + MNxN_RelMC[UU] + MNxN_RelMC[RU] +
123 MNxN_RelMC[LL] + MNxN_RelMC[CC] + MNxN_RelMC[RR] +
124 MNxN_RelMC[LD] + MNxN_RelMC[DD] + MNxN_RelMC[RD] ;
126 double frMNxN_RelMC[9];
for (
int i=0;
i<9;
i++) { frMNxN_RelMC[
i] = MNxN_RelMC[
i] / SumMNxN_RelMC ; }
128 double prMNxN_RelMC = P::Diagonal( frMNxN_RelMC[LU] ) * P::UpDown( frMNxN_RelMC[UU] ) * P::Diagonal( frMNxN_RelMC[RU] ) *
129 P::ReftRight( frMNxN_RelMC[LL] ) * P::Central( frMNxN_RelMC[CC] ) * P::ReftRight( frMNxN_RelMC[RR] ) *
130 P::Diagonal( frMNxN_RelMC[LD] ) * P::UpDown( frMNxN_RelMC[DD] ) * P::Diagonal( frMNxN_RelMC[RD] ) ;
132 double SumMNxN_RelDC = MNxN_RelDC[LU] + MNxN_RelDC[UU] + MNxN_RelDC[RU] +
133 MNxN_RelDC[LL] + MNxN_RelDC[CC] + MNxN_RelDC[RR] +
134 MNxN_RelDC[LD] + MNxN_RelDC[DD] + MNxN_RelDC[RD] ;
136 double frMNxN_RelDC[9];
for (
int i=0;
i<9;
i++) { frMNxN_RelDC[
i] = MNxN_RelDC[
i] / SumMNxN_RelDC ; }
138 double prMNxN_RelDC = P::Diagonal( frMNxN_RelDC[LU] ) * P::UpDown( frMNxN_RelDC[UU] ) * P::Diagonal( frMNxN_RelDC[RU] ) *
139 P::ReftRight( frMNxN_RelDC[LL] ) * P::Central( frMNxN_RelDC[CC] ) * P::ReftRight( frMNxN_RelDC[RR] ) *
140 P::Diagonal( frMNxN_RelDC[LD] ) * P::UpDown( frMNxN_RelDC[DD] ) * P::Diagonal( frMNxN_RelDC[RD] ) ;
142 if ( prMNxN_RelDC > prMNxN_RelMC ) { NewEnergy = NewEnergy_RelDC ; sum8 = sum8_RelDC ; }
143 if ( prMNxN_RelDC <= prMNxN_RelMC ) { NewEnergy = NewEnergy_RelMC ; sum8 = sum8_RelMC ; }
148 if ( NewEnergy == -1000000.0 ||
149 NewEnergy == -1000001.0 ||
150 NewEnergy == -2000000.0 ||
151 NewEnergy == -3000000.0 ||
152 NewEnergy == -3000001.0 ) { *AcceptFlag=
false ; NewEnergy = 0.0 ; }
159 if ( NewEnergy > 10.0 * sum8 ) { *AcceptFlag=
false ; NewEnergy = 0.0 ; }
164 template <
typename T>
167 int missing_index = 0;
169 for (
int i = 0;
i < 9;
i++) {
171 missing[missing_index++] =
i;
176 if (M3x3Input[i] < 0.0) {
return -2000000.0; }
182 if (missing_index == 0) {
return -1000000.0; }
183 if (missing_index > 1) {
return -1000001.0; }
184 if (missing_index == 1) { idxDC = missing[0]; }
187 int input_order[9] = { CC, RR, LL, UU, DD, RU, RD, LU, LD };
191 for (
int id : input_order) {
195 input[input_index++] = TMath::Log(M3x3Input[
id]);
199 M3x3Input[idxDC] = TMath::Exp(ctx_[idxDC].mlp->Evaluate(0, input));
200 return M3x3Input[idxDC];
203 template <
typename DetIdT>
210 std::vector<DetId> NxNaroundDC = topology_->getWindow(itID, 5, 5);
213 double EnergyMax = 0.0;
217 std::vector<DetId>::const_iterator theCells;
219 for (theCells = NxNaroundDC.begin(); theCells != NxNaroundDC.end(); ++theCells) {
220 DetIdT cell = DetIdT(*theCells);
225 if ( goS_it != hit_collection.
end() && goS_it->energy() >= EnergyMax ) {
226 EnergyMax = goS_it->energy();
233 if ( CellMax.null() ) { *AcceptFlag=
false ;
return 0.0 ; }
239 bool dcIn3x3 =
false ;
241 std::vector<DetId> NxNaroundMaxCont = topology_->getWindow(CellMax,3,3);
242 std::vector<DetId>::const_iterator testCell;
243 for (testCell = NxNaroundMaxCont.begin(); testCell != NxNaroundMaxCont.end(); ++testCell) {
244 if ( itID == DetIdT(*testCell) ) { dcIn3x3 =
true ; }
248 if (!dcIn3x3) { *AcceptFlag=
false ;
return 0.0 ; }
251 return makeNxNMatrice_RelDC(CellMax, hit_collection, MNxN_RelMC, AcceptFlag);
258 if (
id.ieta() == 85 ||
id.ieta() == -85 ) { *AcceptFlag=
false ;
return 0.0 ; }
261 int ietaZ =
id.ieta() ;
262 int ietaP = ( ietaZ == -1 ) ? 1 : ietaZ + 1 ;
263 int ietaN = ( ietaZ == 1 ) ? -1 : ietaZ - 1 ;
265 int iphiZ =
id.iphi() ;
266 int iphiP = ( iphiZ == 360 ) ? 1 : iphiZ + 1 ;
267 int iphiN = ( iphiZ == 1 ) ? 360 : iphiZ - 1 ;
269 for (
int i=0;
i<9;
i++) { MNxN[
i] = 0.0 ; }
275 std::vector<DetId>::const_iterator itCells;
276 for (itCells = window.begin(); itCells != window.end(); ++itCells) {
282 if (goS_it != hit_collection.
end()) {
283 double energy = goS_it->energy();
286 else if ( cell.
ieta() == ietaP && cell.
iphi() == iphiZ ) { MNxN[
RR] =
energy; }
287 else if ( cell.
ieta() == ietaP && cell.
iphi() == iphiN ) { MNxN[
RD] =
energy; }
289 else if ( cell.
ieta() == ietaZ && cell.
iphi() == iphiP ) { MNxN[
UU] =
energy; }
290 else if ( cell.
ieta() == ietaZ && cell.
iphi() == iphiZ ) { MNxN[
CC] =
energy; }
291 else if ( cell.
ieta() == ietaZ && cell.
iphi() == iphiN ) { MNxN[
DD] =
energy; }
293 else if ( cell.
ieta() == ietaN && cell.
iphi() == iphiP ) { MNxN[
LU] =
energy; }
294 else if ( cell.
ieta() == ietaN && cell.
iphi() == iphiZ ) { MNxN[
LL] =
energy; }
295 else if ( cell.
ieta() == ietaN && cell.
iphi() == iphiN ) { MNxN[
LD] =
energy; }
297 else { *AcceptFlag=
false ;
return 0.0 ;}
303 double ESUMis = 0.0 ;
304 for (
int i=0;
i<9;
i++) { ESUMis = ESUMis + MNxN[
i] ; }
319 int ixZ = itID.
ix() ;
323 int iyZ = itID.
iy() ;
327 for (
int i=0;
i<9;
i++) { MNxN[
i] = 0.0 ; }
334 std::vector<DetId>::const_iterator itCells;
336 for (itCells = NxNaroundRefXtal.begin(); itCells != NxNaroundRefXtal.end(); ++itCells) {
342 if ( goS_it != hit_collection.
end() ) {
343 double energy = goS_it->energy();
345 if ( cell.
ix() == ixP && cell.
iy() == iyP ) { MNxN[
RU] =
energy; }
346 else if ( cell.
ix() == ixP && cell.
iy() == iyZ ) { MNxN[
RR] =
energy; }
347 else if ( cell.
ix() == ixP && cell.
iy() == iyN ) { MNxN[
RD] =
energy; }
349 else if ( cell.
ix() == ixZ && cell.
iy() == iyP ) { MNxN[
UU] =
energy; }
350 else if ( cell.
ix() == ixZ && cell.
iy() == iyZ ) { MNxN[
CC] =
energy; }
351 else if ( cell.
ix() == ixZ && cell.
iy() == iyN ) { MNxN[
DD] =
energy; }
353 else if ( cell.
ix() == ixN && cell.
iy() == iyP ) { MNxN[
LU] =
energy; }
354 else if ( cell.
ix() == ixN && cell.
iy() == iyZ ) { MNxN[
LL] =
energy; }
355 else if ( cell.
ix() == ixN && cell.
iy() == iyN ) { MNxN[
LD] =
energy; }
357 else { *AcceptFlag=
false ;
return 0.0 ;}
363 double ESUMis = 0.0 ;
364 for (
int i=0;
i<9;
i++) { ESUMis = ESUMis + MNxN[
i] ; }
EcalDeadChannelRecoveryNN()
std::vector< EcalRecHit >::const_iterator const_iterator
double makeNxNMatrice_RelMC(DetIdT itID, const EcalRecHitCollection &hit_collection, double *MNxN_RelMC, bool *AccFlag)
double makeNxNMatrice_RelDC(DetIdT itID, const EcalRecHitCollection &hit_collection, double *MNxN_RelDC, bool *AccFlag)
static std::string const input
int iphi() const
get the crystal iphi
tuple path
else: Piece not in the list, fine.
const CaloSubdetectorTopology * topology_
~EcalDeadChannelRecoveryNN()
static bool isNextToRingBoundary(EEDetId id)
double recover(const DetIdT id, const EcalRecHitCollection &hit_collection, double Sum8Cut, bool *AcceptFlag)
int ieta() const
get the crystal ieta
MultiLayerPerceptronContext ctx_[9]
const_iterator end() const
void setCaloTopology(const CaloTopology *topo)
double estimateEnergy(double *M3x3Input, double epsilon=0.0000001)
virtual std::vector< DetId > getWindow(const DetId &id, const int &northSouthSize, const int &eastWestSize) const
bool null() const
is this a null id ?
const CaloSubdetectorTopology * getSubdetectorTopology(const DetId &id) const
access the subdetector Topology for the given subdetector directly
TMultiLayerPerceptron * mlp
iterator find(key_type k)
void load_file(MultiLayerPerceptronContext &ctx, std::string fn)
volatile std::atomic< bool > shutdown_flag false
std::string fullPath() const