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*)0){
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*)0){
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 == 0) {
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  G4ThreeVector vert_pos = theTrack->GetVertexPosition(); // vertex ,where this track was created
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();
356 
357  const G4VTouchable* pre_touch = preStepPoint->GetTouchable();
358  int pre_levels = detLevels(pre_touch);
359  G4String name1[20]; int copyno1[20];
360  for(int i=0; i<20; ++i) {
361  name1[i] = "";
362  copyno1[i] = 0;
363  }
364  if (pre_levels > 0) {
365  detectorLevel(pre_touch, pre_levels, copyno1, name1);
366  }
367 
368  if ( id == 1 ) {
369 
370  // on 1-st step:
371  if (curstepnumber == 1 ) {
372  entot0 = entot;
373  //UserNtuples->fillg519(entot0,1.);
374 
375  }
376 
377  // on every step:
378 
379  // for Copper:
380  if(prename == "SBST" ) {
381  SumStepc += stepl;
382  // =========
383  }
384  // for ststeel:
385  // if(prename == "SBSTs") {
386  if(prename == "SBSTs" ) {
387  SumStepl += stepl;
388  // =========
389  }
390  // =========
391  // =========
392 
393  // exclude last track point if it is in SD (MI was started their)
394  if (trackstatus != 2 ) {
395  // for SD: Si Det.: SISTATION:SIPLANE:(SIDETL+BOUNDDET +SIDETR + CERAMDET)
396  if(prename == "SIDETL" || prename == "SIDETR" ) {
397  if(prename == "SIDETL") {
398  //UserNtuples->fillg569(EnerDeposit,1.);
399  }
400  if(prename == "SIDETR") {
401  //UserNtuples->fillg570(EnerDeposit,1.);
402  }
403 
404  G4String posname = aStep->GetPostStepPoint()->GetPhysicalVolume()->GetName();
405  if((prename == "SIDETL" && posname != "SIDETL") || (prename == "SIDETR" && posname != "SIDETR")) {
406  if(name1[2] == "SISTATION" ) {
407  //UserNtuples->fillg539(copyno1[2],1.);
408  }
409  if(name1[3] == "SIPLANE" ) {
410  //UserNtuples->fillg540(copyno1[3],1.);
411  }
412 
413  if(prename == "SIDETL") {
414  //UserNtuples->fillg541(EnerDeposit,1.);
415  //UserNtuples->fillg561(numbcont,1.);
416  if(copyno1[2]<2) {
417  //UserNtuples->fillg571(dx,1.);
418  }
419  else if(copyno1[2]<3) {
420  //UserNtuples->fillg563(dx,1.);
421  if(copyno1[3]<2) {
422  }
423  else if(copyno1[3]<3) {
424  //UserNtuples->fillg572(dx,1.);
425  }
426  else if(copyno1[3]<4) {
427  //UserNtuples->fillg573(dx,1.);
428  }
429  else if(copyno1[3]<5) {
430  //UserNtuples->fillg574(dx,1.);
431  }
432  else if(copyno1[3]<6) {
433  //UserNtuples->fillg575(dx,1.);
434  }
435  else if(copyno1[3]<7) {
436  //UserNtuples->fillg576(dx,1.);
437  }
438  else if(copyno1[3]<8) {
439  //UserNtuples->fillg577(dx,1.);
440  }
441  else if(copyno1[3]<9) {
442  //UserNtuples->fillg578(dx,1.);
443  }
444  else if(copyno1[3]<10) {
445  //UserNtuples->fillg579(dx,1.);
446  }
447  }
448  else if(copyno1[2]<4) {
449  //UserNtuples->fillg565(dx,1.);
450  }
451  else if(copyno1[2]<5) {
452  //UserNtuples->fillg567(dx,1.);
453  }
454  }
455  if(prename == "SIDETR") {
456  //UserNtuples->fillg542(EnerDeposit,1.);
457  //UserNtuples->fillg562(numbcont,1.);
458  if(copyno1[2]<2) {
459  //UserNtuples->fillg581(dy,1.);
460  }
461  else if(copyno1[2]<3) {
462  //UserNtuples->fillg564(dy,1.);
463  if(copyno1[3]<2) {
464  }
465  else if(copyno1[3]<3) {
466  //UserNtuples->fillg582(dy,1.);
467  }
468  else if(copyno1[3]<4) {
469  //UserNtuples->fillg583(dy,1.);
470  }
471  else if(copyno1[3]<5) {
472  //UserNtuples->fillg584(dy,1.);
473  }
474  else if(copyno1[3]<6) {
475  //UserNtuples->fillg585(dy,1.);
476  }
477  else if(copyno1[3]<7) {
478  //UserNtuples->fillg586(dy,1.);
479  }
480  else if(copyno1[3]<8) {
481  //UserNtuples->fillg587(dy,1.);
482  }
483  else if(copyno1[3]<9) {
484  //UserNtuples->fillg588(dy,1.);
485  }
486  else if(copyno1[3]<10) {
487  //UserNtuples->fillg589(dy,1.);
488  }
489  }
490  else if(copyno1[2]<4) {
491  //UserNtuples->fillg566(dy,1.);
492  }
493  else if(copyno1[2]<5) {
494  //UserNtuples->fillg568(dy,1.);
495  }
496  }
497 
498  }
499  }
500  // end of prenames SIDETL // SIDETR
501  }
502  // end of trackstatus != 2
503 
504  SumEnerDeposit += EnerDeposit;
505  if (trackstatus == 2 ) {
506  // primary track length
507  // //UserNtuples->fillg508(tracklength,1.);
508  tracklength0 = tracklength;
509  }
510  }
511  // end of primary track !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
512 
513 
514  if (parentID == 1 && curstepnumber == 1) {
515  // particles deposit their energy along primary track
516  numofpart += 1;
517  if(prename == "SBST" ) {
518  //UserNtuples->filld225(vert_pos.y(),vert_pos.z(),1.);
519  }
520  if(prename == "SBSTs" ) {
521  //UserNtuples->filld226(vert_pos.y(),vert_pos.z(),1.);
522  }
523  }
524 
525 }
526 // ==========================================================================
527 // ==========================================================================
528 int BscTest::detLevels(const G4VTouchable* touch) const {
529 
530  //Return number of levels
531  if (touch)
532  return ((touch->GetHistoryDepth())+1);
533  else
534  return 0;
535 }
536 // ==========================================================================
537 
538 G4String BscTest::detName(const G4VTouchable* touch, int level,
539  int currentlevel) const {
540 
541  //Go down to current level
542  if (level > 0 && level >= currentlevel) {
543  int ii = level - currentlevel;
544  return touch->GetVolume(ii)->GetName();
545  } else {
546  return "NotFound";
547  }
548 }
549 
550 void BscTest::detectorLevel(const G4VTouchable* touch, int& level,
551  int* copyno, G4String* name) const {
552 
553  //Get name and copy numbers
554  if (level > 0) {
555  for (int ii = 0; ii < level; ii++) {
556  int i = level - ii - 1;
557  G4VPhysicalVolume* pv = touch->GetVolume(i);
558  if (pv != 0)
559  name[ii] = pv->GetName();
560  else
561  name[ii] = "Unknown";
562  copyno[ii] = touch->GetReplicaNumber(i);
563  }
564  }
565 }
566 // ==========================================================================
567 
568 //=================================================================== End Of Event
569 void BscTest::update(const EndOfEvent * evt) {
570  // ==========================================================================
571 
572  if (verbosity > 1) {
573  iev = (*evt)()->GetEventID();
574  std::cout <<"BscTest:update EndOfEvent = " << iev << std::endl;
575  }
576  // Fill-in ntuple
578 
579  //
580  int trackID = 0;
581  G4PrimaryParticle* thePrim=0;
582 
583 
584  // prim.vertex:
585  G4int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
586  if (nvertex !=1)
587  std::cout << "BscTest: My warning: NumberOfPrimaryVertex != 1 --> = " << nvertex << std::endl;
588 
589  for (int i = 0 ; i<nvertex; i++) {
590  G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(i);
591  if (avertex == 0)
592  std::cout << "BscTest End Of Event ERR: pointer to vertex = 0"
593  << std::endl;
594  G4int npart = avertex->GetNumberOfParticle();
595  if (npart !=1)
596  std::cout << "BscTest: My warning: NumberOfPrimaryPart != 1 --> = " << npart << std::endl;
597  if (npart ==0)
598  std::cout << "BscTest End Of Event ERR: no NumberOfParticle" << std::endl;
599 
600  if (thePrim==0) thePrim=avertex->GetPrimary(trackID);
601 
602  if (thePrim!=0) {
603  // primary vertex:
604  G4double vx=0.,vy=0.,vz=0.;
605  vx = avertex->GetX0();
606  vy = avertex->GetY0();
607  vz = avertex->GetZ0();
608  //UserNtuples->fillh01(vx);
609  //UserNtuples->fillh02(vy);
610  //UserNtuples->fillh03(vz);
611  TheHistManager->GetHisto("VtxX")->Fill(vx);
612  TheHistManager->GetHisto("VtxY")->Fill(vy);
613  TheHistManager->GetHisto("VtxZ")->Fill(vz);
614  }
615  }
616  // prim.vertex loop end
617 
618  //=========================== thePrim != 0 ================================================================================
619  if (thePrim != 0) {
620  //
621  // number of secondary particles deposited their energy along primary track
622  //UserNtuples->fillg518(numofpart,1.);
623  if(lastpo.z()<z4 && lastpo.perp()< 100.) {
624  //UserNtuples->fillg536(numofpart,1.);
625  }
626  //
627 
628  // direction !!!
629  G4ThreeVector mom = thePrim->GetMomentum();
630 
631  double phi = atan2(mom.y(),mom.x());
632  if (phi < 0.) phi += twopi;
633  double phigrad = phi*180./pi;
634 
635  double th = mom.theta();
636  double eta = -log(tan(th/2));
637  TheHistManager->GetHisto("PrimaryEta")->Fill(eta);
638  TheHistManager->GetHisto("PrimaryPhigrad")->Fill(phigrad);
639  TheHistManager->GetHisto("PrimaryTh")->Fill(th*180./pi);
640 
641  TheHistManager->GetHisto("PrimaryLastpoZ")->Fill(lastpo.z());
642  if(lastpo.z() < z4 ) {
643  TheHistManager->GetHisto("PrimaryLastpoX")->Fill(lastpo.x());
644  TheHistManager->GetHisto("PrimaryLastpoY")->Fill(lastpo.y());
645  }
646  if(numofpart > 4 ) {
647  TheHistManager->GetHisto("XLastpoNumofpart")->Fill(lastpo.x());
648  TheHistManager->GetHisto("YLastpoNumofpart")->Fill(lastpo.y());
649  }
650 
651  // ==========================================================================
652 
653  // hit map for Bsc
654  // ==================================
655 
656  std::map<int,float,std::less<int> > themap;
657  std::map<int,float,std::less<int> > themap1;
658 
659  std::map<int,float,std::less<int> > themapxy;
660  std::map<int,float,std::less<int> > themapz;
661  // access to the G4 hit collections: -----> this work OK:
662 
663  // edm::LogInfo("BscTest") << "1";
664  G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
665  // edm::LogInfo("BscTest") << "2";
666  if (verbosity > 0) {
667  std::cout << "BscTest: accessed all HC" << std::endl;;
668  }
669  int CAFIid = G4SDManager::GetSDMpointer()->GetCollectionID("BSCHits");
670 
671  BscG4HitCollection* theCAFI = (BscG4HitCollection*) allHC->GetHC(CAFIid);
672  if (verbosity > 0) {
673  std::cout << "BscTest: theCAFI->entries = " << theCAFI->entries() << std::endl;
674  }
675  int varia ; // = 0 -all; =1 - MI; =2 - noMI
676  //varia = 0;
677  if( lastpo.z()< z4) {
678  varia = 1;
679  }
680  else{
681  varia = 2;
682  } // no MI end:
683  for (int j=0; j<theCAFI->entries(); j++) {
684  BscG4Hit* aHit = (*theCAFI)[j];
685  CLHEP::Hep3Vector hitPoint = aHit->getEntry();
686  double zz = hitPoint.z();
687  TheHistManager->GetHisto("zHits")->Fill(zz);
688  if(tracklength0>8300.) TheHistManager->GetHisto("zHitsTrLoLe")->Fill(zz);
689  }
690 
691  if( varia == 2) {
692  int nhit11 = 0, nhit12 = 0, nhit13 = 0 ;
693  double totallosenergy= 0.;
694  for (int j=0; j<theCAFI->entries(); j++) {
695  BscG4Hit* aHit = (*theCAFI)[j];
696 
697  CLHEP::Hep3Vector hitEntryLocalPoint = aHit->getEntryLocalP();
698  CLHEP::Hep3Vector hitExitLocalPoint = aHit->getExitLocalP();
699  CLHEP::Hep3Vector hitPoint = aHit->getEntry();
700  int trackIDhit = aHit->getTrackID();
701  unsigned int unitID = aHit->getUnitID();
702  double losenergy = aHit->getEnergyLoss();
703 
704  double zz = hitPoint.z();
705 
706  TheHistManager->GetHisto("zHitsnoMI")->Fill(zz);
707 
708  if (verbosity > 2) {
709  std::cout << "BscTest:zHits = " << zz << std::endl;
710  }
711 
712  themap[unitID] += losenergy;
713  totallosenergy += losenergy;
714 
715  int zside, sector;
717  zside = (unitID&32)>>5;
718  sector = (unitID&7);
719 
720  //
721  //=======================================
722  G4ThreeVector middle = (hitExitLocalPoint+hitEntryLocalPoint)/2.;
723  themapz[unitID] = hitPoint.z()+middle.z();
724  //=======================================
725  // Y
726  if(zside==1) {
727  //UserNtuples->fillg24(losenergy,1.);
728  if(losenergy > 0.00003) {
729  themap1[unitID] += 1.;
730  }
731  }
732  //X
733  if(zside==2){
734  //UserNtuples->fillg25(losenergy,1.);
735  if(losenergy > 0.00005) {
736  themap1[unitID] += 1.;
737  }
738  }
739  // }
740  //
741  if(sector==1) {
742  nhit11 += 1;
743  //UserNtuples->fillg33(rr,1.);
744  //UserNtuples->fillg11(yy,1.);
745  }
746  if(sector==2) {
747  nhit12 += 1;
748  //UserNtuples->fillg34(rr,1.);
749  //UserNtuples->fillg86(yy,1.);
750  }
751  if(sector==3) {
752  nhit13 += 1;
753  //UserNtuples->fillg35(rr,1.);
754  //UserNtuples->fillg87(yy,1.);
755  }
756 
757  if(lastpo.z()<z4 && lastpo.perp()< 120.) {
758  // MIonly:
759  //UserNtuples->fillg16(lastpo.z(),1.);
760  //UserNtuples->fillg18(zz,1.);
761  // Station I
762  if( zz < z2){
763  //UserNtuples->fillg54(dx,1.);
764  //UserNtuples->fillg55(dy,1.);
765  }
766  // Station II
767  if( zz < z3 && zz > z2){
768  //UserNtuples->fillg50(dx,1.);
769  //UserNtuples->fillg51(dy,1.);
770  }
771  // Station III
772  if( zz < z4 && zz > z3){
773  //UserNtuples->fillg64(dx,1.);
774  //UserNtuples->fillg65(dy,1.);
775  //UserNtuples->filld209(xx,yy,1.);
776  }
777  }
778  else{
779  // no MIonly:
780  //UserNtuples->fillg17(lastpo.z(),1.);
781  //UserNtuples->fillg19(zz,1.);
782  //UserNtuples->fillg74(incidentEnergyHit,1.);
783  //UserNtuples->fillg75(float(trackIDhit),1.);
784  // Station I
785  if( zz < z2){
786  //UserNtuples->fillg56(dx,1.);
787  //UserNtuples->fillg57(dy,1.);
788  //UserNtuples->fillg20(numofpart,1.);
789  //UserNtuples->fillg21(SumEnerDeposit,1.);
790  if(zside==1) {
791  //UserNtuples->fillg26(losenergy,1.);
792  }
793  if(zside==2){
794  //UserNtuples->fillg76(losenergy,1.);
795  }
796  if(trackIDhit == 1){
797  //UserNtuples->fillg70(dx,1.);
798  //UserNtuples->fillg71(incidentEnergyHit,1.);
799  //UserNtuples->fillg79(losenergy,1.);
800  }
801  else{
802  //UserNtuples->fillg82(dx,1.);
803  }
804  }
805  // Station II
806  if( zz < z3 && zz > z2){
807  //UserNtuples->fillg52(dx,1.);
808  //UserNtuples->fillg53(dy,1.);
809  //UserNtuples->fillg22(numofpart,1.);
810  //UserNtuples->fillg23(SumEnerDeposit,1.);
811  //UserNtuples->fillg80(incidentEnergyHit,1.);
812  //UserNtuples->fillg81(float(trackIDhit),1.);
813  if(zside==1) {
814  //UserNtuples->fillg27(losenergy,1.);
815  }
816  if(zside==2){
817  //UserNtuples->fillg77(losenergy,1.);
818  }
819  if(trackIDhit == 1){
820  //UserNtuples->fillg72(dx,1.);
821  //UserNtuples->fillg73(incidentEnergyHit,1.);
822  }
823  else{
824  //UserNtuples->fillg83(dx,1.);
825  }
826  }
827  // Station III
828  if( zz < z4 && zz > z3){
829  if(zside==1) {
830  //UserNtuples->fillg28(losenergy,1.);
831  }
832  if(zside==2){
833  //UserNtuples->fillg78(losenergy,1.);
834  }
835  }
836  }
837  } // MIonly or noMIonly ENDED
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++) {
841  BscG4Hit* aHit = (*theCAFI)[j];
842  double losenergy = aHit->getEnergyLoss();
843  std::cout << " j hits = " << j << "losenergy = " << losenergy << std::endl;
844  }
845  }
846  // FIBRE Hit collected analysis
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++) {
852  for (int zside=1; zside<3; zside++) {
853  int det= 1;// nhit = 0;
854  // int sScale = 20;
855  int index = BscNumberingScheme::packBscIndex(det, zside, sector);
856  double theTotalEnergy = themap[index];
857  // X planes
858  if(zside<2){
859  //UserNtuples->fillg47(theTotalEnergy,1.);
860  if(theTotalEnergy > 0.00003) {
861  nhitsX += 1;
862  // nhitsecX += themap1[index];
863  // nhit=1;
864  }
865  }
866  // Y planes
867  else {
868  //UserNtuples->fillg49(theTotalEnergy,1.);
869  if(theTotalEnergy > 0.00005) {
870  nhitsY += 1;
871  // nhitsecY += themap1[index];
872  // nhit=1;
873  }
874  }
875 
876  totalEnergy += themap[index];
877  } // for
878  } // for
879  //UserNtuples->fillg39(nhitsecY,1.);
880  if(nhitsecX > 10 || nhitsecY > 10) {
881  nsumhit +=1;
882  //UserNtuples->fillp213(float(sector),float(1.),1.);
883  }
884  else{ //UserNtuples->fillp213(float(sector),float(0.),1.);
885  }
886  } // for
887 
888  if( nsumhit >=2 ) { //UserNtuples->fillp212(vy,float(1.),1.);
889  }
890  else{ //UserNtuples->fillp212(vy,float(0.),1.);
891  }
892  } // MI or no MI or all - end
893  } // primary end
894 
895  if (verbosity > 0) {
896  std::cout << "BscTest: END OF Event " << (*evt)()->GetEventID() << std::endl;
897  }
898 
899 }
900 
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:528
std::string fOutputFile
Definition: BscTest.h:233
TH2F * GetHisto2(Int_t Number)
Definition: BscTest.cc:213
double npart
Definition: HydjetWrapper.h:49
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:538
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
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
G4ThreeVector getEntry() const
Definition: BSCG4Hit.cc:115
void detectorLevel(const G4VTouchable *, int &, int *, G4String *) const
Definition: BscTest.cc:550
int itrk
Definition: BscTest.h:198
void update(const BeginOfJob *run)
This routine will be called when the appropriate signal arrives.
Definition: BscTest.cc:261
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
virtual ~BscTest()
Definition: BscTest.cc:77
G4double tracklength0
Definition: BscTest.h:199