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" 62 std::cout<<
"============================================================================"<<std::endl;
63 std::cout <<
"BscTestconstructor :: Initialized as observer"<< std::endl;
73 std::cout <<
"BscTest constructor :: Initialized BscAnalysisHistManager"<< std::endl;
82 std::cout <<
"Bsc output root file has been created";
85 bscOutputFile.Close();
88 std::cout <<
", and deleted" << std::endl;
95 std::cout << std::endl <<
"BscTest Destructor --------> End of BscTest : " << std::endl;
98 std::cout<<
"BscTest: End of process"<<std::endl;
109 fTypeTitle=managername;
110 fHistArray =
new TObjArray();
111 fHistNamesArray =
new TObjArray();
115 fHistArray->Compress();
116 fHistNamesArray->Compress();
125 fHistArray->Delete();
130 fHistNamesArray->Delete();
131 delete fHistNamesArray;
139 HistInit(
"TrackPhi",
"Primary Phi", 100, 0.,360. );
140 HistInit(
"TrackTheta",
"Primary Theta", 100, 0.,180. );
141 HistInit(
"TrackP",
"Track XY position Z+ ", 80, -80., 80., 80, -80., 80. );
142 HistInit(
"TrackM",
"Track XY position Z-", 80, -80., 80., 80, -80., 80. );
143 HistInit(
"DetIDs",
"Track DetId - vs +", 16, -0.5, 15.5,16, 15.5, 31.5 );
153 std::cout <<
"================================================================"<<std::endl;
154 std::cout <<
" Write this Analysis to File "<<fOutputFile<<std::endl;
155 std::cout <<
"================================================================"<<std::endl;
157 TFile*
file =
new TFile(fOutputFile, fRecreateFile);
168 char* newtitle =
new char[strlen(title)+strlen(fTypeTitle)+5];
169 strcpy(newtitle,title);
170 strcat(newtitle,
" (");
171 strcat(newtitle,fTypeTitle);
172 strcat(newtitle,
") ");
173 fHistArray->AddLast((
new TH1F(name, newtitle, nbinsx, xlow, xup)));
174 fHistNamesArray->AddLast(
new TObjString(name));
183 char* newtitle =
new char[strlen(title)+strlen(fTypeTitle)+5];
184 strcpy(newtitle,title);
185 strcat(newtitle,
" (");
186 strcat(newtitle,fTypeTitle);
187 strcat(newtitle,
") ");
188 fHistArray->AddLast((
new TH2F(name, newtitle, nbinsx, xlow, xup, nbinsy, ylow, yup)));
189 fHistNamesArray->AddLast(
new TObjString(name));
198 if (Number <= fHistArray->GetLast() && fHistArray->At(Number) != (TObject*)0){
200 return (TH1F*)(fHistArray->At(Number));
204 std::cout <<
"!!!!!!!!!!!!!!!!!!GetHisto!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
205 std::cout <<
" WARNING ERROR - HIST ID INCORRECT (TOO HIGH) - " << Number << std::endl;
206 std::cout <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
208 return (TH1F*)(fHistArray->At(0));
217 if (Number <= fHistArray->GetLast() && fHistArray->At(Number) != (TObject*)0){
219 return (TH2F*)(fHistArray->At(Number));
223 std::cout <<
"!!!!!!!!!!!!!!!!GetHisto2!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
224 std::cout <<
" WARNING ERROR - HIST ID INCORRECT (TOO HIGH) - " << Number << std::endl;
225 std::cout <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
227 return (TH2F*)(fHistArray->At(0));
236 Int_t
index = fHistNamesArray->IndexOf(&histname);
237 return GetHisto(index);
245 Int_t
index = fHistNamesArray->IndexOf(&histname);
246 return GetHisto2(index);
254 for(
int i = 0;
i < fHistArray->GetEntries();
i++){
255 ((TH1F*)(fHistArray->At(
i)))->Sumw2();
263 std::cout<<
"BscTest:beggining of job"<<std::endl;;
270 std::cout << std::endl <<
"BscTest:: Begining of Run"<< std::endl;
277 iev = (*evt)()->GetEventID();
279 std::cout <<
"BscTest:update Event number = " <<
iev << std::endl;
286 itrk = (*trk)()->GetTrackID();
288 std::cout <<
"BscTest:update BeginOfTrack number = " <<
itrk << std::endl;
301 itrk = (*trk)()->GetTrackID();
303 std::cout <<
"BscTest:update EndOfTrack number = " <<
itrk << std::endl;
306 G4double tracklength = (*trk)()->GetTrackLength();
312 G4ThreeVector vert_mom = (*trk)()->GetVertexMomentumDirection();
313 G4ThreeVector vert_pos = (*trk)()->GetVertexPosition();
316 const G4Step* aStep = (*trk)()->GetStep();
317 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
318 lastpo = preStepPoint->GetPosition();
329 G4int stepnumber = aStep->GetTrack()->GetCurrentStepNumber();
330 std::cout <<
"BscTest:update Step number = " << stepnumber << std::endl;
333 G4Track* theTrack = aStep->GetTrack();
336 std::cout <<
"BscTest on aStep: No trk info !!!! abort " << std::endl;
338 G4int
id = theTrack->GetTrackID();
339 G4String
particleType = theTrack->GetDefinition()->GetParticleName();
340 G4int parentID = theTrack->GetParentID();
341 G4TrackStatus trackstatus = theTrack->GetTrackStatus();
342 G4double tracklength = theTrack->GetTrackLength();
343 G4ThreeVector trackmom = theTrack->GetMomentum();
344 G4double entot = theTrack->GetTotalEnergy();
345 G4int curstepnumber = theTrack->GetCurrentStepNumber();
346 G4ThreeVector vert_pos = theTrack->GetVertexPosition();
347 G4ThreeVector vert_mom = theTrack->GetVertexMomentumDirection();
348 G4double stepl = aStep->GetStepLength();
349 G4double EnerDeposit = aStep->GetTotalEnergyDeposit();
350 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
351 G4ThreeVector preposition = preStepPoint->GetPosition();
352 G4ThreeVector prelocalpoint = theTrack->GetTouchable()->GetHistory()->
353 GetTopTransform().TransformPoint(preposition);
354 G4VPhysicalVolume* currentPV = preStepPoint->GetPhysicalVolume();
355 G4String prename = currentPV->GetName();
357 const G4VTouchable* pre_touch = preStepPoint->GetTouchable();
359 G4String name1[20];
int copyno1[20];
360 for(
int i=0;
i<20; ++
i) {
364 if (pre_levels > 0) {
371 if (curstepnumber == 1 ) {
380 if(prename ==
"SBST" ) {
386 if(prename ==
"SBSTs" ) {
394 if (trackstatus != 2 ) {
396 if(prename ==
"SIDETL" || prename ==
"SIDETR" ) {
397 if(prename ==
"SIDETL") {
400 if(prename ==
"SIDETR") {
404 G4String posname = aStep->GetPostStepPoint()->GetPhysicalVolume()->GetName();
405 if((prename ==
"SIDETL" && posname !=
"SIDETL") || (prename ==
"SIDETR" && posname !=
"SIDETR")) {
406 if(name1[2] ==
"SISTATION" ) {
409 if(name1[3] ==
"SIPLANE" ) {
413 if(prename ==
"SIDETL") {
419 else if(copyno1[2]<3) {
423 else if(copyno1[3]<3) {
426 else if(copyno1[3]<4) {
429 else if(copyno1[3]<5) {
432 else if(copyno1[3]<6) {
435 else if(copyno1[3]<7) {
438 else if(copyno1[3]<8) {
441 else if(copyno1[3]<9) {
444 else if(copyno1[3]<10) {
448 else if(copyno1[2]<4) {
451 else if(copyno1[2]<5) {
455 if(prename ==
"SIDETR") {
461 else if(copyno1[2]<3) {
465 else if(copyno1[3]<3) {
468 else if(copyno1[3]<4) {
471 else if(copyno1[3]<5) {
474 else if(copyno1[3]<6) {
477 else if(copyno1[3]<7) {
480 else if(copyno1[3]<8) {
483 else if(copyno1[3]<9) {
486 else if(copyno1[3]<10) {
490 else if(copyno1[2]<4) {
493 else if(copyno1[2]<5) {
505 if (trackstatus == 2 ) {
514 if (parentID == 1 && curstepnumber == 1) {
517 if(prename ==
"SBST" ) {
520 if(prename ==
"SBSTs" ) {
532 return ((touch->GetHistoryDepth())+1);
539 int currentlevel)
const {
542 if (level > 0 && level >= currentlevel) {
543 int ii = level - currentlevel;
544 return touch->GetVolume(ii)->GetName();
551 int* copyno, G4String*
name)
const {
556 int i = level -
ii - 1;
557 G4VPhysicalVolume*
pv = touch->GetVolume(i);
559 name[
ii] = pv->GetName();
561 name[
ii] =
"Unknown";
562 copyno[
ii] = touch->GetReplicaNumber(i);
573 iev = (*evt)()->GetEventID();
574 std::cout <<
"BscTest:update EndOfEvent = " <<
iev << std::endl;
581 G4PrimaryParticle* thePrim=0;
585 G4int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
587 std::cout <<
"BscTest: My warning: NumberOfPrimaryVertex != 1 --> = " << nvertex << std::endl;
589 for (
int i = 0 ;
i<nvertex;
i++) {
590 G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(
i);
592 std::cout <<
"BscTest End Of Event ERR: pointer to vertex = 0" 594 G4int
npart = avertex->GetNumberOfParticle();
596 std::cout <<
"BscTest: My warning: NumberOfPrimaryPart != 1 --> = " << npart << std::endl;
598 std::cout <<
"BscTest End Of Event ERR: no NumberOfParticle" << std::endl;
600 if (thePrim==0) thePrim=avertex->GetPrimary(trackID);
604 G4double vx=0.,vy=0.,vz=0.;
605 vx = avertex->GetX0();
606 vy = avertex->GetY0();
607 vz = avertex->GetZ0();
629 G4ThreeVector mom = thePrim->GetMomentum();
631 double phi = atan2(mom.y(),mom.x());
632 if (phi < 0.) phi += twopi;
633 double phigrad = phi*180./
pi;
635 double th = mom.theta();
656 std::map<int,float,std::less<int> > themap;
657 std::map<int,float,std::less<int> > themap1;
659 std::map<int,float,std::less<int> > themapxy;
660 std::map<int,float,std::less<int> > themapz;
664 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
667 std::cout <<
"BscTest: accessed all HC" << std::endl;;
669 int CAFIid = G4SDManager::GetSDMpointer()->GetCollectionID(
"BSCHits");
673 std::cout <<
"BscTest: theCAFI->entries = " << theCAFI->entries() << std::endl;
683 for (
int j=0; j<theCAFI->entries(); j++) {
685 CLHEP::Hep3Vector hitPoint = aHit->
getEntry();
686 double zz = hitPoint.z();
692 int nhit11 = 0, nhit12 = 0, nhit13 = 0 ;
693 double totallosenergy= 0.;
694 for (
int j=0; j<theCAFI->entries(); j++) {
699 CLHEP::Hep3Vector hitPoint = aHit->
getEntry();
704 double zz = hitPoint.z();
709 std::cout <<
"BscTest:zHits = " << zz << std::endl;
712 themap[unitID] += losenergy;
713 totallosenergy += losenergy;
717 zside = (unitID&32)>>5;
722 G4ThreeVector middle = (hitExitLocalPoint+hitEntryLocalPoint)/2.;
723 themapz[unitID] = hitPoint.z()+middle.z();
728 if(losenergy > 0.00003) {
729 themap1[unitID] += 1.;
735 if(losenergy > 0.00005) {
736 themap1[unitID] += 1.;
767 if( zz < z3 && zz >
z2){
772 if( zz < z4 && zz >
z3){
806 if( zz < z3 && zz >
z2){
828 if( zz < z4 && zz >
z3){
838 if(totallosenergy == 0.0) {
839 std::cout <<
"BscTest: number of hits = " << theCAFI->entries() << std::endl;
840 for (
int j=0; j<theCAFI->entries(); j++) {
843 std::cout <<
" j hits = " << j <<
"losenergy = " << losenergy << std::endl;
847 double totalEnergy = 0.;
848 int nhitsX = 0, nhitsY = 0, nsumhit = 0 ;
849 for (
int sector=1; sector<4; sector++) {
850 int nhitsecX = 0, nhitsecY = 0;
851 for (
int zmodule=1; zmodule<11; zmodule++) {
856 double theTotalEnergy = themap[
index];
860 if(theTotalEnergy > 0.00003) {
869 if(theTotalEnergy > 0.00005) {
876 totalEnergy += themap[
index];
880 if(nhitsecX > 10 || nhitsecY > 10) {
896 std::cout <<
"BscTest: END OF Event " << (*evt)()->GetEventID() << std::endl;
T getParameter(std::string const &) const
G4ThreeVector getEntryLocalP() const
TH1F * GetHisto(Int_t Number)
int detLevels(const G4VTouchable *) const
TH2F * GetHisto2(Int_t Number)
unsigned int getUnitID() const
G4String detName(const G4VTouchable *, int, int) const
std::string fRecreateFile
void WriteToFile(const TString &fOutputFile, const TString &fRecreateFile)
void HistInit(const char *name, const char *title, Int_t nbinsx, Axis_t xlow, Axis_t xup)
BscAnalysisHistManager * TheHistManager
Tan< T >::type tan(const T &t)
BscTest(const edm::ParameterSet &p)
static void unpackBscIndex(const unsigned int &idx)
BscNumberingScheme * theBscNumberingScheme
static unsigned int packBscIndex(int det, int zside, int station)
~BscAnalysisHistManager()
G4ThreeVector getExitLocalP() const
G4ThreeVector getEntry() const
void detectorLevel(const G4VTouchable *, int &, int *, G4String *) const
void update(const BeginOfJob *run)
This routine will be called when the appropriate signal arrives.
G4THitsCollection< BscG4Hit > BscG4HitCollection
BscAnalysisHistManager(const TString &managername)
float getEnergyLoss() const