CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/SimG4CMS/Forward/src/BscTest.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 
00004 // system include files
00005 #include <iostream>
00006 #include <iomanip>
00007 #include <cmath>
00008 #include<vector>
00009 //
00010 #include "SimG4Core/Notification/interface/BeginOfEvent.h"
00011 #include "SimG4Core/Notification/interface/EndOfEvent.h"
00012 #include "SimG4Core/Notification/interface/TrackWithHistory.h"
00013 #include "SimG4Core/Notification/interface/TrackInformation.h"
00014  
00015 #include "FWCore/Framework/interface/Event.h"
00016 #include "FWCore/Framework/interface/EventSetup.h"
00017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00018 // to retreive hits
00019 #include "SimG4CMS/Forward/interface/BscNumberingScheme.h"
00020 #include "SimG4CMS/Forward/interface/BscG4HitCollection.h"
00021 #include "SimG4CMS/Forward/interface/BscTest.h"
00022 
00023 //#include "Utilities/GenUtil/interface/CMSexception.h"
00024 //#include "Utilities/UI/interface/SimpleConfigurable.h"
00025 
00026 // G4 stuff
00027 #include "G4SDManager.hh"
00028 #include "G4Step.hh"
00029 #include "G4Track.hh"
00030 #include "G4VProcess.hh"
00031 #include "G4HCofThisEvent.hh"
00032 #include "G4UserEventAction.hh"
00033 #include "G4TransportationManager.hh"
00034 #include "G4ProcessManager.hh"
00035 //#include "G4EventManager.hh"
00036 
00037 #include "CLHEP/Units/GlobalSystemOfUnits.h"
00038 #include "CLHEP/Units/GlobalPhysicalConstants.h"
00039 #include <stdio.h>
00040 //#include <gsl/gsl_fit.h>
00041 
00042 
00043 //================================================================
00044 // Root stuff
00045 
00046 // Include the standard header <cassert> to effectively include
00047 // the standard header <assert.h> within the std namespace.
00048 #include <cassert>
00049 
00050 //================================================================
00051 
00052 //UserVerbosity BscTest::std::cout("BscTest","info","BscTest");
00053 enum ntbsc_elements {
00054   ntbsc_evt
00055 };
00056 
00057 //================================================================
00058 BscTest::BscTest(const edm::ParameterSet &p){
00059   //constructor
00060   edm::ParameterSet m_Anal = p.getParameter<edm::ParameterSet>("BscTest");
00061   verbosity    = m_Anal.getParameter<int>("Verbosity");
00062   //verbosity    = 1;
00063 
00064   fDataLabel  = m_Anal.getParameter<std::string>("FDataLabel");
00065   fOutputFile = m_Anal.getParameter<std::string>("FOutputFile");
00066   fRecreateFile = m_Anal.getParameter<std::string>("FRecreateFile");
00067    
00068   if (verbosity > 0) {
00069     std::cout<<"============================================================================"<<std::endl;
00070     std::cout << "BscTestconstructor :: Initialized as observer"<< std::endl;
00071   }
00072   // Initialization:
00073 
00074   theBscNumberingScheme = new BscNumberingScheme();
00075   bsceventntuple = new TNtuple("NTbscevent","NTbscevent","evt");
00076   whichevent = 0;
00077   TheHistManager = new BscAnalysisHistManager(fDataLabel);
00078 
00079   if (verbosity > 0) {
00080     std::cout << "BscTest constructor :: Initialized BscAnalysisHistManager"<< std::endl;
00081   }
00082 }
00083 
00084 
00085 
00086 BscTest::~BscTest() {
00087   //  delete UserNtuples;
00088   delete theBscNumberingScheme;
00089 
00090   TFile bscOutputFile("newntbsc.root","RECREATE");
00091   std::cout << "Bsc output root file has been created";
00092   bsceventntuple->Write();
00093   std::cout << ", written";
00094   bscOutputFile.Close();
00095   std::cout << ", closed";
00096   delete bsceventntuple;
00097   std::cout << ", and deleted" << std::endl;
00098 
00099   //------->while end
00100 
00101   // Write histograms to file
00102   TheHistManager->WriteToFile(fOutputFile,fRecreateFile);
00103   if (verbosity > 0) {
00104     std::cout << std::endl << "BscTest Destructor  -------->  End of BscTest : "
00105               << std::cout << std::endl; 
00106   }
00107 
00108   std::cout<<"BscTest: End of process"<<std::endl;
00109 
00110 
00111 
00112 }
00113 
00114 //================================================================
00115 // Histoes:
00116 //-----------------------------------------------------------------------------
00117 
00118 BscAnalysisHistManager::BscAnalysisHistManager(TString managername)
00119 {
00120   // The Constructor
00121 
00122   fTypeTitle=managername;
00123   fHistArray = new TObjArray();      // Array to store histos
00124   fHistNamesArray = new TObjArray(); // Array to store histos's names
00125 
00126   BookHistos();
00127 
00128   fHistArray->Compress();            // Removes empty space
00129   fHistNamesArray->Compress();
00130 
00131   //      StoreWeights();                    // Store the weights
00132 
00133 }
00134 //-----------------------------------------------------------------------------
00135 
00136 BscAnalysisHistManager::~BscAnalysisHistManager()
00137 {
00138   // The Destructor
00139 
00140   if(fHistArray){
00141     fHistArray->Delete();
00142     delete fHistArray;
00143   }
00144 
00145   if(fHistNamesArray){
00146     fHistNamesArray->Delete();
00147     delete fHistNamesArray;
00148   }
00149 }
00150 //-----------------------------------------------------------------------------
00151 
00152 void BscAnalysisHistManager::BookHistos()
00153 {
00154   // at Start: (mm)
00155   HistInit("TrackPhi", "Primary Phi",   100,   0.,360. );
00156   HistInit("TrackTheta", "Primary Theta",   100,   0.,180. );
00157   HistInit("TrackP", "Track XY position Z+ ",  80, -80., 80.,  80, -80., 80. );
00158   HistInit("TrackM", "Track XY position Z-",   80, -80., 80.,  80, -80., 80. );
00159   HistInit("DetIDs", "Track DetId - vs +",   16, -0.5, 15.5,16, 15.5, 31.5 );
00160 }
00161 
00162 //-----------------------------------------------------------------------------
00163 
00164 void BscAnalysisHistManager::WriteToFile(TString fOutputFile,TString fRecreateFile)
00165 {
00166 
00167   //Write to file = fOutputFile
00168 
00169   std::cout <<"================================================================"<<std::endl;
00170   std::cout <<" Write this Analysis to File "<<fOutputFile<<std::endl;
00171   std::cout <<"================================================================"<<std::endl;
00172 
00173   TFile* file = new TFile(fOutputFile, fRecreateFile);
00174 
00175   fHistArray->Write();
00176   file->Close();
00177 }
00178 //-----------------------------------------------------------------------------
00179 
00180 void BscAnalysisHistManager::HistInit(const char* name, const char* title, Int_t nbinsx, Axis_t xlow, Axis_t xup)
00181 {
00182   // Add histograms and histograms names to the array
00183 
00184   char* newtitle = new char[strlen(title)+strlen(fTypeTitle)+5];
00185   strcpy(newtitle,title);
00186   strcat(newtitle," (");
00187   strcat(newtitle,fTypeTitle);
00188   strcat(newtitle,") ");
00189   fHistArray->AddLast((new TH1F(name, newtitle, nbinsx, xlow, xup)));
00190   fHistNamesArray->AddLast(new TObjString(name));
00191 
00192 }
00193 //-----------------------------------------------------------------------------
00194 
00195 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)
00196 {
00197   // Add histograms and histograms names to the array
00198 
00199   char* newtitle = new char[strlen(title)+strlen(fTypeTitle)+5];
00200   strcpy(newtitle,title);
00201   strcat(newtitle," (");
00202   strcat(newtitle,fTypeTitle);
00203   strcat(newtitle,") ");
00204   fHistArray->AddLast((new TH2F(name, newtitle, nbinsx, xlow, xup, nbinsy, ylow, yup)));
00205   fHistNamesArray->AddLast(new TObjString(name));
00206 
00207 }
00208 //-----------------------------------------------------------------------------
00209 
00210 TH1F* BscAnalysisHistManager::GetHisto(Int_t Number)
00211 {
00212   // Get a histogram from the array with index = Number
00213 
00214   if (Number <= fHistArray->GetLast()  && fHistArray->At(Number) != (TObject*)0){
00215 
00216     return (TH1F*)(fHistArray->At(Number));
00217 
00218   }else{
00219 
00220     std::cout << "!!!!!!!!!!!!!!!!!!GetHisto!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
00221     std::cout << " WARNING ERROR - HIST ID INCORRECT (TOO HIGH) - " << Number << std::endl;
00222     std::cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
00223 
00224     return (TH1F*)(fHistArray->At(0));
00225   }
00226 }
00227 //-----------------------------------------------------------------------------
00228 
00229 TH2F* BscAnalysisHistManager::GetHisto2(Int_t Number)
00230 {
00231   // Get a histogram from the array with index = Number
00232 
00233   if (Number <= fHistArray->GetLast()  && fHistArray->At(Number) != (TObject*)0){
00234 
00235     return (TH2F*)(fHistArray->At(Number));
00236 
00237   }else{
00238 
00239     std::cout << "!!!!!!!!!!!!!!!!GetHisto2!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
00240     std::cout << " WARNING ERROR - HIST ID INCORRECT (TOO HIGH) - " << Number << std::endl;
00241     std::cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
00242 
00243     return (TH2F*)(fHistArray->At(0));
00244   }
00245 }
00246 //-----------------------------------------------------------------------------
00247 
00248 TH1F* BscAnalysisHistManager::GetHisto(const TObjString histname)
00249 {
00250   // Get a histogram from the array with name = histname
00251 
00252   Int_t index = fHistNamesArray->IndexOf(&histname);
00253   return GetHisto(index);
00254 }
00255 //-----------------------------------------------------------------------------
00256 
00257 TH2F* BscAnalysisHistManager::GetHisto2(const TObjString histname)
00258 {
00259   // Get a histogram from the array with name = histname
00260 
00261   Int_t index = fHistNamesArray->IndexOf(&histname);
00262   return GetHisto2(index);
00263 }
00264 //-----------------------------------------------------------------------------
00265 
00266 void BscAnalysisHistManager::StoreWeights()
00267 {
00268   // Add structure to each histogram to store the weights
00269 
00270   for(int i = 0; i < fHistArray->GetEntries(); i++){
00271     ((TH1F*)(fHistArray->At(i)))->Sumw2();
00272   }
00273 }
00274 
00275 
00276 //==================================================================== per JOB
00277 void BscTest::update(const BeginOfJob * job) {
00278   //job
00279   std::cout<<"BscTest:beggining of job"<<std::endl;;
00280 }
00281 
00282 
00283 //==================================================================== per RUN
00284 void BscTest::update(const BeginOfRun * run) {
00285   //run
00286 
00287   std::cout << std::endl << "BscTest:: Begining of Run"<< std::endl; 
00288 }
00289 
00290 
00291 void BscTest::update(const EndOfRun * run) {;}
00292 
00293 
00294 
00295 //=================================================================== per EVENT
00296 void BscTest::update(const BeginOfEvent * evt) {
00297   iev = (*evt)()->GetEventID();
00298   if (verbosity > 0) {
00299     std::cout <<"BscTest:update Event number = " << iev << std::endl;
00300   }
00301   whichevent++;
00302 }
00303 
00304 //=================================================================== per Track
00305 void BscTest::update(const BeginOfTrack * trk) {
00306   itrk = (*trk)()->GetTrackID();
00307   if (verbosity > 1) {
00308     std::cout <<"BscTest:update BeginOfTrack number = " << itrk << std::endl;
00309   }
00310   if(itrk == 1) {
00311     SumEnerDeposit = 0.;
00312     numofpart = 0;
00313     SumStepl = 0.;
00314     SumStepc = 0.;
00315     tracklength0 = 0.;
00316   }
00317 }
00318 
00319 
00320 
00321 //=================================================================== per EndOfTrack
00322 void BscTest::update(const EndOfTrack * trk) {
00323   itrk = (*trk)()->GetTrackID();
00324   if (verbosity > 1) {
00325     std::cout <<"BscTest:update EndOfTrack number = " << itrk << std::endl;
00326   }
00327   if(itrk == 1) {
00328     G4double tracklength  = (*trk)()->GetTrackLength();    // Accumulated track length
00329 
00330     TheHistManager->GetHisto("SumEDep")->Fill(SumEnerDeposit);
00331     TheHistManager->GetHisto("TrackL")->Fill(tracklength);
00332 
00333     // direction !!!
00334     G4ThreeVector   vert_mom  = (*trk)()->GetVertexMomentumDirection();
00335     G4ThreeVector   vert_pos  = (*trk)()->GetVertexPosition(); // vertex ,where this track was created
00336   
00337     //    float eta = 0.5 * log( (1.+vert_mom.z()) / (1.-vert_mom.z()) );
00338     float phi = atan2(vert_mom.y(),vert_mom.x());
00339     if (phi < 0.) phi += twopi;
00340     if(tracklength < z4) {
00341 
00342     }
00343 
00344     // last step information
00345     const G4Step* aStep = (*trk)()->GetStep();
00346     G4StepPoint*      preStepPoint = aStep->GetPreStepPoint(); 
00347     lastpo   = preStepPoint->GetPosition();     
00348 
00349     // Analysis:
00350 
00351   }
00352 
00353 }
00354 
00355 // ====================================================
00356 
00357 //=================================================================== each STEP
00358 void BscTest::update(const G4Step * aStep) {
00359   // ==========================================================================
00360   
00361   if (verbosity > 2) {
00362     G4int stepnumber  = aStep->GetTrack()->GetCurrentStepNumber();
00363     std::cout <<"BscTest:update Step number = " << stepnumber << std::endl;
00364   }
00365   // track on aStep:                                                                                         !
00366   G4Track*     theTrack     = aStep->GetTrack();   
00367   TrackInformation* trkInfo = dynamic_cast<TrackInformation*> (theTrack->GetUserInformation());
00368   if (trkInfo == 0) {
00369     std::cout << "BscTest on aStep: No trk info !!!! abort " << std::endl;
00370     //     throw Genexception("BscTest:BscTest on aStep: cannot get trkInfo");
00371   } 
00372   G4int         id             = theTrack->GetTrackID();
00373   G4String       particleType   = theTrack->GetDefinition()->GetParticleName();   //   !!!
00374   G4int         parentID       = theTrack->GetParentID();   //   !!!
00375   G4TrackStatus   trackstatus    = theTrack->GetTrackStatus();   //   !!!
00376   G4double       tracklength    = theTrack->GetTrackLength();    // Accumulated track length
00377   G4ThreeVector   trackmom       = theTrack->GetMomentum();
00378   G4double       entot          = theTrack->GetTotalEnergy();   //   !!! deposited on step
00379   G4int         curstepnumber  = theTrack->GetCurrentStepNumber();
00380   G4ThreeVector   vert_pos       = theTrack->GetVertexPosition(); // vertex ,where this track was created
00381   G4ThreeVector   vert_mom       = theTrack->GetVertexMomentumDirection();
00382   G4double        stepl         = aStep->GetStepLength();
00383   G4double        EnerDeposit   = aStep->GetTotalEnergyDeposit();
00384   G4StepPoint*      preStepPoint = aStep->GetPreStepPoint(); 
00385   G4ThreeVector     preposition   = preStepPoint->GetPosition();        
00386   G4ThreeVector     prelocalpoint = theTrack->GetTouchable()->GetHistory()->
00387     GetTopTransform().TransformPoint(preposition);
00388   G4VPhysicalVolume* currentPV     = preStepPoint->GetPhysicalVolume();
00389   G4String         prename       = currentPV->GetName();
00390 
00391   const G4VTouchable*  pre_touch    = preStepPoint->GetTouchable();
00392   int          pre_levels   = detLevels(pre_touch);
00393   G4String name1[20]; int copyno1[20];
00394   if (pre_levels > 0) {
00395     detectorLevel(pre_touch, pre_levels, copyno1, name1);
00396   }
00397 
00398   if ( id == 1 ) {
00399 
00400     // on 1-st step:
00401     if (curstepnumber == 1 ) {
00402       entot0 = entot;
00403       //UserNtuples->fillg519(entot0,1.);
00404 
00405     }
00406 
00407     // on every step:
00408 
00409     // for Copper:
00410     if(prename == "SBST" ) {
00411       SumStepc += stepl;
00412       // =========
00413     }
00414     // for ststeel:
00415     //   if(prename == "SBSTs") {
00416     if(prename == "SBSTs" ) {
00417       SumStepl += stepl;
00418       // =========
00419     }
00420     // =========
00421     // =========
00422 
00423     // exclude last track point if it is in SD (MI was started their)
00424     if (trackstatus != 2 ) {
00425       // for SD:   Si Det.:   SISTATION:SIPLANE:(SIDETL+BOUNDDET        +SIDETR + CERAMDET)
00426       if(prename == "SIDETL" || prename == "SIDETR" ) {
00427         if(prename == "SIDETL") {
00428           //UserNtuples->fillg569(EnerDeposit,1.);
00429         }
00430         if(prename == "SIDETR") {
00431           //UserNtuples->fillg570(EnerDeposit,1.);
00432         }
00433 
00434         G4String posname = aStep->GetPostStepPoint()->GetPhysicalVolume()->GetName();
00435         if((prename == "SIDETL" && posname != "SIDETL") || (prename == "SIDETR" && posname != "SIDETR")) {
00436           if(name1[2] == "SISTATION" ) {
00437             //UserNtuples->fillg539(copyno1[2],1.);
00438           }
00439           if(name1[3] == "SIPLANE" ) {
00440             //UserNtuples->fillg540(copyno1[3],1.);
00441           }
00442 
00443           if(prename == "SIDETL") {
00444             //UserNtuples->fillg541(EnerDeposit,1.);
00445             //UserNtuples->fillg561(numbcont,1.);
00446             if(copyno1[2]<2) {
00447               //UserNtuples->fillg571(dx,1.);
00448             }
00449             else if(copyno1[2]<3) {
00450               //UserNtuples->fillg563(dx,1.);
00451               if(copyno1[3]<2) {
00452               }
00453               else if(copyno1[3]<3) {
00454                 //UserNtuples->fillg572(dx,1.);
00455               }
00456               else if(copyno1[3]<4) {
00457                 //UserNtuples->fillg573(dx,1.);
00458               }
00459               else if(copyno1[3]<5) {
00460                 //UserNtuples->fillg574(dx,1.);
00461               }
00462               else if(copyno1[3]<6) {
00463                 //UserNtuples->fillg575(dx,1.);
00464               }
00465               else if(copyno1[3]<7) {
00466                 //UserNtuples->fillg576(dx,1.);
00467               }
00468               else if(copyno1[3]<8) {
00469                 //UserNtuples->fillg577(dx,1.);
00470               }
00471               else if(copyno1[3]<9) {
00472                 //UserNtuples->fillg578(dx,1.);
00473               }
00474               else if(copyno1[3]<10) {
00475                 //UserNtuples->fillg579(dx,1.);
00476               }
00477             }
00478             else if(copyno1[2]<4) {
00479               //UserNtuples->fillg565(dx,1.);
00480             }
00481             else if(copyno1[2]<5) {
00482               //UserNtuples->fillg567(dx,1.);
00483             }
00484           }
00485           if(prename == "SIDETR") {
00486             //UserNtuples->fillg542(EnerDeposit,1.);
00487             //UserNtuples->fillg562(numbcont,1.);
00488             if(copyno1[2]<2) {
00489               //UserNtuples->fillg581(dy,1.);
00490             }
00491             else if(copyno1[2]<3) {
00492               //UserNtuples->fillg564(dy,1.);
00493               if(copyno1[3]<2) {
00494               }
00495               else if(copyno1[3]<3) {
00496                 //UserNtuples->fillg582(dy,1.);
00497               }
00498               else if(copyno1[3]<4) {
00499                 //UserNtuples->fillg583(dy,1.);
00500               }
00501               else if(copyno1[3]<5) {
00502                 //UserNtuples->fillg584(dy,1.);
00503               }
00504               else if(copyno1[3]<6) {
00505                 //UserNtuples->fillg585(dy,1.);
00506               }
00507               else if(copyno1[3]<7) {
00508                 //UserNtuples->fillg586(dy,1.);
00509               }
00510               else if(copyno1[3]<8) {
00511                 //UserNtuples->fillg587(dy,1.);
00512               }
00513               else if(copyno1[3]<9) {
00514                 //UserNtuples->fillg588(dy,1.);
00515               }
00516               else if(copyno1[3]<10) {
00517                 //UserNtuples->fillg589(dy,1.);
00518               }
00519             }
00520             else if(copyno1[2]<4) {
00521               //UserNtuples->fillg566(dy,1.);
00522             }
00523             else if(copyno1[2]<5) {
00524               //UserNtuples->fillg568(dy,1.);
00525             }
00526           }
00527 
00528         }
00529       }
00530       // end of prenames SIDETL // SIDETR
00531     }
00532     // end of trackstatus != 2
00533 
00534     SumEnerDeposit += EnerDeposit;
00535     if (trackstatus == 2 ) {
00536       // primary track length 
00537       //      //UserNtuples->fillg508(tracklength,1.);
00538       tracklength0 = tracklength;
00539     }
00540   }
00541   // end of primary track !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
00542 
00543 
00544   if (parentID == 1 && curstepnumber == 1) {
00545     // particles deposit their energy along primary track
00546     numofpart += 1;
00547     if(prename == "SBST" ) {
00548       //UserNtuples->filld225(vert_pos.y(),vert_pos.z(),1.);
00549     }
00550     if(prename == "SBSTs" ) {
00551       //UserNtuples->filld226(vert_pos.y(),vert_pos.z(),1.);
00552     }
00553   }
00554 
00555 }
00556 // ==========================================================================
00557 // ==========================================================================
00558 int BscTest::detLevels(const G4VTouchable* touch) const {
00559 
00560   //Return number of levels
00561   if (touch) 
00562     return ((touch->GetHistoryDepth())+1);
00563   else
00564     return 0;
00565 }
00566 // ==========================================================================
00567 
00568 G4String BscTest::detName(const G4VTouchable* touch, int level,
00569                           int currentlevel) const {
00570 
00571   //Go down to current level
00572   if (level > 0 && level >= currentlevel) {
00573     int ii = level - currentlevel; 
00574     return touch->GetVolume(ii)->GetName();
00575   } else {
00576     return "NotFound";
00577   }
00578 }
00579 
00580 void BscTest::detectorLevel(const G4VTouchable* touch, int& level,
00581                             int* copyno, G4String* name) const {
00582 
00583   //Get name and copy numbers
00584   if (level > 0) {
00585     for (int ii = 0; ii < level; ii++) {
00586       int i      = level - ii - 1;
00587       G4VPhysicalVolume* pv = touch->GetVolume(i);
00588       if (pv != 0) 
00589         name[ii] = pv->GetName();
00590       else
00591         name[ii] = "Unknown";
00592       copyno[ii] = touch->GetReplicaNumber(i);
00593     }
00594   }
00595 }
00596 // ==========================================================================
00597 
00598 //===================================================================   End Of Event
00599 void BscTest::update(const EndOfEvent * evt) {
00600   // ==========================================================================
00601   
00602   if (verbosity > 1) {
00603     iev = (*evt)()->GetEventID();
00604     std::cout <<"BscTest:update EndOfEvent = " << iev << std::endl;
00605   }
00606   // Fill-in ntuple
00607   bsceventarray[ntbsc_evt] = (float)whichevent;
00608 
00609   //
00610   int trackID = 0;
00611   G4PrimaryParticle* thePrim=0;
00612 
00613 
00614   // prim.vertex:
00615   G4int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
00616   if (nvertex !=1)
00617     std::cout << "BscTest: My warning: NumberOfPrimaryVertex != 1  -->  = " << nvertex <<  std::endl;
00618 
00619   for (int i = 0 ; i<nvertex; i++) {
00620     G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(i);
00621     if (avertex == 0)
00622       std::cout << "BscTest  End Of Event ERR: pointer to vertex = 0"
00623                 << std::endl;
00624     G4int npart = avertex->GetNumberOfParticle();
00625     if (npart !=1)
00626       std::cout << "BscTest: My warning: NumberOfPrimaryPart != 1  -->  = " << npart <<  std::endl;
00627     if (npart ==0)
00628       std::cout << "BscTest End Of Event ERR: no NumberOfParticle" << std::endl;
00629 
00630     if (thePrim==0) thePrim=avertex->GetPrimary(trackID);
00631 
00632     if (thePrim!=0) {
00633       // primary vertex:
00634       G4double vx=0.,vy=0.,vz=0.;
00635       vx = avertex->GetX0();
00636       vy = avertex->GetY0();
00637       vz = avertex->GetZ0();
00638       //UserNtuples->fillh01(vx);
00639       //UserNtuples->fillh02(vy);
00640       //UserNtuples->fillh03(vz);
00641       TheHistManager->GetHisto("VtxX")->Fill(vx);
00642       TheHistManager->GetHisto("VtxY")->Fill(vy);
00643       TheHistManager->GetHisto("VtxZ")->Fill(vz);
00644     }
00645   }
00646   // prim.vertex loop end
00647 
00648   //=========================== thePrim != 0 ================================================================================
00649   if (thePrim != 0) {
00650     //      inline G4ParticleDefinition * GetG4code() const
00651     //      inline G4PrimaryParticle * GetNext() const
00652     //      inline G4PrimaryParticle * GetDaughter() const
00653 
00654     // prim.vertex
00655     int ivert = 0 ;
00656     G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(ivert);
00657     G4double vx=0.,vy=0.,vz=0.;
00658     vx = avertex->GetX0();
00659     vy = avertex->GetY0();
00660     vz = avertex->GetZ0();
00661 
00662     //
00663     // number of secondary particles deposited their energy along primary track
00664     //UserNtuples->fillg518(numofpart,1.);
00665     if(lastpo.z()<z4 && lastpo.perp()< 100.) {
00666       //UserNtuples->fillg536(numofpart,1.);
00667     }
00668     //
00669 
00670     // direction !!!
00671     G4ThreeVector   mom  = thePrim->GetMomentum();
00672   
00673     double phi = atan2(mom.y(),mom.x());
00674     if (phi < 0.) phi += twopi;
00675     double phigrad = phi*180./pi;
00676 
00677     double th     = mom.theta();
00678     double eta = -log(tan(th/2));
00679     TheHistManager->GetHisto("PrimaryEta")->Fill(eta);
00680     TheHistManager->GetHisto("PrimaryPhigrad")->Fill(phigrad);
00681     TheHistManager->GetHisto("PrimaryTh")->Fill(th*180./pi);
00682 
00683     TheHistManager->GetHisto("PrimaryLastpoZ")->Fill(lastpo.z());
00684     if(lastpo.z() <  z4  ) {
00685       TheHistManager->GetHisto("PrimaryLastpoX")->Fill(lastpo.x());
00686       TheHistManager->GetHisto("PrimaryLastpoY")->Fill(lastpo.y());
00687     }
00688     if(numofpart >  4  ) {
00689       TheHistManager->GetHisto("XLastpoNumofpart")->Fill(lastpo.x());
00690       TheHistManager->GetHisto("YLastpoNumofpart")->Fill(lastpo.y());
00691     }
00692 
00693     // ==========================================================================
00694 
00695     // hit map for Bsc
00696     // ==================================
00697 
00698     std::map<int,float,std::less<int> > themap;
00699     std::map<int,float,std::less<int> > themap1;
00700 
00701     std::map<int,float,std::less<int> > themapxy;
00702     std::map<int,float,std::less<int> > themapz;
00703     // access to the G4 hit collections:  -----> this work OK:
00704 
00705     //  edm::LogInfo("BscTest") << "1";
00706     G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
00707     //  edm::LogInfo("BscTest") << "2";
00708     if (verbosity > 0) {
00709       std::cout << "BscTest:  accessed all HC" << std::endl;;
00710     }
00711     int CAFIid = G4SDManager::GetSDMpointer()->GetCollectionID("BSCHits");
00712 
00713     BscG4HitCollection* theCAFI = (BscG4HitCollection*) allHC->GetHC(CAFIid);
00714     if (verbosity > 0) {
00715       std::cout << "BscTest: theCAFI->entries = " << theCAFI->entries() << std::endl;
00716     }
00717     int varia ;   // = 0 -all; =1 - MI; =2 - noMI
00718     varia = 0;
00719     if(  lastpo.z()< z4) {
00720       varia = 1;
00721     }
00722     else{
00723       varia = 2;
00724     }   // no MI end:
00725 
00726     for (int j=0; j<theCAFI->entries(); j++) {
00727       BscG4Hit* aHit = (*theCAFI)[j];
00728       CLHEP::Hep3Vector hitPoint = aHit->getEntry();
00729       double   zz    = hitPoint.z();
00730       TheHistManager->GetHisto("zHits")->Fill(zz);
00731       if(tracklength0>8300.) TheHistManager->GetHisto("zHitsTrLoLe")->Fill(zz);
00732     }
00733     // varia = 0;
00734     //     if( varia == 0) {
00735     if( varia == 2) {
00736 
00737 
00738       int nhit11 = 0, nhit12 = 0, nhit13 = 0 ;
00739       double  totallosenergy= 0.;
00740       for (int j=0; j<theCAFI->entries(); j++) {
00741         BscG4Hit* aHit = (*theCAFI)[j];
00742 
00743         CLHEP::Hep3Vector hitEntryLocalPoint = aHit->getEntryLocalP();
00744         CLHEP::Hep3Vector hitExitLocalPoint = aHit->getExitLocalP();
00745         CLHEP::Hep3Vector hitPoint = aHit->getEntry();
00746         int trackIDhit  = aHit->getTrackID();
00747         unsigned int unitID = aHit->getUnitID();
00748         double  losenergy = aHit->getEnergyLoss();
00749         double phi_hit   = hitPoint.phi();
00750         if (phi_hit < 0.) phi_hit += twopi;
00751 
00752         double   zz    = hitPoint.z();
00753 
00754         TheHistManager->GetHisto("zHitsnoMI")->Fill(zz);
00755 
00756         if (verbosity > 2) {
00757           std::cout << "BscTest:zHits = " << zz << std::endl;
00758         }
00759 
00760         themap[unitID] += losenergy;
00761         totallosenergy += losenergy;
00762 
00763         int zside, sector;
00764         BscNumberingScheme::unpackBscIndex(unitID);
00765         zside  = (unitID&32)>>5;
00766         sector = (unitID&7);
00767 
00768         //
00769         //=======================================
00770         G4ThreeVector middle = (hitExitLocalPoint+hitEntryLocalPoint)/2.;
00771         themapz[unitID]  = hitPoint.z()+middle.z();
00772         //=======================================
00773         // Y
00774         if(zside==1) {
00775           //UserNtuples->fillg24(losenergy,1.);
00776           if(losenergy > 0.00003) {
00777             themap1[unitID] += 1.;
00778           }
00779         }
00780         //X
00781         if(zside==2){
00782           //UserNtuples->fillg25(losenergy,1.);
00783           if(losenergy > 0.00005) {
00784             themap1[unitID] += 1.;
00785           }
00786         }
00787         //         }
00788         //
00789         if(sector==1) {
00790           nhit11 += 1;
00791           //UserNtuples->fillg33(rr,1.);
00792           //UserNtuples->fillg11(yy,1.);
00793         }
00794         if(sector==2) {
00795           nhit12 += 1;
00796           //UserNtuples->fillg34(rr,1.);
00797           //UserNtuples->fillg86(yy,1.);
00798         }
00799         if(sector==3) {
00800           nhit13 += 1;
00801           //UserNtuples->fillg35(rr,1.);
00802           //UserNtuples->fillg87(yy,1.);
00803         }
00804 
00805         if(lastpo.z()<z4  && lastpo.perp()< 120.) {
00806           // MIonly:
00807           //UserNtuples->fillg16(lastpo.z(),1.);
00808           //UserNtuples->fillg18(zz,1.);
00809           //                                                                     Station I
00810           if( zz < z2){
00811             //UserNtuples->fillg54(dx,1.);
00812             //UserNtuples->fillg55(dy,1.);
00813           }
00814           //                                                                     Station II
00815           if( zz < z3 && zz > z2){
00816             //UserNtuples->fillg50(dx,1.);
00817             //UserNtuples->fillg51(dy,1.);
00818           }
00819           //                                                                     Station III
00820           if( zz < z4 && zz > z3){
00821             //UserNtuples->fillg64(dx,1.);
00822             //UserNtuples->fillg65(dy,1.);
00823             //UserNtuples->filld209(xx,yy,1.);
00824           }
00825         }
00826         else{
00827           // no MIonly:
00828           //UserNtuples->fillg17(lastpo.z(),1.);
00829           //UserNtuples->fillg19(zz,1.);
00830           //UserNtuples->fillg74(incidentEnergyHit,1.);
00831           //UserNtuples->fillg75(float(trackIDhit),1.);
00832           //                                                                     Station I
00833           if( zz < z2){
00834             //UserNtuples->fillg56(dx,1.);
00835             //UserNtuples->fillg57(dy,1.);
00836             //UserNtuples->fillg20(numofpart,1.);
00837             //UserNtuples->fillg21(SumEnerDeposit,1.);
00838             if(zside==1) {
00839               //UserNtuples->fillg26(losenergy,1.);
00840             }
00841             if(zside==2){
00842               //UserNtuples->fillg76(losenergy,1.);
00843             }
00844             if(trackIDhit == 1){
00845               //UserNtuples->fillg70(dx,1.);
00846               //UserNtuples->fillg71(incidentEnergyHit,1.);
00847               //UserNtuples->fillg79(losenergy,1.);
00848             }
00849             else{
00850               //UserNtuples->fillg82(dx,1.);
00851             }
00852           }
00853           //                                                                     Station II
00854           if( zz < z3 && zz > z2){
00855             //UserNtuples->fillg52(dx,1.);
00856             //UserNtuples->fillg53(dy,1.);
00857             //UserNtuples->fillg22(numofpart,1.);
00858             //UserNtuples->fillg23(SumEnerDeposit,1.);
00859             //UserNtuples->fillg80(incidentEnergyHit,1.);
00860             //UserNtuples->fillg81(float(trackIDhit),1.);
00861             if(zside==1) {
00862               //UserNtuples->fillg27(losenergy,1.);
00863             }
00864             if(zside==2){
00865               //UserNtuples->fillg77(losenergy,1.);
00866             }
00867             if(trackIDhit == 1){
00868               //UserNtuples->fillg72(dx,1.);
00869               //UserNtuples->fillg73(incidentEnergyHit,1.);
00870             }
00871             else{
00872               //UserNtuples->fillg83(dx,1.);
00873             }
00874           }
00875           //                                                                     Station III
00876           if( zz < z4 && zz > z3){
00877             if(zside==1) {
00878               //UserNtuples->fillg28(losenergy,1.);
00879             }
00880             if(zside==2){
00881               //UserNtuples->fillg78(losenergy,1.);
00882             }
00883           }
00884         }
00885       }   // MIonly or noMIonly ENDED
00886       if(totallosenergy == 0.0) {
00887         std::cout << "BscTest:     number of hits = " << theCAFI->entries()   << std::endl;
00888         for (int j=0; j<theCAFI->entries(); j++) {
00889           BscG4Hit* aHit = (*theCAFI)[j];
00890           double  losenergy = aHit->getEnergyLoss();
00891           std::cout << " j hits = " << j   << "losenergy = " << losenergy << std::endl;
00892         }
00893       }
00894       //   FIBRE Hit collected analysis
00895       double totalEnergy = 0.;
00896       int nhitsX = 0, nhitsY = 0, nsumhit = 0 ;
00897       for (int sector=1; sector<4; sector++) {
00898         int nhitsecX = 0, nhitsecY = 0;
00899         for (int zmodule=1; zmodule<11; zmodule++) {
00900           for (int zside=1; zside<3; zside++) {
00901             int det= 1, nhit = 0;
00902             //  int sScale = 20;
00903             int index = BscNumberingScheme::packBscIndex(det, zside, sector);
00904             double   theTotalEnergy = themap[index];
00905             //   X planes
00906             if(zside<2){ 
00907               //UserNtuples->fillg47(theTotalEnergy,1.); 
00908               if(theTotalEnergy > 0.00003) {
00909                 nhitsX += 1;
00910                 //          nhitsecX += themap1[index];
00911                 nhit=1;
00912               }
00913             }
00914             //   Y planes
00915             else {
00916               //UserNtuples->fillg49(theTotalEnergy,1.);
00917               if(theTotalEnergy > 0.00005) {
00918                 nhitsY += 1;
00919                 //          nhitsecY += themap1[index];
00920                 nhit=1;
00921               }
00922             }
00923 
00924             totalEnergy += themap[index];
00925           } // for
00926         } // for
00927           //UserNtuples->fillg39(nhitsecY,1.); 
00928         if(nhitsecX > 10 || nhitsecY > 10) {
00929           nsumhit +=1;
00930           //UserNtuples->fillp213(float(sector),float(1.),1.);
00931         }
00932         else{ //UserNtuples->fillp213(float(sector),float(0.),1.);
00933         }
00934       } // for
00935 
00936       if( nsumhit >=2 ) { //UserNtuples->fillp212(vy,float(1.),1.);
00937       }
00938       else{   //UserNtuples->fillp212(vy,float(0.),1.);
00939       }
00940 
00941     }   // MI or no MI or all  - end
00942 
00943 
00944 
00945   }                                                // primary end
00946 
00947   if (verbosity > 0) {
00948     std::cout << "BscTest:  END OF Event " << (*evt)()->GetEventID() << std::endl;
00949   }
00950 
00951 }
00952