00001
00002
00003
00004
00005
00006
00008
00009 #include "RerootExodus/RerootFlsDigitToDigiPE.h"
00010 #include "RerootExodus/RerootExodus.h"
00011
00012 #include "MinosObjectMap/MomNavigator.h"
00013 #include "MessageService/MsgService.h"
00014 #include "MessageService/MsgFormat.h"
00015 #include "JobControl/JobCModuleRegistry.h"
00016 #include "JobControl/JobCommand.h"
00017
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
00024 #include "Plex/PlexHandle.h"
00025
00026 #include "Digitization/DigiList.h"
00027 #include "Digitization/DigiPE.h"
00028 #include "Record/SimSnarlRecord.h"
00029 #include "Record/SimSnarlHeader.h"
00030
00031 #include "TMath.h"
00032
00033 ClassImp(RerootFlsDigitToDigiPE)
00034
00035
00036
00037 CVSID("$Id: RerootFlsDigitToDigiPE.cxx,v 1.12 2006/12/11 03:08:30 rhatcher Exp $");
00038 JOBMODULE(RerootFlsDigitToDigiPE, "RerootFlsDigitToDigiPE",
00039 "Builds RawRecord with RawDigitDataBlock");
00040
00041
00042
00043 RerootFlsDigitToDigiPE::RerootFlsDigitToDigiPE()
00044 {
00045 }
00046
00047
00048
00049 RerootFlsDigitToDigiPE::~RerootFlsDigitToDigiPE()
00050 {
00051 MSG("DetSim", Msg::kVerbose) << "RerootFlsDigitToDigiPE::Destructor\n";
00052 }
00053
00054
00055
00056 JobCResult RerootFlsDigitToDigiPE::Get(MomNavigator *mom)
00057 {
00058
00059
00060
00061 if (!gMINFast) {
00062 static int nmsg = 10;
00063 if (nmsg) {
00064 MSG("DetSim",Msg::kFatal)
00065 << "RerootFlsDigitToDigiPE lacked gMINFast" << endl
00066 << " perhaps the input isn't a REROOT file"
00067 << endl;
00068 nmsg--;
00069 if (!nmsg) MSG("DetSim",Msg::kFatal)
00070 << " ... last such message" << endl;
00071 }
00072 return JobCResult::kError;
00073 }
00074
00075
00076 VldContext vldc = RerootExodus::BuildVldContext();
00077
00079
00080
00081 SimSnarlRecord* simsnarl = 0;
00082
00083
00084 TObject* tobj;
00085 TIter fragiter = mom->FragmentIter();
00086 while( ( tobj = fragiter.Next() ) ) {
00087 simsnarl = dynamic_cast<SimSnarlRecord*>(tobj);
00088 if(simsnarl) break;
00089 }
00090
00091
00092 if(simsnarl == 0) {
00093 Int_t run = RerootExodus::GetRunNo();
00094 Short_t subrun = RerootExodus::GetSubRunNum();
00095 Int_t snarl = RerootExodus::GetSnarlNum();
00096 Int_t trigbits = 0;
00097 Short_t runtype = 0;
00098 Int_t errcode = 0;
00099 Int_t timeframe = RerootExodus::GetTimeFrame(vldc);
00100 Int_t spilltype = -1;
00101
00102 VldTimeStamp mcGenTime(RerootExodus::GetLastEventHistoryTimeStamp());
00103 std::string mcCodename(RerootExodus::GetGminosCodeName().Data());
00104 std::string mcHostname(RerootExodus::GetGminosHostName().Data());
00105 SimSnarlHeader simheader(vldc,run,subrun,runtype,
00106 errcode,snarl,trigbits,timeframe,spilltype,
00107 mcGenTime,mcCodename,mcHostname);
00108
00109 simsnarl = new SimSnarlRecord(simheader);
00110
00111 simsnarl->GetTempTags().Set("stream","SimSnarl");
00112
00113
00114 mom -> AdoptFragment(simsnarl);
00115 }
00116
00118
00119 const TObjArray* scintHitListObj =
00120 dynamic_cast<const TObjArray*>(simsnarl->FindComponent(0,"DigiScintHits"));
00121
00122 std::map<Int_t,const DigiScintHit*> scintMap;
00123 std::map<Int_t,const DigiScintHit*>::iterator scintMapItr;
00124
00125 if(scintHitListObj == 0) {
00126 MSG("Reroot",Msg::kError) << "Cannot find DigiScintHit list in the SimSnarl. (Need to run RerootToTruth Module)" << endl;
00127 } else {
00128
00129 TObjArrayIter itr(scintHitListObj);
00130 const DigiScintHit* scintHit = 0;
00131 while( (scintHit = dynamic_cast<DigiScintHit*>(itr.Next())) !=0 ){
00132 PlexStripEndId seid = scintHit->StripEndId();
00133 scintMap[seid.Build18BitPlnStripKey()] = scintHit;
00134 }
00135 }
00136 MSG("Reroot",Msg::kDebug) << "ScintHit map has " << scintMap.size() << " entries\n";
00137
00138
00139 PlexHandle ph(vldc);
00140
00141
00142 const TClonesArray *flsdigits = RerootExodus::GetFLSDigitList();
00143 REROOT_FLSDigit *flsdigit = 0;
00144 TIter diter(flsdigits);
00145
00146 PlexStripEndId seid;
00147 PlexPixelSpotId psid;
00148 Float_t raw;
00149 Int_t isAB;
00150 const DigiScintHit* scintHit=0;
00151 Int_t totalDigits = 0;
00152 Int_t mappedDigits = 0;
00153
00154
00155
00156 Float_t ADAMO_RNULL = 699050. * (Float_t) (16<<26);
00157
00158 JobCResult result = JobCResult::kPassed;
00159
00160
00161 DigiList<DigiPE> peList(0);
00162
00163 while ( ( flsdigit = (REROOT_FLSDigit*) diter.Next() ) ) {
00164
00165 raw = flsdigit->RawA();
00166 isAB = 0;
00167 if ( raw > 0.0 && raw < ADAMO_RNULL ) {
00168 seid = RerootExodus::PECAB2SEId(flsdigit->IPln(),flsdigit->IExtr(),
00169 flsdigit->ICell(),isAB);
00170 psid = ph.GetPixelSpotId(seid);
00171 MSG("Reroot",Msg::kVerbose) << "FlsDigit: IPln()==" << flsdigit->IPln()
00172 << " IExtr()=" << flsdigit->IExtr()
00173 << " ICell()=" << flsdigit->ICell()
00174 << " isAB=" << isAB
00175 << " -> " << seid.AsString() << endl;
00176
00177
00178 scintMapItr = scintMap.find(seid.Build18BitPlnStripKey());
00179 if(scintMapItr!=scintMap.end()){
00180 scintHit = scintMapItr->second;
00181 mappedDigits++;
00182 } else {
00183 scintHit = NULL;
00184 }
00185
00186 AddPE(peList,seid,psid,flsdigit->SignalPEA(),flsdigit->TDCA(),scintHit);
00187 totalDigits++;
00188 }
00189
00190
00191 raw = flsdigit->RawB();
00192 isAB = 1;
00193 if ( raw > 0.0 && raw < ADAMO_RNULL ) {
00194 seid = RerootExodus::PECAB2SEId(flsdigit->IPln(),flsdigit->IExtr(),
00195 flsdigit->ICell(),isAB);
00196 psid = ph.GetPixelSpotId(seid);
00197
00198 MSG("Reroot",Msg::kVerbose) << "FlsDigit: IPln()==" << flsdigit->IPln()
00199 << " IExtr()=" << flsdigit->IExtr()
00200 << " ICell()=" << flsdigit->ICell()
00201 << " isAB=" << isAB
00202 << " -> " << seid.AsString() << endl;
00203
00204
00205 scintMapItr = scintMap.find(seid.Build18BitPlnStripKey());
00206 if(scintMapItr!=scintMap.end()){
00207 scintHit = scintMapItr->second;
00208 mappedDigits++;
00209 } else {
00210 scintHit = NULL;
00211 }
00212
00213 AddPE(peList,seid,psid,flsdigit->SignalPEB(),flsdigit->TDCB(),scintHit);
00214 totalDigits++;
00215 }
00216 }
00217
00218 MSG("Reroot",Msg::kDebug) << totalDigits << " FLSDigits converted to DigiPE. "
00219 << mappedDigits << " of them mapped to DigiScintHits.\n";
00220
00222
00223
00224
00225
00226 TObjArray* storageArray = peList.CreateObjArray("DigiListPe");
00227 simsnarl->AdoptTemporary(storageArray);
00228
00229 return result;
00230 }
00231
00232
00233 void RerootFlsDigitToDigiPE::AddPE( DigiList<DigiPE>& list,
00234 PlexStripEndId& seid,
00235 PlexPixelSpotId& psid,
00236 Double_t pe,
00237 Double_t time,
00238 const DigiScintHit* scintHit)
00239 {
00240
00241
00242
00243
00244
00245
00246
00247 MsgFormat f51("%5.1f");
00248 MSG("Reroot",Msg::kVerbose) << "FlsDigit: "
00249 << f51(pe) << "pe " << f51(time) << "s "
00250 << psid.AsString() << " " << seid.AsString() << endl;
00251
00252
00253
00254 if(! psid.IsValid() ) {
00255
00256
00257 MSG("Reroot",Msg::kVerbose) << "Ignoring invalid PlexPixelSpotId:"
00258 << psid.AsString() << " "
00259 << seid.AsString() << " "
00260 << f51(pe) << "pe " << endl;
00261 return;
00262 }
00263
00264 int npe = TMath::Nint(pe);
00265 if(npe>0) {
00266 for(int ipe=0; ipe<npe; ipe++) {
00267 DigiPE d(time*1e-9,
00268 psid,
00269 scintHit);
00270 list.push_back(d);
00271 }
00272 }
00273 }
00274
00275
00276
00277
00278
00279
00280 const Registry& RerootFlsDigitToDigiPE::DefaultConfig() const
00281 {
00282 static Registry r;
00283
00284
00285 std::string name = this->GetName();
00286 name += ".config.default";
00287 r.SetName(name.c_str());
00288
00289
00290
00291 r.UnLockValues();
00292
00293 return r;
00294 }
00295
00296 void RerootFlsDigitToDigiPE::Config(const Registry& )
00297 {
00298 }
00299