CMS 3D CMS Logo

BscTest.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 
4 // system include files
5 #include <iostream>
6 #include <iomanip>
7 #include <cmath>
8 #include<vector>
9 //
14 
18 // to retreive hits
22 
23 // G4 stuff
24 #include "G4SDManager.hh"
25 #include "G4Step.hh"
26 #include "G4Track.hh"
27 #include "G4VProcess.hh"
28 #include "G4HCofThisEvent.hh"
29 #include "G4UserEventAction.hh"
30 #include "G4TransportationManager.hh"
31 #include "G4ProcessManager.hh"
32 
33 #include "CLHEP/Units/GlobalSystemOfUnits.h"
34 #include "CLHEP/Units/GlobalPhysicalConstants.h"
35 
36 //================================================================
37 // Root stuff
38 
39 // Include the standard header <cassert> to effectively include
40 // the standard header <assert.h> within the std namespace.
41 #include <cassert>
42 
43 //================================================================
44 
45 //UserVerbosity BscTest::std::cout("BscTest","info","BscTest");
48 };
49 
50 //================================================================
52  //constructor
53  edm::ParameterSet m_Anal = p.getParameter<edm::ParameterSet>("BscTest");
54  verbosity = m_Anal.getParameter<int>("Verbosity");
55  //verbosity = 1;
56 
57  fDataLabel = m_Anal.getParameter<std::string>("FDataLabel");
58  fOutputFile = m_Anal.getParameter<std::string>("FOutputFile");
59  fRecreateFile = m_Anal.getParameter<std::string>("FRecreateFile");
60 
61  if (verbosity > 0) {
62  std::cout<<"============================================================================"<<std::endl;
63  std::cout << "BscTestconstructor :: Initialized as observer"<< std::endl;
64  }
65  // Initialization:
66 
68  bsceventntuple = new TNtuple("NTbscevent","NTbscevent","evt");
69  whichevent = 0;
70  TheHistManager = new BscAnalysisHistManager(fDataLabel);
71 
72  if (verbosity > 0) {
73  std::cout << "BscTest constructor :: Initialized BscAnalysisHistManager"<< std::endl;
74  }
75 }
76 
78  // delete UserNtuples;
79  delete theBscNumberingScheme;
80 
81  TFile bscOutputFile("newntbsc.root","RECREATE");
82  std::cout << "Bsc output root file has been created";
83  bsceventntuple->Write();
84  std::cout << ", written";
85  bscOutputFile.Close();
86  std::cout << ", closed";
87  delete bsceventntuple;
88  std::cout << ", and deleted" << std::endl;
89 
90  //------->while end
91 
92  // Write histograms to file
94  if (verbosity > 0) {
95  std::cout << std::endl << "BscTest Destructor --------> End of BscTest : " << std::endl;
96  }
97 
98  std::cout<<"BscTest: End of process"<<std::endl;
99 }
100 
101 //================================================================
102 // Histoes:
103 //-----------------------------------------------------------------------------
104 
106 {
107  // The Constructor
108 
109  fTypeTitle=managername;
110  fHistArray = new TObjArray(); // Array to store histos
111  fHistNamesArray = new TObjArray(); // Array to store histos's names
112 
113  BookHistos();
114 
115  fHistArray->Compress(); // Removes empty space
116  fHistNamesArray->Compress();
117 }
118 //-----------------------------------------------------------------------------
119 
121 {
122  // The Destructor
123 
124  if(fHistArray){
125  fHistArray->Delete();
126  delete fHistArray;
127  }
128 
129  if(fHistNamesArray){
130  fHistNamesArray->Delete();
131  delete fHistNamesArray;
132  }
133 }
134 //-----------------------------------------------------------------------------
135 
137 {
138  // at Start: (mm)
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 );
144 }
145 
146 //-----------------------------------------------------------------------------
147 
149 {
150 
151  //Write to file = fOutputFile
152 
153  std::cout <<"================================================================"<<std::endl;
154  std::cout <<" Write this Analysis to File "<<fOutputFile<<std::endl;
155  std::cout <<"================================================================"<<std::endl;
156 
157  TFile* file = new TFile(fOutputFile, fRecreateFile);
158 
159  fHistArray->Write();
160  file->Close();
161 }
162 //-----------------------------------------------------------------------------
163 
164 void BscAnalysisHistManager::HistInit(const char* name, const char* title, Int_t nbinsx, Axis_t xlow, Axis_t xup)
165 {
166  // Add histograms and histograms names to the array
167 
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));
175 
176 }
177 //-----------------------------------------------------------------------------
178 
179 void BscAnalysisHistManager::HistInit(const char* name, const char* title, Int_t nbinsx, Axis_t xlow, Axis_t xup, Int_t nbinsy, Axis_t ylow, Axis_t yup)
180 {
181  // Add histograms and histograms names to the array
182 
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));
190 
191 }
192 //-----------------------------------------------------------------------------
193 
195 {
196  // Get a histogram from the array with index = Number
197 
198  if (Number <= fHistArray->GetLast() && fHistArray->At(Number) != (TObject*)nullptr){
199 
200  return (TH1F*)(fHistArray->At(Number));
201 
202  }else{
203 
204  std::cout << "!!!!!!!!!!!!!!!!!!GetHisto!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
205  std::cout << " WARNING ERROR - HIST ID INCORRECT (TOO HIGH) - " << Number << std::endl;
206  std::cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
207 
208  return (TH1F*)(fHistArray->At(0));
209  }
210 }
211 //-----------------------------------------------------------------------------
212 
214 {
215  // Get a histogram from the array with index = Number
216 
217  if (Number <= fHistArray->GetLast() && fHistArray->At(Number) != (TObject*)nullptr){
218 
219  return (TH2F*)(fHistArray->At(Number));
220 
221  }else{
222 
223  std::cout << "!!!!!!!!!!!!!!!!GetHisto2!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
224  std::cout << " WARNING ERROR - HIST ID INCORRECT (TOO HIGH) - " << Number << std::endl;
225  std::cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
226 
227  return (TH2F*)(fHistArray->At(0));
228  }
229 }
230 //-----------------------------------------------------------------------------
231 
232 TH1F* BscAnalysisHistManager::GetHisto(const TObjString& histname)
233 {
234  // Get a histogram from the array with name = histname
235 
236  Int_t index = fHistNamesArray->IndexOf(&histname);
237  return GetHisto(index);
238 }
239 //-----------------------------------------------------------------------------
240 
241 TH2F* BscAnalysisHistManager::GetHisto2(const TObjString& histname)
242 {
243  // Get a histogram from the array with name = histname
244 
245  Int_t index = fHistNamesArray->IndexOf(&histname);
246  return GetHisto2(index);
247 }
248 //-----------------------------------------------------------------------------
249 
251 {
252  // Add structure to each histogram to store the weights
253 
254  for(int i = 0; i < fHistArray->GetEntries(); i++){
255  ((TH1F*)(fHistArray->At(i)))->Sumw2();
256  }
257 }
258 
259 
260 //==================================================================== per JOB
261 void BscTest::update(const BeginOfJob * job) {
262  //job
263  std::cout<<"BscTest:beggining of job"<<std::endl;;
264 }
265 
266 //==================================================================== per RUN
268  //run
269 
270  std::cout << std::endl << "BscTest:: Begining of Run"<< std::endl;
271 }
272 
273 void BscTest::update(const EndOfRun * run) {;}
274 
275 //=================================================================== per EVENT
276 void BscTest::update(const BeginOfEvent * evt) {
277  iev = (*evt)()->GetEventID();
278  if (verbosity > 0) {
279  std::cout <<"BscTest:update Event number = " << iev << std::endl;
280  }
281  whichevent++;
282 }
283 
284 //=================================================================== per Track
285 void BscTest::update(const BeginOfTrack * trk) {
286  itrk = (*trk)()->GetTrackID();
287  if (verbosity > 1) {
288  std::cout <<"BscTest:update BeginOfTrack number = " << itrk << std::endl;
289  }
290  if(itrk == 1) {
291  SumEnerDeposit = 0.;
292  numofpart = 0;
293  SumStepl = 0.;
294  SumStepc = 0.;
295  tracklength0 = 0.;
296  }
297 }
298 
299 //=================================================================== per EndOfTrack
300 void BscTest::update(const EndOfTrack * trk) {
301  itrk = (*trk)()->GetTrackID();
302  if (verbosity > 1) {
303  std::cout <<"BscTest:update EndOfTrack number = " << itrk << std::endl;
304  }
305  if(itrk == 1) {
306  G4double tracklength = (*trk)()->GetTrackLength(); // Accumulated track length
307 
308  TheHistManager->GetHisto("SumEDep")->Fill(SumEnerDeposit);
309  TheHistManager->GetHisto("TrackL")->Fill(tracklength);
310 
311  // direction !!!
312  G4ThreeVector vert_mom = (*trk)()->GetVertexMomentumDirection();
313  G4ThreeVector vert_pos = (*trk)()->GetVertexPosition(); // vertex ,where this track was created
314 
315  // last step information
316  const G4Step* aStep = (*trk)()->GetStep();
317  G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
318  lastpo = preStepPoint->GetPosition();
319  }
320 }
321 
322 // ====================================================
323 
324 //=================================================================== each STEP
325 void BscTest::update(const G4Step * aStep) {
326  // ==========================================================================
327 
328  if (verbosity > 2) {
329  G4int stepnumber = aStep->GetTrack()->GetCurrentStepNumber();
330  std::cout <<"BscTest:update Step number = " << stepnumber << std::endl;
331  }
332  // track on aStep: !
333  G4Track* theTrack = aStep->GetTrack();
334  TrackInformation* trkInfo = dynamic_cast<TrackInformation*> (theTrack->GetUserInformation());
335  if (trkInfo == nullptr) {
336  std::cout << "BscTest on aStep: No trk info !!!! abort " << std::endl;
337  }
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(); // Accumulated track length
343  G4ThreeVector trackmom = theTrack->GetMomentum();
344  G4double entot = theTrack->GetTotalEnergy(); // !!! deposited on step
345  G4int curstepnumber = theTrack->GetCurrentStepNumber();
346  G4double stepl = aStep->GetStepLength();
347  G4double EnerDeposit = aStep->GetTotalEnergyDeposit();
348  G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
349  const G4ThreeVector& preposition = preStepPoint->GetPosition();
350  G4ThreeVector prelocalpoint = theTrack->GetTouchable()->GetHistory()->
351  GetTopTransform().TransformPoint(preposition);
352  G4VPhysicalVolume* currentPV = preStepPoint->GetPhysicalVolume();
353  const G4String& prename = currentPV->GetName();
354 
355  const G4VTouchable* pre_touch = preStepPoint->GetTouchable();
356  int pre_levels = detLevels(pre_touch);
357  G4String name1[20]; int copyno1[20];
358  for(int i=0; i<20; ++i) {
359  name1[i] = "";
360  copyno1[i] = 0;
361  }
362  if (pre_levels > 0) {
363  detectorLevel(pre_touch, pre_levels, copyno1, name1);
364  }
365 
366  if ( id == 1 ) {
367 
368  // on 1-st step:
369  if (curstepnumber == 1 ) {
370  entot0 = entot;
371  //UserNtuples->fillg519(entot0,1.);
372 
373  }
374 
375  // on every step:
376 
377  // for Copper:
378  if(prename == "SBST" ) {
379  SumStepc += stepl;
380  // =========
381  }
382  // for ststeel:
383  // if(prename == "SBSTs") {
384  if(prename == "SBSTs" ) {
385  SumStepl += stepl;
386  // =========
387  }
388  // =========
389  // =========
390 
391  // exclude last track point if it is in SD (MI was started their)
392  if (trackstatus != 2 ) {
393  // for SD: Si Det.: SISTATION:SIPLANE:(SIDETL+BOUNDDET +SIDETR + CERAMDET)
394  if(prename == "SIDETL" || prename == "SIDETR" ) {
395  if(prename == "SIDETL") {
396  //UserNtuples->fillg569(EnerDeposit,1.);
397  }
398  if(prename == "SIDETR") {
399  //UserNtuples->fillg570(EnerDeposit,1.);
400  }
401 
402  G4String posname = aStep->GetPostStepPoint()->GetPhysicalVolume()->GetName();
403  if((prename == "SIDETL" && posname != "SIDETL") || (prename == "SIDETR" && posname != "SIDETR")) {
404  if(name1[2] == "SISTATION" ) {
405  //UserNtuples->fillg539(copyno1[2],1.);
406  }
407  if(name1[3] == "SIPLANE" ) {
408  //UserNtuples->fillg540(copyno1[3],1.);
409  }
410 
411  if(prename == "SIDETL") {
412  //UserNtuples->fillg541(EnerDeposit,1.);
413  //UserNtuples->fillg561(numbcont,1.);
414  if(copyno1[2]<2) {
415  //UserNtuples->fillg571(dx,1.);
416  }
417  else if(copyno1[2]<3) {
418  //UserNtuples->fillg563(dx,1.);
419  if(copyno1[3]<2) {
420  }
421  else if(copyno1[3]<3) {
422  //UserNtuples->fillg572(dx,1.);
423  }
424  else if(copyno1[3]<4) {
425  //UserNtuples->fillg573(dx,1.);
426  }
427  else if(copyno1[3]<5) {
428  //UserNtuples->fillg574(dx,1.);
429  }
430  else if(copyno1[3]<6) {
431  //UserNtuples->fillg575(dx,1.);
432  }
433  else if(copyno1[3]<7) {
434  //UserNtuples->fillg576(dx,1.);
435  }
436  else if(copyno1[3]<8) {
437  //UserNtuples->fillg577(dx,1.);
438  }
439  else if(copyno1[3]<9) {
440  //UserNtuples->fillg578(dx,1.);
441  }
442  else if(copyno1[3]<10) {
443  //UserNtuples->fillg579(dx,1.);
444  }
445  }
446  else if(copyno1[2]<4) {
447  //UserNtuples->fillg565(dx,1.);
448  }
449  else if(copyno1[2]<5) {
450  //UserNtuples->fillg567(dx,1.);
451  }
452  }
453  if(prename == "SIDETR") {
454  //UserNtuples->fillg542(EnerDeposit,1.);
455  //UserNtuples->fillg562(numbcont,1.);
456  if(copyno1[2]<2) {
457  //UserNtuples->fillg581(dy,1.);
458  }
459  else if(copyno1[2]<3) {
460  //UserNtuples->fillg564(dy,1.);
461  if(copyno1[3]<2) {
462  }
463  else if(copyno1[3]<3) {
464  //UserNtuples->fillg582(dy,1.);
465  }
466  else if(copyno1[3]<4) {
467  //UserNtuples->fillg583(dy,1.);
468  }
469  else if(copyno1[3]<5) {
470  //UserNtuples->fillg584(dy,1.);
471  }
472  else if(copyno1[3]<6) {
473  //UserNtuples->fillg585(dy,1.);
474  }
475  else if(copyno1[3]<7) {
476  //UserNtuples->fillg586(dy,1.);
477  }
478  else if(copyno1[3]<8) {
479  //UserNtuples->fillg587(dy,1.);
480  }
481  else if(copyno1[3]<9) {
482  //UserNtuples->fillg588(dy,1.);
483  }
484  else if(copyno1[3]<10) {
485  //UserNtuples->fillg589(dy,1.);
486  }
487  }
488  else if(copyno1[2]<4) {
489  //UserNtuples->fillg566(dy,1.);
490  }
491  else if(copyno1[2]<5) {
492  //UserNtuples->fillg568(dy,1.);
493  }
494  }
495 
496  }
497  }
498  // end of prenames SIDETL // SIDETR
499  }
500  // end of trackstatus != 2
501 
502  SumEnerDeposit += EnerDeposit;
503  if (trackstatus == 2 ) {
504  // primary track length
505  // //UserNtuples->fillg508(tracklength,1.);
506  tracklength0 = tracklength;
507  }
508  }
509  // end of primary track !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
510 
511 
512  if (parentID == 1 && curstepnumber == 1) {
513  // particles deposit their energy along primary track
514  numofpart += 1;
515  if(prename == "SBST" ) {
516  //UserNtuples->filld225(vert_pos.y(),vert_pos.z(),1.);
517  }
518  if(prename == "SBSTs" ) {
519  //UserNtuples->filld226(vert_pos.y(),vert_pos.z(),1.);
520  }
521  }
522 
523 }
524 // ==========================================================================
525 // ==========================================================================
526 int BscTest::detLevels(const G4VTouchable* touch) const {
527 
528  //Return number of levels
529  if (touch)
530  return ((touch->GetHistoryDepth())+1);
531  else
532  return 0;
533 }
534 // ==========================================================================
535 
536 G4String BscTest::detName(const G4VTouchable* touch, int level,
537  int currentlevel) const {
538 
539  //Go down to current level
540  if (level > 0 && level >= currentlevel) {
541  int ii = level - currentlevel;
542  return touch->GetVolume(ii)->GetName();
543  } else {
544  return "NotFound";
545  }
546 }
547 
548 void BscTest::detectorLevel(const G4VTouchable* touch, int& level,
549  int* copyno, G4String* name) const {
550 
551  //Get name and copy numbers
552  if (level > 0) {
553  for (int ii = 0; ii < level; ii++) {
554  int i = level - ii - 1;
555  G4VPhysicalVolume* pv = touch->GetVolume(i);
556  if (pv != nullptr)
557  name[ii] = pv->GetName();
558  else
559  name[ii] = "Unknown";
560  copyno[ii] = touch->GetReplicaNumber(i);
561  }
562  }
563 }
564 // ==========================================================================
565 
566 //=================================================================== End Of Event
567 void BscTest::update(const EndOfEvent * evt) {
568  // ==========================================================================
569 
570  if (verbosity > 1) {
571  iev = (*evt)()->GetEventID();
572  std::cout <<"BscTest:update EndOfEvent = " << iev << std::endl;
573  }
574  // Fill-in ntuple
576 
577  //
578  int trackID = 0;
579  G4PrimaryParticle* thePrim=nullptr;
580 
581 
582  // prim.vertex:
583  G4int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
584  if (nvertex !=1)
585  std::cout << "BscTest: My warning: NumberOfPrimaryVertex != 1 --> = " << nvertex << std::endl;
586 
587  for (int i = 0 ; i<nvertex; i++) {
588  G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(i);
589  if (avertex == nullptr)
590  std::cout << "BscTest End Of Event ERR: pointer to vertex = 0"
591  << std::endl;
592  G4int npart = avertex->GetNumberOfParticle();
593  if (npart !=1)
594  std::cout << "BscTest: My warning: NumberOfPrimaryPart != 1 --> = " << npart << std::endl;
595  if (npart ==0)
596  std::cout << "BscTest End Of Event ERR: no NumberOfParticle" << std::endl;
597 
598  if (thePrim==nullptr) thePrim=avertex->GetPrimary(trackID);
599 
600  if (thePrim!=nullptr) {
601  // primary vertex:
602  G4double vx=0.,vy=0.,vz=0.;
603  vx = avertex->GetX0();
604  vy = avertex->GetY0();
605  vz = avertex->GetZ0();
606  //UserNtuples->fillh01(vx);
607  //UserNtuples->fillh02(vy);
608  //UserNtuples->fillh03(vz);
609  TheHistManager->GetHisto("VtxX")->Fill(vx);
610  TheHistManager->GetHisto("VtxY")->Fill(vy);
611  TheHistManager->GetHisto("VtxZ")->Fill(vz);
612  }
613  }
614  // prim.vertex loop end
615 
616  //=========================== thePrim != 0 ================================================================================
617  if (thePrim != nullptr) {
618  //
619  // number of secondary particles deposited their energy along primary track
620  //UserNtuples->fillg518(numofpart,1.);
621  if(lastpo.z()<z4 && lastpo.perp()< 100.) {
622  //UserNtuples->fillg536(numofpart,1.);
623  }
624  //
625 
626  // direction !!!
627  G4ThreeVector mom = thePrim->GetMomentum();
628 
629  double phi = atan2(mom.y(),mom.x());
630  if (phi < 0.) phi += twopi;
631  double phigrad = phi*180./pi;
632 
633  double th = mom.theta();
634  double eta = -log(tan(th/2));
635  TheHistManager->GetHisto("PrimaryEta")->Fill(eta);
636  TheHistManager->GetHisto("PrimaryPhigrad")->Fill(phigrad);
637  TheHistManager->GetHisto("PrimaryTh")->Fill(th*180./pi);
638 
639  TheHistManager->GetHisto("PrimaryLastpoZ")->Fill(lastpo.z());
640  if(lastpo.z() < z4 ) {
641  TheHistManager->GetHisto("PrimaryLastpoX")->Fill(lastpo.x());
642  TheHistManager->GetHisto("PrimaryLastpoY")->Fill(lastpo.y());
643  }
644  if(numofpart > 4 ) {
645  TheHistManager->GetHisto("XLastpoNumofpart")->Fill(lastpo.x());
646  TheHistManager->GetHisto("YLastpoNumofpart")->Fill(lastpo.y());
647  }
648 
649  // ==========================================================================
650 
651  // hit map for Bsc
652  // ==================================
653 
654  std::map<int,float,std::less<int> > themap;
655  std::map<int,float,std::less<int> > themap1;
656 
657  std::map<int,float,std::less<int> > themapxy;
658  std::map<int,float,std::less<int> > themapz;
659  // access to the G4 hit collections: -----> this work OK:
660 
661  // edm::LogInfo("BscTest") << "1";
662  G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
663  // edm::LogInfo("BscTest") << "2";
664  if (verbosity > 0) {
665  std::cout << "BscTest: accessed all HC" << std::endl;;
666  }
667  int CAFIid = G4SDManager::GetSDMpointer()->GetCollectionID("BSCHits");
668 
669  BscG4HitCollection* theCAFI = (BscG4HitCollection*) allHC->GetHC(CAFIid);
670  if (verbosity > 0) {
671  std::cout << "BscTest: theCAFI->entries = " << theCAFI->entries() << std::endl;
672  }
673  int varia ; // = 0 -all; =1 - MI; =2 - noMI
674  //varia = 0;
675  if( lastpo.z()< z4) {
676  varia = 1;
677  }
678  else{
679  varia = 2;
680  } // no MI end:
681  for (int j=0; j<theCAFI->entries(); j++) {
682  BscG4Hit* aHit = (*theCAFI)[j];
683  CLHEP::Hep3Vector hitPoint = aHit->getEntry();
684  double zz = hitPoint.z();
685  TheHistManager->GetHisto("zHits")->Fill(zz);
686  if(tracklength0>8300.) TheHistManager->GetHisto("zHitsTrLoLe")->Fill(zz);
687  }
688 
689  if( varia == 2) {
690  int nhit11 = 0, nhit12 = 0, nhit13 = 0 ;
691  double totallosenergy= 0.;
692  for (int j=0; j<theCAFI->entries(); j++) {
693  BscG4Hit* aHit = (*theCAFI)[j];
694 
695  CLHEP::Hep3Vector hitEntryLocalPoint = aHit->getEntryLocalP();
696  CLHEP::Hep3Vector hitExitLocalPoint = aHit->getExitLocalP();
697  CLHEP::Hep3Vector hitPoint = aHit->getEntry();
698  int trackIDhit = aHit->getTrackID();
699  unsigned int unitID = aHit->getUnitID();
700  double losenergy = aHit->getEnergyLoss();
701 
702  double zz = hitPoint.z();
703 
704  TheHistManager->GetHisto("zHitsnoMI")->Fill(zz);
705 
706  if (verbosity > 2) {
707  std::cout << "BscTest:zHits = " << zz << std::endl;
708  }
709 
710  themap[unitID] += losenergy;
711  totallosenergy += losenergy;
712 
713  int zside, sector;
715  zside = (unitID&32)>>5;
716  sector = (unitID&7);
717 
718  //
719  //=======================================
720  G4ThreeVector middle = (hitExitLocalPoint+hitEntryLocalPoint)/2.;
721  themapz[unitID] = hitPoint.z()+middle.z();
722  //=======================================
723  // Y
724  if(zside==1) {
725  //UserNtuples->fillg24(losenergy,1.);
726  if(losenergy > 0.00003) {
727  themap1[unitID] += 1.;
728  }
729  }
730  //X
731  if(zside==2){
732  //UserNtuples->fillg25(losenergy,1.);
733  if(losenergy > 0.00005) {
734  themap1[unitID] += 1.;
735  }
736  }
737  // }
738  //
739  if(sector==1) {
740  nhit11 += 1;
741  //UserNtuples->fillg33(rr,1.);
742  //UserNtuples->fillg11(yy,1.);
743  }
744  if(sector==2) {
745  nhit12 += 1;
746  //UserNtuples->fillg34(rr,1.);
747  //UserNtuples->fillg86(yy,1.);
748  }
749  if(sector==3) {
750  nhit13 += 1;
751  //UserNtuples->fillg35(rr,1.);
752  //UserNtuples->fillg87(yy,1.);
753  }
754 
755  if(lastpo.z()<z4 && lastpo.perp()< 120.) {
756  // MIonly:
757  //UserNtuples->fillg16(lastpo.z(),1.);
758  //UserNtuples->fillg18(zz,1.);
759  // Station I
760  if( zz < z2){
761  //UserNtuples->fillg54(dx,1.);
762  //UserNtuples->fillg55(dy,1.);
763  }
764  // Station II
765  if( zz < z3 && zz > z2){
766  //UserNtuples->fillg50(dx,1.);
767  //UserNtuples->fillg51(dy,1.);
768  }
769  // Station III
770  if( zz < z4 && zz > z3){
771  //UserNtuples->fillg64(dx,1.);
772  //UserNtuples->fillg65(dy,1.);
773  //UserNtuples->filld209(xx,yy,1.);
774  }
775  }
776  else{
777  // no MIonly:
778  //UserNtuples->fillg17(lastpo.z(),1.);
779  //UserNtuples->fillg19(zz,1.);
780  //UserNtuples->fillg74(incidentEnergyHit,1.);
781  //UserNtuples->fillg75(float(trackIDhit),1.);
782  // Station I
783  if( zz < z2){
784  //UserNtuples->fillg56(dx,1.);
785  //UserNtuples->fillg57(dy,1.);
786  //UserNtuples->fillg20(numofpart,1.);
787  //UserNtuples->fillg21(SumEnerDeposit,1.);
788  if(zside==1) {
789  //UserNtuples->fillg26(losenergy,1.);
790  }
791  if(zside==2){
792  //UserNtuples->fillg76(losenergy,1.);
793  }
794  if(trackIDhit == 1){
795  //UserNtuples->fillg70(dx,1.);
796  //UserNtuples->fillg71(incidentEnergyHit,1.);
797  //UserNtuples->fillg79(losenergy,1.);
798  }
799  else{
800  //UserNtuples->fillg82(dx,1.);
801  }
802  }
803  // Station II
804  if( zz < z3 && zz > z2){
805  //UserNtuples->fillg52(dx,1.);
806  //UserNtuples->fillg53(dy,1.);
807  //UserNtuples->fillg22(numofpart,1.);
808  //UserNtuples->fillg23(SumEnerDeposit,1.);
809  //UserNtuples->fillg80(incidentEnergyHit,1.);
810  //UserNtuples->fillg81(float(trackIDhit),1.);
811  if(zside==1) {
812  //UserNtuples->fillg27(losenergy,1.);
813  }
814  if(zside==2){
815  //UserNtuples->fillg77(losenergy,1.);
816  }
817  if(trackIDhit == 1){
818  //UserNtuples->fillg72(dx,1.);
819  //UserNtuples->fillg73(incidentEnergyHit,1.);
820  }
821  else{
822  //UserNtuples->fillg83(dx,1.);
823  }
824  }
825  // Station III
826  if( zz < z4 && zz > z3){
827  if(zside==1) {
828  //UserNtuples->fillg28(losenergy,1.);
829  }
830  if(zside==2){
831  //UserNtuples->fillg78(losenergy,1.);
832  }
833  }
834  }
835  } // MIonly or noMIonly ENDED
836  if(totallosenergy == 0.0) {
837  std::cout << "BscTest: number of hits = " << theCAFI->entries() << std::endl;
838  for (int j=0; j<theCAFI->entries(); j++) {
839  BscG4Hit* aHit = (*theCAFI)[j];
840  double losenergy = aHit->getEnergyLoss();
841  std::cout << " j hits = " << j << "losenergy = " << losenergy << std::endl;
842  }
843  }
844  // FIBRE Hit collected analysis
845  double totalEnergy = 0.;
846  int nhitsX = 0, nhitsY = 0, nsumhit = 0 ;
847  for (int sector=1; sector<4; sector++) {
848  int nhitsecX = 0, nhitsecY = 0;
849  for (int zmodule=1; zmodule<11; zmodule++) {
850  for (int zside=1; zside<3; zside++) {
851  int det= 1;// nhit = 0;
852  // int sScale = 20;
853  int index = BscNumberingScheme::packBscIndex(det, zside, sector);
854  double theTotalEnergy = themap[index];
855  // X planes
856  if(zside<2){
857  //UserNtuples->fillg47(theTotalEnergy,1.);
858  if(theTotalEnergy > 0.00003) {
859  nhitsX += 1;
860  // nhitsecX += themap1[index];
861  // nhit=1;
862  }
863  }
864  // Y planes
865  else {
866  //UserNtuples->fillg49(theTotalEnergy,1.);
867  if(theTotalEnergy > 0.00005) {
868  nhitsY += 1;
869  // nhitsecY += themap1[index];
870  // nhit=1;
871  }
872  }
873 
874  totalEnergy += themap[index];
875  } // for
876  } // for
877  //UserNtuples->fillg39(nhitsecY,1.);
878  if(nhitsecX > 10 || nhitsecY > 10) {
879  nsumhit +=1;
880  //UserNtuples->fillp213(float(sector),float(1.),1.);
881  }
882  else{ //UserNtuples->fillp213(float(sector),float(0.),1.);
883  }
884  } // for
885 
886  if( nsumhit >=2 ) { //UserNtuples->fillp212(vy,float(1.),1.);
887  }
888  else{ //UserNtuples->fillp212(vy,float(0.),1.);
889  }
890  } // MI or no MI or all - end
891  } // primary end
892 
893  if (verbosity > 0) {
894  std::cout << "BscTest: END OF Event " << (*evt)()->GetEventID() << std::endl;
895  }
896 
897 }
898 
T getParameter(std::string const &) const
int numofpart
Definition: BscTest.h:216
double z2
Definition: BscTest.h:222
G4double SumStepl
Definition: BscTest.h:214
G4ThreeVector getEntryLocalP() const
Definition: BSCG4Hit.cc:118
TH1F * GetHisto(Int_t Number)
Definition: BscTest.cc:194
G4int getTrackID() const
Definition: BSCG4Hit.cc:133
int detLevels(const G4VTouchable *) const
Definition: BscTest.cc:526
std::string fOutputFile
Definition: BscTest.h:233
TH2F * GetHisto2(Int_t Number)
Definition: BscTest.cc:213
double npart
Definition: HydjetWrapper.h:49
int zside(DetId const &)
G4ThreeVector lastpo
Definition: BscTest.h:218
unsigned int getUnitID() const
Definition: BSCG4Hit.cc:136
int iev
Definition: BscTest.h:197
G4String detName(const G4VTouchable *, int, int) const
Definition: BscTest.cc:536
std::string fRecreateFile
Definition: BscTest.h:234
const Double_t pi
int verbosity
Definition: BscTest.h:211
double z4
Definition: BscTest.h:222
int whichevent
Definition: BscTest.h:229
void WriteToFile(const TString &fOutputFile, const TString &fRecreateFile)
Definition: BscTest.cc:148
std::string fDataLabel
Definition: BscTest.h:232
G4double entot0
Definition: BscTest.h:199
void HistInit(const char *name, const char *title, Int_t nbinsx, Axis_t xlow, Axis_t xup)
Definition: BscTest.cc:164
BscAnalysisHistManager * TheHistManager
Definition: BscTest.h:231
double z3
Definition: BscTest.h:222
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
def pv(vc)
Definition: MetAnalyzer.py:6
G4double SumEnerDeposit
Definition: BscTest.h:214
void update(const BeginOfJob *run) override
This routine will be called when the appropriate signal arrives.
Definition: BscTest.cc:261
BscTest(const edm::ParameterSet &p)
Definition: BscTest.cc:51
static void unpackBscIndex(const unsigned int &idx)
BscNumberingScheme * theBscNumberingScheme
Definition: BscTest.h:194
ii
Definition: cuy.py:588
static unsigned int packBscIndex(int det, int zside, int station)
TNtuple * bsceventntuple
Definition: BscTest.h:227
G4ThreeVector getExitLocalP() const
Definition: BSCG4Hit.cc:121
~BscTest() override
Definition: BscTest.cc:77
G4ThreeVector getEntry() const
Definition: BSCG4Hit.cc:115
void detectorLevel(const G4VTouchable *, int &, int *, G4String *) const
Definition: BscTest.cc:548
int itrk
Definition: BscTest.h:198
Float_t bsceventarray[1]
Definition: BscTest.h:226
G4double SumStepc
Definition: BscTest.h:214
TFile bscOutputFile
Definition: BscTest.h:228
G4THitsCollection< BscG4Hit > BscG4HitCollection
ntbsc_elements
Definition: BscTest.cc:46
BscAnalysisHistManager(const TString &managername)
Definition: BscTest.cc:105
float getEnergyLoss() const
Definition: BSCG4Hit.cc:150
G4double tracklength0
Definition: BscTest.h:199
~BscAnalysisHistManager() override
Definition: BscTest.cc:120