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
44 #include "CLHEP/Random/RandomEngine.h"
45 
46 // G4 stuff
47 #include "G4SDManager.hh"
48 #include "G4Step.hh"
49 #include "G4Track.hh"
50 #include "G4VProcess.hh"
51 #include "G4HCofThisEvent.hh"
52 #include "G4UserEventAction.hh"
53 #include "G4TransportationManager.hh"
54 #include "G4ProcessManager.hh"
55 
56 #include <cstdlib>
57 #include <vector>
58 
59 using namespace std;
60 
61 namespace cms
62 {
63  DigitizerFP420::DigitizerFP420(const edm::ParameterSet& conf):conf_(conf),stripDigitizer_(new FP420DigiMain(conf)) {
64 
65  std::string alias ( conf.getParameter<std::string>("@module_label") );
66 
67  // produces<edm::DetSetVector<HDigiFP420> >().setBranchAlias( alias );
68  // produces<edm::DetSetVector<HDigiFP420SimLink> >().setBranchAlias ( alias + "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, 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  std::unique_ptr<MixCollection<PSimHit> > allTrackerHits(new MixCollection<PSimHit>(cf_simhitvec));
132 
133  // use instead of the previous
134  /*
135  std::cout <<" ============== DigitizerFP420: start loop 1 " << std::endl;
136  edm::Handle<CrossingFrame<PSimHit> > xFrame;
137  std::cout <<" ============== DigitizerFP420: start loop 2 " << std::endl;
138  iEvent.getByLabel("mix","FP420SI",xFrame);
139  std::cout <<" ============== DigitizerFP420: start loop 3 " << std::endl;
140  std::unique_ptr<MixCollection<PSimHit> > allTrackerHits( new MixCollection<PSimHit>(xFrame.product()) );
141  std::cout <<" ============== DigitizerFP420: start loop 4 " << std::endl;
142  */
143 
144  //Loop on PSimHit
145 
146 
148  // Step C: create empty output collection
149  std::unique_ptr<DigiCollectionFP420> output(new DigiCollectionFP420);
150  // std::unique_ptr<edm::DetSetVector<HDigiFP420> > outputfinal(new edm::DetSetVector<HDigiFP420>(output) );
151  // std::unique_ptr<edm::DetSetVector<HDigiFP420> > outputfinal(new edm::DetSetVector<HDigiFP420>(output) );
152  // std::unique_ptr<edm::DetSetVector<HDigiFP420SimLink> > outputlink(new edm::DetSetVector<HDigiFP420SimLink>(output) );
153 
154  SimHitMap.clear();
155 
156  // ==================================
157  if(verbosity>0) {
158  std::cout <<" ===" << std::endl;
159  std::cout <<" ============== DigitizerFP420: MixCollection treatment= " << std::endl;
160  std::cout <<" ===" << std::endl;
161  }
162 
164  for (isim=allTrackerHits->begin(); isim!= allTrackerHits->end();isim++) {
165  unsigned int unitID = (*isim).detUnitId();
166  int det, zside, sector, zmodule;
167  FP420NumberingScheme::unpackFP420Index(unitID, det, zside, sector, zmodule);
168  // below, the continues plane index should be (for even different sensor index zside)
169  // unsigned int intindex = packMYIndex(rn0, pn0, sn0, det, zside, sector, zmodule);
170  unsigned int intindex = FP420NumberingScheme::packMYIndex(rn0, pn0, sn0, det, zside, sector, zmodule);
171  // int zScale=(rn0-1), sScale = (rn0-1)*(pn0-1), dScale = (rn0-1)*(pn0-1)*(sn0-1);
172  // unsigned int intindex = dScale*(det - 1)+sScale*(sector - 1)+zScale*(zmodule - 1)+zside;
173 
174  if(verbosity>0) {
175  double losenergy = (*isim).energyLoss();
176  std::cout <<" ===" << std::endl;
177  std::cout <<" ============== DigitizerFP420: losenergy= " << losenergy << std::endl;
178  std::cout <<" === for intindex = " << intindex << std::endl;
179  }
180  // does not matter which index is used: intindex or unitID - mainly to collect hits under every index
181  SimHitMap[intindex].push_back((*isim));
182  // for development later one( cal be used another index):
183  // SimHitMap[unitID].push_back((*isim));
184  }
185  //============================================================================================================================
186 
187  if(verbosity>0) {
188  std::cout <<" ===" << std::endl;
189  std::cout <<" ============== DigitizerFP420: put zero to container " << std::endl;
190  std::cout <<" ===" << std::endl;
191  }
192  // put zero to container info from the beginning (important! because not any detID is updated with coming of new event !!!!!!
193  // clean info of container from previous event
194  for (int det=1; det<dn0; det++) {
195  for (int sector=1; sector<sn0; sector++) {
196  for (int zmodule=1; zmodule<pn0; zmodule++) {
197  for (int zside=1; zside<rn0; zside++) {
198  // intindex is a continues numbering of FP420
199  unsigned int detID = FP420NumberingScheme::packMYIndex(rn0, pn0, sn0, det, zside, sector, zmodule);
200  // int zScale=(rn0-1), sScale = (rn0-1)*(pn0-1), dScale = (rn0-1)*(pn0-1)*(sn0-1);
201  // unsigned int detID = dScale*(det - 1)+sScale*(sector - 1)+zScale*(zmodule - 1)+zside;
202  std::vector<HDigiFP420> collector;
203  collector.clear();
205  inputRange.first = collector.begin();
206  inputRange.second = collector.end();
207  output->putclear(inputRange,detID);
208  }//for
209  }//for
210  }//for
211  }//for
212  // !!!!!!
213  // if we want to keep Digi container/Collection for one event uncomment the line below and vice versa
214  output->clear(); //container_.clear() --> start from the beginning of the container
215 
216  //============================================================================================================================================
217 
218 
219  if(verbosity>0) {
220  std::cout <<" ===" << std::endl;
221  std::cout <<" ============== DigitizerFP420: start loop over det iu " << std::endl;
222  std::cout <<" ============== DigitizerFP420: SimHitMap.size()= " << SimHitMap.size() << std::endl;
223  std::cout <<" ===" << std::endl;
224  }
225  bool first = true;
226 
228  /*
229  if(verbosity>0) std::cout <<"======= DigitizerFP420: SimHitMap size = " << SimHitMap.size() << std::endl;
230  for(unsigned int i = 0; i < SimHitMap.size(); i++ ) {
231  // std::cout <<" ====== DigitizerFP420: i= " << i << std::endl;
232  vector<PSimHit>::const_iterator simHitIter = SimHitMap[i].begin();
233  vector<PSimHit>::const_iterator simHitIterEnd = SimHitMap[i].end();
234  for (;simHitIter != simHitIterEnd; ++simHitIter) {
235  const PSimHit ihit = *simHitIter;
236  unsigned int unitID = ihit.detUnitId();
237  if(verbosity>0) std::cout <<" ====== DigitizerFP420: unitID= " << unitID << " i= " << i << std::endl;
238  int det, zside, sector, zmodule;
239  FP420NumberingScheme::unpackFP420Index(unitID, det, zside, sector, zmodule);
240  int zScale=(rn0-1), sScale = (rn0-1)*(pn0-1), dScale = (rn0-1)*(pn0-1)*(sn0-1);
241  unsigned int iu = dScale*(det - 1)+sScale*(sector - 1)+zScale*(zmodule - 1)+zside;
242  }
243  }
244 */
246  //============================================================================================================================================
247  // new: <------
248  for(unsigned int i = 0; i < SimHitMap.size(); i++ ) {
249  vector<PSimHit>::const_iterator simHitIter = SimHitMap[i].begin();
250  vector<PSimHit>::const_iterator simHitIterEnd = SimHitMap[i].end();
251  for (;simHitIter != simHitIterEnd; ++simHitIter) {
252  const PSimHit ihit = *simHitIter;
253  unsigned int unitID = ihit.detUnitId();
254  if(verbosity>0 || verbosity==-50) std::cout <<" ====== DigitizerFP420: unitID= " << unitID << "Hit number i= " << i << std::endl;
255  int det, zside, sector, zmodule;
256  FP420NumberingScheme::unpackFP420Index(unitID, det, zside, sector, zmodule);
257 
258  unsigned int iu = FP420NumberingScheme::packMYIndex(rn0, pn0, sn0, det, zside, sector, zmodule);
259  if(verbosity>0 || verbosity==-50) std::cout <<"for Hits iu = " << iu <<" sector = " << sector <<" zmodule = " << zmodule <<" zside = " << zside << " det=" << det << std::endl;
260  // int zScale=(rn0-1), sScale = (rn0-1)*(pn0-1), dScale = (rn0-1)*(pn0-1)*(sn0-1);
261  // unsigned int iu = dScale*(det - 1)+sScale*(sector - 1)+zScale*(zmodule - 1)+zside;
262 
263  if(verbosity>0) {
264  unsigned int index = FP420NumberingScheme::packFP420Index(det, zside, sector, zmodule);
265  std::cout << " DigitizerFP420: index = " << index << " iu = " << iu << std::endl;
266  }
267 
268  // GlobalVector bfield=pSetup->inTesla((*iu)->surface().position());
269  // CLHEP::Hep3Vector Bfieldloc=bfield();
270  G4ThreeVector bfield( 0., 0., 0.0 );
271  // G4ThreeVector bfield( 0.5, 0.5, 1.0 );
272 
273 
274  if(verbosity>0) {
275  std::cout <<" ===" << std::endl;
276  std::cout <<" ============== DigitizerFP420: call run for iu= " << iu << std::endl;
277  std::cout <<" ===" << std::endl;
278  }
279  collector.clear();
280 
282  bfield,
283  iu
284  ); // stripDigitizer_.run... return
285  // ,sScale
286 
287 
288 
289  if(verbosity>0) {
290  std::cout <<" ===" << std::endl;
291  std::cout <<" ===" << std::endl;
292  std::cout <<"======= DigitizerFP420: collector size = " << collector.size() << std::endl;
293  std::cout <<" ===" << std::endl;
294  std::cout <<" ===" << std::endl;
295  }
296  /*
297 
298  std::vector<HDigiFP420> collector;
299  collector.clear();
300  DigiCollectionFP420::Range inputRange;
301  inputRange.first = collector.begin();
302  inputRange.second = collector.end();
303  output->putclear(inputRange,detID);
304  */
305  if (!collector.empty()){
306  if(verbosity>0) {
307  std::cout <<" ============= DigitizerFP420:collector start!!!!!!!!!!!!!!" << std::endl;
308  }
309  DigiCollectionFP420::Range outputRange;
310  outputRange.first = collector.begin();
311  outputRange.second = collector.end();
312 
313  if ( first ) {
314  // use it only if ClusterCollectionFP420 is the ClusterCollection of one event, otherwise, do not use (loose 1st cl. of 1st event only)
315  first = false;
316  unsigned int detID0= 0;
317  output->put(outputRange,detID0); // !!! put into adress 0 for detID which will not be used never
318  } //if ( first )
319 
320  // put !!!
321  output->put(outputRange,iu);
322 
323  } // if(collector.size()>0
324 
325  // } // for
326  // } // for
327  // } // for
328  // } // for
329 
330  }//for
331  }//for
332 
333  // END
334 
335  /*
336  if(verbosity>0) {
337  std::vector<HDigiFP420> theAllDigis;
338  theAllDigis.clear();
339  DigiCollectionFP420::Range outputRange;
340  DigiCollectionFP420::ContainerIterator sort_begin = outputRange.first;
341  DigiCollectionFP420::ContainerIterator sort_end = outputRange.second;
342  theAllDigis.insert(theAllDigis.end(), sort_begin, sort_end);
343  std::cout <<"====== theAllDigis size = " << theAllDigis.size() << std::endl;
344  for (std::vector<HDigiFP420>::iterator isim = theAllDigis.begin();
345  isim != theAllDigis.end(); ++isim){
346  const HDigiFP420 istrip = *isim;
347  std::cout << "*******************************************DigitizerFP420:check1" << std::endl;
348  std::cout << " strip number=" << istrip.strip() << " adc=" << istrip.adc() << std::endl;
349  std::cout <<" channel =" << istrip.channel() <<" V " << istrip.stripV() <<" VW " << istrip.stripVW() << std::endl;
350  std::cout <<" ===" << std::endl;
351  std::cout <<" ===" << std::endl;
352  std::cout <<" =======================" << std::endl;
353  }// for
354  }
355 */
356  if(verbosity==-50) {
357  // check of access to the collector:
358  for (int det=1; det<dn0; det++) {
359  for (int sector=1; sector<sn0; sector++) {
360  for (int zmodule=1; zmodule<pn0; zmodule++) {
361  for (int zside=1; zside<rn0; zside++) {
362  unsigned int iu = FP420NumberingScheme::packMYIndex(rn0, pn0, sn0, det, zside, sector, zmodule);
365  std::cout << "****DigitizerFP420:check2" << std::endl;
366  // std::cout <<" iu = " << iu <<" sector = " << sector <<" zmodule = " << zmodule <<" zside = " << zside << " det=" << det << std::endl;
367  // std::cout <<" layer = " << layer <<" orient = " << orient << std::endl;
368  int newdet, newzside, newsector, newzmodule;
369  FP420NumberingScheme::unpackMYIndex(iu, rn0, pn0, sn0, newdet, newzside, newsector, newzmodule);
370  std::cout <<" newdet = " << newdet <<" newsector = " << newsector <<" newzmodule = " << newzmodule <<" newzside = " << newzside << std::endl;
371 
372  collector.clear();
373  DigiCollectionFP420::Range outputRange;
374  // outputRange = output->get(iu);
375  outputRange = output->get(iu);
376 
377  // fill output in collector vector (for may be sorting? or other checks)
378  std::vector<HDigiFP420> collector;
379  // collector.clear();
380  DigiCollectionFP420::ContainerIterator sort_begin = outputRange.first;
381  DigiCollectionFP420::ContainerIterator sort_end = outputRange.second;
382  for ( ;sort_begin != sort_end; ++sort_begin ) {
383  collector.push_back(*sort_begin);
384  } // for
385  // std::sort(collector.begin(),collector.end());
386  std::cout <<" ===" << std::endl;
387  std::cout <<"====== collector size = " << collector.size() << std::endl;
388  if(!collector.empty()) {
389  std::cout <<" iu = " << iu <<" sector = " << sector <<" zmodule = " << zmodule <<" zside = " << zside << " det=" << det <<" layer = " << layer <<" orient = " << orient << std::endl;
390  std::cout <<" ===" << std::endl;
391  }
392  vector<HDigiFP420>::const_iterator simHitIter = collector.begin();
393  vector<HDigiFP420>::const_iterator simHitIterEnd = collector.end();
394  for (;simHitIter != simHitIterEnd; ++simHitIter) {
395  const HDigiFP420 istrip = *simHitIter;
396  std::cout << " strip number=" << istrip.strip() << " adc=" << istrip.adc() << std::endl;
397  std::cout <<" channel =" << istrip.channel() <<" V " << istrip.stripV() <<" VW " << istrip.stripVW() << std::endl;
398  std::cout <<" ===" << std::endl;
399  std::cout <<" ===" << std::endl;
400  std::cout <<" ===================================================" << std::endl;
401  }
402 
403  //==================================
404 
405  } // for
406  } // for
407  } // for
408  } // for
409 
410  // end of check of access to the strip collection
411 
412  }// if(verbosity
413 
414  // Step D: write output to file
415  if(verbosity>0) {
416  std::cout << "DigitizerFP420 recoutput" << std::endl;
417  }
418  // Step D: write output to file
419  iEvent.put(std::move(output));
420  }//produce
421 
422 } // namespace cms
423 
T getParameter(std::string const &) const
int channel() const
Definition: HDigiFP420.h:22
T getUntrackedParameter(std::string const &, T const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
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)
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:20
int iEvent
Definition: GenABIO.cc:230
static unsigned packMYIndex(int rn0, int pn0, int sn0, int det, int zside, int sector, int zmodule)
int adc() const
Definition: HDigiFP420.h:21
~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:535
std::pair< ContainerIterator, ContainerIterator > Range
Namespace of DDCMS conversion namespace.
T const * product() const
Definition: Handle.h:81
HLT enums.
inputRange
Get input source.
static int unpackOrientation(int rn0, int zside)
def move(src, dest)
Definition: eostools.py:510
unsigned int detUnitId() const
Definition: PSimHit.h:93
int stripV() const
Definition: HDigiFP420.h:26