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