CMS 3D CMS Logo

DigitizerFP420.cc
Go to the documentation of this file.
1 // File: DigitizerFP420.cc
3 // Date: 12.2006
4 // Description: DigitizerFP420 for FP420
5 // Modifications:
7 //
8 // system include files
9 #include <memory>
10 
12 
13 // user include files
15 
18 
26 
29 
30 // needed for the geometry:
38 
39 // Random Number
40 #include "CLHEP/Random/RandomEngine.h"
44 
45 // G4 stuff
46 #include "G4HCofThisEvent.hh"
47 #include "G4ProcessManager.hh"
48 #include "G4SDManager.hh"
49 #include "G4Step.hh"
50 #include "G4Track.hh"
51 #include "G4TransportationManager.hh"
52 #include "G4UserEventAction.hh"
53 #include "G4VProcess.hh"
54 
55 #include <cstdlib>
56 #include <vector>
57 
58 using namespace std;
59 
60 namespace cms {
61  DigitizerFP420::DigitizerFP420(const edm::ParameterSet &conf)
62  : conf_(conf), stripDigitizer_(new FP420DigiMain(conf)) {
63  std::string alias(conf.getParameter<std::string>("@module_label"));
64 
65  // produces<edm::DetSetVector<HDigiFP420> >().setBranchAlias( alias );
66  // produces<edm::DetSetVector<HDigiFP420SimLink> >().setBranchAlias ( alias +
67  // "hDigiFP420SimLink");
68  produces<DigiCollectionFP420>().setBranchAlias(alias);
69 
70  trackerContainers.clear();
71  trackerContainers = conf.getParameter<std::vector<std::string>>("ROUList");
72 
73  verbosity = conf_.getUntrackedParameter<int>("VerbosityLevel");
74  dn0 = conf_.getParameter<int>("NumberFP420Detectors");
75  sn0 = conf_.getParameter<int>("NumberFP420Stations");
76  pn0 = conf_.getParameter<int>("NumberFP420SPlanes");
77  rn0 = 7;
78  // rn0 = 3;
79 
80  // produces<DigiCollectionFP420>();
81 
82  // produces<StripDigiCollection>();
83  // produces<HDigiFP420>();
84  // produces<edm::DetSetVector<HDigiFP420> >().setBranchAlias( alias );
85 
86  // produces<DigiCollectionFP420>();
87  // produces<DigiCollectionFP420>("HDigiFP420");
88 
89  // produces<edm::DigiCollectionFP420>();
90 
91  // produces<edm::DetSetVector<DigiCollectionFP420> >();
92 
93  if (verbosity > 0) {
94  std::cout << "Creating a DigitizerFP420" << std::endl;
95  std::cout << "DigitizerFP420: dn0=" << dn0 << " sn0=" << sn0 << " pn0=" << pn0 << " rn0=" << rn0 << std::endl;
96  std::cout << "DigitizerFP420:trackerContainers.size()=" << trackerContainers.size() << std::endl;
97  }
98  }
99 
100  // Virtual destructor needed.
102  if (verbosity > 0) {
103  std::cout << "Destroying a DigitizerFP420" << std::endl;
104  }
105  delete stripDigitizer_;
106  }
107  // void DigitizerFP420::produce(PSimHitCollection * theCAFI,
108  // DigiCollectionFP420 & output) {
110  // be lazy and include the appropriate namespaces
111  using namespace edm;
112  using namespace std;
113 
114  if (verbosity > 0) {
115  std::cout << " ===" << std::endl;
116  std::cout << " ============== DigitizerFP420: start produce= " << std::endl;
117  std::cout << " ===" << std::endl;
118  }
119  // Get input
120  // std::cout << "DigitizerFP420 start produce" << std::endl;
121  // edm::ESHandle < ParticleDataTable > pdt;
122  // iSetup.getData( pdt );
123 
124  // Step A: Get Inputs for allTrackerHits
125 
127  std::vector<const CrossingFrame<PSimHit> *> cf_simhitvec;
128  for (uint32_t i = 0; i < trackerContainers.size(); i++) {
129  iEvent.getByLabel("mix", trackerContainers[i], cf_simhit);
130  cf_simhitvec.push_back(cf_simhit.product());
131  }
132  std::unique_ptr<MixCollection<PSimHit>> allTrackerHits(new MixCollection<PSimHit>(cf_simhitvec));
133 
134  // use instead of the previous
135  /*
136  std::cout <<" ============== DigitizerFP420: start loop 1 "
137  << std::endl; edm::Handle<CrossingFrame<PSimHit> > xFrame; std::cout <<"
138  ============== DigitizerFP420: start loop 2 " << std::endl;
139  iEvent.getByLabel("mix","FP420SI",xFrame);
140  std::cout <<" ============== DigitizerFP420: start loop 3 "
141  << std::endl; std::unique_ptr<MixCollection<PSimHit> > allTrackerHits( new
142  MixCollection<PSimHit>(xFrame.product()) ); std::cout <<" ==============
143  DigitizerFP420: start loop 4 " << std::endl;
144  */
145 
146  // Loop on PSimHit
147 
149  // Step C: create empty output collection
150  std::unique_ptr<DigiCollectionFP420> output(new DigiCollectionFP420);
151  // std::unique_ptr<edm::DetSetVector<HDigiFP420> > outputfinal(new
152  // edm::DetSetVector<HDigiFP420>(output) );
153  // std::unique_ptr<edm::DetSetVector<HDigiFP420> > outputfinal(new
154  // edm::DetSetVector<HDigiFP420>(output) );
155  // std::unique_ptr<edm::DetSetVector<HDigiFP420SimLink> > outputlink(new
156  // edm::DetSetVector<HDigiFP420SimLink>(output) );
157 
158  SimHitMap.clear();
159 
160  // ==================================
161  if (verbosity > 0) {
162  std::cout << " ===" << std::endl;
163  std::cout << " ============== DigitizerFP420: MixCollection treatment= " << std::endl;
164  std::cout << " ===" << std::endl;
165  }
166 
168  for (isim = allTrackerHits->begin(); isim != allTrackerHits->end(); isim++) {
169  unsigned int unitID = (*isim).detUnitId();
170  int det, zside, sector, zmodule;
171  FP420NumberingScheme::unpackFP420Index(unitID, det, zside, sector, zmodule);
172  // below, the continues plane index should be (for even different sensor
173  // index zside)
174  // unsigned int intindex = packMYIndex(rn0, pn0, sn0, det, zside, sector,
175  // zmodule);
176  unsigned int intindex = FP420NumberingScheme::packMYIndex(rn0, pn0, sn0, det, zside, sector, zmodule);
177  // int zScale=(rn0-1), sScale = (rn0-1)*(pn0-1), dScale =
178  //(rn0-1)*(pn0-1)*(sn0-1); unsigned int intindex = dScale*(det -
179  // 1)+sScale*(sector - 1)+zScale*(zmodule - 1)+zside;
180 
181  if (verbosity > 0) {
182  double losenergy = (*isim).energyLoss();
183  std::cout << " ===" << std::endl;
184  std::cout << " ============== DigitizerFP420: losenergy= " << losenergy << std::endl;
185  std::cout << " === for intindex = " << intindex << std::endl;
186  }
187  // does not matter which index is used: intindex or unitID - mainly to
188  // collect hits under every index
189  SimHitMap[intindex].push_back((*isim));
190  // for development later one( cal be used another index):
191  // SimHitMap[unitID].push_back((*isim));
192  }
193  //============================================================================================================================
194 
195  if (verbosity > 0) {
196  std::cout << " ===" << std::endl;
197  std::cout << " ============== DigitizerFP420: put zero to container " << std::endl;
198  std::cout << " ===" << std::endl;
199  }
200  // put zero to container info from the beginning (important! because not
201  // any detID is updated with coming of new event !!!!!!
202  // clean info of container from previous event
203  for (int det = 1; det < dn0; det++) {
204  for (int sector = 1; sector < sn0; sector++) {
205  for (int zmodule = 1; zmodule < pn0; zmodule++) {
206  for (int zside = 1; zside < rn0; zside++) {
207  // intindex is a continues numbering of FP420
208  unsigned int detID = FP420NumberingScheme::packMYIndex(rn0, pn0, sn0, det, zside, sector, zmodule);
209  // int zScale=(rn0-1), sScale = (rn0-1)*(pn0-1), dScale =
210  // (rn0-1)*(pn0-1)*(sn0-1); unsigned int detID = dScale*(det -
211  // 1)+sScale*(sector - 1)+zScale*(zmodule - 1)+zside;
212  std::vector<HDigiFP420> collector;
213  collector.clear();
215  inputRange.first = collector.begin();
216  inputRange.second = collector.end();
217  output->putclear(inputRange, detID);
218  } // for
219  } // for
220  } // for
221  } // for
222  // !!!!!!
223  // if we want to keep Digi container/Collection for one event uncomment the
224  // line below and vice versa
225  output->clear(); // container_.clear() --> start from the beginning of the
226  // container
227 
228  //============================================================================================================================================
229 
230  if (verbosity > 0) {
231  std::cout << " ===" << std::endl;
232  std::cout << " ============== DigitizerFP420: start loop over det iu " << std::endl;
233  std::cout << " ============== DigitizerFP420: SimHitMap.size()= " << SimHitMap.size() << std::endl;
234  std::cout << " ===" << std::endl;
235  }
236  bool first = true;
237 
239  /*
240  if(verbosity>0) std::cout <<"======= DigitizerFP420: SimHitMap size = " <<
241  SimHitMap.size() << std::endl; for(unsigned int i = 0; i < SimHitMap.size();
242  i++ ) {
243  // std::cout <<" ====== DigitizerFP420: i= " << i << std::endl;
244  vector<PSimHit>::const_iterator simHitIter = SimHitMap[i].begin();
245  vector<PSimHit>::const_iterator simHitIterEnd = SimHitMap[i].end();
246  for (;simHitIter != simHitIterEnd; ++simHitIter) {
247  const PSimHit ihit = *simHitIter;
248  unsigned int unitID = ihit.detUnitId();
249  if(verbosity>0) std::cout <<" ====== DigitizerFP420: unitID= " << unitID
250  << " i= " << i << std::endl; int det, zside, sector, zmodule;
251  FP420NumberingScheme::unpackFP420Index(unitID, det, zside, sector,
252  zmodule); int zScale=(rn0-1), sScale = (rn0-1)*(pn0-1), dScale =
253  (rn0-1)*(pn0-1)*(sn0-1); unsigned int iu = dScale*(det - 1)+sScale*(sector -
254  1)+zScale*(zmodule - 1)+zside;
255  }
256  }
257 */
259  //============================================================================================================================================
260  // new: <------
261  for (unsigned int i = 0; i < SimHitMap.size(); i++) {
262  vector<PSimHit>::const_iterator simHitIter = SimHitMap[i].begin();
263  vector<PSimHit>::const_iterator simHitIterEnd = SimHitMap[i].end();
264  for (; simHitIter != simHitIterEnd; ++simHitIter) {
265  const PSimHit ihit = *simHitIter;
266  unsigned int unitID = ihit.detUnitId();
267  if (verbosity > 0 || verbosity == -50)
268  std::cout << " ====== DigitizerFP420: unitID= " << unitID << "Hit number i= " << i << std::endl;
269  int det, zside, sector, zmodule;
270  FP420NumberingScheme::unpackFP420Index(unitID, det, zside, sector, zmodule);
271 
272  unsigned int iu = FP420NumberingScheme::packMYIndex(rn0, pn0, sn0, det, zside, sector, zmodule);
273  if (verbosity > 0 || verbosity == -50)
274  std::cout << "for Hits iu = " << iu << " sector = " << sector << " zmodule = " << zmodule
275  << " zside = " << zside << " det=" << det << std::endl;
276  // int zScale=(rn0-1), sScale = (rn0-1)*(pn0-1), dScale =
277  // (rn0-1)*(pn0-1)*(sn0-1);
278  // unsigned int iu = dScale*(det - 1)+sScale*(sector - 1)+zScale*(zmodule
279  // - 1)+zside;
280 
281  if (verbosity > 0) {
282  unsigned int index = FP420NumberingScheme::packFP420Index(det, zside, sector, zmodule);
283  std::cout << " DigitizerFP420: index = " << index << " iu = " << iu << std::endl;
284  }
285 
286  // GlobalVector bfield=pSetup->inTesla((*iu)->surface().position());
287  // CLHEP::Hep3Vector Bfieldloc=bfield();
288  G4ThreeVector bfield(0., 0., 0.0);
289  // G4ThreeVector bfield( 0.5, 0.5, 1.0 );
290 
291  if (verbosity > 0) {
292  std::cout << " ===" << std::endl;
293  std::cout << " ============== DigitizerFP420: call run for iu= " << iu << std::endl;
294  std::cout << " ===" << std::endl;
295  }
296  collector.clear();
297 
298  collector = stripDigitizer_->run(SimHitMap[iu], bfield,
299  iu); // stripDigitizer_.run... return
300  // ,sScale
301 
302  if (verbosity > 0) {
303  std::cout << " ===" << std::endl;
304  std::cout << " ===" << std::endl;
305  std::cout << "======= DigitizerFP420: collector size = " << collector.size() << std::endl;
306  std::cout << " ===" << std::endl;
307  std::cout << " ===" << std::endl;
308  }
309  /*
310 
311  std::vector<HDigiFP420> collector;
312  collector.clear();
313  DigiCollectionFP420::Range inputRange;
314  inputRange.first = collector.begin();
315  inputRange.second = collector.end();
316  output->putclear(inputRange,detID);
317  */
318  if (!collector.empty()) {
319  if (verbosity > 0) {
320  std::cout << " ============= DigitizerFP420:collector "
321  "start!!!!!!!!!!!!!!"
322  << std::endl;
323  }
324  DigiCollectionFP420::Range outputRange;
325  outputRange.first = collector.begin();
326  outputRange.second = collector.end();
327 
328  if (first) {
329  // use it only if ClusterCollectionFP420 is the ClusterCollection of
330  // one event, otherwise, do not use (loose 1st cl. of 1st event only)
331  first = false;
332  unsigned int detID0 = 0;
333  output->put(outputRange, detID0); // !!! put into adress 0 for detID
334  // which will not be used never
335  } // if ( first )
336 
337  // put !!!
338  output->put(outputRange, iu);
339 
340  } // if(collector.size()>0
341 
342  // } // for
343  // } // for
344  // } // for
345  // } // for
346 
347  } // for
348  } // for
349 
350  // END
351 
352  /*
353  if(verbosity>0) {
354  std::vector<HDigiFP420> theAllDigis;
355  theAllDigis.clear();
356  DigiCollectionFP420::Range outputRange;
357  DigiCollectionFP420::ContainerIterator sort_begin = outputRange.first;
358  DigiCollectionFP420::ContainerIterator sort_end = outputRange.second;
359  theAllDigis.insert(theAllDigis.end(), sort_begin, sort_end);
360  std::cout <<"====== theAllDigis size = " << theAllDigis.size() <<
361  std::endl; for (std::vector<HDigiFP420>::iterator isim = theAllDigis.begin();
362  isim != theAllDigis.end(); ++isim){
363  const HDigiFP420 istrip = *isim;
364  std::cout <<
365  "*******************************************DigitizerFP420:check1" <<
366  std::endl; std::cout << " strip number=" << istrip.strip() << " adc=" <<
367  istrip.adc() << std::endl; std::cout <<" channel =" << istrip.channel() <<" V
368  " << istrip.stripV() <<" VW " << istrip.stripVW() << std::endl; std::cout <<"
369  ===" << std::endl; std::cout <<" ===" << std::endl; std::cout <<"
370  =======================" << std::endl;
371  }// for
372  }
373 */
374  if (verbosity == -50) {
375  // check of access to the collector:
376  for (int det = 1; det < dn0; det++) {
377  for (int sector = 1; sector < sn0; sector++) {
378  for (int zmodule = 1; zmodule < pn0; zmodule++) {
379  for (int zside = 1; zside < rn0; zside++) {
380  unsigned int iu = FP420NumberingScheme::packMYIndex(rn0, pn0, sn0, det, zside, sector, zmodule);
383  std::cout << "****DigitizerFP420:check2" << std::endl;
384  // std::cout <<" iu = " << iu <<" sector = " << sector <<" zmodule
385  //= " << zmodule <<" zside = " << zside << " det=" << det <<
386  // std::endl; std::cout <<" layer = " << layer <<" orient = "
387  // << orient << std::endl;
388  int newdet, newzside, newsector, newzmodule;
389  FP420NumberingScheme::unpackMYIndex(iu, rn0, pn0, sn0, newdet, newzside, newsector, newzmodule);
390  std::cout << " newdet = " << newdet << " newsector = " << newsector << " newzmodule = " << newzmodule
391  << " newzside = " << newzside << std::endl;
392 
393  collector.clear();
394  DigiCollectionFP420::Range outputRange;
395  // outputRange = output->get(iu);
396  outputRange = output->get(iu);
397 
398  // fill output in collector vector (for may be sorting? or other
399  // checks)
400  std::vector<HDigiFP420> collector;
401  // collector.clear();
402  DigiCollectionFP420::ContainerIterator sort_begin = outputRange.first;
403  DigiCollectionFP420::ContainerIterator sort_end = outputRange.second;
404  for (; sort_begin != sort_end; ++sort_begin) {
405  collector.push_back(*sort_begin);
406  } // for
407  // std::sort(collector.begin(),collector.end());
408  std::cout << " ===" << std::endl;
409  std::cout << "====== collector size = " << collector.size() << std::endl;
410  if (!collector.empty()) {
411  std::cout << " iu = " << iu << " sector = " << sector << " zmodule = " << zmodule
412  << " zside = " << zside << " det=" << det << " layer = " << layer << " orient = " << orient
413  << std::endl;
414  std::cout << " ===" << std::endl;
415  }
416  vector<HDigiFP420>::const_iterator simHitIter = collector.begin();
417  vector<HDigiFP420>::const_iterator simHitIterEnd = collector.end();
418  for (; simHitIter != simHitIterEnd; ++simHitIter) {
419  const HDigiFP420 istrip = *simHitIter;
420  std::cout << " strip number=" << istrip.strip() << " adc=" << istrip.adc() << std::endl;
421  std::cout << " channel =" << istrip.channel() << " V " << istrip.stripV() << " VW " << istrip.stripVW()
422  << std::endl;
423  std::cout << " ===" << std::endl;
424  std::cout << " ===" << std::endl;
425  std::cout << " ===================================================" << std::endl;
426  }
427 
428  //==================================
429 
430  } // for
431  } // for
432  } // for
433  } // for
434 
435  // end of check of access to the strip collection
436 
437  } // if(verbosity
438 
439  // Step D: write output to file
440  if (verbosity > 0) {
441  std::cout << "DigitizerFP420 recoutput" << std::endl;
442  }
443  // Step D: write output to file
444  iEvent.put(std::move(output));
445  } // produce
446 
447 } // namespace cms
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
unsigned int detUnitId() const
Definition: PSimHit.h:97
FP420DigiMain * stripDigitizer_
int stripVW() const
Definition: HDigiFP420.h:21
std::vector< HDigiFP420 >::const_iterator ContainerIterator
T const * product() const
Definition: Handle.h:70
static void unpackFP420Index(const unsigned int &idx, int &det, int &zside, int &station, int &superplane)
edm::ParameterSet conf_
int zside(DetId const &)
static int unpackLayerIndex(int rn0, int zside)
void produce(edm::Event &e, const edm::EventSetup &c) override
std::vector< HDigiFP420 > collector
static void unpackMYIndex(const int &idx, int rn0, int pn0, int sn0, int &det, int &zside, int &sector, int &zmodule)
constexpr std::array< uint8_t, layerIndexSize > layer
T getUntrackedParameter(std::string const &, T const &) const
std::vector< HDigiFP420 > run(const std::vector< PSimHit > &input, const G4ThreeVector &, unsigned int)
int iEvent
Definition: GenABIO.cc:224
int stripV() const
Definition: HDigiFP420.h:23
static unsigned packMYIndex(int rn0, int pn0, int sn0, int det, int zside, int sector, int zmodule)
int channel() const
Definition: HDigiFP420.h:19
~DigitizerFP420() override
static unsigned int packFP420Index(int det, int zside, int station, int superplane)
std::pair< ContainerIterator, ContainerIterator > Range
Namespace of DDCMS conversion namespace.
HLT enums.
int adc() const
Definition: HDigiFP420.h:18
static int unpackOrientation(int rn0, int zside)
int strip() const
Definition: HDigiFP420.h:17
def move(src, dest)
Definition: eostools.py:511