CMS 3D CMS Logo

FP420Test.cc
Go to the documentation of this file.
1 // system include files
2 #include <iostream>
3 #include <map>
4 #include <string>
5 //
6 // user include files
14 //
26 // to retreive hits
29 // G4 stuff
30 #include "G4HCofThisEvent.hh"
31 #include "G4ProcessManager.hh"
32 #include "G4SDManager.hh"
33 #include "G4Step.hh"
34 #include "G4Track.hh"
35 #include "G4TransportationManager.hh"
36 #include "G4UserEventAction.hh"
37 #include "G4VProcess.hh"
38 #include "G4VTouchable.hh"
39 
40 #include <CLHEP/Random/Randomize.h>
41 #include <CLHEP/Units/SystemOfUnits.h>
42 #include <CLHEP/Units/GlobalPhysicalConstants.h>
43 
44 //================================================================
45 // Root stuff
46 #include "TROOT.h"
47 #include "TFile.h"
48 #include "TH1.h"
49 #include "TH2.h"
50 #include "TProfile.h"
51 #include "TNtuple.h"
52 #include "TRandom.h"
53 #include "TLorentzVector.h"
54 #include "TUnixSystem.h"
55 #include "TSystem.h"
56 #include "TMath.h"
57 #include "TF1.h"
58 #include "TObjArray.h"
59 #include "TObjString.h"
60 #include "TNamed.h"
61 
62 class Fp420AnalysisHistManager : public TNamed {
63 public:
64  Fp420AnalysisHistManager(const TString& managername);
65  ~Fp420AnalysisHistManager() override;
66 
67  TH1F* getHisto(Int_t Number);
68  TH1F* getHisto(const TObjString& histname);
69 
70  TH2F* getHisto2(Int_t Number);
71  TH2F* getHisto2(const TObjString& histname);
72 
73  void writeToFile(const TString& fOutputFile, const TString& fRecreateFile);
74 
75 private:
76  void bookHistos();
77  void storeWeights();
78  void histInit(const char* name, const char* title, Int_t nbinsx, Axis_t xlow, Axis_t xup);
79  void histInit(
80  const char* name, const char* title, Int_t nbinsx, Axis_t xlow, Axis_t xup, Int_t nbinsy, Axis_t ylow, Axis_t yup);
81 
82  const char* fTypeTitle;
83  TObjArray* fHistArray;
84  TObjArray* fHistNamesArray;
85 };
86 
87 class FP420Test : public SimWatcher,
88  public Observer<const BeginOfJob*>,
89  public Observer<const BeginOfRun*>,
90  public Observer<const EndOfRun*>,
91  public Observer<const BeginOfEvent*>,
92  public Observer<const BeginOfTrack*>,
93  public Observer<const G4Step*>,
94  public Observer<const EndOfTrack*>,
95  public Observer<const EndOfEvent*> {
96 public:
98  ~FP420Test() override;
99 
100 private:
101  // observer classes
102  void update(const BeginOfJob* run) override;
103  void update(const BeginOfRun* run) override;
104  void update(const EndOfRun* run) override;
105  void update(const BeginOfEvent* evt) override;
106  void update(const BeginOfTrack* trk) override;
107  void update(const G4Step* step) override;
108  void update(const EndOfTrack* trk) override;
109  void update(const EndOfEvent* evt) override;
110 
111 private:
112  // Utilities to get detector levels during a step
113 
114  int detLevels(const G4VTouchable*) const;
115  G4String detName(const G4VTouchable*, int, int) const;
116  void detectorLevel(const G4VTouchable*, int&, int*, G4String*) const;
117 
118  //UHB_Analysis* UserNtuples;
119 
120  int iev;
121  int itrk;
122  G4double entot0, tracklength0;
123 
124  double rinCalo, zinCalo;
127 
128  // sumEnerDeposit - all deposited energy on all steps ; sumStepl - length in steel !!!
130  // numofpart - # particles produced along primary track
132  // last point of the primary track
133  G4ThreeVector lastpo;
134 
135  // z:
136  double z1, z2, z3, z4, zD2, zD3;
137  int sn0, dn0, pn0, rn0;
138  int rn00;
139  double zSiDet, z420;
141  double zBlade, gapBlade;
142 
143  Float_t fp420eventarray[1];
147 
148  Fp420AnalysisHistManager* theHistManager; //Histogram Manager of the analysis
149  std::string fDataLabel; // Data type label
150  std::string fOutputFile; // The output file name
151  std::string fRecreateFile; // Recreate the file flag, default="RECREATE"
152 };
153 
154 //================================================================
156 //================================================================
158  //constructor
159  edm::ParameterSet m_Anal = p.getParameter<edm::ParameterSet>("FP420Test");
160  verbosity = m_Anal.getParameter<int>("Verbosity");
161  //verbosity = 1;
162 
163  fDataLabel = m_Anal.getParameter<std::string>("FDataLabel");
164  fOutputFile = m_Anal.getParameter<std::string>("FOutputFile");
165  fRecreateFile = m_Anal.getParameter<std::string>("FRecreateFile");
166 
167  if (verbosity > 0) {
168  edm::LogVerbatim("FP420Test") << "============================================================================";
169  edm::LogVerbatim("FP420Test") << "FP420Testconstructor :: Initialized as observer";
170  }
171  // Initialization:
172 
173  pn0 = 6;
174  sn0 = 3;
175  rn00 = 7;
176 
177  z420 = 420000.0; // mm
178  zD2 = 4000.0; // mm
179  zD3 = 8000.0; // mm
180  //
181  zBlade = 5.00;
182  gapBlade = 1.6;
183  double gapSupplane = 1.6;
184  zSiPlane = 2 * zBlade + gapBlade + gapSupplane;
185 
186  double zKapton = 0.1;
187  zSiStep = zSiPlane + zKapton;
188 
189  double zBoundDet = 0.020;
190  double zSiElectr = 0.250;
191  double zCeramDet = 0.500;
192  //
193  zSiDet = 0.250;
194  zGapLDet = zBlade / 2 - (zSiDet + zSiElectr + zBoundDet + zCeramDet / 2);
195  //
196  // zSiStation = 5*(2*(5.+1.6)+0.1)+2*6.+1.0 = 79.5
197  double zSiStation = (pn0 - 1) * (2 * (zBlade + gapBlade) + zKapton) + 2 * 6. + 0.0; // = 78.5
198  // 11.=e1, 12.=e2 in zzzrectangle.xml
199  double eee1 = 11.;
200  double eee2 = 12.;
201 
202  zinibeg = (eee1 - eee2) / 2.;
203 
204  z1 = zinibeg + (zSiStation + 10.) / 2 + z420; // z1 - right after 1st Station
205  z2 = z1 + zD2; //z2 - right after middle Station
206  z3 = z1 + zD3; //z3 - right after last Station
207  z4 = z1 + 2 * zD3;
208  //==================================
209 
210  fp420eventntuple = new TNtuple("NTfp420event", "NTfp420event", "evt");
211 
212  whichevent = 0;
213 
214  // fDataLabel = "defaultData";
215  // fOutputFile = "TheAnlysis.root";
216  // fRecreateFile = "RECREATE";
217 
219 
220  if (verbosity > 0) {
221  edm::LogVerbatim("FP420Test") << "FP420Test constructor :: Initialized Fp420AnalysisHistManager";
222  }
223 }
224 
226  // delete UserNtuples;
227 
228  TFile fp420OutputFile("newntfp420.root", "RECREATE");
229  edm::LogVerbatim("FP420Test") << "FP420 output root file has been created";
230  fp420eventntuple->Write();
231  edm::LogVerbatim("FP420Test") << "FP420 output root file has been written";
232  fp420OutputFile.Close();
233  edm::LogVerbatim("FP420Test") << "FP420 output root file has been closed";
234  delete fp420eventntuple;
235  edm::LogVerbatim("FP420Test") << "FP420 output root file pointer has been deleted";
236 
237  //------->while end
238 
239  // Write histograms to file
241  if (verbosity > 0) {
242  edm::LogVerbatim("FP420Test") << std::endl << "FP420Test Destructor --------> End of FP420Test : ";
243  }
244 }
245 
246 //================================================================
247 // Histoes:
248 //-----------------------------------------------------------------------------
249 
251  // The Constructor
252 
253  fTypeTitle = managername;
254  fHistArray = new TObjArray(); // Array to store histos
255  fHistNamesArray = new TObjArray(); // Array to store histos's names
256 
257  TH1::AddDirectory(kFALSE);
258  bookHistos();
259 
260  fHistArray->Compress(); // Removes empty space
261  fHistNamesArray->Compress();
262 
263  // storeWeights(); // Store the weights
264 }
265 //-----------------------------------------------------------------------------
266 
268  // The Destructor
269 
270  if (fHistArray) {
271  fHistArray->Delete();
272  delete fHistArray;
273  }
274 
275  if (fHistNamesArray) {
276  fHistNamesArray->Delete();
277  delete fHistNamesArray;
278  }
279 }
280 //-----------------------------------------------------------------------------
281 
283  // at Start: (mm)
284  histInit("PrimaryEta", "Primary Eta", 100, 9., 12.);
285  histInit("PrimaryPhigrad", "Primary Phigrad", 100, 0., 360.);
286  histInit("PrimaryTh", "Primary Th", 100, 0., 180.);
287  histInit("PrimaryLastpoZ", "Primary Lastpo Z", 100, -200., 430000.);
288  histInit("PrimaryLastpoX", "Primary Lastpo X Z<z4", 100, -30., 30.);
289  histInit("PrimaryLastpoY", "Primary Lastpo Y Z<z4", 100, -30., 30.);
290  histInit("XLastpoNumofpart", "Primary Lastpo X n>10", 100, -30., 30.);
291  histInit("YLastpoNumofpart", "Primary Lastpo Y n>10", 100, -30., 30.);
292  histInit("VtxX", "Vtx X", 100, -50., 50.);
293  histInit("VtxY", "Vtx Y", 100, -50., 50.);
294  histInit("VtxZ", "Vtx Z", 100, -200., 430000.);
295  // Book the histograms and add them to the array
296  histInit("SumEDep", "This is sum Energy deposited", 100, -1, 199.);
297  histInit("TrackL", "This is TrackL", 100, 0., 12000.);
298  histInit("zHits", "z Hits all events", 100, 400000., 430000.);
299  histInit("zHitsnoMI", "z Hits no MI", 100, 400000., 430000.);
300  histInit("zHitsTrLoLe", "z Hits TrLength bigger 8300", 100, 400000., 430000.);
301  histInit("NumberOfHits", "NumberOfHits", 100, 0., 300.);
302 }
303 
304 //-----------------------------------------------------------------------------
305 
306 void Fp420AnalysisHistManager::writeToFile(const TString& fOutputFile, const TString& fRecreateFile) {
307  //Write to file = fOutputFile
308 
309  edm::LogVerbatim("FP420Test") << "================================================================";
310  edm::LogVerbatim("FP420Test") << " Write this Analysis to File " << fOutputFile;
311  edm::LogVerbatim("FP420Test") << "================================================================";
312 
313  TFile* file = new TFile(fOutputFile, fRecreateFile);
314 
315  fHistArray->Write();
316  file->Close();
317 }
318 //-----------------------------------------------------------------------------
319 
320 void Fp420AnalysisHistManager::histInit(const char* name, const char* title, Int_t nbinsx, Axis_t xlow, Axis_t xup) {
321  // Add histograms and histograms names to the array
322 
323  char* newtitle = new char[strlen(title) + strlen(fTypeTitle) + 5];
324  strcpy(newtitle, title);
325  strcat(newtitle, " (");
326  strcat(newtitle, fTypeTitle);
327  strcat(newtitle, ") ");
328  fHistArray->AddLast((new TH1F(name, newtitle, nbinsx, xlow, xup)));
329  fHistNamesArray->AddLast(new TObjString(name));
330 }
331 //-----------------------------------------------------------------------------
332 
334  const char* name, const char* title, Int_t nbinsx, Axis_t xlow, Axis_t xup, Int_t nbinsy, Axis_t ylow, Axis_t yup) {
335  // Add histograms and histograms names to the array
336 
337  char* newtitle = new char[strlen(title) + strlen(fTypeTitle) + 5];
338  strcpy(newtitle, title);
339  strcat(newtitle, " (");
340  strcat(newtitle, fTypeTitle);
341  strcat(newtitle, ") ");
342  fHistArray->AddLast((new TH2F(name, newtitle, nbinsx, xlow, xup, nbinsy, ylow, yup)));
343  fHistNamesArray->AddLast(new TObjString(name));
344 }
345 //-----------------------------------------------------------------------------
346 
348  // Get a histogram from the array with index = Number
349 
350  if (Number <= fHistArray->GetLast() && fHistArray->At(Number) != (TObject*)nullptr) {
351  return (TH1F*)(fHistArray->At(Number));
352 
353  } else {
354  edm::LogVerbatim("FP420Test") << "!!!!!!!!!!!!!!!!!!getHisto!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
355  edm::LogVerbatim("FP420Test") << " WARNING ERROR - HIST ID INCORRECT (TOO HIGH) - " << Number;
356  edm::LogVerbatim("FP420Test") << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
357 
358  return (TH1F*)(fHistArray->At(0));
359  }
360 }
361 //-----------------------------------------------------------------------------
362 
364  // Get a histogram from the array with index = Number
365 
366  if (Number <= fHistArray->GetLast() && fHistArray->At(Number) != (TObject*)nullptr) {
367  return (TH2F*)(fHistArray->At(Number));
368 
369  } else {
370  edm::LogVerbatim("FP420Test") << "!!!!!!!!!!!!!!!!getHisto2!!!!!!!!!!!!!!!!!!!!!!!!!!!";
371  edm::LogVerbatim("FP420Test") << " WARNING ERROR - HIST ID INCORRECT (TOO HIGH) - " << Number;
372  edm::LogVerbatim("FP420Test") << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
373 
374  return (TH2F*)(fHistArray->At(0));
375  }
376 }
377 //-----------------------------------------------------------------------------
378 
379 TH1F* Fp420AnalysisHistManager::getHisto(const TObjString& histname) {
380  // Get a histogram from the array with name = histname
381 
382  Int_t index = fHistNamesArray->IndexOf(&histname);
383  return getHisto(index);
384 }
385 //-----------------------------------------------------------------------------
386 
387 TH2F* Fp420AnalysisHistManager::getHisto2(const TObjString& histname) {
388  // Get a histogram from the array with name = histname
389 
390  Int_t index = fHistNamesArray->IndexOf(&histname);
391  return getHisto2(index);
392 }
393 //-----------------------------------------------------------------------------
394 
396  // Add structure to each histogram to store the weights
397 
398  for (int i = 0; i < fHistArray->GetEntries(); i++) {
399  ((TH1F*)(fHistArray->At(i)))->Sumw2();
400  }
401 }
402 
403 // Histoes end :
404 
405 //================================================================
406 
407 // using several observers
408 
409 //==================================================================== per JOB
410 void FP420Test::update(const BeginOfJob* job) {
411  //job
412  edm::LogVerbatim("FP420Test") << "FP420Test:beggining of job";
413  ;
414 }
415 
416 //==================================================================== per RUN
418  //run
419 
420  edm::LogVerbatim("FP420Test") << std::endl << "FP420Test:: Begining of Run";
421 }
422 
423 void FP420Test::update(const EndOfRun* run) { ; }
424 
425 //=================================================================== per EVENT
426 void FP420Test::update(const BeginOfEvent* evt) {
427  iev = (*evt)()->GetEventID();
428  if (verbosity > 0) {
429  edm::LogVerbatim("FP420Test") << "FP420Test:update Event number = " << iev;
430  }
431  whichevent++;
432 }
433 
434 //=================================================================== per Track
435 void FP420Test::update(const BeginOfTrack* trk) {
436  itrk = (*trk)()->GetTrackID();
437  if (verbosity > 1) {
438  edm::LogVerbatim("FP420Test") << "FP420Test:update BeginOfTrack number = " << itrk;
439  }
440  if (itrk == 1) {
441  sumEnerDeposit = 0.;
442  numofpart = 0;
443  sumStepl = 0.;
444  sumStepc = 0.;
445  tracklength0 = 0.;
446  }
447 }
448 
449 //=================================================================== per EndOfTrack
450 void FP420Test::update(const EndOfTrack* trk) {
451  itrk = (*trk)()->GetTrackID();
452  if (verbosity > 1) {
453  edm::LogVerbatim("FP420Test") << "FP420Test:update EndOfTrack number = " << itrk;
454  }
455  if (itrk == 1) {
456  G4double tracklength = (*trk)()->GetTrackLength(); // Accumulated track length
457 
458  theHistManager->getHisto("SumEDep")->Fill(sumEnerDeposit);
459  theHistManager->getHisto("TrackL")->Fill(tracklength);
460 
461  // direction !!!
462  G4ThreeVector vert_mom = (*trk)()->GetVertexMomentumDirection();
463  G4ThreeVector vert_pos = (*trk)()->GetVertexPosition(); // vertex ,where this track was created
464 
465  // float eta = 0.5 * log( (1.+vert_mom.z()) / (1.-vert_mom.z()) );
466  // float phi = atan2(vert_mom.y(),vert_mom.x());
467  // if (phi < 0.) phi += twopi;
468  // float phigrad = phi*180./pi;
469 
470  // float XV = vert_pos.x(); // mm
471  // float YV = vert_pos.y(); // mm
472  //UserNtuples->fillg543(phigrad,1.);
473  //UserNtuples->fillp203(phigrad,sumStepl,1.);
474  //UserNtuples->fillg544(XV,1.);
475  //UserNtuples->fillp201(XV,sumStepl,1.);
476  //UserNtuples->fillg545(YV,1.);
477  //UserNtuples->fillp202(YV,sumStepl,1.);
478 
479  //UserNtuples->fillg524(eta,1.);
480 
481  //UserNtuples->fillg534(sumStepl,1.);
482  //UserNtuples->fillg535(eta,sumStepl);
483  //UserNtuples->fillp207(eta,sumStepl,1.);
484  //UserNtuples->filld217(eta,sumStepl,1.);
485  //UserNtuples->filld220(phigrad,sumStepl,1.);
486  //UserNtuples->filld221(XV,sumStepl,1.);
487  //UserNtuples->filld222(YV,sumStepl,1.);
488  //UserNtuples->fillg537(sumStepc,1.);
489  //UserNtuples->fillg84(sumStepl,1.);
490 
491  // MI = (multiple interactions):
492  if (tracklength < z4) {
493  // //UserNtuples->fillp208(eta,tracklength,1.);
494  //UserNtuples->filld218(eta,tracklength,1.);
495  //UserNtuples->fillg538(sumStepc,1.);
496  //UserNtuples->fillg85(sumStepl,1.);
497  }
498 
499  // last step information
500  const G4Step* aStep = (*trk)()->GetStep();
501  // G4int csn = (*trk)()->GetCurrentStepNumber();
502  // G4double sl = (*trk)()->GetStepLength();
503  // preStep
504  G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
505  lastpo = preStepPoint->GetPosition();
506 
507  // Analysis:
508  if (lastpo.z() < z1 && lastpo.perp() < 100.) {
509  //UserNtuples->fillg525(eta,1.);
510  //UserNtuples->fillg546(XV,1.);
511  //UserNtuples->fillg551(YV,1.);
512  //UserNtuples->fillg556(phigrad,1.);
513  }
514  if ((lastpo.z() > z1 && lastpo.z() < z2) && lastpo.perp() < 100.) {
515  //UserNtuples->fillg526(eta,1.);
516  //UserNtuples->fillg547(XV,1.);
517  //UserNtuples->fillg552(YV,1.);
518  //UserNtuples->fillg557(phigrad,1.);
519  }
520  if (lastpo.z() < z2 && lastpo.perp() < 100.) {
521  //UserNtuples->fillg527(eta,1.);
522  //UserNtuples->fillg548(XV,1.);
523  //UserNtuples->fillg553(YV,1.);
524  //UserNtuples->fillg558(phigrad,1.);
525  //UserNtuples->fillg521(lastpo.x(),1.);
526  //UserNtuples->fillg522(lastpo.y(),1.);
527  //UserNtuples->fillg523(lastpo.z(),1.);
528  }
529  if (lastpo.z() < z3 && lastpo.perp() < 100.) {
530  //UserNtuples->fillg528(eta,1.);
531  //UserNtuples->fillg549(XV,1.);
532  //UserNtuples->fillg554(YV,1.);
533  //UserNtuples->fillg559(phigrad,1.);
534  }
535  if (lastpo.z() < z4 && lastpo.perp() < 100.) {
536  //UserNtuples->fillg529(eta,1.);
537  //UserNtuples->fillg550(XV,1.);
538  //UserNtuples->fillg555(YV,1.);
539  //UserNtuples->fillg560(phigrad,1.);
540  //UserNtuples->fillg531(lastpo.x(),1.);
541  //UserNtuples->fillg532(lastpo.y(),1.);
542  //UserNtuples->fillg533(lastpo.z(),1.);
543  }
544  }
545 }
546 
547 // ====================================================
548 
549 //=================================================================== each STEP
550 void FP420Test::update(const G4Step* aStep) {
551  // ==========================================================================
552 
553  if (verbosity > 2) {
554  G4int stepnumber = aStep->GetTrack()->GetCurrentStepNumber();
555  edm::LogVerbatim("FP420Test") << "FP420Test:update Step number = " << stepnumber;
556  }
557  // track on aStep: !
558  G4Track* theTrack = aStep->GetTrack();
559  TrackInformation* trkInfo = dynamic_cast<TrackInformation*>(theTrack->GetUserInformation());
560  if (trkInfo == nullptr) {
561  edm::LogVerbatim("FP420Test") << "FP420Test on aStep: No trk info !!!! abort ";
562  }
563  G4int id = theTrack->GetTrackID();
564  G4String particleType = theTrack->GetDefinition()->GetParticleName(); // !!!
565  G4int parentID = theTrack->GetParentID(); // !!!
566  G4TrackStatus trackstatus = theTrack->GetTrackStatus(); // !!!
567  G4double tracklength = theTrack->GetTrackLength(); // Accumulated track length
568  G4ThreeVector trackmom = theTrack->GetMomentum();
569  G4double entot = theTrack->GetTotalEnergy(); // !!! deposited on step
570  G4int curstepnumber = theTrack->GetCurrentStepNumber();
571  // const G4ThreeVector& vert_pos = theTrack->GetVertexPosition(); // vertex ,where this track was created
572  // const G4ThreeVector& vert_mom = theTrack->GetVertexMomentumDirection();
573 
574  // double costheta =vert_mom.z()/sqrt(vert_mom.x()*vert_mom.x()+vert_mom.y()*vert_mom.y()+vert_mom.z()*vert_mom.z());
575  // double theta = acos(min(max(costheta,double(-1.)),double(1.)));
576  // float eta = -log(tan(theta/2));
577  // double phi = -1000.;
578  // if (vert_mom.x() != 0) phi = atan2(vert_mom.y(),vert_mom.x());
579  // if (phi < 0.) phi += twopi;
580  // double phigrad = phi*360./twopi;
581 
582  //G4double trackvel = theTrack->GetVelocity();
583 
584  //edm::LogVerbatim("FP420Test") << " trackstatus= " << trackstatus << " entot= " << entot ;
585 
586  // step points: !
587  G4double stepl = aStep->GetStepLength();
588  G4double EnerDeposit = aStep->GetTotalEnergyDeposit();
589  // pointers: !
590  //G4VPhysicalVolume* physvol = theTrack->GetVolume();
591  //G4VPhysicalVolume* nextphysvol = theTrack->GetNextVolume();
592  //G4Material* materialtr = theTrack->GetMaterial();
593  //G4Material* nextmaterialtr = theTrack->GetNextMaterial();
594 
595  // preStep
596  G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
597  const G4ThreeVector& preposition = preStepPoint->GetPosition();
598  G4ThreeVector prelocalpoint = theTrack->GetTouchable()->GetHistory()->GetTopTransform().TransformPoint(preposition);
599  G4VPhysicalVolume* currentPV = preStepPoint->GetPhysicalVolume();
600  const G4String& prename = currentPV->GetName();
601 
602  const G4VTouchable* pre_touch = preStepPoint->GetTouchable();
603  int pre_levels = detLevels(pre_touch);
604 
605  G4String name1[20];
606  int copyno1[20];
607  for (int i = 0; i < 20; ++i) {
608  name1[i] = "";
609  copyno1[i] = 0;
610  }
611  if (pre_levels > 0) {
612  detectorLevel(pre_touch, pre_levels, copyno1, name1);
613  }
614 
615  // gen_track:
616  // id=1 parentID=1 trackstatus=0,2 tracklength(accumulated) curstepnumber entot vert_pos
617  if (id == 1) {
618  // on 1-st step:
619  if (curstepnumber == 1) {
620  entot0 = entot;
621  //UserNtuples->fillg519(entot0,1.);
622  }
623 
624  // on every step:
625 
626  // for Copper:
627  if (prename == "SBST") {
628  sumStepc += stepl;
629  // =========
630  }
631  // for ststeel:
632  // if(prename == "SBSTs") {
633  if (prename == "SBSTs") {
634  sumStepl += stepl;
635  // =========
636  }
637  // =========
638  // =========
639 
640  // exclude last track point if it is in SD (MI was started their)
641  if (trackstatus != 2) {
642  // for SD: Si Det.: SISTATION:SIPLANE:(SIDETL+BOUNDDET +SIDETR + CERAMDET)
643  if (prename == "SIDETL" || prename == "SIDETR") {
644  if (prename == "SIDETL") {
645  //UserNtuples->fillg569(EnerDeposit,1.);
646  }
647  if (prename == "SIDETR") {
648  //UserNtuples->fillg570(EnerDeposit,1.);
649  }
650 
651  // double numbcont = 10.*(copyno1[2]-1)+copyno1[3];
652 
653  // =========
654  // double xx = preposition.x();
655  // double yy = preposition.y();
656  // double zz = preposition.z();
657  // =========
658  //UserNtuples->fillg580(theta,1.);
659  //UserNtuples->fillg07(phigrad,1.);
660  // double xPrimAtZhit = vert_pos.x() + (zz-vert_pos.z())*tan(theta)*cos(phi);
661  // double yPrimAtZhit = vert_pos.y() + (zz-vert_pos.z())*tan(theta)*sin(phi);
662  // =========
663  // double dx = xPrimAtZhit - xx;
664  // double dy = yPrimAtZhit - yy;
665  // =========
666 
667  // //UserNtuples->fillp212(numbcont,dx,1.);
668  // //UserNtuples->fillp213(numbcont,dy,1.);
669  // =========
670 
671  // last step of current SD Volume:
672  G4String posname = aStep->GetPostStepPoint()->GetPhysicalVolume()->GetName();
673  if ((prename == "SIDETL" && posname != "SIDETL") || (prename == "SIDETR" && posname != "SIDETR")) {
674  if (name1[2] == "SISTATION") {
675  //UserNtuples->fillg539(copyno1[2],1.);
676  }
677  if (name1[3] == "SIPLANE") {
678  //UserNtuples->fillg540(copyno1[3],1.);
679  }
680 
681  if (prename == "SIDETL") {
682  //UserNtuples->fillg541(EnerDeposit,1.);
683  //UserNtuples->fillg561(numbcont,1.);
684  if (copyno1[2] < 2) {
685  //UserNtuples->fillg571(dx,1.);
686  } else if (copyno1[2] < 3) {
687  //UserNtuples->fillg563(dx,1.);
688  if (copyno1[3] < 2) {
689  } else if (copyno1[3] < 3) {
690  //UserNtuples->fillg572(dx,1.);
691  } else if (copyno1[3] < 4) {
692  //UserNtuples->fillg573(dx,1.);
693  } else if (copyno1[3] < 5) {
694  //UserNtuples->fillg574(dx,1.);
695  } else if (copyno1[3] < 6) {
696  //UserNtuples->fillg575(dx,1.);
697  } else if (copyno1[3] < 7) {
698  //UserNtuples->fillg576(dx,1.);
699  } else if (copyno1[3] < 8) {
700  //UserNtuples->fillg577(dx,1.);
701  } else if (copyno1[3] < 9) {
702  //UserNtuples->fillg578(dx,1.);
703  } else if (copyno1[3] < 10) {
704  //UserNtuples->fillg579(dx,1.);
705  }
706  } else if (copyno1[2] < 4) {
707  //UserNtuples->fillg565(dx,1.);
708  } else if (copyno1[2] < 5) {
709  //UserNtuples->fillg567(dx,1.);
710  }
711  }
712  if (prename == "SIDETR") {
713  //UserNtuples->fillg542(EnerDeposit,1.);
714  //UserNtuples->fillg562(numbcont,1.);
715  if (copyno1[2] < 2) {
716  //UserNtuples->fillg581(dy,1.);
717  } else if (copyno1[2] < 3) {
718  //UserNtuples->fillg564(dy,1.);
719  if (copyno1[3] < 2) {
720  } else if (copyno1[3] < 3) {
721  //UserNtuples->fillg582(dy,1.);
722  } else if (copyno1[3] < 4) {
723  //UserNtuples->fillg583(dy,1.);
724  } else if (copyno1[3] < 5) {
725  //UserNtuples->fillg584(dy,1.);
726  } else if (copyno1[3] < 6) {
727  //UserNtuples->fillg585(dy,1.);
728  } else if (copyno1[3] < 7) {
729  //UserNtuples->fillg586(dy,1.);
730  } else if (copyno1[3] < 8) {
731  //UserNtuples->fillg587(dy,1.);
732  } else if (copyno1[3] < 9) {
733  //UserNtuples->fillg588(dy,1.);
734  } else if (copyno1[3] < 10) {
735  //UserNtuples->fillg589(dy,1.);
736  }
737  } else if (copyno1[2] < 4) {
738  //UserNtuples->fillg566(dy,1.);
739  } else if (copyno1[2] < 5) {
740  //UserNtuples->fillg568(dy,1.);
741  }
742  }
743  }
744  }
745  // end of prenames SIDETL // SIDETR
746  }
747  // end of trackstatus != 2
748 
749  // deposition of energy on steps along primary track
750  //UserNtuples->fillg500(EnerDeposit,1.);
751  // collect sum deposited energy on all steps along primary track
752  sumEnerDeposit += EnerDeposit;
753  // position of step for primary track:
754  //UserNtuples->fillg501(preposition.x(),1.);
755  //UserNtuples->fillg502(preposition.y(),1.);
756  //UserNtuples->fillg503(preposition.z(),1.);
757  //UserNtuples->fillg504(preposition.x(),EnerDeposit);
758  //UserNtuples->fillg505(preposition.y(),EnerDeposit);
759  //UserNtuples->fillg506(preposition.z(),EnerDeposit);
760  // 2D step coordinates weighted by energy deposited on step
761  // //UserNtuples->fillp201(preposition.x(),preposition.y(),EnerDeposit);
762  // //UserNtuples->fillp202(preposition.x(),preposition.z(),EnerDeposit);
763  // //UserNtuples->fillp203(preposition.y(),preposition.z(),EnerDeposit);
764  //UserNtuples->filld204(preposition.x(),preposition.y(),EnerDeposit);
765  //UserNtuples->filld205(preposition.x(),preposition.z(),EnerDeposit);
766  //UserNtuples->filld206(preposition.y(),preposition.z(),EnerDeposit);
767  //UserNtuples->filld223(preposition.y(),preposition.z(),EnerDeposit);
768  // last step of primary track
769  if (trackstatus == 2) {
770  // primary track length
771  // //UserNtuples->fillg508(tracklength,1.);
772  tracklength0 = tracklength;
773  // how many steps primary track consist
774  //UserNtuples->fillg509(curstepnumber,1.);
775  // tot. energy of primary track at the end of trajectory(before disappeare)
776  //UserNtuples->fillg510((entot0-entot),1.);
777  //UserNtuples->fillg520((entot0-entot),1.);
778  }
779  }
780  // end of primary track !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
781 
782  if (parentID == 1 && curstepnumber == 1) {
783  // particles deposit their energy along primary track
784  numofpart += 1;
785  // energy of radiated particle
786  //UserNtuples->fillg511(entot,1.);
787  // coordinates of radiated particle
788  //UserNtuples->fillg512(vert_pos.x(),1.);
789  //UserNtuples->fillg513(vert_pos.y(),1.);
790  //UserNtuples->fillg514(vert_pos.z(),1.);
791  //UserNtuples->fillg515(vert_pos.x(),entot);
792  //UserNtuples->fillg516(vert_pos.y(),entot);
793  //UserNtuples->fillg517(vert_pos.z(),entot);
794 
795  //UserNtuples->filld214(vert_pos.x(),vert_pos.y(),1.);
796  //UserNtuples->filld215(vert_pos.x(),vert_pos.z(),1.);
797  //UserNtuples->filld216(vert_pos.y(),vert_pos.z(),1.);
798  //UserNtuples->filld219(vert_pos.y(),vert_pos.z(),1.);
799  //UserNtuples->filld224(vert_pos.y(),vert_pos.z(),1.);
800  if (prename == "SBST") {
801  //UserNtuples->filld225(vert_pos.y(),vert_pos.z(),1.);
802  }
803  if (prename == "SBSTs") {
804  //UserNtuples->filld226(vert_pos.y(),vert_pos.z(),1.);
805  }
806  }
807 
808  // ==========================================================================
809 }
810 // ==========================================================================
811 // ==========================================================================
812 int FP420Test::detLevels(const G4VTouchable* touch) const {
813  //Return number of levels
814  if (touch)
815  return ((touch->GetHistoryDepth()) + 1);
816  else
817  return 0;
818 }
819 // ==========================================================================
820 
821 G4String FP420Test::detName(const G4VTouchable* touch, int level, int currentlevel) const {
822  //Go down to current level
823  if (level > 0 && level >= currentlevel) {
824  int ii = level - currentlevel;
825  return touch->GetVolume(ii)->GetName();
826  } else {
827  return "NotFound";
828  }
829 }
830 
831 void FP420Test::detectorLevel(const G4VTouchable* touch, int& level, int* copyno, G4String* name) const {
832  //Get name and copy numbers
833  if (level > 0) {
834  for (int ii = 0; ii < level; ii++) {
835  int i = level - ii - 1;
836  G4VPhysicalVolume* pv = touch->GetVolume(i);
837  if (pv != nullptr)
838  name[ii] = pv->GetName();
839  else
840  name[ii] = "Unknown";
841  copyno[ii] = touch->GetReplicaNumber(i);
842  }
843  }
844 }
845 // ==========================================================================
846 
847 //=================================================================== End Of Event
848 void FP420Test::update(const EndOfEvent* evt) {
849  // ==========================================================================
850 
851  if (verbosity > 1) {
852  iev = (*evt)()->GetEventID();
853  edm::LogVerbatim("FP420Test") << "FP420Test:update EndOfEvent = " << iev;
854  }
855  // Fill-in ntuple
857 
858  //
859  int trackID = 0;
860  G4PrimaryParticle* thePrim = nullptr;
861 
862  // prim.vertex:
863  G4int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
864  if (nvertex != 1)
865  edm::LogVerbatim("FP420Test") << "FP420Test: My warning: NumberOfPrimaryVertex != 1 --> = " << nvertex;
866 
867  for (int i = 0; i < nvertex; i++) {
868  G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(i);
869  if (avertex == nullptr) {
870  edm::LogVerbatim("FP420Test") << "FP420Test End Of Event ERR: pointer to vertex = 0";
871  continue;
872  }
873  G4int npart = avertex->GetNumberOfParticle();
874  if (npart != 1)
875  edm::LogVerbatim("FP420Test") << "FP420Test: My warning: NumberOfPrimaryPart != 1 --> = " << npart;
876  if (npart == 0)
877  edm::LogVerbatim("FP420Test") << "FP420Test End Of Event ERR: no NumberOfParticle";
878 
879  // find just primary track: track pointer: thePrim
880  if (thePrim == nullptr)
881  thePrim = avertex->GetPrimary(trackID);
882 
883  if (thePrim != nullptr) {
884  // primary vertex:
885  G4double vx = 0., vy = 0., vz = 0.;
886  vx = avertex->GetX0();
887  vy = avertex->GetY0();
888  vz = avertex->GetZ0();
889  //UserNtuples->fillh01(vx);
890  //UserNtuples->fillh02(vy);
891  //UserNtuples->fillh03(vz);
892  theHistManager->getHisto("VtxX")->Fill(vx);
893  theHistManager->getHisto("VtxY")->Fill(vy);
894  theHistManager->getHisto("VtxZ")->Fill(vz);
895  }
896  }
897  // prim.vertex loop end
898 
899  //=========================== thePrim != 0 ================================================================================
900  if (thePrim != nullptr) {
901  // inline G4ParticleDefinition * GetG4code() const
902  // inline G4PrimaryParticle * GetNext() const
903  // inline G4PrimaryParticle * GetDaughter() const
904 
905  // prim.vertex
906  //int ivert = 0 ;
907  //G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(ivert);
908  //G4double vx=0.,vy=0.,vz=0.;
909  //vx = avertex->GetX0();
910  //vy = avertex->GetY0();
911  //vz = avertex->GetZ0();
912 
913  //
914  // number of secondary particles deposited their energy along primary track
915  //UserNtuples->fillg518(numofpart,1.);
916  if (lastpo.z() < z4 && lastpo.perp() < 100.) {
917  //UserNtuples->fillg536(numofpart,1.);
918  }
919  //
920 
921  // direction !!!
922  G4ThreeVector mom = thePrim->GetMomentum();
923 
924  double phi = atan2(mom.y(), mom.x());
925  if (phi < 0.)
926  phi += twopi;
927  double phigrad = phi * 180. / pi;
928 
929  double th = mom.theta();
930  double eta = -log(tan(th / 2));
931  // works OK:
932  // double costheta =mom.z()/sqrt(mom.x()*mom.x()+mom.y()*mom.y()+mom.z()*mom.z());
933  // double theta = acos(min(max(costheta,double(-1.)),double(1.)));
934 
935  //UserNtuples->fillh04(eta);
936  //UserNtuples->fillh05(phigrad);
937  //UserNtuples->fillh06(th);
938 
939  //UserNtuples->fillg13(lastpo.x(),1.);
940  //UserNtuples->fillg14(lastpo.y(),1.);
941  //UserNtuples->fillg15(lastpo.z(),1.);
942 
943  theHistManager->getHisto("PrimaryEta")->Fill(eta);
944  theHistManager->getHisto("PrimaryPhigrad")->Fill(phigrad);
945  theHistManager->getHisto("PrimaryTh")->Fill(th * 180. / pi);
946 
947  theHistManager->getHisto("PrimaryLastpoZ")->Fill(lastpo.z());
948  if (lastpo.z() < z4) {
949  theHistManager->getHisto("PrimaryLastpoX")->Fill(lastpo.x());
950  theHistManager->getHisto("PrimaryLastpoY")->Fill(lastpo.y());
951  }
952  if (numofpart > 4) {
953  theHistManager->getHisto("XLastpoNumofpart")->Fill(lastpo.x());
954  theHistManager->getHisto("YLastpoNumofpart")->Fill(lastpo.y());
955  }
956 
957  // ==========================================================================
958 
959  // hit map for FP420
960  // ==================================
961 
962  std::map<int, float, std::less<int> > themap;
963  std::map<int, float, std::less<int> > themap1;
964 
965  std::map<int, float, std::less<int> > themapxy;
966  std::map<int, float, std::less<int> > themapz;
967  // access to the G4 hit collections: -----> this work OK:
968 
969  // edm::LogInfo("FP420Test") << "1";
970  G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
971  // edm::LogInfo("FP420Test") << "2";
972  if (verbosity > 0) {
973  edm::LogVerbatim("FP420Test") << "FP420Test: accessed all HC";
974  ;
975  }
976  int CAFIid = G4SDManager::GetSDMpointer()->GetCollectionID("FP420SI");
977  // edm::LogInfo("FP420Test") << "3";
978  // edm::LogVerbatim("FP420Test") << " CAFIid = " << CAFIid;;
979 
980  FP420G4HitCollection* theCAFI = (FP420G4HitCollection*)allHC->GetHC(CAFIid);
981  // CaloG4HitCollection* theCAFI = (CaloG4HitCollection*) allHC->GetHC(CAFIid);
982  if (verbosity > 0) {
983  //edm::LogVerbatim("FP420Test") << "FP420Test: theCAFI = " << theCAFI;
984  edm::LogVerbatim("FP420Test") << "FP420Test: theCAFI->entries = " << theCAFI->entries();
985  }
986  // edm::LogInfo("FP420Test") << "theCAFI->entries="<< theCAFI->entries();
987  theHistManager->getHisto("NumberOfHits")->Fill(theCAFI->entries());
988 
989  // access to the G4 hit collections ----> variant 2: give 0 hits
990  // FP420G4HitCollection * theCAFI;
991  // theCAFI = new FP420G4HitCollection();
992  // ==========================================================================
993  // Silicon Hit collection start
994  //0) if particle goes into flat beam pipe below detector:
995  int varia; // = 0 -all; =1 - MI; =2 - noMI
996  // Select MI or noMI over all 3 stations
997  // 1)MI:
998  // if particle goes through window into detector:
999  // lastpoint of track in lateral dir. outside the detector and inside in z
1000  // lastpoint of track in lateral dir. outside the detector and inside in z
1001  // for all except zzzmarta.xml
1002  // if( lastpo.z()<z4 || abs(lastpo.x())> 5. || lastpo.y()< 10.2 || lastpo.y()>30.2 ) {
1003  // for zzzmarta.xml
1004  // if( lastpo.z()<z4 || abs(lastpo.x())> 10. || lastpo.y()< 3.2 || lastpo.y()>43.2 ) {
1005  if (lastpo.z() < z4) {
1006  // if( lastpo.z()<z4 && lastpo.perp()< 100. ) {
1007  // if(lastpo.z()<z4 || lastpo.perp()> 45.) {
1008  //UserNtuples->fillg66(theCAFI->entries(),1.);
1009  varia = 1;
1010  } else {
1011  // 2) no MI start in detector:
1012  //UserNtuples->fillg31(numofpart,1.);
1013  //UserNtuples->fillg67(theCAFI->entries(),1.);
1014  varia = 2;
1015  } // no MI end:
1016  int nhits = theCAFI->entries();
1017  for (int j = 0; j < nhits; j++) {
1018  FP420G4Hit* aHit = (*theCAFI)[j];
1019  G4ThreeVector hitPoint = aHit->getEntry();
1020  double zz = hitPoint.z();
1021  theHistManager->getHisto("zHits")->Fill(zz);
1022  if (tracklength0 > 8300.)
1023  theHistManager->getHisto("zHitsTrLoLe")->Fill(zz);
1024  }
1025  // varia = 0;
1026  // if( varia == 0) {
1027  if (varia == 2) {
1028  // .............
1029  // number of hits < 50
1030  // if(theCAFI->entries() <50) {
1031  // if(theCAFI->entries() > 0) {
1032  // if(theCAFI->entries() > -1) {
1033  // .............
1034  //int nhit11 = 0, nhit12 = 0, nhit13 = 0;
1035  double totallosenergy = 0.;
1036  for (int j = 0; j < nhits; j++) {
1037  FP420G4Hit* aHit = (*theCAFI)[j];
1038 
1039  G4ThreeVector hitEntryLocalPoint = aHit->getEntryLocalP();
1040  G4ThreeVector hitExitLocalPoint = aHit->getExitLocalP();
1041  G4ThreeVector hitPoint = aHit->getEntry();
1042  // double elmenergy = aHit->getEM();
1043  // double hadrenergy = aHit->getHadr();
1044  // double incidentEnergyHit = aHit->getIncidentEnergy();
1045  int trackIDhit = aHit->getTrackID();
1046  unsigned int unitID = aHit->getUnitID();
1047  // double timeslice = aHit->getTimeSlice();
1048  // int timesliceID = aHit->getTimeSliceID();
1049  // double depenergy = aHit->getEnergyDeposit();
1050  // float pabs = aHit->getPabs();
1051  // float tof = aHit->getTof();
1052  double losenergy = aHit->getEnergyLoss();
1053  // int particletype = aHit->getParticleType();
1054  // float thetaEntry = aHit->getThetaAtEntry();
1055  // float phiEntry = aHit->getPhiAtEntry();
1056  // float xEntry = aHit->getX();
1057  // float yEntry = aHit->getY();
1058  // float zEntry = aHit->getZ();
1059  // int parentID = aHit->getParentId();
1060  // float vxget = aHit->getVx();
1061  // float vyget = aHit->getVy();
1062  // float vzget = aHit->getVz();
1063 
1064  // double th_hit = hitPoint.theta();
1065  // double eta_hit = -log(tan(th_hit/2));
1066  // double phi_hit = hitPoint.phi();
1067  // if (phi_hit < 0.) phi_hit += twopi;
1068  // double phigrad_hit = phi_hit*180./pi;
1069  //UserNtuples->fillg60(eta_hit,losenergy);
1070  //UserNtuples->fillg61(eta_hit,1.);
1071  //UserNtuples->fillg62(phigrad_hit,losenergy);
1072  //UserNtuples->fillg63(phigrad_hit,1.);
1073 
1074  // double xx = hitPoint.x();
1075  // double yy = hitPoint.y();
1076  double zz = hitPoint.z();
1077 
1078  theHistManager->getHisto("zHitsnoMI")->Fill(zz);
1079 
1080  if (verbosity > 2) {
1081  edm::LogVerbatim("FP420Test") << "FP420Test:zHits = " << zz;
1082  }
1083  // double rr = hitPoint.perp();
1084  /*
1085  if(aHit->getTrackID() == 1) {
1086  emu += aHit->getEnergyDeposit();} else {
1087  erest += aHit->getEnergyDeposit();}
1088  */
1089 
1090  //collect lost in Si en.of hits in every plane and put it into themap[]
1091  //UserNtuples->fillg30(losenergy,1.);
1092  themap[unitID] += losenergy;
1093  totallosenergy += losenergy;
1094 
1095  int det, zside, sector, zmodule;
1096  // CaloNumberingPacker::unpackCastorIndex(unitID, det, zside, sector, zmodule);
1097  FP420NumberingScheme::unpackFP420Index(unitID, det, zside, sector, zmodule);
1098  int justlayer = FP420NumberingScheme::unpackLayerIndex(rn00, zside); // 1,2
1099  if (justlayer < 1 || justlayer > 2) {
1100  edm::LogVerbatim("FP420Test") << "FP420Test:WRONG justlayer= " << justlayer;
1101  }
1102  // zside=1,2 ; zmodule=1,10 ; sector=1,3
1103  //UserNtuples->fillg44(float(sector),1.);
1104  //UserNtuples->fillg45(float(zmodule),1.);
1105  //UserNtuples->fillg46(float(zside),1.);
1106  // int sScale = 20;
1107  // intindex is a continues numbering of FP420
1108  //int zScale = 2; unsigned int intindex = sScale*(sector - 1)+zScale*(zmodule - 1)+zside; //intindex=1-30:X,Y,X,Y,X,Y...
1109  // int zScale = 10; unsigned int intindex = sScale*(sector - 1)+zScale*(zside - 1)+zmodule; //intindex=1-30:XXXXXXXXXX,YYYYYYYYYY,...
1110  //UserNtuples->fillg40(float(intindex),1.);
1111  //UserNtuples->fillg48(float(intindex),losenergy);
1112  //
1113  //=======================================
1114  // G4ThreeVector middle = (hitExitLocalPoint+hitEntryLocalPoint)/2.;
1115  G4ThreeVector middle = (hitExitLocalPoint - hitEntryLocalPoint) / 2.;
1116  themapz[unitID] = hitPoint.z() + fabs(middle.z());
1117  if (verbosity > 2) {
1118  edm::LogVerbatim("FP420Test") << "1111111111111111111111111111111111111111111111111111111111111111111111111 ";
1119  edm::LogVerbatim("FP420Test") << "FP420Test: det, zside, sector, zmodule = " << det << zside << sector
1120  << zmodule;
1121  edm::LogVerbatim("FP420Test") << "FP420Test: justlayer = " << justlayer;
1122  edm::LogVerbatim("FP420Test") << "FP420Test: hitExitLocalPoint = " << hitExitLocalPoint;
1123  edm::LogVerbatim("FP420Test") << "FP420Test: hitEntryLocalPoint = " << hitEntryLocalPoint;
1124  edm::LogVerbatim("FP420Test") << "FP420Test: middle= " << middle;
1125  edm::LogVerbatim("FP420Test") << "FP420Test: hitPoint.z()-419000.= " << hitPoint.z() - 419000.;
1126 
1127  edm::LogVerbatim("FP420Test") << "FP420Test:zHits-419000. = " << themapz[unitID] - 419000.;
1128  }
1129  //=======================================
1130  // Y
1131  if (zside == 1) {
1132  //UserNtuples->fillg24(losenergy,1.);
1133  if (losenergy > 0.00003) {
1134  themap1[unitID] += 1.;
1135  }
1136  }
1137  //X
1138  if (zside == 2) {
1139  //UserNtuples->fillg25(losenergy,1.);
1140  if (losenergy > 0.00005) {
1141  themap1[unitID] += 1.;
1142  }
1143  }
1144  // }
1145  //
1146  /*
1147  if (sector == 1) {
1148  nhit11 += 1;
1149  //UserNtuples->fillg33(rr,1.);
1150  //UserNtuples->fillg11(yy,1.);
1151  }
1152  if (sector == 2) {
1153  nhit12 += 1;
1154  //UserNtuples->fillg34(rr,1.);
1155  //UserNtuples->fillg86(yy,1.);
1156  }
1157  if (sector == 3) {
1158  nhit13 += 1;
1159  //UserNtuples->fillg35(rr,1.);
1160  //UserNtuples->fillg87(yy,1.);
1161  }
1162  */
1163  //UserNtuples->fillg10(xx,1.);
1164  //UserNtuples->fillg12(zz,1.);
1165  //UserNtuples->fillg32(rr,1.);
1166 
1167  // =========
1168  // double xPrimAtZhit = vx + (zz-vz)*tan(th)*cos(phi);
1169  // double yPrimAtZhit = vy + (zz-vz)*tan(th)*sin(phi);
1170 
1171  // double dx = xPrimAtZhit - xx;
1172  // double dy = yPrimAtZhit - yy;
1173 
1174  // Select SD hits
1175  // if(rr<120.) {
1176  // Select MI or noMI over all 3 stations
1177  if (lastpo.z() < z4 && lastpo.perp() < 120.) {
1178  // MIonly:
1179  //UserNtuples->fillg16(lastpo.z(),1.);
1180  //UserNtuples->fillg18(zz,1.);
1181  // Station I
1182  if (zz < z2) {
1183  //UserNtuples->fillg54(dx,1.);
1184  //UserNtuples->fillg55(dy,1.);
1185  }
1186  // Station II
1187  if (zz < z3 && zz > z2) {
1188  //UserNtuples->fillg50(dx,1.);
1189  //UserNtuples->fillg51(dy,1.);
1190  }
1191  // Station III
1192  if (zz < z4 && zz > z3) {
1193  //UserNtuples->fillg64(dx,1.);
1194  //UserNtuples->fillg65(dy,1.);
1195  //UserNtuples->filld209(xx,yy,1.);
1196  }
1197  } else {
1198  // no MIonly:
1199  //UserNtuples->fillg17(lastpo.z(),1.);
1200  //UserNtuples->fillg19(zz,1.);
1201  //UserNtuples->fillg74(incidentEnergyHit,1.);
1202  //UserNtuples->fillg75(float(trackIDhit),1.);
1203  // Station I
1204  if (zz < z2) {
1205  //UserNtuples->fillg56(dx,1.);
1206  //UserNtuples->fillg57(dy,1.);
1207  //UserNtuples->fillg20(numofpart,1.);
1208  //UserNtuples->fillg21(sumEnerDeposit,1.);
1209  if (zside == 1) {
1210  //UserNtuples->fillg26(losenergy,1.);
1211  }
1212  if (zside == 2) {
1213  //UserNtuples->fillg76(losenergy,1.);
1214  }
1215  if (trackIDhit == 1) {
1216  //UserNtuples->fillg70(dx,1.);
1217  //UserNtuples->fillg71(incidentEnergyHit,1.);
1218  //UserNtuples->fillg79(losenergy,1.);
1219  } else {
1220  //UserNtuples->fillg82(dx,1.);
1221  }
1222  }
1223  // Station II
1224  if (zz < z3 && zz > z2) {
1225  //UserNtuples->fillg52(dx,1.);
1226  //UserNtuples->fillg53(dy,1.);
1227  //UserNtuples->fillg22(numofpart,1.);
1228  //UserNtuples->fillg23(sumEnerDeposit,1.);
1229  //UserNtuples->fillg80(incidentEnergyHit,1.);
1230  //UserNtuples->fillg81(float(trackIDhit),1.);
1231  if (zside == 1) {
1232  //UserNtuples->fillg27(losenergy,1.);
1233  }
1234  if (zside == 2) {
1235  //UserNtuples->fillg77(losenergy,1.);
1236  }
1237  if (trackIDhit == 1) {
1238  //UserNtuples->fillg72(dx,1.);
1239  //UserNtuples->fillg73(incidentEnergyHit,1.);
1240  } else {
1241  //UserNtuples->fillg83(dx,1.);
1242  }
1243  }
1244  // Station III
1245  if (zz < z4 && zz > z3) {
1246  //UserNtuples->fillg68(dx,1.);
1247  //UserNtuples->fillg69(dy,1.);
1248  //UserNtuples->filld210(xx,yy,1.);
1249  //UserNtuples->fillg22(numofpart,1.);
1250  //UserNtuples->fillg23(sumEnerDeposit,1.);
1251  if (zside == 1) {
1252  //UserNtuples->fillg28(losenergy,1.);
1253  }
1254  if (zside == 2) {
1255  //UserNtuples->fillg78(losenergy,1.);
1256  }
1257  }
1258  } // MIonly or noMIonly ENDED
1259  // }
1260 
1261  // !!!!!!!!!!!!!
1262 
1263  } // for loop on all hits ENDED ENDED ENDED !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1264 
1265  // !!!!!!!!!!!!!
1266 
1267  //======================================================================================================SUMHIT
1268  //UserNtuples->fillg29(totallosenergy,1.);
1269  //UserNtuples->fillg36(nhit11,1.);
1270  //UserNtuples->fillg37(nhit12,1.);
1271  //UserNtuples->fillg38(nhit13,1.);
1272  //======================================================================================================SUMHIT
1273  // int rn00=3;//test only with 2 sensors in superlayer, not 4
1274  // int rn00=rn0;//always
1275  if (verbosity > 2) {
1276  edm::LogVerbatim("FP420Test") << "22222222222222222222222222222222222222222222222222222222222222222222222222 ";
1277  }
1278  int det = 1;
1279  int allplacesforsensors = 7;
1280  for (int sector = 1; sector < sn0; sector++) {
1281  for (int zmodule = 1; zmodule < pn0; zmodule++) {
1282  for (int zsideinorder = 1; zsideinorder < allplacesforsensors; zsideinorder++) {
1283  int zside = FP420NumberingScheme::realzside(rn00, zsideinorder); //1,3,5,2,4,6
1284  if (verbosity > 2) {
1285  edm::LogVerbatim("FP420Test") << "FP420Test: sector= " << sector << " zmodule= " << zmodule
1286  << " zsideinorder= " << zsideinorder << " zside= " << zside;
1287  }
1288  if (zside != 0) {
1289  int justlayer = FP420NumberingScheme::unpackLayerIndex(rn00, zside); // 1,2
1290  if (justlayer < 1 || justlayer > 2) {
1291  edm::LogVerbatim("FP420Test") << "FP420Test:WRONG justlayer= " << justlayer;
1292  }
1293  int copyinlayer = FP420NumberingScheme::unpackCopyIndex(rn00, zside); // 1,2,3
1294  if (copyinlayer < 1 || copyinlayer > 3) {
1295  edm::LogVerbatim("FP420Test") << "FP420Test:WRONG copyinlayer= " << copyinlayer;
1296  }
1297  int orientation = FP420NumberingScheme::unpackOrientation(rn00, zside); // Front: = 1; Back: = 2
1298  if (orientation < 1 || orientation > 2) {
1299  edm::LogVerbatim("FP420Test") << "FP420Test:WRONG orientation= " << orientation;
1300  }
1301 
1302  // iu is a continues numbering of planes(!) over two arm FP420 set up
1303  int detfixed =
1304  1; // use this treatment for each set up arm, hence no sense to do it defferently for +FP420 and -FP420;
1305  // and ...[ii] massives have prepared in such a way
1306  unsigned int ii =
1307  FP420NumberingScheme::packMYIndex(rn00, pn0, sn0, detfixed, justlayer, sector, zmodule) - 1;
1308  // ii = 0-19 --> 20 items
1309  if (verbosity > 2) {
1310  edm::LogVerbatim("FP420Test")
1311  << "FP420Test: justlayer = " << justlayer << " copyinlayer = " << copyinlayer
1312  << " orientation = " << orientation << " ii= " << ii;
1313  }
1314  double zdiststat = 0.;
1315  if (sn0 < 4) {
1316  if (sector == 2)
1317  zdiststat = zD3;
1318  } else {
1319  if (sector == 2)
1320  zdiststat = zD2;
1321  if (sector == 3)
1322  zdiststat = zD3;
1323  }
1324  double kplane = -(pn0 - 1) / 2 - 0.5 + (zmodule - 1); //-3.5 +0...5 = -3.5,-2.5,-1.5,+2.5,+1.5
1325  double zcurrent = zinibeg + z420 + (zSiStep - zSiPlane) / 2 + kplane * zSiStep + zdiststat;
1326  //double zcurrent = zinibeg +(zSiStep-zSiPlane)/2 + kplane*zSiStep + (sector-1)*zUnit;
1327  if (verbosity > 2) {
1328  edm::LogVerbatim("FP420Test") << "FP420Test: Leftzcurrent-419000. = " << zcurrent - 419000.;
1329  edm::LogVerbatim("FP420Test") << "FP420Test: zGapLDet = " << zGapLDet;
1330  }
1331  if (justlayer == 1) {
1332  if (orientation == 1)
1333  zcurrent += (zGapLDet + zSiDet / 2);
1334  if (orientation == 2)
1335  zcurrent += zBlade - (zGapLDet + zSiDet / 2);
1336  }
1337  if (justlayer == 2) {
1338  if (orientation == 1)
1339  zcurrent += (zGapLDet + zSiDet / 2) + zBlade + gapBlade;
1340  if (orientation == 2)
1341  zcurrent += 2 * zBlade + gapBlade - (zGapLDet + zSiDet / 2);
1342  }
1343  // .
1344  //
1345  if (det == 2)
1346  zcurrent = -zcurrent;
1347  //
1348  if (verbosity > 2) {
1349  edm::LogVerbatim("FP420Test") << "FP420Test: zcurrent-419000. = " << zcurrent - 419000.;
1350  }
1351  //================================== end of for loops in continuius number iu:
1352  } //if(zside!=0
1353  } // for superlayer
1354  } // for zmodule
1355  } // for sector
1356 
1357  if (verbosity > 2) {
1358  edm::LogVerbatim("FP420Test")
1359  << "----------------------------------------------------------------------------- ";
1360  }
1361 
1362  //======================================================================================================CHECK
1363  if (totallosenergy == 0.0) {
1364  edm::LogVerbatim("FP420Test") << "FP420Test: number of hits = " << theCAFI->entries();
1365  for (int j = 0; j < nhits; j++) {
1366  FP420G4Hit* aHit = (*theCAFI)[j];
1367  double losenergy = aHit->getEnergyLoss();
1368  edm::LogVerbatim("FP420Test") << " j hits = " << j << "losenergy = " << losenergy;
1369  }
1370  }
1371  //======================================================================================================CHECK
1372 
1373  //====================================================================================================== HIT START
1374 
1375  // FIBRE Hit collected analysis
1376  /*
1377  double totalEnergy = 0.;
1378  int nhitsX = 0, nhitsY = 0, nsumhit = 0;
1379  for (int sector = 1; sector < 4; sector++) {
1380  int nhitsecX = 0, nhitsecY = 0;
1381  for (int zmodule = 1; zmodule < 11; zmodule++) {
1382  for (int zside = 1; zside < 3; zside++) {
1383  int det = 1;
1384  // int nhit = 0;
1385  // int sScale = 20;
1386  int index = FP420NumberingScheme::packFP420Index(det, zside, sector, zmodule);
1387  double theTotalEnergy = themap[index];
1388  // X planes
1389  if (zside < 2) {
1390  //UserNtuples->fillg47(theTotalEnergy,1.);
1391  if (theTotalEnergy > 0.00003) {
1392  nhitsX += 1;
1393  // nhitsecX += themap1[index];
1394  // nhit=1;
1395  }
1396  }
1397  // Y planes
1398  else {
1399  //UserNtuples->fillg49(theTotalEnergy,1.);
1400  if (theTotalEnergy > 0.00005) {
1401  nhitsY += 1;
1402  // nhitsecY += themap1[index];
1403  // nhit=1;
1404  }
1405  }
1406  // intindex is a continues numbering of FP420
1407  // int zScale=2; unsigned int intindex = sScale*(sector - 1)+zScale*(zmodule - 1)+zside;
1408  // int zScale=10; unsigned int intindex = sScale*(sector - 1)+zScale*(zside - 1)+zmodule;
1409  //UserNtuples->fillg41(float(intindex),theTotalEnergy);
1410  //UserNtuples->fillg42(float(intindex),1.);
1411  //UserNtuples->fillp208(float(intindex),float(nhit),1.);
1412  //UserNtuples->fillp211(float(intindex),float(themap1[index]),1.);
1413  totalEnergy += themap[index];
1414  } // for
1415  } // for
1416  //UserNtuples->fillg39(nhitsecY,1.);
1417  if (nhitsecX > 10 || nhitsecY > 10) {
1418  nsumhit += 1;
1419  //UserNtuples->fillp213(float(sector),float(1.),1.);
1420  } else { //UserNtuples->fillp213(float(sector),float(0.),1.);
1421  }
1422  } // for
1423  //====================================================================================================== HIT END
1424 
1425  //====================================================================================================== HIT ALL
1426  //UserNtuples->fillg43(totalEnergy,1.);
1427  //UserNtuples->fillg58(nhitsX,1.);
1428  //UserNtuples->fillg59(nhitsY,1.);
1429  // if( nsumhit !=0 ) { //UserNtuples->fillp212(vy,float(1.),1.);
1430  if (nsumhit >= 2) { //UserNtuples->fillp212(vy,float(1.),1.);
1431  } else { //UserNtuples->fillp212(vy,float(0.),1.);
1432  }
1433  */
1434  //====================================================================================================== HIT ALL
1435 
1436  //====================================================================================================== number of hits
1437  // .............
1438  // } // number of hits < 50
1439  // .............
1440  } // MI or no MI or all - end
1441 
1442  } // primary end
1443  //=========================== thePrim != 0 end ===
1444  // ==========================================================================
1445  if (verbosity > 0) {
1446  edm::LogVerbatim("FP420Test") << "FP420Test: END OF Event " << (*evt)()->GetEventID();
1447  }
1448 }
1449 
static int unpackCopyIndex(int rn0, int zside)
void update(const BeginOfJob *run) override
This routine will be called when the appropriate signal arrives.
Definition: FP420Test.cc:410
Log< level::Info, true > LogVerbatim
double z4
Definition: FP420Test.cc:136
#define DEFINE_SIMWATCHER(type)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
G4double sumEnerDeposit
Definition: FP420Test.cc:129
void writeToFile(const TString &fOutputFile, const TString &fRecreateFile)
Definition: FP420Test.cc:306
const char * fTypeTitle
Definition: FP420Test.cc:82
static int realzside(int rn0, int zsideinorder)
static void unpackFP420Index(const unsigned int &idx, int &det, int &zside, int &station, int &superplane)
double zinibeg
Definition: FP420Test.cc:140
double z2
Definition: FP420Test.cc:136
int verbosity
Definition: FP420Test.cc:126
TFile fp420OutputFile
Definition: FP420Test.cc:145
double npart
Definition: HydjetWrapper.h:48
FP420Test(const edm::ParameterSet &p)
Definition: FP420Test.cc:157
int zside(DetId const &)
static int unpackLayerIndex(int rn0, int zside)
std::string fRecreateFile
Definition: FP420Test.cc:151
double zGapLDet
Definition: FP420Test.cc:140
unsigned int getUnitID() const
Definition: FP420G4Hit.cc:125
~FP420Test() override
Definition: FP420Test.cc:225
G4ThreeVector lastpo
Definition: FP420Test.cc:133
const Double_t pi
ntfp420_elements
Definition: FP420Test.cc:155
static unsigned packMYIndex(int rn0, int pn0, int sn0, int det, int zside, int sector, int zmodule)
G4ThreeVector getEntry() const
Definition: FP420G4Hit.cc:104
Fp420AnalysisHistManager * theHistManager
Definition: FP420Test.cc:148
double zD2
Definition: FP420Test.cc:136
std::string fOutputFile
Definition: FP420Test.cc:150
double zBoundDet
Definition: FP420Test.cc:140
unsigned int getTrackID() const
Definition: FP420G4Hit.cc:122
void detectorLevel(const G4VTouchable *, int &, int *, G4String *) const
Definition: FP420Test.cc:831
Fp420AnalysisHistManager(const TString &managername)
Definition: FP420Test.cc:250
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
int whichevent
Definition: FP420Test.cc:146
double zinCalo
Definition: FP420Test.cc:124
G4String detName(const G4VTouchable *, int, int) const
Definition: FP420Test.cc:821
G4ThreeVector getEntryLocalP() const
Definition: FP420G4Hit.cc:107
double zD3
Definition: FP420Test.cc:136
double zSiPlane
Definition: FP420Test.cc:140
double z3
Definition: FP420Test.cc:136
Float_t fp420eventarray[1]
Definition: FP420Test.cc:143
double z1
Definition: FP420Test.cc:136
G4double entot0
Definition: FP420Test.cc:122
G4double sumStepl
Definition: FP420Test.cc:129
TH1F * getHisto(Int_t Number)
Definition: FP420Test.cc:347
ii
Definition: cuy.py:589
double z420
Definition: FP420Test.cc:139
int detLevels(const G4VTouchable *) const
Definition: FP420Test.cc:812
G4THitsCollection< FP420G4Hit > FP420G4HitCollection
int lastTrackID
Definition: FP420Test.cc:125
double zSiStep
Definition: FP420Test.cc:140
int numofpart
Definition: FP420Test.cc:131
void histInit(const char *name, const char *title, Int_t nbinsx, Axis_t xlow, Axis_t xup)
Definition: FP420Test.cc:320
double gapBlade
Definition: FP420Test.cc:141
double rinCalo
Definition: FP420Test.cc:124
TObjArray * fHistArray
Definition: FP420Test.cc:83
G4double sumStepc
Definition: FP420Test.cc:129
TH2F * getHisto2(Int_t Number)
Definition: FP420Test.cc:363
double zSiDet
Definition: FP420Test.cc:139
G4double tracklength0
Definition: FP420Test.cc:122
step
Definition: StallMonitor.cc:83
float getEnergyLoss() const
Definition: FP420G4Hit.cc:141
static int unpackOrientation(int rn0, int zside)
TNtuple * fp420eventntuple
Definition: FP420Test.cc:144
std::string fDataLabel
Definition: FP420Test.cc:149
TObjArray * fHistNamesArray
Definition: FP420Test.cc:84
G4ThreeVector getExitLocalP() const
Definition: FP420G4Hit.cc:110
~Fp420AnalysisHistManager() override
Definition: FP420Test.cc:267
double zBlade
Definition: FP420Test.cc:141
MPlex< T, D1, D2, N > atan2(const MPlex< T, D1, D2, N > &y, const MPlex< T, D1, D2, N > &x)
Definition: Matriplex.h:648