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;
91 double gapSupplane = 1.6;
92 ZSiPlane=2*zBlade+gapBlade+gapSupplane;
95 ZSiStep=ZSiPlane+ZKapton;
97 double ZBoundDet = 0.020;
98 double ZSiElectr = 0.250;
99 double ZCeramDet = 0.500;
102 ZGapLDet= zBlade/2-(ZSiDet+ZSiElectr+ZBoundDet+ZCeramDet/2);
105 double ZSiStation = (pn0-1)*(2*(zBlade+gapBlade)+ZKapton)+2*6.+0.0;
110 zinibeg = (eee1-eee2)/2.;
112 z1 = zinibeg + (ZSiStation+10.)/2 + z420;
118 fp420eventntuple =
new TNtuple(
"NTfp420event",
"NTfp420event",
"evt");
129 std::cout <<
"FP420Test constructor :: Initialized Fp420AnalysisHistManager"<< std::endl;
137 delete theFP420NumberingScheme;
139 TFile fp420OutputFile(
"newntfp420.root",
"RECREATE");
140 std::cout <<
"FP420 output root file has been created";
141 fp420eventntuple->Write();
143 fp420OutputFile.Close();
145 delete fp420eventntuple;
146 std::cout <<
", and deleted" << std::endl;
151 TheHistManager->WriteToFile(fOutputFile,fRecreateFile);
153 std::cout << std::endl <<
"FP420Test Destructor --------> End of FP420Test : "
157 std::cout<<
"FP420Test: End of process"<<std::endl;
171 fTypeTitle=managername;
172 fHistArray =
new TObjArray();
173 fHistNamesArray =
new TObjArray();
175 TH1::AddDirectory(kFALSE);
178 fHistArray->Compress();
179 fHistNamesArray->Compress();
191 fHistArray->Delete();
196 fHistNamesArray->Delete();
197 delete fHistNamesArray;
205 HistInit(
"PrimaryEta",
"Primary Eta", 100, 9., 12. );
206 HistInit(
"PrimaryPhigrad",
"Primary Phigrad", 100, 0.,360. );
207 HistInit(
"PrimaryTh",
"Primary Th", 100, 0.,180. );
208 HistInit(
"PrimaryLastpoZ",
"Primary Lastpo Z", 100, -200.,430000. );
209 HistInit(
"PrimaryLastpoX",
"Primary Lastpo X Z<z4", 100, -30., 30. );
210 HistInit(
"PrimaryLastpoY",
"Primary Lastpo Y Z<z4", 100, -30., 30. );
211 HistInit(
"XLastpoNumofpart",
"Primary Lastpo X n>10", 100, -30., 30. );
212 HistInit(
"YLastpoNumofpart",
"Primary Lastpo Y n>10", 100, -30., 30. );
213 HistInit(
"VtxX",
"Vtx X", 100, -50., 50. );
214 HistInit(
"VtxY",
"Vtx Y", 100, -50., 50. );
215 HistInit(
"VtxZ",
"Vtx Z", 100, -200.,430000. );
217 HistInit(
"SumEDep",
"This is sum Energy deposited", 100, -1, 199.);
218 HistInit(
"TrackL",
"This is TrackL", 100, 0., 12000.);
219 HistInit(
"zHits",
"z Hits all events", 100, 400000.,430000. );
220 HistInit(
"zHitsnoMI",
"z Hits no MI", 100, 400000.,430000. );
221 HistInit(
"zHitsTrLoLe",
"z Hits TrLength bigger 8300",100, 400000.,430000. );
222 HistInit(
"NumberOfHits",
"NumberOfHits",100, 0.,300. );
232 std::cout <<
"================================================================"<<std::endl;
233 std::cout <<
" Write this Analysis to File "<<fOutputFile<<std::endl;
234 std::cout <<
"================================================================"<<std::endl;
236 TFile*
file =
new TFile(fOutputFile, fRecreateFile);
247 char* newtitle =
new char[strlen(title)+strlen(fTypeTitle)+5];
248 strcpy(newtitle,title);
249 strcat(newtitle,
" (");
250 strcat(newtitle,fTypeTitle);
251 strcat(newtitle,
") ");
252 fHistArray->AddLast((
new TH1F(name, newtitle, nbinsx, xlow, xup)));
253 fHistNamesArray->AddLast(
new TObjString(name));
262 char* newtitle =
new char[strlen(title)+strlen(fTypeTitle)+5];
263 strcpy(newtitle,title);
264 strcat(newtitle,
" (");
265 strcat(newtitle,fTypeTitle);
266 strcat(newtitle,
") ");
267 fHistArray->AddLast((
new TH2F(name, newtitle, nbinsx, xlow, xup, nbinsy, ylow, yup)));
268 fHistNamesArray->AddLast(
new TObjString(name));
277 if (Number <= fHistArray->GetLast() && fHistArray->At(Number) != (TObject*)0){
279 return (TH1F*)(fHistArray->At(Number));
283 std::cout <<
"!!!!!!!!!!!!!!!!!!GetHisto!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
284 std::cout <<
" WARNING ERROR - HIST ID INCORRECT (TOO HIGH) - " << Number << std::endl;
285 std::cout <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
287 return (TH1F*)(fHistArray->At(0));
296 if (Number <= fHistArray->GetLast() && fHistArray->At(Number) != (TObject*)0){
298 return (TH2F*)(fHistArray->At(Number));
302 std::cout <<
"!!!!!!!!!!!!!!!!GetHisto2!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
303 std::cout <<
" WARNING ERROR - HIST ID INCORRECT (TOO HIGH) - " << Number << std::endl;
304 std::cout <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
306 return (TH2F*)(fHistArray->At(0));
315 Int_t
index = fHistNamesArray->IndexOf(&histname);
316 return GetHisto(index);
324 Int_t
index = fHistNamesArray->IndexOf(&histname);
325 return GetHisto2(index);
333 for(
int i = 0;
i < fHistArray->GetEntries();
i++){
334 ((TH1F*)(fHistArray->At(
i)))->Sumw2();
407 std::cout<<
"FP420Test:beggining of job"<<std::endl;;
415 std::cout << std::endl <<
"FP420Test:: Begining of Run"<< std::endl;
425 iev = (*evt)()->GetEventID();
427 std::cout <<
"FP420Test:update Event number = " << iev << std::endl;
434 itrk = (*trk)()->GetTrackID();
436 std::cout <<
"FP420Test:update BeginOfTrack number = " << itrk << std::endl;
451 itrk = (*trk)()->GetTrackID();
453 std::cout <<
"FP420Test:update EndOfTrack number = " << itrk << std::endl;
456 G4double tracklength = (*trk)()->GetTrackLength();
458 TheHistManager->GetHisto(
"SumEDep")->Fill(SumEnerDeposit);
459 TheHistManager->GetHisto(
"TrackL")->Fill(tracklength);
462 G4ThreeVector vert_mom = (*trk)()->GetVertexMomentumDirection();
463 G4ThreeVector vert_pos = (*trk)()->GetVertexPosition();
466 float phi = atan2(vert_mom.y(),vert_mom.x());
467 if (phi < 0.) phi += twopi;
492 if(tracklength < z4) {
500 const G4Step* aStep = (*trk)()->GetStep();
504 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
505 lastpo = preStepPoint->GetPosition();
508 if(lastpo.z()<z1 && lastpo.perp()< 100.) {
514 if((lastpo.z()>z1 && lastpo.z()<z2) && lastpo.perp()< 100.) {
520 if(lastpo.z()<z2 && lastpo.perp()< 100.) {
529 if(lastpo.z()<z3 && lastpo.perp()< 100.) {
535 if(lastpo.z()<z4 && lastpo.perp()< 100.) {
564 G4int stepnumber = aStep->GetTrack()->GetCurrentStepNumber();
565 std::cout <<
"FP420Test:update Step number = " << stepnumber << std::endl;
568 G4Track* theTrack = aStep->GetTrack();
571 std::cout <<
"FP420Test on aStep: No trk info !!!! abort " << std::endl;
574 G4int
id = theTrack->GetTrackID();
575 G4String particleType = theTrack->GetDefinition()->GetParticleName();
576 G4int parentID = theTrack->GetParentID();
577 G4TrackStatus trackstatus = theTrack->GetTrackStatus();
578 G4double tracklength = theTrack->GetTrackLength();
579 G4ThreeVector trackmom = theTrack->GetMomentum();
580 G4double entot = theTrack->GetTotalEnergy();
581 G4int curstepnumber = theTrack->GetCurrentStepNumber();
582 G4ThreeVector vert_pos = theTrack->GetVertexPosition();
583 G4ThreeVector vert_mom = theTrack->GetVertexMomentumDirection();
599 G4double stepl = aStep->GetStepLength();
600 G4double EnerDeposit = aStep->GetTotalEnergyDeposit();
608 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
609 G4ThreeVector preposition = preStepPoint->GetPosition();
610 G4ThreeVector prelocalpoint = theTrack->GetTouchable()->GetHistory()->
611 GetTopTransform().TransformPoint(preposition);
612 G4VPhysicalVolume* currentPV = preStepPoint->GetPhysicalVolume();
613 G4String prename = currentPV->GetName();
615 const G4VTouchable* pre_touch = preStepPoint->GetTouchable();
616 int pre_levels = detLevels(pre_touch);
621 G4String name1[20];
int copyno1[20];
622 if (pre_levels > 0) {
623 detectorLevel(pre_touch, pre_levels, copyno1, name1);
679 if (curstepnumber == 1 ) {
688 if(prename ==
"SBST" ) {
694 if(prename ==
"SBSTs" ) {
702 if (trackstatus != 2 ) {
704 if(prename ==
"SIDETL" || prename ==
"SIDETR" ) {
705 if(prename ==
"SIDETL") {
708 if(prename ==
"SIDETR") {
733 G4String posname = aStep->GetPostStepPoint()->GetPhysicalVolume()->GetName();
734 if((prename ==
"SIDETL" && posname !=
"SIDETL") || (prename ==
"SIDETR" && posname !=
"SIDETR")) {
735 if(name1[2] ==
"SISTATION" ) {
738 if(name1[3] ==
"SIPLANE" ) {
742 if(prename ==
"SIDETL") {
748 else if(copyno1[2]<3) {
752 else if(copyno1[3]<3) {
755 else if(copyno1[3]<4) {
758 else if(copyno1[3]<5) {
761 else if(copyno1[3]<6) {
764 else if(copyno1[3]<7) {
767 else if(copyno1[3]<8) {
770 else if(copyno1[3]<9) {
773 else if(copyno1[3]<10) {
777 else if(copyno1[2]<4) {
780 else if(copyno1[2]<5) {
784 if(prename ==
"SIDETR") {
790 else if(copyno1[2]<3) {
794 else if(copyno1[3]<3) {
797 else if(copyno1[3]<4) {
800 else if(copyno1[3]<5) {
803 else if(copyno1[3]<6) {
806 else if(copyno1[3]<7) {
809 else if(copyno1[3]<8) {
812 else if(copyno1[3]<9) {
815 else if(copyno1[3]<10) {
819 else if(copyno1[2]<4) {
822 else if(copyno1[2]<5) {
837 SumEnerDeposit += EnerDeposit;
854 if (trackstatus == 2 ) {
857 tracklength0 = tracklength;
868 if (parentID == 1 && curstepnumber == 1) {
886 if(prename ==
"SBST" ) {
889 if(prename ==
"SBSTs" ) {
905 return ((touch->GetHistoryDepth())+1);
912 int currentlevel)
const {
915 if (level > 0 && level >= currentlevel) {
916 int ii = level - currentlevel;
917 return touch->GetVolume(ii)->GetName();
924 int* copyno, G4String*
name)
const {
929 int i = level -
ii - 1;
930 G4VPhysicalVolume* pv = touch->GetVolume(i);
932 name[
ii] = pv->GetName();
934 name[
ii] =
"Unknown";
935 copyno[
ii] = touch->GetReplicaNumber(i);
946 iev = (*evt)()->GetEventID();
947 std::cout <<
"FP420Test:update EndOfEvent = " << iev << std::endl;
954 G4PrimaryParticle* thePrim=0;
958 G4int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
960 std::cout <<
"FP420Test: My warning: NumberOfPrimaryVertex != 1 --> = " << nvertex << std::endl;
962 for (
int i = 0 ;
i<nvertex;
i++) {
963 G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(
i);
965 std::cout <<
"FP420Test End Of Event ERR: pointer to vertex = 0"
967 G4int
npart = avertex->GetNumberOfParticle();
969 std::cout <<
"FP420Test: My warning: NumberOfPrimaryPart != 1 --> = " << npart << std::endl;
971 std::cout <<
"FP420Test End Of Event ERR: no NumberOfParticle" << std::endl;
974 if (thePrim==0) thePrim=avertex->GetPrimary(trackID);
978 G4double vx=0.,vy=0.,vz=0.;
979 vx = avertex->GetX0();
980 vy = avertex->GetY0();
981 vz = avertex->GetZ0();
985 TheHistManager->GetHisto(
"VtxX")->Fill(vx);
986 TheHistManager->GetHisto(
"VtxY")->Fill(vy);
987 TheHistManager->GetHisto(
"VtxZ")->Fill(vz);
1009 if(lastpo.z()<z4 && lastpo.perp()< 100.) {
1015 G4ThreeVector mom = thePrim->GetMomentum();
1017 double phi = atan2(mom.y(),mom.x());
1018 if (phi < 0.) phi += twopi;
1019 double phigrad = phi*180./
pi;
1021 double th = mom.theta();
1035 TheHistManager->GetHisto(
"PrimaryEta")->Fill(eta);
1036 TheHistManager->GetHisto(
"PrimaryPhigrad")->Fill(phigrad);
1037 TheHistManager->GetHisto(
"PrimaryTh")->Fill(th*180./
pi);
1039 TheHistManager->GetHisto(
"PrimaryLastpoZ")->Fill(lastpo.z());
1040 if(lastpo.z() < z4 ) {
1041 TheHistManager->GetHisto(
"PrimaryLastpoX")->Fill(lastpo.x());
1042 TheHistManager->GetHisto(
"PrimaryLastpoY")->Fill(lastpo.y());
1044 if(numofpart > 4 ) {
1045 TheHistManager->GetHisto(
"XLastpoNumofpart")->Fill(lastpo.x());
1046 TheHistManager->GetHisto(
"YLastpoNumofpart")->Fill(lastpo.y());
1054 map<int,float,less<int> > themap;
1055 map<int,float,less<int> > themap1;
1057 map<int,float,less<int> > themapxy;
1058 map<int,float,less<int> > themapz;
1062 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
1065 std::cout <<
"FP420Test: accessed all HC" << std::endl;;
1067 int CAFIid = G4SDManager::GetSDMpointer()->GetCollectionID(
"FP420SI");
1075 std::cout <<
"FP420Test: theCAFI->entries = " << theCAFI->entries() << std::endl;
1078 TheHistManager->GetHisto(
"NumberOfHits")->Fill(theCAFI->entries());
1097 if( lastpo.z()< z4) {
1110 for (
int j=0;
j<theCAFI->entries();
j++) {
1112 G4ThreeVector hitPoint = aHit->
getEntry();
1113 double zz = hitPoint.z();
1114 TheHistManager->GetHisto(
"zHits")->Fill(zz);
1115 if(tracklength0>8300.) TheHistManager->GetHisto(
"zHitsTrLoLe")->Fill(zz);
1127 int nhit11 = 0, nhit12 = 0, nhit13 = 0 ;
1128 double totallosenergy= 0.;
1129 for (
int j=0;
j<theCAFI->entries();
j++) {
1134 G4ThreeVector hitPoint = aHit->
getEntry();
1139 unsigned int unitID = aHit->
getUnitID();
1159 double phi_hit = hitPoint.phi();
1160 if (phi_hit < 0.) phi_hit += twopi;
1169 double zz = hitPoint.z();
1171 TheHistManager->GetHisto(
"zHitsnoMI")->Fill(zz);
1174 std::cout <<
"FP420Test:zHits = " << zz << std::endl;
1185 themap[unitID] += losenergy;
1186 totallosenergy += losenergy;
1188 int det,
zside, sector, zmodule;
1191 int justlayer = theFP420NumberingScheme->FP420NumberingScheme::unpackLayerIndex(rn00, zside);
1192 if(justlayer<1||justlayer>2) {
1193 std::cout <<
"FP420Test:WRONG justlayer= " << justlayer << std::endl;
1208 G4ThreeVector middle = (hitExitLocalPoint-hitEntryLocalPoint)/2.;
1209 themapz[unitID] = hitPoint.z()+fabs(middle.z());
1211 std::cout <<
"1111111111111111111111111111111111111111111111111111111111111111111111111 " << std::endl;
1212 std::cout <<
"FP420Test: det, zside, sector, zmodule = " << det << zside << sector << zmodule << std::endl;
1213 std::cout <<
"FP420Test: justlayer = " << justlayer << std::endl;
1214 std::cout <<
"FP420Test: hitExitLocalPoint = " << hitExitLocalPoint << std::endl;
1215 std::cout <<
"FP420Test: hitEntryLocalPoint = " << hitEntryLocalPoint << std::endl;
1216 std::cout <<
"FP420Test: middle= " << middle << std::endl;
1217 std::cout <<
"FP420Test: hitPoint.z()-419000.= " << hitPoint.z()-419000. << std::endl;
1219 std::cout <<
"FP420Test:zHits-419000. = " << themapz[unitID]-419000. << std::endl;
1225 if(losenergy > 0.00003) {
1226 themap1[unitID] += 1.;
1232 if(losenergy > 0.00005) {
1233 themap1[unitID] += 1.;
1273 if(lastpo.z()<z4 && lastpo.perp()< 120.) {
1283 if( zz < z3 && zz > z2){
1288 if( zz < z4 && zz > z3){
1312 if(trackIDhit == 1){
1322 if( zz < z3 && zz > z2){
1335 if(trackIDhit == 1){
1344 if( zz < z4 && zz > z3){
1375 std::cout <<
"22222222222222222222222222222222222222222222222222222222222222222222222222 " << std::endl;
1378 int allplacesforsensors=7;
1379 for (
int sector=1; sector < sn0; sector++) {
1380 for (
int zmodule=1; zmodule<pn0; zmodule++) {
1381 for (
int zsideinorder=1; zsideinorder<allplacesforsensors; zsideinorder++) {
1382 int zside = theFP420NumberingScheme->FP420NumberingScheme::realzside(rn00, zsideinorder);
1384 std::cout <<
"FP420Test: sector= " << sector <<
" zmodule= " << zmodule <<
" zsideinorder= " << zsideinorder <<
" zside= " << zside << std::endl;
1387 int justlayer = theFP420NumberingScheme->FP420NumberingScheme::unpackLayerIndex(rn00, zside);
1388 if(justlayer<1||justlayer>2) {
1389 std::cout <<
"FP420Test:WRONG justlayer= " << justlayer << std::endl;
1391 int copyinlayer = theFP420NumberingScheme->FP420NumberingScheme::unpackCopyIndex(rn00, zside);
1392 if(copyinlayer<1||copyinlayer>3) {
1393 std::cout <<
"FP420Test:WRONG copyinlayer= " << copyinlayer << std::endl;
1395 int orientation = theFP420NumberingScheme->FP420NumberingScheme::unpackOrientation(rn00, zside);
1396 if(orientation<1||orientation>2) {
1397 std::cout <<
"FP420Test:WRONG orientation= " << orientation << std::endl;
1403 unsigned int ii=theFP420NumberingScheme->FP420NumberingScheme::packMYIndex(rn00,pn0,sn0,detfixed,justlayer,sector,zmodule)-1;
1406 std::cout <<
"FP420Test: justlayer = " << justlayer <<
" copyinlayer = " << copyinlayer <<
" orientation = " << orientation <<
" ii= " << ii << std::endl;
1408 double zdiststat = 0.;
1410 if(sector==2) zdiststat = zD3;
1413 if(sector==2) zdiststat = zD2;
1414 if(sector==3) zdiststat = zD3;
1416 double kplane = -(pn0-1)/2 - 0.5 + (zmodule-1);
1417 double zcurrent = zinibeg + z420 + (ZSiStep-ZSiPlane)/2 + kplane*ZSiStep + zdiststat;
1420 std::cout <<
"FP420Test: Leftzcurrent-419000. = " << zcurrent-419000. << std::endl;
1421 std::cout <<
"FP420Test: ZGapLDet = " << ZGapLDet << std::endl;
1424 if(orientation==1) zcurrent += (ZGapLDet+ZSiDet/2);
1425 if(orientation==2) zcurrent += zBlade-(ZGapLDet+ZSiDet/2);
1428 if(orientation==1) zcurrent += (ZGapLDet+ZSiDet/2)+zBlade+gapBlade;
1429 if(orientation==2) zcurrent += 2*zBlade+gapBlade-(ZGapLDet+ZSiDet/2);
1433 if(det == 2) zcurrent = -zcurrent;
1436 std::cout <<
"FP420Test: zcurrent-419000. = " << zcurrent-419000. << std::endl;
1446 std::cout <<
"----------------------------------------------------------------------------- " << std::endl;
1452 if(totallosenergy == 0.0) {
1453 std::cout <<
"FP420Test: number of hits = " << theCAFI->entries() << std::endl;
1454 for (
int j=0;
j<theCAFI->entries();
j++) {
1457 std::cout <<
" j hits = " <<
j <<
"losenergy = " << losenergy << std::endl;
1467 double totalEnergy = 0.;
1468 int nhitsX = 0, nhitsY = 0, nsumhit = 0 ;
1469 for (
int sector=1; sector<4; sector++) {
1470 int nhitsecX = 0, nhitsecY = 0;
1471 for (
int zmodule=1; zmodule<11; zmodule++) {
1477 double theTotalEnergy = themap[
index];
1481 if(theTotalEnergy > 0.00003) {
1490 if(theTotalEnergy > 0.00005) {
1503 totalEnergy += themap[
index];
1507 if(nhitsecX > 10 || nhitsecY > 10) {
1545 std::cout <<
"FP420Test: END OF Event " << (*evt)()->GetEventID() << std::endl;
G4String detName(const G4VTouchable *, int, int) const
T getParameter(std::string const &) const
static std::vector< std::string > checklist log
~Fp420AnalysisHistManager()
void HistInit(const char *name, const char *title, Int_t nbinsx, Axis_t xlow, Axis_t xup)
G4ThreeVector getExitLocalP() const
static void unpackFP420Index(const unsigned int &idx, int &det, int &zside, int &station, int &superplane)
FP420Test(const edm::ParameterSet &p)
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
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
int detLevels(const G4VTouchable *) const
TH1F * GetHisto(Int_t Number)
void detectorLevel(const G4VTouchable *, int &, int *, G4String *) const
G4ThreeVector getEntry() const