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