File indexing completed on 2024-09-10 02:59:07
0001
0002 #include <iostream>
0003 #include <map>
0004 #include <string>
0005
0006
0007 #include "FWCore/Framework/interface/Frameworkfwd.h"
0008 #include "FWCore/Framework/interface/MakerMacros.h"
0009 #include "FWCore/Framework/interface/Event.h"
0010 #include "FWCore/Framework/interface/EventSetup.h"
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0013 #include "FWCore/PluginManager/interface/ModuleDef.h"
0014
0015 #include "SimG4Core/Notification/interface/TrackInformation.h"
0016 #include "SimG4Core/Notification/interface/Observer.h"
0017 #include "SimG4Core/Notification/interface/BeginOfJob.h"
0018 #include "SimG4Core/Notification/interface/BeginOfRun.h"
0019 #include "SimG4Core/Notification/interface/EndOfRun.h"
0020 #include "SimG4Core/Notification/interface/BeginOfEvent.h"
0021 #include "SimG4Core/Notification/interface/EndOfEvent.h"
0022 #include "SimG4Core/Notification/interface/BeginOfTrack.h"
0023 #include "SimG4Core/Notification/interface/EndOfTrack.h"
0024 #include "SimG4Core/Watcher/interface/SimWatcher.h"
0025 #include "SimG4Core/Watcher/interface/SimWatcherFactory.h"
0026
0027 #include "SimG4CMS/FP420/interface/FP420NumberingScheme.h"
0028 #include "SimG4CMS/FP420/interface/FP420G4HitCollection.h"
0029
0030 #include "G4HCofThisEvent.hh"
0031 #include "G4ProcessManager.hh"
0032 #include "G4SDManager.hh"
0033 #include "G4Step.hh"
0034 #include "G4Track.hh"
0035 #include "G4TransportationManager.hh"
0036 #include "G4UserEventAction.hh"
0037 #include "G4VProcess.hh"
0038 #include "G4VTouchable.hh"
0039
0040 #include <CLHEP/Random/Randomize.h>
0041 #include <CLHEP/Units/SystemOfUnits.h>
0042 #include <CLHEP/Units/GlobalPhysicalConstants.h>
0043
0044
0045
0046 #include "TROOT.h"
0047 #include "TFile.h"
0048 #include "TH1.h"
0049 #include "TH2.h"
0050 #include "TProfile.h"
0051 #include "TNtuple.h"
0052 #include "TRandom.h"
0053 #include "TLorentzVector.h"
0054 #include "TUnixSystem.h"
0055 #include "TSystem.h"
0056 #include "TMath.h"
0057 #include "TF1.h"
0058 #include "TObjArray.h"
0059 #include "TObjString.h"
0060 #include "TNamed.h"
0061
0062 class Fp420AnalysisHistManager : public TNamed {
0063 public:
0064 Fp420AnalysisHistManager(const TString& managername);
0065 ~Fp420AnalysisHistManager() override;
0066
0067 TH1F* getHisto(Int_t Number);
0068 TH1F* getHisto(const TObjString& histname);
0069
0070 TH2F* getHisto2(Int_t Number);
0071 TH2F* getHisto2(const TObjString& histname);
0072
0073 void writeToFile(const TString& fOutputFile, const TString& fRecreateFile);
0074
0075 private:
0076 void bookHistos();
0077 void storeWeights();
0078 void histInit(const char* name, const char* title, Int_t nbinsx, Axis_t xlow, Axis_t xup);
0079 void histInit(
0080 const char* name, const char* title, Int_t nbinsx, Axis_t xlow, Axis_t xup, Int_t nbinsy, Axis_t ylow, Axis_t yup);
0081
0082 const char* fTypeTitle;
0083 TObjArray* fHistArray;
0084 TObjArray* fHistNamesArray;
0085 };
0086
0087 class FP420Test : public SimWatcher,
0088 public Observer<const BeginOfJob*>,
0089 public Observer<const BeginOfRun*>,
0090 public Observer<const EndOfRun*>,
0091 public Observer<const BeginOfEvent*>,
0092 public Observer<const BeginOfTrack*>,
0093 public Observer<const G4Step*>,
0094 public Observer<const EndOfTrack*>,
0095 public Observer<const EndOfEvent*> {
0096 public:
0097 FP420Test(const edm::ParameterSet& p);
0098 ~FP420Test() override;
0099
0100 private:
0101
0102 void update(const BeginOfJob* run) override;
0103 void update(const BeginOfRun* run) override;
0104 void update(const EndOfRun* run) override;
0105 void update(const BeginOfEvent* evt) override;
0106 void update(const BeginOfTrack* trk) override;
0107 void update(const G4Step* step) override;
0108 void update(const EndOfTrack* trk) override;
0109 void update(const EndOfEvent* evt) override;
0110
0111 private:
0112
0113
0114 int detLevels(const G4VTouchable*) const;
0115 G4String detName(const G4VTouchable*, int, int) const;
0116 void detectorLevel(const G4VTouchable*, int&, int*, G4String*) const;
0117
0118
0119
0120 int iev;
0121 int itrk;
0122 G4double entot0, tracklength0;
0123
0124 double rinCalo, zinCalo;
0125 int lastTrackID;
0126 int verbosity;
0127
0128
0129 G4double sumEnerDeposit, sumStepl, sumStepc;
0130
0131 int numofpart;
0132
0133 G4ThreeVector lastpo;
0134
0135
0136 double z1, z2, z3, z4, zD2, zD3;
0137 int sn0, dn0, pn0, rn0;
0138 int rn00;
0139 double zSiDet, z420;
0140 double zGapLDet, zBoundDet, zSiStep, zSiPlane, zinibeg;
0141 double zBlade, gapBlade;
0142
0143 Float_t fp420eventarray[1];
0144 TNtuple* fp420eventntuple;
0145 TFile fp420OutputFile;
0146 int whichevent;
0147
0148 Fp420AnalysisHistManager* theHistManager;
0149 std::string fDataLabel;
0150 std::string fOutputFile;
0151 std::string fRecreateFile;
0152 };
0153
0154
0155 enum ntfp420_elements { ntfp420_evt };
0156
0157 FP420Test::FP420Test(const edm::ParameterSet& p) {
0158
0159 edm::ParameterSet m_Anal = p.getParameter<edm::ParameterSet>("FP420Test");
0160 verbosity = m_Anal.getParameter<int>("Verbosity");
0161
0162
0163 fDataLabel = m_Anal.getParameter<std::string>("FDataLabel");
0164 fOutputFile = m_Anal.getParameter<std::string>("FOutputFile");
0165 fRecreateFile = m_Anal.getParameter<std::string>("FRecreateFile");
0166
0167 if (verbosity > 0) {
0168 edm::LogVerbatim("FP420Test") << "============================================================================";
0169 edm::LogVerbatim("FP420Test") << "FP420Testconstructor :: Initialized as observer";
0170 }
0171
0172
0173 pn0 = 6;
0174 sn0 = 3;
0175 rn00 = 7;
0176
0177 z420 = 420000.0;
0178 zD2 = 4000.0;
0179 zD3 = 8000.0;
0180
0181 zBlade = 5.00;
0182 gapBlade = 1.6;
0183 double gapSupplane = 1.6;
0184 zSiPlane = 2 * zBlade + gapBlade + gapSupplane;
0185
0186 double zKapton = 0.1;
0187 zSiStep = zSiPlane + zKapton;
0188
0189 double zBoundDet = 0.020;
0190 double zSiElectr = 0.250;
0191 double zCeramDet = 0.500;
0192
0193 zSiDet = 0.250;
0194 zGapLDet = zBlade / 2 - (zSiDet + zSiElectr + zBoundDet + zCeramDet / 2);
0195
0196
0197 double zSiStation = (pn0 - 1) * (2 * (zBlade + gapBlade) + zKapton) + 2 * 6. + 0.0;
0198
0199 double eee1 = 11.;
0200 double eee2 = 12.;
0201
0202 zinibeg = (eee1 - eee2) / 2.;
0203
0204 z1 = zinibeg + (zSiStation + 10.) / 2 + z420;
0205 z2 = z1 + zD2;
0206 z3 = z1 + zD3;
0207 z4 = z1 + 2 * zD3;
0208
0209
0210 fp420eventntuple = new TNtuple("NTfp420event", "NTfp420event", "evt");
0211
0212 whichevent = 0;
0213
0214
0215
0216
0217
0218 theHistManager = new Fp420AnalysisHistManager(fDataLabel);
0219
0220 if (verbosity > 0) {
0221 edm::LogVerbatim("FP420Test") << "FP420Test constructor :: Initialized Fp420AnalysisHistManager";
0222 }
0223 }
0224
0225 FP420Test::~FP420Test() {
0226
0227
0228 TFile fp420OutputFile("newntfp420.root", "RECREATE");
0229 edm::LogVerbatim("FP420Test") << "FP420 output root file has been created";
0230 fp420eventntuple->Write();
0231 edm::LogVerbatim("FP420Test") << "FP420 output root file has been written";
0232 fp420OutputFile.Close();
0233 edm::LogVerbatim("FP420Test") << "FP420 output root file has been closed";
0234 delete fp420eventntuple;
0235 edm::LogVerbatim("FP420Test") << "FP420 output root file pointer has been deleted";
0236
0237
0238
0239
0240 theHistManager->writeToFile(fOutputFile, fRecreateFile);
0241 if (verbosity > 0) {
0242 edm::LogVerbatim("FP420Test") << std::endl << "FP420Test Destructor --------> End of FP420Test : ";
0243 }
0244 }
0245
0246
0247
0248
0249
0250 Fp420AnalysisHistManager::Fp420AnalysisHistManager(const TString& managername) {
0251
0252
0253 fTypeTitle = managername;
0254 fHistArray = new TObjArray();
0255 fHistNamesArray = new TObjArray();
0256
0257 TH1::AddDirectory(kFALSE);
0258 bookHistos();
0259
0260 fHistArray->Compress();
0261 fHistNamesArray->Compress();
0262
0263
0264 }
0265
0266
0267 Fp420AnalysisHistManager::~Fp420AnalysisHistManager() {
0268
0269
0270 if (fHistArray) {
0271 fHistArray->Delete();
0272 delete fHistArray;
0273 }
0274
0275 if (fHistNamesArray) {
0276 fHistNamesArray->Delete();
0277 delete fHistNamesArray;
0278 }
0279 }
0280
0281
0282 void Fp420AnalysisHistManager::bookHistos() {
0283
0284 histInit("PrimaryEta", "Primary Eta", 100, 9., 12.);
0285 histInit("PrimaryPhigrad", "Primary Phigrad", 100, 0., 360.);
0286 histInit("PrimaryTh", "Primary Th", 100, 0., 180.);
0287 histInit("PrimaryLastpoZ", "Primary Lastpo Z", 100, -200., 430000.);
0288 histInit("PrimaryLastpoX", "Primary Lastpo X Z<z4", 100, -30., 30.);
0289 histInit("PrimaryLastpoY", "Primary Lastpo Y Z<z4", 100, -30., 30.);
0290 histInit("XLastpoNumofpart", "Primary Lastpo X n>10", 100, -30., 30.);
0291 histInit("YLastpoNumofpart", "Primary Lastpo Y n>10", 100, -30., 30.);
0292 histInit("VtxX", "Vtx X", 100, -50., 50.);
0293 histInit("VtxY", "Vtx Y", 100, -50., 50.);
0294 histInit("VtxZ", "Vtx Z", 100, -200., 430000.);
0295
0296 histInit("SumEDep", "This is sum Energy deposited", 100, -1, 199.);
0297 histInit("TrackL", "This is TrackL", 100, 0., 12000.);
0298 histInit("zHits", "z Hits all events", 100, 400000., 430000.);
0299 histInit("zHitsnoMI", "z Hits no MI", 100, 400000., 430000.);
0300 histInit("zHitsTrLoLe", "z Hits TrLength bigger 8300", 100, 400000., 430000.);
0301 histInit("NumberOfHits", "NumberOfHits", 100, 0., 300.);
0302 }
0303
0304
0305
0306 void Fp420AnalysisHistManager::writeToFile(const TString& fOutputFile, const TString& fRecreateFile) {
0307
0308
0309 edm::LogVerbatim("FP420Test") << "================================================================";
0310 edm::LogVerbatim("FP420Test") << " Write this Analysis to File " << fOutputFile;
0311 edm::LogVerbatim("FP420Test") << "================================================================";
0312
0313 TFile* file = new TFile(fOutputFile, fRecreateFile);
0314
0315 fHistArray->Write();
0316 file->Close();
0317 }
0318
0319
0320 void Fp420AnalysisHistManager::histInit(const char* name, const char* title, Int_t nbinsx, Axis_t xlow, Axis_t xup) {
0321
0322
0323 char* newtitle = new char[strlen(title) + strlen(fTypeTitle) + 5];
0324 strcpy(newtitle, title);
0325 strcat(newtitle, " (");
0326 strcat(newtitle, fTypeTitle);
0327 strcat(newtitle, ") ");
0328 fHistArray->AddLast((new TH1F(name, newtitle, nbinsx, xlow, xup)));
0329 fHistNamesArray->AddLast(new TObjString(name));
0330 }
0331
0332
0333 void Fp420AnalysisHistManager::histInit(
0334 const char* name, const char* title, Int_t nbinsx, Axis_t xlow, Axis_t xup, Int_t nbinsy, Axis_t ylow, Axis_t yup) {
0335
0336
0337 char* newtitle = new char[strlen(title) + strlen(fTypeTitle) + 5];
0338 strcpy(newtitle, title);
0339 strcat(newtitle, " (");
0340 strcat(newtitle, fTypeTitle);
0341 strcat(newtitle, ") ");
0342 fHistArray->AddLast((new TH2F(name, newtitle, nbinsx, xlow, xup, nbinsy, ylow, yup)));
0343 fHistNamesArray->AddLast(new TObjString(name));
0344 }
0345
0346
0347 TH1F* Fp420AnalysisHistManager::getHisto(Int_t Number) {
0348
0349
0350 if (Number <= fHistArray->GetLast() && fHistArray->At(Number) != (TObject*)nullptr) {
0351 return (TH1F*)(fHistArray->At(Number));
0352
0353 } else {
0354 edm::LogVerbatim("FP420Test") << "!!!!!!!!!!!!!!!!!!getHisto!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
0355 edm::LogVerbatim("FP420Test") << " WARNING ERROR - HIST ID INCORRECT (TOO HIGH) - " << Number;
0356 edm::LogVerbatim("FP420Test") << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
0357
0358 return (TH1F*)(fHistArray->At(0));
0359 }
0360 }
0361
0362
0363 TH2F* Fp420AnalysisHistManager::getHisto2(Int_t Number) {
0364
0365
0366 if (Number <= fHistArray->GetLast() && fHistArray->At(Number) != (TObject*)nullptr) {
0367 return (TH2F*)(fHistArray->At(Number));
0368
0369 } else {
0370 edm::LogVerbatim("FP420Test") << "!!!!!!!!!!!!!!!!getHisto2!!!!!!!!!!!!!!!!!!!!!!!!!!!";
0371 edm::LogVerbatim("FP420Test") << " WARNING ERROR - HIST ID INCORRECT (TOO HIGH) - " << Number;
0372 edm::LogVerbatim("FP420Test") << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
0373
0374 return (TH2F*)(fHistArray->At(0));
0375 }
0376 }
0377
0378
0379 TH1F* Fp420AnalysisHistManager::getHisto(const TObjString& histname) {
0380
0381
0382 Int_t index = fHistNamesArray->IndexOf(&histname);
0383 return getHisto(index);
0384 }
0385
0386
0387 TH2F* Fp420AnalysisHistManager::getHisto2(const TObjString& histname) {
0388
0389
0390 Int_t index = fHistNamesArray->IndexOf(&histname);
0391 return getHisto2(index);
0392 }
0393
0394
0395 void Fp420AnalysisHistManager::storeWeights() {
0396
0397
0398 for (int i = 0; i < fHistArray->GetEntries(); i++) {
0399 ((TH1F*)(fHistArray->At(i)))->Sumw2();
0400 }
0401 }
0402
0403
0404
0405
0406
0407
0408
0409
0410 void FP420Test::update(const BeginOfJob* job) {
0411
0412 edm::LogVerbatim("FP420Test") << "FP420Test:beggining of job";
0413 ;
0414 }
0415
0416
0417 void FP420Test::update(const BeginOfRun* run) {
0418
0419
0420 edm::LogVerbatim("FP420Test") << std::endl << "FP420Test:: Begining of Run";
0421 }
0422
0423 void FP420Test::update(const EndOfRun* run) { ; }
0424
0425
0426 void FP420Test::update(const BeginOfEvent* evt) {
0427 iev = (*evt)()->GetEventID();
0428 if (verbosity > 0) {
0429 edm::LogVerbatim("FP420Test") << "FP420Test:update Event number = " << iev;
0430 }
0431 whichevent++;
0432 }
0433
0434
0435 void FP420Test::update(const BeginOfTrack* trk) {
0436 itrk = (*trk)()->GetTrackID();
0437 if (verbosity > 1) {
0438 edm::LogVerbatim("FP420Test") << "FP420Test:update BeginOfTrack number = " << itrk;
0439 }
0440 if (itrk == 1) {
0441 sumEnerDeposit = 0.;
0442 numofpart = 0;
0443 sumStepl = 0.;
0444 sumStepc = 0.;
0445 tracklength0 = 0.;
0446 }
0447 }
0448
0449
0450 void FP420Test::update(const EndOfTrack* trk) {
0451 itrk = (*trk)()->GetTrackID();
0452 if (verbosity > 1) {
0453 edm::LogVerbatim("FP420Test") << "FP420Test:update EndOfTrack number = " << itrk;
0454 }
0455 if (itrk == 1) {
0456 G4double tracklength = (*trk)()->GetTrackLength();
0457
0458 theHistManager->getHisto("SumEDep")->Fill(sumEnerDeposit);
0459 theHistManager->getHisto("TrackL")->Fill(tracklength);
0460
0461
0462 G4ThreeVector vert_mom = (*trk)()->GetVertexMomentumDirection();
0463 G4ThreeVector vert_pos = (*trk)()->GetVertexPosition();
0464
0465
0466
0467
0468
0469
0470
0471
0472
0473
0474
0475
0476
0477
0478
0479
0480
0481
0482
0483
0484
0485
0486
0487
0488
0489
0490
0491
0492 if (tracklength < z4) {
0493
0494
0495
0496
0497 }
0498
0499
0500 const G4Step* aStep = (*trk)()->GetStep();
0501
0502
0503
0504 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
0505 lastpo = preStepPoint->GetPosition();
0506
0507
0508 if (lastpo.z() < z1 && lastpo.perp() < 100.) {
0509
0510
0511
0512
0513 }
0514 if ((lastpo.z() > z1 && lastpo.z() < z2) && lastpo.perp() < 100.) {
0515
0516
0517
0518
0519 }
0520 if (lastpo.z() < z2 && lastpo.perp() < 100.) {
0521
0522
0523
0524
0525
0526
0527
0528 }
0529 if (lastpo.z() < z3 && lastpo.perp() < 100.) {
0530
0531
0532
0533
0534 }
0535 if (lastpo.z() < z4 && lastpo.perp() < 100.) {
0536
0537
0538
0539
0540
0541
0542
0543 }
0544 }
0545 }
0546
0547
0548
0549
0550 void FP420Test::update(const G4Step* aStep) {
0551
0552
0553 if (verbosity > 2) {
0554 G4int stepnumber = aStep->GetTrack()->GetCurrentStepNumber();
0555 edm::LogVerbatim("FP420Test") << "FP420Test:update Step number = " << stepnumber;
0556 }
0557
0558 G4Track* theTrack = aStep->GetTrack();
0559 TrackInformation* trkInfo = dynamic_cast<TrackInformation*>(theTrack->GetUserInformation());
0560 if (trkInfo == nullptr) {
0561 edm::LogVerbatim("FP420Test") << "FP420Test on aStep: No trk info !!!! abort ";
0562 }
0563 G4int id = theTrack->GetTrackID();
0564 G4String particleType = theTrack->GetDefinition()->GetParticleName();
0565 G4int parentID = theTrack->GetParentID();
0566 G4TrackStatus trackstatus = theTrack->GetTrackStatus();
0567 G4double tracklength = theTrack->GetTrackLength();
0568 G4ThreeVector trackmom = theTrack->GetMomentum();
0569 G4double entot = theTrack->GetTotalEnergy();
0570 G4int curstepnumber = theTrack->GetCurrentStepNumber();
0571
0572
0573
0574
0575
0576
0577
0578
0579
0580
0581
0582
0583
0584
0585
0586
0587 G4double stepl = aStep->GetStepLength();
0588 G4double EnerDeposit = aStep->GetTotalEnergyDeposit();
0589
0590
0591
0592
0593
0594
0595
0596 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
0597 const G4ThreeVector& preposition = preStepPoint->GetPosition();
0598 G4ThreeVector prelocalpoint = theTrack->GetTouchable()->GetHistory()->GetTopTransform().TransformPoint(preposition);
0599 G4VPhysicalVolume* currentPV = preStepPoint->GetPhysicalVolume();
0600 const G4String& prename = currentPV->GetName();
0601
0602 const G4VTouchable* pre_touch = preStepPoint->GetTouchable();
0603 int pre_levels = detLevels(pre_touch);
0604
0605 G4String name1[20];
0606 int copyno1[20];
0607 for (int i = 0; i < 20; ++i) {
0608 name1[i] = "";
0609 copyno1[i] = 0;
0610 }
0611 if (pre_levels > 0) {
0612 detectorLevel(pre_touch, pre_levels, copyno1, name1);
0613 }
0614
0615
0616
0617 if (id == 1) {
0618
0619 if (curstepnumber == 1) {
0620 entot0 = entot;
0621
0622 }
0623
0624
0625
0626
0627 if (prename == "SBST") {
0628 sumStepc += stepl;
0629
0630 }
0631
0632
0633 if (prename == "SBSTs") {
0634 sumStepl += stepl;
0635
0636 }
0637
0638
0639
0640
0641 if (trackstatus != 2) {
0642
0643 if (prename == "SIDETL" || prename == "SIDETR") {
0644 if (prename == "SIDETL") {
0645
0646 }
0647 if (prename == "SIDETR") {
0648
0649 }
0650
0651
0652
0653
0654
0655
0656
0657
0658
0659
0660
0661
0662
0663
0664
0665
0666
0667
0668
0669
0670
0671
0672 G4String posname = aStep->GetPostStepPoint()->GetPhysicalVolume()->GetName();
0673 if ((prename == "SIDETL" && posname != "SIDETL") || (prename == "SIDETR" && posname != "SIDETR")) {
0674 if (name1[2] == "SISTATION") {
0675
0676 }
0677 if (name1[3] == "SIPLANE") {
0678
0679 }
0680
0681 if (prename == "SIDETL") {
0682
0683
0684 if (copyno1[2] < 2) {
0685
0686 } else if (copyno1[2] < 3) {
0687
0688 if (copyno1[3] < 2) {
0689 } else if (copyno1[3] < 3) {
0690
0691 } else if (copyno1[3] < 4) {
0692
0693 } else if (copyno1[3] < 5) {
0694
0695 } else if (copyno1[3] < 6) {
0696
0697 } else if (copyno1[3] < 7) {
0698
0699 } else if (copyno1[3] < 8) {
0700
0701 } else if (copyno1[3] < 9) {
0702
0703 } else if (copyno1[3] < 10) {
0704
0705 }
0706 } else if (copyno1[2] < 4) {
0707
0708 } else if (copyno1[2] < 5) {
0709
0710 }
0711 }
0712 if (prename == "SIDETR") {
0713
0714
0715 if (copyno1[2] < 2) {
0716
0717 } else if (copyno1[2] < 3) {
0718
0719 if (copyno1[3] < 2) {
0720 } else if (copyno1[3] < 3) {
0721
0722 } else if (copyno1[3] < 4) {
0723
0724 } else if (copyno1[3] < 5) {
0725
0726 } else if (copyno1[3] < 6) {
0727
0728 } else if (copyno1[3] < 7) {
0729
0730 } else if (copyno1[3] < 8) {
0731
0732 } else if (copyno1[3] < 9) {
0733
0734 } else if (copyno1[3] < 10) {
0735
0736 }
0737 } else if (copyno1[2] < 4) {
0738
0739 } else if (copyno1[2] < 5) {
0740
0741 }
0742 }
0743 }
0744 }
0745
0746 }
0747
0748
0749
0750
0751
0752 sumEnerDeposit += EnerDeposit;
0753
0754
0755
0756
0757
0758
0759
0760
0761
0762
0763
0764
0765
0766
0767
0768
0769 if (trackstatus == 2) {
0770
0771
0772 tracklength0 = tracklength;
0773
0774
0775
0776
0777
0778 }
0779 }
0780
0781
0782 if (parentID == 1 && curstepnumber == 1) {
0783
0784 numofpart += 1;
0785
0786
0787
0788
0789
0790
0791
0792
0793
0794
0795
0796
0797
0798
0799
0800 if (prename == "SBST") {
0801
0802 }
0803 if (prename == "SBSTs") {
0804
0805 }
0806 }
0807
0808
0809 }
0810
0811
0812 int FP420Test::detLevels(const G4VTouchable* touch) const {
0813
0814 if (touch)
0815 return ((touch->GetHistoryDepth()) + 1);
0816 else
0817 return 0;
0818 }
0819
0820
0821 G4String FP420Test::detName(const G4VTouchable* touch, int level, int currentlevel) const {
0822
0823 if (level > 0 && level >= currentlevel) {
0824 int ii = level - currentlevel;
0825 return touch->GetVolume(ii)->GetName();
0826 } else {
0827 return "NotFound";
0828 }
0829 }
0830
0831 void FP420Test::detectorLevel(const G4VTouchable* touch, int& level, int* copyno, G4String* name) const {
0832
0833 if (level > 0) {
0834 for (int ii = 0; ii < level; ii++) {
0835 int i = level - ii - 1;
0836 G4VPhysicalVolume* pv = touch->GetVolume(i);
0837 if (pv != nullptr)
0838 name[ii] = pv->GetName();
0839 else
0840 name[ii] = "Unknown";
0841 copyno[ii] = touch->GetReplicaNumber(i);
0842 }
0843 }
0844 }
0845
0846
0847
0848 void FP420Test::update(const EndOfEvent* evt) {
0849
0850
0851 if (verbosity > 1) {
0852 iev = (*evt)()->GetEventID();
0853 edm::LogVerbatim("FP420Test") << "FP420Test:update EndOfEvent = " << iev;
0854 }
0855
0856 fp420eventarray[ntfp420_evt] = (float)whichevent;
0857
0858
0859 int trackID = 0;
0860 G4PrimaryParticle* thePrim = nullptr;
0861
0862
0863 G4int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
0864 if (nvertex != 1)
0865 edm::LogVerbatim("FP420Test") << "FP420Test: My warning: NumberOfPrimaryVertex != 1 --> = " << nvertex;
0866
0867 for (int i = 0; i < nvertex; i++) {
0868 G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(i);
0869 if (avertex == nullptr) {
0870 edm::LogVerbatim("FP420Test") << "FP420Test End Of Event ERR: pointer to vertex = 0";
0871 continue;
0872 }
0873 G4int npart = avertex->GetNumberOfParticle();
0874 if (npart != 1)
0875 edm::LogVerbatim("FP420Test") << "FP420Test: My warning: NumberOfPrimaryPart != 1 --> = " << npart;
0876 if (npart == 0)
0877 edm::LogVerbatim("FP420Test") << "FP420Test End Of Event ERR: no NumberOfParticle";
0878
0879
0880 if (thePrim == nullptr)
0881 thePrim = avertex->GetPrimary(trackID);
0882
0883 if (thePrim != nullptr) {
0884
0885 G4double vx = 0., vy = 0., vz = 0.;
0886 vx = avertex->GetX0();
0887 vy = avertex->GetY0();
0888 vz = avertex->GetZ0();
0889
0890
0891
0892 theHistManager->getHisto("VtxX")->Fill(vx);
0893 theHistManager->getHisto("VtxY")->Fill(vy);
0894 theHistManager->getHisto("VtxZ")->Fill(vz);
0895 }
0896 }
0897
0898
0899
0900 if (thePrim != nullptr) {
0901
0902
0903
0904
0905
0906
0907
0908
0909
0910
0911
0912
0913
0914
0915
0916 if (lastpo.z() < z4 && lastpo.perp() < 100.) {
0917
0918 }
0919
0920
0921
0922 G4ThreeVector mom = thePrim->GetMomentum();
0923
0924 double phi = atan2(mom.y(), mom.x());
0925 if (phi < 0.)
0926 phi += twopi;
0927 double phigrad = phi * 180. / pi;
0928
0929 double th = mom.theta();
0930 double eta = -log(tan(th / 2));
0931
0932
0933
0934
0935
0936
0937
0938
0939
0940
0941
0942
0943 theHistManager->getHisto("PrimaryEta")->Fill(eta);
0944 theHistManager->getHisto("PrimaryPhigrad")->Fill(phigrad);
0945 theHistManager->getHisto("PrimaryTh")->Fill(th * 180. / pi);
0946
0947 theHistManager->getHisto("PrimaryLastpoZ")->Fill(lastpo.z());
0948 if (lastpo.z() < z4) {
0949 theHistManager->getHisto("PrimaryLastpoX")->Fill(lastpo.x());
0950 theHistManager->getHisto("PrimaryLastpoY")->Fill(lastpo.y());
0951 }
0952 if (numofpart > 4) {
0953 theHistManager->getHisto("XLastpoNumofpart")->Fill(lastpo.x());
0954 theHistManager->getHisto("YLastpoNumofpart")->Fill(lastpo.y());
0955 }
0956
0957
0958
0959
0960
0961
0962 std::map<int, float, std::less<int> > themap;
0963 std::map<int, float, std::less<int> > themap1;
0964
0965 std::map<int, float, std::less<int> > themapxy;
0966 std::map<int, float, std::less<int> > themapz;
0967
0968
0969
0970 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
0971
0972 if (verbosity > 0) {
0973 edm::LogVerbatim("FP420Test") << "FP420Test: accessed all HC";
0974 ;
0975 }
0976 int CAFIid = G4SDManager::GetSDMpointer()->GetCollectionID("FP420SI");
0977
0978
0979
0980 FP420G4HitCollection* theCAFI = (FP420G4HitCollection*)allHC->GetHC(CAFIid);
0981
0982 if (verbosity > 0) {
0983
0984 edm::LogVerbatim("FP420Test") << "FP420Test: theCAFI->entries = " << theCAFI->entries();
0985 }
0986
0987 theHistManager->getHisto("NumberOfHits")->Fill(theCAFI->entries());
0988
0989
0990
0991
0992
0993
0994
0995 int varia;
0996
0997
0998
0999
1000
1001
1002
1003
1004
1005 if (lastpo.z() < z4) {
1006
1007
1008
1009 varia = 1;
1010 } else {
1011
1012
1013
1014 varia = 2;
1015 }
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
1026
1027 if (varia == 2) {
1028
1029
1030
1031
1032
1033
1034
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
1043
1044
1045 int trackIDhit = aHit->getTrackID();
1046 unsigned int unitID = aHit->getUnitID();
1047
1048
1049
1050
1051
1052 double losenergy = aHit->getEnergyLoss();
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
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
1084
1085
1086
1087
1088
1089
1090
1091
1092 themap[unitID] += losenergy;
1093 totallosenergy += losenergy;
1094
1095 int det, zside, sector, zmodule;
1096
1097 FP420NumberingScheme::unpackFP420Index(unitID, det, zside, sector, zmodule);
1098 int justlayer = FP420NumberingScheme::unpackLayerIndex(rn00, zside);
1099 if (justlayer < 1 || justlayer > 2) {
1100 edm::LogVerbatim("FP420Test") << "FP420Test:WRONG justlayer= " << justlayer;
1101 }
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
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
1131 if (zside == 1) {
1132
1133 if (losenergy > 0.00003) {
1134 themap1[unitID] += 1.;
1135 }
1136 }
1137
1138 if (zside == 2) {
1139
1140 if (losenergy > 0.00005) {
1141 themap1[unitID] += 1.;
1142 }
1143 }
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177 if (lastpo.z() < z4 && lastpo.perp() < 120.) {
1178
1179
1180
1181
1182 if (zz < z2) {
1183
1184
1185 }
1186
1187 if (zz < z3 && zz > z2) {
1188
1189
1190 }
1191
1192 if (zz < z4 && zz > z3) {
1193
1194
1195
1196 }
1197 } else {
1198
1199
1200
1201
1202
1203
1204 if (zz < z2) {
1205
1206
1207
1208
1209 if (zside == 1) {
1210
1211 }
1212 if (zside == 2) {
1213
1214 }
1215 if (trackIDhit == 1) {
1216
1217
1218
1219 } else {
1220
1221 }
1222 }
1223
1224 if (zz < z3 && zz > z2) {
1225
1226
1227
1228
1229
1230
1231 if (zside == 1) {
1232
1233 }
1234 if (zside == 2) {
1235
1236 }
1237 if (trackIDhit == 1) {
1238
1239
1240 } else {
1241
1242 }
1243 }
1244
1245 if (zz < z4 && zz > z3) {
1246
1247
1248
1249
1250
1251 if (zside == 1) {
1252
1253 }
1254 if (zside == 2) {
1255
1256 }
1257 }
1258 }
1259
1260
1261
1262
1263 }
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
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);
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);
1290 if (justlayer < 1 || justlayer > 2) {
1291 edm::LogVerbatim("FP420Test") << "FP420Test:WRONG justlayer= " << justlayer;
1292 }
1293 int copyinlayer = FP420NumberingScheme::unpackCopyIndex(rn00, zside);
1294 if (copyinlayer < 1 || copyinlayer > 3) {
1295 edm::LogVerbatim("FP420Test") << "FP420Test:WRONG copyinlayer= " << copyinlayer;
1296 }
1297 int orientation = FP420NumberingScheme::unpackOrientation(rn00, zside);
1298 if (orientation < 1 || orientation > 2) {
1299 edm::LogVerbatim("FP420Test") << "FP420Test:WRONG orientation= " << orientation;
1300 }
1301
1302
1303 int detfixed =
1304 1;
1305
1306 unsigned int ii =
1307 FP420NumberingScheme::packMYIndex(rn00, pn0, sn0, detfixed, justlayer, sector, zmodule) - 1;
1308
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);
1325 double zcurrent = zinibeg + z420 + (zSiStep - zSiPlane) / 2 + kplane * zSiStep + zdiststat;
1326
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
1352 }
1353 }
1354 }
1355 }
1356
1357 if (verbosity > 2) {
1358 edm::LogVerbatim("FP420Test")
1359 << "----------------------------------------------------------------------------- ";
1360 }
1361
1362
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
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440 }
1441
1442 }
1443
1444
1445 if (verbosity > 0) {
1446 edm::LogVerbatim("FP420Test") << "FP420Test: END OF Event " << (*evt)()->GetEventID();
1447 }
1448 }
1449
1450 DEFINE_SIMWATCHER(FP420Test);