00001 #ifndef moqbase_cxx
00002 #define moqbase_cxx
00003 #include <iostream>
00004
00005 #include "TClonesArray.h"
00006 #include "OfflineMonitor/MoqBase.h"
00007
00008
00009
00010 MoqBase::MoqBase(TChain *chainSR,TChain *chainMC,
00011 TChain *chainTH,TChain *chainEM)
00012 {
00013
00014 fCurRun = -1;
00015 lastEntry = -1;
00016 if(!chainSR) {
00017 record = 0;
00018 emrecord = 0;
00019 mcrecord = 0;
00020 threcord = 0;
00021 Clear();
00022 whichSource = -1;
00023 isMC = true;
00024 isTH = true;
00025 isEM = true;
00026 Nentries = -1;
00027 fCurRun = -1;
00028 return;
00029 }
00030
00031 InitChain(chainSR,chainMC,chainTH,chainEM);
00032 whichSource = 0;
00033
00034 }
00035
00036 MoqBase::MoqBase(JobC *j,string path,int entries)
00037 {
00038 record = 0;
00039 emrecord = 0;
00040 mcrecord = 0;
00041 threcord = 0;
00042 Clear();
00043 isMC = true;
00044 isTH = true;
00045 isEM = true;
00046 Nentries = entries;
00047 whichSource = 1;
00048 jcPath = path;
00049 fCurRun = -1;
00050 lastEntry = -1;
00051 fJC = j;
00052 fChain = NULL;
00053 }
00054
00055 MoqBase::~MoqBase()
00056 {
00057 if(fChain) delete fChain;
00058 }
00059
00060
00061 Int_t MoqBase::GetEntry(Int_t entry)
00062 {
00063
00064 Clear();
00065
00066
00067 int status = 0;
00068 if(whichSource==-1) return 0;
00069 else if(whichSource==0) {
00070 if(entry!=lastEntry) {
00071 status = fChain->Get(entry);
00072 lastEntry = entry;
00073 }
00074 else status = 1;
00075 record = fChain->Record;
00076 mcrecord = fChain->mcRecord;
00077 threcord = fChain->thRecord;
00078 emrecord = fChain->emRecord;
00079 }
00080 else if(whichSource==1) {
00081
00082 isMC = isTH = isEM = true;
00083
00084
00085
00086 if(entry!=lastEntry) {
00087 if(fCurRun!=-1) fJC->Input.GoTo(fCurRun,entry);
00088 fJC->Path(jcPath.c_str()).RunNin(1);
00089 lastEntry = entry;
00090 }
00091
00092 record = (NtpSRRecord*) fJC->Mom.GetFragment("NtpSRRecord");
00093 mcrecord = (NtpMCRecord*) fJC->Mom.GetFragment("NtpMCRecord");
00094 threcord = (NtpTHRecord*) fJC->Mom.GetFragment("NtpTHRecord");
00095 emrecord = (NtpEMRecord*) fJC->Mom.GetFragment("NtpEMRecord");
00096
00097 if(record==0) return 0;
00098
00099 status = 1;
00100 if(mcrecord==0) isMC = false;
00101 if(threcord==0) isTH = false;
00102 if(emrecord==0) isEM = false;
00103 }
00104 else return 0;
00105
00106
00107 ntpHeader = &(record->GetHeader());
00108 fCurRun = ntpHeader->GetRun();
00109 shieldSummary = &(record->vetohdr);
00110 eventSummary = &(record->evthdr);
00111 LoadSlice(0);
00112 LoadEvent(0);
00113 LoadTrack(0);
00114 LoadShower(0);
00115 LoadShieldStrip(0);
00116
00117 if(isEM) {
00118 ntpEMSummary = &(emrecord->emhdr);
00119 LoadEMShower(0);
00120 }
00121
00122 if(isMC) {
00123 LoadTruth(0);
00124 LoadStdHep(0);
00125 }
00126
00127 if(isTH) {
00128 LoadTHSlice(0);
00129 LoadTHTrack(0);
00130 LoadTHShower(0);
00131 }
00132 return status;
00133
00134 }
00135
00136 void MoqBase::InitChain(TChain *chainSR,TChain *chainMC,
00137 TChain *chainTH,TChain *chainEM)
00138 {
00139
00140 record = 0;
00141 emrecord = 0;
00142 mcrecord = 0;
00143 threcord = 0;
00144
00145 fChain = new MoqChain(chainSR,chainMC,chainTH,chainEM);
00146 isMC = fChain->isMC;
00147 isTH = fChain->isTH;
00148 isEM = fChain->isEM;
00149 Nentries = fChain->Nentries;
00150
00151 if(isMC) std::cout << "MC Present" << std::endl;
00152 if(isTH) std::cout << "TH Present" << std::endl;
00153 if(isEM) std::cout << "EM Present" << std::endl;
00154
00155 }
00156
00157 void MoqBase::Clear(){
00158
00159 ntpHeader = 0;
00160 shieldSummary = 0;
00161 eventSummary = 0;
00162 ntpSlice=0;
00163 ntpEvent=0;
00164 ntpTrack=0;
00165 ntpShower=0;
00166 ntpStrip=0;
00167 ntpShieldStrip=0;
00168
00169 ntpTruth=0;
00170 ntpStdHep=0;
00171
00172 ntpTHSlice=0;
00173 ntpTHTrack=0;
00174 ntpTHShower=0;
00175
00176 ntpEMSummary = 0;
00177 ntpEMShower = 0;
00178
00179 }
00180
00181
00182 Bool_t MoqBase::LoadTrack(Int_t itrk){
00183
00184 Bool_t status = false;
00185 TClonesArray& trackArray = *(record->trk);
00186 if(itrk>=0&&itrk<trackArray.GetEntries()) {
00187 ntpTrack = dynamic_cast<NtpSRTrack *>(trackArray[itrk]);
00188 status = true;
00189 }
00190 else ntpTrack = 0;
00191
00192 return status;
00193 }
00194
00195 Bool_t MoqBase::LoadTHTrack(Int_t itrk){
00196
00197 Bool_t status = false;
00198 if(!isTH) return status;
00199 TClonesArray& trackArray = *(threcord->thtrk);
00200 if(itrk>=0&&itrk<trackArray.GetEntries()) {
00201 ntpTHTrack = dynamic_cast<NtpTHTrack *>(trackArray[itrk]);
00202 status = true;
00203 }
00204 else ntpTHTrack = 0;
00205
00206 return status;
00207 }
00208
00209 Bool_t MoqBase::LoadShower(Int_t ishw){
00210
00211 Bool_t status = false;
00212 TClonesArray& showerArray = *(record->shw);
00213 if(ishw>=0&&ishw<showerArray.GetEntries()) {
00214 ntpShower = dynamic_cast<NtpSRShower *>(showerArray[ishw]);
00215 status = true;
00216 }
00217 else ntpShower = 0;
00218
00219 return status;
00220 }
00221
00222 Bool_t MoqBase::LoadTHShower(Int_t ishw){
00223
00224 Bool_t status = false;
00225 if(!isTH) return status;
00226 TClonesArray& showerArray = *(threcord->thshw);
00227 if(ishw>=0&&ishw<showerArray.GetEntries()) {
00228 ntpTHShower = dynamic_cast<NtpTHShower *>(showerArray[ishw]);
00229 status = true;
00230 }
00231 else ntpTHShower = 0;
00232
00233 return status;
00234 }
00235
00236 Bool_t MoqBase::LoadSlice(Int_t islc){
00237
00238 Bool_t status = false;
00239 TClonesArray& sliceArray = *(record->slc);
00240 if(islc>=0&&islc<sliceArray.GetEntries()) {
00241 ntpSlice = dynamic_cast<NtpSRSlice *>(sliceArray[islc]);
00242 status = true;
00243 }
00244 else ntpSlice = 0;
00245
00246 return status;
00247 }
00248
00249 Bool_t MoqBase::LoadTHSlice(Int_t islc){
00250
00251 Bool_t status = false;
00252 if(!isTH) return status;
00253 TClonesArray& sliceArray = *(threcord->thslc);
00254 if(islc>=0&&islc<sliceArray.GetEntries()) {
00255 ntpTHSlice = dynamic_cast<NtpTHSlice *>(sliceArray[islc]);
00256 status = true;
00257 }
00258 else ntpTHSlice = 0;
00259
00260 return status;
00261 }
00262
00263 Bool_t MoqBase::LoadEvent(Int_t ievt){
00264
00265 Bool_t status = false;
00266 TClonesArray& eventArray = *(record->evt);
00267 if(ievt>=0&&ievt<eventArray.GetEntries()) {
00268 ntpEvent = dynamic_cast<NtpSREvent *>(eventArray[ievt]);
00269 status = true;
00270 }
00271 else ntpEvent = 0;
00272
00273 return status;
00274 }
00275
00276 Bool_t MoqBase::LoadTruth(Int_t itr){
00277
00278 Bool_t status = false;
00279 if(!isMC) return status;
00280 TClonesArray& mcArray = *(mcrecord->mc);
00281 if(itr>=0&&itr<mcArray.GetEntries()) {
00282 ntpTruth = dynamic_cast<NtpMCTruth *>(mcArray[itr]);
00283 status = true;
00284 }
00285 else ntpTruth = 0;
00286
00287 return status;
00288 }
00289
00290 Bool_t MoqBase::LoadStdHep(Int_t ish){
00291
00292 Bool_t status = false;
00293 if(!isMC) return status;
00294 TClonesArray& stdhepArray = *(mcrecord->stdhep);
00295 if(ish>=0&&ish<stdhepArray.GetEntries()) {
00296 ntpStdHep = dynamic_cast<NtpMCStdHep *>(stdhepArray[ish]);
00297 status = true;
00298 }
00299 else ntpStdHep = 0;
00300
00301 return status;
00302 }
00303
00304 Bool_t MoqBase::LoadTruthForReco(Int_t ievt,Int_t &itruth){
00305
00306 Bool_t status = false;
00307 ntpTruth = 0;
00308 if(!LoadEvent(ievt)) return status;
00309 if(!isMC) return status;
00310
00311 TClonesArray& mcArray = *(mcrecord->mc);
00312 if(mcArray.GetEntries()==1) {
00313 LoadTruth(0);
00314 return true;
00315 }
00316
00317 float mindist = 999;
00318 int itr = 0;
00319
00320 for(int i=0;i<mcArray.GetEntries();i++){
00321 ntpTruth = dynamic_cast<NtpMCTruth *>(mcArray[i]);
00322 float dist = sqrt(TMath::Power(ntpTruth->vtxx/100.-ntpEvent->vtx.x,2)
00323 +TMath::Power(ntpTruth->vtxy/100.-ntpEvent->vtx.y,2)
00324 +TMath::Power(ntpTruth->vtxz/100.-ntpEvent->vtx.z,2));
00325 if(dist<mindist) {
00326 itr = i;
00327 mindist = dist;
00328 }
00329 }
00330
00331 if(mindist<0.5) {
00332 status = true;
00333 LoadTruth(itr);
00334 itruth = itr;
00335 }
00336 return status;
00337 }
00338
00339 Bool_t MoqBase::LoadSliceForRecoTH(Int_t ievt,Int_t &islice){
00340
00341 Bool_t status = false;
00342 ntpSlice = 0;
00343 if(!LoadEvent(ievt)) return status;
00344 if(!isMC) return status;
00345 if(!isTH) return status;
00346
00347 Int_t itru = 0;
00348 if(LoadTruthForRecoTH(ievt,itru)){
00349 Int_t count = 0;
00350 while(!status){
00351 if(!LoadTHSlice(count)) break;
00352 if(ntpTHSlice->neumc==itru) {
00353 if(LoadSlice(count)){
00354 islice = count;
00355 status = true;
00356 }
00357 }
00358 count += 1;
00359 }
00360 }
00361 return status;
00362 }
00363
00364
00365 Bool_t MoqBase::LoadTruthForRecoTH(Int_t ievt,Int_t &itruth){
00366
00367 Bool_t status = false;
00368 ntpTruth = 0;
00369 if(!LoadEvent(ievt)) return status;
00370 if(!isMC) return status;
00371 if(!isTH) return status;
00372
00373 if(ntpEvent->ntrack>0) {
00374 int *tracks = ntpEvent->trk;
00375 if(LoadTHTrack(int(tracks[0]))){
00376 int ind = ntpTHTrack->neumc;
00377 if(LoadTruth(ind)) {
00378 itruth = ind;
00379 status = true;
00380 }
00381 }
00382 }
00383 if(!status&&ntpEvent->nshower>0) {
00384 int *showers = ntpEvent->shw;
00385 if(LoadTHShower(int(showers[0]))){
00386 int ind = ntpTHShower->neumc;
00387 if(LoadTruth(ind)) {
00388 itruth = ind;
00389 status = true;
00390 }
00391 }
00392 }
00393 return status;
00394
00395 }
00396
00397 Bool_t MoqBase::LoadStrip(Int_t istp){
00398
00399 Bool_t status = false;
00400 TClonesArray& stripArray = *(record->stp);
00401 if(istp>=0&&istp<stripArray.GetEntries()) {
00402 ntpStrip = dynamic_cast<NtpSRStrip *>(stripArray[istp]);
00403 status = true;
00404 }
00405 else ntpStrip = 0;
00406
00407 return status;
00408 }
00409
00410 Bool_t MoqBase::LoadShieldStrip(Int_t istp){
00411
00412 Bool_t status = false;
00413 TClonesArray& stripArray = *(record->vetostp);
00414 if(istp>=0&&istp<stripArray.GetEntries()) {
00415 ntpShieldStrip = dynamic_cast<NtpSRShieldStrip *>(stripArray[istp]);
00416 status = true;
00417 }
00418 else ntpShieldStrip = 0;
00419
00420 return status;
00421 }
00422
00423 Bool_t MoqBase::LoadEMShower(Int_t ishw){
00424
00425 Bool_t status = false;
00426 if(!isEM) return status;
00427 TClonesArray& showerArray = *(emrecord->emshw);
00428 if(ishw>=0&&ishw<showerArray.GetEntries()) {
00429 ntpEMShower = dynamic_cast<NtpEMShower *>(showerArray[ishw]);
00430 status = true;
00431 }
00432 else ntpEMShower = 0;
00433
00434 return status;
00435 }
00436
00437 #endif // #ifdef moqbase_cxx