00001
00002
00003
00004
00005
00006
00007
00009 #include "CompareToReroot.h"
00010 #include "Record/SimSnarlRecord.h"
00011 #include "Record/SimSnarlHeader.h"
00012 #include "MessageService/MsgService.h"
00013 #include "MinosObjectMap/MomNavigator.h"
00014 #include "JobControl/JobCModuleRegistry.h"
00015 #include <map>
00016 #include "RerootExodus/RerootExodus.h"
00017 #include "Plex/PlexHandle.h"
00018 #include "MINF_Classes/MINFast.h"
00019 #include "REROOT_Classes/REROOT_GeomMisc.h"
00020 #include "REROOT_Classes/REROOT_PlanePos.h"
00021 #include "REROOT_Classes/REROOT_PlaneSpec.h"
00022 #include "REROOT_Classes/REROOT_CellPos.h"
00023 #include "Digitization/DigiList.h"
00024 #include "Digitization/DigiPE.h"
00025 #include "Digitization/DigiScintHit.h"
00026 #include "UgliGeometry/UgliGeomHandle.h"
00027
00028 #include "LogCounter.h"
00029
00030 ClassImp(HitCompare)
00031
00032 JOBMODULE(CompareToReroot, "CompareToReroot",
00033 "CompareToReroot");
00034 CVSID("$Id: CompareToReroot.cxx,v 1.8 2006/12/01 20:12:11 rhatcher Exp $");
00035
00036
00037 CompareToReroot::CompareToReroot()
00038 {
00039
00040 fFile = new TFile("reroot_compare.root","RECREATE");
00041 fTree = new TTree("comp","comp");
00042 fHitCompare = new HitCompare;
00043 fTree->Branch("branch","HitCompare",&fHitCompare,32000,1);
00044 }
00045
00046
00047
00048 CompareToReroot::~CompareToReroot()
00049 {
00050 fFile->cd();
00051 fTree->Write("comp");
00052 fFile->Close();
00053 delete fFile;
00054 }
00055
00056
00057
00058 JobCResult CompareToReroot::Ana(const MomNavigator* mom)
00059 {
00060
00061
00062
00063
00064
00065 SimSnarlRecord* simsnarl = 0;
00066 TObject* tobj;
00067 TIter fragiter = mom->FragmentIter();
00068 PlexStripEndId seid;
00069 Float_t adc;
00070 Int_t isAB;
00071 static int event=0;
00072 event++;
00073
00074
00075 while( ( tobj = fragiter.Next() ) ) {
00076 simsnarl = dynamic_cast<SimSnarlRecord*>(tobj);
00077 if(simsnarl) break;
00078 }
00079 const SimSnarlHeader* simHeader = simsnarl->GetSimSnarlHeader();
00080 if(simHeader ==0){
00081 MSG("Photon",Msg::kError) << "Cannot find SimSnarlHeader in SimSnarl." << endl;
00082 return JobCResult::kFailed;
00083 }
00084
00085
00086 VldContext simContext = simHeader->GetVldContext();
00087 PlexHandle plex(simContext);
00088
00089
00090
00091 const TObjArray* hitArray =
00092 dynamic_cast<const TObjArray*>(simsnarl->FindComponent(0,"DigiScintHits"));
00093 if(hitArray==0) {
00094 cout << "Can't find scint hit array.\n";
00095 return JobCResult::kPassed;
00096 };
00097
00098
00099
00100 std::map<int,HitCompare> hmap;
00101 std::map<int,HitCompare>::iterator hmapit;
00102
00103
00104 TIter hitarrayIter(hitArray);
00105 while( (tobj = hitarrayIter.Next()) ) {
00106 const DigiScintHit* scinthit = dynamic_cast<DigiScintHit*>(tobj);
00107 if(scinthit) {
00108 seid = scinthit->StripEndId();
00109 seid.SetEnd(StripEnd::kPositive);
00110 int index1 = seid.GetEncoded();
00111 seid.SetEnd(StripEnd::kNegative);
00112 int index2 = seid.GetEncoded();
00113
00114 hmap[index1].nhits++;
00115 hmap[index1].hit_de += scinthit->DE();
00116 hmap[index1].hit_ds += scinthit->DS();
00117 hmap[index1].hit_x = scinthit->X1();
00118 hmap[index1].hit_t = scinthit->T1();
00119
00120 hmap[index2].nhits++;
00121 hmap[index2].hit_de += scinthit->DE();
00122 hmap[index2].hit_ds += scinthit->DS();
00123 hmap[index2].hit_x = scinthit->X1();
00124 hmap[index2].hit_t = scinthit->T1();
00125 }
00126 }
00127
00128
00129
00130 const TClonesArray *flsdigits = RerootExodus::GetFLSDigitList();
00131 REROOT_FLSDigit *flsdigit = 0;
00132 TIter diter(flsdigits);
00133
00134
00135 Float_t ADAMO_RNULL = 699050. * (Float_t) (16<<26);
00136 while ( ( flsdigit = (REROOT_FLSDigit*) diter.Next() ) ) {
00137
00138 adc = flsdigit->RawA();
00139 isAB = 0;
00140 if ( adc > 0.0 && adc < ADAMO_RNULL ) {
00141 seid = RerootExodus::PECAB2SEId(flsdigit->IPln(),flsdigit->IExtr(),
00142 flsdigit->ICell(),isAB);
00143
00144 if(flsdigit->SignalPEA()>0) {
00145 int index = seid.GetEncoded();
00146 hmap[index].adc_reroot += adc;
00147 hmap[index].tdc_reroot = flsdigit->TDCA();
00148 hmap[index].pe_reroot += flsdigit->SignalPEA();
00149 }
00150 }
00151
00152
00153 adc = flsdigit->RawB();
00154 isAB = 1;
00155 if ( adc > 0.0 && adc < ADAMO_RNULL ) {
00156 seid = RerootExodus::PECAB2SEId(flsdigit->IPln(),flsdigit->IExtr(),
00157 flsdigit->ICell(),isAB);
00158 if(flsdigit->SignalPEB()>0) {
00159 int index = seid.GetEncoded();
00160 hmap[index].adc_reroot += adc;
00161 hmap[index].tdc_reroot = flsdigit->TDCB();
00162 hmap[index].pe_reroot += flsdigit->SignalPEB();
00163 }
00164 }
00165 }
00166
00167
00168
00169
00170 const TObjArray* peListObj =
00171 dynamic_cast<const TObjArray*>(simsnarl->FindTemporary(0,"DigiListPe"));
00172 if(peListObj == 0) {
00173 MSG("DetSim",Msg::kError) << "Cannot find DigiPE list in the SimSnarl. Aborting." << endl;
00174 return JobCResult::kWarning;
00175 }
00176
00177 TObjArrayIter itr(peListObj);
00178 DigiPE* digipe;
00179 while( (digipe = dynamic_cast<DigiPE*>(itr.Next()))!=0 ) {
00180 int index = plex.GetStripEndId(digipe->GetPixelSpotId()).GetEncoded();
00181 float t = digipe->GetTime()*1e9;
00182 if( t < (hmap[index].tfirst_photon)) hmap[index].tfirst_photon = t;
00183 hmap[index].tmean_photon += t;
00184 hmap[index].pe_photon +=1;
00185 };
00186
00187
00188 UgliGeomHandle ugli(simContext);
00189
00190
00191 for(hmapit = hmap.begin(); hmapit!=hmap.end(); hmapit++){
00192 seid = PlexStripEndId(hmapit->first);
00193 hmapit->second.event = event;
00194 hmapit->second.plane = seid.GetPlane();
00195 hmapit->second.strip = seid.GetStrip();
00196 hmapit->second.end = seid.GetEnd();
00197
00198 if(seid.IsValid()) {
00199 UgliStripHandle ustrip = ugli.GetStripHandle(seid);
00200 if(ustrip.IsValid()) {
00201 hmapit->second.halflength = ustrip.GetHalfLength();
00202 hmapit->second.pigtail = ustrip.WlsPigtail(seid.GetEnd());
00203 hmapit->second.clear = ustrip.ClearFiber(seid.GetEnd());
00204 }
00205 }
00206 if(hmapit->second.pe_photon >0)
00207 hmapit->second.tmean_photon /= (float) hmapit->second.pe_photon;
00208 }
00209
00210
00211
00212 double tot_photon = 0;
00213 double tot_reroot = 0;
00214 for(hmapit = hmap.begin(); hmapit!=hmap.end(); hmapit++){
00215 seid = PlexStripEndId(hmapit->first);
00216
00217 seid.SetEnd( (seid.GetEnd()==StripEnd::kPositive)?StripEnd::kNegative:StripEnd::kPositive);
00218 int index = seid.GetEncoded();
00219 hmapit->second.pe_reroot_2 = hmap[index].pe_reroot;
00220 hmapit->second.adc_reroot_2 = hmap[index].adc_reroot;
00221 hmapit->second.tdc_reroot_2 = hmap[index].tdc_reroot;
00222 hmapit->second.pe_photon_2 = hmap[index].pe_photon;
00223 hmapit->second.tfirst_photon_2 = hmap[index].tfirst_photon;
00224 hmapit->second.tmean_photon_2 = hmap[index].tmean_photon;
00225
00226 tot_photon += hmapit->second.pe_photon;
00227 tot_reroot += hmapit->second.pe_reroot;
00228 fHitCompare = &(hmapit->second);
00229 fTree->Fill();
00230 }
00231
00232 static LogCounter counter;
00233 if(counter.Increment()) {
00234 fTree->AutoSave();
00235 cout << counter.fCount << endl;
00236 }
00237 fFile->Write();
00238
00239 static double tot_photon_running = 0;
00240 static double tot_reroot_running = 0;
00241 tot_photon_running += tot_photon;
00242 tot_reroot_running += tot_reroot;
00243 cout << "PhotonTotal: " << tot_photon << "\t RunningTotal:" << tot_photon_running << endl;
00244 cout << "RerootTotal: " << tot_reroot << "\t RunningTotal:" << tot_reroot_running << endl;
00245 cout << "Ratio: " << tot_photon/tot_reroot << "\t RunningTotal:" << tot_photon_running/tot_reroot_running << endl;
00246
00247 return JobCResult::kPassed;
00248 }
00249