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 : " << std::endl;
154 std::cout<<
"FP420Test: End of process"<<std::endl;
168 fTypeTitle=managername;
169 fHistArray =
new TObjArray();
170 fHistNamesArray =
new TObjArray();
172 TH1::AddDirectory(kFALSE);
175 fHistArray->Compress();
176 fHistNamesArray->Compress();
188 fHistArray->Delete();
193 fHistNamesArray->Delete();
194 delete fHistNamesArray;
202 HistInit(
"PrimaryEta",
"Primary Eta", 100, 9., 12. );
203 HistInit(
"PrimaryPhigrad",
"Primary Phigrad", 100, 0.,360. );
204 HistInit(
"PrimaryTh",
"Primary Th", 100, 0.,180. );
205 HistInit(
"PrimaryLastpoZ",
"Primary Lastpo Z", 100, -200.,430000. );
206 HistInit(
"PrimaryLastpoX",
"Primary Lastpo X Z<z4", 100, -30., 30. );
207 HistInit(
"PrimaryLastpoY",
"Primary Lastpo Y Z<z4", 100, -30., 30. );
208 HistInit(
"XLastpoNumofpart",
"Primary Lastpo X n>10", 100, -30., 30. );
209 HistInit(
"YLastpoNumofpart",
"Primary Lastpo Y n>10", 100, -30., 30. );
210 HistInit(
"VtxX",
"Vtx X", 100, -50., 50. );
211 HistInit(
"VtxY",
"Vtx Y", 100, -50., 50. );
212 HistInit(
"VtxZ",
"Vtx Z", 100, -200.,430000. );
214 HistInit(
"SumEDep",
"This is sum Energy deposited", 100, -1, 199.);
215 HistInit(
"TrackL",
"This is TrackL", 100, 0., 12000.);
216 HistInit(
"zHits",
"z Hits all events", 100, 400000.,430000. );
217 HistInit(
"zHitsnoMI",
"z Hits no MI", 100, 400000.,430000. );
218 HistInit(
"zHitsTrLoLe",
"z Hits TrLength bigger 8300",100, 400000.,430000. );
219 HistInit(
"NumberOfHits",
"NumberOfHits",100, 0.,300. );
229 std::cout <<
"================================================================"<<std::endl;
230 std::cout <<
" Write this Analysis to File "<<fOutputFile<<std::endl;
231 std::cout <<
"================================================================"<<std::endl;
233 TFile*
file =
new TFile(fOutputFile, fRecreateFile);
244 char* newtitle =
new char[strlen(title)+strlen(fTypeTitle)+5];
245 strcpy(newtitle,title);
246 strcat(newtitle,
" (");
247 strcat(newtitle,fTypeTitle);
248 strcat(newtitle,
") ");
249 fHistArray->AddLast((
new TH1F(name, newtitle, nbinsx, xlow, xup)));
250 fHistNamesArray->AddLast(
new TObjString(name));
259 char* newtitle =
new char[strlen(title)+strlen(fTypeTitle)+5];
260 strcpy(newtitle,title);
261 strcat(newtitle,
" (");
262 strcat(newtitle,fTypeTitle);
263 strcat(newtitle,
") ");
264 fHistArray->AddLast((
new TH2F(name, newtitle, nbinsx, xlow, xup, nbinsy, ylow, yup)));
265 fHistNamesArray->AddLast(
new TObjString(name));
274 if (Number <= fHistArray->GetLast() && fHistArray->At(Number) != (TObject*)0){
276 return (TH1F*)(fHistArray->At(Number));
280 std::cout <<
"!!!!!!!!!!!!!!!!!!GetHisto!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
281 std::cout <<
" WARNING ERROR - HIST ID INCORRECT (TOO HIGH) - " << Number << std::endl;
282 std::cout <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
284 return (TH1F*)(fHistArray->At(0));
293 if (Number <= fHistArray->GetLast() && fHistArray->At(Number) != (TObject*)0){
295 return (TH2F*)(fHistArray->At(Number));
299 std::cout <<
"!!!!!!!!!!!!!!!!GetHisto2!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
300 std::cout <<
" WARNING ERROR - HIST ID INCORRECT (TOO HIGH) - " << Number << std::endl;
301 std::cout <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
303 return (TH2F*)(fHistArray->At(0));
312 Int_t
index = fHistNamesArray->IndexOf(&histname);
313 return GetHisto(index);
321 Int_t
index = fHistNamesArray->IndexOf(&histname);
322 return GetHisto2(index);
330 for(
int i = 0;
i < fHistArray->GetEntries();
i++){
331 ((TH1F*)(fHistArray->At(
i)))->Sumw2();
404 std::cout<<
"FP420Test:beggining of job"<<std::endl;;
412 std::cout << std::endl <<
"FP420Test:: Begining of Run"<< std::endl;
422 iev = (*evt)()->GetEventID();
424 std::cout <<
"FP420Test:update Event number = " << iev << std::endl;
431 itrk = (*trk)()->GetTrackID();
433 std::cout <<
"FP420Test:update BeginOfTrack number = " << itrk << std::endl;
448 itrk = (*trk)()->GetTrackID();
450 std::cout <<
"FP420Test:update EndOfTrack number = " << itrk << std::endl;
453 G4double tracklength = (*trk)()->GetTrackLength();
455 TheHistManager->GetHisto(
"SumEDep")->Fill(SumEnerDeposit);
456 TheHistManager->GetHisto(
"TrackL")->Fill(tracklength);
459 G4ThreeVector vert_mom = (*trk)()->GetVertexMomentumDirection();
460 G4ThreeVector vert_pos = (*trk)()->GetVertexPosition();
489 if(tracklength < z4) {
497 const G4Step* aStep = (*trk)()->GetStep();
501 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
502 lastpo = preStepPoint->GetPosition();
505 if(lastpo.z()<z1 && lastpo.perp()< 100.) {
511 if((lastpo.z()>z1 && lastpo.z()<z2) && lastpo.perp()< 100.) {
517 if(lastpo.z()<z2 && lastpo.perp()< 100.) {
526 if(lastpo.z()<z3 && lastpo.perp()< 100.) {
532 if(lastpo.z()<z4 && lastpo.perp()< 100.) {
561 G4int stepnumber = aStep->GetTrack()->GetCurrentStepNumber();
562 std::cout <<
"FP420Test:update Step number = " << stepnumber << std::endl;
565 G4Track* theTrack = aStep->GetTrack();
568 std::cout <<
"FP420Test on aStep: No trk info !!!! abort " << std::endl;
571 G4int
id = theTrack->GetTrackID();
572 G4String
particleType = theTrack->GetDefinition()->GetParticleName();
573 G4int parentID = theTrack->GetParentID();
574 G4TrackStatus trackstatus = theTrack->GetTrackStatus();
575 G4double tracklength = theTrack->GetTrackLength();
576 G4ThreeVector trackmom = theTrack->GetMomentum();
577 G4double entot = theTrack->GetTotalEnergy();
578 G4int curstepnumber = theTrack->GetCurrentStepNumber();
579 G4ThreeVector vert_pos = theTrack->GetVertexPosition();
580 G4ThreeVector vert_mom = theTrack->GetVertexMomentumDirection();
596 G4double stepl = aStep->GetStepLength();
597 G4double EnerDeposit = aStep->GetTotalEnergyDeposit();
605 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
606 G4ThreeVector preposition = preStepPoint->GetPosition();
607 G4ThreeVector prelocalpoint = theTrack->GetTouchable()->GetHistory()->
608 GetTopTransform().TransformPoint(preposition);
609 G4VPhysicalVolume* currentPV = preStepPoint->GetPhysicalVolume();
610 G4String prename = currentPV->GetName();
612 const G4VTouchable* pre_touch = preStepPoint->GetTouchable();
613 int pre_levels = detLevels(pre_touch);
618 G4String name1[20];
int copyno1[20];
619 if (pre_levels > 0) {
620 detectorLevel(pre_touch, pre_levels, copyno1, name1);
676 if (curstepnumber == 1 ) {
685 if(prename ==
"SBST" ) {
691 if(prename ==
"SBSTs" ) {
699 if (trackstatus != 2 ) {
701 if(prename ==
"SIDETL" || prename ==
"SIDETR" ) {
702 if(prename ==
"SIDETL") {
705 if(prename ==
"SIDETR") {
730 G4String posname = aStep->GetPostStepPoint()->GetPhysicalVolume()->GetName();
731 if((prename ==
"SIDETL" && posname !=
"SIDETL") || (prename ==
"SIDETR" && posname !=
"SIDETR")) {
732 if(name1[2] ==
"SISTATION" ) {
735 if(name1[3] ==
"SIPLANE" ) {
739 if(prename ==
"SIDETL") {
745 else if(copyno1[2]<3) {
749 else if(copyno1[3]<3) {
752 else if(copyno1[3]<4) {
755 else if(copyno1[3]<5) {
758 else if(copyno1[3]<6) {
761 else if(copyno1[3]<7) {
764 else if(copyno1[3]<8) {
767 else if(copyno1[3]<9) {
770 else if(copyno1[3]<10) {
774 else if(copyno1[2]<4) {
777 else if(copyno1[2]<5) {
781 if(prename ==
"SIDETR") {
787 else if(copyno1[2]<3) {
791 else if(copyno1[3]<3) {
794 else if(copyno1[3]<4) {
797 else if(copyno1[3]<5) {
800 else if(copyno1[3]<6) {
803 else if(copyno1[3]<7) {
806 else if(copyno1[3]<8) {
809 else if(copyno1[3]<9) {
812 else if(copyno1[3]<10) {
816 else if(copyno1[2]<4) {
819 else if(copyno1[2]<5) {
834 SumEnerDeposit += EnerDeposit;
851 if (trackstatus == 2 ) {
854 tracklength0 = tracklength;
865 if (parentID == 1 && curstepnumber == 1) {
883 if(prename ==
"SBST" ) {
886 if(prename ==
"SBSTs" ) {
902 return ((touch->GetHistoryDepth())+1);
909 int currentlevel)
const {
912 if (level > 0 && level >= currentlevel) {
913 int ii = level - currentlevel;
914 return touch->GetVolume(ii)->GetName();
921 int* copyno, G4String*
name)
const {
926 int i = level -
ii - 1;
927 G4VPhysicalVolume*
pv = touch->GetVolume(i);
929 name[
ii] = pv->GetName();
931 name[
ii] =
"Unknown";
932 copyno[
ii] = touch->GetReplicaNumber(i);
943 iev = (*evt)()->GetEventID();
944 std::cout <<
"FP420Test:update EndOfEvent = " << iev << std::endl;
951 G4PrimaryParticle* thePrim=0;
955 G4int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
957 std::cout <<
"FP420Test: My warning: NumberOfPrimaryVertex != 1 --> = " << nvertex << std::endl;
959 for (
int i = 0 ;
i<nvertex;
i++) {
960 G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(
i);
962 std::cout <<
"FP420Test End Of Event ERR: pointer to vertex = 0"
964 G4int
npart = avertex->GetNumberOfParticle();
966 std::cout <<
"FP420Test: My warning: NumberOfPrimaryPart != 1 --> = " << npart << std::endl;
968 std::cout <<
"FP420Test End Of Event ERR: no NumberOfParticle" << std::endl;
971 if (thePrim==0) thePrim=avertex->GetPrimary(trackID);
975 G4double vx=0.,vy=0.,vz=0.;
976 vx = avertex->GetX0();
977 vy = avertex->GetY0();
978 vz = avertex->GetZ0();
982 TheHistManager->GetHisto(
"VtxX")->Fill(vx);
983 TheHistManager->GetHisto(
"VtxY")->Fill(vy);
984 TheHistManager->GetHisto(
"VtxZ")->Fill(vz);
1006 if(lastpo.z()<z4 && lastpo.perp()< 100.) {
1012 G4ThreeVector mom = thePrim->GetMomentum();
1014 double phi = atan2(mom.y(),mom.x());
1015 if (phi < 0.) phi += twopi;
1016 double phigrad = phi*180./
pi;
1018 double th = mom.theta();
1032 TheHistManager->GetHisto(
"PrimaryEta")->Fill(eta);
1033 TheHistManager->GetHisto(
"PrimaryPhigrad")->Fill(phigrad);
1034 TheHistManager->GetHisto(
"PrimaryTh")->Fill(th*180./
pi);
1036 TheHistManager->GetHisto(
"PrimaryLastpoZ")->Fill(lastpo.z());
1037 if(lastpo.z() < z4 ) {
1038 TheHistManager->GetHisto(
"PrimaryLastpoX")->Fill(lastpo.x());
1039 TheHistManager->GetHisto(
"PrimaryLastpoY")->Fill(lastpo.y());
1041 if(numofpart > 4 ) {
1042 TheHistManager->GetHisto(
"XLastpoNumofpart")->Fill(lastpo.x());
1043 TheHistManager->GetHisto(
"YLastpoNumofpart")->Fill(lastpo.y());
1051 map<int,float,less<int> > themap;
1052 map<int,float,less<int> > themap1;
1054 map<int,float,less<int> > themapxy;
1055 map<int,float,less<int> > themapz;
1059 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
1062 std::cout <<
"FP420Test: accessed all HC" << std::endl;;
1064 int CAFIid = G4SDManager::GetSDMpointer()->GetCollectionID(
"FP420SI");
1072 std::cout <<
"FP420Test: theCAFI->entries = " << theCAFI->entries() << std::endl;
1075 TheHistManager->GetHisto(
"NumberOfHits")->Fill(theCAFI->entries());
1093 if( lastpo.z()< z4) {
1106 for (
int j=0;
j<theCAFI->entries();
j++) {
1108 G4ThreeVector hitPoint = aHit->
getEntry();
1109 double zz = hitPoint.z();
1110 TheHistManager->GetHisto(
"zHits")->Fill(zz);
1111 if(tracklength0>8300.) TheHistManager->GetHisto(
"zHitsTrLoLe")->Fill(zz);
1123 int nhit11 = 0, nhit12 = 0, nhit13 = 0 ;
1124 double totallosenergy= 0.;
1125 for (
int j=0;
j<theCAFI->entries();
j++) {
1130 G4ThreeVector hitPoint = aHit->
getEntry();
1135 unsigned int unitID = aHit->
getUnitID();
1165 double zz = hitPoint.z();
1167 TheHistManager->GetHisto(
"zHitsnoMI")->Fill(zz);
1170 std::cout <<
"FP420Test:zHits = " << zz << std::endl;
1181 themap[unitID] += losenergy;
1182 totallosenergy += losenergy;
1184 int det,
zside, sector, zmodule;
1188 if(justlayer<1||justlayer>2) {
1189 std::cout <<
"FP420Test:WRONG justlayer= " << justlayer << std::endl;
1204 G4ThreeVector middle = (hitExitLocalPoint-hitEntryLocalPoint)/2.;
1205 themapz[unitID] = hitPoint.z()+fabs(middle.z());
1207 std::cout <<
"1111111111111111111111111111111111111111111111111111111111111111111111111 " << std::endl;
1208 std::cout <<
"FP420Test: det, zside, sector, zmodule = " << det << zside << sector << zmodule << std::endl;
1209 std::cout <<
"FP420Test: justlayer = " << justlayer << std::endl;
1210 std::cout <<
"FP420Test: hitExitLocalPoint = " << hitExitLocalPoint << std::endl;
1211 std::cout <<
"FP420Test: hitEntryLocalPoint = " << hitEntryLocalPoint << std::endl;
1212 std::cout <<
"FP420Test: middle= " << middle << std::endl;
1213 std::cout <<
"FP420Test: hitPoint.z()-419000.= " << hitPoint.z()-419000. << std::endl;
1215 std::cout <<
"FP420Test:zHits-419000. = " << themapz[unitID]-419000. << std::endl;
1221 if(losenergy > 0.00003) {
1222 themap1[unitID] += 1.;
1228 if(losenergy > 0.00005) {
1229 themap1[unitID] += 1.;
1269 if(lastpo.z()<z4 && lastpo.perp()< 120.) {
1279 if( zz < z3 && zz > z2){
1284 if( zz < z4 && zz > z3){
1308 if(trackIDhit == 1){
1318 if( zz < z3 && zz > z2){
1331 if(trackIDhit == 1){
1340 if( zz < z4 && zz > z3){
1371 std::cout <<
"22222222222222222222222222222222222222222222222222222222222222222222222222 " << std::endl;
1374 int allplacesforsensors=7;
1375 for (
int sector=1; sector < sn0; sector++) {
1376 for (
int zmodule=1; zmodule<pn0; zmodule++) {
1377 for (
int zsideinorder=1; zsideinorder<allplacesforsensors; zsideinorder++) {
1380 std::cout <<
"FP420Test: sector= " << sector <<
" zmodule= " << zmodule <<
" zsideinorder= " << zsideinorder <<
" zside= " << zside << std::endl;
1384 if(justlayer<1||justlayer>2) {
1385 std::cout <<
"FP420Test:WRONG justlayer= " << justlayer << std::endl;
1388 if(copyinlayer<1||copyinlayer>3) {
1389 std::cout <<
"FP420Test:WRONG copyinlayer= " << copyinlayer << std::endl;
1392 if(orientation<1||orientation>2) {
1393 std::cout <<
"FP420Test:WRONG orientation= " << orientation << std::endl;
1402 std::cout <<
"FP420Test: justlayer = " << justlayer <<
" copyinlayer = " << copyinlayer <<
" orientation = " << orientation <<
" ii= " << ii << std::endl;
1404 double zdiststat = 0.;
1406 if(sector==2) zdiststat = zD3;
1409 if(sector==2) zdiststat = zD2;
1410 if(sector==3) zdiststat = zD3;
1412 double kplane = -(pn0-1)/2 - 0.5 + (zmodule-1);
1413 double zcurrent = zinibeg + z420 + (ZSiStep-ZSiPlane)/2 + kplane*ZSiStep + zdiststat;
1416 std::cout <<
"FP420Test: Leftzcurrent-419000. = " << zcurrent-419000. << std::endl;
1417 std::cout <<
"FP420Test: ZGapLDet = " << ZGapLDet << std::endl;
1420 if(orientation==1) zcurrent += (ZGapLDet+ZSiDet/2);
1421 if(orientation==2) zcurrent += zBlade-(ZGapLDet+ZSiDet/2);
1424 if(orientation==1) zcurrent += (ZGapLDet+ZSiDet/2)+zBlade+gapBlade;
1425 if(orientation==2) zcurrent += 2*zBlade+gapBlade-(ZGapLDet+ZSiDet/2);
1429 if(det == 2) zcurrent = -zcurrent;
1432 std::cout <<
"FP420Test: zcurrent-419000. = " << zcurrent-419000. << std::endl;
1442 std::cout <<
"----------------------------------------------------------------------------- " << std::endl;
1448 if(totallosenergy == 0.0) {
1449 std::cout <<
"FP420Test: number of hits = " << theCAFI->entries() << std::endl;
1450 for (
int j=0;
j<theCAFI->entries();
j++) {
1453 std::cout <<
" j hits = " <<
j <<
"losenergy = " << losenergy << std::endl;
1463 double totalEnergy = 0.;
1464 int nhitsX = 0, nhitsY = 0, nsumhit = 0 ;
1465 for (
int sector=1; sector<4; sector++) {
1466 int nhitsecX = 0, nhitsecY = 0;
1467 for (
int zmodule=1; zmodule<11; zmodule++) {
1473 double theTotalEnergy = themap[
index];
1477 if(theTotalEnergy > 0.00003) {
1486 if(theTotalEnergy > 0.00005) {
1499 totalEnergy += themap[
index];
1503 if(nhitsecX > 10 || nhitsecY > 10) {
1541 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)