CMS 3D CMS Logo

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/SystemOfUnits.h"
00038 #include "CLHEP/Units/PhysicalConstants.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 using namespace edm;
00051 using namespace std;
00052 //================================================================
00053 
00054 //UserVerbosity BscTest::std::cout("BscTest","info","BscTest");
00055 enum ntbsc_elements {
00056   ntbsc_evt
00057 };
00058 
00059 //================================================================
00060 BscTest::BscTest(const edm::ParameterSet &p){
00061   //constructor
00062   edm::ParameterSet m_Anal = p.getParameter<edm::ParameterSet>("BscTest");
00063   verbosity    = m_Anal.getParameter<int>("Verbosity");
00064   //verbosity    = 1;
00065 
00066   fDataLabel  = m_Anal.getParameter<std::string>("FDataLabel");
00067   fOutputFile = m_Anal.getParameter<std::string>("FOutputFile");
00068   fRecreateFile = m_Anal.getParameter<std::string>("FRecreateFile");
00069    
00070   if (verbosity > 0) {
00071     std::cout<<"============================================================================"<<std::endl;
00072     std::cout << "BscTestconstructor :: Initialized as observer"<< std::endl;
00073   }
00074   // Initialization:
00075 
00076   theBscNumberingScheme = new BscNumberingScheme();
00077   bsceventntuple = new TNtuple("NTbscevent","NTbscevent","evt");
00078   whichevent = 0;
00079   TheHistManager = new BscAnalysisHistManager(fDataLabel);
00080 
00081   if (verbosity > 0) {
00082     std::cout << "BscTest constructor :: Initialized BscAnalysisHistManager"<< std::endl;
00083   }
00084 }
00085 
00086 
00087 
00088 BscTest::~BscTest() {
00089   //  delete UserNtuples;
00090   delete theBscNumberingScheme;
00091 
00092   TFile bscOutputFile("newntbsc.root","RECREATE");
00093   std::cout << "Bsc output root file has been created";
00094   bsceventntuple->Write();
00095   std::cout << ", written";
00096   bscOutputFile.Close();
00097   std::cout << ", closed";
00098   delete bsceventntuple;
00099   std::cout << ", and deleted" << std::endl;
00100 
00101   //------->while end
00102 
00103   // Write histograms to file
00104   TheHistManager->WriteToFile(fOutputFile,fRecreateFile);
00105   if (verbosity > 0) {
00106     std::cout << std::endl << "BscTest Destructor  -------->  End of BscTest : "
00107               << std::cout << std::endl; 
00108   }
00109 
00110   std::cout<<"BscTest: End of process"<<std::endl;
00111 
00112 
00113 
00114 }
00115 
00116 //================================================================
00117 // Histoes:
00118 //-----------------------------------------------------------------------------
00119 
00120 BscAnalysisHistManager::BscAnalysisHistManager(TString managername)
00121 {
00122   // The Constructor
00123 
00124   fTypeTitle=managername;
00125   fHistArray = new TObjArray();      // Array to store histos
00126   fHistNamesArray = new TObjArray(); // Array to store histos's names
00127 
00128   BookHistos();
00129 
00130   fHistArray->Compress();            // Removes empty space
00131   fHistNamesArray->Compress();
00132 
00133   //      StoreWeights();                    // Store the weights
00134 
00135 }
00136 //-----------------------------------------------------------------------------
00137 
00138 BscAnalysisHistManager::~BscAnalysisHistManager()
00139 {
00140   // The Destructor
00141 
00142   if(fHistArray){
00143     fHistArray->Delete();
00144     delete fHistArray;
00145   }
00146 
00147   if(fHistNamesArray){
00148     fHistNamesArray->Delete();
00149     delete fHistNamesArray;
00150   }
00151 }
00152 //-----------------------------------------------------------------------------
00153 
00154 void BscAnalysisHistManager::BookHistos()
00155 {
00156   // at Start: (mm)
00157   HistInit("TrackPhi", "Primary Phi",   100,   0.,360. );
00158   HistInit("TrackTheta", "Primary Theta",   100,   0.,180. );
00159   HistInit("TrackP", "Track XY position Z+ ",  80, -80., 80.,  80, -80., 80. );
00160   HistInit("TrackM", "Track XY position Z-",   80, -80., 80.,  80, -80., 80. );
00161   HistInit("DetIDs", "Track DetId - vs +",   16, -0.5, 15.5,16, 15.5, 31.5 );
00162 }
00163 
00164 //-----------------------------------------------------------------------------
00165 
00166 void BscAnalysisHistManager::WriteToFile(TString fOutputFile,TString fRecreateFile)
00167 {
00168 
00169   //Write to file = fOutputFile
00170 
00171   std::cout <<"================================================================"<<std::endl;
00172   std::cout <<" Write this Analysis to File "<<fOutputFile<<std::endl;
00173   std::cout <<"================================================================"<<std::endl;
00174 
00175   TFile* file = new TFile(fOutputFile, fRecreateFile);
00176 
00177   fHistArray->Write();
00178   file->Close();
00179 }
00180 //-----------------------------------------------------------------------------
00181 
00182 void BscAnalysisHistManager::HistInit(const char* name, const char* title, Int_t nbinsx, Axis_t xlow, Axis_t xup)
00183 {
00184   // Add histograms and histograms names to the array
00185 
00186   char* newtitle = new char[strlen(title)+strlen(fTypeTitle)+5];
00187   strcpy(newtitle,title);
00188   strcat(newtitle," (");
00189   strcat(newtitle,fTypeTitle);
00190   strcat(newtitle,") ");
00191   fHistArray->AddLast((new TH1F(name, newtitle, nbinsx, xlow, xup)));
00192   fHistNamesArray->AddLast(new TObjString(name));
00193 
00194 }
00195 //-----------------------------------------------------------------------------
00196 
00197 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)
00198 {
00199   // Add histograms and histograms names to the array
00200 
00201   char* newtitle = new char[strlen(title)+strlen(fTypeTitle)+5];
00202   strcpy(newtitle,title);
00203   strcat(newtitle," (");
00204   strcat(newtitle,fTypeTitle);
00205   strcat(newtitle,") ");
00206   fHistArray->AddLast((new TH2F(name, newtitle, nbinsx, xlow, xup, nbinsy, ylow, yup)));
00207   fHistNamesArray->AddLast(new TObjString(name));
00208 
00209 }
00210 //-----------------------------------------------------------------------------
00211 
00212 TH1F* BscAnalysisHistManager::GetHisto(Int_t Number)
00213 {
00214   // Get a histogram from the array with index = Number
00215 
00216   if (Number <= fHistArray->GetLast()  && fHistArray->At(Number) != (TObject*)0){
00217 
00218     return (TH1F*)(fHistArray->At(Number));
00219 
00220   }else{
00221 
00222     std::cout << "!!!!!!!!!!!!!!!!!!GetHisto!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
00223     std::cout << " WARNING ERROR - HIST ID INCORRECT (TOO HIGH) - " << Number << std::endl;
00224     std::cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
00225 
00226     return (TH1F*)(fHistArray->At(0));
00227   }
00228 }
00229 //-----------------------------------------------------------------------------
00230 
00231 TH2F* BscAnalysisHistManager::GetHisto2(Int_t Number)
00232 {
00233   // Get a histogram from the array with index = Number
00234 
00235   if (Number <= fHistArray->GetLast()  && fHistArray->At(Number) != (TObject*)0){
00236 
00237     return (TH2F*)(fHistArray->At(Number));
00238 
00239   }else{
00240 
00241     std::cout << "!!!!!!!!!!!!!!!!GetHisto2!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
00242     std::cout << " WARNING ERROR - HIST ID INCORRECT (TOO HIGH) - " << Number << std::endl;
00243     std::cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
00244 
00245     return (TH2F*)(fHistArray->At(0));
00246   }
00247 }
00248 //-----------------------------------------------------------------------------
00249 
00250 TH1F* BscAnalysisHistManager::GetHisto(const TObjString histname)
00251 {
00252   // Get a histogram from the array with name = histname
00253 
00254   Int_t index = fHistNamesArray->IndexOf(&histname);
00255   return GetHisto(index);
00256 }
00257 //-----------------------------------------------------------------------------
00258 
00259 TH2F* BscAnalysisHistManager::GetHisto2(const TObjString histname)
00260 {
00261   // Get a histogram from the array with name = histname
00262 
00263   Int_t index = fHistNamesArray->IndexOf(&histname);
00264   return GetHisto2(index);
00265 }
00266 //-----------------------------------------------------------------------------
00267 
00268 void BscAnalysisHistManager::StoreWeights()
00269 {
00270   // Add structure to each histogram to store the weights
00271 
00272   for(int i = 0; i < fHistArray->GetEntries(); i++){
00273     ((TH1F*)(fHistArray->At(i)))->Sumw2();
00274   }
00275 }
00276 
00277 
00278 //==================================================================== per JOB
00279 void BscTest::update(const BeginOfJob * job) {
00280   //job
00281   std::cout<<"BscTest:beggining of job"<<std::endl;;
00282 }
00283 
00284 
00285 //==================================================================== per RUN
00286 void BscTest::update(const BeginOfRun * run) {
00287   //run
00288 
00289   std::cout << std::endl << "BscTest:: Begining of Run"<< std::endl; 
00290 }
00291 
00292 
00293 void BscTest::update(const EndOfRun * run) {;}
00294 
00295 
00296 
00297 //=================================================================== per EVENT
00298 void BscTest::update(const BeginOfEvent * evt) {
00299   iev = (*evt)()->GetEventID();
00300   if (verbosity > 0) {
00301     std::cout <<"BscTest:update Event number = " << iev << std::endl;
00302   }
00303   whichevent++;
00304 }
00305 
00306 //=================================================================== per Track
00307 void BscTest::update(const BeginOfTrack * trk) {
00308   itrk = (*trk)()->GetTrackID();
00309   if (verbosity > 1) {
00310     std::cout <<"BscTest:update BeginOfTrack number = " << itrk << std::endl;
00311   }
00312   if(itrk == 1) {
00313     SumEnerDeposit = 0.;
00314     numofpart = 0;
00315     SumStepl = 0.;
00316     SumStepc = 0.;
00317     tracklength0 = 0.;
00318   }
00319 }
00320 
00321 
00322 
00323 //=================================================================== per EndOfTrack
00324 void BscTest::update(const EndOfTrack * trk) {
00325   itrk = (*trk)()->GetTrackID();
00326   if (verbosity > 1) {
00327     std::cout <<"BscTest:update EndOfTrack number = " << itrk << std::endl;
00328   }
00329   if(itrk == 1) {
00330     G4double tracklength  = (*trk)()->GetTrackLength();    // Accumulated track length
00331 
00332     TheHistManager->GetHisto("SumEDep")->Fill(SumEnerDeposit);
00333     TheHistManager->GetHisto("TrackL")->Fill(tracklength);
00334 
00335     // direction !!!
00336     G4ThreeVector   vert_mom  = (*trk)()->GetVertexMomentumDirection();
00337     G4ThreeVector   vert_pos  = (*trk)()->GetVertexPosition(); // vertex ,where this track was created
00338   
00339     //    float eta = 0.5 * log( (1.+vert_mom.z()) / (1.-vert_mom.z()) );
00340     float phi = atan2(vert_mom.y(),vert_mom.x());
00341     if (phi < 0.) phi += twopi;
00342     if(tracklength < z4) {
00343 
00344     }
00345 
00346     // last step information
00347     const G4Step* aStep = (*trk)()->GetStep();
00348     G4StepPoint*      preStepPoint = aStep->GetPreStepPoint(); 
00349     lastpo   = preStepPoint->GetPosition();     
00350 
00351     // Analysis:
00352 
00353   }
00354 
00355 }
00356 
00357 // ====================================================
00358 
00359 //=================================================================== each STEP
00360 void BscTest::update(const G4Step * aStep) {
00361   // ==========================================================================
00362   
00363   if (verbosity > 2) {
00364     G4int stepnumber  = aStep->GetTrack()->GetCurrentStepNumber();
00365     std::cout <<"BscTest:update Step number = " << stepnumber << std::endl;
00366   }
00367   // track on aStep:                                                                                         !
00368   G4Track*     theTrack     = aStep->GetTrack();   
00369   TrackInformation* trkInfo = dynamic_cast<TrackInformation*> (theTrack->GetUserInformation());
00370   if (trkInfo == 0) {
00371     std::cout << "BscTest on aStep: No trk info !!!! abort " << std::endl;
00372     //     throw Genexception("BscTest:BscTest on aStep: cannot get trkInfo");
00373   } 
00374   G4int         id             = theTrack->GetTrackID();
00375   G4String       particleType   = theTrack->GetDefinition()->GetParticleName();   //   !!!
00376   G4int         parentID       = theTrack->GetParentID();   //   !!!
00377   G4TrackStatus   trackstatus    = theTrack->GetTrackStatus();   //   !!!
00378   G4double       tracklength    = theTrack->GetTrackLength();    // Accumulated track length
00379   G4ThreeVector   trackmom       = theTrack->GetMomentum();
00380   G4double       entot          = theTrack->GetTotalEnergy();   //   !!! deposited on step
00381   G4int         curstepnumber  = theTrack->GetCurrentStepNumber();
00382   G4ThreeVector   vert_pos       = theTrack->GetVertexPosition(); // vertex ,where this track was created
00383   G4ThreeVector   vert_mom       = theTrack->GetVertexMomentumDirection();
00384   G4double        stepl         = aStep->GetStepLength();
00385   G4double        EnerDeposit   = aStep->GetTotalEnergyDeposit();
00386   G4StepPoint*      preStepPoint = aStep->GetPreStepPoint(); 
00387   G4ThreeVector     preposition   = preStepPoint->GetPosition();        
00388   G4ThreeVector     prelocalpoint = theTrack->GetTouchable()->GetHistory()->
00389     GetTopTransform().TransformPoint(preposition);
00390   G4VPhysicalVolume* currentPV     = preStepPoint->GetPhysicalVolume();
00391   G4String         prename       = currentPV->GetName();
00392 
00393   const G4VTouchable*  pre_touch    = preStepPoint->GetTouchable();
00394   int          pre_levels   = detLevels(pre_touch);
00395   G4String name1[20]; int copyno1[20];
00396   if (pre_levels > 0) {
00397     detectorLevel(pre_touch, pre_levels, copyno1, name1);
00398   }
00399 
00400   if ( id == 1 ) {
00401 
00402     // on 1-st step:
00403     if (curstepnumber == 1 ) {
00404       entot0 = entot;
00405       //UserNtuples->fillg519(entot0,1.);
00406 
00407     }
00408 
00409     // on every step:
00410 
00411     // for Copper:
00412     if(prename == "SBST" ) {
00413       SumStepc += stepl;
00414       // =========
00415     }
00416     // for ststeel:
00417     //   if(prename == "SBSTs") {
00418     if(prename == "SBSTs" ) {
00419       SumStepl += stepl;
00420       // =========
00421     }
00422     // =========
00423     // =========
00424 
00425     // exclude last track point if it is in SD (MI was started their)
00426     if (trackstatus != 2 ) {
00427       // for SD:   Si Det.:   SISTATION:SIPLANE:(SIDETL+BOUNDDET        +SIDETR + CERAMDET)
00428       if(prename == "SIDETL" || prename == "SIDETR" ) {
00429         if(prename == "SIDETL") {
00430           //UserNtuples->fillg569(EnerDeposit,1.);
00431         }
00432         if(prename == "SIDETR") {
00433           //UserNtuples->fillg570(EnerDeposit,1.);
00434         }
00435 
00436         G4String posname = aStep->GetPostStepPoint()->GetPhysicalVolume()->GetName();
00437         if((prename == "SIDETL" && posname != "SIDETL") || (prename == "SIDETR" && posname != "SIDETR")) {
00438           if(name1[2] == "SISTATION" ) {
00439             //UserNtuples->fillg539(copyno1[2],1.);
00440           }
00441           if(name1[3] == "SIPLANE" ) {
00442             //UserNtuples->fillg540(copyno1[3],1.);
00443           }
00444 
00445           if(prename == "SIDETL") {
00446             //UserNtuples->fillg541(EnerDeposit,1.);
00447             //UserNtuples->fillg561(numbcont,1.);
00448             if(copyno1[2]<2) {
00449               //UserNtuples->fillg571(dx,1.);
00450             }
00451             else if(copyno1[2]<3) {
00452               //UserNtuples->fillg563(dx,1.);
00453               if(copyno1[3]<2) {
00454               }
00455               else if(copyno1[3]<3) {
00456                 //UserNtuples->fillg572(dx,1.);
00457               }
00458               else if(copyno1[3]<4) {
00459                 //UserNtuples->fillg573(dx,1.);
00460               }
00461               else if(copyno1[3]<5) {
00462                 //UserNtuples->fillg574(dx,1.);
00463               }
00464               else if(copyno1[3]<6) {
00465                 //UserNtuples->fillg575(dx,1.);
00466               }
00467               else if(copyno1[3]<7) {
00468                 //UserNtuples->fillg576(dx,1.);
00469               }
00470               else if(copyno1[3]<8) {
00471                 //UserNtuples->fillg577(dx,1.);
00472               }
00473               else if(copyno1[3]<9) {
00474                 //UserNtuples->fillg578(dx,1.);
00475               }
00476               else if(copyno1[3]<10) {
00477                 //UserNtuples->fillg579(dx,1.);
00478               }
00479             }
00480             else if(copyno1[2]<4) {
00481               //UserNtuples->fillg565(dx,1.);
00482             }
00483             else if(copyno1[2]<5) {
00484               //UserNtuples->fillg567(dx,1.);
00485             }
00486           }
00487           if(prename == "SIDETR") {
00488             //UserNtuples->fillg542(EnerDeposit,1.);
00489             //UserNtuples->fillg562(numbcont,1.);
00490             if(copyno1[2]<2) {
00491               //UserNtuples->fillg581(dy,1.);
00492             }
00493             else if(copyno1[2]<3) {
00494               //UserNtuples->fillg564(dy,1.);
00495               if(copyno1[3]<2) {
00496               }
00497               else if(copyno1[3]<3) {
00498                 //UserNtuples->fillg582(dy,1.);
00499               }
00500               else if(copyno1[3]<4) {
00501                 //UserNtuples->fillg583(dy,1.);
00502               }
00503               else if(copyno1[3]<5) {
00504                 //UserNtuples->fillg584(dy,1.);
00505               }
00506               else if(copyno1[3]<6) {
00507                 //UserNtuples->fillg585(dy,1.);
00508               }
00509               else if(copyno1[3]<7) {
00510                 //UserNtuples->fillg586(dy,1.);
00511               }
00512               else if(copyno1[3]<8) {
00513                 //UserNtuples->fillg587(dy,1.);
00514               }
00515               else if(copyno1[3]<9) {
00516                 //UserNtuples->fillg588(dy,1.);
00517               }
00518               else if(copyno1[3]<10) {
00519                 //UserNtuples->fillg589(dy,1.);
00520               }
00521             }
00522             else if(copyno1[2]<4) {
00523               //UserNtuples->fillg566(dy,1.);
00524             }
00525             else if(copyno1[2]<5) {
00526               //UserNtuples->fillg568(dy,1.);
00527             }
00528           }
00529 
00530         }
00531       }
00532       // end of prenames SIDETL // SIDETR
00533     }
00534     // end of trackstatus != 2
00535 
00536     SumEnerDeposit += EnerDeposit;
00537     if (trackstatus == 2 ) {
00538       // primary track length 
00539       //      //UserNtuples->fillg508(tracklength,1.);
00540       tracklength0 = tracklength;
00541     }
00542   }
00543   // end of primary track !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
00544 
00545 
00546   if (parentID == 1 && curstepnumber == 1) {
00547     // particles deposit their energy along primary track
00548     numofpart += 1;
00549     if(prename == "SBST" ) {
00550       //UserNtuples->filld225(vert_pos.y(),vert_pos.z(),1.);
00551     }
00552     if(prename == "SBSTs" ) {
00553       //UserNtuples->filld226(vert_pos.y(),vert_pos.z(),1.);
00554     }
00555   }
00556 
00557 }
00558 // ==========================================================================
00559 // ==========================================================================
00560 int BscTest::detLevels(const G4VTouchable* touch) const {
00561 
00562   //Return number of levels
00563   if (touch) 
00564     return ((touch->GetHistoryDepth())+1);
00565   else
00566     return 0;
00567 }
00568 // ==========================================================================
00569 
00570 G4String BscTest::detName(const G4VTouchable* touch, int level,
00571                           int currentlevel) const {
00572 
00573   //Go down to current level
00574   if (level > 0 && level >= currentlevel) {
00575     int ii = level - currentlevel; 
00576     return touch->GetVolume(ii)->GetName();
00577   } else {
00578     return "NotFound";
00579   }
00580 }
00581 
00582 void BscTest::detectorLevel(const G4VTouchable* touch, int& level,
00583                             int* copyno, G4String* name) const {
00584 
00585   //Get name and copy numbers
00586   if (level > 0) {
00587     for (int ii = 0; ii < level; ii++) {
00588       int i      = level - ii - 1;
00589       G4VPhysicalVolume* pv = touch->GetVolume(i);
00590       if (pv != 0) 
00591         name[ii] = pv->GetName();
00592       else
00593         name[ii] = "Unknown";
00594       copyno[ii] = touch->GetReplicaNumber(i);
00595     }
00596   }
00597 }
00598 // ==========================================================================
00599 
00600 //===================================================================   End Of Event
00601 void BscTest::update(const EndOfEvent * evt) {
00602   // ==========================================================================
00603   
00604   if (verbosity > 1) {
00605     iev = (*evt)()->GetEventID();
00606     std::cout <<"BscTest:update EndOfEvent = " << iev << std::endl;
00607   }
00608   // Fill-in ntuple
00609   bsceventarray[ntbsc_evt] = (float)whichevent;
00610 
00611   //
00612   int trackID = 0;
00613   G4PrimaryParticle* thePrim=0;
00614 
00615 
00616   // prim.vertex:
00617   G4int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
00618   if (nvertex !=1)
00619     std::cout << "BscTest: My warning: NumberOfPrimaryVertex != 1  -->  = " << nvertex <<  std::endl;
00620 
00621   for (int i = 0 ; i<nvertex; i++) {
00622     G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(i);
00623     if (avertex == 0)
00624       std::cout << "BscTest  End Of Event ERR: pointer to vertex = 0"
00625                 << std::endl;
00626     G4int npart = avertex->GetNumberOfParticle();
00627     if (npart !=1)
00628       std::cout << "BscTest: My warning: NumberOfPrimaryPart != 1  -->  = " << npart <<  std::endl;
00629     if (npart ==0)
00630       std::cout << "BscTest End Of Event ERR: no NumberOfParticle" << std::endl;
00631 
00632     if (thePrim==0) thePrim=avertex->GetPrimary(trackID);
00633 
00634     if (thePrim!=0) {
00635       // primary vertex:
00636       G4double vx=0.,vy=0.,vz=0.;
00637       vx = avertex->GetX0();
00638       vy = avertex->GetY0();
00639       vz = avertex->GetZ0();
00640       //UserNtuples->fillh01(vx);
00641       //UserNtuples->fillh02(vy);
00642       //UserNtuples->fillh03(vz);
00643       TheHistManager->GetHisto("VtxX")->Fill(vx);
00644       TheHistManager->GetHisto("VtxY")->Fill(vy);
00645       TheHistManager->GetHisto("VtxZ")->Fill(vz);
00646     }
00647   }
00648   // prim.vertex loop end
00649 
00650   //=========================== thePrim != 0 ================================================================================
00651   if (thePrim != 0) {
00652     //      inline G4ParticleDefinition * GetG4code() const
00653     //      inline G4PrimaryParticle * GetNext() const
00654     //      inline G4PrimaryParticle * GetDaughter() const
00655 
00656     // prim.vertex
00657     int ivert = 0 ;
00658     G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(ivert);
00659     G4double vx=0.,vy=0.,vz=0.;
00660     vx = avertex->GetX0();
00661     vy = avertex->GetY0();
00662     vz = avertex->GetZ0();
00663 
00664     //
00665     // number of secondary particles deposited their energy along primary track
00666     //UserNtuples->fillg518(numofpart,1.);
00667     if(lastpo.z()<z4 && lastpo.perp()< 100.) {
00668       //UserNtuples->fillg536(numofpart,1.);
00669     }
00670     //
00671 
00672     // direction !!!
00673     G4ThreeVector   mom  = thePrim->GetMomentum();
00674   
00675     double phi = atan2(mom.y(),mom.x());
00676     if (phi < 0.) phi += twopi;
00677     double phigrad = phi*180./pi;
00678 
00679     double th     = mom.theta();
00680     double eta = -log(tan(th/2));
00681     TheHistManager->GetHisto("PrimaryEta")->Fill(eta);
00682     TheHistManager->GetHisto("PrimaryPhigrad")->Fill(phigrad);
00683     TheHistManager->GetHisto("PrimaryTh")->Fill(th*180./pi);
00684 
00685     TheHistManager->GetHisto("PrimaryLastpoZ")->Fill(lastpo.z());
00686     if(lastpo.z() <  z4  ) {
00687       TheHistManager->GetHisto("PrimaryLastpoX")->Fill(lastpo.x());
00688       TheHistManager->GetHisto("PrimaryLastpoY")->Fill(lastpo.y());
00689     }
00690     if(numofpart >  4  ) {
00691       TheHistManager->GetHisto("XLastpoNumofpart")->Fill(lastpo.x());
00692       TheHistManager->GetHisto("YLastpoNumofpart")->Fill(lastpo.y());
00693     }
00694 
00695     // ==========================================================================
00696 
00697     // hit map for Bsc
00698     // ==================================
00699 
00700     map<int,float,less<int> > themap;
00701     map<int,float,less<int> > themap1;
00702 
00703     map<int,float,less<int> > themapxy;
00704     map<int,float,less<int> > themapz;
00705     // access to the G4 hit collections:  -----> this work OK:
00706 
00707     //  edm::LogInfo("BscTest") << "1";
00708     G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
00709     //  edm::LogInfo("BscTest") << "2";
00710     if (verbosity > 0) {
00711       std::cout << "BscTest:  accessed all HC" << std::endl;;
00712     }
00713     int CAFIid = G4SDManager::GetSDMpointer()->GetCollectionID("BSCHits");
00714 
00715     BscG4HitCollection* theCAFI = (BscG4HitCollection*) allHC->GetHC(CAFIid);
00716     if (verbosity > 0) {
00717       std::cout << "BscTest: theCAFI->entries = " << theCAFI->entries() << std::endl;
00718     }
00719     int varia ;   // = 0 -all; =1 - MI; =2 - noMI
00720     varia = 0;
00721     if(  lastpo.z()< z4) {
00722       varia = 1;
00723     }
00724     else{
00725       varia = 2;
00726     }   // no MI end:
00727 
00728     for (int j=0; j<theCAFI->entries(); j++) {
00729       BscG4Hit* aHit = (*theCAFI)[j];
00730       Hep3Vector hitPoint = aHit->getEntry();
00731       double   zz    = hitPoint.z();
00732       TheHistManager->GetHisto("zHits")->Fill(zz);
00733       if(tracklength0>8300.) TheHistManager->GetHisto("zHitsTrLoLe")->Fill(zz);
00734     }
00735     // varia = 0;
00736     //     if( varia == 0) {
00737     if( varia == 2) {
00738 
00739 
00740       int nhit11 = 0, nhit12 = 0, nhit13 = 0 ;
00741       double  totallosenergy= 0.;
00742       for (int j=0; j<theCAFI->entries(); j++) {
00743         BscG4Hit* aHit = (*theCAFI)[j];
00744 
00745         Hep3Vector hitEntryLocalPoint = aHit->getEntryLocalP();
00746         Hep3Vector hitExitLocalPoint = aHit->getExitLocalP();
00747         Hep3Vector hitPoint = aHit->getEntry();
00748         int trackIDhit  = aHit->getTrackID();
00749         unsigned int unitID = aHit->getUnitID();
00750         double  losenergy = aHit->getEnergyLoss();
00751         double phi_hit   = hitPoint.phi();
00752         if (phi_hit < 0.) phi_hit += twopi;
00753 
00754         double   zz    = hitPoint.z();
00755 
00756         TheHistManager->GetHisto("zHitsnoMI")->Fill(zz);
00757 
00758         if (verbosity > 2) {
00759           std::cout << "BscTest:zHits = " << zz << std::endl;
00760         }
00761 
00762         themap[unitID] += losenergy;
00763         totallosenergy += losenergy;
00764 
00765         int det, zside, sector;
00766         BscNumberingScheme::unpackBscIndex(unitID);
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 

Generated on Tue Jun 9 17:46:57 2009 for CMSSW by  doxygen 1.5.4