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 : "
105  << std::cout << std::endl;
106  }
107 
108  std::cout<<"BscTest: End of process"<<std::endl;
109 
110 
111 
112 }
113 
114 //================================================================
115 // Histoes:
116 //-----------------------------------------------------------------------------
117 
119 {
120  // The Constructor
121 
122  fTypeTitle=managername;
123  fHistArray = new TObjArray(); // Array to store histos
124  fHistNamesArray = new TObjArray(); // Array to store histos's names
125 
126  BookHistos();
127 
128  fHistArray->Compress(); // Removes empty space
129  fHistNamesArray->Compress();
130 
131  // StoreWeights(); // Store the weights
132 
133 }
134 //-----------------------------------------------------------------------------
135 
137 {
138  // The Destructor
139 
140  if(fHistArray){
141  fHistArray->Delete();
142  delete fHistArray;
143  }
144 
145  if(fHistNamesArray){
146  fHistNamesArray->Delete();
147  delete fHistNamesArray;
148  }
149 }
150 //-----------------------------------------------------------------------------
151 
153 {
154  // at Start: (mm)
155  HistInit("TrackPhi", "Primary Phi", 100, 0.,360. );
156  HistInit("TrackTheta", "Primary Theta", 100, 0.,180. );
157  HistInit("TrackP", "Track XY position Z+ ", 80, -80., 80., 80, -80., 80. );
158  HistInit("TrackM", "Track XY position Z-", 80, -80., 80., 80, -80., 80. );
159  HistInit("DetIDs", "Track DetId - vs +", 16, -0.5, 15.5,16, 15.5, 31.5 );
160 }
161 
162 //-----------------------------------------------------------------------------
163 
164 void BscAnalysisHistManager::WriteToFile(const TString& fOutputFile,const TString& fRecreateFile)
165 {
166 
167  //Write to file = fOutputFile
168 
169  std::cout <<"================================================================"<<std::endl;
170  std::cout <<" Write this Analysis to File "<<fOutputFile<<std::endl;
171  std::cout <<"================================================================"<<std::endl;
172 
173  TFile* file = new TFile(fOutputFile, fRecreateFile);
174 
175  fHistArray->Write();
176  file->Close();
177 }
178 //-----------------------------------------------------------------------------
179 
180 void BscAnalysisHistManager::HistInit(const char* name, const char* title, Int_t nbinsx, Axis_t xlow, Axis_t xup)
181 {
182  // Add histograms and histograms names to the array
183 
184  char* newtitle = new char[strlen(title)+strlen(fTypeTitle)+5];
185  strcpy(newtitle,title);
186  strcat(newtitle," (");
187  strcat(newtitle,fTypeTitle);
188  strcat(newtitle,") ");
189  fHistArray->AddLast((new TH1F(name, newtitle, nbinsx, xlow, xup)));
190  fHistNamesArray->AddLast(new TObjString(name));
191 
192 }
193 //-----------------------------------------------------------------------------
194 
195 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)
196 {
197  // Add histograms and histograms names to the array
198 
199  char* newtitle = new char[strlen(title)+strlen(fTypeTitle)+5];
200  strcpy(newtitle,title);
201  strcat(newtitle," (");
202  strcat(newtitle,fTypeTitle);
203  strcat(newtitle,") ");
204  fHistArray->AddLast((new TH2F(name, newtitle, nbinsx, xlow, xup, nbinsy, ylow, yup)));
205  fHistNamesArray->AddLast(new TObjString(name));
206 
207 }
208 //-----------------------------------------------------------------------------
209 
211 {
212  // Get a histogram from the array with index = Number
213 
214  if (Number <= fHistArray->GetLast() && fHistArray->At(Number) != (TObject*)0){
215 
216  return (TH1F*)(fHistArray->At(Number));
217 
218  }else{
219 
220  std::cout << "!!!!!!!!!!!!!!!!!!GetHisto!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
221  std::cout << " WARNING ERROR - HIST ID INCORRECT (TOO HIGH) - " << Number << std::endl;
222  std::cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
223 
224  return (TH1F*)(fHistArray->At(0));
225  }
226 }
227 //-----------------------------------------------------------------------------
228 
230 {
231  // Get a histogram from the array with index = Number
232 
233  if (Number <= fHistArray->GetLast() && fHistArray->At(Number) != (TObject*)0){
234 
235  return (TH2F*)(fHistArray->At(Number));
236 
237  }else{
238 
239  std::cout << "!!!!!!!!!!!!!!!!GetHisto2!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
240  std::cout << " WARNING ERROR - HIST ID INCORRECT (TOO HIGH) - " << Number << std::endl;
241  std::cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
242 
243  return (TH2F*)(fHistArray->At(0));
244  }
245 }
246 //-----------------------------------------------------------------------------
247 
248 TH1F* BscAnalysisHistManager::GetHisto(const TObjString& histname)
249 {
250  // Get a histogram from the array with name = histname
251 
252  Int_t index = fHistNamesArray->IndexOf(&histname);
253  return GetHisto(index);
254 }
255 //-----------------------------------------------------------------------------
256 
257 TH2F* BscAnalysisHistManager::GetHisto2(const TObjString& histname)
258 {
259  // Get a histogram from the array with name = histname
260 
261  Int_t index = fHistNamesArray->IndexOf(&histname);
262  return GetHisto2(index);
263 }
264 //-----------------------------------------------------------------------------
265 
267 {
268  // Add structure to each histogram to store the weights
269 
270  for(int i = 0; i < fHistArray->GetEntries(); i++){
271  ((TH1F*)(fHistArray->At(i)))->Sumw2();
272  }
273 }
274 
275 
276 //==================================================================== per JOB
278  //job
279  std::cout<<"BscTest:beggining of job"<<std::endl;;
280 }
281 
282 
283 //==================================================================== per RUN
285  //run
286 
287  std::cout << std::endl << "BscTest:: Begining of Run"<< std::endl;
288 }
289 
290 
291 void BscTest::update(const EndOfRun * run) {;}
292 
293 
294 
295 //=================================================================== per EVENT
296 void BscTest::update(const BeginOfEvent * evt) {
297  iev = (*evt)()->GetEventID();
298  if (verbosity > 0) {
299  std::cout <<"BscTest:update Event number = " << iev << std::endl;
300  }
301  whichevent++;
302 }
303 
304 //=================================================================== per Track
305 void BscTest::update(const BeginOfTrack * trk) {
306  itrk = (*trk)()->GetTrackID();
307  if (verbosity > 1) {
308  std::cout <<"BscTest:update BeginOfTrack number = " << itrk << std::endl;
309  }
310  if(itrk == 1) {
311  SumEnerDeposit = 0.;
312  numofpart = 0;
313  SumStepl = 0.;
314  SumStepc = 0.;
315  tracklength0 = 0.;
316  }
317 }
318 
319 
320 
321 //=================================================================== per EndOfTrack
322 void BscTest::update(const EndOfTrack * trk) {
323  itrk = (*trk)()->GetTrackID();
324  if (verbosity > 1) {
325  std::cout <<"BscTest:update EndOfTrack number = " << itrk << std::endl;
326  }
327  if(itrk == 1) {
328  G4double tracklength = (*trk)()->GetTrackLength(); // Accumulated track length
329 
330  TheHistManager->GetHisto("SumEDep")->Fill(SumEnerDeposit);
331  TheHistManager->GetHisto("TrackL")->Fill(tracklength);
332 
333  // direction !!!
334  G4ThreeVector vert_mom = (*trk)()->GetVertexMomentumDirection();
335  G4ThreeVector vert_pos = (*trk)()->GetVertexPosition(); // vertex ,where this track was created
336 
337  // float eta = 0.5 * log( (1.+vert_mom.z()) / (1.-vert_mom.z()) );
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 
726  for (int j=0; j<theCAFI->entries(); j++) {
727  BscG4Hit* aHit = (*theCAFI)[j];
728  CLHEP::Hep3Vector hitPoint = aHit->getEntry();
729  double zz = hitPoint.z();
730  TheHistManager->GetHisto("zHits")->Fill(zz);
731  if(tracklength0>8300.) TheHistManager->GetHisto("zHitsTrLoLe")->Fill(zz);
732  }
733  // varia = 0;
734  // if( varia == 0) {
735  if( varia == 2) {
736 
737 
738  int nhit11 = 0, nhit12 = 0, nhit13 = 0 ;
739  double totallosenergy= 0.;
740  for (int j=0; j<theCAFI->entries(); j++) {
741  BscG4Hit* aHit = (*theCAFI)[j];
742 
743  CLHEP::Hep3Vector hitEntryLocalPoint = aHit->getEntryLocalP();
744  CLHEP::Hep3Vector hitExitLocalPoint = aHit->getExitLocalP();
745  CLHEP::Hep3Vector hitPoint = aHit->getEntry();
746  int trackIDhit = aHit->getTrackID();
747  unsigned int unitID = aHit->getUnitID();
748  double losenergy = aHit->getEnergyLoss();
749  double phi_hit = hitPoint.phi();
750  if (phi_hit < 0.) phi_hit += twopi;
751 
752  double zz = hitPoint.z();
753 
754  TheHistManager->GetHisto("zHitsnoMI")->Fill(zz);
755 
756  if (verbosity > 2) {
757  std::cout << "BscTest:zHits = " << zz << std::endl;
758  }
759 
760  themap[unitID] += losenergy;
761  totallosenergy += losenergy;
762 
763  int zside, sector;
765  zside = (unitID&32)>>5;
766  sector = (unitID&7);
767 
768  //
769  //=======================================
770  G4ThreeVector middle = (hitExitLocalPoint+hitEntryLocalPoint)/2.;
771  themapz[unitID] = hitPoint.z()+middle.z();
772  //=======================================
773  // Y
774  if(zside==1) {
775  //UserNtuples->fillg24(losenergy,1.);
776  if(losenergy > 0.00003) {
777  themap1[unitID] += 1.;
778  }
779  }
780  //X
781  if(zside==2){
782  //UserNtuples->fillg25(losenergy,1.);
783  if(losenergy > 0.00005) {
784  themap1[unitID] += 1.;
785  }
786  }
787  // }
788  //
789  if(sector==1) {
790  nhit11 += 1;
791  //UserNtuples->fillg33(rr,1.);
792  //UserNtuples->fillg11(yy,1.);
793  }
794  if(sector==2) {
795  nhit12 += 1;
796  //UserNtuples->fillg34(rr,1.);
797  //UserNtuples->fillg86(yy,1.);
798  }
799  if(sector==3) {
800  nhit13 += 1;
801  //UserNtuples->fillg35(rr,1.);
802  //UserNtuples->fillg87(yy,1.);
803  }
804 
805  if(lastpo.z()<z4 && lastpo.perp()< 120.) {
806  // MIonly:
807  //UserNtuples->fillg16(lastpo.z(),1.);
808  //UserNtuples->fillg18(zz,1.);
809  // Station I
810  if( zz < z2){
811  //UserNtuples->fillg54(dx,1.);
812  //UserNtuples->fillg55(dy,1.);
813  }
814  // Station II
815  if( zz < z3 && zz > z2){
816  //UserNtuples->fillg50(dx,1.);
817  //UserNtuples->fillg51(dy,1.);
818  }
819  // Station III
820  if( zz < z4 && zz > z3){
821  //UserNtuples->fillg64(dx,1.);
822  //UserNtuples->fillg65(dy,1.);
823  //UserNtuples->filld209(xx,yy,1.);
824  }
825  }
826  else{
827  // no MIonly:
828  //UserNtuples->fillg17(lastpo.z(),1.);
829  //UserNtuples->fillg19(zz,1.);
830  //UserNtuples->fillg74(incidentEnergyHit,1.);
831  //UserNtuples->fillg75(float(trackIDhit),1.);
832  // Station I
833  if( zz < z2){
834  //UserNtuples->fillg56(dx,1.);
835  //UserNtuples->fillg57(dy,1.);
836  //UserNtuples->fillg20(numofpart,1.);
837  //UserNtuples->fillg21(SumEnerDeposit,1.);
838  if(zside==1) {
839  //UserNtuples->fillg26(losenergy,1.);
840  }
841  if(zside==2){
842  //UserNtuples->fillg76(losenergy,1.);
843  }
844  if(trackIDhit == 1){
845  //UserNtuples->fillg70(dx,1.);
846  //UserNtuples->fillg71(incidentEnergyHit,1.);
847  //UserNtuples->fillg79(losenergy,1.);
848  }
849  else{
850  //UserNtuples->fillg82(dx,1.);
851  }
852  }
853  // Station II
854  if( zz < z3 && zz > z2){
855  //UserNtuples->fillg52(dx,1.);
856  //UserNtuples->fillg53(dy,1.);
857  //UserNtuples->fillg22(numofpart,1.);
858  //UserNtuples->fillg23(SumEnerDeposit,1.);
859  //UserNtuples->fillg80(incidentEnergyHit,1.);
860  //UserNtuples->fillg81(float(trackIDhit),1.);
861  if(zside==1) {
862  //UserNtuples->fillg27(losenergy,1.);
863  }
864  if(zside==2){
865  //UserNtuples->fillg77(losenergy,1.);
866  }
867  if(trackIDhit == 1){
868  //UserNtuples->fillg72(dx,1.);
869  //UserNtuples->fillg73(incidentEnergyHit,1.);
870  }
871  else{
872  //UserNtuples->fillg83(dx,1.);
873  }
874  }
875  // Station III
876  if( zz < z4 && zz > z3){
877  if(zside==1) {
878  //UserNtuples->fillg28(losenergy,1.);
879  }
880  if(zside==2){
881  //UserNtuples->fillg78(losenergy,1.);
882  }
883  }
884  }
885  } // MIonly or noMIonly ENDED
886  if(totallosenergy == 0.0) {
887  std::cout << "BscTest: number of hits = " << theCAFI->entries() << std::endl;
888  for (int j=0; j<theCAFI->entries(); j++) {
889  BscG4Hit* aHit = (*theCAFI)[j];
890  double losenergy = aHit->getEnergyLoss();
891  std::cout << " j hits = " << j << "losenergy = " << losenergy << std::endl;
892  }
893  }
894  // FIBRE Hit collected analysis
895  double totalEnergy = 0.;
896  int nhitsX = 0, nhitsY = 0, nsumhit = 0 ;
897  for (int sector=1; sector<4; sector++) {
898  int nhitsecX = 0, nhitsecY = 0;
899  for (int zmodule=1; zmodule<11; zmodule++) {
900  for (int zside=1; zside<3; zside++) {
901  int det= 1;// nhit = 0;
902  // int sScale = 20;
903  int index = BscNumberingScheme::packBscIndex(det, zside, sector);
904  double theTotalEnergy = themap[index];
905  // X planes
906  if(zside<2){
907  //UserNtuples->fillg47(theTotalEnergy,1.);
908  if(theTotalEnergy > 0.00003) {
909  nhitsX += 1;
910  // nhitsecX += themap1[index];
911  // nhit=1;
912  }
913  }
914  // Y planes
915  else {
916  //UserNtuples->fillg49(theTotalEnergy,1.);
917  if(theTotalEnergy > 0.00005) {
918  nhitsY += 1;
919  // nhitsecY += themap1[index];
920  // nhit=1;
921  }
922  }
923 
924  totalEnergy += themap[index];
925  } // for
926  } // for
927  //UserNtuples->fillg39(nhitsecY,1.);
928  if(nhitsecX > 10 || nhitsecY > 10) {
929  nsumhit +=1;
930  //UserNtuples->fillp213(float(sector),float(1.),1.);
931  }
932  else{ //UserNtuples->fillp213(float(sector),float(0.),1.);
933  }
934  } // for
935 
936  if( nsumhit >=2 ) { //UserNtuples->fillp212(vy,float(1.),1.);
937  }
938  else{ //UserNtuples->fillp212(vy,float(0.),1.);
939  }
940 
941  } // MI or no MI or all - end
942 
943 
944 
945  } // primary end
946 
947  if (verbosity > 0) {
948  std::cout << "BscTest: END OF Event " << (*evt)()->GetEventID() << std::endl;
949  }
950 
951 }
952 
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:210
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:229
double npart
Definition: HydjetWrapper.h:44
int zside(DetId const &)
G4ThreeVector lastpo
Definition: BscTest.h:218
TObjArray * fHistNamesArray
Definition: BscTest.h:89
T eta() const
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
tuple particleType
Definition: autophobj.py:28
int whichevent
Definition: BscTest.h:229
void WriteToFile(const TString &fOutputFile, const TString &fRecreateFile)
Definition: BscTest.cc:164
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:180
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:277
Float_t bsceventarray[1]
Definition: BscTest.h:226
G4double SumStepc
Definition: BscTest.h:214
tuple cout
Definition: gather_cfg.py:121
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:118
float getEnergyLoss() const
Definition: BSCG4Hit.cc:150
virtual ~BscTest()
Definition: BscTest.cc:86
G4double tracklength0
Definition: BscTest.h:199
Definition: DDAxes.h:10