24 #include "G4SDManager.hh" 27 #include "G4VProcess.hh" 28 #include "G4HCofThisEvent.hh" 29 #include "G4UserEventAction.hh" 30 #include "G4TransportationManager.hh" 31 #include "G4ProcessManager.hh" 33 #include "CLHEP/Units/GlobalSystemOfUnits.h" 34 #include "CLHEP/Units/GlobalPhysicalConstants.h" 65 std::cout<<
"============================================================================"<<std::endl;
66 std::cout <<
"FP420Testconstructor :: Initialized as observer"<< std::endl;
80 double gapSupplane = 1.6;
81 ZSiPlane=2*zBlade+gapBlade+gapSupplane;
84 ZSiStep=ZSiPlane+ZKapton;
86 double ZBoundDet = 0.020;
87 double ZSiElectr = 0.250;
88 double ZCeramDet = 0.500;
91 ZGapLDet= zBlade/2-(ZSiDet+ZSiElectr+ZBoundDet+ZCeramDet/2);
94 double ZSiStation = (pn0-1)*(2*(zBlade+gapBlade)+ZKapton)+2*6.+0.0;
99 zinibeg = (eee1-eee2)/2.;
101 z1 = zinibeg + (ZSiStation+10.)/2 +
z420;
107 fp420eventntuple =
new TNtuple(
"NTfp420event",
"NTfp420event",
"evt");
118 std::cout <<
"FP420Test constructor :: Initialized Fp420AnalysisHistManager"<< std::endl;
125 TFile fp420OutputFile(
"newntfp420.root",
"RECREATE");
126 std::cout <<
"FP420 output root file has been created";
127 fp420eventntuple->Write();
129 fp420OutputFile.Close();
131 delete fp420eventntuple;
132 std::cout <<
", and deleted" << std::endl;
137 TheHistManager->WriteToFile(fOutputFile,fRecreateFile);
139 std::cout << std::endl <<
"FP420Test Destructor --------> End of FP420Test : " << std::endl;
151 fTypeTitle=managername;
152 fHistArray =
new TObjArray();
153 fHistNamesArray =
new TObjArray();
155 TH1::AddDirectory(kFALSE);
158 fHistArray->Compress();
159 fHistNamesArray->Compress();
171 fHistArray->Delete();
176 fHistNamesArray->Delete();
177 delete fHistNamesArray;
185 HistInit(
"PrimaryEta",
"Primary Eta", 100, 9., 12. );
186 HistInit(
"PrimaryPhigrad",
"Primary Phigrad", 100, 0.,360. );
187 HistInit(
"PrimaryTh",
"Primary Th", 100, 0.,180. );
188 HistInit(
"PrimaryLastpoZ",
"Primary Lastpo Z", 100, -200.,430000. );
189 HistInit(
"PrimaryLastpoX",
"Primary Lastpo X Z<z4", 100, -30., 30. );
190 HistInit(
"PrimaryLastpoY",
"Primary Lastpo Y Z<z4", 100, -30., 30. );
191 HistInit(
"XLastpoNumofpart",
"Primary Lastpo X n>10", 100, -30., 30. );
192 HistInit(
"YLastpoNumofpart",
"Primary Lastpo Y n>10", 100, -30., 30. );
193 HistInit(
"VtxX",
"Vtx X", 100, -50., 50. );
194 HistInit(
"VtxY",
"Vtx Y", 100, -50., 50. );
195 HistInit(
"VtxZ",
"Vtx Z", 100, -200.,430000. );
197 HistInit(
"SumEDep",
"This is sum Energy deposited", 100, -1, 199.);
198 HistInit(
"TrackL",
"This is TrackL", 100, 0., 12000.);
199 HistInit(
"zHits",
"z Hits all events", 100, 400000.,430000. );
200 HistInit(
"zHitsnoMI",
"z Hits no MI", 100, 400000.,430000. );
201 HistInit(
"zHitsTrLoLe",
"z Hits TrLength bigger 8300",100, 400000.,430000. );
202 HistInit(
"NumberOfHits",
"NumberOfHits",100, 0.,300. );
212 std::cout <<
"================================================================"<<std::endl;
213 std::cout <<
" Write this Analysis to File "<<fOutputFile<<std::endl;
214 std::cout <<
"================================================================"<<std::endl;
216 TFile*
file =
new TFile(fOutputFile, fRecreateFile);
227 char* newtitle =
new char[strlen(title)+strlen(fTypeTitle)+5];
228 strcpy(newtitle,title);
229 strcat(newtitle,
" (");
230 strcat(newtitle,fTypeTitle);
231 strcat(newtitle,
") ");
232 fHistArray->AddLast((
new TH1F(name, newtitle, nbinsx, xlow, xup)));
233 fHistNamesArray->AddLast(
new TObjString(name));
242 char* newtitle =
new char[strlen(title)+strlen(fTypeTitle)+5];
243 strcpy(newtitle,title);
244 strcat(newtitle,
" (");
245 strcat(newtitle,fTypeTitle);
246 strcat(newtitle,
") ");
247 fHistArray->AddLast((
new TH2F(name, newtitle, nbinsx, xlow, xup, nbinsy, ylow, yup)));
248 fHistNamesArray->AddLast(
new TObjString(name));
257 if (Number <= fHistArray->GetLast() && fHistArray->At(Number) != (TObject*)0){
259 return (TH1F*)(fHistArray->At(Number));
263 std::cout <<
"!!!!!!!!!!!!!!!!!!GetHisto!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
264 std::cout <<
" WARNING ERROR - HIST ID INCORRECT (TOO HIGH) - " << Number << std::endl;
265 std::cout <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
267 return (TH1F*)(fHistArray->At(0));
276 if (Number <= fHistArray->GetLast() && fHistArray->At(Number) != (TObject*)0){
278 return (TH2F*)(fHistArray->At(Number));
282 std::cout <<
"!!!!!!!!!!!!!!!!GetHisto2!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
283 std::cout <<
" WARNING ERROR - HIST ID INCORRECT (TOO HIGH) - " << Number << std::endl;
284 std::cout <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
286 return (TH2F*)(fHistArray->At(0));
295 Int_t
index = fHistNamesArray->IndexOf(&histname);
296 return GetHisto(index);
304 Int_t
index = fHistNamesArray->IndexOf(&histname);
305 return GetHisto2(index);
313 for(
int i = 0;
i < fHistArray->GetEntries();
i++){
314 ((TH1F*)(fHistArray->At(
i)))->Sumw2();
327 std::cout<<
"FP420Test:beggining of job"<<std::endl;;
335 std::cout << std::endl <<
"FP420Test:: Begining of Run"<< std::endl;
342 iev = (*evt)()->GetEventID();
344 std::cout <<
"FP420Test:update Event number = " << iev << std::endl;
351 itrk = (*trk)()->GetTrackID();
353 std::cout <<
"FP420Test:update BeginOfTrack number = " << itrk << std::endl;
366 itrk = (*trk)()->GetTrackID();
368 std::cout <<
"FP420Test:update EndOfTrack number = " << itrk << std::endl;
371 G4double tracklength = (*trk)()->GetTrackLength();
373 TheHistManager->GetHisto(
"SumEDep")->Fill(SumEnerDeposit);
374 TheHistManager->GetHisto(
"TrackL")->Fill(tracklength);
377 G4ThreeVector vert_mom = (*trk)()->GetVertexMomentumDirection();
378 G4ThreeVector vert_pos = (*trk)()->GetVertexPosition();
407 if(tracklength < z4) {
415 const G4Step* aStep = (*trk)()->GetStep();
419 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
420 lastpo = preStepPoint->GetPosition();
423 if(lastpo.z()<z1 && lastpo.perp()< 100.) {
429 if((lastpo.z()>z1 && lastpo.z()<z2) && lastpo.perp()< 100.) {
435 if(lastpo.z()<z2 && lastpo.perp()< 100.) {
444 if(lastpo.z()<z3 && lastpo.perp()< 100.) {
450 if(lastpo.z()<z4 && lastpo.perp()< 100.) {
469 G4int stepnumber = aStep->GetTrack()->GetCurrentStepNumber();
470 std::cout <<
"FP420Test:update Step number = " << stepnumber << std::endl;
473 G4Track* theTrack = aStep->GetTrack();
476 std::cout <<
"FP420Test on aStep: No trk info !!!! abort " << std::endl;
478 G4int
id = theTrack->GetTrackID();
479 G4String
particleType = theTrack->GetDefinition()->GetParticleName();
480 G4int parentID = theTrack->GetParentID();
481 G4TrackStatus trackstatus = theTrack->GetTrackStatus();
482 G4double tracklength = theTrack->GetTrackLength();
483 G4ThreeVector trackmom = theTrack->GetMomentum();
484 G4double entot = theTrack->GetTotalEnergy();
485 G4int curstepnumber = theTrack->GetCurrentStepNumber();
486 G4ThreeVector vert_pos = theTrack->GetVertexPosition();
487 G4ThreeVector vert_mom = theTrack->GetVertexMomentumDirection();
503 G4double stepl = aStep->GetStepLength();
504 G4double EnerDeposit = aStep->GetTotalEnergyDeposit();
512 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
513 G4ThreeVector preposition = preStepPoint->GetPosition();
514 G4ThreeVector prelocalpoint = theTrack->GetTouchable()->GetHistory()->
515 GetTopTransform().TransformPoint(preposition);
516 G4VPhysicalVolume* currentPV = preStepPoint->GetPhysicalVolume();
517 G4String prename = currentPV->GetName();
519 const G4VTouchable* pre_touch = preStepPoint->GetTouchable();
520 int pre_levels = detLevels(pre_touch);
522 G4String name1[20];
int copyno1[20];
523 for(
int i=0;
i<20; ++
i) {
527 if (pre_levels > 0) {
528 detectorLevel(pre_touch, pre_levels, copyno1, name1);
584 if (curstepnumber == 1 ) {
593 if(prename ==
"SBST" ) {
599 if(prename ==
"SBSTs" ) {
607 if (trackstatus != 2 ) {
609 if(prename ==
"SIDETL" || prename ==
"SIDETR" ) {
610 if(prename ==
"SIDETL") {
613 if(prename ==
"SIDETR") {
638 G4String posname = aStep->GetPostStepPoint()->GetPhysicalVolume()->GetName();
639 if((prename ==
"SIDETL" && posname !=
"SIDETL") || (prename ==
"SIDETR" && posname !=
"SIDETR")) {
640 if(name1[2] ==
"SISTATION" ) {
643 if(name1[3] ==
"SIPLANE" ) {
647 if(prename ==
"SIDETL") {
653 else if(copyno1[2]<3) {
657 else if(copyno1[3]<3) {
660 else if(copyno1[3]<4) {
663 else if(copyno1[3]<5) {
666 else if(copyno1[3]<6) {
669 else if(copyno1[3]<7) {
672 else if(copyno1[3]<8) {
675 else if(copyno1[3]<9) {
678 else if(copyno1[3]<10) {
682 else if(copyno1[2]<4) {
685 else if(copyno1[2]<5) {
689 if(prename ==
"SIDETR") {
695 else if(copyno1[2]<3) {
699 else if(copyno1[3]<3) {
702 else if(copyno1[3]<4) {
705 else if(copyno1[3]<5) {
708 else if(copyno1[3]<6) {
711 else if(copyno1[3]<7) {
714 else if(copyno1[3]<8) {
717 else if(copyno1[3]<9) {
720 else if(copyno1[3]<10) {
724 else if(copyno1[2]<4) {
727 else if(copyno1[2]<5) {
742 SumEnerDeposit += EnerDeposit;
759 if (trackstatus == 2 ) {
762 tracklength0 = tracklength;
773 if (parentID == 1 && curstepnumber == 1) {
791 if(prename ==
"SBST" ) {
794 if(prename ==
"SBSTs" ) {
810 return ((touch->GetHistoryDepth())+1);
817 int currentlevel)
const {
820 if (level > 0 && level >= currentlevel) {
821 int ii = level - currentlevel;
822 return touch->GetVolume(ii)->GetName();
829 int* copyno, G4String*
name)
const {
834 int i = level -
ii - 1;
835 G4VPhysicalVolume*
pv = touch->GetVolume(i);
837 name[
ii] = pv->GetName();
839 name[
ii] =
"Unknown";
840 copyno[
ii] = touch->GetReplicaNumber(i);
851 iev = (*evt)()->GetEventID();
852 std::cout <<
"FP420Test:update EndOfEvent = " << iev << std::endl;
859 G4PrimaryParticle* thePrim=0;
863 G4int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
865 std::cout <<
"FP420Test: My warning: NumberOfPrimaryVertex != 1 --> = " << nvertex << std::endl;
867 for (
int i = 0 ;
i<nvertex;
i++) {
868 G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(
i);
870 std::cout <<
"FP420Test End Of Event ERR: pointer to vertex = 0" 872 G4int
npart = avertex->GetNumberOfParticle();
874 std::cout <<
"FP420Test: My warning: NumberOfPrimaryPart != 1 --> = " << npart << std::endl;
876 std::cout <<
"FP420Test End Of Event ERR: no NumberOfParticle" << std::endl;
879 if (thePrim==0) thePrim=avertex->GetPrimary(trackID);
883 G4double vx=0.,vy=0.,vz=0.;
884 vx = avertex->GetX0();
885 vy = avertex->GetY0();
886 vz = avertex->GetZ0();
890 TheHistManager->GetHisto(
"VtxX")->Fill(vx);
891 TheHistManager->GetHisto(
"VtxY")->Fill(vy);
892 TheHistManager->GetHisto(
"VtxZ")->Fill(vz);
914 if(lastpo.z()<z4 && lastpo.perp()< 100.) {
920 G4ThreeVector mom = thePrim->GetMomentum();
922 double phi = atan2(mom.y(),mom.x());
923 if (phi < 0.) phi += twopi;
924 double phigrad = phi*180./
pi;
926 double th = mom.theta();
940 TheHistManager->GetHisto(
"PrimaryEta")->Fill(eta);
941 TheHistManager->GetHisto(
"PrimaryPhigrad")->Fill(phigrad);
942 TheHistManager->GetHisto(
"PrimaryTh")->Fill(th*180./
pi);
944 TheHistManager->GetHisto(
"PrimaryLastpoZ")->Fill(lastpo.z());
945 if(lastpo.z() < z4 ) {
946 TheHistManager->GetHisto(
"PrimaryLastpoX")->Fill(lastpo.x());
947 TheHistManager->GetHisto(
"PrimaryLastpoY")->Fill(lastpo.y());
950 TheHistManager->GetHisto(
"XLastpoNumofpart")->Fill(lastpo.x());
951 TheHistManager->GetHisto(
"YLastpoNumofpart")->Fill(lastpo.y());
959 map<int,float,less<int> > themap;
960 map<int,float,less<int> > themap1;
962 map<int,float,less<int> > themapxy;
963 map<int,float,less<int> > themapz;
967 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
970 std::cout <<
"FP420Test: accessed all HC" << std::endl;;
972 int CAFIid = G4SDManager::GetSDMpointer()->GetCollectionID(
"FP420SI");
980 std::cout <<
"FP420Test: theCAFI->entries = " << theCAFI->entries() << std::endl;
983 TheHistManager->GetHisto(
"NumberOfHits")->Fill(theCAFI->entries());
1001 if( lastpo.z()< z4) {
1014 for (
int j=0; j<theCAFI->entries(); j++) {
1016 G4ThreeVector hitPoint = aHit->
getEntry();
1017 double zz = hitPoint.z();
1018 TheHistManager->GetHisto(
"zHits")->Fill(zz);
1019 if(tracklength0>8300.) TheHistManager->GetHisto(
"zHitsTrLoLe")->Fill(zz);
1031 int nhit11 = 0, nhit12 = 0, nhit13 = 0 ;
1032 double totallosenergy= 0.;
1033 for (
int j=0; j<theCAFI->entries(); j++) {
1038 G4ThreeVector hitPoint = aHit->
getEntry();
1043 unsigned int unitID = aHit->
getUnitID();
1073 double zz = hitPoint.z();
1075 TheHistManager->GetHisto(
"zHitsnoMI")->Fill(zz);
1078 std::cout <<
"FP420Test:zHits = " << zz << std::endl;
1089 themap[unitID] += losenergy;
1090 totallosenergy += losenergy;
1092 int det,
zside, sector, zmodule;
1096 if(justlayer<1||justlayer>2) {
1097 std::cout <<
"FP420Test:WRONG justlayer= " << justlayer << std::endl;
1112 G4ThreeVector middle = (hitExitLocalPoint-hitEntryLocalPoint)/2.;
1113 themapz[unitID] = hitPoint.z()+fabs(middle.z());
1115 std::cout <<
"1111111111111111111111111111111111111111111111111111111111111111111111111 " << std::endl;
1116 std::cout <<
"FP420Test: det, zside, sector, zmodule = " << det << zside << sector << zmodule << std::endl;
1117 std::cout <<
"FP420Test: justlayer = " << justlayer << std::endl;
1118 std::cout <<
"FP420Test: hitExitLocalPoint = " << hitExitLocalPoint << std::endl;
1119 std::cout <<
"FP420Test: hitEntryLocalPoint = " << hitEntryLocalPoint << std::endl;
1120 std::cout <<
"FP420Test: middle= " << middle << std::endl;
1121 std::cout <<
"FP420Test: hitPoint.z()-419000.= " << hitPoint.z()-419000. << std::endl;
1123 std::cout <<
"FP420Test:zHits-419000. = " << themapz[unitID]-419000. << std::endl;
1129 if(losenergy > 0.00003) {
1130 themap1[unitID] += 1.;
1136 if(losenergy > 0.00005) {
1137 themap1[unitID] += 1.;
1177 if(lastpo.z()<z4 && lastpo.perp()< 120.) {
1187 if( zz < z3 && zz > z2){
1192 if( zz < z4 && zz > z3){
1216 if(trackIDhit == 1){
1226 if( zz < z3 && zz > z2){
1239 if(trackIDhit == 1){
1248 if( zz < z4 && zz > z3){
1279 std::cout <<
"22222222222222222222222222222222222222222222222222222222222222222222222222 " << std::endl;
1282 int allplacesforsensors=7;
1283 for (
int sector=1; sector < sn0; sector++) {
1284 for (
int zmodule=1; zmodule<pn0; zmodule++) {
1285 for (
int zsideinorder=1; zsideinorder<allplacesforsensors; zsideinorder++) {
1288 std::cout <<
"FP420Test: sector= " << sector <<
" zmodule= " << zmodule <<
" zsideinorder= " << zsideinorder <<
" zside= " << zside << std::endl;
1292 if(justlayer<1||justlayer>2) {
1293 std::cout <<
"FP420Test:WRONG justlayer= " << justlayer << std::endl;
1296 if(copyinlayer<1||copyinlayer>3) {
1297 std::cout <<
"FP420Test:WRONG copyinlayer= " << copyinlayer << std::endl;
1300 if(orientation<1||orientation>2) {
1301 std::cout <<
"FP420Test:WRONG orientation= " << orientation << std::endl;
1310 std::cout <<
"FP420Test: justlayer = " << justlayer <<
" copyinlayer = " << copyinlayer <<
" orientation = " << orientation <<
" ii= " << ii << std::endl;
1312 double zdiststat = 0.;
1314 if(sector==2) zdiststat =
zD3;
1317 if(sector==2) zdiststat =
zD2;
1318 if(sector==3) zdiststat =
zD3;
1320 double kplane = -(pn0-1)/2 - 0.5 + (zmodule-1);
1321 double zcurrent = zinibeg +
z420 + (ZSiStep-ZSiPlane)/2 + kplane*ZSiStep + zdiststat;
1324 std::cout <<
"FP420Test: Leftzcurrent-419000. = " << zcurrent-419000. << std::endl;
1325 std::cout <<
"FP420Test: ZGapLDet = " << ZGapLDet << std::endl;
1328 if(orientation==1) zcurrent += (ZGapLDet+ZSiDet/2);
1329 if(orientation==2) zcurrent += zBlade-(ZGapLDet+ZSiDet/2);
1332 if(orientation==1) zcurrent += (ZGapLDet+ZSiDet/2)+zBlade+gapBlade;
1333 if(orientation==2) zcurrent += 2*zBlade+gapBlade-(ZGapLDet+ZSiDet/2);
1337 if(det == 2) zcurrent = -zcurrent;
1340 std::cout <<
"FP420Test: zcurrent-419000. = " << zcurrent-419000. << std::endl;
1350 std::cout <<
"----------------------------------------------------------------------------- " << std::endl;
1356 if(totallosenergy == 0.0) {
1357 std::cout <<
"FP420Test: number of hits = " << theCAFI->entries() << std::endl;
1358 for (
int j=0; j<theCAFI->entries(); j++) {
1361 std::cout <<
" j hits = " << j <<
"losenergy = " << losenergy << std::endl;
1371 double totalEnergy = 0.;
1372 int nhitsX = 0, nhitsY = 0, nsumhit = 0 ;
1373 for (
int sector=1; sector<4; sector++) {
1374 int nhitsecX = 0, nhitsecY = 0;
1375 for (
int zmodule=1; zmodule<11; zmodule++) {
1381 double theTotalEnergy = themap[
index];
1385 if(theTotalEnergy > 0.00003) {
1394 if(theTotalEnergy > 0.00005) {
1407 totalEnergy += themap[
index];
1411 if(nhitsecX > 10 || nhitsecY > 10) {
1442 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
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)