CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CastorShowerLibraryMaker.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Forward
4 // Class : CastorShowerLibraryMaker
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: P. Katsas
10 // Created: 02/2007
11 //
12 // Adapted by W. Carvalho , 02/2009
13 //
15 
20 
23 
25 
26 #include "TFile.h"
27 #include <cmath>
28 #include <iostream>
29 #include <iomanip>
30 
32  NPGParticle(0),DoHadSL(false),DoEmSL(false),
33  emShower(NULL) , hadShower(NULL) {
34 
35  MapOfSecondaries.clear();
36  hadInfo = NULL;
37  emInfo = NULL;
38  edm::ParameterSet p_SLM = p.getParameter<edm::ParameterSet>("CastorShowerLibraryMaker");
39  verbosity = p_SLM.getParameter<int>("Verbosity");
40  eventNtFileName = p_SLM.getParameter<std::string>("EventNtupleFileName");
41  hadSLHolder.nEvtPerBinPhi = p_SLM.getParameter<int>("nhadEvents");
42  emSLHolder.nEvtPerBinPhi = p_SLM.getParameter<int>("nemEvents");
43  hadSLHolder.SLEnergyBins = p_SLM.getParameter<std::vector<double> >("SLhadEnergyBins");
44  hadSLHolder.SLEtaBins = p_SLM.getParameter<std::vector<double> >("SLhadEtaBins");
45  hadSLHolder.SLPhiBins = p_SLM.getParameter<std::vector<double> >("SLhadPhiBins");
46  emSLHolder.SLEnergyBins = p_SLM.getParameter<std::vector<double> >("SLemEnergyBins");
47  emSLHolder.SLEtaBins = p_SLM.getParameter<std::vector<double> >("SLemEtaBins");
48  emSLHolder.SLPhiBins = p_SLM.getParameter<std::vector<double> >("SLemPhiBins");
49  PGParticleIDs = p_SLM.getParameter<std::vector<int> >("PartID");
50  NPGParticle = PGParticleIDs.size();
51 //
52  for(unsigned int i=0;i<PGParticleIDs.size();i++) {
53  switch (int(fabs(PGParticleIDs.at(i)))) {
54  case 11:
55  case 22:
56  DoEmSL = true;
57  break;
58  default:
59  DoHadSL = true;
60  }
61  }
66 
67  std::cout << "============================================================================"<<std::endl;
68  std::cout << "CastorShowerLibraryMaker:: Initialized as observer" << std::endl;
69  std::cout << " Event Ntuple will be created" << std::endl;
70  std::cout << " Event Ntuple file: " << eventNtFileName << std::endl;
71  std::cout << " Number of Hadronic events in E bins: " << hadSLHolder.nEvtPerBinE << std::endl;
72  std::cout << " Number of Hadronic events in Eta bins: " << hadSLHolder.nEvtPerBinEta << std::endl;
73  std::cout << " Number of Hadronic events in Phi bins: " << hadSLHolder.nEvtPerBinPhi << std::endl;
74  std::cout << " Number of Electromag. events in E bins: " << emSLHolder.nEvtPerBinE << std::endl;
75  std::cout << " Number of Electromag. events in Eta bins: " << emSLHolder.nEvtPerBinEta << std::endl;
76  std::cout << " Number of Electromag. events in Phi bins: " << emSLHolder.nEvtPerBinPhi << std::endl;
77  std::cout << "============================================================================"<<std::endl;
78  std::cout << std::endl;
79 
80  // Initializing the SL collections
83 }
85 {
86  int nBinsE,nBinsEta,nBinsPhi,nEvtPerBinPhi;
87  nBinsE = showerholder.SLEnergyBins.size();
88  nBinsEta = showerholder.SLEtaBins.size();
89  nBinsPhi = showerholder.SLPhiBins.size();
90  nEvtPerBinPhi=showerholder.nEvtPerBinPhi;
91 //
92 // Info
93 //
94  showerholder.SLInfo.Energy.setNEvts(nEvtPerBinPhi*nBinsPhi*nBinsEta*nBinsE);
95  showerholder.SLInfo.Energy.setNEvtPerBin(nEvtPerBinPhi*nBinsPhi*nBinsEta);
96  showerholder.SLInfo.Energy.setNBins(nBinsE);
97  showerholder.SLInfo.Energy.setBin(showerholder.SLEnergyBins);
98 //
99  showerholder.SLInfo.Eta.setNEvts(nEvtPerBinPhi*nBinsPhi*nBinsEta);
100  showerholder.SLInfo.Eta.setNEvtPerBin(nEvtPerBinPhi*nBinsPhi);
101  showerholder.SLInfo.Eta.setNBins(nBinsEta);
102  showerholder.SLInfo.Eta.setBin(showerholder.SLEtaBins);
103 //
104  showerholder.SLInfo.Phi.setNEvts(nEvtPerBinPhi*nBinsPhi);
105  showerholder.SLInfo.Phi.setNEvtPerBin(nEvtPerBinPhi);
106  showerholder.SLInfo.Phi.setNBins(nBinsPhi);
107  showerholder.SLInfo.Phi.setBin(showerholder.SLPhiBins);
108 //
109 // Shower
110  showerholder.SLCollection.assign(nBinsE,std::vector<std::vector<std::vector<CastorShowerEvent> > >());
111  showerholder.nEvtInBinE.assign(nBinsE,0);
112  showerholder.nEvtInBinEta.assign(nBinsE,std::vector<int>(0));
113  showerholder.nEvtInBinPhi.assign(nBinsE,std::vector<std::vector<int> >());
114  for(int i=0;i<nBinsE;i++) {
115  showerholder.SLCollection.at(i).assign(nBinsEta,std::vector<std::vector<CastorShowerEvent> >());
116  showerholder.nEvtInBinEta.at(i).assign(nBinsEta,0);
117  showerholder.nEvtInBinPhi.at(i).assign(nBinsEta,std::vector<int>(0));
118  for(int j=0;j<nBinsEta;j++) {
119  showerholder.SLCollection.at(i).at(j).assign(nBinsPhi,std::vector<CastorShowerEvent>());
120  showerholder.nEvtInBinPhi.at(i).at(j).assign(nBinsPhi,0);
121  for(int k=0;k<nBinsPhi;k++)
122  showerholder.SLCollection.at(i).at(j).at(k).assign(nEvtPerBinPhi,CastorShowerEvent());
123  }
124  }
125 }
126 
127 //===============================================================================================
128 
130 
131  Finish();
132 
133  std::cout << "CastorShowerLibraryMaker: End of process" << std::endl;
134 
135 }
136 
137 //=================================================================== per EVENT
139 
140  std::cout << " CastorShowerLibraryMaker::Starting new job " << std::endl;
141 }
142 
143 //==================================================================== per RUN
145 
146  std::cout << std::endl << "CastorShowerLibraryMaker: Starting Run"<< std::endl;
147 
148  std::cout << "CastorShowerLibraryMaker: output event root file created" << std::endl;
149 
150  TString eventfilename = eventNtFileName;
151  theFile = new TFile(eventfilename,"RECREATE");
152  theTree = new TTree("CastorCherenkovPhotons", "Cherenkov Photons");
153 
154  Int_t split = 1;
155  Int_t bsize = 64000;
157  emShower = new CastorShowerEvent();
160  // Create Branchs
161  theTree->Branch("emShowerLibInfo.", "CastorShowerLibraryInfo", &emInfo, bsize, split);
162  theTree->Branch("emParticles.", "CastorShowerEvent", &emShower, bsize, split);
163  theTree->Branch("hadShowerLibInfo.", "CastorShowerLibraryInfo", &hadInfo, bsize, split);
164  theTree->Branch("hadParticles.", "CastorShowerEvent", &hadShower, bsize, split);
165 
166 // set the Info for electromagnetic shower
167 // set the energy bins info
172 // set the eta bins info
177 // set the eta bins info
182 // The same for the hadronic shower
183 // set the energy bins info
188 // set the eta bins info
193 // set the eta bins info
198  // int flag = theTree->GetBranch("CastorShowerLibInfo")->Fill();
199  // Loop on all leaves of this branch to fill Basket buffer.
200  // The function returns the number of bytes committed to the memory basket.
201  // If a write error occurs, the number of bytes returned is -1.
202  // If no data are written, because e.g. the branch is disabled,
203  // the number of bytes returned is 0.
204  // if(flag==-1) {
205  // edm::LogInfo("CastorAnalyzer") << " WARNING: Error writing to Branch \"CastorShowerLibInfo\" \n" ;
206  // } else
207  // if(flag==0) {
208  // edm::LogInfo("CastorAnalyzer") << " WARNING: No data written to Branch \"CastorShowerLibInfo\" \n" ;
209  // }
210 
211  // Initialize "accounting" variables
212 
213  eventIndex = 0;
214 
215 }
216 
217 //=================================================================== per EVENT
219 
220  eventIndex++;
221  stepIndex = 0;
222 // reset the pointers to the shower objects
223  SLShowerptr = NULL;
224  MapOfSecondaries.clear();
225 //
226  std::cout << "CastorShowerLibraryMaker: Processing Event Number: " << eventIndex << std::endl;
227 }
228 
229 //=================================================================== per STEP
230 void CastorShowerLibraryMaker::update(const G4Step * aStep) {
231  static int CurrentPrimary = 0;
232  G4Track *trk = aStep->GetTrack();
233  if (trk->GetCurrentStepNumber()==1) {
234  if (trk->GetParentID()==0) CurrentPrimary = trk->GetDynamicParticle()->GetPDGcode();
235  if (CurrentPrimary==0)
236  SimG4Exception("CastorShowerLibraryMaker::update(G4Step) -> Primary particle undefined");
237  MapOfSecondaries[CurrentPrimary].insert((int)trk->GetTrackID());
238  }
239 /*
240  if(aStep->IsFirstStepInVolume()) {
241  edm::LogInfo("CastorShowerLibraryMaker") << "CastorShowerLibraryMaker::update(const G4Step * aStep):"
242  << "\n IsFirstStepInVolume , "
243  << "time = " << aStep->GetTrack()->GetGlobalTime() ;
244  }
245  stepIndex++;
246 */
247 }
248 
249 //================= End of EVENT ===============
251 
252 // check if the job is done!
253  if (IsSLReady()) update((EndOfRun*)NULL);
254 
255  std::cout << "CastorShowerLibraryMaker: End of Event: " << eventIndex << std::endl;
256 // Get the pointer to the primary particle
257  std::vector<G4PrimaryParticle*> thePrims = GetPrimary(evt);
258  if (thePrims.size() == 0) {
259  edm::LogInfo("CastorShowerLibraryMaker") << "No valid primary particle found. Skipping event" << std::endl;
260  return;
261  }
262 
263 // Loop over primaries
264  for(unsigned int i=0;i<thePrims.size();i++) {
265  G4PrimaryParticle* thePrim = thePrims.at(i);
266  if (!thePrim) {
267  edm::LogInfo("CastorShowerLibraryMaker") << "NULL Pointer to the primary" << std::endl;
268  continue;
269  }
270 // Check primary particle type
271  int particleType = thePrim->GetPDGcode();
272 
273 // set the pointer to the shower collection
274  std::string SLType("");
275  if (particleType==11) {
277  SLType = "Electromagnetic";
278  }
279  else {
281  SLType = "Hadronic";
282  }
283 
284 // Obtain primary particle's initial momentum (pInit)
285  double px=0., py=0., pz=0., pInit = 0., eta = 0., phi = 0.;
286 
287  GetKinematics(thePrim,px,py,pz,pInit,eta,phi);
288  edm::LogInfo("CastorShowerLibraryMaker") << "\n Primary (thePrim) trackID is " << thePrim->GetTrackID() << "\n" ;
289 
290 // Check if current event falls into any bin
291 // first: energy
292  int ebin = FindEnergyBin(pInit);
293  int etabin= FindEtaBin(eta);
294  int phibin = FindPhiBin(phi);
295  std::cout << SLType << std::endl;
296  printSLstatus(ebin,etabin,phibin);
297  if (!SLacceptEvent(ebin,etabin,phibin)) {
298  edm::LogInfo("CastorShowerLibraryMaker") << "Event not accepted for ebin="
299  << ebin<<",etabin="<<etabin<<",phibin="<<phibin<<std::endl;
300  continue;
301  }
302 //
303 // event passed. Fill the vector accordingly
304 //
305 // Look for the Hit Collection
306  edm::LogInfo("CastorShowerLibraryMaker")
307  << "\n CastorShowerLibraryMaker::update(EndOfEvent * evt) - event #"
308  << (*evt)()->GetEventID() ;
309 
310  // access to the G4 hit collections
311  G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
312 /*
313  std::cout << "Number of collections : " << allHC->GetNumberOfCollections() << std::endl;
314  for(int ii = 0;ii<allHC->GetNumberOfCollections();ii++)
315  std::cout << "Name of collection " << ii << " : " << allHC->GetHC(ii)->GetName() << std::endl;
316 */
317  edm::LogInfo("CastorShowerLibraryMaker") << " update(*evt) --> accessed all HC ";
318 
319  CastorShowerEvent* shower=NULL;
320  int cur_evt_idx = SLShowerptr->nEvtInBinPhi.at(ebin).at(etabin).at(phibin);
321  shower = &(SLShowerptr->SLCollection.at(ebin).at(etabin).at(phibin).at(cur_evt_idx));
322 
323 // Get Hit information
324  if (FillShowerEvent(allHC,shower,particleType)) {
325 // Primary particle information
326  shower->setPrimE(pInit);
327  shower->setPrimEta(eta);
328  shower->setPrimPhi(phi);
329  //shower->setPrimX(entry.x());
330  //shower->setPrimY(entry.y());
331  //shower->setPrimZ(entry.z());
332  SLnEvtInBinE(ebin)++;
333  SLnEvtInBinEta(ebin,etabin)++;
334  SLnEvtInBinPhi(ebin,etabin,phibin)++;
335  }
336  }
337 
338  //int iEvt = (*evt)()->GetEventID();
339  //double xint;
340 /*
341  if (modf(log10(iEvt),&xint)==0)
342  std::cout << " CastorShowerLibraryMaker Event " << iEvt << std::endl;
343 */
344  // std::cout << std::endl << "===>>> Done writing user histograms " << std::endl;
345 }
346 
347 //========================= End of RUN ======================
349 {
350 // Fill the tree with the collected objects
351  if (!IsSLReady()) SimG4Exception("\n\nShower Library NOT READY.\n\n");
352 
353  unsigned int ibine,ibineta,ibinphi,ievt; // indexes for em shower
354  unsigned int jbine,jbineta,jbinphi,jevt;// indexes for had shower
355 
356  ibine=ibineta=ibinphi=ievt=jbine=jbineta=jbinphi=jevt=0;
357 
358  int nEvtInTree = 0;
359  int maxEvtInTree=std::max(hadSLHolder.nEvtPerBinE*hadSLHolder.SLEnergyBins.size(),
361 
364 
365  while(nEvtInTree<maxEvtInTree) {
366  if (emShower) emShower->Clear();
367  if (hadShower) hadShower->Clear();
368  while(ibine<emSLHolder.SLEnergyBins.size()){
369  emShower = &(emSLHolder.SLCollection.at(ibine).at(ibineta).at(ibinphi).at(ievt));
370  ievt++;
371  if (ievt==emSLHolder.nEvtPerBinPhi) {ievt=0;ibinphi++;}
372  if (ibinphi==emSLHolder.SLPhiBins.size()) {ibinphi=0;ibineta++;}
373  if (ibineta==emSLHolder.SLEtaBins.size()) {ibineta=0;ibine++;}
374  break;
375  }
376  while(jbine<hadSLHolder.SLEnergyBins.size()){
377  hadShower = &(hadSLHolder.SLCollection.at(jbine).at(jbineta).at(jbinphi).at(jevt));
378  jevt++;
379  if (jevt==hadSLHolder.nEvtPerBinPhi) {jevt=0;jbinphi++;}
380  if (jbinphi==hadSLHolder.SLPhiBins.size()) {jbinphi=0;jbineta++;}
381  if (jbineta==hadSLHolder.SLEtaBins.size()) {jbineta=0;jbine++;}
382  break;
383  }
384  theTree->Fill();
385  nEvtInTree++;
386  if (nEvtInTree==1) {
387  theTree->SetBranchStatus("emShowerLibInfo.",0);
388  theTree->SetBranchStatus("hadShowerLibInfo.",0);
389  }
390  }
391 // check if run is NULL and exit
392  if (run==NULL) throw SimG4Exception("\n\nNumber of needed trigger events reached in CastorShowerLibraryMaker\n\n");
393 }
394 
395 //============================================================
397 
398  // if (doNTcastorevent) {
399 
400  theFile->cd();
401  theTree->Write("",TObject::kOverwrite);
402  std::cout << "CastorShowerLibraryMaker: Ntuple event written" << std::endl;
403  theFile->Close();
404  std::cout << "CastorShowerLibraryMaker: Event file closed" << std::endl;
405 
406  // Delete pointers to objects, now that TTree has been written and TFile closed
407 // delete info;
408 // delete emShower;
409 // delete hadShower;
410  // }
411 }
413  //
414  // returns the integer index of the energy bin, taken from SLenergies vector
415  // returns -1 if ouside valid range
416  //
417  if (!SLShowerptr) {
418  edm::LogInfo("CastorShowerLibraryMaker") << "\n\nFindEnergyBin can be called only after BeginOfEvent\n\n";
419  throw SimG4Exception("\n\nNULL Pointer to the shower library.\n\n");
420  }
421  const std::vector<double>& SLenergies = SLShowerptr->SLEnergyBins;
422  if (energy >= SLenergies.back()) return SLenergies.size()-1;
423 
424  unsigned int i = 0;
425  for(;i<SLenergies.size()-1;i++)
426  if (energy >= SLenergies.at(i) && energy < SLenergies.at(i+1)) return (int)i;
427 
428  // now i points to the last but 1 bin
429  if (energy>=SLenergies.at(i)) return (int)i;
430  // energy outside bin range
431  return -1;
432 }
434  //
435  // returns the integer index of the eta bin, taken from SLetas vector
436  // returns -1 if ouside valid range
437  //
438  if (!SLShowerptr) {
439  edm::LogInfo("CastorShowerLibraryMaker") << "\n\nFindEtaBin can be called only after BeginOfEvent\n\n";
440  throw SimG4Exception("\n\nNULL Pointer to the shower library.\n\n");
441  }
442  const std::vector<double>& SLetas = SLShowerptr->SLEtaBins;
443  if (eta>=SLetas.back()) return SLetas.size()-1;
444  unsigned int i = 0;
445  for(;i<SLetas.size()-1;i++)
446  if (eta >= SLetas.at(i) && eta < SLetas.at(i+1)) return (int)i;
447  // now i points to the last but 1 bin
448  if (eta>=SLetas.at(i)) return (int)i;
449  // eta outside bin range
450  return -1;
451 }
453  //
454  // returns the integer index of the phi bin, taken from SLphis vector
455  // returns -1 if ouside valid range
456  //
457  // needs protection in case phi is outside range -pi,pi
458  //
459  if (!SLShowerptr) {
460  edm::LogInfo("CastorShowerLibraryMaker") << "\n\nFindPhiBin can be called only after BeginOfEvent\n\n";
461  throw SimG4Exception("\n\nNULL Pointer to the shower library.\n\n");
462  }
463  const std::vector<double>& SLphis = SLShowerptr->SLPhiBins;
464  if (phi>=SLphis.back()) return SLphis.size()-1;
465  unsigned int i = 0;
466  for(;i<SLphis.size()-1;i++)
467  if (phi >= SLphis.at(i) && phi < SLphis.at(i+1)) return (int)i;
468  // now i points to the last but 1 bin
469  if (phi>=SLphis.at(i)) return (int)i;
470  // phi outside bin range
471  return -1;
472 }
474 {
475 // at this point, the pointer to the shower library should be NULL
476  if (SLShowerptr) {
477  edm::LogInfo("CastorShowerLibraryMaker") << "\n\nIsSLReady must be called when a new event starts.\n\n";
478  throw SimG4Exception("\n\nNOT NULL Pointer to the shower library.\n\n");
479  }
480 // it is enough to check if all the energy bin is filled
481  if (DoEmSL) {
483  for(unsigned int i=0;i<SLShowerptr->SLEnergyBins.size();i++) {
484  if (!SLisEBinFilled(i)) {
486  return false;
487  }
488  }
489  }
490  if (DoHadSL) {
492  for(unsigned int i=0;i<SLShowerptr->SLEnergyBins.size();i++) {
493  if (!SLisEBinFilled(i)) {
495  return false;
496  }
497  }
498  }
500  return true;
501 }
502 void CastorShowerLibraryMaker::GetKinematics(G4PrimaryParticle* thePrim,double& px, double& py, double& pz, double& pInit, double& eta, double& phi)
503 {
504  px=py=pz=phi=eta=0.0;
505  if (thePrim==0) return;
506  px = thePrim->GetPx()/GeV;
507  py = thePrim->GetPy()/GeV;
508  pz = thePrim->GetPz()/GeV;
509  pInit = sqrt(pow(px,2.)+pow(py,2.)+pow(pz,2.));
510  if (pInit==0) {
511  std::cout << "CastorShowerLibraryMaker::GetKinematics: ERROR: primary has p=0 " << std::endl;
512  return;
513  }
514  double costheta = pz/pInit;
515  double theta = acos(std::min(std::max(costheta,double(-1.)),double(1.)));
516  eta = -log(tan(theta/2.0));
517  phi = (px==0 && py==0) ? 0 : atan2(py,px); // the recommended way of calculating phi
518  //if (px!=0) phi=atan(py/px);
519 }
520 std::vector<G4PrimaryParticle*> CastorShowerLibraryMaker::GetPrimary(const EndOfEvent * evt)
521 {
522  // Find Primary info:
523  int trackID = 0;
524  std::vector<G4PrimaryParticle*> thePrims;
525  G4PrimaryParticle* thePrim = 0;
526  G4int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
527  edm::LogInfo("CastorShowerLibraryMaker") << "Event has " << nvertex << " vertex";
528  if (nvertex!=1) {
529  edm::LogInfo("CastorShowerLibraryMaker") << "CastorShowerLibraryMaker::GetPrimary ERROR: no vertex";
530  return thePrims;
531  }
532 
533  for (int i = 0 ; i<nvertex; i++) {
534  G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(i);
535  if (avertex == 0) {
536  edm::LogInfo("CastorShowerLibraryMaker")
537  << "CastorShowerLibraryMaker::GetPrimary ERROR: pointer to vertex = 0";
538  continue;
539  }
540  unsigned int npart = avertex->GetNumberOfParticle();
541  if (npart!=NPGParticle) continue;
542  for (unsigned int j=0;j<npart;j++) {
543  unsigned int k = 0;
544  //int test_pID = 0;
545  trackID = j;
546  thePrim=avertex->GetPrimary(trackID);
547  while(k<NPGParticle&&PGParticleIDs.at(k++)!=thePrim->GetPDGcode()){;};
548  if (k>NPGParticle) continue; // ID not found in the requested particles
549  thePrims.push_back(thePrim);
550  }
551  }
552  return thePrims;
553 }
555 {
556  int nBinsE =SLShowerptr->SLEnergyBins.size();
557  int nBinsEta=SLShowerptr->SLEtaBins.size();
558  int nBinsPhi=SLShowerptr->SLPhiBins.size();
559  std::vector<double> SLenergies = SLShowerptr->SLEnergyBins;
560  for(int n=0;n<11+(nBinsEta*nBinsPhi);n++) std::cout << "=";
561  std::cout << std::endl;
562  for(int i=0;i<nBinsE;i++) {
563  std::cout << "E bin " << SLenergies.at(i) << " : ";
564  for(int j=0;j<nBinsEta;j++) {
565  for(int k=0;k<nBinsPhi;k++) {
566  (SLisPhiBinFilled(i,j,k))?std::cout << "1":std::cout << "-";
567  }
568  if (j<nBinsEta-1) std::cout << "|";
569  }
570  std::cout << " (" << SLnEvtInBinE(i) << " events)";
571  std::cout << std::endl;
572  if (ebin!=i) continue;
573  std::cout << " ";
574  for(int j=0;j<nBinsEta;j++) {
575  for(int k=0;k<nBinsPhi;k++) {
576  (ebin==i&&etabin==j&&phibin==k)?std::cout << "^":std::cout << " ";
577  }
578  if (j<nBinsEta-1) std::cout << " ";
579  }
580  std::cout << std::endl;
581  }
582  for(int n=0;n<11+(nBinsEta*nBinsPhi);n++) std::cout << "=";
583  std::cout << std::endl;
584 }
586 {
587  if (ebin<0) return false;
588  if (SLisEBinFilled(ebin)) return false;
589 
590  if (etabin<0) return false;
591  if (SLisEtaBinFilled(ebin,etabin)) return false;
592 
593  if (phibin<0) return false;
594  if (SLisPhiBinFilled(ebin,etabin,phibin)) return false;
595  return true;
596 }
597 bool CastorShowerLibraryMaker::FillShowerEvent(G4HCofThisEvent* allHC, CastorShowerEvent* shower,int ipart)
598 {
599  // int CAFIid = G4SDManager::GetSDMpointer()->GetCollectionID("CastorPL"); // Trick to get CASTPL
600  int CAFIid = G4SDManager::GetSDMpointer()->GetCollectionID("CastorFI");
601 
602  CaloG4HitCollection* theCAFI = (CaloG4HitCollection*) allHC->GetHC(CAFIid);
603 
604  CastorNumberingScheme *theCastorNumScheme = new CastorNumberingScheme();
605 
606  unsigned int volumeID=0;
607  double en_in_fi = 0.;
608  //double totalEnergy = 0;
609 
610  int nentries = theCAFI->entries();
611  edm::LogInfo("CastorShowerLibraryMaker") << "Found "<<nentries << " hits in G4HitCollection";
612  if (nentries == 0) {
613  edm::LogInfo("CastorShowerLibraryMaker") << "\n Empty G4HitCollection";
614  return false;
615  }
616 
617 // Compute Total Energy in CastorFI volume
618 /*
619  for(int ihit = 0; ihit < nentries; ihit++) {
620  CaloG4Hit* aHit = (*theCAFI)[ihit];
621  totalEnergy += aHit->getEnergyDeposit();
622  }
623 */
624  if (!shower) {
625  edm::LogInfo("CastorShowerLibraryMaker") << "Error. NULL pointer to CastorShowerEvent";
626  return false;
627  }
628 
629 // Hit position
632  int nHits;
633  nHits=0;
634  for (int ihit = 0; ihit < nentries; ihit++) {
635  CaloG4Hit* aHit = (*theCAFI)[ihit];
636  int hit_particleID = aHit->getTrackID();
637  if (MapOfSecondaries[ipart].find(hit_particleID)==MapOfSecondaries[ipart].end()) {
638  if (verbosity) edm::LogInfo("CastorShowerLibraryMaker") << "Skipping hit from trackID " << hit_particleID;
639  continue;
640  }
641  volumeID = aHit->getUnitID();
642  double hitEnergy = aHit->getEnergyDeposit();
643  en_in_fi += aHit->getEnergyDeposit();
644  float time = aHit->getTimeSlice();
645  int zside, sector, zmodule;
646  theCastorNumScheme->unpackIndex(volumeID, zside, sector,zmodule);
647  entry = aHit->getEntry();
648  position = aHit->getPosition();
649  if (verbosity) edm::LogInfo("CastorShowerLibraryMaker")
650  << "\n side , sector , module = " << zside << " , "
651  << sector << " , " << zmodule
652  << "\n nphotons = " << hitEnergy ;
653 
654  if (verbosity) edm::LogInfo("CastorShowerLibraryMaker")
655  << "\n packIndex = "
656  << theCastorNumScheme->packIndex(zside, sector,zmodule);
657 
658  if(time>100.) {
659  edm::LogInfo("CastorShowerLibraryMaker")
660  << "\n nentries = " << nentries
661  << "\n time[" << ihit << "] = " << time
662  << "\n trackID[" << ihit << "] = " << aHit->getTrackID()
663  << "\n volumeID[" << ihit << "] = " << volumeID
664  << "\n nphotons[" << ihit << "] = " << hitEnergy
665  << "\n side, sector, module = " << zside <<", " << sector<<", " << zmodule
666  << "\n packIndex " << theCastorNumScheme->packIndex(zside,sector,zmodule)
667  << "\n X,Y,Z = " << entry.x() << ","<< entry.y() << "," << entry.z();
668  }
669  if(nHits==0) {
670 /*
671  edm::LogInfo("CastorShowerLibraryMaker")
672  << "\n entry(x,y,z) = (" << entry.x() << ","
673  << entry.y() << "," << entry.z() << ") \n"
674  << "\n entry(eta,phi,z) = (" << entry.eta() << ","
675  << entry.phi() << "," << entry.z() << ") \n"
676  << "\n eta , phi = "
677  << eta << " , " << phi << " \n" ;
678 */
679  shower->setPrimX(entry.x());
680  shower->setPrimY(entry.y());
681  shower->setPrimZ(entry.z());
682  }
683  if (verbosity) edm::LogInfo("CastorShowerLibraryMaker") << "\n Incident Energy = "
684  << aHit->getIncidentEnergy() << " \n" ;
685 
686 
687 // CaloG4Hit information
688  shower->setDetID(volumeID);
689  shower->setHitPosition(position);
690  shower->setNphotons(hitEnergy);
691  shower->setTime(time);
692  nHits++;
693  }
694 // Write number of hits to CastorShowerEvent instance
695  if (nHits==0) {
696  edm::LogInfo("CastorShowerLibraryMaker") << "No hits found for this track (trackID=" << ipart << ")." << std::endl;
697  return false;
698  }
699  shower->setNhit(nHits);
700 
701  edm::LogInfo("CastorShowerLibraryMaker") << "Filling the SL vector with new element ("<<nHits<<" hits)";
702 // update the event counters
703  return true;
704 }
706 {
707  if (!SLShowerptr) {
708  edm::LogInfo("CastorShowerLibraryMaker") << "\n\nSLnEvtInBinE can be called only after BeginOfEvent\n\n";
709  throw SimG4Exception("\n\nNULL Pointer to the shower library.");
710  }
711  return SLShowerptr->nEvtInBinE.at(ebin);
712 }
713 
715 {
716  if (!SLShowerptr) {
717  edm::LogInfo("CastorShowerLibraryMaker") << "\n\nSLnEvtInBinEta can be called only after BeginOfEvent\n\n";
718  throw SimG4Exception("\n\nNULL Pointer to the shower library.");
719  }
720  return SLShowerptr->nEvtInBinEta.at(ebin).at(etabin);
721 }
722 
724 {
725  if (!SLShowerptr) {
726  edm::LogInfo("CastorShowerLibraryMaker") << "\n\nSLnEvtInBinPhi can be called only after BeginOfEvent\n\n";
727  throw SimG4Exception("\n\nNULL Pointer to the shower library.");
728  }
729  return SLShowerptr->nEvtInBinPhi.at(ebin).at(etabin).at(phibin);
730 }
732 {
733  if (!SLShowerptr) {
734  edm::LogInfo("CastorShowerLibraryMaker") << "\n\nSLisEBinFilled can be called only after BeginOfEvent\n\n";
735  throw SimG4Exception("\n\nNULL Pointer to the shower library.");
736  }
737  if (SLShowerptr->nEvtInBinE.at(ebin)<(int)SLShowerptr->nEvtPerBinE) return false;
738  return true;
739 }
741 {
742  if (!SLShowerptr) {
743  edm::LogInfo("CastorShowerLibraryMaker") << "\n\nSLisEtaBinFilled can be called only after BeginOfEvent\n\n";
744  throw SimG4Exception("\n\nNULL Pointer to the shower library.");
745  }
746  if (SLShowerptr->nEvtInBinEta.at(ebin).at(etabin)<(int)SLShowerptr->nEvtPerBinEta) return false;
747  return true;
748 }
750 {
751  if (!SLShowerptr) {
752  edm::LogInfo("CastorShowerLibraryMaker") << "\n\nSLisPhiBinFilled can be called only after BeginOfEvent\n\n";
753  throw SimG4Exception("\n\nNULL Pointer to the shower library.");
754  }
755  if (SLShowerptr->nEvtInBinPhi.at(ebin).at(etabin).at(phibin)<(int)SLShowerptr->nEvtPerBinPhi) return false;
756  return true;
757 }
T getParameter(std::string const &) const
void setNBins(unsigned int n)
int i
Definition: DBlmapReader.cc:9
math::XYZPoint getPosition() const
Definition: CaloG4Hit.h:56
void setTime(float t)
void setPrimEta(float eta)
void setPrimZ(float z)
void setDetID(unsigned int id)
int & SLnEvtInBinEta(int ebin, int etabin)
void setPrimPhi(float phi)
void setBin(double val)
Geom::Theta< T > theta() const
double getIncidentEnergy() const
Definition: CaloG4Hit.h:65
#define NULL
Definition: scimark2.h:8
double npart
Definition: HydjetWrapper.h:45
#define min(a, b)
Definition: mlp_lapack.h:161
T eta() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
bool SLisEtaBinFilled(int ebin, int etabin)
static void unpackIndex(const uint32_t &idx, int &z, int &sector, int &zmodule)
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
void setNEvtPerBin(unsigned int n)
CastorShowerLibraryInfo * hadInfo
const T & max(const T &a, const T &b)
T sqrt(T t)
Definition: SSEVec.h:28
std::pair< std::string, MonitorElement * > entry
Definition: ME_MAP.h:8
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
int j
Definition: DBlmapReader.cc:9
std::vector< std::vector< std::vector< int > > > nEvtInBinPhi
#define end
Definition: vmac.h:38
std::map< int, std::set< int > > MapOfSecondaries
CastorShowerLibraryInfo * emInfo
CastorShowerLibraryMaker(const edm::ParameterSet &p)
int k[5][pyjets_maxn]
void setPrimE(float e)
void setPrimY(float y)
void GetKinematics(G4PrimaryParticle *, double &px, double &py, double &pz, double &pInit, double &eta, double &phi)
void setPrimX(float x)
int getTrackID() const
Definition: CaloG4Hit.h:68
Log< T >::type log(const T &t)
Definition: Log.h:22
int & SLnEvtInBinPhi(int ebin, int etabin, int phibin)
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:13
std::vector< std::vector< int > > nEvtInBinEta
void setHitPosition(Point p)
std::vector< G4PrimaryParticle * > GetPrimary(const EndOfEvent *)
void setNEvts(unsigned int n)
void update(const BeginOfJob *run)
This routine will be called when the appropriate signal arrives.
G4THitsCollection< CaloG4Hit > CaloG4HitCollection
bool SLisPhiBinFilled(int ebin, int etabin, int phibin)
bool FillShowerEvent(G4HCofThisEvent *, CastorShowerEvent *, int)
tuple job
Definition: launcher.py:57
double getTimeSlice() const
Definition: CaloG4Hit.h:70
tuple cout
Definition: gather_cfg.py:41
math::XYZPoint getEntry() const
Definition: CaloG4Hit.h:50
uint32_t getUnitID() const
Definition: CaloG4Hit.h:69
static uint32_t packIndex(int z, int sector, int zmodule)
void setNphotons(float np)
double split
Definition: MVATrainer.cc:139
void setNhit(unsigned int i)
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
double getEnergyDeposit() const
Definition: CaloG4Hit.h:81
Definition: DDAxes.h:10