Bug Summary

File:libraries/FCAL/DFCALCluster_factory.cc
Location:line 98, column 9
Description:Declared variable-length array (VLA) has zero size

Annotated Source Code

1// $Id: DFCALShower_factory.cc 2001 2006-11-28 11:09:47Z mikornic $
2//
3// File: DFCALShower_factory.cc
4// Created: Tue Nov 28 11:57:50 EST 2006
5// Creator: remitche (on Linux mantrid00 2.4.20-18.8smp i686)
6//
7
8#include <iostream>
9#include <fstream>
10#include <math.h>
11#include <DVector3.h>
12using namespace std;
13
14#include <JANA/JEvent.h>
15using namespace jana;
16
17#include "DFCALCluster_factory.h"
18#include "DFCALHit.h"
19
20// Used to sort hits by Energy
21bool FCALHitsSort_C(const DFCALHit* const &thit1, const DFCALHit* const &thit2) {
22 return thit1->E > thit2->E;
23}
24
25
26int ambiguous_events = 0;
27
28//----------------
29// Constructor
30//----------------
31DFCALCluster_factory::DFCALCluster_factory()
32{
33 // Set defaults
34 MIN_CLUSTER_BLOCK_COUNT = 1;
35 MIN_CLUSTER_SEED_ENERGY = 0.035; // GeV
36
37 gPARMS->SetDefaultParameter("FCAL:MIN_CLUSTER_BLOCK_COUNT", MIN_CLUSTER_BLOCK_COUNT);
38 gPARMS->SetDefaultParameter("FCAL:MIN_CLUSTER_SEED_ENERGY", MIN_CLUSTER_SEED_ENERGY);
39
40}
41
42//------------------
43// brun
44//------------------
45jerror_t DFCALCluster_factory::brun(JEventLoop *eventLoop, int runnumber)
46{
47
48 vector<const DFCALGeometry*> fcalGeoms;
49 eventLoop->Get(fcalGeoms);
50 if(fcalGeoms.size()<1){
51 _DBG_std::cerr<<"DFCALCluster_factory.cc"<<":"<<
51<<" "
<<"fcalGeoms.size()<1 !!!"<<endl;
52 throw JException("fcalGeoms.size()<1 !!!");
53 }
54 fcalGeom = fcalGeoms[0];
55
56 return NOERROR;
57}
58
59//------------------
60// evnt
61// Implementation of UConn LGD clusterizer (M. Kornicer)
62//------------------
63jerror_t DFCALCluster_factory::evnt(JEventLoop *eventLoop, int eventnumber)
64{
65
66 vector<const DFCALHit*> fcalhits;
67 eventLoop->Get(fcalhits);
68
69
70 // Sort hits by energy
71 sort(fcalhits.begin(), fcalhits.end(), FCALHitsSort_C);
72
73 // fill user's hit list
74 int nhits = 0;
1
Variable 'nhits' initialized to 0
75 DFCALCluster::userhits_t* hits = (DFCALCluster::userhits_t*) malloc(sizeof(DFCALCluster::userhits_t)*FCAL_USER_HITS_MAX2800);
76
77// Fill the structure that used to be used by clusterizers in Radphi
78 for (vector<const DFCALHit*>::const_iterator hit = fcalhits.begin();
2
Loop condition is false. Execution continues on line 94
79 hit != fcalhits.end(); hit++ ) {
80 if ( (**hit).E < 1e-6 ) continue;
81 hits->hit[nhits].id = (**hit).id;
82 hits->hit[nhits].x = (**hit).x;
83 hits->hit[nhits].y = (**hit).y;
84 hits->hit[nhits].E = (**hit).E; // adjust a hit energy either in the hit or photon factory
85 hits->hit[nhits].t = (**hit).t;
86 nhits++;
87
88 if (nhits >= (int) FCAL_USER_HITS_MAX2800) {
89 cout << "ERROR: FCALCluster_factory: number of hits " << nhits << " larger than " << FCAL_USER_HITS_MAX2800 << endl;
90 break;
91 }
92
93 }
94 hits->nhits = nhits;
95
96// vector<int> hitUsed(nhits, 0); // number of clusters that use a hit
97 // or -1 for seed
98 int hitUsed[nhits];
3
Declared variable-length array (VLA) has zero size
99 for ( int i = 0; i < nhits; i++ ) { hitUsed[i] = 0; }
100
101 const unsigned int max = 999;
102 DFCALCluster* clusterList[max];
103 unsigned int clusterCount = 0;
104 int iter;
105 for ( iter=0; iter < 99; iter++ ) {
106
107 // 1. At beginning of iteration, recompute info for all clusters.
108 // If something changed, return all hits to the pool and repeat.
109
110 bool something_changed = false;
111 for ( unsigned int c = 0; c < clusterCount; c++ ) {
112 //cout << " --------- Update iteration " << iter << endl;
113 something_changed |= clusterList[c]->update( hits );
114 }
115 if (something_changed) {
116 for ( unsigned int c = 0; c < clusterCount; c++ ) {
117 clusterList[c]->resetClusterHits();
118 }
119 // reset hits in factory also:
120 for ( int h = 0; h < nhits; h++ ) hitUsed[h] = 0;
121 }
122 else if (iter > 0) {
123 break;
124 }
125
126 // 2. Look for blocks with energy large enough to require formation
127 // of a new cluster, and assign them as cluster seeds.
128
129 for ( int ih = 0; ih < hits->nhits; ih++ ) {
130 double energy = hits->hit[ih].E;
131 //cout << "hit: " << ih << " E: " << energy << endl;
132 if (energy < MIN_CLUSTER_SEED_ENERGY)
133 break;
134 double totalAllowed = 0;
135 for ( unsigned int c = 0; c < clusterCount; c++ ) {
136 totalAllowed += clusterList[c]->getEallowed(ih);
137 //cout << " totalAlowed from clust " << c << " is " << totalAllowed << endl;
138
139 }
140 if (energy > totalAllowed) {
141 clusterList[clusterCount] = new DFCALCluster( hits->nhits );
142 hitUsed[ih] = -1;
143 clusterList[clusterCount]->addHit(ih,1.);
144 clusterList[clusterCount]->update( hits );
145 ++clusterCount;
146 }
147 else if (iter > 0) {
148 for ( unsigned int c = 0; c < clusterCount; c++ ) {
149 int nh_clust = clusterList[c]->getHits();
150 //cout << " Nhits " << nh_clust << " from clust " << c << " ? " << endl;
151 if ( nh_clust )
152 continue;
153 totalAllowed -= clusterList[c]->getEallowed(ih);
154 //cout << " else totalAlowed from " << c << " E: " << totalAllowed << endl;
155 if (energy > totalAllowed) {
156 if ( clusterList[c]->getHits() == 0 ) {
157 hitUsed[ih] = -1;
158 }
159 else {
160 ++hitUsed[ih];
161 }
162 clusterList[c]->addHit(ih,1.);
163 break;
164 }
165 }
166 }
167 }
168
169
170 // 3. Share all non-seed blocks among seeded clusters, where
171 // any cluster shares a block if it expects at least 1 KeV in it.
172
173 for ( int ih = 0; ih < hits->nhits; ih++ ) {
174 if ( hitUsed[ih] < 0) // cannot share seed
175 continue;
176 double totalExpected = 0;
177 //cout << " Share hit: " << ih << " E: " << hits->hit[ih].E << endl;
178 for ( unsigned int c = 0; c < clusterCount; c++ ) {
179 if (clusterList[c]->getHits() > 0) {
180 totalExpected += clusterList[c]->getEexpected(ih);
181 }
182 }
183 //cout << " totExpected " << totalExpected ;
184 for ( unsigned int c = 0; c < clusterCount; c++ ) {
185 if (clusterList[c]->getHits() > 0) {
186 double expected = clusterList[c]->getEexpected(ih);
187 //cout << " expected " << expected ;
188 if (expected > 1e-6) {
189 clusterList[c]->addHit(ih,expected/totalExpected);
190 ++hitUsed[ih];
191 }
192 }
193 }
194 }
195
196 }
197
198 if (iter == 99) {
199 ++ambiguous_events;
200 }
201
202 for ( unsigned int c = 0; c < clusterCount; c++) {
203 unsigned int blockCount = clusterList[c]->getHits();
204 //cout << " Blocks " << blockCount << endl;
205 if (blockCount < MIN_CLUSTER_BLOCK_COUNT) {
206 delete clusterList[c];
207 continue;
208 }
209 else {
210
211 clusterList[c]->saveHits( hits );
212
213 _data.push_back( clusterList[c] );
214
215 }
216 }
217
218
219 if (hits) {
220 free(hits);
221 hits=0;
222 }
223
224 return NOERROR;
225
226}
227