CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 //#include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
13 //#include "DataFormats/SiStripDigi/interface/SiStripRawDigi.h"
14 //#include "SimDataFormats/TrackerDigiSimLink/interface/StripDigiSimLink.h"
15 
16 // user include files
19 
22 
30 
31 //#include "SimRomanPot/SimFP420/interface/SimRPUtil.h"
32 //#include "SimG4CMS/FP420/interface/FP420NumberingScheme.h"
33 
36 //#include "SimRomanPot/SimFP420/interface/DigiCollectionFP420.h"
37 //#include "SimG4CMS/FP420/interface/FP420G4HitCollection.h"
38 //#include "SimG4CMS/FP420/interface/FP420G4Hit.h"
39 
40 //needed for the geometry:
47 //#include "Geometry/CommonTopologies/interface/StripTopology.h"
48 //#include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetType.h"
49 //#include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
50 //needed for the magnetic field:
51 //#include "MagneticField/Engine/interface/MagneticField.h"
52 //#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
53 //#include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
55 
56 //Data Base infromations
57 //#include "CondFormats/DataRecord/interface/SiStripLorentzAngleRcd.h"
58 //#include "CalibTracker/Records/interface/SiStripGainRcd.h"
59 //#include "CondFormats/DataRecord/interface/SiStripNoisesRcd.h"
60 //#include "CondFormats/DataRecord/interface/SiStripPedestalsRcd.h"
61 //#include "CondFormats/SiStripObjects/interface/SiStripLorentzAngle.h"
62 //#include "CondFormats/SiStripObjects/interface/SiStripNoises.h"
63 //#include "CondFormats/SiStripObjects/interface/SiStripPedestals.h"
64 //#include "CalibFormats/SiStripObjects/interface/SiStripGain.h"
65 //#include "CalibTracker/Records/interface/SiStripDetCablingRcd.h"
66 //#include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
67 
68 //Random Number
72 #include "CLHEP/Random/RandomEngine.h"
73 
74 // G4 stuff
75 #include "G4SDManager.hh"
76 #include "G4Step.hh"
77 #include "G4Track.hh"
78 #include "G4VProcess.hh"
79 #include "G4HCofThisEvent.hh"
80 #include "G4UserEventAction.hh"
81 #include "G4TransportationManager.hh"
82 #include "G4ProcessManager.hh"
83 
84 #include <cstdlib>
85 #include <vector>
86 
87 using namespace std;
88 
89 //#include <iostream>
90 
91 
92 
93 
94 namespace cms
95 {
96  DigitizerFP420::DigitizerFP420(const edm::ParameterSet& conf):conf_(conf),stripDigitizer_(new FP420DigiMain(conf)) {
97 
98 
99  std::string alias ( conf.getParameter<std::string>("@module_label") );
100 
101  // produces<edm::DetSetVector<HDigiFP420> >().setBranchAlias( alias );
102  // produces<edm::DetSetVector<HDigiFP420SimLink> >().setBranchAlias ( alias + "hDigiFP420SimLink");
103  produces<DigiCollectionFP420>().setBranchAlias( alias );
104 
105  trackerContainers.clear();
106  trackerContainers = conf.getParameter<std::vector<std::string> >("ROUList");
107 
108  verbosity = conf_.getUntrackedParameter<int>("VerbosityLevel");
109  dn0 = conf_.getParameter<int>("NumberFP420Detectors");
110  sn0 = conf_.getParameter<int>("NumberFP420Stations");
111  pn0 = conf_.getParameter<int>("NumberFP420SPlanes");
112  rn0 = 7;
113  //rn0 = 3;
114 
115  // produces<DigiCollectionFP420>();
116 
117  // produces<StripDigiCollection>();
118  // produces<HDigiFP420>();
119  // produces<edm::DetSetVector<HDigiFP420> >().setBranchAlias( alias );
120 
121  // produces<DigiCollectionFP420>();
122  // produces<DigiCollectionFP420>("HDigiFP420");
123 
124  // produces<edm::DigiCollectionFP420>();
125 
126  // produces<edm::DetSetVector<DigiCollectionFP420> >();
127 
128  if(verbosity>0) {
129  std::cout << "Creating a DigitizerFP420" << std::endl;
130  std::cout << "DigitizerFP420: dn0=" << dn0 << " sn0=" << sn0 << " pn0=" << pn0 << " rn0=" << rn0 << std::endl;
131  std::cout << "DigitizerFP420:trackerContainers.size()=" << trackerContainers.size() << std::endl;
132 
133  }
134  }
135 
136  // Virtual destructor needed.
138  if(verbosity>0) {
139  std::cout << "Destroying a DigitizerFP420" << std::endl;
140  }
141  delete stripDigitizer_;
142 
143  }
144 
145 
146 
147  // void DigitizerFP420::produce(PSimHitCollection * theCAFI, DigiCollectionFP420 & output) {
149  // be lazy and include the appropriate namespaces
150  using namespace edm;
151  using namespace std;
152 
153  if(verbosity>0) {
154  std::cout <<" ===" << std::endl;
155  std::cout <<" ============== DigitizerFP420: start produce= " << std::endl;
156  std::cout <<" ===" << std::endl;
157  }
158  // Get input
159  // std::cout << "DigitizerFP420 start produce" << std::endl;
160  // edm::ESHandle < ParticleDataTable > pdt;
161  // iSetup.getData( pdt );
162 
163  // Step A: Get Inputs for allTrackerHits
164 
165 
167  std::vector<const CrossingFrame<PSimHit> *> cf_simhitvec;
168  for(uint32_t i = 0; i< trackerContainers.size();i++){
169  iEvent.getByLabel("mix",trackerContainers[i],cf_simhit);
170  cf_simhitvec.push_back(cf_simhit.product()); }
171  std::auto_ptr<MixCollection<PSimHit> > allTrackerHits(new MixCollection<PSimHit>(cf_simhitvec));
172 
173  // use instead of the previous
174  /*
175  std::cout <<" ============== DigitizerFP420: start loop 1 " << std::endl;
176  edm::Handle<CrossingFrame<PSimHit> > xFrame;
177  std::cout <<" ============== DigitizerFP420: start loop 2 " << std::endl;
178  iEvent.getByLabel("mix","FP420SI",xFrame);
179  std::cout <<" ============== DigitizerFP420: start loop 3 " << std::endl;
180  std::auto_ptr<MixCollection<PSimHit> > allTrackerHits( new MixCollection<PSimHit>(xFrame.product()) );
181  std::cout <<" ============== DigitizerFP420: start loop 4 " << std::endl;
182  */
183 
184  // use instead of the previous
185  /*
186  edm::Handle<CrossingFrame<PSimHit> > crossingFrame;
187  const std::string FP420HitsName("FP420SI");
188  bool isHit = true;
189  iEvent.getByLabel("mix",FP420HitsName,crossingFrame);
190  MixCollection<PSimHit> * FP420Hits = 0 ;
191  std::cout <<" ============== DigitizerFP420: start loop 1 " << std::endl;
192  // std::auto_ptr<MixCollection<PSimHit> > allTrackerHits(new MixCollection<PSimHit>(crossingFrame.product()));
193  FP420Hits = new MixCollection<PSimHit>(crossingFrame.product());
194  std::cout <<" ============== DigitizerFP420: start loop 2 " << std::endl;
195  // if ( ! FP420Hits->inRegistry() ) isHit = false;
196  // if ( isHit ) {
197  std::auto_ptr<MixCollection<PSimHit> > allTrackerHits( FP420Hits );
198  std::cout <<" ============== DigitizerFP420: start loop 3 " << std::endl;
199  // }
200  */
201 
202  // std::cout << "DigitizerFP420 Step A done" << std::endl;
203 
204  //Loop on PSimHit
205 
206 
208  // Step C: create empty output collection
209  std::auto_ptr<DigiCollectionFP420> output(new DigiCollectionFP420);
210  // std::auto_ptr<edm::DetSetVector<HDigiFP420> > outputfinal(new edm::DetSetVector<HDigiFP420>(output) );
211  // std::auto_ptr<edm::DetSetVector<HDigiFP420> > outputfinal(new edm::DetSetVector<HDigiFP420>(output) );
212  // std::auto_ptr<edm::DetSetVector<HDigiFP420SimLink> > outputlink(new edm::DetSetVector<HDigiFP420SimLink>(output) );
213 
214  SimHitMap.clear();
215 
216  // ==================================
217  if(verbosity>0) {
218  std::cout <<" ===" << std::endl;
219  std::cout <<" ============== DigitizerFP420: MixCollection treatment= " << std::endl;
220  std::cout <<" ===" << std::endl;
221  }
222 
224  for (isim=allTrackerHits->begin(); isim!= allTrackerHits->end();isim++) {
225  unsigned int unitID = (*isim).detUnitId();
226  int det, zside, sector, zmodule;
227  FP420NumberingScheme::unpackFP420Index(unitID, det, zside, sector, zmodule);
228  // below, the continues plane index should be (for even different sensor index zside)
229  // unsigned int intindex = packMYIndex(rn0, pn0, sn0, det, zside, sector, zmodule);
230  unsigned int intindex = FP420NumberingScheme::packMYIndex(rn0, pn0, sn0, det, zside, sector, zmodule);
231  // int zScale=(rn0-1), sScale = (rn0-1)*(pn0-1), dScale = (rn0-1)*(pn0-1)*(sn0-1);
232  // unsigned int intindex = dScale*(det - 1)+sScale*(sector - 1)+zScale*(zmodule - 1)+zside;
233 
234  if(verbosity>0) {
235  double losenergy = (*isim).energyLoss();
236  std::cout <<" ===" << std::endl;
237  std::cout <<" ============== DigitizerFP420: losenergy= " << losenergy << std::endl;
238  std::cout <<" === for intindex = " << intindex << std::endl;
239  }
240  // does not matter which index is used: intindex or unitID - mainly to collect hits under every index
241  SimHitMap[intindex].push_back((*isim));
242  // for development later one( cal be used another index):
243  // SimHitMap[unitID].push_back((*isim));
244  }
245  //============================================================================================================================
246 
247  if(verbosity>0) {
248  std::cout <<" ===" << std::endl;
249  std::cout <<" ============== DigitizerFP420: put zero to container " << std::endl;
250  std::cout <<" ===" << std::endl;
251  }
252  // put zero to container info from the beginning (important! because not any detID is updated with coming of new event !!!!!!
253  // clean info of container from previous event
254  for (int det=1; det<dn0; det++) {
255  for (int sector=1; sector<sn0; sector++) {
256  for (int zmodule=1; zmodule<pn0; zmodule++) {
257  for (int zside=1; zside<rn0; zside++) {
258  // intindex is a continues numbering of FP420
259  unsigned int detID = FP420NumberingScheme::packMYIndex(rn0, pn0, sn0, det, zside, sector, zmodule);
260  // int zScale=(rn0-1), sScale = (rn0-1)*(pn0-1), dScale = (rn0-1)*(pn0-1)*(sn0-1);
261  // unsigned int detID = dScale*(det - 1)+sScale*(sector - 1)+zScale*(zmodule - 1)+zside;
262  std::vector<HDigiFP420> collector;
263  collector.clear();
265  inputRange.first = collector.begin();
266  inputRange.second = collector.end();
267  output->putclear(inputRange,detID);
268  }//for
269  }//for
270  }//for
271  }//for
272  // !!!!!!
273  // if we want to keep Digi container/Collection for one event uncomment the line below and vice versa
274  output->clear(); //container_.clear() --> start from the beginning of the container
275 
276  //============================================================================================================================================
277 
278 
279  if(verbosity>0) {
280  std::cout <<" ===" << std::endl;
281  std::cout <<" ============== DigitizerFP420: start loop over det iu " << std::endl;
282  std::cout <<" ============== DigitizerFP420: SimHitMap.size()= " << SimHitMap.size() << std::endl;
283  std::cout <<" ===" << std::endl;
284  }
285  bool first = true;
286 
288  /*
289  if(verbosity>0) std::cout <<"======= DigitizerFP420: SimHitMap size = " << SimHitMap.size() << std::endl;
290  for(unsigned int i = 0; i < SimHitMap.size(); i++ ) {
291  // std::cout <<" ====== DigitizerFP420: i= " << i << std::endl;
292  vector<PSimHit>::const_iterator simHitIter = SimHitMap[i].begin();
293  vector<PSimHit>::const_iterator simHitIterEnd = SimHitMap[i].end();
294  for (;simHitIter != simHitIterEnd; ++simHitIter) {
295  const PSimHit ihit = *simHitIter;
296  unsigned int unitID = ihit.detUnitId();
297  if(verbosity>0) std::cout <<" ====== DigitizerFP420: unitID= " << unitID << " i= " << i << std::endl;
298  int det, zside, sector, zmodule;
299  FP420NumberingScheme::unpackFP420Index(unitID, det, zside, sector, zmodule);
300  int zScale=(rn0-1), sScale = (rn0-1)*(pn0-1), dScale = (rn0-1)*(pn0-1)*(sn0-1);
301  unsigned int iu = dScale*(det - 1)+sScale*(sector - 1)+zScale*(zmodule - 1)+zside;
302  }
303  }
304 */
306  //============================================================================================================================================
307  // new: <------
308  for(unsigned int i = 0; i < SimHitMap.size(); i++ ) {
309  vector<PSimHit>::const_iterator simHitIter = SimHitMap[i].begin();
310  vector<PSimHit>::const_iterator simHitIterEnd = SimHitMap[i].end();
311  for (;simHitIter != simHitIterEnd; ++simHitIter) {
312  const PSimHit ihit = *simHitIter;
313  unsigned int unitID = ihit.detUnitId();
314  if(verbosity>0 || verbosity==-50) std::cout <<" ====== DigitizerFP420: unitID= " << unitID << "Hit number i= " << i << std::endl;
315  int det, zside, sector, zmodule;
316  FP420NumberingScheme::unpackFP420Index(unitID, det, zside, sector, zmodule);
317  // <------
318  // old: <------
319  // for (int det=1; det<dn0; det++) {
320  // for (int sector=1; sector<sn0; sector++) {
321  // for (int zmodule=1; zmodule<pn0; zmodule++) {
322  // for (int zside=1; zside<rn0; zside++) {
323  // <------
324 
325 
326 
327 
328 
329  unsigned int iu = FP420NumberingScheme::packMYIndex(rn0, pn0, sn0, det, zside, sector, zmodule);
330  if(verbosity>0 || verbosity==-50) std::cout <<"for Hits iu = " << iu <<" sector = " << sector <<" zmodule = " << zmodule <<" zside = " << zside << " det=" << det << std::endl;
331  // int zScale=(rn0-1), sScale = (rn0-1)*(pn0-1), dScale = (rn0-1)*(pn0-1)*(sn0-1);
332  // unsigned int iu = dScale*(det - 1)+sScale*(sector - 1)+zScale*(zmodule - 1)+zside;
333 
334  if(verbosity>0) {
335  unsigned int index = FP420NumberingScheme::packFP420Index(det, zside, sector, zmodule);
336  std::cout << " DigitizerFP420: index = " << index << " iu = " << iu << std::endl;
337  }
338 
339  // GlobalVector bfield=pSetup->inTesla((*iu)->surface().position());
340  // CLHEP::Hep3Vector Bfieldloc=bfield();
341  G4ThreeVector bfield( 0., 0., 0.0 );
342  // G4ThreeVector bfield( 0.5, 0.5, 1.0 );
343 
344 
345  if(verbosity>0) {
346  std::cout <<" ===" << std::endl;
347  std::cout <<" ============== DigitizerFP420: call run for iu= " << iu << std::endl;
348  std::cout <<" ===" << std::endl;
349  }
350  collector.clear();
351 
353  bfield,
354  iu
355  ); // stripDigitizer_.run... return
356  // ,sScale
357 
358 
359 
360  if(verbosity>0) {
361  std::cout <<" ===" << std::endl;
362  std::cout <<" ===" << std::endl;
363  std::cout <<"======= DigitizerFP420: collector size = " << collector.size() << std::endl;
364  std::cout <<" ===" << std::endl;
365  std::cout <<" ===" << std::endl;
366  }
367  /*
368 
369  std::vector<HDigiFP420> collector;
370  collector.clear();
371  DigiCollectionFP420::Range inputRange;
372  inputRange.first = collector.begin();
373  inputRange.second = collector.end();
374  output->putclear(inputRange,detID);
375  */
376  if (collector.size()>0){
377  if(verbosity>0) {
378  std::cout <<" ============= DigitizerFP420:collector start!!!!!!!!!!!!!!" << std::endl;
379  }
380  DigiCollectionFP420::Range outputRange;
381  outputRange.first = collector.begin();
382  outputRange.second = collector.end();
383 
384  if ( first ) {
385  // use it only if ClusterCollectionFP420 is the ClusterCollection of one event, otherwise, do not use (loose 1st cl. of 1st event only)
386  first = false;
387  unsigned int detID0= 0;
388  output->put(outputRange,detID0); // !!! put into adress 0 for detID which will not be used never
389  } //if ( first )
390 
391  // put !!!
392  output->put(outputRange,iu);
393 
394  } // if(collector.size()>0
395 
396  // } // for
397  // } // for
398  // } // for
399  // } // for
400 
401  }//for
402  }//for
403 
404  // END
405 
406  /*
407  if(verbosity>0) {
408  std::vector<HDigiFP420> theAllDigis;
409  theAllDigis.clear();
410  DigiCollectionFP420::Range outputRange;
411  DigiCollectionFP420::ContainerIterator sort_begin = outputRange.first;
412  DigiCollectionFP420::ContainerIterator sort_end = outputRange.second;
413  theAllDigis.insert(theAllDigis.end(), sort_begin, sort_end);
414  std::cout <<"====== theAllDigis size = " << theAllDigis.size() << std::endl;
415  for (std::vector<HDigiFP420>::iterator isim = theAllDigis.begin();
416  isim != theAllDigis.end(); ++isim){
417  const HDigiFP420 istrip = *isim;
418  std::cout << "*******************************************DigitizerFP420:check1" << std::endl;
419  std::cout << " strip number=" << istrip.strip() << " adc=" << istrip.adc() << std::endl;
420  std::cout <<" channel =" << istrip.channel() <<" V " << istrip.stripV() <<" VW " << istrip.stripVW() << std::endl;
421  std::cout <<" ===" << std::endl;
422  std::cout <<" ===" << std::endl;
423  std::cout <<" =======================" << std::endl;
424  }// for
425  }
426 */
427  if(verbosity==-50) {
428  // check of access to the collector:
429  for (int det=1; det<dn0; det++) {
430  for (int sector=1; sector<sn0; sector++) {
431  for (int zmodule=1; zmodule<pn0; zmodule++) {
432  for (int zside=1; zside<rn0; zside++) {
433  unsigned int iu = FP420NumberingScheme::packMYIndex(rn0, pn0, sn0, det, zside, sector, zmodule);
436  std::cout << "****DigitizerFP420:check2" << std::endl;
437  // std::cout <<" iu = " << iu <<" sector = " << sector <<" zmodule = " << zmodule <<" zside = " << zside << " det=" << det << std::endl;
438  // std::cout <<" layer = " << layer <<" orient = " << orient << std::endl;
439  int newdet, newzside, newsector, newzmodule;
440  FP420NumberingScheme::unpackMYIndex(iu, rn0, pn0, sn0, newdet, newzside, newsector, newzmodule);
441  std::cout <<" newdet = " << newdet <<" newsector = " << newsector <<" newzmodule = " << newzmodule <<" newzside = " << newzside << std::endl;
442 
443  collector.clear();
444  DigiCollectionFP420::Range outputRange;
445  // outputRange = output->get(iu);
446  outputRange = output->get(iu);
447 
448  // fill output in collector vector (for may be sorting? or other checks)
449  std::vector<HDigiFP420> collector;
450  // collector.clear();
451  DigiCollectionFP420::ContainerIterator sort_begin = outputRange.first;
452  DigiCollectionFP420::ContainerIterator sort_end = outputRange.second;
453  for ( ;sort_begin != sort_end; ++sort_begin ) {
454  collector.push_back(*sort_begin);
455  } // for
456  // std::sort(collector.begin(),collector.end());
457  std::cout <<" ===" << std::endl;
458  std::cout <<"====== collector size = " << collector.size() << std::endl;
459  if(collector.size()>0) {
460  std::cout <<" iu = " << iu <<" sector = " << sector <<" zmodule = " << zmodule <<" zside = " << zside << " det=" << det <<" layer = " << layer <<" orient = " << orient << std::endl;
461  std::cout <<" ===" << std::endl;
462  }
463  vector<HDigiFP420>::const_iterator simHitIter = collector.begin();
464  vector<HDigiFP420>::const_iterator simHitIterEnd = collector.end();
465  for (;simHitIter != simHitIterEnd; ++simHitIter) {
466  const HDigiFP420 istrip = *simHitIter;
467  std::cout << " strip number=" << istrip.strip() << " adc=" << istrip.adc() << std::endl;
468  std::cout <<" channel =" << istrip.channel() <<" V " << istrip.stripV() <<" VW " << istrip.stripVW() << std::endl;
469  std::cout <<" ===" << std::endl;
470  std::cout <<" ===" << std::endl;
471  std::cout <<" ===================================================" << std::endl;
472  }
473 
474  //==================================
475 
476  } // for
477  } // for
478  } // for
479  } // for
480 
481  // end of check of access to the strip collection
482 
483  }// if(verbosity
484  //
485 
486 
487  // Step D: write output to file
488  // iEvent.put(output);
489 
490  if(verbosity>0) {
491  std::cout << "DigitizerFP420 recoutput" << std::endl;
492  }
493  // Step D: write output to file
494  iEvent.put(output);
495  // iEvent.put(outputlink);
496  // iEvent.put(pDigis);
497 
498  // Step D: write output to file
499  // iEvent.put(output);
500  // iEvent.put(outputlink);
501  //-------------------------------------------------------------------
502  // std::cout << "DigitizerFP420 recoutput" << std::endl;
503  // iEvent.put(pDigis);
504 
505 
506 
507 
508  }//produce
509 
510 } // namespace cms
511 
512 //}
513 //define this as a plug-in
514 
515 //DEFINE_FWK_MODULE(DigitizerFP420);
T getParameter(std::string const &) const
int channel() const
Definition: HDigiFP420.h:22
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
inputRange
Get input source.
FP420DigiMain * stripDigitizer_
int stripVW() const
Definition: HDigiFP420.h:24
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)
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:20
int iEvent
Definition: GenABIO.cc:230
static unsigned packMYIndex(int rn0, int pn0, int sn0, int det, int zside, int sector, int zmodule)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
int adc() const
Definition: HDigiFP420.h:21
bool first
Definition: L1TdeRCT.cc:75
static unsigned int packFP420Index(int det, int zside, int station, int superplane)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:402
tuple conf
Definition: dbtoconf.py:185
std::pair< ContainerIterator, ContainerIterator > Range
tuple cout
Definition: gather_cfg.py:121
virtual void produce(edm::Event &e, const edm::EventSetup &c)
static int unpackOrientation(int rn0, int zside)
unsigned int detUnitId() const
Definition: PSimHit.h:93
int stripV() const
Definition: HDigiFP420.h:26