CMS 3D CMS Logo

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