test
CMS 3D CMS Logo

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