CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10/src/RecoTBCalo/HcalPlotter/scripts/HistoManager.cc

Go to the documentation of this file.
00001 #include "HistoManager.h"
00002 #include "TProfile.h"
00003 #include <iostream>
00004 
00005 HistoManager::HistoManager(TDirectory* parent)
00006 {
00007   pedHistDir   = (TDirectory*)parent->Get("PEDESTAL");
00008   ledHistDir   = (TDirectory*)parent->Get("LED");
00009   laserHistDir = (TDirectory*)parent->Get("LASER");
00010   beamHistDir  = (TDirectory*)parent->Get("BEAM");
00011   otherHistDir = (TDirectory*)parent->Get("OTHER");
00012 }
00013 
00014 std::string HistoManager::nameForFlavor(HistType ht)
00015 {
00016   switch (ht) {
00017   case(ENERGY) : return "Energy"; break;
00018   case(TIME)   : return "Time";   break;
00019   case(PULSE)  : return "Pulse";  break;
00020   case(ADC)    : return "ADC";    break;
00021   default      : return "";       break;
00022   }
00023 }
00024 
00025 std::string HistoManager::nameForEvent(EventType et)
00026 {
00027   switch(et) {
00028   case(PEDESTAL) : return "Pedestal"; break;
00029   case(LED)      : return "LED";      break;
00030   case(LASER)    : return "Laser";    break;
00031   case(BEAM)     : return "Beam";     break;
00032   default        : return "Other";    break;
00033   }     
00034 }
00035 
00036 TH1* HistoManager::GetAHistogram(const MyHcalDetId& id,
00037                                  HistType ht,
00038                                  EventType et)
00039 {
00040   std::string flavor=nameForFlavor(ht);
00041   TDirectory* td;
00042 
00043   switch (et) {
00044   case(PEDESTAL) : td=pedHistDir;   break;
00045   case(LED)      : td=ledHistDir;   break;
00046   case(LASER)    : td=laserHistDir; break;
00047   case(BEAM)     : td=beamHistDir;  break;
00048   case(UNKNOWN)  : td=otherHistDir; break;
00049   default        : td=0;            break;
00050   }
00051 
00052   if (!td) {
00053     printf("Event type not known, et=%d\n", et);
00054     return 0;
00055   }
00056 
00057   char name[120];
00058 
00059   std::string subdetStr;
00060   switch (id.subdet) {
00061   case (HcalBarrel)  : subdetStr="HB"; break;
00062   case (HcalEndcap)  : subdetStr="HE"; break;
00063   case (HcalOuter)   : subdetStr="HO"; break;
00064   case (HcalForward) : subdetStr="HF"; break;
00065   default            : subdetStr="Other"; break;
00066   }
00067 
00068   TH1* retval=0;
00069   sprintf(name,"%s_%s_%d_%d_%d",
00070           flavor.c_str(),subdetStr.c_str(),id.ieta,id.iphi,id.depth);
00071 
00072   TList* keyList = td->GetListOfKeys();
00073   
00074   for(int keyindex = 0; keyindex<keyList->GetEntries(); ++keyindex) {
00075     std::string keyname = keyList->At(keyindex)->GetName();
00076     if (strstr(keyname.c_str(),name)) {
00077       retval=(TH1*)td->Get(keyname.c_str());
00078       break;
00079     }
00080   }
00081 
00082   return retval;
00083 }
00084 
00085 
00086 
00087 
00088 TH1* HistoManager::GetAHistogram(const MyElectronicsId& eid,
00089                                  HistType ht,
00090                                  EventType et)
00091 {
00092   std::string flavor=nameForFlavor(ht);
00093   TDirectory* td;
00094 
00095   switch (et) {
00096   case(PEDESTAL): td=pedHistDir; break;
00097   case(LED): td=ledHistDir; break;
00098   case(LASER): td=laserHistDir; break;
00099   case(BEAM): td=beamHistDir; break;
00100   case(UNKNOWN): td=otherHistDir; break;
00101   default: td=0; break;
00102   }
00103 
00104   if (td==0) {
00105     printf("Unknown %d !\n", et);
00106     return 0;
00107   }
00108 
00109   char name[120];
00110 
00111 
00112   char topbot;
00113   if (eid.tb==0){topbot = 'b';}
00114   else{topbot='t';}
00115   TH1* retval=0;
00116   sprintf(name,"%d_%d_HTR_%d:%d%c",
00117           eid.fiber, eid.fiberChan, eid.crate, eid.Slot,topbot);
00118   TList* keyList = td->GetListOfKeys();
00119   
00120   for(int keyindex = 0; keyindex<keyList->GetEntries(); ++keyindex) {
00121     std::string keyname = keyList->At(keyindex)->GetName();
00122     if ((strstr(keyname.c_str(),name))&&(strstr(keyname.c_str(),flavor.c_str()))) {
00123       retval=(TH1*)td->Get(keyname.c_str());
00124       break;
00125     }
00126   }
00127 
00128   return retval;
00129 }
00130 
00131 
00132 std::vector<MyHcalDetId> HistoManager::getDetIdsForType(HistType ht,
00133                                                         EventType et)
00134 {
00135   char keyflavor[100];
00136   char keysubDet[100];
00137   MyHcalDetId mydetid;
00138   TDirectory* td;
00139   TList* keyList;
00140   std::vector<MyHcalDetId> retvals;
00141 
00142   std::string flavor=nameForFlavor(ht);
00143 
00144   switch (et) {
00145   case(PEDESTAL) : td=pedHistDir;   break;
00146   case(LED)      : td=ledHistDir;   break;
00147   case(LASER)    : td=laserHistDir; break;
00148   case(BEAM)     : td=beamHistDir;  break;
00149   case(UNKNOWN)  : td=otherHistDir; break;
00150   default        : td=0;            break;
00151   }
00152 
00153   if (!td) {
00154     printf("Event type not known, et=%d\n", et);
00155     return retvals;
00156   }
00157 
00158   keyList = td->GetListOfKeys();
00159   
00160   for(int keyindex = 0; keyindex<keyList->GetEntries(); ++keyindex) {
00161     int converted;
00162     std::string keyname = keyList->At(keyindex)->GetName();
00163     // cout << keyindex << " " << keyname << endl;
00164     while (keyname.find("_")!=std::string::npos)
00165       keyname.replace(keyname.find("_"),1," ");
00166     converted = sscanf(keyname.c_str(),"%s %s %d %d %d",
00167                        keyflavor,keysubDet,
00168                        &mydetid.ieta,&mydetid.iphi,&mydetid.depth);
00169     if( (flavor==keyflavor) && (converted==5) ) {
00170       if (!strcmp(keysubDet,"HB")) mydetid.subdet=HcalBarrel;
00171       else if (!strcmp(keysubDet,"HE")) mydetid.subdet=HcalEndcap;
00172       else if (!strcmp(keysubDet,"HO")) mydetid.subdet=HcalOuter;
00173       else if (!strcmp(keysubDet,"HF")) mydetid.subdet=HcalForward;
00174       else continue; // and do not include this in the list!
00175 
00176       retvals.push_back(mydetid);
00177     }
00178   }
00179 
00180 
00181   return retvals;
00182 }
00183 
00184 
00185 std::vector<MyElectronicsId> HistoManager::getElecIdsForType(HistType ht,
00186                                                         EventType et)
00187 {
00188   char keyflavor[100];
00189   char keysubDet[100];
00190   MyElectronicsId mydeteid;
00191   TDirectory* td;
00192   TList* keyList;
00193   std::vector<MyElectronicsId> retvals;
00194 
00195   std::string flavor=nameForFlavor(ht);
00196 
00197   switch (et) {
00198   case(PEDESTAL): td=pedHistDir; break;
00199   case(LED): td=ledHistDir; break;
00200   case(LASER): td=laserHistDir; break;
00201   case(BEAM): td=beamHistDir; break;
00202   case(UNKNOWN): td=otherHistDir; break;
00203   default: td=0; break;
00204   }
00205   if (!td) {
00206     printf("Event type not known, et=%d\n", et);
00207     return retvals;
00208   }
00209 
00210   keyList = td->GetListOfKeys();
00211   if (keyList==0) return retvals;
00212   
00213   for(int keyindex = 0; keyindex<keyList->GetEntries(); ++keyindex) {
00214     int converted;
00215     std::string keyname = keyList->At(keyindex)->GetName();
00216     while (keyname.find("_")!=std::string::npos)
00217       keyname.replace(keyname.find("_"),1," ");
00218     char bottop;
00219     
00220     //printf("%s\n",keyname.c_str());
00221  
00222     if(strstr(keyname.c_str(),"CALIB")){
00223        converted = sscanf(keyname.c_str(),"%s %*s %s %*d %*d chan=%*s eid=%*d %*d %d %d HTR %d:%d%c ",
00224                           keyflavor,keysubDet, &mydeteid.fiber,&mydeteid.fiberChan,&mydeteid.crate,&mydeteid.Slot,&bottop);
00225             
00226    if (bottop=='t')
00227       {mydeteid.tb=1;}
00228     else
00229       {mydeteid.tb=0;} 
00230 
00231    // printf("%d converts to %d %d %d %d %c\n",converted,mydeteid.fiber,mydeteid.fiberChan,mydeteid.crate,mydeteid.Slot,bottop);
00232 
00233     }else{
00234       converted = sscanf(keyname.c_str(),"%s %s %*d %*d %*d eid=%*d %*d %d %d HTR %d:%d%c ",
00235                          keyflavor,keysubDet, &mydeteid.fiber,&mydeteid.fiberChan,&mydeteid.crate,&mydeteid.Slot,&bottop);
00236       
00237         
00238     if (bottop=='t')
00239       {mydeteid.tb=1;}
00240     else
00241       {mydeteid.tb=0;}
00242     }
00243     //printf("converts to %d %d %d %d %d\n",mydeteid.fiber,mydeteid.fiberChan,mydeteid.crate,mydeteid.Slot,mydeteid.tb);
00244 
00245 
00246     if( (flavor==keyflavor) && (converted==7) )
00247 
00248       retvals.push_back(mydeteid);
00249     
00250   }
00251 
00252   
00253   return retvals;
00254 }
00255 
00256