CMS 3D CMS Logo

FP420ClusterMain.cc
Go to the documentation of this file.
1 // File: FP420ClusterMain.cc
3 // Date: 12.2006
4 // Description: FP420ClusterMain for FP420
5 // Modifications:
7 #include <vector>
8 #include <iostream>
10 
17 
18 #include "CLHEP/Random/RandFlat.h"
19 
20 using namespace std;
21 
22 FP420ClusterMain::FP420ClusterMain(const edm::ParameterSet& conf, int dn, int sn, int pn, int rn)
23  : dn0(dn), sn0(sn), pn0(pn), rn0(rn) {
24  verbosity = conf.getUntrackedParameter<int>("VerbosityLevel");
25  ElectronPerADC_ = conf.getParameter<double>("ElectronFP420PerAdc");
26  clusterMode_ = conf.getParameter<std::string>("ClusterModeFP420");
27  ChannelThreshold = conf.getParameter<double>("ChannelFP420Threshold"); //6
28  SeedThreshold = conf.getParameter<double>("SeedFP420Threshold"); //7
29  ClusterThreshold = conf.getParameter<double>("ClusterFP420Threshold"); //7
30  MaxVoidsInCluster = conf.getParameter<int>("MaxVoidsFP420InCluster"); //1
31 
32  if (verbosity > 0) {
33  std::cout << "FP420ClusterMain constructor: ElectronPerADC = " << ElectronPerADC_ << std::endl;
34  std::cout << " clusterMode = " << clusterMode_ << std::endl;
35  std::cout << " ChannelThreshold = " << ChannelThreshold << std::endl;
36  std::cout << " SeedThreshold = " << SeedThreshold << std::endl;
37  std::cout << " ClusterThreshold = " << ClusterThreshold << std::endl;
38  std::cout << " MaxVoidsInCluster = " << MaxVoidsInCluster << std::endl;
39  }
40  xytype = 2; // only X types of planes
41  ENC_ = 960.; //
42  Thick300 = 0.300;
44  //UseNoiseBadElectrodeFlagFromDB_ = true;
46  //
47  // pitches and ldriftes:
48  //
49  ldriftX = 0.050;
50  ldriftY = 0.050; // was 0.040
51  pitchY = 0.050; // was 0.040
52  pitchX = 0.050;
53  moduleThicknessY = 0.250; // mm
54  moduleThicknessX = 0.250; // mm
55 
56  //numStripsY = 200; // Y plate number of strips:200*0.050=10mm (xytype=1)
57  //numStripsX = 400; // X plate number of strips:400*0.050=20mm (xytype=2)
58  numStripsY = 144; // Y plate number of strips:144*0.050=7.2mm (xytype=1)
59  numStripsX = 160; // X plate number of strips:160*0.050=8.0mm (xytype=2)
60 
61  //numStripsYW = 50; // Y plate number of W strips:50 *0.400=20mm (xytype=1) - W have ortogonal projection
62  //numStripsXW = 25; // X plate number of W strips:25 *0.400=10mm (xytype=2) - W have ortogonal projection
63  numStripsYW = 20; // Y plate number of W strips:20 *0.400=8.0mm (xytype=1) - W have ortogonal projection
64  numStripsXW = 18; // X plate number of W strips:18 *0.400=7.2mm (xytype=2) - W have ortogonal projection
65 
66  // sn0 = 4;
67  // pn0 = 9;
68 
69  if (verbosity > 1) {
70  std::cout << "FP420ClusterMain constructor: sn0 = " << sn0 << " pn0=" << pn0 << " dn0=" << dn0 << " rn0=" << rn0
71  << std::endl;
72  std::cout << "FP420ClusterMain constructor: ENC = " << ENC_ << std::endl;
73  std::cout << " Thick300 = " << Thick300 << std::endl;
74  std::cout << " BadElectrodeProbability = " << BadElectrodeProbability_ << std::endl;
75  std::cout << " ldriftX = " << ldriftX << " ldriftY = " << ldriftY << std::endl;
76  std::cout << " pitchY = " << pitchY << " pitchX = " << pitchX << std::endl;
77  std::cout << " numStripsY = " << numStripsY << " numStripsX = " << numStripsX << std::endl;
78  std::cout << " moduleThicknessY = " << moduleThicknessY << " moduleThicknessX = " << moduleThicknessX << std::endl;
79  }
80 
81  if (UseNoiseBadElectrodeFlagFromDB_ == false) {
82  if (verbosity > 0) {
83  std::cout << "using a SingleNoiseValue and good electrode flags" << std::endl;
84  }
85  } else {
86  if (verbosity > 0) {
87  std::cout << "using Noise and BadElectrode flags accessed from DB" << std::endl;
88  }
89  }
90 
91  if (clusterMode_ == "ClusterProducerFP420") {
92  // ChannelThreshold = 6.0;// was 2.6.0 7 18
93  // SeedThreshold = 7.0;//was 3.7.0 8 20
94  // ClusterThreshold = 7.0;// was 2. 7.0 8 20
95  // MaxVoidsInCluster = 1;
97  std::make_unique<ClusterProducerFP420>(ChannelThreshold, SeedThreshold, ClusterThreshold, MaxVoidsInCluster);
98  validClusterizer_ = true;
99  } else {
100  std::cout << "ERROR:FP420ClusterMain: No valid clusterizer selected" << std::endl;
101  validClusterizer_ = false;
102  }
103 }
104 
105 //void FP420ClusterMain::run(const DigiCollectionFP420 *input, ClusterCollectionFP420 *soutput,
106 // const std::vector<ClusterNoiseFP420>& electrodnoise)
108 
109 {
110  // unpack from iu:
111  // int sScale = 20, zScale=2;
112  // int sector = (iu-1)/sScale + 1 ;
113  // int zmodule = (iu - (sector - 1)*sScale - 1) /zScale + 1 ;
114  // int zside = iu - (sector - 1)*sScale - (zmodule - 1)*zScale ;
115 
116  if (verbosity > 0) {
117  std::cout << "FP420ClusterMain: OK1" << std::endl;
118  }
119  if (validClusterizer_) {
120  int number_detunits = 0;
121  int number_localelectroderechits = 0;
122 
123  // get vector of detunit ids
124  // const std::vector<unsigned int> detIDs = input->detIDs();
125 
126  // to be used in put (besause of 0 in cluster collection for: 1) 1st cluster and 2) case of no cluster)
127  // ignore 0, but to save info for 1st cluster record it second time on place 1 .
128 
129  bool first = true;
130  // loop over detunits
131  for (int det = 1; det < dn0; det++) {
132  for (int sector = 1; sector < sn0; sector++) {
133  for (int zmodule = 1; zmodule < pn0; zmodule++) {
134  for (int zside = 1; zside < rn0; zside++) {
135  // intindex is a continues numbering of FP420
136  unsigned int detID = FP420NumberingScheme::packMYIndex(rn0, pn0, sn0, det, zside, sector, zmodule);
137  if (verbosity > 0) {
138  std::cout << " FP420ClusterMain:1 run loop index no iu = " << detID << std::endl;
139  }
140  float moduleThickness = 0; // plate thickness
141  int numStrips = 0; // number of strips in the module
142  // Y:
143  if (xytype == 1) {
144  numStrips = numStripsY * numStripsYW;
145  moduleThickness = moduleThicknessY;
146  }
147  // X:
148  if (xytype == 2) {
149  numStrips = numStripsX * numStripsXW;
150  moduleThickness = moduleThicknessX;
151  }
152 
153  // for ( std::vector<unsigned int>::const_iterator detunit_iterator = detIDs.begin(); detunit_iterator != detIDs.end(); ++detunit_iterator ) {
154  // unsigned int detID = *detunit_iterator;
155  ++number_detunits;
156 
157  // .
158  // GET DIGI collection !!!!
159  // .
160  // const DigiCollectionFP420::Range digiRange = input->get(detID);
161  DigiCollectionFP420::Range digiRange;
162  std::vector<HDigiFP420> dcollector;
163  // if (dcollector.size()>0){
164  if (verbosity > 0) {
165  std::cout << " FP420ClusterMain:2 number_detunits = " << number_detunits << std::endl;
166  }
167  digiRange = input->get(detID);
168  //digiRange = input.get(detID);
169  // }
170 
171  if (verbosity > 0) {
172  std::cout << " FP420ClusterMain: input->get DONE dcollector.size()=" << dcollector.size() << std::endl;
173  }
174 
175  DigiCollectionFP420::ContainerIterator sort_begin = digiRange.first;
176  DigiCollectionFP420::ContainerIterator sort_end = digiRange.second;
177  for (; sort_begin != sort_end; ++sort_begin) {
178  dcollector.push_back(*sort_begin);
179  } // for
180  if (!dcollector.empty()) {
181  DigiCollectionFP420::ContainerIterator digiRangeIteratorBegin = digiRange.first;
182  DigiCollectionFP420::ContainerIterator digiRangeIteratorEnd = digiRange.second;
183  if (verbosity > 0) {
184  std::cout << " FP420ClusterMain: channel Begin = " << (digiRangeIteratorBegin)->channel() << std::endl;
185  std::cout << " FP420ClusterMain: channel end = " << (digiRangeIteratorEnd - 1)->channel() << std::endl;
186  }
187  if (verbosity > 0) {
188  std::cout << " FP420ClusterMain:3 noise treatment " << std::endl;
189  }
190  if (clusterMode_ == "ClusterProducerFP420") {
191  std::vector<ClusterFP420> collector;
192  // std::vector<ClusterFP420> collector;
193 
194  if (UseNoiseBadElectrodeFlagFromDB_ == false) {
195  //Case of SingleValueNoise flags for all electrodes of a Detector
196 
197  //float noise = ENC_*ldrift/Thick300/ElectronPerADC_;//Noise is proportional to charge collection path
198  float noise =
199  ENC_ * moduleThickness / Thick300 / ElectronPerADC_; //Noise is proportional to moduleThickness
200 
201  //vector<float> noiseVec(numElectrodes,noise);
202  //Construct a ElectrodNoiseVector ( in order to be compliant with the DB access)
203  ElectrodNoiseVector vnoise;
204  ClusterNoiseFP420::ElectrodData theElectrodData;
205 
206  if (verbosity > 0) {
207  std::cout << " FP420ClusterMain:4 numStrips = " << numStrips << std::endl;
208  }
209  for (int electrode = 0; electrode < numStrips; ++electrode) {
210  // discard randomly bad electrode with probability BadElectrodeProbability_
211  bool badFlag = CLHEP::RandFlat::shoot(1.) < BadElectrodeProbability_ ? true : false;
212  theElectrodData.setData(noise, badFlag);
213  vnoise.push_back(theElectrodData); // fill vector vnoise
214  } // for
215 
216  if (verbosity > 0) {
217  std::cout << " FP420ClusterMain:5 BadElectrodeProbability added " << std::endl;
218  }
219  //clusterizeDetUnit or clusterizeDetUnitPixels !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
220  collector.clear();
221  // std::vector<ClusterFP420> collector;
222  // collector = threeThreshold_->clusterizeDetUnit(digiRangeIteratorBegin,digiRangeIteratorEnd,detID,vnoise);
223  // if (dcollector.size()>0){
224  collector = threeThreshold_->clusterizeDetUnitPixels(
225  digiRangeIteratorBegin, digiRangeIteratorEnd, detID, vnoise, xytype, verbosity);
226  // }
227  if (verbosity > 0) {
228  std::cout << " FP420ClusterMain:6 threeThreshold OK " << std::endl;
229  }
230 
231  } else {
232  //Case of Noise and BadElectrode flags access from DB
233  /*
234  const ElectrodNoiseVector& vnoise = electrodnoise->getElectrodNoiseVector(detID);
235 
236  if (vnoise.size() <= 0) {
237  std::cout << "WARNING requested Noise Vector for detID " << detID << " that isn't in map " << std::endl;
238  continue;
239  }
240  collector.clear();
241  collector = threeThreshold_->clusterizeDetUnit(digiRangeIteratorBegin,digiRangeIteratorEnd,detID,vnoise);
242  */
243 
244  } // if (UseNoiseBadElectrodeFlagFromDB
245 
246  if (!collector.empty()) {
248  inputRange.first = collector.begin();
249  inputRange.second = collector.end();
250 
251  if (verbosity > 0) {
252  std::cout << " FP420ClusterMain:7 collector.size()>0 " << std::endl;
253  }
254  if (first) {
255  // use it only if ClusterCollectionFP420 is the ClusterCollection of one event, otherwise, do not use (loose 1st cl. of 1st event only)
256  first = false;
257  unsigned int detID0 = 0;
258  if (verbosity > 0) {
259  std::cout << " FP420ClusterMain:8 first soutput->put " << std::endl;
260  }
261  soutput->put(inputRange, detID0); // !!! put into adress 0 for detID which will not be used never
262  } //if ( first )
263 
264  // !!! put
265  if (verbosity > 0) {
266  std::cout << " FP420ClusterMain:9 soutput->put " << std::endl;
267  }
268  soutput->put(inputRange, detID);
269 
270  number_localelectroderechits += collector.size();
271  } // if (collector.size
272  } // if ( clusterMode
273  if (verbosity > 0) {
274  std::cout << "[FP420ClusterMain] execution in mode " << clusterMode_ << " generating "
275  << number_localelectroderechits << " ClusterFP420s in " << number_detunits << " DetUnits."
276  << std::endl;
277  } //if (verb
278  } // if (dcollector.siz
279  } //for
280  } //for
281  } //for
282  } //for
283 
284  if (verbosity == -50) {
285  // check of access to the collector:
286  for (int det = 1; det < dn0; det++) {
287  for (int sector = 1; sector < sn0; sector++) {
288  for (int zmodule = 1; zmodule < pn0; zmodule++) {
289  for (int zside = 1; zside < rn0; zside++) {
290  // intindex is a continues numbering of FP420
291  unsigned int iu = FP420NumberingScheme::packMYIndex(rn0, pn0, sn0, det, zside, sector, zmodule);
292  std::cout << " iu = " << iu << " sector = " << sector << " zmodule = " << zmodule << " zside = " << zside
293  << " det=" << det << std::endl;
294  std::vector<ClusterFP420> collector;
295  collector.clear();
296  ClusterCollectionFP420::Range outputRange;
297  outputRange = soutput->get(iu);
298  // fill output in collector vector (for may be sorting? or other checks)
299  ClusterCollectionFP420::ContainerIterator sort_begin = outputRange.first;
300  ClusterCollectionFP420::ContainerIterator sort_end = outputRange.second;
301  for (; sort_begin != sort_end; ++sort_begin) {
302  collector.push_back(*sort_begin);
303  } // for
304  std::cout << " ===" << std::endl;
305  std::cout << " ===" << std::endl;
306  std::cout << " =========== FP420ClusterMain:check: iu= " << iu << " zside = " << zside << std::endl;
307  std::cout << " ======renew collector size = " << collector.size() << std::endl;
308  std::cout << " ===" << std::endl;
309  std::cout << " ===" << std::endl;
310  std::vector<ClusterFP420>::const_iterator simHitIter = collector.begin();
311  std::vector<ClusterFP420>::const_iterator simHitIterEnd = collector.end();
312  // loop in #clusters
313  for (; simHitIter != simHitIterEnd; ++simHitIter) {
314  const ClusterFP420 icluster = *simHitIter;
315  // if(icluster.amplitudes().size()>390) {
316  std::cout << " ===== size of cluster= " << icluster.amplitudes().size() << std::endl;
317  std::cout << " ===" << std::endl;
318  std::cout << " ===== firstStrip = " << icluster.firstStrip()
319  << " barycenter = " << icluster.barycenter() << " barycenterW = " << icluster.barycenterW()
320  << std::endl;
321  std::cout << " ===" << std::endl;
322  for (unsigned int i = 0; i < icluster.amplitudes().size(); i++) {
323  std::cout << "i = " << i << " amplitudes = " << icluster.amplitudes()[i] << std::endl;
324  } // for ampl
325  std::cout << " ===" << std::endl;
326  std::cout << " ===" << std::endl;
327  std::cout << " =======================" << std::endl;
328  // }// if(icluster.amplitudes().size()>390
329  } //for cl
330 
331  /*
332  for (DigitalMapType::const_iterator i=collector.begin(); i!=collector.end(); i++) {
333  std::cout << "DigitizerFP420:check: HDigiFP420:: " << std::endl;
334  std::cout << " strip number is as (*i).first = " << (*i).first << " adc is in (*i).second = " << (*i).second << std::endl;
335  }
336  */
337 
338  //==================================
339 
340  } // for
341  } // for
342  } // for
343  } // for
344 
345  // end of check of access to the strip collection
346  std::cout << "======= FP420ClusterMain: end of check " << std::endl;
347 
348  } // if (verbosit
349 
350  } // if ( validClusterizer_
351 }
float barycenter() const
Definition: ClusterFP420.h:30
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
float barycenterW() const
Definition: ClusterFP420.h:33
std::vector< ClusterFP420 >::const_iterator ContainerIterator
std::vector< HDigiFP420 >::const_iterator ContainerIterator
std::unique_ptr< const ClusterProducerFP420 > threeThreshold_
std::vector< ClusterNoiseFP420::ElectrodData > ElectrodNoiseVector
void put(Range input, unsigned int detID)
int zside(DetId const &)
double BadElectrodeProbability_
void run(edm::Handle< DigiCollectionFP420 > &input, ClusterCollectionFP420 *soutput) const
Runs the algorithm.
short firstStrip() const
Definition: ClusterFP420.h:20
static std::string const input
Definition: EdmProvDump.cc:47
T getUntrackedParameter(std::string const &, T const &) const
static unsigned packMYIndex(int rn0, int pn0, int sn0, int det, int zside, int sector, int zmodule)
std::string clusterMode_
std::pair< ContainerIterator, ContainerIterator > Range
FP420ClusterMain(const edm::ParameterSet &conf, int dn, int sn, int pn, int rn)
bool UseNoiseBadElectrodeFlagFromDB_
const Range get(unsigned int detID) const
std::pair< ContainerIterator, ContainerIterator > Range
const std::vector< short > & amplitudes() const
Definition: ClusterFP420.h:28