00001
00002
00003
00004
00005 #include <iostream>
00006 #include <iomanip>
00007 #include <cmath>
00008 #include<vector>
00009
00010 #include "SimG4Core/Notification/interface/BeginOfEvent.h"
00011 #include "SimG4Core/Notification/interface/EndOfEvent.h"
00012 #include "SimG4Core/Notification/interface/TrackWithHistory.h"
00013 #include "SimG4Core/Notification/interface/TrackInformation.h"
00014
00015 #include "FWCore/Framework/interface/Event.h"
00016 #include "FWCore/Framework/interface/EventSetup.h"
00017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00018
00019 #include "SimG4CMS/FP420/interface//FP420NumberingScheme.h"
00020
00021
00022 #include "SimG4CMS/FP420/interface//FP420G4HitCollection.h"
00023
00024 #include "SimG4CMS/FP420/interface/FP420Test.h"
00025
00026
00027
00028
00029
00030 #include "G4SDManager.hh"
00031 #include "G4Step.hh"
00032 #include "G4Track.hh"
00033 #include "G4VProcess.hh"
00034 #include "G4HCofThisEvent.hh"
00035 #include "G4UserEventAction.hh"
00036 #include "G4TransportationManager.hh"
00037 #include "G4ProcessManager.hh"
00038
00039
00040 #include "CLHEP/Units/GlobalSystemOfUnits.h"
00041 #include "CLHEP/Units/GlobalPhysicalConstants.h"
00042 #include <stdio.h>
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 #include <cassert>
00053
00054 using namespace edm;
00055 using namespace std;
00056
00057
00058
00059
00060 enum ntfp420_elements {
00061 ntfp420_evt
00062 };
00063
00064 FP420Test::FP420Test(const edm::ParameterSet &p){
00065
00066 edm::ParameterSet m_Anal = p.getParameter<edm::ParameterSet>("FP420Test");
00067 verbosity = m_Anal.getParameter<int>("Verbosity");
00068
00069
00070 fDataLabel = m_Anal.getParameter<std::string>("FDataLabel");
00071 fOutputFile = m_Anal.getParameter<std::string>("FOutputFile");
00072 fRecreateFile = m_Anal.getParameter<std::string>("FRecreateFile");
00073
00074 if (verbosity > 0) {
00075 std::cout<<"============================================================================"<<std::endl;
00076 std::cout << "FP420Testconstructor :: Initialized as observer"<< std::endl;
00077 }
00078
00079
00080 theFP420NumberingScheme = new FP420NumberingScheme();
00081 pn0 = 6;
00082 sn0 = 3;
00083 rn00 = 7;
00084
00085 z420 = 420000.0;
00086 zD2 = 4000.0;
00087 zD3 = 8000.0;
00088
00089 zBlade = 5.00;
00090 gapBlade = 1.6;
00091 double gapSupplane = 1.6;
00092 ZSiPlane=2*zBlade+gapBlade+gapSupplane;
00093
00094 double ZKapton = 0.1;
00095 ZSiStep=ZSiPlane+ZKapton;
00096
00097 double ZBoundDet = 0.020;
00098 double ZSiElectr = 0.250;
00099 double ZCeramDet = 0.500;
00100
00101 ZSiDet = 0.250;
00102 ZGapLDet= zBlade/2-(ZSiDet+ZSiElectr+ZBoundDet+ZCeramDet/2);
00103
00104
00105 double ZSiStation = (pn0-1)*(2*(zBlade+gapBlade)+ZKapton)+2*6.+0.0;
00106
00107 double eee1=11.;
00108 double eee2=12.;
00109
00110 zinibeg = (eee1-eee2)/2.;
00111
00112 z1 = zinibeg + (ZSiStation+10.)/2 + z420;
00113 z2 = z1+zD2;
00114 z3 = z1+zD3;
00115 z4 = z1+2*zD3;
00116
00117
00118 fp420eventntuple = new TNtuple("NTfp420event","NTfp420event","evt");
00119
00120 whichevent = 0;
00121
00122
00123
00124
00125
00126 TheHistManager = new Fp420AnalysisHistManager(fDataLabel);
00127
00128 if (verbosity > 0) {
00129 std::cout << "FP420Test constructor :: Initialized Fp420AnalysisHistManager"<< std::endl;
00130 }
00131 }
00132
00133
00134
00135 FP420Test::~FP420Test() {
00136
00137 delete theFP420NumberingScheme;
00138
00139 TFile fp420OutputFile("newntfp420.root","RECREATE");
00140 std::cout << "FP420 output root file has been created";
00141 fp420eventntuple->Write();
00142 std::cout << ", written";
00143 fp420OutputFile.Close();
00144 std::cout << ", closed";
00145 delete fp420eventntuple;
00146 std::cout << ", and deleted" << std::endl;
00147
00148
00149
00150
00151 TheHistManager->WriteToFile(fOutputFile,fRecreateFile);
00152 if (verbosity > 0) {
00153 std::cout << std::endl << "FP420Test Destructor --------> End of FP420Test : "
00154 << std::cout << std::endl;
00155 }
00156
00157 std::cout<<"FP420Test: End of process"<<std::endl;
00158
00159
00160
00161 }
00162
00163
00164
00165
00166
00167 Fp420AnalysisHistManager::Fp420AnalysisHistManager(TString managername)
00168 {
00169
00170
00171 fTypeTitle=managername;
00172 fHistArray = new TObjArray();
00173 fHistNamesArray = new TObjArray();
00174
00175 TH1::AddDirectory(kFALSE);
00176 BookHistos();
00177
00178 fHistArray->Compress();
00179 fHistNamesArray->Compress();
00180
00181
00182
00183 }
00184
00185
00186 Fp420AnalysisHistManager::~Fp420AnalysisHistManager()
00187 {
00188
00189
00190 if(fHistArray){
00191 fHistArray->Delete();
00192 delete fHistArray;
00193 }
00194
00195 if(fHistNamesArray){
00196 fHistNamesArray->Delete();
00197 delete fHistNamesArray;
00198 }
00199 }
00200
00201
00202 void Fp420AnalysisHistManager::BookHistos()
00203 {
00204
00205 HistInit("PrimaryEta", "Primary Eta", 100, 9., 12. );
00206 HistInit("PrimaryPhigrad", "Primary Phigrad", 100, 0.,360. );
00207 HistInit("PrimaryTh", "Primary Th", 100, 0.,180. );
00208 HistInit("PrimaryLastpoZ", "Primary Lastpo Z", 100, -200.,430000. );
00209 HistInit("PrimaryLastpoX", "Primary Lastpo X Z<z4", 100, -30., 30. );
00210 HistInit("PrimaryLastpoY", "Primary Lastpo Y Z<z4", 100, -30., 30. );
00211 HistInit("XLastpoNumofpart", "Primary Lastpo X n>10", 100, -30., 30. );
00212 HistInit("YLastpoNumofpart", "Primary Lastpo Y n>10", 100, -30., 30. );
00213 HistInit("VtxX", "Vtx X", 100, -50., 50. );
00214 HistInit("VtxY", "Vtx Y", 100, -50., 50. );
00215 HistInit("VtxZ", "Vtx Z", 100, -200.,430000. );
00216
00217 HistInit("SumEDep", "This is sum Energy deposited", 100, -1, 199.);
00218 HistInit("TrackL", "This is TrackL", 100, 0., 12000.);
00219 HistInit("zHits", "z Hits all events", 100, 400000.,430000. );
00220 HistInit("zHitsnoMI", "z Hits no MI", 100, 400000.,430000. );
00221 HistInit("zHitsTrLoLe", "z Hits TrLength bigger 8300",100, 400000.,430000. );
00222 HistInit("NumberOfHits", "NumberOfHits",100, 0.,300. );
00223 }
00224
00225
00226
00227 void Fp420AnalysisHistManager::WriteToFile(TString fOutputFile,TString fRecreateFile)
00228 {
00229
00230
00231
00232 std::cout <<"================================================================"<<std::endl;
00233 std::cout <<" Write this Analysis to File "<<fOutputFile<<std::endl;
00234 std::cout <<"================================================================"<<std::endl;
00235
00236 TFile* file = new TFile(fOutputFile, fRecreateFile);
00237
00238 fHistArray->Write();
00239 file->Close();
00240 }
00241
00242
00243 void Fp420AnalysisHistManager::HistInit(const char* name, const char* title, Int_t nbinsx, Axis_t xlow, Axis_t xup)
00244 {
00245
00246
00247 char* newtitle = new char[strlen(title)+strlen(fTypeTitle)+5];
00248 strcpy(newtitle,title);
00249 strcat(newtitle," (");
00250 strcat(newtitle,fTypeTitle);
00251 strcat(newtitle,") ");
00252 fHistArray->AddLast((new TH1F(name, newtitle, nbinsx, xlow, xup)));
00253 fHistNamesArray->AddLast(new TObjString(name));
00254
00255 }
00256
00257
00258 void Fp420AnalysisHistManager::HistInit(const char* name, const char* title, Int_t nbinsx, Axis_t xlow, Axis_t xup, Int_t nbinsy, Axis_t ylow, Axis_t yup)
00259 {
00260
00261
00262 char* newtitle = new char[strlen(title)+strlen(fTypeTitle)+5];
00263 strcpy(newtitle,title);
00264 strcat(newtitle," (");
00265 strcat(newtitle,fTypeTitle);
00266 strcat(newtitle,") ");
00267 fHistArray->AddLast((new TH2F(name, newtitle, nbinsx, xlow, xup, nbinsy, ylow, yup)));
00268 fHistNamesArray->AddLast(new TObjString(name));
00269
00270 }
00271
00272
00273 TH1F* Fp420AnalysisHistManager::GetHisto(Int_t Number)
00274 {
00275
00276
00277 if (Number <= fHistArray->GetLast() && fHistArray->At(Number) != (TObject*)0){
00278
00279 return (TH1F*)(fHistArray->At(Number));
00280
00281 }else{
00282
00283 std::cout << "!!!!!!!!!!!!!!!!!!GetHisto!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
00284 std::cout << " WARNING ERROR - HIST ID INCORRECT (TOO HIGH) - " << Number << std::endl;
00285 std::cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
00286
00287 return (TH1F*)(fHistArray->At(0));
00288 }
00289 }
00290
00291
00292 TH2F* Fp420AnalysisHistManager::GetHisto2(Int_t Number)
00293 {
00294
00295
00296 if (Number <= fHistArray->GetLast() && fHistArray->At(Number) != (TObject*)0){
00297
00298 return (TH2F*)(fHistArray->At(Number));
00299
00300 }else{
00301
00302 std::cout << "!!!!!!!!!!!!!!!!GetHisto2!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
00303 std::cout << " WARNING ERROR - HIST ID INCORRECT (TOO HIGH) - " << Number << std::endl;
00304 std::cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
00305
00306 return (TH2F*)(fHistArray->At(0));
00307 }
00308 }
00309
00310
00311 TH1F* Fp420AnalysisHistManager::GetHisto(const TObjString histname)
00312 {
00313
00314
00315 Int_t index = fHistNamesArray->IndexOf(&histname);
00316 return GetHisto(index);
00317 }
00318
00319
00320 TH2F* Fp420AnalysisHistManager::GetHisto2(const TObjString histname)
00321 {
00322
00323
00324 Int_t index = fHistNamesArray->IndexOf(&histname);
00325 return GetHisto2(index);
00326 }
00327
00328
00329 void Fp420AnalysisHistManager::StoreWeights()
00330 {
00331
00332
00333 for(int i = 0; i < fHistArray->GetEntries(); i++){
00334 ((TH1F*)(fHistArray->At(i)))->Sumw2();
00335 }
00336 }
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405 void FP420Test::update(const BeginOfJob * job) {
00406
00407 std::cout<<"FP420Test:beggining of job"<<std::endl;;
00408 }
00409
00410
00411
00412 void FP420Test::update(const BeginOfRun * run) {
00413
00414
00415 std::cout << std::endl << "FP420Test:: Begining of Run"<< std::endl;
00416 }
00417
00418
00419 void FP420Test::update(const EndOfRun * run) {;}
00420
00421
00422
00423
00424 void FP420Test::update(const BeginOfEvent * evt) {
00425 iev = (*evt)()->GetEventID();
00426 if (verbosity > 0) {
00427 std::cout <<"FP420Test:update Event number = " << iev << std::endl;
00428 }
00429 whichevent++;
00430 }
00431
00432
00433 void FP420Test::update(const BeginOfTrack * trk) {
00434 itrk = (*trk)()->GetTrackID();
00435 if (verbosity > 1) {
00436 std::cout <<"FP420Test:update BeginOfTrack number = " << itrk << std::endl;
00437 }
00438 if(itrk == 1) {
00439 SumEnerDeposit = 0.;
00440 numofpart = 0;
00441 SumStepl = 0.;
00442 SumStepc = 0.;
00443 tracklength0 = 0.;
00444 }
00445 }
00446
00447
00448
00449
00450 void FP420Test::update(const EndOfTrack * trk) {
00451 itrk = (*trk)()->GetTrackID();
00452 if (verbosity > 1) {
00453 std::cout <<"FP420Test:update EndOfTrack number = " << itrk << std::endl;
00454 }
00455 if(itrk == 1) {
00456 G4double tracklength = (*trk)()->GetTrackLength();
00457
00458 TheHistManager->GetHisto("SumEDep")->Fill(SumEnerDeposit);
00459 TheHistManager->GetHisto("TrackL")->Fill(tracklength);
00460
00461
00462 G4ThreeVector vert_mom = (*trk)()->GetVertexMomentumDirection();
00463 G4ThreeVector vert_pos = (*trk)()->GetVertexPosition();
00464
00465
00466 float phi = atan2(vert_mom.y(),vert_mom.x());
00467 if (phi < 0.) phi += twopi;
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492 if(tracklength < z4) {
00493
00494
00495
00496
00497 }
00498
00499
00500 const G4Step* aStep = (*trk)()->GetStep();
00501
00502
00503
00504 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
00505 lastpo = preStepPoint->GetPosition();
00506
00507
00508 if(lastpo.z()<z1 && lastpo.perp()< 100.) {
00509
00510
00511
00512
00513 }
00514 if((lastpo.z()>z1 && lastpo.z()<z2) && lastpo.perp()< 100.) {
00515
00516
00517
00518
00519 }
00520 if(lastpo.z()<z2 && lastpo.perp()< 100.) {
00521
00522
00523
00524
00525
00526
00527
00528 }
00529 if(lastpo.z()<z3 && lastpo.perp()< 100.) {
00530
00531
00532
00533
00534 }
00535 if(lastpo.z()<z4 && lastpo.perp()< 100.) {
00536
00537
00538
00539
00540
00541
00542
00543 }
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553 }
00554
00555 }
00556
00557
00558
00559
00560 void FP420Test::update(const G4Step * aStep) {
00561
00562
00563 if (verbosity > 2) {
00564 G4int stepnumber = aStep->GetTrack()->GetCurrentStepNumber();
00565 std::cout <<"FP420Test:update Step number = " << stepnumber << std::endl;
00566 }
00567
00568 G4Track* theTrack = aStep->GetTrack();
00569 TrackInformation* trkInfo = dynamic_cast<TrackInformation*> (theTrack->GetUserInformation());
00570 if (trkInfo == 0) {
00571 std::cout << "FP420Test on aStep: No trk info !!!! abort " << std::endl;
00572
00573 }
00574 G4int id = theTrack->GetTrackID();
00575 G4String particleType = theTrack->GetDefinition()->GetParticleName();
00576 G4int parentID = theTrack->GetParentID();
00577 G4TrackStatus trackstatus = theTrack->GetTrackStatus();
00578 G4double tracklength = theTrack->GetTrackLength();
00579 G4ThreeVector trackmom = theTrack->GetMomentum();
00580 G4double entot = theTrack->GetTotalEnergy();
00581 G4int curstepnumber = theTrack->GetCurrentStepNumber();
00582 G4ThreeVector vert_pos = theTrack->GetVertexPosition();
00583 G4ThreeVector vert_mom = theTrack->GetVertexMomentumDirection();
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599 G4double stepl = aStep->GetStepLength();
00600 G4double EnerDeposit = aStep->GetTotalEnergyDeposit();
00601
00602
00603
00604
00605
00606
00607
00608 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
00609 G4ThreeVector preposition = preStepPoint->GetPosition();
00610 G4ThreeVector prelocalpoint = theTrack->GetTouchable()->GetHistory()->
00611 GetTopTransform().TransformPoint(preposition);
00612 G4VPhysicalVolume* currentPV = preStepPoint->GetPhysicalVolume();
00613 G4String prename = currentPV->GetName();
00614
00615 const G4VTouchable* pre_touch = preStepPoint->GetTouchable();
00616 int pre_levels = detLevels(pre_touch);
00617
00618
00619
00620
00621 G4String name1[20]; int copyno1[20];
00622 if (pre_levels > 0) {
00623 detectorLevel(pre_touch, pre_levels, copyno1, name1);
00624 }
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676 if ( id == 1 ) {
00677
00678
00679 if (curstepnumber == 1 ) {
00680 entot0 = entot;
00681
00682
00683 }
00684
00685
00686
00687
00688 if(prename == "SBST" ) {
00689 SumStepc += stepl;
00690
00691 }
00692
00693
00694 if(prename == "SBSTs" ) {
00695 SumStepl += stepl;
00696
00697 }
00698
00699
00700
00701
00702 if (trackstatus != 2 ) {
00703
00704 if(prename == "SIDETL" || prename == "SIDETR" ) {
00705 if(prename == "SIDETL") {
00706
00707 }
00708 if(prename == "SIDETR") {
00709
00710 }
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733 G4String posname = aStep->GetPostStepPoint()->GetPhysicalVolume()->GetName();
00734 if((prename == "SIDETL" && posname != "SIDETL") || (prename == "SIDETR" && posname != "SIDETR")) {
00735 if(name1[2] == "SISTATION" ) {
00736
00737 }
00738 if(name1[3] == "SIPLANE" ) {
00739
00740 }
00741
00742 if(prename == "SIDETL") {
00743
00744
00745 if(copyno1[2]<2) {
00746
00747 }
00748 else if(copyno1[2]<3) {
00749
00750 if(copyno1[3]<2) {
00751 }
00752 else if(copyno1[3]<3) {
00753
00754 }
00755 else if(copyno1[3]<4) {
00756
00757 }
00758 else if(copyno1[3]<5) {
00759
00760 }
00761 else if(copyno1[3]<6) {
00762
00763 }
00764 else if(copyno1[3]<7) {
00765
00766 }
00767 else if(copyno1[3]<8) {
00768
00769 }
00770 else if(copyno1[3]<9) {
00771
00772 }
00773 else if(copyno1[3]<10) {
00774
00775 }
00776 }
00777 else if(copyno1[2]<4) {
00778
00779 }
00780 else if(copyno1[2]<5) {
00781
00782 }
00783 }
00784 if(prename == "SIDETR") {
00785
00786
00787 if(copyno1[2]<2) {
00788
00789 }
00790 else if(copyno1[2]<3) {
00791
00792 if(copyno1[3]<2) {
00793 }
00794 else if(copyno1[3]<3) {
00795
00796 }
00797 else if(copyno1[3]<4) {
00798
00799 }
00800 else if(copyno1[3]<5) {
00801
00802 }
00803 else if(copyno1[3]<6) {
00804
00805 }
00806 else if(copyno1[3]<7) {
00807
00808 }
00809 else if(copyno1[3]<8) {
00810
00811 }
00812 else if(copyno1[3]<9) {
00813
00814 }
00815 else if(copyno1[3]<10) {
00816
00817 }
00818 }
00819 else if(copyno1[2]<4) {
00820
00821 }
00822 else if(copyno1[2]<5) {
00823
00824 }
00825 }
00826
00827 }
00828 }
00829
00830 }
00831
00832
00833
00834
00835
00836
00837 SumEnerDeposit += EnerDeposit;
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854 if (trackstatus == 2 ) {
00855
00856
00857 tracklength0 = tracklength;
00858
00859
00860
00861
00862
00863 }
00864 }
00865
00866
00867
00868 if (parentID == 1 && curstepnumber == 1) {
00869
00870 numofpart += 1;
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883
00884
00885
00886 if(prename == "SBST" ) {
00887
00888 }
00889 if(prename == "SBSTs" ) {
00890
00891 }
00892 }
00893
00894
00895
00896
00897
00898 }
00899
00900
00901 int FP420Test::detLevels(const G4VTouchable* touch) const {
00902
00903
00904 if (touch)
00905 return ((touch->GetHistoryDepth())+1);
00906 else
00907 return 0;
00908 }
00909
00910
00911 G4String FP420Test::detName(const G4VTouchable* touch, int level,
00912 int currentlevel) const {
00913
00914
00915 if (level > 0 && level >= currentlevel) {
00916 int ii = level - currentlevel;
00917 return touch->GetVolume(ii)->GetName();
00918 } else {
00919 return "NotFound";
00920 }
00921 }
00922
00923 void FP420Test::detectorLevel(const G4VTouchable* touch, int& level,
00924 int* copyno, G4String* name) const {
00925
00926
00927 if (level > 0) {
00928 for (int ii = 0; ii < level; ii++) {
00929 int i = level - ii - 1;
00930 G4VPhysicalVolume* pv = touch->GetVolume(i);
00931 if (pv != 0)
00932 name[ii] = pv->GetName();
00933 else
00934 name[ii] = "Unknown";
00935 copyno[ii] = touch->GetReplicaNumber(i);
00936 }
00937 }
00938 }
00939
00940
00941
00942 void FP420Test::update(const EndOfEvent * evt) {
00943
00944
00945 if (verbosity > 1) {
00946 iev = (*evt)()->GetEventID();
00947 std::cout <<"FP420Test:update EndOfEvent = " << iev << std::endl;
00948 }
00949
00950 fp420eventarray[ntfp420_evt] = (float)whichevent;
00951
00952
00953 int trackID = 0;
00954 G4PrimaryParticle* thePrim=0;
00955
00956
00957
00958 G4int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
00959 if (nvertex !=1)
00960 std::cout << "FP420Test: My warning: NumberOfPrimaryVertex != 1 --> = " << nvertex << std::endl;
00961
00962 for (int i = 0 ; i<nvertex; i++) {
00963 G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(i);
00964 if (avertex == 0)
00965 std::cout << "FP420Test End Of Event ERR: pointer to vertex = 0"
00966 << std::endl;
00967 G4int npart = avertex->GetNumberOfParticle();
00968 if (npart !=1)
00969 std::cout << "FP420Test: My warning: NumberOfPrimaryPart != 1 --> = " << npart << std::endl;
00970 if (npart ==0)
00971 std::cout << "FP420Test End Of Event ERR: no NumberOfParticle" << std::endl;
00972
00973
00974 if (thePrim==0) thePrim=avertex->GetPrimary(trackID);
00975
00976 if (thePrim!=0) {
00977
00978 G4double vx=0.,vy=0.,vz=0.;
00979 vx = avertex->GetX0();
00980 vy = avertex->GetY0();
00981 vz = avertex->GetZ0();
00982
00983
00984
00985 TheHistManager->GetHisto("VtxX")->Fill(vx);
00986 TheHistManager->GetHisto("VtxY")->Fill(vy);
00987 TheHistManager->GetHisto("VtxZ")->Fill(vz);
00988 }
00989 }
00990
00991
00992
00993 if (thePrim != 0) {
00994
00995
00996
00997
00998
00999 int ivert = 0 ;
01000 G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(ivert);
01001 G4double vx=0.,vy=0.,vz=0.;
01002 vx = avertex->GetX0();
01003 vy = avertex->GetY0();
01004 vz = avertex->GetZ0();
01005
01006
01007
01008
01009 if(lastpo.z()<z4 && lastpo.perp()< 100.) {
01010
01011 }
01012
01013
01014
01015 G4ThreeVector mom = thePrim->GetMomentum();
01016
01017 double phi = atan2(mom.y(),mom.x());
01018 if (phi < 0.) phi += twopi;
01019 double phigrad = phi*180./pi;
01020
01021 double th = mom.theta();
01022 double eta = -log(tan(th/2));
01023
01024
01025
01026
01027
01028
01029
01030
01031
01032
01033
01034
01035 TheHistManager->GetHisto("PrimaryEta")->Fill(eta);
01036 TheHistManager->GetHisto("PrimaryPhigrad")->Fill(phigrad);
01037 TheHistManager->GetHisto("PrimaryTh")->Fill(th*180./pi);
01038
01039 TheHistManager->GetHisto("PrimaryLastpoZ")->Fill(lastpo.z());
01040 if(lastpo.z() < z4 ) {
01041 TheHistManager->GetHisto("PrimaryLastpoX")->Fill(lastpo.x());
01042 TheHistManager->GetHisto("PrimaryLastpoY")->Fill(lastpo.y());
01043 }
01044 if(numofpart > 4 ) {
01045 TheHistManager->GetHisto("XLastpoNumofpart")->Fill(lastpo.x());
01046 TheHistManager->GetHisto("YLastpoNumofpart")->Fill(lastpo.y());
01047 }
01048
01049
01050
01051
01052
01053
01054 map<int,float,less<int> > themap;
01055 map<int,float,less<int> > themap1;
01056
01057 map<int,float,less<int> > themapxy;
01058 map<int,float,less<int> > themapz;
01059
01060
01061
01062 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
01063
01064 if (verbosity > 0) {
01065 std::cout << "FP420Test: accessed all HC" << std::endl;;
01066 }
01067 int CAFIid = G4SDManager::GetSDMpointer()->GetCollectionID("FP420SI");
01068
01069
01070
01071 FP420G4HitCollection* theCAFI = (FP420G4HitCollection*) allHC->GetHC(CAFIid);
01072
01073 if (verbosity > 0) {
01074
01075 std::cout << "FP420Test: theCAFI->entries = " << theCAFI->entries() << std::endl;
01076 }
01077
01078 TheHistManager->GetHisto("NumberOfHits")->Fill(theCAFI->entries());
01079
01080
01081
01082
01083
01084
01085
01086 int varia ;
01087 varia = 0;
01088
01089
01090
01091
01092
01093
01094
01095
01096
01097 if( lastpo.z()< z4) {
01098
01099
01100
01101 varia = 1;
01102 }
01103 else{
01104
01105
01106
01107 varia = 2;
01108 }
01109
01110 for (int j=0; j<theCAFI->entries(); j++) {
01111 FP420G4Hit* aHit = (*theCAFI)[j];
01112 G4ThreeVector hitPoint = aHit->getEntry();
01113 double zz = hitPoint.z();
01114 TheHistManager->GetHisto("zHits")->Fill(zz);
01115 if(tracklength0>8300.) TheHistManager->GetHisto("zHitsTrLoLe")->Fill(zz);
01116 }
01117
01118
01119 if( varia == 2) {
01120
01121
01122
01123
01124
01125
01126
01127 int nhit11 = 0, nhit12 = 0, nhit13 = 0 ;
01128 double totallosenergy= 0.;
01129 for (int j=0; j<theCAFI->entries(); j++) {
01130 FP420G4Hit* aHit = (*theCAFI)[j];
01131
01132 G4ThreeVector hitEntryLocalPoint = aHit->getEntryLocalP();
01133 G4ThreeVector hitExitLocalPoint = aHit->getExitLocalP();
01134 G4ThreeVector hitPoint = aHit->getEntry();
01135
01136
01137
01138 int trackIDhit = aHit->getTrackID();
01139 unsigned int unitID = aHit->getUnitID();
01140
01141
01142
01143
01144
01145 double losenergy = aHit->getEnergyLoss();
01146
01147
01148
01149
01150
01151
01152
01153
01154
01155
01156
01157
01158
01159 double phi_hit = hitPoint.phi();
01160 if (phi_hit < 0.) phi_hit += twopi;
01161
01162
01163
01164
01165
01166
01167
01168
01169 double zz = hitPoint.z();
01170
01171 TheHistManager->GetHisto("zHitsnoMI")->Fill(zz);
01172
01173 if (verbosity > 2) {
01174 std::cout << "FP420Test:zHits = " << zz << std::endl;
01175 }
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185 themap[unitID] += losenergy;
01186 totallosenergy += losenergy;
01187
01188 int det, zside, sector, zmodule;
01189
01190 FP420NumberingScheme::unpackFP420Index(unitID, det, zside, sector, zmodule);
01191 int justlayer = theFP420NumberingScheme->FP420NumberingScheme::unpackLayerIndex(rn00, zside);
01192 if(justlayer<1||justlayer>2) {
01193 std::cout << "FP420Test:WRONG justlayer= " << justlayer << std::endl;
01194 }
01195
01196
01197
01198
01199
01200
01201
01202
01203
01204
01205
01206
01207
01208 G4ThreeVector middle = (hitExitLocalPoint-hitEntryLocalPoint)/2.;
01209 themapz[unitID] = hitPoint.z()+fabs(middle.z());
01210 if (verbosity > 2) {
01211 std::cout << "1111111111111111111111111111111111111111111111111111111111111111111111111 " << std::endl;
01212 std::cout << "FP420Test: det, zside, sector, zmodule = " << det << zside << sector << zmodule << std::endl;
01213 std::cout << "FP420Test: justlayer = " << justlayer << std::endl;
01214 std::cout << "FP420Test: hitExitLocalPoint = " << hitExitLocalPoint << std::endl;
01215 std::cout << "FP420Test: hitEntryLocalPoint = " << hitEntryLocalPoint << std::endl;
01216 std::cout << "FP420Test: middle= " << middle << std::endl;
01217 std::cout << "FP420Test: hitPoint.z()-419000.= " << hitPoint.z()-419000. << std::endl;
01218
01219 std::cout << "FP420Test:zHits-419000. = " << themapz[unitID]-419000. << std::endl;
01220 }
01221
01222
01223 if(zside==1) {
01224
01225 if(losenergy > 0.00003) {
01226 themap1[unitID] += 1.;
01227 }
01228 }
01229
01230 if(zside==2){
01231
01232 if(losenergy > 0.00005) {
01233 themap1[unitID] += 1.;
01234 }
01235 }
01236
01237
01238 if(sector==1) {
01239 nhit11 += 1;
01240
01241
01242 }
01243 if(sector==2) {
01244 nhit12 += 1;
01245
01246
01247 }
01248 if(sector==3) {
01249 nhit13 += 1;
01250
01251
01252 }
01253
01254
01255
01256
01257
01258
01259
01260
01261
01262
01263
01264
01265
01266
01267
01268
01269
01270
01271
01272
01273 if(lastpo.z()<z4 && lastpo.perp()< 120.) {
01274
01275
01276
01277
01278 if( zz < z2){
01279
01280
01281 }
01282
01283 if( zz < z3 && zz > z2){
01284
01285
01286 }
01287
01288 if( zz < z4 && zz > z3){
01289
01290
01291
01292 }
01293 }
01294 else{
01295
01296
01297
01298
01299
01300
01301 if( zz < z2){
01302
01303
01304
01305
01306 if(zside==1) {
01307
01308 }
01309 if(zside==2){
01310
01311 }
01312 if(trackIDhit == 1){
01313
01314
01315
01316 }
01317 else{
01318
01319 }
01320 }
01321
01322 if( zz < z3 && zz > z2){
01323
01324
01325
01326
01327
01328
01329 if(zside==1) {
01330
01331 }
01332 if(zside==2){
01333
01334 }
01335 if(trackIDhit == 1){
01336
01337
01338 }
01339 else{
01340
01341 }
01342 }
01343
01344 if( zz < z4 && zz > z3){
01345
01346
01347
01348
01349
01350 if(zside==1) {
01351
01352 }
01353 if(zside==2){
01354
01355 }
01356 }
01357 }
01358
01359
01360
01361
01362 }
01363
01364
01365
01366
01367
01368
01369
01370
01371
01372
01373
01374 if (verbosity > 2) {
01375 std::cout << "22222222222222222222222222222222222222222222222222222222222222222222222222 " << std::endl;
01376 }
01377 int det = 1;
01378 int allplacesforsensors=7;
01379 for (int sector=1; sector < sn0; sector++) {
01380 for (int zmodule=1; zmodule<pn0; zmodule++) {
01381 for (int zsideinorder=1; zsideinorder<allplacesforsensors; zsideinorder++) {
01382 int zside = theFP420NumberingScheme->FP420NumberingScheme::realzside(rn00, zsideinorder);
01383 if (verbosity > 2) {
01384 std::cout << "FP420Test: sector= " << sector << " zmodule= " << zmodule << " zsideinorder= " << zsideinorder << " zside= " << zside << std::endl;
01385 }
01386 if(zside != 0) {
01387 int justlayer = theFP420NumberingScheme->FP420NumberingScheme::unpackLayerIndex(rn00, zside);
01388 if(justlayer<1||justlayer>2) {
01389 std::cout << "FP420Test:WRONG justlayer= " << justlayer << std::endl;
01390 }
01391 int copyinlayer = theFP420NumberingScheme->FP420NumberingScheme::unpackCopyIndex(rn00, zside);
01392 if(copyinlayer<1||copyinlayer>3) {
01393 std::cout << "FP420Test:WRONG copyinlayer= " << copyinlayer << std::endl;
01394 }
01395 int orientation = theFP420NumberingScheme->FP420NumberingScheme::unpackOrientation(rn00, zside);
01396 if(orientation<1||orientation>2) {
01397 std::cout << "FP420Test:WRONG orientation= " << orientation << std::endl;
01398 }
01399
01400
01401 int detfixed=1;
01402
01403 unsigned int ii=theFP420NumberingScheme->FP420NumberingScheme::packMYIndex(rn00,pn0,sn0,detfixed,justlayer,sector,zmodule)-1;
01404
01405 if (verbosity > 2) {
01406 std::cout << "FP420Test: justlayer = " << justlayer << " copyinlayer = " << copyinlayer << " orientation = " << orientation << " ii= " << ii << std::endl;
01407 }
01408 double zdiststat = 0.;
01409 if(sn0<4) {
01410 if(sector==2) zdiststat = zD3;
01411 }
01412 else {
01413 if(sector==2) zdiststat = zD2;
01414 if(sector==3) zdiststat = zD3;
01415 }
01416 double kplane = -(pn0-1)/2 - 0.5 + (zmodule-1);
01417 double zcurrent = zinibeg + z420 + (ZSiStep-ZSiPlane)/2 + kplane*ZSiStep + zdiststat;
01418
01419 if (verbosity > 2) {
01420 std::cout << "FP420Test: Leftzcurrent-419000. = " << zcurrent-419000. << std::endl;
01421 std::cout << "FP420Test: ZGapLDet = " << ZGapLDet << std::endl;
01422 }
01423 if(justlayer==1){
01424 if(orientation==1) zcurrent += (ZGapLDet+ZSiDet/2);
01425 if(orientation==2) zcurrent += zBlade-(ZGapLDet+ZSiDet/2);
01426 }
01427 if(justlayer==2){
01428 if(orientation==1) zcurrent += (ZGapLDet+ZSiDet/2)+zBlade+gapBlade;
01429 if(orientation==2) zcurrent += 2*zBlade+gapBlade-(ZGapLDet+ZSiDet/2);
01430 }
01431
01432
01433 if(det == 2) zcurrent = -zcurrent;
01434
01435 if (verbosity > 2) {
01436 std::cout << "FP420Test: zcurrent-419000. = " << zcurrent-419000. << std::endl;
01437 }
01438
01439 }
01440 }
01441 }
01442 }
01443
01444
01445 if (verbosity > 2) {
01446 std::cout << "----------------------------------------------------------------------------- " << std::endl;
01447 }
01448
01449
01450
01451
01452 if(totallosenergy == 0.0) {
01453 std::cout << "FP420Test: number of hits = " << theCAFI->entries() << std::endl;
01454 for (int j=0; j<theCAFI->entries(); j++) {
01455 FP420G4Hit* aHit = (*theCAFI)[j];
01456 double losenergy = aHit->getEnergyLoss();
01457 std::cout << " j hits = " << j << "losenergy = " << losenergy << std::endl;
01458 }
01459 }
01460
01461
01462
01463
01464
01465
01466
01467 double totalEnergy = 0.;
01468 int nhitsX = 0, nhitsY = 0, nsumhit = 0 ;
01469 for (int sector=1; sector<4; sector++) {
01470 int nhitsecX = 0, nhitsecY = 0;
01471 for (int zmodule=1; zmodule<11; zmodule++) {
01472 for (int zside=1; zside<3; zside++) {
01473 int det= 1, nhit = 0;
01474
01475 int index = FP420NumberingScheme::packFP420Index(det, zside, sector, zmodule);
01476 double theTotalEnergy = themap[index];
01477
01478 if(zside<2){
01479
01480 if(theTotalEnergy > 0.00003) {
01481 nhitsX += 1;
01482
01483 nhit=1;
01484 }
01485 }
01486
01487 else {
01488
01489 if(theTotalEnergy > 0.00005) {
01490 nhitsY += 1;
01491
01492 nhit=1;
01493 }
01494 }
01495
01496
01497
01498
01499
01500
01501
01502 totalEnergy += themap[index];
01503 }
01504 }
01505
01506 if(nhitsecX > 10 || nhitsecY > 10) {
01507 nsumhit +=1;
01508
01509 }
01510 else{
01511 }
01512 }
01513
01514
01515
01516
01517
01518
01519
01520 if( nsumhit >=2 ) {
01521 }
01522 else{
01523 }
01524
01525
01526
01527
01528
01529
01530
01531 }
01532
01533
01534
01535 }
01536
01537
01538
01539
01540
01541
01542
01543 if (verbosity > 0) {
01544 std::cout << "FP420Test: END OF Event " << (*evt)()->GetEventID() << std::endl;
01545 }
01546
01547 }
01548
01549