#include <SimG4CMS/Forward/interface/CastorTestAnalysis.h>
Public Member Functions | |
CastorTestAnalysis (const edm::ParameterSet &p) | |
virtual | ~CastorTestAnalysis () |
Private Member Functions | |
void | Finish () |
void | update (const G4Step *step) |
This routine will be called when the appropriate signal arrives. | |
void | update (const EndOfEvent *evt) |
This routine will be called when the appropriate signal arrives. | |
void | update (const BeginOfEvent *evt) |
This routine will be called when the appropriate signal arrives. | |
void | update (const EndOfRun *run) |
This routine will be called when the appropriate signal arrives. | |
void | update (const BeginOfRun *run) |
This routine will be called when the appropriate signal arrives. | |
void | update (const BeginOfJob *run) |
This routine will be called when the appropriate signal arrives. | |
Private Attributes | |
Float_t | castoreventarray [11] |
TNtuple * | castoreventntuple |
TFile * | castorOutputEventFile |
TFile * | castorOutputStepFile |
Float_t | castorsteparray [14] |
TNtuple * | castorstepntuple |
int | doNTcastorevent |
int | doNTcastorstep |
int | eventIndex |
std::string | eventNtFileName |
int | stepIndex |
std::string | stepNtFileName |
int | verbosity |
Definition at line 63 of file CastorTestAnalysis.h.
CastorTestAnalysis::CastorTestAnalysis | ( | const edm::ParameterSet & | p | ) |
Definition at line 32 of file CastorTestAnalysis.cc.
References castoreventntuple, castorstepntuple, GenMuonPlsPt100GeV_cfg::cout, doNTcastorevent, doNTcastorstep, lat::endl(), eventNtFileName, edm::ParameterSet::getParameter(), stepNtFileName, and verbosity.
00032 { 00033 00034 edm::ParameterSet m_Anal = p.getParameter<edm::ParameterSet>("CastorTestAnalysis"); 00035 verbosity = m_Anal.getParameter<int>("Verbosity"); 00036 doNTcastorstep = m_Anal.getParameter<int>("StepNtupleFlag"); 00037 doNTcastorevent = m_Anal.getParameter<int>("EventNtupleFlag"); 00038 stepNtFileName = m_Anal.getParameter<std::string>("StepNtupleFileName"); 00039 eventNtFileName = m_Anal.getParameter<std::string>("EventNtupleFileName"); 00040 00041 if (verbosity > 0) 00042 std::cout<<std::endl; 00043 std::cout<<"============================================================================"<<std::endl; 00044 std::cout << "CastorTestAnalysis:: Initialized as observer"<< std::endl; 00045 if (doNTcastorstep > 0){ 00046 std::cout <<" Step Ntuple will be created"<< std::endl; 00047 std::cout <<" Step Ntuple file: "<<stepNtFileName<<std::endl; 00048 } 00049 if (doNTcastorevent > 0){ 00050 std::cout <<" Event Ntuple will be created"<< std::endl; 00051 std::cout <<" Step Ntuple file: "<<stepNtFileName<<std::endl; 00052 } 00053 std::cout<<"============================================================================"<<std::endl; 00054 std::cout<<std::endl; 00055 00056 if (doNTcastorstep > 0) 00057 castorstepntuple = new TNtuple("NTcastorstep","NTcastorstep","evt:trackid:charge:pdgcode:x:y:z:stepl:stepe:eta:phi:vpx:vpy:vpz"); 00058 00059 if (doNTcastorevent > 0) 00060 castoreventntuple = new TNtuple("NTcastorevent","NTcastorevent","evt:ihit:detector:sector:module:enem:totalenergy:hitenergy:x:y:z"); 00061 }
CastorTestAnalysis::~CastorTestAnalysis | ( | ) | [virtual] |
Definition at line 63 of file CastorTestAnalysis.cc.
References GenMuonPlsPt100GeV_cfg::cout, lat::endl(), Finish(), and verbosity.
00063 { 00064 //destructor of CastorTestAnalysis 00065 00066 Finish(); 00067 if (verbosity > 0) { 00068 std::cout << std::endl << "End of CastorTestAnalysis" 00069 << std::endl; 00070 } 00071 00072 std::cout<<"CastorTestAnalysis: End of process"<<std::endl; 00073 00074 }
void CastorTestAnalysis::Finish | ( | ) | [private] |
Definition at line 328 of file CastorTestAnalysis.cc.
References castoreventntuple, castorOutputEventFile, castorOutputStepFile, castorstepntuple, GenMuonPlsPt100GeV_cfg::cout, doNTcastorevent, doNTcastorstep, and lat::endl().
Referenced by ~CastorTestAnalysis().
00328 { 00329 if (doNTcastorstep) { 00330 castorOutputStepFile->cd(); 00331 castorstepntuple->Write(); 00332 std::cout << "CastorTestAnalysis: Ntuple step written" <<std::endl; 00333 castorOutputStepFile->Close(); 00334 std::cout << "CastorTestAnalysis: Step file closed" << std::endl; 00335 } 00336 00337 if (doNTcastorevent) { 00338 castorOutputEventFile->cd(); 00339 castoreventntuple->Write("",TObject::kOverwrite); 00340 std::cout << "CastorTestAnalysis: Ntuple event written" << std::endl; 00341 castorOutputEventFile->Close(); 00342 std::cout << "CastorTestAnalysis: Event file closed" << std::endl; 00343 } 00344 00345 }
void CastorTestAnalysis::update | ( | const G4Step * | ) | [private, virtual] |
This routine will be called when the appropriate signal arrives.
Implements Observer< const G4Step * >.
Definition at line 111 of file CastorTestAnalysis.cc.
References castorsteparray, castorstepntuple, GenMuonPlsPt100GeV_cfg::cout, doNTcastorstep, lat::endl(), eta, eventIndex, funct::log(), ntcastors_charge, ntcastors_eta, ntcastors_evt, ntcastors_pdgcode, ntcastors_phi, ntcastors_stepe, ntcastors_stepl, ntcastors_trackid, ntcastors_vpx, ntcastors_vpy, ntcastors_vpz, ntcastors_x, ntcastors_y, ntcastors_z, phi, stepIndex, and verbosity.
00111 { 00112 stepIndex++; 00113 00114 00115 if (doNTcastorstep) { 00116 00117 G4StepPoint * preStepPoint = aStep->GetPreStepPoint(); 00118 // G4StepPoint * postStepPoint= aStep->GetPostStepPoint(); 00119 G4double stepL = aStep->GetStepLength(); 00120 G4double stepE = aStep->GetTotalEnergyDeposit(); 00121 00122 if (verbosity >= 2) 00123 std::cout << "Step " << stepL << ", " << stepE << std::endl; 00124 00125 G4Track * theTrack = aStep->GetTrack(); 00126 G4int theTrackID = theTrack->GetTrackID(); 00127 G4double theCharge = theTrack->GetDynamicParticle()->GetCharge(); 00128 G4String particleType = theTrack->GetDefinition()->GetParticleName(); 00129 G4int pdgcode = theTrack->GetDefinition()->GetPDGEncoding(); 00130 00131 G4ThreeVector vert_mom = theTrack->GetVertexMomentumDirection(); 00132 G4double vpx = vert_mom.x(); 00133 G4double vpy = vert_mom.y(); 00134 G4double vpz = vert_mom.z(); 00135 double eta = 0.5 * log( (1.+vpz) / (1.-vpz) ); 00136 double phi = atan2(vpy,vpx); 00137 00138 G4ThreeVector hitPoint = preStepPoint->GetPosition(); 00139 00140 // Fill-in ntuple 00141 // castorsteparray[ntcastors_evt] = (*evt)()->GetEventID(); 00142 castorsteparray[ntcastors_evt] = (float)eventIndex; 00143 castorsteparray[ntcastors_trackid] = (float)theTrackID; 00144 castorsteparray[ntcastors_charge] = theCharge; 00145 castorsteparray[ntcastors_pdgcode] = pdgcode; 00146 castorsteparray[ntcastors_x] = hitPoint.x(); 00147 castorsteparray[ntcastors_y] = hitPoint.y(); 00148 castorsteparray[ntcastors_z] = hitPoint.z(); 00149 castorsteparray[ntcastors_stepl] = stepL; 00150 castorsteparray[ntcastors_stepe] = stepE; 00151 castorsteparray[ntcastors_eta] = eta; 00152 castorsteparray[ntcastors_phi] = phi; 00153 castorsteparray[ntcastors_vpx] = vpx; 00154 castorsteparray[ntcastors_vpy] = vpy; 00155 castorsteparray[ntcastors_vpz] = vpz; 00156 00157 /* 00158 std::cout<<"TrackID: "<< theTrackID<<std::endl; 00159 std::cout<<" StepN: "<< theTrack->GetCurrentStepNumber() <<std::endl; 00160 std::cout<<" ParentID: "<< aStep->GetTrack()->GetParentID() <<std::endl; 00161 std::cout<<" PDG: "<< pdgcode <<std::endl; 00162 std::cout<<" X,Y,Z (mm): "<< theTrack->GetPosition().x() <<","<< theTrack->GetPosition().y() <<","<< theTrack->GetPosition().z() <<std::endl; 00163 std::cout<<" KE (MeV): "<< theTrack->GetKineticEnergy() <<std::endl; 00164 std::cout<<" Total EDep (MeV): "<< aStep->GetTotalEnergyDeposit() <<std::endl; 00165 std::cout<<" StepLength (mm): "<< aStep->GetStepLength() <<std::endl; 00166 std::cout<<" TrackLength (mm): "<< theTrack->GetTrackLength() <<std::endl; 00167 00168 if ( theTrack->GetNextVolume() != 0 ) 00169 std::cout<<" NextVolume: "<< theTrack->GetNextVolume()->GetName() <<std::endl; 00170 else 00171 std::cout<<" NextVolume: OutOfWorld"<<std::endl; 00172 00173 if(aStep->GetPostStepPoint()->GetProcessDefinedStep() != NULL) 00174 std::cout<<" ProcessName: "<< aStep->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName() <<std::endl; 00175 else 00176 std::cout<<" ProcessName: UserLimit"<<std::endl; 00177 00178 00179 std::cout<<std::endl; 00180 */ 00181 00182 00183 00184 //fill ntuple with step level information 00185 castorstepntuple->Fill(castorsteparray); 00186 } 00187 }
void CastorTestAnalysis::update | ( | const EndOfEvent * | ) | [private, virtual] |
This routine will be called when the appropriate signal arrives.
Implements Observer< const EndOfEvent * >.
Definition at line 190 of file CastorTestAnalysis.cc.
References castoreventarray, castoreventntuple, GenMuonPlsPt100GeV_cfg::cout, doNTcastorevent, lat::endl(), eta, eventIndex, CaloG4Hit::getEnergyDeposit(), CaloG4Hit::getEntry(), CaloG4Hit::getUnitID(), i, funct::log(), max, min, npart, ntcastore_detector, ntcastore_enem, ntcastore_enhad, ntcastore_evt, ntcastore_hitenergy, ntcastore_ihit, ntcastore_module, ntcastore_sector, ntcastore_x, ntcastore_y, ntcastore_z, phi, funct::pow(), funct::sqrt(), funct::tan(), theta, and CastorNumberingScheme::unpackIndex().
00190 { 00191 00192 // Look for the Hit Collection 00193 std::cout << std::endl << "CastorTest::update(EndOfEvent * evt) - event #" << (*evt)()->GetEventID() << std::endl; 00194 00195 // access to the G4 hit collections 00196 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent(); 00197 std::cout << "update(*evt) --> accessed all HC"; 00198 00199 int CAFIid = G4SDManager::GetSDMpointer()->GetCollectionID("CastorFI"); 00200 00201 // int CAPLid = G4SDManager::GetSDMpointer()->GetCollectionID("CASTPL"); 00202 // int CABUid = G4SDManager::GetSDMpointer()->GetCollectionID("CASTBU"); 00203 // int CATUid = G4SDManager::GetSDMpointer()->GetCollectionID("CASTTU"); 00204 00205 CaloG4HitCollection* theCAFI = (CaloG4HitCollection*) allHC->GetHC(CAFIid); 00206 // CaloG4HitCollection* theCAPL = (CaloG4HitCollection*) allHC->GetHC(CAPLid); 00207 // CaloG4HitCollection* theCABU = (CaloG4HitCollection*) allHC->GetHC(CABUid); 00208 // CaloG4HitCollection* theCATU = (CaloG4HitCollection*) allHC->GetHC(CATUid); 00209 00210 CastorNumberingScheme *theCastorNumScheme = new CastorNumberingScheme(); 00211 00212 unsigned int volumeID=0; 00213 std::map<int,float,std::less<int> > themap; 00214 double en_in_fi = 0.; 00215 float totalEnergy = 0; 00216 // double en_in_pl = 0.; 00217 // double en_in_bu = 0.; 00218 // double en_in_tu = 0.; 00219 00220 int nentries = theCAFI->entries(); 00221 00222 if (doNTcastorevent) { 00223 if (nentries > 0) { 00224 for (int ihit = 0; ihit < nentries; ihit++) { 00225 CaloG4Hit* aHit = (*theCAFI)[ihit]; 00226 totalEnergy += aHit->getEnergyDeposit(); 00227 } 00228 00229 for (int ihit = 0; ihit < nentries; ihit++) { 00230 CaloG4Hit* aHit = (*theCAFI)[ihit]; 00231 volumeID = aHit->getUnitID(); 00232 double hitEnergy = aHit->getEnergyDeposit(); 00233 en_in_fi += aHit->getEnergyDeposit(); 00234 // double enEm = aHit->getEM(); 00235 // double enHad = aHit->getHadr(); 00236 00237 // TPM: this doesn't compile for me 00238 //math::XYZPoint hitPoint = aHit->getEntry(); 00239 00240 themap[volumeID] += aHit->getEnergyDeposit(); 00241 int det, zside, sector, zmodule; 00242 00243 // theCastorNumScheme->unpackIndex(volumeID, det, zside, sector,zmodule); 00244 00245 theCastorNumScheme->unpackIndex(volumeID, zside, sector,zmodule); 00246 00247 // int index = CaloNumberingPacker::packCastorIndex(det,zside,sector,zmodule); 00248 // float theTotalEnergy = themap[index]; 00249 00250 castoreventarray[ntcastore_evt] = (float)eventIndex; 00251 castoreventarray[ntcastore_ihit] = (float)ihit; 00252 castoreventarray[ntcastore_detector] = (float)det; 00253 castoreventarray[ntcastore_sector] = (float)sector; 00254 castoreventarray[ntcastore_module] = (float)zmodule; 00255 castoreventarray[ntcastore_enem] = en_in_fi; 00256 castoreventarray[ntcastore_enhad] = totalEnergy; 00257 castoreventarray[ntcastore_hitenergy] = hitEnergy; 00258 castoreventarray[ntcastore_x] = aHit->getEntry().x(); 00259 castoreventarray[ntcastore_y] = aHit->getEntry().y(); 00260 castoreventarray[ntcastore_z] = aHit->getEntry().z(); 00261 00262 castoreventntuple->Fill(castoreventarray); 00263 } 00264 00265 // Find Primary info: 00266 int trackID = 0; 00267 int particleType = 0; 00268 G4PrimaryParticle* thePrim=0; 00269 G4int nvertex = (*evt)()->GetNumberOfPrimaryVertex(); 00270 std::cout << "Event has " << nvertex << " vertex" << std::endl; 00271 if (nvertex==0) 00272 std::cout << "CASTORTest End Of Event ERROR: no vertex" << std::endl; 00273 00274 for (int i = 0 ; i<nvertex; i++) { 00275 00276 G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(i); 00277 if (avertex == 0) 00278 std::cout << "CASTORTest End Of Event ERR: pointer to vertex = 0" << std::endl; 00279 std::cout << "Vertex number :" <<i << std::endl; 00280 int npart = avertex->GetNumberOfParticle(); 00281 if (npart ==0) 00282 std::cout << "CASTORTest End Of Event ERR: no primary!" << std::endl; 00283 if (thePrim==0) thePrim=avertex->GetPrimary(trackID); 00284 } 00285 00286 double px=0.,py=0.,pz=0.; 00287 double eta = 0., phi = 0., pInit = 0.; 00288 00289 if (thePrim != 0) { 00290 px = thePrim->GetPx(); 00291 py = thePrim->GetPy(); 00292 pz = thePrim->GetPz(); 00293 pInit = sqrt(pow(px,2.)+pow(py,2.)+pow(pz,2.)); 00294 if (pInit==0) { 00295 std::cout << "CASTORTest End Of Event ERR: primary has p=0 " << std::endl; 00296 } else { 00297 float costheta = pz/pInit; 00298 float theta = acos(std::min(std::max(costheta,float(-1.)),float(1.))); 00299 eta = -log(tan(theta/2)); 00300 00301 if (px != 0) phi = atan(py/px); 00302 } 00303 particleType = thePrim->GetPDGcode(); 00304 } else { 00305 std::cout << "CASTORTest End Of Event ERR: could not find primary " 00306 << std::endl; 00307 } 00308 00309 00310 } // nentries > 0 00311 } 00312 00313 int iEvt = (*evt)()->GetEventID(); 00314 if (iEvt < 10) 00315 std::cout << " CastorTest Event " << iEvt << std::endl; 00316 else if ((iEvt < 100) && (iEvt%10 == 0)) 00317 std::cout << " CastorTest Event " << iEvt << std::endl; 00318 else if ((iEvt < 1000) && (iEvt%100 == 0)) 00319 std::cout << " CastorTest Event " << iEvt << std::endl; 00320 else if ((iEvt < 10000) && (iEvt%1000 == 0)) 00321 std::cout << " CastorTest Event " << iEvt << std::endl; 00322 00323 std::cout << std::endl << "===>>> Done writing user histograms " << std::endl; 00324 }
void CastorTestAnalysis::update | ( | const BeginOfEvent * | ) | [private, virtual] |
This routine will be called when the appropriate signal arrives.
Implements Observer< const BeginOfEvent * >.
Definition at line 102 of file CastorTestAnalysis.cc.
References GenMuonPlsPt100GeV_cfg::cout, lat::endl(), eventIndex, and stepIndex.
00102 { 00103 std::cout << "CastorTestAnalysis: Processing Event Number: "<<eventIndex<< std::endl; 00104 eventIndex++; 00105 stepIndex = 0; 00106 }
This routine will be called when the appropriate signal arrives.
Implements Observer< const EndOfRun * >.
Definition at line 326 of file CastorTestAnalysis.cc.
void CastorTestAnalysis::update | ( | const BeginOfRun * | ) | [private, virtual] |
This routine will be called when the appropriate signal arrives.
Implements Observer< const BeginOfRun * >.
Definition at line 83 of file CastorTestAnalysis.cc.
References castorOutputEventFile, castorOutputStepFile, GenMuonPlsPt100GeV_cfg::cout, doNTcastorevent, doNTcastorstep, lat::endl(), eventIndex, eventNtFileName, and stepNtFileName.
00083 { 00084 00085 std::cout << std::endl << "CastorTestAnalysis: Starting Run"<< std::endl; 00086 if (doNTcastorstep) { 00087 std::cout << "CastorTestAnalysis: output step root file created"<< std::endl; 00088 TString stepfilename = stepNtFileName; 00089 castorOutputStepFile = new TFile(stepfilename,"RECREATE"); 00090 00091 } 00092 00093 if (doNTcastorevent) { 00094 std::cout << "CastorTestAnalysis: output event root file created"<< std::endl; 00095 TString stepfilename = eventNtFileName; 00096 castorOutputEventFile = new TFile(stepfilename,"RECREATE"); 00097 } 00098 00099 eventIndex = 0; 00100 }
void CastorTestAnalysis::update | ( | const BeginOfJob * | ) | [private, virtual] |
This routine will be called when the appropriate signal arrives.
Implements Observer< const BeginOfJob * >.
Definition at line 77 of file CastorTestAnalysis.cc.
References GenMuonPlsPt100GeV_cfg::cout, and lat::endl().
Float_t CastorTestAnalysis::castoreventarray[11] [private] |
TNtuple* CastorTestAnalysis::castoreventntuple [private] |
Definition at line 98 of file CastorTestAnalysis.h.
Referenced by CastorTestAnalysis(), Finish(), and update().
TFile* CastorTestAnalysis::castorOutputEventFile [private] |
TFile* CastorTestAnalysis::castorOutputStepFile [private] |
Float_t CastorTestAnalysis::castorsteparray[14] [private] |
TNtuple* CastorTestAnalysis::castorstepntuple [private] |
Definition at line 97 of file CastorTestAnalysis.h.
Referenced by CastorTestAnalysis(), Finish(), and update().
int CastorTestAnalysis::doNTcastorevent [private] |
Definition at line 90 of file CastorTestAnalysis.h.
Referenced by CastorTestAnalysis(), Finish(), and update().
int CastorTestAnalysis::doNTcastorstep [private] |
Definition at line 89 of file CastorTestAnalysis.h.
Referenced by CastorTestAnalysis(), Finish(), and update().
int CastorTestAnalysis::eventIndex [private] |
std::string CastorTestAnalysis::eventNtFileName [private] |
Definition at line 92 of file CastorTestAnalysis.h.
Referenced by CastorTestAnalysis(), and update().
int CastorTestAnalysis::stepIndex [private] |
std::string CastorTestAnalysis::stepNtFileName [private] |
Definition at line 91 of file CastorTestAnalysis.h.
Referenced by CastorTestAnalysis(), and update().
int CastorTestAnalysis::verbosity [private] |
Definition at line 88 of file CastorTestAnalysis.h.
Referenced by CastorTestAnalysis(), update(), and ~CastorTestAnalysis().