CMS 3D CMS Logo

BscTest.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 
4 // system include files
5 #include <cmath>
6 #include <iostream>
7 #include <iomanip>
8 #include <map>
9 #include <string>
10 #include <vector>
11 
12 //
19 
31 
32 // to retreive hits
36 
37 // G4 stuff
38 #include "G4SDManager.hh"
39 #include "G4Step.hh"
40 #include "G4Track.hh"
41 #include "G4VProcess.hh"
42 #include "G4HCofThisEvent.hh"
43 #include "G4UserEventAction.hh"
44 #include "G4TransportationManager.hh"
45 #include "G4ProcessManager.hh"
46 #include "G4VTouchable.hh"
47 
48 #include <CLHEP/Vector/ThreeVector.h>
49 #include <CLHEP/Vector/LorentzVector.h>
50 #include <CLHEP/Random/Randomize.h>
51 #include <CLHEP/Units/GlobalSystemOfUnits.h>
52 #include <CLHEP/Units/GlobalPhysicalConstants.h>
53 
54 // ----------------------------------------------------------------
55 // Includes needed for Root ntupling
56 //
57 #include "TROOT.h"
58 #include "TFile.h"
59 #include "TH1.h"
60 #include "TH2.h"
61 #include "TProfile.h"
62 #include "TNtuple.h"
63 #include "TRandom.h"
64 #include "TLorentzVector.h"
65 #include "TUnixSystem.h"
66 #include "TSystem.h"
67 #include "TMath.h"
68 #include "TF1.h"
69 #include "TObjArray.h"
70 #include "TObjString.h"
71 #include "TNamed.h"
72 
73 //#define EDM_ML_DEBUG
74 
75 class BscAnalysisHistManager : public TNamed {
76 public:
77  BscAnalysisHistManager(const TString& managername);
78  ~BscAnalysisHistManager() override;
79 
80  TH1F* getHisto(Int_t Number);
81  TH1F* getHisto(const TObjString& histname);
82 
83  TH2F* getHisto2(Int_t Number);
84  TH2F* getHisto2(const TObjString& histname);
85 
86  void writeToFile(const TString& fOutputFile, const TString& fRecreateFile);
87 
88 private:
89  void bookHistos();
90  void storeWeights();
91  void histInit(const char* name, const char* title, Int_t nbinsx, Axis_t xlow, Axis_t xup);
92  void histInit(
93  const char* name, const char* title, Int_t nbinsx, Axis_t xlow, Axis_t xup, Int_t nbinsy, Axis_t ylow, Axis_t yup);
94 
95  const char* fTypeTitle;
96  TObjArray* fHistArray;
97  TObjArray* fHistNamesArray;
98 };
99 
100 class BscTest : public SimWatcher,
101  public Observer<const BeginOfJob*>,
102  public Observer<const BeginOfRun*>,
103  public Observer<const EndOfRun*>,
104  public Observer<const BeginOfEvent*>,
105  public Observer<const BeginOfTrack*>,
106  public Observer<const G4Step*>,
107  public Observer<const EndOfTrack*>,
108  public Observer<const EndOfEvent*> {
109 public:
110  BscTest(const edm::ParameterSet& p);
111  ~BscTest() override;
112 
113 private:
114  // observer classes
115  void update(const BeginOfJob* run) override;
116  void update(const BeginOfRun* run) override;
117  void update(const EndOfRun* run) override;
118  void update(const BeginOfEvent* evt) override;
119  void update(const BeginOfTrack* trk) override;
120  void update(const G4Step* step) override;
121  void update(const EndOfTrack* trk) override;
122  void update(const EndOfEvent* evt) override;
123 
124  //UHB_Analysis* UserNtuples;
126 
127  int iev;
128  int itrk;
129  G4double entot0, tracklength0;
130 
131  // Utilities to get detector levels during a step
132 
133  int detLevels(const G4VTouchable*) const;
134  G4String detName(const G4VTouchable*, int, int) const;
135  void detectorLevel(const G4VTouchable*, int&, int*, G4String*) const;
136 
137  double rinCalo, zinCalo;
140 
141  // sumEnerDeposit - all deposited energy on all steps ; sumStepl - length in steel !!!
143  // numofpart - # particles produced along primary track
145  // last point of the primary track
146  G4ThreeVector lastpo;
147 
148  // z:
149  double z1, z2, z3, z4;
150 
151 private:
152  Float_t bsceventarray[1];
153  TNtuple* bsceventntuple;
156 
157  BscAnalysisHistManager* TheHistManager; //Histogram Manager of the analysis
158  std::string fDataLabel; // Data type label
159  std::string fOutputFile; // The output file name
160  std::string fRecreateFile; // Recreate the file flag, default="RECREATE"
161 };
162 
164 
165 //================================================================
167  //constructor
168  edm::ParameterSet m_Anal = p.getParameter<edm::ParameterSet>("BscTest");
169  verbosity = m_Anal.getParameter<int>("Verbosity");
170  //verbosity = 1;
171 
172  fDataLabel = m_Anal.getParameter<std::string>("FDataLabel");
173  fOutputFile = m_Anal.getParameter<std::string>("FOutputFile");
174  fRecreateFile = m_Anal.getParameter<std::string>("FRecreateFile");
175 
176  if (verbosity > 0) {
177  edm::LogVerbatim("BscTest") << "============================================================================";
178  edm::LogVerbatim("BscTest") << "BscTestconstructor :: Initialized as observer";
179  }
180  // Initialization:
181 
183  bsceventntuple = new TNtuple("NTbscevent", "NTbscevent", "evt");
184  whichevent = 0;
186 
187  if (verbosity > 0) {
188  edm::LogVerbatim("BscTest") << "BscTest constructor :: Initialized BscAnalysisHistManager";
189  }
190 }
191 
193  // delete UserNtuples;
194  delete theBscNumberingScheme;
195 
196  TFile bscOutputFile("newntbsc.root", "RECREATE");
197  edm::LogVerbatim("BscTest") << "Bsc output root file has been created";
198  bsceventntuple->Write();
199  edm::LogVerbatim("BscTest") << ", written";
200  bscOutputFile.Close();
201  edm::LogVerbatim("BscTest") << ", closed";
202  delete bsceventntuple;
203  edm::LogVerbatim("BscTest") << ", and deleted";
204 
205  //------->while end
206 
207  // Write histograms to file
209  if (verbosity > 0) {
210  edm::LogVerbatim("BscTest") << std::endl << "BscTest Destructor --------> End of BscTest : ";
211  }
212 
213  edm::LogVerbatim("BscTest") << "BscTest: End of process";
214 }
215 
216 //================================================================
217 // Histoes:
218 //-----------------------------------------------------------------------------
219 
221  // The Constructor
222 
223  fTypeTitle = managername;
224  fHistArray = new TObjArray(); // Array to store histos
225  fHistNamesArray = new TObjArray(); // Array to store histos's names
226 
227  bookHistos();
228 
229  fHistArray->Compress(); // Removes empty space
230  fHistNamesArray->Compress();
231 }
232 //-----------------------------------------------------------------------------
233 
235  // The Destructor
236 
237  if (fHistArray) {
238  fHistArray->Delete();
239  delete fHistArray;
240  }
241 
242  if (fHistNamesArray) {
243  fHistNamesArray->Delete();
244  delete fHistNamesArray;
245  }
246 }
247 //-----------------------------------------------------------------------------
248 
250  // at Start: (mm)
251  histInit("TrackPhi", "Primary Phi", 100, 0., 360.);
252  histInit("TrackTheta", "Primary Theta", 100, 0., 180.);
253  histInit("TrackP", "Track XY position Z+ ", 80, -80., 80., 80, -80., 80.);
254  histInit("TrackM", "Track XY position Z-", 80, -80., 80., 80, -80., 80.);
255  histInit("DetIDs", "Track DetId - vs +", 16, -0.5, 15.5, 16, 15.5, 31.5);
256 }
257 
258 //-----------------------------------------------------------------------------
259 
260 void BscAnalysisHistManager::writeToFile(const TString& fOutputFile, const TString& fRecreateFile) {
261  //Write to file = fOutputFile
262 
263  edm::LogVerbatim("BscTest") << "================================================================";
264  edm::LogVerbatim("BscTest") << " Write this Analysis to File " << fOutputFile;
265  edm::LogVerbatim("BscTest") << "================================================================";
266 
267  TFile* file = new TFile(fOutputFile, fRecreateFile);
268 
269  fHistArray->Write();
270  file->Close();
271 }
272 //-----------------------------------------------------------------------------
273 
274 void BscAnalysisHistManager::histInit(const char* name, const char* title, Int_t nbinsx, Axis_t xlow, Axis_t xup) {
275  // Add histograms and histograms names to the array
276 
277  char* newtitle = new char[strlen(title) + strlen(fTypeTitle) + 5];
278  strcpy(newtitle, title);
279  strcat(newtitle, " (");
280  strcat(newtitle, fTypeTitle);
281  strcat(newtitle, ") ");
282  fHistArray->AddLast((new TH1F(name, newtitle, nbinsx, xlow, xup)));
283  fHistNamesArray->AddLast(new TObjString(name));
284 }
285 //-----------------------------------------------------------------------------
286 
288  const char* name, const char* title, Int_t nbinsx, Axis_t xlow, Axis_t xup, Int_t nbinsy, Axis_t ylow, Axis_t yup) {
289  // Add histograms and histograms names to the array
290 
291  char* newtitle = new char[strlen(title) + strlen(fTypeTitle) + 5];
292  strcpy(newtitle, title);
293  strcat(newtitle, " (");
294  strcat(newtitle, fTypeTitle);
295  strcat(newtitle, ") ");
296  fHistArray->AddLast((new TH2F(name, newtitle, nbinsx, xlow, xup, nbinsy, ylow, yup)));
297  fHistNamesArray->AddLast(new TObjString(name));
298 }
299 //-----------------------------------------------------------------------------
300 
302  // Get a histogram from the array with index = Number
303 
304  if (Number <= fHistArray->GetLast() && fHistArray->At(Number) != (TObject*)nullptr) {
305  return (TH1F*)(fHistArray->At(Number));
306 
307  } else {
308  edm::LogVerbatim("BscTest") << "!!!!!!!!!!!!!!!!!!getHisto!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
309  edm::LogVerbatim("BscTest") << " WARNING ERROR - HIST ID INCORRECT (TOO HIGH) - " << Number;
310  edm::LogVerbatim("BscTest") << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
311 
312  return (TH1F*)(fHistArray->At(0));
313  }
314 }
315 //-----------------------------------------------------------------------------
316 
318  // Get a histogram from the array with index = Number
319 
320  if (Number <= fHistArray->GetLast() && fHistArray->At(Number) != (TObject*)nullptr) {
321  return (TH2F*)(fHistArray->At(Number));
322 
323  } else {
324  edm::LogVerbatim("BscTest") << "!!!!!!!!!!!!!!!!getHisto2!!!!!!!!!!!!!!!!!!!!!!!!!!!";
325  edm::LogVerbatim("BscTest") << " WARNING ERROR - HIST ID INCORRECT (TOO HIGH) - " << Number;
326  edm::LogVerbatim("BscTest") << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
327 
328  return (TH2F*)(fHistArray->At(0));
329  }
330 }
331 //-----------------------------------------------------------------------------
332 
333 TH1F* BscAnalysisHistManager::getHisto(const TObjString& histname) {
334  // Get a histogram from the array with name = histname
335 
336  Int_t index = fHistNamesArray->IndexOf(&histname);
337  return getHisto(index);
338 }
339 //-----------------------------------------------------------------------------
340 
341 TH2F* BscAnalysisHistManager::getHisto2(const TObjString& histname) {
342  // Get a histogram from the array with name = histname
343 
344  Int_t index = fHistNamesArray->IndexOf(&histname);
345  return getHisto2(index);
346 }
347 //-----------------------------------------------------------------------------
348 
350  // Add structure to each histogram to store the weights
351 
352  for (int i = 0; i < fHistArray->GetEntries(); i++) {
353  ((TH1F*)(fHistArray->At(i)))->Sumw2();
354  }
355 }
356 
357 //==================================================================== per JOB
358 void BscTest::update(const BeginOfJob* job) {
359  //job
360  edm::LogVerbatim("BscTest") << "BscTest:beggining of job";
361  ;
362 }
363 
364 //==================================================================== per RUN
366  //run
367 
368  edm::LogVerbatim("BscTest") << std::endl << "BscTest:: Begining of Run";
369 }
370 
371 void BscTest::update(const EndOfRun* run) { ; }
372 
373 //=================================================================== per EVENT
374 void BscTest::update(const BeginOfEvent* evt) {
375  iev = (*evt)()->GetEventID();
376  if (verbosity > 0) {
377  edm::LogVerbatim("BscTest") << "BscTest:update Event number = " << iev;
378  }
379  whichevent++;
380 }
381 
382 //=================================================================== per Track
383 void BscTest::update(const BeginOfTrack* trk) {
384  itrk = (*trk)()->GetTrackID();
385  if (verbosity > 1) {
386  edm::LogVerbatim("BscTest") << "BscTest:update BeginOfTrack number = " << itrk;
387  }
388  if (itrk == 1) {
389  sumEnerDeposit = 0.;
390  numofpart = 0;
391  sumStepl = 0.;
392  sumStepc = 0.;
393  tracklength0 = 0.;
394  }
395 }
396 
397 //=================================================================== per EndOfTrack
398 void BscTest::update(const EndOfTrack* trk) {
399  itrk = (*trk)()->GetTrackID();
400  if (verbosity > 1) {
401  edm::LogVerbatim("BscTest") << "BscTest:update EndOfTrack number = " << itrk;
402  }
403  if (itrk == 1) {
404  G4double tracklength = (*trk)()->GetTrackLength(); // Accumulated track length
405 
406  TheHistManager->getHisto("SumEDep")->Fill(sumEnerDeposit);
407  TheHistManager->getHisto("TrackL")->Fill(tracklength);
408 
409  // direction !!!
410  G4ThreeVector vert_mom = (*trk)()->GetVertexMomentumDirection();
411  G4ThreeVector vert_pos = (*trk)()->GetVertexPosition(); // vertex ,where this track was created
412 
413  // last step information
414  const G4Step* aStep = (*trk)()->GetStep();
415  G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
416  lastpo = preStepPoint->GetPosition();
417  }
418 }
419 
420 // ====================================================
421 
422 //=================================================================== each STEP
423 void BscTest::update(const G4Step* aStep) {
424  // ==========================================================================
425 
426  if (verbosity > 2) {
427  G4int stepnumber = aStep->GetTrack()->GetCurrentStepNumber();
428  edm::LogVerbatim("BscTest") << "BscTest:update Step number = " << stepnumber;
429  }
430  // track on aStep: !
431  G4Track* theTrack = aStep->GetTrack();
432  TrackInformation* trkInfo = dynamic_cast<TrackInformation*>(theTrack->GetUserInformation());
433  if (trkInfo == nullptr) {
434  edm::LogVerbatim("BscTest") << "BscTest on aStep: No trk info !!!! abort ";
435  }
436  G4int id = theTrack->GetTrackID();
437  G4String particleType = theTrack->GetDefinition()->GetParticleName(); // !!!
438  G4int parentID = theTrack->GetParentID(); // !!!
439  G4TrackStatus trackstatus = theTrack->GetTrackStatus(); // !!!
440  G4double tracklength = theTrack->GetTrackLength(); // Accumulated track length
441  G4ThreeVector trackmom = theTrack->GetMomentum();
442  G4double entot = theTrack->GetTotalEnergy(); // !!! deposited on step
443  G4int curstepnumber = theTrack->GetCurrentStepNumber();
444  G4double stepl = aStep->GetStepLength();
445  G4double EnerDeposit = aStep->GetTotalEnergyDeposit();
446  G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
447  const G4ThreeVector& preposition = preStepPoint->GetPosition();
448  G4ThreeVector prelocalpoint = theTrack->GetTouchable()->GetHistory()->GetTopTransform().TransformPoint(preposition);
449  G4VPhysicalVolume* currentPV = preStepPoint->GetPhysicalVolume();
450  const G4String& prename = currentPV->GetName();
451 
452  const G4VTouchable* pre_touch = preStepPoint->GetTouchable();
453  int pre_levels = detLevels(pre_touch);
454  G4String name1[20];
455  int copyno1[20];
456  for (int i = 0; i < 20; ++i) {
457  name1[i] = "";
458  copyno1[i] = 0;
459  }
460  if (pre_levels > 0) {
461  detectorLevel(pre_touch, pre_levels, copyno1, name1);
462  }
463 
464  if (id == 1) {
465  // on 1-st step:
466  if (curstepnumber == 1) {
467  entot0 = entot;
468  //UserNtuples->fillg519(entot0,1.);
469  }
470 
471  // on every step:
472 
473  // for Copper:
474  if (prename == "SBST") {
475  sumStepc += stepl;
476  // =========
477  }
478  // for ststeel:
479  // if(prename == "SBSTs") {
480  if (prename == "SBSTs") {
481  sumStepl += stepl;
482  // =========
483  }
484  // =========
485  // =========
486 
487  // exclude last track point if it is in SD (MI was started their)
488  if (trackstatus != 2) {
489  // for SD: Si Det.: SISTATION:SIPLANE:(SIDETL+BOUNDDET +SIDETR + CERAMDET)
490  if (prename == "SIDETL" || prename == "SIDETR") {
491  if (prename == "SIDETL") {
492  //UserNtuples->fillg569(EnerDeposit,1.);
493  }
494  if (prename == "SIDETR") {
495  //UserNtuples->fillg570(EnerDeposit,1.);
496  }
497 
498  G4String posname = aStep->GetPostStepPoint()->GetPhysicalVolume()->GetName();
499  if ((prename == "SIDETL" && posname != "SIDETL") || (prename == "SIDETR" && posname != "SIDETR")) {
500  if (name1[2] == "SISTATION") {
501  //UserNtuples->fillg539(copyno1[2],1.);
502  }
503  if (name1[3] == "SIPLANE") {
504  //UserNtuples->fillg540(copyno1[3],1.);
505  }
506 
507  if (prename == "SIDETL") {
508  //UserNtuples->fillg541(EnerDeposit,1.);
509  //UserNtuples->fillg561(numbcont,1.);
510  if (copyno1[2] < 2) {
511  //UserNtuples->fillg571(dx,1.);
512  } else if (copyno1[2] < 3) {
513  //UserNtuples->fillg563(dx,1.);
514  if (copyno1[3] < 2) {
515  } else if (copyno1[3] < 3) {
516  //UserNtuples->fillg572(dx,1.);
517  } else if (copyno1[3] < 4) {
518  //UserNtuples->fillg573(dx,1.);
519  } else if (copyno1[3] < 5) {
520  //UserNtuples->fillg574(dx,1.);
521  } else if (copyno1[3] < 6) {
522  //UserNtuples->fillg575(dx,1.);
523  } else if (copyno1[3] < 7) {
524  //UserNtuples->fillg576(dx,1.);
525  } else if (copyno1[3] < 8) {
526  //UserNtuples->fillg577(dx,1.);
527  } else if (copyno1[3] < 9) {
528  //UserNtuples->fillg578(dx,1.);
529  } else if (copyno1[3] < 10) {
530  //UserNtuples->fillg579(dx,1.);
531  }
532  } else if (copyno1[2] < 4) {
533  //UserNtuples->fillg565(dx,1.);
534  } else if (copyno1[2] < 5) {
535  //UserNtuples->fillg567(dx,1.);
536  }
537  }
538  if (prename == "SIDETR") {
539  //UserNtuples->fillg542(EnerDeposit,1.);
540  //UserNtuples->fillg562(numbcont,1.);
541  if (copyno1[2] < 2) {
542  //UserNtuples->fillg581(dy,1.);
543  } else if (copyno1[2] < 3) {
544  //UserNtuples->fillg564(dy,1.);
545  if (copyno1[3] < 2) {
546  } else if (copyno1[3] < 3) {
547  //UserNtuples->fillg582(dy,1.);
548  } else if (copyno1[3] < 4) {
549  //UserNtuples->fillg583(dy,1.);
550  } else if (copyno1[3] < 5) {
551  //UserNtuples->fillg584(dy,1.);
552  } else if (copyno1[3] < 6) {
553  //UserNtuples->fillg585(dy,1.);
554  } else if (copyno1[3] < 7) {
555  //UserNtuples->fillg586(dy,1.);
556  } else if (copyno1[3] < 8) {
557  //UserNtuples->fillg587(dy,1.);
558  } else if (copyno1[3] < 9) {
559  //UserNtuples->fillg588(dy,1.);
560  } else if (copyno1[3] < 10) {
561  //UserNtuples->fillg589(dy,1.);
562  }
563  } else if (copyno1[2] < 4) {
564  //UserNtuples->fillg566(dy,1.);
565  } else if (copyno1[2] < 5) {
566  //UserNtuples->fillg568(dy,1.);
567  }
568  }
569  }
570  }
571  // end of prenames SIDETL // SIDETR
572  }
573  // end of trackstatus != 2
574 
575  sumEnerDeposit += EnerDeposit;
576  if (trackstatus == 2) {
577  // primary track length
578  // //UserNtuples->fillg508(tracklength,1.);
579  tracklength0 = tracklength;
580  }
581  }
582  // end of primary track !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
583 
584  if (parentID == 1 && curstepnumber == 1) {
585  // particles deposit their energy along primary track
586  numofpart += 1;
587  if (prename == "SBST") {
588  //UserNtuples->filld225(vert_pos.y(),vert_pos.z(),1.);
589  }
590  if (prename == "SBSTs") {
591  //UserNtuples->filld226(vert_pos.y(),vert_pos.z(),1.);
592  }
593  }
594 }
595 // ==========================================================================
596 // ==========================================================================
597 int BscTest::detLevels(const G4VTouchable* touch) const {
598  //Return number of levels
599  if (touch)
600  return ((touch->GetHistoryDepth()) + 1);
601  else
602  return 0;
603 }
604 // ==========================================================================
605 
606 G4String BscTest::detName(const G4VTouchable* touch, int level, int currentlevel) const {
607  //Go down to current level
608  if (level > 0 && level >= currentlevel) {
609  int ii = level - currentlevel;
610  return touch->GetVolume(ii)->GetName();
611  } else {
612  return "NotFound";
613  }
614 }
615 
616 void BscTest::detectorLevel(const G4VTouchable* touch, int& level, int* copyno, G4String* name) const {
617  //Get name and copy numbers
618  if (level > 0) {
619  for (int ii = 0; ii < level; ii++) {
620  int i = level - ii - 1;
621  G4VPhysicalVolume* pv = touch->GetVolume(i);
622  if (pv != nullptr)
623  name[ii] = pv->GetName();
624  else
625  name[ii] = "Unknown";
626  copyno[ii] = touch->GetReplicaNumber(i);
627  }
628  }
629 }
630 // ==========================================================================
631 
632 //=================================================================== End Of Event
633 void BscTest::update(const EndOfEvent* evt) {
634  // ==========================================================================
635 
636  if (verbosity > 1) {
637  iev = (*evt)()->GetEventID();
638  edm::LogVerbatim("BscTest") << "BscTest:update EndOfEvent = " << iev;
639  }
640  // Fill-in ntuple
642 
643  //
644  int trackID = 0;
645  G4PrimaryParticle* thePrim = nullptr;
646 
647  // prim.vertex:
648  G4int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
649  if (nvertex != 1)
650  edm::LogVerbatim("BscTest") << "BscTest: My warning: NumberOfPrimaryVertex != 1 --> = " << nvertex;
651 
652  for (int i = 0; i < nvertex; i++) {
653  G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(i);
654  if (avertex == nullptr)
655  edm::LogVerbatim("BscTest") << "BscTest End Of Event ERR: pointer to vertex = 0";
656  G4int npart = avertex->GetNumberOfParticle();
657  if (npart != 1)
658  edm::LogVerbatim("BscTest") << "BscTest: My warning: NumberOfPrimaryPart != 1 --> = " << npart;
659  if (npart == 0)
660  edm::LogVerbatim("BscTest") << "BscTest End Of Event ERR: no NumberOfParticle";
661 
662  if (thePrim == nullptr)
663  thePrim = avertex->GetPrimary(trackID);
664 
665  if (thePrim != nullptr) {
666  // primary vertex:
667  G4double vx = 0., vy = 0., vz = 0.;
668  vx = avertex->GetX0();
669  vy = avertex->GetY0();
670  vz = avertex->GetZ0();
671  //UserNtuples->fillh01(vx);
672  //UserNtuples->fillh02(vy);
673  //UserNtuples->fillh03(vz);
674  TheHistManager->getHisto("VtxX")->Fill(vx);
675  TheHistManager->getHisto("VtxY")->Fill(vy);
676  TheHistManager->getHisto("VtxZ")->Fill(vz);
677  }
678  }
679  // prim.vertex loop end
680 
681  //=========================== thePrim != 0 ================================================================================
682  if (thePrim != nullptr) {
683  //
684  // number of secondary particles deposited their energy along primary track
685  //UserNtuples->fillg518(numofpart,1.);
686  if (lastpo.z() < z4 && lastpo.perp() < 100.) {
687  //UserNtuples->fillg536(numofpart,1.);
688  }
689  //
690 
691  // direction !!!
692  G4ThreeVector mom = thePrim->GetMomentum();
693 
694  double phi = atan2(mom.y(), mom.x());
695  if (phi < 0.)
696  phi += twopi;
697  double phigrad = phi * 180. / pi;
698 
699  double th = mom.theta();
700  double eta = -log(tan(th / 2));
701  TheHistManager->getHisto("PrimaryEta")->Fill(eta);
702  TheHistManager->getHisto("PrimaryPhigrad")->Fill(phigrad);
703  TheHistManager->getHisto("PrimaryTh")->Fill(th * 180. / pi);
704 
705  TheHistManager->getHisto("PrimaryLastpoZ")->Fill(lastpo.z());
706  if (lastpo.z() < z4) {
707  TheHistManager->getHisto("PrimaryLastpoX")->Fill(lastpo.x());
708  TheHistManager->getHisto("PrimaryLastpoY")->Fill(lastpo.y());
709  }
710  if (numofpart > 4) {
711  TheHistManager->getHisto("XLastpoNumofpart")->Fill(lastpo.x());
712  TheHistManager->getHisto("YLastpoNumofpart")->Fill(lastpo.y());
713  }
714 
715  // ==========================================================================
716 
717  // hit map for Bsc
718  // ==================================
719 
720  std::map<int, float, std::less<int> > themap;
721  std::map<int, float, std::less<int> > themap1;
722 
723  std::map<int, float, std::less<int> > themapxy;
724  std::map<int, float, std::less<int> > themapz;
725  // access to the G4 hit collections: -----> this work OK:
726 #ifdef EDM_ML_DEBUG
727  edm::LogVerbatim("BscTest") << "1";
728 #endif
729  G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
730 #ifdef EDM_ML_DEBUG
731  edm::LogVerbatim("BscTest") << "2";
732 #endif
733  if (verbosity > 0) {
734  edm::LogVerbatim("BscTest") << "BscTest: accessed all HC";
735  ;
736  }
737  int CAFIid = G4SDManager::GetSDMpointer()->GetCollectionID("BSCHits");
738 
739  BscG4HitCollection* theCAFI = (BscG4HitCollection*)allHC->GetHC(CAFIid);
740  if (verbosity > 0) {
741  edm::LogVerbatim("BscTest") << "BscTest: theCAFI->entries = " << theCAFI->entries();
742  }
743  int varia; // = 0 -all; =1 - MI; =2 - noMI
744  //varia = 0;
745  if (lastpo.z() < z4) {
746  varia = 1;
747  } else {
748  varia = 2;
749  } // no MI end:
750  int nhits = theCAFI->entries();
751  for (int j = 0; j < nhits; j++) {
752  BscG4Hit* aHit = (*theCAFI)[j];
753  const CLHEP::Hep3Vector& hitPoint = aHit->getEntry();
754  double zz = hitPoint.z();
755  TheHistManager->getHisto("zHits")->Fill(zz);
756  if (tracklength0 > 8300.)
757  TheHistManager->getHisto("zHitsTrLoLe")->Fill(zz);
758  }
759 
760  if (varia == 2) {
761  int nhit11 = 0, nhit12 = 0, nhit13 = 0;
762  double totallosenergy = 0.;
763  for (int j = 0; j < nhits; j++) {
764  BscG4Hit* aHit = (*theCAFI)[j];
765 
766  const CLHEP::Hep3Vector& hitEntryLocalPoint = aHit->getEntryLocalP();
767  const CLHEP::Hep3Vector& hitExitLocalPoint = aHit->getExitLocalP();
768  const CLHEP::Hep3Vector& hitPoint = aHit->getEntry();
769  int trackIDhit = aHit->getTrackID();
770  unsigned int unitID = aHit->getUnitID();
771  double losenergy = aHit->getEnergyLoss();
772 
773  double zz = hitPoint.z();
774 
775  TheHistManager->getHisto("zHitsnoMI")->Fill(zz);
776 
777  if (verbosity > 2) {
778  edm::LogVerbatim("BscTest") << "BscTest:zHits = " << zz;
779  }
780 
781  themap[unitID] += losenergy;
782  totallosenergy += losenergy;
783 
784  int zside, sector;
786  zside = (unitID & 32) >> 5;
787  sector = (unitID & 7);
788 
789  //
790  //=======================================
791  G4ThreeVector middle = (hitExitLocalPoint + hitEntryLocalPoint) / 2.;
792  themapz[unitID] = hitPoint.z() + middle.z();
793  //=======================================
794  // Y
795  if (zside == 1) {
796  //UserNtuples->fillg24(losenergy,1.);
797  if (losenergy > 0.00003) {
798  themap1[unitID] += 1.;
799  }
800  }
801  //X
802  if (zside == 2) {
803  //UserNtuples->fillg25(losenergy,1.);
804  if (losenergy > 0.00005) {
805  themap1[unitID] += 1.;
806  }
807  }
808  // }
809  //
810  if (sector == 1) {
811  nhit11 += 1;
812  //UserNtuples->fillg33(rr,1.);
813  //UserNtuples->fillg11(yy,1.);
814  }
815  if (sector == 2) {
816  nhit12 += 1;
817  //UserNtuples->fillg34(rr,1.);
818  //UserNtuples->fillg86(yy,1.);
819  }
820  if (sector == 3) {
821  nhit13 += 1;
822  //UserNtuples->fillg35(rr,1.);
823  //UserNtuples->fillg87(yy,1.);
824  }
825 
826  if (lastpo.z() < z4 && lastpo.perp() < 120.) {
827  // MIonly:
828  //UserNtuples->fillg16(lastpo.z(),1.);
829  //UserNtuples->fillg18(zz,1.);
830  // Station I
831  if (zz < z2) {
832  //UserNtuples->fillg54(dx,1.);
833  //UserNtuples->fillg55(dy,1.);
834  }
835  // Station II
836  if (zz < z3 && zz > z2) {
837  //UserNtuples->fillg50(dx,1.);
838  //UserNtuples->fillg51(dy,1.);
839  }
840  // Station III
841  if (zz < z4 && zz > z3) {
842  //UserNtuples->fillg64(dx,1.);
843  //UserNtuples->fillg65(dy,1.);
844  //UserNtuples->filld209(xx,yy,1.);
845  }
846  } else {
847  // no MIonly:
848  //UserNtuples->fillg17(lastpo.z(),1.);
849  //UserNtuples->fillg19(zz,1.);
850  //UserNtuples->fillg74(incidentEnergyHit,1.);
851  //UserNtuples->fillg75(float(trackIDhit),1.);
852  // Station I
853  if (zz < z2) {
854  //UserNtuples->fillg56(dx,1.);
855  //UserNtuples->fillg57(dy,1.);
856  //UserNtuples->fillg20(numofpart,1.);
857  //UserNtuples->fillg21(sumEnerDeposit,1.);
858  if (zside == 1) {
859  //UserNtuples->fillg26(losenergy,1.);
860  }
861  if (zside == 2) {
862  //UserNtuples->fillg76(losenergy,1.);
863  }
864  if (trackIDhit == 1) {
865  //UserNtuples->fillg70(dx,1.);
866  //UserNtuples->fillg71(incidentEnergyHit,1.);
867  //UserNtuples->fillg79(losenergy,1.);
868  } else {
869  //UserNtuples->fillg82(dx,1.);
870  }
871  }
872  // Station II
873  if (zz < z3 && zz > z2) {
874  //UserNtuples->fillg52(dx,1.);
875  //UserNtuples->fillg53(dy,1.);
876  //UserNtuples->fillg22(numofpart,1.);
877  //UserNtuples->fillg23(sumEnerDeposit,1.);
878  //UserNtuples->fillg80(incidentEnergyHit,1.);
879  //UserNtuples->fillg81(float(trackIDhit),1.);
880  if (zside == 1) {
881  //UserNtuples->fillg27(losenergy,1.);
882  }
883  if (zside == 2) {
884  //UserNtuples->fillg77(losenergy,1.);
885  }
886  if (trackIDhit == 1) {
887  //UserNtuples->fillg72(dx,1.);
888  //UserNtuples->fillg73(incidentEnergyHit,1.);
889  } else {
890  //UserNtuples->fillg83(dx,1.);
891  }
892  }
893  // Station III
894  if (zz < z4 && zz > z3) {
895  if (zside == 1) {
896  //UserNtuples->fillg28(losenergy,1.);
897  }
898  if (zside == 2) {
899  //UserNtuples->fillg78(losenergy,1.);
900  }
901  }
902  }
903  } // MIonly or noMIonly ENDED
904  if (totallosenergy == 0.0) {
905  edm::LogVerbatim("BscTest") << "BscTest: number of hits = " << theCAFI->entries();
906  for (int j = 0; j < nhits; j++) {
907  BscG4Hit* aHit = (*theCAFI)[j];
908  double losenergy = aHit->getEnergyLoss();
909  edm::LogVerbatim("BscTest") << " j hits = " << j << "losenergy = " << losenergy;
910  }
911  }
912  // FIBRE Hit collected analysis
913  double totalEnergy = 0.;
914  int nhitsX = 0, nhitsY = 0, nsumhit = 0;
915  for (int sector = 1; sector < 4; sector++) {
916  int nhitsecX = 0, nhitsecY = 0;
917  for (int zmodule = 1; zmodule < 11; zmodule++) {
918  for (int zside = 1; zside < 3; zside++) {
919  int det = 1; // nhit = 0;
920  // int sScale = 20;
921  int index = BscNumberingScheme::packBscIndex(det, zside, sector);
922  double theTotalEnergy = themap[index];
923  // X planes
924  if (zside < 2) {
925  //UserNtuples->fillg47(theTotalEnergy,1.);
926  if (theTotalEnergy > 0.00003) {
927  nhitsX += 1;
928  // nhitsecX += themap1[index];
929  // nhit=1;
930  }
931  }
932  // Y planes
933  else {
934  //UserNtuples->fillg49(theTotalEnergy,1.);
935  if (theTotalEnergy > 0.00005) {
936  nhitsY += 1;
937  // nhitsecY += themap1[index];
938  // nhit=1;
939  }
940  }
941 
942  totalEnergy += themap[index];
943  } // for
944  } // for
945  //UserNtuples->fillg39(nhitsecY,1.);
946  if (nhitsecX > 10 || nhitsecY > 10) {
947  nsumhit += 1;
948  //UserNtuples->fillp213(float(sector),float(1.),1.);
949  } else { //UserNtuples->fillp213(float(sector),float(0.),1.);
950  }
951  } // for
952 
953  if (nsumhit >= 2) { //UserNtuples->fillp212(vy,float(1.),1.);
954  } else { //UserNtuples->fillp212(vy,float(0.),1.);
955  }
956  } // MI or no MI or all - end
957  } // primary end
958 
959  if (verbosity > 0) {
960  edm::LogVerbatim("BscTest") << "BscTest: END OF Event " << (*evt)()->GetEventID();
961  }
962 }
963 
966 
Log< level::Info, true > LogVerbatim
int numofpart
Definition: BscTest.cc:144
double z2
Definition: BscTest.cc:149
#define DEFINE_SIMWATCHER(type)
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
double z1
Definition: BscTest.cc:149
int detLevels(const G4VTouchable *) const
Definition: BscTest.cc:597
uint32_t getUnitID() const
Definition: BscG4Hit.h:56
std::string fOutputFile
Definition: BscTest.cc:159
TH1F * getHisto(Int_t Number)
Definition: BscTest.cc:301
double npart
Definition: HydjetWrapper.h:46
int zside(DetId const &)
G4ThreeVector lastpo
Definition: BscTest.cc:146
TObjArray * fHistNamesArray
Definition: BscTest.cc:97
int iev
Definition: BscTest.cc:127
TObjArray * fHistArray
Definition: BscTest.cc:96
G4double sumStepc
Definition: BscTest.cc:142
std::string fRecreateFile
Definition: BscTest.cc:160
const Double_t pi
G4String detName(const G4VTouchable *, int, int) const
Definition: BscTest.cc:606
double rinCalo
Definition: BscTest.cc:137
int verbosity
Definition: BscTest.cc:139
double z4
Definition: BscTest.cc:149
const char * fTypeTitle
Definition: BscTest.cc:95
int whichevent
Definition: BscTest.cc:155
void histInit(const char *name, const char *title, Int_t nbinsx, Axis_t xlow, Axis_t xup)
Definition: BscTest.cc:274
static unsigned int packBscIndex(int det, int zside, int station)
void detectorLevel(const G4VTouchable *, int &, int *, G4String *) const
Definition: BscTest.cc:616
std::string fDataLabel
Definition: BscTest.cc:158
G4double entot0
Definition: BscTest.cc:129
int getTrackID() const
Definition: BscG4Hit.h:53
BscAnalysisHistManager * TheHistManager
Definition: BscTest.cc:157
double z3
Definition: BscTest.cc:149
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
def pv(vc)
Definition: MetAnalyzer.py:7
void update(const BeginOfJob *run) override
This routine will be called when the appropriate signal arrives.
Definition: BscTest.cc:358
BscTest(const edm::ParameterSet &p)
Definition: BscTest.cc:166
static void unpackBscIndex(const unsigned int &idx)
double zinCalo
Definition: BscTest.cc:137
BscNumberingScheme * theBscNumberingScheme
Definition: BscTest.cc:125
ii
Definition: cuy.py:589
TH2F * getHisto2(Int_t Number)
Definition: BscTest.cc:317
G4double sumEnerDeposit
Definition: BscTest.cc:142
G4double sumStepl
Definition: BscTest.cc:142
TNtuple * bsceventntuple
Definition: BscTest.cc:153
~BscTest() override
Definition: BscTest.cc:192
int lastTrackID
Definition: BscTest.cc:138
float getEnergyLoss() const
Definition: BscG4Hit.h:69
const G4ThreeVector & getEntry() const
Definition: BscG4Hit.h:29
int itrk
Definition: BscTest.cc:128
const G4ThreeVector & getExitLocalP() const
Definition: BscG4Hit.h:35
Float_t bsceventarray[1]
Definition: BscTest.cc:152
step
Definition: StallMonitor.cc:98
TFile bscOutputFile
Definition: BscTest.cc:154
G4THitsCollection< BscG4Hit > BscG4HitCollection
ntbsc_elements
Definition: BscTest.cc:163
BscAnalysisHistManager(const TString &managername)
Definition: BscTest.cc:220
const G4ThreeVector & getEntryLocalP() const
Definition: BscG4Hit.h:32
void writeToFile(const TString &fOutputFile, const TString &fRecreateFile)
Definition: BscTest.cc:260
G4double tracklength0
Definition: BscTest.cc:129
~BscAnalysisHistManager() override
Definition: BscTest.cc:234