30 #include "G4SDManager.hh"
33 #include "G4VProcess.hh"
34 #include "G4HCofThisEvent.hh"
35 #include "G4UserEventAction.hh"
36 #include "G4TransportationManager.hh"
37 #include "G4ProcessManager.hh"
40 #include "CLHEP/Units/GlobalSystemOfUnits.h"
41 #include "CLHEP/Units/GlobalPhysicalConstants.h"
75 std::cout<<
"============================================================================"<<std::endl;
76 std::cout <<
"FP420Testconstructor :: Initialized as observer"<< std::endl;
90 double gapSupplane = 1.6;
91 ZSiPlane=2*zBlade+gapBlade+gapSupplane;
94 ZSiStep=ZSiPlane+ZKapton;
96 double ZBoundDet = 0.020;
97 double ZSiElectr = 0.250;
98 double ZCeramDet = 0.500;
101 ZGapLDet= zBlade/2-(ZSiDet+ZSiElectr+ZBoundDet+ZCeramDet/2);
104 double ZSiStation = (pn0-1)*(2*(zBlade+gapBlade)+ZKapton)+2*6.+0.0;
109 zinibeg = (eee1-eee2)/2.;
111 z1 = zinibeg + (ZSiStation+10.)/2 + z420;
117 fp420eventntuple =
new TNtuple(
"NTfp420event",
"NTfp420event",
"evt");
128 std::cout <<
"FP420Test constructor :: Initialized Fp420AnalysisHistManager"<< std::endl;
137 TFile fp420OutputFile(
"newntfp420.root",
"RECREATE");
138 std::cout <<
"FP420 output root file has been created";
139 fp420eventntuple->Write();
141 fp420OutputFile.Close();
143 delete fp420eventntuple;
144 std::cout <<
", and deleted" << std::endl;
149 TheHistManager->WriteToFile(fOutputFile,fRecreateFile);
151 std::cout << std::endl <<
"FP420Test Destructor --------> End of FP420Test : "
155 std::cout<<
"FP420Test: End of process"<<std::endl;
169 fTypeTitle=managername;
170 fHistArray =
new TObjArray();
171 fHistNamesArray =
new TObjArray();
173 TH1::AddDirectory(kFALSE);
176 fHistArray->Compress();
177 fHistNamesArray->Compress();
189 fHistArray->Delete();
194 fHistNamesArray->Delete();
195 delete fHistNamesArray;
203 HistInit(
"PrimaryEta",
"Primary Eta", 100, 9., 12. );
204 HistInit(
"PrimaryPhigrad",
"Primary Phigrad", 100, 0.,360. );
205 HistInit(
"PrimaryTh",
"Primary Th", 100, 0.,180. );
206 HistInit(
"PrimaryLastpoZ",
"Primary Lastpo Z", 100, -200.,430000. );
207 HistInit(
"PrimaryLastpoX",
"Primary Lastpo X Z<z4", 100, -30., 30. );
208 HistInit(
"PrimaryLastpoY",
"Primary Lastpo Y Z<z4", 100, -30., 30. );
209 HistInit(
"XLastpoNumofpart",
"Primary Lastpo X n>10", 100, -30., 30. );
210 HistInit(
"YLastpoNumofpart",
"Primary Lastpo Y n>10", 100, -30., 30. );
211 HistInit(
"VtxX",
"Vtx X", 100, -50., 50. );
212 HistInit(
"VtxY",
"Vtx Y", 100, -50., 50. );
213 HistInit(
"VtxZ",
"Vtx Z", 100, -200.,430000. );
215 HistInit(
"SumEDep",
"This is sum Energy deposited", 100, -1, 199.);
216 HistInit(
"TrackL",
"This is TrackL", 100, 0., 12000.);
217 HistInit(
"zHits",
"z Hits all events", 100, 400000.,430000. );
218 HistInit(
"zHitsnoMI",
"z Hits no MI", 100, 400000.,430000. );
219 HistInit(
"zHitsTrLoLe",
"z Hits TrLength bigger 8300",100, 400000.,430000. );
220 HistInit(
"NumberOfHits",
"NumberOfHits",100, 0.,300. );
230 std::cout <<
"================================================================"<<std::endl;
231 std::cout <<
" Write this Analysis to File "<<fOutputFile<<std::endl;
232 std::cout <<
"================================================================"<<std::endl;
234 TFile*
file =
new TFile(fOutputFile, fRecreateFile);
245 char* newtitle =
new char[strlen(title)+strlen(fTypeTitle)+5];
246 strcpy(newtitle,title);
247 strcat(newtitle,
" (");
248 strcat(newtitle,fTypeTitle);
249 strcat(newtitle,
") ");
250 fHistArray->AddLast((
new TH1F(name, newtitle, nbinsx, xlow, xup)));
251 fHistNamesArray->AddLast(
new TObjString(name));
260 char* newtitle =
new char[strlen(title)+strlen(fTypeTitle)+5];
261 strcpy(newtitle,title);
262 strcat(newtitle,
" (");
263 strcat(newtitle,fTypeTitle);
264 strcat(newtitle,
") ");
265 fHistArray->AddLast((
new TH2F(name, newtitle, nbinsx, xlow, xup, nbinsy, ylow, yup)));
266 fHistNamesArray->AddLast(
new TObjString(name));
275 if (Number <= fHistArray->GetLast() && fHistArray->At(Number) != (TObject*)0){
277 return (TH1F*)(fHistArray->At(Number));
281 std::cout <<
"!!!!!!!!!!!!!!!!!!GetHisto!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
282 std::cout <<
" WARNING ERROR - HIST ID INCORRECT (TOO HIGH) - " << Number << std::endl;
283 std::cout <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
285 return (TH1F*)(fHistArray->At(0));
294 if (Number <= fHistArray->GetLast() && fHistArray->At(Number) != (TObject*)0){
296 return (TH2F*)(fHistArray->At(Number));
300 std::cout <<
"!!!!!!!!!!!!!!!!GetHisto2!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
301 std::cout <<
" WARNING ERROR - HIST ID INCORRECT (TOO HIGH) - " << Number << std::endl;
302 std::cout <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
304 return (TH2F*)(fHistArray->At(0));
313 Int_t
index = fHistNamesArray->IndexOf(&histname);
314 return GetHisto(index);
322 Int_t
index = fHistNamesArray->IndexOf(&histname);
323 return GetHisto2(index);
331 for(
int i = 0;
i < fHistArray->GetEntries();
i++){
332 ((TH1F*)(fHistArray->At(
i)))->Sumw2();
405 std::cout<<
"FP420Test:beggining of job"<<std::endl;;
413 std::cout << std::endl <<
"FP420Test:: Begining of Run"<< std::endl;
423 iev = (*evt)()->GetEventID();
425 std::cout <<
"FP420Test:update Event number = " << iev << std::endl;
432 itrk = (*trk)()->GetTrackID();
434 std::cout <<
"FP420Test:update BeginOfTrack number = " << itrk << std::endl;
449 itrk = (*trk)()->GetTrackID();
451 std::cout <<
"FP420Test:update EndOfTrack number = " << itrk << std::endl;
454 G4double tracklength = (*trk)()->GetTrackLength();
456 TheHistManager->GetHisto(
"SumEDep")->Fill(SumEnerDeposit);
457 TheHistManager->GetHisto(
"TrackL")->Fill(tracklength);
460 G4ThreeVector vert_mom = (*trk)()->GetVertexMomentumDirection();
461 G4ThreeVector vert_pos = (*trk)()->GetVertexPosition();
464 float phi = atan2(vert_mom.y(),vert_mom.x());
465 if (phi < 0.) phi += twopi;
490 if(tracklength < z4) {
498 const G4Step* aStep = (*trk)()->GetStep();
502 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
503 lastpo = preStepPoint->GetPosition();
506 if(lastpo.z()<z1 && lastpo.perp()< 100.) {
512 if((lastpo.z()>z1 && lastpo.z()<z2) && lastpo.perp()< 100.) {
518 if(lastpo.z()<z2 && lastpo.perp()< 100.) {
527 if(lastpo.z()<z3 && lastpo.perp()< 100.) {
533 if(lastpo.z()<z4 && lastpo.perp()< 100.) {
562 G4int stepnumber = aStep->GetTrack()->GetCurrentStepNumber();
563 std::cout <<
"FP420Test:update Step number = " << stepnumber << std::endl;
566 G4Track* theTrack = aStep->GetTrack();
569 std::cout <<
"FP420Test on aStep: No trk info !!!! abort " << std::endl;
572 G4int
id = theTrack->GetTrackID();
573 G4String
particleType = theTrack->GetDefinition()->GetParticleName();
574 G4int parentID = theTrack->GetParentID();
575 G4TrackStatus trackstatus = theTrack->GetTrackStatus();
576 G4double tracklength = theTrack->GetTrackLength();
577 G4ThreeVector trackmom = theTrack->GetMomentum();
578 G4double entot = theTrack->GetTotalEnergy();
579 G4int curstepnumber = theTrack->GetCurrentStepNumber();
580 G4ThreeVector vert_pos = theTrack->GetVertexPosition();
581 G4ThreeVector vert_mom = theTrack->GetVertexMomentumDirection();
597 G4double stepl = aStep->GetStepLength();
598 G4double EnerDeposit = aStep->GetTotalEnergyDeposit();
606 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
607 G4ThreeVector preposition = preStepPoint->GetPosition();
608 G4ThreeVector prelocalpoint = theTrack->GetTouchable()->GetHistory()->
609 GetTopTransform().TransformPoint(preposition);
610 G4VPhysicalVolume* currentPV = preStepPoint->GetPhysicalVolume();
611 G4String prename = currentPV->GetName();
613 const G4VTouchable* pre_touch = preStepPoint->GetTouchable();
614 int pre_levels = detLevels(pre_touch);
619 G4String name1[20];
int copyno1[20];
620 if (pre_levels > 0) {
621 detectorLevel(pre_touch, pre_levels, copyno1, name1);
677 if (curstepnumber == 1 ) {
686 if(prename ==
"SBST" ) {
692 if(prename ==
"SBSTs" ) {
700 if (trackstatus != 2 ) {
702 if(prename ==
"SIDETL" || prename ==
"SIDETR" ) {
703 if(prename ==
"SIDETL") {
706 if(prename ==
"SIDETR") {
731 G4String posname = aStep->GetPostStepPoint()->GetPhysicalVolume()->GetName();
732 if((prename ==
"SIDETL" && posname !=
"SIDETL") || (prename ==
"SIDETR" && posname !=
"SIDETR")) {
733 if(name1[2] ==
"SISTATION" ) {
736 if(name1[3] ==
"SIPLANE" ) {
740 if(prename ==
"SIDETL") {
746 else if(copyno1[2]<3) {
750 else if(copyno1[3]<3) {
753 else if(copyno1[3]<4) {
756 else if(copyno1[3]<5) {
759 else if(copyno1[3]<6) {
762 else if(copyno1[3]<7) {
765 else if(copyno1[3]<8) {
768 else if(copyno1[3]<9) {
771 else if(copyno1[3]<10) {
775 else if(copyno1[2]<4) {
778 else if(copyno1[2]<5) {
782 if(prename ==
"SIDETR") {
788 else if(copyno1[2]<3) {
792 else if(copyno1[3]<3) {
795 else if(copyno1[3]<4) {
798 else if(copyno1[3]<5) {
801 else if(copyno1[3]<6) {
804 else if(copyno1[3]<7) {
807 else if(copyno1[3]<8) {
810 else if(copyno1[3]<9) {
813 else if(copyno1[3]<10) {
817 else if(copyno1[2]<4) {
820 else if(copyno1[2]<5) {
835 SumEnerDeposit += EnerDeposit;
852 if (trackstatus == 2 ) {
855 tracklength0 = tracklength;
866 if (parentID == 1 && curstepnumber == 1) {
884 if(prename ==
"SBST" ) {
887 if(prename ==
"SBSTs" ) {
903 return ((touch->GetHistoryDepth())+1);
910 int currentlevel)
const {
913 if (level > 0 && level >= currentlevel) {
914 int ii = level - currentlevel;
915 return touch->GetVolume(ii)->GetName();
922 int* copyno, G4String*
name)
const {
927 int i = level -
ii - 1;
928 G4VPhysicalVolume*
pv = touch->GetVolume(i);
930 name[
ii] = pv->GetName();
932 name[
ii] =
"Unknown";
933 copyno[
ii] = touch->GetReplicaNumber(i);
944 iev = (*evt)()->GetEventID();
945 std::cout <<
"FP420Test:update EndOfEvent = " << iev << std::endl;
952 G4PrimaryParticle* thePrim=0;
956 G4int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
958 std::cout <<
"FP420Test: My warning: NumberOfPrimaryVertex != 1 --> = " << nvertex << std::endl;
960 for (
int i = 0 ;
i<nvertex;
i++) {
961 G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(
i);
963 std::cout <<
"FP420Test End Of Event ERR: pointer to vertex = 0"
965 G4int
npart = avertex->GetNumberOfParticle();
967 std::cout <<
"FP420Test: My warning: NumberOfPrimaryPart != 1 --> = " << npart << std::endl;
969 std::cout <<
"FP420Test End Of Event ERR: no NumberOfParticle" << std::endl;
972 if (thePrim==0) thePrim=avertex->GetPrimary(trackID);
976 G4double vx=0.,vy=0.,vz=0.;
977 vx = avertex->GetX0();
978 vy = avertex->GetY0();
979 vz = avertex->GetZ0();
983 TheHistManager->GetHisto(
"VtxX")->Fill(vx);
984 TheHistManager->GetHisto(
"VtxY")->Fill(vy);
985 TheHistManager->GetHisto(
"VtxZ")->Fill(vz);
1007 if(lastpo.z()<z4 && lastpo.perp()< 100.) {
1013 G4ThreeVector mom = thePrim->GetMomentum();
1015 double phi = atan2(mom.y(),mom.x());
1016 if (phi < 0.) phi += twopi;
1017 double phigrad = phi*180./
pi;
1019 double th = mom.theta();
1033 TheHistManager->GetHisto(
"PrimaryEta")->Fill(eta);
1034 TheHistManager->GetHisto(
"PrimaryPhigrad")->Fill(phigrad);
1035 TheHistManager->GetHisto(
"PrimaryTh")->Fill(th*180./
pi);
1037 TheHistManager->GetHisto(
"PrimaryLastpoZ")->Fill(lastpo.z());
1038 if(lastpo.z() < z4 ) {
1039 TheHistManager->GetHisto(
"PrimaryLastpoX")->Fill(lastpo.x());
1040 TheHistManager->GetHisto(
"PrimaryLastpoY")->Fill(lastpo.y());
1042 if(numofpart > 4 ) {
1043 TheHistManager->GetHisto(
"XLastpoNumofpart")->Fill(lastpo.x());
1044 TheHistManager->GetHisto(
"YLastpoNumofpart")->Fill(lastpo.y());
1052 map<int,float,less<int> > themap;
1053 map<int,float,less<int> > themap1;
1055 map<int,float,less<int> > themapxy;
1056 map<int,float,less<int> > themapz;
1060 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
1063 std::cout <<
"FP420Test: accessed all HC" << std::endl;;
1065 int CAFIid = G4SDManager::GetSDMpointer()->GetCollectionID(
"FP420SI");
1073 std::cout <<
"FP420Test: theCAFI->entries = " << theCAFI->entries() << std::endl;
1076 TheHistManager->GetHisto(
"NumberOfHits")->Fill(theCAFI->entries());
1095 if( lastpo.z()< z4) {
1108 for (
int j=0;
j<theCAFI->entries();
j++) {
1110 G4ThreeVector hitPoint = aHit->
getEntry();
1111 double zz = hitPoint.z();
1112 TheHistManager->GetHisto(
"zHits")->Fill(zz);
1113 if(tracklength0>8300.) TheHistManager->GetHisto(
"zHitsTrLoLe")->Fill(zz);
1125 int nhit11 = 0, nhit12 = 0, nhit13 = 0 ;
1126 double totallosenergy= 0.;
1127 for (
int j=0;
j<theCAFI->entries();
j++) {
1132 G4ThreeVector hitPoint = aHit->
getEntry();
1137 unsigned int unitID = aHit->
getUnitID();
1157 double phi_hit = hitPoint.phi();
1158 if (phi_hit < 0.) phi_hit += twopi;
1167 double zz = hitPoint.z();
1169 TheHistManager->GetHisto(
"zHitsnoMI")->Fill(zz);
1172 std::cout <<
"FP420Test:zHits = " << zz << std::endl;
1183 themap[unitID] += losenergy;
1184 totallosenergy += losenergy;
1186 int det,
zside, sector, zmodule;
1190 if(justlayer<1||justlayer>2) {
1191 std::cout <<
"FP420Test:WRONG justlayer= " << justlayer << std::endl;
1206 G4ThreeVector middle = (hitExitLocalPoint-hitEntryLocalPoint)/2.;
1207 themapz[unitID] = hitPoint.z()+fabs(middle.z());
1209 std::cout <<
"1111111111111111111111111111111111111111111111111111111111111111111111111 " << std::endl;
1210 std::cout <<
"FP420Test: det, zside, sector, zmodule = " << det << zside << sector << zmodule << std::endl;
1211 std::cout <<
"FP420Test: justlayer = " << justlayer << std::endl;
1212 std::cout <<
"FP420Test: hitExitLocalPoint = " << hitExitLocalPoint << std::endl;
1213 std::cout <<
"FP420Test: hitEntryLocalPoint = " << hitEntryLocalPoint << std::endl;
1214 std::cout <<
"FP420Test: middle= " << middle << std::endl;
1215 std::cout <<
"FP420Test: hitPoint.z()-419000.= " << hitPoint.z()-419000. << std::endl;
1217 std::cout <<
"FP420Test:zHits-419000. = " << themapz[unitID]-419000. << std::endl;
1223 if(losenergy > 0.00003) {
1224 themap1[unitID] += 1.;
1230 if(losenergy > 0.00005) {
1231 themap1[unitID] += 1.;
1271 if(lastpo.z()<z4 && lastpo.perp()< 120.) {
1281 if( zz < z3 && zz > z2){
1286 if( zz < z4 && zz > z3){
1310 if(trackIDhit == 1){
1320 if( zz < z3 && zz > z2){
1333 if(trackIDhit == 1){
1342 if( zz < z4 && zz > z3){
1373 std::cout <<
"22222222222222222222222222222222222222222222222222222222222222222222222222 " << std::endl;
1376 int allplacesforsensors=7;
1377 for (
int sector=1; sector < sn0; sector++) {
1378 for (
int zmodule=1; zmodule<pn0; zmodule++) {
1379 for (
int zsideinorder=1; zsideinorder<allplacesforsensors; zsideinorder++) {
1382 std::cout <<
"FP420Test: sector= " << sector <<
" zmodule= " << zmodule <<
" zsideinorder= " << zsideinorder <<
" zside= " << zside << std::endl;
1386 if(justlayer<1||justlayer>2) {
1387 std::cout <<
"FP420Test:WRONG justlayer= " << justlayer << std::endl;
1390 if(copyinlayer<1||copyinlayer>3) {
1391 std::cout <<
"FP420Test:WRONG copyinlayer= " << copyinlayer << std::endl;
1394 if(orientation<1||orientation>2) {
1395 std::cout <<
"FP420Test:WRONG orientation= " << orientation << std::endl;
1404 std::cout <<
"FP420Test: justlayer = " << justlayer <<
" copyinlayer = " << copyinlayer <<
" orientation = " << orientation <<
" ii= " << ii << std::endl;
1406 double zdiststat = 0.;
1408 if(sector==2) zdiststat = zD3;
1411 if(sector==2) zdiststat = zD2;
1412 if(sector==3) zdiststat = zD3;
1414 double kplane = -(pn0-1)/2 - 0.5 + (zmodule-1);
1415 double zcurrent = zinibeg + z420 + (ZSiStep-ZSiPlane)/2 + kplane*ZSiStep + zdiststat;
1418 std::cout <<
"FP420Test: Leftzcurrent-419000. = " << zcurrent-419000. << std::endl;
1419 std::cout <<
"FP420Test: ZGapLDet = " << ZGapLDet << std::endl;
1422 if(orientation==1) zcurrent += (ZGapLDet+ZSiDet/2);
1423 if(orientation==2) zcurrent += zBlade-(ZGapLDet+ZSiDet/2);
1426 if(orientation==1) zcurrent += (ZGapLDet+ZSiDet/2)+zBlade+gapBlade;
1427 if(orientation==2) zcurrent += 2*zBlade+gapBlade-(ZGapLDet+ZSiDet/2);
1431 if(det == 2) zcurrent = -zcurrent;
1434 std::cout <<
"FP420Test: zcurrent-419000. = " << zcurrent-419000. << std::endl;
1444 std::cout <<
"----------------------------------------------------------------------------- " << std::endl;
1450 if(totallosenergy == 0.0) {
1451 std::cout <<
"FP420Test: number of hits = " << theCAFI->entries() << std::endl;
1452 for (
int j=0;
j<theCAFI->entries();
j++) {
1455 std::cout <<
" j hits = " <<
j <<
"losenergy = " << losenergy << std::endl;
1465 double totalEnergy = 0.;
1466 int nhitsX = 0, nhitsY = 0, nsumhit = 0 ;
1467 for (
int sector=1; sector<4; sector++) {
1468 int nhitsecX = 0, nhitsecY = 0;
1469 for (
int zmodule=1; zmodule<11; zmodule++) {
1475 double theTotalEnergy = themap[
index];
1479 if(theTotalEnergy > 0.00003) {
1488 if(theTotalEnergy > 0.00005) {
1501 totalEnergy += themap[
index];
1505 if(nhitsecX > 10 || nhitsecY > 10) {
1543 std::cout <<
"FP420Test: END OF Event " << (*evt)()->GetEventID() << std::endl;
static int unpackCopyIndex(int rn0, int zside)
G4String detName(const G4VTouchable *, int, int) const
T getParameter(std::string const &) const
~Fp420AnalysisHistManager()
void HistInit(const char *name, const char *title, Int_t nbinsx, Axis_t xlow, Axis_t xup)
G4ThreeVector getExitLocalP() const
static int realzside(int rn0, int zsideinorder)
static void unpackFP420Index(const unsigned int &idx, int &det, int &zside, int &station, int &superplane)
FP420Test(const edm::ParameterSet &p)
static int unpackLayerIndex(int rn0, int zside)
void WriteToFile(const TString &fOutputFile, const TString &fRecreateFile)
unsigned int getTrackID() const
void update(const BeginOfJob *run)
This routine will be called when the appropriate signal arrives.
unsigned int getUnitID() const
static unsigned packMYIndex(int rn0, int pn0, int sn0, int det, int zside, int sector, int zmodule)
Fp420AnalysisHistManager(const TString &managername)
Tan< T >::type tan(const T &t)
TH2F * GetHisto2(Int_t Number)
G4ThreeVector getEntryLocalP() const
static unsigned int packFP420Index(int det, int zside, int station, int superplane)
float getEnergyLoss() const
G4THitsCollection< FP420G4Hit > FP420G4HitCollection
Geom::Phi< T > phi() const
int detLevels(const G4VTouchable *) const
TH1F * GetHisto(Int_t Number)
void detectorLevel(const G4VTouchable *, int &, int *, G4String *) const
G4ThreeVector getEntry() const
static int unpackOrientation(int rn0, int zside)